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/Turkish (ISO-8859-_9)"),
702 ENC_ACTION(C_ISO_8859_9)},
703 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
705 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
706 ENC_ACTION(C_ISO_8859_5)},
707 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
708 ENC_ACTION(C_KOI8_R)},
709 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
710 ENC_ACTION(C_KOI8_U)},
711 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
712 ENC_ACTION(C_WINDOWS_1251)},
713 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
715 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
716 ENC_ACTION(C_ISO_2022_JP)},
717 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
719 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
720 ENC_ACTION(C_GB2312)},
721 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
723 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
725 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
726 ENC_ACTION(C_EUC_TW)},
727 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
729 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
730 ENC_ACTION(C_EUC_KR)},
731 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
733 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
734 ENC_ACTION(C_TIS_620)},
735 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
736 ENC_ACTION(C_WINDOWS_874)},
738 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
739 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
740 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
741 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
742 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
743 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
744 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
747 static GtkTargetEntry compose_mime_types[] =
749 {"text/uri-list", 0, 0},
750 {"text/plain", 0, 0},
754 static gboolean compose_put_existing_to_front(MsgInfo *info)
756 GList *compose_list = compose_get_compose_list();
760 for (elem = compose_list; elem != NULL && elem->data != NULL;
762 Compose *c = (Compose*)elem->data;
764 if (!c->targetinfo || !c->targetinfo->msgid ||
768 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
769 gtkut_window_popup(c->window);
777 static GdkColor quote_color =
778 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
780 static GdkColor signature_color = {
787 static GdkColor uri_color = {
794 static void compose_create_tags(GtkTextView *text, Compose *compose)
796 GtkTextBuffer *buffer;
797 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
799 buffer = gtk_text_view_get_buffer(text);
801 if (prefs_common.enable_color) {
802 /* grab the quote colors, converting from an int to a GdkColor */
803 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
805 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
807 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
810 signature_color = quote_color = uri_color = black;
813 gtk_text_buffer_create_tag(buffer, "quote",
814 "foreground-gdk", "e_color,
816 gtk_text_buffer_create_tag(buffer, "signature",
817 "foreground-gdk", &signature_color,
819 gtk_text_buffer_create_tag(buffer, "link",
820 "foreground-gdk", &uri_color,
822 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
823 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
826 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
827 GPtrArray *attach_files)
829 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
832 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
834 return compose_generic_new(account, NULL, item, NULL, NULL);
837 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
839 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
842 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
843 GPtrArray *attach_files, GList *listAddress )
846 GtkTextView *textview;
847 GtkTextBuffer *textbuf;
849 GtkItemFactory *ifactory;
851 if (item && item->prefs && item->prefs->enable_default_account)
852 account = account_find_from_id(item->prefs->default_account);
854 if (!account) account = cur_account;
855 g_return_val_if_fail(account != NULL, NULL);
857 compose = compose_create(account, COMPOSE_NEW);
858 ifactory = gtk_item_factory_from_widget(compose->menubar);
860 compose->replyinfo = NULL;
861 compose->fwdinfo = NULL;
863 textview = GTK_TEXT_VIEW(compose->text);
864 textbuf = gtk_text_view_get_buffer(textview);
865 compose_create_tags(textview, compose);
867 undo_block(compose->undostruct);
869 if (item && item->prefs && item->prefs->enable_default_dictionary &&
871 gtkaspell_change_dict(compose->gtkaspell,
872 item->prefs->default_dictionary);
875 if (account->auto_sig)
876 compose_insert_sig(compose, FALSE);
877 gtk_text_buffer_get_start_iter(textbuf, &iter);
878 gtk_text_buffer_place_cursor(textbuf, &iter);
880 if (account->protocol != A_NNTP) {
881 if (mailto && *mailto != '\0') {
882 compose_entries_set(compose, mailto);
884 } else if (item && item->prefs->enable_default_to) {
885 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
886 compose_entry_mark_default_to(compose, item->prefs->default_to);
888 if (item && item->ret_rcpt) {
889 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
893 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
895 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
898 * CLAWS: just don't allow return receipt request, even if the user
899 * may want to send an email. simple but foolproof.
901 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
903 compose_add_field_list( compose, listAddress );
909 for (i = 0; i < attach_files->len; i++) {
910 file = g_ptr_array_index(attach_files, i);
911 compose_attach_append(compose, file, file, NULL);
915 compose_show_first_last_header(compose, TRUE);
917 /* Set save folder */
918 if (item && item->prefs && item->prefs->save_copy_to_folder) {
919 gchar *folderidentifier;
921 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
922 folderidentifier = folder_item_get_identifier(item);
923 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
924 g_free(folderidentifier);
927 gtk_widget_grab_focus(compose->header_last->entry);
929 undo_unblock(compose->undostruct);
931 if (prefs_common.auto_exteditor)
932 compose_exec_ext_editor(compose);
934 compose->modified = FALSE;
935 compose_set_title(compose);
939 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
940 gboolean override_pref)
942 gchar *privacy = NULL;
944 g_return_if_fail(compose != NULL);
945 g_return_if_fail(account != NULL);
947 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
950 if (account->default_privacy_system
951 && strlen(account->default_privacy_system)) {
952 privacy = account->default_privacy_system;
954 GSList *privacy_avail = privacy_get_system_ids();
955 if (privacy_avail && g_slist_length(privacy_avail)) {
956 privacy = (gchar *)(privacy_avail->data);
959 if (privacy != NULL) {
960 compose->privacy_system = g_strdup(privacy);
961 compose_update_privacy_system_menu_item(compose, FALSE);
962 compose_use_encryption(compose, TRUE);
966 static void compose_force_signing(Compose *compose, PrefsAccount *account)
968 gchar *privacy = NULL;
970 if (account->default_privacy_system
971 && strlen(account->default_privacy_system)) {
972 privacy = account->default_privacy_system;
974 GSList *privacy_avail = privacy_get_system_ids();
975 if (privacy_avail && g_slist_length(privacy_avail)) {
976 privacy = (gchar *)(privacy_avail->data);
979 if (privacy != NULL) {
980 compose->privacy_system = g_strdup(privacy);
981 compose_update_privacy_system_menu_item(compose, FALSE);
982 compose_use_signing(compose, TRUE);
986 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
990 Compose *compose = NULL;
991 g_return_val_if_fail(msginfo_list != NULL, NULL);
993 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
994 g_return_val_if_fail(msginfo != NULL, NULL);
996 list_len = g_slist_length(msginfo_list);
1000 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1001 FALSE, prefs_common.default_reply_list, FALSE, body);
1003 case COMPOSE_REPLY_WITH_QUOTE:
1004 compose = compose_reply(msginfo, TRUE,
1005 FALSE, prefs_common.default_reply_list, FALSE, body);
1007 case COMPOSE_REPLY_WITHOUT_QUOTE:
1008 compose = compose_reply(msginfo, FALSE,
1009 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1011 case COMPOSE_REPLY_TO_SENDER:
1012 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1013 FALSE, FALSE, TRUE, body);
1015 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1016 compose = compose_followup_and_reply_to(msginfo,
1017 prefs_common.reply_with_quote,
1018 FALSE, FALSE, body);
1020 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1021 compose = compose_reply(msginfo, TRUE,
1022 FALSE, FALSE, TRUE, body);
1024 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1025 compose = compose_reply(msginfo, FALSE,
1026 FALSE, FALSE, TRUE, NULL);
1028 case COMPOSE_REPLY_TO_ALL:
1029 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1030 TRUE, FALSE, FALSE, body);
1032 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1033 compose = compose_reply(msginfo, TRUE,
1034 TRUE, FALSE, FALSE, body);
1036 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1037 compose = compose_reply(msginfo, FALSE,
1038 TRUE, FALSE, FALSE, NULL);
1040 case COMPOSE_REPLY_TO_LIST:
1041 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1042 FALSE, TRUE, FALSE, body);
1044 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1045 compose = compose_reply(msginfo, TRUE,
1046 FALSE, TRUE, FALSE, body);
1048 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1049 compose = compose_reply(msginfo, FALSE,
1050 FALSE, TRUE, FALSE, NULL);
1052 case COMPOSE_FORWARD:
1053 if (prefs_common.forward_as_attachment) {
1054 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1057 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1061 case COMPOSE_FORWARD_INLINE:
1062 /* check if we reply to more than one Message */
1063 if (list_len == 1) {
1064 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE);
1067 /* more messages FALL THROUGH */
1068 case COMPOSE_FORWARD_AS_ATTACH:
1069 compose = compose_forward_multiple(NULL, msginfo_list);
1071 case COMPOSE_REDIRECT:
1072 compose = compose_redirect(NULL, msginfo);
1075 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1080 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1081 gboolean to_ml, gboolean to_sender,
1084 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1085 to_sender, FALSE, body);
1088 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1093 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1094 to_sender, TRUE, body);
1097 static void compose_extract_original_charset(Compose *compose)
1099 MsgInfo *info = NULL;
1100 if (compose->replyinfo) {
1101 info = compose->replyinfo;
1102 } else if (compose->fwdinfo) {
1103 info = compose->fwdinfo;
1104 } else if (compose->targetinfo) {
1105 info = compose->targetinfo;
1108 MimeInfo *mimeinfo = procmime_scan_message(info);
1109 MimeInfo *partinfo = mimeinfo;
1110 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1111 partinfo = procmime_mimeinfo_next(partinfo);
1113 compose->orig_charset =
1114 g_strdup(procmime_mimeinfo_get_parameter(
1115 partinfo, "charset"));
1117 procmime_mimeinfo_free_all(mimeinfo);
1121 #define SIGNAL_BLOCK(buffer) { \
1122 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1123 G_CALLBACK(compose_changed_cb), \
1125 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1126 G_CALLBACK(text_inserted), \
1130 #define SIGNAL_UNBLOCK(buffer) { \
1131 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1132 G_CALLBACK(compose_changed_cb), \
1134 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1135 G_CALLBACK(text_inserted), \
1139 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1140 gboolean to_all, gboolean to_ml,
1142 gboolean followup_and_reply_to,
1145 GtkItemFactory *ifactory;
1147 PrefsAccount *account = NULL;
1148 PrefsAccount *reply_account;
1149 GtkTextView *textview;
1150 GtkTextBuffer *textbuf;
1152 g_return_val_if_fail(msginfo != NULL, NULL);
1153 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1155 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1157 g_return_val_if_fail(account != NULL, NULL);
1159 if (to_sender && account->protocol == A_NNTP &&
1160 !followup_and_reply_to) {
1162 account_find_from_address(account->address);
1164 reply_account = compose_current_mail_account();
1168 reply_account = account;
1170 compose = compose_create(account, COMPOSE_REPLY);
1171 ifactory = gtk_item_factory_from_widget(compose->menubar);
1173 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1174 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1176 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1178 if (!compose->replyinfo)
1179 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1181 compose_extract_original_charset(compose);
1183 if (msginfo->folder && msginfo->folder->ret_rcpt)
1184 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1186 /* Set save folder */
1187 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1188 gchar *folderidentifier;
1190 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1191 folderidentifier = folder_item_get_identifier(msginfo->folder);
1192 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1193 g_free(folderidentifier);
1196 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1197 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1198 to_sender, followup_and_reply_to);
1199 compose_show_first_last_header(compose, TRUE);
1201 textview = (GTK_TEXT_VIEW(compose->text));
1202 textbuf = gtk_text_view_get_buffer(textview);
1203 compose_create_tags(textview, compose);
1205 undo_block(compose->undostruct);
1207 if (msginfo->folder && msginfo->folder->prefs &&
1208 msginfo->folder->prefs &&
1209 msginfo->folder->prefs->enable_default_dictionary &&
1211 gtkaspell_change_dict(compose->gtkaspell,
1212 msginfo->folder->prefs->default_dictionary);
1218 if (prefs_common.quotemark && *prefs_common.quotemark)
1219 qmark = prefs_common.quotemark;
1223 compose_quote_fmt(compose, compose->replyinfo,
1224 prefs_common.quotefmt,
1225 qmark, body, FALSE);
1227 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1228 compose_force_encryption(compose, account, FALSE);
1231 SIGNAL_BLOCK(textbuf);
1233 if (account->auto_sig)
1234 compose_insert_sig(compose, FALSE);
1236 compose_wrap_all(compose);
1238 SIGNAL_UNBLOCK(textbuf);
1240 gtk_widget_grab_focus(compose->text);
1242 undo_unblock(compose->undostruct);
1244 if (prefs_common.auto_exteditor)
1245 compose_exec_ext_editor(compose);
1247 compose->modified = FALSE;
1248 compose_set_title(compose);
1252 #define INSERT_FW_HEADER(var, hdr) \
1253 if (msginfo->var && *msginfo->var) { \
1254 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1255 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1256 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1259 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1260 gboolean as_attach, const gchar *body,
1261 gboolean no_extedit)
1264 GtkTextView *textview;
1265 GtkTextBuffer *textbuf;
1268 g_return_val_if_fail(msginfo != NULL, NULL);
1269 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1272 !(account = compose_guess_forward_account_from_msginfo
1274 account = cur_account;
1276 compose = compose_create(account, COMPOSE_FORWARD);
1278 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1279 if (!compose->fwdinfo)
1280 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1282 compose_extract_original_charset(compose);
1284 if (msginfo->subject && *msginfo->subject) {
1285 gchar *buf, *buf2, *p;
1287 buf = p = g_strdup(msginfo->subject);
1288 p += subject_get_prefix_length(p);
1289 memmove(buf, p, strlen(p) + 1);
1291 buf2 = g_strdup_printf("Fw: %s", buf);
1292 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1298 textview = GTK_TEXT_VIEW(compose->text);
1299 textbuf = gtk_text_view_get_buffer(textview);
1300 compose_create_tags(textview, compose);
1302 undo_block(compose->undostruct);
1306 msgfile = procmsg_get_message_file_path(msginfo);
1307 if (!is_file_exist(msgfile))
1308 g_warning("%s: file not exist\n", msgfile);
1310 compose_attach_append(compose, msgfile, msgfile,
1316 MsgInfo *full_msginfo;
1318 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1320 full_msginfo = procmsg_msginfo_copy(msginfo);
1322 if (prefs_common.fw_quotemark &&
1323 *prefs_common.fw_quotemark)
1324 qmark = prefs_common.fw_quotemark;
1328 compose_quote_fmt(compose, full_msginfo,
1329 prefs_common.fw_quotefmt,
1330 qmark, body, FALSE);
1331 compose_attach_parts(compose, msginfo);
1333 procmsg_msginfo_free(full_msginfo);
1336 SIGNAL_BLOCK(textbuf);
1338 if (account->auto_sig)
1339 compose_insert_sig(compose, FALSE);
1341 compose_wrap_all(compose);
1343 SIGNAL_UNBLOCK(textbuf);
1345 gtk_text_buffer_get_start_iter(textbuf, &iter);
1346 gtk_text_buffer_place_cursor(textbuf, &iter);
1348 gtk_widget_grab_focus(compose->header_last->entry);
1350 if (!no_extedit && prefs_common.auto_exteditor)
1351 compose_exec_ext_editor(compose);
1354 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1355 gchar *folderidentifier;
1357 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1358 folderidentifier = folder_item_get_identifier(msginfo->folder);
1359 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1360 g_free(folderidentifier);
1363 undo_unblock(compose->undostruct);
1365 compose->modified = FALSE;
1366 compose_set_title(compose);
1370 #undef INSERT_FW_HEADER
1372 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1375 GtkTextView *textview;
1376 GtkTextBuffer *textbuf;
1380 gboolean single_mail = TRUE;
1382 g_return_val_if_fail(msginfo_list != NULL, NULL);
1384 if (g_slist_length(msginfo_list) > 1)
1385 single_mail = FALSE;
1387 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1388 if (((MsgInfo *)msginfo->data)->folder == NULL)
1391 /* guess account from first selected message */
1393 !(account = compose_guess_forward_account_from_msginfo
1394 (msginfo_list->data)))
1395 account = cur_account;
1397 g_return_val_if_fail(account != NULL, NULL);
1399 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1400 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1401 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1404 compose = compose_create(account, COMPOSE_FORWARD);
1406 textview = GTK_TEXT_VIEW(compose->text);
1407 textbuf = gtk_text_view_get_buffer(textview);
1408 compose_create_tags(textview, compose);
1410 undo_block(compose->undostruct);
1411 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1412 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1413 if (!is_file_exist(msgfile))
1414 g_warning("%s: file not exist\n", msgfile);
1416 compose_attach_append(compose, msgfile, msgfile,
1422 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1423 if (info->subject && *info->subject) {
1424 gchar *buf, *buf2, *p;
1426 buf = p = g_strdup(info->subject);
1427 p += subject_get_prefix_length(p);
1428 memmove(buf, p, strlen(p) + 1);
1430 buf2 = g_strdup_printf("Fw: %s", buf);
1431 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1437 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1438 _("Fw: multiple emails"));
1441 SIGNAL_BLOCK(textbuf);
1443 if (account->auto_sig)
1444 compose_insert_sig(compose, FALSE);
1446 compose_wrap_all(compose);
1448 SIGNAL_UNBLOCK(textbuf);
1450 gtk_text_buffer_get_start_iter(textbuf, &iter);
1451 gtk_text_buffer_place_cursor(textbuf, &iter);
1453 gtk_widget_grab_focus(compose->header_last->entry);
1454 undo_unblock(compose->undostruct);
1455 compose->modified = FALSE;
1456 compose_set_title(compose);
1460 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1462 GtkTextIter start = *iter;
1463 GtkTextIter end_iter;
1464 int start_pos = gtk_text_iter_get_offset(&start);
1466 if (!compose->account->sig_sep)
1469 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1470 start_pos+strlen(compose->account->sig_sep));
1472 /* check sig separator */
1473 str = gtk_text_iter_get_text(&start, &end_iter);
1474 if (!strcmp(str, compose->account->sig_sep)) {
1476 /* check end of line (\n) */
1477 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1478 start_pos+strlen(compose->account->sig_sep));
1479 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1480 start_pos+strlen(compose->account->sig_sep)+1);
1481 tmp = gtk_text_iter_get_text(&start, &end_iter);
1482 if (!strcmp(tmp,"\n")) {
1494 static void compose_colorize_signature(Compose *compose)
1496 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1498 GtkTextIter end_iter;
1499 gtk_text_buffer_get_start_iter(buffer, &iter);
1500 while (gtk_text_iter_forward_line(&iter))
1501 if (compose_is_sig_separator(compose, buffer, &iter)) {
1502 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1503 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1507 void compose_reedit(MsgInfo *msginfo)
1509 Compose *compose = NULL;
1510 PrefsAccount *account = NULL;
1511 GtkTextView *textview;
1512 GtkTextBuffer *textbuf;
1516 gchar buf[BUFFSIZE];
1517 gboolean use_signing = FALSE;
1518 gboolean use_encryption = FALSE;
1519 gchar *privacy_system = NULL;
1521 g_return_if_fail(msginfo != NULL);
1522 g_return_if_fail(msginfo->folder != NULL);
1524 if (compose_put_existing_to_front(msginfo))
1527 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1528 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1529 gchar queueheader_buf[BUFFSIZE];
1532 /* Select Account from queue headers */
1533 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1534 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1535 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1536 account = account_find_from_id(id);
1538 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1539 sizeof(queueheader_buf), "NAID:")) {
1540 id = atoi(&queueheader_buf[strlen("NAID:")]);
1541 account = account_find_from_id(id);
1543 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1544 sizeof(queueheader_buf), "MAID:")) {
1545 id = atoi(&queueheader_buf[strlen("MAID:")]);
1546 account = account_find_from_id(id);
1548 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1549 sizeof(queueheader_buf), "S:")) {
1550 account = account_find_from_address(queueheader_buf);
1552 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1553 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1554 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1555 use_signing = param;
1558 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1559 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1560 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1561 use_encryption = param;
1563 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1564 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1565 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1567 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1568 sizeof(queueheader_buf), "X-Priority: ")) {
1569 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1570 compose->priority = param;
1573 account = msginfo->folder->folder->account;
1575 if (!account && prefs_common.reedit_account_autosel) {
1576 gchar from[BUFFSIZE];
1577 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1578 extract_address(from);
1579 account = account_find_from_address(from);
1582 if (!account) account = cur_account;
1583 g_return_if_fail(account != NULL);
1585 compose = compose_create(account, COMPOSE_REEDIT);
1586 if (privacy_system != NULL) {
1587 compose->privacy_system = privacy_system;
1588 compose_use_signing(compose, use_signing);
1589 compose_use_encryption(compose, use_encryption);
1590 compose_update_privacy_system_menu_item(compose, FALSE);
1592 activate_privacy_system(compose, account, FALSE);
1594 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1596 compose_extract_original_charset(compose);
1598 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1599 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1600 gchar queueheader_buf[BUFFSIZE];
1602 /* Set message save folder */
1603 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1606 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1607 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1608 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1610 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1611 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1613 GtkItemFactory *ifactory;
1614 ifactory = gtk_item_factory_from_widget(compose->menubar);
1615 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1620 if (compose_parse_header(compose, msginfo) < 0) return;
1621 compose_reedit_set_entry(compose, msginfo);
1623 textview = GTK_TEXT_VIEW(compose->text);
1624 textbuf = gtk_text_view_get_buffer(textview);
1625 compose_create_tags(textview, compose);
1627 mark = gtk_text_buffer_get_insert(textbuf);
1628 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1630 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1631 G_CALLBACK(compose_changed_cb),
1634 if (procmime_msginfo_is_encrypted(msginfo)) {
1635 fp = procmime_get_first_encrypted_text_content(msginfo);
1637 compose_force_encryption(compose, account, TRUE);
1639 fp = procmime_get_first_text_content(msginfo);
1641 g_warning("Can't get text part\n");
1644 gboolean prev_autowrap = compose->autowrap;
1646 compose->autowrap = FALSE;
1647 while (fgets(buf, sizeof(buf), fp) != NULL) {
1649 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1651 compose_wrap_all_full(compose, FALSE);
1652 compose->autowrap = prev_autowrap;
1656 compose_attach_parts(compose, msginfo);
1658 compose_colorize_signature(compose);
1660 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1661 G_CALLBACK(compose_changed_cb),
1664 gtk_widget_grab_focus(compose->text);
1666 if (prefs_common.auto_exteditor)
1667 compose_exec_ext_editor(compose);
1668 compose->modified = FALSE;
1669 compose_set_title(compose);
1672 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1676 GtkItemFactory *ifactory;
1679 g_return_val_if_fail(msginfo != NULL, NULL);
1682 account = account_get_reply_account(msginfo,
1683 prefs_common.reply_account_autosel);
1684 g_return_val_if_fail(account != NULL, NULL);
1686 compose = compose_create(account, COMPOSE_REDIRECT);
1687 ifactory = gtk_item_factory_from_widget(compose->menubar);
1688 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1689 compose->replyinfo = NULL;
1690 compose->fwdinfo = NULL;
1692 compose_show_first_last_header(compose, TRUE);
1694 gtk_widget_grab_focus(compose->header_last->entry);
1696 filename = procmsg_get_message_file_path(msginfo);
1697 if (filename == NULL)
1700 compose->redirect_filename = filename;
1702 /* Set save folder */
1703 item = msginfo->folder;
1704 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1705 gchar *folderidentifier;
1707 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1708 folderidentifier = folder_item_get_identifier(item);
1709 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1710 g_free(folderidentifier);
1713 compose_attach_parts(compose, msginfo);
1715 if (msginfo->subject)
1716 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1718 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1720 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1721 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1723 compose_colorize_signature(compose);
1725 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1726 menu_set_sensitive(ifactory, "/Add...", FALSE);
1727 menu_set_sensitive(ifactory, "/Remove", FALSE);
1728 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1730 ifactory = gtk_item_factory_from_widget(compose->menubar);
1731 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1732 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1733 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1734 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1735 menu_set_sensitive(ifactory, "/Edit", FALSE);
1736 menu_set_sensitive(ifactory, "/Options", FALSE);
1737 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1738 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1740 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1741 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1742 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1743 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1744 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1745 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1746 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1748 compose->modified = FALSE;
1749 compose_set_title(compose);
1753 GList *compose_get_compose_list(void)
1755 return compose_list;
1758 void compose_entry_append(Compose *compose, const gchar *address,
1759 ComposeEntryType type)
1763 gboolean in_quote = FALSE;
1764 if (!address || *address == '\0') return;
1771 header = N_("Bcc:");
1773 case COMPOSE_REPLYTO:
1774 header = N_("Reply-To:");
1776 case COMPOSE_NEWSGROUPS:
1777 header = N_("Newsgroups:");
1779 case COMPOSE_FOLLOWUPTO:
1780 header = N_( "Followup-To:");
1787 header = prefs_common.trans_hdr ? gettext(header) : header;
1789 cur = begin = (gchar *)address;
1791 /* we separate the line by commas, but not if we're inside a quoted
1793 while (*cur != '\0') {
1795 in_quote = !in_quote;
1796 if (*cur == ',' && !in_quote) {
1797 gchar *tmp = g_strdup(begin);
1799 tmp[cur-begin]='\0';
1804 compose_add_header_entry(compose, header, tmp);
1811 gchar *tmp = g_strdup(begin);
1813 tmp[cur-begin]='\0';
1818 compose_add_header_entry(compose, header, tmp);
1823 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1825 static GdkColor yellow;
1826 static GdkColor black;
1827 static gboolean yellow_initialised = FALSE;
1831 if (!yellow_initialised) {
1832 gdk_color_parse("#f5f6be", &yellow);
1833 gdk_color_parse("#000000", &black);
1834 yellow_initialised = gdk_colormap_alloc_color(
1835 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
1836 yellow_initialised &= gdk_colormap_alloc_color(
1837 gdk_colormap_get_system(), &black, FALSE, TRUE);
1840 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1841 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1842 if (gtk_entry_get_text(entry) &&
1843 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1844 if (yellow_initialised) {
1845 gtk_widget_modify_base(
1846 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
1847 GTK_STATE_NORMAL, &yellow);
1848 gtk_widget_modify_text(
1849 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
1850 GTK_STATE_NORMAL, &black);
1856 void compose_toolbar_cb(gint action, gpointer data)
1858 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1859 Compose *compose = (Compose*)toolbar_item->parent;
1861 g_return_if_fail(compose != NULL);
1865 compose_send_cb(compose, 0, NULL);
1868 compose_send_later_cb(compose, 0, NULL);
1871 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1874 compose_insert_file_cb(compose, 0, NULL);
1877 compose_attach_cb(compose, 0, NULL);
1880 compose_insert_sig(compose, FALSE);
1883 compose_ext_editor_cb(compose, 0, NULL);
1885 case A_LINEWRAP_CURRENT:
1886 compose_beautify_paragraph(compose, NULL, TRUE);
1888 case A_LINEWRAP_ALL:
1889 compose_wrap_all_full(compose, TRUE);
1892 compose_address_cb(compose, 0, NULL);
1895 case A_CHECK_SPELLING:
1896 compose_check_all(compose);
1904 static void compose_entries_set(Compose *compose, const gchar *mailto)
1908 gchar *subject = NULL;
1913 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1916 compose_entry_append(compose, to, COMPOSE_TO);
1918 compose_entry_append(compose, cc, COMPOSE_CC);
1920 if (!g_utf8_validate (subject, -1, NULL)) {
1921 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1922 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1925 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1929 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1930 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1933 gboolean prev_autowrap = compose->autowrap;
1935 compose->autowrap = FALSE;
1937 mark = gtk_text_buffer_get_insert(buffer);
1938 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1940 if (!g_utf8_validate (body, -1, NULL)) {
1941 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1942 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1945 gtk_text_buffer_insert(buffer, &iter, body, -1);
1947 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1949 compose->autowrap = prev_autowrap;
1950 if (compose->autowrap)
1951 compose_wrap_all(compose);
1960 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1962 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1963 {"Cc:", NULL, TRUE},
1964 {"References:", NULL, FALSE},
1965 {"Bcc:", NULL, TRUE},
1966 {"Newsgroups:", NULL, TRUE},
1967 {"Followup-To:", NULL, TRUE},
1968 {"List-Post:", NULL, FALSE},
1969 {"X-Priority:", NULL, FALSE},
1970 {NULL, NULL, FALSE}};
1986 g_return_val_if_fail(msginfo != NULL, -1);
1988 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1989 procheader_get_header_fields(fp, hentry);
1992 if (hentry[H_REPLY_TO].body != NULL) {
1993 if (hentry[H_REPLY_TO].body[0] != '\0') {
1995 conv_unmime_header(hentry[H_REPLY_TO].body,
1998 g_free(hentry[H_REPLY_TO].body);
1999 hentry[H_REPLY_TO].body = NULL;
2001 if (hentry[H_CC].body != NULL) {
2002 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2003 g_free(hentry[H_CC].body);
2004 hentry[H_CC].body = NULL;
2006 if (hentry[H_REFERENCES].body != NULL) {
2007 if (compose->mode == COMPOSE_REEDIT)
2008 compose->references = hentry[H_REFERENCES].body;
2010 compose->references = compose_parse_references
2011 (hentry[H_REFERENCES].body, msginfo->msgid);
2012 g_free(hentry[H_REFERENCES].body);
2014 hentry[H_REFERENCES].body = NULL;
2016 if (hentry[H_BCC].body != NULL) {
2017 if (compose->mode == COMPOSE_REEDIT)
2019 conv_unmime_header(hentry[H_BCC].body, NULL);
2020 g_free(hentry[H_BCC].body);
2021 hentry[H_BCC].body = NULL;
2023 if (hentry[H_NEWSGROUPS].body != NULL) {
2024 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2025 hentry[H_NEWSGROUPS].body = NULL;
2027 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2028 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2029 compose->followup_to =
2030 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2033 g_free(hentry[H_FOLLOWUP_TO].body);
2034 hentry[H_FOLLOWUP_TO].body = NULL;
2036 if (hentry[H_LIST_POST].body != NULL) {
2039 extract_address(hentry[H_LIST_POST].body);
2040 if (hentry[H_LIST_POST].body[0] != '\0') {
2041 scan_mailto_url(hentry[H_LIST_POST].body,
2042 &to, NULL, NULL, NULL, NULL);
2044 g_free(compose->ml_post);
2045 compose->ml_post = to;
2048 g_free(hentry[H_LIST_POST].body);
2049 hentry[H_LIST_POST].body = NULL;
2052 /* CLAWS - X-Priority */
2053 if (compose->mode == COMPOSE_REEDIT)
2054 if (hentry[H_X_PRIORITY].body != NULL) {
2057 priority = atoi(hentry[H_X_PRIORITY].body);
2058 g_free(hentry[H_X_PRIORITY].body);
2060 hentry[H_X_PRIORITY].body = NULL;
2062 if (priority < PRIORITY_HIGHEST ||
2063 priority > PRIORITY_LOWEST)
2064 priority = PRIORITY_NORMAL;
2066 compose->priority = priority;
2069 if (compose->mode == COMPOSE_REEDIT) {
2070 if (msginfo->inreplyto && *msginfo->inreplyto)
2071 compose->inreplyto = g_strdup(msginfo->inreplyto);
2075 if (msginfo->msgid && *msginfo->msgid)
2076 compose->inreplyto = g_strdup(msginfo->msgid);
2078 if (!compose->references) {
2079 if (msginfo->msgid && *msginfo->msgid) {
2080 if (msginfo->inreplyto && *msginfo->inreplyto)
2081 compose->references =
2082 g_strdup_printf("<%s>\n\t<%s>",
2086 compose->references =
2087 g_strconcat("<", msginfo->msgid, ">",
2089 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2090 compose->references =
2091 g_strconcat("<", msginfo->inreplyto, ">",
2099 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2101 GSList *ref_id_list, *cur;
2105 ref_id_list = references_list_append(NULL, ref);
2106 if (!ref_id_list) return NULL;
2107 if (msgid && *msgid)
2108 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2113 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2114 /* "<" + Message-ID + ">" + CR+LF+TAB */
2115 len += strlen((gchar *)cur->data) + 5;
2117 if (len > MAX_REFERENCES_LEN) {
2118 /* remove second message-ID */
2119 if (ref_id_list && ref_id_list->next &&
2120 ref_id_list->next->next) {
2121 g_free(ref_id_list->next->data);
2122 ref_id_list = g_slist_remove
2123 (ref_id_list, ref_id_list->next->data);
2125 slist_free_strings(ref_id_list);
2126 g_slist_free(ref_id_list);
2133 new_ref = g_string_new("");
2134 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2135 if (new_ref->len > 0)
2136 g_string_append(new_ref, "\n\t");
2137 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2140 slist_free_strings(ref_id_list);
2141 g_slist_free(ref_id_list);
2143 new_ref_str = new_ref->str;
2144 g_string_free(new_ref, FALSE);
2149 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2150 const gchar *fmt, const gchar *qmark,
2151 const gchar *body, gboolean rewrap)
2153 static MsgInfo dummyinfo;
2154 gchar *quote_str = NULL;
2156 gboolean prev_autowrap;
2157 const gchar *trimmed_body = body;
2158 gint cursor_pos = -1;
2159 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2160 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2165 SIGNAL_BLOCK(buffer);
2168 msginfo = &dummyinfo;
2170 if (qmark != NULL) {
2171 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2172 quote_fmt_scan_string(qmark);
2175 buf = quote_fmt_get_buffer();
2177 alertpanel_error(_("Quote mark format error."));
2179 Xstrdup_a(quote_str, buf, goto error)
2182 if (fmt && *fmt != '\0') {
2183 while (trimmed_body && strlen(trimmed_body) > 1
2184 && trimmed_body[0]=='\n')
2187 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2188 quote_fmt_scan_string(fmt);
2191 buf = quote_fmt_get_buffer();
2193 alertpanel_error(_("Message reply/forward format error."));
2199 prev_autowrap = compose->autowrap;
2200 compose->autowrap = FALSE;
2202 mark = gtk_text_buffer_get_insert(buffer);
2203 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2204 if (g_utf8_validate(buf, -1, NULL)) {
2205 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2207 gchar *tmpout = NULL;
2208 tmpout = conv_codeset_strdup
2209 (buf, conv_get_locale_charset_str(),
2211 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2213 tmpout = g_malloc(strlen(buf)*2+1);
2214 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2216 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2220 cursor_pos = quote_fmt_get_cursor_pos();
2221 compose->set_cursor_pos = cursor_pos;
2222 if (cursor_pos == -1) {
2225 gtk_text_buffer_get_start_iter(buffer, &iter);
2226 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2227 gtk_text_buffer_place_cursor(buffer, &iter);
2229 compose->autowrap = prev_autowrap;
2230 if (compose->autowrap && rewrap)
2231 compose_wrap_all(compose);
2238 SIGNAL_UNBLOCK(buffer);
2244 /* if ml_post is of type addr@host and from is of type
2245 * addr-anything@host, return TRUE
2247 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2249 gchar *left_ml = NULL;
2250 gchar *right_ml = NULL;
2251 gchar *left_from = NULL;
2252 gchar *right_from = NULL;
2253 gboolean result = FALSE;
2255 if (!ml_post || !from)
2258 left_ml = g_strdup(ml_post);
2259 if (strstr(left_ml, "@")) {
2260 right_ml = strstr(left_ml, "@")+1;
2261 *(strstr(left_ml, "@")) = '\0';
2264 left_from = g_strdup(from);
2265 if (strstr(left_from, "@")) {
2266 right_from = strstr(left_from, "@")+1;
2267 *(strstr(left_from, "@")) = '\0';
2270 if (left_ml && left_from && right_ml && right_from
2271 && !strncmp(left_from, left_ml, strlen(left_ml))
2272 && !strcmp(right_from, right_ml)) {
2281 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2283 gchar *my_addr1, *my_addr2;
2285 if (!addr1 || !addr2)
2288 Xstrdup_a(my_addr1, addr1, return FALSE);
2289 Xstrdup_a(my_addr2, addr2, return FALSE);
2291 extract_address(my_addr1);
2292 extract_address(my_addr2);
2294 return !strcmp(my_addr1, my_addr2);
2297 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2298 gboolean to_all, gboolean to_ml,
2300 gboolean followup_and_reply_to)
2302 GSList *cc_list = NULL;
2305 gchar *replyto = NULL;
2306 GHashTable *to_table;
2308 gboolean reply_to_ml = FALSE;
2309 gboolean default_reply_to = FALSE;
2311 g_return_if_fail(compose->account != NULL);
2312 g_return_if_fail(msginfo != NULL);
2314 reply_to_ml = to_ml && compose->ml_post;
2316 default_reply_to = msginfo->folder &&
2317 msginfo->folder->prefs->enable_default_reply_to;
2319 if (compose->account->protocol != A_NNTP) {
2320 if (reply_to_ml && !default_reply_to) {
2322 gboolean is_subscr = is_subscription(compose->ml_post,
2325 /* normal answer to ml post with a reply-to */
2326 compose_entry_append(compose,
2329 if (compose->replyto
2330 && !same_address(compose->ml_post, compose->replyto))
2331 compose_entry_append(compose,
2335 /* answer to subscription confirmation */
2336 if (compose->replyto)
2337 compose_entry_append(compose,
2340 else if (msginfo->from)
2341 compose_entry_append(compose,
2346 else if (!(to_all || to_sender) && default_reply_to) {
2347 compose_entry_append(compose,
2348 msginfo->folder->prefs->default_reply_to,
2350 compose_entry_mark_default_to(compose,
2351 msginfo->folder->prefs->default_reply_to);
2354 Xstrdup_a(tmp1, msginfo->from, return);
2355 extract_address(tmp1);
2356 if (to_all || to_sender ||
2357 !account_find_from_address(tmp1))
2358 compose_entry_append(compose,
2359 (compose->replyto && !to_sender)
2360 ? compose->replyto :
2361 msginfo->from ? msginfo->from : "",
2363 else if (!to_all && !to_sender) {
2364 /* reply to the last list of recipients */
2365 compose_entry_append(compose,
2366 msginfo->to ? msginfo->to : "",
2368 compose_entry_append(compose,
2369 msginfo->cc ? msginfo->cc : "",
2374 if (to_sender || (compose->followup_to &&
2375 !strncmp(compose->followup_to, "poster", 6)))
2376 compose_entry_append
2378 (compose->replyto ? compose->replyto :
2379 msginfo->from ? msginfo->from : ""),
2382 else if (followup_and_reply_to || to_all) {
2383 compose_entry_append
2385 (compose->replyto ? compose->replyto :
2386 msginfo->from ? msginfo->from : ""),
2389 compose_entry_append
2391 compose->followup_to ? compose->followup_to :
2392 compose->newsgroups ? compose->newsgroups : "",
2393 COMPOSE_NEWSGROUPS);
2396 compose_entry_append
2398 compose->followup_to ? compose->followup_to :
2399 compose->newsgroups ? compose->newsgroups : "",
2400 COMPOSE_NEWSGROUPS);
2403 if (msginfo->subject && *msginfo->subject) {
2407 buf = p = g_strdup(msginfo->subject);
2408 p += subject_get_prefix_length(p);
2409 memmove(buf, p, strlen(p) + 1);
2411 buf2 = g_strdup_printf("Re: %s", buf);
2412 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2417 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2419 if (to_ml && compose->ml_post) return;
2420 if (!to_all || compose->account->protocol == A_NNTP) return;
2422 if (compose->replyto) {
2423 Xstrdup_a(replyto, compose->replyto, return);
2424 extract_address(replyto);
2426 if (msginfo->from) {
2427 Xstrdup_a(from, msginfo->from, return);
2428 extract_address(from);
2431 if (replyto && from)
2432 cc_list = address_list_append_with_comments(cc_list, from);
2433 if (to_all && msginfo->folder &&
2434 msginfo->folder->prefs->enable_default_reply_to)
2435 cc_list = address_list_append_with_comments(cc_list,
2436 msginfo->folder->prefs->default_reply_to);
2437 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2438 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2440 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2442 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2443 if (compose->account)
2444 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2445 GINT_TO_POINTER(1));
2447 /* remove address on To: and that of current account */
2448 for (cur = cc_list; cur != NULL; ) {
2449 GSList *next = cur->next;
2452 addr = g_strdup(cur->data);
2453 extract_address(addr);
2455 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2456 cc_list = g_slist_remove(cc_list, cur->data);
2458 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2462 hash_free_strings(to_table);
2463 g_hash_table_destroy(to_table);
2466 for (cur = cc_list; cur != NULL; cur = cur->next)
2467 compose_entry_append(compose, (gchar *)cur->data,
2469 slist_free_strings(cc_list);
2470 g_slist_free(cc_list);
2475 #define SET_ENTRY(entry, str) \
2478 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2481 #define SET_ADDRESS(type, str) \
2484 compose_entry_append(compose, str, type); \
2487 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2489 g_return_if_fail(msginfo != NULL);
2491 SET_ENTRY(subject_entry, msginfo->subject);
2492 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2493 SET_ADDRESS(COMPOSE_CC, compose->cc);
2494 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2495 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2496 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2497 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2499 compose_update_priority_menu_item(compose);
2500 compose_update_privacy_system_menu_item(compose, FALSE);
2501 compose_show_first_last_header(compose, TRUE);
2507 static void compose_insert_sig(Compose *compose, gboolean replace)
2509 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2510 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2512 GtkTextIter iter, iter_end;
2514 gboolean prev_autowrap;
2517 g_return_if_fail(compose->account != NULL);
2519 prev_autowrap = compose->autowrap;
2520 compose->autowrap = FALSE;
2522 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2523 G_CALLBACK(compose_changed_cb),
2526 mark = gtk_text_buffer_get_insert(buffer);
2527 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2528 cur_pos = gtk_text_iter_get_offset (&iter);
2530 gtk_text_buffer_get_end_iter(buffer, &iter);
2532 if (replace && compose->sig_str) {
2534 GtkTextIter first_iter, start_iter, end_iter;
2536 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2538 if (compose->sig_str[0] == '\0')
2541 found = gtk_text_iter_forward_search(&first_iter,
2543 GTK_TEXT_SEARCH_TEXT_ONLY,
2544 &start_iter, &end_iter,
2548 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2553 g_free(compose->sig_str);
2554 compose->sig_str = compose_get_signature_str(compose);
2555 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2556 compose->sig_str = g_strdup("");
2558 cur_pos = gtk_text_iter_get_offset(&iter);
2559 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2561 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2562 gtk_text_iter_forward_char(&iter);
2563 gtk_text_iter_forward_char(&iter);
2564 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2565 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2567 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2568 cur_pos = gtk_text_buffer_get_char_count (buffer);
2570 /* put the cursor where it should be
2571 * either where the quote_fmt says, either before the signature */
2572 if (compose->set_cursor_pos < 0)
2573 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2575 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2576 compose->set_cursor_pos);
2578 gtk_text_buffer_place_cursor(buffer, &iter);
2579 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2580 G_CALLBACK(compose_changed_cb),
2583 compose->autowrap = prev_autowrap;
2584 if (compose->autowrap)
2585 compose_wrap_all(compose);
2588 static gchar *compose_get_signature_str(Compose *compose)
2590 gchar *sig_body = NULL;
2591 gchar *sig_str = NULL;
2592 gchar *utf8_sig_str = NULL;
2594 g_return_val_if_fail(compose->account != NULL, NULL);
2596 if (!compose->account->sig_path)
2599 if (compose->account->sig_type == SIG_FILE) {
2600 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2601 g_warning("can't open signature file: %s\n",
2602 compose->account->sig_path);
2607 if (compose->account->sig_type == SIG_COMMAND)
2608 sig_body = get_command_output(compose->account->sig_path);
2612 tmp = file_read_to_str(compose->account->sig_path);
2615 sig_body = normalize_newlines(tmp);
2619 if (compose->account->sig_sep) {
2620 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2624 sig_str = g_strconcat("\n\n", sig_body, NULL);
2627 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2628 utf8_sig_str = sig_str;
2630 utf8_sig_str = conv_codeset_strdup
2631 (sig_str, conv_get_locale_charset_str(),
2637 return utf8_sig_str;
2640 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2643 GtkTextBuffer *buffer;
2646 const gchar *cur_encoding;
2647 gchar buf[BUFFSIZE];
2650 gboolean prev_autowrap;
2651 gboolean badtxt = FALSE;
2653 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2655 if ((fp = g_fopen(file, "rb")) == NULL) {
2656 FILE_OP_ERROR(file, "fopen");
2657 return COMPOSE_INSERT_READ_ERROR;
2660 prev_autowrap = compose->autowrap;
2661 compose->autowrap = FALSE;
2663 text = GTK_TEXT_VIEW(compose->text);
2664 buffer = gtk_text_view_get_buffer(text);
2665 mark = gtk_text_buffer_get_insert(buffer);
2666 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2668 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2669 G_CALLBACK(text_inserted),
2672 cur_encoding = conv_get_locale_charset_str();
2674 while (fgets(buf, sizeof(buf), fp) != NULL) {
2677 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2678 str = g_strdup(buf);
2680 str = conv_codeset_strdup
2681 (buf, cur_encoding, CS_INTERNAL);
2684 /* strip <CR> if DOS/Windows file,
2685 replace <CR> with <LF> if Macintosh file. */
2688 if (len > 0 && str[len - 1] != '\n') {
2690 if (str[len] == '\r') str[len] = '\n';
2693 gtk_text_buffer_insert(buffer, &iter, str, -1);
2697 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2698 G_CALLBACK(text_inserted),
2700 compose->autowrap = prev_autowrap;
2701 if (compose->autowrap)
2702 compose_wrap_all(compose);
2707 return COMPOSE_INSERT_INVALID_CHARACTER;
2709 return COMPOSE_INSERT_SUCCESS;
2712 static void compose_attach_append(Compose *compose, const gchar *file,
2713 const gchar *filename,
2714 const gchar *content_type)
2722 GtkListStore *store;
2725 if (!is_file_exist(file)) {
2726 g_warning("File %s doesn't exist\n", filename);
2729 if ((size = get_file_size(file)) < 0) {
2730 g_warning("Can't get file size of %s\n", filename);
2734 alertpanel_notice(_("File %s is empty."), filename);
2737 if ((fp = g_fopen(file, "rb")) == NULL) {
2738 alertpanel_error(_("Can't read %s."), filename);
2743 ainfo = g_new0(AttachInfo, 1);
2744 auto_ainfo = g_auto_pointer_new_with_free
2745 (ainfo, (GFreeFunc) compose_attach_info_free);
2746 ainfo->file = g_strdup(file);
2749 ainfo->content_type = g_strdup(content_type);
2750 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2752 MsgFlags flags = {0, 0};
2754 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2755 ainfo->encoding = ENC_7BIT;
2757 ainfo->encoding = ENC_8BIT;
2759 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2760 if (msginfo && msginfo->subject)
2761 name = g_strdup(msginfo->subject);
2763 name = g_path_get_basename(filename ? filename : file);
2765 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2767 procmsg_msginfo_free(msginfo);
2769 if (!g_ascii_strncasecmp(content_type, "text", 4))
2770 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2772 ainfo->encoding = ENC_BASE64;
2773 name = g_path_get_basename(filename ? filename : file);
2774 ainfo->name = g_strdup(name);
2778 ainfo->content_type = procmime_get_mime_type(file);
2779 if (!ainfo->content_type) {
2780 ainfo->content_type =
2781 g_strdup("application/octet-stream");
2782 ainfo->encoding = ENC_BASE64;
2783 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2785 procmime_get_encoding_for_text_file(file);
2787 ainfo->encoding = ENC_BASE64;
2788 name = g_path_get_basename(filename ? filename : file);
2789 ainfo->name = g_strdup(name);
2793 if (!strcmp(ainfo->content_type, "unknown")) {
2794 g_free(ainfo->content_type);
2795 ainfo->content_type = g_strdup("application/octet-stream");
2799 size_text = to_human_readable(size);
2801 store = GTK_LIST_STORE(gtk_tree_view_get_model
2802 (GTK_TREE_VIEW(compose->attach_clist)));
2804 gtk_list_store_append(store, &iter);
2805 gtk_list_store_set(store, &iter,
2806 COL_MIMETYPE, ainfo->content_type,
2807 COL_SIZE, size_text,
2808 COL_NAME, ainfo->name,
2810 COL_AUTODATA, auto_ainfo,
2813 g_auto_pointer_free(auto_ainfo);
2816 static void compose_use_signing(Compose *compose, gboolean use_signing)
2818 GtkItemFactory *ifactory;
2819 GtkWidget *menuitem = NULL;
2821 compose->use_signing = use_signing;
2822 ifactory = gtk_item_factory_from_widget(compose->menubar);
2823 menuitem = gtk_item_factory_get_item
2824 (ifactory, "/Options/Sign");
2825 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2829 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2831 GtkItemFactory *ifactory;
2832 GtkWidget *menuitem = NULL;
2834 compose->use_encryption = use_encryption;
2835 ifactory = gtk_item_factory_from_widget(compose->menubar);
2836 menuitem = gtk_item_factory_get_item
2837 (ifactory, "/Options/Encrypt");
2839 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2843 #define NEXT_PART_NOT_CHILD(info) \
2845 node = info->node; \
2846 while (node->children) \
2847 node = g_node_last_child(node); \
2848 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2851 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2855 MimeInfo *firsttext = NULL;
2856 MimeInfo *encrypted = NULL;
2859 const gchar *partname = NULL;
2861 mimeinfo = procmime_scan_message(msginfo);
2862 if (!mimeinfo) return;
2864 if (mimeinfo->node->children == NULL) {
2865 procmime_mimeinfo_free_all(mimeinfo);
2869 /* find first content part */
2870 child = (MimeInfo *) mimeinfo->node->children->data;
2871 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2872 child = (MimeInfo *)child->node->children->data;
2874 if (child->type == MIMETYPE_TEXT) {
2876 debug_print("First text part found\n");
2877 } else if (compose->mode == COMPOSE_REEDIT &&
2878 child->type == MIMETYPE_APPLICATION &&
2879 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2880 encrypted = (MimeInfo *)child->node->parent->data;
2883 child = (MimeInfo *) mimeinfo->node->children->data;
2884 while (child != NULL) {
2885 if (child == encrypted) {
2886 /* skip this part of tree */
2887 NEXT_PART_NOT_CHILD(child);
2891 if (child->type == MIMETYPE_MULTIPART) {
2892 /* get the actual content */
2893 child = procmime_mimeinfo_next(child);
2897 if (child == firsttext) {
2898 child = procmime_mimeinfo_next(child);
2902 outfile = procmime_get_tmp_file_name(child);
2903 if (procmime_get_part(outfile, child) < 0)
2904 g_warning("Can't get the part of multipart message.");
2906 gchar *content_type;
2908 content_type = procmime_get_content_type_str(child->type, child->subtype);
2910 /* if we meet a pgp signature, we don't attach it, but
2911 * we force signing. */
2912 if (strcmp(content_type, "application/pgp-signature")) {
2913 partname = procmime_mimeinfo_get_parameter(child, "filename");
2914 if (partname == NULL)
2915 partname = procmime_mimeinfo_get_parameter(child, "name");
2916 if (partname == NULL)
2918 compose_attach_append(compose, outfile,
2919 partname, content_type);
2921 compose_force_signing(compose, compose->account);
2923 g_free(content_type);
2926 NEXT_PART_NOT_CHILD(child);
2928 procmime_mimeinfo_free_all(mimeinfo);
2931 #undef NEXT_PART_NOT_CHILD
2936 WAIT_FOR_INDENT_CHAR,
2937 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2940 /* return indent length, we allow:
2941 indent characters followed by indent characters or spaces/tabs,
2942 alphabets and numbers immediately followed by indent characters,
2943 and the repeating sequences of the above
2944 If quote ends with multiple spaces, only the first one is included. */
2945 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2946 const GtkTextIter *start, gint *len)
2948 GtkTextIter iter = *start;
2952 IndentState state = WAIT_FOR_INDENT_CHAR;
2955 gint alnum_count = 0;
2956 gint space_count = 0;
2959 if (prefs_common.quote_chars == NULL) {
2963 while (!gtk_text_iter_ends_line(&iter)) {
2964 wc = gtk_text_iter_get_char(&iter);
2965 if (g_unichar_iswide(wc))
2967 clen = g_unichar_to_utf8(wc, ch);
2971 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2972 is_space = g_unichar_isspace(wc);
2974 if (state == WAIT_FOR_INDENT_CHAR) {
2975 if (!is_indent && !g_unichar_isalnum(wc))
2978 quote_len += alnum_count + space_count + 1;
2979 alnum_count = space_count = 0;
2980 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2983 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2984 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
2988 else if (is_indent) {
2989 quote_len += alnum_count + space_count + 1;
2990 alnum_count = space_count = 0;
2993 state = WAIT_FOR_INDENT_CHAR;
2997 gtk_text_iter_forward_char(&iter);
3000 if (quote_len > 0 && space_count > 0)
3006 if (quote_len > 0) {
3008 gtk_text_iter_forward_chars(&iter, quote_len);
3009 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3015 /* return TRUE if the line is itemized */
3016 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3017 const GtkTextIter *start)
3019 GtkTextIter iter = *start;
3024 if (gtk_text_iter_ends_line(&iter))
3028 wc = gtk_text_iter_get_char(&iter);
3029 if (!g_unichar_isspace(wc))
3031 gtk_text_iter_forward_char(&iter);
3032 if (gtk_text_iter_ends_line(&iter))
3036 clen = g_unichar_to_utf8(wc, ch);
3040 if (!strchr("*-+", ch[0]))
3043 gtk_text_iter_forward_char(&iter);
3044 if (gtk_text_iter_ends_line(&iter))
3046 wc = gtk_text_iter_get_char(&iter);
3047 if (g_unichar_isspace(wc))
3053 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3054 const GtkTextIter *start,
3055 GtkTextIter *break_pos,
3059 GtkTextIter iter = *start, line_end = *start;
3060 PangoLogAttr *attrs;
3067 gboolean can_break = FALSE;
3068 gboolean do_break = FALSE;
3069 gboolean was_white = FALSE;
3070 gboolean prev_dont_break = FALSE;
3072 gtk_text_iter_forward_to_line_end(&line_end);
3073 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3074 len = g_utf8_strlen(str, -1);
3075 /* g_print("breaking line: %d: %s (len = %d)\n",
3076 gtk_text_iter_get_line(&iter), str, len); */
3077 attrs = g_new(PangoLogAttr, len + 1);
3079 pango_default_break(str, -1, NULL, attrs, len + 1);
3083 /* skip quote and leading spaces */
3084 for (i = 0; *p != '\0' && i < len; i++) {
3087 wc = g_utf8_get_char(p);
3088 if (i >= quote_len && !g_unichar_isspace(wc))
3090 if (g_unichar_iswide(wc))
3092 else if (*p == '\t')
3096 p = g_utf8_next_char(p);
3099 for (; *p != '\0' && i < len; i++) {
3100 PangoLogAttr *attr = attrs + i;
3104 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3107 was_white = attr->is_white;
3109 /* don't wrap URI */
3110 if ((uri_len = get_uri_len(p)) > 0) {
3112 if (pos > 0 && col > max_col) {
3122 wc = g_utf8_get_char(p);
3123 if (g_unichar_iswide(wc)) {
3125 if (prev_dont_break && can_break && attr->is_line_break)
3127 } else if (*p == '\t')
3131 if (pos > 0 && col > max_col) {
3136 if (*p == '-' || *p == '/')
3137 prev_dont_break = TRUE;
3139 prev_dont_break = FALSE;
3141 p = g_utf8_next_char(p);
3145 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3150 *break_pos = *start;
3151 gtk_text_iter_set_line_offset(break_pos, pos);
3156 static gboolean compose_join_next_line(Compose *compose,
3157 GtkTextBuffer *buffer,
3159 const gchar *quote_str)
3161 GtkTextIter iter_ = *iter, cur, prev, next, end;
3162 PangoLogAttr attrs[3];
3164 gchar *next_quote_str;
3167 gboolean keep_cursor = FALSE;
3169 if (!gtk_text_iter_forward_line(&iter_) ||
3170 gtk_text_iter_ends_line(&iter_))
3173 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3175 if ((quote_str || next_quote_str) &&
3176 strcmp2(quote_str, next_quote_str) != 0) {
3177 g_free(next_quote_str);
3180 g_free(next_quote_str);
3183 if (quote_len > 0) {
3184 gtk_text_iter_forward_chars(&end, quote_len);
3185 if (gtk_text_iter_ends_line(&end))
3189 /* don't join itemized lines */
3190 if (compose_is_itemized(buffer, &end))
3193 /* don't join signature separator */
3194 if (compose_is_sig_separator(compose, buffer, &iter_))
3197 /* delete quote str */
3199 gtk_text_buffer_delete(buffer, &iter_, &end);
3201 /* don't join line breaks put by the user */
3203 gtk_text_iter_backward_char(&cur);
3204 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3205 gtk_text_iter_forward_char(&cur);
3209 gtk_text_iter_forward_char(&cur);
3210 /* delete linebreak and extra spaces */
3211 while (gtk_text_iter_backward_char(&cur)) {
3212 wc1 = gtk_text_iter_get_char(&cur);
3213 if (!g_unichar_isspace(wc1))
3218 while (!gtk_text_iter_ends_line(&cur)) {
3219 wc1 = gtk_text_iter_get_char(&cur);
3220 if (!g_unichar_isspace(wc1))
3222 gtk_text_iter_forward_char(&cur);
3225 if (!gtk_text_iter_equal(&prev, &next)) {
3228 mark = gtk_text_buffer_get_insert(buffer);
3229 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3230 if (gtk_text_iter_equal(&prev, &cur))
3232 gtk_text_buffer_delete(buffer, &prev, &next);
3236 /* insert space if required */
3237 gtk_text_iter_backward_char(&prev);
3238 wc1 = gtk_text_iter_get_char(&prev);
3239 wc2 = gtk_text_iter_get_char(&next);
3240 gtk_text_iter_forward_char(&next);
3241 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3242 pango_default_break(str, -1, NULL, attrs, 3);
3243 if (!attrs[1].is_line_break ||
3244 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3245 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3247 gtk_text_iter_backward_char(&iter_);
3248 gtk_text_buffer_place_cursor(buffer, &iter_);
3257 #define ADD_TXT_POS(bp_, ep_, pti_) \
3258 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3259 last = last->next; \
3260 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3261 last->next = NULL; \
3263 g_warning("alloc error scanning URIs\n"); \
3266 static gboolean automatic_break = FALSE;
3267 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3269 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3270 GtkTextBuffer *buffer;
3271 GtkTextIter iter, break_pos, end_of_line;
3272 gchar *quote_str = NULL;
3274 gboolean wrap_quote = prefs_common.linewrap_quote;
3275 gboolean prev_autowrap = compose->autowrap;
3276 gint startq_offset = -1, noq_offset = -1;
3277 gint uri_start = -1, uri_stop = -1;
3278 gint nouri_start = -1, nouri_stop = -1;
3280 compose->autowrap = FALSE;
3282 buffer = gtk_text_view_get_buffer(text);
3283 undo_wrapping(compose->undostruct, TRUE);
3288 mark = gtk_text_buffer_get_insert(buffer);
3289 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3292 /* move to paragraph start */
3293 gtk_text_iter_set_line_offset(&iter, 0);
3294 if (gtk_text_iter_ends_line(&iter)) {
3295 while (gtk_text_iter_ends_line(&iter) &&
3296 gtk_text_iter_forward_line(&iter))
3299 while (gtk_text_iter_backward_line(&iter)) {
3300 if (gtk_text_iter_ends_line(&iter)) {
3301 gtk_text_iter_forward_line(&iter);
3307 /* go until paragraph end (empty line) */
3309 while (!gtk_text_iter_ends_line(&iter)) {
3310 gchar *scanpos = NULL;
3311 /* parse table - in order of priority */
3313 const gchar *needle; /* token */
3315 /* token search function */
3316 gchar *(*search) (const gchar *haystack,
3317 const gchar *needle);
3318 /* part parsing function */
3319 gboolean (*parse) (const gchar *start,
3320 const gchar *scanpos,
3324 /* part to URI function */
3325 gchar *(*build_uri) (const gchar *bp,
3329 static struct table parser[] = {
3330 {"http://", strcasestr, get_uri_part, make_uri_string},
3331 {"https://", strcasestr, get_uri_part, make_uri_string},
3332 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3333 {"www.", strcasestr, get_uri_part, make_http_string},
3334 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3335 {"@", strcasestr, get_email_part, make_email_string}
3337 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3338 gint last_index = PARSE_ELEMS;
3340 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3344 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3345 G_CALLBACK(text_inserted),
3348 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3351 uri_start = uri_stop = -1;
3353 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3357 if (startq_offset == -1) {
3358 startq_offset = gtk_text_iter_get_offset(&iter);
3362 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3363 if (startq_offset == -1)
3364 startq_offset = gtk_text_iter_get_offset(&iter);
3366 if (startq_offset == -1)
3367 noq_offset = gtk_text_iter_get_offset(&iter);
3370 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3373 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3374 prefs_common.linewrap_len,
3376 GtkTextIter prev, next, cur;
3378 if (prev_autowrap != FALSE || force) {
3379 automatic_break = TRUE;
3380 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3381 automatic_break = FALSE;
3382 } else if (quote_str && wrap_quote) {
3383 automatic_break = TRUE;
3384 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3385 automatic_break = FALSE;
3388 /* remove trailing spaces */
3390 gtk_text_iter_backward_char(&cur);
3392 while (!gtk_text_iter_starts_line(&cur)) {
3395 gtk_text_iter_backward_char(&cur);
3396 wc = gtk_text_iter_get_char(&cur);
3397 if (!g_unichar_isspace(wc))
3401 if (!gtk_text_iter_equal(&prev, &next)) {
3402 gtk_text_buffer_delete(buffer, &prev, &next);
3404 gtk_text_iter_forward_char(&break_pos);
3408 gtk_text_buffer_insert(buffer, &break_pos,
3412 compose_join_next_line(compose, buffer, &iter, quote_str);
3414 /* move iter to current line start */
3415 gtk_text_iter_set_line_offset(&iter, 0);
3422 /* move iter to next line start */
3428 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3429 G_CALLBACK(text_inserted),
3432 while (!gtk_text_iter_ends_line(&end_of_line)) {
3433 gtk_text_iter_forward_char(&end_of_line);
3435 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3437 nouri_start = gtk_text_iter_get_offset(&iter);
3438 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3440 walk_pos = gtk_text_iter_get_offset(&iter);
3441 /* FIXME: this looks phony. scanning for anything in the parse table */
3442 for (n = 0; n < PARSE_ELEMS; n++) {
3445 tmp = parser[n].search(walk, parser[n].needle);
3447 if (scanpos == NULL || tmp < scanpos) {
3456 /* check if URI can be parsed */
3457 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3458 (const gchar **)&ep, FALSE)
3459 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3463 strlen(parser[last_index].needle);
3466 uri_start = walk_pos + (bp - o_walk);
3467 uri_stop = walk_pos + (ep - o_walk);
3471 gtk_text_iter_forward_line(&iter);
3474 if (startq_offset != -1) {
3475 GtkTextIter startquote, endquote;
3476 gtk_text_buffer_get_iter_at_offset(
3477 buffer, &startquote, startq_offset);
3479 gtk_text_buffer_apply_tag_by_name(
3480 buffer, "quote", &startquote, &endquote);
3482 } else if (noq_offset != -1) {
3483 GtkTextIter startnoquote, endnoquote;
3484 gtk_text_buffer_get_iter_at_offset(
3485 buffer, &startnoquote, noq_offset);
3487 gtk_text_buffer_remove_tag_by_name(
3488 buffer, "quote", &startnoquote, &endnoquote);
3493 GtkTextIter nouri_start_iter, nouri_end_iter;
3494 gtk_text_buffer_get_iter_at_offset(
3495 buffer, &nouri_start_iter, nouri_start);
3496 gtk_text_buffer_get_iter_at_offset(
3497 buffer, &nouri_end_iter, nouri_stop);
3498 gtk_text_buffer_remove_tag_by_name(
3499 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3501 if (uri_start > 0 && uri_stop > 0) {
3502 GtkTextIter uri_start_iter, uri_end_iter;
3503 gtk_text_buffer_get_iter_at_offset(
3504 buffer, &uri_start_iter, uri_start);
3505 gtk_text_buffer_get_iter_at_offset(
3506 buffer, &uri_end_iter, uri_stop);
3507 gtk_text_buffer_apply_tag_by_name(
3508 buffer, "link", &uri_start_iter, &uri_end_iter);
3514 undo_wrapping(compose->undostruct, FALSE);
3515 compose->autowrap = prev_autowrap;
3518 void compose_action_cb(void *data)
3520 Compose *compose = (Compose *)data;
3521 compose_wrap_all(compose);
3524 static void compose_wrap_all(Compose *compose)
3526 compose_wrap_all_full(compose, FALSE);
3529 static void compose_wrap_all_full(Compose *compose, gboolean force)
3531 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3532 GtkTextBuffer *buffer;
3535 buffer = gtk_text_view_get_buffer(text);
3537 gtk_text_buffer_get_start_iter(buffer, &iter);
3538 while (!gtk_text_iter_is_end(&iter))
3539 compose_beautify_paragraph(compose, &iter, force);
3543 static void compose_set_title(Compose *compose)
3549 edited = compose->modified ? _(" [Edited]") : "";
3551 subject = gtk_editable_get_chars(
3552 GTK_EDITABLE(compose->subject_entry), 0, -1);
3554 if (subject && strlen(subject))
3555 str = g_strdup_printf(_("%s - Compose message%s"),
3558 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3559 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3565 * compose_current_mail_account:
3567 * Find a current mail account (the currently selected account, or the
3568 * default account, if a news account is currently selected). If a
3569 * mail account cannot be found, display an error message.
3571 * Return value: Mail account, or NULL if not found.
3573 static PrefsAccount *
3574 compose_current_mail_account(void)
3578 if (cur_account && cur_account->protocol != A_NNTP)
3581 ac = account_get_default();
3582 if (!ac || ac->protocol == A_NNTP) {
3583 alertpanel_error(_("Account for sending mail is not specified.\n"
3584 "Please select a mail account before sending."));
3591 static void compose_select_account(Compose *compose, PrefsAccount *account,
3594 GtkItemFactory *ifactory;
3596 g_return_if_fail(account != NULL);
3598 compose->account = account;
3600 compose_set_title(compose);
3602 ifactory = gtk_item_factory_from_widget(compose->menubar);
3604 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3605 menu_set_active(ifactory, "/Options/Sign", TRUE);
3607 menu_set_active(ifactory, "/Options/Sign", FALSE);
3608 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3609 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3611 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3613 activate_privacy_system(compose, account, FALSE);
3615 if (!init && compose->mode != COMPOSE_REDIRECT)
3616 compose_insert_sig(compose, TRUE);
3619 gboolean compose_check_for_valid_recipient(Compose *compose) {
3620 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3621 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3622 gboolean recipient_found = FALSE;
3626 /* free to and newsgroup list */
3627 slist_free_strings(compose->to_list);
3628 g_slist_free(compose->to_list);
3629 compose->to_list = NULL;
3631 slist_free_strings(compose->newsgroup_list);
3632 g_slist_free(compose->newsgroup_list);
3633 compose->newsgroup_list = NULL;
3635 /* search header entries for to and newsgroup entries */
3636 for (list = compose->header_list; list; list = list->next) {
3639 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3640 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3642 if (entry[0] != '\0') {
3643 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3644 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3645 compose->to_list = address_list_append(compose->to_list, entry);
3646 recipient_found = TRUE;
3649 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3650 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3651 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3652 recipient_found = TRUE;
3659 return recipient_found;
3662 static gboolean compose_check_for_set_recipients(Compose *compose)
3664 if (compose->account->set_autocc && compose->account->auto_cc) {
3665 gboolean found_other = FALSE;
3667 /* search header entries for to and newsgroup entries */
3668 for (list = compose->header_list; list; list = list->next) {
3671 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3672 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3674 if (strcmp(entry, compose->account->auto_cc)
3675 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3685 aval = alertpanel(_("Send"),
3686 _("The only recipient is the default CC address. Send anyway?"),
3687 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3688 if (aval != G_ALERTALTERNATE)
3692 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3693 gboolean found_other = FALSE;
3695 /* search header entries for to and newsgroup entries */
3696 for (list = compose->header_list; list; list = list->next) {
3699 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3700 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3702 if (strcmp(entry, compose->account->auto_cc)
3703 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3713 aval = alertpanel(_("Send"),
3714 _("The only recipient is the default BCC address. Send anyway?"),
3715 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3716 if (aval != G_ALERTALTERNATE)
3723 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3727 if (compose_check_for_valid_recipient(compose) == FALSE) {
3728 alertpanel_error(_("Recipient is not specified."));
3732 if (compose_check_for_set_recipients(compose) == FALSE) {
3736 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3737 if (*str == '\0' && check_subject == TRUE) {
3740 aval = alertpanel(_("Send"),
3741 _("Subject is empty. Send it anyway?"),
3742 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3743 if (aval != G_ALERTALTERNATE)
3750 gint compose_send(Compose *compose)
3757 compose_allow_user_actions (compose, FALSE);
3758 compose->sending = TRUE;
3760 if (compose_check_entries(compose, TRUE) == FALSE)
3763 val = compose_queue(compose, &msgnum, &folder);
3767 alertpanel_error(_("Could not queue message for sending:\n\n"
3768 "Charset conversion failed."));
3769 } else if (val == -3) {
3770 alertpanel_error(_("Could not queue message for sending:\n\n"
3771 "Signature failed."));
3772 } else if (val == -2 && errno != 0) {
3773 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3775 alertpanel_error(_("Could not queue message for sending."));
3781 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3782 compose->sending = FALSE;
3783 compose_close(compose);
3784 /* No more compose access in the normal codepath
3785 * after this point! */
3790 alertpanel_error(_("The message was queued but could not be "
3791 "sent.\nUse \"Send queued messages\" from "
3792 "the main window to retry."));
3793 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3794 compose->sending = FALSE;
3795 compose->modified = TRUE;
3796 compose_allow_user_actions (compose, TRUE);
3801 msgpath = folder_item_fetch_msg(folder, msgnum);
3802 val = procmsg_send_message_queue(msgpath);
3805 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3806 compose->sending = FALSE;
3807 compose_allow_user_actions (compose, TRUE);
3809 folder_item_remove_msg(folder, msgnum);
3810 folder_item_scan(folder);
3815 folder_item_remove_msg(folder, msgnum);
3816 folder_item_scan(folder);
3817 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3818 compose_close(compose);
3820 alertpanel_error(_("The message was queued but could not be "
3821 "sent.\nUse \"Send queued messages\" from "
3822 "the main window to retry."));
3823 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3824 compose_allow_user_actions (compose, TRUE);
3825 compose->modified = TRUE;
3826 compose->sending = FALSE;
3834 compose_allow_user_actions (compose, TRUE);
3835 compose->sending = FALSE;
3836 compose->modified = TRUE;
3841 static gboolean compose_use_attach(Compose *compose)
3843 GtkTreeModel *model = gtk_tree_view_get_model
3844 (GTK_TREE_VIEW(compose->attach_clist));
3845 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3848 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3851 gchar buf[BUFFSIZE];
3853 gboolean first_to_address;
3854 gboolean first_cc_address;
3856 ComposeHeaderEntry *headerentry;
3857 const gchar *headerentryname;
3861 debug_print("Writing redirect header\n");
3863 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3864 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3866 first_to_address = TRUE;
3867 for (list = compose->header_list; list; list = list->next) {
3868 headerentry = ((ComposeHeaderEntry *)list->data);
3869 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3871 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3872 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3873 Xstrdup_a(str, entstr, return -1);
3875 if (str[0] != '\0') {
3876 compose_convert_header
3877 (compose, buf, sizeof(buf), str,
3878 strlen("Resent-To") + 2, TRUE);
3880 if (first_to_address) {
3881 fprintf(fp, "Resent-To: ");
3882 first_to_address = FALSE;
3886 fprintf(fp, "%s", buf);
3890 if (!first_to_address) {
3894 first_cc_address = TRUE;
3895 for (list = compose->header_list; list; list = list->next) {
3896 headerentry = ((ComposeHeaderEntry *)list->data);
3897 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3899 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3900 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3901 Xstrdup_a(str, strg, return -1);
3903 if (str[0] != '\0') {
3904 compose_convert_header
3905 (compose, buf, sizeof(buf), str,
3906 strlen("Resent-Cc") + 2, TRUE);
3908 if (first_cc_address) {
3909 fprintf(fp, "Resent-Cc: ");
3910 first_cc_address = FALSE;
3914 fprintf(fp, "%s", buf);
3918 if (!first_cc_address) {
3925 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3927 gchar buf[BUFFSIZE];
3929 const gchar *entstr;
3930 /* struct utsname utsbuf; */
3932 g_return_val_if_fail(fp != NULL, -1);
3933 g_return_val_if_fail(compose->account != NULL, -1);
3934 g_return_val_if_fail(compose->account->address != NULL, -1);
3937 get_rfc822_date(buf, sizeof(buf));
3938 fprintf(fp, "Resent-Date: %s\n", buf);
3941 if (compose->account->name && *compose->account->name) {
3942 compose_convert_header
3943 (compose, buf, sizeof(buf), compose->account->name,
3944 strlen("From: "), TRUE);
3945 fprintf(fp, "Resent-From: %s <%s>\n",
3946 buf, compose->account->address);
3948 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3951 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3952 if (*entstr != '\0') {
3953 Xstrdup_a(str, entstr, return -1);
3956 compose_convert_header(compose, buf, sizeof(buf), str,
3957 strlen("Subject: "), FALSE);
3958 fprintf(fp, "Subject: %s\n", buf);
3962 /* Resent-Message-ID */
3963 if (compose->account->gen_msgid) {
3964 generate_msgid(buf, sizeof(buf));
3965 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3966 compose->msgid = g_strdup(buf);
3969 compose_redirect_write_headers_from_headerlist(compose, fp);
3971 /* separator between header and body */
3977 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3981 gchar buf[BUFFSIZE];
3983 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
3984 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3988 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3989 /* should filter returnpath, delivered-to */
3990 if (g_ascii_strncasecmp(buf, "Return-Path:",
3991 strlen("Return-Path:")) == 0 ||
3992 g_ascii_strncasecmp(buf, "Delivered-To:",
3993 strlen("Delivered-To:")) == 0 ||
3994 g_ascii_strncasecmp(buf, "Received:",
3995 strlen("Received:")) == 0 ||
3996 g_ascii_strncasecmp(buf, "Subject:",
3997 strlen("Subject:")) == 0 ||
3998 g_ascii_strncasecmp(buf, "X-UIDL:",
3999 strlen("X-UIDL:")) == 0)
4002 if (fputs(buf, fdest) == -1)
4005 if (!prefs_common.redirect_keep_from) {
4006 if (g_ascii_strncasecmp(buf, "From:",
4007 strlen("From:")) == 0) {
4008 fputs(" (by way of ", fdest);
4009 if (compose->account->name
4010 && *compose->account->name) {
4011 compose_convert_header
4012 (compose, buf, sizeof(buf),
4013 compose->account->name,
4016 fprintf(fdest, "%s <%s>",
4018 compose->account->address);
4020 fprintf(fdest, "%s",
4021 compose->account->address);
4026 if (fputs("\n", fdest) == -1)
4030 compose_redirect_write_headers(compose, fdest);
4032 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4033 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4046 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
4048 GtkTextBuffer *buffer;
4049 GtkTextIter start, end;
4052 const gchar *out_codeset;
4053 EncodingType encoding;
4054 MimeInfo *mimemsg, *mimetext;
4057 /* create message MimeInfo */
4058 mimemsg = procmime_mimeinfo_new();
4059 mimemsg->type = MIMETYPE_MESSAGE;
4060 mimemsg->subtype = g_strdup("rfc822");
4061 mimemsg->content = MIMECONTENT_MEM;
4062 mimemsg->tmp = TRUE; /* must free content later */
4063 mimemsg->data.mem = compose_get_header(compose);
4065 /* Create text part MimeInfo */
4066 /* get all composed text */
4067 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4068 gtk_text_buffer_get_start_iter(buffer, &start);
4069 gtk_text_buffer_get_end_iter(buffer, &end);
4070 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4071 if (is_ascii_str(chars)) {
4074 out_codeset = CS_US_ASCII;
4075 encoding = ENC_7BIT;
4077 const gchar *src_codeset = CS_INTERNAL;
4079 out_codeset = conv_get_charset_str(compose->out_encoding);
4082 gchar *test_conv_global_out = NULL;
4083 gchar *test_conv_reply = NULL;
4085 /* automatic mode. be automatic. */
4086 codeconv_set_strict(TRUE);
4088 out_codeset = conv_get_outgoing_charset_str();
4090 debug_print("trying to convert to %s\n", out_codeset);
4091 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4094 if (!test_conv_global_out && compose->orig_charset
4095 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4096 out_codeset = compose->orig_charset;
4097 debug_print("failure; trying to convert to %s\n", out_codeset);
4098 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4101 if (!test_conv_global_out && !test_conv_reply) {
4103 out_codeset = CS_INTERNAL;
4104 debug_print("failure; finally using %s\n", out_codeset);
4106 g_free(test_conv_global_out);
4107 g_free(test_conv_reply);
4108 codeconv_set_strict(FALSE);
4111 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4112 out_codeset = CS_ISO_8859_1;
4114 if (prefs_common.encoding_method == CTE_BASE64)
4115 encoding = ENC_BASE64;
4116 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4117 encoding = ENC_QUOTED_PRINTABLE;
4118 else if (prefs_common.encoding_method == CTE_8BIT)
4119 encoding = ENC_8BIT;
4121 encoding = procmime_get_encoding_for_charset(out_codeset);
4123 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4124 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4126 if (action == COMPOSE_WRITE_FOR_SEND) {
4127 codeconv_set_strict(TRUE);
4128 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4129 codeconv_set_strict(FALSE);
4135 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4136 "to the specified %s charset.\n"
4137 "Send it as %s?"), out_codeset, src_codeset);
4138 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4139 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4142 if (aval != G_ALERTALTERNATE) {
4147 out_codeset = src_codeset;
4153 out_codeset = src_codeset;
4159 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4160 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4161 strstr(buf, "\nFrom ") != NULL) {
4162 encoding = ENC_QUOTED_PRINTABLE;
4166 mimetext = procmime_mimeinfo_new();
4167 mimetext->content = MIMECONTENT_MEM;
4168 mimetext->tmp = TRUE; /* must free content later */
4169 mimetext->data.mem = buf;
4170 mimetext->type = MIMETYPE_TEXT;
4171 mimetext->subtype = g_strdup("plain");
4172 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4173 g_strdup(out_codeset));
4174 /* protect trailing spaces when signing message */
4175 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4176 privacy_system_can_sign(compose->privacy_system)) {
4177 encoding = ENC_QUOTED_PRINTABLE;
4180 /* check for line length limit */
4181 if (action == COMPOSE_WRITE_FOR_SEND &&
4182 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4183 check_line_length(buf, 1000, &line) < 0) {
4187 msg = g_strdup_printf
4188 (_("Line %d exceeds the line length limit (998 bytes).\n"
4189 "The contents of the message might be broken on the way to the delivery.\n"
4191 "Send it anyway?"), line + 1);
4192 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4194 if (aval != G_ALERTALTERNATE) {
4199 if (encoding != ENC_UNKNOWN)
4200 procmime_encode_content(mimetext, encoding);
4202 /* append attachment parts */
4203 if (compose_use_attach(compose)) {
4204 MimeInfo *mimempart;
4205 gchar *boundary = NULL;
4206 mimempart = procmime_mimeinfo_new();
4207 mimempart->content = MIMECONTENT_EMPTY;
4208 mimempart->type = MIMETYPE_MULTIPART;
4209 mimempart->subtype = g_strdup("mixed");
4214 boundary = generate_mime_boundary(NULL);
4215 } while (strstr(buf, boundary) != NULL);
4217 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4220 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4222 g_node_append(mimempart->node, mimetext->node);
4223 g_node_append(mimemsg->node, mimempart->node);
4225 compose_add_attachments(compose, mimempart);
4227 g_node_append(mimemsg->node, mimetext->node);
4229 /* sign message if sending */
4230 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4231 privacy_system_can_sign(compose->privacy_system))
4232 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4235 procmime_write_mimeinfo(mimemsg, fp);
4237 procmime_mimeinfo_free_all(mimemsg);
4242 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4244 GtkTextBuffer *buffer;
4245 GtkTextIter start, end;
4250 if ((fp = g_fopen(file, "wb")) == NULL) {
4251 FILE_OP_ERROR(file, "fopen");
4255 /* chmod for security */
4256 if (change_file_mode_rw(fp, file) < 0) {
4257 FILE_OP_ERROR(file, "chmod");
4258 g_warning("can't change file mode\n");
4261 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4262 gtk_text_buffer_get_start_iter(buffer, &start);
4263 gtk_text_buffer_get_end_iter(buffer, &end);
4264 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4266 chars = conv_codeset_strdup
4267 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4270 if (!chars) return -1;
4273 len = strlen(chars);
4274 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4275 FILE_OP_ERROR(file, "fwrite");
4284 if (fclose(fp) == EOF) {
4285 FILE_OP_ERROR(file, "fclose");
4292 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4295 MsgInfo *msginfo = compose->targetinfo;
4297 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4298 if (!msginfo) return -1;
4300 if (!force && MSG_IS_LOCKED(msginfo->flags))
4303 item = msginfo->folder;
4304 g_return_val_if_fail(item != NULL, -1);
4306 if (procmsg_msg_exist(msginfo) &&
4307 (folder_has_parent_of_type(item, F_QUEUE) ||
4308 folder_has_parent_of_type(item, F_DRAFT)
4309 || msginfo == compose->autosaved_draft)) {
4310 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4311 g_warning("can't remove the old message\n");
4319 void compose_remove_draft(Compose *compose)
4322 MsgInfo *msginfo = compose->targetinfo;
4323 drafts = account_get_special_folder(compose->account, F_DRAFT);
4325 if (procmsg_msg_exist(msginfo)) {
4326 folder_item_remove_msg(drafts, msginfo->msgnum);
4331 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
4333 return compose_queue_sub (compose, msgnum, item, FALSE);
4335 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
4342 static gboolean lock = FALSE;
4343 PrefsAccount *mailac = NULL, *newsac = NULL;
4345 debug_print("queueing message...\n");
4346 g_return_val_if_fail(compose->account != NULL, -1);
4350 if (compose_check_entries(compose, check_subject) == FALSE) {
4355 if (!compose->to_list && !compose->newsgroup_list) {
4356 g_warning("can't get recipient list.");
4361 if (compose->to_list) {
4362 if (compose->account->protocol != A_NNTP)
4363 mailac = compose->account;
4364 else if (cur_account && cur_account->protocol != A_NNTP)
4365 mailac = cur_account;
4366 else if (!(mailac = compose_current_mail_account())) {
4368 alertpanel_error(_("No account for sending mails available!"));
4373 if (compose->newsgroup_list) {
4374 if (compose->account->protocol == A_NNTP)
4375 newsac = compose->account;
4376 else if (!newsac->protocol != A_NNTP) {
4378 alertpanel_error(_("No account for posting news available!"));
4383 /* write queue header */
4384 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4385 G_DIR_SEPARATOR, compose);
4386 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4387 FILE_OP_ERROR(tmp, "fopen");
4392 if (change_file_mode_rw(fp, tmp) < 0) {
4393 FILE_OP_ERROR(tmp, "chmod");
4394 g_warning("can't change file mode\n");
4397 /* queueing variables */
4398 fprintf(fp, "AF:\n");
4399 fprintf(fp, "NF:0\n");
4400 fprintf(fp, "PS:10\n");
4401 fprintf(fp, "SRH:1\n");
4402 fprintf(fp, "SFN:\n");
4403 fprintf(fp, "DSR:\n");
4405 fprintf(fp, "MID:<%s>\n", compose->msgid);
4407 fprintf(fp, "MID:\n");
4408 fprintf(fp, "CFG:\n");
4409 fprintf(fp, "PT:0\n");
4410 fprintf(fp, "S:%s\n", compose->account->address);
4411 fprintf(fp, "RQ:\n");
4413 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4415 fprintf(fp, "SSV:\n");
4417 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4419 fprintf(fp, "NSV:\n");
4420 fprintf(fp, "SSH:\n");
4421 /* write recepient list */
4422 if (compose->to_list) {
4423 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4424 for (cur = compose->to_list->next; cur != NULL;
4426 fprintf(fp, ",<%s>", (gchar *)cur->data);
4429 /* write newsgroup list */
4430 if (compose->newsgroup_list) {
4432 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4433 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4434 fprintf(fp, ",%s", (gchar *)cur->data);
4437 /* Sylpheed account IDs */
4439 fprintf(fp, "MAID:%d\n", mailac->account_id);
4441 fprintf(fp, "NAID:%d\n", newsac->account_id);
4443 if (compose->privacy_system != NULL) {
4444 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4445 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4446 if (compose->use_encryption) {
4449 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4450 if (encdata != NULL) {
4451 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4452 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4453 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4455 } /* else we finally dont want to encrypt */
4457 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4458 /* and if encdata was null, it means there's been a problem in
4465 /* Save copy folder */
4466 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4467 gchar *savefolderid;
4469 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4470 fprintf(fp, "SCF:%s\n", savefolderid);
4471 g_free(savefolderid);
4473 /* Save copy folder */
4474 if (compose->return_receipt) {
4475 fprintf(fp, "RRCPT:1\n");
4477 /* Message-ID of message replying to */
4478 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4481 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4482 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4485 /* Message-ID of message forwarding to */
4486 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4489 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4490 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4495 if (compose->redirect_filename != NULL) {
4496 if (compose_redirect_write_to_file(compose, fp) < 0) {
4505 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4510 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4514 if (fclose(fp) == EOF) {
4515 FILE_OP_ERROR(tmp, "fclose");
4521 queue = account_get_special_folder(compose->account, F_QUEUE);
4523 g_warning("can't find queue folder\n");
4528 folder_item_scan(queue);
4529 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
4530 g_warning("can't queue the message\n");
4538 if (compose->mode == COMPOSE_REEDIT) {
4539 compose_remove_reedit_target(compose, FALSE);
4542 if ((msgnum != NULL) && (item != NULL)) {
4550 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4553 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4555 struct stat statbuf;
4556 gchar *type, *subtype;
4557 GtkTreeModel *model;
4560 model = gtk_tree_view_get_model(tree_view);
4562 if (!gtk_tree_model_get_iter_first(model, &iter))
4565 gtk_tree_model_get(model, &iter,
4569 mimepart = procmime_mimeinfo_new();
4570 mimepart->content = MIMECONTENT_FILE;
4571 mimepart->data.filename = g_strdup(ainfo->file);
4572 mimepart->tmp = FALSE; /* or we destroy our attachment */
4573 mimepart->offset = 0;
4575 stat(ainfo->file, &statbuf);
4576 mimepart->length = statbuf.st_size;
4578 type = g_strdup(ainfo->content_type);
4580 if (!strchr(type, '/')) {
4582 type = g_strdup("application/octet-stream");
4585 subtype = strchr(type, '/') + 1;
4586 *(subtype - 1) = '\0';
4587 mimepart->type = procmime_get_media_type(type);
4588 mimepart->subtype = g_strdup(subtype);
4591 if (mimepart->type == MIMETYPE_MESSAGE &&
4592 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4593 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4595 g_hash_table_insert(mimepart->typeparameters,
4596 g_strdup("name"), g_strdup(ainfo->name));
4597 g_hash_table_insert(mimepart->dispositionparameters,
4598 g_strdup("filename"), g_strdup(ainfo->name));
4599 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4602 if (compose->use_signing) {
4603 if (ainfo->encoding == ENC_7BIT)
4604 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4605 else if (ainfo->encoding == ENC_8BIT)
4606 ainfo->encoding = ENC_BASE64;
4609 procmime_encode_content(mimepart, ainfo->encoding);
4611 g_node_append(parent->node, mimepart->node);
4612 } while (gtk_tree_model_iter_next(model, &iter));
4615 #define QUOTE_IF_REQUIRED(out, str) \
4617 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4621 len = strlen(str) + 3; \
4622 if ((__tmp = alloca(len)) == NULL) { \
4623 g_warning("can't allocate memory\n"); \
4624 g_string_free(header, TRUE); \
4627 g_snprintf(__tmp, len, "\"%s\"", str); \
4632 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4633 g_warning("can't allocate memory\n"); \
4634 g_string_free(header, TRUE); \
4637 strcpy(__tmp, str); \
4643 #define IS_IN_CUSTOM_HEADER(header) \
4644 (compose->account->add_customhdr && \
4645 custom_header_find(compose->account->customhdr_list, header) != NULL)
4647 static void compose_add_headerfield_from_headerlist(Compose *compose,
4649 const gchar *fieldname,
4650 const gchar *seperator)
4652 gchar *str, *fieldname_w_colon, *trans_fieldname;
4653 gboolean add_field = FALSE;
4655 ComposeHeaderEntry *headerentry;
4656 const gchar * headerentryname;
4659 if (IS_IN_CUSTOM_HEADER(fieldname))
4662 debug_print("Adding %s-fields\n", fieldname);
4664 fieldstr = g_string_sized_new(64);
4666 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4667 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4669 for (list = compose->header_list; list; list = list->next) {
4670 headerentry = ((ComposeHeaderEntry *)list->data);
4671 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4673 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4674 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4676 if (str[0] != '\0') {
4678 g_string_append(fieldstr, seperator);
4679 g_string_append(fieldstr, str);
4688 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4689 compose_convert_header
4690 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4691 strlen(fieldname) + 2, TRUE);
4692 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4696 g_free(fieldname_w_colon);
4697 g_string_free(fieldstr, TRUE);
4702 static gchar *compose_get_header(Compose *compose)
4704 gchar buf[BUFFSIZE];
4705 const gchar *entry_str;
4709 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4712 g_return_val_if_fail(compose->account != NULL, NULL);
4713 g_return_val_if_fail(compose->account->address != NULL, NULL);
4715 header = g_string_sized_new(64);
4718 if (compose->account->add_date) {
4719 get_rfc822_date(buf, sizeof(buf));
4720 g_string_append_printf(header, "Date: %s\n", buf);
4724 if (compose->account->name && *compose->account->name) {
4725 compose_convert_header
4726 (compose, buf, sizeof(buf), compose->account->name,
4727 strlen("From: "), TRUE);
4728 QUOTE_IF_REQUIRED(name, buf);
4729 g_string_append_printf(header, "From: %s <%s>\n",
4730 name, compose->account->address);
4732 g_string_append_printf(header, "From: %s\n", compose->account->address);
4735 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4738 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4741 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4744 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4747 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4749 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4752 compose_convert_header(compose, buf, sizeof(buf), str,
4753 strlen("Subject: "), FALSE);
4754 g_string_append_printf(header, "Subject: %s\n", buf);
4760 if (compose->account->gen_msgid) {
4761 generate_msgid(buf, sizeof(buf));
4762 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4763 compose->msgid = g_strdup(buf);
4766 if (compose->remove_references == FALSE) {
4768 if (compose->inreplyto && compose->to_list)
4769 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4772 if (compose->references)
4773 g_string_append_printf(header, "References: %s\n", compose->references);
4777 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4780 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4783 if (compose->account->organization &&
4784 strlen(compose->account->organization) &&
4785 !IS_IN_CUSTOM_HEADER("Organization")) {
4786 compose_convert_header(compose, buf, sizeof(buf),
4787 compose->account->organization,
4788 strlen("Organization: "), FALSE);
4789 g_string_append_printf(header, "Organization: %s\n", buf);
4792 /* Program version and system info */
4793 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4794 !compose->newsgroup_list) {
4795 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4797 gtk_major_version, gtk_minor_version, gtk_micro_version,
4800 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4801 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4803 gtk_major_version, gtk_minor_version, gtk_micro_version,
4807 /* custom headers */
4808 if (compose->account->add_customhdr) {
4811 for (cur = compose->account->customhdr_list; cur != NULL;
4813 CustomHeader *chdr = (CustomHeader *)cur->data;
4815 if (custom_header_is_allowed(chdr->name)) {
4816 compose_convert_header
4817 (compose, buf, sizeof(buf),
4818 chdr->value ? chdr->value : "",
4819 strlen(chdr->name) + 2, FALSE);
4820 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4826 switch (compose->priority) {
4827 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4828 "X-Priority: 1 (Highest)\n");
4830 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4831 "X-Priority: 2 (High)\n");
4833 case PRIORITY_NORMAL: break;
4834 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4835 "X-Priority: 4 (Low)\n");
4837 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4838 "X-Priority: 5 (Lowest)\n");
4840 default: debug_print("compose: priority unknown : %d\n",
4844 /* Request Return Receipt */
4845 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4846 if (compose->return_receipt) {
4847 if (compose->account->name
4848 && *compose->account->name) {
4849 compose_convert_header(compose, buf, sizeof(buf),
4850 compose->account->name,
4851 strlen("Disposition-Notification-To: "),
4853 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4855 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4859 /* get special headers */
4860 for (list = compose->header_list; list; list = list->next) {
4861 ComposeHeaderEntry *headerentry;
4864 gchar *headername_wcolon;
4865 gchar *headername_trans;
4868 gboolean standard_header = FALSE;
4870 headerentry = ((ComposeHeaderEntry *)list->data);
4872 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4873 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4878 if (!strstr(tmp, ":")) {
4879 headername_wcolon = g_strconcat(tmp, ":", NULL);
4880 headername = g_strdup(tmp);
4882 headername_wcolon = g_strdup(tmp);
4883 headername = g_strdup(strtok(tmp, ":"));
4887 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4888 Xstrdup_a(headervalue, entry_str, return NULL);
4889 subst_char(headervalue, '\r', ' ');
4890 subst_char(headervalue, '\n', ' ');
4891 string = std_headers;
4892 while (*string != NULL) {
4893 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4894 if (!strcmp(headername_trans,headername_wcolon))
4895 standard_header = TRUE;
4898 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4899 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
4902 g_free(headername_wcolon);
4906 g_string_free(header, FALSE);
4911 #undef IS_IN_CUSTOM_HEADER
4913 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
4914 gint header_len, gboolean addr_field)
4916 gchar *tmpstr = NULL;
4917 const gchar *out_codeset = NULL;
4919 g_return_if_fail(src != NULL);
4920 g_return_if_fail(dest != NULL);
4922 if (len < 1) return;
4924 tmpstr = g_strdup(src);
4926 subst_char(tmpstr, '\n', ' ');
4927 subst_char(tmpstr, '\r', ' ');
4930 if (!g_utf8_validate(tmpstr, -1, NULL)) {
4931 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
4932 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
4937 codeconv_set_strict(TRUE);
4938 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4939 conv_get_charset_str(compose->out_encoding));
4940 codeconv_set_strict(FALSE);
4942 if (!dest || *dest == '\0') {
4943 gchar *test_conv_global_out = NULL;
4944 gchar *test_conv_reply = NULL;
4946 /* automatic mode. be automatic. */
4947 codeconv_set_strict(TRUE);
4949 out_codeset = conv_get_outgoing_charset_str();
4951 debug_print("trying to convert to %s\n", out_codeset);
4952 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4955 if (!test_conv_global_out && compose->orig_charset) {
4956 out_codeset = compose->orig_charset;
4957 debug_print("failure; trying to convert to %s\n", out_codeset);
4958 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4961 if (!test_conv_global_out && !test_conv_reply) {
4963 out_codeset = CS_INTERNAL;
4964 debug_print("finally using %s\n", out_codeset);
4966 g_free(test_conv_global_out);
4967 g_free(test_conv_reply);
4968 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4970 codeconv_set_strict(FALSE);
4975 static void compose_create_header_entry(Compose *compose)
4977 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4981 GList *combo_list = NULL;
4983 const gchar *header = NULL;
4984 ComposeHeaderEntry *headerentry;
4985 gboolean standard_header = FALSE;
4987 headerentry = g_new0(ComposeHeaderEntry, 1);
4990 combo = gtk_combo_new();
4992 while(*string != NULL) {
4993 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4996 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4997 g_list_free(combo_list);
4998 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4999 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5000 G_CALLBACK(compose_grab_focus_cb), compose);
5001 gtk_widget_show(combo);
5002 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5003 if (compose->header_last) {
5004 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5006 while (*string != NULL) {
5007 if (!strcmp(*string, last_header_entry))
5008 standard_header = TRUE;
5011 if (standard_header)
5012 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5014 if (!compose->header_last || !standard_header) {
5015 switch(compose->account->protocol) {
5017 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5020 header = prefs_common.trans_hdr ? _("To:") : "To:";
5025 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5027 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5028 G_CALLBACK(compose_grab_focus_cb), compose);
5031 entry = gtk_entry_new();
5032 gtk_widget_show(entry);
5033 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);
5035 g_signal_connect(G_OBJECT(entry), "key-press-event",
5036 G_CALLBACK(compose_headerentry_key_press_event_cb),
5038 g_signal_connect(G_OBJECT(entry), "changed",
5039 G_CALLBACK(compose_headerentry_changed_cb),
5041 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5042 G_CALLBACK(compose_grab_focus_cb), compose);
5045 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5046 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5047 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5048 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5049 G_CALLBACK(compose_header_drag_received_cb),
5051 g_signal_connect(G_OBJECT(entry), "drag-drop",
5052 G_CALLBACK(compose_drag_drop),
5055 address_completion_register_entry(GTK_ENTRY(entry));
5057 headerentry->compose = compose;
5058 headerentry->combo = combo;
5059 headerentry->entry = entry;
5060 headerentry->headernum = compose->header_nextrow;
5062 compose->header_nextrow++;
5063 compose->header_last = headerentry;
5066 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5068 ComposeHeaderEntry *last_header;
5070 last_header = compose->header_last;
5072 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5073 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5076 static GtkWidget *compose_create_header(Compose *compose)
5080 GtkWidget *from_optmenu_hbox;
5081 GtkWidget *header_scrolledwin;
5082 GtkWidget *header_table;
5086 /* header labels and entries */
5087 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5088 gtk_widget_show(header_scrolledwin);
5089 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5091 header_table = gtk_table_new(2, 2, FALSE);
5092 gtk_widget_show(header_table);
5093 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
5094 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5095 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5098 /* option menu for selecting accounts */
5099 hbox = gtk_hbox_new(FALSE, 0);
5100 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
5101 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
5102 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
5104 from_optmenu_hbox = compose_account_option_menu_create(compose);
5105 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5106 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5109 compose->header_table = header_table;
5110 compose->header_list = NULL;
5111 compose->header_nextrow = count;
5113 compose_create_header_entry(compose);
5115 compose->table = NULL;
5117 return header_scrolledwin ;
5120 GtkWidget *compose_create_attach(Compose *compose)
5122 GtkWidget *attach_scrwin;
5123 GtkWidget *attach_clist;
5125 GtkListStore *store;
5126 GtkCellRenderer *renderer;
5127 GtkTreeViewColumn *column;
5128 GtkTreeSelection *selection;
5130 /* attachment list */
5131 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5132 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5133 GTK_POLICY_AUTOMATIC,
5134 GTK_POLICY_AUTOMATIC);
5135 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5137 store = gtk_list_store_new(N_ATTACH_COLS,
5142 G_TYPE_AUTO_POINTER,
5144 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5145 (GTK_TREE_MODEL(store)));
5146 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5147 g_object_unref(store);
5149 renderer = gtk_cell_renderer_text_new();
5150 column = gtk_tree_view_column_new_with_attributes
5151 (_("Mime type"), renderer, "text",
5152 COL_MIMETYPE, NULL);
5153 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5155 renderer = gtk_cell_renderer_text_new();
5156 column = gtk_tree_view_column_new_with_attributes
5157 (_("Size"), renderer, "text",
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 (_("Name"), renderer, "text",
5165 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5167 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5168 prefs_common.enable_rules_hint);
5169 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5170 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5172 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5173 G_CALLBACK(attach_selected), compose);
5174 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5175 G_CALLBACK(attach_button_pressed), compose);
5176 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5177 G_CALLBACK(attach_key_pressed), compose);
5180 gtk_drag_dest_set(attach_clist,
5181 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5182 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5183 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5184 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5185 G_CALLBACK(compose_attach_drag_received_cb),
5187 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5188 G_CALLBACK(compose_drag_drop),
5191 compose->attach_scrwin = attach_scrwin;
5192 compose->attach_clist = attach_clist;
5194 return attach_scrwin;
5197 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5198 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5200 static GtkWidget *compose_create_others(Compose *compose)
5203 GtkWidget *savemsg_checkbtn;
5204 GtkWidget *savemsg_entry;
5205 GtkWidget *savemsg_select;
5208 gchar *folderidentifier;
5210 /* Table for settings */
5211 table = gtk_table_new(3, 1, FALSE);
5212 gtk_widget_show(table);
5213 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5216 /* Save Message to folder */
5217 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5218 gtk_widget_show(savemsg_checkbtn);
5219 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5220 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5221 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5223 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5224 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5226 savemsg_entry = gtk_entry_new();
5227 gtk_widget_show(savemsg_entry);
5228 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5229 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5230 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5231 G_CALLBACK(compose_grab_focus_cb), compose);
5232 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5233 folderidentifier = folder_item_get_identifier(account_get_special_folder
5234 (compose->account, F_OUTBOX));
5235 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5236 g_free(folderidentifier);
5239 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5240 gtk_widget_show(savemsg_select);
5241 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5242 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5243 G_CALLBACK(compose_savemsg_select_cb),
5248 compose->savemsg_checkbtn = savemsg_checkbtn;
5249 compose->savemsg_entry = savemsg_entry;
5254 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5256 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5257 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5260 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5265 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5268 path = folder_item_get_identifier(dest);
5270 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5274 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5277 #define BLOCK_WRAP() { \
5278 prev_autowrap = compose->autowrap; \
5279 buffer = gtk_text_view_get_buffer( \
5280 GTK_TEXT_VIEW(compose->text)); \
5281 compose->autowrap = FALSE; \
5283 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5284 G_CALLBACK(compose_changed_cb), \
5286 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5287 G_CALLBACK(text_inserted), \
5290 #define UNBLOCK_WRAP() { \
5291 compose->autowrap = prev_autowrap; \
5292 if (compose->autowrap) \
5293 compose_wrap_all(compose); \
5295 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5296 G_CALLBACK(compose_changed_cb), \
5298 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5299 G_CALLBACK(text_inserted), \
5304 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5308 GtkTextBuffer *buffer;
5310 if (event->button == 3) {
5312 GtkTextIter sel_start, sel_end;
5313 gboolean stuff_selected;
5315 /* move the cursor to allow GtkAspell to check the word
5316 * under the mouse */
5317 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5318 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5320 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5323 stuff_selected = gtk_text_buffer_get_selection_bounds(
5324 GTK_TEXT_VIEW(text)->buffer,
5325 &sel_start, &sel_end);
5327 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5328 /* reselect stuff */
5330 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5331 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5332 &sel_start, &sel_end);
5334 return FALSE; /* pass the event so that the right-click goes through */
5337 if (event->button == 2) {
5339 entry_paste_clipboard(compose, compose->focused_editable,
5340 prefs_common.linewrap_pastes,
5341 GDK_SELECTION_PRIMARY);
5348 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
5354 GtkWidget *handlebox;
5356 GtkWidget *notebook;
5361 GtkWidget *subject_hbox;
5362 GtkWidget *subject_frame;
5363 GtkWidget *subject_entry;
5367 GtkWidget *edit_vbox;
5368 GtkWidget *ruler_hbox;
5370 GtkWidget *scrolledwin;
5372 GtkTextBuffer *buffer;
5373 GtkClipboard *clipboard;
5375 UndoMain *undostruct;
5377 gchar *titles[N_ATTACH_COLS];
5378 guint n_menu_entries;
5381 gboolean success[1];
5382 GtkWidget *popupmenu;
5383 GtkItemFactory *popupfactory;
5384 GtkItemFactory *ifactory;
5385 GtkWidget *tmpl_menu;
5387 GtkWidget *menuitem;
5390 GtkAspell * gtkaspell = NULL;
5393 static GdkGeometry geometry;
5395 g_return_val_if_fail(account != NULL, NULL);
5397 debug_print("Creating compose window...\n");
5398 compose = g_new0(Compose, 1);
5400 titles[COL_MIMETYPE] = _("MIME type");
5401 titles[COL_SIZE] = _("Size");
5402 titles[COL_NAME] = _("Name");
5404 compose->account = account;
5406 compose->mutex = g_mutex_new();
5407 compose->set_cursor_pos = -1;
5409 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5410 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5411 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5413 if (!geometry.max_width) {
5414 geometry.max_width = gdk_screen_width();
5415 geometry.max_height = gdk_screen_height();
5418 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5419 &geometry, GDK_HINT_MAX_SIZE);
5420 if (!geometry.min_width) {
5421 geometry.min_width = 600;
5422 geometry.min_height = 480;
5424 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5425 &geometry, GDK_HINT_MIN_SIZE);
5426 gtk_widget_set_uposition(window, prefs_common.compose_x,
5427 prefs_common.compose_y);
5429 g_signal_connect(G_OBJECT(window), "delete_event",
5430 G_CALLBACK(compose_delete_cb), compose);
5431 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5432 gtk_widget_realize(window);
5434 gtkut_widget_set_composer_icon(window);
5436 vbox = gtk_vbox_new(FALSE, 0);
5437 gtk_container_add(GTK_CONTAINER(window), vbox);
5439 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5440 menubar = menubar_create(window, compose_entries,
5441 n_menu_entries, "<Compose>", compose);
5442 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5444 if (prefs_common.toolbar_detachable) {
5445 handlebox = gtk_handle_box_new();
5447 handlebox = gtk_hbox_new(FALSE, 0);
5449 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5451 gtk_widget_realize(handlebox);
5452 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5455 vbox2 = gtk_vbox_new(FALSE, 2);
5456 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5457 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5460 notebook = gtk_notebook_new();
5461 gtk_widget_set_size_request(notebook, -1, 130);
5462 gtk_widget_show(notebook);
5464 /* header labels and entries */
5465 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
5466 /* attachment list */
5467 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
5469 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
5472 subject_hbox = gtk_hbox_new(FALSE, 0);
5473 gtk_widget_show(subject_hbox);
5475 subject_frame = gtk_frame_new(NULL);
5476 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5477 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5478 gtk_widget_show(subject_frame);
5480 subject = gtk_hbox_new(FALSE, 0);
5481 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5482 gtk_widget_show(subject);
5484 label = gtk_label_new(_("Subject:"));
5485 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5486 gtk_widget_show(label);
5488 subject_entry = gtk_entry_new();
5489 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5490 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5491 G_CALLBACK(compose_grab_focus_cb), compose);
5492 gtk_widget_show(subject_entry);
5493 compose->subject_entry = subject_entry;
5494 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5496 edit_vbox = gtk_vbox_new(FALSE, 0);
5498 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5501 ruler_hbox = gtk_hbox_new(FALSE, 0);
5502 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5504 ruler = gtk_shruler_new();
5505 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5506 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5510 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5511 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5512 GTK_POLICY_AUTOMATIC,
5513 GTK_POLICY_AUTOMATIC);
5514 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5516 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5517 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5519 text = gtk_text_view_new();
5520 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5521 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5522 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5523 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5524 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5526 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5528 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5529 G_CALLBACK(compose_edit_size_alloc),
5531 g_signal_connect(G_OBJECT(buffer), "changed",
5532 G_CALLBACK(compose_changed_cb), compose);
5533 g_signal_connect(G_OBJECT(text), "grab_focus",
5534 G_CALLBACK(compose_grab_focus_cb), compose);
5535 g_signal_connect(G_OBJECT(buffer), "insert_text",
5536 G_CALLBACK(text_inserted), compose);
5537 g_signal_connect(G_OBJECT(text), "button_press_event",
5538 G_CALLBACK(text_clicked), compose);
5539 g_signal_connect(G_OBJECT(subject_entry), "changed",
5540 G_CALLBACK(compose_changed_cb), compose);
5543 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5544 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5545 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5546 g_signal_connect(G_OBJECT(text), "drag_data_received",
5547 G_CALLBACK(compose_insert_drag_received_cb),
5549 g_signal_connect(G_OBJECT(text), "drag-drop",
5550 G_CALLBACK(compose_drag_drop),
5552 gtk_widget_show_all(vbox);
5554 /* pane between attach clist and text */
5555 paned = gtk_vpaned_new();
5556 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5557 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5558 gtk_paned_add1(GTK_PANED(paned), notebook);
5559 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5560 gtk_widget_show_all(paned);
5563 if (prefs_common.textfont) {
5564 PangoFontDescription *font_desc;
5566 font_desc = pango_font_description_from_string
5567 (prefs_common.textfont);
5569 gtk_widget_modify_font(text, font_desc);
5570 pango_font_description_free(font_desc);
5574 color[0] = quote_color;
5575 cmap = gdk_drawable_get_colormap(window->window);
5576 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5577 if (success[0] == FALSE) {
5580 g_warning("Compose: color allocation failed.\n");
5581 style = gtk_widget_get_style(text);
5582 quote_color = style->black;
5585 n_entries = sizeof(compose_popup_entries) /
5586 sizeof(compose_popup_entries[0]);
5587 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5588 "<Compose>", &popupfactory,
5591 ifactory = gtk_item_factory_from_widget(menubar);
5592 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5593 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5594 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5596 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5598 undostruct = undo_init(text);
5599 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5602 address_completion_start(window);
5604 compose->window = window;
5605 compose->vbox = vbox;
5606 compose->menubar = menubar;
5607 compose->handlebox = handlebox;
5609 compose->vbox2 = vbox2;
5611 compose->paned = paned;
5613 compose->edit_vbox = edit_vbox;
5614 compose->ruler_hbox = ruler_hbox;
5615 compose->ruler = ruler;
5616 compose->scrolledwin = scrolledwin;
5617 compose->text = text;
5619 compose->focused_editable = NULL;
5621 compose->popupmenu = popupmenu;
5622 compose->popupfactory = popupfactory;
5624 compose->tmpl_menu = tmpl_menu;
5626 compose->mode = mode;
5628 compose->targetinfo = NULL;
5629 compose->replyinfo = NULL;
5630 compose->fwdinfo = NULL;
5632 compose->replyto = NULL;
5634 compose->bcc = NULL;
5635 compose->followup_to = NULL;
5637 compose->ml_post = NULL;
5639 compose->inreplyto = NULL;
5640 compose->references = NULL;
5641 compose->msgid = NULL;
5642 compose->boundary = NULL;
5644 compose->autowrap = prefs_common.autowrap;
5646 compose->use_signing = FALSE;
5647 compose->use_encryption = FALSE;
5648 compose->privacy_system = NULL;
5650 compose->modified = FALSE;
5652 compose->return_receipt = FALSE;
5654 compose->to_list = NULL;
5655 compose->newsgroup_list = NULL;
5657 compose->undostruct = undostruct;
5659 compose->sig_str = NULL;
5661 compose->exteditor_file = NULL;
5662 compose->exteditor_pid = -1;
5663 compose->exteditor_tag = -1;
5664 compose->draft_timeout_tag = -1;
5667 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5668 if (mode != COMPOSE_REDIRECT) {
5669 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5670 strcmp(prefs_common.dictionary, _("None"))) {
5671 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5672 prefs_common.dictionary,
5673 conv_get_locale_charset_str(),
5674 prefs_common.misspelled_col,
5675 prefs_common.check_while_typing,
5676 prefs_common.use_alternate,
5677 GTK_TEXT_VIEW(text),
5678 GTK_WINDOW(compose->window));
5680 alertpanel_error(_("Spell checker could not "
5682 gtkaspell_checkers_strerror());
5683 gtkaspell_checkers_reset_error();
5685 if (!gtkaspell_set_sug_mode(gtkaspell,
5686 prefs_common.aspell_sugmode)) {
5687 debug_print("Aspell: could not set "
5688 "suggestion mode %s\n",
5689 gtkaspell_checkers_strerror());
5690 gtkaspell_checkers_reset_error();
5693 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5697 compose->gtkaspell = gtkaspell;
5700 compose_select_account(compose, account, TRUE);
5702 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5703 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5704 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5706 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5707 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5709 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5710 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5713 if (account->protocol != A_NNTP)
5714 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5716 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5718 addressbook_set_target_compose(compose);
5720 if (mode != COMPOSE_REDIRECT)
5721 compose_set_template_menu(compose);
5723 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5724 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5727 compose_list = g_list_append(compose_list, compose);
5729 if (!prefs_common.show_ruler)
5730 gtk_widget_hide(ruler_hbox);
5732 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5733 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5734 prefs_common.show_ruler);
5737 compose->priority = PRIORITY_NORMAL;
5738 compose_update_priority_menu_item(compose);
5740 compose_set_out_encoding(compose);
5743 compose_update_actions_menu(compose);
5745 /* Privacy Systems menu */
5746 compose_update_privacy_systems_menu(compose);
5748 activate_privacy_system(compose, account, TRUE);
5749 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5750 gtk_widget_show(window);
5755 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5761 gint num = 0, def_menu = 0;
5763 accounts = account_get_list();
5764 g_return_val_if_fail(accounts != NULL, NULL);
5766 hbox = gtk_hbox_new(FALSE, 0);
5767 optmenu = gtk_option_menu_new();
5768 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5769 menu = gtk_menu_new();
5771 for (; accounts != NULL; accounts = accounts->next, num++) {
5772 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5773 GtkWidget *menuitem;
5776 if (ac == compose->account) def_menu = num;
5779 name = g_strdup_printf("%s: %s <%s>",
5781 ac->name, ac->address);
5783 name = g_strdup_printf("%s: %s",
5784 ac->account_name, ac->address);
5785 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5787 g_signal_connect(G_OBJECT(menuitem), "activate",
5788 G_CALLBACK(account_activated),
5792 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5793 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5798 static void compose_set_priority_cb(gpointer data,
5802 Compose *compose = (Compose *) data;
5803 compose->priority = action;
5806 static void compose_update_priority_menu_item(Compose * compose)
5808 GtkItemFactory *ifactory;
5809 GtkWidget *menuitem = NULL;
5811 ifactory = gtk_item_factory_from_widget(compose->menubar);
5813 switch (compose->priority) {
5814 case PRIORITY_HIGHEST:
5815 menuitem = gtk_item_factory_get_item
5816 (ifactory, "/Options/Priority/Highest");
5819 menuitem = gtk_item_factory_get_item
5820 (ifactory, "/Options/Priority/High");
5822 case PRIORITY_NORMAL:
5823 menuitem = gtk_item_factory_get_item
5824 (ifactory, "/Options/Priority/Normal");
5827 menuitem = gtk_item_factory_get_item
5828 (ifactory, "/Options/Priority/Low");
5830 case PRIORITY_LOWEST:
5831 menuitem = gtk_item_factory_get_item
5832 (ifactory, "/Options/Priority/Lowest");
5835 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5838 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5840 Compose *compose = (Compose *) data;
5842 GtkItemFactory *ifactory;
5843 gboolean can_sign = FALSE, can_encrypt = FALSE;
5845 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5847 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5850 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5851 g_free(compose->privacy_system);
5852 compose->privacy_system = NULL;
5853 if (systemid != NULL) {
5854 compose->privacy_system = g_strdup(systemid);
5856 can_sign = privacy_system_can_sign(systemid);
5857 can_encrypt = privacy_system_can_encrypt(systemid);
5860 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5862 ifactory = gtk_item_factory_from_widget(compose->menubar);
5863 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5864 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5867 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
5869 static gchar *branch_path = "/Options/Privacy System";
5870 GtkItemFactory *ifactory;
5871 GtkWidget *menuitem = NULL;
5873 gboolean can_sign = FALSE, can_encrypt = FALSE;
5874 gboolean found = FALSE;
5876 ifactory = gtk_item_factory_from_widget(compose->menubar);
5878 if (compose->privacy_system != NULL) {
5881 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5882 g_return_if_fail(menuitem != NULL);
5884 amenu = GTK_MENU_SHELL(menuitem)->children;
5886 while (amenu != NULL) {
5887 GList *alist = amenu->next;
5889 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
5890 if (systemid != NULL) {
5891 if (strcmp(systemid, compose->privacy_system) == 0) {
5892 menuitem = GTK_WIDGET(amenu->data);
5894 can_sign = privacy_system_can_sign(systemid);
5895 can_encrypt = privacy_system_can_encrypt(systemid);
5899 } else if (strlen(compose->privacy_system) == 0) {
5900 menuitem = GTK_WIDGET(amenu->data);
5903 can_encrypt = FALSE;
5910 if (menuitem != NULL)
5911 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5913 if (warn && !found && strlen(compose->privacy_system)) {
5914 gchar *tmp = g_strdup_printf(
5915 _("The privacy system '%s' cannot be loaded. You "
5916 "will not be able to sign or encrypt this message."),
5917 compose->privacy_system);
5918 alertpanel_warning(tmp);
5923 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5924 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5927 static void compose_set_out_encoding(Compose *compose)
5929 GtkItemFactoryEntry *entry;
5930 GtkItemFactory *ifactory;
5931 CharSet out_encoding;
5932 gchar *path, *p, *q;
5935 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
5936 ifactory = gtk_item_factory_from_widget(compose->menubar);
5938 for (entry = compose_entries; entry->callback != compose_address_cb;
5940 if (entry->callback == compose_set_encoding_cb &&
5941 (CharSet)entry->callback_action == out_encoding) {
5942 p = q = path = g_strdup(entry->path);
5954 item = gtk_item_factory_get_item(ifactory, path);
5955 gtk_widget_activate(item);
5962 static void compose_set_template_menu(Compose *compose)
5964 GSList *tmpl_list, *cur;
5968 tmpl_list = template_get_config();
5970 menu = gtk_menu_new();
5972 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5973 Template *tmpl = (Template *)cur->data;
5975 item = gtk_menu_item_new_with_label(tmpl->name);
5976 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5977 g_signal_connect(G_OBJECT(item), "activate",
5978 G_CALLBACK(compose_template_activate_cb),
5980 g_object_set_data(G_OBJECT(item), "template", tmpl);
5981 gtk_widget_show(item);
5984 gtk_widget_show(menu);
5985 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5988 void compose_update_actions_menu(Compose *compose)
5990 GtkItemFactory *ifactory;
5992 ifactory = gtk_item_factory_from_widget(compose->menubar);
5993 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5996 void compose_update_privacy_systems_menu(Compose *compose)
5998 static gchar *branch_path = "/Options/Privacy System";
5999 GtkItemFactory *ifactory;
6000 GtkWidget *menuitem;
6001 GSList *systems, *cur;
6004 GtkWidget *system_none;
6007 ifactory = gtk_item_factory_from_widget(compose->menubar);
6009 /* remove old entries */
6010 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6011 g_return_if_fail(menuitem != NULL);
6013 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6014 while (amenu != NULL) {
6015 GList *alist = amenu->next;
6016 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6020 system_none = gtk_item_factory_get_widget(ifactory,
6021 "/Options/Privacy System/None");
6023 g_signal_connect(G_OBJECT(system_none), "activate",
6024 G_CALLBACK(compose_set_privacy_system_cb), compose);
6026 systems = privacy_get_system_ids();
6027 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6028 gchar *systemid = cur->data;
6030 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6031 widget = gtk_radio_menu_item_new_with_label(group,
6032 privacy_system_get_name(systemid));
6033 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6034 g_strdup(systemid), g_free);
6035 g_signal_connect(G_OBJECT(widget), "activate",
6036 G_CALLBACK(compose_set_privacy_system_cb), compose);
6038 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6039 gtk_widget_show(widget);
6042 g_slist_free(systems);
6045 void compose_reflect_prefs_all(void)
6050 for (cur = compose_list; cur != NULL; cur = cur->next) {
6051 compose = (Compose *)cur->data;
6052 compose_set_template_menu(compose);
6056 void compose_reflect_prefs_pixmap_theme(void)
6061 for (cur = compose_list; cur != NULL; cur = cur->next) {
6062 compose = (Compose *)cur->data;
6063 toolbar_update(TOOLBAR_COMPOSE, compose);
6067 static void compose_template_apply(Compose *compose, Template *tmpl,
6071 GtkTextBuffer *buffer;
6075 gchar *parsed_str = NULL;
6076 gint cursor_pos = 0;
6079 text = GTK_TEXT_VIEW(compose->text);
6080 buffer = gtk_text_view_get_buffer(text);
6082 if (tmpl->subject && *tmpl->subject != '\0')
6083 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
6085 if (tmpl->to && *tmpl->to != '\0')
6086 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
6087 if (tmpl->cc && *tmpl->cc != '\0')
6088 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
6090 if (tmpl->bcc && *tmpl->bcc != '\0')
6091 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
6094 gtk_text_buffer_set_text(buffer, "", -1);
6096 mark = gtk_text_buffer_get_insert(buffer);
6097 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6100 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6101 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6104 if (prefs_common.quotemark && *prefs_common.quotemark)
6105 qmark = prefs_common.quotemark;
6109 if (compose->replyinfo != NULL)
6110 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6111 tmpl->value, qmark, NULL, FALSE);
6112 else if (compose->fwdinfo != NULL)
6113 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6114 tmpl->value, qmark, NULL, FALSE);
6119 if (replace && parsed_str && compose->account->auto_sig)
6120 compose_insert_sig(compose, FALSE);
6122 if (replace && parsed_str) {
6123 gtk_text_buffer_get_start_iter(buffer, &iter);
6124 gtk_text_buffer_place_cursor(buffer, &iter);
6128 cursor_pos = quote_fmt_get_cursor_pos();
6129 compose->set_cursor_pos = cursor_pos;
6130 if (cursor_pos == -1)
6132 gtk_text_buffer_get_start_iter(buffer, &iter);
6133 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6134 gtk_text_buffer_place_cursor(buffer, &iter);
6137 compose_changed_cb(NULL, compose);
6140 static void compose_destroy(Compose *compose)
6142 compose_list = g_list_remove(compose_list, compose);
6144 /* NOTE: address_completion_end() does nothing with the window
6145 * however this may change. */
6146 address_completion_end(compose->window);
6148 slist_free_strings(compose->to_list);
6149 g_slist_free(compose->to_list);
6150 slist_free_strings(compose->newsgroup_list);
6151 g_slist_free(compose->newsgroup_list);
6152 slist_free_strings(compose->header_list);
6153 g_slist_free(compose->header_list);
6155 procmsg_msginfo_free(compose->targetinfo);
6156 procmsg_msginfo_free(compose->replyinfo);
6157 procmsg_msginfo_free(compose->fwdinfo);
6159 g_free(compose->replyto);
6160 g_free(compose->cc);
6161 g_free(compose->bcc);
6162 g_free(compose->newsgroups);
6163 g_free(compose->followup_to);
6165 g_free(compose->ml_post);
6167 g_free(compose->inreplyto);
6168 g_free(compose->references);
6169 g_free(compose->msgid);
6170 g_free(compose->boundary);
6172 if (compose->redirect_filename)
6173 g_free(compose->redirect_filename);
6174 if (compose->undostruct)
6175 undo_destroy(compose->undostruct);
6177 g_free(compose->sig_str);
6179 g_free(compose->exteditor_file);
6181 g_free(compose->orig_charset);
6183 g_free(compose->privacy_system);
6185 if (addressbook_get_target_compose() == compose)
6186 addressbook_set_target_compose(NULL);
6189 if (compose->gtkaspell) {
6190 gtkaspell_delete(compose->gtkaspell);
6191 compose->gtkaspell = NULL;
6195 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6196 prefs_common.compose_height = compose->window->allocation.height;
6198 if (!gtk_widget_get_parent(compose->paned))
6199 gtk_widget_destroy(compose->paned);
6200 gtk_widget_destroy(compose->popupmenu);
6202 gtk_widget_destroy(compose->window);
6203 toolbar_destroy(compose->toolbar);
6204 g_free(compose->toolbar);
6205 g_mutex_free(compose->mutex);
6209 static void compose_attach_info_free(AttachInfo *ainfo)
6211 g_free(ainfo->file);
6212 g_free(ainfo->content_type);
6213 g_free(ainfo->name);
6217 static void compose_attach_remove_selected(Compose *compose)
6219 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6220 GtkTreeSelection *selection;
6222 GtkTreeModel *model;
6224 selection = gtk_tree_view_get_selection(tree_view);
6225 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6230 for (cur = sel; cur != NULL; cur = cur->next) {
6231 GtkTreePath *path = cur->data;
6232 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6235 gtk_tree_path_free(path);
6238 for (cur = sel; cur != NULL; cur = cur->next) {
6239 GtkTreeRowReference *ref = cur->data;
6240 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6243 if (gtk_tree_model_get_iter(model, &iter, path))
6244 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6246 gtk_tree_path_free(path);
6247 gtk_tree_row_reference_free(ref);
6253 static struct _AttachProperty
6256 GtkWidget *mimetype_entry;
6257 GtkWidget *encoding_optmenu;
6258 GtkWidget *path_entry;
6259 GtkWidget *filename_entry;
6261 GtkWidget *cancel_btn;
6264 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6266 gtk_tree_path_free((GtkTreePath *)ptr);
6269 static void compose_attach_property(Compose *compose)
6271 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6273 GtkOptionMenu *optmenu;
6274 GtkTreeSelection *selection;
6276 GtkTreeModel *model;
6279 static gboolean cancelled;
6281 /* only if one selected */
6282 selection = gtk_tree_view_get_selection(tree_view);
6283 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6286 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6290 path = (GtkTreePath *) sel->data;
6291 gtk_tree_model_get_iter(model, &iter, path);
6292 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6295 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6301 if (!attach_prop.window)
6302 compose_attach_property_create(&cancelled);
6303 gtk_widget_grab_focus(attach_prop.ok_btn);
6304 gtk_widget_show(attach_prop.window);
6305 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6307 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6308 if (ainfo->encoding == ENC_UNKNOWN)
6309 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6310 GINT_TO_POINTER(ENC_BASE64));
6312 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6313 GINT_TO_POINTER(ainfo->encoding));
6315 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6316 ainfo->content_type ? ainfo->content_type : "");
6317 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6318 ainfo->file ? ainfo->file : "");
6319 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6320 ainfo->name ? ainfo->name : "");
6323 const gchar *entry_text;
6325 gchar *cnttype = NULL;
6329 GtkWidget *menuitem;
6334 gtk_widget_hide(attach_prop.window);
6339 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6340 if (*entry_text != '\0') {
6343 text = g_strstrip(g_strdup(entry_text));
6344 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6345 cnttype = g_strdup(text);
6348 alertpanel_error(_("Invalid MIME type."));
6354 menu = gtk_option_menu_get_menu(optmenu);
6355 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6356 ainfo->encoding = GPOINTER_TO_INT
6357 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6359 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6360 if (*entry_text != '\0') {
6361 if (is_file_exist(entry_text) &&
6362 (size = get_file_size(entry_text)) > 0)
6363 file = g_strdup(entry_text);
6366 (_("File doesn't exist or is empty."));
6372 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6373 if (*entry_text != '\0') {
6374 g_free(ainfo->name);
6375 ainfo->name = g_strdup(entry_text);
6379 g_free(ainfo->content_type);
6380 ainfo->content_type = cnttype;
6383 g_free(ainfo->file);
6389 /* update tree store */
6390 text = to_human_readable(ainfo->size);
6391 gtk_tree_model_get_iter(model, &iter, path);
6392 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6393 COL_MIMETYPE, ainfo->content_type,
6395 COL_NAME, ainfo->name,
6401 gtk_tree_path_free(path);
6404 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6406 label = gtk_label_new(str); \
6407 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6408 GTK_FILL, 0, 0, 0); \
6409 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6411 entry = gtk_entry_new(); \
6412 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6413 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6416 static void compose_attach_property_create(gboolean *cancelled)
6422 GtkWidget *mimetype_entry;
6425 GtkWidget *optmenu_menu;
6426 GtkWidget *menuitem;
6427 GtkWidget *path_entry;
6428 GtkWidget *filename_entry;
6431 GtkWidget *cancel_btn;
6432 GList *mime_type_list, *strlist;
6434 debug_print("Creating attach_property window...\n");
6436 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6437 gtk_widget_set_size_request(window, 480, -1);
6438 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6439 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6440 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6441 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6442 g_signal_connect(G_OBJECT(window), "delete_event",
6443 G_CALLBACK(attach_property_delete_event),
6445 g_signal_connect(G_OBJECT(window), "key_press_event",
6446 G_CALLBACK(attach_property_key_pressed),
6449 vbox = gtk_vbox_new(FALSE, 8);
6450 gtk_container_add(GTK_CONTAINER(window), vbox);
6452 table = gtk_table_new(4, 2, FALSE);
6453 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6454 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6455 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6457 label = gtk_label_new(_("MIME type"));
6458 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6460 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6461 mimetype_entry = gtk_combo_new();
6462 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6463 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6465 /* stuff with list */
6466 mime_type_list = procmime_get_mime_type_list();
6468 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6469 MimeType *type = (MimeType *) mime_type_list->data;
6472 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6474 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6477 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6478 (GCompareFunc)strcmp2);
6481 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6483 for (mime_type_list = strlist; mime_type_list != NULL;
6484 mime_type_list = mime_type_list->next)
6485 g_free(mime_type_list->data);
6486 g_list_free(strlist);
6488 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6490 label = gtk_label_new(_("Encoding"));
6491 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6493 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6495 hbox = gtk_hbox_new(FALSE, 0);
6496 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6497 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6499 optmenu = gtk_option_menu_new();
6500 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6502 optmenu_menu = gtk_menu_new();
6503 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6504 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6505 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6506 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6507 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6508 ENC_QUOTED_PRINTABLE);
6509 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6511 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6513 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6515 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6516 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6518 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
6519 &ok_btn, GTK_STOCK_OK,
6521 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6522 gtk_widget_grab_default(ok_btn);
6524 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6525 G_CALLBACK(attach_property_ok),
6527 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6528 G_CALLBACK(attach_property_cancel),
6531 gtk_widget_show_all(vbox);
6533 attach_prop.window = window;
6534 attach_prop.mimetype_entry = mimetype_entry;
6535 attach_prop.encoding_optmenu = optmenu;
6536 attach_prop.path_entry = path_entry;
6537 attach_prop.filename_entry = filename_entry;
6538 attach_prop.ok_btn = ok_btn;
6539 attach_prop.cancel_btn = cancel_btn;
6542 #undef SET_LABEL_AND_ENTRY
6544 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6550 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6556 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6557 gboolean *cancelled)
6565 static gboolean attach_property_key_pressed(GtkWidget *widget,
6567 gboolean *cancelled)
6569 if (event && event->keyval == GDK_Escape) {
6576 static void compose_exec_ext_editor(Compose *compose)
6583 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6584 G_DIR_SEPARATOR, compose);
6586 if (pipe(pipe_fds) < 0) {
6592 if ((pid = fork()) < 0) {
6599 /* close the write side of the pipe */
6602 compose->exteditor_file = g_strdup(tmp);
6603 compose->exteditor_pid = pid;
6605 compose_set_ext_editor_sensitive(compose, FALSE);
6607 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6608 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6612 } else { /* process-monitoring process */
6618 /* close the read side of the pipe */
6621 if (compose_write_body_to_file(compose, tmp) < 0) {
6622 fd_write_all(pipe_fds[1], "2\n", 2);
6626 pid_ed = compose_exec_ext_editor_real(tmp);
6628 fd_write_all(pipe_fds[1], "1\n", 2);
6632 /* wait until editor is terminated */
6633 waitpid(pid_ed, NULL, 0);
6635 fd_write_all(pipe_fds[1], "0\n", 2);
6642 #endif /* G_OS_UNIX */
6646 static gint compose_exec_ext_editor_real(const gchar *file)
6648 static gchar *def_cmd = "emacs %s";
6654 g_return_val_if_fail(file != NULL, -1);
6656 if ((pid = fork()) < 0) {
6661 if (pid != 0) return pid;
6663 /* grandchild process */
6665 if (setpgid(0, getppid()))
6668 if (prefs_common.ext_editor_cmd &&
6669 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6670 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6671 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6673 if (prefs_common.ext_editor_cmd)
6674 g_warning("External editor command line is invalid: '%s'\n",
6675 prefs_common.ext_editor_cmd);
6676 g_snprintf(buf, sizeof(buf), def_cmd, file);
6679 cmdline = strsplit_with_quote(buf, " ", 1024);
6680 execvp(cmdline[0], cmdline);
6683 g_strfreev(cmdline);
6688 static gboolean compose_ext_editor_kill(Compose *compose)
6690 pid_t pgid = compose->exteditor_pid * -1;
6693 ret = kill(pgid, 0);
6695 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6699 msg = g_strdup_printf
6700 (_("The external editor is still working.\n"
6701 "Force terminating the process?\n"
6702 "process group id: %d"), -pgid);
6703 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
6704 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
6708 if (val == G_ALERTALTERNATE) {
6709 g_source_remove(compose->exteditor_tag);
6710 g_io_channel_shutdown(compose->exteditor_ch,
6712 g_io_channel_unref(compose->exteditor_ch);
6714 if (kill(pgid, SIGTERM) < 0) perror("kill");
6715 waitpid(compose->exteditor_pid, NULL, 0);
6717 g_warning("Terminated process group id: %d", -pgid);
6718 g_warning("Temporary file: %s",
6719 compose->exteditor_file);
6721 compose_set_ext_editor_sensitive(compose, TRUE);
6723 g_free(compose->exteditor_file);
6724 compose->exteditor_file = NULL;
6725 compose->exteditor_pid = -1;
6726 compose->exteditor_ch = NULL;
6727 compose->exteditor_tag = -1;
6735 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6739 Compose *compose = (Compose *)data;
6742 debug_print(_("Compose: input from monitoring process\n"));
6744 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6746 g_io_channel_shutdown(source, FALSE, NULL);
6747 g_io_channel_unref(source);
6749 waitpid(compose->exteditor_pid, NULL, 0);
6751 if (buf[0] == '0') { /* success */
6752 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6753 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6755 gtk_text_buffer_set_text(buffer, "", -1);
6756 compose_insert_file(compose, compose->exteditor_file);
6757 compose_changed_cb(NULL, compose);
6759 if (g_unlink(compose->exteditor_file) < 0)
6760 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6761 } else if (buf[0] == '1') { /* failed */
6762 g_warning("Couldn't exec external editor\n");
6763 if (g_unlink(compose->exteditor_file) < 0)
6764 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6765 } else if (buf[0] == '2') {
6766 g_warning("Couldn't write to file\n");
6767 } else if (buf[0] == '3') {
6768 g_warning("Pipe read failed\n");
6771 compose_set_ext_editor_sensitive(compose, TRUE);
6773 g_free(compose->exteditor_file);
6774 compose->exteditor_file = NULL;
6775 compose->exteditor_pid = -1;
6776 compose->exteditor_ch = NULL;
6777 compose->exteditor_tag = -1;
6782 static void compose_set_ext_editor_sensitive(Compose *compose,
6785 GtkItemFactory *ifactory;
6787 ifactory = gtk_item_factory_from_widget(compose->menubar);
6789 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6790 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6791 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6792 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6793 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6794 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6795 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6798 gtk_widget_set_sensitive(compose->text, sensitive);
6799 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6800 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6801 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6802 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6803 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6804 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6805 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
6806 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
6808 #endif /* G_OS_UNIX */
6811 * compose_undo_state_changed:
6813 * Change the sensivity of the menuentries undo and redo
6815 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6816 gint redo_state, gpointer data)
6818 GtkWidget *widget = GTK_WIDGET(data);
6819 GtkItemFactory *ifactory;
6821 g_return_if_fail(widget != NULL);
6823 ifactory = gtk_item_factory_from_widget(widget);
6825 switch (undo_state) {
6826 case UNDO_STATE_TRUE:
6827 if (!undostruct->undo_state) {
6828 undostruct->undo_state = TRUE;
6829 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6832 case UNDO_STATE_FALSE:
6833 if (undostruct->undo_state) {
6834 undostruct->undo_state = FALSE;
6835 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6838 case UNDO_STATE_UNCHANGED:
6840 case UNDO_STATE_REFRESH:
6841 menu_set_sensitive(ifactory, "/Edit/Undo",
6842 undostruct->undo_state);
6845 g_warning("Undo state not recognized");
6849 switch (redo_state) {
6850 case UNDO_STATE_TRUE:
6851 if (!undostruct->redo_state) {
6852 undostruct->redo_state = TRUE;
6853 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6856 case UNDO_STATE_FALSE:
6857 if (undostruct->redo_state) {
6858 undostruct->redo_state = FALSE;
6859 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6862 case UNDO_STATE_UNCHANGED:
6864 case UNDO_STATE_REFRESH:
6865 menu_set_sensitive(ifactory, "/Edit/Redo",
6866 undostruct->redo_state);
6869 g_warning("Redo state not recognized");
6874 /* callback functions */
6876 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6877 * includes "non-client" (windows-izm) in calculation, so this calculation
6878 * may not be accurate.
6880 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6881 GtkAllocation *allocation,
6882 GtkSHRuler *shruler)
6884 if (prefs_common.show_ruler) {
6885 gint char_width = 0, char_height = 0;
6886 gint line_width_in_chars;
6888 gtkut_get_font_size(GTK_WIDGET(widget),
6889 &char_width, &char_height);
6890 line_width_in_chars =
6891 (allocation->width - allocation->x) / char_width;
6893 /* got the maximum */
6894 gtk_ruler_set_range(GTK_RULER(shruler),
6895 0.0, line_width_in_chars, 0,
6896 /*line_width_in_chars*/ char_width);
6902 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6904 Compose *compose = (Compose *)data;
6907 gchar *folderidentifier;
6909 ac = account_find_from_id(
6910 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
6911 g_return_if_fail(ac != NULL);
6913 if (ac != compose->account)
6914 compose_select_account(compose, ac, FALSE);
6916 /* Set message save folder */
6917 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6918 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
6920 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
6921 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
6923 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6924 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6925 folderidentifier = folder_item_get_identifier(account_get_special_folder
6926 (compose->account, F_OUTBOX));
6927 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
6928 g_free(folderidentifier);
6932 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
6933 GtkTreeViewColumn *column, Compose *compose)
6935 compose_attach_property(compose);
6938 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6941 Compose *compose = (Compose *)data;
6942 GtkTreeSelection *attach_selection;
6943 gint attach_nr_selected;
6944 GtkItemFactory *ifactory;
6946 if (!event) return FALSE;
6948 if (event->button == 3) {
6949 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
6950 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
6951 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6953 if (attach_nr_selected > 0)
6955 menu_set_sensitive(ifactory, "/Remove", TRUE);
6956 menu_set_sensitive(ifactory, "/Properties...", TRUE);
6958 menu_set_sensitive(ifactory, "/Remove", FALSE);
6959 menu_set_sensitive(ifactory, "/Properties...", FALSE);
6962 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6963 NULL, NULL, event->button, event->time);
6970 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6973 Compose *compose = (Compose *)data;
6975 if (!event) return FALSE;
6977 switch (event->keyval) {
6979 compose_attach_remove_selected(compose);
6985 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6987 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6988 toolbar_comp_set_sensitive(compose, allow);
6989 menu_set_sensitive(ifactory, "/Message", allow);
6990 menu_set_sensitive(ifactory, "/Edit", allow);
6992 menu_set_sensitive(ifactory, "/Spelling", allow);
6994 menu_set_sensitive(ifactory, "/Options", allow);
6995 menu_set_sensitive(ifactory, "/Tools", allow);
6996 menu_set_sensitive(ifactory, "/Help", allow);
6998 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7002 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7004 Compose *compose = (Compose *)data;
7006 if (prefs_common.work_offline && !inc_offline_should_override())
7009 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7010 gtk_timeout_remove(compose->draft_timeout_tag);
7011 compose->draft_timeout_tag = -1;
7014 compose_send(compose);
7017 static void compose_send_later_cb(gpointer data, guint action,
7020 Compose *compose = (Compose *)data;
7023 val = compose_queue_sub(compose, NULL, NULL, TRUE);
7025 compose_close(compose);
7026 else if (val == -2) {
7027 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7031 void compose_draft (gpointer data)
7033 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7036 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7038 Compose *compose = (Compose *)data;
7042 MsgFlags flag = {0, 0};
7043 static gboolean lock = FALSE;
7044 MsgInfo *newmsginfo;
7046 gboolean target_locked = FALSE;
7050 draft = account_get_special_folder(compose->account, F_DRAFT);
7051 g_return_if_fail(draft != NULL);
7053 if (!g_mutex_trylock(compose->mutex)) {
7054 /* we don't want to lock the mutex once it's available,
7055 * because as the only other part of compose.c locking
7056 * it is compose_close - which means once unlocked,
7057 * the compose struct will be freed */
7058 debug_print("couldn't lock mutex, probably sending\n");
7064 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7065 G_DIR_SEPARATOR, compose);
7066 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7067 FILE_OP_ERROR(tmp, "fopen");
7071 /* chmod for security */
7072 if (change_file_mode_rw(fp, tmp) < 0) {
7073 FILE_OP_ERROR(tmp, "chmod");
7074 g_warning("can't change file mode\n");
7077 /* Save draft infos */
7078 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7079 fprintf(fp, "S:%s\n", compose->account->address);
7080 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7081 gchar *savefolderid;
7083 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7084 fprintf(fp, "SCF:%s\n", savefolderid);
7085 g_free(savefolderid);
7087 if (compose->return_receipt) {
7088 fprintf(fp, "RRCPT:1\n");
7090 if (compose->privacy_system) {
7091 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7092 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7093 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7097 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
7105 if (compose->targetinfo) {
7106 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7107 flag.perm_flags = target_locked?MSG_LOCKED:0;
7109 flag.tmp_flags = MSG_DRAFT;
7111 folder_item_scan(draft);
7112 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7115 if (action != COMPOSE_AUTO_SAVE)
7116 alertpanel_error(_("Could not save draft."));
7120 draft->mtime = 0; /* force updating */
7122 if (compose->mode == COMPOSE_REEDIT) {
7123 compose_remove_reedit_target(compose, TRUE);
7126 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7128 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7130 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
7132 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7133 if (compose_use_attach(compose))
7134 procmsg_msginfo_set_flags(newmsginfo, 0,
7135 MSG_HAS_ATTACHMENT);
7137 procmsg_msginfo_free(newmsginfo);
7140 folder_item_scan(draft);
7142 if (action == COMPOSE_QUIT_EDITING) {
7144 g_mutex_unlock(compose->mutex); /* must be done before closing */
7145 compose_close(compose);
7151 path = folder_item_fetch_msg(draft, msgnum);
7153 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
7156 if (g_stat(path, &s) < 0) {
7157 FILE_OP_ERROR(path, "stat");
7163 procmsg_msginfo_free(compose->targetinfo);
7164 compose->targetinfo = procmsg_msginfo_new();
7165 compose->targetinfo->msgnum = msgnum;
7166 compose->targetinfo->size = s.st_size;
7167 compose->targetinfo->mtime = s.st_mtime;
7168 compose->targetinfo->folder = draft;
7170 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
7171 compose->mode = COMPOSE_REEDIT;
7173 if (action == COMPOSE_AUTO_SAVE) {
7174 compose->autosaved_draft = compose->targetinfo;
7176 compose->modified = FALSE;
7177 compose_set_title(compose);
7181 g_mutex_unlock(compose->mutex);
7184 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7186 Compose *compose = (Compose *)data;
7189 if (compose->redirect_filename != NULL)
7192 file_list = filesel_select_multiple_files_open(_("Select file"));
7197 for ( tmp = file_list; tmp; tmp = tmp->next) {
7198 gchar *file = (gchar *) tmp->data;
7199 gchar *utf8_filename = conv_filename_to_utf8(file);
7200 compose_attach_append(compose, file, utf8_filename, NULL);
7201 compose_changed_cb(NULL, compose);
7203 g_free(utf8_filename);
7205 g_list_free(file_list);
7209 static void compose_insert_file_cb(gpointer data, guint action,
7212 Compose *compose = (Compose *)data;
7215 file_list = filesel_select_multiple_files_open(_("Select file"));
7220 for ( tmp = file_list; tmp; tmp = tmp->next) {
7221 gchar *file = (gchar *) tmp->data;
7222 gchar *filedup = g_strdup(file);
7223 gchar *shortfile = g_path_get_basename(filedup);
7224 ComposeInsertResult res;
7226 res = compose_insert_file(compose, file);
7227 if (res == COMPOSE_INSERT_READ_ERROR) {
7228 alertpanel_error(_("File '%s' could not be read."), shortfile);
7229 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7230 alertpanel_error(_("File '%s' contained invalid characters\n"
7231 "for the current encoding, insertion may be incorrect."), shortfile);
7237 g_list_free(file_list);
7241 static void compose_insert_sig_cb(gpointer data, guint action,
7244 Compose *compose = (Compose *)data;
7246 compose_insert_sig(compose, FALSE);
7249 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7253 Compose *compose = (Compose *)data;
7255 gtkut_widget_get_uposition(widget, &x, &y);
7256 prefs_common.compose_x = x;
7257 prefs_common.compose_y = y;
7259 if (compose->sending)
7261 compose_close_cb(compose, 0, NULL);
7265 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7267 Compose *compose = (Compose *)data;
7271 if (compose->exteditor_tag != -1) {
7272 if (!compose_ext_editor_kill(compose))
7277 if (compose->modified) {
7278 val = alertpanel(_("Discard message"),
7279 _("This message has been modified. Discard it?"),
7280 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7283 case G_ALERTDEFAULT:
7284 if (prefs_common.autosave)
7285 compose_remove_draft(compose);
7287 case G_ALERTALTERNATE:
7288 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7295 compose_close(compose);
7298 static void compose_set_encoding_cb(gpointer data, guint action,
7301 Compose *compose = (Compose *)data;
7303 if (GTK_CHECK_MENU_ITEM(widget)->active)
7304 compose->out_encoding = (CharSet)action;
7307 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7309 Compose *compose = (Compose *)data;
7311 addressbook_open(compose);
7314 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7316 Compose *compose = (Compose *)data;
7321 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7322 g_return_if_fail(tmpl != NULL);
7324 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7326 val = alertpanel(_("Apply template"), msg,
7327 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7330 if (val == G_ALERTDEFAULT)
7331 compose_template_apply(compose, tmpl, TRUE);
7332 else if (val == G_ALERTALTERNATE)
7333 compose_template_apply(compose, tmpl, FALSE);
7336 static void compose_ext_editor_cb(gpointer data, guint action,
7339 Compose *compose = (Compose *)data;
7341 compose_exec_ext_editor(compose);
7344 static void compose_undo_cb(Compose *compose)
7346 gboolean prev_autowrap = compose->autowrap;
7348 compose->autowrap = FALSE;
7349 undo_undo(compose->undostruct);
7350 compose->autowrap = prev_autowrap;
7353 static void compose_redo_cb(Compose *compose)
7355 gboolean prev_autowrap = compose->autowrap;
7357 compose->autowrap = FALSE;
7358 undo_redo(compose->undostruct);
7359 compose->autowrap = prev_autowrap;
7362 static void entry_cut_clipboard(GtkWidget *entry)
7364 if (GTK_IS_EDITABLE(entry))
7365 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7366 else if (GTK_IS_TEXT_VIEW(entry))
7367 gtk_text_buffer_cut_clipboard(
7368 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7369 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7373 static void entry_copy_clipboard(GtkWidget *entry)
7375 if (GTK_IS_EDITABLE(entry))
7376 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7377 else if (GTK_IS_TEXT_VIEW(entry))
7378 gtk_text_buffer_copy_clipboard(
7379 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7380 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7383 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7384 gboolean wrap, GdkAtom clip)
7386 if (GTK_IS_TEXT_VIEW(entry)) {
7387 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7388 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7389 GtkTextIter start_iter, end_iter;
7392 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7394 if (contents == NULL)
7397 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7398 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7400 start = gtk_text_iter_get_offset(&start_iter);
7402 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7405 end = start + strlen(contents);
7406 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7407 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7408 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7409 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7410 mark_start = gtk_text_buffer_get_insert(buffer);
7411 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7412 gtk_text_iter_backward_char(&start_iter);
7413 compose_beautify_paragraph(compose, &start_iter, TRUE);
7416 } else if (GTK_IS_EDITABLE(entry))
7417 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7421 static void entry_allsel(GtkWidget *entry)
7423 if (GTK_IS_EDITABLE(entry))
7424 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7425 else if (GTK_IS_TEXT_VIEW(entry)) {
7426 GtkTextIter startiter, enditer;
7427 GtkTextBuffer *textbuf;
7429 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7430 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7431 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7433 gtk_text_buffer_move_mark_by_name(textbuf,
7434 "selection_bound", &startiter);
7435 gtk_text_buffer_move_mark_by_name(textbuf,
7436 "insert", &enditer);
7440 static void compose_cut_cb(Compose *compose)
7442 if (compose->focused_editable &&
7443 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7444 entry_cut_clipboard(compose->focused_editable);
7447 static void compose_copy_cb(Compose *compose)
7449 if (compose->focused_editable &&
7450 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7451 entry_copy_clipboard(compose->focused_editable);
7454 static void compose_paste_cb(Compose *compose)
7457 GtkTextBuffer *buffer;
7459 if (compose->focused_editable &&
7460 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7461 entry_paste_clipboard(compose, compose->focused_editable,
7462 prefs_common.linewrap_pastes,
7463 GDK_SELECTION_CLIPBOARD);
7467 static void compose_paste_as_quote_cb(Compose *compose)
7469 gint wrap_quote = prefs_common.linewrap_quote;
7470 if (compose->focused_editable &&
7471 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7472 /* let text_insert() (called directly or at a later time
7473 * after the gtk_editable_paste_clipboard) know that
7474 * text is to be inserted as a quotation. implemented
7475 * by using a simple refcount... */
7476 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7477 G_OBJECT(compose->focused_editable),
7478 "paste_as_quotation"));
7479 g_object_set_data(G_OBJECT(compose->focused_editable),
7480 "paste_as_quotation",
7481 GINT_TO_POINTER(paste_as_quotation + 1));
7482 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7483 entry_paste_clipboard(compose, compose->focused_editable,
7484 prefs_common.linewrap_pastes,
7485 GDK_SELECTION_CLIPBOARD);
7486 prefs_common.linewrap_quote = wrap_quote;
7490 static void compose_paste_no_wrap_cb(Compose *compose)
7493 GtkTextBuffer *buffer;
7495 if (compose->focused_editable &&
7496 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7497 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7498 GDK_SELECTION_CLIPBOARD);
7502 static void compose_paste_wrap_cb(Compose *compose)
7505 GtkTextBuffer *buffer;
7507 if (compose->focused_editable &&
7508 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7509 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7510 GDK_SELECTION_CLIPBOARD);
7514 static void compose_allsel_cb(Compose *compose)
7516 if (compose->focused_editable &&
7517 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7518 entry_allsel(compose->focused_editable);
7521 static void textview_move_beginning_of_line (GtkTextView *text)
7523 GtkTextBuffer *buffer;
7527 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7529 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7530 mark = gtk_text_buffer_get_insert(buffer);
7531 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7532 gtk_text_iter_set_line_offset(&ins, 0);
7533 gtk_text_buffer_place_cursor(buffer, &ins);
7536 static void textview_move_forward_character (GtkTextView *text)
7538 GtkTextBuffer *buffer;
7542 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7544 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7545 mark = gtk_text_buffer_get_insert(buffer);
7546 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7547 if (gtk_text_iter_forward_cursor_position(&ins))
7548 gtk_text_buffer_place_cursor(buffer, &ins);
7551 static void textview_move_backward_character (GtkTextView *text)
7553 GtkTextBuffer *buffer;
7557 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7559 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7560 mark = gtk_text_buffer_get_insert(buffer);
7561 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7562 if (gtk_text_iter_backward_cursor_position(&ins))
7563 gtk_text_buffer_place_cursor(buffer, &ins);
7566 static void textview_move_forward_word (GtkTextView *text)
7568 GtkTextBuffer *buffer;
7573 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7575 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7576 mark = gtk_text_buffer_get_insert(buffer);
7577 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7578 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7579 if (gtk_text_iter_forward_word_ends(&ins, count)) {
7580 gtk_text_iter_backward_word_start(&ins);
7581 gtk_text_buffer_place_cursor(buffer, &ins);
7585 static void textview_move_backward_word (GtkTextView *text)
7587 GtkTextBuffer *buffer;
7592 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7594 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7595 mark = gtk_text_buffer_get_insert(buffer);
7596 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7597 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7598 if (gtk_text_iter_backward_word_starts(&ins, 1))
7599 gtk_text_buffer_place_cursor(buffer, &ins);
7602 static void textview_move_end_of_line (GtkTextView *text)
7604 GtkTextBuffer *buffer;
7608 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7610 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7611 mark = gtk_text_buffer_get_insert(buffer);
7612 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7613 if (gtk_text_iter_forward_to_line_end(&ins))
7614 gtk_text_buffer_place_cursor(buffer, &ins);
7617 static void textview_move_next_line (GtkTextView *text)
7619 GtkTextBuffer *buffer;
7624 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7626 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7627 mark = gtk_text_buffer_get_insert(buffer);
7628 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7629 offset = gtk_text_iter_get_line_offset(&ins);
7630 if (gtk_text_iter_forward_line(&ins)) {
7631 gtk_text_iter_set_line_offset(&ins, offset);
7632 gtk_text_buffer_place_cursor(buffer, &ins);
7636 static void textview_move_previous_line (GtkTextView *text)
7638 GtkTextBuffer *buffer;
7643 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7645 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7646 mark = gtk_text_buffer_get_insert(buffer);
7647 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7648 offset = gtk_text_iter_get_line_offset(&ins);
7649 if (gtk_text_iter_backward_line(&ins)) {
7650 gtk_text_iter_set_line_offset(&ins, offset);
7651 gtk_text_buffer_place_cursor(buffer, &ins);
7655 static void textview_delete_forward_character (GtkTextView *text)
7657 GtkTextBuffer *buffer;
7659 GtkTextIter ins, end_iter;
7661 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7663 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7664 mark = gtk_text_buffer_get_insert(buffer);
7665 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7667 if (gtk_text_iter_forward_char(&end_iter)) {
7668 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7672 static void textview_delete_backward_character (GtkTextView *text)
7674 GtkTextBuffer *buffer;
7676 GtkTextIter ins, end_iter;
7678 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7680 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7681 mark = gtk_text_buffer_get_insert(buffer);
7682 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7684 if (gtk_text_iter_backward_char(&end_iter)) {
7685 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7689 static void textview_delete_forward_word (GtkTextView *text)
7691 GtkTextBuffer *buffer;
7693 GtkTextIter ins, end_iter;
7695 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7697 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7698 mark = gtk_text_buffer_get_insert(buffer);
7699 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7701 if (gtk_text_iter_forward_word_end(&end_iter)) {
7702 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7706 static void textview_delete_backward_word (GtkTextView *text)
7708 GtkTextBuffer *buffer;
7710 GtkTextIter ins, end_iter;
7712 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7714 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7715 mark = gtk_text_buffer_get_insert(buffer);
7716 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7718 if (gtk_text_iter_backward_word_start(&end_iter)) {
7719 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7723 static void textview_delete_line (GtkTextView *text)
7725 GtkTextBuffer *buffer;
7727 GtkTextIter ins, start_iter, end_iter;
7730 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7732 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7733 mark = gtk_text_buffer_get_insert(buffer);
7734 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7737 gtk_text_iter_set_line_offset(&start_iter, 0);
7740 if (gtk_text_iter_ends_line(&end_iter))
7741 found = gtk_text_iter_forward_char(&end_iter);
7743 found = gtk_text_iter_forward_to_line_end(&end_iter);
7746 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7749 static void textview_delete_to_line_end (GtkTextView *text)
7751 GtkTextBuffer *buffer;
7753 GtkTextIter ins, end_iter;
7756 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7758 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7759 mark = gtk_text_buffer_get_insert(buffer);
7760 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7762 if (gtk_text_iter_ends_line(&end_iter))
7763 found = gtk_text_iter_forward_char(&end_iter);
7765 found = gtk_text_iter_forward_to_line_end(&end_iter);
7767 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7770 static void compose_advanced_action_cb(Compose *compose,
7771 ComposeCallAdvancedAction action)
7773 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7775 void (*do_action) (GtkTextView *text);
7776 } action_table[] = {
7777 {textview_move_beginning_of_line},
7778 {textview_move_forward_character},
7779 {textview_move_backward_character},
7780 {textview_move_forward_word},
7781 {textview_move_backward_word},
7782 {textview_move_end_of_line},
7783 {textview_move_next_line},
7784 {textview_move_previous_line},
7785 {textview_delete_forward_character},
7786 {textview_delete_backward_character},
7787 {textview_delete_forward_word},
7788 {textview_delete_backward_word},
7789 {textview_delete_line},
7790 {NULL}, /* gtk_stext_delete_line_n */
7791 {textview_delete_to_line_end}
7794 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
7796 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
7797 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
7798 if (action_table[action].do_action)
7799 action_table[action].do_action(text);
7801 g_warning("Not implemented yet.");
7805 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
7809 if (GTK_IS_EDITABLE(widget)) {
7810 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
7811 gtk_editable_set_position(GTK_EDITABLE(widget),
7814 if (widget->parent && widget->parent->parent
7815 && widget->parent->parent->parent) {
7816 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
7817 gint y = widget->allocation.y;
7818 gint height = widget->allocation.height;
7819 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
7820 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
7822 if (y < (int)shown->value) {
7823 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
7825 if (y + height > (int)shown->value + (int)shown->page_size) {
7826 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
7827 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7828 y + height - (int)shown->page_size - 1);
7830 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7831 (int)shown->upper - (int)shown->page_size - 1);
7838 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
7839 compose->focused_editable = widget;
7842 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
7844 compose->modified = TRUE;
7845 compose_set_title(compose);
7848 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
7850 Compose *compose = (Compose *)data;
7853 compose_wrap_all_full(compose, TRUE);
7855 compose_beautify_paragraph(compose, NULL, TRUE);
7858 static void compose_toggle_autowrap_cb(gpointer data, guint action,
7861 Compose *compose = (Compose *)data;
7862 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7863 if (compose->autowrap)
7864 compose_wrap_all_full(compose, TRUE);
7865 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7868 static void compose_toggle_sign_cb(gpointer data, guint action,
7871 Compose *compose = (Compose *)data;
7873 if (GTK_CHECK_MENU_ITEM(widget)->active)
7874 compose->use_signing = TRUE;
7876 compose->use_signing = FALSE;
7879 static void compose_toggle_encrypt_cb(gpointer data, guint action,
7882 Compose *compose = (Compose *)data;
7884 if (GTK_CHECK_MENU_ITEM(widget)->active)
7885 compose->use_encryption = TRUE;
7887 compose->use_encryption = FALSE;
7890 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
7892 g_free(compose->privacy_system);
7894 compose->privacy_system = g_strdup(account->default_privacy_system);
7895 compose_update_privacy_system_menu_item(compose, warn);
7898 static void compose_toggle_ruler_cb(gpointer data, guint action,
7901 Compose *compose = (Compose *)data;
7903 if (GTK_CHECK_MENU_ITEM(widget)->active) {
7904 gtk_widget_show(compose->ruler_hbox);
7905 prefs_common.show_ruler = TRUE;
7907 gtk_widget_hide(compose->ruler_hbox);
7908 gtk_widget_queue_resize(compose->edit_vbox);
7909 prefs_common.show_ruler = FALSE;
7913 static void compose_attach_drag_received_cb (GtkWidget *widget,
7914 GdkDragContext *drag_context,
7917 GtkSelectionData *data,
7922 Compose *compose = (Compose *)user_data;
7925 if (gdk_atom_name(data->type) &&
7926 !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7927 list = uri_list_extract_filenames((const gchar *)data->data);
7928 for (tmp = list; tmp != NULL; tmp = tmp->next)
7929 compose_attach_append
7930 (compose, (const gchar *)tmp->data,
7931 (const gchar *)tmp->data, NULL);
7932 if (list) compose_changed_cb(NULL, compose);
7933 list_free_strings(list);
7935 } else if (gdk_atom_name(data->type) &&
7936 !strcmp(gdk_atom_name(data->type), "text/plain") &&
7937 data->data && !strcmp(data->data, "Dummy-Summaryview")) {
7938 /* comes from our summaryview */
7939 SummaryView * summaryview = NULL;
7940 GSList * list = NULL, *cur = NULL;
7942 if (mainwindow_get_mainwindow())
7943 summaryview = mainwindow_get_mainwindow()->summaryview;
7946 list = summary_get_selected_msg_list(summaryview);
7948 for (cur = list; cur; cur = cur->next) {
7949 MsgInfo *msginfo = (MsgInfo *)cur->data;
7952 file = procmsg_get_message_file_full(msginfo,
7955 compose_attach_append(compose, (const gchar *)file,
7956 (const gchar *)file, "message/rfc822");
7964 static gboolean compose_drag_drop(GtkWidget *widget,
7965 GdkDragContext *drag_context,
7967 guint time, gpointer user_data)
7969 /* not handling this signal makes compose_insert_drag_received_cb
7974 static void compose_insert_drag_received_cb (GtkWidget *widget,
7975 GdkDragContext *drag_context,
7978 GtkSelectionData *data,
7983 Compose *compose = (Compose *)user_data;
7986 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
7988 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7989 list = uri_list_extract_filenames((const gchar *)data->data);
7990 for (tmp = list; tmp != NULL; tmp = tmp->next) {
7991 compose_insert_file(compose, (const gchar *)tmp->data);
7993 list_free_strings(list);
7995 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7998 #if GTK_CHECK_VERSION(2, 8, 0)
7999 /* do nothing, handled by GTK */
8001 gchar *tmpfile = get_tmp_file();
8002 str_write_to_file((const gchar *)data->data, tmpfile);
8003 compose_insert_file(compose, tmpfile);
8006 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8010 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8013 static void compose_header_drag_received_cb (GtkWidget *widget,
8014 GdkDragContext *drag_context,
8017 GtkSelectionData *data,
8022 GtkEditable *entry = (GtkEditable *)user_data;
8023 gchar *email = (gchar *)data->data;
8025 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8028 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8029 gchar *decoded=g_new(gchar, strlen(email));
8032 email += strlen("mailto:");
8033 decode_uri(decoded, email); /* will fit */
8034 gtk_editable_delete_text(entry, 0, -1);
8035 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8036 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8040 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8043 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8046 Compose *compose = (Compose *)data;
8048 if (GTK_CHECK_MENU_ITEM(widget)->active)
8049 compose->return_receipt = TRUE;
8051 compose->return_receipt = FALSE;
8054 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8057 Compose *compose = (Compose *)data;
8059 if (GTK_CHECK_MENU_ITEM(widget)->active)
8060 compose->remove_references = TRUE;
8062 compose->remove_references = FALSE;
8065 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8067 ComposeHeaderEntry *headerentry)
8069 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
8070 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
8071 !(event->state & GDK_MODIFIER_MASK) &&
8072 (event->keyval == GDK_BackSpace) &&
8073 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
8074 gtk_container_remove
8075 (GTK_CONTAINER(headerentry->compose->header_table),
8076 headerentry->combo);
8077 gtk_container_remove
8078 (GTK_CONTAINER(headerentry->compose->header_table),
8079 headerentry->entry);
8080 headerentry->compose->header_list =
8081 g_slist_remove(headerentry->compose->header_list,
8083 g_free(headerentry);
8084 } else if (event->keyval == GDK_Tab) {
8085 if (headerentry->compose->header_last == headerentry) {
8086 /* Override default next focus, and give it to subject_entry
8087 * instead of notebook tabs
8089 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8090 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8097 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8098 ComposeHeaderEntry *headerentry)
8100 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8101 headerentry->compose->header_list =
8102 g_slist_append(headerentry->compose->header_list,
8105 compose_create_header_entry(headerentry->compose);
8106 g_signal_handlers_disconnect_matched
8107 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8108 0, 0, NULL, NULL, headerentry);
8110 /* Automatically scroll down */
8111 compose_show_first_last_header(headerentry->compose, FALSE);
8117 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8119 GtkAdjustment *vadj;
8121 g_return_if_fail(compose);
8122 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8123 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8125 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8126 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8129 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8130 const gchar *text, gint len, Compose *compose)
8132 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8133 (G_OBJECT(compose->text), "paste_as_quotation"));
8136 g_return_if_fail(text != NULL);
8138 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8139 G_CALLBACK(text_inserted),
8141 if (paste_as_quotation) {
8148 new_text = g_strndup(text, len);
8149 if (prefs_common.quotemark && *prefs_common.quotemark)
8150 qmark = prefs_common.quotemark;
8154 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8155 gtk_text_buffer_place_cursor(buffer, iter);
8157 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8159 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8160 GINT_TO_POINTER(paste_as_quotation - 1));
8162 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8163 gtk_text_buffer_place_cursor(buffer, iter);
8165 if (strcmp(text, "\n") || automatic_break
8166 || gtk_text_iter_starts_line(iter))
8167 gtk_text_buffer_insert(buffer, iter, text, len);
8169 debug_print("insert nowrap \\n\n");
8170 gtk_text_buffer_insert_with_tags_by_name(buffer,
8171 iter, text, len, "no_join", NULL);
8175 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8177 compose_beautify_paragraph(compose, iter, FALSE);
8179 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8180 gtk_text_buffer_delete_mark(buffer, mark);
8182 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8183 G_CALLBACK(text_inserted),
8185 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8187 if (prefs_common.autosave &&
8188 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8189 compose->draft_timeout_tag = gtk_timeout_add
8190 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8192 static gint compose_defer_auto_save_draft(Compose *compose)
8194 compose->draft_timeout_tag = -1;
8195 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8200 static void compose_check_all(Compose *compose)
8202 if (compose->gtkaspell)
8203 gtkaspell_check_all(compose->gtkaspell);
8206 static void compose_highlight_all(Compose *compose)
8208 if (compose->gtkaspell)
8209 gtkaspell_highlight_all(compose->gtkaspell);
8212 static void compose_check_backwards(Compose *compose)
8214 if (compose->gtkaspell)
8215 gtkaspell_check_backwards(compose->gtkaspell);
8217 GtkItemFactory *ifactory;
8218 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8219 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8220 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8224 static void compose_check_forwards_go(Compose *compose)
8226 if (compose->gtkaspell)
8227 gtkaspell_check_forwards_go(compose->gtkaspell);
8229 GtkItemFactory *ifactory;
8230 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8231 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8232 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8238 *\brief Guess originating forward account from MsgInfo and several
8239 * "common preference" settings. Return NULL if no guess.
8241 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8243 PrefsAccount *account = NULL;
8245 g_return_val_if_fail(msginfo, NULL);
8246 g_return_val_if_fail(msginfo->folder, NULL);
8247 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8249 if (msginfo->folder->prefs->enable_default_account)
8250 account = account_find_from_id(msginfo->folder->prefs->default_account);
8253 account = msginfo->folder->folder->account;
8255 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8257 Xstrdup_a(to, msginfo->to, return NULL);
8258 extract_address(to);
8259 account = account_find_from_address(to);
8262 if (!account && prefs_common.forward_account_autosel) {
8264 if (!procheader_get_header_from_msginfo
8265 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8266 extract_address(cc);
8267 account = account_find_from_address(cc);
8274 static gboolean compose_close(Compose *compose)
8278 if (!g_mutex_trylock(compose->mutex)) {
8279 /* we have to wait for the (possibly deferred by auto-save)
8280 * drafting to be done, before destroying the compose under
8282 debug_print("waiting for drafting to finish...\n");
8283 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8286 g_return_val_if_fail(compose, FALSE);
8287 gtkut_widget_get_uposition(compose->window, &x, &y);
8288 prefs_common.compose_x = x;
8289 prefs_common.compose_y = y;
8290 g_mutex_unlock(compose->mutex);
8291 compose_destroy(compose);
8296 * Add entry field for each address in list.
8297 * \param compose E-Mail composition object.
8298 * \param listAddress List of (formatted) E-Mail addresses.
8300 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8305 addr = ( gchar * ) node->data;
8306 compose_entry_append( compose, addr, COMPOSE_TO );
8307 node = g_list_next( node );
8311 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8315 GSList *new_msglist = NULL;
8316 MsgInfo *tmp_msginfo = NULL;
8317 gboolean originally_enc = FALSE;
8318 Compose *compose = NULL;
8320 g_return_if_fail(msgview != NULL);
8322 g_return_if_fail(msginfo_list != NULL);
8324 if (g_slist_length(msginfo_list) == 1) {
8325 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8326 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8328 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8329 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8330 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8331 orig_msginfo, mimeinfo);
8332 if (tmp_msginfo != NULL) {
8333 new_msglist = g_slist_append(NULL, tmp_msginfo);
8334 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8335 originally_enc = TRUE;
8341 body = messageview_get_selection(msgview);
8344 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8345 procmsg_msginfo_free(tmp_msginfo);
8346 g_slist_free(new_msglist);
8348 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8350 if (originally_enc) {
8351 compose_force_encryption(compose, compose->account, FALSE);