2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #ifndef PANGO_ENABLE_ENGINE
27 # define PANGO_ENABLE_ENGINE
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtkmain.h>
34 #include <gtk/gtkmenu.h>
35 #include <gtk/gtkmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkcheckmenuitem.h>
38 #include <gtk/gtkoptionmenu.h>
39 #include <gtk/gtkwidget.h>
40 #include <gtk/gtkvpaned.h>
41 #include <gtk/gtkentry.h>
42 #include <gtk/gtkeditable.h>
43 #include <gtk/gtkwindow.h>
44 #include <gtk/gtksignal.h>
45 #include <gtk/gtkvbox.h>
46 #include <gtk/gtkcontainer.h>
47 #include <gtk/gtkhandlebox.h>
48 #include <gtk/gtktoolbar.h>
49 #include <gtk/gtktable.h>
50 #include <gtk/gtkhbox.h>
51 #include <gtk/gtklabel.h>
52 #include <gtk/gtkscrolledwindow.h>
53 #include <gtk/gtktreeview.h>
54 #include <gtk/gtkliststore.h>
55 #include <gtk/gtktreeselection.h>
56 #include <gtk/gtktreemodel.h>
58 #include <gtk/gtkdnd.h>
59 #include <gtk/gtkclipboard.h>
60 #include <pango/pango-break.h>
65 #include <sys/types.h>
71 # include <sys/wait.h>
75 #ifndef G_OS_WIN32 /* fixme we should have a configure test. */
79 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
86 #include "mainwindow.h"
88 #include "addressbook.h"
89 #include "folderview.h"
92 #include "stock_pixmap.h"
93 #include "send_message.h"
96 #include "customheader.h"
97 #include "prefs_common.h"
98 #include "prefs_account.h"
102 #include "procheader.h"
103 #include "procmime.h"
104 #include "statusbar.h"
107 #include "quoted-printable.h"
108 #include "codeconv.h"
110 #include "gtkutils.h"
112 #include "alertpanel.h"
113 #include "manage_window.h"
114 #include "gtkshruler.h"
116 #include "addr_compl.h"
117 #include "quote_fmt.h"
119 #include "foldersel.h"
122 #include "message_search.h"
134 #define N_ATTACH_COLS (N_COL_COLUMNS)
138 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
143 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
144 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
145 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
146 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
150 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
151 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
152 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
153 } ComposeCallAdvancedAction;
157 PRIORITY_HIGHEST = 1,
166 COMPOSE_INSERT_SUCCESS,
167 COMPOSE_INSERT_READ_ERROR,
168 COMPOSE_INSERT_INVALID_CHARACTER,
169 COMPOSE_INSERT_NO_FILE
170 } ComposeInsertResult;
174 COMPOSE_QUIT_EDITING,
175 COMPOSE_KEEP_EDITING,
177 } ComposeDraftAction;
181 COMPOSE_WRITE_FOR_SEND,
182 COMPOSE_WRITE_FOR_STORE
185 #define B64_LINE_SIZE 57
186 #define B64_BUFFSIZE 77
188 #define MAX_REFERENCES_LEN 999
190 static GList *compose_list = NULL;
192 Compose *compose_generic_new (PrefsAccount *account,
195 GPtrArray *attach_files,
196 GList *listAddress );
198 static Compose *compose_create (PrefsAccount *account,
202 static GtkWidget *compose_account_option_menu_create
204 static void compose_set_out_encoding (Compose *compose);
205 static void compose_set_template_menu (Compose *compose);
206 static void compose_template_apply (Compose *compose,
209 static void compose_destroy (Compose *compose);
211 static void compose_entries_set (Compose *compose,
212 const gchar *mailto);
213 static gint compose_parse_header (Compose *compose,
215 static gchar *compose_parse_references (const gchar *ref,
218 static gchar *compose_quote_fmt (Compose *compose,
225 static void compose_reply_set_entry (Compose *compose,
231 followup_and_reply_to);
232 static void compose_reedit_set_entry (Compose *compose,
235 static void compose_insert_sig (Compose *compose,
237 static gchar *compose_get_signature_str (Compose *compose);
238 static ComposeInsertResult compose_insert_file (Compose *compose,
241 static void compose_attach_append (Compose *compose,
244 const gchar *content_type);
245 static void compose_attach_parts (Compose *compose,
248 static void compose_beautify_paragraph (Compose *compose,
249 GtkTextIter *par_iter,
251 static void compose_wrap_all (Compose *compose);
252 static void compose_wrap_all_full (Compose *compose,
255 static void compose_set_title (Compose *compose);
256 static void compose_select_account (Compose *compose,
257 PrefsAccount *account,
260 static PrefsAccount *compose_current_mail_account(void);
261 /* static gint compose_send (Compose *compose); */
262 static gboolean compose_check_for_valid_recipient
264 static gboolean compose_check_entries (Compose *compose,
265 gboolean check_subject);
266 static gint compose_write_to_file (Compose *compose,
269 gboolean attach_parts);
270 static gint compose_write_body_to_file (Compose *compose,
272 static gint compose_remove_reedit_target (Compose *compose,
274 void compose_remove_draft (Compose *compose);
275 static gint compose_queue_sub (Compose *compose,
279 gboolean check_subject,
280 gboolean remove_reedit_target);
281 static void compose_add_attachments (Compose *compose,
283 static gchar *compose_get_header (Compose *compose);
285 static void compose_convert_header (Compose *compose,
290 gboolean addr_field);
292 static void compose_attach_info_free (AttachInfo *ainfo);
293 static void compose_attach_remove_selected (Compose *compose);
295 static void compose_attach_property (Compose *compose);
296 static void compose_attach_property_create (gboolean *cancelled);
297 static void attach_property_ok (GtkWidget *widget,
298 gboolean *cancelled);
299 static void attach_property_cancel (GtkWidget *widget,
300 gboolean *cancelled);
301 static gint attach_property_delete_event (GtkWidget *widget,
303 gboolean *cancelled);
304 static gboolean attach_property_key_pressed (GtkWidget *widget,
306 gboolean *cancelled);
308 static void compose_exec_ext_editor (Compose *compose);
310 static gint compose_exec_ext_editor_real (const gchar *file);
311 static gboolean compose_ext_editor_kill (Compose *compose);
312 static gboolean compose_input_cb (GIOChannel *source,
313 GIOCondition condition,
315 static void compose_set_ext_editor_sensitive (Compose *compose,
317 #endif /* G_OS_UNIX */
319 static void compose_undo_state_changed (UndoMain *undostruct,
324 static void compose_create_header_entry (Compose *compose);
325 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
326 static void compose_update_priority_menu_item(Compose * compose);
328 static void compose_add_field_list ( Compose *compose,
329 GList *listAddress );
331 /* callback functions */
333 static gboolean compose_edit_size_alloc (GtkEditable *widget,
334 GtkAllocation *allocation,
335 GtkSHRuler *shruler);
336 static void account_activated (GtkMenuItem *menuitem,
338 static void attach_selected (GtkTreeView *tree_view,
339 GtkTreePath *tree_path,
340 GtkTreeViewColumn *column,
342 static gboolean attach_button_pressed (GtkWidget *widget,
343 GdkEventButton *event,
345 static gboolean attach_key_pressed (GtkWidget *widget,
349 static void compose_send_cb (gpointer data,
352 static void compose_send_later_cb (gpointer data,
356 static void compose_draft_cb (gpointer data,
360 static void compose_attach_cb (gpointer data,
363 static void compose_insert_file_cb (gpointer data,
366 static void compose_insert_sig_cb (gpointer data,
370 static void compose_close_cb (gpointer data,
374 static void compose_set_encoding_cb (gpointer data,
378 static void compose_address_cb (gpointer data,
381 static void compose_template_activate_cb(GtkWidget *widget,
384 static void compose_ext_editor_cb (gpointer data,
388 static gint compose_delete_cb (GtkWidget *widget,
392 static void compose_undo_cb (Compose *compose);
393 static void compose_redo_cb (Compose *compose);
394 static void compose_cut_cb (Compose *compose);
395 static void compose_copy_cb (Compose *compose);
396 static void compose_paste_cb (Compose *compose);
397 static void compose_paste_as_quote_cb (Compose *compose);
398 static void compose_paste_no_wrap_cb (Compose *compose);
399 static void compose_paste_wrap_cb (Compose *compose);
400 static void compose_allsel_cb (Compose *compose);
402 static void compose_advanced_action_cb (Compose *compose,
403 ComposeCallAdvancedAction action);
405 static void compose_grab_focus_cb (GtkWidget *widget,
408 static void compose_changed_cb (GtkTextBuffer *textbuf,
411 static void compose_wrap_cb (gpointer data,
414 static void compose_find_cb (gpointer data,
417 static void compose_toggle_autowrap_cb (gpointer data,
421 static void compose_toggle_ruler_cb (gpointer data,
424 static void compose_toggle_sign_cb (gpointer data,
427 static void compose_toggle_encrypt_cb (gpointer data,
430 static void compose_set_privacy_system_cb(GtkWidget *widget,
432 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
433 static void activate_privacy_system (Compose *compose,
434 PrefsAccount *account,
436 static void compose_use_signing(Compose *compose, gboolean use_signing);
437 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
438 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
440 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
442 static void compose_set_priority_cb (gpointer data,
446 static void compose_attach_drag_received_cb (GtkWidget *widget,
447 GdkDragContext *drag_context,
450 GtkSelectionData *data,
454 static void compose_insert_drag_received_cb (GtkWidget *widget,
455 GdkDragContext *drag_context,
458 GtkSelectionData *data,
462 static void compose_header_drag_received_cb (GtkWidget *widget,
463 GdkDragContext *drag_context,
466 GtkSelectionData *data,
471 static gboolean compose_drag_drop (GtkWidget *widget,
472 GdkDragContext *drag_context,
474 guint time, gpointer user_data);
476 static void text_inserted (GtkTextBuffer *buffer,
481 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
482 gboolean to_all, gboolean to_ml,
484 gboolean followup_and_reply_to,
487 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
488 ComposeHeaderEntry *headerentry);
489 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
491 ComposeHeaderEntry *headerentry);
493 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
495 static void compose_allow_user_actions (Compose *compose, gboolean allow);
498 static void compose_check_all (Compose *compose);
499 static void compose_highlight_all (Compose *compose);
500 static void compose_check_backwards (Compose *compose);
501 static void compose_check_forwards_go (Compose *compose);
504 static gint compose_defer_auto_save_draft (Compose *compose);
505 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
507 static GtkItemFactoryEntry compose_popup_entries[] =
509 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
510 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
511 {N_("/---"), NULL, NULL, 0, "<Separator>"},
512 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
515 static GtkItemFactoryEntry compose_entries[] =
517 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
518 {N_("/_Message/_Send"), "<control>Return",
519 compose_send_cb, 0, NULL},
520 {N_("/_Message/Send _later"), "<shift><control>S",
521 compose_send_later_cb, 0, NULL},
522 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
523 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
524 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
525 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
526 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
527 {N_("/_Message/_Save"),
528 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
529 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
530 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
532 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
533 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
534 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
535 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
536 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
537 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
538 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
539 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
540 {N_("/_Edit/Special paste/as _quotation"),
541 NULL, compose_paste_as_quote_cb, 0, NULL},
542 {N_("/_Edit/Special paste/_wrapped"),
543 NULL, compose_paste_wrap_cb, 0, NULL},
544 {N_("/_Edit/Special paste/_unwrapped"),
545 NULL, compose_paste_no_wrap_cb, 0, NULL},
546 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
547 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
548 {N_("/_Edit/A_dvanced/Move a character backward"),
550 compose_advanced_action_cb,
551 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
553 {N_("/_Edit/A_dvanced/Move a character forward"),
555 compose_advanced_action_cb,
556 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
558 {N_("/_Edit/A_dvanced/Move a word backward"),
560 compose_advanced_action_cb,
561 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
563 {N_("/_Edit/A_dvanced/Move a word forward"),
565 compose_advanced_action_cb,
566 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
568 {N_("/_Edit/A_dvanced/Move to beginning of line"),
569 NULL, /* "<control>A" */
570 compose_advanced_action_cb,
571 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
573 {N_("/_Edit/A_dvanced/Move to end of line"),
575 compose_advanced_action_cb,
576 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
578 {N_("/_Edit/A_dvanced/Move to previous line"),
580 compose_advanced_action_cb,
581 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
583 {N_("/_Edit/A_dvanced/Move to next line"),
585 compose_advanced_action_cb,
586 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
588 {N_("/_Edit/A_dvanced/Delete a character backward"),
590 compose_advanced_action_cb,
591 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
593 {N_("/_Edit/A_dvanced/Delete a character forward"),
595 compose_advanced_action_cb,
596 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
598 {N_("/_Edit/A_dvanced/Delete a word backward"),
599 NULL, /* "<control>W" */
600 compose_advanced_action_cb,
601 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
603 {N_("/_Edit/A_dvanced/Delete a word forward"),
604 NULL, /* "<alt>D", */
605 compose_advanced_action_cb,
606 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
608 {N_("/_Edit/A_dvanced/Delete line"),
610 compose_advanced_action_cb,
611 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
613 {N_("/_Edit/A_dvanced/Delete entire line"),
615 compose_advanced_action_cb,
616 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
618 {N_("/_Edit/A_dvanced/Delete to end of line"),
620 compose_advanced_action_cb,
621 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
623 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
625 "<control>F", compose_find_cb, 0, NULL},
626 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
627 {N_("/_Edit/_Wrap current paragraph"),
628 "<control>L", compose_wrap_cb, 0, NULL},
629 {N_("/_Edit/Wrap all long _lines"),
630 "<control><alt>L", compose_wrap_cb, 1, NULL},
631 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
632 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
633 {N_("/_Edit/Edit with e_xternal editor"),
634 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
636 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
637 {N_("/_Spelling/_Check all or check selection"),
638 NULL, compose_check_all, 0, NULL},
639 {N_("/_Spelling/_Highlight all misspelled words"),
640 NULL, compose_highlight_all, 0, NULL},
641 {N_("/_Spelling/Check _backwards misspelled word"),
642 NULL, compose_check_backwards , 0, NULL},
643 {N_("/_Spelling/_Forward to next misspelled word"),
644 NULL, compose_check_forwards_go, 0, NULL},
645 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
646 {N_("/_Spelling/Options"),
647 NULL, NULL, 0, "<Branch>"},
649 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
650 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
651 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
652 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
653 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
654 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
655 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
656 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
657 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
658 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
659 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
660 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
661 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
662 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
663 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
664 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
665 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
667 #define ENC_ACTION(action) \
668 NULL, compose_set_encoding_cb, action, \
669 "/Options/Character encoding/Automatic"
671 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
672 {N_("/_Options/Character _encoding/_Automatic"),
673 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
674 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
676 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
677 ENC_ACTION(C_US_ASCII)},
678 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
679 ENC_ACTION(C_UTF_8)},
680 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
682 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
683 ENC_ACTION(C_ISO_8859_1)},
684 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
685 ENC_ACTION(C_ISO_8859_15)},
686 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
687 ENC_ACTION(C_WINDOWS_1252)},
688 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
690 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
691 ENC_ACTION(C_ISO_8859_2)},
692 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
694 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
695 ENC_ACTION(C_ISO_8859_13)},
696 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
697 ENC_ACTION(C_ISO_8859_4)},
698 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
700 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
701 ENC_ACTION(C_ISO_8859_7)},
702 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
704 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
705 ENC_ACTION(C_ISO_8859_8)},
706 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
707 ENC_ACTION(C_WINDOWS_1255)},
708 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
710 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
711 ENC_ACTION(C_ISO_8859_6)},
712 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
713 ENC_ACTION(C_CP1256)},
714 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
716 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
717 ENC_ACTION(C_ISO_8859_9)},
718 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
720 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
721 ENC_ACTION(C_ISO_8859_5)},
722 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
723 ENC_ACTION(C_KOI8_R)},
724 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
725 ENC_ACTION(C_KOI8_U)},
726 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
727 ENC_ACTION(C_WINDOWS_1251)},
728 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
730 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
731 ENC_ACTION(C_ISO_2022_JP)},
732 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
734 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
735 ENC_ACTION(C_GB2312)},
736 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
738 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
740 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
741 ENC_ACTION(C_EUC_TW)},
742 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
744 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
745 ENC_ACTION(C_EUC_KR)},
746 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
748 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
749 ENC_ACTION(C_TIS_620)},
750 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
751 ENC_ACTION(C_WINDOWS_874)},
753 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
754 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
755 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
756 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
757 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
758 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
759 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
762 static GtkTargetEntry compose_mime_types[] =
764 {"text/uri-list", 0, 0},
765 {"text/plain", 0, 0},
769 static gboolean compose_put_existing_to_front(MsgInfo *info)
771 GList *compose_list = compose_get_compose_list();
775 for (elem = compose_list; elem != NULL && elem->data != NULL;
777 Compose *c = (Compose*)elem->data;
779 if (!c->targetinfo || !c->targetinfo->msgid ||
783 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
784 gtkut_window_popup(c->window);
792 static GdkColor quote_color1 =
793 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
794 static GdkColor quote_color2 =
795 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
796 static GdkColor quote_color3 =
797 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
799 static GdkColor quote_bgcolor1 =
800 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
801 static GdkColor quote_bgcolor2 =
802 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
803 static GdkColor quote_bgcolor3 =
804 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
806 static GdkColor signature_color = {
813 static GdkColor uri_color = {
820 static void compose_create_tags(GtkTextView *text, Compose *compose)
822 GtkTextBuffer *buffer;
823 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
829 buffer = gtk_text_view_get_buffer(text);
831 if (prefs_common.enable_color) {
832 /* grab the quote colors, converting from an int to a GdkColor */
833 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
835 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
837 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
839 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
841 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
843 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
845 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
847 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
850 signature_color = quote_color1 = quote_color2 = quote_color3 =
851 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black;
854 if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
855 gtk_text_buffer_create_tag(buffer, "quote0",
856 "foreground-gdk", "e_color1,
857 "paragraph-background-gdk", "e_bgcolor1,
859 gtk_text_buffer_create_tag(buffer, "quote1",
860 "foreground-gdk", "e_color2,
861 "paragraph-background-gdk", "e_bgcolor2,
863 gtk_text_buffer_create_tag(buffer, "quote2",
864 "foreground-gdk", "e_color3,
865 "paragraph-background-gdk", "e_bgcolor3,
868 gtk_text_buffer_create_tag(buffer, "quote0",
869 "foreground-gdk", "e_color1,
871 gtk_text_buffer_create_tag(buffer, "quote1",
872 "foreground-gdk", "e_color2,
874 gtk_text_buffer_create_tag(buffer, "quote2",
875 "foreground-gdk", "e_color3,
879 gtk_text_buffer_create_tag(buffer, "signature",
880 "foreground-gdk", &signature_color,
882 gtk_text_buffer_create_tag(buffer, "link",
883 "foreground-gdk", &uri_color,
885 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
886 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
888 color[0] = quote_color1;
889 color[1] = quote_color2;
890 color[2] = quote_color3;
891 color[3] = quote_bgcolor1;
892 color[4] = quote_bgcolor2;
893 color[5] = quote_bgcolor3;
894 color[6] = signature_color;
895 color[7] = uri_color;
896 cmap = gdk_drawable_get_colormap(compose->window->window);
897 gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
899 for (i = 0; i < 8; i++) {
900 if (success[i] == FALSE) {
903 g_warning("Compose: color allocation failed.\n");
904 style = gtk_widget_get_style(GTK_WIDGET(text));
905 quote_color1 = quote_color2 = quote_color3 =
906 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 =
907 signature_color = uri_color = black;
912 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
913 GPtrArray *attach_files)
915 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
918 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
920 return compose_generic_new(account, NULL, item, NULL, NULL);
923 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
925 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
928 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
929 GPtrArray *attach_files, GList *listAddress )
932 GtkTextView *textview;
933 GtkTextBuffer *textbuf;
935 GtkItemFactory *ifactory;
937 if (item && item->prefs && item->prefs->enable_default_account)
938 account = account_find_from_id(item->prefs->default_account);
940 if (!account) account = cur_account;
941 g_return_val_if_fail(account != NULL, NULL);
943 compose = compose_create(account, COMPOSE_NEW, FALSE);
945 ifactory = gtk_item_factory_from_widget(compose->menubar);
947 compose->replyinfo = NULL;
948 compose->fwdinfo = NULL;
950 textview = GTK_TEXT_VIEW(compose->text);
951 textbuf = gtk_text_view_get_buffer(textview);
952 compose_create_tags(textview, compose);
954 undo_block(compose->undostruct);
956 if (item && item->prefs && item->prefs->enable_default_dictionary &&
958 gtkaspell_change_dict(compose->gtkaspell,
959 item->prefs->default_dictionary);
962 if (account->auto_sig)
963 compose_insert_sig(compose, FALSE);
964 gtk_text_buffer_get_start_iter(textbuf, &iter);
965 gtk_text_buffer_place_cursor(textbuf, &iter);
967 if (account->protocol != A_NNTP) {
968 if (mailto && *mailto != '\0') {
969 compose_entries_set(compose, mailto);
971 } else if (item && item->prefs->enable_default_to) {
972 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
973 compose_entry_mark_default_to(compose, item->prefs->default_to);
975 if (item && item->ret_rcpt) {
976 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
980 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
982 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
985 * CLAWS: just don't allow return receipt request, even if the user
986 * may want to send an email. simple but foolproof.
988 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
990 compose_add_field_list( compose, listAddress );
996 for (i = 0; i < attach_files->len; i++) {
997 file = g_ptr_array_index(attach_files, i);
998 compose_attach_append(compose, file, file, NULL);
1002 compose_show_first_last_header(compose, TRUE);
1004 /* Set save folder */
1005 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1006 gchar *folderidentifier;
1008 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1009 folderidentifier = folder_item_get_identifier(item);
1010 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1011 g_free(folderidentifier);
1014 gtk_widget_grab_focus(compose->header_last->entry);
1016 undo_unblock(compose->undostruct);
1018 if (prefs_common.auto_exteditor)
1019 compose_exec_ext_editor(compose);
1021 compose->modified = FALSE;
1022 compose_set_title(compose);
1026 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1027 gboolean override_pref)
1029 gchar *privacy = NULL;
1031 g_return_if_fail(compose != NULL);
1032 g_return_if_fail(account != NULL);
1034 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1037 if (account->default_privacy_system
1038 && strlen(account->default_privacy_system)) {
1039 privacy = account->default_privacy_system;
1041 GSList *privacy_avail = privacy_get_system_ids();
1042 if (privacy_avail && g_slist_length(privacy_avail)) {
1043 privacy = (gchar *)(privacy_avail->data);
1046 if (privacy != NULL) {
1047 compose->privacy_system = g_strdup(privacy);
1048 compose_update_privacy_system_menu_item(compose, FALSE);
1049 compose_use_encryption(compose, TRUE);
1053 static void compose_force_signing(Compose *compose, PrefsAccount *account)
1055 gchar *privacy = NULL;
1057 if (account->default_privacy_system
1058 && strlen(account->default_privacy_system)) {
1059 privacy = account->default_privacy_system;
1061 GSList *privacy_avail = privacy_get_system_ids();
1062 if (privacy_avail && g_slist_length(privacy_avail)) {
1063 privacy = (gchar *)(privacy_avail->data);
1066 if (privacy != NULL) {
1067 compose->privacy_system = g_strdup(privacy);
1068 compose_update_privacy_system_menu_item(compose, FALSE);
1069 compose_use_signing(compose, TRUE);
1073 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1077 Compose *compose = NULL;
1078 g_return_val_if_fail(msginfo_list != NULL, NULL);
1080 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1081 g_return_val_if_fail(msginfo != NULL, NULL);
1083 list_len = g_slist_length(msginfo_list);
1087 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1088 FALSE, prefs_common.default_reply_list, FALSE, body);
1090 case COMPOSE_REPLY_WITH_QUOTE:
1091 compose = compose_reply(msginfo, TRUE,
1092 FALSE, prefs_common.default_reply_list, FALSE, body);
1094 case COMPOSE_REPLY_WITHOUT_QUOTE:
1095 compose = compose_reply(msginfo, FALSE,
1096 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1098 case COMPOSE_REPLY_TO_SENDER:
1099 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1100 FALSE, FALSE, TRUE, body);
1102 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1103 compose = compose_followup_and_reply_to(msginfo,
1104 prefs_common.reply_with_quote,
1105 FALSE, FALSE, body);
1107 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1108 compose = compose_reply(msginfo, TRUE,
1109 FALSE, FALSE, TRUE, body);
1111 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1112 compose = compose_reply(msginfo, FALSE,
1113 FALSE, FALSE, TRUE, NULL);
1115 case COMPOSE_REPLY_TO_ALL:
1116 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1117 TRUE, FALSE, FALSE, body);
1119 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1120 compose = compose_reply(msginfo, TRUE,
1121 TRUE, FALSE, FALSE, body);
1123 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1124 compose = compose_reply(msginfo, FALSE,
1125 TRUE, FALSE, FALSE, NULL);
1127 case COMPOSE_REPLY_TO_LIST:
1128 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1129 FALSE, TRUE, FALSE, body);
1131 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1132 compose = compose_reply(msginfo, TRUE,
1133 FALSE, TRUE, FALSE, body);
1135 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1136 compose = compose_reply(msginfo, FALSE,
1137 FALSE, TRUE, FALSE, NULL);
1139 case COMPOSE_FORWARD:
1140 if (prefs_common.forward_as_attachment) {
1141 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1144 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1148 case COMPOSE_FORWARD_INLINE:
1149 /* check if we reply to more than one Message */
1150 if (list_len == 1) {
1151 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1154 /* more messages FALL THROUGH */
1155 case COMPOSE_FORWARD_AS_ATTACH:
1156 compose = compose_forward_multiple(NULL, msginfo_list);
1158 case COMPOSE_REDIRECT:
1159 compose = compose_redirect(NULL, msginfo, FALSE);
1162 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1167 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1168 gboolean to_ml, gboolean to_sender,
1171 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1172 to_sender, FALSE, body);
1175 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1180 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1181 to_sender, TRUE, body);
1184 static void compose_extract_original_charset(Compose *compose)
1186 MsgInfo *info = NULL;
1187 if (compose->replyinfo) {
1188 info = compose->replyinfo;
1189 } else if (compose->fwdinfo) {
1190 info = compose->fwdinfo;
1191 } else if (compose->targetinfo) {
1192 info = compose->targetinfo;
1195 MimeInfo *mimeinfo = procmime_scan_message(info);
1196 MimeInfo *partinfo = mimeinfo;
1197 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1198 partinfo = procmime_mimeinfo_next(partinfo);
1200 compose->orig_charset =
1201 g_strdup(procmime_mimeinfo_get_parameter(
1202 partinfo, "charset"));
1204 procmime_mimeinfo_free_all(mimeinfo);
1208 #define SIGNAL_BLOCK(buffer) { \
1209 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1210 G_CALLBACK(compose_changed_cb), \
1212 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1213 G_CALLBACK(text_inserted), \
1217 #define SIGNAL_UNBLOCK(buffer) { \
1218 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1219 G_CALLBACK(compose_changed_cb), \
1221 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1222 G_CALLBACK(text_inserted), \
1226 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1227 gboolean to_all, gboolean to_ml,
1229 gboolean followup_and_reply_to,
1232 GtkItemFactory *ifactory;
1234 PrefsAccount *account = NULL;
1235 PrefsAccount *reply_account;
1236 GtkTextView *textview;
1237 GtkTextBuffer *textbuf;
1239 g_return_val_if_fail(msginfo != NULL, NULL);
1240 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1242 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1244 g_return_val_if_fail(account != NULL, NULL);
1246 if (to_sender && account->protocol == A_NNTP &&
1247 !followup_and_reply_to) {
1249 account_find_from_address(account->address);
1251 reply_account = compose_current_mail_account();
1255 reply_account = account;
1257 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1259 compose->updating = TRUE;
1261 ifactory = gtk_item_factory_from_widget(compose->menubar);
1263 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1264 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1266 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1267 if (!compose->replyinfo)
1268 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1270 compose_extract_original_charset(compose);
1272 if (msginfo->folder && msginfo->folder->ret_rcpt)
1273 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1275 /* Set save folder */
1276 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1277 gchar *folderidentifier;
1279 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1280 folderidentifier = folder_item_get_identifier(msginfo->folder);
1281 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1282 g_free(folderidentifier);
1285 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1286 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1287 to_sender, followup_and_reply_to);
1288 compose_show_first_last_header(compose, TRUE);
1290 textview = (GTK_TEXT_VIEW(compose->text));
1291 textbuf = gtk_text_view_get_buffer(textview);
1292 compose_create_tags(textview, compose);
1294 undo_block(compose->undostruct);
1296 if (msginfo->folder && msginfo->folder->prefs &&
1297 msginfo->folder->prefs &&
1298 msginfo->folder->prefs->enable_default_dictionary &&
1300 gtkaspell_change_dict(compose->gtkaspell,
1301 msginfo->folder->prefs->default_dictionary);
1307 if (prefs_common.quotemark && *prefs_common.quotemark)
1308 qmark = prefs_common.quotemark;
1312 compose_quote_fmt(compose, compose->replyinfo,
1313 prefs_common.quotefmt,
1314 qmark, body, FALSE);
1316 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1317 compose_force_encryption(compose, account, FALSE);
1320 SIGNAL_BLOCK(textbuf);
1322 if (account->auto_sig)
1323 compose_insert_sig(compose, FALSE);
1325 compose_wrap_all(compose);
1327 SIGNAL_UNBLOCK(textbuf);
1329 gtk_widget_grab_focus(compose->text);
1331 undo_unblock(compose->undostruct);
1333 if (prefs_common.auto_exteditor)
1334 compose_exec_ext_editor(compose);
1336 compose->modified = FALSE;
1337 compose_set_title(compose);
1339 compose->updating = FALSE;
1341 if (compose->deferred_destroy) {
1342 compose_destroy(compose);
1349 #define INSERT_FW_HEADER(var, hdr) \
1350 if (msginfo->var && *msginfo->var) { \
1351 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1352 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1353 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1356 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1357 gboolean as_attach, const gchar *body,
1358 gboolean no_extedit,
1362 GtkTextView *textview;
1363 GtkTextBuffer *textbuf;
1366 g_return_val_if_fail(msginfo != NULL, NULL);
1367 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1370 !(account = compose_guess_forward_account_from_msginfo
1372 account = cur_account;
1374 compose = compose_create(account, COMPOSE_FORWARD, batch);
1376 compose->updating = TRUE;
1377 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1378 if (!compose->fwdinfo)
1379 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1381 compose_extract_original_charset(compose);
1383 if (msginfo->subject && *msginfo->subject) {
1384 gchar *buf, *buf2, *p;
1386 buf = p = g_strdup(msginfo->subject);
1387 p += subject_get_prefix_length(p);
1388 memmove(buf, p, strlen(p) + 1);
1390 buf2 = g_strdup_printf("Fw: %s", buf);
1391 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1397 textview = GTK_TEXT_VIEW(compose->text);
1398 textbuf = gtk_text_view_get_buffer(textview);
1399 compose_create_tags(textview, compose);
1401 undo_block(compose->undostruct);
1405 msgfile = procmsg_get_message_file_path(msginfo);
1406 if (!is_file_exist(msgfile))
1407 g_warning("%s: file not exist\n", msgfile);
1409 compose_attach_append(compose, msgfile, msgfile,
1415 MsgInfo *full_msginfo;
1417 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1419 full_msginfo = procmsg_msginfo_copy(msginfo);
1421 if (prefs_common.fw_quotemark &&
1422 *prefs_common.fw_quotemark)
1423 qmark = prefs_common.fw_quotemark;
1427 compose_quote_fmt(compose, full_msginfo,
1428 prefs_common.fw_quotefmt,
1429 qmark, body, FALSE);
1430 compose_attach_parts(compose, msginfo);
1432 procmsg_msginfo_free(full_msginfo);
1435 SIGNAL_BLOCK(textbuf);
1437 if (account->auto_sig)
1438 compose_insert_sig(compose, FALSE);
1440 compose_wrap_all(compose);
1442 SIGNAL_UNBLOCK(textbuf);
1444 gtk_text_buffer_get_start_iter(textbuf, &iter);
1445 gtk_text_buffer_place_cursor(textbuf, &iter);
1447 gtk_widget_grab_focus(compose->header_last->entry);
1449 if (!no_extedit && prefs_common.auto_exteditor)
1450 compose_exec_ext_editor(compose);
1453 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1454 gchar *folderidentifier;
1456 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1457 folderidentifier = folder_item_get_identifier(msginfo->folder);
1458 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1459 g_free(folderidentifier);
1462 undo_unblock(compose->undostruct);
1464 compose->modified = FALSE;
1465 compose_set_title(compose);
1467 compose->updating = FALSE;
1469 if (compose->deferred_destroy) {
1470 compose_destroy(compose);
1477 #undef INSERT_FW_HEADER
1479 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1482 GtkTextView *textview;
1483 GtkTextBuffer *textbuf;
1487 gboolean single_mail = TRUE;
1489 g_return_val_if_fail(msginfo_list != NULL, NULL);
1491 if (g_slist_length(msginfo_list) > 1)
1492 single_mail = FALSE;
1494 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1495 if (((MsgInfo *)msginfo->data)->folder == NULL)
1498 /* guess account from first selected message */
1500 !(account = compose_guess_forward_account_from_msginfo
1501 (msginfo_list->data)))
1502 account = cur_account;
1504 g_return_val_if_fail(account != NULL, NULL);
1506 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1507 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1508 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1511 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1513 compose->updating = TRUE;
1515 textview = GTK_TEXT_VIEW(compose->text);
1516 textbuf = gtk_text_view_get_buffer(textview);
1517 compose_create_tags(textview, compose);
1519 undo_block(compose->undostruct);
1520 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1521 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1523 if (!is_file_exist(msgfile))
1524 g_warning("%s: file not exist\n", msgfile);
1526 compose_attach_append(compose, msgfile, msgfile,
1532 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1533 if (info->subject && *info->subject) {
1534 gchar *buf, *buf2, *p;
1536 buf = p = g_strdup(info->subject);
1537 p += subject_get_prefix_length(p);
1538 memmove(buf, p, strlen(p) + 1);
1540 buf2 = g_strdup_printf("Fw: %s", buf);
1541 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1547 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1548 _("Fw: multiple emails"));
1551 SIGNAL_BLOCK(textbuf);
1553 if (account->auto_sig)
1554 compose_insert_sig(compose, FALSE);
1556 compose_wrap_all(compose);
1558 SIGNAL_UNBLOCK(textbuf);
1560 gtk_text_buffer_get_start_iter(textbuf, &iter);
1561 gtk_text_buffer_place_cursor(textbuf, &iter);
1563 gtk_widget_grab_focus(compose->header_last->entry);
1564 undo_unblock(compose->undostruct);
1565 compose->modified = FALSE;
1566 compose_set_title(compose);
1568 compose->updating = FALSE;
1570 if (compose->deferred_destroy) {
1571 compose_destroy(compose);
1578 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1580 GtkTextIter start = *iter;
1581 GtkTextIter end_iter;
1582 int start_pos = gtk_text_iter_get_offset(&start);
1584 if (!compose->account->sig_sep)
1587 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1588 start_pos+strlen(compose->account->sig_sep));
1590 /* check sig separator */
1591 str = gtk_text_iter_get_text(&start, &end_iter);
1592 if (!strcmp(str, compose->account->sig_sep)) {
1594 /* check end of line (\n) */
1595 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1596 start_pos+strlen(compose->account->sig_sep));
1597 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1598 start_pos+strlen(compose->account->sig_sep)+1);
1599 tmp = gtk_text_iter_get_text(&start, &end_iter);
1600 if (!strcmp(tmp,"\n")) {
1612 static void compose_colorize_signature(Compose *compose)
1614 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1616 GtkTextIter end_iter;
1617 gtk_text_buffer_get_start_iter(buffer, &iter);
1618 while (gtk_text_iter_forward_line(&iter))
1619 if (compose_is_sig_separator(compose, buffer, &iter)) {
1620 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1621 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1625 Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
1627 Compose *compose = NULL;
1628 PrefsAccount *account = NULL;
1629 GtkTextView *textview;
1630 GtkTextBuffer *textbuf;
1634 gchar buf[BUFFSIZE];
1635 gboolean use_signing = FALSE;
1636 gboolean use_encryption = FALSE;
1637 gchar *privacy_system = NULL;
1639 g_return_val_if_fail(msginfo != NULL, NULL);
1640 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1642 if (compose_put_existing_to_front(msginfo)) {
1646 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1647 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1648 gchar queueheader_buf[BUFFSIZE];
1651 /* Select Account from queue headers */
1652 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1653 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1654 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1655 account = account_find_from_id(id);
1657 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1658 sizeof(queueheader_buf), "NAID:")) {
1659 id = atoi(&queueheader_buf[strlen("NAID:")]);
1660 account = account_find_from_id(id);
1662 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1663 sizeof(queueheader_buf), "MAID:")) {
1664 id = atoi(&queueheader_buf[strlen("MAID:")]);
1665 account = account_find_from_id(id);
1667 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1668 sizeof(queueheader_buf), "S:")) {
1669 account = account_find_from_address(queueheader_buf);
1671 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1672 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1673 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1674 use_signing = param;
1677 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1678 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1679 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1680 use_encryption = param;
1682 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1683 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1684 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1686 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1687 sizeof(queueheader_buf), "X-Priority: ")) {
1688 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1689 compose->priority = param;
1692 account = msginfo->folder->folder->account;
1695 if (!account && prefs_common.reedit_account_autosel) {
1696 gchar from[BUFFSIZE];
1697 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1698 extract_address(from);
1699 account = account_find_from_address(from);
1703 account = cur_account;
1705 g_return_val_if_fail(account != NULL, NULL);
1707 compose = compose_create(account, COMPOSE_REEDIT, batch);
1709 compose->updating = TRUE;
1711 if (privacy_system != NULL) {
1712 compose->privacy_system = privacy_system;
1713 compose_use_signing(compose, use_signing);
1714 compose_use_encryption(compose, use_encryption);
1715 compose_update_privacy_system_menu_item(compose, FALSE);
1717 activate_privacy_system(compose, account, FALSE);
1720 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1722 compose_extract_original_charset(compose);
1724 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1725 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1726 gchar queueheader_buf[BUFFSIZE];
1728 /* Set message save folder */
1729 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1732 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1733 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1734 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1736 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1737 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1739 GtkItemFactory *ifactory;
1740 ifactory = gtk_item_factory_from_widget(compose->menubar);
1741 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1746 if (compose_parse_header(compose, msginfo) < 0) {
1747 compose->updating = FALSE;
1748 compose_destroy(compose);
1751 compose_reedit_set_entry(compose, msginfo);
1753 textview = GTK_TEXT_VIEW(compose->text);
1754 textbuf = gtk_text_view_get_buffer(textview);
1755 compose_create_tags(textview, compose);
1757 mark = gtk_text_buffer_get_insert(textbuf);
1758 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1760 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1761 G_CALLBACK(compose_changed_cb),
1764 if (procmime_msginfo_is_encrypted(msginfo)) {
1765 fp = procmime_get_first_encrypted_text_content(msginfo);
1767 compose_force_encryption(compose, account, TRUE);
1770 fp = procmime_get_first_text_content(msginfo);
1773 g_warning("Can't get text part\n");
1777 gboolean prev_autowrap = compose->autowrap;
1779 compose->autowrap = FALSE;
1780 while (fgets(buf, sizeof(buf), fp) != NULL) {
1782 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1784 compose_wrap_all_full(compose, FALSE);
1785 compose->autowrap = prev_autowrap;
1789 compose_attach_parts(compose, msginfo);
1791 compose_colorize_signature(compose);
1793 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1794 G_CALLBACK(compose_changed_cb),
1797 gtk_widget_grab_focus(compose->text);
1799 if (prefs_common.auto_exteditor) {
1800 compose_exec_ext_editor(compose);
1802 compose->modified = FALSE;
1803 compose_set_title(compose);
1805 compose->updating = FALSE;
1807 if (compose->deferred_destroy) {
1808 compose_destroy(compose);
1814 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
1819 GtkItemFactory *ifactory;
1822 g_return_val_if_fail(msginfo != NULL, NULL);
1825 account = account_get_reply_account(msginfo,
1826 prefs_common.reply_account_autosel);
1827 g_return_val_if_fail(account != NULL, NULL);
1829 compose = compose_create(account, COMPOSE_REDIRECT, batch);
1831 compose->updating = TRUE;
1833 ifactory = gtk_item_factory_from_widget(compose->menubar);
1834 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1835 compose->replyinfo = NULL;
1836 compose->fwdinfo = NULL;
1838 compose_show_first_last_header(compose, TRUE);
1840 gtk_widget_grab_focus(compose->header_last->entry);
1842 filename = procmsg_get_message_file_path(msginfo);
1844 if (filename == NULL) {
1845 compose->updating = FALSE;
1846 compose_destroy(compose);
1851 compose->redirect_filename = filename;
1853 /* Set save folder */
1854 item = msginfo->folder;
1855 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1856 gchar *folderidentifier;
1858 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1859 folderidentifier = folder_item_get_identifier(item);
1860 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1861 g_free(folderidentifier);
1864 compose_attach_parts(compose, msginfo);
1866 if (msginfo->subject)
1867 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1869 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1871 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1872 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1874 compose_colorize_signature(compose);
1876 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1877 menu_set_sensitive(ifactory, "/Add...", FALSE);
1878 menu_set_sensitive(ifactory, "/Remove", FALSE);
1879 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1881 ifactory = gtk_item_factory_from_widget(compose->menubar);
1882 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1883 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1884 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1885 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1886 menu_set_sensitive(ifactory, "/Edit", FALSE);
1887 menu_set_sensitive(ifactory, "/Options", FALSE);
1888 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1889 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1891 if (compose->toolbar->draft_btn)
1892 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1893 if (compose->toolbar->insert_btn)
1894 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1895 if (compose->toolbar->attach_btn)
1896 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1897 if (compose->toolbar->sig_btn)
1898 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1899 if (compose->toolbar->exteditor_btn)
1900 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1901 if (compose->toolbar->linewrap_current_btn)
1902 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1903 if (compose->toolbar->linewrap_all_btn)
1904 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1906 compose->modified = FALSE;
1907 compose_set_title(compose);
1908 compose->updating = FALSE;
1910 if (compose->deferred_destroy) {
1911 compose_destroy(compose);
1918 GList *compose_get_compose_list(void)
1920 return compose_list;
1923 void compose_entry_append(Compose *compose, const gchar *address,
1924 ComposeEntryType type)
1928 gboolean in_quote = FALSE;
1929 if (!address || *address == '\0') return;
1936 header = N_("Bcc:");
1938 case COMPOSE_REPLYTO:
1939 header = N_("Reply-To:");
1941 case COMPOSE_NEWSGROUPS:
1942 header = N_("Newsgroups:");
1944 case COMPOSE_FOLLOWUPTO:
1945 header = N_( "Followup-To:");
1952 header = prefs_common.trans_hdr ? gettext(header) : header;
1954 cur = begin = (gchar *)address;
1956 /* we separate the line by commas, but not if we're inside a quoted
1958 while (*cur != '\0') {
1960 in_quote = !in_quote;
1961 if (*cur == ',' && !in_quote) {
1962 gchar *tmp = g_strdup(begin);
1964 tmp[cur-begin]='\0';
1967 while (*tmp == ' ' || *tmp == '\t')
1969 compose_add_header_entry(compose, header, tmp);
1976 gchar *tmp = g_strdup(begin);
1978 tmp[cur-begin]='\0';
1981 while (*tmp == ' ' || *tmp == '\t')
1983 compose_add_header_entry(compose, header, tmp);
1988 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1990 static GdkColor yellow;
1991 static GdkColor black;
1992 static gboolean yellow_initialised = FALSE;
1996 if (!yellow_initialised) {
1997 gdk_color_parse("#f5f6be", &yellow);
1998 gdk_color_parse("#000000", &black);
1999 yellow_initialised = gdk_colormap_alloc_color(
2000 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
2001 yellow_initialised &= gdk_colormap_alloc_color(
2002 gdk_colormap_get_system(), &black, FALSE, TRUE);
2005 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
2006 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
2007 if (gtk_entry_get_text(entry) &&
2008 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
2009 if (yellow_initialised) {
2010 gtk_widget_modify_base(
2011 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2012 GTK_STATE_NORMAL, &yellow);
2013 gtk_widget_modify_text(
2014 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2015 GTK_STATE_NORMAL, &black);
2021 void compose_toolbar_cb(gint action, gpointer data)
2023 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2024 Compose *compose = (Compose*)toolbar_item->parent;
2026 g_return_if_fail(compose != NULL);
2030 compose_send_cb(compose, 0, NULL);
2033 compose_send_later_cb(compose, 0, NULL);
2036 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2039 compose_insert_file_cb(compose, 0, NULL);
2042 compose_attach_cb(compose, 0, NULL);
2045 compose_insert_sig(compose, FALSE);
2048 compose_ext_editor_cb(compose, 0, NULL);
2050 case A_LINEWRAP_CURRENT:
2051 compose_beautify_paragraph(compose, NULL, TRUE);
2053 case A_LINEWRAP_ALL:
2054 compose_wrap_all_full(compose, TRUE);
2057 compose_address_cb(compose, 0, NULL);
2060 case A_CHECK_SPELLING:
2061 compose_check_all(compose);
2069 static void compose_entries_set(Compose *compose, const gchar *mailto)
2073 gchar *subject = NULL;
2078 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
2081 compose_entry_append(compose, to, COMPOSE_TO);
2083 compose_entry_append(compose, cc, COMPOSE_CC);
2085 if (!g_utf8_validate (subject, -1, NULL)) {
2086 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2087 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2090 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2094 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2095 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2098 gboolean prev_autowrap = compose->autowrap;
2100 compose->autowrap = FALSE;
2102 mark = gtk_text_buffer_get_insert(buffer);
2103 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2105 if (!g_utf8_validate (body, -1, NULL)) {
2106 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2107 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2110 gtk_text_buffer_insert(buffer, &iter, body, -1);
2112 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2114 compose->autowrap = prev_autowrap;
2115 if (compose->autowrap)
2116 compose_wrap_all(compose);
2125 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2127 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2128 {"Cc:", NULL, TRUE},
2129 {"References:", NULL, FALSE},
2130 {"Bcc:", NULL, TRUE},
2131 {"Newsgroups:", NULL, TRUE},
2132 {"Followup-To:", NULL, TRUE},
2133 {"List-Post:", NULL, FALSE},
2134 {"X-Priority:", NULL, FALSE},
2135 {NULL, NULL, FALSE}};
2151 g_return_val_if_fail(msginfo != NULL, -1);
2153 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2154 procheader_get_header_fields(fp, hentry);
2157 if (hentry[H_REPLY_TO].body != NULL) {
2158 if (hentry[H_REPLY_TO].body[0] != '\0') {
2160 conv_unmime_header(hentry[H_REPLY_TO].body,
2163 g_free(hentry[H_REPLY_TO].body);
2164 hentry[H_REPLY_TO].body = NULL;
2166 if (hentry[H_CC].body != NULL) {
2167 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2168 g_free(hentry[H_CC].body);
2169 hentry[H_CC].body = NULL;
2171 if (hentry[H_REFERENCES].body != NULL) {
2172 if (compose->mode == COMPOSE_REEDIT)
2173 compose->references = hentry[H_REFERENCES].body;
2175 compose->references = compose_parse_references
2176 (hentry[H_REFERENCES].body, msginfo->msgid);
2177 g_free(hentry[H_REFERENCES].body);
2179 hentry[H_REFERENCES].body = NULL;
2181 if (hentry[H_BCC].body != NULL) {
2182 if (compose->mode == COMPOSE_REEDIT)
2184 conv_unmime_header(hentry[H_BCC].body, NULL);
2185 g_free(hentry[H_BCC].body);
2186 hentry[H_BCC].body = NULL;
2188 if (hentry[H_NEWSGROUPS].body != NULL) {
2189 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2190 hentry[H_NEWSGROUPS].body = NULL;
2192 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2193 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2194 compose->followup_to =
2195 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2198 g_free(hentry[H_FOLLOWUP_TO].body);
2199 hentry[H_FOLLOWUP_TO].body = NULL;
2201 if (hentry[H_LIST_POST].body != NULL) {
2204 extract_address(hentry[H_LIST_POST].body);
2205 if (hentry[H_LIST_POST].body[0] != '\0') {
2206 scan_mailto_url(hentry[H_LIST_POST].body,
2207 &to, NULL, NULL, NULL, NULL);
2209 g_free(compose->ml_post);
2210 compose->ml_post = to;
2213 g_free(hentry[H_LIST_POST].body);
2214 hentry[H_LIST_POST].body = NULL;
2217 /* CLAWS - X-Priority */
2218 if (compose->mode == COMPOSE_REEDIT)
2219 if (hentry[H_X_PRIORITY].body != NULL) {
2222 priority = atoi(hentry[H_X_PRIORITY].body);
2223 g_free(hentry[H_X_PRIORITY].body);
2225 hentry[H_X_PRIORITY].body = NULL;
2227 if (priority < PRIORITY_HIGHEST ||
2228 priority > PRIORITY_LOWEST)
2229 priority = PRIORITY_NORMAL;
2231 compose->priority = priority;
2234 if (compose->mode == COMPOSE_REEDIT) {
2235 if (msginfo->inreplyto && *msginfo->inreplyto)
2236 compose->inreplyto = g_strdup(msginfo->inreplyto);
2240 if (msginfo->msgid && *msginfo->msgid)
2241 compose->inreplyto = g_strdup(msginfo->msgid);
2243 if (!compose->references) {
2244 if (msginfo->msgid && *msginfo->msgid) {
2245 if (msginfo->inreplyto && *msginfo->inreplyto)
2246 compose->references =
2247 g_strdup_printf("<%s>\n\t<%s>",
2251 compose->references =
2252 g_strconcat("<", msginfo->msgid, ">",
2254 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2255 compose->references =
2256 g_strconcat("<", msginfo->inreplyto, ">",
2264 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2266 GSList *ref_id_list, *cur;
2270 ref_id_list = references_list_append(NULL, ref);
2271 if (!ref_id_list) return NULL;
2272 if (msgid && *msgid)
2273 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2278 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2279 /* "<" + Message-ID + ">" + CR+LF+TAB */
2280 len += strlen((gchar *)cur->data) + 5;
2282 if (len > MAX_REFERENCES_LEN) {
2283 /* remove second message-ID */
2284 if (ref_id_list && ref_id_list->next &&
2285 ref_id_list->next->next) {
2286 g_free(ref_id_list->next->data);
2287 ref_id_list = g_slist_remove
2288 (ref_id_list, ref_id_list->next->data);
2290 slist_free_strings(ref_id_list);
2291 g_slist_free(ref_id_list);
2298 new_ref = g_string_new("");
2299 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2300 if (new_ref->len > 0)
2301 g_string_append(new_ref, "\n\t");
2302 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2305 slist_free_strings(ref_id_list);
2306 g_slist_free(ref_id_list);
2308 new_ref_str = new_ref->str;
2309 g_string_free(new_ref, FALSE);
2314 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2315 const gchar *fmt, const gchar *qmark,
2316 const gchar *body, gboolean rewrap)
2318 static MsgInfo dummyinfo;
2319 gchar *quote_str = NULL;
2321 gboolean prev_autowrap;
2322 const gchar *trimmed_body = body;
2323 gint cursor_pos = -1;
2324 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2325 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2330 SIGNAL_BLOCK(buffer);
2333 msginfo = &dummyinfo;
2335 if (qmark != NULL) {
2336 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2337 quote_fmt_scan_string(qmark);
2340 buf = quote_fmt_get_buffer();
2342 alertpanel_error(_("Quote mark format error."));
2344 Xstrdup_a(quote_str, buf, goto error)
2347 if (fmt && *fmt != '\0') {
2348 while (trimmed_body && strlen(trimmed_body) > 1
2349 && trimmed_body[0]=='\n')
2352 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2353 quote_fmt_scan_string(fmt);
2356 buf = quote_fmt_get_buffer();
2358 alertpanel_error(_("Message reply/forward format error."));
2364 prev_autowrap = compose->autowrap;
2365 compose->autowrap = FALSE;
2367 mark = gtk_text_buffer_get_insert(buffer);
2368 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2369 if (g_utf8_validate(buf, -1, NULL)) {
2370 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2372 gchar *tmpout = NULL;
2373 tmpout = conv_codeset_strdup
2374 (buf, conv_get_locale_charset_str_no_utf8(),
2376 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2378 tmpout = g_malloc(strlen(buf)*2+1);
2379 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2381 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2385 cursor_pos = quote_fmt_get_cursor_pos();
2386 compose->set_cursor_pos = cursor_pos;
2387 if (cursor_pos == -1) {
2390 gtk_text_buffer_get_start_iter(buffer, &iter);
2391 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2392 gtk_text_buffer_place_cursor(buffer, &iter);
2394 compose->autowrap = prev_autowrap;
2395 if (compose->autowrap && rewrap)
2396 compose_wrap_all(compose);
2403 SIGNAL_UNBLOCK(buffer);
2409 /* if ml_post is of type addr@host and from is of type
2410 * addr-anything@host, return TRUE
2412 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2414 gchar *left_ml = NULL;
2415 gchar *right_ml = NULL;
2416 gchar *left_from = NULL;
2417 gchar *right_from = NULL;
2418 gboolean result = FALSE;
2420 if (!ml_post || !from)
2423 left_ml = g_strdup(ml_post);
2424 if (strstr(left_ml, "@")) {
2425 right_ml = strstr(left_ml, "@")+1;
2426 *(strstr(left_ml, "@")) = '\0';
2429 left_from = g_strdup(from);
2430 if (strstr(left_from, "@")) {
2431 right_from = strstr(left_from, "@")+1;
2432 *(strstr(left_from, "@")) = '\0';
2435 if (left_ml && left_from && right_ml && right_from
2436 && !strncmp(left_from, left_ml, strlen(left_ml))
2437 && !strcmp(right_from, right_ml)) {
2446 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2448 gchar *my_addr1, *my_addr2;
2450 if (!addr1 || !addr2)
2453 Xstrdup_a(my_addr1, addr1, return FALSE);
2454 Xstrdup_a(my_addr2, addr2, return FALSE);
2456 extract_address(my_addr1);
2457 extract_address(my_addr2);
2459 return !strcmp(my_addr1, my_addr2);
2462 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2463 gboolean to_all, gboolean to_ml,
2465 gboolean followup_and_reply_to)
2467 GSList *cc_list = NULL;
2470 gchar *replyto = NULL;
2471 GHashTable *to_table;
2473 gboolean reply_to_ml = FALSE;
2474 gboolean default_reply_to = FALSE;
2476 g_return_if_fail(compose->account != NULL);
2477 g_return_if_fail(msginfo != NULL);
2479 reply_to_ml = to_ml && compose->ml_post;
2481 default_reply_to = msginfo->folder &&
2482 msginfo->folder->prefs->enable_default_reply_to;
2484 if (compose->account->protocol != A_NNTP) {
2485 if (reply_to_ml && !default_reply_to) {
2487 gboolean is_subscr = is_subscription(compose->ml_post,
2490 /* normal answer to ml post with a reply-to */
2491 compose_entry_append(compose,
2494 if (compose->replyto
2495 && !same_address(compose->ml_post, compose->replyto))
2496 compose_entry_append(compose,
2500 /* answer to subscription confirmation */
2501 if (compose->replyto)
2502 compose_entry_append(compose,
2505 else if (msginfo->from)
2506 compose_entry_append(compose,
2511 else if (!(to_all || to_sender) && default_reply_to) {
2512 compose_entry_append(compose,
2513 msginfo->folder->prefs->default_reply_to,
2515 compose_entry_mark_default_to(compose,
2516 msginfo->folder->prefs->default_reply_to);
2521 Xstrdup_a(tmp1, msginfo->from, return);
2522 extract_address(tmp1);
2523 if (to_all || to_sender ||
2524 !account_find_from_address(tmp1))
2525 compose_entry_append(compose,
2526 (compose->replyto && !to_sender)
2527 ? compose->replyto :
2528 msginfo->from ? msginfo->from : "",
2530 else if (!to_all && !to_sender) {
2531 /* reply to the last list of recipients */
2532 compose_entry_append(compose,
2533 msginfo->to ? msginfo->to : "",
2535 compose_entry_append(compose,
2536 msginfo->cc ? msginfo->cc : "",
2541 if (to_sender || (compose->followup_to &&
2542 !strncmp(compose->followup_to, "poster", 6)))
2543 compose_entry_append
2545 (compose->replyto ? compose->replyto :
2546 msginfo->from ? msginfo->from : ""),
2549 else if (followup_and_reply_to || to_all) {
2550 compose_entry_append
2552 (compose->replyto ? compose->replyto :
2553 msginfo->from ? msginfo->from : ""),
2556 compose_entry_append
2558 compose->followup_to ? compose->followup_to :
2559 compose->newsgroups ? compose->newsgroups : "",
2560 COMPOSE_NEWSGROUPS);
2563 compose_entry_append
2565 compose->followup_to ? compose->followup_to :
2566 compose->newsgroups ? compose->newsgroups : "",
2567 COMPOSE_NEWSGROUPS);
2570 if (msginfo->subject && *msginfo->subject) {
2574 buf = p = g_strdup(msginfo->subject);
2575 p += subject_get_prefix_length(p);
2576 memmove(buf, p, strlen(p) + 1);
2578 buf2 = g_strdup_printf("Re: %s", buf);
2579 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2584 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2586 if (to_ml && compose->ml_post) return;
2587 if (!to_all || compose->account->protocol == A_NNTP) return;
2589 if (compose->replyto) {
2590 Xstrdup_a(replyto, compose->replyto, return);
2591 extract_address(replyto);
2593 if (msginfo->from) {
2594 Xstrdup_a(from, msginfo->from, return);
2595 extract_address(from);
2598 if (replyto && from)
2599 cc_list = address_list_append_with_comments(cc_list, from);
2600 if (to_all && msginfo->folder &&
2601 msginfo->folder->prefs->enable_default_reply_to)
2602 cc_list = address_list_append_with_comments(cc_list,
2603 msginfo->folder->prefs->default_reply_to);
2604 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2605 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2607 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2609 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2610 if (compose->account)
2611 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2612 GINT_TO_POINTER(1));
2614 /* remove address on To: and that of current account */
2615 for (cur = cc_list; cur != NULL; ) {
2616 GSList *next = cur->next;
2619 addr = g_strdup(cur->data);
2620 extract_address(addr);
2622 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2623 cc_list = g_slist_remove(cc_list, cur->data);
2625 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2629 hash_free_strings(to_table);
2630 g_hash_table_destroy(to_table);
2633 for (cur = cc_list; cur != NULL; cur = cur->next)
2634 compose_entry_append(compose, (gchar *)cur->data,
2636 slist_free_strings(cc_list);
2637 g_slist_free(cc_list);
2642 #define SET_ENTRY(entry, str) \
2645 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2648 #define SET_ADDRESS(type, str) \
2651 compose_entry_append(compose, str, type); \
2654 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2656 g_return_if_fail(msginfo != NULL);
2658 SET_ENTRY(subject_entry, msginfo->subject);
2659 SET_ENTRY(from_name, msginfo->from);
2660 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2661 SET_ADDRESS(COMPOSE_CC, compose->cc);
2662 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2663 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2664 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2665 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2667 compose_update_priority_menu_item(compose);
2668 compose_update_privacy_system_menu_item(compose, FALSE);
2669 compose_show_first_last_header(compose, TRUE);
2675 static void compose_insert_sig(Compose *compose, gboolean replace)
2677 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2678 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2680 GtkTextIter iter, iter_end;
2682 gboolean prev_autowrap;
2685 g_return_if_fail(compose->account != NULL);
2687 prev_autowrap = compose->autowrap;
2688 compose->autowrap = FALSE;
2690 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2691 G_CALLBACK(compose_changed_cb),
2694 mark = gtk_text_buffer_get_insert(buffer);
2695 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2696 cur_pos = gtk_text_iter_get_offset (&iter);
2698 gtk_text_buffer_get_end_iter(buffer, &iter);
2700 if (replace && compose->sig_str) {
2702 GtkTextIter first_iter, start_iter, end_iter;
2704 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2706 if (compose->sig_str[0] == '\0')
2709 found = gtk_text_iter_forward_search(&first_iter,
2711 GTK_TEXT_SEARCH_TEXT_ONLY,
2712 &start_iter, &end_iter,
2716 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2721 g_free(compose->sig_str);
2722 compose->sig_str = compose_get_signature_str(compose);
2723 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2724 compose->sig_str = g_strdup("");
2726 cur_pos = gtk_text_iter_get_offset(&iter);
2727 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2729 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2730 gtk_text_iter_forward_char(&iter);
2731 gtk_text_iter_forward_char(&iter);
2732 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2733 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2735 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2736 cur_pos = gtk_text_buffer_get_char_count (buffer);
2738 /* put the cursor where it should be
2739 * either where the quote_fmt says, either before the signature */
2740 if (compose->set_cursor_pos < 0)
2741 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2743 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2744 compose->set_cursor_pos);
2746 gtk_text_buffer_place_cursor(buffer, &iter);
2747 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2748 G_CALLBACK(compose_changed_cb),
2751 compose->autowrap = prev_autowrap;
2752 if (compose->autowrap)
2753 compose_wrap_all(compose);
2756 static gchar *compose_get_signature_str(Compose *compose)
2758 gchar *sig_body = NULL;
2759 gchar *sig_str = NULL;
2760 gchar *utf8_sig_str = NULL;
2762 g_return_val_if_fail(compose->account != NULL, NULL);
2764 if (!compose->account->sig_path)
2767 if (compose->account->sig_type == SIG_FILE) {
2768 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2769 g_warning("can't open signature file: %s\n",
2770 compose->account->sig_path);
2775 if (compose->account->sig_type == SIG_COMMAND)
2776 sig_body = get_command_output(compose->account->sig_path);
2780 tmp = file_read_to_str(compose->account->sig_path);
2783 sig_body = normalize_newlines(tmp);
2787 if (compose->account->sig_sep) {
2788 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2792 sig_str = g_strconcat("\n\n", sig_body, NULL);
2795 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2796 utf8_sig_str = sig_str;
2798 utf8_sig_str = conv_codeset_strdup
2799 (sig_str, conv_get_locale_charset_str_no_utf8(),
2805 return utf8_sig_str;
2808 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2811 GtkTextBuffer *buffer;
2814 const gchar *cur_encoding;
2815 gchar buf[BUFFSIZE];
2818 gboolean prev_autowrap;
2819 gboolean badtxt = FALSE;
2821 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2823 if ((fp = g_fopen(file, "rb")) == NULL) {
2824 FILE_OP_ERROR(file, "fopen");
2825 return COMPOSE_INSERT_READ_ERROR;
2828 prev_autowrap = compose->autowrap;
2829 compose->autowrap = FALSE;
2831 text = GTK_TEXT_VIEW(compose->text);
2832 buffer = gtk_text_view_get_buffer(text);
2833 mark = gtk_text_buffer_get_insert(buffer);
2834 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2836 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2837 G_CALLBACK(text_inserted),
2840 cur_encoding = conv_get_locale_charset_str_no_utf8();
2842 while (fgets(buf, sizeof(buf), fp) != NULL) {
2845 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2846 str = g_strdup(buf);
2848 str = conv_codeset_strdup
2849 (buf, cur_encoding, CS_INTERNAL);
2852 /* strip <CR> if DOS/Windows file,
2853 replace <CR> with <LF> if Macintosh file. */
2856 if (len > 0 && str[len - 1] != '\n') {
2858 if (str[len] == '\r') str[len] = '\n';
2861 gtk_text_buffer_insert(buffer, &iter, str, -1);
2865 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2866 G_CALLBACK(text_inserted),
2868 compose->autowrap = prev_autowrap;
2869 if (compose->autowrap)
2870 compose_wrap_all(compose);
2875 return COMPOSE_INSERT_INVALID_CHARACTER;
2877 return COMPOSE_INSERT_SUCCESS;
2880 static void compose_attach_append(Compose *compose, const gchar *file,
2881 const gchar *filename,
2882 const gchar *content_type)
2890 GtkListStore *store;
2892 gboolean has_binary = FALSE;
2894 if (!is_file_exist(file)) {
2895 g_warning("File %s doesn't exist\n", filename);
2898 if ((size = get_file_size(file)) < 0) {
2899 g_warning("Can't get file size of %s\n", filename);
2903 alertpanel_notice(_("File %s is empty."), filename);
2906 if ((fp = g_fopen(file, "rb")) == NULL) {
2907 alertpanel_error(_("Can't read %s."), filename);
2912 ainfo = g_new0(AttachInfo, 1);
2913 auto_ainfo = g_auto_pointer_new_with_free
2914 (ainfo, (GFreeFunc) compose_attach_info_free);
2915 ainfo->file = g_strdup(file);
2918 ainfo->content_type = g_strdup(content_type);
2919 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2921 MsgFlags flags = {0, 0};
2923 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
2924 ainfo->encoding = ENC_7BIT;
2926 ainfo->encoding = ENC_8BIT;
2928 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2929 if (msginfo && msginfo->subject)
2930 name = g_strdup(msginfo->subject);
2932 name = g_path_get_basename(filename ? filename : file);
2934 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2936 procmsg_msginfo_free(msginfo);
2938 if (!g_ascii_strncasecmp(content_type, "text", 4))
2939 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
2941 ainfo->encoding = ENC_BASE64;
2942 name = g_path_get_basename(filename ? filename : file);
2943 ainfo->name = g_strdup(name);
2947 ainfo->content_type = procmime_get_mime_type(file);
2948 if (!ainfo->content_type) {
2949 ainfo->content_type =
2950 g_strdup("application/octet-stream");
2951 ainfo->encoding = ENC_BASE64;
2952 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2954 procmime_get_encoding_for_text_file(file, &has_binary);
2956 ainfo->encoding = ENC_BASE64;
2957 name = g_path_get_basename(filename ? filename : file);
2958 ainfo->name = g_strdup(name);
2962 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
2963 g_free(ainfo->content_type);
2964 ainfo->content_type = g_strdup("application/octet-stream");
2968 size_text = to_human_readable(size);
2970 store = GTK_LIST_STORE(gtk_tree_view_get_model
2971 (GTK_TREE_VIEW(compose->attach_clist)));
2973 gtk_list_store_append(store, &iter);
2974 gtk_list_store_set(store, &iter,
2975 COL_MIMETYPE, ainfo->content_type,
2976 COL_SIZE, size_text,
2977 COL_NAME, ainfo->name,
2979 COL_AUTODATA, auto_ainfo,
2982 g_auto_pointer_free(auto_ainfo);
2985 static void compose_use_signing(Compose *compose, gboolean use_signing)
2987 GtkItemFactory *ifactory;
2988 GtkWidget *menuitem = NULL;
2990 compose->use_signing = use_signing;
2991 ifactory = gtk_item_factory_from_widget(compose->menubar);
2992 menuitem = gtk_item_factory_get_item
2993 (ifactory, "/Options/Sign");
2994 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2998 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
3000 GtkItemFactory *ifactory;
3001 GtkWidget *menuitem = NULL;
3003 compose->use_encryption = use_encryption;
3004 ifactory = gtk_item_factory_from_widget(compose->menubar);
3005 menuitem = gtk_item_factory_get_item
3006 (ifactory, "/Options/Encrypt");
3008 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3012 #define NEXT_PART_NOT_CHILD(info) \
3014 node = info->node; \
3015 while (node->children) \
3016 node = g_node_last_child(node); \
3017 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3020 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3024 MimeInfo *firsttext = NULL;
3025 MimeInfo *encrypted = NULL;
3028 const gchar *partname = NULL;
3030 mimeinfo = procmime_scan_message(msginfo);
3031 if (!mimeinfo) return;
3033 if (mimeinfo->node->children == NULL) {
3034 procmime_mimeinfo_free_all(mimeinfo);
3038 /* find first content part */
3039 child = (MimeInfo *) mimeinfo->node->children->data;
3040 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3041 child = (MimeInfo *)child->node->children->data;
3043 if (child->type == MIMETYPE_TEXT) {
3045 debug_print("First text part found\n");
3046 } else if (compose->mode == COMPOSE_REEDIT &&
3047 child->type == MIMETYPE_APPLICATION &&
3048 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3049 encrypted = (MimeInfo *)child->node->parent->data;
3052 child = (MimeInfo *) mimeinfo->node->children->data;
3053 while (child != NULL) {
3054 if (child == encrypted) {
3055 /* skip this part of tree */
3056 NEXT_PART_NOT_CHILD(child);
3060 if (child->type == MIMETYPE_MULTIPART) {
3061 /* get the actual content */
3062 child = procmime_mimeinfo_next(child);
3066 if (child == firsttext) {
3067 child = procmime_mimeinfo_next(child);
3071 outfile = procmime_get_tmp_file_name(child);
3072 if (procmime_get_part(outfile, child) < 0)
3073 g_warning("Can't get the part of multipart message.");
3075 gchar *content_type;
3077 content_type = procmime_get_content_type_str(child->type, child->subtype);
3079 /* if we meet a pgp signature, we don't attach it, but
3080 * we force signing. */
3081 if (strcmp(content_type, "application/pgp-signature")) {
3082 partname = procmime_mimeinfo_get_parameter(child, "filename");
3083 if (partname == NULL)
3084 partname = procmime_mimeinfo_get_parameter(child, "name");
3085 if (partname == NULL)
3087 compose_attach_append(compose, outfile,
3088 partname, content_type);
3090 compose_force_signing(compose, compose->account);
3092 g_free(content_type);
3095 NEXT_PART_NOT_CHILD(child);
3097 procmime_mimeinfo_free_all(mimeinfo);
3100 #undef NEXT_PART_NOT_CHILD
3105 WAIT_FOR_INDENT_CHAR,
3106 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3109 /* return indent length, we allow:
3110 indent characters followed by indent characters or spaces/tabs,
3111 alphabets and numbers immediately followed by indent characters,
3112 and the repeating sequences of the above
3113 If quote ends with multiple spaces, only the first one is included. */
3114 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3115 const GtkTextIter *start, gint *len)
3117 GtkTextIter iter = *start;
3121 IndentState state = WAIT_FOR_INDENT_CHAR;
3124 gint alnum_count = 0;
3125 gint space_count = 0;
3128 if (prefs_common.quote_chars == NULL) {
3132 while (!gtk_text_iter_ends_line(&iter)) {
3133 wc = gtk_text_iter_get_char(&iter);
3134 if (g_unichar_iswide(wc))
3136 clen = g_unichar_to_utf8(wc, ch);
3140 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3141 is_space = g_unichar_isspace(wc);
3143 if (state == WAIT_FOR_INDENT_CHAR) {
3144 if (!is_indent && !g_unichar_isalnum(wc))
3147 quote_len += alnum_count + space_count + 1;
3148 alnum_count = space_count = 0;
3149 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3152 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3153 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3157 else if (is_indent) {
3158 quote_len += alnum_count + space_count + 1;
3159 alnum_count = space_count = 0;
3162 state = WAIT_FOR_INDENT_CHAR;
3166 gtk_text_iter_forward_char(&iter);
3169 if (quote_len > 0 && space_count > 0)
3175 if (quote_len > 0) {
3177 gtk_text_iter_forward_chars(&iter, quote_len);
3178 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3184 /* return TRUE if the line is itemized */
3185 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3186 const GtkTextIter *start)
3188 GtkTextIter iter = *start;
3193 if (gtk_text_iter_ends_line(&iter))
3197 wc = gtk_text_iter_get_char(&iter);
3198 if (!g_unichar_isspace(wc))
3200 gtk_text_iter_forward_char(&iter);
3201 if (gtk_text_iter_ends_line(&iter))
3205 clen = g_unichar_to_utf8(wc, ch);
3209 if (!strchr("*-+", ch[0]))
3212 gtk_text_iter_forward_char(&iter);
3213 if (gtk_text_iter_ends_line(&iter))
3215 wc = gtk_text_iter_get_char(&iter);
3216 if (g_unichar_isspace(wc))
3222 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3223 const GtkTextIter *start,
3224 GtkTextIter *break_pos,
3228 GtkTextIter iter = *start, line_end = *start;
3229 PangoLogAttr *attrs;
3236 gboolean can_break = FALSE;
3237 gboolean do_break = FALSE;
3238 gboolean was_white = FALSE;
3239 gboolean prev_dont_break = FALSE;
3241 gtk_text_iter_forward_to_line_end(&line_end);
3242 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3243 len = g_utf8_strlen(str, -1);
3244 /* g_print("breaking line: %d: %s (len = %d)\n",
3245 gtk_text_iter_get_line(&iter), str, len); */
3246 attrs = g_new(PangoLogAttr, len + 1);
3248 pango_default_break(str, -1, NULL, attrs, len + 1);
3252 /* skip quote and leading spaces */
3253 for (i = 0; *p != '\0' && i < len; i++) {
3256 wc = g_utf8_get_char(p);
3257 if (i >= quote_len && !g_unichar_isspace(wc))
3259 if (g_unichar_iswide(wc))
3261 else if (*p == '\t')
3265 p = g_utf8_next_char(p);
3268 for (; *p != '\0' && i < len; i++) {
3269 PangoLogAttr *attr = attrs + i;
3273 if (attr->is_line_break && can_break && was_white && !prev_dont_break)
3276 was_white = attr->is_white;
3278 /* don't wrap URI */
3279 if ((uri_len = get_uri_len(p)) > 0) {
3281 if (pos > 0 && col > max_col) {
3291 wc = g_utf8_get_char(p);
3292 if (g_unichar_iswide(wc)) {
3294 if (prev_dont_break && can_break && attr->is_line_break)
3296 } else if (*p == '\t')
3300 if (pos > 0 && col > max_col) {
3305 if (*p == '-' || *p == '/')
3306 prev_dont_break = TRUE;
3308 prev_dont_break = FALSE;
3310 p = g_utf8_next_char(p);
3314 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
3319 *break_pos = *start;
3320 gtk_text_iter_set_line_offset(break_pos, pos);
3325 static gboolean compose_join_next_line(Compose *compose,
3326 GtkTextBuffer *buffer,
3328 const gchar *quote_str)
3330 GtkTextIter iter_ = *iter, cur, prev, next, end;
3331 PangoLogAttr attrs[3];
3333 gchar *next_quote_str;
3336 gboolean keep_cursor = FALSE;
3338 if (!gtk_text_iter_forward_line(&iter_) ||
3339 gtk_text_iter_ends_line(&iter_))
3342 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
3344 if ((quote_str || next_quote_str) &&
3345 strcmp2(quote_str, next_quote_str) != 0) {
3346 g_free(next_quote_str);
3349 g_free(next_quote_str);
3352 if (quote_len > 0) {
3353 gtk_text_iter_forward_chars(&end, quote_len);
3354 if (gtk_text_iter_ends_line(&end))
3358 /* don't join itemized lines */
3359 if (compose_is_itemized(buffer, &end))
3362 /* don't join signature separator */
3363 if (compose_is_sig_separator(compose, buffer, &iter_))
3366 /* delete quote str */
3368 gtk_text_buffer_delete(buffer, &iter_, &end);
3370 /* don't join line breaks put by the user */
3372 gtk_text_iter_backward_char(&cur);
3373 if (gtk_text_iter_has_tag(&cur, compose->no_join_tag)) {
3374 gtk_text_iter_forward_char(&cur);
3378 gtk_text_iter_forward_char(&cur);
3379 /* delete linebreak and extra spaces */
3380 while (gtk_text_iter_backward_char(&cur)) {
3381 wc1 = gtk_text_iter_get_char(&cur);
3382 if (!g_unichar_isspace(wc1))
3387 while (!gtk_text_iter_ends_line(&cur)) {
3388 wc1 = gtk_text_iter_get_char(&cur);
3389 if (!g_unichar_isspace(wc1))
3391 gtk_text_iter_forward_char(&cur);
3394 if (!gtk_text_iter_equal(&prev, &next)) {
3397 mark = gtk_text_buffer_get_insert(buffer);
3398 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
3399 if (gtk_text_iter_equal(&prev, &cur))
3401 gtk_text_buffer_delete(buffer, &prev, &next);
3405 /* insert space if required */
3406 gtk_text_iter_backward_char(&prev);
3407 wc1 = gtk_text_iter_get_char(&prev);
3408 wc2 = gtk_text_iter_get_char(&next);
3409 gtk_text_iter_forward_char(&next);
3410 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
3411 pango_default_break(str, -1, NULL, attrs, 3);
3412 if (!attrs[1].is_line_break ||
3413 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
3414 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
3416 gtk_text_iter_backward_char(&iter_);
3417 gtk_text_buffer_place_cursor(buffer, &iter_);
3426 #define ADD_TXT_POS(bp_, ep_, pti_) \
3427 if ((last->next = alloca(sizeof(struct txtpos))) != NULL) { \
3428 last = last->next; \
3429 last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
3430 last->next = NULL; \
3432 g_warning("alloc error scanning URIs\n"); \
3435 static gboolean automatic_break = FALSE;
3436 static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force)
3438 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3439 GtkTextBuffer *buffer;
3440 GtkTextIter iter, break_pos, end_of_line;
3441 gchar *quote_str = NULL;
3443 gboolean wrap_quote = prefs_common.linewrap_quote;
3444 gboolean prev_autowrap = compose->autowrap;
3445 gint startq_offset = -1, noq_offset = -1;
3446 gint uri_start = -1, uri_stop = -1;
3447 gint nouri_start = -1, nouri_stop = -1;
3448 gint num_blocks = 0;
3449 gint quotelevel = -1;
3451 compose->autowrap = FALSE;
3453 buffer = gtk_text_view_get_buffer(text);
3454 undo_wrapping(compose->undostruct, TRUE);
3459 mark = gtk_text_buffer_get_insert(buffer);
3460 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
3463 /* move to paragraph start */
3464 gtk_text_iter_set_line_offset(&iter, 0);
3465 if (gtk_text_iter_ends_line(&iter)) {
3466 while (gtk_text_iter_ends_line(&iter) &&
3467 gtk_text_iter_forward_line(&iter))
3470 while (gtk_text_iter_backward_line(&iter)) {
3471 if (gtk_text_iter_ends_line(&iter)) {
3472 gtk_text_iter_forward_line(&iter);
3478 /* go until paragraph end (empty line) */
3480 while (!gtk_text_iter_ends_line(&iter)) {
3481 gchar *scanpos = NULL;
3482 /* parse table - in order of priority */
3484 const gchar *needle; /* token */
3486 /* token search function */
3487 gchar *(*search) (const gchar *haystack,
3488 const gchar *needle);
3489 /* part parsing function */
3490 gboolean (*parse) (const gchar *start,
3491 const gchar *scanpos,
3495 /* part to URI function */
3496 gchar *(*build_uri) (const gchar *bp,
3500 static struct table parser[] = {
3501 {"http://", strcasestr, get_uri_part, make_uri_string},
3502 {"https://", strcasestr, get_uri_part, make_uri_string},
3503 {"ftp://", strcasestr, get_uri_part, make_uri_string},
3504 {"www.", strcasestr, get_uri_part, make_http_string},
3505 {"mailto:", strcasestr, get_uri_part, make_uri_string},
3506 {"@", strcasestr, get_email_part, make_email_string}
3508 const gint PARSE_ELEMS = sizeof parser / sizeof parser[0];
3509 gint last_index = PARSE_ELEMS;
3511 gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL;
3514 if (!prev_autowrap && num_blocks == 0) {
3516 g_signal_handlers_block_by_func(G_OBJECT(buffer),
3517 G_CALLBACK(text_inserted),
3520 if (gtk_text_iter_has_tag(&iter, compose->no_wrap_tag) && !force)
3523 uri_start = uri_stop = -1;
3525 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
3529 if (startq_offset == -1) {
3530 startq_offset = gtk_text_iter_get_offset(&iter);
3534 debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str);
3535 if (startq_offset == -1)
3536 startq_offset = gtk_text_iter_get_offset(&iter);
3537 quotelevel = get_quote_level(quote_str, prefs_common.quote_chars);
3538 if (quotelevel > 2) {
3539 /* recycle colors */
3540 if (prefs_common.recycle_quote_colors)
3546 if (startq_offset == -1)
3547 noq_offset = gtk_text_iter_get_offset(&iter);
3551 if (prev_autowrap == FALSE && !force && !wrap_quote) {
3554 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
3555 prefs_common.linewrap_len,
3557 GtkTextIter prev, next, cur;
3559 if (prev_autowrap != FALSE || force) {
3560 automatic_break = TRUE;
3561 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3562 automatic_break = FALSE;
3563 } else if (quote_str && wrap_quote) {
3564 automatic_break = TRUE;
3565 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
3566 automatic_break = FALSE;
3569 /* remove trailing spaces */
3571 gtk_text_iter_backward_char(&cur);
3573 while (!gtk_text_iter_starts_line(&cur)) {
3576 gtk_text_iter_backward_char(&cur);
3577 wc = gtk_text_iter_get_char(&cur);
3578 if (!g_unichar_isspace(wc))
3582 if (!gtk_text_iter_equal(&prev, &next)) {
3583 gtk_text_buffer_delete(buffer, &prev, &next);
3585 gtk_text_iter_forward_char(&break_pos);
3589 gtk_text_buffer_insert(buffer, &break_pos,
3593 compose_join_next_line(compose, buffer, &iter, quote_str);
3595 /* move iter to current line start */
3596 gtk_text_iter_set_line_offset(&iter, 0);
3603 /* move iter to next line start */
3608 if (!prev_autowrap && num_blocks > 0) {
3610 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
3611 G_CALLBACK(text_inserted),
3615 while (!gtk_text_iter_ends_line(&end_of_line)) {
3616 gtk_text_iter_forward_char(&end_of_line);
3618 o_walk = walk = gtk_text_buffer_get_text(buffer, &iter, &end_of_line, FALSE);
3620 nouri_start = gtk_text_iter_get_offset(&iter);
3621 nouri_stop = gtk_text_iter_get_offset(&end_of_line);
3623 walk_pos = gtk_text_iter_get_offset(&iter);
3624 /* FIXME: this looks phony. scanning for anything in the parse table */
3625 for (n = 0; n < PARSE_ELEMS; n++) {
3628 tmp = parser[n].search(walk, parser[n].needle);
3630 if (scanpos == NULL || tmp < scanpos) {
3639 /* check if URI can be parsed */
3640 if (parser[last_index].parse(walk, scanpos, (const gchar **)&bp,
3641 (const gchar **)&ep, FALSE)
3642 && (size_t) (ep - bp - 1) > strlen(parser[last_index].needle)) {
3646 strlen(parser[last_index].needle);
3649 uri_start = walk_pos + (bp - o_walk);
3650 uri_stop = walk_pos + (ep - o_walk);
3654 gtk_text_iter_forward_line(&iter);
3657 if (startq_offset != -1) {
3658 GtkTextIter startquote, endquote;
3659 gtk_text_buffer_get_iter_at_offset(
3660 buffer, &startquote, startq_offset);
3662 switch (quotelevel) {
3663 case 0: gtk_text_buffer_apply_tag_by_name(
3664 buffer, "quote0", &startquote, &endquote);
3666 case 1: gtk_text_buffer_apply_tag_by_name(
3667 buffer, "quote1", &startquote, &endquote);
3669 case 2: gtk_text_buffer_apply_tag_by_name(
3670 buffer, "quote2", &startquote, &endquote);
3674 } else if (noq_offset != -1) {
3675 GtkTextIter startnoquote, endnoquote;
3676 gtk_text_buffer_get_iter_at_offset(
3677 buffer, &startnoquote, noq_offset);
3679 gtk_text_buffer_remove_tag_by_name(
3680 buffer, "quote0", &startnoquote, &endnoquote);
3681 gtk_text_buffer_remove_tag_by_name(
3682 buffer, "quote1", &startnoquote, &endnoquote);
3683 gtk_text_buffer_remove_tag_by_name(
3684 buffer, "quote2", &startnoquote, &endnoquote);
3689 GtkTextIter nouri_start_iter, nouri_end_iter;
3690 gtk_text_buffer_get_iter_at_offset(
3691 buffer, &nouri_start_iter, nouri_start);
3692 gtk_text_buffer_get_iter_at_offset(
3693 buffer, &nouri_end_iter, nouri_stop);
3694 gtk_text_buffer_remove_tag_by_name(
3695 buffer, "link", &nouri_start_iter, &nouri_end_iter);
3697 if (uri_start > 0 && uri_stop > 0) {
3698 GtkTextIter uri_start_iter, uri_end_iter;
3699 gtk_text_buffer_get_iter_at_offset(
3700 buffer, &uri_start_iter, uri_start);
3701 gtk_text_buffer_get_iter_at_offset(
3702 buffer, &uri_end_iter, uri_stop);
3703 gtk_text_buffer_apply_tag_by_name(
3704 buffer, "link", &uri_start_iter, &uri_end_iter);
3710 undo_wrapping(compose->undostruct, FALSE);
3711 compose->autowrap = prev_autowrap;
3714 void compose_action_cb(void *data)
3716 Compose *compose = (Compose *)data;
3717 compose_wrap_all(compose);
3720 static void compose_wrap_all(Compose *compose)
3722 compose_wrap_all_full(compose, FALSE);
3725 static void compose_wrap_all_full(Compose *compose, gboolean force)
3727 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3728 GtkTextBuffer *buffer;
3731 buffer = gtk_text_view_get_buffer(text);
3733 gtk_text_buffer_get_start_iter(buffer, &iter);
3734 while (!gtk_text_iter_is_end(&iter))
3735 compose_beautify_paragraph(compose, &iter, force);
3739 static void compose_set_title(Compose *compose)