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);
1262 ifactory = gtk_item_factory_from_widget(compose->menubar);
1264 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1265 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1267 compose->updating = TRUE;
1268 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1269 if (!compose->replyinfo)
1270 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1271 compose->updating = FALSE;
1273 if (compose->deferred_destroy) {
1274 compose_destroy(compose);
1278 compose_extract_original_charset(compose);
1280 if (msginfo->folder && msginfo->folder->ret_rcpt)
1281 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1283 /* Set save folder */
1284 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1285 gchar *folderidentifier;
1287 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1288 folderidentifier = folder_item_get_identifier(msginfo->folder);
1289 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1290 g_free(folderidentifier);
1293 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1294 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1295 to_sender, followup_and_reply_to);
1296 compose_show_first_last_header(compose, TRUE);
1298 textview = (GTK_TEXT_VIEW(compose->text));
1299 textbuf = gtk_text_view_get_buffer(textview);
1300 compose_create_tags(textview, compose);
1302 undo_block(compose->undostruct);
1304 if (msginfo->folder && msginfo->folder->prefs &&
1305 msginfo->folder->prefs &&
1306 msginfo->folder->prefs->enable_default_dictionary &&
1308 gtkaspell_change_dict(compose->gtkaspell,
1309 msginfo->folder->prefs->default_dictionary);
1315 if (prefs_common.quotemark && *prefs_common.quotemark)
1316 qmark = prefs_common.quotemark;
1320 compose_quote_fmt(compose, compose->replyinfo,
1321 prefs_common.quotefmt,
1322 qmark, body, FALSE);
1324 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1325 compose_force_encryption(compose, account, FALSE);
1328 SIGNAL_BLOCK(textbuf);
1330 if (account->auto_sig)
1331 compose_insert_sig(compose, FALSE);
1333 compose_wrap_all(compose);
1335 SIGNAL_UNBLOCK(textbuf);
1337 gtk_widget_grab_focus(compose->text);
1339 undo_unblock(compose->undostruct);
1341 if (prefs_common.auto_exteditor)
1342 compose_exec_ext_editor(compose);
1344 compose->modified = FALSE;
1345 compose_set_title(compose);
1349 #define INSERT_FW_HEADER(var, hdr) \
1350 if (msginfo->var && *msginfo->var) { \
1351 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1352 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1353 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1356 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1357 gboolean as_attach, const gchar *body,
1358 gboolean no_extedit,
1362 GtkTextView *textview;
1363 GtkTextBuffer *textbuf;
1366 g_return_val_if_fail(msginfo != NULL, NULL);
1367 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1370 !(account = compose_guess_forward_account_from_msginfo
1372 account = cur_account;
1374 compose = compose_create(account, COMPOSE_FORWARD, batch);
1376 compose->updating = TRUE;
1377 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1378 if (!compose->fwdinfo)
1379 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1380 compose->updating = FALSE;
1382 if (compose->deferred_destroy) {
1383 compose_destroy(compose);
1387 compose_extract_original_charset(compose);
1389 if (msginfo->subject && *msginfo->subject) {
1390 gchar *buf, *buf2, *p;
1392 buf = p = g_strdup(msginfo->subject);
1393 p += subject_get_prefix_length(p);
1394 memmove(buf, p, strlen(p) + 1);
1396 buf2 = g_strdup_printf("Fw: %s", buf);
1397 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1403 textview = GTK_TEXT_VIEW(compose->text);
1404 textbuf = gtk_text_view_get_buffer(textview);
1405 compose_create_tags(textview, compose);
1407 undo_block(compose->undostruct);
1411 msgfile = procmsg_get_message_file_path(msginfo);
1412 if (!is_file_exist(msgfile))
1413 g_warning("%s: file not exist\n", msgfile);
1415 compose_attach_append(compose, msgfile, msgfile,
1421 MsgInfo *full_msginfo;
1423 compose->updating = TRUE;
1424 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1426 full_msginfo = procmsg_msginfo_copy(msginfo);
1427 compose->updating = FALSE;
1429 if (compose->deferred_destroy) {
1430 compose_destroy(compose);
1434 if (prefs_common.fw_quotemark &&
1435 *prefs_common.fw_quotemark)
1436 qmark = prefs_common.fw_quotemark;
1440 compose_quote_fmt(compose, full_msginfo,
1441 prefs_common.fw_quotefmt,
1442 qmark, body, FALSE);
1443 compose_attach_parts(compose, msginfo);
1445 procmsg_msginfo_free(full_msginfo);
1448 SIGNAL_BLOCK(textbuf);
1450 if (account->auto_sig)
1451 compose_insert_sig(compose, FALSE);
1453 compose_wrap_all(compose);
1455 SIGNAL_UNBLOCK(textbuf);
1457 gtk_text_buffer_get_start_iter(textbuf, &iter);
1458 gtk_text_buffer_place_cursor(textbuf, &iter);
1460 gtk_widget_grab_focus(compose->header_last->entry);
1462 if (!no_extedit && prefs_common.auto_exteditor)
1463 compose_exec_ext_editor(compose);
1466 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1467 gchar *folderidentifier;
1469 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1470 folderidentifier = folder_item_get_identifier(msginfo->folder);
1471 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1472 g_free(folderidentifier);
1475 undo_unblock(compose->undostruct);
1477 compose->modified = FALSE;
1478 compose_set_title(compose);
1482 #undef INSERT_FW_HEADER
1484 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1487 GtkTextView *textview;
1488 GtkTextBuffer *textbuf;
1492 gboolean single_mail = TRUE;
1494 g_return_val_if_fail(msginfo_list != NULL, NULL);
1496 if (g_slist_length(msginfo_list) > 1)
1497 single_mail = FALSE;
1499 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1500 if (((MsgInfo *)msginfo->data)->folder == NULL)
1503 /* guess account from first selected message */
1505 !(account = compose_guess_forward_account_from_msginfo
1506 (msginfo_list->data)))
1507 account = cur_account;
1509 g_return_val_if_fail(account != NULL, NULL);
1511 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1512 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1513 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1516 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1518 textview = GTK_TEXT_VIEW(compose->text);
1519 textbuf = gtk_text_view_get_buffer(textview);
1520 compose_create_tags(textview, compose);
1522 undo_block(compose->undostruct);
1523 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1524 compose->updating = TRUE;
1525 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1526 compose->updating = FALSE;
1527 if (compose->deferred_destroy) {
1528 compose_destroy(compose);
1532 if (!is_file_exist(msgfile))
1533 g_warning("%s: file not exist\n", msgfile);
1535 compose_attach_append(compose, msgfile, msgfile,
1541 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1542 if (info->subject && *info->subject) {
1543 gchar *buf, *buf2, *p;
1545 buf = p = g_strdup(info->subject);
1546 p += subject_get_prefix_length(p);
1547 memmove(buf, p, strlen(p) + 1);
1549 buf2 = g_strdup_printf("Fw: %s", buf);
1550 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1556 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1557 _("Fw: multiple emails"));
1560 SIGNAL_BLOCK(textbuf);
1562 if (account->auto_sig)
1563 compose_insert_sig(compose, FALSE);
1565 compose_wrap_all(compose);
1567 SIGNAL_UNBLOCK(textbuf);
1569 gtk_text_buffer_get_start_iter(textbuf, &iter);
1570 gtk_text_buffer_place_cursor(textbuf, &iter);
1572 gtk_widget_grab_focus(compose->header_last->entry);
1573 undo_unblock(compose->undostruct);
1574 compose->modified = FALSE;
1575 compose_set_title(compose);
1579 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1581 GtkTextIter start = *iter;
1582 GtkTextIter end_iter;
1583 int start_pos = gtk_text_iter_get_offset(&start);
1585 if (!compose->account->sig_sep)
1588 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1589 start_pos+strlen(compose->account->sig_sep));
1591 /* check sig separator */
1592 str = gtk_text_iter_get_text(&start, &end_iter);
1593 if (!strcmp(str, compose->account->sig_sep)) {
1595 /* check end of line (\n) */
1596 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1597 start_pos+strlen(compose->account->sig_sep));
1598 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1599 start_pos+strlen(compose->account->sig_sep)+1);
1600 tmp = gtk_text_iter_get_text(&start, &end_iter);
1601 if (!strcmp(tmp,"\n")) {
1613 static void compose_colorize_signature(Compose *compose)
1615 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1617 GtkTextIter end_iter;
1618 gtk_text_buffer_get_start_iter(buffer, &iter);
1619 while (gtk_text_iter_forward_line(&iter))
1620 if (compose_is_sig_separator(compose, buffer, &iter)) {
1621 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1622 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1626 void compose_reedit(MsgInfo *msginfo)
1628 Compose *compose = NULL;
1629 PrefsAccount *account = NULL;
1630 GtkTextView *textview;
1631 GtkTextBuffer *textbuf;
1635 gchar buf[BUFFSIZE];
1636 gboolean use_signing = FALSE;
1637 gboolean use_encryption = FALSE;
1638 gchar *privacy_system = NULL;
1640 g_return_if_fail(msginfo != NULL);
1641 g_return_if_fail(msginfo->folder != NULL);
1643 if (compose_put_existing_to_front(msginfo)) {
1647 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1648 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1649 gchar queueheader_buf[BUFFSIZE];
1652 /* Select Account from queue headers */
1653 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1654 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1655 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1656 account = account_find_from_id(id);
1658 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1659 sizeof(queueheader_buf), "NAID:")) {
1660 id = atoi(&queueheader_buf[strlen("NAID:")]);
1661 account = account_find_from_id(id);
1663 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1664 sizeof(queueheader_buf), "MAID:")) {
1665 id = atoi(&queueheader_buf[strlen("MAID:")]);
1666 account = account_find_from_id(id);
1668 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1669 sizeof(queueheader_buf), "S:")) {
1670 account = account_find_from_address(queueheader_buf);
1672 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1673 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1674 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1675 use_signing = param;
1678 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1679 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1680 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1681 use_encryption = param;
1683 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1684 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1685 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1687 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1688 sizeof(queueheader_buf), "X-Priority: ")) {
1689 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1690 compose->priority = param;
1693 account = msginfo->folder->folder->account;
1696 if (!account && prefs_common.reedit_account_autosel) {
1697 gchar from[BUFFSIZE];
1698 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1699 extract_address(from);
1700 account = account_find_from_address(from);
1704 account = cur_account;
1706 g_return_if_fail(account != NULL);
1708 compose = compose_create(account, COMPOSE_REEDIT, FALSE);
1709 if (privacy_system != NULL) {
1710 compose->privacy_system = privacy_system;
1711 compose_use_signing(compose, use_signing);
1712 compose_use_encryption(compose, use_encryption);
1713 compose_update_privacy_system_menu_item(compose, FALSE);
1715 activate_privacy_system(compose, account, FALSE);
1718 compose->updating = TRUE;
1719 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1720 compose->updating = FALSE;
1722 if (compose->deferred_destroy) {
1723 compose_destroy(compose);
1727 compose_extract_original_charset(compose);
1729 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1730 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1731 gchar queueheader_buf[BUFFSIZE];
1733 /* Set message save folder */
1734 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1737 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1738 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1739 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1741 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1742 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1744 GtkItemFactory *ifactory;
1745 ifactory = gtk_item_factory_from_widget(compose->menubar);
1746 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1751 if (compose_parse_header(compose, msginfo) < 0) {
1754 compose_reedit_set_entry(compose, msginfo);
1756 textview = GTK_TEXT_VIEW(compose->text);
1757 textbuf = gtk_text_view_get_buffer(textview);
1758 compose_create_tags(textview, compose);
1760 mark = gtk_text_buffer_get_insert(textbuf);
1761 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1763 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1764 G_CALLBACK(compose_changed_cb),
1767 if (procmime_msginfo_is_encrypted(msginfo)) {
1768 fp = procmime_get_first_encrypted_text_content(msginfo);
1770 compose_force_encryption(compose, account, TRUE);
1773 fp = procmime_get_first_text_content(msginfo);
1776 g_warning("Can't get text part\n");
1780 gboolean prev_autowrap = compose->autowrap;
1782 compose->autowrap = FALSE;
1783 while (fgets(buf, sizeof(buf), fp) != NULL) {
1785 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1787 compose_wrap_all_full(compose, FALSE);
1788 compose->autowrap = prev_autowrap;
1792 compose_attach_parts(compose, msginfo);
1794 compose_colorize_signature(compose);
1796 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1797 G_CALLBACK(compose_changed_cb),
1800 gtk_widget_grab_focus(compose->text);
1802 if (prefs_common.auto_exteditor) {
1803 compose_exec_ext_editor(compose);
1805 compose->modified = FALSE;
1806 compose_set_title(compose);
1809 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
1814 GtkItemFactory *ifactory;
1817 g_return_val_if_fail(msginfo != NULL, NULL);
1820 account = account_get_reply_account(msginfo,
1821 prefs_common.reply_account_autosel);
1822 g_return_val_if_fail(account != NULL, NULL);
1824 compose = compose_create(account, COMPOSE_REDIRECT, batch);
1825 ifactory = gtk_item_factory_from_widget(compose->menubar);
1826 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1827 compose->replyinfo = NULL;
1828 compose->fwdinfo = NULL;
1830 compose_show_first_last_header(compose, TRUE);
1832 gtk_widget_grab_focus(compose->header_last->entry);
1834 compose->updating = TRUE;
1835 filename = procmsg_get_message_file_path(msginfo);
1836 compose->updating = FALSE;
1838 if (compose->deferred_destroy) {
1839 compose_destroy(compose);
1844 if (filename == NULL)
1847 compose->redirect_filename = filename;
1849 /* Set save folder */
1850 item = msginfo->folder;
1851 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1852 gchar *folderidentifier;
1854 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1855 folderidentifier = folder_item_get_identifier(item);
1856 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1857 g_free(folderidentifier);
1860 compose_attach_parts(compose, msginfo);
1862 if (msginfo->subject)
1863 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1865 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1867 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1868 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1870 compose_colorize_signature(compose);
1872 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1873 menu_set_sensitive(ifactory, "/Add...", FALSE);
1874 menu_set_sensitive(ifactory, "/Remove", FALSE);
1875 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1877 ifactory = gtk_item_factory_from_widget(compose->menubar);
1878 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1879 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1880 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1881 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1882 menu_set_sensitive(ifactory, "/Edit", FALSE);
1883 menu_set_sensitive(ifactory, "/Options", FALSE);
1884 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1885 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1887 if (compose->toolbar->draft_btn)
1888 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1889 if (compose->toolbar->insert_btn)
1890 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1891 if (compose->toolbar->attach_btn)
1892 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1893 if (compose->toolbar->sig_btn)
1894 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1895 if (compose->toolbar->exteditor_btn)
1896 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1897 if (compose->toolbar->linewrap_current_btn)
1898 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1899 if (compose->toolbar->linewrap_all_btn)
1900 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1902 compose->modified = FALSE;
1903 compose_set_title(compose);
1907 GList *compose_get_compose_list(void)
1909 return compose_list;
1912 void compose_entry_append(Compose *compose, const gchar *address,
1913 ComposeEntryType type)
1917 gboolean in_quote = FALSE;
1918 if (!address || *address == '\0') return;
1925 header = N_("Bcc:");
1927 case COMPOSE_REPLYTO:
1928 header = N_("Reply-To:");
1930 case COMPOSE_NEWSGROUPS:
1931 header = N_("Newsgroups:");
1933 case COMPOSE_FOLLOWUPTO:
1934 header = N_( "Followup-To:");
1941 header = prefs_common.trans_hdr ? gettext(header) : header;
1943 cur = begin = (gchar *)address;
1945 /* we separate the line by commas, but not if we're inside a quoted
1947 while (*cur != '\0') {
1949 in_quote = !in_quote;
1950 if (*cur == ',' && !in_quote) {
1951 gchar *tmp = g_strdup(begin);
1953 tmp[cur-begin]='\0';
1958 compose_add_header_entry(compose, header, tmp);
1965 gchar *tmp = g_strdup(begin);
1967 tmp[cur-begin]='\0';
1972 compose_add_header_entry(compose, header, tmp);
1977 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1979 static GdkColor yellow;
1980 static GdkColor black;
1981 static gboolean yellow_initialised = FALSE;
1985 if (!yellow_initialised) {
1986 gdk_color_parse("#f5f6be", &yellow);
1987 gdk_color_parse("#000000", &black);
1988 yellow_initialised = gdk_colormap_alloc_color(
1989 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
1990 yellow_initialised &= gdk_colormap_alloc_color(
1991 gdk_colormap_get_system(), &black, FALSE, TRUE);
1994 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1995 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1996 if (gtk_entry_get_text(entry) &&
1997 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1998 if (yellow_initialised) {
1999 gtk_widget_modify_base(
2000 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2001 GTK_STATE_NORMAL, &yellow);
2002 gtk_widget_modify_text(
2003 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2004 GTK_STATE_NORMAL, &black);
2010 void compose_toolbar_cb(gint action, gpointer data)
2012 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2013 Compose *compose = (Compose*)toolbar_item->parent;
2015 g_return_if_fail(compose != NULL);
2019 compose_send_cb(compose, 0, NULL);
2022 compose_send_later_cb(compose, 0, NULL);
2025 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2028 compose_insert_file_cb(compose, 0, NULL);
2031 compose_attach_cb(compose, 0, NULL);
2034 compose_insert_sig(compose, FALSE);
2037 compose_ext_editor_cb(compose, 0, NULL);
2039 case A_LINEWRAP_CURRENT:
2040 compose_beautify_paragraph(compose, NULL, TRUE);
2042 case A_LINEWRAP_ALL:
2043 compose_wrap_all_full(compose, TRUE);
2046 compose_address_cb(compose, 0, NULL);
2049 case A_CHECK_SPELLING:
2050 compose_check_all(compose);
2058 static void compose_entries_set(Compose *compose, const gchar *mailto)
2062 gchar *subject = NULL;
2067 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
2070 compose_entry_append(compose, to, COMPOSE_TO);
2072 compose_entry_append(compose, cc, COMPOSE_CC);
2074 if (!g_utf8_validate (subject, -1, NULL)) {
2075 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2076 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2079 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2083 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2084 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2087 gboolean prev_autowrap = compose->autowrap;
2089 compose->autowrap = FALSE;
2091 mark = gtk_text_buffer_get_insert(buffer);
2092 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2094 if (!g_utf8_validate (body, -1, NULL)) {
2095 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2096 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2099 gtk_text_buffer_insert(buffer, &iter, body, -1);
2101 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2103 compose->autowrap = prev_autowrap;
2104 if (compose->autowrap)
2105 compose_wrap_all(compose);
2114 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2116 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2117 {"Cc:", NULL, TRUE},
2118 {"References:", NULL, FALSE},
2119 {"Bcc:", NULL, TRUE},
2120 {"Newsgroups:", NULL, TRUE},
2121 {"Followup-To:", NULL, TRUE},
2122 {"List-Post:", NULL, FALSE},
2123 {"X-Priority:", NULL, FALSE},
2124 {NULL, NULL, FALSE}};
2140 g_return_val_if_fail(msginfo != NULL, -1);
2142 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2143 procheader_get_header_fields(fp, hentry);
2146 if (hentry[H_REPLY_TO].body != NULL) {
2147 if (hentry[H_REPLY_TO].body[0] != '\0') {
2149 conv_unmime_header(hentry[H_REPLY_TO].body,
2152 g_free(hentry[H_REPLY_TO].body);
2153 hentry[H_REPLY_TO].body = NULL;
2155 if (hentry[H_CC].body != NULL) {
2156 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2157 g_free(hentry[H_CC].body);
2158 hentry[H_CC].body = NULL;
2160 if (hentry[H_REFERENCES].body != NULL) {
2161 if (compose->mode == COMPOSE_REEDIT)
2162 compose->references = hentry[H_REFERENCES].body;
2164 compose->references = compose_parse_references
2165 (hentry[H_REFERENCES].body, msginfo->msgid);
2166 g_free(hentry[H_REFERENCES].body);
2168 hentry[H_REFERENCES].body = NULL;
2170 if (hentry[H_BCC].body != NULL) {
2171 if (compose->mode == COMPOSE_REEDIT)
2173 conv_unmime_header(hentry[H_BCC].body, NULL);
2174 g_free(hentry[H_BCC].body);
2175 hentry[H_BCC].body = NULL;
2177 if (hentry[H_NEWSGROUPS].body != NULL) {
2178 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2179 hentry[H_NEWSGROUPS].body = NULL;
2181 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2182 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2183 compose->followup_to =
2184 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2187 g_free(hentry[H_FOLLOWUP_TO].body);
2188 hentry[H_FOLLOWUP_TO].body = NULL;
2190 if (hentry[H_LIST_POST].body != NULL) {
2193 extract_address(hentry[H_LIST_POST].body);
2194 if (hentry[H_LIST_POST].body[0] != '\0') {
2195 scan_mailto_url(hentry[H_LIST_POST].body,
2196 &to, NULL, NULL, NULL, NULL);
2198 g_free(compose->ml_post);
2199 compose->ml_post = to;
2202 g_free(hentry[H_LIST_POST].body);
2203 hentry[H_LIST_POST].body = NULL;
2206 /* CLAWS - X-Priority */
2207 if (compose->mode == COMPOSE_REEDIT)
2208 if (hentry[H_X_PRIORITY].body != NULL) {
2211 priority = atoi(hentry[H_X_PRIORITY].body);
2212 g_free(hentry[H_X_PRIORITY].body);
2214 hentry[H_X_PRIORITY].body = NULL;
2216 if (priority < PRIORITY_HIGHEST ||
2217 priority > PRIORITY_LOWEST)
2218 priority = PRIORITY_NORMAL;
2220 compose->priority = priority;
2223 if (compose->mode == COMPOSE_REEDIT) {
2224 if (msginfo->inreplyto && *msginfo->inreplyto)
2225 compose->inreplyto = g_strdup(msginfo->inreplyto);
2229 if (msginfo->msgid && *msginfo->msgid)
2230 compose->inreplyto = g_strdup(msginfo->msgid);
2232 if (!compose->references) {
2233 if (msginfo->msgid && *msginfo->msgid) {
2234 if (msginfo->inreplyto && *msginfo->inreplyto)
2235 compose->references =
2236 g_strdup_printf("<%s>\n\t<%s>",
2240 compose->references =
2241 g_strconcat("<", msginfo->msgid, ">",
2243 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2244 compose->references =
2245 g_strconcat("<", msginfo->inreplyto, ">",
2253 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2255 GSList *ref_id_list, *cur;
2259 ref_id_list = references_list_append(NULL, ref);
2260 if (!ref_id_list) return NULL;
2261 if (msgid && *msgid)
2262 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2267 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2268 /* "<" + Message-ID + ">" + CR+LF+TAB */
2269 len += strlen((gchar *)cur->data) + 5;
2271 if (len > MAX_REFERENCES_LEN) {
2272 /* remove second message-ID */
2273 if (ref_id_list && ref_id_list->next &&
2274 ref_id_list->next->next) {
2275 g_free(ref_id_list->next->data);
2276 ref_id_list = g_slist_remove
2277 (ref_id_list, ref_id_list->next->data);
2279 slist_free_strings(ref_id_list);
2280 g_slist_free(ref_id_list);
2287 new_ref = g_string_new("");
2288 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2289 if (new_ref->len > 0)
2290 g_string_append(new_ref, "\n\t");
2291 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2294 slist_free_strings(ref_id_list);
2295 g_slist_free(ref_id_list);
2297 new_ref_str = new_ref->str;
2298 g_string_free(new_ref, FALSE);
2303 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2304 const gchar *fmt, const gchar *qmark,
2305 const gchar *body, gboolean rewrap)
2307 static MsgInfo dummyinfo;
2308 gchar *quote_str = NULL;
2310 gboolean prev_autowrap;
2311 const gchar *trimmed_body = body;
2312 gint cursor_pos = -1;
2313 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2314 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2319 SIGNAL_BLOCK(buffer);
2322 msginfo = &dummyinfo;
2324 if (qmark != NULL) {
2325 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2326 quote_fmt_scan_string(qmark);
2329 buf = quote_fmt_get_buffer();
2331 alertpanel_error(_("Quote mark format error."));
2333 Xstrdup_a(quote_str, buf, goto error)
2336 if (fmt && *fmt != '\0') {
2337 while (trimmed_body && strlen(trimmed_body) > 1
2338 && trimmed_body[0]=='\n')
2341 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2342 quote_fmt_scan_string(fmt);
2345 buf = quote_fmt_get_buffer();
2347 alertpanel_error(_("Message reply/forward format error."));
2353 prev_autowrap = compose->autowrap;
2354 compose->autowrap = FALSE;
2356 mark = gtk_text_buffer_get_insert(buffer);
2357 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2358 if (g_utf8_validate(buf, -1, NULL)) {
2359 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2361 gchar *tmpout = NULL;
2362 tmpout = conv_codeset_strdup
2363 (buf, conv_get_locale_charset_str_no_utf8(),
2365 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2367 tmpout = g_malloc(strlen(buf)*2+1);
2368 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2370 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2374 cursor_pos = quote_fmt_get_cursor_pos();
2375 compose->set_cursor_pos = cursor_pos;
2376 if (cursor_pos == -1) {
2379 gtk_text_buffer_get_start_iter(buffer, &iter);
2380 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2381 gtk_text_buffer_place_cursor(buffer, &iter);
2383 compose->autowrap = prev_autowrap;
2384 if (compose->autowrap && rewrap)
2385 compose_wrap_all(compose);
2392 SIGNAL_UNBLOCK(buffer);
2398 /* if ml_post is of type addr@host and from is of type
2399 * addr-anything@host, return TRUE
2401 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2403 gchar *left_ml = NULL;
2404 gchar *right_ml = NULL;
2405 gchar *left_from = NULL;
2406 gchar *right_from = NULL;
2407 gboolean result = FALSE;
2409 if (!ml_post || !from)
2412 left_ml = g_strdup(ml_post);
2413 if (strstr(left_ml, "@")) {
2414 right_ml = strstr(left_ml, "@")+1;
2415 *(strstr(left_ml, "@")) = '\0';
2418 left_from = g_strdup(from);
2419 if (strstr(left_from, "@")) {
2420 right_from = strstr(left_from, "@")+1;
2421 *(strstr(left_from, "@")) = '\0';
2424 if (left_ml && left_from && right_ml && right_from
2425 && !strncmp(left_from, left_ml, strlen(left_ml))
2426 && !strcmp(right_from, right_ml)) {
2435 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2437 gchar *my_addr1, *my_addr2;
2439 if (!addr1 || !addr2)
2442 Xstrdup_a(my_addr1, addr1, return FALSE);
2443 Xstrdup_a(my_addr2, addr2, return FALSE);
2445 extract_address(my_addr1);
2446 extract_address(my_addr2);
2448 return !strcmp(my_addr1, my_addr2);
2451 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2452 gboolean to_all, gboolean to_ml,
2454 gboolean followup_and_reply_to)
2456 GSList *cc_list = NULL;
2459 gchar *replyto = NULL;
2460 GHashTable *to_table;
2462 gboolean reply_to_ml = FALSE;
2463 gboolean default_reply_to = FALSE;
2465 g_return_if_fail(compose->account != NULL);
2466 g_return_if_fail(msginfo != NULL);
2468 reply_to_ml = to_ml && compose->ml_post;
2470 default_reply_to = msginfo->folder &&
2471 msginfo->folder->prefs->enable_default_reply_to;
2473 if (compose->account->protocol != A_NNTP) {
2474 if (reply_to_ml && !default_reply_to) {
2476 gboolean is_subscr = is_subscription(compose->ml_post,
2479 /* normal answer to ml post with a reply-to */
2480 compose_entry_append(compose,
2483 if (compose->replyto
2484 && !same_address(compose->ml_post, compose->replyto))
2485 compose_entry_append(compose,
2489 /* answer to subscription confirmation */
2490 if (compose->replyto)
2491 compose_entry_append(compose,
2494 else if (msginfo->from)
2495 compose_entry_append(compose,
2500 else if (!(to_all || to_sender) && default_reply_to) {
2501 compose_entry_append(compose,
2502 msginfo->folder->prefs->default_reply_to,
2504 compose_entry_mark_default_to(compose,
2505 msginfo->folder->prefs->default_reply_to);
2510 Xstrdup_a(tmp1, msginfo->from, return);
2511 extract_address(tmp1);
2512 if (to_all || to_sender ||
2513 !account_find_from_address(tmp1))
2514 compose_entry_append(compose,
2515 (compose->replyto && !to_sender)
2516 ? compose->replyto :
2517 msginfo->from ? msginfo->from : "",
2519 else if (!to_all && !to_sender) {
2520 /* reply to the last list of recipients */
2521 compose_entry_append(compose,
2522 msginfo->to ? msginfo->to : "",
2524 compose_entry_append(compose,
2525 msginfo->cc ? msginfo->cc : "",
2530 if (to_sender || (compose->followup_to &&
2531 !strncmp(compose->followup_to, "poster", 6)))
2532 compose_entry_append
2534 (compose->replyto ? compose->replyto :
2535 msginfo->from ? msginfo->from : ""),
2538 else if (followup_and_reply_to || to_all) {
2539 compose_entry_append
2541 (compose->replyto ? compose->replyto :
2542 msginfo->from ? msginfo->from : ""),
2545 compose_entry_append
2547 compose->followup_to ? compose->followup_to :
2548 compose->newsgroups ? compose->newsgroups : "",
2549 COMPOSE_NEWSGROUPS);
2552 compose_entry_append
2554 compose->followup_to ? compose->followup_to :
2555 compose->newsgroups ? compose->newsgroups : "",
2556 COMPOSE_NEWSGROUPS);
2559 if (msginfo->subject && *msginfo->subject) {
2563 buf = p = g_strdup(msginfo->subject);
2564 p += subject_get_prefix_length(p);
2565 memmove(buf, p, strlen(p) + 1);
2567 buf2 = g_strdup_printf("Re: %s", buf);
2568 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2573 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2575 if (to_ml && compose->ml_post) return;
2576 if (!to_all || compose->account->protocol == A_NNTP) return;
2578 if (compose->replyto) {
2579 Xstrdup_a(replyto, compose->replyto, return);
2580 extract_address(replyto);
2582 if (msginfo->from) {
2583 Xstrdup_a(from, msginfo->from, return);
2584 extract_address(from);
2587 if (replyto && from)
2588 cc_list = address_list_append_with_comments(cc_list, from);
2589 if (to_all && msginfo->folder &&
2590 msginfo->folder->prefs->enable_default_reply_to)
2591 cc_list = address_list_append_with_comments(cc_list,
2592 msginfo->folder->prefs->default_reply_to);
2593 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2594 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2596 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2598 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2599 if (compose->account)
2600 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2601 GINT_TO_POINTER(1));
2603 /* remove address on To: and that of current account */
2604 for (cur = cc_list; cur != NULL; ) {
2605 GSList *next = cur->next;
2608 addr = g_strdup(cur->data);
2609 extract_address(addr);
2611 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2612 cc_list = g_slist_remove(cc_list, cur->data);
2614 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2618 hash_free_strings(to_table);
2619 g_hash_table_destroy(to_table);
2622 for (cur = cc_list; cur != NULL; cur = cur->next)
2623 compose_entry_append(compose, (gchar *)cur->data,
2625 slist_free_strings(cc_list);
2626 g_slist_free(cc_list);
2631 #define SET_ENTRY(entry, str) \
2634 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2637 #define SET_ADDRESS(type, str) \
2640 compose_entry_append(compose, str, type); \
2643 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2645 g_return_if_fail(msginfo != NULL);
2647 SET_ENTRY(subject_entry, msginfo->subject);
2648 SET_ENTRY(from_name, msginfo->from);
2649 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2650 SET_ADDRESS(COMPOSE_CC, compose->cc);
2651 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2652 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2653 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2654 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2656 compose_update_priority_menu_item(compose);
2657 compose_update_privacy_system_menu_item(compose, FALSE);
2658 compose_show_first_last_header(compose, TRUE);
2664 static void compose_insert_sig(Compose *compose, gboolean replace)
2666 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2667 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2669 GtkTextIter iter, iter_end;
2671 gboolean prev_autowrap;
2674 g_return_if_fail(compose->account != NULL);
2676 prev_autowrap = compose->autowrap;
2677 compose->autowrap = FALSE;
2679 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2680 G_CALLBACK(compose_changed_cb),
2683 mark = gtk_text_buffer_get_insert(buffer);
2684 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2685 cur_pos = gtk_text_iter_get_offset (&iter);
2687 gtk_text_buffer_get_end_iter(buffer, &iter);
2689 if (replace && compose->sig_str) {
2691 GtkTextIter first_iter, start_iter, end_iter;
2693 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2695 if (compose->sig_str[0] == '\0')
2698 found = gtk_text_iter_forward_search(&first_iter,
2700 GTK_TEXT_SEARCH_TEXT_ONLY,
2701 &start_iter, &end_iter,
2705 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2710 g_free(compose->sig_str);
2711 compose->sig_str = compose_get_signature_str(compose);
2712 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2713 compose->sig_str = g_strdup("");
2715 cur_pos = gtk_text_iter_get_offset(&iter);
2716 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2718 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2719 gtk_text_iter_forward_char(&iter);
2720 gtk_text_iter_forward_char(&iter);
2721 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2722 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2724 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2725 cur_pos = gtk_text_buffer_get_char_count (buffer);
2727 /* put the cursor where it should be
2728 * either where the quote_fmt says, either before the signature */
2729 if (compose->set_cursor_pos < 0)
2730 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2732 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2733 compose->set_cursor_pos);
2735 gtk_text_buffer_place_cursor(buffer, &iter);
2736 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2737 G_CALLBACK(compose_changed_cb),
2740 compose->autowrap = prev_autowrap;
2741 if (compose->autowrap)
2742 compose_wrap_all(compose);
2745 static gchar *compose_get_signature_str(Compose *compose)
2747 gchar *sig_body = NULL;
2748 gchar *sig_str = NULL;
2749 gchar *utf8_sig_str = NULL;
2751 g_return_val_if_fail(compose->account != NULL, NULL);
2753 if (!compose->account->sig_path)
2756 if (compose->account->sig_type == SIG_FILE) {
2757 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2758 g_warning("can't open signature file: %s\n",
2759 compose->account->sig_path);
2764 if (compose->account->sig_type == SIG_COMMAND)
2765 sig_body = get_command_output(compose->account->sig_path);
2769 tmp = file_read_to_str(compose->account->sig_path);
2772 sig_body = normalize_newlines(tmp);
2776 if (compose->account->sig_sep) {
2777 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2781 sig_str = g_strconcat("\n\n", sig_body, NULL);
2784 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2785 utf8_sig_str = sig_str;
2787 utf8_sig_str = conv_codeset_strdup
2788 (sig_str, conv_get_locale_charset_str_no_utf8(),
2794 return utf8_sig_str;
2797 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2800 GtkTextBuffer *buffer;
2803 const gchar *cur_encoding;
2804 gchar buf[BUFFSIZE];
2807 gboolean prev_autowrap;
2808 gboolean badtxt = FALSE;
2810 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2812 if ((fp = g_fopen(file, "rb")) == NULL) {
2813 FILE_OP_ERROR(file, "fopen");
2814 return COMPOSE_INSERT_READ_ERROR;
2817 prev_autowrap = compose->autowrap;
2818 compose->autowrap = FALSE;
2820 text = GTK_TEXT_VIEW(compose->text);
2821 buffer = gtk_text_view_get_buffer(text);
2822 mark = gtk_text_buffer_get_insert(buffer);
2823 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2825 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2826 G_CALLBACK(text_inserted),
2829 cur_encoding = conv_get_locale_charset_str_no_utf8();
2831 while (fgets(buf, sizeof(buf), fp) != NULL) {
2834 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2835 str = g_strdup(buf);
2837 str = conv_codeset_strdup
2838 (buf, cur_encoding, CS_INTERNAL);
2841 /* strip <CR> if DOS/Windows file,
2842 replace <CR> with <LF> if Macintosh file. */
2845 if (len > 0 && str[len - 1] != '\n') {
2847 if (str[len] == '\r') str[len] = '\n';
2850 gtk_text_buffer_insert(buffer, &iter, str, -1);
2854 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2855 G_CALLBACK(text_inserted),
2857 compose->autowrap = prev_autowrap;
2858 if (compose->autowrap)
2859 compose_wrap_all(compose);
2864 return COMPOSE_INSERT_INVALID_CHARACTER;
2866 return COMPOSE_INSERT_SUCCESS;
2869 static void compose_attach_append(Compose *compose, const gchar *file,
2870 const gchar *filename,
2871 const gchar *content_type)
2879 GtkListStore *store;
2881 gboolean has_binary = FALSE;
2883 if (!is_file_exist(file)) {
2884 g_warning("File %s doesn't exist\n", filename);
2887 if ((size = get_file_size(file)) < 0) {
2888 g_warning("Can't get file size of %s\n", filename);
2892 alertpanel_notice(_("File %s is empty."), filename);
2895 if ((fp = g_fopen(file, "rb")) == NULL) {
2896 alertpanel_error(_("Can't read %s."), filename);
2901 ainfo = g_new0(AttachInfo, 1);
2902 auto_ainfo = g_auto_pointer_new_with_free
2903 (ainfo, (GFreeFunc) compose_attach_info_free);
2904 ainfo->file = g_strdup(file);
2907 ainfo->content_type = g_strdup(content_type);
2908 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2910 MsgFlags flags = {0, 0};
2912 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
2913 ainfo->encoding = ENC_7BIT;
2915 ainfo->encoding = ENC_8BIT;
2917 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2918 if (msginfo && msginfo->subject)
2919 name = g_strdup(msginfo->subject);
2921 name = g_path_get_basename(filename ? filename : file);
2923 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2925 procmsg_msginfo_free(msginfo);
2927 if (!g_ascii_strncasecmp(content_type, "text", 4))
2928 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
2930 ainfo->encoding = ENC_BASE64;
2931 name = g_path_get_basename(filename ? filename : file);
2932 ainfo->name = g_strdup(name);
2936 ainfo->content_type = procmime_get_mime_type(file);
2937 if (!ainfo->content_type) {
2938 ainfo->content_type =
2939 g_strdup("application/octet-stream");
2940 ainfo->encoding = ENC_BASE64;
2941 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2943 procmime_get_encoding_for_text_file(file, &has_binary);
2945 ainfo->encoding = ENC_BASE64;
2946 name = g_path_get_basename(filename ? filename : file);
2947 ainfo->name = g_strdup(name);
2951 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
2952 g_free(ainfo->content_type);
2953 ainfo->content_type = g_strdup("application/octet-stream");
2957 size_text = to_human_readable(size);
2959 store = GTK_LIST_STORE(gtk_tree_view_get_model
2960 (GTK_TREE_VIEW(compose->attach_clist)));
2962 gtk_list_store_append(store, &iter);
2963 gtk_list_store_set(store, &iter,
2964 COL_MIMETYPE, ainfo->content_type,
2965 COL_SIZE, size_text,
2966 COL_NAME, ainfo->name,
2968 COL_AUTODATA, auto_ainfo,
2971 g_auto_pointer_free(auto_ainfo);
2974 static void compose_use_signing(Compose *compose, gboolean use_signing)
2976 GtkItemFactory *ifactory;
2977 GtkWidget *menuitem = NULL;
2979 compose->use_signing = use_signing;
2980 ifactory = gtk_item_factory_from_widget(compose->menubar);
2981 menuitem = gtk_item_factory_get_item
2982 (ifactory, "/Options/Sign");
2983 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2987 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2989 GtkItemFactory *ifactory;
2990 GtkWidget *menuitem = NULL;
2992 compose->use_encryption = use_encryption;
2993 ifactory = gtk_item_factory_from_widget(compose->menubar);
2994 menuitem = gtk_item_factory_get_item
2995 (ifactory, "/Options/Encrypt");
2997 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3001 #define NEXT_PART_NOT_CHILD(info) \
3003 node = info->node; \
3004 while (node->children) \
3005 node = g_node_last_child(node); \
3006 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3009 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3013 MimeInfo *firsttext = NULL;
3014 MimeInfo *encrypted = NULL;
3017 const gchar *partname = NULL;
3019 mimeinfo = procmime_scan_message(msginfo);
3020 if (!mimeinfo) return;
3022 if (mimeinfo->node->children == NULL) {
3023 procmime_mimeinfo_free_all(mimeinfo);
3027 /* find first content part */
3028 child = (MimeInfo *) mimeinfo->node->children->data;
3029 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3030 child = (MimeInfo *)child->node->children->data;
3032 if (child->type == MIMETYPE_TEXT) {
3034 debug_print("First text part found\n");
3035 } else if (compose->mode == COMPOSE_REEDIT &&
3036 child->type == MIMETYPE_APPLICATION &&
3037 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3038 encrypted = (MimeInfo *)child->node->parent->data;
3041 child = (MimeInfo *) mimeinfo->node->children->data;
3042 while (child != NULL) {
3043 if (child == encrypted) {
3044 /* skip this part of tree */
3045 NEXT_PART_NOT_CHILD(child);
3049 if (child->type == MIMETYPE_MULTIPART) {
3050 /* get the actual content */
3051 child = procmime_mimeinfo_next(child);
3055 if (child == firsttext) {
3056 child = procmime_mimeinfo_next(child);
3060 outfile = procmime_get_tmp_file_name(child);
3061 if (procmime_get_part(outfile, child) < 0)
3062 g_warning("Can't get the part of multipart message.");
3064 gchar *content_type;
3066 content_type = procmime_get_content_type_str(child->type, child->subtype);
3068 /* if we meet a pgp signature, we don't attach it, but
3069 * we force signing. */
3070 if (strcmp(content_type, "application/pgp-signature")) {
3071 partname = procmime_mimeinfo_get_parameter(child, "filename");
3072 if (partname == NULL)
3073 partname = procmime_mimeinfo_get_parameter(child, "name");
3074 if (partname == NULL)
3076 compose_attach_append(compose, outfile,
3077 partname, content_type);
3079 compose_force_signing(compose, compose->account);
3081 g_free(content_type);
3084 NEXT_PART_NOT_CHILD(child);
3086 procmime_mimeinfo_free_all(mimeinfo);
3089 #undef NEXT_PART_NOT_CHILD
3094 WAIT_FOR_INDENT_CHAR,
3095 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3098 /* return indent length, we allow:
3099 indent characters followed by indent characters or spaces/tabs,
3100 alphabets and numbers immediately followed by indent characters,
3101 and the repeating sequences of the above
3102 If quote ends with multiple spaces, only the first one is included. */
3103 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3104 const GtkTextIter *start, gint *len)
3106 GtkTextIter iter = *start;
3110 IndentState state = WAIT_FOR_INDENT_CHAR;
3113 gint alnum_count = 0;
3114 gint space_count = 0;
3117 if (prefs_common.quote_chars == NULL) {
3121 while (!gtk_text_iter_ends_line(&iter)) {
3122 wc = gtk_text_iter_get_char(&iter);
3123 if (g_unichar_iswide(wc))
3125 clen = g_unichar_to_utf8(wc, ch);
3129 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3130 is_space = g_unichar_isspace(wc);
3132 if (state == WAIT_FOR_INDENT_CHAR) {
3133 if (!is_indent && !g_unichar_isalnum(wc))
3136 quote_len += alnum_count + space_count + 1;
3137 alnum_count = space_count = 0;
3138 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3141 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3142 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3146 else if (is_indent) {
3147 quote_len += alnum_count + space_count + 1;
3148 alnum_count = space_count = 0;
3151 state = WAIT_FOR_INDENT_CHAR;
3155 gtk_text_iter_forward_char(&iter);
3158 if (quote_len > 0 && space_count > 0)
3164 if (quote_len > 0) {
3166 gtk_text_iter_forward_chars(&iter, quote_len);
3167 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3173 /* return TRUE if the line is itemized */
3174 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3175 const GtkTextIter *start)
3177 GtkTextIter iter = *start;
3182 if (gtk_text_iter_ends_line(&iter))
3186 wc = gtk_text_iter_get_char(&iter);
3187 if (!g_unichar_isspace(wc))
3189 gtk_text_iter_forward_char(&iter);
3190 if (gtk_text_iter_ends_line(&iter))
3194 clen = g_unichar_to_utf8(wc, ch);
3198 if (!strchr("*-+", ch[0]))
3201 gtk_text_iter_forward_char(&iter);
3202 if (gtk_text_iter_ends_line(&iter))
3204 wc = gtk_text_iter_get_char(&iter);
3205 if (g_unichar_isspace(wc))
3211 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3212 const GtkTextIter *start,
3213 GtkTextIter *break_pos,
3217 GtkTextIter iter = *start, line_end = *start;
3218 PangoLogAttr *attrs;
3225 gboolean can_break = FALSE;
3226 gboolean do_break = FALSE;
3227 gboolean was_white = FALSE;
3228 gboolean prev_dont_break = FALSE;
3230 gtk_text_iter_forward_to_line_end(&line_end);
3231 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3232 len = g_utf8_strlen(str, -1);
3233 /* g_print("breaking line: %d: %s (len = %d)\n",
3234 gtk_text_iter_get_line(&iter), str, len); */
3235 attrs = g_new(PangoLogAttr, len + 1);
3237 pango_default_break(str, -1, NULL, attrs, len + 1);
3241 /* skip quote and leading spaces */
3242 for (i = 0; *p != '\0' && i < len; i++) {
3245 wc = g_utf8_get_char(p);
3246 if (i >= quote_len && !g_unichar_isspace(wc))
3248 if (g_unichar_iswide(wc))
3250 else if (*p == '\t')
3254 p = g_utf8_next_char(p);
3257 for (; *p != '\0' && i < len; i++) {
3258 PangoLogAttr *attr = attrs + i;
3262 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3265 was_white = attr->is_white;
3267 /* don't wrap URI */
3268 if ((uri_len = get_uri_len(p)) > 0) {
3270 if (pos > 0 && col > max_col) {
3280 wc = g_utf8_get_char(p);
3281 if (g_unichar_iswide(wc)) {
3283 if (prev_dont_break && can_break && attr->is_line_break)
3285 } else if (*p == '\t')
3289 if (pos > 0 && col > max_col) {
3294 if (*p == '-' || *p == '/')
3295 prev_dont_break = TRUE;
3297 prev_dont_break = FALSE;
3299 p = g_utf8_next_char(p);
3303 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3308 *break_pos = *start;
3309 gtk_text_iter_set_line_offset(break_pos, pos);
3314 static gboolean compose_join_next_line(Compose *compose,
3315 GtkTextBuffer *buffer,
3317 const gchar *quote_str)
3319 GtkTextIter iter_ = *iter, cur, prev, next, end;
3320 PangoLogAttr attrs[3];
3322 gchar *next_quote_str;
3325 gboolean keep_cursor = FALSE;
3327 if (!gtk_text_iter_forward_line(&iter_) ||
3328 gtk_text_iter_ends_line(&iter_))
3331 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3333 if ((quote_str || next_quote_str) &&
3334 strcmp2(quote_str, next_quote_str) != 0) {
3335 g_free(next_quote_str);
3338 g_free(next_quote_str);
3341 if (quote_len > 0) {
3342 gtk_text_iter_forward_chars(&end, quote_len);
3343 if (gtk_text_iter_ends_line(&end))
3347 /* don't join itemized lines */
3348 if (compose_is_itemized(buffer, &end))
3351 /* don't join signature separator */
3352 if (compose_is_sig_separator(compose, buffer, &iter_))
3355 /* delete quote str */
3357 gtk_text_buffer_delete(buffer, &iter_, &end);
3359 /* don't join line breaks put by the user */
3361 gtk_text_iter_backward_char(&cur);
3362 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3363 gtk_text_iter_forward_char(&cur);
3367 gtk_text_iter_forward_char(&cur);
3368 /* delete linebreak and extra spaces */
3369 while (gtk_text_iter_backward_char(&cur)) {
3370 wc1 = gtk_text_iter_get_char(&cur);
3371 if (!g_unichar_isspace(wc1))
3376 while (!gtk_text_iter_ends_line(&cur)) {
3377 wc1 = gtk_text_iter_get_char(&cur);
3378 if (!g_unichar_isspace(wc1))
3380 gtk_text_iter_forward_char(&cur);
3383 if (!gtk_text_iter_equal(&prev, &next)) {
3386 mark = gtk_text_buffer_get_insert(buffer);
3387 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3388 if (gtk_text_iter_equal(&prev, &cur))
3390 gtk_text_buffer_delete(buffer, &prev, &next);
3394 /* insert space if required */
3395 gtk_text_iter_backward_char(&prev);
3396 wc1 = gtk_text_iter_get_char(&prev);
3397 wc2 = gtk_text_iter_get_char(&next);
3398 gtk_text_iter_forward_char(&next);
3399 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3400 pango_default_break(str, -1, NULL, attrs, 3);
3401 if (!attrs[1].is_line_break ||
3402 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3403 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3405 gtk_text_iter_backward_char(&iter_);
3406 gtk_text_buffer_place_cursor(buffer, &iter_);
3415 #define ADD_TXT_POS(bp_, ep_, pti_) \
3416 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3417 last = last->next; \
3418 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3419 last->next = NULL; \
3421 g_warning("alloc error scanning URIs\n"); \
3424 static gboolean automatic_break = FALSE;
3425 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3427 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3428 GtkTextBuffer *buffer;
3429 GtkTextIter iter, break_pos, end_of_line;
3430 gchar *quote_str = NULL;
3432 gboolean wrap_quote = prefs_common.linewrap_quote;
3433 gboolean prev_autowrap = compose->autowrap;
3434 gint startq_offset = -1, noq_offset = -1;
3435 gint uri_start = -1, uri_stop = -1;
3436 gint nouri_start = -1, nouri_stop = -1;
3437 gint num_blocks = 0;
3438 gint quotelevel = -1;
3440 compose->autowrap = FALSE;
3442 buffer = gtk_text_view_get_buffer(text);
3443 undo_wrapping(compose->undostruct, TRUE);
3448 mark = gtk_text_buffer_get_insert(buffer);
3449 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3452 /* move to paragraph start */
3453 gtk_text_iter_set_line_offset(&iter, 0);
3454 if (gtk_text_iter_ends_line(&iter)) {
3455 while (gtk_text_iter_ends_line(&iter) &&
3456 gtk_text_iter_forward_line(&iter))
3459 while (gtk_text_iter_backward_line(&iter)) {
3460 if (gtk_text_iter_ends_line(&iter)) {
3461 gtk_text_iter_forward_line(&iter);
3467 /* go until paragraph end (empty line) */
3469 while (!gtk_text_iter_ends_line(&iter)) {
3470 gchar *scanpos = NULL;
3471 /* parse table - in order of priority */
3473 const gchar *needle; /* token */
3475 /* token search function */
3476 gchar *(*search) (const gchar *haystack,
3477 const gchar *needle);
3478 /* part parsing function */
3479 gboolean (*parse) (const gchar *start,
3480 const gchar *scanpos,
3484 /* part to URI function */
3485 gchar *(*build_uri) (const gchar *bp,
3489 static struct table parser[] = {
3490 {"http://", strcasestr, get_uri_part, make_uri_string},
3491 {"https://", strcasestr, get_uri_part, make_uri_string},
3492 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3493 {"www.", strcasestr, get_uri_part, make_http_string},
3494 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3495 {"@", strcasestr, get_email_part, make_email_string}
3497 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3498 gint last_index = PARSE_ELEMS;
3500 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3503 if (!prev_autowrap && num_blocks == 0) {
3505 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3506 G_CALLBACK(text_inserted),
3509 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3512 uri_start = uri_stop = -1;
3514 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3518 if (startq_offset == -1) {
3519 startq_offset = gtk_text_iter_get_offset(&iter);
3523 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3524 if (startq_offset == -1)
3525 startq_offset = gtk_text_iter_get_offset(&iter);
3526 quotelevel = get_quote_level(quote_str, prefs_common.quote_chars);
3527 if (quotelevel > 2) {
3528 /* recycle colors */
3529 if (prefs_common.recycle_quote_colors)
3535 if (startq_offset == -1)
3536 noq_offset = gtk_text_iter_get_offset(&iter);
3540 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3543 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3544 prefs_common.linewrap_len,
3546 GtkTextIter prev, next, cur;
3548 if (prev_autowrap != FALSE || force) {
3549 automatic_break = TRUE;
3550 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3551 automatic_break = FALSE;
3552 } else if (quote_str && wrap_quote) {
3553 automatic_break = TRUE;
3554 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3555 automatic_break = FALSE;
3558 /* remove trailing spaces */
3560 gtk_text_iter_backward_char(&cur);
3562 while (!gtk_text_iter_starts_line(&cur)) {
3565 gtk_text_iter_backward_char(&cur);
3566 wc = gtk_text_iter_get_char(&cur);
3567 if (!g_unichar_isspace(wc))
3571 if (!gtk_text_iter_equal(&prev, &next)) {
3572 gtk_text_buffer_delete(buffer, &prev, &next);
3574 gtk_text_iter_forward_char(&break_pos);
3578 gtk_text_buffer_insert(buffer, &break_pos,
3582 compose_join_next_line(compose, buffer, &iter, quote_str);
3584 /* move iter to current line start */
3585 gtk_text_iter_set_line_offset(&iter, 0);
3592 /* move iter to next line start */
3597 if (!prev_autowrap && num_blocks > 0) {
3599 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3600 G_CALLBACK(text_inserted),
3604 while (!gtk_text_iter_ends_line(&end_of_line)) {
3605 gtk_text_iter_forward_char(&end_of_line);
3607 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3609 nouri_start = gtk_text_iter_get_offset(&iter);
3610 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3612 walk_pos = gtk_text_iter_get_offset(&iter);
3613 /* FIXME: this looks phony. scanning for anything in the parse table */
3614 for (n = 0; n < PARSE_ELEMS; n++) {
3617 tmp = parser[n].search(walk, parser[n].needle);
3619 if (scanpos == NULL || tmp < scanpos) {
3628 /* check if URI can be parsed */
3629 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3630 (const gchar **)&ep, FALSE)
3631 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3635 strlen(parser[last_index].needle);
3638 uri_start = walk_pos + (bp - o_walk);
3639 uri_stop = walk_pos + (ep - o_walk);
3643 gtk_text_iter_forward_line(&iter);
3646 if (startq_offset != -1) {
3647 GtkTextIter startquote, endquote;
3648 gtk_text_buffer_get_iter_at_offset(
3649 buffer, &startquote, startq_offset);
3651 switch (quotelevel) {
3652 case 0: gtk_text_buffer_apply_tag_by_name(
3653 buffer, "quote0", &startquote, &endquote);
3655 case 1: gtk_text_buffer_apply_tag_by_name(
3656 buffer, "quote1", &startquote, &endquote);
3658 case 2: gtk_text_buffer_apply_tag_by_name(
3659 buffer, "quote2", &startquote, &endquote);
3663 } else if (noq_offset != -1) {
3664 GtkTextIter startnoquote, endnoquote;
3665 gtk_text_buffer_get_iter_at_offset(
3666 buffer, &startnoquote, noq_offset);
3668 gtk_text_buffer_remove_tag_by_name(
3669 buffer, "quote0", &startnoquote, &endnoquote);
3670 gtk_text_buffer_remove_tag_by_name(
3671 buffer, "quote1", &startnoquote, &endnoquote);
3672 gtk_text_buffer_remove_tag_by_name(
3673 buffer, "quote2", &startnoquote, &endnoquote);
3678 GtkTextIter nouri_start_iter, nouri_end_iter;
3679 gtk_text_buffer_get_iter_at_offset(
3680 buffer, &nouri_start_iter, nouri_start);
3681 gtk_text_buffer_get_iter_at_offset(
3682 buffer, &nouri_end_iter, nouri_stop);
3683 gtk_text_buffer_remove_tag_by_name(
3684 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3686 if (uri_start > 0 && uri_stop > 0) {
3687 GtkTextIter uri_start_iter, uri_end_iter;
3688 gtk_text_buffer_get_iter_at_offset(
3689 buffer, &uri_start_iter, uri_start);
3690 gtk_text_buffer_get_iter_at_offset(
3691 buffer, &uri_end_iter, uri_stop);
3692 gtk_text_buffer_apply_tag_by_name(
3693 buffer, "link", &uri_start_iter, &uri_end_iter);
3699 undo_wrapping(compose->undostruct, FALSE);
3700 compose->autowrap = prev_autowrap;
3703 void compose_action_cb(void *data)
3705 Compose *compose = (Compose *)data;
3706 compose_wrap_all(compose);
3709 static void compose_wrap_all(Compose *compose)
3711 compose_wrap_all_full(compose, FALSE);
3714 static void compose_wrap_all_full(Compose *compose, gboolean force)
3716 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3717 GtkTextBuffer *buffer;
3720 buffer = gtk_text_view_get_buffer(text);
3722 gtk_text_buffer_get_start_iter(buffer, &iter);
3723 while (!gtk_text_iter_is_end(&iter))
3724 compose_beautify_paragraph(compose, &iter, force);
3728 static void compose_set_title(Compose *compose)
3734 edited = compose->modified ? _(" [Edited]") : "";
3736 subject = gtk_editable_get_chars(
3737 GTK_EDITABLE(compose->subject_entry), 0, -1);
3739 if (subject && strlen(subject))
3740 str = g_strdup_printf(_("%s - Compose message%s"),
3743 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3744 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3750 * compose_current_mail_account:
3752 * Find a current mail account (the currently selected account, or the
3753 * default account, if a news account is currently selected). If a
3754 * mail account cannot be found, display an error message.
3756 * Return value: Mail account, or NULL if not found.
3758 static PrefsAccount *
3759 compose_current_mail_account(void)
3763 if (cur_account && cur_account->protocol != A_NNTP)
3766 ac = account_get_default();
3767 if (!ac || ac->protocol == A_NNTP) {
3768 alertpanel_error(_("Account for sending mail is not specified.\n"
3769 "Please select a mail account before sending."));
3776 #define QUOTE_IF_REQUIRED(out, str) \
3778 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3782 len = strlen(str) + 3; \
3783 if ((__tmp = alloca(len)) == NULL) { \
3784 g_warning("can't allocate memory\n"); \
3785 g_string_free(header, TRUE); \
3788 g_snprintf(__tmp, len, "\"%s\"", str); \
3793 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3794 g_warning("can't allocate memory\n"); \
3795 g_string_free(header, TRUE); \
3798 strcpy(__tmp, str); \
3804 #define QUOTE_IF_REQUIRED_NORMAL(out, str, errret) \
3806 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3810 len = strlen(str) + 3; \
3811 if ((__tmp = alloca(len)) == NULL) { \
3812 g_warning("can't allocate memory\n"); \
3815 g_snprintf(__tmp, len, "\"%s\"", str); \
3820 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3821 g_warning("can't allocate memory\n"); \
3824 strcpy(__tmp, str); \
3830 static void compose_select_account(Compose *compose, PrefsAccount *account,
3833 GtkItemFactory *ifactory;
3836 g_return_if_fail(account != NULL);
3838 compose->account = account;
3840 if (account->name && *account->name) {
3842 QUOTE_IF_REQUIRED_NORMAL(buf, account->name, return);
3843 from = g_strdup_printf("%s <%s>",
3844 buf, account->address);
3845 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
3847 from = g_strdup_printf("<%s>",
3849 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
3854 compose_set_title(compose);
3856 ifactory = gtk_item_factory_from_widget(compose->menubar);
3858 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3859 menu_set_active(ifactory, "/Options/Sign", TRUE);
3861 menu_set_active(ifactory, "/Options/Sign", FALSE);
3862 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3863 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3865 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3867 activate_privacy_system(compose, account, FALSE);
3869 if (!init && compose->mode != COMPOSE_REDIRECT)
3870 compose_insert_sig(compose, TRUE);
3873 gboolean compose_check_for_valid_recipient(Compose *compose) {
3874 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3875 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3876 gboolean recipient_found = FALSE;
3880 /* free to and newsgroup list */
3881 slist_free_strings(compose->to_list);
3882 g_slist_free(compose->to_list);
3883 compose->to_list = NULL;
3885 slist_free_strings(compose->newsgroup_list);
3886 g_slist_free(compose->newsgroup_list);
3887 compose->newsgroup_list = NULL;
3889 /* search header entries for to and newsgroup entries */
3890 for (list = compose->header_list; list; list = list->next) {
3893 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3894 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3896 if (entry[0] != '\0') {
3897 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3898 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3899 compose->to_list = address_list_append(compose->to_list, entry);
3900 recipient_found = TRUE;
3903 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3904 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3905 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3906 recipient_found = TRUE;
3913 return recipient_found;
3916 static gboolean compose_check_for_set_recipients(Compose *compose)
3918 if (compose->account->set_autocc && compose->account->auto_cc) {
3919 gboolean found_other = FALSE;
3921 /* search header entries for to and newsgroup entries */
3922 for (list = compose->header_list; list; list = list->next) {
3925 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3926 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3928 if (strcmp(entry, compose->account->auto_cc)
3929 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3939 aval = alertpanel(_("Send"),
3940 _("The only recipient is the default CC address. Send anyway?"),
3941 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3942 if (aval != G_ALERTALTERNATE)
3946 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3947 gboolean found_other = FALSE;
3949 /* search header entries for to and newsgroup entries */
3950 for (list = compose->header_list; list; list = list->next) {
3953 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3954 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3956 if (strcmp(entry, compose->account->auto_cc)
3957 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3967 aval = alertpanel(_("Send"),
3968 _("The only recipient is the default BCC address. Send anyway?"),
3969 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3970 if (aval != G_ALERTALTERNATE)
3977 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3981 if (compose_check_for_valid_recipient(compose) == FALSE) {
3982 alertpanel_error(_("Recipient is not specified."));
3986 if (compose_check_for_set_recipients(compose) == FALSE) {
3990 if (!compose->batch) {
3991 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3992 if (*str == '\0' && check_subject == TRUE) {
3995 aval = alertpanel(_("Send"),
3996 _("Subject is empty. Send it anyway?"),
3997 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3998 if (aval != G_ALERTALTERNATE)
4006 gint compose_send(Compose *compose)
4011 gchar *msgpath = NULL;
4012 gboolean discard_window = FALSE;
4014 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS
4015 || compose->batch == TRUE)
4016 discard_window = TRUE;
4018 compose_allow_user_actions (compose, FALSE);
4019 compose->sending = TRUE;
4021 if (compose_check_entries(compose, TRUE) == FALSE) {
4022 if (compose->batch) {
4023 gtk_widget_show_all(compose->window);
4028 val = compose_queue(compose, &msgnum, &folder, &msgpath);
4031 if (compose->batch) {
4032 gtk_widget_show_all(compose->window);
4035 alertpanel_error(_("Could not queue message for sending:\n\n"
4036 "Charset conversion failed."));
4037 } else if (val == -3) {
4038 alertpanel_error(_("Could not queue message for sending:\n\n"
4039 "Signature failed."));
4040 } else if (val == -2 && errno != 0) {
4041 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
4043 alertpanel_error(_("Could not queue message for sending."));
4048 if (discard_window) {
4049 compose->sending = FALSE;
4050 compose_close(compose);
4051 /* No more compose access in the normal codepath
4052 * after this point! */
4057 alertpanel_error(_("The message was queued but could not be "
4058 "sent.\nUse \"Send queued messages\" from "
4059 "the main window to retry."));
4060 if (!discard_window) {
4066 if (msgpath == NULL) {
4067 msgpath = folder_item_fetch_msg(folder, msgnum);
4068 val = procmsg_send_message_queue(msgpath);
4071 val = procmsg_send_message_queue(msgpath);
4075 if (!discard_window) {
4076 compose->sending = FALSE;
4077 compose_allow_user_actions (compose, TRUE);
4079 folder_item_remove_msg(folder, msgnum);
4080 folder_item_scan(folder);
4085 folder_item_remove_msg(folder, msgnum);
4086 folder_item_scan(folder);
4087 if (!discard_window)
4088 compose_close(compose);
4090 alertpanel_error(_("The message was queued but could not be "
4091 "sent.\nUse \"Send queued messages\" from "
4092 "the main window to retry."));
4093 if (!discard_window) {
4102 compose_allow_user_actions (compose, TRUE);
4103 compose->sending = FALSE;
4104 compose->modified = TRUE;
4109 static gboolean compose_use_attach(Compose *compose)
4111 GtkTreeModel *model = gtk_tree_view_get_model
4112 (GTK_TREE_VIEW(compose->attach_clist));
4113 return gtk_tree_model_iter_n_children(model, NULL) > 0;
4116 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
4119 gchar buf[BUFFSIZE];
4121 gboolean first_to_address;
4122 gboolean first_cc_address;
4124 ComposeHeaderEntry *headerentry;
4125 const gchar *headerentryname;
4129 debug_print("Writing redirect header\n");
4131 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
4132 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
4134 first_to_address = TRUE;
4135 for (list = compose->header_list; list; list = list->next) {
4136 headerentry = ((ComposeHeaderEntry *)list->data);
4137 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4139 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
4140 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4141 Xstrdup_a(str, entstr, return -1);
4143 if (str[0] != '\0') {
4144 compose_convert_header
4145 (compose, buf, sizeof(buf), str,
4146 strlen("Resent-To") + 2, TRUE);
4148 if (first_to_address) {
4149 fprintf(fp, "Resent-To: ");
4150 first_to_address = FALSE;
4154 fprintf(fp, "%s", buf);
4158 if (!first_to_address) {
4162 first_cc_address = TRUE;
4163 for (list = compose->header_list; list; list = list->next) {
4164 headerentry = ((ComposeHeaderEntry *)list->data);
4165 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4167 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
4168 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4169 Xstrdup_a(str, strg, return -1);
4171 if (str[0] != '\0') {
4172 compose_convert_header
4173 (compose, buf, sizeof(buf), str,
4174 strlen("Resent-Cc") + 2, TRUE);
4176 if (first_cc_address) {
4177 fprintf(fp, "Resent-Cc: ");
4178 first_cc_address = FALSE;
4182 fprintf(fp, "%s", buf);
4186 if (!first_cc_address) {
4193 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
4195 gchar buf[BUFFSIZE];
4197 const gchar *entstr;
4198 /* struct utsname utsbuf; */
4200 g_return_val_if_fail(fp != NULL, -1);
4201 g_return_val_if_fail(compose->account != NULL, -1);
4202 g_return_val_if_fail(compose->account->address != NULL, -1);
4205 get_rfc822_date(buf, sizeof(buf));
4206 fprintf(fp, "Resent-Date: %s\n", buf);
4209 if (compose->account->name && *compose->account->name) {
4210 compose_convert_header
4211 (compose, buf, sizeof(buf), compose->account->name,
4212 strlen("From: "), TRUE);
4213 fprintf(fp, "Resent-From: %s <%s>\n",
4214 buf, compose->account->address);
4216 fprintf(fp, "Resent-From: %s\n", compose->account->address);
4219 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4220 if (*entstr != '\0') {
4221 Xstrdup_a(str, entstr, return -1);
4224 compose_convert_header(compose, buf, sizeof(buf), str,
4225 strlen("Subject: "), FALSE);
4226 fprintf(fp, "Subject: %s\n", buf);
4230 /* Resent-Message-ID */
4231 if (compose->account->gen_msgid) {
4232 generate_msgid(buf, sizeof(buf));
4233 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
4234 compose->msgid = g_strdup(buf);
4237 compose_redirect_write_headers_from_headerlist(compose, fp);
4239 /* separator between header and body */
4245 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
4249 gchar buf[BUFFSIZE];
4251 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
4252 FILE_OP_ERROR(compose->redirect_filename, "fopen");
4256 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
4257 /* should filter returnpath, delivered-to */
4258 if (g_ascii_strncasecmp(buf, "Return-Path:",
4259 strlen("Return-Path:")) == 0 ||
4260 g_ascii_strncasecmp(buf, "Delivered-To:",
4261 strlen("Delivered-To:")) == 0 ||
4262 g_ascii_strncasecmp(buf, "Received:",
4263 strlen("Received:")) == 0 ||
4264 g_ascii_strncasecmp(buf, "Subject:",
4265 strlen("Subject:")) == 0 ||
4266 g_ascii_strncasecmp(buf, "X-UIDL:",
4267 strlen("X-UIDL:")) == 0)
4270 if (fputs(buf, fdest) == -1)
4273 if (!prefs_common.redirect_keep_from) {
4274 if (g_ascii_strncasecmp(buf, "From:",
4275 strlen("From:")) == 0) {
4276 fputs(" (by way of ", fdest);
4277 if (compose->account->name
4278 && *compose->account->name) {
4279 compose_convert_header
4280 (compose, buf, sizeof(buf),
4281 compose->account->name,
4284 fprintf(fdest, "%s <%s>",
4286 compose->account->address);
4288 fprintf(fdest, "%s",
4289 compose->account->address);
4294 if (fputs("\n", fdest) == -1)
4298 compose_redirect_write_headers(compose, fdest);
4300 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4301 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4314 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
4316 GtkTextBuffer *buffer;
4317 GtkTextIter start, end;
4320 const gchar *out_codeset;
4321 EncodingType encoding;
4322 MimeInfo *mimemsg, *mimetext;
4325 /* create message MimeInfo */
4326 mimemsg = procmime_mimeinfo_new();
4327 mimemsg->type = MIMETYPE_MESSAGE;
4328 mimemsg->subtype = g_strdup("rfc822");
4329 mimemsg->content = MIMECONTENT_MEM;
4330 mimemsg->tmp = TRUE; /* must free content later */
4331 mimemsg->data.mem = compose_get_header(compose);
4333 /* Create text part MimeInfo */
4334 /* get all composed text */
4335 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4336 gtk_text_buffer_get_start_iter(buffer, &start);
4337 gtk_text_buffer_get_end_iter(buffer, &end);
4338 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4339 if (is_ascii_str(chars)) {
4342 out_codeset = CS_US_ASCII;
4343 encoding = ENC_7BIT;
4345 const gchar *src_codeset = CS_INTERNAL;
4347 out_codeset = conv_get_charset_str(compose->out_encoding);
4350 gchar *test_conv_global_out = NULL;
4351 gchar *test_conv_reply = NULL;
4353 /* automatic mode. be automatic. */
4354 codeconv_set_strict(TRUE);
4356 out_codeset = conv_get_outgoing_charset_str();
4358 debug_print("trying to convert to %s\n", out_codeset);
4359 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4362 if (!test_conv_global_out && compose->orig_charset
4363 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4364 out_codeset = compose->orig_charset;
4365 debug_print("failure; trying to convert to %s\n", out_codeset);
4366 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4369 if (!test_conv_global_out && !test_conv_reply) {
4371 out_codeset = CS_INTERNAL;
4372 debug_print("failure; finally using %s\n", out_codeset);
4374 g_free(test_conv_global_out);
4375 g_free(test_conv_reply);
4376 codeconv_set_strict(FALSE);
4379 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4380 out_codeset = CS_ISO_8859_1;
4382 if (prefs_common.encoding_method == CTE_BASE64)
4383 encoding = ENC_BASE64;
4384 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4385 encoding = ENC_QUOTED_PRINTABLE;
4386 else if (prefs_common.encoding_method == CTE_8BIT)
4387 encoding = ENC_8BIT;
4389 encoding = procmime_get_encoding_for_charset(out_codeset);
4391 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4392 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4394 if (action == COMPOSE_WRITE_FOR_SEND) {
4395 codeconv_set_strict(TRUE);
4396 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4397 codeconv_set_strict(FALSE);
4403 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4404 "to the specified %s charset.\n"
4405 "Send it as %s?"), out_codeset, src_codeset);
4406 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4407 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4410 if (aval != G_ALERTALTERNATE) {
4415 out_codeset = src_codeset;
4421 out_codeset = src_codeset;
4427 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4428 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4429 strstr(buf, "\nFrom ") != NULL) {
4430 encoding = ENC_QUOTED_PRINTABLE;
4434 mimetext = procmime_mimeinfo_new();
4435 mimetext->content = MIMECONTENT_MEM;
4436 mimetext->tmp = TRUE; /* must free content later */
4437 mimetext->data.mem = buf;
4438 mimetext->type = MIMETYPE_TEXT;
4439 mimetext->subtype = g_strdup("plain");
4440 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4441 g_strdup(out_codeset));
4442 /* protect trailing spaces when signing message */
4443 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4444 privacy_system_can_sign(compose->privacy_system)) {
4445 encoding = ENC_QUOTED_PRINTABLE;
4448 /* check for line length limit */
4449 if (action == COMPOSE_WRITE_FOR_SEND &&
4450 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4451 check_line_length(buf, 1000, &line) < 0) {
4455 msg = g_strdup_printf
4456 (_("Line %d exceeds the line length limit (998 bytes).\n"
4457 "The contents of the message might be broken on the way to the delivery.\n"
4459 "Send it anyway?"), line + 1);
4460 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4462 if (aval != G_ALERTALTERNATE) {
4467 if (encoding != ENC_UNKNOWN)
4468 procmime_encode_content(mimetext, encoding);
4470 /* append attachment parts */
4471 if (compose_use_attach(compose)) {
4472 MimeInfo *mimempart;
4473 gchar *boundary = NULL;
4474 mimempart = procmime_mimeinfo_new();
4475 mimempart->content = MIMECONTENT_EMPTY;
4476 mimempart->type = MIMETYPE_MULTIPART;
4477 mimempart->subtype = g_strdup("mixed");
4481 boundary = generate_mime_boundary(NULL);
4482 } while (strstr(buf, boundary) != NULL);
4484 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4487 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4489 g_node_append(mimempart->node, mimetext->node);
4490 g_node_append(mimemsg->node, mimempart->node);
4492 compose_add_attachments(compose, mimempart);
4494 g_node_append(mimemsg->node, mimetext->node);
4496 /* sign message if sending */
4497 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4498 privacy_system_can_sign(compose->privacy_system))
4499 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4502 procmime_write_mimeinfo(mimemsg, fp);
4504 procmime_mimeinfo_free_all(mimemsg);
4509 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4511 GtkTextBuffer *buffer;
4512 GtkTextIter start, end;
4517 if ((fp = g_fopen(file, "wb")) == NULL) {
4518 FILE_OP_ERROR(file, "fopen");
4522 /* chmod for security */
4523 if (change_file_mode_rw(fp, file) < 0) {
4524 FILE_OP_ERROR(file, "chmod");
4525 g_warning("can't change file mode\n");
4528 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4529 gtk_text_buffer_get_start_iter(buffer, &start);
4530 gtk_text_buffer_get_end_iter(buffer, &end);
4531 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4533 chars = conv_codeset_strdup
4534 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4537 if (!chars) return -1;
4540 len = strlen(chars);
4541 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4542 FILE_OP_ERROR(file, "fwrite");
4551 if (fclose(fp) == EOF) {
4552 FILE_OP_ERROR(file, "fclose");
4559 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4562 MsgInfo *msginfo = compose->targetinfo;
4564 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4565 if (!msginfo) return -1;
4567 if (!force && MSG_IS_LOCKED(msginfo->flags))
4570 item = msginfo->folder;
4571 g_return_val_if_fail(item != NULL, -1);
4573 if (procmsg_msg_exist(msginfo) &&
4574 (folder_has_parent_of_type(item, F_QUEUE) ||
4575 folder_has_parent_of_type(item, F_DRAFT)
4576 || msginfo == compose->autosaved_draft)) {
4577 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4578 g_warning("can't remove the old message\n");
4586 void compose_remove_draft(Compose *compose)
4589 MsgInfo *msginfo = compose->targetinfo;
4590 drafts = account_get_special_folder(compose->account, F_DRAFT);
4592 if (procmsg_msg_exist(msginfo)) {
4593 folder_item_remove_msg(drafts, msginfo->msgnum);
4598 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath)
4600 return compose_queue_sub (compose, msgnum, item, msgpath, FALSE);
4602 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath, gboolean check_subject)
4609 static gboolean lock = FALSE;
4610 PrefsAccount *mailac = NULL, *newsac = NULL;
4612 debug_print("queueing message...\n");
4613 g_return_val_if_fail(compose->account != NULL, -1);
4617 if (compose_check_entries(compose, check_subject) == FALSE) {
4622 if (!compose->to_list && !compose->newsgroup_list) {
4623 g_warning("can't get recipient list.");
4628 if (compose->to_list) {
4629 if (compose->account->protocol != A_NNTP)
4630 mailac = compose->account;
4631 else if (cur_account && cur_account->protocol != A_NNTP)
4632 mailac = cur_account;
4633 else if (!(mailac = compose_current_mail_account())) {
4635 alertpanel_error(_("No account for sending mails available!"));
4640 if (compose->newsgroup_list) {
4641 if (compose->account->protocol == A_NNTP)
4642 newsac = compose->account;
4643 else if (!newsac->protocol != A_NNTP) {
4645 alertpanel_error(_("No account for posting news available!"));
4650 /* write queue header */
4651 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4652 G_DIR_SEPARATOR, compose);
4653 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4654 FILE_OP_ERROR(tmp, "fopen");
4659 if (change_file_mode_rw(fp, tmp) < 0) {
4660 FILE_OP_ERROR(tmp, "chmod");
4661 g_warning("can't change file mode\n");
4664 /* queueing variables */
4665 fprintf(fp, "AF:\n");
4666 fprintf(fp, "NF:0\n");
4667 fprintf(fp, "PS:10\n");
4668 fprintf(fp, "SRH:1\n");
4669 fprintf(fp, "SFN:\n");
4670 fprintf(fp, "DSR:\n");
4672 fprintf(fp, "MID:<%s>\n", compose->msgid);
4674 fprintf(fp, "MID:\n");
4675 fprintf(fp, "CFG:\n");
4676 fprintf(fp, "PT:0\n");
4677 fprintf(fp, "S:%s\n", compose->account->address);
4678 fprintf(fp, "RQ:\n");
4680 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4682 fprintf(fp, "SSV:\n");
4684 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4686 fprintf(fp, "NSV:\n");
4687 fprintf(fp, "SSH:\n");
4688 /* write recepient list */
4689 if (compose->to_list) {
4690 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4691 for (cur = compose->to_list->next; cur != NULL;
4693 fprintf(fp, ",<%s>", (gchar *)cur->data);
4696 /* write newsgroup list */
4697 if (compose->newsgroup_list) {
4699 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4700 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4701 fprintf(fp, ",%s", (gchar *)cur->data);
4704 /* Sylpheed account IDs */
4706 fprintf(fp, "MAID:%d\n", mailac->account_id);
4708 fprintf(fp, "NAID:%d\n", newsac->account_id);
4711 if (compose->privacy_system != NULL) {
4712 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4713 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4714 if (compose->use_encryption) {
4716 if (mailac && mailac->encrypt_to_self) {
4717 GSList *tmp_list = g_slist_copy(compose->to_list);
4718 tmp_list = g_slist_append(tmp_list, compose->account->address);
4719 encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
4720 g_slist_free(tmp_list);
4722 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4724 if (encdata != NULL) {
4725 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4726 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4727 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4729 } /* else we finally dont want to encrypt */
4731 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4732 /* and if encdata was null, it means there's been a problem in
4739 /* Save copy folder */
4740 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4741 gchar *savefolderid;
4743 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4744 fprintf(fp, "SCF:%s\n", savefolderid);
4745 g_free(savefolderid);
4747 /* Save copy folder */
4748 if (compose->return_receipt) {
4749 fprintf(fp, "RRCPT:1\n");
4751 /* Message-ID of message replying to */
4752 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4755 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4756 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4759 /* Message-ID of message forwarding to */
4760 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4763 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4764 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4769 if (compose->redirect_filename != NULL) {
4770 if (compose_redirect_write_to_file(compose, fp) < 0) {
4779 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4784 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4788 if (fclose(fp) == EOF) {
4789 FILE_OP_ERROR(tmp, "fclose");
4795 queue = account_get_special_folder(compose->account, F_QUEUE);
4797 g_warning("can't find queue folder\n");
4802 folder_item_scan(queue);
4803 if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
4804 g_warning("can't queue the message\n");
4810 if (msgpath == NULL) {
4816 if (compose->mode == COMPOSE_REEDIT) {
4817 compose_remove_reedit_target(compose, FALSE);
4820 if ((msgnum != NULL) && (item != NULL)) {
4828 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4831 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4833 struct stat statbuf;
4834 gchar *type, *subtype;
4835 GtkTreeModel *model;
4838 model = gtk_tree_view_get_model(tree_view);
4840 if (!gtk_tree_model_get_iter_first(model, &iter))
4843 gtk_tree_model_get(model, &iter,
4847 mimepart = procmime_mimeinfo_new();
4848 mimepart->content = MIMECONTENT_FILE;
4849 mimepart->data.filename = g_strdup(ainfo->file);
4850 mimepart->tmp = FALSE; /* or we destroy our attachment */
4851 mimepart->offset = 0;
4853 stat(ainfo->file, &statbuf);
4854 mimepart->length = statbuf.st_size;
4856 type = g_strdup(ainfo->content_type);
4858 if (!strchr(type, '/')) {
4860 type = g_strdup("application/octet-stream");
4863 subtype = strchr(type, '/') + 1;
4864 *(subtype - 1) = '\0';
4865 mimepart->type = procmime_get_media_type(type);
4866 mimepart->subtype = g_strdup(subtype);
4869 if (mimepart->type == MIMETYPE_MESSAGE &&
4870 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4871 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4873 g_hash_table_insert(mimepart->typeparameters,
4874 g_strdup("name"), g_strdup(ainfo->name));
4875 g_hash_table_insert(mimepart->dispositionparameters,
4876 g_strdup("filename"), g_strdup(ainfo->name));
4877 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4880 if (compose->use_signing) {
4881 if (ainfo->encoding == ENC_7BIT)
4882 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4883 else if (ainfo->encoding == ENC_8BIT)
4884 ainfo->encoding = ENC_BASE64;
4887 procmime_encode_content(mimepart, ainfo->encoding);
4889 g_node_append(parent->node, mimepart->node);
4890 } while (gtk_tree_model_iter_next(model, &iter));
4893 #define IS_IN_CUSTOM_HEADER(header) \
4894 (compose->account->add_customhdr && \
4895 custom_header_find(compose->account->customhdr_list, header) != NULL)
4897 static void compose_add_headerfield_from_headerlist(Compose *compose,
4899 const gchar *fieldname,
4900 const gchar *seperator)
4902 gchar *str, *fieldname_w_colon, *trans_fieldname;
4903 gboolean add_field = FALSE;
4905 ComposeHeaderEntry *headerentry;
4906 const gchar * headerentryname;
4909 if (IS_IN_CUSTOM_HEADER(fieldname))
4912 debug_print("Adding %s-fields\n", fieldname);
4914 fieldstr = g_string_sized_new(64);
4916 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4917 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4919 for (list = compose->header_list; list; list = list->next) {
4920 headerentry = ((ComposeHeaderEntry *)list->data);
4921 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4923 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4924 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4926 if (str[0] != '\0') {
4928 g_string_append(fieldstr, seperator);
4929 g_string_append(fieldstr, str);
4938 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4939 compose_convert_header
4940 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4941 strlen(fieldname) + 2, TRUE);
4942 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4946 g_free(fieldname_w_colon);
4947 g_string_free(fieldstr, TRUE);
4952 static gchar *compose_get_header(Compose *compose)
4954 gchar buf[BUFFSIZE];
4955 const gchar *entry_str;
4959 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4961 gchar *from_name = NULL, *from_address = NULL;
4964 g_return_val_if_fail(compose->account != NULL, NULL);
4965 g_return_val_if_fail(compose->account->address != NULL, NULL);
4967 header = g_string_sized_new(64);
4970 if (compose->account->add_date) {
4971 get_rfc822_date(buf, sizeof(buf));
4972 g_string_append_printf(header, "Date: %s\n", buf);
4977 if (compose->account->name && *compose->account->name) {
4979 QUOTE_IF_REQUIRED(buf, compose->account->name);
4980 tmp = g_strdup_printf("%s <%s>",
4981 buf, compose->account->address);
4983 tmp = g_strdup_printf("%s",
4984 compose->account->address);
4986 if (!strcmp(gtk_entry_get_text(GTK_ENTRY(compose->from_name)), tmp)
4987 || strlen(gtk_entry_get_text(GTK_ENTRY(compose->from_name))) == 0) {
4989 from_name = compose->account->name ? g_strdup(compose->account->name):NULL;
4990 from_address = g_strdup(compose->account->address);
4992 gchar *spec = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
4993 /* extract name and address */
4994 if (strstr(spec, " <") && strstr(spec, ">")) {
4995 from_address = g_strdup(strrchr(spec, '<')+1);
4996 *(strrchr(from_address, '>')) = '\0';
4997 from_name = g_strdup(spec);
4998 *(strrchr(from_name, '<')) = '\0';
5001 from_address = g_strdup(spec);
5008 if (from_name && *from_name) {
5009 compose_convert_header
5010 (compose, buf, sizeof(buf), from_name,
5011 strlen("From: "), TRUE);
5012 QUOTE_IF_REQUIRED(name, buf);
5014 g_string_append_printf(header, "From: %s <%s>\n",
5015 name, from_address);
5017 g_string_append_printf(header, "From: %s\n", from_address);
5020 g_free(from_address);
5023 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
5026 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
5029 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
5032 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
5035 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
5037 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
5040 compose_convert_header(compose, buf, sizeof(buf), str,
5041 strlen("Subject: "), FALSE);
5042 g_string_append_printf(header, "Subject: %s\n", buf);
5048 if (compose->account->gen_msgid) {
5049 generate_msgid(buf, sizeof(buf));
5050 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
5051 compose->msgid = g_strdup(buf);
5054 if (compose->remove_references == FALSE) {
5056 if (compose->inreplyto && compose->to_list)
5057 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
5060 if (compose->references)
5061 g_string_append_printf(header, "References: %s\n", compose->references);
5065 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
5068 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
5071 if (compose->account->organization &&
5072 strlen(compose->account->organization) &&
5073 !IS_IN_CUSTOM_HEADER("Organization")) {
5074 compose_convert_header(compose, buf, sizeof(buf),
5075 compose->account->organization,
5076 strlen("Organization: "), FALSE);
5077 g_string_append_printf(header, "Organization: %s\n", buf);
5080 /* Program version and system info */
5081 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
5082 !compose->newsgroup_list) {
5083 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
5085 gtk_major_version, gtk_minor_version, gtk_micro_version,
5088 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
5089 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
5091 gtk_major_version, gtk_minor_version, gtk_micro_version,
5095 /* custom headers */
5096 if (compose->account->add_customhdr) {
5099 for (cur = compose->account->customhdr_list; cur != NULL;
5101 CustomHeader *chdr = (CustomHeader *)cur->data;
5103 if (custom_header_is_allowed(chdr->name)) {
5104 compose_convert_header
5105 (compose, buf, sizeof(buf),
5106 chdr->value ? chdr->value : "",
5107 strlen(chdr->name) + 2, FALSE);
5108 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
5114 switch (compose->priority) {
5115 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
5116 "X-Priority: 1 (Highest)\n");
5118 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
5119 "X-Priority: 2 (High)\n");
5121 case PRIORITY_NORMAL: break;
5122 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
5123 "X-Priority: 4 (Low)\n");
5125 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
5126 "X-Priority: 5 (Lowest)\n");
5128 default: debug_print("compose: priority unknown : %d\n",
5132 /* Request Return Receipt */
5133 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
5134 if (compose->return_receipt) {
5135 if (compose->account->name
5136 && *compose->account->name) {
5137 compose_convert_header(compose, buf, sizeof(buf),
5138 compose->account->name,
5139 strlen("Disposition-Notification-To: "),
5141 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
5143 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
5147 /* get special headers */
5148 for (list = compose->header_list; list; list = list->next) {
5149 ComposeHeaderEntry *headerentry;
5152 gchar *headername_wcolon;
5153 gchar *headername_trans;
5156 gboolean standard_header = FALSE;
5158 headerentry = ((ComposeHeaderEntry *)list->data);
5160 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
5161 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
5166 if (!strstr(tmp, ":")) {
5167 headername_wcolon = g_strconcat(tmp, ":", NULL);
5168 headername = g_strdup(tmp);
5170 headername_wcolon = g_strdup(tmp);
5171 headername = g_strdup(strtok(tmp, ":"));
5175 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
5176 Xstrdup_a(headervalue, entry_str, return NULL);
5177 subst_char(headervalue, '\r', ' ');
5178 subst_char(headervalue, '\n', ' ');
5179 string = std_headers;
5180 while (*string != NULL) {
5181 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
5182 if (!strcmp(headername_trans,headername_wcolon))
5183 standard_header = TRUE;
5186 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
5187 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
5190 g_free(headername_wcolon);
5194 g_string_free(header, FALSE);
5199 #undef IS_IN_CUSTOM_HEADER
5201 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
5202 gint header_len, gboolean addr_field)
5204 gchar *tmpstr = NULL;
5205 const gchar *out_codeset = NULL;
5207 g_return_if_fail(src != NULL);
5208 g_return_if_fail(dest != NULL);
5210 if (len < 1) return;
5212 tmpstr = g_strdup(src);
5214 subst_char(tmpstr, '\n', ' ');
5215 subst_char(tmpstr, '\r', ' ');
5218 if (!g_utf8_validate(tmpstr, -1, NULL)) {
5219 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
5220 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
5225 codeconv_set_strict(TRUE);
5226 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5227 conv_get_charset_str(compose->out_encoding));
5228 codeconv_set_strict(FALSE);
5230 if (!dest || *dest == '\0') {
5231 gchar *test_conv_global_out = NULL;
5232 gchar *test_conv_reply = NULL;
5234 /* automatic mode. be automatic. */
5235 codeconv_set_strict(TRUE);
5237 out_codeset = conv_get_outgoing_charset_str();
5239 debug_print("trying to convert to %s\n", out_codeset);
5240 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5243 if (!test_conv_global_out && compose->orig_charset
5244 && strcmp(compose->orig_charset, CS_US_ASCII)) {
5245 out_codeset = compose->orig_charset;
5246 debug_print("failure; trying to convert to %s\n", out_codeset);
5247 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5250 if (!test_conv_global_out && !test_conv_reply) {
5252 out_codeset = CS_INTERNAL;
5253 debug_print("finally using %s\n", out_codeset);
5255 g_free(test_conv_global_out);
5256 g_free(test_conv_reply);
5257 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5259 codeconv_set_strict(FALSE);
5264 static void compose_create_header_entry(Compose *compose)
5266 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5270 GList *combo_list = NULL;
5272 const gchar *header = NULL;
5273 ComposeHeaderEntry *headerentry;
5274 gboolean standard_header = FALSE;
5276 headerentry = g_new0(ComposeHeaderEntry, 1);
5279 combo = gtk_combo_new();
5281 while(*string != NULL) {
5282 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
5285 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5286 g_list_free(combo_list);
5287 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5288 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5289 G_CALLBACK(compose_grab_focus_cb), compose);
5290 gtk_widget_show(combo);
5291 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5292 if (compose->header_last) {
5293 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5295 while (*string != NULL) {
5296 if (!strcmp(*string, last_header_entry))
5297 standard_header = TRUE;
5300 if (standard_header)
5301 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5303 if (!compose->header_last || !standard_header) {
5304 switch(compose->account->protocol) {
5306 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5309 header = prefs_common.trans_hdr ? _("To:") : "To:";
5314 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5316 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5317 G_CALLBACK(compose_grab_focus_cb), compose);
5320 entry = gtk_entry_new();
5321 gtk_widget_show(entry);
5322 gtk_tooltips_set_tip(compose->tooltips, entry,
5323 _("Use <tab> to autocomplete from addressbook"), NULL);
5324 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);
5326 g_signal_connect(G_OBJECT(entry), "key-press-event",
5327 G_CALLBACK(compose_headerentry_key_press_event_cb),
5329 g_signal_connect(G_OBJECT(entry), "changed",
5330 G_CALLBACK(compose_headerentry_changed_cb),
5332 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5333 G_CALLBACK(compose_grab_focus_cb), compose);
5336 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5337 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5338 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5339 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5340 G_CALLBACK(compose_header_drag_received_cb),
5342 g_signal_connect(G_OBJECT(entry), "drag-drop",
5343 G_CALLBACK(compose_drag_drop),
5346 address_completion_register_entry(GTK_ENTRY(entry));
5348 headerentry->compose = compose;
5349 headerentry->combo = combo;
5350 headerentry->entry = entry;
5351 headerentry->headernum = compose->header_nextrow;
5353 compose->header_nextrow++;
5354 compose->header_last = headerentry;
5357 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5359 ComposeHeaderEntry *last_header;
5361 last_header = compose->header_last;
5363 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5364 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5367 static GtkWidget *compose_create_header(Compose *compose)
5371 GtkWidget *from_optmenu_hbox;
5372 GtkWidget *header_scrolledwin;
5373 GtkWidget *header_table;
5377 /* header labels and entries */
5378 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5379 gtk_widget_show(header_scrolledwin);
5380 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5382 header_table = gtk_table_new(2, 2, FALSE);
5383 gtk_widget_show(header_table);
5384 gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
5385 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5386 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5389 /* option menu for selecting accounts */
5390 hbox = gtk_hbox_new(FALSE, 0);
5391 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
5392 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
5393 //gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
5394 // GTK_FILL, 0, 2, 0);
5395 from_optmenu_hbox = compose_account_option_menu_create(compose);
5396 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5397 0, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5400 compose->header_table = header_table;
5401 compose->header_list = NULL;
5402 compose->header_nextrow = count;
5404 compose_create_header_entry(compose);
5406 compose->table = NULL;
5408 return header_scrolledwin ;
5411 GtkWidget *compose_create_attach(Compose *compose)
5413 GtkWidget *attach_scrwin;
5414 GtkWidget *attach_clist;
5416 GtkListStore *store;
5417 GtkCellRenderer *renderer;
5418 GtkTreeViewColumn *column;
5419 GtkTreeSelection *selection;
5421 /* attachment list */
5422 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5423 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5424 GTK_POLICY_AUTOMATIC,
5425 GTK_POLICY_AUTOMATIC);
5426 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5428 store = gtk_list_store_new(N_ATTACH_COLS,
5433 G_TYPE_AUTO_POINTER,
5435 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5436 (GTK_TREE_MODEL(store)));
5437 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5438 g_object_unref(store);
5440 renderer = gtk_cell_renderer_text_new();
5441 column = gtk_tree_view_column_new_with_attributes
5442 (_("Mime type"), renderer, "text",
5443 COL_MIMETYPE, NULL);
5444 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5446 renderer = gtk_cell_renderer_text_new();
5447 column = gtk_tree_view_column_new_with_attributes
5448 (_("Size"), renderer, "text",
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 (_("Name"), renderer, "text",
5456 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5458 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5459 prefs_common.enable_rules_hint);
5460 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5461 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5463 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5464 G_CALLBACK(attach_selected), compose);
5465 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5466 G_CALLBACK(attach_button_pressed), compose);
5467 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5468 G_CALLBACK(attach_key_pressed), compose);
5471 gtk_drag_dest_set(attach_clist,
5472 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5473 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5474 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5475 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5476 G_CALLBACK(compose_attach_drag_received_cb),
5478 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5479 G_CALLBACK(compose_drag_drop),
5482 compose->attach_scrwin = attach_scrwin;
5483 compose->attach_clist = attach_clist;
5485 return attach_scrwin;
5488 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5489 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5491 static GtkWidget *compose_create_others(Compose *compose)
5494 GtkWidget *savemsg_checkbtn;
5495 GtkWidget *savemsg_entry;
5496 GtkWidget *savemsg_select;
5499 gchar *folderidentifier;
5501 /* Table for settings */
5502 table = gtk_table_new(3, 1, FALSE);
5503 gtk_container_set_border_width(GTK_CONTAINER(table), BORDER_WIDTH);
5504 gtk_widget_show(table);
5505 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5508 /* Save Message to folder */
5509 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5510 gtk_widget_show(savemsg_checkbtn);
5511 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5512 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5513 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5515 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5516 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5518 savemsg_entry = gtk_entry_new();
5519 gtk_widget_show(savemsg_entry);
5520 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5521 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5522 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5523 G_CALLBACK(compose_grab_focus_cb), compose);
5524 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5525 folderidentifier = folder_item_get_identifier(account_get_special_folder
5526 (compose->account, F_OUTBOX));
5527 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5528 g_free(folderidentifier);
5531 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5532 gtk_widget_show(savemsg_select);
5533 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5534 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5535 G_CALLBACK(compose_savemsg_select_cb),
5540 compose->savemsg_checkbtn = savemsg_checkbtn;
5541 compose->savemsg_entry = savemsg_entry;
5546 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5548 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5549 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5552 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5557 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5560 path = folder_item_get_identifier(dest);
5562 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5566 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5567 GdkAtom clip, GtkTextIter *insert_place);
5569 #define BLOCK_WRAP() { \
5570 prev_autowrap = compose->autowrap; \
5571 buffer = gtk_text_view_get_buffer( \
5572 GTK_TEXT_VIEW(compose->text)); \
5573 compose->autowrap = FALSE; \
5575 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5576 G_CALLBACK(compose_changed_cb), \
5578 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5579 G_CALLBACK(text_inserted), \
5582 #define UNBLOCK_WRAP() { \
5583 compose->autowrap = prev_autowrap; \
5584 if (compose->autowrap) \
5585 compose_wrap_all(compose); \
5587 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5588 G_CALLBACK(compose_changed_cb), \
5590 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5591 G_CALLBACK(text_inserted), \
5596 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5600 GtkTextBuffer *buffer;
5602 if (event->button == 3) {
5604 GtkTextIter sel_start, sel_end;
5605 gboolean stuff_selected;
5607 /* move the cursor to allow GtkAspell to check the word
5608 * under the mouse */
5609 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5610 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5612 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5615 stuff_selected = gtk_text_buffer_get_selection_bounds(
5616 GTK_TEXT_VIEW(text)->buffer,
5617 &sel_start, &sel_end);
5619 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5620 /* reselect stuff */
5622 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5623 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5624 &sel_start, &sel_end);
5626 return FALSE; /* pass the event so that the right-click goes through */
5629 if (event->button == 2) {
5634 /* get the middle-click position to paste at the correct place */
5635 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5636 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5638 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5641 entry_paste_clipboard(compose, text,
5642 prefs_common.linewrap_pastes,
5643 GDK_SELECTION_PRIMARY, &iter);
5651 static void compose_spell_menu_changed(void *data)
5653 Compose *compose = (Compose *)data;
5655 GtkWidget *menuitem;
5656 GtkWidget *parent_item;
5657 GtkMenu *menu = GTK_MENU(gtk_menu_new());
5658 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
5661 if (compose->gtkaspell == NULL)
5664 parent_item = gtk_item_factory_get_item(ifactory,
5665 "/Spelling/Options");
5667 /* setting the submenu removes /Spelling/Options from the factory
5668 * so we need to save it */
5670 if (parent_item == NULL) {
5671 parent_item = compose->aspell_options_menu;
5672 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(parent_item));
5674 compose->aspell_options_menu = parent_item;
5676 spell_menu = gtkaspell_make_config_menu(compose->gtkaspell);
5678 spell_menu = g_slist_reverse(spell_menu);
5679 for (items = spell_menu;
5680 items; items = items->next) {
5681 menuitem = GTK_WIDGET(GTK_MENU_ITEM(items->data));
5682 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), GTK_WIDGET(menuitem));
5683 gtk_widget_show(GTK_WIDGET(menuitem));
5685 g_slist_free(spell_menu);
5687 gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), GTK_WIDGET(menu));
5692 static Compose *compose_create(PrefsAccount *account, ComposeMode mode,
5699 GtkWidget *handlebox;
5701 GtkWidget *notebook;
5706 GtkWidget *subject_hbox;
5707 GtkWidget *subject_frame;
5708 GtkWidget *subject_entry;
5712 GtkWidget *edit_vbox;
5713 GtkWidget *ruler_hbox;
5715 GtkWidget *scrolledwin;
5717 GtkTextBuffer *buffer;
5718 GtkClipboard *clipboard;
5720 UndoMain *undostruct;
5722 gchar *titles[N_ATTACH_COLS];
5723 guint n_menu_entries;
5724 GtkWidget *popupmenu;
5725 GtkItemFactory *popupfactory;
5726 GtkItemFactory *ifactory;
5727 GtkWidget *tmpl_menu;
5729 GtkWidget *menuitem;
5732 GtkAspell * gtkaspell = NULL;
5735 static GdkGeometry geometry;
5737 g_return_val_if_fail(account != NULL, NULL);
5739 debug_print("Creating compose window...\n");
5740 compose = g_new0(Compose, 1);
5742 titles[COL_MIMETYPE] = _("MIME type");
5743 titles[COL_SIZE] = _("Size");
5744 titles[COL_NAME] = _("Name");
5746 compose->batch = batch;
5747 compose->account = account;
5749 compose->mutex = g_mutex_new();
5750 compose->set_cursor_pos = -1;
5752 compose->tooltips = gtk_tooltips_new();
5754 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5755 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5756 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5758 if (!geometry.max_width) {
5759 geometry.max_width = gdk_screen_width();
5760 geometry.max_height = gdk_screen_height();
5763 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5764 &geometry, GDK_HINT_MAX_SIZE);
5765 if (!geometry.min_width) {
5766 geometry.min_width = 600;
5767 geometry.min_height = 480;
5769 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5770 &geometry, GDK_HINT_MIN_SIZE);
5771 gtk_widget_set_uposition(window, prefs_common.compose_x,
5772 prefs_common.compose_y);
5774 g_signal_connect(G_OBJECT(window), "delete_event",
5775 G_CALLBACK(compose_delete_cb), compose);
5776 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5777 gtk_widget_realize(window);
5779 gtkut_widget_set_composer_icon(window);
5781 vbox = gtk_vbox_new(FALSE, 0);
5782 gtk_container_add(GTK_CONTAINER(window), vbox);
5784 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5785 menubar = menubar_create(window, compose_entries,
5786 n_menu_entries, "<Compose>", compose);
5787 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5789 if (prefs_common.toolbar_detachable) {
5790 handlebox = gtk_handle_box_new();
5792 handlebox = gtk_hbox_new(FALSE, 0);
5794 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5796 gtk_widget_realize(handlebox);
5797 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5800 vbox2 = gtk_vbox_new(FALSE, 2);
5801 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5802 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5805 notebook = gtk_notebook_new();
5806 gtk_widget_set_size_request(notebook, -1, 130);
5807 gtk_widget_show(notebook);
5809 /* header labels and entries */
5810 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5811 compose_create_header(compose),
5812 gtk_label_new_with_mnemonic(_("Hea_der")));
5813 /* attachment list */
5814 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5815 compose_create_attach(compose),
5816 gtk_label_new_with_mnemonic(_("_Attachments")));
5818 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5819 compose_create_others(compose),
5820 gtk_label_new_with_mnemonic(_("Othe_rs")));
5823 subject_hbox = gtk_hbox_new(FALSE, 0);
5824 gtk_widget_show(subject_hbox);
5826 subject_frame = gtk_frame_new(NULL);
5827 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5828 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5829 gtk_widget_show(subject_frame);
5831 subject = gtk_hbox_new(FALSE, 0);
5832 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5833 gtk_widget_show(subject);
5835 label = gtk_label_new(_("Subject:"));
5836 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5837 gtk_widget_show(label);
5839 subject_entry = gtk_entry_new();
5840 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5841 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5842 G_CALLBACK(compose_grab_focus_cb), compose);
5843 gtk_widget_show(subject_entry);
5844 compose->subject_entry = subject_entry;
5845 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5847 edit_vbox = gtk_vbox_new(FALSE, 0);
5849 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5852 ruler_hbox = gtk_hbox_new(FALSE, 0);
5853 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5855 ruler = gtk_shruler_new();
5856 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5857 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5861 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5862 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5863 GTK_POLICY_AUTOMATIC,
5864 GTK_POLICY_AUTOMATIC);
5865 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5867 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5868 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5870 text = gtk_text_view_new();
5871 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5872 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5873 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5874 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5875 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5877 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5879 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5880 G_CALLBACK(compose_edit_size_alloc),
5882 g_signal_connect(G_OBJECT(buffer), "changed",
5883 G_CALLBACK(compose_changed_cb), compose);
5884 g_signal_connect(G_OBJECT(text), "grab_focus",
5885 G_CALLBACK(compose_grab_focus_cb), compose);
5886 g_signal_connect(G_OBJECT(buffer), "insert_text",
5887 G_CALLBACK(text_inserted), compose);
5888 g_signal_connect(G_OBJECT(text), "button_press_event",
5889 G_CALLBACK(text_clicked), compose);
5890 g_signal_connect(G_OBJECT(subject_entry), "changed",
5891 G_CALLBACK(compose_changed_cb), compose);
5894 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5895 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5896 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5897 g_signal_connect(G_OBJECT(text), "drag_data_received",
5898 G_CALLBACK(compose_insert_drag_received_cb),
5900 g_signal_connect(G_OBJECT(text), "drag-drop",
5901 G_CALLBACK(compose_drag_drop),
5903 gtk_widget_show_all(vbox);
5905 /* pane between attach clist and text */
5906 paned = gtk_vpaned_new();
5907 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5908 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5909 gtk_paned_add1(GTK_PANED(paned), notebook);
5910 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5911 gtk_widget_show_all(paned);
5914 if (prefs_common.textfont) {
5915 PangoFontDescription *font_desc;
5917 font_desc = pango_font_description_from_string
5918 (prefs_common.textfont);
5920 gtk_widget_modify_font(text, font_desc);
5921 pango_font_description_free(font_desc);
5925 n_entries = sizeof(compose_popup_entries) /
5926 sizeof(compose_popup_entries[0]);
5927 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5928 "<Compose>", &popupfactory,
5931 ifactory = gtk_item_factory_from_widget(menubar);
5932 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5933 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5934 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5936 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5938 undostruct = undo_init(text);
5939 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5942 address_completion_start(window);
5944 compose->window = window;
5945 compose->vbox = vbox;
5946 compose->menubar = menubar;
5947 compose->handlebox = handlebox;
5949 compose->vbox2 = vbox2;
5951 compose->paned = paned;
5953 compose->edit_vbox = edit_vbox;
5954 compose->ruler_hbox = ruler_hbox;
5955 compose->ruler = ruler;
5956 compose->scrolledwin = scrolledwin;
5957 compose->text = text;
5959 compose->focused_editable = NULL;
5961 compose->popupmenu = popupmenu;
5962 compose->popupfactory = popupfactory;
5964 compose->tmpl_menu = tmpl_menu;
5966 compose->mode = mode;
5968 compose->targetinfo = NULL;
5969 compose->replyinfo = NULL;
5970 compose->fwdinfo = NULL;
5972 compose->replyto = NULL;
5974 compose->bcc = NULL;
5975 compose->followup_to = NULL;
5977 compose->ml_post = NULL;
5979 compose->inreplyto = NULL;
5980 compose->references = NULL;
5981 compose->msgid = NULL;
5982 compose->boundary = NULL;
5984 compose->autowrap = prefs_common.autowrap;
5986 compose->use_signing = FALSE;
5987 compose->use_encryption = FALSE;
5988 compose->privacy_system = NULL;
5990 compose->modified = FALSE;
5992 compose->return_receipt = FALSE;
5994 compose->to_list = NULL;
5995 compose->newsgroup_list = NULL;
5997 compose->undostruct = undostruct;
5999 compose->sig_str = NULL;
6001 compose->exteditor_file = NULL;
6002 compose->exteditor_pid = -1;
6003 compose->exteditor_tag = -1;
6004 compose->draft_timeout_tag = -1;
6007 menu_set_sensitive(ifactory, "/Spelling", FALSE);
6008 if (mode != COMPOSE_REDIRECT) {
6009 if (prefs_common.enable_aspell && prefs_common.dictionary &&
6010 strcmp(prefs_common.dictionary, "")) {
6011 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
6012 prefs_common.dictionary,
6013 conv_get_locale_charset_str(),
6014 prefs_common.misspelled_col,
6015 prefs_common.check_while_typing,
6016 prefs_common.recheck_when_changing_dict,
6017 prefs_common.use_alternate,
6018 GTK_TEXT_VIEW(text),
6019 GTK_WINDOW(compose->window),
6020 compose_spell_menu_changed,
6023 alertpanel_error(_("Spell checker could not "
6025 gtkaspell_checkers_strerror());
6026 gtkaspell_checkers_reset_error();
6028 if (!gtkaspell_set_sug_mode(gtkaspell,
6029 prefs_common.aspell_sugmode)) {
6030 debug_print("Aspell: could not set "
6031 "suggestion mode %s\n",
6032 gtkaspell_checkers_strerror());
6033 gtkaspell_checkers_reset_error();
6036 menu_set_sensitive(ifactory, "/Spelling", TRUE);
6040 compose->gtkaspell = gtkaspell;
6041 compose_spell_menu_changed(compose);
6044 compose_select_account(compose, account, TRUE);
6046 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
6047 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
6048 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
6050 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
6051 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
6053 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
6054 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
6057 if (account->protocol != A_NNTP)
6058 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
6060 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
6062 addressbook_set_target_compose(compose);
6064 if (mode != COMPOSE_REDIRECT)
6065 compose_set_template_menu(compose);
6067 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6068 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
6071 compose_list = g_list_append(compose_list, compose);
6073 if (!prefs_common.show_ruler)
6074 gtk_widget_hide(ruler_hbox);
6076 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
6077 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
6078 prefs_common.show_ruler);
6081 compose->priority = PRIORITY_NORMAL;
6082 compose_update_priority_menu_item(compose);
6084 compose_set_out_encoding(compose);
6087 compose_update_actions_menu(compose);
6089 /* Privacy Systems menu */
6090 compose_update_privacy_systems_menu(compose);
6092 activate_privacy_system(compose, account, TRUE);
6093 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
6095 gtk_widget_realize(window);
6097 gtk_widget_show(window);
6103 static GtkWidget *compose_account_option_menu_create(Compose *compose)
6109 GtkWidget *from_name = NULL;
6111 gint num = 0, def_menu = 0;
6113 accounts = account_get_list();
6114 g_return_val_if_fail(accounts != NULL, NULL);
6116 optmenu = gtk_option_menu_new();
6117 menu = gtk_menu_new();
6119 hbox = gtk_hbox_new(FALSE, 6);
6120 from_name = gtk_entry_new();
6122 g_signal_connect_after(G_OBJECT(from_name), "grab_focus",
6123 G_CALLBACK(compose_grab_focus_cb), compose);
6125 for (; accounts != NULL; accounts = accounts->next, num++) {
6126 PrefsAccount *ac = (PrefsAccount *)accounts->data;
6127 GtkWidget *menuitem;
6128 gchar *name, *from = NULL;
6130 if (ac == compose->account) def_menu = num;
6132 name = g_markup_printf_escaped("From: <i>%s</i>",
6135 if (ac == compose->account) {
6136 if (ac->name && *ac->name) {
6138 QUOTE_IF_REQUIRED_NORMAL(buf, ac->name, return NULL);
6139 from = g_strdup_printf("%s <%s>",
6141 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6143 from = g_strdup_printf("%s",
6145 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6148 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
6149 gtk_label_set_use_markup (
6150 GTK_LABEL (gtk_bin_get_child (GTK_BIN (menuitem))),
6154 g_signal_connect(G_OBJECT(menuitem), "activate",
6155 G_CALLBACK(account_activated),
6159 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
6160 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
6162 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
6163 gtk_box_pack_start(GTK_BOX(hbox), from_name, TRUE, TRUE, 0);
6165 gtk_tooltips_set_tip(compose->tooltips, optmenu,
6166 _("Account to use for this email"), NULL);
6167 gtk_tooltips_set_tip(compose->tooltips, from_name,
6168 _("Sender address to be used"), NULL);
6170 compose->from_name = from_name;
6175 static void compose_set_priority_cb(gpointer data,
6179 Compose *compose = (Compose *) data;
6180 compose->priority = action;
6183 static void compose_update_priority_menu_item(Compose * compose)
6185 GtkItemFactory *ifactory;
6186 GtkWidget *menuitem = NULL;
6188 ifactory = gtk_item_factory_from_widget(compose->menubar);
6190 switch (compose->priority) {
6191 case PRIORITY_HIGHEST:
6192 menuitem = gtk_item_factory_get_item
6193 (ifactory, "/Options/Priority/Highest");
6196 menuitem = gtk_item_factory_get_item
6197 (ifactory, "/Options/Priority/High");
6199 case PRIORITY_NORMAL:
6200 menuitem = gtk_item_factory_get_item
6201 (ifactory, "/Options/Priority/Normal");
6204 menuitem = gtk_item_factory_get_item
6205 (ifactory, "/Options/Priority/Low");
6207 case PRIORITY_LOWEST:
6208 menuitem = gtk_item_factory_get_item
6209 (ifactory, "/Options/Priority/Lowest");
6212 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6215 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
6217 Compose *compose = (Compose *) data;
6219 GtkItemFactory *ifactory;
6220 gboolean can_sign = FALSE, can_encrypt = FALSE;
6222 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
6224 if (!GTK_CHECK_MENU_ITEM(widget)->active)
6227 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
6228 g_free(compose->privacy_system);
6229 compose->privacy_system = NULL;
6230 if (systemid != NULL) {
6231 compose->privacy_system = g_strdup(systemid);
6233 can_sign = privacy_system_can_sign(systemid);
6234 can_encrypt = privacy_system_can_encrypt(systemid);
6237 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
6239 ifactory = gtk_item_factory_from_widget(compose->menubar);
6240 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6241 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6244 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
6246 static gchar *branch_path = "/Options/Privacy System";
6247 GtkItemFactory *ifactory;
6248 GtkWidget *menuitem = NULL;
6250 gboolean can_sign = FALSE, can_encrypt = FALSE;
6251 gboolean found = FALSE;
6253 ifactory = gtk_item_factory_from_widget(compose->menubar);
6255 if (compose->privacy_system != NULL) {
6258 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6259 g_return_if_fail(menuitem != NULL);
6261 amenu = GTK_MENU_SHELL(menuitem)->children;
6263 while (amenu != NULL) {
6264 GList *alist = amenu->next;
6266 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
6267 if (systemid != NULL) {
6268 if (strcmp(systemid, compose->privacy_system) == 0) {
6269 menuitem = GTK_WIDGET(amenu->data);
6271 can_sign = privacy_system_can_sign(systemid);
6272 can_encrypt = privacy_system_can_encrypt(systemid);
6276 } else if (strlen(compose->privacy_system) == 0) {
6277 menuitem = GTK_WIDGET(amenu->data);
6280 can_encrypt = FALSE;
6287 if (menuitem != NULL)
6288 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6290 if (warn && !found && strlen(compose->privacy_system)) {
6291 gchar *tmp = g_strdup_printf(
6292 _("The privacy system '%s' cannot be loaded. You "
6293 "will not be able to sign or encrypt this message."),
6294 compose->privacy_system);
6295 alertpanel_warning(tmp);
6300 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6301 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6304 static void compose_set_out_encoding(Compose *compose)
6306 GtkItemFactoryEntry *entry;
6307 GtkItemFactory *ifactory;
6308 CharSet out_encoding;
6309 gchar *path, *p, *q;
6312 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
6313 ifactory = gtk_item_factory_from_widget(compose->menubar);
6315 for (entry = compose_entries; entry->callback != compose_address_cb;
6317 if (entry->callback == compose_set_encoding_cb &&
6318 (CharSet)entry->callback_action == out_encoding) {
6319 p = q = path = g_strdup(entry->path);
6331 item = gtk_item_factory_get_item(ifactory, path);
6332 gtk_widget_activate(item);
6339 static void compose_set_template_menu(Compose *compose)
6341 GSList *tmpl_list, *cur;
6345 tmpl_list = template_get_config();
6347 menu = gtk_menu_new();
6349 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
6350 Template *tmpl = (Template *)cur->data;
6352 item = gtk_menu_item_new_with_label(tmpl->name);
6353 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6354 g_signal_connect(G_OBJECT(item), "activate",
6355 G_CALLBACK(compose_template_activate_cb),
6357 g_object_set_data(G_OBJECT(item), "template", tmpl);
6358 gtk_widget_show(item);
6361 gtk_widget_show(menu);
6362 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
6365 void compose_update_actions_menu(Compose *compose)
6367 GtkItemFactory *ifactory;
6369 ifactory = gtk_item_factory_from_widget(compose->menubar);
6370 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6373 void compose_update_privacy_systems_menu(Compose *compose)
6375 static gchar *branch_path = "/Options/Privacy System";
6376 GtkItemFactory *ifactory;
6377 GtkWidget *menuitem;
6378 GSList *systems, *cur;
6381 GtkWidget *system_none;
6384 ifactory = gtk_item_factory_from_widget(compose->menubar);
6386 /* remove old entries */
6387 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6388 g_return_if_fail(menuitem != NULL);
6390 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6391 while (amenu != NULL) {
6392 GList *alist = amenu->next;
6393 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6397 system_none = gtk_item_factory_get_widget(ifactory,
6398 "/Options/Privacy System/None");
6400 g_signal_connect(G_OBJECT(system_none), "activate",
6401 G_CALLBACK(compose_set_privacy_system_cb), compose);
6403 systems = privacy_get_system_ids();
6404 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6405 gchar *systemid = cur->data;
6407 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6408 widget = gtk_radio_menu_item_new_with_label(group,
6409 privacy_system_get_name(systemid));
6410 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6411 g_strdup(systemid), g_free);
6412 g_signal_connect(G_OBJECT(widget), "activate",
6413 G_CALLBACK(compose_set_privacy_system_cb), compose);
6415 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6416 gtk_widget_show(widget);
6419 g_slist_free(systems);
6422 void compose_reflect_prefs_all(void)
6427 for (cur = compose_list; cur != NULL; cur = cur->next) {
6428 compose = (Compose *)cur->data;
6429 compose_set_template_menu(compose);
6433 void compose_reflect_prefs_pixmap_theme(void)
6438 for (cur = compose_list; cur != NULL; cur = cur->next) {
6439 compose = (Compose *)cur->data;
6440 toolbar_update(TOOLBAR_COMPOSE, compose);
6444 static void compose_template_apply(Compose *compose, Template *tmpl,
6448 GtkTextBuffer *buffer;
6452 gchar *parsed_str = NULL;
6453 gint cursor_pos = 0;
6456 /* process the body */
6458 text = GTK_TEXT_VIEW(compose->text);
6459 buffer = gtk_text_view_get_buffer(text);
6462 gtk_text_buffer_set_text(buffer, "", -1);
6464 mark = gtk_text_buffer_get_insert(buffer);
6465 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6468 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6469 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6472 if (prefs_common.quotemark && *prefs_common.quotemark)
6473 qmark = prefs_common.quotemark;
6477 if (compose->replyinfo != NULL)
6478 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6479 tmpl->value, qmark, NULL, FALSE);
6480 else if (compose->fwdinfo != NULL)
6481 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6482 tmpl->value, qmark, NULL, FALSE);
6487 if (replace && parsed_str && compose->account->auto_sig)
6488 compose_insert_sig(compose, FALSE);
6490 if (replace && parsed_str) {
6491 gtk_text_buffer_get_start_iter(buffer, &iter);
6492 gtk_text_buffer_place_cursor(buffer, &iter);
6496 cursor_pos = quote_fmt_get_cursor_pos();
6497 compose->set_cursor_pos = cursor_pos;
6498 if (cursor_pos == -1)
6500 gtk_text_buffer_get_start_iter(buffer, &iter);
6501 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6502 gtk_text_buffer_place_cursor(buffer, &iter);
6505 /* process the other fields */
6506 compose_template_apply_fields(compose, tmpl);
6508 compose_changed_cb(NULL, compose);
6511 void compose_template_apply_fields(Compose *compose, Template *tmpl)
6513 static MsgInfo dummyinfo;
6514 MsgInfo *msginfo = NULL;
6517 if (compose->replyinfo != NULL)
6518 msginfo = compose->replyinfo;
6519 else if (compose->fwdinfo != NULL)
6520 msginfo = compose->fwdinfo;
6522 msginfo = &dummyinfo;
6524 if (tmpl->to && *tmpl->to != '\0') {
6525 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6526 quote_fmt_scan_string(tmpl->to);
6529 buf = quote_fmt_get_buffer();
6531 alertpanel_error(_("Message To format error."));
6533 compose_entry_append(compose, buf, COMPOSE_TO);
6537 if (tmpl->cc && *tmpl->cc != '\0') {
6538 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6539 quote_fmt_scan_string(tmpl->cc);
6542 buf = quote_fmt_get_buffer();
6544 alertpanel_error(_("Message Cc format error."));
6546 compose_entry_append(compose, buf, COMPOSE_CC);
6550 if (tmpl->bcc && *tmpl->bcc != '\0') {
6551 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6552 quote_fmt_scan_string(tmpl->bcc);
6555 buf = quote_fmt_get_buffer();
6557 alertpanel_error(_("Message Bcc format error."));
6559 compose_entry_append(compose, buf, COMPOSE_BCC);
6563 /* process the subject */
6564 if (tmpl->subject && *tmpl->subject != '\0') {
6565 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6566 quote_fmt_scan_string(tmpl->subject);
6569 buf = quote_fmt_get_buffer();
6571 alertpanel_error(_("Message subject format error."));
6573 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
6578 static void compose_destroy(Compose *compose)
6580 compose_list = g_list_remove(compose_list, compose);
6582 if (compose->updating) {
6583 debug_print("danger, not destroying anything now\n");
6584 compose->deferred_destroy = TRUE;
6587 /* NOTE: address_completion_end() does nothing with the window
6588 * however this may change. */
6589 address_completion_end(compose->window);
6591 slist_free_strings(compose->to_list);
6592 g_slist_free(compose->to_list);
6593 slist_free_strings(compose->newsgroup_list);
6594 g_slist_free(compose->newsgroup_list);
6595 slist_free_strings(compose->header_list);
6596 g_slist_free(compose->header_list);
6598 procmsg_msginfo_free(compose->targetinfo);
6599 procmsg_msginfo_free(compose->replyinfo);
6600 procmsg_msginfo_free(compose->fwdinfo);
6602 g_free(compose->replyto);
6603 g_free(compose->cc);
6604 g_free(compose->bcc);
6605 g_free(compose->newsgroups);
6606 g_free(compose->followup_to);
6608 g_free(compose->ml_post);
6610 g_free(compose->inreplyto);
6611 g_free(compose->references);
6612 g_free(compose->msgid);
6613 g_free(compose->boundary);
6615 g_free(compose->redirect_filename);
6616 if (compose->undostruct)
6617 undo_destroy(compose->undostruct);
6619 g_free(compose->sig_str);
6621 g_free(compose->exteditor_file);
6623 g_free(compose->orig_charset);
6625 g_free(compose->privacy_system);
6627 if (addressbook_get_target_compose() == compose)
6628 addressbook_set_target_compose(NULL);
6631 if (compose->gtkaspell) {
6632 gtkaspell_delete(compose->gtkaspell);
6633 compose->gtkaspell = NULL;
6637 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6638 prefs_common.compose_height = compose->window->allocation.height;
6640 if (!gtk_widget_get_parent(compose->paned))
6641 gtk_widget_destroy(compose->paned);
6642 gtk_widget_destroy(compose->popupmenu);
6644 gtk_widget_destroy(compose->window);
6645 toolbar_destroy(compose->toolbar);
6646 g_free(compose->toolbar);
6647 g_mutex_free(compose->mutex);
6651 static void compose_attach_info_free(AttachInfo *ainfo)
6653 g_free(ainfo->file);
6654 g_free(ainfo->content_type);
6655 g_free(ainfo->name);
6659 static void compose_attach_remove_selected(Compose *compose)
6661 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6662 GtkTreeSelection *selection;
6664 GtkTreeModel *model;
6666 selection = gtk_tree_view_get_selection(tree_view);
6667 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6672 for (cur = sel; cur != NULL; cur = cur->next) {
6673 GtkTreePath *path = cur->data;
6674 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6677 gtk_tree_path_free(path);
6680 for (cur = sel; cur != NULL; cur = cur->next) {
6681 GtkTreeRowReference *ref = cur->data;
6682 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6685 if (gtk_tree_model_get_iter(model, &iter, path))
6686 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6688 gtk_tree_path_free(path);
6689 gtk_tree_row_reference_free(ref);
6695 static struct _AttachProperty
6698 GtkWidget *mimetype_entry;
6699 GtkWidget *encoding_optmenu;
6700 GtkWidget *path_entry;
6701 GtkWidget *filename_entry;
6703 GtkWidget *cancel_btn;
6706 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6708 gtk_tree_path_free((GtkTreePath *)ptr);
6711 static void compose_attach_property(Compose *compose)
6713 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6715 GtkOptionMenu *optmenu;
6716 GtkTreeSelection *selection;
6718 GtkTreeModel *model;
6721 static gboolean cancelled;
6723 /* only if one selected */
6724 selection = gtk_tree_view_get_selection(tree_view);
6725 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6728 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6732 path = (GtkTreePath *) sel->data;
6733 gtk_tree_model_get_iter(model, &iter, path);
6734 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6737 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6743 if (!attach_prop.window)
6744 compose_attach_property_create(&cancelled);
6745 gtk_widget_grab_focus(attach_prop.ok_btn);
6746 gtk_widget_show(attach_prop.window);
6747 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6749 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6750 if (ainfo->encoding == ENC_UNKNOWN)
6751 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6752 GINT_TO_POINTER(ENC_BASE64));
6754 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6755 GINT_TO_POINTER(ainfo->encoding));
6757 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6758 ainfo->content_type ? ainfo->content_type : "");
6759 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6760 ainfo->file ? ainfo->file : "");
6761 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6762 ainfo->name ? ainfo->name : "");
6765 const gchar *entry_text;
6767 gchar *cnttype = NULL;
6771 GtkWidget *menuitem;
6776 gtk_widget_hide(attach_prop.window);
6781 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6782 if (*entry_text != '\0') {
6785 text = g_strstrip(g_strdup(entry_text));
6786 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6787 cnttype = g_strdup(text);
6790 alertpanel_error(_("Invalid MIME type."));
6796 menu = gtk_option_menu_get_menu(optmenu);
6797 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6798 ainfo->encoding = GPOINTER_TO_INT
6799 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6801 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6802 if (*entry_text != '\0') {
6803 if (is_file_exist(entry_text) &&
6804 (size = get_file_size(entry_text)) > 0)
6805 file = g_strdup(entry_text);
6808 (_("File doesn't exist or is empty."));
6814 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6815 if (*entry_text != '\0') {
6816 g_free(ainfo->name);
6817 ainfo->name = g_strdup(entry_text);
6821 g_free(ainfo->content_type);
6822 ainfo->content_type = cnttype;
6825 g_free(ainfo->file);
6831 /* update tree store */
6832 text = to_human_readable(ainfo->size);
6833 gtk_tree_model_get_iter(model, &iter, path);
6834 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6835 COL_MIMETYPE, ainfo->content_type,
6837 COL_NAME, ainfo->name,
6843 gtk_tree_path_free(path);
6846 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6848 label = gtk_label_new(str); \
6849 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6850 GTK_FILL, 0, 0, 0); \
6851 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6853 entry = gtk_entry_new(); \
6854 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6855 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6858 static void compose_attach_property_create(gboolean *cancelled)
6864 GtkWidget *mimetype_entry;
6867 GtkWidget *optmenu_menu;
6868 GtkWidget *menuitem;
6869 GtkWidget *path_entry;
6870 GtkWidget *filename_entry;
6873 GtkWidget *cancel_btn;
6874 GList *mime_type_list, *strlist;
6876 debug_print("Creating attach_property window...\n");
6878 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6879 gtk_widget_set_size_request(window, 480, -1);
6880 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6881 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6882 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6883 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6884 g_signal_connect(G_OBJECT(window), "delete_event",
6885 G_CALLBACK(attach_property_delete_event),
6887 g_signal_connect(G_OBJECT(window), "key_press_event",
6888 G_CALLBACK(attach_property_key_pressed),
6891 vbox = gtk_vbox_new(FALSE, 8);
6892 gtk_container_add(GTK_CONTAINER(window), vbox);
6894 table = gtk_table_new(4, 2, FALSE);
6895 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6896 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6897 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6899 label = gtk_label_new(_("MIME type"));
6900 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6902 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6903 mimetype_entry = gtk_combo_new();
6904 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6905 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6907 /* stuff with list */
6908 mime_type_list = procmime_get_mime_type_list();
6910 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6911 MimeType *type = (MimeType *) mime_type_list->data;
6914 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6916 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6919 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6920 (GCompareFunc)strcmp2);
6923 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6925 for (mime_type_list = strlist; mime_type_list != NULL;
6926 mime_type_list = mime_type_list->next)
6927 g_free(mime_type_list->data);
6928 g_list_free(strlist);
6930 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6932 label = gtk_label_new(_("Encoding"));
6933 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6935 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6937 hbox = gtk_hbox_new(FALSE, 0);
6938 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6939 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6941 optmenu = gtk_option_menu_new();
6942 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6944 optmenu_menu = gtk_menu_new();
6945 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6946 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6947 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6948 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6949 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6950 ENC_QUOTED_PRINTABLE);
6951 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6953 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6955 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6957 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6958 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6960 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
6961 &ok_btn, GTK_STOCK_OK,
6963 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6964 gtk_widget_grab_default(ok_btn);
6966 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6967 G_CALLBACK(attach_property_ok),
6969 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6970 G_CALLBACK(attach_property_cancel),
6973 gtk_widget_show_all(vbox);
6975 attach_prop.window = window;
6976 attach_prop.mimetype_entry = mimetype_entry;
6977 attach_prop.encoding_optmenu = optmenu;
6978 attach_prop.path_entry = path_entry;
6979 attach_prop.filename_entry = filename_entry;
6980 attach_prop.ok_btn = ok_btn;
6981 attach_prop.cancel_btn = cancel_btn;
6984 #undef SET_LABEL_AND_ENTRY
6986 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6992 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6998 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6999 gboolean *cancelled)
7007 static gboolean attach_property_key_pressed(GtkWidget *widget,
7009 gboolean *cancelled)
7011 if (event && event->keyval == GDK_Escape) {
7018 static void compose_exec_ext_editor(Compose *compose)
7025 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
7026 G_DIR_SEPARATOR, compose);
7028 if (pipe(pipe_fds) < 0) {
7034 if ((pid = fork()) < 0) {
7041 /* close the write side of the pipe */
7044 compose->exteditor_file = g_strdup(tmp);
7045 compose->exteditor_pid = pid;
7047 compose_set_ext_editor_sensitive(compose, FALSE);
7049 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
7050 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
7054 } else { /* process-monitoring process */
7060 /* close the read side of the pipe */
7063 if (compose_write_body_to_file(compose, tmp) < 0) {
7064 fd_write_all(pipe_fds[1], "2\n", 2);
7068 pid_ed = compose_exec_ext_editor_real(tmp);
7070 fd_write_all(pipe_fds[1], "1\n", 2);
7074 /* wait until editor is terminated */
7075 waitpid(pid_ed, NULL, 0);
7077 fd_write_all(pipe_fds[1], "0\n", 2);
7084 #endif /* G_OS_UNIX */
7088 static gint compose_exec_ext_editor_real(const gchar *file)
7095 g_return_val_if_fail(file != NULL, -1);
7097 if ((pid = fork()) < 0) {
7102 if (pid != 0) return pid;
7104 /* grandchild process */
7106 if (setpgid(0, getppid()))
7109 if (prefs_common.ext_editor_cmd &&
7110 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
7111 *(p + 1) == 's' && !strchr(p + 2, '%')) {
7112 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
7114 if (prefs_common.ext_editor_cmd)
7115 g_warning("External editor command line is invalid: '%s'\n",
7116 prefs_common.ext_editor_cmd);
7117 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
7120 cmdline = strsplit_with_quote(buf, " ", 1024);
7121 execvp(cmdline[0], cmdline);
7124 g_strfreev(cmdline);
7129 static gboolean compose_ext_editor_kill(Compose *compose)
7131 pid_t pgid = compose->exteditor_pid * -1;
7134 ret = kill(pgid, 0);
7136 if (ret == 0 || (ret == -1 && EPERM == errno)) {
7140 msg = g_strdup_printf
7141 (_("The external editor is still working.\n"
7142 "Force terminating the process?\n"
7143 "process group id: %d"), -pgid);
7144 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
7145 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
7149 if (val == G_ALERTALTERNATE) {
7150 g_source_remove(compose->exteditor_tag);
7151 g_io_channel_shutdown(compose->exteditor_ch,
7153 g_io_channel_unref(compose->exteditor_ch);
7155 if (kill(pgid, SIGTERM) < 0) perror("kill");
7156 waitpid(compose->exteditor_pid, NULL, 0);
7158 g_warning("Terminated process group id: %d", -pgid);
7159 g_warning("Temporary file: %s",
7160 compose->exteditor_file);
7162 compose_set_ext_editor_sensitive(compose, TRUE);
7164 g_free(compose->exteditor_file);
7165 compose->exteditor_file = NULL;
7166 compose->exteditor_pid = -1;
7167 compose->exteditor_ch = NULL;
7168 compose->exteditor_tag = -1;
7176 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
7180 Compose *compose = (Compose *)data;
7183 debug_print(_("Compose: input from monitoring process\n"));
7185 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
7187 g_io_channel_shutdown(source, FALSE, NULL);
7188 g_io_channel_unref(source);
7190 waitpid(compose->exteditor_pid, NULL, 0);
7192 if (buf[0] == '0') { /* success */
7193 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7194 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
7196 gtk_text_buffer_set_text(buffer, "", -1);
7197 compose_insert_file(compose, compose->exteditor_file);
7198 compose_changed_cb(NULL, compose);
7200 if (g_unlink(compose->exteditor_file) < 0)
7201 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7202 } else if (buf[0] == '1') { /* failed */
7203 g_warning("Couldn't exec external editor\n");
7204 if (g_unlink(compose->exteditor_file) < 0)
7205 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7206 } else if (buf[0] == '2') {
7207 g_warning("Couldn't write to file\n");
7208 } else if (buf[0] == '3') {
7209 g_warning("Pipe read failed\n");
7212 compose_set_ext_editor_sensitive(compose, TRUE);
7214 g_free(compose->exteditor_file);
7215 compose->exteditor_file = NULL;
7216 compose->exteditor_pid = -1;
7217 compose->exteditor_ch = NULL;
7218 compose->exteditor_tag = -1;
7223 static void compose_set_ext_editor_sensitive(Compose *compose,
7226 GtkItemFactory *ifactory;
7228 ifactory = gtk_item_factory_from_widget(compose->menubar);
7230 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
7231 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
7232 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
7233 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
7234 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
7235 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
7236 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
7239 gtk_widget_set_sensitive(compose->text, sensitive);
7240 if (compose->toolbar->send_btn)
7241 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
7242 if (compose->toolbar->sendl_btn)
7243 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
7244 if (compose->toolbar->draft_btn)
7245 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
7246 if (compose->toolbar->insert_btn)
7247 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
7248 if (compose->toolbar->sig_btn)
7249 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
7250 if (compose->toolbar->exteditor_btn)
7251 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
7252 if (compose->toolbar->linewrap_current_btn)
7253 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
7254 if (compose->toolbar->linewrap_all_btn)
7255 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
7257 #endif /* G_OS_UNIX */
7260 * compose_undo_state_changed:
7262 * Change the sensivity of the menuentries undo and redo
7264 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
7265 gint redo_state, gpointer data)
7267 GtkWidget *widget = GTK_WIDGET(data);
7268 GtkItemFactory *ifactory;
7270 g_return_if_fail(widget != NULL);
7272 ifactory = gtk_item_factory_from_widget(widget);
7274 switch (undo_state) {
7275 case UNDO_STATE_TRUE:
7276 if (!undostruct->undo_state) {
7277 undostruct->undo_state = TRUE;
7278 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
7281 case UNDO_STATE_FALSE:
7282 if (undostruct->undo_state) {
7283 undostruct->undo_state = FALSE;
7284 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
7287 case UNDO_STATE_UNCHANGED:
7289 case UNDO_STATE_REFRESH:
7290 menu_set_sensitive(ifactory, "/Edit/Undo",
7291 undostruct->undo_state);
7294 g_warning("Undo state not recognized");
7298 switch (redo_state) {
7299 case UNDO_STATE_TRUE:
7300 if (!undostruct->redo_state) {
7301 undostruct->redo_state = TRUE;
7302 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
7305 case UNDO_STATE_FALSE:
7306 if (undostruct->redo_state) {
7307 undostruct->redo_state = FALSE;
7308 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
7311 case UNDO_STATE_UNCHANGED:
7313 case UNDO_STATE_REFRESH:
7314 menu_set_sensitive(ifactory, "/Edit/Redo",
7315 undostruct->redo_state);
7318 g_warning("Redo state not recognized");
7323 /* callback functions */
7325 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
7326 * includes "non-client" (windows-izm) in calculation, so this calculation
7327 * may not be accurate.
7329 static gboolean compose_edit_size_alloc(GtkEditable *widget,
7330 GtkAllocation *allocation,
7331 GtkSHRuler *shruler)
7333 if (prefs_common.show_ruler) {
7334 gint char_width = 0, char_height = 0;
7335 gint line_width_in_chars;
7337 gtkut_get_font_size(GTK_WIDGET(widget),
7338 &char_width, &char_height);
7339 line_width_in_chars =
7340 (allocation->width - allocation->x) / char_width;
7342 /* got the maximum */
7343 gtk_ruler_set_range(GTK_RULER(shruler),
7344 0.0, line_width_in_chars, 0,
7345 /*line_width_in_chars*/ char_width);
7351 static void account_activated(GtkMenuItem *menuitem, gpointer data)
7353 Compose *compose = (Compose *)data;
7356 gchar *folderidentifier;
7358 ac = account_find_from_id(
7359 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
7360 g_return_if_fail(ac != NULL);
7362 if (ac != compose->account)
7363 compose_select_account(compose, ac, FALSE);
7365 /* Set message save folder */
7366 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7367 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
7369 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
7370 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
7372 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7373 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7374 folderidentifier = folder_item_get_identifier(account_get_special_folder
7375 (compose->account, F_OUTBOX));
7376 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
7377 g_free(folderidentifier);
7381 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
7382 GtkTreeViewColumn *column, Compose *compose)
7384 compose_attach_property(compose);
7387 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
7390 Compose *compose = (Compose *)data;
7391 GtkTreeSelection *attach_selection;
7392 gint attach_nr_selected;
7393 GtkItemFactory *ifactory;
7395 if (!event) return FALSE;
7397 if (event->button == 3) {
7398 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
7399 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
7400 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7402 if (attach_nr_selected > 0)
7404 menu_set_sensitive(ifactory, "/Remove", TRUE);
7405 menu_set_sensitive(ifactory, "/Properties...", TRUE);
7407 menu_set_sensitive(ifactory, "/Remove", FALSE);
7408 menu_set_sensitive(ifactory, "/Properties...", FALSE);
7411 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
7412 NULL, NULL, event->button, event->time);
7419 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
7422 Compose *compose = (Compose *)data;
7424 if (!event) return FALSE;
7426 switch (event->keyval) {
7428 compose_attach_remove_selected(compose);
7434 static void compose_allow_user_actions (Compose *compose, gboolean allow)
7436 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
7437 toolbar_comp_set_sensitive(compose, allow);
7438 menu_set_sensitive(ifactory, "/Message", allow);
7439 menu_set_sensitive(ifactory, "/Edit", allow);
7441 menu_set_sensitive(ifactory, "/Spelling", allow);
7443 menu_set_sensitive(ifactory, "/Options", allow);
7444 menu_set_sensitive(ifactory, "/Tools", allow);
7445 menu_set_sensitive(ifactory, "/Help", allow);
7447 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7451 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7453 Compose *compose = (Compose *)data;
7455 if (prefs_common.work_offline &&
7456 !inc_offline_should_override(
7457 _("Sylpheed-Claws needs network access in order "
7458 "to send this email.")))
7461 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7462 gtk_timeout_remove(compose->draft_timeout_tag);
7463 compose->draft_timeout_tag = -1;
7466 compose_send(compose);
7469 static void compose_send_later_cb(gpointer data, guint action,
7472 Compose *compose = (Compose *)data;
7475 val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE);
7477 compose_close(compose);
7478 else if (val == -2) {
7479 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7480 } else if (val == -3) {
7481 alertpanel_error(_("Could not queue message for sending:\n\n"
7482 "Signature failed."));
7483 } else if (val == -4) {
7484 alertpanel_error(_("Could not queue message for sending:\n\n"
7485 "Charset conversion failed."));
7489 void compose_draft (gpointer data)
7491 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7494 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7496 Compose *compose = (Compose *)data;
7500 MsgFlags flag = {0, 0};
7501 static gboolean lock = FALSE;
7502 MsgInfo *newmsginfo;
7504 gboolean target_locked = FALSE;
7508 draft = account_get_special_folder(compose->account, F_DRAFT);
7509 g_return_if_fail(draft != NULL);
7511 if (!g_mutex_trylock(compose->mutex)) {
7512 /* we don't want to lock the mutex once it's available,
7513 * because as the only other part of compose.c locking
7514 * it is compose_close - which means once unlocked,
7515 * the compose struct will be freed */
7516 debug_print("couldn't lock mutex, probably sending\n");
7522 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7523 G_DIR_SEPARATOR, compose);
7524 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7525 FILE_OP_ERROR(tmp, "fopen");
7529 /* chmod for security */
7530 if (change_file_mode_rw(fp, tmp) < 0) {
7531 FILE_OP_ERROR(tmp, "chmod");
7532 g_warning("can't change file mode\n");
7535 /* Save draft infos */
7536 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7537 fprintf(fp, "S:%s\n", compose->account->address);
7539 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7540 gchar *savefolderid;
7542 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7543 fprintf(fp, "SCF:%s\n", savefolderid);
7544 g_free(savefolderid);
7546 if (compose->return_receipt) {
7547 fprintf(fp, "RRCPT:1\n");
7549 if (compose->privacy_system) {
7550 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7551 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7552 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7556 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
7564 if (compose->targetinfo) {
7565 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7566 flag.perm_flags = target_locked?MSG_LOCKED:0;
7568 flag.tmp_flags = MSG_DRAFT;
7570 folder_item_scan(draft);
7571 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7574 if (action != COMPOSE_AUTO_SAVE)
7575 alertpanel_error(_("Could not save draft."));
7579 draft->mtime = 0; /* force updating */
7581 if (compose->mode == COMPOSE_REEDIT) {
7582 compose_remove_reedit_target(compose, TRUE);
7585 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7587 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7589 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
7591 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7592 if (compose_use_attach(compose))
7593 procmsg_msginfo_set_flags(newmsginfo, 0,
7594 MSG_HAS_ATTACHMENT);
7596 procmsg_msginfo_free(newmsginfo);
7599 folder_item_scan(draft);
7601 if (action == COMPOSE_QUIT_EDITING) {
7603 g_mutex_unlock(compose->mutex); /* must be done before closing */
7604 compose_close(compose);
7610 path = folder_item_fetch_msg(draft, msgnum);
7612 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
7615 if (g_stat(path, &s) < 0) {
7616 FILE_OP_ERROR(path, "stat");
7622 procmsg_msginfo_free(compose->targetinfo);
7623 compose->targetinfo = procmsg_msginfo_new();
7624 compose->targetinfo->msgnum = msgnum;
7625 compose->targetinfo->size = s.st_size;
7626 compose->targetinfo->mtime = s.st_mtime;
7627 compose->targetinfo->folder = draft;
7629 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
7630 compose->mode = COMPOSE_REEDIT;
7632 if (action == COMPOSE_AUTO_SAVE) {
7633 compose->autosaved_draft = compose->targetinfo;
7635 compose->modified = FALSE;
7636 compose_set_title(compose);
7640 g_mutex_unlock(compose->mutex);
7643 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7645 Compose *compose = (Compose *)data;
7648 if (compose->redirect_filename != NULL)
7651 file_list = filesel_select_multiple_files_open(_("Select file"));
7656 for ( tmp = file_list; tmp; tmp = tmp->next) {
7657 gchar *file = (gchar *) tmp->data;
7658 gchar *utf8_filename = conv_filename_to_utf8(file);
7659 compose_attach_append(compose, file, utf8_filename, NULL);
7660 compose_changed_cb(NULL, compose);
7662 g_free(utf8_filename);
7664 g_list_free(file_list);
7668 static void compose_insert_file_cb(gpointer data, guint action,
7671 Compose *compose = (Compose *)data;
7674 file_list = filesel_select_multiple_files_open(_("Select file"));
7679 for ( tmp = file_list; tmp; tmp = tmp->next) {
7680 gchar *file = (gchar *) tmp->data;
7681 gchar *filedup = g_strdup(file);
7682 gchar *shortfile = g_path_get_basename(filedup);
7683 ComposeInsertResult res;
7685 res = compose_insert_file(compose, file);
7686 if (res == COMPOSE_INSERT_READ_ERROR) {
7687 alertpanel_error(_("File '%s' could not be read."), shortfile);
7688 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7689 alertpanel_error(_("File '%s' contained invalid characters\n"
7690 "for the current encoding, insertion may be incorrect."), shortfile);
7696 g_list_free(file_list);
7700 static void compose_insert_sig_cb(gpointer data, guint action,
7703 Compose *compose = (Compose *)data;
7705 compose_insert_sig(compose, FALSE);
7708 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7712 Compose *compose = (Compose *)data;
7714 gtkut_widget_get_uposition(widget, &x, &y);
7715 prefs_common.compose_x = x;
7716 prefs_common.compose_y = y;
7718 if (compose->sending)
7720 compose_close_cb(compose, 0, NULL);
7724 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7726 Compose *compose = (Compose *)data;
7730 if (compose->exteditor_tag != -1) {
7731 if (!compose_ext_editor_kill(compose))
7736 if (compose->modified) {
7737 val = alertpanel(_("Discard message"),
7738 _("This message has been modified. Discard it?"),
7739 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7742 case G_ALERTDEFAULT:
7743 if (prefs_common.autosave)
7744 compose_remove_draft(compose);
7746 case G_ALERTALTERNATE:
7747 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7754 compose_close(compose);
7757 static void compose_set_encoding_cb(gpointer data, guint action,
7760 Compose *compose = (Compose *)data;
7762 if (GTK_CHECK_MENU_ITEM(widget)->active)
7763 compose->out_encoding = (CharSet)action;
7766 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7768 Compose *compose = (Compose *)data;
7770 addressbook_open(compose);
7773 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7775 Compose *compose = (Compose *)data;
7780 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7781 g_return_if_fail(tmpl != NULL);
7783 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7785 val = alertpanel(_("Apply template"), msg,
7786 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7789 if (val == G_ALERTDEFAULT)
7790 compose_template_apply(compose, tmpl, TRUE);
7791 else if (val == G_ALERTALTERNATE)
7792 compose_template_apply(compose, tmpl, FALSE);
7795 static void compose_ext_editor_cb(gpointer data, guint action,
7798 Compose *compose = (Compose *)data;
7800 compose_exec_ext_editor(compose);
7803 static void compose_undo_cb(Compose *compose)
7805 gboolean prev_autowrap = compose->autowrap;
7807 compose->autowrap = FALSE;
7808 undo_undo(compose->undostruct);
7809 compose->autowrap = prev_autowrap;
7812 static void compose_redo_cb(Compose *compose)
7814 gboolean prev_autowrap = compose->autowrap;
7816 compose->autowrap = FALSE;
7817 undo_redo(compose->undostruct);
7818 compose->autowrap = prev_autowrap;
7821 static void entry_cut_clipboard(GtkWidget *entry)
7823 if (GTK_IS_EDITABLE(entry))
7824 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7825 else if (GTK_IS_TEXT_VIEW(entry))
7826 gtk_text_buffer_cut_clipboard(
7827 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7828 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7832 static void entry_copy_clipboard(GtkWidget *entry)
7834 if (GTK_IS_EDITABLE(entry))
7835 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7836 else if (GTK_IS_TEXT_VIEW(entry))
7837 gtk_text_buffer_copy_clipboard(
7838 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7839 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7842 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7843 gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
7845 if (GTK_IS_TEXT_VIEW(entry)) {
7846 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7847 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7848 GtkTextIter start_iter, end_iter;
7851 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7853 if (contents == NULL)
7856 /* we shouldn't delete the selection when middle-click-pasting, or we
7857 * can't mid-click-paste our own selection */
7858 if (clip != GDK_SELECTION_PRIMARY)
7859 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7861 if (insert_place == NULL) {
7862 /* if insert_place isn't specified, insert at the cursor.
7863 * used for Ctrl-V pasting */
7864 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7865 start = gtk_text_iter_get_offset(&start_iter);
7866 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7868 /* if insert_place is specified, paste here.
7869 * used for mid-click-pasting */
7870 start = gtk_text_iter_get_offset(insert_place);
7871 gtk_text_buffer_insert(buffer, insert_place, contents, strlen(contents));
7875 /* paste unwrapped: mark the paste so it's not wrapped later */
7876 end = start + strlen(contents);
7877 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7878 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7879 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7880 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7881 /* rewrap paragraph now (after a mid-click-paste) */
7882 mark_start = gtk_text_buffer_get_insert(buffer);
7883 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7884 gtk_text_iter_backward_char(&start_iter);
7885 compose_beautify_paragraph(compose, &start_iter, TRUE);
7888 } else if (GTK_IS_EDITABLE(entry))
7889 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7893 static void entry_allsel(GtkWidget *entry)
7895 if (GTK_IS_EDITABLE(entry))
7896 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7897 else if (GTK_IS_TEXT_VIEW(entry)) {
7898 GtkTextIter startiter, enditer;
7899 GtkTextBuffer *textbuf;
7901 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7902 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7903 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7905 gtk_text_buffer_move_mark_by_name(textbuf,
7906 "selection_bound", &startiter);
7907 gtk_text_buffer_move_mark_by_name(textbuf,
7908 "insert", &enditer);
7912 static void compose_cut_cb(Compose *compose)
7914 if (compose->focused_editable &&
7915 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7916 entry_cut_clipboard(compose->focused_editable);
7919 static void compose_copy_cb(Compose *compose)
7921 if (compose->focused_editable &&
7922 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7923 entry_copy_clipboard(compose->focused_editable);
7926 static void compose_paste_cb(Compose *compose)
7929 GtkTextBuffer *buffer;
7931 if (compose->focused_editable &&
7932 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7933 entry_paste_clipboard(compose, compose->focused_editable,
7934 prefs_common.linewrap_pastes,
7935 GDK_SELECTION_CLIPBOARD, NULL);
7939 static void compose_paste_as_quote_cb(Compose *compose)
7941 gint wrap_quote = prefs_common.linewrap_quote;
7942 if (compose->focused_editable &&
7943 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7944 /* let text_insert() (called directly or at a later time
7945 * after the gtk_editable_paste_clipboard) know that
7946 * text is to be inserted as a quotation. implemented
7947 * by using a simple refcount... */
7948 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7949 G_OBJECT(compose->focused_editable),
7950 "paste_as_quotation"));
7951 g_object_set_data(G_OBJECT(compose->focused_editable),
7952 "paste_as_quotation",
7953 GINT_TO_POINTER(paste_as_quotation + 1));
7954 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7955 entry_paste_clipboard(compose, compose->focused_editable,
7956 prefs_common.linewrap_pastes,
7957 GDK_SELECTION_CLIPBOARD, NULL);
7958 prefs_common.linewrap_quote = wrap_quote;
7962 static void compose_paste_no_wrap_cb(Compose *compose)
7965 GtkTextBuffer *buffer;
7967 if (compose->focused_editable &&
7968 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7969 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7970 GDK_SELECTION_CLIPBOARD, NULL);
7974 static void compose_paste_wrap_cb(Compose *compose)
7977 GtkTextBuffer *buffer;
7979 if (compose->focused_editable &&
7980 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7981 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7982 GDK_SELECTION_CLIPBOARD, NULL);
7986 static void compose_allsel_cb(Compose *compose)
7988 if (compose->focused_editable &&
7989 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7990 entry_allsel(compose->focused_editable);
7993 static void textview_move_beginning_of_line (GtkTextView *text)
7995 GtkTextBuffer *buffer;
7999 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8001 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8002 mark = gtk_text_buffer_get_insert(buffer);
8003 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8004 gtk_text_iter_set_line_offset(&ins, 0);
8005 gtk_text_buffer_place_cursor(buffer, &ins);
8008 static void textview_move_forward_character (GtkTextView *text)
8010 GtkTextBuffer *buffer;
8014 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8016 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8017 mark = gtk_text_buffer_get_insert(buffer);
8018 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8019 if (gtk_text_iter_forward_cursor_position(&ins))
8020 gtk_text_buffer_place_cursor(buffer, &ins);
8023 static void textview_move_backward_character (GtkTextView *text)
8025 GtkTextBuffer *buffer;
8029 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8031 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8032 mark = gtk_text_buffer_get_insert(buffer);
8033 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8034 if (gtk_text_iter_backward_cursor_position(&ins))
8035 gtk_text_buffer_place_cursor(buffer, &ins);
8038 static void textview_move_forward_word (GtkTextView *text)
8040 GtkTextBuffer *buffer;
8045 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8047 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8048 mark = gtk_text_buffer_get_insert(buffer);
8049 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8050 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8051 if (gtk_text_iter_forward_word_ends(&ins, count)) {
8052 gtk_text_iter_backward_word_start(&ins);
8053 gtk_text_buffer_place_cursor(buffer, &ins);
8057 static void textview_move_backward_word (GtkTextView *text)
8059 GtkTextBuffer *buffer;
8064 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8066 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8067 mark = gtk_text_buffer_get_insert(buffer);
8068 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8069 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8070 if (gtk_text_iter_backward_word_starts(&ins, 1))
8071 gtk_text_buffer_place_cursor(buffer, &ins);
8074 static void textview_move_end_of_line (GtkTextView *text)
8076 GtkTextBuffer *buffer;
8080 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8082 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8083 mark = gtk_text_buffer_get_insert(buffer);
8084 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8085 if (gtk_text_iter_forward_to_line_end(&ins))
8086 gtk_text_buffer_place_cursor(buffer, &ins);
8089 static void textview_move_next_line (GtkTextView *text)
8091 GtkTextBuffer *buffer;
8096 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8098 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8099 mark = gtk_text_buffer_get_insert(buffer);
8100 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8101 offset = gtk_text_iter_get_line_offset(&ins);
8102 if (gtk_text_iter_forward_line(&ins)) {
8103 gtk_text_iter_set_line_offset(&ins, offset);
8104 gtk_text_buffer_place_cursor(buffer, &ins);
8108 static void textview_move_previous_line (GtkTextView *text)
8110 GtkTextBuffer *buffer;
8115 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8117 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8118 mark = gtk_text_buffer_get_insert(buffer);
8119 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8120 offset = gtk_text_iter_get_line_offset(&ins);
8121 if (gtk_text_iter_backward_line(&ins)) {
8122 gtk_text_iter_set_line_offset(&ins, offset);
8123 gtk_text_buffer_place_cursor(buffer, &ins);
8127 static void textview_delete_forward_character (GtkTextView *text)
8129 GtkTextBuffer *buffer;
8131 GtkTextIter ins, end_iter;
8133 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8135 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8136 mark = gtk_text_buffer_get_insert(buffer);
8137 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8139 if (gtk_text_iter_forward_char(&end_iter)) {
8140 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8144 static void textview_delete_backward_character (GtkTextView *text)
8146 GtkTextBuffer *buffer;
8148 GtkTextIter ins, end_iter;
8150 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8152 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8153 mark = gtk_text_buffer_get_insert(buffer);
8154 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8156 if (gtk_text_iter_backward_char(&end_iter)) {
8157 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8161 static void textview_delete_forward_word (GtkTextView *text)
8163 GtkTextBuffer *buffer;
8165 GtkTextIter ins, end_iter;
8167 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8169 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8170 mark = gtk_text_buffer_get_insert(buffer);
8171 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8173 if (gtk_text_iter_forward_word_end(&end_iter)) {
8174 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8178 static void textview_delete_backward_word (GtkTextView *text)
8180 GtkTextBuffer *buffer;
8182 GtkTextIter ins, end_iter;
8184 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8186 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8187 mark = gtk_text_buffer_get_insert(buffer);
8188 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8190 if (gtk_text_iter_backward_word_start(&end_iter)) {
8191 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8195 static void textview_delete_line (GtkTextView *text)
8197 GtkTextBuffer *buffer;
8199 GtkTextIter ins, start_iter, end_iter;
8202 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8204 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8205 mark = gtk_text_buffer_get_insert(buffer);
8206 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8209 gtk_text_iter_set_line_offset(&start_iter, 0);
8212 if (gtk_text_iter_ends_line(&end_iter))
8213 found = gtk_text_iter_forward_char(&end_iter);
8215 found = gtk_text_iter_forward_to_line_end(&end_iter);
8218 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
8221 static void textview_delete_to_line_end (GtkTextView *text)
8223 GtkTextBuffer *buffer;
8225 GtkTextIter ins, end_iter;
8228 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8230 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8231 mark = gtk_text_buffer_get_insert(buffer);
8232 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8234 if (gtk_text_iter_ends_line(&end_iter))
8235 found = gtk_text_iter_forward_char(&end_iter);
8237 found = gtk_text_iter_forward_to_line_end(&end_iter);
8239 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8242 static void compose_advanced_action_cb(Compose *compose,
8243 ComposeCallAdvancedAction action)
8245 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8247 void (*do_action) (GtkTextView *text);
8248 } action_table[] = {
8249 {textview_move_beginning_of_line},
8250 {textview_move_forward_character},
8251 {textview_move_backward_character},
8252 {textview_move_forward_word},
8253 {textview_move_backward_word},
8254 {textview_move_end_of_line},
8255 {textview_move_next_line},
8256 {textview_move_previous_line},
8257 {textview_delete_forward_character},
8258 {textview_delete_backward_character},
8259 {textview_delete_forward_word},
8260 {textview_delete_backward_word},
8261 {textview_delete_line},
8262 {NULL}, /* gtk_stext_delete_line_n */
8263 {textview_delete_to_line_end}
8266 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
8268 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
8269 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
8270 if (action_table[action].do_action)
8271 action_table[action].do_action(text);
8273 g_warning("Not implemented yet.");
8277 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
8281 if (GTK_IS_EDITABLE(widget)) {
8282 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
8283 gtk_editable_set_position(GTK_EDITABLE(widget),
8286 if (widget->parent && widget->parent->parent
8287 && widget->parent->parent->parent) {
8288 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
8289 gint y = widget->allocation.y;
8290 gint height = widget->allocation.height;
8291 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
8292 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
8294 if (y < (int)shown->value) {
8295 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
8297 if (y + height > (int)shown->value + (int)shown->page_size) {
8298 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
8299 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8300 y + height - (int)shown->page_size - 1);
8302 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8303 (int)shown->upper - (int)shown->page_size - 1);
8310 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
8311 compose->focused_editable = widget;
8314 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
8316 compose->modified = TRUE;
8317 compose_set_title(compose);
8320 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
8322 Compose *compose = (Compose *)data;
8325 compose_wrap_all_full(compose, TRUE);
8327 compose_beautify_paragraph(compose, NULL, TRUE);
8330 static void compose_find_cb(gpointer data, guint action, GtkWidget *widget)
8332 Compose *compose = (Compose *)data;
8334 message_search_compose(compose);
8337 static void compose_toggle_autowrap_cb(gpointer data, guint action,
8340 Compose *compose = (Compose *)data;
8341 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8342 if (compose->autowrap)
8343 compose_wrap_all_full(compose, TRUE);
8344 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8347 static void compose_toggle_sign_cb(gpointer data, guint action,
8350 Compose *compose = (Compose *)data;
8352 if (GTK_CHECK_MENU_ITEM(widget)->active)
8353 compose->use_signing = TRUE;
8355 compose->use_signing = FALSE;
8358 static void compose_toggle_encrypt_cb(gpointer data, guint action,
8361 Compose *compose = (Compose *)data;
8363 if (GTK_CHECK_MENU_ITEM(widget)->active)
8364 compose->use_encryption = TRUE;
8366 compose->use_encryption = FALSE;
8369 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
8371 g_free(compose->privacy_system);
8373 compose->privacy_system = g_strdup(account->default_privacy_system);
8374 compose_update_privacy_system_menu_item(compose, warn);
8377 static void compose_toggle_ruler_cb(gpointer data, guint action,
8380 Compose *compose = (Compose *)data;
8382 if (GTK_CHECK_MENU_ITEM(widget)->active) {
8383 gtk_widget_show(compose->ruler_hbox);
8384 prefs_common.show_ruler = TRUE;
8386 gtk_widget_hide(compose->ruler_hbox);
8387 gtk_widget_queue_resize(compose->edit_vbox);
8388 prefs_common.show_ruler = FALSE;
8392 static void compose_attach_drag_received_cb (GtkWidget *widget,
8393 GdkDragContext *context,
8396 GtkSelectionData *data,
8401 Compose *compose = (Compose *)user_data;
8404 if (gdk_atom_name(data->type) &&
8405 !strcmp(gdk_atom_name(data->type), "text/uri-list")
8406 && gtk_drag_get_source_widget(context) !=
8407 mainwindow_get_mainwindow()->summaryview->ctree) {
8408 list = uri_list_extract_filenames((const gchar *)data->data);
8409 for (tmp = list; tmp != NULL; tmp = tmp->next)
8410 compose_attach_append
8411 (compose, (const gchar *)tmp->data,
8412 (const gchar *)tmp->data, NULL);
8413 if (list) compose_changed_cb(NULL, compose);
8414 list_free_strings(list);
8416 } else if (gtk_drag_get_source_widget(context)
8417 == mainwindow_get_mainwindow()->summaryview->ctree) {
8418 /* comes from our summaryview */
8419 SummaryView * summaryview = NULL;
8420 GSList * list = NULL, *cur = NULL;
8422 if (mainwindow_get_mainwindow())
8423 summaryview = mainwindow_get_mainwindow()->summaryview;
8426 list = summary_get_selected_msg_list(summaryview);
8428 for (cur = list; cur; cur = cur->next) {
8429 MsgInfo *msginfo = (MsgInfo *)cur->data;
8432 file = procmsg_get_message_file_full(msginfo,
8435 compose_attach_append(compose, (const gchar *)file,
8436 (const gchar *)file, "message/rfc822");
8444 static gboolean compose_drag_drop(GtkWidget *widget,
8445 GdkDragContext *drag_context,
8447 guint time, gpointer user_data)
8449 /* not handling this signal makes compose_insert_drag_received_cb
8454 static void compose_insert_drag_received_cb (GtkWidget *widget,
8455 GdkDragContext *drag_context,
8458 GtkSelectionData *data,
8463 Compose *compose = (Compose *)user_data;
8466 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
8468 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
8469 list = uri_list_extract_filenames((const gchar *)data->data);
8470 for (tmp = list; tmp != NULL; tmp = tmp->next) {
8471 compose_insert_file(compose, (const gchar *)tmp->data);
8473 list_free_strings(list);
8475 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8478 #if GTK_CHECK_VERSION(2, 8, 0)
8479 /* do nothing, handled by GTK */
8481 gchar *tmpfile = get_tmp_file();
8482 str_write_to_file((const gchar *)data->data, tmpfile);
8483 compose_insert_file(compose, tmpfile);
8486 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8490 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8493 static void compose_header_drag_received_cb (GtkWidget *widget,
8494 GdkDragContext *drag_context,
8497 GtkSelectionData *data,
8502 GtkEditable *entry = (GtkEditable *)user_data;
8503 gchar *email = (gchar *)data->data;
8505 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8508 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8509 gchar *decoded=g_new(gchar, strlen(email));
8512 email += strlen("mailto:");
8513 decode_uri(decoded, email); /* will fit */
8514 gtk_editable_delete_text(entry, 0, -1);
8515 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8516 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8520 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8523 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8526 Compose *compose = (Compose *)data;
8528 if (GTK_CHECK_MENU_ITEM(widget)->active)
8529 compose->return_receipt = TRUE;
8531 compose->return_receipt = FALSE;
8534 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8537 Compose *compose = (Compose *)data;
8539 if (GTK_CHECK_MENU_ITEM(widget)->active)
8540 compose->remove_references = TRUE;
8542 compose->remove_references = FALSE;
8545 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8547 ComposeHeaderEntry *headerentry)
8549 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
8550 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
8551 !(event->state & GDK_MODIFIER_MASK) &&
8552 (event->keyval == GDK_BackSpace) &&
8553 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
8554 gtk_container_remove
8555 (GTK_CONTAINER(headerentry->compose->header_table),
8556 headerentry->combo);
8557 gtk_container_remove
8558 (GTK_CONTAINER(headerentry->compose->header_table),
8559 headerentry->entry);
8560 headerentry->compose->header_list =
8561 g_slist_remove(headerentry->compose->header_list,
8563 g_free(headerentry);
8564 } else if (event->keyval == GDK_Tab) {
8565 if (headerentry->compose->header_last == headerentry) {
8566 /* Override default next focus, and give it to subject_entry
8567 * instead of notebook tabs
8569 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8570 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8577 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8578 ComposeHeaderEntry *headerentry)
8580 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8581 headerentry->compose->header_list =
8582 g_slist_append(headerentry->compose->header_list,
8585 compose_create_header_entry(headerentry->compose);
8586 g_signal_handlers_disconnect_matched
8587 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8588 0, 0, NULL, NULL, headerentry);
8590 /* Automatically scroll down */
8591 compose_show_first_last_header(headerentry->compose, FALSE);
8597 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8599 GtkAdjustment *vadj;
8601 g_return_if_fail(compose);
8602 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8603 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8605 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8606 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8609 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8610 const gchar *text, gint len, Compose *compose)
8612 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8613 (G_OBJECT(compose->text), "paste_as_quotation"));
8616 g_return_if_fail(text != NULL);
8618 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8619 G_CALLBACK(text_inserted),
8621 if (paste_as_quotation) {
8628 new_text = g_strndup(text, len);
8629 if (prefs_common.quotemark && *prefs_common.quotemark)
8630 qmark = prefs_common.quotemark;
8634 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8635 gtk_text_buffer_place_cursor(buffer, iter);
8637 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8639 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8640 GINT_TO_POINTER(paste_as_quotation - 1));
8642 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8643 gtk_text_buffer_place_cursor(buffer, iter);
8645 if (strcmp(text, "\n") || automatic_break
8646 || gtk_text_iter_starts_line(iter))
8647 gtk_text_buffer_insert(buffer, iter, text, len);
8649 debug_print("insert nowrap \\n\n");
8650 gtk_text_buffer_insert_with_tags_by_name(buffer,
8651 iter, text, len, "no_join", NULL);
8655 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8657 compose_beautify_paragraph(compose, iter, FALSE);
8659 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8660 gtk_text_buffer_delete_mark(buffer, mark);
8662 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8663 G_CALLBACK(text_inserted),
8665 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8667 if (prefs_common.autosave &&
8668 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8669 compose->draft_timeout_tag = gtk_timeout_add
8670 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8672 static gint compose_defer_auto_save_draft(Compose *compose)
8674 compose->draft_timeout_tag = -1;
8675 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8680 static void compose_check_all(Compose *compose)
8682 if (compose->gtkaspell)
8683 gtkaspell_check_all(compose->gtkaspell);
8686 static void compose_highlight_all(Compose *compose)
8688 if (compose->gtkaspell)
8689 gtkaspell_highlight_all(compose->gtkaspell);
8692 static void compose_check_backwards(Compose *compose)
8694 if (compose->gtkaspell)
8695 gtkaspell_check_backwards(compose->gtkaspell);
8697 GtkItemFactory *ifactory;
8698 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8699 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8700 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8704 static void compose_check_forwards_go(Compose *compose)
8706 if (compose->gtkaspell)
8707 gtkaspell_check_forwards_go(compose->gtkaspell);
8709 GtkItemFactory *ifactory;
8710 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8711 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8712 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8718 *\brief Guess originating forward account from MsgInfo and several
8719 * "common preference" settings. Return NULL if no guess.
8721 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8723 PrefsAccount *account = NULL;
8725 g_return_val_if_fail(msginfo, NULL);
8726 g_return_val_if_fail(msginfo->folder, NULL);
8727 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8729 if (msginfo->folder->prefs->enable_default_account)
8730 account = account_find_from_id(msginfo->folder->prefs->default_account);
8733 account = msginfo->folder->folder->account;
8735 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8737 Xstrdup_a(to, msginfo->to, return NULL);
8738 extract_address(to);
8739 account = account_find_from_address(to);
8742 if (!account && prefs_common.forward_account_autosel) {
8744 if (!procheader_get_header_from_msginfo
8745 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8746 extract_address(cc);
8747 account = account_find_from_address(cc);
8754 static gboolean compose_close(Compose *compose)
8758 if (!g_mutex_trylock(compose->mutex)) {
8759 /* we have to wait for the (possibly deferred by auto-save)
8760 * drafting to be done, before destroying the compose under
8762 debug_print("waiting for drafting to finish...\n");
8763 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8766 g_return_val_if_fail(compose, FALSE);
8767 gtkut_widget_get_uposition(compose->window, &x, &y);
8768 prefs_common.compose_x = x;
8769 prefs_common.compose_y = y;
8770 g_mutex_unlock(compose->mutex);
8771 compose_destroy(compose);
8776 * Add entry field for each address in list.
8777 * \param compose E-Mail composition object.
8778 * \param listAddress List of (formatted) E-Mail addresses.
8780 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8785 addr = ( gchar * ) node->data;
8786 compose_entry_append( compose, addr, COMPOSE_TO );
8787 node = g_list_next( node );
8791 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8795 GSList *new_msglist = NULL;
8796 MsgInfo *tmp_msginfo = NULL;
8797 gboolean originally_enc = FALSE;
8798 Compose *compose = NULL;
8800 g_return_if_fail(msgview != NULL);
8802 g_return_if_fail(msginfo_list != NULL);
8804 if (g_slist_length(msginfo_list) == 1) {
8805 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8806 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8808 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8809 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8810 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8811 orig_msginfo, mimeinfo);
8812 if (tmp_msginfo != NULL) {
8813 new_msglist = g_slist_append(NULL, tmp_msginfo);
8814 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8815 originally_enc = TRUE;
8821 body = messageview_get_selection(msgview);
8824 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8825 procmsg_msginfo_free(tmp_msginfo);
8826 g_slist_free(new_msglist);
8828 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8830 if (originally_enc) {
8831 compose_force_encryption(compose, compose->account, FALSE);
8837 void compose_set_position(Compose *compose, gint pos)
8839 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8841 gtkut_text_view_set_position(text, pos);
8844 gboolean compose_search_string(Compose *compose,
8845 const gchar *str, gboolean case_sens)
8847 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8849 return gtkut_text_view_search_string(text, str, case_sens);
8852 gboolean compose_search_string_backward(Compose *compose,
8853 const gchar *str, gboolean case_sens)
8855 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8857 return gtkut_text_view_search_string_backward(text, str, case_sens);