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 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2125 G_CALLBACK(compose_changed_cb),
2127 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2128 G_CALLBACK(text_inserted),
2132 msginfo = &dummyinfo;
2134 if (qmark != NULL) {
2135 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2136 quote_fmt_scan_string(qmark);
2139 buf = quote_fmt_get_buffer();
2141 alertpanel_error(_("Quote mark format error."));
2143 Xstrdup_a(quote_str, buf, goto error)
2146 if (fmt && *fmt != '\0') {
2147 while (trimmed_body && strlen(trimmed_body) > 1
2148 && trimmed_body[0]=='\n')
2151 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2152 quote_fmt_scan_string(fmt);
2155 buf = quote_fmt_get_buffer();
2157 alertpanel_error(_("Message reply/forward format error."));
2163 prev_autowrap = compose->autowrap;
2164 compose->autowrap = FALSE;
2166 mark = gtk_text_buffer_get_insert(buffer);
2167 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2168 if (g_utf8_validate(buf, -1, NULL)) {
2169 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2171 gchar *tmpout = NULL;
2172 tmpout = conv_codeset_strdup
2173 (buf, conv_get_locale_charset_str(),
2175 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2177 tmpout = g_malloc(strlen(buf)*2+1);
2178 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2180 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2184 cursor_pos = quote_fmt_get_cursor_pos();
2185 compose->set_cursor_pos = cursor_pos;
2186 if (cursor_pos == -1) {
2189 gtk_text_buffer_get_start_iter(buffer, &iter);
2190 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2191 gtk_text_buffer_place_cursor(buffer, &iter);
2193 compose->autowrap = prev_autowrap;
2194 if (compose->autowrap && rewrap)
2195 compose_wrap_all(compose);
2202 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2203 G_CALLBACK(compose_changed_cb),
2205 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2206 G_CALLBACK(text_inserted),
2213 /* if ml_post is of type addr@host and from is of type
2214 * addr-anything@host, return TRUE
2216 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2218 gchar *left_ml = NULL;
2219 gchar *right_ml = NULL;
2220 gchar *left_from = NULL;
2221 gchar *right_from = NULL;
2222 gboolean result = FALSE;
2224 if (!ml_post || !from)
2227 left_ml = g_strdup(ml_post);
2228 if (strstr(left_ml, "@")) {
2229 right_ml = strstr(left_ml, "@")+1;
2230 *(strstr(left_ml, "@")) = '\0';
2233 left_from = g_strdup(from);
2234 if (strstr(left_from, "@")) {
2235 right_from = strstr(left_from, "@")+1;
2236 *(strstr(left_from, "@")) = '\0';
2239 if (left_ml && left_from && right_ml && right_from
2240 && !strncmp(left_from, left_ml, strlen(left_ml))
2241 && !strcmp(right_from, right_ml)) {
2250 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2252 gchar *my_addr1, *my_addr2;
2254 if (!addr1 || !addr2)
2257 Xstrdup_a(my_addr1, addr1, return FALSE);
2258 Xstrdup_a(my_addr2, addr2, return FALSE);
2260 extract_address(my_addr1);
2261 extract_address(my_addr2);
2263 return !strcmp(my_addr1, my_addr2);
2266 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2267 gboolean to_all, gboolean to_ml,
2269 gboolean followup_and_reply_to)
2271 GSList *cc_list = NULL;
2274 gchar *replyto = NULL;
2275 GHashTable *to_table;
2277 gboolean reply_to_ml = FALSE;
2278 gboolean default_reply_to = FALSE;
2280 g_return_if_fail(compose->account != NULL);
2281 g_return_if_fail(msginfo != NULL);
2283 reply_to_ml = to_ml && compose->ml_post;
2285 default_reply_to = msginfo->folder &&
2286 msginfo->folder->prefs->enable_default_reply_to;
2288 if (compose->account->protocol != A_NNTP) {
2289 if (reply_to_ml && !default_reply_to) {
2291 gboolean is_subscr = is_subscription(compose->ml_post,
2294 /* normal answer to ml post with a reply-to */
2295 compose_entry_append(compose,
2298 if (compose->replyto
2299 && !same_address(compose->ml_post, compose->replyto))
2300 compose_entry_append(compose,
2304 /* answer to subscription confirmation */
2305 if (compose->replyto)
2306 compose_entry_append(compose,
2309 else if (msginfo->from)
2310 compose_entry_append(compose,
2315 else if (!(to_all || to_sender) && default_reply_to) {
2316 compose_entry_append(compose,
2317 msginfo->folder->prefs->default_reply_to,
2319 compose_entry_mark_default_to(compose,
2320 msginfo->folder->prefs->default_reply_to);
2323 Xstrdup_a(tmp1, msginfo->from, return);
2324 extract_address(tmp1);
2325 if (to_all || to_sender ||
2326 !account_find_from_address(tmp1))
2327 compose_entry_append(compose,
2328 (compose->replyto && !to_sender)
2329 ? compose->replyto :
2330 msginfo->from ? msginfo->from : "",
2332 else if (!to_all && !to_sender) {
2333 /* reply to the last list of recipients */
2334 compose_entry_append(compose,
2335 msginfo->to ? msginfo->to : "",
2337 compose_entry_append(compose,
2338 msginfo->cc ? msginfo->cc : "",
2343 if (to_sender || (compose->followup_to &&
2344 !strncmp(compose->followup_to, "poster", 6)))
2345 compose_entry_append
2347 (compose->replyto ? compose->replyto :
2348 msginfo->from ? msginfo->from : ""),
2351 else if (followup_and_reply_to || to_all) {
2352 compose_entry_append
2354 (compose->replyto ? compose->replyto :
2355 msginfo->from ? msginfo->from : ""),
2358 compose_entry_append
2360 compose->followup_to ? compose->followup_to :
2361 compose->newsgroups ? compose->newsgroups : "",
2362 COMPOSE_NEWSGROUPS);
2365 compose_entry_append
2367 compose->followup_to ? compose->followup_to :
2368 compose->newsgroups ? compose->newsgroups : "",
2369 COMPOSE_NEWSGROUPS);
2372 if (msginfo->subject && *msginfo->subject) {
2376 buf = p = g_strdup(msginfo->subject);
2377 p += subject_get_prefix_length(p);
2378 memmove(buf, p, strlen(p) + 1);
2380 buf2 = g_strdup_printf("Re: %s", buf);
2381 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2386 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2388 if (to_ml && compose->ml_post) return;
2389 if (!to_all || compose->account->protocol == A_NNTP) return;
2391 if (compose->replyto) {
2392 Xstrdup_a(replyto, compose->replyto, return);
2393 extract_address(replyto);
2395 if (msginfo->from) {
2396 Xstrdup_a(from, msginfo->from, return);
2397 extract_address(from);
2400 if (replyto && from)
2401 cc_list = address_list_append_with_comments(cc_list, from);
2402 if (to_all && msginfo->folder &&
2403 msginfo->folder->prefs->enable_default_reply_to)
2404 cc_list = address_list_append_with_comments(cc_list,
2405 msginfo->folder->prefs->default_reply_to);
2406 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2407 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2409 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2411 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2412 if (compose->account)
2413 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2414 GINT_TO_POINTER(1));
2416 /* remove address on To: and that of current account */
2417 for (cur = cc_list; cur != NULL; ) {
2418 GSList *next = cur->next;
2421 addr = g_strdup(cur->data);
2422 extract_address(addr);
2424 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2425 cc_list = g_slist_remove(cc_list, cur->data);
2427 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2431 hash_free_strings(to_table);
2432 g_hash_table_destroy(to_table);
2435 for (cur = cc_list; cur != NULL; cur = cur->next)
2436 compose_entry_append(compose, (gchar *)cur->data,
2438 slist_free_strings(cc_list);
2439 g_slist_free(cc_list);
2444 #define SET_ENTRY(entry, str) \
2447 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2450 #define SET_ADDRESS(type, str) \
2453 compose_entry_append(compose, str, type); \
2456 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2458 g_return_if_fail(msginfo != NULL);
2460 SET_ENTRY(subject_entry, msginfo->subject);
2461 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2462 SET_ADDRESS(COMPOSE_CC, compose->cc);
2463 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2464 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2465 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2466 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2468 compose_update_priority_menu_item(compose);
2469 compose_update_privacy_system_menu_item(compose, FALSE);
2470 compose_show_first_last_header(compose, TRUE);
2476 static void compose_insert_sig(Compose *compose, gboolean replace)
2478 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2479 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2481 GtkTextIter iter, iter_end;
2483 gboolean prev_autowrap;
2486 g_return_if_fail(compose->account != NULL);
2488 prev_autowrap = compose->autowrap;
2489 compose->autowrap = FALSE;
2491 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2492 G_CALLBACK(compose_changed_cb),
2495 mark = gtk_text_buffer_get_insert(buffer);
2496 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2497 cur_pos = gtk_text_iter_get_offset (&iter);
2499 gtk_text_buffer_get_end_iter(buffer, &iter);
2501 if (replace && compose->sig_str) {
2503 GtkTextIter first_iter, start_iter, end_iter;
2505 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2507 if (compose->sig_str[0] == '\0')
2510 found = gtk_text_iter_forward_search(&first_iter,
2512 GTK_TEXT_SEARCH_TEXT_ONLY,
2513 &start_iter, &end_iter,
2517 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2522 g_free(compose->sig_str);
2523 compose->sig_str = compose_get_signature_str(compose);
2524 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2525 compose->sig_str = g_strdup("");
2527 cur_pos = gtk_text_iter_get_offset(&iter);
2528 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2530 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2531 gtk_text_iter_forward_char(&iter);
2532 gtk_text_iter_forward_char(&iter);
2533 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2534 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2536 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2537 cur_pos = gtk_text_buffer_get_char_count (buffer);
2539 /* put the cursor where it should be
2540 * either where the quote_fmt says, either before the signature */
2541 if (compose->set_cursor_pos < 0)
2542 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2544 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2545 compose->set_cursor_pos);
2547 gtk_text_buffer_place_cursor(buffer, &iter);
2548 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2549 G_CALLBACK(compose_changed_cb),
2552 compose->autowrap = prev_autowrap;
2553 if (compose->autowrap)
2554 compose_wrap_all(compose);
2557 static gchar *compose_get_signature_str(Compose *compose)
2559 gchar *sig_body = NULL;
2560 gchar *sig_str = NULL;
2561 gchar *utf8_sig_str = NULL;
2563 g_return_val_if_fail(compose->account != NULL, NULL);
2565 if (!compose->account->sig_path)
2568 if (compose->account->sig_type == SIG_FILE) {
2569 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2570 g_warning("can't open signature file: %s\n",
2571 compose->account->sig_path);
2576 if (compose->account->sig_type == SIG_COMMAND)
2577 sig_body = get_command_output(compose->account->sig_path);
2581 tmp = file_read_to_str(compose->account->sig_path);
2584 sig_body = normalize_newlines(tmp);
2588 if (compose->account->sig_sep) {
2589 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2593 sig_str = g_strconcat("\n\n", sig_body, NULL);
2596 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2597 utf8_sig_str = sig_str;
2599 utf8_sig_str = conv_codeset_strdup
2600 (sig_str, conv_get_locale_charset_str(),
2606 return utf8_sig_str;
2609 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2612 GtkTextBuffer *buffer;
2615 const gchar *cur_encoding;
2616 gchar buf[BUFFSIZE];
2619 gboolean prev_autowrap;
2620 gboolean badtxt = FALSE;
2622 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2624 if ((fp = g_fopen(file, "rb")) == NULL) {
2625 FILE_OP_ERROR(file, "fopen");
2626 return COMPOSE_INSERT_READ_ERROR;
2629 prev_autowrap = compose->autowrap;
2630 compose->autowrap = FALSE;
2632 text = GTK_TEXT_VIEW(compose->text);
2633 buffer = gtk_text_view_get_buffer(text);
2634 mark = gtk_text_buffer_get_insert(buffer);
2635 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2637 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2638 G_CALLBACK(text_inserted),
2641 cur_encoding = conv_get_locale_charset_str();
2643 while (fgets(buf, sizeof(buf), fp) != NULL) {
2646 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2647 str = g_strdup(buf);
2649 str = conv_codeset_strdup
2650 (buf, cur_encoding, CS_INTERNAL);
2653 /* strip <CR> if DOS/Windows file,
2654 replace <CR> with <LF> if Macintosh file. */
2657 if (len > 0 && str[len - 1] != '\n') {
2659 if (str[len] == '\r') str[len] = '\n';
2662 gtk_text_buffer_insert(buffer, &iter, str, -1);
2666 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2667 G_CALLBACK(text_inserted),
2669 compose->autowrap = prev_autowrap;
2670 if (compose->autowrap)
2671 compose_wrap_all(compose);
2676 return COMPOSE_INSERT_INVALID_CHARACTER;
2678 return COMPOSE_INSERT_SUCCESS;
2681 static void compose_attach_append(Compose *compose, const gchar *file,
2682 const gchar *filename,
2683 const gchar *content_type)
2691 GtkListStore *store;
2694 if (!is_file_exist(file)) {
2695 g_warning("File %s doesn't exist\n", filename);
2698 if ((size = get_file_size(file)) < 0) {
2699 g_warning("Can't get file size of %s\n", filename);
2703 alertpanel_notice(_("File %s is empty."), filename);
2706 if ((fp = g_fopen(file, "rb")) == NULL) {
2707 alertpanel_error(_("Can't read %s."), filename);
2712 ainfo = g_new0(AttachInfo, 1);
2713 auto_ainfo = g_auto_pointer_new_with_free
2714 (ainfo, (GFreeFunc) compose_attach_info_free);
2715 ainfo->file = g_strdup(file);
2718 ainfo->content_type = g_strdup(content_type);
2719 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2721 MsgFlags flags = {0, 0};
2723 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2724 ainfo->encoding = ENC_7BIT;
2726 ainfo->encoding = ENC_8BIT;
2728 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2729 if (msginfo && msginfo->subject)
2730 name = g_strdup(msginfo->subject);
2732 name = g_path_get_basename(filename ? filename : file);
2734 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2736 procmsg_msginfo_free(msginfo);
2738 if (!g_ascii_strncasecmp(content_type, "text", 4))
2739 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2741 ainfo->encoding = ENC_BASE64;
2742 name = g_path_get_basename(filename ? filename : file);
2743 ainfo->name = g_strdup(name);
2747 ainfo->content_type = procmime_get_mime_type(file);
2748 if (!ainfo->content_type) {
2749 ainfo->content_type =
2750 g_strdup("application/octet-stream");
2751 ainfo->encoding = ENC_BASE64;
2752 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2754 procmime_get_encoding_for_text_file(file);
2756 ainfo->encoding = ENC_BASE64;
2757 name = g_path_get_basename(filename ? filename : file);
2758 ainfo->name = g_strdup(name);
2762 if (!strcmp(ainfo->content_type, "unknown")) {
2763 g_free(ainfo->content_type);
2764 ainfo->content_type = g_strdup("application/octet-stream");
2768 size_text = to_human_readable(size);
2770 store = GTK_LIST_STORE(gtk_tree_view_get_model
2771 (GTK_TREE_VIEW(compose->attach_clist)));
2773 gtk_list_store_append(store, &iter);
2774 gtk_list_store_set(store, &iter,
2775 COL_MIMETYPE, ainfo->content_type,
2776 COL_SIZE, size_text,
2777 COL_NAME, ainfo->name,
2779 COL_AUTODATA, auto_ainfo,
2782 g_auto_pointer_free(auto_ainfo);
2785 static void compose_use_signing(Compose *compose, gboolean use_signing)
2787 GtkItemFactory *ifactory;
2788 GtkWidget *menuitem = NULL;
2790 compose->use_signing = use_signing;
2791 ifactory = gtk_item_factory_from_widget(compose->menubar);
2792 menuitem = gtk_item_factory_get_item
2793 (ifactory, "/Options/Sign");
2794 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2798 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2800 GtkItemFactory *ifactory;
2801 GtkWidget *menuitem = NULL;
2803 compose->use_encryption = use_encryption;
2804 ifactory = gtk_item_factory_from_widget(compose->menubar);
2805 menuitem = gtk_item_factory_get_item
2806 (ifactory, "/Options/Encrypt");
2808 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2812 #define NEXT_PART_NOT_CHILD(info) \
2814 node = info->node; \
2815 while (node->children) \
2816 node = g_node_last_child(node); \
2817 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2820 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2824 MimeInfo *firsttext = NULL;
2825 MimeInfo *encrypted = NULL;
2828 const gchar *partname = NULL;
2830 mimeinfo = procmime_scan_message(msginfo);
2831 if (!mimeinfo) return;
2833 if (mimeinfo->node->children == NULL) {
2834 procmime_mimeinfo_free_all(mimeinfo);
2838 /* find first content part */
2839 child = (MimeInfo *) mimeinfo->node->children->data;
2840 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2841 child = (MimeInfo *)child->node->children->data;
2843 if (child->type == MIMETYPE_TEXT) {
2845 debug_print("First text part found\n");
2846 } else if (compose->mode == COMPOSE_REEDIT &&
2847 child->type == MIMETYPE_APPLICATION &&
2848 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2849 encrypted = (MimeInfo *)child->node->parent->data;
2852 child = (MimeInfo *) mimeinfo->node->children->data;
2853 while (child != NULL) {
2854 if (child == encrypted) {
2855 /* skip this part of tree */
2856 NEXT_PART_NOT_CHILD(child);
2860 if (child->type == MIMETYPE_MULTIPART) {
2861 /* get the actual content */
2862 child = procmime_mimeinfo_next(child);
2866 if (child == firsttext) {
2867 child = procmime_mimeinfo_next(child);
2871 outfile = procmime_get_tmp_file_name(child);
2872 if (procmime_get_part(outfile, child) < 0)
2873 g_warning("Can't get the part of multipart message.");
2875 gchar *content_type;
2877 content_type = procmime_get_content_type_str(child->type, child->subtype);
2879 /* if we meet a pgp signature, we don't attach it, but
2880 * we force signing. */
2881 if (strcmp(content_type, "application/pgp-signature")) {
2882 partname = procmime_mimeinfo_get_parameter(child, "filename");
2883 if (partname == NULL)
2884 partname = procmime_mimeinfo_get_parameter(child, "name");
2885 if (partname == NULL)
2887 compose_attach_append(compose, outfile,
2888 partname, content_type);
2890 compose_force_signing(compose, compose->account);
2892 g_free(content_type);
2895 NEXT_PART_NOT_CHILD(child);
2897 procmime_mimeinfo_free_all(mimeinfo);
2900 #undef NEXT_PART_NOT_CHILD
2905 WAIT_FOR_INDENT_CHAR,
2906 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2909 /* return indent length, we allow:
2910 indent characters followed by indent characters or spaces/tabs,
2911 alphabets and numbers immediately followed by indent characters,
2912 and the repeating sequences of the above
2913 If quote ends with multiple spaces, only the first one is included. */
2914 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2915 const GtkTextIter *start, gint *len)
2917 GtkTextIter iter = *start;
2921 IndentState state = WAIT_FOR_INDENT_CHAR;
2924 gint alnum_count = 0;
2925 gint space_count = 0;
2928 if (prefs_common.quote_chars == NULL) {
2932 while (!gtk_text_iter_ends_line(&iter)) {
2933 wc = gtk_text_iter_get_char(&iter);
2934 if (g_unichar_iswide(wc))
2936 clen = g_unichar_to_utf8(wc, ch);
2940 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2941 is_space = g_unichar_isspace(wc);
2943 if (state == WAIT_FOR_INDENT_CHAR) {
2944 if (!is_indent && !g_unichar_isalnum(wc))
2947 quote_len += alnum_count + space_count + 1;
2948 alnum_count = space_count = 0;
2949 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2952 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2953 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
2957 else if (is_indent) {
2958 quote_len += alnum_count + space_count + 1;
2959 alnum_count = space_count = 0;
2962 state = WAIT_FOR_INDENT_CHAR;
2966 gtk_text_iter_forward_char(&iter);
2969 if (quote_len > 0 && space_count > 0)
2975 if (quote_len > 0) {
2977 gtk_text_iter_forward_chars(&iter, quote_len);
2978 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
2984 /* return TRUE if the line is itemized */
2985 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
2986 const GtkTextIter *start)
2988 GtkTextIter iter = *start;
2993 if (gtk_text_iter_ends_line(&iter))
2997 wc = gtk_text_iter_get_char(&iter);
2998 if (!g_unichar_isspace(wc))
3000 gtk_text_iter_forward_char(&iter);
3001 if (gtk_text_iter_ends_line(&iter))
3005 clen = g_unichar_to_utf8(wc, ch);
3009 if (!strchr("*-+", ch[0]))
3012 gtk_text_iter_forward_char(&iter);
3013 if (gtk_text_iter_ends_line(&iter))
3015 wc = gtk_text_iter_get_char(&iter);
3016 if (g_unichar_isspace(wc))
3022 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3023 const GtkTextIter *start,
3024 GtkTextIter *break_pos,
3028 GtkTextIter iter = *start, line_end = *start;
3029 PangoLogAttr *attrs;
3036 gboolean can_break = FALSE;
3037 gboolean do_break = FALSE;
3038 gboolean was_white = FALSE;
3039 gboolean prev_dont_break = FALSE;
3041 gtk_text_iter_forward_to_line_end(&line_end);
3042 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3043 len = g_utf8_strlen(str, -1);
3044 /* g_print("breaking line: %d: %s (len = %d)\n",
3045 gtk_text_iter_get_line(&iter), str, len); */
3046 attrs = g_new(PangoLogAttr, len + 1);
3048 pango_default_break(str, -1, NULL, attrs, len + 1);
3052 /* skip quote and leading spaces */
3053 for (i = 0; *p != '\0' && i < len; i++) {
3056 wc = g_utf8_get_char(p);
3057 if (i >= quote_len && !g_unichar_isspace(wc))
3059 if (g_unichar_iswide(wc))
3061 else if (*p == '\t')
3065 p = g_utf8_next_char(p);
3068 for (; *p != '\0' && i < len; i++) {
3069 PangoLogAttr *attr = attrs + i;
3073 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3076 was_white = attr->is_white;
3078 /* don't wrap URI */
3079 if ((uri_len = get_uri_len(p)) > 0) {
3081 if (pos > 0 && col > max_col) {
3091 wc = g_utf8_get_char(p);
3092 if (g_unichar_iswide(wc)) {
3094 if (prev_dont_break && can_break && attr->is_line_break)
3096 } else if (*p == '\t')
3100 if (pos > 0 && col > max_col) {
3105 if (*p == '-' || *p == '/')
3106 prev_dont_break = TRUE;
3108 prev_dont_break = FALSE;
3110 p = g_utf8_next_char(p);
3114 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3119 *break_pos = *start;
3120 gtk_text_iter_set_line_offset(break_pos, pos);
3125 static gboolean compose_join_next_line(Compose *compose,
3126 GtkTextBuffer *buffer,
3128 const gchar *quote_str)
3130 GtkTextIter iter_ = *iter, cur, prev, next, end;
3131 PangoLogAttr attrs[3];
3133 gchar *next_quote_str;
3136 gboolean keep_cursor = FALSE;
3138 if (!gtk_text_iter_forward_line(&iter_) ||
3139 gtk_text_iter_ends_line(&iter_))
3142 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3144 if ((quote_str || next_quote_str) &&
3145 strcmp2(quote_str, next_quote_str) != 0) {
3146 g_free(next_quote_str);
3149 g_free(next_quote_str);
3152 if (quote_len > 0) {
3153 gtk_text_iter_forward_chars(&end, quote_len);
3154 if (gtk_text_iter_ends_line(&end))
3158 /* don't join itemized lines */
3159 if (compose_is_itemized(buffer, &end))
3162 /* don't join signature separator */
3163 if (compose_is_sig_separator(compose, buffer, &iter_))
3166 /* delete quote str */
3168 gtk_text_buffer_delete(buffer, &iter_, &end);
3170 /* delete linebreak and extra spaces */
3172 while (gtk_text_iter_backward_char(&cur)) {
3173 wc1 = gtk_text_iter_get_char(&cur);
3174 if (!g_unichar_isspace(wc1))
3179 while (!gtk_text_iter_ends_line(&cur)) {
3180 wc1 = gtk_text_iter_get_char(&cur);
3181 if (!g_unichar_isspace(wc1))
3183 gtk_text_iter_forward_char(&cur);
3186 if (!gtk_text_iter_equal(&prev, &next)) {
3189 mark = gtk_text_buffer_get_insert(buffer);
3190 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3191 if (gtk_text_iter_equal(&prev, &cur))
3193 gtk_text_buffer_delete(buffer, &prev, &next);
3197 /* insert space if required */
3198 gtk_text_iter_backward_char(&prev);
3199 wc1 = gtk_text_iter_get_char(&prev);
3200 wc2 = gtk_text_iter_get_char(&next);
3201 gtk_text_iter_forward_char(&next);
3202 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3203 pango_default_break(str, -1, NULL, attrs, 3);
3204 if (!attrs[1].is_line_break ||
3205 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3206 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3208 gtk_text_iter_backward_char(&iter_);
3209 gtk_text_buffer_place_cursor(buffer, &iter_);
3218 #define ADD_TXT_POS(bp_, ep_, pti_) \
3219 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3220 last = last->next; \
3221 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3222 last->next = NULL; \
3224 g_warning("alloc error scanning URIs\n"); \
3227 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3229 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3230 GtkTextBuffer *buffer;
3231 GtkTextIter iter, break_pos, end_of_line;
3232 gchar *quote_str = NULL;
3234 gboolean wrap_quote = prefs_common.linewrap_quote;
3235 gboolean prev_autowrap = compose->autowrap;
3236 gint startq_offset = -1, noq_offset = -1;
3237 gint uri_start = -1, uri_stop = -1;
3238 gint nouri_start = -1, nouri_stop = -1;
3240 compose->autowrap = FALSE;
3242 buffer = gtk_text_view_get_buffer(text);
3243 undo_wrapping(compose->undostruct, TRUE);
3248 mark = gtk_text_buffer_get_insert(buffer);
3249 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3252 /* move to paragraph start */
3253 gtk_text_iter_set_line_offset(&iter, 0);
3254 if (gtk_text_iter_ends_line(&iter)) {
3255 while (gtk_text_iter_ends_line(&iter) &&
3256 gtk_text_iter_forward_line(&iter))
3259 while (gtk_text_iter_backward_line(&iter)) {
3260 if (gtk_text_iter_ends_line(&iter)) {
3261 gtk_text_iter_forward_line(&iter);
3267 /* go until paragraph end (empty line) */
3268 while (!gtk_text_iter_ends_line(&iter)) {
3269 gchar *scanpos = NULL;
3270 /* parse table - in order of priority */
3272 const gchar *needle; /* token */
3274 /* token search function */
3275 gchar *(*search) (const gchar *haystack,
3276 const gchar *needle);
3277 /* part parsing function */
3278 gboolean (*parse) (const gchar *start,
3279 const gchar *scanpos,
3283 /* part to URI function */
3284 gchar *(*build_uri) (const gchar *bp,
3288 static struct table parser[] = {
3289 {"http://", strcasestr, get_uri_part, make_uri_string},
3290 {"https://", strcasestr, get_uri_part, make_uri_string},
3291 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3292 {"www.", strcasestr, get_uri_part, make_http_string},
3293 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3294 {"@", strcasestr, get_email_part, make_email_string}
3296 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3297 gint last_index = PARSE_ELEMS;
3299 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3302 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3305 uri_start = uri_stop = -1;
3306 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3310 if (startq_offset == -1) {
3311 startq_offset = gtk_text_iter_get_offset(&iter);
3315 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3316 if (startq_offset == -1)
3317 startq_offset = gtk_text_iter_get_offset(&iter);
3319 if (startq_offset == -1)
3320 noq_offset = gtk_text_iter_get_offset(&iter);
3323 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3326 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3327 prefs_common.linewrap_len,
3329 GtkTextIter prev, next, cur;
3331 if (prev_autowrap != FALSE || force)
3332 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3333 else if (quote_str && wrap_quote)
3334 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3337 /* remove trailing spaces */
3339 gtk_text_iter_backward_char(&cur);
3341 while (!gtk_text_iter_starts_line(&cur)) {
3344 gtk_text_iter_backward_char(&cur);
3345 wc = gtk_text_iter_get_char(&cur);
3346 if (!g_unichar_isspace(wc))
3350 if (!gtk_text_iter_equal(&prev, &next)) {
3351 gtk_text_buffer_delete(buffer, &prev, &next);
3353 gtk_text_iter_forward_char(&break_pos);
3357 gtk_text_buffer_insert(buffer, &break_pos,
3361 compose_join_next_line(compose, buffer, &iter, quote_str);
3363 /* move iter to current line start */
3364 gtk_text_iter_set_line_offset(&iter, 0);
3371 /* move iter to next line start */
3377 while (!gtk_text_iter_ends_line(&end_of_line)) {
3378 gtk_text_iter_forward_char(&end_of_line);
3380 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3382 nouri_start = gtk_text_iter_get_offset(&iter);
3383 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3385 walk_pos = gtk_text_iter_get_offset(&iter);
3386 /* FIXME: this looks phony. scanning for anything in the parse table */
3387 for (n = 0; n < PARSE_ELEMS; n++) {
3390 tmp = parser[n].search(walk, parser[n].needle);
3392 if (scanpos == NULL || tmp < scanpos) {
3401 /* check if URI can be parsed */
3402 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3403 (const gchar **)&ep, FALSE)
3404 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3408 strlen(parser[last_index].needle);
3411 uri_start = walk_pos + (bp - o_walk);
3412 uri_stop = walk_pos + (ep - o_walk);
3416 gtk_text_iter_forward_line(&iter);
3419 if (startq_offset != -1) {
3420 GtkTextIter startquote, endquote;
3421 gtk_text_buffer_get_iter_at_offset(
3422 buffer, &startquote, startq_offset);
3424 gtk_text_buffer_apply_tag_by_name(
3425 buffer, "quote", &startquote, &endquote);
3427 } else if (noq_offset != -1) {
3428 GtkTextIter startnoquote, endnoquote;
3429 gtk_text_buffer_get_iter_at_offset(
3430 buffer, &startnoquote, noq_offset);
3432 gtk_text_buffer_remove_tag_by_name(
3433 buffer, "quote", &startnoquote, &endnoquote);
3438 GtkTextIter nouri_start_iter, nouri_end_iter;
3439 gtk_text_buffer_get_iter_at_offset(
3440 buffer, &nouri_start_iter, nouri_start);
3441 gtk_text_buffer_get_iter_at_offset(
3442 buffer, &nouri_end_iter, nouri_stop);
3443 gtk_text_buffer_remove_tag_by_name(
3444 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3446 if (uri_start > 0 && uri_stop > 0) {
3447 GtkTextIter uri_start_iter, uri_end_iter;
3448 gtk_text_buffer_get_iter_at_offset(
3449 buffer, &uri_start_iter, uri_start);
3450 gtk_text_buffer_get_iter_at_offset(
3451 buffer, &uri_end_iter, uri_stop);
3452 gtk_text_buffer_apply_tag_by_name(
3453 buffer, "link", &uri_start_iter, &uri_end_iter);
3459 undo_wrapping(compose->undostruct, FALSE);
3460 compose->autowrap = prev_autowrap;
3463 void compose_action_cb(void *data)
3465 Compose *compose = (Compose *)data;
3466 compose_wrap_all(compose);
3469 static void compose_wrap_all(Compose *compose)
3471 compose_wrap_all_full(compose, FALSE);
3474 static void compose_wrap_all_full(Compose *compose, gboolean force)
3476 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3477 GtkTextBuffer *buffer;
3480 buffer = gtk_text_view_get_buffer(text);
3482 gtk_text_buffer_get_start_iter(buffer, &iter);
3483 while (!gtk_text_iter_is_end(&iter))
3484 compose_beautify_paragraph(compose, &iter, force);
3488 static void compose_set_title(Compose *compose)
3494 edited = compose->modified ? _(" [Edited]") : "";
3496 subject = gtk_editable_get_chars(
3497 GTK_EDITABLE(compose->subject_entry), 0, -1);
3499 if (subject && strlen(subject))
3500 str = g_strdup_printf(_("%s - Compose message%s"),
3503 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3504 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3510 * compose_current_mail_account:
3512 * Find a current mail account (the currently selected account, or the
3513 * default account, if a news account is currently selected). If a
3514 * mail account cannot be found, display an error message.
3516 * Return value: Mail account, or NULL if not found.
3518 static PrefsAccount *
3519 compose_current_mail_account(void)
3523 if (cur_account && cur_account->protocol != A_NNTP)
3526 ac = account_get_default();
3527 if (!ac || ac->protocol == A_NNTP) {
3528 alertpanel_error(_("Account for sending mail is not specified.\n"
3529 "Please select a mail account before sending."));
3536 static void compose_select_account(Compose *compose, PrefsAccount *account,
3539 GtkItemFactory *ifactory;
3541 g_return_if_fail(account != NULL);
3543 compose->account = account;
3545 compose_set_title(compose);
3547 ifactory = gtk_item_factory_from_widget(compose->menubar);
3549 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3550 menu_set_active(ifactory, "/Options/Sign", TRUE);
3552 menu_set_active(ifactory, "/Options/Sign", FALSE);
3553 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3554 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3556 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3558 activate_privacy_system(compose, account, FALSE);
3560 if (!init && compose->mode != COMPOSE_REDIRECT)
3561 compose_insert_sig(compose, TRUE);
3564 gboolean compose_check_for_valid_recipient(Compose *compose) {
3565 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3566 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3567 gboolean recipient_found = FALSE;
3571 /* free to and newsgroup list */
3572 slist_free_strings(compose->to_list);
3573 g_slist_free(compose->to_list);
3574 compose->to_list = NULL;
3576 slist_free_strings(compose->newsgroup_list);
3577 g_slist_free(compose->newsgroup_list);
3578 compose->newsgroup_list = NULL;
3580 /* search header entries for to and newsgroup entries */
3581 for (list = compose->header_list; list; list = list->next) {
3584 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3585 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3587 if (entry[0] != '\0') {
3588 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3589 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3590 compose->to_list = address_list_append(compose->to_list, entry);
3591 recipient_found = TRUE;
3594 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3595 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3596 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3597 recipient_found = TRUE;
3604 return recipient_found;
3607 static gboolean compose_check_for_set_recipients(Compose *compose)
3609 if (compose->account->set_autocc && compose->account->auto_cc) {
3610 gboolean found_other = FALSE;
3612 /* search header entries for to and newsgroup entries */
3613 for (list = compose->header_list; list; list = list->next) {
3616 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3617 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3619 if (strcmp(entry, compose->account->auto_cc)
3620 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3630 aval = alertpanel(_("Send"),
3631 _("The only recipient is the default CC address. Send anyway?"),
3632 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3633 if (aval != G_ALERTDEFAULT)
3637 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3638 gboolean found_other = FALSE;
3640 /* search header entries for to and newsgroup entries */
3641 for (list = compose->header_list; list; list = list->next) {
3644 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3645 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3647 if (strcmp(entry, compose->account->auto_cc)
3648 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3658 aval = alertpanel(_("Send"),
3659 _("The only recipient is the default BCC address. Send anyway?"),
3660 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3661 if (aval != G_ALERTDEFAULT)
3668 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3672 if (compose_check_for_valid_recipient(compose) == FALSE) {
3673 alertpanel_error(_("Recipient is not specified."));
3677 if (compose_check_for_set_recipients(compose) == FALSE) {
3681 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3682 if (*str == '\0' && check_subject == TRUE) {
3685 aval = alertpanel(_("Send"),
3686 _("Subject is empty. Send it anyway?"),
3687 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3688 if (aval != G_ALERTDEFAULT)
3695 gint compose_send(Compose *compose)
3702 compose_allow_user_actions (compose, FALSE);
3703 compose->sending = TRUE;
3705 if (compose_check_entries(compose, TRUE) == FALSE)
3708 val = compose_queue(compose, &msgnum, &folder);
3712 alertpanel_error(_("Could not queue message for sending:\n\n"
3713 "Charset conversion failed."));
3714 } else if (val == -3) {
3715 alertpanel_error(_("Could not queue message for sending:\n\n"
3716 "Signature failed."));
3717 } else if (val == -2) {
3718 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3720 alertpanel_error(_("Could not queue message for sending."));
3726 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3727 compose->sending = FALSE;
3728 compose_close(compose);
3729 /* No more compose access in the normal codepath
3730 * after this point! */
3735 alertpanel_error(_("The message was queued but could not be "
3736 "sent.\nUse \"Send queued messages\" from "
3737 "the main window to retry."));
3738 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3739 compose->sending = FALSE;
3740 compose_allow_user_actions (compose, TRUE);
3745 msgpath = folder_item_fetch_msg(folder, msgnum);
3746 val = procmsg_send_message_queue(msgpath);
3749 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3750 compose->sending = FALSE;
3751 compose_allow_user_actions (compose, TRUE);
3753 folder_item_remove_msg(folder, msgnum);
3754 folder_item_scan(folder);
3759 folder_item_remove_msg(folder, msgnum);
3760 folder_item_scan(folder);
3761 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3762 compose_close(compose);
3764 alertpanel_error(_("The message was queued but could not be "
3765 "sent.\nUse \"Send queued messages\" from "
3766 "the main window to retry."));
3767 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3768 compose_allow_user_actions (compose, TRUE);
3769 compose->sending = FALSE;
3777 compose_allow_user_actions (compose, TRUE);
3778 compose->sending = FALSE;
3783 static gboolean compose_use_attach(Compose *compose)
3785 GtkTreeModel *model = gtk_tree_view_get_model
3786 (GTK_TREE_VIEW(compose->attach_clist));
3787 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3790 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3793 gchar buf[BUFFSIZE];
3795 gboolean first_to_address;
3796 gboolean first_cc_address;
3798 ComposeHeaderEntry *headerentry;
3799 const gchar *headerentryname;
3803 debug_print("Writing redirect header\n");
3805 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3806 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3808 first_to_address = TRUE;
3809 for (list = compose->header_list; list; list = list->next) {
3810 headerentry = ((ComposeHeaderEntry *)list->data);
3811 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3813 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3814 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3815 Xstrdup_a(str, entstr, return -1);
3817 if (str[0] != '\0') {
3818 compose_convert_header
3819 (compose, buf, sizeof(buf), str,
3820 strlen("Resent-To") + 2, TRUE);
3822 if (first_to_address) {
3823 fprintf(fp, "Resent-To: ");
3824 first_to_address = FALSE;
3828 fprintf(fp, "%s", buf);
3832 if (!first_to_address) {
3836 first_cc_address = TRUE;
3837 for (list = compose->header_list; list; list = list->next) {
3838 headerentry = ((ComposeHeaderEntry *)list->data);
3839 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3841 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3842 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3843 Xstrdup_a(str, strg, return -1);
3845 if (str[0] != '\0') {
3846 compose_convert_header
3847 (compose, buf, sizeof(buf), str,
3848 strlen("Resent-Cc") + 2, TRUE);
3850 if (first_cc_address) {
3851 fprintf(fp, "Resent-Cc: ");
3852 first_cc_address = FALSE;
3856 fprintf(fp, "%s", buf);
3860 if (!first_cc_address) {
3867 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3869 gchar buf[BUFFSIZE];
3871 const gchar *entstr;
3872 /* struct utsname utsbuf; */
3874 g_return_val_if_fail(fp != NULL, -1);
3875 g_return_val_if_fail(compose->account != NULL, -1);
3876 g_return_val_if_fail(compose->account->address != NULL, -1);
3879 get_rfc822_date(buf, sizeof(buf));
3880 fprintf(fp, "Resent-Date: %s\n", buf);
3883 if (compose->account->name && *compose->account->name) {
3884 compose_convert_header
3885 (compose, buf, sizeof(buf), compose->account->name,
3886 strlen("From: "), TRUE);
3887 fprintf(fp, "Resent-From: %s <%s>\n",
3888 buf, compose->account->address);
3890 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3893 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3894 if (*entstr != '\0') {
3895 Xstrdup_a(str, entstr, return -1);
3898 compose_convert_header(compose, buf, sizeof(buf), str,
3899 strlen("Subject: "), FALSE);
3900 fprintf(fp, "Subject: %s\n", buf);
3904 /* Resent-Message-ID */
3905 if (compose->account->gen_msgid) {
3906 generate_msgid(buf, sizeof(buf));
3907 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3908 compose->msgid = g_strdup(buf);
3911 compose_redirect_write_headers_from_headerlist(compose, fp);
3913 /* separator between header and body */
3919 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3923 gchar buf[BUFFSIZE];
3925 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
3926 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3930 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3931 /* should filter returnpath, delivered-to */
3932 if (g_ascii_strncasecmp(buf, "Return-Path:",
3933 strlen("Return-Path:")) == 0 ||
3934 g_ascii_strncasecmp(buf, "Delivered-To:",
3935 strlen("Delivered-To:")) == 0 ||
3936 g_ascii_strncasecmp(buf, "Received:",
3937 strlen("Received:")) == 0 ||
3938 g_ascii_strncasecmp(buf, "Subject:",
3939 strlen("Subject:")) == 0 ||
3940 g_ascii_strncasecmp(buf, "X-UIDL:",
3941 strlen("X-UIDL:")) == 0)
3944 if (fputs(buf, fdest) == -1)
3947 if (!prefs_common.redirect_keep_from) {
3948 if (g_ascii_strncasecmp(buf, "From:",
3949 strlen("From:")) == 0) {
3950 fputs(" (by way of ", fdest);
3951 if (compose->account->name
3952 && *compose->account->name) {
3953 compose_convert_header
3954 (compose, buf, sizeof(buf),
3955 compose->account->name,
3958 fprintf(fdest, "%s <%s>",
3960 compose->account->address);
3962 fprintf(fdest, "%s",
3963 compose->account->address);
3968 if (fputs("\n", fdest) == -1)
3972 compose_redirect_write_headers(compose, fdest);
3974 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3975 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
3988 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
3990 GtkTextBuffer *buffer;
3991 GtkTextIter start, end;
3994 const gchar *out_codeset;
3995 EncodingType encoding;
3996 MimeInfo *mimemsg, *mimetext;
3999 /* create message MimeInfo */
4000 mimemsg = procmime_mimeinfo_new();
4001 mimemsg->type = MIMETYPE_MESSAGE;
4002 mimemsg->subtype = g_strdup("rfc822");
4003 mimemsg->content = MIMECONTENT_MEM;
4004 mimemsg->tmp = TRUE; /* must free content later */
4005 mimemsg->data.mem = compose_get_header(compose);
4007 /* Create text part MimeInfo */
4008 /* get all composed text */
4009 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4010 gtk_text_buffer_get_start_iter(buffer, &start);
4011 gtk_text_buffer_get_end_iter(buffer, &end);
4012 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4013 if (is_ascii_str(chars)) {
4016 out_codeset = CS_US_ASCII;
4017 encoding = ENC_7BIT;
4019 const gchar *src_codeset = CS_INTERNAL;
4021 out_codeset = conv_get_charset_str(compose->out_encoding);
4024 gchar *test_conv_global_out = NULL;
4025 gchar *test_conv_reply = NULL;
4027 /* automatic mode. be automatic. */
4028 codeconv_set_strict(TRUE);
4030 out_codeset = conv_get_outgoing_charset_str();
4032 debug_print("trying to convert to %s\n", out_codeset);
4033 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4036 if (!test_conv_global_out && compose->orig_charset) {
4037 out_codeset = compose->orig_charset;
4038 debug_print("failure; trying to convert to %s\n", out_codeset);
4039 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4042 if (!test_conv_global_out && !test_conv_reply) {
4044 out_codeset = CS_INTERNAL;
4045 debug_print("finally using %s\n", out_codeset);
4047 g_free(test_conv_global_out);
4048 g_free(test_conv_reply);
4049 codeconv_set_strict(FALSE);
4052 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4053 out_codeset = CS_ISO_8859_1;
4055 if (prefs_common.encoding_method == CTE_BASE64)
4056 encoding = ENC_BASE64;
4057 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4058 encoding = ENC_QUOTED_PRINTABLE;
4059 else if (prefs_common.encoding_method == CTE_8BIT)
4060 encoding = ENC_8BIT;
4062 encoding = procmime_get_encoding_for_charset(out_codeset);
4064 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4065 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4067 if (action == COMPOSE_WRITE_FOR_SEND) {
4068 codeconv_set_strict(TRUE);
4069 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4070 codeconv_set_strict(FALSE);
4076 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4077 "to the specified %s charset.\n"
4078 "Send it as %s?"), out_codeset, src_codeset);
4079 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_YES, GTK_STOCK_NO, NULL, FALSE,
4080 NULL, ALERT_ERROR, G_ALERTALTERNATE);
4083 if (aval != G_ALERTDEFAULT) {
4088 out_codeset = src_codeset;
4094 out_codeset = src_codeset;
4100 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4101 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4102 strstr(buf, "\nFrom ") != NULL) {
4103 encoding = ENC_QUOTED_PRINTABLE;
4107 mimetext = procmime_mimeinfo_new();
4108 mimetext->content = MIMECONTENT_MEM;
4109 mimetext->tmp = TRUE; /* must free content later */
4110 mimetext->data.mem = buf;
4111 mimetext->type = MIMETYPE_TEXT;
4112 mimetext->subtype = g_strdup("plain");
4113 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4114 g_strdup(out_codeset));
4115 /* protect trailing spaces when signing message */
4116 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4117 privacy_system_can_sign(compose->privacy_system)) {
4118 encoding = ENC_QUOTED_PRINTABLE;
4121 /* check for line length limit */
4122 if (action == COMPOSE_WRITE_FOR_SEND &&
4123 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4124 check_line_length(buf, 1000, &line) < 0) {
4128 msg = g_strdup_printf
4129 (_("Line %d exceeds the line length limit (998 bytes).\n"
4130 "The contents of the message might be broken on the way to the delivery.\n"
4132 "Send it anyway?"), line + 1);
4133 aval = alertpanel(_("Warning"), msg, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
4135 if (aval != G_ALERTDEFAULT) {
4140 if (encoding != ENC_UNKNOWN)
4141 procmime_encode_content(mimetext, encoding);
4143 /* append attachment parts */
4144 if (compose_use_attach(compose)) {
4145 MimeInfo *mimempart;
4146 gchar *boundary = NULL;
4147 mimempart = procmime_mimeinfo_new();
4148 mimempart->content = MIMECONTENT_EMPTY;
4149 mimempart->type = MIMETYPE_MULTIPART;
4150 mimempart->subtype = g_strdup("mixed");
4155 boundary = generate_mime_boundary(NULL);
4156 } while (strstr(buf, boundary) != NULL);
4158 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4161 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4163 g_node_append(mimempart->node, mimetext->node);
4164 g_node_append(mimemsg->node, mimempart->node);
4166 compose_add_attachments(compose, mimempart);
4168 g_node_append(mimemsg->node, mimetext->node);
4170 /* sign message if sending */
4171 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4172 privacy_system_can_sign(compose->privacy_system))
4173 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4176 procmime_write_mimeinfo(mimemsg, fp);
4178 procmime_mimeinfo_free_all(mimemsg);
4183 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4185 GtkTextBuffer *buffer;
4186 GtkTextIter start, end;
4191 if ((fp = g_fopen(file, "wb")) == NULL) {
4192 FILE_OP_ERROR(file, "fopen");
4196 /* chmod for security */
4197 if (change_file_mode_rw(fp, file) < 0) {
4198 FILE_OP_ERROR(file, "chmod");
4199 g_warning("can't change file mode\n");
4202 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4203 gtk_text_buffer_get_start_iter(buffer, &start);
4204 gtk_text_buffer_get_end_iter(buffer, &end);
4205 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4207 chars = conv_codeset_strdup
4208 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4211 if (!chars) return -1;
4214 len = strlen(chars);
4215 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4216 FILE_OP_ERROR(file, "fwrite");
4225 if (fclose(fp) == EOF) {
4226 FILE_OP_ERROR(file, "fclose");
4233 static gint compose_remove_reedit_target(Compose *compose)
4236 MsgInfo *msginfo = compose->targetinfo;
4238 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4239 if (!msginfo) return -1;
4241 item = msginfo->folder;
4242 g_return_val_if_fail(item != NULL, -1);
4244 if (procmsg_msg_exist(msginfo) &&
4245 (folder_has_parent_of_type(item, F_QUEUE) ||
4246 folder_has_parent_of_type(item, F_DRAFT)
4247 || msginfo == compose->autosaved_draft)) {
4248 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4249 g_warning("can't remove the old message\n");
4257 void compose_remove_draft(Compose *compose)
4260 MsgInfo *msginfo = compose->targetinfo;
4261 drafts = account_get_special_folder(compose->account, F_DRAFT);
4263 if (procmsg_msg_exist(msginfo)) {
4264 folder_item_remove_msg(drafts, msginfo->msgnum);
4269 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
4271 return compose_queue_sub (compose, msgnum, item, FALSE);
4273 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
4280 static gboolean lock = FALSE;
4281 PrefsAccount *mailac = NULL, *newsac = NULL;
4283 debug_print("queueing message...\n");
4284 g_return_val_if_fail(compose->account != NULL, -1);
4288 if (compose_check_entries(compose, check_subject) == FALSE) {
4293 if (!compose->to_list && !compose->newsgroup_list) {
4294 g_warning("can't get recipient list.");
4299 if (compose->to_list) {
4300 if (compose->account->protocol != A_NNTP)
4301 mailac = compose->account;
4302 else if (cur_account && cur_account->protocol != A_NNTP)
4303 mailac = cur_account;
4304 else if (!(mailac = compose_current_mail_account())) {
4306 alertpanel_error(_("No account for sending mails available!"));
4311 if (compose->newsgroup_list) {
4312 if (compose->account->protocol == A_NNTP)
4313 newsac = compose->account;
4314 else if (!newsac->protocol != A_NNTP) {
4316 alertpanel_error(_("No account for posting news available!"));
4321 if (prefs_common.linewrap_at_send)
4322 compose_wrap_all(compose);
4324 /* write queue header */
4325 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4326 G_DIR_SEPARATOR, compose);
4327 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4328 FILE_OP_ERROR(tmp, "fopen");
4333 if (change_file_mode_rw(fp, tmp) < 0) {
4334 FILE_OP_ERROR(tmp, "chmod");
4335 g_warning("can't change file mode\n");
4338 /* queueing variables */
4339 fprintf(fp, "AF:\n");
4340 fprintf(fp, "NF:0\n");
4341 fprintf(fp, "PS:10\n");
4342 fprintf(fp, "SRH:1\n");
4343 fprintf(fp, "SFN:\n");
4344 fprintf(fp, "DSR:\n");
4346 fprintf(fp, "MID:<%s>\n", compose->msgid);
4348 fprintf(fp, "MID:\n");
4349 fprintf(fp, "CFG:\n");
4350 fprintf(fp, "PT:0\n");
4351 fprintf(fp, "S:%s\n", compose->account->address);
4352 fprintf(fp, "RQ:\n");
4354 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4356 fprintf(fp, "SSV:\n");
4358 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4360 fprintf(fp, "NSV:\n");
4361 fprintf(fp, "SSH:\n");
4362 /* write recepient list */
4363 if (compose->to_list) {
4364 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4365 for (cur = compose->to_list->next; cur != NULL;
4367 fprintf(fp, ",<%s>", (gchar *)cur->data);
4370 /* write newsgroup list */
4371 if (compose->newsgroup_list) {
4373 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4374 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4375 fprintf(fp, ",%s", (gchar *)cur->data);
4378 /* Sylpheed account IDs */
4380 fprintf(fp, "MAID:%d\n", mailac->account_id);
4382 fprintf(fp, "NAID:%d\n", newsac->account_id);
4384 if (compose->privacy_system != NULL) {
4385 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4386 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4387 if (compose->use_encryption) {
4390 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4391 if (encdata != NULL) {
4392 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4393 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4394 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4396 } /* else we finally dont want to encrypt */
4398 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4399 /* and if encdata was null, it means there's been a problem in
4406 /* Save copy folder */
4407 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4408 gchar *savefolderid;
4410 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4411 fprintf(fp, "SCF:%s\n", savefolderid);
4412 g_free(savefolderid);
4414 /* Save copy folder */
4415 if (compose->return_receipt) {
4416 fprintf(fp, "RRCPT:1\n");
4418 /* Message-ID of message replying to */
4419 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4422 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4423 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4426 /* Message-ID of message forwarding to */
4427 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4430 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4431 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4436 if (compose->redirect_filename != NULL) {
4437 if (compose_redirect_write_to_file(compose, fp) < 0) {
4446 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4451 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4455 if (fclose(fp) == EOF) {
4456 FILE_OP_ERROR(tmp, "fclose");
4462 queue = account_get_special_folder(compose->account, F_QUEUE);
4464 g_warning("can't find queue folder\n");
4469 folder_item_scan(queue);
4470 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
4471 g_warning("can't queue the message\n");
4479 if (compose->mode == COMPOSE_REEDIT) {
4480 compose_remove_reedit_target(compose);
4483 if ((msgnum != NULL) && (item != NULL)) {
4491 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4494 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4496 struct stat statbuf;
4497 gchar *type, *subtype;
4498 GtkTreeModel *model;
4501 model = gtk_tree_view_get_model(tree_view);
4503 if (!gtk_tree_model_get_iter_first(model, &iter))
4506 gtk_tree_model_get(model, &iter,
4510 mimepart = procmime_mimeinfo_new();
4511 mimepart->content = MIMECONTENT_FILE;
4512 mimepart->data.filename = g_strdup(ainfo->file);
4513 mimepart->tmp = FALSE; /* or we destroy our attachment */
4514 mimepart->offset = 0;
4516 stat(ainfo->file, &statbuf);
4517 mimepart->length = statbuf.st_size;
4519 type = g_strdup(ainfo->content_type);
4521 if (!strchr(type, '/')) {
4523 type = g_strdup("application/octet-stream");
4526 subtype = strchr(type, '/') + 1;
4527 *(subtype - 1) = '\0';
4528 mimepart->type = procmime_get_media_type(type);
4529 mimepart->subtype = g_strdup(subtype);
4532 if (mimepart->type == MIMETYPE_MESSAGE &&
4533 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4534 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4536 g_hash_table_insert(mimepart->typeparameters,
4537 g_strdup("name"), g_strdup(ainfo->name));
4538 g_hash_table_insert(mimepart->dispositionparameters,
4539 g_strdup("filename"), g_strdup(ainfo->name));
4540 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4543 if (compose->use_signing) {
4544 if (ainfo->encoding == ENC_7BIT)
4545 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4546 else if (ainfo->encoding == ENC_8BIT)
4547 ainfo->encoding = ENC_BASE64;
4550 procmime_encode_content(mimepart, ainfo->encoding);
4552 g_node_append(parent->node, mimepart->node);
4553 } while (gtk_tree_model_iter_next(model, &iter));
4556 #define QUOTE_IF_REQUIRED(out, str) \
4558 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4562 len = strlen(str) + 3; \
4563 if ((__tmp = alloca(len)) == NULL) { \
4564 g_warning("can't allocate memory\n"); \
4565 g_string_free(header, TRUE); \
4568 g_snprintf(__tmp, len, "\"%s\"", str); \
4573 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4574 g_warning("can't allocate memory\n"); \
4575 g_string_free(header, TRUE); \
4578 strcpy(__tmp, str); \
4584 #define IS_IN_CUSTOM_HEADER(header) \
4585 (compose->account->add_customhdr && \
4586 custom_header_find(compose->account->customhdr_list, header) != NULL)
4588 static void compose_add_headerfield_from_headerlist(Compose *compose,
4590 const gchar *fieldname,
4591 const gchar *seperator)
4593 gchar *str, *fieldname_w_colon, *trans_fieldname;
4594 gboolean add_field = FALSE;
4596 ComposeHeaderEntry *headerentry;
4597 const gchar * headerentryname;
4600 if (IS_IN_CUSTOM_HEADER(fieldname))
4603 debug_print("Adding %s-fields\n", fieldname);
4605 fieldstr = g_string_sized_new(64);
4607 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4608 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4610 for (list = compose->header_list; list; list = list->next) {
4611 headerentry = ((ComposeHeaderEntry *)list->data);
4612 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4614 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4615 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4617 if (str[0] != '\0') {
4619 g_string_append(fieldstr, seperator);
4620 g_string_append(fieldstr, str);
4629 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4630 compose_convert_header
4631 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4632 strlen(fieldname) + 2, TRUE);
4633 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4637 g_free(fieldname_w_colon);
4638 g_string_free(fieldstr, TRUE);
4643 static gchar *compose_get_header(Compose *compose)
4645 gchar buf[BUFFSIZE];
4646 const gchar *entry_str;
4650 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4653 g_return_val_if_fail(compose->account != NULL, NULL);
4654 g_return_val_if_fail(compose->account->address != NULL, NULL);
4656 header = g_string_sized_new(64);
4659 if (compose->account->add_date) {
4660 get_rfc822_date(buf, sizeof(buf));
4661 g_string_append_printf(header, "Date: %s\n", buf);
4665 if (compose->account->name && *compose->account->name) {
4666 compose_convert_header
4667 (compose, buf, sizeof(buf), compose->account->name,
4668 strlen("From: "), TRUE);
4669 QUOTE_IF_REQUIRED(name, buf);
4670 g_string_append_printf(header, "From: %s <%s>\n",
4671 name, compose->account->address);
4673 g_string_append_printf(header, "From: %s\n", compose->account->address);
4676 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4679 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4682 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4685 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4688 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4690 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4693 compose_convert_header(compose, buf, sizeof(buf), str,
4694 strlen("Subject: "), FALSE);
4695 g_string_append_printf(header, "Subject: %s\n", buf);
4701 if (compose->account->gen_msgid) {
4702 generate_msgid(buf, sizeof(buf));
4703 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4704 compose->msgid = g_strdup(buf);
4707 if (compose->remove_references == FALSE) {
4709 if (compose->inreplyto && compose->to_list)
4710 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4713 if (compose->references)
4714 g_string_append_printf(header, "References: %s\n", compose->references);
4718 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4721 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4724 if (compose->account->organization &&
4725 strlen(compose->account->organization) &&
4726 !IS_IN_CUSTOM_HEADER("Organization")) {
4727 compose_convert_header(compose, buf, sizeof(buf),
4728 compose->account->organization,
4729 strlen("Organization: "), FALSE);
4730 g_string_append_printf(header, "Organization: %s\n", buf);
4733 /* Program version and system info */
4734 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4735 !compose->newsgroup_list) {
4736 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4738 gtk_major_version, gtk_minor_version, gtk_micro_version,
4741 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4742 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4744 gtk_major_version, gtk_minor_version, gtk_micro_version,
4748 /* custom headers */
4749 if (compose->account->add_customhdr) {
4752 for (cur = compose->account->customhdr_list; cur != NULL;
4754 CustomHeader *chdr = (CustomHeader *)cur->data;
4756 if (custom_header_is_allowed(chdr->name)) {
4757 compose_convert_header
4758 (compose, buf, sizeof(buf),
4759 chdr->value ? chdr->value : "",
4760 strlen(chdr->name) + 2, FALSE);
4761 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4767 switch (compose->priority) {
4768 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4769 "X-Priority: 1 (Highest)\n");
4771 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4772 "X-Priority: 2 (High)\n");
4774 case PRIORITY_NORMAL: break;
4775 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4776 "X-Priority: 4 (Low)\n");
4778 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4779 "X-Priority: 5 (Lowest)\n");
4781 default: debug_print("compose: priority unknown : %d\n",
4785 /* Request Return Receipt */
4786 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4787 if (compose->return_receipt) {
4788 if (compose->account->name
4789 && *compose->account->name) {
4790 compose_convert_header(compose, buf, sizeof(buf),
4791 compose->account->name,
4792 strlen("Disposition-Notification-To: "),
4794 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4796 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4800 /* get special headers */
4801 for (list = compose->header_list; list; list = list->next) {
4802 ComposeHeaderEntry *headerentry;
4805 gchar *headername_wcolon;
4806 gchar *headername_trans;
4809 gboolean standard_header = FALSE;
4811 headerentry = ((ComposeHeaderEntry *)list->data);
4813 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4814 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4819 if (!strstr(tmp, ":")) {
4820 headername_wcolon = g_strconcat(tmp, ":", NULL);
4821 headername = g_strdup(tmp);
4823 headername_wcolon = g_strdup(tmp);
4824 headername = g_strdup(strtok(tmp, ":"));
4828 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4829 Xstrdup_a(headervalue, entry_str, return NULL);
4830 subst_char(headervalue, '\r', ' ');
4831 subst_char(headervalue, '\n', ' ');
4832 string = std_headers;
4833 while (*string != NULL) {
4834 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4835 if (!strcmp(headername_trans,headername_wcolon))
4836 standard_header = TRUE;
4839 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4840 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
4843 g_free(headername_wcolon);
4847 g_string_free(header, FALSE);
4852 #undef IS_IN_CUSTOM_HEADER
4854 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
4855 gint header_len, gboolean addr_field)
4857 gchar *tmpstr = NULL;
4858 const gchar *out_codeset = NULL;
4860 g_return_if_fail(src != NULL);
4861 g_return_if_fail(dest != NULL);
4863 if (len < 1) return;
4865 tmpstr = g_strdup(src);
4867 subst_char(tmpstr, '\n', ' ');
4868 subst_char(tmpstr, '\r', ' ');
4871 if (!g_utf8_validate(tmpstr, -1, NULL)) {
4872 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
4873 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
4878 codeconv_set_strict(TRUE);
4879 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4880 conv_get_charset_str(compose->out_encoding));
4881 codeconv_set_strict(FALSE);
4883 if (!dest || *dest == '\0') {
4884 gchar *test_conv_global_out = NULL;
4885 gchar *test_conv_reply = NULL;
4887 /* automatic mode. be automatic. */
4888 codeconv_set_strict(TRUE);
4890 out_codeset = conv_get_outgoing_charset_str();
4892 debug_print("trying to convert to %s\n", out_codeset);
4893 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4896 if (!test_conv_global_out && compose->orig_charset) {
4897 out_codeset = compose->orig_charset;
4898 debug_print("failure; trying to convert to %s\n", out_codeset);
4899 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4902 if (!test_conv_global_out && !test_conv_reply) {
4904 out_codeset = CS_INTERNAL;
4905 debug_print("finally using %s\n", out_codeset);
4907 g_free(test_conv_global_out);
4908 g_free(test_conv_reply);
4909 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4911 codeconv_set_strict(FALSE);
4916 static void compose_create_header_entry(Compose *compose)
4918 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4922 GList *combo_list = NULL;
4924 const gchar *header = NULL;
4925 ComposeHeaderEntry *headerentry;
4926 gboolean standard_header = FALSE;
4928 headerentry = g_new0(ComposeHeaderEntry, 1);
4931 combo = gtk_combo_new();
4933 while(*string != NULL) {
4934 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4937 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4938 g_list_free(combo_list);
4939 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4940 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4941 G_CALLBACK(compose_grab_focus_cb), compose);
4942 gtk_widget_show(combo);
4943 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4944 if (compose->header_last) {
4945 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4947 while (*string != NULL) {
4948 if (!strcmp(*string, last_header_entry))
4949 standard_header = TRUE;
4952 if (standard_header)
4953 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4955 if (!compose->header_last || !standard_header) {
4956 switch(compose->account->protocol) {
4958 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4961 header = prefs_common.trans_hdr ? _("To:") : "To:";
4966 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4968 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4969 G_CALLBACK(compose_grab_focus_cb), compose);
4972 entry = gtk_entry_new();
4973 gtk_widget_show(entry);
4974 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);
4976 g_signal_connect(G_OBJECT(entry), "key-press-event",
4977 G_CALLBACK(compose_headerentry_key_press_event_cb),
4979 g_signal_connect(G_OBJECT(entry), "changed",
4980 G_CALLBACK(compose_headerentry_changed_cb),
4982 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
4983 G_CALLBACK(compose_grab_focus_cb), compose);
4986 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
4987 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
4988 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4989 g_signal_connect(G_OBJECT(entry), "drag_data_received",
4990 G_CALLBACK(compose_header_drag_received_cb),
4992 g_signal_connect(G_OBJECT(entry), "drag-drop",
4993 G_CALLBACK(compose_drag_drop),
4996 address_completion_register_entry(GTK_ENTRY(entry));
4998 headerentry->compose = compose;
4999 headerentry->combo = combo;
5000 headerentry->entry = entry;
5001 headerentry->headernum = compose->header_nextrow;
5003 compose->header_nextrow++;
5004 compose->header_last = headerentry;
5007 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5009 ComposeHeaderEntry *last_header;
5011 last_header = compose->header_last;
5013 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5014 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5017 static GtkWidget *compose_create_header(Compose *compose)
5021 GtkWidget *from_optmenu_hbox;
5022 GtkWidget *header_scrolledwin;
5023 GtkWidget *header_table;
5027 /* header labels and entries */
5028 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5029 gtk_widget_show(header_scrolledwin);
5030 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5032 header_table = gtk_table_new(2, 2, FALSE);
5033 gtk_widget_show(header_table);
5034 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
5035 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5036 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5039 /* option menu for selecting accounts */
5040 hbox = gtk_hbox_new(FALSE, 0);
5041 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
5042 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
5043 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
5045 from_optmenu_hbox = compose_account_option_menu_create(compose);
5046 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5047 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5050 compose->header_table = header_table;
5051 compose->header_list = NULL;
5052 compose->header_nextrow = count;
5054 compose_create_header_entry(compose);
5056 compose->table = NULL;
5058 return header_scrolledwin ;
5061 GtkWidget *compose_create_attach(Compose *compose)
5063 GtkWidget *attach_scrwin;
5064 GtkWidget *attach_clist;
5066 GtkListStore *store;
5067 GtkCellRenderer *renderer;
5068 GtkTreeViewColumn *column;
5069 GtkTreeSelection *selection;
5071 /* attachment list */
5072 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5073 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5074 GTK_POLICY_AUTOMATIC,
5075 GTK_POLICY_AUTOMATIC);
5076 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5078 store = gtk_list_store_new(N_ATTACH_COLS,
5083 G_TYPE_AUTO_POINTER,
5085 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5086 (GTK_TREE_MODEL(store)));
5087 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5088 g_object_unref(store);
5090 renderer = gtk_cell_renderer_text_new();
5091 column = gtk_tree_view_column_new_with_attributes
5092 (_("Mime type"), renderer, "text",
5093 COL_MIMETYPE, NULL);
5094 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5096 renderer = gtk_cell_renderer_text_new();
5097 column = gtk_tree_view_column_new_with_attributes
5098 (_("Size"), renderer, "text",
5100 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5102 renderer = gtk_cell_renderer_text_new();
5103 column = gtk_tree_view_column_new_with_attributes
5104 (_("Name"), renderer, "text",
5106 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5108 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5109 prefs_common.enable_rules_hint);
5110 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5111 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5113 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5114 G_CALLBACK(attach_selected), compose);
5115 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5116 G_CALLBACK(attach_button_pressed), compose);
5117 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5118 G_CALLBACK(attach_key_pressed), compose);
5121 gtk_drag_dest_set(attach_clist,
5122 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5123 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5124 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5125 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5126 G_CALLBACK(compose_attach_drag_received_cb),
5128 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5129 G_CALLBACK(compose_drag_drop),
5132 compose->attach_scrwin = attach_scrwin;
5133 compose->attach_clist = attach_clist;
5135 return attach_scrwin;
5138 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5139 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5141 static GtkWidget *compose_create_others(Compose *compose)
5144 GtkWidget *savemsg_checkbtn;
5145 GtkWidget *savemsg_entry;
5146 GtkWidget *savemsg_select;
5149 gchar *folderidentifier;
5151 /* Table for settings */
5152 table = gtk_table_new(3, 1, FALSE);
5153 gtk_widget_show(table);
5154 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5157 /* Save Message to folder */
5158 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5159 gtk_widget_show(savemsg_checkbtn);
5160 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5161 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5162 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5164 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5165 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5167 savemsg_entry = gtk_entry_new();
5168 gtk_widget_show(savemsg_entry);
5169 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5170 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5171 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5172 G_CALLBACK(compose_grab_focus_cb), compose);
5173 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5174 folderidentifier = folder_item_get_identifier(account_get_special_folder
5175 (compose->account, F_OUTBOX));
5176 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5177 g_free(folderidentifier);
5180 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5181 gtk_widget_show(savemsg_select);
5182 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5183 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5184 G_CALLBACK(compose_savemsg_select_cb),
5189 compose->savemsg_checkbtn = savemsg_checkbtn;
5190 compose->savemsg_entry = savemsg_entry;
5195 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5197 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5198 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5201 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5206 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5209 path = folder_item_get_identifier(dest);
5211 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5215 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5218 #define BLOCK_WRAP() { \
5219 prev_autowrap = compose->autowrap; \
5220 buffer = gtk_text_view_get_buffer( \
5221 GTK_TEXT_VIEW(compose->text)); \
5222 compose->autowrap = FALSE; \
5224 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5225 G_CALLBACK(compose_changed_cb), \
5227 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5228 G_CALLBACK(text_inserted), \
5231 #define UNBLOCK_WRAP() { \
5232 compose->autowrap = prev_autowrap; \
5233 if (compose->autowrap) \
5234 compose_wrap_all(compose); \
5236 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5237 G_CALLBACK(compose_changed_cb), \
5239 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5240 G_CALLBACK(text_inserted), \
5245 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5249 GtkTextBuffer *buffer;
5251 if (event->button == 3) {
5254 /* move the cursor to allow GtkAspell to check the word
5255 * under the mouse */
5256 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5257 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5259 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5261 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5262 return FALSE; /* pass the event so that the right-click goes through */
5265 if (event->button == 2) {
5267 entry_paste_clipboard(compose, compose->focused_editable,
5268 prefs_common.linewrap_pastes,
5269 GDK_SELECTION_PRIMARY);
5276 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
5282 GtkWidget *handlebox;
5284 GtkWidget *notebook;
5289 GtkWidget *subject_hbox;
5290 GtkWidget *subject_frame;
5291 GtkWidget *subject_entry;
5295 GtkWidget *edit_vbox;
5296 GtkWidget *ruler_hbox;
5298 GtkWidget *scrolledwin;
5300 GtkTextBuffer *buffer;
5301 GtkClipboard *clipboard;
5303 UndoMain *undostruct;
5305 gchar *titles[N_ATTACH_COLS];
5306 guint n_menu_entries;
5309 gboolean success[1];
5310 GtkWidget *popupmenu;
5311 GtkItemFactory *popupfactory;
5312 GtkItemFactory *ifactory;
5313 GtkWidget *tmpl_menu;
5315 GtkWidget *menuitem;
5318 GtkAspell * gtkaspell = NULL;
5321 static GdkGeometry geometry;
5323 g_return_val_if_fail(account != NULL, NULL);
5325 debug_print("Creating compose window...\n");
5326 compose = g_new0(Compose, 1);
5328 titles[COL_MIMETYPE] = _("MIME type");
5329 titles[COL_SIZE] = _("Size");
5330 titles[COL_NAME] = _("Name");
5332 compose->account = account;
5334 compose->mutex = g_mutex_new();
5335 compose->set_cursor_pos = -1;
5337 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5338 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5339 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5341 if (!geometry.max_width) {
5342 geometry.max_width = gdk_screen_width();
5343 geometry.max_height = gdk_screen_height();
5346 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5347 &geometry, GDK_HINT_MAX_SIZE);
5348 if (!geometry.min_width) {
5349 geometry.min_width = 600;
5350 geometry.min_height = 480;
5352 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5353 &geometry, GDK_HINT_MIN_SIZE);
5354 gtk_widget_set_uposition(window, prefs_common.compose_x,
5355 prefs_common.compose_y);
5357 g_signal_connect(G_OBJECT(window), "delete_event",
5358 G_CALLBACK(compose_delete_cb), compose);
5359 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5360 gtk_widget_realize(window);
5362 gtkut_widget_set_composer_icon(window);
5364 vbox = gtk_vbox_new(FALSE, 0);
5365 gtk_container_add(GTK_CONTAINER(window), vbox);
5367 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5368 menubar = menubar_create(window, compose_entries,
5369 n_menu_entries, "<Compose>", compose);
5370 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5372 if (prefs_common.toolbar_detachable) {
5373 handlebox = gtk_handle_box_new();
5375 handlebox = gtk_hbox_new(FALSE, 0);
5377 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5379 gtk_widget_realize(handlebox);
5380 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5383 vbox2 = gtk_vbox_new(FALSE, 2);
5384 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5385 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5388 notebook = gtk_notebook_new();
5389 gtk_widget_set_size_request(notebook, -1, 130);
5390 gtk_widget_show(notebook);
5392 /* header labels and entries */
5393 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
5394 /* attachment list */
5395 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
5397 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
5400 subject_hbox = gtk_hbox_new(FALSE, 0);
5401 gtk_widget_show(subject_hbox);
5403 subject_frame = gtk_frame_new(NULL);
5404 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5405 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5406 gtk_widget_show(subject_frame);
5408 subject = gtk_hbox_new(FALSE, 0);
5409 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5410 gtk_widget_show(subject);
5412 label = gtk_label_new(_("Subject:"));
5413 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5414 gtk_widget_show(label);
5416 subject_entry = gtk_entry_new();
5417 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5418 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5419 G_CALLBACK(compose_grab_focus_cb), compose);
5420 gtk_widget_show(subject_entry);
5421 compose->subject_entry = subject_entry;
5422 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5424 edit_vbox = gtk_vbox_new(FALSE, 0);
5426 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5429 ruler_hbox = gtk_hbox_new(FALSE, 0);
5430 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5432 ruler = gtk_shruler_new();
5433 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5434 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5438 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5439 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5440 GTK_POLICY_AUTOMATIC,
5441 GTK_POLICY_AUTOMATIC);
5442 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5444 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5445 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5447 text = gtk_text_view_new();
5448 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5449 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5450 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5451 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5452 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5454 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5456 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5457 G_CALLBACK(compose_edit_size_alloc),
5459 g_signal_connect(G_OBJECT(buffer), "changed",
5460 G_CALLBACK(compose_changed_cb), compose);
5461 g_signal_connect(G_OBJECT(text), "grab_focus",
5462 G_CALLBACK(compose_grab_focus_cb), compose);
5463 g_signal_connect(G_OBJECT(buffer), "insert_text",
5464 G_CALLBACK(text_inserted), compose);
5465 g_signal_connect(G_OBJECT(text), "button_press_event",
5466 G_CALLBACK(text_clicked), compose);
5469 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5470 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5471 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5472 g_signal_connect(G_OBJECT(text), "drag_data_received",
5473 G_CALLBACK(compose_insert_drag_received_cb),
5475 g_signal_connect(G_OBJECT(text), "drag-drop",
5476 G_CALLBACK(compose_drag_drop),
5478 gtk_widget_show_all(vbox);
5480 /* pane between attach clist and text */
5481 paned = gtk_vpaned_new();
5482 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5483 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5484 gtk_paned_add1(GTK_PANED(paned), notebook);
5485 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5486 gtk_widget_show_all(paned);
5489 if (prefs_common.textfont) {
5490 PangoFontDescription *font_desc;
5492 font_desc = pango_font_description_from_string
5493 (prefs_common.textfont);
5495 gtk_widget_modify_font(text, font_desc);
5496 pango_font_description_free(font_desc);
5500 color[0] = quote_color;
5501 cmap = gdk_drawable_get_colormap(window->window);
5502 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5503 if (success[0] == FALSE) {
5506 g_warning("Compose: color allocation failed.\n");
5507 style = gtk_widget_get_style(text);
5508 quote_color = style->black;
5511 n_entries = sizeof(compose_popup_entries) /
5512 sizeof(compose_popup_entries[0]);
5513 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5514 "<Compose>", &popupfactory,
5517 ifactory = gtk_item_factory_from_widget(menubar);
5518 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5519 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5520 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5522 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5524 undostruct = undo_init(text);
5525 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5528 address_completion_start(window);
5530 compose->window = window;
5531 compose->vbox = vbox;
5532 compose->menubar = menubar;
5533 compose->handlebox = handlebox;
5535 compose->vbox2 = vbox2;
5537 compose->paned = paned;
5539 compose->edit_vbox = edit_vbox;
5540 compose->ruler_hbox = ruler_hbox;
5541 compose->ruler = ruler;
5542 compose->scrolledwin = scrolledwin;
5543 compose->text = text;
5545 compose->focused_editable = NULL;
5547 compose->popupmenu = popupmenu;
5548 compose->popupfactory = popupfactory;
5550 compose->tmpl_menu = tmpl_menu;
5552 compose->mode = mode;
5554 compose->targetinfo = NULL;
5555 compose->replyinfo = NULL;
5556 compose->fwdinfo = NULL;
5558 compose->replyto = NULL;
5560 compose->bcc = NULL;
5561 compose->followup_to = NULL;
5563 compose->ml_post = NULL;
5565 compose->inreplyto = NULL;
5566 compose->references = NULL;
5567 compose->msgid = NULL;
5568 compose->boundary = NULL;
5570 compose->autowrap = prefs_common.autowrap;
5572 compose->use_signing = FALSE;
5573 compose->use_encryption = FALSE;
5574 compose->privacy_system = NULL;
5576 compose->modified = FALSE;
5578 compose->return_receipt = FALSE;
5580 compose->to_list = NULL;
5581 compose->newsgroup_list = NULL;
5583 compose->undostruct = undostruct;
5585 compose->sig_str = NULL;
5587 compose->exteditor_file = NULL;
5588 compose->exteditor_pid = -1;
5589 compose->exteditor_tag = -1;
5590 compose->draft_timeout_tag = -1;
5593 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5594 if (mode != COMPOSE_REDIRECT) {
5595 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5596 strcmp(prefs_common.dictionary, _("None"))) {
5597 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5598 prefs_common.dictionary,
5599 conv_get_locale_charset_str(),
5600 prefs_common.misspelled_col,
5601 prefs_common.check_while_typing,
5602 prefs_common.use_alternate,
5603 GTK_TEXT_VIEW(text),
5604 GTK_WINDOW(compose->window));
5606 alertpanel_error(_("Spell checker could not "
5608 gtkaspell_checkers_strerror());
5609 gtkaspell_checkers_reset_error();
5611 if (!gtkaspell_set_sug_mode(gtkaspell,
5612 prefs_common.aspell_sugmode)) {
5613 debug_print("Aspell: could not set "
5614 "suggestion mode %s\n",
5615 gtkaspell_checkers_strerror());
5616 gtkaspell_checkers_reset_error();
5619 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5623 compose->gtkaspell = gtkaspell;
5626 compose_select_account(compose, account, TRUE);
5628 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5629 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5630 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5632 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5633 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5635 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5636 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5639 if (account->protocol != A_NNTP)
5640 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5642 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5644 addressbook_set_target_compose(compose);
5646 if (mode != COMPOSE_REDIRECT)
5647 compose_set_template_menu(compose);
5649 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5650 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5653 compose_list = g_list_append(compose_list, compose);
5655 if (!prefs_common.show_ruler)
5656 gtk_widget_hide(ruler_hbox);
5658 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5659 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5660 prefs_common.show_ruler);
5663 compose->priority = PRIORITY_NORMAL;
5664 compose_update_priority_menu_item(compose);
5666 compose_set_out_encoding(compose);
5669 compose_update_actions_menu(compose);
5671 /* Privacy Systems menu */
5672 compose_update_privacy_systems_menu(compose);
5674 activate_privacy_system(compose, account, TRUE);
5675 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5676 gtk_widget_show(window);
5681 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5687 gint num = 0, def_menu = 0;
5689 accounts = account_get_list();
5690 g_return_val_if_fail(accounts != NULL, NULL);
5692 hbox = gtk_hbox_new(FALSE, 0);
5693 optmenu = gtk_option_menu_new();
5694 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5695 menu = gtk_menu_new();
5697 for (; accounts != NULL; accounts = accounts->next, num++) {
5698 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5699 GtkWidget *menuitem;
5702 if (ac == compose->account) def_menu = num;
5705 name = g_strdup_printf("%s: %s <%s>",
5707 ac->name, ac->address);
5709 name = g_strdup_printf("%s: %s",
5710 ac->account_name, ac->address);
5711 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5713 g_signal_connect(G_OBJECT(menuitem), "activate",
5714 G_CALLBACK(account_activated),
5718 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5719 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5724 static void compose_set_priority_cb(gpointer data,
5728 Compose *compose = (Compose *) data;
5729 compose->priority = action;
5732 static void compose_update_priority_menu_item(Compose * compose)
5734 GtkItemFactory *ifactory;
5735 GtkWidget *menuitem = NULL;
5737 ifactory = gtk_item_factory_from_widget(compose->menubar);
5739 switch (compose->priority) {
5740 case PRIORITY_HIGHEST:
5741 menuitem = gtk_item_factory_get_item
5742 (ifactory, "/Options/Priority/Highest");
5745 menuitem = gtk_item_factory_get_item
5746 (ifactory, "/Options/Priority/High");
5748 case PRIORITY_NORMAL:
5749 menuitem = gtk_item_factory_get_item
5750 (ifactory, "/Options/Priority/Normal");
5753 menuitem = gtk_item_factory_get_item
5754 (ifactory, "/Options/Priority/Low");
5756 case PRIORITY_LOWEST:
5757 menuitem = gtk_item_factory_get_item
5758 (ifactory, "/Options/Priority/Lowest");
5761 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5764 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5766 Compose *compose = (Compose *) data;
5768 GtkItemFactory *ifactory;
5769 gboolean can_sign = FALSE, can_encrypt = FALSE;
5771 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5773 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5776 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5777 g_free(compose->privacy_system);
5778 compose->privacy_system = NULL;
5779 if (systemid != NULL) {
5780 compose->privacy_system = g_strdup(systemid);
5782 can_sign = privacy_system_can_sign(systemid);
5783 can_encrypt = privacy_system_can_encrypt(systemid);
5786 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5788 ifactory = gtk_item_factory_from_widget(compose->menubar);
5789 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5790 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5793 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
5795 static gchar *branch_path = "/Options/Privacy System";
5796 GtkItemFactory *ifactory;
5797 GtkWidget *menuitem = NULL;
5799 gboolean can_sign = FALSE, can_encrypt = FALSE;
5800 gboolean found = FALSE;
5802 ifactory = gtk_item_factory_from_widget(compose->menubar);
5804 if (compose->privacy_system != NULL) {
5807 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5808 g_return_if_fail(menuitem != NULL);
5810 amenu = GTK_MENU_SHELL(menuitem)->children;
5812 while (amenu != NULL) {
5813 GList *alist = amenu->next;
5815 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
5816 if (systemid != NULL) {
5817 if (strcmp(systemid, compose->privacy_system) == 0) {
5818 menuitem = GTK_WIDGET(amenu->data);
5820 can_sign = privacy_system_can_sign(systemid);
5821 can_encrypt = privacy_system_can_encrypt(systemid);
5825 } else if (strlen(compose->privacy_system) == 0) {
5826 menuitem = GTK_WIDGET(amenu->data);
5829 can_encrypt = FALSE;
5836 if (menuitem != NULL)
5837 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5839 if (warn && !found && strlen(compose->privacy_system)) {
5840 gchar *tmp = g_strdup_printf(
5841 _("The privacy system '%s' cannot be loaded. You "
5842 "will not be able to sign or encrypt this message."),
5843 compose->privacy_system);
5844 alertpanel_warning(tmp);
5849 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5850 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5853 static void compose_set_out_encoding(Compose *compose)
5855 GtkItemFactoryEntry *entry;
5856 GtkItemFactory *ifactory;
5857 CharSet out_encoding;
5858 gchar *path, *p, *q;
5861 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
5862 ifactory = gtk_item_factory_from_widget(compose->menubar);
5864 for (entry = compose_entries; entry->callback != compose_address_cb;
5866 if (entry->callback == compose_set_encoding_cb &&
5867 (CharSet)entry->callback_action == out_encoding) {
5868 p = q = path = g_strdup(entry->path);
5880 item = gtk_item_factory_get_item(ifactory, path);
5881 gtk_widget_activate(item);
5888 static void compose_set_template_menu(Compose *compose)
5890 GSList *tmpl_list, *cur;
5894 tmpl_list = template_get_config();
5896 menu = gtk_menu_new();
5898 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5899 Template *tmpl = (Template *)cur->data;
5901 item = gtk_menu_item_new_with_label(tmpl->name);
5902 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5903 g_signal_connect(G_OBJECT(item), "activate",
5904 G_CALLBACK(compose_template_activate_cb),
5906 g_object_set_data(G_OBJECT(item), "template", tmpl);
5907 gtk_widget_show(item);
5910 gtk_widget_show(menu);
5911 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5914 void compose_update_actions_menu(Compose *compose)
5916 GtkItemFactory *ifactory;
5918 ifactory = gtk_item_factory_from_widget(compose->menubar);
5919 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5922 void compose_update_privacy_systems_menu(Compose *compose)
5924 static gchar *branch_path = "/Options/Privacy System";
5925 GtkItemFactory *ifactory;
5926 GtkWidget *menuitem;
5927 GSList *systems, *cur;
5930 GtkWidget *system_none;
5933 ifactory = gtk_item_factory_from_widget(compose->menubar);
5935 /* remove old entries */
5936 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5937 g_return_if_fail(menuitem != NULL);
5939 amenu = GTK_MENU_SHELL(menuitem)->children->next;
5940 while (amenu != NULL) {
5941 GList *alist = amenu->next;
5942 gtk_widget_destroy(GTK_WIDGET(amenu->data));
5946 system_none = gtk_item_factory_get_widget(ifactory,
5947 "/Options/Privacy System/None");
5949 g_signal_connect(G_OBJECT(system_none), "activate",
5950 G_CALLBACK(compose_set_privacy_system_cb), compose);
5952 systems = privacy_get_system_ids();
5953 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
5954 gchar *systemid = cur->data;
5956 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
5957 widget = gtk_radio_menu_item_new_with_label(group,
5958 privacy_system_get_name(systemid));
5959 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
5960 g_strdup(systemid), g_free);
5961 g_signal_connect(G_OBJECT(widget), "activate",
5962 G_CALLBACK(compose_set_privacy_system_cb), compose);
5964 gtk_menu_append(GTK_MENU(system_none->parent), widget);
5965 gtk_widget_show(widget);
5968 g_slist_free(systems);
5971 void compose_reflect_prefs_all(void)
5976 for (cur = compose_list; cur != NULL; cur = cur->next) {
5977 compose = (Compose *)cur->data;
5978 compose_set_template_menu(compose);
5982 void compose_reflect_prefs_pixmap_theme(void)
5987 for (cur = compose_list; cur != NULL; cur = cur->next) {
5988 compose = (Compose *)cur->data;
5989 toolbar_update(TOOLBAR_COMPOSE, compose);
5993 static void compose_template_apply(Compose *compose, Template *tmpl,
5997 GtkTextBuffer *buffer;
6002 gint cursor_pos = 0;
6003 if (!tmpl || !tmpl->value) return;
6005 text = GTK_TEXT_VIEW(compose->text);
6006 buffer = gtk_text_view_get_buffer(text);
6008 if (tmpl->subject && *tmpl->subject != '\0')
6009 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
6011 if (tmpl->to && *tmpl->to != '\0')
6012 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
6013 if (tmpl->cc && *tmpl->cc != '\0')
6014 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
6016 if (tmpl->bcc && *tmpl->bcc != '\0')
6017 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
6020 gtk_text_buffer_set_text(buffer, "", -1);
6022 mark = gtk_text_buffer_get_insert(buffer);
6023 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6025 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6026 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6029 if (prefs_common.quotemark && *prefs_common.quotemark)
6030 qmark = prefs_common.quotemark;
6034 if (compose->replyinfo != NULL)
6035 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6036 tmpl->value, qmark, NULL, FALSE);
6037 else if (compose->fwdinfo != NULL)
6038 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6039 tmpl->value, qmark, NULL, FALSE);
6044 if (replace && parsed_str && compose->account->auto_sig)
6045 compose_insert_sig(compose, FALSE);
6047 if (replace && parsed_str) {
6048 gtk_text_buffer_get_start_iter(buffer, &iter);
6049 gtk_text_buffer_place_cursor(buffer, &iter);
6053 cursor_pos = quote_fmt_get_cursor_pos();
6054 compose->set_cursor_pos = cursor_pos;
6055 if (cursor_pos == -1)
6057 gtk_text_buffer_get_start_iter(buffer, &iter);
6058 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6059 gtk_text_buffer_place_cursor(buffer, &iter);
6063 compose_changed_cb(NULL, compose);
6066 static void compose_destroy(Compose *compose)
6068 compose_list = g_list_remove(compose_list, compose);
6070 /* NOTE: address_completion_end() does nothing with the window
6071 * however this may change. */
6072 address_completion_end(compose->window);
6074 slist_free_strings(compose->to_list);
6075 g_slist_free(compose->to_list);
6076 slist_free_strings(compose->newsgroup_list);
6077 g_slist_free(compose->newsgroup_list);
6078 slist_free_strings(compose->header_list);
6079 g_slist_free(compose->header_list);
6081 procmsg_msginfo_free(compose->targetinfo);
6082 procmsg_msginfo_free(compose->replyinfo);
6083 procmsg_msginfo_free(compose->fwdinfo);
6085 g_free(compose->replyto);
6086 g_free(compose->cc);
6087 g_free(compose->bcc);
6088 g_free(compose->newsgroups);
6089 g_free(compose->followup_to);
6091 g_free(compose->ml_post);
6093 g_free(compose->inreplyto);
6094 g_free(compose->references);
6095 g_free(compose->msgid);
6096 g_free(compose->boundary);
6098 if (compose->redirect_filename)
6099 g_free(compose->redirect_filename);
6100 if (compose->undostruct)
6101 undo_destroy(compose->undostruct);
6103 g_free(compose->sig_str);
6105 g_free(compose->exteditor_file);
6107 g_free(compose->orig_charset);
6109 g_free(compose->privacy_system);
6111 if (addressbook_get_target_compose() == compose)
6112 addressbook_set_target_compose(NULL);
6115 if (compose->gtkaspell) {
6116 gtkaspell_delete(compose->gtkaspell);
6117 compose->gtkaspell = NULL;
6121 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6122 prefs_common.compose_height = compose->window->allocation.height;
6124 if (!gtk_widget_get_parent(compose->paned))
6125 gtk_widget_destroy(compose->paned);
6126 gtk_widget_destroy(compose->popupmenu);
6128 gtk_widget_destroy(compose->window);
6129 toolbar_destroy(compose->toolbar);
6130 g_free(compose->toolbar);
6131 g_mutex_free(compose->mutex);
6135 static void compose_attach_info_free(AttachInfo *ainfo)
6137 g_free(ainfo->file);
6138 g_free(ainfo->content_type);
6139 g_free(ainfo->name);
6143 static void compose_attach_remove_selected(Compose *compose)
6145 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6146 GtkTreeSelection *selection;
6148 GtkTreeModel *model;
6150 selection = gtk_tree_view_get_selection(tree_view);
6151 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6156 for (cur = sel; cur != NULL; cur = cur->next) {
6157 GtkTreePath *path = cur->data;
6158 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6161 gtk_tree_path_free(path);
6164 for (cur = sel; cur != NULL; cur = cur->next) {
6165 GtkTreeRowReference *ref = cur->data;
6166 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6169 if (gtk_tree_model_get_iter(model, &iter, path))
6170 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6172 gtk_tree_path_free(path);
6173 gtk_tree_row_reference_free(ref);
6179 static struct _AttachProperty
6182 GtkWidget *mimetype_entry;
6183 GtkWidget *encoding_optmenu;
6184 GtkWidget *path_entry;
6185 GtkWidget *filename_entry;
6187 GtkWidget *cancel_btn;
6190 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6192 gtk_tree_path_free((GtkTreePath *)ptr);
6195 static void compose_attach_property(Compose *compose)
6197 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6199 GtkOptionMenu *optmenu;
6200 GtkTreeSelection *selection;
6202 GtkTreeModel *model;
6205 static gboolean cancelled;
6207 /* only if one selected */
6208 selection = gtk_tree_view_get_selection(tree_view);
6209 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6212 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6216 path = (GtkTreePath *) sel->data;
6217 gtk_tree_model_get_iter(model, &iter, path);
6218 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6221 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6227 if (!attach_prop.window)
6228 compose_attach_property_create(&cancelled);
6229 gtk_widget_grab_focus(attach_prop.ok_btn);
6230 gtk_widget_show(attach_prop.window);
6231 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6233 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6234 if (ainfo->encoding == ENC_UNKNOWN)
6235 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6236 GINT_TO_POINTER(ENC_BASE64));
6238 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6239 GINT_TO_POINTER(ainfo->encoding));
6241 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6242 ainfo->content_type ? ainfo->content_type : "");
6243 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6244 ainfo->file ? ainfo->file : "");
6245 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6246 ainfo->name ? ainfo->name : "");
6249 const gchar *entry_text;
6251 gchar *cnttype = NULL;
6255 GtkWidget *menuitem;
6260 gtk_widget_hide(attach_prop.window);
6265 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6266 if (*entry_text != '\0') {
6269 text = g_strstrip(g_strdup(entry_text));
6270 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6271 cnttype = g_strdup(text);
6274 alertpanel_error(_("Invalid MIME type."));
6280 menu = gtk_option_menu_get_menu(optmenu);
6281 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6282 ainfo->encoding = GPOINTER_TO_INT
6283 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6285 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6286 if (*entry_text != '\0') {
6287 if (is_file_exist(entry_text) &&
6288 (size = get_file_size(entry_text)) > 0)
6289 file = g_strdup(entry_text);
6292 (_("File doesn't exist or is empty."));
6298 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6299 if (*entry_text != '\0') {
6300 g_free(ainfo->name);
6301 ainfo->name = g_strdup(entry_text);
6305 g_free(ainfo->content_type);
6306 ainfo->content_type = cnttype;
6309 g_free(ainfo->file);
6315 /* update tree store */
6316 text = to_human_readable(ainfo->size);
6317 gtk_tree_model_get_iter(model, &iter, path);
6318 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6319 COL_MIMETYPE, ainfo->content_type,
6321 COL_NAME, ainfo->name,
6327 gtk_tree_path_free(path);
6330 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6332 label = gtk_label_new(str); \
6333 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6334 GTK_FILL, 0, 0, 0); \
6335 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6337 entry = gtk_entry_new(); \
6338 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6339 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6342 static void compose_attach_property_create(gboolean *cancelled)
6348 GtkWidget *mimetype_entry;
6351 GtkWidget *optmenu_menu;
6352 GtkWidget *menuitem;
6353 GtkWidget *path_entry;
6354 GtkWidget *filename_entry;
6357 GtkWidget *cancel_btn;
6358 GList *mime_type_list, *strlist;
6360 debug_print("Creating attach_property window...\n");
6362 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6363 gtk_widget_set_size_request(window, 480, -1);
6364 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6365 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6366 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6367 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6368 g_signal_connect(G_OBJECT(window), "delete_event",
6369 G_CALLBACK(attach_property_delete_event),
6371 g_signal_connect(G_OBJECT(window), "key_press_event",
6372 G_CALLBACK(attach_property_key_pressed),
6375 vbox = gtk_vbox_new(FALSE, 8);
6376 gtk_container_add(GTK_CONTAINER(window), vbox);
6378 table = gtk_table_new(4, 2, FALSE);
6379 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6380 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6381 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6383 label = gtk_label_new(_("MIME type"));
6384 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6386 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6387 mimetype_entry = gtk_combo_new();
6388 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6389 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6391 /* stuff with list */
6392 mime_type_list = procmime_get_mime_type_list();
6394 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6395 MimeType *type = (MimeType *) mime_type_list->data;
6398 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6400 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6403 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6404 (GCompareFunc)strcmp2);
6407 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6409 for (mime_type_list = strlist; mime_type_list != NULL;
6410 mime_type_list = mime_type_list->next)
6411 g_free(mime_type_list->data);
6412 g_list_free(strlist);
6414 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6416 label = gtk_label_new(_("Encoding"));
6417 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6419 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6421 hbox = gtk_hbox_new(FALSE, 0);
6422 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6423 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6425 optmenu = gtk_option_menu_new();
6426 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6428 optmenu_menu = gtk_menu_new();
6429 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6430 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6431 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6432 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6433 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6434 ENC_QUOTED_PRINTABLE);
6435 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6437 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6439 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6441 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6442 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6444 gtkut_stock_button_set_create(&hbbox, &ok_btn, GTK_STOCK_OK,
6445 &cancel_btn, GTK_STOCK_CANCEL,
6447 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6448 gtk_widget_grab_default(ok_btn);
6450 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6451 G_CALLBACK(attach_property_ok),
6453 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6454 G_CALLBACK(attach_property_cancel),
6457 gtk_widget_show_all(vbox);
6459 attach_prop.window = window;
6460 attach_prop.mimetype_entry = mimetype_entry;
6461 attach_prop.encoding_optmenu = optmenu;
6462 attach_prop.path_entry = path_entry;
6463 attach_prop.filename_entry = filename_entry;
6464 attach_prop.ok_btn = ok_btn;
6465 attach_prop.cancel_btn = cancel_btn;
6468 #undef SET_LABEL_AND_ENTRY
6470 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6476 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6482 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6483 gboolean *cancelled)
6491 static gboolean attach_property_key_pressed(GtkWidget *widget,
6493 gboolean *cancelled)
6495 if (event && event->keyval == GDK_Escape) {
6502 static void compose_exec_ext_editor(Compose *compose)
6509 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6510 G_DIR_SEPARATOR, compose);
6512 if (pipe(pipe_fds) < 0) {
6518 if ((pid = fork()) < 0) {
6525 /* close the write side of the pipe */
6528 compose->exteditor_file = g_strdup(tmp);
6529 compose->exteditor_pid = pid;
6531 compose_set_ext_editor_sensitive(compose, FALSE);
6533 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6534 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6538 } else { /* process-monitoring process */
6544 /* close the read side of the pipe */
6547 if (compose_write_body_to_file(compose, tmp) < 0) {
6548 fd_write_all(pipe_fds[1], "2\n", 2);
6552 pid_ed = compose_exec_ext_editor_real(tmp);
6554 fd_write_all(pipe_fds[1], "1\n", 2);
6558 /* wait until editor is terminated */
6559 waitpid(pid_ed, NULL, 0);
6561 fd_write_all(pipe_fds[1], "0\n", 2);
6568 #endif /* G_OS_UNIX */
6572 static gint compose_exec_ext_editor_real(const gchar *file)
6574 static gchar *def_cmd = "emacs %s";
6580 g_return_val_if_fail(file != NULL, -1);
6582 if ((pid = fork()) < 0) {
6587 if (pid != 0) return pid;
6589 /* grandchild process */
6591 if (setpgid(0, getppid()))
6594 if (prefs_common.ext_editor_cmd &&
6595 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6596 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6597 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6599 if (prefs_common.ext_editor_cmd)
6600 g_warning("External editor command line is invalid: '%s'\n",
6601 prefs_common.ext_editor_cmd);
6602 g_snprintf(buf, sizeof(buf), def_cmd, file);
6605 cmdline = strsplit_with_quote(buf, " ", 1024);
6606 execvp(cmdline[0], cmdline);
6609 g_strfreev(cmdline);
6614 static gboolean compose_ext_editor_kill(Compose *compose)
6616 pid_t pgid = compose->exteditor_pid * -1;
6619 ret = kill(pgid, 0);
6621 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6625 msg = g_strdup_printf
6626 (_("The external editor is still working.\n"
6627 "Force terminating the process?\n"
6628 "process group id: %d"), -pgid);
6629 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_YES, GTK_STOCK_NO,
6630 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
6634 if (val == G_ALERTDEFAULT) {
6635 g_source_remove(compose->exteditor_tag);
6636 g_io_channel_shutdown(compose->exteditor_ch,
6638 g_io_channel_unref(compose->exteditor_ch);
6640 if (kill(pgid, SIGTERM) < 0) perror("kill");
6641 waitpid(compose->exteditor_pid, NULL, 0);
6643 g_warning("Terminated process group id: %d", -pgid);
6644 g_warning("Temporary file: %s",
6645 compose->exteditor_file);
6647 compose_set_ext_editor_sensitive(compose, TRUE);
6649 g_free(compose->exteditor_file);
6650 compose->exteditor_file = NULL;
6651 compose->exteditor_pid = -1;
6652 compose->exteditor_ch = NULL;
6653 compose->exteditor_tag = -1;
6661 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6665 Compose *compose = (Compose *)data;
6668 debug_print(_("Compose: input from monitoring process\n"));
6670 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6672 g_io_channel_shutdown(source, FALSE, NULL);
6673 g_io_channel_unref(source);
6675 waitpid(compose->exteditor_pid, NULL, 0);
6677 if (buf[0] == '0') { /* success */
6678 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6679 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6681 gtk_text_buffer_set_text(buffer, "", -1);
6682 compose_insert_file(compose, compose->exteditor_file);
6683 compose_changed_cb(NULL, compose);
6685 if (g_unlink(compose->exteditor_file) < 0)
6686 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6687 } else if (buf[0] == '1') { /* failed */
6688 g_warning("Couldn't exec external editor\n");
6689 if (g_unlink(compose->exteditor_file) < 0)
6690 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6691 } else if (buf[0] == '2') {
6692 g_warning("Couldn't write to file\n");
6693 } else if (buf[0] == '3') {
6694 g_warning("Pipe read failed\n");
6697 compose_set_ext_editor_sensitive(compose, TRUE);
6699 g_free(compose->exteditor_file);
6700 compose->exteditor_file = NULL;
6701 compose->exteditor_pid = -1;
6702 compose->exteditor_ch = NULL;
6703 compose->exteditor_tag = -1;
6708 static void compose_set_ext_editor_sensitive(Compose *compose,
6711 GtkItemFactory *ifactory;
6713 ifactory = gtk_item_factory_from_widget(compose->menubar);
6715 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6716 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6717 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6718 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6719 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6720 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6721 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6724 gtk_widget_set_sensitive(compose->text, sensitive);
6725 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6726 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6727 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6728 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6729 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6730 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6731 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
6732 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
6734 #endif /* G_OS_UNIX */
6737 * compose_undo_state_changed:
6739 * Change the sensivity of the menuentries undo and redo
6741 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6742 gint redo_state, gpointer data)
6744 GtkWidget *widget = GTK_WIDGET(data);
6745 GtkItemFactory *ifactory;
6747 g_return_if_fail(widget != NULL);
6749 ifactory = gtk_item_factory_from_widget(widget);
6751 switch (undo_state) {
6752 case UNDO_STATE_TRUE:
6753 if (!undostruct->undo_state) {
6754 undostruct->undo_state = TRUE;
6755 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6758 case UNDO_STATE_FALSE:
6759 if (undostruct->undo_state) {
6760 undostruct->undo_state = FALSE;
6761 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6764 case UNDO_STATE_UNCHANGED:
6766 case UNDO_STATE_REFRESH:
6767 menu_set_sensitive(ifactory, "/Edit/Undo",
6768 undostruct->undo_state);
6771 g_warning("Undo state not recognized");
6775 switch (redo_state) {
6776 case UNDO_STATE_TRUE:
6777 if (!undostruct->redo_state) {
6778 undostruct->redo_state = TRUE;
6779 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6782 case UNDO_STATE_FALSE:
6783 if (undostruct->redo_state) {
6784 undostruct->redo_state = FALSE;
6785 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6788 case UNDO_STATE_UNCHANGED:
6790 case UNDO_STATE_REFRESH:
6791 menu_set_sensitive(ifactory, "/Edit/Redo",
6792 undostruct->redo_state);
6795 g_warning("Redo state not recognized");
6800 /* callback functions */
6802 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6803 * includes "non-client" (windows-izm) in calculation, so this calculation
6804 * may not be accurate.
6806 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6807 GtkAllocation *allocation,
6808 GtkSHRuler *shruler)
6810 if (prefs_common.show_ruler) {
6811 gint char_width = 0, char_height = 0;
6812 gint line_width_in_chars;
6814 gtkut_get_font_size(GTK_WIDGET(widget),
6815 &char_width, &char_height);
6816 line_width_in_chars =
6817 (allocation->width - allocation->x) / char_width;
6819 /* got the maximum */
6820 gtk_ruler_set_range(GTK_RULER(shruler),
6821 0.0, line_width_in_chars, 0,
6822 /*line_width_in_chars*/ char_width);
6828 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6830 Compose *compose = (Compose *)data;
6833 gchar *folderidentifier;
6835 ac = account_find_from_id(
6836 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
6837 g_return_if_fail(ac != NULL);
6839 if (ac != compose->account)
6840 compose_select_account(compose, ac, FALSE);
6842 /* Set message save folder */
6843 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6844 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
6846 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
6847 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
6849 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6850 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6851 folderidentifier = folder_item_get_identifier(account_get_special_folder
6852 (compose->account, F_OUTBOX));
6853 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
6854 g_free(folderidentifier);
6858 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
6859 GtkTreeViewColumn *column, Compose *compose)
6861 compose_attach_property(compose);
6864 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6867 Compose *compose = (Compose *)data;
6868 GtkTreeSelection *attach_selection;
6869 gint attach_nr_selected;
6870 GtkItemFactory *ifactory;
6872 if (!event) return FALSE;
6874 if (event->button == 3) {
6875 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
6876 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
6877 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6879 if (attach_nr_selected > 0)
6881 menu_set_sensitive(ifactory, "/Remove", TRUE);
6882 menu_set_sensitive(ifactory, "/Properties...", TRUE);
6884 menu_set_sensitive(ifactory, "/Remove", FALSE);
6885 menu_set_sensitive(ifactory, "/Properties...", FALSE);
6888 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6889 NULL, NULL, event->button, event->time);
6896 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6899 Compose *compose = (Compose *)data;
6901 if (!event) return FALSE;
6903 switch (event->keyval) {
6905 compose_attach_remove_selected(compose);
6911 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6913 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6914 toolbar_comp_set_sensitive(compose, allow);
6915 menu_set_sensitive(ifactory, "/Message", allow);
6916 menu_set_sensitive(ifactory, "/Edit", allow);
6918 menu_set_sensitive(ifactory, "/Spelling", allow);
6920 menu_set_sensitive(ifactory, "/Options", allow);
6921 menu_set_sensitive(ifactory, "/Tools", allow);
6922 menu_set_sensitive(ifactory, "/Help", allow);
6924 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
6928 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6930 Compose *compose = (Compose *)data;
6932 if (prefs_common.work_offline && !inc_offline_should_override())
6935 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
6936 gtk_timeout_remove(compose->draft_timeout_tag);
6937 compose->draft_timeout_tag = -1;
6940 compose_send(compose);
6943 static void compose_send_later_cb(gpointer data, guint action,
6946 Compose *compose = (Compose *)data;
6949 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6951 compose_close(compose);
6952 else if (val == -2) {
6953 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
6957 void compose_draft (gpointer data)
6959 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6962 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6964 Compose *compose = (Compose *)data;
6968 MsgFlags flag = {0, 0};
6969 static gboolean lock = FALSE;
6970 MsgInfo *newmsginfo;
6975 draft = account_get_special_folder(compose->account, F_DRAFT);
6976 g_return_if_fail(draft != NULL);
6978 if (!g_mutex_trylock(compose->mutex)) {
6979 /* we don't want to lock the mutex once it's available,
6980 * because as the only other part of compose.c locking
6981 * it is compose_close - which means once unlocked,
6982 * the compose struct will be freed */
6983 debug_print("couldn't lock mutex, probably sending\n");
6989 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
6990 G_DIR_SEPARATOR, compose);
6991 if ((fp = g_fopen(tmp, "wb")) == NULL) {
6992 FILE_OP_ERROR(tmp, "fopen");
6996 /* chmod for security */
6997 if (change_file_mode_rw(fp, tmp) < 0) {
6998 FILE_OP_ERROR(tmp, "chmod");
6999 g_warning("can't change file mode\n");
7002 /* Save draft infos */
7003 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7004 fprintf(fp, "S:%s\n", compose->account->address);
7005 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7006 gchar *savefolderid;
7008 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7009 fprintf(fp, "SCF:%s\n", savefolderid);
7010 g_free(savefolderid);
7012 if (compose->return_receipt) {
7013 fprintf(fp, "RRCPT:1\n");
7015 if (compose->privacy_system) {
7016 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7017 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7018 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7022 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
7030 folder_item_scan(draft);
7031 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7034 if (action != COMPOSE_AUTO_SAVE)
7035 alertpanel_error(_("Could not save draft."));
7039 draft->mtime = 0; /* force updating */
7041 if (compose->mode == COMPOSE_REEDIT) {
7042 compose_remove_reedit_target(compose);
7045 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7047 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7048 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7049 if (compose_use_attach(compose))
7050 procmsg_msginfo_set_flags(newmsginfo, 0,
7051 MSG_HAS_ATTACHMENT);
7053 procmsg_msginfo_free(newmsginfo);
7056 folder_item_scan(draft);
7058 if (action == COMPOSE_QUIT_EDITING) {
7060 g_mutex_unlock(compose->mutex); /* must be done before closing */
7061 compose_close(compose);
7067 path = folder_item_fetch_msg(draft, msgnum);
7068 g_return_if_fail(path != NULL);
7069 if (g_stat(path, &s) < 0) {
7070 FILE_OP_ERROR(path, "stat");
7076 procmsg_msginfo_free(compose->targetinfo);
7077 compose->targetinfo = procmsg_msginfo_new();
7078 compose->targetinfo->msgnum = msgnum;
7079 compose->targetinfo->size = s.st_size;
7080 compose->targetinfo->mtime = s.st_mtime;
7081 compose->targetinfo->folder = draft;
7082 compose->mode = COMPOSE_REEDIT;
7084 if (action == COMPOSE_AUTO_SAVE) {
7085 compose->autosaved_draft = compose->targetinfo;
7087 compose->modified = FALSE;
7088 compose_set_title(compose);
7092 g_mutex_unlock(compose->mutex);
7095 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7097 Compose *compose = (Compose *)data;
7100 if (compose->redirect_filename != NULL)
7103 file_list = filesel_select_multiple_files_open(_("Select file"));
7108 for ( tmp = file_list; tmp; tmp = tmp->next) {
7109 gchar *file = (gchar *) tmp->data;
7110 gchar *utf8_filename = conv_filename_to_utf8(file);
7111 compose_attach_append(compose, file, utf8_filename, NULL);
7112 compose_changed_cb(NULL, compose);
7114 g_free(utf8_filename);
7116 g_list_free(file_list);
7120 static void compose_insert_file_cb(gpointer data, guint action,
7123 Compose *compose = (Compose *)data;
7126 file_list = filesel_select_multiple_files_open(_("Select file"));
7131 for ( tmp = file_list; tmp; tmp = tmp->next) {
7132 gchar *file = (gchar *) tmp->data;
7133 gchar *filedup = g_strdup(file);
7134 gchar *shortfile = g_path_get_basename(filedup);
7135 ComposeInsertResult res;
7137 res = compose_insert_file(compose, file);
7138 if (res == COMPOSE_INSERT_READ_ERROR) {
7139 alertpanel_error(_("File '%s' could not be read."), shortfile);
7140 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7141 alertpanel_error(_("File '%s' contained invalid characters\n"
7142 "for the current encoding, insertion may be incorrect."), shortfile);
7148 g_list_free(file_list);
7152 static void compose_insert_sig_cb(gpointer data, guint action,
7155 Compose *compose = (Compose *)data;
7157 compose_insert_sig(compose, FALSE);
7160 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7164 Compose *compose = (Compose *)data;
7166 gtkut_widget_get_uposition(widget, &x, &y);
7167 prefs_common.compose_x = x;
7168 prefs_common.compose_y = y;
7170 if (compose->sending)
7172 compose_close_cb(compose, 0, NULL);
7176 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7178 Compose *compose = (Compose *)data;
7182 if (compose->exteditor_tag != -1) {
7183 if (!compose_ext_editor_kill(compose))
7188 if (compose->modified) {
7189 val = alertpanel(_("Discard message"),
7190 _("This message has been modified. Discard it?"),
7191 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7194 case G_ALERTDEFAULT:
7195 if (prefs_common.autosave)
7196 compose_remove_draft(compose);
7198 case G_ALERTALTERNATE:
7199 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7206 compose_close(compose);
7209 static void compose_set_encoding_cb(gpointer data, guint action,
7212 Compose *compose = (Compose *)data;
7214 if (GTK_CHECK_MENU_ITEM(widget)->active)
7215 compose->out_encoding = (CharSet)action;
7218 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7220 Compose *compose = (Compose *)data;
7222 addressbook_open(compose);
7225 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7227 Compose *compose = (Compose *)data;
7232 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7233 g_return_if_fail(tmpl != NULL);
7235 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7237 val = alertpanel(_("Apply template"), msg,
7238 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7241 if (val == G_ALERTDEFAULT)
7242 compose_template_apply(compose, tmpl, TRUE);
7243 else if (val == G_ALERTALTERNATE)
7244 compose_template_apply(compose, tmpl, FALSE);
7247 static void compose_ext_editor_cb(gpointer data, guint action,
7250 Compose *compose = (Compose *)data;
7252 compose_exec_ext_editor(compose);
7255 static void compose_undo_cb(Compose *compose)
7257 gboolean prev_autowrap = compose->autowrap;
7259 compose->autowrap = FALSE;
7260 undo_undo(compose->undostruct);
7261 compose->autowrap = prev_autowrap;
7264 static void compose_redo_cb(Compose *compose)
7266 gboolean prev_autowrap = compose->autowrap;
7268 compose->autowrap = FALSE;
7269 undo_redo(compose->undostruct);
7270 compose->autowrap = prev_autowrap;
7273 static void entry_cut_clipboard(GtkWidget *entry)
7275 if (GTK_IS_EDITABLE(entry))
7276 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7277 else if (GTK_IS_TEXT_VIEW(entry))
7278 gtk_text_buffer_cut_clipboard(
7279 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7280 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7284 static void entry_copy_clipboard(GtkWidget *entry)
7286 if (GTK_IS_EDITABLE(entry))
7287 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7288 else if (GTK_IS_TEXT_VIEW(entry))
7289 gtk_text_buffer_copy_clipboard(
7290 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7291 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7294 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7295 gboolean wrap, GdkAtom clip)
7297 if (GTK_IS_TEXT_VIEW(entry)) {
7298 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7299 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7300 GtkTextIter start_iter, end_iter;
7303 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7305 if (contents == NULL)
7308 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7309 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7311 start = gtk_text_iter_get_offset(&start_iter);
7313 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7316 end = start + strlen(contents);
7317 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7318 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7319 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7320 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7321 mark_start = gtk_text_buffer_get_insert(buffer);
7322 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7323 gtk_text_iter_backward_char(&start_iter);
7324 compose_beautify_paragraph(compose, &start_iter, TRUE);
7327 } else if (GTK_IS_EDITABLE(entry))
7328 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7332 static void entry_allsel(GtkWidget *entry)
7334 if (GTK_IS_EDITABLE(entry))
7335 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7336 else if (GTK_IS_TEXT_VIEW(entry)) {
7337 GtkTextIter startiter, enditer;
7338 GtkTextBuffer *textbuf;
7340 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7341 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7342 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7344 gtk_text_buffer_move_mark_by_name(textbuf,
7345 "selection_bound", &startiter);
7346 gtk_text_buffer_move_mark_by_name(textbuf,
7347 "insert", &enditer);
7351 static void compose_cut_cb(Compose *compose)
7353 if (compose->focused_editable &&
7354 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7355 entry_cut_clipboard(compose->focused_editable);
7358 static void compose_copy_cb(Compose *compose)
7360 if (compose->focused_editable &&
7361 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7362 entry_copy_clipboard(compose->focused_editable);
7365 static void compose_paste_cb(Compose *compose)
7368 GtkTextBuffer *buffer;
7370 if (compose->focused_editable &&
7371 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7372 entry_paste_clipboard(compose, compose->focused_editable,
7373 prefs_common.linewrap_pastes,
7374 GDK_SELECTION_CLIPBOARD);
7378 static void compose_paste_as_quote_cb(Compose *compose)
7380 gint wrap_quote = prefs_common.linewrap_quote;
7381 if (compose->focused_editable &&
7382 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7383 /* let text_insert() (called directly or at a later time
7384 * after the gtk_editable_paste_clipboard) know that
7385 * text is to be inserted as a quotation. implemented
7386 * by using a simple refcount... */
7387 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7388 G_OBJECT(compose->focused_editable),
7389 "paste_as_quotation"));
7390 g_object_set_data(G_OBJECT(compose->focused_editable),
7391 "paste_as_quotation",
7392 GINT_TO_POINTER(paste_as_quotation + 1));
7393 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7394 entry_paste_clipboard(compose, compose->focused_editable,
7395 prefs_common.linewrap_pastes,
7396 GDK_SELECTION_CLIPBOARD);
7397 prefs_common.linewrap_quote = wrap_quote;
7401 static void compose_paste_no_wrap_cb(Compose *compose)
7404 GtkTextBuffer *buffer;
7406 if (compose->focused_editable &&
7407 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7408 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7409 GDK_SELECTION_CLIPBOARD);
7413 static void compose_paste_wrap_cb(Compose *compose)
7416 GtkTextBuffer *buffer;
7418 if (compose->focused_editable &&
7419 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7420 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7421 GDK_SELECTION_CLIPBOARD);
7425 static void compose_allsel_cb(Compose *compose)
7427 if (compose->focused_editable &&
7428 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7429 entry_allsel(compose->focused_editable);
7432 static void textview_move_beginning_of_line (GtkTextView *text)
7434 GtkTextBuffer *buffer;
7438 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7440 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7441 mark = gtk_text_buffer_get_insert(buffer);
7442 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7443 gtk_text_iter_set_line_offset(&ins, 0);
7444 gtk_text_buffer_place_cursor(buffer, &ins);
7447 static void textview_move_forward_character (GtkTextView *text)
7449 GtkTextBuffer *buffer;
7453 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7455 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7456 mark = gtk_text_buffer_get_insert(buffer);
7457 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7458 if (gtk_text_iter_forward_cursor_position(&ins))
7459 gtk_text_buffer_place_cursor(buffer, &ins);
7462 static void textview_move_backward_character (GtkTextView *text)
7464 GtkTextBuffer *buffer;
7468 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7470 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7471 mark = gtk_text_buffer_get_insert(buffer);
7472 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7473 if (gtk_text_iter_backward_cursor_position(&ins))
7474 gtk_text_buffer_place_cursor(buffer, &ins);
7477 static void textview_move_forward_word (GtkTextView *text)
7479 GtkTextBuffer *buffer;
7484 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7486 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7487 mark = gtk_text_buffer_get_insert(buffer);
7488 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7489 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7490 if (gtk_text_iter_forward_word_ends(&ins, count)) {
7491 gtk_text_iter_backward_word_start(&ins);
7492 gtk_text_buffer_place_cursor(buffer, &ins);
7496 static void textview_move_backward_word (GtkTextView *text)
7498 GtkTextBuffer *buffer;
7503 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7505 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7506 mark = gtk_text_buffer_get_insert(buffer);
7507 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7508 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7509 if (gtk_text_iter_backward_word_starts(&ins, 1))
7510 gtk_text_buffer_place_cursor(buffer, &ins);
7513 static void textview_move_end_of_line (GtkTextView *text)
7515 GtkTextBuffer *buffer;
7519 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7521 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7522 mark = gtk_text_buffer_get_insert(buffer);
7523 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7524 if (gtk_text_iter_forward_to_line_end(&ins))
7525 gtk_text_buffer_place_cursor(buffer, &ins);
7528 static void textview_move_next_line (GtkTextView *text)
7530 GtkTextBuffer *buffer;
7535 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7537 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7538 mark = gtk_text_buffer_get_insert(buffer);
7539 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7540 offset = gtk_text_iter_get_line_offset(&ins);
7541 if (gtk_text_iter_forward_line(&ins)) {
7542 gtk_text_iter_set_line_offset(&ins, offset);
7543 gtk_text_buffer_place_cursor(buffer, &ins);
7547 static void textview_move_previous_line (GtkTextView *text)
7549 GtkTextBuffer *buffer;
7554 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7556 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7557 mark = gtk_text_buffer_get_insert(buffer);
7558 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7559 offset = gtk_text_iter_get_line_offset(&ins);
7560 if (gtk_text_iter_backward_line(&ins)) {
7561 gtk_text_iter_set_line_offset(&ins, offset);
7562 gtk_text_buffer_place_cursor(buffer, &ins);
7566 static void textview_delete_forward_character (GtkTextView *text)
7568 GtkTextBuffer *buffer;
7570 GtkTextIter ins, end_iter;
7572 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7574 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7575 mark = gtk_text_buffer_get_insert(buffer);
7576 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7578 if (gtk_text_iter_forward_char(&end_iter)) {
7579 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7583 static void textview_delete_backward_character (GtkTextView *text)
7585 GtkTextBuffer *buffer;
7587 GtkTextIter ins, end_iter;
7589 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7591 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7592 mark = gtk_text_buffer_get_insert(buffer);
7593 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7595 if (gtk_text_iter_backward_char(&end_iter)) {
7596 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7600 static void textview_delete_forward_word (GtkTextView *text)
7602 GtkTextBuffer *buffer;
7604 GtkTextIter ins, end_iter;
7606 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7608 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7609 mark = gtk_text_buffer_get_insert(buffer);
7610 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7612 if (gtk_text_iter_forward_word_end(&end_iter)) {
7613 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7617 static void textview_delete_backward_word (GtkTextView *text)
7619 GtkTextBuffer *buffer;
7621 GtkTextIter ins, end_iter;
7623 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7625 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7626 mark = gtk_text_buffer_get_insert(buffer);
7627 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7629 if (gtk_text_iter_backward_word_start(&end_iter)) {
7630 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7634 static void textview_delete_line (GtkTextView *text)
7636 GtkTextBuffer *buffer;
7638 GtkTextIter ins, start_iter, end_iter;
7641 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7643 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7644 mark = gtk_text_buffer_get_insert(buffer);
7645 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7648 gtk_text_iter_set_line_offset(&start_iter, 0);
7651 if (gtk_text_iter_ends_line(&end_iter))
7652 found = gtk_text_iter_forward_char(&end_iter);
7654 found = gtk_text_iter_forward_to_line_end(&end_iter);
7657 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7660 static void textview_delete_to_line_end (GtkTextView *text)
7662 GtkTextBuffer *buffer;
7664 GtkTextIter ins, end_iter;
7667 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7669 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7670 mark = gtk_text_buffer_get_insert(buffer);
7671 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7673 if (gtk_text_iter_ends_line(&end_iter))
7674 found = gtk_text_iter_forward_char(&end_iter);
7676 found = gtk_text_iter_forward_to_line_end(&end_iter);
7678 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7681 static void compose_advanced_action_cb(Compose *compose,
7682 ComposeCallAdvancedAction action)
7684 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7686 void (*do_action) (GtkTextView *text);
7687 } action_table[] = {
7688 {textview_move_beginning_of_line},
7689 {textview_move_forward_character},
7690 {textview_move_backward_character},
7691 {textview_move_forward_word},
7692 {textview_move_backward_word},
7693 {textview_move_end_of_line},
7694 {textview_move_next_line},
7695 {textview_move_previous_line},
7696 {textview_delete_forward_character},
7697 {textview_delete_backward_character},
7698 {textview_delete_forward_word},
7699 {textview_delete_backward_word},
7700 {textview_delete_line},
7701 {NULL}, /* gtk_stext_delete_line_n */
7702 {textview_delete_to_line_end}
7705 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
7707 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
7708 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
7709 if (action_table[action].do_action)
7710 action_table[action].do_action(text);
7712 g_warning("Not implemented yet.");
7716 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
7720 if (GTK_IS_EDITABLE(widget)) {
7721 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
7722 gtk_editable_set_position(GTK_EDITABLE(widget),
7725 if (widget->parent && widget->parent->parent
7726 && widget->parent->parent->parent) {
7727 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
7728 gint y = widget->allocation.y;
7729 gint height = widget->allocation.height;
7730 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
7731 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
7733 if (y < (int)shown->value) {
7734 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
7736 if (y + height > (int)shown->value + (int)shown->page_size) {
7737 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
7738 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7739 y + height - (int)shown->page_size - 1);
7741 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7742 (int)shown->upper - (int)shown->page_size - 1);
7749 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
7750 compose->focused_editable = widget;
7753 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
7755 compose->modified = TRUE;
7756 compose_set_title(compose);
7759 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
7761 Compose *compose = (Compose *)data;
7764 compose_wrap_all_full(compose, TRUE);
7766 compose_beautify_paragraph(compose, NULL, TRUE);
7769 static void compose_toggle_autowrap_cb(gpointer data, guint action,
7772 Compose *compose = (Compose *)data;
7773 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7774 if (compose->autowrap)
7775 compose_wrap_all_full(compose, TRUE);
7778 static void compose_toggle_sign_cb(gpointer data, guint action,
7781 Compose *compose = (Compose *)data;
7783 if (GTK_CHECK_MENU_ITEM(widget)->active)
7784 compose->use_signing = TRUE;
7786 compose->use_signing = FALSE;
7789 static void compose_toggle_encrypt_cb(gpointer data, guint action,
7792 Compose *compose = (Compose *)data;
7794 if (GTK_CHECK_MENU_ITEM(widget)->active)
7795 compose->use_encryption = TRUE;
7797 compose->use_encryption = FALSE;
7800 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
7802 g_free(compose->privacy_system);
7804 compose->privacy_system = g_strdup(account->default_privacy_system);
7805 compose_update_privacy_system_menu_item(compose, warn);
7808 static void compose_toggle_ruler_cb(gpointer data, guint action,
7811 Compose *compose = (Compose *)data;
7813 if (GTK_CHECK_MENU_ITEM(widget)->active) {
7814 gtk_widget_show(compose->ruler_hbox);
7815 prefs_common.show_ruler = TRUE;
7817 gtk_widget_hide(compose->ruler_hbox);
7818 gtk_widget_queue_resize(compose->edit_vbox);
7819 prefs_common.show_ruler = FALSE;
7823 static void compose_attach_drag_received_cb (GtkWidget *widget,
7824 GdkDragContext *drag_context,
7827 GtkSelectionData *data,
7832 Compose *compose = (Compose *)user_data;
7835 if (gdk_atom_name(data->type) &&
7836 !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7837 list = uri_list_extract_filenames((const gchar *)data->data);
7838 for (tmp = list; tmp != NULL; tmp = tmp->next)
7839 compose_attach_append
7840 (compose, (const gchar *)tmp->data,
7841 (const gchar *)tmp->data, NULL);
7842 if (list) compose_changed_cb(NULL, compose);
7843 list_free_strings(list);
7845 } else if (gdk_atom_name(data->type) &&
7846 !strcmp(gdk_atom_name(data->type), "text/plain") &&
7847 data->data && !strcmp(data->data, "Dummy-Summaryview")) {
7848 /* comes from our summaryview */
7849 SummaryView * summaryview = NULL;
7850 GSList * list = NULL, *cur = NULL;
7852 if (mainwindow_get_mainwindow())
7853 summaryview = mainwindow_get_mainwindow()->summaryview;
7856 list = summary_get_selected_msg_list(summaryview);
7858 for (cur = list; cur; cur = cur->next) {
7859 MsgInfo *msginfo = (MsgInfo *)cur->data;
7862 file = procmsg_get_message_file_full(msginfo,
7865 compose_attach_append(compose, (const gchar *)file,
7866 (const gchar *)file, "message/rfc822");
7874 static gboolean compose_drag_drop(GtkWidget *widget,
7875 GdkDragContext *drag_context,
7877 guint time, gpointer user_data)
7879 /* not handling this signal makes compose_insert_drag_received_cb
7884 static void compose_insert_drag_received_cb (GtkWidget *widget,
7885 GdkDragContext *drag_context,
7888 GtkSelectionData *data,
7893 Compose *compose = (Compose *)user_data;
7896 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
7898 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7899 list = uri_list_extract_filenames((const gchar *)data->data);
7900 for (tmp = list; tmp != NULL; tmp = tmp->next) {
7901 compose_insert_file(compose, (const gchar *)tmp->data);
7903 list_free_strings(list);
7905 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7908 #if GTK_CHECK_VERSION(2, 8, 0)
7909 /* do nothing, handled by GTK */
7911 gchar *tmpfile = get_tmp_file();
7912 str_write_to_file((const gchar *)data->data, tmpfile);
7913 compose_insert_file(compose, tmpfile);
7916 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7920 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7923 static void compose_header_drag_received_cb (GtkWidget *widget,
7924 GdkDragContext *drag_context,
7927 GtkSelectionData *data,
7932 GtkEditable *entry = (GtkEditable *)user_data;
7933 gchar *email = (gchar *)data->data;
7935 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
7938 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
7939 gchar *decoded=g_new(gchar, strlen(email));
7942 email += strlen("mailto:");
7943 decode_uri(decoded, email); /* will fit */
7944 gtk_editable_delete_text(entry, 0, -1);
7945 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
7946 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7950 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7953 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
7956 Compose *compose = (Compose *)data;
7958 if (GTK_CHECK_MENU_ITEM(widget)->active)
7959 compose->return_receipt = TRUE;
7961 compose->return_receipt = FALSE;
7964 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
7967 Compose *compose = (Compose *)data;
7969 if (GTK_CHECK_MENU_ITEM(widget)->active)
7970 compose->remove_references = TRUE;
7972 compose->remove_references = FALSE;
7975 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
7977 ComposeHeaderEntry *headerentry)
7979 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
7980 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
7981 !(event->state & GDK_MODIFIER_MASK) &&
7982 (event->keyval == GDK_BackSpace) &&
7983 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
7984 gtk_container_remove
7985 (GTK_CONTAINER(headerentry->compose->header_table),
7986 headerentry->combo);
7987 gtk_container_remove
7988 (GTK_CONTAINER(headerentry->compose->header_table),
7989 headerentry->entry);
7990 headerentry->compose->header_list =
7991 g_slist_remove(headerentry->compose->header_list,
7993 g_free(headerentry);
7994 } else if (event->keyval == GDK_Tab) {
7995 if (headerentry->compose->header_last == headerentry) {
7996 /* Override default next focus, and give it to subject_entry
7997 * instead of notebook tabs
7999 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8000 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8007 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8008 ComposeHeaderEntry *headerentry)
8010 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8011 headerentry->compose->header_list =
8012 g_slist_append(headerentry->compose->header_list,
8015 compose_create_header_entry(headerentry->compose);
8016 g_signal_handlers_disconnect_matched
8017 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8018 0, 0, NULL, NULL, headerentry);
8020 /* Automatically scroll down */
8021 compose_show_first_last_header(headerentry->compose, FALSE);
8027 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8029 GtkAdjustment *vadj;
8031 g_return_if_fail(compose);
8032 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8033 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8035 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8036 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8039 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8040 const gchar *text, gint len, Compose *compose)
8042 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8043 (G_OBJECT(compose->text), "paste_as_quotation"));
8046 g_return_if_fail(text != NULL);
8048 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8049 G_CALLBACK(text_inserted),
8051 if (paste_as_quotation) {
8058 new_text = g_strndup(text, len);
8059 if (prefs_common.quotemark && *prefs_common.quotemark)
8060 qmark = prefs_common.quotemark;
8064 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8065 gtk_text_buffer_place_cursor(buffer, iter);
8067 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8069 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8070 GINT_TO_POINTER(paste_as_quotation - 1));
8072 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8073 gtk_text_buffer_place_cursor(buffer, iter);
8075 gtk_text_buffer_insert(buffer, iter, text, len);
8077 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8079 compose_beautify_paragraph(compose, iter, FALSE);
8081 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8082 gtk_text_buffer_delete_mark(buffer, mark);
8084 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8085 G_CALLBACK(text_inserted),
8087 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8089 if (prefs_common.autosave &&
8090 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8091 compose->draft_timeout_tag = gtk_timeout_add
8092 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8094 static gint compose_defer_auto_save_draft(Compose *compose)
8096 compose->draft_timeout_tag = -1;
8097 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8102 static void compose_check_all(Compose *compose)
8104 if (compose->gtkaspell)
8105 gtkaspell_check_all(compose->gtkaspell);
8108 static void compose_highlight_all(Compose *compose)
8110 if (compose->gtkaspell)
8111 gtkaspell_highlight_all(compose->gtkaspell);
8114 static void compose_check_backwards(Compose *compose)
8116 if (compose->gtkaspell)
8117 gtkaspell_check_backwards(compose->gtkaspell);
8119 GtkItemFactory *ifactory;
8120 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8121 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8122 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8126 static void compose_check_forwards_go(Compose *compose)
8128 if (compose->gtkaspell)
8129 gtkaspell_check_forwards_go(compose->gtkaspell);
8131 GtkItemFactory *ifactory;
8132 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8133 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8134 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8140 *\brief Guess originating forward account from MsgInfo and several
8141 * "common preference" settings. Return NULL if no guess.
8143 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8145 PrefsAccount *account = NULL;
8147 g_return_val_if_fail(msginfo, NULL);
8148 g_return_val_if_fail(msginfo->folder, NULL);
8149 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8151 if (msginfo->folder->prefs->enable_default_account)
8152 account = account_find_from_id(msginfo->folder->prefs->default_account);
8155 account = msginfo->folder->folder->account;
8157 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8159 Xstrdup_a(to, msginfo->to, return NULL);
8160 extract_address(to);
8161 account = account_find_from_address(to);
8164 if (!account && prefs_common.forward_account_autosel) {
8166 if (!procheader_get_header_from_msginfo
8167 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8168 extract_address(cc);
8169 account = account_find_from_address(cc);
8176 static gboolean compose_close(Compose *compose)
8180 if (!g_mutex_trylock(compose->mutex)) {
8181 /* we have to wait for the (possibly deferred by auto-save)
8182 * drafting to be done, before destroying the compose under
8184 debug_print("waiting for drafting to finish...\n");
8185 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8188 g_return_val_if_fail(compose, FALSE);
8189 gtkut_widget_get_uposition(compose->window, &x, &y);
8190 prefs_common.compose_x = x;
8191 prefs_common.compose_y = y;
8192 g_mutex_unlock(compose->mutex);
8193 compose_destroy(compose);
8198 * Add entry field for each address in list.
8199 * \param compose E-Mail composition object.
8200 * \param listAddress List of (formatted) E-Mail addresses.
8202 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8207 addr = ( gchar * ) node->data;
8208 compose_entry_append( compose, addr, COMPOSE_TO );
8209 node = g_list_next( node );
8213 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8217 GSList *new_msglist = NULL;
8218 MsgInfo *tmp_msginfo = NULL;
8219 gboolean originally_enc = FALSE;
8220 Compose *compose = NULL;
8222 g_return_if_fail(msgview != NULL);
8224 g_return_if_fail(msginfo_list != NULL);
8226 if (g_slist_length(msginfo_list) == 1) {
8227 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8228 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8230 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8231 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8232 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8233 orig_msginfo, mimeinfo);
8234 if (tmp_msginfo != NULL) {
8235 new_msglist = g_slist_append(NULL, tmp_msginfo);
8236 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8237 originally_enc = TRUE;
8243 body = messageview_get_selection(msgview);
8246 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8247 procmsg_msginfo_free(tmp_msginfo);
8248 g_slist_free(new_msglist);
8250 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8252 if (originally_enc) {
8253 compose_force_encryption(compose, compose->account, FALSE);