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},
635 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
636 {N_("/_Spelling/_Spelling Configuration"),
637 NULL, NULL, 0, "<Branch>"},
639 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
640 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
641 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
642 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
643 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
644 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
645 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
646 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
647 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
648 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
649 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
650 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
651 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
652 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
653 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
654 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
655 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
657 #define ENC_ACTION(action) \
658 NULL, compose_set_encoding_cb, action, \
659 "/Options/Character encoding/Automatic"
661 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
662 {N_("/_Options/Character _encoding/_Automatic"),
663 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
664 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
666 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
667 ENC_ACTION(C_US_ASCII)},
668 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
669 ENC_ACTION(C_UTF_8)},
670 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
672 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
673 ENC_ACTION(C_ISO_8859_1)},
674 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
675 ENC_ACTION(C_ISO_8859_15)},
676 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
678 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
679 ENC_ACTION(C_ISO_8859_2)},
680 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
682 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
683 ENC_ACTION(C_ISO_8859_13)},
684 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
685 ENC_ACTION(C_ISO_8859_4)},
686 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
688 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
689 ENC_ACTION(C_ISO_8859_7)},
690 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
692 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
693 ENC_ACTION(C_ISO_8859_8)},
694 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
695 ENC_ACTION(C_WINDOWS_1255)},
696 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
698 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
699 ENC_ACTION(C_ISO_8859_9)},
700 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
702 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
703 ENC_ACTION(C_ISO_8859_5)},
704 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
705 ENC_ACTION(C_KOI8_R)},
706 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
707 ENC_ACTION(C_KOI8_U)},
708 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
709 ENC_ACTION(C_WINDOWS_1251)},
710 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
712 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
713 ENC_ACTION(C_ISO_2022_JP)},
714 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
716 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
717 ENC_ACTION(C_GB2312)},
718 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
720 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
722 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
723 ENC_ACTION(C_EUC_TW)},
724 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
726 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
727 ENC_ACTION(C_EUC_KR)},
728 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
730 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
731 ENC_ACTION(C_TIS_620)},
732 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
733 ENC_ACTION(C_WINDOWS_874)},
735 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
736 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
737 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
738 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
739 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
740 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
741 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
744 static GtkTargetEntry compose_mime_types[] =
746 {"text/uri-list", 0, 0},
747 {"text/plain", 0, 0},
751 static gboolean compose_put_existing_to_front(MsgInfo *info)
753 GList *compose_list = compose_get_compose_list();
757 for (elem = compose_list; elem != NULL && elem->data != NULL;
759 Compose *c = (Compose*)elem->data;
761 if (!c->targetinfo || !c->targetinfo->msgid ||
765 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
766 gtkut_window_popup(c->window);
774 static GdkColor quote_color =
775 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
777 static GdkColor signature_color = {
784 static GdkColor uri_color = {
791 static void compose_create_tags(GtkTextView *text, Compose *compose)
793 GtkTextBuffer *buffer;
794 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
796 buffer = gtk_text_view_get_buffer(text);
798 if (prefs_common.enable_color) {
799 /* grab the quote colors, converting from an int to a GdkColor */
800 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
802 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
804 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
807 signature_color = quote_color = uri_color = black;
810 gtk_text_buffer_create_tag(buffer, "quote",
811 "foreground-gdk", "e_color,
813 gtk_text_buffer_create_tag(buffer, "signature",
814 "foreground-gdk", &signature_color,
816 gtk_text_buffer_create_tag(buffer, "link",
817 "foreground-gdk", &uri_color,
819 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
822 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
823 GPtrArray *attach_files)
825 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
828 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
830 return compose_generic_new(account, NULL, item, NULL, NULL);
833 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
835 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
838 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
839 GPtrArray *attach_files, GList *listAddress )
842 GtkTextView *textview;
843 GtkTextBuffer *textbuf;
845 GtkItemFactory *ifactory;
847 if (item && item->prefs && item->prefs->enable_default_account)
848 account = account_find_from_id(item->prefs->default_account);
850 if (!account) account = cur_account;
851 g_return_val_if_fail(account != NULL, NULL);
853 compose = compose_create(account, COMPOSE_NEW);
854 ifactory = gtk_item_factory_from_widget(compose->menubar);
856 compose->replyinfo = NULL;
857 compose->fwdinfo = NULL;
859 textview = GTK_TEXT_VIEW(compose->text);
860 textbuf = gtk_text_view_get_buffer(textview);
861 compose_create_tags(textview, compose);
863 undo_block(compose->undostruct);
865 if (item && item->prefs && item->prefs->enable_default_dictionary &&
867 gtkaspell_change_dict(compose->gtkaspell,
868 item->prefs->default_dictionary);
871 if (account->auto_sig)
872 compose_insert_sig(compose, FALSE);
873 gtk_text_buffer_get_start_iter(textbuf, &iter);
874 gtk_text_buffer_place_cursor(textbuf, &iter);
876 if (account->protocol != A_NNTP) {
877 if (mailto && *mailto != '\0') {
878 compose_entries_set(compose, mailto);
880 } else if (item && item->prefs->enable_default_to) {
881 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
882 compose_entry_mark_default_to(compose, item->prefs->default_to);
884 if (item && item->ret_rcpt) {
885 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
889 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
891 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
894 * CLAWS: just don't allow return receipt request, even if the user
895 * may want to send an email. simple but foolproof.
897 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
899 compose_add_field_list( compose, listAddress );
905 for (i = 0; i < attach_files->len; i++) {
906 file = g_ptr_array_index(attach_files, i);
907 compose_attach_append(compose, file, file, NULL);
911 compose_show_first_last_header(compose, TRUE);
913 /* Set save folder */
914 if (item && item->prefs && item->prefs->save_copy_to_folder) {
915 gchar *folderidentifier;
917 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
918 folderidentifier = folder_item_get_identifier(item);
919 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
920 g_free(folderidentifier);
923 gtk_widget_grab_focus(compose->header_last->entry);
925 undo_unblock(compose->undostruct);
927 if (prefs_common.auto_exteditor)
928 compose_exec_ext_editor(compose);
930 compose_set_title(compose);
934 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
935 gboolean override_pref)
937 gchar *privacy = NULL;
939 g_return_if_fail(compose != NULL);
940 g_return_if_fail(account != NULL);
942 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
945 if (account->default_privacy_system
946 && strlen(account->default_privacy_system)) {
947 privacy = account->default_privacy_system;
949 GSList *privacy_avail = privacy_get_system_ids();
950 if (privacy_avail && g_slist_length(privacy_avail)) {
951 privacy = (gchar *)(privacy_avail->data);
954 if (privacy != NULL) {
955 compose->privacy_system = g_strdup(privacy);
956 compose_update_privacy_system_menu_item(compose, FALSE);
957 compose_use_encryption(compose, TRUE);
961 static void compose_force_signing(Compose *compose, PrefsAccount *account)
963 gchar *privacy = NULL;
965 if (account->default_privacy_system
966 && strlen(account->default_privacy_system)) {
967 privacy = account->default_privacy_system;
969 GSList *privacy_avail = privacy_get_system_ids();
970 if (privacy_avail && g_slist_length(privacy_avail)) {
971 privacy = (gchar *)(privacy_avail->data);
974 if (privacy != NULL) {
975 compose->privacy_system = g_strdup(privacy);
976 compose_update_privacy_system_menu_item(compose, FALSE);
977 compose_use_signing(compose, TRUE);
981 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
985 Compose *compose = NULL;
986 g_return_val_if_fail(msginfo_list != NULL, NULL);
988 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
989 g_return_val_if_fail(msginfo != NULL, NULL);
991 list_len = g_slist_length(msginfo_list);
995 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
996 FALSE, prefs_common.default_reply_list, FALSE, body);
998 case COMPOSE_REPLY_WITH_QUOTE:
999 compose = compose_reply(msginfo, TRUE,
1000 FALSE, prefs_common.default_reply_list, FALSE, body);
1002 case COMPOSE_REPLY_WITHOUT_QUOTE:
1003 compose = compose_reply(msginfo, FALSE,
1004 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1006 case COMPOSE_REPLY_TO_SENDER:
1007 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1008 FALSE, FALSE, TRUE, body);
1010 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1011 compose = compose_followup_and_reply_to(msginfo,
1012 prefs_common.reply_with_quote,
1013 FALSE, FALSE, body);
1015 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1016 compose = compose_reply(msginfo, TRUE,
1017 FALSE, FALSE, TRUE, body);
1019 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1020 compose = compose_reply(msginfo, FALSE,
1021 FALSE, FALSE, TRUE, NULL);
1023 case COMPOSE_REPLY_TO_ALL:
1024 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1025 TRUE, FALSE, FALSE, body);
1027 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1028 compose = compose_reply(msginfo, TRUE,
1029 TRUE, FALSE, FALSE, body);
1031 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1032 compose = compose_reply(msginfo, FALSE,
1033 TRUE, FALSE, FALSE, NULL);
1035 case COMPOSE_REPLY_TO_LIST:
1036 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1037 FALSE, TRUE, FALSE, body);
1039 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1040 compose = compose_reply(msginfo, TRUE,
1041 FALSE, TRUE, FALSE, body);
1043 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1044 compose = compose_reply(msginfo, FALSE,
1045 FALSE, TRUE, FALSE, NULL);
1047 case COMPOSE_FORWARD:
1048 if (prefs_common.forward_as_attachment) {
1049 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1052 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1056 case COMPOSE_FORWARD_INLINE:
1057 /* check if we reply to more than one Message */
1058 if (list_len == 1) {
1059 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE);
1062 /* more messages FALL THROUGH */
1063 case COMPOSE_FORWARD_AS_ATTACH:
1064 compose = compose_forward_multiple(NULL, msginfo_list);
1066 case COMPOSE_REDIRECT:
1067 compose = compose_redirect(NULL, msginfo);
1070 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1075 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1076 gboolean to_ml, gboolean to_sender,
1079 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1080 to_sender, FALSE, body);
1083 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1088 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1089 to_sender, TRUE, body);
1092 static void compose_extract_original_charset(Compose *compose)
1094 MsgInfo *info = NULL;
1095 if (compose->replyinfo) {
1096 info = compose->replyinfo;
1097 } else if (compose->fwdinfo) {
1098 info = compose->fwdinfo;
1099 } else if (compose->targetinfo) {
1100 info = compose->targetinfo;
1103 MimeInfo *mimeinfo = procmime_scan_message(info);
1104 MimeInfo *partinfo = mimeinfo;
1105 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1106 partinfo = procmime_mimeinfo_next(partinfo);
1108 compose->orig_charset =
1109 g_strdup(procmime_mimeinfo_get_parameter(
1110 partinfo, "charset"));
1112 procmime_mimeinfo_free_all(mimeinfo);
1116 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1117 gboolean to_all, gboolean to_ml,
1119 gboolean followup_and_reply_to,
1122 GtkItemFactory *ifactory;
1124 PrefsAccount *account = NULL;
1125 PrefsAccount *reply_account;
1126 GtkTextView *textview;
1127 GtkTextBuffer *textbuf;
1131 g_return_val_if_fail(msginfo != NULL, NULL);
1132 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1134 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1136 g_return_val_if_fail(account != NULL, NULL);
1138 if (to_sender && account->protocol == A_NNTP &&
1139 !followup_and_reply_to) {
1141 account_find_from_address(account->address);
1143 reply_account = compose_current_mail_account();
1147 reply_account = account;
1149 compose = compose_create(account, COMPOSE_REPLY);
1150 ifactory = gtk_item_factory_from_widget(compose->menubar);
1152 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1153 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1155 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1157 if (!compose->replyinfo)
1158 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1160 compose_extract_original_charset(compose);
1162 if (msginfo->folder && msginfo->folder->ret_rcpt)
1163 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1165 /* Set save folder */
1166 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1167 gchar *folderidentifier;
1169 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1170 folderidentifier = folder_item_get_identifier(msginfo->folder);
1171 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1172 g_free(folderidentifier);
1175 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1176 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1177 to_sender, followup_and_reply_to);
1178 compose_show_first_last_header(compose, TRUE);
1180 textview = (GTK_TEXT_VIEW(compose->text));
1181 textbuf = gtk_text_view_get_buffer(textview);
1182 compose_create_tags(textview, compose);
1184 undo_block(compose->undostruct);
1186 if (msginfo->folder && msginfo->folder->prefs &&
1187 msginfo->folder->prefs &&
1188 msginfo->folder->prefs->enable_default_dictionary &&
1190 gtkaspell_change_dict(compose->gtkaspell,
1191 msginfo->folder->prefs->default_dictionary);
1197 if (prefs_common.quotemark && *prefs_common.quotemark)
1198 qmark = prefs_common.quotemark;
1202 compose_quote_fmt(compose, compose->replyinfo,
1203 prefs_common.quotefmt,
1206 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1207 compose_force_encryption(compose, account, FALSE);
1210 if (account->auto_sig)
1211 compose_insert_sig(compose, FALSE);
1213 cursor_pos = quote_fmt_get_cursor_pos();
1214 gtk_text_buffer_get_start_iter(textbuf, &iter);
1215 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cursor_pos);
1216 gtk_text_buffer_place_cursor(textbuf, &iter);
1218 compose_wrap_all(compose);
1220 gtk_widget_grab_focus(compose->text);
1222 undo_unblock(compose->undostruct);
1224 if (prefs_common.auto_exteditor)
1225 compose_exec_ext_editor(compose);
1227 compose_set_title(compose);
1231 #define INSERT_FW_HEADER(var, hdr) \
1232 if (msginfo->var && *msginfo->var) { \
1233 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1234 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1235 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1238 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1239 gboolean as_attach, const gchar *body,
1240 gboolean no_extedit)
1243 GtkTextView *textview;
1244 GtkTextBuffer *textbuf;
1247 g_return_val_if_fail(msginfo != NULL, NULL);
1248 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1251 !(account = compose_guess_forward_account_from_msginfo
1253 account = cur_account;
1255 compose = compose_create(account, COMPOSE_FORWARD);
1257 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1258 if (!compose->fwdinfo)
1259 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1261 compose_extract_original_charset(compose);
1263 if (msginfo->subject && *msginfo->subject) {
1264 gchar *buf, *buf2, *p;
1266 buf = p = g_strdup(msginfo->subject);
1267 p += subject_get_prefix_length(p);
1268 memmove(buf, p, strlen(p) + 1);
1270 buf2 = g_strdup_printf("Fw: %s", buf);
1271 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1277 textview = GTK_TEXT_VIEW(compose->text);
1278 textbuf = gtk_text_view_get_buffer(textview);
1279 compose_create_tags(textview, compose);
1284 msgfile = procmsg_get_message_file_path(msginfo);
1285 if (!is_file_exist(msgfile))
1286 g_warning("%s: file not exist\n", msgfile);
1288 compose_attach_append(compose, msgfile, msgfile,
1294 MsgInfo *full_msginfo;
1296 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1298 full_msginfo = procmsg_msginfo_copy(msginfo);
1300 if (prefs_common.fw_quotemark &&
1301 *prefs_common.fw_quotemark)
1302 qmark = prefs_common.fw_quotemark;
1306 compose_quote_fmt(compose, full_msginfo,
1307 prefs_common.fw_quotefmt,
1309 compose_attach_parts(compose, msginfo);
1311 procmsg_msginfo_free(full_msginfo);
1314 if (account->auto_sig)
1315 compose_insert_sig(compose, FALSE);
1317 compose_wrap_all(compose);
1319 gtk_text_buffer_get_start_iter(textbuf, &iter);
1320 gtk_text_buffer_place_cursor(textbuf, &iter);
1322 gtk_widget_grab_focus(compose->header_last->entry);
1324 if (!no_extedit && prefs_common.auto_exteditor)
1325 compose_exec_ext_editor(compose);
1328 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1329 gchar *folderidentifier;
1331 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1332 folderidentifier = folder_item_get_identifier(msginfo->folder);
1333 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1334 g_free(folderidentifier);
1337 compose_set_title(compose);
1341 #undef INSERT_FW_HEADER
1343 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1346 GtkTextView *textview;
1347 GtkTextBuffer *textbuf;
1351 gboolean single_mail = TRUE;
1353 g_return_val_if_fail(msginfo_list != NULL, NULL);
1355 if (g_slist_length(msginfo_list) > 1)
1356 single_mail = FALSE;
1358 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1359 if (((MsgInfo *)msginfo->data)->folder == NULL)
1362 /* guess account from first selected message */
1364 !(account = compose_guess_forward_account_from_msginfo
1365 (msginfo_list->data)))
1366 account = cur_account;
1368 g_return_val_if_fail(account != NULL, NULL);
1370 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1371 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1372 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1375 compose = compose_create(account, COMPOSE_FORWARD);
1377 textview = GTK_TEXT_VIEW(compose->text);
1378 textbuf = gtk_text_view_get_buffer(textview);
1379 compose_create_tags(textview, compose);
1381 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1382 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1383 if (!is_file_exist(msgfile))
1384 g_warning("%s: file not exist\n", msgfile);
1386 compose_attach_append(compose, msgfile, msgfile,
1392 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1393 if (info->subject && *info->subject) {
1394 gchar *buf, *buf2, *p;
1396 buf = p = g_strdup(info->subject);
1397 p += subject_get_prefix_length(p);
1398 memmove(buf, p, strlen(p) + 1);
1400 buf2 = g_strdup_printf("Fw: %s", buf);
1401 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1407 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1408 _("Fw: multiple emails"));
1411 if (account->auto_sig)
1412 compose_insert_sig(compose, FALSE);
1414 compose_wrap_all(compose);
1416 gtk_text_buffer_get_start_iter(textbuf, &iter);
1417 gtk_text_buffer_place_cursor(textbuf, &iter);
1419 gtk_widget_grab_focus(compose->header_last->entry);
1421 compose_set_title(compose);
1425 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1427 GtkTextIter start = *iter;
1428 GtkTextIter end_iter;
1429 int start_pos = gtk_text_iter_get_offset(&start);
1431 if (!compose->account->sig_sep)
1434 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1435 start_pos+strlen(compose->account->sig_sep));
1437 /* check sig separator */
1438 if (!strcmp(gtk_text_iter_get_text(&start, &end_iter),
1439 compose->account->sig_sep)) {
1440 /* check end of line (\n) */
1441 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1442 start_pos+strlen(compose->account->sig_sep));
1443 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1444 start_pos+strlen(compose->account->sig_sep)+1);
1446 if (!strcmp(gtk_text_iter_get_text(&start, &end_iter),"\n"));
1455 static void compose_colorize_signature(Compose *compose)
1457 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1459 GtkTextIter end_iter;
1460 gtk_text_buffer_get_start_iter(buffer, &iter);
1461 while (gtk_text_iter_forward_line(&iter))
1462 if (compose_is_sig_separator(compose, buffer, &iter)) {
1463 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1464 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1468 void compose_reedit(MsgInfo *msginfo)
1470 Compose *compose = NULL;
1471 PrefsAccount *account = NULL;
1472 GtkTextView *textview;
1473 GtkTextBuffer *textbuf;
1477 gchar buf[BUFFSIZE];
1478 gboolean use_signing = FALSE;
1479 gboolean use_encryption = FALSE;
1480 gchar *privacy_system = NULL;
1482 g_return_if_fail(msginfo != NULL);
1483 g_return_if_fail(msginfo->folder != NULL);
1485 if (compose_put_existing_to_front(msginfo))
1488 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1489 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1490 gchar queueheader_buf[BUFFSIZE];
1493 /* Select Account from queue headers */
1494 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1495 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1496 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1497 account = account_find_from_id(id);
1499 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1500 sizeof(queueheader_buf), "NAID:")) {
1501 id = atoi(&queueheader_buf[strlen("NAID:")]);
1502 account = account_find_from_id(id);
1504 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1505 sizeof(queueheader_buf), "MAID:")) {
1506 id = atoi(&queueheader_buf[strlen("MAID:")]);
1507 account = account_find_from_id(id);
1509 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1510 sizeof(queueheader_buf), "S:")) {
1511 account = account_find_from_address(queueheader_buf);
1513 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1514 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1515 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1516 use_signing = param;
1519 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1520 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1521 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1522 use_encryption = param;
1524 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1525 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1526 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1528 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1529 sizeof(queueheader_buf), "X-Priority: ")) {
1530 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1531 compose->priority = param;
1534 account = msginfo->folder->folder->account;
1536 if (!account && prefs_common.reedit_account_autosel) {
1537 gchar from[BUFFSIZE];
1538 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1539 extract_address(from);
1540 account = account_find_from_address(from);
1543 if (!account) account = cur_account;
1544 g_return_if_fail(account != NULL);
1546 compose = compose_create(account, COMPOSE_REEDIT);
1547 if (privacy_system != NULL) {
1548 compose->privacy_system = privacy_system;
1549 compose_use_signing(compose, use_signing);
1550 compose_use_encryption(compose, use_encryption);
1551 compose_update_privacy_system_menu_item(compose, FALSE);
1553 activate_privacy_system(compose, account, FALSE);
1555 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1557 compose_extract_original_charset(compose);
1559 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1560 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1561 gchar queueheader_buf[BUFFSIZE];
1563 /* Set message save folder */
1564 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1567 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1568 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1569 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1573 if (compose_parse_header(compose, msginfo) < 0) return;
1574 compose_reedit_set_entry(compose, msginfo);
1576 textview = GTK_TEXT_VIEW(compose->text);
1577 textbuf = gtk_text_view_get_buffer(textview);
1578 compose_create_tags(textview, compose);
1580 mark = gtk_text_buffer_get_insert(textbuf);
1581 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1583 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1584 G_CALLBACK(compose_changed_cb),
1587 if (procmime_msginfo_is_encrypted(msginfo)) {
1588 fp = procmime_get_first_encrypted_text_content(msginfo);
1590 compose_force_encryption(compose, account, TRUE);
1592 fp = procmime_get_first_text_content(msginfo);
1594 g_warning("Can't get text part\n");
1597 gboolean prev_autowrap = compose->autowrap;
1599 compose->autowrap = FALSE;
1600 while (fgets(buf, sizeof(buf), fp) != NULL) {
1602 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1604 compose_wrap_all_full(compose, FALSE);
1605 compose->autowrap = prev_autowrap;
1609 compose_attach_parts(compose, msginfo);
1611 compose_colorize_signature(compose);
1613 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1614 G_CALLBACK(compose_changed_cb),
1617 gtk_widget_grab_focus(compose->text);
1619 if (prefs_common.auto_exteditor)
1620 compose_exec_ext_editor(compose);
1621 compose_set_title(compose);
1624 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1628 GtkItemFactory *ifactory;
1631 g_return_val_if_fail(msginfo != NULL, NULL);
1634 account = account_get_reply_account(msginfo,
1635 prefs_common.reply_account_autosel);
1636 g_return_val_if_fail(account != NULL, NULL);
1638 compose = compose_create(account, COMPOSE_REDIRECT);
1639 ifactory = gtk_item_factory_from_widget(compose->menubar);
1640 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1641 compose->replyinfo = NULL;
1642 compose->fwdinfo = NULL;
1644 compose_show_first_last_header(compose, TRUE);
1646 gtk_widget_grab_focus(compose->header_last->entry);
1648 filename = procmsg_get_message_file_path(msginfo);
1649 if (filename == NULL)
1652 compose->redirect_filename = filename;
1654 /* Set save folder */
1655 item = msginfo->folder;
1656 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1657 gchar *folderidentifier;
1659 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1660 folderidentifier = folder_item_get_identifier(item);
1661 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1662 g_free(folderidentifier);
1665 compose_attach_parts(compose, msginfo);
1667 if (msginfo->subject)
1668 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1670 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1672 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1673 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1675 compose_colorize_signature(compose);
1677 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1678 menu_set_sensitive(ifactory, "/Add...", FALSE);
1679 menu_set_sensitive(ifactory, "/Remove", FALSE);
1680 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1682 ifactory = gtk_item_factory_from_widget(compose->menubar);
1683 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1684 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1685 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1686 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1687 menu_set_sensitive(ifactory, "/Edit", FALSE);
1688 menu_set_sensitive(ifactory, "/Options", FALSE);
1689 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1690 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1692 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1693 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1694 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1695 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1696 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1697 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1698 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1700 compose_set_title(compose);
1704 GList *compose_get_compose_list(void)
1706 return compose_list;
1709 void compose_entry_append(Compose *compose, const gchar *address,
1710 ComposeEntryType type)
1714 gboolean in_quote = FALSE;
1715 if (!address || *address == '\0') return;
1722 header = N_("Bcc:");
1724 case COMPOSE_REPLYTO:
1725 header = N_("Reply-To:");
1727 case COMPOSE_NEWSGROUPS:
1728 header = N_("Newsgroups:");
1730 case COMPOSE_FOLLOWUPTO:
1731 header = N_( "Followup-To:");
1738 header = prefs_common.trans_hdr ? gettext(header) : header;
1740 cur = begin = (gchar *)address;
1742 /* we separate the line by commas, but not if we're inside a quoted
1744 while (*cur != '\0') {
1746 in_quote = !in_quote;
1747 if (*cur == ',' && !in_quote) {
1748 gchar *tmp = g_strdup(begin);
1750 tmp[cur-begin]='\0';
1755 compose_add_header_entry(compose, header, tmp);
1762 gchar *tmp = g_strdup(begin);
1764 tmp[cur-begin]='\0';
1769 compose_add_header_entry(compose, header, tmp);
1774 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1776 static GtkStyle *bold_style = NULL;
1777 static GdkColor bold_color;
1781 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1782 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1783 if (gtk_entry_get_text(entry) &&
1784 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1785 gtk_widget_ensure_style(GTK_WIDGET(entry));
1787 gtkut_convert_int_to_gdk_color
1788 (prefs_common.color_new, &bold_color);
1789 bold_style = gtk_style_copy(gtk_widget_get_style
1790 (GTK_WIDGET(entry)));
1791 pango_font_description_set_weight
1792 (bold_style->font_desc, PANGO_WEIGHT_BOLD);
1793 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1795 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1800 void compose_toolbar_cb(gint action, gpointer data)
1802 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1803 Compose *compose = (Compose*)toolbar_item->parent;
1805 g_return_if_fail(compose != NULL);
1809 compose_send_cb(compose, 0, NULL);
1812 compose_send_later_cb(compose, 0, NULL);
1815 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1818 compose_insert_file_cb(compose, 0, NULL);
1821 compose_attach_cb(compose, 0, NULL);
1824 compose_insert_sig(compose, FALSE);
1827 compose_ext_editor_cb(compose, 0, NULL);
1829 case A_LINEWRAP_CURRENT:
1830 compose_beautify_paragraph(compose, NULL, TRUE);
1832 case A_LINEWRAP_ALL:
1833 compose_wrap_all_full(compose, TRUE);
1836 compose_address_cb(compose, 0, NULL);
1839 case A_CHECK_SPELLING:
1840 compose_check_all(compose);
1848 static void compose_entries_set(Compose *compose, const gchar *mailto)
1852 gchar *subject = NULL;
1857 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1860 compose_entry_append(compose, to, COMPOSE_TO);
1862 compose_entry_append(compose, cc, COMPOSE_CC);
1864 if (!g_utf8_validate (subject, -1, NULL)) {
1865 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1866 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1869 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1873 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1874 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1877 gboolean prev_autowrap = compose->autowrap;
1879 compose->autowrap = FALSE;
1881 mark = gtk_text_buffer_get_insert(buffer);
1882 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1884 if (!g_utf8_validate (body, -1, NULL)) {
1885 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1886 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1889 gtk_text_buffer_insert(buffer, &iter, body, -1);
1891 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1893 compose->autowrap = prev_autowrap;
1894 if (compose->autowrap)
1895 compose_wrap_all(compose);
1904 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1906 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1907 {"Cc:", NULL, TRUE},
1908 {"References:", NULL, FALSE},
1909 {"Bcc:", NULL, TRUE},
1910 {"Newsgroups:", NULL, TRUE},
1911 {"Followup-To:", NULL, TRUE},
1912 {"List-Post:", NULL, FALSE},
1913 {"X-Priority:", NULL, FALSE},
1914 {NULL, NULL, FALSE}};
1930 g_return_val_if_fail(msginfo != NULL, -1);
1932 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1933 procheader_get_header_fields(fp, hentry);
1936 if (hentry[H_REPLY_TO].body != NULL) {
1937 if (hentry[H_REPLY_TO].body[0] != '\0') {
1939 conv_unmime_header(hentry[H_REPLY_TO].body,
1942 g_free(hentry[H_REPLY_TO].body);
1943 hentry[H_REPLY_TO].body = NULL;
1945 if (hentry[H_CC].body != NULL) {
1946 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
1947 g_free(hentry[H_CC].body);
1948 hentry[H_CC].body = NULL;
1950 if (hentry[H_REFERENCES].body != NULL) {
1951 if (compose->mode == COMPOSE_REEDIT)
1952 compose->references = hentry[H_REFERENCES].body;
1954 compose->references = compose_parse_references
1955 (hentry[H_REFERENCES].body, msginfo->msgid);
1956 g_free(hentry[H_REFERENCES].body);
1958 hentry[H_REFERENCES].body = NULL;
1960 if (hentry[H_BCC].body != NULL) {
1961 if (compose->mode == COMPOSE_REEDIT)
1963 conv_unmime_header(hentry[H_BCC].body, NULL);
1964 g_free(hentry[H_BCC].body);
1965 hentry[H_BCC].body = NULL;
1967 if (hentry[H_NEWSGROUPS].body != NULL) {
1968 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1969 hentry[H_NEWSGROUPS].body = NULL;
1971 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1972 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
1973 compose->followup_to =
1974 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
1977 g_free(hentry[H_FOLLOWUP_TO].body);
1978 hentry[H_FOLLOWUP_TO].body = NULL;
1980 if (hentry[H_LIST_POST].body != NULL) {
1983 extract_address(hentry[H_LIST_POST].body);
1984 if (hentry[H_LIST_POST].body[0] != '\0') {
1985 scan_mailto_url(hentry[H_LIST_POST].body,
1986 &to, NULL, NULL, NULL, NULL);
1988 g_free(compose->ml_post);
1989 compose->ml_post = to;
1992 g_free(hentry[H_LIST_POST].body);
1993 hentry[H_LIST_POST].body = NULL;
1996 /* CLAWS - X-Priority */
1997 if (compose->mode == COMPOSE_REEDIT)
1998 if (hentry[H_X_PRIORITY].body != NULL) {
2001 priority = atoi(hentry[H_X_PRIORITY].body);
2002 g_free(hentry[H_X_PRIORITY].body);
2004 hentry[H_X_PRIORITY].body = NULL;
2006 if (priority < PRIORITY_HIGHEST ||
2007 priority > PRIORITY_LOWEST)
2008 priority = PRIORITY_NORMAL;
2010 compose->priority = priority;
2013 if (compose->mode == COMPOSE_REEDIT) {
2014 if (msginfo->inreplyto && *msginfo->inreplyto)
2015 compose->inreplyto = g_strdup(msginfo->inreplyto);
2019 if (msginfo->msgid && *msginfo->msgid)
2020 compose->inreplyto = g_strdup(msginfo->msgid);
2022 if (!compose->references) {
2023 if (msginfo->msgid && *msginfo->msgid) {
2024 if (msginfo->inreplyto && *msginfo->inreplyto)
2025 compose->references =
2026 g_strdup_printf("<%s>\n\t<%s>",
2030 compose->references =
2031 g_strconcat("<", msginfo->msgid, ">",
2033 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2034 compose->references =
2035 g_strconcat("<", msginfo->inreplyto, ">",
2043 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2045 GSList *ref_id_list, *cur;
2049 ref_id_list = references_list_append(NULL, ref);
2050 if (!ref_id_list) return NULL;
2051 if (msgid && *msgid)
2052 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2057 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2058 /* "<" + Message-ID + ">" + CR+LF+TAB */
2059 len += strlen((gchar *)cur->data) + 5;
2061 if (len > MAX_REFERENCES_LEN) {
2062 /* remove second message-ID */
2063 if (ref_id_list && ref_id_list->next &&
2064 ref_id_list->next->next) {
2065 g_free(ref_id_list->next->data);
2066 ref_id_list = g_slist_remove
2067 (ref_id_list, ref_id_list->next->data);
2069 slist_free_strings(ref_id_list);
2070 g_slist_free(ref_id_list);
2077 new_ref = g_string_new("");
2078 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2079 if (new_ref->len > 0)
2080 g_string_append(new_ref, "\n\t");
2081 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2084 slist_free_strings(ref_id_list);
2085 g_slist_free(ref_id_list);
2087 new_ref_str = new_ref->str;
2088 g_string_free(new_ref, FALSE);
2093 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2094 const gchar *fmt, const gchar *qmark,
2097 static MsgInfo dummyinfo;
2098 gchar *quote_str = NULL;
2102 gboolean prev_autowrap;
2103 const gchar *trimmed_body = body;
2104 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2105 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2108 msginfo = &dummyinfo;
2110 if (qmark != NULL) {
2111 quote_fmt_init(msginfo, NULL, NULL);
2112 quote_fmt_scan_string(qmark);
2115 buf = quote_fmt_get_buffer();
2117 alertpanel_error(_("Quote mark format error."));
2119 Xstrdup_a(quote_str, buf, return NULL)
2122 if (fmt && *fmt != '\0') {
2123 while (trimmed_body && strlen(trimmed_body) > 1
2124 && trimmed_body[0]=='\n')
2127 quote_fmt_init(msginfo, quote_str, trimmed_body);
2128 quote_fmt_scan_string(fmt);
2131 buf = quote_fmt_get_buffer();
2133 alertpanel_error(_("Message reply/forward format error."));
2139 prev_autowrap = compose->autowrap;
2140 compose->autowrap = FALSE;
2142 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2143 G_CALLBACK(compose_changed_cb),
2145 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2146 G_CALLBACK(text_inserted),
2148 for (p = buf; *p != '\0'; ) {
2153 mark = gtk_text_buffer_get_insert(buffer);
2154 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2156 lastp = strchr(p, '\n');
2157 len = lastp ? lastp - p + 1 : -1;
2159 if (g_utf8_validate(p, -1, NULL)) {
2160 gtk_text_buffer_insert(buffer, &iter, p, len);
2162 gchar *tmpin = g_strdup(p);
2163 gchar *tmpout = NULL;
2165 tmpout = conv_codeset_strdup
2166 (tmpin, conv_get_locale_charset_str(),
2168 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
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 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2195 gboolean to_all, gboolean to_ml,
2197 gboolean followup_and_reply_to)
2199 GSList *cc_list = NULL;
2202 gchar *replyto = NULL;
2203 GHashTable *to_table;
2205 g_return_if_fail(compose->account != NULL);
2206 g_return_if_fail(msginfo != NULL);
2208 if (compose->account->protocol != A_NNTP) {
2209 if (to_ml && compose->ml_post
2210 && !(msginfo->folder &&
2211 msginfo->folder->prefs->enable_default_reply_to)) {
2212 compose_entry_append(compose,
2215 if (compose->replyto) {
2216 gchar *tmp1 = NULL, *tmp2 = NULL;
2217 Xstrdup_a(tmp1, compose->replyto, return);
2218 if (compose->ml_post)
2219 Xstrdup_a(tmp2, compose->ml_post, return);
2220 extract_address(tmp1);
2221 extract_address(tmp2);
2222 if (tmp1 && tmp2 && strcmp(tmp1, tmp2))
2223 compose_entry_append(compose,
2228 else if (!(to_all || to_sender)
2230 && msginfo->folder->prefs->enable_default_reply_to) {
2231 compose_entry_append(compose,
2232 msginfo->folder->prefs->default_reply_to,
2235 compose_entry_append(compose,
2236 (compose->replyto && !to_sender)
2237 ? compose->replyto :
2238 msginfo->from ? msginfo->from : "",
2241 if (to_sender || (compose->followup_to &&
2242 !strncmp(compose->followup_to, "poster", 6)))
2243 compose_entry_append
2245 (compose->replyto ? compose->replyto :
2246 msginfo->from ? msginfo->from : ""),
2249 else if (followup_and_reply_to || to_all) {
2250 compose_entry_append
2252 (compose->replyto ? compose->replyto :
2253 msginfo->from ? msginfo->from : ""),
2256 compose_entry_append
2258 compose->followup_to ? compose->followup_to :
2259 compose->newsgroups ? compose->newsgroups : "",
2260 COMPOSE_NEWSGROUPS);
2263 compose_entry_append
2265 compose->followup_to ? compose->followup_to :
2266 compose->newsgroups ? compose->newsgroups : "",
2267 COMPOSE_NEWSGROUPS);
2270 if (msginfo->subject && *msginfo->subject) {
2274 buf = p = g_strdup(msginfo->subject);
2275 p += subject_get_prefix_length(p);
2276 memmove(buf, p, strlen(p) + 1);
2278 buf2 = g_strdup_printf("Re: %s", buf);
2279 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2284 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2286 if (to_ml && compose->ml_post) return;
2287 if (!to_all || compose->account->protocol == A_NNTP) return;
2289 if (compose->replyto) {
2290 Xstrdup_a(replyto, compose->replyto, return);
2291 extract_address(replyto);
2293 if (msginfo->from) {
2294 Xstrdup_a(from, msginfo->from, return);
2295 extract_address(from);
2298 if (replyto && from)
2299 cc_list = address_list_append_with_comments(cc_list, from);
2300 if (to_all && msginfo->folder &&
2301 msginfo->folder->prefs->enable_default_reply_to)
2302 cc_list = address_list_append_with_comments(cc_list,
2303 msginfo->folder->prefs->default_reply_to);
2304 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2305 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2307 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2309 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2310 if (compose->account)
2311 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2312 GINT_TO_POINTER(1));
2314 /* remove address on To: and that of current account */
2315 for (cur = cc_list; cur != NULL; ) {
2316 GSList *next = cur->next;
2319 addr = g_strdup(cur->data);
2320 extract_address(addr);
2322 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2323 cc_list = g_slist_remove(cc_list, cur->data);
2325 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2329 hash_free_strings(to_table);
2330 g_hash_table_destroy(to_table);
2333 for (cur = cc_list; cur != NULL; cur = cur->next)
2334 compose_entry_append(compose, (gchar *)cur->data,
2336 slist_free_strings(cc_list);
2337 g_slist_free(cc_list);
2342 #define SET_ENTRY(entry, str) \
2345 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2348 #define SET_ADDRESS(type, str) \
2351 compose_entry_append(compose, str, type); \
2354 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2356 g_return_if_fail(msginfo != NULL);
2358 SET_ENTRY(subject_entry, msginfo->subject);
2359 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2360 SET_ADDRESS(COMPOSE_CC, compose->cc);
2361 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2362 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2363 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2364 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2366 compose_update_priority_menu_item(compose);
2367 compose_update_privacy_system_menu_item(compose, FALSE);
2368 compose_show_first_last_header(compose, TRUE);
2374 static void compose_insert_sig(Compose *compose, gboolean replace)
2376 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2377 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2379 GtkTextIter iter, iter_end;
2381 gboolean prev_autowrap;
2384 g_return_if_fail(compose->account != NULL);
2386 prev_autowrap = compose->autowrap;
2387 compose->autowrap = FALSE;
2389 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2390 G_CALLBACK(compose_changed_cb),
2393 mark = gtk_text_buffer_get_insert(buffer);
2394 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2395 cur_pos = gtk_text_iter_get_offset (&iter);
2397 gtk_text_buffer_get_end_iter(buffer, &iter);
2399 if (replace && compose->sig_str) {
2401 GtkTextIter first_iter, start_iter, end_iter;
2403 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2405 if (compose->sig_str[0] == '\0')
2408 found = gtk_text_iter_forward_search(&first_iter,
2410 GTK_TEXT_SEARCH_TEXT_ONLY,
2411 &start_iter, &end_iter,
2415 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2420 g_free(compose->sig_str);
2421 compose->sig_str = compose_get_signature_str(compose);
2422 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2423 compose->sig_str = g_strdup("");
2425 cur_pos = gtk_text_iter_get_offset(&iter);
2426 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2428 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2429 gtk_text_iter_forward_char(&iter);
2430 gtk_text_iter_forward_char(&iter);
2431 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2432 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2434 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2435 cur_pos = gtk_text_buffer_get_char_count (buffer);
2437 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2438 gtk_text_buffer_place_cursor(buffer, &iter);
2440 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2441 G_CALLBACK(compose_changed_cb),
2444 compose->autowrap = prev_autowrap;
2445 if (compose->autowrap)
2446 compose_wrap_all(compose);
2449 static gchar *compose_get_signature_str(Compose *compose)
2451 gchar *sig_body = NULL;
2452 gchar *sig_str = NULL;
2453 gchar *utf8_sig_str = NULL;
2455 g_return_val_if_fail(compose->account != NULL, NULL);
2457 if (!compose->account->sig_path)
2460 if (compose->account->sig_type == SIG_FILE) {
2461 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2462 g_warning("can't open signature file: %s\n",
2463 compose->account->sig_path);
2468 if (compose->account->sig_type == SIG_COMMAND)
2469 sig_body = get_command_output(compose->account->sig_path);
2473 tmp = file_read_to_str(compose->account->sig_path);
2476 sig_body = normalize_newlines(tmp);
2480 if (compose->account->sig_sep) {
2481 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2485 sig_str = g_strconcat("\n\n", sig_body, NULL);
2488 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2489 utf8_sig_str = sig_str;
2491 utf8_sig_str = conv_codeset_strdup
2492 (sig_str, conv_get_locale_charset_str(),
2498 return utf8_sig_str;
2501 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2504 GtkTextBuffer *buffer;
2507 const gchar *cur_encoding;
2508 gchar buf[BUFFSIZE];
2511 gboolean prev_autowrap;
2512 gboolean badtxt = FALSE;
2514 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2516 if ((fp = g_fopen(file, "rb")) == NULL) {
2517 FILE_OP_ERROR(file, "fopen");
2518 return COMPOSE_INSERT_READ_ERROR;
2521 prev_autowrap = compose->autowrap;
2522 compose->autowrap = FALSE;
2524 text = GTK_TEXT_VIEW(compose->text);
2525 buffer = gtk_text_view_get_buffer(text);
2526 mark = gtk_text_buffer_get_insert(buffer);
2527 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2529 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2530 G_CALLBACK(text_inserted),
2533 cur_encoding = conv_get_locale_charset_str();
2535 while (fgets(buf, sizeof(buf), fp) != NULL) {
2538 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2539 str = g_strdup(buf);
2541 str = conv_codeset_strdup
2542 (buf, cur_encoding, CS_INTERNAL);
2545 /* strip <CR> if DOS/Windows file,
2546 replace <CR> with <LF> if Macintosh file. */
2549 if (len > 0 && str[len - 1] != '\n') {
2551 if (str[len] == '\r') str[len] = '\n';
2554 gtk_text_buffer_insert(buffer, &iter, str, -1);
2558 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2559 G_CALLBACK(text_inserted),
2561 compose->autowrap = prev_autowrap;
2562 if (compose->autowrap)
2563 compose_wrap_all(compose);
2568 return COMPOSE_INSERT_INVALID_CHARACTER;
2570 return COMPOSE_INSERT_SUCCESS;
2573 static void compose_attach_append(Compose *compose, const gchar *file,
2574 const gchar *filename,
2575 const gchar *content_type)
2583 GtkListStore *store;
2586 if (!is_file_exist(file)) {
2587 g_warning("File %s doesn't exist\n", filename);
2590 if ((size = get_file_size(file)) < 0) {
2591 g_warning("Can't get file size of %s\n", filename);
2595 alertpanel_notice(_("File %s is empty."), filename);
2598 if ((fp = g_fopen(file, "rb")) == NULL) {
2599 alertpanel_error(_("Can't read %s."), filename);
2604 ainfo = g_new0(AttachInfo, 1);
2605 auto_ainfo = g_auto_pointer_new_with_free
2606 (ainfo, (GFreeFunc) compose_attach_info_free);
2607 ainfo->file = g_strdup(file);
2610 ainfo->content_type = g_strdup(content_type);
2611 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2613 MsgFlags flags = {0, 0};
2615 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2616 ainfo->encoding = ENC_7BIT;
2618 ainfo->encoding = ENC_8BIT;
2620 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2621 if (msginfo && msginfo->subject)
2622 name = g_strdup(msginfo->subject);
2624 name = g_path_get_basename(filename ? filename : file);
2626 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2628 procmsg_msginfo_free(msginfo);
2630 if (!g_ascii_strncasecmp(content_type, "text", 4))
2631 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2633 ainfo->encoding = ENC_BASE64;
2634 name = g_path_get_basename(filename ? filename : file);
2635 ainfo->name = g_strdup(name);
2639 ainfo->content_type = procmime_get_mime_type(file);
2640 if (!ainfo->content_type) {
2641 ainfo->content_type =
2642 g_strdup("application/octet-stream");
2643 ainfo->encoding = ENC_BASE64;
2644 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2646 procmime_get_encoding_for_text_file(file);
2648 ainfo->encoding = ENC_BASE64;
2649 name = g_path_get_basename(filename ? filename : file);
2650 ainfo->name = g_strdup(name);
2654 if (!strcmp(ainfo->content_type, "unknown")) {
2655 g_free(ainfo->content_type);
2656 ainfo->content_type = g_strdup("application/octet-stream");
2660 size_text = to_human_readable(size);
2662 store = GTK_LIST_STORE(gtk_tree_view_get_model
2663 (GTK_TREE_VIEW(compose->attach_clist)));
2665 gtk_list_store_append(store, &iter);
2666 gtk_list_store_set(store, &iter,
2667 COL_MIMETYPE, ainfo->content_type,
2668 COL_SIZE, size_text,
2669 COL_NAME, ainfo->name,
2671 COL_AUTODATA, auto_ainfo,
2674 g_auto_pointer_free(auto_ainfo);
2677 static void compose_use_signing(Compose *compose, gboolean use_signing)
2679 GtkItemFactory *ifactory;
2680 GtkWidget *menuitem = NULL;
2682 compose->use_signing = use_signing;
2683 ifactory = gtk_item_factory_from_widget(compose->menubar);
2684 menuitem = gtk_item_factory_get_item
2685 (ifactory, "/Options/Sign");
2686 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2690 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2692 GtkItemFactory *ifactory;
2693 GtkWidget *menuitem = NULL;
2695 compose->use_encryption = use_encryption;
2696 ifactory = gtk_item_factory_from_widget(compose->menubar);
2697 menuitem = gtk_item_factory_get_item
2698 (ifactory, "/Options/Encrypt");
2700 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2704 #define NEXT_PART_NOT_CHILD(info) \
2706 node = info->node; \
2707 while (node->children) \
2708 node = g_node_last_child(node); \
2709 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2712 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2716 MimeInfo *firsttext = NULL;
2717 MimeInfo *encrypted = NULL;
2720 const gchar *partname = NULL;
2722 mimeinfo = procmime_scan_message(msginfo);
2723 if (!mimeinfo) return;
2725 if (mimeinfo->node->children == NULL) {
2726 procmime_mimeinfo_free_all(mimeinfo);
2730 /* find first content part */
2731 child = (MimeInfo *) mimeinfo->node->children->data;
2732 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2733 child = (MimeInfo *)child->node->children->data;
2735 if (child->type == MIMETYPE_TEXT) {
2737 debug_print("First text part found\n");
2738 } else if (compose->mode == COMPOSE_REEDIT &&
2739 child->type == MIMETYPE_APPLICATION &&
2740 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2741 encrypted = (MimeInfo *)child->node->parent->data;
2744 child = (MimeInfo *) mimeinfo->node->children->data;
2745 while (child != NULL) {
2746 if (child == encrypted) {
2747 /* skip this part of tree */
2748 NEXT_PART_NOT_CHILD(child);
2752 if (child->type == MIMETYPE_MULTIPART) {
2753 /* get the actual content */
2754 child = procmime_mimeinfo_next(child);
2758 if (child == firsttext) {
2759 child = procmime_mimeinfo_next(child);
2763 outfile = procmime_get_tmp_file_name(child);
2764 if (procmime_get_part(outfile, child) < 0)
2765 g_warning("Can't get the part of multipart message.");
2767 gchar *content_type;
2769 content_type = procmime_get_content_type_str(child->type, child->subtype);
2771 /* if we meet a pgp signature, we don't attach it, but
2772 * we force signing. */
2773 if (strcmp(content_type, "application/pgp-signature")) {
2774 partname = procmime_mimeinfo_get_parameter(child, "filename");
2775 if (partname == NULL)
2776 partname = procmime_mimeinfo_get_parameter(child, "name");
2777 if (partname == NULL)
2779 compose_attach_append(compose, outfile,
2780 partname, content_type);
2782 compose_force_signing(compose, compose->account);
2784 g_free(content_type);
2787 NEXT_PART_NOT_CHILD(child);
2789 procmime_mimeinfo_free_all(mimeinfo);
2792 #undef NEXT_PART_NOT_CHILD
2797 WAIT_FOR_INDENT_CHAR,
2798 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2801 /* return indent length, we allow:
2802 indent characters followed by indent characters or spaces/tabs,
2803 alphabets and numbers immediately followed by indent characters,
2804 and the repeating sequences of the above
2805 If quote ends with multiple spaces, only the first one is included. */
2806 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2807 const GtkTextIter *start, gint *len)
2809 GtkTextIter iter = *start;
2813 IndentState state = WAIT_FOR_INDENT_CHAR;
2816 gint alnum_count = 0;
2817 gint space_count = 0;
2820 if (prefs_common.quote_chars == NULL) {
2824 while (!gtk_text_iter_ends_line(&iter)) {
2825 wc = gtk_text_iter_get_char(&iter);
2826 if (g_unichar_iswide(wc))
2828 clen = g_unichar_to_utf8(wc, ch);
2832 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2833 is_space = g_unichar_isspace(wc);
2835 if (state == WAIT_FOR_INDENT_CHAR) {
2836 if (!is_indent && !g_unichar_isalnum(wc))
2839 quote_len += alnum_count + space_count + 1;
2840 alnum_count = space_count = 0;
2841 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2844 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2845 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
2849 else if (is_indent) {
2850 quote_len += alnum_count + space_count + 1;
2851 alnum_count = space_count = 0;
2854 state = WAIT_FOR_INDENT_CHAR;
2858 gtk_text_iter_forward_char(&iter);
2861 if (quote_len > 0 && space_count > 0)
2867 if (quote_len > 0) {
2869 gtk_text_iter_forward_chars(&iter, quote_len);
2870 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
2876 /* return TRUE if the line is itemized */
2877 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
2878 const GtkTextIter *start)
2880 GtkTextIter iter = *start;
2885 if (gtk_text_iter_ends_line(&iter))
2889 wc = gtk_text_iter_get_char(&iter);
2890 if (!g_unichar_isspace(wc))
2892 gtk_text_iter_forward_char(&iter);
2893 if (gtk_text_iter_ends_line(&iter))
2897 clen = g_unichar_to_utf8(wc, ch);
2901 if (!strchr("*-+", ch[0]))
2904 gtk_text_iter_forward_char(&iter);
2905 if (gtk_text_iter_ends_line(&iter))
2907 wc = gtk_text_iter_get_char(&iter);
2908 if (g_unichar_isspace(wc))
2914 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
2915 const GtkTextIter *start,
2916 GtkTextIter *break_pos,
2920 GtkTextIter iter = *start, line_end = *start;
2921 PangoLogAttr *attrs;
2928 gboolean can_break = FALSE;
2929 gboolean do_break = FALSE;
2930 gboolean was_white = FALSE;
2931 gboolean prev_dont_break = FALSE;
2933 gtk_text_iter_forward_to_line_end(&line_end);
2934 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
2935 len = g_utf8_strlen(str, -1);
2936 /* g_print("breaking line: %d: %s (len = %d)\n",
2937 gtk_text_iter_get_line(&iter), str, len); */
2938 attrs = g_new(PangoLogAttr, len + 1);
2940 pango_default_break(str, -1, NULL, attrs, len + 1);
2944 /* skip quote and leading spaces */
2945 for (i = 0; *p != '\0' && i < len; i++) {
2948 wc = g_utf8_get_char(p);
2949 if (i >= quote_len && !g_unichar_isspace(wc))
2951 if (g_unichar_iswide(wc))
2953 else if (*p == '\t')
2957 p = g_utf8_next_char(p);
2960 for (; *p != '\0' && i < len; i++) {
2961 PangoLogAttr *attr = attrs + i;
2965 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
2968 was_white = attr->is_white;
2970 /* don't wrap URI */
2971 if ((uri_len = get_uri_len(p)) > 0) {
2973 if (pos > 0 && col > max_col) {
2983 wc = g_utf8_get_char(p);
2984 if (g_unichar_iswide(wc)) {
2986 if (prev_dont_break && can_break && attr->is_line_break)
2988 } else if (*p == '\t')
2992 if (pos > 0 && col > max_col) {
2997 if (*p == '-' || *p == '/')
2998 prev_dont_break = TRUE;
3000 prev_dont_break = FALSE;
3002 p = g_utf8_next_char(p);
3006 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3011 *break_pos = *start;
3012 gtk_text_iter_set_line_offset(break_pos, pos);
3017 static gboolean compose_join_next_line(Compose *compose,
3018 GtkTextBuffer *buffer,
3020 const gchar *quote_str)
3022 GtkTextIter iter_ = *iter, cur, prev, next, end;
3023 PangoLogAttr attrs[3];
3025 gchar *next_quote_str;
3028 gboolean keep_cursor = FALSE;
3030 if (!gtk_text_iter_forward_line(&iter_) ||
3031 gtk_text_iter_ends_line(&iter_))
3034 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3036 if ((quote_str || next_quote_str) &&
3037 strcmp2(quote_str, next_quote_str) != 0) {
3038 g_free(next_quote_str);
3041 g_free(next_quote_str);
3044 if (quote_len > 0) {
3045 gtk_text_iter_forward_chars(&end, quote_len);
3046 if (gtk_text_iter_ends_line(&end))
3050 /* don't join itemized lines */
3051 if (compose_is_itemized(buffer, &end))
3054 /* don't join signature separator */
3055 if (compose_is_sig_separator(compose, buffer, &iter_))
3058 /* delete quote str */
3060 gtk_text_buffer_delete(buffer, &iter_, &end);
3062 /* delete linebreak and extra spaces */
3064 while (gtk_text_iter_backward_char(&cur)) {
3065 wc1 = gtk_text_iter_get_char(&cur);
3066 if (!g_unichar_isspace(wc1))
3071 while (!gtk_text_iter_ends_line(&cur)) {
3072 wc1 = gtk_text_iter_get_char(&cur);
3073 if (!g_unichar_isspace(wc1))
3075 gtk_text_iter_forward_char(&cur);
3078 if (!gtk_text_iter_equal(&prev, &next)) {
3081 mark = gtk_text_buffer_get_insert(buffer);
3082 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3083 if (gtk_text_iter_equal(&prev, &cur))
3085 gtk_text_buffer_delete(buffer, &prev, &next);
3089 /* insert space if required */
3090 gtk_text_iter_backward_char(&prev);
3091 wc1 = gtk_text_iter_get_char(&prev);
3092 wc2 = gtk_text_iter_get_char(&next);
3093 gtk_text_iter_forward_char(&next);
3094 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3095 pango_default_break(str, -1, NULL, attrs, 3);
3096 if (!attrs[1].is_line_break ||
3097 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3098 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3100 gtk_text_iter_backward_char(&iter_);
3101 gtk_text_buffer_place_cursor(buffer, &iter_);
3110 #define ADD_TXT_POS(bp_, ep_, pti_) \
3111 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3112 last = last->next; \
3113 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3114 last->next = NULL; \
3116 g_warning("alloc error scanning URIs\n"); \
3119 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3121 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3122 GtkTextBuffer *buffer;
3123 GtkTextIter iter, break_pos, end_of_line;
3124 gchar *quote_str = NULL;
3126 gboolean wrap_quote = prefs_common.linewrap_quote;
3127 gboolean prev_autowrap = compose->autowrap;
3128 gint startq_offset = -1, noq_offset = -1;
3129 gint uri_start = -1, uri_stop = -1;
3130 gint nouri_start = -1, nouri_stop = -1;
3132 compose->autowrap = FALSE;
3134 buffer = gtk_text_view_get_buffer(text);
3136 undo_block(compose->undostruct);
3142 mark = gtk_text_buffer_get_insert(buffer);
3143 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3146 /* move to paragraph start */
3147 gtk_text_iter_set_line_offset(&iter, 0);
3148 if (gtk_text_iter_ends_line(&iter)) {
3149 while (gtk_text_iter_ends_line(&iter) &&
3150 gtk_text_iter_forward_line(&iter))
3153 while (gtk_text_iter_backward_line(&iter)) {
3154 if (gtk_text_iter_ends_line(&iter)) {
3155 gtk_text_iter_forward_line(&iter);
3161 /* go until paragraph end (empty line) */
3162 while (!gtk_text_iter_ends_line(&iter)) {
3163 gchar *scanpos = NULL;
3164 /* parse table - in order of priority */
3166 const gchar *needle; /* token */
3168 /* token search function */
3169 gchar *(*search) (const gchar *haystack,
3170 const gchar *needle);
3171 /* part parsing function */
3172 gboolean (*parse) (const gchar *start,
3173 const gchar *scanpos,
3176 /* part to URI function */
3177 gchar *(*build_uri) (const gchar *bp,
3181 static struct table parser[] = {
3182 {"http://", strcasestr, get_uri_part, make_uri_string},
3183 {"https://", strcasestr, get_uri_part, make_uri_string},
3184 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3185 {"www.", strcasestr, get_uri_part, make_http_string},
3186 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3187 {"@", strcasestr, get_email_part, make_email_string}
3189 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3190 gint last_index = PARSE_ELEMS;
3192 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3195 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3198 uri_start = uri_stop = -1;
3199 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3203 if (startq_offset == -1) {
3204 startq_offset = gtk_text_iter_get_offset(&iter);
3208 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3209 if (startq_offset == -1)
3210 startq_offset = gtk_text_iter_get_offset(&iter);
3212 if (startq_offset == -1)
3213 noq_offset = gtk_text_iter_get_offset(&iter);
3216 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3219 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3220 prefs_common.linewrap_len,
3222 GtkTextIter prev, next, cur;
3224 if (prev_autowrap != FALSE || force)
3225 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3226 else if (quote_str && wrap_quote)
3227 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3230 /* remove trailing spaces */
3232 gtk_text_iter_backward_char(&cur);
3234 while (!gtk_text_iter_starts_line(&cur)) {
3237 gtk_text_iter_backward_char(&cur);
3238 wc = gtk_text_iter_get_char(&cur);
3239 if (!g_unichar_isspace(wc))
3243 if (!gtk_text_iter_equal(&prev, &next)) {
3244 gtk_text_buffer_delete(buffer, &prev, &next);
3246 gtk_text_iter_forward_char(&break_pos);
3250 gtk_text_buffer_insert(buffer, &break_pos,
3254 compose_join_next_line(compose, buffer, &iter, quote_str);
3256 /* move iter to current line start */
3257 gtk_text_iter_set_line_offset(&iter, 0);
3260 /* move iter to next line start */
3266 while (!gtk_text_iter_ends_line(&end_of_line)) {
3267 gtk_text_iter_forward_char(&end_of_line);
3269 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3271 nouri_start = gtk_text_iter_get_offset(&iter);
3272 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3274 walk_pos = gtk_text_iter_get_offset(&iter);
3275 /* FIXME: this looks phony. scanning for anything in the parse table */
3276 for (n = 0; n < PARSE_ELEMS; n++) {
3279 tmp = parser[n].search(walk, parser[n].needle);
3281 if (scanpos == NULL || tmp < scanpos) {
3290 /* check if URI can be parsed */
3291 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,(const gchar **)&ep)
3292 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3296 strlen(parser[last_index].needle);
3299 uri_start = walk_pos + (bp - o_walk);
3300 uri_stop = walk_pos + (ep - o_walk);
3304 gtk_text_iter_forward_line(&iter);
3307 if (startq_offset != -1) {
3308 GtkTextIter startquote, endquote;
3309 gtk_text_buffer_get_iter_at_offset(
3310 buffer, &startquote, startq_offset);
3312 gtk_text_buffer_apply_tag_by_name(
3313 buffer, "quote", &startquote, &endquote);
3315 } else if (noq_offset != -1) {
3316 GtkTextIter startnoquote, endnoquote;
3317 gtk_text_buffer_get_iter_at_offset(
3318 buffer, &startnoquote, noq_offset);
3320 gtk_text_buffer_remove_tag_by_name(
3321 buffer, "quote", &startnoquote, &endnoquote);
3326 GtkTextIter nouri_start_iter, nouri_end_iter;
3327 gtk_text_buffer_get_iter_at_offset(
3328 buffer, &nouri_start_iter, nouri_start);
3329 gtk_text_buffer_get_iter_at_offset(
3330 buffer, &nouri_end_iter, nouri_stop);
3331 gtk_text_buffer_remove_tag_by_name(
3332 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3334 if (uri_start > 0 && uri_stop > 0) {
3335 GtkTextIter uri_start_iter, uri_end_iter;
3336 gtk_text_buffer_get_iter_at_offset(
3337 buffer, &uri_start_iter, uri_start);
3338 gtk_text_buffer_get_iter_at_offset(
3339 buffer, &uri_end_iter, uri_stop);
3340 gtk_text_buffer_apply_tag_by_name(
3341 buffer, "link", &uri_start_iter, &uri_end_iter);
3348 undo_unblock(compose->undostruct);
3349 compose->autowrap = prev_autowrap;
3352 static void compose_wrap_all(Compose *compose)
3354 compose_wrap_all_full(compose, FALSE);
3357 static void compose_wrap_all_full(Compose *compose, gboolean force)
3359 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3360 GtkTextBuffer *buffer;
3363 buffer = gtk_text_view_get_buffer(text);
3365 undo_block(compose->undostruct);
3367 gtk_text_buffer_get_start_iter(buffer, &iter);
3368 while (!gtk_text_iter_is_end(&iter))
3369 compose_beautify_paragraph(compose, &iter, force);
3371 undo_unblock(compose->undostruct);
3374 static void compose_set_title(Compose *compose)
3380 edited = compose->modified ? _(" [Edited]") : "";
3382 subject = gtk_editable_get_chars(
3383 GTK_EDITABLE(compose->subject_entry), 0, -1);
3385 if (subject && strlen(subject))
3386 str = g_strdup_printf(_("%s - Compose message%s"),
3388 else if (compose->account && compose->account->address)
3389 str = g_strdup_printf(_("%s - Compose message%s"),
3390 compose->account->address, edited);
3392 str = g_strdup_printf(_("Compose message%s"), edited);
3393 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3399 * compose_current_mail_account:
3401 * Find a current mail account (the currently selected account, or the
3402 * default account, if a news account is currently selected). If a
3403 * mail account cannot be found, display an error message.
3405 * Return value: Mail account, or NULL if not found.
3407 static PrefsAccount *
3408 compose_current_mail_account(void)
3412 if (cur_account && cur_account->protocol != A_NNTP)
3415 ac = account_get_default();
3416 if (!ac || ac->protocol == A_NNTP) {
3417 alertpanel_error(_("Account for sending mail is not specified.\n"
3418 "Please select a mail account before sending."));
3425 static void compose_select_account(Compose *compose, PrefsAccount *account,
3428 GtkItemFactory *ifactory;
3430 g_return_if_fail(account != NULL);
3432 compose->account = account;
3434 compose_set_title(compose);
3436 ifactory = gtk_item_factory_from_widget(compose->menubar);
3438 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3439 menu_set_active(ifactory, "/Options/Sign", TRUE);
3441 menu_set_active(ifactory, "/Options/Sign", FALSE);
3442 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3443 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3445 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3447 activate_privacy_system(compose, account, FALSE);
3449 if (!init && compose->mode != COMPOSE_REDIRECT)
3450 compose_insert_sig(compose, TRUE);
3453 gboolean compose_check_for_valid_recipient(Compose *compose) {
3454 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3455 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3456 gboolean recipient_found = FALSE;
3460 /* free to and newsgroup list */
3461 slist_free_strings(compose->to_list);
3462 g_slist_free(compose->to_list);
3463 compose->to_list = NULL;
3465 slist_free_strings(compose->newsgroup_list);
3466 g_slist_free(compose->newsgroup_list);
3467 compose->newsgroup_list = NULL;
3469 /* search header entries for to and newsgroup entries */
3470 for (list = compose->header_list; list; list = list->next) {
3473 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3474 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3476 if (entry[0] != '\0') {
3477 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3478 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3479 compose->to_list = address_list_append(compose->to_list, entry);
3480 recipient_found = TRUE;
3483 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3484 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3485 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3486 recipient_found = TRUE;
3493 return recipient_found;
3496 static gboolean compose_check_for_set_recipients(Compose *compose)
3498 if (compose->account->set_autocc && compose->account->auto_cc) {
3499 gboolean found_other = FALSE;
3501 /* search header entries for to and newsgroup entries */
3502 for (list = compose->header_list; list; list = list->next) {
3505 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3506 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3508 if (strcmp(entry, compose->account->auto_cc)
3509 || strcmp(header, (prefs_common.trans_hdr ? gettext("Cc:") : "Cc:"))) {
3519 aval = alertpanel(_("Send"),
3520 _("The only recipient is the default CC address. Send anyway?"),
3521 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3522 if (aval != G_ALERTDEFAULT)
3526 if (compose->account->set_autobcc && compose->account->auto_bcc) {
3527 gboolean found_other = FALSE;
3529 /* search header entries for to and newsgroup entries */
3530 for (list = compose->header_list; list; list = list->next) {
3533 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3534 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3536 if (strcmp(entry, compose->account->auto_cc)
3537 || strcmp(header, (prefs_common.trans_hdr ? gettext("Bcc:") : "Bcc:"))) {
3547 aval = alertpanel(_("Send"),
3548 _("The only recipient is the default BCC address. Send anyway?"),
3549 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3550 if (aval != G_ALERTDEFAULT)
3557 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3561 if (compose_check_for_valid_recipient(compose) == FALSE) {
3562 alertpanel_error(_("Recipient is not specified."));
3566 if (compose_check_for_set_recipients(compose) == FALSE) {
3570 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3571 if (*str == '\0' && check_subject == TRUE) {
3574 aval = alertpanel(_("Send"),
3575 _("Subject is empty. Send it anyway?"),
3576 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3577 if (aval != G_ALERTDEFAULT)
3584 gint compose_send(Compose *compose)
3591 compose_allow_user_actions (compose, FALSE);
3592 compose->sending = TRUE;
3594 if (compose_check_entries(compose, TRUE) == FALSE)
3597 val = compose_queue(compose, &msgnum, &folder);
3601 alertpanel_error(_("Could not queue message for sending:\n\n"
3602 "Charset conversion failed."));
3603 } else if (val == -3) {
3604 alertpanel_error(_("Could not queue message for sending:\n\n"
3605 "Signature failed."));
3606 } else if (val == -2) {
3607 alertpanel_error(_("Could not queue message for sending:\n\n%s."), strerror(errno));
3609 alertpanel_error(_("Could not queue message for sending."));
3615 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3616 compose->sending = FALSE;
3617 compose_close(compose);
3618 /* No more compose access in the normal codepath
3619 * after this point! */
3624 alertpanel_error(_("The message was queued but could not be "
3625 "sent.\nUse \"Send queued messages\" from "
3626 "the main window to retry."));
3627 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3628 compose->sending = FALSE;
3629 compose_allow_user_actions (compose, TRUE);
3634 msgpath = folder_item_fetch_msg(folder, msgnum);
3635 val = procmsg_send_message_queue(msgpath);
3638 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3639 compose->sending = FALSE;
3640 compose_allow_user_actions (compose, TRUE);
3642 folder_item_remove_msg(folder, msgnum);
3643 folder_item_scan(folder);
3648 folder_item_remove_msg(folder, msgnum);
3649 folder_item_scan(folder);
3650 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3651 compose_close(compose);
3653 alertpanel_error(_("The message was queued but could not be "
3654 "sent.\nUse \"Send queued messages\" from "
3655 "the main window to retry."));
3656 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3657 compose_allow_user_actions (compose, TRUE);
3658 compose->sending = FALSE;
3666 compose_allow_user_actions (compose, TRUE);
3667 compose->sending = FALSE;
3672 static gboolean compose_use_attach(Compose *compose)
3674 GtkTreeModel *model = gtk_tree_view_get_model
3675 (GTK_TREE_VIEW(compose->attach_clist));
3676 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3679 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3682 gchar buf[BUFFSIZE];
3684 gboolean first_to_address;
3685 gboolean first_cc_address;
3687 ComposeHeaderEntry *headerentry;
3688 const gchar *headerentryname;
3692 debug_print("Writing redirect header\n");
3694 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3695 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3697 first_to_address = TRUE;
3698 for (list = compose->header_list; list; list = list->next) {
3699 headerentry = ((ComposeHeaderEntry *)list->data);
3700 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3702 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3703 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3704 Xstrdup_a(str, entstr, return -1);
3706 if (str[0] != '\0') {
3707 compose_convert_header
3708 (compose, buf, sizeof(buf), str,
3709 strlen("Resent-To") + 2, TRUE);
3711 if (first_to_address) {
3712 fprintf(fp, "Resent-To: ");
3713 first_to_address = FALSE;
3717 fprintf(fp, "%s", buf);
3721 if (!first_to_address) {
3725 first_cc_address = TRUE;
3726 for (list = compose->header_list; list; list = list->next) {
3727 headerentry = ((ComposeHeaderEntry *)list->data);
3728 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3730 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3731 const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3732 Xstrdup_a(str, strg, return -1);
3734 if (str[0] != '\0') {
3735 compose_convert_header
3736 (compose, buf, sizeof(buf), str,
3737 strlen("Resent-Cc") + 2, TRUE);
3739 if (first_cc_address) {
3740 fprintf(fp, "Resent-Cc: ");
3741 first_cc_address = FALSE;
3745 fprintf(fp, "%s", buf);
3749 if (!first_cc_address) {