2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #ifndef PANGO_ENABLE_ENGINE
27 # define PANGO_ENABLE_ENGINE
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtkmain.h>
34 #include <gtk/gtkmenu.h>
35 #include <gtk/gtkmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkcheckmenuitem.h>
38 #include <gtk/gtkoptionmenu.h>
39 #include <gtk/gtkwidget.h>
40 #include <gtk/gtkvpaned.h>
41 #include <gtk/gtkentry.h>
42 #include <gtk/gtkeditable.h>
43 #include <gtk/gtkwindow.h>
44 #include <gtk/gtksignal.h>
45 #include <gtk/gtkvbox.h>
46 #include <gtk/gtkcontainer.h>
47 #include <gtk/gtkhandlebox.h>
48 #include <gtk/gtktoolbar.h>
49 #include <gtk/gtktable.h>
50 #include <gtk/gtkhbox.h>
51 #include <gtk/gtklabel.h>
52 #include <gtk/gtkscrolledwindow.h>
53 #include <gtk/gtktreeview.h>
54 #include <gtk/gtkliststore.h>
55 #include <gtk/gtktreeselection.h>
56 #include <gtk/gtktreemodel.h>
58 #include <gtk/gtkdnd.h>
59 #include <gtk/gtkclipboard.h>
60 #include <pango/pango-break.h>
65 #include <sys/types.h>
71 # include <sys/wait.h>
75 #ifndef G_OS_WIN32 /* fixme we should have a configure test. */
79 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
86 #include "mainwindow.h"
88 #include "addressbook.h"
89 #include "folderview.h"
92 #include "stock_pixmap.h"
93 #include "send_message.h"
96 #include "customheader.h"
97 #include "prefs_common.h"
98 #include "prefs_account.h"
102 #include "procheader.h"
103 #include "procmime.h"
104 #include "statusbar.h"
107 #include "quoted-printable.h"
108 #include "codeconv.h"
110 #include "gtkutils.h"
112 #include "alertpanel.h"
113 #include "manage_window.h"
114 #include "gtkshruler.h"
116 #include "addr_compl.h"
117 #include "quote_fmt.h"
119 #include "foldersel.h"
122 #include "message_search.h"
134 #define N_ATTACH_COLS (N_COL_COLUMNS)
138 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
143 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
144 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
145 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
146 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
150 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
151 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
152 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
153 } ComposeCallAdvancedAction;
157 PRIORITY_HIGHEST = 1,
166 COMPOSE_INSERT_SUCCESS,
167 COMPOSE_INSERT_READ_ERROR,
168 COMPOSE_INSERT_INVALID_CHARACTER,
169 COMPOSE_INSERT_NO_FILE
170 } ComposeInsertResult;
174 COMPOSE_QUIT_EDITING,
175 COMPOSE_KEEP_EDITING,
177 } ComposeDraftAction;
181 COMPOSE_WRITE_FOR_SEND,
182 COMPOSE_WRITE_FOR_STORE
185 #define B64_LINE_SIZE 57
186 #define B64_BUFFSIZE 77
188 #define MAX_REFERENCES_LEN 999
190 static GList *compose_list = NULL;
192 Compose *compose_generic_new (PrefsAccount *account,
195 GPtrArray *attach_files,
196 GList *listAddress );
198 static Compose *compose_create (PrefsAccount *account,
202 static GtkWidget *compose_account_option_menu_create
204 static void compose_set_out_encoding (Compose *compose);
205 static void compose_set_template_menu (Compose *compose);
206 static void compose_template_apply (Compose *compose,
209 static void compose_destroy (Compose *compose);
211 static void compose_entries_set (Compose *compose,
212 const gchar *mailto);
213 static gint compose_parse_header (Compose *compose,
215 static gchar *compose_parse_references (const gchar *ref,
218 static gchar *compose_quote_fmt (Compose *compose,
225 static void compose_reply_set_entry (Compose *compose,
231 followup_and_reply_to);
232 static void compose_reedit_set_entry (Compose *compose,
235 static void compose_insert_sig (Compose *compose,
237 static gchar *compose_get_signature_str (Compose *compose);
238 static ComposeInsertResult compose_insert_file (Compose *compose,
241 static void compose_attach_append (Compose *compose,
244 const gchar *content_type);
245 static void compose_attach_parts (Compose *compose,
248 static void compose_beautify_paragraph (Compose *compose,
249 GtkTextIter *par_iter,
251 static void compose_wrap_all (Compose *compose);
252 static void compose_wrap_all_full (Compose *compose,
255 static void compose_set_title (Compose *compose);
256 static void compose_select_account (Compose *compose,
257 PrefsAccount *account,
260 static PrefsAccount *compose_current_mail_account(void);
261 /* static gint compose_send (Compose *compose); */
262 static gboolean compose_check_for_valid_recipient
264 static gboolean compose_check_entries (Compose *compose,
265 gboolean check_subject);
266 static gint compose_write_to_file (Compose *compose,
269 static gint compose_write_body_to_file (Compose *compose,
271 static gint compose_remove_reedit_target (Compose *compose,
273 void compose_remove_draft (Compose *compose);
274 static gint compose_queue (Compose *compose,
278 static gint compose_queue_sub (Compose *compose,
282 gboolean check_subject);
283 static void compose_add_attachments (Compose *compose,
285 static gchar *compose_get_header (Compose *compose);
287 static void compose_convert_header (Compose *compose,
292 gboolean addr_field);
294 static void compose_attach_info_free (AttachInfo *ainfo);
295 static void compose_attach_remove_selected (Compose *compose);
297 static void compose_attach_property (Compose *compose);
298 static void compose_attach_property_create (gboolean *cancelled);
299 static void attach_property_ok (GtkWidget *widget,
300 gboolean *cancelled);
301 static void attach_property_cancel (GtkWidget *widget,
302 gboolean *cancelled);
303 static gint attach_property_delete_event (GtkWidget *widget,
305 gboolean *cancelled);
306 static gboolean attach_property_key_pressed (GtkWidget *widget,
308 gboolean *cancelled);
310 static void compose_exec_ext_editor (Compose *compose);
312 static gint compose_exec_ext_editor_real (const gchar *file);
313 static gboolean compose_ext_editor_kill (Compose *compose);
314 static gboolean compose_input_cb (GIOChannel *source,
315 GIOCondition condition,
317 static void compose_set_ext_editor_sensitive (Compose *compose,
319 #endif /* G_OS_UNIX */
321 static void compose_undo_state_changed (UndoMain *undostruct,
326 static void compose_create_header_entry (Compose *compose);
327 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
328 static void compose_update_priority_menu_item(Compose * compose);
330 static void compose_add_field_list ( Compose *compose,
331 GList *listAddress );
333 /* callback functions */
335 static gboolean compose_edit_size_alloc (GtkEditable *widget,
336 GtkAllocation *allocation,
337 GtkSHRuler *shruler);
338 static void account_activated (GtkMenuItem *menuitem,
340 static void attach_selected (GtkTreeView *tree_view,
341 GtkTreePath *tree_path,
342 GtkTreeViewColumn *column,
344 static gboolean attach_button_pressed (GtkWidget *widget,
345 GdkEventButton *event,
347 static gboolean attach_key_pressed (GtkWidget *widget,
351 static void compose_send_cb (gpointer data,
354 static void compose_send_later_cb (gpointer data,
358 static void compose_draft_cb (gpointer data,
362 static void compose_attach_cb (gpointer data,
365 static void compose_insert_file_cb (gpointer data,
368 static void compose_insert_sig_cb (gpointer data,
372 static void compose_close_cb (gpointer data,
376 static void compose_set_encoding_cb (gpointer data,
380 static void compose_address_cb (gpointer data,
383 static void compose_template_activate_cb(GtkWidget *widget,
386 static void compose_ext_editor_cb (gpointer data,
390 static gint compose_delete_cb (GtkWidget *widget,
394 static void compose_undo_cb (Compose *compose);
395 static void compose_redo_cb (Compose *compose);
396 static void compose_cut_cb (Compose *compose);
397 static void compose_copy_cb (Compose *compose);
398 static void compose_paste_cb (Compose *compose);
399 static void compose_paste_as_quote_cb (Compose *compose);
400 static void compose_paste_no_wrap_cb (Compose *compose);
401 static void compose_paste_wrap_cb (Compose *compose);
402 static void compose_allsel_cb (Compose *compose);
404 static void compose_advanced_action_cb (Compose *compose,
405 ComposeCallAdvancedAction action);
407 static void compose_grab_focus_cb (GtkWidget *widget,
410 static void compose_changed_cb (GtkTextBuffer *textbuf,
413 static void compose_wrap_cb (gpointer data,
416 static void compose_find_cb (gpointer data,
419 static void compose_toggle_autowrap_cb (gpointer data,
423 static void compose_toggle_ruler_cb (gpointer data,
426 static void compose_toggle_sign_cb (gpointer data,
429 static void compose_toggle_encrypt_cb (gpointer data,
432 static void compose_set_privacy_system_cb(GtkWidget *widget,
434 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
435 static void activate_privacy_system (Compose *compose,
436 PrefsAccount *account,
438 static void compose_use_signing(Compose *compose, gboolean use_signing);
439 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
440 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
442 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
444 static void compose_set_priority_cb (gpointer data,
448 static void compose_attach_drag_received_cb (GtkWidget *widget,
449 GdkDragContext *drag_context,
452 GtkSelectionData *data,
456 static void compose_insert_drag_received_cb (GtkWidget *widget,
457 GdkDragContext *drag_context,
460 GtkSelectionData *data,
464 static void compose_header_drag_received_cb (GtkWidget *widget,
465 GdkDragContext *drag_context,
468 GtkSelectionData *data,
473 static gboolean compose_drag_drop (GtkWidget *widget,
474 GdkDragContext *drag_context,
476 guint time, gpointer user_data);
478 static void text_inserted (GtkTextBuffer *buffer,
483 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
484 gboolean to_all, gboolean to_ml,
486 gboolean followup_and_reply_to,
489 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
490 ComposeHeaderEntry *headerentry);
491 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
493 ComposeHeaderEntry *headerentry);
495 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
497 static void compose_allow_user_actions (Compose *compose, gboolean allow);
500 static void compose_check_all (Compose *compose);
501 static void compose_highlight_all (Compose *compose);
502 static void compose_check_backwards (Compose *compose);
503 static void compose_check_forwards_go (Compose *compose);
506 static gint compose_defer_auto_save_draft (Compose *compose);
507 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
509 static gboolean compose_close (Compose *compose);
511 static GtkItemFactoryEntry compose_popup_entries[] =
513 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
514 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
515 {N_("/---"), NULL, NULL, 0, "<Separator>"},
516 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
519 static GtkItemFactoryEntry compose_entries[] =
521 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
522 {N_("/_Message/_Send"), "<control>Return",
523 compose_send_cb, 0, NULL},
524 {N_("/_Message/Send _later"), "<shift><control>S",
525 compose_send_later_cb, 0, NULL},
526 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
527 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
528 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
529 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
530 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
531 {N_("/_Message/_Save"),
532 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
533 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
534 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
536 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
537 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
538 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
539 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
540 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
541 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
542 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
543 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
544 {N_("/_Edit/Special paste/as _quotation"),
545 NULL, compose_paste_as_quote_cb, 0, NULL},
546 {N_("/_Edit/Special paste/_wrapped"),
547 NULL, compose_paste_wrap_cb, 0, NULL},
548 {N_("/_Edit/Special paste/_unwrapped"),
549 NULL, compose_paste_no_wrap_cb, 0, NULL},
550 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
551 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
552 {N_("/_Edit/A_dvanced/Move a character backward"),
554 compose_advanced_action_cb,
555 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
557 {N_("/_Edit/A_dvanced/Move a character forward"),
559 compose_advanced_action_cb,
560 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
562 {N_("/_Edit/A_dvanced/Move a word backward"),
564 compose_advanced_action_cb,
565 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
567 {N_("/_Edit/A_dvanced/Move a word forward"),
569 compose_advanced_action_cb,
570 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
572 {N_("/_Edit/A_dvanced/Move to beginning of line"),
573 NULL, /* "<control>A" */
574 compose_advanced_action_cb,
575 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
577 {N_("/_Edit/A_dvanced/Move to end of line"),
579 compose_advanced_action_cb,
580 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
582 {N_("/_Edit/A_dvanced/Move to previous line"),
584 compose_advanced_action_cb,
585 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
587 {N_("/_Edit/A_dvanced/Move to next line"),
589 compose_advanced_action_cb,
590 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
592 {N_("/_Edit/A_dvanced/Delete a character backward"),
594 compose_advanced_action_cb,
595 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
597 {N_("/_Edit/A_dvanced/Delete a character forward"),
599 compose_advanced_action_cb,
600 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
602 {N_("/_Edit/A_dvanced/Delete a word backward"),
603 NULL, /* "<control>W" */
604 compose_advanced_action_cb,
605 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
607 {N_("/_Edit/A_dvanced/Delete a word forward"),
608 NULL, /* "<alt>D", */
609 compose_advanced_action_cb,
610 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
612 {N_("/_Edit/A_dvanced/Delete line"),
614 compose_advanced_action_cb,
615 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
617 {N_("/_Edit/A_dvanced/Delete entire line"),
619 compose_advanced_action_cb,
620 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
622 {N_("/_Edit/A_dvanced/Delete to end of line"),
624 compose_advanced_action_cb,
625 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
627 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
629 "<control>F", compose_find_cb, 0, NULL},
630 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
631 {N_("/_Edit/_Wrap current paragraph"),
632 "<control>L", compose_wrap_cb, 0, NULL},
633 {N_("/_Edit/Wrap all long _lines"),
634 "<control><alt>L", compose_wrap_cb, 1, NULL},
635 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
636 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
637 {N_("/_Edit/Edit with e_xternal editor"),
638 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
640 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
641 {N_("/_Spelling/_Check all or check selection"),
642 NULL, compose_check_all, 0, NULL},
643 {N_("/_Spelling/_Highlight all misspelled words"),
644 NULL, compose_highlight_all, 0, NULL},
645 {N_("/_Spelling/Check _backwards misspelled word"),
646 NULL, compose_check_backwards , 0, NULL},
647 {N_("/_Spelling/_Forward to next misspelled word"),
648 NULL, compose_check_forwards_go, 0, NULL},
649 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
650 {N_("/_Spelling/Options"),
651 NULL, NULL, 0, "<Branch>"},
653 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
654 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
655 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
656 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
657 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
658 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
659 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
660 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
661 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
662 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
663 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
664 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
665 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
666 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
667 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
668 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
669 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
671 #define ENC_ACTION(action) \
672 NULL, compose_set_encoding_cb, action, \
673 "/Options/Character encoding/Automatic"
675 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
676 {N_("/_Options/Character _encoding/_Automatic"),
677 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
678 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
680 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
681 ENC_ACTION(C_US_ASCII)},
682 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
683 ENC_ACTION(C_UTF_8)},
684 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
686 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
687 ENC_ACTION(C_ISO_8859_1)},
688 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
689 ENC_ACTION(C_ISO_8859_15)},
690 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
691 ENC_ACTION(C_WINDOWS_1252)},
692 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
694 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
695 ENC_ACTION(C_ISO_8859_2)},
696 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
698 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
699 ENC_ACTION(C_ISO_8859_13)},
700 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
701 ENC_ACTION(C_ISO_8859_4)},
702 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
704 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
705 ENC_ACTION(C_ISO_8859_7)},
706 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
708 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
709 ENC_ACTION(C_ISO_8859_8)},
710 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
711 ENC_ACTION(C_WINDOWS_1255)},
712 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
714 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
715 ENC_ACTION(C_ISO_8859_6)},
716 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
717 ENC_ACTION(C_CP1256)},
718 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
720 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
721 ENC_ACTION(C_ISO_8859_9)},
722 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
724 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
725 ENC_ACTION(C_ISO_8859_5)},
726 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
727 ENC_ACTION(C_KOI8_R)},
728 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
729 ENC_ACTION(C_KOI8_U)},
730 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
731 ENC_ACTION(C_WINDOWS_1251)},
732 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
734 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
735 ENC_ACTION(C_ISO_2022_JP)},
736 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
738 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
739 ENC_ACTION(C_GB2312)},
740 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
742 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
744 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
745 ENC_ACTION(C_EUC_TW)},
746 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
748 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
749 ENC_ACTION(C_EUC_KR)},
750 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
752 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
753 ENC_ACTION(C_TIS_620)},
754 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
755 ENC_ACTION(C_WINDOWS_874)},
757 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
758 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
759 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
760 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
761 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
762 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
763 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
766 static GtkTargetEntry compose_mime_types[] =
768 {"text/uri-list", 0, 0},
769 {"text/plain", 0, 0},
773 static gboolean compose_put_existing_to_front(MsgInfo *info)
775 GList *compose_list = compose_get_compose_list();
779 for (elem = compose_list; elem != NULL && elem->data != NULL;
781 Compose *c = (Compose*)elem->data;
783 if (!c->targetinfo || !c->targetinfo->msgid ||
787 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
788 gtkut_window_popup(c->window);
796 static GdkColor quote_color1 =
797 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
798 static GdkColor quote_color2 =
799 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
800 static GdkColor quote_color3 =
801 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
803 static GdkColor quote_bgcolor1 =
804 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
805 static GdkColor quote_bgcolor2 =
806 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
807 static GdkColor quote_bgcolor3 =
808 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
810 static GdkColor signature_color = {
817 static GdkColor uri_color = {
824 static void compose_create_tags(GtkTextView *text, Compose *compose)
826 GtkTextBuffer *buffer;
827 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
833 buffer = gtk_text_view_get_buffer(text);
835 if (prefs_common.enable_color) {
836 /* grab the quote colors, converting from an int to a GdkColor */
837 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
839 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
841 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
843 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
845 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
847 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
849 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
851 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
854 signature_color = quote_color1 = quote_color2 = quote_color3 =
855 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black;
858 if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
859 gtk_text_buffer_create_tag(buffer, "quote0",
860 "foreground-gdk", "e_color1,
861 "paragraph-background-gdk", "e_bgcolor1,
863 gtk_text_buffer_create_tag(buffer, "quote1",
864 "foreground-gdk", "e_color2,
865 "paragraph-background-gdk", "e_bgcolor2,
867 gtk_text_buffer_create_tag(buffer, "quote2",
868 "foreground-gdk", "e_color3,
869 "paragraph-background-gdk", "e_bgcolor3,
872 gtk_text_buffer_create_tag(buffer, "quote0",
873 "foreground-gdk", "e_color1,
875 gtk_text_buffer_create_tag(buffer, "quote1",
876 "foreground-gdk", "e_color2,
878 gtk_text_buffer_create_tag(buffer, "quote2",
879 "foreground-gdk", "e_color3,
883 gtk_text_buffer_create_tag(buffer, "signature",
884 "foreground-gdk", &signature_color,
886 gtk_text_buffer_create_tag(buffer, "link",
887 "foreground-gdk", &uri_color,
889 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
890 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
892 color[0] = quote_color1;
893 color[1] = quote_color2;
894 color[2] = quote_color3;
895 color[3] = quote_bgcolor1;
896 color[4] = quote_bgcolor2;
897 color[5] = quote_bgcolor3;
898 color[6] = signature_color;
899 color[7] = uri_color;
900 cmap = gdk_drawable_get_colormap(compose->window->window);
901 gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
903 for (i = 0; i < 8; i++) {
904 if (success[i] == FALSE) {
907 g_warning("Compose: color allocation failed.\n");
908 style = gtk_widget_get_style(GTK_WIDGET(text));
909 quote_color1 = quote_color2 = quote_color3 =
910 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 =
911 signature_color = uri_color = black;
916 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
917 GPtrArray *attach_files)
919 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
922 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
924 return compose_generic_new(account, NULL, item, NULL, NULL);
927 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
929 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
932 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
933 GPtrArray *attach_files, GList *listAddress )
936 GtkTextView *textview;
937 GtkTextBuffer *textbuf;
939 GtkItemFactory *ifactory;
941 if (item && item->prefs && item->prefs->enable_default_account)
942 account = account_find_from_id(item->prefs->default_account);
944 if (!account) account = cur_account;
945 g_return_val_if_fail(account != NULL, NULL);
947 compose = compose_create(account, COMPOSE_NEW, FALSE);
949 ifactory = gtk_item_factory_from_widget(compose->menubar);
951 compose->replyinfo = NULL;
952 compose->fwdinfo = NULL;
954 textview = GTK_TEXT_VIEW(compose->text);
955 textbuf = gtk_text_view_get_buffer(textview);
956 compose_create_tags(textview, compose);
958 undo_block(compose->undostruct);
960 if (item && item->prefs && item->prefs->enable_default_dictionary &&
962 gtkaspell_change_dict(compose->gtkaspell,
963 item->prefs->default_dictionary);
966 if (account->auto_sig)
967 compose_insert_sig(compose, FALSE);
968 gtk_text_buffer_get_start_iter(textbuf, &iter);
969 gtk_text_buffer_place_cursor(textbuf, &iter);
971 if (account->protocol != A_NNTP) {
972 if (mailto && *mailto != '\0') {
973 compose_entries_set(compose, mailto);
975 } else if (item && item->prefs->enable_default_to) {
976 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
977 compose_entry_mark_default_to(compose, item->prefs->default_to);
979 if (item && item->ret_rcpt) {
980 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
984 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
986 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
989 * CLAWS: just don't allow return receipt request, even if the user
990 * may want to send an email. simple but foolproof.
992 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
994 compose_add_field_list( compose, listAddress );
1000 for (i = 0; i < attach_files->len; i++) {
1001 file = g_ptr_array_index(attach_files, i);
1002 compose_attach_append(compose, file, file, NULL);
1006 compose_show_first_last_header(compose, TRUE);
1008 /* Set save folder */
1009 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1010 gchar *folderidentifier;
1012 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1013 folderidentifier = folder_item_get_identifier(item);
1014 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1015 g_free(folderidentifier);
1018 gtk_widget_grab_focus(compose->header_last->entry);
1020 undo_unblock(compose->undostruct);
1022 if (prefs_common.auto_exteditor)
1023 compose_exec_ext_editor(compose);
1025 compose->modified = FALSE;
1026 compose_set_title(compose);
1030 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1031 gboolean override_pref)
1033 gchar *privacy = NULL;
1035 g_return_if_fail(compose != NULL);
1036 g_return_if_fail(account != NULL);
1038 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1041 if (account->default_privacy_system
1042 && strlen(account->default_privacy_system)) {
1043 privacy = account->default_privacy_system;
1045 GSList *privacy_avail = privacy_get_system_ids();
1046 if (privacy_avail && g_slist_length(privacy_avail)) {
1047 privacy = (gchar *)(privacy_avail->data);
1050 if (privacy != NULL) {
1051 compose->privacy_system = g_strdup(privacy);
1052 compose_update_privacy_system_menu_item(compose, FALSE);
1053 compose_use_encryption(compose, TRUE);
1057 static void compose_force_signing(Compose *compose, PrefsAccount *account)
1059 gchar *privacy = NULL;
1061 if (account->default_privacy_system
1062 && strlen(account->default_privacy_system)) {
1063 privacy = account->default_privacy_system;
1065 GSList *privacy_avail = privacy_get_system_ids();
1066 if (privacy_avail && g_slist_length(privacy_avail)) {
1067 privacy = (gchar *)(privacy_avail->data);
1070 if (privacy != NULL) {
1071 compose->privacy_system = g_strdup(privacy);
1072 compose_update_privacy_system_menu_item(compose, FALSE);
1073 compose_use_signing(compose, TRUE);
1077 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1081 Compose *compose = NULL;
1082 g_return_val_if_fail(msginfo_list != NULL, NULL);
1084 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1085 g_return_val_if_fail(msginfo != NULL, NULL);
1087 list_len = g_slist_length(msginfo_list);
1091 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1092 FALSE, prefs_common.default_reply_list, FALSE, body);
1094 case COMPOSE_REPLY_WITH_QUOTE:
1095 compose = compose_reply(msginfo, TRUE,
1096 FALSE, prefs_common.default_reply_list, FALSE, body);
1098 case COMPOSE_REPLY_WITHOUT_QUOTE:
1099 compose = compose_reply(msginfo, FALSE,
1100 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1102 case COMPOSE_REPLY_TO_SENDER:
1103 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1104 FALSE, FALSE, TRUE, body);
1106 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1107 compose = compose_followup_and_reply_to(msginfo,
1108 prefs_common.reply_with_quote,
1109 FALSE, FALSE, body);
1111 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1112 compose = compose_reply(msginfo, TRUE,
1113 FALSE, FALSE, TRUE, body);
1115 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1116 compose = compose_reply(msginfo, FALSE,
1117 FALSE, FALSE, TRUE, NULL);
1119 case COMPOSE_REPLY_TO_ALL:
1120 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1121 TRUE, FALSE, FALSE, body);
1123 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1124 compose = compose_reply(msginfo, TRUE,
1125 TRUE, FALSE, FALSE, body);
1127 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1128 compose = compose_reply(msginfo, FALSE,
1129 TRUE, FALSE, FALSE, NULL);
1131 case COMPOSE_REPLY_TO_LIST:
1132 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1133 FALSE, TRUE, FALSE, body);
1135 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1136 compose = compose_reply(msginfo, TRUE,
1137 FALSE, TRUE, FALSE, body);
1139 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1140 compose = compose_reply(msginfo, FALSE,
1141 FALSE, TRUE, FALSE, NULL);
1143 case COMPOSE_FORWARD:
1144 if (prefs_common.forward_as_attachment) {
1145 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1148 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1152 case COMPOSE_FORWARD_INLINE:
1153 /* check if we reply to more than one Message */
1154 if (list_len == 1) {
1155 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1158 /* more messages FALL THROUGH */
1159 case COMPOSE_FORWARD_AS_ATTACH:
1160 compose = compose_forward_multiple(NULL, msginfo_list);
1162 case COMPOSE_REDIRECT:
1163 compose = compose_redirect(NULL, msginfo, FALSE);
1166 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1171 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1172 gboolean to_ml, gboolean to_sender,
1175 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1176 to_sender, FALSE, body);
1179 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1184 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1185 to_sender, TRUE, body);
1188 static void compose_extract_original_charset(Compose *compose)
1190 MsgInfo *info = NULL;
1191 if (compose->replyinfo) {
1192 info = compose->replyinfo;
1193 } else if (compose->fwdinfo) {
1194 info = compose->fwdinfo;
1195 } else if (compose->targetinfo) {
1196 info = compose->targetinfo;
1199 MimeInfo *mimeinfo = procmime_scan_message(info);
1200 MimeInfo *partinfo = mimeinfo;
1201 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1202 partinfo = procmime_mimeinfo_next(partinfo);
1204 compose->orig_charset =
1205 g_strdup(procmime_mimeinfo_get_parameter(
1206 partinfo, "charset"));
1208 procmime_mimeinfo_free_all(mimeinfo);
1212 #define SIGNAL_BLOCK(buffer) { \
1213 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1214 G_CALLBACK(compose_changed_cb), \
1216 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1217 G_CALLBACK(text_inserted), \
1221 #define SIGNAL_UNBLOCK(buffer) { \
1222 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1223 G_CALLBACK(compose_changed_cb), \
1225 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1226 G_CALLBACK(text_inserted), \
1230 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1231 gboolean to_all, gboolean to_ml,
1233 gboolean followup_and_reply_to,
1236 GtkItemFactory *ifactory;
1238 PrefsAccount *account = NULL;
1239 PrefsAccount *reply_account;
1240 GtkTextView *textview;
1241 GtkTextBuffer *textbuf;
1243 g_return_val_if_fail(msginfo != NULL, NULL);
1244 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1246 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1248 g_return_val_if_fail(account != NULL, NULL);
1250 if (to_sender && account->protocol == A_NNTP &&
1251 !followup_and_reply_to) {
1253 account_find_from_address(account->address);
1255 reply_account = compose_current_mail_account();
1259 reply_account = account;
1261 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1263 compose->updating = TRUE;
1265 ifactory = gtk_item_factory_from_widget(compose->menubar);
1267 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1268 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1270 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1271 if (!compose->replyinfo)
1272 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1274 compose_extract_original_charset(compose);
1276 if (msginfo->folder && msginfo->folder->ret_rcpt)
1277 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1279 /* Set save folder */
1280 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1281 gchar *folderidentifier;
1283 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1284 folderidentifier = folder_item_get_identifier(msginfo->folder);
1285 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1286 g_free(folderidentifier);
1289 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1290 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1291 to_sender, followup_and_reply_to);
1292 compose_show_first_last_header(compose, TRUE);
1294 textview = (GTK_TEXT_VIEW(compose->text));
1295 textbuf = gtk_text_view_get_buffer(textview);
1296 compose_create_tags(textview, compose);
1298 undo_block(compose->undostruct);
1300 if (msginfo->folder && msginfo->folder->prefs &&
1301 msginfo->folder->prefs &&
1302 msginfo->folder->prefs->enable_default_dictionary &&
1304 gtkaspell_change_dict(compose->gtkaspell,
1305 msginfo->folder->prefs->default_dictionary);
1311 if (prefs_common.quotemark && *prefs_common.quotemark)
1312 qmark = prefs_common.quotemark;
1316 compose_quote_fmt(compose, compose->replyinfo,
1317 prefs_common.quotefmt,
1318 qmark, body, FALSE);
1320 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1321 compose_force_encryption(compose, account, FALSE);
1324 SIGNAL_BLOCK(textbuf);
1326 if (account->auto_sig)
1327 compose_insert_sig(compose, FALSE);
1329 compose_wrap_all(compose);
1331 SIGNAL_UNBLOCK(textbuf);
1333 gtk_widget_grab_focus(compose->text);
1335 undo_unblock(compose->undostruct);
1337 if (prefs_common.auto_exteditor)
1338 compose_exec_ext_editor(compose);
1340 compose->modified = FALSE;
1341 compose_set_title(compose);
1343 compose->updating = FALSE;
1345 if (compose->deferred_destroy) {
1346 compose_destroy(compose);
1353 #define INSERT_FW_HEADER(var, hdr) \
1354 if (msginfo->var && *msginfo->var) { \
1355 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1356 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1357 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1360 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1361 gboolean as_attach, const gchar *body,
1362 gboolean no_extedit,
1366 GtkTextView *textview;
1367 GtkTextBuffer *textbuf;
1370 g_return_val_if_fail(msginfo != NULL, NULL);
1371 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1374 !(account = compose_guess_forward_account_from_msginfo
1376 account = cur_account;
1378 compose = compose_create(account, COMPOSE_FORWARD, batch);
1380 compose->updating = TRUE;
1381 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1382 if (!compose->fwdinfo)
1383 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1385 compose_extract_original_charset(compose);
1387 if (msginfo->subject && *msginfo->subject) {
1388 gchar *buf, *buf2, *p;
1390 buf = p = g_strdup(msginfo->subject);
1391 p += subject_get_prefix_length(p);
1392 memmove(buf, p, strlen(p) + 1);
1394 buf2 = g_strdup_printf("Fw: %s", buf);
1395 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1401 textview = GTK_TEXT_VIEW(compose->text);
1402 textbuf = gtk_text_view_get_buffer(textview);
1403 compose_create_tags(textview, compose);
1405 undo_block(compose->undostruct);
1409 msgfile = procmsg_get_message_file_path(msginfo);
1410 if (!is_file_exist(msgfile))
1411 g_warning("%s: file not exist\n", msgfile);
1413 compose_attach_append(compose, msgfile, msgfile,
1419 MsgInfo *full_msginfo;
1421 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1423 full_msginfo = procmsg_msginfo_copy(msginfo);
1425 if (prefs_common.fw_quotemark &&
1426 *prefs_common.fw_quotemark)
1427 qmark = prefs_common.fw_quotemark;
1431 compose_quote_fmt(compose, full_msginfo,
1432 prefs_common.fw_quotefmt,
1433 qmark, body, FALSE);
1434 compose_attach_parts(compose, msginfo);
1436 procmsg_msginfo_free(full_msginfo);
1439 SIGNAL_BLOCK(textbuf);
1441 if (account->auto_sig)
1442 compose_insert_sig(compose, FALSE);
1444 compose_wrap_all(compose);
1446 SIGNAL_UNBLOCK(textbuf);
1448 gtk_text_buffer_get_start_iter(textbuf, &iter);
1449 gtk_text_buffer_place_cursor(textbuf, &iter);
1451 gtk_widget_grab_focus(compose->header_last->entry);
1453 if (!no_extedit && prefs_common.auto_exteditor)
1454 compose_exec_ext_editor(compose);
1457 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1458 gchar *folderidentifier;
1460 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1461 folderidentifier = folder_item_get_identifier(msginfo->folder);
1462 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1463 g_free(folderidentifier);
1466 undo_unblock(compose->undostruct);
1468 compose->modified = FALSE;
1469 compose_set_title(compose);
1471 compose->updating = FALSE;
1473 if (compose->deferred_destroy) {
1474 compose_destroy(compose);
1481 #undef INSERT_FW_HEADER
1483 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1486 GtkTextView *textview;
1487 GtkTextBuffer *textbuf;
1491 gboolean single_mail = TRUE;
1493 g_return_val_if_fail(msginfo_list != NULL, NULL);
1495 if (g_slist_length(msginfo_list) > 1)
1496 single_mail = FALSE;
1498 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1499 if (((MsgInfo *)msginfo->data)->folder == NULL)
1502 /* guess account from first selected message */
1504 !(account = compose_guess_forward_account_from_msginfo
1505 (msginfo_list->data)))
1506 account = cur_account;
1508 g_return_val_if_fail(account != NULL, NULL);
1510 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1511 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1512 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1515 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1517 compose->updating = TRUE;
1519 textview = GTK_TEXT_VIEW(compose->text);
1520 textbuf = gtk_text_view_get_buffer(textview);
1521 compose_create_tags(textview, compose);
1523 undo_block(compose->undostruct);
1524 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1525 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1527 if (!is_file_exist(msgfile))
1528 g_warning("%s: file not exist\n", msgfile);
1530 compose_attach_append(compose, msgfile, msgfile,
1536 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1537 if (info->subject && *info->subject) {
1538 gchar *buf, *buf2, *p;
1540 buf = p = g_strdup(info->subject);
1541 p += subject_get_prefix_length(p);
1542 memmove(buf, p, strlen(p) + 1);
1544 buf2 = g_strdup_printf("Fw: %s", buf);
1545 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1551 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1552 _("Fw: multiple emails"));
1555 SIGNAL_BLOCK(textbuf);
1557 if (account->auto_sig)
1558 compose_insert_sig(compose, FALSE);
1560 compose_wrap_all(compose);
1562 SIGNAL_UNBLOCK(textbuf);
1564 gtk_text_buffer_get_start_iter(textbuf, &iter);
1565 gtk_text_buffer_place_cursor(textbuf, &iter);
1567 gtk_widget_grab_focus(compose->header_last->entry);
1568 undo_unblock(compose->undostruct);
1569 compose->modified = FALSE;
1570 compose_set_title(compose);
1572 compose->updating = FALSE;
1574 if (compose->deferred_destroy) {
1575 compose_destroy(compose);
1582 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1584 GtkTextIter start = *iter;
1585 GtkTextIter end_iter;
1586 int start_pos = gtk_text_iter_get_offset(&start);
1588 if (!compose->account->sig_sep)
1591 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1592 start_pos+strlen(compose->account->sig_sep));
1594 /* check sig separator */
1595 str = gtk_text_iter_get_text(&start, &end_iter);
1596 if (!strcmp(str, compose->account->sig_sep)) {
1598 /* check end of line (\n) */
1599 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1600 start_pos+strlen(compose->account->sig_sep));
1601 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1602 start_pos+strlen(compose->account->sig_sep)+1);
1603 tmp = gtk_text_iter_get_text(&start, &end_iter);
1604 if (!strcmp(tmp,"\n")) {
1616 static void compose_colorize_signature(Compose *compose)
1618 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1620 GtkTextIter end_iter;
1621 gtk_text_buffer_get_start_iter(buffer, &iter);
1622 while (gtk_text_iter_forward_line(&iter))
1623 if (compose_is_sig_separator(compose, buffer, &iter)) {
1624 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1625 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1629 void compose_reedit(MsgInfo *msginfo)
1631 Compose *compose = NULL;
1632 PrefsAccount *account = NULL;
1633 GtkTextView *textview;
1634 GtkTextBuffer *textbuf;
1638 gchar buf[BUFFSIZE];
1639 gboolean use_signing = FALSE;
1640 gboolean use_encryption = FALSE;
1641 gchar *privacy_system = NULL;
1643 g_return_if_fail(msginfo != NULL);
1644 g_return_if_fail(msginfo->folder != NULL);
1646 if (compose_put_existing_to_front(msginfo)) {
1650 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1651 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1652 gchar queueheader_buf[BUFFSIZE];
1655 /* Select Account from queue headers */
1656 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1657 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1658 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1659 account = account_find_from_id(id);
1661 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1662 sizeof(queueheader_buf), "NAID:")) {
1663 id = atoi(&queueheader_buf[strlen("NAID:")]);
1664 account = account_find_from_id(id);
1666 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1667 sizeof(queueheader_buf), "MAID:")) {
1668 id = atoi(&queueheader_buf[strlen("MAID:")]);
1669 account = account_find_from_id(id);
1671 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1672 sizeof(queueheader_buf), "S:")) {
1673 account = account_find_from_address(queueheader_buf);
1675 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1676 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1677 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1678 use_signing = param;
1681 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1682 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1683 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1684 use_encryption = param;
1686 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1687 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1688 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1690 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1691 sizeof(queueheader_buf), "X-Priority: ")) {
1692 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1693 compose->priority = param;
1696 account = msginfo->folder->folder->account;
1699 if (!account && prefs_common.reedit_account_autosel) {
1700 gchar from[BUFFSIZE];
1701 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1702 extract_address(from);
1703 account = account_find_from_address(from);
1707 account = cur_account;
1709 g_return_if_fail(account != NULL);
1711 compose = compose_create(account, COMPOSE_REEDIT, FALSE);
1713 compose->updating = TRUE;
1715 if (privacy_system != NULL) {
1716 compose->privacy_system = privacy_system;
1717 compose_use_signing(compose, use_signing);
1718 compose_use_encryption(compose, use_encryption);
1719 compose_update_privacy_system_menu_item(compose, FALSE);
1721 activate_privacy_system(compose, account, FALSE);
1724 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1726 compose_extract_original_charset(compose);
1728 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1729 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1730 gchar queueheader_buf[BUFFSIZE];
1732 /* Set message save folder */
1733 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1736 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1737 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1738 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1740 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1741 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1743 GtkItemFactory *ifactory;
1744 ifactory = gtk_item_factory_from_widget(compose->menubar);
1745 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1750 if (compose_parse_header(compose, msginfo) < 0) {
1751 compose->updating = FALSE;
1752 compose_destroy(compose);
1755 compose_reedit_set_entry(compose, msginfo);
1757 textview = GTK_TEXT_VIEW(compose->text);
1758 textbuf = gtk_text_view_get_buffer(textview);
1759 compose_create_tags(textview, compose);
1761 mark = gtk_text_buffer_get_insert(textbuf);
1762 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1764 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1765 G_CALLBACK(compose_changed_cb),
1768 if (procmime_msginfo_is_encrypted(msginfo)) {
1769 fp = procmime_get_first_encrypted_text_content(msginfo);
1771 compose_force_encryption(compose, account, TRUE);
1774 fp = procmime_get_first_text_content(msginfo);
1777 g_warning("Can't get text part\n");
1781 gboolean prev_autowrap = compose->autowrap;
1783 compose->autowrap = FALSE;
1784 while (fgets(buf, sizeof(buf), fp) != NULL) {
1786 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1788 compose_wrap_all_full(compose, FALSE);
1789 compose->autowrap = prev_autowrap;
1793 compose_attach_parts(compose, msginfo);
1795 compose_colorize_signature(compose);
1797 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1798 G_CALLBACK(compose_changed_cb),
1801 gtk_widget_grab_focus(compose->text);
1803 if (prefs_common.auto_exteditor) {
1804 compose_exec_ext_editor(compose);
1806 compose->modified = FALSE;
1807 compose_set_title(compose);
1809 compose->updating = FALSE;
1811 if (compose->deferred_destroy) {
1812 compose_destroy(compose);
1816 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
1821 GtkItemFactory *ifactory;
1824 g_return_val_if_fail(msginfo != NULL, NULL);
1827 account = account_get_reply_account(msginfo,
1828 prefs_common.reply_account_autosel);
1829 g_return_val_if_fail(account != NULL, NULL);
1831 compose = compose_create(account, COMPOSE_REDIRECT, batch);
1833 compose->updating = TRUE;
1835 ifactory = gtk_item_factory_from_widget(compose->menubar);
1836 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1837 compose->replyinfo = NULL;
1838 compose->fwdinfo = NULL;
1840 compose_show_first_last_header(compose, TRUE);
1842 gtk_widget_grab_focus(compose->header_last->entry);
1844 filename = procmsg_get_message_file_path(msginfo);
1846 if (filename == NULL) {
1847 compose->updating = FALSE;
1848 compose_destroy(compose);
1853 compose->redirect_filename = filename;
1855 /* Set save folder */
1856 item = msginfo->folder;
1857 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1858 gchar *folderidentifier;
1860 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1861 folderidentifier = folder_item_get_identifier(item);
1862 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1863 g_free(folderidentifier);
1866 compose_attach_parts(compose, msginfo);
1868 if (msginfo->subject)
1869 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1871 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1873 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1874 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1876 compose_colorize_signature(compose);
1878 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1879 menu_set_sensitive(ifactory, "/Add...", FALSE);
1880 menu_set_sensitive(ifactory, "/Remove", FALSE);
1881 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1883 ifactory = gtk_item_factory_from_widget(compose->menubar);
1884 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1885 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1886 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1887 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1888 menu_set_sensitive(ifactory, "/Edit", FALSE);
1889 menu_set_sensitive(ifactory, "/Options", FALSE);
1890 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1891 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1893 if (compose->toolbar->draft_btn)
1894 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1895 if (compose->toolbar->insert_btn)
1896 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1897 if (compose->toolbar->attach_btn)
1898 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1899 if (compose->toolbar->sig_btn)
1900 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1901 if (compose->toolbar->exteditor_btn)
1902 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1903 if (compose->toolbar->linewrap_current_btn)
1904 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1905 if (compose->toolbar->linewrap_all_btn)
1906 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1908 compose->modified = FALSE;
1909 compose_set_title(compose);
1910 compose->updating = FALSE;
1912 if (compose->deferred_destroy) {
1913 compose_destroy(compose);
1920 GList *compose_get_compose_list(void)
1922 return compose_list;
1925 void compose_entry_append(Compose *compose, const gchar *address,
1926 ComposeEntryType type)
1930 gboolean in_quote = FALSE;
1931 if (!address || *address == '\0') return;
1938 header = N_("Bcc:");
1940 case COMPOSE_REPLYTO:
1941 header = N_("Reply-To:");
1943 case COMPOSE_NEWSGROUPS:
1944 header = N_("Newsgroups:");
1946 case COMPOSE_FOLLOWUPTO:
1947 header = N_( "Followup-To:");
1954 header = prefs_common.trans_hdr ? gettext(header) : header;
1956 cur = begin = (gchar *)address;
1958 /* we separate the line by commas, but not if we're inside a quoted
1960 while (*cur != '\0') {
1962 in_quote = !in_quote;
1963 if (*cur == ',' && !in_quote) {
1964 gchar *tmp = g_strdup(begin);
1966 tmp[cur-begin]='\0';
1969 while (*tmp == ' ' || *tmp == '\t')
1971 compose_add_header_entry(compose, header, tmp);
1978 gchar *tmp = g_strdup(begin);
1980 tmp[cur-begin]='\0';
1983 while (*tmp == ' ' || *tmp == '\t')
1985 compose_add_header_entry(compose, header, tmp);
1990 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1992 static GdkColor yellow;
1993 static GdkColor black;
1994 static gboolean yellow_initialised = FALSE;
1998 if (!yellow_initialised) {
1999 gdk_color_parse("#f5f6be", &yellow);
2000 gdk_color_parse("#000000", &black);
2001 yellow_initialised = gdk_colormap_alloc_color(
2002 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
2003 yellow_initialised &= gdk_colormap_alloc_color(
2004 gdk_colormap_get_system(), &black, FALSE, TRUE);
2007 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
2008 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
2009 if (gtk_entry_get_text(entry) &&
2010 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
2011 if (yellow_initialised) {
2012 gtk_widget_modify_base(
2013 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2014 GTK_STATE_NORMAL, &yellow);
2015 gtk_widget_modify_text(
2016 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2017 GTK_STATE_NORMAL, &black);
2023 void compose_toolbar_cb(gint action, gpointer data)
2025 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2026 Compose *compose = (Compose*)toolbar_item->parent;
2028 g_return_if_fail(compose != NULL);
2032 compose_send_cb(compose, 0, NULL);
2035 compose_send_later_cb(compose, 0, NULL);
2038 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2041 compose_insert_file_cb(compose, 0, NULL);
2044 compose_attach_cb(compose, 0, NULL);
2047 compose_insert_sig(compose, FALSE);
2050 compose_ext_editor_cb(compose, 0, NULL);
2052 case A_LINEWRAP_CURRENT:
2053 compose_beautify_paragraph(compose, NULL, TRUE);
2055 case A_LINEWRAP_ALL:
2056 compose_wrap_all_full(compose, TRUE);
2059 compose_address_cb(compose, 0, NULL);
2062 case A_CHECK_SPELLING:
2063 compose_check_all(compose);
2071 static void compose_entries_set(Compose *compose, const gchar *mailto)
2075 gchar *subject = NULL;
2080 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
2083 compose_entry_append(compose, to, COMPOSE_TO);
2085 compose_entry_append(compose, cc, COMPOSE_CC);
2087 if (!g_utf8_validate (subject, -1, NULL)) {
2088 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2089 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2092 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2096 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2097 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2100 gboolean prev_autowrap = compose->autowrap;
2102 compose->autowrap = FALSE;
2104 mark = gtk_text_buffer_get_insert(buffer);
2105 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2107 if (!g_utf8_validate (body, -1, NULL)) {
2108 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2109 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2112 gtk_text_buffer_insert(buffer, &iter, body, -1);
2114 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2116 compose->autowrap = prev_autowrap;
2117 if (compose->autowrap)
2118 compose_wrap_all(compose);
2127 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2129 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2130 {"Cc:", NULL, TRUE},
2131 {"References:", NULL, FALSE},
2132 {"Bcc:", NULL, TRUE},
2133 {"Newsgroups:", NULL, TRUE},
2134 {"Followup-To:", NULL, TRUE},
2135 {"List-Post:", NULL, FALSE},
2136 {"X-Priority:", NULL, FALSE},
2137 {NULL, NULL, FALSE}};
2153 g_return_val_if_fail(msginfo != NULL, -1);
2155 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2156 procheader_get_header_fields(fp, hentry);
2159 if (hentry[H_REPLY_TO].body != NULL) {
2160 if (hentry[H_REPLY_TO].body[0] != '\0') {
2162 conv_unmime_header(hentry[H_REPLY_TO].body,
2165 g_free(hentry[H_REPLY_TO].body);
2166 hentry[H_REPLY_TO].body = NULL;
2168 if (hentry[H_CC].body != NULL) {
2169 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2170 g_free(hentry[H_CC].body);
2171 hentry[H_CC].body = NULL;
2173 if (hentry[H_REFERENCES].body != NULL) {
2174 if (compose->mode == COMPOSE_REEDIT)
2175 compose->references = hentry[H_REFERENCES].body;
2177 compose->references = compose_parse_references
2178 (hentry[H_REFERENCES].body, msginfo->msgid);
2179 g_free(hentry[H_REFERENCES].body);
2181 hentry[H_REFERENCES].body = NULL;
2183 if (hentry[H_BCC].body != NULL) {
2184 if (compose->mode == COMPOSE_REEDIT)
2186 conv_unmime_header(hentry[H_BCC].body, NULL);
2187 g_free(hentry[H_BCC].body);
2188 hentry[H_BCC].body = NULL;
2190 if (hentry[H_NEWSGROUPS].body != NULL) {
2191 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2192 hentry[H_NEWSGROUPS].body = NULL;
2194 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2195 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2196 compose->followup_to =
2197 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2200 g_free(hentry[H_FOLLOWUP_TO].body);
2201 hentry[H_FOLLOWUP_TO].body = NULL;
2203 if (hentry[H_LIST_POST].body != NULL) {
2206 extract_address(hentry[H_LIST_POST].body);
2207 if (hentry[H_LIST_POST].body[0] != '\0') {
2208 scan_mailto_url(hentry[H_LIST_POST].body,
2209 &to, NULL, NULL, NULL, NULL);
2211 g_free(compose->ml_post);
2212 compose->ml_post = to;
2215 g_free(hentry[H_LIST_POST].body);
2216 hentry[H_LIST_POST].body = NULL;
2219 /* CLAWS - X-Priority */
2220 if (compose->mode == COMPOSE_REEDIT)
2221 if (hentry[H_X_PRIORITY].body != NULL) {
2224 priority = atoi(hentry[H_X_PRIORITY].body);
2225 g_free(hentry[H_X_PRIORITY].body);
2227 hentry[H_X_PRIORITY].body = NULL;
2229 if (priority < PRIORITY_HIGHEST ||
2230 priority > PRIORITY_LOWEST)
2231 priority = PRIORITY_NORMAL;
2233 compose->priority = priority;
2236 if (compose->mode == COMPOSE_REEDIT) {
2237 if (msginfo->inreplyto && *msginfo->inreplyto)
2238 compose->inreplyto = g_strdup(msginfo->inreplyto);
2242 if (msginfo->msgid && *msginfo->msgid)
2243 compose->inreplyto = g_strdup(msginfo->msgid);
2245 if (!compose->references) {
2246 if (msginfo->msgid && *msginfo->msgid) {
2247 if (msginfo->inreplyto && *msginfo->inreplyto)
2248 compose->references =
2249 g_strdup_printf("<%s>\n\t<%s>",
2253 compose->references =
2254 g_strconcat("<", msginfo->msgid, ">",
2256 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2257 compose->references =
2258 g_strconcat("<", msginfo->inreplyto, ">",
2266 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2268 GSList *ref_id_list, *cur;
2272 ref_id_list = references_list_append(NULL, ref);
2273 if (!ref_id_list) return NULL;
2274 if (msgid && *msgid)
2275 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2280 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2281 /* "<" + Message-ID + ">" + CR+LF+TAB */
2282 len += strlen((gchar *)cur->data) + 5;
2284 if (len > MAX_REFERENCES_LEN) {
2285 /* remove second message-ID */
2286 if (ref_id_list && ref_id_list->next &&
2287 ref_id_list->next->next) {
2288 g_free(ref_id_list->next->data);
2289 ref_id_list = g_slist_remove
2290 (ref_id_list, ref_id_list->next->data);
2292 slist_free_strings(ref_id_list);
2293 g_slist_free(ref_id_list);
2300 new_ref = g_string_new("");
2301 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2302 if (new_ref->len > 0)
2303 g_string_append(new_ref, "\n\t");
2304 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2307 slist_free_strings(ref_id_list);
2308 g_slist_free(ref_id_list);
2310 new_ref_str = new_ref->str;
2311 g_string_free(new_ref, FALSE);
2316 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2317 const gchar *fmt, const gchar *qmark,
2318 const gchar *body, gboolean rewrap)
2320 static MsgInfo dummyinfo;
2321 gchar *quote_str = NULL;
2323 gboolean prev_autowrap;
2324 const gchar *trimmed_body = body;
2325 gint cursor_pos = -1;
2326 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2327 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2332 SIGNAL_BLOCK(buffer);
2335 msginfo = &dummyinfo;
2337 if (qmark != NULL) {
2338 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2339 quote_fmt_scan_string(qmark);
2342 buf = quote_fmt_get_buffer();
2344 alertpanel_error(_("Quote mark format error."));
2346 Xstrdup_a(quote_str, buf, goto error)
2349 if (fmt && *fmt != '\0') {
2350 while (trimmed_body && strlen(trimmed_body) > 1
2351 && trimmed_body[0]=='\n')
2354 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2355 quote_fmt_scan_string(fmt);
2358 buf = quote_fmt_get_buffer();
2360 alertpanel_error(_("Message reply/forward format error."));
2366 prev_autowrap = compose->autowrap;
2367 compose->autowrap = FALSE;
2369 mark = gtk_text_buffer_get_insert(buffer);
2370 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2371 if (g_utf8_validate(buf, -1, NULL)) {
2372 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2374 gchar *tmpout = NULL;
2375 tmpout = conv_codeset_strdup
2376 (buf, conv_get_locale_charset_str_no_utf8(),
2378 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2380 tmpout = g_malloc(strlen(buf)*2+1);
2381 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2383 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2387 cursor_pos = quote_fmt_get_cursor_pos();
2388 compose->set_cursor_pos = cursor_pos;
2389 if (cursor_pos == -1) {
2392 gtk_text_buffer_get_start_iter(buffer, &iter);
2393 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2394 gtk_text_buffer_place_cursor(buffer, &iter);
2396 compose->autowrap = prev_autowrap;
2397 if (compose->autowrap && rewrap)
2398 compose_wrap_all(compose);
2405 SIGNAL_UNBLOCK(buffer);
2411 /* if ml_post is of type addr@host and from is of type
2412 * addr-anything@host, return TRUE
2414 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2416 gchar *left_ml = NULL;
2417 gchar *right_ml = NULL;
2418 gchar *left_from = NULL;
2419 gchar *right_from = NULL;
2420 gboolean result = FALSE;
2422 if (!ml_post || !from)
2425 left_ml = g_strdup(ml_post);
2426 if (strstr(left_ml, "@")) {
2427 right_ml = strstr(left_ml, "@")+1;
2428 *(strstr(left_ml, "@")) = '\0';
2431 left_from = g_strdup(from);
2432 if (strstr(left_from, "@")) {
2433 right_from = strstr(left_from, "@")+1;
2434 *(strstr(left_from, "@")) = '\0';
2437 if (left_ml && left_from && right_ml && right_from
2438 && !strncmp(left_from, left_ml, strlen(left_ml))
2439 && !strcmp(right_from, right_ml)) {
2448 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2450 gchar *my_addr1, *my_addr2;
2452 if (!addr1 || !addr2)
2455 Xstrdup_a(my_addr1, addr1, return FALSE);
2456 Xstrdup_a(my_addr2, addr2, return FALSE);
2458 extract_address(my_addr1);
2459 extract_address(my_addr2);
2461 return !strcmp(my_addr1, my_addr2);
2464 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2465 gboolean to_all, gboolean to_ml,
2467 gboolean followup_and_reply_to)
2469 GSList *cc_list = NULL;
2472 gchar *replyto = NULL;
2473 GHashTable *to_table;
2475 gboolean reply_to_ml = FALSE;
2476 gboolean default_reply_to = FALSE;
2478 g_return_if_fail(compose->account != NULL);
2479 g_return_if_fail(msginfo != NULL);
2481 reply_to_ml = to_ml && compose->ml_post;
2483 default_reply_to = msginfo->folder &&
2484 msginfo->folder->prefs->enable_default_reply_to;
2486 if (compose->account->protocol != A_NNTP) {
2487 if (reply_to_ml && !default_reply_to) {
2489 gboolean is_subscr = is_subscription(compose->ml_post,
2492 /* normal answer to ml post with a reply-to */
2493 compose_entry_append(compose,
2496 if (compose->replyto
2497 && !same_address(compose->ml_post, compose->replyto))
2498 compose_entry_append(compose,
2502 /* answer to subscription confirmation */
2503 if (compose->replyto)
2504 compose_entry_append(compose,
2507 else if (msginfo->from)
2508 compose_entry_append(compose,
2513 else if (!(to_all || to_sender) && default_reply_to) {
2514 compose_entry_append(compose,
2515 msginfo->folder->prefs->default_reply_to,
2517 compose_entry_mark_default_to(compose,
2518 msginfo->folder->prefs->default_reply_to);
2523 Xstrdup_a(tmp1, msginfo->from, return);
2524 extract_address(tmp1);
2525 if (to_all || to_sender ||
2526 !account_find_from_address(tmp1))
2527 compose_entry_append(compose,
2528 (compose->replyto && !to_sender)
2529 ? compose->replyto :
2530 msginfo->from ? msginfo->from : "",
2532 else if (!to_all && !to_sender) {
2533 /* reply to the last list of recipients */
2534 compose_entry_append(compose,
2535 msginfo->to ? msginfo->to : "",
2537 compose_entry_append(compose,
2538 msginfo->cc ? msginfo->cc : "",
2543 if (to_sender || (compose->followup_to &&
2544 !strncmp(compose->followup_to, "poster", 6)))
2545 compose_entry_append
2547 (compose->replyto ? compose->replyto :
2548 msginfo->from ? msginfo->from : ""),
2551 else if (followup_and_reply_to || to_all) {
2552 compose_entry_append
2554 (compose->replyto ? compose->replyto :
2555 msginfo->from ? msginfo->from : ""),
2558 compose_entry_append
2560 compose->followup_to ? compose->followup_to :
2561 compose->newsgroups ? compose->newsgroups : "",
2562 COMPOSE_NEWSGROUPS);
2565 compose_entry_append
2567 compose->followup_to ? compose->followup_to :
2568 compose->newsgroups ? compose->newsgroups : "",
2569 COMPOSE_NEWSGROUPS);
2572 if (msginfo->subject && *msginfo->subject) {
2576 buf = p = g_strdup(msginfo->subject);
2577 p += subject_get_prefix_length(p);
2578 memmove(buf, p, strlen(p) + 1);
2580 buf2 = g_strdup_printf("Re: %s", buf);
2581 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2586 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2588 if (to_ml && compose->ml_post) return;
2589 if (!to_all || compose->account->protocol == A_NNTP) return;
2591 if (compose->replyto) {
2592 Xstrdup_a(replyto, compose->replyto, return);
2593 extract_address(replyto);
2595 if (msginfo->from) {
2596 Xstrdup_a(from, msginfo->from, return);
2597 extract_address(from);
2600 if (replyto && from)
2601 cc_list = address_list_append_with_comments(cc_list, from);
2602 if (to_all && msginfo->folder &&
2603 msginfo->folder->prefs->enable_default_reply_to)
2604 cc_list = address_list_append_with_comments(cc_list,
2605 msginfo->folder->prefs->default_reply_to);
2606 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2607 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2609 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2611 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2612 if (compose->account)
2613 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2614 GINT_TO_POINTER(1));
2616 /* remove address on To: and that of current account */
2617 for (cur = cc_list; cur != NULL; ) {
2618 GSList *next = cur->next;
2621 addr = g_strdup(cur->data);
2622 extract_address(addr);
2624 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2625 cc_list = g_slist_remove(cc_list, cur->data);
2627 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2631 hash_free_strings(to_table);
2632 g_hash_table_destroy(to_table);
2635 for (cur = cc_list; cur != NULL; cur = cur->next)
2636 compose_entry_append(compose, (gchar *)cur->data,
2638 slist_free_strings(cc_list);
2639 g_slist_free(cc_list);
2644 #define SET_ENTRY(entry, str) \
2647 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2650 #define SET_ADDRESS(type, str) \
2653 compose_entry_append(compose, str, type); \
2656 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2658 g_return_if_fail(msginfo != NULL);
2660 SET_ENTRY(subject_entry, msginfo->subject);
2661 SET_ENTRY(from_name, msginfo->from);
2662 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2663 SET_ADDRESS(COMPOSE_CC, compose->cc);
2664 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2665 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2666 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2667 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2669 compose_update_priority_menu_item(compose);
2670 compose_update_privacy_system_menu_item(compose, FALSE);
2671 compose_show_first_last_header(compose, TRUE);
2677 static void compose_insert_sig(Compose *compose, gboolean replace)
2679 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2680 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2682 GtkTextIter iter, iter_end;
2684 gboolean prev_autowrap;
2687 g_return_if_fail(compose->account != NULL);
2689 prev_autowrap = compose->autowrap;
2690 compose->autowrap = FALSE;
2692 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2693 G_CALLBACK(compose_changed_cb),
2696 mark = gtk_text_buffer_get_insert(buffer);
2697 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2698 cur_pos = gtk_text_iter_get_offset (&iter);
2700 gtk_text_buffer_get_end_iter(buffer, &iter);
2702 if (replace && compose->sig_str) {
2704 GtkTextIter first_iter, start_iter, end_iter;
2706 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2708 if (compose->sig_str[0] == '\0')
2711 found = gtk_text_iter_forward_search(&first_iter,
2713 GTK_TEXT_SEARCH_TEXT_ONLY,
2714 &start_iter, &end_iter,
2718 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2723 g_free(compose->sig_str);
2724 compose->sig_str = compose_get_signature_str(compose);
2725 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2726 compose->sig_str = g_strdup("");
2728 cur_pos = gtk_text_iter_get_offset(&iter);
2729 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2731 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2732 gtk_text_iter_forward_char(&iter);
2733 gtk_text_iter_forward_char(&iter);
2734 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2735 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2737 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2738 cur_pos = gtk_text_buffer_get_char_count (buffer);
2740 /* put the cursor where it should be
2741 * either where the quote_fmt says, either before the signature */
2742 if (compose->set_cursor_pos < 0)
2743 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2745 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2746 compose->set_cursor_pos);
2748 gtk_text_buffer_place_cursor(buffer, &iter);
2749 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2750 G_CALLBACK(compose_changed_cb),
2753 compose->autowrap = prev_autowrap;
2754 if (compose->autowrap)
2755 compose_wrap_all(compose);
2758 static gchar *compose_get_signature_str(Compose *compose)
2760 gchar *sig_body = NULL;
2761 gchar *sig_str = NULL;
2762 gchar *utf8_sig_str = NULL;
2764 g_return_val_if_fail(compose->account != NULL, NULL);
2766 if (!compose->account->sig_path)
2769 if (compose->account->sig_type == SIG_FILE) {
2770 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2771 g_warning("can't open signature file: %s\n",
2772 compose->account->sig_path);
2777 if (compose->account->sig_type == SIG_COMMAND)
2778 sig_body = get_command_output(compose->account->sig_path);
2782 tmp = file_read_to_str(compose->account->sig_path);
2785 sig_body = normalize_newlines(tmp);
2789 if (compose->account->sig_sep) {
2790 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2794 sig_str = g_strconcat("\n\n", sig_body, NULL);
2797 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2798 utf8_sig_str = sig_str;
2800 utf8_sig_str = conv_codeset_strdup
2801 (sig_str, conv_get_locale_charset_str_no_utf8(),
2807 return utf8_sig_str;
2810 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2813 GtkTextBuffer *buffer;
2816 const gchar *cur_encoding;
2817 gchar buf[BUFFSIZE];
2820 gboolean prev_autowrap;
2821 gboolean badtxt = FALSE;
2823 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2825 if ((fp = g_fopen(file, "rb")) == NULL) {
2826 FILE_OP_ERROR(file, "fopen");
2827 return COMPOSE_INSERT_READ_ERROR;
2830 prev_autowrap = compose->autowrap;
2831 compose->autowrap = FALSE;
2833 text = GTK_TEXT_VIEW(compose->text);
2834 buffer = gtk_text_view_get_buffer(text);
2835 mark = gtk_text_buffer_get_insert(buffer);
2836 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2838 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2839 G_CALLBACK(text_inserted),
2842 cur_encoding = conv_get_locale_charset_str_no_utf8();
2844 while (fgets(buf, sizeof(buf), fp) != NULL) {
2847 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2848 str = g_strdup(buf);
2850 str = conv_codeset_strdup
2851 (buf, cur_encoding, CS_INTERNAL);
2854 /* strip <CR> if DOS/Windows file,
2855 replace <CR> with <LF> if Macintosh file. */
2858 if (len > 0 && str[len - 1] != '\n') {
2860 if (str[len] == '\r') str[len] = '\n';
2863 gtk_text_buffer_insert(buffer, &iter, str, -1);
2867 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2868 G_CALLBACK(text_inserted),
2870 compose->autowrap = prev_autowrap;
2871 if (compose->autowrap)
2872 compose_wrap_all(compose);
2877 return COMPOSE_INSERT_INVALID_CHARACTER;
2879 return COMPOSE_INSERT_SUCCESS;
2882 static void compose_attach_append(Compose *compose, const gchar *file,
2883 const gchar *filename,
2884 const gchar *content_type)
2892 GtkListStore *store;
2894 gboolean has_binary = FALSE;
2896 if (!is_file_exist(file)) {
2897 g_warning("File %s doesn't exist\n", filename);
2900 if ((size = get_file_size(file)) < 0) {
2901 g_warning("Can't get file size of %s\n", filename);
2905 alertpanel_notice(_("File %s is empty."), filename);
2908 if ((fp = g_fopen(file, "rb")) == NULL) {
2909 alertpanel_error(_("Can't read %s."), filename);
2914 ainfo = g_new0(AttachInfo, 1);
2915 auto_ainfo = g_auto_pointer_new_with_free
2916 (ainfo, (GFreeFunc) compose_attach_info_free);
2917 ainfo->file = g_strdup(file);
2920 ainfo->content_type = g_strdup(content_type);
2921 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2923 MsgFlags flags = {0, 0};
2925 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
2926 ainfo->encoding = ENC_7BIT;
2928 ainfo->encoding = ENC_8BIT;
2930 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2931 if (msginfo && msginfo->subject)
2932 name = g_strdup(msginfo->subject);
2934 name = g_path_get_basename(filename ? filename : file);
2936 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2938 procmsg_msginfo_free(msginfo);
2940 if (!g_ascii_strncasecmp(content_type, "text", 4))
2941 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
2943 ainfo->encoding = ENC_BASE64;
2944 name = g_path_get_basename(filename ? filename : file);
2945 ainfo->name = g_strdup(name);
2949 ainfo->content_type = procmime_get_mime_type(file);
2950 if (!ainfo->content_type) {
2951 ainfo->content_type =
2952 g_strdup("application/octet-stream");
2953 ainfo->encoding = ENC_BASE64;
2954 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2956 procmime_get_encoding_for_text_file(file, &has_binary);
2958 ainfo->encoding = ENC_BASE64;
2959 name = g_path_get_basename(filename ? filename : file);
2960 ainfo->name = g_strdup(name);
2964 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
2965 g_free(ainfo->content_type);
2966 ainfo->content_type = g_strdup("application/octet-stream");
2970 size_text = to_human_readable(size);
2972 store = GTK_LIST_STORE(gtk_tree_view_get_model
2973 (GTK_TREE_VIEW(compose->attach_clist)));
2975 gtk_list_store_append(store, &iter);
2976 gtk_list_store_set(store, &iter,
2977 COL_MIMETYPE, ainfo->content_type,
2978 COL_SIZE, size_text,
2979 COL_NAME, ainfo->name,
2981 COL_AUTODATA, auto_ainfo,
2984 g_auto_pointer_free(auto_ainfo);
2987 static void compose_use_signing(Compose *compose, gboolean use_signing)
2989 GtkItemFactory *ifactory;
2990 GtkWidget *menuitem = NULL;
2992 compose->use_signing = use_signing;
2993 ifactory = gtk_item_factory_from_widget(compose->menubar);
2994 menuitem = gtk_item_factory_get_item
2995 (ifactory, "/Options/Sign");
2996 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3000 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
3002 GtkItemFactory *ifactory;
3003 GtkWidget *menuitem = NULL;
3005 compose->use_encryption = use_encryption;
3006 ifactory = gtk_item_factory_from_widget(compose->menubar);
3007 menuitem = gtk_item_factory_get_item
3008 (ifactory, "/Options/Encrypt");
3010 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3014 #define NEXT_PART_NOT_CHILD(info) \
3016 node = info->node; \
3017 while (node->children) \
3018 node = g_node_last_child(node); \
3019 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3022 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3026 MimeInfo *firsttext = NULL;
3027 MimeInfo *encrypted = NULL;
3030 const gchar *partname = NULL;
3032 mimeinfo = procmime_scan_message(msginfo);
3033 if (!mimeinfo) return;
3035 if (mimeinfo->node->children == NULL) {
3036 procmime_mimeinfo_free_all(mimeinfo);
3040 /* find first content part */
3041 child = (MimeInfo *) mimeinfo->node->children->data;
3042 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3043 child = (MimeInfo *)child->node->children->data;
3045 if (child->type == MIMETYPE_TEXT) {
3047 debug_print("First text part found\n");
3048 } else if (compose->mode == COMPOSE_REEDIT &&
3049 child->type == MIMETYPE_APPLICATION &&
3050 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3051 encrypted = (MimeInfo *)child->node->parent->data;
3054 child = (MimeInfo *) mimeinfo->node->children->data;
3055 while (child != NULL) {
3056 if (child == encrypted) {
3057 /* skip this part of tree */
3058 NEXT_PART_NOT_CHILD(child);
3062 if (child->type == MIMETYPE_MULTIPART) {
3063 /* get the actual content */
3064 child = procmime_mimeinfo_next(child);
3068 if (child == firsttext) {
3069 child = procmime_mimeinfo_next(child);
3073 outfile = procmime_get_tmp_file_name(child);
3074 if (procmime_get_part(outfile, child) < 0)
3075 g_warning("Can't get the part of multipart message.");
3077 gchar *content_type;
3079 content_type = procmime_get_content_type_str(child->type, child->subtype);
3081 /* if we meet a pgp signature, we don't attach it, but
3082 * we force signing. */
3083 if (strcmp(content_type, "application/pgp-signature")) {
3084 partname = procmime_mimeinfo_get_parameter(child, "filename");
3085 if (partname == NULL)
3086 partname = procmime_mimeinfo_get_parameter(child, "name");
3087 if (partname == NULL)
3089 compose_attach_append(compose, outfile,
3090 partname, content_type);
3092 compose_force_signing(compose, compose->account);
3094 g_free(content_type);
3097 NEXT_PART_NOT_CHILD(child);
3099 procmime_mimeinfo_free_all(mimeinfo);
3102 #undef NEXT_PART_NOT_CHILD
3107 WAIT_FOR_INDENT_CHAR,
3108 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3111 /* return indent length, we allow:
3112 indent characters followed by indent characters or spaces/tabs,
3113 alphabets and numbers immediately followed by indent characters,
3114 and the repeating sequences of the above
3115 If quote ends with multiple spaces, only the first one is included. */
3116 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3117 const GtkTextIter *start, gint *len)
3119 GtkTextIter iter = *start;
3123 IndentState state = WAIT_FOR_INDENT_CHAR;
3126 gint alnum_count = 0;
3127 gint space_count = 0;
3130 if (prefs_common.quote_chars == NULL) {
3134 while (!gtk_text_iter_ends_line(&iter)) {
3135 wc = gtk_text_iter_get_char(&iter);
3136 if (g_unichar_iswide(wc))
3138 clen = g_unichar_to_utf8(wc, ch);
3142 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3143 is_space = g_unichar_isspace(wc);
3145 if (state == WAIT_FOR_INDENT_CHAR) {
3146 if (!is_indent && !g_unichar_isalnum(wc))
3149 quote_len += alnum_count + space_count + 1;
3150 alnum_count = space_count = 0;
3151 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3154 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3155 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3159 else if (is_indent) {
3160 quote_len += alnum_count + space_count + 1;
3161 alnum_count = space_count = 0;
3164 state = WAIT_FOR_INDENT_CHAR;
3168 gtk_text_iter_forward_char(&iter);
3171 if (quote_len > 0 && space_count > 0)
3177 if (quote_len > 0) {
3179 gtk_text_iter_forward_chars(&iter, quote_len);
3180 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3186 /* return TRUE if the line is itemized */
3187 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3188 const GtkTextIter *start)
3190 GtkTextIter iter = *start;
3195 if (gtk_text_iter_ends_line(&iter))
3199 wc = gtk_text_iter_get_char(&iter);
3200 if (!g_unichar_isspace(wc))
3202 gtk_text_iter_forward_char(&iter);
3203 if (gtk_text_iter_ends_line(&iter))
3207 clen = g_unichar_to_utf8(wc, ch);
3211 if (!strchr("*-+", ch[0]))
3214 gtk_text_iter_forward_char(&iter);
3215 if (gtk_text_iter_ends_line(&iter))
3217 wc = gtk_text_iter_get_char(&iter);
3218 if (g_unichar_isspace(wc))
3224 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3225 const GtkTextIter *start,
3226 GtkTextIter *break_pos,
3230 GtkTextIter iter = *start, line_end = *start;
3231 PangoLogAttr *attrs;
3238 gboolean can_break = FALSE;
3239 gboolean do_break = FALSE;
3240 gboolean was_white = FALSE;
3241 gboolean prev_dont_break = FALSE;
3243 gtk_text_iter_forward_to_line_end(&line_end);
3244 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3245 len = g_utf8_strlen(str, -1);
3246 /* g_print("breaking line: %d: %s (len = %d)\n",
3247 gtk_text_iter_get_line(&iter), str, len); */
3248 attrs = g_new(PangoLogAttr, len + 1);
3250 pango_default_break(str, -1, NULL, attrs, len + 1);
3254 /* skip quote and leading spaces */
3255 for (i = 0; *p != '\0' && i < len; i++) {
3258 wc = g_utf8_get_char(p);
3259 if (i >= quote_len && !g_unichar_isspace(wc))
3261 if (g_unichar_iswide(wc))
3263 else if (*p == '\t')
3267 p = g_utf8_next_char(p);
3270 for (; *p != '\0' && i < len; i++) {
3271 PangoLogAttr *attr = attrs + i;
3275 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3278 was_white = attr->is_white;
3280 /* don't wrap URI */
3281 if ((uri_len = get_uri_len(p)) > 0) {
3283 if (pos > 0 && col > max_col) {
3293 wc = g_utf8_get_char(p);
3294 if (g_unichar_iswide(wc)) {
3296 if (prev_dont_break && can_break && attr->is_line_break)
3298 } else if (*p == '\t')
3302 if (pos > 0 && col > max_col) {
3307 if (*p == '-' || *p == '/')
3308 prev_dont_break = TRUE;
3310 prev_dont_break = FALSE;
3312 p = g_utf8_next_char(p);
3316 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3321 *break_pos = *start;
3322 gtk_text_iter_set_line_offset(break_pos, pos);
3327 static gboolean compose_join_next_line(Compose *compose,
3328 GtkTextBuffer *buffer,
3330 const gchar *quote_str)
3332 GtkTextIter iter_ = *iter, cur, prev, next, end;
3333 PangoLogAttr attrs[3];
3335 gchar *next_quote_str;
3338 gboolean keep_cursor = FALSE;
3340 if (!gtk_text_iter_forward_line(&iter_) ||
3341 gtk_text_iter_ends_line(&iter_))
3344 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3346 if ((quote_str || next_quote_str) &&
3347 strcmp2(quote_str, next_quote_str) != 0) {
3348 g_free(next_quote_str);
3351 g_free(next_quote_str);
3354 if (quote_len > 0) {
3355 gtk_text_iter_forward_chars(&end, quote_len);
3356 if (gtk_text_iter_ends_line(&end))
3360 /* don't join itemized lines */
3361 if (compose_is_itemized(buffer, &end))
3364 /* don't join signature separator */
3365 if (compose_is_sig_separator(compose, buffer, &iter_))
3368 /* delete quote str */
3370 gtk_text_buffer_delete(buffer, &iter_, &end);
3372 /* don't join line breaks put by the user */
3374 gtk_text_iter_backward_char(&cur);
3375 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3376 gtk_text_iter_forward_char(&cur);
3380 gtk_text_iter_forward_char(&cur);
3381 /* delete linebreak and extra spaces */
3382 while (gtk_text_iter_backward_char(&cur)) {
3383 wc1 = gtk_text_iter_get_char(&cur);
3384 if (!g_unichar_isspace(wc1))
3389 while (!gtk_text_iter_ends_line(&cur)) {
3390 wc1 = gtk_text_iter_get_char(&cur);
3391 if (!g_unichar_isspace(wc1))
3393 gtk_text_iter_forward_char(&cur);
3396 if (!gtk_text_iter_equal(&prev, &next)) {
3399 mark = gtk_text_buffer_get_insert(buffer);
3400 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3401 if (gtk_text_iter_equal(&prev, &cur))
3403 gtk_text_buffer_delete(buffer, &prev, &next);
3407 /* insert space if required */
3408 gtk_text_iter_backward_char(&prev);
3409 wc1 = gtk_text_iter_get_char(&prev);
3410 wc2 = gtk_text_iter_get_char(&next);
3411 gtk_text_iter_forward_char(&next);
3412 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3413 pango_default_break(str, -1, NULL, attrs, 3);
3414 if (!attrs[1].is_line_break ||
3415 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3416 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3418 gtk_text_iter_backward_char(&iter_);
3419 gtk_text_buffer_place_cursor(buffer, &iter_);
3428 #define ADD_TXT_POS(bp_, ep_, pti_) \
3429 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3430 last = last->next; \
3431 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3432 last->next = NULL; \
3434 g_warning("alloc error scanning URIs\n"); \
3437 static gboolean automatic_break = FALSE;
3438 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3440 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3441 GtkTextBuffer *buffer;
3442 GtkTextIter iter, break_pos, end_of_line;
3443 gchar *quote_str = NULL;
3445 gboolean wrap_quote = prefs_common.linewrap_quote;
3446 gboolean prev_autowrap = compose->autowrap;
3447 gint startq_offset = -1, noq_offset = -1;
3448 gint uri_start = -1, uri_stop = -1;
3449 gint nouri_start = -1, nouri_stop = -1;
3450 gint num_blocks = 0;
3451 gint quotelevel = -1;
3453 compose->autowrap = FALSE;
3455 buffer = gtk_text_view_get_buffer(text);
3456 undo_wrapping(compose->undostruct, TRUE);
3461 mark = gtk_text_buffer_get_insert(buffer);
3462 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3465 /* move to paragraph start */
3466 gtk_text_iter_set_line_offset(&iter, 0);
3467 if (gtk_text_iter_ends_line(&iter)) {
3468 while (gtk_text_iter_ends_line(&iter) &&
3469 gtk_text_iter_forward_line(&iter))
3472 while (gtk_text_iter_backward_line(&iter)) {
3473 if (gtk_text_iter_ends_line(&iter)) {
3474 gtk_text_iter_forward_line(&iter);
3480 /* go until paragraph end (empty line) */
3482 while (!gtk_text_iter_ends_line(&iter)) {
3483 gchar *scanpos = NULL;
3484 /* parse table - in order of priority */
3486 const gchar *needle; /* token */
3488 /* token search function */
3489 gchar *(*search) (const gchar *haystack,
3490 const gchar *needle);
3491 /* part parsing function */
3492 gboolean (*parse) (const gchar *start,
3493 const gchar *scanpos,
3497 /* part to URI function */
3498 gchar *(*build_uri) (const gchar *bp,
3502 static struct table parser[] = {
3503 {"http://", strcasestr, get_uri_part, make_uri_string},
3504 {"https://", strcasestr, get_uri_part, make_uri_string},
3505 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3506 {"www.", strcasestr, get_uri_part, make_http_string},
3507 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3508 {"@", strcasestr, get_email_part, make_email_string}
3510 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3511 gint last_index = PARSE_ELEMS;
3513 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3516 if (!prev_autowrap && num_blocks == 0) {
3518 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3519 G_CALLBACK(text_inserted),
3522 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3525 uri_start = uri_stop = -1;
3527 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3531 if (startq_offset == -1) {
3532 startq_offset = gtk_text_iter_get_offset(&iter);
3536 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3537 if (startq_offset == -1)
3538 startq_offset = gtk_text_iter_get_offset(&iter);
3539 quotelevel = get_quote_level(quote_str, prefs_common.quote_chars);
3540 if (quotelevel > 2) {
3541 /* recycle colors */
3542 if (prefs_common.recycle_quote_colors)
3548 if (startq_offset == -1)
3549 noq_offset = gtk_text_iter_get_offset(&iter);
3553 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3556 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3557 prefs_common.linewrap_len,
3559 GtkTextIter prev, next, cur;
3561 if (prev_autowrap != FALSE || force) {
3562 automatic_break = TRUE;
3563 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3564 automatic_break = FALSE;
3565 } else if (quote_str && wrap_quote) {
3566 automatic_break = TRUE;
3567 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3568 automatic_break = FALSE;
3571 /* remove trailing spaces */
3573 gtk_text_iter_backward_char(&cur);
3575 while (!gtk_text_iter_starts_line(&cur)) {
3578 gtk_text_iter_backward_char(&cur);
3579 wc = gtk_text_iter_get_char(&cur);
3580 if (!g_unichar_isspace(wc))
3584 if (!gtk_text_iter_equal(&prev, &next)) {
3585 gtk_text_buffer_delete(buffer, &prev, &next);
3587 gtk_text_iter_forward_char(&break_pos);
3591 gtk_text_buffer_insert(buffer, &break_pos,
3595 compose_join_next_line(compose, buffer, &iter, quote_str);
3597 /* move iter to current line start */
3598 gtk_text_iter_set_line_offset(&iter, 0);
3605 /* move iter to next line start */
3610 if (!prev_autowrap && num_blocks > 0) {
3612 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3613 G_CALLBACK(text_inserted),
3617 while (!gtk_text_iter_ends_line(&end_of_line)) {
3618 gtk_text_iter_forward_char(&end_of_line);
3620 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3622 nouri_start = gtk_text_iter_get_offset(&iter);
3623 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3625 walk_pos = gtk_text_iter_get_offset(&iter);
3626 /* FIXME: this looks phony. scanning for anything in the parse table */
3627 for (n = 0; n < PARSE_ELEMS; n++) {
3630 tmp = parser[n].search(walk, parser[n].needle);
3632 if (scanpos == NULL || tmp < scanpos) {
3641 /* check if URI can be parsed */
3642 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3643 (const gchar **)&ep, FALSE)
3644 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3648 strlen(parser[last_index].needle);
3651 uri_start = walk_pos + (bp - o_walk);
3652 uri_stop = walk_pos + (ep - o_walk);
3656 gtk_text_iter_forward_line(&iter);
3659 if (startq_offset != -1) {
3660 GtkTextIter startquote, endquote;
3661 gtk_text_buffer_get_iter_at_offset(
3662 buffer, &startquote, startq_offset);
3664 switch (quotelevel) {
3665 case 0: gtk_text_buffer_apply_tag_by_name(
3666 buffer, "quote0", &startquote, &endquote);
3668 case 1: gtk_text_buffer_apply_tag_by_name(
3669 buffer, "quote1", &startquote, &endquote);
3671 case 2: gtk_text_buffer_apply_tag_by_name(
3672 buffer, "quote2", &startquote, &endquote);
3676 } else if (noq_offset != -1) {
3677 GtkTextIter startnoquote, endnoquote;
3678 gtk_text_buffer_get_iter_at_offset(
3679 buffer, &startnoquote, noq_offset);
3681 gtk_text_buffer_remove_tag_by_name(
3682 buffer, "quote0", &startnoquote, &endnoquote);
3683 gtk_text_buffer_remove_tag_by_name(
3684 buffer, "quote1", &startnoquote, &endnoquote);
3685 gtk_text_buffer_remove_tag_by_name(
3686 buffer, "quote2", &startnoquote, &endnoquote);
3691 GtkTextIter nouri_start_iter, nouri_end_iter;
3692 gtk_text_buffer_get_iter_at_offset(
3693 buffer, &nouri_start_iter, nouri_start);
3694 gtk_text_buffer_get_iter_at_offset(
3695 buffer, &nouri_end_iter, nouri_stop);
3696 gtk_text_buffer_remove_tag_by_name(
3697 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3699 if (uri_start > 0 && uri_stop > 0) {
3700 GtkTextIter uri_start_iter, uri_end_iter;
3701 gtk_text_buffer_get_iter_at_offset(
3702 buffer, &uri_start_iter, uri_start);
3703 gtk_text_buffer_get_iter_at_offset(
3704 buffer, &uri_end_iter, uri_stop);
3705 gtk_text_buffer_apply_tag_by_name(
3706 buffer, "link", &uri_start_iter, &uri_end_iter);
3712 undo_wrapping(compose->undostruct, FALSE);
3713 compose->autowrap = prev_autowrap;
3716 void compose_action_cb(void *data)
3718 Compose *compose = (Compose *)data;
3719 compose_wrap_all(compose);
3722 static void compose_wrap_all(Compose *compose)
3724 compose_wrap_all_full(compose, FALSE);
3727 static void compose_wrap_all_full(Compose *compose, gboolean force)
3729 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3730 GtkTextBuffer *buffer;
3733 buffer = gtk_text_view_get_buffer(text);
3735 gtk_text_buffer_get_start_iter(buffer, &iter);
3736 while (!gtk_text_iter_is_end(&iter))
3737 compose_beautify_paragraph(compose, &iter, force);
3741 static void compose_set_title(Compose *compose)
3747 edited = compose->modified ? _(" [Edited]") : "";
3749 subject = gtk_editable_get_chars(
3750 GTK_EDITABLE(compose->subject_entry), 0, -1);
3752 if (subject && strlen(subject))
3753 str = g_strdup_printf(_("%s - Compose message%s"),
3756 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3757 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3763 * compose_current_mail_account:
3765 * Find a current mail account (the currently selected account, or the
3766 * default account, if a news account is currently selected). If a
3767 * mail account cannot be found, display an error message.
3769 * Return value: Mail account, or NULL if not found.
3771 static PrefsAccount *
3772 compose_current_mail_account(void)
3776 if (cur_account && cur_account->protocol != A_NNTP)
3779 ac = account_get_default();
3780 if (!ac || ac->protocol == A_NNTP) {
3781 alertpanel_error(_("Account for sending mail is not specified.\n"
3782 "Please select a mail account before sending."));
3789 #define QUOTE_IF_REQUIRED(out, str) \
3791 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3795 len = strlen(str) + 3; \
3796 if ((__tmp = alloca(len)) == NULL) { \
3797 g_warning("can't allocate memory\n"); \
3798 g_string_free(header, TRUE); \
3801 g_snprintf(__tmp, len, "\"%s\"", str); \
3806 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3807 g_warning("can't allocate memory\n"); \
3808 g_string_free(header, TRUE); \
3811 strcpy(__tmp, str); \
3817 #define QUOTE_IF_REQUIRED_NORMAL(out, str, errret) \
3819 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3823 len = strlen(str) + 3; \
3824 if ((__tmp = alloca(len)) == NULL) { \
3825 g_warning("can't allocate memory\n"); \
3828 g_snprintf(__tmp, len, "\"%s\"", str); \
3833 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3834 g_warning("can't allocate memory\n"); \
3837 strcpy(__tmp, str); \
3843 static void compose_select_account(Compose *compose, PrefsAccount *account,
3846 GtkItemFactory *ifactory;
3849 g_return_if_fail(account != NULL);
3851 compose->account = account;
3853 if (account->name && *account->name) {
3855 QUOTE_IF_REQUIRED_NORMAL(buf, account->name, return);
3856 from = g_strdup_printf("%s <%s>",
3857 buf, account->address);
3858 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
3860 from = g_strdup_printf("<%s>",
3862 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
3867 compose_set_title(compose);
3869 ifactory = gtk_item_factory_from_widget(compose->menubar);
3871 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3872 menu_set_active(ifactory, "/Options/Sign", TRUE);
3874 menu_set_active(ifactory, "/Options/Sign", FALSE);
3875 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3876 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3878 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3880 activate_privacy_system(compose, account, FALSE);
3882 if (!init && compose->mode != COMPOSE_REDIRECT)
3883 compose_insert_sig(compose, TRUE);
3886 gboolean compose_check_for_valid_recipient(Compose *compose) {
3887 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3888 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3889 gboolean recipient_found = FALSE;
3893 /* free to and newsgroup list */
3894 slist_free_strings(compose->to_list);
3895 g_slist_free(compose->to_list);
3896 compose->to_list = NULL;
3898 slist_free_strings(compose->newsgroup_list);
3899 g_slist_free(compose->newsgroup_list);
3900 compose->newsgroup_list = NULL;
3902 /* search header entries for to and newsgroup entries */
3903 for (list = compose->header_list; list; list = list->next) {
3906 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3907 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3909 if (entry[0] != '\0') {
3910 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3911 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3912 compose->to_list = address_list_append(compose->to_list, entry);
3913 recipient_found = TRUE;
3916 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3917 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3918 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3919 recipient_found = TRUE;
3926 return recipient_found;
3929 static gboolean compose_check_for_set_recipients(Compose *compose)
3931 if (compose->account->set_autocc && compose->account->auto_cc) {
3932 gboolean found_other = FALSE;
3934 /* search header entries for to and newsgroup entries */
3935 for (list = compose->header_list; list; list = list->next) {
3938 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3939 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3941 if (strcmp(entry, compose->account->auto_cc)
3942 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3952 aval = alertpanel(_("Send"),
3953 _("The only recipient is the default CC address. Send anyway?"),
3954 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3955 if (aval != G_ALERTALTERNATE)
3959 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3960 gboolean found_other = FALSE;
3962 /* search header entries for to and newsgroup entries */
3963 for (list = compose->header_list; list; list = list->next) {
3966 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3967 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3969 if (strcmp(entry, compose->account->auto_cc)
3970 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3980 aval = alertpanel(_("Send"),
3981 _("The only recipient is the default BCC address. Send anyway?"),
3982 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3983 if (aval != G_ALERTALTERNATE)
3990 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3994 if (compose_check_for_valid_recipient(compose) == FALSE) {
3995 alertpanel_error(_("Recipient is not specified."));
3999 if (compose_check_for_set_recipients(compose) == FALSE) {
4003 if (!compose->batch) {
4004 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4005 if (*str == '\0' && check_subject == TRUE) {
4008 aval = alertpanel(_("Send"),
4009 _("Subject is empty. Send it anyway?"),
4010 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4011 if (aval != G_ALERTALTERNATE)
4019 gint compose_send(Compose *compose)
4024 gchar *msgpath = NULL;
4025 gboolean discard_window = FALSE;
4027 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS
4028 || compose->batch == TRUE)
4029 discard_window = TRUE;
4031 compose_allow_user_actions (compose, FALSE);
4032 compose->sending = TRUE;
4034 if (compose_check_entries(compose, TRUE) == FALSE) {
4035 if (compose->batch) {
4036 gtk_widget_show_all(compose->window);
4041 val = compose_queue(compose, &msgnum, &folder, &msgpath);
4044 if (compose->batch) {
4045 gtk_widget_show_all(compose->window);
4048 alertpanel_error(_("Could not queue message for sending:\n\n"
4049 "Charset conversion failed."));
4050 } else if (val == -3) {
4051 alertpanel_error(_("Could not queue message for sending:\n\n"
4052 "Signature failed."));
4053 } else if (val == -2 && errno != 0) {
4054 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
4056 alertpanel_error(_("Could not queue message for sending."));
4061 if (discard_window) {
4062 compose->sending = FALSE;
4063 compose_close(compose);
4064 /* No more compose access in the normal codepath
4065 * after this point! */
4070 alertpanel_error(_("The message was queued but could not be "
4071 "sent.\nUse \"Send queued messages\" from "
4072 "the main window to retry."));
4073 if (!discard_window) {
4079 if (msgpath == NULL) {
4080 msgpath = folder_item_fetch_msg(folder, msgnum);
4081 val = procmsg_send_message_queue(msgpath);
4084 val = procmsg_send_message_queue(msgpath);
4088 if (!discard_window) {
4089 compose->sending = FALSE;
4090 compose_allow_user_actions (compose, TRUE);
4092 folder_item_remove_msg(folder, msgnum);
4093 folder_item_scan(folder);
4098 folder_item_remove_msg(folder, msgnum);
4099 folder_item_scan(folder);
4100 if (!discard_window)
4101 compose_close(compose);
4103 alertpanel_error(_("The message was queued but could not be "
4104 "sent.\nUse \"Send queued messages\" from "
4105 "the main window to retry."));
4106 if (!discard_window) {
4115 compose_allow_user_actions (compose, TRUE);
4116 compose->sending = FALSE;
4117 compose->modified = TRUE;
4122 static gboolean compose_use_attach(Compose *compose)
4124 GtkTreeModel *model = gtk_tree_view_get_model
4125 (GTK_TREE_VIEW(compose->attach_clist));
4126 return gtk_tree_model_iter_n_children(model, NULL) > 0;
4129 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
4132 gchar buf[BUFFSIZE];
4134 gboolean first_to_address;
4135 gboolean first_cc_address;
4137 ComposeHeaderEntry *headerentry;
4138 const gchar *headerentryname;
4142 debug_print("Writing redirect header\n");
4144 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
4145 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
4147 first_to_address = TRUE;
4148 for (list = compose->header_list; list; list = list->next) {
4149 headerentry = ((ComposeHeaderEntry *)list->data);
4150 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4152 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
4153 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4154 Xstrdup_a(str, entstr, return -1);
4156 if (str[0] != '\0') {
4157 compose_convert_header
4158 (compose, buf, sizeof(buf), str,
4159 strlen("Resent-To") + 2, TRUE);
4161 if (first_to_address) {
4162 fprintf(fp, "Resent-To: ");
4163 first_to_address = FALSE;
4167 fprintf(fp, "%s", buf);
4171 if (!first_to_address) {
4175 first_cc_address = TRUE;
4176 for (list = compose->header_list; list; list = list->next) {
4177 headerentry = ((ComposeHeaderEntry *)list->data);
4178 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4180 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
4181 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4182 Xstrdup_a(str, strg, return -1);
4184 if (str[0] != '\0') {
4185 compose_convert_header
4186 (compose, buf, sizeof(buf), str,
4187 strlen("Resent-Cc") + 2, TRUE);
4189 if (first_cc_address) {
4190 fprintf(fp, "Resent-Cc: ");
4191 first_cc_address = FALSE;
4195 fprintf(fp, "%s", buf);
4199 if (!first_cc_address) {
4206 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
4208 gchar buf[BUFFSIZE];
4210 const gchar *entstr;
4211 /* struct utsname utsbuf; */
4213 g_return_val_if_fail(fp != NULL, -1);
4214 g_return_val_if_fail(compose->account != NULL, -1);
4215 g_return_val_if_fail(compose->account->address != NULL, -1);
4218 get_rfc822_date(buf, sizeof(buf));
4219 fprintf(fp, "Resent-Date: %s\n", buf);
4222 if (compose->account->name && *compose->account->name) {
4223 compose_convert_header
4224 (compose, buf, sizeof(buf), compose->account->name,
4225 strlen("From: "), TRUE);
4226 fprintf(fp, "Resent-From: %s <%s>\n",
4227 buf, compose->account->address);
4229 fprintf(fp, "Resent-From: %s\n", compose->account->address);
4232 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4233 if (*entstr != '\0') {
4234 Xstrdup_a(str, entstr, return -1);
4237 compose_convert_header(compose, buf, sizeof(buf), str,
4238 strlen("Subject: "), FALSE);
4239 fprintf(fp, "Subject: %s\n", buf);
4243 /* Resent-Message-ID */
4244 if (compose->account->gen_msgid) {
4245 generate_msgid(buf, sizeof(buf));
4246 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
4247 compose->msgid = g_strdup(buf);
4250 compose_redirect_write_headers_from_headerlist(compose, fp);
4252 /* separator between header and body */
4258 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
4262 gchar buf[BUFFSIZE];
4264 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
4265 FILE_OP_ERROR(compose->redirect_filename, "fopen");
4269 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
4270 /* should filter returnpath, delivered-to */
4271 if (g_ascii_strncasecmp(buf, "Return-Path:",
4272 strlen("Return-Path:")) == 0 ||
4273 g_ascii_strncasecmp(buf, "Delivered-To:",
4274 strlen("Delivered-To:")) == 0 ||
4275 g_ascii_strncasecmp(buf, "Received:",
4276 strlen("Received:")) == 0 ||
4277 g_ascii_strncasecmp(buf, "Subject:",
4278 strlen("Subject:")) == 0 ||
4279 g_ascii_strncasecmp(buf, "X-UIDL:",
4280 strlen("X-UIDL:")) == 0)
4283 if (fputs(buf, fdest) == -1)
4286 if (!prefs_common.redirect_keep_from) {
4287 if (g_ascii_strncasecmp(buf, "From:",
4288 strlen("From:")) == 0) {
4289 fputs(" (by way of ", fdest);
4290 if (compose->account->name
4291 && *compose->account->name) {
4292 compose_convert_header
4293 (compose, buf, sizeof(buf),
4294 compose->account->name,
4297 fprintf(fdest, "%s <%s>",
4299 compose->account->address);
4301 fprintf(fdest, "%s",
4302 compose->account->address);
4307 if (fputs("\n", fdest) == -1)
4311 compose_redirect_write_headers(compose, fdest);
4313 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4314 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4327 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
4329 GtkTextBuffer *buffer;
4330 GtkTextIter start, end;
4333 const gchar *out_codeset;
4334 EncodingType encoding;
4335 MimeInfo *mimemsg, *mimetext;
4338 /* create message MimeInfo */
4339 mimemsg = procmime_mimeinfo_new();
4340 mimemsg->type = MIMETYPE_MESSAGE;
4341 mimemsg->subtype = g_strdup("rfc822");
4342 mimemsg->content = MIMECONTENT_MEM;
4343 mimemsg->tmp = TRUE; /* must free content later */
4344 mimemsg->data.mem = compose_get_header(compose);
4346 /* Create text part MimeInfo */
4347 /* get all composed text */
4348 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4349 gtk_text_buffer_get_start_iter(buffer, &start);
4350 gtk_text_buffer_get_end_iter(buffer, &end);
4351 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4352 if (is_ascii_str(chars)) {
4355 out_codeset = CS_US_ASCII;
4356 encoding = ENC_7BIT;
4358 const gchar *src_codeset = CS_INTERNAL;
4360 out_codeset = conv_get_charset_str(compose->out_encoding);
4363 gchar *test_conv_global_out = NULL;
4364 gchar *test_conv_reply = NULL;
4366 /* automatic mode. be automatic. */
4367 codeconv_set_strict(TRUE);
4369 out_codeset = conv_get_outgoing_charset_str();
4371 debug_print("trying to convert to %s\n", out_codeset);
4372 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4375 if (!test_conv_global_out && compose->orig_charset
4376 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4377 out_codeset = compose->orig_charset;
4378 debug_print("failure; trying to convert to %s\n", out_codeset);
4379 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4382 if (!test_conv_global_out && !test_conv_reply) {
4384 out_codeset = CS_INTERNAL;
4385 debug_print("failure; finally using %s\n", out_codeset);
4387 g_free(test_conv_global_out);
4388 g_free(test_conv_reply);
4389 codeconv_set_strict(FALSE);
4392 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4393 out_codeset = CS_ISO_8859_1;
4395 if (prefs_common.encoding_method == CTE_BASE64)
4396 encoding = ENC_BASE64;
4397 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4398 encoding = ENC_QUOTED_PRINTABLE;
4399 else if (prefs_common.encoding_method == CTE_8BIT)
4400 encoding = ENC_8BIT;
4402 encoding = procmime_get_encoding_for_charset(out_codeset);
4404 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4405 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4407 if (action == COMPOSE_WRITE_FOR_SEND) {
4408 codeconv_set_strict(TRUE);
4409 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4410 codeconv_set_strict(FALSE);
4416 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4417 "to the specified %s charset.\n"
4418 "Send it as %s?"), out_codeset, src_codeset);
4419 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4420 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4423 if (aval != G_ALERTALTERNATE) {
4428 out_codeset = src_codeset;
4434 out_codeset = src_codeset;
4440 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4441 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4442 strstr(buf, "\nFrom ") != NULL) {
4443 encoding = ENC_QUOTED_PRINTABLE;
4447 mimetext = procmime_mimeinfo_new();
4448 mimetext->content = MIMECONTENT_MEM;
4449 mimetext->tmp = TRUE; /* must free content later */
4450 mimetext->data.mem = buf;
4451 mimetext->type = MIMETYPE_TEXT;
4452 mimetext->subtype = g_strdup("plain");
4453 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4454 g_strdup(out_codeset));
4455 /* protect trailing spaces when signing message */
4456 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4457 privacy_system_can_sign(compose->privacy_system)) {
4458 encoding = ENC_QUOTED_PRINTABLE;
4461 /* check for line length limit */
4462 if (action == COMPOSE_WRITE_FOR_SEND &&
4463 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4464 check_line_length(buf, 1000, &line) < 0) {
4468 msg = g_strdup_printf
4469 (_("Line %d exceeds the line length limit (998 bytes).\n"
4470 "The contents of the message might be broken on the way to the delivery.\n"
4472 "Send it anyway?"), line + 1);
4473 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4475 if (aval != G_ALERTALTERNATE) {
4480 if (encoding != ENC_UNKNOWN)
4481 procmime_encode_content(mimetext, encoding);
4483 /* append attachment parts */
4484 if (compose_use_attach(compose)) {
4485 MimeInfo *mimempart;
4486 gchar *boundary = NULL;
4487 mimempart = procmime_mimeinfo_new();
4488 mimempart->content = MIMECONTENT_EMPTY;
4489 mimempart->type = MIMETYPE_MULTIPART;
4490 mimempart->subtype = g_strdup("mixed");
4494 boundary = generate_mime_boundary(NULL);
4495 } while (strstr(buf, boundary) != NULL);
4497 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4500 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4502 g_node_append(mimempart->node, mimetext->node);
4503 g_node_append(mimemsg->node, mimempart->node);
4505 compose_add_attachments(compose, mimempart);
4507 g_node_append(mimemsg->node, mimetext->node);
4509 /* sign message if sending */
4510 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4511 privacy_system_can_sign(compose->privacy_system))
4512 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4515 procmime_write_mimeinfo(mimemsg, fp);
4517 procmime_mimeinfo_free_all(mimemsg);
4522 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4524 GtkTextBuffer *buffer;
4525 GtkTextIter start, end;
4530 if ((fp = g_fopen(file, "wb")) == NULL) {
4531 FILE_OP_ERROR(file, "fopen");
4535 /* chmod for security */
4536 if (change_file_mode_rw(fp, file) < 0) {
4537 FILE_OP_ERROR(file, "chmod");
4538 g_warning("can't change file mode\n");
4541 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4542 gtk_text_buffer_get_start_iter(buffer, &start);
4543 gtk_text_buffer_get_end_iter(buffer, &end);
4544 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4546 chars = conv_codeset_strdup
4547 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4550 if (!chars) return -1;
4553 len = strlen(chars);
4554 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4555 FILE_OP_ERROR(file, "fwrite");
4564 if (fclose(fp) == EOF) {
4565 FILE_OP_ERROR(file, "fclose");
4572 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4575 MsgInfo *msginfo = compose->targetinfo;
4577 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4578 if (!msginfo) return -1;
4580 if (!force && MSG_IS_LOCKED(msginfo->flags))
4583 item = msginfo->folder;
4584 g_return_val_if_fail(item != NULL, -1);
4586 if (procmsg_msg_exist(msginfo) &&
4587 (folder_has_parent_of_type(item, F_QUEUE) ||
4588 folder_has_parent_of_type(item, F_DRAFT)
4589 || msginfo == compose->autosaved_draft)) {
4590 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4591 g_warning("can't remove the old message\n");
4599 void compose_remove_draft(Compose *compose)
4602 MsgInfo *msginfo = compose->targetinfo;
4603 drafts = account_get_special_folder(compose->account, F_DRAFT);
4605 if (procmsg_msg_exist(msginfo)) {
4606 folder_item_remove_msg(drafts, msginfo->msgnum);
4611 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath)
4613 return compose_queue_sub (compose, msgnum, item, msgpath, FALSE);
4615 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath, gboolean check_subject)
4622 static gboolean lock = FALSE;
4623 PrefsAccount *mailac = NULL, *newsac = NULL;
4625 debug_print("queueing message...\n");
4626 g_return_val_if_fail(compose->account != NULL, -1);
4630 if (compose_check_entries(compose, check_subject) == FALSE) {
4635 if (!compose->to_list && !compose->newsgroup_list) {
4636 g_warning("can't get recipient list.");
4641 if (compose->to_list) {
4642 if (compose->account->protocol != A_NNTP)
4643 mailac = compose->account;
4644 else if (cur_account && cur_account->protocol != A_NNTP)
4645 mailac = cur_account;
4646 else if (!(mailac = compose_current_mail_account())) {
4648 alertpanel_error(_("No account for sending mails available!"));
4653 if (compose->newsgroup_list) {
4654 if (compose->account->protocol == A_NNTP)
4655 newsac = compose->account;
4656 else if (!newsac->protocol != A_NNTP) {
4658 alertpanel_error(_("No account for posting news available!"));
4663 /* write queue header */
4664 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4665 G_DIR_SEPARATOR, compose);
4666 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4667 FILE_OP_ERROR(tmp, "fopen");
4672 if (change_file_mode_rw(fp, tmp) < 0) {
4673 FILE_OP_ERROR(tmp, "chmod");
4674 g_warning("can't change file mode\n");
4677 /* queueing variables */
4678 fprintf(fp, "AF:\n");
4679 fprintf(fp, "NF:0\n");
4680 fprintf(fp, "PS:10\n");
4681 fprintf(fp, "SRH:1\n");
4682 fprintf(fp, "SFN:\n");
4683 fprintf(fp, "DSR:\n");
4685 fprintf(fp, "MID:<%s>\n", compose->msgid);
4687 fprintf(fp, "MID:\n");
4688 fprintf(fp, "CFG:\n");
4689 fprintf(fp, "PT:0\n");
4690 fprintf(fp, "S:%s\n", compose->account->address);
4691 fprintf(fp, "RQ:\n");
4693 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4695 fprintf(fp, "SSV:\n");
4697 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4699 fprintf(fp, "NSV:\n");
4700 fprintf(fp, "SSH:\n");
4701 /* write recepient list */
4702 if (compose->to_list) {
4703 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4704 for (cur = compose->to_list->next; cur != NULL;
4706 fprintf(fp, ",<%s>", (gchar *)cur->data);
4709 /* write newsgroup list */
4710 if (compose->newsgroup_list) {
4712 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4713 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4714 fprintf(fp, ",%s", (gchar *)cur->data);
4717 /* Sylpheed account IDs */
4719 fprintf(fp, "MAID:%d\n", mailac->account_id);
4721 fprintf(fp, "NAID:%d\n", newsac->account_id);
4724 if (compose->privacy_system != NULL) {
4725 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4726 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4727 if (compose->use_encryption) {
4729 if (mailac && mailac->encrypt_to_self) {
4730 GSList *tmp_list = g_slist_copy(compose->to_list);
4731 tmp_list = g_slist_append(tmp_list, compose->account->address);
4732 encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
4733 g_slist_free(tmp_list);
4735 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4737 if (encdata != NULL) {
4738 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4739 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4740 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4742 } /* else we finally dont want to encrypt */
4744 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4745 /* and if encdata was null, it means there's been a problem in
4752 /* Save copy folder */
4753 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4754 gchar *savefolderid;
4756 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4757 fprintf(fp, "SCF:%s\n", savefolderid);
4758 g_free(savefolderid);
4760 /* Save copy folder */
4761 if (compose->return_receipt) {
4762 fprintf(fp, "RRCPT:1\n");
4764 /* Message-ID of message replying to */
4765 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4768 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4769 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4772 /* Message-ID of message forwarding to */
4773 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4776 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4777 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4782 if (compose->redirect_filename != NULL) {
4783 if (compose_redirect_write_to_file(compose, fp) < 0) {
4792 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4797 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4801 if (fclose(fp) == EOF) {
4802 FILE_OP_ERROR(tmp, "fclose");
4808 queue = account_get_special_folder(compose->account, F_QUEUE);
4810 g_warning("can't find queue folder\n");
4815 folder_item_scan(queue);
4816 if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
4817 g_warning("can't queue the message\n");
4823 if (msgpath == NULL) {
4829 if (compose->mode == COMPOSE_REEDIT) {
4830 compose_remove_reedit_target(compose, FALSE);
4833 if ((msgnum != NULL) && (item != NULL)) {
4841 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4844 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4846 struct stat statbuf;
4847 gchar *type, *subtype;
4848 GtkTreeModel *model;
4851 model = gtk_tree_view_get_model(tree_view);
4853 if (!gtk_tree_model_get_iter_first(model, &iter))
4856 gtk_tree_model_get(model, &iter,
4860 mimepart = procmime_mimeinfo_new();
4861 mimepart->content = MIMECONTENT_FILE;
4862 mimepart->data.filename = g_strdup(ainfo->file);
4863 mimepart->tmp = FALSE; /* or we destroy our attachment */
4864 mimepart->offset = 0;
4866 stat(ainfo->file, &statbuf);
4867 mimepart->length = statbuf.st_size;
4869 type = g_strdup(ainfo->content_type);
4871 if (!strchr(type, '/')) {
4873 type = g_strdup("application/octet-stream");
4876 subtype = strchr(type, '/') + 1;
4877 *(subtype - 1) = '\0';
4878 mimepart->type = procmime_get_media_type(type);
4879 mimepart->subtype = g_strdup(subtype);
4882 if (mimepart->type == MIMETYPE_MESSAGE &&
4883 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4884 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4886 g_hash_table_insert(mimepart->typeparameters,
4887 g_strdup("name"), g_strdup(ainfo->name));
4888 g_hash_table_insert(mimepart->dispositionparameters,
4889 g_strdup("filename"), g_strdup(ainfo->name));
4890 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4893 if (compose->use_signing) {
4894 if (ainfo->encoding == ENC_7BIT)
4895 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4896 else if (ainfo->encoding == ENC_8BIT)
4897 ainfo->encoding = ENC_BASE64;
4900 procmime_encode_content(mimepart, ainfo->encoding);
4902 g_node_append(parent->node, mimepart->node);
4903 } while (gtk_tree_model_iter_next(model, &iter));
4906 #define IS_IN_CUSTOM_HEADER(header) \
4907 (compose->account->add_customhdr && \
4908 custom_header_find(compose->account->customhdr_list, header) != NULL)
4910 static void compose_add_headerfield_from_headerlist(Compose *compose,
4912 const gchar *fieldname,
4913 const gchar *seperator)
4915 gchar *str, *fieldname_w_colon, *trans_fieldname;
4916 gboolean add_field = FALSE;
4918 ComposeHeaderEntry *headerentry;
4919 const gchar * headerentryname;
4922 if (IS_IN_CUSTOM_HEADER(fieldname))
4925 debug_print("Adding %s-fields\n", fieldname);
4927 fieldstr = g_string_sized_new(64);
4929 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4930 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4932 for (list = compose->header_list; list; list = list->next) {
4933 headerentry = ((ComposeHeaderEntry *)list->data);
4934 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4936 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4937 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4939 if (str[0] != '\0') {
4941 g_string_append(fieldstr, seperator);
4942 g_string_append(fieldstr, str);
4951 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4952 compose_convert_header
4953 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4954 strlen(fieldname) + 2, TRUE);
4955 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4959 g_free(fieldname_w_colon);
4960 g_string_free(fieldstr, TRUE);
4965 static gchar *compose_get_header(Compose *compose)
4967 gchar buf[BUFFSIZE];
4968 const gchar *entry_str;
4972 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4974 gchar *from_name = NULL, *from_address = NULL;
4977 g_return_val_if_fail(compose->account != NULL, NULL);
4978 g_return_val_if_fail(compose->account->address != NULL, NULL);
4980 header = g_string_sized_new(64);
4983 if (compose->account->add_date) {
4984 get_rfc822_date(buf, sizeof(buf));
4985 g_string_append_printf(header, "Date: %s\n", buf);
4990 if (compose->account->name && *compose->account->name) {
4992 QUOTE_IF_REQUIRED(buf, compose->account->name);
4993 tmp = g_strdup_printf("%s <%s>",
4994 buf, compose->account->address);
4996 tmp = g_strdup_printf("%s",
4997 compose->account->address);
4999 if (!strcmp(gtk_entry_get_text(GTK_ENTRY(compose->from_name)), tmp)
5000 || strlen(gtk_entry_get_text(GTK_ENTRY(compose->from_name))) == 0) {
5002 from_name = compose->account->name ? g_strdup(compose->account->name):NULL;
5003 from_address = g_strdup(compose->account->address);
5005 gchar *spec = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
5006 /* extract name and address */
5007 if (strstr(spec, " <") && strstr(spec, ">")) {
5008 from_address = g_strdup(strrchr(spec, '<')+1);
5009 *(strrchr(from_address, '>')) = '\0';
5010 from_name = g_strdup(spec);
5011 *(strrchr(from_name, '<')) = '\0';
5014 from_address = g_strdup(spec);
5021 if (from_name && *from_name) {
5022 compose_convert_header
5023 (compose, buf, sizeof(buf), from_name,
5024 strlen("From: "), TRUE);
5025 QUOTE_IF_REQUIRED(name, buf);
5027 g_string_append_printf(header, "From: %s <%s>\n",
5028 name, from_address);
5030 g_string_append_printf(header, "From: %s\n", from_address);
5033 g_free(from_address);
5036 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
5039 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
5042 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
5045 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
5048 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
5050 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
5053 compose_convert_header(compose, buf, sizeof(buf), str,
5054 strlen("Subject: "), FALSE);
5055 g_string_append_printf(header, "Subject: %s\n", buf);
5061 if (compose->account->gen_msgid) {
5062 generate_msgid(buf, sizeof(buf));
5063 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
5064 compose->msgid = g_strdup(buf);
5067 if (compose->remove_references == FALSE) {
5069 if (compose->inreplyto && compose->to_list)
5070 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
5073 if (compose->references)
5074 g_string_append_printf(header, "References: %s\n", compose->references);
5078 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
5081 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
5084 if (compose->account->organization &&
5085 strlen(compose->account->organization) &&
5086 !IS_IN_CUSTOM_HEADER("Organization")) {
5087 compose_convert_header(compose, buf, sizeof(buf),
5088 compose->account->organization,
5089 strlen("Organization: "), FALSE);
5090 g_string_append_printf(header, "Organization: %s\n", buf);
5093 /* Program version and system info */
5094 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
5095 !compose->newsgroup_list) {
5096 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
5098 gtk_major_version, gtk_minor_version, gtk_micro_version,
5101 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
5102 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
5104 gtk_major_version, gtk_minor_version, gtk_micro_version,
5108 /* custom headers */
5109 if (compose->account->add_customhdr) {
5112 for (cur = compose->account->customhdr_list; cur != NULL;
5114 CustomHeader *chdr = (CustomHeader *)cur->data;
5116 if (custom_header_is_allowed(chdr->name)) {
5117 compose_convert_header
5118 (compose, buf, sizeof(buf),
5119 chdr->value ? chdr->value : "",
5120 strlen(chdr->name) + 2, FALSE);
5121 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
5127 switch (compose->priority) {
5128 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
5129 "X-Priority: 1 (Highest)\n");
5131 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
5132 "X-Priority: 2 (High)\n");
5134 case PRIORITY_NORMAL: break;
5135 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
5136 "X-Priority: 4 (Low)\n");
5138 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
5139 "X-Priority: 5 (Lowest)\n");
5141 default: debug_print("compose: priority unknown : %d\n",
5145 /* Request Return Receipt */
5146 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
5147 if (compose->return_receipt) {
5148 if (compose->account->name
5149 && *compose->account->name) {
5150 compose_convert_header(compose, buf, sizeof(buf),
5151 compose->account->name,
5152 strlen("Disposition-Notification-To: "),
5154 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
5156 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
5160 /* get special headers */
5161 for (list = compose->header_list; list; list = list->next) {
5162 ComposeHeaderEntry *headerentry;
5165 gchar *headername_wcolon;
5166 gchar *headername_trans;
5169 gboolean standard_header = FALSE;
5171 headerentry = ((ComposeHeaderEntry *)list->data);
5173 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
5174 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
5179 if (!strstr(tmp, ":")) {
5180 headername_wcolon = g_strconcat(tmp, ":", NULL);
5181 headername = g_strdup(tmp);
5183 headername_wcolon = g_strdup(tmp);
5184 headername = g_strdup(strtok(tmp, ":"));
5188 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
5189 Xstrdup_a(headervalue, entry_str, return NULL);
5190 subst_char(headervalue, '\r', ' ');
5191 subst_char(headervalue, '\n', ' ');
5192 string = std_headers;
5193 while (*string != NULL) {
5194 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
5195 if (!strcmp(headername_trans,headername_wcolon))
5196 standard_header = TRUE;
5199 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
5200 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
5203 g_free(headername_wcolon);
5207 g_string_free(header, FALSE);
5212 #undef IS_IN_CUSTOM_HEADER
5214 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
5215 gint header_len, gboolean addr_field)
5217 gchar *tmpstr = NULL;
5218 const gchar *out_codeset = NULL;
5220 g_return_if_fail(src != NULL);
5221 g_return_if_fail(dest != NULL);
5223 if (len < 1) return;
5225 tmpstr = g_strdup(src);
5227 subst_char(tmpstr, '\n', ' ');
5228 subst_char(tmpstr, '\r', ' ');
5231 if (!g_utf8_validate(tmpstr, -1, NULL)) {
5232 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
5233 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
5238 codeconv_set_strict(TRUE);
5239 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5240 conv_get_charset_str(compose->out_encoding));
5241 codeconv_set_strict(FALSE);
5243 if (!dest || *dest == '\0') {
5244 gchar *test_conv_global_out = NULL;
5245 gchar *test_conv_reply = NULL;
5247 /* automatic mode. be automatic. */
5248 codeconv_set_strict(TRUE);
5250 out_codeset = conv_get_outgoing_charset_str();
5252 debug_print("trying to convert to %s\n", out_codeset);
5253 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5256 if (!test_conv_global_out && compose->orig_charset
5257 && strcmp(compose->orig_charset, CS_US_ASCII)) {
5258 out_codeset = compose->orig_charset;
5259 debug_print("failure; trying to convert to %s\n", out_codeset);
5260 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5263 if (!test_conv_global_out && !test_conv_reply) {
5265 out_codeset = CS_INTERNAL;
5266 debug_print("finally using %s\n", out_codeset);
5268 g_free(test_conv_global_out);
5269 g_free(test_conv_reply);
5270 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5272 codeconv_set_strict(FALSE);
5277 static void compose_create_header_entry(Compose *compose)
5279 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5283 GList *combo_list = NULL;
5285 const gchar *header = NULL;
5286 ComposeHeaderEntry *headerentry;
5287 gboolean standard_header = FALSE;
5289 headerentry = g_new0(ComposeHeaderEntry, 1);
5292 combo = gtk_combo_new();
5294 while(*string != NULL) {
5295 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
5298 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5299 g_list_free(combo_list);
5300 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5301 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5302 G_CALLBACK(compose_grab_focus_cb), compose);
5303 gtk_widget_show(combo);
5304 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5305 if (compose->header_last) {
5306 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5308 while (*string != NULL) {
5309 if (!strcmp(*string, last_header_entry))
5310 standard_header = TRUE;
5313 if (standard_header)
5314 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5316 if (!compose->header_last || !standard_header) {
5317 switch(compose->account->protocol) {
5319 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5322 header = prefs_common.trans_hdr ? _("To:") : "To:";
5327 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5329 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5330 G_CALLBACK(compose_grab_focus_cb), compose);
5333 entry = gtk_entry_new();
5334 gtk_widget_show(entry);
5335 gtk_tooltips_set_tip(compose->tooltips, entry,
5336 _("Use <tab> to autocomplete from addressbook"), NULL);
5337 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);
5339 g_signal_connect(G_OBJECT(entry), "key-press-event",
5340 G_CALLBACK(compose_headerentry_key_press_event_cb),
5342 g_signal_connect(G_OBJECT(entry), "changed",
5343 G_CALLBACK(compose_headerentry_changed_cb),
5345 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5346 G_CALLBACK(compose_grab_focus_cb), compose);
5349 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5350 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5351 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5352 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5353 G_CALLBACK(compose_header_drag_received_cb),
5355 g_signal_connect(G_OBJECT(entry), "drag-drop",
5356 G_CALLBACK(compose_drag_drop),
5359 address_completion_register_entry(GTK_ENTRY(entry));
5361 headerentry->compose = compose;
5362 headerentry->combo = combo;
5363 headerentry->entry = entry;
5364 headerentry->headernum = compose->header_nextrow;
5366 compose->header_nextrow++;
5367 compose->header_last = headerentry;
5370 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5372 ComposeHeaderEntry *last_header;
5374 last_header = compose->header_last;
5376 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5377 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5380 static GtkWidget *compose_create_header(Compose *compose)
5382 GtkWidget *from_optmenu_hbox;
5383 GtkWidget *header_scrolledwin;
5384 GtkWidget *header_table;
5388 /* header labels and entries */
5389 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5390 gtk_widget_show(header_scrolledwin);
5391 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5393 header_table = gtk_table_new(2, 2, FALSE);
5394 gtk_widget_show(header_table);
5395 gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
5396 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5397 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5400 /* option menu for selecting accounts */
5401 from_optmenu_hbox = compose_account_option_menu_create(compose);
5402 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5403 0, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5406 compose->header_table = header_table;
5407 compose->header_list = NULL;
5408 compose->header_nextrow = count;
5410 compose_create_header_entry(compose);
5412 compose->table = NULL;
5414 return header_scrolledwin ;
5417 GtkWidget *compose_create_attach(Compose *compose)
5419 GtkWidget *attach_scrwin;
5420 GtkWidget *attach_clist;
5422 GtkListStore *store;
5423 GtkCellRenderer *renderer;
5424 GtkTreeViewColumn *column;
5425 GtkTreeSelection *selection;
5427 /* attachment list */
5428 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5429 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5430 GTK_POLICY_AUTOMATIC,
5431 GTK_POLICY_AUTOMATIC);
5432 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5434 store = gtk_list_store_new(N_ATTACH_COLS,
5439 G_TYPE_AUTO_POINTER,
5441 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5442 (GTK_TREE_MODEL(store)));
5443 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5444 g_object_unref(store);
5446 renderer = gtk_cell_renderer_text_new();
5447 column = gtk_tree_view_column_new_with_attributes
5448 (_("Mime type"), renderer, "text",
5449 COL_MIMETYPE, NULL);
5450 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5452 renderer = gtk_cell_renderer_text_new();
5453 column = gtk_tree_view_column_new_with_attributes
5454 (_("Size"), renderer, "text",
5456 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5458 renderer = gtk_cell_renderer_text_new();
5459 column = gtk_tree_view_column_new_with_attributes
5460 (_("Name"), renderer, "text",
5462 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5464 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5465 prefs_common.enable_rules_hint);
5466 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5467 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5469 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5470 G_CALLBACK(attach_selected), compose);
5471 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5472 G_CALLBACK(attach_button_pressed), compose);
5473 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5474 G_CALLBACK(attach_key_pressed), compose);
5477 gtk_drag_dest_set(attach_clist,
5478 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5479 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5480 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5481 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5482 G_CALLBACK(compose_attach_drag_received_cb),
5484 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5485 G_CALLBACK(compose_drag_drop),
5488 compose->attach_scrwin = attach_scrwin;
5489 compose->attach_clist = attach_clist;
5491 return attach_scrwin;
5494 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5495 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5497 static GtkWidget *compose_create_others(Compose *compose)
5500 GtkWidget *savemsg_checkbtn;
5501 GtkWidget *savemsg_entry;
5502 GtkWidget *savemsg_select;
5505 gchar *folderidentifier;
5507 /* Table for settings */
5508 table = gtk_table_new(3, 1, FALSE);
5509 gtk_container_set_border_width(GTK_CONTAINER(table), BORDER_WIDTH);
5510 gtk_widget_show(table);
5511 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5514 /* Save Message to folder */
5515 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5516 gtk_widget_show(savemsg_checkbtn);
5517 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5518 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5519 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5521 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5522 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5524 savemsg_entry = gtk_entry_new();
5525 gtk_widget_show(savemsg_entry);
5526 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5527 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5528 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5529 G_CALLBACK(compose_grab_focus_cb), compose);
5530 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5531 folderidentifier = folder_item_get_identifier(account_get_special_folder
5532 (compose->account, F_OUTBOX));
5533 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5534 g_free(folderidentifier);
5537 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5538 gtk_widget_show(savemsg_select);
5539 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5540 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5541 G_CALLBACK(compose_savemsg_select_cb),
5546 compose->savemsg_checkbtn = savemsg_checkbtn;
5547 compose->savemsg_entry = savemsg_entry;
5552 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5554 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5555 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5558 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5563 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5566 path = folder_item_get_identifier(dest);
5568 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5572 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5573 GdkAtom clip, GtkTextIter *insert_place);
5575 #define BLOCK_WRAP() { \
5576 prev_autowrap = compose->autowrap; \
5577 buffer = gtk_text_view_get_buffer( \
5578 GTK_TEXT_VIEW(compose->text)); \
5579 compose->autowrap = FALSE; \
5581 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5582 G_CALLBACK(compose_changed_cb), \
5584 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5585 G_CALLBACK(text_inserted), \
5588 #define UNBLOCK_WRAP() { \
5589 compose->autowrap = prev_autowrap; \
5590 if (compose->autowrap) \
5591 compose_wrap_all(compose); \
5593 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5594 G_CALLBACK(compose_changed_cb), \
5596 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5597 G_CALLBACK(text_inserted), \
5602 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5606 GtkTextBuffer *buffer;
5608 if (event->button == 3) {
5610 GtkTextIter sel_start, sel_end;
5611 gboolean stuff_selected;
5613 /* move the cursor to allow GtkAspell to check the word
5614 * under the mouse */
5615 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5616 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5618 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5621 stuff_selected = gtk_text_buffer_get_selection_bounds(
5622 GTK_TEXT_VIEW(text)->buffer,
5623 &sel_start, &sel_end);
5625 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5626 /* reselect stuff */
5628 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5629 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5630 &sel_start, &sel_end);
5632 return FALSE; /* pass the event so that the right-click goes through */
5635 if (event->button == 2) {
5640 /* get the middle-click position to paste at the correct place */
5641 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5642 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5644 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5647 entry_paste_clipboard(compose, text,
5648 prefs_common.linewrap_pastes,
5649 GDK_SELECTION_PRIMARY, &iter);
5657 static void compose_spell_menu_changed(void *data)
5659 Compose *compose = (Compose *)data;
5661 GtkWidget *menuitem;
5662 GtkWidget *parent_item;
5663 GtkMenu *menu = GTK_MENU(gtk_menu_new());
5664 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
5667 if (compose->gtkaspell == NULL)
5670 parent_item = gtk_item_factory_get_item(ifactory,
5671 "/Spelling/Options");
5673 /* setting the submenu removes /Spelling/Options from the factory
5674 * so we need to save it */
5676 if (parent_item == NULL) {
5677 parent_item = compose->aspell_options_menu;
5678 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(parent_item));
5680 compose->aspell_options_menu = parent_item;
5682 spell_menu = gtkaspell_make_config_menu(compose->gtkaspell);
5684 spell_menu = g_slist_reverse(spell_menu);
5685 for (items = spell_menu;
5686 items; items = items->next) {
5687 menuitem = GTK_WIDGET(GTK_MENU_ITEM(items->data));
5688 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), GTK_WIDGET(menuitem));
5689 gtk_widget_show(GTK_WIDGET(menuitem));
5691 g_slist_free(spell_menu);
5693 gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), GTK_WIDGET(menu));
5698 static gboolean compose_force_window_origin = TRUE;
5699 static Compose *compose_create(PrefsAccount *account, ComposeMode mode,
5706 GtkWidget *handlebox;
5708 GtkWidget *notebook;
5713 GtkWidget *subject_hbox;
5714 GtkWidget *subject_frame;
5715 GtkWidget *subject_entry;
5719 GtkWidget *edit_vbox;
5720 GtkWidget *ruler_hbox;
5722 GtkWidget *scrolledwin;
5724 GtkTextBuffer *buffer;
5725 GtkClipboard *clipboard;
5727 UndoMain *undostruct;
5729 gchar *titles[N_ATTACH_COLS];
5730 guint n_menu_entries;
5731 GtkWidget *popupmenu;
5732 GtkItemFactory *popupfactory;
5733 GtkItemFactory *ifactory;
5734 GtkWidget *tmpl_menu;
5736 GtkWidget *menuitem;
5739 GtkAspell * gtkaspell = NULL;
5742 static GdkGeometry geometry;
5744 g_return_val_if_fail(account != NULL, NULL);
5746 debug_print("Creating compose window...\n");
5747 compose = g_new0(Compose, 1);
5749 titles[COL_MIMETYPE] = _("MIME type");
5750 titles[COL_SIZE] = _("Size");
5751 titles[COL_NAME] = _("Name");
5753 compose->batch = batch;
5754 compose->account = account;
5756 compose->mutex = g_mutex_new();
5757 compose->set_cursor_pos = -1;
5759 compose->tooltips = gtk_tooltips_new();
5761 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5762 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5763 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5765 if (!geometry.max_width) {
5766 geometry.max_width = gdk_screen_width();
5767 geometry.max_height = gdk_screen_height();
5770 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5771 &geometry, GDK_HINT_MAX_SIZE);
5772 if (!geometry.min_width) {
5773 geometry.min_width = 600;
5774 geometry.min_height = 480;
5776 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5777 &geometry, GDK_HINT_MIN_SIZE);
5779 if (compose_force_window_origin)
5780 gtk_widget_set_uposition(window, prefs_common.compose_x,
5781 prefs_common.compose_y);
5783 g_signal_connect(G_OBJECT(window), "delete_event",
5784 G_CALLBACK(compose_delete_cb), compose);
5785 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5786 gtk_widget_realize(window);
5788 gtkut_widget_set_composer_icon(window);
5790 vbox = gtk_vbox_new(FALSE, 0);
5791 gtk_container_add(GTK_CONTAINER(window), vbox);
5793 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5794 menubar = menubar_create(window, compose_entries,
5795 n_menu_entries, "<Compose>", compose);
5796 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5798 if (prefs_common.toolbar_detachable) {
5799 handlebox = gtk_handle_box_new();
5801 handlebox = gtk_hbox_new(FALSE, 0);
5803 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5805 gtk_widget_realize(handlebox);
5806 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5809 vbox2 = gtk_vbox_new(FALSE, 2);
5810 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5811 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5814 notebook = gtk_notebook_new();
5815 gtk_widget_set_size_request(notebook, -1, 130);
5816 gtk_widget_show(notebook);
5818 /* header labels and entries */
5819 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5820 compose_create_header(compose),
5821 gtk_label_new_with_mnemonic(_("Hea_der")));
5822 /* attachment list */
5823 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5824 compose_create_attach(compose),
5825 gtk_label_new_with_mnemonic(_("_Attachments")));
5827 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5828 compose_create_others(compose),
5829 gtk_label_new_with_mnemonic(_("Othe_rs")));
5832 subject_hbox = gtk_hbox_new(FALSE, 0);
5833 gtk_widget_show(subject_hbox);
5835 subject_frame = gtk_frame_new(NULL);
5836 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5837 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5838 gtk_widget_show(subject_frame);
5840 subject = gtk_hbox_new(FALSE, 0);
5841 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5842 gtk_widget_show(subject);
5844 label = gtk_label_new(_("Subject:"));
5845 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5846 gtk_widget_show(label);
5848 subject_entry = gtk_entry_new();
5849 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5850 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5851 G_CALLBACK(compose_grab_focus_cb), compose);
5852 gtk_widget_show(subject_entry);
5853 compose->subject_entry = subject_entry;
5854 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5856 edit_vbox = gtk_vbox_new(FALSE, 0);
5858 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5861 ruler_hbox = gtk_hbox_new(FALSE, 0);
5862 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5864 ruler = gtk_shruler_new();
5865 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5866 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5870 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5871 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5872 GTK_POLICY_AUTOMATIC,
5873 GTK_POLICY_AUTOMATIC);
5874 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5876 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5877 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5879 text = gtk_text_view_new();
5880 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5881 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5882 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5883 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5884 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5886 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5888 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5889 G_CALLBACK(compose_edit_size_alloc),
5891 g_signal_connect(G_OBJECT(buffer), "changed",
5892 G_CALLBACK(compose_changed_cb), compose);
5893 g_signal_connect(G_OBJECT(text), "grab_focus",
5894 G_CALLBACK(compose_grab_focus_cb), compose);
5895 g_signal_connect(G_OBJECT(buffer), "insert_text",
5896 G_CALLBACK(text_inserted), compose);
5897 g_signal_connect(G_OBJECT(text), "button_press_event",
5898 G_CALLBACK(text_clicked), compose);
5899 g_signal_connect(G_OBJECT(subject_entry), "changed",
5900 G_CALLBACK(compose_changed_cb), compose);
5903 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5904 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5905 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5906 g_signal_connect(G_OBJECT(text), "drag_data_received",
5907 G_CALLBACK(compose_insert_drag_received_cb),
5909 g_signal_connect(G_OBJECT(text), "drag-drop",
5910 G_CALLBACK(compose_drag_drop),
5912 gtk_widget_show_all(vbox);
5914 /* pane between attach clist and text */
5915 paned = gtk_vpaned_new();
5916 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5917 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5918 gtk_paned_add1(GTK_PANED(paned), notebook);
5919 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5920 gtk_widget_show_all(paned);
5923 if (prefs_common.textfont) {
5924 PangoFontDescription *font_desc;
5926 font_desc = pango_font_description_from_string
5927 (prefs_common.textfont);
5929 gtk_widget_modify_font(text, font_desc);
5930 pango_font_description_free(font_desc);
5934 n_entries = sizeof(compose_popup_entries) /
5935 sizeof(compose_popup_entries[0]);
5936 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5937 "<Compose>", &popupfactory,
5940 ifactory = gtk_item_factory_from_widget(menubar);
5941 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5942 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5943 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5945 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5947 undostruct = undo_init(text);
5948 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5951 address_completion_start(window);
5953 compose->window = window;
5954 compose->vbox = vbox;
5955 compose->menubar = menubar;
5956 compose->handlebox = handlebox;
5958 compose->vbox2 = vbox2;
5960 compose->paned = paned;
5962 compose->edit_vbox = edit_vbox;
5963 compose->ruler_hbox = ruler_hbox;
5964 compose->ruler = ruler;
5965 compose->scrolledwin = scrolledwin;
5966 compose->text = text;
5968 compose->focused_editable = NULL;
5970 compose->popupmenu = popupmenu;
5971 compose->popupfactory = popupfactory;
5973 compose->tmpl_menu = tmpl_menu;
5975 compose->mode = mode;
5977 compose->targetinfo = NULL;
5978 compose->replyinfo = NULL;
5979 compose->fwdinfo = NULL;
5981 compose->replyto = NULL;
5983 compose->bcc = NULL;
5984 compose->followup_to = NULL;
5986 compose->ml_post = NULL;
5988 compose->inreplyto = NULL;
5989 compose->references = NULL;
5990 compose->msgid = NULL;
5991 compose->boundary = NULL;
5993 compose->autowrap = prefs_common.autowrap;
5995 compose->use_signing = FALSE;
5996 compose->use_encryption = FALSE;
5997 compose->privacy_system = NULL;
5999 compose->modified = FALSE;
6001 compose->return_receipt = FALSE;
6003 compose->to_list = NULL;
6004 compose->newsgroup_list = NULL;
6006 compose->undostruct = undostruct;
6008 compose->sig_str = NULL;
6010 compose->exteditor_file = NULL;
6011 compose->exteditor_pid = -1;
6012 compose->exteditor_tag = -1;
6013 compose->draft_timeout_tag = -1;
6016 menu_set_sensitive(ifactory, "/Spelling", FALSE);
6017 if (mode != COMPOSE_REDIRECT) {
6018 if (prefs_common.enable_aspell && prefs_common.dictionary &&
6019 strcmp(prefs_common.dictionary, "")) {
6020 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
6021 prefs_common.dictionary,
6022 conv_get_locale_charset_str(),
6023 prefs_common.misspelled_col,
6024 prefs_common.check_while_typing,
6025 prefs_common.recheck_when_changing_dict,
6026 prefs_common.use_alternate,
6027 GTK_TEXT_VIEW(text),
6028 GTK_WINDOW(compose->window),
6029 compose_spell_menu_changed,
6032 alertpanel_error(_("Spell checker could not "
6034 gtkaspell_checkers_strerror());
6035 gtkaspell_checkers_reset_error();
6037 if (!gtkaspell_set_sug_mode(gtkaspell,
6038 prefs_common.aspell_sugmode)) {
6039 debug_print("Aspell: could not set "
6040 "suggestion mode %s\n",
6041 gtkaspell_checkers_strerror());
6042 gtkaspell_checkers_reset_error();
6045 menu_set_sensitive(ifactory, "/Spelling", TRUE);
6049 compose->gtkaspell = gtkaspell;
6050 compose_spell_menu_changed(compose);
6053 compose_select_account(compose, account, TRUE);
6055 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
6056 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
6057 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
6059 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
6060 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
6062 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
6063 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
6066 if (account->protocol != A_NNTP)
6067 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
6069 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
6071 addressbook_set_target_compose(compose);
6073 if (mode != COMPOSE_REDIRECT)
6074 compose_set_template_menu(compose);
6076 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6077 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
6080 compose_list = g_list_append(compose_list, compose);
6082 if (!prefs_common.show_ruler)
6083 gtk_widget_hide(ruler_hbox);
6085 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
6086 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
6087 prefs_common.show_ruler);
6090 compose->priority = PRIORITY_NORMAL;
6091 compose_update_priority_menu_item(compose);
6093 compose_set_out_encoding(compose);
6096 compose_update_actions_menu(compose);
6098 /* Privacy Systems menu */
6099 compose_update_privacy_systems_menu(compose);
6101 activate_privacy_system(compose, account, TRUE);
6102 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
6104 gtk_widget_realize(window);
6106 gtk_widget_show(window);
6112 static GtkWidget *compose_account_option_menu_create(Compose *compose)
6118 GtkWidget *from_name = NULL;
6120 gint num = 0, def_menu = 0;
6122 accounts = account_get_list();
6123 g_return_val_if_fail(accounts != NULL, NULL);
6125 optmenu = gtk_option_menu_new();
6126 menu = gtk_menu_new();
6128 hbox = gtk_hbox_new(FALSE, 6);
6129 from_name = gtk_entry_new();
6131 g_signal_connect_after(G_OBJECT(from_name), "grab_focus",
6132 G_CALLBACK(compose_grab_focus_cb), compose);
6134 for (; accounts != NULL; accounts = accounts->next, num++) {
6135 PrefsAccount *ac = (PrefsAccount *)accounts->data;
6136 GtkWidget *menuitem;
6137 gchar *name, *from = NULL;
6139 if (ac == compose->account) def_menu = num;
6141 name = g_markup_printf_escaped("From: <i>%s</i>",
6144 if (ac == compose->account) {
6145 if (ac->name && *ac->name) {
6147 QUOTE_IF_REQUIRED_NORMAL(buf, ac->name, return NULL);
6148 from = g_strdup_printf("%s <%s>",
6150 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6152 from = g_strdup_printf("%s",
6154 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6157 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
6158 gtk_label_set_use_markup (
6159 GTK_LABEL (gtk_bin_get_child (GTK_BIN (menuitem))),
6163 g_signal_connect(G_OBJECT(menuitem), "activate",
6164 G_CALLBACK(account_activated),
6168 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
6169 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
6171 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
6172 gtk_box_pack_start(GTK_BOX(hbox), from_name, TRUE, TRUE, 0);
6174 gtk_tooltips_set_tip(compose->tooltips, optmenu,
6175 _("Account to use for this email"), NULL);
6176 gtk_tooltips_set_tip(compose->tooltips, from_name,
6177 _("Sender address to be used"), NULL);
6179 compose->from_name = from_name;
6184 static void compose_set_priority_cb(gpointer data,
6188 Compose *compose = (Compose *) data;
6189 compose->priority = action;
6192 static void compose_update_priority_menu_item(Compose * compose)
6194 GtkItemFactory *ifactory;
6195 GtkWidget *menuitem = NULL;
6197 ifactory = gtk_item_factory_from_widget(compose->menubar);
6199 switch (compose->priority) {
6200 case PRIORITY_HIGHEST:
6201 menuitem = gtk_item_factory_get_item
6202 (ifactory, "/Options/Priority/Highest");
6205 menuitem = gtk_item_factory_get_item
6206 (ifactory, "/Options/Priority/High");
6208 case PRIORITY_NORMAL:
6209 menuitem = gtk_item_factory_get_item
6210 (ifactory, "/Options/Priority/Normal");
6213 menuitem = gtk_item_factory_get_item
6214 (ifactory, "/Options/Priority/Low");
6216 case PRIORITY_LOWEST:
6217 menuitem = gtk_item_factory_get_item
6218 (ifactory, "/Options/Priority/Lowest");
6221 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6224 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
6226 Compose *compose = (Compose *) data;
6228 GtkItemFactory *ifactory;
6229 gboolean can_sign = FALSE, can_encrypt = FALSE;
6231 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
6233 if (!GTK_CHECK_MENU_ITEM(widget)->active)
6236 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
6237 g_free(compose->privacy_system);
6238 compose->privacy_system = NULL;
6239 if (systemid != NULL) {
6240 compose->privacy_system = g_strdup(systemid);
6242 can_sign = privacy_system_can_sign(systemid);
6243 can_encrypt = privacy_system_can_encrypt(systemid);
6246 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
6248 ifactory = gtk_item_factory_from_widget(compose->menubar);
6249 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6250 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6253 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
6255 static gchar *branch_path = "/Options/Privacy System";
6256 GtkItemFactory *ifactory;
6257 GtkWidget *menuitem = NULL;
6259 gboolean can_sign = FALSE, can_encrypt = FALSE;
6260 gboolean found = FALSE;
6262 ifactory = gtk_item_factory_from_widget(compose->menubar);
6264 if (compose->privacy_system != NULL) {
6267 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6268 g_return_if_fail(menuitem != NULL);
6270 amenu = GTK_MENU_SHELL(menuitem)->children;
6272 while (amenu != NULL) {
6273 GList *alist = amenu->next;
6275 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
6276 if (systemid != NULL) {
6277 if (strcmp(systemid, compose->privacy_system) == 0) {
6278 menuitem = GTK_WIDGET(amenu->data);
6280 can_sign = privacy_system_can_sign(systemid);
6281 can_encrypt = privacy_system_can_encrypt(systemid);
6285 } else if (strlen(compose->privacy_system) == 0) {
6286 menuitem = GTK_WIDGET(amenu->data);
6289 can_encrypt = FALSE;
6296 if (menuitem != NULL)
6297 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6299 if (warn && !found && strlen(compose->privacy_system)) {
6300 gchar *tmp = g_strdup_printf(
6301 _("The privacy system '%s' cannot be loaded. You "
6302 "will not be able to sign or encrypt this message."),
6303 compose->privacy_system);
6304 alertpanel_warning(tmp);
6309 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6310 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6313 static void compose_set_out_encoding(Compose *compose)
6315 GtkItemFactoryEntry *entry;
6316 GtkItemFactory *ifactory;
6317 CharSet out_encoding;
6318 gchar *path, *p, *q;
6321 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
6322 ifactory = gtk_item_factory_from_widget(compose->menubar);
6324 for (entry = compose_entries; entry->callback != compose_address_cb;
6326 if (entry->callback == compose_set_encoding_cb &&
6327 (CharSet)entry->callback_action == out_encoding) {
6328 p = q = path = g_strdup(entry->path);
6340 item = gtk_item_factory_get_item(ifactory, path);
6341 gtk_widget_activate(item);
6348 static void compose_set_template_menu(Compose *compose)
6350 GSList *tmpl_list, *cur;
6354 tmpl_list = template_get_config();
6356 menu = gtk_menu_new();
6358 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
6359 Template *tmpl = (Template *)cur->data;
6361 item = gtk_menu_item_new_with_label(tmpl->name);
6362 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6363 g_signal_connect(G_OBJECT(item), "activate",
6364 G_CALLBACK(compose_template_activate_cb),
6366 g_object_set_data(G_OBJECT(item), "template", tmpl);
6367 gtk_widget_show(item);
6370 gtk_widget_show(menu);
6371 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
6374 void compose_update_actions_menu(Compose *compose)
6376 GtkItemFactory *ifactory;
6378 ifactory = gtk_item_factory_from_widget(compose->menubar);
6379 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6382 void compose_update_privacy_systems_menu(Compose *compose)
6384 static gchar *branch_path = "/Options/Privacy System";
6385 GtkItemFactory *ifactory;
6386 GtkWidget *menuitem;
6387 GSList *systems, *cur;
6390 GtkWidget *system_none;
6393 ifactory = gtk_item_factory_from_widget(compose->menubar);
6395 /* remove old entries */
6396 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6397 g_return_if_fail(menuitem != NULL);
6399 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6400 while (amenu != NULL) {
6401 GList *alist = amenu->next;
6402 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6406 system_none = gtk_item_factory_get_widget(ifactory,
6407 "/Options/Privacy System/None");
6409 g_signal_connect(G_OBJECT(system_none), "activate",
6410 G_CALLBACK(compose_set_privacy_system_cb), compose);
6412 systems = privacy_get_system_ids();
6413 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6414 gchar *systemid = cur->data;
6416 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6417 widget = gtk_radio_menu_item_new_with_label(group,
6418 privacy_system_get_name(systemid));
6419 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6420 g_strdup(systemid), g_free);
6421 g_signal_connect(G_OBJECT(widget), "activate",
6422 G_CALLBACK(compose_set_privacy_system_cb), compose);
6424 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6425 gtk_widget_show(widget);
6428 g_slist_free(systems);
6431 void compose_reflect_prefs_all(void)
6436 for (cur = compose_list; cur != NULL; cur = cur->next) {
6437 compose = (Compose *)cur->data;
6438 compose_set_template_menu(compose);
6442 void compose_reflect_prefs_pixmap_theme(void)
6447 for (cur = compose_list; cur != NULL; cur = cur->next) {
6448 compose = (Compose *)cur->data;
6449 toolbar_update(TOOLBAR_COMPOSE, compose);
6453 static void compose_template_apply(Compose *compose, Template *tmpl,
6457 GtkTextBuffer *buffer;
6461 gchar *parsed_str = NULL;
6462 gint cursor_pos = 0;
6465 /* process the body */
6467 text = GTK_TEXT_VIEW(compose->text);
6468 buffer = gtk_text_view_get_buffer(text);
6471 gtk_text_buffer_set_text(buffer, "", -1);
6473 mark = gtk_text_buffer_get_insert(buffer);
6474 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6477 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6478 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6481 if (prefs_common.quotemark && *prefs_common.quotemark)
6482 qmark = prefs_common.quotemark;
6486 if (compose->replyinfo != NULL)
6487 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6488 tmpl->value, qmark, NULL, FALSE);
6489 else if (compose->fwdinfo != NULL)
6490 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6491 tmpl->value, qmark, NULL, FALSE);
6496 if (replace && parsed_str && compose->account->auto_sig)
6497 compose_insert_sig(compose, FALSE);
6499 if (replace && parsed_str) {
6500 gtk_text_buffer_get_start_iter(buffer, &iter);
6501 gtk_text_buffer_place_cursor(buffer, &iter);
6505 cursor_pos = quote_fmt_get_cursor_pos();
6506 compose->set_cursor_pos = cursor_pos;
6507 if (cursor_pos == -1)
6509 gtk_text_buffer_get_start_iter(buffer, &iter);
6510 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6511 gtk_text_buffer_place_cursor(buffer, &iter);
6514 /* process the other fields */
6515 compose_template_apply_fields(compose, tmpl);
6517 compose_changed_cb(NULL, compose);
6520 void compose_template_apply_fields(Compose *compose, Template *tmpl)
6522 static MsgInfo dummyinfo;
6523 MsgInfo *msginfo = NULL;
6526 if (compose->replyinfo != NULL)
6527 msginfo = compose->replyinfo;
6528 else if (compose->fwdinfo != NULL)
6529 msginfo = compose->fwdinfo;
6531 msginfo = &dummyinfo;
6533 if (tmpl->to && *tmpl->to != '\0') {
6534 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6535 quote_fmt_scan_string(tmpl->to);
6538 buf = quote_fmt_get_buffer();
6540 alertpanel_error(_("Message To format error."));
6542 compose_entry_append(compose, buf, COMPOSE_TO);
6546 if (tmpl->cc && *tmpl->cc != '\0') {
6547 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6548 quote_fmt_scan_string(tmpl->cc);
6551 buf = quote_fmt_get_buffer();
6553 alertpanel_error(_("Message Cc format error."));
6555 compose_entry_append(compose, buf, COMPOSE_CC);
6559 if (tmpl->bcc && *tmpl->bcc != '\0') {
6560 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6561 quote_fmt_scan_string(tmpl->bcc);
6564 buf = quote_fmt_get_buffer();
6566 alertpanel_error(_("Message Bcc format error."));
6568 compose_entry_append(compose, buf, COMPOSE_BCC);
6572 /* process the subject */
6573 if (tmpl->subject && *tmpl->subject != '\0') {
6574 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6575 quote_fmt_scan_string(tmpl->subject);
6578 buf = quote_fmt_get_buffer();
6580 alertpanel_error(_("Message subject format error."));
6582 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
6587 static void compose_destroy(Compose *compose)
6589 compose_list = g_list_remove(compose_list, compose);
6591 if (compose->updating) {
6592 debug_print("danger, not destroying anything now\n");
6593 compose->deferred_destroy = TRUE;
6596 /* NOTE: address_completion_end() does nothing with the window
6597 * however this may change. */
6598 address_completion_end(compose->window);
6600 slist_free_strings(compose->to_list);
6601 g_slist_free(compose->to_list);
6602 slist_free_strings(compose->newsgroup_list);
6603 g_slist_free(compose->newsgroup_list);
6604 slist_free_strings(compose->header_list);
6605 g_slist_free(compose->header_list);
6607 procmsg_msginfo_free(compose->targetinfo);
6608 procmsg_msginfo_free(compose->replyinfo);
6609 procmsg_msginfo_free(compose->fwdinfo);
6611 g_free(compose->replyto);
6612 g_free(compose->cc);
6613 g_free(compose->bcc);
6614 g_free(compose->newsgroups);
6615 g_free(compose->followup_to);
6617 g_free(compose->ml_post);
6619 g_free(compose->inreplyto);
6620 g_free(compose->references);
6621 g_free(compose->msgid);
6622 g_free(compose->boundary);
6624 g_free(compose->redirect_filename);
6625 if (compose->undostruct)
6626 undo_destroy(compose->undostruct);
6628 g_free(compose->sig_str);
6630 g_free(compose->exteditor_file);
6632 g_free(compose->orig_charset);
6634 g_free(compose->privacy_system);
6636 if (addressbook_get_target_compose() == compose)
6637 addressbook_set_target_compose(NULL);
6640 if (compose->gtkaspell) {
6641 gtkaspell_delete(compose->gtkaspell);
6642 compose->gtkaspell = NULL;
6646 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6647 prefs_common.compose_height = compose->window->allocation.height;
6649 if (!gtk_widget_get_parent(compose->paned))
6650 gtk_widget_destroy(compose->paned);
6651 gtk_widget_destroy(compose->popupmenu);
6653 gtk_widget_destroy(compose->window);
6654 toolbar_destroy(compose->toolbar);
6655 g_free(compose->toolbar);
6656 g_mutex_free(compose->mutex);
6660 static void compose_attach_info_free(AttachInfo *ainfo)
6662 g_free(ainfo->file);
6663 g_free(ainfo->content_type);
6664 g_free(ainfo->name);
6668 static void compose_attach_remove_selected(Compose *compose)
6670 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6671 GtkTreeSelection *selection;
6673 GtkTreeModel *model;
6675 selection = gtk_tree_view_get_selection(tree_view);
6676 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6681 for (cur = sel; cur != NULL; cur = cur->next) {
6682 GtkTreePath *path = cur->data;
6683 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6686 gtk_tree_path_free(path);
6689 for (cur = sel; cur != NULL; cur = cur->next) {
6690 GtkTreeRowReference *ref = cur->data;
6691 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6694 if (gtk_tree_model_get_iter(model, &iter, path))
6695 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6697 gtk_tree_path_free(path);
6698 gtk_tree_row_reference_free(ref);
6704 static struct _AttachProperty
6707 GtkWidget *mimetype_entry;
6708 GtkWidget *encoding_optmenu;
6709 GtkWidget *path_entry;
6710 GtkWidget *filename_entry;
6712 GtkWidget *cancel_btn;
6715 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6717 gtk_tree_path_free((GtkTreePath *)ptr);
6720 static void compose_attach_property(Compose *compose)
6722 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6724 GtkOptionMenu *optmenu;
6725 GtkTreeSelection *selection;
6727 GtkTreeModel *model;
6730 static gboolean cancelled;
6732 /* only if one selected */
6733 selection = gtk_tree_view_get_selection(tree_view);
6734 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6737 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6741 path = (GtkTreePath *) sel->data;
6742 gtk_tree_model_get_iter(model, &iter, path);
6743 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6746 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6752 if (!attach_prop.window)
6753 compose_attach_property_create(&cancelled);
6754 gtk_widget_grab_focus(attach_prop.ok_btn);
6755 gtk_widget_show(attach_prop.window);
6756 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6758 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6759 if (ainfo->encoding == ENC_UNKNOWN)
6760 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6761 GINT_TO_POINTER(ENC_BASE64));
6763 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6764 GINT_TO_POINTER(ainfo->encoding));
6766 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6767 ainfo->content_type ? ainfo->content_type : "");
6768 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6769 ainfo->file ? ainfo->file : "");
6770 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6771 ainfo->name ? ainfo->name : "");
6774 const gchar *entry_text;
6776 gchar *cnttype = NULL;
6780 GtkWidget *menuitem;
6785 gtk_widget_hide(attach_prop.window);
6790 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6791 if (*entry_text != '\0') {
6794 text = g_strstrip(g_strdup(entry_text));
6795 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6796 cnttype = g_strdup(text);
6799 alertpanel_error(_("Invalid MIME type."));
6805 menu = gtk_option_menu_get_menu(optmenu);
6806 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6807 ainfo->encoding = GPOINTER_TO_INT
6808 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6810 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6811 if (*entry_text != '\0') {
6812 if (is_file_exist(entry_text) &&
6813 (size = get_file_size(entry_text)) > 0)
6814 file = g_strdup(entry_text);
6817 (_("File doesn't exist or is empty."));
6823 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6824 if (*entry_text != '\0') {
6825 g_free(ainfo->name);
6826 ainfo->name = g_strdup(entry_text);
6830 g_free(ainfo->content_type);
6831 ainfo->content_type = cnttype;
6834 g_free(ainfo->file);
6840 /* update tree store */
6841 text = to_human_readable(ainfo->size);
6842 gtk_tree_model_get_iter(model, &iter, path);
6843 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6844 COL_MIMETYPE, ainfo->content_type,
6846 COL_NAME, ainfo->name,
6852 gtk_tree_path_free(path);
6855 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6857 label = gtk_label_new(str); \
6858 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6859 GTK_FILL, 0, 0, 0); \
6860 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6862 entry = gtk_entry_new(); \
6863 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6864 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6867 static void compose_attach_property_create(gboolean *cancelled)
6873 GtkWidget *mimetype_entry;
6876 GtkWidget *optmenu_menu;
6877 GtkWidget *menuitem;
6878 GtkWidget *path_entry;
6879 GtkWidget *filename_entry;
6882 GtkWidget *cancel_btn;
6883 GList *mime_type_list, *strlist;
6885 debug_print("Creating attach_property window...\n");
6887 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6888 gtk_widget_set_size_request(window, 480, -1);
6889 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6890 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6891 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6892 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6893 g_signal_connect(G_OBJECT(window), "delete_event",
6894 G_CALLBACK(attach_property_delete_event),
6896 g_signal_connect(G_OBJECT(window), "key_press_event",
6897 G_CALLBACK(attach_property_key_pressed),
6900 vbox = gtk_vbox_new(FALSE, 8);
6901 gtk_container_add(GTK_CONTAINER(window), vbox);
6903 table = gtk_table_new(4, 2, FALSE);
6904 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6905 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6906 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6908 label = gtk_label_new(_("MIME type"));
6909 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6911 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6912 mimetype_entry = gtk_combo_new();
6913 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6914 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6916 /* stuff with list */
6917 mime_type_list = procmime_get_mime_type_list();
6919 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6920 MimeType *type = (MimeType *) mime_type_list->data;
6923 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6925 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6928 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6929 (GCompareFunc)strcmp2);
6932 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6934 for (mime_type_list = strlist; mime_type_list != NULL;
6935 mime_type_list = mime_type_list->next)
6936 g_free(mime_type_list->data);
6937 g_list_free(strlist);
6939 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6941 label = gtk_label_new(_("Encoding"));
6942 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6944 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6946 hbox = gtk_hbox_new(FALSE, 0);
6947 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6948 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6950 optmenu = gtk_option_menu_new();
6951 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6953 optmenu_menu = gtk_menu_new();
6954 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6955 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6956 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6957 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6958 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6959 ENC_QUOTED_PRINTABLE);
6960 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6962 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6964 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6966 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6967 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6969 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
6970 &ok_btn, GTK_STOCK_OK,
6972 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6973 gtk_widget_grab_default(ok_btn);
6975 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6976 G_CALLBACK(attach_property_ok),
6978 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6979 G_CALLBACK(attach_property_cancel),
6982 gtk_widget_show_all(vbox);
6984 attach_prop.window = window;
6985 attach_prop.mimetype_entry = mimetype_entry;
6986 attach_prop.encoding_optmenu = optmenu;
6987 attach_prop.path_entry = path_entry;
6988 attach_prop.filename_entry = filename_entry;
6989 attach_prop.ok_btn = ok_btn;
6990 attach_prop.cancel_btn = cancel_btn;
6993 #undef SET_LABEL_AND_ENTRY
6995 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
7001 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
7007 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
7008 gboolean *cancelled)
7016 static gboolean attach_property_key_pressed(GtkWidget *widget,
7018 gboolean *cancelled)
7020 if (event && event->keyval == GDK_Escape) {
7027 static void compose_exec_ext_editor(Compose *compose)
7034 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
7035 G_DIR_SEPARATOR, compose);
7037 if (pipe(pipe_fds) < 0) {
7043 if ((pid = fork()) < 0) {
7050 /* close the write side of the pipe */
7053 compose->exteditor_file = g_strdup(tmp);
7054 compose->exteditor_pid = pid;
7056 compose_set_ext_editor_sensitive(compose, FALSE);
7058 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
7059 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
7063 } else { /* process-monitoring process */
7069 /* close the read side of the pipe */
7072 if (compose_write_body_to_file(compose, tmp) < 0) {
7073 fd_write_all(pipe_fds[1], "2\n", 2);
7077 pid_ed = compose_exec_ext_editor_real(tmp);
7079 fd_write_all(pipe_fds[1], "1\n", 2);
7083 /* wait until editor is terminated */
7084 waitpid(pid_ed, NULL, 0);
7086 fd_write_all(pipe_fds[1], "0\n", 2);
7093 #endif /* G_OS_UNIX */
7097 static gint compose_exec_ext_editor_real(const gchar *file)
7104 g_return_val_if_fail(file != NULL, -1);
7106 if ((pid = fork()) < 0) {
7111 if (pid != 0) return pid;
7113 /* grandchild process */
7115 if (setpgid(0, getppid()))
7118 if (prefs_common.ext_editor_cmd &&
7119 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
7120 *(p + 1) == 's' && !strchr(p + 2, '%')) {
7121 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
7123 if (prefs_common.ext_editor_cmd)
7124 g_warning("External editor command line is invalid: '%s'\n",
7125 prefs_common.ext_editor_cmd);
7126 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
7129 cmdline = strsplit_with_quote(buf, " ", 1024);
7130 execvp(cmdline[0], cmdline);
7133 g_strfreev(cmdline);
7138 static gboolean compose_ext_editor_kill(Compose *compose)
7140 pid_t pgid = compose->exteditor_pid * -1;
7143 ret = kill(pgid, 0);
7145 if (ret == 0 || (ret == -1 && EPERM == errno)) {
7149 msg = g_strdup_printf
7150 (_("The external editor is still working.\n"
7151 "Force terminating the process?\n"
7152 "process group id: %d"), -pgid);
7153 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
7154 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
7158 if (val == G_ALERTALTERNATE) {
7159 g_source_remove(compose->exteditor_tag);
7160 g_io_channel_shutdown(compose->exteditor_ch,
7162 g_io_channel_unref(compose->exteditor_ch);
7164 if (kill(pgid, SIGTERM) < 0) perror("kill");
7165 waitpid(compose->exteditor_pid, NULL, 0);
7167 g_warning("Terminated process group id: %d", -pgid);
7168 g_warning("Temporary file: %s",
7169 compose->exteditor_file);
7171 compose_set_ext_editor_sensitive(compose, TRUE);
7173 g_free(compose->exteditor_file);
7174 compose->exteditor_file = NULL;
7175 compose->exteditor_pid = -1;
7176 compose->exteditor_ch = NULL;
7177 compose->exteditor_tag = -1;
7185 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
7189 Compose *compose = (Compose *)data;
7192 debug_print(_("Compose: input from monitoring process\n"));
7194 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
7196 g_io_channel_shutdown(source, FALSE, NULL);
7197 g_io_channel_unref(source);
7199 waitpid(compose->exteditor_pid, NULL, 0);
7201 if (buf[0] == '0') { /* success */
7202 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7203 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
7205 gtk_text_buffer_set_text(buffer, "", -1);
7206 compose_insert_file(compose, compose->exteditor_file);
7207 compose_changed_cb(NULL, compose);
7209 if (g_unlink(compose->exteditor_file) < 0)
7210 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7211 } else if (buf[0] == '1') { /* failed */
7212 g_warning("Couldn't exec external editor\n");
7213 if (g_unlink(compose->exteditor_file) < 0)
7214 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7215 } else if (buf[0] == '2') {
7216 g_warning("Couldn't write to file\n");
7217 } else if (buf[0] == '3') {
7218 g_warning("Pipe read failed\n");
7221 compose_set_ext_editor_sensitive(compose, TRUE);
7223 g_free(compose->exteditor_file);
7224 compose->exteditor_file = NULL;
7225 compose->exteditor_pid = -1;
7226 compose->exteditor_ch = NULL;
7227 compose->exteditor_tag = -1;
7232 static void compose_set_ext_editor_sensitive(Compose *compose,
7235 GtkItemFactory *ifactory;
7237 ifactory = gtk_item_factory_from_widget(compose->menubar);
7239 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
7240 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
7241 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
7242 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
7243 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
7244 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
7245 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
7248 gtk_widget_set_sensitive(compose->text, sensitive);
7249 if (compose->toolbar->send_btn)
7250 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
7251 if (compose->toolbar->sendl_btn)
7252 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
7253 if (compose->toolbar->draft_btn)
7254 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
7255 if (compose->toolbar->insert_btn)
7256 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
7257 if (compose->toolbar->sig_btn)
7258 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
7259 if (compose->toolbar->exteditor_btn)
7260 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
7261 if (compose->toolbar->linewrap_current_btn)
7262 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
7263 if (compose->toolbar->linewrap_all_btn)
7264 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
7266 #endif /* G_OS_UNIX */
7269 * compose_undo_state_changed:
7271 * Change the sensivity of the menuentries undo and redo
7273 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
7274 gint redo_state, gpointer data)
7276 GtkWidget *widget = GTK_WIDGET(data);
7277 GtkItemFactory *ifactory;
7279 g_return_if_fail(widget != NULL);
7281 ifactory = gtk_item_factory_from_widget(widget);
7283 switch (undo_state) {
7284 case UNDO_STATE_TRUE:
7285 if (!undostruct->undo_state) {
7286 undostruct->undo_state = TRUE;
7287 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
7290 case UNDO_STATE_FALSE:
7291 if (undostruct->undo_state) {
7292 undostruct->undo_state = FALSE;
7293 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
7296 case UNDO_STATE_UNCHANGED:
7298 case UNDO_STATE_REFRESH:
7299 menu_set_sensitive(ifactory, "/Edit/Undo",
7300 undostruct->undo_state);
7303 g_warning("Undo state not recognized");
7307 switch (redo_state) {
7308 case UNDO_STATE_TRUE:
7309 if (!undostruct->redo_state) {
7310 undostruct->redo_state = TRUE;
7311 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
7314 case UNDO_STATE_FALSE:
7315 if (undostruct->redo_state) {
7316 undostruct->redo_state = FALSE;
7317 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
7320 case UNDO_STATE_UNCHANGED:
7322 case UNDO_STATE_REFRESH:
7323 menu_set_sensitive(ifactory, "/Edit/Redo",
7324 undostruct->redo_state);
7327 g_warning("Redo state not recognized");
7332 /* callback functions */
7334 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
7335 * includes "non-client" (windows-izm) in calculation, so this calculation
7336 * may not be accurate.
7338 static gboolean compose_edit_size_alloc(GtkEditable *widget,
7339 GtkAllocation *allocation,
7340 GtkSHRuler *shruler)
7342 if (prefs_common.show_ruler) {
7343 gint char_width = 0, char_height = 0;
7344 gint line_width_in_chars;
7346 gtkut_get_font_size(GTK_WIDGET(widget),
7347 &char_width, &char_height);
7348 line_width_in_chars =
7349 (allocation->width - allocation->x) / char_width;
7351 /* got the maximum */
7352 gtk_ruler_set_range(GTK_RULER(shruler),
7353 0.0, line_width_in_chars, 0,
7354 /*line_width_in_chars*/ char_width);
7360 static void account_activated(GtkMenuItem *menuitem, gpointer data)
7362 Compose *compose = (Compose *)data;
7365 gchar *folderidentifier;
7367 ac = account_find_from_id(
7368 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
7369 g_return_if_fail(ac != NULL);
7371 if (ac != compose->account)
7372 compose_select_account(compose, ac, FALSE);
7374 /* Set message save folder */
7375 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7376 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
7378 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
7379 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
7381 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7382 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7383 folderidentifier = folder_item_get_identifier(account_get_special_folder
7384 (compose->account, F_OUTBOX));
7385 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
7386 g_free(folderidentifier);
7390 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
7391 GtkTreeViewColumn *column, Compose *compose)
7393 compose_attach_property(compose);
7396 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
7399 Compose *compose = (Compose *)data;
7400 GtkTreeSelection *attach_selection;
7401 gint attach_nr_selected;
7402 GtkItemFactory *ifactory;
7404 if (!event) return FALSE;
7406 if (event->button == 3) {
7407 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
7408 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
7409 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7411 if (attach_nr_selected > 0)
7413 menu_set_sensitive(ifactory, "/Remove", TRUE);
7414 menu_set_sensitive(ifactory, "/Properties...", TRUE);
7416 menu_set_sensitive(ifactory, "/Remove", FALSE);
7417 menu_set_sensitive(ifactory, "/Properties...", FALSE);
7420 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
7421 NULL, NULL, event->button, event->time);
7428 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
7431 Compose *compose = (Compose *)data;
7433 if (!event) return FALSE;
7435 switch (event->keyval) {
7437 compose_attach_remove_selected(compose);
7443 static void compose_allow_user_actions (Compose *compose, gboolean allow)
7445 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
7446 toolbar_comp_set_sensitive(compose, allow);
7447 menu_set_sensitive(ifactory, "/Message", allow);
7448 menu_set_sensitive(ifactory, "/Edit", allow);
7450 menu_set_sensitive(ifactory, "/Spelling", allow);
7452 menu_set_sensitive(ifactory, "/Options", allow);
7453 menu_set_sensitive(ifactory, "/Tools", allow);
7454 menu_set_sensitive(ifactory, "/Help", allow);
7456 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7460 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7462 Compose *compose = (Compose *)data;
7464 if (prefs_common.work_offline &&
7465 !inc_offline_should_override(
7466 _("Sylpheed-Claws needs network access in order "
7467 "to send this email.")))
7470 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7471 gtk_timeout_remove(compose->draft_timeout_tag);
7472 compose->draft_timeout_tag = -1;
7475 compose_send(compose);
7478 static void compose_send_later_cb(gpointer data, guint action,
7481 Compose *compose = (Compose *)data;
7484 val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE);
7486 compose_close(compose);
7487 else if (val == -2) {
7488 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7489 } else if (val == -3) {
7490 alertpanel_error(_("Could not queue message for sending:\n\n"
7491 "Signature failed."));
7492 } else if (val == -4) {
7493 alertpanel_error(_("Could not queue message for sending:\n\n"
7494 "Charset conversion failed."));
7498 void compose_draft (gpointer data)
7500 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7503 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7505 Compose *compose = (Compose *)data;
7509 MsgFlags flag = {0, 0};
7510 static gboolean lock = FALSE;
7511 MsgInfo *newmsginfo;
7513 gboolean target_locked = FALSE;
7517 draft = account_get_special_folder(compose->account, F_DRAFT);
7518 g_return_if_fail(draft != NULL);
7520 if (!g_mutex_trylock(compose->mutex)) {
7521 /* we don't want to lock the mutex once it's available,
7522 * because as the only other part of compose.c locking
7523 * it is compose_close - which means once unlocked,
7524 * the compose struct will be freed */
7525 debug_print("couldn't lock mutex, probably sending\n");
7531 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7532 G_DIR_SEPARATOR, compose);
7533 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7534 FILE_OP_ERROR(tmp, "fopen");
7538 /* chmod for security */
7539 if (change_file_mode_rw(fp, tmp) < 0) {
7540 FILE_OP_ERROR(tmp, "chmod");
7541 g_warning("can't change file mode\n");
7544 /* Save draft infos */
7545 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7546 fprintf(fp, "S:%s\n", compose->account->address);
7548 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7549 gchar *savefolderid;
7551 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7552 fprintf(fp, "SCF:%s\n", savefolderid);
7553 g_free(savefolderid);
7555 if (compose->return_receipt) {
7556 fprintf(fp, "RRCPT:1\n");
7558 if (compose->privacy_system) {
7559 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7560 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7561 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7565 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
7573 if (compose->targetinfo) {
7574 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7575 flag.perm_flags = target_locked?MSG_LOCKED:0;
7577 flag.tmp_flags = MSG_DRAFT;
7579 folder_item_scan(draft);
7580 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7583 if (action != COMPOSE_AUTO_SAVE)
7584 alertpanel_error(_("Could not save draft."));
7588 draft->mtime = 0; /* force updating */
7590 if (compose->mode == COMPOSE_REEDIT) {
7591 compose_remove_reedit_target(compose, TRUE);
7594 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7596 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7598 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
7600 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7601 if (compose_use_attach(compose))
7602 procmsg_msginfo_set_flags(newmsginfo, 0,
7603 MSG_HAS_ATTACHMENT);
7605 procmsg_msginfo_free(newmsginfo);
7608 folder_item_scan(draft);
7610 if (action == COMPOSE_QUIT_EDITING) {
7612 g_mutex_unlock(compose->mutex); /* must be done before closing */
7613 compose_close(compose);
7619 path = folder_item_fetch_msg(draft, msgnum);
7621 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
7624 if (g_stat(path, &s) < 0) {
7625 FILE_OP_ERROR(path, "stat");
7631 procmsg_msginfo_free(compose->targetinfo);
7632 compose->targetinfo = procmsg_msginfo_new();
7633 compose->targetinfo->msgnum = msgnum;
7634 compose->targetinfo->size = s.st_size;
7635 compose->targetinfo->mtime = s.st_mtime;
7636 compose->targetinfo->folder = draft;
7638 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
7639 compose->mode = COMPOSE_REEDIT;
7641 if (action == COMPOSE_AUTO_SAVE) {
7642 compose->autosaved_draft = compose->targetinfo;
7644 compose->modified = FALSE;
7645 compose_set_title(compose);
7649 g_mutex_unlock(compose->mutex);
7652 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7654 Compose *compose = (Compose *)data;
7657 if (compose->redirect_filename != NULL)
7660 file_list = filesel_select_multiple_files_open(_("Select file"));
7665 for ( tmp = file_list; tmp; tmp = tmp->next) {
7666 gchar *file = (gchar *) tmp->data;
7667 gchar *utf8_filename = conv_filename_to_utf8(file);
7668 compose_attach_append(compose, file, utf8_filename, NULL);
7669 compose_changed_cb(NULL, compose);
7671 g_free(utf8_filename);
7673 g_list_free(file_list);
7677 static void compose_insert_file_cb(gpointer data, guint action,
7680 Compose *compose = (Compose *)data;
7683 file_list = filesel_select_multiple_files_open(_("Select file"));
7688 for ( tmp = file_list; tmp; tmp = tmp->next) {
7689 gchar *file = (gchar *) tmp->data;
7690 gchar *filedup = g_strdup(file);
7691 gchar *shortfile = g_path_get_basename(filedup);
7692 ComposeInsertResult res;
7694 res = compose_insert_file(compose, file);
7695 if (res == COMPOSE_INSERT_READ_ERROR) {
7696 alertpanel_error(_("File '%s' could not be read."), shortfile);
7697 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7698 alertpanel_error(_("File '%s' contained invalid characters\n"
7699 "for the current encoding, insertion may be incorrect."), shortfile);
7705 g_list_free(file_list);
7709 static void compose_insert_sig_cb(gpointer data, guint action,
7712 Compose *compose = (Compose *)data;
7714 compose_insert_sig(compose, FALSE);
7717 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7721 Compose *compose = (Compose *)data;
7723 gtkut_widget_get_uposition(widget, &x, &y);
7724 prefs_common.compose_x = x;
7725 prefs_common.compose_y = y;
7727 if (compose->sending || compose->updating)
7729 compose_close_cb(compose, 0, NULL);
7733 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7735 Compose *compose = (Compose *)data;
7739 if (compose->exteditor_tag != -1) {
7740 if (!compose_ext_editor_kill(compose))
7745 if (compose->modified) {
7746 val = alertpanel(_("Discard message"),
7747 _("This message has been modified. Discard it?"),
7748 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7751 case G_ALERTDEFAULT:
7752 if (prefs_common.autosave)
7753 compose_remove_draft(compose);
7755 case G_ALERTALTERNATE:
7756 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7763 compose_close(compose);
7766 static void compose_set_encoding_cb(gpointer data, guint action,
7769 Compose *compose = (Compose *)data;
7771 if (GTK_CHECK_MENU_ITEM(widget)->active)
7772 compose->out_encoding = (CharSet)action;
7775 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7777 Compose *compose = (Compose *)data;
7779 addressbook_open(compose);
7782 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7784 Compose *compose = (Compose *)data;
7789 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7790 g_return_if_fail(tmpl != NULL);
7792 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7794 val = alertpanel(_("Apply template"), msg,
7795 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7798 if (val == G_ALERTDEFAULT)
7799 compose_template_apply(compose, tmpl, TRUE);
7800 else if (val == G_ALERTALTERNATE)
7801 compose_template_apply(compose, tmpl, FALSE);
7804 static void compose_ext_editor_cb(gpointer data, guint action,
7807 Compose *compose = (Compose *)data;
7809 compose_exec_ext_editor(compose);
7812 static void compose_undo_cb(Compose *compose)
7814 gboolean prev_autowrap = compose->autowrap;
7816 compose->autowrap = FALSE;
7817 undo_undo(compose->undostruct);
7818 compose->autowrap = prev_autowrap;
7821 static void compose_redo_cb(Compose *compose)
7823 gboolean prev_autowrap = compose->autowrap;
7825 compose->autowrap = FALSE;
7826 undo_redo(compose->undostruct);
7827 compose->autowrap = prev_autowrap;
7830 static void entry_cut_clipboard(GtkWidget *entry)
7832 if (GTK_IS_EDITABLE(entry))
7833 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7834 else if (GTK_IS_TEXT_VIEW(entry))
7835 gtk_text_buffer_cut_clipboard(
7836 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7837 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7841 static void entry_copy_clipboard(GtkWidget *entry)
7843 if (GTK_IS_EDITABLE(entry))
7844 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7845 else if (GTK_IS_TEXT_VIEW(entry))
7846 gtk_text_buffer_copy_clipboard(
7847 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7848 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7851 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7852 gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
7854 if (GTK_IS_TEXT_VIEW(entry)) {
7855 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7856 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7857 GtkTextIter start_iter, end_iter;
7860 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7862 if (contents == NULL)
7865 /* we shouldn't delete the selection when middle-click-pasting, or we
7866 * can't mid-click-paste our own selection */
7867 if (clip != GDK_SELECTION_PRIMARY)
7868 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7870 if (insert_place == NULL) {
7871 /* if insert_place isn't specified, insert at the cursor.
7872 * used for Ctrl-V pasting */
7873 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7874 start = gtk_text_iter_get_offset(&start_iter);
7875 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7877 /* if insert_place is specified, paste here.
7878 * used for mid-click-pasting */
7879 start = gtk_text_iter_get_offset(insert_place);
7880 gtk_text_buffer_insert(buffer, insert_place, contents, strlen(contents));
7884 /* paste unwrapped: mark the paste so it's not wrapped later */
7885 end = start + strlen(contents);
7886 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7887 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7888 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7889 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7890 /* rewrap paragraph now (after a mid-click-paste) */
7891 mark_start = gtk_text_buffer_get_insert(buffer);
7892 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7893 gtk_text_iter_backward_char(&start_iter);
7894 compose_beautify_paragraph(compose, &start_iter, TRUE);
7897 } else if (GTK_IS_EDITABLE(entry))
7898 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7902 static void entry_allsel(GtkWidget *entry)
7904 if (GTK_IS_EDITABLE(entry))
7905 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7906 else if (GTK_IS_TEXT_VIEW(entry)) {
7907 GtkTextIter startiter, enditer;
7908 GtkTextBuffer *textbuf;
7910 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7911 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7912 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7914 gtk_text_buffer_move_mark_by_name(textbuf,
7915 "selection_bound", &startiter);
7916 gtk_text_buffer_move_mark_by_name(textbuf,
7917 "insert", &enditer);
7921 static void compose_cut_cb(Compose *compose)
7923 if (compose->focused_editable &&
7924 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7925 entry_cut_clipboard(compose->focused_editable);
7928 static void compose_copy_cb(Compose *compose)
7930 if (compose->focused_editable &&
7931 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7932 entry_copy_clipboard(compose->focused_editable);
7935 static void compose_paste_cb(Compose *compose)
7938 GtkTextBuffer *buffer;
7940 if (compose->focused_editable &&
7941 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7942 entry_paste_clipboard(compose, compose->focused_editable,
7943 prefs_common.linewrap_pastes,
7944 GDK_SELECTION_CLIPBOARD, NULL);
7948 static void compose_paste_as_quote_cb(Compose *compose)
7950 gint wrap_quote = prefs_common.linewrap_quote;
7951 if (compose->focused_editable &&
7952 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7953 /* let text_insert() (called directly or at a later time
7954 * after the gtk_editable_paste_clipboard) know that
7955 * text is to be inserted as a quotation. implemented
7956 * by using a simple refcount... */
7957 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7958 G_OBJECT(compose->focused_editable),
7959 "paste_as_quotation"));
7960 g_object_set_data(G_OBJECT(compose->focused_editable),
7961 "paste_as_quotation",
7962 GINT_TO_POINTER(paste_as_quotation + 1));
7963 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7964 entry_paste_clipboard(compose, compose->focused_editable,
7965 prefs_common.linewrap_pastes,
7966 GDK_SELECTION_CLIPBOARD, NULL);
7967 prefs_common.linewrap_quote = wrap_quote;
7971 static void compose_paste_no_wrap_cb(Compose *compose)
7974 GtkTextBuffer *buffer;
7976 if (compose->focused_editable &&
7977 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7978 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7979 GDK_SELECTION_CLIPBOARD, NULL);
7983 static void compose_paste_wrap_cb(Compose *compose)
7986 GtkTextBuffer *buffer;
7988 if (compose->focused_editable &&
7989 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7990 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7991 GDK_SELECTION_CLIPBOARD, NULL);
7995 static void compose_allsel_cb(Compose *compose)
7997 if (compose->focused_editable &&
7998 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7999 entry_allsel(compose->focused_editable);
8002 static void textview_move_beginning_of_line (GtkTextView *text)
8004 GtkTextBuffer *buffer;
8008 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8010 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8011 mark = gtk_text_buffer_get_insert(buffer);
8012 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8013 gtk_text_iter_set_line_offset(&ins, 0);
8014 gtk_text_buffer_place_cursor(buffer, &ins);
8017 static void textview_move_forward_character (GtkTextView *text)
8019 GtkTextBuffer *buffer;
8023 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8025 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8026 mark = gtk_text_buffer_get_insert(buffer);
8027 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8028 if (gtk_text_iter_forward_cursor_position(&ins))
8029 gtk_text_buffer_place_cursor(buffer, &ins);
8032 static void textview_move_backward_character (GtkTextView *text)
8034 GtkTextBuffer *buffer;
8038 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8040 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8041 mark = gtk_text_buffer_get_insert(buffer);
8042 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8043 if (gtk_text_iter_backward_cursor_position(&ins))
8044 gtk_text_buffer_place_cursor(buffer, &ins);
8047 static void textview_move_forward_word (GtkTextView *text)
8049 GtkTextBuffer *buffer;
8054 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8056 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8057 mark = gtk_text_buffer_get_insert(buffer);
8058 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8059 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8060 if (gtk_text_iter_forward_word_ends(&ins, count)) {
8061 gtk_text_iter_backward_word_start(&ins);
8062 gtk_text_buffer_place_cursor(buffer, &ins);
8066 static void textview_move_backward_word (GtkTextView *text)
8068 GtkTextBuffer *buffer;
8073 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8075 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8076 mark = gtk_text_buffer_get_insert(buffer);
8077 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8078 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8079 if (gtk_text_iter_backward_word_starts(&ins, 1))
8080 gtk_text_buffer_place_cursor(buffer, &ins);
8083 static void textview_move_end_of_line (GtkTextView *text)
8085 GtkTextBuffer *buffer;
8089 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8091 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8092 mark = gtk_text_buffer_get_insert(buffer);
8093 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8094 if (gtk_text_iter_forward_to_line_end(&ins))
8095 gtk_text_buffer_place_cursor(buffer, &ins);
8098 static void textview_move_next_line (GtkTextView *text)
8100 GtkTextBuffer *buffer;
8105 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8107 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8108 mark = gtk_text_buffer_get_insert(buffer);
8109 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8110 offset = gtk_text_iter_get_line_offset(&ins);
8111 if (gtk_text_iter_forward_line(&ins)) {
8112 gtk_text_iter_set_line_offset(&ins, offset);
8113 gtk_text_buffer_place_cursor(buffer, &ins);
8117 static void textview_move_previous_line (GtkTextView *text)
8119 GtkTextBuffer *buffer;
8124 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8126 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8127 mark = gtk_text_buffer_get_insert(buffer);
8128 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8129 offset = gtk_text_iter_get_line_offset(&ins);
8130 if (gtk_text_iter_backward_line(&ins)) {
8131 gtk_text_iter_set_line_offset(&ins, offset);
8132 gtk_text_buffer_place_cursor(buffer, &ins);
8136 static void textview_delete_forward_character (GtkTextView *text)
8138 GtkTextBuffer *buffer;
8140 GtkTextIter ins, end_iter;
8142 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8144 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8145 mark = gtk_text_buffer_get_insert(buffer);
8146 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8148 if (gtk_text_iter_forward_char(&end_iter)) {
8149 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8153 static void textview_delete_backward_character (GtkTextView *text)
8155 GtkTextBuffer *buffer;
8157 GtkTextIter ins, end_iter;
8159 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8161 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8162 mark = gtk_text_buffer_get_insert(buffer);
8163 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8165 if (gtk_text_iter_backward_char(&end_iter)) {
8166 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8170 static void textview_delete_forward_word (GtkTextView *text)
8172 GtkTextBuffer *buffer;
8174 GtkTextIter ins, end_iter;
8176 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8178 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8179 mark = gtk_text_buffer_get_insert(buffer);
8180 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8182 if (gtk_text_iter_forward_word_end(&end_iter)) {
8183 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8187 static void textview_delete_backward_word (GtkTextView *text)
8189 GtkTextBuffer *buffer;
8191 GtkTextIter ins, end_iter;
8193 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8195 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8196 mark = gtk_text_buffer_get_insert(buffer);
8197 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8199 if (gtk_text_iter_backward_word_start(&end_iter)) {
8200 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8204 static void textview_delete_line (GtkTextView *text)
8206 GtkTextBuffer *buffer;
8208 GtkTextIter ins, start_iter, end_iter;
8211 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8213 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8214 mark = gtk_text_buffer_get_insert(buffer);
8215 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8218 gtk_text_iter_set_line_offset(&start_iter, 0);
8221 if (gtk_text_iter_ends_line(&end_iter))
8222 found = gtk_text_iter_forward_char(&end_iter);
8224 found = gtk_text_iter_forward_to_line_end(&end_iter);
8227 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
8230 static void textview_delete_to_line_end (GtkTextView *text)
8232 GtkTextBuffer *buffer;
8234 GtkTextIter ins, end_iter;
8237 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8239 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8240 mark = gtk_text_buffer_get_insert(buffer);
8241 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8243 if (gtk_text_iter_ends_line(&end_iter))
8244 found = gtk_text_iter_forward_char(&end_iter);
8246 found = gtk_text_iter_forward_to_line_end(&end_iter);
8248 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8251 static void compose_advanced_action_cb(Compose *compose,
8252 ComposeCallAdvancedAction action)
8254 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8256 void (*do_action) (GtkTextView *text);
8257 } action_table[] = {
8258 {textview_move_beginning_of_line},
8259 {textview_move_forward_character},
8260 {textview_move_backward_character},
8261 {textview_move_forward_word},
8262 {textview_move_backward_word},
8263 {textview_move_end_of_line},
8264 {textview_move_next_line},
8265 {textview_move_previous_line},
8266 {textview_delete_forward_character},
8267 {textview_delete_backward_character},
8268 {textview_delete_forward_word},
8269 {textview_delete_backward_word},
8270 {textview_delete_line},
8271 {NULL}, /* gtk_stext_delete_line_n */
8272 {textview_delete_to_line_end}
8275 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
8277 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
8278 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
8279 if (action_table[action].do_action)
8280 action_table[action].do_action(text);
8282 g_warning("Not implemented yet.");
8286 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
8290 if (GTK_IS_EDITABLE(widget)) {
8291 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
8292 gtk_editable_set_position(GTK_EDITABLE(widget),
8295 if (widget->parent && widget->parent->parent
8296 && widget->parent->parent->parent) {
8297 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
8298 gint y = widget->allocation.y;
8299 gint height = widget->allocation.height;
8300 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
8301 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
8303 if (y < (int)shown->value) {
8304 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
8306 if (y + height > (int)shown->value + (int)shown->page_size) {
8307 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
8308 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8309 y + height - (int)shown->page_size - 1);
8311 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8312 (int)shown->upper - (int)shown->page_size - 1);
8319 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
8320 compose->focused_editable = widget;
8323 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
8325 compose->modified = TRUE;
8326 compose_set_title(compose);
8329 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
8331 Compose *compose = (Compose *)data;
8334 compose_wrap_all_full(compose, TRUE);
8336 compose_beautify_paragraph(compose, NULL, TRUE);
8339 static void compose_find_cb(gpointer data, guint action, GtkWidget *widget)
8341 Compose *compose = (Compose *)data;
8343 message_search_compose(compose);
8346 static void compose_toggle_autowrap_cb(gpointer data, guint action,
8349 Compose *compose = (Compose *)data;
8350 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8351 if (compose->autowrap)
8352 compose_wrap_all_full(compose, TRUE);
8353 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8356 static void compose_toggle_sign_cb(gpointer data, guint action,
8359 Compose *compose = (Compose *)data;
8361 if (GTK_CHECK_MENU_ITEM(widget)->active)
8362 compose->use_signing = TRUE;
8364 compose->use_signing = FALSE;
8367 static void compose_toggle_encrypt_cb(gpointer data, guint action,
8370 Compose *compose = (Compose *)data;
8372 if (GTK_CHECK_MENU_ITEM(widget)->active)
8373 compose->use_encryption = TRUE;
8375 compose->use_encryption = FALSE;
8378 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
8380 g_free(compose->privacy_system);
8382 compose->privacy_system = g_strdup(account->default_privacy_system);
8383 compose_update_privacy_system_menu_item(compose, warn);
8386 static void compose_toggle_ruler_cb(gpointer data, guint action,
8389 Compose *compose = (Compose *)data;
8391 if (GTK_CHECK_MENU_ITEM(widget)->active) {
8392 gtk_widget_show(compose->ruler_hbox);
8393 prefs_common.show_ruler = TRUE;
8395 gtk_widget_hide(compose->ruler_hbox);
8396 gtk_widget_queue_resize(compose->edit_vbox);
8397 prefs_common.show_ruler = FALSE;
8401 static void compose_attach_drag_received_cb (GtkWidget *widget,
8402 GdkDragContext *context,
8405 GtkSelectionData *data,
8410 Compose *compose = (Compose *)user_data;
8413 if (gdk_atom_name(data->type) &&
8414 !strcmp(gdk_atom_name(data->type), "text/uri-list")
8415 && gtk_drag_get_source_widget(context) !=
8416 mainwindow_get_mainwindow()->summaryview->ctree) {
8417 list = uri_list_extract_filenames((const gchar *)data->data);
8418 for (tmp = list; tmp != NULL; tmp = tmp->next)
8419 compose_attach_append
8420 (compose, (const gchar *)tmp->data,
8421 (const gchar *)tmp->data, NULL);
8422 if (list) compose_changed_cb(NULL, compose);
8423 list_free_strings(list);
8425 } else if (gtk_drag_get_source_widget(context)
8426 == mainwindow_get_mainwindow()->summaryview->ctree) {
8427 /* comes from our summaryview */
8428 SummaryView * summaryview = NULL;
8429 GSList * list = NULL, *cur = NULL;
8431 if (mainwindow_get_mainwindow())
8432 summaryview = mainwindow_get_mainwindow()->summaryview;
8435 list = summary_get_selected_msg_list(summaryview);
8437 for (cur = list; cur; cur = cur->next) {
8438 MsgInfo *msginfo = (MsgInfo *)cur->data;
8441 file = procmsg_get_message_file_full(msginfo,
8444 compose_attach_append(compose, (const gchar *)file,
8445 (const gchar *)file, "message/rfc822");
8453 static gboolean compose_drag_drop(GtkWidget *widget,
8454 GdkDragContext *drag_context,
8456 guint time, gpointer user_data)
8458 /* not handling this signal makes compose_insert_drag_received_cb
8463 static void compose_insert_drag_received_cb (GtkWidget *widget,
8464 GdkDragContext *drag_context,
8467 GtkSelectionData *data,
8472 Compose *compose = (Compose *)user_data;
8475 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
8477 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
8478 list = uri_list_extract_filenames((const gchar *)data->data);
8479 for (tmp = list; tmp != NULL; tmp = tmp->next) {
8480 compose_insert_file(compose, (const gchar *)tmp->data);
8482 list_free_strings(list);
8484 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8487 #if GTK_CHECK_VERSION(2, 8, 0)
8488 /* do nothing, handled by GTK */
8490 gchar *tmpfile = get_tmp_file();
8491 str_write_to_file((const gchar *)data->data, tmpfile);
8492 compose_insert_file(compose, tmpfile);
8495 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8499 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8502 static void compose_header_drag_received_cb (GtkWidget *widget,
8503 GdkDragContext *drag_context,
8506 GtkSelectionData *data,
8511 GtkEditable *entry = (GtkEditable *)user_data;
8512 gchar *email = (gchar *)data->data;
8514 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8517 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8518 gchar *decoded=g_new(gchar, strlen(email));
8521 email += strlen("mailto:");
8522 decode_uri(decoded, email); /* will fit */
8523 gtk_editable_delete_text(entry, 0, -1);
8524 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8525 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8529 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8532 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8535 Compose *compose = (Compose *)data;
8537 if (GTK_CHECK_MENU_ITEM(widget)->active)
8538 compose->return_receipt = TRUE;
8540 compose->return_receipt = FALSE;
8543 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8546 Compose *compose = (Compose *)data;
8548 if (GTK_CHECK_MENU_ITEM(widget)->active)
8549 compose->remove_references = TRUE;
8551 compose->remove_references = FALSE;
8554 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8556 ComposeHeaderEntry *headerentry)
8558 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
8559 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
8560 !(event->state & GDK_MODIFIER_MASK) &&
8561 (event->keyval == GDK_BackSpace) &&
8562 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
8563 gtk_container_remove
8564 (GTK_CONTAINER(headerentry->compose->header_table),
8565 headerentry->combo);
8566 gtk_container_remove
8567 (GTK_CONTAINER(headerentry->compose->header_table),
8568 headerentry->entry);
8569 headerentry->compose->header_list =
8570 g_slist_remove(headerentry->compose->header_list,
8572 g_free(headerentry);
8573 } else if (event->keyval == GDK_Tab) {
8574 if (headerentry->compose->header_last == headerentry) {
8575 /* Override default next focus, and give it to subject_entry
8576 * instead of notebook tabs
8578 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8579 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8586 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8587 ComposeHeaderEntry *headerentry)
8589 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8590 headerentry->compose->header_list =
8591 g_slist_append(headerentry->compose->header_list,
8594 compose_create_header_entry(headerentry->compose);
8595 g_signal_handlers_disconnect_matched
8596 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8597 0, 0, NULL, NULL, headerentry);
8599 /* Automatically scroll down */
8600 compose_show_first_last_header(headerentry->compose, FALSE);
8606 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8608 GtkAdjustment *vadj;
8610 g_return_if_fail(compose);
8611 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8612 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8614 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8615 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8618 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8619 const gchar *text, gint len, Compose *compose)
8621 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8622 (G_OBJECT(compose->text), "paste_as_quotation"));
8625 g_return_if_fail(text != NULL);
8627 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8628 G_CALLBACK(text_inserted),
8630 if (paste_as_quotation) {
8637 new_text = g_strndup(text, len);
8638 if (prefs_common.quotemark && *prefs_common.quotemark)
8639 qmark = prefs_common.quotemark;
8643 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8644 gtk_text_buffer_place_cursor(buffer, iter);
8646 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8648 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8649 GINT_TO_POINTER(paste_as_quotation - 1));
8651 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8652 gtk_text_buffer_place_cursor(buffer, iter);
8654 if (strcmp(text, "\n") || automatic_break
8655 || gtk_text_iter_starts_line(iter))
8656 gtk_text_buffer_insert(buffer, iter, text, len);
8658 debug_print("insert nowrap \\n\n");
8659 gtk_text_buffer_insert_with_tags_by_name(buffer,
8660 iter, text, len, "no_join", NULL);
8664 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8666 compose_beautify_paragraph(compose, iter, FALSE);
8668 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8669 gtk_text_buffer_delete_mark(buffer, mark);
8671 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8672 G_CALLBACK(text_inserted),
8674 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8676 if (prefs_common.autosave &&
8677 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8678 compose->draft_timeout_tag = gtk_timeout_add
8679 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8681 static gint compose_defer_auto_save_draft(Compose *compose)
8683 compose->draft_timeout_tag = -1;
8684 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8689 static void compose_check_all(Compose *compose)
8691 if (compose->gtkaspell)
8692 gtkaspell_check_all(compose->gtkaspell);
8695 static void compose_highlight_all(Compose *compose)
8697 if (compose->gtkaspell)
8698 gtkaspell_highlight_all(compose->gtkaspell);
8701 static void compose_check_backwards(Compose *compose)
8703 if (compose->gtkaspell)
8704 gtkaspell_check_backwards(compose->gtkaspell);
8706 GtkItemFactory *ifactory;
8707 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8708 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8709 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8713 static void compose_check_forwards_go(Compose *compose)
8715 if (compose->gtkaspell)
8716 gtkaspell_check_forwards_go(compose->gtkaspell);
8718 GtkItemFactory *ifactory;
8719 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8720 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8721 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8727 *\brief Guess originating forward account from MsgInfo and several
8728 * "common preference" settings. Return NULL if no guess.
8730 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8732 PrefsAccount *account = NULL;
8734 g_return_val_if_fail(msginfo, NULL);
8735 g_return_val_if_fail(msginfo->folder, NULL);
8736 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8738 if (msginfo->folder->prefs->enable_default_account)
8739 account = account_find_from_id(msginfo->folder->prefs->default_account);
8742 account = msginfo->folder->folder->account;
8744 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8746 Xstrdup_a(to, msginfo->to, return NULL);
8747 extract_address(to);
8748 account = account_find_from_address(to);
8751 if (!account && prefs_common.forward_account_autosel) {
8753 if (!procheader_get_header_from_msginfo
8754 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8755 extract_address(cc);
8756 account = account_find_from_address(cc);
8763 static gboolean compose_close(Compose *compose)
8767 if (!g_mutex_trylock(compose->mutex)) {
8768 /* we have to wait for the (possibly deferred by auto-save)
8769 * drafting to be done, before destroying the compose under
8771 debug_print("waiting for drafting to finish...\n");
8772 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8775 g_return_val_if_fail(compose, FALSE);
8776 gtkut_widget_get_uposition(compose->window, &x, &y);
8777 prefs_common.compose_x = x;
8778 prefs_common.compose_y = y;
8779 g_mutex_unlock(compose->mutex);
8780 compose_destroy(compose);
8785 * Add entry field for each address in list.
8786 * \param compose E-Mail composition object.
8787 * \param listAddress List of (formatted) E-Mail addresses.
8789 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8794 addr = ( gchar * ) node->data;
8795 compose_entry_append( compose, addr, COMPOSE_TO );
8796 node = g_list_next( node );
8800 static void compose_reply_from_messageview_real(MessageView *msgview, GSList *msginfo_list,
8801 guint action, gboolean opening_multiple)
8804 GSList *new_msglist = NULL;
8805 MsgInfo *tmp_msginfo = NULL;
8806 gboolean originally_enc = FALSE;
8807 Compose *compose = NULL;
8809 g_return_if_fail(msgview != NULL);
8811 g_return_if_fail(msginfo_list != NULL);
8813 if (g_slist_length(msginfo_list) == 1 && !opening_multiple) {
8814 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8815 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8817 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8818 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8819 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8820 orig_msginfo, mimeinfo);
8821 if (tmp_msginfo != NULL) {
8822 new_msglist = g_slist_append(NULL, tmp_msginfo);
8823 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8824 originally_enc = TRUE;
8830 if (!opening_multiple)
8831 body = messageview_get_selection(msgview);
8834 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8835 procmsg_msginfo_free(tmp_msginfo);
8836 g_slist_free(new_msglist);
8838 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8840 if (originally_enc) {
8841 compose_force_encryption(compose, compose->account, FALSE);
8847 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8850 if ((!prefs_common.forward_as_attachment || action != COMPOSE_FORWARD)
8851 && action != COMPOSE_FORWARD_AS_ATTACH && g_slist_length(msginfo_list) > 1) {
8852 GSList *cur = msginfo_list;
8853 gchar *msg = g_strdup_printf(_("You are about to reply to %d "
8854 "messages. Opening the windows "
8855 "could take some time. Do you "
8856 "want to continue?"),
8857 g_slist_length(msginfo_list));
8858 if (g_slist_length(msginfo_list) > 9
8859 && alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, "+" GTK_STOCK_YES, NULL)
8860 != G_ALERTALTERNATE) {
8865 /* We'll open multiple compose windows */
8866 /* let the WM place the next windows */
8867 compose_force_window_origin = FALSE;
8868 for (; cur; cur = cur->next) {
8870 tmplist.data = cur->data;
8871 tmplist.next = NULL;
8872 compose_reply_from_messageview_real(msgview, &tmplist, action, TRUE);
8874 compose_force_window_origin = TRUE;
8876 /* forwarding multiple mails as attachments is done via a
8877 * single compose window */
8878 compose_reply_from_messageview_real(msgview, msginfo_list, action, FALSE);
8882 void compose_set_position(Compose *compose, gint pos)
8884 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8886 gtkut_text_view_set_position(text, pos);
8889 gboolean compose_search_string(Compose *compose,
8890 const gchar *str, gboolean case_sens)
8892 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8894 return gtkut_text_view_search_string(text, str, case_sens);
8897 gboolean compose_search_string_backward(Compose *compose,
8898 const gchar *str, gboolean case_sens)
8900 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8902 return gtkut_text_view_search_string_backward(text, str, case_sens);