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)));
1714 font_desc = pango_font_description_from_string
1717 if (bold_style->font_desc)
1718 pango_font_description_free
1719 (bold_style->font_desc);
1720 bold_style->font_desc = font_desc;
1722 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1724 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1729 void compose_toolbar_cb(gint action, gpointer data)
1731 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1732 Compose *compose = (Compose*)toolbar_item->parent;
1734 g_return_if_fail(compose != NULL);
1738 compose_send_cb(compose, 0, NULL);
1741 compose_send_later_cb(compose, 0, NULL);
1744 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1747 compose_insert_file_cb(compose, 0, NULL);
1750 compose_attach_cb(compose, 0, NULL);
1753 compose_insert_sig(compose, FALSE);
1756 compose_ext_editor_cb(compose, 0, NULL);
1758 case A_LINEWRAP_CURRENT:
1759 compose_wrap_paragraph(compose, NULL, TRUE);
1761 case A_LINEWRAP_ALL:
1762 compose_wrap_all_full(compose, TRUE);
1765 compose_address_cb(compose, 0, NULL);
1768 case A_CHECK_SPELLING:
1769 compose_check_all(compose);
1777 static void compose_entries_set(Compose *compose, const gchar *mailto)
1781 gchar *subject = NULL;
1786 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1789 compose_entry_append(compose, to, COMPOSE_TO);
1791 compose_entry_append(compose, cc, COMPOSE_CC);
1793 if (!g_utf8_validate (subject, -1, NULL)) {
1794 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1795 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1798 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1802 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1803 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1806 gboolean prev_autowrap = compose->autowrap;
1808 compose->autowrap = FALSE;
1810 mark = gtk_text_buffer_get_insert(buffer);
1811 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1813 if (!g_utf8_validate (body, -1, NULL)) {
1814 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1815 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1818 gtk_text_buffer_insert(buffer, &iter, body, -1);
1820 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1822 compose->autowrap = prev_autowrap;
1823 if (compose->autowrap)
1824 compose_wrap_all(compose);
1833 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1835 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1836 {"Cc:", NULL, TRUE},
1837 {"References:", NULL, FALSE},
1838 {"Bcc:", NULL, TRUE},
1839 {"Newsgroups:", NULL, TRUE},
1840 {"Followup-To:", NULL, TRUE},
1841 {"List-Post:", NULL, FALSE},
1842 {"X-Priority:", NULL, FALSE},
1843 {NULL, NULL, FALSE}};
1859 g_return_val_if_fail(msginfo != NULL, -1);
1861 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1862 procheader_get_header_fields(fp, hentry);
1865 if (hentry[H_REPLY_TO].body != NULL) {
1866 if (hentry[H_REPLY_TO].body[0] != '\0') {
1868 conv_unmime_header(hentry[H_REPLY_TO].body,
1871 g_free(hentry[H_REPLY_TO].body);
1872 hentry[H_REPLY_TO].body = NULL;
1874 if (hentry[H_CC].body != NULL) {
1875 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
1876 g_free(hentry[H_CC].body);
1877 hentry[H_CC].body = NULL;
1879 if (hentry[H_REFERENCES].body != NULL) {
1880 if (compose->mode == COMPOSE_REEDIT)
1881 compose->references = hentry[H_REFERENCES].body;
1883 compose->references = compose_parse_references
1884 (hentry[H_REFERENCES].body, msginfo->msgid);
1885 g_free(hentry[H_REFERENCES].body);
1887 hentry[H_REFERENCES].body = NULL;
1889 if (hentry[H_BCC].body != NULL) {
1890 if (compose->mode == COMPOSE_REEDIT)
1892 conv_unmime_header(hentry[H_BCC].body, NULL);
1893 g_free(hentry[H_BCC].body);
1894 hentry[H_BCC].body = NULL;
1896 if (hentry[H_NEWSGROUPS].body != NULL) {
1897 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1898 hentry[H_NEWSGROUPS].body = NULL;
1900 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1901 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
1902 compose->followup_to =
1903 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
1906 g_free(hentry[H_FOLLOWUP_TO].body);
1907 hentry[H_FOLLOWUP_TO].body = NULL;
1909 if (hentry[H_LIST_POST].body != NULL) {
1912 extract_address(hentry[H_LIST_POST].body);
1913 if (hentry[H_LIST_POST].body[0] != '\0') {
1914 scan_mailto_url(hentry[H_LIST_POST].body,
1915 &to, NULL, NULL, NULL, NULL);
1917 g_free(compose->ml_post);
1918 compose->ml_post = to;
1921 g_free(hentry[H_LIST_POST].body);
1922 hentry[H_LIST_POST].body = NULL;
1925 /* CLAWS - X-Priority */
1926 if (compose->mode == COMPOSE_REEDIT)
1927 if (hentry[H_X_PRIORITY].body != NULL) {
1930 priority = atoi(hentry[H_X_PRIORITY].body);
1931 g_free(hentry[H_X_PRIORITY].body);
1933 hentry[H_X_PRIORITY].body = NULL;
1935 if (priority < PRIORITY_HIGHEST ||
1936 priority > PRIORITY_LOWEST)
1937 priority = PRIORITY_NORMAL;
1939 compose->priority = priority;
1942 if (compose->mode == COMPOSE_REEDIT) {
1943 if (msginfo->inreplyto && *msginfo->inreplyto)
1944 compose->inreplyto = g_strdup(msginfo->inreplyto);
1948 if (msginfo->msgid && *msginfo->msgid)
1949 compose->inreplyto = g_strdup(msginfo->msgid);
1951 if (!compose->references) {
1952 if (msginfo->msgid && *msginfo->msgid) {
1953 if (msginfo->inreplyto && *msginfo->inreplyto)
1954 compose->references =
1955 g_strdup_printf("<%s>\n\t<%s>",
1959 compose->references =
1960 g_strconcat("<", msginfo->msgid, ">",
1962 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
1963 compose->references =
1964 g_strconcat("<", msginfo->inreplyto, ">",
1972 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1974 GSList *ref_id_list, *cur;
1978 ref_id_list = references_list_append(NULL, ref);
1979 if (!ref_id_list) return NULL;
1980 if (msgid && *msgid)
1981 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1986 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1987 /* "<" + Message-ID + ">" + CR+LF+TAB */
1988 len += strlen((gchar *)cur->data) + 5;
1990 if (len > MAX_REFERENCES_LEN) {
1991 /* remove second message-ID */
1992 if (ref_id_list && ref_id_list->next &&
1993 ref_id_list->next->next) {
1994 g_free(ref_id_list->next->data);
1995 ref_id_list = g_slist_remove
1996 (ref_id_list, ref_id_list->next->data);
1998 slist_free_strings(ref_id_list);
1999 g_slist_free(ref_id_list);
2006 new_ref = g_string_new("");
2007 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2008 if (new_ref->len > 0)
2009 g_string_append(new_ref, "\n\t");
2010 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2013 slist_free_strings(ref_id_list);
2014 g_slist_free(ref_id_list);
2016 new_ref_str = new_ref->str;
2017 g_string_free(new_ref, FALSE);
2022 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2023 const gchar *fmt, const gchar *qmark,
2026 static MsgInfo dummyinfo;
2027 gchar *quote_str = NULL;
2031 gboolean prev_autowrap;
2032 const gchar *trimmed_body = body;
2033 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2034 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2037 msginfo = &dummyinfo;
2039 if (qmark != NULL) {
2040 quote_fmt_init(msginfo, NULL, NULL);
2041 quote_fmt_scan_string(qmark);
2044 buf = quote_fmt_get_buffer();
2046 alertpanel_error(_("Quote mark format error."));
2048 Xstrdup_a(quote_str, buf, return NULL)
2051 if (fmt && *fmt != '\0') {
2052 while (trimmed_body && strlen(trimmed_body) > 1
2053 && trimmed_body[0]=='\n')
2056 quote_fmt_init(msginfo, quote_str, trimmed_body);
2057 quote_fmt_scan_string(fmt);
2060 buf = quote_fmt_get_buffer();
2062 alertpanel_error(_("Message reply/forward format error."));
2068 prev_autowrap = compose->autowrap;
2069 compose->autowrap = FALSE;
2071 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2072 G_CALLBACK(compose_changed_cb),
2074 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2075 G_CALLBACK(text_inserted),
2077 for (p = buf; *p != '\0'; ) {
2082 mark = gtk_text_buffer_get_insert(buffer);
2083 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2085 lastp = strchr(p, '\n');
2086 len = lastp ? lastp - p + 1 : -1;
2088 gtk_text_buffer_insert(buffer, &iter, p, len);
2096 compose->autowrap = prev_autowrap;
2097 if (compose->autowrap)
2098 compose_wrap_all(compose);
2100 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2101 G_CALLBACK(compose_changed_cb),
2103 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2104 G_CALLBACK(text_inserted),
2111 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2112 gboolean to_all, gboolean to_ml,
2114 gboolean followup_and_reply_to)
2116 GSList *cc_list = NULL;
2119 gchar *replyto = NULL;
2120 GHashTable *to_table;
2122 g_return_if_fail(compose->account != NULL);
2123 g_return_if_fail(msginfo != NULL);
2125 if (compose->account->protocol != A_NNTP) {
2126 if (!compose->replyto && to_ml && compose->ml_post
2127 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
2128 compose_entry_append(compose,
2131 else if (!(to_all || to_sender)
2133 && msginfo->folder->prefs->enable_default_reply_to) {
2134 compose_entry_append(compose,
2135 msginfo->folder->prefs->default_reply_to,
2138 compose_entry_append(compose,
2139 (compose->replyto && !to_sender)
2140 ? compose->replyto :
2141 msginfo->from ? msginfo->from : "",
2144 if (to_sender || (compose->followup_to &&
2145 !strncmp(compose->followup_to, "poster", 6)))
2146 compose_entry_append
2148 (compose->replyto ? compose->replyto :
2149 msginfo->from ? msginfo->from : ""),
2152 else if (followup_and_reply_to || to_all) {
2153 compose_entry_append
2155 (compose->replyto ? compose->replyto :
2156 msginfo->from ? msginfo->from : ""),
2159 compose_entry_append
2161 compose->followup_to ? compose->followup_to :
2162 compose->newsgroups ? compose->newsgroups : "",
2163 COMPOSE_NEWSGROUPS);
2166 compose_entry_append
2168 compose->followup_to ? compose->followup_to :
2169 compose->newsgroups ? compose->newsgroups : "",
2170 COMPOSE_NEWSGROUPS);
2173 if (msginfo->subject && *msginfo->subject) {
2177 buf = p = g_strdup(msginfo->subject);
2178 p += subject_get_prefix_length(p);
2179 memmove(buf, p, strlen(p) + 1);
2181 buf2 = g_strdup_printf("Re: %s", buf);
2182 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2187 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2189 if (to_ml && compose->ml_post) return;
2190 if (!to_all || compose->account->protocol == A_NNTP) return;
2192 if (compose->replyto) {
2193 Xstrdup_a(replyto, compose->replyto, return);
2194 extract_address(replyto);
2196 if (msginfo->from) {
2197 Xstrdup_a(from, msginfo->from, return);
2198 extract_address(from);
2201 if (replyto && from)
2202 cc_list = address_list_append_with_comments(cc_list, from);
2203 if (to_all && msginfo->folder &&
2204 msginfo->folder->prefs->enable_default_reply_to)
2205 cc_list = address_list_append_with_comments(cc_list,
2206 msginfo->folder->prefs->default_reply_to);
2207 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2208 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2210 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2212 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2213 if (compose->account)
2214 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2215 GINT_TO_POINTER(1));
2217 /* remove address on To: and that of current account */
2218 for (cur = cc_list; cur != NULL; ) {
2219 GSList *next = cur->next;
2222 addr = g_strdup(cur->data);
2223 extract_address(addr);
2225 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2226 cc_list = g_slist_remove(cc_list, cur->data);
2228 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2232 hash_free_strings(to_table);
2233 g_hash_table_destroy(to_table);
2236 for (cur = cc_list; cur != NULL; cur = cur->next)
2237 compose_entry_append(compose, (gchar *)cur->data,
2239 slist_free_strings(cc_list);
2240 g_slist_free(cc_list);
2245 #define SET_ENTRY(entry, str) \
2248 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2251 #define SET_ADDRESS(type, str) \
2254 compose_entry_append(compose, str, type); \
2257 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2259 g_return_if_fail(msginfo != NULL);
2261 SET_ENTRY(subject_entry, msginfo->subject);
2262 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2263 SET_ADDRESS(COMPOSE_CC, compose->cc);
2264 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2265 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2266 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2267 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2269 compose_update_priority_menu_item(compose);
2270 compose_update_privacy_system_menu_item(compose);
2271 compose_show_first_last_header(compose, TRUE);
2277 static void compose_insert_sig(Compose *compose, gboolean replace)
2279 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2280 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2282 GtkTextIter iter, iter_end;
2284 gboolean prev_autowrap;
2287 g_return_if_fail(compose->account != NULL);
2289 prev_autowrap = compose->autowrap;
2290 compose->autowrap = FALSE;
2292 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2293 G_CALLBACK(compose_changed_cb),
2296 mark = gtk_text_buffer_get_insert(buffer);
2297 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2298 cur_pos = gtk_text_iter_get_offset (&iter);
2300 gtk_text_buffer_get_end_iter(buffer, &iter);
2302 if (replace && compose->sig_str) {
2304 GtkTextIter first_iter, start_iter, end_iter;
2306 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2308 if (compose->sig_str[0] == '\0')
2311 found = gtk_text_iter_forward_search(&first_iter,
2313 GTK_TEXT_SEARCH_TEXT_ONLY,
2314 &start_iter, &end_iter,
2318 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2323 g_free(compose->sig_str);
2324 compose->sig_str = compose_get_signature_str(compose);
2325 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2326 compose->sig_str = g_strdup("");
2328 cur_pos = gtk_text_iter_get_offset(&iter);
2329 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2331 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2332 gtk_text_iter_forward_char(&iter);
2333 gtk_text_iter_forward_char(&iter);
2334 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2335 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2337 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2338 cur_pos = gtk_text_buffer_get_char_count (buffer);
2340 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2341 gtk_text_buffer_place_cursor(buffer, &iter);
2343 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2344 G_CALLBACK(compose_changed_cb),
2347 compose->autowrap = prev_autowrap;
2348 if (compose->autowrap)
2349 compose_wrap_all(compose);
2352 static gchar *compose_get_signature_str(Compose *compose)
2354 gchar *sig_body = NULL;
2355 gchar *sig_str = NULL;
2356 gchar *utf8_sig_str = NULL;
2358 g_return_val_if_fail(compose->account != NULL, NULL);
2360 if (!compose->account->sig_path)
2363 if (compose->account->sig_type == SIG_FILE) {
2364 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2365 g_warning("can't open signature file: %s\n",
2366 compose->account->sig_path);
2371 if (compose->account->sig_type == SIG_COMMAND)
2372 sig_body = get_command_output(compose->account->sig_path);
2376 tmp = file_read_to_str(compose->account->sig_path);
2379 sig_body = normalize_newlines(tmp);
2383 if (compose->account->sig_sep) {
2384 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2388 sig_str = g_strconcat("\n\n", sig_body, NULL);
2391 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2392 utf8_sig_str = sig_str;
2394 utf8_sig_str = conv_codeset_strdup
2395 (sig_str, conv_get_locale_charset_str(),
2401 return utf8_sig_str;
2404 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2407 GtkTextBuffer *buffer;
2410 const gchar *cur_encoding;
2411 gchar buf[BUFFSIZE];
2414 gboolean prev_autowrap;
2415 gboolean badtxt = FALSE;
2417 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2419 if ((fp = g_fopen(file, "rb")) == NULL) {
2420 FILE_OP_ERROR(file, "fopen");
2421 return COMPOSE_INSERT_READ_ERROR;
2424 prev_autowrap = compose->autowrap;
2425 compose->autowrap = FALSE;
2427 text = GTK_TEXT_VIEW(compose->text);
2428 buffer = gtk_text_view_get_buffer(text);
2429 mark = gtk_text_buffer_get_insert(buffer);
2430 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2432 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2433 G_CALLBACK(text_inserted),
2436 cur_encoding = conv_get_locale_charset_str();
2438 while (fgets(buf, sizeof(buf), fp) != NULL) {
2441 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2442 str = g_strdup(buf);
2444 str = conv_codeset_strdup
2445 (buf, cur_encoding, CS_INTERNAL);
2448 /* strip <CR> if DOS/Windows file,
2449 replace <CR> with <LF> if Macintosh file. */
2452 if (len > 0 && str[len - 1] != '\n') {
2454 if (str[len] == '\r') str[len] = '\n';
2457 gtk_text_buffer_insert(buffer, &iter, str, -1);
2461 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2462 G_CALLBACK(text_inserted),
2464 compose->autowrap = prev_autowrap;
2465 if (compose->autowrap)
2466 compose_wrap_all(compose);
2471 return COMPOSE_INSERT_INVALID_CHARACTER;
2473 return COMPOSE_INSERT_SUCCESS;
2476 static void compose_attach_append(Compose *compose, const gchar *file,
2477 const gchar *filename,
2478 const gchar *content_type)
2486 GtkListStore *store;
2489 if (!is_file_exist(file)) {
2490 g_warning("File %s doesn't exist\n", filename);
2493 if ((size = get_file_size(file)) < 0) {
2494 g_warning("Can't get file size of %s\n", filename);
2498 alertpanel_notice(_("File %s is empty."), filename);
2501 if ((fp = g_fopen(file, "rb")) == NULL) {
2502 alertpanel_error(_("Can't read %s."), filename);
2507 ainfo = g_new0(AttachInfo, 1);
2508 auto_ainfo = g_auto_pointer_new_with_free
2509 (ainfo, (GFreeFunc) compose_attach_info_free);
2510 ainfo->file = g_strdup(file);
2513 ainfo->content_type = g_strdup(content_type);
2514 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2516 MsgFlags flags = {0, 0};
2518 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2519 ainfo->encoding = ENC_7BIT;
2521 ainfo->encoding = ENC_8BIT;
2523 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2524 if (msginfo && msginfo->subject)
2525 name = g_strdup(msginfo->subject);
2527 name = g_path_get_basename(filename ? filename : file);
2529 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2531 procmsg_msginfo_free(msginfo);
2533 if (!g_ascii_strncasecmp(content_type, "text", 4))
2534 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2536 ainfo->encoding = ENC_BASE64;
2537 name = g_path_get_basename(filename ? filename : file);
2538 ainfo->name = g_strdup(name);
2542 ainfo->content_type = procmime_get_mime_type(file);
2543 if (!ainfo->content_type) {
2544 ainfo->content_type =
2545 g_strdup("application/octet-stream");
2546 ainfo->encoding = ENC_BASE64;
2547 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2549 procmime_get_encoding_for_text_file(file);
2551 ainfo->encoding = ENC_BASE64;
2552 name = g_path_get_basename(filename ? filename : file);
2553 ainfo->name = g_strdup(name);
2557 if (!strcmp(ainfo->content_type, "unknown")) {
2558 g_free(ainfo->content_type);
2559 ainfo->content_type = g_strdup("application/octet-stream");
2563 size_text = to_human_readable(size);
2565 store = GTK_LIST_STORE(gtk_tree_view_get_model
2566 (GTK_TREE_VIEW(compose->attach_clist)));
2568 gtk_list_store_append(store, &iter);
2569 gtk_list_store_set(store, &iter,
2570 COL_MIMETYPE, ainfo->content_type,
2571 COL_SIZE, size_text,
2572 COL_NAME, ainfo->name,
2574 COL_AUTODATA, auto_ainfo,
2577 g_auto_pointer_free(auto_ainfo);
2580 static void compose_use_signing(Compose *compose, gboolean use_signing)
2582 GtkItemFactory *ifactory;
2583 GtkWidget *menuitem = NULL;
2585 compose->use_signing = use_signing;
2586 ifactory = gtk_item_factory_from_widget(compose->menubar);
2587 menuitem = gtk_item_factory_get_item
2588 (ifactory, "/Options/Sign");
2589 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2593 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2595 GtkItemFactory *ifactory;
2596 GtkWidget *menuitem = NULL;
2598 compose->use_encryption = use_encryption;
2599 ifactory = gtk_item_factory_from_widget(compose->menubar);
2600 menuitem = gtk_item_factory_get_item
2601 (ifactory, "/Options/Encrypt");
2603 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2607 #define NEXT_PART_NOT_CHILD(info) \
2609 node = info->node; \
2610 while (node->children) \
2611 node = g_node_last_child(node); \
2612 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2615 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2619 MimeInfo *firsttext = NULL;
2620 MimeInfo *encrypted = NULL;
2623 const gchar *partname = NULL;
2625 mimeinfo = procmime_scan_message(msginfo);
2626 if (!mimeinfo) return;
2628 if (mimeinfo->node->children == NULL) {
2629 procmime_mimeinfo_free_all(mimeinfo);
2633 /* find first content part */
2634 child = (MimeInfo *) mimeinfo->node->children->data;
2635 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2636 child = (MimeInfo *)child->node->children->data;
2638 if (child->type == MIMETYPE_TEXT) {
2640 debug_print("First text part found\n");
2641 } else if (compose->mode == COMPOSE_REEDIT &&
2642 child->type == MIMETYPE_APPLICATION &&
2643 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2644 encrypted = (MimeInfo *)child->node->parent->data;
2647 child = (MimeInfo *) mimeinfo->node->children->data;
2648 while (child != NULL) {
2649 if (child == encrypted) {
2650 /* skip this part of tree */
2651 NEXT_PART_NOT_CHILD(child);
2655 if (child->type == MIMETYPE_MULTIPART) {
2656 /* get the actual content */
2657 child = procmime_mimeinfo_next(child);
2661 if (child == firsttext) {
2662 child = procmime_mimeinfo_next(child);
2666 outfile = procmime_get_tmp_file_name(child);
2667 if (procmime_get_part(outfile, child) < 0)
2668 g_warning("Can't get the part of multipart message.");
2670 gchar *content_type;
2672 content_type = procmime_get_content_type_str(child->type, child->subtype);
2674 /* if we meet a pgp signature, we don't attach it, but
2675 * we force signing. */
2676 if (strcmp(content_type, "application/pgp-signature")) {
2677 partname = procmime_mimeinfo_get_parameter(child, "filename");
2678 if (partname == NULL)
2679 partname = procmime_mimeinfo_get_parameter(child, "name");
2680 if (partname == NULL)
2682 compose_attach_append(compose, outfile,
2683 partname, content_type);
2685 compose_force_signing(compose, compose->account);
2687 g_free(content_type);
2690 NEXT_PART_NOT_CHILD(child);
2692 procmime_mimeinfo_free_all(mimeinfo);
2695 #undef NEXT_PART_NOT_CHILD
2700 WAIT_FOR_INDENT_CHAR,
2701 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2704 /* return indent length, we allow:
2705 indent characters followed by indent characters or spaces/tabs,
2706 alphabets and numbers immediately followed by indent characters,
2707 and the repeating sequences of the above
2708 If quote ends with multiple spaces, only the first one is included. */
2709 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2710 const GtkTextIter *start, gint *len)
2712 GtkTextIter iter = *start;
2716 IndentState state = WAIT_FOR_INDENT_CHAR;
2719 gint alnum_count = 0;
2720 gint space_count = 0;
2723 if (prefs_common.quote_chars == NULL) {
2727 while (!gtk_text_iter_ends_line(&iter)) {
2728 wc = gtk_text_iter_get_char(&iter);
2729 if (g_unichar_iswide(wc))
2731 clen = g_unichar_to_utf8(wc, ch);
2735 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2736 is_space = g_unichar_isspace(wc);
2738 if (state == WAIT_FOR_INDENT_CHAR) {
2739 if (!is_indent && !g_unichar_isalnum(wc))
2742 quote_len += alnum_count + space_count + 1;
2743 alnum_count = space_count = 0;
2744 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2747 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2748 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
2752 else if (is_indent) {
2753 quote_len += alnum_count + space_count + 1;
2754 alnum_count = space_count = 0;
2757 state = WAIT_FOR_INDENT_CHAR;
2761 gtk_text_iter_forward_char(&iter);
2764 if (quote_len > 0 && space_count > 0)
2770 if (quote_len > 0) {
2772 gtk_text_iter_forward_chars(&iter, quote_len);
2773 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
2779 /* return TRUE if the line is itemized */
2780 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
2781 const GtkTextIter *start)
2783 GtkTextIter iter = *start;
2788 if (gtk_text_iter_ends_line(&iter))
2792 wc = gtk_text_iter_get_char(&iter);
2793 if (!g_unichar_isspace(wc))
2795 gtk_text_iter_forward_char(&iter);
2796 if (gtk_text_iter_ends_line(&iter))
2800 clen = g_unichar_to_utf8(wc, ch);
2804 if (!strchr("*-+", ch[0]))
2807 gtk_text_iter_forward_char(&iter);
2808 if (gtk_text_iter_ends_line(&iter))
2810 wc = gtk_text_iter_get_char(&iter);
2811 if (g_unichar_isspace(wc))
2817 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
2818 const GtkTextIter *start,
2819 GtkTextIter *break_pos,
2823 GtkTextIter iter = *start, line_end = *start;
2824 PangoLogAttr *attrs;
2831 gboolean can_break = FALSE;
2832 gboolean do_break = FALSE;
2833 gboolean was_white = FALSE;
2834 gboolean prev_dont_break = FALSE;
2836 gtk_text_iter_forward_to_line_end(&line_end);
2837 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
2838 len = g_utf8_strlen(str, -1);
2839 /* g_print("breaking line: %d: %s (len = %d)\n",
2840 gtk_text_iter_get_line(&iter), str, len); */
2841 attrs = g_new(PangoLogAttr, len + 1);
2843 pango_default_break(str, -1, NULL, attrs, len + 1);
2847 /* skip quote and leading spaces */
2848 for (i = 0; *p != '\0' && i < len; i++) {
2851 wc = g_utf8_get_char(p);
2852 if (i >= quote_len && !g_unichar_isspace(wc))
2854 if (g_unichar_iswide(wc))
2856 else if (*p == '\t')
2860 p = g_utf8_next_char(p);
2863 for (; *p != '\0' && i < len; i++) {
2864 PangoLogAttr *attr = attrs + i;
2868 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
2871 was_white = attr->is_white;
2873 /* don't wrap URI */
2874 if ((uri_len = get_uri_len(p)) > 0) {
2876 if (pos > 0 && col > max_col) {
2886 wc = g_utf8_get_char(p);
2887 if (g_unichar_iswide(wc)) {
2889 if (prev_dont_break && can_break && attr->is_line_break)
2891 } else if (*p == '\t')
2895 if (pos > 0 && col > max_col) {
2900 if (*p == '-' || *p == '/')
2901 prev_dont_break = TRUE;
2903 prev_dont_break = FALSE;
2905 p = g_utf8_next_char(p);
2909 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
2914 *break_pos = *start;
2915 gtk_text_iter_set_line_offset(break_pos, pos);
2920 static gboolean compose_join_next_line(Compose *compose,
2921 GtkTextBuffer *buffer,
2923 const gchar *quote_str)
2925 GtkTextIter iter_ = *iter, cur, prev, next, end;
2926 PangoLogAttr attrs[3];
2928 gchar *next_quote_str;
2931 gboolean keep_cursor = FALSE;
2933 if (!gtk_text_iter_forward_line(&iter_) ||
2934 gtk_text_iter_ends_line(&iter_))
2937 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
2939 if ((quote_str || next_quote_str) &&
2940 strcmp2(quote_str, next_quote_str) != 0) {
2941 g_free(next_quote_str);
2944 g_free(next_quote_str);
2947 if (quote_len > 0) {
2948 gtk_text_iter_forward_chars(&end, quote_len);
2949 if (gtk_text_iter_ends_line(&end))
2953 /* don't join itemized lines */
2954 if (compose_is_itemized(buffer, &end))
2957 /* don't join signature separator */
2958 if (compose_is_sig_separator(compose, buffer, &iter_))
2961 /* delete quote str */
2963 gtk_text_buffer_delete(buffer, &iter_, &end);
2965 /* delete linebreak and extra spaces */
2967 while (gtk_text_iter_backward_char(&cur)) {
2968 wc1 = gtk_text_iter_get_char(&cur);
2969 if (!g_unichar_isspace(wc1))
2974 while (!gtk_text_iter_ends_line(&cur)) {
2975 wc1 = gtk_text_iter_get_char(&cur);
2976 if (!g_unichar_isspace(wc1))
2978 gtk_text_iter_forward_char(&cur);
2981 if (!gtk_text_iter_equal(&prev, &next)) {
2984 mark = gtk_text_buffer_get_insert(buffer);
2985 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
2986 if (gtk_text_iter_equal(&prev, &cur))
2988 gtk_text_buffer_delete(buffer, &prev, &next);
2992 /* insert space if required */
2993 gtk_text_iter_backward_char(&prev);
2994 wc1 = gtk_text_iter_get_char(&prev);
2995 wc2 = gtk_text_iter_get_char(&next);
2996 gtk_text_iter_forward_char(&next);
2997 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
2998 pango_default_break(str, -1, NULL, attrs, 3);
2999 if (!attrs[1].is_line_break ||
3000 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3001 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3003 gtk_text_iter_backward_char(&iter_);
3004 gtk_text_buffer_place_cursor(buffer, &iter_);
3013 #define ADD_TXT_POS(bp_, ep_, pti_) \
3014 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3015 last = last->next; \
3016 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3017 last->next = NULL; \
3019 g_warning("alloc error scanning URIs\n"); \
3022 static void compose_wrap_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3024 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3025 GtkTextBuffer *buffer;
3026 GtkTextIter iter, break_pos, end_of_line;
3027 gchar *quote_str = NULL;
3029 gboolean wrap_quote = prefs_common.linewrap_quote;
3030 gboolean prev_autowrap = compose->autowrap;
3031 gint startq_offset = -1, noq_offset = -1;
3032 gint uri_start = -1, uri_stop = -1;
3033 gint nouri_start = -1, nouri_stop = -1;
3035 compose->autowrap = FALSE;
3037 buffer = gtk_text_view_get_buffer(text);
3039 undo_block(compose->undostruct);
3045 mark = gtk_text_buffer_get_insert(buffer);
3046 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3049 /* move to paragraph start */
3050 gtk_text_iter_set_line_offset(&iter, 0);
3051 if (gtk_text_iter_ends_line(&iter)) {
3052 while (gtk_text_iter_ends_line(&iter) &&
3053 gtk_text_iter_forward_line(&iter))
3056 while (gtk_text_iter_backward_line(&iter)) {
3057 if (gtk_text_iter_ends_line(&iter)) {
3058 gtk_text_iter_forward_line(&iter);
3064 /* go until paragraph end (empty line) */
3065 while (!gtk_text_iter_ends_line(&iter)) {
3066 gchar *scanpos = NULL;
3067 /* parse table - in order of priority */
3069 const gchar *needle; /* token */
3071 /* token search function */
3072 gchar *(*search) (const gchar *haystack,
3073 const gchar *needle);
3074 /* part parsing function */
3075 gboolean (*parse) (const gchar *start,
3076 const gchar *scanpos,
3079 /* part to URI function */
3080 gchar *(*build_uri) (const gchar *bp,
3084 static struct table parser[] = {
3085 {"http://", strcasestr, get_uri_part, make_uri_string},
3086 {"https://", strcasestr, get_uri_part, make_uri_string},
3087 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3088 {"www.", strcasestr, get_uri_part, make_http_string},
3089 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3090 {"@", strcasestr, get_email_part, make_email_string}
3092 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3093 gint last_index = PARSE_ELEMS;
3095 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3098 if (gtk_text_iter_has_tag(&iter, no_wrap_tag) && !force)
3101 uri_start = uri_stop = -1;
3102 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3106 if (startq_offset == -1) {
3107 startq_offset = gtk_text_iter_get_offset(&iter);
3111 debug_print("compose_wrap_paragraph(): quote_str = '%s'\n", quote_str);
3112 startq_offset = gtk_text_iter_get_offset(&iter);
3114 if (startq_offset == -1)
3115 noq_offset = gtk_text_iter_get_offset(&iter);
3118 if (prev_autowrap == FALSE && !force) {
3121 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3122 prefs_common.linewrap_len,
3124 GtkTextIter prev, next, cur;
3126 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3128 /* remove trailing spaces */
3130 gtk_text_iter_backward_char(&cur);
3132 while (!gtk_text_iter_starts_line(&cur)) {
3135 gtk_text_iter_backward_char(&cur);
3136 wc = gtk_text_iter_get_char(&cur);
3137 if (!g_unichar_isspace(wc))
3141 if (!gtk_text_iter_equal(&prev, &next)) {
3142 gtk_text_buffer_delete(buffer, &prev, &next);
3144 gtk_text_iter_forward_char(&break_pos);
3148 gtk_text_buffer_insert(buffer, &break_pos,
3152 compose_join_next_line(compose, buffer, &iter, quote_str);
3154 /* move iter to current line start */
3155 gtk_text_iter_set_line_offset(&iter, 0);
3158 /* move iter to next line start */
3164 while (!gtk_text_iter_ends_line(&end_of_line)) {
3165 gtk_text_iter_forward_char(&end_of_line);
3167 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3169 nouri_start = gtk_text_iter_get_offset(&iter);
3170 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3172 walk_pos = gtk_text_iter_get_offset(&iter);
3173 /* FIXME: this looks phony. scanning for anything in the parse table */
3174 for (n = 0; n < PARSE_ELEMS; n++) {
3177 tmp = parser[n].search(walk, parser[n].needle);
3179 if (scanpos == NULL || tmp < scanpos) {
3188 /* check if URI can be parsed */
3189 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,(const gchar **)&ep)
3190 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3194 strlen(parser[last_index].needle);
3197 uri_start = walk_pos + (bp - o_walk);
3198 uri_stop = walk_pos + (ep - o_walk);
3202 gtk_text_iter_forward_line(&iter);
3205 if (startq_offset != -1) {
3206 GtkTextIter startquote, endquote;
3207 gtk_text_buffer_get_iter_at_offset(
3208 buffer, &startquote, startq_offset);
3210 gtk_text_buffer_apply_tag_by_name(
3211 buffer, "quote", &startquote, &endquote);
3213 } else if (noq_offset != -1) {
3214 GtkTextIter startnoquote, endnoquote;
3215 gtk_text_buffer_get_iter_at_offset(
3216 buffer, &startnoquote, noq_offset);
3218 gtk_text_buffer_remove_tag_by_name(
3219 buffer, "quote", &startnoquote, &endnoquote);
3224 GtkTextIter nouri_start_iter, nouri_end_iter;
3225 gtk_text_buffer_get_iter_at_offset(
3226 buffer, &nouri_start_iter, nouri_start);
3227 gtk_text_buffer_get_iter_at_offset(
3228 buffer, &nouri_end_iter, nouri_stop);
3229 gtk_text_buffer_remove_tag_by_name(
3230 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3232 if (uri_start > 0 && uri_stop > 0) {
3233 GtkTextIter uri_start_iter, uri_end_iter;
3234 gtk_text_buffer_get_iter_at_offset(
3235 buffer, &uri_start_iter, uri_start);
3236 gtk_text_buffer_get_iter_at_offset(
3237 buffer, &uri_end_iter, uri_stop);
3238 gtk_text_buffer_apply_tag_by_name(
3239 buffer, "link", &uri_start_iter, &uri_end_iter);
3246 undo_unblock(compose->undostruct);
3247 compose->autowrap = prev_autowrap;
3250 static void compose_wrap_all(Compose *compose)
3252 compose_wrap_all_full(compose, FALSE);
3255 static void compose_wrap_all_full(Compose *compose, gboolean force)
3257 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3258 GtkTextBuffer *buffer;
3261 buffer = gtk_text_view_get_buffer(text);
3263 undo_block(compose->undostruct);
3265 gtk_text_buffer_get_start_iter(buffer, &iter);
3266 while (!gtk_text_iter_is_end(&iter))
3267 compose_wrap_paragraph(compose, &iter, force);
3269 undo_unblock(compose->undostruct);
3272 static void compose_set_title(Compose *compose)
3277 edited = compose->modified ? _(" [Edited]") : "";
3278 if (compose->account && compose->account->address)
3279 str = g_strdup_printf(_("%s - Compose message%s"),
3280 compose->account->address, edited);
3282 str = g_strdup_printf(_("Compose message%s"), edited);
3283 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3288 * compose_current_mail_account:
3290 * Find a current mail account (the currently selected account, or the
3291 * default account, if a news account is currently selected). If a
3292 * mail account cannot be found, display an error message.
3294 * Return value: Mail account, or NULL if not found.
3296 static PrefsAccount *
3297 compose_current_mail_account(void)
3301 if (cur_account && cur_account->protocol != A_NNTP)
3304 ac = account_get_default();
3305 if (!ac || ac->protocol == A_NNTP) {
3306 alertpanel_error(_("Account for sending mail is not specified.\n"
3307 "Please select a mail account before sending."));
3314 static void compose_select_account(Compose *compose, PrefsAccount *account,
3317 GtkItemFactory *ifactory;
3319 g_return_if_fail(account != NULL);
3321 compose->account = account;
3323 compose_set_title(compose);
3325 ifactory = gtk_item_factory_from_widget(compose->menubar);
3327 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3328 menu_set_active(ifactory, "/Options/Sign", TRUE);
3330 menu_set_active(ifactory, "/Options/Sign", FALSE);
3331 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3332 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3334 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3336 activate_privacy_system(compose, account);
3338 if (!init && compose->mode != COMPOSE_REDIRECT)
3339 compose_insert_sig(compose, TRUE);
3342 gboolean compose_check_for_valid_recipient(Compose *compose) {
3343 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3344 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3345 gboolean recipient_found = FALSE;
3349 /* free to and newsgroup list */
3350 slist_free_strings(compose->to_list);
3351 g_slist_free(compose->to_list);
3352 compose->to_list = NULL;
3354 slist_free_strings(compose->newsgroup_list);
3355 g_slist_free(compose->newsgroup_list);
3356 compose->newsgroup_list = NULL;
3358 /* search header entries for to and newsgroup entries */
3359 for (list = compose->header_list; list; list = list->next) {
3362 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3363 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3365 if (entry[0] != '\0') {
3366 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3367 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3368 compose->to_list = address_list_append(compose->to_list, entry);
3369 recipient_found = TRUE;
3372 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3373 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3374 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3375 recipient_found = TRUE;
3382 return recipient_found;
3385 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3389 if (compose_check_for_valid_recipient(compose) == FALSE) {
3390 alertpanel_error(_("Recipient is not specified."));
3394 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3395 if (*str == '\0' && check_subject == TRUE) {
3398 aval = alertpanel(_("Send"),
3399 _("Subject is empty. Send it anyway?"),
3400 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3401 if (aval != G_ALERTDEFAULT)
3408 gint compose_send(Compose *compose)
3415 compose_allow_user_actions (compose, FALSE);
3416 compose->sending = TRUE;
3418 if (compose_check_entries(compose, TRUE) == FALSE)
3421 val = compose_queue(compose, &msgnum, &folder);
3425 alertpanel_error(_("Could not queue message for sending:\n\n"
3426 "Signature failed."));
3427 } else if (val == -2) {
3428 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3430 alertpanel_error(_("Could not queue message for sending."));
3436 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3437 compose->sending = FALSE;
3438 compose_close(compose);
3439 /* No more compose access in the normal codepath
3440 * after this point! */
3445 alertpanel_error(_("The message was queued but could not be "
3446 "sent.\nUse \"Send queued messages\" from "
3447 "the main window to retry."));
3448 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3449 compose->sending = FALSE;
3450 compose_allow_user_actions (compose, TRUE);
3455 msgpath = folder_item_fetch_msg(folder, msgnum);
3456 val = procmsg_send_message_queue(msgpath);
3459 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3460 compose->sending = FALSE;
3461 compose_allow_user_actions (compose, TRUE);
3463 folder_item_remove_msg(folder, msgnum);
3464 folder_item_scan(folder);
3469 folder_item_remove_msg(folder, msgnum);
3470 folder_item_scan(folder);
3471 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3472 compose_close(compose);
3474 alertpanel_error(_("The message was queued but could not be "
3475 "sent.\nUse \"Send queued messages\" from "
3476 "the main window to retry."));
3477 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3478 compose_allow_user_actions (compose, TRUE);
3479 compose->sending = FALSE;
3487 compose_allow_user_actions (compose, TRUE);
3488 compose->sending = FALSE;
3493 static gboolean compose_use_attach(Compose *compose)
3495 GtkTreeModel *model = gtk_tree_view_get_model
3496 (GTK_TREE_VIEW(compose->attach_clist));
3497 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3500 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3503 gchar buf[BUFFSIZE];
3505 gboolean first_to_address;
3506 gboolean first_cc_address;
3508 ComposeHeaderEntry *headerentry;
3509 const gchar *headerentryname;
3513 debug_print("Writing redirect header\n");
3515 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3516 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3518 first_to_address = TRUE;
3519 for (list = compose->header_list; list; list = list->next) {
3520 headerentry = ((ComposeHeaderEntry *)list->data);
3521 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3523 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3524 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3525 Xstrdup_a(str, entstr, return -1);
3527 if (str[0] != '\0') {
3528 compose_convert_header
3529 (compose, buf, sizeof(buf), str,
3530 strlen("Resent-To") + 2, TRUE);
3532 if (first_to_address) {
3533 fprintf(fp, "Resent-To: ");
3534 first_to_address = FALSE;
3538 fprintf(fp, "%s", buf);
3542 if (!first_to_address) {
3546 first_cc_address = TRUE;
3547 for (list = compose->header_list; list; list = list->next) {
3548 headerentry = ((ComposeHeaderEntry *)list->data);
3549 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3551 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3552 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3553 Xstrdup_a(str, strg, return -1);
3555 if (str[0] != '\0') {
3556 compose_convert_header
3557 (compose, buf, sizeof(buf), str,
3558 strlen("Resent-Cc") + 2, TRUE);
3560 if (first_cc_address) {
3561 fprintf(fp, "Resent-Cc: ");
3562 first_cc_address = FALSE;
3566 fprintf(fp, "%s", buf);
3570 if (!first_cc_address) {
3577 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3579 gchar buf[BUFFSIZE];
3581 const gchar *entstr;
3582 /* struct utsname utsbuf; */
3584 g_return_val_if_fail(fp != NULL, -1);
3585 g_return_val_if_fail(compose->account != NULL, -1);
3586 g_return_val_if_fail(compose->account->address != NULL, -1);
3589 get_rfc822_date(buf, sizeof(buf));
3590 fprintf(fp, "Resent-Date: %s\n", buf);
3593 if (compose->account->name && *compose->account->name) {
3594 compose_convert_header
3595 (compose, buf, sizeof(buf), compose->account->name,
3596 strlen("From: "), TRUE);
3597 fprintf(fp, "Resent-From: %s <%s>\n",
3598 buf, compose->account->address);
3600 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3603 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3604 if (*entstr != '\0') {
3605 Xstrdup_a(str, entstr, return -1);
3608 compose_convert_header(compose, buf, sizeof(buf), str,
3609 strlen("Subject: "), FALSE);
3610 fprintf(fp, "Subject: %s\n", buf);
3614 /* Resent-Message-ID */
3615 if (compose->account->gen_msgid) {
3616 generate_msgid(buf, sizeof(buf));
3617 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3618 compose->msgid = g_strdup(buf);
3621 compose_redirect_write_headers_from_headerlist(compose, fp);
3623 /* separator between header and body */
3629 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3633 gchar buf[BUFFSIZE];
3635 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
3636 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3640 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3641 /* should filter returnpath, delivered-to */
3642 if (g_ascii_strncasecmp(buf, "Return-Path:",
3643 strlen("Return-Path:")) == 0 ||
3644 g_ascii_strncasecmp(buf, "Delivered-To:",
3645 strlen("Delivered-To:")) == 0 ||
3646 g_ascii_strncasecmp(buf, "Received:",
3647 strlen("Received:")) == 0 ||
3648 g_ascii_strncasecmp(buf, "Subject:",
3649 strlen("Subject:")) == 0 ||
3650 g_ascii_strncasecmp(buf, "X-UIDL:",
3651 strlen("X-UIDL:")) == 0)
3654 if (fputs(buf, fdest) == -1)
3657 if (!prefs_common.redirect_keep_from) {
3658 if (g_ascii_strncasecmp(buf, "From:",
3659 strlen("From:")) == 0) {
3660 fputs(" (by way of ", fdest);
3661 if (compose->account->name
3662 && *compose->account->name) {
3663 compose_convert_header
3664 (compose, buf, sizeof(buf),
3665 compose->account->name,
3668 fprintf(fdest, "%s <%s>",
3670 compose->account->address);
3672 fprintf(fdest, "%s",
3673 compose->account->address);
3678 if (fputs("\n", fdest) == -1)
3682 compose_redirect_write_headers(compose, fdest);
3684 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3685 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
3698 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
3700 GtkTextBuffer *buffer;
3701 GtkTextIter start, end;
3704 const gchar *out_codeset;
3705 EncodingType encoding;
3706 MimeInfo *mimemsg, *mimetext;
3709 /* create message MimeInfo */
3710 mimemsg = procmime_mimeinfo_new();
3711 mimemsg->type = MIMETYPE_MESSAGE;
3712 mimemsg->subtype = g_strdup("rfc822");
3713 mimemsg->content = MIMECONTENT_MEM;
3714 mimemsg->data.mem = compose_get_header(compose);
3716 /* Create text part MimeInfo */
3717 /* get all composed text */
3718 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
3719 gtk_text_buffer_get_start_iter(buffer, &start);
3720 gtk_text_buffer_get_end_iter(buffer, &end);
3721 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
3722 if (is_ascii_str(chars)) {
3725 out_codeset = CS_US_ASCII;
3726 encoding = ENC_7BIT;
3728 const gchar *src_codeset;
3730 out_codeset = conv_get_charset_str(compose->out_encoding);
3732 out_codeset = conv_get_outgoing_charset_str();
3734 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
3735 out_codeset = CS_ISO_8859_1;
3737 if (prefs_common.encoding_method == CTE_BASE64)
3738 encoding = ENC_BASE64;
3739 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3740 encoding = ENC_QUOTED_PRINTABLE;
3741 else if (prefs_common.encoding_method == CTE_8BIT)
3742 encoding = ENC_8BIT;
3744 encoding = procmime_get_encoding_for_charset(out_codeset);
3746 src_codeset = CS_INTERNAL;
3747 /* if current encoding is US-ASCII, set it the same as
3748 outgoing one to prevent code conversion failure */
3749 if (!g_ascii_strcasecmp(src_codeset, CS_US_ASCII))
3750 src_codeset = out_codeset;
3752 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3753 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3755 if (action == COMPOSE_WRITE_FOR_SEND) {
3756 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3762 msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
3764 "Send it anyway?"), src_codeset, out_codeset);
3765 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_YES, GTK_STOCK_NO, NULL, FALSE,
3766 NULL, ALERT_ERROR, G_ALERTALTERNATE);
3769 if (aval != G_ALERTDEFAULT) {
3774 out_codeset = src_codeset;
3780 out_codeset = src_codeset;
3786 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
3787 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
3788 strstr(buf, "\nFrom ") != NULL) {
3789 encoding = ENC_QUOTED_PRINTABLE;
3793 mimetext = procmime_mimeinfo_new();
3794 mimetext->content = MIMECONTENT_MEM;
3795 mimetext->data.mem = buf;
3796 mimetext->type = MIMETYPE_TEXT;
3797 mimetext->subtype = g_strdup("plain");
3798 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
3799 g_strdup(out_codeset));
3800 /* protect trailing spaces when signing message */
3801 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
3802 privacy_system_can_sign(compose->privacy_system)) {
3803 if (encoding == ENC_7BIT)
3804 encoding = ENC_QUOTED_PRINTABLE;
3805 else if (encoding == ENC_8BIT)
3806 encoding = ENC_BASE64;
3809 /* check for line length limit */
3810 if (encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
3811 check_line_length(buf, 1000, &line) < 0) {
3815 msg = g_strdup_printf
3816 (_("Line %d exceeds the line length limit (998 bytes).\n"
3817 "The contents of the message might be broken on the way to the delivery.\n"
3819 "Send it anyway?"), line + 1);
3820 aval = alertpanel(_("Warning"), msg, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
3821 if (aval != G_ALERTDEFAULT) {
3829 if (encoding != ENC_UNKNOWN)
3830 procmime_encode_content(mimetext, encoding);
3832 /* append attachment parts */
3833 if (compose_use_attach(compose)) {
3834 MimeInfo *mimempart;
3836 mimempart = procmime_mimeinfo_new();
3837 mimempart->content = MIMECONTENT_EMPTY;
3838 mimempart->type = MIMETYPE_MULTIPART;
3839 mimempart->subtype = g_strdup("mixed");
3840 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
3841 generate_mime_boundary(NULL));
3843 mimetext->disposition = DISPOSITIONTYPE_INLINE;
3845 g_node_append(mimempart->node, mimetext->node);
3846 g_node_append(mimemsg->node, mimempart->node);
3848 compose_add_attachments(compose, mimempart);
3850 g_node_append(mimemsg->node, mimetext->node);
3852 /* sign message if sending */
3853 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
3854 privacy_system_can_sign(compose->privacy_system))
3855 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
3858 procmime_write_mimeinfo(mimemsg, fp);
3860 procmime_mimeinfo_free_all(mimemsg);
3865 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3867 GtkTextBuffer *buffer;
3868 GtkTextIter start, end;
3873 if ((fp = g_fopen(file, "wb")) == NULL) {
3874 FILE_OP_ERROR(file, "fopen");
3878 /* chmod for security */
3879 if (change_file_mode_rw(fp, file) < 0) {
3880 FILE_OP_ERROR(file, "chmod");
3881 g_warning("can't change file mode\n");
3884 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
3885 gtk_text_buffer_get_start_iter(buffer, &start);
3886 gtk_text_buffer_get_end_iter(buffer, &end);
3887 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
3889 chars = conv_codeset_strdup
3890 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
3893 if (!chars) return -1;
3896 len = strlen(chars);
3897 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3898 FILE_OP_ERROR(file, "fwrite");
3907 if (fclose(fp) == EOF) {
3908 FILE_OP_ERROR(file, "fclose");
3915 static gint compose_remove_reedit_target(Compose *compose)
3918 MsgInfo *msginfo = compose->targetinfo;
3920 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3921 if (!msginfo) return -1;
3923 item = msginfo->folder;
3924 g_return_val_if_fail(item != NULL, -1);
3926 if (procmsg_msg_exist(msginfo) &&
3927 (folder_has_parent_of_type(item, F_QUEUE) ||
3928 folder_has_parent_of_type(item, F_DRAFT)
3929 || msginfo == compose->autosaved_draft)) {
3930 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3931 g_warning("can't remove the old message\n");
3939 void compose_remove_draft(Compose *compose)
3942 MsgInfo *msginfo = compose->targetinfo;
3943 drafts = account_get_special_folder(compose->account, F_DRAFT);
3945 if (procmsg_msg_exist(msginfo)) {
3946 folder_item_remove_msg(drafts, msginfo->msgnum);
3951 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3953 return compose_queue_sub (compose, msgnum, item, FALSE);
3955 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3962 static gboolean lock = FALSE;
3963 PrefsAccount *mailac = NULL, *newsac = NULL;
3965 debug_print("queueing message...\n");
3966 g_return_val_if_fail(compose->account != NULL, -1);
3970 if (compose_check_entries(compose, check_subject) == FALSE) {
3975 if (!compose->to_list && !compose->newsgroup_list) {
3976 g_warning("can't get recipient list.");
3981 if (compose->to_list) {
3982 if (compose->account->protocol != A_NNTP)
3983 mailac = compose->account;
3984 else if (cur_account && cur_account->protocol != A_NNTP)
3985 mailac = cur_account;
3986 else if (!(mailac = compose_current_mail_account())) {
3988 alertpanel_error(_("No account for sending mails available!"));
3993 if (compose->newsgroup_list) {
3994 if (compose->account->protocol == A_NNTP)
3995 newsac = compose->account;
3996 else if (!newsac->protocol != A_NNTP) {
3998 alertpanel_error(_("No account for posting news available!"));
4003 if (prefs_common.linewrap_at_send)
4004 compose_wrap_all(compose);
4006 /* write queue header */
4007 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4008 G_DIR_SEPARATOR, compose);
4009 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4010 FILE_OP_ERROR(tmp, "fopen");
4015 if (change_file_mode_rw(fp, tmp) < 0) {
4016 FILE_OP_ERROR(tmp, "chmod");
4017 g_warning("can't change file mode\n");
4020 /* queueing variables */
4021 fprintf(fp, "AF:\n");
4022 fprintf(fp, "NF:0\n");
4023 fprintf(fp, "PS:10\n");
4024 fprintf(fp, "SRH:1\n");
4025 fprintf(fp, "SFN:\n");
4026 fprintf(fp, "DSR:\n");
4028 fprintf(fp, "MID:<%s>\n", compose->msgid);
4030 fprintf(fp, "MID:\n");
4031 fprintf(fp, "CFG:\n");
4032 fprintf(fp, "PT:0\n");
4033 fprintf(fp, "S:%s\n", compose->account->address);
4034 fprintf(fp, "RQ:\n");
4036 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4038 fprintf(fp, "SSV:\n");
4040 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4042 fprintf(fp, "NSV:\n");
4043 fprintf(fp, "SSH:\n");
4044 /* write recepient list */
4045 if (compose->to_list) {
4046 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4047 for (cur = compose->to_list->next; cur != NULL;
4049 fprintf(fp, ",<%s>", (gchar *)cur->data);
4052 /* write newsgroup list */
4053 if (compose->newsgroup_list) {
4055 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4056 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4057 fprintf(fp, ",%s", (gchar *)cur->data);
4060 /* Sylpheed account IDs */
4062 fprintf(fp, "MAID:%d\n", mailac->account_id);
4064 fprintf(fp, "NAID:%d\n", newsac->account_id);
4066 if (compose->privacy_system != NULL) {
4067 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4068 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4069 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4070 if (compose->use_encryption) {
4073 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4074 if (encdata != NULL)
4075 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4081 /* Save copy folder */
4082 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4083 gchar *savefolderid;
4085 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4086 fprintf(fp, "SCF:%s\n", savefolderid);
4087 g_free(savefolderid);
4089 /* Message-ID of message replying to */
4090 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4093 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4094 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4097 /* Message-ID of message forwarding to */
4098 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4101 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4102 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4107 if (compose->redirect_filename != NULL) {
4108 if (compose_redirect_write_to_file(compose, fp) < 0) {
4117 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4122 return result - 1; /* -2 for a generic error, -3 for signing error */
4126 if (fclose(fp) == EOF) {
4127 FILE_OP_ERROR(tmp, "fclose");
4133 queue = account_get_special_folder(compose->account, F_QUEUE);
4135 g_warning("can't find queue folder\n");
4140 folder_item_scan(queue);
4141 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
4142 g_warning("can't queue the message\n");
4150 if (compose->mode == COMPOSE_REEDIT) {
4151 compose_remove_reedit_target(compose);
4154 if ((msgnum != NULL) && (item != NULL)) {
4162 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4165 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4167 struct stat statbuf;
4168 gchar *type, *subtype;
4169 GtkTreeModel *model;
4172 model = gtk_tree_view_get_model(tree_view);
4174 if (!gtk_tree_model_get_iter_first(model, &iter))
4177 gtk_tree_model_get(model, &iter,
4181 mimepart = procmime_mimeinfo_new();
4182 mimepart->content = MIMECONTENT_FILE;
4183 mimepart->data.filename = g_strdup(ainfo->file);
4184 mimepart->offset = 0;
4186 stat(ainfo->file, &statbuf);
4187 mimepart->length = statbuf.st_size;
4189 type = g_strdup(ainfo->content_type);
4191 if (!strchr(type, '/')) {
4193 type = g_strdup("application/octet-stream");
4196 subtype = strchr(type, '/') + 1;
4197 *(subtype - 1) = '\0';
4198 mimepart->type = procmime_get_media_type(type);
4199 mimepart->subtype = g_strdup(subtype);
4202 if (mimepart->type == MIMETYPE_MESSAGE &&
4203 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4204 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4206 g_hash_table_insert(mimepart->typeparameters,
4207 g_strdup("name"), g_strdup(ainfo->name));
4208 g_hash_table_insert(mimepart->dispositionparameters,
4209 g_strdup("filename"), g_strdup(ainfo->name));
4210 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4213 if (compose->use_signing) {
4214 if (ainfo->encoding == ENC_7BIT)
4215 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4216 else if (ainfo->encoding == ENC_8BIT)
4217 ainfo->encoding = ENC_BASE64;
4220 procmime_encode_content(mimepart, ainfo->encoding);
4222 g_node_append(parent->node, mimepart->node);
4223 } while (gtk_tree_model_iter_next(model, &iter));
4226 #define QUOTE_IF_REQUIRED(out, str) \
4228 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4232 len = strlen(str) + 3; \
4233 if ((__tmp = alloca(len)) == NULL) { \
4234 g_warning("can't allocate memory\n"); \
4235 g_string_free(header, TRUE); \
4238 g_snprintf(__tmp, len, "\"%s\"", str); \
4243 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4244 g_warning("can't allocate memory\n"); \
4245 g_string_free(header, TRUE); \
4248 strcpy(__tmp, str); \
4254 #define IS_IN_CUSTOM_HEADER(header) \
4255 (compose->account->add_customhdr && \
4256 custom_header_find(compose->account->customhdr_list, header) != NULL)
4258 static void compose_add_headerfield_from_headerlist(Compose *compose,
4260 const gchar *fieldname,
4261 const gchar *seperator)
4263 gchar *str, *fieldname_w_colon, *trans_fieldname;
4264 gboolean add_field = FALSE;
4266 ComposeHeaderEntry *headerentry;
4267 const gchar * headerentryname;
4270 if (IS_IN_CUSTOM_HEADER(fieldname))
4273 debug_print("Adding %s-fields\n", fieldname);
4275 fieldstr = g_string_sized_new(64);
4277 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4278 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4280 for (list = compose->header_list; list; list = list->next) {
4281 headerentry = ((ComposeHeaderEntry *)list->data);
4282 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4284 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4285 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4287 if (str[0] != '\0') {
4289 g_string_append(fieldstr, seperator);
4290 g_string_append(fieldstr, str);
4299 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4300 compose_convert_header
4301 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4302 strlen(fieldname) + 2, TRUE);
4303 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4307 g_free(fieldname_w_colon);
4308 g_string_free(fieldstr, TRUE);
4313 static gchar *compose_get_header(Compose *compose)
4315 gchar buf[BUFFSIZE];
4316 const gchar *entry_str;
4320 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4323 g_return_val_if_fail(compose->account != NULL, NULL);
4324 g_return_val_if_fail(compose->account->address != NULL, NULL);
4326 header = g_string_sized_new(64);
4329 if (compose->account->add_date) {
4330 get_rfc822_date(buf, sizeof(buf));
4331 g_string_append_printf(header, "Date: %s\n", buf);
4335 if (compose->account->name && *compose->account->name) {
4336 compose_convert_header
4337 (compose, buf, sizeof(buf), compose->account->name,
4338 strlen("From: "), TRUE);
4339 QUOTE_IF_REQUIRED(name, buf);
4340 g_string_append_printf(header, "From: %s <%s>\n",
4341 name, compose->account->address);
4343 g_string_append_printf(header, "From: %s\n", compose->account->address);
4346 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4349 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4352 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4355 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4358 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4359 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4362 compose_convert_header(compose, buf, sizeof(buf), str,
4363 strlen("Subject: "), FALSE);
4364 g_string_append_printf(header, "Subject: %s\n", buf);
4370 if (compose->account->gen_msgid) {
4371 generate_msgid(buf, sizeof(buf));
4372 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4373 compose->msgid = g_strdup(buf);
4376 if (compose->remove_references == FALSE) {
4378 if (compose->inreplyto && compose->to_list)
4379 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4382 if (compose->references)
4383 g_string_append_printf(header, "References: %s\n", compose->references);
4387 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4390 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4393 if (compose->account->organization &&
4394 strlen(compose->account->organization) &&
4395 !IS_IN_CUSTOM_HEADER("Organization")) {
4396 compose_convert_header(compose, buf, sizeof(buf),
4397 compose->account->organization,
4398 strlen("Organization: "), FALSE);
4399 g_string_append_printf(header, "Organization: %s\n", buf);
4402 /* Program version and system info */
4403 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4404 !compose->newsgroup_list) {
4405 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4407 gtk_major_version, gtk_minor_version, gtk_micro_version,
4410 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4411 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4413 gtk_major_version, gtk_minor_version, gtk_micro_version,
4417 /* custom headers */
4418 if (compose->account->add_customhdr) {
4421 for (cur = compose->account->customhdr_list; cur != NULL;
4423 CustomHeader *chdr = (CustomHeader *)cur->data;
4425 if (custom_header_is_allowed(chdr->name)) {
4426 compose_convert_header
4427 (compose, buf, sizeof(buf),
4428 chdr->value ? chdr->value : "",
4429 strlen(chdr->name) + 2, FALSE);
4430 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4436 switch (compose->priority) {
4437 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4438 "X-Priority: 1 (Highest)\n");
4440 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4441 "X-Priority: 2 (High)\n");
4443 case PRIORITY_NORMAL: break;
4444 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4445 "X-Priority: 4 (Low)\n");
4447 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4448 "X-Priority: 5 (Lowest)\n");
4450 default: debug_print("compose: priority unknown : %d\n",
4454 /* Request Return Receipt */
4455 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4456 if (compose->return_receipt) {
4457 if (compose->account->name
4458 && *compose->account->name) {
4459 compose_convert_header(compose, buf, sizeof(buf),
4460 compose->account->name,
4461 strlen("Disposition-Notification-To: "),
4463 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4465 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4469 /* get special headers */
4470 for (list = compose->header_list; list; list = list->next) {
4471 ComposeHeaderEntry *headerentry;
4474 gchar *headername_wcolon;
4475 gchar *headername_trans;
4478 gboolean standard_header = FALSE;
4480 headerentry = ((ComposeHeaderEntry *)list->data);
4482 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4483 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4488 if (!strstr(tmp, ":")) {
4489 headername_wcolon = g_strconcat(tmp, ":", NULL);
4490 headername = g_strdup(tmp);
4492 headername_wcolon = g_strdup(tmp);
4493 headername = g_strdup(strtok(tmp, ":"));
4497 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4498 Xstrdup_a(headervalue, entry_str, return NULL);
4499 subst_char(headervalue, '\r', ' ');
4500 subst_char(headervalue, '\n', ' ');
4501 string = std_headers;
4502 while (*string != NULL) {
4503 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4504 if (!strcmp(headername_trans,headername_wcolon))
4505 standard_header = TRUE;
4508 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4509 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
4512 g_free(headername_wcolon);
4516 g_string_free(header, FALSE);
4521 #undef IS_IN_CUSTOM_HEADER
4523 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
4524 gint header_len, gboolean addr_field)
4526 gchar *tmpstr = NULL;
4528 g_return_if_fail(src != NULL);
4529 g_return_if_fail(dest != NULL);
4531 if (len < 1) return;
4533 tmpstr = g_strdup(src);
4535 subst_char(tmpstr, '\n', ' ');
4536 subst_char(tmpstr, '\r', ' ');
4539 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4540 conv_get_charset_str(compose->out_encoding));
4544 static void compose_create_header_entry(Compose *compose)
4546 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4550 GList *combo_list = NULL;
4552 const gchar *header = NULL;
4553 ComposeHeaderEntry *headerentry;
4554 gboolean standard_header = FALSE;
4556 headerentry = g_new0(ComposeHeaderEntry, 1);
4559 combo = gtk_combo_new();
4561 while(*string != NULL) {
4562 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4565 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4566 g_list_free(combo_list);
4567 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4568 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4569 G_CALLBACK(compose_grab_focus_cb), compose);
4570 gtk_widget_show(combo);
4571 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4572 if (compose->header_last) {
4573 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4575 while (*string != NULL) {
4576 if (!strcmp(*string, last_header_entry))
4577 standard_header = TRUE;
4580 if (standard_header)
4581 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4583 if (!compose->header_last || !standard_header) {
4584 switch(compose->account->protocol) {
4586 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4589 header = prefs_common.trans_hdr ? _("To:") : "To:";
4594 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4596 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4597 G_CALLBACK(compose_grab_focus_cb), compose);
4600 entry = gtk_entry_new();
4601 gtk_widget_show(entry);
4602 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);
4604 g_signal_connect(G_OBJECT(entry), "key-press-event",
4605 G_CALLBACK(compose_headerentry_key_press_event_cb),
4607 g_signal_connect(G_OBJECT(entry), "changed",
4608 G_CALLBACK(compose_headerentry_changed_cb),
4610 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
4611 G_CALLBACK(compose_grab_focus_cb), compose);
4614 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
4615 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
4616 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4617 g_signal_connect(G_OBJECT(entry), "drag_data_received",
4618 G_CALLBACK(compose_header_drag_received_cb),
4620 g_signal_connect(G_OBJECT(entry), "drag-drop",
4621 G_CALLBACK(compose_drag_drop),
4624 address_completion_register_entry(GTK_ENTRY(entry));
4626 headerentry->compose = compose;
4627 headerentry->combo = combo;
4628 headerentry->entry = entry;
4629 headerentry->headernum = compose->header_nextrow;
4631 compose->header_nextrow++;
4632 compose->header_last = headerentry;
4635 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4637 ComposeHeaderEntry *last_header;
4639 last_header = compose->header_last;
4641 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4642 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4645 static GtkWidget *compose_create_header(Compose *compose)
4649 GtkWidget *from_optmenu_hbox;
4650 GtkWidget *header_scrolledwin;
4651 GtkWidget *header_table;
4655 /* header labels and entries */
4656 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4657 gtk_widget_show(header_scrolledwin);
4658 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4660 header_table = gtk_table_new(2, 2, FALSE);
4661 gtk_widget_show(header_table);
4662 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4663 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4664 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4667 /* option menu for selecting accounts */
4668 hbox = gtk_hbox_new(FALSE, 0);
4669 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4670 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4671 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4673 from_optmenu_hbox = compose_account_option_menu_create(compose);
4674 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4675 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4678 compose->header_table = header_table;
4679 compose->header_list = NULL;
4680 compose->header_nextrow = count;
4682 compose_create_header_entry(compose);
4684 compose->table = NULL;
4686 return header_scrolledwin ;
4689 GtkWidget *compose_create_attach(Compose *compose)
4691 GtkWidget *attach_scrwin;
4692 GtkWidget *attach_clist;
4694 GtkListStore *store;
4695 GtkCellRenderer *renderer;
4696 GtkTreeViewColumn *column;
4697 GtkTreeSelection *selection;
4699 /* attachment list */
4700 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4701 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4702 GTK_POLICY_AUTOMATIC,
4703 GTK_POLICY_AUTOMATIC);
4704 gtk_widget_set_size_request(attach_scrwin, -1, 80);
4706 store = gtk_list_store_new(N_ATTACH_COLS,
4711 G_TYPE_AUTO_POINTER,
4713 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
4714 (GTK_TREE_MODEL(store)));
4715 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4716 g_object_unref(store);
4718 renderer = gtk_cell_renderer_text_new();
4719 column = gtk_tree_view_column_new_with_attributes
4720 (_("Mime type"), renderer, "text",
4721 COL_MIMETYPE, NULL);
4722 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
4724 renderer = gtk_cell_renderer_text_new();
4725 column = gtk_tree_view_column_new_with_attributes
4726 (_("Size"), renderer, "text",
4728 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
4730 renderer = gtk_cell_renderer_text_new();
4731 column = gtk_tree_view_column_new_with_attributes
4732 (_("Name"), renderer, "text",
4734 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
4736 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
4737 prefs_common.enable_rules_hint);
4738 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
4739 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
4741 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
4742 G_CALLBACK(attach_selected), compose);
4743 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
4744 G_CALLBACK(attach_button_pressed), compose);
4745 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
4746 G_CALLBACK(attach_key_pressed), compose);
4749 gtk_drag_dest_set(attach_clist,
4750 GTK_DEST_DEFAULT_ALL, compose_mime_types,
4751 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
4752 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4753 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
4754 G_CALLBACK(compose_attach_drag_received_cb),
4756 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
4757 G_CALLBACK(compose_drag_drop),
4760 compose->attach_scrwin = attach_scrwin;
4761 compose->attach_clist = attach_clist;
4763 return attach_scrwin;
4766 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4767 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4769 static GtkWidget *compose_create_others(Compose *compose)
4772 GtkWidget *savemsg_checkbtn;
4773 GtkWidget *savemsg_entry;
4774 GtkWidget *savemsg_select;
4777 gchar *folderidentifier;
4779 /* Table for settings */
4780 table = gtk_table_new(3, 1, FALSE);
4781 gtk_widget_show(table);
4782 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4785 /* Save Message to folder */
4786 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4787 gtk_widget_show(savemsg_checkbtn);
4788 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4789 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4790 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4792 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
4793 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
4795 savemsg_entry = gtk_entry_new();
4796 gtk_widget_show(savemsg_entry);
4797 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4798 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4799 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
4800 G_CALLBACK(compose_grab_focus_cb), compose);
4801 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4802 folderidentifier = folder_item_get_identifier(account_get_special_folder
4803 (compose->account, F_OUTBOX));
4804 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4805 g_free(folderidentifier);
4808 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4809 gtk_widget_show(savemsg_select);
4810 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4811 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
4812 G_CALLBACK(compose_savemsg_select_cb),
4817 compose->savemsg_checkbtn = savemsg_checkbtn;
4818 compose->savemsg_entry = savemsg_entry;
4823 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4825 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4826 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4829 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4834 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4837 path = folder_item_get_identifier(dest);
4839 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4843 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4849 GtkWidget *handlebox;
4851 GtkWidget *notebook;
4856 GtkWidget *subject_hbox;
4857 GtkWidget *subject_frame;
4858 GtkWidget *subject_entry;
4862 GtkWidget *edit_vbox;
4863 GtkWidget *ruler_hbox;
4865 GtkWidget *scrolledwin;
4867 GtkTextBuffer *buffer;
4868 GtkClipboard *clipboard;
4870 UndoMain *undostruct;
4872 gchar *titles[N_ATTACH_COLS];
4873 guint n_menu_entries;
4876 gboolean success[1];
4877 GtkWidget *popupmenu;
4878 GtkItemFactory *popupfactory;
4879 GtkItemFactory *ifactory;
4880 GtkWidget *tmpl_menu;
4882 GtkWidget *menuitem;
4885 GtkAspell * gtkaspell = NULL;
4888 static GdkGeometry geometry;
4890 g_return_val_if_fail(account != NULL, NULL);
4892 debug_print("Creating compose window...\n");
4893 compose = g_new0(Compose, 1);
4895 titles[COL_MIMETYPE] = _("MIME type");
4896 titles[COL_SIZE] = _("Size");
4897 titles[COL_NAME] = _("Name");
4899 compose->account = account;
4901 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4902 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
4903 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
4905 if (!geometry.max_width) {
4906 geometry.max_width = gdk_screen_width();
4907 geometry.max_height = gdk_screen_height();
4909 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4910 &geometry, GDK_HINT_MAX_SIZE);
4911 if (!geometry.min_width) {
4912 geometry.min_width = 600;
4913 geometry.min_height = 480;
4915 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4916 &geometry, GDK_HINT_MIN_SIZE);
4917 gtk_widget_set_uposition(window, prefs_common.compose_x,
4918 prefs_common.compose_y);
4920 g_signal_connect(G_OBJECT(window), "delete_event",
4921 G_CALLBACK(compose_delete_cb), compose);
4922 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4923 gtk_widget_realize(window);
4925 gtkut_widget_set_composer_icon(window);
4927 vbox = gtk_vbox_new(FALSE, 0);
4928 gtk_container_add(GTK_CONTAINER(window), vbox);
4930 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4931 menubar = menubar_create(window, compose_entries,
4932 n_menu_entries, "<Compose>", compose);
4933 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4935 if (prefs_common.toolbar_detachable) {
4936 handlebox = gtk_handle_box_new();
4938 handlebox = gtk_hbox_new(FALSE, 0);
4940 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4942 gtk_widget_realize(handlebox);
4943 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
4946 vbox2 = gtk_vbox_new(FALSE, 2);
4947 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4948 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4951 notebook = gtk_notebook_new();
4952 gtk_widget_set_size_request(notebook, -1, 130);
4953 gtk_widget_show(notebook);
4955 /* header labels and entries */
4956 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4957 /* attachment list */
4958 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4960 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4963 subject_hbox = gtk_hbox_new(FALSE, 0);
4964 gtk_widget_show(subject_hbox);
4966 subject_frame = gtk_frame_new(NULL);
4967 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4968 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4969 gtk_widget_show(subject_frame);
4971 subject = gtk_hbox_new(FALSE, 0);
4972 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4973 gtk_widget_show(subject);
4975 label = gtk_label_new(_("Subject:"));
4976 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4977 gtk_widget_show(label);
4979 subject_entry = gtk_entry_new();
4980 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4981 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
4982 G_CALLBACK(compose_grab_focus_cb), compose);
4983 gtk_widget_show(subject_entry);
4984 compose->subject_entry = subject_entry;
4985 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4987 edit_vbox = gtk_vbox_new(FALSE, 0);
4989 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4992 ruler_hbox = gtk_hbox_new(FALSE, 0);
4993 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4995 ruler = gtk_shruler_new();
4996 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4997 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5001 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5002 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5003 GTK_POLICY_AUTOMATIC,
5004 GTK_POLICY_AUTOMATIC);
5005 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5007 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5008 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5010 text = gtk_text_view_new();
5011 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5012 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5013 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5014 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5015 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5017 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5019 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5020 G_CALLBACK(compose_edit_size_alloc),
5022 g_signal_connect(G_OBJECT(buffer), "changed",
5023 G_CALLBACK(compose_changed_cb), compose);
5024 g_signal_connect(G_OBJECT(text), "grab_focus",
5025 G_CALLBACK(compose_grab_focus_cb), compose);
5026 g_signal_connect(G_OBJECT(buffer), "insert_text",
5027 G_CALLBACK(text_inserted), compose);
5030 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5031 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5032 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5033 g_signal_connect(G_OBJECT(text), "drag_data_received",
5034 G_CALLBACK(compose_insert_drag_received_cb),
5036 g_signal_connect(G_OBJECT(text), "drag-drop",
5037 G_CALLBACK(compose_drag_drop),
5039 gtk_widget_show_all(vbox);
5041 /* pane between attach clist and text */
5042 paned = gtk_vpaned_new();
5043 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5044 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5045 gtk_paned_add1(GTK_PANED(paned), notebook);
5046 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5047 gtk_widget_show_all(paned);
5050 if (prefs_common.textfont) {
5051 PangoFontDescription *font_desc;
5053 font_desc = pango_font_description_from_string
5054 (prefs_common.textfont);
5056 gtk_widget_modify_font(text, font_desc);
5057 pango_font_description_free(font_desc);
5061 color[0] = quote_color;
5062 cmap = gdk_drawable_get_colormap(window->window);
5063 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5064 if (success[0] == FALSE) {
5067 g_warning("Compose: color allocation failed.\n");
5068 style = gtk_widget_get_style(text);
5069 quote_color = style->black;
5072 n_entries = sizeof(compose_popup_entries) /
5073 sizeof(compose_popup_entries[0]);
5074 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5075 "<Compose>", &popupfactory,
5078 ifactory = gtk_item_factory_from_widget(menubar);
5079 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5080 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5081 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5083 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5085 undostruct = undo_init(text);
5086 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5089 address_completion_start(window);
5091 compose->window = window;
5092 compose->vbox = vbox;
5093 compose->menubar = menubar;
5094 compose->handlebox = handlebox;
5096 compose->vbox2 = vbox2;
5098 compose->paned = paned;
5100 compose->edit_vbox = edit_vbox;
5101 compose->ruler_hbox = ruler_hbox;
5102 compose->ruler = ruler;
5103 compose->scrolledwin = scrolledwin;
5104 compose->text = text;
5106 compose->focused_editable = NULL;
5108 compose->popupmenu = popupmenu;
5109 compose->popupfactory = popupfactory;
5111 compose->tmpl_menu = tmpl_menu;
5113 compose->mode = mode;
5115 compose->targetinfo = NULL;
5116 compose->replyinfo = NULL;
5117 compose->fwdinfo = NULL;
5119 compose->replyto = NULL;
5121 compose->bcc = NULL;
5122 compose->followup_to = NULL;
5124 compose->ml_post = NULL;
5126 compose->inreplyto = NULL;
5127 compose->references = NULL;
5128 compose->msgid = NULL;
5129 compose->boundary = NULL;
5131 compose->autowrap = prefs_common.autowrap;
5133 compose->use_signing = FALSE;
5134 compose->use_encryption = FALSE;
5135 compose->privacy_system = NULL;
5137 compose->modified = FALSE;
5139 compose->return_receipt = FALSE;
5141 compose->to_list = NULL;
5142 compose->newsgroup_list = NULL;
5144 compose->undostruct = undostruct;
5146 compose->sig_str = NULL;
5148 compose->exteditor_file = NULL;
5149 compose->exteditor_pid = -1;
5150 compose->exteditor_tag = -1;
5151 compose->draft_timeout_tag = -1;
5154 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5155 if (mode != COMPOSE_REDIRECT) {
5156 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5157 strcmp(prefs_common.dictionary, _("None"))) {
5158 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5159 prefs_common.dictionary,
5160 conv_get_locale_charset_str(),
5161 prefs_common.misspelled_col,
5162 prefs_common.check_while_typing,
5163 prefs_common.use_alternate,
5164 GTK_TEXT_VIEW(text),
5165 GTK_WINDOW(compose->window));
5167 alertpanel_error(_("Spell checker could not "
5169 gtkaspell_checkers_strerror());
5170 gtkaspell_checkers_reset_error();
5173 GtkWidget *menuitem;
5175 if (!gtkaspell_set_sug_mode(gtkaspell,
5176 prefs_common.aspell_sugmode)) {
5177 debug_print("Aspell: could not set "
5178 "suggestion mode %s\n",
5179 gtkaspell_checkers_strerror());
5180 gtkaspell_checkers_reset_error();
5183 menuitem = gtk_item_factory_get_item(ifactory,
5184 "/Spelling/Spelling Configuration");
5185 gtkaspell_populate_submenu(gtkaspell, menuitem);
5186 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5190 compose->gtkaspell = gtkaspell;
5193 compose_select_account(compose, account, TRUE);
5195 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5196 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5197 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5199 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5200 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5202 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5203 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5206 if (account->protocol != A_NNTP)
5207 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5209 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5211 addressbook_set_target_compose(compose);
5213 if (mode != COMPOSE_REDIRECT)
5214 compose_set_template_menu(compose);
5216 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5217 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5220 compose_list = g_list_append(compose_list, compose);
5222 if (!prefs_common.show_ruler)
5223 gtk_widget_hide(ruler_hbox);
5225 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5226 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5227 prefs_common.show_ruler);
5230 compose->priority = PRIORITY_NORMAL;
5231 compose_update_priority_menu_item(compose);
5233 compose_set_out_encoding(compose);
5236 compose_update_actions_menu(compose);
5238 /* Privacy Systems menu */
5239 compose_update_privacy_systems_menu(compose);
5241 activate_privacy_system(compose, account);
5242 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5243 gtk_widget_show(window);
5248 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5254 gint num = 0, def_menu = 0;
5256 accounts = account_get_list();
5257 g_return_val_if_fail(accounts != NULL, NULL);
5259 hbox = gtk_hbox_new(FALSE, 0);
5260 optmenu = gtk_option_menu_new();
5261 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5262 menu = gtk_menu_new();
5264 for (; accounts != NULL; accounts = accounts->next, num++) {
5265 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5266 GtkWidget *menuitem;
5269 if (ac == compose->account) def_menu = num;
5272 name = g_strdup_printf("%s: %s <%s>",
5274 ac->name, ac->address);
5276 name = g_strdup_printf("%s: %s",
5277 ac->account_name, ac->address);
5278 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5280 g_signal_connect(G_OBJECT(menuitem), "activate",
5281 G_CALLBACK(account_activated),
5285 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5286 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5291 static void compose_set_priority_cb(gpointer data,
5295 Compose *compose = (Compose *) data;
5296 compose->priority = action;
5299 static void compose_update_priority_menu_item(Compose * compose)
5301 GtkItemFactory *ifactory;
5302 GtkWidget *menuitem = NULL;
5304 ifactory = gtk_item_factory_from_widget(compose->menubar);
5306 switch (compose->priority) {
5307 case PRIORITY_HIGHEST:
5308 menuitem = gtk_item_factory_get_item
5309 (ifactory, "/Options/Priority/Highest");
5312 menuitem = gtk_item_factory_get_item
5313 (ifactory, "/Options/Priority/High");
5315 case PRIORITY_NORMAL:
5316 menuitem = gtk_item_factory_get_item
5317 (ifactory, "/Options/Priority/Normal");
5320 menuitem = gtk_item_factory_get_item
5321 (ifactory, "/Options/Priority/Low");
5323 case PRIORITY_LOWEST:
5324 menuitem = gtk_item_factory_get_item
5325 (ifactory, "/Options/Priority/Lowest");
5328 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5331 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5333 Compose *compose = (Compose *) data;
5335 GtkItemFactory *ifactory;
5336 gboolean can_sign = FALSE, can_encrypt = FALSE;
5338 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5340 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5343 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5344 g_free(compose->privacy_system);
5345 compose->privacy_system = NULL;
5346 if (systemid != NULL) {
5347 compose->privacy_system = g_strdup(systemid);
5349 can_sign = privacy_system_can_sign(systemid);
5350 can_encrypt = privacy_system_can_encrypt(systemid);
5353 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5355 ifactory = gtk_item_factory_from_widget(compose->menubar);
5356 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5357 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5360 static void compose_update_privacy_system_menu_item(Compose * compose)
5362 static gchar *branch_path = "/Options/Privacy System";
5363 GtkItemFactory *ifactory;
5364 GtkWidget *menuitem = NULL;
5366 gboolean can_sign = FALSE, can_encrypt = FALSE;
5368 ifactory = gtk_item_factory_from_widget(compose->menubar);
5370 if (compose->privacy_system != NULL) {
5373 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5374 g_return_if_fail(menuitem != NULL);
5376 amenu = GTK_MENU_SHELL(menuitem)->children;
5378 while (amenu != NULL) {
5379 GList *alist = amenu->next;
5381 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
5382 if (systemid != NULL)
5383 if (strcmp(systemid, compose->privacy_system) == 0) {
5384 menuitem = GTK_WIDGET(amenu->data);
5386 can_sign = privacy_system_can_sign(systemid);
5387 can_encrypt = privacy_system_can_encrypt(systemid);
5394 if (menuitem != NULL)
5395 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5398 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5399 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5402 static void compose_set_out_encoding(Compose *compose)
5404 GtkItemFactoryEntry *entry;
5405 GtkItemFactory *ifactory;
5406 CharSet out_encoding;
5407 gchar *path, *p, *q;
5410 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
5411 ifactory = gtk_item_factory_from_widget(compose->menubar);
5413 for (entry = compose_entries; entry->callback != compose_address_cb;
5415 if (entry->callback == compose_set_encoding_cb &&
5416 (CharSet)entry->callback_action == out_encoding) {
5417 p = q = path = g_strdup(entry->path);
5429 item = gtk_item_factory_get_item(ifactory, path);
5430 gtk_widget_activate(item);
5437 static void compose_set_template_menu(Compose *compose)
5439 GSList *tmpl_list, *cur;
5443 tmpl_list = template_get_config();
5445 menu = gtk_menu_new();
5447 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5448 Template *tmpl = (Template *)cur->data;
5450 item = gtk_menu_item_new_with_label(tmpl->name);
5451 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5452 g_signal_connect(G_OBJECT(item), "activate",
5453 G_CALLBACK(compose_template_activate_cb),
5455 g_object_set_data(G_OBJECT(item), "template", tmpl);
5456 gtk_widget_show(item);
5459 gtk_widget_show(menu);
5460 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5463 void compose_update_actions_menu(Compose *compose)
5465 GtkItemFactory *ifactory;
5467 ifactory = gtk_item_factory_from_widget(compose->menubar);
5468 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5471 void compose_update_privacy_systems_menu(Compose *compose)
5473 static gchar *branch_path = "/Options/Privacy System";
5474 GtkItemFactory *ifactory;
5475 GtkWidget *menuitem;
5476 GSList *systems, *cur;
5479 GtkWidget *system_none;
5482 ifactory = gtk_item_factory_from_widget(compose->menubar);
5484 /* remove old entries */
5485 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5486 g_return_if_fail(menuitem != NULL);
5488 amenu = GTK_MENU_SHELL(menuitem)->children->next;
5489 while (amenu != NULL) {
5490 GList *alist = amenu->next;
5491 gtk_widget_destroy(GTK_WIDGET(amenu->data));
5495 system_none = gtk_item_factory_get_widget(ifactory,
5496 "/Options/Privacy System/None");
5498 g_signal_connect(G_OBJECT(system_none), "activate",
5499 G_CALLBACK(compose_set_privacy_system_cb), compose);
5501 systems = privacy_get_system_ids();
5502 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
5503 gchar *systemid = cur->data;
5505 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
5506 widget = gtk_radio_menu_item_new_with_label(group,
5507 privacy_system_get_name(systemid));
5508 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
5509 g_strdup(systemid), g_free);
5510 g_signal_connect(G_OBJECT(widget), "activate",
5511 G_CALLBACK(compose_set_privacy_system_cb), compose);
5513 gtk_menu_append(GTK_MENU(system_none->parent), widget);
5514 gtk_widget_show(widget);
5517 g_slist_free(systems);
5520 void compose_reflect_prefs_all(void)
5525 for (cur = compose_list; cur != NULL; cur = cur->next) {
5526 compose = (Compose *)cur->data;
5527 compose_set_template_menu(compose);
5531 void compose_reflect_prefs_pixmap_theme(void)
5536 for (cur = compose_list; cur != NULL; cur = cur->next) {
5537 compose = (Compose *)cur->data;
5538 toolbar_update(TOOLBAR_COMPOSE, compose);
5542 static void compose_template_apply(Compose *compose, Template *tmpl,
5546 GtkTextBuffer *buffer;
5552 if (!tmpl || !tmpl->value) return;
5554 text = GTK_TEXT_VIEW(compose->text);
5555 buffer = gtk_text_view_get_buffer(text);
5557 if (tmpl->subject && *tmpl->subject != '\0')
5558 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5560 if (tmpl->to && *tmpl->to != '\0')
5561 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5562 if (tmpl->cc && *tmpl->cc != '\0')
5563 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5565 if (tmpl->bcc && *tmpl->bcc != '\0')
5566 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5569 gtk_text_buffer_set_text(buffer, "", -1);
5571 mark = gtk_text_buffer_get_insert(buffer);
5572 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
5574 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
5575 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5578 if (prefs_common.quotemark && *prefs_common.quotemark)
5579 qmark = prefs_common.quotemark;
5583 if (compose->replyinfo != NULL)
5584 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5585 tmpl->value, qmark, NULL);
5586 else if (compose->fwdinfo != NULL)
5587 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
5588 tmpl->value, qmark, NULL);
5593 if (replace && parsed_str && compose->account->auto_sig)
5594 compose_insert_sig(compose, FALSE);
5596 if (replace && parsed_str) {
5597 gtk_text_buffer_get_start_iter(buffer, &iter);
5598 gtk_text_buffer_place_cursor(buffer, &iter);
5602 compose_changed_cb(NULL, compose);
5605 static void compose_destroy(Compose *compose)
5607 compose_list = g_list_remove(compose_list, compose);
5609 /* NOTE: address_completion_end() does nothing with the window
5610 * however this may change. */
5611 address_completion_end(compose->window);
5613 slist_free_strings(compose->to_list);
5614 g_slist_free(compose->to_list);
5615 slist_free_strings(compose->newsgroup_list);
5616 g_slist_free(compose->newsgroup_list);
5617 slist_free_strings(compose->header_list);
5618 g_slist_free(compose->header_list);
5620 procmsg_msginfo_free(compose->targetinfo);
5621 procmsg_msginfo_free(compose->replyinfo);
5622 procmsg_msginfo_free(compose->fwdinfo);
5624 g_free(compose->replyto);
5625 g_free(compose->cc);
5626 g_free(compose->bcc);
5627 g_free(compose->newsgroups);
5628 g_free(compose->followup_to);
5630 g_free(compose->ml_post);
5632 g_free(compose->inreplyto);
5633 g_free(compose->references);
5634 g_free(compose->msgid);
5635 g_free(compose->boundary);
5637 if (compose->redirect_filename)
5638 g_free(compose->redirect_filename);
5639 if (compose->undostruct)
5640 undo_destroy(compose->undostruct);
5642 g_free(compose->sig_str);
5644 g_free(compose->exteditor_file);
5646 if (addressbook_get_target_compose() == compose)
5647 addressbook_set_target_compose(NULL);
5650 if (compose->gtkaspell) {
5651 gtkaspell_delete(compose->gtkaspell);
5652 compose->gtkaspell = NULL;
5656 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5657 prefs_common.compose_height = compose->window->allocation.height;
5659 if (!gtk_widget_get_parent(compose->paned))
5660 gtk_widget_destroy(compose->paned);
5661 gtk_widget_destroy(compose->popupmenu);
5663 gtk_widget_destroy(compose->window);
5664 toolbar_destroy(compose->toolbar);
5665 g_free(compose->toolbar);
5669 static void compose_attach_info_free(AttachInfo *ainfo)
5671 g_free(ainfo->file);
5672 g_free(ainfo->content_type);
5673 g_free(ainfo->name);
5677 static void compose_attach_remove_selected(Compose *compose)
5679 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
5680 GtkTreeSelection *selection;
5682 GtkTreeModel *model;
5684 selection = gtk_tree_view_get_selection(tree_view);
5685 sel = gtk_tree_selection_get_selected_rows(selection, &model);
5690 for (cur = sel; cur != NULL; cur = cur->next) {
5691 GtkTreePath *path = cur->data;
5692 GtkTreeRowReference *ref = gtk_tree_row_reference_new
5695 gtk_tree_path_free(path);
5698 for (cur = sel; cur != NULL; cur = cur->next) {
5699 GtkTreeRowReference *ref = cur->data;
5700 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
5703 if (gtk_tree_model_get_iter(model, &iter, path))
5704 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
5706 gtk_tree_path_free(path);
5707 gtk_tree_row_reference_free(ref);
5713 static struct _AttachProperty
5716 GtkWidget *mimetype_entry;
5717 GtkWidget *encoding_optmenu;
5718 GtkWidget *path_entry;
5719 GtkWidget *filename_entry;
5721 GtkWidget *cancel_btn;
5724 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
5726 gtk_tree_path_free((GtkTreePath *)ptr);
5729 static void compose_attach_property(Compose *compose)
5731 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
5733 GtkOptionMenu *optmenu;
5734 GtkTreeSelection *selection;
5736 GtkTreeModel *model;
5739 static gboolean cancelled;
5741 /* only if one selected */
5742 selection = gtk_tree_view_get_selection(tree_view);
5743 if (gtk_tree_selection_count_selected_rows(selection) != 1)
5746 sel = gtk_tree_selection_get_selected_rows(selection, &model);
5750 path = (GtkTreePath *) sel->data;
5751 gtk_tree_model_get_iter(model, &iter, path);
5752 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
5755 g_list_foreach(sel, gtk_tree_path_free_, NULL);
5761 if (!attach_prop.window)
5762 compose_attach_property_create(&cancelled);
5763 gtk_widget_grab_focus(attach_prop.ok_btn);
5764 gtk_widget_show(attach_prop.window);
5765 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5767 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5768 if (ainfo->encoding == ENC_UNKNOWN)
5769 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5770 GINT_TO_POINTER(ENC_BASE64));
5772 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5773 GINT_TO_POINTER(ainfo->encoding));
5775 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5776 ainfo->content_type ? ainfo->content_type : "");
5777 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5778 ainfo->file ? ainfo->file : "");
5779 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5780 ainfo->name ? ainfo->name : "");
5783 const gchar *entry_text;
5785 gchar *cnttype = NULL;
5789 GtkWidget *menuitem;
5794 gtk_widget_hide(attach_prop.window);
5799 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5800 if (*entry_text != '\0') {
5803 text = g_strstrip(g_strdup(entry_text));
5804 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5805 cnttype = g_strdup(text);
5808 alertpanel_error(_("Invalid MIME type."));
5814 menu = gtk_option_menu_get_menu(optmenu);
5815 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5816 ainfo->encoding = GPOINTER_TO_INT
5817 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
5819 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5820 if (*entry_text != '\0') {
5821 if (is_file_exist(entry_text) &&
5822 (size = get_file_size(entry_text)) > 0)
5823 file = g_strdup(entry_text);
5826 (_("File doesn't exist or is empty."));
5832 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5833 if (*entry_text != '\0') {
5834 g_free(ainfo->name);
5835 ainfo->name = g_strdup(entry_text);
5839 g_free(ainfo->content_type);
5840 ainfo->content_type = cnttype;
5843 g_free(ainfo->file);
5849 /* update tree store */
5850 text = to_human_readable(ainfo->size);
5851 gtk_tree_model_get_iter(model, &iter, path);
5852 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
5853 COL_MIMETYPE, ainfo->content_type,
5855 COL_NAME, ainfo->file,
5861 gtk_tree_path_free(path);
5864 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5866 label = gtk_label_new(str); \
5867 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5868 GTK_FILL, 0, 0, 0); \
5869 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5871 entry = gtk_entry_new(); \
5872 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5873 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5876 static void compose_attach_property_create(gboolean *cancelled)
5882 GtkWidget *mimetype_entry;
5885 GtkWidget *optmenu_menu;
5886 GtkWidget *menuitem;
5887 GtkWidget *path_entry;
5888 GtkWidget *filename_entry;
5891 GtkWidget *cancel_btn;
5892 GList *mime_type_list, *strlist;
5894 debug_print("Creating attach_property window...\n");
5896 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5897 gtk_widget_set_size_request(window, 480, -1);
5898 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5899 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
5900 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5901 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5902 g_signal_connect(G_OBJECT(window), "delete_event",
5903 G_CALLBACK(attach_property_delete_event),
5905 g_signal_connect(G_OBJECT(window), "key_press_event",
5906 G_CALLBACK(attach_property_key_pressed),
5909 vbox = gtk_vbox_new(FALSE, 8);
5910 gtk_container_add(GTK_CONTAINER(window), vbox);
5912 table = gtk_table_new(4, 2, FALSE);
5913 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5914 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5915 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5917 label = gtk_label_new(_("MIME type"));
5918 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5920 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5921 mimetype_entry = gtk_combo_new();
5922 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5923 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5925 /* stuff with list */
5926 mime_type_list = procmime_get_mime_type_list();
5928 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5929 MimeType *type = (MimeType *) mime_type_list->data;
5930 strlist = g_list_append(strlist,
5931 g_strdup_printf("%s/%s",
5932 type->type, type->sub_type));
5935 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5937 for (mime_type_list = strlist; mime_type_list != NULL;
5938 mime_type_list = mime_type_list->next)
5939 g_free(mime_type_list->data);
5940 g_list_free(strlist);
5942 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5944 label = gtk_label_new(_("Encoding"));
5945 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5947 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5949 hbox = gtk_hbox_new(FALSE, 0);
5950 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5951 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5953 optmenu = gtk_option_menu_new();
5954 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5956 optmenu_menu = gtk_menu_new();
5957 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5958 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5959 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5960 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5961 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
5962 ENC_QUOTED_PRINTABLE);
5963 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5965 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5967 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5969 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5970 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5972 gtkut_stock_button_set_create(&hbbox, &ok_btn, GTK_STOCK_OK,
5973 &cancel_btn, GTK_STOCK_CANCEL,
5975 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5976 gtk_widget_grab_default(ok_btn);
5978 g_signal_connect(G_OBJECT(ok_btn), "clicked",
5979 G_CALLBACK(attach_property_ok),
5981 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
5982 G_CALLBACK(attach_property_cancel),
5985 gtk_widget_show_all(vbox);
5987 attach_prop.window = window;
5988 attach_prop.mimetype_entry = mimetype_entry;
5989 attach_prop.encoding_optmenu = optmenu;
5990 attach_prop.path_entry = path_entry;
5991 attach_prop.filename_entry = filename_entry;
5992 attach_prop.ok_btn = ok_btn;
5993 attach_prop.cancel_btn = cancel_btn;
5996 #undef SET_LABEL_AND_ENTRY
5998 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6004 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6010 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6011 gboolean *cancelled)
6019 static gboolean attach_property_key_pressed(GtkWidget *widget,
6021 gboolean *cancelled)
6023 if (event && event->keyval == GDK_Escape) {
6030 static void compose_exec_ext_editor(Compose *compose)
6037 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6038 G_DIR_SEPARATOR, compose);
6040 if (pipe(pipe_fds) < 0) {
6046 if ((pid = fork()) < 0) {
6053 /* close the write side of the pipe */
6056 compose->exteditor_file = g_strdup(tmp);
6057 compose->exteditor_pid = pid;
6059 compose_set_ext_editor_sensitive(compose, FALSE);
6061 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6062 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6066 } else { /* process-monitoring process */
6072 /* close the read side of the pipe */
6075 if (compose_write_body_to_file(compose, tmp) < 0) {
6076 fd_write_all(pipe_fds[1], "2\n", 2);
6080 pid_ed = compose_exec_ext_editor_real(tmp);
6082 fd_write_all(pipe_fds[1], "1\n", 2);
6086 /* wait until editor is terminated */
6087 waitpid(pid_ed, NULL, 0);
6089 fd_write_all(pipe_fds[1], "0\n", 2);
6096 #endif /* G_OS_UNIX */
6100 static gint compose_exec_ext_editor_real(const gchar *file)
6102 static gchar *def_cmd = "emacs %s";
6108 g_return_val_if_fail(file != NULL, -1);
6110 if ((pid = fork()) < 0) {
6115 if (pid != 0) return pid;
6117 /* grandchild process */
6119 if (setpgid(0, getppid()))
6122 if (prefs_common.ext_editor_cmd &&
6123 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6124 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6125 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6127 if (prefs_common.ext_editor_cmd)
6128 g_warning("External editor command line is invalid: '%s'\n",
6129 prefs_common.ext_editor_cmd);
6130 g_snprintf(buf, sizeof(buf), def_cmd, file);
6133 cmdline = strsplit_with_quote(buf, " ", 1024);
6134 execvp(cmdline[0], cmdline);
6137 g_strfreev(cmdline);
6142 static gboolean compose_ext_editor_kill(Compose *compose)
6144 pid_t pgid = compose->exteditor_pid * -1;
6147 ret = kill(pgid, 0);
6149 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6153 msg = g_strdup_printf
6154 (_("The external editor is still working.\n"
6155 "Force terminating the process?\n"
6156 "process group id: %d"), -pgid);
6157 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_YES, GTK_STOCK_NO,
6158 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
6162 if (val == G_ALERTDEFAULT) {
6163 g_source_remove(compose->exteditor_tag);
6164 g_io_channel_shutdown(compose->exteditor_ch,
6166 g_io_channel_unref(compose->exteditor_ch);
6168 if (kill(pgid, SIGTERM) < 0) perror("kill");
6169 waitpid(compose->exteditor_pid, NULL, 0);
6171 g_warning("Terminated process group id: %d", -pgid);
6172 g_warning("Temporary file: %s",
6173 compose->exteditor_file);
6175 compose_set_ext_editor_sensitive(compose, TRUE);
6177 g_free(compose->exteditor_file);
6178 compose->exteditor_file = NULL;
6179 compose->exteditor_pid = -1;
6180 compose->exteditor_ch = NULL;
6181 compose->exteditor_tag = -1;
6189 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6193 Compose *compose = (Compose *)data;
6196 debug_print(_("Compose: input from monitoring process\n"));
6198 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6200 g_io_channel_shutdown(source, FALSE, NULL);
6201 g_io_channel_unref(source);
6203 waitpid(compose->exteditor_pid, NULL, 0);
6205 if (buf[0] == '0') { /* success */
6206 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6207 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6209 gtk_text_buffer_set_text(buffer, "", -1);
6210 compose_insert_file(compose, compose->exteditor_file);
6211 compose_changed_cb(NULL, compose);
6213 if (g_unlink(compose->exteditor_file) < 0)
6214 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6215 } else if (buf[0] == '1') { /* failed */
6216 g_warning("Couldn't exec external editor\n");
6217 if (g_unlink(compose->exteditor_file) < 0)
6218 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6219 } else if (buf[0] == '2') {
6220 g_warning("Couldn't write to file\n");
6221 } else if (buf[0] == '3') {
6222 g_warning("Pipe read failed\n");
6225 compose_set_ext_editor_sensitive(compose, TRUE);
6227 g_free(compose->exteditor_file);
6228 compose->exteditor_file = NULL;
6229 compose->exteditor_pid = -1;
6230 compose->exteditor_ch = NULL;
6231 compose->exteditor_tag = -1;
6236 static void compose_set_ext_editor_sensitive(Compose *compose,
6239 GtkItemFactory *ifactory;
6241 ifactory = gtk_item_factory_from_widget(compose->menubar);
6243 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6244 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6245 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6246 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6247 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6248 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6249 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6252 gtk_widget_set_sensitive(compose->text, sensitive);
6253 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6254 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6255 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6256 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6257 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6258 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6259 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
6260 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
6262 #endif /* G_OS_UNIX */
6265 * compose_undo_state_changed:
6267 * Change the sensivity of the menuentries undo and redo
6269 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6270 gint redo_state, gpointer data)
6272 GtkWidget *widget = GTK_WIDGET(data);
6273 GtkItemFactory *ifactory;
6275 g_return_if_fail(widget != NULL);
6277 ifactory = gtk_item_factory_from_widget(widget);
6279 switch (undo_state) {
6280 case UNDO_STATE_TRUE:
6281 if (!undostruct->undo_state) {
6282 undostruct->undo_state = TRUE;
6283 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6286 case UNDO_STATE_FALSE:
6287 if (undostruct->undo_state) {
6288 undostruct->undo_state = FALSE;
6289 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6292 case UNDO_STATE_UNCHANGED:
6294 case UNDO_STATE_REFRESH:
6295 menu_set_sensitive(ifactory, "/Edit/Undo",
6296 undostruct->undo_state);
6299 g_warning("Undo state not recognized");
6303 switch (redo_state) {
6304 case UNDO_STATE_TRUE:
6305 if (!undostruct->redo_state) {
6306 undostruct->redo_state = TRUE;
6307 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6310 case UNDO_STATE_FALSE:
6311 if (undostruct->redo_state) {
6312 undostruct->redo_state = FALSE;
6313 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6316 case UNDO_STATE_UNCHANGED:
6318 case UNDO_STATE_REFRESH:
6319 menu_set_sensitive(ifactory, "/Edit/Redo",
6320 undostruct->redo_state);
6323 g_warning("Redo state not recognized");
6328 /* callback functions */
6330 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6331 * includes "non-client" (windows-izm) in calculation, so this calculation
6332 * may not be accurate.
6334 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6335 GtkAllocation *allocation,
6336 GtkSHRuler *shruler)
6338 if (prefs_common.show_ruler) {
6339 gint char_width = 0, char_height = 0;
6340 gint line_width_in_chars;
6342 gtkut_get_font_size(GTK_WIDGET(widget),
6343 &char_width, &char_height);
6344 line_width_in_chars =
6345 (allocation->width - allocation->x) / char_width;
6347 /* got the maximum */
6348 gtk_ruler_set_range(GTK_RULER(shruler),
6349 0.0, line_width_in_chars, 0,
6350 /*line_width_in_chars*/ char_width);
6356 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6358 Compose *compose = (Compose *)data;
6361 gchar *folderidentifier;
6363 ac = account_find_from_id(
6364 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
6365 g_return_if_fail(ac != NULL);
6367 if (ac != compose->account)
6368 compose_select_account(compose, ac, FALSE);
6370 /* Set message save folder */
6371 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6372 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
6374 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
6375 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
6377 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6378 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6379 folderidentifier = folder_item_get_identifier(account_get_special_folder
6380 (compose->account, F_OUTBOX));
6381 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
6382 g_free(folderidentifier);
6386 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
6387 GtkTreeViewColumn *column, Compose *compose)
6389 compose_attach_property(compose);
6392 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6395 Compose *compose = (Compose *)data;
6397 if (!event) return FALSE;
6399 if (event->button == 3) {
6400 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6401 NULL, NULL, event->button, event->time);
6408 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6411 Compose *compose = (Compose *)data;
6413 if (!event) return FALSE;
6415 switch (event->keyval) {
6417 compose_attach_remove_selected(compose);
6423 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6425 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6426 toolbar_comp_set_sensitive(compose, allow);
6427 menu_set_sensitive(ifactory, "/Message", allow);
6428 menu_set_sensitive(ifactory, "/Edit", allow);
6430 menu_set_sensitive(ifactory, "/Spelling", allow);
6432 menu_set_sensitive(ifactory, "/Options", allow);
6433 menu_set_sensitive(ifactory, "/Tools", allow);
6434 menu_set_sensitive(ifactory, "/Help", allow);
6436 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
6440 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6442 Compose *compose = (Compose *)data;
6444 if (prefs_common.work_offline)
6445 if (alertpanel(_("Offline warning"),
6446 _("You're working offline. Override?"),
6447 GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT)
6450 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
6451 gtk_timeout_remove(compose->draft_timeout_tag);
6452 compose->draft_timeout_tag = -1;
6455 compose_send(compose);
6458 static void compose_send_later_cb(gpointer data, guint action,
6461 Compose *compose = (Compose *)data;
6464 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6466 compose_close(compose);
6467 else if (val == -2) {
6468 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
6472 void compose_draft (gpointer data)
6474 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6477 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6479 Compose *compose = (Compose *)data;
6483 MsgFlags flag = {0, 0};
6484 static gboolean lock = FALSE;
6485 MsgInfo *newmsginfo;
6490 draft = account_get_special_folder(compose->account, F_DRAFT);
6491 g_return_if_fail(draft != NULL);
6495 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
6496 G_DIR_SEPARATOR, compose);
6497 if ((fp = g_fopen(tmp, "wb")) == NULL) {
6498 FILE_OP_ERROR(tmp, "fopen");
6502 /* chmod for security */
6503 if (change_file_mode_rw(fp, tmp) < 0) {
6504 FILE_OP_ERROR(tmp, "chmod");
6505 g_warning("can't change file mode\n");
6508 /* Save draft infos */
6509 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
6510 fprintf(fp, "S:%s\n", compose->account->address);
6511 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
6512 gchar *savefolderid;
6514 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6515 fprintf(fp, "SCF:%s\n", savefolderid);
6516 g_free(savefolderid);
6518 if (compose->privacy_system) {
6519 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
6520 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
6521 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
6525 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
6534 folder_item_scan(draft);
6535 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
6542 draft->mtime = 0; /* force updating */
6544 if (compose->mode == COMPOSE_REEDIT) {
6545 compose_remove_reedit_target(compose);
6548 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6550 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6551 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
6552 if (compose_use_attach(compose))
6553 procmsg_msginfo_set_flags(newmsginfo, 0,
6554 MSG_HAS_ATTACHMENT);
6556 procmsg_msginfo_free(newmsginfo);
6559 folder_item_scan(draft);
6563 if (action == COMPOSE_QUIT_EDITING)
6564 compose_close(compose);
6569 path = folder_item_fetch_msg(draft, msgnum);
6570 g_return_if_fail(path != NULL);
6571 if (g_stat(path, &s) < 0) {
6572 FILE_OP_ERROR(path, "stat");
6579 procmsg_msginfo_free(compose->targetinfo);
6580 compose->targetinfo = procmsg_msginfo_new();
6581 compose->targetinfo->msgnum = msgnum;
6582 compose->targetinfo->size = s.st_size;
6583 compose->targetinfo->mtime = s.st_mtime;
6584 compose->targetinfo->folder = draft;
6585 compose->mode = COMPOSE_REEDIT;
6587 if (action == COMPOSE_AUTO_SAVE) {
6588 compose->autosaved_draft = compose->targetinfo;
6593 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6595 Compose *compose = (Compose *)data;
6598 if (compose->redirect_filename != NULL)
6601 file_list = filesel_select_multiple_files_open(_("Select file"));
6606 for ( tmp = file_list; tmp; tmp = tmp->next) {
6607 gchar *file = (gchar *) tmp->data;
6608 gchar *utf8_filename = conv_filename_to_utf8(file);
6609 compose_attach_append(compose, file, utf8_filename, NULL);
6610 compose_changed_cb(NULL, compose);
6612 g_free(utf8_filename);
6614 g_list_free(file_list);
6618 static void compose_insert_file_cb(gpointer data, guint action,
6621 Compose *compose = (Compose *)data;
6624 file_list = filesel_select_multiple_files_open(_("Select file"));
6629 for ( tmp = file_list; tmp; tmp = tmp->next) {
6630 gchar *file = (gchar *) tmp->data;
6631 gchar *filedup = g_strdup(file);
6632 gchar *shortfile = g_path_get_basename(filedup);
6633 ComposeInsertResult res;
6635 res = compose_insert_file(compose, file);
6636 if (res == COMPOSE_INSERT_READ_ERROR) {
6637 alertpanel_error(_("File '%s' could not be read."), shortfile);
6638 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
6639 alertpanel_error(_("File '%s' contained invalid characters\n"
6640 "for the current encoding, insertion may be incorrect."), shortfile);
6646 g_list_free(file_list);
6650 static void compose_insert_sig_cb(gpointer data, guint action,
6653 Compose *compose = (Compose *)data;
6655 compose_insert_sig(compose, FALSE);
6658 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6662 Compose *compose = (Compose *)data;
6664 gtkut_widget_get_uposition(widget, &x, &y);
6665 prefs_common.compose_x = x;
6666 prefs_common.compose_y = y;
6668 if (compose->sending)
6670 compose_close_cb(compose, 0, NULL);
6674 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6676 Compose *compose = (Compose *)data;
6680 if (compose->exteditor_tag != -1) {
6681 if (!compose_ext_editor_kill(compose))
6686 if (compose->modified) {
6687 val = alertpanel(_("Discard message"),
6688 _("This message has been modified. discard it?"),
6689 _("Discard"), _("to Draft"), GTK_STOCK_CANCEL);
6692 case G_ALERTDEFAULT:
6693 if (prefs_common.autosave)
6694 compose_remove_draft(compose);
6696 case G_ALERTALTERNATE:
6697 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6704 compose_close(compose);
6707 static void compose_set_encoding_cb(gpointer data, guint action,
6710 Compose *compose = (Compose *)data;
6712 if (GTK_CHECK_MENU_ITEM(widget)->active)
6713 compose->out_encoding = (CharSet)action;
6716 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6718 Compose *compose = (Compose *)data;
6720 addressbook_open(compose);
6723 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6725 Compose *compose = (Compose *)data;
6730 tmpl = g_object_get_data(G_OBJECT(widget), "template");
6731 g_return_if_fail(tmpl != NULL);
6733 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
6735 val = alertpanel(_("Apply template"), msg,
6736 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
6739 if (val == G_ALERTDEFAULT)
6740 compose_template_apply(compose, tmpl, TRUE);
6741 else if (val == G_ALERTALTERNATE)
6742 compose_template_apply(compose, tmpl, FALSE);
6745 static void compose_ext_editor_cb(gpointer data, guint action,
6748 Compose *compose = (Compose *)data;
6750 compose_exec_ext_editor(compose);
6753 static void compose_undo_cb(Compose *compose)
6755 gboolean prev_autowrap = compose->autowrap;
6757 compose->autowrap = FALSE;
6758 undo_undo(compose->undostruct);
6759 compose->autowrap = prev_autowrap;
6762 static void compose_redo_cb(Compose *compose)
6764 gboolean prev_autowrap = compose->autowrap;
6766 compose->autowrap = FALSE;
6767 undo_redo(compose->undostruct);
6768 compose->autowrap = prev_autowrap;
6771 static void entry_cut_clipboard(GtkWidget *entry)
6773 if (GTK_IS_EDITABLE(entry))
6774 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
6775 else if (GTK_IS_TEXT_VIEW(entry))
6776 gtk_text_buffer_cut_clipboard(
6777 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
6778 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
6782 static void entry_copy_clipboard(GtkWidget *entry)
6784 if (GTK_IS_EDITABLE(entry))
6785 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
6786 else if (GTK_IS_TEXT_VIEW(entry))
6787 gtk_text_buffer_copy_clipboard(
6788 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
6789 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
6792 static void entry_paste_clipboard(GtkWidget *entry, gboolean wrap)
6794 if (GTK_IS_EDITABLE(entry))
6795 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
6796 else if (GTK_IS_TEXT_VIEW(entry)) {
6797 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
6798 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
6799 GtkTextIter start_iter, end_iter;
6802 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
6804 if (contents == NULL)
6807 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
6808 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
6810 start = gtk_text_iter_get_offset(&start_iter);
6812 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
6815 end = start + strlen(contents);
6816 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
6817 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
6818 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
6824 static void entry_allsel(GtkWidget *entry)
6826 if (GTK_IS_EDITABLE(entry))
6827 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
6828 else if (GTK_IS_TEXT_VIEW(entry)) {
6829 GtkTextIter startiter, enditer;
6830 GtkTextBuffer *textbuf;
6832 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
6833 gtk_text_buffer_get_start_iter(textbuf, &startiter);
6834 gtk_text_buffer_get_end_iter(textbuf, &enditer);
6836 gtk_text_buffer_move_mark_by_name(textbuf,
6837 "selection_bound", &startiter);
6838 gtk_text_buffer_move_mark_by_name(textbuf,
6839 "insert", &enditer);
6843 static void compose_cut_cb(Compose *compose)
6845 if (compose->focused_editable &&
6846 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6847 entry_cut_clipboard(compose->focused_editable);
6850 static void compose_copy_cb(Compose *compose)
6852 if (compose->focused_editable &&
6853 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6854 entry_copy_clipboard(compose->focused_editable);
6857 #define BLOCK_WRAP() { \
6858 prev_autowrap = compose->autowrap; \
6859 buffer = gtk_text_view_get_buffer( \
6860 GTK_TEXT_VIEW(compose->text)); \
6861 compose->autowrap = FALSE; \
6863 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
6864 G_CALLBACK(compose_changed_cb), \
6866 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
6867 G_CALLBACK(text_inserted), \
6870 #define UNBLOCK_WRAP() { \
6871 compose->autowrap = prev_autowrap; \
6872 if (compose->autowrap) \
6873 compose_wrap_all(compose); \
6875 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
6876 G_CALLBACK(compose_changed_cb), \
6878 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
6879 G_CALLBACK(text_inserted), \
6883 static void compose_paste_cb(Compose *compose)
6886 GtkTextBuffer *buffer;
6888 if (compose->focused_editable &&
6889 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6890 entry_paste_clipboard(compose->focused_editable, prefs_common.linewrap_pastes);
6894 static void compose_paste_as_quote_cb(Compose *compose)
6896 gint wrap_quote = prefs_common.linewrap_quote;
6897 if (compose->focused_editable &&
6898 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6899 /* let text_insert() (called directly or at a later time
6900 * after the gtk_editable_paste_clipboard) know that
6901 * text is to be inserted as a quotation. implemented
6902 * by using a simple refcount... */
6903 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
6904 G_OBJECT(compose->focused_editable),
6905 "paste_as_quotation"));
6906 g_object_set_data(G_OBJECT(compose->focused_editable),
6907 "paste_as_quotation",
6908 GINT_TO_POINTER(paste_as_quotation + 1));
6909 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
6910 entry_paste_clipboard(compose->focused_editable, prefs_common.linewrap_pastes);
6911 prefs_common.linewrap_quote = wrap_quote;
6915 static void compose_paste_no_wrap_cb(Compose *compose)
6918 GtkTextBuffer *buffer;
6920 if (compose->focused_editable &&
6921 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6922 entry_paste_clipboard(compose->focused_editable, FALSE);
6926 static void compose_paste_wrap_cb(Compose *compose)
6929 GtkTextBuffer *buffer;
6931 if (compose->focused_editable &&
6932 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6933 entry_paste_clipboard(compose->focused_editable, TRUE);
6937 static void compose_allsel_cb(Compose *compose)
6939 if (compose->focused_editable &&
6940 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6941 entry_allsel(compose->focused_editable);
6944 static void textview_move_beginning_of_line (GtkTextView *text)
6946 GtkTextBuffer *buffer;
6950 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
6952 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6953 mark = gtk_text_buffer_get_insert(buffer);
6954 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
6955 gtk_text_iter_set_line_offset(&ins, 0);
6956 gtk_text_buffer_place_cursor(buffer, &ins);
6959 static void textview_move_forward_character (GtkTextView *text)
6961 GtkTextBuffer *buffer;
6965 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
6967 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6968 mark = gtk_text_buffer_get_insert(buffer);
6969 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
6970 if (gtk_text_iter_forward_cursor_position(&ins))
6971 gtk_text_buffer_place_cursor(buffer, &ins);
6974 static void textview_move_backward_character (GtkTextView *text)
6976 GtkTextBuffer *buffer;
6980 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
6982 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6983 mark = gtk_text_buffer_get_insert(buffer);
6984 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
6985 if (gtk_text_iter_backward_cursor_position(&ins))
6986 gtk_text_buffer_place_cursor(buffer, &ins);
6989 static void textview_move_forward_word (GtkTextView *text)
6991 GtkTextBuffer *buffer;
6996 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
6998 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6999 mark = gtk_text_buffer_get_insert(buffer);
7000 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7001 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7002 if (gtk_text_iter_forward_word_ends(&ins, count)) {
7003 gtk_text_iter_backward_word_start(&ins);
7004 gtk_text_buffer_place_cursor(buffer, &ins);
7008 static void textview_move_backward_word (GtkTextView *text)
7010 GtkTextBuffer *buffer;
7015 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7017 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7018 mark = gtk_text_buffer_get_insert(buffer);
7019 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7020 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7021 if (gtk_text_iter_backward_word_starts(&ins, 1))
7022 gtk_text_buffer_place_cursor(buffer, &ins);
7025 static void textview_move_end_of_line (GtkTextView *text)
7027 GtkTextBuffer *buffer;
7031 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7033 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7034 mark = gtk_text_buffer_get_insert(buffer);
7035 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7036 if (gtk_text_iter_forward_to_line_end(&ins))
7037 gtk_text_buffer_place_cursor(buffer, &ins);
7040 static void textview_move_next_line (GtkTextView *text)
7042 GtkTextBuffer *buffer;
7047 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7049 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7050 mark = gtk_text_buffer_get_insert(buffer);
7051 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7052 offset = gtk_text_iter_get_line_offset(&ins);
7053 if (gtk_text_iter_forward_line(&ins)) {
7054 gtk_text_iter_set_line_offset(&ins, offset);
7055 gtk_text_buffer_place_cursor(buffer, &ins);
7059 static void textview_move_previous_line (GtkTextView *text)
7061 GtkTextBuffer *buffer;
7066 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7068 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7069 mark = gtk_text_buffer_get_insert(buffer);
7070 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7071 offset = gtk_text_iter_get_line_offset(&ins);
7072 if (gtk_text_iter_backward_line(&ins)) {
7073 gtk_text_iter_set_line_offset(&ins, offset);
7074 gtk_text_buffer_place_cursor(buffer, &ins);
7078 static void textview_delete_forward_character (GtkTextView *text)
7080 GtkTextBuffer *buffer;
7082 GtkTextIter ins, end_iter;
7084 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7086 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7087 mark = gtk_text_buffer_get_insert(buffer);
7088 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7090 if (gtk_text_iter_forward_char(&end_iter)) {
7091 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7095 static void textview_delete_backward_character (GtkTextView *text)
7097 GtkTextBuffer *buffer;
7099 GtkTextIter ins, end_iter;
7101 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7103 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7104 mark = gtk_text_buffer_get_insert(buffer);
7105 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7107 if (gtk_text_iter_backward_char(&end_iter)) {
7108 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7112 static void textview_delete_forward_word (GtkTextView *text)
7114 GtkTextBuffer *buffer;
7116 GtkTextIter ins, end_iter;
7118 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7120 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7121 mark = gtk_text_buffer_get_insert(buffer);
7122 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7124 if (gtk_text_iter_forward_word_end(&end_iter)) {
7125 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7129 static void textview_delete_backward_word (GtkTextView *text)
7131 GtkTextBuffer *buffer;
7133 GtkTextIter ins, end_iter;
7135 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7137 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7138 mark = gtk_text_buffer_get_insert(buffer);
7139 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7141 if (gtk_text_iter_backward_word_start(&end_iter)) {
7142 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7146 static void textview_delete_line (GtkTextView *text)
7148 GtkTextBuffer *buffer;
7150 GtkTextIter ins, start_iter, end_iter;
7153 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7155 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7156 mark = gtk_text_buffer_get_insert(buffer);
7157 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7160 gtk_text_iter_set_line_offset(&start_iter, 0);
7163 if (gtk_text_iter_ends_line(&end_iter))
7164 found = gtk_text_iter_forward_char(&end_iter);
7166 found = gtk_text_iter_forward_to_line_end(&end_iter);
7169 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7172 static void textview_delete_to_line_end (GtkTextView *text)
7174 GtkTextBuffer *buffer;
7176 GtkTextIter ins, end_iter;
7179 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7181 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7182 mark = gtk_text_buffer_get_insert(buffer);
7183 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7185 if (gtk_text_iter_ends_line(&end_iter))
7186 found = gtk_text_iter_forward_char(&end_iter);
7188 found = gtk_text_iter_forward_to_line_end(&end_iter);
7190 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7193 static void compose_advanced_action_cb(Compose *compose,
7194 ComposeCallAdvancedAction action)
7196 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7198 void (*do_action) (GtkTextView *text);
7199 } action_table[] = {
7200 {textview_move_beginning_of_line},
7201 {textview_move_forward_character},
7202 {textview_move_backward_character},
7203 {textview_move_forward_word},
7204 {textview_move_backward_word},
7205 {textview_move_end_of_line},
7206 {textview_move_next_line},
7207 {textview_move_previous_line},
7208 {textview_delete_forward_character},
7209 {textview_delete_backward_character},
7210 {textview_delete_forward_word},
7211 {textview_delete_backward_word},
7212 {textview_delete_line},
7213 {NULL}, /* gtk_stext_delete_line_n */
7214 {textview_delete_to_line_end}
7217 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
7219 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
7220 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
7221 if (action_table[action].do_action)
7222 action_table[action].do_action(text);
7224 g_warning("Not implemented yet.");
7228 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
7232 if (GTK_IS_EDITABLE(widget)) {
7233 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
7234 gtk_editable_set_position(GTK_EDITABLE(widget),
7239 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
7240 compose->focused_editable = widget;
7243 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
7245 if (compose->modified == FALSE) {
7246 compose->modified = TRUE;
7247 compose_set_title(compose);
7251 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
7253 Compose *compose = (Compose *)data;
7256 compose_wrap_all_full(compose, TRUE);
7258 compose_wrap_paragraph(compose, NULL, TRUE);
7261 static void compose_toggle_autowrap_cb(gpointer data, guint action,
7264 Compose *compose = (Compose *)data;
7265 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7266 if (compose->autowrap)
7267 compose_wrap_all_full(compose, TRUE);
7270 static void compose_toggle_sign_cb(gpointer data, guint action,
7273 Compose *compose = (Compose *)data;
7275 if (GTK_CHECK_MENU_ITEM(widget)->active)
7276 compose->use_signing = TRUE;
7278 compose->use_signing = FALSE;
7281 static void compose_toggle_encrypt_cb(gpointer data, guint action,
7284 Compose *compose = (Compose *)data;
7286 if (GTK_CHECK_MENU_ITEM(widget)->active)
7287 compose->use_encryption = TRUE;
7289 compose->use_encryption = FALSE;
7292 static void activate_privacy_system(Compose *compose, PrefsAccount *account)
7294 g_free(compose->privacy_system);
7295 compose->privacy_system = g_strdup(account->default_privacy_system);
7296 compose_update_privacy_system_menu_item(compose);
7299 static void compose_toggle_ruler_cb(gpointer data, guint action,
7302 Compose *compose = (Compose *)data;
7304 if (GTK_CHECK_MENU_ITEM(widget)->active) {
7305 gtk_widget_show(compose->ruler_hbox);
7306 prefs_common.show_ruler = TRUE;
7308 gtk_widget_hide(compose->ruler_hbox);
7309 gtk_widget_queue_resize(compose->edit_vbox);
7310 prefs_common.show_ruler = FALSE;
7314 static void compose_attach_drag_received_cb (GtkWidget *widget,
7315 GdkDragContext *drag_context,
7318 GtkSelectionData *data,
7323 Compose *compose = (Compose *)user_data;
7326 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7327 list = uri_list_extract_filenames((const gchar *)data->data);
7328 for (tmp = list; tmp != NULL; tmp = tmp->next)
7329 compose_attach_append
7330 (compose, (const gchar *)tmp->data,
7331 (const gchar *)tmp->data, NULL);
7332 if (list) compose_changed_cb(NULL, compose);
7333 list_free_strings(list);
7338 static gboolean compose_drag_drop(GtkWidget *widget,
7339 GdkDragContext *drag_context,
7341 guint time, gpointer user_data)
7343 /* not handling this signal makes compose_insert_drag_received_cb
7348 static void compose_insert_drag_received_cb (GtkWidget *widget,
7349 GdkDragContext *drag_context,
7352 GtkSelectionData *data,
7357 Compose *compose = (Compose *)user_data;
7360 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
7362 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7363 list = uri_list_extract_filenames((const gchar *)data->data);
7364 for (tmp = list; tmp != NULL; tmp = tmp->next) {
7365 compose_insert_file(compose, (const gchar *)tmp->data);
7367 list_free_strings(list);
7369 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7372 gchar *tmpfile = get_tmp_file();
7373 str_write_to_file((const gchar *)data->data, tmpfile);
7374 compose_insert_file(compose, tmpfile);
7377 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7380 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7383 static void compose_header_drag_received_cb (GtkWidget *widget,
7384 GdkDragContext *drag_context,
7387 GtkSelectionData *data,
7392 GtkEditable *entry = (GtkEditable *)user_data;
7393 gchar *email = (gchar *)data->data;
7395 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
7398 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
7399 gchar *decoded=g_new(gchar, strlen(email));
7402 email += strlen("mailto:");
7403 decode_uri(decoded, email); /* will fit */
7404 gtk_editable_delete_text(entry, 0, -1);
7405 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
7406 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7410 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7413 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
7416 Compose *compose = (Compose *)data;
7418 if (GTK_CHECK_MENU_ITEM(widget)->active)
7419 compose->return_receipt = TRUE;
7421 compose->return_receipt = FALSE;
7424 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
7427 Compose *compose = (Compose *)data;
7429 if (GTK_CHECK_MENU_ITEM(widget)->active)
7430 compose->remove_references = TRUE;
7432 compose->remove_references = FALSE;
7435 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
7437 ComposeHeaderEntry *headerentry)
7439 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
7440 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
7441 !(event->state & GDK_MODIFIER_MASK) &&
7442 (event->keyval == GDK_BackSpace) &&
7443 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
7444 gtk_container_remove
7445 (GTK_CONTAINER(headerentry->compose->header_table),
7446 headerentry->combo);
7447 gtk_container_remove
7448 (GTK_CONTAINER(headerentry->compose->header_table),
7449 headerentry->entry);
7450 headerentry->compose->header_list =
7451 g_slist_remove(headerentry->compose->header_list,
7453 g_free(headerentry);
7454 } else if (event->keyval == GDK_Tab) {
7455 if (headerentry->compose->header_last == headerentry) {
7456 /* Override default next focus, and give it to subject_entry
7457 * instead of notebook tabs
7459 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
7460 gtk_widget_grab_focus(headerentry->compose->subject_entry);
7467 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
7468 ComposeHeaderEntry *headerentry)
7470 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
7471 headerentry->compose->header_list =
7472 g_slist_append(headerentry->compose->header_list,
7475 compose_create_header_entry(headerentry->compose);
7476 g_signal_handlers_disconnect_matched
7477 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
7478 0, 0, NULL, NULL, headerentry);
7480 /* Automatically scroll down */
7481 compose_show_first_last_header(headerentry->compose, FALSE);
7487 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
7489 GtkAdjustment *vadj;
7491 g_return_if_fail(compose);
7492 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
7493 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
7495 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
7496 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
7499 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
7500 const gchar *text, gint len, Compose *compose)
7502 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
7503 (G_OBJECT(compose->text), "paste_as_quotation"));
7506 g_return_if_fail(text != NULL);
7508 g_signal_handlers_block_by_func(G_OBJECT(buffer),
7509 G_CALLBACK(text_inserted),
7511 if (paste_as_quotation) {
7518 new_text = g_strndup(text, len);
7519 if (prefs_common.quotemark && *prefs_common.quotemark)
7520 qmark = prefs_common.quotemark;
7524 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
7525 gtk_text_buffer_place_cursor(buffer, iter);
7527 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
7529 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
7530 GINT_TO_POINTER(paste_as_quotation - 1));
7532 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
7534 gtk_text_buffer_insert(buffer, iter, text, len);
7536 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
7538 /* compose_wrap_all_full(compose, FALSE); */
7539 compose_wrap_paragraph(compose, iter, FALSE);
7541 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
7542 gtk_text_buffer_delete_mark(buffer, mark);
7544 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
7545 G_CALLBACK(text_inserted),
7547 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
7549 if (prefs_common.autosave &&
7550 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
7551 compose->draft_timeout_tag = gtk_timeout_add
7552 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
7554 static gint compose_defer_auto_save_draft(Compose *compose)
7556 compose->draft_timeout_tag = -1;
7557 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
7562 static void compose_check_all(Compose *compose)
7564 if (compose->gtkaspell)
7565 gtkaspell_check_all(compose->gtkaspell);
7568 static void compose_highlight_all(Compose *compose)
7570 if (compose->gtkaspell)
7571 gtkaspell_highlight_all(compose->gtkaspell);
7574 static void compose_check_backwards(Compose *compose)
7576 if (compose->gtkaspell)
7577 gtkaspell_check_backwards(compose->gtkaspell);
7579 GtkItemFactory *ifactory;
7580 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7581 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7582 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
7586 static void compose_check_forwards_go(Compose *compose)
7588 if (compose->gtkaspell)
7589 gtkaspell_check_forwards_go(compose->gtkaspell);
7591 GtkItemFactory *ifactory;
7592 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7593 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7594 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
7600 *\brief Guess originating forward account from MsgInfo and several
7601 * "common preference" settings. Return NULL if no guess.
7603 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
7605 PrefsAccount *account = NULL;
7607 g_return_val_if_fail(msginfo, NULL);
7608 g_return_val_if_fail(msginfo->folder, NULL);
7609 g_return_val_if_fail(msginfo->folder->prefs, NULL);
7611 if (msginfo->folder->prefs->enable_default_account)
7612 account = account_find_from_id(msginfo->folder->prefs->default_account);
7615 account = msginfo->folder->folder->account;
7617 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
7619 Xstrdup_a(to, msginfo->to, return NULL);
7620 extract_address(to);
7621 account = account_find_from_address(to);
7624 if (!account && prefs_common.forward_account_autosel) {
7626 if (!procheader_get_header_from_msginfo
7627 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
7628 extract_address(cc);
7629 account = account_find_from_address(cc);
7636 static void compose_close(Compose *compose)
7640 g_return_if_fail(compose);
7641 gtkut_widget_get_uposition(compose->window, &x, &y);
7642 prefs_common.compose_x = x;
7643 prefs_common.compose_y = y;
7644 compose_destroy(compose);
7648 * Add entry field for each address in list.
7649 * \param compose E-Mail composition object.
7650 * \param listAddress List of (formatted) E-Mail addresses.
7652 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
7657 addr = ( gchar * ) node->data;
7658 compose_entry_append( compose, addr, COMPOSE_TO );
7659 node = g_list_next( node );
7663 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
7667 GSList *new_msglist = NULL;
7668 MsgInfo *tmp_msginfo = NULL;
7670 g_return_if_fail(msgview != NULL);
7672 g_return_if_fail(msginfo_list != NULL);
7674 if (g_slist_length(msginfo_list) == 1) {
7675 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
7676 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
7678 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
7679 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
7681 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
7682 orig_msginfo, mimeinfo);
7683 if (tmp_msginfo != NULL) {
7684 new_msglist = g_slist_append(NULL, tmp_msginfo);
7689 body = messageview_get_selection(msgview);
7692 compose_reply_mode((ComposeMode)action, new_msglist, body);
7693 procmsg_msginfo_free(tmp_msginfo);
7694 g_slist_free(new_msglist);
7696 compose_reply_mode((ComposeMode)action, msginfo_list, body);