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 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
959 g_return_if_fail(msginfo_list != NULL);
961 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
962 g_return_if_fail(msginfo != NULL);
964 list_len = g_slist_length(msginfo_list);
968 compose_reply(msginfo, prefs_common.reply_with_quote,
969 FALSE, prefs_common.default_reply_list, FALSE, body);
971 case COMPOSE_REPLY_WITH_QUOTE:
972 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
974 case COMPOSE_REPLY_WITHOUT_QUOTE:
975 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
977 case COMPOSE_REPLY_TO_SENDER:
978 compose_reply(msginfo, prefs_common.reply_with_quote,
979 FALSE, FALSE, TRUE, body);
981 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
982 compose_followup_and_reply_to(msginfo,
983 prefs_common.reply_with_quote,
986 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
987 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
989 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
990 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
992 case COMPOSE_REPLY_TO_ALL:
993 compose_reply(msginfo, prefs_common.reply_with_quote,
994 TRUE, FALSE, FALSE, body);
996 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
997 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
999 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1000 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
1002 case COMPOSE_REPLY_TO_LIST:
1003 compose_reply(msginfo, prefs_common.reply_with_quote,
1004 FALSE, TRUE, FALSE, body);
1006 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1007 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
1009 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1010 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
1012 case COMPOSE_FORWARD:
1013 if (prefs_common.forward_as_attachment) {
1014 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1017 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1021 case COMPOSE_FORWARD_INLINE:
1022 /* check if we reply to more than one Message */
1023 if (list_len == 1) {
1024 compose_forward(NULL, msginfo, FALSE, body, FALSE);
1027 /* more messages FALL THROUGH */
1028 case COMPOSE_FORWARD_AS_ATTACH:
1029 compose_forward_multiple(NULL, msginfo_list);
1031 case COMPOSE_REDIRECT:
1032 compose_redirect(NULL, msginfo);
1035 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1039 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1040 gboolean to_ml, gboolean to_sender,
1043 compose_generic_reply(msginfo, quote, to_all, to_ml,
1044 to_sender, FALSE, body);
1047 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1052 compose_generic_reply(msginfo, quote, to_all, FALSE,
1053 to_sender, TRUE, body);
1056 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1057 gboolean to_all, gboolean to_ml,
1059 gboolean followup_and_reply_to,
1062 GtkItemFactory *ifactory;
1064 PrefsAccount *account = NULL;
1065 PrefsAccount *reply_account;
1066 GtkTextView *textview;
1067 GtkTextBuffer *textbuf;
1071 g_return_if_fail(msginfo != NULL);
1072 g_return_if_fail(msginfo->folder != NULL);
1074 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1076 g_return_if_fail(account != NULL);
1078 if (to_sender && account->protocol == A_NNTP &&
1079 !followup_and_reply_to) {
1081 account_find_from_address(account->address);
1083 reply_account = compose_current_mail_account();
1087 reply_account = account;
1089 compose = compose_create(account, COMPOSE_REPLY);
1090 ifactory = gtk_item_factory_from_widget(compose->menubar);
1092 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1093 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1095 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1096 if (!compose->replyinfo)
1097 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1099 if (msginfo->folder && msginfo->folder->ret_rcpt)
1100 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1102 /* Set save folder */
1103 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1104 gchar *folderidentifier;
1106 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1107 folderidentifier = folder_item_get_identifier(msginfo->folder);
1108 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1109 g_free(folderidentifier);
1112 if (compose_parse_header(compose, msginfo) < 0) return;
1113 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1114 to_sender, followup_and_reply_to);
1115 compose_show_first_last_header(compose, TRUE);
1117 textview = (GTK_TEXT_VIEW(compose->text));
1118 textbuf = gtk_text_view_get_buffer(textview);
1119 compose_create_tags(textview, compose);
1121 undo_block(compose->undostruct);
1123 if (msginfo->folder && msginfo->folder->prefs &&
1124 msginfo->folder->prefs &&
1125 msginfo->folder->prefs->enable_default_dictionary &&
1127 gtkaspell_change_dict(compose->gtkaspell,
1128 msginfo->folder->prefs->default_dictionary);
1134 if (prefs_common.quotemark && *prefs_common.quotemark)
1135 qmark = prefs_common.quotemark;
1139 compose_quote_fmt(compose, compose->replyinfo,
1140 prefs_common.quotefmt,
1143 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1144 compose_force_encryption(compose, account, FALSE);
1147 if (account->auto_sig)
1148 compose_insert_sig(compose, FALSE);
1150 cursor_pos = quote_fmt_get_cursor_pos();
1151 gtk_text_buffer_get_start_iter(textbuf, &iter);
1152 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cursor_pos);
1153 gtk_text_buffer_place_cursor(textbuf, &iter);
1155 compose_wrap_all(compose);
1157 gtk_widget_grab_focus(compose->text);
1159 undo_unblock(compose->undostruct);
1161 if (prefs_common.auto_exteditor)
1162 compose_exec_ext_editor(compose);
1165 #define INSERT_FW_HEADER(var, hdr) \
1166 if (msginfo->var && *msginfo->var) { \
1167 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1168 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1169 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1172 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1173 gboolean as_attach, const gchar *body,
1174 gboolean no_extedit)
1177 GtkTextView *textview;
1178 GtkTextBuffer *textbuf;
1181 g_return_val_if_fail(msginfo != NULL, NULL);
1182 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1185 !(account = compose_guess_forward_account_from_msginfo
1187 account = cur_account;
1189 compose = compose_create(account, COMPOSE_FORWARD);
1191 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1192 if (!compose->fwdinfo)
1193 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1195 if (msginfo->subject && *msginfo->subject) {
1196 gchar *buf, *buf2, *p;
1198 buf = p = g_strdup(msginfo->subject);
1199 p += subject_get_prefix_length(p);
1200 memmove(buf, p, strlen(p) + 1);
1202 buf2 = g_strdup_printf("Fw: %s", buf);
1203 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1209 textview = GTK_TEXT_VIEW(compose->text);
1210 textbuf = gtk_text_view_get_buffer(textview);
1211 compose_create_tags(textview, compose);
1216 msgfile = procmsg_get_message_file_path(msginfo);
1217 if (!is_file_exist(msgfile))
1218 g_warning("%s: file not exist\n", msgfile);
1220 compose_attach_append(compose, msgfile, msgfile,
1226 MsgInfo *full_msginfo;
1228 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1230 full_msginfo = procmsg_msginfo_copy(msginfo);
1232 if (prefs_common.fw_quotemark &&
1233 *prefs_common.fw_quotemark)
1234 qmark = prefs_common.fw_quotemark;
1238 compose_quote_fmt(compose, full_msginfo,
1239 prefs_common.fw_quotefmt,
1241 compose_attach_parts(compose, msginfo);
1243 procmsg_msginfo_free(full_msginfo);
1246 if (account->auto_sig)
1247 compose_insert_sig(compose, FALSE);
1249 compose_wrap_all(compose);
1251 gtk_text_buffer_get_start_iter(textbuf, &iter);
1252 gtk_text_buffer_place_cursor(textbuf, &iter);
1254 gtk_widget_grab_focus(compose->header_last->entry);
1256 if (!no_extedit && prefs_common.auto_exteditor)
1257 compose_exec_ext_editor(compose);
1260 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1261 gchar *folderidentifier;
1263 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1264 folderidentifier = folder_item_get_identifier(msginfo->folder);
1265 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1266 g_free(folderidentifier);
1272 #undef INSERT_FW_HEADER
1274 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1277 GtkTextView *textview;
1278 GtkTextBuffer *textbuf;
1283 g_return_val_if_fail(msginfo_list != NULL, NULL);
1285 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1286 if (((MsgInfo *)msginfo->data)->folder == NULL)
1289 /* guess account from first selected message */
1291 !(account = compose_guess_forward_account_from_msginfo
1292 (msginfo_list->data)))
1293 account = cur_account;
1295 g_return_val_if_fail(account != NULL, NULL);
1297 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1298 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1299 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1302 compose = compose_create(account, COMPOSE_FORWARD);
1304 textview = GTK_TEXT_VIEW(compose->text);
1305 textbuf = gtk_text_view_get_buffer(textview);
1306 compose_create_tags(textview, compose);
1308 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1309 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1310 if (!is_file_exist(msgfile))
1311 g_warning("%s: file not exist\n", msgfile);
1313 compose_attach_append(compose, msgfile, msgfile,
1318 if (account->auto_sig)
1319 compose_insert_sig(compose, FALSE);
1321 compose_wrap_all(compose);
1323 gtk_text_buffer_get_start_iter(textbuf, &iter);
1324 gtk_text_buffer_place_cursor(textbuf, &iter);
1326 gtk_widget_grab_focus(compose->header_last->entry);
1331 void compose_reedit(MsgInfo *msginfo)
1333 Compose *compose = NULL;
1334 PrefsAccount *account = NULL;
1335 GtkTextView *textview;
1336 GtkTextBuffer *textbuf;
1340 gchar buf[BUFFSIZE];
1341 gboolean use_signing = FALSE;
1342 gboolean use_encryption = FALSE;
1343 gchar *privacy_system = NULL;
1345 g_return_if_fail(msginfo != NULL);
1346 g_return_if_fail(msginfo->folder != NULL);
1348 if (compose_put_existing_to_front(msginfo))
1351 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1352 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1353 gchar queueheader_buf[BUFFSIZE];
1356 /* Select Account from queue headers */
1357 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1358 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1359 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1360 account = account_find_from_id(id);
1362 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1363 sizeof(queueheader_buf), "NAID:")) {
1364 id = atoi(&queueheader_buf[strlen("NAID:")]);
1365 account = account_find_from_id(id);
1367 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1368 sizeof(queueheader_buf), "MAID:")) {
1369 id = atoi(&queueheader_buf[strlen("MAID:")]);
1370 account = account_find_from_id(id);
1372 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1373 sizeof(queueheader_buf), "S:")) {
1374 account = account_find_from_address(queueheader_buf);
1376 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1377 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1378 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1379 use_signing = param;
1382 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1383 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1384 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1385 use_encryption = param;
1387 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1388 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1389 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1391 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1392 sizeof(queueheader_buf), "X-Priority: ")) {
1393 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1394 compose->priority = param;
1397 account = msginfo->folder->folder->account;
1399 if (!account && prefs_common.reedit_account_autosel) {
1400 gchar from[BUFFSIZE];
1401 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1402 extract_address(from);
1403 account = account_find_from_address(from);
1406 if (!account) account = cur_account;
1407 g_return_if_fail(account != NULL);
1409 compose = compose_create(account, COMPOSE_REEDIT);
1410 if (privacy_system != NULL) {
1411 compose->privacy_system = privacy_system;
1412 compose_use_signing(compose, use_signing);
1413 compose_use_encryption(compose, use_encryption);
1414 compose_update_privacy_system_menu_item(compose);
1416 activate_privacy_system(compose, account);
1418 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1420 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1421 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1422 gchar queueheader_buf[BUFFSIZE];
1424 /* Set message save folder */
1425 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1428 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1429 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1430 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1434 if (compose_parse_header(compose, msginfo) < 0) return;
1435 compose_reedit_set_entry(compose, msginfo);
1437 textview = GTK_TEXT_VIEW(compose->text);
1438 textbuf = gtk_text_view_get_buffer(textview);
1439 compose_create_tags(textview, compose);
1441 mark = gtk_text_buffer_get_insert(textbuf);
1442 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1444 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1445 G_CALLBACK(compose_changed_cb),
1448 if (procmime_msginfo_is_encrypted(msginfo)) {
1449 fp = procmime_get_first_encrypted_text_content(msginfo);
1451 compose_force_encryption(compose, account, TRUE);
1453 fp = procmime_get_first_text_content(msginfo);
1455 g_warning("Can't get text part\n");
1458 gboolean prev_autowrap = compose->autowrap;
1460 compose->autowrap = FALSE;
1461 while (fgets(buf, sizeof(buf), fp) != NULL) {
1463 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1465 compose->autowrap = prev_autowrap;
1469 compose_attach_parts(compose, msginfo);
1471 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1472 G_CALLBACK(compose_changed_cb),
1475 gtk_widget_grab_focus(compose->text);
1477 if (prefs_common.auto_exteditor)
1478 compose_exec_ext_editor(compose);
1481 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1485 GtkItemFactory *ifactory;
1488 g_return_val_if_fail(msginfo != NULL, NULL);
1491 account = account_get_reply_account(msginfo,
1492 prefs_common.reply_account_autosel);
1493 g_return_val_if_fail(account != NULL, NULL);
1495 compose = compose_create(account, COMPOSE_REDIRECT);
1496 ifactory = gtk_item_factory_from_widget(compose->menubar);
1497 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1498 compose->replyinfo = NULL;
1499 compose->fwdinfo = NULL;
1501 compose_show_first_last_header(compose, TRUE);
1503 gtk_widget_grab_focus(compose->header_last->entry);
1505 filename = procmsg_get_message_file_path(msginfo);
1506 if (filename == NULL)
1509 compose->redirect_filename = filename;
1511 /* Set save folder */
1512 item = msginfo->folder;
1513 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1514 gchar *folderidentifier;
1516 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1517 folderidentifier = folder_item_get_identifier(item);
1518 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1519 g_free(folderidentifier);
1522 compose_attach_parts(compose, msginfo);
1524 if (msginfo->subject)
1525 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1527 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1529 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1530 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1532 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1533 menu_set_sensitive(ifactory, "/Add...", FALSE);
1534 menu_set_sensitive(ifactory, "/Remove", FALSE);
1535 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1537 ifactory = gtk_item_factory_from_widget(compose->menubar);
1538 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1539 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1540 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1541 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1542 menu_set_sensitive(ifactory, "/Edit", FALSE);
1543 menu_set_sensitive(ifactory, "/Options", FALSE);
1544 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1545 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1547 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1548 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1549 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1550 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1551 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1552 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1553 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1558 GList *compose_get_compose_list(void)
1560 return compose_list;
1563 void compose_entry_append(Compose *compose, const gchar *address,
1564 ComposeEntryType type)
1568 gboolean in_quote = FALSE;
1569 if (!address || *address == '\0') return;
1576 header = N_("Bcc:");
1578 case COMPOSE_REPLYTO:
1579 header = N_("Reply-To:");
1581 case COMPOSE_NEWSGROUPS:
1582 header = N_("Newsgroups:");
1584 case COMPOSE_FOLLOWUPTO:
1585 header = N_( "Followup-To:");
1592 header = prefs_common.trans_hdr ? gettext(header) : header;
1594 cur = begin = (gchar *)address;
1596 /* we separate the line by commas, but not if we're inside a quoted
1598 while (*cur != '\0') {
1600 in_quote = !in_quote;
1601 if (*cur == ',' && !in_quote) {
1602 gchar *tmp = g_strdup(begin);
1604 tmp[cur-begin]='\0';
1609 compose_add_header_entry(compose, header, tmp);
1616 gchar *tmp = g_strdup(begin);
1618 tmp[cur-begin]='\0';
1623 compose_add_header_entry(compose, header, tmp);
1628 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1630 static GtkStyle *bold_style = NULL;
1631 static GdkColor bold_color;
1635 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1636 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1637 if (gtk_entry_get_text(entry) &&
1638 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1639 gtk_widget_ensure_style(GTK_WIDGET(entry));
1641 PangoFontDescription *font_desc = NULL;
1642 gtkut_convert_int_to_gdk_color
1643 (prefs_common.color_new, &bold_color);
1644 bold_style = gtk_style_copy(gtk_widget_get_style
1645 (GTK_WIDGET(entry)));
1647 font_desc = pango_font_description_from_string
1650 if (bold_style->font_desc)
1651 pango_font_description_free
1652 (bold_style->font_desc);
1653 bold_style->font_desc = font_desc;
1655 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1657 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1662 void compose_toolbar_cb(gint action, gpointer data)
1664 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1665 Compose *compose = (Compose*)toolbar_item->parent;
1667 g_return_if_fail(compose != NULL);
1671 compose_send_cb(compose, 0, NULL);
1674 compose_send_later_cb(compose, 0, NULL);
1677 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1680 compose_insert_file_cb(compose, 0, NULL);
1683 compose_attach_cb(compose, 0, NULL);
1686 compose_insert_sig(compose, FALSE);
1689 compose_ext_editor_cb(compose, 0, NULL);
1691 case A_LINEWRAP_CURRENT:
1692 compose_wrap_paragraph(compose, NULL, TRUE);
1694 case A_LINEWRAP_ALL:
1695 compose_wrap_all_full(compose, TRUE);
1698 compose_address_cb(compose, 0, NULL);
1701 case A_CHECK_SPELLING:
1702 compose_check_all(compose);
1710 static void compose_entries_set(Compose *compose, const gchar *mailto)
1714 gchar *subject = NULL;
1719 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1722 compose_entry_append(compose, to, COMPOSE_TO);
1724 compose_entry_append(compose, cc, COMPOSE_CC);
1726 if (!g_utf8_validate (subject, -1, NULL)) {
1727 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1728 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1731 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1735 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1736 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1739 gboolean prev_autowrap = compose->autowrap;
1741 compose->autowrap = FALSE;
1743 mark = gtk_text_buffer_get_insert(buffer);
1744 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1746 if (!g_utf8_validate (body, -1, NULL)) {
1747 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1748 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1751 gtk_text_buffer_insert(buffer, &iter, body, -1);
1753 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1755 compose->autowrap = prev_autowrap;
1756 if (compose->autowrap)
1757 compose_wrap_all(compose);
1766 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1768 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1769 {"Cc:", NULL, TRUE},
1770 {"References:", NULL, FALSE},
1771 {"Bcc:", NULL, TRUE},
1772 {"Newsgroups:", NULL, TRUE},
1773 {"Followup-To:", NULL, TRUE},
1774 {"List-Post:", NULL, FALSE},
1775 {"X-Priority:", NULL, FALSE},
1776 {NULL, NULL, FALSE}};
1792 g_return_val_if_fail(msginfo != NULL, -1);
1794 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1795 procheader_get_header_fields(fp, hentry);
1798 if (hentry[H_REPLY_TO].body != NULL) {
1799 if (hentry[H_REPLY_TO].body[0] != '\0') {
1801 conv_unmime_header(hentry[H_REPLY_TO].body,
1804 g_free(hentry[H_REPLY_TO].body);
1805 hentry[H_REPLY_TO].body = NULL;
1807 if (hentry[H_CC].body != NULL) {
1808 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
1809 g_free(hentry[H_CC].body);
1810 hentry[H_CC].body = NULL;
1812 if (hentry[H_REFERENCES].body != NULL) {
1813 if (compose->mode == COMPOSE_REEDIT)
1814 compose->references = hentry[H_REFERENCES].body;
1816 compose->references = compose_parse_references
1817 (hentry[H_REFERENCES].body, msginfo->msgid);
1818 g_free(hentry[H_REFERENCES].body);
1820 hentry[H_REFERENCES].body = NULL;
1822 if (hentry[H_BCC].body != NULL) {
1823 if (compose->mode == COMPOSE_REEDIT)
1825 conv_unmime_header(hentry[H_BCC].body, NULL);
1826 g_free(hentry[H_BCC].body);
1827 hentry[H_BCC].body = NULL;
1829 if (hentry[H_NEWSGROUPS].body != NULL) {
1830 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1831 hentry[H_NEWSGROUPS].body = NULL;
1833 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1834 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
1835 compose->followup_to =
1836 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
1839 g_free(hentry[H_FOLLOWUP_TO].body);
1840 hentry[H_FOLLOWUP_TO].body = NULL;
1842 if (hentry[H_LIST_POST].body != NULL) {
1845 extract_address(hentry[H_LIST_POST].body);
1846 if (hentry[H_LIST_POST].body[0] != '\0') {
1847 scan_mailto_url(hentry[H_LIST_POST].body,
1848 &to, NULL, NULL, NULL, NULL);
1850 g_free(compose->ml_post);
1851 compose->ml_post = to;
1854 g_free(hentry[H_LIST_POST].body);
1855 hentry[H_LIST_POST].body = NULL;
1858 /* CLAWS - X-Priority */
1859 if (compose->mode == COMPOSE_REEDIT)
1860 if (hentry[H_X_PRIORITY].body != NULL) {
1863 priority = atoi(hentry[H_X_PRIORITY].body);
1864 g_free(hentry[H_X_PRIORITY].body);
1866 hentry[H_X_PRIORITY].body = NULL;
1868 if (priority < PRIORITY_HIGHEST ||
1869 priority > PRIORITY_LOWEST)
1870 priority = PRIORITY_NORMAL;
1872 compose->priority = priority;
1875 if (compose->mode == COMPOSE_REEDIT) {
1876 if (msginfo->inreplyto && *msginfo->inreplyto)
1877 compose->inreplyto = g_strdup(msginfo->inreplyto);
1881 if (msginfo->msgid && *msginfo->msgid)
1882 compose->inreplyto = g_strdup(msginfo->msgid);
1884 if (!compose->references) {
1885 if (msginfo->msgid && *msginfo->msgid) {
1886 if (msginfo->inreplyto && *msginfo->inreplyto)
1887 compose->references =
1888 g_strdup_printf("<%s>\n\t<%s>",
1892 compose->references =
1893 g_strconcat("<", msginfo->msgid, ">",
1895 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
1896 compose->references =
1897 g_strconcat("<", msginfo->inreplyto, ">",
1905 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1907 GSList *ref_id_list, *cur;
1911 ref_id_list = references_list_append(NULL, ref);
1912 if (!ref_id_list) return NULL;
1913 if (msgid && *msgid)
1914 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1919 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1920 /* "<" + Message-ID + ">" + CR+LF+TAB */
1921 len += strlen((gchar *)cur->data) + 5;
1923 if (len > MAX_REFERENCES_LEN) {
1924 /* remove second message-ID */
1925 if (ref_id_list && ref_id_list->next &&
1926 ref_id_list->next->next) {
1927 g_free(ref_id_list->next->data);
1928 ref_id_list = g_slist_remove
1929 (ref_id_list, ref_id_list->next->data);
1931 slist_free_strings(ref_id_list);
1932 g_slist_free(ref_id_list);
1939 new_ref = g_string_new("");
1940 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1941 if (new_ref->len > 0)
1942 g_string_append(new_ref, "\n\t");
1943 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
1946 slist_free_strings(ref_id_list);
1947 g_slist_free(ref_id_list);
1949 new_ref_str = new_ref->str;
1950 g_string_free(new_ref, FALSE);
1955 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1956 const gchar *fmt, const gchar *qmark,
1959 static MsgInfo dummyinfo;
1960 gchar *quote_str = NULL;
1964 gboolean prev_autowrap;
1965 const gchar *trimmed_body = body;
1966 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1967 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1970 msginfo = &dummyinfo;
1972 if (qmark != NULL) {
1973 quote_fmt_init(msginfo, NULL, NULL);
1974 quote_fmt_scan_string(qmark);
1977 buf = quote_fmt_get_buffer();
1979 alertpanel_error(_("Quote mark format error."));
1981 Xstrdup_a(quote_str, buf, return NULL)
1984 if (fmt && *fmt != '\0') {
1985 while (trimmed_body && strlen(trimmed_body) > 1
1986 && trimmed_body[0]=='\n')
1989 quote_fmt_init(msginfo, quote_str, trimmed_body);
1990 quote_fmt_scan_string(fmt);
1993 buf = quote_fmt_get_buffer();
1995 alertpanel_error(_("Message reply/forward format error."));
2001 prev_autowrap = compose->autowrap;
2002 compose->autowrap = FALSE;
2004 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2005 G_CALLBACK(compose_changed_cb),
2007 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2008 G_CALLBACK(text_inserted),
2010 for (p = buf; *p != '\0'; ) {
2015 mark = gtk_text_buffer_get_insert(buffer);
2016 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2018 lastp = strchr(p, '\n');
2019 len = lastp ? lastp - p + 1 : -1;
2021 gtk_text_buffer_insert(buffer, &iter, p, len);
2029 compose->autowrap = prev_autowrap;
2030 if (compose->autowrap)
2031 compose_wrap_all(compose);
2033 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2034 G_CALLBACK(compose_changed_cb),
2036 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2037 G_CALLBACK(text_inserted),
2044 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2045 gboolean to_all, gboolean to_ml,
2047 gboolean followup_and_reply_to)
2049 GSList *cc_list = NULL;
2052 gchar *replyto = NULL;
2053 GHashTable *to_table;
2055 g_return_if_fail(compose->account != NULL);
2056 g_return_if_fail(msginfo != NULL);
2058 if (compose->account->protocol != A_NNTP) {
2059 if (!compose->replyto && to_ml && compose->ml_post
2060 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
2061 compose_entry_append(compose,
2064 else if (!(to_all || to_sender)
2066 && msginfo->folder->prefs->enable_default_reply_to) {
2067 compose_entry_append(compose,
2068 msginfo->folder->prefs->default_reply_to,
2071 compose_entry_append(compose,
2072 (compose->replyto && !to_sender)
2073 ? compose->replyto :
2074 msginfo->from ? msginfo->from : "",
2077 if (to_sender || (compose->followup_to &&
2078 !strncmp(compose->followup_to, "poster", 6)))
2079 compose_entry_append
2081 (compose->replyto ? compose->replyto :
2082 msginfo->from ? msginfo->from : ""),
2085 else if (followup_and_reply_to || to_all) {
2086 compose_entry_append
2088 (compose->replyto ? compose->replyto :
2089 msginfo->from ? msginfo->from : ""),
2092 compose_entry_append
2094 compose->followup_to ? compose->followup_to :
2095 compose->newsgroups ? compose->newsgroups : "",
2096 COMPOSE_NEWSGROUPS);
2099 compose_entry_append
2101 compose->followup_to ? compose->followup_to :
2102 compose->newsgroups ? compose->newsgroups : "",
2103 COMPOSE_NEWSGROUPS);
2106 if (msginfo->subject && *msginfo->subject) {
2110 buf = p = g_strdup(msginfo->subject);
2111 p += subject_get_prefix_length(p);
2112 memmove(buf, p, strlen(p) + 1);
2114 buf2 = g_strdup_printf("Re: %s", buf);
2115 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2120 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2122 if (to_ml && compose->ml_post) return;
2123 if (!to_all || compose->account->protocol == A_NNTP) return;
2125 if (compose->replyto) {
2126 Xstrdup_a(replyto, compose->replyto, return);
2127 extract_address(replyto);
2129 if (msginfo->from) {
2130 Xstrdup_a(from, msginfo->from, return);
2131 extract_address(from);
2134 if (replyto && from)
2135 cc_list = address_list_append_with_comments(cc_list, from);
2136 if (to_all && msginfo->folder &&
2137 msginfo->folder->prefs->enable_default_reply_to)
2138 cc_list = address_list_append_with_comments(cc_list,
2139 msginfo->folder->prefs->default_reply_to);
2140 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2141 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2143 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2145 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2146 if (compose->account)
2147 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2148 GINT_TO_POINTER(1));
2150 /* remove address on To: and that of current account */
2151 for (cur = cc_list; cur != NULL; ) {
2152 GSList *next = cur->next;
2155 addr = g_strdup(cur->data);
2156 extract_address(addr);
2158 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2159 cc_list = g_slist_remove(cc_list, cur->data);
2161 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2165 hash_free_strings(to_table);
2166 g_hash_table_destroy(to_table);
2169 for (cur = cc_list; cur != NULL; cur = cur->next)
2170 compose_entry_append(compose, (gchar *)cur->data,
2172 slist_free_strings(cc_list);
2173 g_slist_free(cc_list);
2178 #define SET_ENTRY(entry, str) \
2181 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2184 #define SET_ADDRESS(type, str) \
2187 compose_entry_append(compose, str, type); \
2190 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2192 g_return_if_fail(msginfo != NULL);
2194 SET_ENTRY(subject_entry, msginfo->subject);
2195 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2196 SET_ADDRESS(COMPOSE_CC, compose->cc);
2197 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2198 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2199 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2200 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2202 compose_update_priority_menu_item(compose);
2203 compose_update_privacy_system_menu_item(compose);
2204 compose_show_first_last_header(compose, TRUE);
2210 static void compose_insert_sig(Compose *compose, gboolean replace)
2212 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2213 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2215 GtkTextIter iter, iter_end;
2217 gboolean prev_autowrap;
2220 g_return_if_fail(compose->account != NULL);
2222 prev_autowrap = compose->autowrap;
2223 compose->autowrap = FALSE;
2225 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2226 G_CALLBACK(compose_changed_cb),
2229 mark = gtk_text_buffer_get_insert(buffer);
2230 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2231 cur_pos = gtk_text_iter_get_offset (&iter);
2233 gtk_text_buffer_get_end_iter(buffer, &iter);
2235 if (replace && compose->sig_str) {
2237 GtkTextIter first_iter, start_iter, end_iter;
2239 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2241 if (compose->sig_str[0] == '\0')
2244 found = gtk_text_iter_forward_search(&first_iter,
2246 GTK_TEXT_SEARCH_TEXT_ONLY,
2247 &start_iter, &end_iter,
2251 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2256 g_free(compose->sig_str);
2257 compose->sig_str = compose_get_signature_str(compose);
2258 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2259 compose->sig_str = g_strdup("");
2261 cur_pos = gtk_text_iter_get_offset(&iter);
2262 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2264 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2265 gtk_text_iter_forward_char(&iter);
2266 gtk_text_iter_forward_char(&iter);
2267 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2268 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2270 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2271 cur_pos = gtk_text_buffer_get_char_count (buffer);
2273 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2274 gtk_text_buffer_place_cursor(buffer, &iter);
2276 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2277 G_CALLBACK(compose_changed_cb),
2280 compose->autowrap = prev_autowrap;
2281 if (compose->autowrap)
2282 compose_wrap_all(compose);
2285 static gchar *compose_get_signature_str(Compose *compose)
2287 gchar *sig_body = NULL;
2288 gchar *sig_str = NULL;
2289 gchar *utf8_sig_str = NULL;
2291 g_return_val_if_fail(compose->account != NULL, NULL);
2293 if (!compose->account->sig_path)
2296 if (compose->account->sig_type == SIG_FILE) {
2297 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2298 g_warning("can't open signature file: %s\n",
2299 compose->account->sig_path);
2304 if (compose->account->sig_type == SIG_COMMAND)
2305 sig_body = get_command_output(compose->account->sig_path);
2309 tmp = file_read_to_str(compose->account->sig_path);
2312 sig_body = normalize_newlines(tmp);
2316 if (compose->account->sig_sep) {
2317 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2321 sig_str = g_strconcat("\n\n", sig_body, NULL);
2324 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2325 utf8_sig_str = sig_str;
2327 utf8_sig_str = conv_codeset_strdup
2328 (sig_str, conv_get_locale_charset_str(),
2334 return utf8_sig_str;
2337 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2340 GtkTextBuffer *buffer;
2343 const gchar *cur_encoding;
2344 gchar buf[BUFFSIZE];
2347 gboolean prev_autowrap;
2348 gboolean badtxt = FALSE;
2350 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2352 if ((fp = g_fopen(file, "rb")) == NULL) {
2353 FILE_OP_ERROR(file, "fopen");
2354 return COMPOSE_INSERT_READ_ERROR;
2357 prev_autowrap = compose->autowrap;
2358 compose->autowrap = FALSE;
2360 text = GTK_TEXT_VIEW(compose->text);
2361 buffer = gtk_text_view_get_buffer(text);
2362 mark = gtk_text_buffer_get_insert(buffer);
2363 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2365 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2366 G_CALLBACK(text_inserted),
2369 cur_encoding = conv_get_locale_charset_str();
2371 while (fgets(buf, sizeof(buf), fp) != NULL) {
2374 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2375 str = g_strdup(buf);
2377 str = conv_codeset_strdup
2378 (buf, cur_encoding, CS_INTERNAL);
2381 /* strip <CR> if DOS/Windows file,
2382 replace <CR> with <LF> if Macintosh file. */
2385 if (len > 0 && str[len - 1] != '\n') {
2387 if (str[len] == '\r') str[len] = '\n';
2390 gtk_text_buffer_insert(buffer, &iter, str, -1);
2394 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2395 G_CALLBACK(text_inserted),
2397 compose->autowrap = prev_autowrap;
2398 if (compose->autowrap)
2399 compose_wrap_all(compose);
2404 return COMPOSE_INSERT_INVALID_CHARACTER;
2406 return COMPOSE_INSERT_SUCCESS;
2409 static void compose_attach_append(Compose *compose, const gchar *file,
2410 const gchar *filename,
2411 const gchar *content_type)
2419 GtkListStore *store;
2422 if (!is_file_exist(file)) {
2423 g_warning("File %s doesn't exist\n", filename);
2426 if ((size = get_file_size(file)) < 0) {
2427 g_warning("Can't get file size of %s\n", filename);
2431 alertpanel_notice(_("File %s is empty."), filename);
2434 if ((fp = g_fopen(file, "rb")) == NULL) {
2435 alertpanel_error(_("Can't read %s."), filename);
2440 ainfo = g_new0(AttachInfo, 1);
2441 auto_ainfo = g_auto_pointer_new_with_free
2442 (ainfo, (GFreeFunc) compose_attach_info_free);
2443 ainfo->file = g_strdup(file);
2446 ainfo->content_type = g_strdup(content_type);
2447 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2449 MsgFlags flags = {0, 0};
2451 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2452 ainfo->encoding = ENC_7BIT;
2454 ainfo->encoding = ENC_8BIT;
2456 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2457 if (msginfo && msginfo->subject)
2458 name = g_strdup(msginfo->subject);
2460 name = g_path_get_basename(filename ? filename : file);
2462 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2464 procmsg_msginfo_free(msginfo);
2466 if (!g_ascii_strncasecmp(content_type, "text", 4))
2467 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2469 ainfo->encoding = ENC_BASE64;
2470 name = g_path_get_basename(filename ? filename : file);
2471 ainfo->name = g_strdup(name);
2475 ainfo->content_type = procmime_get_mime_type(file);
2476 if (!ainfo->content_type) {
2477 ainfo->content_type =
2478 g_strdup("application/octet-stream");
2479 ainfo->encoding = ENC_BASE64;
2480 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2482 procmime_get_encoding_for_text_file(file);
2484 ainfo->encoding = ENC_BASE64;
2485 name = g_path_get_basename(filename ? filename : file);
2486 ainfo->name = g_strdup(name);
2490 if (!strcmp(ainfo->content_type, "unknown")) {
2491 g_free(ainfo->content_type);
2492 ainfo->content_type = g_strdup("application/octet-stream");
2496 size_text = to_human_readable(size);
2498 store = GTK_LIST_STORE(gtk_tree_view_get_model
2499 (GTK_TREE_VIEW(compose->attach_clist)));
2501 gtk_list_store_append(store, &iter);
2502 gtk_list_store_set(store, &iter,
2503 COL_MIMETYPE, ainfo->content_type,
2504 COL_SIZE, size_text,
2505 COL_NAME, ainfo->name,
2507 COL_AUTODATA, auto_ainfo,
2510 g_auto_pointer_free(auto_ainfo);
2513 static void compose_use_signing(Compose *compose, gboolean use_signing)
2515 GtkItemFactory *ifactory;
2516 GtkWidget *menuitem = NULL;
2518 compose->use_signing = use_signing;
2519 ifactory = gtk_item_factory_from_widget(compose->menubar);
2520 menuitem = gtk_item_factory_get_item
2521 (ifactory, "/Options/Sign");
2522 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2526 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2528 GtkItemFactory *ifactory;
2529 GtkWidget *menuitem = NULL;
2531 compose->use_encryption = use_encryption;
2532 ifactory = gtk_item_factory_from_widget(compose->menubar);
2533 menuitem = gtk_item_factory_get_item
2534 (ifactory, "/Options/Encrypt");
2536 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2540 #define NEXT_PART_NOT_CHILD(info) \
2542 node = info->node; \
2543 while (node->children) \
2544 node = g_node_last_child(node); \
2545 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2548 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2552 MimeInfo *firsttext = NULL;
2553 MimeInfo *encrypted = NULL;
2556 const gchar *partname = NULL;
2558 mimeinfo = procmime_scan_message(msginfo);
2559 if (!mimeinfo) return;
2561 if (mimeinfo->node->children == NULL) {
2562 procmime_mimeinfo_free_all(mimeinfo);
2566 /* find first content part */
2567 child = (MimeInfo *) mimeinfo->node->children->data;
2568 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2569 child = (MimeInfo *)child->node->children->data;
2571 if (child->type == MIMETYPE_TEXT) {
2573 debug_print("First text part found\n");
2574 } else if (compose->mode == COMPOSE_REEDIT &&
2575 child->type == MIMETYPE_APPLICATION &&
2576 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2577 encrypted = (MimeInfo *)child->node->parent->data;
2580 child = (MimeInfo *) mimeinfo->node->children->data;
2581 while (child != NULL) {
2582 if (child == encrypted) {
2583 /* skip this part of tree */
2584 NEXT_PART_NOT_CHILD(child);
2588 if (child->type == MIMETYPE_MULTIPART) {
2589 /* get the actual content */
2590 child = procmime_mimeinfo_next(child);
2594 if (child == firsttext) {
2595 child = procmime_mimeinfo_next(child);
2599 outfile = procmime_get_tmp_file_name(child);
2600 if (procmime_get_part(outfile, child) < 0)
2601 g_warning("Can't get the part of multipart message.");
2603 gchar *content_type;
2605 content_type = procmime_get_content_type_str(child->type, child->subtype);
2606 partname = procmime_mimeinfo_get_parameter(child, "filename");
2607 if (partname == NULL)
2608 partname = procmime_mimeinfo_get_parameter(child, "name");
2609 if (partname == NULL)
2611 compose_attach_append(compose, outfile,
2612 partname, content_type);
2613 g_free(content_type);
2616 NEXT_PART_NOT_CHILD(child);
2618 procmime_mimeinfo_free_all(mimeinfo);
2621 #undef NEXT_PART_NOT_CHILD
2626 WAIT_FOR_INDENT_CHAR,
2627 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2630 /* return indent length, we allow:
2631 indent characters followed by indent characters or spaces/tabs,
2632 alphabets and numbers immediately followed by indent characters,
2633 and the repeating sequences of the above
2634 If quote ends with multiple spaces, only the first one is included. */
2635 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2636 const GtkTextIter *start, gint *len)
2638 GtkTextIter iter = *start;
2642 IndentState state = WAIT_FOR_INDENT_CHAR;
2645 gint alnum_count = 0;
2646 gint space_count = 0;
2649 if (prefs_common.quote_chars == NULL) {
2653 while (!gtk_text_iter_ends_line(&iter)) {
2654 wc = gtk_text_iter_get_char(&iter);
2655 if (g_unichar_iswide(wc))
2657 clen = g_unichar_to_utf8(wc, ch);
2661 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2662 is_space = g_unichar_isspace(wc);
2664 if (state == WAIT_FOR_INDENT_CHAR) {
2665 if (!is_indent && !g_unichar_isalnum(wc))
2668 quote_len += alnum_count + space_count + 1;
2669 alnum_count = space_count = 0;
2670 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2673 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2674 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
2678 else if (is_indent) {
2679 quote_len += alnum_count + space_count + 1;
2680 alnum_count = space_count = 0;
2683 state = WAIT_FOR_INDENT_CHAR;
2687 gtk_text_iter_forward_char(&iter);
2690 if (quote_len > 0 && space_count > 0)
2696 if (quote_len > 0) {
2698 gtk_text_iter_forward_chars(&iter, quote_len);
2699 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
2705 /* return TRUE if the line is itemized */
2706 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
2707 const GtkTextIter *start)
2709 GtkTextIter iter = *start;
2714 if (gtk_text_iter_ends_line(&iter))
2718 wc = gtk_text_iter_get_char(&iter);
2719 if (!g_unichar_isspace(wc))
2721 gtk_text_iter_forward_char(&iter);
2722 if (gtk_text_iter_ends_line(&iter))
2726 clen = g_unichar_to_utf8(wc, ch);
2730 if (!strchr("*-+", ch[0]))
2733 gtk_text_iter_forward_char(&iter);
2734 if (gtk_text_iter_ends_line(&iter))
2736 wc = gtk_text_iter_get_char(&iter);
2737 if (g_unichar_isspace(wc))
2743 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
2744 const GtkTextIter *start,
2745 GtkTextIter *break_pos,
2749 GtkTextIter iter = *start, line_end = *start;
2750 PangoLogAttr *attrs;
2757 gboolean can_break = FALSE;
2758 gboolean do_break = FALSE;
2759 gboolean was_white = FALSE;
2760 gboolean prev_dont_break = FALSE;
2762 gtk_text_iter_forward_to_line_end(&line_end);
2763 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
2764 len = g_utf8_strlen(str, -1);
2765 /* g_print("breaking line: %d: %s (len = %d)\n",
2766 gtk_text_iter_get_line(&iter), str, len); */
2767 attrs = g_new(PangoLogAttr, len + 1);
2769 pango_default_break(str, -1, NULL, attrs, len + 1);
2773 /* skip quote and leading spaces */
2774 for (i = 0; *p != '\0' && i < len; i++) {
2777 wc = g_utf8_get_char(p);
2778 if (i >= quote_len && !g_unichar_isspace(wc))
2780 if (g_unichar_iswide(wc))
2782 else if (*p == '\t')
2786 p = g_utf8_next_char(p);
2789 for (; *p != '\0' && i < len; i++) {
2790 PangoLogAttr *attr = attrs + i;
2794 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
2797 was_white = attr->is_white;
2799 /* don't wrap URI */
2800 if ((uri_len = get_uri_len(p)) > 0) {
2802 if (pos > 0 && col > max_col) {
2812 wc = g_utf8_get_char(p);
2813 if (g_unichar_iswide(wc)) {
2815 if (prev_dont_break && can_break && attr->is_line_break)
2817 } else if (*p == '\t')
2821 if (pos > 0 && col > max_col) {
2826 if (*p == '-' || *p == '/')
2827 prev_dont_break = TRUE;
2829 prev_dont_break = FALSE;
2831 p = g_utf8_next_char(p);
2835 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
2840 *break_pos = *start;
2841 gtk_text_iter_set_line_offset(break_pos, pos);
2846 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
2848 GtkTextIter start = *iter;
2849 GtkTextIter end_iter;
2850 int start_pos = gtk_text_iter_get_offset(&start);
2852 if (!compose->account->sig_sep)
2855 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2856 start_pos+strlen(compose->account->sig_sep));
2858 /* check sig separator */
2859 if (!strcmp(gtk_text_iter_get_text(&start, &end_iter),
2860 compose->account->sig_sep)) {
2861 /* check end of line (\n) */
2862 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
2863 start_pos+strlen(compose->account->sig_sep));
2864 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2865 start_pos+strlen(compose->account->sig_sep)+1);
2867 if (!strcmp(gtk_text_iter_get_text(&start, &end_iter),"\n"));
2876 static gboolean compose_join_next_line(Compose *compose,
2877 GtkTextBuffer *buffer,
2879 const gchar *quote_str)
2881 GtkTextIter iter_ = *iter, cur, prev, next, end;
2882 PangoLogAttr attrs[3];
2884 gchar *next_quote_str;
2887 gboolean keep_cursor = FALSE;
2889 if (!gtk_text_iter_forward_line(&iter_) ||
2890 gtk_text_iter_ends_line(&iter_))
2893 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
2895 if ((quote_str || next_quote_str) &&
2896 strcmp2(quote_str, next_quote_str) != 0) {
2897 g_free(next_quote_str);
2900 g_free(next_quote_str);
2903 if (quote_len > 0) {
2904 gtk_text_iter_forward_chars(&end, quote_len);
2905 if (gtk_text_iter_ends_line(&end))
2909 /* don't join itemized lines */
2910 if (compose_is_itemized(buffer, &end))
2913 /* don't join signature separator */
2914 if (compose_is_sig_separator(compose, buffer, &iter_))
2917 /* delete quote str */
2919 gtk_text_buffer_delete(buffer, &iter_, &end);
2921 /* delete linebreak and extra spaces */
2923 while (gtk_text_iter_backward_char(&cur)) {
2924 wc1 = gtk_text_iter_get_char(&cur);
2925 if (!g_unichar_isspace(wc1))
2930 while (!gtk_text_iter_ends_line(&cur)) {
2931 wc1 = gtk_text_iter_get_char(&cur);
2932 if (!g_unichar_isspace(wc1))
2934 gtk_text_iter_forward_char(&cur);
2937 if (!gtk_text_iter_equal(&prev, &next)) {
2940 mark = gtk_text_buffer_get_insert(buffer);
2941 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
2942 if (gtk_text_iter_equal(&prev, &cur))
2944 gtk_text_buffer_delete(buffer, &prev, &next);
2948 /* insert space if required */
2949 gtk_text_iter_backward_char(&prev);
2950 wc1 = gtk_text_iter_get_char(&prev);
2951 wc2 = gtk_text_iter_get_char(&next);
2952 gtk_text_iter_forward_char(&next);
2953 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
2954 pango_default_break(str, -1, NULL, attrs, 3);
2955 if (!attrs[1].is_line_break ||
2956 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
2957 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
2959 gtk_text_iter_backward_char(&iter_);
2960 gtk_text_buffer_place_cursor(buffer, &iter_);
2969 #define ADD_TXT_POS(bp_, ep_, pti_) \
2970 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
2971 last = last->next; \
2972 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
2973 last->next = NULL; \
2975 g_warning("alloc error scanning URIs\n"); \
2978 static void compose_wrap_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
2980 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2981 GtkTextBuffer *buffer;
2982 GtkTextIter iter, break_pos, end_of_line;
2983 gchar *quote_str = NULL;
2985 gboolean wrap_quote = prefs_common.linewrap_quote;
2986 gboolean prev_autowrap = compose->autowrap;
2987 gint startq_offset = -1, noq_offset = -1;
2988 gint uri_start = -1, uri_stop = -1;
2989 gint nouri_start = -1, nouri_stop = -1;
2991 compose->autowrap = FALSE;
2993 buffer = gtk_text_view_get_buffer(text);
2995 undo_block(compose->undostruct);
3001 mark = gtk_text_buffer_get_insert(buffer);
3002 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3005 /* move to paragraph start */
3006 gtk_text_iter_set_line_offset(&iter, 0);
3007 if (gtk_text_iter_ends_line(&iter)) {
3008 while (gtk_text_iter_ends_line(&iter) &&
3009 gtk_text_iter_forward_line(&iter))
3012 while (gtk_text_iter_backward_line(&iter)) {
3013 if (gtk_text_iter_ends_line(&iter)) {
3014 gtk_text_iter_forward_line(&iter);
3020 /* go until paragraph end (empty line) */
3021 while (!gtk_text_iter_ends_line(&iter)) {
3022 gchar *scanpos = NULL;
3023 /* parse table - in order of priority */
3025 const gchar *needle; /* token */
3027 /* token search function */
3028 gchar *(*search) (const gchar *haystack,
3029 const gchar *needle);
3030 /* part parsing function */
3031 gboolean (*parse) (const gchar *start,
3032 const gchar *scanpos,
3035 /* part to URI function */
3036 gchar *(*build_uri) (const gchar *bp,
3040 static struct table parser[] = {
3041 {"http://", strcasestr, get_uri_part, make_uri_string},
3042 {"https://", strcasestr, get_uri_part, make_uri_string},
3043 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3044 {"www.", strcasestr, get_uri_part, make_http_string},
3045 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3046 {"@", strcasestr, get_email_part, make_email_string}
3048 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3049 gint last_index = PARSE_ELEMS;
3051 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3054 if (gtk_text_iter_has_tag(&iter, no_wrap_tag) && !force)
3057 uri_start = uri_stop = -1;
3058 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3062 if (startq_offset == -1) {
3063 startq_offset = gtk_text_iter_get_offset(&iter);
3067 debug_print("compose_wrap_paragraph(): quote_str = '%s'\n", quote_str);
3068 startq_offset = gtk_text_iter_get_offset(&iter);
3070 if (startq_offset == -1)
3071 noq_offset = gtk_text_iter_get_offset(&iter);
3074 if (prev_autowrap == FALSE && !force) {
3077 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3078 prefs_common.linewrap_len,
3080 GtkTextIter prev, next, cur;
3082 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3084 /* remove trailing spaces */
3086 gtk_text_iter_backward_char(&cur);
3088 while (!gtk_text_iter_starts_line(&cur)) {
3091 gtk_text_iter_backward_char(&cur);
3092 wc = gtk_text_iter_get_char(&cur);
3093 if (!g_unichar_isspace(wc))
3097 if (!gtk_text_iter_equal(&prev, &next)) {
3098 gtk_text_buffer_delete(buffer, &prev, &next);
3100 gtk_text_iter_forward_char(&break_pos);
3104 gtk_text_buffer_insert(buffer, &break_pos,
3108 compose_join_next_line(compose, buffer, &iter, quote_str);
3110 /* move iter to current line start */
3111 gtk_text_iter_set_line_offset(&iter, 0);
3114 /* move iter to next line start */
3120 while (!gtk_text_iter_ends_line(&end_of_line)) {
3121 gtk_text_iter_forward_char(&end_of_line);
3123 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3125 nouri_start = gtk_text_iter_get_offset(&iter);
3126 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3128 walk_pos = gtk_text_iter_get_offset(&iter);
3129 /* FIXME: this looks phony. scanning for anything in the parse table */
3130 for (n = 0; n < PARSE_ELEMS; n++) {
3133 tmp = parser[n].search(walk, parser[n].needle);
3135 if (scanpos == NULL || tmp < scanpos) {
3144 /* check if URI can be parsed */
3145 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,(const gchar **)&ep)
3146 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3150 strlen(parser[last_index].needle);
3153 uri_start = walk_pos + (bp - o_walk);
3154 uri_stop = walk_pos + (ep - o_walk);
3158 gtk_text_iter_forward_line(&iter);
3161 if (startq_offset != -1) {
3162 GtkTextIter startquote, endquote;
3163 gtk_text_buffer_get_iter_at_offset(
3164 buffer, &startquote, startq_offset);
3166 gtk_text_buffer_apply_tag_by_name(
3167 buffer, "quote", &startquote, &endquote);
3169 } else if (noq_offset != -1) {
3170 GtkTextIter startnoquote, endnoquote;
3171 gtk_text_buffer_get_iter_at_offset(
3172 buffer, &startnoquote, noq_offset);
3174 gtk_text_buffer_remove_tag_by_name(
3175 buffer, "quote", &startnoquote, &endnoquote);
3180 GtkTextIter nouri_start_iter, nouri_end_iter;
3181 gtk_text_buffer_get_iter_at_offset(
3182 buffer, &nouri_start_iter, nouri_start);
3183 gtk_text_buffer_get_iter_at_offset(
3184 buffer, &nouri_end_iter, nouri_stop);
3185 gtk_text_buffer_remove_tag_by_name(
3186 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3188 if (uri_start > 0 && uri_stop > 0) {
3189 GtkTextIter uri_start_iter, uri_end_iter;
3190 gtk_text_buffer_get_iter_at_offset(
3191 buffer, &uri_start_iter, uri_start);
3192 gtk_text_buffer_get_iter_at_offset(
3193 buffer, &uri_end_iter, uri_stop);
3194 gtk_text_buffer_apply_tag_by_name(
3195 buffer, "link", &uri_start_iter, &uri_end_iter);
3202 undo_unblock(compose->undostruct);
3203 compose->autowrap = prev_autowrap;
3206 static void compose_wrap_all(Compose *compose)
3208 compose_wrap_all_full(compose, FALSE);
3211 static void compose_wrap_all_full(Compose *compose, gboolean force)
3213 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3214 GtkTextBuffer *buffer;
3217 buffer = gtk_text_view_get_buffer(text);
3219 undo_block(compose->undostruct);
3221 gtk_text_buffer_get_start_iter(buffer, &iter);
3222 while (!gtk_text_iter_is_end(&iter))
3223 compose_wrap_paragraph(compose, &iter, force);
3225 undo_unblock(compose->undostruct);
3228 static void compose_set_title(Compose *compose)
3233 edited = compose->modified ? _(" [Edited]") : "";
3234 if (compose->account && compose->account->address)
3235 str = g_strdup_printf(_("%s - Compose message%s"),
3236 compose->account->address, edited);
3238 str = g_strdup_printf(_("Compose message%s"), edited);
3239 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3244 * compose_current_mail_account:
3246 * Find a current mail account (the currently selected account, or the
3247 * default account, if a news account is currently selected). If a
3248 * mail account cannot be found, display an error message.
3250 * Return value: Mail account, or NULL if not found.
3252 static PrefsAccount *
3253 compose_current_mail_account(void)
3257 if (cur_account && cur_account->protocol != A_NNTP)
3260 ac = account_get_default();
3261 if (!ac || ac->protocol == A_NNTP) {
3262 alertpanel_error(_("Account for sending mail is not specified.\n"
3263 "Please select a mail account before sending."));
3270 static void compose_select_account(Compose *compose, PrefsAccount *account,
3273 GtkItemFactory *ifactory;
3275 g_return_if_fail(account != NULL);
3277 compose->account = account;
3279 compose_set_title(compose);
3281 ifactory = gtk_item_factory_from_widget(compose->menubar);
3283 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3284 menu_set_active(ifactory, "/Options/Sign", TRUE);
3286 menu_set_active(ifactory, "/Options/Sign", FALSE);
3287 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3288 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3290 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3292 activate_privacy_system(compose, account);
3294 if (!init && compose->mode != COMPOSE_REDIRECT)
3295 compose_insert_sig(compose, TRUE);
3298 gboolean compose_check_for_valid_recipient(Compose *compose) {
3299 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3300 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3301 gboolean recipient_found = FALSE;
3305 /* free to and newsgroup list */
3306 slist_free_strings(compose->to_list);
3307 g_slist_free(compose->to_list);
3308 compose->to_list = NULL;
3310 slist_free_strings(compose->newsgroup_list);
3311 g_slist_free(compose->newsgroup_list);
3312 compose->newsgroup_list = NULL;
3314 /* search header entries for to and newsgroup entries */
3315 for (list = compose->header_list; list; list = list->next) {
3318 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3319 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3321 if (entry[0] != '\0') {
3322 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3323 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3324 compose->to_list = address_list_append(compose->to_list, entry);
3325 recipient_found = TRUE;
3328 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3329 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3330 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3331 recipient_found = TRUE;
3338 return recipient_found;
3341 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3345 if (compose_check_for_valid_recipient(compose) == FALSE) {
3346 alertpanel_error(_("Recipient is not specified."));
3350 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3351 if (*str == '\0' && check_subject == TRUE) {
3354 aval = alertpanel(_("Send"),
3355 _("Subject is empty. Send it anyway?"),
3356 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3357 if (aval != G_ALERTDEFAULT)
3364 gint compose_send(Compose *compose)
3371 compose_allow_user_actions (compose, FALSE);
3372 compose->sending = TRUE;
3374 if (compose_check_entries(compose, TRUE) == FALSE)
3377 val = compose_queue(compose, &msgnum, &folder);
3381 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3383 alertpanel_error(_("Could not queue message for sending."));
3389 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3390 compose->sending = FALSE;
3391 compose_close(compose);
3392 /* No more compose access in the normal codepath
3393 * after this point! */
3398 alertpanel_error(_("The message was queued but could not be "
3399 "sent.\nUse \"Send queued messages\" from "
3400 "the main window to retry."));
3401 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3402 compose->sending = FALSE;
3403 compose_allow_user_actions (compose, TRUE);
3408 msgpath = folder_item_fetch_msg(folder, msgnum);
3409 val = procmsg_send_message_queue(msgpath);
3412 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3413 compose->sending = FALSE;
3414 compose_allow_user_actions (compose, TRUE);
3416 folder_item_remove_msg(folder, msgnum);
3417 folder_item_scan(folder);
3422 folder_item_remove_msg(folder, msgnum);
3423 folder_item_scan(folder);
3424 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3425 compose_close(compose);
3427 alertpanel_error(_("The message was queued but could not be "
3428 "sent.\nUse \"Send queued messages\" from "
3429 "the main window to retry."));
3430 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3431 compose_allow_user_actions (compose, TRUE);
3432 compose->sending = FALSE;
3440 compose_allow_user_actions (compose, TRUE);
3441 compose->sending = FALSE;
3446 static gboolean compose_use_attach(Compose *compose)
3448 GtkTreeModel *model = gtk_tree_view_get_model
3449 (GTK_TREE_VIEW(compose->attach_clist));
3450 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3453 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3456 gchar buf[BUFFSIZE];
3458 gboolean first_to_address;
3459 gboolean first_cc_address;
3461 ComposeHeaderEntry *headerentry;
3462 const gchar *headerentryname;
3466 debug_print("Writing redirect header\n");
3468 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3469 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3471 first_to_address = TRUE;
3472 for (list = compose->header_list; list; list = list->next) {
3473 headerentry = ((ComposeHeaderEntry *)list->data);
3474 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3476 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3477 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3478 Xstrdup_a(str, entstr, return -1);
3480 if (str[0] != '\0') {
3481 compose_convert_header
3482 (compose, buf, sizeof(buf), str,
3483 strlen("Resent-To") + 2, TRUE);
3485 if (first_to_address) {
3486 fprintf(fp, "Resent-To: ");
3487 first_to_address = FALSE;
3491 fprintf(fp, "%s", buf);
3495 if (!first_to_address) {
3499 first_cc_address = TRUE;
3500 for (list = compose->header_list; list; list = list->next) {
3501 headerentry = ((ComposeHeaderEntry *)list->data);
3502 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3504 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3505 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3506 Xstrdup_a(str, strg, return -1);
3508 if (str[0] != '\0') {
3509 compose_convert_header
3510 (compose, buf, sizeof(buf), str,
3511 strlen("Resent-Cc") + 2, TRUE);
3513 if (first_cc_address) {
3514 fprintf(fp, "Resent-Cc: ");
3515 first_cc_address = FALSE;
3519 fprintf(fp, "%s", buf);
3523 if (!first_cc_address) {
3530 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3532 gchar buf[BUFFSIZE];
3534 const gchar *entstr;
3535 /* struct utsname utsbuf; */
3537 g_return_val_if_fail(fp != NULL, -1);
3538 g_return_val_if_fail(compose->account != NULL, -1);
3539 g_return_val_if_fail(compose->account->address != NULL, -1);
3542 get_rfc822_date(buf, sizeof(buf));
3543 fprintf(fp, "Resent-Date: %s\n", buf);
3546 if (compose->account->name && *compose->account->name) {
3547 compose_convert_header
3548 (compose, buf, sizeof(buf), compose->account->name,
3549 strlen("From: "), TRUE);
3550 fprintf(fp, "Resent-From: %s <%s>\n",
3551 buf, compose->account->address);
3553 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3556 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3557 if (*entstr != '\0') {
3558 Xstrdup_a(str, entstr, return -1);
3561 compose_convert_header(compose, buf, sizeof(buf), str,
3562 strlen("Subject: "), FALSE);
3563 fprintf(fp, "Subject: %s\n", buf);
3567 /* Resent-Message-ID */
3568 if (compose->account->gen_msgid) {
3569 generate_msgid(buf, sizeof(buf));
3570 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3571 compose->msgid = g_strdup(buf);
3574 compose_redirect_write_headers_from_headerlist(compose, fp);
3576 /* separator between header and body */
3582 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3586 gchar buf[BUFFSIZE];
3588 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
3589 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3593 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3594 /* should filter returnpath, delivered-to */
3595 if (g_ascii_strncasecmp(buf, "Return-Path:",
3596 strlen("Return-Path:")) == 0 ||
3597 g_ascii_strncasecmp(buf, "Delivered-To:",
3598 strlen("Delivered-To:")) == 0 ||
3599 g_ascii_strncasecmp(buf, "Received:",
3600 strlen("Received:")) == 0 ||
3601 g_ascii_strncasecmp(buf, "Subject:",
3602 strlen("Subject:")) == 0 ||
3603 g_ascii_strncasecmp(buf, "X-UIDL:",
3604 strlen("X-UIDL:")) == 0)
3607 if (fputs(buf, fdest) == -1)
3610 if (!prefs_common.redirect_keep_from) {
3611 if (g_ascii_strncasecmp(buf, "From:",
3612 strlen("From:")) == 0) {
3613 fputs(" (by way of ", fdest);
3614 if (compose->account->name
3615 && *compose->account->name) {
3616 compose_convert_header
3617 (compose, buf, sizeof(buf),
3618 compose->account->name,
3621 fprintf(fdest, "%s <%s>",
3623 compose->account->address);
3625 fprintf(fdest, "%s",
3626 compose->account->address);
3631 if (fputs("\n", fdest) == -1)
3635 compose_redirect_write_headers(compose, fdest);
3637 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3638 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
3651 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
3653 GtkTextBuffer *buffer;
3654 GtkTextIter start, end;
3657 const gchar *out_codeset;
3658 EncodingType encoding;
3659 MimeInfo *mimemsg, *mimetext;
3662 /* create message MimeInfo */
3663 mimemsg = procmime_mimeinfo_new();
3664 mimemsg->type = MIMETYPE_MESSAGE;
3665 mimemsg->subtype = g_strdup("rfc822");
3666 mimemsg->content = MIMECONTENT_MEM;
3667 mimemsg->data.mem = compose_get_header(compose);
3669 /* Create text part MimeInfo */
3670 /* get all composed text */
3671 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
3672 gtk_text_buffer_get_start_iter(buffer, &start);
3673 gtk_text_buffer_get_end_iter(buffer, &end);
3674 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
3675 if (is_ascii_str(chars)) {
3678 out_codeset = CS_US_ASCII;
3679 encoding = ENC_7BIT;
3681 const gchar *src_codeset;
3683 out_codeset = conv_get_charset_str(compose->out_encoding);
3685 out_codeset = conv_get_outgoing_charset_str();
3687 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
3688 out_codeset = CS_ISO_8859_1;
3690 if (prefs_common.encoding_method == CTE_BASE64)
3691 encoding = ENC_BASE64;
3692 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3693 encoding = ENC_QUOTED_PRINTABLE;
3694 else if (prefs_common.encoding_method == CTE_8BIT)
3695 encoding = ENC_8BIT;
3697 encoding = procmime_get_encoding_for_charset(out_codeset);
3699 src_codeset = CS_INTERNAL;
3700 /* if current encoding is US-ASCII, set it the same as
3701 outgoing one to prevent code conversion failure */
3702 if (!g_ascii_strcasecmp(src_codeset, CS_US_ASCII))
3703 src_codeset = out_codeset;
3705 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3706 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3708 if (action == COMPOSE_WRITE_FOR_SEND) {
3709 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3715 msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
3717 "Send it anyway?"), src_codeset, out_codeset);
3718 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_YES, GTK_STOCK_NO, NULL, FALSE,
3719 NULL, ALERT_ERROR, G_ALERTALTERNATE);
3722 if (aval != G_ALERTDEFAULT) {
3727 out_codeset = src_codeset;
3733 out_codeset = src_codeset;
3739 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
3740 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
3741 strstr(buf, "\nFrom ") != NULL) {
3742 encoding = ENC_QUOTED_PRINTABLE;
3746 mimetext = procmime_mimeinfo_new();
3747 mimetext->content = MIMECONTENT_MEM;
3748 mimetext->data.mem = buf;
3749 mimetext->type = MIMETYPE_TEXT;
3750 mimetext->subtype = g_strdup("plain");
3751 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
3752 g_strdup(out_codeset));
3753 /* protect trailing spaces when signing message */
3754 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
3755 privacy_system_can_sign(compose->privacy_system)) {
3756 if (encoding == ENC_7BIT)
3757 encoding = ENC_QUOTED_PRINTABLE;
3758 else if (encoding == ENC_8BIT)
3759 encoding = ENC_BASE64;
3762 /* check for line length limit */
3763 if (encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
3764 check_line_length(buf, 1000, &line) < 0) {
3768 msg = g_strdup_printf
3769 (_("Line %d exceeds the line length limit (998 bytes).\n"
3770 "The contents of the message might be broken on the way to the delivery.\n"
3772 "Send it anyway?"), line + 1);
3773 aval = alertpanel(_("Warning"), msg, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
3774 if (aval != G_ALERTDEFAULT) {
3782 if (encoding != ENC_UNKNOWN)
3783 procmime_encode_content(mimetext, encoding);
3785 /* append attachment parts */
3786 if (compose_use_attach(compose)) {
3787 MimeInfo *mimempart;
3789 mimempart = procmime_mimeinfo_new();
3790 mimempart->content = MIMECONTENT_EMPTY;
3791 mimempart->type = MIMETYPE_MULTIPART;
3792 mimempart->subtype = g_strdup("mixed");
3793 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
3794 generate_mime_boundary(NULL));
3796 mimetext->disposition = DISPOSITIONTYPE_INLINE;
3798 g_node_append(mimempart->node, mimetext->node);
3799 g_node_append(mimemsg->node, mimempart->node);
3801 compose_add_attachments(compose, mimempart);
3803 g_node_append(mimemsg->node, mimetext->node);
3805 /* sign message if sending */
3806 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
3807 privacy_system_can_sign(compose->privacy_system))
3808 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
3811 procmime_write_mimeinfo(mimemsg, fp);
3813 procmime_mimeinfo_free_all(mimemsg);
3818 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3820 GtkTextBuffer *buffer;
3821 GtkTextIter start, end;
3826 if ((fp = g_fopen(file, "wb")) == NULL) {
3827 FILE_OP_ERROR(file, "fopen");
3831 /* chmod for security */
3832 if (change_file_mode_rw(fp, file) < 0) {
3833 FILE_OP_ERROR(file, "chmod");
3834 g_warning("can't change file mode\n");
3837 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
3838 gtk_text_buffer_get_start_iter(buffer, &start);
3839 gtk_text_buffer_get_end_iter(buffer, &end);
3840 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
3842 chars = conv_codeset_strdup
3843 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
3846 if (!chars) return -1;
3849 len = strlen(chars);
3850 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3851 FILE_OP_ERROR(file, "fwrite");
3860 if (fclose(fp) == EOF) {
3861 FILE_OP_ERROR(file, "fclose");
3868 static gint compose_remove_reedit_target(Compose *compose)
3871 MsgInfo *msginfo = compose->targetinfo;
3873 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3874 if (!msginfo) return -1;
3876 item = msginfo->folder;
3877 g_return_val_if_fail(item != NULL, -1);
3879 if (procmsg_msg_exist(msginfo) &&
3880 (folder_has_parent_of_type(item, F_QUEUE) ||
3881 folder_has_parent_of_type(item, F_DRAFT)
3882 || msginfo == compose->autosaved_draft)) {
3883 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3884 g_warning("can't remove the old message\n");
3892 void compose_remove_draft(Compose *compose)
3895 MsgInfo *msginfo = compose->targetinfo;
3896 drafts = account_get_special_folder(compose->account, F_DRAFT);
3898 if (procmsg_msg_exist(msginfo)) {
3899 folder_item_remove_msg(drafts, msginfo->msgnum);
3904 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3906 return compose_queue_sub (compose, msgnum, item, FALSE);
3908 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3915 static gboolean lock = FALSE;
3916 PrefsAccount *mailac = NULL, *newsac = NULL;
3918 debug_print("queueing message...\n");
3919 g_return_val_if_fail(compose->account != NULL, -1);
3923 if (compose_check_entries(compose, check_subject) == FALSE) {
3928 if (!compose->to_list && !compose->newsgroup_list) {
3929 g_warning("can't get recipient list.");
3934 if (compose->to_list) {
3935 if (compose->account->protocol != A_NNTP)
3936 mailac = compose->account;
3937 else if (cur_account && cur_account->protocol != A_NNTP)
3938 mailac = cur_account;
3939 else if (!(mailac = compose_current_mail_account())) {
3941 alertpanel_error(_("No account for sending mails available!"));
3946 if (compose->newsgroup_list) {
3947 if (compose->account->protocol == A_NNTP)
3948 newsac = compose->account;
3949 else if (!newsac->protocol != A_NNTP) {
3951 alertpanel_error(_("No account for posting news available!"));
3956 if (prefs_common.linewrap_at_send)
3957 compose_wrap_all(compose);
3959 /* write queue header */
3960 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
3961 G_DIR_SEPARATOR, compose);
3962 if ((fp = g_fopen(tmp, "wb")) == NULL) {
3963 FILE_OP_ERROR(tmp, "fopen");
3968 if (change_file_mode_rw(fp, tmp) < 0) {
3969 FILE_OP_ERROR(tmp, "chmod");
3970 g_warning("can't change file mode\n");
3973 /* queueing variables */
3974 fprintf(fp, "AF:\n");
3975 fprintf(fp, "NF:0\n");
3976 fprintf(fp, "PS:10\n");
3977 fprintf(fp, "SRH:1\n");
3978 fprintf(fp, "SFN:\n");
3979 fprintf(fp, "DSR:\n");
3981 fprintf(fp, "MID:<%s>\n", compose->msgid);
3983 fprintf(fp, "MID:\n");
3984 fprintf(fp, "CFG:\n");
3985 fprintf(fp, "PT:0\n");
3986 fprintf(fp, "S:%s\n", compose->account->address);
3987 fprintf(fp, "RQ:\n");
3989 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3991 fprintf(fp, "SSV:\n");
3993 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3995 fprintf(fp, "NSV:\n");
3996 fprintf(fp, "SSH:\n");
3997 /* write recepient list */
3998 if (compose->to_list) {
3999 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4000 for (cur = compose->to_list->next; cur != NULL;
4002 fprintf(fp, ",<%s>", (gchar *)cur->data);
4005 /* write newsgroup list */
4006 if (compose->newsgroup_list) {
4008 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4009 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4010 fprintf(fp, ",%s", (gchar *)cur->data);
4013 /* Sylpheed account IDs */
4015 fprintf(fp, "MAID:%d\n", mailac->account_id);
4017 fprintf(fp, "NAID:%d\n", newsac->account_id);
4019 if (compose->privacy_system != NULL) {
4020 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4021 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4022 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4023 if (compose->use_encryption) {
4026 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4027 if (encdata != NULL)
4028 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4034 /* Save copy folder */
4035 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4036 gchar *savefolderid;
4038 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4039 fprintf(fp, "SCF:%s\n", savefolderid);
4040 g_free(savefolderid);
4042 /* Message-ID of message replying to */
4043 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4046 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4047 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4050 /* Message-ID of message forwarding to */
4051 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4054 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4055 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4060 if (compose->redirect_filename != NULL) {
4061 if (compose_redirect_write_to_file(compose, fp) < 0) {
4069 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND) < 0) {
4078 if (fclose(fp) == EOF) {
4079 FILE_OP_ERROR(tmp, "fclose");
4085 queue = account_get_special_folder(compose->account, F_QUEUE);
4087 g_warning("can't find queue folder\n");
4092 folder_item_scan(queue);
4093 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
4094 g_warning("can't queue the message\n");
4102 if (compose->mode == COMPOSE_REEDIT) {
4103 compose_remove_reedit_target(compose);
4106 if ((msgnum != NULL) && (item != NULL)) {
4114 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4117 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4119 struct stat statbuf;
4120 gchar *type, *subtype;
4121 GtkTreeModel *model;
4124 model = gtk_tree_view_get_model(tree_view);
4126 if (!gtk_tree_model_get_iter_first(model, &iter))
4129 gtk_tree_model_get(model, &iter,
4133 mimepart = procmime_mimeinfo_new();
4134 mimepart->content = MIMECONTENT_FILE;
4135 mimepart->data.filename = g_strdup(ainfo->file);
4136 mimepart->offset = 0;
4138 stat(ainfo->file, &statbuf);
4139 mimepart->length = statbuf.st_size;
4141 type = g_strdup(ainfo->content_type);
4143 if (!strchr(type, '/')) {
4145 type = g_strdup("application/octet-stream");
4148 subtype = strchr(type, '/') + 1;
4149 *(subtype - 1) = '\0';
4150 mimepart->type = procmime_get_media_type(type);
4151 mimepart->subtype = g_strdup(subtype);
4154 if (mimepart->type == MIMETYPE_MESSAGE &&
4155 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4156 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4158 g_hash_table_insert(mimepart->typeparameters,
4159 g_strdup("name"), g_strdup(ainfo->name));
4160 g_hash_table_insert(mimepart->dispositionparameters,
4161 g_strdup("filename"), g_strdup(ainfo->name));
4162 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4165 if (compose->use_signing) {
4166 if (ainfo->encoding == ENC_7BIT)
4167 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4168 else if (ainfo->encoding == ENC_8BIT)
4169 ainfo->encoding = ENC_BASE64;
4172 procmime_encode_content(mimepart, ainfo->encoding);
4174 g_node_append(parent->node, mimepart->node);
4175 } while (gtk_tree_model_iter_next(model, &iter));
4178 #define QUOTE_IF_REQUIRED(out, str) \
4180 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4184 len = strlen(str) + 3; \
4185 if ((__tmp = alloca(len)) == NULL) { \
4186 g_warning("can't allocate memory\n"); \
4187 g_string_free(header, TRUE); \
4190 g_snprintf(__tmp, len, "\"%s\"", str); \
4195 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4196 g_warning("can't allocate memory\n"); \
4197 g_string_free(header, TRUE); \
4200 strcpy(__tmp, str); \
4206 #define IS_IN_CUSTOM_HEADER(header) \
4207 (compose->account->add_customhdr && \
4208 custom_header_find(compose->account->customhdr_list, header) != NULL)
4210 static void compose_add_headerfield_from_headerlist(Compose *compose,
4212 const gchar *fieldname,
4213 const gchar *seperator)
4215 gchar *str, *fieldname_w_colon, *trans_fieldname;
4216 gboolean add_field = FALSE;
4218 ComposeHeaderEntry *headerentry;
4219 const gchar * headerentryname;
4222 if (IS_IN_CUSTOM_HEADER(fieldname))
4225 debug_print("Adding %s-fields\n", fieldname);
4227 fieldstr = g_string_sized_new(64);
4229 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4230 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4232 for (list = compose->header_list; list; list = list->next) {
4233 headerentry = ((ComposeHeaderEntry *)list->data);
4234 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4236 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4237 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4239 if (str[0] != '\0') {
4241 g_string_append(fieldstr, seperator);
4242 g_string_append(fieldstr, str);
4251 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4252 compose_convert_header
4253 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4254 strlen(fieldname) + 2, TRUE);
4255 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4259 g_free(fieldname_w_colon);
4260 g_string_free(fieldstr, TRUE);
4265 static gchar *compose_get_header(Compose *compose)
4267 gchar buf[BUFFSIZE];
4268 const gchar *entry_str;
4272 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4275 g_return_val_if_fail(compose->account != NULL, NULL);
4276 g_return_val_if_fail(compose->account->address != NULL, NULL);
4278 header = g_string_sized_new(64);
4281 if (compose->account->add_date) {
4282 get_rfc822_date(buf, sizeof(buf));
4283 g_string_append_printf(header, "Date: %s\n", buf);
4287 if (compose->account->name && *compose->account->name) {
4288 compose_convert_header
4289 (compose, buf, sizeof(buf), compose->account->name,
4290 strlen("From: "), TRUE);
4291 QUOTE_IF_REQUIRED(name, buf);
4292 g_string_append_printf(header, "From: %s <%s>\n",
4293 name, compose->account->address);
4295 g_string_append_printf(header, "From: %s\n", compose->account->address);
4298 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4301 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4304 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4307 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4310 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4311 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4314 compose_convert_header(compose, buf, sizeof(buf), str,
4315 strlen("Subject: "), FALSE);
4316 g_string_append_printf(header, "Subject: %s\n", buf);
4322 if (compose->account->gen_msgid) {
4323 generate_msgid(buf, sizeof(buf));
4324 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4325 compose->msgid = g_strdup(buf);
4328 if (compose->remove_references == FALSE) {
4330 if (compose->inreplyto && compose->to_list)
4331 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4334 if (compose->references)
4335 g_string_append_printf(header, "References: %s\n", compose->references);
4339 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4342 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4345 if (compose->account->organization &&
4346 strlen(compose->account->organization) &&
4347 !IS_IN_CUSTOM_HEADER("Organization")) {
4348 compose_convert_header(compose, buf, sizeof(buf),
4349 compose->account->organization,
4350 strlen("Organization: "), FALSE);
4351 g_string_append_printf(header, "Organization: %s\n", buf);
4354 /* Program version and system info */
4355 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4356 !compose->newsgroup_list) {
4357 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4359 gtk_major_version, gtk_minor_version, gtk_micro_version,
4362 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4363 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4365 gtk_major_version, gtk_minor_version, gtk_micro_version,
4369 /* custom headers */
4370 if (compose->account->add_customhdr) {
4373 for (cur = compose->account->customhdr_list; cur != NULL;
4375 CustomHeader *chdr = (CustomHeader *)cur->data;
4377 if (custom_header_is_allowed(chdr->name)) {
4378 compose_convert_header
4379 (compose, buf, sizeof(buf),
4380 chdr->value ? chdr->value : "",
4381 strlen(chdr->name) + 2, FALSE);
4382 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4388 switch (compose->priority) {
4389 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4390 "X-Priority: 1 (Highest)\n");
4392 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4393 "X-Priority: 2 (High)\n");
4395 case PRIORITY_NORMAL: break;
4396 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4397 "X-Priority: 4 (Low)\n");
4399 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4400 "X-Priority: 5 (Lowest)\n");
4402 default: debug_print("compose: priority unknown : %d\n",
4406 /* Request Return Receipt */
4407 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4408 if (compose->return_receipt) {
4409 if (compose->account->name
4410 && *compose->account->name) {
4411 compose_convert_header(compose, buf, sizeof(buf),
4412 compose->account->name,
4413 strlen("Disposition-Notification-To: "),
4415 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4417 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4421 /* get special headers */
4422 for (list = compose->header_list; list; list = list->next) {
4423 ComposeHeaderEntry *headerentry;
4426 gchar *headername_wcolon;
4427 gchar *headername_trans;
4430 gboolean standard_header = FALSE;
4432 headerentry = ((ComposeHeaderEntry *)list->data);
4434 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4435 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4440 if (!strstr(tmp, ":")) {
4441 headername_wcolon = g_strconcat(tmp, ":", NULL);
4442 headername = g_strdup(tmp);
4444 headername_wcolon = g_strdup(tmp);
4445 headername = g_strdup(strtok(tmp, ":"));
4449 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4450 Xstrdup_a(headervalue, entry_str, return NULL);
4451 subst_char(headervalue, '\r', ' ');
4452 subst_char(headervalue, '\n', ' ');
4453 string = std_headers;
4454 while (*string != NULL) {
4455 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4456 if (!strcmp(headername_trans,headername_wcolon))
4457 standard_header = TRUE;
4460 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4461 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
4464 g_free(headername_wcolon);
4468 g_string_free(header, FALSE);
4473 #undef IS_IN_CUSTOM_HEADER
4475 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
4476 gint header_len, gboolean addr_field)
4478 gchar *tmpstr = NULL;
4480 g_return_if_fail(src != NULL);
4481 g_return_if_fail(dest != NULL);
4483 if (len < 1) return;
4485 tmpstr = g_strdup(src);
4487 subst_char(tmpstr, '\n', ' ');
4488 subst_char(tmpstr, '\r', ' ');
4491 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4492 conv_get_charset_str(compose->out_encoding));
4496 static void compose_create_header_entry(Compose *compose)
4498 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4502 GList *combo_list = NULL;
4504 const gchar *header = NULL;
4505 ComposeHeaderEntry *headerentry;
4506 gboolean standard_header = FALSE;
4508 headerentry = g_new0(ComposeHeaderEntry, 1);
4511 combo = gtk_combo_new();
4513 while(*string != NULL) {
4514 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4517 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4518 g_list_free(combo_list);
4519 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4520 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4521 G_CALLBACK(compose_grab_focus_cb), compose);
4522 gtk_widget_show(combo);
4523 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4524 if (compose->header_last) {
4525 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4527 while (*string != NULL) {
4528 if (!strcmp(*string, last_header_entry))
4529 standard_header = TRUE;
4532 if (standard_header)
4533 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4535 if (!compose->header_last || !standard_header) {
4536 switch(compose->account->protocol) {
4538 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4541 header = prefs_common.trans_hdr ? _("To:") : "To:";
4546 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4548 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4549 G_CALLBACK(compose_grab_focus_cb), compose);
4552 entry = gtk_entry_new();
4553 gtk_widget_show(entry);
4554 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);
4556 g_signal_connect(G_OBJECT(entry), "key-press-event",
4557 G_CALLBACK(compose_headerentry_key_press_event_cb),
4559 g_signal_connect(G_OBJECT(entry), "changed",
4560 G_CALLBACK(compose_headerentry_changed_cb),
4562 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
4563 G_CALLBACK(compose_grab_focus_cb), compose);
4566 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
4567 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
4568 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4569 g_signal_connect(G_OBJECT(entry), "drag_data_received",
4570 G_CALLBACK(compose_header_drag_received_cb),
4572 g_signal_connect(G_OBJECT(entry), "drag-drop",
4573 G_CALLBACK(compose_drag_drop),
4576 address_completion_register_entry(GTK_ENTRY(entry));
4578 headerentry->compose = compose;
4579 headerentry->combo = combo;
4580 headerentry->entry = entry;
4581 headerentry->headernum = compose->header_nextrow;
4583 compose->header_nextrow++;
4584 compose->header_last = headerentry;
4587 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4589 ComposeHeaderEntry *last_header;
4591 last_header = compose->header_last;
4593 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4594 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4597 static GtkWidget *compose_create_header(Compose *compose)
4601 GtkWidget *from_optmenu_hbox;
4602 GtkWidget *header_scrolledwin;
4603 GtkWidget *header_table;
4607 /* header labels and entries */
4608 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4609 gtk_widget_show(header_scrolledwin);
4610 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4612 header_table = gtk_table_new(2, 2, FALSE);
4613 gtk_widget_show(header_table);
4614 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4615 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4616 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4619 /* option menu for selecting accounts */
4620 hbox = gtk_hbox_new(FALSE, 0);
4621 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4622 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4623 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4625 from_optmenu_hbox = compose_account_option_menu_create(compose);
4626 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4627 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4630 compose->header_table = header_table;
4631 compose->header_list = NULL;
4632 compose->header_nextrow = count;
4634 compose_create_header_entry(compose);
4636 compose->table = NULL;
4638 return header_scrolledwin ;
4641 GtkWidget *compose_create_attach(Compose *compose)
4643 GtkWidget *attach_scrwin;
4644 GtkWidget *attach_clist;
4646 GtkListStore *store;
4647 GtkCellRenderer *renderer;
4648 GtkTreeViewColumn *column;
4649 GtkTreeSelection *selection;
4651 /* attachment list */
4652 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4653 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4654 GTK_POLICY_AUTOMATIC,
4655 GTK_POLICY_AUTOMATIC);
4656 gtk_widget_set_size_request(attach_scrwin, -1, 80);
4658 store = gtk_list_store_new(N_ATTACH_COLS,
4663 G_TYPE_AUTO_POINTER,
4665 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
4666 (GTK_TREE_MODEL(store)));
4667 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4668 g_object_unref(store);
4670 renderer = gtk_cell_renderer_text_new();
4671 column = gtk_tree_view_column_new_with_attributes
4672 (_("Mime type"), renderer, "text",
4673 COL_MIMETYPE, NULL);
4674 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
4676 renderer = gtk_cell_renderer_text_new();
4677 column = gtk_tree_view_column_new_with_attributes
4678 (_("Size"), renderer, "text",
4680 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
4682 renderer = gtk_cell_renderer_text_new();
4683 column = gtk_tree_view_column_new_with_attributes
4684 (_("Name"), renderer, "text",
4686 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
4688 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
4689 prefs_common.enable_rules_hint);
4690 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
4691 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
4693 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
4694 G_CALLBACK(attach_selected), compose);
4695 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
4696 G_CALLBACK(attach_button_pressed), compose);
4697 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
4698 G_CALLBACK(attach_key_pressed), compose);
4701 gtk_drag_dest_set(attach_clist,
4702 GTK_DEST_DEFAULT_ALL, compose_mime_types,
4703 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
4704 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4705 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
4706 G_CALLBACK(compose_attach_drag_received_cb),
4708 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
4709 G_CALLBACK(compose_drag_drop),
4712 compose->attach_scrwin = attach_scrwin;
4713 compose->attach_clist = attach_clist;
4715 return attach_scrwin;
4718 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4719 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4721 static GtkWidget *compose_create_others(Compose *compose)
4724 GtkWidget *savemsg_checkbtn;
4725 GtkWidget *savemsg_entry;
4726 GtkWidget *savemsg_select;
4729 gchar *folderidentifier;
4731 /* Table for settings */
4732 table = gtk_table_new(3, 1, FALSE);
4733 gtk_widget_show(table);
4734 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4737 /* Save Message to folder */
4738 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4739 gtk_widget_show(savemsg_checkbtn);
4740 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4741 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4742 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4744 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
4745 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
4747 savemsg_entry = gtk_entry_new();
4748 gtk_widget_show(savemsg_entry);
4749 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4750 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4751 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
4752 G_CALLBACK(compose_grab_focus_cb), compose);
4753 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4754 folderidentifier = folder_item_get_identifier(account_get_special_folder
4755 (compose->account, F_OUTBOX));
4756 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4757 g_free(folderidentifier);
4760 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4761 gtk_widget_show(savemsg_select);
4762 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4763 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
4764 G_CALLBACK(compose_savemsg_select_cb),
4769 compose->savemsg_checkbtn = savemsg_checkbtn;
4770 compose->savemsg_entry = savemsg_entry;
4775 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4777 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4778 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4781 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4786 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4789 path = folder_item_get_identifier(dest);
4791 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4795 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4801 GtkWidget *handlebox;
4803 GtkWidget *notebook;
4808 GtkWidget *subject_hbox;
4809 GtkWidget *subject_frame;
4810 GtkWidget *subject_entry;
4814 GtkWidget *edit_vbox;
4815 GtkWidget *ruler_hbox;
4817 GtkWidget *scrolledwin;
4819 GtkTextBuffer *buffer;
4820 GtkClipboard *clipboard;
4822 UndoMain *undostruct;
4824 gchar *titles[N_ATTACH_COLS];
4825 guint n_menu_entries;
4828 gboolean success[1];
4829 GtkWidget *popupmenu;
4830 GtkItemFactory *popupfactory;
4831 GtkItemFactory *ifactory;
4832 GtkWidget *tmpl_menu;
4834 GtkWidget *menuitem;
4837 GtkAspell * gtkaspell = NULL;
4840 static GdkGeometry geometry;
4842 g_return_val_if_fail(account != NULL, NULL);
4844 debug_print("Creating compose window...\n");
4845 compose = g_new0(Compose, 1);
4847 titles[COL_MIMETYPE] = _("MIME type");
4848 titles[COL_SIZE] = _("Size");
4849 titles[COL_NAME] = _("Name");
4851 compose->account = account;
4853 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4854 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
4855 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
4857 if (!geometry.max_width) {
4858 geometry.max_width = gdk_screen_width();
4859 geometry.max_height = gdk_screen_height();
4861 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4862 &geometry, GDK_HINT_MAX_SIZE);
4863 if (!geometry.min_width) {
4864 geometry.min_width = 600;
4865 geometry.min_height = 480;
4867 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4868 &geometry, GDK_HINT_MIN_SIZE);
4869 gtk_widget_set_uposition(window, prefs_common.compose_x,
4870 prefs_common.compose_y);
4872 g_signal_connect(G_OBJECT(window), "delete_event",
4873 G_CALLBACK(compose_delete_cb), compose);
4874 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4875 gtk_widget_realize(window);
4877 gtkut_widget_set_composer_icon(window);
4879 vbox = gtk_vbox_new(FALSE, 0);
4880 gtk_container_add(GTK_CONTAINER(window), vbox);
4882 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4883 menubar = menubar_create(window, compose_entries,
4884 n_menu_entries, "<Compose>", compose);
4885 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4887 if (prefs_common.toolbar_detachable) {
4888 handlebox = gtk_handle_box_new();
4890 handlebox = gtk_hbox_new(FALSE, 0);
4892 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4894 gtk_widget_realize(handlebox);
4895 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
4898 vbox2 = gtk_vbox_new(FALSE, 2);
4899 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4900 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4903 notebook = gtk_notebook_new();
4904 gtk_widget_set_size_request(notebook, -1, 130);
4905 gtk_widget_show(notebook);
4907 /* header labels and entries */
4908 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4909 /* attachment list */
4910 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4912 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4915 subject_hbox = gtk_hbox_new(FALSE, 0);
4916 gtk_widget_show(subject_hbox);
4918 subject_frame = gtk_frame_new(NULL);
4919 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4920 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4921 gtk_widget_show(subject_frame);
4923 subject = gtk_hbox_new(FALSE, 0);
4924 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4925 gtk_widget_show(subject);
4927 label = gtk_label_new(_("Subject:"));
4928 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4929 gtk_widget_show(label);
4931 subject_entry = gtk_entry_new();
4932 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4933 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
4934 G_CALLBACK(compose_grab_focus_cb), compose);
4935 gtk_widget_show(subject_entry);
4936 compose->subject_entry = subject_entry;
4937 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4939 edit_vbox = gtk_vbox_new(FALSE, 0);
4941 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4944 ruler_hbox = gtk_hbox_new(FALSE, 0);
4945 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4947 ruler = gtk_shruler_new();
4948 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4949 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4953 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4954 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4955 GTK_POLICY_AUTOMATIC,
4956 GTK_POLICY_AUTOMATIC);
4957 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
4959 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4960 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
4962 text = gtk_text_view_new();
4963 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
4964 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
4965 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
4966 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
4967 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
4969 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4971 g_signal_connect_after(G_OBJECT(text), "size_allocate",
4972 G_CALLBACK(compose_edit_size_alloc),
4974 g_signal_connect(G_OBJECT(buffer), "changed",
4975 G_CALLBACK(compose_changed_cb), compose);
4976 g_signal_connect(G_OBJECT(text), "grab_focus",
4977 G_CALLBACK(compose_grab_focus_cb), compose);
4978 g_signal_connect(G_OBJECT(buffer), "insert_text",
4979 G_CALLBACK(text_inserted), compose);
4982 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
4983 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
4984 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4985 g_signal_connect(G_OBJECT(text), "drag_data_received",
4986 G_CALLBACK(compose_insert_drag_received_cb),
4988 g_signal_connect(G_OBJECT(text), "drag-drop",
4989 G_CALLBACK(compose_drag_drop),
4991 gtk_widget_show_all(vbox);
4993 /* pane between attach clist and text */
4994 paned = gtk_vpaned_new();
4995 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4996 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4997 gtk_paned_add1(GTK_PANED(paned), notebook);
4998 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4999 gtk_widget_show_all(paned);
5002 if (prefs_common.textfont) {
5003 PangoFontDescription *font_desc;
5005 font_desc = pango_font_description_from_string
5006 (prefs_common.textfont);
5008 gtk_widget_modify_font(text, font_desc);
5009 pango_font_description_free(font_desc);
5013 color[0] = quote_color;
5014 cmap = gdk_drawable_get_colormap(window->window);
5015 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5016 if (success[0] == FALSE) {
5019 g_warning("Compose: color allocation failed.\n");
5020 style = gtk_widget_get_style(text);
5021 quote_color = style->black;
5024 n_entries = sizeof(compose_popup_entries) /
5025 sizeof(compose_popup_entries[0]);
5026 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5027 "<Compose>", &popupfactory,
5030 ifactory = gtk_item_factory_from_widget(menubar);
5031 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5032 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5033 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5035 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5037 undostruct = undo_init(text);
5038 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5041 address_completion_start(window);
5043 compose->window = window;
5044 compose->vbox = vbox;
5045 compose->menubar = menubar;
5046 compose->handlebox = handlebox;
5048 compose->vbox2 = vbox2;
5050 compose->paned = paned;
5052 compose->edit_vbox = edit_vbox;
5053 compose->ruler_hbox = ruler_hbox;
5054 compose->ruler = ruler;
5055 compose->scrolledwin = scrolledwin;
5056 compose->text = text;
5058 compose->focused_editable = NULL;
5060 compose->popupmenu = popupmenu;
5061 compose->popupfactory = popupfactory;
5063 compose->tmpl_menu = tmpl_menu;
5065 compose->mode = mode;
5067 compose->targetinfo = NULL;
5068 compose->replyinfo = NULL;
5069 compose->fwdinfo = NULL;
5071 compose->replyto = NULL;
5073 compose->bcc = NULL;
5074 compose->followup_to = NULL;
5076 compose->ml_post = NULL;
5078 compose->inreplyto = NULL;
5079 compose->references = NULL;
5080 compose->msgid = NULL;
5081 compose->boundary = NULL;
5083 compose->autowrap = prefs_common.autowrap;
5085 compose->use_signing = FALSE;
5086 compose->use_encryption = FALSE;
5087 compose->privacy_system = NULL;
5089 compose->modified = FALSE;
5091 compose->return_receipt = FALSE;
5093 compose->to_list = NULL;
5094 compose->newsgroup_list = NULL;
5096 compose->undostruct = undostruct;
5098 compose->sig_str = NULL;
5100 compose->exteditor_file = NULL;
5101 compose->exteditor_pid = -1;
5102 compose->exteditor_tag = -1;
5103 compose->draft_timeout_tag = -1;
5106 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5107 if (mode != COMPOSE_REDIRECT) {
5108 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5109 strcmp(prefs_common.dictionary, _("None"))) {
5110 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5111 prefs_common.dictionary,
5112 conv_get_locale_charset_str(),
5113 prefs_common.misspelled_col,
5114 prefs_common.check_while_typing,
5115 prefs_common.use_alternate,
5116 GTK_TEXT_VIEW(text),
5117 GTK_WINDOW(compose->window));
5119 alertpanel_error(_("Spell checker could not "
5121 gtkaspell_checkers_strerror());
5122 gtkaspell_checkers_reset_error();
5125 GtkWidget *menuitem;
5127 if (!gtkaspell_set_sug_mode(gtkaspell,
5128 prefs_common.aspell_sugmode)) {
5129 debug_print("Aspell: could not set "
5130 "suggestion mode %s\n",
5131 gtkaspell_checkers_strerror());
5132 gtkaspell_checkers_reset_error();
5135 menuitem = gtk_item_factory_get_item(ifactory,
5136 "/Spelling/Spelling Configuration");
5137 gtkaspell_populate_submenu(gtkaspell, menuitem);
5138 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5142 compose->gtkaspell = gtkaspell;
5145 compose_select_account(compose, account, TRUE);
5147 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5148 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5149 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5151 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5152 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5154 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5155 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5158 if (account->protocol != A_NNTP)
5159 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5161 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5163 addressbook_set_target_compose(compose);
5165 if (mode != COMPOSE_REDIRECT)
5166 compose_set_template_menu(compose);
5168 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5169 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5172 compose_list = g_list_append(compose_list, compose);
5174 if (!prefs_common.show_ruler)
5175 gtk_widget_hide(ruler_hbox);
5177 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5178 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5179 prefs_common.show_ruler);
5182 compose->priority = PRIORITY_NORMAL;
5183 compose_update_priority_menu_item(compose);
5185 compose_set_out_encoding(compose);
5188 compose_update_actions_menu(compose);
5190 /* Privacy Systems menu */
5191 compose_update_privacy_systems_menu(compose);
5193 activate_privacy_system(compose, account);
5194 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5195 gtk_widget_show(window);
5200 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5206 gint num = 0, def_menu = 0;
5208 accounts = account_get_list();
5209 g_return_val_if_fail(accounts != NULL, NULL);
5211 hbox = gtk_hbox_new(FALSE, 0);
5212 optmenu = gtk_option_menu_new();
5213 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5214 menu = gtk_menu_new();
5216 for (; accounts != NULL; accounts = accounts->next, num++) {
5217 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5218 GtkWidget *menuitem;
5221 if (ac == compose->account) def_menu = num;
5224 name = g_strdup_printf("%s: %s <%s>",
5226 ac->name, ac->address);
5228 name = g_strdup_printf("%s: %s",
5229 ac->account_name, ac->address);
5230 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5232 g_signal_connect(G_OBJECT(menuitem), "activate",
5233 G_CALLBACK(account_activated),
5237 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5238 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5243 static void compose_set_priority_cb(gpointer data,
5247 Compose *compose = (Compose *) data;
5248 compose->priority = action;
5251 static void compose_update_priority_menu_item(Compose * compose)
5253 GtkItemFactory *ifactory;
5254 GtkWidget *menuitem = NULL;
5256 ifactory = gtk_item_factory_from_widget(compose->menubar);
5258 switch (compose->priority) {
5259 case PRIORITY_HIGHEST:
5260 menuitem = gtk_item_factory_get_item
5261 (ifactory, "/Options/Priority/Highest");
5264 menuitem = gtk_item_factory_get_item
5265 (ifactory, "/Options/Priority/High");
5267 case PRIORITY_NORMAL:
5268 menuitem = gtk_item_factory_get_item
5269 (ifactory, "/Options/Priority/Normal");
5272 menuitem = gtk_item_factory_get_item
5273 (ifactory, "/Options/Priority/Low");
5275 case PRIORITY_LOWEST:
5276 menuitem = gtk_item_factory_get_item
5277 (ifactory, "/Options/Priority/Lowest");
5280 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5283 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5285 Compose *compose = (Compose *) data;
5287 GtkItemFactory *ifactory;
5288 gboolean can_sign = FALSE, can_encrypt = FALSE;
5290 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5292 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5295 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5296 g_free(compose->privacy_system);
5297 compose->privacy_system = NULL;
5298 if (systemid != NULL) {
5299 compose->privacy_system = g_strdup(systemid);
5301 can_sign = privacy_system_can_sign(systemid);
5302 can_encrypt = privacy_system_can_encrypt(systemid);
5305 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5307 ifactory = gtk_item_factory_from_widget(compose->menubar);
5308 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5309 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5312 static void compose_update_privacy_system_menu_item(Compose * compose)
5314 static gchar *branch_path = "/Options/Privacy System";
5315 GtkItemFactory *ifactory;
5316 GtkWidget *menuitem = NULL;
5318 gboolean can_sign = FALSE, can_encrypt = FALSE;
5320 ifactory = gtk_item_factory_from_widget(compose->menubar);
5322 if (compose->privacy_system != NULL) {
5325 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5326 g_return_if_fail(menuitem != NULL);
5328 amenu = GTK_MENU_SHELL(menuitem)->children;
5330 while (amenu != NULL) {
5331 GList *alist = amenu->next;
5333 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
5334 if (systemid != NULL)
5335 if (strcmp(systemid, compose->privacy_system) == 0) {
5336 menuitem = GTK_WIDGET(amenu->data);
5338 can_sign = privacy_system_can_sign(systemid);
5339 can_encrypt = privacy_system_can_encrypt(systemid);
5346 if (menuitem != NULL)
5347 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5350 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5351 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5354 static void compose_set_out_encoding(Compose *compose)
5356 GtkItemFactoryEntry *entry;
5357 GtkItemFactory *ifactory;
5358 CharSet out_encoding;
5359 gchar *path, *p, *q;
5362 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
5363 ifactory = gtk_item_factory_from_widget(compose->menubar);
5365 for (entry = compose_entries; entry->callback != compose_address_cb;
5367 if (entry->callback == compose_set_encoding_cb &&
5368 (CharSet)entry->callback_action == out_encoding) {
5369 p = q = path = g_strdup(entry->path);
5381 item = gtk_item_factory_get_item(ifactory, path);
5382 gtk_widget_activate(item);
5389 static void compose_set_template_menu(Compose *compose)
5391 GSList *tmpl_list, *cur;
5395 tmpl_list = template_get_config();
5397 menu = gtk_menu_new();
5399 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5400 Template *tmpl = (Template *)cur->data;
5402 item = gtk_menu_item_new_with_label(tmpl->name);
5403 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5404 g_signal_connect(G_OBJECT(item), "activate",
5405 G_CALLBACK(compose_template_activate_cb),
5407 g_object_set_data(G_OBJECT(item), "template", tmpl);
5408 gtk_widget_show(item);
5411 gtk_widget_show(menu);
5412 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5415 void compose_update_actions_menu(Compose *compose)
5417 GtkItemFactory *ifactory;
5419 ifactory = gtk_item_factory_from_widget(compose->menubar);
5420 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5423 void compose_update_privacy_systems_menu(Compose *compose)
5425 static gchar *branch_path = "/Options/Privacy System";
5426 GtkItemFactory *ifactory;
5427 GtkWidget *menuitem;
5428 GSList *systems, *cur;
5431 GtkWidget *system_none;
5434 ifactory = gtk_item_factory_from_widget(compose->menubar);
5436 /* remove old entries */
5437 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5438 g_return_if_fail(menuitem != NULL);
5440 amenu = GTK_MENU_SHELL(menuitem)->children->next;
5441 while (amenu != NULL) {
5442 GList *alist = amenu->next;
5443 gtk_widget_destroy(GTK_WIDGET(amenu->data));
5447 system_none = gtk_item_factory_get_widget(ifactory,
5448 "/Options/Privacy System/None");
5450 g_signal_connect(G_OBJECT(system_none), "activate",
5451 G_CALLBACK(compose_set_privacy_system_cb), compose);
5453 systems = privacy_get_system_ids();
5454 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
5455 gchar *systemid = cur->data;
5457 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
5458 widget = gtk_radio_menu_item_new_with_label(group,
5459 privacy_system_get_name(systemid));
5460 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
5461 g_strdup(systemid), g_free);
5462 g_signal_connect(G_OBJECT(widget), "activate",
5463 G_CALLBACK(compose_set_privacy_system_cb), compose);
5465 gtk_menu_append(GTK_MENU(system_none->parent), widget);
5466 gtk_widget_show(widget);
5469 g_slist_free(systems);
5472 void compose_reflect_prefs_all(void)
5477 for (cur = compose_list; cur != NULL; cur = cur->next) {
5478 compose = (Compose *)cur->data;
5479 compose_set_template_menu(compose);
5483 void compose_reflect_prefs_pixmap_theme(void)
5488 for (cur = compose_list; cur != NULL; cur = cur->next) {
5489 compose = (Compose *)cur->data;
5490 toolbar_update(TOOLBAR_COMPOSE, compose);
5494 static void compose_template_apply(Compose *compose, Template *tmpl,
5498 GtkTextBuffer *buffer;
5504 if (!tmpl || !tmpl->value) return;
5506 text = GTK_TEXT_VIEW(compose->text);
5507 buffer = gtk_text_view_get_buffer(text);
5509 if (tmpl->subject && *tmpl->subject != '\0')
5510 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5512 if (tmpl->to && *tmpl->to != '\0')
5513 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5514 if (tmpl->cc && *tmpl->cc != '\0')
5515 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5517 if (tmpl->bcc && *tmpl->bcc != '\0')
5518 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5521 gtk_text_buffer_set_text(buffer, "", -1);
5523 mark = gtk_text_buffer_get_insert(buffer);
5524 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
5526 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
5527 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5530 if (prefs_common.quotemark && *prefs_common.quotemark)
5531 qmark = prefs_common.quotemark;
5535 if (compose->replyinfo != NULL)
5536 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5537 tmpl->value, qmark, NULL);
5538 else if (compose->fwdinfo != NULL)
5539 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
5540 tmpl->value, qmark, NULL);
5545 if (replace && parsed_str && compose->account->auto_sig)
5546 compose_insert_sig(compose, FALSE);
5548 if (replace && parsed_str) {
5549 gtk_text_buffer_get_start_iter(buffer, &iter);
5550 gtk_text_buffer_place_cursor(buffer, &iter);
5554 compose_changed_cb(NULL, compose);
5557 static void compose_destroy(Compose *compose)
5559 compose_list = g_list_remove(compose_list, compose);
5561 /* NOTE: address_completion_end() does nothing with the window
5562 * however this may change. */
5563 address_completion_end(compose->window);
5565 slist_free_strings(compose->to_list);
5566 g_slist_free(compose->to_list);
5567 slist_free_strings(compose->newsgroup_list);
5568 g_slist_free(compose->newsgroup_list);
5569 slist_free_strings(compose->header_list);
5570 g_slist_free(compose->header_list);
5572 procmsg_msginfo_free(compose->targetinfo);
5573 procmsg_msginfo_free(compose->replyinfo);
5574 procmsg_msginfo_free(compose->fwdinfo);
5576 g_free(compose->replyto);
5577 g_free(compose->cc);
5578 g_free(compose->bcc);
5579 g_free(compose->newsgroups);
5580 g_free(compose->followup_to);
5582 g_free(compose->ml_post);
5584 g_free(compose->inreplyto);
5585 g_free(compose->references);
5586 g_free(compose->msgid);
5587 g_free(compose->boundary);
5589 if (compose->redirect_filename)
5590 g_free(compose->redirect_filename);
5591 if (compose->undostruct)
5592 undo_destroy(compose->undostruct);
5594 g_free(compose->sig_str);
5596 g_free(compose->exteditor_file);
5598 if (addressbook_get_target_compose() == compose)
5599 addressbook_set_target_compose(NULL);
5602 if (compose->gtkaspell) {
5603 gtkaspell_delete(compose->gtkaspell);
5604 compose->gtkaspell = NULL;
5608 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5609 prefs_common.compose_height = compose->window->allocation.height;
5611 if (!gtk_widget_get_parent(compose->paned))
5612 gtk_widget_destroy(compose->paned);
5613 gtk_widget_destroy(compose->popupmenu);
5615 gtk_widget_destroy(compose->window);
5616 toolbar_destroy(compose->toolbar);
5617 g_free(compose->toolbar);
5621 static void compose_attach_info_free(AttachInfo *ainfo)
5623 g_free(ainfo->file);
5624 g_free(ainfo->content_type);
5625 g_free(ainfo->name);
5629 static void compose_attach_remove_selected(Compose *compose)
5631 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
5632 GtkTreeSelection *selection;
5634 GtkTreeModel *model;
5636 selection = gtk_tree_view_get_selection(tree_view);
5637 sel = gtk_tree_selection_get_selected_rows(selection, &model);
5642 for (cur = sel; cur != NULL; cur = cur->next) {
5643 GtkTreePath *path = cur->data;
5644 GtkTreeRowReference *ref = gtk_tree_row_reference_new
5647 gtk_tree_path_free(path);
5650 for (cur = sel; cur != NULL; cur = cur->next) {
5651 GtkTreeRowReference *ref = cur->data;
5652 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
5655 if (gtk_tree_model_get_iter(model, &iter, path))
5656 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
5658 gtk_tree_path_free(path);
5659 gtk_tree_row_reference_free(ref);
5665 static struct _AttachProperty
5668 GtkWidget *mimetype_entry;
5669 GtkWidget *encoding_optmenu;
5670 GtkWidget *path_entry;
5671 GtkWidget *filename_entry;
5673 GtkWidget *cancel_btn;
5676 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
5678 gtk_tree_path_free((GtkTreePath *)ptr);
5681 static void compose_attach_property(Compose *compose)
5683 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
5685 GtkOptionMenu *optmenu;
5686 GtkTreeSelection *selection;
5688 GtkTreeModel *model;
5691 static gboolean cancelled;
5693 /* only if one selected */
5694 selection = gtk_tree_view_get_selection(tree_view);
5695 if (gtk_tree_selection_count_selected_rows(selection) != 1)
5698 sel = gtk_tree_selection_get_selected_rows(selection, &model);
5702 path = (GtkTreePath *) sel->data;
5703 gtk_tree_model_get_iter(model, &iter, path);
5704 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
5707 g_list_foreach(sel, gtk_tree_path_free_, NULL);
5713 if (!attach_prop.window)
5714 compose_attach_property_create(&cancelled);
5715 gtk_widget_grab_focus(attach_prop.ok_btn);
5716 gtk_widget_show(attach_prop.window);
5717 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5719 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5720 if (ainfo->encoding == ENC_UNKNOWN)
5721 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5722 GINT_TO_POINTER(ENC_BASE64));
5724 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5725 GINT_TO_POINTER(ainfo->encoding));
5727 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5728 ainfo->content_type ? ainfo->content_type : "");
5729 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5730 ainfo->file ? ainfo->file : "");
5731 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5732 ainfo->name ? ainfo->name : "");
5735 const gchar *entry_text;
5737 gchar *cnttype = NULL;
5741 GtkWidget *menuitem;
5746 gtk_widget_hide(attach_prop.window);
5751 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5752 if (*entry_text != '\0') {
5755 text = g_strstrip(g_strdup(entry_text));
5756 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5757 cnttype = g_strdup(text);
5760 alertpanel_error(_("Invalid MIME type."));
5766 menu = gtk_option_menu_get_menu(optmenu);
5767 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5768 ainfo->encoding = GPOINTER_TO_INT
5769 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
5771 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5772 if (*entry_text != '\0') {
5773 if (is_file_exist(entry_text) &&
5774 (size = get_file_size(entry_text)) > 0)
5775 file = g_strdup(entry_text);
5778 (_("File doesn't exist or is empty."));
5784 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5785 if (*entry_text != '\0') {
5786 g_free(ainfo->name);
5787 ainfo->name = g_strdup(entry_text);
5791 g_free(ainfo->content_type);
5792 ainfo->content_type = cnttype;
5795 g_free(ainfo->file);
5801 /* update tree store */
5802 text = to_human_readable(ainfo->size);
5803 gtk_tree_model_get_iter(model, &iter, path);
5804 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
5805 COL_MIMETYPE, ainfo->content_type,
5807 COL_NAME, ainfo->file,
5813 gtk_tree_path_free(path);
5816 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5818 label = gtk_label_new(str); \
5819 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5820 GTK_FILL, 0, 0, 0); \
5821 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5823 entry = gtk_entry_new(); \
5824 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5825 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5828 static void compose_attach_property_create(gboolean *cancelled)
5834 GtkWidget *mimetype_entry;
5837 GtkWidget *optmenu_menu;
5838 GtkWidget *menuitem;
5839 GtkWidget *path_entry;
5840 GtkWidget *filename_entry;
5843 GtkWidget *cancel_btn;
5844 GList *mime_type_list, *strlist;
5846 debug_print("Creating attach_property window...\n");
5848 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5849 gtk_widget_set_size_request(window, 480, -1);
5850 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5851 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
5852 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5853 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5854 g_signal_connect(G_OBJECT(window), "delete_event",
5855 G_CALLBACK(attach_property_delete_event),
5857 g_signal_connect(G_OBJECT(window), "key_press_event",
5858 G_CALLBACK(attach_property_key_pressed),
5861 vbox = gtk_vbox_new(FALSE, 8);
5862 gtk_container_add(GTK_CONTAINER(window), vbox);
5864 table = gtk_table_new(4, 2, FALSE);
5865 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5866 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5867 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5869 label = gtk_label_new(_("MIME type"));
5870 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5872 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5873 mimetype_entry = gtk_combo_new();
5874 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5875 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5877 /* stuff with list */
5878 mime_type_list = procmime_get_mime_type_list();
5880 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5881 MimeType *type = (MimeType *) mime_type_list->data;
5882 strlist = g_list_append(strlist,
5883 g_strdup_printf("%s/%s",
5884 type->type, type->sub_type));
5887 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5889 for (mime_type_list = strlist; mime_type_list != NULL;
5890 mime_type_list = mime_type_list->next)
5891 g_free(mime_type_list->data);
5892 g_list_free(strlist);
5894 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5896 label = gtk_label_new(_("Encoding"));
5897 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5899 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5901 hbox = gtk_hbox_new(FALSE, 0);
5902 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5903 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5905 optmenu = gtk_option_menu_new();
5906 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5908 optmenu_menu = gtk_menu_new();
5909 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5910 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5911 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5912 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5913 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
5914 ENC_QUOTED_PRINTABLE);
5915 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5917 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5919 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5921 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5922 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5924 gtkut_stock_button_set_create(&hbbox, &ok_btn, GTK_STOCK_OK,
5925 &cancel_btn, GTK_STOCK_CANCEL,
5927 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5928 gtk_widget_grab_default(ok_btn);
5930 g_signal_connect(G_OBJECT(ok_btn), "clicked",
5931 G_CALLBACK(attach_property_ok),
5933 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
5934 G_CALLBACK(attach_property_cancel),
5937 gtk_widget_show_all(vbox);
5939 attach_prop.window = window;
5940 attach_prop.mimetype_entry = mimetype_entry;
5941 attach_prop.encoding_optmenu = optmenu;
5942 attach_prop.path_entry = path_entry;
5943 attach_prop.filename_entry = filename_entry;
5944 attach_prop.ok_btn = ok_btn;
5945 attach_prop.cancel_btn = cancel_btn;
5948 #undef SET_LABEL_AND_ENTRY
5950 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5956 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5962 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5963 gboolean *cancelled)
5971 static gboolean attach_property_key_pressed(GtkWidget *widget,
5973 gboolean *cancelled)
5975 if (event && event->keyval == GDK_Escape) {
5982 static void compose_exec_ext_editor(Compose *compose)
5989 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
5990 G_DIR_SEPARATOR, compose);
5992 if (pipe(pipe_fds) < 0) {
5998 if ((pid = fork()) < 0) {
6005 /* close the write side of the pipe */
6008 compose->exteditor_file = g_strdup(tmp);
6009 compose->exteditor_pid = pid;
6011 compose_set_ext_editor_sensitive(compose, FALSE);
6013 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6014 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6018 } else { /* process-monitoring process */
6024 /* close the read side of the pipe */
6027 if (compose_write_body_to_file(compose, tmp) < 0) {
6028 fd_write_all(pipe_fds[1], "2\n", 2);
6032 pid_ed = compose_exec_ext_editor_real(tmp);
6034 fd_write_all(pipe_fds[1], "1\n", 2);
6038 /* wait until editor is terminated */
6039 waitpid(pid_ed, NULL, 0);
6041 fd_write_all(pipe_fds[1], "0\n", 2);
6048 #endif /* G_OS_UNIX */
6052 static gint compose_exec_ext_editor_real(const gchar *file)
6054 static gchar *def_cmd = "emacs %s";
6060 g_return_val_if_fail(file != NULL, -1);
6062 if ((pid = fork()) < 0) {
6067 if (pid != 0) return pid;
6069 /* grandchild process */
6071 if (setpgid(0, getppid()))
6074 if (prefs_common.ext_editor_cmd &&
6075 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6076 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6077 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6079 if (prefs_common.ext_editor_cmd)
6080 g_warning("External editor command line is invalid: '%s'\n",
6081 prefs_common.ext_editor_cmd);
6082 g_snprintf(buf, sizeof(buf), def_cmd, file);
6085 cmdline = strsplit_with_quote(buf, " ", 1024);
6086 execvp(cmdline[0], cmdline);
6089 g_strfreev(cmdline);
6094 static gboolean compose_ext_editor_kill(Compose *compose)
6096 pid_t pgid = compose->exteditor_pid * -1;
6099 ret = kill(pgid, 0);
6101 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6105 msg = g_strdup_printf
6106 (_("The external editor is still working.\n"
6107 "Force terminating the process?\n"
6108 "process group id: %d"), -pgid);
6109 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_YES, GTK_STOCK_NO,
6110 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
6114 if (val == G_ALERTDEFAULT) {
6115 g_source_remove(compose->exteditor_tag);
6116 g_io_channel_shutdown(compose->exteditor_ch,
6118 g_io_channel_unref(compose->exteditor_ch);
6120 if (kill(pgid, SIGTERM) < 0) perror("kill");
6121 waitpid(compose->exteditor_pid, NULL, 0);
6123 g_warning("Terminated process group id: %d", -pgid);
6124 g_warning("Temporary file: %s",
6125 compose->exteditor_file);
6127 compose_set_ext_editor_sensitive(compose, TRUE);
6129 g_free(compose->exteditor_file);
6130 compose->exteditor_file = NULL;
6131 compose->exteditor_pid = -1;
6132 compose->exteditor_ch = NULL;
6133 compose->exteditor_tag = -1;
6141 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6145 Compose *compose = (Compose *)data;
6148 debug_print(_("Compose: input from monitoring process\n"));
6150 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6152 g_io_channel_shutdown(source, FALSE, NULL);
6153 g_io_channel_unref(source);
6155 waitpid(compose->exteditor_pid, NULL, 0);
6157 if (buf[0] == '0') { /* success */
6158 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6159 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6161 gtk_text_buffer_set_text(buffer, "", -1);
6162 compose_insert_file(compose, compose->exteditor_file);
6163 compose_changed_cb(NULL, compose);
6165 if (g_unlink(compose->exteditor_file) < 0)
6166 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6167 } else if (buf[0] == '1') { /* failed */
6168 g_warning("Couldn't exec external editor\n");
6169 if (g_unlink(compose->exteditor_file) < 0)
6170 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6171 } else if (buf[0] == '2') {
6172 g_warning("Couldn't write to file\n");
6173 } else if (buf[0] == '3') {
6174 g_warning("Pipe read failed\n");
6177 compose_set_ext_editor_sensitive(compose, TRUE);
6179 g_free(compose->exteditor_file);
6180 compose->exteditor_file = NULL;
6181 compose->exteditor_pid = -1;
6182 compose->exteditor_ch = NULL;
6183 compose->exteditor_tag = -1;
6188 static void compose_set_ext_editor_sensitive(Compose *compose,
6191 GtkItemFactory *ifactory;
6193 ifactory = gtk_item_factory_from_widget(compose->menubar);
6195 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6196 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6197 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6198 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6199 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6200 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6201 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6204 gtk_widget_set_sensitive(compose->text, sensitive);
6205 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6206 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6207 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6208 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6209 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6210 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6211 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
6212 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
6214 #endif /* G_OS_UNIX */
6217 * compose_undo_state_changed:
6219 * Change the sensivity of the menuentries undo and redo
6221 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6222 gint redo_state, gpointer data)
6224 GtkWidget *widget = GTK_WIDGET(data);
6225 GtkItemFactory *ifactory;
6227 g_return_if_fail(widget != NULL);
6229 ifactory = gtk_item_factory_from_widget(widget);
6231 switch (undo_state) {
6232 case UNDO_STATE_TRUE:
6233 if (!undostruct->undo_state) {
6234 undostruct->undo_state = TRUE;
6235 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6238 case UNDO_STATE_FALSE:
6239 if (undostruct->undo_state) {
6240 undostruct->undo_state = FALSE;
6241 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6244 case UNDO_STATE_UNCHANGED:
6246 case UNDO_STATE_REFRESH:
6247 menu_set_sensitive(ifactory, "/Edit/Undo",
6248 undostruct->undo_state);
6251 g_warning("Undo state not recognized");
6255 switch (redo_state) {
6256 case UNDO_STATE_TRUE:
6257 if (!undostruct->redo_state) {
6258 undostruct->redo_state = TRUE;
6259 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6262 case UNDO_STATE_FALSE:
6263 if (undostruct->redo_state) {
6264 undostruct->redo_state = FALSE;
6265 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6268 case UNDO_STATE_UNCHANGED:
6270 case UNDO_STATE_REFRESH:
6271 menu_set_sensitive(ifactory, "/Edit/Redo",
6272 undostruct->redo_state);
6275 g_warning("Redo state not recognized");
6280 /* callback functions */
6282 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6283 * includes "non-client" (windows-izm) in calculation, so this calculation
6284 * may not be accurate.
6286 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6287 GtkAllocation *allocation,
6288 GtkSHRuler *shruler)
6290 if (prefs_common.show_ruler) {
6291 gint char_width = 0, char_height = 0;
6292 gint line_width_in_chars;
6294 gtkut_get_font_size(GTK_WIDGET(widget),
6295 &char_width, &char_height);
6296 line_width_in_chars =
6297 (allocation->width - allocation->x) / char_width;
6299 /* got the maximum */
6300 gtk_ruler_set_range(GTK_RULER(shruler),
6301 0.0, line_width_in_chars, 0,
6302 /*line_width_in_chars*/ char_width);
6308 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6310 Compose *compose = (Compose *)data;
6313 gchar *folderidentifier;
6315 ac = account_find_from_id(
6316 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
6317 g_return_if_fail(ac != NULL);
6319 if (ac != compose->account)
6320 compose_select_account(compose, ac, FALSE);
6322 /* Set message save folder */
6323 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6324 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
6326 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
6327 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
6329 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6330 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6331 folderidentifier = folder_item_get_identifier(account_get_special_folder
6332 (compose->account, F_OUTBOX));
6333 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
6334 g_free(folderidentifier);
6338 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
6339 GtkTreeViewColumn *column, Compose *compose)
6341 compose_attach_property(compose);
6344 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6347 Compose *compose = (Compose *)data;
6349 if (!event) return FALSE;
6351 if (event->button == 3) {
6352 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6353 NULL, NULL, event->button, event->time);
6360 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6363 Compose *compose = (Compose *)data;
6365 if (!event) return FALSE;
6367 switch (event->keyval) {
6369 compose_attach_remove_selected(compose);
6375 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6377 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6378 toolbar_comp_set_sensitive(compose, allow);
6379 menu_set_sensitive(ifactory, "/Message", allow);
6380 menu_set_sensitive(ifactory, "/Edit", allow);
6382 menu_set_sensitive(ifactory, "/Spelling", allow);
6384 menu_set_sensitive(ifactory, "/Options", allow);
6385 menu_set_sensitive(ifactory, "/Tools", allow);
6386 menu_set_sensitive(ifactory, "/Help", allow);
6388 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
6392 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6394 Compose *compose = (Compose *)data;
6396 if (prefs_common.work_offline)
6397 if (alertpanel(_("Offline warning"),
6398 _("You're working offline. Override?"),
6399 GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT)
6402 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
6403 gtk_timeout_remove(compose->draft_timeout_tag);
6404 compose->draft_timeout_tag = -1;
6407 compose_send(compose);
6410 static void compose_send_later_cb(gpointer data, guint action,
6413 Compose *compose = (Compose *)data;
6416 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6418 compose_close(compose);
6419 else if (val == -2) {
6420 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
6424 void compose_draft (gpointer data)
6426 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6429 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6431 Compose *compose = (Compose *)data;
6435 MsgFlags flag = {0, 0};
6436 static gboolean lock = FALSE;
6437 MsgInfo *newmsginfo;
6442 draft = account_get_special_folder(compose->account, F_DRAFT);
6443 g_return_if_fail(draft != NULL);
6447 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
6448 G_DIR_SEPARATOR, compose);
6449 if ((fp = g_fopen(tmp, "wb")) == NULL) {
6450 FILE_OP_ERROR(tmp, "fopen");
6454 /* chmod for security */
6455 if (change_file_mode_rw(fp, tmp) < 0) {
6456 FILE_OP_ERROR(tmp, "chmod");
6457 g_warning("can't change file mode\n");
6460 /* Save draft infos */
6461 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
6462 fprintf(fp, "S:%s\n", compose->account->address);
6463 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
6464 gchar *savefolderid;
6466 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6467 fprintf(fp, "SCF:%s\n", savefolderid);
6468 g_free(savefolderid);
6470 if (compose->privacy_system) {
6471 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
6472 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
6473 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
6477 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
6486 folder_item_scan(draft);
6487 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
6494 draft->mtime = 0; /* force updating */
6496 if (compose->mode == COMPOSE_REEDIT) {
6497 compose_remove_reedit_target(compose);
6500 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6502 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6503 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
6504 if (compose_use_attach(compose))
6505 procmsg_msginfo_set_flags(newmsginfo, 0,
6506 MSG_HAS_ATTACHMENT);
6508 procmsg_msginfo_free(newmsginfo);
6511 folder_item_scan(draft);
6515 if (action == COMPOSE_QUIT_EDITING)
6516 compose_close(compose);
6521 path = folder_item_fetch_msg(draft, msgnum);
6522 g_return_if_fail(path != NULL);
6523 if (g_stat(path, &s) < 0) {
6524 FILE_OP_ERROR(path, "stat");
6531 procmsg_msginfo_free(compose->targetinfo);
6532 compose->targetinfo = procmsg_msginfo_new();
6533 compose->targetinfo->msgnum = msgnum;
6534 compose->targetinfo->size = s.st_size;
6535 compose->targetinfo->mtime = s.st_mtime;
6536 compose->targetinfo->folder = draft;
6537 compose->mode = COMPOSE_REEDIT;
6539 if (action == COMPOSE_AUTO_SAVE) {
6540 compose->autosaved_draft = compose->targetinfo;
6545 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6547 Compose *compose = (Compose *)data;
6550 if (compose->redirect_filename != NULL)
6553 file_list = filesel_select_multiple_files_open(_("Select file"));
6558 for ( tmp = file_list; tmp; tmp = tmp->next) {
6559 gchar *file = (gchar *) tmp->data;
6560 gchar *utf8_filename = conv_filename_to_utf8(file);
6561 compose_attach_append(compose, file, utf8_filename, NULL);
6562 compose_changed_cb(NULL, compose);
6564 g_free(utf8_filename);
6566 g_list_free(file_list);
6570 static void compose_insert_file_cb(gpointer data, guint action,
6573 Compose *compose = (Compose *)data;
6576 file_list = filesel_select_multiple_files_open(_("Select file"));
6581 for ( tmp = file_list; tmp; tmp = tmp->next) {
6582 gchar *file = (gchar *) tmp->data;
6583 gchar *filedup = g_strdup(file);
6584 gchar *shortfile = g_path_get_basename(filedup);
6585 ComposeInsertResult res;
6587 res = compose_insert_file(compose, file);
6588 if (res == COMPOSE_INSERT_READ_ERROR) {
6589 alertpanel_error(_("File '%s' could not be read."), shortfile);
6590 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
6591 alertpanel_error(_("File '%s' contained invalid characters\n"
6592 "for the current encoding, insertion may be incorrect."), shortfile);
6598 g_list_free(file_list);
6602 static void compose_insert_sig_cb(gpointer data, guint action,
6605 Compose *compose = (Compose *)data;
6607 compose_insert_sig(compose, FALSE);
6610 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6614 Compose *compose = (Compose *)data;
6616 gtkut_widget_get_uposition(widget, &x, &y);
6617 prefs_common.compose_x = x;
6618 prefs_common.compose_y = y;
6620 if (compose->sending)
6622 compose_close_cb(compose, 0, NULL);
6626 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6628 Compose *compose = (Compose *)data;
6632 if (compose->exteditor_tag != -1) {
6633 if (!compose_ext_editor_kill(compose))
6638 if (compose->modified) {
6639 val = alertpanel(_("Discard message"),
6640 _("This message has been modified. discard it?"),
6641 _("Discard"), _("to Draft"), GTK_STOCK_CANCEL);
6644 case G_ALERTDEFAULT:
6645 if (prefs_common.autosave)
6646 compose_remove_draft(compose);
6648 case G_ALERTALTERNATE:
6649 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6656 compose_close(compose);
6659 static void compose_set_encoding_cb(gpointer data, guint action,
6662 Compose *compose = (Compose *)data;
6664 if (GTK_CHECK_MENU_ITEM(widget)->active)
6665 compose->out_encoding = (CharSet)action;
6668 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6670 Compose *compose = (Compose *)data;
6672 addressbook_open(compose);
6675 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6677 Compose *compose = (Compose *)data;
6682 tmpl = g_object_get_data(G_OBJECT(widget), "template");
6683 g_return_if_fail(tmpl != NULL);
6685 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
6687 val = alertpanel(_("Apply template"), msg,
6688 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
6691 if (val == G_ALERTDEFAULT)
6692 compose_template_apply(compose, tmpl, TRUE);
6693 else if (val == G_ALERTALTERNATE)
6694 compose_template_apply(compose, tmpl, FALSE);
6697 static void compose_ext_editor_cb(gpointer data, guint action,
6700 Compose *compose = (Compose *)data;
6702 compose_exec_ext_editor(compose);
6705 static void compose_undo_cb(Compose *compose)
6707 gboolean prev_autowrap = compose->autowrap;
6709 compose->autowrap = FALSE;
6710 undo_undo(compose->undostruct);
6711 compose->autowrap = prev_autowrap;
6714 static void compose_redo_cb(Compose *compose)
6716 gboolean prev_autowrap = compose->autowrap;
6718 compose->autowrap = FALSE;
6719 undo_redo(compose->undostruct);
6720 compose->autowrap = prev_autowrap;
6723 static void entry_cut_clipboard(GtkWidget *entry)
6725 if (GTK_IS_EDITABLE(entry))
6726 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
6727 else if (GTK_IS_TEXT_VIEW(entry))
6728 gtk_text_buffer_cut_clipboard(
6729 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
6730 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
6734 static void entry_copy_clipboard(GtkWidget *entry)
6736 if (GTK_IS_EDITABLE(entry))
6737 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
6738 else if (GTK_IS_TEXT_VIEW(entry))
6739 gtk_text_buffer_copy_clipboard(
6740 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
6741 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
6744 static void entry_paste_clipboard(GtkWidget *entry, gboolean wrap)
6746 if (GTK_IS_EDITABLE(entry))
6747 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
6748 else if (GTK_IS_TEXT_VIEW(entry)) {
6749 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
6750 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
6751 GtkTextIter start_iter, end_iter;
6754 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
6756 if (contents == NULL)
6759 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
6760 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
6762 start = gtk_text_iter_get_offset(&start_iter);
6764 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
6767 end = start + strlen(contents);
6768 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
6769 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
6770 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
6776 static void entry_allsel(GtkWidget *entry)
6778 if (GTK_IS_EDITABLE(entry))
6779 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
6780 else if (GTK_IS_TEXT_VIEW(entry)) {
6781 GtkTextIter startiter, enditer;
6782 GtkTextBuffer *textbuf;
6784 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
6785 gtk_text_buffer_get_start_iter(textbuf, &startiter);
6786 gtk_text_buffer_get_end_iter(textbuf, &enditer);
6788 gtk_text_buffer_move_mark_by_name(textbuf,
6789 "selection_bound", &startiter);
6790 gtk_text_buffer_move_mark_by_name(textbuf,
6791 "insert", &enditer);
6795 static void compose_cut_cb(Compose *compose)
6797 if (compose->focused_editable &&
6798 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6799 entry_cut_clipboard(compose->focused_editable);
6802 static void compose_copy_cb(Compose *compose)
6804 if (compose->focused_editable &&
6805 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6806 entry_copy_clipboard(compose->focused_editable);
6809 #define BLOCK_WRAP() { \
6810 prev_autowrap = compose->autowrap; \
6811 buffer = gtk_text_view_get_buffer( \
6812 GTK_TEXT_VIEW(compose->text)); \
6813 compose->autowrap = FALSE; \
6815 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
6816 G_CALLBACK(compose_changed_cb), \
6818 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
6819 G_CALLBACK(text_inserted), \
6822 #define UNBLOCK_WRAP() { \
6823 compose->autowrap = prev_autowrap; \
6824 if (compose->autowrap) \
6825 compose_wrap_all(compose); \
6827 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
6828 G_CALLBACK(compose_changed_cb), \
6830 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
6831 G_CALLBACK(text_inserted), \
6835 static void compose_paste_cb(Compose *compose)
6838 GtkTextBuffer *buffer;
6840 if (compose->focused_editable &&
6841 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6842 entry_paste_clipboard(compose->focused_editable, prefs_common.linewrap_pastes);
6846 static void compose_paste_as_quote_cb(Compose *compose)
6848 gint wrap_quote = prefs_common.linewrap_quote;
6849 if (compose->focused_editable &&
6850 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6851 /* let text_insert() (called directly or at a later time
6852 * after the gtk_editable_paste_clipboard) know that
6853 * text is to be inserted as a quotation. implemented
6854 * by using a simple refcount... */
6855 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
6856 G_OBJECT(compose->focused_editable),
6857 "paste_as_quotation"));
6858 g_object_set_data(G_OBJECT(compose->focused_editable),
6859 "paste_as_quotation",
6860 GINT_TO_POINTER(paste_as_quotation + 1));
6861 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
6862 entry_paste_clipboard(compose->focused_editable, prefs_common.linewrap_pastes);
6863 prefs_common.linewrap_quote = wrap_quote;
6867 static void compose_paste_no_wrap_cb(Compose *compose)
6870 GtkTextBuffer *buffer;
6872 if (compose->focused_editable &&
6873 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6874 entry_paste_clipboard(compose->focused_editable, FALSE);
6878 static void compose_paste_wrap_cb(Compose *compose)
6881 GtkTextBuffer *buffer;
6883 if (compose->focused_editable &&
6884 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6885 entry_paste_clipboard(compose->focused_editable, TRUE);
6889 static void compose_allsel_cb(Compose *compose)
6891 if (compose->focused_editable &&
6892 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6893 entry_allsel(compose->focused_editable);
6896 static void textview_move_beginning_of_line (GtkTextView *text)
6898 GtkTextBuffer *buffer;
6902 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
6904 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6905 mark = gtk_text_buffer_get_insert(buffer);
6906 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
6907 gtk_text_iter_set_line_offset(&ins, 0);
6908 gtk_text_buffer_place_cursor(buffer, &ins);
6911 static void textview_move_forward_character (GtkTextView *text)
6913 GtkTextBuffer *buffer;
6917 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
6919 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6920 mark = gtk_text_buffer_get_insert(buffer);
6921 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
6922 if (gtk_text_iter_forward_cursor_position(&ins))
6923 gtk_text_buffer_place_cursor(buffer, &ins);
6926 static void textview_move_backward_character (GtkTextView *text)
6928 GtkTextBuffer *buffer;
6932 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
6934 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6935 mark = gtk_text_buffer_get_insert(buffer);
6936 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
6937 if (gtk_text_iter_backward_cursor_position(&ins))
6938 gtk_text_buffer_place_cursor(buffer, &ins);
6941 static void textview_move_forward_word (GtkTextView *text)
6943 GtkTextBuffer *buffer;
6948 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
6950 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6951 mark = gtk_text_buffer_get_insert(buffer);
6952 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
6953 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
6954 if (gtk_text_iter_forward_word_ends(&ins, count)) {
6955 gtk_text_iter_backward_word_start(&ins);
6956 gtk_text_buffer_place_cursor(buffer, &ins);
6960 static void textview_move_backward_word (GtkTextView *text)
6962 GtkTextBuffer *buffer;
6967 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
6969 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6970 mark = gtk_text_buffer_get_insert(buffer);
6971 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
6972 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
6973 if (gtk_text_iter_backward_word_starts(&ins, 1))
6974 gtk_text_buffer_place_cursor(buffer, &ins);
6977 static void textview_move_end_of_line (GtkTextView *text)
6979 GtkTextBuffer *buffer;
6983 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
6985 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
6986 mark = gtk_text_buffer_get_insert(buffer);
6987 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
6988 if (gtk_text_iter_forward_to_line_end(&ins))
6989 gtk_text_buffer_place_cursor(buffer, &ins);
6992 static void textview_move_next_line (GtkTextView *text)
6994 GtkTextBuffer *buffer;
6999 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7001 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7002 mark = gtk_text_buffer_get_insert(buffer);
7003 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7004 offset = gtk_text_iter_get_line_offset(&ins);
7005 if (gtk_text_iter_forward_line(&ins)) {
7006 gtk_text_iter_set_line_offset(&ins, offset);
7007 gtk_text_buffer_place_cursor(buffer, &ins);
7011 static void textview_move_previous_line (GtkTextView *text)
7013 GtkTextBuffer *buffer;
7018 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7020 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7021 mark = gtk_text_buffer_get_insert(buffer);
7022 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7023 offset = gtk_text_iter_get_line_offset(&ins);
7024 if (gtk_text_iter_backward_line(&ins)) {
7025 gtk_text_iter_set_line_offset(&ins, offset);
7026 gtk_text_buffer_place_cursor(buffer, &ins);
7030 static void textview_delete_forward_character (GtkTextView *text)
7032 GtkTextBuffer *buffer;
7034 GtkTextIter ins, end_iter;
7036 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7038 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7039 mark = gtk_text_buffer_get_insert(buffer);
7040 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7042 if (gtk_text_iter_forward_char(&end_iter)) {
7043 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7047 static void textview_delete_backward_character (GtkTextView *text)
7049 GtkTextBuffer *buffer;
7051 GtkTextIter ins, end_iter;
7053 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7055 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7056 mark = gtk_text_buffer_get_insert(buffer);
7057 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7059 if (gtk_text_iter_backward_char(&end_iter)) {
7060 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7064 static void textview_delete_forward_word (GtkTextView *text)
7066 GtkTextBuffer *buffer;
7068 GtkTextIter ins, end_iter;
7070 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7072 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7073 mark = gtk_text_buffer_get_insert(buffer);
7074 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7076 if (gtk_text_iter_forward_word_end(&end_iter)) {
7077 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7081 static void textview_delete_backward_word (GtkTextView *text)
7083 GtkTextBuffer *buffer;
7085 GtkTextIter ins, end_iter;
7087 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7089 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7090 mark = gtk_text_buffer_get_insert(buffer);
7091 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7093 if (gtk_text_iter_backward_word_start(&end_iter)) {
7094 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7098 static void textview_delete_line (GtkTextView *text)
7100 GtkTextBuffer *buffer;
7102 GtkTextIter ins, start_iter, end_iter;
7105 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7107 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7108 mark = gtk_text_buffer_get_insert(buffer);
7109 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7112 gtk_text_iter_set_line_offset(&start_iter, 0);
7115 if (gtk_text_iter_ends_line(&end_iter))
7116 found = gtk_text_iter_forward_char(&end_iter);
7118 found = gtk_text_iter_forward_to_line_end(&end_iter);
7121 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7124 static void textview_delete_to_line_end (GtkTextView *text)
7126 GtkTextBuffer *buffer;
7128 GtkTextIter ins, end_iter;
7131 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7133 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7134 mark = gtk_text_buffer_get_insert(buffer);
7135 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7137 if (gtk_text_iter_ends_line(&end_iter))
7138 found = gtk_text_iter_forward_char(&end_iter);
7140 found = gtk_text_iter_forward_to_line_end(&end_iter);
7142 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7145 static void compose_advanced_action_cb(Compose *compose,
7146 ComposeCallAdvancedAction action)
7148 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7150 void (*do_action) (GtkTextView *text);
7151 } action_table[] = {
7152 {textview_move_beginning_of_line},
7153 {textview_move_forward_character},
7154 {textview_move_backward_character},
7155 {textview_move_forward_word},
7156 {textview_move_backward_word},
7157 {textview_move_end_of_line},
7158 {textview_move_next_line},
7159 {textview_move_previous_line},
7160 {textview_delete_forward_character},
7161 {textview_delete_backward_character},
7162 {textview_delete_forward_word},
7163 {textview_delete_backward_word},
7164 {textview_delete_line},
7165 {NULL}, /* gtk_stext_delete_line_n */
7166 {textview_delete_to_line_end}
7169 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
7171 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
7172 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
7173 if (action_table[action].do_action)
7174 action_table[action].do_action(text);
7176 g_warning("Not implemented yet.");
7180 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
7184 if (GTK_IS_EDITABLE(widget)) {
7185 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
7186 gtk_editable_set_position(GTK_EDITABLE(widget),
7191 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
7192 compose->focused_editable = widget;
7195 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
7197 if (compose->modified == FALSE) {
7198 compose->modified = TRUE;
7199 compose_set_title(compose);
7203 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
7205 Compose *compose = (Compose *)data;
7208 compose_wrap_all_full(compose, TRUE);
7210 compose_wrap_paragraph(compose, NULL, TRUE);
7213 static void compose_toggle_autowrap_cb(gpointer data, guint action,
7216 Compose *compose = (Compose *)data;
7217 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7218 if (compose->autowrap)
7219 compose_wrap_all_full(compose, TRUE);
7222 static void compose_toggle_sign_cb(gpointer data, guint action,
7225 Compose *compose = (Compose *)data;
7227 if (GTK_CHECK_MENU_ITEM(widget)->active)
7228 compose->use_signing = TRUE;
7230 compose->use_signing = FALSE;
7233 static void compose_toggle_encrypt_cb(gpointer data, guint action,
7236 Compose *compose = (Compose *)data;
7238 if (GTK_CHECK_MENU_ITEM(widget)->active)
7239 compose->use_encryption = TRUE;
7241 compose->use_encryption = FALSE;
7244 static void activate_privacy_system(Compose *compose, PrefsAccount *account)
7246 g_free(compose->privacy_system);
7247 compose->privacy_system = g_strdup(account->default_privacy_system);
7248 compose_update_privacy_system_menu_item(compose);
7251 static void compose_toggle_ruler_cb(gpointer data, guint action,
7254 Compose *compose = (Compose *)data;
7256 if (GTK_CHECK_MENU_ITEM(widget)->active) {
7257 gtk_widget_show(compose->ruler_hbox);
7258 prefs_common.show_ruler = TRUE;
7260 gtk_widget_hide(compose->ruler_hbox);
7261 gtk_widget_queue_resize(compose->edit_vbox);
7262 prefs_common.show_ruler = FALSE;
7266 static void compose_attach_drag_received_cb (GtkWidget *widget,
7267 GdkDragContext *drag_context,
7270 GtkSelectionData *data,
7275 Compose *compose = (Compose *)user_data;
7278 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7279 list = uri_list_extract_filenames((const gchar *)data->data);
7280 for (tmp = list; tmp != NULL; tmp = tmp->next)
7281 compose_attach_append
7282 (compose, (const gchar *)tmp->data,
7283 (const gchar *)tmp->data, NULL);
7284 if (list) compose_changed_cb(NULL, compose);
7285 list_free_strings(list);
7290 static gboolean compose_drag_drop(GtkWidget *widget,
7291 GdkDragContext *drag_context,
7293 guint time, gpointer user_data)
7295 /* not handling this signal makes compose_insert_drag_received_cb
7300 static void compose_insert_drag_received_cb (GtkWidget *widget,
7301 GdkDragContext *drag_context,
7304 GtkSelectionData *data,
7309 Compose *compose = (Compose *)user_data;
7312 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
7314 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7315 list = uri_list_extract_filenames((const gchar *)data->data);
7316 for (tmp = list; tmp != NULL; tmp = tmp->next) {
7317 compose_insert_file(compose, (const gchar *)tmp->data);
7319 list_free_strings(list);
7321 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7324 gchar *tmpfile = get_tmp_file();
7325 str_write_to_file((const gchar *)data->data, tmpfile);
7326 compose_insert_file(compose, tmpfile);
7329 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7332 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7335 static void compose_header_drag_received_cb (GtkWidget *widget,
7336 GdkDragContext *drag_context,
7339 GtkSelectionData *data,
7344 GtkEditable *entry = (GtkEditable *)user_data;
7345 gchar *email = (gchar *)data->data;
7347 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
7350 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
7351 gchar *decoded=g_new(gchar, strlen(email));
7354 email += strlen("mailto:");
7355 decode_uri(decoded, email); /* will fit */
7356 gtk_editable_delete_text(entry, 0, -1);
7357 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
7358 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7362 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7365 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
7368 Compose *compose = (Compose *)data;
7370 if (GTK_CHECK_MENU_ITEM(widget)->active)
7371 compose->return_receipt = TRUE;
7373 compose->return_receipt = FALSE;
7376 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
7379 Compose *compose = (Compose *)data;
7381 if (GTK_CHECK_MENU_ITEM(widget)->active)
7382 compose->remove_references = TRUE;
7384 compose->remove_references = FALSE;
7387 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
7389 ComposeHeaderEntry *headerentry)
7391 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
7392 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
7393 !(event->state & GDK_MODIFIER_MASK) &&
7394 (event->keyval == GDK_BackSpace) &&
7395 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
7396 gtk_container_remove
7397 (GTK_CONTAINER(headerentry->compose->header_table),
7398 headerentry->combo);
7399 gtk_container_remove
7400 (GTK_CONTAINER(headerentry->compose->header_table),
7401 headerentry->entry);
7402 headerentry->compose->header_list =
7403 g_slist_remove(headerentry->compose->header_list,
7405 g_free(headerentry);
7406 } else if (event->keyval == GDK_Tab) {
7407 if (headerentry->compose->header_last == headerentry) {
7408 /* Override default next focus, and give it to subject_entry
7409 * instead of notebook tabs
7411 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
7412 gtk_widget_grab_focus(headerentry->compose->subject_entry);
7419 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
7420 ComposeHeaderEntry *headerentry)
7422 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
7423 headerentry->compose->header_list =
7424 g_slist_append(headerentry->compose->header_list,
7427 compose_create_header_entry(headerentry->compose);
7428 g_signal_handlers_disconnect_matched
7429 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
7430 0, 0, NULL, NULL, headerentry);
7432 /* Automatically scroll down */
7433 compose_show_first_last_header(headerentry->compose, FALSE);
7439 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
7441 GtkAdjustment *vadj;
7443 g_return_if_fail(compose);
7444 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
7445 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
7447 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
7448 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
7451 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
7452 const gchar *text, gint len, Compose *compose)
7454 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
7455 (G_OBJECT(compose->text), "paste_as_quotation"));
7458 g_return_if_fail(text != NULL);
7460 g_signal_handlers_block_by_func(G_OBJECT(buffer),
7461 G_CALLBACK(text_inserted),
7463 if (paste_as_quotation) {
7470 new_text = g_strndup(text, len);
7471 if (prefs_common.quotemark && *prefs_common.quotemark)
7472 qmark = prefs_common.quotemark;
7476 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
7477 gtk_text_buffer_place_cursor(buffer, iter);
7479 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
7481 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
7482 GINT_TO_POINTER(paste_as_quotation - 1));
7484 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
7486 gtk_text_buffer_insert(buffer, iter, text, len);
7488 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
7489 compose_wrap_all_full(compose, FALSE);
7490 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
7491 gtk_text_buffer_delete_mark(buffer, mark);
7493 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
7494 G_CALLBACK(text_inserted),
7496 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
7498 if (prefs_common.autosave &&
7499 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
7500 compose->draft_timeout_tag = gtk_timeout_add
7501 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
7503 static gint compose_defer_auto_save_draft(Compose *compose)
7505 compose->draft_timeout_tag = -1;
7506 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
7511 static void compose_check_all(Compose *compose)
7513 if (compose->gtkaspell)
7514 gtkaspell_check_all(compose->gtkaspell);
7517 static void compose_highlight_all(Compose *compose)
7519 if (compose->gtkaspell)
7520 gtkaspell_highlight_all(compose->gtkaspell);
7523 static void compose_check_backwards(Compose *compose)
7525 if (compose->gtkaspell)
7526 gtkaspell_check_backwards(compose->gtkaspell);
7528 GtkItemFactory *ifactory;
7529 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7530 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7531 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
7535 static void compose_check_forwards_go(Compose *compose)
7537 if (compose->gtkaspell)
7538 gtkaspell_check_forwards_go(compose->gtkaspell);
7540 GtkItemFactory *ifactory;
7541 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7542 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7543 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
7549 *\brief Guess originating forward account from MsgInfo and several
7550 * "common preference" settings. Return NULL if no guess.
7552 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
7554 PrefsAccount *account = NULL;
7556 g_return_val_if_fail(msginfo, NULL);
7557 g_return_val_if_fail(msginfo->folder, NULL);
7558 g_return_val_if_fail(msginfo->folder->prefs, NULL);
7560 if (msginfo->folder->prefs->enable_default_account)
7561 account = account_find_from_id(msginfo->folder->prefs->default_account);
7564 account = msginfo->folder->folder->account;
7566 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
7568 Xstrdup_a(to, msginfo->to, return NULL);
7569 extract_address(to);
7570 account = account_find_from_address(to);
7573 if (!account && prefs_common.forward_account_autosel) {
7575 if (!procheader_get_header_from_msginfo
7576 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
7577 extract_address(cc);
7578 account = account_find_from_address(cc);
7585 static void compose_close(Compose *compose)
7589 g_return_if_fail(compose);
7590 gtkut_widget_get_uposition(compose->window, &x, &y);
7591 prefs_common.compose_x = x;
7592 prefs_common.compose_y = y;
7593 compose_destroy(compose);
7597 * Add entry field for each address in list.
7598 * \param compose E-Mail composition object.
7599 * \param listAddress List of (formatted) E-Mail addresses.
7601 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
7606 addr = ( gchar * ) node->data;
7607 compose_entry_append( compose, addr, COMPOSE_TO );
7608 node = g_list_next( node );
7612 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
7616 GSList *new_msglist = NULL;
7617 MsgInfo *tmp_msginfo = NULL;
7619 g_return_if_fail(msgview != NULL);
7621 g_return_if_fail(msginfo_list != NULL);
7623 if (g_slist_length(msginfo_list) == 1) {
7624 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
7625 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
7627 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
7628 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
7630 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
7631 orig_msginfo, mimeinfo);
7632 if (tmp_msginfo != NULL) {
7633 new_msglist = g_slist_append(NULL, tmp_msginfo);
7638 body = messageview_get_selection(msgview);
7641 compose_reply_mode((ComposeMode)action, new_msglist, body);
7642 procmsg_msginfo_free(tmp_msginfo);
7643 g_slist_free(new_msglist);
7645 compose_reply_mode((ComposeMode)action, msginfo_list, body);