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;
3286 compose->autowrap = FALSE;
3288 buffer = gtk_text_view_get_buffer(text);
3289 undo_wrapping(compose->undostruct, TRUE);
3294 mark = gtk_text_buffer_get_insert(buffer);
3295 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3298 /* move to paragraph start */
3299 gtk_text_iter_set_line_offset(&iter, 0);
3300 if (gtk_text_iter_ends_line(&iter)) {
3301 while (gtk_text_iter_ends_line(&iter) &&
3302 gtk_text_iter_forward_line(&iter))
3305 while (gtk_text_iter_backward_line(&iter)) {
3306 if (gtk_text_iter_ends_line(&iter)) {
3307 gtk_text_iter_forward_line(&iter);
3313 /* go until paragraph end (empty line) */
3315 while (!gtk_text_iter_ends_line(&iter)) {
3316 gchar *scanpos = NULL;
3317 /* parse table - in order of priority */
3319 const gchar *needle; /* token */
3321 /* token search function */
3322 gchar *(*search) (const gchar *haystack,
3323 const gchar *needle);
3324 /* part parsing function */
3325 gboolean (*parse) (const gchar *start,
3326 const gchar *scanpos,
3330 /* part to URI function */
3331 gchar *(*build_uri) (const gchar *bp,
3335 static struct table parser[] = {
3336 {"http://", strcasestr, get_uri_part, make_uri_string},
3337 {"https://", strcasestr, get_uri_part, make_uri_string},
3338 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3339 {"www.", strcasestr, get_uri_part, make_http_string},
3340 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3341 {"@", strcasestr, get_email_part, make_email_string}
3343 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3344 gint last_index = PARSE_ELEMS;
3346 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3350 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3351 G_CALLBACK(text_inserted),
3354 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3357 uri_start = uri_stop = -1;
3359 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3363 if (startq_offset == -1) {
3364 startq_offset = gtk_text_iter_get_offset(&iter);
3368 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3369 if (startq_offset == -1)
3370 startq_offset = gtk_text_iter_get_offset(&iter);
3372 if (startq_offset == -1)
3373 noq_offset = gtk_text_iter_get_offset(&iter);
3376 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3379 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3380 prefs_common.linewrap_len,
3382 GtkTextIter prev, next, cur;
3384 if (prev_autowrap != FALSE || force) {
3385 automatic_break = TRUE;
3386 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3387 automatic_break = FALSE;
3388 } else if (quote_str && wrap_quote) {
3389 automatic_break = TRUE;
3390 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3391 automatic_break = FALSE;
3394 /* remove trailing spaces */
3396 gtk_text_iter_backward_char(&cur);
3398 while (!gtk_text_iter_starts_line(&cur)) {
3401 gtk_text_iter_backward_char(&cur);
3402 wc = gtk_text_iter_get_char(&cur);
3403 if (!g_unichar_isspace(wc))
3407 if (!gtk_text_iter_equal(&prev, &next)) {
3408 gtk_text_buffer_delete(buffer, &prev, &next);
3410 gtk_text_iter_forward_char(&break_pos);
3414 gtk_text_buffer_insert(buffer, &break_pos,
3418 compose_join_next_line(compose, buffer, &iter, quote_str);
3420 /* move iter to current line start */
3421 gtk_text_iter_set_line_offset(&iter, 0);
3428 /* move iter to next line start */
3434 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3435 G_CALLBACK(text_inserted),
3438 while (!gtk_text_iter_ends_line(&end_of_line)) {
3439 gtk_text_iter_forward_char(&end_of_line);
3441 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3443 nouri_start = gtk_text_iter_get_offset(&iter);
3444 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3446 walk_pos = gtk_text_iter_get_offset(&iter);
3447 /* FIXME: this looks phony. scanning for anything in the parse table */
3448 for (n = 0; n < PARSE_ELEMS; n++) {
3451 tmp = parser[n].search(walk, parser[n].needle);
3453 if (scanpos == NULL || tmp < scanpos) {
3462 /* check if URI can be parsed */
3463 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3464 (const gchar **)&ep, FALSE)
3465 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3469 strlen(parser[last_index].needle);
3472 uri_start = walk_pos + (bp - o_walk);
3473 uri_stop = walk_pos + (ep - o_walk);
3477 gtk_text_iter_forward_line(&iter);
3480 if (startq_offset != -1) {
3481 GtkTextIter startquote, endquote;
3482 gtk_text_buffer_get_iter_at_offset(
3483 buffer, &startquote, startq_offset);
3485 gtk_text_buffer_apply_tag_by_name(
3486 buffer, "quote", &startquote, &endquote);
3488 } else if (noq_offset != -1) {
3489 GtkTextIter startnoquote, endnoquote;
3490 gtk_text_buffer_get_iter_at_offset(
3491 buffer, &startnoquote, noq_offset);
3493 gtk_text_buffer_remove_tag_by_name(
3494 buffer, "quote", &startnoquote, &endnoquote);
3499 GtkTextIter nouri_start_iter, nouri_end_iter;
3500 gtk_text_buffer_get_iter_at_offset(
3501 buffer, &nouri_start_iter, nouri_start);
3502 gtk_text_buffer_get_iter_at_offset(
3503 buffer, &nouri_end_iter, nouri_stop);
3504 gtk_text_buffer_remove_tag_by_name(
3505 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3507 if (uri_start > 0 && uri_stop > 0) {
3508 GtkTextIter uri_start_iter, uri_end_iter;
3509 gtk_text_buffer_get_iter_at_offset(
3510 buffer, &uri_start_iter, uri_start);
3511 gtk_text_buffer_get_iter_at_offset(
3512 buffer, &uri_end_iter, uri_stop);
3513 gtk_text_buffer_apply_tag_by_name(
3514 buffer, "link", &uri_start_iter, &uri_end_iter);
3520 undo_wrapping(compose->undostruct, FALSE);
3521 compose->autowrap = prev_autowrap;
3524 void compose_action_cb(void *data)
3526 Compose *compose = (Compose *)data;
3527 compose_wrap_all(compose);
3530 static void compose_wrap_all(Compose *compose)
3532 compose_wrap_all_full(compose, FALSE);
3535 static void compose_wrap_all_full(Compose *compose, gboolean force)
3537 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3538 GtkTextBuffer *buffer;
3541 buffer = gtk_text_view_get_buffer(text);
3543 gtk_text_buffer_get_start_iter(buffer, &iter);
3544 while (!gtk_text_iter_is_end(&iter))
3545 compose_beautify_paragraph(compose, &iter, force);
3549 static void compose_set_title(Compose *compose)
3555 edited = compose->modified ? _(" [Edited]") : "";
3557 subject = gtk_editable_get_chars(
3558 GTK_EDITABLE(compose->subject_entry), 0, -1);
3560 if (subject && strlen(subject))
3561 str = g_strdup_printf(_("%s - Compose message%s"),
3564 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3565 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3571 * compose_current_mail_account:
3573 * Find a current mail account (the currently selected account, or the
3574 * default account, if a news account is currently selected). If a
3575 * mail account cannot be found, display an error message.
3577 * Return value: Mail account, or NULL if not found.
3579 static PrefsAccount *
3580 compose_current_mail_account(void)
3584 if (cur_account && cur_account->protocol != A_NNTP)
3587 ac = account_get_default();
3588 if (!ac || ac->protocol == A_NNTP) {
3589 alertpanel_error(_("Account for sending mail is not specified.\n"
3590 "Please select a mail account before sending."));
3597 static void compose_select_account(Compose *compose, PrefsAccount *account,
3600 GtkItemFactory *ifactory;
3602 g_return_if_fail(account != NULL);
3604 compose->account = account;
3606 compose_set_title(compose);
3608 ifactory = gtk_item_factory_from_widget(compose->menubar);
3610 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3611 menu_set_active(ifactory, "/Options/Sign", TRUE);
3613 menu_set_active(ifactory, "/Options/Sign", FALSE);
3614 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3615 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3617 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3619 activate_privacy_system(compose, account, FALSE);
3621 if (!init && compose->mode != COMPOSE_REDIRECT)
3622 compose_insert_sig(compose, TRUE);
3625 gboolean compose_check_for_valid_recipient(Compose *compose) {
3626 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3627 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3628 gboolean recipient_found = FALSE;
3632 /* free to and newsgroup list */
3633 slist_free_strings(compose->to_list);
3634 g_slist_free(compose->to_list);
3635 compose->to_list = NULL;
3637 slist_free_strings(compose->newsgroup_list);
3638 g_slist_free(compose->newsgroup_list);
3639 compose->newsgroup_list = NULL;
3641 /* search header entries for to and newsgroup entries */
3642 for (list = compose->header_list; list; list = list->next) {
3645 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3646 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3648 if (entry[0] != '\0') {
3649 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3650 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3651 compose->to_list = address_list_append(compose->to_list, entry);
3652 recipient_found = TRUE;
3655 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3656 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3657 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3658 recipient_found = TRUE;
3665 return recipient_found;
3668 static gboolean compose_check_for_set_recipients(Compose *compose)
3670 if (compose->account->set_autocc && compose->account->auto_cc) {
3671 gboolean found_other = FALSE;
3673 /* search header entries for to and newsgroup entries */
3674 for (list = compose->header_list; list; list = list->next) {
3677 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3678 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3680 if (strcmp(entry, compose->account->auto_cc)
3681 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3691 aval = alertpanel(_("Send"),
3692 _("The only recipient is the default CC address. Send anyway?"),
3693 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3694 if (aval != G_ALERTALTERNATE)
3698 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3699 gboolean found_other = FALSE;
3701 /* search header entries for to and newsgroup entries */
3702 for (list = compose->header_list; list; list = list->next) {
3705 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3706 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3708 if (strcmp(entry, compose->account->auto_cc)
3709 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3719 aval = alertpanel(_("Send"),
3720 _("The only recipient is the default BCC address. Send anyway?"),
3721 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3722 if (aval != G_ALERTALTERNATE)
3729 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3733 if (compose_check_for_valid_recipient(compose) == FALSE) {
3734 alertpanel_error(_("Recipient is not specified."));
3738 if (compose_check_for_set_recipients(compose) == FALSE) {
3742 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3743 if (*str == '\0' && check_subject == TRUE) {
3746 aval = alertpanel(_("Send"),
3747 _("Subject is empty. Send it anyway?"),
3748 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3749 if (aval != G_ALERTALTERNATE)
3756 gint compose_send(Compose *compose)
3763 compose_allow_user_actions (compose, FALSE);
3764 compose->sending = TRUE;
3766 if (compose_check_entries(compose, TRUE) == FALSE)
3769 val = compose_queue(compose, &msgnum, &folder);
3773 alertpanel_error(_("Could not queue message for sending:\n\n"
3774 "Charset conversion failed."));
3775 } else if (val == -3) {
3776 alertpanel_error(_("Could not queue message for sending:\n\n"
3777 "Signature failed."));
3778 } else if (val == -2 && errno != 0) {
3779 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3781 alertpanel_error(_("Could not queue message for sending."));
3787 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3788 compose->sending = FALSE;
3789 compose_close(compose);
3790 /* No more compose access in the normal codepath
3791 * after this point! */
3796 alertpanel_error(_("The message was queued but could not be "
3797 "sent.\nUse \"Send queued messages\" from "
3798 "the main window to retry."));
3799 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3800 compose->sending = FALSE;
3801 compose->modified = TRUE;
3802 compose_allow_user_actions (compose, TRUE);
3807 msgpath = folder_item_fetch_msg(folder, msgnum);
3808 val = procmsg_send_message_queue(msgpath);
3811 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3812 compose->sending = FALSE;
3813 compose_allow_user_actions (compose, TRUE);
3815 folder_item_remove_msg(folder, msgnum);
3816 folder_item_scan(folder);
3821 folder_item_remove_msg(folder, msgnum);
3822 folder_item_scan(folder);
3823 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3824 compose_close(compose);
3826 alertpanel_error(_("The message was queued but could not be "
3827 "sent.\nUse \"Send queued messages\" from "
3828 "the main window to retry."));
3829 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3830 compose_allow_user_actions (compose, TRUE);
3831 compose->modified = TRUE;
3832 compose->sending = FALSE;
3840 compose_allow_user_actions (compose, TRUE);
3841 compose->sending = FALSE;
3842 compose->modified = TRUE;
3847 static gboolean compose_use_attach(Compose *compose)
3849 GtkTreeModel *model = gtk_tree_view_get_model
3850 (GTK_TREE_VIEW(compose->attach_clist));
3851 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3854 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3857 gchar buf[BUFFSIZE];
3859 gboolean first_to_address;
3860 gboolean first_cc_address;
3862 ComposeHeaderEntry *headerentry;
3863 const gchar *headerentryname;
3867 debug_print("Writing redirect header\n");
3869 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3870 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3872 first_to_address = TRUE;
3873 for (list = compose->header_list; list; list = list->next) {
3874 headerentry = ((ComposeHeaderEntry *)list->data);
3875 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3877 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3878 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3879 Xstrdup_a(str, entstr, return -1);
3881 if (str[0] != '\0') {
3882 compose_convert_header
3883 (compose, buf, sizeof(buf), str,
3884 strlen("Resent-To") + 2, TRUE);
3886 if (first_to_address) {
3887 fprintf(fp, "Resent-To: ");
3888 first_to_address = FALSE;
3892 fprintf(fp, "%s", buf);
3896 if (!first_to_address) {
3900 first_cc_address = TRUE;
3901 for (list = compose->header_list; list; list = list->next) {
3902 headerentry = ((ComposeHeaderEntry *)list->data);
3903 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3905 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3906 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3907 Xstrdup_a(str, strg, return -1);
3909 if (str[0] != '\0') {
3910 compose_convert_header
3911 (compose, buf, sizeof(buf), str,
3912 strlen("Resent-Cc") + 2, TRUE);
3914 if (first_cc_address) {
3915 fprintf(fp, "Resent-Cc: ");
3916 first_cc_address = FALSE;
3920 fprintf(fp, "%s", buf);
3924 if (!first_cc_address) {
3931 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3933 gchar buf[BUFFSIZE];
3935 const gchar *entstr;
3936 /* struct utsname utsbuf; */
3938 g_return_val_if_fail(fp != NULL, -1);
3939 g_return_val_if_fail(compose->account != NULL, -1);
3940 g_return_val_if_fail(compose->account->address != NULL, -1);
3943 get_rfc822_date(buf, sizeof(buf));
3944 fprintf(fp, "Resent-Date: %s\n", buf);
3947 if (compose->account->name && *compose->account->name) {
3948 compose_convert_header
3949 (compose, buf, sizeof(buf), compose->account->name,
3950 strlen("From: "), TRUE);
3951 fprintf(fp, "Resent-From: %s <%s>\n",
3952 buf, compose->account->address);
3954 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3957 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3958 if (*entstr != '\0') {
3959 Xstrdup_a(str, entstr, return -1);
3962 compose_convert_header(compose, buf, sizeof(buf), str,
3963 strlen("Subject: "), FALSE);
3964 fprintf(fp, "Subject: %s\n", buf);
3968 /* Resent-Message-ID */
3969 if (compose->account->gen_msgid) {
3970 generate_msgid(buf, sizeof(buf));
3971 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3972 compose->msgid = g_strdup(buf);
3975 compose_redirect_write_headers_from_headerlist(compose, fp);
3977 /* separator between header and body */
3983 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3987 gchar buf[BUFFSIZE];
3989 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
3990 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3994 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3995 /* should filter returnpath, delivered-to */
3996 if (g_ascii_strncasecmp(buf, "Return-Path:",
3997 strlen("Return-Path:")) == 0 ||
3998 g_ascii_strncasecmp(buf, "Delivered-To:",
3999 strlen("Delivered-To:")) == 0 ||
4000 g_ascii_strncasecmp(buf, "Received:",
4001 strlen("Received:")) == 0 ||
4002 g_ascii_strncasecmp(buf, "Subject:",
4003 strlen("Subject:")) == 0 ||
4004 g_ascii_strncasecmp(buf, "X-UIDL:",
4005 strlen("X-UIDL:")) == 0)
4008 if (fputs(buf, fdest) == -1)
4011 if (!prefs_common.redirect_keep_from) {
4012 if (g_ascii_strncasecmp(buf, "From:",
4013 strlen("From:")) == 0) {
4014 fputs(" (by way of ", fdest);
4015 if (compose->account->name
4016 && *compose->account->name) {
4017 compose_convert_header
4018 (compose, buf, sizeof(buf),
4019 compose->account->name,
4022 fprintf(fdest, "%s <%s>",
4024 compose->account->address);
4026 fprintf(fdest, "%s",
4027 compose->account->address);
4032 if (fputs("\n", fdest) == -1)
4036 compose_redirect_write_headers(compose, fdest);
4038 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4039 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4052 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
4054 GtkTextBuffer *buffer;
4055 GtkTextIter start, end;
4058 const gchar *out_codeset;
4059 EncodingType encoding;
4060 MimeInfo *mimemsg, *mimetext;
4063 /* create message MimeInfo */
4064 mimemsg = procmime_mimeinfo_new();
4065 mimemsg->type = MIMETYPE_MESSAGE;
4066 mimemsg->subtype = g_strdup("rfc822");
4067 mimemsg->content = MIMECONTENT_MEM;
4068 mimemsg->tmp = TRUE; /* must free content later */
4069 mimemsg->data.mem = compose_get_header(compose);
4071 /* Create text part MimeInfo */
4072 /* get all composed text */
4073 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4074 gtk_text_buffer_get_start_iter(buffer, &start);
4075 gtk_text_buffer_get_end_iter(buffer, &end);
4076 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4077 if (is_ascii_str(chars)) {
4080 out_codeset = CS_US_ASCII;
4081 encoding = ENC_7BIT;
4083 const gchar *src_codeset = CS_INTERNAL;
4085 out_codeset = conv_get_charset_str(compose->out_encoding);
4088 gchar *test_conv_global_out = NULL;
4089 gchar *test_conv_reply = NULL;
4091 /* automatic mode. be automatic. */
4092 codeconv_set_strict(TRUE);
4094 out_codeset = conv_get_outgoing_charset_str();
4096 debug_print("trying to convert to %s\n", out_codeset);
4097 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4100 if (!test_conv_global_out && compose->orig_charset
4101 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4102 out_codeset = compose->orig_charset;
4103 debug_print("failure; trying to convert to %s\n", out_codeset);
4104 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4107 if (!test_conv_global_out && !test_conv_reply) {
4109 out_codeset = CS_INTERNAL;
4110 debug_print("failure; finally using %s\n", out_codeset);
4112 g_free(test_conv_global_out);
4113 g_free(test_conv_reply);
4114 codeconv_set_strict(FALSE);
4117 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4118 out_codeset = CS_ISO_8859_1;
4120 if (prefs_common.encoding_method == CTE_BASE64)
4121 encoding = ENC_BASE64;
4122 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4123 encoding = ENC_QUOTED_PRINTABLE;
4124 else if (prefs_common.encoding_method == CTE_8BIT)
4125 encoding = ENC_8BIT;
4127 encoding = procmime_get_encoding_for_charset(out_codeset);
4129 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4130 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4132 if (action == COMPOSE_WRITE_FOR_SEND) {
4133 codeconv_set_strict(TRUE);
4134 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4135 codeconv_set_strict(FALSE);
4141 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4142 "to the specified %s charset.\n"
4143 "Send it as %s?"), out_codeset, src_codeset);
4144 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4145 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4148 if (aval != G_ALERTALTERNATE) {
4153 out_codeset = src_codeset;
4159 out_codeset = src_codeset;
4165 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4166 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4167 strstr(buf, "\nFrom ") != NULL) {
4168 encoding = ENC_QUOTED_PRINTABLE;
4172 mimetext = procmime_mimeinfo_new();
4173 mimetext->content = MIMECONTENT_MEM;
4174 mimetext->tmp = TRUE; /* must free content later */
4175 mimetext->data.mem = buf;
4176 mimetext->type = MIMETYPE_TEXT;
4177 mimetext->subtype = g_strdup("plain");
4178 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4179 g_strdup(out_codeset));
4180 /* protect trailing spaces when signing message */
4181 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4182 privacy_system_can_sign(compose->privacy_system)) {
4183 encoding = ENC_QUOTED_PRINTABLE;
4186 /* check for line length limit */
4187 if (action == COMPOSE_WRITE_FOR_SEND &&
4188 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4189 check_line_length(buf, 1000, &line) < 0) {
4193 msg = g_strdup_printf
4194 (_("Line %d exceeds the line length limit (998 bytes).\n"
4195 "The contents of the message might be broken on the way to the delivery.\n"
4197 "Send it anyway?"), line + 1);
4198 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4200 if (aval != G_ALERTALTERNATE) {
4205 if (encoding != ENC_UNKNOWN)
4206 procmime_encode_content(mimetext, encoding);
4208 /* append attachment parts */
4209 if (compose_use_attach(compose)) {
4210 MimeInfo *mimempart;
4211 gchar *boundary = NULL;
4212 mimempart = procmime_mimeinfo_new();
4213 mimempart->content = MIMECONTENT_EMPTY;
4214 mimempart->type = MIMETYPE_MULTIPART;
4215 mimempart->subtype = g_strdup("mixed");
4220 boundary = generate_mime_boundary(NULL);
4221 } while (strstr(buf, boundary) != NULL);
4223 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4226 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4228 g_node_append(mimempart->node, mimetext->node);
4229 g_node_append(mimemsg->node, mimempart->node);
4231 compose_add_attachments(compose, mimempart);
4233 g_node_append(mimemsg->node, mimetext->node);
4235 /* sign message if sending */
4236 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4237 privacy_system_can_sign(compose->privacy_system))
4238 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4241 procmime_write_mimeinfo(mimemsg, fp);
4243 procmime_mimeinfo_free_all(mimemsg);
4248 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4250 GtkTextBuffer *buffer;
4251 GtkTextIter start, end;
4256 if ((fp = g_fopen(file, "wb")) == NULL) {
4257 FILE_OP_ERROR(file, "fopen");
4261 /* chmod for security */
4262 if (change_file_mode_rw(fp, file) < 0) {
4263 FILE_OP_ERROR(file, "chmod");
4264 g_warning("can't change file mode\n");
4267 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4268 gtk_text_buffer_get_start_iter(buffer, &start);
4269 gtk_text_buffer_get_end_iter(buffer, &end);
4270 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4272 chars = conv_codeset_strdup
4273 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4276 if (!chars) return -1;
4279 len = strlen(chars);
4280 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4281 FILE_OP_ERROR(file, "fwrite");
4290 if (fclose(fp) == EOF) {
4291 FILE_OP_ERROR(file, "fclose");
4298 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4301 MsgInfo *msginfo = compose->targetinfo;
4303 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4304 if (!msginfo) return -1;
4306 if (!force && MSG_IS_LOCKED(msginfo->flags))
4309 item = msginfo->folder;
4310 g_return_val_if_fail(item != NULL, -1);
4312 if (procmsg_msg_exist(msginfo) &&
4313 (folder_has_parent_of_type(item, F_QUEUE) ||
4314 folder_has_parent_of_type(item, F_DRAFT)
4315 || msginfo == compose->autosaved_draft)) {
4316 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4317 g_warning("can't remove the old message\n");
4325 void compose_remove_draft(Compose *compose)
4328 MsgInfo *msginfo = compose->targetinfo;
4329 drafts = account_get_special_folder(compose->account, F_DRAFT);
4331 if (procmsg_msg_exist(msginfo)) {
4332 folder_item_remove_msg(drafts, msginfo->msgnum);
4337 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
4339 return compose_queue_sub (compose, msgnum, item, FALSE);
4341 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
4348 static gboolean lock = FALSE;
4349 PrefsAccount *mailac = NULL, *newsac = NULL;
4351 debug_print("queueing message...\n");
4352 g_return_val_if_fail(compose->account != NULL, -1);
4356 if (compose_check_entries(compose, check_subject) == FALSE) {
4361 if (!compose->to_list && !compose->newsgroup_list) {
4362 g_warning("can't get recipient list.");
4367 if (compose->to_list) {
4368 if (compose->account->protocol != A_NNTP)
4369 mailac = compose->account;
4370 else if (cur_account && cur_account->protocol != A_NNTP)
4371 mailac = cur_account;
4372 else if (!(mailac = compose_current_mail_account())) {
4374 alertpanel_error(_("No account for sending mails available!"));
4379 if (compose->newsgroup_list) {
4380 if (compose->account->protocol == A_NNTP)
4381 newsac = compose->account;
4382 else if (!newsac->protocol != A_NNTP) {
4384 alertpanel_error(_("No account for posting news available!"));
4389 /* write queue header */
4390 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4391 G_DIR_SEPARATOR, compose);
4392 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4393 FILE_OP_ERROR(tmp, "fopen");
4398 if (change_file_mode_rw(fp, tmp) < 0) {
4399 FILE_OP_ERROR(tmp, "chmod");
4400 g_warning("can't change file mode\n");
4403 /* queueing variables */
4404 fprintf(fp, "AF:\n");
4405 fprintf(fp, "NF:0\n");
4406 fprintf(fp, "PS:10\n");
4407 fprintf(fp, "SRH:1\n");
4408 fprintf(fp, "SFN:\n");
4409 fprintf(fp, "DSR:\n");
4411 fprintf(fp, "MID:<%s>\n", compose->msgid);
4413 fprintf(fp, "MID:\n");
4414 fprintf(fp, "CFG:\n");
4415 fprintf(fp, "PT:0\n");
4416 fprintf(fp, "S:%s\n", compose->account->address);
4417 fprintf(fp, "RQ:\n");
4419 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4421 fprintf(fp, "SSV:\n");
4423 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4425 fprintf(fp, "NSV:\n");
4426 fprintf(fp, "SSH:\n");
4427 /* write recepient list */
4428 if (compose->to_list) {
4429 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4430 for (cur = compose->to_list->next; cur != NULL;
4432 fprintf(fp, ",<%s>", (gchar *)cur->data);
4435 /* write newsgroup list */
4436 if (compose->newsgroup_list) {
4438 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4439 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4440 fprintf(fp, ",%s", (gchar *)cur->data);
4443 /* Sylpheed account IDs */
4445 fprintf(fp, "MAID:%d\n", mailac->account_id);
4447 fprintf(fp, "NAID:%d\n", newsac->account_id);
4449 if (compose->privacy_system != NULL) {
4450 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4451 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4452 if (compose->use_encryption) {
4455 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4456 if (encdata != NULL) {
4457 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4458 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4459 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4461 } /* else we finally dont want to encrypt */
4463 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4464 /* and if encdata was null, it means there's been a problem in
4471 /* Save copy folder */
4472 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4473 gchar *savefolderid;
4475 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4476 fprintf(fp, "SCF:%s\n", savefolderid);
4477 g_free(savefolderid);
4479 /* Save copy folder */
4480 if (compose->return_receipt) {
4481 fprintf(fp, "RRCPT:1\n");
4483 /* Message-ID of message replying to */
4484 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4487 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4488 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4491 /* Message-ID of message forwarding to */
4492 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4495 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4496 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4501 if (compose->redirect_filename != NULL) {
4502 if (compose_redirect_write_to_file(compose, fp) < 0) {
4511 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4516 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4520 if (fclose(fp) == EOF) {
4521 FILE_OP_ERROR(tmp, "fclose");
4527 queue = account_get_special_folder(compose->account, F_QUEUE);
4529 g_warning("can't find queue folder\n");
4534 folder_item_scan(queue);
4535 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
4536 g_warning("can't queue the message\n");
4544 if (compose->mode == COMPOSE_REEDIT) {
4545 compose_remove_reedit_target(compose, FALSE);
4548 if ((msgnum != NULL) && (item != NULL)) {
4556 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4559 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4561 struct stat statbuf;
4562 gchar *type, *subtype;
4563 GtkTreeModel *model;
4566 model = gtk_tree_view_get_model(tree_view);
4568 if (!gtk_tree_model_get_iter_first(model, &iter))
4571 gtk_tree_model_get(model, &iter,
4575 mimepart = procmime_mimeinfo_new();
4576 mimepart->content = MIMECONTENT_FILE;
4577 mimepart->data.filename = g_strdup(ainfo->file);
4578 mimepart->tmp = FALSE; /* or we destroy our attachment */
4579 mimepart->offset = 0;
4581 stat(ainfo->file, &statbuf);
4582 mimepart->length = statbuf.st_size;
4584 type = g_strdup(ainfo->content_type);
4586 if (!strchr(type, '/')) {
4588 type = g_strdup("application/octet-stream");
4591 subtype = strchr(type, '/') + 1;
4592 *(subtype - 1) = '\0';
4593 mimepart->type = procmime_get_media_type(type);
4594 mimepart->subtype = g_strdup(subtype);
4597 if (mimepart->type == MIMETYPE_MESSAGE &&
4598 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4599 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4601 g_hash_table_insert(mimepart->typeparameters,
4602 g_strdup("name"), g_strdup(ainfo->name));
4603 g_hash_table_insert(mimepart->dispositionparameters,
4604 g_strdup("filename"), g_strdup(ainfo->name));
4605 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4608 if (compose->use_signing) {
4609 if (ainfo->encoding == ENC_7BIT)
4610 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4611 else if (ainfo->encoding == ENC_8BIT)
4612 ainfo->encoding = ENC_BASE64;
4615 procmime_encode_content(mimepart, ainfo->encoding);
4617 g_node_append(parent->node, mimepart->node);
4618 } while (gtk_tree_model_iter_next(model, &iter));
4621 #define QUOTE_IF_REQUIRED(out, str) \
4623 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4627 len = strlen(str) + 3; \
4628 if ((__tmp = alloca(len)) == NULL) { \
4629 g_warning("can't allocate memory\n"); \
4630 g_string_free(header, TRUE); \
4633 g_snprintf(__tmp, len, "\"%s\"", str); \
4638 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4639 g_warning("can't allocate memory\n"); \
4640 g_string_free(header, TRUE); \
4643 strcpy(__tmp, str); \
4649 #define IS_IN_CUSTOM_HEADER(header) \
4650 (compose->account->add_customhdr && \
4651 custom_header_find(compose->account->customhdr_list, header) != NULL)
4653 static void compose_add_headerfield_from_headerlist(Compose *compose,
4655 const gchar *fieldname,
4656 const gchar *seperator)
4658 gchar *str, *fieldname_w_colon, *trans_fieldname;
4659 gboolean add_field = FALSE;
4661 ComposeHeaderEntry *headerentry;
4662 const gchar * headerentryname;
4665 if (IS_IN_CUSTOM_HEADER(fieldname))
4668 debug_print("Adding %s-fields\n", fieldname);
4670 fieldstr = g_string_sized_new(64);
4672 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4673 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4675 for (list = compose->header_list; list; list = list->next) {
4676 headerentry = ((ComposeHeaderEntry *)list->data);
4677 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4679 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4680 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4682 if (str[0] != '\0') {
4684 g_string_append(fieldstr, seperator);
4685 g_string_append(fieldstr, str);
4694 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4695 compose_convert_header
4696 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4697 strlen(fieldname) + 2, TRUE);
4698 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4702 g_free(fieldname_w_colon);
4703 g_string_free(fieldstr, TRUE);
4708 static gchar *compose_get_header(Compose *compose)
4710 gchar buf[BUFFSIZE];
4711 const gchar *entry_str;
4715 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4718 g_return_val_if_fail(compose->account != NULL, NULL);
4719 g_return_val_if_fail(compose->account->address != NULL, NULL);
4721 header = g_string_sized_new(64);
4724 if (compose->account->add_date) {
4725 get_rfc822_date(buf, sizeof(buf));
4726 g_string_append_printf(header, "Date: %s\n", buf);
4730 if (compose->account->name && *compose->account->name) {
4731 compose_convert_header
4732 (compose, buf, sizeof(buf), compose->account->name,
4733 strlen("From: "), TRUE);
4734 QUOTE_IF_REQUIRED(name, buf);
4735 g_string_append_printf(header, "From: %s <%s>\n",
4736 name, compose->account->address);
4738 g_string_append_printf(header, "From: %s\n", compose->account->address);
4741 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4744 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4747 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4750 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4753 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4755 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4758 compose_convert_header(compose, buf, sizeof(buf), str,
4759 strlen("Subject: "), FALSE);
4760 g_string_append_printf(header, "Subject: %s\n", buf);
4766 if (compose->account->gen_msgid) {
4767 generate_msgid(buf, sizeof(buf));
4768 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4769 compose->msgid = g_strdup(buf);
4772 if (compose->remove_references == FALSE) {
4774 if (compose->inreplyto && compose->to_list)
4775 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4778 if (compose->references)
4779 g_string_append_printf(header, "References: %s\n", compose->references);
4783 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4786 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4789 if (compose->account->organization &&
4790 strlen(compose->account->organization) &&
4791 !IS_IN_CUSTOM_HEADER("Organization")) {
4792 compose_convert_header(compose, buf, sizeof(buf),
4793 compose->account->organization,
4794 strlen("Organization: "), FALSE);
4795 g_string_append_printf(header, "Organization: %s\n", buf);
4798 /* Program version and system info */
4799 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4800 !compose->newsgroup_list) {
4801 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4803 gtk_major_version, gtk_minor_version, gtk_micro_version,
4806 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4807 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4809 gtk_major_version, gtk_minor_version, gtk_micro_version,
4813 /* custom headers */
4814 if (compose->account->add_customhdr) {
4817 for (cur = compose->account->customhdr_list; cur != NULL;
4819 CustomHeader *chdr = (CustomHeader *)cur->data;
4821 if (custom_header_is_allowed(chdr->name)) {
4822 compose_convert_header
4823 (compose, buf, sizeof(buf),
4824 chdr->value ? chdr->value : "",
4825 strlen(chdr->name) + 2, FALSE);
4826 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4832 switch (compose->priority) {
4833 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4834 "X-Priority: 1 (Highest)\n");
4836 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4837 "X-Priority: 2 (High)\n");
4839 case PRIORITY_NORMAL: break;
4840 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4841 "X-Priority: 4 (Low)\n");
4843 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4844 "X-Priority: 5 (Lowest)\n");
4846 default: debug_print("compose: priority unknown : %d\n",
4850 /* Request Return Receipt */
4851 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4852 if (compose->return_receipt) {
4853 if (compose->account->name
4854 && *compose->account->name) {
4855 compose_convert_header(compose, buf, sizeof(buf),
4856 compose->account->name,
4857 strlen("Disposition-Notification-To: "),
4859 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4861 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4865 /* get special headers */
4866 for (list = compose->header_list; list; list = list->next) {
4867 ComposeHeaderEntry *headerentry;
4870 gchar *headername_wcolon;
4871 gchar *headername_trans;
4874 gboolean standard_header = FALSE;
4876 headerentry = ((ComposeHeaderEntry *)list->data);
4878 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4879 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4884 if (!strstr(tmp, ":")) {
4885 headername_wcolon = g_strconcat(tmp, ":", NULL);
4886 headername = g_strdup(tmp);
4888 headername_wcolon = g_strdup(tmp);
4889 headername = g_strdup(strtok(tmp, ":"));
4893 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4894 Xstrdup_a(headervalue, entry_str, return NULL);
4895 subst_char(headervalue, '\r', ' ');
4896 subst_char(headervalue, '\n', ' ');
4897 string = std_headers;
4898 while (*string != NULL) {
4899 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4900 if (!strcmp(headername_trans,headername_wcolon))
4901 standard_header = TRUE;
4904 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4905 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
4908 g_free(headername_wcolon);
4912 g_string_free(header, FALSE);
4917 #undef IS_IN_CUSTOM_HEADER
4919 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
4920 gint header_len, gboolean addr_field)
4922 gchar *tmpstr = NULL;
4923 const gchar *out_codeset = NULL;
4925 g_return_if_fail(src != NULL);
4926 g_return_if_fail(dest != NULL);
4928 if (len < 1) return;
4930 tmpstr = g_strdup(src);
4932 subst_char(tmpstr, '\n', ' ');
4933 subst_char(tmpstr, '\r', ' ');
4936 if (!g_utf8_validate(tmpstr, -1, NULL)) {
4937 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
4938 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
4943 codeconv_set_strict(TRUE);
4944 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4945 conv_get_charset_str(compose->out_encoding));
4946 codeconv_set_strict(FALSE);
4948 if (!dest || *dest == '\0') {
4949 gchar *test_conv_global_out = NULL;
4950 gchar *test_conv_reply = NULL;
4952 /* automatic mode. be automatic. */
4953 codeconv_set_strict(TRUE);
4955 out_codeset = conv_get_outgoing_charset_str();
4957 debug_print("trying to convert to %s\n", out_codeset);
4958 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4961 if (!test_conv_global_out && compose->orig_charset) {
4962 out_codeset = compose->orig_charset;
4963 debug_print("failure; trying to convert to %s\n", out_codeset);
4964 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4967 if (!test_conv_global_out && !test_conv_reply) {
4969 out_codeset = CS_INTERNAL;
4970 debug_print("finally using %s\n", out_codeset);
4972 g_free(test_conv_global_out);
4973 g_free(test_conv_reply);
4974 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4976 codeconv_set_strict(FALSE);
4981 static void compose_create_header_entry(Compose *compose)
4983 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4987 GList *combo_list = NULL;
4989 const gchar *header = NULL;
4990 ComposeHeaderEntry *headerentry;
4991 gboolean standard_header = FALSE;
4993 headerentry = g_new0(ComposeHeaderEntry, 1);
4996 combo = gtk_combo_new();
4998 while(*string != NULL) {
4999 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
5002 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5003 g_list_free(combo_list);
5004 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5005 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5006 G_CALLBACK(compose_grab_focus_cb), compose);
5007 gtk_widget_show(combo);
5008 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5009 if (compose->header_last) {
5010 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5012 while (*string != NULL) {
5013 if (!strcmp(*string, last_header_entry))
5014 standard_header = TRUE;
5017 if (standard_header)
5018 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5020 if (!compose->header_last || !standard_header) {
5021 switch(compose->account->protocol) {
5023 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5026 header = prefs_common.trans_hdr ? _("To:") : "To:";
5031 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5033 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5034 G_CALLBACK(compose_grab_focus_cb), compose);
5037 entry = gtk_entry_new();
5038 gtk_widget_show(entry);
5039 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);
5041 g_signal_connect(G_OBJECT(entry), "key-press-event",
5042 G_CALLBACK(compose_headerentry_key_press_event_cb),
5044 g_signal_connect(G_OBJECT(entry), "changed",
5045 G_CALLBACK(compose_headerentry_changed_cb),
5047 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5048 G_CALLBACK(compose_grab_focus_cb), compose);
5051 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5052 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5053 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5054 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5055 G_CALLBACK(compose_header_drag_received_cb),
5057 g_signal_connect(G_OBJECT(entry), "drag-drop",
5058 G_CALLBACK(compose_drag_drop),
5061 address_completion_register_entry(GTK_ENTRY(entry));
5063 headerentry->compose = compose;
5064 headerentry->combo = combo;
5065 headerentry->entry = entry;
5066 headerentry->headernum = compose->header_nextrow;
5068 compose->header_nextrow++;
5069 compose->header_last = headerentry;
5072 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5074 ComposeHeaderEntry *last_header;
5076 last_header = compose->header_last;
5078 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5079 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5082 static GtkWidget *compose_create_header(Compose *compose)
5086 GtkWidget *from_optmenu_hbox;
5087 GtkWidget *header_scrolledwin;
5088 GtkWidget *header_table;
5092 /* header labels and entries */
5093 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5094 gtk_widget_show(header_scrolledwin);
5095 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5097 header_table = gtk_table_new(2, 2, FALSE);
5098 gtk_widget_show(header_table);
5099 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
5100 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5101 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5104 /* option menu for selecting accounts */
5105 hbox = gtk_hbox_new(FALSE, 0);
5106 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
5107 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
5108 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
5110 from_optmenu_hbox = compose_account_option_menu_create(compose);
5111 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5112 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5115 compose->header_table = header_table;
5116 compose->header_list = NULL;
5117 compose->header_nextrow = count;
5119 compose_create_header_entry(compose);
5121 compose->table = NULL;
5123 return header_scrolledwin ;
5126 GtkWidget *compose_create_attach(Compose *compose)
5128 GtkWidget *attach_scrwin;
5129 GtkWidget *attach_clist;
5131 GtkListStore *store;
5132 GtkCellRenderer *renderer;
5133 GtkTreeViewColumn *column;
5134 GtkTreeSelection *selection;
5136 /* attachment list */
5137 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5138 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5139 GTK_POLICY_AUTOMATIC,
5140 GTK_POLICY_AUTOMATIC);
5141 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5143 store = gtk_list_store_new(N_ATTACH_COLS,
5148 G_TYPE_AUTO_POINTER,
5150 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5151 (GTK_TREE_MODEL(store)));
5152 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5153 g_object_unref(store);
5155 renderer = gtk_cell_renderer_text_new();
5156 column = gtk_tree_view_column_new_with_attributes
5157 (_("Mime type"), renderer, "text",
5158 COL_MIMETYPE, NULL);
5159 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5161 renderer = gtk_cell_renderer_text_new();
5162 column = gtk_tree_view_column_new_with_attributes
5163 (_("Size"), renderer, "text",
5165 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5167 renderer = gtk_cell_renderer_text_new();
5168 column = gtk_tree_view_column_new_with_attributes
5169 (_("Name"), renderer, "text",
5171 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5173 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5174 prefs_common.enable_rules_hint);
5175 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5176 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5178 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5179 G_CALLBACK(attach_selected), compose);
5180 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5181 G_CALLBACK(attach_button_pressed), compose);
5182 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5183 G_CALLBACK(attach_key_pressed), compose);
5186 gtk_drag_dest_set(attach_clist,
5187 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5188 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5189 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5190 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5191 G_CALLBACK(compose_attach_drag_received_cb),
5193 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5194 G_CALLBACK(compose_drag_drop),
5197 compose->attach_scrwin = attach_scrwin;
5198 compose->attach_clist = attach_clist;
5200 return attach_scrwin;
5203 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5204 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5206 static GtkWidget *compose_create_others(Compose *compose)
5209 GtkWidget *savemsg_checkbtn;
5210 GtkWidget *savemsg_entry;
5211 GtkWidget *savemsg_select;
5214 gchar *folderidentifier;
5216 /* Table for settings */
5217 table = gtk_table_new(3, 1, FALSE);
5218 gtk_widget_show(table);
5219 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5222 /* Save Message to folder */
5223 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5224 gtk_widget_show(savemsg_checkbtn);
5225 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5226 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5227 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5229 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5230 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5232 savemsg_entry = gtk_entry_new();
5233 gtk_widget_show(savemsg_entry);
5234 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5235 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5236 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5237 G_CALLBACK(compose_grab_focus_cb), compose);
5238 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5239 folderidentifier = folder_item_get_identifier(account_get_special_folder
5240 (compose->account, F_OUTBOX));
5241 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5242 g_free(folderidentifier);
5245 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5246 gtk_widget_show(savemsg_select);
5247 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5248 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5249 G_CALLBACK(compose_savemsg_select_cb),
5254 compose->savemsg_checkbtn = savemsg_checkbtn;
5255 compose->savemsg_entry = savemsg_entry;
5260 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5262 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5263 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5266 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5271 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5274 path = folder_item_get_identifier(dest);
5276 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5280 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5283 #define BLOCK_WRAP() { \
5284 prev_autowrap = compose->autowrap; \
5285 buffer = gtk_text_view_get_buffer( \
5286 GTK_TEXT_VIEW(compose->text)); \
5287 compose->autowrap = FALSE; \
5289 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5290 G_CALLBACK(compose_changed_cb), \
5292 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5293 G_CALLBACK(text_inserted), \
5296 #define UNBLOCK_WRAP() { \
5297 compose->autowrap = prev_autowrap; \
5298 if (compose->autowrap) \
5299 compose_wrap_all(compose); \
5301 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5302 G_CALLBACK(compose_changed_cb), \
5304 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5305 G_CALLBACK(text_inserted), \
5310 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5314 GtkTextBuffer *buffer;
5316 if (event->button == 3) {
5318 GtkTextIter sel_start, sel_end;
5319 gboolean stuff_selected;
5321 /* move the cursor to allow GtkAspell to check the word
5322 * under the mouse */
5323 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5324 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5326 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5329 stuff_selected = gtk_text_buffer_get_selection_bounds(
5330 GTK_TEXT_VIEW(text)->buffer,
5331 &sel_start, &sel_end);
5333 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5334 /* reselect stuff */
5336 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5337 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5338 &sel_start, &sel_end);
5340 return FALSE; /* pass the event so that the right-click goes through */
5343 if (event->button == 2) {
5345 entry_paste_clipboard(compose, compose->focused_editable,
5346 prefs_common.linewrap_pastes,
5347 GDK_SELECTION_PRIMARY);
5354 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
5360 GtkWidget *handlebox;
5362 GtkWidget *notebook;
5367 GtkWidget *subject_hbox;
5368 GtkWidget *subject_frame;
5369 GtkWidget *subject_entry;
5373 GtkWidget *edit_vbox;
5374 GtkWidget *ruler_hbox;
5376 GtkWidget *scrolledwin;
5378 GtkTextBuffer *buffer;
5379 GtkClipboard *clipboard;
5381 UndoMain *undostruct;
5383 gchar *titles[N_ATTACH_COLS];
5384 guint n_menu_entries;
5387 gboolean success[1];
5388 GtkWidget *popupmenu;
5389 GtkItemFactory *popupfactory;
5390 GtkItemFactory *ifactory;
5391 GtkWidget *tmpl_menu;
5393 GtkWidget *menuitem;
5396 GtkAspell * gtkaspell = NULL;
5399 static GdkGeometry geometry;
5401 g_return_val_if_fail(account != NULL, NULL);
5403 debug_print("Creating compose window...\n");
5404 compose = g_new0(Compose, 1);
5406 titles[COL_MIMETYPE] = _("MIME type");
5407 titles[COL_SIZE] = _("Size");
5408 titles[COL_NAME] = _("Name");
5410 compose->account = account;
5412 compose->mutex = g_mutex_new();
5413 compose->set_cursor_pos = -1;
5415 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5416 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5417 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5419 if (!geometry.max_width) {
5420 geometry.max_width = gdk_screen_width();
5421 geometry.max_height = gdk_screen_height();
5424 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5425 &geometry, GDK_HINT_MAX_SIZE);
5426 if (!geometry.min_width) {
5427 geometry.min_width = 600;
5428 geometry.min_height = 480;
5430 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5431 &geometry, GDK_HINT_MIN_SIZE);
5432 gtk_widget_set_uposition(window, prefs_common.compose_x,
5433 prefs_common.compose_y);
5435 g_signal_connect(G_OBJECT(window), "delete_event",
5436 G_CALLBACK(compose_delete_cb), compose);
5437 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5438 gtk_widget_realize(window);
5440 gtkut_widget_set_composer_icon(window);
5442 vbox = gtk_vbox_new(FALSE, 0);
5443 gtk_container_add(GTK_CONTAINER(window), vbox);
5445 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5446 menubar = menubar_create(window, compose_entries,
5447 n_menu_entries, "<Compose>", compose);
5448 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5450 if (prefs_common.toolbar_detachable) {
5451 handlebox = gtk_handle_box_new();
5453 handlebox = gtk_hbox_new(FALSE, 0);
5455 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5457 gtk_widget_realize(handlebox);
5458 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5461 vbox2 = gtk_vbox_new(FALSE, 2);
5462 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5463 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5466 notebook = gtk_notebook_new();
5467 gtk_widget_set_size_request(notebook, -1, 130);
5468 gtk_widget_show(notebook);
5470 /* header labels and entries */
5471 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
5472 /* attachment list */
5473 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
5475 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
5478 subject_hbox = gtk_hbox_new(FALSE, 0);
5479 gtk_widget_show(subject_hbox);
5481 subject_frame = gtk_frame_new(NULL);
5482 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5483 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5484 gtk_widget_show(subject_frame);
5486 subject = gtk_hbox_new(FALSE, 0);
5487 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5488 gtk_widget_show(subject);
5490 label = gtk_label_new(_("Subject:"));
5491 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5492 gtk_widget_show(label);
5494 subject_entry = gtk_entry_new();
5495 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5496 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5497 G_CALLBACK(compose_grab_focus_cb), compose);
5498 gtk_widget_show(subject_entry);
5499 compose->subject_entry = subject_entry;
5500 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5502 edit_vbox = gtk_vbox_new(FALSE, 0);
5504 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5507 ruler_hbox = gtk_hbox_new(FALSE, 0);
5508 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5510 ruler = gtk_shruler_new();
5511 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5512 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5516 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5517 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5518 GTK_POLICY_AUTOMATIC,
5519 GTK_POLICY_AUTOMATIC);
5520 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5522 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5523 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5525 text = gtk_text_view_new();
5526 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5527 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5528 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5529 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5530 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5532 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5534 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5535 G_CALLBACK(compose_edit_size_alloc),
5537 g_signal_connect(G_OBJECT(buffer), "changed",
5538 G_CALLBACK(compose_changed_cb), compose);
5539 g_signal_connect(G_OBJECT(text), "grab_focus",
5540 G_CALLBACK(compose_grab_focus_cb), compose);
5541 g_signal_connect(G_OBJECT(buffer), "insert_text",
5542 G_CALLBACK(text_inserted), compose);
5543 g_signal_connect(G_OBJECT(text), "button_press_event",
5544 G_CALLBACK(text_clicked), compose);
5545 g_signal_connect(G_OBJECT(subject_entry), "changed",
5546 G_CALLBACK(compose_changed_cb), compose);
5549 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5550 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5551 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5552 g_signal_connect(G_OBJECT(text), "drag_data_received",
5553 G_CALLBACK(compose_insert_drag_received_cb),
5555 g_signal_connect(G_OBJECT(text), "drag-drop",
5556 G_CALLBACK(compose_drag_drop),
5558 gtk_widget_show_all(vbox);
5560 /* pane between attach clist and text */
5561 paned = gtk_vpaned_new();
5562 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5563 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5564 gtk_paned_add1(GTK_PANED(paned), notebook);
5565 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5566 gtk_widget_show_all(paned);
5569 if (prefs_common.textfont) {
5570 PangoFontDescription *font_desc;
5572 font_desc = pango_font_description_from_string
5573 (prefs_common.textfont);
5575 gtk_widget_modify_font(text, font_desc);
5576 pango_font_description_free(font_desc);
5580 color[0] = quote_color;
5581 cmap = gdk_drawable_get_colormap(window->window);
5582 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5583 if (success[0] == FALSE) {
5586 g_warning("Compose: color allocation failed.\n");
5587 style = gtk_widget_get_style(text);
5588 quote_color = style->black;
5591 n_entries = sizeof(compose_popup_entries) /
5592 sizeof(compose_popup_entries[0]);
5593 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5594 "<Compose>", &popupfactory,
5597 ifactory = gtk_item_factory_from_widget(menubar);
5598 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5599 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5600 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5602 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5604 undostruct = undo_init(text);
5605 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5608 address_completion_start(window);
5610 compose->window = window;
5611 compose->vbox = vbox;
5612 compose->menubar = menubar;
5613 compose->handlebox = handlebox;
5615 compose->vbox2 = vbox2;
5617 compose->paned = paned;
5619 compose->edit_vbox = edit_vbox;
5620 compose->ruler_hbox = ruler_hbox;
5621 compose->ruler = ruler;
5622 compose->scrolledwin = scrolledwin;
5623 compose->text = text;
5625 compose->focused_editable = NULL;
5627 compose->popupmenu = popupmenu;
5628 compose->popupfactory = popupfactory;
5630 compose->tmpl_menu = tmpl_menu;
5632 compose->mode = mode;
5634 compose->targetinfo = NULL;
5635 compose->replyinfo = NULL;
5636 compose->fwdinfo = NULL;
5638 compose->replyto = NULL;
5640 compose->bcc = NULL;
5641 compose->followup_to = NULL;
5643 compose->ml_post = NULL;
5645 compose->inreplyto = NULL;
5646 compose->references = NULL;
5647 compose->msgid = NULL;
5648 compose->boundary = NULL;
5650 compose->autowrap = prefs_common.autowrap;
5652 compose->use_signing = FALSE;
5653 compose->use_encryption = FALSE;
5654 compose->privacy_system = NULL;
5656 compose->modified = FALSE;
5658 compose->return_receipt = FALSE;
5660 compose->to_list = NULL;
5661 compose->newsgroup_list = NULL;
5663 compose->undostruct = undostruct;
5665 compose->sig_str = NULL;
5667 compose->exteditor_file = NULL;
5668 compose->exteditor_pid = -1;
5669 compose->exteditor_tag = -1;
5670 compose->draft_timeout_tag = -1;
5673 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5674 if (mode != COMPOSE_REDIRECT) {
5675 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5676 strcmp(prefs_common.dictionary, _("None"))) {
5677 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5678 prefs_common.dictionary,
5679 conv_get_locale_charset_str(),
5680 prefs_common.misspelled_col,
5681 prefs_common.check_while_typing,
5682 prefs_common.use_alternate,
5683 GTK_TEXT_VIEW(text),
5684 GTK_WINDOW(compose->window));
5686 alertpanel_error(_("Spell checker could not "
5688 gtkaspell_checkers_strerror());
5689 gtkaspell_checkers_reset_error();
5691 if (!gtkaspell_set_sug_mode(gtkaspell,
5692 prefs_common.aspell_sugmode)) {
5693 debug_print("Aspell: could not set "
5694 "suggestion mode %s\n",
5695 gtkaspell_checkers_strerror());
5696 gtkaspell_checkers_reset_error();
5699 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5703 compose->gtkaspell = gtkaspell;
5706 compose_select_account(compose, account, TRUE);
5708 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5709 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5710 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5712 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5713 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5715 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5716 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5719 if (account->protocol != A_NNTP)
5720 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5722 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5724 addressbook_set_target_compose(compose);
5726 if (mode != COMPOSE_REDIRECT)
5727 compose_set_template_menu(compose);
5729 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5730 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5733 compose_list = g_list_append(compose_list, compose);
5735 if (!prefs_common.show_ruler)
5736 gtk_widget_hide(ruler_hbox);
5738 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5739 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5740 prefs_common.show_ruler);
5743 compose->priority = PRIORITY_NORMAL;
5744 compose_update_priority_menu_item(compose);
5746 compose_set_out_encoding(compose);
5749 compose_update_actions_menu(compose);
5751 /* Privacy Systems menu */
5752 compose_update_privacy_systems_menu(compose);
5754 activate_privacy_system(compose, account, TRUE);
5755 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5756 gtk_widget_show(window);
5761 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5767 gint num = 0, def_menu = 0;
5769 accounts = account_get_list();
5770 g_return_val_if_fail(accounts != NULL, NULL);
5772 hbox = gtk_hbox_new(FALSE, 0);
5773 optmenu = gtk_option_menu_new();
5774 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5775 menu = gtk_menu_new();
5777 for (; accounts != NULL; accounts = accounts->next, num++) {
5778 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5779 GtkWidget *menuitem;
5782 if (ac == compose->account) def_menu = num;
5785 name = g_strdup_printf("%s: %s <%s>",
5787 ac->name, ac->address);
5789 name = g_strdup_printf("%s: %s",
5790 ac->account_name, ac->address);
5791 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5793 g_signal_connect(G_OBJECT(menuitem), "activate",
5794 G_CALLBACK(account_activated),
5798 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5799 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5804 static void compose_set_priority_cb(gpointer data,
5808 Compose *compose = (Compose *) data;
5809 compose->priority = action;
5812 static void compose_update_priority_menu_item(Compose * compose)
5814 GtkItemFactory *ifactory;
5815 GtkWidget *menuitem = NULL;
5817 ifactory = gtk_item_factory_from_widget(compose->menubar);
5819 switch (compose->priority) {
5820 case PRIORITY_HIGHEST:
5821 menuitem = gtk_item_factory_get_item
5822 (ifactory, "/Options/Priority/Highest");
5825 menuitem = gtk_item_factory_get_item
5826 (ifactory, "/Options/Priority/High");
5828 case PRIORITY_NORMAL:
5829 menuitem = gtk_item_factory_get_item
5830 (ifactory, "/Options/Priority/Normal");
5833 menuitem = gtk_item_factory_get_item
5834 (ifactory, "/Options/Priority/Low");
5836 case PRIORITY_LOWEST:
5837 menuitem = gtk_item_factory_get_item
5838 (ifactory, "/Options/Priority/Lowest");
5841 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5844 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5846 Compose *compose = (Compose *) data;
5848 GtkItemFactory *ifactory;
5849 gboolean can_sign = FALSE, can_encrypt = FALSE;
5851 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5853 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5856 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5857 g_free(compose->privacy_system);
5858 compose->privacy_system = NULL;
5859 if (systemid != NULL) {
5860 compose->privacy_system = g_strdup(systemid);
5862 can_sign = privacy_system_can_sign(systemid);
5863 can_encrypt = privacy_system_can_encrypt(systemid);
5866 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5868 ifactory = gtk_item_factory_from_widget(compose->menubar);
5869 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5870 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5873 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
5875 static gchar *branch_path = "/Options/Privacy System";
5876 GtkItemFactory *ifactory;
5877 GtkWidget *menuitem = NULL;
5879 gboolean can_sign = FALSE, can_encrypt = FALSE;
5880 gboolean found = FALSE;
5882 ifactory = gtk_item_factory_from_widget(compose->menubar);
5884 if (compose->privacy_system != NULL) {
5887 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5888 g_return_if_fail(menuitem != NULL);
5890 amenu = GTK_MENU_SHELL(menuitem)->children;
5892 while (amenu != NULL) {
5893 GList *alist = amenu->next;
5895 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
5896 if (systemid != NULL) {
5897 if (strcmp(systemid, compose->privacy_system) == 0) {
5898 menuitem = GTK_WIDGET(amenu->data);
5900 can_sign = privacy_system_can_sign(systemid);
5901 can_encrypt = privacy_system_can_encrypt(systemid);
5905 } else if (strlen(compose->privacy_system) == 0) {
5906 menuitem = GTK_WIDGET(amenu->data);
5909 can_encrypt = FALSE;
5916 if (menuitem != NULL)
5917 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5919 if (warn && !found && strlen(compose->privacy_system)) {
5920 gchar *tmp = g_strdup_printf(
5921 _("The privacy system '%s' cannot be loaded. You "
5922 "will not be able to sign or encrypt this message."),
5923 compose->privacy_system);
5924 alertpanel_warning(tmp);
5929 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5930 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5933 static void compose_set_out_encoding(Compose *compose)
5935 GtkItemFactoryEntry *entry;
5936 GtkItemFactory *ifactory;
5937 CharSet out_encoding;
5938 gchar *path, *p, *q;
5941 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
5942 ifactory = gtk_item_factory_from_widget(compose->menubar);
5944 for (entry = compose_entries; entry->callback != compose_address_cb;
5946 if (entry->callback == compose_set_encoding_cb &&
5947 (CharSet)entry->callback_action == out_encoding) {
5948 p = q = path = g_strdup(entry->path);
5960 item = gtk_item_factory_get_item(ifactory, path);
5961 gtk_widget_activate(item);
5968 static void compose_set_template_menu(Compose *compose)
5970 GSList *tmpl_list, *cur;
5974 tmpl_list = template_get_config();
5976 menu = gtk_menu_new();
5978 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5979 Template *tmpl = (Template *)cur->data;
5981 item = gtk_menu_item_new_with_label(tmpl->name);
5982 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5983 g_signal_connect(G_OBJECT(item), "activate",
5984 G_CALLBACK(compose_template_activate_cb),
5986 g_object_set_data(G_OBJECT(item), "template", tmpl);
5987 gtk_widget_show(item);
5990 gtk_widget_show(menu);
5991 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5994 void compose_update_actions_menu(Compose *compose)
5996 GtkItemFactory *ifactory;
5998 ifactory = gtk_item_factory_from_widget(compose->menubar);
5999 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6002 void compose_update_privacy_systems_menu(Compose *compose)
6004 static gchar *branch_path = "/Options/Privacy System";
6005 GtkItemFactory *ifactory;
6006 GtkWidget *menuitem;
6007 GSList *systems, *cur;
6010 GtkWidget *system_none;
6013 ifactory = gtk_item_factory_from_widget(compose->menubar);
6015 /* remove old entries */
6016 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6017 g_return_if_fail(menuitem != NULL);
6019 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6020 while (amenu != NULL) {
6021 GList *alist = amenu->next;
6022 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6026 system_none = gtk_item_factory_get_widget(ifactory,
6027 "/Options/Privacy System/None");
6029 g_signal_connect(G_OBJECT(system_none), "activate",
6030 G_CALLBACK(compose_set_privacy_system_cb), compose);
6032 systems = privacy_get_system_ids();
6033 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6034 gchar *systemid = cur->data;
6036 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6037 widget = gtk_radio_menu_item_new_with_label(group,
6038 privacy_system_get_name(systemid));
6039 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6040 g_strdup(systemid), g_free);
6041 g_signal_connect(G_OBJECT(widget), "activate",
6042 G_CALLBACK(compose_set_privacy_system_cb), compose);
6044 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6045 gtk_widget_show(widget);
6048 g_slist_free(systems);
6051 void compose_reflect_prefs_all(void)
6056 for (cur = compose_list; cur != NULL; cur = cur->next) {
6057 compose = (Compose *)cur->data;
6058 compose_set_template_menu(compose);
6062 void compose_reflect_prefs_pixmap_theme(void)
6067 for (cur = compose_list; cur != NULL; cur = cur->next) {
6068 compose = (Compose *)cur->data;
6069 toolbar_update(TOOLBAR_COMPOSE, compose);
6073 static void compose_template_apply(Compose *compose, Template *tmpl,
6077 GtkTextBuffer *buffer;
6081 gchar *parsed_str = NULL;
6082 gint cursor_pos = 0;
6085 text = GTK_TEXT_VIEW(compose->text);
6086 buffer = gtk_text_view_get_buffer(text);
6088 if (tmpl->subject && *tmpl->subject != '\0')
6089 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
6091 if (tmpl->to && *tmpl->to != '\0')
6092 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
6093 if (tmpl->cc && *tmpl->cc != '\0')
6094 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
6096 if (tmpl->bcc && *tmpl->bcc != '\0')
6097 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
6100 gtk_text_buffer_set_text(buffer, "", -1);
6102 mark = gtk_text_buffer_get_insert(buffer);
6103 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6106 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6107 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6110 if (prefs_common.quotemark && *prefs_common.quotemark)
6111 qmark = prefs_common.quotemark;
6115 if (compose->replyinfo != NULL)
6116 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6117 tmpl->value, qmark, NULL, FALSE);
6118 else if (compose->fwdinfo != NULL)
6119 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6120 tmpl->value, qmark, NULL, FALSE);
6125 if (replace && parsed_str && compose->account->auto_sig)
6126 compose_insert_sig(compose, FALSE);
6128 if (replace && parsed_str) {
6129 gtk_text_buffer_get_start_iter(buffer, &iter);
6130 gtk_text_buffer_place_cursor(buffer, &iter);
6134 cursor_pos = quote_fmt_get_cursor_pos();
6135 compose->set_cursor_pos = cursor_pos;
6136 if (cursor_pos == -1)
6138 gtk_text_buffer_get_start_iter(buffer, &iter);
6139 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6140 gtk_text_buffer_place_cursor(buffer, &iter);
6143 compose_changed_cb(NULL, compose);
6146 static void compose_destroy(Compose *compose)
6148 compose_list = g_list_remove(compose_list, compose);
6150 /* NOTE: address_completion_end() does nothing with the window
6151 * however this may change. */
6152 address_completion_end(compose->window);
6154 slist_free_strings(compose->to_list);
6155 g_slist_free(compose->to_list);
6156 slist_free_strings(compose->newsgroup_list);
6157 g_slist_free(compose->newsgroup_list);
6158 slist_free_strings(compose->header_list);
6159 g_slist_free(compose->header_list);
6161 procmsg_msginfo_free(compose->targetinfo);
6162 procmsg_msginfo_free(compose->replyinfo);
6163 procmsg_msginfo_free(compose->fwdinfo);
6165 g_free(compose->replyto);
6166 g_free(compose->cc);
6167 g_free(compose->bcc);
6168 g_free(compose->newsgroups);
6169 g_free(compose->followup_to);
6171 g_free(compose->ml_post);
6173 g_free(compose->inreplyto);
6174 g_free(compose->references);
6175 g_free(compose->msgid);
6176 g_free(compose->boundary);
6178 if (compose->redirect_filename)
6179 g_free(compose->redirect_filename);
6180 if (compose->undostruct)
6181 undo_destroy(compose->undostruct);
6183 g_free(compose->sig_str);
6185 g_free(compose->exteditor_file);
6187 g_free(compose->orig_charset);
6189 g_free(compose->privacy_system);
6191 if (addressbook_get_target_compose() == compose)
6192 addressbook_set_target_compose(NULL);
6195 if (compose->gtkaspell) {
6196 gtkaspell_delete(compose->gtkaspell);
6197 compose->gtkaspell = NULL;
6201 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6202 prefs_common.compose_height = compose->window->allocation.height;
6204 if (!gtk_widget_get_parent(compose->paned))
6205 gtk_widget_destroy(compose->paned);
6206 gtk_widget_destroy(compose->popupmenu);
6208 gtk_widget_destroy(compose->window);
6209 toolbar_destroy(compose->toolbar);
6210 g_free(compose->toolbar);
6211 g_mutex_free(compose->mutex);
6215 static void compose_attach_info_free(AttachInfo *ainfo)
6217 g_free(ainfo->file);
6218 g_free(ainfo->content_type);
6219 g_free(ainfo->name);
6223 static void compose_attach_remove_selected(Compose *compose)
6225 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6226 GtkTreeSelection *selection;
6228 GtkTreeModel *model;
6230 selection = gtk_tree_view_get_selection(tree_view);
6231 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6236 for (cur = sel; cur != NULL; cur = cur->next) {
6237 GtkTreePath *path = cur->data;
6238 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6241 gtk_tree_path_free(path);
6244 for (cur = sel; cur != NULL; cur = cur->next) {
6245 GtkTreeRowReference *ref = cur->data;
6246 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6249 if (gtk_tree_model_get_iter(model, &iter, path))
6250 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6252 gtk_tree_path_free(path);
6253 gtk_tree_row_reference_free(ref);
6259 static struct _AttachProperty
6262 GtkWidget *mimetype_entry;
6263 GtkWidget *encoding_optmenu;
6264 GtkWidget *path_entry;
6265 GtkWidget *filename_entry;
6267 GtkWidget *cancel_btn;
6270 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6272 gtk_tree_path_free((GtkTreePath *)ptr);
6275 static void compose_attach_property(Compose *compose)
6277 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6279 GtkOptionMenu *optmenu;
6280 GtkTreeSelection *selection;
6282 GtkTreeModel *model;
6285 static gboolean cancelled;
6287 /* only if one selected */
6288 selection = gtk_tree_view_get_selection(tree_view);
6289 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6292 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6296 path = (GtkTreePath *) sel->data;
6297 gtk_tree_model_get_iter(model, &iter, path);
6298 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6301 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6307 if (!attach_prop.window)
6308 compose_attach_property_create(&cancelled);
6309 gtk_widget_grab_focus(attach_prop.ok_btn);
6310 gtk_widget_show(attach_prop.window);
6311 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6313 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6314 if (ainfo->encoding == ENC_UNKNOWN)
6315 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6316 GINT_TO_POINTER(ENC_BASE64));
6318 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6319 GINT_TO_POINTER(ainfo->encoding));
6321 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6322 ainfo->content_type ? ainfo->content_type : "");
6323 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6324 ainfo->file ? ainfo->file : "");
6325 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6326 ainfo->name ? ainfo->name : "");
6329 const gchar *entry_text;
6331 gchar *cnttype = NULL;
6335 GtkWidget *menuitem;
6340 gtk_widget_hide(attach_prop.window);
6345 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6346 if (*entry_text != '\0') {
6349 text = g_strstrip(g_strdup(entry_text));
6350 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6351 cnttype = g_strdup(text);
6354 alertpanel_error(_("Invalid MIME type."));
6360 menu = gtk_option_menu_get_menu(optmenu);
6361 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6362 ainfo->encoding = GPOINTER_TO_INT
6363 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6365 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6366 if (*entry_text != '\0') {
6367 if (is_file_exist(entry_text) &&
6368 (size = get_file_size(entry_text)) > 0)
6369 file = g_strdup(entry_text);
6372 (_("File doesn't exist or is empty."));
6378 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6379 if (*entry_text != '\0') {
6380 g_free(ainfo->name);
6381 ainfo->name = g_strdup(entry_text);
6385 g_free(ainfo->content_type);
6386 ainfo->content_type = cnttype;
6389 g_free(ainfo->file);
6395 /* update tree store */
6396 text = to_human_readable(ainfo->size);
6397 gtk_tree_model_get_iter(model, &iter, path);
6398 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6399 COL_MIMETYPE, ainfo->content_type,
6401 COL_NAME, ainfo->name,
6407 gtk_tree_path_free(path);
6410 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6412 label = gtk_label_new(str); \
6413 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6414 GTK_FILL, 0, 0, 0); \
6415 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6417 entry = gtk_entry_new(); \
6418 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6419 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6422 static void compose_attach_property_create(gboolean *cancelled)
6428 GtkWidget *mimetype_entry;
6431 GtkWidget *optmenu_menu;
6432 GtkWidget *menuitem;
6433 GtkWidget *path_entry;
6434 GtkWidget *filename_entry;
6437 GtkWidget *cancel_btn;
6438 GList *mime_type_list, *strlist;
6440 debug_print("Creating attach_property window...\n");
6442 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6443 gtk_widget_set_size_request(window, 480, -1);
6444 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6445 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6446 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6447 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6448 g_signal_connect(G_OBJECT(window), "delete_event",
6449 G_CALLBACK(attach_property_delete_event),
6451 g_signal_connect(G_OBJECT(window), "key_press_event",
6452 G_CALLBACK(attach_property_key_pressed),
6455 vbox = gtk_vbox_new(FALSE, 8);
6456 gtk_container_add(GTK_CONTAINER(window), vbox);
6458 table = gtk_table_new(4, 2, FALSE);
6459 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6460 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6461 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6463 label = gtk_label_new(_("MIME type"));
6464 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6466 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6467 mimetype_entry = gtk_combo_new();
6468 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6469 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6471 /* stuff with list */
6472 mime_type_list = procmime_get_mime_type_list();
6474 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6475 MimeType *type = (MimeType *) mime_type_list->data;
6478 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6480 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6483 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6484 (GCompareFunc)strcmp2);
6487 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6489 for (mime_type_list = strlist; mime_type_list != NULL;
6490 mime_type_list = mime_type_list->next)
6491 g_free(mime_type_list->data);
6492 g_list_free(strlist);
6494 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6496 label = gtk_label_new(_("Encoding"));
6497 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6499 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6501 hbox = gtk_hbox_new(FALSE, 0);
6502 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6503 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6505 optmenu = gtk_option_menu_new();
6506 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6508 optmenu_menu = gtk_menu_new();
6509 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6510 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6511 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6512 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6513 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6514 ENC_QUOTED_PRINTABLE);
6515 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6517 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6519 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6521 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6522 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6524 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
6525 &ok_btn, GTK_STOCK_OK,
6527 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6528 gtk_widget_grab_default(ok_btn);
6530 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6531 G_CALLBACK(attach_property_ok),
6533 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6534 G_CALLBACK(attach_property_cancel),
6537 gtk_widget_show_all(vbox);
6539 attach_prop.window = window;
6540 attach_prop.mimetype_entry = mimetype_entry;
6541 attach_prop.encoding_optmenu = optmenu;
6542 attach_prop.path_entry = path_entry;
6543 attach_prop.filename_entry = filename_entry;
6544 attach_prop.ok_btn = ok_btn;
6545 attach_prop.cancel_btn = cancel_btn;
6548 #undef SET_LABEL_AND_ENTRY
6550 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6556 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6562 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6563 gboolean *cancelled)
6571 static gboolean attach_property_key_pressed(GtkWidget *widget,
6573 gboolean *cancelled)
6575 if (event && event->keyval == GDK_Escape) {
6582 static void compose_exec_ext_editor(Compose *compose)
6589 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6590 G_DIR_SEPARATOR, compose);
6592 if (pipe(pipe_fds) < 0) {
6598 if ((pid = fork()) < 0) {
6605 /* close the write side of the pipe */
6608 compose->exteditor_file = g_strdup(tmp);
6609 compose->exteditor_pid = pid;
6611 compose_set_ext_editor_sensitive(compose, FALSE);
6613 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6614 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6618 } else { /* process-monitoring process */
6624 /* close the read side of the pipe */
6627 if (compose_write_body_to_file(compose, tmp) < 0) {
6628 fd_write_all(pipe_fds[1], "2\n", 2);
6632 pid_ed = compose_exec_ext_editor_real(tmp);
6634 fd_write_all(pipe_fds[1], "1\n", 2);
6638 /* wait until editor is terminated */
6639 waitpid(pid_ed, NULL, 0);
6641 fd_write_all(pipe_fds[1], "0\n", 2);
6648 #endif /* G_OS_UNIX */
6652 static gint compose_exec_ext_editor_real(const gchar *file)
6659 g_return_val_if_fail(file != NULL, -1);
6661 if ((pid = fork()) < 0) {
6666 if (pid != 0) return pid;
6668 /* grandchild process */
6670 if (setpgid(0, getppid()))
6673 if (prefs_common.ext_editor_cmd &&
6674 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6675 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6676 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6678 if (prefs_common.ext_editor_cmd)
6679 g_warning("External editor command line is invalid: '%s'\n",
6680 prefs_common.ext_editor_cmd);
6681 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
6684 cmdline = strsplit_with_quote(buf, " ", 1024);
6685 execvp(cmdline[0], cmdline);
6688 g_strfreev(cmdline);
6693 static gboolean compose_ext_editor_kill(Compose *compose)
6695 pid_t pgid = compose->exteditor_pid * -1;
6698 ret = kill(pgid, 0);
6700 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6704 msg = g_strdup_printf
6705 (_("The external editor is still working.\n"
6706 "Force terminating the process?\n"
6707 "process group id: %d"), -pgid);
6708 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
6709 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
6713 if (val == G_ALERTALTERNATE) {
6714 g_source_remove(compose->exteditor_tag);
6715 g_io_channel_shutdown(compose->exteditor_ch,
6717 g_io_channel_unref(compose->exteditor_ch);
6719 if (kill(pgid, SIGTERM) < 0) perror("kill");
6720 waitpid(compose->exteditor_pid, NULL, 0);
6722 g_warning("Terminated process group id: %d", -pgid);
6723 g_warning("Temporary file: %s",
6724 compose->exteditor_file);
6726 compose_set_ext_editor_sensitive(compose, TRUE);
6728 g_free(compose->exteditor_file);
6729 compose->exteditor_file = NULL;
6730 compose->exteditor_pid = -1;
6731 compose->exteditor_ch = NULL;
6732 compose->exteditor_tag = -1;
6740 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6744 Compose *compose = (Compose *)data;
6747 debug_print(_("Compose: input from monitoring process\n"));
6749 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6751 g_io_channel_shutdown(source, FALSE, NULL);
6752 g_io_channel_unref(source);
6754 waitpid(compose->exteditor_pid, NULL, 0);
6756 if (buf[0] == '0') { /* success */
6757 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6758 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6760 gtk_text_buffer_set_text(buffer, "", -1);
6761 compose_insert_file(compose, compose->exteditor_file);
6762 compose_changed_cb(NULL, compose);
6764 if (g_unlink(compose->exteditor_file) < 0)
6765 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6766 } else if (buf[0] == '1') { /* failed */
6767 g_warning("Couldn't exec external editor\n");
6768 if (g_unlink(compose->exteditor_file) < 0)
6769 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6770 } else if (buf[0] == '2') {
6771 g_warning("Couldn't write to file\n");
6772 } else if (buf[0] == '3') {
6773 g_warning("Pipe read failed\n");
6776 compose_set_ext_editor_sensitive(compose, TRUE);
6778 g_free(compose->exteditor_file);
6779 compose->exteditor_file = NULL;
6780 compose->exteditor_pid = -1;
6781 compose->exteditor_ch = NULL;
6782 compose->exteditor_tag = -1;
6787 static void compose_set_ext_editor_sensitive(Compose *compose,
6790 GtkItemFactory *ifactory;
6792 ifactory = gtk_item_factory_from_widget(compose->menubar);
6794 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6795 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6796 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6797 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6798 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6799 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6800 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6803 gtk_widget_set_sensitive(compose->text, sensitive);
6804 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6805 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6806 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6807 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6808 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6809 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6810 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
6811 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
6813 #endif /* G_OS_UNIX */
6816 * compose_undo_state_changed:
6818 * Change the sensivity of the menuentries undo and redo
6820 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6821 gint redo_state, gpointer data)
6823 GtkWidget *widget = GTK_WIDGET(data);
6824 GtkItemFactory *ifactory;
6826 g_return_if_fail(widget != NULL);
6828 ifactory = gtk_item_factory_from_widget(widget);
6830 switch (undo_state) {
6831 case UNDO_STATE_TRUE:
6832 if (!undostruct->undo_state) {
6833 undostruct->undo_state = TRUE;
6834 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6837 case UNDO_STATE_FALSE:
6838 if (undostruct->undo_state) {
6839 undostruct->undo_state = FALSE;
6840 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6843 case UNDO_STATE_UNCHANGED:
6845 case UNDO_STATE_REFRESH:
6846 menu_set_sensitive(ifactory, "/Edit/Undo",
6847 undostruct->undo_state);
6850 g_warning("Undo state not recognized");
6854 switch (redo_state) {
6855 case UNDO_STATE_TRUE:
6856 if (!undostruct->redo_state) {
6857 undostruct->redo_state = TRUE;
6858 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6861 case UNDO_STATE_FALSE:
6862 if (undostruct->redo_state) {
6863 undostruct->redo_state = FALSE;
6864 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6867 case UNDO_STATE_UNCHANGED:
6869 case UNDO_STATE_REFRESH:
6870 menu_set_sensitive(ifactory, "/Edit/Redo",
6871 undostruct->redo_state);
6874 g_warning("Redo state not recognized");
6879 /* callback functions */
6881 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6882 * includes "non-client" (windows-izm) in calculation, so this calculation
6883 * may not be accurate.
6885 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6886 GtkAllocation *allocation,
6887 GtkSHRuler *shruler)
6889 if (prefs_common.show_ruler) {
6890 gint char_width = 0, char_height = 0;
6891 gint line_width_in_chars;
6893 gtkut_get_font_size(GTK_WIDGET(widget),
6894 &char_width, &char_height);
6895 line_width_in_chars =
6896 (allocation->width - allocation->x) / char_width;
6898 /* got the maximum */
6899 gtk_ruler_set_range(GTK_RULER(shruler),
6900 0.0, line_width_in_chars, 0,
6901 /*line_width_in_chars*/ char_width);
6907 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6909 Compose *compose = (Compose *)data;
6912 gchar *folderidentifier;
6914 ac = account_find_from_id(
6915 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
6916 g_return_if_fail(ac != NULL);
6918 if (ac != compose->account)
6919 compose_select_account(compose, ac, FALSE);
6921 /* Set message save folder */
6922 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6923 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
6925 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
6926 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
6928 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6929 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6930 folderidentifier = folder_item_get_identifier(account_get_special_folder
6931 (compose->account, F_OUTBOX));
6932 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
6933 g_free(folderidentifier);
6937 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
6938 GtkTreeViewColumn *column, Compose *compose)
6940 compose_attach_property(compose);
6943 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6946 Compose *compose = (Compose *)data;
6947 GtkTreeSelection *attach_selection;
6948 gint attach_nr_selected;
6949 GtkItemFactory *ifactory;
6951 if (!event) return FALSE;
6953 if (event->button == 3) {
6954 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
6955 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
6956 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6958 if (attach_nr_selected > 0)
6960 menu_set_sensitive(ifactory, "/Remove", TRUE);
6961 menu_set_sensitive(ifactory, "/Properties...", TRUE);
6963 menu_set_sensitive(ifactory, "/Remove", FALSE);
6964 menu_set_sensitive(ifactory, "/Properties...", FALSE);
6967 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6968 NULL, NULL, event->button, event->time);
6975 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6978 Compose *compose = (Compose *)data;
6980 if (!event) return FALSE;
6982 switch (event->keyval) {
6984 compose_attach_remove_selected(compose);
6990 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6992 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6993 toolbar_comp_set_sensitive(compose, allow);
6994 menu_set_sensitive(ifactory, "/Message", allow);
6995 menu_set_sensitive(ifactory, "/Edit", allow);
6997 menu_set_sensitive(ifactory, "/Spelling", allow);
6999 menu_set_sensitive(ifactory, "/Options", allow);
7000 menu_set_sensitive(ifactory, "/Tools", allow);
7001 menu_set_sensitive(ifactory, "/Help", allow);
7003 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7007 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7009 Compose *compose = (Compose *)data;
7011 if (prefs_common.work_offline && !inc_offline_should_override())
7014 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7015 gtk_timeout_remove(compose->draft_timeout_tag);
7016 compose->draft_timeout_tag = -1;
7019 compose_send(compose);
7022 static void compose_send_later_cb(gpointer data, guint action,
7025 Compose *compose = (Compose *)data;
7028 val = compose_queue_sub(compose, NULL, NULL, TRUE);
7030 compose_close(compose);
7031 else if (val == -2) {
7032 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7036 void compose_draft (gpointer data)
7038 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7041 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7043 Compose *compose = (Compose *)data;
7047 MsgFlags flag = {0, 0};
7048 static gboolean lock = FALSE;
7049 MsgInfo *newmsginfo;
7051 gboolean target_locked = FALSE;
7055 draft = account_get_special_folder(compose->account, F_DRAFT);
7056 g_return_if_fail(draft != NULL);
7058 if (!g_mutex_trylock(compose->mutex)) {
7059 /* we don't want to lock the mutex once it's available,
7060 * because as the only other part of compose.c locking
7061 * it is compose_close - which means once unlocked,
7062 * the compose struct will be freed */
7063 debug_print("couldn't lock mutex, probably sending\n");
7069 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7070 G_DIR_SEPARATOR, compose);
7071 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7072 FILE_OP_ERROR(tmp, "fopen");
7076 /* chmod for security */
7077 if (change_file_mode_rw(fp, tmp) < 0) {
7078 FILE_OP_ERROR(tmp, "chmod");
7079 g_warning("can't change file mode\n");
7082 /* Save draft infos */
7083 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7084 fprintf(fp, "S:%s\n", compose->account->address);
7085 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7086 gchar *savefolderid;
7088 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7089 fprintf(fp, "SCF:%s\n", savefolderid);
7090 g_free(savefolderid);
7092 if (compose->return_receipt) {
7093 fprintf(fp, "RRCPT:1\n");
7095 if (compose->privacy_system) {
7096 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7097 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7098 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7102 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
7110 if (compose->targetinfo) {
7111 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7112 flag.perm_flags = target_locked?MSG_LOCKED:0;
7114 flag.tmp_flags = MSG_DRAFT;
7116 folder_item_scan(draft);
7117 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7120 if (action != COMPOSE_AUTO_SAVE)
7121 alertpanel_error(_("Could not save draft."));
7125 draft->mtime = 0; /* force updating */
7127 if (compose->mode == COMPOSE_REEDIT) {
7128 compose_remove_reedit_target(compose, TRUE);
7131 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7133 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7135 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
7137 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7138 if (compose_use_attach(compose))
7139 procmsg_msginfo_set_flags(newmsginfo, 0,
7140 MSG_HAS_ATTACHMENT);
7142 procmsg_msginfo_free(newmsginfo);
7145 folder_item_scan(draft);
7147 if (action == COMPOSE_QUIT_EDITING) {
7149 g_mutex_unlock(compose->mutex); /* must be done before closing */
7150 compose_close(compose);
7156 path = folder_item_fetch_msg(draft, msgnum);
7158 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
7161 if (g_stat(path, &s) < 0) {
7162 FILE_OP_ERROR(path, "stat");
7168 procmsg_msginfo_free(compose->targetinfo);
7169 compose->targetinfo = procmsg_msginfo_new();
7170 compose->targetinfo->msgnum = msgnum;
7171 compose->targetinfo->size = s.st_size;
7172 compose->targetinfo->mtime = s.st_mtime;
7173 compose->targetinfo->folder = draft;
7175 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
7176 compose->mode = COMPOSE_REEDIT;
7178 if (action == COMPOSE_AUTO_SAVE) {
7179 compose->autosaved_draft = compose->targetinfo;
7181 compose->modified = FALSE;
7182 compose_set_title(compose);
7186 g_mutex_unlock(compose->mutex);
7189 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7191 Compose *compose = (Compose *)data;
7194 if (compose->redirect_filename != NULL)
7197 file_list = filesel_select_multiple_files_open(_("Select file"));
7202 for ( tmp = file_list; tmp; tmp = tmp->next) {
7203 gchar *file = (gchar *) tmp->data;
7204 gchar *utf8_filename = conv_filename_to_utf8(file);
7205 compose_attach_append(compose, file, utf8_filename, NULL);
7206 compose_changed_cb(NULL, compose);
7208 g_free(utf8_filename);
7210 g_list_free(file_list);
7214 static void compose_insert_file_cb(gpointer data, guint action,
7217 Compose *compose = (Compose *)data;
7220 file_list = filesel_select_multiple_files_open(_("Select file"));
7225 for ( tmp = file_list; tmp; tmp = tmp->next) {
7226 gchar *file = (gchar *) tmp->data;
7227 gchar *filedup = g_strdup(file);
7228 gchar *shortfile = g_path_get_basename(filedup);
7229 ComposeInsertResult res;
7231 res = compose_insert_file(compose, file);
7232 if (res == COMPOSE_INSERT_READ_ERROR) {
7233 alertpanel_error(_("File '%s' could not be read."), shortfile);
7234 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7235 alertpanel_error(_("File '%s' contained invalid characters\n"
7236 "for the current encoding, insertion may be incorrect."), shortfile);
7242 g_list_free(file_list);
7246 static void compose_insert_sig_cb(gpointer data, guint action,
7249 Compose *compose = (Compose *)data;
7251 compose_insert_sig(compose, FALSE);
7254 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7258 Compose *compose = (Compose *)data;
7260 gtkut_widget_get_uposition(widget, &x, &y);
7261 prefs_common.compose_x = x;
7262 prefs_common.compose_y = y;
7264 if (compose->sending)
7266 compose_close_cb(compose, 0, NULL);
7270 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7272 Compose *compose = (Compose *)data;
7276 if (compose->exteditor_tag != -1) {
7277 if (!compose_ext_editor_kill(compose))
7282 if (compose->modified) {
7283 val = alertpanel(_("Discard message"),
7284 _("This message has been modified. Discard it?"),
7285 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7288 case G_ALERTDEFAULT:
7289 if (prefs_common.autosave)
7290 compose_remove_draft(compose);
7292 case G_ALERTALTERNATE:
7293 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7300 compose_close(compose);
7303 static void compose_set_encoding_cb(gpointer data, guint action,
7306 Compose *compose = (Compose *)data;
7308 if (GTK_CHECK_MENU_ITEM(widget)->active)
7309 compose->out_encoding = (CharSet)action;
7312 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7314 Compose *compose = (Compose *)data;
7316 addressbook_open(compose);
7319 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7321 Compose *compose = (Compose *)data;
7326 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7327 g_return_if_fail(tmpl != NULL);
7329 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7331 val = alertpanel(_("Apply template"), msg,
7332 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7335 if (val == G_ALERTDEFAULT)
7336 compose_template_apply(compose, tmpl, TRUE);
7337 else if (val == G_ALERTALTERNATE)
7338 compose_template_apply(compose, tmpl, FALSE);
7341 static void compose_ext_editor_cb(gpointer data, guint action,
7344 Compose *compose = (Compose *)data;
7346 compose_exec_ext_editor(compose);
7349 static void compose_undo_cb(Compose *compose)
7351 gboolean prev_autowrap = compose->autowrap;
7353 compose->autowrap = FALSE;
7354 undo_undo(compose->undostruct);
7355 compose->autowrap = prev_autowrap;
7358 static void compose_redo_cb(Compose *compose)
7360 gboolean prev_autowrap = compose->autowrap;
7362 compose->autowrap = FALSE;
7363 undo_redo(compose->undostruct);
7364 compose->autowrap = prev_autowrap;
7367 static void entry_cut_clipboard(GtkWidget *entry)
7369 if (GTK_IS_EDITABLE(entry))
7370 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7371 else if (GTK_IS_TEXT_VIEW(entry))
7372 gtk_text_buffer_cut_clipboard(
7373 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7374 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7378 static void entry_copy_clipboard(GtkWidget *entry)
7380 if (GTK_IS_EDITABLE(entry))
7381 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7382 else if (GTK_IS_TEXT_VIEW(entry))
7383 gtk_text_buffer_copy_clipboard(
7384 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7385 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7388 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7389 gboolean wrap, GdkAtom clip)
7391 if (GTK_IS_TEXT_VIEW(entry)) {
7392 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7393 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7394 GtkTextIter start_iter, end_iter;
7397 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7399 if (contents == NULL)
7402 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7403 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7405 start = gtk_text_iter_get_offset(&start_iter);
7407 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7410 end = start + strlen(contents);
7411 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7412 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7413 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7414 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7415 mark_start = gtk_text_buffer_get_insert(buffer);
7416 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7417 gtk_text_iter_backward_char(&start_iter);
7418 compose_beautify_paragraph(compose, &start_iter, TRUE);
7421 } else if (GTK_IS_EDITABLE(entry))
7422 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7426 static void entry_allsel(GtkWidget *entry)
7428 if (GTK_IS_EDITABLE(entry))
7429 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7430 else if (GTK_IS_TEXT_VIEW(entry)) {
7431 GtkTextIter startiter, enditer;
7432 GtkTextBuffer *textbuf;
7434 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7435 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7436 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7438 gtk_text_buffer_move_mark_by_name(textbuf,
7439 "selection_bound", &startiter);
7440 gtk_text_buffer_move_mark_by_name(textbuf,
7441 "insert", &enditer);
7445 static void compose_cut_cb(Compose *compose)
7447 if (compose->focused_editable &&
7448 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7449 entry_cut_clipboard(compose->focused_editable);
7452 static void compose_copy_cb(Compose *compose)
7454 if (compose->focused_editable &&
7455 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7456 entry_copy_clipboard(compose->focused_editable);
7459 static void compose_paste_cb(Compose *compose)
7462 GtkTextBuffer *buffer;
7464 if (compose->focused_editable &&
7465 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7466 entry_paste_clipboard(compose, compose->focused_editable,
7467 prefs_common.linewrap_pastes,
7468 GDK_SELECTION_CLIPBOARD);
7472 static void compose_paste_as_quote_cb(Compose *compose)
7474 gint wrap_quote = prefs_common.linewrap_quote;
7475 if (compose->focused_editable &&
7476 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7477 /* let text_insert() (called directly or at a later time
7478 * after the gtk_editable_paste_clipboard) know that
7479 * text is to be inserted as a quotation. implemented
7480 * by using a simple refcount... */
7481 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7482 G_OBJECT(compose->focused_editable),
7483 "paste_as_quotation"));
7484 g_object_set_data(G_OBJECT(compose->focused_editable),
7485 "paste_as_quotation",
7486 GINT_TO_POINTER(paste_as_quotation + 1));
7487 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7488 entry_paste_clipboard(compose, compose->focused_editable,
7489 prefs_common.linewrap_pastes,
7490 GDK_SELECTION_CLIPBOARD);
7491 prefs_common.linewrap_quote = wrap_quote;
7495 static void compose_paste_no_wrap_cb(Compose *compose)
7498 GtkTextBuffer *buffer;
7500 if (compose->focused_editable &&
7501 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7502 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7503 GDK_SELECTION_CLIPBOARD);
7507 static void compose_paste_wrap_cb(Compose *compose)
7510 GtkTextBuffer *buffer;
7512 if (compose->focused_editable &&
7513 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7514 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7515 GDK_SELECTION_CLIPBOARD);
7519 static void compose_allsel_cb(Compose *compose)
7521 if (compose->focused_editable &&
7522 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7523 entry_allsel(compose->focused_editable);
7526 static void textview_move_beginning_of_line (GtkTextView *text)
7528 GtkTextBuffer *buffer;
7532 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7534 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7535 mark = gtk_text_buffer_get_insert(buffer);
7536 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7537 gtk_text_iter_set_line_offset(&ins, 0);
7538 gtk_text_buffer_place_cursor(buffer, &ins);
7541 static void textview_move_forward_character (GtkTextView *text)
7543 GtkTextBuffer *buffer;
7547 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7549 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7550 mark = gtk_text_buffer_get_insert(buffer);
7551 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7552 if (gtk_text_iter_forward_cursor_position(&ins))
7553 gtk_text_buffer_place_cursor(buffer, &ins);
7556 static void textview_move_backward_character (GtkTextView *text)
7558 GtkTextBuffer *buffer;
7562 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7564 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7565 mark = gtk_text_buffer_get_insert(buffer);
7566 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7567 if (gtk_text_iter_backward_cursor_position(&ins))
7568 gtk_text_buffer_place_cursor(buffer, &ins);
7571 static void textview_move_forward_word (GtkTextView *text)
7573 GtkTextBuffer *buffer;
7578 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7580 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7581 mark = gtk_text_buffer_get_insert(buffer);
7582 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7583 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7584 if (gtk_text_iter_forward_word_ends(&ins, count)) {
7585 gtk_text_iter_backward_word_start(&ins);
7586 gtk_text_buffer_place_cursor(buffer, &ins);
7590 static void textview_move_backward_word (GtkTextView *text)
7592 GtkTextBuffer *buffer;
7597 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7599 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7600 mark = gtk_text_buffer_get_insert(buffer);
7601 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7602 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7603 if (gtk_text_iter_backward_word_starts(&ins, 1))
7604 gtk_text_buffer_place_cursor(buffer, &ins);
7607 static void textview_move_end_of_line (GtkTextView *text)
7609 GtkTextBuffer *buffer;
7613 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7615 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7616 mark = gtk_text_buffer_get_insert(buffer);
7617 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7618 if (gtk_text_iter_forward_to_line_end(&ins))
7619 gtk_text_buffer_place_cursor(buffer, &ins);
7622 static void textview_move_next_line (GtkTextView *text)
7624 GtkTextBuffer *buffer;
7629 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7631 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7632 mark = gtk_text_buffer_get_insert(buffer);
7633 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7634 offset = gtk_text_iter_get_line_offset(&ins);
7635 if (gtk_text_iter_forward_line(&ins)) {
7636 gtk_text_iter_set_line_offset(&ins, offset);
7637 gtk_text_buffer_place_cursor(buffer, &ins);
7641 static void textview_move_previous_line (GtkTextView *text)
7643 GtkTextBuffer *buffer;
7648 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7650 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7651 mark = gtk_text_buffer_get_insert(buffer);
7652 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7653 offset = gtk_text_iter_get_line_offset(&ins);
7654 if (gtk_text_iter_backward_line(&ins)) {
7655 gtk_text_iter_set_line_offset(&ins, offset);
7656 gtk_text_buffer_place_cursor(buffer, &ins);
7660 static void textview_delete_forward_character (GtkTextView *text)
7662 GtkTextBuffer *buffer;
7664 GtkTextIter ins, end_iter;
7666 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7668 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7669 mark = gtk_text_buffer_get_insert(buffer);
7670 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7672 if (gtk_text_iter_forward_char(&end_iter)) {
7673 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7677 static void textview_delete_backward_character (GtkTextView *text)
7679 GtkTextBuffer *buffer;
7681 GtkTextIter ins, end_iter;
7683 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7685 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7686 mark = gtk_text_buffer_get_insert(buffer);
7687 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7689 if (gtk_text_iter_backward_char(&end_iter)) {
7690 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7694 static void textview_delete_forward_word (GtkTextView *text)
7696 GtkTextBuffer *buffer;
7698 GtkTextIter ins, end_iter;
7700 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7702 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7703 mark = gtk_text_buffer_get_insert(buffer);
7704 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7706 if (gtk_text_iter_forward_word_end(&end_iter)) {
7707 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7711 static void textview_delete_backward_word (GtkTextView *text)
7713 GtkTextBuffer *buffer;
7715 GtkTextIter ins, end_iter;
7717 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7719 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7720 mark = gtk_text_buffer_get_insert(buffer);
7721 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7723 if (gtk_text_iter_backward_word_start(&end_iter)) {
7724 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7728 static void textview_delete_line (GtkTextView *text)
7730 GtkTextBuffer *buffer;
7732 GtkTextIter ins, start_iter, end_iter;
7735 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7737 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7738 mark = gtk_text_buffer_get_insert(buffer);
7739 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7742 gtk_text_iter_set_line_offset(&start_iter, 0);
7745 if (gtk_text_iter_ends_line(&end_iter))
7746 found = gtk_text_iter_forward_char(&end_iter);
7748 found = gtk_text_iter_forward_to_line_end(&end_iter);
7751 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7754 static void textview_delete_to_line_end (GtkTextView *text)
7756 GtkTextBuffer *buffer;
7758 GtkTextIter ins, end_iter;
7761 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7763 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7764 mark = gtk_text_buffer_get_insert(buffer);
7765 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7767 if (gtk_text_iter_ends_line(&end_iter))
7768 found = gtk_text_iter_forward_char(&end_iter);
7770 found = gtk_text_iter_forward_to_line_end(&end_iter);
7772 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7775 static void compose_advanced_action_cb(Compose *compose,
7776 ComposeCallAdvancedAction action)
7778 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7780 void (*do_action) (GtkTextView *text);
7781 } action_table[] = {
7782 {textview_move_beginning_of_line},
7783 {textview_move_forward_character},
7784 {textview_move_backward_character},
7785 {textview_move_forward_word},
7786 {textview_move_backward_word},
7787 {textview_move_end_of_line},
7788 {textview_move_next_line},
7789 {textview_move_previous_line},
7790 {textview_delete_forward_character},
7791 {textview_delete_backward_character},
7792 {textview_delete_forward_word},
7793 {textview_delete_backward_word},
7794 {textview_delete_line},
7795 {NULL}, /* gtk_stext_delete_line_n */
7796 {textview_delete_to_line_end}
7799 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
7801 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
7802 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
7803 if (action_table[action].do_action)
7804 action_table[action].do_action(text);
7806 g_warning("Not implemented yet.");
7810 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
7814 if (GTK_IS_EDITABLE(widget)) {
7815 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
7816 gtk_editable_set_position(GTK_EDITABLE(widget),
7819 if (widget->parent && widget->parent->parent
7820 && widget->parent->parent->parent) {
7821 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
7822 gint y = widget->allocation.y;
7823 gint height = widget->allocation.height;
7824 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
7825 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
7827 if (y < (int)shown->value) {
7828 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
7830 if (y + height > (int)shown->value + (int)shown->page_size) {
7831 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
7832 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7833 y + height - (int)shown->page_size - 1);
7835 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7836 (int)shown->upper - (int)shown->page_size - 1);
7843 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
7844 compose->focused_editable = widget;
7847 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
7849 compose->modified = TRUE;
7850 compose_set_title(compose);
7853 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
7855 Compose *compose = (Compose *)data;
7858 compose_wrap_all_full(compose, TRUE);
7860 compose_beautify_paragraph(compose, NULL, TRUE);
7863 static void compose_toggle_autowrap_cb(gpointer data, guint action,
7866 Compose *compose = (Compose *)data;
7867 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7868 if (compose->autowrap)
7869 compose_wrap_all_full(compose, TRUE);
7870 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7873 static void compose_toggle_sign_cb(gpointer data, guint action,
7876 Compose *compose = (Compose *)data;
7878 if (GTK_CHECK_MENU_ITEM(widget)->active)
7879 compose->use_signing = TRUE;
7881 compose->use_signing = FALSE;
7884 static void compose_toggle_encrypt_cb(gpointer data, guint action,
7887 Compose *compose = (Compose *)data;
7889 if (GTK_CHECK_MENU_ITEM(widget)->active)
7890 compose->use_encryption = TRUE;
7892 compose->use_encryption = FALSE;
7895 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
7897 g_free(compose->privacy_system);
7899 compose->privacy_system = g_strdup(account->default_privacy_system);
7900 compose_update_privacy_system_menu_item(compose, warn);
7903 static void compose_toggle_ruler_cb(gpointer data, guint action,
7906 Compose *compose = (Compose *)data;
7908 if (GTK_CHECK_MENU_ITEM(widget)->active) {
7909 gtk_widget_show(compose->ruler_hbox);
7910 prefs_common.show_ruler = TRUE;
7912 gtk_widget_hide(compose->ruler_hbox);
7913 gtk_widget_queue_resize(compose->edit_vbox);
7914 prefs_common.show_ruler = FALSE;
7918 static void compose_attach_drag_received_cb (GtkWidget *widget,
7919 GdkDragContext *drag_context,
7922 GtkSelectionData *data,
7927 Compose *compose = (Compose *)user_data;
7930 if (gdk_atom_name(data->type) &&
7931 !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7932 list = uri_list_extract_filenames((const gchar *)data->data);
7933 for (tmp = list; tmp != NULL; tmp = tmp->next)
7934 compose_attach_append
7935 (compose, (const gchar *)tmp->data,
7936 (const gchar *)tmp->data, NULL);
7937 if (list) compose_changed_cb(NULL, compose);
7938 list_free_strings(list);
7940 } else if (gdk_atom_name(data->type) &&
7941 !strcmp(gdk_atom_name(data->type), "text/plain") &&
7942 data->data && !strcmp(data->data, "Dummy-Summaryview")) {
7943 /* comes from our summaryview */
7944 SummaryView * summaryview = NULL;
7945 GSList * list = NULL, *cur = NULL;
7947 if (mainwindow_get_mainwindow())
7948 summaryview = mainwindow_get_mainwindow()->summaryview;
7951 list = summary_get_selected_msg_list(summaryview);
7953 for (cur = list; cur; cur = cur->next) {
7954 MsgInfo *msginfo = (MsgInfo *)cur->data;
7957 file = procmsg_get_message_file_full(msginfo,
7960 compose_attach_append(compose, (const gchar *)file,
7961 (const gchar *)file, "message/rfc822");
7969 static gboolean compose_drag_drop(GtkWidget *widget,
7970 GdkDragContext *drag_context,
7972 guint time, gpointer user_data)
7974 /* not handling this signal makes compose_insert_drag_received_cb
7979 static void compose_insert_drag_received_cb (GtkWidget *widget,
7980 GdkDragContext *drag_context,
7983 GtkSelectionData *data,
7988 Compose *compose = (Compose *)user_data;
7991 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
7993 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7994 list = uri_list_extract_filenames((const gchar *)data->data);
7995 for (tmp = list; tmp != NULL; tmp = tmp->next) {
7996 compose_insert_file(compose, (const gchar *)tmp->data);
7998 list_free_strings(list);
8000 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8003 #if GTK_CHECK_VERSION(2, 8, 0)
8004 /* do nothing, handled by GTK */
8006 gchar *tmpfile = get_tmp_file();
8007 str_write_to_file((const gchar *)data->data, tmpfile);
8008 compose_insert_file(compose, tmpfile);
8011 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8015 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8018 static void compose_header_drag_received_cb (GtkWidget *widget,
8019 GdkDragContext *drag_context,
8022 GtkSelectionData *data,
8027 GtkEditable *entry = (GtkEditable *)user_data;
8028 gchar *email = (gchar *)data->data;
8030 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8033 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8034 gchar *decoded=g_new(gchar, strlen(email));
8037 email += strlen("mailto:");
8038 decode_uri(decoded, email); /* will fit */
8039 gtk_editable_delete_text(entry, 0, -1);
8040 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8041 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8045 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8048 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8051 Compose *compose = (Compose *)data;
8053 if (GTK_CHECK_MENU_ITEM(widget)->active)
8054 compose->return_receipt = TRUE;
8056 compose->return_receipt = FALSE;
8059 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8062 Compose *compose = (Compose *)data;
8064 if (GTK_CHECK_MENU_ITEM(widget)->active)
8065 compose->remove_references = TRUE;
8067 compose->remove_references = FALSE;
8070 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8072 ComposeHeaderEntry *headerentry)
8074 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
8075 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
8076 !(event->state & GDK_MODIFIER_MASK) &&
8077 (event->keyval == GDK_BackSpace) &&
8078 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
8079 gtk_container_remove
8080 (GTK_CONTAINER(headerentry->compose->header_table),
8081 headerentry->combo);
8082 gtk_container_remove
8083 (GTK_CONTAINER(headerentry->compose->header_table),
8084 headerentry->entry);
8085 headerentry->compose->header_list =
8086 g_slist_remove(headerentry->compose->header_list,
8088 g_free(headerentry);
8089 } else if (event->keyval == GDK_Tab) {
8090 if (headerentry->compose->header_last == headerentry) {
8091 /* Override default next focus, and give it to subject_entry
8092 * instead of notebook tabs
8094 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8095 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8102 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8103 ComposeHeaderEntry *headerentry)
8105 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8106 headerentry->compose->header_list =
8107 g_slist_append(headerentry->compose->header_list,
8110 compose_create_header_entry(headerentry->compose);
8111 g_signal_handlers_disconnect_matched
8112 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8113 0, 0, NULL, NULL, headerentry);
8115 /* Automatically scroll down */
8116 compose_show_first_last_header(headerentry->compose, FALSE);
8122 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8124 GtkAdjustment *vadj;
8126 g_return_if_fail(compose);
8127 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8128 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8130 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8131 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8134 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8135 const gchar *text, gint len, Compose *compose)
8137 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8138 (G_OBJECT(compose->text), "paste_as_quotation"));
8141 g_return_if_fail(text != NULL);
8143 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8144 G_CALLBACK(text_inserted),
8146 if (paste_as_quotation) {
8153 new_text = g_strndup(text, len);
8154 if (prefs_common.quotemark && *prefs_common.quotemark)
8155 qmark = prefs_common.quotemark;
8159 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8160 gtk_text_buffer_place_cursor(buffer, iter);
8162 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8164 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8165 GINT_TO_POINTER(paste_as_quotation - 1));
8167 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8168 gtk_text_buffer_place_cursor(buffer, iter);
8170 if (strcmp(text, "\n") || automatic_break
8171 || gtk_text_iter_starts_line(iter))
8172 gtk_text_buffer_insert(buffer, iter, text, len);
8174 debug_print("insert nowrap \\n\n");
8175 gtk_text_buffer_insert_with_tags_by_name(buffer,
8176 iter, text, len, "no_join", NULL);
8180 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8182 compose_beautify_paragraph(compose, iter, FALSE);
8184 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8185 gtk_text_buffer_delete_mark(buffer, mark);
8187 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8188 G_CALLBACK(text_inserted),
8190 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8192 if (prefs_common.autosave &&
8193 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8194 compose->draft_timeout_tag = gtk_timeout_add
8195 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8197 static gint compose_defer_auto_save_draft(Compose *compose)
8199 compose->draft_timeout_tag = -1;
8200 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8205 static void compose_check_all(Compose *compose)
8207 if (compose->gtkaspell)
8208 gtkaspell_check_all(compose->gtkaspell);
8211 static void compose_highlight_all(Compose *compose)
8213 if (compose->gtkaspell)
8214 gtkaspell_highlight_all(compose->gtkaspell);
8217 static void compose_check_backwards(Compose *compose)
8219 if (compose->gtkaspell)
8220 gtkaspell_check_backwards(compose->gtkaspell);
8222 GtkItemFactory *ifactory;
8223 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8224 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8225 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8229 static void compose_check_forwards_go(Compose *compose)
8231 if (compose->gtkaspell)
8232 gtkaspell_check_forwards_go(compose->gtkaspell);
8234 GtkItemFactory *ifactory;
8235 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8236 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8237 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8243 *\brief Guess originating forward account from MsgInfo and several
8244 * "common preference" settings. Return NULL if no guess.
8246 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8248 PrefsAccount *account = NULL;
8250 g_return_val_if_fail(msginfo, NULL);
8251 g_return_val_if_fail(msginfo->folder, NULL);
8252 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8254 if (msginfo->folder->prefs->enable_default_account)
8255 account = account_find_from_id(msginfo->folder->prefs->default_account);
8258 account = msginfo->folder->folder->account;
8260 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8262 Xstrdup_a(to, msginfo->to, return NULL);
8263 extract_address(to);
8264 account = account_find_from_address(to);
8267 if (!account && prefs_common.forward_account_autosel) {
8269 if (!procheader_get_header_from_msginfo
8270 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8271 extract_address(cc);
8272 account = account_find_from_address(cc);
8279 static gboolean compose_close(Compose *compose)
8283 if (!g_mutex_trylock(compose->mutex)) {
8284 /* we have to wait for the (possibly deferred by auto-save)
8285 * drafting to be done, before destroying the compose under
8287 debug_print("waiting for drafting to finish...\n");
8288 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8291 g_return_val_if_fail(compose, FALSE);
8292 gtkut_widget_get_uposition(compose->window, &x, &y);
8293 prefs_common.compose_x = x;
8294 prefs_common.compose_y = y;
8295 g_mutex_unlock(compose->mutex);
8296 compose_destroy(compose);
8301 * Add entry field for each address in list.
8302 * \param compose E-Mail composition object.
8303 * \param listAddress List of (formatted) E-Mail addresses.
8305 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8310 addr = ( gchar * ) node->data;
8311 compose_entry_append( compose, addr, COMPOSE_TO );
8312 node = g_list_next( node );
8316 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8320 GSList *new_msglist = NULL;
8321 MsgInfo *tmp_msginfo = NULL;
8322 gboolean originally_enc = FALSE;
8323 Compose *compose = NULL;
8325 g_return_if_fail(msgview != NULL);
8327 g_return_if_fail(msginfo_list != NULL);
8329 if (g_slist_length(msginfo_list) == 1) {
8330 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8331 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8333 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8334 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8335 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8336 orig_msginfo, mimeinfo);
8337 if (tmp_msginfo != NULL) {
8338 new_msglist = g_slist_append(NULL, tmp_msginfo);
8339 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8340 originally_enc = TRUE;
8346 body = messageview_get_selection(msgview);
8349 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8350 procmsg_msginfo_free(tmp_msginfo);
8351 g_slist_free(new_msglist);
8353 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8355 if (originally_enc) {
8356 compose_force_encryption(compose, compose->account, FALSE);