2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2005 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 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>
77 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
84 #include "mainwindow.h"
86 #include "addressbook.h"
87 #include "folderview.h"
90 #include "stock_pixmap.h"
91 #include "send_message.h"
94 #include "customheader.h"
95 #include "prefs_common.h"
96 #include "prefs_account.h"
100 #include "procheader.h"
101 #include "procmime.h"
102 #include "statusbar.h"
105 #include "quoted-printable.h"
106 #include "codeconv.h"
108 #include "gtkutils.h"
110 #include "alertpanel.h"
111 #include "manage_window.h"
112 #include "gtkshruler.h"
114 #include "addr_compl.h"
115 #include "quote_fmt.h"
116 #include "template.h"
118 #include "foldersel.h"
131 #define N_ATTACH_COLS (N_COL_COLUMNS)
135 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
136 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
137 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
138 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
143 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
144 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
145 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
146 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
150 } ComposeCallAdvancedAction;
154 PRIORITY_HIGHEST = 1,
163 COMPOSE_INSERT_SUCCESS,
164 COMPOSE_INSERT_READ_ERROR,
165 COMPOSE_INSERT_INVALID_CHARACTER,
166 COMPOSE_INSERT_NO_FILE
167 } ComposeInsertResult;
171 COMPOSE_QUIT_EDITING,
172 COMPOSE_KEEP_EDITING,
174 } ComposeDraftAction;
178 COMPOSE_WRITE_FOR_SEND,
179 COMPOSE_WRITE_FOR_STORE
182 #define B64_LINE_SIZE 57
183 #define B64_BUFFSIZE 77
185 #define MAX_REFERENCES_LEN 999
187 static GList *compose_list = NULL;
189 Compose *compose_generic_new (PrefsAccount *account,
192 GPtrArray *attach_files,
193 GList *listAddress );
195 static Compose *compose_create (PrefsAccount *account,
198 static GtkWidget *compose_account_option_menu_create
200 static void compose_set_out_encoding (Compose *compose);
201 static void compose_set_template_menu (Compose *compose);
202 static void compose_template_apply (Compose *compose,
205 static void compose_destroy (Compose *compose);
207 static void compose_entries_set (Compose *compose,
208 const gchar *mailto);
209 static gint compose_parse_header (Compose *compose,
211 static gchar *compose_parse_references (const gchar *ref,
214 static gchar *compose_quote_fmt (Compose *compose,
220 static void compose_reply_set_entry (Compose *compose,
226 followup_and_reply_to);
227 static void compose_reedit_set_entry (Compose *compose,
230 static void compose_insert_sig (Compose *compose,
232 static gchar *compose_get_signature_str (Compose *compose);
233 static ComposeInsertResult compose_insert_file (Compose *compose,
236 static void compose_attach_append (Compose *compose,
239 const gchar *content_type);
240 static void compose_attach_parts (Compose *compose,
243 static void compose_beautify_paragraph (Compose *compose,
244 GtkTextIter *par_iter,
246 static void compose_wrap_all (Compose *compose);
247 static void compose_wrap_all_full (Compose *compose,
250 static void compose_set_title (Compose *compose);
251 static void compose_select_account (Compose *compose,
252 PrefsAccount *account,
255 static PrefsAccount *compose_current_mail_account(void);
256 /* static gint compose_send (Compose *compose); */
257 static gboolean compose_check_for_valid_recipient
259 static gboolean compose_check_entries (Compose *compose,
260 gboolean check_subject);
261 static gint compose_write_to_file (Compose *compose,
264 static gint compose_write_body_to_file (Compose *compose,
266 static gint compose_remove_reedit_target (Compose *compose);
267 void compose_remove_draft (Compose *compose);
268 static gint compose_queue (Compose *compose,
271 static gint compose_queue_sub (Compose *compose,
274 gboolean check_subject);
275 static void compose_add_attachments (Compose *compose,
277 static gchar *compose_get_header (Compose *compose);
279 static void compose_convert_header (Compose *compose,
284 gboolean addr_field);
286 static void compose_attach_info_free (AttachInfo *ainfo);
287 static void compose_attach_remove_selected (Compose *compose);
289 static void compose_attach_property (Compose *compose);
290 static void compose_attach_property_create (gboolean *cancelled);
291 static void attach_property_ok (GtkWidget *widget,
292 gboolean *cancelled);
293 static void attach_property_cancel (GtkWidget *widget,
294 gboolean *cancelled);
295 static gint attach_property_delete_event (GtkWidget *widget,
297 gboolean *cancelled);
298 static gboolean attach_property_key_pressed (GtkWidget *widget,
300 gboolean *cancelled);
302 static void compose_exec_ext_editor (Compose *compose);
304 static gint compose_exec_ext_editor_real (const gchar *file);
305 static gboolean compose_ext_editor_kill (Compose *compose);
306 static gboolean compose_input_cb (GIOChannel *source,
307 GIOCondition condition,
309 static void compose_set_ext_editor_sensitive (Compose *compose,
311 #endif /* G_OS_UNIX */
313 static void compose_undo_state_changed (UndoMain *undostruct,
318 static void compose_create_header_entry (Compose *compose);
319 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
320 static void compose_update_priority_menu_item(Compose * compose);
322 static void compose_add_field_list ( Compose *compose,
323 GList *listAddress );
325 /* callback functions */
327 static gboolean compose_edit_size_alloc (GtkEditable *widget,
328 GtkAllocation *allocation,
329 GtkSHRuler *shruler);
330 static void account_activated (GtkMenuItem *menuitem,
332 static void attach_selected (GtkTreeView *tree_view,
333 GtkTreePath *tree_path,
334 GtkTreeViewColumn *column,
336 static gboolean attach_button_pressed (GtkWidget *widget,
337 GdkEventButton *event,
339 static gboolean attach_key_pressed (GtkWidget *widget,
343 static void compose_send_cb (gpointer data,
346 static void compose_send_later_cb (gpointer data,
350 static void compose_draft_cb (gpointer data,
354 static void compose_attach_cb (gpointer data,
357 static void compose_insert_file_cb (gpointer data,
360 static void compose_insert_sig_cb (gpointer data,
364 static void compose_close_cb (gpointer data,
368 static void compose_set_encoding_cb (gpointer data,
372 static void compose_address_cb (gpointer data,
375 static void compose_template_activate_cb(GtkWidget *widget,
378 static void compose_ext_editor_cb (gpointer data,
382 static gint compose_delete_cb (GtkWidget *widget,
386 static void compose_undo_cb (Compose *compose);
387 static void compose_redo_cb (Compose *compose);
388 static void compose_cut_cb (Compose *compose);
389 static void compose_copy_cb (Compose *compose);
390 static void compose_paste_cb (Compose *compose);
391 static void compose_paste_as_quote_cb (Compose *compose);
392 static void compose_paste_no_wrap_cb (Compose *compose);
393 static void compose_paste_wrap_cb (Compose *compose);
394 static void compose_allsel_cb (Compose *compose);
396 static void compose_advanced_action_cb (Compose *compose,
397 ComposeCallAdvancedAction action);
399 static void compose_grab_focus_cb (GtkWidget *widget,
402 static void compose_changed_cb (GtkTextBuffer *textbuf,
405 static void compose_wrap_cb (gpointer data,
408 static void compose_toggle_autowrap_cb (gpointer data,
412 static void compose_toggle_ruler_cb (gpointer data,
415 static void compose_toggle_sign_cb (gpointer data,
418 static void compose_toggle_encrypt_cb (gpointer data,
421 static void compose_set_privacy_system_cb(GtkWidget *widget,
423 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
424 static void activate_privacy_system (Compose *compose,
425 PrefsAccount *account,
427 static void compose_use_signing(Compose *compose, gboolean use_signing);
428 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
429 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
431 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
433 static void compose_set_priority_cb (gpointer data,
437 static void compose_attach_drag_received_cb (GtkWidget *widget,
438 GdkDragContext *drag_context,
441 GtkSelectionData *data,
445 static void compose_insert_drag_received_cb (GtkWidget *widget,
446 GdkDragContext *drag_context,
449 GtkSelectionData *data,
453 static void compose_header_drag_received_cb (GtkWidget *widget,
454 GdkDragContext *drag_context,
457 GtkSelectionData *data,
462 static gboolean compose_drag_drop (GtkWidget *widget,
463 GdkDragContext *drag_context,
465 guint time, gpointer user_data);
467 static void text_inserted (GtkTextBuffer *buffer,
472 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
473 gboolean to_all, gboolean to_ml,
475 gboolean followup_and_reply_to,
478 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
479 ComposeHeaderEntry *headerentry);
480 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
482 ComposeHeaderEntry *headerentry);
484 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
486 static void compose_allow_user_actions (Compose *compose, gboolean allow);
489 static void compose_check_all (Compose *compose);
490 static void compose_highlight_all (Compose *compose);
491 static void compose_check_backwards (Compose *compose);
492 static void compose_check_forwards_go (Compose *compose);
495 static gint compose_defer_auto_save_draft (Compose *compose);
496 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
498 static gboolean compose_close (Compose *compose);
500 static GtkItemFactoryEntry compose_popup_entries[] =
502 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
503 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
504 {N_("/---"), NULL, NULL, 0, "<Separator>"},
505 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
508 static GtkItemFactoryEntry compose_entries[] =
510 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
511 {N_("/_Message/_Send"), "<control>Return",
512 compose_send_cb, 0, NULL},
513 {N_("/_Message/Send _later"), "<shift><control>S",
514 compose_send_later_cb, 0, NULL},
515 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
516 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
517 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
518 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
519 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
520 {N_("/_Message/_Save"),
521 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
522 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
523 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
525 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
526 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
527 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
528 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
529 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
530 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
531 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
532 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
533 {N_("/_Edit/Special paste/as _quotation"),
534 NULL, compose_paste_as_quote_cb, 0, NULL},
535 {N_("/_Edit/Special paste/_wrapped"),
536 NULL, compose_paste_wrap_cb, 0, NULL},
537 {N_("/_Edit/Special paste/_unwrapped"),
538 NULL, compose_paste_no_wrap_cb, 0, NULL},
539 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
540 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
541 {N_("/_Edit/A_dvanced/Move a character backward"),
543 compose_advanced_action_cb,
544 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
546 {N_("/_Edit/A_dvanced/Move a character forward"),
548 compose_advanced_action_cb,
549 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
551 {N_("/_Edit/A_dvanced/Move a word backward"),
553 compose_advanced_action_cb,
554 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
556 {N_("/_Edit/A_dvanced/Move a word forward"),
558 compose_advanced_action_cb,
559 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
561 {N_("/_Edit/A_dvanced/Move to beginning of line"),
562 NULL, /* "<control>A" */
563 compose_advanced_action_cb,
564 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
566 {N_("/_Edit/A_dvanced/Move to end of line"),
568 compose_advanced_action_cb,
569 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
571 {N_("/_Edit/A_dvanced/Move to previous line"),
573 compose_advanced_action_cb,
574 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
576 {N_("/_Edit/A_dvanced/Move to next line"),
578 compose_advanced_action_cb,
579 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
581 {N_("/_Edit/A_dvanced/Delete a character backward"),
583 compose_advanced_action_cb,
584 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
586 {N_("/_Edit/A_dvanced/Delete a character forward"),
588 compose_advanced_action_cb,
589 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
591 {N_("/_Edit/A_dvanced/Delete a word backward"),
592 NULL, /* "<control>W" */
593 compose_advanced_action_cb,
594 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
596 {N_("/_Edit/A_dvanced/Delete a word forward"),
597 NULL, /* "<alt>D", */
598 compose_advanced_action_cb,
599 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
601 {N_("/_Edit/A_dvanced/Delete line"),
603 compose_advanced_action_cb,
604 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
606 {N_("/_Edit/A_dvanced/Delete entire line"),
608 compose_advanced_action_cb,
609 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
611 {N_("/_Edit/A_dvanced/Delete to end of line"),
613 compose_advanced_action_cb,
614 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
616 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
617 {N_("/_Edit/_Wrap current paragraph"),
618 "<control>L", compose_wrap_cb, 0, NULL},
619 {N_("/_Edit/Wrap all long _lines"),
620 "<control><alt>L", compose_wrap_cb, 1, NULL},
621 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
622 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
623 {N_("/_Edit/Edit with e_xternal editor"),
624 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
626 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
627 {N_("/_Spelling/_Check all or check selection"),
628 NULL, compose_check_all, 0, NULL},
629 {N_("/_Spelling/_Highlight all misspelled words"),
630 NULL, compose_highlight_all, 0, NULL},
631 {N_("/_Spelling/Check _backwards misspelled word"),
632 NULL, compose_check_backwards , 0, NULL},
633 {N_("/_Spelling/_Forward to next misspelled word"),
634 NULL, compose_check_forwards_go, 0, NULL},
636 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
637 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
638 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
639 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
640 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
641 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
642 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
643 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
644 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
645 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
646 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
647 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
648 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
649 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
650 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
651 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
652 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
654 #define ENC_ACTION(action) \
655 NULL, compose_set_encoding_cb, action, \
656 "/Options/Character encoding/Automatic"
658 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
659 {N_("/_Options/Character _encoding/_Automatic"),
660 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
661 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
663 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
664 ENC_ACTION(C_US_ASCII)},
665 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
666 ENC_ACTION(C_UTF_8)},
667 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
669 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
670 ENC_ACTION(C_ISO_8859_1)},
671 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
672 ENC_ACTION(C_ISO_8859_15)},
673 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
675 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
676 ENC_ACTION(C_ISO_8859_2)},
677 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
679 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
680 ENC_ACTION(C_ISO_8859_13)},
681 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
682 ENC_ACTION(C_ISO_8859_4)},
683 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
685 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
686 ENC_ACTION(C_ISO_8859_7)},
687 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
689 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
690 ENC_ACTION(C_ISO_8859_8)},
691 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
692 ENC_ACTION(C_WINDOWS_1255)},
693 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
695 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
696 ENC_ACTION(C_ISO_8859_9)},
697 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
699 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
700 ENC_ACTION(C_ISO_8859_5)},
701 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
702 ENC_ACTION(C_KOI8_R)},
703 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
704 ENC_ACTION(C_KOI8_U)},
705 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
706 ENC_ACTION(C_WINDOWS_1251)},
707 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
709 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
710 ENC_ACTION(C_ISO_2022_JP)},
711 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
713 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
714 ENC_ACTION(C_GB2312)},
715 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
717 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
719 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
720 ENC_ACTION(C_EUC_TW)},
721 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
723 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
724 ENC_ACTION(C_EUC_KR)},
725 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
727 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
728 ENC_ACTION(C_TIS_620)},
729 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
730 ENC_ACTION(C_WINDOWS_874)},
732 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
733 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
734 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
735 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
736 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
737 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
738 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
741 static GtkTargetEntry compose_mime_types[] =
743 {"text/uri-list", 0, 0},
744 {"text/plain", 0, 0},
748 static gboolean compose_put_existing_to_front(MsgInfo *info)
750 GList *compose_list = compose_get_compose_list();
754 for (elem = compose_list; elem != NULL && elem->data != NULL;
756 Compose *c = (Compose*)elem->data;
758 if (!c->targetinfo || !c->targetinfo->msgid ||
762 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
763 gtkut_window_popup(c->window);
771 static GdkColor quote_color =
772 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
774 static GdkColor signature_color = {
781 static GdkColor uri_color = {
788 static void compose_create_tags(GtkTextView *text, Compose *compose)
790 GtkTextBuffer *buffer;
791 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
793 buffer = gtk_text_view_get_buffer(text);
795 if (prefs_common.enable_color) {
796 /* grab the quote colors, converting from an int to a GdkColor */
797 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
799 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
801 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
804 signature_color = quote_color = uri_color = black;
807 gtk_text_buffer_create_tag(buffer, "quote",
808 "foreground-gdk", "e_color,
810 gtk_text_buffer_create_tag(buffer, "signature",
811 "foreground-gdk", &signature_color,
813 gtk_text_buffer_create_tag(buffer, "link",
814 "foreground-gdk", &uri_color,
816 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
819 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
820 GPtrArray *attach_files)
822 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
825 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
827 return compose_generic_new(account, NULL, item, NULL, NULL);
830 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
832 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
835 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
836 GPtrArray *attach_files, GList *listAddress )
839 GtkTextView *textview;
840 GtkTextBuffer *textbuf;
842 GtkItemFactory *ifactory;
844 if (item && item->prefs && item->prefs->enable_default_account)
845 account = account_find_from_id(item->prefs->default_account);
847 if (!account) account = cur_account;
848 g_return_val_if_fail(account != NULL, NULL);
850 compose = compose_create(account, COMPOSE_NEW);
851 ifactory = gtk_item_factory_from_widget(compose->menubar);
853 compose->replyinfo = NULL;
854 compose->fwdinfo = NULL;
856 textview = GTK_TEXT_VIEW(compose->text);
857 textbuf = gtk_text_view_get_buffer(textview);
858 compose_create_tags(textview, compose);
860 undo_block(compose->undostruct);
862 if (item && item->prefs && item->prefs->enable_default_dictionary &&
864 gtkaspell_change_dict(compose->gtkaspell,
865 item->prefs->default_dictionary);
868 if (account->auto_sig)
869 compose_insert_sig(compose, FALSE);
870 gtk_text_buffer_get_start_iter(textbuf, &iter);
871 gtk_text_buffer_place_cursor(textbuf, &iter);
873 if (account->protocol != A_NNTP) {
874 if (mailto && *mailto != '\0') {
875 compose_entries_set(compose, mailto);
877 } else if (item && item->prefs->enable_default_to) {
878 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
879 compose_entry_mark_default_to(compose, item->prefs->default_to);
881 if (item && item->ret_rcpt) {
882 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
886 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
888 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
891 * CLAWS: just don't allow return receipt request, even if the user
892 * may want to send an email. simple but foolproof.
894 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
896 compose_add_field_list( compose, listAddress );
902 for (i = 0; i < attach_files->len; i++) {
903 file = g_ptr_array_index(attach_files, i);
904 compose_attach_append(compose, file, file, NULL);
908 compose_show_first_last_header(compose, TRUE);
910 /* Set save folder */
911 if (item && item->prefs && item->prefs->save_copy_to_folder) {
912 gchar *folderidentifier;
914 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
915 folderidentifier = folder_item_get_identifier(item);
916 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
917 g_free(folderidentifier);
920 gtk_widget_grab_focus(compose->header_last->entry);
922 undo_unblock(compose->undostruct);
924 if (prefs_common.auto_exteditor)
925 compose_exec_ext_editor(compose);
927 compose_set_title(compose);
931 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
932 gboolean override_pref)
934 gchar *privacy = NULL;
936 g_return_if_fail(compose != NULL);
937 g_return_if_fail(account != NULL);
939 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
942 if (account->default_privacy_system
943 && strlen(account->default_privacy_system)) {
944 privacy = account->default_privacy_system;
946 GSList *privacy_avail = privacy_get_system_ids();
947 if (privacy_avail && g_slist_length(privacy_avail)) {
948 privacy = (gchar *)(privacy_avail->data);
951 if (privacy != NULL) {
952 compose->privacy_system = g_strdup(privacy);
953 compose_update_privacy_system_menu_item(compose, FALSE);
954 compose_use_encryption(compose, TRUE);
958 static void compose_force_signing(Compose *compose, PrefsAccount *account)
960 gchar *privacy = NULL;
962 if (account->default_privacy_system
963 && strlen(account->default_privacy_system)) {
964 privacy = account->default_privacy_system;
966 GSList *privacy_avail = privacy_get_system_ids();
967 if (privacy_avail && g_slist_length(privacy_avail)) {
968 privacy = (gchar *)(privacy_avail->data);
971 if (privacy != NULL) {
972 compose->privacy_system = g_strdup(privacy);
973 compose_update_privacy_system_menu_item(compose, FALSE);
974 compose_use_signing(compose, TRUE);
978 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
982 Compose *compose = NULL;
983 g_return_val_if_fail(msginfo_list != NULL, NULL);
985 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
986 g_return_val_if_fail(msginfo != NULL, NULL);
988 list_len = g_slist_length(msginfo_list);
992 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
993 FALSE, prefs_common.default_reply_list, FALSE, body);
995 case COMPOSE_REPLY_WITH_QUOTE:
996 compose = compose_reply(msginfo, TRUE,
997 FALSE, prefs_common.default_reply_list, FALSE, body);
999 case COMPOSE_REPLY_WITHOUT_QUOTE:
1000 compose = compose_reply(msginfo, FALSE,
1001 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1003 case COMPOSE_REPLY_TO_SENDER:
1004 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1005 FALSE, FALSE, TRUE, body);
1007 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1008 compose = compose_followup_and_reply_to(msginfo,
1009 prefs_common.reply_with_quote,
1010 FALSE, FALSE, body);
1012 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1013 compose = compose_reply(msginfo, TRUE,
1014 FALSE, FALSE, TRUE, body);
1016 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1017 compose = compose_reply(msginfo, FALSE,
1018 FALSE, FALSE, TRUE, NULL);
1020 case COMPOSE_REPLY_TO_ALL:
1021 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1022 TRUE, FALSE, FALSE, body);
1024 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1025 compose = compose_reply(msginfo, TRUE,
1026 TRUE, FALSE, FALSE, body);
1028 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1029 compose = compose_reply(msginfo, FALSE,
1030 TRUE, FALSE, FALSE, NULL);
1032 case COMPOSE_REPLY_TO_LIST:
1033 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1034 FALSE, TRUE, FALSE, body);
1036 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1037 compose = compose_reply(msginfo, TRUE,
1038 FALSE, TRUE, FALSE, body);
1040 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1041 compose = compose_reply(msginfo, FALSE,
1042 FALSE, TRUE, FALSE, NULL);
1044 case COMPOSE_FORWARD:
1045 if (prefs_common.forward_as_attachment) {
1046 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1049 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1053 case COMPOSE_FORWARD_INLINE:
1054 /* check if we reply to more than one Message */
1055 if (list_len == 1) {
1056 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE);
1059 /* more messages FALL THROUGH */
1060 case COMPOSE_FORWARD_AS_ATTACH:
1061 compose = compose_forward_multiple(NULL, msginfo_list);
1063 case COMPOSE_REDIRECT:
1064 compose = compose_redirect(NULL, msginfo);
1067 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1072 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1073 gboolean to_ml, gboolean to_sender,
1076 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1077 to_sender, FALSE, body);
1080 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1085 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1086 to_sender, TRUE, body);
1089 static void compose_extract_original_charset(Compose *compose)
1091 MsgInfo *info = NULL;
1092 if (compose->replyinfo) {
1093 info = compose->replyinfo;
1094 } else if (compose->fwdinfo) {
1095 info = compose->fwdinfo;
1096 } else if (compose->targetinfo) {
1097 info = compose->targetinfo;
1100 MimeInfo *mimeinfo = procmime_scan_message(info);
1101 MimeInfo *partinfo = mimeinfo;
1102 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1103 partinfo = procmime_mimeinfo_next(partinfo);
1105 compose->orig_charset =
1106 g_strdup(procmime_mimeinfo_get_parameter(
1107 partinfo, "charset"));
1109 procmime_mimeinfo_free_all(mimeinfo);
1113 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1114 gboolean to_all, gboolean to_ml,
1116 gboolean followup_and_reply_to,
1119 GtkItemFactory *ifactory;
1121 PrefsAccount *account = NULL;
1122 PrefsAccount *reply_account;
1123 GtkTextView *textview;
1124 GtkTextBuffer *textbuf;
1126 g_return_val_if_fail(msginfo != NULL, NULL);
1127 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1129 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1131 g_return_val_if_fail(account != NULL, NULL);
1133 if (to_sender && account->protocol == A_NNTP &&
1134 !followup_and_reply_to) {
1136 account_find_from_address(account->address);
1138 reply_account = compose_current_mail_account();
1142 reply_account = account;
1144 compose = compose_create(account, COMPOSE_REPLY);
1145 ifactory = gtk_item_factory_from_widget(compose->menubar);
1147 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1148 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1150 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1152 if (!compose->replyinfo)
1153 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1155 compose_extract_original_charset(compose);
1157 if (msginfo->folder && msginfo->folder->ret_rcpt)
1158 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1160 /* Set save folder */
1161 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1162 gchar *folderidentifier;
1164 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1165 folderidentifier = folder_item_get_identifier(msginfo->folder);
1166 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1167 g_free(folderidentifier);
1170 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1171 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1172 to_sender, followup_and_reply_to);
1173 compose_show_first_last_header(compose, TRUE);
1175 textview = (GTK_TEXT_VIEW(compose->text));
1176 textbuf = gtk_text_view_get_buffer(textview);
1177 compose_create_tags(textview, compose);
1179 undo_block(compose->undostruct);
1181 if (msginfo->folder && msginfo->folder->prefs &&
1182 msginfo->folder->prefs &&
1183 msginfo->folder->prefs->enable_default_dictionary &&
1185 gtkaspell_change_dict(compose->gtkaspell,
1186 msginfo->folder->prefs->default_dictionary);
1192 if (prefs_common.quotemark && *prefs_common.quotemark)
1193 qmark = prefs_common.quotemark;
1197 compose_quote_fmt(compose, compose->replyinfo,
1198 prefs_common.quotefmt,
1201 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1202 compose_force_encryption(compose, account, FALSE);
1205 if (account->auto_sig)
1206 compose_insert_sig(compose, FALSE);
1208 compose_wrap_all(compose);
1210 gtk_widget_grab_focus(compose->text);
1212 undo_unblock(compose->undostruct);
1214 if (prefs_common.auto_exteditor)
1215 compose_exec_ext_editor(compose);
1217 compose_set_title(compose);
1221 #define INSERT_FW_HEADER(var, hdr) \
1222 if (msginfo->var && *msginfo->var) { \
1223 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1224 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1225 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1228 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1229 gboolean as_attach, const gchar *body,
1230 gboolean no_extedit)
1233 GtkTextView *textview;
1234 GtkTextBuffer *textbuf;
1237 g_return_val_if_fail(msginfo != NULL, NULL);
1238 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1241 !(account = compose_guess_forward_account_from_msginfo
1243 account = cur_account;
1245 compose = compose_create(account, COMPOSE_FORWARD);
1247 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1248 if (!compose->fwdinfo)
1249 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1251 compose_extract_original_charset(compose);
1253 if (msginfo->subject && *msginfo->subject) {
1254 gchar *buf, *buf2, *p;
1256 buf = p = g_strdup(msginfo->subject);
1257 p += subject_get_prefix_length(p);
1258 memmove(buf, p, strlen(p) + 1);
1260 buf2 = g_strdup_printf("Fw: %s", buf);
1261 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1267 textview = GTK_TEXT_VIEW(compose->text);
1268 textbuf = gtk_text_view_get_buffer(textview);
1269 compose_create_tags(textview, compose);
1274 msgfile = procmsg_get_message_file_path(msginfo);
1275 if (!is_file_exist(msgfile))
1276 g_warning("%s: file not exist\n", msgfile);
1278 compose_attach_append(compose, msgfile, msgfile,
1284 MsgInfo *full_msginfo;
1286 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1288 full_msginfo = procmsg_msginfo_copy(msginfo);
1290 if (prefs_common.fw_quotemark &&
1291 *prefs_common.fw_quotemark)
1292 qmark = prefs_common.fw_quotemark;
1296 compose_quote_fmt(compose, full_msginfo,
1297 prefs_common.fw_quotefmt,
1299 compose_attach_parts(compose, msginfo);
1301 procmsg_msginfo_free(full_msginfo);
1304 if (account->auto_sig)
1305 compose_insert_sig(compose, FALSE);
1307 compose_wrap_all(compose);
1309 gtk_text_buffer_get_start_iter(textbuf, &iter);
1310 gtk_text_buffer_place_cursor(textbuf, &iter);
1312 gtk_widget_grab_focus(compose->header_last->entry);
1314 if (!no_extedit && prefs_common.auto_exteditor)
1315 compose_exec_ext_editor(compose);
1318 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1319 gchar *folderidentifier;
1321 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1322 folderidentifier = folder_item_get_identifier(msginfo->folder);
1323 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1324 g_free(folderidentifier);
1327 compose_set_title(compose);
1331 #undef INSERT_FW_HEADER
1333 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1336 GtkTextView *textview;
1337 GtkTextBuffer *textbuf;
1341 gboolean single_mail = TRUE;
1343 g_return_val_if_fail(msginfo_list != NULL, NULL);
1345 if (g_slist_length(msginfo_list) > 1)
1346 single_mail = FALSE;
1348 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1349 if (((MsgInfo *)msginfo->data)->folder == NULL)
1352 /* guess account from first selected message */
1354 !(account = compose_guess_forward_account_from_msginfo
1355 (msginfo_list->data)))
1356 account = cur_account;
1358 g_return_val_if_fail(account != NULL, NULL);
1360 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1361 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1362 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1365 compose = compose_create(account, COMPOSE_FORWARD);
1367 textview = GTK_TEXT_VIEW(compose->text);
1368 textbuf = gtk_text_view_get_buffer(textview);
1369 compose_create_tags(textview, compose);
1371 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1372 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1373 if (!is_file_exist(msgfile))
1374 g_warning("%s: file not exist\n", msgfile);
1376 compose_attach_append(compose, msgfile, msgfile,
1382 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1383 if (info->subject && *info->subject) {
1384 gchar *buf, *buf2, *p;
1386 buf = p = g_strdup(info->subject);
1387 p += subject_get_prefix_length(p);
1388 memmove(buf, p, strlen(p) + 1);
1390 buf2 = g_strdup_printf("Fw: %s", buf);
1391 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1397 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1398 _("Fw: multiple emails"));
1401 if (account->auto_sig)
1402 compose_insert_sig(compose, FALSE);
1404 compose_wrap_all(compose);
1406 gtk_text_buffer_get_start_iter(textbuf, &iter);
1407 gtk_text_buffer_place_cursor(textbuf, &iter);
1409 gtk_widget_grab_focus(compose->header_last->entry);
1411 compose_set_title(compose);
1415 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1417 GtkTextIter start = *iter;
1418 GtkTextIter end_iter;
1419 int start_pos = gtk_text_iter_get_offset(&start);
1421 if (!compose->account->sig_sep)
1424 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1425 start_pos+strlen(compose->account->sig_sep));
1427 /* check sig separator */
1428 str = gtk_text_iter_get_text(&start, &end_iter);
1429 if (!strcmp(str, compose->account->sig_sep)) {
1431 /* check end of line (\n) */
1432 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1433 start_pos+strlen(compose->account->sig_sep));
1434 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1435 start_pos+strlen(compose->account->sig_sep)+1);
1436 tmp = gtk_text_iter_get_text(&start, &end_iter);
1437 if (!strcmp(tmp,"\n")) {
1449 static void compose_colorize_signature(Compose *compose)
1451 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1453 GtkTextIter end_iter;
1454 gtk_text_buffer_get_start_iter(buffer, &iter);
1455 while (gtk_text_iter_forward_line(&iter))
1456 if (compose_is_sig_separator(compose, buffer, &iter)) {
1457 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1458 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1462 void compose_reedit(MsgInfo *msginfo)
1464 Compose *compose = NULL;
1465 PrefsAccount *account = NULL;
1466 GtkTextView *textview;
1467 GtkTextBuffer *textbuf;
1471 gchar buf[BUFFSIZE];
1472 gboolean use_signing = FALSE;
1473 gboolean use_encryption = FALSE;
1474 gchar *privacy_system = NULL;
1476 g_return_if_fail(msginfo != NULL);
1477 g_return_if_fail(msginfo->folder != NULL);
1479 if (compose_put_existing_to_front(msginfo))
1482 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1483 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1484 gchar queueheader_buf[BUFFSIZE];
1487 /* Select Account from queue headers */
1488 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1489 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1490 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1491 account = account_find_from_id(id);
1493 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1494 sizeof(queueheader_buf), "NAID:")) {
1495 id = atoi(&queueheader_buf[strlen("NAID:")]);
1496 account = account_find_from_id(id);
1498 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1499 sizeof(queueheader_buf), "MAID:")) {
1500 id = atoi(&queueheader_buf[strlen("MAID:")]);
1501 account = account_find_from_id(id);
1503 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1504 sizeof(queueheader_buf), "S:")) {
1505 account = account_find_from_address(queueheader_buf);
1507 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1508 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1509 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1510 use_signing = param;
1513 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1514 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1515 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1516 use_encryption = param;
1518 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1519 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1520 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1522 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1523 sizeof(queueheader_buf), "X-Priority: ")) {
1524 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1525 compose->priority = param;
1528 account = msginfo->folder->folder->account;
1530 if (!account && prefs_common.reedit_account_autosel) {
1531 gchar from[BUFFSIZE];
1532 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1533 extract_address(from);
1534 account = account_find_from_address(from);
1537 if (!account) account = cur_account;
1538 g_return_if_fail(account != NULL);
1540 compose = compose_create(account, COMPOSE_REEDIT);
1541 if (privacy_system != NULL) {
1542 compose->privacy_system = privacy_system;
1543 compose_use_signing(compose, use_signing);
1544 compose_use_encryption(compose, use_encryption);
1545 compose_update_privacy_system_menu_item(compose, FALSE);
1547 activate_privacy_system(compose, account, FALSE);
1549 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1551 compose_extract_original_charset(compose);
1553 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1554 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1555 gchar queueheader_buf[BUFFSIZE];
1557 /* Set message save folder */
1558 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1561 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1562 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1563 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1567 if (compose_parse_header(compose, msginfo) < 0) return;
1568 compose_reedit_set_entry(compose, msginfo);
1570 textview = GTK_TEXT_VIEW(compose->text);
1571 textbuf = gtk_text_view_get_buffer(textview);
1572 compose_create_tags(textview, compose);
1574 mark = gtk_text_buffer_get_insert(textbuf);
1575 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1577 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1578 G_CALLBACK(compose_changed_cb),
1581 if (procmime_msginfo_is_encrypted(msginfo)) {
1582 fp = procmime_get_first_encrypted_text_content(msginfo);
1584 compose_force_encryption(compose, account, TRUE);
1586 fp = procmime_get_first_text_content(msginfo);
1588 g_warning("Can't get text part\n");
1591 gboolean prev_autowrap = compose->autowrap;
1593 compose->autowrap = FALSE;
1594 while (fgets(buf, sizeof(buf), fp) != NULL) {
1596 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1598 compose_wrap_all_full(compose, FALSE);
1599 compose->autowrap = prev_autowrap;
1603 compose_attach_parts(compose, msginfo);
1605 compose_colorize_signature(compose);
1607 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1608 G_CALLBACK(compose_changed_cb),
1611 gtk_widget_grab_focus(compose->text);
1613 if (prefs_common.auto_exteditor)
1614 compose_exec_ext_editor(compose);
1615 compose_set_title(compose);
1618 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1622 GtkItemFactory *ifactory;
1625 g_return_val_if_fail(msginfo != NULL, NULL);
1628 account = account_get_reply_account(msginfo,
1629 prefs_common.reply_account_autosel);
1630 g_return_val_if_fail(account != NULL, NULL);
1632 compose = compose_create(account, COMPOSE_REDIRECT);
1633 ifactory = gtk_item_factory_from_widget(compose->menubar);
1634 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1635 compose->replyinfo = NULL;
1636 compose->fwdinfo = NULL;
1638 compose_show_first_last_header(compose, TRUE);
1640 gtk_widget_grab_focus(compose->header_last->entry);
1642 filename = procmsg_get_message_file_path(msginfo);
1643 if (filename == NULL)
1646 compose->redirect_filename = filename;
1648 /* Set save folder */
1649 item = msginfo->folder;
1650 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1651 gchar *folderidentifier;
1653 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1654 folderidentifier = folder_item_get_identifier(item);
1655 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1656 g_free(folderidentifier);
1659 compose_attach_parts(compose, msginfo);
1661 if (msginfo->subject)
1662 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1664 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1666 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1667 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1669 compose_colorize_signature(compose);
1671 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1672 menu_set_sensitive(ifactory, "/Add...", FALSE);
1673 menu_set_sensitive(ifactory, "/Remove", FALSE);
1674 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1676 ifactory = gtk_item_factory_from_widget(compose->menubar);
1677 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1678 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1679 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1680 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1681 menu_set_sensitive(ifactory, "/Edit", FALSE);
1682 menu_set_sensitive(ifactory, "/Options", FALSE);
1683 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1684 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1686 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1687 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1688 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1689 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1690 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1691 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1692 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1694 compose_set_title(compose);
1698 GList *compose_get_compose_list(void)
1700 return compose_list;
1703 void compose_entry_append(Compose *compose, const gchar *address,
1704 ComposeEntryType type)
1708 gboolean in_quote = FALSE;
1709 if (!address || *address == '\0') return;
1716 header = N_("Bcc:");
1718 case COMPOSE_REPLYTO:
1719 header = N_("Reply-To:");
1721 case COMPOSE_NEWSGROUPS:
1722 header = N_("Newsgroups:");
1724 case COMPOSE_FOLLOWUPTO:
1725 header = N_( "Followup-To:");
1732 header = prefs_common.trans_hdr ? gettext(header) : header;
1734 cur = begin = (gchar *)address;
1736 /* we separate the line by commas, but not if we're inside a quoted
1738 while (*cur != '\0') {
1740 in_quote = !in_quote;
1741 if (*cur == ',' && !in_quote) {
1742 gchar *tmp = g_strdup(begin);
1744 tmp[cur-begin]='\0';
1749 compose_add_header_entry(compose, header, tmp);
1756 gchar *tmp = g_strdup(begin);
1758 tmp[cur-begin]='\0';
1763 compose_add_header_entry(compose, header, tmp);
1768 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1770 static GtkStyle *bold_style = NULL;
1771 static GdkColor bold_color;
1775 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1776 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1777 if (gtk_entry_get_text(entry) &&
1778 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1779 gtk_widget_ensure_style(GTK_WIDGET(entry));
1781 gtkut_convert_int_to_gdk_color
1782 (prefs_common.color_new, &bold_color);
1783 bold_style = gtk_style_copy(gtk_widget_get_style
1784 (GTK_WIDGET(entry)));
1785 pango_font_description_set_weight
1786 (bold_style->font_desc, PANGO_WEIGHT_BOLD);
1787 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1789 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1794 void compose_toolbar_cb(gint action, gpointer data)
1796 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1797 Compose *compose = (Compose*)toolbar_item->parent;
1799 g_return_if_fail(compose != NULL);
1803 compose_send_cb(compose, 0, NULL);
1806 compose_send_later_cb(compose, 0, NULL);
1809 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1812 compose_insert_file_cb(compose, 0, NULL);
1815 compose_attach_cb(compose, 0, NULL);
1818 compose_insert_sig(compose, FALSE);
1821 compose_ext_editor_cb(compose, 0, NULL);
1823 case A_LINEWRAP_CURRENT:
1824 compose_beautify_paragraph(compose, NULL, TRUE);
1826 case A_LINEWRAP_ALL:
1827 compose_wrap_all_full(compose, TRUE);
1830 compose_address_cb(compose, 0, NULL);
1833 case A_CHECK_SPELLING:
1834 compose_check_all(compose);
1842 static void compose_entries_set(Compose *compose, const gchar *mailto)
1846 gchar *subject = NULL;
1851 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1854 compose_entry_append(compose, to, COMPOSE_TO);
1856 compose_entry_append(compose, cc, COMPOSE_CC);
1858 if (!g_utf8_validate (subject, -1, NULL)) {
1859 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1860 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1863 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1867 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1868 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1871 gboolean prev_autowrap = compose->autowrap;
1873 compose->autowrap = FALSE;
1875 mark = gtk_text_buffer_get_insert(buffer);
1876 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1878 if (!g_utf8_validate (body, -1, NULL)) {
1879 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1880 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1883 gtk_text_buffer_insert(buffer, &iter, body, -1);
1885 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1887 compose->autowrap = prev_autowrap;
1888 if (compose->autowrap)
1889 compose_wrap_all(compose);
1898 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1900 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1901 {"Cc:", NULL, TRUE},
1902 {"References:", NULL, FALSE},
1903 {"Bcc:", NULL, TRUE},
1904 {"Newsgroups:", NULL, TRUE},
1905 {"Followup-To:", NULL, TRUE},
1906 {"List-Post:", NULL, FALSE},
1907 {"X-Priority:", NULL, FALSE},
1908 {NULL, NULL, FALSE}};
1924 g_return_val_if_fail(msginfo != NULL, -1);
1926 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1927 procheader_get_header_fields(fp, hentry);
1930 if (hentry[H_REPLY_TO].body != NULL) {
1931 if (hentry[H_REPLY_TO].body[0] != '\0') {
1933 conv_unmime_header(hentry[H_REPLY_TO].body,
1936 g_free(hentry[H_REPLY_TO].body);
1937 hentry[H_REPLY_TO].body = NULL;
1939 if (hentry[H_CC].body != NULL) {
1940 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
1941 g_free(hentry[H_CC].body);
1942 hentry[H_CC].body = NULL;
1944 if (hentry[H_REFERENCES].body != NULL) {
1945 if (compose->mode == COMPOSE_REEDIT)
1946 compose->references = hentry[H_REFERENCES].body;
1948 compose->references = compose_parse_references
1949 (hentry[H_REFERENCES].body, msginfo->msgid);
1950 g_free(hentry[H_REFERENCES].body);
1952 hentry[H_REFERENCES].body = NULL;
1954 if (hentry[H_BCC].body != NULL) {
1955 if (compose->mode == COMPOSE_REEDIT)
1957 conv_unmime_header(hentry[H_BCC].body, NULL);
1958 g_free(hentry[H_BCC].body);
1959 hentry[H_BCC].body = NULL;
1961 if (hentry[H_NEWSGROUPS].body != NULL) {
1962 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1963 hentry[H_NEWSGROUPS].body = NULL;
1965 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1966 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
1967 compose->followup_to =
1968 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
1971 g_free(hentry[H_FOLLOWUP_TO].body);
1972 hentry[H_FOLLOWUP_TO].body = NULL;
1974 if (hentry[H_LIST_POST].body != NULL) {
1977 extract_address(hentry[H_LIST_POST].body);
1978 if (hentry[H_LIST_POST].body[0] != '\0') {
1979 scan_mailto_url(hentry[H_LIST_POST].body,
1980 &to, NULL, NULL, NULL, NULL);
1982 g_free(compose->ml_post);
1983 compose->ml_post = to;
1986 g_free(hentry[H_LIST_POST].body);
1987 hentry[H_LIST_POST].body = NULL;
1990 /* CLAWS - X-Priority */
1991 if (compose->mode == COMPOSE_REEDIT)
1992 if (hentry[H_X_PRIORITY].body != NULL) {
1995 priority = atoi(hentry[H_X_PRIORITY].body);
1996 g_free(hentry[H_X_PRIORITY].body);
1998 hentry[H_X_PRIORITY].body = NULL;
2000 if (priority < PRIORITY_HIGHEST ||
2001 priority > PRIORITY_LOWEST)
2002 priority = PRIORITY_NORMAL;
2004 compose->priority = priority;
2007 if (compose->mode == COMPOSE_REEDIT) {
2008 if (msginfo->inreplyto && *msginfo->inreplyto)
2009 compose->inreplyto = g_strdup(msginfo->inreplyto);
2013 if (msginfo->msgid && *msginfo->msgid)
2014 compose->inreplyto = g_strdup(msginfo->msgid);
2016 if (!compose->references) {
2017 if (msginfo->msgid && *msginfo->msgid) {
2018 if (msginfo->inreplyto && *msginfo->inreplyto)
2019 compose->references =
2020 g_strdup_printf("<%s>\n\t<%s>",
2024 compose->references =
2025 g_strconcat("<", msginfo->msgid, ">",
2027 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2028 compose->references =
2029 g_strconcat("<", msginfo->inreplyto, ">",
2037 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2039 GSList *ref_id_list, *cur;
2043 ref_id_list = references_list_append(NULL, ref);
2044 if (!ref_id_list) return NULL;
2045 if (msgid && *msgid)
2046 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2051 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2052 /* "<" + Message-ID + ">" + CR+LF+TAB */
2053 len += strlen((gchar *)cur->data) + 5;
2055 if (len > MAX_REFERENCES_LEN) {
2056 /* remove second message-ID */
2057 if (ref_id_list && ref_id_list->next &&
2058 ref_id_list->next->next) {
2059 g_free(ref_id_list->next->data);
2060 ref_id_list = g_slist_remove
2061 (ref_id_list, ref_id_list->next->data);
2063 slist_free_strings(ref_id_list);
2064 g_slist_free(ref_id_list);
2071 new_ref = g_string_new("");
2072 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2073 if (new_ref->len > 0)
2074 g_string_append(new_ref, "\n\t");
2075 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2078 slist_free_strings(ref_id_list);
2079 g_slist_free(ref_id_list);
2081 new_ref_str = new_ref->str;
2082 g_string_free(new_ref, FALSE);
2087 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2088 const gchar *fmt, const gchar *qmark,
2091 static MsgInfo dummyinfo;
2092 gchar *quote_str = NULL;
2096 gboolean prev_autowrap;
2097 const gchar *trimmed_body = body;
2098 gint cursor_pos = 0;
2099 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2100 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2104 msginfo = &dummyinfo;
2106 if (qmark != NULL) {
2107 quote_fmt_init(msginfo, NULL, NULL);
2108 quote_fmt_scan_string(qmark);
2111 buf = quote_fmt_get_buffer();
2113 alertpanel_error(_("Quote mark format error."));
2115 Xstrdup_a(quote_str, buf, return NULL)
2118 if (fmt && *fmt != '\0') {
2119 while (trimmed_body && strlen(trimmed_body) > 1
2120 && trimmed_body[0]=='\n')
2123 quote_fmt_init(msginfo, quote_str, trimmed_body);
2124 quote_fmt_scan_string(fmt);
2127 buf = quote_fmt_get_buffer();
2129 alertpanel_error(_("Message reply/forward format error."));
2135 prev_autowrap = compose->autowrap;
2136 compose->autowrap = FALSE;
2138 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2139 G_CALLBACK(compose_changed_cb),
2141 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2142 G_CALLBACK(text_inserted),
2144 for (p = buf; *p != '\0'; ) {
2147 mark = gtk_text_buffer_get_insert(buffer);
2148 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2150 lastp = strchr(p, '\n');
2151 len = lastp ? lastp - p + 1 : -1;
2153 if (g_utf8_validate(p, -1, NULL)) {
2154 gtk_text_buffer_insert(buffer, &iter, p, len);
2156 gchar *tmpin = g_strdup(p);
2157 gchar *tmpout = NULL;
2159 tmpout = conv_codeset_strdup
2160 (tmpin, conv_get_locale_charset_str(),
2162 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2173 cursor_pos = quote_fmt_get_cursor_pos();
2174 gtk_text_buffer_get_start_iter(buffer, &iter);
2175 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2176 gtk_text_buffer_place_cursor(buffer, &iter);
2179 compose->autowrap = prev_autowrap;
2180 if (compose->autowrap)
2181 compose_wrap_all(compose);
2183 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2184 G_CALLBACK(compose_changed_cb),
2186 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2187 G_CALLBACK(text_inserted),
2194 /* if ml_post is of type addr@host and from is of type
2195 * addr-anything@host, return TRUE
2197 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2199 gchar *left_ml = NULL;
2200 gchar *right_ml = NULL;
2201 gchar *left_from = NULL;
2202 gchar *right_from = NULL;
2203 gboolean result = FALSE;
2205 if (!ml_post || !from)
2208 left_ml = g_strdup(ml_post);
2209 if (strstr(left_ml, "@")) {
2210 right_ml = strstr(left_ml, "@")+1;
2211 *(strstr(left_ml, "@")) = '\0';
2214 left_from = g_strdup(from);
2215 if (strstr(left_from, "@")) {
2216 right_from = strstr(left_from, "@")+1;
2217 *(strstr(left_from, "@")) = '\0';
2220 if (left_ml && left_from && right_ml && right_from
2221 && !strncmp(left_from, left_ml, strlen(left_ml))
2222 && !strcmp(right_from, right_ml)) {
2231 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2233 gchar *my_addr1, *my_addr2;
2235 if (!addr1 || !addr2)
2238 Xstrdup_a(my_addr1, addr1, return FALSE);
2239 Xstrdup_a(my_addr2, addr2, return FALSE);
2241 extract_address(my_addr1);
2242 extract_address(my_addr2);
2244 return !strcmp(my_addr1, my_addr2);
2247 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2248 gboolean to_all, gboolean to_ml,
2250 gboolean followup_and_reply_to)
2252 GSList *cc_list = NULL;
2255 gchar *replyto = NULL;
2256 GHashTable *to_table;
2258 gboolean reply_to_ml = FALSE;
2259 gboolean default_reply_to = FALSE;
2261 g_return_if_fail(compose->account != NULL);
2262 g_return_if_fail(msginfo != NULL);
2264 reply_to_ml = to_ml && compose->ml_post;
2266 default_reply_to = msginfo->folder &&
2267 msginfo->folder->prefs->enable_default_reply_to;
2269 if (compose->account->protocol != A_NNTP) {
2270 if (reply_to_ml && !default_reply_to) {
2272 gboolean is_subscr = is_subscription(compose->ml_post,
2275 /* normal answer to ml post with a reply-to */
2276 compose_entry_append(compose,
2279 if (compose->replyto
2280 && !same_address(compose->ml_post, compose->replyto))
2281 compose_entry_append(compose,
2285 /* answer to subscription confirmation */
2286 if (compose->replyto)
2287 compose_entry_append(compose,
2290 else if (msginfo->from)
2291 compose_entry_append(compose,
2296 else if (!(to_all || to_sender) && default_reply_to) {
2297 compose_entry_append(compose,
2298 msginfo->folder->prefs->default_reply_to,
2300 compose_entry_mark_default_to(compose,
2301 msginfo->folder->prefs->default_reply_to);
2304 Xstrdup_a(tmp1, msginfo->from, return);
2305 extract_address(tmp1);
2306 if (to_all || to_sender ||
2307 !account_find_from_address(tmp1))
2308 compose_entry_append(compose,
2309 (compose->replyto && !to_sender)
2310 ? compose->replyto :
2311 msginfo->from ? msginfo->from : "",
2313 else if (!to_all && !to_sender) {
2314 /* reply to the last list of recipients */
2315 compose_entry_append(compose,
2316 msginfo->to ? msginfo->to : "",
2318 compose_entry_append(compose,
2319 msginfo->cc ? msginfo->cc : "",
2324 if (to_sender || (compose->followup_to &&
2325 !strncmp(compose->followup_to, "poster", 6)))
2326 compose_entry_append
2328 (compose->replyto ? compose->replyto :
2329 msginfo->from ? msginfo->from : ""),
2332 else if (followup_and_reply_to || to_all) {
2333 compose_entry_append
2335 (compose->replyto ? compose->replyto :
2336 msginfo->from ? msginfo->from : ""),
2339 compose_entry_append
2341 compose->followup_to ? compose->followup_to :
2342 compose->newsgroups ? compose->newsgroups : "",
2343 COMPOSE_NEWSGROUPS);
2346 compose_entry_append
2348 compose->followup_to ? compose->followup_to :
2349 compose->newsgroups ? compose->newsgroups : "",
2350 COMPOSE_NEWSGROUPS);
2353 if (msginfo->subject && *msginfo->subject) {
2357 buf = p = g_strdup(msginfo->subject);
2358 p += subject_get_prefix_length(p);
2359 memmove(buf, p, strlen(p) + 1);
2361 buf2 = g_strdup_printf("Re: %s", buf);
2362 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2367 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2369 if (to_ml && compose->ml_post) return;
2370 if (!to_all || compose->account->protocol == A_NNTP) return;
2372 if (compose->replyto) {
2373 Xstrdup_a(replyto, compose->replyto, return);
2374 extract_address(replyto);
2376 if (msginfo->from) {
2377 Xstrdup_a(from, msginfo->from, return);
2378 extract_address(from);
2381 if (replyto && from)
2382 cc_list = address_list_append_with_comments(cc_list, from);
2383 if (to_all && msginfo->folder &&
2384 msginfo->folder->prefs->enable_default_reply_to)
2385 cc_list = address_list_append_with_comments(cc_list,
2386 msginfo->folder->prefs->default_reply_to);
2387 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2388 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2390 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2392 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2393 if (compose->account)
2394 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2395 GINT_TO_POINTER(1));
2397 /* remove address on To: and that of current account */
2398 for (cur = cc_list; cur != NULL; ) {
2399 GSList *next = cur->next;
2402 addr = g_strdup(cur->data);
2403 extract_address(addr);
2405 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2406 cc_list = g_slist_remove(cc_list, cur->data);
2408 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2412 hash_free_strings(to_table);
2413 g_hash_table_destroy(to_table);
2416 for (cur = cc_list; cur != NULL; cur = cur->next)
2417 compose_entry_append(compose, (gchar *)cur->data,
2419 slist_free_strings(cc_list);
2420 g_slist_free(cc_list);
2425 #define SET_ENTRY(entry, str) \
2428 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2431 #define SET_ADDRESS(type, str) \
2434 compose_entry_append(compose, str, type); \
2437 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2439 g_return_if_fail(msginfo != NULL);
2441 SET_ENTRY(subject_entry, msginfo->subject);
2442 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2443 SET_ADDRESS(COMPOSE_CC, compose->cc);
2444 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2445 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2446 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2447 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2449 compose_update_priority_menu_item(compose);
2450 compose_update_privacy_system_menu_item(compose, FALSE);
2451 compose_show_first_last_header(compose, TRUE);
2457 static void compose_insert_sig(Compose *compose, gboolean replace)
2459 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2460 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2462 GtkTextIter iter, iter_end;
2464 gboolean prev_autowrap;
2467 g_return_if_fail(compose->account != NULL);
2469 prev_autowrap = compose->autowrap;
2470 compose->autowrap = FALSE;
2472 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2473 G_CALLBACK(compose_changed_cb),
2476 mark = gtk_text_buffer_get_insert(buffer);
2477 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2478 cur_pos = gtk_text_iter_get_offset (&iter);
2480 gtk_text_buffer_get_end_iter(buffer, &iter);
2482 if (replace && compose->sig_str) {
2484 GtkTextIter first_iter, start_iter, end_iter;
2486 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2488 if (compose->sig_str[0] == '\0')
2491 found = gtk_text_iter_forward_search(&first_iter,
2493 GTK_TEXT_SEARCH_TEXT_ONLY,
2494 &start_iter, &end_iter,
2498 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2503 g_free(compose->sig_str);
2504 compose->sig_str = compose_get_signature_str(compose);
2505 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2506 compose->sig_str = g_strdup("");
2508 cur_pos = gtk_text_iter_get_offset(&iter);
2509 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2511 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2512 gtk_text_iter_forward_char(&iter);
2513 gtk_text_iter_forward_char(&iter);
2514 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2515 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2517 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2518 cur_pos = gtk_text_buffer_get_char_count (buffer);
2520 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2521 gtk_text_buffer_place_cursor(buffer, &iter);
2523 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2524 G_CALLBACK(compose_changed_cb),
2527 compose->autowrap = prev_autowrap;
2528 if (compose->autowrap)
2529 compose_wrap_all(compose);
2532 static gchar *compose_get_signature_str(Compose *compose)
2534 gchar *sig_body = NULL;
2535 gchar *sig_str = NULL;
2536 gchar *utf8_sig_str = NULL;
2538 g_return_val_if_fail(compose->account != NULL, NULL);
2540 if (!compose->account->sig_path)
2543 if (compose->account->sig_type == SIG_FILE) {
2544 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2545 g_warning("can't open signature file: %s\n",
2546 compose->account->sig_path);
2551 if (compose->account->sig_type == SIG_COMMAND)
2552 sig_body = get_command_output(compose->account->sig_path);
2556 tmp = file_read_to_str(compose->account->sig_path);
2559 sig_body = normalize_newlines(tmp);
2563 if (compose->account->sig_sep) {
2564 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2568 sig_str = g_strconcat("\n\n", sig_body, NULL);
2571 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2572 utf8_sig_str = sig_str;
2574 utf8_sig_str = conv_codeset_strdup
2575 (sig_str, conv_get_locale_charset_str(),
2581 return utf8_sig_str;
2584 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2587 GtkTextBuffer *buffer;
2590 const gchar *cur_encoding;
2591 gchar buf[BUFFSIZE];
2594 gboolean prev_autowrap;
2595 gboolean badtxt = FALSE;
2597 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2599 if ((fp = g_fopen(file, "rb")) == NULL) {
2600 FILE_OP_ERROR(file, "fopen");
2601 return COMPOSE_INSERT_READ_ERROR;
2604 prev_autowrap = compose->autowrap;
2605 compose->autowrap = FALSE;
2607 text = GTK_TEXT_VIEW(compose->text);
2608 buffer = gtk_text_view_get_buffer(text);
2609 mark = gtk_text_buffer_get_insert(buffer);
2610 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2612 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2613 G_CALLBACK(text_inserted),
2616 cur_encoding = conv_get_locale_charset_str();
2618 while (fgets(buf, sizeof(buf), fp) != NULL) {
2621 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2622 str = g_strdup(buf);
2624 str = conv_codeset_strdup
2625 (buf, cur_encoding, CS_INTERNAL);
2628 /* strip <CR> if DOS/Windows file,
2629 replace <CR> with <LF> if Macintosh file. */
2632 if (len > 0 && str[len - 1] != '\n') {
2634 if (str[len] == '\r') str[len] = '\n';
2637 gtk_text_buffer_insert(buffer, &iter, str, -1);
2641 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2642 G_CALLBACK(text_inserted),
2644 compose->autowrap = prev_autowrap;
2645 if (compose->autowrap)
2646 compose_wrap_all(compose);
2651 return COMPOSE_INSERT_INVALID_CHARACTER;
2653 return COMPOSE_INSERT_SUCCESS;
2656 static void compose_attach_append(Compose *compose, const gchar *file,
2657 const gchar *filename,
2658 const gchar *content_type)
2666 GtkListStore *store;
2669 if (!is_file_exist(file)) {
2670 g_warning("File %s doesn't exist\n", filename);
2673 if ((size = get_file_size(file)) < 0) {
2674 g_warning("Can't get file size of %s\n", filename);
2678 alertpanel_notice(_("File %s is empty."), filename);
2681 if ((fp = g_fopen(file, "rb")) == NULL) {
2682 alertpanel_error(_("Can't read %s."), filename);
2687 ainfo = g_new0(AttachInfo, 1);
2688 auto_ainfo = g_auto_pointer_new_with_free
2689 (ainfo, (GFreeFunc) compose_attach_info_free);
2690 ainfo->file = g_strdup(file);
2693 ainfo->content_type = g_strdup(content_type);
2694 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2696 MsgFlags flags = {0, 0};
2698 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2699 ainfo->encoding = ENC_7BIT;
2701 ainfo->encoding = ENC_8BIT;
2703 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2704 if (msginfo && msginfo->subject)
2705 name = g_strdup(msginfo->subject);
2707 name = g_path_get_basename(filename ? filename : file);
2709 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2711 procmsg_msginfo_free(msginfo);
2713 if (!g_ascii_strncasecmp(content_type, "text", 4))
2714 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2716 ainfo->encoding = ENC_BASE64;
2717 name = g_path_get_basename(filename ? filename : file);
2718 ainfo->name = g_strdup(name);
2722 ainfo->content_type = procmime_get_mime_type(file);
2723 if (!ainfo->content_type) {
2724 ainfo->content_type =
2725 g_strdup("application/octet-stream");
2726 ainfo->encoding = ENC_BASE64;
2727 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2729 procmime_get_encoding_for_text_file(file);
2731 ainfo->encoding = ENC_BASE64;
2732 name = g_path_get_basename(filename ? filename : file);
2733 ainfo->name = g_strdup(name);
2737 if (!strcmp(ainfo->content_type, "unknown")) {
2738 g_free(ainfo->content_type);
2739 ainfo->content_type = g_strdup("application/octet-stream");
2743 size_text = to_human_readable(size);
2745 store = GTK_LIST_STORE(gtk_tree_view_get_model
2746 (GTK_TREE_VIEW(compose->attach_clist)));
2748 gtk_list_store_append(store, &iter);
2749 gtk_list_store_set(store, &iter,
2750 COL_MIMETYPE, ainfo->content_type,
2751 COL_SIZE, size_text,
2752 COL_NAME, ainfo->name,
2754 COL_AUTODATA, auto_ainfo,
2757 g_auto_pointer_free(auto_ainfo);
2760 static void compose_use_signing(Compose *compose, gboolean use_signing)
2762 GtkItemFactory *ifactory;
2763 GtkWidget *menuitem = NULL;
2765 compose->use_signing = use_signing;
2766 ifactory = gtk_item_factory_from_widget(compose->menubar);
2767 menuitem = gtk_item_factory_get_item
2768 (ifactory, "/Options/Sign");
2769 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2773 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2775 GtkItemFactory *ifactory;
2776 GtkWidget *menuitem = NULL;
2778 compose->use_encryption = use_encryption;
2779 ifactory = gtk_item_factory_from_widget(compose->menubar);
2780 menuitem = gtk_item_factory_get_item
2781 (ifactory, "/Options/Encrypt");
2783 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2787 #define NEXT_PART_NOT_CHILD(info) \
2789 node = info->node; \
2790 while (node->children) \
2791 node = g_node_last_child(node); \
2792 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2795 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2799 MimeInfo *firsttext = NULL;
2800 MimeInfo *encrypted = NULL;
2803 const gchar *partname = NULL;
2805 mimeinfo = procmime_scan_message(msginfo);
2806 if (!mimeinfo) return;
2808 if (mimeinfo->node->children == NULL) {
2809 procmime_mimeinfo_free_all(mimeinfo);
2813 /* find first content part */
2814 child = (MimeInfo *) mimeinfo->node->children->data;
2815 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2816 child = (MimeInfo *)child->node->children->data;
2818 if (child->type == MIMETYPE_TEXT) {
2820 debug_print("First text part found\n");
2821 } else if (compose->mode == COMPOSE_REEDIT &&
2822 child->type == MIMETYPE_APPLICATION &&
2823 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2824 encrypted = (MimeInfo *)child->node->parent->data;
2827 child = (MimeInfo *) mimeinfo->node->children->data;
2828 while (child != NULL) {
2829 if (child == encrypted) {
2830 /* skip this part of tree */
2831 NEXT_PART_NOT_CHILD(child);
2835 if (child->type == MIMETYPE_MULTIPART) {
2836 /* get the actual content */
2837 child = procmime_mimeinfo_next(child);
2841 if (child == firsttext) {
2842 child = procmime_mimeinfo_next(child);
2846 outfile = procmime_get_tmp_file_name(child);
2847 if (procmime_get_part(outfile, child) < 0)
2848 g_warning("Can't get the part of multipart message.");
2850 gchar *content_type;
2852 content_type = procmime_get_content_type_str(child->type, child->subtype);
2854 /* if we meet a pgp signature, we don't attach it, but
2855 * we force signing. */
2856 if (strcmp(content_type, "application/pgp-signature")) {
2857 partname = procmime_mimeinfo_get_parameter(child, "filename");
2858 if (partname == NULL)
2859 partname = procmime_mimeinfo_get_parameter(child, "name");
2860 if (partname == NULL)
2862 compose_attach_append(compose, outfile,
2863 partname, content_type);
2865 compose_force_signing(compose, compose->account);
2867 g_free(content_type);
2870 NEXT_PART_NOT_CHILD(child);
2872 procmime_mimeinfo_free_all(mimeinfo);
2875 #undef NEXT_PART_NOT_CHILD
2880 WAIT_FOR_INDENT_CHAR,
2881 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2884 /* return indent length, we allow:
2885 indent characters followed by indent characters or spaces/tabs,
2886 alphabets and numbers immediately followed by indent characters,
2887 and the repeating sequences of the above
2888 If quote ends with multiple spaces, only the first one is included. */
2889 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2890 const GtkTextIter *start, gint *len)
2892 GtkTextIter iter = *start;
2896 IndentState state = WAIT_FOR_INDENT_CHAR;
2899 gint alnum_count = 0;
2900 gint space_count = 0;
2903 if (prefs_common.quote_chars == NULL) {
2907 while (!gtk_text_iter_ends_line(&iter)) {
2908 wc = gtk_text_iter_get_char(&iter);
2909 if (g_unichar_iswide(wc))
2911 clen = g_unichar_to_utf8(wc, ch);
2915 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2916 is_space = g_unichar_isspace(wc);
2918 if (state == WAIT_FOR_INDENT_CHAR) {
2919 if (!is_indent && !g_unichar_isalnum(wc))
2922 quote_len += alnum_count + space_count + 1;
2923 alnum_count = space_count = 0;
2924 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2927 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2928 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
2932 else if (is_indent) {
2933 quote_len += alnum_count + space_count + 1;
2934 alnum_count = space_count = 0;
2937 state = WAIT_FOR_INDENT_CHAR;
2941 gtk_text_iter_forward_char(&iter);
2944 if (quote_len > 0 && space_count > 0)
2950 if (quote_len > 0) {
2952 gtk_text_iter_forward_chars(&iter, quote_len);
2953 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
2959 /* return TRUE if the line is itemized */
2960 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
2961 const GtkTextIter *start)
2963 GtkTextIter iter = *start;
2968 if (gtk_text_iter_ends_line(&iter))
2972 wc = gtk_text_iter_get_char(&iter);
2973 if (!g_unichar_isspace(wc))
2975 gtk_text_iter_forward_char(&iter);
2976 if (gtk_text_iter_ends_line(&iter))
2980 clen = g_unichar_to_utf8(wc, ch);
2984 if (!strchr("*-+", ch[0]))
2987 gtk_text_iter_forward_char(&iter);
2988 if (gtk_text_iter_ends_line(&iter))
2990 wc = gtk_text_iter_get_char(&iter);
2991 if (g_unichar_isspace(wc))
2997 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
2998 const GtkTextIter *start,
2999 GtkTextIter *break_pos,
3003 GtkTextIter iter = *start, line_end = *start;
3004 PangoLogAttr *attrs;
3011 gboolean can_break = FALSE;
3012 gboolean do_break = FALSE;
3013 gboolean was_white = FALSE;
3014 gboolean prev_dont_break = FALSE;
3016 gtk_text_iter_forward_to_line_end(&line_end);
3017 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3018 len = g_utf8_strlen(str, -1);
3019 /* g_print("breaking line: %d: %s (len = %d)\n",
3020 gtk_text_iter_get_line(&iter), str, len); */
3021 attrs = g_new(PangoLogAttr, len + 1);
3023 pango_default_break(str, -1, NULL, attrs, len + 1);
3027 /* skip quote and leading spaces */
3028 for (i = 0; *p != '\0' && i < len; i++) {
3031 wc = g_utf8_get_char(p);
3032 if (i >= quote_len && !g_unichar_isspace(wc))
3034 if (g_unichar_iswide(wc))
3036 else if (*p == '\t')
3040 p = g_utf8_next_char(p);
3043 for (; *p != '\0' && i < len; i++) {
3044 PangoLogAttr *attr = attrs + i;
3048 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3051 was_white = attr->is_white;
3053 /* don't wrap URI */
3054 if ((uri_len = get_uri_len(p)) > 0) {
3056 if (pos > 0 && col > max_col) {
3066 wc = g_utf8_get_char(p);
3067 if (g_unichar_iswide(wc)) {
3069 if (prev_dont_break && can_break && attr->is_line_break)
3071 } else if (*p == '\t')
3075 if (pos > 0 && col > max_col) {
3080 if (*p == '-' || *p == '/')
3081 prev_dont_break = TRUE;
3083 prev_dont_break = FALSE;
3085 p = g_utf8_next_char(p);
3089 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3094 *break_pos = *start;
3095 gtk_text_iter_set_line_offset(break_pos, pos);
3100 static gboolean compose_join_next_line(Compose *compose,
3101 GtkTextBuffer *buffer,
3103 const gchar *quote_str)
3105 GtkTextIter iter_ = *iter, cur, prev, next, end;
3106 PangoLogAttr attrs[3];
3108 gchar *next_quote_str;
3111 gboolean keep_cursor = FALSE;
3113 if (!gtk_text_iter_forward_line(&iter_) ||
3114 gtk_text_iter_ends_line(&iter_))
3117 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3119 if ((quote_str || next_quote_str) &&
3120 strcmp2(quote_str, next_quote_str) != 0) {
3121 g_free(next_quote_str);
3124 g_free(next_quote_str);
3127 if (quote_len > 0) {
3128 gtk_text_iter_forward_chars(&end, quote_len);
3129 if (gtk_text_iter_ends_line(&end))
3133 /* don't join itemized lines */
3134 if (compose_is_itemized(buffer, &end))
3137 /* don't join signature separator */
3138 if (compose_is_sig_separator(compose, buffer, &iter_))
3141 /* delete quote str */
3143 gtk_text_buffer_delete(buffer, &iter_, &end);
3145 /* delete linebreak and extra spaces */
3147 while (gtk_text_iter_backward_char(&cur)) {
3148 wc1 = gtk_text_iter_get_char(&cur);
3149 if (!g_unichar_isspace(wc1))
3154 while (!gtk_text_iter_ends_line(&cur)) {
3155 wc1 = gtk_text_iter_get_char(&cur);
3156 if (!g_unichar_isspace(wc1))
3158 gtk_text_iter_forward_char(&cur);
3161 if (!gtk_text_iter_equal(&prev, &next)) {
3164 mark = gtk_text_buffer_get_insert(buffer);
3165 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3166 if (gtk_text_iter_equal(&prev, &cur))
3168 gtk_text_buffer_delete(buffer, &prev, &next);
3172 /* insert space if required */
3173 gtk_text_iter_backward_char(&prev);
3174 wc1 = gtk_text_iter_get_char(&prev);
3175 wc2 = gtk_text_iter_get_char(&next);
3176 gtk_text_iter_forward_char(&next);
3177 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3178 pango_default_break(str, -1, NULL, attrs, 3);
3179 if (!attrs[1].is_line_break ||
3180 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3181 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3183 gtk_text_iter_backward_char(&iter_);
3184 gtk_text_buffer_place_cursor(buffer, &iter_);
3193 #define ADD_TXT_POS(bp_, ep_, pti_) \
3194 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3195 last = last->next; \
3196 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3197 last->next = NULL; \
3199 g_warning("alloc error scanning URIs\n"); \
3202 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3204 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3205 GtkTextBuffer *buffer;
3206 GtkTextIter iter, break_pos, end_of_line;
3207 gchar *quote_str = NULL;
3209 gboolean wrap_quote = prefs_common.linewrap_quote;
3210 gboolean prev_autowrap = compose->autowrap;
3211 gint startq_offset = -1, noq_offset = -1;
3212 gint uri_start = -1, uri_stop = -1;
3213 gint nouri_start = -1, nouri_stop = -1;
3215 compose->autowrap = FALSE;
3217 buffer = gtk_text_view_get_buffer(text);
3219 undo_block(compose->undostruct);
3225 mark = gtk_text_buffer_get_insert(buffer);
3226 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3229 /* move to paragraph start */
3230 gtk_text_iter_set_line_offset(&iter, 0);
3231 if (gtk_text_iter_ends_line(&iter)) {
3232 while (gtk_text_iter_ends_line(&iter) &&
3233 gtk_text_iter_forward_line(&iter))
3236 while (gtk_text_iter_backward_line(&iter)) {
3237 if (gtk_text_iter_ends_line(&iter)) {
3238 gtk_text_iter_forward_line(&iter);
3244 /* go until paragraph end (empty line) */
3245 while (!gtk_text_iter_ends_line(&iter)) {
3246 gchar *scanpos = NULL;
3247 /* parse table - in order of priority */
3249 const gchar *needle; /* token */
3251 /* token search function */
3252 gchar *(*search) (const gchar *haystack,
3253 const gchar *needle);
3254 /* part parsing function */
3255 gboolean (*parse) (const gchar *start,
3256 const gchar *scanpos,
3260 /* part to URI function */
3261 gchar *(*build_uri) (const gchar *bp,
3265 static struct table parser[] = {
3266 {"http://", strcasestr, get_uri_part, make_uri_string},
3267 {"https://", strcasestr, get_uri_part, make_uri_string},
3268 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3269 {"www.", strcasestr, get_uri_part, make_http_string},
3270 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3271 {"@", strcasestr, get_email_part, make_email_string}
3273 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3274 gint last_index = PARSE_ELEMS;
3276 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3279 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3282 uri_start = uri_stop = -1;
3283 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3287 if (startq_offset == -1) {
3288 startq_offset = gtk_text_iter_get_offset(&iter);
3292 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3293 if (startq_offset == -1)
3294 startq_offset = gtk_text_iter_get_offset(&iter);
3296 if (startq_offset == -1)
3297 noq_offset = gtk_text_iter_get_offset(&iter);
3300 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3303 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3304 prefs_common.linewrap_len,
3306 GtkTextIter prev, next, cur;
3308 if (prev_autowrap != FALSE || force)
3309 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3310 else if (quote_str && wrap_quote)
3311 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3314 /* remove trailing spaces */
3316 gtk_text_iter_backward_char(&cur);
3318 while (!gtk_text_iter_starts_line(&cur)) {
3321 gtk_text_iter_backward_char(&cur);
3322 wc = gtk_text_iter_get_char(&cur);
3323 if (!g_unichar_isspace(wc))
3327 if (!gtk_text_iter_equal(&prev, &next)) {
3328 gtk_text_buffer_delete(buffer, &prev, &next);
3330 gtk_text_iter_forward_char(&break_pos);
3334 gtk_text_buffer_insert(buffer, &break_pos,
3338 compose_join_next_line(compose, buffer, &iter, quote_str);
3340 /* move iter to current line start */
3341 gtk_text_iter_set_line_offset(&iter, 0);
3344 /* move iter to next line start */
3350 while (!gtk_text_iter_ends_line(&end_of_line)) {
3351 gtk_text_iter_forward_char(&end_of_line);
3353 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3355 nouri_start = gtk_text_iter_get_offset(&iter);
3356 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3358 walk_pos = gtk_text_iter_get_offset(&iter);
3359 /* FIXME: this looks phony. scanning for anything in the parse table */
3360 for (n = 0; n < PARSE_ELEMS; n++) {
3363 tmp = parser[n].search(walk, parser[n].needle);
3365 if (scanpos == NULL || tmp < scanpos) {
3374 /* check if URI can be parsed */
3375 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3376 (const gchar **)&ep, FALSE)
3377 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3381 strlen(parser[last_index].needle);
3384 uri_start = walk_pos + (bp - o_walk);
3385 uri_stop = walk_pos + (ep - o_walk);
3389 gtk_text_iter_forward_line(&iter);
3392 if (startq_offset != -1) {
3393 GtkTextIter startquote, endquote;
3394 gtk_text_buffer_get_iter_at_offset(
3395 buffer, &startquote, startq_offset);
3397 gtk_text_buffer_apply_tag_by_name(
3398 buffer, "quote", &startquote, &endquote);
3400 } else if (noq_offset != -1) {
3401 GtkTextIter startnoquote, endnoquote;
3402 gtk_text_buffer_get_iter_at_offset(
3403 buffer, &startnoquote, noq_offset);
3405 gtk_text_buffer_remove_tag_by_name(
3406 buffer, "quote", &startnoquote, &endnoquote);
3411 GtkTextIter nouri_start_iter, nouri_end_iter;
3412 gtk_text_buffer_get_iter_at_offset(
3413 buffer, &nouri_start_iter, nouri_start);
3414 gtk_text_buffer_get_iter_at_offset(
3415 buffer, &nouri_end_iter, nouri_stop);
3416 gtk_text_buffer_remove_tag_by_name(
3417 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3419 if (uri_start > 0 && uri_stop > 0) {
3420 GtkTextIter uri_start_iter, uri_end_iter;
3421 gtk_text_buffer_get_iter_at_offset(
3422 buffer, &uri_start_iter, uri_start);
3423 gtk_text_buffer_get_iter_at_offset(
3424 buffer, &uri_end_iter, uri_stop);
3425 gtk_text_buffer_apply_tag_by_name(
3426 buffer, "link", &uri_start_iter, &uri_end_iter);
3433 undo_unblock(compose->undostruct);
3434 compose->autowrap = prev_autowrap;
3437 static void compose_wrap_all(Compose *compose)
3439 compose_wrap_all_full(compose, FALSE);
3442 static void compose_wrap_all_full(Compose *compose, gboolean force)
3444 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3445 GtkTextBuffer *buffer;
3448 buffer = gtk_text_view_get_buffer(text);
3450 undo_block(compose->undostruct);
3452 gtk_text_buffer_get_start_iter(buffer, &iter);
3453 while (!gtk_text_iter_is_end(&iter))
3454 compose_beautify_paragraph(compose, &iter, force);
3456 undo_unblock(compose->undostruct);
3459 static void compose_set_title(Compose *compose)
3465 edited = compose->modified ? _(" [Edited]") : "";
3467 subject = gtk_editable_get_chars(
3468 GTK_EDITABLE(compose->subject_entry), 0, -1);
3470 if (subject && strlen(subject))
3471 str = g_strdup_printf(_("%s - Compose message%s"),
3474 str = g_strdup_printf(_("[no subject] - Compose message%s"), edited);
3475 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3481 * compose_current_mail_account:
3483 * Find a current mail account (the currently selected account, or the
3484 * default account, if a news account is currently selected). If a
3485 * mail account cannot be found, display an error message.
3487 * Return value: Mail account, or NULL if not found.
3489 static PrefsAccount *
3490 compose_current_mail_account(void)
3494 if (cur_account && cur_account->protocol != A_NNTP)
3497 ac = account_get_default();
3498 if (!ac || ac->protocol == A_NNTP) {
3499 alertpanel_error(_("Account for sending mail is not specified.\n"
3500 "Please select a mail account before sending."));
3507 static void compose_select_account(Compose *compose, PrefsAccount *account,
3510 GtkItemFactory *ifactory;
3512 g_return_if_fail(account != NULL);
3514 compose->account = account;
3516 compose_set_title(compose);
3518 ifactory = gtk_item_factory_from_widget(compose->menubar);
3520 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3521 menu_set_active(ifactory, "/Options/Sign", TRUE);
3523 menu_set_active(ifactory, "/Options/Sign", FALSE);
3524 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3525 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3527 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3529 activate_privacy_system(compose, account, FALSE);
3531 if (!init && compose->mode != COMPOSE_REDIRECT)
3532 compose_insert_sig(compose, TRUE);
3535 gboolean compose_check_for_valid_recipient(Compose *compose) {
3536 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3537 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3538 gboolean recipient_found = FALSE;
3542 /* free to and newsgroup list */
3543 slist_free_strings(compose->to_list);
3544 g_slist_free(compose->to_list);
3545 compose->to_list = NULL;
3547 slist_free_strings(compose->newsgroup_list);
3548 g_slist_free(compose->newsgroup_list);
3549 compose->newsgroup_list = NULL;
3551 /* search header entries for to and newsgroup entries */
3552 for (list = compose->header_list; list; list = list->next) {
3555 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3556 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3558 if (entry[0] != '\0') {
3559 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3560 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3561 compose->to_list = address_list_append(compose->to_list, entry);
3562 recipient_found = TRUE;
3565 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3566 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3567 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3568 recipient_found = TRUE;
3575 return recipient_found;
3578 static gboolean compose_check_for_set_recipients(Compose *compose)
3580 if (compose->account->set_autocc && compose->account->auto_cc) {
3581 gboolean found_other = FALSE;
3583 /* search header entries for to and newsgroup entries */
3584 for (list = compose->header_list; list; list = list->next) {
3587 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3588 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3590 if (strcmp(entry, compose->account->auto_cc)
3591 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3601 aval = alertpanel(_("Send"),
3602 _("The only recipient is the default CC address. Send anyway?"),
3603 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3604 if (aval != G_ALERTDEFAULT)
3608 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3609 gboolean found_other = FALSE;
3611 /* search header entries for to and newsgroup entries */
3612 for (list = compose->header_list; list; list = list->next) {
3615 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3616 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3618 if (strcmp(entry, compose->account->auto_cc)
3619 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3629 aval = alertpanel(_("Send"),
3630 _("The only recipient is the default BCC address. Send anyway?"),
3631 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3632 if (aval != G_ALERTDEFAULT)
3639 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3643 if (compose_check_for_valid_recipient(compose) == FALSE) {
3644 alertpanel_error(_("Recipient is not specified."));
3648 if (compose_check_for_set_recipients(compose) == FALSE) {
3652 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3653 if (*str == '\0' && check_subject == TRUE) {
3656 aval = alertpanel(_("Send"),
3657 _("Subject is empty. Send it anyway?"),
3658 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3659 if (aval != G_ALERTDEFAULT)
3666 gint compose_send(Compose *compose)
3673 compose_allow_user_actions (compose, FALSE);
3674 compose->sending = TRUE;
3676 if (compose_check_entries(compose, TRUE) == FALSE)
3679 val = compose_queue(compose, &msgnum, &folder);
3683 alertpanel_error(_("Could not queue message for sending:\n\n"
3684 "Charset conversion failed."));
3685 } else if (val == -3) {
3686 alertpanel_error(_("Could not queue message for sending:\n\n"
3687 "Signature failed."));
3688 } else if (val == -2) {
3689 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3691 alertpanel_error(_("Could not queue message for sending."));
3697 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3698 compose->sending = FALSE;
3699 compose_close(compose);
3700 /* No more compose access in the normal codepath
3701 * after this point! */
3706 alertpanel_error(_("The message was queued but could not be "
3707 "sent.\nUse \"Send queued messages\" from "
3708 "the main window to retry."));
3709 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3710 compose->sending = FALSE;
3711 compose_allow_user_actions (compose, TRUE);
3716 msgpath = folder_item_fetch_msg(folder, msgnum);
3717 val = procmsg_send_message_queue(msgpath);
3720 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3721 compose->sending = FALSE;
3722 compose_allow_user_actions (compose, TRUE);
3724 folder_item_remove_msg(folder, msgnum);
3725 folder_item_scan(folder);
3730 folder_item_remove_msg(folder, msgnum);
3731 folder_item_scan(folder);
3732 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3733 compose_close(compose);
3735 alertpanel_error(_("The message was queued but could not be "
3736 "sent.\nUse \"Send queued messages\" from "
3737 "the main window to retry."));
3738 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3739 compose_allow_user_actions (compose, TRUE);
3740 compose->sending = FALSE;
3748 compose_allow_user_actions (compose, TRUE);
3749 compose->sending = FALSE;
3754 static gboolean compose_use_attach(Compose *compose)
3756 GtkTreeModel *model = gtk_tree_view_get_model
3757 (GTK_TREE_VIEW(compose->attach_clist));
3758 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3761 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3764 gchar buf[BUFFSIZE];
3766 gboolean first_to_address;
3767 gboolean first_cc_address;
3769 ComposeHeaderEntry *headerentry;
3770 const gchar *headerentryname;
3774 debug_print("Writing redirect header\n");
3776 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3777 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3779 first_to_address = TRUE;
3780 for (list = compose->header_list; list; list = list->next) {
3781 headerentry = ((ComposeHeaderEntry *)list->data);
3782 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3784 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3785 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3786 Xstrdup_a(str, entstr, return -1);
3788 if (str[0] != '\0') {
3789 compose_convert_header
3790 (compose, buf, sizeof(buf), str,
3791 strlen("Resent-To") + 2, TRUE);
3793 if (first_to_address) {
3794 fprintf(fp, "Resent-To: ");
3795 first_to_address = FALSE;
3799 fprintf(fp, "%s", buf);
3803 if (!first_to_address) {
3807 first_cc_address = TRUE;
3808 for (list = compose->header_list; list; list = list->next) {
3809 headerentry = ((ComposeHeaderEntry *)list->data);
3810 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3812 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3813 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3814 Xstrdup_a(str, strg, return -1);
3816 if (str[0] != '\0') {
3817 compose_convert_header
3818 (compose, buf, sizeof(buf), str,
3819 strlen("Resent-Cc") + 2, TRUE);
3821 if (first_cc_address) {
3822 fprintf(fp, "Resent-Cc: ");
3823 first_cc_address = FALSE;
3827 fprintf(fp, "%s", buf);
3831 if (!first_cc_address) {
3838 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3840 gchar buf[BUFFSIZE];
3842 const gchar *entstr;
3843 /* struct utsname utsbuf; */
3845 g_return_val_if_fail(fp != NULL, -1);
3846 g_return_val_if_fail(compose->account != NULL, -1);
3847 g_return_val_if_fail(compose->account->address != NULL, -1);
3850 get_rfc822_date(buf, sizeof(buf));
3851 fprintf(fp, "Resent-Date: %s\n", buf);
3854 if (compose->account->name && *compose->account->name) {
3855 compose_convert_header
3856 (compose, buf, sizeof(buf), compose->account->name,
3857 strlen("From: "), TRUE);
3858 fprintf(fp, "Resent-From: %s <%s>\n",
3859 buf, compose->account->address);
3861 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3864 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3865 if (*entstr != '\0') {
3866 Xstrdup_a(str, entstr, return -1);
3869 compose_convert_header(compose, buf, sizeof(buf), str,
3870 strlen("Subject: "), FALSE);
3871 fprintf(fp, "Subject: %s\n", buf);
3875 /* Resent-Message-ID */
3876 if (compose->account->gen_msgid) {
3877 generate_msgid(buf, sizeof(buf));
3878 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3879 compose->msgid = g_strdup(buf);
3882 compose_redirect_write_headers_from_headerlist(compose, fp);
3884 /* separator between header and body */
3890 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3894 gchar buf[BUFFSIZE];
3896 if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
3897 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3901 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3902 /* should filter returnpath, delivered-to */
3903 if (g_ascii_strncasecmp(buf, "Return-Path:",
3904 strlen("Return-Path:")) == 0 ||
3905 g_ascii_strncasecmp(buf, "Delivered-To:",
3906 strlen("Delivered-To:")) == 0 ||
3907 g_ascii_strncasecmp(buf, "Received:",
3908 strlen("Received:")) == 0 ||
3909 g_ascii_strncasecmp(buf, "Subject:",
3910 strlen("Subject:")) == 0 ||
3911 g_ascii_strncasecmp(buf, "X-UIDL:",
3912 strlen("X-UIDL:")) == 0)
3915 if (fputs(buf, fdest) == -1)
3918 if (!prefs_common.redirect_keep_from) {
3919 if (g_ascii_strncasecmp(buf, "From:",
3920 strlen("From:")) == 0) {
3921 fputs(" (by way of ", fdest);
3922 if (compose->account->name
3923 && *compose->account->name) {
3924 compose_convert_header
3925 (compose, buf, sizeof(buf),
3926 compose->account->name,
3929 fprintf(fdest, "%s <%s>",
3931 compose->account->address);
3933 fprintf(fdest, "%s",
3934 compose->account->address);
3939 if (fputs("\n", fdest) == -1)
3943 compose_redirect_write_headers(compose, fdest);
3945 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3946 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
3959 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
3961 GtkTextBuffer *buffer;
3962 GtkTextIter start, end;
3965 const gchar *out_codeset;
3966 EncodingType encoding;
3967 MimeInfo *mimemsg, *mimetext;
3970 /* create message MimeInfo */
3971 mimemsg = procmime_mimeinfo_new();
3972 mimemsg->type = MIMETYPE_MESSAGE;
3973 mimemsg->subtype = g_strdup("rfc822");
3974 mimemsg->content = MIMECONTENT_MEM;
3975 mimemsg->data.mem = compose_get_header(compose);
3977 /* Create text part MimeInfo */
3978 /* get all composed text */
3979 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
3980 gtk_text_buffer_get_start_iter(buffer, &start);
3981 gtk_text_buffer_get_end_iter(buffer, &end);
3982 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
3983 if (is_ascii_str(chars)) {
3986 out_codeset = CS_US_ASCII;
3987 encoding = ENC_7BIT;
3989 const gchar *src_codeset = CS_INTERNAL;
3991 out_codeset = conv_get_charset_str(compose->out_encoding);
3994 gchar *test_conv_global_out = NULL;
3995 gchar *test_conv_reply = NULL;
3997 /* automatic mode. be automatic. */
3998 codeconv_set_strict(TRUE);
4000 out_codeset = conv_get_outgoing_charset_str();
4002 debug_print("trying to convert to %s\n", out_codeset);
4003 test_conv_global_out = conv_codeset_strdup(chars, src_codeset, out_codeset);
4006 if (!test_conv_global_out && compose->orig_charset) {
4007 out_codeset = compose->orig_charset;
4008 debug_print("failure; trying to convert to %s\n", out_codeset);
4009 test_conv_reply = conv_codeset_strdup(chars, src_codeset, out_codeset);
4012 if (!test_conv_global_out && !test_conv_reply) {
4014 out_codeset = CS_INTERNAL;
4015 debug_print("finally using %s\n", out_codeset);
4017 g_free(test_conv_global_out);
4018 g_free(test_conv_reply);
4019 codeconv_set_strict(FALSE);
4022 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
4023 out_codeset = CS_ISO_8859_1;
4025 if (prefs_common.encoding_method == CTE_BASE64)
4026 encoding = ENC_BASE64;
4027 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
4028 encoding = ENC_QUOTED_PRINTABLE;
4029 else if (prefs_common.encoding_method == CTE_8BIT)
4030 encoding = ENC_8BIT;
4032 encoding = procmime_get_encoding_for_charset(out_codeset);
4034 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
4035 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
4037 if (action == COMPOSE_WRITE_FOR_SEND) {
4038 codeconv_set_strict(TRUE);
4039 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
4040 codeconv_set_strict(FALSE);
4046 msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
4047 "to the specified %s charset.\n"
4048 "Send it as %s?"), out_codeset, src_codeset);
4049 aval = alertpanel_full(_("Error"), msg, GTK_STOCK_YES, GTK_STOCK_NO, NULL, FALSE,
4050 NULL, ALERT_ERROR, G_ALERTALTERNATE);
4053 if (aval != G_ALERTDEFAULT) {
4058 out_codeset = src_codeset;
4064 out_codeset = src_codeset;
4070 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
4071 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
4072 strstr(buf, "\nFrom ") != NULL) {
4073 encoding = ENC_QUOTED_PRINTABLE;
4077 mimetext = procmime_mimeinfo_new();
4078 mimetext->content = MIMECONTENT_MEM;
4079 mimetext->data.mem = buf;
4080 mimetext->type = MIMETYPE_TEXT;
4081 mimetext->subtype = g_strdup("plain");
4082 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
4083 g_strdup(out_codeset));
4084 /* protect trailing spaces when signing message */
4085 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4086 privacy_system_can_sign(compose->privacy_system)) {
4087 encoding = ENC_QUOTED_PRINTABLE;
4090 /* check for line length limit */
4091 if (action == COMPOSE_WRITE_FOR_SEND &&
4092 encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
4093 check_line_length(buf, 1000, &line) < 0) {
4097 msg = g_strdup_printf
4098 (_("Line %d exceeds the line length limit (998 bytes).\n"
4099 "The contents of the message might be broken on the way to the delivery.\n"
4101 "Send it anyway?"), line + 1);
4102 aval = alertpanel(_("Warning"), msg, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
4104 if (aval != G_ALERTDEFAULT) {
4109 if (encoding != ENC_UNKNOWN)
4110 procmime_encode_content(mimetext, encoding);
4112 /* append attachment parts */
4113 if (compose_use_attach(compose)) {
4114 MimeInfo *mimempart;
4115 gchar *boundary = NULL;
4116 mimempart = procmime_mimeinfo_new();
4117 mimempart->content = MIMECONTENT_EMPTY;
4118 mimempart->type = MIMETYPE_MULTIPART;
4119 mimempart->subtype = g_strdup("mixed");
4124 boundary = generate_mime_boundary(NULL);
4125 } while (strstr(buf, boundary) != NULL);
4127 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
4130 mimetext->disposition = DISPOSITIONTYPE_INLINE;
4132 g_node_append(mimempart->node, mimetext->node);
4133 g_node_append(mimemsg->node, mimempart->node);
4135 compose_add_attachments(compose, mimempart);
4137 g_node_append(mimemsg->node, mimetext->node);
4139 /* sign message if sending */
4140 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
4141 privacy_system_can_sign(compose->privacy_system))
4142 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
4145 procmime_write_mimeinfo(mimemsg, fp);
4147 procmime_mimeinfo_free_all(mimemsg);
4152 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
4154 GtkTextBuffer *buffer;
4155 GtkTextIter start, end;
4160 if ((fp = g_fopen(file, "wb")) == NULL) {
4161 FILE_OP_ERROR(file, "fopen");
4165 /* chmod for security */
4166 if (change_file_mode_rw(fp, file) < 0) {
4167 FILE_OP_ERROR(file, "chmod");
4168 g_warning("can't change file mode\n");
4171 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
4172 gtk_text_buffer_get_start_iter(buffer, &start);
4173 gtk_text_buffer_get_end_iter(buffer, &end);
4174 tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
4176 chars = conv_codeset_strdup
4177 (tmp, CS_INTERNAL, conv_get_locale_charset_str());
4180 if (!chars) return -1;
4183 len = strlen(chars);
4184 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
4185 FILE_OP_ERROR(file, "fwrite");
4194 if (fclose(fp) == EOF) {
4195 FILE_OP_ERROR(file, "fclose");
4202 static gint compose_remove_reedit_target(Compose *compose)
4205 MsgInfo *msginfo = compose->targetinfo;
4207 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
4208 if (!msginfo) return -1;
4210 item = msginfo->folder;
4211 g_return_val_if_fail(item != NULL, -1);
4213 if (procmsg_msg_exist(msginfo) &&
4214 (folder_has_parent_of_type(item, F_QUEUE) ||
4215 folder_has_parent_of_type(item, F_DRAFT)
4216 || msginfo == compose->autosaved_draft)) {
4217 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
4218 g_warning("can't remove the old message\n");
4226 void compose_remove_draft(Compose *compose)
4229 MsgInfo *msginfo = compose->targetinfo;
4230 drafts = account_get_special_folder(compose->account, F_DRAFT);
4232 if (procmsg_msg_exist(msginfo)) {
4233 folder_item_remove_msg(drafts, msginfo->msgnum);
4238 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
4240 return compose_queue_sub (compose, msgnum, item, FALSE);
4242 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
4249 static gboolean lock = FALSE;
4250 PrefsAccount *mailac = NULL, *newsac = NULL;
4252 debug_print("queueing message...\n");
4253 g_return_val_if_fail(compose->account != NULL, -1);
4257 if (compose_check_entries(compose, check_subject) == FALSE) {
4262 if (!compose->to_list && !compose->newsgroup_list) {
4263 g_warning("can't get recipient list.");
4268 if (compose->to_list) {
4269 if (compose->account->protocol != A_NNTP)
4270 mailac = compose->account;
4271 else if (cur_account && cur_account->protocol != A_NNTP)
4272 mailac = cur_account;
4273 else if (!(mailac = compose_current_mail_account())) {
4275 alertpanel_error(_("No account for sending mails available!"));
4280 if (compose->newsgroup_list) {
4281 if (compose->account->protocol == A_NNTP)
4282 newsac = compose->account;
4283 else if (!newsac->protocol != A_NNTP) {
4285 alertpanel_error(_("No account for posting news available!"));
4290 if (prefs_common.linewrap_at_send)
4291 compose_wrap_all(compose);
4293 /* write queue header */
4294 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
4295 G_DIR_SEPARATOR, compose);
4296 if ((fp = g_fopen(tmp, "wb")) == NULL) {
4297 FILE_OP_ERROR(tmp, "fopen");
4302 if (change_file_mode_rw(fp, tmp) < 0) {
4303 FILE_OP_ERROR(tmp, "chmod");
4304 g_warning("can't change file mode\n");
4307 /* queueing variables */
4308 fprintf(fp, "AF:\n");
4309 fprintf(fp, "NF:0\n");
4310 fprintf(fp, "PS:10\n");
4311 fprintf(fp, "SRH:1\n");
4312 fprintf(fp, "SFN:\n");
4313 fprintf(fp, "DSR:\n");
4315 fprintf(fp, "MID:<%s>\n", compose->msgid);
4317 fprintf(fp, "MID:\n");
4318 fprintf(fp, "CFG:\n");
4319 fprintf(fp, "PT:0\n");
4320 fprintf(fp, "S:%s\n", compose->account->address);
4321 fprintf(fp, "RQ:\n");
4323 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
4325 fprintf(fp, "SSV:\n");
4327 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
4329 fprintf(fp, "NSV:\n");
4330 fprintf(fp, "SSH:\n");
4331 /* write recepient list */
4332 if (compose->to_list) {
4333 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
4334 for (cur = compose->to_list->next; cur != NULL;
4336 fprintf(fp, ",<%s>", (gchar *)cur->data);
4339 /* write newsgroup list */
4340 if (compose->newsgroup_list) {
4342 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
4343 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
4344 fprintf(fp, ",%s", (gchar *)cur->data);
4347 /* Sylpheed account IDs */
4349 fprintf(fp, "MAID:%d\n", mailac->account_id);
4351 fprintf(fp, "NAID:%d\n", newsac->account_id);
4353 if (compose->privacy_system != NULL) {
4354 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
4355 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
4356 if (compose->use_encryption) {
4359 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
4360 if (encdata != NULL) {
4361 if (strcmp(encdata, "_DONT_ENCRYPT_")) {
4362 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4363 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
4365 } /* else we finally dont want to encrypt */
4367 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
4368 /* and if encdata was null, it means there's been a problem in
4375 /* Save copy folder */
4376 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4377 gchar *savefolderid;
4379 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4380 fprintf(fp, "SCF:%s\n", savefolderid);
4381 g_free(savefolderid);
4383 /* Message-ID of message replying to */
4384 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
4387 folderid = folder_item_get_identifier(compose->replyinfo->folder);
4388 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
4391 /* Message-ID of message forwarding to */
4392 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
4395 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
4396 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
4401 if (compose->redirect_filename != NULL) {
4402 if (compose_redirect_write_to_file(compose, fp) < 0) {
4411 if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND)) < 0) {
4416 return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
4420 if (fclose(fp) == EOF) {
4421 FILE_OP_ERROR(tmp, "fclose");
4427 queue = account_get_special_folder(compose->account, F_QUEUE);
4429 g_warning("can't find queue folder\n");
4434 folder_item_scan(queue);
4435 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
4436 g_warning("can't queue the message\n");
4444 if (compose->mode == COMPOSE_REEDIT) {
4445 compose_remove_reedit_target(compose);
4448 if ((msgnum != NULL) && (item != NULL)) {
4456 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
4459 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
4461 struct stat statbuf;
4462 gchar *type, *subtype;
4463 GtkTreeModel *model;
4466 model = gtk_tree_view_get_model(tree_view);
4468 if (!gtk_tree_model_get_iter_first(model, &iter))
4471 gtk_tree_model_get(model, &iter,
4475 mimepart = procmime_mimeinfo_new();
4476 mimepart->content = MIMECONTENT_FILE;
4477 mimepart->data.filename = g_strdup(ainfo->file);
4478 mimepart->offset = 0;
4480 stat(ainfo->file, &statbuf);
4481 mimepart->length = statbuf.st_size;
4483 type = g_strdup(ainfo->content_type);
4485 if (!strchr(type, '/')) {
4487 type = g_strdup("application/octet-stream");
4490 subtype = strchr(type, '/') + 1;
4491 *(subtype - 1) = '\0';
4492 mimepart->type = procmime_get_media_type(type);
4493 mimepart->subtype = g_strdup(subtype);
4496 if (mimepart->type == MIMETYPE_MESSAGE &&
4497 !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) {
4498 mimepart->disposition = DISPOSITIONTYPE_INLINE;
4500 g_hash_table_insert(mimepart->typeparameters,
4501 g_strdup("name"), g_strdup(ainfo->name));
4502 g_hash_table_insert(mimepart->dispositionparameters,
4503 g_strdup("filename"), g_strdup(ainfo->name));
4504 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
4507 if (compose->use_signing) {
4508 if (ainfo->encoding == ENC_7BIT)
4509 ainfo->encoding = ENC_QUOTED_PRINTABLE;
4510 else if (ainfo->encoding == ENC_8BIT)
4511 ainfo->encoding = ENC_BASE64;
4514 procmime_encode_content(mimepart, ainfo->encoding);
4516 g_node_append(parent->node, mimepart->node);
4517 } while (gtk_tree_model_iter_next(model, &iter));
4520 #define QUOTE_IF_REQUIRED(out, str) \
4522 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4526 len = strlen(str) + 3; \
4527 if ((__tmp = alloca(len)) == NULL) { \
4528 g_warning("can't allocate memory\n"); \
4529 g_string_free(header, TRUE); \
4532 g_snprintf(__tmp, len, "\"%s\"", str); \
4537 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
4538 g_warning("can't allocate memory\n"); \
4539 g_string_free(header, TRUE); \
4542 strcpy(__tmp, str); \
4548 #define IS_IN_CUSTOM_HEADER(header) \
4549 (compose->account->add_customhdr && \
4550 custom_header_find(compose->account->customhdr_list, header) != NULL)
4552 static void compose_add_headerfield_from_headerlist(Compose *compose,
4554 const gchar *fieldname,
4555 const gchar *seperator)
4557 gchar *str, *fieldname_w_colon, *trans_fieldname;
4558 gboolean add_field = FALSE;
4560 ComposeHeaderEntry *headerentry;
4561 const gchar * headerentryname;
4564 if (IS_IN_CUSTOM_HEADER(fieldname))
4567 debug_print("Adding %s-fields\n", fieldname);
4569 fieldstr = g_string_sized_new(64);
4571 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
4572 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
4574 for (list = compose->header_list; list; list = list->next) {
4575 headerentry = ((ComposeHeaderEntry *)list->data);
4576 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4578 if (!g_utf8_collate(trans_fieldname, headerentryname)) {
4579 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
4581 if (str[0] != '\0') {
4583 g_string_append(fieldstr, seperator);
4584 g_string_append(fieldstr, str);
4593 buf = g_new0(gchar, fieldstr->len * 4 + 256);
4594 compose_convert_header
4595 (compose, buf, fieldstr->len * 4 + 256, fieldstr->str,
4596 strlen(fieldname) + 2, TRUE);
4597 g_string_append_printf(header, "%s: %s\n", fieldname, buf);
4601 g_free(fieldname_w_colon);
4602 g_string_free(fieldstr, TRUE);
4607 static gchar *compose_get_header(Compose *compose)
4609 gchar buf[BUFFSIZE];
4610 const gchar *entry_str;
4614 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4617 g_return_val_if_fail(compose->account != NULL, NULL);
4618 g_return_val_if_fail(compose->account->address != NULL, NULL);
4620 header = g_string_sized_new(64);
4623 if (compose->account->add_date) {
4624 get_rfc822_date(buf, sizeof(buf));
4625 g_string_append_printf(header, "Date: %s\n", buf);
4629 if (compose->account->name && *compose->account->name) {
4630 compose_convert_header
4631 (compose, buf, sizeof(buf), compose->account->name,
4632 strlen("From: "), TRUE);
4633 QUOTE_IF_REQUIRED(name, buf);
4634 g_string_append_printf(header, "From: %s <%s>\n",
4635 name, compose->account->address);
4637 g_string_append_printf(header, "From: %s\n", compose->account->address);
4640 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
4643 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
4646 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
4649 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
4652 str = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
4654 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4657 compose_convert_header(compose, buf, sizeof(buf), str,
4658 strlen("Subject: "), FALSE);
4659 g_string_append_printf(header, "Subject: %s\n", buf);
4665 if (compose->account->gen_msgid) {
4666 generate_msgid(buf, sizeof(buf));
4667 g_string_append_printf(header, "Message-ID: <%s>\n", buf);
4668 compose->msgid = g_strdup(buf);
4671 if (compose->remove_references == FALSE) {
4673 if (compose->inreplyto && compose->to_list)
4674 g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4677 if (compose->references)
4678 g_string_append_printf(header, "References: %s\n", compose->references);
4682 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4685 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4688 if (compose->account->organization &&
4689 strlen(compose->account->organization) &&
4690 !IS_IN_CUSTOM_HEADER("Organization")) {
4691 compose_convert_header(compose, buf, sizeof(buf),
4692 compose->account->organization,
4693 strlen("Organization: "), FALSE);
4694 g_string_append_printf(header, "Organization: %s\n", buf);
4697 /* Program version and system info */
4698 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4699 !compose->newsgroup_list) {
4700 g_string_append_printf(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4702 gtk_major_version, gtk_minor_version, gtk_micro_version,
4705 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4706 g_string_append_printf(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4708 gtk_major_version, gtk_minor_version, gtk_micro_version,
4712 /* custom headers */
4713 if (compose->account->add_customhdr) {
4716 for (cur = compose->account->customhdr_list; cur != NULL;
4718 CustomHeader *chdr = (CustomHeader *)cur->data;
4720 if (custom_header_is_allowed(chdr->name)) {
4721 compose_convert_header
4722 (compose, buf, sizeof(buf),
4723 chdr->value ? chdr->value : "",
4724 strlen(chdr->name) + 2, FALSE);
4725 g_string_append_printf(header, "%s: %s\n", chdr->name, buf);
4731 switch (compose->priority) {
4732 case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"
4733 "X-Priority: 1 (Highest)\n");
4735 case PRIORITY_HIGH: g_string_append_printf(header, "Importance: high\n"
4736 "X-Priority: 2 (High)\n");
4738 case PRIORITY_NORMAL: break;
4739 case PRIORITY_LOW: g_string_append_printf(header, "Importance: low\n"
4740 "X-Priority: 4 (Low)\n");
4742 case PRIORITY_LOWEST: g_string_append_printf(header, "Importance: low\n"
4743 "X-Priority: 5 (Lowest)\n");
4745 default: debug_print("compose: priority unknown : %d\n",
4749 /* Request Return Receipt */
4750 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4751 if (compose->return_receipt) {
4752 if (compose->account->name
4753 && *compose->account->name) {
4754 compose_convert_header(compose, buf, sizeof(buf),
4755 compose->account->name,
4756 strlen("Disposition-Notification-To: "),
4758 g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4760 g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
4764 /* get special headers */
4765 for (list = compose->header_list; list; list = list->next) {
4766 ComposeHeaderEntry *headerentry;
4769 gchar *headername_wcolon;
4770 gchar *headername_trans;
4773 gboolean standard_header = FALSE;
4775 headerentry = ((ComposeHeaderEntry *)list->data);
4777 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4778 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4783 if (!strstr(tmp, ":")) {
4784 headername_wcolon = g_strconcat(tmp, ":", NULL);
4785 headername = g_strdup(tmp);
4787 headername_wcolon = g_strdup(tmp);
4788 headername = g_strdup(strtok(tmp, ":"));
4792 entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4793 Xstrdup_a(headervalue, entry_str, return NULL);
4794 subst_char(headervalue, '\r', ' ');
4795 subst_char(headervalue, '\n', ' ');
4796 string = std_headers;
4797 while (*string != NULL) {
4798 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4799 if (!strcmp(headername_trans,headername_wcolon))
4800 standard_header = TRUE;
4803 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4804 g_string_append_printf(header, "%s %s\n", headername_wcolon, headervalue);
4807 g_free(headername_wcolon);
4811 g_string_free(header, FALSE);
4816 #undef IS_IN_CUSTOM_HEADER
4818 static void compose_convert_header(Compose *compose, gchar *dest, gint len, gchar *src,
4819 gint header_len, gboolean addr_field)
4821 gchar *tmpstr = NULL;
4822 const gchar *out_codeset = NULL;
4824 g_return_if_fail(src != NULL);
4825 g_return_if_fail(dest != NULL);
4827 if (len < 1) return;
4829 tmpstr = g_strdup(src);
4831 subst_char(tmpstr, '\n', ' ');
4832 subst_char(tmpstr, '\r', ' ');
4835 if (!g_utf8_validate(tmpstr, -1, NULL)) {
4836 gchar *mybuf = g_malloc(strlen(tmpstr)*2 +1);
4837 conv_localetodisp(mybuf, strlen(tmpstr)*2 +1, tmpstr);
4842 codeconv_set_strict(TRUE);
4843 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4844 conv_get_charset_str(compose->out_encoding));
4845 codeconv_set_strict(FALSE);
4847 if (!dest || *dest == '\0') {
4848 gchar *test_conv_global_out = NULL;
4849 gchar *test_conv_reply = NULL;
4851 /* automatic mode. be automatic. */
4852 codeconv_set_strict(TRUE);
4854 out_codeset = conv_get_outgoing_charset_str();
4856 debug_print("trying to convert to %s\n", out_codeset);
4857 test_conv_global_out = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4860 if (!test_conv_global_out && compose->orig_charset) {
4861 out_codeset = compose->orig_charset;
4862 debug_print("failure; trying to convert to %s\n", out_codeset);
4863 test_conv_reply = conv_codeset_strdup(src, CS_INTERNAL, out_codeset);
4866 if (!test_conv_global_out && !test_conv_reply) {
4868 out_codeset = CS_INTERNAL;
4869 debug_print("finally using %s\n", out_codeset);
4871 g_free(test_conv_global_out);
4872 g_free(test_conv_reply);
4873 conv_encode_header_full(dest, len, tmpstr, header_len, addr_field,
4875 codeconv_set_strict(FALSE);
4880 static void compose_create_header_entry(Compose *compose)
4882 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4886 GList *combo_list = NULL;
4888 const gchar *header = NULL;
4889 ComposeHeaderEntry *headerentry;
4890 gboolean standard_header = FALSE;
4892 headerentry = g_new0(ComposeHeaderEntry, 1);
4895 combo = gtk_combo_new();
4897 while(*string != NULL) {
4898 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4901 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4902 g_list_free(combo_list);
4903 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4904 g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4905 G_CALLBACK(compose_grab_focus_cb), compose);
4906 gtk_widget_show(combo);
4907 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4908 if (compose->header_last) {
4909 const gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4911 while (*string != NULL) {
4912 if (!strcmp(*string, last_header_entry))
4913 standard_header = TRUE;
4916 if (standard_header)
4917 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4919 if (!compose->header_last || !standard_header) {
4920 switch(compose->account->protocol) {
4922 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4925 header = prefs_common.trans_hdr ? _("To:") : "To:";
4930 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4932 g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
4933 G_CALLBACK(compose_grab_focus_cb), compose);
4936 entry = gtk_entry_new();
4937 gtk_widget_show(entry);
4938 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);
4940 g_signal_connect(G_OBJECT(entry), "key-press-event",
4941 G_CALLBACK(compose_headerentry_key_press_event_cb),
4943 g_signal_connect(G_OBJECT(entry), "changed",
4944 G_CALLBACK(compose_headerentry_changed_cb),
4946 g_signal_connect_after(G_OBJECT(entry), "grab_focus",
4947 G_CALLBACK(compose_grab_focus_cb), compose);
4950 gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types,
4951 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
4952 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4953 g_signal_connect(G_OBJECT(entry), "drag_data_received",
4954 G_CALLBACK(compose_header_drag_received_cb),
4956 g_signal_connect(G_OBJECT(entry), "drag-drop",
4957 G_CALLBACK(compose_drag_drop),
4960 address_completion_register_entry(GTK_ENTRY(entry));
4962 headerentry->compose = compose;
4963 headerentry->combo = combo;
4964 headerentry->entry = entry;
4965 headerentry->headernum = compose->header_nextrow;
4967 compose->header_nextrow++;
4968 compose->header_last = headerentry;
4971 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4973 ComposeHeaderEntry *last_header;
4975 last_header = compose->header_last;
4977 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4978 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4981 static GtkWidget *compose_create_header(Compose *compose)
4985 GtkWidget *from_optmenu_hbox;
4986 GtkWidget *header_scrolledwin;
4987 GtkWidget *header_table;
4991 /* header labels and entries */
4992 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4993 gtk_widget_show(header_scrolledwin);
4994 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4996 header_table = gtk_table_new(2, 2, FALSE);
4997 gtk_widget_show(header_table);
4998 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4999 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
5000 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
5003 /* option menu for selecting accounts */
5004 hbox = gtk_hbox_new(FALSE, 0);
5005 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
5006 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
5007 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
5009 from_optmenu_hbox = compose_account_option_menu_create(compose);
5010 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
5011 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
5014 compose->header_table = header_table;
5015 compose->header_list = NULL;
5016 compose->header_nextrow = count;
5018 compose_create_header_entry(compose);
5020 compose->table = NULL;
5022 return header_scrolledwin ;
5025 GtkWidget *compose_create_attach(Compose *compose)
5027 GtkWidget *attach_scrwin;
5028 GtkWidget *attach_clist;
5030 GtkListStore *store;
5031 GtkCellRenderer *renderer;
5032 GtkTreeViewColumn *column;
5033 GtkTreeSelection *selection;
5035 /* attachment list */
5036 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
5037 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
5038 GTK_POLICY_AUTOMATIC,
5039 GTK_POLICY_AUTOMATIC);
5040 gtk_widget_set_size_request(attach_scrwin, -1, 80);
5042 store = gtk_list_store_new(N_ATTACH_COLS,
5047 G_TYPE_AUTO_POINTER,
5049 attach_clist = GTK_WIDGET(gtk_tree_view_new_with_model
5050 (GTK_TREE_MODEL(store)));
5051 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
5052 g_object_unref(store);
5054 renderer = gtk_cell_renderer_text_new();
5055 column = gtk_tree_view_column_new_with_attributes
5056 (_("Mime type"), renderer, "text",
5057 COL_MIMETYPE, NULL);
5058 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5060 renderer = gtk_cell_renderer_text_new();
5061 column = gtk_tree_view_column_new_with_attributes
5062 (_("Size"), renderer, "text",
5064 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5066 renderer = gtk_cell_renderer_text_new();
5067 column = gtk_tree_view_column_new_with_attributes
5068 (_("Name"), renderer, "text",
5070 gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column);
5072 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(attach_clist),
5073 prefs_common.enable_rules_hint);
5074 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(attach_clist));
5075 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
5077 g_signal_connect(G_OBJECT(attach_clist), "row_activated",
5078 G_CALLBACK(attach_selected), compose);
5079 g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
5080 G_CALLBACK(attach_button_pressed), compose);
5081 g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
5082 G_CALLBACK(attach_key_pressed), compose);
5085 gtk_drag_dest_set(attach_clist,
5086 GTK_DEST_DEFAULT_ALL, compose_mime_types,
5087 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5088 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5089 g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
5090 G_CALLBACK(compose_attach_drag_received_cb),
5092 g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
5093 G_CALLBACK(compose_drag_drop),
5096 compose->attach_scrwin = attach_scrwin;
5097 compose->attach_clist = attach_clist;
5099 return attach_scrwin;
5102 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
5103 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
5105 static GtkWidget *compose_create_others(Compose *compose)
5108 GtkWidget *savemsg_checkbtn;
5109 GtkWidget *savemsg_entry;
5110 GtkWidget *savemsg_select;
5113 gchar *folderidentifier;
5115 /* Table for settings */
5116 table = gtk_table_new(3, 1, FALSE);
5117 gtk_widget_show(table);
5118 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
5121 /* Save Message to folder */
5122 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
5123 gtk_widget_show(savemsg_checkbtn);
5124 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5125 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5126 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
5128 g_signal_connect(G_OBJECT(savemsg_checkbtn), "toggled",
5129 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
5131 savemsg_entry = gtk_entry_new();
5132 gtk_widget_show(savemsg_entry);
5133 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
5134 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
5135 g_signal_connect_after(G_OBJECT(savemsg_entry), "grab_focus",
5136 G_CALLBACK(compose_grab_focus_cb), compose);
5137 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5138 folderidentifier = folder_item_get_identifier(account_get_special_folder
5139 (compose->account, F_OUTBOX));
5140 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
5141 g_free(folderidentifier);
5144 savemsg_select = gtk_button_new_with_label (_("Select ..."));
5145 gtk_widget_show(savemsg_select);
5146 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
5147 g_signal_connect(G_OBJECT(savemsg_select), "clicked",
5148 G_CALLBACK(compose_savemsg_select_cb),
5153 compose->savemsg_checkbtn = savemsg_checkbtn;
5154 compose->savemsg_entry = savemsg_entry;
5159 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
5161 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
5162 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
5165 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
5170 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
5173 path = folder_item_get_identifier(dest);
5175 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
5179 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap,
5182 #define BLOCK_WRAP() { \
5183 prev_autowrap = compose->autowrap; \
5184 buffer = gtk_text_view_get_buffer( \
5185 GTK_TEXT_VIEW(compose->text)); \
5186 compose->autowrap = FALSE; \
5188 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5189 G_CALLBACK(compose_changed_cb), \
5191 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
5192 G_CALLBACK(text_inserted), \
5195 #define UNBLOCK_WRAP() { \
5196 compose->autowrap = prev_autowrap; \
5197 if (compose->autowrap) \
5198 compose_wrap_all(compose); \
5200 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5201 G_CALLBACK(compose_changed_cb), \
5203 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
5204 G_CALLBACK(text_inserted), \
5209 static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
5213 GtkTextBuffer *buffer;
5215 if (event->button == 3) {
5218 /* move the cursor to allow GtkAspell to check the word
5219 * under the mouse */
5220 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
5221 GTK_TEXT_WINDOW_TEXT, event->x, event->y,
5223 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
5225 gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
5226 return FALSE; /* pass the event so that the right-click goes through */
5229 if (event->button == 2) {
5231 entry_paste_clipboard(compose, compose->focused_editable,
5232 prefs_common.linewrap_pastes,
5233 GDK_SELECTION_PRIMARY);
5240 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
5246 GtkWidget *handlebox;
5248 GtkWidget *notebook;
5253 GtkWidget *subject_hbox;
5254 GtkWidget *subject_frame;
5255 GtkWidget *subject_entry;
5259 GtkWidget *edit_vbox;
5260 GtkWidget *ruler_hbox;
5262 GtkWidget *scrolledwin;
5264 GtkTextBuffer *buffer;
5265 GtkClipboard *clipboard;
5267 UndoMain *undostruct;
5269 gchar *titles[N_ATTACH_COLS];
5270 guint n_menu_entries;
5273 gboolean success[1];
5274 GtkWidget *popupmenu;
5275 GtkItemFactory *popupfactory;
5276 GtkItemFactory *ifactory;
5277 GtkWidget *tmpl_menu;
5279 GtkWidget *menuitem;
5282 GtkAspell * gtkaspell = NULL;
5285 static GdkGeometry geometry;
5287 g_return_val_if_fail(account != NULL, NULL);
5289 debug_print("Creating compose window...\n");
5290 compose = g_new0(Compose, 1);
5292 titles[COL_MIMETYPE] = _("MIME type");
5293 titles[COL_SIZE] = _("Size");
5294 titles[COL_NAME] = _("Name");
5296 compose->account = account;
5298 compose->mutex = g_mutex_new();
5300 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
5301 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
5302 gtk_widget_set_size_request(window, -1, prefs_common.compose_height);
5304 if (!geometry.max_width) {
5305 geometry.max_width = gdk_screen_width();
5306 geometry.max_height = gdk_screen_height();
5309 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5310 &geometry, GDK_HINT_MAX_SIZE);
5311 if (!geometry.min_width) {
5312 geometry.min_width = 600;
5313 geometry.min_height = 480;
5315 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
5316 &geometry, GDK_HINT_MIN_SIZE);
5317 gtk_widget_set_uposition(window, prefs_common.compose_x,
5318 prefs_common.compose_y);
5320 g_signal_connect(G_OBJECT(window), "delete_event",
5321 G_CALLBACK(compose_delete_cb), compose);
5322 MANAGE_WINDOW_SIGNALS_CONNECT(window);
5323 gtk_widget_realize(window);
5325 gtkut_widget_set_composer_icon(window);
5327 vbox = gtk_vbox_new(FALSE, 0);
5328 gtk_container_add(GTK_CONTAINER(window), vbox);
5330 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
5331 menubar = menubar_create(window, compose_entries,
5332 n_menu_entries, "<Compose>", compose);
5333 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
5335 if (prefs_common.toolbar_detachable) {
5336 handlebox = gtk_handle_box_new();
5338 handlebox = gtk_hbox_new(FALSE, 0);
5340 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
5342 gtk_widget_realize(handlebox);
5343 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
5346 vbox2 = gtk_vbox_new(FALSE, 2);
5347 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
5348 gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0);
5351 notebook = gtk_notebook_new();
5352 gtk_widget_set_size_request(notebook, -1, 130);
5353 gtk_widget_show(notebook);
5355 /* header labels and entries */
5356 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
5357 /* attachment list */
5358 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
5360 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
5363 subject_hbox = gtk_hbox_new(FALSE, 0);
5364 gtk_widget_show(subject_hbox);
5366 subject_frame = gtk_frame_new(NULL);
5367 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_NONE);
5368 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, 0);
5369 gtk_widget_show(subject_frame);
5371 subject = gtk_hbox_new(FALSE, 0);
5372 gtk_container_set_border_width(GTK_CONTAINER(subject), 0);
5373 gtk_widget_show(subject);
5375 label = gtk_label_new(_("Subject:"));
5376 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 0);
5377 gtk_widget_show(label);
5379 subject_entry = gtk_entry_new();
5380 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 0);
5381 g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
5382 G_CALLBACK(compose_grab_focus_cb), compose);
5383 gtk_widget_show(subject_entry);
5384 compose->subject_entry = subject_entry;
5385 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5387 edit_vbox = gtk_vbox_new(FALSE, 0);
5389 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5392 ruler_hbox = gtk_hbox_new(FALSE, 0);
5393 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5395 ruler = gtk_shruler_new();
5396 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5397 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5401 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5402 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5403 GTK_POLICY_AUTOMATIC,
5404 GTK_POLICY_AUTOMATIC);
5405 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
5407 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5408 gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
5410 text = gtk_text_view_new();
5411 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
5412 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
5413 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
5414 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
5415 gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
5417 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5419 g_signal_connect_after(G_OBJECT(text), "size_allocate",
5420 G_CALLBACK(compose_edit_size_alloc),
5422 g_signal_connect(G_OBJECT(buffer), "changed",
5423 G_CALLBACK(compose_changed_cb), compose);
5424 g_signal_connect(G_OBJECT(text), "grab_focus",
5425 G_CALLBACK(compose_grab_focus_cb), compose);
5426 g_signal_connect(G_OBJECT(buffer), "insert_text",
5427 G_CALLBACK(text_inserted), compose);
5428 g_signal_connect(G_OBJECT(text), "button_press_event",
5429 G_CALLBACK(text_clicked), compose);
5432 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types,
5433 sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
5434 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5435 g_signal_connect(G_OBJECT(text), "drag_data_received",
5436 G_CALLBACK(compose_insert_drag_received_cb),
5438 g_signal_connect(G_OBJECT(text), "drag-drop",
5439 G_CALLBACK(compose_drag_drop),
5441 gtk_widget_show_all(vbox);
5443 /* pane between attach clist and text */
5444 paned = gtk_vpaned_new();
5445 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5446 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5447 gtk_paned_add1(GTK_PANED(paned), notebook);
5448 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5449 gtk_widget_show_all(paned);
5452 if (prefs_common.textfont) {
5453 PangoFontDescription *font_desc;
5455 font_desc = pango_font_description_from_string
5456 (prefs_common.textfont);
5458 gtk_widget_modify_font(text, font_desc);
5459 pango_font_description_free(font_desc);
5463 color[0] = quote_color;
5464 cmap = gdk_drawable_get_colormap(window->window);
5465 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5466 if (success[0] == FALSE) {
5469 g_warning("Compose: color allocation failed.\n");
5470 style = gtk_widget_get_style(text);
5471 quote_color = style->black;
5474 n_entries = sizeof(compose_popup_entries) /
5475 sizeof(compose_popup_entries[0]);
5476 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5477 "<Compose>", &popupfactory,
5480 ifactory = gtk_item_factory_from_widget(menubar);
5481 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5482 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5483 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
5485 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5487 undostruct = undo_init(text);
5488 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5491 address_completion_start(window);
5493 compose->window = window;
5494 compose->vbox = vbox;
5495 compose->menubar = menubar;
5496 compose->handlebox = handlebox;
5498 compose->vbox2 = vbox2;
5500 compose->paned = paned;
5502 compose->edit_vbox = edit_vbox;
5503 compose->ruler_hbox = ruler_hbox;
5504 compose->ruler = ruler;
5505 compose->scrolledwin = scrolledwin;
5506 compose->text = text;
5508 compose->focused_editable = NULL;
5510 compose->popupmenu = popupmenu;
5511 compose->popupfactory = popupfactory;
5513 compose->tmpl_menu = tmpl_menu;
5515 compose->mode = mode;
5517 compose->targetinfo = NULL;
5518 compose->replyinfo = NULL;
5519 compose->fwdinfo = NULL;
5521 compose->replyto = NULL;
5523 compose->bcc = NULL;
5524 compose->followup_to = NULL;
5526 compose->ml_post = NULL;
5528 compose->inreplyto = NULL;
5529 compose->references = NULL;
5530 compose->msgid = NULL;
5531 compose->boundary = NULL;
5533 compose->autowrap = prefs_common.autowrap;
5535 compose->use_signing = FALSE;
5536 compose->use_encryption = FALSE;
5537 compose->privacy_system = NULL;
5539 compose->modified = FALSE;
5541 compose->return_receipt = FALSE;
5543 compose->to_list = NULL;
5544 compose->newsgroup_list = NULL;
5546 compose->undostruct = undostruct;
5548 compose->sig_str = NULL;
5550 compose->exteditor_file = NULL;
5551 compose->exteditor_pid = -1;
5552 compose->exteditor_tag = -1;
5553 compose->draft_timeout_tag = -1;
5556 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5557 if (mode != COMPOSE_REDIRECT) {
5558 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5559 strcmp(prefs_common.dictionary, _("None"))) {
5560 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5561 prefs_common.dictionary,
5562 conv_get_locale_charset_str(),
5563 prefs_common.misspelled_col,
5564 prefs_common.check_while_typing,
5565 prefs_common.use_alternate,
5566 GTK_TEXT_VIEW(text),
5567 GTK_WINDOW(compose->window));
5569 alertpanel_error(_("Spell checker could not "
5571 gtkaspell_checkers_strerror());
5572 gtkaspell_checkers_reset_error();
5574 if (!gtkaspell_set_sug_mode(gtkaspell,
5575 prefs_common.aspell_sugmode)) {
5576 debug_print("Aspell: could not set "
5577 "suggestion mode %s\n",
5578 gtkaspell_checkers_strerror());
5579 gtkaspell_checkers_reset_error();
5582 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5586 compose->gtkaspell = gtkaspell;
5589 compose_select_account(compose, account, TRUE);
5591 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
5592 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5593 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5595 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
5596 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5598 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5599 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5602 if (account->protocol != A_NNTP)
5603 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5605 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5607 addressbook_set_target_compose(compose);
5609 if (mode != COMPOSE_REDIRECT)
5610 compose_set_template_menu(compose);
5612 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5613 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5616 compose_list = g_list_append(compose_list, compose);
5618 if (!prefs_common.show_ruler)
5619 gtk_widget_hide(ruler_hbox);
5621 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Show ruler");
5622 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
5623 prefs_common.show_ruler);
5626 compose->priority = PRIORITY_NORMAL;
5627 compose_update_priority_menu_item(compose);
5629 compose_set_out_encoding(compose);
5632 compose_update_actions_menu(compose);
5634 /* Privacy Systems menu */
5635 compose_update_privacy_systems_menu(compose);
5637 activate_privacy_system(compose, account, TRUE);
5638 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5639 gtk_widget_show(window);
5644 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5650 gint num = 0, def_menu = 0;
5652 accounts = account_get_list();
5653 g_return_val_if_fail(accounts != NULL, NULL);
5655 hbox = gtk_hbox_new(FALSE, 0);
5656 optmenu = gtk_option_menu_new();
5657 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5658 menu = gtk_menu_new();
5660 for (; accounts != NULL; accounts = accounts->next, num++) {
5661 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5662 GtkWidget *menuitem;
5665 if (ac == compose->account) def_menu = num;
5668 name = g_strdup_printf("%s: %s <%s>",
5670 ac->name, ac->address);
5672 name = g_strdup_printf("%s: %s",
5673 ac->account_name, ac->address);
5674 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5676 g_signal_connect(G_OBJECT(menuitem), "activate",
5677 G_CALLBACK(account_activated),
5681 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5682 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5687 static void compose_set_priority_cb(gpointer data,
5691 Compose *compose = (Compose *) data;
5692 compose->priority = action;
5695 static void compose_update_priority_menu_item(Compose * compose)
5697 GtkItemFactory *ifactory;
5698 GtkWidget *menuitem = NULL;
5700 ifactory = gtk_item_factory_from_widget(compose->menubar);
5702 switch (compose->priority) {
5703 case PRIORITY_HIGHEST:
5704 menuitem = gtk_item_factory_get_item
5705 (ifactory, "/Options/Priority/Highest");
5708 menuitem = gtk_item_factory_get_item
5709 (ifactory, "/Options/Priority/High");
5711 case PRIORITY_NORMAL:
5712 menuitem = gtk_item_factory_get_item
5713 (ifactory, "/Options/Priority/Normal");
5716 menuitem = gtk_item_factory_get_item
5717 (ifactory, "/Options/Priority/Low");
5719 case PRIORITY_LOWEST:
5720 menuitem = gtk_item_factory_get_item
5721 (ifactory, "/Options/Priority/Lowest");
5724 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5727 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5729 Compose *compose = (Compose *) data;
5731 GtkItemFactory *ifactory;
5732 gboolean can_sign = FALSE, can_encrypt = FALSE;
5734 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5736 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5739 systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
5740 g_free(compose->privacy_system);
5741 compose->privacy_system = NULL;
5742 if (systemid != NULL) {
5743 compose->privacy_system = g_strdup(systemid);
5745 can_sign = privacy_system_can_sign(systemid);
5746 can_encrypt = privacy_system_can_encrypt(systemid);
5749 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5751 ifactory = gtk_item_factory_from_widget(compose->menubar);
5752 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5753 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5756 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn)
5758 static gchar *branch_path = "/Options/Privacy System";
5759 GtkItemFactory *ifactory;
5760 GtkWidget *menuitem = NULL;
5762 gboolean can_sign = FALSE, can_encrypt = FALSE;
5763 gboolean found = FALSE;
5765 ifactory = gtk_item_factory_from_widget(compose->menubar);
5767 if (compose->privacy_system != NULL) {
5770 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5771 g_return_if_fail(menuitem != NULL);
5773 amenu = GTK_MENU_SHELL(menuitem)->children;
5775 while (amenu != NULL) {
5776 GList *alist = amenu->next;
5778 systemid = g_object_get_data(G_OBJECT(amenu->data), "privacy_system");
5779 if (systemid != NULL) {
5780 if (strcmp(systemid, compose->privacy_system) == 0) {
5781 menuitem = GTK_WIDGET(amenu->data);
5783 can_sign = privacy_system_can_sign(systemid);
5784 can_encrypt = privacy_system_can_encrypt(systemid);
5788 } else if (strlen(compose->privacy_system) == 0) {
5789 menuitem = GTK_WIDGET(amenu->data);
5792 can_encrypt = FALSE;
5799 if (menuitem != NULL)
5800 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5802 if (warn && !found && strlen(compose->privacy_system)) {
5803 gchar *tmp = g_strdup_printf(
5804 _("The privacy system '%s' cannot be loaded. You "
5805 "will not be able to sign or encrypt this message."),
5806 compose->privacy_system);
5807 alertpanel_warning(tmp);
5812 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5813 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5816 static void compose_set_out_encoding(Compose *compose)
5818 GtkItemFactoryEntry *entry;
5819 GtkItemFactory *ifactory;
5820 CharSet out_encoding;
5821 gchar *path, *p, *q;
5824 out_encoding = conv_get_charset_from_str(prefs_common.outgoing_charset);
5825 ifactory = gtk_item_factory_from_widget(compose->menubar);
5827 for (entry = compose_entries; entry->callback != compose_address_cb;
5829 if (entry->callback == compose_set_encoding_cb &&
5830 (CharSet)entry->callback_action == out_encoding) {
5831 p = q = path = g_strdup(entry->path);
5843 item = gtk_item_factory_get_item(ifactory, path);
5844 gtk_widget_activate(item);
5851 static void compose_set_template_menu(Compose *compose)
5853 GSList *tmpl_list, *cur;
5857 tmpl_list = template_get_config();
5859 menu = gtk_menu_new();
5861 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5862 Template *tmpl = (Template *)cur->data;
5864 item = gtk_menu_item_new_with_label(tmpl->name);
5865 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
5866 g_signal_connect(G_OBJECT(item), "activate",
5867 G_CALLBACK(compose_template_activate_cb),
5869 g_object_set_data(G_OBJECT(item), "template", tmpl);
5870 gtk_widget_show(item);
5873 gtk_widget_show(menu);
5874 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5877 void compose_update_actions_menu(Compose *compose)
5879 GtkItemFactory *ifactory;
5881 ifactory = gtk_item_factory_from_widget(compose->menubar);
5882 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5885 void compose_update_privacy_systems_menu(Compose *compose)
5887 static gchar *branch_path = "/Options/Privacy System";
5888 GtkItemFactory *ifactory;
5889 GtkWidget *menuitem;
5890 GSList *systems, *cur;
5893 GtkWidget *system_none;
5896 ifactory = gtk_item_factory_from_widget(compose->menubar);
5898 /* remove old entries */
5899 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5900 g_return_if_fail(menuitem != NULL);
5902 amenu = GTK_MENU_SHELL(menuitem)->children->next;
5903 while (amenu != NULL) {
5904 GList *alist = amenu->next;
5905 gtk_widget_destroy(GTK_WIDGET(amenu->data));
5909 system_none = gtk_item_factory_get_widget(ifactory,
5910 "/Options/Privacy System/None");
5912 g_signal_connect(G_OBJECT(system_none), "activate",
5913 G_CALLBACK(compose_set_privacy_system_cb), compose);
5915 systems = privacy_get_system_ids();
5916 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
5917 gchar *systemid = cur->data;
5919 group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(system_none));
5920 widget = gtk_radio_menu_item_new_with_label(group,
5921 privacy_system_get_name(systemid));
5922 g_object_set_data_full(G_OBJECT(widget), "privacy_system",
5923 g_strdup(systemid), g_free);
5924 g_signal_connect(G_OBJECT(widget), "activate",
5925 G_CALLBACK(compose_set_privacy_system_cb), compose);
5927 gtk_menu_append(GTK_MENU(system_none->parent), widget);
5928 gtk_widget_show(widget);
5931 g_slist_free(systems);
5934 void compose_reflect_prefs_all(void)
5939 for (cur = compose_list; cur != NULL; cur = cur->next) {
5940 compose = (Compose *)cur->data;
5941 compose_set_template_menu(compose);
5945 void compose_reflect_prefs_pixmap_theme(void)
5950 for (cur = compose_list; cur != NULL; cur = cur->next) {
5951 compose = (Compose *)cur->data;
5952 toolbar_update(TOOLBAR_COMPOSE, compose);
5956 static void compose_template_apply(Compose *compose, Template *tmpl,
5960 GtkTextBuffer *buffer;
5965 gint cursor_pos = 0;
5966 if (!tmpl || !tmpl->value) return;
5968 text = GTK_TEXT_VIEW(compose->text);
5969 buffer = gtk_text_view_get_buffer(text);
5971 if (tmpl->subject && *tmpl->subject != '\0')
5972 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5974 if (tmpl->to && *tmpl->to != '\0')
5975 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5976 if (tmpl->cc && *tmpl->cc != '\0')
5977 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5979 if (tmpl->bcc && *tmpl->bcc != '\0')
5980 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5983 gtk_text_buffer_set_text(buffer, "", -1);
5985 mark = gtk_text_buffer_get_insert(buffer);
5986 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
5988 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
5989 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5992 if (prefs_common.quotemark && *prefs_common.quotemark)
5993 qmark = prefs_common.quotemark;
5997 if (compose->replyinfo != NULL)
5998 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5999 tmpl->value, qmark, NULL);
6000 else if (compose->fwdinfo != NULL)
6001 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
6002 tmpl->value, qmark, NULL);
6007 if (replace && parsed_str && compose->account->auto_sig)
6008 compose_insert_sig(compose, FALSE);
6010 if (replace && parsed_str) {
6011 gtk_text_buffer_get_start_iter(buffer, &iter);
6012 gtk_text_buffer_place_cursor(buffer, &iter);
6016 cursor_pos = quote_fmt_get_cursor_pos();
6017 gtk_text_buffer_get_start_iter(buffer, &iter);
6018 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
6019 gtk_text_buffer_place_cursor(buffer, &iter);
6023 compose_changed_cb(NULL, compose);
6026 static void compose_destroy(Compose *compose)
6028 compose_list = g_list_remove(compose_list, compose);
6030 /* NOTE: address_completion_end() does nothing with the window
6031 * however this may change. */
6032 address_completion_end(compose->window);
6034 slist_free_strings(compose->to_list);
6035 g_slist_free(compose->to_list);
6036 slist_free_strings(compose->newsgroup_list);
6037 g_slist_free(compose->newsgroup_list);
6038 slist_free_strings(compose->header_list);
6039 g_slist_free(compose->header_list);
6041 procmsg_msginfo_free(compose->targetinfo);
6042 procmsg_msginfo_free(compose->replyinfo);
6043 procmsg_msginfo_free(compose->fwdinfo);
6045 g_free(compose->replyto);
6046 g_free(compose->cc);
6047 g_free(compose->bcc);
6048 g_free(compose->newsgroups);
6049 g_free(compose->followup_to);
6051 g_free(compose->ml_post);
6053 g_free(compose->inreplyto);
6054 g_free(compose->references);
6055 g_free(compose->msgid);
6056 g_free(compose->boundary);
6058 if (compose->redirect_filename)
6059 g_free(compose->redirect_filename);
6060 if (compose->undostruct)
6061 undo_destroy(compose->undostruct);
6063 g_free(compose->sig_str);
6065 g_free(compose->exteditor_file);
6067 g_free(compose->orig_charset);
6069 g_free(compose->privacy_system);
6071 if (addressbook_get_target_compose() == compose)
6072 addressbook_set_target_compose(NULL);
6075 if (compose->gtkaspell) {
6076 gtkaspell_delete(compose->gtkaspell);
6077 compose->gtkaspell = NULL;
6081 prefs_common.compose_width = compose->scrolledwin->allocation.width;
6082 prefs_common.compose_height = compose->window->allocation.height;
6084 if (!gtk_widget_get_parent(compose->paned))
6085 gtk_widget_destroy(compose->paned);
6086 gtk_widget_destroy(compose->popupmenu);
6088 gtk_widget_destroy(compose->window);
6089 toolbar_destroy(compose->toolbar);
6090 g_free(compose->toolbar);
6091 g_mutex_free(compose->mutex);
6095 static void compose_attach_info_free(AttachInfo *ainfo)
6097 g_free(ainfo->file);
6098 g_free(ainfo->content_type);
6099 g_free(ainfo->name);
6103 static void compose_attach_remove_selected(Compose *compose)
6105 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6106 GtkTreeSelection *selection;
6108 GtkTreeModel *model;
6110 selection = gtk_tree_view_get_selection(tree_view);
6111 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6116 for (cur = sel; cur != NULL; cur = cur->next) {
6117 GtkTreePath *path = cur->data;
6118 GtkTreeRowReference *ref = gtk_tree_row_reference_new
6121 gtk_tree_path_free(path);
6124 for (cur = sel; cur != NULL; cur = cur->next) {
6125 GtkTreeRowReference *ref = cur->data;
6126 GtkTreePath *path = gtk_tree_row_reference_get_path(ref);
6129 if (gtk_tree_model_get_iter(model, &iter, path))
6130 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
6132 gtk_tree_path_free(path);
6133 gtk_tree_row_reference_free(ref);
6139 static struct _AttachProperty
6142 GtkWidget *mimetype_entry;
6143 GtkWidget *encoding_optmenu;
6144 GtkWidget *path_entry;
6145 GtkWidget *filename_entry;
6147 GtkWidget *cancel_btn;
6150 static void gtk_tree_path_free_(gpointer ptr, gpointer data)
6152 gtk_tree_path_free((GtkTreePath *)ptr);
6155 static void compose_attach_property(Compose *compose)
6157 GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
6159 GtkOptionMenu *optmenu;
6160 GtkTreeSelection *selection;
6162 GtkTreeModel *model;
6165 static gboolean cancelled;
6167 /* only if one selected */
6168 selection = gtk_tree_view_get_selection(tree_view);
6169 if (gtk_tree_selection_count_selected_rows(selection) != 1)
6172 sel = gtk_tree_selection_get_selected_rows(selection, &model);
6176 path = (GtkTreePath *) sel->data;
6177 gtk_tree_model_get_iter(model, &iter, path);
6178 gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1);
6181 g_list_foreach(sel, gtk_tree_path_free_, NULL);
6187 if (!attach_prop.window)
6188 compose_attach_property_create(&cancelled);
6189 gtk_widget_grab_focus(attach_prop.ok_btn);
6190 gtk_widget_show(attach_prop.window);
6191 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
6193 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
6194 if (ainfo->encoding == ENC_UNKNOWN)
6195 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6196 GINT_TO_POINTER(ENC_BASE64));
6198 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
6199 GINT_TO_POINTER(ainfo->encoding));
6201 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
6202 ainfo->content_type ? ainfo->content_type : "");
6203 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
6204 ainfo->file ? ainfo->file : "");
6205 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
6206 ainfo->name ? ainfo->name : "");
6209 const gchar *entry_text;
6211 gchar *cnttype = NULL;
6215 GtkWidget *menuitem;
6220 gtk_widget_hide(attach_prop.window);
6225 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
6226 if (*entry_text != '\0') {
6229 text = g_strstrip(g_strdup(entry_text));
6230 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
6231 cnttype = g_strdup(text);
6234 alertpanel_error(_("Invalid MIME type."));
6240 menu = gtk_option_menu_get_menu(optmenu);
6241 menuitem = gtk_menu_get_active(GTK_MENU(menu));
6242 ainfo->encoding = GPOINTER_TO_INT
6243 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
6245 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
6246 if (*entry_text != '\0') {
6247 if (is_file_exist(entry_text) &&
6248 (size = get_file_size(entry_text)) > 0)
6249 file = g_strdup(entry_text);
6252 (_("File doesn't exist or is empty."));
6258 entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
6259 if (*entry_text != '\0') {
6260 g_free(ainfo->name);
6261 ainfo->name = g_strdup(entry_text);
6265 g_free(ainfo->content_type);
6266 ainfo->content_type = cnttype;
6269 g_free(ainfo->file);
6275 /* update tree store */
6276 text = to_human_readable(ainfo->size);
6277 gtk_tree_model_get_iter(model, &iter, path);
6278 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
6279 COL_MIMETYPE, ainfo->content_type,
6281 COL_NAME, ainfo->name,
6287 gtk_tree_path_free(path);
6290 #define SET_LABEL_AND_ENTRY(str, entry, top) \
6292 label = gtk_label_new(str); \
6293 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
6294 GTK_FILL, 0, 0, 0); \
6295 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
6297 entry = gtk_entry_new(); \
6298 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
6299 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
6302 static void compose_attach_property_create(gboolean *cancelled)
6308 GtkWidget *mimetype_entry;
6311 GtkWidget *optmenu_menu;
6312 GtkWidget *menuitem;
6313 GtkWidget *path_entry;
6314 GtkWidget *filename_entry;
6317 GtkWidget *cancel_btn;
6318 GList *mime_type_list, *strlist;
6320 debug_print("Creating attach_property window...\n");
6322 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
6323 gtk_widget_set_size_request(window, 480, -1);
6324 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
6325 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
6326 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
6327 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
6328 g_signal_connect(G_OBJECT(window), "delete_event",
6329 G_CALLBACK(attach_property_delete_event),
6331 g_signal_connect(G_OBJECT(window), "key_press_event",
6332 G_CALLBACK(attach_property_key_pressed),
6335 vbox = gtk_vbox_new(FALSE, 8);
6336 gtk_container_add(GTK_CONTAINER(window), vbox);
6338 table = gtk_table_new(4, 2, FALSE);
6339 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
6340 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
6341 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
6343 label = gtk_label_new(_("MIME type"));
6344 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
6346 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6347 mimetype_entry = gtk_combo_new();
6348 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
6349 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6351 /* stuff with list */
6352 mime_type_list = procmime_get_mime_type_list();
6354 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
6355 MimeType *type = (MimeType *) mime_type_list->data;
6356 strlist = g_list_append(strlist,
6357 g_strdup_printf("%s/%s",
6358 type->type, type->sub_type));
6361 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
6363 for (mime_type_list = strlist; mime_type_list != NULL;
6364 mime_type_list = mime_type_list->next)
6365 g_free(mime_type_list->data);
6366 g_list_free(strlist);
6368 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
6370 label = gtk_label_new(_("Encoding"));
6371 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
6373 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
6375 hbox = gtk_hbox_new(FALSE, 0);
6376 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
6377 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
6379 optmenu = gtk_option_menu_new();
6380 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
6382 optmenu_menu = gtk_menu_new();
6383 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
6384 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6385 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
6386 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6387 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
6388 ENC_QUOTED_PRINTABLE);
6389 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6391 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
6393 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
6395 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
6396 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
6398 gtkut_stock_button_set_create(&hbbox, &ok_btn, GTK_STOCK_OK,
6399 &cancel_btn, GTK_STOCK_CANCEL,
6401 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
6402 gtk_widget_grab_default(ok_btn);
6404 g_signal_connect(G_OBJECT(ok_btn), "clicked",
6405 G_CALLBACK(attach_property_ok),
6407 g_signal_connect(G_OBJECT(cancel_btn), "clicked",
6408 G_CALLBACK(attach_property_cancel),
6411 gtk_widget_show_all(vbox);
6413 attach_prop.window = window;
6414 attach_prop.mimetype_entry = mimetype_entry;
6415 attach_prop.encoding_optmenu = optmenu;
6416 attach_prop.path_entry = path_entry;
6417 attach_prop.filename_entry = filename_entry;
6418 attach_prop.ok_btn = ok_btn;
6419 attach_prop.cancel_btn = cancel_btn;
6422 #undef SET_LABEL_AND_ENTRY
6424 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
6430 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
6436 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
6437 gboolean *cancelled)
6445 static gboolean attach_property_key_pressed(GtkWidget *widget,
6447 gboolean *cancelled)
6449 if (event && event->keyval == GDK_Escape) {
6456 static void compose_exec_ext_editor(Compose *compose)
6463 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
6464 G_DIR_SEPARATOR, compose);
6466 if (pipe(pipe_fds) < 0) {
6472 if ((pid = fork()) < 0) {
6479 /* close the write side of the pipe */
6482 compose->exteditor_file = g_strdup(tmp);
6483 compose->exteditor_pid = pid;
6485 compose_set_ext_editor_sensitive(compose, FALSE);
6487 compose->exteditor_ch = g_io_channel_unix_new(pipe_fds[0]);
6488 compose->exteditor_tag = g_io_add_watch(compose->exteditor_ch,
6492 } else { /* process-monitoring process */
6498 /* close the read side of the pipe */
6501 if (compose_write_body_to_file(compose, tmp) < 0) {
6502 fd_write_all(pipe_fds[1], "2\n", 2);
6506 pid_ed = compose_exec_ext_editor_real(tmp);
6508 fd_write_all(pipe_fds[1], "1\n", 2);
6512 /* wait until editor is terminated */
6513 waitpid(pid_ed, NULL, 0);
6515 fd_write_all(pipe_fds[1], "0\n", 2);
6522 #endif /* G_OS_UNIX */
6526 static gint compose_exec_ext_editor_real(const gchar *file)
6528 static gchar *def_cmd = "emacs %s";
6534 g_return_val_if_fail(file != NULL, -1);
6536 if ((pid = fork()) < 0) {
6541 if (pid != 0) return pid;
6543 /* grandchild process */
6545 if (setpgid(0, getppid()))
6548 if (prefs_common.ext_editor_cmd &&
6549 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6550 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6551 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6553 if (prefs_common.ext_editor_cmd)
6554 g_warning("External editor command line is invalid: '%s'\n",
6555 prefs_common.ext_editor_cmd);
6556 g_snprintf(buf, sizeof(buf), def_cmd, file);
6559 cmdline = strsplit_with_quote(buf, " ", 1024);
6560 execvp(cmdline[0], cmdline);
6563 g_strfreev(cmdline);
6568 static gboolean compose_ext_editor_kill(Compose *compose)
6570 pid_t pgid = compose->exteditor_pid * -1;
6573 ret = kill(pgid, 0);
6575 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6579 msg = g_strdup_printf
6580 (_("The external editor is still working.\n"
6581 "Force terminating the process?\n"
6582 "process group id: %d"), -pgid);
6583 val = alertpanel_full(_("Notice"), msg, GTK_STOCK_YES, GTK_STOCK_NO,
6584 NULL, FALSE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
6588 if (val == G_ALERTDEFAULT) {
6589 g_source_remove(compose->exteditor_tag);
6590 g_io_channel_shutdown(compose->exteditor_ch,
6592 g_io_channel_unref(compose->exteditor_ch);
6594 if (kill(pgid, SIGTERM) < 0) perror("kill");
6595 waitpid(compose->exteditor_pid, NULL, 0);
6597 g_warning("Terminated process group id: %d", -pgid);
6598 g_warning("Temporary file: %s",
6599 compose->exteditor_file);
6601 compose_set_ext_editor_sensitive(compose, TRUE);
6603 g_free(compose->exteditor_file);
6604 compose->exteditor_file = NULL;
6605 compose->exteditor_pid = -1;
6606 compose->exteditor_ch = NULL;
6607 compose->exteditor_tag = -1;
6615 static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
6619 Compose *compose = (Compose *)data;
6622 debug_print(_("Compose: input from monitoring process\n"));
6624 g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
6626 g_io_channel_shutdown(source, FALSE, NULL);
6627 g_io_channel_unref(source);
6629 waitpid(compose->exteditor_pid, NULL, 0);
6631 if (buf[0] == '0') { /* success */
6632 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
6633 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
6635 gtk_text_buffer_set_text(buffer, "", -1);
6636 compose_insert_file(compose, compose->exteditor_file);
6637 compose_changed_cb(NULL, compose);
6639 if (g_unlink(compose->exteditor_file) < 0)
6640 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6641 } else if (buf[0] == '1') { /* failed */
6642 g_warning("Couldn't exec external editor\n");
6643 if (g_unlink(compose->exteditor_file) < 0)
6644 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6645 } else if (buf[0] == '2') {
6646 g_warning("Couldn't write to file\n");
6647 } else if (buf[0] == '3') {
6648 g_warning("Pipe read failed\n");
6651 compose_set_ext_editor_sensitive(compose, TRUE);
6653 g_free(compose->exteditor_file);
6654 compose->exteditor_file = NULL;
6655 compose->exteditor_pid = -1;
6656 compose->exteditor_ch = NULL;
6657 compose->exteditor_tag = -1;
6662 static void compose_set_ext_editor_sensitive(Compose *compose,
6665 GtkItemFactory *ifactory;
6667 ifactory = gtk_item_factory_from_widget(compose->menubar);
6669 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6670 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6671 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
6672 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
6673 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6674 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6675 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6678 gtk_widget_set_sensitive(compose->text, sensitive);
6679 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6680 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6681 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6682 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6683 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6684 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6685 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
6686 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
6688 #endif /* G_OS_UNIX */
6691 * compose_undo_state_changed:
6693 * Change the sensivity of the menuentries undo and redo
6695 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6696 gint redo_state, gpointer data)
6698 GtkWidget *widget = GTK_WIDGET(data);
6699 GtkItemFactory *ifactory;
6701 g_return_if_fail(widget != NULL);
6703 ifactory = gtk_item_factory_from_widget(widget);
6705 switch (undo_state) {
6706 case UNDO_STATE_TRUE:
6707 if (!undostruct->undo_state) {
6708 undostruct->undo_state = TRUE;
6709 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6712 case UNDO_STATE_FALSE:
6713 if (undostruct->undo_state) {
6714 undostruct->undo_state = FALSE;
6715 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6718 case UNDO_STATE_UNCHANGED:
6720 case UNDO_STATE_REFRESH:
6721 menu_set_sensitive(ifactory, "/Edit/Undo",
6722 undostruct->undo_state);
6725 g_warning("Undo state not recognized");
6729 switch (redo_state) {
6730 case UNDO_STATE_TRUE:
6731 if (!undostruct->redo_state) {
6732 undostruct->redo_state = TRUE;
6733 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6736 case UNDO_STATE_FALSE:
6737 if (undostruct->redo_state) {
6738 undostruct->redo_state = FALSE;
6739 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6742 case UNDO_STATE_UNCHANGED:
6744 case UNDO_STATE_REFRESH:
6745 menu_set_sensitive(ifactory, "/Edit/Redo",
6746 undostruct->redo_state);
6749 g_warning("Redo state not recognized");
6754 /* callback functions */
6756 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6757 * includes "non-client" (windows-izm) in calculation, so this calculation
6758 * may not be accurate.
6760 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6761 GtkAllocation *allocation,
6762 GtkSHRuler *shruler)
6764 if (prefs_common.show_ruler) {
6765 gint char_width = 0, char_height = 0;
6766 gint line_width_in_chars;
6768 gtkut_get_font_size(GTK_WIDGET(widget),
6769 &char_width, &char_height);
6770 line_width_in_chars =
6771 (allocation->width - allocation->x) / char_width;
6773 /* got the maximum */
6774 gtk_ruler_set_range(GTK_RULER(shruler),
6775 0.0, line_width_in_chars, 0,
6776 /*line_width_in_chars*/ char_width);
6782 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6784 Compose *compose = (Compose *)data;
6787 gchar *folderidentifier;
6789 ac = account_find_from_id(
6790 GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID)));
6791 g_return_if_fail(ac != NULL);
6793 if (ac != compose->account)
6794 compose_select_account(compose, ac, FALSE);
6796 /* Set message save folder */
6797 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6798 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
6800 g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
6801 G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
6803 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6804 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6805 folderidentifier = folder_item_get_identifier(account_get_special_folder
6806 (compose->account, F_OUTBOX));
6807 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
6808 g_free(folderidentifier);
6812 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
6813 GtkTreeViewColumn *column, Compose *compose)
6815 compose_attach_property(compose);
6818 static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6821 Compose *compose = (Compose *)data;
6822 GtkTreeSelection *attach_selection;
6823 gint attach_nr_selected;
6824 GtkItemFactory *ifactory;
6826 if (!event) return FALSE;
6828 if (event->button == 3) {
6829 attach_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
6830 attach_nr_selected = gtk_tree_selection_count_selected_rows(attach_selection);
6831 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6833 if (attach_nr_selected > 0)
6835 menu_set_sensitive(ifactory, "/Remove", TRUE);
6836 menu_set_sensitive(ifactory, "/Properties...", TRUE);
6838 menu_set_sensitive(ifactory, "/Remove", FALSE);
6839 menu_set_sensitive(ifactory, "/Properties...", FALSE);
6842 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6843 NULL, NULL, event->button, event->time);
6850 static gboolean attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6853 Compose *compose = (Compose *)data;
6855 if (!event) return FALSE;
6857 switch (event->keyval) {
6859 compose_attach_remove_selected(compose);
6865 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6867 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6868 toolbar_comp_set_sensitive(compose, allow);
6869 menu_set_sensitive(ifactory, "/Message", allow);
6870 menu_set_sensitive(ifactory, "/Edit", allow);
6872 menu_set_sensitive(ifactory, "/Spelling", allow);
6874 menu_set_sensitive(ifactory, "/Options", allow);
6875 menu_set_sensitive(ifactory, "/Tools", allow);
6876 menu_set_sensitive(ifactory, "/Help", allow);
6878 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow);
6882 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6884 Compose *compose = (Compose *)data;
6886 if (prefs_common.work_offline && !inc_offline_should_override())
6889 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
6890 gtk_timeout_remove(compose->draft_timeout_tag);
6891 compose->draft_timeout_tag = -1;
6894 compose_send(compose);
6897 static void compose_send_later_cb(gpointer data, guint action,
6900 Compose *compose = (Compose *)data;
6903 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6905 compose_close(compose);
6906 else if (val == -2) {
6907 alertpanel_error(_("Could not queue message:\n\n%s."), strerror(errno));
6911 void compose_draft (gpointer data)
6913 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6916 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6918 Compose *compose = (Compose *)data;
6922 MsgFlags flag = {0, 0};
6923 static gboolean lock = FALSE;
6924 MsgInfo *newmsginfo;
6929 draft = account_get_special_folder(compose->account, F_DRAFT);
6930 g_return_if_fail(draft != NULL);
6932 if (!g_mutex_trylock(compose->mutex)) {
6933 /* we don't want to lock the mutex once it's available,
6934 * because as the only other part of compose.c locking
6935 * it is compose_close - which means once unlocked,
6936 * the compose struct will be freed */
6937 debug_print("couldn't lock mutex, probably sending\n");
6943 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
6944 G_DIR_SEPARATOR, compose);
6945 if ((fp = g_fopen(tmp, "wb")) == NULL) {
6946 FILE_OP_ERROR(tmp, "fopen");
6950 /* chmod for security */
6951 if (change_file_mode_rw(fp, tmp) < 0) {
6952 FILE_OP_ERROR(tmp, "chmod");
6953 g_warning("can't change file mode\n");
6956 /* Save draft infos */
6957 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
6958 fprintf(fp, "S:%s\n", compose->account->address);
6959 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
6960 gchar *savefolderid;
6962 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6963 fprintf(fp, "SCF:%s\n", savefolderid);
6964 g_free(savefolderid);
6966 if (compose->privacy_system) {
6967 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
6968 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
6969 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
6973 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
6981 folder_item_scan(draft);
6982 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
6985 if (action != COMPOSE_AUTO_SAVE)
6986 alertpanel_error(_("Could not save draft."));
6990 draft->mtime = 0; /* force updating */
6992 if (compose->mode == COMPOSE_REEDIT) {
6993 compose_remove_reedit_target(compose);
6996 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6998 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6999 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
7000 if (compose_use_attach(compose))
7001 procmsg_msginfo_set_flags(newmsginfo, 0,
7002 MSG_HAS_ATTACHMENT);
7004 procmsg_msginfo_free(newmsginfo);
7007 folder_item_scan(draft);
7009 if (action == COMPOSE_QUIT_EDITING) {
7011 g_mutex_unlock(compose->mutex); /* must be done before closing */
7012 compose_close(compose);
7018 path = folder_item_fetch_msg(draft, msgnum);
7019 g_return_if_fail(path != NULL);
7020 if (g_stat(path, &s) < 0) {
7021 FILE_OP_ERROR(path, "stat");
7027 procmsg_msginfo_free(compose->targetinfo);
7028 compose->targetinfo = procmsg_msginfo_new();
7029 compose->targetinfo->msgnum = msgnum;
7030 compose->targetinfo->size = s.st_size;
7031 compose->targetinfo->mtime = s.st_mtime;
7032 compose->targetinfo->folder = draft;
7033 compose->mode = COMPOSE_REEDIT;
7035 if (action == COMPOSE_AUTO_SAVE) {
7036 compose->autosaved_draft = compose->targetinfo;
7038 compose->modified = FALSE;
7039 compose_set_title(compose);
7043 g_mutex_unlock(compose->mutex);
7046 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
7048 Compose *compose = (Compose *)data;
7051 if (compose->redirect_filename != NULL)
7054 file_list = filesel_select_multiple_files_open(_("Select file"));
7059 for ( tmp = file_list; tmp; tmp = tmp->next) {
7060 gchar *file = (gchar *) tmp->data;
7061 gchar *utf8_filename = conv_filename_to_utf8(file);
7062 compose_attach_append(compose, file, utf8_filename, NULL);
7063 compose_changed_cb(NULL, compose);
7065 g_free(utf8_filename);
7067 g_list_free(file_list);
7071 static void compose_insert_file_cb(gpointer data, guint action,
7074 Compose *compose = (Compose *)data;
7077 file_list = filesel_select_multiple_files_open(_("Select file"));
7082 for ( tmp = file_list; tmp; tmp = tmp->next) {
7083 gchar *file = (gchar *) tmp->data;
7084 gchar *filedup = g_strdup(file);
7085 gchar *shortfile = g_path_get_basename(filedup);
7086 ComposeInsertResult res;
7088 res = compose_insert_file(compose, file);
7089 if (res == COMPOSE_INSERT_READ_ERROR) {
7090 alertpanel_error(_("File '%s' could not be read."), shortfile);
7091 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
7092 alertpanel_error(_("File '%s' contained invalid characters\n"
7093 "for the current encoding, insertion may be incorrect."), shortfile);
7099 g_list_free(file_list);
7103 static void compose_insert_sig_cb(gpointer data, guint action,
7106 Compose *compose = (Compose *)data;
7108 compose_insert_sig(compose, FALSE);
7111 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
7115 Compose *compose = (Compose *)data;
7117 gtkut_widget_get_uposition(widget, &x, &y);
7118 prefs_common.compose_x = x;
7119 prefs_common.compose_y = y;
7121 if (compose->sending)
7123 compose_close_cb(compose, 0, NULL);
7127 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
7129 Compose *compose = (Compose *)data;
7133 if (compose->exteditor_tag != -1) {
7134 if (!compose_ext_editor_kill(compose))
7139 if (compose->modified) {
7140 val = alertpanel(_("Discard message"),
7141 _("This message has been modified. Discard it?"),
7142 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
7145 case G_ALERTDEFAULT:
7146 if (prefs_common.autosave)
7147 compose_remove_draft(compose);
7149 case G_ALERTALTERNATE:
7150 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
7157 compose_close(compose);
7160 static void compose_set_encoding_cb(gpointer data, guint action,
7163 Compose *compose = (Compose *)data;
7165 if (GTK_CHECK_MENU_ITEM(widget)->active)
7166 compose->out_encoding = (CharSet)action;
7169 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
7171 Compose *compose = (Compose *)data;
7173 addressbook_open(compose);
7176 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
7178 Compose *compose = (Compose *)data;
7183 tmpl = g_object_get_data(G_OBJECT(widget), "template");
7184 g_return_if_fail(tmpl != NULL);
7186 msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
7188 val = alertpanel(_("Apply template"), msg,
7189 _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);
7192 if (val == G_ALERTDEFAULT)
7193 compose_template_apply(compose, tmpl, TRUE);
7194 else if (val == G_ALERTALTERNATE)
7195 compose_template_apply(compose, tmpl, FALSE);
7198 static void compose_ext_editor_cb(gpointer data, guint action,
7201 Compose *compose = (Compose *)data;
7203 compose_exec_ext_editor(compose);
7206 static void compose_undo_cb(Compose *compose)
7208 gboolean prev_autowrap = compose->autowrap;
7210 compose->autowrap = FALSE;
7211 undo_undo(compose->undostruct);
7212 compose->autowrap = prev_autowrap;
7215 static void compose_redo_cb(Compose *compose)
7217 gboolean prev_autowrap = compose->autowrap;
7219 compose->autowrap = FALSE;
7220 undo_redo(compose->undostruct);
7221 compose->autowrap = prev_autowrap;
7224 static void entry_cut_clipboard(GtkWidget *entry)
7226 if (GTK_IS_EDITABLE(entry))
7227 gtk_editable_cut_clipboard (GTK_EDITABLE(entry));
7228 else if (GTK_IS_TEXT_VIEW(entry))
7229 gtk_text_buffer_cut_clipboard(
7230 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7231 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
7235 static void entry_copy_clipboard(GtkWidget *entry)
7237 if (GTK_IS_EDITABLE(entry))
7238 gtk_editable_copy_clipboard (GTK_EDITABLE(entry));
7239 else if (GTK_IS_TEXT_VIEW(entry))
7240 gtk_text_buffer_copy_clipboard(
7241 gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)),
7242 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
7245 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
7246 gboolean wrap, GdkAtom clip)
7248 if (GTK_IS_TEXT_VIEW(entry)) {
7249 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7250 GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
7251 GtkTextIter start_iter, end_iter;
7254 gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
7256 if (contents == NULL)
7259 gtk_text_buffer_delete_selection(buffer, FALSE, TRUE);
7260 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7262 start = gtk_text_iter_get_offset(&start_iter);
7264 gtk_text_buffer_insert(buffer, &start_iter, contents, strlen(contents));
7267 end = start + strlen(contents);
7268 gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
7269 gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
7270 gtk_text_buffer_apply_tag_by_name(buffer, "no_wrap", &start_iter, &end_iter);
7271 } else if (wrap && clip == GDK_SELECTION_PRIMARY) {
7272 mark_start = gtk_text_buffer_get_insert(buffer);
7273 gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
7274 gtk_text_iter_backward_char(&start_iter);
7275 compose_beautify_paragraph(compose, &start_iter, TRUE);
7278 } else if (GTK_IS_EDITABLE(entry))
7279 gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
7283 static void entry_allsel(GtkWidget *entry)
7285 if (GTK_IS_EDITABLE(entry))
7286 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
7287 else if (GTK_IS_TEXT_VIEW(entry)) {
7288 GtkTextIter startiter, enditer;
7289 GtkTextBuffer *textbuf;
7291 textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
7292 gtk_text_buffer_get_start_iter(textbuf, &startiter);
7293 gtk_text_buffer_get_end_iter(textbuf, &enditer);
7295 gtk_text_buffer_move_mark_by_name(textbuf,
7296 "selection_bound", &startiter);
7297 gtk_text_buffer_move_mark_by_name(textbuf,
7298 "insert", &enditer);
7302 static void compose_cut_cb(Compose *compose)
7304 if (compose->focused_editable &&
7305 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7306 entry_cut_clipboard(compose->focused_editable);
7309 static void compose_copy_cb(Compose *compose)
7311 if (compose->focused_editable &&
7312 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7313 entry_copy_clipboard(compose->focused_editable);
7316 static void compose_paste_cb(Compose *compose)
7319 GtkTextBuffer *buffer;
7321 if (compose->focused_editable &&
7322 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7323 entry_paste_clipboard(compose, compose->focused_editable,
7324 prefs_common.linewrap_pastes,
7325 GDK_SELECTION_CLIPBOARD);
7329 static void compose_paste_as_quote_cb(Compose *compose)
7331 gint wrap_quote = prefs_common.linewrap_quote;
7332 if (compose->focused_editable &&
7333 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
7334 /* let text_insert() (called directly or at a later time
7335 * after the gtk_editable_paste_clipboard) know that
7336 * text is to be inserted as a quotation. implemented
7337 * by using a simple refcount... */
7338 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data(
7339 G_OBJECT(compose->focused_editable),
7340 "paste_as_quotation"));
7341 g_object_set_data(G_OBJECT(compose->focused_editable),
7342 "paste_as_quotation",
7343 GINT_TO_POINTER(paste_as_quotation + 1));
7344 prefs_common.linewrap_quote = prefs_common.linewrap_pastes;
7345 entry_paste_clipboard(compose, compose->focused_editable,
7346 prefs_common.linewrap_pastes,
7347 GDK_SELECTION_CLIPBOARD);
7348 prefs_common.linewrap_quote = wrap_quote;
7352 static void compose_paste_no_wrap_cb(Compose *compose)
7355 GtkTextBuffer *buffer;
7357 if (compose->focused_editable &&
7358 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7359 entry_paste_clipboard(compose, compose->focused_editable, FALSE,
7360 GDK_SELECTION_CLIPBOARD);
7364 static void compose_paste_wrap_cb(Compose *compose)
7367 GtkTextBuffer *buffer;
7369 if (compose->focused_editable &&
7370 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7371 entry_paste_clipboard(compose, compose->focused_editable, TRUE,
7372 GDK_SELECTION_CLIPBOARD);
7376 static void compose_allsel_cb(Compose *compose)
7378 if (compose->focused_editable &&
7379 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
7380 entry_allsel(compose->focused_editable);
7383 static void textview_move_beginning_of_line (GtkTextView *text)
7385 GtkTextBuffer *buffer;
7389 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7391 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7392 mark = gtk_text_buffer_get_insert(buffer);
7393 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7394 gtk_text_iter_set_line_offset(&ins, 0);
7395 gtk_text_buffer_place_cursor(buffer, &ins);
7398 static void textview_move_forward_character (GtkTextView *text)
7400 GtkTextBuffer *buffer;
7404 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7406 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7407 mark = gtk_text_buffer_get_insert(buffer);
7408 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7409 if (gtk_text_iter_forward_cursor_position(&ins))
7410 gtk_text_buffer_place_cursor(buffer, &ins);
7413 static void textview_move_backward_character (GtkTextView *text)
7415 GtkTextBuffer *buffer;
7419 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7421 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7422 mark = gtk_text_buffer_get_insert(buffer);
7423 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7424 if (gtk_text_iter_backward_cursor_position(&ins))
7425 gtk_text_buffer_place_cursor(buffer, &ins);
7428 static void textview_move_forward_word (GtkTextView *text)
7430 GtkTextBuffer *buffer;
7435 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7437 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7438 mark = gtk_text_buffer_get_insert(buffer);
7439 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7440 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7441 if (gtk_text_iter_forward_word_ends(&ins, count)) {
7442 gtk_text_iter_backward_word_start(&ins);
7443 gtk_text_buffer_place_cursor(buffer, &ins);
7447 static void textview_move_backward_word (GtkTextView *text)
7449 GtkTextBuffer *buffer;
7454 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7456 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7457 mark = gtk_text_buffer_get_insert(buffer);
7458 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7459 count = gtk_text_iter_inside_word (&ins) ? 2 : 1;
7460 if (gtk_text_iter_backward_word_starts(&ins, 1))
7461 gtk_text_buffer_place_cursor(buffer, &ins);
7464 static void textview_move_end_of_line (GtkTextView *text)
7466 GtkTextBuffer *buffer;
7470 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7472 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7473 mark = gtk_text_buffer_get_insert(buffer);
7474 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7475 if (gtk_text_iter_forward_to_line_end(&ins))
7476 gtk_text_buffer_place_cursor(buffer, &ins);
7479 static void textview_move_next_line (GtkTextView *text)
7481 GtkTextBuffer *buffer;
7486 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7488 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7489 mark = gtk_text_buffer_get_insert(buffer);
7490 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7491 offset = gtk_text_iter_get_line_offset(&ins);
7492 if (gtk_text_iter_forward_line(&ins)) {
7493 gtk_text_iter_set_line_offset(&ins, offset);
7494 gtk_text_buffer_place_cursor(buffer, &ins);
7498 static void textview_move_previous_line (GtkTextView *text)
7500 GtkTextBuffer *buffer;
7505 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7507 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7508 mark = gtk_text_buffer_get_insert(buffer);
7509 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7510 offset = gtk_text_iter_get_line_offset(&ins);
7511 if (gtk_text_iter_backward_line(&ins)) {
7512 gtk_text_iter_set_line_offset(&ins, offset);
7513 gtk_text_buffer_place_cursor(buffer, &ins);
7517 static void textview_delete_forward_character (GtkTextView *text)
7519 GtkTextBuffer *buffer;
7521 GtkTextIter ins, end_iter;
7523 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7525 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7526 mark = gtk_text_buffer_get_insert(buffer);
7527 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7529 if (gtk_text_iter_forward_char(&end_iter)) {
7530 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7534 static void textview_delete_backward_character (GtkTextView *text)
7536 GtkTextBuffer *buffer;
7538 GtkTextIter ins, end_iter;
7540 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7542 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7543 mark = gtk_text_buffer_get_insert(buffer);
7544 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7546 if (gtk_text_iter_backward_char(&end_iter)) {
7547 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7551 static void textview_delete_forward_word (GtkTextView *text)
7553 GtkTextBuffer *buffer;
7555 GtkTextIter ins, end_iter;
7557 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7559 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7560 mark = gtk_text_buffer_get_insert(buffer);
7561 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7563 if (gtk_text_iter_forward_word_end(&end_iter)) {
7564 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7568 static void textview_delete_backward_word (GtkTextView *text)
7570 GtkTextBuffer *buffer;
7572 GtkTextIter ins, end_iter;
7574 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7576 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7577 mark = gtk_text_buffer_get_insert(buffer);
7578 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7580 if (gtk_text_iter_backward_word_start(&end_iter)) {
7581 gtk_text_buffer_delete(buffer, &end_iter, &ins);
7585 static void textview_delete_line (GtkTextView *text)
7587 GtkTextBuffer *buffer;
7589 GtkTextIter ins, start_iter, end_iter;
7592 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7594 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7595 mark = gtk_text_buffer_get_insert(buffer);
7596 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7599 gtk_text_iter_set_line_offset(&start_iter, 0);
7602 if (gtk_text_iter_ends_line(&end_iter))
7603 found = gtk_text_iter_forward_char(&end_iter);
7605 found = gtk_text_iter_forward_to_line_end(&end_iter);
7608 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
7611 static void textview_delete_to_line_end (GtkTextView *text)
7613 GtkTextBuffer *buffer;
7615 GtkTextIter ins, end_iter;
7618 g_return_if_fail(GTK_IS_TEXT_VIEW(text));
7620 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
7621 mark = gtk_text_buffer_get_insert(buffer);
7622 gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
7624 if (gtk_text_iter_ends_line(&end_iter))
7625 found = gtk_text_iter_forward_char(&end_iter);
7627 found = gtk_text_iter_forward_to_line_end(&end_iter);
7629 gtk_text_buffer_delete(buffer, &ins, &end_iter);
7632 static void compose_advanced_action_cb(Compose *compose,
7633 ComposeCallAdvancedAction action)
7635 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
7637 void (*do_action) (GtkTextView *text);
7638 } action_table[] = {
7639 {textview_move_beginning_of_line},
7640 {textview_move_forward_character},
7641 {textview_move_backward_character},
7642 {textview_move_forward_word},
7643 {textview_move_backward_word},
7644 {textview_move_end_of_line},
7645 {textview_move_next_line},
7646 {textview_move_previous_line},
7647 {textview_delete_forward_character},
7648 {textview_delete_backward_character},
7649 {textview_delete_forward_word},
7650 {textview_delete_backward_word},
7651 {textview_delete_line},
7652 {NULL}, /* gtk_stext_delete_line_n */
7653 {textview_delete_to_line_end}
7656 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
7658 if (action >= COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE &&
7659 action <= COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END) {
7660 if (action_table[action].do_action)
7661 action_table[action].do_action(text);
7663 g_warning("Not implemented yet.");
7667 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
7671 if (GTK_IS_EDITABLE(widget)) {
7672 str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
7673 gtk_editable_set_position(GTK_EDITABLE(widget),
7676 if (widget->parent && widget->parent->parent
7677 && widget->parent->parent->parent) {
7678 if (GTK_IS_SCROLLED_WINDOW(widget->parent->parent->parent)) {
7679 gint y = widget->allocation.y;
7680 gint height = widget->allocation.height;
7681 GtkAdjustment *shown = gtk_scrolled_window_get_vadjustment
7682 (GTK_SCROLLED_WINDOW(widget->parent->parent->parent));
7684 if (y < (int)shown->value) {
7685 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown), y - 1);
7687 if (y + height > (int)shown->value + (int)shown->page_size) {
7688 if (y - height - 1 < (int)shown->upper - (int)shown->page_size) {
7689 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7690 y + height - (int)shown->page_size - 1);
7692 gtk_adjustment_set_value(GTK_ADJUSTMENT(shown),
7693 (int)shown->upper - (int)shown->page_size - 1);
7700 if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget))
7701 compose->focused_editable = widget;
7704 static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
7706 compose->modified = TRUE;
7707 compose_set_title(compose);
7710 static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
7712 Compose *compose = (Compose *)data;
7715 compose_wrap_all_full(compose, TRUE);
7717 compose_beautify_paragraph(compose, NULL, TRUE);
7720 static void compose_toggle_autowrap_cb(gpointer data, guint action,
7723 Compose *compose = (Compose *)data;
7724 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
7725 if (compose->autowrap)
7726 compose_wrap_all_full(compose, TRUE);
7729 static void compose_toggle_sign_cb(gpointer data, guint action,
7732 Compose *compose = (Compose *)data;
7734 if (GTK_CHECK_MENU_ITEM(widget)->active)
7735 compose->use_signing = TRUE;
7737 compose->use_signing = FALSE;
7740 static void compose_toggle_encrypt_cb(gpointer data, guint action,
7743 Compose *compose = (Compose *)data;
7745 if (GTK_CHECK_MENU_ITEM(widget)->active)
7746 compose->use_encryption = TRUE;
7748 compose->use_encryption = FALSE;
7751 static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
7753 g_free(compose->privacy_system);
7755 compose->privacy_system = g_strdup(account->default_privacy_system);
7756 compose_update_privacy_system_menu_item(compose, warn);
7759 static void compose_toggle_ruler_cb(gpointer data, guint action,
7762 Compose *compose = (Compose *)data;
7764 if (GTK_CHECK_MENU_ITEM(widget)->active) {
7765 gtk_widget_show(compose->ruler_hbox);
7766 prefs_common.show_ruler = TRUE;
7768 gtk_widget_hide(compose->ruler_hbox);
7769 gtk_widget_queue_resize(compose->edit_vbox);
7770 prefs_common.show_ruler = FALSE;
7774 static void compose_attach_drag_received_cb (GtkWidget *widget,
7775 GdkDragContext *drag_context,
7778 GtkSelectionData *data,
7783 Compose *compose = (Compose *)user_data;
7786 if (gdk_atom_name(data->type) &&
7787 !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7788 list = uri_list_extract_filenames((const gchar *)data->data);
7789 for (tmp = list; tmp != NULL; tmp = tmp->next)
7790 compose_attach_append
7791 (compose, (const gchar *)tmp->data,
7792 (const gchar *)tmp->data, NULL);
7793 if (list) compose_changed_cb(NULL, compose);
7794 list_free_strings(list);
7796 } else if (gdk_atom_name(data->type) &&
7797 !strcmp(gdk_atom_name(data->type), "text/plain") &&
7798 data->data && !strcmp(data->data, "Dummy-Summaryview")) {
7799 /* comes from our summaryview */
7800 SummaryView * summaryview = NULL;
7801 GSList * list = NULL, *cur = NULL;
7803 if (mainwindow_get_mainwindow())
7804 summaryview = mainwindow_get_mainwindow()->summaryview;
7807 list = summary_get_selected_msg_list(summaryview);
7809 for (cur = list; cur; cur = cur->next) {
7810 MsgInfo *msginfo = (MsgInfo *)cur->data;
7813 file = procmsg_get_message_file_full(msginfo,
7816 compose_attach_append(compose, (const gchar *)file,
7817 (const gchar *)file, "message/rfc822");
7825 static gboolean compose_drag_drop(GtkWidget *widget,
7826 GdkDragContext *drag_context,
7828 guint time, gpointer user_data)
7830 /* not handling this signal makes compose_insert_drag_received_cb
7835 static void compose_insert_drag_received_cb (GtkWidget *widget,
7836 GdkDragContext *drag_context,
7839 GtkSelectionData *data,
7844 Compose *compose = (Compose *)user_data;
7847 /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
7849 if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
7850 list = uri_list_extract_filenames((const gchar *)data->data);
7851 for (tmp = list; tmp != NULL; tmp = tmp->next) {
7852 compose_insert_file(compose, (const gchar *)tmp->data);
7854 list_free_strings(list);
7856 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7859 gchar *tmpfile = get_tmp_file();
7860 str_write_to_file((const gchar *)data->data, tmpfile);
7861 compose_insert_file(compose, tmpfile);
7864 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7867 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7870 static void compose_header_drag_received_cb (GtkWidget *widget,
7871 GdkDragContext *drag_context,
7874 GtkSelectionData *data,
7879 GtkEditable *entry = (GtkEditable *)user_data;
7880 gchar *email = (gchar *)data->data;
7882 /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
7885 if (!strncmp(email, "mailto:", strlen("mailto:"))) {
7886 gchar *decoded=g_new(gchar, strlen(email));
7889 email += strlen("mailto:");
7890 decode_uri(decoded, email); /* will fit */
7891 gtk_editable_delete_text(entry, 0, -1);
7892 gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
7893 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7897 gtk_drag_finish(drag_context, TRUE, FALSE, time);
7900 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
7903 Compose *compose = (Compose *)data;
7905 if (GTK_CHECK_MENU_ITEM(widget)->active)
7906 compose->return_receipt = TRUE;
7908 compose->return_receipt = FALSE;
7911 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
7914 Compose *compose = (Compose *)data;
7916 if (GTK_CHECK_MENU_ITEM(widget)->active)
7917 compose->remove_references = TRUE;
7919 compose->remove_references = FALSE;
7922 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
7924 ComposeHeaderEntry *headerentry)
7926 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
7927 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
7928 !(event->state & GDK_MODIFIER_MASK) &&
7929 (event->keyval == GDK_BackSpace) &&
7930 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
7931 gtk_container_remove
7932 (GTK_CONTAINER(headerentry->compose->header_table),
7933 headerentry->combo);
7934 gtk_container_remove
7935 (GTK_CONTAINER(headerentry->compose->header_table),
7936 headerentry->entry);
7937 headerentry->compose->header_list =
7938 g_slist_remove(headerentry->compose->header_list,
7940 g_free(headerentry);
7941 } else if (event->keyval == GDK_Tab) {
7942 if (headerentry->compose->header_last == headerentry) {
7943 /* Override default next focus, and give it to subject_entry
7944 * instead of notebook tabs
7946 g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event");
7947 gtk_widget_grab_focus(headerentry->compose->subject_entry);
7954 gboolean compose_headerentry_changed_cb(GtkWidget *entry,
7955 ComposeHeaderEntry *headerentry)
7957 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
7958 headerentry->compose->header_list =
7959 g_slist_append(headerentry->compose->header_list,
7962 compose_create_header_entry(headerentry->compose);
7963 g_signal_handlers_disconnect_matched
7964 (G_OBJECT(entry), G_SIGNAL_MATCH_DATA,
7965 0, 0, NULL, NULL, headerentry);
7967 /* Automatically scroll down */
7968 compose_show_first_last_header(headerentry->compose, FALSE);
7974 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
7976 GtkAdjustment *vadj;
7978 g_return_if_fail(compose);
7979 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
7980 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
7982 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
7983 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
7986 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
7987 const gchar *text, gint len, Compose *compose)
7989 gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
7990 (G_OBJECT(compose->text), "paste_as_quotation"));
7993 g_return_if_fail(text != NULL);
7995 g_signal_handlers_block_by_func(G_OBJECT(buffer),
7996 G_CALLBACK(text_inserted),
7998 if (paste_as_quotation) {
8005 new_text = g_strndup(text, len);
8006 if (prefs_common.quotemark && *prefs_common.quotemark)
8007 qmark = prefs_common.quotemark;
8011 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8012 gtk_text_buffer_place_cursor(buffer, iter);
8014 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
8016 g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
8017 GINT_TO_POINTER(paste_as_quotation - 1));
8019 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8021 gtk_text_buffer_insert(buffer, iter, text, len);
8023 mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
8025 compose_beautify_paragraph(compose, iter, FALSE);
8027 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
8028 gtk_text_buffer_delete_mark(buffer, mark);
8030 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
8031 G_CALLBACK(text_inserted),
8033 g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
8035 if (prefs_common.autosave &&
8036 gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
8037 compose->draft_timeout_tag = gtk_timeout_add
8038 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
8040 static gint compose_defer_auto_save_draft(Compose *compose)
8042 compose->draft_timeout_tag = -1;
8043 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
8048 static void compose_check_all(Compose *compose)
8050 if (compose->gtkaspell)
8051 gtkaspell_check_all(compose->gtkaspell);
8054 static void compose_highlight_all(Compose *compose)
8056 if (compose->gtkaspell)
8057 gtkaspell_highlight_all(compose->gtkaspell);
8060 static void compose_check_backwards(Compose *compose)
8062 if (compose->gtkaspell)
8063 gtkaspell_check_backwards(compose->gtkaspell);
8065 GtkItemFactory *ifactory;
8066 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8067 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8068 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8072 static void compose_check_forwards_go(Compose *compose)
8074 if (compose->gtkaspell)
8075 gtkaspell_check_forwards_go(compose->gtkaspell);
8077 GtkItemFactory *ifactory;
8078 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
8079 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
8080 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
8086 *\brief Guess originating forward account from MsgInfo and several
8087 * "common preference" settings. Return NULL if no guess.
8089 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
8091 PrefsAccount *account = NULL;
8093 g_return_val_if_fail(msginfo, NULL);
8094 g_return_val_if_fail(msginfo->folder, NULL);
8095 g_return_val_if_fail(msginfo->folder->prefs, NULL);
8097 if (msginfo->folder->prefs->enable_default_account)
8098 account = account_find_from_id(msginfo->folder->prefs->default_account);
8101 account = msginfo->folder->folder->account;
8103 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
8105 Xstrdup_a(to, msginfo->to, return NULL);
8106 extract_address(to);
8107 account = account_find_from_address(to);
8110 if (!account && prefs_common.forward_account_autosel) {
8112 if (!procheader_get_header_from_msginfo
8113 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
8114 extract_address(cc);
8115 account = account_find_from_address(cc);
8122 static gboolean compose_close(Compose *compose)
8126 if (!g_mutex_trylock(compose->mutex)) {
8127 /* we have to wait for the (possibly deferred by auto-save)
8128 * drafting to be done, before destroying the compose under
8130 debug_print("waiting for drafting to finish...\n");
8131 g_timeout_add (500, (GSourceFunc) compose_close, compose);
8134 g_return_val_if_fail(compose, FALSE);
8135 gtkut_widget_get_uposition(compose->window, &x, &y);
8136 prefs_common.compose_x = x;
8137 prefs_common.compose_y = y;
8138 g_mutex_unlock(compose->mutex);
8139 compose_destroy(compose);
8144 * Add entry field for each address in list.
8145 * \param compose E-Mail composition object.
8146 * \param listAddress List of (formatted) E-Mail addresses.
8148 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
8153 addr = ( gchar * ) node->data;
8154 compose_entry_append( compose, addr, COMPOSE_TO );
8155 node = g_list_next( node );
8159 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
8163 GSList *new_msglist = NULL;
8164 MsgInfo *tmp_msginfo = NULL;
8165 gboolean originally_enc = FALSE;
8166 Compose *compose = NULL;
8168 g_return_if_fail(msgview != NULL);
8170 g_return_if_fail(msginfo_list != NULL);
8172 if (g_slist_length(msginfo_list) == 1) {
8173 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
8174 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
8176 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
8177 !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
8178 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
8179 orig_msginfo, mimeinfo);
8180 if (tmp_msginfo != NULL) {
8181 new_msglist = g_slist_append(NULL, tmp_msginfo);
8182 if (procmime_msginfo_is_encrypted(orig_msginfo)) {
8183 originally_enc = TRUE;
8189 body = messageview_get_selection(msgview);
8192 compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
8193 procmsg_msginfo_free(tmp_msginfo);
8194 g_slist_free(new_msglist);
8196 compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
8198 if (originally_enc) {
8199 compose_force_encryption(compose, compose->account, FALSE);