2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2005 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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>
69 /* #include <sys/utsname.h> */
76 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
82 #include "mainwindow.h"
84 #include "addressbook.h"
85 #include "folderview.h"
88 #include "stock_pixmap.h"
89 #include "send_message.h"
92 #include "customheader.h"
93 #include "prefs_common.h"
94 #include "prefs_account.h"
98 #include "procheader.h"
100 #include "statusbar.h"
103 #include "quoted-printable.h"
104 #include "codeconv.h"
106 #include "gtkutils.h"
108 #include "alertpanel.h"
109 #include "manage_window.h"
110 #include "gtkshruler.h"
112 #include "addr_compl.h"
113 #include "quote_fmt.h"
114 #include "template.h"
116 #include "foldersel.h"
129 #define N_ATTACH_COLS (N_COL_COLUMNS)
133 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
134 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
135 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
136 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
137 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
138 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
141 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
142 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
143 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
144 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
145 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
146 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
148 } ComposeCallAdvancedAction;
152 PRIORITY_HIGHEST = 1,
161 COMPOSE_INSERT_SUCCESS,
162 COMPOSE_INSERT_READ_ERROR,
163 COMPOSE_INSERT_INVALID_CHARACTER,
164 COMPOSE_INSERT_NO_FILE
165 } ComposeInsertResult;
169 COMPOSE_QUIT_EDITING,
170 COMPOSE_KEEP_EDITING,
172 } ComposeDraftAction;
176 COMPOSE_WRITE_FOR_SEND,
177 COMPOSE_WRITE_FOR_STORE
180 #define B64_LINE_SIZE 57
181 #define B64_BUFFSIZE 77
183 #define MAX_REFERENCES_LEN 999
185 static GdkColor quote_color = {0, 0, 0, 0xbfff};
187 static GList *compose_list = NULL;
189 Compose *compose_generic_new (PrefsAccount *account,
192 GPtrArray *attach_files,
193 GList *listAddress );
195 static Compose *compose_create (PrefsAccount *account,
198 static GtkWidget *compose_account_option_menu_create
200 static void compose_set_out_encoding (Compose *compose);
201 static void compose_set_template_menu (Compose *compose);
202 static void compose_template_apply (Compose *compose,
205 static void compose_destroy (Compose *compose);
207 static void compose_entries_set (Compose *compose,
208 const gchar *mailto);
209 static gint compose_parse_header (Compose *compose,
211 static gchar *compose_parse_references (const gchar *ref,
214 static gchar *compose_quote_fmt (Compose *compose,
220 static void compose_reply_set_entry (Compose *compose,
226 followup_and_reply_to);
227 static void compose_reedit_set_entry (Compose *compose,
230 static void compose_insert_sig (Compose *compose,
232 static gchar *compose_get_signature_str (Compose *compose);
233 static ComposeInsertResult compose_insert_file (Compose *compose,
236 static void compose_attach_append (Compose *compose,
239 const gchar *content_type);
240 static void compose_attach_parts (Compose *compose,
243 static void compose_wrap_paragraph (Compose *compose,
244 GtkTextIter *par_iter);
245 static void compose_wrap_all (Compose *compose);
246 static void compose_wrap_all_full (Compose *compose,
249 static void compose_set_title (Compose *compose);
250 static void compose_select_account (Compose *compose,
251 PrefsAccount *account,
254 static PrefsAccount *compose_current_mail_account(void);
255 /* static gint compose_send (Compose *compose); */
256 static gboolean compose_check_for_valid_recipient
258 static gboolean compose_check_entries (Compose *compose,
259 gboolean check_subject);
260 static gint compose_write_to_file (Compose *compose,
263 static gint compose_write_body_to_file (Compose *compose,
265 static gint compose_remove_reedit_target (Compose *compose);
266 void compose_remove_draft (Compose *compose);
267 static gint compose_queue (Compose *compose,
270 static gint compose_queue_sub (Compose *compose,
273 gboolean check_subject);
274 static void compose_add_attachments (Compose *compose,
276 static gchar *compose_get_header (Compose *compose);
278 static void compose_convert_header (Compose *compose,
283 gboolean addr_field);
285 static void compose_attach_info_free (AttachInfo *ainfo);
286 static void compose_attach_remove_selected (Compose *compose);
288 static void compose_attach_property (Compose *compose);
289 static void compose_attach_property_create (gboolean *cancelled);
290 static void attach_property_ok (GtkWidget *widget,
291 gboolean *cancelled);
292 static void attach_property_cancel (GtkWidget *widget,
293 gboolean *cancelled);
294 static gint attach_property_delete_event (GtkWidget *widget,
296 gboolean *cancelled);
297 static gboolean attach_property_key_pressed (GtkWidget *widget,
299 gboolean *cancelled);
301 static void compose_exec_ext_editor (Compose *compose);
302 static gint compose_exec_ext_editor_real (const gchar *file);
303 static gboolean compose_ext_editor_kill (Compose *compose);
304 static void compose_input_cb (gpointer data,
306 GdkInputCondition condition);
307 static void compose_set_ext_editor_sensitive (Compose *compose,
310 static void compose_undo_state_changed (UndoMain *undostruct,
315 static void compose_create_header_entry (Compose *compose);
316 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
317 static void compose_update_priority_menu_item(Compose * compose);
319 static void compose_add_field_list ( Compose *compose,
320 GList *listAddress );
322 /* callback functions */
324 static gboolean compose_edit_size_alloc (GtkEditable *widget,
325 GtkAllocation *allocation,
326 GtkSHRuler *shruler);
327 static void account_activated (GtkMenuItem *menuitem,
329 static void attach_selected (GtkTreeView *tree_view,
330 GtkTreePath *tree_path,
331 GtkTreeViewColumn *column,
333 static gboolean attach_button_pressed (GtkWidget *widget,
334 GdkEventButton *event,
336 static gboolean attach_key_pressed (GtkWidget *widget,
340 static void compose_send_cb (gpointer data,
343 static void compose_send_later_cb (gpointer data,
347 static void compose_draft_cb (gpointer data,
351 static void compose_attach_cb (gpointer data,
354 static void compose_insert_file_cb (gpointer data,
357 static void compose_insert_sig_cb (gpointer data,
361 static void compose_close_cb (gpointer data,
365 static void compose_set_encoding_cb (gpointer data,
369 static void compose_address_cb (gpointer data,
372 static void compose_template_activate_cb(GtkWidget *widget,
375 static void compose_ext_editor_cb (gpointer data,
379 static gint compose_delete_cb (GtkWidget *widget,
383 static void compose_undo_cb (Compose *compose);
384 static void compose_redo_cb (Compose *compose);
385 static void compose_cut_cb (Compose *compose);
386 static void compose_copy_cb (Compose *compose);
387 static void compose_paste_cb (Compose *compose);
388 static void compose_paste_as_quote_cb (Compose *compose);
389 static void compose_allsel_cb (Compose *compose);
391 static void compose_advanced_action_cb (Compose *compose,
392 ComposeCallAdvancedAction action);
394 static void compose_grab_focus_cb (GtkWidget *widget,
397 static void compose_changed_cb (GtkTextBuffer *textbuf,
400 static void compose_wrap_cb (gpointer data,
403 static void compose_toggle_autowrap_cb (gpointer data,
408 static void compose_toggle_to_cb (gpointer data,
411 static void compose_toggle_cc_cb (gpointer data,
414 static void compose_toggle_bcc_cb (gpointer data,
417 static void compose_toggle_replyto_cb (gpointer data,
420 static void compose_toggle_followupto_cb(gpointer data,
423 static void compose_toggle_attach_cb (gpointer data,
427 static void compose_toggle_ruler_cb (gpointer data,
430 static void compose_toggle_sign_cb (gpointer data,
433 static void compose_toggle_encrypt_cb (gpointer data,
436 static void compose_set_privacy_system_cb(GtkWidget *widget,
438 static void compose_update_privacy_system_menu_item(Compose * compose);
439 static void activate_privacy_system (Compose *compose,
440 PrefsAccount *account);
441 static void compose_use_signing(Compose *compose, gboolean use_signing);
442 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
443 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
445 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
447 static void compose_set_priority_cb (gpointer data,
451 static void compose_attach_drag_received_cb (GtkWidget *widget,
452 GdkDragContext *drag_context,
455 GtkSelectionData *data,
459 static void compose_insert_drag_received_cb (GtkWidget *widget,
460 GdkDragContext *drag_context,
463 GtkSelectionData *data,
467 static void compose_header_drag_received_cb (GtkWidget *widget,
468 GdkDragContext *drag_context,
471 GtkSelectionData *data,
476 static gboolean compose_drag_drop (GtkWidget *widget,
477 GdkDragContext *drag_context,
479 guint time, gpointer user_data);
481 static void to_activated (GtkWidget *widget,
483 static void newsgroups_activated (GtkWidget *widget,
485 static void cc_activated (GtkWidget *widget,
487 static void bcc_activated (GtkWidget *widget,
489 static void replyto_activated (GtkWidget *widget,
491 static void followupto_activated (GtkWidget *widget,
493 static void subject_activated (GtkWidget *widget,
497 static void text_inserted (GtkTextBuffer *buffer,
502 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
503 gboolean to_all, gboolean to_ml,
505 gboolean followup_and_reply_to,
508 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
509 ComposeHeaderEntry *headerentry);
510 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
512 ComposeHeaderEntry *headerentry);
514 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
516 static void compose_allow_user_actions (Compose *compose, gboolean allow);
519 static void compose_check_all (Compose *compose);
520 static void compose_highlight_all (Compose *compose);
521 static void compose_check_backwards (Compose *compose);
522 static void compose_check_forwards_go (Compose *compose);
525 static gint compose_defer_auto_save_draft (Compose *compose);
526 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
528 static void compose_close (Compose *compose);
530 static GtkItemFactoryEntry compose_popup_entries[] =
532 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
533 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
534 {N_("/---"), NULL, NULL, 0, "<Separator>"},
535 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
538 static GtkItemFactoryEntry compose_entries[] =
540 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
541 {N_("/_Message/_Send"), "<control>Return",
542 compose_send_cb, 0, NULL},
543 {N_("/_Message/Send _later"), "<shift><control>S",
544 compose_send_later_cb, 0, NULL},
545 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
546 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
547 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
548 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
549 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
550 {N_("/_Message/_Save"),
551 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
552 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
553 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
555 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
556 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
557 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
558 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
559 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
560 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
561 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
562 {N_("/_Edit/Paste as _quotation"),
563 NULL, compose_paste_as_quote_cb, 0, NULL},
564 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
565 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
566 {N_("/_Edit/A_dvanced/Move a character backward"),
568 compose_advanced_action_cb,
569 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
571 {N_("/_Edit/A_dvanced/Move a character forward"),
573 compose_advanced_action_cb,
574 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
576 {N_("/_Edit/A_dvanced/Move a word backward"),
578 compose_advanced_action_cb,
579 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
581 {N_("/_Edit/A_dvanced/Move a word forward"),
583 compose_advanced_action_cb,
584 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
586 {N_("/_Edit/A_dvanced/Move to beginning of line"),
587 NULL, /* "<control>A" */
588 compose_advanced_action_cb,
589 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
591 {N_("/_Edit/A_dvanced/Move to end of line"),
593 compose_advanced_action_cb,
594 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
596 {N_("/_Edit/A_dvanced/Move to previous line"),
598 compose_advanced_action_cb,
599 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
601 {N_("/_Edit/A_dvanced/Move to next line"),
603 compose_advanced_action_cb,
604 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
606 {N_("/_Edit/A_dvanced/Delete a character backward"),
608 compose_advanced_action_cb,
609 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
611 {N_("/_Edit/A_dvanced/Delete a character forward"),
613 compose_advanced_action_cb,
614 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
616 {N_("/_Edit/A_dvanced/Delete a word backward"),
617 NULL, /* "<control>W" */
618 compose_advanced_action_cb,
619 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
621 {N_("/_Edit/A_dvanced/Delete a word forward"),
622 NULL, /* "<alt>D", */
623 compose_advanced_action_cb,
624 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
626 {N_("/_Edit/A_dvanced/Delete line"),
628 compose_advanced_action_cb,
629 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
631 {N_("/_Edit/A_dvanced/Delete entire line"),
633 compose_advanced_action_cb,
634 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
636 {N_("/_Edit/A_dvanced/Delete to end of line"),
638 compose_advanced_action_cb,
639 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
641 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
642 {N_("/_Edit/_Wrap current paragraph"),
643 "<control>L", compose_wrap_cb, 0, NULL},
644 {N_("/_Edit/Wrap all long _lines"),
645 "<control><alt>L", compose_wrap_cb, 1, NULL},
646 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
647 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
648 {N_("/_Edit/Edit with e_xternal editor"),
649 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
651 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
652 {N_("/_Spelling/_Check all or check selection"),
653 NULL, compose_check_all, 0, NULL},
654 {N_("/_Spelling/_Highlight all misspelled words"),
655 NULL, compose_highlight_all, 0, NULL},
656 {N_("/_Spelling/Check _backwards misspelled word"),
657 NULL, compose_check_backwards , 0, NULL},
658 {N_("/_Spelling/_Forward to next misspelled word"),
659 NULL, compose_check_forwards_go, 0, NULL},
660 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
661 {N_("/_Spelling/_Spelling Configuration"),
662 NULL, NULL, 0, "<Branch>"},
664 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
665 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
666 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
667 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
668 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
669 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
670 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
671 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
672 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
673 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
674 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
675 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
676 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
677 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
678 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
679 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
680 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
682 #define ENC_ACTION(action) \
683 NULL, compose_set_encoding_cb, action, \
684 "/Options/Character encoding/Automatic"
686 {N_("/_Options/Character _encoding"), NULL, NULL, 0, "<Branch>"},
687 {N_("/_Options/Character _encoding/_Automatic"),
688 NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
689 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
691 {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
692 ENC_ACTION(C_US_ASCII)},
693 {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
694 ENC_ACTION(C_UTF_8)},
695 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
697 {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
698 ENC_ACTION(C_ISO_8859_1)},
699 {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
700 ENC_ACTION(C_ISO_8859_15)},
701 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
703 {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
704 ENC_ACTION(C_ISO_8859_2)},
705 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
707 {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
708 ENC_ACTION(C_ISO_8859_13)},
709 {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
710 ENC_ACTION(C_ISO_8859_4)},
711 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
713 {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
714 ENC_ACTION(C_ISO_8859_7)},
715 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
717 {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
718 ENC_ACTION(C_ISO_8859_8)},
719 {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
720 ENC_ACTION(C_WINDOWS_1255)},
721 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
723 {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
724 ENC_ACTION(C_ISO_8859_9)},
725 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
727 {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
728 ENC_ACTION(C_ISO_8859_5)},
729 {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
730 ENC_ACTION(C_KOI8_R)},
731 {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
732 ENC_ACTION(C_KOI8_U)},
733 {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
734 ENC_ACTION(C_WINDOWS_1251)},
735 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
737 {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
738 ENC_ACTION(C_ISO_2022_JP)},
739 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
741 {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
742 ENC_ACTION(C_GB2312)},
743 {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
745 {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
747 {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
748 ENC_ACTION(C_EUC_TW)},
749 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
751 {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
752 ENC_ACTION(C_EUC_KR)},
753 {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
755 {N_("/_Options/Character _encoding/Thai (TIS-620)"),
756 ENC_ACTION(C_TIS_620)},
757 {N_("/_Options/Character _encoding/Thai (Windows-874)"),
758 ENC_ACTION(C_WINDOWS_874)},
760 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
761 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
762 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
763 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
764 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
765 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
766 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
769 static GtkTargetEntry compose_mime_types[] =
771 {"text/uri-list", 0, 0},
772 {"text/plain", 0, 0},
776 static gboolean compose_put_existing_to_front(MsgInfo *info)
778 GList *compose_list = compose_get_compose_list();
782 for (elem = compose_list; elem != NULL && elem->data != NULL;
784 Compose *c = (Compose*)elem->data;
786 if (!c->targetinfo || !c->targetinfo->msgid ||
790 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
791 gtkut_window_popup(c->window);
799 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
800 GPtrArray *attach_files)
802 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
805 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
807 return compose_generic_new(account, NULL, item, NULL, NULL);
810 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
812 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
815 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
816 GPtrArray *attach_files, GList *listAddress )
819 GtkTextView *textview;
820 GtkTextBuffer *textbuf;
822 GtkItemFactory *ifactory;
824 if (item && item->prefs && item->prefs->enable_default_account)
825 account = account_find_from_id(item->prefs->default_account);
827 if (!account) account = cur_account;
828 g_return_val_if_fail(account != NULL, NULL);
830 compose = compose_create(account, COMPOSE_NEW);
831 ifactory = gtk_item_factory_from_widget(compose->menubar);
833 compose->replyinfo = NULL;
834 compose->fwdinfo = NULL;
836 textview = GTK_TEXT_VIEW(compose->text);
837 textbuf = gtk_text_view_get_buffer(textview);
839 undo_block(compose->undostruct);
841 if (item && item->prefs && item->prefs->enable_default_dictionary &&
843 gtkaspell_change_dict(compose->gtkaspell,
844 item->prefs->default_dictionary);
847 if (account->auto_sig)
848 compose_insert_sig(compose, FALSE);
849 gtk_text_buffer_get_start_iter(textbuf, &iter);
850 gtk_text_buffer_place_cursor(textbuf, &iter);
852 if (account->protocol != A_NNTP) {
853 if (mailto && *mailto != '\0') {
854 compose_entries_set(compose, mailto);
856 } else if (item && item->prefs->enable_default_to) {
857 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
858 compose_entry_mark_default_to(compose, item->prefs->default_to);
860 if (item && item->ret_rcpt) {
861 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
865 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
868 * CLAWS: just don't allow return receipt request, even if the user
869 * may want to send an email. simple but foolproof.
871 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
873 compose_add_field_list( compose, listAddress );
879 for (i = 0; i < attach_files->len; i++) {
880 file = g_ptr_array_index(attach_files, i);
881 compose_attach_append(compose, file, file, NULL);
885 compose_show_first_last_header(compose, TRUE);
887 /* Set save folder */
888 if (item && item->prefs && item->prefs->save_copy_to_folder) {
889 gchar *folderidentifier;
891 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
892 folderidentifier = folder_item_get_identifier(item);
893 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
894 g_free(folderidentifier);
897 gtk_widget_grab_focus(compose->header_last->entry);
899 undo_unblock(compose->undostruct);
901 if (prefs_common.auto_exteditor)
902 compose_exec_ext_editor(compose);
907 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
912 g_return_if_fail(msginfo_list != NULL);
914 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
915 g_return_if_fail(msginfo != NULL);
917 list_len = g_slist_length(msginfo_list);
921 compose_reply(msginfo, prefs_common.reply_with_quote,
922 FALSE, prefs_common.default_reply_list, FALSE, body);
924 case COMPOSE_REPLY_WITH_QUOTE:
925 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
927 case COMPOSE_REPLY_WITHOUT_QUOTE:
928 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
930 case COMPOSE_REPLY_TO_SENDER:
931 compose_reply(msginfo, prefs_common.reply_with_quote,
932 FALSE, FALSE, TRUE, body);
934 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
935 compose_followup_and_reply_to(msginfo,
936 prefs_common.reply_with_quote,
939 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
940 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
942 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
943 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
945 case COMPOSE_REPLY_TO_ALL:
946 compose_reply(msginfo, prefs_common.reply_with_quote,
947 TRUE, FALSE, FALSE, body);
949 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
950 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
952 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
953 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
955 case COMPOSE_REPLY_TO_LIST:
956 compose_reply(msginfo, prefs_common.reply_with_quote,
957 FALSE, TRUE, FALSE, body);
959 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
960 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
962 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
963 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
965 case COMPOSE_FORWARD:
966 if (prefs_common.forward_as_attachment) {
967 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
970 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
974 case COMPOSE_FORWARD_INLINE:
975 /* check if we reply to more than one Message */
977 compose_forward(NULL, msginfo, FALSE, body, FALSE);
980 /* more messages FALL THROUGH */
981 case COMPOSE_FORWARD_AS_ATTACH:
982 compose_forward_multiple(NULL, msginfo_list);
984 case COMPOSE_REDIRECT:
985 compose_redirect(NULL, msginfo);
988 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
992 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
993 gboolean to_ml, gboolean to_sender,
996 compose_generic_reply(msginfo, quote, to_all, to_ml,
997 to_sender, FALSE, body);
1000 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
1005 compose_generic_reply(msginfo, quote, to_all, FALSE,
1006 to_sender, TRUE, body);
1009 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
1010 gboolean to_all, gboolean to_ml,
1012 gboolean followup_and_reply_to,
1015 GtkItemFactory *ifactory;
1017 PrefsAccount *account = NULL;
1018 PrefsAccount *reply_account;
1019 GtkTextView *textview;
1020 GtkTextBuffer *textbuf;
1024 g_return_if_fail(msginfo != NULL);
1025 g_return_if_fail(msginfo->folder != NULL);
1027 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
1029 g_return_if_fail(account != NULL);
1031 if (to_sender && account->protocol == A_NNTP &&
1032 !followup_and_reply_to) {
1034 account_find_from_address(account->address);
1036 reply_account = compose_current_mail_account();
1040 reply_account = account;
1042 compose = compose_create(account, COMPOSE_REPLY);
1043 ifactory = gtk_item_factory_from_widget(compose->menubar);
1045 menu_set_active(ifactory, "/Options/Remove references", FALSE);
1046 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
1048 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
1049 if (!compose->replyinfo)
1050 compose->replyinfo = procmsg_msginfo_copy(msginfo);
1052 if (msginfo->folder && msginfo->folder->ret_rcpt)
1053 menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
1055 /* Set save folder */
1056 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1057 gchar *folderidentifier;
1059 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1060 folderidentifier = folder_item_get_identifier(msginfo->folder);
1061 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1062 g_free(folderidentifier);
1065 if (compose_parse_header(compose, msginfo) < 0) return;
1066 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1067 to_sender, followup_and_reply_to);
1068 compose_show_first_last_header(compose, TRUE);
1070 textview = (GTK_TEXT_VIEW(compose->text));
1071 textbuf = gtk_text_view_get_buffer(textview);
1073 undo_block(compose->undostruct);
1075 if (msginfo->folder && msginfo->folder->prefs &&
1076 msginfo->folder->prefs &&
1077 msginfo->folder->prefs->enable_default_dictionary &&
1079 gtkaspell_change_dict(compose->gtkaspell,
1080 msginfo->folder->prefs->default_dictionary);
1086 if (prefs_common.quotemark && *prefs_common.quotemark)
1087 qmark = prefs_common.quotemark;
1091 compose_quote_fmt(compose, compose->replyinfo,
1092 prefs_common.quotefmt,
1096 if (account->auto_sig)
1097 compose_insert_sig(compose, FALSE);
1099 cursor_pos = quote_fmt_get_cursor_pos();
1100 gtk_text_buffer_get_start_iter(textbuf, &iter);
1101 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cursor_pos);
1102 gtk_text_buffer_place_cursor(textbuf, &iter);
1104 if (quote && prefs_common.linewrap_quote)
1105 compose_wrap_all(compose);
1107 gtk_widget_grab_focus(compose->text);
1109 undo_unblock(compose->undostruct);
1111 if (prefs_common.auto_exteditor)
1112 compose_exec_ext_editor(compose);
1115 #define INSERT_FW_HEADER(var, hdr) \
1116 if (msginfo->var && *msginfo->var) { \
1117 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1118 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1119 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1122 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1123 gboolean as_attach, const gchar *body,
1124 gboolean no_extedit)
1127 GtkTextView *textview;
1128 GtkTextBuffer *textbuf;
1131 g_return_val_if_fail(msginfo != NULL, NULL);
1132 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1135 !(account = compose_guess_forward_account_from_msginfo
1137 account = cur_account;
1139 compose = compose_create(account, COMPOSE_FORWARD);
1141 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1142 if (!compose->fwdinfo)
1143 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1145 if (msginfo->subject && *msginfo->subject) {
1146 gchar *buf, *buf2, *p;
1148 buf = p = g_strdup(msginfo->subject);
1149 p += subject_get_prefix_length(p);
1150 memmove(buf, p, strlen(p) + 1);
1152 buf2 = g_strdup_printf("Fw: %s", buf);
1153 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1159 textview = GTK_TEXT_VIEW(compose->text);
1160 textbuf = gtk_text_view_get_buffer(textview);
1165 msgfile = procmsg_get_message_file_path(msginfo);
1166 if (!is_file_exist(msgfile))
1167 g_warning("%s: file not exist\n", msgfile);
1169 compose_attach_append(compose, msgfile, msgfile,
1175 MsgInfo *full_msginfo;
1177 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1179 full_msginfo = procmsg_msginfo_copy(msginfo);
1181 if (prefs_common.fw_quotemark &&
1182 *prefs_common.fw_quotemark)
1183 qmark = prefs_common.fw_quotemark;
1187 compose_quote_fmt(compose, full_msginfo,
1188 prefs_common.fw_quotefmt,
1190 compose_attach_parts(compose, msginfo);
1192 procmsg_msginfo_free(full_msginfo);
1195 if (account->auto_sig)
1196 compose_insert_sig(compose, FALSE);
1198 if (prefs_common.linewrap_quote)
1199 compose_wrap_all(compose);
1201 gtk_text_buffer_get_start_iter(textbuf, &iter);
1202 gtk_text_buffer_place_cursor(textbuf, &iter);
1204 #if 0 /* NEW COMPOSE GUI */
1205 if (account->protocol != A_NNTP)
1206 gtk_widget_grab_focus(compose->to_entry);
1208 gtk_widget_grab_focus(compose->newsgroups_entry);
1210 gtk_widget_grab_focus(compose->header_last->entry);
1212 if (!no_extedit && prefs_common.auto_exteditor)
1213 compose_exec_ext_editor(compose);
1216 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1217 gchar *folderidentifier;
1219 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1220 folderidentifier = folder_item_get_identifier(msginfo->folder);
1221 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1222 g_free(folderidentifier);
1228 #undef INSERT_FW_HEADER
1230 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1233 GtkTextView *textview;
1234 GtkTextBuffer *textbuf;
1239 g_return_val_if_fail(msginfo_list != NULL, NULL);
1241 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1242 if (((MsgInfo *)msginfo->data)->folder == NULL)
1245 /* guess account from first selected message */
1247 !(account = compose_guess_forward_account_from_msginfo
1248 (msginfo_list->data)))
1249 account = cur_account;
1251 g_return_val_if_fail(account != NULL, NULL);
1253 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1254 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1255 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1258 compose = compose_create(account, COMPOSE_FORWARD);
1260 textview = GTK_TEXT_VIEW(compose->text);
1261 textbuf = gtk_text_view_get_buffer(textview);
1263 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1264 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1265 if (!is_file_exist(msgfile))
1266 g_warning("%s: file not exist\n", msgfile);
1268 compose_attach_append(compose, msgfile, msgfile,
1273 if (account->auto_sig)
1274 compose_insert_sig(compose, FALSE);
1276 if (prefs_common.linewrap_quote)
1277 compose_wrap_all(compose);
1279 gtk_text_buffer_get_start_iter(textbuf, &iter);
1280 gtk_text_buffer_place_cursor(textbuf, &iter);
1282 gtk_widget_grab_focus(compose->header_last->entry);
1284 #if 0 /* NEW COMPOSE GUI */
1285 if (account->protocol != A_NNTP)
1286 gtk_widget_grab_focus(compose->to_entry);
1288 gtk_widget_grab_focus(compose->newsgroups_entry);
1294 void compose_reedit(MsgInfo *msginfo)
1296 Compose *compose = NULL;
1297 PrefsAccount *account = NULL;
1298 GtkTextView *textview;
1299 GtkTextBuffer *textbuf;
1303 gchar buf[BUFFSIZE];
1304 gboolean use_signing = FALSE;
1305 gboolean use_encryption = FALSE;
1306 gchar *privacy_system = NULL;
1308 g_return_if_fail(msginfo != NULL);
1309 g_return_if_fail(msginfo->folder != NULL);
1311 if (compose_put_existing_to_front(msginfo))
1314 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1315 gchar queueheader_buf[BUFFSIZE];
1318 /* Select Account from queue headers */
1319 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1320 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1321 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1322 account = account_find_from_id(id);
1324 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1325 sizeof(queueheader_buf), "NAID:")) {
1326 id = atoi(&queueheader_buf[strlen("NAID:")]);
1327 account = account_find_from_id(id);
1329 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1330 sizeof(queueheader_buf), "MAID:")) {
1331 id = atoi(&queueheader_buf[strlen("MAID:")]);
1332 account = account_find_from_id(id);
1334 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1335 sizeof(queueheader_buf), "S:")) {
1336 account = account_find_from_address(queueheader_buf);
1338 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1339 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1340 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1341 use_signing = param;
1344 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1345 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1346 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1347 use_encryption = param;
1349 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1350 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1351 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1353 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1354 sizeof(queueheader_buf), "X-Priority: ")) {
1355 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1356 compose->priority = param;
1359 account = msginfo->folder->folder->account;
1361 if (!account && prefs_common.reedit_account_autosel) {
1362 gchar from[BUFFSIZE];
1363 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1364 extract_address(from);
1365 account = account_find_from_address(from);
1368 if (!account) account = cur_account;
1369 g_return_if_fail(account != NULL);
1371 compose = compose_create(account, COMPOSE_REEDIT);
1372 compose->privacy_system = privacy_system;
1373 compose_use_signing(compose, use_signing);
1374 compose_use_encryption(compose, use_encryption);
1375 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1377 if (msginfo->folder->stype == F_QUEUE
1378 || msginfo->folder->stype == F_DRAFT) {
1379 gchar queueheader_buf[BUFFSIZE];
1381 /* Set message save folder */
1382 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1385 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1386 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1387 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1391 if (compose_parse_header(compose, msginfo) < 0) return;
1392 compose_reedit_set_entry(compose, msginfo);
1394 textview = GTK_TEXT_VIEW(compose->text);
1395 textbuf = gtk_text_view_get_buffer(textview);
1396 mark = gtk_text_buffer_get_insert(textbuf);
1397 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1399 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1400 G_CALLBACK(compose_changed_cb),
1403 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1404 g_warning("Can't get text part\n");
1406 gboolean prev_autowrap = compose->autowrap;
1408 compose->autowrap = FALSE;
1409 while (fgets(buf, sizeof(buf), fp) != NULL) {
1411 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1413 compose->autowrap = prev_autowrap;
1417 compose_attach_parts(compose, msginfo);
1419 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1420 G_CALLBACK(compose_changed_cb),
1423 gtk_widget_grab_focus(compose->text);
1425 if (prefs_common.auto_exteditor)
1426 compose_exec_ext_editor(compose);
1429 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1433 GtkItemFactory *ifactory;
1436 g_return_val_if_fail(msginfo != NULL, NULL);
1439 account = account_get_reply_account(msginfo,
1440 prefs_common.reply_account_autosel);
1441 g_return_val_if_fail(account != NULL, NULL);
1443 compose = compose_create(account, COMPOSE_REDIRECT);
1444 ifactory = gtk_item_factory_from_widget(compose->menubar);
1446 compose->replyinfo = NULL;
1447 compose->fwdinfo = NULL;
1449 compose_show_first_last_header(compose, TRUE);
1451 gtk_widget_grab_focus(compose->header_last->entry);
1453 filename = procmsg_get_message_file_path(msginfo);
1454 if (filename == NULL)
1457 compose->redirect_filename = filename;
1459 /* Set save folder */
1460 item = msginfo->folder;
1461 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1462 gchar *folderidentifier;
1464 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1465 folderidentifier = folder_item_get_identifier(item);
1466 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1467 g_free(folderidentifier);
1470 compose_attach_parts(compose, msginfo);
1472 if (msginfo->subject)
1473 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1475 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1477 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1478 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1480 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1481 menu_set_sensitive(ifactory, "/Add...", FALSE);
1482 menu_set_sensitive(ifactory, "/Remove", FALSE);
1483 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1485 ifactory = gtk_item_factory_from_widget(compose->menubar);
1486 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1487 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1488 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1489 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1490 menu_set_sensitive(ifactory, "/Edit", FALSE);
1491 menu_set_sensitive(ifactory, "/Options", FALSE);
1492 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1493 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1495 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1496 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1497 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1498 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1499 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1500 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1501 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1506 GList *compose_get_compose_list(void)
1508 return compose_list;
1511 void compose_entry_append(Compose *compose, const gchar *address,
1512 ComposeEntryType type)
1516 gboolean in_quote = FALSE;
1517 if (!address || *address == '\0') return;
1524 header = N_("Bcc:");
1526 case COMPOSE_REPLYTO:
1527 header = N_("Reply-To:");
1529 case COMPOSE_NEWSGROUPS:
1530 header = N_("Newsgroups:");
1532 case COMPOSE_FOLLOWUPTO:
1533 header = N_( "Followup-To:");
1540 header = prefs_common.trans_hdr ? gettext(header) : header;
1542 cur = begin = (gchar *)address;
1544 /* we separate the line by commas, but not if we're inside a quoted
1546 while (*cur != '\0') {
1548 in_quote = !in_quote;
1549 if (*cur == ',' && !in_quote) {
1550 gchar *tmp = g_strdup(begin);
1552 tmp[cur-begin]='\0';
1557 compose_add_header_entry(compose, header, tmp);
1564 gchar *tmp = g_strdup(begin);
1566 tmp[cur-begin]='\0';
1571 compose_add_header_entry(compose, header, tmp);
1576 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1578 static GtkStyle *bold_style = NULL;
1579 static GdkColor bold_color;
1583 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1584 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1585 if (gtk_entry_get_text(entry) &&
1586 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1587 gtk_widget_ensure_style(GTK_WIDGET(entry));
1589 PangoFontDescription *font_desc = NULL;
1590 gtkut_convert_int_to_gdk_color
1591 (prefs_common.color_new, &bold_color);
1592 bold_style = gtk_style_copy(gtk_widget_get_style
1593 (GTK_WIDGET(entry)));
1595 font_desc = pango_font_description_from_string
1598 if (bold_style->font_desc)
1599 pango_font_description_free
1600 (bold_style->font_desc);
1601 bold_style->font_desc = font_desc;
1603 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1605 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1610 void compose_toolbar_cb(gint action, gpointer data)
1612 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1613 Compose *compose = (Compose*)toolbar_item->parent;
1615 g_return_if_fail(compose != NULL);
1619 compose_send_cb(compose, 0, NULL);
1622 compose_send_later_cb(compose, 0, NULL);
1625 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1628 compose_insert_file_cb(compose, 0, NULL);
1631 compose_attach_cb(compose, 0, NULL);
1634 compose_insert_sig(compose, FALSE);
1637 compose_ext_editor_cb(compose, 0, NULL);
1639 case A_LINEWRAP_CURRENT:
1640 compose_wrap_paragraph(compose, NULL);
1642 case A_LINEWRAP_ALL:
1643 compose_wrap_all(compose);
1646 compose_address_cb(compose, 0, NULL);
1649 case A_CHECK_SPELLING:
1650 compose_check_all(compose);
1658 static void compose_entries_set(Compose *compose, const gchar *mailto)
1662 gchar *subject = NULL;
1667 scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body);
1670 compose_entry_append(compose, to, COMPOSE_TO);
1672 compose_entry_append(compose, cc, COMPOSE_CC);
1674 if (!g_utf8_validate (subject, -1, NULL)) {
1675 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1676 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1679 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1683 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1684 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1687 gboolean prev_autowrap = compose->autowrap;
1689 compose->autowrap = FALSE;
1691 mark = gtk_text_buffer_get_insert(buffer);
1692 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1694 if (!g_utf8_validate (body, -1, NULL)) {
1695 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1696 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1699 gtk_text_buffer_insert(buffer, &iter, body, -1);
1701 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1703 compose->autowrap = prev_autowrap;
1704 if (compose->autowrap)
1705 compose_wrap_all(compose);
1714 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1716 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1717 {"Cc:", NULL, TRUE},
1718 {"References:", NULL, FALSE},
1719 {"Bcc:", NULL, TRUE},
1720 {"Newsgroups:", NULL, TRUE},
1721 {"Followup-To:", NULL, TRUE},
1722 {"List-Post:", NULL, FALSE},
1723 {"X-Priority:", NULL, FALSE},
1724 {NULL, NULL, FALSE}};
1740 g_return_val_if_fail(msginfo != NULL, -1);
1742 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1743 procheader_get_header_fields(fp, hentry);
1746 if (hentry[H_REPLY_TO].body != NULL) {
1747 if (hentry[H_REPLY_TO].body[0] != '\0') {
1749 conv_unmime_header(hentry[H_REPLY_TO].body,
1752 g_free(hentry[H_REPLY_TO].body);
1753 hentry[H_REPLY_TO].body = NULL;
1755 if (hentry[H_CC].body != NULL) {
1756 compose->cc = conv_unmime_header(hentry[H_CC].body, NULL);
1757 g_free(hentry[H_CC].body);
1758 hentry[H_CC].body = NULL;
1760 if (hentry[H_REFERENCES].body != NULL) {
1761 if (compose->mode == COMPOSE_REEDIT)
1762 compose->references = hentry[H_REFERENCES].body;
1764 compose->references = compose_parse_references
1765 (hentry[H_REFERENCES].body, msginfo->msgid);
1766 g_free(hentry[H_REFERENCES].body);
1768 hentry[H_REFERENCES].body = NULL;
1770 if (hentry[H_BCC].body != NULL) {
1771 if (compose->mode == COMPOSE_REEDIT)
1773 conv_unmime_header(hentry[H_BCC].body, NULL);
1774 g_free(hentry[H_BCC].body);
1775 hentry[H_BCC].body = NULL;
1777 if (hentry[H_NEWSGROUPS].body != NULL) {
1778 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1779 hentry[H_NEWSGROUPS].body = NULL;
1781 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1782 if (hentry[H_FOLLOWUP_TO].body[0] != '\0') {
1783 compose->followup_to =
1784 conv_unmime_header(hentry[H_FOLLOWUP_TO].body,
1787 g_free(hentry[H_FOLLOWUP_TO].body);
1788 hentry[H_FOLLOWUP_TO].body = NULL;
1790 if (hentry[H_LIST_POST].body != NULL) {
1793 extract_address(hentry[H_LIST_POST].body);
1794 if (hentry[H_LIST_POST].body[0] != '\0') {
1795 scan_mailto_url(hentry[H_LIST_POST].body,
1796 &to, NULL, NULL, NULL, NULL);
1798 g_free(compose->ml_post);
1799 compose->ml_post = to;
1802 g_free(hentry[H_LIST_POST].body);
1803 hentry[H_LIST_POST].body = NULL;
1806 /* CLAWS - X-Priority */
1807 if (compose->mode == COMPOSE_REEDIT)
1808 if (hentry[H_X_PRIORITY].body != NULL) {
1811 priority = atoi(hentry[H_X_PRIORITY].body);
1812 g_free(hentry[H_X_PRIORITY].body);
1814 hentry[H_X_PRIORITY].body = NULL;
1816 if (priority < PRIORITY_HIGHEST ||
1817 priority > PRIORITY_LOWEST)
1818 priority = PRIORITY_NORMAL;
1820 compose->priority = priority;
1823 if (compose->mode == COMPOSE_REEDIT) {
1824 if (msginfo->inreplyto && *msginfo->inreplyto)
1825 compose->inreplyto = g_strdup(msginfo->inreplyto);
1829 if (msginfo->msgid && *msginfo->msgid)
1830 compose->inreplyto = g_strdup(msginfo->msgid);
1832 if (!compose->references) {
1833 if (msginfo->msgid && *msginfo->msgid) {
1834 if (msginfo->inreplyto && *msginfo->inreplyto)
1835 compose->references =
1836 g_strdup_printf("<%s>\n\t<%s>",
1840 compose->references =
1841 g_strconcat("<", msginfo->msgid, ">",
1843 } else if (msginfo->inreplyto && *msginfo->inreplyto) {
1844 compose->references =
1845 g_strconcat("<", msginfo->inreplyto, ">",
1853 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1855 GSList *ref_id_list, *cur;
1859 ref_id_list = references_list_append(NULL, ref);
1860 if (!ref_id_list) return NULL;
1861 if (msgid && *msgid)
1862 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1867 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1868 /* "<" + Message-ID + ">" + CR+LF+TAB */
1869 len += strlen((gchar *)cur->data) + 5;
1871 if (len > MAX_REFERENCES_LEN) {
1872 /* remove second message-ID */
1873 if (ref_id_list && ref_id_list->next &&
1874 ref_id_list->next->next) {
1875 g_free(ref_id_list->next->data);
1876 ref_id_list = g_slist_remove
1877 (ref_id_list, ref_id_list->next->data);
1879 slist_free_strings(ref_id_list);
1880 g_slist_free(ref_id_list);
1887 new_ref = g_string_new("");
1888 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1889 if (new_ref->len > 0)
1890 g_string_append(new_ref, "\n\t");
1891 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
1894 slist_free_strings(ref_id_list);
1895 g_slist_free(ref_id_list);
1897 new_ref_str = new_ref->str;
1898 g_string_free(new_ref, FALSE);
1903 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1904 const gchar *fmt, const gchar *qmark,
1907 static MsgInfo dummyinfo;
1908 gchar *quote_str = NULL;
1912 gboolean prev_autowrap;
1913 const gchar *trimmed_body = body;
1916 msginfo = &dummyinfo;
1918 if (qmark != NULL) {
1919 quote_fmt_init(msginfo, NULL, NULL);
1920 quote_fmt_scan_string(qmark);
1923 buf = quote_fmt_get_buffer();
1925 alertpanel_error(_("Quote mark format error."));
1927 Xstrdup_a(quote_str, buf, return NULL)
1930 if (fmt && *fmt != '\0') {
1931 while (trimmed_body && strlen(trimmed_body) > 1
1932 && trimmed_body[0]=='\n')
1935 quote_fmt_init(msginfo, quote_str, trimmed_body);
1936 quote_fmt_scan_string(fmt);
1939 buf = quote_fmt_get_buffer();
1941 alertpanel_error(_("Message reply/forward format error."));
1947 prev_autowrap = compose->autowrap;
1948 compose->autowrap = FALSE;
1950 for (p = buf; *p != '\0'; ) {
1951 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1952 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1956 g_signal_handlers_block_by_func(G_OBJECT(buffer),
1957 G_CALLBACK(compose_changed_cb),
1959 g_signal_handlers_block_by_func(G_OBJECT(buffer),
1960 G_CALLBACK(text_inserted),
1963 mark = gtk_text_buffer_get_insert(buffer);
1964 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1966 lastp = strchr(p, '\n');
1967 len = lastp ? lastp - p + 1 : -1;
1969 gtk_text_buffer_insert(buffer, &iter, p, len);
1971 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
1972 G_CALLBACK(compose_changed_cb),
1974 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
1975 G_CALLBACK(text_inserted),
1984 compose->autowrap = prev_autowrap;
1985 if (compose->autowrap)
1986 compose_wrap_all(compose);
1991 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1992 gboolean to_all, gboolean to_ml,
1994 gboolean followup_and_reply_to)
1996 GSList *cc_list = NULL;
1999 gchar *replyto = NULL;
2000 GHashTable *to_table;
2002 g_return_if_fail(compose->account != NULL);
2003 g_return_if_fail(msginfo != NULL);
2005 if (compose->account->protocol != A_NNTP) {
2006 if (!compose->replyto && to_ml && compose->ml_post
2007 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
2008 compose_entry_append(compose,
2011 else if (!(to_all || to_sender)
2013 && msginfo->folder->prefs->enable_default_reply_to) {
2014 compose_entry_append(compose,
2015 msginfo->folder->prefs->default_reply_to,
2018 compose_entry_append(compose,
2019 (compose->replyto && !to_sender)
2020 ? compose->replyto :
2021 msginfo->from ? msginfo->from : "",
2024 if (to_sender || (compose->followup_to &&
2025 !strncmp(compose->followup_to, "poster", 6)))
2026 compose_entry_append
2028 (compose->replyto ? compose->replyto :
2029 msginfo->from ? msginfo->from : ""),
2032 else if (followup_and_reply_to || to_all) {
2033 compose_entry_append
2035 (compose->replyto ? compose->replyto :
2036 msginfo->from ? msginfo->from : ""),
2039 compose_entry_append
2041 compose->followup_to ? compose->followup_to :
2042 compose->newsgroups ? compose->newsgroups : "",
2043 COMPOSE_NEWSGROUPS);
2046 compose_entry_append
2048 compose->followup_to ? compose->followup_to :
2049 compose->newsgroups ? compose->newsgroups : "",
2050 COMPOSE_NEWSGROUPS);
2053 if (msginfo->subject && *msginfo->subject) {
2057 buf = p = g_strdup(msginfo->subject);
2058 p += subject_get_prefix_length(p);
2059 memmove(buf, p, strlen(p) + 1);
2061 buf2 = g_strdup_printf("Re: %s", buf);
2062 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
2067 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
2069 if (to_ml && compose->ml_post) return;
2070 if (!to_all || compose->account->protocol == A_NNTP) return;
2072 if (compose->replyto) {
2073 Xstrdup_a(replyto, compose->replyto, return);
2074 extract_address(replyto);
2076 if (msginfo->from) {
2077 Xstrdup_a(from, msginfo->from, return);
2078 extract_address(from);
2081 if (replyto && from)
2082 cc_list = address_list_append_with_comments(cc_list, from);
2083 if (to_all && msginfo->folder &&
2084 msginfo->folder->prefs->enable_default_reply_to)
2085 cc_list = address_list_append_with_comments(cc_list,
2086 msginfo->folder->prefs->default_reply_to);
2087 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
2088 cc_list = address_list_append_with_comments(cc_list, compose->cc);
2090 to_table = g_hash_table_new(g_str_hash, g_str_equal);
2092 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
2093 if (compose->account)
2094 g_hash_table_insert(to_table, g_strdup(compose->account->address),
2095 GINT_TO_POINTER(1));
2097 /* remove address on To: and that of current account */
2098 for (cur = cc_list; cur != NULL; ) {
2099 GSList *next = cur->next;
2102 addr = g_strdup(cur->data);
2103 extract_address(addr);
2105 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2106 cc_list = g_slist_remove(cc_list, cur->data);
2108 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2112 hash_free_strings(to_table);
2113 g_hash_table_destroy(to_table);
2116 for (cur = cc_list; cur != NULL; cur = cur->next)
2117 compose_entry_append(compose, (gchar *)cur->data,
2119 slist_free_strings(cc_list);
2120 g_slist_free(cc_list);
2125 #define SET_ENTRY(entry, str) \
2128 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2131 #define SET_ADDRESS(type, str) \
2134 compose_entry_append(compose, str, type); \
2137 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2139 g_return_if_fail(msginfo != NULL);
2141 SET_ENTRY(subject_entry, msginfo->subject);
2142 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2143 SET_ADDRESS(COMPOSE_CC, compose->cc);
2144 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2145 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2146 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2147 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2149 compose_update_priority_menu_item(compose);
2150 compose_update_privacy_system_menu_item(compose);
2151 compose_show_first_last_header(compose, TRUE);
2157 static void compose_insert_sig(Compose *compose, gboolean replace)
2159 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2160 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2164 gboolean prev_autowrap;
2167 g_return_if_fail(compose->account != NULL);
2169 prev_autowrap = compose->autowrap;
2170 compose->autowrap = FALSE;
2172 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2173 G_CALLBACK(compose_changed_cb),
2176 mark = gtk_text_buffer_get_insert(buffer);
2177 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2178 cur_pos = gtk_text_iter_get_offset (&iter);
2180 gtk_text_buffer_get_end_iter(buffer, &iter);
2182 if (replace && compose->sig_str) {
2184 GtkTextIter first_iter, start_iter, end_iter;
2186 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2188 if (compose->sig_str[0] == '\0')
2191 found = gtk_text_iter_forward_search(&first_iter,
2193 GTK_TEXT_SEARCH_TEXT_ONLY,
2194 &start_iter, &end_iter,
2198 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2203 g_free(compose->sig_str);
2204 compose->sig_str = compose_get_signature_str(compose);
2205 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2206 compose->sig_str = g_strdup("");
2208 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2210 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2211 cur_pos = gtk_text_buffer_get_char_count (buffer);
2213 gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
2214 gtk_text_buffer_place_cursor(buffer, &iter);
2216 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2217 G_CALLBACK(compose_changed_cb),
2220 compose->autowrap = prev_autowrap;
2221 if (compose->autowrap)
2222 compose_wrap_all(compose);
2225 static gchar *compose_get_signature_str(Compose *compose)
2227 gchar *sig_body = NULL;
2228 gchar *sig_str = NULL;
2229 gchar *utf8_sig_str = NULL;
2231 g_return_val_if_fail(compose->account != NULL, NULL);
2233 if (!compose->account->sig_path)
2236 if (compose->account->sig_type == SIG_FILE) {
2237 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2238 g_warning("can't open signature file: %s\n",
2239 compose->account->sig_path);
2244 if (compose->account->sig_type == SIG_COMMAND)
2245 sig_body = get_command_output(compose->account->sig_path);
2249 tmp = file_read_to_str(compose->account->sig_path);
2252 sig_body = normalize_newlines(tmp);
2256 if (compose->account->sig_sep) {
2257 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2261 sig_str = g_strconcat("\n\n", sig_body, NULL);
2264 if (!g_utf8_validate(sig_str,1, NULL)) {
2265 utf8_sig_str = conv_codeset_strdup
2266 (sig_str, conv_get_locale_charset_str(), CS_INTERNAL);
2269 utf8_sig_str = sig_str;
2272 return utf8_sig_str;
2275 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2278 GtkTextBuffer *buffer;
2281 const gchar *cur_encoding;
2282 gchar buf[BUFFSIZE];
2285 gboolean prev_autowrap;
2286 gboolean badtxt = FALSE;
2288 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2290 if ((fp = fopen(file, "rb")) == NULL) {
2291 FILE_OP_ERROR(file, "fopen");
2292 return COMPOSE_INSERT_READ_ERROR;
2295 prev_autowrap = compose->autowrap;
2296 compose->autowrap = FALSE;
2298 text = GTK_TEXT_VIEW(compose->text);
2299 buffer = gtk_text_view_get_buffer(text);
2300 mark = gtk_text_buffer_get_insert(buffer);
2301 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2303 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2304 G_CALLBACK(text_inserted),
2307 cur_encoding = conv_get_locale_charset_str();
2309 while (fgets(buf, sizeof(buf), fp) != NULL) {
2312 str = conv_codeset_strdup(buf, cur_encoding, CS_INTERNAL);
2315 /* strip <CR> if DOS/Windows file,
2316 replace <CR> with <LF> if Macintosh file. */
2319 if (len > 0 && str[len - 1] != '\n') {
2321 if (str[len] == '\r') str[len] = '\n';
2324 gtk_text_buffer_insert(buffer, &iter, str, -1);
2328 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2329 G_CALLBACK(text_inserted),
2331 compose->autowrap = prev_autowrap;
2332 if (compose->autowrap)
2333 compose_wrap_all(compose);
2338 return COMPOSE_INSERT_INVALID_CHARACTER;
2340 return COMPOSE_INSERT_SUCCESS;
2343 static void compose_attach_append(Compose *compose, const gchar *file,
2344 const gchar *filename,
2345 const gchar *content_type)
2353 GtkListStore *store;
2356 if (!is_file_exist(file)) {
2357 g_warning("File %s doesn't exist\n", filename);
2360 if ((size = get_file_size(file)) < 0) {
2361 g_warning("Can't get file size of %s\n", filename);
2365 alertpanel_notice(_("File %s is empty."), filename);
2368 if ((fp = fopen(file, "rb")) == NULL) {
2369 alertpanel_error(_("Can't read %s."), filename);
2374 #if 0 /* NEW COMPOSE GUI */
2375 if (!compose->use_attach) {
2376 GtkItemFactory *ifactory;
2378 ifactory = gtk_item_factory_from_widget(compose->menubar);
2379 menu_set_active(ifactory, "/View/Attachment", TRUE);
2382 ainfo = g_new0(AttachInfo, 1);
2383 auto_ainfo = g_auto_pointer_new_with_free
2384 (ainfo, (GFreeFunc) compose_attach_info_free);
2385 ainfo->file = g_strdup(file);
2388 ainfo->content_type = g_strdup(content_type);
2389 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2391 MsgFlags flags = {0, 0};
2393 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2394 ainfo->encoding = ENC_7BIT;
2396 ainfo->encoding = ENC_8BIT;
2398 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2399 if (msginfo && msginfo->subject)
2400 name = g_strdup(msginfo->subject);
2402 name = g_path_get_basename(filename ? filename : file);
2404 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2406 procmsg_msginfo_free(msginfo);
2408 if (!g_ascii_strncasecmp(content_type, "text", 4))
2409 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2411 ainfo->encoding = ENC_BASE64;
2412 name = g_path_get_basename(filename ? filename : file);
2413 ainfo->name = g_strdup(name);
2417 ainfo->content_type = procmime_get_mime_type(file);
2418 if (!ainfo->content_type) {
2419 ainfo->content_type =
2420 g_strdup("application/octet-stream");
2421 ainfo->encoding = ENC_BASE64;
2422 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2424 procmime_get_encoding_for_text_file(file);
2426 ainfo->encoding = ENC_BASE64;
2427 name = g_path_get_basename(filename ? filename : file);
2428 ainfo->name = g_strdup(name);
2432 if (!strcmp(ainfo->content_type, "unknown")) {
2433 g_free(ainfo->content_type);
2434 ainfo->content_type = g_strdup("application/octet-stream");
2438 size_text = to_human_readable(size);
2440 store = GTK_LIST_STORE(gtk_tree_view_get_model
2441 (GTK_TREE_VIEW(compose->attach_clist)));
2443 gtk_list_store_append(store, &iter);
2444 gtk_list_store_set(store, &iter,
2445 COL_MIMETYPE, ainfo->content_type,
2446 COL_SIZE, size_text,
2447 COL_NAME, ainfo->name,
2449 COL_AUTODATA, auto_ainfo,
2452 g_auto_pointer_free(auto_ainfo);
2455 static void compose_use_signing(Compose *compose, gboolean use_signing)
2457 GtkItemFactory *ifactory;
2458 GtkWidget *menuitem = NULL;
2460 compose->use_signing = use_signing;
2461 ifactory = gtk_item_factory_from_widget(compose->menubar);
2462 menuitem = gtk_item_factory_get_item
2463 (ifactory, "/Options/Sign");
2464 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2468 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2470 GtkItemFactory *ifactory;
2471 GtkWidget *menuitem = NULL;
2473 compose->use_encryption = use_encryption;
2474 ifactory = gtk_item_factory_from_widget(compose->menubar);
2475 menuitem = gtk_item_factory_get_item
2476 (ifactory, "/Options/Encrypt");
2478 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2482 #define NEXT_PART_NOT_CHILD(info) \
2484 node = info->node; \
2485 while (node->children) \
2486 node = g_node_last_child(node); \
2487 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2490 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2494 MimeInfo *firsttext = NULL;
2495 MimeInfo *encrypted = NULL;
2498 const gchar *partname = NULL;
2500 mimeinfo = procmime_scan_message(msginfo);
2501 if (!mimeinfo) return;
2503 if (mimeinfo->node->children == NULL) {
2504 procmime_mimeinfo_free_all(mimeinfo);
2508 /* find first content part */
2509 child = (MimeInfo *) mimeinfo->node->children->data;
2510 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2511 child = (MimeInfo *)child->node->children->data;
2513 if (child->type == MIMETYPE_TEXT) {
2515 debug_print("First text part found\n");
2516 } else if (compose->mode == COMPOSE_REEDIT &&
2517 child->type == MIMETYPE_APPLICATION &&
2518 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2520 val = alertpanel(_("Encrypted message"),
2521 _("Cannot re-edit an encrypted message. \n"
2522 "Discard encrypted part?"),
2523 _("Yes"), _("No"), NULL);
2524 if (val == G_ALERTDEFAULT)
2525 encrypted = (MimeInfo *)child->node->parent->data;
2528 child = (MimeInfo *) mimeinfo->node->children->data;
2529 while (child != NULL) {
2530 if (child == encrypted) {
2531 /* skip this part of tree */
2532 NEXT_PART_NOT_CHILD(child);
2536 if (child->type == MIMETYPE_MULTIPART) {
2537 /* get the actual content */
2538 child = procmime_mimeinfo_next(child);
2542 if (child == firsttext) {
2543 child = procmime_mimeinfo_next(child);
2547 outfile = procmime_get_tmp_file_name(child);
2548 if (procmime_get_part(outfile, child) < 0)
2549 g_warning("Can't get the part of multipart message.");
2551 gchar *content_type;
2553 content_type = procmime_get_content_type_str(child->type, child->subtype);
2554 partname = procmime_mimeinfo_get_parameter(child, "name");
2555 if (partname == NULL)
2557 compose_attach_append(compose, outfile,
2558 partname, content_type);
2559 g_free(content_type);
2562 NEXT_PART_NOT_CHILD(child);
2564 procmime_mimeinfo_free_all(mimeinfo);
2567 #undef NEXT_PART_NOT_CHILD
2572 WAIT_FOR_INDENT_CHAR,
2573 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2576 /* return indent length, we allow:
2577 indent characters followed by indent characters or spaces/tabs,
2578 alphabets and numbers immediately followed by indent characters,
2579 and the repeating sequences of the above
2580 If quote ends with multiple spaces, only the first one is included. */
2581 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2582 const GtkTextIter *start, gint *len)
2584 GtkTextIter iter = *start;
2588 IndentState state = WAIT_FOR_INDENT_CHAR;
2591 gint alnum_count = 0;
2592 gint space_count = 0;
2595 if (prefs_common.quote_chars == NULL) {
2599 while (!gtk_text_iter_ends_line(&iter)) {
2600 wc = gtk_text_iter_get_char(&iter);
2601 if (g_unichar_iswide(wc))
2603 clen = g_unichar_to_utf8(wc, ch);
2607 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2608 is_space = g_unichar_isspace(wc);
2610 if (state == WAIT_FOR_INDENT_CHAR) {
2611 if (!is_indent && !g_unichar_isalnum(wc))
2614 quote_len += alnum_count + space_count + 1;
2615 alnum_count = space_count = 0;
2616 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2619 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2620 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
2624 else if (is_indent) {
2625 quote_len += alnum_count + space_count + 1;
2626 alnum_count = space_count = 0;
2629 state = WAIT_FOR_INDENT_CHAR;
2633 gtk_text_iter_forward_char(&iter);
2636 if (quote_len > 0 && space_count > 0)
2642 if (quote_len > 0) {
2644 gtk_text_iter_forward_chars(&iter, quote_len);
2645 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
2651 /* return TRUE if the line is itemized */
2652 static gboolean compose_is_itemized(GtkTextBuffer *buffer,
2653 const GtkTextIter *start)
2655 GtkTextIter iter = *start;
2660 if (gtk_text_iter_ends_line(&iter))
2664 wc = gtk_text_iter_get_char(&iter);
2665 if (!g_unichar_isspace(wc))
2667 gtk_text_iter_forward_char(&iter);
2668 if (gtk_text_iter_ends_line(&iter))
2672 clen = g_unichar_to_utf8(wc, ch);
2676 if (!strchr("*-+", ch[0]))
2679 gtk_text_iter_forward_char(&iter);
2680 if (gtk_text_iter_ends_line(&iter))
2682 wc = gtk_text_iter_get_char(&iter);
2683 if (g_unichar_isspace(wc))
2689 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
2690 const GtkTextIter *start,
2691 GtkTextIter *break_pos,
2695 GtkTextIter iter = *start, line_end = *start;
2696 PangoLogAttr *attrs;
2703 gboolean can_break = FALSE;
2704 gboolean do_break = FALSE;
2705 gboolean was_white = FALSE;
2707 gtk_text_iter_forward_to_line_end(&line_end);
2708 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
2709 len = g_utf8_strlen(str, -1);
2710 /* g_print("breaking line: %d: %s (len = %d)\n",
2711 gtk_text_iter_get_line(&iter), str, len); */
2712 attrs = g_new(PangoLogAttr, len + 1);
2714 pango_default_break(str, -1, NULL, attrs, len + 1);
2718 /* skip quote and leading spaces */
2719 for (i = 0; *p != '\0' && i < len; i++) {
2722 wc = g_utf8_get_char(p);
2723 if (i >= quote_len && !g_unichar_isspace(wc))
2725 if (g_unichar_iswide(wc))
2727 else if (*p == '\t')
2731 p = g_utf8_next_char(p);
2734 for (; *p != '\0' && i < len; i++) {
2735 PangoLogAttr *attr = attrs + i;
2739 if (attr->is_line_break && can_break && was_white)
2742 was_white = attr->is_white;
2744 /* don't wrap URI */
2745 if ((uri_len = get_uri_len(p)) > 0) {
2747 if (pos > 0 && col > max_col) {
2757 wc = g_utf8_get_char(p);
2758 if (g_unichar_iswide(wc))
2760 else if (*p == '\t')
2764 if (pos > 0 && col > max_col) {
2769 p = g_utf8_next_char(p);
2773 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
2778 *break_pos = *start;
2779 gtk_text_iter_set_line_offset(break_pos, pos);
2784 static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter)
2786 GtkTextIter start = *iter;
2787 GtkTextIter end_iter;
2788 int start_pos = gtk_text_iter_get_offset(&start);
2790 if (!compose->account->sig_sep)
2793 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2794 start_pos+strlen(compose->account->sig_sep));
2796 /* check sig separator */
2797 if (!strcmp(gtk_text_iter_get_text(&start, &end_iter),
2798 compose->account->sig_sep)) {
2799 /* check end of line (\n) */
2800 gtk_text_buffer_get_iter_at_offset(textbuf, &start,
2801 start_pos+strlen(compose->account->sig_sep));
2802 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2803 start_pos+strlen(compose->account->sig_sep)+1);
2805 if (!strcmp(gtk_text_iter_get_text(&start, &end_iter),"\n"));
2814 static gboolean compose_join_next_line(Compose *compose,
2815 GtkTextBuffer *buffer,
2817 const gchar *quote_str)
2819 GtkTextIter iter_ = *iter, cur, prev, next, end;
2820 PangoLogAttr attrs[3];
2822 gchar *next_quote_str;
2825 gboolean keep_cursor = FALSE;
2827 if (!gtk_text_iter_forward_line(&iter_) ||
2828 gtk_text_iter_ends_line(&iter_))
2831 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
2833 if ((quote_str || next_quote_str) &&
2834 strcmp2(quote_str, next_quote_str) != 0) {
2835 g_free(next_quote_str);
2838 g_free(next_quote_str);
2841 if (quote_len > 0) {
2842 gtk_text_iter_forward_chars(&end, quote_len);
2843 if (gtk_text_iter_ends_line(&end))
2847 /* don't join itemized lines */
2848 if (compose_is_itemized(buffer, &end))
2851 /* don't join signature separator */
2852 if (compose_is_sig_separator(compose, buffer, &iter_))
2855 /* delete quote str */
2857 gtk_text_buffer_delete(buffer, &iter_, &end);
2859 /* delete linebreak and extra spaces */
2861 while (gtk_text_iter_backward_char(&cur)) {
2862 wc1 = gtk_text_iter_get_char(&cur);
2863 if (!g_unichar_isspace(wc1))
2868 while (!gtk_text_iter_ends_line(&cur)) {
2869 wc1 = gtk_text_iter_get_char(&cur);
2870 if (!g_unichar_isspace(wc1))
2872 gtk_text_iter_forward_char(&cur);
2875 if (!gtk_text_iter_equal(&prev, &next)) {
2878 mark = gtk_text_buffer_get_insert(buffer);
2879 gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
2880 if (gtk_text_iter_equal(&prev, &cur))
2882 gtk_text_buffer_delete(buffer, &prev, &next);
2886 /* insert space if required */
2887 gtk_text_iter_backward_char(&prev);
2888 wc1 = gtk_text_iter_get_char(&prev);
2889 wc2 = gtk_text_iter_get_char(&next);
2890 gtk_text_iter_forward_char(&next);
2891 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
2892 pango_default_break(str, -1, NULL, attrs, 3);
2893 if (!attrs[1].is_line_break ||
2894 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
2895 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
2897 gtk_text_iter_backward_char(&iter_);
2898 gtk_text_buffer_place_cursor(buffer, &iter_);
2907 static void compose_wrap_paragraph(Compose *compose, GtkTextIter *par_iter)
2909 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2910 GtkTextBuffer *buffer;
2911 GtkTextIter iter, break_pos;
2912 gchar *quote_str = NULL;
2914 gboolean wrap_quote = prefs_common.linewrap_quote;
2915 gboolean prev_autowrap = compose->autowrap;
2917 compose->autowrap = FALSE;
2919 buffer = gtk_text_view_get_buffer(text);
2921 undo_block(compose->undostruct);
2927 mark = gtk_text_buffer_get_insert(buffer);
2928 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2931 /* move to paragraph start */
2932 gtk_text_iter_set_line_offset(&iter, 0);
2933 if (gtk_text_iter_ends_line(&iter)) {
2934 while (gtk_text_iter_ends_line(&iter) &&
2935 gtk_text_iter_forward_line(&iter))
2938 while (gtk_text_iter_backward_line(&iter)) {
2939 if (gtk_text_iter_ends_line(&iter)) {
2940 gtk_text_iter_forward_line(&iter);
2946 /* go until paragraph end (empty line) */
2947 while (!gtk_text_iter_ends_line(&iter)) {
2948 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
2951 gtk_text_iter_forward_line(&iter);
2955 debug_print("compose_wrap_paragraph(): quote_str = '%s'\n", quote_str);
2958 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
2959 prefs_common.linewrap_len,
2961 GtkTextIter prev, next, cur;
2963 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
2965 /* remove trailing spaces */
2967 gtk_text_iter_backward_char(&cur);
2969 while (!gtk_text_iter_starts_line(&cur)) {
2972 gtk_text_iter_backward_char(&cur);
2973 wc = gtk_text_iter_get_char(&cur);
2974 if (!g_unichar_isspace(wc))
2978 if (!gtk_text_iter_equal(&prev, &next)) {
2979 gtk_text_buffer_delete(buffer, &prev, &next);
2981 gtk_text_iter_forward_char(&break_pos);
2985 gtk_text_buffer_insert(buffer, &break_pos,
2989 compose_join_next_line(compose, buffer, &iter, quote_str);
2991 /* move iter to current line start */
2992 gtk_text_iter_set_line_offset(&iter, 0);
2994 /* move iter to next line start */
2996 gtk_text_iter_forward_line(&iter);
3005 undo_unblock(compose->undostruct);
3006 compose->autowrap = prev_autowrap;
3009 static void compose_wrap_all(Compose *compose)
3011 compose_wrap_all_full(compose, FALSE);
3014 static void compose_wrap_all_full(Compose *compose, gboolean autowrap)
3016 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
3017 GtkTextBuffer *buffer;
3020 buffer = gtk_text_view_get_buffer(text);
3022 undo_block(compose->undostruct);
3024 gtk_text_buffer_get_start_iter(buffer, &iter);
3025 while (!gtk_text_iter_is_end(&iter))
3026 compose_wrap_paragraph(compose, &iter);
3028 undo_unblock(compose->undostruct);
3031 static void compose_set_title(Compose *compose)
3036 edited = compose->modified ? _(" [Edited]") : "";
3037 if (compose->account && compose->account->address)
3038 str = g_strdup_printf(_("%s - Compose message%s"),
3039 compose->account->address, edited);
3041 str = g_strdup_printf(_("Compose message%s"), edited);
3042 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3047 * compose_current_mail_account:
3049 * Find a current mail account (the currently selected account, or the
3050 * default account, if a news account is currently selected). If a
3051 * mail account cannot be found, display an error message.
3053 * Return value: Mail account, or NULL if not found.
3055 static PrefsAccount *
3056 compose_current_mail_account(void)
3060 if (cur_account && cur_account->protocol != A_NNTP)
3063 ac = account_get_default();
3064 if (!ac || ac->protocol == A_NNTP) {
3065 alertpanel_error(_("Account for sending mail is not specified.\n"
3066 "Please select a mail account before sending."));
3073 static void compose_select_account(Compose *compose, PrefsAccount *account,
3076 GtkItemFactory *ifactory;
3078 g_return_if_fail(account != NULL);
3080 compose->account = account;
3082 compose_set_title(compose);
3084 ifactory = gtk_item_factory_from_widget(compose->menubar);
3086 if (account->protocol == A_NNTP) {
3087 gtk_widget_show(compose->newsgroups_hbox);
3088 gtk_widget_show(compose->newsgroups_entry);
3089 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
3090 compose->use_newsgroups = TRUE;
3092 menu_set_active(ifactory, "/View/To", FALSE);
3093 menu_set_sensitive(ifactory, "/View/To", TRUE);
3094 menu_set_active(ifactory, "/View/Cc", FALSE);
3095 menu_set_sensitive(ifactory, "/View/Cc", TRUE);
3096 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
3098 gtk_widget_hide(compose->newsgroups_hbox);
3099 gtk_widget_hide(compose->newsgroups_entry);
3100 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
3101 gtk_widget_queue_resize(compose->table_vbox);
3102 compose->use_newsgroups = FALSE;
3104 menu_set_active(ifactory, "/View/To", TRUE);
3105 menu_set_sensitive(ifactory, "/View/To", FALSE);
3106 menu_set_active(ifactory, "/View/Cc", TRUE);
3107 menu_set_sensitive(ifactory, "/View/Cc", FALSE);
3108 menu_set_active(ifactory, "/View/Followup to", FALSE);
3109 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
3112 if (account->set_autocc) {
3113 compose_entry_show(compose, COMPOSE_ENTRY_CC);
3114 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
3115 compose_entry_set(compose, account->auto_cc,
3118 if (account->set_autobcc) {
3119 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
3120 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
3121 compose_entry_set(compose, account->auto_bcc,
3124 if (account->set_autoreplyto) {
3125 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
3126 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
3127 compose_entry_set(compose, account->auto_replyto,
3128 COMPOSE_ENTRY_REPLY_TO);
3133 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3134 menu_set_active(ifactory, "/Options/Sign", TRUE);
3136 menu_set_active(ifactory, "/Options/Sign", FALSE);
3137 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3138 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3140 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3142 activate_privacy_system(compose, account);
3144 if (!init && compose->mode != COMPOSE_REDIRECT)
3145 compose_insert_sig(compose, TRUE);
3148 gboolean compose_check_for_valid_recipient(Compose *compose) {
3149 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3150 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3151 gboolean recipient_found = FALSE;
3155 /* free to and newsgroup list */
3156 slist_free_strings(compose->to_list);
3157 g_slist_free(compose->to_list);
3158 compose->to_list = NULL;
3160 slist_free_strings(compose->newsgroup_list);
3161 g_slist_free(compose->newsgroup_list);
3162 compose->newsgroup_list = NULL;
3164 /* search header entries for to and newsgroup entries */
3165 for (list = compose->header_list; list; list = list->next) {
3168 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3169 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3171 if (entry[0] != '\0') {
3172 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3173 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3174 compose->to_list = address_list_append(compose->to_list, entry);
3175 recipient_found = TRUE;
3178 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3179 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3180 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3181 recipient_found = TRUE;
3188 return recipient_found;
3191 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3195 if (compose_check_for_valid_recipient(compose) == FALSE) {
3196 alertpanel_error(_("Recipient is not specified."));
3200 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3201 if (*str == '\0' && check_subject == TRUE) {
3204 aval = alertpanel(_("Send"),
3205 _("Subject is empty. Send it anyway?"),
3206 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
3207 if (aval != G_ALERTDEFAULT)
3214 gint compose_send(Compose *compose)
3221 compose_allow_user_actions (compose, FALSE);
3222 compose->sending = TRUE;
3224 if (compose_check_entries(compose, TRUE) == FALSE)
3227 val = compose_queue(compose, &msgnum, &folder);
3230 alertpanel_error(_("Could not queue message for sending."));
3235 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3236 compose->sending = FALSE;
3237 compose_close(compose);
3238 /* No more compose access in the normal codepath
3239 * after this point! */
3244 alertpanel_error(_("The message was queued but could not be "
3245 "sent.\nUse \"Send queued messages\" from "
3246 "the main window to retry."));
3247 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3248 compose->sending = FALSE;
3249 compose_allow_user_actions (compose, TRUE);
3254 msgpath = folder_item_fetch_msg(folder, msgnum);
3255 val = procmsg_send_message_queue(msgpath);