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 static gint compose_write_body_to_file (Compose *compose,
271 static gint compose_remove_reedit_target (Compose *compose,
273 void compose_remove_draft (Compose *compose);
274 static gint compose_queue (Compose *compose,
278 static gint compose_queue_sub (Compose *compose,
282 gboolean check_subject);
283 static void compose_add_attachments (Compose *compose,
285 static gchar *compose_get_header (Compose *compose);
287 static void compose_convert_header (Compose *compose,
292 gboolean addr_field);
294 static void compose_attach_info_free (AttachInfo *ainfo);
295 static void compose_attach_remove_selected (Compose *compose);
297 static void compose_attach_property (Compose *compose);
298 static void compose_attach_property_create (gboolean *cancelled);
299 static void attach_property_ok (GtkWidget *widget,
300 gboolean *cancelled);
301 static void attach_property_cancel (GtkWidget *widget,
302 gboolean *cancelled);
303 static gint attach_property_delete_event (GtkWidget *widget,
305 gboolean *cancelled);
306 static gboolean attach_property_key_pressed (GtkWidget *widget,
308 gboolean *cancelled);
310 static void compose_exec_ext_editor (Compose *compose);
312 static gint compose_exec_ext_editor_real (const gchar *file);
313 static gboolean compose_ext_editor_kill (Compose *compose);
314 static gboolean compose_input_cb (GIOChannel *source,
315 GIOCondition condition,
317 static void compose_set_ext_editor_sensitive (Compose *compose,
319 #endif /* G_OS_UNIX */
321 static void compose_undo_state_changed (UndoMain *undostruct,
326 static void compose_create_header_entry (Compose *compose);
327 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
328 static void compose_update_priority_menu_item(Compose * compose);
330 static void compose_add_field_list ( Compose *compose,
331 GList *listAddress );
333 /* callback functions */
335 static gboolean compose_edit_size_alloc (GtkEditable *widget,
336 GtkAllocation *allocation,
337 GtkSHRuler *shruler);
338 static void account_activated (GtkMenuItem *menuitem,
340 static void attach_selected (GtkTreeView *tree_view,
341 GtkTreePath *tree_path,
342 GtkTreeViewColumn *column,
344 static gboolean attach_button_pressed (GtkWidget *widget,
345 GdkEventButton *event,
347 static gboolean attach_key_pressed (GtkWidget *widget,
351 static void compose_send_cb (gpointer data,
354 static void compose_send_later_cb (gpointer data,
358 static void compose_draft_cb (gpointer data,
362 static void compose_attach_cb (gpointer data,
365 static void compose_insert_file_cb (gpointer data,
368 static void compose_insert_sig_cb (gpointer data,
372 static void compose_close_cb (gpointer data,
376 static void compose_set_encoding_cb (gpointer data,
380 static void compose_address_cb (gpointer data,
383 static void compose_template_activate_cb(GtkWidget *widget,
386 static void compose_ext_editor_cb (gpointer data,
390 static gint compose_delete_cb (GtkWidget *widget,
394 static void compose_undo_cb (Compose *compose);
395 static void compose_redo_cb (Compose *compose);
396 static void compose_cut_cb (Compose *compose);
397 static void compose_copy_cb (Compose *compose);
398 static void compose_paste_cb (Compose *compose);
399 static void compose_paste_as_quote_cb (Compose *compose);
400 static void compose_paste_no_wrap_cb (Compose *compose);
401 static void compose_paste_wrap_cb (Compose *compose);
402 static void compose_allsel_cb (Compose *compose);
404 static void compose_advanced_action_cb (Compose *compose,
405 ComposeCallAdvancedAction action);
407 static void compose_grab_focus_cb (GtkWidget *widget,
410 static void compose_changed_cb (GtkTextBuffer *textbuf,
413 static void compose_wrap_cb (gpointer data,
416 static void compose_find_cb (gpointer data,
419 static void compose_toggle_autowrap_cb (gpointer data,
423 static void compose_toggle_ruler_cb (gpointer data,
426 static void compose_toggle_sign_cb (gpointer data,
429 static void compose_toggle_encrypt_cb (gpointer data,
432 static void compose_set_privacy_system_cb(GtkWidget *widget,
434 static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
435 static void activate_privacy_system (Compose *compose,
436 PrefsAccount *account,
438 static void compose_use_signing(Compose *compose, gboolean use_signing);
439 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
440 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
442 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
444 static void compose_set_priority_cb (gpointer data,
448 static void compose_attach_drag_received_cb (GtkWidget *widget,
449 GdkDragContext *drag_context,
452 GtkSelectionData *data,
456 static void compose_insert_drag_received_cb (GtkWidget *widget,
457 GdkDragContext *drag_context,
460 GtkSelectionData *data,
464 static void compose_header_drag_received_cb (GtkWidget *widget,
465 GdkDragContext *drag_context,
468 GtkSelectionData *data,
473 static gboolean compose_drag_drop (GtkWidget *widget,
474 GdkDragContext *drag_context,
476 guint time, gpointer user_data);
478 static void text_inserted (GtkTextBuffer *buffer,
483 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
484 gboolean to_all, gboolean to_ml,
486 gboolean followup_and_reply_to,
489 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
490 ComposeHeaderEntry *headerentry);
491 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
493 ComposeHeaderEntry *headerentry);
495 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
497 static void compose_allow_user_actions (Compose *compose, gboolean allow);
500 static void compose_check_all (Compose *compose);
501 static void compose_highlight_all (Compose *compose);
502 static void compose_check_backwards (Compose *compose);
503 static void compose_check_forwards_go (Compose *compose);
506 static gint compose_defer_auto_save_draft (Compose *compose);
507 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
509 static gboolean compose_close (Compose *compose);
511 static GtkItemFactoryEntry compose_popup_entries[] =
513 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
514 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
515 {N_("/---"), NULL, NULL, 0, "<Separator>"},
516 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
519 static GtkItemFactoryEntry compose_entries[] =
521 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
522 {N_("/_Message/_Send"), "<control>Return",
523 compose_send_cb, 0, NULL},
524 {N_("/_Message/Send _later"), "<shift><control>S",
525 compose_send_later_cb, 0, NULL},
526 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
527 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
528 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
529 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
530 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
531 {N_("/_Message/_Save"),
532 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
533 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
534 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
536 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
537 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
538 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
539 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
540 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
541 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
542 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
543 {N_("/_Edit/Special paste"), NULL, NULL, 0, "<Branch>"},
544 {N_("/_Edit/Special paste/as _quotation"),
545 NULL, compose_paste_as_quote_cb, 0, NULL},
546 {N_("/_Edit/Special paste/_wrapped"),
547 NULL, compose_paste_wrap_cb, 0, NULL},
548 {N_("/_Edit/Special paste/_unwrapped"),
549 NULL, compose_paste_no_wrap_cb, 0, NULL},
550 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
551 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
552 {N_("/_Edit/A_dvanced/Move a character backward"),
554 compose_advanced_action_cb,
555 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
557 {N_("/_Edit/A_dvanced/Move a character forward"),
559 compose_advanced_action_cb,
560 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
562 {N_("/_Edit/A_dvanced/Move a word backward"),
564 compose_advanced_action_cb,
565 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
567 {N_("/_Edit/A_dvanced/Move a word forward"),
569 compose_advanced_action_cb,
570 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
572 {N_("/_Edit/A_dvanced/Move to beginning of line"),
573 NULL, /* "<control>A" */
574 compose_advanced_action_cb,
575 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
577 {N_("/_Edit/A_dvanced/Move to end of line"),
579 compose_advanced_action_cb,
580 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
582 {N_("/_Edit/A_dvanced/Move to previous line"),
584 compose_advanced_action_cb,
585 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
587 {N_("/_Edit/A_dvanced/Move to next line"),
589 compose_advanced_action_cb,
590 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
592 {N_("/_Edit/A_dvanced/Delete a character backward"),
594 compose_advanced_action_cb,
595 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
597 {N_("/_Edit/A_dvanced/Delete a character forward"),
599 compose_advanced_action_cb,
600 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
602 {N_("/_Edit/A_dvanced/Delete a word backward"),
603 NULL, /* "<control>W" */
604 compose_advanced_action_cb,
605 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
607 {N_("/_Edit/A_dvanced/Delete a word forward"),
608 NULL, /* "<alt>D", */
609 compose_advanced_action_cb,
610 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
612 {N_("/_Edit/A_dvanced/Delete line"),
614 compose_advanced_action_cb,
615 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
617 {N_("/_Edit/A_dvanced/Delete entire line"),
619 compose_advanced_action_cb,
620 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
622 {N_("/_Edit/A_dvanced/Delete to end of line"),
624 compose_advanced_action_cb,
625 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
627 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
629 "<control>F", compose_find_cb, 0, NULL},
630 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
631 {N_("/_Edit/_Wrap current paragraph"),
632 "<control>L", compose_wrap_cb, 0, NULL},
633 {N_("/_Edit/Wrap all long _lines"),
634 "<control><alt>L", compose_wrap_cb, 1, NULL},
635 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
636 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
637 {N_("/_Edit/Edit with e_xternal editor"),
638 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
640 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
641 {N_("/_Spelling/_Check all or check selection"),
642 NULL, compose_check_all, 0, NULL},
643 {N_("/_Spelling/_Highlight all misspelled words"),
644 NULL, compose_highlight_all, 0, NULL},
645 {N_("/_Spelling/Check _backwards misspelled word"),
646 NULL, compose_check_backwards , 0, NULL},
647 {N_("/_Spelling/_Forward to next misspelled word"),
648 NULL, compose_check_forwards_go, 0, NULL},
649 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
650 {N_("/_Spelling/Options"),
651 NULL, NULL, 0, "<Branch>"},
653 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
654 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
655 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
656 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
657 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
658 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
659 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
660 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
661 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
662 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
663 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
664 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
665 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
666 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
667 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
668 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
669 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
671 #define ENC_ACTION(action) \
672 NULL, compose_set_encoding_cb, action, \
673 "/Options/Character encoding/Automatic"
675 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
676 {N_("/_Options/Character _encoding/_Automatic"),
677 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
678 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
680 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
681 ENC_ACTION(C_US_ASCII)},
682 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
683 ENC_ACTION(C_UTF_8)},
684 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
686 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
687 ENC_ACTION(C_ISO_8859_1)},
688 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
689 ENC_ACTION(C_ISO_8859_15)},
690 {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
691 ENC_ACTION(C_WINDOWS_1252)},
692 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
694 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
695 ENC_ACTION(C_ISO_8859_2)},
696 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
698 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
699 ENC_ACTION(C_ISO_8859_13)},
700 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
701 ENC_ACTION(C_ISO_8859_4)},
702 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
704 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
705 ENC_ACTION(C_ISO_8859_7)},
706 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
708 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
709 ENC_ACTION(C_ISO_8859_8)},
710 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
711 ENC_ACTION(C_WINDOWS_1255)},
712 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
714 {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
715 ENC_ACTION(C_ISO_8859_6)},
716 {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
717 ENC_ACTION(C_CP1256)},
718 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
720 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
721 ENC_ACTION(C_ISO_8859_9)},
722 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
724 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
725 ENC_ACTION(C_ISO_8859_5)},
726 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
727 ENC_ACTION(C_KOI8_R)},
728 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
729 ENC_ACTION(C_KOI8_U)},
730 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
731 ENC_ACTION(C_WINDOWS_1251)},
732 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
734 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
735 ENC_ACTION(C_ISO_2022_JP)},
736 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
738 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
739 ENC_ACTION(C_GB2312)},
740 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
742 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
744 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
745 ENC_ACTION(C_EUC_TW)},
746 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
748 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
749 ENC_ACTION(C_EUC_KR)},
750 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
752 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
753 ENC_ACTION(C_TIS_620)},
754 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
755 ENC_ACTION(C_WINDOWS_874)},
757 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
758 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
759 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
760 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
761 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
762 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
763 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
766 static GtkTargetEntry compose_mime_types[] =
768 {"text/uri-list", 0, 0},
769 {"text/plain", 0, 0},
773 static gboolean compose_put_existing_to_front(MsgInfo *info)
775 GList *compose_list = compose_get_compose_list();
779 for (elem = compose_list; elem != NULL && elem->data != NULL;
781 Compose *c = (Compose*)elem->data;
783 if (!c->targetinfo || !c->targetinfo->msgid ||
787 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
788 gtkut_window_popup(c->window);
796 static GdkColor quote_color1 =
797 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
798 static GdkColor quote_color2 =
799 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
800 static GdkColor quote_color3 =
801 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
803 static GdkColor quote_bgcolor1 =
804 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
805 static GdkColor quote_bgcolor2 =
806 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
807 static GdkColor quote_bgcolor3 =
808 {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
810 static GdkColor signature_color = {
817 static GdkColor uri_color = {
824 static void compose_create_tags(GtkTextView *text, Compose *compose)
826 GtkTextBuffer *buffer;
827 GdkColor black = {(gulong)0, (gushort)0, (gushort)0, (gushort)0};
833 buffer = gtk_text_view_get_buffer(text);
835 if (prefs_common.enable_color) {
836 /* grab the quote colors, converting from an int to a GdkColor */
837 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
839 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
841 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
843 gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
845 gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
847 gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
849 gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
851 gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
854 signature_color = quote_color1 = quote_color2 = quote_color3 =
855 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black;
858 if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
859 gtk_text_buffer_create_tag(buffer, "quote0",
860 "foreground-gdk", "e_color1,
861 "paragraph-background-gdk", "e_bgcolor1,
863 gtk_text_buffer_create_tag(buffer, "quote1",
864 "foreground-gdk", "e_color2,
865 "paragraph-background-gdk", "e_bgcolor2,
867 gtk_text_buffer_create_tag(buffer, "quote2",
868 "foreground-gdk", "e_color3,
869 "paragraph-background-gdk", "e_bgcolor3,
872 gtk_text_buffer_create_tag(buffer, "quote0",
873 "foreground-gdk", "e_color1,
875 gtk_text_buffer_create_tag(buffer, "quote1",
876 "foreground-gdk", "e_color2,
878 gtk_text_buffer_create_tag(buffer, "quote2",
879 "foreground-gdk", "e_color3,
883 gtk_text_buffer_create_tag(buffer, "signature",
884 "foreground-gdk", &signature_color,
886 gtk_text_buffer_create_tag(buffer, "link",
887 "foreground-gdk", &uri_color,
889 compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL);
890 compose->no_join_tag = gtk_text_buffer_create_tag(buffer, "no_join", NULL);
892 color[0] = quote_color1;
893 color[1] = quote_color2;
894 color[2] = quote_color3;
895 color[3] = quote_bgcolor1;
896 color[4] = quote_bgcolor2;
897 color[5] = quote_bgcolor3;
898 color[6] = signature_color;
899 color[7] = uri_color;
900 cmap = gdk_drawable_get_colormap(compose->window->window);
901 gdk_colormap_alloc_colors(cmap, color, 8, FALSE, TRUE, success);
903 for (i = 0; i < 8; i++) {
904 if (success[i] == FALSE) {
907 g_warning("Compose: color allocation failed.\n");
908 style = gtk_widget_get_style(GTK_WIDGET(text));
909 quote_color1 = quote_color2 = quote_color3 =
910 quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 =
911 signature_color = uri_color = black;
916 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
917 GPtrArray *attach_files)
919 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
922 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
924 return compose_generic_new(account, NULL, item, NULL, NULL);
927 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
929 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
932 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
933 GPtrArray *attach_files, GList *listAddress )
936 GtkTextView *textview;
937 GtkTextBuffer *textbuf;
939 GtkItemFactory *ifactory;
941 if (item && item->prefs && item->prefs->enable_default_account)
942 account = account_find_from_id(item->prefs->default_account);
944 if (!account) account = cur_account;
945 g_return_val_if_fail(account != NULL, NULL);
947 compose = compose_create(account, COMPOSE_NEW, FALSE);
949 ifactory = gtk_item_factory_from_widget(compose->menubar);
951 compose->replyinfo = NULL;
952 compose->fwdinfo = NULL;
954 textview = GTK_TEXT_VIEW(compose->text);
955 textbuf = gtk_text_view_get_buffer(textview);
956 compose_create_tags(textview, compose);
958 undo_block(compose->undostruct);
960 if (item && item->prefs && item->prefs->enable_default_dictionary &&
962 gtkaspell_change_dict(compose->gtkaspell,
963 item->prefs->default_dictionary);
966 if (account->auto_sig)
967 compose_insert_sig(compose, FALSE);
968 gtk_text_buffer_get_start_iter(textbuf, &iter);
969 gtk_text_buffer_place_cursor(textbuf, &iter);
971 if (account->protocol != A_NNTP) {
972 if (mailto && *mailto != '\0') {
973 compose_entries_set(compose, mailto);
975 } else if (item && item->prefs->enable_default_to) {
976 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
977 compose_entry_mark_default_to(compose, item->prefs->default_to);
979 if (item && item->ret_rcpt) {
980 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
984 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
986 compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
989 * CLAWS: just don't allow return receipt request, even if the user
990 * may want to send an email. simple but foolproof.
992 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
994 compose_add_field_list( compose, listAddress );
1000 for (i = 0; i < attach_files->len; i++) {
1001 file = g_ptr_array_index(attach_files, i);
1002 compose_attach_append(compose, file, file, NULL);
1006 compose_show_first_last_header(compose, TRUE);
1008 /* Set save folder */
1009 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1010 gchar *folderidentifier;
1012 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1013 folderidentifier = folder_item_get_identifier(item);
1014 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1015 g_free(folderidentifier);
1018 gtk_widget_grab_focus(compose->header_last->entry);
1020 undo_unblock(compose->undostruct);
1022 if (prefs_common.auto_exteditor)
1023 compose_exec_ext_editor(compose);
1025 compose->modified = FALSE;
1026 compose_set_title(compose);
1030 static void compose_force_encryption(Compose *compose, PrefsAccount *account,
1031 gboolean override_pref)
1033 gchar *privacy = NULL;
1035 g_return_if_fail(compose != NULL);
1036 g_return_if_fail(account != NULL);
1038 if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
1041 if (account->default_privacy_system
1042 && strlen(account->default_privacy_system)) {
1043 privacy = account->default_privacy_system;
1045 GSList *privacy_avail = privacy_get_system_ids();
1046 if (privacy_avail && g_slist_length(privacy_avail)) {
1047 privacy = (gchar *)(privacy_avail->data);
1050 if (privacy != NULL) {
1051 compose->privacy_system = g_strdup(privacy);
1052 compose_update_privacy_system_menu_item(compose, FALSE);
1053 compose_use_encryption(compose, TRUE);
1057 static void compose_force_signing(Compose *compose, PrefsAccount *account)
1059 gchar *privacy = NULL;
1061 if (account->default_privacy_system
1062 && strlen(account->default_privacy_system)) {
1063 privacy = account->default_privacy_system;
1065 GSList *privacy_avail = privacy_get_system_ids();
1066 if (privacy_avail && g_slist_length(privacy_avail)) {
1067 privacy = (gchar *)(privacy_avail->data);
1070 if (privacy != NULL) {
1071 compose->privacy_system = g_strdup(privacy);
1072 compose_update_privacy_system_menu_item(compose, FALSE);
1073 compose_use_signing(compose, TRUE);
1077 Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
1081 Compose *compose = NULL;
1082 g_return_val_if_fail(msginfo_list != NULL, NULL);
1084 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
1085 g_return_val_if_fail(msginfo != NULL, NULL);
1087 list_len = g_slist_length(msginfo_list);
1091 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1092 FALSE, prefs_common.default_reply_list, FALSE, body);
1094 case COMPOSE_REPLY_WITH_QUOTE:
1095 compose = compose_reply(msginfo, TRUE,
1096 FALSE, prefs_common.default_reply_list, FALSE, body);
1098 case COMPOSE_REPLY_WITHOUT_QUOTE:
1099 compose = compose_reply(msginfo, FALSE,
1100 FALSE, prefs_common.default_reply_list, FALSE, NULL);
1102 case COMPOSE_REPLY_TO_SENDER:
1103 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1104 FALSE, FALSE, TRUE, body);
1106 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
1107 compose = compose_followup_and_reply_to(msginfo,
1108 prefs_common.reply_with_quote,
1109 FALSE, FALSE, body);
1111 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
1112 compose = compose_reply(msginfo, TRUE,
1113 FALSE, FALSE, TRUE, body);
1115 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
1116 compose = compose_reply(msginfo, FALSE,
1117 FALSE, FALSE, TRUE, NULL);
1119 case COMPOSE_REPLY_TO_ALL:
1120 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1121 TRUE, FALSE, FALSE, body);
1123 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
1124 compose = compose_reply(msginfo, TRUE,
1125 TRUE, FALSE, FALSE, body);
1127 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
1128 compose = compose_reply(msginfo, FALSE,
1129 TRUE, FALSE, FALSE, NULL);
1131 case COMPOSE_REPLY_TO_LIST:
1132 compose = compose_reply(msginfo, prefs_common.reply_with_quote,
1133 FALSE, TRUE, FALSE, body);
1135 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
1136 compose = compose_reply(msginfo, TRUE,
1137 FALSE, TRUE, FALSE, body);
1139 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
1140 compose = compose_reply(msginfo, FALSE,
1141 FALSE, TRUE, FALSE, NULL);
1143 case COMPOSE_FORWARD:
1144 if (prefs_common.forward_as_attachment) {
1145 compose = compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
1148 compose = compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
1152 case COMPOSE_FORWARD_INLINE:
1153 /* check if we reply to more than one Message */
1154 if (list_len == 1) {
1155 compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE);
1158 /* more messages FALL THROUGH */
1159 case COMPOSE_FORWARD_AS_ATTACH:
1160 compose = compose_forward_multiple(NULL, msginfo_list);
1162 case COMPOSE_REDIRECT:
1163 compose = compose_redirect(NULL, msginfo, FALSE);
1166 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
1171 Compose *compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
1172 gboolean to_ml, gboolean to_sender,
1175 return compose_generic_reply(msginfo, quote, to_all, to_ml,
1176 to_sender, FALSE, body);
1179 Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1184 return compose_generic_reply(msginfo, quote, to_all, FALSE,
1185 to_sender, TRUE, body);
1188 static void compose_extract_original_charset(Compose *compose)
1190 MsgInfo *info = NULL;
1191 if (compose->replyinfo) {
1192 info = compose->replyinfo;
1193 } else if (compose->fwdinfo) {
1194 info = compose->fwdinfo;
1195 } else if (compose->targetinfo) {
1196 info = compose->targetinfo;
1199 MimeInfo *mimeinfo = procmime_scan_message(info);
1200 MimeInfo *partinfo = mimeinfo;
1201 while (partinfo && partinfo->type != MIMETYPE_TEXT)
1202 partinfo = procmime_mimeinfo_next(partinfo);
1204 compose->orig_charset =
1205 g_strdup(procmime_mimeinfo_get_parameter(
1206 partinfo, "charset"));
1208 procmime_mimeinfo_free_all(mimeinfo);
1212 #define SIGNAL_BLOCK(buffer) { \
1213 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1214 G_CALLBACK(compose_changed_cb), \
1216 g_signal_handlers_block_by_func(G_OBJECT(buffer), \
1217 G_CALLBACK(text_inserted), \
1221 #define SIGNAL_UNBLOCK(buffer) { \
1222 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1223 G_CALLBACK(compose_changed_cb), \
1225 g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \
1226 G_CALLBACK(text_inserted), \
1230 static Compose *compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1231 gboolean to_all, gboolean to_ml,
1233 gboolean followup_and_reply_to,
1236 GtkItemFactory *ifactory;
1238 PrefsAccount *account = NULL;
1239 PrefsAccount *reply_account;
1240 GtkTextView *textview;
1241 GtkTextBuffer *textbuf;
1243 g_return_val_if_fail(msginfo != NULL, NULL);
1244 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1246 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1248 g_return_val_if_fail(account != NULL, NULL);
1250 if (to_sender && account->protocol == A_NNTP &&
1251 !followup_and_reply_to) {
1253 account_find_from_address(account->address);
1255 reply_account = compose_current_mail_account();
1259 reply_account = account;
1261 compose = compose_create(account, COMPOSE_REPLY, FALSE);
1263 compose->updating = TRUE;
1265 ifactory = gtk_item_factory_from_widget(compose->menubar);
1267 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1268 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1270 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1271 if (!compose->replyinfo)
1272 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1274 compose_extract_original_charset(compose);
1276 if (msginfo->folder && msginfo->folder->ret_rcpt)
1277 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1279 /* Set save folder */
1280 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1281 gchar *folderidentifier;
1283 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1284 folderidentifier = folder_item_get_identifier(msginfo->folder);
1285 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1286 g_free(folderidentifier);
1289 if (compose_parse_header(compose, msginfo) < 0) return NULL;
1290 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1291 to_sender, followup_and_reply_to);
1292 compose_show_first_last_header(compose, TRUE);
1294 textview = (GTK_TEXT_VIEW(compose->text));
1295 textbuf = gtk_text_view_get_buffer(textview);
1296 compose_create_tags(textview, compose);
1298 undo_block(compose->undostruct);
1300 if (msginfo->folder && msginfo->folder->prefs &&
1301 msginfo->folder->prefs &&
1302 msginfo->folder->prefs->enable_default_dictionary &&
1304 gtkaspell_change_dict(compose->gtkaspell,
1305 msginfo->folder->prefs->default_dictionary);
1311 if (prefs_common.quotemark && *prefs_common.quotemark)
1312 qmark = prefs_common.quotemark;
1316 compose_quote_fmt(compose, compose->replyinfo,
1317 prefs_common.quotefmt,
1318 qmark, body, FALSE);
1320 if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
1321 compose_force_encryption(compose, account, FALSE);
1324 SIGNAL_BLOCK(textbuf);
1326 if (account->auto_sig)
1327 compose_insert_sig(compose, FALSE);
1329 compose_wrap_all(compose);
1331 SIGNAL_UNBLOCK(textbuf);
1333 gtk_widget_grab_focus(compose->text);
1335 undo_unblock(compose->undostruct);
1337 if (prefs_common.auto_exteditor)
1338 compose_exec_ext_editor(compose);
1340 compose->modified = FALSE;
1341 compose_set_title(compose);
1343 compose->updating = FALSE;
1345 if (compose->deferred_destroy) {
1346 compose_destroy(compose);
1353 #define INSERT_FW_HEADER(var, hdr) \
1354 if (msginfo->var && *msginfo->var) { \
1355 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1356 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1357 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1360 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1361 gboolean as_attach, const gchar *body,
1362 gboolean no_extedit,
1366 GtkTextView *textview;
1367 GtkTextBuffer *textbuf;
1370 g_return_val_if_fail(msginfo != NULL, NULL);
1371 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1374 !(account = compose_guess_forward_account_from_msginfo
1376 account = cur_account;
1378 compose = compose_create(account, COMPOSE_FORWARD, batch);
1380 compose->updating = TRUE;
1381 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1382 if (!compose->fwdinfo)
1383 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1385 compose_extract_original_charset(compose);
1387 if (msginfo->subject && *msginfo->subject) {
1388 gchar *buf, *buf2, *p;
1390 buf = p = g_strdup(msginfo->subject);
1391 p += subject_get_prefix_length(p);
1392 memmove(buf, p, strlen(p) + 1);
1394 buf2 = g_strdup_printf("Fw: %s", buf);
1395 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1401 textview = GTK_TEXT_VIEW(compose->text);
1402 textbuf = gtk_text_view_get_buffer(textview);
1403 compose_create_tags(textview, compose);
1405 undo_block(compose->undostruct);
1409 msgfile = procmsg_get_message_file_path(msginfo);
1410 if (!is_file_exist(msgfile))
1411 g_warning("%s: file not exist\n", msgfile);
1413 compose_attach_append(compose, msgfile, msgfile,
1419 MsgInfo *full_msginfo;
1421 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1423 full_msginfo = procmsg_msginfo_copy(msginfo);
1425 if (prefs_common.fw_quotemark &&
1426 *prefs_common.fw_quotemark)
1427 qmark = prefs_common.fw_quotemark;
1431 compose_quote_fmt(compose, full_msginfo,
1432 prefs_common.fw_quotefmt,
1433 qmark, body, FALSE);
1434 compose_attach_parts(compose, msginfo);
1436 procmsg_msginfo_free(full_msginfo);
1439 SIGNAL_BLOCK(textbuf);
1441 if (account->auto_sig)
1442 compose_insert_sig(compose, FALSE);
1444 compose_wrap_all(compose);
1446 SIGNAL_UNBLOCK(textbuf);
1448 gtk_text_buffer_get_start_iter(textbuf, &iter);
1449 gtk_text_buffer_place_cursor(textbuf, &iter);
1451 gtk_widget_grab_focus(compose->header_last->entry);
1453 if (!no_extedit && prefs_common.auto_exteditor)
1454 compose_exec_ext_editor(compose);
1457 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1458 gchar *folderidentifier;
1460 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1461 folderidentifier = folder_item_get_identifier(msginfo->folder);
1462 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1463 g_free(folderidentifier);
1466 undo_unblock(compose->undostruct);
1468 compose->modified = FALSE;
1469 compose_set_title(compose);
1471 compose->updating = FALSE;
1473 if (compose->deferred_destroy) {
1474 compose_destroy(compose);
1481 #undef INSERT_FW_HEADER
1483 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1486 GtkTextView *textview;
1487 GtkTextBuffer *textbuf;
1491 gboolean single_mail = TRUE;
1493 g_return_val_if_fail(msginfo_list != NULL, NULL);
1495 if (g_slist_length(msginfo_list) > 1)
1496 single_mail = FALSE;
1498 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1499 if (((MsgInfo *)msginfo->data)->folder == NULL)
1502 /* guess account from first selected message */
1504 !(account = compose_guess_forward_account_from_msginfo
1505 (msginfo_list->data)))
1506 account = cur_account;
1508 g_return_val_if_fail(account != NULL, NULL);
1510 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1511 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1512 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1515 compose = compose_create(account, COMPOSE_FORWARD, FALSE);
1517 compose->updating = TRUE;
1519 textview = GTK_TEXT_VIEW(compose->text);
1520 textbuf = gtk_text_view_get_buffer(textview);
1521 compose_create_tags(textview, compose);
1523 undo_block(compose->undostruct);
1524 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1525 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1527 if (!is_file_exist(msgfile))
1528 g_warning("%s: file not exist\n", msgfile);
1530 compose_attach_append(compose, msgfile, msgfile,
1536 MsgInfo *info = (MsgInfo *)msginfo_list->data;
1537 if (info->subject && *info->subject) {
1538 gchar *buf, *buf2, *p;
1540 buf = p = g_strdup(info->subject);
1541 p += subject_get_prefix_length(p);
1542 memmove(buf, p, strlen(p) + 1);
1544 buf2 = g_strdup_printf("Fw: %s", buf);
1545 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1551 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1552 _("Fw: multiple emails"));
1555 SIGNAL_BLOCK(textbuf);
1557 if (account->auto_sig)
1558 compose_insert_sig(compose, FALSE);
1560 compose_wrap_all(compose);
1562 SIGNAL_UNBLOCK(textbuf);
1564 gtk_text_buffer_get_start_iter(textbuf, &iter);
1565 gtk_text_buffer_place_cursor(textbuf, &iter);
1567 gtk_widget_grab_focus(compose->header_last->entry);
1568 undo_unblock(compose->undostruct);
1569 compose->modified = FALSE;
1570 compose_set_title(compose);
1572 compose->updating = FALSE;
1574 if (compose->deferred_destroy) {
1575 compose_destroy(compose);
1582 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
1584 GtkTextIter start = *iter;
1585 GtkTextIter end_iter;
1586 int start_pos = gtk_text_iter_get_offset(&start);
1588 if (!compose->account->sig_sep)
1591 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1592 start_pos+strlen(compose->account->sig_sep));
1594 /* check sig separator */
1595 str = gtk_text_iter_get_text(&start, &end_iter);
1596 if (!strcmp(str, compose->account->sig_sep)) {
1598 /* check end of line (\n) */
1599 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
1600 start_pos+strlen(compose->account->sig_sep));
1601 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
1602 start_pos+strlen(compose->account->sig_sep)+1);
1603 tmp = gtk_text_iter_get_text(&start, &end_iter);
1604 if (!strcmp(tmp,"\n")) {
1616 static void compose_colorize_signature(Compose *compose)
1618 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
1620 GtkTextIter end_iter;
1621 gtk_text_buffer_get_start_iter(buffer, &iter);
1622 while (gtk_text_iter_forward_line(&iter))
1623 if (compose_is_sig_separator(compose, buffer, &iter)) {
1624 gtk_text_buffer_get_end_iter(buffer, &end_iter);
1625 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &end_iter);
1629 void compose_reedit(MsgInfo *msginfo)
1631 Compose *compose = NULL;
1632 PrefsAccount *account = NULL;
1633 GtkTextView *textview;
1634 GtkTextBuffer *textbuf;
1638 gchar buf[BUFFSIZE];
1639 gboolean use_signing = FALSE;
1640 gboolean use_encryption = FALSE;
1641 gchar *privacy_system = NULL;
1643 g_return_if_fail(msginfo != NULL);
1644 g_return_if_fail(msginfo->folder != NULL);
1646 if (compose_put_existing_to_front(msginfo)) {
1650 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1651 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1652 gchar queueheader_buf[BUFFSIZE];
1655 /* Select Account from queue headers */
1656 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1657 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1658 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1659 account = account_find_from_id(id);
1661 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1662 sizeof(queueheader_buf), "NAID:")) {
1663 id = atoi(&queueheader_buf[strlen("NAID:")]);
1664 account = account_find_from_id(id);
1666 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1667 sizeof(queueheader_buf), "MAID:")) {
1668 id = atoi(&queueheader_buf[strlen("MAID:")]);
1669 account = account_find_from_id(id);
1671 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1672 sizeof(queueheader_buf), "S:")) {
1673 account = account_find_from_address(queueheader_buf);
1675 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1676 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1677 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1678 use_signing = param;
1681 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1682 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1683 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1684 use_encryption = param;
1686 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1687 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1688 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1690 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1691 sizeof(queueheader_buf), "X-Priority: ")) {
1692 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1693 compose->priority = param;
1696 account = msginfo->folder->folder->account;
1699 if (!account && prefs_common.reedit_account_autosel) {
1700 gchar from[BUFFSIZE];
1701 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
1702 extract_address(from);
1703 account = account_find_from_address(from);
1707 account = cur_account;
1709 g_return_if_fail(account != NULL);
1711 compose = compose_create(account, COMPOSE_REEDIT, FALSE);
1713 compose->updating = TRUE;
1715 if (privacy_system != NULL) {
1716 compose->privacy_system = privacy_system;
1717 compose_use_signing(compose, use_signing);
1718 compose_use_encryption(compose, use_encryption);
1719 compose_update_privacy_system_menu_item(compose, FALSE);
1721 activate_privacy_system(compose, account, FALSE);
1724 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1726 compose_extract_original_charset(compose);
1728 if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1729 folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1730 gchar queueheader_buf[BUFFSIZE];
1732 /* Set message save folder */
1733 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1736 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1737 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1738 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1740 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "RRCPT:")) {
1741 gint active = atoi(&queueheader_buf[strlen("RRCPT:")]);
1743 GtkItemFactory *ifactory;
1744 ifactory = gtk_item_factory_from_widget(compose->menubar);
1745 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1750 if (compose_parse_header(compose, msginfo) < 0) {
1751 compose->updating = FALSE;
1752 compose_destroy(compose);
1755 compose_reedit_set_entry(compose, msginfo);
1757 textview = GTK_TEXT_VIEW(compose->text);
1758 textbuf = gtk_text_view_get_buffer(textview);
1759 compose_create_tags(textview, compose);
1761 mark = gtk_text_buffer_get_insert(textbuf);
1762 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1764 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1765 G_CALLBACK(compose_changed_cb),
1768 if (procmime_msginfo_is_encrypted(msginfo)) {
1769 fp = procmime_get_first_encrypted_text_content(msginfo);
1771 compose_force_encryption(compose, account, TRUE);
1774 fp = procmime_get_first_text_content(msginfo);
1777 g_warning("Can't get text part\n");
1781 gboolean prev_autowrap = compose->autowrap;
1783 compose->autowrap = FALSE;
1784 while (fgets(buf, sizeof(buf), fp) != NULL) {
1786 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1788 compose_wrap_all_full(compose, FALSE);
1789 compose->autowrap = prev_autowrap;
1793 compose_attach_parts(compose, msginfo);
1795 compose_colorize_signature(compose);
1797 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1798 G_CALLBACK(compose_changed_cb),
1801 gtk_widget_grab_focus(compose->text);
1803 if (prefs_common.auto_exteditor) {
1804 compose_exec_ext_editor(compose);
1806 compose->modified = FALSE;
1807 compose_set_title(compose);
1809 compose->updating = FALSE;
1811 if (compose->deferred_destroy) {
1812 compose_destroy(compose);
1816 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
1821 GtkItemFactory *ifactory;
1824 g_return_val_if_fail(msginfo != NULL, NULL);
1827 account = account_get_reply_account(msginfo,
1828 prefs_common.reply_account_autosel);
1829 g_return_val_if_fail(account != NULL, NULL);
1831 compose = compose_create(account, COMPOSE_REDIRECT, batch);
1833 compose->updating = TRUE;
1835 ifactory = gtk_item_factory_from_widget(compose->menubar);
1836 compose_create_tags(GTK_TEXT_VIEW(compose->text), compose);
1837 compose->replyinfo = NULL;
1838 compose->fwdinfo = NULL;
1840 compose_show_first_last_header(compose, TRUE);
1842 gtk_widget_grab_focus(compose->header_last->entry);
1844 filename = procmsg_get_message_file_path(msginfo);
1846 if (filename == NULL) {
1847 compose->updating = FALSE;
1848 compose_destroy(compose);
1853 compose->redirect_filename = filename;
1855 /* Set save folder */
1856 item = msginfo->folder;
1857 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1858 gchar *folderidentifier;
1860 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1861 folderidentifier = folder_item_get_identifier(item);
1862 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1863 g_free(folderidentifier);
1866 compose_attach_parts(compose, msginfo);
1868 if (msginfo->subject)
1869 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1871 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1873 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
1874 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1876 compose_colorize_signature(compose);
1878 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1879 menu_set_sensitive(ifactory, "/Add...", FALSE);
1880 menu_set_sensitive(ifactory, "/Remove", FALSE);
1881 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1883 ifactory = gtk_item_factory_from_widget(compose->menubar);
1884 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1885 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1886 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1887 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1888 menu_set_sensitive(ifactory, "/Edit", FALSE);
1889 menu_set_sensitive(ifactory, "/Options", FALSE);
1890 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1891 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1893 if (compose->toolbar->draft_btn)
1894 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1895 if (compose->toolbar->insert_btn)
1896 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1897 if (compose->toolbar->attach_btn)
1898 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1899 if (compose->toolbar->sig_btn)
1900 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1901 if (compose->toolbar->exteditor_btn)
1902 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1903 if (compose->toolbar->linewrap_current_btn)
1904 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1905 if (compose->toolbar->linewrap_all_btn)
1906 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1908 compose->modified = FALSE;
1909 compose_set_title(compose);
1910 compose->updating = FALSE;
1912 if (compose->deferred_destroy) {
1913 compose_destroy(compose);
1920 GList *compose_get_compose_list(void)
1922 return compose_list;
1925 void compose_entry_append(Compose *compose, const gchar *address,
1926 ComposeEntryType type)
1930 gboolean in_quote = FALSE;
1931 if (!address || *address == '\0') return;
1938 header = N_("Bcc:");
1940 case COMPOSE_REPLYTO:
1941 header = N_("Reply-To:");
1943 case COMPOSE_NEWSGROUPS:
1944 header = N_("Newsgroups:");
1946 case COMPOSE_FOLLOWUPTO:
1947 header = N_( "Followup-To:");
1954 header = prefs_common.trans_hdr ? gettext(header) : header;
1956 cur = begin = (gchar *)address;
1958 /* we separate the line by commas, but not if we're inside a quoted
1960 while (*cur != '\0') {
1962 in_quote = !in_quote;
1963 if (*cur == ',' && !in_quote) {
1964 gchar *tmp = g_strdup(begin);
1966 tmp[cur-begin]='\0';
1969 while (*tmp == ' ' || *tmp == '\t')
1971 compose_add_header_entry(compose, header, tmp);
1978 gchar *tmp = g_strdup(begin);
1980 tmp[cur-begin]='\0';
1983 while (*tmp == ' ' || *tmp == '\t')
1985 compose_add_header_entry(compose, header, tmp);
1990 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1992 static GdkColor yellow;
1993 static GdkColor black;
1994 static gboolean yellow_initialised = FALSE;
1998 if (!yellow_initialised) {
1999 gdk_color_parse("#f5f6be", &yellow);
2000 gdk_color_parse("#000000", &black);
2001 yellow_initialised = gdk_colormap_alloc_color(
2002 gdk_colormap_get_system(), &yellow, FALSE, TRUE);
2003 yellow_initialised &= gdk_colormap_alloc_color(
2004 gdk_colormap_get_system(), &black, FALSE, TRUE);
2007 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
2008 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
2009 if (gtk_entry_get_text(entry) &&
2010 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
2011 if (yellow_initialised) {
2012 gtk_widget_modify_base(
2013 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2014 GTK_STATE_NORMAL, &yellow);
2015 gtk_widget_modify_text(
2016 GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
2017 GTK_STATE_NORMAL, &black);
2023 void compose_toolbar_cb(gint action, gpointer data)
2025 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2026 Compose *compose = (Compose*)toolbar_item->parent;
2028 g_return_if_fail(compose != NULL);
2032 compose_send_cb(compose, 0, NULL);
2035 compose_send_later_cb(compose, 0, NULL);
2038 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
2041 compose_insert_file_cb(compose, 0, NULL);
2044 compose_attach_cb(compose, 0, NULL);
2047 compose_insert_sig(compose, FALSE);
2050 compose_ext_editor_cb(compose, 0, NULL);
2052 case A_LINEWRAP_CURRENT:
2053 compose_beautify_paragraph(compose, NULL, TRUE);
2055 case A_LINEWRAP_ALL:
2056 compose_wrap_all_full(compose, TRUE);
2059 compose_address_cb(compose, 0, NULL);
2062 case A_CHECK_SPELLING:
2063 compose_check_all(compose);
2071 static void compose_entries_set(Compose *compose, const gchar *mailto)
2075 gchar *subject = NULL;
2080 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
2083 compose_entry_append(compose, to, COMPOSE_TO);
2085 compose_entry_append(compose, cc, COMPOSE_CC);
2087 if (!g_utf8_validate (subject, -1, NULL)) {
2088 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
2089 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
2092 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
2096 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2097 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2100 gboolean prev_autowrap = compose->autowrap;
2102 compose->autowrap = FALSE;
2104 mark = gtk_text_buffer_get_insert(buffer);
2105 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2107 if (!g_utf8_validate (body, -1, NULL)) {
2108 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
2109 gtk_text_buffer_insert(buffer, &iter, temp, -1);
2112 gtk_text_buffer_insert(buffer, &iter, body, -1);
2114 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
2116 compose->autowrap = prev_autowrap;
2117 if (compose->autowrap)
2118 compose_wrap_all(compose);
2127 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
2129 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
2130 {"Cc:", NULL, TRUE},
2131 {"References:", NULL, FALSE},
2132 {"Bcc:", NULL, TRUE},
2133 {"Newsgroups:", NULL, TRUE},
2134 {"Followup-To:", NULL, TRUE},
2135 {"List-Post:", NULL, FALSE},
2136 {"X-Priority:", NULL, FALSE},
2137 {NULL, NULL, FALSE}};
2153 g_return_val_if_fail(msginfo != NULL, -1);
2155 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
2156 procheader_get_header_fields(fp, hentry);
2159 if (hentry[H_REPLY_TO].body != NULL) {
2160 if (hentry[H_REPLY_TO].body[0] != '\0') {
2162 conv_unmime_header(hentry[H_REPLY_TO].body,
2165 g_free(hentry[H_REPLY_TO].body);
2166 hentry[H_REPLY_TO].body = NULL;
2168 if (hentry[H_CC].body != NULL) {
2169 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
2170 g_free(hentry[H_CC].body);
2171 hentry[H_CC].body = NULL;
2173 if (hentry[H_REFERENCES].body != NULL) {
2174 if (compose->mode == COMPOSE_REEDIT)
2175 compose->references = hentry[H_REFERENCES].body;
2177 compose->references = compose_parse_references
2178 (hentry[H_REFERENCES].body, msginfo->msgid);
2179 g_free(hentry[H_REFERENCES].body);
2181 hentry[H_REFERENCES].body = NULL;
2183 if (hentry[H_BCC].body != NULL) {
2184 if (compose->mode == COMPOSE_REEDIT)
2186 conv_unmime_header(hentry[H_BCC].body, NULL);
2187 g_free(hentry[H_BCC].body);
2188 hentry[H_BCC].body = NULL;
2190 if (hentry[H_NEWSGROUPS].body != NULL) {
2191 compose->newsgroups = hentry[H_NEWSGROUPS].body;
2192 hentry[H_NEWSGROUPS].body = NULL;
2194 if (hentry[H_FOLLOWUP_TO].body != NULL) {
2195 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
2196 compose->followup_to =
2197 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
2200 g_free(hentry[H_FOLLOWUP_TO].body);
2201 hentry[H_FOLLOWUP_TO].body = NULL;
2203 if (hentry[H_LIST_POST].body != NULL) {
2206 extract_address(hentry[H_LIST_POST].body);
2207 if (hentry[H_LIST_POST].body[0] != '\0') {
2208 scan_mailto_url(hentry[H_LIST_POST].body,
2209 &to, NULL, NULL, NULL, NULL);
2211 g_free(compose->ml_post);
2212 compose->ml_post = to;
2215 g_free(hentry[H_LIST_POST].body);
2216 hentry[H_LIST_POST].body = NULL;
2219 /* CLAWS - X-Priority */
2220 if (compose->mode == COMPOSE_REEDIT)
2221 if (hentry[H_X_PRIORITY].body != NULL) {
2224 priority = atoi(hentry[H_X_PRIORITY].body);
2225 g_free(hentry[H_X_PRIORITY].body);
2227 hentry[H_X_PRIORITY].body = NULL;
2229 if (priority < PRIORITY_HIGHEST ||
2230 priority > PRIORITY_LOWEST)
2231 priority = PRIORITY_NORMAL;
2233 compose->priority = priority;
2236 if (compose->mode == COMPOSE_REEDIT) {
2237 if (msginfo->inreplyto && *msginfo->inreplyto)
2238 compose->inreplyto = g_strdup(msginfo->inreplyto);
2242 if (msginfo->msgid && *msginfo->msgid)
2243 compose->inreplyto = g_strdup(msginfo->msgid);
2245 if (!compose->references) {
2246 if (msginfo->msgid && *msginfo->msgid) {
2247 if (msginfo->inreplyto && *msginfo->inreplyto)
2248 compose->references =
2249 g_strdup_printf("<%s>\n\t<%s>",
2253 compose->references =
2254 g_strconcat("<", msginfo->msgid, ">",
2256 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
2257 compose->references =
2258 g_strconcat("<", msginfo->inreplyto, ">",
2266 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
2268 GSList *ref_id_list, *cur;
2272 ref_id_list = references_list_append(NULL, ref);
2273 if (!ref_id_list) return NULL;
2274 if (msgid && *msgid)
2275 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
2280 for (cur = ref_id_list; cur != NULL; cur = cur->next)
2281 /* "<" + Message-ID + ">" + CR+LF+TAB */
2282 len += strlen((gchar *)cur->data) + 5;
2284 if (len > MAX_REFERENCES_LEN) {
2285 /* remove second message-ID */
2286 if (ref_id_list && ref_id_list->next &&
2287 ref_id_list->next->next) {
2288 g_free(ref_id_list->next->data);
2289 ref_id_list = g_slist_remove
2290 (ref_id_list, ref_id_list->next->data);
2292 slist_free_strings(ref_id_list);
2293 g_slist_free(ref_id_list);
2300 new_ref = g_string_new("");
2301 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
2302 if (new_ref->len > 0)
2303 g_string_append(new_ref, "\n\t");
2304 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
2307 slist_free_strings(ref_id_list);
2308 g_slist_free(ref_id_list);
2310 new_ref_str = new_ref->str;
2311 g_string_free(new_ref, FALSE);
2316 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
2317 const gchar *fmt, const gchar *qmark,
2318 const gchar *body, gboolean rewrap)
2320 static MsgInfo dummyinfo;
2321 gchar *quote_str = NULL;
2323 gboolean prev_autowrap;
2324 const gchar *trimmed_body = body;
2325 gint cursor_pos = -1;
2326 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2327 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2332 SIGNAL_BLOCK(buffer);
2335 msginfo = &dummyinfo;
2337 if (qmark != NULL) {
2338 quote_fmt_init(msginfo, NULL, NULL, FALSE);
2339 quote_fmt_scan_string(qmark);
2342 buf = quote_fmt_get_buffer();
2344 alertpanel_error(_("Quote mark format error."));
2346 Xstrdup_a(quote_str, buf, goto error)
2349 if (fmt && *fmt != '\0') {
2350 while (trimmed_body && strlen(trimmed_body) > 1
2351 && trimmed_body[0]=='\n')
2354 quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE);
2355 quote_fmt_scan_string(fmt);
2358 buf = quote_fmt_get_buffer();
2360 alertpanel_error(_("Message reply/forward format error."));
2366 prev_autowrap = compose->autowrap;
2367 compose->autowrap = FALSE;
2369 mark = gtk_text_buffer_get_insert(buffer);
2370 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2371 if (g_utf8_validate(buf, -1, NULL)) {
2372 gtk_text_buffer_insert(buffer, &iter, buf, -1);
2374 gchar *tmpout = NULL;
2375 tmpout = conv_codeset_strdup
2376 (buf, conv_get_locale_charset_str_no_utf8(),
2378 if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
2380 tmpout = g_malloc(strlen(buf)*2+1);
2381 conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
2383 gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
2387 cursor_pos = quote_fmt_get_cursor_pos();
2388 compose->set_cursor_pos = cursor_pos;
2389 if (cursor_pos == -1) {
2392 gtk_text_buffer_get_start_iter(buffer, &iter);
2393 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
2394 gtk_text_buffer_place_cursor(buffer, &iter);
2396 compose->autowrap = prev_autowrap;
2397 if (compose->autowrap && rewrap)
2398 compose_wrap_all(compose);
2405 SIGNAL_UNBLOCK(buffer);
2411 /* if ml_post is of type addr@host and from is of type
2412 * addr-anything@host, return TRUE
2414 static gboolean is_subscription(const gchar *ml_post, const gchar *from)
2416 gchar *left_ml = NULL;
2417 gchar *right_ml = NULL;
2418 gchar *left_from = NULL;
2419 gchar *right_from = NULL;
2420 gboolean result = FALSE;
2422 if (!ml_post || !from)
2425 left_ml = g_strdup(ml_post);
2426 if (strstr(left_ml, "@")) {
2427 right_ml = strstr(left_ml, "@")+1;
2428 *(strstr(left_ml, "@")) = '\0';
2431 left_from = g_strdup(from);
2432 if (strstr(left_from, "@")) {
2433 right_from = strstr(left_from, "@")+1;
2434 *(strstr(left_from, "@")) = '\0';
2437 if (left_ml && left_from && right_ml && right_from
2438 && !strncmp(left_from, left_ml, strlen(left_ml))
2439 && !strcmp(right_from, right_ml)) {
2448 static gboolean same_address(const gchar *addr1, const gchar *addr2)
2450 gchar *my_addr1, *my_addr2;
2452 if (!addr1 || !addr2)
2455 Xstrdup_a(my_addr1, addr1, return FALSE);
2456 Xstrdup_a(my_addr2, addr2, return FALSE);
2458 extract_address(my_addr1);
2459 extract_address(my_addr2);
2461 return !strcmp(my_addr1, my_addr2);
2464 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
2465 gboolean to_all, gboolean to_ml,
2467 gboolean followup_and_reply_to)
2469 GSList *cc_list = NULL;
2472 gchar *replyto = NULL;
2473 GHashTable *to_table;
2475 gboolean reply_to_ml = FALSE;
2476 gboolean default_reply_to = FALSE;
2478 g_return_if_fail(compose->account != NULL);
2479 g_return_if_fail(msginfo != NULL);
2481 reply_to_ml = to_ml && compose->ml_post;
2483 default_reply_to = msginfo->folder &&
2484 msginfo->folder->prefs->enable_default_reply_to;
2486 if (compose->account->protocol != A_NNTP) {
2487 if (reply_to_ml && !default_reply_to) {
2489 gboolean is_subscr = is_subscription(compose->ml_post,
2492 /* normal answer to ml post with a reply-to */
2493 compose_entry_append(compose,
2496 if (compose->replyto
2497 && !same_address(compose->ml_post, compose->replyto))
2498 compose_entry_append(compose,
2502 /* answer to subscription confirmation */
2503 if (compose->replyto)
2504 compose_entry_append(compose,
2507 else if (msginfo->from)
2508 compose_entry_append(compose,
2513 else if (!(to_all || to_sender) && default_reply_to) {
2514 compose_entry_append(compose,
2515 msginfo->folder->prefs->default_reply_to,
2517 compose_entry_mark_default_to(compose,
2518 msginfo->folder->prefs->default_reply_to);
2523 Xstrdup_a(tmp1, msginfo->from, return);
2524 extract_address(tmp1);
2525 if (to_all || to_sender ||
2526 !account_find_from_address(tmp1))
2527 compose_entry_append(compose,
2528 (compose->replyto && !to_sender)
2529 ? compose->replyto :
2530 msginfo->from ? msginfo->from : "",
2532 else if (!to_all && !to_sender) {
2533 /* reply to the last list of recipients */
2534 compose_entry_append(compose,
2535 msginfo->to ? msginfo->to : "",
2537 compose_entry_append(compose,
2538 msginfo->cc ? msginfo->cc : "",
2543 if (to_sender || (compose->followup_to &&
2544 !strncmp(compose->followup_to, "poster", 6)))
2545 compose_entry_append
2547 (compose->replyto ? compose->replyto :
2548 msginfo->from ? msginfo->from : ""),
2551 else if (followup_and_reply_to || to_all) {
2552 compose_entry_append
2554 (compose->replyto ? compose->replyto :
2555 msginfo->from ? msginfo->from : ""),
2558 compose_entry_append
2560 compose->followup_to ? compose->followup_to :
2561 compose->newsgroups ? compose->newsgroups : "",
2562 COMPOSE_NEWSGROUPS);
2565 compose_entry_append
2567 compose->followup_to ? compose->followup_to :
2568 compose->newsgroups ? compose->newsgroups : "",
2569 COMPOSE_NEWSGROUPS);
2572 if (msginfo->subject && *msginfo->subject) {
2576 buf = p = g_strdup(msginfo->subject);
2577 p += subject_get_prefix_length(p);
2578 memmove(buf, p, strlen(p) + 1);
2580 buf2 = g_strdup_printf("Re: %s", buf);
2581 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2586 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2588 if (to_ml && compose->ml_post) return;
2589 if (!to_all || compose->account->protocol == A_NNTP) return;
2591 if (compose->replyto) {
2592 Xstrdup_a(replyto, compose->replyto, return);
2593 extract_address(replyto);
2595 if (msginfo->from) {
2596 Xstrdup_a(from, msginfo->from, return);
2597 extract_address(from);
2600 if (replyto && from)
2601 cc_list = address_list_append_with_comments(cc_list, from);
2602 if (to_all && msginfo->folder &&
2603 msginfo->folder->prefs->enable_default_reply_to)
2604 cc_list = address_list_append_with_comments(cc_list,
2605 msginfo->folder->prefs->default_reply_to);
2606 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2607 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2609 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2611 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2612 if (compose->account)
2613 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2614 GINT_TO_POINTER(1));
2616 /* remove address on To: and that of current account */
2617 for (cur = cc_list; cur != NULL; ) {
2618 GSList *next = cur->next;
2621 addr = g_strdup(cur->data);
2622 extract_address(addr);
2624 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2625 cc_list = g_slist_remove(cc_list, cur->data);
2627 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2631 hash_free_strings(to_table);
2632 g_hash_table_destroy(to_table);
2635 for (cur = cc_list; cur != NULL; cur = cur->next)
2636 compose_entry_append(compose, (gchar *)cur->data,
2638 slist_free_strings(cc_list);
2639 g_slist_free(cc_list);
2644 #define SET_ENTRY(entry, str) \
2647 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2650 #define SET_ADDRESS(type, str) \
2653 compose_entry_append(compose, str, type); \
2656 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2658 g_return_if_fail(msginfo != NULL);
2660 SET_ENTRY(subject_entry, msginfo->subject);
2661 SET_ENTRY(from_name, msginfo->from);
2662 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2663 SET_ADDRESS(COMPOSE_CC, compose->cc);
2664 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2665 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2666 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2667 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2669 compose_update_priority_menu_item(compose);
2670 compose_update_privacy_system_menu_item(compose, FALSE);
2671 compose_show_first_last_header(compose, TRUE);
2677 static void compose_insert_sig(Compose *compose, gboolean replace)
2679 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2680 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2682 GtkTextIter iter, iter_end;
2684 gboolean prev_autowrap;
2687 g_return_if_fail(compose->account != NULL);
2689 prev_autowrap = compose->autowrap;
2690 compose->autowrap = FALSE;
2692 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2693 G_CALLBACK(compose_changed_cb),
2696 mark = gtk_text_buffer_get_insert(buffer);
2697 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2698 cur_pos = gtk_text_iter_get_offset (&iter);
2700 gtk_text_buffer_get_end_iter(buffer, &iter);
2702 if (replace && compose->sig_str) {
2704 GtkTextIter first_iter, start_iter, end_iter;
2706 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2708 if (compose->sig_str[0] == '\0')
2711 found = gtk_text_iter_forward_search(&first_iter,
2713 GTK_TEXT_SEARCH_TEXT_ONLY,
2714 &start_iter, &end_iter,
2718 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2723 g_free(compose->sig_str);
2724 compose->sig_str = compose_get_signature_str(compose);
2725 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2726 compose->sig_str = g_strdup("");
2728 cur_pos = gtk_text_iter_get_offset(&iter);
2729 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2731 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2732 gtk_text_iter_forward_char(&iter);
2733 gtk_text_iter_forward_char(&iter);
2734 gtk_text_buffer_get_end_iter(buffer, &iter_end);
2735 gtk_text_buffer_apply_tag_by_name(buffer,"signature",&iter, &iter_end);
2737 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2738 cur_pos = gtk_text_buffer_get_char_count (buffer);
2740 /* put the cursor where it should be
2741 * either where the quote_fmt says, either before the signature */
2742 if (compose->set_cursor_pos < 0)
2743 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2745 gtk_text_buffer_get_iter_at_offset(buffer, &iter,
2746 compose->set_cursor_pos);
2748 gtk_text_buffer_place_cursor(buffer, &iter);
2749 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2750 G_CALLBACK(compose_changed_cb),
2753 compose->autowrap = prev_autowrap;
2754 if (compose->autowrap)
2755 compose_wrap_all(compose);
2758 static gchar *compose_get_signature_str(Compose *compose)
2760 gchar *sig_body = NULL;
2761 gchar *sig_str = NULL;
2762 gchar *utf8_sig_str = NULL;
2764 g_return_val_if_fail(compose->account != NULL, NULL);
2766 if (!compose->account->sig_path)
2769 if (compose->account->sig_type == SIG_FILE) {
2770 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2771 g_warning("can't open signature file: %s\n",
2772 compose->account->sig_path);
2777 if (compose->account->sig_type == SIG_COMMAND)
2778 sig_body = get_command_output(compose->account->sig_path);
2782 tmp = file_read_to_str(compose->account->sig_path);
2785 sig_body = normalize_newlines(tmp);
2789 if (compose->account->sig_sep) {
2790 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2794 sig_str = g_strconcat("\n\n", sig_body, NULL);
2797 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
2798 utf8_sig_str = sig_str;
2800 utf8_sig_str = conv_codeset_strdup
2801 (sig_str, conv_get_locale_charset_str_no_utf8(),
2807 return utf8_sig_str;
2810 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2813 GtkTextBuffer *buffer;
2816 const gchar *cur_encoding;
2817 gchar buf[BUFFSIZE];
2820 gboolean prev_autowrap;
2821 gboolean badtxt = FALSE;
2823 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2825 if ((fp = g_fopen(file, "rb")) == NULL) {
2826 FILE_OP_ERROR(file, "fopen");
2827 return COMPOSE_INSERT_READ_ERROR;
2830 prev_autowrap = compose->autowrap;
2831 compose->autowrap = FALSE;
2833 text = GTK_TEXT_VIEW(compose->text);
2834 buffer = gtk_text_view_get_buffer(text);
2835 mark = gtk_text_buffer_get_insert(buffer);
2836 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2838 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2839 G_CALLBACK(text_inserted),
2842 cur_encoding = conv_get_locale_charset_str_no_utf8();
2844 while (fgets(buf, sizeof(buf), fp) != NULL) {
2847 if (g_utf8_validate(buf, -1, NULL) == TRUE)
2848 str = g_strdup(buf);
2850 str = conv_codeset_strdup
2851 (buf, cur_encoding, CS_INTERNAL);
2854 /* strip <CR> if DOS/Windows file,
2855 replace <CR> with <LF> if Macintosh file. */
2858 if (len > 0 && str[len - 1] != '\n') {
2860 if (str[len] == '\r') str[len] = '\n';
2863 gtk_text_buffer_insert(buffer, &iter, str, -1);
2867 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2868 G_CALLBACK(text_inserted),
2870 compose->autowrap = prev_autowrap;
2871 if (compose->autowrap)
2872 compose_wrap_all(compose);
2877 return COMPOSE_INSERT_INVALID_CHARACTER;
2879 return COMPOSE_INSERT_SUCCESS;
2882 static void compose_attach_append(Compose *compose, const gchar *file,
2883 const gchar *filename,
2884 const gchar *content_type)
2892 GtkListStore *store;
2894 gboolean has_binary = FALSE;
2896 if (!is_file_exist(file)) {
2897 g_warning("File %s doesn't exist\n", filename);
2900 if ((size = get_file_size(file)) < 0) {
2901 g_warning("Can't get file size of %s\n", filename);
2905 alertpanel_notice(_("File %s is empty."), filename);
2908 if ((fp = g_fopen(file, "rb")) == NULL) {
2909 alertpanel_error(_("Can't read %s."), filename);
2914 ainfo = g_new0(AttachInfo, 1);
2915 auto_ainfo = g_auto_pointer_new_with_free
2916 (ainfo, (GFreeFunc) compose_attach_info_free);
2917 ainfo->file = g_strdup(file);
2920 ainfo->content_type = g_strdup(content_type);
2921 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2923 MsgFlags flags = {0, 0};
2925 if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
2926 ainfo->encoding = ENC_7BIT;
2928 ainfo->encoding = ENC_8BIT;
2930 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2931 if (msginfo && msginfo->subject)
2932 name = g_strdup(msginfo->subject);
2934 name = g_path_get_basename(filename ? filename : file);
2936 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2938 procmsg_msginfo_free(msginfo);
2940 if (!g_ascii_strncasecmp(content_type, "text", 4))
2941 ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
2943 ainfo->encoding = ENC_BASE64;
2944 name = g_path_get_basename(filename ? filename : file);
2945 ainfo->name = g_strdup(name);
2949 ainfo->content_type = procmime_get_mime_type(file);
2950 if (!ainfo->content_type) {
2951 ainfo->content_type =
2952 g_strdup("application/octet-stream");
2953 ainfo->encoding = ENC_BASE64;
2954 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2956 procmime_get_encoding_for_text_file(file, &has_binary);
2958 ainfo->encoding = ENC_BASE64;
2959 name = g_path_get_basename(filename ? filename : file);
2960 ainfo->name = g_strdup(name);
2964 if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
2965 g_free(ainfo->content_type);
2966 ainfo->content_type = g_strdup("application/octet-stream");
2970 size_text = to_human_readable(size);
2972 store = GTK_LIST_STORE(gtk_tree_view_get_model
2973 (GTK_TREE_VIEW(compose->attach_clist)));
2975 gtk_list_store_append(store, &iter);
2976 gtk_list_store_set(store, &iter,
2977 COL_MIMETYPE, ainfo->content_type,
2978 COL_SIZE, size_text,
2979 COL_NAME, ainfo->name,
2981 COL_AUTODATA, auto_ainfo,
2984 g_auto_pointer_free(auto_ainfo);
2987 static void compose_use_signing(Compose *compose, gboolean use_signing)
2989 GtkItemFactory *ifactory;
2990 GtkWidget *menuitem = NULL;
2992 compose->use_signing = use_signing;
2993 ifactory = gtk_item_factory_from_widget(compose->menubar);
2994 menuitem = gtk_item_factory_get_item
2995 (ifactory, "/Options/Sign");
2996 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3000 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
3002 GtkItemFactory *ifactory;
3003 GtkWidget *menuitem = NULL;
3005 compose->use_encryption = use_encryption;
3006 ifactory = gtk_item_factory_from_widget(compose->menubar);
3007 menuitem = gtk_item_factory_get_item
3008 (ifactory, "/Options/Encrypt");
3010 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3014 #define NEXT_PART_NOT_CHILD(info) \
3016 node = info->node; \
3017 while (node->children) \
3018 node = g_node_last_child(node); \
3019 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
3022 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
3026 MimeInfo *firsttext = NULL;
3027 MimeInfo *encrypted = NULL;
3030 const gchar *partname = NULL;
3032 mimeinfo = procmime_scan_message(msginfo);
3033 if (!mimeinfo) return;
3035 if (mimeinfo->node->children == NULL) {
3036 procmime_mimeinfo_free_all(mimeinfo);
3040 /* find first content part */
3041 child = (MimeInfo *) mimeinfo->node->children->data;
3042 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
3043 child = (MimeInfo *)child->node->children->data;
3045 if (child->type == MIMETYPE_TEXT) {
3047 debug_print("First text part found\n");
3048 } else if (compose->mode == COMPOSE_REEDIT &&
3049 child->type == MIMETYPE_APPLICATION &&
3050 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
3051 encrypted = (MimeInfo *)child->node->parent->data;
3054 child = (MimeInfo *) mimeinfo->node->children->data;
3055 while (child != NULL) {
3056 if (child == encrypted) {
3057 /* skip this part of tree */
3058 NEXT_PART_NOT_CHILD(child);
3062 if (child->type == MIMETYPE_MULTIPART) {
3063 /* get the actual content */
3064 child = procmime_mimeinfo_next(child);
3068 if (child == firsttext) {
3069 child = procmime_mimeinfo_next(child);
3073 outfile = procmime_get_tmp_file_name(child);
3074 if (procmime_get_part(outfile, child) < 0)
3075 g_warning("Can't get the part of multipart message.");
3077 gchar *content_type;
3079 content_type = procmime_get_content_type_str(child->type, child->subtype);
3081 /* if we meet a pgp signature, we don't attach it, but
3082 * we force signing. */
3083 if (strcmp(content_type, "application/pgp-signature")) {
3084 partname = procmime_mimeinfo_get_parameter(child, "filename");
3085 if (partname == NULL)
3086 partname = procmime_mimeinfo_get_parameter(child, "name");
3087 if (partname == NULL)
3089 compose_attach_append(compose, outfile,
3090 partname, content_type);
3092 compose_force_signing(compose, compose->account);
3094 g_free(content_type);
3097 NEXT_PART_NOT_CHILD(child);
3099 procmime_mimeinfo_free_all(mimeinfo);
3102 #undef NEXT_PART_NOT_CHILD
3107 WAIT_FOR_INDENT_CHAR,
3108 WAIT_FOR_INDENT_CHAR_OR_SPACE,
3111 /* return indent length, we allow:
3112 indent characters followed by indent characters or spaces/tabs,
3113 alphabets and numbers immediately followed by indent characters,
3114 and the repeating sequences of the above
3115 If quote ends with multiple spaces, only the first one is included. */
3116 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
3117 const GtkTextIter *start, gint *len)
3119 GtkTextIter iter = *start;
3123 IndentState state = WAIT_FOR_INDENT_CHAR;
3126 gint alnum_count = 0;
3127 gint space_count = 0;
3130 if (prefs_common.quote_chars == NULL) {
3134 while (!gtk_text_iter_ends_line(&iter)) {
3135 wc = gtk_text_iter_get_char(&iter);
3136 if (g_unichar_iswide(wc))
3138 clen = g_unichar_to_utf8(wc, ch);
3142 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
3143 is_space = g_unichar_isspace(wc);
3145 if (state == WAIT_FOR_INDENT_CHAR) {
3146 if (!is_indent && !g_unichar_isalnum(wc))
3149 quote_len += alnum_count + space_count + 1;
3150 alnum_count = space_count = 0;
3151 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
3154 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
3155 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
3159 else if (is_indent) {
3160 quote_len += alnum_count + space_count + 1;
3161 alnum_count = space_count = 0;
3164 state = WAIT_FOR_INDENT_CHAR;
3168 gtk_text_iter_forward_char(&iter);
3171 if (quote_len > 0 && space_count > 0)
3177 if (quote_len > 0) {
3179 gtk_text_iter_forward_chars(&iter, quote_len);
3180 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
3186 /* return TRUE if the line is itemized */
3187 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
3188 const GtkTextIter *start)
3190 GtkTextIter iter = *start;
3195 if (gtk_text_iter_ends_line(&iter))
3199 wc = gtk_text_iter_get_char(&iter);
3200 if (!g_unichar_isspace(wc))
3202 gtk_text_iter_forward_char(&iter);
3203 if (gtk_text_iter_ends_line(&iter))
3207 clen = g_unichar_to_utf8(wc, ch);
3211 if (!strchr("*-+", ch[0]))
3214 gtk_text_iter_forward_char(&iter);
3215 if (gtk_text_iter_ends_line(&iter))
3217 wc = gtk_text_iter_get_char(&iter);
3218 if (g_unichar_isspace(wc))
3224 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
3225 const GtkTextIter *start,
3226 GtkTextIter *break_pos,
3230 GtkTextIter iter = *start, line_end = *start;
3231 PangoLogAttr *attrs;
3238 gboolean can_break = FALSE;
3239 gboolean do_break = FALSE;
3240 gboolean was_white = FALSE;
3241 gboolean prev_dont_break = FALSE;
3243 gtk_text_iter_forward_to_line_end(&line_end);
3244 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
3245 len = g_utf8_strlen(str, -1);
3246 /* g_print("breaking line: %d: %s (len = %d)\n",
3247 gtk_text_iter_get_line(&iter), str, len); */
3248 attrs = g_new(PangoLogAttr, len + 1);
3250 pango_default_break(str, -1, NULL, attrs, len + 1);