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"
118 #include "template.h"
120 #include "foldersel.h"
133 #define N_ATTACH_COLS (N_COL_COLUMNS)
137 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
138 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
143 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
144 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
145 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
146 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
150 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
151 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
152 } ComposeCallAdvancedAction;
156 PRIORITY_HIGHEST = 1,
165 COMPOSE_INSERT_SUCCESS,
166 COMPOSE_INSERT_READ_ERROR,
167 COMPOSE_INSERT_INVALID_CHARACTER,
168 COMPOSE_INSERT_NO_FILE
169 } ComposeInsertResult;
173 COMPOSE_QUIT_EDITING,
174 COMPOSE_KEEP_EDITING,
176 } ComposeDraftAction;
180 COMPOSE_WRITE_FOR_SEND,
181 COMPOSE_WRITE_FOR_STORE
184 #define B64_LINE_SIZE 57
185 #define B64_BUFFSIZE 77
187 #define MAX_REFERENCES_LEN 999
189 static GList *compose_list = NULL;
191 Compose *compose_generic_new (PrefsAccount *account,
194 GPtrArray *attach_files,
195 GList *listAddress );
197 static Compose *compose_create (PrefsAccount *account,
200 static GtkWidget *compose_account_option_menu_create
202 static void compose_set_out_encoding (Compose *compose);
203 static void compose_set_template_menu (Compose *compose);
204 static void compose_template_apply (Compose *compose,
207 static void compose_destroy (Compose *compose);
209 static void compose_entries_set (Compose *compose,
210 const gchar *mailto);
211 static gint compose_parse_header (Compose *compose,
213 static gchar *compose_parse_references (const gchar *ref,
216 static gchar *compose_quote_fmt (Compose *compose,
223 static void compose_reply_set_entry (Compose *compose,
229 followup_and_reply_to);
230 static void compose_reedit_set_entry (Compose *compose,
233 static void compose_insert_sig (Compose *compose,
235 static gchar *compose_get_signature_str (Compose *compose);
236 static ComposeInsertResult compose_insert_file (Compose *compose,
239 static void compose_attach_append (Compose *compose,
242 const gchar *content_type);
243 static void compose_attach_parts (Compose *compose,
246 static void compose_beautify_paragraph (Compose *compose,
247 GtkTextIter *par_iter,
249 static void compose_wrap_all (Compose *compose);
250 static void compose_wrap_all_full (Compose *compose,
253 static void compose_set_title (Compose *compose);
254 static void compose_select_account (Compose *compose,
255 PrefsAccount *account,
258 static PrefsAccount *compose_current_mail_account(void);
259 /* static gint compose_send (Compose *compose); */
260 static gboolean compose_check_for_valid_recipient
262 static gboolean compose_check_entries (Compose *compose,
263 gboolean check_subject);
264 static gint compose_write_to_file (Compose *compose,
267 static gint compose_write_body_to_file (Compose *compose,
269 static gint compose_remove_reedit_target (Compose *compose,
271 void compose_remove_draft (Compose *compose);
272 static gint compose_queue (Compose *compose,
275 static gint compose_queue_sub (Compose *compose,
278 gboolean check_subject);
279 static void compose_add_attachments (Compose *compose,
281 static gchar *compose_get_header (Compose *compose);
283 static void compose_convert_header (Compose *compose,
288 gboolean addr_field);
290 static void compose_attach_info_free (AttachInfo *ainfo);
291 static void compose_attach_remove_selected (Compose *compose);
293 static void compose_attach_property (Compose *compose);
294 static void compose_attach_property_create (gboolean *cancelled);
295 static void attach_property_ok (GtkWidget *widget,
296 gboolean *cancelled);
297 static void attach_property_cancel (GtkWidget *widget,
298 gboolean *cancelled);
299 static gint attach_property_delete_event (GtkWidget *widget,
301 gboolean *cancelled);
302 static gboolean attach_property_key_pressed (GtkWidget *widget,
304 gboolean *cancelled);
306 static void compose_exec_ext_editor (Compose *compose);
308 static gint compose_exec_ext_editor_real (const gchar *file);
309 static gboolean compose_ext_editor_kill (Compose *compose);
310 static gboolean compose_input_cb (GIOChannel *source,
311 GIOCondition condition,
313 static void compose_set_ext_editor_sensitive (Compose *compose,
315 #endif /* G_OS_UNIX */
317 static void compose_undo_state_changed (UndoMain *undostruct,
322 static void compose_create_header_entry (Compose *compose);
323 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
324 static void compose_update_priority_menu_item(Compose * compose);
326 static void compose_add_field_list ( Compose *compose,
327 GList *listAddress );
329 /* callback functions */
331 static gboolean compose_edit_size_alloc (GtkEditable *widget,
332 GtkAllocation *allocation,
333 GtkSHRuler *shruler);
334 static void account_activated (GtkMenuItem *menuitem,
336 static void attach_selected (GtkTreeView *tree_view,
337 GtkTreePath *tree_path,
338 GtkTreeViewColumn *column,
340 static gboolean attach_button_pressed (GtkWidget *widget,
341 GdkEventButton *event,
343 static gboolean attach_key_pressed (GtkWidget *widget,
347 static void compose_send_cb (gpointer data,
350 static void compose_send_later_cb (gpointer data,
354 static void compose_draft_cb (gpointer data,
358 static void compose_attach_cb (gpointer data,
361 static void compose_insert_file_cb (gpointer data,
364 static void compose_insert_sig_cb (gpointer data,
368 static void compose_close_cb (gpointer data,
372 static void compose_set_encoding_cb (gpointer data,
376 static void compose_address_cb (gpointer data,
379 static void compose_template_activate_cb(GtkWidget *widget,
382 static void compose_ext_editor_cb (gpointer data,
386 static gint compose_delete_cb (GtkWidget *widget,
390 static void compose_undo_cb (Compose *compose);
391 static void compose_redo_cb (Compose *compose);
392 static void compose_cut_cb (Compose *compose);
393 static void compose_copy_cb (Compose *compose);
394 static void compose_paste_cb (Compose *compose);
395 static void compose_paste_as_quote_cb (Compose *compose);
396 static void compose_paste_no_wrap_cb (Compose *compose);
397 static void compose_paste_wrap_cb (Compose *compose);
398 static void compose_allsel_cb (Compose *compose);
400 static void compose_advanced_action_cb (Compose *compose,
401 ComposeCallAdvancedAction action);
403 static void compose_grab_focus_cb (GtkWidget *widget,
406 static void compose_changed_cb (GtkTextBuffer *textbuf,
409 static void compose_wrap_cb (gpointer data,
412 static void compose_toggle_autowrap_cb (gpointer data,
416 static void compose_toggle_ruler_cb (gpointer data,
419 static void compose_toggle_sign_cb (gpointer data,
422 static void compose_toggle_encrypt_cb (gpointer data,
425 static void compose_set_privacy_system_cb(GtkWidget *widget,
427 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
428 static void activate_privacy_system (Compose *compose,
429 PrefsAccount *account,
431 static void compose_use_signing(Compose *compose, gboolean use_signing);
432 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
433 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
435 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
437 static void compose_set_priority_cb (gpointer data,
441 static void compose_attach_drag_received_cb (GtkWidget *widget,
442 GdkDragContext *drag_context,
445 GtkSelectionData *data,
449 static void compose_insert_drag_received_cb (GtkWidget *widget,
450 GdkDragContext *drag_context,
453 GtkSelectionData *data,
457 static void compose_header_drag_received_cb (GtkWidget *widget,
458 GdkDragContext *drag_context,
461 GtkSelectionData *data,
466 static gboolean compose_drag_drop (GtkWidget *widget,
467 GdkDragContext *drag_context,
469 guint time, gpointer user_data);
471 static void text_inserted (GtkTextBuffer *buffer,
476 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
477 gboolean to_all, gboolean to_ml,
479 gboolean followup_and_reply_to,
482 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
483 ComposeHeaderEntry *headerentry);
484 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
486 ComposeHeaderEntry *headerentry);
488 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
490 static void compose_allow_user_actions (Compose *compose, gboolean allow);
493 static void compose_check_all (Compose *compose);
494 static void compose_highlight_all (Compose *compose);
495 static void compose_check_backwards (Compose *compose);
496 static void compose_check_forwards_go (Compose *compose);
499 static gint compose_defer_auto_save_draft (Compose *compose);
500 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
502 static gboolean compose_close (Compose *compose);
504 static GtkItemFactoryEntry compose_popup_entries[] =
506 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
507 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
508 {N_("/---"), NULL, NULL, 0, "<Separator>"},
509 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
512 static GtkItemFactoryEntry compose_entries[] =
514 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
515 {N_("/_Message/_Send"), "<control>Return",
516 compose_send_cb, 0, NULL},
517 {N_("/_Message/Send _later"), "<shift><control>S",
518 compose_send_later_cb, 0, NULL},
519 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
520 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
521 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
522 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
523 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
524 {N_("/_Message/_Save"),
525 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
526 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
527 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
529 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
530 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
531 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
532 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
533 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
534 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
535 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
536 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
537 {N_("/_Edit/Special paste/as _quotation"),
538 NULL, compose_paste_as_quote_cb, 0, NULL},
539 {N_("/_Edit/Special paste/_wrapped"),
540 NULL, compose_paste_wrap_cb, 0, NULL},
541 {N_("/_Edit/Special paste/_unwrapped"),
542 NULL, compose_paste_no_wrap_cb, 0, NULL},
543 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
544 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
545 {N_("/_Edit/A_dvanced/Move a character backward"),
547 compose_advanced_action_cb,
548 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
550 {N_("/_Edit/A_dvanced/Move a character forward"),
552 compose_advanced_action_cb,
553 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
555 {N_("/_Edit/A_dvanced/Move a word backward"),
557 compose_advanced_action_cb,
558 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
560 {N_("/_Edit/A_dvanced/Move a word forward"),
562 compose_advanced_action_cb,
563 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
565 {N_("/_Edit/A_dvanced/Move to beginning of line"),
566 NULL, /* "<control>A" */
567 compose_advanced_action_cb,
568 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
570 {N_("/_Edit/A_dvanced/Move to end of line"),
572 compose_advanced_action_cb,
573 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
575 {N_("/_Edit/A_dvanced/Move to previous line"),
577 compose_advanced_action_cb,
578 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
580 {N_("/_Edit/A_dvanced/Move to next line"),
582 compose_advanced_action_cb,
583 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
585 {N_("/_Edit/A_dvanced/Delete a character backward"),
587 compose_advanced_action_cb,
588 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
590 {N_("/_Edit/A_dvanced/Delete a character forward"),
592 compose_advanced_action_cb,
593 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
595 {N_("/_Edit/A_dvanced/Delete a word backward"),
596 NULL, /* "<control>W" */
597 compose_advanced_action_cb,
598 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
600 {N_("/_Edit/A_dvanced/Delete a word forward"),
601 NULL, /* "<alt>D", */
602 compose_advanced_action_cb,
603 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
605 {N_("/_Edit/A_dvanced/Delete line"),
607 compose_advanced_action_cb,
608 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
610 {N_("/_Edit/A_dvanced/Delete entire line"),
612 compose_advanced_action_cb,
613 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
615 {N_("/_Edit/A_dvanced/Delete to end of line"),
617 compose_advanced_action_cb,
618 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
620 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
621 {N_("/_Edit/_Wrap current paragraph"),
622 "<control>L", compose_wrap_cb, 0, NULL},
623 {N_("/_Edit/Wrap all long _lines"),
624 "<control><alt>L", compose_wrap_cb, 1, NULL},
625 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
626 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
627 {N_("/_Edit/Edit with e_xternal editor"),
628 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
630 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
631 {N_("/_Spelling/_Check all or check selection"),
632 NULL, compose_check_all, 0, NULL},
633 {N_("/_Spelling/_Highlight all misspelled words"),
634 NULL, compose_highlight_all, 0, NULL},
635 {N_("/_Spelling/Check _backwards misspelled word"),
636 NULL, compose_check_backwards , 0, NULL},
637 {N_("/_Spelling/_Forward to next misspelled word"),
638 NULL, compose_check_forwards_go, 0, NULL},
640 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
641 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
642 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
643 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
644 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
645 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
646 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
647 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
648 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
649 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
650 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
651 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
652 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
653 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
654 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
655 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
656 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
658 #define ENC_ACTION(action) \
659 NULL, compose_set_encoding_cb, action, \
660 "/Options/Character encoding/Automatic"
662 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
663 {N_("/_Options/Character _encoding/_Automatic"),
664 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
665 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
667 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
668 ENC_ACTION(C_US_ASCII)},
669 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
670 ENC_ACTION(C_UTF_8)},
671 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
673 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
674 ENC_ACTION(C_ISO_8859_1)},
675 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
676 ENC_ACTION(C_ISO_8859_15)},
677 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
678 ENC_ACTION(C_WINDOWS_1252)},
679 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
681 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
682 ENC_ACTION(C_ISO_8859_2)},
683 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
685 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
686 ENC_ACTION(C_ISO_8859_13)},
687 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
688 ENC_ACTION(C_ISO_8859_4)},
689 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
691 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
692 ENC_ACTION(C_ISO_8859_7)},
693 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
695 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
696 ENC_ACTION(C_ISO_8859_8)},
697 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
698 ENC_ACTION(C_WINDOWS_1255)},
699 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
701 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
702 ENC_ACTION(C_ISO_8859_6)},
703 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
704 ENC_ACTION(C_CP1256)},
705 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
707 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
708 ENC_ACTION(C_ISO_8859_9)},
709 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
711 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
712 ENC_ACTION(C_ISO_8859_5)},
713 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
714 ENC_ACTION(C_KOI8_R)},
715 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
716 ENC_ACTION(C_KOI8_U)},
717 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
718 ENC_ACTION(C_WINDOWS_1251)},
719 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
721 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
722 ENC_ACTION(C_ISO_2022_JP)},
723 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
725 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
726 ENC_ACTION(C_GB2312)},
727 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
729 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
731 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
732 ENC_ACTION(C_EUC_TW)},
733 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
735 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
736 ENC_ACTION(C_EUC_KR)},
737 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
739 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
740 ENC_ACTION(C_TIS_620)},
741 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
742 ENC_ACTION(C_WINDOWS_874)},
744 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
745 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
746 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
747 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
748 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
749 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
750 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
753 static GtkTargetEntry compose_mime_types[] =
755 {"text/uri-list", 0, 0},
756 {"text/plain", 0, 0},
760 static gboolean compose_put_existing_to_front(MsgInfo *info)
762 GList *compose_list = compose_get_compose_list();
766 for (elem = compose_list; elem != NULL && elem->data != NULL;
768 Compose *c = (Compose*)elem->data;
770 if (!c->targetinfo || !c->targetinfo->msgid ||
774 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
775 gtkut_window_popup(c->window);
783 static GdkColor quote_color =
784 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
786 static GdkColor signature_color = {
793 static GdkColor uri_color = {
800 static void compose_create_tags(GtkTextView *text, Compose *compose)
802 GtkTextBuffer *buffer;
803 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
805 buffer = gtk_text_view_get_buffer(text);
807 if (prefs_common.enable_color) {
808 /* grab the quote colors, converting from an int to a GdkColor */
809 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
811 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
813 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
816 signature_color = quote_color = uri_color = black;
819 gtk_text_buffer_create_tag(buffer, "quote",
820 "foreground-gdk", "e_color,
822 gtk_text_buffer_create_tag(buffer, "signature",
823 "foreground-gdk", &signature_color,
825 gtk_text_buffer_create_tag(buffer, "link",
826 "foreground-gdk", &uri_color,
828 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
829 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
832 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
833 GPtrArray *attach_files)
835 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
838 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
840 return compose_generic_new(account, NULL, item, NULL, NULL);
843 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
845 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
848 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
849 GPtrArray *attach_files, GList *listAddress )
852 GtkTextView *textview;
853 GtkTextBuffer *textbuf;
855 GtkItemFactory *ifactory;
857 if (item && item->prefs && item->prefs->enable_default_account)
858 account = account_find_from_id(item->prefs->default_account);
860 if (!account) account = cur_account;
861 g_return_val_if_fail(account != NULL, NULL);
863 compose = compose_create(account, COMPOSE_NEW);
864 ifactory = gtk_item_factory_from_widget(compose->menubar);
866 compose->replyinfo = NULL;
867 compose->fwdinfo = NULL;
869 textview = GTK_TEXT_VIEW(compose->text);
870 textbuf = gtk_text_view_get_buffer(textview);
871 compose_create_tags(textview, compose);
873 undo_block(compose->undostruct);
875 if (item && item->prefs && item->prefs->enable_default_dictionary &&
877 gtkaspell_change_dict(compose->gtkaspell,
878 item->prefs->default_dictionary);
881 if (account->auto_sig)
882 compose_insert_sig(compose, FALSE);
883 gtk_text_buffer_get_start_iter(textbuf, &iter);
884 gtk_text_buffer_place_cursor(textbuf, &iter);
886 if (account->protocol != A_NNTP) {
887 if (mailto && *mailto != '\0') {
888 compose_entries_set(compose, mailto);
890 } else if (item && item->prefs->enable_default_to) {
891 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
892 compose_entry_mark_default_to(compose, item->prefs->default_to);
894 if (item && item->ret_rcpt) {
895 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
899 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
901 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
904 * CLAWS: just don't allow return receipt request, even if the user
905 * may want to send an email. simple but foolproof.
907 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
909 compose_add_field_list( compose, listAddress );
915 for (i = 0; i < attach_files->len; i++) {
916 file = g_ptr_array_index(attach_files, i);
917 compose_attach_append(compose, file, file, NULL);
921 compose_show_first_last_header(compose, TRUE);
923 /* Set save folder */
924 if (item && item->prefs && item->prefs->save_copy_to_folder) {
925 gchar *folderidentifier;
927 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
928 folderidentifier = folder_item_get_identifier(item);
929 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
930 g_free(folderidentifier);
933 gtk_widget_grab_focus(compose->header_last->entry);
935 undo_unblock(compose->undostruct);
937 if (prefs_common.auto_exteditor)
938 compose_exec_ext_editor(compose);
940 compose->modified = FALSE;
941 compose_set_title(compose);
945 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
946 gboolean override_pref)
948 gchar *privacy = NULL;
950 g_return_if_fail(compose != NULL);
951 g_return_if_fail(account != NULL);
953 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
956 if (account->default_privacy_system
957 && strlen(account->default_privacy_system)) {
958 privacy = account->default_privacy_system;
960 GSList *privacy_avail = privacy_get_system_ids();
961 if (privacy_avail && g_slist_length(privacy_avail)) {
962 privacy = (gchar *)(privacy_avail->data);
965 if (privacy != NULL) {
966 compose->privacy_system = g_strdup(privacy);
967 compose_update_privacy_system_menu_item(compose, FALSE);
968 compose_use_encryption(compose, TRUE);
972 static void compose_force_signing(Compose *compose, PrefsAccount *account)
974 gchar *privacy = NULL;
976 if (account->default_privacy_system
977 && strlen(account->default_privacy_system)) {
978 privacy = account->default_privacy_system;
980 GSList *privacy_avail = privacy_get_system_ids();
981 if (privacy_avail && g_slist_length(privacy_avail)) {
982 privacy = (gchar *)(privacy_avail->data);
985 if (privacy != NULL) {
986 compose->privacy_system = g_strdup(privacy);
987 compose_update_privacy_system_menu_item(compose, FALSE);
988 compose_use_signing(compose, TRUE);
992 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
996 Compose *compose = NULL;
997 g_return_val_if_fail(msginfo_list != NULL, NULL);
999 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1000 g_return_val_if_fail(msginfo != NULL, NULL);
1002 list_len = g_slist_length(msginfo_list);
1006 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1007 FALSE, prefs_common.default_reply_list, FALSE, body);
1009 case COMPOSE_REPLY_WITH_QUOTE:
1010 compose = compose_reply(msginfo, TRUE,
1011 FALSE, prefs_common.default_reply_list, FALSE, body);
1013 case COMPOSE_REPLY_WITHOUT_QUOTE:
1014 compose = compose_reply(msginfo, FALSE,
1015 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1017 case COMPOSE_REPLY_TO_SENDER:
1018 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1019 FALSE, FALSE, TRUE, body);
1021 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1022 compose = compose_followup_and_reply_to(msginfo,
1023 prefs_common.reply_with_quote,
1024 FALSE, FALSE, body);
1026 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1027 compose = compose_reply(msginfo, TRUE,
1028 FALSE, FALSE, TRUE, body);
1030 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1031 compose = compose_reply(msginfo, FALSE,
1032 FALSE, FALSE, TRUE, NULL);
1034 case COMPOSE_REPLY_TO_ALL:
1035 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1036 TRUE, FALSE, FALSE, body);
1038 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1039 compose = compose_reply(msginfo, TRUE,
1040 TRUE, FALSE, FALSE, body);
1042 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1043 compose = compose_reply(msginfo, FALSE,
1044 TRUE, FALSE, FALSE, NULL);
1046 case COMPOSE_REPLY_TO_LIST:
1047 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1048 FALSE, TRUE, FALSE, body);
1050 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1051 compose = compose_reply(msginfo, TRUE,
1052 FALSE, TRUE, FALSE, body);
1054 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1055 compose = compose_reply(msginfo, FALSE,
1056 FALSE, TRUE, FALSE, NULL);
1058 case COMPOSE_FORWARD:
1059 if (prefs_common.forward_as_attachment) {
1060 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1063 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1067 case COMPOSE_FORWARD_INLINE:
1068 /* check if we reply to more than one Message */
1069 if (list_len == 1) {
1070 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE);
1073 /* more messages FALL THROUGH */
1074 case COMPOSE_FORWARD_AS_ATTACH:
1075 compose = compose_forward_multiple(NULL, msginfo_list);
1077 case COMPOSE_REDIRECT:
1078 compose = compose_redirect(NULL, msginfo);
1081 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1086 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1087 gboolean to_ml, gboolean to_sender,
1090 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1091 to_sender, FALSE, body);
1094 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1099 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1100 to_sender, TRUE, body);
1103 static void compose_extract_original_charset(Compose *compose)
1105 MsgInfo *info = NULL;
1106 if (compose->replyinfo) {
1107 info = compose->replyinfo;
1108 } else if (compose->fwdinfo) {
1109 info = compose->fwdinfo;
1110 } else if (compose->targetinfo) {
1111 info = compose->targetinfo;
1114 MimeInfo *mimeinfo = procmime_scan_message(info);
1115 MimeInfo *partinfo = mimeinfo;
1116 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1117 partinfo = procmime_mimeinfo_next(partinfo);
1119 compose->orig_charset =
1120 g_strdup(procmime_mimeinfo_get_parameter(
1121 partinfo, "charset"));
1123 procmime_mimeinfo_free_all(mimeinfo);
1127 #define SIGNAL_BLOCK(buffer) { \
1128 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1129 G_CALLBACK(compose_changed_cb), \
1131 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1132 G_CALLBACK(text_inserted), \
1136 #define SIGNAL_UNBLOCK(buffer) { \
1137 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1138 G_CALLBACK(compose_changed_cb), \
1140 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1141 G_CALLBACK(text_inserted), \
1145 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1146 gboolean to_all, gboolean to_ml,
1148 gboolean followup_and_reply_to,
1151 GtkItemFactory *ifactory;
1153 PrefsAccount *account = NULL;
1154 PrefsAccount *reply_account;
1155 GtkTextView *textview;
1156 GtkTextBuffer *textbuf;
1158 g_return_val_if_fail(msginfo != NULL, NULL);
1159 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1161 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1163 g_return_val_if_fail(account != NULL, NULL);
1165 if (to_sender && account->protocol == A_NNTP &&
1166 !followup_and_reply_to) {
1168 account_find_from_address(account->address);
1170 reply_account = compose_current_mail_account();
1174 reply_account = account;
1176 compose = compose_create(account, COMPOSE_REPLY);
1177 ifactory = gtk_item_factory_from_widget(compose->menubar);
1179 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1180 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1182 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1184 if (!compose->replyinfo)
1185 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1187 compose_extract_original_charset(compose);
1189 if (msginfo->folder && msginfo->folder->ret_rcpt)
1190 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1192 /* Set save folder */
1193 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1194 gchar *folderidentifier;
1196 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1197 folderidentifier = folder_item_get_identifier(msginfo->folder);
1198 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1199 g_free(folderidentifier);
1202 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1203 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1204 to_sender, followup_and_reply_to);
1205 compose_show_first_last_header(compose, TRUE);
1207 textview = (GTK_TEXT_VIEW(compose->text));
1208 textbuf = gtk_text_view_get_buffer(textview);
1209 compose_create_tags(textview, compose);
1211 undo_block(compose->undostruct);
1213 if (msginfo->folder && msginfo->folder->prefs &&
1214 msginfo->folder->prefs &&
1215 msginfo->folder->prefs->enable_default_dictionary &&
1217 gtkaspell_change_dict(compose->gtkaspell,
1218 msginfo->folder->prefs->default_dictionary);
1224 if (prefs_common.quotemark && *prefs_common.quotemark)
1225 qmark = prefs_common.quotemark;
1229 compose_quote_fmt(compose, compose->replyinfo,
1230 prefs_common.quotefmt,
1231 qmark, body, FALSE);
1233 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1234 compose_force_encryption(compose, account, FALSE);
1237 SIGNAL_BLOCK(textbuf);
1239 if (account->auto_sig)
1240 compose_insert_sig(compose, FALSE);
1242 compose_wrap_all(compose);
1244 SIGNAL_UNBLOCK(textbuf);
1246 gtk_widget_grab_focus(compose->text);
1248 undo_unblock(compose->undostruct);
1250 if (prefs_common.auto_exteditor)
1251 compose_exec_ext_editor(compose);
1253 compose->modified = FALSE;
1254 compose_set_title(compose);
1258 #define INSERT_FW_HEADER(var, hdr) \
1259 if (msginfo->var && *msginfo->var) { \
1260 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1261 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1262 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1265 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1266 gboolean as_attach, const gchar *body,
1267 gboolean no_extedit)
1270 GtkTextView *textview;
1271 GtkTextBuffer *textbuf;
1274 g_return_val_if_fail(msginfo != NULL, NULL);
1275 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1278 !(account = compose_guess_forward_account_from_msginfo
1280 account = cur_account;
1282 compose = compose_create(account, COMPOSE_FORWARD);
1284 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1285 if (!compose->fwdinfo)
1286 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1288 compose_extract_original_charset(compose);
1290 if (msginfo->subject && *msginfo->subject) {
1291 gchar *buf, *buf2, *p;
1293 buf = p = g_strdup(msginfo->subject);
1294 p += subject_get_prefix_length(p);
1295 memmove(buf, p, strlen(p) + 1);
1297 buf2 = g_strdup_printf("Fw: %s", buf);
1298 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1304 textview = GTK_TEXT_VIEW(compose->text);
1305 textbuf = gtk_text_view_get_buffer(textview);
1306 compose_create_tags(textview, compose);
1308 undo_block(compose->undostruct);
1312 msgfile = procmsg_get_message_file_path(msginfo);
1313 if (!is_file_exist(msgfile))
1314 g_warning("%s: file not exist\n", msgfile);
1316 compose_attach_append(compose, msgfile, msgfile,
1322 MsgInfo *full_msginfo;
1324 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1326 full_msginfo = procmsg_msginfo_copy(msginfo);
1328 if (prefs_common.fw_quotemark &&
1329 *prefs_common.fw_quotemark)
1330 qmark = prefs_common.fw_quotemark;
1334 compose_quote_fmt(compose, full_msginfo,
1335 prefs_common.fw_quotefmt,
1336 qmark, body, FALSE);
1337 compose_attach_parts(compose, msginfo);
1339 procmsg_msginfo_free(full_msginfo);
1342 SIGNAL_BLOCK(textbuf);
1344 if (account->auto_sig)
1345 compose_insert_sig(compose, FALSE);
1347 compose_wrap_all(compose);
1349 SIGNAL_UNBLOCK(textbuf);
1351 gtk_text_buffer_get_start_iter(textbuf, &iter);
1352 gtk_text_buffer_place_cursor(textbuf, &iter);
1354 gtk_widget_grab_focus(compose->header_last->entry);
1356 if (!no_extedit && prefs_common.auto_exteditor)
1357 compose_exec_ext_editor(compose);
1360 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1361 gchar *folderidentifier;
1363 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1364 folderidentifier = folder_item_get_identifier(msginfo->folder);
1365 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1366 g_free(folderidentifier);
1369 undo_unblock(compose->undostruct);
1371 compose->modified = FALSE;
1372 compose_set_title(compose);
1376 #undef INSERT_FW_HEADER
1378 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1381 GtkTextView *textview;
1382 GtkTextBuffer *textbuf;
1386 gboolean single_mail = TRUE;
1388 g_return_val_if_fail(msginfo_list != NULL, NULL);
1390 if (g_slist_length(msginfo_list) > 1)
1391 single_mail = FALSE;
1393 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1394 if (((MsgInfo *)msginfo->data)->folder == NULL)
1397 /* guess account from first selected message */
1399 !(account = compose_guess_forward_account_from_msginfo
1400 (msginfo_list->data)))
1401 account = cur_account;
1403 g_return_val_if_fail(account != NULL, NULL);
1405 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1406 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1407 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1410 compose = compose_create(account, COMPOSE_FORWARD);
1412 textview = GTK_TEXT_VIEW(compose->text);
1413 textbuf = gtk_text_view_get_buffer(textview);
1414 compose_create_tags(textview, compose);
1416 undo_block(compose->undostruct);
1417 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1418 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1419 if (!is_file_exist(msgfile))
1420 g_warning("%s: file not exist\n", msgfile);
1422 compose_attach_append(compose, msgfile, msgfile,
1428 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1429 if (info->subject && *info->subject) {
1430 gchar *buf, *buf2, *p;
1432 buf = p = g_strdup(info->subject);
1433 p += subject_get_prefix_length(p);
1434 memmove(buf, p, strlen(p) + 1);
1436 buf2 = g_strdup_printf("Fw: %s", buf);
1437 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1443 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1444 _("Fw: multiple emails"));
1447 SIGNAL_BLOCK(textbuf);
1449 if (account->auto_sig)
1450 compose_insert_sig(compose, FALSE);
1452 compose_wrap_all(compose);
1454 SIGNAL_UNBLOCK(textbuf);
1456 gtk_text_buffer_get_start_iter(textbuf, &iter);
1457 gtk_text_buffer_place_cursor(textbuf, &iter);
1459 gtk_widget_grab_focus(compose->header_last->entry);
1460 undo_unblock(compose->undostruct);
1461 compose->modified = FALSE;
1462 compose_set_title(compose);
1466 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1468 GtkTextIter start = *iter;
1469 GtkTextIter end_iter;
1470 int start_pos = gtk_text_iter_get_offset(&start);
1472 if (!compose->account->sig_sep)
1475 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1476 start_pos+strlen(compose->account->sig_sep));
1478 /* check sig separator */
1479 str = gtk_text_iter_get_text(&start, &end_iter);
1480 if (!strcmp(str, compose->account->sig_sep)) {
1482 /* check end of line (\n) */
1483 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1484 start_pos+strlen(compose->account->sig_sep));
1485 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1486 start_pos+strlen(compose->account->sig_sep)+1);
1487 tmp = gtk_text_iter_get_text(&start, &end_iter);
1488 if (!strcmp(tmp,"\n")) {
1500 static void compose_colorize_signature(Compose *compose)
1502 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1504 GtkTextIter end_iter;
1505 gtk_text_buffer_get_start_iter(buffer, &iter);
1506 while (gtk_text_iter_forward_line(&iter))
1507 if (compose_is_sig_separator(compose, buffer, &iter)) {
1508 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1509 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1513 void compose_reedit(MsgInfo *msginfo)
1515 Compose *compose = NULL;
1516 PrefsAccount *account = NULL;
1517 GtkTextView *textview;
1518 GtkTextBuffer *textbuf;
1522 gchar buf[BUFFSIZE];
1523 gboolean use_signing = FALSE;
1524 gboolean use_encryption = FALSE;
1525 gchar *privacy_system = NULL;
1527 g_return_if_fail(msginfo != NULL);
1528 g_return_if_fail(msginfo->folder != NULL);
1530 if (compose_put_existing_to_front(msginfo))
1533 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1534 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1535 gchar queueheader_buf[BUFFSIZE];
1538 /* Select Account from queue headers */
1539 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1540 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1541 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1542 account = account_find_from_id(id);
1544 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1545 sizeof(queueheader_buf), "NAID:")) {
1546 id = atoi(&queueheader_buf[strlen("NAID:")]);
1547 account = account_find_from_id(id);
1549 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1550 sizeof(queueheader_buf), "MAID:")) {
1551 id = atoi(&queueheader_buf[strlen("MAID:")]);
1552 account = account_find_from_id(id);
1554 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1555 sizeof(queueheader_buf), "S:")) {
1556 account = account_find_from_address(queueheader_buf);
1558 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1559 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1560 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1561 use_signing = param;
1564 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1565 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1566 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1567 use_encryption = param;
1569 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1570 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1571 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1573 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1574 sizeof(queueheader_buf), "X-Priority: ")) {
1575 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1576 compose->priority = param;
1579 account = msginfo->folder->folder->account;
1581 if (!account && prefs_common.reedit_account_autosel) {
1582 gchar from[BUFFSIZE];
1583 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1584 extract_address(from);
1585 account = account_find_from_address(from);
1588 if (!account) account = cur_account;
1589 g_return_if_fail(account != NULL);
1591 compose = compose_create(account, COMPOSE_REEDIT);
1592 if (privacy_system != NULL) {
1593 compose->privacy_system = privacy_system;
1594 compose_use_signing(compose, use_signing);
1595 compose_use_encryption(compose, use_encryption);
1596 compose_update_privacy_system_menu_item(compose, FALSE);
1598 activate_privacy_system(compose, account, FALSE);
1600 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1602 compose_extract_original_charset(compose);
1604 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1605 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1606 gchar queueheader_buf[BUFFSIZE];
1608 /* Set message save folder */
1609 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1612 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1613 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1614 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1616 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1617 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1619 GtkItemFactory *ifactory;
1620 ifactory = gtk_item_factory_from_widget(compose->menubar);
1621 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1626 if (compose_parse_header(compose, msginfo) < 0) return;
1627 compose_reedit_set_entry(compose, msginfo);
1629 textview = GTK_TEXT_VIEW(compose->text);
1630 textbuf = gtk_text_view_get_buffer(textview);
1631 compose_create_tags(textview, compose);
1633 mark = gtk_text_buffer_get_insert(textbuf);
1634 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1636 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1637 G_CALLBACK(compose_changed_cb),
1640 if (procmime_msginfo_is_encrypted(msginfo)) {
1641 fp = procmime_get_first_encrypted_text_content(msginfo);
1643 compose_force_encryption(compose, account, TRUE);
1645 fp = procmime_get_first_text_content(msginfo);
1647 g_warning("Can't get text part\n");
1650 gboolean prev_autowrap = compose->autowrap;
1652 compose->autowrap = FALSE;
1653 while (fgets(buf, sizeof(buf), fp) != NULL) {
1655 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1657 compose_wrap_all_full(compose, FALSE);
1658 compose->autowrap = prev_autowrap;
1662 compose_attach_parts(compose, msginfo);
1664 compose_colorize_signature(compose);
1666 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1667 G_CALLBACK(compose_changed_cb),
1670 gtk_widget_grab_focus(compose->text);
1672 if (prefs_common.auto_exteditor)
1673 compose_exec_ext_editor(compose);
1674 compose->modified = FALSE;
1675 compose_set_title(compose);
1678 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1682 GtkItemFactory *ifactory;
1685 g_return_val_if_fail(msginfo != NULL, NULL);
1688 account = account_get_reply_account(msginfo,
1689 prefs_common.reply_account_autosel);
1690 g_return_val_if_fail(account != NULL, NULL);
1692 compose = compose_create(account, COMPOSE_REDIRECT);
1693 ifactory = gtk_item_factory_from_widget(compose->menubar);
1694 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1695 compose->replyinfo = NULL;
1696 compose->fwdinfo = NULL;
1698 compose_show_first_last_header(compose, TRUE);
1700 gtk_widget_grab_focus(compose->header_last->entry);
1702 filename = procmsg_get_message_file_path(msginfo);
1703 if (filename == NULL)
1706 compose->redirect_filename = filename;
1708 /* Set save folder */
1709 item = msginfo->folder;
1710 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1711 gchar *folderidentifier;
1713 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1714 folderidentifier = folder_item_get_identifier(item);
1715 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1716 g_free(folderidentifier);
1719 compose_attach_parts(compose, msginfo);
1721 if (msginfo->subject)
1722 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1724 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1726 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1727 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1729 compose_colorize_signature(compose);
1731 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1732 menu_set_sensitive(ifactory, "/Add...", FALSE);
1733 menu_set_sensitive(ifactory, "/Remove", FALSE);
1734 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1736 ifactory = gtk_item_factory_from_widget(compose->menubar);
1737 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1738 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1739 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1740 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1741 menu_set_sensitive(ifactory, "/Edit", FALSE);
1742 menu_set_sensitive(ifactory, "/Options", FALSE);
1743 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1744 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1746 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1747 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1748 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1749 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1750 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1751 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1752 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1754 compose->modified = FALSE;
1755 compose_set_title(compose);
1759 GList *compose_get_compose_list(void)
1761 return compose_list;
1764 void compose_entry_append(Compose *compose, const gchar *address,
1765 ComposeEntryType type)
1769 gboolean in_quote = FALSE;
1770 if (!address || *address == '\0') return;
1777 header = N_("Bcc:");
1779 case COMPOSE_REPLYTO:
1780 header = N_("Reply-To:");
1782 case COMPOSE_NEWSGROUPS:
1783 header = N_("Newsgroups:");
1785 case COMPOSE_FOLLOWUPTO:
1786 header = N_( "Followup-To:");
1793 header = prefs_common.trans_hdr ? gettext(header) : header;
1795 cur = begin = (gchar *)address;
1797 /* we separate the line by commas, but not if we're inside a quoted
1799 while (*cur != '\0') {
1801 in_quote = !in_quote;
1802 if (*cur == ',' && !in_quote) {
1803 gchar *tmp = g_strdup(begin);
1805 tmp[cur-begin]='\0';
1810 compose_add_header_entry(compose, header, tmp);
1817 gchar *tmp = g_strdup(begin);
1819 tmp[cur-begin]='\0';
1824 compose_add_header_entry(compose, header, tmp);
1829 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1831 static GdkColor yellow;
1832 static GdkColor black;
1833 static gboolean yellow_initialised = FALSE;
1837 if (!yellow_initialised) {
1838 gdk_color_parse("#f5f6be", &yellow);
1839 gdk_color_parse("#000000", &black);
1840 yellow_initialised = gdk_colormap_alloc_color(
1841 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
1842 yellow_initialised &= gdk_colormap_alloc_color(
1843 gdk_colormap_get_system(), &black, FALSE, TRUE);
1846 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1847 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1848 if (gtk_entry_get_text(entry) &&
1849 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1850 if (yellow_initialised) {
1851 gtk_widget_modify_base(
1852 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
1853 GTK_STATE_NORMAL, &yellow);
1854 gtk_widget_modify_text(
1855 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
1856 GTK_STATE_NORMAL, &black);
1862 void compose_toolbar_cb(gint action, gpointer data)
1864 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1865 Compose *compose = (Compose*)toolbar_item->parent;
1867 g_return_if_fail(compose != NULL);
1871 compose_send_cb(compose, 0, NULL);
1874 compose_send_later_cb(compose, 0, NULL);
1877 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1880 compose_insert_file_cb(compose, 0, NULL);
1883 compose_attach_cb(compose, 0, NULL);
1886 compose_insert_sig(compose, FALSE);
1889 compose_ext_editor_cb(compose, 0, NULL);
1891 case A_LINEWRAP_CURRENT:
1892 compose_beautify_paragraph(compose, NULL, TRUE);
1894 case A_LINEWRAP_ALL:
1895 compose_wrap_all_full(compose, TRUE);
1898 compose_address_cb(compose, 0, NULL);
1901 case A_CHECK_SPELLING:
1902 compose_check_all(compose);
1910 static void compose_entries_set(Compose *compose, const gchar *mailto)
1914 gchar *subject = NULL;
1919 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1922 compose_entry_append(compose, to, COMPOSE_TO);
1924 compose_entry_append(compose, cc, COMPOSE_CC);
1926 if (!g_utf8_validate (subject, -1, NULL)) {
1927 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1928 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1931 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1935 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1936 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1939 gboolean prev_autowrap = compose->autowrap;
1941 compose->autowrap = FALSE;
1943 mark = gtk_text_buffer_get_insert(buffer);
1944 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1946 if (!g_utf8_validate (body, -1, NULL)) {
1947 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1948 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1951 gtk_text_buffer_insert(buffer, &iter, body, -1);
1953 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1955 compose->autowrap = prev_autowrap;
1956 if (compose->autowrap)
1957 compose_wrap_all(compose);
1966 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1968 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1969 {"Cc:", NULL, TRUE},
1970 {"References:", NULL, FALSE},
1971 {"Bcc:", NULL, TRUE},
1972 {"Newsgroups:", NULL, TRUE},
1973 {"Followup-To:", NULL, TRUE},
1974 {"List-Post:", NULL, FALSE},
1975 {"X-Priority:", NULL, FALSE},
1976 {NULL, NULL, FALSE}};
1992 g_return_val_if_fail(msginfo != NULL, -1);
1994 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1995 procheader_get_header_fields(fp, hentry);
1998 if (hentry[H_REPLY_TO].body != NULL) {
1999 if (hentry[H_REPLY_TO].body[0] != '\0') {
2001 conv_unmime_header(hentry[H_REPLY_TO].body,
2004 g_free(hentry[H_REPLY_TO].body);
2005 hentry[H_REPLY_TO].body = NULL;
2007 if (hentry[H_CC].body != NULL) {
2008 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2009 g_free(hentry[H_CC].body);
2010 hentry[H_CC].body = NULL;
2012 if (hentry[H_REFERENCES].body != NULL) {
2013 if (compose->mode == COMPOSE_REEDIT)
2014 compose->references = hentry[H_REFERENCES].body;
2016 compose->references = compose_parse_references
2017 (hentry[H_REFERENCES].body, msginfo->msgid);
2018 g_free(hentry[H_REFERENCES].body);
2020 hentry[H_REFERENCES].body = NULL;
2022 if (hentry[H_BCC].body != NULL) {
2023 if (compose->mode == COMPOSE_REEDIT)
2025 conv_unmime_header(hentry[H_BCC].body, NULL);
2026 g_free(hentry[H_BCC].body);
2027 hentry[H_BCC].body = NULL;
2029 if (hentry[H_NEWSGROUPS].body != NULL) {
2030 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2031 hentry[H_NEWSGROUPS].body = NULL;
2033 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2034 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2035 compose->followup_to =
2036 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2039 g_free(hentry[H_FOLLOWUP_TO].body);
2040 hentry[H_FOLLOWUP_TO].body = NULL;
2042 if (hentry[H_LIST_POST].body != NULL) {
2045 extract_address(hentry[H_LIST_POST].body);
2046 if (hentry[H_LIST_POST].body[0] != '\0') {
2047 scan_mailto_url(hentry[H_LIST_POST].body,
2048 &to, NULL, NULL, NULL, NULL);
2050 g_free(compose->ml_post);
2051 compose->ml_post = to;
2054 g_free(hentry[H_LIST_POST].body);
2055 hentry[H_LIST_POST].body = NULL;
2058 /* CLAWS - X-Priority */
2059 if (compose->mode == COMPOSE_REEDIT)
2060 if (hentry[H_X_PRIORITY].body != NULL) {
2063 priority = atoi(hentry[H_X_PRIORITY].body);
2064 g_free(hentry[H_X_PRIORITY].body);
2066 hentry[H_X_PRIORITY].body = NULL;
2068 if (priority < PRIORITY_HIGHEST ||
2069 priority > PRIORITY_LOWEST)
2070 priority = PRIORITY_NORMAL;
2072 compose->priority = priority;
2075 if (compose->mode == COMPOSE_REEDIT) {
2076 if (msginfo->inreplyto && *msginfo->inreplyto)
2077 compose->inreplyto = g_strdup(msginfo->inreplyto);
2081 if (msginfo->msgid && *msginfo->msgid)
2082 compose->inreplyto = g_strdup(msginfo->msgid);
2084 if (!compose->references) {
2085 if (msginfo->msgid && *msginfo->msgid) {
2086 if (msginfo->inreplyto && *msginfo->inreplyto)
2087 compose->references =
2088 g_strdup_printf("<%s>\n\t<%s>",
2092 compose->references =
2093 g_strconcat("<", msginfo->msgid, ">",
2095 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2096 compose->references =
2097 g_strconcat("<", msginfo->inreplyto, ">",
2105 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2107 GSList *ref_id_list, *cur;
2111 ref_id_list = references_list_append(NULL, ref);
2112 if (!ref_id_list) return NULL;
2113 if (msgid && *msgid)
2114 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2119 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2120 /* "<" + Message-ID + ">" + CR+LF+TAB */
2121 len += strlen((gchar *)cur->data) + 5;
2123 if (len > MAX_REFERENCES_LEN) {
2124 /* remove second message-ID */
2125 if (ref_id_list && ref_id_list->next &&
2126 ref_id_list->next->next) {
2127 g_free(ref_id_list->next->data);
2128 ref_id_list = g_slist_remove
2129 (ref_id_list, ref_id_list->next->data);
2131 slist_free_strings(ref_id_list);
2132 g_slist_free(ref_id_list);
2139 new_ref = g_string_new("");
2140 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2141 if (new_ref->len > 0)
2142 g_string_append(new_ref, "\n\t");
2143 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2146 slist_free_strings(ref_id_list);
2147 g_slist_free(ref_id_list);
2149 new_ref_str = new_ref->str;
2150 g_string_free(new_ref, FALSE);
2155 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2156 const gchar *fmt, const gchar *qmark,
2157 const gchar *body, gboolean rewrap)
2159 static MsgInfo dummyinfo;
2160 gchar *quote_str = NULL;
2162 gboolean prev_autowrap;
2163 const gchar *trimmed_body = body;
2164 gint cursor_pos = -1;
2165 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2166 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2171 SIGNAL_BLOCK(buffer);
2174 msginfo = &dummyinfo;
2176 if (qmark != NULL) {
2177 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2178 quote_fmt_scan_string(qmark);
2181 buf = quote_fmt_get_buffer();
2183 alertpanel_error(_("Quote mark format error."));
2185 Xstrdup_a(quote_str, buf, goto error)
2188 if (fmt && *fmt != '\0') {
2189 while (trimmed_body && strlen(trimmed_body) > 1
2190 && trimmed_body[0]=='\n')
2193 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2194 quote_fmt_scan_string(fmt);
2197 buf = quote_fmt_get_buffer();
2199 alertpanel_error(_("Message reply/forward format error."));
2205 prev_autowrap = compose->autowrap;
2206 compose->autowrap = FALSE;
2208 mark = gtk_text_buffer_get_insert(buffer);
2209 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2210 if (g_utf8_validate(buf, -1, NULL)) {
2211 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2213 gchar *tmpout = NULL;
2214 tmpout = conv_codeset_strdup
2215 (buf, conv_get_locale_charset_str(),
2217 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2219 tmpout = g_malloc(strlen(buf)*2+1);
2220 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2222 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2226 cursor_pos = quote_fmt_get_cursor_pos();
2227 compose->set_cursor_pos = cursor_pos;
2228 if (cursor_pos == -1) {
2231 gtk_text_buffer_get_start_iter(buffer, &iter);
2232 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2233 gtk_text_buffer_place_cursor(buffer, &iter);
2235 compose->autowrap = prev_autowrap;
2236 if (compose->autowrap && rewrap)
2237 compose_wrap_all(compose);
2244 SIGNAL_UNBLOCK(buffer);
2250 /* if ml_post is of type addr@host and from is of type
2251 * addr-anything@host, return TRUE
2253 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2255 gchar *left_ml = NULL;
2256 gchar *right_ml = NULL;
2257 gchar *left_from = NULL;
2258 gchar *right_from = NULL;
2259 gboolean result = FALSE;
2261 if (!ml_post || !from)
2264 left_ml = g_strdup(ml_post);
2265 if (strstr(left_ml, "@")) {
2266 right_ml = strstr(left_ml, "@")+1;
2267 *(strstr(left_ml, "@")) = '\0';
2270 left_from = g_strdup(from);
2271 if (strstr(left_from, "@")) {
2272 right_from = strstr(left_from, "@")+1;
2273 *(strstr(left_from, "@")) = '\0';
2276 if (left_ml && left_from && right_ml && right_from
2277 && !strncmp(left_from, left_ml, strlen(left_ml))
2278 && !strcmp(right_from, right_ml)) {
2287 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2289 gchar *my_addr1, *my_addr2;
2291 if (!addr1 || !addr2)
2294 Xstrdup_a(my_addr1, addr1, return FALSE);
2295 Xstrdup_a(my_addr2, addr2, return FALSE);
2297 extract_address(my_addr1);
2298 extract_address(my_addr2);
2300 return !strcmp(my_addr1, my_addr2);
2303 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2304 gboolean to_all, gboolean to_ml,
2306 gboolean followup_and_reply_to)
2308 GSList *cc_list = NULL;
2311 gchar *replyto = NULL;
2312 GHashTable *to_table;
2314 gboolean reply_to_ml = FALSE;
2315 gboolean default_reply_to = FALSE;
2317 g_return_if_fail(compose->account != NULL);
2318 g_return_if_fail(msginfo != NULL);
2320 reply_to_ml = to_ml && compose->ml_post;
2322 default_reply_to = msginfo->folder &&
2323 msginfo->folder->prefs->enable_default_reply_to;
2325 if (compose->account->protocol != A_NNTP) {
2326 if (reply_to_ml && !default_reply_to) {
2328 gboolean is_subscr = is_subscription(compose->ml_post,
2331 /* normal answer to ml post with a reply-to */
2332 compose_entry_append(compose,
2335 if (compose->replyto
2336 && !same_address(compose->ml_post, compose->replyto))
2337 compose_entry_append(compose,
2341 /* answer to subscription confirmation */
2342 if (compose->replyto)
2343 compose_entry_append(compose,
2346 else if (msginfo->from)
2347 compose_entry_append(compose,
2352 else if (!(to_all || to_sender) && default_reply_to) {
2353 compose_entry_append(compose,
2354 msginfo->folder->prefs->default_reply_to,
2356 compose_entry_mark_default_to(compose,
2357 msginfo->folder->prefs->default_reply_to);
2360 Xstrdup_a(tmp1, msginfo->from, return);
2361 extract_address(tmp1);
2362 if (to_all || to_sender ||
2363 !account_find_from_address(tmp1))
2364 compose_entry_append(compose,
2365 (compose->replyto && !to_sender)
2366 ? compose->replyto :
2367 msginfo->from ? msginfo->from : "",
2369 else if (!to_all && !to_sender) {
2370 /* reply to the last list of recipients */
2371 compose_entry_append(compose,
2372 msginfo->to ? msginfo->to : "",
2374 compose_entry_append(compose,
2375 msginfo->cc ? msginfo->cc : "",
2380 if (to_sender || (compose->followup_to &&
2381 !strncmp(compose->followup_to, "poster", 6)))
2382 compose_entry_append
2384 (compose->replyto ? compose->replyto :
2385 msginfo->from ? msginfo->from : ""),
2388 else if (followup_and_reply_to || to_all) {
2389 compose_entry_append
2391 (compose->replyto ? compose->replyto :
2392 msginfo->from ? msginfo->from : ""),
2395 compose_entry_append
2397 compose->followup_to ? compose->followup_to :
2398 compose->newsgroups ? compose->newsgroups : "",
2399 COMPOSE_NEWSGROUPS);
2402 compose_entry_append
2404 compose->followup_to ? compose->followup_to :
2405 compose->newsgroups ? compose->newsgroups : "",
2406 COMPOSE_NEWSGROUPS);
2409 if (msginfo->subject && *msginfo->subject) {
2413 buf = p = g_strdup(msginfo->subject);
2414 p += subject_get_prefix_length(p);
2415 memmove(buf, p, strlen(p) + 1);
2417 buf2 = g_strdup_printf("Re: %s", buf);
2418 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2423 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2425 if (to_ml && compose->ml_post) return;
2426 if (!to_all || compose->account->protocol == A_NNTP) return;
2428 if (compose->replyto) {
2429 Xstrdup_a(replyto, compose->replyto, return);
2430 extract_address(replyto);
2432 if (msginfo->from) {
2433 Xstrdup_a(from, msginfo->from, return);
2434 extract_address(from);
2437 if (replyto && from)
2438 cc_list = address_list_append_with_comments(cc_list, from);
2439 if (to_all && msginfo->folder &&
2440 msginfo->folder->prefs->enable_default_reply_to)
2441 cc_list = address_list_append_with_comments(cc_list,
2442 msginfo->folder->prefs->default_reply_to);
2443 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2444 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2446 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2448 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2449 if (compose->account)
2450 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2451 GINT_TO_POINTER(1));
2453 /* remove address on To: and that of current account */
2454 for (cur = cc_list; cur != NULL; ) {
2455 GSList *next = cur->next;
2458 addr = g_strdup(cur->data);
2459 extract_address(addr);
2461 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2462 cc_list = g_slist_remove(cc_list, cur->data);
2464 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2468 hash_free_strings(to_table);
2469 g_hash_table_destroy(to_table);
2472 for (cur = cc_list; cur != NULL; cur = cur->next)
2473 compose_entry_append(compose, (gchar *)cur->data,
2475 slist_free_strings(cc_list);
2476 g_slist_free(cc_list);
2481 #define SET_ENTRY(entry, str) \
2484 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2487 #define SET_ADDRESS(type, str) \
2490 compose_entry_append(compose, str, type); \
2493 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2495 g_return_if_fail(msginfo != NULL);
2497 SET_ENTRY(subject_entry, msginfo->subject);
2498 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2499 SET_ADDRESS(COMPOSE_CC, compose->cc);
2500 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2501 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2502 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2503 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2505 compose_update_priority_menu_item(compose);
2506 compose_update_privacy_system_menu_item(compose, FALSE);
2507 compose_show_first_last_header(compose, TRUE);
2513 static void compose_insert_sig(Compose *compose, gboolean replace)
2515 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2516 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2518 GtkTextIter iter, iter_end;
2520 gboolean prev_autowrap;
2523 g_return_if_fail(compose->account != NULL);
2525 prev_autowrap = compose->autowrap;
2526 compose->autowrap = FALSE;
2528 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2529 G_CALLBACK(compose_changed_cb),
2532 mark = gtk_text_buffer_get_insert(buffer);
2533 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2534 cur_pos = gtk_text_iter_get_offset (&iter);
2536 gtk_text_buffer_get_end_iter(buffer, &iter);
2538 if (replace && compose->sig_str) {
2540 GtkTextIter first_iter, start_iter, end_iter;
2542 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2544 if (compose->sig_str[0] == '\0')
2547 found = gtk_text_iter_forward_search(&first_iter,
2549 GTK_TEXT_SEARCH_TEXT_ONLY,
2550 &start_iter, &end_iter,
2554 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2559 g_free(compose->sig_str);
2560 compose->sig_str = compose_get_signature_str(compose);
2561 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2562 compose->sig_str = g_strdup("");
2564 cur_pos = gtk_text_iter_get_offset(&iter);
2565 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2567 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2568 gtk_text_iter_forward_char(&iter);
2569 gtk_text_iter_forward_char(&iter);
2570 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2571 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2573 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2574 cur_pos = gtk_text_buffer_get_char_count (buffer);
2576 /* put the cursor where it should be
2577 * either where the quote_fmt says, either before the signature */
2578 if (compose->set_cursor_pos < 0)
2579 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2581 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2582 compose->set_cursor_pos);
2584 gtk_text_buffer_place_cursor(buffer, &iter);
2585 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2586 G_CALLBACK(compose_changed_cb),
2589 compose->autowrap = prev_autowrap;
2590 if (compose->autowrap)
2591 compose_wrap_all(compose);
2594 static gchar *compose_get_signature_str(Compose *compose)
2596 gchar *sig_body = NULL;
2597 gchar *sig_str = NULL;
2598 gchar *utf8_sig_str = NULL;
2600 g_return_val_if_fail(compose->account != NULL, NULL);
2602 if (!compose->account->sig_path)
2605 if (compose->account->sig_type == SIG_FILE) {
2606 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2607 g_warning("can't open signature file: %s\n",
2608 compose->account->sig_path);
2613 if (compose->account->sig_type == SIG_COMMAND)
2614 sig_body = get_command_output(compose->account->sig_path);
2618 tmp = file_read_to_str(compose->account->sig_path);
2621 sig_body = normalize_newlines(tmp);
2625 if (compose->account->sig_sep) {
2626 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2630 sig_str = g_strconcat("\n\n", sig_body, NULL);
2633 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2634 utf8_sig_str = sig_str;
2636 utf8_sig_str = conv_codeset_strdup
2637 (sig_str, conv_get_locale_charset_str(),
2643 return utf8_sig_str;
2646 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2649 GtkTextBuffer *buffer;
2652 const gchar *cur_encoding;
2653 gchar buf[BUFFSIZE];
2656 gboolean prev_autowrap;
2657 gboolean badtxt = FALSE;
2659 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2661 if ((fp = g_fopen(file, "rb")) == NULL) {
2662 FILE_OP_ERROR(file, "fopen");
2663 return COMPOSE_INSERT_READ_ERROR;
2666 prev_autowrap = compose->autowrap;
2667 compose->autowrap = FALSE;
2669 text = GTK_TEXT_VIEW(compose->text);
2670 buffer = gtk_text_view_get_buffer(text);
2671 mark = gtk_text_buffer_get_insert(buffer);
2672 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2674 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2675 G_CALLBACK(text_inserted),
2678 cur_encoding = conv_get_locale_charset_str();
2680 while (fgets(buf, sizeof(buf), fp) != NULL) {
2683 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2684 str = g_strdup(buf);
2686 str = conv_codeset_strdup
2687 (buf, cur_encoding, CS_INTERNAL);
2690 /* strip <CR> if DOS/Windows file,
2691 replace <CR> with <LF> if Macintosh file. */
2694 if (len > 0 && str[len - 1] != '\n') {
2696 if (str[len] == '\r') str[len] = '\n';
2699 gtk_text_buffer_insert(buffer, &iter, str, -1);
2703 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2704 G_CALLBACK(text_inserted),
2706 compose->autowrap = prev_autowrap;
2707 if (compose->autowrap)
2708 compose_wrap_all(compose);
2713 return COMPOSE_INSERT_INVALID_CHARACTER;
2715 return COMPOSE_INSERT_SUCCESS;
2718 static void compose_attach_append(Compose *compose, const gchar *file,
2719 const gchar *filename,
2720 const gchar *content_type)
2728 GtkListStore *store;
2731 if (!is_file_exist(file)) {
2732 g_warning("File %s doesn't exist\n", filename);
2735 if ((size = get_file_size(file)) < 0) {
2736 g_warning("Can't get file size of %s\n", filename);
2740 alertpanel_notice(_("File %s is empty."), filename);
2743 if ((fp = g_fopen(file, "rb")) == NULL) {
2744 alertpanel_error(_("Can't read %s."), filename);
2749 ainfo = g_new0(AttachInfo, 1);
2750 auto_ainfo = g_auto_pointer_new_with_free
2751 (ainfo, (GFreeFunc) compose_attach_info_free);
2752 ainfo->file = g_strdup(file);
2755 ainfo->content_type = g_strdup(content_type);
2756 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2758 MsgFlags flags = {0, 0};
2760 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2761 ainfo->encoding = ENC_7BIT;
2763 ainfo->encoding = ENC_8BIT;
2765 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2766 if (msginfo && msginfo->subject)
2767 name = g_strdup(msginfo->subject);
2769 name = g_path_get_basename(filename ? filename : file);
2771 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2773 procmsg_msginfo_free(msginfo);
2775 if (!g_ascii_strncasecmp(content_type, "text", 4))
2776 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2778 ainfo->encoding = ENC_BASE64;
2779 name = g_path_get_basename(filename ? filename : file);
2780 ainfo->name = g_strdup(name);
2784 ainfo->content_type = procmime_get_mime_type(file);
2785 if (!ainfo->content_type) {
2786 ainfo->content_type =
2787 g_strdup("application/octet-stream");
2788 ainfo->encoding = ENC_BASE64;
2789 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2791 procmime_get_encoding_for_text_file(file);
2793 ainfo->encoding = ENC_BASE64;
2794 name = g_path_get_basename(filename ? filename : file);
2795 ainfo->name = g_strdup(name);
2799 if (!strcmp(ainfo->content_type, "unknown")) {
2800 g_free(ainfo->content_type);
2801 ainfo->content_type = g_strdup("application/octet-stream");
2805 size_text = to_human_readable(size);
2807 store = GTK_LIST_STORE(gtk_tree_view_get_model
2808 (GTK_TREE_VIEW(compose->attach_clist)));
2810 gtk_list_store_append(store, &iter);
2811 gtk_list_store_set(store, &iter,
2812 COL_MIMETYPE, ainfo->content_type,
2813 COL_SIZE, size_text,
2814 COL_NAME, ainfo->name,
2816 COL_AUTODATA, auto_ainfo,
2819 g_auto_pointer_free(auto_ainfo);
2822 static void compose_use_signing(Compose *compose, gboolean use_signing)
2824 GtkItemFactory *ifactory;
2825 GtkWidget *menuitem = NULL;
2827 compose->use_signing = use_signing;
2828 ifactory = gtk_item_factory_from_widget(compose->menubar);
2829 menuitem = gtk_item_factory_get_item
2830 (ifactory, "/Options/Sign");
2831 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2835 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2837 GtkItemFactory *ifactory;
2838 GtkWidget *menuitem = NULL;
2840 compose->use_encryption = use_encryption;
2841 ifactory = gtk_item_factory_from_widget(compose->menubar);
2842 menuitem = gtk_item_factory_get_item
2843 (ifactory, "/Options/Encrypt");
2845 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2849 #define NEXT_PART_NOT_CHILD(info) \
2851 node = info->node; \
2852 while (node->children) \
2853 node = g_node_last_child(node); \
2854 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2857 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2861 MimeInfo *firsttext = NULL;
2862 MimeInfo *encrypted = NULL;
2865 const gchar *partname = NULL;
2867 mimeinfo = procmime_scan_message(msginfo);
2868 if (!mimeinfo) return;
2870 if (mimeinfo->node->children == NULL) {
2871 procmime_mimeinfo_free_all(mimeinfo);
2875 /* find first content part */
2876 child = (MimeInfo *) mimeinfo->node->children->data;
2877 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2878 child = (MimeInfo *)child->node->children->data;
2880 if (child->type == MIMETYPE_TEXT) {
2882 debug_print("First text part found\n");
2883 } else if (compose->mode == COMPOSE_REEDIT &&
2884 child->type == MIMETYPE_APPLICATION &&
2885 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2886 encrypted = (MimeInfo *)child->node->parent->data;
2889 child = (MimeInfo *) mimeinfo->node->children->data;
2890 while (child != NULL) {
2891 if (child == encrypted) {
2892 /* skip this part of tree */
2893 NEXT_PART_NOT_CHILD(child);
2897 if (child->type == MIMETYPE_MULTIPART) {
2898 /* get the actual content */
2899 child = procmime_mimeinfo_next(child);
2903 if (child == firsttext) {
2904 child = procmime_mimeinfo_next(child);
2908 outfile = procmime_get_tmp_file_name(child);
2909 if (procmime_get_part(outfile, child) < 0)
2910 g_warning("Can't get the part of multipart message.");
2912 gchar *content_type;
2914 content_type = procmime_get_content_type_str(child->type, child->subtype);
2916 /* if we meet a pgp signature, we don't attach it, but
2917 * we force signing. */
2918 if (strcmp(content_type, "application/pgp-signature")) {
2919 partname = procmime_mimeinfo_get_parameter(child, "filename");
2920 if (partname == NULL)
2921 partname = procmime_mimeinfo_get_parameter(child, "name");
2922 if (partname == NULL)
2924 compose_attach_append(compose, outfile,
2925 partname, content_type);
2927 compose_force_signing(compose, compose->account);
2929 g_free(content_type);
2932 NEXT_PART_NOT_CHILD(child);
2934 procmime_mimeinfo_free_all(mimeinfo);
2937 #undef NEXT_PART_NOT_CHILD
2942 WAIT_FOR_INDENT_CHAR,
2943 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2946 /* return indent length, we allow:
2947 indent characters followed by indent characters or spaces/tabs,
2948 alphabets and numbers immediately followed by indent characters,
2949 and the repeating sequences of the above
2950 If quote ends with multiple spaces, only the first one is included. */
2951 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2952 const GtkTextIter *start, gint *len)
2954 GtkTextIter iter = *start;
2958 IndentState state = WAIT_FOR_INDENT_CHAR;
2961 gint alnum_count = 0;
2962 gint space_count = 0;
2965 if (prefs_common.quote_chars == NULL) {
2969 while (!gtk_text_iter_ends_line(&iter)) {
2970 wc = gtk_text_iter_get_char(&iter);
2971 if (g_unichar_iswide(wc))
2973 clen = g_unichar_to_utf8(wc, ch);
2977 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2978 is_space = g_unichar_isspace(wc);
2980 if (state == WAIT_FOR_INDENT_CHAR) {
2981 if (!is_indent && !g_unichar_isalnum(wc))
2984 quote_len += alnum_count + space_count + 1;
2985 alnum_count = space_count = 0;
2986 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2989 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2990 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
2994 else if (is_indent) {
2995 quote_len += alnum_count + space_count + 1;
2996 alnum_count = space_count = 0;
2999 state = WAIT_FOR_INDENT_CHAR;
3003 gtk_text_iter_forward_char(&iter);
3006 if (quote_len > 0 && space_count > 0)
3012 if (quote_len > 0) {
3014 gtk_text_iter_forward_chars(&iter, quote_len);
3015 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3021 /* return TRUE if the line is itemized */
3022 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3023 const GtkTextIter *start)
3025 GtkTextIter iter = *start;
3030 if (gtk_text_iter_ends_line(&iter))
3034 wc = gtk_text_iter_get_char(&iter);
3035 if (!g_unichar_isspace(wc))
3037 gtk_text_iter_forward_char(&iter);
3038 if (gtk_text_iter_ends_line(&iter))
3042 clen = g_unichar_to_utf8(wc, ch);
3046 if (!strchr("*-+", ch[0]))
3049 gtk_text_iter_forward_char(&iter);
3050 if (gtk_text_iter_ends_line(&iter))
3052 wc = gtk_text_iter_get_char(&iter);
3053 if (g_unichar_isspace(wc))
3059 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3060 const GtkTextIter *start,
3061 GtkTextIter *break_pos,
3065 GtkTextIter iter = *start, line_end = *start;
3066 PangoLogAttr *attrs;
3073 gboolean can_break = FALSE;
3074 gboolean do_break = FALSE;
3075 gboolean was_white = FALSE;
3076 gboolean prev_dont_break = FALSE;
3078 gtk_text_iter_forward_to_line_end(&line_end);
3079 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3080 len = g_utf8_strlen(str, -1);
3081 /* g_print("breaking line: %d: %s (len = %d)\n",
3082 gtk_text_iter_get_line(&iter), str, len); */
3083 attrs = g_new(PangoLogAttr, len + 1);
3085 pango_default_break(str, -1, NULL, attrs, len + 1);
3089 /* skip quote and leading spaces */
3090 for (i = 0; *p != '\0' && i < len; i++) {
3093 wc = g_utf8_get_char(p);
3094 if (i >= quote_len && !g_unichar_isspace(wc))
3096 if (g_unichar_iswide(wc))
3098 else if (*p == '\t')
3102 p = g_utf8_next_char(p);
3105 for (; *p != '\0' && i < len; i++) {
3106 PangoLogAttr *attr = attrs + i;
3110 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3113 was_white = attr->is_white;
3115 /* don't wrap URI */
3116 if ((uri_len = get_uri_len(p)) > 0) {
3118 if (pos > 0 && col > max_col) {
3128 wc = g_utf8_get_char(p);
3129 if (g_unichar_iswide(wc)) {
3131 if (prev_dont_break && can_break && attr->is_line_break)
3133 } else if (*p == '\t')
3137 if (pos > 0 && col > max_col) {
3142 if (*p == '-' || *p == '/')
3143 prev_dont_break = TRUE;
3145 prev_dont_break = FALSE;
3147 p = g_utf8_next_char(p);
3151 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3156 *break_pos = *start;
3157 gtk_text_iter_set_line_offset(break_pos, pos);
3162 static gboolean compose_join_next_line(Compose *compose,
3163 GtkTextBuffer *buffer,
3165 const gchar *quote_str)
3167 GtkTextIter iter_ = *iter, cur, prev, next, end;
3168 PangoLogAttr attrs[3];
3170 gchar *next_quote_str;
3173 gboolean keep_cursor = FALSE;
3175 if (!gtk_text_iter_forward_line(&iter_) ||
3176 gtk_text_iter_ends_line(&iter_))
3179 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3181 if ((quote_str || next_quote_str) &&
3182 strcmp2(quote_str, next_quote_str) != 0) {
3183 g_free(next_quote_str);
3186 g_free(next_quote_str);
3189 if (quote_len > 0) {
3190 gtk_text_iter_forward_chars(&end, quote_len);
3191 if (gtk_text_iter_ends_line(&end))
3195 /* don't join itemized lines */
3196 if (compose_is_itemized(buffer, &end))
3199 /* don't join signature separator */
3200 if (compose_is_sig_separator(compose, buffer, &iter_))
3203 /* delete quote str */
3205 gtk_text_buffer_delete(buffer, &iter_, &end);
3207 /* don't join line breaks put by the user */
3209 gtk_text_iter_backward_char(&cur);
3210 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3211 gtk_text_iter_forward_char(&cur);
3215 gtk_text_iter_forward_char(&cur);
3216 /* delete linebreak and extra spaces */
3217 while (gtk_text_iter_backward_char(&cur)) {
3218 wc1 = gtk_text_iter_get_char(&cur);
3219 if (!g_unichar_isspace(wc1))
3224 while (!gtk_text_iter_ends_line(&cur)) {
3225 wc1 = gtk_text_iter_get_char(&cur);
3226 if (!g_unichar_isspace(wc1))
3228 gtk_text_iter_forward_char(&cur);
3231 if (!gtk_text_iter_equal(&prev, &next)) {
3234 mark = gtk_text_buffer_get_insert(buffer);
3235 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3236 if (gtk_text_iter_equal(&prev, &cur))
3238 gtk_text_buffer_delete(buffer, &prev, &next);
3242 /* insert space if required */
3243 gtk_text_iter_backward_char(&prev);
3244 wc1 = gtk_text_iter_get_char(&prev);
3245 wc2 = gtk_text_iter_get_char(&next);
3246 gtk_text_iter_forward_char(&next);
3247 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3248 pango_default_break(str, -1, NULL, attrs, 3);
3249 if (!attrs[1].is_line_break ||
3250 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3251 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3253 gtk_text_iter_backward_char(&iter_);
3254 gtk_text_buffer_place_cursor(buffer, &iter_);
3263 #define ADD_TXT_POS(bp_, ep_, pti_) \
3264 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3265 last = last->next; \
3266 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3267 last->next = NULL; \
3269 g_warning("alloc error scanning URIs\n"); \
3272 static gboolean automatic_break = FALSE;
3273 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3275 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3276 GtkTextBuffer *buffer;
3277 GtkTextIter iter, break_pos, end_of_line;
3278 gchar *quote_str = NULL;
3280 gboolean wrap_quote = prefs_common.linewrap_quote;
3281 gboolean prev_autowrap = compose->autowrap;
3282 gint startq_offset = -1, noq_offset = -1;
3283 gint uri_start = -1, uri_stop = -1;
3284 gint nouri_start = -1, nouri_stop = -1;
3285 gint num_blocks = 0;
3287 compose->autowrap = FALSE;
3289 buffer = gtk_text_view_get_buffer(text);
3290 undo_wrapping(compose->undostruct, TRUE);
3295 mark = gtk_text_buffer_get_insert(buffer);
3296 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3299 /* move to paragraph start */
3300 gtk_text_iter_set_line_offset(&iter, 0);
3301 if (gtk_text_iter_ends_line(&iter)) {
3302 while (gtk_text_iter_ends_line(&iter) &&
3303 gtk_text_iter_forward_line(&iter))
3306 while (gtk_text_iter_backward_line(&iter)) {
3307 if (gtk_text_iter_ends_line(&iter)) {
3308 gtk_text_iter_forward_line(&iter);
3314 /* go until paragraph end (empty line) */
3316 while (!gtk_text_iter_ends_line(&iter)) {
3317 gchar *scanpos = NULL;
3318 /* parse table - in order of priority */
3320 const gchar *needle; /* token */
3322 /* token search function */
3323 gchar *(*search) (const gchar *haystack,
3324 const gchar *needle);
3325 /* part parsing function */
3326 gboolean (*parse) (const gchar *start,
3327 const gchar *scanpos,
3331 /* part to URI function */
3332 gchar *(*build_uri) (const gchar *bp,
3336 static struct table parser[] = {
3337 {"http://", strcasestr, get_uri_part, make_uri_string},
3338 {"https://", strcasestr, get_uri_part, make_uri_string},
3339 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3340 {"www.", strcasestr, get_uri_part, make_http_string},
3341 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3342 {"@", strcasestr, get_email_part, make_email_string}
3344 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3345 gint last_index = PARSE_ELEMS;
3347 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3350 if (!prev_autowrap && num_blocks == 0) {
3352 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3353 G_CALLBACK(text_inserted),
3356 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3359 uri_start = uri_stop = -1;
3361 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3365 if (startq_offset == -1) {
3366 startq_offset = gtk_text_iter_get_offset(&iter);
3370 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3371 if (startq_offset == -1)
3372 startq_offset = gtk_text_iter_get_offset(&iter);
3374 if (startq_offset == -1)
3375 noq_offset = gtk_text_iter_get_offset(&iter);
3378 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3381 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3382 prefs_common.linewrap_len,
3384 GtkTextIter prev, next, cur;
3386 if (prev_autowrap != FALSE || force) {
3387 automatic_break = TRUE;
3388 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3389 automatic_break = FALSE;
3390 } else if (quote_str && wrap_quote) {
3391 automatic_break = TRUE;
3392 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3393 automatic_break = FALSE;
3396 /* remove trailing spaces */
3398 gtk_text_iter_backward_char(&cur);
3400 while (!gtk_text_iter_starts_line(&cur)) {
3403 gtk_text_iter_backward_char(&cur);
3404 wc = gtk_text_iter_get_char(&cur);
3405 if (!g_unichar_isspace(wc))
3409 if (!gtk_text_iter_equal(&prev, &next)) {
3410 gtk_text_buffer_delete(buffer, &prev, &next);
3412 gtk_text_iter_forward_char(&break_pos);
3416 gtk_text_buffer_insert(buffer, &break_pos,
3420 compose_join_next_line(compose, buffer, &iter, quote_str);
3422 /* move iter to current line start */
3423 gtk_text_iter_set_line_offset(&iter, 0);
3430 /* move iter to next line start */
3435 if (!prev_autowrap) {
3436 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3437 G_CALLBACK(text_inserted),
3441 while (!gtk_text_iter_ends_line(&end_of_line)) {
3442 gtk_text_iter_forward_char(&end_of_line);
3444 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3446 nouri_start = gtk_text_iter_get_offset(&iter);
3447 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3449 walk_pos = gtk_text_iter_get_offset(&iter);
3450 /* FIXME: this looks phony. scanning for anything in the parse table */
3451 for (n = 0; n < PARSE_ELEMS; n++) {
3454 tmp = parser[n].search(walk, parser[n].needle);
3456 if (scanpos == NULL || tmp < scanpos) {
3465 /* check if URI can be parsed */
3466 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3467 (const gchar **)&ep, FALSE)
3468 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3472 strlen(parser[last_index].needle);
3475 uri_start = walk_pos + (bp - o_walk);
3476 uri_stop = walk_pos + (ep - o_walk);
3480 gtk_text_iter_forward_line(&iter);
3483 if (startq_offset != -1) {
3484 GtkTextIter startquote, endquote;
3485 gtk_text_buffer_get_iter_at_offset(
3486 buffer, &startquote, startq_offset);
3488 gtk_text_buffer_apply_tag_by_name(
3489 buffer, "quote", &startquote, &endquote);
3491 } else if (noq_offset != -1) {
3492 GtkTextIter startnoquote, endnoquote;
3493 gtk_text_buffer_get_iter_at_offset(
3494 buffer, &startnoquote, noq_offset);
3496 gtk_text_buffer_remove_tag_by_name(
3497 buffer, "quote", &startnoquote, &endnoquote);
3502 GtkTextIter nouri_start_iter, nouri_end_iter;
3503 gtk_text_buffer_get_iter_at_offset(
3504 buffer, &nouri_start_iter, nouri_start);
3505 gtk_text_buffer_get_iter_at_offset(
3506 buffer, &nouri_end_iter, nouri_stop);
3507 gtk_text_buffer_remove_tag_by_name(
3508 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3510 if (uri_start > 0 && uri_stop > 0) {
3511 GtkTextIter uri_start_iter, uri_end_iter;
3512 gtk_text_buffer_get_iter_at_offset(
3513 buffer, &uri_start_iter, uri_start);
3514 gtk_text_buffer_get_iter_at_offset(
3515 buffer, &uri_end_iter, uri_stop);
3516 gtk_text_buffer_apply_tag_by_name(
3517 buffer, "link", &uri_start_iter, &uri_end_iter);
3523 undo_wrapping(compose->undostruct, FALSE);
3524 compose->autowrap = prev_autowrap;
3527 void compose_action_cb(void *data)
3529 Compose *compose = (Compose *)data;
3530 compose_wrap_all(compose);
3533 static void compose_wrap_all(Compose *compose)
3535 compose_wrap_all_full(compose, FALSE);
3538 static void compose_wrap_all_full(Compose *compose, gboolean force)
3540 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3541 GtkTextBuffer *buffer;
3544 buffer = gtk_text_view_get_buffer(text);
3546 gtk_text_buffer_get_start_iter(buffer, &iter);
3547 while (!gtk_text_iter_is_end(&iter))
3548 compose_beautify_paragraph(compose, &iter, force);
3552 static void compose_set_title(Compose *compose)
3558 edited = compose->modified ? _(" [Edited]") : "";
3560 subject = gtk_editable_get_chars(
3561 GTK_EDITABLE(compose->subject_entry), 0, -1);
3563 if (subject && strlen(subject))
3564 str = g_strdup_printf(_("%s - Compose message%s"),
3567 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3568 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3574 * compose_current_mail_account:
3576 * Find a current mail account (the currently selected account, or the
3577 * default account, if a news account is currently selected). If a
3578 * mail account cannot be found, display an error message.
3580 * Return value: Mail account, or NULL if not found.
3582 static PrefsAccount *
3583 compose_current_mail_account(void)
3587 if (cur_account && cur_account->protocol != A_NNTP)
3590 ac = account_get_default();
3591 if (!ac || ac->protocol == A_NNTP) {
3592 alertpanel_error(_("Account for sending mail is not specified.\n"
3593 "Please select a mail account before sending."));
3600 static void compose_select_account(Compose *compose, PrefsAccount *account,
3603 GtkItemFactory *ifactory;
3605 g_return_if_fail(account != NULL);
3607 compose->account = account;
3609 compose_set_title(compose);
3611 ifactory = gtk_item_factory_from_widget(compose->menubar);
3613 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3614 menu_set_active(ifactory, "/Options/Sign", TRUE);
3616 menu_set_active(ifactory, "/Options/Sign", FALSE);
3617 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3618 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3620 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3622 activate_privacy_system(compose, account, FALSE);
3624 if (!init && compose->mode != COMPOSE_REDIRECT)
3625 compose_insert_sig(compose, TRUE);
3628 gboolean compose_check_for_valid_recipient(Compose *compose) {
3629 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3630 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3631 gboolean recipient_found = FALSE;
3635 /* free to and newsgroup list */
3636 slist_free_strings(compose->to_list);
3637 g_slist_free(compose->to_list);
3638 compose->to_list = NULL;
3640 slist_free_strings(compose->newsgroup_list);
3641 g_slist_free(compose->newsgroup_list);
3642 compose->newsgroup_list = NULL;
3644 /* search header entries for to and newsgroup entries */
3645 for (list = compose->header_list; list; list = list->next) {
3648 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3649 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3651 if (entry[0] != '\0') {
3652 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3653 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3654 compose->to_list = address_list_append(compose->to_list, entry);
3655 recipient_found = TRUE;
3658 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3659 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3660 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3661 recipient_found = TRUE;
3668 return recipient_found;
3671 static gboolean compose_check_for_set_recipients(Compose *compose)
3673 if (compose->account->set_autocc && compose->account->auto_cc) {
3674 gboolean found_other = FALSE;
3676 /* search header entries for to and newsgroup entries */
3677 for (list = compose->header_list; list; list = list->next) {
3680 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3681 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3683 if (strcmp(entry, compose->account->auto_cc)
3684 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3694 aval = alertpanel(_("Send"),
3695 _("The only recipient is the default CC address. Send anyway?"),
3696 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3697 if (aval != G_ALERTALTERNATE)
3701 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3702 gboolean found_other = FALSE;
3704 /* search header entries for to and newsgroup entries */
3705 for (list = compose->header_list; list; list = list->next) {
3708 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3709 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3711 if (strcmp(entry, compose->account->auto_cc)
3712 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3722 aval = alertpanel(_("Send"),
3723 _("The only recipient is the default BCC address. Send anyway?"),
3724 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3725 if (aval != G_ALERTALTERNATE)
3732 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3736 if (compose_check_for_valid_recipient(compose) == FALSE) {
3737 alertpanel_error(_("Recipient is not specified."));
3741 if (compose_check_for_set_recipients(compose) == FALSE) {
3745 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3746 if (*str == '\0' && check_subject == TRUE) {
3749 aval = alertpanel(_("Send"),
3750 _("Subject is empty. Send it anyway?"),
3751 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3752 if (aval != G_ALERTALTERNATE)
3759 gint compose_send(Compose *compose)
3766 compose_allow_user_actions (compose, FALSE);
3767 compose->sending = TRUE;
3769 if (compose_check_entries(compose, TRUE) == FALSE)
3772 val = compose_queue(compose, &msgnum, &folder);
3776 alertpanel_error(_("Could not queue message for sending:\n\n"
3777 "Charset conversion failed."));
3778 } else if (val == -3) {
3779 alertpanel_error(_("Could not queue message for sending:\n\n"
3780 "Signature failed."));
3781 } else if (val == -2 && errno != 0) {
3782 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3784 alertpanel_error(_("Could not queue message for sending."));
3790 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3791 compose->sending = FALSE;
3792 compose_close(compose);
3793 /* No more compose access in the normal codepath
3794 * after this point! */
3799 alertpanel_error(_("The message was queued but could not be "
3800 "sent.\nUse \"Send queued messages\" from "
3801 "the main window to retry."));
3802 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3803 compose->sending = FALSE;
3804 compose->modified = TRUE;
3805 compose_allow_user_actions (compose, TRUE);
3810 msgpath = folder_item_fetch_msg(folder, msgnum);
3811 val = procmsg_send_message_queue(msgpath);
3814 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3815 compose->sending = FALSE;
3816 compose_allow_user_actions (compose, TRUE);
3818 folder_item_remove_msg(folder, msgnum);
3819 folder_item_scan(folder);
3824 folder_item_remove_msg(folder, msgnum);
3825 folder_item_scan(folder);
3826 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3827 compose_close(compose);
3829 alertpanel_error(_("The message was queued but could not be "
3830 "sent.\nUse \"Send queued messages\" from "
3831 "the main window to retry."));
3832 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3833 compose_allow_user_actions (compose, TRUE);
3834 compose->modified = TRUE;
3835 compose->sending = FALSE;
3843 compose_allow_user_actions (compose, TRUE);
3844 compose->sending = FALSE;
3845 compose->modified = TRUE;
3850 static gboolean compose_use_attach(Compose *compose)
3852 GtkTreeModel *model = gtk_tree_view_get_model
3853 (GTK_TREE_VIEW(compose->attach_clist));
3854 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3857 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3860 gchar buf[BUFFSIZE];
3862 gboolean first_to_address;
3863 gboolean first_cc_address;
3865 ComposeHeaderEntry *headerentry;
3866 const gchar *headerentryname;
3870 debug_print("Writing redirect header\n");
3872 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3873 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3875 first_to_address = TRUE;
3876 for (list = compose->header_list; list; list = list->next) {
3877 headerentry = ((ComposeHeaderEntry *)list->data);
3878 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3880 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3881 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3882 Xstrdup_a(str, entstr, return -1);
3884 if (str[0] != '\0') {
3885 compose_convert_header
3886 (compose, buf, sizeof(buf), str,
3887 strlen("Resent-To") + 2, TRUE);
3889 if (first_to_address) {
3890 fprintf(fp, "Resent-To: ");
3891 first_to_address = FALSE;
3895 fprintf(fp, "%s", buf);
3899 if (!first_to_address) {
3903 first_cc_address = TRUE;
3904 for (list = compose->header_list; list; list = list->next) {
3905 headerentry = ((ComposeHeaderEntry *)list->data);
3906 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3908 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3909 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3910 Xstrdup_a(str, strg, return -1);
3912 if (str[0] != '\0') {
3913 compose_convert_header
3914 (compose, buf, sizeof(buf), str,
3915 strlen("Resent-Cc") + 2, TRUE);
3917 if (first_cc_address) {
3918 fprintf(fp, "Resent-Cc: ");
3919 first_cc_address = FALSE;
3923 fprintf(fp, "%s", buf);
3927 if (!first_cc_address) {
3934 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3936 gchar buf[BUFFSIZE];
3938 const gchar *entstr;
3939 /* struct utsname utsbuf; */
3941 g_return_val_if_fail(fp != NULL, -1);
3942 g_return_val_if_fail(compose->account != NULL, -1);
3943 g_return_val_if_fail(compose->account->address != NULL, -1);
3946 get_rfc822_date(buf, sizeof(buf));
3947 fprintf(fp, "Resent-Date: %s\n", buf);
3950 if (compose->account->name && *compose->account->name) {
3951 compose_convert_header
3952 (compose, buf, sizeof(buf), compose->account->name,
3953 strlen("From: "), TRUE);
3954 fprintf(fp, "Resent-From: %s <%s>\n",
3955 buf, compose->account->address);
3957 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3960 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3961 if (*entstr != '\0') {
3962 Xstrdup_a(str, entstr, return -1);
3965 compose_convert_header(compose, buf, sizeof(buf), str,
3966 strlen("Subject: "), FALSE);
3967 fprintf(fp, "Subject: %s\n", buf);
3971 /* Resent-Message-ID */
3972 if (compose->account->gen_msgid) {
3973 generate_msgid(buf, sizeof(buf));
3974 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3975 compose->msgid = g_strdup(buf);
3978 compose_redirect_write_headers_from_headerlist(compose, fp);
3980 /* separator between header and body */
3986 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3990 gchar buf[BUFFSIZE];
3992 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
3993 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3997 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3998 /* should filter returnpath, delivered-to */
3999 if (g_ascii_strncasecmp(buf, "Return-Path:",
4000 strlen("Return-Path:")) == 0 ||
4001 g_ascii_strncasecmp(buf, "Delivered-To:",
4002 strlen("Delivered-To:")) == 0 ||
4003 g_ascii_strncasecmp(buf, "Received:",
4004 strlen("Received:")) == 0 ||
4005 g_ascii_strncasecmp(buf, "Subject:",
4006 strlen("Subject:")) == 0 ||
4007 g_ascii_strncasecmp(buf, "X-UIDL:",
4008 strlen("X-UIDL:")) == 0)
4011 if (fputs(buf, fdest) == -1)
4014 if (!prefs_common.redirect_keep_from) {
4015 if (g_ascii_strncasecmp(buf, "From:",
4016 strlen("From:")) == 0) {
4017 fputs(" (by way of ", fdest);
4018 if (compose->account->name
4019 && *compose->account->name) {
4020 compose_convert_header
4021 (compose, buf, sizeof(buf),
4022 compose->account->name,
4025 fprintf(fdest, "%s <%s>",
4027 compose->account->address);
4029 fprintf(fdest, "%s",
4030 compose->account->address);
4035 if (fputs("\n", fdest) == -1)
4039 compose_redirect_write_headers(compose, fdest);
4041 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4042 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4055 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
4057 GtkTextBuffer *buffer;
4058 GtkTextIter start, end;
4061 const gchar *out_codeset;
4062 EncodingType encoding;
4063 MimeInfo *mimemsg, *mimetext;
4066 /* create message MimeInfo */
4067 mimemsg = procmime_mimeinfo_new();
4068 mimemsg->type = MIMETYPE_MESSAGE;
4069 mimemsg->subtype = g_strdup("rfc822");
4070 mimemsg->content = MIMECONTENT_MEM;
4071 mimemsg->tmp = TRUE; /* must free content later */
4072 mimemsg->data.mem = compose_get_header(compose);
4074 /* Create text part MimeInfo */
4075 /* get all composed text */
4076 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4077 gtk_text_buffer_get_start_iter(buffer, &start);
4078 gtk_text_buffer_get_end_iter(buffer, &end);
4079 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4080 if (is_ascii_str(chars)) {
4083 out_codeset = CS_US_ASCII;
4084 encoding = ENC_7BIT;
4086 const gchar *src_codeset = CS_INTERNAL;
4088 out_codeset = conv_get_charset_str(compose->out_encoding);
4091 gchar *test_conv_global_out = NULL;
4092 gchar *test_conv_reply = NULL;
4094 /* automatic mode. be automatic. */
4095 codeconv_set_strict(TRUE);
4097 out_codeset = conv_get_outgoing_charset_str();
4099 debug_print("trying to convert to %s\n", out_codeset);
4100 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4103 if (!test_conv_global_out && compose->orig_charset
4104 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4105 out_codeset = compose->orig_charset;
4106 debug_print("failure; trying to convert to %s\n", out_codeset);
4107 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4110 if (!test_conv_global_out && !test_conv_reply) {
4112 out_codeset = CS_INTERNAL;
4113 debug_print("failure; finally using %s\n", out_codeset);
4115 g_free(test_conv_global_out);
4116 g_free(test_conv_reply);
4117 codeconv_set_strict(FALSE);
4120 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4121 out_codeset = CS_ISO_8859_1;
4123 if (prefs_common.encoding_method == CTE_BASE64)
4124 encoding = ENC_BASE64;
4125 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4126 encoding = ENC_QUOTED_PRINTABLE;
4127 else if (prefs_common.encoding_method == CTE_8BIT)
4128 encoding = ENC_8BIT;
4130 encoding = procmime_get_encoding_for_charset(out_codeset);
4132 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4133 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4135 if (action == COMPOSE_WRITE_FOR_SEND) {
4136 codeconv_set_strict(TRUE);
4137 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4138 codeconv_set_strict(FALSE);
4144 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4145 "to the specified %s charset.\n"
4146 "Send it as %s?"), out_codeset, src_codeset);
4147 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4148 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4151 if (aval != G_ALERTALTERNATE) {
4156 out_codeset = src_codeset;
4162 out_codeset = src_codeset;
4168 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4169 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4170 strstr(buf, "\nFrom ") != NULL) {
4171 encoding = ENC_QUOTED_PRINTABLE;
4175 mimetext = procmime_mimeinfo_new();
4176 mimetext->content = MIMECONTENT_MEM;
4177 mimetext->tmp = TRUE; /* must free content later */
4178 mimetext->data.mem = buf;
4179 mimetext->type = MIMETYPE_TEXT;
4180 mimetext->subtype = g_strdup("plain");
4181 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4182 g_strdup(out_codeset));
4183 /* protect trailing spaces when signing message */
4184 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4185 privacy_system_can_sign(compose->privacy_system)) {
4186 encoding = ENC_QUOTED_PRINTABLE;
4189 /* check for line length limit */
4190 if (action == COMPOSE_WRITE_FOR_SEND &&
4191 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4192 check_line_length(buf, 1000, &line) < 0) {
4196 msg = g_strdup_printf
4197 (_("Line %d exceeds the line length limit (998 bytes).\n"
4198 "The contents of the message might be broken on the way to the delivery.\n"
4200 "Send it anyway?"), line + 1);
4201 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4203 if (aval != G_ALERTALTERNATE) {
4208 if (encoding != ENC_UNKNOWN)
4209 procmime_encode_content(mimetext, encoding);
4211 /* append attachment parts */
4212 if (compose_use_attach(compose)) {
4213 MimeInfo *mimempart;
4214 gchar *boundary = NULL;
4215 mimempart = procmime_mimeinfo_new();
4216 mimempart->content = MIMECONTENT_EMPTY;
4217 mimempart->type = MIMETYPE_MULTIPART;
4218 mimempart->subtype = g_strdup("mixed");
4223 boundary = generate_mime_boundary(NULL);
4224 } while (strstr(buf, boundary) != NULL);
4226 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4229 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4231 g_node_append(mimempart->node, mimetext->node);
4232 g_node_append(mimemsg->node, mimempart->node);
4234 compose_add_attachments(compose, mimempart);
4236 g_node_append(mimemsg->node, mimetext->node);
4238 /* sign message if sending */
4239 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4240 privacy_system_can_sign(compose->privacy_system))
4241 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4244 procmime_write_mimeinfo(mimemsg, fp);
4246 procmime_mimeinfo_free_all(mimemsg);
4251 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4253 GtkTextBuffer *buffer;
4254 GtkTextIter start, end;
4259 if ((fp = g_fopen(file, "wb")) == NULL) {
4260 FILE_OP_ERROR(file, "fopen");
4264 /* chmod for security */
4265 if (change_file_mode_rw(fp, file) < 0) {
4266 FILE_OP_ERROR(file, "chmod");
4267 g_warning("can't change file mode\n");
4270 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4271 gtk_text_buffer_get_start_iter(buffer, &start);
4272 gtk_text_buffer_get_end_iter(buffer, &end);
4273 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4275 chars = conv_codeset_strdup
4276 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4279 if (!chars) return -1;
4282 len = strlen(chars);
4283 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4284 FILE_OP_ERROR(file, "fwrite");
4293 if (fclose(fp) == EOF) {
4294 FILE_OP_ERROR(file, "fclose");
4301 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4304 MsgInfo *msginfo = compose->targetinfo;
4306 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4307 if (!msginfo) return -1;
4309 if (!force && MSG_IS_LOCKED(msginfo->flags))
4312 item = msginfo->folder;
4313 g_return_val_if_fail(item != NULL, -1);
4315 if (procmsg_msg_exist(msginfo) &&
4316 (folder_has_parent_of_type(item, F_QUEUE) ||
4317 folder_has_parent_of_type(item, F_DRAFT)
4318 || msginfo == compose->autosaved_draft)) {
4319 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4320 g_warning("can't remove the old message\n");
4328 void compose_remove_draft(Compose *compose)
4331 MsgInfo *msginfo = compose->targetinfo;
4332 drafts = account_get_special_folder(compose->account, F_DRAFT);
4334 if (procmsg_msg_exist(msginfo)) {
4335 folder_item_remove_msg(drafts, msginfo->msgnum);
4340 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
4342 return compose_queue_sub (compose, msgnum, item, FALSE);
4344 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
4351 static gboolean lock = FALSE;
4352 PrefsAccount *mailac = NULL, *newsac = NULL;
4354 debug_print("queueing message...\n");
4355 g_return_val_if_fail(compose->account != NULL, -1);
4359 if (compose_check_entries(compose, check_subject) == FALSE) {
4364 if (!compose->to_list && !compose->newsgroup_list) {
4365 g_warning("can't get recipient list.");
4370 if (compose->to_list) {
4371 if (compose->account->protocol != A_NNTP)
4372 mailac = compose->account;
4373 else if (cur_account && cur_account->protocol != A_NNTP)
4374 mailac = cur_account;
4375 else if (!(mailac = compose_current_mail_account())) {
4377 alertpanel_error(_("No account for sending mails available!"));
4382 if (compose->newsgroup_list) {
4383 if (compose->account->protocol == A_NNTP)
4384 newsac = compose->account;
4385 else if (!newsac->protocol != A_NNTP) {
4387 alertpanel_error(_("No account for posting news available!"));
4392 /* write queue header */
4393 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4394 G_DIR_SEPARATOR, compose);
4395 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4396 FILE_OP_ERROR(tmp, "fopen");
4401 if (change_file_mode_rw(fp, tmp) < 0) {
4402 FILE_OP_ERROR(tmp, "chmod");
4403 g_warning("can't change file mode\n");
4406 /* queueing variables */
4407 fprintf(fp, "AF:\n");
4408 fprintf(fp, "NF:0\n");
4409 fprintf(fp, "PS:10\n");
4410 fprintf(fp, "SRH:1\n");
4411 fprintf(fp, "SFN:\n");
4412 fprintf(fp, "DSR:\n");
4414 fprintf(fp, "MID:<%s>\n", compose->msgid);
4416 fprintf(fp, "MID:\n");
4417 fprintf(fp, "CFG:\n");
4418 fprintf(fp, "PT:0\n");
4419 fprintf(fp, "S:%s\n", compose->account->address);
4420 fprintf(fp, "RQ:\n");
4422 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4424 fprintf(fp, "SSV:\n");
4426 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4428 fprintf(fp, "NSV:\n");
4429 fprintf(fp, "SSH:\n");
4430 /* write recepient list */
4431 if (compose->to_list) {
4432 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4433 for (cur = compose->to_list->next; cur != NULL;
4435 fprintf(fp, ",<%s>", (gchar *)cur->data);
4438 /* write newsgroup list */
4439 if (compose->newsgroup_list) {
4441 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4442 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4443 fprintf(fp, ",%s", (gchar *)cur->data);
4446 /* Sylpheed account IDs */
4448 fprintf(fp, "MAID:%d\n", mailac->account_id);
4450 fprintf(fp, "NAID:%d\n", newsac->account_id);
4452 if (compose->privacy_system != NULL) {
4453 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4454 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4455 if (compose->use_encryption) {
4458 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4459 if (encdata != NULL) {
4460 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4461 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4462 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4464 } /* else we finally dont want to encrypt */
4466 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4467 /* and if encdata was null, it means there's been a problem in
4474 /* Save copy folder */
4475 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4476 gchar *savefolderid;
4478 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4479 fprintf(fp, "SCF:%s\n", savefolderid);
4480 g_free(savefolderid);
4482 /* Save copy folder */
4483 if (compose->return_receipt) {
4484 fprintf(fp, "RRCPT:1\n");
4486 /* Message-ID of message replying to */
4487 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4490 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4491 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4494 /* Message-ID of message forwarding to */
4495 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4498 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4499 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4504 if (compose->redirect_filename != NULL) {
4505 if (compose_redirect_write_to_file(compose, fp) < 0) {
4514 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4519 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4523 if (fclose(fp) == EOF) {
4524 FILE_OP_ERROR(tmp, "fclose");
4530 queue = account_get_special_folder(compose->account, F_QUEUE);
4532 g_warning("can't find queue folder\n");
4537 folder_item_scan(queue);
4538 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
4539 g_warning("can't queue the message\n");
4547 if (compose->mode == COMPOSE_REEDIT) {
4548 compose_remove_reedit_target(compose, FALSE);
4551 if ((msgnum != NULL) && (item != NULL)) {
4559 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4562 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4564 struct stat statbuf;
4565 gchar *type, *subtype;
4566 GtkTreeModel *model;
4569 model = gtk_tree_view_get_model(tree_view);
4571 if (!gtk_tree_model_get_iter_first(model, &iter))
4574 gtk_tree_model_get(model, &iter,
4578 mimepart = procmime_mimeinfo_new();
4579 mimepart->content = MIMECONTENT_FILE;
4580 mimepart->data.filename = g_strdup(ainfo->file);
4581 mimepart->tmp = FALSE; /* or we destroy our attachment */
4582 mimepart->offset = 0;
4584 stat(ainfo->file, &statbuf);
4585 mimepart->length = statbuf.st_size;
4587 type = g_strdup(ainfo->content_type);
4589 if (!strchr(type, '/')) {
4591 type = g_strdup("application/octet-stream");
4594 subtype = strchr(type, '/') + 1;
4595 *(subtype - 1) = '\0';
4596 mimepart->type = procmime_get_media_type(type);
4597 mimepart->subtype = g_strdup(subtype);
4600 if (mimepart->type == MIMETYPE_MESSAGE &&
4601 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4602 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4604 g_hash_table_insert(mimepart->typeparameters,
4605 g_strdup("name"), g_strdup(ainfo->name));
4606 g_hash_table_insert(mimepart->dispositionparameters,
4607 g_strdup("filename"), g_strdup(ainfo->name));
4608 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4611 if (compose->use_signing) {
4612 if (ainfo->encoding == ENC_7BIT)
4613 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4614 else if (ainfo->encoding == ENC_8BIT)
4615 ainfo->encoding = ENC_BASE64;
4618 procmime_encode_content(mimepart, ainfo->encoding);
4620 g_node_append(parent->node, mimepart->node);
4621 } while (gtk_tree_model_iter_next(model, &iter));
4624 #define QUOTE_IF_REQUIRED(out, str) \
4626 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4630 len = strlen(str) + 3; \
4631 if ((__tmp = alloca(len)) == NULL) { \
4632 g_warning("can't allocate memory\n"); \
4633 g_string_free(header, TRUE); \
4636 g_snprintf(__tmp, len, "\"%s\"", str); \
4641 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4642 g_warning("can't allocate memory\n"); \
4643 g_string_free(header, TRUE); \
4646 strcpy(__tmp, str); \
4652 #define IS_IN_CUSTOM_HEADER(header) \
4653 (compose->account->add_customhdr && \
4654 custom_header_find(compose->account->customhdr_list, header) != NULL)
4656 static void compose_add_headerfield_from_headerlist(Compose *compose,
4658 const gchar *fieldname,
4659 const gchar *seperator)
4661 gchar *str, *fieldname_w_colon, *trans_fieldname;
4662 gboolean add_field = FALSE;
4664 ComposeHeaderEntry *headerentry;
4665 const gchar * headerentryname;
4668 if (IS_IN_CUSTOM_HEADER(fieldname))
4671 debug_print("Adding %s-fields\n", fieldname);
4673 fieldstr = g_string_sized_new(64);
4675 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4676 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4678 for (list = compose->header_list; list; list = list->next) {
4679 headerentry = ((ComposeHeaderEntry *)list->data);
4680 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4682 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4683 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4685 if (str[0] != '\0') {
4687 g_string_append(fieldstr, seperator);
4688 g_string_append(fieldstr, str);
4697 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4698 compose_convert_header
4699 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4700 strlen(fieldname) + 2, TRUE);
4701 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4705 g_free(fieldname_w_colon);
4706 g_string_free(fieldstr, TRUE);
4711 static gchar *compose_get_header(Compose *compose)
4713 gchar buf[BUFFSIZE];
4714 const gchar *entry_str;
4718 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4721 g_return_val_if_fail(compose->account != NULL, NULL);
4722 g_return_val_if_fail(compose->account->address != NULL, NULL);
4724 header = g_string_sized_new(64);
4727 if (compose->account->add_date) {
4728 get_rfc822_date(buf, sizeof(buf));
4729 g_string_append_printf(header, "Date: %s\n", buf);
4733 if (compose->account->name && *compose->account->name) {
4734 compose_convert_header
4735 (compose, buf, sizeof(buf), compose->account->name,
4736 strlen("From: "), TRUE);
4737 QUOTE_IF_REQUIRED(name, buf);
4738 g_string_append_printf(header, "From: %s <%s>\n",
4739 name, compose->account->address);
4741 g_string_append_printf(header, "From: %s\n", compose->account->address);
4744 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4747 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4750 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4753 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4756 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4758 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4761 compose_convert_header(compose, buf, sizeof(buf), str,
4762 strlen("Subject: "), FALSE);
4763 g_string_append_printf(header, "Subject: %s\n", buf);
4769 if (compose->account->gen_msgid) {
4770 generate_msgid(buf, sizeof(buf));
4771 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4772 compose->msgid = g_strdup(buf);
4775 if (compose->remove_references == FALSE) {
4777 if (compose->inreplyto && compose->to_list)
4778 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4781 if (compose->references)
4782 g_string_append_printf(header, "References: %s\n", compose->references);
4786 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4789 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4792 if (compose->account->organization &&
4793 strlen(compose->account->organization) &&
4794 !IS_IN_CUSTOM_HEADER("Organization")) {
4795 compose_convert_header(compose, buf, sizeof(buf),
4796 compose->account->organization,
4797 strlen("Organization: "), FALSE);
4798 g_string_append_printf(header, "Organization: %s\n", buf);
4801 /* Program version and system info */
4802 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4803 !compose->newsgroup_list) {
4804 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4806 gtk_major_version, gtk_minor_version, gtk_micro_version,
4809 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4810 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4812 gtk_major_version, gtk_minor_version, gtk_micro_version,
4816 /* custom headers */
4817 if (compose->account->add_customhdr) {
4820 for (cur = compose->account->customhdr_list; cur != NULL;
4822 CustomHeader *chdr = (CustomHeader *)cur->data;
4824 if (custom_header_is_allowed(chdr->name)) {
4825 compose_convert_header
4826 (compose, buf, sizeof(buf),
4827 chdr->value ? chdr->value : "",
4828 strlen(chdr->name) + 2, FALSE);
4829 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4835 switch (compose->priority) {
4836 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4837 "X-Priority: 1 (Highest)\n");
4839 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4840 "X-Priority: 2 (High)\n");
4842 case PRIORITY_NORMAL: break;
4843 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4844 "X-Priority: 4 (Low)\n");
4846 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4847 "X-Priority: 5 (Lowest)\n");
4849 default: debug_print("compose: priority unknown : %d\n",
4853 /* Request Return Receipt */
4854 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4855 if (compose->return_receipt) {
4856 if (compose->account->name
4857 && *compose->account->name) {
4858 compose_convert_header(compose, buf, sizeof(buf),
4859 compose->account->name,
4860 strlen("Disposition-Notification-To: "),
4862 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4864 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4868 /* get special headers */
4869 for (list = compose->header_list; list; list = list->next) {
4870 ComposeHeaderEntry *headerentry;
4873 gchar *headername_wcolon;
4874 gchar *headername_trans;
4877 gboolean standard_header = FALSE;
4879 headerentry = ((ComposeHeaderEntry *)list->data);
4881 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4882 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4887 if (!strstr(tmp, ":")) {
4888 headername_wcolon = g_strconcat(tmp, ":", NULL);
4889 headername = g_strdup(tmp);
4891 headername_wcolon = g_strdup(tmp);
4892 headername = g_strdup(strtok(tmp, ":"));
4896 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4897 Xstrdup_a(headervalue, entry_str, return NULL);
4898 subst_char(headervalue, '\r', ' ');
4899 subst_char(headervalue, '\n', ' ');
4900 string = std_headers;
4901 while (*string != NULL) {
4902 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4903 if (!strcmp(headername_trans,headername_wcolon))
4904 standard_header = TRUE;
4907 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4908 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
4911 g_free(headername_wcolon);
4915 g_string_free(header, FALSE);
4920 #undef IS_IN_CUSTOM_HEADER
4922 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
4923 gint header_len, gboolean addr_field)
4925 gchar *tmpstr = NULL;
4926 const gchar *out_codeset = NULL;
4928 g_return_if_fail(src != NULL);
4929 g_return_if_fail(dest != NULL);
4931 if (len < 1) return;
4933 tmpstr = g_strdup(src);
4935 subst_char(tmpstr, '\n', ' ');
4936 subst_char(tmpstr, '\r', ' ');
4939 if (!g_utf8_validate(tmpstr, -1, NULL)) {
4940 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
4941 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
4946 codeconv_set_strict(TRUE);
4947 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4948 conv_get_charset_str(compose->out_encoding));
4949 codeconv_set_strict(FALSE);
4951 if (!dest || *dest == '\0') {
4952 gchar *test_conv_global_out = NULL;
4953 gchar *test_conv_reply = NULL;
4955 /* automatic mode. be automatic. */
4956 codeconv_set_strict(TRUE);
4958 out_codeset = conv_get_outgoing_charset_str();
4960 debug_print("trying to convert to %s\n", out_codeset);
4961 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4964 if (!test_conv_global_out && compose->orig_charset) {
4965 out_codeset = compose->orig_charset;
4966 debug_print("failure; trying to convert to %s\n", out_codeset);
4967 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4970 if (!test_conv_global_out && !test_conv_reply) {
4972 out_codeset = CS_INTERNAL;
4973 debug_print("finally using %s\n", out_codeset);
4975 g_free(test_conv_global_out);
4976 g_free(test_conv_reply);
4977 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4979 codeconv_set_strict(FALSE);
4984 static void compose_create_header_entry(Compose *compose)
4986 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4990 GList *combo_list = NULL;
4992 const gchar *header = NULL;
4993 ComposeHeaderEntry *headerentry;
4994 gboolean standard_header = FALSE;
4996 headerentry = g_new0(ComposeHeaderEntry, 1);
4999 combo = gtk_combo_new();
5001 while(*string != NULL) {
5002 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
5005 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5006 g_list_free(combo_list);
5007 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5008 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5009 G_CALLBACK(compose_grab_focus_cb), compose);
5010 gtk_widget_show(combo);
5011 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5012 if (compose->header_last) {
5013 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5015 while (*string != NULL) {
5016 if (!strcmp(*string, last_header_entry))
5017 standard_header = TRUE;
5020 if (standard_header)
5021 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5023 if (!compose->header_last || !standard_header) {
5024 switch(compose->account->protocol) {
5026 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5029 header = prefs_common.trans_hdr ? _("To:") : "To:";
5034 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5036 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5037 G_CALLBACK(compose_grab_focus_cb), compose);
5040 entry = gtk_entry_new();
5041 gtk_widget_show(entry);
5042 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);
5044 g_signal_connect(G_OBJECT(entry), "key-press-event",
5045 G_CALLBACK(compose_headerentry_key_press_event_cb),
5047 g_signal_connect(G_OBJECT(entry), "changed",
5048 G_CALLBACK(compose_headerentry_changed_cb),
5050 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5051 G_CALLBACK(compose_grab_focus_cb), compose);
5054 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5055 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5056 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5057 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5058 G_CALLBACK(compose_header_drag_received_cb),
5060 g_signal_connect(G_OBJECT(entry), "drag-drop",
5061 G_CALLBACK(compose_drag_drop),
5064 address_completion_register_entry(GTK_ENTRY(entry));
5066 headerentry->compose = compose;
5067 headerentry->combo = combo;
5068 headerentry->entry = entry;
5069 headerentry->headernum = compose->header_nextrow;
5071 compose->header_nextrow++;
5072 compose->header_last = headerentry;
5075 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5077 ComposeHeaderEntry *last_header;
5079 last_header = compose->header_last;
5081 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5082 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5085 static GtkWidget *compose_create_header(Compose *compose)
5089 GtkWidget *from_optmenu_hbox;
5090 GtkWidget *header_scrolledwin;
5091 GtkWidget *header_table;
5095 /* header labels and entries */
5096 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5097 gtk_widget_show(header_scrolledwin);
5098 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5100 header_table = gtk_table_new(2, 2, FALSE);
5101 gtk_widget_show(header_table);
5102 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
5103 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5104 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5107 /* option menu for selecting accounts */
5108 hbox = gtk_hbox_new(FALSE, 0);
5109 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
5110 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
5111 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
5113 from_optmenu_hbox = compose_account_option_menu_create(compose);
5114 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5115 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5118 compose->header_table = header_table;
5119 compose->header_list = NULL;
5120 compose->header_nextrow = count;
5122 compose_create_header_entry(compose);
5124 compose->table = NULL;
5126 return header_scrolledwin ;
5129 GtkWidget *compose_create_attach(Compose *compose)
5131 GtkWidget *attach_scrwin;
5132 GtkWidget *attach_clist;
5134 GtkListStore *store;
5135 GtkCellRenderer *renderer;
5136 GtkTreeViewColumn *column;
5137 GtkTreeSelection *selection;
5139 /* attachment list */
5140 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5141 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5142 GTK_POLICY_AUTOMATIC,
5143 GTK_POLICY_AUTOMATIC);
5144 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5146 store = gtk_list_store_new(N_ATTACH_COLS,
5151 G_TYPE_AUTO_POINTER,
5153 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5154 (GTK_TREE_MODEL(store)));
5155 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5156 g_object_unref(store);
5158 renderer = gtk_cell_renderer_text_new();
5159 column = gtk_tree_view_column_new_with_attributes
5160 (_("Mime type"), renderer, "text",
5161 COL_MIMETYPE, NULL);
5162 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5164 renderer = gtk_cell_renderer_text_new();
5165 column = gtk_tree_view_column_new_with_attributes
5166 (_("Size"), renderer, "text",
5168 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5170 renderer = gtk_cell_renderer_text_new();
5171 column = gtk_tree_view_column_new_with_attributes
5172 (_("Name"), renderer, "text",
5174 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5176 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5177 prefs_common.enable_rules_hint);
5178 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5179 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5181 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5182 G_CALLBACK(attach_selected), compose);
5183 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5184 G_CALLBACK(attach_button_pressed), compose);
5185 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5186 G_CALLBACK(attach_key_pressed), compose);
5189 gtk_drag_dest_set(attach_clist,
5190 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5191 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5192 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5193 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5194 G_CALLBACK(compose_attach_drag_received_cb),
5196 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5197 G_CALLBACK(compose_drag_drop),
5200 compose->attach_scrwin = attach_scrwin;
5201 compose->attach_clist = attach_clist;
5203 return attach_scrwin;
5206 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5207 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5209 static GtkWidget *compose_create_others(Compose *compose)
5212 GtkWidget *savemsg_checkbtn;
5213 GtkWidget *savemsg_entry;
5214 GtkWidget *savemsg_select;
5217 gchar *folderidentifier;
5219 /* Table for settings */
5220 table = gtk_table_new(3, 1, FALSE);
5221 gtk_widget_show(table);
5222 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5225 /* Save Message to folder */
5226 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5227 gtk_widget_show(savemsg_checkbtn);
5228 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5229 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5230 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5232 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5233 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5235 savemsg_entry = gtk_entry_new();
5236 gtk_widget_show(savemsg_entry);
5237 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5238 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5239 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5240 G_CALLBACK(compose_grab_focus_cb), compose);
5241 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5242 folderidentifier = folder_item_get_identifier(account_get_special_folder
5243 (compose->account, F_OUTBOX));
5244 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5245 g_free(folderidentifier);
5248 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5249 gtk_widget_show(savemsg_select);
5250 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5251 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5252 G_CALLBACK(compose_savemsg_select_cb),
5257 compose->savemsg_checkbtn = savemsg_checkbtn;
5258 compose->savemsg_entry = savemsg_entry;
5263 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5265 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5266 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5269 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5274 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5277 path = folder_item_get_identifier(dest);
5279 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5283 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5286 #define BLOCK_WRAP() { \
5287 prev_autowrap = compose->autowrap; \
5288 buffer = gtk_text_view_get_buffer( \
5289 GTK_TEXT_VIEW(compose->text)); \
5290 compose->autowrap = FALSE; \
5292 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5293 G_CALLBACK(compose_changed_cb), \
5295 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5296 G_CALLBACK(text_inserted), \
5299 #define UNBLOCK_WRAP() { \
5300 compose->autowrap = prev_autowrap; \
5301 if (compose->autowrap) \
5302 compose_wrap_all(compose); \
5304 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5305 G_CALLBACK(compose_changed_cb), \
5307 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5308 G_CALLBACK(text_inserted), \
5313 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5317 GtkTextBuffer *buffer;
5319 if (event->button == 3) {
5321 GtkTextIter sel_start, sel_end;
5322 gboolean stuff_selected;
5324 /* move the cursor to allow GtkAspell to check the word
5325 * under the mouse */
5326 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5327 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5329 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5332 stuff_selected = gtk_text_buffer_get_selection_bounds(
5333 GTK_TEXT_VIEW(text)->buffer,
5334 &sel_start, &sel_end);
5336 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5337 /* reselect stuff */
5339 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5340 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5341 &sel_start, &sel_end);
5343 return FALSE; /* pass the event so that the right-click goes through */
5346 if (event->button == 2) {
5348 entry_paste_clipboard(compose, compose->focused_editable,
5349 prefs_common.linewrap_pastes,
5350 GDK_SELECTION_PRIMARY);
5357 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
5363 GtkWidget *handlebox;
5365 GtkWidget *notebook;
5370 GtkWidget *subject_hbox;
5371 GtkWidget *subject_frame;
5372 GtkWidget *subject_entry;
5376 GtkWidget *edit_vbox;
5377 GtkWidget *ruler_hbox;
5379 GtkWidget *scrolledwin;
5381 GtkTextBuffer *buffer;
5382 GtkClipboard *clipboard;
5384 UndoMain *undostruct;
5386 gchar *titles[N_ATTACH_COLS];
5387 guint n_menu_entries;
5390 gboolean success[1];
5391 GtkWidget *popupmenu;
5392 GtkItemFactory *popupfactory;
5393 GtkItemFactory *ifactory;
5394 GtkWidget *tmpl_menu;
5396 GtkWidget *menuitem;
5399 GtkAspell * gtkaspell = NULL;
5402 static GdkGeometry geometry;
5404 g_return_val_if_fail(account != NULL, NULL);
5406 debug_print("Creating compose window...\n");
5407 compose = g_new0(Compose, 1);
5409 titles[COL_MIMETYPE] = _("MIME type");
5410 titles[COL_SIZE] = _("Size");
5411 titles[COL_NAME] = _("Name");
5413 compose->account = account;
5415 compose->mutex = g_mutex_new();
5416 compose->set_cursor_pos = -1;
5418 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5419 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5420 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5422 if (!geometry.max_width) {
5423 geometry.max_width = gdk_screen_width();
5424 geometry.max_height = gdk_screen_height();
5427 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5428 &geometry, GDK_HINT_MAX_SIZE);
5429 if (!geometry.min_width) {
5430 geometry.min_width = 600;
5431 geometry.min_height = 480;
5433 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5434 &geometry, GDK_HINT_MIN_SIZE);
5435 gtk_widget_set_uposition(window, prefs_common.compose_x,
5436 prefs_common.compose_y);
5438 g_signal_connect(G_OBJECT(window), "delete_event",
5439 G_CALLBACK(compose_delete_cb), compose);
5440 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5441 gtk_widget_realize(window);
5443 gtkut_widget_set_composer_icon(window);
5445 vbox = gtk_vbox_new(FALSE, 0);
5446 gtk_container_add(GTK_CONTAINER(window), vbox);
5448 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5449 menubar = menubar_create(window, compose_entries,
5450 n_menu_entries, "<Compose>", compose);
5451 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5453 if (prefs_common.toolbar_detachable) {
5454 handlebox = gtk_handle_box_new();
5456 handlebox = gtk_hbox_new(FALSE, 0);
5458 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5460 gtk_widget_realize(handlebox);
5461 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5464 vbox2 = gtk_vbox_new(FALSE, 2);
5465 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5466 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5469 notebook = gtk_notebook_new();
5470 gtk_widget_set_size_request(notebook, -1, 130);
5471 gtk_widget_show(notebook);
5473 /* header labels and entries */
5474 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
5475 /* attachment list */
5476 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
5478 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
5481 subject_hbox = gtk_hbox_new(FALSE, 0);
5482 gtk_widget_show(subject_hbox);
5484 subject_frame = gtk_frame_new(NULL);
5485 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5486 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5487 gtk_widget_show(subject_frame);
5489 subject = gtk_hbox_new(FALSE, 0);
5490 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5491 gtk_widget_show(subject);
5493 label = gtk_label_new(_("Subject:"));
5494 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5495 gtk_widget_show(label);
5497 subject_entry = gtk_entry_new();
5498 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5499 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5500 G_CALLBACK(compose_grab_focus_cb), compose);
5501 gtk_widget_show(subject_entry);
5502 compose->subject_entry = subject_entry;
5503 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5505 edit_vbox = gtk_vbox_new(FALSE, 0);
5507 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5510 ruler_hbox = gtk_hbox_new(FALSE, 0);
5511 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5513 ruler = gtk_shruler_new();
5514 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5515 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5519 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5520 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5521 GTK_POLICY_AUTOMATIC,
5522 GTK_POLICY_AUTOMATIC);
5523 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5525 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5526 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5528 text = gtk_text_view_new();
5529 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5530 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5531 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5532 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5533 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5535 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5537 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5538 G_CALLBACK(compose_edit_size_alloc),
5540 g_signal_connect(G_OBJECT(buffer), "changed",
5541 G_CALLBACK(compose_changed_cb), compose);
5542 g_signal_connect(G_OBJECT(text), "grab_focus",
5543 G_CALLBACK(compose_grab_focus_cb), compose);
5544 g_signal_connect(G_OBJECT(buffer), "insert_text",
5545 G_CALLBACK(text_inserted), compose);
5546 g_signal_connect(G_OBJECT(text), "button_press_event",
5547 G_CALLBACK(text_clicked), compose);
5548 g_signal_connect(G_OBJECT(subject_entry), "changed",
5549 G_CALLBACK(compose_changed_cb), compose);
5552 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5553 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5554 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5555 g_signal_connect(G_OBJECT(text), "drag_data_received",
5556 G_CALLBACK(compose_insert_drag_received_cb),
5558 g_signal_connect(G_OBJECT(text), "drag-drop",
5559 G_CALLBACK(compose_drag_drop),
5561 gtk_widget_show_all(vbox);
5563 /* pane between attach clist and text */
5564 paned = gtk_vpaned_new();
5565 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5566 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5567 gtk_paned_add1(GTK_PANED(paned), notebook);
5568 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5569 gtk_widget_show_all(paned);
5572 if (prefs_common.textfont) {
5573 PangoFontDescription *font_desc;
5575 font_desc = pango_font_description_from_string
5576 (prefs_common.textfont);
5578 gtk_widget_modify_font(text, font_desc);
5579 pango_font_description_free(font_desc);
5583 color[0] = quote_color;
5584 cmap = gdk_drawable_get_colormap(window->window);
5585 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5586 if (success[0] == FALSE) {
5589 g_warning("Compose: color allocation failed.\n");
5590 style = gtk_widget_get_style(text);
5591 quote_color = style->black;
5594 n_entries = sizeof(compose_popup_entries) /
5595 sizeof(compose_popup_entries[0]);
5596 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5597 "<Compose>", &popupfactory,
5600 ifactory = gtk_item_factory_from_widget(menubar);
5601 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5602 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5603 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5605 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5607 undostruct = undo_init(text);
5608 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5611 address_completion_start(window);
5613 compose->window = window;
5614 compose->vbox = vbox;
5615 compose->menubar = menubar;
5616 compose->handlebox = handlebox;
5618 compose->vbox2 = vbox2;
5620 compose->paned = paned;
5622 compose->edit_vbox = edit_vbox;
5623 compose->ruler_hbox = ruler_hbox;
5624 compose->ruler = ruler;
5625 compose->scrolledwin = scrolledwin;
5626 compose->text = text;
5628 compose->focused_editable = NULL;
5630 compose->popupmenu = popupmenu;
5631 compose->popupfactory = popupfactory;
5633 compose->tmpl_menu = tmpl_menu;
5635 compose->mode = mode;
5637 compose->targetinfo = NULL;
5638 compose->replyinfo = NULL;
5639 compose->fwdinfo = NULL;
5641 compose->replyto = NULL;
5643 compose->bcc = NULL;
5644 compose->followup_to = NULL;
5646 compose->ml_post = NULL;
5648 compose->inreplyto = NULL;
5649 compose->references = NULL;
5650 compose->msgid = NULL;
5651 compose->boundary = NULL;
5653 compose->autowrap = prefs_common.autowrap;
5655 compose->use_signing = FALSE;
5656 compose->use_encryption = FALSE;
5657 compose->privacy_system = NULL;
5659 compose->modified = FALSE;
5661 compose->return_receipt = FALSE;
5663 compose->to_list = NULL;
5664 compose->newsgroup_list = NULL;
5666 compose->undostruct = undostruct;
5668 compose->sig_str = NULL;
5670 compose->exteditor_file = NULL;
5671 compose->exteditor_pid = -1;
5672 compose->exteditor_tag = -1;
5673 compose->draft_timeout_tag = -1;
5676 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5677 if (mode != COMPOSE_REDIRECT) {
5678 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5679 strcmp(prefs_common.dictionary, _("None"))) {
5680 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5681 prefs_common.dictionary,
5682 conv_get_locale_charset_str(),
5683 prefs_common.misspelled_col,
5684 prefs_common.check_while_typing,
5685 prefs_common.use_alternate,
5686 GTK_TEXT_VIEW(text),
5687 GTK_WINDOW(compose->window));
5689 alertpanel_error(_("Spell checker could not "
5691 gtkaspell_checkers_strerror());
5692 gtkaspell_checkers_reset_error();
5694 if (!gtkaspell_set_sug_mode(gtkaspell,
5695 prefs_common.aspell_sugmode)) {
5696 debug_print("Aspell: could not set "
5697 "suggestion mode %s\n",
5698 gtkaspell_checkers_strerror());
5699 gtkaspell_checkers_reset_error();
5702 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5706 compose->gtkaspell = gtkaspell;
5709 compose_select_account(compose, account, TRUE);
5711 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5712 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5713 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5715 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5716 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5718 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5719 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5722 if (account->protocol != A_NNTP)
5723 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5725 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5727 addressbook_set_target_compose(compose);
5729 if (mode != COMPOSE_REDIRECT)
5730 compose_set_template_menu(compose);
5732 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5733 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5736 compose_list = g_list_append(compose_list, compose);
5738 if (!prefs_common.show_ruler)
5739 gtk_widget_hide(ruler_hbox);
5741 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5742 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5743 prefs_common.show_ruler);
5746 compose->priority = PRIORITY_NORMAL;
5747 compose_update_priority_menu_item(compose);
5749 compose_set_out_encoding(compose);
5752 compose_update_actions_menu(compose);
5754 /* Privacy Systems menu */
5755 compose_update_privacy_systems_menu(compose);
5757 activate_privacy_system(compose, account, TRUE);
5758 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5759 gtk_widget_show(window);
5764 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5770 gint num = 0, def_menu = 0;
5772 accounts = account_get_list();
5773 g_return_val_if_fail(accounts != NULL, NULL);
5775 hbox = gtk_hbox_new(FALSE, 0);
5776 optmenu = gtk_option_menu_new();
5777 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5778 menu = gtk_menu_new();
5780 for (; accounts != NULL; accounts = accounts->next, num++) {
5781 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5782 GtkWidget *menuitem;
5785 if (ac == compose->account) def_menu = num;
5788 name = g_strdup_printf("%s: %s <%s>",
5790 ac->name, ac->address);
5792 name = g_strdup_printf("%s: %s",
5793 ac->account_name, ac->address);
5794 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5796 g_signal_connect(G_OBJECT(menuitem), "activate",
5797 G_CALLBACK(account_activated),
5801 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5802 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5807 static void compose_set_priority_cb(gpointer data,
5811 Compose *compose = (Compose *) data;
5812 compose->priority = action;
5815 static void compose_update_priority_menu_item(Compose * compose)
5817 GtkItemFactory *ifactory;
5818 GtkWidget *menuitem = NULL;
5820 ifactory = gtk_item_factory_from_widget(compose->menubar);
5822 switch (compose->priority) {
5823 case PRIORITY_HIGHEST:
5824 menuitem = gtk_item_factory_get_item
5825 (ifactory, "/Options/Priority/Highest");
5828 menuitem = gtk_item_factory_get_item
5829 (ifactory, "/Options/Priority/High");
5831 case PRIORITY_NORMAL:
5832 menuitem = gtk_item_factory_get_item
5833 (ifactory, "/Options/Priority/Normal");
5836 menuitem = gtk_item_factory_get_item
5837 (ifactory, "/Options/Priority/Low");
5839 case PRIORITY_LOWEST:
5840 menuitem = gtk_item_factory_get_item
5841 (ifactory, "/Options/Priority/Lowest");
5844 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5847 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5849 Compose *compose = (Compose *) data;
5851 GtkItemFactory *ifactory;
5852 gboolean can_sign = FALSE, can_encrypt = FALSE;
5854 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5856 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5859 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5860 g_free(compose->privacy_system);
5861 compose->privacy_system = NULL;
5862 if (systemid != NULL) {
5863 compose->privacy_system = g_strdup(systemid);
5865 can_sign = privacy_system_can_sign(systemid);
5866 can_encrypt = privacy_system_can_encrypt(systemid);
5869 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5871 ifactory = gtk_item_factory_from_widget(compose->menubar);
5872 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5873 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5876 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
5878 static gchar *branch_path = "/Options/Privacy System";
5879 GtkItemFactory *ifactory;
5880 GtkWidget *menuitem = NULL;
5882 gboolean can_sign = FALSE, can_encrypt = FALSE;
5883 gboolean found = FALSE;
5885 ifactory = gtk_item_factory_from_widget(compose->menubar);
5887 if (compose->privacy_system != NULL) {
5890 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5891 g_return_if_fail(menuitem != NULL);
5893 amenu = GTK_MENU_SHELL(menuitem)->children;
5895 while (amenu != NULL) {
5896 GList *alist = amenu->next;
5898 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
5899 if (systemid != NULL) {
5900 if (strcmp(systemid, compose->privacy_system) == 0) {
5901 menuitem = GTK_WIDGET(amenu->data);
5903 can_sign = privacy_system_can_sign(systemid);
5904 can_encrypt = privacy_system_can_encrypt(systemid);
5908 } else if (strlen(compose->privacy_system) == 0) {
5909 menuitem = GTK_WIDGET(amenu->data);
5912 can_encrypt = FALSE;
5919 if (menuitem != NULL)
5920 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5922 if (warn && !found && strlen(compose->privacy_system)) {
5923 gchar *tmp = g_strdup_printf(
5924 _("The privacy system '%s' cannot be loaded. You "
5925 "will not be able to sign or encrypt this message."),
5926 compose->privacy_system);
5927 alertpanel_warning(tmp);
5932 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5933 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5936 static void compose_set_out_encoding(Compose *compose)
5938 GtkItemFactoryEntry *entry;
5939 GtkItemFactory *ifactory;
5940 CharSet out_encoding;
5941 gchar *path, *p, *q;
5944 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
5945 ifactory = gtk_item_factory_from_widget(compose->menubar);
5947 for (entry = compose_entries; entry->callback != compose_address_cb;
5949 if (entry->callback == compose_set_encoding_cb &&
5950 (CharSet)entry->callback_action == out_encoding) {
5951 p = q = path = g_strdup(entry->path);
5963 item = gtk_item_factory_get_item(ifactory, path);
5964 gtk_widget_activate(item);
5971 static void compose_set_template_menu(Compose *compose)
5973 GSList *tmpl_list, *cur;
5977 tmpl_list = template_get_config();
5979 menu = gtk_menu_new();
5981 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5982 Template *tmpl = (Template *)cur->data;
5984 item = gtk_menu_item_new_with_label(tmpl->name);
5985 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5986 g_signal_connect(G_OBJECT(item), "activate",
5987 G_CALLBACK(compose_template_activate_cb),
5989 g_object_set_data(G_OBJECT(item), "template", tmpl);
5990 gtk_widget_show(item);
5993 gtk_widget_show(menu);
5994 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5997 void compose_update_actions_menu(Compose *compose)
5999 GtkItemFactory *ifactory;
6001 ifactory = gtk_item_factory_from_widget(compose->menubar);
6002 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6005 void compose_update_privacy_systems_menu(Compose *compose)
6007 static gchar *branch_path = "/Options/Privacy System";
6008 GtkItemFactory *ifactory;
6009 GtkWidget *menuitem;
6010 GSList *systems, *cur;
6013 GtkWidget *system_none;
6016 ifactory = gtk_item_factory_from_widget(compose->menubar);
6018 /* remove old entries */
6019 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6020 g_return_if_fail(menuitem != NULL);
6022 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6023 while (amenu != NULL) {
6024 GList *alist = amenu->next;
6025 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6029 system_none = gtk_item_factory_get_widget(ifactory,
6030 "/Options/Privacy System/None");
6032 g_signal_connect(G_OBJECT(system_none), "activate",
6033 G_CALLBACK(compose_set_privacy_system_cb), compose);
6035 systems = privacy_get_system_ids();
6036 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6037 gchar *systemid = cur->data;
6039 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6040 widget = gtk_radio_menu_item_new_with_label(group,
6041 privacy_system_get_name(systemid));
6042 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6043 g_strdup(systemid), g_free);
6044 g_signal_connect(G_OBJECT(widget), "activate",
6045 G_CALLBACK(compose_set_privacy_system_cb), compose);
6047 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6048 gtk_widget_show(widget);
6051 g_slist_free(systems);
6054 void compose_reflect_prefs_all(void)
6059 for (cur = compose_list; cur != NULL; cur = cur->next) {
6060 compose = (Compose *)cur->data;
6061 compose_set_template_menu(compose);
6065 void compose_reflect_prefs_pixmap_theme(void)
6070 for (cur = compose_list; cur != NULL; cur = cur->next) {
6071 compose = (Compose *)cur->data;
6072 toolbar_update(TOOLBAR_COMPOSE, compose);
6076 static void compose_template_apply(Compose *compose, Template *tmpl,
6080 GtkTextBuffer *buffer;
6084 gchar *parsed_str = NULL;
6085 gint cursor_pos = 0;
6088 text = GTK_TEXT_VIEW(compose->text);
6089 buffer = gtk_text_view_get_buffer(text);
6091 if (tmpl->subject && *tmpl->subject != '\0')
6092 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
6094 if (tmpl->to && *tmpl->to != '\0')
6095 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
6096 if (tmpl->cc && *tmpl->cc != '\0')
6097 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
6099 if (tmpl->bcc && *tmpl->bcc != '\0')
6100 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
6103 gtk_text_buffer_set_text(buffer, "", -1);
6105 mark = gtk_text_buffer_get_insert(buffer);
6106 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6109 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6110 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6113 if (prefs_common.quotemark && *prefs_common.quotemark)
6114 qmark = prefs_common.quotemark;
6118 if (compose->replyinfo != NULL)
6119 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6120 tmpl->value, qmark, NULL, FALSE);
6121 else if (compose->fwdinfo != NULL)
6122 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6123 tmpl->value, qmark, NULL, FALSE);
6128 if (replace && parsed_str && compose->account->auto_sig)
6129 compose_insert_sig(compose, FALSE);
6131 if (replace && parsed_str) {
6132 gtk_text_buffer_get_start_iter(buffer, &iter);
6133 gtk_text_buffer_place_cursor(buffer, &iter);
6137 cursor_pos = quote_fmt_get_cursor_pos();
6138 compose->set_cursor_pos = cursor_pos;
6139 if (cursor_pos == -1)
6141 gtk_text_buffer_get_start_iter(buffer, &iter);
6142 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6143 gtk_text_buffer_place_cursor(buffer, &iter);
6146 compose_changed_cb(NULL, compose);
6149 static void compose_destroy(Compose *compose)
6151 compose_list = g_list_remove(compose_list, compose);
6153 /* NOTE: address_completion_end() does nothing with the window
6154 * however this may change. */
6155 address_completion_end(compose->window);
6157 slist_free_strings(compose->to_list);
6158 g_slist_free(compose->to_list);
6159 slist_free_strings(compose->newsgroup_list);
6160 g_slist_free(compose->newsgroup_list);
6161 slist_free_strings(compose->header_list);
6162 g_slist_free(compose->header_list);
6164 procmsg_msginfo_free(compose->targetinfo);
6165 procmsg_msginfo_free(compose->replyinfo);
6166 procmsg_msginfo_free(compose->fwdinfo);
6168 g_free(compose->replyto);
6169 g_free(compose->cc);
6170 g_free(compose->bcc);
6171 g_free(compose->newsgroups);
6172 g_free(compose->followup_to);
6174 g_free(compose->ml_post);
6176 g_free(compose->inreplyto);
6177 g_free(compose->references);
6178 g_free(compose->msgid);
6179 g_free(compose->boundary);
6181 if (compose->redirect_filename)
6182 g_free(compose->redirect_filename);
6183 if (compose->undostruct)
6184 undo_destroy(compose->undostruct);
6186 g_free(compose->sig_str);
6188 g_free(compose->exteditor_file);
6190 g_free(compose->orig_charset);
6192 g_free(compose->privacy_system);
6194 if (addressbook_get_target_compose() == compose)
6195 addressbook_set_target_compose(NULL);
6198 if (compose->gtkaspell) {
6199 gtkaspell_delete(compose->gtkaspell);
6200 compose->gtkaspell = NULL;
6204 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6205 prefs_common.compose_height = compose->window->allocation.height;
6207 if (!gtk_widget_get_parent(compose->paned))
6208 gtk_widget_destroy(compose->paned);
6209 gtk_widget_destroy(compose->popupmenu);
6211 gtk_widget_destroy(compose->window);
6212 toolbar_destroy(compose->toolbar);
6213 g_free(compose->toolbar);
6214 g_mutex_free(compose->mutex);
6218 static void compose_attach_info_free(AttachInfo *ainfo)
6220 g_free(ainfo->file);
6221 g_free(ainfo->content_type);
6222 g_free(ainfo->name);
6226 static void compose_attach_remove_selected(Compose *compose)
6228 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6229 GtkTreeSelection *selection;
6231 GtkTreeModel *model;
6233 selection = gtk_tree_view_get_selection(tree_view);
6234 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6239 for (cur = sel; cur != NULL; cur = cur->next) {
6240 GtkTreePath *path = cur->data;
6241 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6244 gtk_tree_path_free(path);
6247 for (cur = sel; cur != NULL; cur = cur->next) {
6248 GtkTreeRowReference *ref = cur->data;
6249 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6252 if (gtk_tree_model_get_iter(model, &iter, path))
6253 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6255 gtk_tree_path_free(path);
6256 gtk_tree_row_reference_free(ref);
6262 static struct _AttachProperty
6265 GtkWidget *mimetype_entry;
6266 GtkWidget *encoding_optmenu;
6267 GtkWidget *path_entry;
6268 GtkWidget *filename_entry;
6270 GtkWidget *cancel_btn;
6273 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6275 gtk_tree_path_free((GtkTreePath *)ptr);
6278 static void compose_attach_property(Compose *compose)
6280 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6282 GtkOptionMenu *optmenu;
6283 GtkTreeSelection *selection;
6285 GtkTreeModel *model;
6288 static gboolean cancelled;
6290 /* only if one selected */
6291 selection = gtk_tree_view_get_selection(tree_view);
6292 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6295 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6299 path = (GtkTreePath *) sel->data;
6300 gtk_tree_model_get_iter(model, &iter, path);
6301 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6304 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6310 if (!attach_prop.window)
6311 compose_attach_property_create(&cancelled);
6312 gtk_widget_grab_focus(attach_prop.ok_btn);
6313 gtk_widget_show(attach_prop.window);
6314 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6316 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6317 if (ainfo->encoding == ENC_UNKNOWN)
6318 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6319 GINT_TO_POINTER(ENC_BASE64));
6321 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6322 GINT_TO_POINTER(ainfo->encoding));
6324 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6325 ainfo->content_type ? ainfo->content_type : "");
6326 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6327 ainfo->file ? ainfo->file : "");
6328 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6329 ainfo->name ? ainfo->name : "");
6332 const gchar *entry_text;
6334 gchar *cnttype = NULL;
6338 GtkWidget *menuitem;
6343 gtk_widget_hide(attach_prop.window);
6348 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6349 if (*entry_text != '\0') {
6352 text = g_strstrip(g_strdup(entry_text));
6353 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6354 cnttype = g_strdup(text);
6357 alertpanel_error(_("Invalid MIME type."));
6363 menu = gtk_option_menu_get_menu(optmenu);
6364 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6365 ainfo->encoding = GPOINTER_TO_INT
6366 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6368 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6369 if (*entry_text != '\0') {
6370 if (is_file_exist(entry_text) &&
6371 (size = get_file_size(entry_text)) > 0)
6372 file = g_strdup(entry_text);
6375 (_("File doesn't exist or is empty."));
6381 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6382 if (*entry_text != '\0') {
6383 g_free(ainfo->name);
6384 ainfo->name = g_strdup(entry_text);
6388 g_free(ainfo->content_type);
6389 ainfo->content_type = cnttype;
6392 g_free(ainfo->file);
6398 /* update tree store */
6399 text = to_human_readable(ainfo->size);
6400 gtk_tree_model_get_iter(model, &iter, path);
6401 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6402 COL_MIMETYPE, ainfo->content_type,
6404 COL_NAME, ainfo->name,
6410 gtk_tree_path_free(path);
6413 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6415 label = gtk_label_new(str); \
6416 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6417 GTK_FILL, 0, 0, 0); \
6418 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6420 entry = gtk_entry_new(); \
6421 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6422 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6425 static void compose_attach_property_create(gboolean *cancelled)
6431 GtkWidget *mimetype_entry;
6434 GtkWidget *optmenu_menu;
6435 GtkWidget *menuitem;
6436 GtkWidget *path_entry;
6437 GtkWidget *filename_entry;
6440 GtkWidget *cancel_btn;
6441 GList *mime_type_list, *strlist;
6443 debug_print("Creating attach_property window...\n");
6445 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6446 gtk_widget_set_size_request(window, 480, -1);
6447 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6448 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6449 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6450 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6451 g_signal_connect(G_OBJECT(window), "delete_event",
6452 G_CALLBACK(attach_property_delete_event),
6454 g_signal_connect(G_OBJECT(window), "key_press_event",
6455 G_CALLBACK(attach_property_key_pressed),
6458 vbox = gtk_vbox_new(FALSE, 8);
6459 gtk_container_add(GTK_CONTAINER(window), vbox);
6461 table = gtk_table_new(4, 2, FALSE);
6462 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6463 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6464 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6466 label = gtk_label_new(_("MIME type"));
6467 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6469 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6470 mimetype_entry = gtk_combo_new();
6471 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6472 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6474 /* stuff with list */
6475 mime_type_list = procmime_get_mime_type_list();
6477 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6478 MimeType *type = (MimeType *) mime_type_list->data;
6481 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6483 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6486 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6487 (GCompareFunc)strcmp2);
6490 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6492 for (mime_type_list = strlist; mime_type_list != NULL;
6493 mime_type_list = mime_type_list->next)
6494 g_free(mime_type_list->data);
6495 g_list_free(strlist);
6497 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6499 label = gtk_label_new(_("Encoding"));
6500 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6502 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6504 hbox = gtk_hbox_new(FALSE, 0);
6505 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6506 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6508 optmenu = gtk_option_menu_new();
6509 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6511 optmenu_menu = gtk_menu_new();
6512 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6513 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6514 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6515 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6516 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6517 ENC_QUOTED_PRINTABLE);
6518 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6520 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6522 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6524 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6525 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6527 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
6528 &ok_btn, GTK_STOCK_OK,
6530 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6531 gtk_widget_grab_default(ok_btn);
6533 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6534 G_CALLBACK(attach_property_ok),
6536 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6537 G_CALLBACK(attach_property_cancel),
6540 gtk_widget_show_all(vbox);
6542 attach_prop.window = window;
6543 attach_prop.mimetype_entry = mimetype_entry;
6544 attach_prop.encoding_optmenu = optmenu;
6545 attach_prop.path_entry = path_entry;
6546 attach_prop.filename_entry = filename_entry;
6547 attach_prop.ok_btn = ok_btn;
6548 attach_prop.cancel_btn = cancel_btn;
6551 #undef SET_LABEL_AND_ENTRY
6553 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6559 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6565 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6566 gboolean *cancelled)
6574 static gboolean attach_property_key_pressed(GtkWidget *widget,
6576 gboolean *cancelled)
6578 if (event && event->keyval == GDK_Escape) {
6585 static void compose_exec_ext_editor(Compose *compose)
6592 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6593 G_DIR_SEPARATOR, compose);
6595 if (pipe(pipe_fds) < 0) {
6601 if ((pid = fork()) < 0) {
6608 /* close the write side of the pipe */
6611 compose->exteditor_file = g_strdup(tmp);
6612 compose->exteditor_pid = pid;
6614 compose_set_ext_editor_sensitive(compose, FALSE);
6616 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6617 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6621 } else { /* process-monitoring process */
6627 /* close the read side of the pipe */
6630 if (compose_write_body_to_file(compose, tmp) < 0) {
6631 fd_write_all(pipe_fds[1], "2\n", 2);
6635 pid_ed = compose_exec_ext_editor_real(tmp);
6637 fd_write_all(pipe_fds[1], "1\n", 2);
6641 /* wait until editor is terminated */
6642 waitpid(pid_ed, NULL, 0);
6644 fd_write_all(pipe_fds[1], "0\n", 2);
6651 #endif /* G_OS_UNIX */
6655 static gint compose_exec_ext_editor_real(const gchar *file)
6662 g_return_val_if_fail(file != NULL, -1);
6664 if ((pid = fork()) < 0) {
6669 if (pid != 0) return pid;
6671 /* grandchild process */
6673 if (setpgid(0, getppid()))
6676 if (prefs_common.ext_editor_cmd &&
6677 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6678 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6679 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6681 if (prefs_common.ext_editor_cmd)
6682 g_warning("External editor command line is invalid: '%s'\n",
6683 prefs_common.ext_editor_cmd);
6684 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
6687 cmdline = strsplit_with_quote(buf, " ", 1024);
6688 execvp(cmdline[0], cmdline);
6691 g_strfreev(cmdline);
6696 static gboolean compose_ext_editor_kill(Compose *compose)
6698 pid_t pgid = compose->exteditor_pid * -1;
6701 ret = kill(pgid, 0);
6703 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6707 msg = g_strdup_printf
6708 (_("The external editor is still working.\n"
6709 "Force terminating the process?\n"
6710 "process group id: %d"), -pgid);
6711 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
6712 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
6716 if (val == G_ALERTALTERNATE) {
6717 g_source_remove(compose->exteditor_tag);
6718 g_io_channel_shutdown(compose->exteditor_ch,
6720 g_io_channel_unref(compose->exteditor_ch);
6722 if (kill(pgid, SIGTERM) < 0) perror("kill");
6723 waitpid(compose->exteditor_pid, NULL, 0);
6725 g_warning("Terminated process group id: %d", -pgid);
6726 g_warning("Temporary file: %s",
6727 compose->exteditor_file);
6729 compose_set_ext_editor_sensitive(compose, TRUE);
6731 g_free(compose->exteditor_file);
6732 compose->exteditor_file = NULL;
6733 compose->exteditor_pid = -1;
6734 compose->exteditor_ch = NULL;
6735 compose->exteditor_tag = -1;
6743 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6747 Compose *compose = (Compose *)data;
6750 debug_print(_("Compose: input from monitoring process\n"));
6752 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6754 g_io_channel_shutdown(source, FALSE, NULL);
6755 g_io_channel_unref(source);
6757 waitpid(compose->exteditor_pid, NULL, 0);
6759 if (buf[0] == '0') { /* success */
6760 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6761 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6763 gtk_text_buffer_set_text(buffer, "", -1);
6764 compose_insert_file(compose, compose->exteditor_file);
6765 compose_changed_cb(NULL, compose);
6767 if (g_unlink(compose->exteditor_file) < 0)
6768 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6769 } else if (buf[0] == '1') { /* failed */
6770 g_warning("Couldn't exec external editor\n");
6771 if (g_unlink(compose->exteditor_file) < 0)
6772 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6773 } else if (buf[0] == '2') {
6774 g_warning("Couldn't write to file\n");
6775 } else if (buf[0] == '3') {
6776 g_warning("Pipe read failed\n");
6779 compose_set_ext_editor_sensitive(compose, TRUE);
6781 g_free(compose->exteditor_file);
6782 compose->exteditor_file = NULL;
6783 compose->exteditor_pid = -1;
6784 compose->exteditor_ch = NULL;
6785 compose->exteditor_tag = -1;
6790 static void compose_set_ext_editor_sensitive(Compose *compose,
6793 GtkItemFactory *ifactory;
6795 ifactory = gtk_item_factory_from_widget(compose->menubar);
6797 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6798 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6799 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6800 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6801 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6802 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6803 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6806 gtk_widget_set_sensitive(compose->text, sensitive);
6807 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6808 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6809 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6810 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6811 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6812 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6813 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
6814 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
6816 #endif /* G_OS_UNIX */
6819 * compose_undo_state_changed:
6821 * Change the sensivity of the menuentries undo and redo
6823 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6824 gint redo_state, gpointer data)
6826 GtkWidget *widget = GTK_WIDGET(data);
6827 GtkItemFactory *ifactory;
6829 g_return_if_fail(widget != NULL);
6831 ifactory = gtk_item_factory_from_widget(widget);
6833 switch (undo_state) {
6834 case UNDO_STATE_TRUE:
6835 if (!undostruct->undo_state) {
6836 undostruct->undo_state = TRUE;
6837 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6840 case UNDO_STATE_FALSE:
6841 if (undostruct->undo_state) {
6842 undostruct->undo_state = FALSE;
6843 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6846 case UNDO_STATE_UNCHANGED:
6848 case UNDO_STATE_REFRESH:
6849 menu_set_sensitive(ifactory, "/Edit/Undo",
6850 undostruct->undo_state);
6853 g_warning("Undo state not recognized");
6857 switch (redo_state) {
6858 case UNDO_STATE_TRUE:
6859 if (!undostruct->redo_state) {
6860 undostruct->redo_state = TRUE;
6861 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6864 case UNDO_STATE_FALSE:
6865 if (undostruct->redo_state) {
6866 undostruct->redo_state = FALSE;
6867 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6870 case UNDO_STATE_UNCHANGED:
6872 case UNDO_STATE_REFRESH:
6873 menu_set_sensitive(ifactory, "/Edit/Redo",
6874 undostruct->redo_state);
6877 g_warning("Redo state not recognized");
6882 /* callback functions */
6884 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6885 * includes "non-client" (windows-izm) in calculation, so this calculation
6886 * may not be accurate.
6888 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6889 GtkAllocation *allocation,
6890 GtkSHRuler *shruler)
6892 if (prefs_common.show_ruler) {
6893 gint char_width = 0, char_height = 0;
6894 gint line_width_in_chars;
6896 gtkut_get_font_size(GTK_WIDGET(widget),
6897 &char_width, &char_height);
6898 line_width_in_chars =
6899 (allocation->width - allocation->x) / char_width;
6901 /* got the maximum */
6902 gtk_ruler_set_range(GTK_RULER(shruler),
6903 0.0, line_width_in_chars, 0,
6904 /*line_width_in_chars*/ char_width);
6910 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6912 Compose *compose = (Compose *)data;
6915 gchar *folderidentifier;
6917 ac = account_find_from_id(
6918 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
6919 g_return_if_fail(ac != NULL);
6921 if (ac != compose->account)
6922 compose_select_account(compose, ac, FALSE);
6924 /* Set message save folder */
6925 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6926 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
6928 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
6929 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
6931 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6932 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6933 folderidentifier = folder_item_get_identifier(account_get_special_folder
6934 (compose->account, F_OUTBOX));
6935 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
6936 g_free(folderidentifier);
6940 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
6941 GtkTreeViewColumn *column, Compose *compose)
6943 compose_attach_property(compose);
6946 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6949 Compose *compose = (Compose *)data;
6950 GtkTreeSelection *attach_selection;
6951 gint attach_nr_selected;
6952 GtkItemFactory *ifactory;
6954 if (!event) return FALSE;
6956 if (event->button == 3) {
6957 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
6958 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
6959 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6961 if (attach_nr_selected > 0)
6963 menu_set_sensitive(ifactory, "/Remove", TRUE);
6964 menu_set_sensitive(ifactory, "/Properties...", TRUE);
6966 menu_set_sensitive(ifactory, "/Remove", FALSE);
6967 menu_set_sensitive(ifactory, "/Properties...", FALSE);
6970 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6971 NULL, NULL, event->button, event->time);
6978 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6981 Compose *compose = (Compose *)data;
6983 if (!event) return FALSE;
6985 switch (event->keyval) {
6987 compose_attach_remove_selected(compose);
6993 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6995 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6996 toolbar_comp_set_sensitive(compose, allow);
6997 menu_set_sensitive(ifactory, "/Message", allow);
6998 menu_set_sensitive(ifactory, "/Edit", allow);
7000 menu_set_sensitive(ifactory, "/Spelling", allow);
7002 menu_set_sensitive(ifactory, "/Options", allow);
7003 menu_set_sensitive(ifactory, "/Tools", allow);
7004 menu_set_sensitive(ifactory, "/Help", allow);
7006 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7010 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7012 Compose *compose = (Compose *)data;
7014 if (prefs_common.work_offline && !inc_offline_should_override())
7017 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7018 gtk_timeout_remove(compose->draft_timeout_tag);
7019 compose->draft_timeout_tag = -1;
7022 compose_send(compose);
7025 static void compose_send_later_cb(gpointer data, guint action,
7028 Compose *compose = (Compose *)data;
7031 val = compose_queue_sub(compose, NULL, NULL, TRUE);
7033 compose_close(compose);
7034 else if (val == -2) {
7035 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7039 void compose_draft (gpointer data)
7041 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7044 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7046 Compose *compose = (Compose *)data;
7050 MsgFlags flag = {0, 0};
7051 static gboolean lock = FALSE;
7052 MsgInfo *newmsginfo;
7054 gboolean target_locked = FALSE;
7058 draft = account_get_special_folder(compose->account, F_DRAFT);
7059 g_return_if_fail(draft != NULL);
7061 if (!g_mutex_trylock(compose->mutex)) {
7062 /* we don't want to lock the mutex once it's available,
7063 * because as the only other part of compose.c locking
7064 * it is compose_close - which means once unlocked,
7065 * the compose struct will be freed */
7066 debug_print("couldn't lock mutex, probably sending\n");
7072 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7073 G_DIR_SEPARATOR, compose);
7074 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7075 FILE_OP_ERROR(tmp, "fopen");
7079 /* chmod for security */
7080 if (change_file_mode_rw(fp, tmp) < 0) {
7081 FILE_OP_ERROR(tmp, "chmod");
7082 g_warning("can't change file mode\n");
7085 /* Save draft infos */
7086 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7087 fprintf(fp, "S:%s\n", compose->account->address);
7088 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7089 gchar *savefolderid;
7091 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7092 fprintf(fp, "SCF:%s\n", savefolderid);
7093 g_free(savefolderid);
7095 if (compose->return_receipt) {
7096 fprintf(fp, "RRCPT:1\n");
7098 if (compose->privacy_system) {
7099 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7100 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7101 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7105 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
7113 if (compose->targetinfo) {
7114 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7115 flag.perm_flags = target_locked?MSG_LOCKED:0;
7117 flag.tmp_flags = MSG_DRAFT;
7119 folder_item_scan(draft);
7120 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7123 if (action != COMPOSE_AUTO_SAVE)
7124 alertpanel_error(_("Could not save draft."));
7128 draft->mtime = 0; /* force updating */
7130 if (compose->mode == COMPOSE_REEDIT) {
7131 compose_remove_reedit_target(compose, TRUE);
7134 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7136 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7138 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
7140 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7141 if (compose_use_attach(compose))
7142 procmsg_msginfo_set_flags(newmsginfo, 0,
7143 MSG_HAS_ATTACHMENT);
7145 procmsg_msginfo_free(newmsginfo);
7148 folder_item_scan(draft);
7150 if (action == COMPOSE_QUIT_EDITING) {
7152 g_mutex_unlock(compose->mutex); /* must be done before closing */
7153 compose_close(compose);
7159 path = folder_item_fetch_msg(draft, msgnum);
7161 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
7164 if (g_stat(path, &s) < 0) {
7165 FILE_OP_ERROR(path, "stat");
7171 procmsg_msginfo_free(compose->targetinfo);
7172 compose->targetinfo = procmsg_msginfo_new();
7173 compose->targetinfo->msgnum = msgnum;
7174 compose->targetinfo->size = s.st_size;
7175 compose->targetinfo->mtime = s.st_mtime;
7176 compose->targetinfo->folder = draft;
7178 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
7179 compose->mode = COMPOSE_REEDIT;
7181 if (action == COMPOSE_AUTO_SAVE) {
7182 compose->autosaved_draft = compose->targetinfo;
7184 compose->modified = FALSE;
7185 compose_set_title(compose);
7189 g_mutex_unlock(compose->mutex);
7192 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7194 Compose *compose = (Compose *)data;
7197 if (compose->redirect_filename != NULL)
7200 file_list = filesel_select_multiple_files_open(_("Select file"));
7205 for ( tmp = file_list; tmp; tmp = tmp->next) {
7206 gchar *file = (gchar *) tmp->data;
7207 gchar *utf8_filename = conv_filename_to_utf8(file);
7208 compose_attach_append(compose, file, utf8_filename, NULL);
7209 compose_changed_cb(NULL, compose);
7211 g_free(utf8_filename);
7213 g_list_free(file_list);
7217 static void compose_insert_file_cb(gpointer data, guint action,
7220 Compose *compose = (Compose *)data;
7223 file_list = filesel_select_multiple_files_open(_("Select file"));
7228 for ( tmp = file_list; tmp; tmp = tmp->next) {
7229 gchar *file = (gchar *) tmp->data;
7230 gchar *filedup = g_strdup(file);
7231 gchar *shortfile = g_path_get_basename(filedup);
7232 ComposeInsertResult res;
7234 res = compose_insert_file(compose, file);
7235 if (res == COMPOSE_INSERT_READ_ERROR) {
7236 alertpanel_error(_("File '%s' could not be read."), shortfile);
7237 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7238 alertpanel_error(_("File '%s' contained invalid characters\n"
7239 "for the current encoding, insertion may be incorrect."), shortfile);
7245 g_list_free(file_list);
7249 static void compose_insert_sig_cb(gpointer data, guint action,
7252 Compose *compose = (Compose *)data;
7254 compose_insert_sig(compose, FALSE);
7257 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7261 Compose *compose = (Compose *)data;
7263 gtkut_widget_get_uposition(widget, &x, &y);
7264 prefs_common.compose_x = x;
7265 prefs_common.compose_y = y;
7267 if (compose->sending)
7269 compose_close_cb(compose, 0, NULL);
7273 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7275 Compose *compose = (Compose *)data;
7279 if (compose->exteditor_tag != -1) {
7280 if (!compose_ext_editor_kill(compose))
7285 if (compose->modified) {
7286 val = alertpanel(_("Discard message"),
7287 _("This message has been modified. Discard it?"),
7288 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7291 case G_ALERTDEFAULT:
7292 if (prefs_common.autosave)
7293 compose_remove_draft(compose);
7295 case G_ALERTALTERNATE:
7296 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7303 compose_close(compose);
7306 static void compose_set_encoding_cb(gpointer data, guint action,
7309 Compose *compose = (Compose *)data;
7311 if (GTK_CHECK_MENU_ITEM(widget)->active)
7312 compose->out_encoding = (CharSet)action;
7315 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7317 Compose *compose = (Compose *)data;
7319 addressbook_open(compose);
7322 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7324 Compose *compose = (Compose *)data;
7329 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7330 g_return_if_fail(tmpl != NULL);
7332 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7334 val = alertpanel(_("Apply template"), msg,
7335 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7338 if (val == G_ALERTDEFAULT)
7339 compose_template_apply(compose, tmpl, TRUE);
7340 else if (val == G_ALERTALTERNATE)
7341 compose_template_apply(compose, tmpl, FALSE);
7344 static void compose_ext_editor_cb(gpointer data, guint action,
7347 Compose *compose = (Compose *)data;
7349 compose_exec_ext_editor(compose);
7352 static void compose_undo_cb(Compose *compose)
7354 gboolean prev_autowrap = compose->autowrap;
7356 compose->autowrap = FALSE;
7357 undo_undo(compose->undostruct);
7358 compose->autowrap = prev_autowrap;
7361 static void compose_redo_cb(Compose *compose)
7363 gboolean prev_autowrap = compose->autowrap;
7365 compose->autowrap = FALSE;
7366 undo_redo(compose->undostruct);
7367 compose->autowrap = prev_autowrap;
7370 static void entry_cut_clipboard(GtkWidget *entry)
7372 if (GTK_IS_EDITABLE(entry))
7373 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7374 else if (GTK_IS_TEXT_VIEW(entry))
7375 gtk_text_buffer_cut_clipboard(
7376 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7377 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7381 static void entry_copy_clipboard(GtkWidget *entry)
7383 if (GTK_IS_EDITABLE(entry))
7384 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7385 else if (GTK_IS_TEXT_VIEW(entry))
7386 gtk_text_buffer_copy_clipboard(
7387 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7388 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7391 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7392 gboolean wrap, GdkAtom clip)
7394 if (GTK_IS_TEXT_VIEW(entry)) {
7395 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7396 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7397 GtkTextIter start_iter, end_iter;
7400 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7402 if (contents == NULL)
7405 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7406 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7408 start = gtk_text_iter_get_offset(&start_iter);
7410 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7413 end = start + strlen(contents);
7414 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7415 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7416 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7417 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7418 mark_start = gtk_text_buffer_get_insert(buffer);
7419 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7420 gtk_text_iter_backward_char(&start_iter);
7421 compose_beautify_paragraph(compose, &start_iter, TRUE);
7424 } else if (GTK_IS_EDITABLE(entry))
7425 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7429 static void entry_allsel(GtkWidget *entry)
7431 if (GTK_IS_EDITABLE(entry))
7432 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7433 else if (GTK_IS_TEXT_VIEW(entry)) {
7434 GtkTextIter startiter, enditer;
7435 GtkTextBuffer *textbuf;
7437 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7438 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7439 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7441 gtk_text_buffer_move_mark_by_name(textbuf,
7442 "selection_bound", &startiter);
7443 gtk_text_buffer_move_mark_by_name(textbuf,
7444 "insert", &enditer);
7448 static void compose_cut_cb(Compose *compose)
7450 if (compose->focused_editable &&
7451 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7452 entry_cut_clipboard(compose->focused_editable);
7455 static void compose_copy_cb(Compose *compose)
7457 if (compose->focused_editable &&
7458 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7459 entry_copy_clipboard(compose->focused_editable);
7462 static void compose_paste_cb(Compose *compose)
7465 GtkTextBuffer *buffer;
7467 if (compose->focused_editable &&
7468 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7469 entry_paste_clipboard(compose, compose->focused_editable,
7470 prefs_common.linewrap_pastes,
7471 GDK_SELECTION_CLIPBOARD);
7475 static void compose_paste_as_quote_cb(Compose *compose)
7477 gint wrap_quote = prefs_common.linewrap_quote;
7478 if (compose->focused_editable &&
7479 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7480 /* let text_insert() (called directly or at a later time
7481 * after the gtk_editable_paste_clipboard) know that
7482 * text is to be inserted as a quotation. implemented
7483 * by using a simple refcount... */
7484 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7485 G_OBJECT(compose->focused_editable),
7486 "paste_as_quotation"));
7487 g_object_set_data(G_OBJECT(compose->focused_editable),
7488 "paste_as_quotation",
7489 GINT_TO_POINTER(paste_as_quotation + 1));
7490 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7491 entry_paste_clipboard(compose, compose->focused_editable,
7492 prefs_common.linewrap_pastes,
7493 GDK_SELECTION_CLIPBOARD);
7494 prefs_common.linewrap_quote = wrap_quote;
7498 static void compose_paste_no_wrap_cb(Compose *compose)
7501 GtkTextBuffer *buffer;
7503 if (compose->focused_editable &&
7504 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7505 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7506 GDK_SELECTION_CLIPBOARD);
7510 static void compose_paste_wrap_cb(Compose *compose)
7513 GtkTextBuffer *buffer;
7515 if (compose->focused_editable &&
7516 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7517 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7518 GDK_SELECTION_CLIPBOARD);
7522 static void compose_allsel_cb(Compose *compose)
7524 if (compose->focused_editable &&
7525 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7526 entry_allsel(compose->focused_editable);
7529 static void textview_move_beginning_of_line (GtkTextView *text)
7531 GtkTextBuffer *buffer;
7535 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7537 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7538 mark = gtk_text_buffer_get_insert(buffer);
7539 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7540 gtk_text_iter_set_line_offset(&ins, 0);
7541 gtk_text_buffer_place_cursor(buffer, &ins);
7544 static void textview_move_forward_character (GtkTextView *text)
7546 GtkTextBuffer *buffer;
7550 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7552 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7553 mark = gtk_text_buffer_get_insert(buffer);
7554 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7555 if (gtk_text_iter_forward_cursor_position(&ins))
7556 gtk_text_buffer_place_cursor(buffer, &ins);
7559 static void textview_move_backward_character (GtkTextView *text)
7561 GtkTextBuffer *buffer;
7565 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7567 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7568 mark = gtk_text_buffer_get_insert(buffer);
7569 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7570 if (gtk_text_iter_backward_cursor_position(&ins))
7571 gtk_text_buffer_place_cursor(buffer, &ins);
7574 static void textview_move_forward_word (GtkTextView *text)
7576 GtkTextBuffer *buffer;
7581 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7583 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7584 mark = gtk_text_buffer_get_insert(buffer);
7585 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7586 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7587 if (gtk_text_iter_forward_word_ends(&ins, count)) {
7588 gtk_text_iter_backward_word_start(&ins);
7589 gtk_text_buffer_place_cursor(buffer, &ins);
7593 static void textview_move_backward_word (GtkTextView *text)
7595 GtkTextBuffer *buffer;
7600 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7602 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7603 mark = gtk_text_buffer_get_insert(buffer);
7604 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7605 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7606 if (gtk_text_iter_backward_word_starts(&ins, 1))
7607 gtk_text_buffer_place_cursor(buffer, &ins);
7610 static void textview_move_end_of_line (GtkTextView *text)
7612 GtkTextBuffer *buffer;
7616 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7618 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7619 mark = gtk_text_buffer_get_insert(buffer);
7620 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7621 if (gtk_text_iter_forward_to_line_end(&ins))
7622 gtk_text_buffer_place_cursor(buffer, &ins);
7625 static void textview_move_next_line (GtkTextView *text)
7627 GtkTextBuffer *buffer;
7632 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7634 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7635 mark = gtk_text_buffer_get_insert(buffer);
7636 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7637 offset = gtk_text_iter_get_line_offset(&ins);
7638 if (gtk_text_iter_forward_line(&ins)) {
7639 gtk_text_iter_set_line_offset(&ins, offset);
7640 gtk_text_buffer_place_cursor(buffer, &ins);
7644 static void textview_move_previous_line (GtkTextView *text)
7646 GtkTextBuffer *buffer;
7651 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7653 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7654 mark = gtk_text_buffer_get_insert(buffer);
7655 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7656 offset = gtk_text_iter_get_line_offset(&ins);
7657 if (gtk_text_iter_backward_line(&ins)) {
7658 gtk_text_iter_set_line_offset(&ins, offset);
7659 gtk_text_buffer_place_cursor(buffer, &ins);
7663 static void textview_delete_forward_character (GtkTextView *text)
7665 GtkTextBuffer *buffer;
7667 GtkTextIter ins, end_iter;
7669 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7671 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7672 mark = gtk_text_buffer_get_insert(buffer);
7673 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7675 if (gtk_text_iter_forward_char(&end_iter)) {
7676 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7680 static void textview_delete_backward_character (GtkTextView *text)
7682 GtkTextBuffer *buffer;
7684 GtkTextIter ins, end_iter;
7686 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7688 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7689 mark = gtk_text_buffer_get_insert(buffer);
7690 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7692 if (gtk_text_iter_backward_char(&end_iter)) {
7693 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7697 static void textview_delete_forward_word (GtkTextView *text)
7699 GtkTextBuffer *buffer;
7701 GtkTextIter ins, end_iter;
7703 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7705 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7706 mark = gtk_text_buffer_get_insert(buffer);
7707 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7709 if (gtk_text_iter_forward_word_end(&end_iter)) {
7710 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7714 static void textview_delete_backward_word (GtkTextView *text)
7716 GtkTextBuffer *buffer;
7718 GtkTextIter ins, end_iter;
7720 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7722 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7723 mark = gtk_text_buffer_get_insert(buffer);
7724 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7726 if (gtk_text_iter_backward_word_start(&end_iter)) {
7727 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7731 static void textview_delete_line (GtkTextView *text)
7733 GtkTextBuffer *buffer;
7735 GtkTextIter ins, start_iter, end_iter;
7738 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7740 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7741 mark = gtk_text_buffer_get_insert(buffer);
7742 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7745 gtk_text_iter_set_line_offset(&start_iter, 0);
7748 if (gtk_text_iter_ends_line(&end_iter))
7749 found = gtk_text_iter_forward_char(&end_iter);
7751 found = gtk_text_iter_forward_to_line_end(&end_iter);
7754 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7757 static void textview_delete_to_line_end (GtkTextView *text)
7759 GtkTextBuffer *buffer;
7761 GtkTextIter ins, end_iter;
7764 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7766 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7767 mark = gtk_text_buffer_get_insert(buffer);
7768 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7770 if (gtk_text_iter_ends_line(&end_iter))
7771 found = gtk_text_iter_forward_char(&end_iter);
7773 found = gtk_text_iter_forward_to_line_end(&end_iter);
7775 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7778 static void compose_advanced_action_cb(Compose *compose,
7779 ComposeCallAdvancedAction action)
7781 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7783 void (*do_action) (GtkTextView *text);
7784 } action_table[] = {
7785 {textview_move_beginning_of_line},
7786 {textview_move_forward_character},
7787 {textview_move_backward_character},
7788 {textview_move_forward_word},
7789 {textview_move_backward_word},
7790 {textview_move_end_of_line},
7791 {textview_move_next_line},
7792 {textview_move_previous_line},
7793 {textview_delete_forward_character},
7794 {textview_delete_backward_character},
7795 {textview_delete_forward_word},
7796 {textview_delete_backward_word},
7797 {textview_delete_line},
7798 {NULL}, /* gtk_stext_delete_line_n */
7799 {textview_delete_to_line_end}
7802 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
7804 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
7805 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
7806 if (action_table[action].do_action)
7807 action_table[action].do_action(text);
7809 g_warning("Not implemented yet.");
7813 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
7817 if (GTK_IS_EDITABLE(widget)) {
7818 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
7819 gtk_editable_set_position(GTK_EDITABLE(widget),
7822 if (widget->parent && widget->parent->parent
7823 && widget->parent->parent->parent) {
7824 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
7825 gint y = widget->allocation.y;
7826 gint height = widget->allocation.height;
7827 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
7828 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
7830 if (y < (int)shown->value) {
7831 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
7833 if (y + height > (int)shown->value + (int)shown->page_size) {
7834 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
7835 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7836 y + height - (int)shown->page_size - 1);
7838 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7839 (int)shown->upper - (int)shown->page_size - 1);
7846 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
7847 compose->focused_editable = widget;
7850 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
7852 compose->modified = TRUE;
7853 compose_set_title(compose);
7856 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
7858 Compose *compose = (Compose *)data;
7861 compose_wrap_all_full(compose, TRUE);
7863 compose_beautify_paragraph(compose, NULL, TRUE);
7866 static void compose_toggle_autowrap_cb(gpointer data, guint action,
7869 Compose *compose = (Compose *)data;
7870 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7871 if (compose->autowrap)
7872 compose_wrap_all_full(compose, TRUE);
7873 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7876 static void compose_toggle_sign_cb(gpointer data, guint action,
7879 Compose *compose = (Compose *)data;
7881 if (GTK_CHECK_MENU_ITEM(widget)->active)
7882 compose->use_signing = TRUE;
7884 compose->use_signing = FALSE;
7887 static void compose_toggle_encrypt_cb(gpointer data, guint action,
7890 Compose *compose = (Compose *)data;
7892 if (GTK_CHECK_MENU_ITEM(widget)->active)
7893 compose->use_encryption = TRUE;
7895 compose->use_encryption = FALSE;
7898 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
7900 g_free(compose->privacy_system);
7902 compose->privacy_system = g_strdup(account->default_privacy_system);
7903 compose_update_privacy_system_menu_item(compose, warn);
7906 static void compose_toggle_ruler_cb(gpointer data, guint action,
7909 Compose *compose = (Compose *)data;
7911 if (GTK_CHECK_MENU_ITEM(widget)->active) {
7912 gtk_widget_show(compose->ruler_hbox);
7913 prefs_common.show_ruler = TRUE;
7915 gtk_widget_hide(compose->ruler_hbox);
7916 gtk_widget_queue_resize(compose->edit_vbox);
7917 prefs_common.show_ruler = FALSE;
7921 static void compose_attach_drag_received_cb (GtkWidget *widget,
7922 GdkDragContext *context,
7925 GtkSelectionData *data,
7930 Compose *compose = (Compose *)user_data;
7933 if (gdk_atom_name(data->type) &&
7934 !strcmp(gdk_atom_name(data->type), "text/uri-list")
7935 && gtk_drag_get_source_widget(context) !=
7936 mainwindow_get_mainwindow()->summaryview->ctree) {
7937 list = uri_list_extract_filenames((const gchar *)data->data);
7938 for (tmp = list; tmp != NULL; tmp = tmp->next)
7939 compose_attach_append
7940 (compose, (const gchar *)tmp->data,
7941 (const gchar *)tmp->data, NULL);
7942 if (list) compose_changed_cb(NULL, compose);
7943 list_free_strings(list);
7945 } else if (gtk_drag_get_source_widget(context)
7946 == mainwindow_get_mainwindow()->summaryview->ctree) {
7947 /* comes from our summaryview */
7948 SummaryView * summaryview = NULL;
7949 GSList * list = NULL, *cur = NULL;
7951 if (mainwindow_get_mainwindow())
7952 summaryview = mainwindow_get_mainwindow()->summaryview;
7955 list = summary_get_selected_msg_list(summaryview);
7957 for (cur = list; cur; cur = cur->next) {
7958 MsgInfo *msginfo = (MsgInfo *)cur->data;
7961 file = procmsg_get_message_file_full(msginfo,
7964 compose_attach_append(compose, (const gchar *)file,
7965 (const gchar *)file, "message/rfc822");
7973 static gboolean compose_drag_drop(GtkWidget *widget,
7974 GdkDragContext *drag_context,
7976 guint time, gpointer user_data)
7978 /* not handling this signal makes compose_insert_drag_received_cb
7983 static void compose_insert_drag_received_cb (GtkWidget *widget,
7984 GdkDragContext *drag_context,
7987 GtkSelectionData *data,
7992 Compose *compose = (Compose *)user_data;
7995 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
7997 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7998 list = uri_list_extract_filenames((const gchar *)data->data);
7999 for (tmp = list; tmp != NULL; tmp = tmp->next) {
8000 compose_insert_file(compose, (const gchar *)tmp->data);
8002 list_free_strings(list);
8004 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8007 #if GTK_CHECK_VERSION(2, 8, 0)
8008 /* do nothing, handled by GTK */
8010 gchar *tmpfile = get_tmp_file();
8011 str_write_to_file((const gchar *)data->data, tmpfile);
8012 compose_insert_file(compose, tmpfile);
8015 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8019 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8022 static void compose_header_drag_received_cb (GtkWidget *widget,
8023 GdkDragContext *drag_context,
8026 GtkSelectionData *data,
8031 GtkEditable *entry = (GtkEditable *)user_data;
8032 gchar *email = (gchar *)data->data;
8034 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8037 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8038 gchar *decoded=g_new(gchar, strlen(email));
8041 email += strlen("mailto:");
8042 decode_uri(decoded, email); /* will fit */
8043 gtk_editable_delete_text(entry, 0, -1);
8044 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8045 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8049 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8052 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8055 Compose *compose = (Compose *)data;
8057 if (GTK_CHECK_MENU_ITEM(widget)->active)
8058 compose->return_receipt = TRUE;
8060 compose->return_receipt = FALSE;
8063 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8066 Compose *compose = (Compose *)data;
8068 if (GTK_CHECK_MENU_ITEM(widget)->active)
8069 compose->remove_references = TRUE;
8071 compose->remove_references = FALSE;
8074 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8076 ComposeHeaderEntry *headerentry)
8078 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
8079 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
8080 !(event->state & GDK_MODIFIER_MASK) &&
8081 (event->keyval == GDK_BackSpace) &&
8082 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
8083 gtk_container_remove
8084 (GTK_CONTAINER(headerentry->compose->header_table),
8085 headerentry->combo);
8086 gtk_container_remove
8087 (GTK_CONTAINER(headerentry->compose->header_table),
8088 headerentry->entry);
8089 headerentry->compose->header_list =
8090 g_slist_remove(headerentry->compose->header_list,
8092 g_free(headerentry);
8093 } else if (event->keyval == GDK_Tab) {
8094 if (headerentry->compose->header_last == headerentry) {
8095 /* Override default next focus, and give it to subject_entry
8096 * instead of notebook tabs
8098 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8099 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8106 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8107 ComposeHeaderEntry *headerentry)
8109 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8110 headerentry->compose->header_list =
8111 g_slist_append(headerentry->compose->header_list,
8114 compose_create_header_entry(headerentry->compose);
8115 g_signal_handlers_disconnect_matched
8116 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8117 0, 0, NULL, NULL, headerentry);
8119 /* Automatically scroll down */
8120 compose_show_first_last_header(headerentry->compose, FALSE);
8126 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8128 GtkAdjustment *vadj;
8130 g_return_if_fail(compose);
8131 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8132 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8134 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8135 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8138 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8139 const gchar *text, gint len, Compose *compose)
8141 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8142 (G_OBJECT(compose->text), "paste_as_quotation"));
8145 g_return_if_fail(text != NULL);
8147 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8148 G_CALLBACK(text_inserted),
8150 if (paste_as_quotation) {
8157 new_text = g_strndup(text, len);
8158 if (prefs_common.quotemark && *prefs_common.quotemark)
8159 qmark = prefs_common.quotemark;
8163 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8164 gtk_text_buffer_place_cursor(buffer, iter);
8166 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8168 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8169 GINT_TO_POINTER(paste_as_quotation - 1));
8171 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8172 gtk_text_buffer_place_cursor(buffer, iter);
8174 if (strcmp(text, "\n") || automatic_break
8175 || gtk_text_iter_starts_line(iter))
8176 gtk_text_buffer_insert(buffer, iter, text, len);
8178 debug_print("insert nowrap \\n\n");
8179 gtk_text_buffer_insert_with_tags_by_name(buffer,
8180 iter, text, len, "no_join", NULL);
8184 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8186 compose_beautify_paragraph(compose, iter, FALSE);
8188 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8189 gtk_text_buffer_delete_mark(buffer, mark);
8191 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8192 G_CALLBACK(text_inserted),
8194 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8196 if (prefs_common.autosave &&
8197 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8198 compose->draft_timeout_tag = gtk_timeout_add
8199 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8201 static gint compose_defer_auto_save_draft(Compose *compose)
8203 compose->draft_timeout_tag = -1;
8204 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8209 static void compose_check_all(Compose *compose)
8211 if (compose->gtkaspell)
8212 gtkaspell_check_all(compose->gtkaspell);
8215 static void compose_highlight_all(Compose *compose)
8217 if (compose->gtkaspell)
8218 gtkaspell_highlight_all(compose->gtkaspell);
8221 static void compose_check_backwards(Compose *compose)
8223 if (compose->gtkaspell)
8224 gtkaspell_check_backwards(compose->gtkaspell);
8226 GtkItemFactory *ifactory;
8227 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8228 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8229 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8233 static void compose_check_forwards_go(Compose *compose)
8235 if (compose->gtkaspell)
8236 gtkaspell_check_forwards_go(compose->gtkaspell);
8238 GtkItemFactory *ifactory;
8239 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8240 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8241 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8247 *\brief Guess originating forward account from MsgInfo and several
8248 * "common preference" settings. Return NULL if no guess.
8250 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8252 PrefsAccount *account = NULL;
8254 g_return_val_if_fail(msginfo, NULL);
8255 g_return_val_if_fail(msginfo->folder, NULL);
8256 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8258 if (msginfo->folder->prefs->enable_default_account)
8259 account = account_find_from_id(msginfo->folder->prefs->default_account);
8262 account = msginfo->folder->folder->account;
8264 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8266 Xstrdup_a(to, msginfo->to, return NULL);
8267 extract_address(to);
8268 account = account_find_from_address(to);
8271 if (!account && prefs_common.forward_account_autosel) {
8273 if (!procheader_get_header_from_msginfo
8274 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8275 extract_address(cc);
8276 account = account_find_from_address(cc);
8283 static gboolean compose_close(Compose *compose)
8287 if (!g_mutex_trylock(compose->mutex)) {
8288 /* we have to wait for the (possibly deferred by auto-save)
8289 * drafting to be done, before destroying the compose under
8291 debug_print("waiting for drafting to finish...\n");
8292 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8295 g_return_val_if_fail(compose, FALSE);
8296 gtkut_widget_get_uposition(compose->window, &x, &y);
8297 prefs_common.compose_x = x;
8298 prefs_common.compose_y = y;
8299 g_mutex_unlock(compose->mutex);
8300 compose_destroy(compose);
8305 * Add entry field for each address in list.
8306 * \param compose E-Mail composition object.
8307 * \param listAddress List of (formatted) E-Mail addresses.
8309 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8314 addr = ( gchar * ) node->data;
8315 compose_entry_append( compose, addr, COMPOSE_TO );
8316 node = g_list_next( node );
8320 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8324 GSList *new_msglist = NULL;
8325 MsgInfo *tmp_msginfo = NULL;
8326 gboolean originally_enc = FALSE;
8327 Compose *compose = NULL;
8329 g_return_if_fail(msgview != NULL);
8331 g_return_if_fail(msginfo_list != NULL);
8333 if (g_slist_length(msginfo_list) == 1) {
8334 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8335 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8337 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8338 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8339 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8340 orig_msginfo, mimeinfo);
8341 if (tmp_msginfo != NULL) {
8342 new_msglist = g_slist_append(NULL, tmp_msginfo);
8343 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8344 originally_enc = TRUE;
8350 body = messageview_get_selection(msgview);
8353 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8354 procmsg_msginfo_free(tmp_msginfo);
8355 g_slist_free(new_msglist);
8357 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8359 if (originally_enc) {
8360 compose_force_encryption(compose, compose->account, FALSE);