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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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)
83 #include "mainwindow.h"
85 #include "addressbook.h"
86 #include "folderview.h"
89 #include "stock_pixmap.h"
90 #include "send_message.h"
93 #include "customheader.h"
94 #include "prefs_common.h"
95 #include "prefs_account.h"
99 #include "procheader.h"
100 #include "procmime.h"
101 #include "statusbar.h"
104 #include "quoted-printable.h"
105 #include "codeconv.h"
107 #include "gtkutils.h"
109 #include "alertpanel.h"
110 #include "manage_window.h"
111 #include "gtkshruler.h"
113 #include "addr_compl.h"
114 #include "quote_fmt.h"
115 #include "template.h"
117 #include "foldersel.h"
130 #define N_ATTACH_COLS (N_COL_COLUMNS)
134 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
135 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
136 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
137 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
138 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
142 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
143 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
144 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
145 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
146 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
149 } ComposeCallAdvancedAction;
153 PRIORITY_HIGHEST = 1,
162 COMPOSE_INSERT_SUCCESS,
163 COMPOSE_INSERT_READ_ERROR,
164 COMPOSE_INSERT_INVALID_CHARACTER,
165 COMPOSE_INSERT_NO_FILE
166 } ComposeInsertResult;
170 COMPOSE_QUIT_EDITING,
171 COMPOSE_KEEP_EDITING,
173 } ComposeDraftAction;
177 COMPOSE_WRITE_FOR_SEND,
178 COMPOSE_WRITE_FOR_STORE
181 #define B64_LINE_SIZE 57
182 #define B64_BUFFSIZE 77
184 #define MAX_REFERENCES_LEN 999
186 static GList *compose_list = NULL;
188 Compose *compose_generic_new (PrefsAccount *account,
191 GPtrArray *attach_files,
192 GList *listAddress );
194 static Compose *compose_create (PrefsAccount *account,
197 static GtkWidget *compose_account_option_menu_create
199 static void compose_set_out_encoding (Compose *compose);
200 static void compose_set_template_menu (Compose *compose);
201 static void compose_template_apply (Compose *compose,
204 static void compose_destroy (Compose *compose);
206 static void compose_entries_set (Compose *compose,
207 const gchar *mailto);
208 static gint compose_parse_header (Compose *compose,
210 static gchar *compose_parse_references (const gchar *ref,
213 static gchar *compose_quote_fmt (Compose *compose,
219 static void compose_reply_set_entry (Compose *compose,
225 followup_and_reply_to);
226 static void compose_reedit_set_entry (Compose *compose,
229 static void compose_insert_sig (Compose *compose,
231 static gchar *compose_get_signature_str (Compose *compose);
232 static ComposeInsertResult compose_insert_file (Compose *compose,
235 static void compose_attach_append (Compose *compose,
238 const gchar *content_type);
239 static void compose_attach_parts (Compose *compose,
242 static void compose_wrap_paragraph (Compose *compose,
243 GtkTextIter *par_iter,
245 static void compose_wrap_all (Compose *compose);
246 static void compose_wrap_all_full (Compose *compose,
249 static void compose_set_title (Compose *compose);
250 static void compose_select_account (Compose *compose,
251 PrefsAccount *account,
254 static PrefsAccount *compose_current_mail_account(void);
255 /* static gint compose_send (Compose *compose); */
256 static gboolean compose_check_for_valid_recipient
258 static gboolean compose_check_entries (Compose *compose,
259 gboolean check_subject);
260 static gint compose_write_to_file (Compose *compose,
263 static gint compose_write_body_to_file (Compose *compose,
265 static gint compose_remove_reedit_target (Compose *compose);
266 void compose_remove_draft (Compose *compose);
267 static gint compose_queue (Compose *compose,
270 static gint compose_queue_sub (Compose *compose,
273 gboolean check_subject);
274 static void compose_add_attachments (Compose *compose,
276 static gchar *compose_get_header (Compose *compose);
278 static void compose_convert_header (Compose *compose,
283 gboolean addr_field);
285 static void compose_attach_info_free (AttachInfo *ainfo);
286 static void compose_attach_remove_selected (Compose *compose);
288 static void compose_attach_property (Compose *compose);
289 static void compose_attach_property_create (gboolean *cancelled);
290 static void attach_property_ok (GtkWidget *widget,
291 gboolean *cancelled);
292 static void attach_property_cancel (GtkWidget *widget,
293 gboolean *cancelled);
294 static gint attach_property_delete_event (GtkWidget *widget,
296 gboolean *cancelled);
297 static gboolean attach_property_key_pressed (GtkWidget *widget,
299 gboolean *cancelled);
301 static void compose_exec_ext_editor (Compose *compose);
303 static gint compose_exec_ext_editor_real (const gchar *file);
304 static gboolean compose_ext_editor_kill (Compose *compose);
305 static gboolean compose_input_cb (GIOChannel *source,
306 GIOCondition condition,
308 static void compose_set_ext_editor_sensitive (Compose *compose,
310 #endif /* G_OS_UNIX */
312 static void compose_undo_state_changed (UndoMain *undostruct,
317 static void compose_create_header_entry (Compose *compose);
318 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
319 static void compose_update_priority_menu_item(Compose * compose);
321 static void compose_add_field_list ( Compose *compose,
322 GList *listAddress );
324 /* callback functions */
326 static gboolean compose_edit_size_alloc (GtkEditable *widget,
327 GtkAllocation *allocation,
328 GtkSHRuler *shruler);
329 static void account_activated (GtkMenuItem *menuitem,
331 static void attach_selected (GtkTreeView *tree_view,
332 GtkTreePath *tree_path,
333 GtkTreeViewColumn *column,
335 static gboolean attach_button_pressed (GtkWidget *widget,
336 GdkEventButton *event,
338 static gboolean attach_key_pressed (GtkWidget *widget,
342 static void compose_send_cb (gpointer data,
345 static void compose_send_later_cb (gpointer data,
349 static void compose_draft_cb (gpointer data,
353 static void compose_attach_cb (gpointer data,
356 static void compose_insert_file_cb (gpointer data,
359 static void compose_insert_sig_cb (gpointer data,
363 static void compose_close_cb (gpointer data,
367 static void compose_set_encoding_cb (gpointer data,
371 static void compose_address_cb (gpointer data,
374 static void compose_template_activate_cb(GtkWidget *widget,
377 static void compose_ext_editor_cb (gpointer data,
381 static gint compose_delete_cb (GtkWidget *widget,
385 static void compose_undo_cb (Compose *compose);
386 static void compose_redo_cb (Compose *compose);
387 static void compose_cut_cb (Compose *compose);
388 static void compose_copy_cb (Compose *compose);
389 static void compose_paste_cb (Compose *compose);
390 static void compose_paste_as_quote_cb (Compose *compose);
391 static void compose_paste_no_wrap_cb (Compose *compose);
392 static void compose_paste_wrap_cb (Compose *compose);
393 static void compose_allsel_cb (Compose *compose);
395 static void compose_advanced_action_cb (Compose *compose,
396 ComposeCallAdvancedAction action);
398 static void compose_grab_focus_cb (GtkWidget *widget,
401 static void compose_changed_cb (GtkTextBuffer *textbuf,
404 static void compose_wrap_cb (gpointer data,
407 static void compose_toggle_autowrap_cb (gpointer data,
411 static void compose_toggle_ruler_cb (gpointer data,
414 static void compose_toggle_sign_cb (gpointer data,
417 static void compose_toggle_encrypt_cb (gpointer data,
420 static void compose_set_privacy_system_cb(GtkWidget *widget,
422 static void compose_update_privacy_system_menu_item(Compose * compose);
423 static void activate_privacy_system (Compose *compose,
424 PrefsAccount *account);
425 static void compose_use_signing(Compose *compose, gboolean use_signing);
426 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
427 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
429 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
431 static void compose_set_priority_cb (gpointer data,
435 static void compose_attach_drag_received_cb (GtkWidget *widget,
436 GdkDragContext *drag_context,
439 GtkSelectionData *data,
443 static void compose_insert_drag_received_cb (GtkWidget *widget,
444 GdkDragContext *drag_context,
447 GtkSelectionData *data,
451 static void compose_header_drag_received_cb (GtkWidget *widget,
452 GdkDragContext *drag_context,
455 GtkSelectionData *data,
460 static gboolean compose_drag_drop (GtkWidget *widget,
461 GdkDragContext *drag_context,
463 guint time, gpointer user_data);
465 static void text_inserted (GtkTextBuffer *buffer,
470 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
471 gboolean to_all, gboolean to_ml,
473 gboolean followup_and_reply_to,
476 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
477 ComposeHeaderEntry *headerentry);
478 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
480 ComposeHeaderEntry *headerentry);
482 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
484 static void compose_allow_user_actions (Compose *compose, gboolean allow);
487 static void compose_check_all (Compose *compose);
488 static void compose_highlight_all (Compose *compose);
489 static void compose_check_backwards (Compose *compose);
490 static void compose_check_forwards_go (Compose *compose);
493 static gint compose_defer_auto_save_draft (Compose *compose);
494 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
496 static void compose_close (Compose *compose);
498 static GtkItemFactoryEntry compose_popup_entries[] =
500 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
501 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
502 {N_("/---"), NULL, NULL, 0, "<Separator>"},
503 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
506 static GtkItemFactoryEntry compose_entries[] =
508 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
509 {N_("/_Message/_Send"), "<control>Return",
510 compose_send_cb, 0, NULL},
511 {N_("/_Message/Send _later"), "<shift><control>S",
512 compose_send_later_cb, 0, NULL},
513 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
514 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
515 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
516 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
517 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
518 {N_("/_Message/_Save"),
519 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
520 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
521 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
523 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
524 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
525 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
526 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
527 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
528 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
529 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
530 {N_("/_Edit/Special paste/as _quotation"),
531 NULL, compose_paste_as_quote_cb, 0, NULL},
532 {N_("/_Edit/Special paste/_wrapped"),
533 NULL, compose_paste_wrap_cb, 0, NULL},
534 {N_("/_Edit/Special paste/_unwrapped"),
535 NULL, compose_paste_no_wrap_cb, 0, NULL},
536 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
537 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
538 {N_("/_Edit/A_dvanced/Move a character backward"),
540 compose_advanced_action_cb,
541 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
543 {N_("/_Edit/A_dvanced/Move a character forward"),
545 compose_advanced_action_cb,
546 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
548 {N_("/_Edit/A_dvanced/Move a word backward"),
550 compose_advanced_action_cb,
551 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
553 {N_("/_Edit/A_dvanced/Move a word forward"),
555 compose_advanced_action_cb,
556 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
558 {N_("/_Edit/A_dvanced/Move to beginning of line"),
559 NULL, /* "<control>A" */
560 compose_advanced_action_cb,
561 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
563 {N_("/_Edit/A_dvanced/Move to end of line"),
565 compose_advanced_action_cb,
566 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
568 {N_("/_Edit/A_dvanced/Move to previous line"),
570 compose_advanced_action_cb,
571 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
573 {N_("/_Edit/A_dvanced/Move to next line"),
575 compose_advanced_action_cb,
576 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
578 {N_("/_Edit/A_dvanced/Delete a character backward"),
580 compose_advanced_action_cb,
581 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
583 {N_("/_Edit/A_dvanced/Delete a character forward"),
585 compose_advanced_action_cb,
586 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
588 {N_("/_Edit/A_dvanced/Delete a word backward"),
589 NULL, /* "<control>W" */
590 compose_advanced_action_cb,
591 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
593 {N_("/_Edit/A_dvanced/Delete a word forward"),
594 NULL, /* "<alt>D", */
595 compose_advanced_action_cb,
596 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
598 {N_("/_Edit/A_dvanced/Delete line"),
600 compose_advanced_action_cb,
601 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
603 {N_("/_Edit/A_dvanced/Delete entire line"),
605 compose_advanced_action_cb,
606 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
608 {N_("/_Edit/A_dvanced/Delete to end of line"),
610 compose_advanced_action_cb,
611 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
613 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
614 {N_("/_Edit/_Wrap current paragraph"),
615 "<control>L", compose_wrap_cb, 0, NULL},
616 {N_("/_Edit/Wrap all long _lines"),
617 "<control><alt>L", compose_wrap_cb, 1, NULL},
618 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
619 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
620 {N_("/_Edit/Edit with e_xternal editor"),
621 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
623 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
624 {N_("/_Spelling/_Check all or check selection"),
625 NULL, compose_check_all, 0, NULL},
626 {N_("/_Spelling/_Highlight all misspelled words"),
627 NULL, compose_highlight_all, 0, NULL},
628 {N_("/_Spelling/Check _backwards misspelled word"),
629 NULL, compose_check_backwards , 0, NULL},
630 {N_("/_Spelling/_Forward to next misspelled word"),
631 NULL, compose_check_forwards_go, 0, NULL},
632 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
633 {N_("/_Spelling/_Spelling Configuration"),
634 NULL, NULL, 0, "<Branch>"},
636 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
637 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
638 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
639 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
640 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
641 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
642 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
643 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
644 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
645 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
646 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
647 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
648 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
649 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
650 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
651 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
652 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
654 #define ENC_ACTION(action) \
655 NULL, compose_set_encoding_cb, action, \
656 "/Options/Character encoding/Automatic"
658 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
659 {N_("/_Options/Character _encoding/_Automatic"),
660 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
661 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
663 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
664 ENC_ACTION(C_US_ASCII)},
665 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
666 ENC_ACTION(C_UTF_8)},
667 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
669 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
670 ENC_ACTION(C_ISO_8859_1)},
671 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
672 ENC_ACTION(C_ISO_8859_15)},
673 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
675 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
676 ENC_ACTION(C_ISO_8859_2)},
677 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
679 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
680 ENC_ACTION(C_ISO_8859_13)},
681 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
682 ENC_ACTION(C_ISO_8859_4)},
683 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
685 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
686 ENC_ACTION(C_ISO_8859_7)},
687 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
689 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
690 ENC_ACTION(C_ISO_8859_8)},
691 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
692 ENC_ACTION(C_WINDOWS_1255)},
693 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
695 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
696 ENC_ACTION(C_ISO_8859_9)},
697 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
699 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
700 ENC_ACTION(C_ISO_8859_5)},
701 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
702 ENC_ACTION(C_KOI8_R)},
703 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
704 ENC_ACTION(C_KOI8_U)},
705 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
706 ENC_ACTION(C_WINDOWS_1251)},
707 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
709 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
710 ENC_ACTION(C_ISO_2022_JP)},
711 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
713 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
714 ENC_ACTION(C_GB2312)},
715 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
717 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
719 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
720 ENC_ACTION(C_EUC_TW)},
721 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
723 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
724 ENC_ACTION(C_EUC_KR)},
725 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
727 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
728 ENC_ACTION(C_TIS_620)},
729 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
730 ENC_ACTION(C_WINDOWS_874)},
732 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
733 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
734 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
735 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
736 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
737 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
738 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
741 static GtkTargetEntry compose_mime_types[] =
743 {"text/uri-list", 0, 0},
744 {"text/plain", 0, 0},
748 static gboolean compose_put_existing_to_front(MsgInfo *info)
750 GList *compose_list = compose_get_compose_list();
754 for (elem = compose_list; elem != NULL && elem->data != NULL;
756 Compose *c = (Compose*)elem->data;
758 if (!c->targetinfo || !c->targetinfo->msgid ||
762 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
763 gtkut_window_popup(c->window);
771 static GdkColor quote_color =
772 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
774 static GdkColor signature_color = {
781 static GdkColor uri_color = {
788 static GtkTextTag *no_wrap_tag = NULL;
790 static void compose_create_tags(GtkTextView *text, Compose *compose)
792 GtkTextBuffer *buffer;
793 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
795 buffer = gtk_text_view_get_buffer(text);
797 if (prefs_common.enable_color) {
798 /* grab the quote colors, converting from an int to a GdkColor */
799 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
801 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
803 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
806 signature_color = quote_color = uri_color = black;
809 gtk_text_buffer_create_tag(buffer, "quote",
810 "foreground-gdk", "e_color,
812 gtk_text_buffer_create_tag(buffer, "signature",
813 "foreground-gdk", &signature_color,
815 gtk_text_buffer_create_tag(buffer, "link",
816 "foreground-gdk", &uri_color,
818 no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
821 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
822 GPtrArray *attach_files)
824 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
827 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
829 return compose_generic_new(account, NULL, item, NULL, NULL);
832 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
834 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
837 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
838 GPtrArray *attach_files, GList *listAddress )
841 GtkTextView *textview;
842 GtkTextBuffer *textbuf;
844 GtkItemFactory *ifactory;
846 if (item && item->prefs && item->prefs->enable_default_account)
847 account = account_find_from_id(item->prefs->default_account);
849 if (!account) account = cur_account;
850 g_return_val_if_fail(account != NULL, NULL);
852 compose = compose_create(account, COMPOSE_NEW);
853 ifactory = gtk_item_factory_from_widget(compose->menubar);
855 compose->replyinfo = NULL;
856 compose->fwdinfo = NULL;
858 textview = GTK_TEXT_VIEW(compose->text);
859 textbuf = gtk_text_view_get_buffer(textview);
860 compose_create_tags(textview, compose);
862 undo_block(compose->undostruct);
864 if (item && item->prefs && item->prefs->enable_default_dictionary &&
866 gtkaspell_change_dict(compose->gtkaspell,
867 item->prefs->default_dictionary);
870 if (account->auto_sig)
871 compose_insert_sig(compose, FALSE);
872 gtk_text_buffer_get_start_iter(textbuf, &iter);
873 gtk_text_buffer_place_cursor(textbuf, &iter);
875 if (account->protocol != A_NNTP) {
876 if (mailto && *mailto != '\0') {
877 compose_entries_set(compose, mailto);
879 } else if (item && item->prefs->enable_default_to) {
880 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
881 compose_entry_mark_default_to(compose, item->prefs->default_to);
883 if (item && item->ret_rcpt) {
884 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
888 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
891 * CLAWS: just don't allow return receipt request, even if the user
892 * may want to send an email. simple but foolproof.
894 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
896 compose_add_field_list( compose, listAddress );
902 for (i = 0; i < attach_files->len; i++) {
903 file = g_ptr_array_index(attach_files, i);
904 compose_attach_append(compose, file, file, NULL);
908 compose_show_first_last_header(compose, TRUE);
910 /* Set save folder */
911 if (item && item->prefs && item->prefs->save_copy_to_folder) {
912 gchar *folderidentifier;
914 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
915 folderidentifier = folder_item_get_identifier(item);
916 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
917 g_free(folderidentifier);
920 gtk_widget_grab_focus(compose->header_last->entry);
922 undo_unblock(compose->undostruct);
924 if (prefs_common.auto_exteditor)
925 compose_exec_ext_editor(compose);
930 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
931 gboolean override_pref)
933 gchar *privacy = NULL;
935 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
938 if (account->default_privacy_system
939 && strlen(account->default_privacy_system)) {
940 privacy = account->default_privacy_system;
942 GSList *privacy_avail = privacy_get_system_ids();
943 if (privacy_avail && g_slist_length(privacy_avail)) {
944 privacy = (gchar *)(privacy_avail->data);
947 if (privacy != NULL) {
948 compose->privacy_system = g_strdup(privacy);
949 compose_update_privacy_system_menu_item(compose);
950 compose_use_encryption(compose, TRUE);
954 static void compose_force_signing(Compose *compose, PrefsAccount *account)
956 gchar *privacy = NULL;
958 if (account->default_privacy_system
959 && strlen(account->default_privacy_system)) {
960 privacy = account->default_privacy_system;
962 GSList *privacy_avail = privacy_get_system_ids();
963 if (privacy_avail && g_slist_length(privacy_avail)) {
964 privacy = (gchar *)(privacy_avail->data);
967 if (privacy != NULL) {
968 compose->privacy_system = g_strdup(privacy);
969 compose_update_privacy_system_menu_item(compose);
970 compose_use_signing(compose, TRUE);
974 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
979 g_return_if_fail(msginfo_list != NULL);
981 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
982 g_return_if_fail(msginfo != NULL);
984 list_len = g_slist_length(msginfo_list);
988 compose_reply(msginfo, prefs_common.reply_with_quote,
989 FALSE, prefs_common.default_reply_list, FALSE, body);
991 case COMPOSE_REPLY_WITH_QUOTE:
992 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
994 case COMPOSE_REPLY_WITHOUT_QUOTE:
995 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
997 case COMPOSE_REPLY_TO_SENDER:
998 compose_reply(msginfo, prefs_common.reply_with_quote,
999 FALSE, FALSE, TRUE, body);
1001 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1002 compose_followup_and_reply_to(msginfo,
1003 prefs_common.reply_with_quote,
1004 FALSE, FALSE, body);
1006 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1007 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
1009 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1010 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
1012 case COMPOSE_REPLY_TO_ALL:
1013 compose_reply(msginfo, prefs_common.reply_with_quote,
1014 TRUE, FALSE, FALSE, body);
1016 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1017 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
1019 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1020 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
1022 case COMPOSE_REPLY_TO_LIST:
1023 compose_reply(msginfo, prefs_common.reply_with_quote,
1024 FALSE, TRUE, FALSE, body);
1026 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1027 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
1029 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1030 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
1032 case COMPOSE_FORWARD:
1033 if (prefs_common.forward_as_attachment) {
1034 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1037 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1041 case COMPOSE_FORWARD_INLINE:
1042 /* check if we reply to more than one Message */
1043 if (list_len == 1) {
1044 compose_forward(NULL, msginfo, FALSE, body, FALSE);
1047 /* more messages FALL THROUGH */
1048 case COMPOSE_FORWARD_AS_ATTACH:
1049 compose_forward_multiple(NULL, msginfo_list);
1051 case COMPOSE_REDIRECT:
1052 compose_redirect(NULL, msginfo);
1055 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1059 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1060 gboolean to_ml, gboolean to_sender,
1063 compose_generic_reply(msginfo, quote, to_all, to_ml,
1064 to_sender, FALSE, body);
1067 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1072 compose_generic_reply(msginfo, quote, to_all, FALSE,
1073 to_sender, TRUE, body);
1076 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1077 gboolean to_all, gboolean to_ml,
1079 gboolean followup_and_reply_to,
1082 GtkItemFactory *ifactory;
1084 PrefsAccount *account = NULL;
1085 PrefsAccount *reply_account;
1086 GtkTextView *textview;
1087 GtkTextBuffer *textbuf;
1091 g_return_if_fail(msginfo != NULL);
1092 g_return_if_fail(msginfo->folder != NULL);
1094 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1096 g_return_if_fail(account != NULL);
1098 if (to_sender && account->protocol == A_NNTP &&
1099 !followup_and_reply_to) {
1101 account_find_from_address(account->address);
1103 reply_account = compose_current_mail_account();
1107 reply_account = account;
1109 compose = compose_create(account, COMPOSE_REPLY);
1110 ifactory = gtk_item_factory_from_widget(compose->menubar);
1112 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1113 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1115 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1116 if (!compose->replyinfo)
1117 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1119 if (msginfo->folder && msginfo->folder->ret_rcpt)
1120 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1122 /* Set save folder */
1123 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1124 gchar *folderidentifier;
1126 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1127 folderidentifier = folder_item_get_identifier(msginfo->folder);
1128 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1129 g_free(folderidentifier);
1132 if (compose_parse_header(compose, msginfo) < 0) return;
1133 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1134 to_sender, followup_and_reply_to);
1135 compose_show_first_last_header(compose, TRUE);
1137 textview = (GTK_TEXT_VIEW(compose->text));
1138 textbuf = gtk_text_view_get_buffer(textview);
1139 compose_create_tags(textview, compose);
1141 undo_block(compose->undostruct);
1143 if (msginfo->folder && msginfo->folder->prefs &&
1144 msginfo->folder->prefs &&
1145 msginfo->folder->prefs->enable_default_dictionary &&
1147 gtkaspell_change_dict(compose->gtkaspell,
1148 msginfo->folder->prefs->default_dictionary);
1154 if (prefs_common.quotemark && *prefs_common.quotemark)
1155 qmark = prefs_common.quotemark;
1159 compose_quote_fmt(compose, compose->replyinfo,
1160 prefs_common.quotefmt,
1163 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1164 compose_force_encryption(compose, account, FALSE);
1167 if (account->auto_sig)
1168 compose_insert_sig(compose, FALSE);
1170 cursor_pos = quote_fmt_get_cursor_pos();
1171 gtk_text_buffer_get_start_iter(textbuf, &iter);
1172 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cursor_pos);
1173 gtk_text_buffer_place_cursor(textbuf, &iter);
1175 compose_wrap_all(compose);
1177 gtk_widget_grab_focus(compose->text);
1179 undo_unblock(compose->undostruct);
1181 if (prefs_common.auto_exteditor)
1182 compose_exec_ext_editor(compose);
1185 #define INSERT_FW_HEADER(var, hdr) \
1186 if (msginfo->var && *msginfo->var) { \
1187 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1188 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1189 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1192 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1193 gboolean as_attach, const gchar *body,
1194 gboolean no_extedit)
1197 GtkTextView *textview;
1198 GtkTextBuffer *textbuf;
1201 g_return_val_if_fail(msginfo != NULL, NULL);
1202 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1205 !(account = compose_guess_forward_account_from_msginfo
1207 account = cur_account;
1209 compose = compose_create(account, COMPOSE_FORWARD);
1211 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1212 if (!compose->fwdinfo)
1213 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1215 if (msginfo->subject && *msginfo->subject) {
1216 gchar *buf, *buf2, *p;
1218 buf = p = g_strdup(msginfo->subject);
1219 p += subject_get_prefix_length(p);
1220 memmove(buf, p, strlen(p) + 1);
1222 buf2 = g_strdup_printf("Fw: %s", buf);
1223 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1229 textview = GTK_TEXT_VIEW(compose->text);
1230 textbuf = gtk_text_view_get_buffer(textview);
1231 compose_create_tags(textview, compose);
1236 msgfile = procmsg_get_message_file_path(msginfo);
1237 if (!is_file_exist(msgfile))
1238 g_warning("%s: file not exist\n", msgfile);
1240 compose_attach_append(compose, msgfile, msgfile,
1246 MsgInfo *full_msginfo;
1248 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1250 full_msginfo = procmsg_msginfo_copy(msginfo);
1252 if (prefs_common.fw_quotemark &&
1253 *prefs_common.fw_quotemark)
1254 qmark = prefs_common.fw_quotemark;
1258 compose_quote_fmt(compose, full_msginfo,
1259 prefs_common.fw_quotefmt,
1261 compose_attach_parts(compose, msginfo);
1263 procmsg_msginfo_free(full_msginfo);
1266 if (account->auto_sig)
1267 compose_insert_sig(compose, FALSE);
1269 compose_wrap_all(compose);
1271 gtk_text_buffer_get_start_iter(textbuf, &iter);
1272 gtk_text_buffer_place_cursor(textbuf, &iter);
1274 gtk_widget_grab_focus(compose->header_last->entry);
1276 if (!no_extedit && prefs_common.auto_exteditor)
1277 compose_exec_ext_editor(compose);
1280 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1281 gchar *folderidentifier;
1283 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1284 folderidentifier = folder_item_get_identifier(msginfo->folder);
1285 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1286 g_free(folderidentifier);
1292 #undef INSERT_FW_HEADER
1294 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1297 GtkTextView *textview;
1298 GtkTextBuffer *textbuf;
1303 g_return_val_if_fail(msginfo_list != NULL, NULL);
1305 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1306 if (((MsgInfo *)msginfo->data)->folder == NULL)
1309 /* guess account from first selected message */
1311 !(account = compose_guess_forward_account_from_msginfo
1312 (msginfo_list->data)))
1313 account = cur_account;
1315 g_return_val_if_fail(account != NULL, NULL);
1317 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1318 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1319 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1322 compose = compose_create(account, COMPOSE_FORWARD);
1324 textview = GTK_TEXT_VIEW(compose->text);
1325 textbuf = gtk_text_view_get_buffer(textview);
1326 compose_create_tags(textview, compose);
1328 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1329 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1330 if (!is_file_exist(msgfile))
1331 g_warning("%s: file not exist\n", msgfile);
1333 compose_attach_append(compose, msgfile, msgfile,
1338 if (account->auto_sig)
1339 compose_insert_sig(compose, FALSE);
1341 compose_wrap_all(compose);
1343 gtk_text_buffer_get_start_iter(textbuf, &iter);
1344 gtk_text_buffer_place_cursor(textbuf, &iter);
1346 gtk_widget_grab_focus(compose->header_last->entry);
1351 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1353 GtkTextIter start = *iter;
1354 GtkTextIter end_iter;
1355 int start_pos = gtk_text_iter_get_offset(&start);
1357 if (!compose->account->sig_sep)
1360 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1361 start_pos+strlen(compose->account->sig_sep));
1363 /* check sig separator */
1364 if (!strcmp(gtk_text_iter_get_text(&start, &end_iter),
1365 compose->account->sig_sep)) {
1366 /* check end of line (\n) */
1367 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1368 start_pos+strlen(compose->account->sig_sep));
1369 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1370 start_pos+strlen(compose->account->sig_sep)+1);
1372 if (!strcmp(gtk_text_iter_get_text(&start, &end_iter),"\n"));
1381 static void compose_colorize_signature(Compose *compose)
1383 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1385 GtkTextIter end_iter;
1386 gtk_text_buffer_get_start_iter(buffer, &iter);
1387 while (gtk_text_iter_forward_line(&iter))
1388 if (compose_is_sig_separator(compose, buffer, &iter)) {
1389 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1390 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1394 void compose_reedit(MsgInfo *msginfo)
1396 Compose *compose = NULL;
1397 PrefsAccount *account = NULL;
1398 GtkTextView *textview;
1399 GtkTextBuffer *textbuf;
1403 gchar buf[BUFFSIZE];
1404 gboolean use_signing = FALSE;
1405 gboolean use_encryption = FALSE;
1406 gchar *privacy_system = NULL;
1408 g_return_if_fail(msginfo != NULL);
1409 g_return_if_fail(msginfo->folder != NULL);
1411 if (compose_put_existing_to_front(msginfo))
1414 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1415 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1416 gchar queueheader_buf[BUFFSIZE];
1419 /* Select Account from queue headers */
1420 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1421 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1422 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1423 account = account_find_from_id(id);
1425 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1426 sizeof(queueheader_buf), "NAID:")) {
1427 id = atoi(&queueheader_buf[strlen("NAID:")]);
1428 account = account_find_from_id(id);
1430 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1431 sizeof(queueheader_buf), "MAID:")) {
1432 id = atoi(&queueheader_buf[strlen("MAID:")]);
1433 account = account_find_from_id(id);
1435 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1436 sizeof(queueheader_buf), "S:")) {
1437 account = account_find_from_address(queueheader_buf);
1439 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1440 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1441 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1442 use_signing = param;
1445 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1446 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1447 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1448 use_encryption = param;
1450 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1451 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1452 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1454 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1455 sizeof(queueheader_buf), "X-Priority: ")) {
1456 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1457 compose->priority = param;
1460 account = msginfo->folder->folder->account;
1462 if (!account && prefs_common.reedit_account_autosel) {
1463 gchar from[BUFFSIZE];
1464 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1465 extract_address(from);
1466 account = account_find_from_address(from);
1469 if (!account) account = cur_account;
1470 g_return_if_fail(account != NULL);
1472 compose = compose_create(account, COMPOSE_REEDIT);
1473 if (privacy_system != NULL) {
1474 compose->privacy_system = privacy_system;
1475 compose_use_signing(compose, use_signing);
1476 compose_use_encryption(compose, use_encryption);
1477 compose_update_privacy_system_menu_item(compose);
1479 activate_privacy_system(compose, account);
1481 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1483 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1484 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1485 gchar queueheader_buf[BUFFSIZE];
1487 /* Set message save folder */
1488 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1491 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1492 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1493 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1497 if (compose_parse_header(compose, msginfo) < 0) return;
1498 compose_reedit_set_entry(compose, msginfo);
1500 textview = GTK_TEXT_VIEW(compose->text);
1501 textbuf = gtk_text_view_get_buffer(textview);
1502 compose_create_tags(textview, compose);
1504 mark = gtk_text_buffer_get_insert(textbuf);
1505 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1507 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1508 G_CALLBACK(compose_changed_cb),
1511 if (procmime_msginfo_is_encrypted(msginfo)) {
1512 fp = procmime_get_first_encrypted_text_content(msginfo);
1514 compose_force_encryption(compose, account, TRUE);
1516 fp = procmime_get_first_text_content(msginfo);
1518 g_warning("Can't get text part\n");
1521 gboolean prev_autowrap = compose->autowrap;
1523 compose->autowrap = FALSE;
1524 while (fgets(buf, sizeof(buf), fp) != NULL) {
1526 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1528 compose->autowrap = prev_autowrap;
1532 compose_attach_parts(compose, msginfo);
1534 compose_colorize_signature(compose);
1536 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1537 G_CALLBACK(compose_changed_cb),
1540 gtk_widget_grab_focus(compose->text);
1542 if (prefs_common.auto_exteditor)
1543 compose_exec_ext_editor(compose);
1546 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1550 GtkItemFactory *ifactory;
1553 g_return_val_if_fail(msginfo != NULL, NULL);
1556 account = account_get_reply_account(msginfo,
1557 prefs_common.reply_account_autosel);
1558 g_return_val_if_fail(account != NULL, NULL);
1560 compose = compose_create(account, COMPOSE_REDIRECT);
1561 ifactory = gtk_item_factory_from_widget(compose->menubar);
1562 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1563 compose->replyinfo = NULL;
1564 compose->fwdinfo = NULL;
1566 compose_show_first_last_header(compose, TRUE);
1568 gtk_widget_grab_focus(compose->header_last->entry);
1570 filename = procmsg_get_message_file_path(msginfo);
1571 if (filename == NULL)
1574 compose->redirect_filename = filename;
1576 /* Set save folder */
1577 item = msginfo->folder;
1578 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1579 gchar *folderidentifier;
1581 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1582 folderidentifier = folder_item_get_identifier(item);
1583 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1584 g_free(folderidentifier);
1587 compose_attach_parts(compose, msginfo);
1589 if (msginfo->subject)
1590 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1592 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1594 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1595 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1597 compose_colorize_signature(compose);
1599 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1600 menu_set_sensitive(ifactory, "/Add...", FALSE);
1601 menu_set_sensitive(ifactory, "/Remove", FALSE);
1602 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1604 ifactory = gtk_item_factory_from_widget(compose->menubar);
1605 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1606 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1607 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1608 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1609 menu_set_sensitive(ifactory, "/Edit", FALSE);
1610 menu_set_sensitive(ifactory, "/Options", FALSE);
1611 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1612 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1614 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1615 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1616 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1617 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1618 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1619 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1620 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1625 GList *compose_get_compose_list(void)
1627 return compose_list;
1630 void compose_entry_append(Compose *compose, const gchar *address,
1631 ComposeEntryType type)
1635 gboolean in_quote = FALSE;
1636 if (!address || *address == '\0') return;
1643 header = N_("Bcc:");
1645 case COMPOSE_REPLYTO:
1646 header = N_("Reply-To:");
1648 case COMPOSE_NEWSGROUPS:
1649 header = N_("Newsgroups:");
1651 case COMPOSE_FOLLOWUPTO:
1652 header = N_( "Followup-To:");
1659 header = prefs_common.trans_hdr ? gettext(header) : header;
1661 cur = begin = (gchar *)address;
1663 /* we separate the line by commas, but not if we're inside a quoted
1665 while (*cur != '\0') {
1667 in_quote = !in_quote;
1668 if (*cur == ',' && !in_quote) {
1669 gchar *tmp = g_strdup(begin);
1671 tmp[cur-begin]='\0';
1676 compose_add_header_entry(compose, header, tmp);
1683 gchar *tmp = g_strdup(begin);
1685 tmp[cur-begin]='\0';
1690 compose_add_header_entry(compose, header, tmp);
1695 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1697 static GtkStyle *bold_style = NULL;
1698 static GdkColor bold_color;
1702 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1703 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1704 if (gtk_entry_get_text(entry) &&
1705 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1706 gtk_widget_ensure_style(GTK_WIDGET(entry));
1708 PangoFontDescription *font_desc = NULL;
1709 gtkut_convert_int_to_gdk_color
1710 (prefs_common.color_new, &bold_color);
1711 bold_style = gtk_style_copy(gtk_widget_get_style
1712 (GTK_WIDGET(entry)));
1713 pango_font_description_set_weight
1714 (bold_style->font_desc, PANGO_WEIGHT_BOLD);
1715 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1717 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1722 void compose_toolbar_cb(gint action, gpointer data)
1724 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1725 Compose *compose = (Compose*)toolbar_item->parent;
1727 g_return_if_fail(compose != NULL);
1731 compose_send_cb(compose, 0, NULL);
1734 compose_send_later_cb(compose, 0, NULL);
1737 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1740 compose_insert_file_cb(compose, 0, NULL);
1743 compose_attach_cb(compose, 0, NULL);
1746 compose_insert_sig(compose, FALSE);
1749 compose_ext_editor_cb(compose, 0, NULL);
1751 case A_LINEWRAP_CURRENT:
1752 compose_wrap_paragraph(compose, NULL, TRUE);
1754 case A_LINEWRAP_ALL:
1755 compose_wrap_all_full(compose, TRUE);
1758 compose_address_cb(compose, 0, NULL);
1761 case A_CHECK_SPELLING:
1762 compose_check_all(compose);
1770 static void compose_entries_set(Compose *compose, const gchar *mailto)
1774 gchar *subject = NULL;
1779 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1782 compose_entry_append(compose, to, COMPOSE_TO);
1784 compose_entry_append(compose, cc, COMPOSE_CC);
1786 if (!g_utf8_validate (subject, -1, NULL)) {
1787 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1788 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1791 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1795 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1796 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1799 gboolean prev_autowrap = compose->autowrap;
1801 compose->autowrap = FALSE;
1803 mark = gtk_text_buffer_get_insert(buffer);
1804 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1806 if (!g_utf8_validate (body, -1, NULL)) {
1807 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1808 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1811 gtk_text_buffer_insert(buffer, &iter, body, -1);
1813 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1815 compose->autowrap = prev_autowrap;
1816 if (compose->autowrap)
1817 compose_wrap_all(compose);
1826 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1828 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1829 {"Cc:", NULL, TRUE},
1830 {"References:", NULL, FALSE},
1831 {"Bcc:", NULL, TRUE},
1832 {"Newsgroups:", NULL, TRUE},
1833 {"Followup-To:", NULL, TRUE},
1834 {"List-Post:", NULL, FALSE},
1835 {"X-Priority:", NULL, FALSE},
1836 {NULL, NULL, FALSE}};
1852 g_return_val_if_fail(msginfo != NULL, -1);
1854 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1855 procheader_get_header_fields(fp, hentry);
1858 if (hentry[H_REPLY_TO].body != NULL) {
1859 if (hentry[H_REPLY_TO].body[0] != '\0') {
1861 conv_unmime_header(hentry[H_REPLY_TO].body,
1864 g_free(hentry[H_REPLY_TO].body);
1865 hentry[H_REPLY_TO].body = NULL;
1867 if (hentry[H_CC].body != NULL) {
1868 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
1869 g_free(hentry[H_CC].body);
1870 hentry[H_CC].body = NULL;
1872 if (hentry[H_REFERENCES].body != NULL) {
1873 if (compose->mode == COMPOSE_REEDIT)
1874 compose->references = hentry[H_REFERENCES].body;
1876 compose->references = compose_parse_references
1877 (hentry[H_REFERENCES].body, msginfo->msgid);
1878 g_free(hentry[H_REFERENCES].body);
1880 hentry[H_REFERENCES].body = NULL;
1882 if (hentry[H_BCC].body != NULL) {
1883 if (compose->mode == COMPOSE_REEDIT)
1885 conv_unmime_header(hentry[H_BCC].body, NULL);
1886 g_free(hentry[H_BCC].body);
1887 hentry[H_BCC].body = NULL;
1889 if (hentry[H_NEWSGROUPS].body != NULL) {
1890 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1891 hentry[H_NEWSGROUPS].body = NULL;
1893 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1894 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
1895 compose->followup_to =
1896 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
1899 g_free(hentry[H_FOLLOWUP_TO].body);
1900 hentry[H_FOLLOWUP_TO].body = NULL;
1902 if (hentry[H_LIST_POST].body != NULL) {
1905 extract_address(hentry[H_LIST_POST].body);
1906 if (hentry[H_LIST_POST].body[0] != '\0') {
1907 scan_mailto_url(hentry[H_LIST_POST].body,
1908 &to, NULL, NULL, NULL, NULL);
1910 g_free(compose->ml_post);
1911 compose->ml_post = to;
1914 g_free(hentry[H_LIST_POST].body);
1915 hentry[H_LIST_POST].body = NULL;
1918 /* CLAWS - X-Priority */
1919 if (compose->mode == COMPOSE_REEDIT)
1920 if (hentry[H_X_PRIORITY].body != NULL) {
1923 priority = atoi(hentry[H_X_PRIORITY].body);
1924 g_free(hentry[H_X_PRIORITY].body);
1926 hentry[H_X_PRIORITY].body = NULL;
1928 if (priority < PRIORITY_HIGHEST ||
1929 priority > PRIORITY_LOWEST)
1930 priority = PRIORITY_NORMAL;
1932 compose->priority = priority;
1935 if (compose->mode == COMPOSE_REEDIT) {
1936 if (msginfo->inreplyto && *msginfo->inreplyto)
1937 compose->inreplyto = g_strdup(msginfo->inreplyto);
1941 if (msginfo->msgid && *msginfo->msgid)
1942 compose->inreplyto = g_strdup(msginfo->msgid);
1944 if (!compose->references) {
1945 if (msginfo->msgid && *msginfo->msgid) {
1946 if (msginfo->inreplyto && *msginfo->inreplyto)
1947 compose->references =
1948 g_strdup_printf("<%s>\n\t<%s>",
1952 compose->references =
1953 g_strconcat("<", msginfo->msgid, ">",
1955 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
1956 compose->references =
1957 g_strconcat("<", msginfo->inreplyto, ">",
1965 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1967 GSList *ref_id_list, *cur;
1971 ref_id_list = references_list_append(NULL, ref);
1972 if (!ref_id_list) return NULL;
1973 if (msgid && *msgid)
1974 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1979 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1980 /* "<" + Message-ID + ">" + CR+LF+TAB */
1981 len += strlen((gchar *)cur->data) + 5;
1983 if (len > MAX_REFERENCES_LEN) {
1984 /* remove second message-ID */
1985 if (ref_id_list && ref_id_list->next &&
1986 ref_id_list->next->next) {
1987 g_free(ref_id_list->next->data);
1988 ref_id_list = g_slist_remove
1989 (ref_id_list, ref_id_list->next->data);
1991 slist_free_strings(ref_id_list);
1992 g_slist_free(ref_id_list);
1999 new_ref = g_string_new("");
2000 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2001 if (new_ref->len > 0)
2002 g_string_append(new_ref, "\n\t");
2003 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2006 slist_free_strings(ref_id_list);
2007 g_slist_free(ref_id_list);
2009 new_ref_str = new_ref->str;
2010 g_string_free(new_ref, FALSE);
2015 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2016 const gchar *fmt, const gchar *qmark,
2019 static MsgInfo dummyinfo;
2020 gchar *quote_str = NULL;
2024 gboolean prev_autowrap;
2025 const gchar *trimmed_body = body;
2026 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2027 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2030 msginfo = &dummyinfo;
2032 if (qmark != NULL) {
2033 quote_fmt_init(msginfo, NULL, NULL);
2034 quote_fmt_scan_string(qmark);
2037 buf = quote_fmt_get_buffer();
2039 alertpanel_error(_("Quote mark format error."));
2041 Xstrdup_a(quote_str, buf, return NULL)
2044 if (fmt && *fmt != '\0') {
2045 while (trimmed_body && strlen(trimmed_body) > 1
2046 && trimmed_body[0]=='\n')
2049 quote_fmt_init(msginfo, quote_str, trimmed_body);
2050 quote_fmt_scan_string(fmt);
2053 buf = quote_fmt_get_buffer();
2055 alertpanel_error(_("Message reply/forward format error."));
2061 prev_autowrap = compose->autowrap;
2062 compose->autowrap = FALSE;
2064 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2065 G_CALLBACK(compose_changed_cb),
2067 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2068 G_CALLBACK(text_inserted),
2070 for (p = buf; *p != '\0'; ) {
2075 mark = gtk_text_buffer_get_insert(buffer);
2076 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2078 lastp = strchr(p, '\n');
2079 len = lastp ? lastp - p + 1 : -1;
2081 gtk_text_buffer_insert(buffer, &iter, p, len);
2089 compose->autowrap = prev_autowrap;
2090 if (compose->autowrap)
2091 compose_wrap_all(compose);
2093 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2094 G_CALLBACK(compose_changed_cb),
2096 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2097 G_CALLBACK(text_inserted),
2104 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2105 gboolean to_all, gboolean to_ml,
2107 gboolean followup_and_reply_to)
2109 GSList *cc_list = NULL;
2112 gchar *replyto = NULL;
2113 GHashTable *to_table;
2115 g_return_if_fail(compose->account != NULL);
2116 g_return_if_fail(msginfo != NULL);
2118 if (compose->account->protocol != A_NNTP) {
2119 if (!compose->replyto && to_ml && compose->ml_post
2120 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
2121 compose_entry_append(compose,
2124 else if (!(to_all || to_sender)
2126 && msginfo->folder->prefs->enable_default_reply_to) {
2127 compose_entry_append(compose,
2128 msginfo->folder->prefs->default_reply_to,
2131 compose_entry_append(compose,
2132 (compose->replyto && !to_sender)
2133 ? compose->replyto :
2134 msginfo->from ? msginfo->from : "",
2137 if (to_sender || (compose->followup_to &&
2138 !strncmp(compose->followup_to, "poster", 6)))
2139 compose_entry_append
2141 (compose->replyto ? compose->replyto :
2142 msginfo->from ? msginfo->from : ""),
2145 else if (followup_and_reply_to || to_all) {
2146 compose_entry_append
2148 (compose->replyto ? compose->replyto :
2149 msginfo->from ? msginfo->from : ""),
2152 compose_entry_append
2154 compose->followup_to ? compose->followup_to :
2155 compose->newsgroups ? compose->newsgroups : "",
2156 COMPOSE_NEWSGROUPS);
2159 compose_entry_append
2161 compose->followup_to ? compose->followup_to :
2162 compose->newsgroups ? compose->newsgroups : "",
2163 COMPOSE_NEWSGROUPS);
2166 if (msginfo->subject && *msginfo->subject) {
2170 buf = p = g_strdup(msginfo->subject);
2171 p += subject_get_prefix_length(p);
2172 memmove(buf, p, strlen(p) + 1);
2174 buf2 = g_strdup_printf("Re: %s", buf);
2175 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2180 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2182 if (to_ml && compose->ml_post) return;
2183 if (!to_all || compose->account->protocol == A_NNTP) return;
2185 if (compose->replyto) {
2186 Xstrdup_a(replyto, compose->replyto, return);
2187 extract_address(replyto);
2189 if (msginfo->from) {
2190 Xstrdup_a(from, msginfo->from, return);
2191 extract_address(from);
2194 if (replyto && from)
2195 cc_list = address_list_append_with_comments(cc_list, from);
2196 if (to_all && msginfo->folder &&
2197 msginfo->folder->prefs->enable_default_reply_to)
2198 cc_list = address_list_append_with_comments(cc_list,
2199 msginfo->folder->prefs->default_reply_to);
2200 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2201 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2203 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2205 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2206 if (compose->account)
2207 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2208 GINT_TO_POINTER(1));
2210 /* remove address on To: and that of current account */
2211 for (cur = cc_list; cur != NULL; ) {
2212 GSList *next = cur->next;
2215 addr = g_strdup(cur->data);
2216 extract_address(addr);
2218 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2219 cc_list = g_slist_remove(cc_list, cur->data);
2221 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2225 hash_free_strings(to_table);
2226 g_hash_table_destroy(to_table);
2229 for (cur = cc_list; cur != NULL; cur = cur->next)
2230 compose_entry_append(compose, (gchar *)cur->data,
2232 slist_free_strings(cc_list);
2233 g_slist_free(cc_list);
2238 #define SET_ENTRY(entry, str) \
2241 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2244 #define SET_ADDRESS(type, str) \
2247 compose_entry_append(compose, str, type); \
2250 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2252 g_return_if_fail(msginfo != NULL);
2254 SET_ENTRY(subject_entry, msginfo->subject);
2255 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2256 SET_ADDRESS(COMPOSE_CC, compose->cc);
2257 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2258 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2259 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2260 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2262 compose_update_priority_menu_item(compose);
2263 compose_update_privacy_system_menu_item(compose);
2264 compose_show_first_last_header(compose, TRUE);
2270 static void compose_insert_sig(Compose *compose, gboolean replace)
2272 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2273 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2275 GtkTextIter iter, iter_end;
2277 gboolean prev_autowrap;
2280 g_return_if_fail(compose->account != NULL);
2282 prev_autowrap = compose->autowrap;
2283 compose->autowrap = FALSE;
2285 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2286 G_CALLBACK(compose_changed_cb),
2289 mark = gtk_text_buffer_get_insert(buffer);
2290 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2291 cur_pos = gtk_text_iter_get_offset (&iter);
2293 gtk_text_buffer_get_end_iter(buffer, &iter);
2295 if (replace && compose->sig_str) {
2297 GtkTextIter first_iter, start_iter, end_iter;
2299 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2301 if (compose->sig_str[0] == '\0')
2304 found = gtk_text_iter_forward_search(&first_iter,
2306 GTK_TEXT_SEARCH_TEXT_ONLY,
2307 &start_iter, &end_iter,
2311 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2316 g_free(compose->sig_str);
2317 compose->sig_str = compose_get_signature_str(compose);
2318 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2319 compose->sig_str = g_strdup("");
2321 cur_pos = gtk_text_iter_get_offset(&iter);
2322 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2324 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2325 gtk_text_iter_forward_char(&iter);
2326 gtk_text_iter_forward_char(&iter);
2327 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2328 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2330 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2331 cur_pos = gtk_text_buffer_get_char_count (buffer);
2333 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2334 gtk_text_buffer_place_cursor(buffer, &iter);
2336 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2337 G_CALLBACK(compose_changed_cb),
2340 compose->autowrap = prev_autowrap;
2341 if (compose->autowrap)
2342 compose_wrap_all(compose);
2345 static gchar *compose_get_signature_str(Compose *compose)
2347 gchar *sig_body = NULL;
2348 gchar *sig_str = NULL;
2349 gchar *utf8_sig_str = NULL;
2351 g_return_val_if_fail(compose->account != NULL, NULL);
2353 if (!compose->account->sig_path)
2356 if (compose->account->sig_type == SIG_FILE) {
2357 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2358 g_warning("can't open signature file: %s\n",
2359 compose->account->sig_path);
2364 if (compose->account->sig_type == SIG_COMMAND)
2365 sig_body = get_command_output(compose->account->sig_path);
2369 tmp = file_read_to_str(compose->account->sig_path);
2372 sig_body = normalize_newlines(tmp);
2376 if (compose->account->sig_sep) {
2377 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2381 sig_str = g_strconcat("\n\n", sig_body, NULL);
2384 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2385 utf8_sig_str = sig_str;
2387 utf8_sig_str = conv_codeset_strdup
2388 (sig_str, conv_get_locale_charset_str(),
2394 return utf8_sig_str;
2397 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2400 GtkTextBuffer *buffer;
2403 const gchar *cur_encoding;
2404 gchar buf[BUFFSIZE];
2407 gboolean prev_autowrap;
2408 gboolean badtxt = FALSE;
2410 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2412 if ((fp = g_fopen(file, "rb")) == NULL) {
2413 FILE_OP_ERROR(file, "fopen");
2414 return COMPOSE_INSERT_READ_ERROR;
2417 prev_autowrap = compose->autowrap;
2418 compose->autowrap = FALSE;
2420 text = GTK_TEXT_VIEW(compose->text);
2421 buffer = gtk_text_view_get_buffer(text);
2422 mark = gtk_text_buffer_get_insert(buffer);
2423 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2425 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2426 G_CALLBACK(text_inserted),
2429 cur_encoding = conv_get_locale_charset_str();
2431 while (fgets(buf, sizeof(buf), fp) != NULL) {
2434 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2435 str = g_strdup(buf);
2437 str = conv_codeset_strdup
2438 (buf, cur_encoding, CS_INTERNAL);
2441 /* strip <CR> if DOS/Windows file,
2442 replace <CR> with <LF> if Macintosh file. */
2445 if (len > 0 && str[len - 1] != '\n') {
2447 if (str[len] == '\r') str[len] = '\n';
2450 gtk_text_buffer_insert(buffer, &iter, str, -1);
2454 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2455 G_CALLBACK(text_inserted),
2457 compose->autowrap = prev_autowrap;
2458 if (compose->autowrap)
2459 compose_wrap_all(compose);
2464 return COMPOSE_INSERT_INVALID_CHARACTER;
2466 return COMPOSE_INSERT_SUCCESS;
2469 static void compose_attach_append(Compose *compose, const gchar *file,
2470 const gchar *filename,
2471 const gchar *content_type)
2479 GtkListStore *store;
2482 if (!is_file_exist(file)) {
2483 g_warning("File %s doesn't exist\n", filename);
2486 if ((size = get_file_size(file)) < 0) {
2487 g_warning("Can't get file size of %s\n", filename);
2491 alertpanel_notice(_("File %s is empty."), filename);
2494 if ((fp = g_fopen(file, "rb")) == NULL) {
2495 alertpanel_error(_("Can't read %s."), filename);
2500 ainfo = g_new0(AttachInfo, 1);
2501 auto_ainfo = g_auto_pointer_new_with_free
2502 (ainfo, (GFreeFunc) compose_attach_info_free);
2503 ainfo->file = g_strdup(file);
2506 ainfo->content_type = g_strdup(content_type);
2507 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2509 MsgFlags flags = {0, 0};
2511 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2512 ainfo->encoding = ENC_7BIT;
2514 ainfo->encoding = ENC_8BIT;
2516 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2517 if (msginfo && msginfo->subject)
2518 name = g_strdup(msginfo->subject);
2520 name = g_path_get_basename(filename ? filename : file);
2522 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2524 procmsg_msginfo_free(msginfo);
2526 if (!g_ascii_strncasecmp(content_type, "text", 4))
2527 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2529 ainfo->encoding = ENC_BASE64;
2530 name = g_path_get_basename(filename ? filename : file);
2531 ainfo->name = g_strdup(name);
2535 ainfo->content_type = procmime_get_mime_type(file);
2536 if (!ainfo->content_type) {
2537 ainfo->content_type =
2538 g_strdup("application/octet-stream");
2539 ainfo->encoding = ENC_BASE64;
2540 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2542 procmime_get_encoding_for_text_file(file);
2544 ainfo->encoding = ENC_BASE64;
2545 name = g_path_get_basename(filename ? filename : file);
2546 ainfo->name = g_strdup(name);
2550 if (!strcmp(ainfo->content_type, "unknown")) {
2551 g_free(ainfo->content_type);
2552 ainfo->content_type = g_strdup("application/octet-stream");
2556 size_text = to_human_readable(size);
2558 store = GTK_LIST_STORE(gtk_tree_view_get_model
2559 (GTK_TREE_VIEW(compose->attach_clist)));
2561 gtk_list_store_append(store, &iter);
2562 gtk_list_store_set(store, &iter,
2563 COL_MIMETYPE, ainfo->content_type,
2564 COL_SIZE, size_text,
2565 COL_NAME, ainfo->name,
2567 COL_AUTODATA, auto_ainfo,
2570 g_auto_pointer_free(auto_ainfo);
2573 static void compose_use_signing(Compose *compose, gboolean use_signing)
2575 GtkItemFactory *ifactory;
2576 GtkWidget *menuitem = NULL;
2578 compose->use_signing = use_signing;
2579 ifactory = gtk_item_factory_from_widget(compose->menubar);
2580 menuitem = gtk_item_factory_get_item
2581 (ifactory, "/Options/Sign");
2582 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2586 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2588 GtkItemFactory *ifactory;
2589 GtkWidget *menuitem = NULL;
2591 compose->use_encryption = use_encryption;
2592 ifactory = gtk_item_factory_from_widget(compose->menubar);
2593 menuitem = gtk_item_factory_get_item
2594 (ifactory, "/Options/Encrypt");
2596 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2600 #define NEXT_PART_NOT_CHILD(info) \
2602 node = info->node; \
2603 while (node->children) \
2604 node = g_node_last_child(node); \
2605 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2608 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2612 MimeInfo *firsttext = NULL;
2613 MimeInfo *encrypted = NULL;
2616 const gchar *partname = NULL;
2618 mimeinfo = procmime_scan_message(msginfo);
2619 if (!mimeinfo) return;
2621 if (mimeinfo->node->children == NULL) {
2622 procmime_mimeinfo_free_all(mimeinfo);
2626 /* find first content part */
2627 child = (MimeInfo *) mimeinfo->node->children->data;
2628 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2629 child = (MimeInfo *)child->node->children->data;
2631 if (child->type == MIMETYPE_TEXT) {
2633 debug_print("First text part found\n");
2634 } else if (compose->mode == COMPOSE_REEDIT &&
2635 child->type == MIMETYPE_APPLICATION &&
2636 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2637 encrypted = (MimeInfo *)child->node->parent->data;
2640 child = (MimeInfo *) mimeinfo->node->children->data;
2641 while (child != NULL) {
2642 if (child == encrypted) {
2643 /* skip this part of tree */
2644 NEXT_PART_NOT_CHILD(child);
2648 if (child->type == MIMETYPE_MULTIPART) {
2649 /* get the actual content */
2650 child = procmime_mimeinfo_next(child);
2654 if (child == firsttext) {
2655 child = procmime_mimeinfo_next(child);
2659 outfile = procmime_get_tmp_file_name(child);
2660 if (procmime_get_part(outfile, child) < 0)
2661 g_warning("Can't get the part of multipart message.");
2663 gchar *content_type;
2665 content_type = procmime_get_content_type_str(child->type, child->subtype);
2667 /* if we meet a pgp signature, we don't attach it, but
2668 * we force signing. */
2669 if (strcmp(content_type, "application/pgp-signature")) {
2670 partname = procmime_mimeinfo_get_parameter(child, "filename");
2671 if (partname == NULL)
2672 partname = procmime_mimeinfo_get_parameter(child, "name");
2673 if (partname == NULL)
2675 compose_attach_append(compose, outfile,
2676 partname, content_type);
2678 compose_force_signing(compose, compose->account);
2680 g_free(content_type);
2683 NEXT_PART_NOT_CHILD(child);
2685 procmime_mimeinfo_free_all(mimeinfo);
2688 #undef NEXT_PART_NOT_CHILD
2693 WAIT_FOR_INDENT_CHAR,
2694 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2697 /* return indent length, we allow:
2698 indent characters followed by indent characters or spaces/tabs,
2699 alphabets and numbers immediately followed by indent characters,
2700 and the repeating sequences of the above
2701 If quote ends with multiple spaces, only the first one is included. */
2702 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2703 const GtkTextIter *start, gint *len)
2705 GtkTextIter iter = *start;
2709 IndentState state = WAIT_FOR_INDENT_CHAR;
2712 gint alnum_count = 0;
2713 gint space_count = 0;
2716 if (prefs_common.quote_chars == NULL) {
2720 while (!gtk_text_iter_ends_line(&iter)) {
2721 wc = gtk_text_iter_get_char(&iter);
2722 if (g_unichar_iswide(wc))
2724 clen = g_unichar_to_utf8(wc, ch);
2728 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2729 is_space = g_unichar_isspace(wc);
2731 if (state == WAIT_FOR_INDENT_CHAR) {
2732 if (!is_indent && !g_unichar_isalnum(wc))
2735 quote_len += alnum_count + space_count + 1;
2736 alnum_count = space_count = 0;
2737 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2740 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2741 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
2745 else if (is_indent) {
2746 quote_len += alnum_count + space_count + 1;
2747 alnum_count = space_count = 0;
2750 state = WAIT_FOR_INDENT_CHAR;
2754 gtk_text_iter_forward_char(&iter);
2757 if (quote_len > 0 && space_count > 0)
2763 if (quote_len > 0) {
2765 gtk_text_iter_forward_chars(&iter, quote_len);
2766 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
2772 /* return TRUE if the line is itemized */
2773 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
2774 const GtkTextIter *start)
2776 GtkTextIter iter = *start;
2781 if (gtk_text_iter_ends_line(&iter))
2785 wc = gtk_text_iter_get_char(&iter);
2786 if (!g_unichar_isspace(wc))
2788 gtk_text_iter_forward_char(&iter);
2789 if (gtk_text_iter_ends_line(&iter))
2793 clen = g_unichar_to_utf8(wc, ch);
2797 if (!strchr("*-+", ch[0]))
2800 gtk_text_iter_forward_char(&iter);
2801 if (gtk_text_iter_ends_line(&iter))
2803 wc = gtk_text_iter_get_char(&iter);
2804 if (g_unichar_isspace(wc))
2810 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
2811 const GtkTextIter *start,
2812 GtkTextIter *break_pos,
2816 GtkTextIter iter = *start, line_end = *start;
2817 PangoLogAttr *attrs;
2824 gboolean can_break = FALSE;
2825 gboolean do_break = FALSE;
2826 gboolean was_white = FALSE;
2827 gboolean prev_dont_break = FALSE;
2829 gtk_text_iter_forward_to_line_end(&line_end);
2830 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
2831 len = g_utf8_strlen(str, -1);
2832 /* g_print("breaking line: %d: %s (len = %d)\n",
2833 gtk_text_iter_get_line(&iter), str, len); */
2834 attrs = g_new(PangoLogAttr, len + 1);
2836 pango_default_break(str, -1, NULL, attrs, len + 1);
2840 /* skip quote and leading spaces */
2841 for (i = 0; *p != '\0' && i < len; i++) {
2844 wc = g_utf8_get_char(p);
2845 if (i >= quote_len && !g_unichar_isspace(wc))
2847 if (g_unichar_iswide(wc))
2849 else if (*p == '\t')
2853 p = g_utf8_next_char(p);
2856 for (; *p != '\0' && i < len; i++) {
2857 PangoLogAttr *attr = attrs + i;
2861 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
2864 was_white = attr->is_white;
2866 /* don't wrap URI */
2867 if ((uri_len = get_uri_len(p)) > 0) {
2869 if (pos > 0 && col > max_col) {
2879 wc = g_utf8_get_char(p);
2880 if (g_unichar_iswide(wc)) {
2882 if (prev_dont_break && can_break && attr->is_line_break)
2884 } else if (*p == '\t')
2888 if (pos > 0 && col > max_col) {
2893 if (*p == '-' || *p == '/')
2894 prev_dont_break = TRUE;
2896 prev_dont_break = FALSE;
2898 p = g_utf8_next_char(p);
2902 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
2907 *break_pos = *start;
2908 gtk_text_iter_set_line_offset(break_pos, pos);
2913 static gboolean compose_join_next_line(Compose *compose,
2914 GtkTextBuffer *buffer,
2916 const gchar *quote_str)
2918 GtkTextIter iter_ = *iter, cur, prev, next, end;
2919 PangoLogAttr attrs[3];
2921 gchar *next_quote_str;
2924 gboolean keep_cursor = FALSE;
2926 if (!gtk_text_iter_forward_line(&iter_) ||
2927 gtk_text_iter_ends_line(&iter_))
2930 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
2932 if ((quote_str || next_quote_str) &&
2933 strcmp2(quote_str, next_quote_str) != 0) {
2934 g_free(next_quote_str);
2937 g_free(next_quote_str);
2940 if (quote_len > 0) {
2941 gtk_text_iter_forward_chars(&end, quote_len);
2942 if (gtk_text_iter_ends_line(&end))
2946 /* don't join itemized lines */
2947 if (compose_is_itemized(buffer, &end))
2950 /* don't join signature separator */
2951 if (compose_is_sig_separator(compose, buffer, &iter_))
2954 /* delete quote str */
2956 gtk_text_buffer_delete(buffer, &iter_, &end);
2958 /* delete linebreak and extra spaces */
2960 while (gtk_text_iter_backward_char(&cur)) {
2961 wc1 = gtk_text_iter_get_char(&cur);
2962 if (!g_unichar_isspace(wc1))
2967 while (!gtk_text_iter_ends_line(&cur)) {
2968 wc1 = gtk_text_iter_get_char(&cur);
2969 if (!g_unichar_isspace(wc1))
2971 gtk_text_iter_forward_char(&cur);
2974 if (!gtk_text_iter_equal(&prev, &next)) {
2977 mark = gtk_text_buffer_get_insert(buffer);
2978 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
2979 if (gtk_text_iter_equal(&prev, &cur))
2981 gtk_text_buffer_delete(buffer, &prev, &next);
2985 /* insert space if required */
2986 gtk_text_iter_backward_char(&prev);
2987 wc1 = gtk_text_iter_get_char(&prev);
2988 wc2 = gtk_text_iter_get_char(&next);
2989 gtk_text_iter_forward_char(&next);
2990 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
2991 pango_default_break(str, -1, NULL, attrs, 3);
2992 if (!attrs[1].is_line_break ||
2993 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
2994 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
2996 gtk_text_iter_backward_char(&iter_);
2997 gtk_text_buffer_place_cursor(buffer, &iter_);
3006 #define ADD_TXT_POS(bp_, ep_, pti_) \
3007 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3008 last = last->next; \
3009 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3010 last->next = NULL; \
3012 g_warning("alloc error scanning URIs\n"); \
3015 static void compose_wrap_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3017 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3018 GtkTextBuffer *buffer;
3019 GtkTextIter iter, break_pos, end_of_line;
3020 gchar *quote_str = NULL;
3022 gboolean wrap_quote = prefs_common.linewrap_quote;
3023 gboolean prev_autowrap = compose->autowrap;
3024 gint startq_offset = -1, noq_offset = -1;
3025 gint uri_start = -1, uri_stop = -1;
3026 gint nouri_start = -1, nouri_stop = -1;
3028 compose->autowrap = FALSE;
3030 buffer = gtk_text_view_get_buffer(text);
3032 undo_block(compose->undostruct);
3038 mark = gtk_text_buffer_get_insert(buffer);
3039 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3042 /* move to paragraph start */
3043 gtk_text_iter_set_line_offset(&iter, 0);
3044 if (gtk_text_iter_ends_line(&iter)) {
3045 while (gtk_text_iter_ends_line(&iter) &&
3046 gtk_text_iter_forward_line(&iter))
3049 while (gtk_text_iter_backward_line(&iter)) {
3050 if (gtk_text_iter_ends_line(&iter)) {
3051 gtk_text_iter_forward_line(&iter);
3057 /* go until paragraph end (empty line) */
3058 while (!gtk_text_iter_ends_line(&iter)) {
3059 gchar *scanpos = NULL;
3060 /* parse table - in order of priority */
3062 const gchar *needle; /* token */
3064 /* token search function */
3065 gchar *(*search) (const gchar *haystack,
3066 const gchar *needle);
3067 /* part parsing function */
3068 gboolean (*parse) (const gchar *start,
3069 const gchar *scanpos,
3072 /* part to URI function */
3073 gchar *(*build_uri) (const gchar *bp,
3077 static struct table parser[] = {
3078 {"http://", strcasestr, get_uri_part, make_uri_string},
3079 {"https://", strcasestr, get_uri_part, make_uri_string},
3080 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3081 {"www.", strcasestr, get_uri_part, make_http_string},
3082 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3083 {"@", strcasestr, get_email_part, make_email_string}
3085 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3086 gint last_index = PARSE_ELEMS;
3088 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3091 if (gtk_text_iter_has_tag(&iter, no_wrap_tag) && !force)
3094 uri_start = uri_stop = -1;
3095 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3099 if (startq_offset == -1) {
3100 startq_offset = gtk_text_iter_get_offset(&iter);
3104 debug_print("compose_wrap_paragraph(): quote_str = '%s'\n", quote_str);
3105 startq_offset = gtk_text_iter_get_offset(&iter);
3107 if (startq_offset == -1)
3108 noq_offset = gtk_text_iter_get_offset(&iter);
3111 if (prev_autowrap == FALSE && !force) {
3114 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3115 prefs_common.linewrap_len,
3117 GtkTextIter prev, next, cur;
3119 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3121 /* remove trailing spaces */
3123 gtk_text_iter_backward_char(&cur);
3125 while (!gtk_text_iter_starts_line(&cur)) {
3128 gtk_text_iter_backward_char(&cur);
3129 wc = gtk_text_iter_get_char(&cur);
3130 if (!g_unichar_isspace(wc))
3134 if (!gtk_text_iter_equal(&prev, &next)) {
3135 gtk_text_buffer_delete(buffer, &prev, &next);
3137 gtk_text_iter_forward_char(&break_pos);
3141 gtk_text_buffer_insert(buffer, &break_pos,
3145 compose_join_next_line(compose, buffer, &iter, quote_str);
3147 /* move iter to current line start */
3148 gtk_text_iter_set_line_offset(&iter, 0);
3151 /* move iter to next line start */
3157 while (!gtk_text_iter_ends_line(&end_of_line)) {
3158 gtk_text_iter_forward_char(&end_of_line);
3160 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3162 nouri_start = gtk_text_iter_get_offset(&iter);
3163 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3165 walk_pos = gtk_text_iter_get_offset(&iter);
3166 /* FIXME: this looks phony. scanning for anything in the parse table */
3167 for (n = 0; n < PARSE_ELEMS; n++) {
3170 tmp = parser[n].search(walk, parser[n].needle);
3172 if (scanpos == NULL || tmp < scanpos) {
3181 /* check if URI can be parsed */
3182 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,(const gchar **)&ep)
3183 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3187 strlen(parser[last_index].needle);
3190 uri_start = walk_pos + (bp - o_walk);
3191 uri_stop = walk_pos + (ep - o_walk);
3195 gtk_text_iter_forward_line(&iter);
3198 if (startq_offset != -1) {
3199 GtkTextIter startquote, endquote;
3200 gtk_text_buffer_get_iter_at_offset(
3201 buffer, &startquote, startq_offset);
3203 gtk_text_buffer_apply_tag_by_name(
3204 buffer, "quote", &startquote, &endquote);
3206 } else if (noq_offset != -1) {
3207 GtkTextIter startnoquote, endnoquote;
3208 gtk_text_buffer_get_iter_at_offset(
3209 buffer, &startnoquote, noq_offset);
3211 gtk_text_buffer_remove_tag_by_name(
3212 buffer, "quote", &startnoquote, &endnoquote);
3217 GtkTextIter nouri_start_iter, nouri_end_iter;
3218 gtk_text_buffer_get_iter_at_offset(
3219 buffer, &nouri_start_iter, nouri_start);
3220 gtk_text_buffer_get_iter_at_offset(
3221 buffer, &nouri_end_iter, nouri_stop);
3222 gtk_text_buffer_remove_tag_by_name(
3223 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3225 if (uri_start > 0 && uri_stop > 0) {
3226 GtkTextIter uri_start_iter, uri_end_iter;
3227 gtk_text_buffer_get_iter_at_offset(
3228 buffer, &uri_start_iter, uri_start);
3229 gtk_text_buffer_get_iter_at_offset(
3230 buffer, &uri_end_iter, uri_stop);
3231 gtk_text_buffer_apply_tag_by_name(
3232 buffer, "link", &uri_start_iter, &uri_end_iter);
3239 undo_unblock(compose->undostruct);
3240 compose->autowrap = prev_autowrap;
3243 static void compose_wrap_all(Compose *compose)
3245 compose_wrap_all_full(compose, FALSE);
3248 static void compose_wrap_all_full(Compose *compose, gboolean force)
3250 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3251 GtkTextBuffer *buffer;
3254 buffer = gtk_text_view_get_buffer(text);
3256 undo_block(compose->undostruct);
3258 gtk_text_buffer_get_start_iter(buffer, &iter);
3259 while (!gtk_text_iter_is_end(&iter))
3260 compose_wrap_paragraph(compose, &iter, force);
3262 undo_unblock(compose->undostruct);
3265 static void compose_set_title(Compose *compose)
3270 edited = compose->modified ? _(" [Edited]") : "";
3271 if (compose->account && compose->account->address)
3272 str = g_strdup_printf(_("%s - Compose message%s"),
3273 compose->account->address, edited);
3275 str = g_strdup_printf(_("Compose message%s"), edited);
3276 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3281 * compose_current_mail_account:
3283 * Find a current mail account (the currently selected account, or the
3284 * default account, if a news account is currently selected). If a
3285 * mail account cannot be found, display an error message.
3287 * Return value: Mail account, or NULL if not found.
3289 static PrefsAccount *
3290 compose_current_mail_account(void)
3294 if (cur_account && cur_account->protocol != A_NNTP)
3297 ac = account_get_default();
3298 if (!ac || ac->protocol == A_NNTP) {
3299 alertpanel_error(_("Account for sending mail is not specified.\n"
3300 "Please select a mail account before sending."));
3307 static void compose_select_account(Compose *compose, PrefsAccount *account,
3310 GtkItemFactory *ifactory;
3312 g_return_if_fail(account != NULL);
3314 compose->account = account;
3316 compose_set_title(compose);
3318 ifactory = gtk_item_factory_from_widget(compose->menubar);
3320 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3321 menu_set_active(ifactory, "/Options/Sign", TRUE);
3323 menu_set_active(ifactory, "/Options/Sign", FALSE);
3324 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3325 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3327 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3329 activate_privacy_system(compose, account);
3331 if (!init && compose->mode != COMPOSE_REDIRECT)
3332 compose_insert_sig(compose, TRUE);
3335 gboolean compose_check_for_valid_recipient(Compose *compose) {
3336 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3337 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3338 gboolean recipient_found = FALSE;
3342 /* free to and newsgroup list */
3343 slist_free_strings(compose->to_list);
3344 g_slist_free(compose->to_list);
3345 compose->to_list = NULL;
3347 slist_free_strings(compose->newsgroup_list);
3348 g_slist_free(compose->newsgroup_list);
3349 compose->newsgroup_list = NULL;
3351 /* search header entries for to and newsgroup entries */
3352 for (list = compose->header_list; list; list = list->next) {
3355 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3356 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3358 if (entry[0] != '\0') {
3359 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3360 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3361 compose->to_list = address_list_append(compose->to_list, entry);
3362 recipient_found = TRUE;
3365 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3366 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3367 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3368 recipient_found = TRUE;
3375 return recipient_found;
3378 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3382 if (compose_check_for_valid_recipient(compose) == FALSE) {
3383 alertpanel_error(_("Recipient is not specified."));
3387 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3388 if (*str == '\0' && check_subject == TRUE) {
3391 aval = alertpanel(_("Send"),
3392 _("Subject is empty. Send it anyway?"),
3393 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3394 if (aval != G_ALERTDEFAULT)
3401 gint compose_send(Compose *compose)
3408 compose_allow_user_actions (compose, FALSE);
3409 compose->sending = TRUE;
3411 if (compose_check_entries(compose, TRUE) == FALSE)
3414 val = compose_queue(compose, &msgnum, &folder);
3418 alertpanel_error(_("Could not queue message for sending:\n\n"
3419 "Signature failed."));
3420 } else if (val == -2) {
3421 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3423 alertpanel_error(_("Could not queue message for sending."));
3429 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3430 compose->sending = FALSE;
3431 compose_close(compose);
3432 /* No more compose access in the normal codepath
3433 * after this point! */
3438 alertpanel_error(_("The message was queued but could not be "
3439 "sent.\nUse \"Send queued messages\" from "
3440 "the main window to retry."));
3441 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3442 compose->sending = FALSE;
3443 compose_allow_user_actions (compose, TRUE);
3448 msgpath = folder_item_fetch_msg(folder, msgnum);
3449 val = procmsg_send_message_queue(msgpath);
3452 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3453 compose->sending = FALSE;
3454 compose_allow_user_actions (compose, TRUE);
3456 folder_item_remove_msg(folder, msgnum);
3457 folder_item_scan(folder);
3462 folder_item_remove_msg(folder, msgnum);
3463 folder_item_scan(folder);
3464 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3465 compose_close(compose);
3467 alertpanel_error(_("The message was queued but could not be "
3468 "sent.\nUse \"Send queued messages\" from "
3469 "the main window to retry."));
3470 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3471 compose_allow_user_actions (compose, TRUE);
3472 compose->sending = FALSE;
3480 compose_allow_user_actions (compose, TRUE);
3481 compose->sending = FALSE;
3486 static gboolean compose_use_attach(Compose *compose)
3488 GtkTreeModel *model = gtk_tree_view_get_model
3489 (GTK_TREE_VIEW(compose->attach_clist));
3490 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3493 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3496 gchar buf[BUFFSIZE];
3498 gboolean first_to_address;
3499 gboolean first_cc_address;
3501 ComposeHeaderEntry *headerentry;
3502 const gchar *headerentryname;
3506 debug_print("Writing redirect header\n");
3508 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3509 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3511 first_to_address = TRUE;
3512 for (list = compose->header_list; list; list = list->next) {
3513 headerentry = ((ComposeHeaderEntry *)list->data);
3514 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3516 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3517 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3518 Xstrdup_a(str, entstr, return -1);
3520 if (str[0] != '\0') {
3521 compose_convert_header
3522 (compose, buf, sizeof(buf), str,
3523 strlen("Resent-To") + 2, TRUE);
3525 if (first_to_address) {
3526 fprintf(fp, "Resent-To: ");
3527 first_to_address = FALSE;
3531 fprintf(fp, "%s", buf);
3535 if (!first_to_address) {
3539 first_cc_address = TRUE;
3540 for (list = compose->header_list; list; list = list->next) {
3541 headerentry = ((ComposeHeaderEntry *)list->data);
3542 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3544 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3545 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3546 Xstrdup_a(str, strg, return -1);
3548 if (str[0] != '\0') {
3549 compose_convert_header
3550 (compose, buf, sizeof(buf), str,
3551 strlen("Resent-Cc") + 2, TRUE);
3553 if (first_cc_address) {
3554 fprintf(fp, "Resent-Cc: ");
3555 first_cc_address = FALSE;
3559 fprintf(fp, "%s", buf);
3563 if (!first_cc_address) {
3570 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3572 gchar buf[BUFFSIZE];
3574 const gchar *entstr;
3575 /* struct utsname utsbuf; */
3577 g_return_val_if_fail(fp != NULL, -1);
3578 g_return_val_if_fail(compose->account != NULL, -1);
3579 g_return_val_if_fail(compose->account->address != NULL, -1);
3582 get_rfc822_date(buf, sizeof(buf));
3583 fprintf(fp, "Resent-Date: %s\n", buf);
3586 if (compose->account->name && *compose->account->name) {
3587 compose_convert_header
3588 (compose, buf, sizeof(buf), compose->account->name,
3589 strlen("From: "), TRUE);
3590 fprintf(fp, "Resent-From: %s <%s>\n",
3591 buf, compose->account->address);
3593 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3596 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3597 if (*entstr != '\0') {
3598 Xstrdup_a(str, entstr, return -1);
3601 compose_convert_header(compose, buf, sizeof(buf), str,
3602 strlen("Subject: "), FALSE);
3603 fprintf(fp, "Subject: %s\n", buf);
3607 /* Resent-Message-ID */
3608 if (compose->account->gen_msgid) {
3609 generate_msgid(buf, sizeof(buf));
3610 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3611 compose->msgid = g_strdup(buf);
3614 compose_redirect_write_headers_from_headerlist(compose, fp);
3616 /* separator between header and body */
3622 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3626 gchar buf[BUFFSIZE];
3628 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
3629 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3633 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3634 /* should filter returnpath, delivered-to */
3635 if (g_ascii_strncasecmp(buf, "Return-Path:",
3636 strlen("Return-Path:")) == 0 ||
3637 g_ascii_strncasecmp(buf, "Delivered-To:",
3638 strlen("Delivered-To:")) == 0 ||
3639 g_ascii_strncasecmp(buf, "Received:",
3640 strlen("Received:")) == 0 ||
3641 g_ascii_strncasecmp(buf, "Subject:",
3642 strlen("Subject:")) == 0 ||
3643 g_ascii_strncasecmp(buf, "X-UIDL:",
3644 strlen("X-UIDL:")) == 0)
3647 if (fputs(buf, fdest) == -1)
3650 if (!prefs_common.redirect_keep_from) {
3651 if (g_ascii_strncasecmp(buf, "From:",
3652 strlen("From:")) == 0) {
3653 fputs(" (by way of ", fdest);
3654 if (compose->account->name
3655 && *compose->account->name) {
3656 compose_convert_header
3657 (compose, buf, sizeof(buf),
3658 compose->account->name,
3661 fprintf(fdest, "%s <%s>",
3663 compose->account->address);
3665 fprintf(fdest, "%s",
3666 compose->account->address);
3671 if (fputs("\n", fdest) == -1)
3675 compose_redirect_write_headers(compose, fdest);
3677 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3678 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
3691 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
3693 GtkTextBuffer *buffer;
3694 GtkTextIter start, end;
3697 const gchar *out_codeset;
3698 EncodingType encoding;
3699 MimeInfo *mimemsg, *mimetext;
3702 /* create message MimeInfo */
3703 mimemsg = procmime_mimeinfo_new();
3704 mimemsg->type = MIMETYPE_MESSAGE;
3705 mimemsg->subtype = g_strdup("rfc822");
3706 mimemsg->content = MIMECONTENT_MEM;
3707 mimemsg->data.mem = compose_get_header(compose);
3709 /* Create text part MimeInfo */
3710 /* get all composed text */
3711 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
3712 gtk_text_buffer_get_start_iter(buffer, &start);
3713 gtk_text_buffer_get_end_iter(buffer, &end);
3714 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
3715 if (is_ascii_str(chars)) {
3718 out_codeset = CS_US_ASCII;
3719 encoding = ENC_7BIT;
3721 const gchar *src_codeset;
3723 out_codeset = conv_get_charset_str(compose->out_encoding);
3725 out_codeset = conv_get_outgoing_charset_str();
3727 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
3728 out_codeset = CS_ISO_8859_1;
3730 if (prefs_common.encoding_method == CTE_BASE64)
3731 encoding = ENC_BASE64;
3732 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3733 encoding = ENC_QUOTED_PRINTABLE;
3734 else if (prefs_common.encoding_method == CTE_8BIT)
3735 encoding = ENC_8BIT;
3737 encoding = procmime_get_encoding_for_charset(out_codeset);
3739 src_codeset = CS_INTERNAL;
3740 /* if current encoding is US-ASCII, set it the same as
3741 outgoing one to prevent code conversion failure */
3742 if (!g_ascii_strcasecmp(src_codeset, CS_US_ASCII))
3743 src_codeset = out_codeset;
3745 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3746 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3748 if (action == COMPOSE_WRITE_FOR_SEND) {
3749 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3755 msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
3757 "Send it anyway?"), src_codeset, out_codeset);
3758 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_YES, GTK_STOCK_NO, NULL, FALSE,
3759 NULL, ALERT_ERROR, G_ALERTALTERNATE);
3762 if (aval != G_ALERTDEFAULT) {
3767 out_codeset = src_codeset;
3773 out_codeset = src_codeset;
3779 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
3780 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
3781 strstr(buf, "\nFrom ") != NULL) {
3782 encoding = ENC_QUOTED_PRINTABLE;
3786 mimetext = procmime_mimeinfo_new();
3787 mimetext->content = MIMECONTENT_MEM;
3788 mimetext->data.mem = buf;
3789 mimetext->type = MIMETYPE_TEXT;
3790 mimetext->subtype = g_strdup("plain");
3791 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
3792 g_strdup(out_codeset));
3793 /* protect trailing spaces when signing message */
3794 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
3795 privacy_system_can_sign(compose->privacy_system)) {
3796 if (encoding == ENC_7BIT)
3797 encoding = ENC_QUOTED_PRINTABLE;
3798 else if (encoding == ENC_8BIT)
3799 encoding = ENC_BASE64;
3802 /* check for line length limit */
3803 if (encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
3804 check_line_length(buf, 1000, &line) < 0) {
3808 msg = g_strdup_printf
3809 (_("Line %d exceeds the line length limit (998 bytes).\n"
3810 "The contents of the message might be broken on the way to the delivery.\n"
3812 "Send it anyway?"), line + 1);
3813 aval = alertpanel(_("Warning"), msg, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
3814 if (aval != G_ALERTDEFAULT) {
3822 if (encoding != ENC_UNKNOWN)
3823 procmime_encode_content(mimetext, encoding);
3825 /* append attachment parts */
3826 if (compose_use_attach(compose)) {
3827 MimeInfo *mimempart;
3829 mimempart = procmime_mimeinfo_new();
3830 mimempart->content = MIMECONTENT_EMPTY;
3831 mimempart->type = MIMETYPE_MULTIPART;
3832 mimempart->subtype = g_strdup("mixed");
3833 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
3834 generate_mime_boundary(NULL));
3836 mimetext->disposition = DISPOSITIONTYPE_INLINE;
3838 g_node_append(mimempart->node, mimetext->node);
3839 g_node_append(mimemsg->node, mimempart->node);
3841 compose_add_attachments(compose, mimempart);
3843 g_node_append(mimemsg->node, mimetext->node);
3845 /* sign message if sending */
3846 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
3847 privacy_system_can_sign(compose->privacy_system))
3848 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
3851 procmime_write_mimeinfo(mimemsg, fp);
3853 procmime_mimeinfo_free_all(mimemsg);
3858 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3860 GtkTextBuffer *buffer;
3861 GtkTextIter start, end;
3866 if ((fp = g_fopen(file, "wb")) == NULL) {
3867 FILE_OP_ERROR(file, "fopen");
3871 /* chmod for security */
3872 if (change_file_mode_rw(fp, file) < 0) {
3873 FILE_OP_ERROR(file, "chmod");
3874 g_warning("can't change file mode\n");
3877 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
3878 gtk_text_buffer_get_start_iter(buffer, &start);
3879 gtk_text_buffer_get_end_iter(buffer, &end);
3880 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
3882 chars = conv_codeset_strdup
3883 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
3886 if (!chars) return -1;
3889 len = strlen(chars);
3890 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3891 FILE_OP_ERROR(file, "fwrite");
3900 if (fclose(fp) == EOF) {
3901 FILE_OP_ERROR(file, "fclose");
3908 static gint compose_remove_reedit_target(Compose *compose)
3911 MsgInfo *msginfo = compose->targetinfo;
3913 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3914 if (!msginfo) return -1;
3916 item = msginfo->folder;
3917 g_return_val_if_fail(item != NULL, -1);
3919 if (procmsg_msg_exist(msginfo) &&
3920 (folder_has_parent_of_type(item, F_QUEUE) ||
3921 folder_has_parent_of_type(item, F_DRAFT)
3922 || msginfo == compose->autosaved_draft)) {
3923 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3924 g_warning("can't remove the old message\n");
3932 void compose_remove_draft(Compose *compose)
3935 MsgInfo *msginfo = compose->targetinfo;
3936 drafts = account_get_special_folder(compose->account, F_DRAFT);
3938 if (procmsg_msg_exist(msginfo)) {
3939 folder_item_remove_msg(drafts, msginfo->msgnum);
3944 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3946 return compose_queue_sub (compose, msgnum, item, FALSE);
3948 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3955 static gboolean lock = FALSE;
3956 PrefsAccount *mailac = NULL, *newsac = NULL;
3958 debug_print("queueing message...\n");
3959 g_return_val_if_fail(compose->account != NULL, -1);
3963 if (compose_check_entries(compose, check_subject) == FALSE) {
3968 if (!compose->to_list && !compose->newsgroup_list) {
3969 g_warning("can't get recipient list.");
3974 if (compose->to_list) {
3975 if (compose->account->protocol != A_NNTP)
3976 mailac = compose->account;
3977 else if (cur_account && cur_account->protocol != A_NNTP)
3978 mailac = cur_account;
3979 else if (!(mailac = compose_current_mail_account())) {
3981 alertpanel_error(_("No account for sending mails available!"));
3986 if (compose->newsgroup_list) {
3987 if (compose->account->protocol == A_NNTP)
3988 newsac = compose->account;
3989 else if (!newsac->protocol != A_NNTP) {
3991 alertpanel_error(_("No account for posting news available!"));
3996 if (prefs_common.linewrap_at_send)
3997 compose_wrap_all(compose);
3999 /* write queue header */
4000 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4001 G_DIR_SEPARATOR, compose);
4002 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4003 FILE_OP_ERROR(tmp, "fopen");
4008 if (change_file_mode_rw(fp, tmp) < 0) {
4009 FILE_OP_ERROR(tmp, "chmod");
4010 g_warning("can't change file mode\n");
4013 /* queueing variables */
4014 fprintf(fp, "AF:\n");
4015 fprintf(fp, "NF:0\n");
4016 fprintf(fp, "PS:10\n");
4017 fprintf(fp, "SRH:1\n");
4018 fprintf(fp, "SFN:\n");
4019 fprintf(fp, "DSR:\n");
4021 fprintf(fp, "MID:<%s>\n", compose->msgid);
4023 fprintf(fp, "MID:\n");
4024 fprintf(fp, "CFG:\n");
4025 fprintf(fp, "PT:0\n");
4026 fprintf(fp, "S:%s\n", compose->account->address);
4027 fprintf(fp, "RQ:\n");
4029 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4031 fprintf(fp, "SSV:\n");
4033 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4035 fprintf(fp, "NSV:\n");
4036 fprintf(fp, "SSH:\n");
4037 /* write recepient list */
4038 if (compose->to_list) {
4039 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4040 for (cur = compose->to_list->next; cur != NULL;
4042 fprintf(fp, ",<%s>", (gchar *)cur->data);
4045 /* write newsgroup list */
4046 if (compose->newsgroup_list) {
4048 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4049 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4050 fprintf(fp, ",%s", (gchar *)cur->data);
4053 /* Sylpheed account IDs */
4055 fprintf(fp, "MAID:%d\n", mailac->account_id);
4057 fprintf(fp, "NAID:%d\n", newsac->account_id);
4059 if (compose->privacy_system != NULL) {
4060 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4061 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4062 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4063 if (compose->use_encryption) {
4066 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4067 if (encdata != NULL)
4068 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4074 /* Save copy folder */
4075 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4076 gchar *savefolderid;
4078 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4079 fprintf(fp, "SCF:%s\n", savefolderid);
4080 g_free(savefolderid);
4082 /* Message-ID of message replying to */
4083 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4086 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4087 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4090 /* Message-ID of message forwarding to */
4091 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4094 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4095 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4100 if (compose->redirect_filename != NULL) {
4101 if (compose_redirect_write_to_file(compose, fp) < 0) {
4110 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4115 return result - 1; /* -2 for a generic error, -3 for signing error */
4119 if (fclose(fp) == EOF) {
4120 FILE_OP_ERROR(tmp, "fclose");
4126 queue = account_get_special_folder(compose->account, F_QUEUE);
4128 g_warning("can't find queue folder\n");
4133 folder_item_scan(queue);
4134 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
4135 g_warning("can't queue the message\n");
4143 if (compose->mode == COMPOSE_REEDIT) {
4144 compose_remove_reedit_target(compose);
4147 if ((msgnum != NULL) && (item != NULL)) {
4155 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4158 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4160 struct stat statbuf;
4161 gchar *type, *subtype;
4162 GtkTreeModel *model;
4165 model = gtk_tree_view_get_model(tree_view);
4167 if (!gtk_tree_model_get_iter_first(model, &iter))
4170 gtk_tree_model_get(model, &iter,
4174 mimepart = procmime_mimeinfo_new();
4175 mimepart->content = MIMECONTENT_FILE;
4176 mimepart->data.filename = g_strdup(ainfo->file);
4177 mimepart->offset = 0;
4179 stat(ainfo->file, &statbuf);
4180 mimepart->length = statbuf.st_size;
4182 type = g_strdup(ainfo->content_type);
4184 if (!strchr(type, '/')) {
4186 type = g_strdup("application/octet-stream");
4189 subtype = strchr(type, '/') + 1;
4190 *(subtype - 1) = '\0';
4191 mimepart->type = procmime_get_media_type(type);
4192 mimepart->subtype = g_strdup(subtype);
4195 if (mimepart->type == MIMETYPE_MESSAGE &&
4196 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4197 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4199 g_hash_table_insert(mimepart->typeparameters,
4200 g_strdup("name"), g_strdup(ainfo->name));
4201 g_hash_table_insert(mimepart->dispositionparameters,
4202 g_strdup("filename"), g_strdup(ainfo->name));
4203 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4206 if (compose->use_signing) {
4207 if (ainfo->encoding == ENC_7BIT)
4208 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4209 else if (ainfo->encoding == ENC_8BIT)
4210 ainfo->encoding = ENC_BASE64;
4213 procmime_encode_content(mimepart, ainfo->encoding);
4215 g_node_append(parent->node, mimepart->node);
4216 } while (gtk_tree_model_iter_next(model, &iter));
4219 #define QUOTE_IF_REQUIRED(out, str) \
4221 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4225 len = strlen(str) + 3; \
4226 if ((__tmp = alloca(len)) == NULL) { \
4227 g_warning("can't allocate memory\n"); \
4228 g_string_free(header, TRUE); \
4231 g_snprintf(__tmp, len, "\"%s\"", str); \
4236 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4237 g_warning("can't allocate memory\n"); \
4238 g_string_free(header, TRUE); \
4241 strcpy(__tmp, str); \
4247 #define IS_IN_CUSTOM_HEADER(header) \
4248 (compose->account->add_customhdr && \
4249 custom_header_find(compose->account->customhdr_list, header) != NULL)
4251 static void compose_add_headerfield_from_headerlist(Compose *compose,
4253 const gchar *fieldname,
4254 const gchar *seperator)
4256 gchar *str, *fieldname_w_colon, *trans_fieldname;
4257 gboolean add_field = FALSE;
4259 ComposeHeaderEntry *headerentry;
4260 const gchar * headerentryname;
4263 if (IS_IN_CUSTOM_HEADER(fieldname))
4266 debug_print("Adding %s-fields\n", fieldname);
4268 fieldstr = g_string_sized_new(64);
4270 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4271 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4273 for (list = compose->header_list; list; list = list->next) {
4274 headerentry = ((ComposeHeaderEntry *)list->data);
4275 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4277 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4278 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4280 if (str[0] != '\0') {
4282 g_string_append(fieldstr, seperator);
4283 g_string_append(fieldstr, str);
4292 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4293 compose_convert_header
4294 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4295 strlen(fieldname) + 2, TRUE);
4296 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4300 g_free(fieldname_w_colon);
4301 g_string_free(fieldstr, TRUE);
4306 static gchar *compose_get_header(Compose *compose)
4308 gchar buf[BUFFSIZE];
4309 const gchar *entry_str;
4313 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4316 g_return_val_if_fail(compose->account != NULL, NULL);
4317 g_return_val_if_fail(compose->account->address != NULL, NULL);
4319 header = g_string_sized_new(64);
4322 if (compose->account->add_date) {
4323 get_rfc822_date(buf, sizeof(buf));
4324 g_string_append_printf(header, "Date: %s\n", buf);
4328 if (compose->account->name && *compose->account->name) {
4329 compose_convert_header
4330 (compose, buf, sizeof(buf), compose->account->name,
4331 strlen("From: "), TRUE);
4332 QUOTE_IF_REQUIRED(name, buf);
4333 g_string_append_printf(header, "From: %s <%s>\n",
4334 name, compose->account->address);
4336 g_string_append_printf(header, "From: %s\n", compose->account->address);
4339 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4342 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4345 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4348 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4351 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4352 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4355 compose_convert_header(compose, buf, sizeof(buf), str,
4356 strlen("Subject: "), FALSE);
4357 g_string_append_printf(header, "Subject: %s\n", buf);
4363 if (compose->account->gen_msgid) {
4364 generate_msgid(buf, sizeof(buf));
4365 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4366 compose->msgid = g_strdup(buf);
4369 if (compose->remove_references == FALSE) {
4371 if (compose->inreplyto && compose->to_list)
4372 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4375 if (compose->references)
4376 g_string_append_printf(header, "References: %s\n", compose->references);
4380 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4383 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4386 if (compose->account->organization &&
4387 strlen(compose->account->organization) &&
4388 !IS_IN_CUSTOM_HEADER("Organization")) {
4389 compose_convert_header(compose, buf, sizeof(buf),
4390 compose->account->organization,
4391 strlen("Organization: "), FALSE);
4392 g_string_append_printf(header, "Organization: %s\n", buf);
4395 /* Program version and system info */
4396 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4397 !compose->newsgroup_list) {
4398 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4400 gtk_major_version, gtk_minor_version, gtk_micro_version,
4403 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4404 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4406 gtk_major_version, gtk_minor_version, gtk_micro_version,
4410 /* custom headers */
4411 if (compose->account->add_customhdr) {
4414 for (cur = compose->account->customhdr_list; cur != NULL;
4416 CustomHeader *chdr = (CustomHeader *)cur->data;
4418 if (custom_header_is_allowed(chdr->name)) {
4419 compose_convert_header
4420 (compose, buf, sizeof(buf),
4421 chdr->value ? chdr->value : "",
4422 strlen(chdr->name) + 2, FALSE);
4423 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4429 switch (compose->priority) {
4430 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4431 "X-Priority: 1 (Highest)\n");
4433 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4434 "X-Priority: 2 (High)\n");
4436 case PRIORITY_NORMAL: break;
4437 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4438 "X-Priority: 4 (Low)\n");
4440 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4441 "X-Priority: 5 (Lowest)\n");
4443 default: debug_print("compose: priority unknown : %d\n",
4447 /* Request Return Receipt */
4448 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4449 if (compose->return_receipt) {
4450 if (compose->account->name
4451 && *compose->account->name) {
4452 compose_convert_header(compose, buf, sizeof(buf),
4453 compose->account->name,
4454 strlen("Disposition-Notification-To: "),
4456 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4458 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4462 /* get special headers */
4463 for (list = compose->header_list; list; list = list->next) {
4464 ComposeHeaderEntry *headerentry;
4467 gchar *headername_wcolon;
4468 gchar *headername_trans;
4471 gboolean standard_header = FALSE;
4473 headerentry = ((ComposeHeaderEntry *)list->data);
4475 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4476 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4481 if (!strstr(tmp, ":")) {
4482 headername_wcolon = g_strconcat(tmp, ":", NULL);
4483 headername = g_strdup(tmp);
4485 headername_wcolon = g_strdup(tmp);
4486 headername = g_strdup(strtok(tmp, ":"));
4490 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4491 Xstrdup_a(headervalue, entry_str, return NULL);
4492 subst_char(headervalue, '\r', ' ');
4493 subst_char(headervalue, '\n', ' ');
4494 string = std_headers;
4495 while (*string != NULL) {
4496 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4497 if (!strcmp(headername_trans,headername_wcolon))
4498 standard_header = TRUE;
4501 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4502 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
4505 g_free(headername_wcolon);
4509 g_string_free(header, FALSE);
4514 #undef IS_IN_CUSTOM_HEADER
4516 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
4517 gint header_len, gboolean addr_field)
4519 gchar *tmpstr = NULL;
4521 g_return_if_fail(src != NULL);
4522 g_return_if_fail(dest != NULL);
4524 if (len < 1) return;
4526 tmpstr = g_strdup(src);
4528 subst_char(tmpstr, '\n', ' ');
4529 subst_char(tmpstr, '\r', ' ');
4532 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4533 conv_get_charset_str(compose->out_encoding));
4537 static void compose_create_header_entry(Compose *compose)
4539 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4543 GList *combo_list = NULL;
4545 const gchar *header = NULL;
4546 ComposeHeaderEntry *headerentry;
4547 gboolean standard_header = FALSE;
4549 headerentry = g_new0(ComposeHeaderEntry, 1);
4552 combo = gtk_combo_new();
4554 while(*string != NULL) {
4555 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4558 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4559 g_list_free(combo_list);
4560 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4561 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4562 G_CALLBACK(compose_grab_focus_cb), compose);
4563 gtk_widget_show(combo);
4564 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4565 if (compose->header_last) {
4566 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4568 while (*string != NULL) {
4569 if (!strcmp(*string, last_header_entry))
4570 standard_header = TRUE;
4573 if (standard_header)
4574 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4576 if (!compose->header_last || !standard_header) {
4577 switch(compose->account->protocol) {
4579 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4582 header = prefs_common.trans_hdr ? _("To:") : "To:";
4587 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4589 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4590 G_CALLBACK(compose_grab_focus_cb), compose);
4593 entry = gtk_entry_new();
4594 gtk_widget_show(entry);
4595 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);
4597 g_signal_connect(G_OBJECT(entry), "key-press-event",
4598 G_CALLBACK(compose_headerentry_key_press_event_cb),
4600 g_signal_connect(G_OBJECT(entry), "changed",
4601 G_CALLBACK(compose_headerentry_changed_cb),
4603 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
4604 G_CALLBACK(compose_grab_focus_cb), compose);
4607 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
4608 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
4609 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4610 g_signal_connect(G_OBJECT(entry), "drag_data_received",
4611 G_CALLBACK(compose_header_drag_received_cb),
4613 g_signal_connect(G_OBJECT(entry), "drag-drop",
4614 G_CALLBACK(compose_drag_drop),
4617 address_completion_register_entry(GTK_ENTRY(entry));
4619 headerentry->compose = compose;
4620 headerentry->combo = combo;
4621 headerentry->entry = entry;
4622 headerentry->headernum = compose->header_nextrow;
4624 compose->header_nextrow++;
4625 compose->header_last = headerentry;
4628 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4630 ComposeHeaderEntry *last_header;
4632 last_header = compose->header_last;
4634 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4635 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4638 static GtkWidget *compose_create_header(Compose *compose)
4642 GtkWidget *from_optmenu_hbox;
4643 GtkWidget *header_scrolledwin;
4644 GtkWidget *header_table;
4648 /* header labels and entries */
4649 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4650 gtk_widget_show(header_scrolledwin);
4651 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4653 header_table = gtk_table_new(2, 2, FALSE);
4654 gtk_widget_show(header_table);
4655 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4656 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4657 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4660 /* option menu for selecting accounts */
4661 hbox = gtk_hbox_new(FALSE, 0);
4662 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4663 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4664 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4666 from_optmenu_hbox = compose_account_option_menu_create(compose);
4667 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4668 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4671 compose->header_table = header_table;
4672 compose->header_list = NULL;
4673 compose->header_nextrow = count;
4675 compose_create_header_entry(compose);
4677 compose->table = NULL;
4679 return header_scrolledwin ;
4682 GtkWidget *compose_create_attach(Compose *compose)
4684 GtkWidget *attach_scrwin;
4685 GtkWidget *attach_clist;
4687 GtkListStore *store;
4688 GtkCellRenderer *renderer;
4689 GtkTreeViewColumn *column;
4690 GtkTreeSelection *selection;
4692 /* attachment list */
4693 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4694 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4695 GTK_POLICY_AUTOMATIC,
4696 GTK_POLICY_AUTOMATIC);
4697 gtk_widget_set_size_request(attach_scrwin, -1, 80);
4699 store = gtk_list_store_new(N_ATTACH_COLS,
4704 G_TYPE_AUTO_POINTER,
4706 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
4707 (GTK_TREE_MODEL(store)));
4708 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4709 g_object_unref(store);
4711 renderer = gtk_cell_renderer_text_new();
4712 column = gtk_tree_view_column_new_with_attributes
4713 (_("Mime type"), renderer, "text",
4714 COL_MIMETYPE, NULL);
4715 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
4717 renderer = gtk_cell_renderer_text_new();
4718 column = gtk_tree_view_column_new_with_attributes
4719 (_("Size"), renderer, "text",
4721 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
4723 renderer = gtk_cell_renderer_text_new();
4724 column = gtk_tree_view_column_new_with_attributes
4725 (_("Name"), renderer, "text",
4727 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
4729 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
4730 prefs_common.enable_rules_hint);
4731 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
4732 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
4734 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
4735 G_CALLBACK(attach_selected), compose);
4736 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
4737 G_CALLBACK(attach_button_pressed), compose);
4738 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
4739 G_CALLBACK(attach_key_pressed), compose);
4742 gtk_drag_dest_set(attach_clist,
4743 GTK_DEST_DEFAULT_ALL, compose_mime_types,
4744 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
4745 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4746 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
4747 G_CALLBACK(compose_attach_drag_received_cb),
4749 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
4750 G_CALLBACK(compose_drag_drop),
4753 compose->attach_scrwin = attach_scrwin;
4754 compose->attach_clist = attach_clist;
4756 return attach_scrwin;
4759 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4760 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4762 static GtkWidget *compose_create_others(Compose *compose)
4765 GtkWidget *savemsg_checkbtn;
4766 GtkWidget *savemsg_entry;
4767 GtkWidget *savemsg_select;
4770 gchar *folderidentifier;
4772 /* Table for settings */
4773 table = gtk_table_new(3, 1, FALSE);
4774 gtk_widget_show(table);
4775 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4778 /* Save Message to folder */
4779 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4780 gtk_widget_show(savemsg_checkbtn);
4781 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4782 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4783 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4785 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
4786 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
4788 savemsg_entry = gtk_entry_new();
4789 gtk_widget_show(savemsg_entry);
4790 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4791 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4792 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
4793 G_CALLBACK(compose_grab_focus_cb), compose);
4794 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4795 folderidentifier = folder_item_get_identifier(account_get_special_folder
4796 (compose->account, F_OUTBOX));
4797 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4798 g_free(folderidentifier);
4801 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4802 gtk_widget_show(savemsg_select);
4803 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4804 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
4805 G_CALLBACK(compose_savemsg_select_cb),
4810 compose->savemsg_checkbtn = savemsg_checkbtn;
4811 compose->savemsg_entry = savemsg_entry;
4816 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4818 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4819 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4822 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4827 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4830 path = folder_item_get_identifier(dest);
4832 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4836 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4842 GtkWidget *handlebox;
4844 GtkWidget *notebook;
4849 GtkWidget *subject_hbox;
4850 GtkWidget *subject_frame;
4851 GtkWidget *subject_entry;
4855 GtkWidget *edit_vbox;
4856 GtkWidget *ruler_hbox;
4858 GtkWidget *scrolledwin;
4860 GtkTextBuffer *buffer;
4861 GtkClipboard *clipboard;
4863 UndoMain *undostruct;
4865 gchar *titles[N_ATTACH_COLS];
4866 guint n_menu_entries;
4869 gboolean success[1];
4870 GtkWidget *popupmenu;
4871 GtkItemFactory *popupfactory;
4872 GtkItemFactory *ifactory;
4873 GtkWidget *tmpl_menu;
4875 GtkWidget *menuitem;
4878 GtkAspell * gtkaspell = NULL;
4881 static GdkGeometry geometry;
4883 g_return_val_if_fail(account != NULL, NULL);
4885 debug_print("Creating compose window...\n");
4886 compose = g_new0(Compose, 1);
4888 titles[COL_MIMETYPE] = _("MIME type");
4889 titles[COL_SIZE] = _("Size");
4890 titles[COL_NAME] = _("Name");
4892 compose->account = account;
4894 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4895 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
4896 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
4898 if (!geometry.max_width) {
4899 geometry.max_width = gdk_screen_width();
4900 geometry.max_height = gdk_screen_height();
4902 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4903 &geometry, GDK_HINT_MAX_SIZE);
4904 if (!geometry.min_width) {
4905 geometry.min_width = 600;
4906 geometry.min_height = 480;
4908 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4909 &geometry, GDK_HINT_MIN_SIZE);
4910 gtk_widget_set_uposition(window, prefs_common.compose_x,
4911 prefs_common.compose_y);
4913 g_signal_connect(G_OBJECT(window), "delete_event",
4914 G_CALLBACK(compose_delete_cb), compose);
4915 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4916 gtk_widget_realize(window);
4918 gtkut_widget_set_composer_icon(window);
4920 vbox = gtk_vbox_new(FALSE, 0);
4921 gtk_container_add(GTK_CONTAINER(window), vbox);
4923 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4924 menubar = menubar_create(window, compose_entries,
4925 n_menu_entries, "<Compose>", compose);
4926 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4928 if (prefs_common.toolbar_detachable) {
4929 handlebox = gtk_handle_box_new();
4931 handlebox = gtk_hbox_new(FALSE, 0);
4933 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4935 gtk_widget_realize(handlebox);
4936 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
4939 vbox2 = gtk_vbox_new(FALSE, 2);
4940 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4941 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4944 notebook = gtk_notebook_new();
4945 gtk_widget_set_size_request(notebook, -1, 130);
4946 gtk_widget_show(notebook);
4948 /* header labels and entries */
4949 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4950 /* attachment list */
4951 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4953 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4956 subject_hbox = gtk_hbox_new(FALSE, 0);
4957 gtk_widget_show(subject_hbox);
4959 subject_frame = gtk_frame_new(NULL);
4960 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4961 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4962 gtk_widget_show(subject_frame);
4964 subject = gtk_hbox_new(FALSE, 0);
4965 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4966 gtk_widget_show(subject);
4968 label = gtk_label_new(_("Subject:"));
4969 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4970 gtk_widget_show(label);
4972 subject_entry = gtk_entry_new();
4973 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4974 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
4975 G_CALLBACK(compose_grab_focus_cb), compose);
4976 gtk_widget_show(subject_entry);
4977 compose->subject_entry = subject_entry;
4978 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4980 edit_vbox = gtk_vbox_new(FALSE, 0);
4982 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4985 ruler_hbox = gtk_hbox_new(FALSE, 0);
4986 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4988 ruler = gtk_shruler_new();
4989 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4990 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4994 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4995 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4996 GTK_POLICY_AUTOMATIC,
4997 GTK_POLICY_AUTOMATIC);
4998 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5000 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5001 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5003 text = gtk_text_view_new();
5004 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5005 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5006 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5007 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5008 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5010 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5012 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5013 G_CALLBACK(compose_edit_size_alloc),
5015 g_signal_connect(G_OBJECT(buffer), "changed",
5016 G_CALLBACK(compose_changed_cb), compose);
5017 g_signal_connect(G_OBJECT(text), "grab_focus",
5018 G_CALLBACK(compose_grab_focus_cb), compose);
5019 g_signal_connect(G_OBJECT(buffer), "insert_text",
5020 G_CALLBACK(text_inserted), compose);
5023 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5024 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5025 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5026 g_signal_connect(G_OBJECT(text), "drag_data_received",
5027 G_CALLBACK(compose_insert_drag_received_cb),
5029 g_signal_connect(G_OBJECT(text), "drag-drop",
5030 G_CALLBACK(compose_drag_drop),
5032 gtk_widget_show_all(vbox);
5034 /* pane between attach clist and text */
5035 paned = gtk_vpaned_new();
5036 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5037 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5038 gtk_paned_add1(GTK_PANED(paned), notebook);
5039 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5040 gtk_widget_show_all(paned);
5043 if (prefs_common.textfont) {
5044 PangoFontDescription *font_desc;
5046 font_desc = pango_font_description_from_string
5047 (prefs_common.textfont);
5049 gtk_widget_modify_font(text, font_desc);
5050 pango_font_description_free(font_desc);
5054 color[0] = quote_color;
5055 cmap = gdk_drawable_get_colormap(window->window);
5056 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5057 if (success[0] == FALSE) {
5060 g_warning("Compose: color allocation failed.\n");
5061 style = gtk_widget_get_style(text);
5062 quote_color = style->black;
5065 n_entries = sizeof(compose_popup_entries) /
5066 sizeof(compose_popup_entries[0]);
5067 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5068 "<Compose>", &popupfactory,
5071 ifactory = gtk_item_factory_from_widget(menubar);
5072 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5073 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5074 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5076 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5078 undostruct = undo_init(text);
5079 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5082 address_completion_start(window);
5084 compose->window = window;
5085 compose->vbox = vbox;
5086 compose->menubar = menubar;
5087 compose->handlebox = handlebox;
5089 compose->vbox2 = vbox2;
5091 compose->paned = paned;
5093 compose->edit_vbox = edit_vbox;
5094 compose->ruler_hbox = ruler_hbox;
5095 compose->ruler = ruler;
5096 compose->scrolledwin = scrolledwin;
5097 compose->text = text;
5099 compose->focused_editable = NULL;
5101 compose->popupmenu = popupmenu;
5102 compose->popupfactory = popupfactory;
5104 compose->tmpl_menu = tmpl_menu;
5106 compose->mode = mode;
5108 compose->targetinfo = NULL;
5109 compose->replyinfo = NULL;
5110 compose->fwdinfo = NULL;
5112 compose->replyto = NULL;
5114 compose->bcc = NULL;
5115 compose->followup_to = NULL;
5117 compose->ml_post = NULL;
5119 compose->inreplyto = NULL;
5120 compose->references = NULL;
5121 compose->msgid = NULL;
5122 compose->boundary = NULL;
5124 compose->autowrap = prefs_common.autowrap;
5126 compose->use_signing = FALSE;
5127 compose->use_encryption = FALSE;
5128 compose->privacy_system = NULL;
5130 compose->modified = FALSE;
5132 compose->return_receipt = FALSE;
5134 compose->to_list = NULL;
5135 compose->newsgroup_list = NULL;
5137 compose->undostruct = undostruct;
5139 compose->sig_str = NULL;
5141 compose->exteditor_file = NULL;
5142 compose->exteditor_pid = -1;
5143 compose->exteditor_tag = -1;
5144 compose->draft_timeout_tag = -1;
5147 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5148 if (mode != COMPOSE_REDIRECT) {
5149 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5150 strcmp(prefs_common.dictionary, _("None"))) {
5151 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5152 prefs_common.dictionary,
5153 conv_get_locale_charset_str(),
5154 prefs_common.misspelled_col,
5155 prefs_common.check_while_typing,
5156 prefs_common.use_alternate,
5157 GTK_TEXT_VIEW(text),
5158 GTK_WINDOW(compose->window));
5160 alertpanel_error(_("Spell checker could not "
5162 gtkaspell_checkers_strerror());
5163 gtkaspell_checkers_reset_error();
5166 GtkWidget *menuitem;
5168 if (!gtkaspell_set_sug_mode(gtkaspell,
5169 prefs_common.aspell_sugmode)) {
5170 debug_print("Aspell: could not set "
5171 "suggestion mode %s\n",
5172 gtkaspell_checkers_strerror());
5173 gtkaspell_checkers_reset_error();
5176 menuitem = gtk_item_factory_get_item(ifactory,
5177 "/Spelling/Spelling Configuration");
5178 gtkaspell_populate_submenu(gtkaspell, menuitem);
5179 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5183 compose->gtkaspell = gtkaspell;
5186 compose_select_account(compose, account, TRUE);
5188 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5189 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5190 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5192 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5193 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5195 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5196 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5199 if (account->protocol != A_NNTP)
5200 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5202 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5204 addressbook_set_target_compose(compose);
5206 if (mode != COMPOSE_REDIRECT)
5207 compose_set_template_menu(compose);
5209 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5210 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5213 compose_list = g_list_append(compose_list, compose);
5215 if (!prefs_common.show_ruler)
5216 gtk_widget_hide(ruler_hbox);
5218 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5219 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5220 prefs_common.show_ruler);
5223 compose->priority = PRIORITY_NORMAL;
5224 compose_update_priority_menu_item(compose);
5226 compose_set_out_encoding(compose);
5229 compose_update_actions_menu(compose);
5231 /* Privacy Systems menu */
5232 compose_update_privacy_systems_menu(compose);
5234 activate_privacy_system(compose, account);
5235 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5236 gtk_widget_show(window);
5241 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5247 gint num = 0, def_menu = 0;
5249 accounts = account_get_list();
5250 g_return_val_if_fail(accounts != NULL, NULL);
5252 hbox = gtk_hbox_new(FALSE, 0);
5253 optmenu = gtk_option_menu_new();
5254 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5255 menu = gtk_menu_new();
5257 for (; accounts != NULL; accounts = accounts->next, num++) {
5258 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5259 GtkWidget *menuitem;
5262 if (ac == compose->account) def_menu = num;
5265 name = g_strdup_printf("%s: %s <%s>",
5267 ac->name, ac->address);
5269 name = g_strdup_printf("%s: %s",
5270 ac->account_name, ac->address);
5271 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5273 g_signal_connect(G_OBJECT(menuitem), "activate",
5274 G_CALLBACK(account_activated),
5278 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5279 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5284 static void compose_set_priority_cb(gpointer data,
5288 Compose *compose = (Compose *) data;
5289 compose->priority = action;
5292 static void compose_update_priority_menu_item(Compose * compose)
5294 GtkItemFactory *ifactory;
5295 GtkWidget *menuitem = NULL;
5297 ifactory = gtk_item_factory_from_widget(compose->menubar);
5299 switch (compose->priority) {
5300 case PRIORITY_HIGHEST:
5301 menuitem = gtk_item_factory_get_item
5302 (ifactory, "/Options/Priority/Highest");
5305 menuitem = gtk_item_factory_get_item
5306 (ifactory, "/Options/Priority/High");
5308 case PRIORITY_NORMAL:
5309 menuitem = gtk_item_factory_get_item
5310 (ifactory, "/Options/Priority/Normal");
5313 menuitem = gtk_item_factory_get_item
5314 (ifactory, "/Options/Priority/Low");
5316 case PRIORITY_LOWEST:
5317 menuitem = gtk_item_factory_get_item
5318 (ifactory, "/Options/Priority/Lowest");
5321 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5324 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5326 Compose *compose = (Compose *) data;
5328 GtkItemFactory *ifactory;
5329 gboolean can_sign = FALSE, can_encrypt = FALSE;
5331 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5333 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5336 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5337 g_free(compose->privacy_system);
5338 compose->privacy_system = NULL;
5339 if (systemid != NULL) {
5340 compose->privacy_system = g_strdup(systemid);
5342 can_sign = privacy_system_can_sign(systemid);
5343 can_encrypt = privacy_system_can_encrypt(systemid);
5346 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5348 ifactory = gtk_item_factory_from_widget(compose->menubar);
5349 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5350 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5353 static void compose_update_privacy_system_menu_item(Compose * compose)
5355 static gchar *branch_path = "/Options/Privacy System";
5356 GtkItemFactory *ifactory;
5357 GtkWidget *menuitem = NULL;
5359 gboolean can_sign = FALSE, can_encrypt = FALSE;
5361 ifactory = gtk_item_factory_from_widget(compose->menubar);
5363 if (compose->privacy_system != NULL) {
5366 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5367 g_return_if_fail(menuitem != NULL);
5369 amenu = GTK_MENU_SHELL(menuitem)->children;
5371 while (amenu != NULL) {
5372 GList *alist = amenu->next;
5374 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
5375 if (systemid != NULL)
5376 if (strcmp(systemid, compose->privacy_system) == 0) {
5377 menuitem = GTK_WIDGET(amenu->data);
5379 can_sign = privacy_system_can_sign(systemid);
5380 can_encrypt = privacy_system_can_encrypt(systemid);
5387 if (menuitem != NULL)
5388 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5391 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5392 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5395 static void compose_set_out_encoding(Compose *compose)
5397 GtkItemFactoryEntry *entry;
5398 GtkItemFactory *ifactory;
5399 CharSet out_encoding;
5400 gchar *path, *p, *q;
5403 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
5404 ifactory = gtk_item_factory_from_widget(compose->menubar);
5406 for (entry = compose_entries; entry->callback != compose_address_cb;
5408 if (entry->callback == compose_set_encoding_cb &&
5409 (CharSet)entry->callback_action == out_encoding) {
5410 p = q = path = g_strdup(entry->path);
5422 item = gtk_item_factory_get_item(ifactory, path);
5423 gtk_widget_activate(item);
5430 static void compose_set_template_menu(Compose *compose)
5432 GSList *tmpl_list, *cur;
5436 tmpl_list = template_get_config();
5438 menu = gtk_menu_new();
5440 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5441 Template *tmpl = (Template *)cur->data;
5443 item = gtk_menu_item_new_with_label(tmpl->name);
5444 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5445 g_signal_connect(G_OBJECT(item), "activate",
5446 G_CALLBACK(compose_template_activate_cb),
5448 g_object_set_data(G_OBJECT(item), "template", tmpl);
5449 gtk_widget_show(item);
5452 gtk_widget_show(menu);
5453 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5456 void compose_update_actions_menu(Compose *compose)
5458 GtkItemFactory *ifactory;
5460 ifactory = gtk_item_factory_from_widget(compose->menubar);
5461 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5464 void compose_update_privacy_systems_menu(Compose *compose)
5466 static gchar *branch_path = "/Options/Privacy System";
5467 GtkItemFactory *ifactory;
5468 GtkWidget *menuitem;
5469 GSList *systems, *cur;
5472 GtkWidget *system_none;
5475 ifactory = gtk_item_factory_from_widget(compose->menubar);
5477 /* remove old entries */
5478 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5479 g_return_if_fail(menuitem != NULL);
5481 amenu = GTK_MENU_SHELL(menuitem)->children->next;
5482 while (amenu != NULL) {
5483 GList *alist = amenu->next;
5484 gtk_widget_destroy(GTK_WIDGET(amenu->data));
5488 system_none = gtk_item_factory_get_widget(ifactory,
5489 "/Options/Privacy System/None");
5491 g_signal_connect(G_OBJECT(system_none), "activate",
5492 G_CALLBACK(compose_set_privacy_system_cb), compose);
5494 systems = privacy_get_system_ids();
5495 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
5496 gchar *systemid = cur->data;
5498 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
5499 widget = gtk_radio_menu_item_new_with_label(group,
5500 privacy_system_get_name(systemid));
5501 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
5502 g_strdup(systemid), g_free);
5503 g_signal_connect(G_OBJECT(widget), "activate",
5504 G_CALLBACK(compose_set_privacy_system_cb), compose);
5506 gtk_menu_append(GTK_MENU(system_none->parent), widget);
5507 gtk_widget_show(widget);
5510 g_slist_free(systems);
5513 void compose_reflect_prefs_all(void)
5518 for (cur = compose_list; cur != NULL; cur = cur->next) {
5519 compose = (Compose *)cur->data;
5520 compose_set_template_menu(compose);
5524 void compose_reflect_prefs_pixmap_theme(void)
5529 for (cur = compose_list; cur != NULL; cur = cur->next) {
5530 compose = (Compose *)cur->data;
5531 toolbar_update(TOOLBAR_COMPOSE, compose);
5535 static void compose_template_apply(Compose *compose, Template *tmpl,
5539 GtkTextBuffer *buffer;
5545 if (!tmpl || !tmpl->value) return;
5547 text = GTK_TEXT_VIEW(compose->text);
5548 buffer = gtk_text_view_get_buffer(text);
5550 if (tmpl->subject && *tmpl->subject != '\0')
5551 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5553 if (tmpl->to && *tmpl->to != '\0')
5554 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5555 if (tmpl->cc && *tmpl->cc != '\0')
5556 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5558 if (tmpl->bcc && *tmpl->bcc != '\0')
5559 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5562 gtk_text_buffer_set_text(buffer, "", -1);
5564 mark = gtk_text_buffer_get_insert(buffer);
5565 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
5567 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
5568 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5571 if (prefs_common.quotemark && *prefs_common.quotemark)
5572 qmark = prefs_common.quotemark;
5576 if (compose->replyinfo != NULL)
5577 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5578 tmpl->value, qmark, NULL);
5579 else if (compose->fwdinfo != NULL)
5580 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
5581 tmpl->value, qmark, NULL);
5586 if (replace && parsed_str && compose->account->auto_sig)
5587 compose_insert_sig(compose, FALSE);
5589 if (replace && parsed_str) {
5590 gtk_text_buffer_get_start_iter(buffer, &iter);
5591 gtk_text_buffer_place_cursor(buffer, &iter);
5595 compose_changed_cb(NULL, compose);
5598 static void compose_destroy(Compose *compose)
5600 compose_list = g_list_remove(compose_list, compose);
5602 /* NOTE: address_completion_end() does nothing with the window
5603 * however this may change. */
5604 address_completion_end(compose->window);
5606 slist_free_strings(compose->to_list);
5607 g_slist_free(compose->to_list);
5608 slist_free_strings(compose->newsgroup_list);
5609 g_slist_free(compose->newsgroup_list);
5610 slist_free_strings(compose->header_list);
5611 g_slist_free(compose->header_list);
5613 procmsg_msginfo_free(compose->targetinfo);
5614 procmsg_msginfo_free(compose->replyinfo);
5615 procmsg_msginfo_free(compose->fwdinfo);
5617 g_free(compose->replyto);
5618 g_free(compose->cc);
5619 g_free(compose->bcc);
5620 g_free(compose->newsgroups);
5621 g_free(compose->followup_to);
5623 g_free(compose->ml_post);
5625 g_free(compose->inreplyto);
5626 g_free(compose->references);
5627 g_free(compose->msgid);
5628 g_free(compose->boundary);
5630 if (compose->redirect_filename)
5631 g_free(compose->redirect_filename);
5632 if (compose->undostruct)
5633 undo_destroy(compose->undostruct);
5635 g_free(compose->sig_str);
5637 g_free(compose->exteditor_file);
5639 if (addressbook_get_target_compose() == compose)
5640 addressbook_set_target_compose(NULL);
5643 if (compose->gtkaspell) {
5644 gtkaspell_delete(compose->gtkaspell);
5645 compose->gtkaspell = NULL;
5649 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5650 prefs_common.compose_height = compose->window->allocation.height;
5652 if (!gtk_widget_get_parent(compose->paned))
5653 gtk_widget_destroy(compose->paned);
5654 gtk_widget_destroy(compose->popupmenu);
5656 gtk_widget_destroy(compose->window);
5657 toolbar_destroy(compose->toolbar);
5658 g_free(compose->toolbar);
5662 static void compose_attach_info_free(AttachInfo *ainfo)
5664 g_free(ainfo->file);
5665 g_free(ainfo->content_type);
5666 g_free(ainfo->name);
5670 static void compose_attach_remove_selected(Compose *compose)
5672 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
5673 GtkTreeSelection *selection;
5675 GtkTreeModel *model;
5677 selection = gtk_tree_view_get_selection(tree_view);
5678 sel = gtk_tree_selection_get_selected_rows(selection, &model);
5683 for (cur = sel; cur != NULL; cur = cur->next) {
5684 GtkTreePath *path = cur->data;
5685 GtkTreeRowReference *ref = gtk_tree_row_reference_new
5688 gtk_tree_path_free(path);
5691 for (cur = sel; cur != NULL; cur = cur->next) {
5692 GtkTreeRowReference *ref = cur->data;
5693 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
5696 if (gtk_tree_model_get_iter(model, &iter, path))
5697 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
5699 gtk_tree_path_free(path);
5700 gtk_tree_row_reference_free(ref);
5706 static struct _AttachProperty
5709 GtkWidget *mimetype_entry;
5710 GtkWidget *encoding_optmenu;
5711 GtkWidget *path_entry;
5712 GtkWidget *filename_entry;
5714 GtkWidget *cancel_btn;
5717 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
5719 gtk_tree_path_free((GtkTreePath *)ptr);
5722 static void compose_attach_property(Compose *compose)
5724 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
5726 GtkOptionMenu *optmenu;
5727 GtkTreeSelection *selection;
5729 GtkTreeModel *model;
5732 static gboolean cancelled;
5734 /* only if one selected */
5735 selection = gtk_tree_view_get_selection(tree_view);
5736 if (gtk_tree_selection_count_selected_rows(selection) != 1)
5739 sel = gtk_tree_selection_get_selected_rows(selection, &model);
5743 path = (GtkTreePath *) sel->data;
5744 gtk_tree_model_get_iter(model, &iter, path);
5745 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
5748 g_list_foreach(sel, gtk_tree_path_free_, NULL);
5754 if (!attach_prop.window)
5755 compose_attach_property_create(&cancelled);
5756 gtk_widget_grab_focus(attach_prop.ok_btn);
5757 gtk_widget_show(attach_prop.window);
5758 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5760 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5761 if (ainfo->encoding == ENC_UNKNOWN)
5762 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5763 GINT_TO_POINTER(ENC_BASE64));
5765 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5766 GINT_TO_POINTER(ainfo->encoding));
5768 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5769 ainfo->content_type ? ainfo->content_type : "");
5770 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5771 ainfo->file ? ainfo->file : "");
5772 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5773 ainfo->name ? ainfo->name : "");
5776 const gchar *entry_text;
5778 gchar *cnttype = NULL;
5782 GtkWidget *menuitem;
5787 gtk_widget_hide(attach_prop.window);
5792 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5793 if (*entry_text != '\0') {
5796 text = g_strstrip(g_strdup(entry_text));
5797 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5798 cnttype = g_strdup(text);
5801 alertpanel_error(_("Invalid MIME type."));
5807 menu = gtk_option_menu_get_menu(optmenu);
5808 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5809 ainfo->encoding = GPOINTER_TO_INT
5810 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
5812 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5813 if (*entry_text != '\0') {
5814 if (is_file_exist(entry_text) &&
5815 (size = get_file_size(entry_text)) > 0)
5816 file = g_strdup(entry_text);
5819 (_("File doesn't exist or is empty."));
5825 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5826 if (*entry_text != '\0') {
5827 g_free(ainfo->name);
5828 ainfo->name = g_strdup(entry_text);
5832 g_free(ainfo->content_type);
5833 ainfo->content_type = cnttype;
5836 g_free(ainfo->file);
5842 /* update tree store */
5843 text = to_human_readable(ainfo->size);
5844 gtk_tree_model_get_iter(model, &iter, path);
5845 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
5846 COL_MIMETYPE, ainfo->content_type,
5848 COL_NAME, ainfo->file,
5854 gtk_tree_path_free(path);
5857 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5859 label = gtk_label_new(str); \
5860 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5861 GTK_FILL, 0, 0, 0); \
5862 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5864 entry = gtk_entry_new(); \
5865 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5866 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5869 static void compose_attach_property_create(gboolean *cancelled)
5875 GtkWidget *mimetype_entry;
5878 GtkWidget *optmenu_menu;
5879 GtkWidget *menuitem;
5880 GtkWidget *path_entry;
5881 GtkWidget *filename_entry;
5884 GtkWidget *cancel_btn;
5885 GList *mime_type_list, *strlist;
5887 debug_print("Creating attach_property window...\n");
5889 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5890 gtk_widget_set_size_request(window, 480, -1);
5891 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5892 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
5893 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5894 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5895 g_signal_connect(G_OBJECT(window), "delete_event",
5896 G_CALLBACK(attach_property_delete_event),
5898 g_signal_connect(G_OBJECT(window), "key_press_event",
5899 G_CALLBACK(attach_property_key_pressed),
5902 vbox = gtk_vbox_new(FALSE, 8);
5903 gtk_container_add(GTK_CONTAINER(window), vbox);
5905 table = gtk_table_new(4, 2, FALSE);
5906 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5907 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5908 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5910 label = gtk_label_new(_("MIME type"));
5911 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5913 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5914 mimetype_entry = gtk_combo_new();
5915 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5916 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5918 /* stuff with list */
5919 mime_type_list = procmime_get_mime_type_list();
5921 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5922 MimeType *type = (MimeType *) mime_type_list->data;
5923 strlist = g_list_append(strlist,
5924 g_strdup_printf("%s/%s",
5925 type->type, type->sub_type));
5928 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5930 for (mime_type_list = strlist; mime_type_list != NULL;
5931 mime_type_list = mime_type_list->next)
5932 g_free(mime_type_list->data);
5933 g_list_free(strlist);
5935 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5937 label = gtk_label_new(_("Encoding"));
5938 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5940 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5942 hbox = gtk_hbox_new(FALSE, 0);
5943 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5944 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5946 optmenu = gtk_option_menu_new();
5947 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5949 optmenu_menu = gtk_menu_new();
5950 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5951 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5952 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5953 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5954 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
5955 ENC_QUOTED_PRINTABLE);
5956 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5958 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5960 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5962 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5963 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5965 gtkut_stock_button_set_create(&hbbox, &ok_btn, GTK_STOCK_OK,
5966 &cancel_btn, GTK_STOCK_CANCEL,
5968 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5969 gtk_widget_grab_default(ok_btn);
5971 g_signal_connect(G_OBJECT(ok_btn), "clicked",
5972 G_CALLBACK(attach_property_ok),
5974 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
5975 G_CALLBACK(attach_property_cancel),
5978 gtk_widget_show_all(vbox);
5980 attach_prop.window = window;
5981 attach_prop.mimetype_entry = mimetype_entry;
5982 attach_prop.encoding_optmenu = optmenu;
5983 attach_prop.path_entry = path_entry;
5984 attach_prop.filename_entry = filename_entry;
5985 attach_prop.ok_btn = ok_btn;
5986 attach_prop.cancel_btn = cancel_btn;
5989 #undef SET_LABEL_AND_ENTRY
5991 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5997 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6003 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6004 gboolean *cancelled)
6012 static gboolean attach_property_key_pressed(GtkWidget *widget,
6014 gboolean *cancelled)
6016 if (event && event->keyval == GDK_Escape) {
6023 static void compose_exec_ext_editor(Compose *compose)
6030 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6031 G_DIR_SEPARATOR, compose);
6033 if (pipe(pipe_fds) < 0) {
6039 if ((pid = fork()) < 0) {
6046 /* close the write side of the pipe */
6049 compose->exteditor_file = g_strdup(tmp);
6050 compose->exteditor_pid = pid;
6052 compose_set_ext_editor_sensitive(compose, FALSE);
6054 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6055 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6059 } else { /* process-monitoring process */
6065 /* close the read side of the pipe */
6068 if (compose_write_body_to_file(compose, tmp) < 0) {
6069 fd_write_all(pipe_fds[1], "2\n", 2);
6073 pid_ed = compose_exec_ext_editor_real(tmp);
6075 fd_write_all(pipe_fds[1], "1\n", 2);
6079 /* wait until editor is terminated */
6080 waitpid(pid_ed, NULL, 0);
6082 fd_write_all(pipe_fds[1], "0\n", 2);
6089 #endif /* G_OS_UNIX */
6093 static gint compose_exec_ext_editor_real(const gchar *file)
6095 static gchar *def_cmd = "emacs %s";
6101 g_return_val_if_fail(file != NULL, -1);
6103 if ((pid = fork()) < 0) {
6108 if (pid != 0) return pid;
6110 /* grandchild process */
6112 if (setpgid(0, getppid()))
6115 if (prefs_common.ext_editor_cmd &&
6116 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6117 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6118 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6120 if (prefs_common.ext_editor_cmd)
6121 g_warning("External editor command line is invalid: '%s'\n",
6122 prefs_common.ext_editor_cmd);
6123 g_snprintf(buf, sizeof(buf), def_cmd, file);
6126 cmdline = strsplit_with_quote(buf, " ", 1024);
6127 execvp(cmdline[0], cmdline);
6130 g_strfreev(cmdline);
6135 static gboolean compose_ext_editor_kill(Compose *compose)
6137 pid_t pgid = compose->exteditor_pid * -1;
6140 ret = kill(pgid, 0);
6142 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6146 msg = g_strdup_printf
6147 (_("The external editor is still working.\n"
6148 "Force terminating the process?\n"
6149 "process group id: %d"), -pgid);
6150 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_YES, GTK_STOCK_NO,
6151 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
6155 if (val == G_ALERTDEFAULT) {
6156 g_source_remove(compose->exteditor_tag);
6157 g_io_channel_shutdown(compose->exteditor_ch,
6159 g_io_channel_unref(compose->exteditor_ch);
6161 if (kill(pgid, SIGTERM) < 0) perror("kill");
6162 waitpid(compose->exteditor_pid, NULL, 0);
6164 g_warning("Terminated process group id: %d", -pgid);
6165 g_warning("Temporary file: %s",
6166 compose->exteditor_file);
6168 compose_set_ext_editor_sensitive(compose, TRUE);
6170 g_free(compose->exteditor_file);
6171 compose->exteditor_file = NULL;
6172 compose->exteditor_pid = -1;
6173 compose->exteditor_ch = NULL;
6174 compose->exteditor_tag = -1;
6182 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6186 Compose *compose = (Compose *)data;
6189 debug_print(_("Compose: input from monitoring process\n"));
6191 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6193 g_io_channel_shutdown(source, FALSE, NULL);
6194 g_io_channel_unref(source);
6196 waitpid(compose->exteditor_pid, NULL, 0);
6198 if (buf[0] == '0') { /* success */
6199 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6200 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6202 gtk_text_buffer_set_text(buffer, "", -1);
6203 compose_insert_file(compose, compose->exteditor_file);
6204 compose_changed_cb(NULL, compose);
6206 if (g_unlink(compose->exteditor_file) < 0)
6207 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6208 } else if (buf[0] == '1') { /* failed */
6209 g_warning("Couldn't exec external editor\n");
6210 if (g_unlink(compose->exteditor_file) < 0)
6211 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6212 } else if (buf[0] == '2') {
6213 g_warning("Couldn't write to file\n");
6214 } else if (buf[0] == '3') {
6215 g_warning("Pipe read failed\n");
6218 compose_set_ext_editor_sensitive(compose, TRUE);
6220 g_free(compose->exteditor_file);
6221 compose->exteditor_file = NULL;
6222 compose->exteditor_pid = -1;
6223 compose->exteditor_ch = NULL;
6224 compose->exteditor_tag = -1;
6229 static void compose_set_ext_editor_sensitive(Compose *compose,
6232 GtkItemFactory *ifactory;
6234 ifactory = gtk_item_factory_from_widget(compose->menubar);
6236 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6237 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6238 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6239 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6240 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6241 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6242 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6245 gtk_widget_set_sensitive(compose->text, sensitive);
6246 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6247 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6248 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6249 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6250 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6251 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6252 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
6253 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
6255 #endif /* G_OS_UNIX */
6258 * compose_undo_state_changed:
6260 * Change the sensivity of the menuentries undo and redo
6262 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6263 gint redo_state, gpointer data)
6265 GtkWidget *widget = GTK_WIDGET(data);
6266 GtkItemFactory *ifactory;
6268 g_return_if_fail(widget != NULL);
6270 ifactory = gtk_item_factory_from_widget(widget);
6272 switch (undo_state) {
6273 case UNDO_STATE_TRUE:
6274 if (!undostruct->undo_state) {
6275 undostruct->undo_state = TRUE;
6276 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6279 case UNDO_STATE_FALSE:
6280 if (undostruct->undo_state) {
6281 undostruct->undo_state = FALSE;
6282 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6285 case UNDO_STATE_UNCHANGED:
6287 case UNDO_STATE_REFRESH:
6288 menu_set_sensitive(ifactory, "/Edit/Undo",
6289 undostruct->undo_state);
6292 g_warning("Undo state not recognized");
6296 switch (redo_state) {
6297 case UNDO_STATE_TRUE:
6298 if (!undostruct->redo_state) {
6299 undostruct->redo_state = TRUE;
6300 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6303 case UNDO_STATE_FALSE:
6304 if (undostruct->redo_state) {
6305 undostruct->redo_state = FALSE;
6306 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6309 case UNDO_STATE_UNCHANGED:
6311 case UNDO_STATE_REFRESH:
6312 menu_set_sensitive(ifactory, "/Edit/Redo",
6313 undostruct->redo_state);
6316 g_warning("Redo state not recognized");
6321 /* callback functions */
6323 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6324 * includes "non-client" (windows-izm) in calculation, so this calculation
6325 * may not be accurate.
6327 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6328 GtkAllocation *allocation,
6329 GtkSHRuler *shruler)
6331 if (prefs_common.show_ruler) {
6332 gint char_width = 0, char_height = 0;
6333 gint line_width_in_chars;
6335 gtkut_get_font_size(GTK_WIDGET(widget),
6336 &char_width, &char_height);
6337 line_width_in_chars =
6338 (allocation->width - allocation->x) / char_width;
6340 /* got the maximum */
6341 gtk_ruler_set_range(GTK_RULER(shruler),
6342 0.0, line_width_in_chars, 0,
6343 /*line_width_in_chars*/ char_width);
6349 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6351 Compose *compose = (Compose *)data;
6354 gchar *folderidentifier;
6356 ac = account_find_from_id(
6357 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
6358 g_return_if_fail(ac != NULL);
6360 if (ac != compose->account)
6361 compose_select_account(compose, ac, FALSE);
6363 /* Set message save folder */
6364 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6365 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
6367 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
6368 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
6370 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6371 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6372 folderidentifier = folder_item_get_identifier(account_get_special_folder
6373 (compose->account, F_OUTBOX));
6374 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
6375 g_free(folderidentifier);
6379 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
6380 GtkTreeViewColumn *column, Compose *compose)
6382 compose_attach_property(compose);
6385 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6388 Compose *compose = (Compose *)data;
6390 if (!event) return FALSE;
6392 if (event->button == 3) {
6393 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6394 NULL, NULL, event->button, event->time);
6401 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6404 Compose *compose = (Compose *)data;
6406 if (!event) return FALSE;
6408 switch (event->keyval) {
6410 compose_attach_remove_selected(compose);
6416 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6418 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6419 toolbar_comp_set_sensitive(compose, allow);
6420 menu_set_sensitive(ifactory, "/Message", allow);
6421 menu_set_sensitive(ifactory, "/Edit", allow);
6423 menu_set_sensitive(ifactory, "/Spelling", allow);
6425 menu_set_sensitive(ifactory, "/Options", allow);
6426 menu_set_sensitive(ifactory, "/Tools", allow);
6427 menu_set_sensitive(ifactory, "/Help", allow);
6429 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
6433 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6435 Compose *compose = (Compose *)data;
6437 if (prefs_common.work_offline)
6438 if (alertpanel(_("Offline warning"),
6439 _("You're working offline. Override?"),
6440 GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT)
6443 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
6444 gtk_timeout_remove(compose->draft_timeout_tag);
6445 compose->draft_timeout_tag = -1;
6448 compose_send(compose);
6451 static void compose_send_later_cb(gpointer data, guint action,
6454 Compose *compose = (Compose *)data;
6457 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6459 compose_close(compose);
6460 else if (val == -2) {
6461 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
6465 void compose_draft (gpointer data)
6467 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6470 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6472 Compose *compose = (Compose *)data;
6476 MsgFlags flag = {0, 0};
6477 static gboolean lock = FALSE;
6478 MsgInfo *newmsginfo;
6483 draft = account_get_special_folder(compose->account, F_DRAFT);
6484 g_return_if_fail(draft != NULL);
6488 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
6489 G_DIR_SEPARATOR, compose);
6490 if ((fp = g_fopen(tmp, "wb")) == NULL) {
6491 FILE_OP_ERROR(tmp, "fopen");
6495 /* chmod for security */
6496 if (change_file_mode_rw(fp, tmp) < 0) {
6497 FILE_OP_ERROR(tmp, "chmod");
6498 g_warning("can't change file mode\n");
6501 /* Save draft infos */
6502 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
6503 fprintf(fp, "S:%s\n", compose->account->address);
6504 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
6505 gchar *savefolderid;
6507 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6508 fprintf(fp, "SCF:%s\n", savefolderid);
6509 g_free(savefolderid);
6511 if (compose->privacy_system) {
6512 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
6513 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
6514 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
6518 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
6527 folder_item_scan(draft);
6528 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
6535 draft->mtime = 0; /* force updating */
6537 if (compose->mode == COMPOSE_REEDIT) {
6538 compose_remove_reedit_target(compose);
6541 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6543 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6544 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
6545 if (compose_use_attach(compose))
6546 procmsg_msginfo_set_flags(newmsginfo, 0,
6547 MSG_HAS_ATTACHMENT);
6549 procmsg_msginfo_free(newmsginfo);
6552 folder_item_scan(draft);
6556 if (action == COMPOSE_QUIT_EDITING)
6557 compose_close(compose);
6562 path = folder_item_fetch_msg(draft, msgnum);
6563 g_return_if_fail(path != NULL);
6564 if (g_stat(path, &s) < 0) {
6565 FILE_OP_ERROR(path, "stat");
6572 procmsg_msginfo_free(compose->targetinfo);
6573 compose->targetinfo = procmsg_msginfo_new();
6574 compose->targetinfo->msgnum = msgnum;
6575 compose->targetinfo->size = s.st_size;
6576 compose->targetinfo->mtime = s.st_mtime;
6577 compose->targetinfo->folder = draft;
6578 compose->mode = COMPOSE_REEDIT;
6580 if (action == COMPOSE_AUTO_SAVE) {
6581 compose->autosaved_draft = compose->targetinfo;
6586 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6588 Compose *compose = (Compose *)data;
6591 if (compose->redirect_filename != NULL)
6594 file_list = filesel_select_multiple_files_open(_("Select file"));
6599 for ( tmp = file_list; tmp; tmp = tmp->next) {
6600 gchar *file = (gchar *) tmp->data;
6601 gchar *utf8_filename = conv_filename_to_utf8(file);
6602 compose_attach_append(compose, file, utf8_filename, NULL);
6603 compose_changed_cb(NULL, compose);
6605 g_free(utf8_filename);
6607 g_list_free(file_list);
6611 static void compose_insert_file_cb(gpointer data, guint action,
6614 Compose *compose = (Compose *)data;
6617 file_list = filesel_select_multiple_files_open(_("Select file"));
6622 for ( tmp = file_list; tmp; tmp = tmp->next) {
6623 gchar *file = (gchar *) tmp->data;
6624 gchar *filedup = g_strdup(file);
6625 gchar *shortfile = g_path_get_basename(filedup);
6626 ComposeInsertResult res;
6628 res = compose_insert_file(compose, file);
6629 if (res == COMPOSE_INSERT_READ_ERROR) {
6630 alertpanel_error(_("File '%s' could not be read."), shortfile);
6631 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
6632 alertpanel_error(_("File '%s' contained invalid characters\n"
6633 "for the current encoding, insertion may be incorrect."), shortfile);
6639 g_list_free(file_list);
6643 static void compose_insert_sig_cb(gpointer data, guint action,
6646 Compose *compose = (Compose *)data;
6648 compose_insert_sig(compose, FALSE);
6651 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6655 Compose *compose = (Compose *)data;
6657 gtkut_widget_get_uposition(widget, &x, &y);
6658 prefs_common.compose_x = x;
6659 prefs_common.compose_y = y;
6661 if (compose->sending)
6663 compose_close_cb(compose, 0, NULL);
6667 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6669 Compose *compose = (Compose *)data;
6673 if (compose->exteditor_tag != -1) {
6674 if (!compose_ext_editor_kill(compose))
6679 if (compose->modified) {
6680 val = alertpanel(_("Discard message"),
6681 _("This message has been modified. discard it?"),
6682 _("Discard"), _("to Draft"), GTK_STOCK_CANCEL);
6685 case G_ALERTDEFAULT:
6686 if (prefs_common.autosave)
6687 compose_remove_draft(compose);
6689 case G_ALERTALTERNATE:
6690 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6697 compose_close(compose);
6700 static void compose_set_encoding_cb(gpointer data, guint action,
6703 Compose *compose = (Compose *)data;
6705 if (GTK_CHECK_MENU_ITEM(widget)->active)
6706 compose->out_encoding = (CharSet)action;
6709 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6711 Compose *compose = (Compose *)data;
6713 addressbook_open(compose);
6716 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6718 Compose *compose = (Compose *)data;
6723 tmpl = g_object_get_data(G_OBJECT(widget), "template");
6724 g_return_if_fail(tmpl != NULL);
6726 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
6728 val = alertpanel(_("Apply template"), msg,
6729 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
6732 if (val == G_ALERTDEFAULT)
6733 compose_template_apply(compose, tmpl, TRUE);
6734 else if (val == G_ALERTALTERNATE)
6735 compose_template_apply(compose, tmpl, FALSE);
6738 static void compose_ext_editor_cb(gpointer data, guint action,
6741 Compose *compose = (Compose *)data;
6743 compose_exec_ext_editor(compose);
6746 static void compose_undo_cb(Compose *compose)
6748 gboolean prev_autowrap = compose->autowrap;
6750 compose->autowrap = FALSE;
6751 undo_undo(compose->undostruct);
6752 compose->autowrap = prev_autowrap;
6755 static void compose_redo_cb(Compose *compose)
6757 gboolean prev_autowrap = compose->autowrap;
6759 compose->autowrap = FALSE;
6760 undo_redo(compose->undostruct);
6761 compose->autowrap = prev_autowrap;
6764 static void entry_cut_clipboard(GtkWidget *entry)
6766 if (GTK_IS_EDITABLE(entry))
6767 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
6768 else if (GTK_IS_TEXT_VIEW(entry))
6769 gtk_text_buffer_cut_clipboard(
6770 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
6771 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
6775 static void entry_copy_clipboard(GtkWidget *entry)
6777 if (GTK_IS_EDITABLE(entry))
6778 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
6779 else if (GTK_IS_TEXT_VIEW(entry))
6780 gtk_text_buffer_copy_clipboard(
6781 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
6782 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
6785 static void entry_paste_clipboard(GtkWidget *entry, gboolean wrap)
6787 if (GTK_IS_EDITABLE(entry))
6788 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
6789 else if (GTK_IS_TEXT_VIEW(entry)) {
6790 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
6791 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
6792 GtkTextIter start_iter, end_iter;
6795 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
6797 if (contents == NULL)
6800 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
6801 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
6803 start = gtk_text_iter_get_offset(&start_iter);
6805 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
6808 end = start + strlen(contents);
6809 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
6810 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
6811 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
6817 static void entry_allsel(GtkWidget *entry)
6819 if (GTK_IS_EDITABLE(entry))
6820 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
6821 else if (GTK_IS_TEXT_VIEW(entry)) {
6822 GtkTextIter startiter, enditer;
6823 GtkTextBuffer *textbuf;
6825 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
6826 gtk_text_buffer_get_start_iter(textbuf, &startiter);
6827 gtk_text_buffer_get_end_iter(textbuf, &enditer);
6829 gtk_text_buffer_move_mark_by_name(textbuf,
6830 "selection_bound", &startiter);
6831 gtk_text_buffer_move_mark_by_name(textbuf,
6832 "insert", &enditer);
6836 static void compose_cut_cb(Compose *compose)
6838 if (compose->focused_editable &&
6839 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6840 entry_cut_clipboard(compose->focused_editable);
6843 static void compose_copy_cb(Compose *compose)
6845 if (compose->focused_editable &&
6846 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6847 entry_copy_clipboard(compose->focused_editable);
6850 #define BLOCK_WRAP() { \
6851 prev_autowrap = compose->autowrap; \
6852 buffer = gtk_text_view_get_buffer( \
6853 GTK_TEXT_VIEW(compose->text)); \
6854 compose->autowrap = FALSE; \
6856 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
6857 G_CALLBACK(compose_changed_cb), \
6859 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
6860 G_CALLBACK(text_inserted), \
6863 #define UNBLOCK_WRAP() { \
6864 compose->autowrap = prev_autowrap; \
6865 if (compose->autowrap) \
6866 compose_wrap_all(compose); \
6868 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
6869 G_CALLBACK(compose_changed_cb), \
6871 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
6872 G_CALLBACK(text_inserted), \
6876 static void compose_paste_cb(Compose *compose)
6879 GtkTextBuffer *buffer;
6881 if (compose->focused_editable &&
6882 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6883 entry_paste_clipboard(compose->focused_editable, prefs_common.linewrap_pastes);
6887 static void compose_paste_as_quote_cb(Compose *compose)
6889 gint wrap_quote = prefs_common.linewrap_quote;
6890 if (compose->focused_editable &&
6891 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6892 /* let text_insert() (called directly or at a later time
6893 * after the gtk_editable_paste_clipboard) know that
6894 * text is to be inserted as a quotation. implemented
6895 * by using a simple refcount... */
6896 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
6897 G_OBJECT(compose->focused_editable),
6898 "paste_as_quotation"));
6899 g_object_set_data(G_OBJECT(compose->focused_editable),
6900 "paste_as_quotation",
6901 GINT_TO_POINTER(paste_as_quotation + 1));
6902 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
6903 entry_paste_clipboard(compose->focused_editable, prefs_common.linewrap_pastes);
6904 prefs_common.linewrap_quote = wrap_quote;
6908 static void compose_paste_no_wrap_cb(Compose *compose)
6911 GtkTextBuffer *buffer;
6913 if (compose->focused_editable &&
6914 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6915 entry_paste_clipboard(compose->focused_editable, FALSE);
6919 static void compose_paste_wrap_cb(Compose *compose)
6922 GtkTextBuffer *buffer;
6924 if (compose->focused_editable &&
6925 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6926 entry_paste_clipboard(compose->focused_editable, TRUE);
6930 static void compose_allsel_cb(Compose *compose)
6932 if (compose->focused_editable &&
6933 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6934 entry_allsel(compose->focused_editable);
6937 static void textview_move_beginning_of_line (GtkTextView *text)
6939 GtkTextBuffer *buffer;
6943 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
6945 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6946 mark = gtk_text_buffer_get_insert(buffer);
6947 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
6948 gtk_text_iter_set_line_offset(&ins, 0);
6949 gtk_text_buffer_place_cursor(buffer, &ins);
6952 static void textview_move_forward_character (GtkTextView *text)
6954 GtkTextBuffer *buffer;
6958 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
6960 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6961 mark = gtk_text_buffer_get_insert(buffer);
6962 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
6963 if (gtk_text_iter_forward_cursor_position(&ins))
6964 gtk_text_buffer_place_cursor(buffer, &ins);
6967 static void textview_move_backward_character (GtkTextView *text)
6969 GtkTextBuffer *buffer;
6973 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
6975 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6976 mark = gtk_text_buffer_get_insert(buffer);
6977 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
6978 if (gtk_text_iter_backward_cursor_position(&ins))
6979 gtk_text_buffer_place_cursor(buffer, &ins);
6982 static void textview_move_forward_word (GtkTextView *text)
6984 GtkTextBuffer *buffer;
6989 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
6991 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6992 mark = gtk_text_buffer_get_insert(buffer);
6993 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
6994 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
6995 if (gtk_text_iter_forward_word_ends(&ins, count)) {
6996 gtk_text_iter_backward_word_start(&ins);
6997 gtk_text_buffer_place_cursor(buffer, &ins);
7001 static void textview_move_backward_word (GtkTextView *text)
7003 GtkTextBuffer *buffer;
7008 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7010 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7011 mark = gtk_text_buffer_get_insert(buffer);
7012 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7013 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7014 if (gtk_text_iter_backward_word_starts(&ins, 1))
7015 gtk_text_buffer_place_cursor(buffer, &ins);
7018 static void textview_move_end_of_line (GtkTextView *text)
7020 GtkTextBuffer *buffer;
7024 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7026 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7027 mark = gtk_text_buffer_get_insert(buffer);
7028 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7029 if (gtk_text_iter_forward_to_line_end(&ins))
7030 gtk_text_buffer_place_cursor(buffer, &ins);
7033 static void textview_move_next_line (GtkTextView *text)
7035 GtkTextBuffer *buffer;
7040 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7042 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7043 mark = gtk_text_buffer_get_insert(buffer);
7044 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7045 offset = gtk_text_iter_get_line_offset(&ins);
7046 if (gtk_text_iter_forward_line(&ins)) {
7047 gtk_text_iter_set_line_offset(&ins, offset);
7048 gtk_text_buffer_place_cursor(buffer, &ins);
7052 static void textview_move_previous_line (GtkTextView *text)
7054 GtkTextBuffer *buffer;
7059 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7061 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7062 mark = gtk_text_buffer_get_insert(buffer);
7063 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7064 offset = gtk_text_iter_get_line_offset(&ins);
7065 if (gtk_text_iter_backward_line(&ins)) {
7066 gtk_text_iter_set_line_offset(&ins, offset);
7067 gtk_text_buffer_place_cursor(buffer, &ins);
7071 static void textview_delete_forward_character (GtkTextView *text)
7073 GtkTextBuffer *buffer;
7075 GtkTextIter ins, end_iter;
7077 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7079 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7080 mark = gtk_text_buffer_get_insert(buffer);
7081 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7083 if (gtk_text_iter_forward_char(&end_iter)) {
7084 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7088 static void textview_delete_backward_character (GtkTextView *text)
7090 GtkTextBuffer *buffer;
7092 GtkTextIter ins, end_iter;
7094 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7096 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7097 mark = gtk_text_buffer_get_insert(buffer);
7098 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7100 if (gtk_text_iter_backward_char(&end_iter)) {
7101 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7105 static void textview_delete_forward_word (GtkTextView *text)
7107 GtkTextBuffer *buffer;
7109 GtkTextIter ins, end_iter;
7111 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7113 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7114 mark = gtk_text_buffer_get_insert(buffer);
7115 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7117 if (gtk_text_iter_forward_word_end(&end_iter)) {
7118 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7122 static void textview_delete_backward_word (GtkTextView *text)
7124 GtkTextBuffer *buffer;
7126 GtkTextIter ins, end_iter;
7128 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7130 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7131 mark = gtk_text_buffer_get_insert(buffer);
7132 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7134 if (gtk_text_iter_backward_word_start(&end_iter)) {
7135 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7139 static void textview_delete_line (GtkTextView *text)
7141 GtkTextBuffer *buffer;
7143 GtkTextIter ins, start_iter, end_iter;
7146 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7148 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7149 mark = gtk_text_buffer_get_insert(buffer);
7150 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7153 gtk_text_iter_set_line_offset(&start_iter, 0);
7156 if (gtk_text_iter_ends_line(&end_iter))
7157 found = gtk_text_iter_forward_char(&end_iter);
7159 found = gtk_text_iter_forward_to_line_end(&end_iter);
7162 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7165 static void textview_delete_to_line_end (GtkTextView *text)
7167 GtkTextBuffer *buffer;
7169 GtkTextIter ins, end_iter;
7172 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7174 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7175 mark = gtk_text_buffer_get_insert(buffer);
7176 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7178 if (gtk_text_iter_ends_line(&end_iter))
7179 found = gtk_text_iter_forward_char(&end_iter);
7181 found = gtk_text_iter_forward_to_line_end(&end_iter);
7183 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7186 static void compose_advanced_action_cb(Compose *compose,
7187 ComposeCallAdvancedAction action)
7189 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7191 void (*do_action) (GtkTextView *text);
7192 } action_table[] = {
7193 {textview_move_beginning_of_line},
7194 {textview_move_forward_character},
7195 {textview_move_backward_character},
7196 {textview_move_forward_word},
7197 {textview_move_backward_word},
7198 {textview_move_end_of_line},
7199 {textview_move_next_line},
7200 {textview_move_previous_line},
7201 {textview_delete_forward_character},
7202 {textview_delete_backward_character},
7203 {textview_delete_forward_word},
7204 {textview_delete_backward_word},
7205 {textview_delete_line},
7206 {NULL}, /* gtk_stext_delete_line_n */
7207 {textview_delete_to_line_end}
7210 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
7212 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
7213 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
7214 if (action_table[action].do_action)
7215 action_table[action].do_action(text);
7217 g_warning("Not implemented yet.");
7221 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
7225 if (GTK_IS_EDITABLE(widget)) {
7226 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
7227 gtk_editable_set_position(GTK_EDITABLE(widget),
7232 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
7233 compose->focused_editable = widget;
7236 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
7238 if (compose->modified == FALSE) {
7239 compose->modified = TRUE;
7240 compose_set_title(compose);
7244 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
7246 Compose *compose = (Compose *)data;
7249 compose_wrap_all_full(compose, TRUE);
7251 compose_wrap_paragraph(compose, NULL, TRUE);
7254 static void compose_toggle_autowrap_cb(gpointer data, guint action,
7257 Compose *compose = (Compose *)data;
7258 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7259 if (compose->autowrap)
7260 compose_wrap_all_full(compose, TRUE);
7263 static void compose_toggle_sign_cb(gpointer data, guint action,
7266 Compose *compose = (Compose *)data;
7268 if (GTK_CHECK_MENU_ITEM(widget)->active)
7269 compose->use_signing = TRUE;
7271 compose->use_signing = FALSE;
7274 static void compose_toggle_encrypt_cb(gpointer data, guint action,
7277 Compose *compose = (Compose *)data;
7279 if (GTK_CHECK_MENU_ITEM(widget)->active)
7280 compose->use_encryption = TRUE;
7282 compose->use_encryption = FALSE;
7285 static void activate_privacy_system(Compose *compose, PrefsAccount *account)
7287 g_free(compose->privacy_system);
7288 compose->privacy_system = g_strdup(account->default_privacy_system);
7289 compose_update_privacy_system_menu_item(compose);
7292 static void compose_toggle_ruler_cb(gpointer data, guint action,
7295 Compose *compose = (Compose *)data;
7297 if (GTK_CHECK_MENU_ITEM(widget)->active) {
7298 gtk_widget_show(compose->ruler_hbox);
7299 prefs_common.show_ruler = TRUE;
7301 gtk_widget_hide(compose->ruler_hbox);
7302 gtk_widget_queue_resize(compose->edit_vbox);
7303 prefs_common.show_ruler = FALSE;
7307 static void compose_attach_drag_received_cb (GtkWidget *widget,
7308 GdkDragContext *drag_context,
7311 GtkSelectionData *data,
7316 Compose *compose = (Compose *)user_data;
7319 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7320 list = uri_list_extract_filenames((const gchar *)data->data);
7321 for (tmp = list; tmp != NULL; tmp = tmp->next)
7322 compose_attach_append
7323 (compose, (const gchar *)tmp->data,
7324 (const gchar *)tmp->data, NULL);
7325 if (list) compose_changed_cb(NULL, compose);
7326 list_free_strings(list);
7331 static gboolean compose_drag_drop(GtkWidget *widget,
7332 GdkDragContext *drag_context,
7334 guint time, gpointer user_data)
7336 /* not handling this signal makes compose_insert_drag_received_cb
7341 static void compose_insert_drag_received_cb (GtkWidget *widget,
7342 GdkDragContext *drag_context,
7345 GtkSelectionData *data,
7350 Compose *compose = (Compose *)user_data;
7353 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
7355 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7356 list = uri_list_extract_filenames((const gchar *)data->data);
7357 for (tmp = list; tmp != NULL; tmp = tmp->next) {
7358 compose_insert_file(compose, (const gchar *)tmp->data);
7360 list_free_strings(list);
7362 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7365 gchar *tmpfile = get_tmp_file();
7366 str_write_to_file((const gchar *)data->data, tmpfile);
7367 compose_insert_file(compose, tmpfile);
7370 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7373 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7376 static void compose_header_drag_received_cb (GtkWidget *widget,
7377 GdkDragContext *drag_context,
7380 GtkSelectionData *data,
7385 GtkEditable *entry = (GtkEditable *)user_data;
7386 gchar *email = (gchar *)data->data;
7388 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
7391 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
7392 gchar *decoded=g_new(gchar, strlen(email));
7395 email += strlen("mailto:");
7396 decode_uri(decoded, email); /* will fit */
7397 gtk_editable_delete_text(entry, 0, -1);
7398 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
7399 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7403 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7406 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
7409 Compose *compose = (Compose *)data;
7411 if (GTK_CHECK_MENU_ITEM(widget)->active)
7412 compose->return_receipt = TRUE;
7414 compose->return_receipt = FALSE;
7417 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
7420 Compose *compose = (Compose *)data;
7422 if (GTK_CHECK_MENU_ITEM(widget)->active)
7423 compose->remove_references = TRUE;
7425 compose->remove_references = FALSE;
7428 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
7430 ComposeHeaderEntry *headerentry)
7432 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
7433 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
7434 !(event->state & GDK_MODIFIER_MASK) &&
7435 (event->keyval == GDK_BackSpace) &&
7436 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
7437 gtk_container_remove
7438 (GTK_CONTAINER(headerentry->compose->header_table),
7439 headerentry->combo);
7440 gtk_container_remove
7441 (GTK_CONTAINER(headerentry->compose->header_table),
7442 headerentry->entry);
7443 headerentry->compose->header_list =
7444 g_slist_remove(headerentry->compose->header_list,
7446 g_free(headerentry);
7447 } else if (event->keyval == GDK_Tab) {
7448 if (headerentry->compose->header_last == headerentry) {
7449 /* Override default next focus, and give it to subject_entry
7450 * instead of notebook tabs
7452 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
7453 gtk_widget_grab_focus(headerentry->compose->subject_entry);
7460 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
7461 ComposeHeaderEntry *headerentry)
7463 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
7464 headerentry->compose->header_list =
7465 g_slist_append(headerentry->compose->header_list,
7468 compose_create_header_entry(headerentry->compose);
7469 g_signal_handlers_disconnect_matched
7470 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
7471 0, 0, NULL, NULL, headerentry);
7473 /* Automatically scroll down */
7474 compose_show_first_last_header(headerentry->compose, FALSE);
7480 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
7482 GtkAdjustment *vadj;
7484 g_return_if_fail(compose);
7485 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
7486 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
7488 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
7489 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
7492 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
7493 const gchar *text, gint len, Compose *compose)
7495 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
7496 (G_OBJECT(compose->text), "paste_as_quotation"));
7499 g_return_if_fail(text != NULL);
7501 g_signal_handlers_block_by_func(G_OBJECT(buffer),
7502 G_CALLBACK(text_inserted),
7504 if (paste_as_quotation) {
7511 new_text = g_strndup(text, len);
7512 if (prefs_common.quotemark && *prefs_common.quotemark)
7513 qmark = prefs_common.quotemark;
7517 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
7518 gtk_text_buffer_place_cursor(buffer, iter);
7520 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
7522 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
7523 GINT_TO_POINTER(paste_as_quotation - 1));
7525 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
7527 gtk_text_buffer_insert(buffer, iter, text, len);
7529 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
7531 /* compose_wrap_all_full(compose, FALSE); */
7532 compose_wrap_paragraph(compose, iter, FALSE);
7534 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
7535 gtk_text_buffer_delete_mark(buffer, mark);
7537 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
7538 G_CALLBACK(text_inserted),
7540 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
7542 if (prefs_common.autosave &&
7543 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
7544 compose->draft_timeout_tag = gtk_timeout_add
7545 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
7547 static gint compose_defer_auto_save_draft(Compose *compose)
7549 compose->draft_timeout_tag = -1;
7550 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
7555 static void compose_check_all(Compose *compose)
7557 if (compose->gtkaspell)
7558 gtkaspell_check_all(compose->gtkaspell);
7561 static void compose_highlight_all(Compose *compose)
7563 if (compose->gtkaspell)
7564 gtkaspell_highlight_all(compose->gtkaspell);
7567 static void compose_check_backwards(Compose *compose)
7569 if (compose->gtkaspell)
7570 gtkaspell_check_backwards(compose->gtkaspell);
7572 GtkItemFactory *ifactory;
7573 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7574 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7575 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
7579 static void compose_check_forwards_go(Compose *compose)
7581 if (compose->gtkaspell)
7582 gtkaspell_check_forwards_go(compose->gtkaspell);
7584 GtkItemFactory *ifactory;
7585 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7586 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7587 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
7593 *\brief Guess originating forward account from MsgInfo and several
7594 * "common preference" settings. Return NULL if no guess.
7596 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
7598 PrefsAccount *account = NULL;
7600 g_return_val_if_fail(msginfo, NULL);
7601 g_return_val_if_fail(msginfo->folder, NULL);
7602 g_return_val_if_fail(msginfo->folder->prefs, NULL);
7604 if (msginfo->folder->prefs->enable_default_account)
7605 account = account_find_from_id(msginfo->folder->prefs->default_account);
7608 account = msginfo->folder->folder->account;
7610 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
7612 Xstrdup_a(to, msginfo->to, return NULL);
7613 extract_address(to);
7614 account = account_find_from_address(to);
7617 if (!account && prefs_common.forward_account_autosel) {
7619 if (!procheader_get_header_from_msginfo
7620 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
7621 extract_address(cc);
7622 account = account_find_from_address(cc);
7629 static void compose_close(Compose *compose)
7633 g_return_if_fail(compose);
7634 gtkut_widget_get_uposition(compose->window, &x, &y);
7635 prefs_common.compose_x = x;
7636 prefs_common.compose_y = y;
7637 compose_destroy(compose);
7641 * Add entry field for each address in list.
7642 * \param compose E-Mail composition object.
7643 * \param listAddress List of (formatted) E-Mail addresses.
7645 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
7650 addr = ( gchar * ) node->data;
7651 compose_entry_append( compose, addr, COMPOSE_TO );
7652 node = g_list_next( node );
7656 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
7660 GSList *new_msglist = NULL;
7661 MsgInfo *tmp_msginfo = NULL;
7663 g_return_if_fail(msgview != NULL);
7665 g_return_if_fail(msginfo_list != NULL);
7667 if (g_slist_length(msginfo_list) == 1) {
7668 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
7669 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
7671 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
7672 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
7674 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
7675 orig_msginfo, mimeinfo);
7676 if (tmp_msginfo != NULL) {
7677 new_msglist = g_slist_append(NULL, tmp_msginfo);
7682 body = messageview_get_selection(msgview);
7685 compose_reply_mode((ComposeMode)action, new_msglist, body);
7686 procmsg_msginfo_free(tmp_msginfo);
7687 g_slist_free(new_msglist);
7689 compose_reply_mode((ComposeMode)action, msginfo_list, body);