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"
123 #include "combobox.h"
135 #define N_ATTACH_COLS (N_COL_COLUMNS)
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
143 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
144 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
145 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
146 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
150 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
151 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
152 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
153 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
154 } ComposeCallAdvancedAction;
158 PRIORITY_HIGHEST = 1,
167 COMPOSE_INSERT_SUCCESS,
168 COMPOSE_INSERT_READ_ERROR,
169 COMPOSE_INSERT_INVALID_CHARACTER,
170 COMPOSE_INSERT_NO_FILE
171 } ComposeInsertResult;
175 COMPOSE_QUIT_EDITING,
176 COMPOSE_KEEP_EDITING,
178 } ComposeDraftAction;
182 COMPOSE_WRITE_FOR_SEND,
183 COMPOSE_WRITE_FOR_STORE
186 #define B64_LINE_SIZE 57
187 #define B64_BUFFSIZE 77
189 #define MAX_REFERENCES_LEN 999
191 static GList *compose_list = NULL;
193 Compose *compose_generic_new (PrefsAccount *account,
196 GPtrArray *attach_files,
197 GList *listAddress );
199 static Compose *compose_create (PrefsAccount *account,
203 static GtkWidget *compose_account_option_menu_create
205 static void compose_set_out_encoding (Compose *compose);
206 static void compose_set_template_menu (Compose *compose);
207 static void compose_template_apply (Compose *compose,
210 static void compose_destroy (Compose *compose);
212 static void compose_entries_set (Compose *compose,
213 const gchar *mailto);
214 static gint compose_parse_header (Compose *compose,
216 static gchar *compose_parse_references (const gchar *ref,
219 static gchar *compose_quote_fmt (Compose *compose,
226 static void compose_reply_set_entry (Compose *compose,
232 followup_and_reply_to);
233 static void compose_reedit_set_entry (Compose *compose,
236 static void compose_insert_sig (Compose *compose,
238 static gchar *compose_get_signature_str (Compose *compose);
239 static ComposeInsertResult compose_insert_file (Compose *compose,
242 static void compose_attach_append (Compose *compose,
245 const gchar *content_type);
246 static void compose_attach_parts (Compose *compose,
249 static void compose_beautify_paragraph (Compose *compose,
250 GtkTextIter *par_iter,
252 static void compose_wrap_all (Compose *compose);
253 static void compose_wrap_all_full (Compose *compose,
256 static void compose_set_title (Compose *compose);
257 static void compose_select_account (Compose *compose,
258 PrefsAccount *account,
261 static PrefsAccount *compose_current_mail_account(void);
262 /* static gint compose_send (Compose *compose); */
263 static gboolean compose_check_for_valid_recipient
265 static gboolean compose_check_entries (Compose *compose,
266 gboolean check_subject);
267 static gint compose_write_to_file (Compose *compose,
270 gboolean attach_parts);
271 static gint compose_write_body_to_file (Compose *compose,
273 static gint compose_remove_reedit_target (Compose *compose,
275 void compose_remove_draft (Compose *compose);
276 static gint compose_queue_sub (Compose *compose,
280 gboolean check_subject,
281 gboolean remove_reedit_target);
282 static void compose_add_attachments (Compose *compose,
284 static gchar *compose_get_header (Compose *compose);
286 static void compose_convert_header (Compose *compose,
291 gboolean addr_field);
293 static void compose_attach_info_free (AttachInfo *ainfo);
294 static void compose_attach_remove_selected (Compose *compose);
296 static void compose_attach_property (Compose *compose);
297 static void compose_attach_property_create (gboolean *cancelled);
298 static void attach_property_ok (GtkWidget *widget,
299 gboolean *cancelled);
300 static void attach_property_cancel (GtkWidget *widget,
301 gboolean *cancelled);
302 static gint attach_property_delete_event (GtkWidget *widget,
304 gboolean *cancelled);
305 static gboolean attach_property_key_pressed (GtkWidget *widget,
307 gboolean *cancelled);
309 static void compose_exec_ext_editor (Compose *compose);
311 static gint compose_exec_ext_editor_real (const gchar *file);
312 static gboolean compose_ext_editor_kill (Compose *compose);
313 static gboolean compose_input_cb (GIOChannel *source,
314 GIOCondition condition,
316 static void compose_set_ext_editor_sensitive (Compose *compose,
318 #endif /* G_OS_UNIX */
320 static void compose_undo_state_changed (UndoMain *undostruct,
325 static void compose_create_header_entry (Compose *compose);
326 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
327 static void compose_update_priority_menu_item(Compose * compose);
329 static void compose_spell_menu_changed (void *data);
331 static void compose_add_field_list ( Compose *compose,
332 GList *listAddress );
334 /* callback functions */
336 static gboolean compose_edit_size_alloc (GtkEditable *widget,
337 GtkAllocation *allocation,
338 GtkSHRuler *shruler);
339 static void account_activated (GtkComboBox *optmenu,
341 static void attach_selected (GtkTreeView *tree_view,
342 GtkTreePath *tree_path,
343 GtkTreeViewColumn *column,
345 static gboolean attach_button_pressed (GtkWidget *widget,
346 GdkEventButton *event,
348 static gboolean attach_key_pressed (GtkWidget *widget,
352 static void compose_send_cb (gpointer data,
355 static void compose_send_later_cb (gpointer data,
359 static void compose_draft_cb (gpointer data,
363 static void compose_attach_cb (gpointer data,
366 static void compose_insert_file_cb (gpointer data,
369 static void compose_insert_sig_cb (gpointer data,
373 static void compose_close_cb (gpointer data,
377 static void compose_set_encoding_cb (gpointer data,
381 static void compose_address_cb (gpointer data,
384 static void compose_template_activate_cb(GtkWidget *widget,
387 static void compose_ext_editor_cb (gpointer data,
391 static gint compose_delete_cb (GtkWidget *widget,
395 static void compose_undo_cb (Compose *compose);
396 static void compose_redo_cb (Compose *compose);
397 static void compose_cut_cb (Compose *compose);
398 static void compose_copy_cb (Compose *compose);
399 static void compose_paste_cb (Compose *compose);
400 static void compose_paste_as_quote_cb (Compose *compose);
401 static void compose_paste_no_wrap_cb (Compose *compose);
402 static void compose_paste_wrap_cb (Compose *compose);
403 static void compose_allsel_cb (Compose *compose);
405 static void compose_advanced_action_cb (Compose *compose,
406 ComposeCallAdvancedAction action);
408 static void compose_grab_focus_cb (GtkWidget *widget,
411 static void compose_changed_cb (GtkTextBuffer *textbuf,
414 static void compose_wrap_cb (gpointer data,
417 static void compose_find_cb (gpointer data,
420 static void compose_toggle_autowrap_cb (gpointer data,
424 static void compose_toggle_ruler_cb (gpointer data,
427 static void compose_toggle_sign_cb (gpointer data,
430 static void compose_toggle_encrypt_cb (gpointer data,
433 static void compose_set_privacy_system_cb(GtkWidget *widget,
435 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
436 static void activate_privacy_system (Compose *compose,
437 PrefsAccount *account,
439 static void compose_use_signing(Compose *compose, gboolean use_signing);
440 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
441 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
443 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
445 static void compose_set_priority_cb (gpointer data,
449 static void compose_attach_drag_received_cb (GtkWidget *widget,
450 GdkDragContext *drag_context,
453 GtkSelectionData *data,
457 static void compose_insert_drag_received_cb (GtkWidget *widget,
458 GdkDragContext *drag_context,
461 GtkSelectionData *data,
465 static void compose_header_drag_received_cb (GtkWidget *widget,
466 GdkDragContext *drag_context,
469 GtkSelectionData *data,
474 static gboolean compose_drag_drop (GtkWidget *widget,
475 GdkDragContext *drag_context,
477 guint time, gpointer user_data);
479 static void text_inserted (GtkTextBuffer *buffer,
484 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
485 gboolean to_all, gboolean to_ml,
487 gboolean followup_and_reply_to,
490 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
491 ComposeHeaderEntry *headerentry);
492 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
494 ComposeHeaderEntry *headerentry);
496 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
498 static void compose_allow_user_actions (Compose *compose, gboolean allow);
501 static void compose_check_all (Compose *compose);
502 static void compose_highlight_all (Compose *compose);
503 static void compose_check_backwards (Compose *compose);
504 static void compose_check_forwards_go (Compose *compose);
507 static gint compose_defer_auto_save_draft (Compose *compose);
508 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
510 static GtkItemFactoryEntry compose_popup_entries[] =
512 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
513 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
514 {N_("/---"), NULL, NULL, 0, "<Separator>"},
515 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
518 static GtkItemFactoryEntry compose_entries[] =
520 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
521 {N_("/_Message/_Send"), "<control>Return",
522 compose_send_cb, 0, NULL},
523 {N_("/_Message/Send _later"), "<shift><control>S",
524 compose_send_later_cb, 0, NULL},
525 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
526 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
527 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
528 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
529 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
530 {N_("/_Message/_Save"),
531 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
532 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
533 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
535 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
536 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
537 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
538 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
539 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
540 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
541 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
542 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
543 {N_("/_Edit/Special paste/as _quotation"),
544 NULL, compose_paste_as_quote_cb, 0, NULL},
545 {N_("/_Edit/Special paste/_wrapped"),
546 NULL, compose_paste_wrap_cb, 0, NULL},
547 {N_("/_Edit/Special paste/_unwrapped"),
548 NULL, compose_paste_no_wrap_cb, 0, NULL},
549 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
550 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
551 {N_("/_Edit/A_dvanced/Move a character backward"),
553 compose_advanced_action_cb,
554 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
556 {N_("/_Edit/A_dvanced/Move a character forward"),
558 compose_advanced_action_cb,
559 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
561 {N_("/_Edit/A_dvanced/Move a word backward"),
563 compose_advanced_action_cb,
564 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
566 {N_("/_Edit/A_dvanced/Move a word forward"),
568 compose_advanced_action_cb,
569 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
571 {N_("/_Edit/A_dvanced/Move to beginning of line"),
572 NULL, /* "<control>A" */
573 compose_advanced_action_cb,
574 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
576 {N_("/_Edit/A_dvanced/Move to end of line"),
578 compose_advanced_action_cb,
579 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
581 {N_("/_Edit/A_dvanced/Move to previous line"),
583 compose_advanced_action_cb,
584 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
586 {N_("/_Edit/A_dvanced/Move to next line"),
588 compose_advanced_action_cb,
589 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
591 {N_("/_Edit/A_dvanced/Delete a character backward"),
593 compose_advanced_action_cb,
594 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
596 {N_("/_Edit/A_dvanced/Delete a character forward"),
598 compose_advanced_action_cb,
599 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
601 {N_("/_Edit/A_dvanced/Delete a word backward"),
602 NULL, /* "<control>W" */
603 compose_advanced_action_cb,
604 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
606 {N_("/_Edit/A_dvanced/Delete a word forward"),
607 NULL, /* "<alt>D", */
608 compose_advanced_action_cb,
609 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
611 {N_("/_Edit/A_dvanced/Delete line"),
613 compose_advanced_action_cb,
614 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
616 {N_("/_Edit/A_dvanced/Delete entire line"),
618 compose_advanced_action_cb,
619 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
621 {N_("/_Edit/A_dvanced/Delete to end of line"),
623 compose_advanced_action_cb,
624 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
626 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
628 "<control>F", compose_find_cb, 0, NULL},
629 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
630 {N_("/_Edit/_Wrap current paragraph"),
631 "<control>L", compose_wrap_cb, 0, NULL},
632 {N_("/_Edit/Wrap all long _lines"),
633 "<control><alt>L", compose_wrap_cb, 1, NULL},
634 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
635 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
636 {N_("/_Edit/Edit with e_xternal editor"),
637 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
639 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
640 {N_("/_Spelling/_Check all or check selection"),
641 NULL, compose_check_all, 0, NULL},
642 {N_("/_Spelling/_Highlight all misspelled words"),
643 NULL, compose_highlight_all, 0, NULL},
644 {N_("/_Spelling/Check _backwards misspelled word"),
645 NULL, compose_check_backwards , 0, NULL},
646 {N_("/_Spelling/_Forward to next misspelled word"),
647 NULL, compose_check_forwards_go, 0, NULL},
648 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
649 {N_("/_Spelling/Options"),
650 NULL, NULL, 0, "<Branch>"},
652 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
653 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
654 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
655 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
656 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
657 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
658 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
659 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
660 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
661 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
662 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
663 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
664 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
665 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
666 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
667 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
668 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
670 #define ENC_ACTION(action) \
671 NULL, compose_set_encoding_cb, action, \
672 "/Options/Character encoding/Automatic"
674 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
675 {N_("/_Options/Character _encoding/_Automatic"),
676 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
677 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
679 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
680 ENC_ACTION(C_US_ASCII)},
681 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
682 ENC_ACTION(C_UTF_8)},
683 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
685 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
686 ENC_ACTION(C_ISO_8859_1)},
687 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
688 ENC_ACTION(C_ISO_8859_15)},
689 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
690 ENC_ACTION(C_WINDOWS_1252)},
691 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
693 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
694 ENC_ACTION(C_ISO_8859_2)},
695 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
697 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
698 ENC_ACTION(C_ISO_8859_13)},
699 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
700 ENC_ACTION(C_ISO_8859_4)},
701 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
703 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
704 ENC_ACTION(C_ISO_8859_7)},
705 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
707 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
708 ENC_ACTION(C_ISO_8859_8)},
709 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
710 ENC_ACTION(C_WINDOWS_1255)},
711 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
713 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
714 ENC_ACTION(C_ISO_8859_6)},
715 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
716 ENC_ACTION(C_CP1256)},
717 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
719 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
720 ENC_ACTION(C_ISO_8859_9)},
721 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
723 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
724 ENC_ACTION(C_ISO_8859_5)},
725 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
726 ENC_ACTION(C_KOI8_R)},
727 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
728 ENC_ACTION(C_KOI8_U)},
729 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
730 ENC_ACTION(C_WINDOWS_1251)},
731 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
733 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
734 ENC_ACTION(C_ISO_2022_JP)},
735 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
737 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
738 ENC_ACTION(C_GB2312)},
739 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
741 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
743 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
744 ENC_ACTION(C_EUC_TW)},
745 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
747 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
748 ENC_ACTION(C_EUC_KR)},
749 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
751 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
752 ENC_ACTION(C_TIS_620)},
753 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
754 ENC_ACTION(C_WINDOWS_874)},
756 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
757 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
758 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
759 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
760 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
761 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
762 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
765 static GtkTargetEntry compose_mime_types[] =
767 {"text/uri-list", 0, 0},
768 {"text/plain", 0, 0},
772 static gboolean compose_put_existing_to_front(MsgInfo *info)
774 GList *compose_list = compose_get_compose_list();
778 for (elem = compose_list; elem != NULL && elem->data != NULL;
780 Compose *c = (Compose*)elem->data;
782 if (!c->targetinfo || !c->targetinfo->msgid ||
786 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
787 gtkut_window_popup(c->window);
795 static GdkColor quote_color1 =
796 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
797 static GdkColor quote_color2 =
798 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
799 static GdkColor quote_color3 =
800 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
802 static GdkColor quote_bgcolor1 =
803 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
804 static GdkColor quote_bgcolor2 =
805 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
806 static GdkColor quote_bgcolor3 =
807 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
809 static GdkColor signature_color = {
816 static GdkColor uri_color = {
823 static void compose_create_tags(GtkTextView *text, Compose *compose)
825 GtkTextBuffer *buffer;
826 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
832 buffer = gtk_text_view_get_buffer(text);
834 if (prefs_common.enable_color) {
835 /* grab the quote colors, converting from an int to a GdkColor */
836 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
838 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
840 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
842 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
844 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
846 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
848 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
850 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
853 signature_color = quote_color1 = quote_color2 = quote_color3 =
854 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black;
857 if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
858 gtk_text_buffer_create_tag(buffer, "quote0",
859 "foreground-gdk", "e_color1,
860 "paragraph-background-gdk", "e_bgcolor1,
862 gtk_text_buffer_create_tag(buffer, "quote1",
863 "foreground-gdk", "e_color2,
864 "paragraph-background-gdk", "e_bgcolor2,
866 gtk_text_buffer_create_tag(buffer, "quote2",
867 "foreground-gdk", "e_color3,
868 "paragraph-background-gdk", "e_bgcolor3,
871 gtk_text_buffer_create_tag(buffer, "quote0",
872 "foreground-gdk", "e_color1,
874 gtk_text_buffer_create_tag(buffer, "quote1",
875 "foreground-gdk", "e_color2,
877 gtk_text_buffer_create_tag(buffer, "quote2",
878 "foreground-gdk", "e_color3,
882 gtk_text_buffer_create_tag(buffer, "signature",
883 "foreground-gdk", &signature_color,
885 gtk_text_buffer_create_tag(buffer, "link",
886 "foreground-gdk", &uri_color,
888 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
889 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
891 color[0] = quote_color1;
892 color[1] = quote_color2;
893 color[2] = quote_color3;
894 color[3] = quote_bgcolor1;
895 color[4] = quote_bgcolor2;
896 color[5] = quote_bgcolor3;
897 color[6] = signature_color;
898 color[7] = uri_color;
899 cmap = gdk_drawable_get_colormap(compose->window->window);
900 gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
902 for (i = 0; i < 8; i++) {
903 if (success[i] == FALSE) {
906 g_warning("Compose: color allocation failed.\n");
907 style = gtk_widget_get_style(GTK_WIDGET(text));
908 quote_color1 = quote_color2 = quote_color3 =
909 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 =
910 signature_color = uri_color = black;
915 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
916 GPtrArray *attach_files)
918 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
921 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
923 return compose_generic_new(account, NULL, item, NULL, NULL);
926 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
928 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
931 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
932 GPtrArray *attach_files, GList *listAddress )
935 GtkTextView *textview;
936 GtkTextBuffer *textbuf;
938 GtkItemFactory *ifactory;
940 if (item && item->prefs && item->prefs->enable_default_account)
941 account = account_find_from_id(item->prefs->default_account);
943 if (!account) account = cur_account;
944 g_return_val_if_fail(account != NULL, NULL);
946 compose = compose_create(account, COMPOSE_NEW, FALSE);
948 ifactory = gtk_item_factory_from_widget(compose->menubar);
950 compose->replyinfo = NULL;
951 compose->fwdinfo = NULL;
953 textview = GTK_TEXT_VIEW(compose->text);
954 textbuf = gtk_text_view_get_buffer(textview);
955 compose_create_tags(textview, compose);
957 undo_block(compose->undostruct);
959 if (item && item->prefs && item->prefs->enable_default_dictionary &&
961 gtkaspell_change_dict(compose->gtkaspell,
962 item->prefs->default_dictionary);
963 compose_spell_menu_changed(compose);
966 if (account->auto_sig)
967 compose_insert_sig(compose, FALSE);
968 gtk_text_buffer_get_start_iter(textbuf, &iter);
969 gtk_text_buffer_place_cursor(textbuf, &iter);
971 if (account->protocol != A_NNTP) {
972 if (mailto && *mailto != '\0') {
973 compose_entries_set(compose, mailto);
975 } else if (item && item->prefs->enable_default_to) {
976 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
977 compose_entry_mark_default_to(compose, item->prefs->default_to);
979 if (item && item->ret_rcpt) {
980 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
984 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
986 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
989 * CLAWS: just don't allow return receipt request, even if the user
990 * may want to send an email. simple but foolproof.
992 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
994 compose_add_field_list( compose, listAddress );
1000 for (i = 0; i < attach_files->len; i++) {
1001 file = g_ptr_array_index(attach_files, i);
1002 compose_attach_append(compose, file, file, NULL);
1006 compose_show_first_last_header(compose, TRUE);
1008 /* Set save folder */
1009 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1010 gchar *folderidentifier;
1012 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1013 folderidentifier = folder_item_get_identifier(item);
1014 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1015 g_free(folderidentifier);
1018 gtk_widget_grab_focus(compose->header_last->entry);
1020 undo_unblock(compose->undostruct);
1022 if (prefs_common.auto_exteditor)
1023 compose_exec_ext_editor(compose);
1025 compose->modified = FALSE;
1026 compose_set_title(compose);
1030 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1031 gboolean override_pref)
1033 gchar *privacy = NULL;
1035 g_return_if_fail(compose != NULL);
1036 g_return_if_fail(account != NULL);
1038 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1041 if (account->default_privacy_system
1042 && strlen(account->default_privacy_system)) {
1043 privacy = account->default_privacy_system;
1045 GSList *privacy_avail = privacy_get_system_ids();
1046 if (privacy_avail && g_slist_length(privacy_avail)) {
1047 privacy = (gchar *)(privacy_avail->data);
1050 if (privacy != NULL) {
1051 compose->privacy_system = g_strdup(privacy);
1052 compose_update_privacy_system_menu_item(compose, FALSE);
1053 compose_use_encryption(compose, TRUE);
1057 static void compose_force_signing(Compose *compose, PrefsAccount *account)
1059 gchar *privacy = NULL;
1061 if (account->default_privacy_system
1062 && strlen(account->default_privacy_system)) {
1063 privacy = account->default_privacy_system;
1065 GSList *privacy_avail = privacy_get_system_ids();
1066 if (privacy_avail && g_slist_length(privacy_avail)) {
1067 privacy = (gchar *)(privacy_avail->data);
1070 if (privacy != NULL) {
1071 compose->privacy_system = g_strdup(privacy);
1072 compose_update_privacy_system_menu_item(compose, FALSE);
1073 compose_use_signing(compose, TRUE);
1077 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1081 Compose *compose = NULL;
1082 g_return_val_if_fail(msginfo_list != NULL, NULL);
1084 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1085 g_return_val_if_fail(msginfo != NULL, NULL);
1087 list_len = g_slist_length(msginfo_list);
1091 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1092 FALSE, prefs_common.default_reply_list, FALSE, body);
1094 case COMPOSE_REPLY_WITH_QUOTE:
1095 compose = compose_reply(msginfo, TRUE,
1096 FALSE, prefs_common.default_reply_list, FALSE, body);
1098 case COMPOSE_REPLY_WITHOUT_QUOTE:
1099 compose = compose_reply(msginfo, FALSE,
1100 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1102 case COMPOSE_REPLY_TO_SENDER:
1103 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1104 FALSE, FALSE, TRUE, body);
1106 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1107 compose = compose_followup_and_reply_to(msginfo,
1108 prefs_common.reply_with_quote,
1109 FALSE, FALSE, body);
1111 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1112 compose = compose_reply(msginfo, TRUE,
1113 FALSE, FALSE, TRUE, body);
1115 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1116 compose = compose_reply(msginfo, FALSE,
1117 FALSE, FALSE, TRUE, NULL);
1119 case COMPOSE_REPLY_TO_ALL:
1120 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1121 TRUE, FALSE, FALSE, body);
1123 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1124 compose = compose_reply(msginfo, TRUE,
1125 TRUE, FALSE, FALSE, body);
1127 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1128 compose = compose_reply(msginfo, FALSE,
1129 TRUE, FALSE, FALSE, NULL);
1131 case COMPOSE_REPLY_TO_LIST:
1132 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1133 FALSE, TRUE, FALSE, body);
1135 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1136 compose = compose_reply(msginfo, TRUE,
1137 FALSE, TRUE, FALSE, body);
1139 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1140 compose = compose_reply(msginfo, FALSE,
1141 FALSE, TRUE, FALSE, NULL);
1143 case COMPOSE_FORWARD:
1144 if (prefs_common.forward_as_attachment) {
1145 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1148 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1152 case COMPOSE_FORWARD_INLINE:
1153 /* check if we reply to more than one Message */
1154 if (list_len == 1) {
1155 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1158 /* more messages FALL THROUGH */
1159 case COMPOSE_FORWARD_AS_ATTACH:
1160 compose = compose_forward_multiple(NULL, msginfo_list);
1162 case COMPOSE_REDIRECT:
1163 compose = compose_redirect(NULL, msginfo, FALSE);
1166 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1171 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1172 gboolean to_ml, gboolean to_sender,
1175 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1176 to_sender, FALSE, body);
1179 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1184 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1185 to_sender, TRUE, body);
1188 static void compose_extract_original_charset(Compose *compose)
1190 MsgInfo *info = NULL;
1191 if (compose->replyinfo) {
1192 info = compose->replyinfo;
1193 } else if (compose->fwdinfo) {
1194 info = compose->fwdinfo;
1195 } else if (compose->targetinfo) {
1196 info = compose->targetinfo;
1199 MimeInfo *mimeinfo = procmime_scan_message(info);
1200 MimeInfo *partinfo = mimeinfo;
1201 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1202 partinfo = procmime_mimeinfo_next(partinfo);
1204 compose->orig_charset =
1205 g_strdup(procmime_mimeinfo_get_parameter(
1206 partinfo, "charset"));
1208 procmime_mimeinfo_free_all(mimeinfo);
1212 #define SIGNAL_BLOCK(buffer) { \
1213 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1214 G_CALLBACK(compose_changed_cb), \
1216 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1217 G_CALLBACK(text_inserted), \
1221 #define SIGNAL_UNBLOCK(buffer) { \
1222 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1223 G_CALLBACK(compose_changed_cb), \
1225 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1226 G_CALLBACK(text_inserted), \
1230 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1231 gboolean to_all, gboolean to_ml,
1233 gboolean followup_and_reply_to,
1236 GtkItemFactory *ifactory;
1238 PrefsAccount *account = NULL;
1239 PrefsAccount *reply_account;
1240 GtkTextView *textview;
1241 GtkTextBuffer *textbuf;
1243 g_return_val_if_fail(msginfo != NULL, NULL);
1244 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1246 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1248 g_return_val_if_fail(account != NULL, NULL);
1250 if (to_sender && account->protocol == A_NNTP &&
1251 !followup_and_reply_to) {
1253 account_find_from_address(account->address);
1255 reply_account = compose_current_mail_account();
1259 reply_account = account;
1261 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1263 compose->updating = TRUE;
1265 ifactory = gtk_item_factory_from_widget(compose->menubar);
1267 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1268 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1270 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1271 if (!compose->replyinfo)
1272 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1274 compose_extract_original_charset(compose);
1276 if (msginfo->folder && msginfo->folder->ret_rcpt)
1277 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1279 /* Set save folder */
1280 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1281 gchar *folderidentifier;
1283 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1284 folderidentifier = folder_item_get_identifier(msginfo->folder);
1285 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1286 g_free(folderidentifier);
1289 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1290 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1291 to_sender, followup_and_reply_to);
1292 compose_show_first_last_header(compose, TRUE);
1294 textview = (GTK_TEXT_VIEW(compose->text));
1295 textbuf = gtk_text_view_get_buffer(textview);
1296 compose_create_tags(textview, compose);
1298 undo_block(compose->undostruct);
1300 if (msginfo->folder && msginfo->folder->prefs &&
1301 msginfo->folder->prefs &&
1302 msginfo->folder->prefs->enable_default_dictionary &&
1304 gtkaspell_change_dict(compose->gtkaspell,
1305 msginfo->folder->prefs->default_dictionary);
1311 if (prefs_common.quotemark && *prefs_common.quotemark)
1312 qmark = prefs_common.quotemark;
1316 compose_quote_fmt(compose, compose->replyinfo,
1317 prefs_common.quotefmt,
1318 qmark, body, FALSE);
1320 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1321 compose_force_encryption(compose, account, FALSE);
1324 SIGNAL_BLOCK(textbuf);
1326 if (account->auto_sig)
1327 compose_insert_sig(compose, FALSE);
1329 compose_wrap_all(compose);
1331 SIGNAL_UNBLOCK(textbuf);
1333 gtk_widget_grab_focus(compose->text);
1335 undo_unblock(compose->undostruct);
1337 if (prefs_common.auto_exteditor)
1338 compose_exec_ext_editor(compose);
1340 compose->modified = FALSE;
1341 compose_set_title(compose);
1343 compose->updating = FALSE;
1345 if (compose->deferred_destroy) {
1346 compose_destroy(compose);
1353 #define INSERT_FW_HEADER(var, hdr) \
1354 if (msginfo->var && *msginfo->var) { \
1355 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1356 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1357 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1360 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1361 gboolean as_attach, const gchar *body,
1362 gboolean no_extedit,
1366 GtkTextView *textview;
1367 GtkTextBuffer *textbuf;
1370 g_return_val_if_fail(msginfo != NULL, NULL);
1371 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1374 !(account = compose_guess_forward_account_from_msginfo
1376 account = cur_account;
1378 compose = compose_create(account, COMPOSE_FORWARD, batch);
1380 compose->updating = TRUE;
1381 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1382 if (!compose->fwdinfo)
1383 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1385 compose_extract_original_charset(compose);
1387 if (msginfo->subject && *msginfo->subject) {
1388 gchar *buf, *buf2, *p;
1390 buf = p = g_strdup(msginfo->subject);
1391 p += subject_get_prefix_length(p);
1392 memmove(buf, p, strlen(p) + 1);
1394 buf2 = g_strdup_printf("Fw: %s", buf);
1395 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1401 textview = GTK_TEXT_VIEW(compose->text);
1402 textbuf = gtk_text_view_get_buffer(textview);
1403 compose_create_tags(textview, compose);
1405 undo_block(compose->undostruct);
1409 msgfile = procmsg_get_message_file_path(msginfo);
1410 if (!is_file_exist(msgfile))
1411 g_warning("%s: file not exist\n", msgfile);
1413 compose_attach_append(compose, msgfile, msgfile,
1419 MsgInfo *full_msginfo;
1421 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1423 full_msginfo = procmsg_msginfo_copy(msginfo);
1425 if (prefs_common.fw_quotemark &&
1426 *prefs_common.fw_quotemark)
1427 qmark = prefs_common.fw_quotemark;
1431 compose_quote_fmt(compose, full_msginfo,
1432 prefs_common.fw_quotefmt,
1433 qmark, body, FALSE);
1434 compose_attach_parts(compose, msginfo);
1436 procmsg_msginfo_free(full_msginfo);
1439 SIGNAL_BLOCK(textbuf);
1441 if (account->auto_sig)
1442 compose_insert_sig(compose, FALSE);
1444 compose_wrap_all(compose);
1446 SIGNAL_UNBLOCK(textbuf);
1448 gtk_text_buffer_get_start_iter(textbuf, &iter);
1449 gtk_text_buffer_place_cursor(textbuf, &iter);
1451 gtk_widget_grab_focus(compose->header_last->entry);
1453 if (!no_extedit && prefs_common.auto_exteditor)
1454 compose_exec_ext_editor(compose);
1457 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1458 gchar *folderidentifier;
1460 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1461 folderidentifier = folder_item_get_identifier(msginfo->folder);
1462 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1463 g_free(folderidentifier);
1466 undo_unblock(compose->undostruct);
1468 compose->modified = FALSE;
1469 compose_set_title(compose);
1471 compose->updating = FALSE;
1473 if (compose->deferred_destroy) {
1474 compose_destroy(compose);
1481 #undef INSERT_FW_HEADER
1483 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1486 GtkTextView *textview;
1487 GtkTextBuffer *textbuf;
1491 gboolean single_mail = TRUE;
1493 g_return_val_if_fail(msginfo_list != NULL, NULL);
1495 if (g_slist_length(msginfo_list) > 1)
1496 single_mail = FALSE;
1498 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1499 if (((MsgInfo *)msginfo->data)->folder == NULL)
1502 /* guess account from first selected message */
1504 !(account = compose_guess_forward_account_from_msginfo
1505 (msginfo_list->data)))
1506 account = cur_account;
1508 g_return_val_if_fail(account != NULL, NULL);
1510 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1511 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1512 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1515 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1517 compose->updating = TRUE;
1519 textview = GTK_TEXT_VIEW(compose->text);
1520 textbuf = gtk_text_view_get_buffer(textview);
1521 compose_create_tags(textview, compose);
1523 undo_block(compose->undostruct);
1524 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1525 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1527 if (!is_file_exist(msgfile))
1528 g_warning("%s: file not exist\n", msgfile);
1530 compose_attach_append(compose, msgfile, msgfile,
1536 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1537 if (info->subject && *info->subject) {
1538 gchar *buf, *buf2, *p;
1540 buf = p = g_strdup(info->subject);
1541 p += subject_get_prefix_length(p);
1542 memmove(buf, p, strlen(p) + 1);
1544 buf2 = g_strdup_printf("Fw: %s", buf);
1545 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1551 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1552 _("Fw: multiple emails"));
1555 SIGNAL_BLOCK(textbuf);
1557 if (account->auto_sig)
1558 compose_insert_sig(compose, FALSE);
1560 compose_wrap_all(compose);
1562 SIGNAL_UNBLOCK(textbuf);
1564 gtk_text_buffer_get_start_iter(textbuf, &iter);
1565 gtk_text_buffer_place_cursor(textbuf, &iter);
1567 gtk_widget_grab_focus(compose->header_last->entry);
1568 undo_unblock(compose->undostruct);
1569 compose->modified = FALSE;
1570 compose_set_title(compose);
1572 compose->updating = FALSE;
1574 if (compose->deferred_destroy) {
1575 compose_destroy(compose);
1582 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1584 GtkTextIter start = *iter;
1585 GtkTextIter end_iter;
1586 int start_pos = gtk_text_iter_get_offset(&start);
1588 if (!compose->account->sig_sep)
1591 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1592 start_pos+strlen(compose->account->sig_sep));
1594 /* check sig separator */
1595 str = gtk_text_iter_get_text(&start, &end_iter);
1596 if (!strcmp(str, compose->account->sig_sep)) {
1598 /* check end of line (\n) */
1599 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1600 start_pos+strlen(compose->account->sig_sep));
1601 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1602 start_pos+strlen(compose->account->sig_sep)+1);
1603 tmp = gtk_text_iter_get_text(&start, &end_iter);
1604 if (!strcmp(tmp,"\n")) {
1616 static void compose_colorize_signature(Compose *compose)
1618 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1620 GtkTextIter end_iter;
1621 gtk_text_buffer_get_start_iter(buffer, &iter);
1622 while (gtk_text_iter_forward_line(&iter))
1623 if (compose_is_sig_separator(compose, buffer, &iter)) {
1624 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1625 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1629 Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
1631 Compose *compose = NULL;
1632 PrefsAccount *account = NULL;
1633 GtkTextView *textview;
1634 GtkTextBuffer *textbuf;
1638 gchar buf[BUFFSIZE];
1639 gboolean use_signing = FALSE;
1640 gboolean use_encryption = FALSE;
1641 gchar *privacy_system = NULL;
1643 g_return_val_if_fail(msginfo != NULL, NULL);
1644 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1646 if (compose_put_existing_to_front(msginfo)) {
1650 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1651 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1652 gchar queueheader_buf[BUFFSIZE];
1655 /* Select Account from queue headers */
1656 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1657 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1658 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1659 account = account_find_from_id(id);
1661 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1662 sizeof(queueheader_buf), "NAID:")) {
1663 id = atoi(&queueheader_buf[strlen("NAID:")]);
1664 account = account_find_from_id(id);
1666 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1667 sizeof(queueheader_buf), "MAID:")) {
1668 id = atoi(&queueheader_buf[strlen("MAID:")]);
1669 account = account_find_from_id(id);
1671 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1672 sizeof(queueheader_buf), "S:")) {
1673 account = account_find_from_address(queueheader_buf);
1675 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1676 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1677 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1678 use_signing = param;
1681 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1682 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1683 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1684 use_encryption = param;
1686 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1687 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1688 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1690 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1691 sizeof(queueheader_buf), "X-Priority: ")) {
1692 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1693 compose->priority = param;
1696 account = msginfo->folder->folder->account;
1699 if (!account && prefs_common.reedit_account_autosel) {
1700 gchar from[BUFFSIZE];
1701 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1702 extract_address(from);
1703 account = account_find_from_address(from);
1707 account = cur_account;
1709 g_return_val_if_fail(account != NULL, NULL);
1711 compose = compose_create(account, COMPOSE_REEDIT, batch);
1713 compose->updating = TRUE;
1715 if (privacy_system != NULL) {
1716 compose->privacy_system = privacy_system;
1717 compose_use_signing(compose, use_signing);
1718 compose_use_encryption(compose, use_encryption);
1719 compose_update_privacy_system_menu_item(compose, FALSE);
1721 activate_privacy_system(compose, account, FALSE);
1724 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1726 compose_extract_original_charset(compose);
1728 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1729 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1730 gchar queueheader_buf[BUFFSIZE];
1732 /* Set message save folder */
1733 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1736 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1737 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1738 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1740 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1741 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1743 GtkItemFactory *ifactory;
1744 ifactory = gtk_item_factory_from_widget(compose->menubar);
1745 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1750 if (compose_parse_header(compose, msginfo) < 0) {
1751 compose->updating = FALSE;
1752 compose_destroy(compose);
1755 compose_reedit_set_entry(compose, msginfo);
1757 textview = GTK_TEXT_VIEW(compose->text);
1758 textbuf = gtk_text_view_get_buffer(textview);
1759 compose_create_tags(textview, compose);
1761 mark = gtk_text_buffer_get_insert(textbuf);
1762 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1764 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1765 G_CALLBACK(compose_changed_cb),
1768 if (procmime_msginfo_is_encrypted(msginfo)) {
1769 fp = procmime_get_first_encrypted_text_content(msginfo);
1771 compose_force_encryption(compose, account, TRUE);
1774 fp = procmime_get_first_text_content(msginfo);
1777 g_warning("Can't get text part\n");
1781 gboolean prev_autowrap = compose->autowrap;
1783 compose->autowrap = FALSE;
1784 while (fgets(buf, sizeof(buf), fp) != NULL) {
1786 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1788 compose_wrap_all_full(compose, FALSE);
1789 compose->autowrap = prev_autowrap;
1793 compose_attach_parts(compose, msginfo);
1795 compose_colorize_signature(compose);
1797 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1798 G_CALLBACK(compose_changed_cb),
1801 gtk_widget_grab_focus(compose->text);
1803 if (prefs_common.auto_exteditor) {
1804 compose_exec_ext_editor(compose);
1806 compose->modified = FALSE;
1807 compose_set_title(compose);
1809 compose->updating = FALSE;
1811 if (compose->deferred_destroy) {
1812 compose_destroy(compose);
1816 compose->sig_str = compose_get_signature_str(compose);
1821 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
1826 GtkItemFactory *ifactory;
1829 g_return_val_if_fail(msginfo != NULL, NULL);
1832 account = account_get_reply_account(msginfo,
1833 prefs_common.reply_account_autosel);
1834 g_return_val_if_fail(account != NULL, NULL);
1836 compose = compose_create(account, COMPOSE_REDIRECT, batch);
1838 compose->updating = TRUE;
1840 ifactory = gtk_item_factory_from_widget(compose->menubar);
1841 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1842 compose->replyinfo = NULL;
1843 compose->fwdinfo = NULL;
1845 compose_show_first_last_header(compose, TRUE);
1847 gtk_widget_grab_focus(compose->header_last->entry);
1849 filename = procmsg_get_message_file_path(msginfo);
1851 if (filename == NULL) {
1852 compose->updating = FALSE;
1853 compose_destroy(compose);
1858 compose->redirect_filename = filename;
1860 /* Set save folder */
1861 item = msginfo->folder;
1862 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1863 gchar *folderidentifier;
1865 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1866 folderidentifier = folder_item_get_identifier(item);
1867 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1868 g_free(folderidentifier);
1871 compose_attach_parts(compose, msginfo);
1873 if (msginfo->subject)
1874 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1876 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1878 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1879 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1881 compose_colorize_signature(compose);
1883 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1884 menu_set_sensitive(ifactory, "/Add...", FALSE);
1885 menu_set_sensitive(ifactory, "/Remove", FALSE);
1886 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1888 ifactory = gtk_item_factory_from_widget(compose->menubar);
1889 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1890 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1891 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1892 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1893 menu_set_sensitive(ifactory, "/Edit", FALSE);
1894 menu_set_sensitive(ifactory, "/Options", FALSE);
1895 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1896 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1898 if (compose->toolbar->draft_btn)
1899 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1900 if (compose->toolbar->insert_btn)
1901 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1902 if (compose->toolbar->attach_btn)
1903 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1904 if (compose->toolbar->sig_btn)
1905 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1906 if (compose->toolbar->exteditor_btn)
1907 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1908 if (compose->toolbar->linewrap_current_btn)
1909 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1910 if (compose->toolbar->linewrap_all_btn)
1911 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1913 compose->modified = FALSE;
1914 compose_set_title(compose);
1915 compose->updating = FALSE;
1917 if (compose->deferred_destroy) {
1918 compose_destroy(compose);
1925 GList *compose_get_compose_list(void)
1927 return compose_list;
1930 void compose_entry_append(Compose *compose, const gchar *address,
1931 ComposeEntryType type)
1935 gboolean in_quote = FALSE;
1936 if (!address || *address == '\0') return;
1943 header = N_("Bcc:");
1945 case COMPOSE_REPLYTO:
1946 header = N_("Reply-To:");
1948 case COMPOSE_NEWSGROUPS:
1949 header = N_("Newsgroups:");
1951 case COMPOSE_FOLLOWUPTO:
1952 header = N_( "Followup-To:");
1959 header = prefs_common.trans_hdr ? gettext(header) : header;
1961 cur = begin = (gchar *)address;
1963 /* we separate the line by commas, but not if we're inside a quoted
1965 while (*cur != '\0') {
1967 in_quote = !in_quote;
1968 if (*cur == ',' && !in_quote) {
1969 gchar *tmp = g_strdup(begin);
1971 tmp[cur-begin]='\0';
1974 while (*tmp == ' ' || *tmp == '\t')
1976 compose_add_header_entry(compose, header, tmp);
1983 gchar *tmp = g_strdup(begin);
1985 tmp[cur-begin]='\0';
1988 while (*tmp == ' ' || *tmp == '\t')
1990 compose_add_header_entry(compose, header, tmp);
1995 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1997 static GdkColor yellow;
1998 static GdkColor black;
1999 static gboolean yellow_initialised = FALSE;
2003 if (!yellow_initialised) {
2004 gdk_color_parse("#f5f6be", &yellow);
2005 gdk_color_parse("#000000", &black);
2006 yellow_initialised = gdk_colormap_alloc_color(
2007 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
2008 yellow_initialised &= gdk_colormap_alloc_color(
2009 gdk_colormap_get_system(), &black, FALSE, TRUE);
2012 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
2013 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
2014 if (gtk_entry_get_text(entry) &&
2015 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
2016 if (yellow_initialised) {
2017 gtk_widget_modify_base(
2018 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2019 GTK_STATE_NORMAL, &yellow);
2020 gtk_widget_modify_text(
2021 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2022 GTK_STATE_NORMAL, &black);
2028 void compose_toolbar_cb(gint action, gpointer data)
2030 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2031 Compose *compose = (Compose*)toolbar_item->parent;
2033 g_return_if_fail(compose != NULL);
2037 compose_send_cb(compose, 0, NULL);
2040 compose_send_later_cb(compose, 0, NULL);
2043 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2046 compose_insert_file_cb(compose, 0, NULL);
2049 compose_attach_cb(compose, 0, NULL);
2052 compose_insert_sig(compose, FALSE);
2055 compose_ext_editor_cb(compose, 0, NULL);
2057 case A_LINEWRAP_CURRENT:
2058 compose_beautify_paragraph(compose, NULL, TRUE);
2060 case A_LINEWRAP_ALL:
2061 compose_wrap_all_full(compose, TRUE);
2064 compose_address_cb(compose, 0, NULL);
2067 case A_CHECK_SPELLING:
2068 compose_check_all(compose);
2076 static void compose_entries_set(Compose *compose, const gchar *mailto)
2080 gchar *subject = NULL;
2085 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
2088 compose_entry_append(compose, to, COMPOSE_TO);
2090 compose_entry_append(compose, cc, COMPOSE_CC);
2092 if (!g_utf8_validate (subject, -1, NULL)) {
2093 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2094 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2097 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2101 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2102 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2105 gboolean prev_autowrap = compose->autowrap;
2107 compose->autowrap = FALSE;
2109 mark = gtk_text_buffer_get_insert(buffer);
2110 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2112 if (!g_utf8_validate (body, -1, NULL)) {
2113 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2114 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2117 gtk_text_buffer_insert(buffer, &iter, body, -1);
2119 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2121 compose->autowrap = prev_autowrap;
2122 if (compose->autowrap)
2123 compose_wrap_all(compose);
2132 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2134 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2135 {"Cc:", NULL, TRUE},
2136 {"References:", NULL, FALSE},
2137 {"Bcc:", NULL, TRUE},
2138 {"Newsgroups:", NULL, TRUE},
2139 {"Followup-To:", NULL, TRUE},
2140 {"List-Post:", NULL, FALSE},
2141 {"X-Priority:", NULL, FALSE},
2142 {NULL, NULL, FALSE}};
2158 g_return_val_if_fail(msginfo != NULL, -1);
2160 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2161 procheader_get_header_fields(fp, hentry);
2164 if (hentry[H_REPLY_TO].body != NULL) {
2165 if (hentry[H_REPLY_TO].body[0] != '\0') {
2167 conv_unmime_header(hentry[H_REPLY_TO].body,
2170 g_free(hentry[H_REPLY_TO].body);
2171 hentry[H_REPLY_TO].body = NULL;
2173 if (hentry[H_CC].body != NULL) {
2174 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2175 g_free(hentry[H_CC].body);
2176 hentry[H_CC].body = NULL;
2178 if (hentry[H_REFERENCES].body != NULL) {
2179 if (compose->mode == COMPOSE_REEDIT)
2180 compose->references = hentry[H_REFERENCES].body;
2182 compose->references = compose_parse_references
2183 (hentry[H_REFERENCES].body, msginfo->msgid);
2184 g_free(hentry[H_REFERENCES].body);
2186 hentry[H_REFERENCES].body = NULL;
2188 if (hentry[H_BCC].body != NULL) {
2189 if (compose->mode == COMPOSE_REEDIT)
2191 conv_unmime_header(hentry[H_BCC].body, NULL);
2192 g_free(hentry[H_BCC].body);
2193 hentry[H_BCC].body = NULL;
2195 if (hentry[H_NEWSGROUPS].body != NULL) {
2196 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2197 hentry[H_NEWSGROUPS].body = NULL;
2199 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2200 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2201 compose->followup_to =
2202 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2205 g_free(hentry[H_FOLLOWUP_TO].body);
2206 hentry[H_FOLLOWUP_TO].body = NULL;
2208 if (hentry[H_LIST_POST].body != NULL) {
2211 extract_address(hentry[H_LIST_POST].body);
2212 if (hentry[H_LIST_POST].body[0] != '\0') {
2213 scan_mailto_url(hentry[H_LIST_POST].body,
2214 &to, NULL, NULL, NULL, NULL);
2216 g_free(compose->ml_post);
2217 compose->ml_post = to;
2220 g_free(hentry[H_LIST_POST].body);
2221 hentry[H_LIST_POST].body = NULL;
2224 /* CLAWS - X-Priority */
2225 if (compose->mode == COMPOSE_REEDIT)
2226 if (hentry[H_X_PRIORITY].body != NULL) {
2229 priority = atoi(hentry[H_X_PRIORITY].body);
2230 g_free(hentry[H_X_PRIORITY].body);
2232 hentry[H_X_PRIORITY].body = NULL;
2234 if (priority < PRIORITY_HIGHEST ||
2235 priority > PRIORITY_LOWEST)
2236 priority = PRIORITY_NORMAL;
2238 compose->priority = priority;
2241 if (compose->mode == COMPOSE_REEDIT) {
2242 if (msginfo->inreplyto && *msginfo->inreplyto)
2243 compose->inreplyto = g_strdup(msginfo->inreplyto);
2247 if (msginfo->msgid && *msginfo->msgid)
2248 compose->inreplyto = g_strdup(msginfo->msgid);
2250 if (!compose->references) {
2251 if (msginfo->msgid && *msginfo->msgid) {
2252 if (msginfo->inreplyto && *msginfo->inreplyto)
2253 compose->references =
2254 g_strdup_printf("<%s>\n\t<%s>",
2258 compose->references =
2259 g_strconcat("<", msginfo->msgid, ">",
2261 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2262 compose->references =
2263 g_strconcat("<", msginfo->inreplyto, ">",
2271 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2273 GSList *ref_id_list, *cur;
2277 ref_id_list = references_list_append(NULL, ref);
2278 if (!ref_id_list) return NULL;
2279 if (msgid && *msgid)
2280 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2285 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2286 /* "<" + Message-ID + ">" + CR+LF+TAB */
2287 len += strlen((gchar *)cur->data) + 5;
2289 if (len > MAX_REFERENCES_LEN) {
2290 /* remove second message-ID */
2291 if (ref_id_list && ref_id_list->next &&
2292 ref_id_list->next->next) {
2293 g_free(ref_id_list->next->data);
2294 ref_id_list = g_slist_remove
2295 (ref_id_list, ref_id_list->next->data);
2297 slist_free_strings(ref_id_list);
2298 g_slist_free(ref_id_list);
2305 new_ref = g_string_new("");
2306 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2307 if (new_ref->len > 0)
2308 g_string_append(new_ref, "\n\t");
2309 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2312 slist_free_strings(ref_id_list);
2313 g_slist_free(ref_id_list);
2315 new_ref_str = new_ref->str;
2316 g_string_free(new_ref, FALSE);
2321 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2322 const gchar *fmt, const gchar *qmark,
2323 const gchar *body, gboolean rewrap)
2325 static MsgInfo dummyinfo;
2326 gchar *quote_str = NULL;
2328 gboolean prev_autowrap;
2329 const gchar *trimmed_body = body;
2330 gint cursor_pos = -1;
2331 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2332 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2337 SIGNAL_BLOCK(buffer);
2340 msginfo = &dummyinfo;
2342 if (qmark != NULL) {
2343 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2344 quote_fmt_scan_string(qmark);
2347 buf = quote_fmt_get_buffer();
2349 alertpanel_error(_("Quote mark format error."));
2351 Xstrdup_a(quote_str, buf, goto error)
2354 if (fmt && *fmt != '\0') {
2355 while (trimmed_body && strlen(trimmed_body) > 1
2356 && trimmed_body[0]=='\n')
2359 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2360 quote_fmt_scan_string(fmt);
2363 buf = quote_fmt_get_buffer();
2365 alertpanel_error(_("Message reply/forward format error."));
2371 prev_autowrap = compose->autowrap;
2372 compose->autowrap = FALSE;
2374 mark = gtk_text_buffer_get_insert(buffer);
2375 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2376 if (g_utf8_validate(buf, -1, NULL)) {
2377 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2379 gchar *tmpout = NULL;
2380 tmpout = conv_codeset_strdup
2381 (buf, conv_get_locale_charset_str_no_utf8(),
2383 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2385 tmpout = g_malloc(strlen(buf)*2+1);
2386 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2388 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2392 cursor_pos = quote_fmt_get_cursor_pos();
2393 compose->set_cursor_pos = cursor_pos;
2394 if (cursor_pos == -1) {
2397 gtk_text_buffer_get_start_iter(buffer, &iter);
2398 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2399 gtk_text_buffer_place_cursor(buffer, &iter);
2401 compose->autowrap = prev_autowrap;
2402 if (compose->autowrap && rewrap)
2403 compose_wrap_all(compose);
2410 SIGNAL_UNBLOCK(buffer);
2416 /* if ml_post is of type addr@host and from is of type
2417 * addr-anything@host, return TRUE
2419 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2421 gchar *left_ml = NULL;
2422 gchar *right_ml = NULL;
2423 gchar *left_from = NULL;
2424 gchar *right_from = NULL;
2425 gboolean result = FALSE;
2427 if (!ml_post || !from)
2430 left_ml = g_strdup(ml_post);
2431 if (strstr(left_ml, "@")) {
2432 right_ml = strstr(left_ml, "@")+1;
2433 *(strstr(left_ml, "@")) = '\0';
2436 left_from = g_strdup(from);
2437 if (strstr(left_from, "@")) {
2438 right_from = strstr(left_from, "@")+1;
2439 *(strstr(left_from, "@")) = '\0';
2442 if (left_ml && left_from && right_ml && right_from
2443 && !strncmp(left_from, left_ml, strlen(left_ml))
2444 && !strcmp(right_from, right_ml)) {
2453 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2455 gchar *my_addr1, *my_addr2;
2457 if (!addr1 || !addr2)
2460 Xstrdup_a(my_addr1, addr1, return FALSE);
2461 Xstrdup_a(my_addr2, addr2, return FALSE);
2463 extract_address(my_addr1);
2464 extract_address(my_addr2);
2466 return !strcmp(my_addr1, my_addr2);
2469 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2470 gboolean to_all, gboolean to_ml,
2472 gboolean followup_and_reply_to)
2474 GSList *cc_list = NULL;
2477 gchar *replyto = NULL;
2478 GHashTable *to_table;
2480 gboolean reply_to_ml = FALSE;
2481 gboolean default_reply_to = FALSE;
2483 g_return_if_fail(compose->account != NULL);
2484 g_return_if_fail(msginfo != NULL);
2486 reply_to_ml = to_ml && compose->ml_post;
2488 default_reply_to = msginfo->folder &&
2489 msginfo->folder->prefs->enable_default_reply_to;
2491 if (compose->account->protocol != A_NNTP) {
2492 if (reply_to_ml && !default_reply_to) {
2494 gboolean is_subscr = is_subscription(compose->ml_post,
2497 /* normal answer to ml post with a reply-to */
2498 compose_entry_append(compose,
2501 if (compose->replyto
2502 && !same_address(compose->ml_post, compose->replyto))
2503 compose_entry_append(compose,
2507 /* answer to subscription confirmation */
2508 if (compose->replyto)
2509 compose_entry_append(compose,
2512 else if (msginfo->from)
2513 compose_entry_append(compose,
2518 else if (!(to_all || to_sender) && default_reply_to) {
2519 compose_entry_append(compose,
2520 msginfo->folder->prefs->default_reply_to,
2522 compose_entry_mark_default_to(compose,
2523 msginfo->folder->prefs->default_reply_to);
2528 Xstrdup_a(tmp1, msginfo->from, return);
2529 extract_address(tmp1);
2530 if (to_all || to_sender ||
2531 !account_find_from_address(tmp1))
2532 compose_entry_append(compose,
2533 (compose->replyto && !to_sender)
2534 ? compose->replyto :
2535 msginfo->from ? msginfo->from : "",
2537 else if (!to_all && !to_sender) {
2538 /* reply to the last list of recipients */
2539 compose_entry_append(compose,
2540 msginfo->to ? msginfo->to : "",
2542 compose_entry_append(compose,
2543 msginfo->cc ? msginfo->cc : "",
2548 if (to_sender || (compose->followup_to &&
2549 !strncmp(compose->followup_to, "poster", 6)))
2550 compose_entry_append
2552 (compose->replyto ? compose->replyto :
2553 msginfo->from ? msginfo->from : ""),
2556 else if (followup_and_reply_to || to_all) {
2557 compose_entry_append
2559 (compose->replyto ? compose->replyto :
2560 msginfo->from ? msginfo->from : ""),
2563 compose_entry_append
2565 compose->followup_to ? compose->followup_to :
2566 compose->newsgroups ? compose->newsgroups : "",
2567 COMPOSE_NEWSGROUPS);
2570 compose_entry_append
2572 compose->followup_to ? compose->followup_to :
2573 compose->newsgroups ? compose->newsgroups : "",
2574 COMPOSE_NEWSGROUPS);
2577 if (msginfo->subject && *msginfo->subject) {
2581 buf = p = g_strdup(msginfo->subject);
2582 p += subject_get_prefix_length(p);
2583 memmove(buf, p, strlen(p) + 1);
2585 buf2 = g_strdup_printf("Re: %s", buf);
2586 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2591 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2593 if (to_ml && compose->ml_post) return;
2594 if (!to_all || compose->account->protocol == A_NNTP) return;
2596 if (compose->replyto) {
2597 Xstrdup_a(replyto, compose->replyto, return);
2598 extract_address(replyto);
2600 if (msginfo->from) {
2601 Xstrdup_a(from, msginfo->from, return);
2602 extract_address(from);
2605 if (replyto && from)
2606 cc_list = address_list_append_with_comments(cc_list, from);
2607 if (to_all && msginfo->folder &&
2608 msginfo->folder->prefs->enable_default_reply_to)
2609 cc_list = address_list_append_with_comments(cc_list,
2610 msginfo->folder->prefs->default_reply_to);
2611 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2612 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2614 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2616 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2617 if (compose->account)
2618 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2619 GINT_TO_POINTER(1));
2621 /* remove address on To: and that of current account */
2622 for (cur = cc_list; cur != NULL; ) {
2623 GSList *next = cur->next;
2626 addr = g_strdup(cur->data);
2627 extract_address(addr);
2629 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2630 cc_list = g_slist_remove(cc_list, cur->data);
2632 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2636 hash_free_strings(to_table);
2637 g_hash_table_destroy(to_table);
2640 for (cur = cc_list; cur != NULL; cur = cur->next)
2641 compose_entry_append(compose, (gchar *)cur->data,
2643 slist_free_strings(cc_list);
2644 g_slist_free(cc_list);
2649 #define SET_ENTRY(entry, str) \
2652 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2655 #define SET_ADDRESS(type, str) \
2658 compose_entry_append(compose, str, type); \
2661 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2663 g_return_if_fail(msginfo != NULL);
2665 SET_ENTRY(subject_entry, msginfo->subject);
2666 SET_ENTRY(from_name, msginfo->from);
2667 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2668 SET_ADDRESS(COMPOSE_CC, compose->cc);
2669 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2670 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2671 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2672 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2674 compose_update_priority_menu_item(compose);
2675 compose_update_privacy_system_menu_item(compose, FALSE);
2676 compose_show_first_last_header(compose, TRUE);
2682 static void compose_insert_sig(Compose *compose, gboolean replace)
2684 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2685 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2687 GtkTextIter iter, iter_end;
2689 gchar *search = NULL;
2690 gboolean prev_autowrap;
2691 gboolean found = FALSE, shift = FALSE;
2694 g_return_if_fail(compose->account != NULL);
2696 prev_autowrap = compose->autowrap;
2697 compose->autowrap = FALSE;
2699 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2700 G_CALLBACK(compose_changed_cb),
2703 mark = gtk_text_buffer_get_insert(buffer);
2704 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2705 cur_pos = gtk_text_iter_get_offset (&iter);
2707 gtk_text_buffer_get_end_iter(buffer, &iter);
2709 search = compose->sig_str;
2711 if (replace && search) {
2712 GtkTextIter first_iter, start_iter, end_iter;
2714 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2716 if (compose->sig_str[0] == '\0')
2719 found = gtk_text_iter_forward_search(&first_iter,
2721 GTK_TEXT_SEARCH_TEXT_ONLY,
2722 &start_iter, &end_iter,
2726 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2730 if (replace && !found && search && strlen(search) > 2
2731 && search[0] == '\n' && search[1] == '\n') {
2737 g_free(compose->sig_str);
2738 compose->sig_str = compose_get_signature_str(compose);
2739 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2740 compose->sig_str = g_strdup("");
2742 cur_pos = gtk_text_iter_get_offset(&iter);
2744 gtk_text_buffer_insert(buffer, &iter, compose->sig_str + 1, -1);
2746 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2748 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2749 gtk_text_iter_forward_char(&iter);
2750 gtk_text_iter_forward_char(&iter);
2751 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2752 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2754 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2755 cur_pos = gtk_text_buffer_get_char_count (buffer);
2757 /* put the cursor where it should be
2758 * either where the quote_fmt says, either before the signature */
2759 if (compose->set_cursor_pos < 0)
2760 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2762 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2763 compose->set_cursor_pos);
2765 gtk_text_buffer_place_cursor(buffer, &iter);
2766 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2767 G_CALLBACK(compose_changed_cb),
2770 compose->autowrap = prev_autowrap;
2771 if (compose->autowrap)
2772 compose_wrap_all(compose);
2775 static gchar *compose_get_signature_str(Compose *compose)
2777 gchar *sig_body = NULL;
2778 gchar *sig_str = NULL;
2779 gchar *utf8_sig_str = NULL;
2781 g_return_val_if_fail(compose->account != NULL, NULL);
2783 if (!compose->account->sig_path)
2786 if (compose->account->sig_type == SIG_FILE) {
2787 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2788 g_warning("can't open signature file: %s\n",
2789 compose->account->sig_path);
2794 if (compose->account->sig_type == SIG_COMMAND)
2795 sig_body = get_command_output(compose->account->sig_path);
2799 tmp = file_read_to_str(compose->account->sig_path);
2802 sig_body = normalize_newlines(tmp);
2806 if (compose->account->sig_sep) {
2807 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2811 sig_str = g_strconcat("\n\n", sig_body, NULL);
2814 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2815 utf8_sig_str = sig_str;
2817 utf8_sig_str = conv_codeset_strdup
2818 (sig_str, conv_get_locale_charset_str_no_utf8(),
2824 return utf8_sig_str;
2827 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2830 GtkTextBuffer *buffer;
2833 const gchar *cur_encoding;
2834 gchar buf[BUFFSIZE];
2837 gboolean prev_autowrap;
2838 gboolean badtxt = FALSE;
2840 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2842 if ((fp = g_fopen(file, "rb")) == NULL) {
2843 FILE_OP_ERROR(file, "fopen");
2844 return COMPOSE_INSERT_READ_ERROR;
2847 prev_autowrap = compose->autowrap;
2848 compose->autowrap = FALSE;
2850 text = GTK_TEXT_VIEW(compose->text);
2851 buffer = gtk_text_view_get_buffer(text);
2852 mark = gtk_text_buffer_get_insert(buffer);
2853 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2855 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2856 G_CALLBACK(text_inserted),
2859 cur_encoding = conv_get_locale_charset_str_no_utf8();
2861 while (fgets(buf, sizeof(buf), fp) != NULL) {
2864 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2865 str = g_strdup(buf);
2867 str = conv_codeset_strdup
2868 (buf, cur_encoding, CS_INTERNAL);
2871 /* strip <CR> if DOS/Windows file,
2872 replace <CR> with <LF> if Macintosh file. */
2875 if (len > 0 && str[len - 1] != '\n') {
2877 if (str[len] == '\r') str[len] = '\n';
2880 gtk_text_buffer_insert(buffer, &iter, str, -1);
2884 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2885 G_CALLBACK(text_inserted),
2887 compose->autowrap = prev_autowrap;
2888 if (compose->autowrap)
2889 compose_wrap_all(compose);
2894 return COMPOSE_INSERT_INVALID_CHARACTER;
2896 return COMPOSE_INSERT_SUCCESS;
2899 static void compose_attach_append(Compose *compose, const gchar *file,
2900 const gchar *filename,
2901 const gchar *content_type)
2909 GtkListStore *store;
2911 gboolean has_binary = FALSE;
2913 if (!is_file_exist(file)) {
2914 g_warning("File %s doesn't exist\n", filename);
2917 if ((size = get_file_size(file)) < 0) {
2918 g_warning("Can't get file size of %s\n", filename);
2922 alertpanel_notice(_("File %s is empty."), filename);
2925 if ((fp = g_fopen(file, "rb")) == NULL) {
2926 alertpanel_error(_("Can't read %s."), filename);
2931 ainfo = g_new0(AttachInfo, 1);
2932 auto_ainfo = g_auto_pointer_new_with_free
2933 (ainfo, (GFreeFunc) compose_attach_info_free);
2934 ainfo->file = g_strdup(file);
2937 ainfo->content_type = g_strdup(content_type);
2938 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2940 MsgFlags flags = {0, 0};
2942 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
2943 ainfo->encoding = ENC_7BIT;
2945 ainfo->encoding = ENC_8BIT;
2947 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2948 if (msginfo && msginfo->subject)
2949 name = g_strdup(msginfo->subject);
2951 name = g_path_get_basename(filename ? filename : file);
2953 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2955 procmsg_msginfo_free(msginfo);
2957 if (!g_ascii_strncasecmp(content_type, "text", 4))
2958 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
2960 ainfo->encoding = ENC_BASE64;
2961 name = g_path_get_basename(filename ? filename : file);
2962 ainfo->name = g_strdup(name);
2966 ainfo->content_type = procmime_get_mime_type(file);
2967 if (!ainfo->content_type) {
2968 ainfo->content_type =
2969 g_strdup("application/octet-stream");
2970 ainfo->encoding = ENC_BASE64;
2971 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2973 procmime_get_encoding_for_text_file(file, &has_binary);
2975 ainfo->encoding = ENC_BASE64;
2976 name = g_path_get_basename(filename ? filename : file);
2977 ainfo->name = g_strdup(name);
2981 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
2982 g_free(ainfo->content_type);
2983 ainfo->content_type = g_strdup("application/octet-stream");
2987 size_text = to_human_readable(size);
2989 store = GTK_LIST_STORE(gtk_tree_view_get_model
2990 (GTK_TREE_VIEW(compose->attach_clist)));
2992 gtk_list_store_append(store, &iter);
2993 gtk_list_store_set(store, &iter,
2994 COL_MIMETYPE, ainfo->content_type,
2995 COL_SIZE, size_text,
2996 COL_NAME, ainfo->name,
2998 COL_AUTODATA, auto_ainfo,
3001 g_auto_pointer_free(auto_ainfo);
3004 static void compose_use_signing(Compose *compose, gboolean use_signing)
3006 GtkItemFactory *ifactory;
3007 GtkWidget *menuitem = NULL;
3009 compose->use_signing = use_signing;
3010 ifactory = gtk_item_factory_from_widget(compose->menubar);
3011 menuitem = gtk_item_factory_get_item
3012 (ifactory, "/Options/Sign");
3013 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3017 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
3019 GtkItemFactory *ifactory;
3020 GtkWidget *menuitem = NULL;
3022 compose->use_encryption = use_encryption;
3023 ifactory = gtk_item_factory_from_widget(compose->menubar);
3024 menuitem = gtk_item_factory_get_item
3025 (ifactory, "/Options/Encrypt");
3027 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3031 #define NEXT_PART_NOT_CHILD(info) \
3033 node = info->node; \
3034 while (node->children) \
3035 node = g_node_last_child(node); \
3036 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3039 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3043 MimeInfo *firsttext = NULL;
3044 MimeInfo *encrypted = NULL;
3047 const gchar *partname = NULL;
3049 mimeinfo = procmime_scan_message(msginfo);
3050 if (!mimeinfo) return;
3052 if (mimeinfo->node->children == NULL) {
3053 procmime_mimeinfo_free_all(mimeinfo);
3057 /* find first content part */
3058 child = (MimeInfo *) mimeinfo->node->children->data;
3059 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3060 child = (MimeInfo *)child->node->children->data;
3062 if (child->type == MIMETYPE_TEXT) {
3064 debug_print("First text part found\n");
3065 } else if (compose->mode == COMPOSE_REEDIT &&
3066 child->type == MIMETYPE_APPLICATION &&
3067 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3068 encrypted = (MimeInfo *)child->node->parent->data;
3071 child = (MimeInfo *) mimeinfo->node->children->data;
3072 while (child != NULL) {
3073 if (child == encrypted) {
3074 /* skip this part of tree */
3075 NEXT_PART_NOT_CHILD(child);
3079 if (child->type == MIMETYPE_MULTIPART) {
3080 /* get the actual content */
3081 child = procmime_mimeinfo_next(child);
3085 if (child == firsttext) {
3086 child = procmime_mimeinfo_next(child);
3090 outfile = procmime_get_tmp_file_name(child);
3091 if (procmime_get_part(outfile, child) < 0)
3092 g_warning("Can't get the part of multipart message.");
3094 gchar *content_type;
3096 content_type = procmime_get_content_type_str(child->type, child->subtype);
3098 /* if we meet a pgp signature, we don't attach it, but
3099 * we force signing. */
3100 if (strcmp(content_type, "application/pgp-signature")) {
3101 partname = procmime_mimeinfo_get_parameter(child, "filename");
3102 if (partname == NULL)
3103 partname = procmime_mimeinfo_get_parameter(child, "name");
3104 if (partname == NULL)
3106 compose_attach_append(compose, outfile,
3107 partname, content_type);
3109 compose_force_signing(compose, compose->account);
3111 g_free(content_type);
3114 NEXT_PART_NOT_CHILD(child);
3116 procmime_mimeinfo_free_all(mimeinfo);
3119 #undef NEXT_PART_NOT_CHILD
3124 WAIT_FOR_INDENT_CHAR,
3125 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3128 /* return indent length, we allow:
3129 indent characters followed by indent characters or spaces/tabs,
3130 alphabets and numbers immediately followed by indent characters,
3131 and the repeating sequences of the above
3132 If quote ends with multiple spaces, only the first one is included. */
3133 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3134 const GtkTextIter *start, gint *len)
3136 GtkTextIter iter = *start;
3140 IndentState state = WAIT_FOR_INDENT_CHAR;
3143 gint alnum_count = 0;
3144 gint space_count = 0;
3147 if (prefs_common.quote_chars == NULL) {
3151 while (!gtk_text_iter_ends_line(&iter)) {
3152 wc = gtk_text_iter_get_char(&iter);
3153 if (g_unichar_iswide(wc))
3155 clen = g_unichar_to_utf8(wc, ch);
3159 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3160 is_space = g_unichar_isspace(wc);
3162 if (state == WAIT_FOR_INDENT_CHAR) {
3163 if (!is_indent && !g_unichar_isalnum(wc))
3166 quote_len += alnum_count + space_count + 1;
3167 alnum_count = space_count = 0;
3168 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3171 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3172 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3176 else if (is_indent) {
3177 quote_len += alnum_count + space_count + 1;
3178 alnum_count = space_count = 0;
3181 state = WAIT_FOR_INDENT_CHAR;
3185 gtk_text_iter_forward_char(&iter);
3188 if (quote_len > 0 && space_count > 0)
3194 if (quote_len > 0) {
3196 gtk_text_iter_forward_chars(&iter, quote_len);
3197 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3203 /* return TRUE if the line is itemized */
3204 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3205 const GtkTextIter *start)
3207 GtkTextIter iter = *start;
3212 if (gtk_text_iter_ends_line(&iter))
3216 wc = gtk_text_iter_get_char(&iter);
3217 if (!g_unichar_isspace(wc))
3219 gtk_text_iter_forward_char(&iter);
3220 if (gtk_text_iter_ends_line(&iter))
3224 clen = g_unichar_to_utf8(wc, ch);
3228 if (!strchr("*-+", ch[0]))
3231 gtk_text_iter_forward_char(&iter);
3232 if (gtk_text_iter_ends_line(&iter))
3234 wc = gtk_text_iter_get_char(&iter);
3235 if (g_unichar_isspace(wc))
3241 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3242 const GtkTextIter *start,
3243 GtkTextIter *break_pos,
3247 GtkTextIter iter = *start, line_end = *start;
3248 PangoLogAttr *attrs;
3255 gboolean can_break = FALSE;
3256 gboolean do_break = FALSE;
3257 gboolean was_white = FALSE;
3258 gboolean prev_dont_break = FALSE;
3260 gtk_text_iter_forward_to_line_end(&line_end);
3261 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3262 len = g_utf8_strlen(str, -1);
3263 /* g_print("breaking line: %d: %s (len = %d)\n",
3264 gtk_text_iter_get_line(&iter), str, len); */
3265 attrs = g_new(PangoLogAttr, len + 1);
3267 pango_default_break(str, -1, NULL, attrs, len + 1);
3271 /* skip quote and leading spaces */
3272 for (i = 0; *p != '\0' && i < len; i++) {
3275 wc = g_utf8_get_char(p);
3276 if (i >= quote_len && !g_unichar_isspace(wc))
3278 if (g_unichar_iswide(wc))
3280 else if (*p == '\t')
3284 p = g_utf8_next_char(p);
3287 for (; *p != '\0' && i < len; i++) {
3288 PangoLogAttr *attr = attrs + i;
3292 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3295 was_white = attr->is_white;
3297 /* don't wrap URI */
3298 if ((uri_len = get_uri_len(p)) > 0) {
3300 if (pos > 0 && col > max_col) {
3310 wc = g_utf8_get_char(p);
3311 if (g_unichar_iswide(wc)) {
3313 if (prev_dont_break && can_break && attr->is_line_break)
3315 } else if (*p == '\t')
3319 if (pos > 0 && col > max_col) {
3324 if (*p == '-' || *p == '/')
3325 prev_dont_break = TRUE;
3327 prev_dont_break = FALSE;
3329 p = g_utf8_next_char(p);
3333 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3338 *break_pos = *start;
3339 gtk_text_iter_set_line_offset(break_pos, pos);
3344 static gboolean compose_join_next_line(Compose *compose,
3345 GtkTextBuffer *buffer,
3347 const gchar *quote_str)
3349 GtkTextIter iter_ = *iter, cur, prev, next, end;
3350 PangoLogAttr attrs[3];
3352 gchar *next_quote_str;
3355 gboolean keep_cursor = FALSE;
3357 if (!gtk_text_iter_forward_line(&iter_) ||
3358 gtk_text_iter_ends_line(&iter_))
3361 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3363 if ((quote_str || next_quote_str) &&
3364 strcmp2(quote_str, next_quote_str) != 0) {
3365 g_free(next_quote_str);
3368 g_free(next_quote_str);
3371 if (quote_len > 0) {
3372 gtk_text_iter_forward_chars(&end, quote_len);
3373 if (gtk_text_iter_ends_line(&end))
3377 /* don't join itemized lines */
3378 if (compose_is_itemized(buffer, &end))
3381 /* don't join signature separator */
3382 if (compose_is_sig_separator(compose, buffer, &iter_))
3385 /* delete quote str */
3387 gtk_text_buffer_delete(buffer, &iter_, &end);
3389 /* don't join line breaks put by the user */
3391 gtk_text_iter_backward_char(&cur);
3392 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3393 gtk_text_iter_forward_char(&cur);
3397 gtk_text_iter_forward_char(&cur);
3398 /* delete linebreak and extra spaces */
3399 while (gtk_text_iter_backward_char(&cur)) {
3400 wc1 = gtk_text_iter_get_char(&cur);
3401 if (!g_unichar_isspace(wc1))
3406 while (!gtk_text_iter_ends_line(&cur)) {
3407 wc1 = gtk_text_iter_get_char(&cur);
3408 if (!g_unichar_isspace(wc1))
3410 gtk_text_iter_forward_char(&cur);
3413 if (!gtk_text_iter_equal(&prev, &next)) {
3416 mark = gtk_text_buffer_get_insert(buffer);
3417 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3418 if (gtk_text_iter_equal(&prev, &cur))
3420 gtk_text_buffer_delete(buffer, &prev, &next);
3424 /* insert space if required */
3425 gtk_text_iter_backward_char(&prev);
3426 wc1 = gtk_text_iter_get_char(&prev);
3427 wc2 = gtk_text_iter_get_char(&next);
3428 gtk_text_iter_forward_char(&next);
3429 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3430 pango_default_break(str, -1, NULL, attrs, 3);
3431 if (!attrs[1].is_line_break ||
3432 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3433 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3435 gtk_text_iter_backward_char(&iter_);
3436 gtk_text_buffer_place_cursor(buffer, &iter_);
3445 #define ADD_TXT_POS(bp_, ep_, pti_) \
3446 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3447 last = last->next; \
3448 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3449 last->next = NULL; \
3451 g_warning("alloc error scanning URIs\n"); \
3454 static gboolean automatic_break = FALSE;
3455 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3457 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3458 GtkTextBuffer *buffer;
3459 GtkTextIter iter, break_pos, end_of_line;
3460 gchar *quote_str = NULL;
3462 gboolean wrap_quote = prefs_common.linewrap_quote;
3463 gboolean prev_autowrap = compose->autowrap;
3464 gint startq_offset = -1, noq_offset = -1;
3465 gint uri_start = -1, uri_stop = -1;
3466 gint nouri_start = -1, nouri_stop = -1;
3467 gint num_blocks = 0;
3468 gint quotelevel = -1;
3470 compose->autowrap = FALSE;
3472 buffer = gtk_text_view_get_buffer(text);
3473 undo_wrapping(compose->undostruct, TRUE);
3478 mark = gtk_text_buffer_get_insert(buffer);
3479 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3482 /* move to paragraph start */
3483 gtk_text_iter_set_line_offset(&iter, 0);
3484 if (gtk_text_iter_ends_line(&iter)) {
3485 while (gtk_text_iter_ends_line(&iter) &&
3486 gtk_text_iter_forward_line(&iter))
3489 while (gtk_text_iter_backward_line(&iter)) {
3490 if (gtk_text_iter_ends_line(&iter)) {
3491 gtk_text_iter_forward_line(&iter);
3497 /* go until paragraph end (empty line) */
3499 while (!gtk_text_iter_ends_line(&iter)) {
3500 gchar *scanpos = NULL;
3501 /* parse table - in order of priority */
3503 const gchar *needle; /* token */
3505 /* token search function */
3506 gchar *(*search) (const gchar *haystack,
3507 const gchar *needle);
3508 /* part parsing function */
3509 gboolean (*parse) (const gchar *start,
3510 const gchar *scanpos,
3514 /* part to URI function */
3515 gchar *(*build_uri) (const gchar *bp,
3519 static struct table parser[] = {
3520 {"http://", strcasestr, get_uri_part, make_uri_string},
3521 {"https://", strcasestr, get_uri_part, make_uri_string},
3522 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3523 {"sftp://", strcasestr, get_uri_part, make_uri_string},
3524 {"www.", strcasestr, get_uri_part, make_http_string},
3525 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3526 {"@", strcasestr, get_email_part, make_email_string}
3528 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3529 gint last_index = PARSE_ELEMS;
3531 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3534 if (!prev_autowrap && num_blocks == 0) {
3536 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3537 G_CALLBACK(text_inserted),
3540 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3543 uri_start = uri_stop = -1;
3545 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3549 if (startq_offset == -1) {
3550 startq_offset = gtk_text_iter_get_offset(&iter);
3554 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3555 if (startq_offset == -1)
3556 startq_offset = gtk_text_iter_get_offset(&iter);
3557 quotelevel = get_quote_level(quote_str, prefs_common.quote_chars);
3558 if (quotelevel > 2) {
3559 /* recycle colors */
3560 if (prefs_common.recycle_quote_colors)
3566 if (startq_offset == -1)
3567 noq_offset = gtk_text_iter_get_offset(&iter);
3571 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3574 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3575 prefs_common.linewrap_len,
3577 GtkTextIter prev, next, cur;
3579 if (prev_autowrap != FALSE || force) {
3580 automatic_break = TRUE;
3581 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3582 automatic_break = FALSE;
3583 } else if (quote_str && wrap_quote) {
3584 automatic_break = TRUE;
3585 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3586 automatic_break = FALSE;
3589 /* remove trailing spaces */
3591 gtk_text_iter_backward_char(&cur);
3593 while (!gtk_text_iter_starts_line(&cur)) {
3596 gtk_text_iter_backward_char(&cur);
3597 wc = gtk_text_iter_get_char(&cur);
3598 if (!g_unichar_isspace(wc))
3602 if (!gtk_text_iter_equal(&prev, &next)) {
3603 gtk_text_buffer_delete(buffer, &prev, &next);
3605 gtk_text_iter_forward_char(&break_pos);
3609 gtk_text_buffer_insert(buffer, &break_pos,
3613 compose_join_next_line(compose, buffer, &iter, quote_str);
3615 /* move iter to current line start */
3616 gtk_text_iter_set_line_offset(&iter, 0);
3623 /* move iter to next line start */
3628 if (!prev_autowrap && num_blocks > 0) {
3630 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3631 G_CALLBACK(text_inserted),
3635 while (!gtk_text_iter_ends_line(&end_of_line)) {
3636 gtk_text_iter_forward_char(&end_of_line);
3638 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3640 nouri_start = gtk_text_iter_get_offset(&iter);
3641 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3643 walk_pos = gtk_text_iter_get_offset(&iter);
3644 /* FIXME: this looks phony. scanning for anything in the parse table */
3645 for (n = 0; n < PARSE_ELEMS; n++) {
3648 tmp = parser[n].search(walk, parser[n].needle);
3650 if (scanpos == NULL || tmp < scanpos) {
3659 /* check if URI can be parsed */
3660 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3661 (const gchar **)&ep, FALSE)
3662 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3666 strlen(parser[last_index].needle);
3669 uri_start = walk_pos + (bp - o_walk);
3670 uri_stop = walk_pos + (ep - o_walk);
3674 gtk_text_iter_forward_line(&iter);
3677 if (startq_offset != -1) {
3678 GtkTextIter startquote, endquote;
3679 gtk_text_buffer_get_iter_at_offset(
3680 buffer, &startquote, startq_offset);
3682 switch (quotelevel) {
3683 case 0: gtk_text_buffer_apply_tag_by_name(
3684 buffer, "quote0", &startquote, &endquote);
3686 case 1: gtk_text_buffer_apply_tag_by_name(
3687 buffer, "quote1", &startquote, &endquote);
3689 case 2: gtk_text_buffer_apply_tag_by_name(
3690 buffer, "quote2", &startquote, &endquote);
3694 } else if (noq_offset != -1) {
3695 GtkTextIter startnoquote, endnoquote;
3696 gtk_text_buffer_get_iter_at_offset(
3697 buffer, &startnoquote, noq_offset);
3699 gtk_text_buffer_remove_tag_by_name(
3700 buffer, "quote0", &startnoquote, &endnoquote);
3701 gtk_text_buffer_remove_tag_by_name(
3702 buffer, "quote1", &startnoquote, &endnoquote);
3703 gtk_text_buffer_remove_tag_by_name(
3704 buffer, "quote2", &startnoquote, &endnoquote);
3709 GtkTextIter nouri_start_iter, nouri_end_iter;
3710 gtk_text_buffer_get_iter_at_offset(
3711 buffer, &nouri_start_iter, nouri_start);
3712 gtk_text_buffer_get_iter_at_offset(
3713 buffer, &nouri_end_iter, nouri_stop);
3714 gtk_text_buffer_remove_tag_by_name(
3715 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3717 if (uri_start > 0 && uri_stop > 0) {
3718 GtkTextIter uri_start_iter, uri_end_iter;
3719 gtk_text_buffer_get_iter_at_offset(
3720 buffer, &uri_start_iter, uri_start);
3721 gtk_text_buffer_get_iter_at_offset(
3722 buffer, &uri_end_iter, uri_stop);
3723 gtk_text_buffer_apply_tag_by_name(
3724 buffer, "link", &uri_start_iter, &uri_end_iter);
3730 undo_wrapping(compose->undostruct, FALSE);
3731 compose->autowrap = prev_autowrap;
3734 void compose_action_cb(void *data)
3736 Compose *compose = (Compose *)data;
3737 compose_wrap_all(compose);
3740 static void compose_wrap_all(Compose *compose)
3742 compose_wrap_all_full(compose, FALSE);
3745 static void compose_wrap_all_full(Compose *compose, gboolean force)
3747 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3748 GtkTextBuffer *buffer;
3751 buffer = gtk_text_view_get_buffer(text);
3753 gtk_text_buffer_get_start_iter(buffer, &iter);
3754 while (!gtk_text_iter_is_end(&iter))
3755 compose_beautify_paragraph(compose, &iter, force);
3759 static void compose_set_title(Compose *compose)
3765 edited = compose->modified ? _(" [Edited]") : "";
3767 subject = gtk_editable_get_chars(
3768 GTK_EDITABLE(compose->subject_entry), 0, -1);
3770 if (subject && strlen(subject))
3771 str = g_strdup_printf(_("%s - Compose message%s"),
3774 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3775 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3781 * compose_current_mail_account:
3783 * Find a current mail account (the currently selected account, or the
3784 * default account, if a news account is currently selected). If a
3785 * mail account cannot be found, display an error message.
3787 * Return value: Mail account, or NULL if not found.
3789 static PrefsAccount *
3790 compose_current_mail_account(void)
3794 if (cur_account && cur_account->protocol != A_NNTP)
3797 ac = account_get_default();
3798 if (!ac || ac->protocol == A_NNTP) {
3799 alertpanel_error(_("Account for sending mail is not specified.\n"
3800 "Please select a mail account before sending."));
3807 #define QUOTE_IF_REQUIRED(out, str) \
3809 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3813 len = strlen(str) + 3; \
3814 if ((__tmp = alloca(len)) == NULL) { \
3815 g_warning("can't allocate memory\n"); \
3816 g_string_free(header, TRUE); \
3819 g_snprintf(__tmp, len, "\"%s\"", str); \
3824 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3825 g_warning("can't allocate memory\n"); \
3826 g_string_free(header, TRUE); \
3829 strcpy(__tmp, str); \
3835 #define QUOTE_IF_REQUIRED_NORMAL(out, str, errret) \
3837 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3841 len = strlen(str) + 3; \
3842 if ((__tmp = alloca(len)) == NULL) { \
3843 g_warning("can't allocate memory\n"); \
3846 g_snprintf(__tmp, len, "\"%s\"", str); \
3851 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3852 g_warning("can't allocate memory\n"); \
3855 strcpy(__tmp, str); \
3861 static void compose_select_account(Compose *compose, PrefsAccount *account,
3864 GtkItemFactory *ifactory;
3867 g_return_if_fail(account != NULL);
3869 compose->account = account;
3871 if (account->name && *account->name) {
3873 QUOTE_IF_REQUIRED_NORMAL(buf, account->name, return);
3874 from = g_strdup_printf("%s <%s>",
3875 buf, account->address);
3876 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
3878 from = g_strdup_printf("<%s>",
3880 gtk_entry_set_text(GTK_ENTRY(compose->from_name), from);
3885 compose_set_title(compose);
3887 ifactory = gtk_item_factory_from_widget(compose->menubar);
3889 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3890 menu_set_active(ifactory, "/Options/Sign", TRUE);
3892 menu_set_active(ifactory, "/Options/Sign", FALSE);
3893 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3894 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3896 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3898 activate_privacy_system(compose, account, FALSE);
3900 if (!init && compose->mode != COMPOSE_REDIRECT) {
3901 undo_block(compose->undostruct);
3902 compose_insert_sig(compose, TRUE);
3903 undo_unblock(compose->undostruct);
3907 gboolean compose_check_for_valid_recipient(Compose *compose) {
3908 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3909 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3910 gboolean recipient_found = FALSE;
3914 /* free to and newsgroup list */
3915 slist_free_strings(compose->to_list);
3916 g_slist_free(compose->to_list);
3917 compose->to_list = NULL;
3919 slist_free_strings(compose->newsgroup_list);
3920 g_slist_free(compose->newsgroup_list);
3921 compose->newsgroup_list = NULL;
3923 /* search header entries for to and newsgroup entries */
3924 for (list = compose->header_list; list; list = list->next) {
3927 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3928 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3930 if (entry[0] != '\0') {
3931 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3932 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3933 compose->to_list = address_list_append(compose->to_list, entry);
3934 recipient_found = TRUE;
3937 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3938 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3939 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3940 recipient_found = TRUE;
3947 return recipient_found;
3950 static gboolean compose_check_for_set_recipients(Compose *compose)
3952 if (compose->account->set_autocc && compose->account->auto_cc) {
3953 gboolean found_other = FALSE;
3955 /* search header entries for to and newsgroup entries */
3956 for (list = compose->header_list; list; list = list->next) {
3959 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3960 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3962 if (strcmp(entry, compose->account->auto_cc)
3963 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3973 if (compose->batch) {
3974 gtk_widget_show_all(compose->window);
3976 aval = alertpanel(_("Send"),
3977 _("The only recipient is the default CC address. Send anyway?"),
3978 GTK_STOCK_CANCEL, _("+_Send"), NULL);
3979 if (aval != G_ALERTALTERNATE)
3983 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3984 gboolean found_other = FALSE;
3986 /* search header entries for to and newsgroup entries */
3987 for (list = compose->header_list; list; list = list->next) {
3990 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3991 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3993 if (strcmp(entry, compose->account->auto_cc)
3994 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
4004 if (compose->batch) {
4005 gtk_widget_show_all(compose->window);
4007 aval = alertpanel(_("Send"),
4008 _("The only recipient is the default BCC address. Send anyway?"),
4009 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4010 if (aval != G_ALERTALTERNATE)
4017 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
4021 if (compose_check_for_valid_recipient(compose) == FALSE) {
4022 if (compose->batch) {
4023 gtk_widget_show_all(compose->window);
4025 alertpanel_error(_("Recipient is not specified."));
4029 if (compose_check_for_set_recipients(compose) == FALSE) {
4033 if (!compose->batch) {
4034 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4035 if (*str == '\0' && check_subject == TRUE) {
4038 aval = alertpanel(_("Send"),
4039 _("Subject is empty. Send it anyway?"),
4040 GTK_STOCK_CANCEL, _("+_Send"), NULL);
4041 if (aval != G_ALERTALTERNATE)
4049 gint compose_send(Compose *compose)
4052 FolderItem *folder = NULL;
4054 gchar *msgpath = NULL;
4055 gboolean discard_window = FALSE;
4056 gchar *errstr = NULL;
4057 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS
4058 || compose->batch == TRUE)
4059 discard_window = TRUE;
4061 compose_allow_user_actions (compose, FALSE);
4062 compose->sending = TRUE;
4064 if (compose_check_entries(compose, TRUE) == FALSE) {
4065 if (compose->batch) {
4066 gtk_widget_show_all(compose->window);
4071 val = compose_queue(compose, &msgnum, &folder, &msgpath, TRUE);
4074 if (compose->batch) {
4075 gtk_widget_show_all(compose->window);
4078 alertpanel_error(_("Could not queue message for sending:\n\n"
4079 "Charset conversion failed."));
4080 } else if (val == -3) {
4081 if (privacy_peek_error())
4082 alertpanel_error(_("Could not queue message for sending:\n\n"
4083 "Signature failed: %s"), privacy_get_error());
4084 } else if (val == -2 && errno != 0) {
4085 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
4087 alertpanel_error(_("Could not queue message for sending."));
4092 if (discard_window) {
4093 compose->sending = FALSE;
4094 compose_close(compose);
4095 /* No more compose access in the normal codepath
4096 * after this point! */
4101 alertpanel_error(_("The message was queued but could not be "
4102 "sent.\nUse \"Send queued messages\" from "
4103 "the main window to retry."));
4104 if (!discard_window) {
4110 if (msgpath == NULL) {
4111 msgpath = folder_item_fetch_msg(folder, msgnum);
4112 val = procmsg_send_message_queue(msgpath, &errstr);
4115 val = procmsg_send_message_queue(msgpath, &errstr);
4119 if (!discard_window) {
4120 compose->sending = FALSE;
4121 compose_allow_user_actions (compose, TRUE);
4123 folder_item_remove_msg(folder, msgnum);
4124 folder_item_scan(folder);
4129 folder_item_remove_msg(folder, msgnum);
4130 folder_item_scan(folder);
4131 if (!discard_window)
4132 compose_close(compose);
4135 gchar *tmp = g_strdup_printf(_("%s\nUse \"Send queued messages\" from "
4136 "the main window to retry."), errstr);
4138 alertpanel_error_log(tmp);
4141 alertpanel_error_log(_("The message was queued but could not be "
4142 "sent.\nUse \"Send queued messages\" from "
4143 "the main window to retry."));
4145 if (!discard_window) {
4154 compose_allow_user_actions (compose, TRUE);
4155 compose->sending = FALSE;
4156 compose->modified = TRUE;
4161 static gboolean compose_use_attach(Compose *compose)
4163 GtkTreeModel *model = gtk_tree_view_get_model
4164 (GTK_TREE_VIEW(compose->attach_clist));
4165 return gtk_tree_model_iter_n_children(model, NULL) > 0;
4168 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
4171 gchar buf[BUFFSIZE];
4173 gboolean first_to_address;
4174 gboolean first_cc_address;
4176 ComposeHeaderEntry *headerentry;
4177 const gchar *headerentryname;
4181 debug_print("Writing redirect header\n");
4183 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
4184 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
4186 first_to_address = TRUE;
4187 for (list = compose->header_list; list; list = list->next) {
4188 headerentry = ((ComposeHeaderEntry *)list->data);
4189 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4191 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
4192 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4193 Xstrdup_a(str, entstr, return -1);
4195 if (str[0] != '\0') {
4196 compose_convert_header
4197 (compose, buf, sizeof(buf), str,
4198 strlen("Resent-To") + 2, TRUE);
4200 if (first_to_address) {
4201 fprintf(fp, "Resent-To: ");
4202 first_to_address = FALSE;
4206 fprintf(fp, "%s", buf);
4210 if (!first_to_address) {
4214 first_cc_address = TRUE;
4215 for (list = compose->header_list; list; list = list->next) {
4216 headerentry = ((ComposeHeaderEntry *)list->data);
4217 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4219 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
4220 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4221 Xstrdup_a(str, strg, return -1);
4223 if (str[0] != '\0') {
4224 compose_convert_header
4225 (compose, buf, sizeof(buf), str,
4226 strlen("Resent-Cc") + 2, TRUE);
4228 if (first_cc_address) {
4229 fprintf(fp, "Resent-Cc: ");
4230 first_cc_address = FALSE;
4234 fprintf(fp, "%s", buf);
4238 if (!first_cc_address) {
4245 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
4247 gchar buf[BUFFSIZE];
4249 const gchar *entstr;
4250 /* struct utsname utsbuf; */
4252 g_return_val_if_fail(fp != NULL, -1);
4253 g_return_val_if_fail(compose->account != NULL, -1);
4254 g_return_val_if_fail(compose->account->address != NULL, -1);
4257 get_rfc822_date(buf, sizeof(buf));
4258 fprintf(fp, "Resent-Date: %s\n", buf);
4261 if (compose->account->name && *compose->account->name) {
4262 compose_convert_header
4263 (compose, buf, sizeof(buf), compose->account->name,
4264 strlen("From: "), TRUE);
4265 fprintf(fp, "Resent-From: %s <%s>\n",
4266 buf, compose->account->address);
4268 fprintf(fp, "Resent-From: %s\n", compose->account->address);
4271 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4272 if (*entstr != '\0') {
4273 Xstrdup_a(str, entstr, return -1);
4276 compose_convert_header(compose, buf, sizeof(buf), str,
4277 strlen("Subject: "), FALSE);
4278 fprintf(fp, "Subject: %s\n", buf);
4282 /* Resent-Message-ID */
4283 if (compose->account->gen_msgid) {
4284 generate_msgid(buf, sizeof(buf));
4285 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
4286 compose->msgid = g_strdup(buf);
4289 compose_redirect_write_headers_from_headerlist(compose, fp);
4291 /* separator between header and body */
4297 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
4301 gchar buf[BUFFSIZE];
4303 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
4304 FILE_OP_ERROR(compose->redirect_filename, "fopen");
4308 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
4309 /* should filter returnpath, delivered-to */
4310 if (g_ascii_strncasecmp(buf, "Return-Path:",
4311 strlen("Return-Path:")) == 0 ||
4312 g_ascii_strncasecmp(buf, "Delivered-To:",
4313 strlen("Delivered-To:")) == 0 ||
4314 g_ascii_strncasecmp(buf, "Received:",
4315 strlen("Received:")) == 0 ||
4316 g_ascii_strncasecmp(buf, "Subject:",
4317 strlen("Subject:")) == 0 ||
4318 g_ascii_strncasecmp(buf, "X-UIDL:",
4319 strlen("X-UIDL:")) == 0)
4322 if (fputs(buf, fdest) == -1)
4325 if (!prefs_common.redirect_keep_from) {
4326 if (g_ascii_strncasecmp(buf, "From:",
4327 strlen("From:")) == 0) {
4328 fputs(" (by way of ", fdest);
4329 if (compose->account->name
4330 && *compose->account->name) {
4331 compose_convert_header
4332 (compose, buf, sizeof(buf),
4333 compose->account->name,
4336 fprintf(fdest, "%s <%s>",
4338 compose->account->address);
4340 fprintf(fdest, "%s",
4341 compose->account->address);
4346 if (fputs("\n", fdest) == -1)
4350 compose_redirect_write_headers(compose, fdest);
4352 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
4353 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
4366 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gboolean attach_parts)
4368 GtkTextBuffer *buffer;
4369 GtkTextIter start, end;
4372 const gchar *out_codeset;
4373 EncodingType encoding;
4374 MimeInfo *mimemsg, *mimetext;
4377 if (action == COMPOSE_WRITE_FOR_SEND)
4378 attach_parts = TRUE;
4380 /* create message MimeInfo */
4381 mimemsg = procmime_mimeinfo_new();
4382 mimemsg->type = MIMETYPE_MESSAGE;
4383 mimemsg->subtype = g_strdup("rfc822");
4384 mimemsg->content = MIMECONTENT_MEM;
4385 mimemsg->tmp = TRUE; /* must free content later */
4386 mimemsg->data.mem = compose_get_header(compose);
4388 /* Create text part MimeInfo */
4389 /* get all composed text */
4390 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4391 gtk_text_buffer_get_start_iter(buffer, &start);
4392 gtk_text_buffer_get_end_iter(buffer, &end);
4393 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4394 if (is_ascii_str(chars)) {
4397 out_codeset = CS_US_ASCII;
4398 encoding = ENC_7BIT;
4400 const gchar *src_codeset = CS_INTERNAL;
4402 out_codeset = conv_get_charset_str(compose->out_encoding);
4405 gchar *test_conv_global_out = NULL;
4406 gchar *test_conv_reply = NULL;
4408 /* automatic mode. be automatic. */
4409 codeconv_set_strict(TRUE);
4411 out_codeset = conv_get_outgoing_charset_str();
4413 debug_print("trying to convert to %s\n", out_codeset);
4414 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4417 if (!test_conv_global_out && compose->orig_charset
4418 && strcmp(compose->orig_charset, CS_US_ASCII)) {
4419 out_codeset = compose->orig_charset;
4420 debug_print("failure; trying to convert to %s\n", out_codeset);
4421 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4424 if (!test_conv_global_out && !test_conv_reply) {
4426 out_codeset = CS_INTERNAL;
4427 debug_print("failure; finally using %s\n", out_codeset);
4429 g_free(test_conv_global_out);
4430 g_free(test_conv_reply);
4431 codeconv_set_strict(FALSE);
4434 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4435 out_codeset = CS_ISO_8859_1;
4437 if (prefs_common.encoding_method == CTE_BASE64)
4438 encoding = ENC_BASE64;
4439 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4440 encoding = ENC_QUOTED_PRINTABLE;
4441 else if (prefs_common.encoding_method == CTE_8BIT)
4442 encoding = ENC_8BIT;
4444 encoding = procmime_get_encoding_for_charset(out_codeset);
4446 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4447 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4449 if (action == COMPOSE_WRITE_FOR_SEND) {
4450 codeconv_set_strict(TRUE);
4451 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4452 codeconv_set_strict(FALSE);
4458 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4459 "to the specified %s charset.\n"
4460 "Send it as %s?"), out_codeset, src_codeset);
4461 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
4462 NULL, ALERT_ERROR, G_ALERTDEFAULT);
4465 if (aval != G_ALERTALTERNATE) {
4470 out_codeset = src_codeset;
4476 out_codeset = src_codeset;
4482 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4483 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4484 strstr(buf, "\nFrom ") != NULL) {
4485 encoding = ENC_QUOTED_PRINTABLE;
4489 mimetext = procmime_mimeinfo_new();
4490 mimetext->content = MIMECONTENT_MEM;
4491 mimetext->tmp = TRUE; /* must free content later */
4492 mimetext->data.mem = buf;
4493 mimetext->type = MIMETYPE_TEXT;
4494 mimetext->subtype = g_strdup("plain");
4495 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4496 g_strdup(out_codeset));
4497 /* protect trailing spaces when signing message */
4498 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4499 privacy_system_can_sign(compose->privacy_system)) {
4500 encoding = ENC_QUOTED_PRINTABLE;
4503 /* check for line length limit */
4504 if (action == COMPOSE_WRITE_FOR_SEND &&
4505 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4506 check_line_length(buf, 1000, &line) < 0) {
4510 msg = g_strdup_printf
4511 (_("Line %d exceeds the line length limit (998 bytes).\n"
4512 "The contents of the message might be broken on the way to the delivery.\n"
4514 "Send it anyway?"), line + 1);
4515 aval = alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL);
4517 if (aval != G_ALERTALTERNATE) {
4522 if (encoding != ENC_UNKNOWN)
4523 procmime_encode_content(mimetext, encoding);
4525 /* append attachment parts */
4526 if (compose_use_attach(compose) && attach_parts) {
4527 MimeInfo *mimempart;
4528 gchar *boundary = NULL;
4529 mimempart = procmime_mimeinfo_new();
4530 mimempart->content = MIMECONTENT_EMPTY;
4531 mimempart->type = MIMETYPE_MULTIPART;
4532 mimempart->subtype = g_strdup("mixed");
4536 boundary = generate_mime_boundary(NULL);
4537 } while (strstr(buf, boundary) != NULL);
4539 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4542 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4544 g_node_append(mimempart->node, mimetext->node);
4545 g_node_append(mimemsg->node, mimempart->node);
4547 compose_add_attachments(compose, mimempart);
4549 g_node_append(mimemsg->node, mimetext->node);
4551 /* sign message if sending */
4552 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4553 privacy_system_can_sign(compose->privacy_system))
4554 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4557 procmime_write_mimeinfo(mimemsg, fp);
4559 procmime_mimeinfo_free_all(mimemsg);
4564 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4566 GtkTextBuffer *buffer;
4567 GtkTextIter start, end;
4572 if ((fp = g_fopen(file, "wb")) == NULL) {
4573 FILE_OP_ERROR(file, "fopen");
4577 /* chmod for security */
4578 if (change_file_mode_rw(fp, file) < 0) {
4579 FILE_OP_ERROR(file, "chmod");
4580 g_warning("can't change file mode\n");
4583 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4584 gtk_text_buffer_get_start_iter(buffer, &start);
4585 gtk_text_buffer_get_end_iter(buffer, &end);
4586 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4588 chars = conv_codeset_strdup
4589 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4592 if (!chars) return -1;
4595 len = strlen(chars);
4596 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4597 FILE_OP_ERROR(file, "fwrite");
4606 if (fclose(fp) == EOF) {
4607 FILE_OP_ERROR(file, "fclose");
4614 static gint compose_remove_reedit_target(Compose *compose, gboolean force)
4617 MsgInfo *msginfo = compose->targetinfo;
4619 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4620 if (!msginfo) return -1;
4622 if (!force && MSG_IS_LOCKED(msginfo->flags))
4625 item = msginfo->folder;
4626 g_return_val_if_fail(item != NULL, -1);
4628 if (procmsg_msg_exist(msginfo) &&
4629 (folder_has_parent_of_type(item, F_QUEUE) ||
4630 folder_has_parent_of_type(item, F_DRAFT)
4631 || msginfo == compose->autosaved_draft)) {
4632 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4633 g_warning("can't remove the old message\n");
4641 void compose_remove_draft(Compose *compose)
4644 MsgInfo *msginfo = compose->targetinfo;
4645 drafts = account_get_special_folder(compose->account, F_DRAFT);
4647 if (procmsg_msg_exist(msginfo)) {
4648 folder_item_remove_msg(drafts, msginfo->msgnum);
4653 gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath,
4654 gboolean remove_reedit_target)
4656 return compose_queue_sub (compose, msgnum, item, msgpath, FALSE, remove_reedit_target);
4658 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
4659 gchar **msgpath, gboolean check_subject,
4660 gboolean remove_reedit_target)
4667 static gboolean lock = FALSE;
4668 PrefsAccount *mailac = NULL, *newsac = NULL;
4670 debug_print("queueing message...\n");
4671 g_return_val_if_fail(compose->account != NULL, -1);
4675 if (compose_check_entries(compose, check_subject) == FALSE) {
4677 if (compose->batch) {
4678 gtk_widget_show_all(compose->window);
4683 if (!compose->to_list && !compose->newsgroup_list) {
4684 g_warning("can't get recipient list.");
4689 if (compose->to_list) {
4690 if (compose->account->protocol != A_NNTP)
4691 mailac = compose->account;
4692 else if (cur_account && cur_account->protocol != A_NNTP)
4693 mailac = cur_account;
4694 else if (!(mailac = compose_current_mail_account())) {
4696 alertpanel_error(_("No account for sending mails available!"));
4701 if (compose->newsgroup_list) {
4702 if (compose->account->protocol == A_NNTP)
4703 newsac = compose->account;
4704 else if (!newsac->protocol != A_NNTP) {
4706 alertpanel_error(_("No account for posting news available!"));
4711 /* write queue header */
4712 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4713 G_DIR_SEPARATOR, compose);
4714 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4715 FILE_OP_ERROR(tmp, "fopen");
4721 if (change_file_mode_rw(fp, tmp) < 0) {
4722 FILE_OP_ERROR(tmp, "chmod");
4723 g_warning("can't change file mode\n");
4726 /* queueing variables */
4727 fprintf(fp, "AF:\n");
4728 fprintf(fp, "NF:0\n");
4729 fprintf(fp, "PS:10\n");
4730 fprintf(fp, "SRH:1\n");
4731 fprintf(fp, "SFN:\n");
4732 fprintf(fp, "DSR:\n");
4734 fprintf(fp, "MID:<%s>\n", compose->msgid);
4736 fprintf(fp, "MID:\n");
4737 fprintf(fp, "CFG:\n");
4738 fprintf(fp, "PT:0\n");
4739 fprintf(fp, "S:%s\n", compose->account->address);
4740 fprintf(fp, "RQ:\n");
4742 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4744 fprintf(fp, "SSV:\n");
4746 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4748 fprintf(fp, "NSV:\n");
4749 fprintf(fp, "SSH:\n");
4750 /* write recepient list */
4751 if (compose->to_list) {
4752 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4753 for (cur = compose->to_list->next; cur != NULL;
4755 fprintf(fp, ",<%s>", (gchar *)cur->data);
4758 /* write newsgroup list */
4759 if (compose->newsgroup_list) {
4761 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4762 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4763 fprintf(fp, ",%s", (gchar *)cur->data);
4766 /* Sylpheed account IDs */
4768 fprintf(fp, "MAID:%d\n", mailac->account_id);
4770 fprintf(fp, "NAID:%d\n", newsac->account_id);
4773 if (compose->privacy_system != NULL) {
4774 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4775 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4776 if (compose->use_encryption) {
4778 if (mailac && mailac->encrypt_to_self) {
4779 GSList *tmp_list = g_slist_copy(compose->to_list);
4780 tmp_list = g_slist_append(tmp_list, compose->account->address);
4781 encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
4782 g_slist_free(tmp_list);
4784 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4786 if (encdata != NULL) {
4787 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4788 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4789 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4791 } /* else we finally dont want to encrypt */
4793 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4794 /* and if encdata was null, it means there's been a problem in
4801 /* Save copy folder */
4802 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4803 gchar *savefolderid;
4805 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4806 fprintf(fp, "SCF:%s\n", savefolderid);
4807 g_free(savefolderid);
4809 /* Save copy folder */
4810 if (compose->return_receipt) {
4811 fprintf(fp, "RRCPT:1\n");
4813 /* Message-ID of message replying to */
4814 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4817 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4818 fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4821 /* Message-ID of message forwarding to */
4822 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4825 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4826 fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4830 /* end of headers */
4831 fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
4833 if (compose->redirect_filename != NULL) {
4834 if (compose_redirect_write_to_file(compose, fp) < 0) {
4843 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND, TRUE)) < 0) {
4848 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4852 if (fclose(fp) == EOF) {
4853 FILE_OP_ERROR(tmp, "fclose");
4860 if (item && *item) {
4863 queue = account_get_special_folder(compose->account, F_QUEUE);
4866 g_warning("can't find queue folder\n");
4872 folder_item_scan(queue);
4873 if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
4874 g_warning("can't queue the message\n");
4881 if (msgpath == NULL) {
4887 if (compose->mode == COMPOSE_REEDIT && remove_reedit_target) {
4888 compose_remove_reedit_target(compose, FALSE);
4891 if ((msgnum != NULL) && (item != NULL)) {
4899 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4902 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4904 struct stat statbuf;
4905 gchar *type, *subtype;
4906 GtkTreeModel *model;
4909 model = gtk_tree_view_get_model(tree_view);
4911 if (!gtk_tree_model_get_iter_first(model, &iter))
4914 gtk_tree_model_get(model, &iter,
4918 mimepart = procmime_mimeinfo_new();
4919 mimepart->content = MIMECONTENT_FILE;
4920 mimepart->data.filename = g_strdup(ainfo->file);
4921 mimepart->tmp = FALSE; /* or we destroy our attachment */
4922 mimepart->offset = 0;
4924 stat(ainfo->file, &statbuf);
4925 mimepart->length = statbuf.st_size;
4927 type = g_strdup(ainfo->content_type);
4929 if (!strchr(type, '/')) {
4931 type = g_strdup("application/octet-stream");
4934 subtype = strchr(type, '/') + 1;
4935 *(subtype - 1) = '\0';
4936 mimepart->type = procmime_get_media_type(type);
4937 mimepart->subtype = g_strdup(subtype);
4940 if (mimepart->type == MIMETYPE_MESSAGE &&
4941 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4942 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4944 g_hash_table_insert(mimepart->typeparameters,
4945 g_strdup("name"), g_strdup(ainfo->name));
4946 g_hash_table_insert(mimepart->dispositionparameters,
4947 g_strdup("filename"), g_strdup(ainfo->name));
4948 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4951 if (compose->use_signing) {
4952 if (ainfo->encoding == ENC_7BIT)
4953 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4954 else if (ainfo->encoding == ENC_8BIT)
4955 ainfo->encoding = ENC_BASE64;
4958 procmime_encode_content(mimepart, ainfo->encoding);
4960 g_node_append(parent->node, mimepart->node);
4961 } while (gtk_tree_model_iter_next(model, &iter));
4964 #define IS_IN_CUSTOM_HEADER(header) \
4965 (compose->account->add_customhdr && \
4966 custom_header_find(compose->account->customhdr_list, header) != NULL)
4968 static void compose_add_headerfield_from_headerlist(Compose *compose,
4970 const gchar *fieldname,
4971 const gchar *seperator)
4973 gchar *str, *fieldname_w_colon, *trans_fieldname;
4974 gboolean add_field = FALSE;
4976 ComposeHeaderEntry *headerentry;
4977 const gchar * headerentryname;
4980 if (IS_IN_CUSTOM_HEADER(fieldname))
4983 debug_print("Adding %s-fields\n", fieldname);
4985 fieldstr = g_string_sized_new(64);
4987 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4988 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4990 for (list = compose->header_list; list; list = list->next) {
4991 headerentry = ((ComposeHeaderEntry *)list->data);
4992 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4994 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4995 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4997 if (str[0] != '\0') {
4999 g_string_append(fieldstr, seperator);
5000 g_string_append(fieldstr, str);
5009 buf = g_new0(gchar, fieldstr->len * 4 + 256);
5010 compose_convert_header
5011 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
5012 strlen(fieldname) + 2, TRUE);
5013 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
5017 g_free(fieldname_w_colon);
5018 g_string_free(fieldstr, TRUE);
5023 static gchar *compose_get_header(Compose *compose)
5025 gchar buf[BUFFSIZE];
5026 const gchar *entry_str;
5030 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5032 gchar *from_name = NULL, *from_address = NULL;
5035 g_return_val_if_fail(compose->account != NULL, NULL);
5036 g_return_val_if_fail(compose->account->address != NULL, NULL);
5038 header = g_string_sized_new(64);
5041 get_rfc822_date(buf, sizeof(buf));
5042 g_string_append_printf(header, "Date: %s\n", buf);
5046 if (compose->account->name && *compose->account->name) {
5048 QUOTE_IF_REQUIRED(buf, compose->account->name);
5049 tmp = g_strdup_printf("%s <%s>",
5050 buf, compose->account->address);
5052 tmp = g_strdup_printf("%s",
5053 compose->account->address);
5055 if (!strcmp(gtk_entry_get_text(GTK_ENTRY(compose->from_name)), tmp)
5056 || strlen(gtk_entry_get_text(GTK_ENTRY(compose->from_name))) == 0) {
5058 from_name = compose->account->name ? g_strdup(compose->account->name):NULL;
5059 from_address = g_strdup(compose->account->address);
5061 gchar *spec = gtk_editable_get_chars(GTK_EDITABLE(compose->from_name), 0, -1);
5062 /* extract name and address */
5063 if (strstr(spec, " <") && strstr(spec, ">")) {
5064 from_address = g_strdup(strrchr(spec, '<')+1);
5065 *(strrchr(from_address, '>')) = '\0';
5066 from_name = g_strdup(spec);
5067 *(strrchr(from_name, '<')) = '\0';
5070 from_address = g_strdup(spec);
5077 if (from_name && *from_name) {
5078 compose_convert_header
5079 (compose, buf, sizeof(buf), from_name,
5080 strlen("From: "), TRUE);
5081 QUOTE_IF_REQUIRED(name, buf);
5083 g_string_append_printf(header, "From: %s <%s>\n",
5084 name, from_address);
5086 g_string_append_printf(header, "From: %s\n", from_address);
5089 g_free(from_address);
5092 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
5095 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
5098 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
5101 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
5104 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
5106 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
5109 compose_convert_header(compose, buf, sizeof(buf), str,
5110 strlen("Subject: "), FALSE);
5111 g_string_append_printf(header, "Subject: %s\n", buf);
5117 if (compose->account->gen_msgid) {
5118 generate_msgid(buf, sizeof(buf));
5119 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
5120 compose->msgid = g_strdup(buf);
5123 if (compose->remove_references == FALSE) {
5125 if (compose->inreplyto && compose->to_list)
5126 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
5129 if (compose->references)
5130 g_string_append_printf(header, "References: %s\n", compose->references);
5134 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
5137 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
5140 if (compose->account->organization &&
5141 strlen(compose->account->organization) &&
5142 !IS_IN_CUSTOM_HEADER("Organization")) {
5143 compose_convert_header(compose, buf, sizeof(buf),
5144 compose->account->organization,
5145 strlen("Organization: "), FALSE);
5146 g_string_append_printf(header, "Organization: %s\n", buf);
5149 /* Program version and system info */
5150 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
5151 !compose->newsgroup_list) {
5152 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
5154 gtk_major_version, gtk_minor_version, gtk_micro_version,
5157 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
5158 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
5160 gtk_major_version, gtk_minor_version, gtk_micro_version,
5164 /* custom headers */
5165 if (compose->account->add_customhdr) {
5168 for (cur = compose->account->customhdr_list; cur != NULL;
5170 CustomHeader *chdr = (CustomHeader *)cur->data;
5172 if (custom_header_is_allowed(chdr->name)) {
5173 compose_convert_header
5174 (compose, buf, sizeof(buf),
5175 chdr->value ? chdr->value : "",
5176 strlen(chdr->name) + 2, FALSE);
5177 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
5183 switch (compose->priority) {
5184 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
5185 "X-Priority: 1 (Highest)\n");
5187 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
5188 "X-Priority: 2 (High)\n");
5190 case PRIORITY_NORMAL: break;
5191 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
5192 "X-Priority: 4 (Low)\n");
5194 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
5195 "X-Priority: 5 (Lowest)\n");
5197 default: debug_print("compose: priority unknown : %d\n",
5201 /* Request Return Receipt */
5202 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
5203 if (compose->return_receipt) {
5204 if (compose->account->name
5205 && *compose->account->name) {
5206 compose_convert_header(compose, buf, sizeof(buf),
5207 compose->account->name,
5208 strlen("Disposition-Notification-To: "),
5210 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
5212 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
5216 /* get special headers */
5217 for (list = compose->header_list; list; list = list->next) {
5218 ComposeHeaderEntry *headerentry;
5221 gchar *headername_wcolon;
5222 gchar *headername_trans;
5225 gboolean standard_header = FALSE;
5227 headerentry = ((ComposeHeaderEntry *)list->data);
5229 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
5230 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
5235 if (!strstr(tmp, ":")) {
5236 headername_wcolon = g_strconcat(tmp, ":", NULL);
5237 headername = g_strdup(tmp);
5239 headername_wcolon = g_strdup(tmp);
5240 headername = g_strdup(strtok(tmp, ":"));
5244 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
5245 Xstrdup_a(headervalue, entry_str, return NULL);
5246 subst_char(headervalue, '\r', ' ');
5247 subst_char(headervalue, '\n', ' ');
5248 string = std_headers;
5249 while (*string != NULL) {
5250 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
5251 if (!strcmp(headername_trans,headername_wcolon))
5252 standard_header = TRUE;
5255 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
5256 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
5259 g_free(headername_wcolon);
5263 g_string_free(header, FALSE);
5268 #undef IS_IN_CUSTOM_HEADER
5270 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
5271 gint header_len, gboolean addr_field)
5273 gchar *tmpstr = NULL;
5274 const gchar *out_codeset = NULL;
5276 g_return_if_fail(src != NULL);
5277 g_return_if_fail(dest != NULL);
5279 if (len < 1) return;
5281 tmpstr = g_strdup(src);
5283 subst_char(tmpstr, '\n', ' ');
5284 subst_char(tmpstr, '\r', ' ');
5287 if (!g_utf8_validate(tmpstr, -1, NULL)) {
5288 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
5289 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
5294 codeconv_set_strict(TRUE);
5295 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5296 conv_get_charset_str(compose->out_encoding));
5297 codeconv_set_strict(FALSE);
5299 if (!dest || *dest == '\0') {
5300 gchar *test_conv_global_out = NULL;
5301 gchar *test_conv_reply = NULL;
5303 /* automatic mode. be automatic. */
5304 codeconv_set_strict(TRUE);
5306 out_codeset = conv_get_outgoing_charset_str();
5308 debug_print("trying to convert to %s\n", out_codeset);
5309 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5312 if (!test_conv_global_out && compose->orig_charset
5313 && strcmp(compose->orig_charset, CS_US_ASCII)) {
5314 out_codeset = compose->orig_charset;
5315 debug_print("failure; trying to convert to %s\n", out_codeset);
5316 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
5319 if (!test_conv_global_out && !test_conv_reply) {
5321 out_codeset = CS_INTERNAL;
5322 debug_print("finally using %s\n", out_codeset);
5324 g_free(test_conv_global_out);
5325 g_free(test_conv_reply);
5326 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
5328 codeconv_set_strict(FALSE);
5333 static void compose_create_header_entry(Compose *compose)
5335 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
5339 GList *combo_list = NULL;
5341 const gchar *header = NULL;
5342 ComposeHeaderEntry *headerentry;
5343 gboolean standard_header = FALSE;
5345 headerentry = g_new0(ComposeHeaderEntry, 1);
5348 combo = gtk_combo_new();
5350 while(*string != NULL) {
5351 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
5354 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
5355 g_list_free(combo_list);
5356 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
5357 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5358 G_CALLBACK(compose_grab_focus_cb), compose);
5359 gtk_widget_show(combo);
5360 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
5361 if (compose->header_last) {
5362 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5364 while (*string != NULL) {
5365 if (!strcmp(*string, last_header_entry))
5366 standard_header = TRUE;
5369 if (standard_header)
5370 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
5372 if (!compose->header_last || !standard_header) {
5373 switch(compose->account->protocol) {
5375 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
5378 header = prefs_common.trans_hdr ? _("To:") : "To:";
5383 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
5385 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
5386 G_CALLBACK(compose_grab_focus_cb), compose);
5389 entry = gtk_entry_new();
5390 gtk_widget_show(entry);
5391 gtk_tooltips_set_tip(compose->tooltips, entry,
5392 _("Use <tab> to autocomplete from addressbook"), NULL);
5393 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);
5395 g_signal_connect(G_OBJECT(entry), "key-press-event",
5396 G_CALLBACK(compose_headerentry_key_press_event_cb),
5398 g_signal_connect(G_OBJECT(entry), "changed",
5399 G_CALLBACK(compose_headerentry_changed_cb),
5401 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
5402 G_CALLBACK(compose_grab_focus_cb), compose);
5405 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5406 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5407 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5408 g_signal_connect(G_OBJECT(entry), "drag_data_received",
5409 G_CALLBACK(compose_header_drag_received_cb),
5411 g_signal_connect(G_OBJECT(entry), "drag-drop",
5412 G_CALLBACK(compose_drag_drop),
5415 address_completion_register_entry(GTK_ENTRY(entry));
5417 headerentry->compose = compose;
5418 headerentry->combo = combo;
5419 headerentry->entry = entry;
5420 headerentry->headernum = compose->header_nextrow;
5422 compose->header_nextrow++;
5423 compose->header_last = headerentry;
5426 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
5428 ComposeHeaderEntry *last_header;
5430 last_header = compose->header_last;
5432 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
5433 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
5436 static GtkWidget *compose_create_header(Compose *compose)
5438 GtkWidget *from_optmenu_hbox;
5439 GtkWidget *header_scrolledwin;
5440 GtkWidget *header_table;
5444 /* header labels and entries */
5445 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5446 gtk_widget_show(header_scrolledwin);
5447 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
5449 header_table = gtk_table_new(2, 2, FALSE);
5450 gtk_widget_show(header_table);
5451 gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
5452 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5453 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5456 /* option menu for selecting accounts */
5457 from_optmenu_hbox = compose_account_option_menu_create(compose);
5458 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5459 0, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5462 compose->header_table = header_table;
5463 compose->header_list = NULL;
5464 compose->header_nextrow = count;
5466 compose_create_header_entry(compose);
5468 compose->table = NULL;
5470 return header_scrolledwin ;
5473 GtkWidget *compose_create_attach(Compose *compose)
5475 GtkWidget *attach_scrwin;
5476 GtkWidget *attach_clist;
5478 GtkListStore *store;
5479 GtkCellRenderer *renderer;
5480 GtkTreeViewColumn *column;
5481 GtkTreeSelection *selection;
5483 /* attachment list */
5484 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5485 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5486 GTK_POLICY_AUTOMATIC,
5487 GTK_POLICY_AUTOMATIC);
5488 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5490 store = gtk_list_store_new(N_ATTACH_COLS,
5495 G_TYPE_AUTO_POINTER,
5497 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5498 (GTK_TREE_MODEL(store)));
5499 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5500 g_object_unref(store);
5502 renderer = gtk_cell_renderer_text_new();
5503 column = gtk_tree_view_column_new_with_attributes
5504 (_("Mime type"), renderer, "text",
5505 COL_MIMETYPE, NULL);
5506 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5508 renderer = gtk_cell_renderer_text_new();
5509 column = gtk_tree_view_column_new_with_attributes
5510 (_("Size"), renderer, "text",
5512 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5514 renderer = gtk_cell_renderer_text_new();
5515 column = gtk_tree_view_column_new_with_attributes
5516 (_("Name"), renderer, "text",
5518 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5520 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5521 prefs_common.enable_rules_hint);
5522 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5523 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5525 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5526 G_CALLBACK(attach_selected), compose);
5527 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5528 G_CALLBACK(attach_button_pressed), compose);
5529 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5530 G_CALLBACK(attach_key_pressed), compose);
5533 gtk_drag_dest_set(attach_clist,
5534 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5535 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5536 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5537 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5538 G_CALLBACK(compose_attach_drag_received_cb),
5540 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5541 G_CALLBACK(compose_drag_drop),
5544 compose->attach_scrwin = attach_scrwin;
5545 compose->attach_clist = attach_clist;
5547 return attach_scrwin;
5550 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5551 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5553 static GtkWidget *compose_create_others(Compose *compose)
5556 GtkWidget *savemsg_checkbtn;
5557 GtkWidget *savemsg_entry;
5558 GtkWidget *savemsg_select;
5561 gchar *folderidentifier;
5563 /* Table for settings */
5564 table = gtk_table_new(3, 1, FALSE);
5565 gtk_container_set_border_width(GTK_CONTAINER(table), BORDER_WIDTH);
5566 gtk_widget_show(table);
5567 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5570 /* Save Message to folder */
5571 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5572 gtk_widget_show(savemsg_checkbtn);
5573 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5574 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5575 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5577 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5578 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5580 savemsg_entry = gtk_entry_new();
5581 gtk_widget_show(savemsg_entry);
5582 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5583 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5584 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5585 G_CALLBACK(compose_grab_focus_cb), compose);
5586 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5587 folderidentifier = folder_item_get_identifier(account_get_special_folder
5588 (compose->account, F_OUTBOX));
5589 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5590 g_free(folderidentifier);
5593 savemsg_select = gtkut_get_browse_file_btn(_("_Browse"));
5594 gtk_widget_show(savemsg_select);
5595 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5596 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5597 G_CALLBACK(compose_savemsg_select_cb),
5602 compose->savemsg_checkbtn = savemsg_checkbtn;
5603 compose->savemsg_entry = savemsg_entry;
5608 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5610 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5611 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5614 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5619 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5622 path = folder_item_get_identifier(dest);
5624 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5628 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5629 GdkAtom clip, GtkTextIter *insert_place);
5631 #define BLOCK_WRAP() { \
5632 prev_autowrap = compose->autowrap; \
5633 buffer = gtk_text_view_get_buffer( \
5634 GTK_TEXT_VIEW(compose->text)); \
5635 compose->autowrap = FALSE; \
5637 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5638 G_CALLBACK(compose_changed_cb), \
5640 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5641 G_CALLBACK(text_inserted), \
5644 #define UNBLOCK_WRAP() { \
5645 compose->autowrap = prev_autowrap; \
5646 if (compose->autowrap) \
5647 compose_wrap_all(compose); \
5649 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5650 G_CALLBACK(compose_changed_cb), \
5652 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5653 G_CALLBACK(text_inserted), \
5658 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5662 GtkTextBuffer *buffer;
5664 if (event->button == 3) {
5666 GtkTextIter sel_start, sel_end;
5667 gboolean stuff_selected;
5669 /* move the cursor to allow GtkAspell to check the word
5670 * under the mouse */
5671 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5672 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5674 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5677 stuff_selected = gtk_text_buffer_get_selection_bounds(
5678 GTK_TEXT_VIEW(text)->buffer,
5679 &sel_start, &sel_end);
5681 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5682 /* reselect stuff */
5684 && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
5685 gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
5686 &sel_start, &sel_end);
5688 return FALSE; /* pass the event so that the right-click goes through */
5691 if (event->button == 2) {
5696 /* get the middle-click position to paste at the correct place */
5697 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5698 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5700 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5703 entry_paste_clipboard(compose, text,
5704 prefs_common.linewrap_pastes,
5705 GDK_SELECTION_PRIMARY, &iter);
5713 static void compose_spell_menu_changed(void *data)
5715 Compose *compose = (Compose *)data;
5717 GtkWidget *menuitem;
5718 GtkWidget *parent_item;
5719 GtkMenu *menu = GTK_MENU(gtk_menu_new());
5720 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
5723 if (compose->gtkaspell == NULL)
5726 parent_item = gtk_item_factory_get_item(ifactory,
5727 "/Spelling/Options");
5729 /* setting the submenu removes /Spelling/Options from the factory
5730 * so we need to save it */
5732 if (parent_item == NULL) {
5733 parent_item = compose->aspell_options_menu;
5734 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(parent_item));
5736 compose->aspell_options_menu = parent_item;
5738 spell_menu = gtkaspell_make_config_menu(compose->gtkaspell);
5740 spell_menu = g_slist_reverse(spell_menu);
5741 for (items = spell_menu;
5742 items; items = items->next) {
5743 menuitem = GTK_WIDGET(GTK_MENU_ITEM(items->data));
5744 gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), GTK_WIDGET(menuitem));
5745 gtk_widget_show(GTK_WIDGET(menuitem));
5747 g_slist_free(spell_menu);
5749 gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), GTK_WIDGET(menu));
5754 static gboolean compose_force_window_origin = TRUE;
5755 static Compose *compose_create(PrefsAccount *account, ComposeMode mode,
5762 GtkWidget *handlebox;
5764 GtkWidget *notebook;
5769 GtkWidget *subject_hbox;
5770 GtkWidget *subject_frame;
5771 GtkWidget *subject_entry;
5775 GtkWidget *edit_vbox;
5776 GtkWidget *ruler_hbox;
5778 GtkWidget *scrolledwin;
5780 GtkTextBuffer *buffer;
5781 GtkClipboard *clipboard;
5783 UndoMain *undostruct;
5785 gchar *titles[N_ATTACH_COLS];
5786 guint n_menu_entries;
5787 GtkWidget *popupmenu;
5788 GtkItemFactory *popupfactory;
5789 GtkItemFactory *ifactory;
5790 GtkWidget *tmpl_menu;
5792 GtkWidget *menuitem;
5795 GtkAspell * gtkaspell = NULL;
5798 static GdkGeometry geometry;
5800 g_return_val_if_fail(account != NULL, NULL);
5802 debug_print("Creating compose window...\n");
5803 compose = g_new0(Compose, 1);
5805 titles[COL_MIMETYPE] = _("MIME type");
5806 titles[COL_SIZE] = _("Size");
5807 titles[COL_NAME] = _("Name");
5809 compose->batch = batch;
5810 compose->account = account;
5812 compose->mutex = g_mutex_new();
5813 compose->set_cursor_pos = -1;
5815 compose->tooltips = gtk_tooltips_new();
5817 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5818 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5819 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5821 if (!geometry.max_width) {
5822 geometry.max_width = gdk_screen_width();
5823 geometry.max_height = gdk_screen_height();
5826 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5827 &geometry, GDK_HINT_MAX_SIZE);
5828 if (!geometry.min_width) {
5829 geometry.min_width = 600;
5830 geometry.min_height = 480;
5832 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5833 &geometry, GDK_HINT_MIN_SIZE);
5835 if (compose_force_window_origin)
5836 gtk_widget_set_uposition(window, prefs_common.compose_x,
5837 prefs_common.compose_y);
5839 g_signal_connect(G_OBJECT(window), "delete_event",
5840 G_CALLBACK(compose_delete_cb), compose);
5841 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5842 gtk_widget_realize(window);
5844 gtkut_widget_set_composer_icon(window);
5846 vbox = gtk_vbox_new(FALSE, 0);
5847 gtk_container_add(GTK_CONTAINER(window), vbox);
5849 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5850 menubar = menubar_create(window, compose_entries,
5851 n_menu_entries, "<Compose>", compose);
5852 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5854 if (prefs_common.toolbar_detachable) {
5855 handlebox = gtk_handle_box_new();
5857 handlebox = gtk_hbox_new(FALSE, 0);
5859 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5861 gtk_widget_realize(handlebox);
5862 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5865 vbox2 = gtk_vbox_new(FALSE, 2);
5866 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5867 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5870 notebook = gtk_notebook_new();
5871 gtk_widget_set_size_request(notebook, -1, 130);
5872 gtk_widget_show(notebook);
5874 /* header labels and entries */
5875 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5876 compose_create_header(compose),
5877 gtk_label_new_with_mnemonic(_("Hea_der")));
5878 /* attachment list */
5879 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5880 compose_create_attach(compose),
5881 gtk_label_new_with_mnemonic(_("_Attachments")));
5883 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
5884 compose_create_others(compose),
5885 gtk_label_new_with_mnemonic(_("Othe_rs")));
5888 subject_hbox = gtk_hbox_new(FALSE, 0);
5889 gtk_widget_show(subject_hbox);
5891 subject_frame = gtk_frame_new(NULL);
5892 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5893 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5894 gtk_widget_show(subject_frame);
5896 subject = gtk_hbox_new(FALSE, 0);
5897 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5898 gtk_widget_show(subject);
5900 label = gtk_label_new(_("Subject:"));
5901 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5902 gtk_widget_show(label);
5904 subject_entry = gtk_entry_new();
5905 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5906 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5907 G_CALLBACK(compose_grab_focus_cb), compose);
5908 gtk_widget_show(subject_entry);
5909 compose->subject_entry = subject_entry;
5910 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5912 edit_vbox = gtk_vbox_new(FALSE, 0);
5914 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5917 ruler_hbox = gtk_hbox_new(FALSE, 0);
5918 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5920 ruler = gtk_shruler_new();
5921 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5922 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5926 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5927 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5928 GTK_POLICY_AUTOMATIC,
5929 GTK_POLICY_AUTOMATIC);
5930 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5932 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5933 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5935 text = gtk_text_view_new();
5936 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5937 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5938 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5939 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5940 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5942 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5944 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5945 G_CALLBACK(compose_edit_size_alloc),
5947 g_signal_connect(G_OBJECT(buffer), "changed",
5948 G_CALLBACK(compose_changed_cb), compose);
5949 g_signal_connect(G_OBJECT(text), "grab_focus",
5950 G_CALLBACK(compose_grab_focus_cb), compose);
5951 g_signal_connect(G_OBJECT(buffer), "insert_text",
5952 G_CALLBACK(text_inserted), compose);
5953 g_signal_connect(G_OBJECT(text), "button_press_event",
5954 G_CALLBACK(text_clicked), compose);
5955 g_signal_connect(G_OBJECT(subject_entry), "changed",
5956 G_CALLBACK(compose_changed_cb), compose);
5959 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5960 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5961 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5962 g_signal_connect(G_OBJECT(text), "drag_data_received",
5963 G_CALLBACK(compose_insert_drag_received_cb),
5965 g_signal_connect(G_OBJECT(text), "drag-drop",
5966 G_CALLBACK(compose_drag_drop),
5968 gtk_widget_show_all(vbox);
5970 /* pane between attach clist and text */
5971 paned = gtk_vpaned_new();
5972 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5973 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5974 gtk_paned_add1(GTK_PANED(paned), notebook);
5975 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5976 gtk_widget_show_all(paned);
5979 if (prefs_common.textfont) {
5980 PangoFontDescription *font_desc;
5982 font_desc = pango_font_description_from_string
5983 (prefs_common.textfont);
5985 gtk_widget_modify_font(text, font_desc);
5986 pango_font_description_free(font_desc);
5990 n_entries = sizeof(compose_popup_entries) /
5991 sizeof(compose_popup_entries[0]);
5992 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5993 "<Compose>", &popupfactory,
5996 ifactory = gtk_item_factory_from_widget(menubar);
5997 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5998 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5999 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
6001 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6003 undostruct = undo_init(text);
6004 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
6007 address_completion_start(window);
6009 compose->window = window;
6010 compose->vbox = vbox;
6011 compose->menubar = menubar;
6012 compose->handlebox = handlebox;
6014 compose->vbox2 = vbox2;
6016 compose->paned = paned;
6018 compose->edit_vbox = edit_vbox;
6019 compose->ruler_hbox = ruler_hbox;
6020 compose->ruler = ruler;
6021 compose->scrolledwin = scrolledwin;
6022 compose->text = text;
6024 compose->focused_editable = NULL;
6026 compose->popupmenu = popupmenu;
6027 compose->popupfactory = popupfactory;
6029 compose->tmpl_menu = tmpl_menu;
6031 compose->mode = mode;
6033 compose->targetinfo = NULL;
6034 compose->replyinfo = NULL;
6035 compose->fwdinfo = NULL;
6037 compose->replyto = NULL;
6039 compose->bcc = NULL;
6040 compose->followup_to = NULL;
6042 compose->ml_post = NULL;
6044 compose->inreplyto = NULL;
6045 compose->references = NULL;
6046 compose->msgid = NULL;
6047 compose->boundary = NULL;
6049 compose->autowrap = prefs_common.autowrap;
6051 compose->use_signing = FALSE;
6052 compose->use_encryption = FALSE;
6053 compose->privacy_system = NULL;
6055 compose->modified = FALSE;
6057 compose->return_receipt = FALSE;
6059 compose->to_list = NULL;
6060 compose->newsgroup_list = NULL;
6062 compose->undostruct = undostruct;
6064 compose->sig_str = NULL;
6066 compose->exteditor_file = NULL;
6067 compose->exteditor_pid = -1;
6068 compose->exteditor_tag = -1;
6069 compose->draft_timeout_tag = -1;
6072 menu_set_sensitive(ifactory, "/Spelling", FALSE);
6073 if (mode != COMPOSE_REDIRECT) {
6074 if (prefs_common.enable_aspell && prefs_common.dictionary &&
6075 strcmp(prefs_common.dictionary, "")) {
6076 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
6077 prefs_common.dictionary,
6078 conv_get_locale_charset_str(),
6079 prefs_common.misspelled_col,
6080 prefs_common.check_while_typing,
6081 prefs_common.recheck_when_changing_dict,
6082 prefs_common.use_alternate,
6083 GTK_TEXT_VIEW(text),
6084 GTK_WINDOW(compose->window),
6085 compose_spell_menu_changed,
6088 alertpanel_error(_("Spell checker could not "
6090 gtkaspell_checkers_strerror());
6091 gtkaspell_checkers_reset_error();
6093 if (!gtkaspell_set_sug_mode(gtkaspell,
6094 prefs_common.aspell_sugmode)) {
6095 debug_print("Aspell: could not set "
6096 "suggestion mode %s\n",
6097 gtkaspell_checkers_strerror());
6098 gtkaspell_checkers_reset_error();
6101 menu_set_sensitive(ifactory, "/Spelling", TRUE);
6105 compose->gtkaspell = gtkaspell;
6106 compose_spell_menu_changed(compose);
6109 compose_select_account(compose, account, TRUE);
6111 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
6112 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
6113 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
6115 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
6116 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
6118 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
6119 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
6122 if (account->protocol != A_NNTP)
6123 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
6125 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
6127 addressbook_set_target_compose(compose);
6129 if (mode != COMPOSE_REDIRECT)
6130 compose_set_template_menu(compose);
6132 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
6133 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
6136 compose_list = g_list_append(compose_list, compose);
6138 if (!prefs_common.show_ruler)
6139 gtk_widget_hide(ruler_hbox);
6141 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
6142 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
6143 prefs_common.show_ruler);
6146 compose->priority = PRIORITY_NORMAL;
6147 compose_update_priority_menu_item(compose);
6149 compose_set_out_encoding(compose);
6152 compose_update_actions_menu(compose);
6154 /* Privacy Systems menu */
6155 compose_update_privacy_systems_menu(compose);
6157 activate_privacy_system(compose, account, TRUE);
6158 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
6160 gtk_widget_realize(window);
6162 gtk_widget_show(window);
6168 static GtkWidget *compose_account_option_menu_create(Compose *compose)
6173 GtkWidget *optmenubox;
6176 GtkWidget *from_name = NULL;
6178 gint num = 0, def_menu = 0;
6180 accounts = account_get_list();
6181 g_return_val_if_fail(accounts != NULL, NULL);
6183 optmenubox = gtk_event_box_new();
6184 optmenu = gtkut_sc_combobox_create(optmenubox, FALSE);
6185 menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
6187 hbox = gtk_hbox_new(FALSE, 6);
6188 from_name = gtk_entry_new();
6190 g_signal_connect_after(G_OBJECT(from_name), "grab_focus",
6191 G_CALLBACK(compose_grab_focus_cb), compose);
6193 for (; accounts != NULL; accounts = accounts->next, num++) {
6194 PrefsAccount *ac = (PrefsAccount *)accounts->data;
6195 gchar *name, *from = NULL;
6197 if (ac == compose->account) def_menu = num;
6199 name = g_markup_printf_escaped(_("From: <i>%s</i>"),
6202 if (ac == compose->account) {
6203 if (ac->name && *ac->name) {
6205 QUOTE_IF_REQUIRED_NORMAL(buf, ac->name, return NULL);
6206 from = g_strdup_printf("%s <%s>",
6208 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6210 from = g_strdup_printf("%s",
6212 gtk_entry_set_text(GTK_ENTRY(from_name), from);
6215 COMBOBOX_ADD(menu, name, ac->account_id);
6220 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), def_menu);
6222 g_signal_connect(G_OBJECT(optmenu), "changed",
6223 G_CALLBACK(account_activated),
6226 gtk_box_pack_start(GTK_BOX(hbox), optmenubox, FALSE, FALSE, 0);
6227 gtk_box_pack_start(GTK_BOX(hbox), from_name, TRUE, TRUE, 0);
6229 gtk_tooltips_set_tip(compose->tooltips, optmenubox,
6230 _("Account to use for this email"), NULL);
6231 gtk_tooltips_set_tip(compose->tooltips, from_name,
6232 _("Sender address to be used"), NULL);
6234 compose->from_name = from_name;
6239 static void compose_set_priority_cb(gpointer data,
6243 Compose *compose = (Compose *) data;
6244 compose->priority = action;
6247 static void compose_update_priority_menu_item(Compose * compose)
6249 GtkItemFactory *ifactory;
6250 GtkWidget *menuitem = NULL;
6252 ifactory = gtk_item_factory_from_widget(compose->menubar);
6254 switch (compose->priority) {
6255 case PRIORITY_HIGHEST:
6256 menuitem = gtk_item_factory_get_item
6257 (ifactory, "/Options/Priority/Highest");
6260 menuitem = gtk_item_factory_get_item
6261 (ifactory, "/Options/Priority/High");
6263 case PRIORITY_NORMAL:
6264 menuitem = gtk_item_factory_get_item
6265 (ifactory, "/Options/Priority/Normal");
6268 menuitem = gtk_item_factory_get_item
6269 (ifactory, "/Options/Priority/Low");
6271 case PRIORITY_LOWEST:
6272 menuitem = gtk_item_factory_get_item
6273 (ifactory, "/Options/Priority/Lowest");
6276 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6279 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
6281 Compose *compose = (Compose *) data;
6283 GtkItemFactory *ifactory;
6284 gboolean can_sign = FALSE, can_encrypt = FALSE;
6286 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
6288 if (!GTK_CHECK_MENU_ITEM(widget)->active)
6291 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
6292 g_free(compose->privacy_system);
6293 compose->privacy_system = NULL;
6294 if (systemid != NULL) {
6295 compose->privacy_system = g_strdup(systemid);
6297 can_sign = privacy_system_can_sign(systemid);
6298 can_encrypt = privacy_system_can_encrypt(systemid);
6301 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
6303 ifactory = gtk_item_factory_from_widget(compose->menubar);
6304 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6305 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6308 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
6310 static gchar *branch_path = "/Options/Privacy System";
6311 GtkItemFactory *ifactory;
6312 GtkWidget *menuitem = NULL;
6314 gboolean can_sign = FALSE, can_encrypt = FALSE;
6315 gboolean found = FALSE;
6317 ifactory = gtk_item_factory_from_widget(compose->menubar);
6319 if (compose->privacy_system != NULL) {
6322 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6323 g_return_if_fail(menuitem != NULL);
6325 amenu = GTK_MENU_SHELL(menuitem)->children;
6327 while (amenu != NULL) {
6328 GList *alist = amenu->next;
6330 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
6331 if (systemid != NULL) {
6332 if (strcmp(systemid, compose->privacy_system) == 0) {
6333 menuitem = GTK_WIDGET(amenu->data);
6335 can_sign = privacy_system_can_sign(systemid);
6336 can_encrypt = privacy_system_can_encrypt(systemid);
6340 } else if (strlen(compose->privacy_system) == 0) {
6341 menuitem = GTK_WIDGET(amenu->data);
6344 can_encrypt = FALSE;
6351 if (menuitem != NULL)
6352 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6354 if (warn && !found && strlen(compose->privacy_system)) {
6355 gchar *tmp = g_strdup_printf(
6356 _("The privacy system '%s' cannot be loaded. You "
6357 "will not be able to sign or encrypt this message."),
6358 compose->privacy_system);
6359 alertpanel_warning(tmp);
6364 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
6365 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
6368 static void compose_set_out_encoding(Compose *compose)
6370 GtkItemFactoryEntry *entry;
6371 GtkItemFactory *ifactory;
6372 CharSet out_encoding;
6373 gchar *path, *p, *q;
6376 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
6377 ifactory = gtk_item_factory_from_widget(compose->menubar);
6379 for (entry = compose_entries; entry->callback != compose_address_cb;
6381 if (entry->callback == compose_set_encoding_cb &&
6382 (CharSet)entry->callback_action == out_encoding) {
6383 p = q = path = g_strdup(entry->path);
6395 item = gtk_item_factory_get_item(ifactory, path);
6396 gtk_widget_activate(item);
6403 static void compose_set_template_menu(Compose *compose)
6405 GSList *tmpl_list, *cur;
6409 tmpl_list = template_get_config();
6411 menu = gtk_menu_new();
6413 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
6414 Template *tmpl = (Template *)cur->data;
6416 item = gtk_menu_item_new_with_label(tmpl->name);
6417 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
6418 g_signal_connect(G_OBJECT(item), "activate",
6419 G_CALLBACK(compose_template_activate_cb),
6421 g_object_set_data(G_OBJECT(item), "template", tmpl);
6422 gtk_widget_show(item);
6425 gtk_widget_show(menu);
6426 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
6429 void compose_update_actions_menu(Compose *compose)
6431 GtkItemFactory *ifactory;
6433 ifactory = gtk_item_factory_from_widget(compose->menubar);
6434 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
6437 void compose_update_privacy_systems_menu(Compose *compose)
6439 static gchar *branch_path = "/Options/Privacy System";
6440 GtkItemFactory *ifactory;
6441 GtkWidget *menuitem;
6442 GSList *systems, *cur;
6445 GtkWidget *system_none;
6448 ifactory = gtk_item_factory_from_widget(compose->menubar);
6450 /* remove old entries */
6451 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
6452 g_return_if_fail(menuitem != NULL);
6454 amenu = GTK_MENU_SHELL(menuitem)->children->next;
6455 while (amenu != NULL) {
6456 GList *alist = amenu->next;
6457 gtk_widget_destroy(GTK_WIDGET(amenu->data));
6461 system_none = gtk_item_factory_get_widget(ifactory,
6462 "/Options/Privacy System/None");
6464 g_signal_connect(G_OBJECT(system_none), "activate",
6465 G_CALLBACK(compose_set_privacy_system_cb), compose);
6467 systems = privacy_get_system_ids();
6468 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
6469 gchar *systemid = cur->data;
6471 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
6472 widget = gtk_radio_menu_item_new_with_label(group,
6473 privacy_system_get_name(systemid));
6474 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
6475 g_strdup(systemid), g_free);
6476 g_signal_connect(G_OBJECT(widget), "activate",
6477 G_CALLBACK(compose_set_privacy_system_cb), compose);
6479 gtk_menu_append(GTK_MENU(system_none->parent), widget);
6480 gtk_widget_show(widget);
6483 g_slist_free(systems);
6486 void compose_reflect_prefs_all(void)
6491 for (cur = compose_list; cur != NULL; cur = cur->next) {
6492 compose = (Compose *)cur->data;
6493 compose_set_template_menu(compose);
6497 void compose_reflect_prefs_pixmap_theme(void)
6502 for (cur = compose_list; cur != NULL; cur = cur->next) {
6503 compose = (Compose *)cur->data;
6504 toolbar_update(TOOLBAR_COMPOSE, compose);
6508 static void compose_template_apply(Compose *compose, Template *tmpl,
6512 GtkTextBuffer *buffer;
6516 gchar *parsed_str = NULL;
6517 gint cursor_pos = 0;
6520 /* process the body */
6522 text = GTK_TEXT_VIEW(compose->text);
6523 buffer = gtk_text_view_get_buffer(text);
6526 gtk_text_buffer_set_text(buffer, "", -1);
6528 mark = gtk_text_buffer_get_insert(buffer);
6529 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
6532 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
6533 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
6536 if (prefs_common.quotemark && *prefs_common.quotemark)
6537 qmark = prefs_common.quotemark;
6541 if (compose->replyinfo != NULL)
6542 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
6543 tmpl->value, qmark, NULL, FALSE);
6544 else if (compose->fwdinfo != NULL)
6545 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6546 tmpl->value, qmark, NULL, FALSE);
6551 if (replace && parsed_str && compose->account->auto_sig)
6552 compose_insert_sig(compose, FALSE);
6554 if (replace && parsed_str) {
6555 gtk_text_buffer_get_start_iter(buffer, &iter);
6556 gtk_text_buffer_place_cursor(buffer, &iter);
6560 cursor_pos = quote_fmt_get_cursor_pos();
6561 compose->set_cursor_pos = cursor_pos;
6562 if (cursor_pos == -1)
6564 gtk_text_buffer_get_start_iter(buffer, &iter);
6565 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6566 gtk_text_buffer_place_cursor(buffer, &iter);
6569 /* process the other fields */
6570 compose_template_apply_fields(compose, tmpl);
6572 compose_changed_cb(NULL, compose);
6575 void compose_template_apply_fields(Compose *compose, Template *tmpl)
6577 static MsgInfo dummyinfo;
6578 MsgInfo *msginfo = NULL;
6581 if (compose->replyinfo != NULL)
6582 msginfo = compose->replyinfo;
6583 else if (compose->fwdinfo != NULL)
6584 msginfo = compose->fwdinfo;
6586 msginfo = &dummyinfo;
6588 if (tmpl->to && *tmpl->to != '\0') {
6589 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6590 quote_fmt_scan_string(tmpl->to);
6593 buf = quote_fmt_get_buffer();
6595 alertpanel_error(_("Message To format error."));
6597 compose_entry_append(compose, buf, COMPOSE_TO);
6601 if (tmpl->cc && *tmpl->cc != '\0') {
6602 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6603 quote_fmt_scan_string(tmpl->cc);
6606 buf = quote_fmt_get_buffer();
6608 alertpanel_error(_("Message Cc format error."));
6610 compose_entry_append(compose, buf, COMPOSE_CC);
6614 if (tmpl->bcc && *tmpl->bcc != '\0') {
6615 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6616 quote_fmt_scan_string(tmpl->bcc);
6619 buf = quote_fmt_get_buffer();
6621 alertpanel_error(_("Message Bcc format error."));
6623 compose_entry_append(compose, buf, COMPOSE_BCC);
6627 /* process the subject */
6628 if (tmpl->subject && *tmpl->subject != '\0') {
6629 quote_fmt_init(msginfo, NULL, NULL, FALSE);
6630 quote_fmt_scan_string(tmpl->subject);
6633 buf = quote_fmt_get_buffer();
6635 alertpanel_error(_("Message subject format error."));
6637 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
6642 static void compose_destroy(Compose *compose)
6644 compose_list = g_list_remove(compose_list, compose);
6646 if (compose->updating) {
6647 debug_print("danger, not destroying anything now\n");
6648 compose->deferred_destroy = TRUE;
6651 /* NOTE: address_completion_end() does nothing with the window
6652 * however this may change. */
6653 address_completion_end(compose->window);
6655 slist_free_strings(compose->to_list);
6656 g_slist_free(compose->to_list);
6657 slist_free_strings(compose->newsgroup_list);
6658 g_slist_free(compose->newsgroup_list);
6659 slist_free_strings(compose->header_list);
6660 g_slist_free(compose->header_list);
6662 procmsg_msginfo_free(compose->targetinfo);
6663 procmsg_msginfo_free(compose->replyinfo);
6664 procmsg_msginfo_free(compose->fwdinfo);
6666 g_free(compose->replyto);
6667 g_free(compose->cc);
6668 g_free(compose->bcc);
6669 g_free(compose->newsgroups);
6670 g_free(compose->followup_to);
6672 g_free(compose->ml_post);
6674 g_free(compose->inreplyto);
6675 g_free(compose->references);
6676 g_free(compose->msgid);
6677 g_free(compose->boundary);
6679 g_free(compose->redirect_filename);
6680 if (compose->undostruct)
6681 undo_destroy(compose->undostruct);
6683 g_free(compose->sig_str);
6685 g_free(compose->exteditor_file);
6687 g_free(compose->orig_charset);
6689 g_free(compose->privacy_system);
6691 if (addressbook_get_target_compose() == compose)
6692 addressbook_set_target_compose(NULL);
6695 if (compose->gtkaspell) {
6696 gtkaspell_delete(compose->gtkaspell);
6697 compose->gtkaspell = NULL;
6701 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6702 prefs_common.compose_height = compose->window->allocation.height;
6704 if (!gtk_widget_get_parent(compose->paned))
6705 gtk_widget_destroy(compose->paned);
6706 gtk_widget_destroy(compose->popupmenu);
6708 gtk_widget_destroy(compose->window);
6709 toolbar_destroy(compose->toolbar);
6710 g_free(compose->toolbar);
6711 g_mutex_free(compose->mutex);
6715 static void compose_attach_info_free(AttachInfo *ainfo)
6717 g_free(ainfo->file);
6718 g_free(ainfo->content_type);
6719 g_free(ainfo->name);
6723 static void compose_attach_remove_selected(Compose *compose)
6725 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6726 GtkTreeSelection *selection;
6728 GtkTreeModel *model;
6730 selection = gtk_tree_view_get_selection(tree_view);
6731 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6736 for (cur = sel; cur != NULL; cur = cur->next) {
6737 GtkTreePath *path = cur->data;
6738 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6741 gtk_tree_path_free(path);
6744 for (cur = sel; cur != NULL; cur = cur->next) {
6745 GtkTreeRowReference *ref = cur->data;
6746 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6749 if (gtk_tree_model_get_iter(model, &iter, path))
6750 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6752 gtk_tree_path_free(path);
6753 gtk_tree_row_reference_free(ref);
6759 static struct _AttachProperty
6762 GtkWidget *mimetype_entry;
6763 GtkWidget *encoding_optmenu;
6764 GtkWidget *path_entry;
6765 GtkWidget *filename_entry;
6767 GtkWidget *cancel_btn;
6770 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6772 gtk_tree_path_free((GtkTreePath *)ptr);
6775 static void compose_attach_property(Compose *compose)
6777 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6779 GtkComboBox *optmenu;
6780 GtkTreeSelection *selection;
6782 GtkTreeModel *model;
6785 static gboolean cancelled;
6787 /* only if one selected */
6788 selection = gtk_tree_view_get_selection(tree_view);
6789 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6792 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6796 path = (GtkTreePath *) sel->data;
6797 gtk_tree_model_get_iter(model, &iter, path);
6798 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6801 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6807 if (!attach_prop.window)
6808 compose_attach_property_create(&cancelled);
6809 gtk_widget_grab_focus(attach_prop.ok_btn);
6810 gtk_widget_show(attach_prop.window);
6811 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6813 optmenu = GTK_COMBO_BOX(attach_prop.encoding_optmenu);
6814 if (ainfo->encoding == ENC_UNKNOWN)
6815 combobox_select_by_data(optmenu, ENC_BASE64);
6817 combobox_select_by_data(optmenu, ainfo->encoding);
6819 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6820 ainfo->content_type ? ainfo->content_type : "");
6821 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6822 ainfo->file ? ainfo->file : "");
6823 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6824 ainfo->name ? ainfo->name : "");
6827 const gchar *entry_text;
6829 gchar *cnttype = NULL;
6836 gtk_widget_hide(attach_prop.window);
6841 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6842 if (*entry_text != '\0') {
6845 text = g_strstrip(g_strdup(entry_text));
6846 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6847 cnttype = g_strdup(text);
6850 alertpanel_error(_("Invalid MIME type."));
6856 ainfo->encoding = combobox_get_active_data(optmenu);
6858 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6859 if (*entry_text != '\0') {
6860 if (is_file_exist(entry_text) &&
6861 (size = get_file_size(entry_text)) > 0)
6862 file = g_strdup(entry_text);
6865 (_("File doesn't exist or is empty."));
6871 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6872 if (*entry_text != '\0') {
6873 g_free(ainfo->name);
6874 ainfo->name = g_strdup(entry_text);
6878 g_free(ainfo->content_type);
6879 ainfo->content_type = cnttype;
6882 g_free(ainfo->file);
6888 /* update tree store */
6889 text = to_human_readable(ainfo->size);
6890 gtk_tree_model_get_iter(model, &iter, path);
6891 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6892 COL_MIMETYPE, ainfo->content_type,
6894 COL_NAME, ainfo->name,
6900 gtk_tree_path_free(path);
6903 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6905 label = gtk_label_new(str); \
6906 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6907 GTK_FILL, 0, 0, 0); \
6908 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6910 entry = gtk_entry_new(); \
6911 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6912 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6915 static void compose_attach_property_create(gboolean *cancelled)
6921 GtkWidget *mimetype_entry;
6924 GtkListStore *optmenu_menu;
6925 GtkWidget *path_entry;
6926 GtkWidget *filename_entry;
6929 GtkWidget *cancel_btn;
6930 GList *mime_type_list, *strlist;
6933 debug_print("Creating attach_property window...\n");
6935 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6936 gtk_widget_set_size_request(window, 480, -1);
6937 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6938 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6939 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6940 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6941 g_signal_connect(G_OBJECT(window), "delete_event",
6942 G_CALLBACK(attach_property_delete_event),
6944 g_signal_connect(G_OBJECT(window), "key_press_event",
6945 G_CALLBACK(attach_property_key_pressed),
6948 vbox = gtk_vbox_new(FALSE, 8);
6949 gtk_container_add(GTK_CONTAINER(window), vbox);
6951 table = gtk_table_new(4, 2, FALSE);
6952 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6953 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6954 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6956 label = gtk_label_new(_("MIME type"));
6957 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6959 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6960 mimetype_entry = gtk_combo_new();
6961 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6962 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6964 /* stuff with list */
6965 mime_type_list = procmime_get_mime_type_list();
6967 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6968 MimeType *type = (MimeType *) mime_type_list->data;
6971 tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
6973 if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
6976 strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
6977 (GCompareFunc)strcmp2);
6980 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6982 for (mime_type_list = strlist; mime_type_list != NULL;
6983 mime_type_list = mime_type_list->next)
6984 g_free(mime_type_list->data);
6985 g_list_free(strlist);
6987 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6989 label = gtk_label_new(_("Encoding"));
6990 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6992 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6994 hbox = gtk_hbox_new(FALSE, 0);
6995 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6996 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6998 optmenu = gtkut_sc_combobox_create(NULL, TRUE);
6999 optmenu_menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
7001 COMBOBOX_ADD(optmenu_menu, "7bit", ENC_7BIT);
7002 COMBOBOX_ADD(optmenu_menu, "8bit", ENC_8BIT);
7003 COMBOBOX_ADD(optmenu_menu, "quoted-printable", ENC_QUOTED_PRINTABLE);
7004 COMBOBOX_ADD(optmenu_menu, "base64", ENC_BASE64);
7005 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), 0);
7007 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
7009 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
7010 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
7012 gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
7013 &ok_btn, GTK_STOCK_OK,
7015 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
7016 gtk_widget_grab_default(ok_btn);
7018 g_signal_connect(G_OBJECT(ok_btn), "clicked",
7019 G_CALLBACK(attach_property_ok),
7021 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
7022 G_CALLBACK(attach_property_cancel),
7025 gtk_widget_show_all(vbox);
7027 attach_prop.window = window;
7028 attach_prop.mimetype_entry = mimetype_entry;
7029 attach_prop.encoding_optmenu = optmenu;
7030 attach_prop.path_entry = path_entry;
7031 attach_prop.filename_entry = filename_entry;
7032 attach_prop.ok_btn = ok_btn;
7033 attach_prop.cancel_btn = cancel_btn;
7036 #undef SET_LABEL_AND_ENTRY
7038 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
7044 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
7050 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
7051 gboolean *cancelled)
7059 static gboolean attach_property_key_pressed(GtkWidget *widget,
7061 gboolean *cancelled)
7063 if (event && event->keyval == GDK_Escape) {
7070 static void compose_exec_ext_editor(Compose *compose)
7077 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
7078 G_DIR_SEPARATOR, compose);
7080 if (pipe(pipe_fds) < 0) {
7086 if ((pid = fork()) < 0) {
7093 /* close the write side of the pipe */
7096 compose->exteditor_file = g_strdup(tmp);
7097 compose->exteditor_pid = pid;
7099 compose_set_ext_editor_sensitive(compose, FALSE);
7101 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
7102 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
7106 } else { /* process-monitoring process */
7112 /* close the read side of the pipe */
7115 if (compose_write_body_to_file(compose, tmp) < 0) {
7116 fd_write_all(pipe_fds[1], "2\n", 2);
7120 pid_ed = compose_exec_ext_editor_real(tmp);
7122 fd_write_all(pipe_fds[1], "1\n", 2);
7126 /* wait until editor is terminated */
7127 waitpid(pid_ed, NULL, 0);
7129 fd_write_all(pipe_fds[1], "0\n", 2);
7136 #endif /* G_OS_UNIX */
7140 static gint compose_exec_ext_editor_real(const gchar *file)
7147 g_return_val_if_fail(file != NULL, -1);
7149 if ((pid = fork()) < 0) {
7154 if (pid != 0) return pid;
7156 /* grandchild process */
7158 if (setpgid(0, getppid()))
7161 if (prefs_common.ext_editor_cmd &&
7162 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
7163 *(p + 1) == 's' && !strchr(p + 2, '%')) {
7164 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
7166 if (prefs_common.ext_editor_cmd)
7167 g_warning("External editor command line is invalid: '%s'\n",
7168 prefs_common.ext_editor_cmd);
7169 g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
7172 cmdline = strsplit_with_quote(buf, " ", 1024);
7173 execvp(cmdline[0], cmdline);
7176 g_strfreev(cmdline);
7181 static gboolean compose_ext_editor_kill(Compose *compose)
7183 pid_t pgid = compose->exteditor_pid * -1;
7186 ret = kill(pgid, 0);
7188 if (ret == 0 || (ret == -1 && EPERM == errno)) {
7192 msg = g_strdup_printf
7193 (_("The external editor is still working.\n"
7194 "Force terminating the process?\n"
7195 "process group id: %d"), -pgid);
7196 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_NO, GTK_STOCK_YES,
7197 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT);
7201 if (val == G_ALERTALTERNATE) {
7202 g_source_remove(compose->exteditor_tag);
7203 g_io_channel_shutdown(compose->exteditor_ch,
7205 g_io_channel_unref(compose->exteditor_ch);
7207 if (kill(pgid, SIGTERM) < 0) perror("kill");
7208 waitpid(compose->exteditor_pid, NULL, 0);
7210 g_warning("Terminated process group id: %d", -pgid);
7211 g_warning("Temporary file: %s",
7212 compose->exteditor_file);
7214 compose_set_ext_editor_sensitive(compose, TRUE);
7216 g_free(compose->exteditor_file);
7217 compose->exteditor_file = NULL;
7218 compose->exteditor_pid = -1;
7219 compose->exteditor_ch = NULL;
7220 compose->exteditor_tag = -1;
7228 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
7232 Compose *compose = (Compose *)data;
7235 debug_print(_("Compose: input from monitoring process\n"));
7237 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
7239 g_io_channel_shutdown(source, FALSE, NULL);
7240 g_io_channel_unref(source);
7242 waitpid(compose->exteditor_pid, NULL, 0);
7244 if (buf[0] == '0') { /* success */
7245 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7246 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
7248 gtk_text_buffer_set_text(buffer, "", -1);
7249 compose_insert_file(compose, compose->exteditor_file);
7250 compose_changed_cb(NULL, compose);
7252 if (g_unlink(compose->exteditor_file) < 0)
7253 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7254 } else if (buf[0] == '1') { /* failed */
7255 g_warning("Couldn't exec external editor\n");
7256 if (g_unlink(compose->exteditor_file) < 0)
7257 FILE_OP_ERROR(compose->exteditor_file, "unlink");
7258 } else if (buf[0] == '2') {
7259 g_warning("Couldn't write to file\n");
7260 } else if (buf[0] == '3') {
7261 g_warning("Pipe read failed\n");
7264 compose_set_ext_editor_sensitive(compose, TRUE);
7266 g_free(compose->exteditor_file);
7267 compose->exteditor_file = NULL;
7268 compose->exteditor_pid = -1;
7269 compose->exteditor_ch = NULL;
7270 compose->exteditor_tag = -1;
7275 static void compose_set_ext_editor_sensitive(Compose *compose,
7278 GtkItemFactory *ifactory;
7280 ifactory = gtk_item_factory_from_widget(compose->menubar);
7282 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
7283 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
7284 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
7285 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
7286 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
7287 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
7288 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
7291 gtk_widget_set_sensitive(compose->text, sensitive);
7292 if (compose->toolbar->send_btn)
7293 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
7294 if (compose->toolbar->sendl_btn)
7295 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
7296 if (compose->toolbar->draft_btn)
7297 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
7298 if (compose->toolbar->insert_btn)
7299 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
7300 if (compose->toolbar->sig_btn)
7301 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
7302 if (compose->toolbar->exteditor_btn)
7303 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
7304 if (compose->toolbar->linewrap_current_btn)
7305 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
7306 if (compose->toolbar->linewrap_all_btn)
7307 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
7309 #endif /* G_OS_UNIX */
7312 * compose_undo_state_changed:
7314 * Change the sensivity of the menuentries undo and redo
7316 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
7317 gint redo_state, gpointer data)
7319 GtkWidget *widget = GTK_WIDGET(data);
7320 GtkItemFactory *ifactory;
7322 g_return_if_fail(widget != NULL);
7324 ifactory = gtk_item_factory_from_widget(widget);
7326 switch (undo_state) {
7327 case UNDO_STATE_TRUE:
7328 if (!undostruct->undo_state) {
7329 undostruct->undo_state = TRUE;
7330 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
7333 case UNDO_STATE_FALSE:
7334 if (undostruct->undo_state) {
7335 undostruct->undo_state = FALSE;
7336 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
7339 case UNDO_STATE_UNCHANGED:
7341 case UNDO_STATE_REFRESH:
7342 menu_set_sensitive(ifactory, "/Edit/Undo",
7343 undostruct->undo_state);
7346 g_warning("Undo state not recognized");
7350 switch (redo_state) {
7351 case UNDO_STATE_TRUE:
7352 if (!undostruct->redo_state) {
7353 undostruct->redo_state = TRUE;
7354 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
7357 case UNDO_STATE_FALSE:
7358 if (undostruct->redo_state) {
7359 undostruct->redo_state = FALSE;
7360 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
7363 case UNDO_STATE_UNCHANGED:
7365 case UNDO_STATE_REFRESH:
7366 menu_set_sensitive(ifactory, "/Edit/Redo",
7367 undostruct->redo_state);
7370 g_warning("Redo state not recognized");
7375 /* callback functions */
7377 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
7378 * includes "non-client" (windows-izm) in calculation, so this calculation
7379 * may not be accurate.
7381 static gboolean compose_edit_size_alloc(GtkEditable *widget,
7382 GtkAllocation *allocation,
7383 GtkSHRuler *shruler)
7385 if (prefs_common.show_ruler) {
7386 gint char_width = 0, char_height = 0;
7387 gint line_width_in_chars;
7389 gtkut_get_font_size(GTK_WIDGET(widget),
7390 &char_width, &char_height);
7391 line_width_in_chars =
7392 (allocation->width - allocation->x) / char_width;
7394 /* got the maximum */
7395 gtk_ruler_set_range(GTK_RULER(shruler),
7396 0.0, line_width_in_chars, 0,
7397 /*line_width_in_chars*/ char_width);
7403 static void account_activated(GtkComboBox *optmenu, gpointer data)
7405 Compose *compose = (Compose *)data;
7408 gchar *folderidentifier;
7409 gint account_id = 0;
7413 /* Get ID of active account in the combo box */
7414 menu = gtk_combo_box_get_model(optmenu);
7415 gtk_combo_box_get_active_iter(optmenu, &iter);
7416 gtk_tree_model_get(menu, &iter, 1, &account_id, -1);
7418 ac = account_find_from_id(account_id);
7419 g_return_if_fail(ac != NULL);
7421 if (ac != compose->account)
7422 compose_select_account(compose, ac, FALSE);
7424 /* Set message save folder */
7425 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7426 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
7428 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
7429 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
7431 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7432 if (account_get_special_folder(compose->account, F_OUTBOX)) {
7433 folderidentifier = folder_item_get_identifier(account_get_special_folder
7434 (compose->account, F_OUTBOX));
7435 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
7436 g_free(folderidentifier);
7440 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
7441 GtkTreeViewColumn *column, Compose *compose)
7443 compose_attach_property(compose);
7446 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
7449 Compose *compose = (Compose *)data;
7450 GtkTreeSelection *attach_selection;
7451 gint attach_nr_selected;
7452 GtkItemFactory *ifactory;
7454 if (!event) return FALSE;
7456 if (event->button == 3) {
7457 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
7458 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
7459 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7461 if (attach_nr_selected > 0)
7463 menu_set_sensitive(ifactory, "/Remove", TRUE);
7464 menu_set_sensitive(ifactory, "/Properties...", TRUE);
7466 menu_set_sensitive(ifactory, "/Remove", FALSE);
7467 menu_set_sensitive(ifactory, "/Properties...", FALSE);
7470 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
7471 NULL, NULL, event->button, event->time);
7478 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
7481 Compose *compose = (Compose *)data;
7483 if (!event) return FALSE;
7485 switch (event->keyval) {
7487 compose_attach_remove_selected(compose);
7493 static void compose_allow_user_actions (Compose *compose, gboolean allow)
7495 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
7496 toolbar_comp_set_sensitive(compose, allow);
7497 menu_set_sensitive(ifactory, "/Message", allow);
7498 menu_set_sensitive(ifactory, "/Edit", allow);
7500 menu_set_sensitive(ifactory, "/Spelling", allow);
7502 menu_set_sensitive(ifactory, "/Options", allow);
7503 menu_set_sensitive(ifactory, "/Tools", allow);
7504 menu_set_sensitive(ifactory, "/Help", allow);
7506 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
7510 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
7512 Compose *compose = (Compose *)data;
7514 if (prefs_common.work_offline &&
7515 !inc_offline_should_override(
7516 _("Sylpheed-Claws needs network access in order "
7517 "to send this email.")))
7520 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
7521 gtk_timeout_remove(compose->draft_timeout_tag);
7522 compose->draft_timeout_tag = -1;
7525 compose_send(compose);
7528 static void compose_send_later_cb(gpointer data, guint action,
7531 Compose *compose = (Compose *)data;
7534 val = compose_queue_sub(compose, NULL, NULL, NULL, TRUE, TRUE);
7536 compose_close(compose);
7537 else if (val == -1) {
7538 alertpanel_error(_("Could not queue message."));
7539 } else if (val == -2) {
7540 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
7541 } else if (val == -3) {
7542 if (privacy_peek_error())
7543 alertpanel_error(_("Could not queue message for sending:\n\n"
7544 "Signature failed: %s"), privacy_get_error());
7545 } else if (val == -4) {
7546 alertpanel_error(_("Could not queue message for sending:\n\n"
7547 "Charset conversion failed."));
7551 void compose_draft (gpointer data)
7553 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7556 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
7558 Compose *compose = (Compose *)data;
7562 MsgFlags flag = {0, 0};
7563 static gboolean lock = FALSE;
7564 MsgInfo *newmsginfo;
7566 gboolean target_locked = FALSE;
7570 draft = account_get_special_folder(compose->account, F_DRAFT);
7571 g_return_if_fail(draft != NULL);
7573 if (!g_mutex_trylock(compose->mutex)) {
7574 /* we don't want to lock the mutex once it's available,
7575 * because as the only other part of compose.c locking
7576 * it is compose_close - which means once unlocked,
7577 * the compose struct will be freed */
7578 debug_print("couldn't lock mutex, probably sending\n");
7584 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
7585 G_DIR_SEPARATOR, compose);
7586 if ((fp = g_fopen(tmp, "wb")) == NULL) {
7587 FILE_OP_ERROR(tmp, "fopen");
7591 /* chmod for security */
7592 if (change_file_mode_rw(fp, tmp) < 0) {
7593 FILE_OP_ERROR(tmp, "chmod");
7594 g_warning("can't change file mode\n");
7597 /* Save draft infos */
7598 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
7599 fprintf(fp, "S:%s\n", compose->account->address);
7601 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
7602 gchar *savefolderid;
7604 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
7605 fprintf(fp, "SCF:%s\n", savefolderid);
7606 g_free(savefolderid);
7608 if (compose->return_receipt) {
7609 fprintf(fp, "RRCPT:1\n");
7611 if (compose->privacy_system) {
7612 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
7613 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
7614 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
7617 /* end of headers */
7618 fprintf(fp, "X-Sylpheed-End-Special-Headers: 1\n");
7620 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE, action != COMPOSE_AUTO_SAVE) < 0) {
7628 if (compose->targetinfo) {
7629 target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
7630 flag.perm_flags = target_locked?MSG_LOCKED:0;
7632 flag.tmp_flags = MSG_DRAFT;
7634 folder_item_scan(draft);
7635 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
7638 if (action != COMPOSE_AUTO_SAVE)
7639 alertpanel_error(_("Could not save draft."));
7644 if (compose->mode == COMPOSE_REEDIT) {
7645 compose_remove_reedit_target(compose, TRUE);
7648 newmsginfo = folder_item_get_msginfo(draft, msgnum);
7650 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
7652 procmsg_msginfo_set_flags(newmsginfo, MSG_LOCKED, MSG_DRAFT);
7654 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7655 if (compose_use_attach(compose) && action != COMPOSE_AUTO_SAVE)
7656 procmsg_msginfo_set_flags(newmsginfo, 0,
7657 MSG_HAS_ATTACHMENT);
7659 procmsg_msginfo_free(newmsginfo);
7662 folder_item_scan(draft);
7664 if (action == COMPOSE_QUIT_EDITING) {
7666 g_mutex_unlock(compose->mutex); /* must be done before closing */
7667 compose_close(compose);
7673 path = folder_item_fetch_msg(draft, msgnum);
7675 debug_print("can't fetch %s:%d\n",draft->path, msgnum);
7678 if (g_stat(path, &s) < 0) {
7679 FILE_OP_ERROR(path, "stat");
7685 procmsg_msginfo_free(compose->targetinfo);
7686 compose->targetinfo = procmsg_msginfo_new();
7687 compose->targetinfo->msgnum = msgnum;
7688 compose->targetinfo->size = s.st_size;
7689 compose->targetinfo->mtime = s.st_mtime;
7690 compose->targetinfo->folder = draft;
7692 procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0);
7693 compose->mode = COMPOSE_REEDIT;
7695 if (action == COMPOSE_AUTO_SAVE) {
7696 compose->autosaved_draft = compose->targetinfo;
7698 compose->modified = FALSE;
7699 compose_set_title(compose);
7703 g_mutex_unlock(compose->mutex);
7706 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7708 Compose *compose = (Compose *)data;
7711 if (compose->redirect_filename != NULL)
7714 file_list = filesel_select_multiple_files_open(_("Select file"));
7719 for ( tmp = file_list; tmp; tmp = tmp->next) {
7720 gchar *file = (gchar *) tmp->data;
7721 gchar *utf8_filename = conv_filename_to_utf8(file);
7722 compose_attach_append(compose, file, utf8_filename, NULL);
7723 compose_changed_cb(NULL, compose);
7725 g_free(utf8_filename);
7727 g_list_free(file_list);
7731 static void compose_insert_file_cb(gpointer data, guint action,
7734 Compose *compose = (Compose *)data;
7737 file_list = filesel_select_multiple_files_open(_("Select file"));
7742 for ( tmp = file_list; tmp; tmp = tmp->next) {
7743 gchar *file = (gchar *) tmp->data;
7744 gchar *filedup = g_strdup(file);
7745 gchar *shortfile = g_path_get_basename(filedup);
7746 ComposeInsertResult res;
7748 res = compose_insert_file(compose, file);
7749 if (res == COMPOSE_INSERT_READ_ERROR) {
7750 alertpanel_error(_("File '%s' could not be read."), shortfile);
7751 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7752 alertpanel_error(_("File '%s' contained invalid characters\n"
7753 "for the current encoding, insertion may be incorrect."), shortfile);
7759 g_list_free(file_list);
7763 static void compose_insert_sig_cb(gpointer data, guint action,
7766 Compose *compose = (Compose *)data;
7768 compose_insert_sig(compose, FALSE);
7771 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7775 Compose *compose = (Compose *)data;
7777 gtkut_widget_get_uposition(widget, &x, &y);
7778 prefs_common.compose_x = x;
7779 prefs_common.compose_y = y;
7781 if (compose->sending || compose->updating)
7783 compose_close_cb(compose, 0, NULL);
7787 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7789 Compose *compose = (Compose *)data;
7793 if (compose->exteditor_tag != -1) {
7794 if (!compose_ext_editor_kill(compose))
7799 if (compose->modified) {
7800 val = alertpanel(_("Discard message"),
7801 _("This message has been modified. Discard it?"),
7802 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7805 case G_ALERTDEFAULT:
7806 if (prefs_common.autosave)
7807 compose_remove_draft(compose);
7809 case G_ALERTALTERNATE:
7810 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7817 compose_close(compose);
7820 static void compose_set_encoding_cb(gpointer data, guint action,
7823 Compose *compose = (Compose *)data;
7825 if (GTK_CHECK_MENU_ITEM(widget)->active)
7826 compose->out_encoding = (CharSet)action;
7829 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7831 Compose *compose = (Compose *)data;
7833 addressbook_open(compose);
7836 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7838 Compose *compose = (Compose *)data;
7843 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7844 g_return_if_fail(tmpl != NULL);
7846 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7848 val = alertpanel(_("Apply template"), msg,
7849 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7852 if (val == G_ALERTDEFAULT)
7853 compose_template_apply(compose, tmpl, TRUE);
7854 else if (val == G_ALERTALTERNATE)
7855 compose_template_apply(compose, tmpl, FALSE);
7858 static void compose_ext_editor_cb(gpointer data, guint action,
7861 Compose *compose = (Compose *)data;
7863 compose_exec_ext_editor(compose);
7866 static void compose_undo_cb(Compose *compose)
7868 gboolean prev_autowrap = compose->autowrap;
7870 compose->autowrap = FALSE;
7871 undo_undo(compose->undostruct);
7872 compose->autowrap = prev_autowrap;
7875 static void compose_redo_cb(Compose *compose)
7877 gboolean prev_autowrap = compose->autowrap;
7879 compose->autowrap = FALSE;
7880 undo_redo(compose->undostruct);
7881 compose->autowrap = prev_autowrap;
7884 static void entry_cut_clipboard(GtkWidget *entry)
7886 if (GTK_IS_EDITABLE(entry))
7887 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7888 else if (GTK_IS_TEXT_VIEW(entry))
7889 gtk_text_buffer_cut_clipboard(
7890 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7891 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7895 static void entry_copy_clipboard(GtkWidget *entry)
7897 if (GTK_IS_EDITABLE(entry))
7898 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7899 else if (GTK_IS_TEXT_VIEW(entry))
7900 gtk_text_buffer_copy_clipboard(
7901 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7902 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7905 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7906 gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
7908 if (GTK_IS_TEXT_VIEW(entry)) {
7909 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7910 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7911 GtkTextIter start_iter, end_iter;
7914 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7916 if (contents == NULL)
7919 /* we shouldn't delete the selection when middle-click-pasting, or we
7920 * can't mid-click-paste our own selection */
7921 if (clip != GDK_SELECTION_PRIMARY)
7922 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7924 if (insert_place == NULL) {
7925 /* if insert_place isn't specified, insert at the cursor.
7926 * used for Ctrl-V pasting */
7927 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7928 start = gtk_text_iter_get_offset(&start_iter);
7929 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7931 /* if insert_place is specified, paste here.
7932 * used for mid-click-pasting */
7933 start = gtk_text_iter_get_offset(insert_place);
7934 gtk_text_buffer_insert(buffer, insert_place, contents, strlen(contents));
7938 /* paste unwrapped: mark the paste so it's not wrapped later */
7939 end = start + strlen(contents);
7940 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7941 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7942 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7943 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7944 /* rewrap paragraph now (after a mid-click-paste) */
7945 mark_start = gtk_text_buffer_get_insert(buffer);
7946 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7947 gtk_text_iter_backward_char(&start_iter);
7948 compose_beautify_paragraph(compose, &start_iter, TRUE);
7951 } else if (GTK_IS_EDITABLE(entry))
7952 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7956 static void entry_allsel(GtkWidget *entry)
7958 if (GTK_IS_EDITABLE(entry))
7959 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7960 else if (GTK_IS_TEXT_VIEW(entry)) {
7961 GtkTextIter startiter, enditer;
7962 GtkTextBuffer *textbuf;
7964 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7965 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7966 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7968 gtk_text_buffer_move_mark_by_name(textbuf,
7969 "selection_bound", &startiter);
7970 gtk_text_buffer_move_mark_by_name(textbuf,
7971 "insert", &enditer);
7975 static void compose_cut_cb(Compose *compose)
7977 if (compose->focused_editable &&
7978 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7979 entry_cut_clipboard(compose->focused_editable);
7982 static void compose_copy_cb(Compose *compose)
7984 if (compose->focused_editable &&
7985 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7986 entry_copy_clipboard(compose->focused_editable);
7989 static void compose_paste_cb(Compose *compose)
7992 GtkTextBuffer *buffer;
7994 if (compose->focused_editable &&
7995 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7996 entry_paste_clipboard(compose, compose->focused_editable,
7997 prefs_common.linewrap_pastes,
7998 GDK_SELECTION_CLIPBOARD, NULL);
8002 static void compose_paste_as_quote_cb(Compose *compose)
8004 gint wrap_quote = prefs_common.linewrap_quote;
8005 if (compose->focused_editable &&
8006 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
8007 /* let text_insert() (called directly or at a later time
8008 * after the gtk_editable_paste_clipboard) know that
8009 * text is to be inserted as a quotation. implemented
8010 * by using a simple refcount... */
8011 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
8012 G_OBJECT(compose->focused_editable),
8013 "paste_as_quotation"));
8014 g_object_set_data(G_OBJECT(compose->focused_editable),
8015 "paste_as_quotation",
8016 GINT_TO_POINTER(paste_as_quotation + 1));
8017 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
8018 entry_paste_clipboard(compose, compose->focused_editable,
8019 prefs_common.linewrap_pastes,
8020 GDK_SELECTION_CLIPBOARD, NULL);
8021 prefs_common.linewrap_quote = wrap_quote;
8025 static void compose_paste_no_wrap_cb(Compose *compose)
8028 GtkTextBuffer *buffer;
8030 if (compose->focused_editable &&
8031 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8032 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
8033 GDK_SELECTION_CLIPBOARD, NULL);
8037 static void compose_paste_wrap_cb(Compose *compose)
8040 GtkTextBuffer *buffer;
8042 if (compose->focused_editable &&
8043 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8044 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
8045 GDK_SELECTION_CLIPBOARD, NULL);
8049 static void compose_allsel_cb(Compose *compose)
8051 if (compose->focused_editable &&
8052 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
8053 entry_allsel(compose->focused_editable);
8056 static void textview_move_beginning_of_line (GtkTextView *text)
8058 GtkTextBuffer *buffer;
8062 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8064 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8065 mark = gtk_text_buffer_get_insert(buffer);
8066 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8067 gtk_text_iter_set_line_offset(&ins, 0);
8068 gtk_text_buffer_place_cursor(buffer, &ins);
8071 static void textview_move_forward_character (GtkTextView *text)
8073 GtkTextBuffer *buffer;
8077 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8079 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8080 mark = gtk_text_buffer_get_insert(buffer);
8081 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8082 if (gtk_text_iter_forward_cursor_position(&ins))
8083 gtk_text_buffer_place_cursor(buffer, &ins);
8086 static void textview_move_backward_character (GtkTextView *text)
8088 GtkTextBuffer *buffer;
8092 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8094 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8095 mark = gtk_text_buffer_get_insert(buffer);
8096 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8097 if (gtk_text_iter_backward_cursor_position(&ins))
8098 gtk_text_buffer_place_cursor(buffer, &ins);
8101 static void textview_move_forward_word (GtkTextView *text)
8103 GtkTextBuffer *buffer;
8108 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8110 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8111 mark = gtk_text_buffer_get_insert(buffer);
8112 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8113 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8114 if (gtk_text_iter_forward_word_ends(&ins, count)) {
8115 gtk_text_iter_backward_word_start(&ins);
8116 gtk_text_buffer_place_cursor(buffer, &ins);
8120 static void textview_move_backward_word (GtkTextView *text)
8122 GtkTextBuffer *buffer;
8127 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8129 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8130 mark = gtk_text_buffer_get_insert(buffer);
8131 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8132 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
8133 if (gtk_text_iter_backward_word_starts(&ins, 1))
8134 gtk_text_buffer_place_cursor(buffer, &ins);
8137 static void textview_move_end_of_line (GtkTextView *text)
8139 GtkTextBuffer *buffer;
8143 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8145 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8146 mark = gtk_text_buffer_get_insert(buffer);
8147 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8148 if (gtk_text_iter_forward_to_line_end(&ins))
8149 gtk_text_buffer_place_cursor(buffer, &ins);
8152 static void textview_move_next_line (GtkTextView *text)
8154 GtkTextBuffer *buffer;
8159 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8161 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8162 mark = gtk_text_buffer_get_insert(buffer);
8163 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8164 offset = gtk_text_iter_get_line_offset(&ins);
8165 if (gtk_text_iter_forward_line(&ins)) {
8166 gtk_text_iter_set_line_offset(&ins, offset);
8167 gtk_text_buffer_place_cursor(buffer, &ins);
8171 static void textview_move_previous_line (GtkTextView *text)
8173 GtkTextBuffer *buffer;
8178 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8180 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8181 mark = gtk_text_buffer_get_insert(buffer);
8182 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8183 offset = gtk_text_iter_get_line_offset(&ins);
8184 if (gtk_text_iter_backward_line(&ins)) {
8185 gtk_text_iter_set_line_offset(&ins, offset);
8186 gtk_text_buffer_place_cursor(buffer, &ins);
8190 static void textview_delete_forward_character (GtkTextView *text)
8192 GtkTextBuffer *buffer;
8194 GtkTextIter ins, end_iter;
8196 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8198 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8199 mark = gtk_text_buffer_get_insert(buffer);
8200 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8202 if (gtk_text_iter_forward_char(&end_iter)) {
8203 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8207 static void textview_delete_backward_character (GtkTextView *text)
8209 GtkTextBuffer *buffer;
8211 GtkTextIter ins, end_iter;
8213 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8215 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8216 mark = gtk_text_buffer_get_insert(buffer);
8217 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8219 if (gtk_text_iter_backward_char(&end_iter)) {
8220 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8224 static void textview_delete_forward_word (GtkTextView *text)
8226 GtkTextBuffer *buffer;
8228 GtkTextIter ins, end_iter;
8230 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8232 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8233 mark = gtk_text_buffer_get_insert(buffer);
8234 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8236 if (gtk_text_iter_forward_word_end(&end_iter)) {
8237 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8241 static void textview_delete_backward_word (GtkTextView *text)
8243 GtkTextBuffer *buffer;
8245 GtkTextIter ins, end_iter;
8247 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8249 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8250 mark = gtk_text_buffer_get_insert(buffer);
8251 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8253 if (gtk_text_iter_backward_word_start(&end_iter)) {
8254 gtk_text_buffer_delete(buffer, &end_iter, &ins);
8258 static void textview_delete_line (GtkTextView *text)
8260 GtkTextBuffer *buffer;
8262 GtkTextIter ins, start_iter, end_iter;
8265 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8267 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8268 mark = gtk_text_buffer_get_insert(buffer);
8269 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8272 gtk_text_iter_set_line_offset(&start_iter, 0);
8275 if (gtk_text_iter_ends_line(&end_iter))
8276 found = gtk_text_iter_forward_char(&end_iter);
8278 found = gtk_text_iter_forward_to_line_end(&end_iter);
8281 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
8284 static void textview_delete_to_line_end (GtkTextView *text)
8286 GtkTextBuffer *buffer;
8288 GtkTextIter ins, end_iter;
8291 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
8293 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
8294 mark = gtk_text_buffer_get_insert(buffer);
8295 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
8297 if (gtk_text_iter_ends_line(&end_iter))
8298 found = gtk_text_iter_forward_char(&end_iter);
8300 found = gtk_text_iter_forward_to_line_end(&end_iter);
8302 gtk_text_buffer_delete(buffer, &ins, &end_iter);
8305 static void compose_advanced_action_cb(Compose *compose,
8306 ComposeCallAdvancedAction action)
8308 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8310 void (*do_action) (GtkTextView *text);
8311 } action_table[] = {
8312 {textview_move_beginning_of_line},
8313 {textview_move_forward_character},
8314 {textview_move_backward_character},
8315 {textview_move_forward_word},
8316 {textview_move_backward_word},
8317 {textview_move_end_of_line},
8318 {textview_move_next_line},
8319 {textview_move_previous_line},
8320 {textview_delete_forward_character},
8321 {textview_delete_backward_character},
8322 {textview_delete_forward_word},
8323 {textview_delete_backward_word},
8324 {textview_delete_line},
8325 {NULL}, /* gtk_stext_delete_line_n */
8326 {textview_delete_to_line_end}
8329 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
8331 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
8332 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
8333 if (action_table[action].do_action)
8334 action_table[action].do_action(text);
8336 g_warning("Not implemented yet.");
8340 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
8344 if (GTK_IS_EDITABLE(widget)) {
8345 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
8346 gtk_editable_set_position(GTK_EDITABLE(widget),
8349 if (widget->parent && widget->parent->parent
8350 && widget->parent->parent->parent) {
8351 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
8352 gint y = widget->allocation.y;
8353 gint height = widget->allocation.height;
8354 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
8355 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
8357 if (y < (int)shown->value) {
8358 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
8360 if (y + height > (int)shown->value + (int)shown->page_size) {
8361 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
8362 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8363 y + height - (int)shown->page_size - 1);
8365 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
8366 (int)shown->upper - (int)shown->page_size - 1);
8373 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
8374 compose->focused_editable = widget;
8377 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
8379 compose->modified = TRUE;
8380 compose_set_title(compose);
8383 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
8385 Compose *compose = (Compose *)data;
8388 compose_wrap_all_full(compose, TRUE);
8390 compose_beautify_paragraph(compose, NULL, TRUE);
8393 static void compose_find_cb(gpointer data, guint action, GtkWidget *widget)
8395 Compose *compose = (Compose *)data;
8397 message_search_compose(compose);
8400 static void compose_toggle_autowrap_cb(gpointer data, guint action,
8403 Compose *compose = (Compose *)data;
8404 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8405 if (compose->autowrap)
8406 compose_wrap_all_full(compose, TRUE);
8407 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
8410 static void compose_toggle_sign_cb(gpointer data, guint action,
8413 Compose *compose = (Compose *)data;
8415 if (GTK_CHECK_MENU_ITEM(widget)->active)
8416 compose->use_signing = TRUE;
8418 compose->use_signing = FALSE;
8421 static void compose_toggle_encrypt_cb(gpointer data, guint action,
8424 Compose *compose = (Compose *)data;
8426 if (GTK_CHECK_MENU_ITEM(widget)->active)
8427 compose->use_encryption = TRUE;
8429 compose->use_encryption = FALSE;
8432 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
8434 g_free(compose->privacy_system);
8436 compose->privacy_system = g_strdup(account->default_privacy_system);
8437 compose_update_privacy_system_menu_item(compose, warn);
8440 static void compose_toggle_ruler_cb(gpointer data, guint action,
8443 Compose *compose = (Compose *)data;
8445 if (GTK_CHECK_MENU_ITEM(widget)->active) {
8446 gtk_widget_show(compose->ruler_hbox);
8447 prefs_common.show_ruler = TRUE;
8449 gtk_widget_hide(compose->ruler_hbox);
8450 gtk_widget_queue_resize(compose->edit_vbox);
8451 prefs_common.show_ruler = FALSE;
8455 static void compose_attach_drag_received_cb (GtkWidget *widget,
8456 GdkDragContext *context,
8459 GtkSelectionData *data,
8464 Compose *compose = (Compose *)user_data;
8467 if (gdk_atom_name(data->type) &&
8468 !strcmp(gdk_atom_name(data->type), "text/uri-list")
8469 && gtk_drag_get_source_widget(context) !=
8470 mainwindow_get_mainwindow()->summaryview->ctree) {
8471 list = uri_list_extract_filenames((const gchar *)data->data);
8472 for (tmp = list; tmp != NULL; tmp = tmp->next)
8473 compose_attach_append
8474 (compose, (const gchar *)tmp->data,
8475 (const gchar *)tmp->data, NULL);
8476 if (list) compose_changed_cb(NULL, compose);
8477 list_free_strings(list);
8479 } else if (gtk_drag_get_source_widget(context)
8480 == mainwindow_get_mainwindow()->summaryview->ctree) {
8481 /* comes from our summaryview */
8482 SummaryView * summaryview = NULL;
8483 GSList * list = NULL, *cur = NULL;
8485 if (mainwindow_get_mainwindow())
8486 summaryview = mainwindow_get_mainwindow()->summaryview;
8489 list = summary_get_selected_msg_list(summaryview);
8491 for (cur = list; cur; cur = cur->next) {
8492 MsgInfo *msginfo = (MsgInfo *)cur->data;
8495 file = procmsg_get_message_file_full(msginfo,
8498 compose_attach_append(compose, (const gchar *)file,
8499 (const gchar *)file, "message/rfc822");
8507 static gboolean compose_drag_drop(GtkWidget *widget,
8508 GdkDragContext *drag_context,
8510 guint time, gpointer user_data)
8512 /* not handling this signal makes compose_insert_drag_received_cb
8517 static void compose_insert_drag_received_cb (GtkWidget *widget,
8518 GdkDragContext *drag_context,
8521 GtkSelectionData *data,
8526 Compose *compose = (Compose *)user_data;
8529 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
8531 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
8532 AlertValue val = G_ALERTDEFAULT;
8534 switch (prefs_common.compose_dnd_mode) {
8535 case COMPOSE_DND_ASK:
8536 val = alertpanel_full(_("Insert or attach?"),
8537 _("Do you want to insert the contents of the file(s) "
8538 "into the message body, or attach it to the email?"),
8539 GTK_STOCK_CANCEL, _("+_Insert"), _("_Attach"),
8540 TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
8542 case COMPOSE_DND_INSERT:
8543 val = G_ALERTALTERNATE;
8545 case COMPOSE_DND_ATTACH:
8549 /* unexpected case */
8550 g_warning("error: unexpected compose_dnd_mode option value in compose_insert_drag_received_cb()");
8553 if (val & G_ALERTDISABLE) {
8554 val &= ~G_ALERTDISABLE;
8555 /* remember what action to perform by default, only if we don't click Cancel */
8556 if (val == G_ALERTALTERNATE)
8557 prefs_common.compose_dnd_mode = COMPOSE_DND_INSERT;
8558 else if (val == G_ALERTOTHER)
8559 prefs_common.compose_dnd_mode = COMPOSE_DND_ATTACH;
8562 if (val == G_ALERTDEFAULT || val == G_ALERTCANCEL) {
8563 gtk_drag_finish(drag_context, FALSE, FALSE, time);
8565 } else if (val == G_ALERTOTHER) {
8566 compose_attach_drag_received_cb(widget, drag_context, x, y, data, info, time, user_data);
8569 list = uri_list_extract_filenames((const gchar *)data->data);
8570 for (tmp = list; tmp != NULL; tmp = tmp->next) {
8571 compose_insert_file(compose, (const gchar *)tmp->data);
8573 list_free_strings(list);
8575 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8578 #if GTK_CHECK_VERSION(2, 8, 0)
8579 /* do nothing, handled by GTK */
8581 gchar *tmpfile = get_tmp_file();
8582 str_write_to_file((const gchar *)data->data, tmpfile);
8583 compose_insert_file(compose, tmpfile);
8586 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8590 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8593 static void compose_header_drag_received_cb (GtkWidget *widget,
8594 GdkDragContext *drag_context,
8597 GtkSelectionData *data,
8602 GtkEditable *entry = (GtkEditable *)user_data;
8603 gchar *email = (gchar *)data->data;
8605 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
8608 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
8609 gchar *decoded=g_new(gchar, strlen(email));
8612 email += strlen("mailto:");
8613 decode_uri(decoded, email); /* will fit */
8614 gtk_editable_delete_text(entry, 0, -1);
8615 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
8616 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8620 gtk_drag_finish(drag_context, TRUE, FALSE, time);
8623 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
8626 Compose *compose = (Compose *)data;
8628 if (GTK_CHECK_MENU_ITEM(widget)->active)
8629 compose->return_receipt = TRUE;
8631 compose->return_receipt = FALSE;
8634 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
8637 Compose *compose = (Compose *)data;
8639 if (GTK_CHECK_MENU_ITEM(widget)->active)
8640 compose->remove_references = TRUE;
8642 compose->remove_references = FALSE;
8645 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
8647 ComposeHeaderEntry *headerentry)
8649 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
8650 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
8651 !(event->state & GDK_MODIFIER_MASK) &&
8652 (event->keyval == GDK_BackSpace) &&
8653 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
8654 gtk_container_remove
8655 (GTK_CONTAINER(headerentry->compose->header_table),
8656 headerentry->combo);
8657 gtk_container_remove
8658 (GTK_CONTAINER(headerentry->compose->header_table),
8659 headerentry->entry);
8660 headerentry->compose->header_list =
8661 g_slist_remove(headerentry->compose->header_list,
8663 g_free(headerentry);
8664 } else if (event->keyval == GDK_Tab) {
8665 if (headerentry->compose->header_last == headerentry) {
8666 /* Override default next focus, and give it to subject_entry
8667 * instead of notebook tabs
8669 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
8670 gtk_widget_grab_focus(headerentry->compose->subject_entry);
8677 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
8678 ComposeHeaderEntry *headerentry)
8680 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
8681 headerentry->compose->header_list =
8682 g_slist_append(headerentry->compose->header_list,
8685 compose_create_header_entry(headerentry->compose);
8686 g_signal_handlers_disconnect_matched
8687 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
8688 0, 0, NULL, NULL, headerentry);
8690 /* Automatically scroll down */
8691 compose_show_first_last_header(headerentry->compose, FALSE);
8697 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
8699 GtkAdjustment *vadj;
8701 g_return_if_fail(compose);
8702 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
8703 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
8705 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
8706 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
8709 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
8710 const gchar *text, gint len, Compose *compose)
8712 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
8713 (G_OBJECT(compose->text), "paste_as_quotation"));
8716 g_return_if_fail(text != NULL);
8718 g_signal_handlers_block_by_func(G_OBJECT(buffer),
8719 G_CALLBACK(text_inserted),
8721 if (paste_as_quotation) {
8728 new_text = g_strndup(text, len);
8729 if (prefs_common.quotemark && *prefs_common.quotemark)
8730 qmark = prefs_common.quotemark;
8734 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8735 gtk_text_buffer_place_cursor(buffer, iter);
8737 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
8739 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8740 GINT_TO_POINTER(paste_as_quotation - 1));
8742 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8743 gtk_text_buffer_place_cursor(buffer, iter);
8745 if (strcmp(text, "\n") || automatic_break
8746 || gtk_text_iter_starts_line(iter))
8747 gtk_text_buffer_insert(buffer, iter, text, len);
8749 debug_print("insert nowrap \\n\n");
8750 gtk_text_buffer_insert_with_tags_by_name(buffer,
8751 iter, text, len, "no_join", NULL);
8755 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8757 compose_beautify_paragraph(compose, iter, FALSE);
8759 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8760 gtk_text_buffer_delete_mark(buffer, mark);
8762 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8763 G_CALLBACK(text_inserted),
8765 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8767 if (prefs_common.autosave &&
8768 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8769 compose->draft_timeout_tag = gtk_timeout_add
8770 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8772 static gint compose_defer_auto_save_draft(Compose *compose)
8774 compose->draft_timeout_tag = -1;
8775 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8780 static void compose_check_all(Compose *compose)
8782 if (compose->gtkaspell)
8783 gtkaspell_check_all(compose->gtkaspell);
8786 static void compose_highlight_all(Compose *compose)
8788 if (compose->gtkaspell)
8789 gtkaspell_highlight_all(compose->gtkaspell);
8792 static void compose_check_backwards(Compose *compose)
8794 if (compose->gtkaspell)
8795 gtkaspell_check_backwards(compose->gtkaspell);
8797 GtkItemFactory *ifactory;
8798 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8799 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8800 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8804 static void compose_check_forwards_go(Compose *compose)
8806 if (compose->gtkaspell)
8807 gtkaspell_check_forwards_go(compose->gtkaspell);
8809 GtkItemFactory *ifactory;
8810 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8811 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8812 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8818 *\brief Guess originating forward account from MsgInfo and several
8819 * "common preference" settings. Return NULL if no guess.
8821 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8823 PrefsAccount *account = NULL;
8825 g_return_val_if_fail(msginfo, NULL);
8826 g_return_val_if_fail(msginfo->folder, NULL);
8827 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8829 if (msginfo->folder->prefs->enable_default_account)
8830 account = account_find_from_id(msginfo->folder->prefs->default_account);
8833 account = msginfo->folder->folder->account;
8835 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8837 Xstrdup_a(to, msginfo->to, return NULL);
8838 extract_address(to);
8839 account = account_find_from_address(to);
8842 if (!account && prefs_common.forward_account_autosel) {
8844 if (!procheader_get_header_from_msginfo
8845 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8846 extract_address(cc);
8847 account = account_find_from_address(cc);
8854 gboolean compose_close(Compose *compose)
8858 if (!g_mutex_trylock(compose->mutex)) {
8859 /* we have to wait for the (possibly deferred by auto-save)
8860 * drafting to be done, before destroying the compose under
8862 debug_print("waiting for drafting to finish...\n");
8863 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8866 g_return_val_if_fail(compose, FALSE);
8867 gtkut_widget_get_uposition(compose->window, &x, &y);
8868 prefs_common.compose_x = x;
8869 prefs_common.compose_y = y;
8870 g_mutex_unlock(compose->mutex);
8871 compose_destroy(compose);
8876 * Add entry field for each address in list.
8877 * \param compose E-Mail composition object.
8878 * \param listAddress List of (formatted) E-Mail addresses.
8880 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8885 addr = ( gchar * ) node->data;
8886 compose_entry_append( compose, addr, COMPOSE_TO );
8887 node = g_list_next( node );
8891 static void compose_reply_from_messageview_real(MessageView *msgview, GSList *msginfo_list,
8892 guint action, gboolean opening_multiple)
8895 GSList *new_msglist = NULL;
8896 MsgInfo *tmp_msginfo = NULL;
8897 gboolean originally_enc = FALSE;
8898 Compose *compose = NULL;
8900 g_return_if_fail(msgview != NULL);
8902 g_return_if_fail(msginfo_list != NULL);
8904 if (g_slist_length(msginfo_list) == 1 && !opening_multiple) {
8905 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8906 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8908 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8909 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8910 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8911 orig_msginfo, mimeinfo);
8912 if (tmp_msginfo != NULL) {
8913 new_msglist = g_slist_append(NULL, tmp_msginfo);
8914 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8915 originally_enc = TRUE;
8921 if (!opening_multiple)
8922 body = messageview_get_selection(msgview);
8925 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8926 procmsg_msginfo_free(tmp_msginfo);
8927 g_slist_free(new_msglist);
8929 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8931 if (originally_enc) {
8932 compose_force_encryption(compose, compose->account, FALSE);
8938 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8941 if ((!prefs_common.forward_as_attachment || action != COMPOSE_FORWARD)
8942 && action != COMPOSE_FORWARD_AS_ATTACH && g_slist_length(msginfo_list) > 1) {
8943 GSList *cur = msginfo_list;
8944 gchar *msg = g_strdup_printf(_("You are about to reply to %d "
8945 "messages. Opening the windows "
8946 "could take some time. Do you "
8947 "want to continue?"),
8948 g_slist_length(msginfo_list));
8949 if (g_slist_length(msginfo_list) > 9
8950 && alertpanel(_("Warning"), msg, GTK_STOCK_CANCEL, "+" GTK_STOCK_YES, NULL)
8951 != G_ALERTALTERNATE) {
8956 /* We'll open multiple compose windows */
8957 /* let the WM place the next windows */
8958 compose_force_window_origin = FALSE;
8959 for (; cur; cur = cur->next) {
8961 tmplist.data = cur->data;
8962 tmplist.next = NULL;
8963 compose_reply_from_messageview_real(msgview, &tmplist, action, TRUE);
8965 compose_force_window_origin = TRUE;
8967 /* forwarding multiple mails as attachments is done via a
8968 * single compose window */
8969 compose_reply_from_messageview_real(msgview, msginfo_list, action, FALSE);
8973 void compose_set_position(Compose *compose, gint pos)
8975 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8977 gtkut_text_view_set_position(text, pos);
8980 gboolean compose_search_string(Compose *compose,
8981 const gchar *str, gboolean case_sens)
8983 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8985 return gtkut_text_view_search_string(text, str, case_sens);
8988 gboolean compose_search_string_backward(Compose *compose,
8989 const gchar *str, gboolean case_sens)
8991 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
8993 return gtkut_text_view_search_string_backward(text, str, case_sens);