2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #ifndef PANGO_ENABLE_ENGINE
27 # define PANGO_ENABLE_ENGINE
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtkmain.h>
34 #include <gtk/gtkmenu.h>
35 #include <gtk/gtkmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkcheckmenuitem.h>
38 #include <gtk/gtkoptionmenu.h>
39 #include <gtk/gtkwidget.h>
40 #include <gtk/gtkvpaned.h>
41 #include <gtk/gtkentry.h>
42 #include <gtk/gtkeditable.h>
43 #include <gtk/gtkwindow.h>
44 #include <gtk/gtksignal.h>
45 #include <gtk/gtkvbox.h>
46 #include <gtk/gtkcontainer.h>
47 #include <gtk/gtkhandlebox.h>
48 #include <gtk/gtktoolbar.h>
49 #include <gtk/gtktable.h>
50 #include <gtk/gtkhbox.h>
51 #include <gtk/gtklabel.h>
52 #include <gtk/gtkscrolledwindow.h>
53 #include <gtk/gtktreeview.h>
54 #include <gtk/gtkliststore.h>
55 #include <gtk/gtktreeselection.h>
56 #include <gtk/gtktreemodel.h>
58 #include <gtk/gtkdnd.h>
59 #include <gtk/gtkclipboard.h>
60 #include <pango/pango-break.h>
65 #include <sys/types.h>
71 # include <sys/wait.h>
75 #ifndef G_OS_WIN32 /* fixme we should have a configure test. */
79 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
86 #include "mainwindow.h"
88 #include "addressbook.h"
89 #include "folderview.h"
92 #include "stock_pixmap.h"
93 #include "send_message.h"
96 #include "customheader.h"
97 #include "prefs_common.h"
98 #include "prefs_account.h"
102 #include "procheader.h"
103 #include "procmime.h"
104 #include "statusbar.h"
107 #include "quoted-printable.h"
108 #include "codeconv.h"
110 #include "gtkutils.h"
112 #include "alertpanel.h"
113 #include "manage_window.h"
114 #include "gtkshruler.h"
116 #include "addr_compl.h"
117 #include "quote_fmt.h"
119 #include "foldersel.h"
122 #include "message_search.h"
123 #include "combobox.h"
135 #define N_ATTACH_COLS (N_COL_COLUMNS)
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
141 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
142 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
143 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
144 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
145 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
146 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
148 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
149 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
150 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
151 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
152 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
153 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
154 } ComposeCallAdvancedAction;
158 PRIORITY_HIGHEST = 1,
167 COMPOSE_INSERT_SUCCESS,
168 COMPOSE_INSERT_READ_ERROR,
169 COMPOSE_INSERT_INVALID_CHARACTER,
170 COMPOSE_INSERT_NO_FILE
171 } ComposeInsertResult;
175 COMPOSE_QUIT_EDITING,
176 COMPOSE_KEEP_EDITING,
178 } ComposeDraftAction;
182 COMPOSE_WRITE_FOR_SEND,
183 COMPOSE_WRITE_FOR_STORE
186 #define B64_LINE_SIZE 57
187 #define B64_BUFFSIZE 77
189 #define MAX_REFERENCES_LEN 999
191 static GList *compose_list = NULL;
193 Compose *compose_generic_new (PrefsAccount *account,
196 GPtrArray *attach_files,
197 GList *listAddress );
199 static Compose *compose_create (PrefsAccount *account,
203 static GtkWidget *compose_account_option_menu_create
205 static void compose_set_out_encoding (Compose *compose);
206 static void compose_set_template_menu (Compose *compose);
207 static void compose_template_apply (Compose *compose,
210 static void compose_destroy (Compose *compose);
212 static void compose_entries_set (Compose *compose,
213 const gchar *mailto);
214 static gint compose_parse_header (Compose *compose,
216 static gchar *compose_parse_references (const gchar *ref,
219 static gchar *compose_quote_fmt (Compose *compose,
226 static void compose_reply_set_entry (Compose *compose,
232 followup_and_reply_to);
233 static void compose_reedit_set_entry (Compose *compose,
236 static void compose_insert_sig (Compose *compose,
238 static gchar *compose_get_signature_str (Compose *compose);
239 static ComposeInsertResult compose_insert_file (Compose *compose,
242 static void compose_attach_append (Compose *compose,
245 const gchar *content_type);
246 static void compose_attach_parts (Compose *compose,
249 static void compose_beautify_paragraph (Compose *compose,
250 GtkTextIter *par_iter,
252 static void compose_wrap_all (Compose *compose);
253 static void compose_wrap_all_full (Compose *compose,
256 static void compose_set_title (Compose *compose);
257 static void compose_select_account (Compose *compose,
258 PrefsAccount *account,
261 static PrefsAccount *compose_current_mail_account(void);
262 /* static gint compose_send (Compose *compose); */
263 static gboolean compose_check_for_valid_recipient
265 static gboolean compose_check_entries (Compose *compose,
266 gboolean check_subject);
267 static gint compose_write_to_file (Compose *compose,
270 gboolean attach_parts);
271 static gint compose_write_body_to_file (Compose *compose,
273 static gint compose_remove_reedit_target (Compose *compose,
275 void compose_remove_draft (Compose *compose);
276 static gint compose_queue_sub (Compose *compose,
280 gboolean check_subject,
281 gboolean remove_reedit_target);
282 static void compose_add_attachments (Compose *compose,
284 static gchar *compose_get_header (Compose *compose);
286 static void compose_convert_header (Compose *compose,
291 gboolean addr_field);
293 static void compose_attach_info_free (AttachInfo *ainfo);
294 static void compose_attach_remove_selected (Compose *compose);
296 static void compose_attach_property (Compose *compose);
297 static void compose_attach_property_create (gboolean *cancelled);
298 static void attach_property_ok (GtkWidget *widget,
299 gboolean *cancelled);
300 static void attach_property_cancel (GtkWidget *widget,
301 gboolean *cancelled);
302 static gint attach_property_delete_event (GtkWidget *widget,
304 gboolean *cancelled);
305 static gboolean attach_property_key_pressed (GtkWidget *widget,
307 gboolean *cancelled);
309 static void compose_exec_ext_editor (Compose *compose);
311 static gint compose_exec_ext_editor_real (const gchar *file);
312 static gboolean compose_ext_editor_kill (Compose *compose);
313 static gboolean compose_input_cb (GIOChannel *source,
314 GIOCondition condition,
316 static void compose_set_ext_editor_sensitive (Compose *compose,
318 #endif /* G_OS_UNIX */
320 static void compose_undo_state_changed (UndoMain *undostruct,
325 static void compose_create_header_entry (Compose *compose);
326 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
327 static void compose_update_priority_menu_item(Compose * compose);
329 static void compose_spell_menu_changed (void *data);
331 static void compose_add_field_list ( Compose *compose,
332 GList *listAddress );
334 /* callback functions */
336 static gboolean compose_edit_size_alloc (GtkEditable *widget,
337 GtkAllocation *allocation,
338 GtkSHRuler *shruler);
339 static void account_activated (GtkComboBox *optmenu,
341 static void attach_selected (GtkTreeView *tree_view,
342 GtkTreePath *tree_path,
343 GtkTreeViewColumn *column,
345 static gboolean attach_button_pressed (GtkWidget *widget,
346 GdkEventButton *event,
348 static gboolean attach_key_pressed (GtkWidget *widget,
352 static void compose_send_cb (gpointer data,
355 static void compose_send_later_cb (gpointer data,
359 static void compose_draft_cb (gpointer data,
363 static void compose_attach_cb (gpointer data,
366 static void compose_insert_file_cb (gpointer data,
369 static void compose_insert_sig_cb (gpointer data,
373 static void compose_close_cb (gpointer data,
377 static void compose_set_encoding_cb (gpointer data,
381 static void compose_address_cb (gpointer data,
384 static void compose_template_activate_cb(GtkWidget *widget,
387 static void compose_ext_editor_cb (gpointer data,
391 static gint compose_delete_cb (GtkWidget *widget,
395 static void compose_undo_cb (Compose *compose);
396 static void compose_redo_cb (Compose *compose);
397 static void compose_cut_cb (Compose *compose);
398 static void compose_copy_cb (Compose *compose);
399 static void compose_paste_cb (Compose *compose);
400 static void compose_paste_as_quote_cb (Compose *compose);
401 static void compose_paste_no_wrap_cb (Compose *compose);
402 static void compose_paste_wrap_cb (Compose *compose);
403 static void compose_allsel_cb (Compose *compose);
405 static void compose_advanced_action_cb (Compose *compose,
406 ComposeCallAdvancedAction action);
408 static void compose_grab_focus_cb (GtkWidget *widget,
411 static void compose_changed_cb (GtkTextBuffer *textbuf,
414 static void compose_wrap_cb (gpointer data,
417 static void compose_find_cb (gpointer data,
420 static void compose_toggle_autowrap_cb (gpointer data,
424 static void compose_toggle_ruler_cb (gpointer data,
427 static void compose_toggle_sign_cb (gpointer data,
430 static void compose_toggle_encrypt_cb (gpointer data,
433 static void compose_set_privacy_system_cb(GtkWidget *widget,
435 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
436 static void activate_privacy_system (Compose *compose,
437 PrefsAccount *account,
439 static void compose_use_signing(Compose *compose, gboolean use_signing);
440 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
441 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
443 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
445 static void compose_set_priority_cb (gpointer data,
449 static void compose_attach_drag_received_cb (GtkWidget *widget,
450 GdkDragContext *drag_context,
453 GtkSelectionData *data,
457 static void compose_insert_drag_received_cb (GtkWidget *widget,
458 GdkDragContext *drag_context,
461 GtkSelectionData *data,
465 static void compose_header_drag_received_cb (GtkWidget *widget,
466 GdkDragContext *drag_context,
469 GtkSelectionData *data,
474 static gboolean compose_drag_drop (GtkWidget *widget,
475 GdkDragContext *drag_context,
477 guint time, gpointer user_data);
479 static void text_inserted (GtkTextBuffer *buffer,
484 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
485 gboolean to_all, gboolean to_ml,
487 gboolean followup_and_reply_to,
490 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
491 ComposeHeaderEntry *headerentry);
492 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
494 ComposeHeaderEntry *headerentry);
496 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
498 static void compose_allow_user_actions (Compose *compose, gboolean allow);
501 static void compose_check_all (Compose *compose);
502 static void compose_highlight_all (Compose *compose);
503 static void compose_check_backwards (Compose *compose);
504 static void compose_check_forwards_go (Compose *compose);
507 static gint compose_defer_auto_save_draft (Compose *compose);
508 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
510 static GtkItemFactoryEntry compose_popup_entries[] =
512 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
513 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
514 {N_("/---"), NULL, NULL, 0, "<Separator>"},
515 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
518 static GtkItemFactoryEntry compose_entries[] =
520 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
521 {N_("/_Message/_Send"), "<control>Return",
522 compose_send_cb, 0, NULL},
523 {N_("/_Message/Send _later"), "<shift><control>S",
524 compose_send_later_cb, 0, NULL},
525 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
526 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
527 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
528 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
529 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
530 {N_("/_Message/_Save"),
531 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
532 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
533 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
535 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
536 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
537 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
538 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
539 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
540 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
541 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
542 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
543 {N_("/_Edit/Special paste/as _quotation"),
544 NULL, compose_paste_as_quote_cb, 0, NULL},
545 {N_("/_Edit/Special paste/_wrapped"),
546 NULL, compose_paste_wrap_cb, 0, NULL},
547 {N_("/_Edit/Special paste/_unwrapped"),
548 NULL, compose_paste_no_wrap_cb, 0, NULL},
549 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
550 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
551 {N_("/_Edit/A_dvanced/Move a character backward"),
553 compose_advanced_action_cb,
554 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
556 {N_("/_Edit/A_dvanced/Move a character forward"),
558 compose_advanced_action_cb,
559 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
561 {N_("/_Edit/A_dvanced/Move a word backward"),
563 compose_advanced_action_cb,
564 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
566 {N_("/_Edit/A_dvanced/Move a word forward"),
568 compose_advanced_action_cb,
569 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
571 {N_("/_Edit/A_dvanced/Move to beginning of line"),
572 NULL, /* "<control>A" */
573 compose_advanced_action_cb,
574 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
576 {N_("/_Edit/A_dvanced/Move to end of line"),
578 compose_advanced_action_cb,
579 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
581 {N_("/_Edit/A_dvanced/Move to previous line"),
583 compose_advanced_action_cb,
584 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
586 {N_("/_Edit/A_dvanced/Move to next line"),
588 compose_advanced_action_cb,
589 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
591 {N_("/_Edit/A_dvanced/Delete a character backward"),
593 compose_advanced_action_cb,
594 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
596 {N_("/_Edit/A_dvanced/Delete a character forward"),
598 compose_advanced_action_cb,
599 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
601 {N_("/_Edit/A_dvanced/Delete a word backward"),
602 NULL, /* "<control>W" */
603 compose_advanced_action_cb,
604 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
606 {N_("/_Edit/A_dvanced/Delete a word forward"),
607 NULL, /* "<alt>D", */
608 compose_advanced_action_cb,
609 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
611 {N_("/_Edit/A_dvanced/Delete line"),
613 compose_advanced_action_cb,
614 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
616 {N_("/_Edit/A_dvanced/Delete entire line"),
618 compose_advanced_action_cb,
619 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
621 {N_("/_Edit/A_dvanced/Delete to end of line"),
623 compose_advanced_action_cb,
624 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
626 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
628 "<control>F", compose_find_cb, 0, NULL},
629 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
630 {N_("/_Edit/_Wrap current paragraph"),
631 "<control>L", compose_wrap_cb, 0, NULL},
632 {N_("/_Edit/Wrap all long _lines"),
633 "<control><alt>L", compose_wrap_cb, 1, NULL},
634 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
635 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
636 {N_("/_Edit/Edit with e_xternal editor"),
637 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
639 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
640 {N_("/_Spelling/_Check all or check selection"),
641 NULL, compose_check_all, 0, NULL},
642 {N_("/_Spelling/_Highlight all misspelled words"),
643 NULL, compose_highlight_all, 0, NULL},
644 {N_("/_Spelling/Check _backwards misspelled word"),
645 NULL, compose_check_backwards , 0, NULL},
646 {N_("/_Spelling/_Forward to next misspelled word"),
647 NULL, compose_check_forwards_go, 0, NULL},
648 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
649 {N_("/_Spelling/Options"),
650 NULL, NULL, 0, "<Branch>"},
652 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
653 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
654 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
655 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
656 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
657 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
658 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
659 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
660 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
661 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
662 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
663 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
664 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
665 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
666 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
667 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
668 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
670 #define ENC_ACTION(action) \
671 NULL, compose_set_encoding_cb, action, \
672 "/Options/Character encoding/Automatic"
674 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
675 {N_("/_Options/Character _encoding/_Automatic"),
676 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
677 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
679 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
680 ENC_ACTION(C_US_ASCII)},
681 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
682 ENC_ACTION(C_UTF_8)},
683 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
685 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
686 ENC_ACTION(C_ISO_8859_1)},
687 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
688 ENC_ACTION(C_ISO_8859_15)},
689 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
690 ENC_ACTION(C_WINDOWS_1252)},
691 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
693 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
694 ENC_ACTION(C_ISO_8859_2)},
695 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
697 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
698 ENC_ACTION(C_ISO_8859_13)},
699 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
700 ENC_ACTION(C_ISO_8859_4)},
701 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
703 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
704 ENC_ACTION(C_ISO_8859_7)},
705 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
707 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
708 ENC_ACTION(C_ISO_8859_8)},
709 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
710 ENC_ACTION(C_WINDOWS_1255)},
711 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
713 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
714 ENC_ACTION(C_ISO_8859_6)},
715 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
716 ENC_ACTION(C_CP1256)},
717 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
719 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
720 ENC_ACTION(C_ISO_8859_9)},
721 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
723 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
724 ENC_ACTION(C_ISO_8859_5)},
725 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
726 ENC_ACTION(C_KOI8_R)},
727 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
728 ENC_ACTION(C_KOI8_U)},
729 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
730 ENC_ACTION(C_WINDOWS_1251)},
731 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
733 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
734 ENC_ACTION(C_ISO_2022_JP)},
735 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
737 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
738 ENC_ACTION(C_GB2312)},
739 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
741 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
743 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
744 ENC_ACTION(C_EUC_TW)},
745 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
747 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
748 ENC_ACTION(C_EUC_KR)},
749 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
751 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
752 ENC_ACTION(C_TIS_620)},
753 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
754 ENC_ACTION(C_WINDOWS_874)},
756 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
757 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
758 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
759 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
760 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
761 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
762 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
765 static GtkTargetEntry compose_mime_types[] =
767 {"text/uri-list", 0, 0},
768 {"text/plain", 0, 0},
772 static gboolean compose_put_existing_to_front(MsgInfo *info)
774 GList *compose_list = compose_get_compose_list();
778 for (elem = compose_list; elem != NULL && elem->data != NULL;
780 Compose *c = (Compose*)elem->data;
782 if (!c->targetinfo || !c->targetinfo->msgid ||
786 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
787 gtkut_window_popup(c->window);
795 static GdkColor quote_color1 =
796 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
797 static GdkColor quote_color2 =
798 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
799 static GdkColor quote_color3 =
800 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
802 static GdkColor quote_bgcolor1 =
803 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
804 static GdkColor quote_bgcolor2 =
805 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
806 static GdkColor quote_bgcolor3 =
807 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
809 static GdkColor signature_color = {
816 static GdkColor uri_color = {
823 static void compose_create_tags(GtkTextView *text, Compose *compose)
825 GtkTextBuffer *buffer;
826 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
832 buffer = gtk_text_view_get_buffer(text);
834 if (prefs_common.enable_color) {
835 /* grab the quote colors, converting from an int to a GdkColor */
836 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
838 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
840 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
842 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
844 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
846 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
848 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
850 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
853 signature_color = quote_color1 = quote_color2 = quote_color3 =
854 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black;
857 if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
858 gtk_text_buffer_create_tag(buffer, "quote0",
859 "foreground-gdk", "e_color1,
860 "paragraph-background-gdk", "e_bgcolor1,
862 gtk_text_buffer_create_tag(buffer, "quote1",
863 "foreground-gdk", "e_color2,
864 "paragraph-background-gdk", "e_bgcolor2,
866 gtk_text_buffer_create_tag(buffer, "quote2",
867 "foreground-gdk", "e_color3,
868 "paragraph-background-gdk", "e_bgcolor3,
871 gtk_text_buffer_create_tag(buffer, "quote0",
872 "foreground-gdk", "e_color1,
874 gtk_text_buffer_create_tag(buffer, "quote1",
875 "foreground-gdk", "e_color2,
877 gtk_text_buffer_create_tag(buffer, "quote2",
878 "foreground-gdk", "e_color3,
882 gtk_text_buffer_create_tag(buffer, "signature",
883 "foreground-gdk", &signature_color,
885 gtk_text_buffer_create_tag(buffer, "link",
886 "foreground-gdk", &uri_color,
888 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
889 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
891 color[0] = quote_color1;
892 color[1] = quote_color2;
893 color[2] = quote_color3;
894 color[3] = quote_bgcolor1;
895 color[4] = quote_bgcolor2;
896 color[5] = quote_bgcolor3;
897 color[6] = signature_color;
898 color[7] = uri_color;
899 cmap = gdk_drawable_get_colormap(compose->window->window);
900 gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
902 for (i = 0; i < 8; i++) {
903 if (success[i] == FALSE) {
906 g_warning("Compose: color allocation failed.\n");
907 style = gtk_widget_get_style(GTK_WIDGET(text));
908 quote_color1 = quote_color2 = quote_color3 =
909 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 =
910 signature_color = uri_color = black;
915 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
916 GPtrArray *attach_files)
918 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
921 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
923 return compose_generic_new(account, NULL, item, NULL, NULL);
926 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
928 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
931 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
932 GPtrArray *attach_files, GList *listAddress )
935 GtkTextView *textview;
936 GtkTextBuffer *textbuf;
938 GtkItemFactory *ifactory;
940 if (item && item->prefs && item->prefs->enable_default_account)
941 account = account_find_from_id(item->prefs->default_account);
943 if (!account) account = cur_account;
944 g_return_val_if_fail(account != NULL, NULL);
946 compose = compose_create(account, COMPOSE_NEW, FALSE);
948 ifactory = gtk_item_factory_from_widget(compose->menubar);
950 compose->replyinfo = NULL;
951 compose->fwdinfo = NULL;
953 textview = GTK_TEXT_VIEW(compose->text);
954 textbuf = gtk_text_view_get_buffer(textview);
955 compose_create_tags(textview, compose);
957 undo_block(compose->undostruct);
959 if (item && item->prefs && item->prefs->enable_default_dictionary &&
961 gtkaspell_change_dict(compose->gtkaspell,
962 item->prefs->default_dictionary);
963 compose_spell_menu_changed(compose);
966 if (account->auto_sig)
967 compose_insert_sig(compose, FALSE);
968 gtk_text_buffer_get_start_iter(textbuf, &iter);
969 gtk_text_buffer_place_cursor(textbuf, &iter);
971 if (account->protocol != A_NNTP) {
972 if (mailto && *mailto != '\0') {
973 compose_entries_set(compose, mailto);
975 } else if (item && item->prefs->enable_default_to) {
976 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
977 compose_entry_mark_default_to(compose, item->prefs->default_to);
979 if (item && item->ret_rcpt) {
980 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
984 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
986 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
989 * CLAWS: just don't allow return receipt request, even if the user
990 * may want to send an email. simple but foolproof.
992 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
994 compose_add_field_list( compose, listAddress );
1000 for (i = 0; i < attach_files->len; i++) {
1001 file = g_ptr_array_index(attach_files, i);
1002 compose_attach_append(compose, file, file, NULL);
1006 compose_show_first_last_header(compose, TRUE);
1008 /* Set save folder */
1009 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1010 gchar *folderidentifier;
1012 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1013 folderidentifier = folder_item_get_identifier(item);
1014 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1015 g_free(folderidentifier);
1018 gtk_widget_grab_focus(compose->header_last->entry);
1020 undo_unblock(compose->undostruct);
1022 if (prefs_common.auto_exteditor)
1023 compose_exec_ext_editor(compose);
1025 compose->modified = FALSE;
1026 compose_set_title(compose);
1030 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1031 gboolean override_pref)
1033 gchar *privacy = NULL;
1035 g_return_if_fail(compose != NULL);
1036 g_return_if_fail(account != NULL);
1038 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1041 if (account->default_privacy_system
1042 && strlen(account->default_privacy_system)) {
1043 privacy = account->default_privacy_system;
1045 GSList *privacy_avail = privacy_get_system_ids();
1046 if (privacy_avail && g_slist_length(privacy_avail)) {
1047 privacy = (gchar *)(privacy_avail->data);
1050 if (privacy != NULL) {
1051 compose->privacy_system = g_strdup(privacy);
1052 compose_update_privacy_system_menu_item(compose, FALSE);
1053 compose_use_encryption(compose, TRUE);
1057 static void compose_force_signing(Compose *compose, PrefsAccount *account)
1059 gchar *privacy = NULL;
1061 if (account->default_privacy_system
1062 && strlen(account->default_privacy_system)) {
1063 privacy = account->default_privacy_system;
1065 GSList *privacy_avail = privacy_get_system_ids();
1066 if (privacy_avail && g_slist_length(privacy_avail)) {
1067 privacy = (gchar *)(privacy_avail->data);
1070 if (privacy != NULL) {
1071 compose->privacy_system = g_strdup(privacy);
1072 compose_update_privacy_system_menu_item(compose, FALSE);
1073 compose_use_signing(compose, TRUE);
1077 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1081 Compose *compose = NULL;
1082 g_return_val_if_fail(msginfo_list != NULL, NULL);
1084 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1085 g_return_val_if_fail(msginfo != NULL, NULL);
1087 list_len = g_slist_length(msginfo_list);
1091 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1092 FALSE, prefs_common.default_reply_list, FALSE, body);
1094 case COMPOSE_REPLY_WITH_QUOTE:
1095 compose = compose_reply(msginfo, TRUE,
1096 FALSE, prefs_common.default_reply_list, FALSE, body);
1098 case COMPOSE_REPLY_WITHOUT_QUOTE:
1099 compose = compose_reply(msginfo, FALSE,
1100 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1102 case COMPOSE_REPLY_TO_SENDER:
1103 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1104 FALSE, FALSE, TRUE, body);
1106 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1107 compose = compose_followup_and_reply_to(msginfo,
1108 prefs_common.reply_with_quote,
1109 FALSE, FALSE, body);
1111 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1112 compose = compose_reply(msginfo, TRUE,
1113 FALSE, FALSE, TRUE, body);
1115 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1116 compose = compose_reply(msginfo, FALSE,
1117 FALSE, FALSE, TRUE, NULL);
1119 case COMPOSE_REPLY_TO_ALL:
1120 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1121 TRUE, FALSE, FALSE, body);
1123 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1124 compose = compose_reply(msginfo, TRUE,
1125 TRUE, FALSE, FALSE, body);
1127 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1128 compose = compose_reply(msginfo, FALSE,
1129 TRUE, FALSE, FALSE, NULL);
1131 case COMPOSE_REPLY_TO_LIST:
1132 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1133 FALSE, TRUE, FALSE, body);
1135 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1136 compose = compose_reply(msginfo, TRUE,
1137 FALSE, TRUE, FALSE, body);
1139 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1140 compose = compose_reply(msginfo, FALSE,
1141 FALSE, TRUE, FALSE, NULL);
1143 case COMPOSE_FORWARD:
1144 if (prefs_common.forward_as_attachment) {
1145 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1148 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1152 case COMPOSE_FORWARD_INLINE:
1153 /* check if we reply to more than one Message */
1154 if (list_len == 1) {
1155 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1158 /* more messages FALL THROUGH */
1159 case COMPOSE_FORWARD_AS_ATTACH:
1160 compose = compose_forward_multiple(NULL, msginfo_list);
1162 case COMPOSE_REDIRECT:
1163 compose = compose_redirect(NULL, msginfo, FALSE);
1166 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1171 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1172 gboolean to_ml, gboolean to_sender,
1175 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1176 to_sender, FALSE, body);
1179 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1184 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1185 to_sender, TRUE, body);
1188 static void compose_extract_original_charset(Compose *compose)
1190 MsgInfo *info = NULL;
1191 if (compose->replyinfo) {
1192 info = compose->replyinfo;
1193 } else if (compose->fwdinfo) {
1194 info = compose->fwdinfo;
1195 } else if (compose->targetinfo) {
1196 info = compose->targetinfo;
1199 MimeInfo *mimeinfo = procmime_scan_message(info);
1200 MimeInfo *partinfo = mimeinfo;
1201 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1202 partinfo = procmime_mimeinfo_next(partinfo);
1204 compose->orig_charset =
1205 g_strdup(procmime_mimeinfo_get_parameter(
1206 partinfo, "charset"));
1208 procmime_mimeinfo_free_all(mimeinfo);
1212 #define SIGNAL_BLOCK(buffer) { \
1213 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1214 G_CALLBACK(compose_changed_cb), \
1216 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1217 G_CALLBACK(text_inserted), \
1221 #define SIGNAL_UNBLOCK(buffer) { \
1222 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1223 G_CALLBACK(compose_changed_cb), \
1225 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1226 G_CALLBACK(text_inserted), \
1230 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1231 gboolean to_all, gboolean to_ml,
1233 gboolean followup_and_reply_to,
1236 GtkItemFactory *ifactory;
1238 PrefsAccount *account = NULL;
1239 PrefsAccount *reply_account;
1240 GtkTextView *textview;
1241 GtkTextBuffer *textbuf;
1243 g_return_val_if_fail(msginfo != NULL, NULL);
1244 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1246 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1248 g_return_val_if_fail(account != NULL, NULL);
1250 if (to_sender && account->protocol == A_NNTP &&
1251 !followup_and_reply_to) {
1253 account_find_from_address(account->address);
1255 reply_account = compose_current_mail_account();
1259 reply_account = account;
1261 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1263 compose->updating = TRUE;
1265 ifactory = gtk_item_factory_from_widget(compose->menubar);
1267 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1268 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1270 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1271 if (!compose->replyinfo)
1272 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1274 compose_extract_original_charset(compose);
1276 if (msginfo->folder && msginfo->folder->ret_rcpt)
1277 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1279 /* Set save folder */
1280 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1281 gchar *folderidentifier;
1283 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1284 folderidentifier = folder_item_get_identifier(msginfo->folder);
1285 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1286 g_free(folderidentifier);
1289 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1290 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1291 to_sender, followup_and_reply_to);
1292 compose_show_first_last_header(compose, TRUE);
1294 textview = (GTK_TEXT_VIEW(compose->text));
1295 textbuf = gtk_text_view_get_buffer(textview);
1296 compose_create_tags(textview, compose);
1298 undo_block(compose->undostruct);
1300 if (msginfo->folder && msginfo->folder->prefs &&
1301 msginfo->folder->prefs &&
1302 msginfo->folder->prefs->enable_default_dictionary &&
1304 gtkaspell_change_dict(compose->gtkaspell,
1305 msginfo->folder->prefs->default_dictionary);
1311 if (prefs_common.quotemark && *prefs_common.quotemark)
1312 qmark = prefs_common.quotemark;
1316 compose_quote_fmt(compose, compose->replyinfo,
1317 prefs_common.quotefmt,
1318 qmark, body, FALSE);
1319 quote_fmt_reset_vartable();
1321 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1322 compose_force_encryption(compose, account, FALSE);
1325 SIGNAL_BLOCK(textbuf);
1327 if (account->auto_sig)
1328 compose_insert_sig(compose, FALSE);
1330 compose_wrap_all(compose);
1332 SIGNAL_UNBLOCK(textbuf);
1334 gtk_widget_grab_focus(compose->text);
1336 undo_unblock(compose->undostruct);
1338 if (prefs_common.auto_exteditor)
1339 compose_exec_ext_editor(compose);
1341 compose->modified = FALSE;
1342 compose_set_title(compose);
1344 compose->updating = FALSE;
1346 if (compose->deferred_destroy) {
1347 compose_destroy(compose);
1354 #define INSERT_FW_HEADER(var, hdr) \
1355 if (msginfo->var && *msginfo->var) { \
1356 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1357 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1358 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1361 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1362 gboolean as_attach, const gchar *body,
1363 gboolean no_extedit,
1367 GtkTextView *textview;
1368 GtkTextBuffer *textbuf;
1371 g_return_val_if_fail(msginfo != NULL, NULL);
1372 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1375 !(account = compose_guess_forward_account_from_msginfo
1377 account = cur_account;
1379 compose = compose_create(account, COMPOSE_FORWARD, batch);
1381 compose->updating = TRUE;
1382 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1383 if (!compose->fwdinfo)
1384 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1386 compose_extract_original_charset(compose);
1388 if (msginfo->subject && *msginfo->subject) {
1389 gchar *buf, *buf2, *p;
1391 buf = p = g_strdup(msginfo->subject);
1392 p += subject_get_prefix_length(p);
1393 memmove(buf, p, strlen(p) + 1);
1395 buf2 = g_strdup_printf("Fw: %s", buf);
1396 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1402 textview = GTK_TEXT_VIEW(compose->text);
1403 textbuf = gtk_text_view_get_buffer(textview);
1404 compose_create_tags(textview, compose);
1406 undo_block(compose->undostruct);
1410 msgfile = procmsg_get_message_file_path(msginfo);
1411 if (!is_file_exist(msgfile))
1412 g_warning("%s: file not exist\n", msgfile);
1414 compose_attach_append(compose, msgfile, msgfile,
1420 MsgInfo *full_msginfo;
1422 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1424 full_msginfo = procmsg_msginfo_copy(msginfo);
1426 if (prefs_common.fw_quotemark &&
1427 *prefs_common.fw_quotemark)
1428 qmark = prefs_common.fw_quotemark;
1432 compose_quote_fmt(compose, full_msginfo,
1433 prefs_common.fw_quotefmt,
1434 qmark, body, FALSE);
1435 quote_fmt_reset_vartable();
1436 compose_attach_parts(compose, msginfo);
1438 procmsg_msginfo_free(full_msginfo);
1441 SIGNAL_BLOCK(textbuf);
1443 if (account->auto_sig)
1444 compose_insert_sig(compose, FALSE);
1446 compose_wrap_all(compose);
1448 SIGNAL_UNBLOCK(textbuf);
1450 gtk_text_buffer_get_start_iter(textbuf, &iter);
1451 gtk_text_buffer_place_cursor(textbuf, &iter);
1453 gtk_widget_grab_focus(compose->header_last->entry);
1455 if (!no_extedit && prefs_common.auto_exteditor)
1456 compose_exec_ext_editor(compose);
1459 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1460 gchar *folderidentifier;
1462 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1463 folderidentifier = folder_item_get_identifier(msginfo->folder);
1464 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1465 g_free(folderidentifier);
1468 undo_unblock(compose->undostruct);
1470 compose->modified = FALSE;
1471 compose_set_title(compose);
1473 compose->updating = FALSE;
1475 if (compose->deferred_destroy) {
1476 compose_destroy(compose);
1483 #undef INSERT_FW_HEADER
1485 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1488 GtkTextView *textview;
1489 GtkTextBuffer *textbuf;
1493 gboolean single_mail = TRUE;
1495 g_return_val_if_fail(msginfo_list != NULL, NULL);
1497 if (g_slist_length(msginfo_list) > 1)
1498 single_mail = FALSE;
1500 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1501 if (((MsgInfo *)msginfo->data)->folder == NULL)
1504 /* guess account from first selected message */
1506 !(account = compose_guess_forward_account_from_msginfo
1507 (msginfo_list->data)))
1508 account = cur_account;
1510 g_return_val_if_fail(account != NULL, NULL);
1512 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1513 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1514 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1517 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1519 compose->updating = TRUE;
1521 textview = GTK_TEXT_VIEW(compose->text);
1522 textbuf = gtk_text_view_get_buffer(textview);
1523 compose_create_tags(textview, compose);
1525 undo_block(compose->undostruct);
1526 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1527 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1529 if (!is_file_exist(msgfile))
1530 g_warning("%s: file not exist\n", msgfile);
1532 compose_attach_append(compose, msgfile, msgfile,
1538 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1539 if (info->subject && *info->subject) {
1540 gchar *buf, *buf2, *p;
1542 buf = p = g_strdup(info->subject);
1543 p += subject_get_prefix_length(p);
1544 memmove(buf, p, strlen(p) + 1);
1546 buf2 = g_strdup_printf("Fw: %s", buf);
1547 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1553 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1554 _("Fw: multiple emails"));
1557 SIGNAL_BLOCK(textbuf);
1559 if (account->auto_sig)
1560 compose_insert_sig(compose, FALSE);
1562 compose_wrap_all(compose);
1564 SIGNAL_UNBLOCK(textbuf);
1566 gtk_text_buffer_get_start_iter(textbuf, &iter);
1567 gtk_text_buffer_place_cursor(textbuf, &iter);
1569 gtk_widget_grab_focus(compose->header_last->entry);
1570 undo_unblock(compose->undostruct);
1571 compose->modified = FALSE;
1572 compose_set_title(compose);
1574 compose->updating = FALSE;
1576 if (compose->deferred_destroy) {
1577 compose_destroy(compose);
1584 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1586 GtkTextIter start = *iter;
1587 GtkTextIter end_iter;
1588 int start_pos = gtk_text_iter_get_offset(&start);
1590 if (!compose->account->sig_sep)
1593 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1594 start_pos+strlen(compose->account->sig_sep));
1596 /* check sig separator */
1597 str = gtk_text_iter_get_text(&start, &end_iter);
1598 if (!strcmp(str, compose->account->sig_sep)) {
1600 /* check end of line (\n) */
1601 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1602 start_pos+strlen(compose->account->sig_sep));
1603 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1604 start_pos+strlen(compose->account->sig_sep)+1);
1605 tmp = gtk_text_iter_get_text(&start, &end_iter);
1606 if (!strcmp(tmp,"\n")) {
1618 static void compose_colorize_signature(Compose *compose)
1620 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1622 GtkTextIter end_iter;
1623 gtk_text_buffer_get_start_iter(buffer, &iter);
1624 while (gtk_text_iter_forward_line(&iter))
1625 if (compose_is_sig_separator(compose, buffer, &iter)) {
1626 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1627 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1631 Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
1633 Compose *compose = NULL;
1634 PrefsAccount *account = NULL;
1635 GtkTextView *textview;
1636 GtkTextBuffer *textbuf;
1640 gchar buf[BUFFSIZE];
1641 gboolean use_signing = FALSE;
1642 gboolean use_encryption = FALSE;
1643 gchar *privacy_system = NULL;
1645 g_return_val_if_fail(msginfo != NULL, NULL);
1646 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1648 if (compose_put_existing_to_front(msginfo)) {
1652 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1653 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1654 gchar queueheader_buf[BUFFSIZE];
1657 /* Select Account from queue headers */
1658 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1659 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1660 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1661 account = account_find_from_id(id);
1663 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1664 sizeof(queueheader_buf), "NAID:")) {
1665 id = atoi(&queueheader_buf[strlen("NAID:")]);
1666 account = account_find_from_id(id);
1668 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1669 sizeof(queueheader_buf), "MAID:")) {
1670 id = atoi(&queueheader_buf[strlen("MAID:")]);
1671 account = account_find_from_id(id);
1673 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1674 sizeof(queueheader_buf), "S:")) {
1675 account = account_find_from_address(queueheader_buf);
1677 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1678 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1679 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1680 use_signing = param;
1683 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1684 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1685 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1686 use_encryption = param;
1688 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1689 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1690 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1692 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1693 sizeof(queueheader_buf), "X-Priority: ")) {
1694 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1695 compose->priority = param;
1698 account = msginfo->folder->folder->account;
1701 if (!account && prefs_common.reedit_account_autosel) {
1702 gchar from[BUFFSIZE];
1703 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1704 extract_address(from);
1705 account = account_find_from_address(from);
1709 account = cur_account;
1711 g_return_val_if_fail(account != NULL, NULL);
1713 compose = compose_create(account, COMPOSE_REEDIT, batch);
1715 compose->updating = TRUE;
1717 if (privacy_system != NULL) {
1718 compose->privacy_system = privacy_system;
1719 compose_use_signing(compose, use_signing);
1720 compose_use_encryption(compose, use_encryption);
1721 compose_update_privacy_system_menu_item(compose, FALSE);
1723 activate_privacy_system(compose, account, FALSE);
1726 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1728 compose_extract_original_charset(compose);
1730 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1731 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1732 gchar queueheader_buf[BUFFSIZE];
1734 /* Set message save folder */
1735 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1738 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1739 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1740 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1742 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1743 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1745 GtkItemFactory *ifactory;
1746 ifactory = gtk_item_factory_from_widget(compose->menubar);
1747 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1752 if (compose_parse_header(compose, msginfo) < 0) {
1753 compose->updating = FALSE;
1754 compose_destroy(compose);
1757 compose_reedit_set_entry(compose, msginfo);
1759 textview = GTK_TEXT_VIEW(compose->text);
1760 textbuf = gtk_text_view_get_buffer(textview);
1761 compose_create_tags(textview, compose);
1763 mark = gtk_text_buffer_get_insert(textbuf);
1764 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1766 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1767 G_CALLBACK(compose_changed_cb),
1770 if (procmime_msginfo_is_encrypted(msginfo)) {
1771 fp = procmime_get_first_encrypted_text_content(msginfo);
1773 compose_force_encryption(compose, account, TRUE);
1776 fp = procmime_get_first_text_content(msginfo);
1779 g_warning("Can't get text part\n");
1783 gboolean prev_autowrap = compose->autowrap;
1785 compose->autowrap = FALSE;
1786 while (fgets(buf, sizeof(buf), fp) != NULL) {
1788 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1790 compose_wrap_all_full(compose, FALSE);
1791 compose->autowrap = prev_autowrap;
1795 compose_attach_parts(compose, msginfo);
1797 compose_colorize_signature(compose);
1799 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1800 G_CALLBACK(compose_changed_cb),
1803 gtk_widget_grab_focus(compose->text);
1805 if (prefs_common.auto_exteditor) {
1806 compose_exec_ext_editor(compose);
1808 compose->modified = FALSE;
1809 compose_set_title(compose);
1811 compose->updating = FALSE;
1813 if (compose->deferred_destroy) {
1814 compose_destroy(compose);
1818 compose->sig_str = compose_get_signature_str(compose);
1823 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
1828 GtkItemFactory *ifactory;
1831 g_return_val_if_fail(msginfo != NULL, NULL);
1834 account = account_get_reply_account(msginfo,
1835 prefs_common.reply_account_autosel);
1836 g_return_val_if_fail(account != NULL, NULL);
1838 compose = compose_create(account, COMPOSE_REDIRECT, batch);
1840 compose->updating = TRUE;
1842 ifactory = gtk_item_factory_from_widget(compose->menubar);
1843 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1844 compose->replyinfo = NULL;
1845 compose->fwdinfo = NULL;
1847 compose_show_first_last_header(compose, TRUE);
1849 gtk_widget_grab_focus(compose->header_last->entry);
1851 filename = procmsg_get_message_file_path(msginfo);
1853 if (filename == NULL) {
1854 compose->updating = FALSE;
1855 compose_destroy(compose);
1860 compose->redirect_filename = filename;
1862 /* Set save folder */
1863 item = msginfo->folder;
1864 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1865 gchar *folderidentifier;
1867 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1868 folderidentifier = folder_item_get_identifier(item);
1869 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1870 g_free(folderidentifier);
1873 compose_attach_parts(compose, msginfo);
1875 if (msginfo->subject)
1876 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1878 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1880 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1881 quote_fmt_reset_vartable();
1882 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1884 compose_colorize_signature(compose);
1886 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1887 menu_set_sensitive(ifactory, "/Add...", FALSE);
1888 menu_set_sensitive(ifactory, "/Remove", FALSE);
1889 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1891 ifactory = gtk_item_factory_from_widget(compose->menubar);
1892 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1893 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1894 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1895 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1896 menu_set_sensitive(ifactory, "/Edit", FALSE);
1897 menu_set_sensitive(ifactory, "/Options", FALSE);
1898 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1899 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1901 if (compose->toolbar->draft_btn)
1902 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1903 if (compose->toolbar->insert_btn)
1904 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1905 if (compose->toolbar->attach_btn)
1906 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1907 if (compose->toolbar->sig_btn)
1908 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1909 if (compose->toolbar->exteditor_btn)
1910 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1911 if (compose->toolbar->linewrap_current_btn)
1912 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1913 if (compose->toolbar->linewrap_all_btn)
1914 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1916 compose->modified = FALSE;
1917 compose_set_title(compose);
1918 compose->updating = FALSE;
1920 if (compose->deferred_destroy) {
1921 compose_destroy(compose);
1928 GList *compose_get_compose_list(void)
1930 return compose_list;
1933 void compose_entry_append(Compose *compose, const gchar *address,
1934 ComposeEntryType type)
1938 gboolean in_quote = FALSE;
1939 if (!address || *address == '\0') return;
1946 header = N_("Bcc:");
1948 case COMPOSE_REPLYTO:
1949 header = N_("Reply-To:");
1951 case COMPOSE_NEWSGROUPS:
1952 header = N_("Newsgroups:");
1954 case COMPOSE_FOLLOWUPTO:
1955 header = N_( "Followup-To:");
1962 header = prefs_common.trans_hdr ? gettext(header) : header;
1964 cur = begin = (gchar *)address;
1966 /* we separate the line by commas, but not if we're inside a quoted
1968 while (*cur != '\0') {
1970 in_quote = !in_quote;
1971 if (*cur == ',' && !in_quote) {
1972 gchar *tmp = g_strdup(begin);
1974 tmp[cur-begin]='\0';
1977 while (*tmp == ' ' || *tmp == '\t')
1979 compose_add_header_entry(compose, header, tmp);
1986 gchar *tmp = g_strdup(begin);
1988 tmp[cur-begin]='\0';
1991 while (*tmp == ' ' || *tmp == '\t')
1993 compose_add_header_entry(compose, header, tmp);
1998 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
2000 static GdkColor yellow;
2001 static GdkColor black;
2002 static gboolean yellow_initialised = FALSE;
2006 if (!yellow_initialised) {
2007 gdk_color_parse("#f5f6be", &yellow);
2008 gdk_color_parse("#000000", &black);
2009 yellow_initialised = gdk_colormap_alloc_color(
2010 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
2011 yellow_initialised &= gdk_colormap_alloc_color(
2012 gdk_colormap_get_system(), &black, FALSE, TRUE);
2015 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
2016 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
2017 if (gtk_entry_get_text(entry) &&
2018 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
2019 if (yellow_initialised) {
2020 gtk_widget_modify_base(
2021 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2022 GTK_STATE_NORMAL, &yellow);
2023 gtk_widget_modify_text(
2024 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2025 GTK_STATE_NORMAL, &black);
2031 void compose_toolbar_cb(gint action, gpointer data)
2033 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2034 Compose *compose = (Compose*)toolbar_item->parent;
2036 g_return_if_fail(compose != NULL);
2040 compose_send_cb(compose, 0, NULL);
2043 compose_send_later_cb(compose, 0, NULL);
2046 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2049 compose_insert_file_cb(compose, 0, NULL);
2052 compose_attach_cb(compose, 0, NULL);
2055 compose_insert_sig(compose, FALSE);
2058 compose_ext_editor_cb(compose, 0, NULL);
2060 case A_LINEWRAP_CURRENT:
2061 compose_beautify_paragraph(compose, NULL, TRUE);
2063 case A_LINEWRAP_ALL:
2064 compose_wrap_all_full(compose, TRUE);
2067 compose_address_cb(compose, 0, NULL);
2070 case A_CHECK_SPELLING:
2071 compose_check_all(compose);
2079 static void compose_entries_set(Compose *compose, const gchar *mailto)
2083 gchar *subject = NULL;
2088 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
2091 compose_entry_append(compose, to, COMPOSE_TO);
2093 compose_entry_append(compose, cc, COMPOSE_CC);
2095 if (!g_utf8_validate (subject, -1, NULL)) {
2096 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2097 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2100 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2104 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2105 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2108 gboolean prev_autowrap = compose->autowrap;
2110 compose->autowrap = FALSE;
2112 mark = gtk_text_buffer_get_insert(buffer);
2113 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2115 if (!g_utf8_validate (body, -1, NULL)) {
2116 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2117 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2120 gtk_text_buffer_insert(buffer, &iter, body, -1);
2122 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2124 compose->autowrap = prev_autowrap;
2125 if (compose->autowrap)
2126 compose_wrap_all(compose);
2135 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2137 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2138 {"Cc:", NULL, TRUE},
2139 {"References:", NULL, FALSE},
2140 {"Bcc:", NULL, TRUE},
2141 {"Newsgroups:", NULL, TRUE},
2142 {"Followup-To:", NULL, TRUE},
2143 {"List-Post:", NULL, FALSE},
2144 {"X-Priority:", NULL, FALSE},
2145 {NULL, NULL, FALSE}};
2161 g_return_val_if_fail(msginfo != NULL, -1);
2163 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2164 procheader_get_header_fields(fp, hentry);
2167 if (hentry[H_REPLY_TO].body != NULL) {
2168 if (hentry[H_REPLY_TO].body[0] != '\0') {
2170 conv_unmime_header(hentry[H_REPLY_TO].body,
2173 g_free(hentry[H_REPLY_TO].body);
2174 hentry[H_REPLY_TO].body = NULL;
2176 if (hentry[H_CC].body != NULL) {
2177 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2178 g_free(hentry[H_CC].body);
2179 hentry[H_CC].body = NULL;
2181 if (hentry[H_REFERENCES].body != NULL) {
2182 if (compose->mode == COMPOSE_REEDIT)
2183 compose->references = hentry[H_REFERENCES].body;
2185 compose->references = compose_parse_references
2186 (hentry[H_REFERENCES].body, msginfo->msgid);
2187 g_free(hentry[H_REFERENCES].body);
2189 hentry[H_REFERENCES].body = NULL;
2191 if (hentry[H_BCC].body != NULL) {
2192 if (compose->mode == COMPOSE_REEDIT)
2194 conv_unmime_header(hentry[H_BCC].body, NULL);
2195 g_free(hentry[H_BCC].body);
2196 hentry[H_BCC].body = NULL;
2198 if (hentry[H_NEWSGROUPS].body != NULL) {
2199 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2200 hentry[H_NEWSGROUPS].body = NULL;
2202 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2203 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2204 compose->followup_to =
2205 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2208 g_free(hentry[H_FOLLOWUP_TO].body);
2209 hentry[H_FOLLOWUP_TO].body = NULL;
2211 if (hentry[H_LIST_POST].body != NULL) {
2214 extract_address(hentry[H_LIST_POST].body);
2215 if (hentry[H_LIST_POST].body[0] != '\0') {
2216 scan_mailto_url(hentry[H_LIST_POST].body,
2217 &to, NULL, NULL, NULL, NULL);
2219 g_free(compose->ml_post);
2220 compose->ml_post = to;
2223 g_free(hentry[H_LIST_POST].body);
2224 hentry[H_LIST_POST].body = NULL;
2227 /* CLAWS - X-Priority */
2228 if (compose->mode == COMPOSE_REEDIT)
2229 if (hentry[H_X_PRIORITY].body != NULL) {
2232 priority = atoi(hentry[H_X_PRIORITY].body);
2233 g_free(hentry[H_X_PRIORITY].body);
2235 hentry[H_X_PRIORITY].body = NULL;
2237 if (priority < PRIORITY_HIGHEST ||
2238 priority > PRIORITY_LOWEST)
2239 priority = PRIORITY_NORMAL;
2241 compose->priority = priority;
2244 if (compose->mode == COMPOSE_REEDIT) {
2245 if (msginfo->inreplyto && *msginfo->inreplyto)
2246 compose->inreplyto = g_strdup(msginfo->inreplyto);
2250 if (msginfo->msgid && *msginfo->msgid)
2251 compose->inreplyto = g_strdup(msginfo->msgid);
2253 if (!compose->references) {
2254 if (msginfo->msgid && *msginfo->msgid) {
2255 if (msginfo->inreplyto && *msginfo->inreplyto)
2256 compose->references =
2257 g_strdup_printf("<%s>\n\t<%s>",
2261 compose->references =
2262 g_strconcat("<", msginfo->msgid, ">",
2264 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2265 compose->references =
2266 g_strconcat("<", msginfo->inreplyto, ">",
2274 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2276 GSList *ref_id_list, *cur;
2280 ref_id_list = references_list_append(NULL, ref);
2281 if (!ref_id_list) return NULL;
2282 if (msgid && *msgid)
2283 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2288 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2289 /* "<" + Message-ID + ">" + CR+LF+TAB */
2290 len += strlen((gchar *)cur->data) + 5;
2292 if (len > MAX_REFERENCES_LEN) {
2293 /* remove second message-ID */
2294 if (ref_id_list && ref_id_list->next &&
2295 ref_id_list->next->next) {
2296 g_free(ref_id_list->next->data);
2297 ref_id_list = g_slist_remove
2298 (ref_id_list, ref_id_list->next->data);
2300 slist_free_strings(ref_id_list);
2301 g_slist_free(ref_id_list);
2308 new_ref = g_string_new("");
2309 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2310 if (new_ref->len > 0)
2311 g_string_append(new_ref, "\n\t");
2312 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2315 slist_free_strings(ref_id_list);
2316 g_slist_free(ref_id_list);
2318 new_ref_str = new_ref->str;
2319 g_string_free(new_ref, FALSE);
2324 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2325 const gchar *fmt, const gchar *qmark,
2326 const gchar *body, gboolean rewrap)
2328 static MsgInfo dummyinfo;
2329 gchar *quote_str = NULL;
2331 gboolean prev_autowrap;
2332 const gchar *trimmed_body = body;
2333 gint cursor_pos = -1;
2334 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2335 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2340 SIGNAL_BLOCK(buffer);
2343 msginfo = &dummyinfo;
2345 if (qmark != NULL) {
2346 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2347 quote_fmt_scan_string(qmark);
2350 buf = quote_fmt_get_buffer();
2352 alertpanel_error(_("Quote mark format error."));
2354 Xstrdup_a(quote_str, buf, goto error)
2357 if (fmt && *fmt != '\0') {
2358 while (trimmed_body && strlen(trimmed_body) > 1
2359 && trimmed_body[0]=='\n')
2362 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2363 quote_fmt_scan_string(fmt);
2366 buf = quote_fmt_get_buffer();
2368 alertpanel_error(_("Message reply/forward format error."));
2374 prev_autowrap = compose->autowrap;
2375 compose->autowrap = FALSE;
2377 mark = gtk_text_buffer_get_insert(buffer);
2378 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2379 if (g_utf8_validate(buf, -1, NULL)) {
2380 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2382 gchar *tmpout = NULL;
2383 tmpout = conv_codeset_strdup
2384 (buf, conv_get_locale_charset_str_no_utf8(),
2386 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2388 tmpout = g_malloc(strlen(buf)*2+1);
2389 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2391 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2395 cursor_pos = quote_fmt_get_cursor_pos();
2396 compose->set_cursor_pos = cursor_pos;
2397 if (cursor_pos == -1) {
2400 gtk_text_buffer_get_start_iter(buffer, &iter);
2401 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2402 gtk_text_buffer_place_cursor(buffer, &iter);
2404 compose->autowrap = prev_autowrap;
2405 if (compose->autowrap && rewrap)
2406 compose_wrap_all(compose);
2413 SIGNAL_UNBLOCK(buffer);
2419 /* if ml_post is of type addr@host and from is of type
2420 * addr-anything@host, return TRUE
2422 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2424 gchar *left_ml = NULL;
2425 gchar *right_ml = NULL;
2426 gchar *left_from = NULL;
2427 gchar *right_from = NULL;
2428 gboolean result = FALSE;
2430 if (!ml_post || !from)
2433 left_ml = g_strdup(ml_post);
2434 if (strstr(left_ml, "@")) {
2435 right_ml = strstr(left_ml, "@")+1;
2436 *(strstr(left_ml, "@")) = '\0';
2439 left_from = g_strdup(from);
2440 if (strstr(left_from, "@")) {
2441 right_from = strstr(left_from, "@")+1;
2442 *(strstr(left_from, "@")) = '\0';
2445 if (left_ml && left_from && right_ml && right_from
2446 && !strncmp(left_from, left_ml, strlen(left_ml))
2447 && !strcmp(right_from, right_ml)) {
2456 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2458 gchar *my_addr1, *my_addr2;
2460 if (!addr1 || !addr2)
2463 Xstrdup_a(my_addr1, addr1, return FALSE);
2464 Xstrdup_a(my_addr2, addr2, return FALSE);
2466 extract_address(my_addr1);
2467 extract_address(my_addr2);
2469 return !strcmp(my_addr1, my_addr2);
2472 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2473 gboolean to_all, gboolean to_ml,
2475 gboolean followup_and_reply_to)
2477 GSList *cc_list = NULL;
2480 gchar *replyto = NULL;
2481 GHashTable *to_table;
2483 gboolean reply_to_ml = FALSE;
2484 gboolean default_reply_to = FALSE;
2486 g_return_if_fail(compose->account != NULL);
2487 g_return_if_fail(msginfo != NULL);
2489 reply_to_ml = to_ml && compose->ml_post;
2491 default_reply_to = msginfo->folder &&
2492 msginfo->folder->prefs->enable_default_reply_to;
2494 if (compose->account->protocol != A_NNTP) {
2495 if (reply_to_ml && !default_reply_to) {
2497 gboolean is_subscr = is_subscription(compose->ml_post,
2500 /* normal answer to ml post with a reply-to */
2501 compose_entry_append(compose,
2504 if (compose->replyto
2505 && !same_address(compose->ml_post, compose->replyto))
2506 compose_entry_append(compose,
2510 /* answer to subscription confirmation */
2511 if (compose->replyto)
2512 compose_entry_append(compose,
2515 else if (msginfo->from)
2516 compose_entry_append(compose,
2521 else if (!(to_all || to_sender) && default_reply_to) {
2522 compose_entry_append(compose,
2523 msginfo->folder->prefs->default_reply_to,
2525 compose_entry_mark_default_to(compose,
2526 msginfo->folder->prefs->default_reply_to);
2531 Xstrdup_a(tmp1, msginfo->from, return);
2532 extract_address(tmp1);
2533 if (to_all || to_sender ||
2534 !account_find_from_address(tmp1))
2535 compose_entry_append(compose,
2536 (compose->replyto && !to_sender)
2537 ? compose->replyto :
2538 msginfo->from ? msginfo->from : "",
2540 else if (!to_all && !to_sender) {
2541 /* reply to the last list of recipients */
2542 compose_entry_append(compose,
2543 msginfo->to ? msginfo->to : "",
2545 compose_entry_append(compose,
2546 msginfo->cc ? msginfo->cc : "",
2551 if (to_sender || (compose->followup_to &&
2552 !strncmp(compose->followup_to, "poster", 6)))
2553 compose_entry_append
2555 (compose->replyto ? compose->replyto :
2556 msginfo->from ? msginfo->from : ""),
2559 else if (followup_and_reply_to || to_all) {
2560 compose_entry_append
2562 (compose->replyto ? compose->replyto :
2563 msginfo->from ? msginfo->from : ""),
2566 compose_entry_append
2568 compose->followup_to ? compose->followup_to :
2569 compose->newsgroups ? compose->newsgroups : "",
2570 COMPOSE_NEWSGROUPS);
2573 compose_entry_append
2575 compose->followup_to ? compose->followup_to :
2576 compose->newsgroups ? compose->newsgroups : "",
2577 COMPOSE_NEWSGROUPS);
2580 if (msginfo->subject && *msginfo->subject) {
2584 buf = p = g_strdup(msginfo->subject);
2585 p += subject_get_prefix_length(p);
2586 memmove(buf, p, strlen(p) + 1);
2588 buf2 = g_strdup_printf("Re: %s", buf);
2589 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2594 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2596 if (to_ml && compose->ml_post) return;
2597 if (!to_all || compose->account->protocol == A_NNTP) return;
2599 if (compose->replyto) {
2600 Xstrdup_a(replyto, compose->replyto, return);
2601 extract_address(replyto);
2603 if (msginfo->from) {
2604 Xstrdup_a(from, msginfo->from, return);
2605 extract_address(from);
2608 if (replyto && from)
2609 cc_list = address_list_append_with_comments(cc_list, from);
2610 if (to_all && msginfo->folder &&
2611 msginfo->folder->prefs->enable_default_reply_to)
2612 cc_list = address_list_append_with_comments(cc_list,
2613 msginfo->folder->prefs->default_reply_to);
2614 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2615 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2617 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2619 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2620 if (compose->account)
2621 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2622 GINT_TO_POINTER(1));
2624 /* remove address on To: and that of current account */
2625 for (cur = cc_list; cur != NULL; ) {
2626 GSList *next = cur->next;
2629 addr = g_strdup(cur->data);
2630 extract_address(addr);
2632 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2633 cc_list = g_slist_remove(cc_list, cur->data);
2635 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2639 hash_free_strings(to_table);
2640 g_hash_table_destroy(to_table);
2643 for (cur = cc_list; cur != NULL; cur = cur->next)
2644 compose_entry_append(compose, (gchar *)cur->data,
2646 slist_free_strings(cc_list);
2647 g_slist_free(cc_list);
2652 #define SET_ENTRY(entry, str) \
2655 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2658 #define SET_ADDRESS(type, str) \
2661 compose_entry_append(compose, str, type); \
2664 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2666 g_return_if_fail(msginfo != NULL);
2668 SET_ENTRY(subject_entry, msginfo->subject);
2669 SET_ENTRY(from_name, msginfo->from);
2670 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2671 SET_ADDRESS(COMPOSE_CC, compose->cc);
2672 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2673 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2674 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2675 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2677 compose_update_priority_menu_item(compose);
2678 compose_update_privacy_system_menu_item(compose, FALSE);
2679 compose_show_first_last_header(compose, TRUE);
2685 static void compose_insert_sig(Compose *compose, gboolean replace)
2687 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2688 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2690 GtkTextIter iter, iter_end;
2692 gchar *search = NULL;
2693 gboolean prev_autowrap;
2694 gboolean found = FALSE, shift = FALSE;
2697 g_return_if_fail(compose->account != NULL);
2699 prev_autowrap = compose->autowrap;
2700 compose->autowrap = FALSE;
2702 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2703 G_CALLBACK(compose_changed_cb),
2706 mark = gtk_text_buffer_get_insert(buffer);
2707 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2708 cur_pos = gtk_text_iter_get_offset (&iter);
2710 gtk_text_buffer_get_end_iter(buffer, &iter);
2712 search = compose->sig_str;
2714 if (replace && search) {
2715 GtkTextIter first_iter, start_iter, end_iter;
2717 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2719 if (compose->sig_str[0] == '\0')
2722 found = gtk_text_iter_forward_search(&first_iter,
2724 GTK_TEXT_SEARCH_TEXT_ONLY,
2725 &start_iter, &end_iter,
2729 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2733 if (replace && !found && search && strlen(search) > 2
2734 && search[0] == '\n' && search[1] == '\n') {
2740 g_free(compose->sig_str);
2741 compose->sig_str = compose_get_signature_str(compose);
2742 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2743 compose->sig_str = g_strdup("");
2745 cur_pos = gtk_text_iter_get_offset(&iter);
2747 gtk_text_buffer_insert(buffer, &iter, compose->sig_str + 1, -1);
2749 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2751 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2752 gtk_text_iter_forward_char(&iter);
2753 gtk_text_iter_forward_char(&iter);
2754 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2755 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2757 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2758 cur_pos = gtk_text_buffer_get_char_count (buffer);
2760 /* put the cursor where it should be
2761 * either where the quote_fmt says, either before the signature */
2762 if (compose->set_cursor_pos < 0)
2763 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2765 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2766 compose->set_cursor_pos);
2768 gtk_text_buffer_place_cursor(buffer, &iter);
2769 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2770 G_CALLBACK(compose_changed_cb),
2773 compose->autowrap = prev_autowrap;
2774 if (compose->autowrap)
2775 compose_wrap_all(compose);
2778 static gchar *compose_get_signature_str(Compose *compose)
2780 gchar *sig_body = NULL;
2781 gchar *sig_str = NULL;
2782 gchar *utf8_sig_str = NULL;
2784 g_return_val_if_fail(compose->account != NULL, NULL);
2786 if (!compose->account->sig_path)
2789 if (compose->account->sig_type == SIG_FILE) {
2790 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2791 g_warning("can't open signature file: %s\n",
2792 compose->account->sig_path);
2797 if (compose->account->sig_type == SIG_COMMAND)
2798 sig_body = get_command_output(compose->account->sig_path);
2802 tmp = file_read_to_str(compose->account->sig_path);
2805 sig_body = normalize_newlines(tmp);
2809 if (compose->account->sig_sep) {
2810 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2814 sig_str = g_strconcat("\n\n", sig_body, NULL);
2817 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2818 utf8_sig_str = sig_str;
2820 utf8_sig_str = conv_codeset_strdup
2821 (sig_str, conv_get_locale_charset_str_no_utf8(),
2827 return utf8_sig_str;
2830 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2833 GtkTextBuffer *buffer;
2836 const gchar *cur_encoding;
2837 gchar buf[BUFFSIZE];
2840 gboolean prev_autowrap;
2841 gboolean badtxt = FALSE;
2843 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2845 if ((fp = g_fopen(file, "rb")) == NULL) {
2846 FILE_OP_ERROR(file, "fopen");
2847 return COMPOSE_INSERT_READ_ERROR;
2850 prev_autowrap = compose->autowrap;
2851 compose->autowrap = FALSE;
2853 text = GTK_TEXT_VIEW(compose->text);
2854 buffer = gtk_text_view_get_buffer(text);
2855 mark = gtk_text_buffer_get_insert(buffer);
2856 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2858 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2859 G_CALLBACK(text_inserted),
2862 cur_encoding = conv_get_locale_charset_str_no_utf8();
2864 while (fgets(buf, sizeof(buf), fp) != NULL) {
2867 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2868 str = g_strdup(buf);
2870 str = conv_codeset_strdup
2871 (buf, cur_encoding, CS_INTERNAL);
2874 /* strip <CR> if DOS/Windows file,
2875 replace <CR> with <LF> if Macintosh file. */
2878 if (len > 0 && str[len - 1] != '\n') {
2880 if (str[len] == '\r') str[len] = '\n';
2883 gtk_text_buffer_insert(buffer, &iter, str, -1);
2887 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2888 G_CALLBACK(text_inserted),
2890 compose->autowrap = prev_autowrap;
2891 if (compose->autowrap)
2892 compose_wrap_all(compose);
2897 return COMPOSE_INSERT_INVALID_CHARACTER;
2899 return COMPOSE_INSERT_SUCCESS;
2902 static void compose_attach_append(Compose *compose, const gchar *file,
2903 const gchar *filename,
2904 const gchar *content_type)
2912 GtkListStore *store;
2914 gboolean has_binary = FALSE;
2916 if (!is_file_exist(file)) {
2917 g_warning("File %s doesn't exist\n", filename);
2920 if ((size = get_file_size(file)) < 0) {
2921 g_warning("Can't get file size of %s\n", filename);
2925 alertpanel_notice(_("File %s is empty."), filename);
2928 if ((fp = g_fopen(file, "rb")) == NULL) {
2929 alertpanel_error(_("Can't read %s."), filename);
2934 ainfo = g_new0(AttachInfo, 1);
2935 auto_ainfo = g_auto_pointer_new_with_free
2936 (ainfo, (GFreeFunc) compose_attach_info_free);
2937 ainfo->file = g_strdup(file);
2940 ainfo->content_type = g_strdup(content_type);
2941 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2943 MsgFlags flags = {0, 0};
2945 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
2946 ainfo->encoding = ENC_7BIT;
2948 ainfo->encoding = ENC_8BIT;
2950 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2951 if (msginfo && msginfo->subject)
2952 name = g_strdup(msginfo->subject);
2954 name = g_path_get_basename(filename ? filename : file);
2956 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2958 procmsg_msginfo_free(msginfo);
2960 if (!g_ascii_strncasecmp(content_type, "text", 4))
2961 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
2963 ainfo->encoding = ENC_BASE64;
2964 name = g_path_get_basename(filename ? filename : file);
2965 ainfo->name = g_strdup(name);
2969 ainfo->content_type = procmime_get_mime_type(file);
2970 if (!ainfo->content_type) {
2971 ainfo->content_type =
2972 g_strdup("application/octet-stream");
2973 ainfo->encoding = ENC_BASE64;
2974 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2976 procmime_get_encoding_for_text_file(file, &has_binary);
2978 ainfo->encoding = ENC_BASE64;
2979 name = g_path_get_basename(filename ? filename : file);
2980 ainfo->name = g_strdup(name);
2984 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
2985 g_free(ainfo->content_type);
2986 ainfo->content_type = g_strdup("application/octet-stream");
2990 size_text = to_human_readable(size);
2992 store = GTK_LIST_STORE(gtk_tree_view_get_model
2993 (GTK_TREE_VIEW(compose->attach_clist)));
2995 gtk_list_store_append(store, &iter);
2996 gtk_list_store_set(store, &iter,
2997 COL_MIMETYPE, ainfo->content_type,
2998 COL_SIZE, size_text,
2999 COL_NAME, ainfo->name,
3001 COL_AUTODATA, auto_ainfo,
3004 g_auto_pointer_free(auto_ainfo);
3007 static void compose_use_signing(Compose *compose, gboolean use_signing)
3009 GtkItemFactory *ifactory;
3010 GtkWidget *menuitem = NULL;
3012 compose->use_signing = use_signing;
3013 ifactory = gtk_item_factory_from_widget(compose->menubar);
3014 menuitem = gtk_item_factory_get_item
3015 (ifactory, "/Options/Sign");
3016 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3020 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
3022 GtkItemFactory *ifactory;
3023 GtkWidget *menuitem = NULL;
3025 compose->use_encryption = use_encryption;
3026 ifactory = gtk_item_factory_from_widget(compose->menubar);
3027 menuitem = gtk_item_factory_get_item
3028 (ifactory, "/Options/Encrypt");
3030 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3034 #define NEXT_PART_NOT_CHILD(info) \
3036 node = info->node; \
3037 while (node->children) \
3038 node = g_node_last_child(node); \
3039 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3042 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3046 MimeInfo *firsttext = NULL;
3047 MimeInfo *encrypted = NULL;
3050 const gchar *partname = NULL;
3052 mimeinfo = procmime_scan_message(msginfo);
3053 if (!mimeinfo) return;
3055 if (mimeinfo->node->children == NULL) {
3056 procmime_mimeinfo_free_all(mimeinfo);
3060 /* find first content part */
3061 child = (MimeInfo *) mimeinfo->node->children->data;
3062 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3063 child = (MimeInfo *)child->node->children->data;
3065 if (child->type == MIMETYPE_TEXT) {
3067 debug_print("First text part found\n");
3068 } else if (compose->mode == COMPOSE_REEDIT &&
3069 child->type == MIMETYPE_APPLICATION &&
3070 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3071 encrypted = (MimeInfo *)child->node->parent->data;
3074 child = (MimeInfo *) mimeinfo->node->children->data;
3075 while (child != NULL) {
3076 if (child == encrypted) {
3077 /* skip this part of tree */
3078 NEXT_PART_NOT_CHILD(child);
3082 if (child->type == MIMETYPE_MULTIPART) {
3083 /* get the actual content */
3084 child = procmime_mimeinfo_next(child);
3088 if (child == firsttext) {
3089 child = procmime_mimeinfo_next(child);
3093 outfile = procmime_get_tmp_file_name(child);
3094 if (procmime_get_part(outfile, child) < 0)
3095 g_warning("Can't get the part of multipart message.");
3097 gchar *content_type;
3099 content_type = procmime_get_content_type_str(child->type, child->subtype);
3101 /* if we meet a pgp signature, we don't attach it, but
3102 * we force signing. */
3103 if (strcmp(content_type, "application/pgp-signature")) {
3104 partname = procmime_mimeinfo_get_parameter(child, "filename");
3105 if (partname == NULL)
3106 partname = procmime_mimeinfo_get_parameter(child, "name");
3107 if (partname == NULL)
3109 compose_attach_append(compose, outfile,
3110 partname, content_type);
3112 compose_force_signing(compose, compose->account);
3114 g_free(content_type);
3117 NEXT_PART_NOT_CHILD(child);
3119 procmime_mimeinfo_free_all(mimeinfo);
3122 #undef NEXT_PART_NOT_CHILD
3127 WAIT_FOR_INDENT_CHAR,
3128 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3131 /* return indent length, we allow:
3132 indent characters followed by indent characters or spaces/tabs,
3133 alphabets and numbers immediately followed by indent characters,
3134 and the repeating sequences of the above
3135 If quote ends with multiple spaces, only the first one is included. */
3136 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3137 const GtkTextIter *start, gint *len)
3139 GtkTextIter iter = *start;
3143 IndentState state = WAIT_FOR_INDENT_CHAR;
3146 gint alnum_count = 0;
3147 gint space_count = 0;
3150 if (prefs_common.quote_chars == NULL) {
3154 while (!gtk_text_iter_ends_line(&iter)) {
3155 wc = gtk_text_iter_get_char(&iter);
3156 if (g_unichar_iswide(wc))
3158 clen = g_unichar_to_utf8(wc, ch);
3162 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3163 is_space = g_unichar_isspace(wc);
3165 if (state == WAIT_FOR_INDENT_CHAR) {
3166 if (!is_indent && !g_unichar_isalnum(wc))
3169 quote_len += alnum_count + space_count + 1;
3170 alnum_count = space_count = 0;
3171 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3174 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3175 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3179 else if (is_indent) {
3180 quote_len += alnum_count + space_count + 1;
3181 alnum_count = space_count = 0;
3184 state = WAIT_FOR_INDENT_CHAR;
3188 gtk_text_iter_forward_char(&iter);
3191 if (quote_len > 0 && space_count > 0)
3197 if (quote_len > 0) {
3199 gtk_text_iter_forward_chars(&iter, quote_len);
3200 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3206 /* return TRUE if the line is itemized */
3207 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3208 const GtkTextIter *start)
3210 GtkTextIter iter = *start;
3215 if (gtk_text_iter_ends_line(&iter))
3219 wc = gtk_text_iter_get_char(&iter);
3220 if (!g_unichar_isspace(wc))
3222 gtk_text_iter_forward_char(&iter);
3223 if (gtk_text_iter_ends_line(&iter))
3227 clen = g_unichar_to_utf8(wc, ch);
3231 if (!strchr("*-+", ch[0]))
3234 gtk_text_iter_forward_char(&iter);
3235 if (gtk_text_iter_ends_line(&iter))
3237 wc = gtk_text_iter_get_char(&iter);
3238 if (g_unichar_isspace(wc))
3244 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3245 const GtkTextIter *start,
3246 GtkTextIter *break_pos,
3250 GtkTextIter iter = *start, line_end = *start;