2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2005 Hiroyuki Yamamoto
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>
77 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
84 #include "mainwindow.h"
86 #include "addressbook.h"
87 #include "folderview.h"
90 #include "stock_pixmap.h"
91 #include "send_message.h"
94 #include "customheader.h"
95 #include "prefs_common.h"
96 #include "prefs_account.h"
100 #include "procheader.h"
101 #include "procmime.h"
102 #include "statusbar.h"
105 #include "quoted-printable.h"
106 #include "codeconv.h"
108 #include "gtkutils.h"
110 #include "alertpanel.h"
111 #include "manage_window.h"
112 #include "gtkshruler.h"
114 #include "addr_compl.h"
115 #include "quote_fmt.h"
116 #include "template.h"
118 #include "foldersel.h"
131 #define N_ATTACH_COLS (N_COL_COLUMNS)
135 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
136 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
137 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
138 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
143 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
144 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
145 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
146 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
150 } ComposeCallAdvancedAction;
154 PRIORITY_HIGHEST = 1,
163 COMPOSE_INSERT_SUCCESS,
164 COMPOSE_INSERT_READ_ERROR,
165 COMPOSE_INSERT_INVALID_CHARACTER,
166 COMPOSE_INSERT_NO_FILE
167 } ComposeInsertResult;
171 COMPOSE_QUIT_EDITING,
172 COMPOSE_KEEP_EDITING,
174 } ComposeDraftAction;
178 COMPOSE_WRITE_FOR_SEND,
179 COMPOSE_WRITE_FOR_STORE
182 #define B64_LINE_SIZE 57
183 #define B64_BUFFSIZE 77
185 #define MAX_REFERENCES_LEN 999
187 static GList *compose_list = NULL;
189 Compose *compose_generic_new (PrefsAccount *account,
192 GPtrArray *attach_files,
193 GList *listAddress );
195 static Compose *compose_create (PrefsAccount *account,
198 static GtkWidget *compose_account_option_menu_create
200 static void compose_set_out_encoding (Compose *compose);
201 static void compose_set_template_menu (Compose *compose);
202 static void compose_template_apply (Compose *compose,
205 static void compose_destroy (Compose *compose);
207 static void compose_entries_set (Compose *compose,
208 const gchar *mailto);
209 static gint compose_parse_header (Compose *compose,
211 static gchar *compose_parse_references (const gchar *ref,
214 static gchar *compose_quote_fmt (Compose *compose,
221 static void compose_reply_set_entry (Compose *compose,
227 followup_and_reply_to);
228 static void compose_reedit_set_entry (Compose *compose,
231 static void compose_insert_sig (Compose *compose,
233 static gchar *compose_get_signature_str (Compose *compose);
234 static ComposeInsertResult compose_insert_file (Compose *compose,
237 static void compose_attach_append (Compose *compose,
240 const gchar *content_type);
241 static void compose_attach_parts (Compose *compose,
244 static void compose_beautify_paragraph (Compose *compose,
245 GtkTextIter *par_iter,
247 static void compose_wrap_all (Compose *compose);
248 static void compose_wrap_all_full (Compose *compose,
251 static void compose_set_title (Compose *compose);
252 static void compose_select_account (Compose *compose,
253 PrefsAccount *account,
256 static PrefsAccount *compose_current_mail_account(void);
257 /* static gint compose_send (Compose *compose); */
258 static gboolean compose_check_for_valid_recipient
260 static gboolean compose_check_entries (Compose *compose,
261 gboolean check_subject);
262 static gint compose_write_to_file (Compose *compose,
265 static gint compose_write_body_to_file (Compose *compose,
267 static gint compose_remove_reedit_target (Compose *compose);
268 void compose_remove_draft (Compose *compose);
269 static gint compose_queue (Compose *compose,
272 static gint compose_queue_sub (Compose *compose,
275 gboolean check_subject);
276 static void compose_add_attachments (Compose *compose,
278 static gchar *compose_get_header (Compose *compose);
280 static void compose_convert_header (Compose *compose,
285 gboolean addr_field);
287 static void compose_attach_info_free (AttachInfo *ainfo);
288 static void compose_attach_remove_selected (Compose *compose);
290 static void compose_attach_property (Compose *compose);
291 static void compose_attach_property_create (gboolean *cancelled);
292 static void attach_property_ok (GtkWidget *widget,
293 gboolean *cancelled);
294 static void attach_property_cancel (GtkWidget *widget,
295 gboolean *cancelled);
296 static gint attach_property_delete_event (GtkWidget *widget,
298 gboolean *cancelled);
299 static gboolean attach_property_key_pressed (GtkWidget *widget,
301 gboolean *cancelled);
303 static void compose_exec_ext_editor (Compose *compose);
305 static gint compose_exec_ext_editor_real (const gchar *file);
306 static gboolean compose_ext_editor_kill (Compose *compose);
307 static gboolean compose_input_cb (GIOChannel *source,
308 GIOCondition condition,
310 static void compose_set_ext_editor_sensitive (Compose *compose,
312 #endif /* G_OS_UNIX */
314 static void compose_undo_state_changed (UndoMain *undostruct,
319 static void compose_create_header_entry (Compose *compose);
320 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
321 static void compose_update_priority_menu_item(Compose * compose);
323 static void compose_add_field_list ( Compose *compose,
324 GList *listAddress );
326 /* callback functions */
328 static gboolean compose_edit_size_alloc (GtkEditable *widget,
329 GtkAllocation *allocation,
330 GtkSHRuler *shruler);
331 static void account_activated (GtkMenuItem *menuitem,
333 static void attach_selected (GtkTreeView *tree_view,
334 GtkTreePath *tree_path,
335 GtkTreeViewColumn *column,
337 static gboolean attach_button_pressed (GtkWidget *widget,
338 GdkEventButton *event,
340 static gboolean attach_key_pressed (GtkWidget *widget,
344 static void compose_send_cb (gpointer data,
347 static void compose_send_later_cb (gpointer data,
351 static void compose_draft_cb (gpointer data,
355 static void compose_attach_cb (gpointer data,
358 static void compose_insert_file_cb (gpointer data,
361 static void compose_insert_sig_cb (gpointer data,
365 static void compose_close_cb (gpointer data,
369 static void compose_set_encoding_cb (gpointer data,
373 static void compose_address_cb (gpointer data,
376 static void compose_template_activate_cb(GtkWidget *widget,
379 static void compose_ext_editor_cb (gpointer data,
383 static gint compose_delete_cb (GtkWidget *widget,
387 static void compose_undo_cb (Compose *compose);
388 static void compose_redo_cb (Compose *compose);
389 static void compose_cut_cb (Compose *compose);
390 static void compose_copy_cb (Compose *compose);
391 static void compose_paste_cb (Compose *compose);
392 static void compose_paste_as_quote_cb (Compose *compose);
393 static void compose_paste_no_wrap_cb (Compose *compose);
394 static void compose_paste_wrap_cb (Compose *compose);
395 static void compose_allsel_cb (Compose *compose);
397 static void compose_advanced_action_cb (Compose *compose,
398 ComposeCallAdvancedAction action);
400 static void compose_grab_focus_cb (GtkWidget *widget,
403 static void compose_changed_cb (GtkTextBuffer *textbuf,
406 static void compose_wrap_cb (gpointer data,
409 static void compose_toggle_autowrap_cb (gpointer data,
413 static void compose_toggle_ruler_cb (gpointer data,
416 static void compose_toggle_sign_cb (gpointer data,
419 static void compose_toggle_encrypt_cb (gpointer data,
422 static void compose_set_privacy_system_cb(GtkWidget *widget,
424 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
425 static void activate_privacy_system (Compose *compose,
426 PrefsAccount *account,
428 static void compose_use_signing(Compose *compose, gboolean use_signing);
429 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
430 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
432 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
434 static void compose_set_priority_cb (gpointer data,
438 static void compose_attach_drag_received_cb (GtkWidget *widget,
439 GdkDragContext *drag_context,
442 GtkSelectionData *data,
446 static void compose_insert_drag_received_cb (GtkWidget *widget,
447 GdkDragContext *drag_context,
450 GtkSelectionData *data,
454 static void compose_header_drag_received_cb (GtkWidget *widget,
455 GdkDragContext *drag_context,
458 GtkSelectionData *data,
463 static gboolean compose_drag_drop (GtkWidget *widget,
464 GdkDragContext *drag_context,
466 guint time, gpointer user_data);
468 static void text_inserted (GtkTextBuffer *buffer,
473 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
474 gboolean to_all, gboolean to_ml,
476 gboolean followup_and_reply_to,
479 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
480 ComposeHeaderEntry *headerentry);
481 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
483 ComposeHeaderEntry *headerentry);
485 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
487 static void compose_allow_user_actions (Compose *compose, gboolean allow);
490 static void compose_check_all (Compose *compose);
491 static void compose_highlight_all (Compose *compose);
492 static void compose_check_backwards (Compose *compose);
493 static void compose_check_forwards_go (Compose *compose);
496 static gint compose_defer_auto_save_draft (Compose *compose);
497 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
499 static gboolean compose_close (Compose *compose);
501 static GtkItemFactoryEntry compose_popup_entries[] =
503 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
504 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
505 {N_("/---"), NULL, NULL, 0, "<Separator>"},
506 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
509 static GtkItemFactoryEntry compose_entries[] =
511 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
512 {N_("/_Message/_Send"), "<control>Return",
513 compose_send_cb, 0, NULL},
514 {N_("/_Message/Send _later"), "<shift><control>S",
515 compose_send_later_cb, 0, NULL},
516 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
517 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
518 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
519 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
520 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
521 {N_("/_Message/_Save"),
522 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
523 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
524 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
526 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
527 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
528 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
529 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
530 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
531 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
532 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
533 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
534 {N_("/_Edit/Special paste/as _quotation"),
535 NULL, compose_paste_as_quote_cb, 0, NULL},
536 {N_("/_Edit/Special paste/_wrapped"),
537 NULL, compose_paste_wrap_cb, 0, NULL},
538 {N_("/_Edit/Special paste/_unwrapped"),
539 NULL, compose_paste_no_wrap_cb, 0, NULL},
540 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
541 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
542 {N_("/_Edit/A_dvanced/Move a character backward"),
544 compose_advanced_action_cb,
545 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
547 {N_("/_Edit/A_dvanced/Move a character forward"),
549 compose_advanced_action_cb,
550 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
552 {N_("/_Edit/A_dvanced/Move a word backward"),
554 compose_advanced_action_cb,
555 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
557 {N_("/_Edit/A_dvanced/Move a word forward"),
559 compose_advanced_action_cb,
560 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
562 {N_("/_Edit/A_dvanced/Move to beginning of line"),
563 NULL, /* "<control>A" */
564 compose_advanced_action_cb,
565 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
567 {N_("/_Edit/A_dvanced/Move to end of line"),
569 compose_advanced_action_cb,
570 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
572 {N_("/_Edit/A_dvanced/Move to previous line"),
574 compose_advanced_action_cb,
575 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
577 {N_("/_Edit/A_dvanced/Move to next line"),
579 compose_advanced_action_cb,
580 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
582 {N_("/_Edit/A_dvanced/Delete a character backward"),
584 compose_advanced_action_cb,
585 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
587 {N_("/_Edit/A_dvanced/Delete a character forward"),
589 compose_advanced_action_cb,
590 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
592 {N_("/_Edit/A_dvanced/Delete a word backward"),
593 NULL, /* "<control>W" */
594 compose_advanced_action_cb,
595 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
597 {N_("/_Edit/A_dvanced/Delete a word forward"),
598 NULL, /* "<alt>D", */
599 compose_advanced_action_cb,
600 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
602 {N_("/_Edit/A_dvanced/Delete line"),
604 compose_advanced_action_cb,
605 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
607 {N_("/_Edit/A_dvanced/Delete entire line"),
609 compose_advanced_action_cb,
610 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
612 {N_("/_Edit/A_dvanced/Delete to end of line"),
614 compose_advanced_action_cb,
615 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
617 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
618 {N_("/_Edit/_Wrap current paragraph"),
619 "<control>L", compose_wrap_cb, 0, NULL},
620 {N_("/_Edit/Wrap all long _lines"),
621 "<control><alt>L", compose_wrap_cb, 1, NULL},
622 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
623 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
624 {N_("/_Edit/Edit with e_xternal editor"),
625 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
627 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
628 {N_("/_Spelling/_Check all or check selection"),
629 NULL, compose_check_all, 0, NULL},
630 {N_("/_Spelling/_Highlight all misspelled words"),
631 NULL, compose_highlight_all, 0, NULL},
632 {N_("/_Spelling/Check _backwards misspelled word"),
633 NULL, compose_check_backwards , 0, NULL},
634 {N_("/_Spelling/_Forward to next misspelled word"),
635 NULL, compose_check_forwards_go, 0, NULL},
637 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
638 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
639 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
640 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
641 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
642 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
643 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
644 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
645 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
646 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
647 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
648 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
649 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
650 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
651 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
652 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
653 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
655 #define ENC_ACTION(action) \
656 NULL, compose_set_encoding_cb, action, \
657 "/Options/Character encoding/Automatic"
659 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
660 {N_("/_Options/Character _encoding/_Automatic"),
661 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
662 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
664 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
665 ENC_ACTION(C_US_ASCII)},
666 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
667 ENC_ACTION(C_UTF_8)},
668 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
670 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
671 ENC_ACTION(C_ISO_8859_1)},
672 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
673 ENC_ACTION(C_ISO_8859_15)},
674 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
675 ENC_ACTION(C_WINDOWS_1252)},
676 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
678 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
679 ENC_ACTION(C_ISO_8859_2)},
680 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
682 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
683 ENC_ACTION(C_ISO_8859_13)},
684 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
685 ENC_ACTION(C_ISO_8859_4)},
686 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
688 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
689 ENC_ACTION(C_ISO_8859_7)},
690 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
692 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
693 ENC_ACTION(C_ISO_8859_8)},
694 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
695 ENC_ACTION(C_WINDOWS_1255)},
696 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
698 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
699 ENC_ACTION(C_ISO_8859_9)},
700 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
702 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
703 ENC_ACTION(C_ISO_8859_5)},
704 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
705 ENC_ACTION(C_KOI8_R)},
706 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
707 ENC_ACTION(C_KOI8_U)},
708 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
709 ENC_ACTION(C_WINDOWS_1251)},
710 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
712 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
713 ENC_ACTION(C_ISO_2022_JP)},
714 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
716 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
717 ENC_ACTION(C_GB2312)},
718 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
720 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
722 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
723 ENC_ACTION(C_EUC_TW)},
724 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
726 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
727 ENC_ACTION(C_EUC_KR)},
728 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
730 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
731 ENC_ACTION(C_TIS_620)},
732 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
733 ENC_ACTION(C_WINDOWS_874)},
735 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
736 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
737 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
738 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
739 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
740 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
741 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
744 static GtkTargetEntry compose_mime_types[] =
746 {"text/uri-list", 0, 0},
747 {"text/plain", 0, 0},
751 static gboolean compose_put_existing_to_front(MsgInfo *info)
753 GList *compose_list = compose_get_compose_list();
757 for (elem = compose_list; elem != NULL && elem->data != NULL;
759 Compose *c = (Compose*)elem->data;
761 if (!c->targetinfo || !c->targetinfo->msgid ||
765 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
766 gtkut_window_popup(c->window);
774 static GdkColor quote_color =
775 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
777 static GdkColor signature_color = {
784 static GdkColor uri_color = {
791 static void compose_create_tags(GtkTextView *text, Compose *compose)
793 GtkTextBuffer *buffer;
794 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
796 buffer = gtk_text_view_get_buffer(text);
798 if (prefs_common.enable_color) {
799 /* grab the quote colors, converting from an int to a GdkColor */
800 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
802 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
804 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
807 signature_color = quote_color = uri_color = black;
810 gtk_text_buffer_create_tag(buffer, "quote",
811 "foreground-gdk", "e_color,
813 gtk_text_buffer_create_tag(buffer, "signature",
814 "foreground-gdk", &signature_color,
816 gtk_text_buffer_create_tag(buffer, "link",
817 "foreground-gdk", &uri_color,
819 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
822 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
823 GPtrArray *attach_files)
825 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
828 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
830 return compose_generic_new(account, NULL, item, NULL, NULL);
833 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
835 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
838 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
839 GPtrArray *attach_files, GList *listAddress )
842 GtkTextView *textview;
843 GtkTextBuffer *textbuf;
845 GtkItemFactory *ifactory;
847 if (item && item->prefs && item->prefs->enable_default_account)
848 account = account_find_from_id(item->prefs->default_account);
850 if (!account) account = cur_account;
851 g_return_val_if_fail(account != NULL, NULL);
853 compose = compose_create(account, COMPOSE_NEW);
854 ifactory = gtk_item_factory_from_widget(compose->menubar);
856 compose->replyinfo = NULL;
857 compose->fwdinfo = NULL;
859 textview = GTK_TEXT_VIEW(compose->text);
860 textbuf = gtk_text_view_get_buffer(textview);
861 compose_create_tags(textview, compose);
863 undo_block(compose->undostruct);
865 if (item && item->prefs && item->prefs->enable_default_dictionary &&
867 gtkaspell_change_dict(compose->gtkaspell,
868 item->prefs->default_dictionary);
871 if (account->auto_sig)
872 compose_insert_sig(compose, FALSE);
873 gtk_text_buffer_get_start_iter(textbuf, &iter);
874 gtk_text_buffer_place_cursor(textbuf, &iter);
876 if (account->protocol != A_NNTP) {
877 if (mailto && *mailto != '\0') {
878 compose_entries_set(compose, mailto);
880 } else if (item && item->prefs->enable_default_to) {
881 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
882 compose_entry_mark_default_to(compose, item->prefs->default_to);
884 if (item && item->ret_rcpt) {
885 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
889 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
891 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
894 * CLAWS: just don't allow return receipt request, even if the user
895 * may want to send an email. simple but foolproof.
897 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
899 compose_add_field_list( compose, listAddress );
905 for (i = 0; i < attach_files->len; i++) {
906 file = g_ptr_array_index(attach_files, i);
907 compose_attach_append(compose, file, file, NULL);
911 compose_show_first_last_header(compose, TRUE);
913 /* Set save folder */
914 if (item && item->prefs && item->prefs->save_copy_to_folder) {
915 gchar *folderidentifier;
917 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
918 folderidentifier = folder_item_get_identifier(item);
919 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
920 g_free(folderidentifier);
923 gtk_widget_grab_focus(compose->header_last->entry);
925 undo_unblock(compose->undostruct);
927 if (prefs_common.auto_exteditor)
928 compose_exec_ext_editor(compose);
930 compose->modified = FALSE;
931 compose_set_title(compose);
935 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
936 gboolean override_pref)
938 gchar *privacy = NULL;
940 g_return_if_fail(compose != NULL);
941 g_return_if_fail(account != NULL);
943 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
946 if (account->default_privacy_system
947 && strlen(account->default_privacy_system)) {
948 privacy = account->default_privacy_system;
950 GSList *privacy_avail = privacy_get_system_ids();
951 if (privacy_avail && g_slist_length(privacy_avail)) {
952 privacy = (gchar *)(privacy_avail->data);
955 if (privacy != NULL) {
956 compose->privacy_system = g_strdup(privacy);
957 compose_update_privacy_system_menu_item(compose, FALSE);
958 compose_use_encryption(compose, TRUE);
962 static void compose_force_signing(Compose *compose, PrefsAccount *account)
964 gchar *privacy = NULL;
966 if (account->default_privacy_system
967 && strlen(account->default_privacy_system)) {
968 privacy = account->default_privacy_system;
970 GSList *privacy_avail = privacy_get_system_ids();
971 if (privacy_avail && g_slist_length(privacy_avail)) {
972 privacy = (gchar *)(privacy_avail->data);
975 if (privacy != NULL) {
976 compose->privacy_system = g_strdup(privacy);
977 compose_update_privacy_system_menu_item(compose, FALSE);
978 compose_use_signing(compose, TRUE);
982 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
986 Compose *compose = NULL;
987 g_return_val_if_fail(msginfo_list != NULL, NULL);
989 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
990 g_return_val_if_fail(msginfo != NULL, NULL);
992 list_len = g_slist_length(msginfo_list);
996 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
997 FALSE, prefs_common.default_reply_list, FALSE, body);
999 case COMPOSE_REPLY_WITH_QUOTE:
1000 compose = compose_reply(msginfo, TRUE,
1001 FALSE, prefs_common.default_reply_list, FALSE, body);
1003 case COMPOSE_REPLY_WITHOUT_QUOTE:
1004 compose = compose_reply(msginfo, FALSE,
1005 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1007 case COMPOSE_REPLY_TO_SENDER:
1008 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1009 FALSE, FALSE, TRUE, body);
1011 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1012 compose = compose_followup_and_reply_to(msginfo,
1013 prefs_common.reply_with_quote,
1014 FALSE, FALSE, body);
1016 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1017 compose = compose_reply(msginfo, TRUE,
1018 FALSE, FALSE, TRUE, body);
1020 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1021 compose = compose_reply(msginfo, FALSE,
1022 FALSE, FALSE, TRUE, NULL);
1024 case COMPOSE_REPLY_TO_ALL:
1025 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1026 TRUE, FALSE, FALSE, body);
1028 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1029 compose = compose_reply(msginfo, TRUE,
1030 TRUE, FALSE, FALSE, body);
1032 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1033 compose = compose_reply(msginfo, FALSE,
1034 TRUE, FALSE, FALSE, NULL);
1036 case COMPOSE_REPLY_TO_LIST:
1037 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1038 FALSE, TRUE, FALSE, body);
1040 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1041 compose = compose_reply(msginfo, TRUE,
1042 FALSE, TRUE, FALSE, body);
1044 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1045 compose = compose_reply(msginfo, FALSE,
1046 FALSE, TRUE, FALSE, NULL);
1048 case COMPOSE_FORWARD:
1049 if (prefs_common.forward_as_attachment) {
1050 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1053 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1057 case COMPOSE_FORWARD_INLINE:
1058 /* check if we reply to more than one Message */
1059 if (list_len == 1) {
1060 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE);
1063 /* more messages FALL THROUGH */
1064 case COMPOSE_FORWARD_AS_ATTACH:
1065 compose = compose_forward_multiple(NULL, msginfo_list);
1067 case COMPOSE_REDIRECT:
1068 compose = compose_redirect(NULL, msginfo);
1071 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1076 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1077 gboolean to_ml, gboolean to_sender,
1080 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1081 to_sender, FALSE, body);
1084 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1089 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1090 to_sender, TRUE, body);
1093 static void compose_extract_original_charset(Compose *compose)
1095 MsgInfo *info = NULL;
1096 if (compose->replyinfo) {
1097 info = compose->replyinfo;
1098 } else if (compose->fwdinfo) {
1099 info = compose->fwdinfo;
1100 } else if (compose->targetinfo) {
1101 info = compose->targetinfo;
1104 MimeInfo *mimeinfo = procmime_scan_message(info);
1105 MimeInfo *partinfo = mimeinfo;
1106 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1107 partinfo = procmime_mimeinfo_next(partinfo);
1109 compose->orig_charset =
1110 g_strdup(procmime_mimeinfo_get_parameter(
1111 partinfo, "charset"));
1113 procmime_mimeinfo_free_all(mimeinfo);
1117 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1118 gboolean to_all, gboolean to_ml,
1120 gboolean followup_and_reply_to,
1123 GtkItemFactory *ifactory;
1125 PrefsAccount *account = NULL;
1126 PrefsAccount *reply_account;
1127 GtkTextView *textview;
1128 GtkTextBuffer *textbuf;
1130 g_return_val_if_fail(msginfo != NULL, NULL);
1131 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1133 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1135 g_return_val_if_fail(account != NULL, NULL);
1137 if (to_sender && account->protocol == A_NNTP &&
1138 !followup_and_reply_to) {
1140 account_find_from_address(account->address);
1142 reply_account = compose_current_mail_account();
1146 reply_account = account;
1148 compose = compose_create(account, COMPOSE_REPLY);
1149 ifactory = gtk_item_factory_from_widget(compose->menubar);
1151 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1152 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1154 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1156 if (!compose->replyinfo)
1157 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1159 compose_extract_original_charset(compose);
1161 if (msginfo->folder && msginfo->folder->ret_rcpt)
1162 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1164 /* Set save folder */
1165 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1166 gchar *folderidentifier;
1168 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1169 folderidentifier = folder_item_get_identifier(msginfo->folder);
1170 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1171 g_free(folderidentifier);
1174 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1175 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1176 to_sender, followup_and_reply_to);
1177 compose_show_first_last_header(compose, TRUE);
1179 textview = (GTK_TEXT_VIEW(compose->text));
1180 textbuf = gtk_text_view_get_buffer(textview);
1181 compose_create_tags(textview, compose);
1183 undo_block(compose->undostruct);
1185 if (msginfo->folder && msginfo->folder->prefs &&
1186 msginfo->folder->prefs &&
1187 msginfo->folder->prefs->enable_default_dictionary &&
1189 gtkaspell_change_dict(compose->gtkaspell,
1190 msginfo->folder->prefs->default_dictionary);
1196 if (prefs_common.quotemark && *prefs_common.quotemark)
1197 qmark = prefs_common.quotemark;
1201 compose_quote_fmt(compose, compose->replyinfo,
1202 prefs_common.quotefmt,
1203 qmark, body, FALSE);
1205 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1206 compose_force_encryption(compose, account, FALSE);
1209 if (account->auto_sig)
1210 compose_insert_sig(compose, FALSE);
1212 compose_wrap_all(compose);
1214 gtk_widget_grab_focus(compose->text);
1216 undo_unblock(compose->undostruct);
1218 if (prefs_common.auto_exteditor)
1219 compose_exec_ext_editor(compose);
1221 compose->modified = FALSE;
1222 compose_set_title(compose);
1226 #define INSERT_FW_HEADER(var, hdr) \
1227 if (msginfo->var && *msginfo->var) { \
1228 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1229 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1230 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1233 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1234 gboolean as_attach, const gchar *body,
1235 gboolean no_extedit)
1238 GtkTextView *textview;
1239 GtkTextBuffer *textbuf;
1242 g_return_val_if_fail(msginfo != NULL, NULL);
1243 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1246 !(account = compose_guess_forward_account_from_msginfo
1248 account = cur_account;
1250 compose = compose_create(account, COMPOSE_FORWARD);
1252 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1253 if (!compose->fwdinfo)
1254 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1256 compose_extract_original_charset(compose);
1258 if (msginfo->subject && *msginfo->subject) {
1259 gchar *buf, *buf2, *p;
1261 buf = p = g_strdup(msginfo->subject);
1262 p += subject_get_prefix_length(p);
1263 memmove(buf, p, strlen(p) + 1);
1265 buf2 = g_strdup_printf("Fw: %s", buf);
1266 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1272 textview = GTK_TEXT_VIEW(compose->text);
1273 textbuf = gtk_text_view_get_buffer(textview);
1274 compose_create_tags(textview, compose);
1276 undo_block(compose->undostruct);
1280 msgfile = procmsg_get_message_file_path(msginfo);
1281 if (!is_file_exist(msgfile))
1282 g_warning("%s: file not exist\n", msgfile);
1284 compose_attach_append(compose, msgfile, msgfile,
1290 MsgInfo *full_msginfo;
1292 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1294 full_msginfo = procmsg_msginfo_copy(msginfo);
1296 if (prefs_common.fw_quotemark &&
1297 *prefs_common.fw_quotemark)
1298 qmark = prefs_common.fw_quotemark;
1302 compose_quote_fmt(compose, full_msginfo,
1303 prefs_common.fw_quotefmt,
1304 qmark, body, FALSE);
1305 compose_attach_parts(compose, msginfo);
1307 procmsg_msginfo_free(full_msginfo);
1310 if (account->auto_sig)
1311 compose_insert_sig(compose, FALSE);
1313 compose_wrap_all(compose);
1315 gtk_text_buffer_get_start_iter(textbuf, &iter);
1316 gtk_text_buffer_place_cursor(textbuf, &iter);
1318 gtk_widget_grab_focus(compose->header_last->entry);
1320 if (!no_extedit && prefs_common.auto_exteditor)
1321 compose_exec_ext_editor(compose);
1324 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1325 gchar *folderidentifier;
1327 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1328 folderidentifier = folder_item_get_identifier(msginfo->folder);
1329 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1330 g_free(folderidentifier);
1333 undo_unblock(compose->undostruct);
1335 compose->modified = FALSE;
1336 compose_set_title(compose);
1340 #undef INSERT_FW_HEADER
1342 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1345 GtkTextView *textview;
1346 GtkTextBuffer *textbuf;
1350 gboolean single_mail = TRUE;
1352 g_return_val_if_fail(msginfo_list != NULL, NULL);
1354 if (g_slist_length(msginfo_list) > 1)
1355 single_mail = FALSE;
1357 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1358 if (((MsgInfo *)msginfo->data)->folder == NULL)
1361 /* guess account from first selected message */
1363 !(account = compose_guess_forward_account_from_msginfo
1364 (msginfo_list->data)))
1365 account = cur_account;
1367 g_return_val_if_fail(account != NULL, NULL);
1369 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1370 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1371 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1374 compose = compose_create(account, COMPOSE_FORWARD);
1376 textview = GTK_TEXT_VIEW(compose->text);
1377 textbuf = gtk_text_view_get_buffer(textview);
1378 compose_create_tags(textview, compose);
1380 undo_block(compose->undostruct);
1381 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1382 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1383 if (!is_file_exist(msgfile))
1384 g_warning("%s: file not exist\n", msgfile);
1386 compose_attach_append(compose, msgfile, msgfile,
1392 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1393 if (info->subject && *info->subject) {
1394 gchar *buf, *buf2, *p;
1396 buf = p = g_strdup(info->subject);
1397 p += subject_get_prefix_length(p);
1398 memmove(buf, p, strlen(p) + 1);
1400 buf2 = g_strdup_printf("Fw: %s", buf);
1401 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1407 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1408 _("Fw: multiple emails"));
1411 if (account->auto_sig)
1412 compose_insert_sig(compose, FALSE);
1414 compose_wrap_all(compose);
1416 gtk_text_buffer_get_start_iter(textbuf, &iter);
1417 gtk_text_buffer_place_cursor(textbuf, &iter);
1419 gtk_widget_grab_focus(compose->header_last->entry);
1420 undo_unblock(compose->undostruct);
1421 compose->modified = FALSE;
1422 compose_set_title(compose);
1426 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1428 GtkTextIter start = *iter;
1429 GtkTextIter end_iter;
1430 int start_pos = gtk_text_iter_get_offset(&start);
1432 if (!compose->account->sig_sep)
1435 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1436 start_pos+strlen(compose->account->sig_sep));
1438 /* check sig separator */
1439 str = gtk_text_iter_get_text(&start, &end_iter);
1440 if (!strcmp(str, compose->account->sig_sep)) {
1442 /* check end of line (\n) */
1443 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1444 start_pos+strlen(compose->account->sig_sep));
1445 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1446 start_pos+strlen(compose->account->sig_sep)+1);
1447 tmp = gtk_text_iter_get_text(&start, &end_iter);
1448 if (!strcmp(tmp,"\n")) {
1460 static void compose_colorize_signature(Compose *compose)
1462 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1464 GtkTextIter end_iter;
1465 gtk_text_buffer_get_start_iter(buffer, &iter);
1466 while (gtk_text_iter_forward_line(&iter))
1467 if (compose_is_sig_separator(compose, buffer, &iter)) {
1468 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1469 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1473 void compose_reedit(MsgInfo *msginfo)
1475 Compose *compose = NULL;
1476 PrefsAccount *account = NULL;
1477 GtkTextView *textview;
1478 GtkTextBuffer *textbuf;
1482 gchar buf[BUFFSIZE];
1483 gboolean use_signing = FALSE;
1484 gboolean use_encryption = FALSE;
1485 gchar *privacy_system = NULL;
1487 g_return_if_fail(msginfo != NULL);
1488 g_return_if_fail(msginfo->folder != NULL);
1490 if (compose_put_existing_to_front(msginfo))
1493 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1494 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1495 gchar queueheader_buf[BUFFSIZE];
1498 /* Select Account from queue headers */
1499 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1500 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1501 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1502 account = account_find_from_id(id);
1504 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1505 sizeof(queueheader_buf), "NAID:")) {
1506 id = atoi(&queueheader_buf[strlen("NAID:")]);
1507 account = account_find_from_id(id);
1509 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1510 sizeof(queueheader_buf), "MAID:")) {
1511 id = atoi(&queueheader_buf[strlen("MAID:")]);
1512 account = account_find_from_id(id);
1514 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1515 sizeof(queueheader_buf), "S:")) {
1516 account = account_find_from_address(queueheader_buf);
1518 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1519 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1520 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1521 use_signing = param;
1524 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1525 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1526 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1527 use_encryption = param;
1529 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1530 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1531 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1533 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1534 sizeof(queueheader_buf), "X-Priority: ")) {
1535 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1536 compose->priority = param;
1539 account = msginfo->folder->folder->account;
1541 if (!account && prefs_common.reedit_account_autosel) {
1542 gchar from[BUFFSIZE];
1543 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1544 extract_address(from);
1545 account = account_find_from_address(from);
1548 if (!account) account = cur_account;
1549 g_return_if_fail(account != NULL);
1551 compose = compose_create(account, COMPOSE_REEDIT);
1552 if (privacy_system != NULL) {
1553 compose->privacy_system = privacy_system;
1554 compose_use_signing(compose, use_signing);
1555 compose_use_encryption(compose, use_encryption);
1556 compose_update_privacy_system_menu_item(compose, FALSE);
1558 activate_privacy_system(compose, account, FALSE);
1560 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1562 compose_extract_original_charset(compose);
1564 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1565 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1566 gchar queueheader_buf[BUFFSIZE];
1568 /* Set message save folder */
1569 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1572 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1573 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1574 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1576 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1577 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1579 GtkItemFactory *ifactory;
1580 ifactory = gtk_item_factory_from_widget(compose->menubar);
1581 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1586 if (compose_parse_header(compose, msginfo) < 0) return;
1587 compose_reedit_set_entry(compose, msginfo);
1589 textview = GTK_TEXT_VIEW(compose->text);
1590 textbuf = gtk_text_view_get_buffer(textview);
1591 compose_create_tags(textview, compose);
1593 mark = gtk_text_buffer_get_insert(textbuf);
1594 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1596 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1597 G_CALLBACK(compose_changed_cb),
1600 if (procmime_msginfo_is_encrypted(msginfo)) {
1601 fp = procmime_get_first_encrypted_text_content(msginfo);
1603 compose_force_encryption(compose, account, TRUE);
1605 fp = procmime_get_first_text_content(msginfo);
1607 g_warning("Can't get text part\n");
1610 gboolean prev_autowrap = compose->autowrap;
1612 compose->autowrap = FALSE;
1613 while (fgets(buf, sizeof(buf), fp) != NULL) {
1615 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1617 compose_wrap_all_full(compose, FALSE);
1618 compose->autowrap = prev_autowrap;
1622 compose_attach_parts(compose, msginfo);
1624 compose_colorize_signature(compose);
1626 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1627 G_CALLBACK(compose_changed_cb),
1630 gtk_widget_grab_focus(compose->text);
1632 if (prefs_common.auto_exteditor)
1633 compose_exec_ext_editor(compose);
1634 compose->modified = FALSE;
1635 compose_set_title(compose);
1638 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1642 GtkItemFactory *ifactory;
1645 g_return_val_if_fail(msginfo != NULL, NULL);
1648 account = account_get_reply_account(msginfo,
1649 prefs_common.reply_account_autosel);
1650 g_return_val_if_fail(account != NULL, NULL);
1652 compose = compose_create(account, COMPOSE_REDIRECT);
1653 ifactory = gtk_item_factory_from_widget(compose->menubar);
1654 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1655 compose->replyinfo = NULL;
1656 compose->fwdinfo = NULL;
1658 compose_show_first_last_header(compose, TRUE);
1660 gtk_widget_grab_focus(compose->header_last->entry);
1662 filename = procmsg_get_message_file_path(msginfo);
1663 if (filename == NULL)
1666 compose->redirect_filename = filename;
1668 /* Set save folder */
1669 item = msginfo->folder;
1670 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1671 gchar *folderidentifier;
1673 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1674 folderidentifier = folder_item_get_identifier(item);
1675 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1676 g_free(folderidentifier);
1679 compose_attach_parts(compose, msginfo);
1681 if (msginfo->subject)
1682 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1684 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1686 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1687 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1689 compose_colorize_signature(compose);
1691 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1692 menu_set_sensitive(ifactory, "/Add...", FALSE);
1693 menu_set_sensitive(ifactory, "/Remove", FALSE);
1694 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1696 ifactory = gtk_item_factory_from_widget(compose->menubar);
1697 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1698 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1699 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1700 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1701 menu_set_sensitive(ifactory, "/Edit", FALSE);
1702 menu_set_sensitive(ifactory, "/Options", FALSE);
1703 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1704 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1706 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1707 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1708 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1709 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1710 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1711 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1712 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1714 compose->modified = FALSE;
1715 compose_set_title(compose);
1719 GList *compose_get_compose_list(void)
1721 return compose_list;
1724 void compose_entry_append(Compose *compose, const gchar *address,
1725 ComposeEntryType type)
1729 gboolean in_quote = FALSE;
1730 if (!address || *address == '\0') return;
1737 header = N_("Bcc:");
1739 case COMPOSE_REPLYTO:
1740 header = N_("Reply-To:");
1742 case COMPOSE_NEWSGROUPS:
1743 header = N_("Newsgroups:");
1745 case COMPOSE_FOLLOWUPTO:
1746 header = N_( "Followup-To:");
1753 header = prefs_common.trans_hdr ? gettext(header) : header;
1755 cur = begin = (gchar *)address;
1757 /* we separate the line by commas, but not if we're inside a quoted
1759 while (*cur != '\0') {
1761 in_quote = !in_quote;
1762 if (*cur == ',' && !in_quote) {
1763 gchar *tmp = g_strdup(begin);
1765 tmp[cur-begin]='\0';
1770 compose_add_header_entry(compose, header, tmp);
1777 gchar *tmp = g_strdup(begin);
1779 tmp[cur-begin]='\0';
1784 compose_add_header_entry(compose, header, tmp);
1789 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1791 static GtkStyle *bold_style = NULL;
1792 static GdkColor bold_color;
1796 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1797 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1798 if (gtk_entry_get_text(entry) &&
1799 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1800 gtk_widget_ensure_style(GTK_WIDGET(entry));
1802 gtkut_convert_int_to_gdk_color
1803 (prefs_common.color_new, &bold_color);
1804 bold_style = gtk_style_copy(gtk_widget_get_style
1805 (GTK_WIDGET(entry)));
1806 pango_font_description_set_weight
1807 (bold_style->font_desc, PANGO_WEIGHT_BOLD);
1808 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1810 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1815 void compose_toolbar_cb(gint action, gpointer data)
1817 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1818 Compose *compose = (Compose*)toolbar_item->parent;
1820 g_return_if_fail(compose != NULL);
1824 compose_send_cb(compose, 0, NULL);
1827 compose_send_later_cb(compose, 0, NULL);
1830 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1833 compose_insert_file_cb(compose, 0, NULL);
1836 compose_attach_cb(compose, 0, NULL);
1839 compose_insert_sig(compose, FALSE);
1842 compose_ext_editor_cb(compose, 0, NULL);
1844 case A_LINEWRAP_CURRENT:
1845 compose_beautify_paragraph(compose, NULL, TRUE);
1847 case A_LINEWRAP_ALL:
1848 compose_wrap_all_full(compose, TRUE);
1851 compose_address_cb(compose, 0, NULL);
1854 case A_CHECK_SPELLING:
1855 compose_check_all(compose);
1863 static void compose_entries_set(Compose *compose, const gchar *mailto)
1867 gchar *subject = NULL;
1872 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1875 compose_entry_append(compose, to, COMPOSE_TO);
1877 compose_entry_append(compose, cc, COMPOSE_CC);
1879 if (!g_utf8_validate (subject, -1, NULL)) {
1880 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1881 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1884 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1888 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1889 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1892 gboolean prev_autowrap = compose->autowrap;
1894 compose->autowrap = FALSE;
1896 mark = gtk_text_buffer_get_insert(buffer);
1897 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1899 if (!g_utf8_validate (body, -1, NULL)) {
1900 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1901 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1904 gtk_text_buffer_insert(buffer, &iter, body, -1);
1906 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1908 compose->autowrap = prev_autowrap;
1909 if (compose->autowrap)
1910 compose_wrap_all(compose);
1919 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1921 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1922 {"Cc:", NULL, TRUE},
1923 {"References:", NULL, FALSE},
1924 {"Bcc:", NULL, TRUE},
1925 {"Newsgroups:", NULL, TRUE},
1926 {"Followup-To:", NULL, TRUE},
1927 {"List-Post:", NULL, FALSE},
1928 {"X-Priority:", NULL, FALSE},
1929 {NULL, NULL, FALSE}};
1945 g_return_val_if_fail(msginfo != NULL, -1);
1947 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1948 procheader_get_header_fields(fp, hentry);
1951 if (hentry[H_REPLY_TO].body != NULL) {
1952 if (hentry[H_REPLY_TO].body[0] != '\0') {
1954 conv_unmime_header(hentry[H_REPLY_TO].body,
1957 g_free(hentry[H_REPLY_TO].body);
1958 hentry[H_REPLY_TO].body = NULL;
1960 if (hentry[H_CC].body != NULL) {
1961 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
1962 g_free(hentry[H_CC].body);
1963 hentry[H_CC].body = NULL;
1965 if (hentry[H_REFERENCES].body != NULL) {
1966 if (compose->mode == COMPOSE_REEDIT)
1967 compose->references = hentry[H_REFERENCES].body;
1969 compose->references = compose_parse_references
1970 (hentry[H_REFERENCES].body, msginfo->msgid);
1971 g_free(hentry[H_REFERENCES].body);
1973 hentry[H_REFERENCES].body = NULL;
1975 if (hentry[H_BCC].body != NULL) {
1976 if (compose->mode == COMPOSE_REEDIT)
1978 conv_unmime_header(hentry[H_BCC].body, NULL);
1979 g_free(hentry[H_BCC].body);
1980 hentry[H_BCC].body = NULL;
1982 if (hentry[H_NEWSGROUPS].body != NULL) {
1983 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1984 hentry[H_NEWSGROUPS].body = NULL;
1986 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1987 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
1988 compose->followup_to =
1989 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
1992 g_free(hentry[H_FOLLOWUP_TO].body);
1993 hentry[H_FOLLOWUP_TO].body = NULL;
1995 if (hentry[H_LIST_POST].body != NULL) {
1998 extract_address(hentry[H_LIST_POST].body);
1999 if (hentry[H_LIST_POST].body[0] != '\0') {
2000 scan_mailto_url(hentry[H_LIST_POST].body,
2001 &to, NULL, NULL, NULL, NULL);
2003 g_free(compose->ml_post);
2004 compose->ml_post = to;
2007 g_free(hentry[H_LIST_POST].body);
2008 hentry[H_LIST_POST].body = NULL;
2011 /* CLAWS - X-Priority */
2012 if (compose->mode == COMPOSE_REEDIT)
2013 if (hentry[H_X_PRIORITY].body != NULL) {
2016 priority = atoi(hentry[H_X_PRIORITY].body);
2017 g_free(hentry[H_X_PRIORITY].body);
2019 hentry[H_X_PRIORITY].body = NULL;
2021 if (priority < PRIORITY_HIGHEST ||
2022 priority > PRIORITY_LOWEST)
2023 priority = PRIORITY_NORMAL;
2025 compose->priority = priority;
2028 if (compose->mode == COMPOSE_REEDIT) {
2029 if (msginfo->inreplyto && *msginfo->inreplyto)
2030 compose->inreplyto = g_strdup(msginfo->inreplyto);
2034 if (msginfo->msgid && *msginfo->msgid)
2035 compose->inreplyto = g_strdup(msginfo->msgid);
2037 if (!compose->references) {
2038 if (msginfo->msgid && *msginfo->msgid) {
2039 if (msginfo->inreplyto && *msginfo->inreplyto)
2040 compose->references =
2041 g_strdup_printf("<%s>\n\t<%s>",
2045 compose->references =
2046 g_strconcat("<", msginfo->msgid, ">",
2048 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2049 compose->references =
2050 g_strconcat("<", msginfo->inreplyto, ">",
2058 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2060 GSList *ref_id_list, *cur;
2064 ref_id_list = references_list_append(NULL, ref);
2065 if (!ref_id_list) return NULL;
2066 if (msgid && *msgid)
2067 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2072 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2073 /* "<" + Message-ID + ">" + CR+LF+TAB */
2074 len += strlen((gchar *)cur->data) + 5;
2076 if (len > MAX_REFERENCES_LEN) {
2077 /* remove second message-ID */
2078 if (ref_id_list && ref_id_list->next &&
2079 ref_id_list->next->next) {
2080 g_free(ref_id_list->next->data);
2081 ref_id_list = g_slist_remove
2082 (ref_id_list, ref_id_list->next->data);
2084 slist_free_strings(ref_id_list);
2085 g_slist_free(ref_id_list);
2092 new_ref = g_string_new("");
2093 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2094 if (new_ref->len > 0)
2095 g_string_append(new_ref, "\n\t");
2096 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2099 slist_free_strings(ref_id_list);
2100 g_slist_free(ref_id_list);
2102 new_ref_str = new_ref->str;
2103 g_string_free(new_ref, FALSE);
2108 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2109 const gchar *fmt, const gchar *qmark,
2110 const gchar *body, gboolean rewrap)
2112 static MsgInfo dummyinfo;
2113 gchar *quote_str = NULL;
2115 gboolean prev_autowrap;
2116 const gchar *trimmed_body = body;
2117 gint cursor_pos = -1;
2118 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2119 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2124 msginfo = &dummyinfo;
2126 if (qmark != NULL) {
2127 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2128 quote_fmt_scan_string(qmark);
2131 buf = quote_fmt_get_buffer();
2133 alertpanel_error(_("Quote mark format error."));
2135 Xstrdup_a(quote_str, buf, return NULL)
2138 if (fmt && *fmt != '\0') {
2139 while (trimmed_body && strlen(trimmed_body) > 1
2140 && trimmed_body[0]=='\n')
2143 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2144 quote_fmt_scan_string(fmt);
2147 buf = quote_fmt_get_buffer();
2149 alertpanel_error(_("Message reply/forward format error."));
2155 prev_autowrap = compose->autowrap;
2156 compose->autowrap = FALSE;
2158 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2159 G_CALLBACK(compose_changed_cb),
2161 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2162 G_CALLBACK(text_inserted),
2165 mark = gtk_text_buffer_get_insert(buffer);
2166 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2167 if (g_utf8_validate(buf, -1, NULL)) {
2168 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2170 gchar *tmpout = NULL;
2171 tmpout = conv_codeset_strdup
2172 (buf, conv_get_locale_charset_str(),
2174 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2176 tmpout = g_malloc(strlen(buf)*2+1);
2177 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2179 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2183 cursor_pos = quote_fmt_get_cursor_pos();
2184 compose->set_cursor_pos = cursor_pos;
2185 if (cursor_pos == -1) {
2188 gtk_text_buffer_get_start_iter(buffer, &iter);
2189 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2190 gtk_text_buffer_place_cursor(buffer, &iter);
2192 compose->autowrap = prev_autowrap;
2193 if (compose->autowrap && rewrap)
2194 compose_wrap_all(compose);
2196 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2197 G_CALLBACK(compose_changed_cb),
2199 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2200 G_CALLBACK(text_inserted),
2207 /* if ml_post is of type addr@host and from is of type
2208 * addr-anything@host, return TRUE
2210 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2212 gchar *left_ml = NULL;
2213 gchar *right_ml = NULL;
2214 gchar *left_from = NULL;
2215 gchar *right_from = NULL;
2216 gboolean result = FALSE;
2218 if (!ml_post || !from)
2221 left_ml = g_strdup(ml_post);
2222 if (strstr(left_ml, "@")) {
2223 right_ml = strstr(left_ml, "@")+1;
2224 *(strstr(left_ml, "@")) = '\0';
2227 left_from = g_strdup(from);
2228 if (strstr(left_from, "@")) {
2229 right_from = strstr(left_from, "@")+1;
2230 *(strstr(left_from, "@")) = '\0';
2233 if (left_ml && left_from && right_ml && right_from
2234 && !strncmp(left_from, left_ml, strlen(left_ml))
2235 && !strcmp(right_from, right_ml)) {
2244 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2246 gchar *my_addr1, *my_addr2;
2248 if (!addr1 || !addr2)
2251 Xstrdup_a(my_addr1, addr1, return FALSE);
2252 Xstrdup_a(my_addr2, addr2, return FALSE);
2254 extract_address(my_addr1);
2255 extract_address(my_addr2);
2257 return !strcmp(my_addr1, my_addr2);
2260 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2261 gboolean to_all, gboolean to_ml,
2263 gboolean followup_and_reply_to)
2265 GSList *cc_list = NULL;
2268 gchar *replyto = NULL;
2269 GHashTable *to_table;
2271 gboolean reply_to_ml = FALSE;
2272 gboolean default_reply_to = FALSE;
2274 g_return_if_fail(compose->account != NULL);
2275 g_return_if_fail(msginfo != NULL);
2277 reply_to_ml = to_ml && compose->ml_post;
2279 default_reply_to = msginfo->folder &&
2280 msginfo->folder->prefs->enable_default_reply_to;
2282 if (compose->account->protocol != A_NNTP) {
2283 if (reply_to_ml && !default_reply_to) {
2285 gboolean is_subscr = is_subscription(compose->ml_post,
2288 /* normal answer to ml post with a reply-to */
2289 compose_entry_append(compose,
2292 if (compose->replyto
2293 && !same_address(compose->ml_post, compose->replyto))
2294 compose_entry_append(compose,
2298 /* answer to subscription confirmation */
2299 if (compose->replyto)
2300 compose_entry_append(compose,
2303 else if (msginfo->from)
2304 compose_entry_append(compose,
2309 else if (!(to_all || to_sender) && default_reply_to) {
2310 compose_entry_append(compose,
2311 msginfo->folder->prefs->default_reply_to,
2313 compose_entry_mark_default_to(compose,
2314 msginfo->folder->prefs->default_reply_to);
2317 Xstrdup_a(tmp1, msginfo->from, return);
2318 extract_address(tmp1);
2319 if (to_all || to_sender ||
2320 !account_find_from_address(tmp1))
2321 compose_entry_append(compose,
2322 (compose->replyto && !to_sender)
2323 ? compose->replyto :
2324 msginfo->from ? msginfo->from : "",
2326 else if (!to_all && !to_sender) {
2327 /* reply to the last list of recipients */
2328 compose_entry_append(compose,
2329 msginfo->to ? msginfo->to : "",
2331 compose_entry_append(compose,
2332 msginfo->cc ? msginfo->cc : "",
2337 if (to_sender || (compose->followup_to &&
2338 !strncmp(compose->followup_to, "poster", 6)))
2339 compose_entry_append
2341 (compose->replyto ? compose->replyto :
2342 msginfo->from ? msginfo->from : ""),
2345 else if (followup_and_reply_to || to_all) {
2346 compose_entry_append
2348 (compose->replyto ? compose->replyto :
2349 msginfo->from ? msginfo->from : ""),
2352 compose_entry_append
2354 compose->followup_to ? compose->followup_to :
2355 compose->newsgroups ? compose->newsgroups : "",
2356 COMPOSE_NEWSGROUPS);
2359 compose_entry_append
2361 compose->followup_to ? compose->followup_to :
2362 compose->newsgroups ? compose->newsgroups : "",
2363 COMPOSE_NEWSGROUPS);
2366 if (msginfo->subject && *msginfo->subject) {
2370 buf = p = g_strdup(msginfo->subject);
2371 p += subject_get_prefix_length(p);
2372 memmove(buf, p, strlen(p) + 1);
2374 buf2 = g_strdup_printf("Re: %s", buf);
2375 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2380 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2382 if (to_ml && compose->ml_post) return;
2383 if (!to_all || compose->account->protocol == A_NNTP) return;
2385 if (compose->replyto) {
2386 Xstrdup_a(replyto, compose->replyto, return);
2387 extract_address(replyto);
2389 if (msginfo->from) {
2390 Xstrdup_a(from, msginfo->from, return);
2391 extract_address(from);
2394 if (replyto && from)
2395 cc_list = address_list_append_with_comments(cc_list, from);
2396 if (to_all && msginfo->folder &&
2397 msginfo->folder->prefs->enable_default_reply_to)
2398 cc_list = address_list_append_with_comments(cc_list,
2399 msginfo->folder->prefs->default_reply_to);
2400 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2401 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2403 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2405 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2406 if (compose->account)
2407 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2408 GINT_TO_POINTER(1));
2410 /* remove address on To: and that of current account */
2411 for (cur = cc_list; cur != NULL; ) {
2412 GSList *next = cur->next;
2415 addr = g_strdup(cur->data);
2416 extract_address(addr);
2418 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2419 cc_list = g_slist_remove(cc_list, cur->data);
2421 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2425 hash_free_strings(to_table);
2426 g_hash_table_destroy(to_table);
2429 for (cur = cc_list; cur != NULL; cur = cur->next)
2430 compose_entry_append(compose, (gchar *)cur->data,
2432 slist_free_strings(cc_list);
2433 g_slist_free(cc_list);
2438 #define SET_ENTRY(entry, str) \
2441 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2444 #define SET_ADDRESS(type, str) \
2447 compose_entry_append(compose, str, type); \
2450 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2452 g_return_if_fail(msginfo != NULL);
2454 SET_ENTRY(subject_entry, msginfo->subject);
2455 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2456 SET_ADDRESS(COMPOSE_CC, compose->cc);
2457 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2458 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2459 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2460 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2462 compose_update_priority_menu_item(compose);
2463 compose_update_privacy_system_menu_item(compose, FALSE);
2464 compose_show_first_last_header(compose, TRUE);
2470 static void compose_insert_sig(Compose *compose, gboolean replace)
2472 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2473 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2475 GtkTextIter iter, iter_end;
2477 gboolean prev_autowrap;
2480 g_return_if_fail(compose->account != NULL);
2482 prev_autowrap = compose->autowrap;
2483 compose->autowrap = FALSE;
2485 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2486 G_CALLBACK(compose_changed_cb),
2489 mark = gtk_text_buffer_get_insert(buffer);
2490 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2491 cur_pos = gtk_text_iter_get_offset (&iter);
2493 gtk_text_buffer_get_end_iter(buffer, &iter);
2495 if (replace && compose->sig_str) {
2497 GtkTextIter first_iter, start_iter, end_iter;
2499 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2501 if (compose->sig_str[0] == '\0')
2504 found = gtk_text_iter_forward_search(&first_iter,
2506 GTK_TEXT_SEARCH_TEXT_ONLY,
2507 &start_iter, &end_iter,
2511 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2516 g_free(compose->sig_str);
2517 compose->sig_str = compose_get_signature_str(compose);
2518 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2519 compose->sig_str = g_strdup("");
2521 cur_pos = gtk_text_iter_get_offset(&iter);
2522 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2524 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2525 gtk_text_iter_forward_char(&iter);
2526 gtk_text_iter_forward_char(&iter);
2527 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2528 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2530 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2531 cur_pos = gtk_text_buffer_get_char_count (buffer);
2533 /* put the cursor where it should be
2534 * either where the quote_fmt says, either before the signature */
2535 if (compose->set_cursor_pos < 0)
2536 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2538 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2539 compose->set_cursor_pos);
2541 gtk_text_buffer_place_cursor(buffer, &iter);
2542 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2543 G_CALLBACK(compose_changed_cb),
2546 compose->autowrap = prev_autowrap;
2547 if (compose->autowrap)
2548 compose_wrap_all(compose);
2551 static gchar *compose_get_signature_str(Compose *compose)
2553 gchar *sig_body = NULL;
2554 gchar *sig_str = NULL;
2555 gchar *utf8_sig_str = NULL;
2557 g_return_val_if_fail(compose->account != NULL, NULL);
2559 if (!compose->account->sig_path)
2562 if (compose->account->sig_type == SIG_FILE) {
2563 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2564 g_warning("can't open signature file: %s\n",
2565 compose->account->sig_path);
2570 if (compose->account->sig_type == SIG_COMMAND)
2571 sig_body = get_command_output(compose->account->sig_path);
2575 tmp = file_read_to_str(compose->account->sig_path);
2578 sig_body = normalize_newlines(tmp);
2582 if (compose->account->sig_sep) {
2583 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2587 sig_str = g_strconcat("\n\n", sig_body, NULL);
2590 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2591 utf8_sig_str = sig_str;
2593 utf8_sig_str = conv_codeset_strdup
2594 (sig_str, conv_get_locale_charset_str(),
2600 return utf8_sig_str;
2603 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2606 GtkTextBuffer *buffer;
2609 const gchar *cur_encoding;
2610 gchar buf[BUFFSIZE];
2613 gboolean prev_autowrap;
2614 gboolean badtxt = FALSE;
2616 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2618 if ((fp = g_fopen(file, "rb")) == NULL) {
2619 FILE_OP_ERROR(file, "fopen");
2620 return COMPOSE_INSERT_READ_ERROR;
2623 prev_autowrap = compose->autowrap;
2624 compose->autowrap = FALSE;
2626 text = GTK_TEXT_VIEW(compose->text);
2627 buffer = gtk_text_view_get_buffer(text);
2628 mark = gtk_text_buffer_get_insert(buffer);
2629 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2631 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2632 G_CALLBACK(text_inserted),
2635 cur_encoding = conv_get_locale_charset_str();
2637 while (fgets(buf, sizeof(buf), fp) != NULL) {
2640 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2641 str = g_strdup(buf);
2643 str = conv_codeset_strdup
2644 (buf, cur_encoding, CS_INTERNAL);
2647 /* strip <CR> if DOS/Windows file,
2648 replace <CR> with <LF> if Macintosh file. */
2651 if (len > 0 && str[len - 1] != '\n') {
2653 if (str[len] == '\r') str[len] = '\n';
2656 gtk_text_buffer_insert(buffer, &iter, str, -1);
2660 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2661 G_CALLBACK(text_inserted),
2663 compose->autowrap = prev_autowrap;
2664 if (compose->autowrap)
2665 compose_wrap_all(compose);
2670 return COMPOSE_INSERT_INVALID_CHARACTER;
2672 return COMPOSE_INSERT_SUCCESS;
2675 static void compose_attach_append(Compose *compose, const gchar *file,
2676 const gchar *filename,
2677 const gchar *content_type)
2685 GtkListStore *store;
2688 if (!is_file_exist(file)) {
2689 g_warning("File %s doesn't exist\n", filename);
2692 if ((size = get_file_size(file)) < 0) {
2693 g_warning("Can't get file size of %s\n", filename);
2697 alertpanel_notice(_("File %s is empty."), filename);
2700 if ((fp = g_fopen(file, "rb")) == NULL) {
2701 alertpanel_error(_("Can't read %s."), filename);
2706 ainfo = g_new0(AttachInfo, 1);
2707 auto_ainfo = g_auto_pointer_new_with_free
2708 (ainfo, (GFreeFunc) compose_attach_info_free);
2709 ainfo->file = g_strdup(file);
2712 ainfo->content_type = g_strdup(content_type);
2713 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2715 MsgFlags flags = {0, 0};
2717 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2718 ainfo->encoding = ENC_7BIT;
2720 ainfo->encoding = ENC_8BIT;
2722 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2723 if (msginfo && msginfo->subject)
2724 name = g_strdup(msginfo->subject);
2726 name = g_path_get_basename(filename ? filename : file);
2728 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2730 procmsg_msginfo_free(msginfo);
2732 if (!g_ascii_strncasecmp(content_type, "text", 4))
2733 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2735 ainfo->encoding = ENC_BASE64;
2736 name = g_path_get_basename(filename ? filename : file);
2737 ainfo->name = g_strdup(name);
2741 ainfo->content_type = procmime_get_mime_type(file);
2742 if (!ainfo->content_type) {
2743 ainfo->content_type =
2744 g_strdup("application/octet-stream");
2745 ainfo->encoding = ENC_BASE64;
2746 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2748 procmime_get_encoding_for_text_file(file);
2750 ainfo->encoding = ENC_BASE64;
2751 name = g_path_get_basename(filename ? filename : file);
2752 ainfo->name = g_strdup(name);
2756 if (!strcmp(ainfo->content_type, "unknown")) {
2757 g_free(ainfo->content_type);
2758 ainfo->content_type = g_strdup("application/octet-stream");
2762 size_text = to_human_readable(size);
2764 store = GTK_LIST_STORE(gtk_tree_view_get_model
2765 (GTK_TREE_VIEW(compose->attach_clist)));
2767 gtk_list_store_append(store, &iter);
2768 gtk_list_store_set(store, &iter,
2769 COL_MIMETYPE, ainfo->content_type,
2770 COL_SIZE, size_text,
2771 COL_NAME, ainfo->name,
2773 COL_AUTODATA, auto_ainfo,
2776 g_auto_pointer_free(auto_ainfo);
2779 static void compose_use_signing(Compose *compose, gboolean use_signing)
2781 GtkItemFactory *ifactory;
2782 GtkWidget *menuitem = NULL;
2784 compose->use_signing = use_signing;
2785 ifactory = gtk_item_factory_from_widget(compose->menubar);
2786 menuitem = gtk_item_factory_get_item
2787 (ifactory, "/Options/Sign");
2788 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2792 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2794 GtkItemFactory *ifactory;
2795 GtkWidget *menuitem = NULL;
2797 compose->use_encryption = use_encryption;
2798 ifactory = gtk_item_factory_from_widget(compose->menubar);
2799 menuitem = gtk_item_factory_get_item
2800 (ifactory, "/Options/Encrypt");
2802 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2806 #define NEXT_PART_NOT_CHILD(info) \
2808 node = info->node; \
2809 while (node->children) \
2810 node = g_node_last_child(node); \
2811 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2814 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2818 MimeInfo *firsttext = NULL;
2819 MimeInfo *encrypted = NULL;
2822 const gchar *partname = NULL;
2824 mimeinfo = procmime_scan_message(msginfo);
2825 if (!mimeinfo) return;
2827 if (mimeinfo->node->children == NULL) {
2828 procmime_mimeinfo_free_all(mimeinfo);
2832 /* find first content part */
2833 child = (MimeInfo *) mimeinfo->node->children->data;
2834 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2835 child = (MimeInfo *)child->node->children->data;
2837 if (child->type == MIMETYPE_TEXT) {
2839 debug_print("First text part found\n");
2840 } else if (compose->mode == COMPOSE_REEDIT &&
2841 child->type == MIMETYPE_APPLICATION &&
2842 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2843 encrypted = (MimeInfo *)child->node->parent->data;
2846 child = (MimeInfo *) mimeinfo->node->children->data;
2847 while (child != NULL) {
2848 if (child == encrypted) {
2849 /* skip this part of tree */
2850 NEXT_PART_NOT_CHILD(child);
2854 if (child->type == MIMETYPE_MULTIPART) {
2855 /* get the actual content */
2856 child = procmime_mimeinfo_next(child);
2860 if (child == firsttext) {
2861 child = procmime_mimeinfo_next(child);
2865 outfile = procmime_get_tmp_file_name(child);
2866 if (procmime_get_part(outfile, child) < 0)
2867 g_warning("Can't get the part of multipart message.");
2869 gchar *content_type;
2871 content_type = procmime_get_content_type_str(child->type, child->subtype);
2873 /* if we meet a pgp signature, we don't attach it, but
2874 * we force signing. */
2875 if (strcmp(content_type, "application/pgp-signature")) {
2876 partname = procmime_mimeinfo_get_parameter(child, "filename");
2877 if (partname == NULL)
2878 partname = procmime_mimeinfo_get_parameter(child, "name");
2879 if (partname == NULL)
2881 compose_attach_append(compose, outfile,
2882 partname, content_type);
2884 compose_force_signing(compose, compose->account);
2886 g_free(content_type);
2889 NEXT_PART_NOT_CHILD(child);
2891 procmime_mimeinfo_free_all(mimeinfo);
2894 #undef NEXT_PART_NOT_CHILD
2899 WAIT_FOR_INDENT_CHAR,
2900 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2903 /* return indent length, we allow:
2904 indent characters followed by indent characters or spaces/tabs,
2905 alphabets and numbers immediately followed by indent characters,
2906 and the repeating sequences of the above
2907 If quote ends with multiple spaces, only the first one is included. */
2908 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2909 const GtkTextIter *start, gint *len)
2911 GtkTextIter iter = *start;
2915 IndentState state = WAIT_FOR_INDENT_CHAR;
2918 gint alnum_count = 0;
2919 gint space_count = 0;
2922 if (prefs_common.quote_chars == NULL) {
2926 while (!gtk_text_iter_ends_line(&iter)) {
2927 wc = gtk_text_iter_get_char(&iter);
2928 if (g_unichar_iswide(wc))
2930 clen = g_unichar_to_utf8(wc, ch);
2934 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2935 is_space = g_unichar_isspace(wc);
2937 if (state == WAIT_FOR_INDENT_CHAR) {
2938 if (!is_indent && !g_unichar_isalnum(wc))
2941 quote_len += alnum_count + space_count + 1;
2942 alnum_count = space_count = 0;
2943 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2946 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2947 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
2951 else if (is_indent) {
2952 quote_len += alnum_count + space_count + 1;
2953 alnum_count = space_count = 0;
2956 state = WAIT_FOR_INDENT_CHAR;
2960 gtk_text_iter_forward_char(&iter);
2963 if (quote_len > 0 && space_count > 0)
2969 if (quote_len > 0) {
2971 gtk_text_iter_forward_chars(&iter, quote_len);
2972 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
2978 /* return TRUE if the line is itemized */
2979 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
2980 const GtkTextIter *start)
2982 GtkTextIter iter = *start;
2987 if (gtk_text_iter_ends_line(&iter))
2991 wc = gtk_text_iter_get_char(&iter);
2992 if (!g_unichar_isspace(wc))
2994 gtk_text_iter_forward_char(&iter);
2995 if (gtk_text_iter_ends_line(&iter))
2999 clen = g_unichar_to_utf8(wc, ch);
3003 if (!strchr("*-+", ch[0]))
3006 gtk_text_iter_forward_char(&iter);
3007 if (gtk_text_iter_ends_line(&iter))
3009 wc = gtk_text_iter_get_char(&iter);
3010 if (g_unichar_isspace(wc))
3016 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3017 const GtkTextIter *start,
3018 GtkTextIter *break_pos,
3022 GtkTextIter iter = *start, line_end = *start;
3023 PangoLogAttr *attrs;
3030 gboolean can_break = FALSE;
3031 gboolean do_break = FALSE;
3032 gboolean was_white = FALSE;
3033 gboolean prev_dont_break = FALSE;
3035 gtk_text_iter_forward_to_line_end(&line_end);
3036 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3037 len = g_utf8_strlen(str, -1);
3038 /* g_print("breaking line: %d: %s (len = %d)\n",
3039 gtk_text_iter_get_line(&iter), str, len); */
3040 attrs = g_new(PangoLogAttr, len + 1);
3042 pango_default_break(str, -1, NULL, attrs, len + 1);
3046 /* skip quote and leading spaces */
3047 for (i = 0; *p != '\0' && i < len; i++) {
3050 wc = g_utf8_get_char(p);
3051 if (i >= quote_len && !g_unichar_isspace(wc))
3053 if (g_unichar_iswide(wc))
3055 else if (*p == '\t')
3059 p = g_utf8_next_char(p);
3062 for (; *p != '\0' && i < len; i++) {
3063 PangoLogAttr *attr = attrs + i;
3067 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3070 was_white = attr->is_white;
3072 /* don't wrap URI */
3073 if ((uri_len = get_uri_len(p)) > 0) {
3075 if (pos > 0 && col > max_col) {
3085 wc = g_utf8_get_char(p);
3086 if (g_unichar_iswide(wc)) {
3088 if (prev_dont_break && can_break && attr->is_line_break)
3090 } else if (*p == '\t')
3094 if (pos > 0 && col > max_col) {
3099 if (*p == '-' || *p == '/')
3100 prev_dont_break = TRUE;
3102 prev_dont_break = FALSE;
3104 p = g_utf8_next_char(p);
3108 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3113 *break_pos = *start;
3114 gtk_text_iter_set_line_offset(break_pos, pos);
3119 static gboolean compose_join_next_line(Compose *compose,
3120 GtkTextBuffer *buffer,
3122 const gchar *quote_str)
3124 GtkTextIter iter_ = *iter, cur, prev, next, end;
3125 PangoLogAttr attrs[3];
3127 gchar *next_quote_str;
3130 gboolean keep_cursor = FALSE;
3132 if (!gtk_text_iter_forward_line(&iter_) ||
3133 gtk_text_iter_ends_line(&iter_))
3136 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3138 if ((quote_str || next_quote_str) &&
3139 strcmp2(quote_str, next_quote_str) != 0) {
3140 g_free(next_quote_str);
3143 g_free(next_quote_str);
3146 if (quote_len > 0) {
3147 gtk_text_iter_forward_chars(&end, quote_len);
3148 if (gtk_text_iter_ends_line(&end))
3152 /* don't join itemized lines */
3153 if (compose_is_itemized(buffer, &end))
3156 /* don't join signature separator */
3157 if (compose_is_sig_separator(compose, buffer, &iter_))
3160 /* delete quote str */
3162 gtk_text_buffer_delete(buffer, &iter_, &end);
3164 /* delete linebreak and extra spaces */
3166 while (gtk_text_iter_backward_char(&cur)) {
3167 wc1 = gtk_text_iter_get_char(&cur);
3168 if (!g_unichar_isspace(wc1))
3173 while (!gtk_text_iter_ends_line(&cur)) {
3174 wc1 = gtk_text_iter_get_char(&cur);
3175 if (!g_unichar_isspace(wc1))
3177 gtk_text_iter_forward_char(&cur);
3180 if (!gtk_text_iter_equal(&prev, &next)) {
3183 mark = gtk_text_buffer_get_insert(buffer);
3184 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3185 if (gtk_text_iter_equal(&prev, &cur))
3187 gtk_text_buffer_delete(buffer, &prev, &next);
3191 /* insert space if required */
3192 gtk_text_iter_backward_char(&prev);
3193 wc1 = gtk_text_iter_get_char(&prev);
3194 wc2 = gtk_text_iter_get_char(&next);
3195 gtk_text_iter_forward_char(&next);
3196 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3197 pango_default_break(str, -1, NULL, attrs, 3);
3198 if (!attrs[1].is_line_break ||
3199 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3200 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3202 gtk_text_iter_backward_char(&iter_);
3203 gtk_text_buffer_place_cursor(buffer, &iter_);
3212 #define ADD_TXT_POS(bp_, ep_, pti_) \
3213 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3214 last = last->next; \
3215 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3216 last->next = NULL; \
3218 g_warning("alloc error scanning URIs\n"); \
3221 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3223 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3224 GtkTextBuffer *buffer;
3225 GtkTextIter iter, break_pos, end_of_line;
3226 gchar *quote_str = NULL;
3228 gboolean wrap_quote = prefs_common.linewrap_quote;
3229 gboolean prev_autowrap = compose->autowrap;
3230 gint startq_offset = -1, noq_offset = -1;
3231 gint uri_start = -1, uri_stop = -1;
3232 gint nouri_start = -1, nouri_stop = -1;
3234 compose->autowrap = FALSE;
3236 buffer = gtk_text_view_get_buffer(text);
3237 undo_wrapping(compose->undostruct, TRUE);
3242 mark = gtk_text_buffer_get_insert(buffer);
3243 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3246 /* move to paragraph start */
3247 gtk_text_iter_set_line_offset(&iter, 0);
3248 if (gtk_text_iter_ends_line(&iter)) {
3249 while (gtk_text_iter_ends_line(&iter) &&
3250 gtk_text_iter_forward_line(&iter))
3253 while (gtk_text_iter_backward_line(&iter)) {
3254 if (gtk_text_iter_ends_line(&iter)) {
3255 gtk_text_iter_forward_line(&iter);
3261 /* go until paragraph end (empty line) */
3262 while (!gtk_text_iter_ends_line(&iter)) {
3263 gchar *scanpos = NULL;
3264 /* parse table - in order of priority */
3266 const gchar *needle; /* token */
3268 /* token search function */
3269 gchar *(*search) (const gchar *haystack,
3270 const gchar *needle);
3271 /* part parsing function */
3272 gboolean (*parse) (const gchar *start,
3273 const gchar *scanpos,
3277 /* part to URI function */
3278 gchar *(*build_uri) (const gchar *bp,
3282 static struct table parser[] = {
3283 {"http://", strcasestr, get_uri_part, make_uri_string},
3284 {"https://", strcasestr, get_uri_part, make_uri_string},
3285 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3286 {"www.", strcasestr, get_uri_part, make_http_string},
3287 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3288 {"@", strcasestr, get_email_part, make_email_string}
3290 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3291 gint last_index = PARSE_ELEMS;
3293 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3296 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3299 uri_start = uri_stop = -1;
3300 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3304 if (startq_offset == -1) {
3305 startq_offset = gtk_text_iter_get_offset(&iter);
3309 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3310 if (startq_offset == -1)
3311 startq_offset = gtk_text_iter_get_offset(&iter);
3313 if (startq_offset == -1)
3314 noq_offset = gtk_text_iter_get_offset(&iter);
3317 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3320 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3321 prefs_common.linewrap_len,
3323 GtkTextIter prev, next, cur;
3325 if (prev_autowrap != FALSE || force)
3326 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3327 else if (quote_str && wrap_quote)
3328 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3331 /* remove trailing spaces */
3333 gtk_text_iter_backward_char(&cur);
3335 while (!gtk_text_iter_starts_line(&cur)) {
3338 gtk_text_iter_backward_char(&cur);
3339 wc = gtk_text_iter_get_char(&cur);
3340 if (!g_unichar_isspace(wc))
3344 if (!gtk_text_iter_equal(&prev, &next)) {
3345 gtk_text_buffer_delete(buffer, &prev, &next);
3347 gtk_text_iter_forward_char(&break_pos);
3351 gtk_text_buffer_insert(buffer, &break_pos,
3355 compose_join_next_line(compose, buffer, &iter, quote_str);
3357 /* move iter to current line start */
3358 gtk_text_iter_set_line_offset(&iter, 0);
3361 /* move iter to next line start */
3367 while (!gtk_text_iter_ends_line(&end_of_line)) {
3368 gtk_text_iter_forward_char(&end_of_line);
3370 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3372 nouri_start = gtk_text_iter_get_offset(&iter);
3373 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3375 walk_pos = gtk_text_iter_get_offset(&iter);
3376 /* FIXME: this looks phony. scanning for anything in the parse table */
3377 for (n = 0; n < PARSE_ELEMS; n++) {
3380 tmp = parser[n].search(walk, parser[n].needle);
3382 if (scanpos == NULL || tmp < scanpos) {
3391 /* check if URI can be parsed */
3392 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3393 (const gchar **)&ep, FALSE)
3394 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3398 strlen(parser[last_index].needle);
3401 uri_start = walk_pos + (bp - o_walk);
3402 uri_stop = walk_pos + (ep - o_walk);
3406 gtk_text_iter_forward_line(&iter);
3409 if (startq_offset != -1) {
3410 GtkTextIter startquote, endquote;
3411 gtk_text_buffer_get_iter_at_offset(
3412 buffer, &startquote, startq_offset);
3414 gtk_text_buffer_apply_tag_by_name(
3415 buffer, "quote", &startquote, &endquote);
3417 } else if (noq_offset != -1) {
3418 GtkTextIter startnoquote, endnoquote;
3419 gtk_text_buffer_get_iter_at_offset(
3420 buffer, &startnoquote, noq_offset);
3422 gtk_text_buffer_remove_tag_by_name(
3423 buffer, "quote", &startnoquote, &endnoquote);
3428 GtkTextIter nouri_start_iter, nouri_end_iter;
3429 gtk_text_buffer_get_iter_at_offset(
3430 buffer, &nouri_start_iter, nouri_start);
3431 gtk_text_buffer_get_iter_at_offset(
3432 buffer, &nouri_end_iter, nouri_stop);
3433 gtk_text_buffer_remove_tag_by_name(
3434 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3436 if (uri_start > 0 && uri_stop > 0) {
3437 GtkTextIter uri_start_iter, uri_end_iter;
3438 gtk_text_buffer_get_iter_at_offset(
3439 buffer, &uri_start_iter, uri_start);
3440 gtk_text_buffer_get_iter_at_offset(
3441 buffer, &uri_end_iter, uri_stop);
3442 gtk_text_buffer_apply_tag_by_name(
3443 buffer, "link", &uri_start_iter, &uri_end_iter);
3449 undo_wrapping(compose->undostruct, FALSE);
3450 compose->autowrap = prev_autowrap;
3453 void compose_action_cb(void *data)
3455 Compose *compose = (Compose *)data;
3456 compose_wrap_all(compose);
3459 static void compose_wrap_all(Compose *compose)
3461 compose_wrap_all_full(compose, FALSE);
3464 static void compose_wrap_all_full(Compose *compose, gboolean force)
3466 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3467 GtkTextBuffer *buffer;
3470 buffer = gtk_text_view_get_buffer(text);
3472 gtk_text_buffer_get_start_iter(buffer, &iter);
3473 while (!gtk_text_iter_is_end(&iter))
3474 compose_beautify_paragraph(compose, &iter, force);
3478 static void compose_set_title(Compose *compose)
3484 edited = compose->modified ? _(" [Edited]") : "";
3486 subject = gtk_editable_get_chars(
3487 GTK_EDITABLE(compose->subject_entry), 0, -1);
3489 if (subject && strlen(subject))
3490 str = g_strdup_printf(_("%s - Compose message%s"),
3493 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3494 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3500 * compose_current_mail_account:
3502 * Find a current mail account (the currently selected account, or the
3503 * default account, if a news account is currently selected). If a
3504 * mail account cannot be found, display an error message.
3506 * Return value: Mail account, or NULL if not found.
3508 static PrefsAccount *
3509 compose_current_mail_account(void)
3513 if (cur_account && cur_account->protocol != A_NNTP)
3516 ac = account_get_default();
3517 if (!ac || ac->protocol == A_NNTP) {
3518 alertpanel_error(_("Account for sending mail is not specified.\n"
3519 "Please select a mail account before sending."));
3526 static void compose_select_account(Compose *compose, PrefsAccount *account,
3529 GtkItemFactory *ifactory;
3531 g_return_if_fail(account != NULL);
3533 compose->account = account;
3535 compose_set_title(compose);
3537 ifactory = gtk_item_factory_from_widget(compose->menubar);
3539 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3540 menu_set_active(ifactory, "/Options/Sign", TRUE);
3542 menu_set_active(ifactory, "/Options/Sign", FALSE);
3543 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3544 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3546 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3548 activate_privacy_system(compose, account, FALSE);
3550 if (!init && compose->mode != COMPOSE_REDIRECT)
3551 compose_insert_sig(compose, TRUE);
3554 gboolean compose_check_for_valid_recipient(Compose *compose) {
3555 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3556 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3557 gboolean recipient_found = FALSE;
3561 /* free to and newsgroup list */
3562 slist_free_strings(compose->to_list);
3563 g_slist_free(compose->to_list);
3564 compose->to_list = NULL;
3566 slist_free_strings(compose->newsgroup_list);
3567 g_slist_free(compose->newsgroup_list);
3568 compose->newsgroup_list = NULL;
3570 /* search header entries for to and newsgroup entries */
3571 for (list = compose->header_list; list; list = list->next) {
3574 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3575 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3577 if (entry[0] != '\0') {
3578 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3579 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3580 compose->to_list = address_list_append(compose->to_list, entry);
3581 recipient_found = TRUE;
3584 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3585 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3586 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3587 recipient_found = TRUE;
3594 return recipient_found;
3597 static gboolean compose_check_for_set_recipients(Compose *compose)
3599 if (compose->account->set_autocc && compose->account->auto_cc) {
3600 gboolean found_other = FALSE;
3602 /* search header entries for to and newsgroup entries */
3603 for (list = compose->header_list; list; list = list->next) {
3606 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3607 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3609 if (strcmp(entry, compose->account->auto_cc)
3610 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3620 aval = alertpanel(_("Send"),
3621 _("The only recipient is the default CC address. Send anyway?"),
3622 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3623 if (aval != G_ALERTDEFAULT)
3627 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3628 gboolean found_other = FALSE;
3630 /* search header entries for to and newsgroup entries */
3631 for (list = compose->header_list; list; list = list->next) {
3634 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3635 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3637 if (strcmp(entry, compose->account->auto_cc)
3638 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3648 aval = alertpanel(_("Send"),
3649 _("The only recipient is the default BCC address. Send anyway?"),
3650 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3651 if (aval != G_ALERTDEFAULT)
3658 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3662 if (compose_check_for_valid_recipient(compose) == FALSE) {
3663 alertpanel_error(_("Recipient is not specified."));
3667 if (compose_check_for_set_recipients(compose) == FALSE) {
3671 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3672 if (*str == '\0' && check_subject == TRUE) {
3675 aval = alertpanel(_("Send"),
3676 _("Subject is empty. Send it anyway?"),
3677 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3678 if (aval != G_ALERTDEFAULT)
3685 gint compose_send(Compose *compose)
3692 compose_allow_user_actions (compose, FALSE);
3693 compose->sending = TRUE;
3695 if (compose_check_entries(compose, TRUE) == FALSE)
3698 val = compose_queue(compose, &msgnum, &folder);
3702 alertpanel_error(_("Could not queue message for sending:\n\n"
3703 "Charset conversion failed."));
3704 } else if (val == -3) {
3705 alertpanel_error(_("Could not queue message for sending:\n\n"
3706 "Signature failed."));
3707 } else if (val == -2) {
3708 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3710 alertpanel_error(_("Could not queue message for sending."));
3716 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3717 compose->sending = FALSE;
3718 compose_close(compose);
3719 /* No more compose access in the normal codepath
3720 * after this point! */
3725 alertpanel_error(_("The message was queued but could not be "
3726 "sent.\nUse \"Send queued messages\" from "
3727 "the main window to retry."));
3728 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3729 compose->sending = FALSE;
3730 compose_allow_user_actions (compose, TRUE);
3735 msgpath = folder_item_fetch_msg(folder, msgnum);
3736 val = procmsg_send_message_queue(msgpath);
3739 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3740 compose->sending = FALSE;
3741 compose_allow_user_actions (compose, TRUE);
3743 folder_item_remove_msg(folder, msgnum);
3744 folder_item_scan(folder);
3749 folder_item_remove_msg(folder, msgnum);
3750 folder_item_scan(folder);
3751 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3752 compose_close(compose);
3754 alertpanel_error(_("The message was queued but could not be "
3755 "sent.\nUse \"Send queued messages\" from "
3756 "the main window to retry."));
3757 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3758 compose_allow_user_actions (compose, TRUE);
3759 compose->sending = FALSE;
3767 compose_allow_user_actions (compose, TRUE);
3768 compose->sending = FALSE;
3773 static gboolean compose_use_attach(Compose *compose)
3775 GtkTreeModel *model = gtk_tree_view_get_model
3776 (GTK_TREE_VIEW(compose->attach_clist));
3777 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3780 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3783 gchar buf[BUFFSIZE];
3785 gboolean first_to_address;
3786 gboolean first_cc_address;
3788 ComposeHeaderEntry *headerentry;
3789 const gchar *headerentryname;
3793 debug_print("Writing redirect header\n");
3795 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3796 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3798 first_to_address = TRUE;
3799 for (list = compose->header_list; list; list = list->next) {
3800 headerentry = ((ComposeHeaderEntry *)list->data);
3801 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3803 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3804 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3805 Xstrdup_a(str, entstr, return -1);
3807 if (str[0] != '\0') {
3808 compose_convert_header
3809 (compose, buf, sizeof(buf), str,
3810 strlen("Resent-To") + 2, TRUE);
3812 if (first_to_address) {
3813 fprintf(fp, "Resent-To: ");
3814 first_to_address = FALSE;
3818 fprintf(fp, "%s", buf);
3822 if (!first_to_address) {
3826 first_cc_address = TRUE;
3827 for (list = compose->header_list; list; list = list->next) {
3828 headerentry = ((ComposeHeaderEntry *)list->data);
3829 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3831 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3832 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3833 Xstrdup_a(str, strg, return -1);
3835 if (str[0] != '\0') {
3836 compose_convert_header
3837 (compose, buf, sizeof(buf), str,
3838 strlen("Resent-Cc") + 2, TRUE);
3840 if (first_cc_address) {
3841 fprintf(fp, "Resent-Cc: ");
3842 first_cc_address = FALSE;
3846 fprintf(fp, "%s", buf);
3850 if (!first_cc_address) {
3857 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3859 gchar buf[BUFFSIZE];
3861 const gchar *entstr;
3862 /* struct utsname utsbuf; */
3864 g_return_val_if_fail(fp != NULL, -1);
3865 g_return_val_if_fail(compose->account != NULL, -1);
3866 g_return_val_if_fail(compose->account->address != NULL, -1);
3869 get_rfc822_date(buf, sizeof(buf));
3870 fprintf(fp, "Resent-Date: %s\n", buf);
3873 if (compose->account->name && *compose->account->name) {
3874 compose_convert_header
3875 (compose, buf, sizeof(buf), compose->account->name,
3876 strlen("From: "), TRUE);
3877 fprintf(fp, "Resent-From: %s <%s>\n",
3878 buf, compose->account->address);
3880 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3883 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3884 if (*entstr != '\0') {
3885 Xstrdup_a(str, entstr, return -1);
3888 compose_convert_header(compose, buf, sizeof(buf), str,
3889 strlen("Subject: "), FALSE);
3890 fprintf(fp, "Subject: %s\n", buf);
3894 /* Resent-Message-ID */
3895 if (compose->account->gen_msgid) {
3896 generate_msgid(buf, sizeof(buf));
3897 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3898 compose->msgid = g_strdup(buf);
3901 compose_redirect_write_headers_from_headerlist(compose, fp);
3903 /* separator between header and body */
3909 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3913 gchar buf[BUFFSIZE];
3915 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
3916 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3920 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3921 /* should filter returnpath, delivered-to */
3922 if (g_ascii_strncasecmp(buf, "Return-Path:",
3923 strlen("Return-Path:")) == 0 ||
3924 g_ascii_strncasecmp(buf, "Delivered-To:",
3925 strlen("Delivered-To:")) == 0 ||
3926 g_ascii_strncasecmp(buf, "Received:",
3927 strlen("Received:")) == 0 ||
3928 g_ascii_strncasecmp(buf, "Subject:",
3929 strlen("Subject:")) == 0 ||
3930 g_ascii_strncasecmp(buf, "X-UIDL:",
3931 strlen("X-UIDL:")) == 0)
3934 if (fputs(buf, fdest) == -1)
3937 if (!prefs_common.redirect_keep_from) {
3938 if (g_ascii_strncasecmp(buf, "From:",
3939 strlen("From:")) == 0) {
3940 fputs(" (by way of ", fdest);
3941 if (compose->account->name
3942 && *compose->account->name) {
3943 compose_convert_header
3944 (compose, buf, sizeof(buf),
3945 compose->account->name,
3948 fprintf(fdest, "%s <%s>",
3950 compose->account->address);
3952 fprintf(fdest, "%s",
3953 compose->account->address);
3958 if (fputs("\n", fdest) == -1)
3962 compose_redirect_write_headers(compose, fdest);
3964 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3965 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
3978 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
3980 GtkTextBuffer *buffer;
3981 GtkTextIter start, end;
3984 const gchar *out_codeset;
3985 EncodingType encoding;
3986 MimeInfo *mimemsg, *mimetext;
3989 /* create message MimeInfo */
3990 mimemsg = procmime_mimeinfo_new();
3991 mimemsg->type = MIMETYPE_MESSAGE;
3992 mimemsg->subtype = g_strdup("rfc822");
3993 mimemsg->content = MIMECONTENT_MEM;
3994 mimemsg->data.mem = compose_get_header(compose);
3996 /* Create text part MimeInfo */
3997 /* get all composed text */
3998 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
3999 gtk_text_buffer_get_start_iter(buffer, &start);
4000 gtk_text_buffer_get_end_iter(buffer, &end);
4001 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4002 if (is_ascii_str(chars)) {
4005 out_codeset = CS_US_ASCII;
4006 encoding = ENC_7BIT;
4008 const gchar *src_codeset = CS_INTERNAL;
4010 out_codeset = conv_get_charset_str(compose->out_encoding);
4013 gchar *test_conv_global_out = NULL;
4014 gchar *test_conv_reply = NULL;
4016 /* automatic mode. be automatic. */
4017 codeconv_set_strict(TRUE);
4019 out_codeset = conv_get_outgoing_charset_str();
4021 debug_print("trying to convert to %s\n", out_codeset);
4022 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4025 if (!test_conv_global_out && compose->orig_charset) {
4026 out_codeset = compose->orig_charset;
4027 debug_print("failure; trying to convert to %s\n", out_codeset);
4028 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4031 if (!test_conv_global_out && !test_conv_reply) {
4033 out_codeset = CS_INTERNAL;
4034 debug_print("finally using %s\n", out_codeset);
4036 g_free(test_conv_global_out);
4037 g_free(test_conv_reply);
4038 codeconv_set_strict(FALSE);
4041 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4042 out_codeset = CS_ISO_8859_1;
4044 if (prefs_common.encoding_method == CTE_BASE64)
4045 encoding = ENC_BASE64;
4046 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4047 encoding = ENC_QUOTED_PRINTABLE;
4048 else if (prefs_common.encoding_method == CTE_8BIT)
4049 encoding = ENC_8BIT;
4051 encoding = procmime_get_encoding_for_charset(out_codeset);
4053 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4054 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4056 if (action == COMPOSE_WRITE_FOR_SEND) {
4057 codeconv_set_strict(TRUE);
4058 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4059 codeconv_set_strict(FALSE);
4065 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4066 "to the specified %s charset.\n"
4067 "Send it as %s?"), out_codeset, src_codeset);
4068 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_YES, GTK_STOCK_NO, NULL, FALSE,
4069 NULL, ALERT_ERROR, G_ALERTALTERNATE);
4072 if (aval != G_ALERTDEFAULT) {
4077 out_codeset = src_codeset;
4083 out_codeset = src_codeset;
4089 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4090 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4091 strstr(buf, "\nFrom ") != NULL) {
4092 encoding = ENC_QUOTED_PRINTABLE;
4096 mimetext = procmime_mimeinfo_new();
4097 mimetext->content = MIMECONTENT_MEM;
4098 mimetext->data.mem = buf;
4099 mimetext->type = MIMETYPE_TEXT;
4100 mimetext->subtype = g_strdup("plain");
4101 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4102 g_strdup(out_codeset));
4103 /* protect trailing spaces when signing message */
4104 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4105 privacy_system_can_sign(compose->privacy_system)) {
4106 encoding = ENC_QUOTED_PRINTABLE;
4109 /* check for line length limit */
4110 if (action == COMPOSE_WRITE_FOR_SEND &&
4111 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4112 check_line_length(buf, 1000, &line) < 0) {
4116 msg = g_strdup_printf
4117 (_("Line %d exceeds the line length limit (998 bytes).\n"
4118 "The contents of the message might be broken on the way to the delivery.\n"
4120 "Send it anyway?"), line + 1);
4121 aval = alertpanel(_("Warning"), msg, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
4123 if (aval != G_ALERTDEFAULT) {
4128 if (encoding != ENC_UNKNOWN)
4129 procmime_encode_content(mimetext, encoding);
4131 /* append attachment parts */
4132 if (compose_use_attach(compose)) {
4133 MimeInfo *mimempart;
4134 gchar *boundary = NULL;
4135 mimempart = procmime_mimeinfo_new();
4136 mimempart->content = MIMECONTENT_EMPTY;
4137 mimempart->type = MIMETYPE_MULTIPART;
4138 mimempart->subtype = g_strdup("mixed");
4143 boundary = generate_mime_boundary(NULL);
4144 } while (strstr(buf, boundary) != NULL);
4146 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4149 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4151 g_node_append(mimempart->node, mimetext->node);
4152 g_node_append(mimemsg->node, mimempart->node);
4154 compose_add_attachments(compose, mimempart);
4156 g_node_append(mimemsg->node, mimetext->node);
4158 /* sign message if sending */
4159 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4160 privacy_system_can_sign(compose->privacy_system))
4161 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4164 procmime_write_mimeinfo(mimemsg, fp);
4166 procmime_mimeinfo_free_all(mimemsg);
4171 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4173 GtkTextBuffer *buffer;
4174 GtkTextIter start, end;
4179 if ((fp = g_fopen(file, "wb")) == NULL) {
4180 FILE_OP_ERROR(file, "fopen");
4184 /* chmod for security */
4185 if (change_file_mode_rw(fp, file) < 0) {
4186 FILE_OP_ERROR(file, "chmod");
4187 g_warning("can't change file mode\n");
4190 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4191 gtk_text_buffer_get_start_iter(buffer, &start);
4192 gtk_text_buffer_get_end_iter(buffer, &end);
4193 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4195 chars = conv_codeset_strdup
4196 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4199 if (!chars) return -1;
4202 len = strlen(chars);
4203 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4204 FILE_OP_ERROR(file, "fwrite");
4213 if (fclose(fp) == EOF) {
4214 FILE_OP_ERROR(file, "fclose");
4221 static gint compose_remove_reedit_target(Compose *compose)
4224 MsgInfo *msginfo = compose->targetinfo;
4226 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4227 if (!msginfo) return -1;
4229 item = msginfo->folder;
4230 g_return_val_if_fail(item != NULL, -1);
4232 if (procmsg_msg_exist(msginfo) &&
4233 (folder_has_parent_of_type(item, F_QUEUE) ||
4234 folder_has_parent_of_type(item, F_DRAFT)
4235 || msginfo == compose->autosaved_draft)) {
4236 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4237 g_warning("can't remove the old message\n");
4245 void compose_remove_draft(Compose *compose)
4248 MsgInfo *msginfo = compose->targetinfo;
4249 drafts = account_get_special_folder(compose->account, F_DRAFT);
4251 if (procmsg_msg_exist(msginfo)) {
4252 folder_item_remove_msg(drafts, msginfo->msgnum);
4257 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
4259 return compose_queue_sub (compose, msgnum, item, FALSE);
4261 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
4268 static gboolean lock = FALSE;
4269 PrefsAccount *mailac = NULL, *newsac = NULL;
4271 debug_print("queueing message...\n");
4272 g_return_val_if_fail(compose->account != NULL, -1);
4276 if (compose_check_entries(compose, check_subject) == FALSE) {
4281 if (!compose->to_list && !compose->newsgroup_list) {
4282 g_warning("can't get recipient list.");
4287 if (compose->to_list) {
4288 if (compose->account->protocol != A_NNTP)
4289 mailac = compose->account;
4290 else if (cur_account && cur_account->protocol != A_NNTP)
4291 mailac = cur_account;
4292 else if (!(mailac = compose_current_mail_account())) {
4294 alertpanel_error(_("No account for sending mails available!"));
4299 if (compose->newsgroup_list) {
4300 if (compose->account->protocol == A_NNTP)
4301 newsac = compose->account;
4302 else if (!newsac->protocol != A_NNTP) {
4304 alertpanel_error(_("No account for posting news available!"));
4309 if (prefs_common.linewrap_at_send)
4310 compose_wrap_all(compose);
4312 /* write queue header */
4313 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4314 G_DIR_SEPARATOR, compose);
4315 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4316 FILE_OP_ERROR(tmp, "fopen");
4321 if (change_file_mode_rw(fp, tmp) < 0) {
4322 FILE_OP_ERROR(tmp, "chmod");
4323 g_warning("can't change file mode\n");
4326 /* queueing variables */
4327 fprintf(fp, "AF:\n");
4328 fprintf(fp, "NF:0\n");
4329 fprintf(fp, "PS:10\n");
4330 fprintf(fp, "SRH:1\n");
4331 fprintf(fp, "SFN:\n");
4332 fprintf(fp, "DSR:\n");
4334 fprintf(fp, "MID:<%s>\n", compose->msgid);
4336 fprintf(fp, "MID:\n");
4337 fprintf(fp, "CFG:\n");
4338 fprintf(fp, "PT:0\n");
4339 fprintf(fp, "S:%s\n", compose->account->address);
4340 fprintf(fp, "RQ:\n");
4342 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4344 fprintf(fp, "SSV:\n");
4346 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4348 fprintf(fp, "NSV:\n");
4349 fprintf(fp, "SSH:\n");
4350 /* write recepient list */
4351 if (compose->to_list) {
4352 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4353 for (cur = compose->to_list->next; cur != NULL;
4355 fprintf(fp, ",<%s>", (gchar *)cur->data);
4358 /* write newsgroup list */
4359 if (compose->newsgroup_list) {
4361 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4362 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4363 fprintf(fp, ",%s", (gchar *)cur->data);
4366 /* Sylpheed account IDs */
4368 fprintf(fp, "MAID:%d\n", mailac->account_id);
4370 fprintf(fp, "NAID:%d\n", newsac->account_id);
4372 if (compose->privacy_system != NULL) {
4373 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4374 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4375 if (compose->use_encryption) {
4378 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4379 if (encdata != NULL) {
4380 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4381 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4382 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4384 } /* else we finally dont want to encrypt */
4386 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4387 /* and if encdata was null, it means there's been a problem in
4394 /* Save copy folder */
4395 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4396 gchar *savefolderid;
4398 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4399 fprintf(fp, "SCF:%s\n", savefolderid);
4400 g_free(savefolderid);
4402 /* Save copy folder */
4403 if (compose->return_receipt) {
4404 fprintf(fp, "RRCPT:1\n");
4406 /* Message-ID of message replying to */
4407 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4410 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4411 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4414 /* Message-ID of message forwarding to */
4415 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4418 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4419 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4424 if (compose->redirect_filename != NULL) {
4425 if (compose_redirect_write_to_file(compose, fp) < 0) {
4434 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4439 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4443 if (fclose(fp) == EOF) {
4444 FILE_OP_ERROR(tmp, "fclose");
4450 queue = account_get_special_folder(compose->account, F_QUEUE);
4452 g_warning("can't find queue folder\n");
4457 folder_item_scan(queue);
4458 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
4459 g_warning("can't queue the message\n");
4467 if (compose->mode == COMPOSE_REEDIT) {
4468 compose_remove_reedit_target(compose);
4471 if ((msgnum != NULL) && (item != NULL)) {
4479 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4482 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4484 struct stat statbuf;
4485 gchar *type, *subtype;
4486 GtkTreeModel *model;
4489 model = gtk_tree_view_get_model(tree_view);
4491 if (!gtk_tree_model_get_iter_first(model, &iter))
4494 gtk_tree_model_get(model, &iter,
4498 mimepart = procmime_mimeinfo_new();
4499 mimepart->content = MIMECONTENT_FILE;
4500 mimepart->data.filename = g_strdup(ainfo->file);
4501 mimepart->offset = 0;
4503 stat(ainfo->file, &statbuf);
4504 mimepart->length = statbuf.st_size;
4506 type = g_strdup(ainfo->content_type);
4508 if (!strchr(type, '/')) {
4510 type = g_strdup("application/octet-stream");
4513 subtype = strchr(type, '/') + 1;
4514 *(subtype - 1) = '\0';
4515 mimepart->type = procmime_get_media_type(type);
4516 mimepart->subtype = g_strdup(subtype);
4519 if (mimepart->type == MIMETYPE_MESSAGE &&
4520 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4521 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4523 g_hash_table_insert(mimepart->typeparameters,
4524 g_strdup("name"), g_strdup(ainfo->name));
4525 g_hash_table_insert(mimepart->dispositionparameters,
4526 g_strdup("filename"), g_strdup(ainfo->name));
4527 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4530 if (compose->use_signing) {
4531 if (ainfo->encoding == ENC_7BIT)
4532 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4533 else if (ainfo->encoding == ENC_8BIT)
4534 ainfo->encoding = ENC_BASE64;
4537 procmime_encode_content(mimepart, ainfo->encoding);
4539 g_node_append(parent->node, mimepart->node);
4540 } while (gtk_tree_model_iter_next(model, &iter));
4543 #define QUOTE_IF_REQUIRED(out, str) \
4545 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4549 len = strlen(str) + 3; \
4550 if ((__tmp = alloca(len)) == NULL) { \
4551 g_warning("can't allocate memory\n"); \
4552 g_string_free(header, TRUE); \
4555 g_snprintf(__tmp, len, "\"%s\"", str); \
4560 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4561 g_warning("can't allocate memory\n"); \
4562 g_string_free(header, TRUE); \
4565 strcpy(__tmp, str); \
4571 #define IS_IN_CUSTOM_HEADER(header) \
4572 (compose->account->add_customhdr && \
4573 custom_header_find(compose->account->customhdr_list, header) != NULL)
4575 static void compose_add_headerfield_from_headerlist(Compose *compose,
4577 const gchar *fieldname,
4578 const gchar *seperator)
4580 gchar *str, *fieldname_w_colon, *trans_fieldname;
4581 gboolean add_field = FALSE;
4583 ComposeHeaderEntry *headerentry;
4584 const gchar * headerentryname;
4587 if (IS_IN_CUSTOM_HEADER(fieldname))
4590 debug_print("Adding %s-fields\n", fieldname);
4592 fieldstr = g_string_sized_new(64);
4594 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4595 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4597 for (list = compose->header_list; list; list = list->next) {
4598 headerentry = ((ComposeHeaderEntry *)list->data);
4599 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4601 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4602 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4604 if (str[0] != '\0') {
4606 g_string_append(fieldstr, seperator);
4607 g_string_append(fieldstr, str);
4616 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4617 compose_convert_header
4618 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4619 strlen(fieldname) + 2, TRUE);
4620 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4624 g_free(fieldname_w_colon);
4625 g_string_free(fieldstr, TRUE);
4630 static gchar *compose_get_header(Compose *compose)
4632 gchar buf[BUFFSIZE];
4633 const gchar *entry_str;
4637 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4640 g_return_val_if_fail(compose->account != NULL, NULL);
4641 g_return_val_if_fail(compose->account->address != NULL, NULL);
4643 header = g_string_sized_new(64);
4646 if (compose->account->add_date) {
4647 get_rfc822_date(buf, sizeof(buf));
4648 g_string_append_printf(header, "Date: %s\n", buf);
4652 if (compose->account->name && *compose->account->name) {
4653 compose_convert_header
4654 (compose, buf, sizeof(buf), compose->account->name,
4655 strlen("From: "), TRUE);
4656 QUOTE_IF_REQUIRED(name, buf);
4657 g_string_append_printf(header, "From: %s <%s>\n",
4658 name, compose->account->address);
4660 g_string_append_printf(header, "From: %s\n", compose->account->address);
4663 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4666 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4669 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4672 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4675 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4677 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4680 compose_convert_header(compose, buf, sizeof(buf), str,
4681 strlen("Subject: "), FALSE);
4682 g_string_append_printf(header, "Subject: %s\n", buf);
4688 if (compose->account->gen_msgid) {
4689 generate_msgid(buf, sizeof(buf));
4690 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4691 compose->msgid = g_strdup(buf);
4694 if (compose->remove_references == FALSE) {
4696 if (compose->inreplyto && compose->to_list)
4697 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4700 if (compose->references)
4701 g_string_append_printf(header, "References: %s\n", compose->references);
4705 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4708 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4711 if (compose->account->organization &&
4712 strlen(compose->account->organization) &&
4713 !IS_IN_CUSTOM_HEADER("Organization")) {
4714 compose_convert_header(compose, buf, sizeof(buf),
4715 compose->account->organization,
4716 strlen("Organization: "), FALSE);
4717 g_string_append_printf(header, "Organization: %s\n", buf);
4720 /* Program version and system info */
4721 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4722 !compose->newsgroup_list) {
4723 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4725 gtk_major_version, gtk_minor_version, gtk_micro_version,
4728 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4729 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4731 gtk_major_version, gtk_minor_version, gtk_micro_version,
4735 /* custom headers */
4736 if (compose->account->add_customhdr) {
4739 for (cur = compose->account->customhdr_list; cur != NULL;
4741 CustomHeader *chdr = (CustomHeader *)cur->data;
4743 if (custom_header_is_allowed(chdr->name)) {
4744 compose_convert_header
4745 (compose, buf, sizeof(buf),
4746 chdr->value ? chdr->value : "",
4747 strlen(chdr->name) + 2, FALSE);
4748 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4754 switch (compose->priority) {
4755 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4756 "X-Priority: 1 (Highest)\n");
4758 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4759 "X-Priority: 2 (High)\n");
4761 case PRIORITY_NORMAL: break;
4762 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4763 "X-Priority: 4 (Low)\n");
4765 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4766 "X-Priority: 5 (Lowest)\n");
4768 default: debug_print("compose: priority unknown : %d\n",
4772 /* Request Return Receipt */
4773 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4774 if (compose->return_receipt) {
4775 if (compose->account->name
4776 && *compose->account->name) {
4777 compose_convert_header(compose, buf, sizeof(buf),
4778 compose->account->name,
4779 strlen("Disposition-Notification-To: "),
4781 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4783 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4787 /* get special headers */
4788 for (list = compose->header_list; list; list = list->next) {
4789 ComposeHeaderEntry *headerentry;
4792 gchar *headername_wcolon;
4793 gchar *headername_trans;
4796 gboolean standard_header = FALSE;
4798 headerentry = ((ComposeHeaderEntry *)list->data);
4800 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4801 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4806 if (!strstr(tmp, ":")) {
4807 headername_wcolon = g_strconcat(tmp, ":", NULL);
4808 headername = g_strdup(tmp);
4810 headername_wcolon = g_strdup(tmp);
4811 headername = g_strdup(strtok(tmp, ":"));
4815 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4816 Xstrdup_a(headervalue, entry_str, return NULL);
4817 subst_char(headervalue, '\r', ' ');
4818 subst_char(headervalue, '\n', ' ');
4819 string = std_headers;
4820 while (*string != NULL) {
4821 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4822 if (!strcmp(headername_trans,headername_wcolon))
4823 standard_header = TRUE;
4826 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4827 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
4830 g_free(headername_wcolon);
4834 g_string_free(header, FALSE);
4839 #undef IS_IN_CUSTOM_HEADER
4841 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
4842 gint header_len, gboolean addr_field)
4844 gchar *tmpstr = NULL;
4845 const gchar *out_codeset = NULL;
4847 g_return_if_fail(src != NULL);
4848 g_return_if_fail(dest != NULL);
4850 if (len < 1) return;
4852 tmpstr = g_strdup(src);
4854 subst_char(tmpstr, '\n', ' ');
4855 subst_char(tmpstr, '\r', ' ');
4858 if (!g_utf8_validate(tmpstr, -1, NULL)) {
4859 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
4860 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
4865 codeconv_set_strict(TRUE);
4866 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4867 conv_get_charset_str(compose->out_encoding));
4868 codeconv_set_strict(FALSE);
4870 if (!dest || *dest == '\0') {
4871 gchar *test_conv_global_out = NULL;
4872 gchar *test_conv_reply = NULL;
4874 /* automatic mode. be automatic. */
4875 codeconv_set_strict(TRUE);
4877 out_codeset = conv_get_outgoing_charset_str();
4879 debug_print("trying to convert to %s\n", out_codeset);
4880 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4883 if (!test_conv_global_out && compose->orig_charset) {
4884 out_codeset = compose->orig_charset;
4885 debug_print("failure; trying to convert to %s\n", out_codeset);
4886 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4889 if (!test_conv_global_out && !test_conv_reply) {
4891 out_codeset = CS_INTERNAL;
4892 debug_print("finally using %s\n", out_codeset);
4894 g_free(test_conv_global_out);
4895 g_free(test_conv_reply);
4896 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4898 codeconv_set_strict(FALSE);
4903 static void compose_create_header_entry(Compose *compose)
4905 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4909 GList *combo_list = NULL;
4911 const gchar *header = NULL;
4912 ComposeHeaderEntry *headerentry;
4913 gboolean standard_header = FALSE;
4915 headerentry = g_new0(ComposeHeaderEntry, 1);
4918 combo = gtk_combo_new();
4920 while(*string != NULL) {
4921 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4924 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4925 g_list_free(combo_list);
4926 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4927 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4928 G_CALLBACK(compose_grab_focus_cb), compose);
4929 gtk_widget_show(combo);
4930 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4931 if (compose->header_last) {
4932 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4934 while (*string != NULL) {
4935 if (!strcmp(*string, last_header_entry))
4936 standard_header = TRUE;
4939 if (standard_header)
4940 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4942 if (!compose->header_last || !standard_header) {
4943 switch(compose->account->protocol) {
4945 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4948 header = prefs_common.trans_hdr ? _("To:") : "To:";
4953 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4955 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4956 G_CALLBACK(compose_grab_focus_cb), compose);
4959 entry = gtk_entry_new();
4960 gtk_widget_show(entry);
4961 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);
4963 g_signal_connect(G_OBJECT(entry), "key-press-event",
4964 G_CALLBACK(compose_headerentry_key_press_event_cb),
4966 g_signal_connect(G_OBJECT(entry), "changed",
4967 G_CALLBACK(compose_headerentry_changed_cb),
4969 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
4970 G_CALLBACK(compose_grab_focus_cb), compose);
4973 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
4974 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
4975 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4976 g_signal_connect(G_OBJECT(entry), "drag_data_received",
4977 G_CALLBACK(compose_header_drag_received_cb),
4979 g_signal_connect(G_OBJECT(entry), "drag-drop",
4980 G_CALLBACK(compose_drag_drop),
4983 address_completion_register_entry(GTK_ENTRY(entry));
4985 headerentry->compose = compose;
4986 headerentry->combo = combo;
4987 headerentry->entry = entry;
4988 headerentry->headernum = compose->header_nextrow;
4990 compose->header_nextrow++;
4991 compose->header_last = headerentry;
4994 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4996 ComposeHeaderEntry *last_header;
4998 last_header = compose->header_last;
5000 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5001 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5004 static GtkWidget *compose_create_header(Compose *compose)
5008 GtkWidget *from_optmenu_hbox;
5009 GtkWidget *header_scrolledwin;
5010 GtkWidget *header_table;
5014 /* header labels and entries */
5015 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5016 gtk_widget_show(header_scrolledwin);
5017 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5019 header_table = gtk_table_new(2, 2, FALSE);
5020 gtk_widget_show(header_table);
5021 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
5022 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5023 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5026 /* option menu for selecting accounts */
5027 hbox = gtk_hbox_new(FALSE, 0);
5028 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
5029 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
5030 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
5032 from_optmenu_hbox = compose_account_option_menu_create(compose);
5033 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5034 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5037 compose->header_table = header_table;
5038 compose->header_list = NULL;
5039 compose->header_nextrow = count;
5041 compose_create_header_entry(compose);
5043 compose->table = NULL;
5045 return header_scrolledwin ;
5048 GtkWidget *compose_create_attach(Compose *compose)
5050 GtkWidget *attach_scrwin;
5051 GtkWidget *attach_clist;
5053 GtkListStore *store;
5054 GtkCellRenderer *renderer;
5055 GtkTreeViewColumn *column;
5056 GtkTreeSelection *selection;
5058 /* attachment list */
5059 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5060 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5061 GTK_POLICY_AUTOMATIC,
5062 GTK_POLICY_AUTOMATIC);
5063 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5065 store = gtk_list_store_new(N_ATTACH_COLS,
5070 G_TYPE_AUTO_POINTER,
5072 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5073 (GTK_TREE_MODEL(store)));
5074 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5075 g_object_unref(store);
5077 renderer = gtk_cell_renderer_text_new();
5078 column = gtk_tree_view_column_new_with_attributes
5079 (_("Mime type"), renderer, "text",
5080 COL_MIMETYPE, NULL);
5081 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5083 renderer = gtk_cell_renderer_text_new();
5084 column = gtk_tree_view_column_new_with_attributes
5085 (_("Size"), renderer, "text",
5087 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5089 renderer = gtk_cell_renderer_text_new();
5090 column = gtk_tree_view_column_new_with_attributes
5091 (_("Name"), renderer, "text",
5093 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5095 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5096 prefs_common.enable_rules_hint);
5097 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5098 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5100 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5101 G_CALLBACK(attach_selected), compose);
5102 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5103 G_CALLBACK(attach_button_pressed), compose);
5104 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5105 G_CALLBACK(attach_key_pressed), compose);
5108 gtk_drag_dest_set(attach_clist,
5109 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5110 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5111 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5112 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5113 G_CALLBACK(compose_attach_drag_received_cb),
5115 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5116 G_CALLBACK(compose_drag_drop),
5119 compose->attach_scrwin = attach_scrwin;
5120 compose->attach_clist = attach_clist;
5122 return attach_scrwin;
5125 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5126 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5128 static GtkWidget *compose_create_others(Compose *compose)
5131 GtkWidget *savemsg_checkbtn;
5132 GtkWidget *savemsg_entry;
5133 GtkWidget *savemsg_select;
5136 gchar *folderidentifier;
5138 /* Table for settings */
5139 table = gtk_table_new(3, 1, FALSE);
5140 gtk_widget_show(table);
5141 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5144 /* Save Message to folder */
5145 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5146 gtk_widget_show(savemsg_checkbtn);
5147 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5148 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5149 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5151 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5152 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5154 savemsg_entry = gtk_entry_new();
5155 gtk_widget_show(savemsg_entry);
5156 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5157 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5158 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5159 G_CALLBACK(compose_grab_focus_cb), compose);
5160 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5161 folderidentifier = folder_item_get_identifier(account_get_special_folder
5162 (compose->account, F_OUTBOX));
5163 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5164 g_free(folderidentifier);
5167 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5168 gtk_widget_show(savemsg_select);
5169 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5170 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5171 G_CALLBACK(compose_savemsg_select_cb),
5176 compose->savemsg_checkbtn = savemsg_checkbtn;
5177 compose->savemsg_entry = savemsg_entry;
5182 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5184 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5185 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5188 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5193 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5196 path = folder_item_get_identifier(dest);
5198 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5202 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5205 #define BLOCK_WRAP() { \
5206 prev_autowrap = compose->autowrap; \
5207 buffer = gtk_text_view_get_buffer( \
5208 GTK_TEXT_VIEW(compose->text)); \
5209 compose->autowrap = FALSE; \
5211 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5212 G_CALLBACK(compose_changed_cb), \
5214 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5215 G_CALLBACK(text_inserted), \
5218 #define UNBLOCK_WRAP() { \
5219 compose->autowrap = prev_autowrap; \
5220 if (compose->autowrap) \
5221 compose_wrap_all(compose); \
5223 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5224 G_CALLBACK(compose_changed_cb), \
5226 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5227 G_CALLBACK(text_inserted), \
5232 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5236 GtkTextBuffer *buffer;
5238 if (event->button == 3) {
5241 /* move the cursor to allow GtkAspell to check the word
5242 * under the mouse */
5243 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5244 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5246 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5248 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5249 return FALSE; /* pass the event so that the right-click goes through */
5252 if (event->button == 2) {
5254 entry_paste_clipboard(compose, compose->focused_editable,
5255 prefs_common.linewrap_pastes,
5256 GDK_SELECTION_PRIMARY);
5263 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
5269 GtkWidget *handlebox;
5271 GtkWidget *notebook;
5276 GtkWidget *subject_hbox;
5277 GtkWidget *subject_frame;
5278 GtkWidget *subject_entry;
5282 GtkWidget *edit_vbox;
5283 GtkWidget *ruler_hbox;
5285 GtkWidget *scrolledwin;
5287 GtkTextBuffer *buffer;
5288 GtkClipboard *clipboard;
5290 UndoMain *undostruct;
5292 gchar *titles[N_ATTACH_COLS];
5293 guint n_menu_entries;
5296 gboolean success[1];
5297 GtkWidget *popupmenu;
5298 GtkItemFactory *popupfactory;
5299 GtkItemFactory *ifactory;
5300 GtkWidget *tmpl_menu;
5302 GtkWidget *menuitem;
5305 GtkAspell * gtkaspell = NULL;
5308 static GdkGeometry geometry;
5310 g_return_val_if_fail(account != NULL, NULL);
5312 debug_print("Creating compose window...\n");
5313 compose = g_new0(Compose, 1);
5315 titles[COL_MIMETYPE] = _("MIME type");
5316 titles[COL_SIZE] = _("Size");
5317 titles[COL_NAME] = _("Name");
5319 compose->account = account;
5321 compose->mutex = g_mutex_new();
5322 compose->set_cursor_pos = -1;
5324 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5325 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5326 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5328 if (!geometry.max_width) {
5329 geometry.max_width = gdk_screen_width();
5330 geometry.max_height = gdk_screen_height();
5333 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5334 &geometry, GDK_HINT_MAX_SIZE);
5335 if (!geometry.min_width) {
5336 geometry.min_width = 600;
5337 geometry.min_height = 480;
5339 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5340 &geometry, GDK_HINT_MIN_SIZE);
5341 gtk_widget_set_uposition(window, prefs_common.compose_x,
5342 prefs_common.compose_y);
5344 g_signal_connect(G_OBJECT(window), "delete_event",
5345 G_CALLBACK(compose_delete_cb), compose);
5346 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5347 gtk_widget_realize(window);
5349 gtkut_widget_set_composer_icon(window);
5351 vbox = gtk_vbox_new(FALSE, 0);
5352 gtk_container_add(GTK_CONTAINER(window), vbox);
5354 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5355 menubar = menubar_create(window, compose_entries,
5356 n_menu_entries, "<Compose>", compose);
5357 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5359 if (prefs_common.toolbar_detachable) {
5360 handlebox = gtk_handle_box_new();
5362 handlebox = gtk_hbox_new(FALSE, 0);
5364 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5366 gtk_widget_realize(handlebox);
5367 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5370 vbox2 = gtk_vbox_new(FALSE, 2);
5371 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5372 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5375 notebook = gtk_notebook_new();
5376 gtk_widget_set_size_request(notebook, -1, 130);
5377 gtk_widget_show(notebook);
5379 /* header labels and entries */
5380 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
5381 /* attachment list */
5382 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
5384 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
5387 subject_hbox = gtk_hbox_new(FALSE, 0);
5388 gtk_widget_show(subject_hbox);
5390 subject_frame = gtk_frame_new(NULL);
5391 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5392 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5393 gtk_widget_show(subject_frame);
5395 subject = gtk_hbox_new(FALSE, 0);
5396 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5397 gtk_widget_show(subject);
5399 label = gtk_label_new(_("Subject:"));
5400 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5401 gtk_widget_show(label);
5403 subject_entry = gtk_entry_new();
5404 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5405 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5406 G_CALLBACK(compose_grab_focus_cb), compose);
5407 gtk_widget_show(subject_entry);
5408 compose->subject_entry = subject_entry;
5409 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5411 edit_vbox = gtk_vbox_new(FALSE, 0);
5413 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5416 ruler_hbox = gtk_hbox_new(FALSE, 0);
5417 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5419 ruler = gtk_shruler_new();
5420 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5421 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5425 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5426 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5427 GTK_POLICY_AUTOMATIC,
5428 GTK_POLICY_AUTOMATIC);
5429 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5431 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5432 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5434 text = gtk_text_view_new();
5435 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5436 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5437 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5438 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5439 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5441 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5443 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5444 G_CALLBACK(compose_edit_size_alloc),
5446 g_signal_connect(G_OBJECT(buffer), "changed",
5447 G_CALLBACK(compose_changed_cb), compose);
5448 g_signal_connect(G_OBJECT(text), "grab_focus",
5449 G_CALLBACK(compose_grab_focus_cb), compose);
5450 g_signal_connect(G_OBJECT(buffer), "insert_text",
5451 G_CALLBACK(text_inserted), compose);
5452 g_signal_connect(G_OBJECT(text), "button_press_event",
5453 G_CALLBACK(text_clicked), compose);
5456 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5457 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5458 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5459 g_signal_connect(G_OBJECT(text), "drag_data_received",
5460 G_CALLBACK(compose_insert_drag_received_cb),
5462 g_signal_connect(G_OBJECT(text), "drag-drop",
5463 G_CALLBACK(compose_drag_drop),
5465 gtk_widget_show_all(vbox);
5467 /* pane between attach clist and text */
5468 paned = gtk_vpaned_new();
5469 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5470 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5471 gtk_paned_add1(GTK_PANED(paned), notebook);
5472 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5473 gtk_widget_show_all(paned);
5476 if (prefs_common.textfont) {
5477 PangoFontDescription *font_desc;
5479 font_desc = pango_font_description_from_string
5480 (prefs_common.textfont);
5482 gtk_widget_modify_font(text, font_desc);
5483 pango_font_description_free(font_desc);
5487 color[0] = quote_color;
5488 cmap = gdk_drawable_get_colormap(window->window);
5489 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5490 if (success[0] == FALSE) {
5493 g_warning("Compose: color allocation failed.\n");
5494 style = gtk_widget_get_style(text);
5495 quote_color = style->black;
5498 n_entries = sizeof(compose_popup_entries) /
5499 sizeof(compose_popup_entries[0]);
5500 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5501 "<Compose>", &popupfactory,
5504 ifactory = gtk_item_factory_from_widget(menubar);
5505 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5506 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5507 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5509 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5511 undostruct = undo_init(text);
5512 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5515 address_completion_start(window);
5517 compose->window = window;
5518 compose->vbox = vbox;
5519 compose->menubar = menubar;
5520 compose->handlebox = handlebox;
5522 compose->vbox2 = vbox2;
5524 compose->paned = paned;
5526 compose->edit_vbox = edit_vbox;
5527 compose->ruler_hbox = ruler_hbox;
5528 compose->ruler = ruler;
5529 compose->scrolledwin = scrolledwin;
5530 compose->text = text;
5532 compose->focused_editable = NULL;
5534 compose->popupmenu = popupmenu;
5535 compose->popupfactory = popupfactory;
5537 compose->tmpl_menu = tmpl_menu;
5539 compose->mode = mode;
5541 compose->targetinfo = NULL;
5542 compose->replyinfo = NULL;
5543 compose->fwdinfo = NULL;
5545 compose->replyto = NULL;
5547 compose->bcc = NULL;
5548 compose->followup_to = NULL;
5550 compose->ml_post = NULL;
5552 compose->inreplyto = NULL;
5553 compose->references = NULL;
5554 compose->msgid = NULL;
5555 compose->boundary = NULL;
5557 compose->autowrap = prefs_common.autowrap;
5559 compose->use_signing = FALSE;
5560 compose->use_encryption = FALSE;
5561 compose->privacy_system = NULL;
5563 compose->modified = FALSE;
5565 compose->return_receipt = FALSE;
5567 compose->to_list = NULL;
5568 compose->newsgroup_list = NULL;
5570 compose->undostruct = undostruct;
5572 compose->sig_str = NULL;
5574 compose->exteditor_file = NULL;
5575 compose->exteditor_pid = -1;
5576 compose->exteditor_tag = -1;
5577 compose->draft_timeout_tag = -1;
5580 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5581 if (mode != COMPOSE_REDIRECT) {
5582 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5583 strcmp(prefs_common.dictionary, _("None"))) {
5584 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5585 prefs_common.dictionary,
5586 conv_get_locale_charset_str(),
5587 prefs_common.misspelled_col,
5588 prefs_common.check_while_typing,
5589 prefs_common.use_alternate,
5590 GTK_TEXT_VIEW(text),
5591 GTK_WINDOW(compose->window));
5593 alertpanel_error(_("Spell checker could not "
5595 gtkaspell_checkers_strerror());
5596 gtkaspell_checkers_reset_error();
5598 if (!gtkaspell_set_sug_mode(gtkaspell,
5599 prefs_common.aspell_sugmode)) {
5600 debug_print("Aspell: could not set "
5601 "suggestion mode %s\n",
5602 gtkaspell_checkers_strerror());
5603 gtkaspell_checkers_reset_error();
5606 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5610 compose->gtkaspell = gtkaspell;
5613 compose_select_account(compose, account, TRUE);
5615 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5616 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5617 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5619 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5620 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5622 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5623 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5626 if (account->protocol != A_NNTP)
5627 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5629 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5631 addressbook_set_target_compose(compose);
5633 if (mode != COMPOSE_REDIRECT)
5634 compose_set_template_menu(compose);
5636 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5637 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5640 compose_list = g_list_append(compose_list, compose);
5642 if (!prefs_common.show_ruler)
5643 gtk_widget_hide(ruler_hbox);
5645 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5646 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5647 prefs_common.show_ruler);
5650 compose->priority = PRIORITY_NORMAL;
5651 compose_update_priority_menu_item(compose);
5653 compose_set_out_encoding(compose);
5656 compose_update_actions_menu(compose);
5658 /* Privacy Systems menu */
5659 compose_update_privacy_systems_menu(compose);
5661 activate_privacy_system(compose, account, TRUE);
5662 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5663 gtk_widget_show(window);
5668 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5674 gint num = 0, def_menu = 0;
5676 accounts = account_get_list();
5677 g_return_val_if_fail(accounts != NULL, NULL);
5679 hbox = gtk_hbox_new(FALSE, 0);
5680 optmenu = gtk_option_menu_new();
5681 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5682 menu = gtk_menu_new();
5684 for (; accounts != NULL; accounts = accounts->next, num++) {
5685 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5686 GtkWidget *menuitem;
5689 if (ac == compose->account) def_menu = num;
5692 name = g_strdup_printf("%s: %s <%s>",
5694 ac->name, ac->address);
5696 name = g_strdup_printf("%s: %s",
5697 ac->account_name, ac->address);
5698 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5700 g_signal_connect(G_OBJECT(menuitem), "activate",
5701 G_CALLBACK(account_activated),
5705 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5706 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5711 static void compose_set_priority_cb(gpointer data,
5715 Compose *compose = (Compose *) data;
5716 compose->priority = action;
5719 static void compose_update_priority_menu_item(Compose * compose)
5721 GtkItemFactory *ifactory;
5722 GtkWidget *menuitem = NULL;
5724 ifactory = gtk_item_factory_from_widget(compose->menubar);
5726 switch (compose->priority) {
5727 case PRIORITY_HIGHEST:
5728 menuitem = gtk_item_factory_get_item
5729 (ifactory, "/Options/Priority/Highest");
5732 menuitem = gtk_item_factory_get_item
5733 (ifactory, "/Options/Priority/High");
5735 case PRIORITY_NORMAL:
5736 menuitem = gtk_item_factory_get_item
5737 (ifactory, "/Options/Priority/Normal");
5740 menuitem = gtk_item_factory_get_item
5741 (ifactory, "/Options/Priority/Low");
5743 case PRIORITY_LOWEST:
5744 menuitem = gtk_item_factory_get_item
5745 (ifactory, "/Options/Priority/Lowest");
5748 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5751 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5753 Compose *compose = (Compose *) data;
5755 GtkItemFactory *ifactory;
5756 gboolean can_sign = FALSE, can_encrypt = FALSE;
5758 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5760 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5763 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5764 g_free(compose->privacy_system);
5765 compose->privacy_system = NULL;
5766 if (systemid != NULL) {
5767 compose->privacy_system = g_strdup(systemid);
5769 can_sign = privacy_system_can_sign(systemid);
5770 can_encrypt = privacy_system_can_encrypt(systemid);
5773 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5775 ifactory = gtk_item_factory_from_widget(compose->menubar);
5776 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5777 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5780 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
5782 static gchar *branch_path = "/Options/Privacy System";
5783 GtkItemFactory *ifactory;
5784 GtkWidget *menuitem = NULL;
5786 gboolean can_sign = FALSE, can_encrypt = FALSE;
5787 gboolean found = FALSE;
5789 ifactory = gtk_item_factory_from_widget(compose->menubar);
5791 if (compose->privacy_system != NULL) {
5794 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5795 g_return_if_fail(menuitem != NULL);
5797 amenu = GTK_MENU_SHELL(menuitem)->children;
5799 while (amenu != NULL) {
5800 GList *alist = amenu->next;
5802 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
5803 if (systemid != NULL) {
5804 if (strcmp(systemid, compose->privacy_system) == 0) {
5805 menuitem = GTK_WIDGET(amenu->data);
5807 can_sign = privacy_system_can_sign(systemid);
5808 can_encrypt = privacy_system_can_encrypt(systemid);
5812 } else if (strlen(compose->privacy_system) == 0) {
5813 menuitem = GTK_WIDGET(amenu->data);
5816 can_encrypt = FALSE;
5823 if (menuitem != NULL)
5824 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5826 if (warn && !found && strlen(compose->privacy_system)) {
5827 gchar *tmp = g_strdup_printf(
5828 _("The privacy system '%s' cannot be loaded. You "
5829 "will not be able to sign or encrypt this message."),
5830 compose->privacy_system);
5831 alertpanel_warning(tmp);
5836 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5837 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5840 static void compose_set_out_encoding(Compose *compose)
5842 GtkItemFactoryEntry *entry;
5843 GtkItemFactory *ifactory;
5844 CharSet out_encoding;
5845 gchar *path, *p, *q;
5848 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
5849 ifactory = gtk_item_factory_from_widget(compose->menubar);
5851 for (entry = compose_entries; entry->callback != compose_address_cb;
5853 if (entry->callback == compose_set_encoding_cb &&
5854 (CharSet)entry->callback_action == out_encoding) {
5855 p = q = path = g_strdup(entry->path);
5867 item = gtk_item_factory_get_item(ifactory, path);
5868 gtk_widget_activate(item);
5875 static void compose_set_template_menu(Compose *compose)
5877 GSList *tmpl_list, *cur;
5881 tmpl_list = template_get_config();
5883 menu = gtk_menu_new();
5885 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5886 Template *tmpl = (Template *)cur->data;
5888 item = gtk_menu_item_new_with_label(tmpl->name);
5889 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5890 g_signal_connect(G_OBJECT(item), "activate",
5891 G_CALLBACK(compose_template_activate_cb),
5893 g_object_set_data(G_OBJECT(item), "template", tmpl);
5894 gtk_widget_show(item);
5897 gtk_widget_show(menu);
5898 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5901 void compose_update_actions_menu(Compose *compose)
5903 GtkItemFactory *ifactory;
5905 ifactory = gtk_item_factory_from_widget(compose->menubar);
5906 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5909 void compose_update_privacy_systems_menu(Compose *compose)
5911 static gchar *branch_path = "/Options/Privacy System";
5912 GtkItemFactory *ifactory;
5913 GtkWidget *menuitem;
5914 GSList *systems, *cur;
5917 GtkWidget *system_none;
5920 ifactory = gtk_item_factory_from_widget(compose->menubar);
5922 /* remove old entries */
5923 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5924 g_return_if_fail(menuitem != NULL);
5926 amenu = GTK_MENU_SHELL(menuitem)->children->next;
5927 while (amenu != NULL) {
5928 GList *alist = amenu->next;
5929 gtk_widget_destroy(GTK_WIDGET(amenu->data));
5933 system_none = gtk_item_factory_get_widget(ifactory,
5934 "/Options/Privacy System/None");
5936 g_signal_connect(G_OBJECT(system_none), "activate",
5937 G_CALLBACK(compose_set_privacy_system_cb), compose);
5939 systems = privacy_get_system_ids();
5940 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
5941 gchar *systemid = cur->data;
5943 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
5944 widget = gtk_radio_menu_item_new_with_label(group,
5945 privacy_system_get_name(systemid));
5946 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
5947 g_strdup(systemid), g_free);
5948 g_signal_connect(G_OBJECT(widget), "activate",
5949 G_CALLBACK(compose_set_privacy_system_cb), compose);
5951 gtk_menu_append(GTK_MENU(system_none->parent), widget);
5952 gtk_widget_show(widget);
5955 g_slist_free(systems);
5958 void compose_reflect_prefs_all(void)
5963 for (cur = compose_list; cur != NULL; cur = cur->next) {
5964 compose = (Compose *)cur->data;
5965 compose_set_template_menu(compose);
5969 void compose_reflect_prefs_pixmap_theme(void)
5974 for (cur = compose_list; cur != NULL; cur = cur->next) {
5975 compose = (Compose *)cur->data;
5976 toolbar_update(TOOLBAR_COMPOSE, compose);
5980 static void compose_template_apply(Compose *compose, Template *tmpl,
5984 GtkTextBuffer *buffer;
5989 gint cursor_pos = 0;
5990 if (!tmpl || !tmpl->value) return;
5992 text = GTK_TEXT_VIEW(compose->text);
5993 buffer = gtk_text_view_get_buffer(text);
5995 if (tmpl->subject && *tmpl->subject != '\0')
5996 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5998 if (tmpl->to && *tmpl->to != '\0')
5999 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
6000 if (tmpl->cc && *tmpl->cc != '\0')
6001 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
6003 if (tmpl->bcc && *tmpl->bcc != '\0')
6004 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
6007 gtk_text_buffer_set_text(buffer, "", -1);
6009 mark = gtk_text_buffer_get_insert(buffer);
6010 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6012 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6013 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6016 if (prefs_common.quotemark && *prefs_common.quotemark)
6017 qmark = prefs_common.quotemark;
6021 if (compose->replyinfo != NULL)
6022 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6023 tmpl->value, qmark, NULL, FALSE);
6024 else if (compose->fwdinfo != NULL)
6025 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6026 tmpl->value, qmark, NULL, FALSE);
6031 if (replace && parsed_str && compose->account->auto_sig)
6032 compose_insert_sig(compose, FALSE);
6034 if (replace && parsed_str) {
6035 gtk_text_buffer_get_start_iter(buffer, &iter);
6036 gtk_text_buffer_place_cursor(buffer, &iter);
6040 cursor_pos = quote_fmt_get_cursor_pos();
6041 compose->set_cursor_pos = cursor_pos;
6042 if (cursor_pos == -1)
6044 gtk_text_buffer_get_start_iter(buffer, &iter);
6045 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6046 gtk_text_buffer_place_cursor(buffer, &iter);
6050 compose_changed_cb(NULL, compose);
6053 static void compose_destroy(Compose *compose)
6055 compose_list = g_list_remove(compose_list, compose);
6057 /* NOTE: address_completion_end() does nothing with the window
6058 * however this may change. */
6059 address_completion_end(compose->window);
6061 slist_free_strings(compose->to_list);
6062 g_slist_free(compose->to_list);
6063 slist_free_strings(compose->newsgroup_list);
6064 g_slist_free(compose->newsgroup_list);
6065 slist_free_strings(compose->header_list);
6066 g_slist_free(compose->header_list);
6068 procmsg_msginfo_free(compose->targetinfo);
6069 procmsg_msginfo_free(compose->replyinfo);
6070 procmsg_msginfo_free(compose->fwdinfo);
6072 g_free(compose->replyto);
6073 g_free(compose->cc);
6074 g_free(compose->bcc);
6075 g_free(compose->newsgroups);
6076 g_free(compose->followup_to);
6078 g_free(compose->ml_post);
6080 g_free(compose->inreplyto);
6081 g_free(compose->references);
6082 g_free(compose->msgid);
6083 g_free(compose->boundary);
6085 if (compose->redirect_filename)
6086 g_free(compose->redirect_filename);
6087 if (compose->undostruct)
6088 undo_destroy(compose->undostruct);
6090 g_free(compose->sig_str);
6092 g_free(compose->exteditor_file);
6094 g_free(compose->orig_charset);
6096 g_free(compose->privacy_system);
6098 if (addressbook_get_target_compose() == compose)
6099 addressbook_set_target_compose(NULL);
6102 if (compose->gtkaspell) {
6103 gtkaspell_delete(compose->gtkaspell);
6104 compose->gtkaspell = NULL;
6108 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6109 prefs_common.compose_height = compose->window->allocation.height;
6111 if (!gtk_widget_get_parent(compose->paned))
6112 gtk_widget_destroy(compose->paned);
6113 gtk_widget_destroy(compose->popupmenu);
6115 gtk_widget_destroy(compose->window);
6116 toolbar_destroy(compose->toolbar);
6117 g_free(compose->toolbar);
6118 g_mutex_free(compose->mutex);
6122 static void compose_attach_info_free(AttachInfo *ainfo)
6124 g_free(ainfo->file);
6125 g_free(ainfo->content_type);
6126 g_free(ainfo->name);
6130 static void compose_attach_remove_selected(Compose *compose)
6132 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6133 GtkTreeSelection *selection;
6135 GtkTreeModel *model;
6137 selection = gtk_tree_view_get_selection(tree_view);
6138 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6143 for (cur = sel; cur != NULL; cur = cur->next) {
6144 GtkTreePath *path = cur->data;
6145 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6148 gtk_tree_path_free(path);
6151 for (cur = sel; cur != NULL; cur = cur->next) {
6152 GtkTreeRowReference *ref = cur->data;
6153 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6156 if (gtk_tree_model_get_iter(model, &iter, path))
6157 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6159 gtk_tree_path_free(path);
6160 gtk_tree_row_reference_free(ref);
6166 static struct _AttachProperty
6169 GtkWidget *mimetype_entry;
6170 GtkWidget *encoding_optmenu;
6171 GtkWidget *path_entry;
6172 GtkWidget *filename_entry;
6174 GtkWidget *cancel_btn;
6177 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6179 gtk_tree_path_free((GtkTreePath *)ptr);
6182 static void compose_attach_property(Compose *compose)
6184 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6186 GtkOptionMenu *optmenu;
6187 GtkTreeSelection *selection;
6189 GtkTreeModel *model;
6192 static gboolean cancelled;
6194 /* only if one selected */
6195 selection = gtk_tree_view_get_selection(tree_view);
6196 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6199 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6203 path = (GtkTreePath *) sel->data;
6204 gtk_tree_model_get_iter(model, &iter, path);
6205 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6208 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6214 if (!attach_prop.window)
6215 compose_attach_property_create(&cancelled);
6216 gtk_widget_grab_focus(attach_prop.ok_btn);
6217 gtk_widget_show(attach_prop.window);
6218 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6220 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6221 if (ainfo->encoding == ENC_UNKNOWN)
6222 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6223 GINT_TO_POINTER(ENC_BASE64));
6225 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6226 GINT_TO_POINTER(ainfo->encoding));
6228 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6229 ainfo->content_type ? ainfo->content_type : "");
6230 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6231 ainfo->file ? ainfo->file : "");
6232 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6233 ainfo->name ? ainfo->name : "");
6236 const gchar *entry_text;
6238 gchar *cnttype = NULL;
6242 GtkWidget *menuitem;
6247 gtk_widget_hide(attach_prop.window);
6252 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6253 if (*entry_text != '\0') {
6256 text = g_strstrip(g_strdup(entry_text));
6257 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6258 cnttype = g_strdup(text);
6261 alertpanel_error(_("Invalid MIME type."));
6267 menu = gtk_option_menu_get_menu(optmenu);
6268 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6269 ainfo->encoding = GPOINTER_TO_INT
6270 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6272 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6273 if (*entry_text != '\0') {
6274 if (is_file_exist(entry_text) &&
6275 (size = get_file_size(entry_text)) > 0)
6276 file = g_strdup(entry_text);
6279 (_("File doesn't exist or is empty."));
6285 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6286 if (*entry_text != '\0') {
6287 g_free(ainfo->name);
6288 ainfo->name = g_strdup(entry_text);
6292 g_free(ainfo->content_type);
6293 ainfo->content_type = cnttype;
6296 g_free(ainfo->file);
6302 /* update tree store */
6303 text = to_human_readable(ainfo->size);
6304 gtk_tree_model_get_iter(model, &iter, path);
6305 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6306 COL_MIMETYPE, ainfo->content_type,
6308 COL_NAME, ainfo->name,
6314 gtk_tree_path_free(path);
6317 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6319 label = gtk_label_new(str); \
6320 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6321 GTK_FILL, 0, 0, 0); \
6322 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6324 entry = gtk_entry_new(); \
6325 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6326 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6329 static void compose_attach_property_create(gboolean *cancelled)
6335 GtkWidget *mimetype_entry;
6338 GtkWidget *optmenu_menu;
6339 GtkWidget *menuitem;
6340 GtkWidget *path_entry;
6341 GtkWidget *filename_entry;
6344 GtkWidget *cancel_btn;
6345 GList *mime_type_list, *strlist;
6347 debug_print("Creating attach_property window...\n");
6349 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6350 gtk_widget_set_size_request(window, 480, -1);
6351 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6352 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6353 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6354 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6355 g_signal_connect(G_OBJECT(window), "delete_event",
6356 G_CALLBACK(attach_property_delete_event),
6358 g_signal_connect(G_OBJECT(window), "key_press_event",
6359 G_CALLBACK(attach_property_key_pressed),
6362 vbox = gtk_vbox_new(FALSE, 8);
6363 gtk_container_add(GTK_CONTAINER(window), vbox);
6365 table = gtk_table_new(4, 2, FALSE);
6366 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6367 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6368 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6370 label = gtk_label_new(_("MIME type"));
6371 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6373 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6374 mimetype_entry = gtk_combo_new();
6375 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6376 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6378 /* stuff with list */
6379 mime_type_list = procmime_get_mime_type_list();
6381 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6382 MimeType *type = (MimeType *) mime_type_list->data;
6385 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6387 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6390 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6391 (GCompareFunc)strcmp2);
6394 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6396 for (mime_type_list = strlist; mime_type_list != NULL;
6397 mime_type_list = mime_type_list->next)
6398 g_free(mime_type_list->data);
6399 g_list_free(strlist);
6401 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6403 label = gtk_label_new(_("Encoding"));
6404 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6406 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6408 hbox = gtk_hbox_new(FALSE, 0);
6409 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6410 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6412 optmenu = gtk_option_menu_new();
6413 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6415 optmenu_menu = gtk_menu_new();
6416 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6417 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6418 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6419 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6420 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6421 ENC_QUOTED_PRINTABLE);
6422 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6424 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6426 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6428 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6429 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6431 gtkut_stock_button_set_create(&hbbox, &ok_btn, GTK_STOCK_OK,
6432 &cancel_btn, GTK_STOCK_CANCEL,
6434 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6435 gtk_widget_grab_default(ok_btn);
6437 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6438 G_CALLBACK(attach_property_ok),
6440 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6441 G_CALLBACK(attach_property_cancel),
6444 gtk_widget_show_all(vbox);
6446 attach_prop.window = window;
6447 attach_prop.mimetype_entry = mimetype_entry;
6448 attach_prop.encoding_optmenu = optmenu;
6449 attach_prop.path_entry = path_entry;
6450 attach_prop.filename_entry = filename_entry;
6451 attach_prop.ok_btn = ok_btn;
6452 attach_prop.cancel_btn = cancel_btn;
6455 #undef SET_LABEL_AND_ENTRY
6457 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6463 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6469 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6470 gboolean *cancelled)
6478 static gboolean attach_property_key_pressed(GtkWidget *widget,
6480 gboolean *cancelled)
6482 if (event && event->keyval == GDK_Escape) {
6489 static void compose_exec_ext_editor(Compose *compose)
6496 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6497 G_DIR_SEPARATOR, compose);
6499 if (pipe(pipe_fds) < 0) {
6505 if ((pid = fork()) < 0) {
6512 /* close the write side of the pipe */
6515 compose->exteditor_file = g_strdup(tmp);
6516 compose->exteditor_pid = pid;
6518 compose_set_ext_editor_sensitive(compose, FALSE);
6520 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6521 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6525 } else { /* process-monitoring process */
6531 /* close the read side of the pipe */
6534 if (compose_write_body_to_file(compose, tmp) < 0) {
6535 fd_write_all(pipe_fds[1], "2\n", 2);
6539 pid_ed = compose_exec_ext_editor_real(tmp);
6541 fd_write_all(pipe_fds[1], "1\n", 2);
6545 /* wait until editor is terminated */
6546 waitpid(pid_ed, NULL, 0);
6548 fd_write_all(pipe_fds[1], "0\n", 2);
6555 #endif /* G_OS_UNIX */
6559 static gint compose_exec_ext_editor_real(const gchar *file)
6561 static gchar *def_cmd = "emacs %s";
6567 g_return_val_if_fail(file != NULL, -1);
6569 if ((pid = fork()) < 0) {
6574 if (pid != 0) return pid;
6576 /* grandchild process */
6578 if (setpgid(0, getppid()))
6581 if (prefs_common.ext_editor_cmd &&
6582 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6583 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6584 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6586 if (prefs_common.ext_editor_cmd)
6587 g_warning("External editor command line is invalid: '%s'\n",
6588 prefs_common.ext_editor_cmd);
6589 g_snprintf(buf, sizeof(buf), def_cmd, file);
6592 cmdline = strsplit_with_quote(buf, " ", 1024);
6593 execvp(cmdline[0], cmdline);
6596 g_strfreev(cmdline);
6601 static gboolean compose_ext_editor_kill(Compose *compose)
6603 pid_t pgid = compose->exteditor_pid * -1;
6606 ret = kill(pgid, 0);
6608 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6612 msg = g_strdup_printf
6613 (_("The external editor is still working.\n"
6614 "Force terminating the process?\n"
6615 "process group id: %d"), -pgid);
6616 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_YES, GTK_STOCK_NO,
6617 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
6621 if (val == G_ALERTDEFAULT) {
6622 g_source_remove(compose->exteditor_tag);
6623 g_io_channel_shutdown(compose->exteditor_ch,
6625 g_io_channel_unref(compose->exteditor_ch);
6627 if (kill(pgid, SIGTERM) < 0) perror("kill");
6628 waitpid(compose->exteditor_pid, NULL, 0);
6630 g_warning("Terminated process group id: %d", -pgid);
6631 g_warning("Temporary file: %s",
6632 compose->exteditor_file);
6634 compose_set_ext_editor_sensitive(compose, TRUE);
6636 g_free(compose->exteditor_file);
6637 compose->exteditor_file = NULL;
6638 compose->exteditor_pid = -1;
6639 compose->exteditor_ch = NULL;
6640 compose->exteditor_tag = -1;
6648 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6652 Compose *compose = (Compose *)data;
6655 debug_print(_("Compose: input from monitoring process\n"));
6657 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6659 g_io_channel_shutdown(source, FALSE, NULL);
6660 g_io_channel_unref(source);
6662 waitpid(compose->exteditor_pid, NULL, 0);
6664 if (buf[0] == '0') { /* success */
6665 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6666 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6668 gtk_text_buffer_set_text(buffer, "", -1);
6669 compose_insert_file(compose, compose->exteditor_file);
6670 compose_changed_cb(NULL, compose);
6672 if (g_unlink(compose->exteditor_file) < 0)
6673 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6674 } else if (buf[0] == '1') { /* failed */
6675 g_warning("Couldn't exec external editor\n");
6676 if (g_unlink(compose->exteditor_file) < 0)
6677 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6678 } else if (buf[0] == '2') {
6679 g_warning("Couldn't write to file\n");
6680 } else if (buf[0] == '3') {
6681 g_warning("Pipe read failed\n");
6684 compose_set_ext_editor_sensitive(compose, TRUE);
6686 g_free(compose->exteditor_file);
6687 compose->exteditor_file = NULL;
6688 compose->exteditor_pid = -1;
6689 compose->exteditor_ch = NULL;
6690 compose->exteditor_tag = -1;
6695 static void compose_set_ext_editor_sensitive(Compose *compose,
6698 GtkItemFactory *ifactory;
6700 ifactory = gtk_item_factory_from_widget(compose->menubar);
6702 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6703 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6704 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6705 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6706 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6707 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6708 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6711 gtk_widget_set_sensitive(compose->text, sensitive);
6712 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6713 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6714 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6715 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6716 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6717 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6718 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
6719 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
6721 #endif /* G_OS_UNIX */
6724 * compose_undo_state_changed:
6726 * Change the sensivity of the menuentries undo and redo
6728 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6729 gint redo_state, gpointer data)
6731 GtkWidget *widget = GTK_WIDGET(data);
6732 GtkItemFactory *ifactory;
6734 g_return_if_fail(widget != NULL);
6736 ifactory = gtk_item_factory_from_widget(widget);
6738 switch (undo_state) {
6739 case UNDO_STATE_TRUE:
6740 if (!undostruct->undo_state) {
6741 undostruct->undo_state = TRUE;
6742 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6745 case UNDO_STATE_FALSE:
6746 if (undostruct->undo_state) {
6747 undostruct->undo_state = FALSE;
6748 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6751 case UNDO_STATE_UNCHANGED:
6753 case UNDO_STATE_REFRESH:
6754 menu_set_sensitive(ifactory, "/Edit/Undo",
6755 undostruct->undo_state);
6758 g_warning("Undo state not recognized");
6762 switch (redo_state) {
6763 case UNDO_STATE_TRUE:
6764 if (!undostruct->redo_state) {
6765 undostruct->redo_state = TRUE;
6766 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6769 case UNDO_STATE_FALSE:
6770 if (undostruct->redo_state) {
6771 undostruct->redo_state = FALSE;
6772 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6775 case UNDO_STATE_UNCHANGED:
6777 case UNDO_STATE_REFRESH:
6778 menu_set_sensitive(ifactory, "/Edit/Redo",
6779 undostruct->redo_state);
6782 g_warning("Redo state not recognized");
6787 /* callback functions */
6789 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6790 * includes "non-client" (windows-izm) in calculation, so this calculation
6791 * may not be accurate.
6793 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6794 GtkAllocation *allocation,
6795 GtkSHRuler *shruler)
6797 if (prefs_common.show_ruler) {
6798 gint char_width = 0, char_height = 0;
6799 gint line_width_in_chars;
6801 gtkut_get_font_size(GTK_WIDGET(widget),
6802 &char_width, &char_height);
6803 line_width_in_chars =
6804 (allocation->width - allocation->x) / char_width;
6806 /* got the maximum */
6807 gtk_ruler_set_range(GTK_RULER(shruler),
6808 0.0, line_width_in_chars, 0,
6809 /*line_width_in_chars*/ char_width);
6815 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6817 Compose *compose = (Compose *)data;
6820 gchar *folderidentifier;
6822 ac = account_find_from_id(
6823 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
6824 g_return_if_fail(ac != NULL);
6826 if (ac != compose->account)
6827 compose_select_account(compose, ac, FALSE);
6829 /* Set message save folder */
6830 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6831 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
6833 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
6834 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
6836 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6837 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6838 folderidentifier = folder_item_get_identifier(account_get_special_folder
6839 (compose->account, F_OUTBOX));
6840 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
6841 g_free(folderidentifier);
6845 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
6846 GtkTreeViewColumn *column, Compose *compose)
6848 compose_attach_property(compose);
6851 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6854 Compose *compose = (Compose *)data;
6855 GtkTreeSelection *attach_selection;
6856 gint attach_nr_selected;
6857 GtkItemFactory *ifactory;
6859 if (!event) return FALSE;
6861 if (event->button == 3) {
6862 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
6863 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
6864 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6866 if (attach_nr_selected > 0)
6868 menu_set_sensitive(ifactory, "/Remove", TRUE);
6869 menu_set_sensitive(ifactory, "/Properties...", TRUE);
6871 menu_set_sensitive(ifactory, "/Remove", FALSE);
6872 menu_set_sensitive(ifactory, "/Properties...", FALSE);
6875 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6876 NULL, NULL, event->button, event->time);
6883 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6886 Compose *compose = (Compose *)data;
6888 if (!event) return FALSE;
6890 switch (event->keyval) {
6892 compose_attach_remove_selected(compose);
6898 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6900 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6901 toolbar_comp_set_sensitive(compose, allow);
6902 menu_set_sensitive(ifactory, "/Message", allow);
6903 menu_set_sensitive(ifactory, "/Edit", allow);
6905 menu_set_sensitive(ifactory, "/Spelling", allow);
6907 menu_set_sensitive(ifactory, "/Options", allow);
6908 menu_set_sensitive(ifactory, "/Tools", allow);
6909 menu_set_sensitive(ifactory, "/Help", allow);
6911 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
6915 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6917 Compose *compose = (Compose *)data;
6919 if (prefs_common.work_offline && !inc_offline_should_override())
6922 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
6923 gtk_timeout_remove(compose->draft_timeout_tag);
6924 compose->draft_timeout_tag = -1;
6927 compose_send(compose);
6930 static void compose_send_later_cb(gpointer data, guint action,
6933 Compose *compose = (Compose *)data;
6936 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6938 compose_close(compose);
6939 else if (val == -2) {
6940 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
6944 void compose_draft (gpointer data)
6946 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6949 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6951 Compose *compose = (Compose *)data;
6955 MsgFlags flag = {0, 0};
6956 static gboolean lock = FALSE;
6957 MsgInfo *newmsginfo;
6962 draft = account_get_special_folder(compose->account, F_DRAFT);
6963 g_return_if_fail(draft != NULL);
6965 if (!g_mutex_trylock(compose->mutex)) {
6966 /* we don't want to lock the mutex once it's available,
6967 * because as the only other part of compose.c locking
6968 * it is compose_close - which means once unlocked,
6969 * the compose struct will be freed */
6970 debug_print("couldn't lock mutex, probably sending\n");
6976 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
6977 G_DIR_SEPARATOR, compose);
6978 if ((fp = g_fopen(tmp, "wb")) == NULL) {
6979 FILE_OP_ERROR(tmp, "fopen");
6983 /* chmod for security */
6984 if (change_file_mode_rw(fp, tmp) < 0) {
6985 FILE_OP_ERROR(tmp, "chmod");
6986 g_warning("can't change file mode\n");
6989 /* Save draft infos */
6990 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
6991 fprintf(fp, "S:%s\n", compose->account->address);
6992 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
6993 gchar *savefolderid;
6995 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6996 fprintf(fp, "SCF:%s\n", savefolderid);
6997 g_free(savefolderid);
6999 if (compose->return_receipt) {
7000 fprintf(fp, "RRCPT:1\n");
7002 if (compose->privacy_system) {
7003 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7004 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7005 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7009 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
7017 folder_item_scan(draft);
7018 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7021 if (action != COMPOSE_AUTO_SAVE)
7022 alertpanel_error(_("Could not save draft."));
7026 draft->mtime = 0; /* force updating */
7028 if (compose->mode == COMPOSE_REEDIT) {
7029 compose_remove_reedit_target(compose);
7032 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7034 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7035 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7036 if (compose_use_attach(compose))
7037 procmsg_msginfo_set_flags(newmsginfo, 0,
7038 MSG_HAS_ATTACHMENT);
7040 procmsg_msginfo_free(newmsginfo);
7043 folder_item_scan(draft);
7045 if (action == COMPOSE_QUIT_EDITING) {
7047 g_mutex_unlock(compose->mutex); /* must be done before closing */
7048 compose_close(compose);
7054 path = folder_item_fetch_msg(draft, msgnum);
7055 g_return_if_fail(path != NULL);
7056 if (g_stat(path, &s) < 0) {
7057 FILE_OP_ERROR(path, "stat");
7063 procmsg_msginfo_free(compose->targetinfo);
7064 compose->targetinfo = procmsg_msginfo_new();
7065 compose->targetinfo->msgnum = msgnum;
7066 compose->targetinfo->size = s.st_size;
7067 compose->targetinfo->mtime = s.st_mtime;
7068 compose->targetinfo->folder = draft;
7069 compose->mode = COMPOSE_REEDIT;
7071 if (action == COMPOSE_AUTO_SAVE) {
7072 compose->autosaved_draft = compose->targetinfo;
7074 compose->modified = FALSE;
7075 compose_set_title(compose);
7079 g_mutex_unlock(compose->mutex);
7082 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7084 Compose *compose = (Compose *)data;
7087 if (compose->redirect_filename != NULL)
7090 file_list = filesel_select_multiple_files_open(_("Select file"));
7095 for ( tmp = file_list; tmp; tmp = tmp->next) {
7096 gchar *file = (gchar *) tmp->data;
7097 gchar *utf8_filename = conv_filename_to_utf8(file);
7098 compose_attach_append(compose, file, utf8_filename, NULL);
7099 compose_changed_cb(NULL, compose);
7101 g_free(utf8_filename);
7103 g_list_free(file_list);
7107 static void compose_insert_file_cb(gpointer data, guint action,
7110 Compose *compose = (Compose *)data;
7113 file_list = filesel_select_multiple_files_open(_("Select file"));
7118 for ( tmp = file_list; tmp; tmp = tmp->next) {
7119 gchar *file = (gchar *) tmp->data;
7120 gchar *filedup = g_strdup(file);
7121 gchar *shortfile = g_path_get_basename(filedup);
7122 ComposeInsertResult res;
7124 res = compose_insert_file(compose, file);
7125 if (res == COMPOSE_INSERT_READ_ERROR) {
7126 alertpanel_error(_("File '%s' could not be read."), shortfile);
7127 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7128 alertpanel_error(_("File '%s' contained invalid characters\n"
7129 "for the current encoding, insertion may be incorrect."), shortfile);
7135 g_list_free(file_list);
7139 static void compose_insert_sig_cb(gpointer data, guint action,
7142 Compose *compose = (Compose *)data;
7144 compose_insert_sig(compose, FALSE);
7147 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7151 Compose *compose = (Compose *)data;
7153 gtkut_widget_get_uposition(widget, &x, &y);
7154 prefs_common.compose_x = x;
7155 prefs_common.compose_y = y;
7157 if (compose->sending)
7159 compose_close_cb(compose, 0, NULL);
7163 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7165 Compose *compose = (Compose *)data;
7169 if (compose->exteditor_tag != -1) {
7170 if (!compose_ext_editor_kill(compose))
7175 if (compose->modified) {
7176 val = alertpanel(_("Discard message"),
7177 _("This message has been modified. Discard it?"),
7178 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7181 case G_ALERTDEFAULT:
7182 if (prefs_common.autosave)
7183 compose_remove_draft(compose);
7185 case G_ALERTALTERNATE:
7186 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7193 compose_close(compose);
7196 static void compose_set_encoding_cb(gpointer data, guint action,
7199 Compose *compose = (Compose *)data;
7201 if (GTK_CHECK_MENU_ITEM(widget)->active)
7202 compose->out_encoding = (CharSet)action;
7205 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7207 Compose *compose = (Compose *)data;
7209 addressbook_open(compose);
7212 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7214 Compose *compose = (Compose *)data;
7219 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7220 g_return_if_fail(tmpl != NULL);
7222 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7224 val = alertpanel(_("Apply template"), msg,
7225 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7228 if (val == G_ALERTDEFAULT)
7229 compose_template_apply(compose, tmpl, TRUE);
7230 else if (val == G_ALERTALTERNATE)
7231 compose_template_apply(compose, tmpl, FALSE);
7234 static void compose_ext_editor_cb(gpointer data, guint action,
7237 Compose *compose = (Compose *)data;
7239 compose_exec_ext_editor(compose);
7242 static void compose_undo_cb(Compose *compose)
7244 gboolean prev_autowrap = compose->autowrap;
7246 compose->autowrap = FALSE;
7247 undo_undo(compose->undostruct);
7248 compose->autowrap = prev_autowrap;
7251 static void compose_redo_cb(Compose *compose)
7253 gboolean prev_autowrap = compose->autowrap;
7255 compose->autowrap = FALSE;
7256 undo_redo(compose->undostruct);
7257 compose->autowrap = prev_autowrap;
7260 static void entry_cut_clipboard(GtkWidget *entry)
7262 if (GTK_IS_EDITABLE(entry))
7263 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7264 else if (GTK_IS_TEXT_VIEW(entry))
7265 gtk_text_buffer_cut_clipboard(
7266 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7267 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7271 static void entry_copy_clipboard(GtkWidget *entry)
7273 if (GTK_IS_EDITABLE(entry))
7274 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7275 else if (GTK_IS_TEXT_VIEW(entry))
7276 gtk_text_buffer_copy_clipboard(
7277 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7278 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7281 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7282 gboolean wrap, GdkAtom clip)
7284 if (GTK_IS_TEXT_VIEW(entry)) {
7285 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7286 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7287 GtkTextIter start_iter, end_iter;
7290 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7292 if (contents == NULL)
7295 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7296 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7298 start = gtk_text_iter_get_offset(&start_iter);
7300 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7303 end = start + strlen(contents);
7304 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7305 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7306 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7307 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7308 mark_start = gtk_text_buffer_get_insert(buffer);
7309 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7310 gtk_text_iter_backward_char(&start_iter);
7311 compose_beautify_paragraph(compose, &start_iter, TRUE);
7314 } else if (GTK_IS_EDITABLE(entry))
7315 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7319 static void entry_allsel(GtkWidget *entry)
7321 if (GTK_IS_EDITABLE(entry))
7322 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7323 else if (GTK_IS_TEXT_VIEW(entry)) {
7324 GtkTextIter startiter, enditer;
7325 GtkTextBuffer *textbuf;
7327 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7328 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7329 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7331 gtk_text_buffer_move_mark_by_name(textbuf,
7332 "selection_bound", &startiter);
7333 gtk_text_buffer_move_mark_by_name(textbuf,
7334 "insert", &enditer);
7338 static void compose_cut_cb(Compose *compose)
7340 if (compose->focused_editable &&
7341 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7342 entry_cut_clipboard(compose->focused_editable);
7345 static void compose_copy_cb(Compose *compose)
7347 if (compose->focused_editable &&
7348 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7349 entry_copy_clipboard(compose->focused_editable);
7352 static void compose_paste_cb(Compose *compose)
7355 GtkTextBuffer *buffer;
7357 if (compose->focused_editable &&
7358 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7359 entry_paste_clipboard(compose, compose->focused_editable,
7360 prefs_common.linewrap_pastes,
7361 GDK_SELECTION_CLIPBOARD);
7365 static void compose_paste_as_quote_cb(Compose *compose)
7367 gint wrap_quote = prefs_common.linewrap_quote;
7368 if (compose->focused_editable &&
7369 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7370 /* let text_insert() (called directly or at a later time
7371 * after the gtk_editable_paste_clipboard) know that
7372 * text is to be inserted as a quotation. implemented
7373 * by using a simple refcount... */
7374 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7375 G_OBJECT(compose->focused_editable),
7376 "paste_as_quotation"));
7377 g_object_set_data(G_OBJECT(compose->focused_editable),
7378 "paste_as_quotation",
7379 GINT_TO_POINTER(paste_as_quotation + 1));
7380 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7381 entry_paste_clipboard(compose, compose->focused_editable,
7382 prefs_common.linewrap_pastes,
7383 GDK_SELECTION_CLIPBOARD);
7384 prefs_common.linewrap_quote = wrap_quote;
7388 static void compose_paste_no_wrap_cb(Compose *compose)
7391 GtkTextBuffer *buffer;
7393 if (compose->focused_editable &&
7394 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7395 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7396 GDK_SELECTION_CLIPBOARD);
7400 static void compose_paste_wrap_cb(Compose *compose)
7403 GtkTextBuffer *buffer;
7405 if (compose->focused_editable &&
7406 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7407 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7408 GDK_SELECTION_CLIPBOARD);
7412 static void compose_allsel_cb(Compose *compose)
7414 if (compose->focused_editable &&
7415 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7416 entry_allsel(compose->focused_editable);
7419 static void textview_move_beginning_of_line (GtkTextView *text)
7421 GtkTextBuffer *buffer;
7425 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7427 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7428 mark = gtk_text_buffer_get_insert(buffer);
7429 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7430 gtk_text_iter_set_line_offset(&ins, 0);
7431 gtk_text_buffer_place_cursor(buffer, &ins);
7434 static void textview_move_forward_character (GtkTextView *text)
7436 GtkTextBuffer *buffer;
7440 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7442 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7443 mark = gtk_text_buffer_get_insert(buffer);
7444 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7445 if (gtk_text_iter_forward_cursor_position(&ins))
7446 gtk_text_buffer_place_cursor(buffer, &ins);
7449 static void textview_move_backward_character (GtkTextView *text)
7451 GtkTextBuffer *buffer;
7455 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7457 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7458 mark = gtk_text_buffer_get_insert(buffer);
7459 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7460 if (gtk_text_iter_backward_cursor_position(&ins))
7461 gtk_text_buffer_place_cursor(buffer, &ins);
7464 static void textview_move_forward_word (GtkTextView *text)
7466 GtkTextBuffer *buffer;
7471 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7473 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7474 mark = gtk_text_buffer_get_insert(buffer);
7475 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7476 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7477 if (gtk_text_iter_forward_word_ends(&ins, count)) {
7478 gtk_text_iter_backward_word_start(&ins);
7479 gtk_text_buffer_place_cursor(buffer, &ins);
7483 static void textview_move_backward_word (GtkTextView *text)
7485 GtkTextBuffer *buffer;
7490 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7492 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7493 mark = gtk_text_buffer_get_insert(buffer);
7494 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7495 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7496 if (gtk_text_iter_backward_word_starts(&ins, 1))
7497 gtk_text_buffer_place_cursor(buffer, &ins);
7500 static void textview_move_end_of_line (GtkTextView *text)
7502 GtkTextBuffer *buffer;
7506 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7508 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7509 mark = gtk_text_buffer_get_insert(buffer);
7510 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7511 if (gtk_text_iter_forward_to_line_end(&ins))
7512 gtk_text_buffer_place_cursor(buffer, &ins);
7515 static void textview_move_next_line (GtkTextView *text)
7517 GtkTextBuffer *buffer;
7522 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7524 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7525 mark = gtk_text_buffer_get_insert(buffer);
7526 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7527 offset = gtk_text_iter_get_line_offset(&ins);
7528 if (gtk_text_iter_forward_line(&ins)) {
7529 gtk_text_iter_set_line_offset(&ins, offset);
7530 gtk_text_buffer_place_cursor(buffer, &ins);
7534 static void textview_move_previous_line (GtkTextView *text)
7536 GtkTextBuffer *buffer;
7541 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7543 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7544 mark = gtk_text_buffer_get_insert(buffer);
7545 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7546 offset = gtk_text_iter_get_line_offset(&ins);
7547 if (gtk_text_iter_backward_line(&ins)) {
7548 gtk_text_iter_set_line_offset(&ins, offset);
7549 gtk_text_buffer_place_cursor(buffer, &ins);
7553 static void textview_delete_forward_character (GtkTextView *text)
7555 GtkTextBuffer *buffer;
7557 GtkTextIter ins, end_iter;
7559 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7561 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7562 mark = gtk_text_buffer_get_insert(buffer);
7563 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7565 if (gtk_text_iter_forward_char(&end_iter)) {
7566 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7570 static void textview_delete_backward_character (GtkTextView *text)
7572 GtkTextBuffer *buffer;
7574 GtkTextIter ins, end_iter;
7576 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7578 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7579 mark = gtk_text_buffer_get_insert(buffer);
7580 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7582 if (gtk_text_iter_backward_char(&end_iter)) {
7583 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7587 static void textview_delete_forward_word (GtkTextView *text)
7589 GtkTextBuffer *buffer;
7591 GtkTextIter ins, end_iter;
7593 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7595 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7596 mark = gtk_text_buffer_get_insert(buffer);
7597 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7599 if (gtk_text_iter_forward_word_end(&end_iter)) {
7600 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7604 static void textview_delete_backward_word (GtkTextView *text)
7606 GtkTextBuffer *buffer;
7608 GtkTextIter ins, end_iter;
7610 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7612 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7613 mark = gtk_text_buffer_get_insert(buffer);
7614 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7616 if (gtk_text_iter_backward_word_start(&end_iter)) {
7617 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7621 static void textview_delete_line (GtkTextView *text)
7623 GtkTextBuffer *buffer;
7625 GtkTextIter ins, start_iter, end_iter;
7628 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7630 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7631 mark = gtk_text_buffer_get_insert(buffer);
7632 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7635 gtk_text_iter_set_line_offset(&start_iter, 0);
7638 if (gtk_text_iter_ends_line(&end_iter))
7639 found = gtk_text_iter_forward_char(&end_iter);
7641 found = gtk_text_iter_forward_to_line_end(&end_iter);
7644 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7647 static void textview_delete_to_line_end (GtkTextView *text)
7649 GtkTextBuffer *buffer;
7651 GtkTextIter ins, end_iter;
7654 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7656 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7657 mark = gtk_text_buffer_get_insert(buffer);
7658 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7660 if (gtk_text_iter_ends_line(&end_iter))
7661 found = gtk_text_iter_forward_char(&end_iter);
7663 found = gtk_text_iter_forward_to_line_end(&end_iter);
7665 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7668 static void compose_advanced_action_cb(Compose *compose,
7669 ComposeCallAdvancedAction action)
7671 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7673 void (*do_action) (GtkTextView *text);
7674 } action_table[] = {
7675 {textview_move_beginning_of_line},
7676 {textview_move_forward_character},
7677 {textview_move_backward_character},
7678 {textview_move_forward_word},
7679 {textview_move_backward_word},
7680 {textview_move_end_of_line},
7681 {textview_move_next_line},
7682 {textview_move_previous_line},
7683 {textview_delete_forward_character},
7684 {textview_delete_backward_character},
7685 {textview_delete_forward_word},
7686 {textview_delete_backward_word},
7687 {textview_delete_line},
7688 {NULL}, /* gtk_stext_delete_line_n */
7689 {textview_delete_to_line_end}
7692 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
7694 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
7695 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
7696 if (action_table[action].do_action)
7697 action_table[action].do_action(text);
7699 g_warning("Not implemented yet.");
7703 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
7707 if (GTK_IS_EDITABLE(widget)) {
7708 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
7709 gtk_editable_set_position(GTK_EDITABLE(widget),
7712 if (widget->parent && widget->parent->parent
7713 && widget->parent->parent->parent) {
7714 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
7715 gint y = widget->allocation.y;
7716 gint height = widget->allocation.height;
7717 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
7718 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
7720 if (y < (int)shown->value) {
7721 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
7723 if (y + height > (int)shown->value + (int)shown->page_size) {
7724 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
7725 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7726 y + height - (int)shown->page_size - 1);
7728 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7729 (int)shown->upper - (int)shown->page_size - 1);
7736 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
7737 compose->focused_editable = widget;
7740 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
7742 compose->modified = TRUE;
7743 compose_set_title(compose);
7746 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
7748 Compose *compose = (Compose *)data;
7751 compose_wrap_all_full(compose, TRUE);
7753 compose_beautify_paragraph(compose, NULL, TRUE);
7756 static void compose_toggle_autowrap_cb(gpointer data, guint action,
7759 Compose *compose = (Compose *)data;
7760 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7761 if (compose->autowrap)
7762 compose_wrap_all_full(compose, TRUE);
7765 static void compose_toggle_sign_cb(gpointer data, guint action,
7768 Compose *compose = (Compose *)data;
7770 if (GTK_CHECK_MENU_ITEM(widget)->active)
7771 compose->use_signing = TRUE;
7773 compose->use_signing = FALSE;
7776 static void compose_toggle_encrypt_cb(gpointer data, guint action,
7779 Compose *compose = (Compose *)data;
7781 if (GTK_CHECK_MENU_ITEM(widget)->active)
7782 compose->use_encryption = TRUE;
7784 compose->use_encryption = FALSE;
7787 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
7789 g_free(compose->privacy_system);
7791 compose->privacy_system = g_strdup(account->default_privacy_system);
7792 compose_update_privacy_system_menu_item(compose, warn);
7795 static void compose_toggle_ruler_cb(gpointer data, guint action,
7798 Compose *compose = (Compose *)data;
7800 if (GTK_CHECK_MENU_ITEM(widget)->active) {
7801 gtk_widget_show(compose->ruler_hbox);
7802 prefs_common.show_ruler = TRUE;
7804 gtk_widget_hide(compose->ruler_hbox);
7805 gtk_widget_queue_resize(compose->edit_vbox);
7806 prefs_common.show_ruler = FALSE;
7810 static void compose_attach_drag_received_cb (GtkWidget *widget,
7811 GdkDragContext *drag_context,
7814 GtkSelectionData *data,
7819 Compose *compose = (Compose *)user_data;
7822 if (gdk_atom_name(data->type) &&
7823 !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7824 list = uri_list_extract_filenames((const gchar *)data->data);
7825 for (tmp = list; tmp != NULL; tmp = tmp->next)
7826 compose_attach_append
7827 (compose, (const gchar *)tmp->data,
7828 (const gchar *)tmp->data, NULL);
7829 if (list) compose_changed_cb(NULL, compose);
7830 list_free_strings(list);
7832 } else if (gdk_atom_name(data->type) &&
7833 !strcmp(gdk_atom_name(data->type), "text/plain") &&
7834 data->data && !strcmp(data->data, "Dummy-Summaryview")) {
7835 /* comes from our summaryview */
7836 SummaryView * summaryview = NULL;
7837 GSList * list = NULL, *cur = NULL;
7839 if (mainwindow_get_mainwindow())
7840 summaryview = mainwindow_get_mainwindow()->summaryview;
7843 list = summary_get_selected_msg_list(summaryview);
7845 for (cur = list; cur; cur = cur->next) {
7846 MsgInfo *msginfo = (MsgInfo *)cur->data;
7849 file = procmsg_get_message_file_full(msginfo,
7852 compose_attach_append(compose, (const gchar *)file,
7853 (const gchar *)file, "message/rfc822");
7861 static gboolean compose_drag_drop(GtkWidget *widget,
7862 GdkDragContext *drag_context,
7864 guint time, gpointer user_data)
7866 /* not handling this signal makes compose_insert_drag_received_cb
7871 static void compose_insert_drag_received_cb (GtkWidget *widget,
7872 GdkDragContext *drag_context,
7875 GtkSelectionData *data,
7880 Compose *compose = (Compose *)user_data;
7883 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
7885 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7886 list = uri_list_extract_filenames((const gchar *)data->data);
7887 for (tmp = list; tmp != NULL; tmp = tmp->next) {
7888 compose_insert_file(compose, (const gchar *)tmp->data);
7890 list_free_strings(list);
7892 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7895 #if GTK_CHECK_VERSION(2, 8, 0)
7896 /* do nothing, handled by GTK */
7898 gchar *tmpfile = get_tmp_file();
7899 str_write_to_file((const gchar *)data->data, tmpfile);
7900 compose_insert_file(compose, tmpfile);
7903 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7907 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7910 static void compose_header_drag_received_cb (GtkWidget *widget,
7911 GdkDragContext *drag_context,
7914 GtkSelectionData *data,
7919 GtkEditable *entry = (GtkEditable *)user_data;
7920 gchar *email = (gchar *)data->data;
7922 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
7925 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
7926 gchar *decoded=g_new(gchar, strlen(email));
7929 email += strlen("mailto:");
7930 decode_uri(decoded, email); /* will fit */
7931 gtk_editable_delete_text(entry, 0, -1);
7932 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
7933 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7937 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7940 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
7943 Compose *compose = (Compose *)data;
7945 if (GTK_CHECK_MENU_ITEM(widget)->active)
7946 compose->return_receipt = TRUE;
7948 compose->return_receipt = FALSE;
7951 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
7954 Compose *compose = (Compose *)data;
7956 if (GTK_CHECK_MENU_ITEM(widget)->active)
7957 compose->remove_references = TRUE;
7959 compose->remove_references = FALSE;
7962 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
7964 ComposeHeaderEntry *headerentry)
7966 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
7967 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
7968 !(event->state & GDK_MODIFIER_MASK) &&
7969 (event->keyval == GDK_BackSpace) &&
7970 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
7971 gtk_container_remove
7972 (GTK_CONTAINER(headerentry->compose->header_table),
7973 headerentry->combo);
7974 gtk_container_remove
7975 (GTK_CONTAINER(headerentry->compose->header_table),
7976 headerentry->entry);
7977 headerentry->compose->header_list =
7978 g_slist_remove(headerentry->compose->header_list,
7980 g_free(headerentry);
7981 } else if (event->keyval == GDK_Tab) {
7982 if (headerentry->compose->header_last == headerentry) {
7983 /* Override default next focus, and give it to subject_entry
7984 * instead of notebook tabs
7986 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
7987 gtk_widget_grab_focus(headerentry->compose->subject_entry);
7994 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
7995 ComposeHeaderEntry *headerentry)
7997 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
7998 headerentry->compose->header_list =
7999 g_slist_append(headerentry->compose->header_list,
8002 compose_create_header_entry(headerentry->compose);
8003 g_signal_handlers_disconnect_matched
8004 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8005 0, 0, NULL, NULL, headerentry);
8007 /* Automatically scroll down */
8008 compose_show_first_last_header(headerentry->compose, FALSE);
8014 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8016 GtkAdjustment *vadj;
8018 g_return_if_fail(compose);
8019 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8020 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8022 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8023 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8026 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8027 const gchar *text, gint len, Compose *compose)
8029 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8030 (G_OBJECT(compose->text), "paste_as_quotation"));
8033 g_return_if_fail(text != NULL);
8035 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8036 G_CALLBACK(text_inserted),
8038 if (paste_as_quotation) {
8045 new_text = g_strndup(text, len);
8046 if (prefs_common.quotemark && *prefs_common.quotemark)
8047 qmark = prefs_common.quotemark;
8051 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8052 gtk_text_buffer_place_cursor(buffer, iter);
8054 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8056 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8057 GINT_TO_POINTER(paste_as_quotation - 1));
8059 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8060 gtk_text_buffer_place_cursor(buffer, iter);
8062 gtk_text_buffer_insert(buffer, iter, text, len);
8064 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8066 compose_beautify_paragraph(compose, iter, FALSE);
8068 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8069 gtk_text_buffer_delete_mark(buffer, mark);
8071 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8072 G_CALLBACK(text_inserted),
8074 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8076 if (prefs_common.autosave &&
8077 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8078 compose->draft_timeout_tag = gtk_timeout_add
8079 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8081 static gint compose_defer_auto_save_draft(Compose *compose)
8083 compose->draft_timeout_tag = -1;
8084 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8089 static void compose_check_all(Compose *compose)
8091 if (compose->gtkaspell)
8092 gtkaspell_check_all(compose->gtkaspell);
8095 static void compose_highlight_all(Compose *compose)
8097 if (compose->gtkaspell)
8098 gtkaspell_highlight_all(compose->gtkaspell);
8101 static void compose_check_backwards(Compose *compose)
8103 if (compose->gtkaspell)
8104 gtkaspell_check_backwards(compose->gtkaspell);
8106 GtkItemFactory *ifactory;
8107 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8108 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8109 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8113 static void compose_check_forwards_go(Compose *compose)
8115 if (compose->gtkaspell)
8116 gtkaspell_check_forwards_go(compose->gtkaspell);
8118 GtkItemFactory *ifactory;
8119 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8120 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8121 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8127 *\brief Guess originating forward account from MsgInfo and several
8128 * "common preference" settings. Return NULL if no guess.
8130 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8132 PrefsAccount *account = NULL;
8134 g_return_val_if_fail(msginfo, NULL);
8135 g_return_val_if_fail(msginfo->folder, NULL);
8136 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8138 if (msginfo->folder->prefs->enable_default_account)
8139 account = account_find_from_id(msginfo->folder->prefs->default_account);
8142 account = msginfo->folder->folder->account;
8144 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8146 Xstrdup_a(to, msginfo->to, return NULL);
8147 extract_address(to);
8148 account = account_find_from_address(to);
8151 if (!account && prefs_common.forward_account_autosel) {
8153 if (!procheader_get_header_from_msginfo
8154 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8155 extract_address(cc);
8156 account = account_find_from_address(cc);
8163 static gboolean compose_close(Compose *compose)
8167 if (!g_mutex_trylock(compose->mutex)) {
8168 /* we have to wait for the (possibly deferred by auto-save)
8169 * drafting to be done, before destroying the compose under
8171 debug_print("waiting for drafting to finish...\n");
8172 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8175 g_return_val_if_fail(compose, FALSE);
8176 gtkut_widget_get_uposition(compose->window, &x, &y);
8177 prefs_common.compose_x = x;
8178 prefs_common.compose_y = y;
8179 g_mutex_unlock(compose->mutex);
8180 compose_destroy(compose);
8185 * Add entry field for each address in list.
8186 * \param compose E-Mail composition object.
8187 * \param listAddress List of (formatted) E-Mail addresses.
8189 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8194 addr = ( gchar * ) node->data;
8195 compose_entry_append( compose, addr, COMPOSE_TO );
8196 node = g_list_next( node );
8200 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8204 GSList *new_msglist = NULL;
8205 MsgInfo *tmp_msginfo = NULL;
8206 gboolean originally_enc = FALSE;
8207 Compose *compose = NULL;
8209 g_return_if_fail(msgview != NULL);
8211 g_return_if_fail(msginfo_list != NULL);
8213 if (g_slist_length(msginfo_list) == 1) {
8214 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8215 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8217 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8218 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8219 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8220 orig_msginfo, mimeinfo);
8221 if (tmp_msginfo != NULL) {
8222 new_msglist = g_slist_append(NULL, tmp_msginfo);
8223 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8224 originally_enc = TRUE;
8230 body = messageview_get_selection(msgview);
8233 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8234 procmsg_msginfo_free(tmp_msginfo);
8235 g_slist_free(new_msglist);
8237 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8239 if (originally_enc) {
8240 compose_force_encryption(compose, compose->account, FALSE);