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.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
31 #include <gtk/gtkitemfactory.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkclist.h>
36 #include <gtk/gtkctree.h>
37 #include <gtk/gtkvpaned.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkeditable.h>
40 #include <gtk/gtkwindow.h>
41 #include <gtk/gtksignal.h>
42 #include <gtk/gtkvbox.h>
43 #include <gtk/gtkcontainer.h>
44 #include <gtk/gtkhandlebox.h>
45 #include <gtk/gtktoolbar.h>
46 #include <gtk/gtktable.h>
47 #include <gtk/gtkhbox.h>
48 #include <gtk/gtklabel.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtkthemes.h>
51 #include <gtk/gtkdnd.h>
56 #include <sys/types.h>
60 /* #include <sys/utsname.h> */
67 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
74 #include "mainwindow.h"
77 #include "addressbook.h"
78 #include "folderview.h"
81 #include "stock_pixmap.h"
82 #include "send_message.h"
85 #include "customheader.h"
86 #include "prefs_common.h"
87 #include "prefs_account.h"
91 #include "procheader.h"
93 #include "statusbar.h"
96 #include "quoted-printable.h"
101 #include "alertpanel.h"
102 #include "manage_window.h"
103 #include "gtkshruler.h"
105 #include "addr_compl.h"
106 #include "quote_fmt.h"
107 #include "template.h"
109 #include "foldersel.h"
119 #define N_ATTACH_COLS 3
123 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
124 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
125 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
126 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
127 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
128 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
129 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
130 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
131 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
132 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
133 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
134 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
135 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
136 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
137 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
138 } ComposeCallGtkSTextAction;
142 PRIORITY_HIGHEST = 1,
151 COMPOSE_INSERT_SUCCESS,
152 COMPOSE_INSERT_READ_ERROR,
153 COMPOSE_INSERT_INVALID_CHARACTER,
154 COMPOSE_INSERT_NO_FILE
155 } ComposeInsertResult;
159 COMPOSE_QUIT_EDITING,
160 COMPOSE_KEEP_EDITING,
162 } ComposeDraftAction;
166 COMPOSE_WRITE_FOR_SEND,
167 COMPOSE_WRITE_FOR_STORE
171 #define B64_LINE_SIZE 57
172 #define B64_BUFFSIZE 77
174 #define MAX_REFERENCES_LEN 999
176 static GdkColor quote_color = {0, 0, 0, 0xbfff};
178 static GList *compose_list = NULL;
180 Compose *compose_generic_new (PrefsAccount *account,
183 GPtrArray *attach_files,
184 GList *listAddress );
186 static Compose *compose_create (PrefsAccount *account,
189 static GtkWidget *compose_account_option_menu_create
191 static void compose_set_template_menu (Compose *compose);
192 static void compose_template_apply (Compose *compose,
195 static void compose_destroy (Compose *compose);
197 static void compose_entries_set (Compose *compose,
198 const gchar *mailto);
199 static gint compose_parse_header (Compose *compose,
201 static gchar *compose_parse_references (const gchar *ref,
204 static gchar *compose_quote_fmt (Compose *compose,
210 static void compose_reply_set_entry (Compose *compose,
216 followup_and_reply_to);
217 static void compose_reedit_set_entry (Compose *compose,
219 static void compose_insert_sig (Compose *compose,
221 static gchar *compose_get_signature_str (Compose *compose);
222 static ComposeInsertResult compose_insert_file (Compose *compose,
224 static void compose_attach_append (Compose *compose,
227 const gchar *content_type);
228 static void compose_attach_parts (Compose *compose,
230 static void compose_wrap_line (Compose *compose);
231 static void compose_wrap_line_all (Compose *compose);
232 static void compose_wrap_line_all_full (Compose *compose,
234 static void compose_set_title (Compose *compose);
235 static void compose_select_account (Compose *compose,
236 PrefsAccount *account,
239 static PrefsAccount *compose_current_mail_account(void);
240 /* static gint compose_send (Compose *compose); */
241 static gboolean compose_check_for_valid_recipient
243 static gboolean compose_check_entries (Compose *compose,
244 gboolean check_subject);
245 static gint compose_write_to_file (Compose *compose,
248 static gint compose_write_body_to_file (Compose *compose,
250 static gint compose_remove_reedit_target (Compose *compose);
251 void compose_remove_draft (Compose *compose);
252 static gint compose_queue (Compose *compose,
255 static gint compose_queue_sub (Compose *compose,
258 gboolean check_subject);
259 static void compose_add_attachments (Compose *compose,
261 static gchar *compose_get_header (Compose *compose);
263 static void compose_convert_header (gchar *dest,
267 gboolean addr_field);
269 static void compose_attach_info_free (AttachInfo *ainfo);
270 static void compose_attach_remove_selected (Compose *compose);
272 static void compose_attach_property (Compose *compose);
273 static void compose_attach_property_create (gboolean *cancelled);
274 static void attach_property_ok (GtkWidget *widget,
275 gboolean *cancelled);
276 static void attach_property_cancel (GtkWidget *widget,
277 gboolean *cancelled);
278 static gint attach_property_delete_event (GtkWidget *widget,
280 gboolean *cancelled);
281 static void attach_property_key_pressed (GtkWidget *widget,
283 gboolean *cancelled);
285 static void compose_exec_ext_editor (Compose *compose);
286 static gint compose_exec_ext_editor_real (const gchar *file);
287 static gboolean compose_ext_editor_kill (Compose *compose);
288 static void compose_input_cb (gpointer data,
290 GdkInputCondition condition);
291 static void compose_set_ext_editor_sensitive (Compose *compose,
294 static void compose_undo_state_changed (UndoMain *undostruct,
299 static gint calc_cursor_xpos (GtkSText *text,
303 static void compose_create_header_entry (Compose *compose);
304 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
305 static void compose_update_priority_menu_item(Compose * compose);
307 static void compose_add_field_list ( Compose *compose,
308 GList *listAddress );
310 /* callback functions */
312 static gboolean compose_edit_size_alloc (GtkEditable *widget,
313 GtkAllocation *allocation,
314 GtkSHRuler *shruler);
315 static void account_activated (GtkMenuItem *menuitem,
317 static void attach_selected (GtkCList *clist,
322 static void attach_button_pressed (GtkWidget *widget,
323 GdkEventButton *event,
325 static void attach_key_pressed (GtkWidget *widget,
329 static void compose_send_cb (gpointer data,
332 static void compose_send_later_cb (gpointer data,
336 static void compose_draft_cb (gpointer data,
340 static void compose_attach_cb (gpointer data,
343 static void compose_insert_file_cb (gpointer data,
346 static void compose_insert_sig_cb (gpointer data,
350 static void compose_close_cb (gpointer data,
354 static void compose_address_cb (gpointer data,
357 static void compose_template_activate_cb(GtkWidget *widget,
360 static void compose_ext_editor_cb (gpointer data,
364 static gint compose_delete_cb (GtkWidget *widget,
367 static void compose_destroy_cb (GtkWidget *widget,
370 static void compose_undo_cb (Compose *compose);
371 static void compose_redo_cb (Compose *compose);
372 static void compose_cut_cb (Compose *compose);
373 static void compose_copy_cb (Compose *compose);
374 static void compose_paste_cb (Compose *compose);
375 static void compose_paste_as_quote_cb (Compose *compose);
376 static void compose_allsel_cb (Compose *compose);
378 static void compose_gtk_stext_action_cb (Compose *compose,
379 ComposeCallGtkSTextAction action);
381 static void compose_grab_focus_cb (GtkWidget *widget,
384 static void compose_changed_cb (GtkEditable *editable,
386 static void compose_button_press_cb (GtkWidget *widget,
387 GdkEventButton *event,
390 static void compose_key_press_cb (GtkWidget *widget,
395 static void compose_toggle_autowrap_cb (gpointer data,
400 static void compose_toggle_to_cb (gpointer data,
403 static void compose_toggle_cc_cb (gpointer data,
406 static void compose_toggle_bcc_cb (gpointer data,
409 static void compose_toggle_replyto_cb (gpointer data,
412 static void compose_toggle_followupto_cb(gpointer data,
415 static void compose_toggle_attach_cb (gpointer data,
419 static void compose_toggle_ruler_cb (gpointer data,
422 static void compose_toggle_sign_cb (gpointer data,
425 static void compose_toggle_encrypt_cb (gpointer data,
428 static void compose_set_privacy_system_cb(GtkWidget *widget,
430 static void compose_update_privacy_system_menu_item(Compose * compose);
431 static void activate_privacy_system (Compose *compose,
432 PrefsAccount *account);
433 static void compose_use_signing(Compose *compose, gboolean use_signing);
434 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
435 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
437 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
439 static void compose_set_priority_cb (gpointer data,
443 static void compose_attach_drag_received_cb (GtkWidget *widget,
444 GdkDragContext *drag_context,
447 GtkSelectionData *data,
451 static void compose_insert_drag_received_cb (GtkWidget *widget,
452 GdkDragContext *drag_context,
455 GtkSelectionData *data,
461 static void to_activated (GtkWidget *widget,
463 static void newsgroups_activated (GtkWidget *widget,
465 static void cc_activated (GtkWidget *widget,
467 static void bcc_activated (GtkWidget *widget,
469 static void replyto_activated (GtkWidget *widget,
471 static void followupto_activated (GtkWidget *widget,
473 static void subject_activated (GtkWidget *widget,
477 static void text_activated (GtkWidget *widget,
479 static void text_inserted (GtkWidget *widget,
484 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
485 gboolean to_all, gboolean to_ml,
487 gboolean followup_and_reply_to,
490 void compose_headerentry_changed_cb (GtkWidget *entry,
491 ComposeHeaderEntry *headerentry);
492 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
494 ComposeHeaderEntry *headerentry);
495 static gboolean compose_headerentry_button_pressed (GtkWidget *entry,
496 GdkEventButton *event,
499 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
501 static void compose_allow_user_actions (Compose *compose, gboolean allow);
504 static void compose_check_all (Compose *compose);
505 static void compose_highlight_all (Compose *compose);
506 static void compose_check_backwards (Compose *compose);
507 static void compose_check_forwards_go (Compose *compose);
510 static gboolean compose_send_control_enter (Compose *compose);
511 static gint compose_defer_auto_save_draft (Compose *compose);
512 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
514 static void compose_close (Compose *compose);
516 static GtkItemFactoryEntry compose_popup_entries[] =
518 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
519 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
520 {N_("/---"), NULL, NULL, 0, "<Separator>"},
521 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
524 static GtkItemFactoryEntry compose_entries[] =
526 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
527 {N_("/_Message/_Send"), "<control>Return",
528 compose_send_cb, 0, NULL},
529 {N_("/_Message/Send _later"), "<shift><control>S",
530 compose_send_later_cb, 0, NULL},
531 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
532 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
533 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
534 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
535 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
536 {N_("/_Message/_Save"),
537 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
538 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
539 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
541 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
542 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
543 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
544 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
545 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
546 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
547 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
548 {N_("/_Edit/Paste as _quotation"),
549 NULL, compose_paste_as_quote_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_gtk_stext_action_cb,
555 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
557 {N_("/_Edit/A_dvanced/Move a character forward"),
559 compose_gtk_stext_action_cb,
560 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
562 {N_("/_Edit/A_dvanced/Move a word backward"),
564 compose_gtk_stext_action_cb,
565 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
567 {N_("/_Edit/A_dvanced/Move a word forward"),
569 compose_gtk_stext_action_cb,
570 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
572 {N_("/_Edit/A_dvanced/Move to beginning of line"),
573 NULL, /* "<control>A" */
574 compose_gtk_stext_action_cb,
575 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
577 {N_("/_Edit/A_dvanced/Move to end of line"),
579 compose_gtk_stext_action_cb,
580 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
582 {N_("/_Edit/A_dvanced/Move to previous line"),
584 compose_gtk_stext_action_cb,
585 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
587 {N_("/_Edit/A_dvanced/Move to next line"),
589 compose_gtk_stext_action_cb,
590 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
592 {N_("/_Edit/A_dvanced/Delete a character backward"),
594 compose_gtk_stext_action_cb,
595 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
597 {N_("/_Edit/A_dvanced/Delete a character forward"),
599 compose_gtk_stext_action_cb,
600 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
602 {N_("/_Edit/A_dvanced/Delete a word backward"),
603 NULL, /* "<control>W" */
604 compose_gtk_stext_action_cb,
605 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
607 {N_("/_Edit/A_dvanced/Delete a word forward"),
608 NULL, /* "<alt>D", */
609 compose_gtk_stext_action_cb,
610 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
612 {N_("/_Edit/A_dvanced/Delete line"),
614 compose_gtk_stext_action_cb,
615 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
617 {N_("/_Edit/A_dvanced/Delete entire line"),
619 compose_gtk_stext_action_cb,
620 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
622 {N_("/_Edit/A_dvanced/Delete to end of line"),
624 compose_gtk_stext_action_cb,
625 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
627 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
628 {N_("/_Edit/_Wrap current paragraph"),
629 "<control>L", compose_wrap_line, 0, NULL},
630 {N_("/_Edit/Wrap all long _lines"),
631 "<control><alt>L", compose_wrap_line_all, 0, NULL},
632 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
633 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
634 {N_("/_Edit/Edit with e_xternal editor"),
635 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
637 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
638 {N_("/_Spelling/_Check all or check selection"),
639 NULL, compose_check_all, 0, NULL},
640 {N_("/_Spelling/_Highlight all misspelled words"),
641 NULL, compose_highlight_all, 0, NULL},
642 {N_("/_Spelling/Check _backwards misspelled word"),
643 NULL, compose_check_backwards , 0, NULL},
644 {N_("/_Spelling/_Forward to next misspelled word"),
645 NULL, compose_check_forwards_go, 0, NULL},
646 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
647 {N_("/_Spelling/_Spelling Configuration"),
648 NULL, NULL, 0, "<Branch>"},
650 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
651 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
652 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
653 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
654 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
655 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
656 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
657 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
658 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
659 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
660 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
661 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
662 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
663 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
664 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
665 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
666 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
667 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
668 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
669 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
670 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
671 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
674 static GtkTargetEntry compose_mime_types[] =
676 {"text/uri-list", 0, 0}
679 static gboolean compose_put_existing_to_front(MsgInfo *info)
681 GList *compose_list = compose_get_compose_list();
685 for (elem = compose_list; elem != NULL && elem->data != NULL;
687 Compose *c = (Compose*)elem->data;
689 if (!c->targetinfo || !c->targetinfo->msgid ||
693 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
694 gtkut_window_popup(c->window);
702 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
703 GPtrArray *attach_files)
705 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
708 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
710 return compose_generic_new(account, NULL, item, NULL, NULL);
713 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
715 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
718 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
719 GPtrArray *attach_files, GList *listAddress )
723 GtkItemFactory *ifactory;
725 if (item && item->prefs && item->prefs->enable_default_account)
726 account = account_find_from_id(item->prefs->default_account);
728 if (!account) account = cur_account;
729 g_return_val_if_fail(account != NULL, NULL);
731 compose = compose_create(account, COMPOSE_NEW);
732 ifactory = gtk_item_factory_from_widget(compose->menubar);
734 compose->replyinfo = NULL;
735 compose->fwdinfo = NULL;
737 text = GTK_STEXT(compose->text);
738 gtk_stext_freeze(text);
741 if (item && item->prefs && item->prefs->enable_default_dictionary &&
743 gtkaspell_change_dict(compose->gtkaspell,
744 item->prefs->default_dictionary);
747 if (account->auto_sig)
748 compose_insert_sig(compose, FALSE);
749 gtk_editable_set_position(GTK_EDITABLE(text), 0);
750 gtk_stext_set_point(text, 0);
752 gtk_stext_thaw(text);
754 if (account->protocol != A_NNTP) {
755 if (mailto && *mailto != '\0') {
756 compose_entries_set(compose, mailto);
758 } else if (item && item->prefs->enable_default_to) {
759 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
760 compose_entry_mark_default_to(compose, item->prefs->default_to);
762 if (item && item->ret_rcpt) {
763 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
767 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
770 * CLAWS: just don't allow return receipt request, even if the user
771 * may want to send an email. simple but foolproof.
773 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
775 compose_add_field_list( compose, listAddress );
781 for (i = 0; i < attach_files->len; i++) {
782 file = g_ptr_array_index(attach_files, i);
783 compose_attach_append(compose, file, file, NULL);
787 compose_show_first_last_header(compose, TRUE);
789 /* Set save folder */
790 if (item && item->prefs && item->prefs->save_copy_to_folder) {
791 gchar *folderidentifier;
793 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
794 folderidentifier = folder_item_get_identifier(item);
795 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
796 g_free(folderidentifier);
799 gtk_widget_grab_focus(compose->header_last->entry);
801 if (prefs_common.auto_exteditor)
802 compose_exec_ext_editor(compose);
808 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
809 const gchar *followupto, gchar * to)
813 if (!account) account = cur_account;
814 g_return_val_if_fail(account != NULL, NULL);
815 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
817 compose = compose_create(account, COMPOSE_NEW);
819 if (prefs_common.auto_sig)
820 compose_insert_sig(compose);
821 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
822 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
824 compose_entry_append(compose, to, COMPOSE_TO);
825 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
826 gtk_widget_grab_focus(compose->subject_entry);
832 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
837 g_return_if_fail(msginfo_list != NULL);
839 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
840 g_return_if_fail(msginfo != NULL);
842 list_len = g_slist_length(msginfo_list);
846 compose_reply(msginfo, prefs_common.reply_with_quote,
847 FALSE, prefs_common.default_reply_list, FALSE, body);
849 case COMPOSE_REPLY_WITH_QUOTE:
850 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
852 case COMPOSE_REPLY_WITHOUT_QUOTE:
853 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
855 case COMPOSE_REPLY_TO_SENDER:
856 compose_reply(msginfo, prefs_common.reply_with_quote,
857 FALSE, FALSE, TRUE, body);
859 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
860 compose_followup_and_reply_to(msginfo,
861 prefs_common.reply_with_quote,
864 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
865 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
867 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
868 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
870 case COMPOSE_REPLY_TO_ALL:
871 compose_reply(msginfo, prefs_common.reply_with_quote,
872 TRUE, FALSE, FALSE, body);
874 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
875 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
877 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
878 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
880 case COMPOSE_REPLY_TO_LIST:
881 compose_reply(msginfo, prefs_common.reply_with_quote,
882 FALSE, TRUE, FALSE, body);
884 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
885 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
887 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
888 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
890 case COMPOSE_FORWARD:
891 if (prefs_common.forward_as_attachment) {
892 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
895 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
899 case COMPOSE_FORWARD_INLINE:
900 /* check if we reply to more than one Message */
902 compose_forward(NULL, msginfo, FALSE, body, FALSE);
905 /* more messages FALL THROUGH */
906 case COMPOSE_FORWARD_AS_ATTACH:
907 compose_forward_multiple(NULL, msginfo_list);
909 case COMPOSE_REDIRECT:
910 compose_redirect(NULL, msginfo);
913 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
917 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
918 gboolean to_ml, gboolean to_sender,
921 compose_generic_reply(msginfo, quote, to_all, to_ml,
922 to_sender, FALSE, body);
925 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
930 compose_generic_reply(msginfo, quote, to_all, FALSE,
931 to_sender, TRUE, body);
934 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
935 gboolean to_all, gboolean to_ml,
937 gboolean followup_and_reply_to,
940 GtkItemFactory *ifactory;
942 PrefsAccount *account = NULL;
943 PrefsAccount *reply_account;
946 g_return_if_fail(msginfo != NULL);
947 g_return_if_fail(msginfo->folder != NULL);
949 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
951 g_return_if_fail(account != NULL);
953 if (to_sender && account->protocol == A_NNTP &&
954 !followup_and_reply_to) {
956 account_find_from_address(account->address);
958 reply_account = compose_current_mail_account();
962 reply_account = account;
964 compose = compose_create(account, COMPOSE_REPLY);
965 ifactory = gtk_item_factory_from_widget(compose->menubar);
967 menu_set_active(ifactory, "/Options/Remove references", FALSE);
968 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
970 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
971 if (!compose->replyinfo)
972 compose->replyinfo = procmsg_msginfo_copy(msginfo);
974 if (msginfo->folder && msginfo->folder->ret_rcpt)
975 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
977 /* Set save folder */
978 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
979 gchar *folderidentifier;
981 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
982 folderidentifier = folder_item_get_identifier(msginfo->folder);
983 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
984 g_free(folderidentifier);
987 if (compose_parse_header(compose, msginfo) < 0) return;
988 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
989 to_sender, followup_and_reply_to);
990 compose_show_first_last_header(compose, TRUE);
992 text = GTK_STEXT(compose->text);
993 gtk_stext_freeze(text);
996 if (msginfo->folder && msginfo->folder->prefs &&
997 msginfo->folder->prefs &&
998 msginfo->folder->prefs->enable_default_dictionary &&
1000 gtkaspell_change_dict(compose->gtkaspell,
1001 msginfo->folder->prefs->default_dictionary);
1007 if (prefs_common.quotemark && *prefs_common.quotemark)
1008 qmark = prefs_common.quotemark;
1012 compose_quote_fmt(compose, compose->replyinfo,
1013 prefs_common.quotefmt,
1017 if (account->auto_sig)
1018 compose_insert_sig(compose, FALSE);
1020 /* Must thaw here, otherwise the GtkSTextEdit will become confused
1021 * when positioning cursor */
1022 gtk_stext_thaw(text);
1025 gtk_editable_set_position
1026 (GTK_EDITABLE(text), quote_fmt_get_cursor_pos());
1027 gtk_stext_set_point(text, quote_fmt_get_cursor_pos());
1030 if (quote && prefs_common.linewrap_quote) {
1031 gtk_stext_freeze(text);
1032 compose_wrap_line_all(compose);
1033 gtk_stext_thaw(text);
1036 gtk_widget_grab_focus(compose->text);
1038 if (prefs_common.auto_exteditor)
1039 compose_exec_ext_editor(compose);
1042 #define INSERT_FW_HEADER(var, hdr) \
1043 if (msginfo->var && *msginfo->var) { \
1044 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1045 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1046 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1049 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1050 gboolean as_attach, const gchar *body,
1051 gboolean no_extedit)
1056 g_return_val_if_fail(msginfo != NULL, NULL);
1057 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1060 !(account = compose_guess_forward_account_from_msginfo
1062 account = cur_account;
1064 compose = compose_create(account, COMPOSE_FORWARD);
1066 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1067 if (!compose->fwdinfo)
1068 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1070 if (msginfo->subject && *msginfo->subject) {
1071 gchar *buf, *buf2, *p;
1073 buf = p = g_strdup(msginfo->subject);
1074 p += subject_get_prefix_length(p);
1075 memmove(buf, p, strlen(p) + 1);
1077 buf2 = g_strdup_printf("Fw: %s", buf);
1078 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1084 text = GTK_STEXT(compose->text);
1085 gtk_stext_freeze(text);
1090 msgfile = procmsg_get_message_file_path(msginfo);
1091 if (!is_file_exist(msgfile))
1092 g_warning("%s: file not exist\n", msgfile);
1094 compose_attach_append(compose, msgfile, msgfile,
1100 MsgInfo *full_msginfo;
1102 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1104 full_msginfo = procmsg_msginfo_copy(msginfo);
1106 if (prefs_common.fw_quotemark &&
1107 *prefs_common.fw_quotemark)
1108 qmark = prefs_common.fw_quotemark;
1112 compose_quote_fmt(compose, full_msginfo,
1113 prefs_common.fw_quotefmt,
1115 compose_attach_parts(compose, msginfo);
1117 procmsg_msginfo_free(full_msginfo);
1120 if (account->auto_sig)
1121 compose_insert_sig(compose, FALSE);
1123 if (prefs_common.linewrap_quote)
1124 compose_wrap_line_all(compose);
1126 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1127 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1129 gtk_stext_thaw(text);
1130 #if 0 /* NEW COMPOSE GUI */
1131 if (account->protocol != A_NNTP)
1132 gtk_widget_grab_focus(compose->to_entry);
1134 gtk_widget_grab_focus(compose->newsgroups_entry);
1136 gtk_widget_grab_focus(compose->header_last->entry);
1138 if (!no_extedit && prefs_common.auto_exteditor)
1139 compose_exec_ext_editor(compose);
1142 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1143 gchar *folderidentifier;
1145 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1146 folderidentifier = folder_item_get_identifier(msginfo->folder);
1147 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1148 g_free(folderidentifier);
1154 #undef INSERT_FW_HEADER
1156 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1163 g_return_val_if_fail(msginfo_list != NULL, NULL);
1165 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1166 if (((MsgInfo *)msginfo->data)->folder == NULL)
1169 /* guess account from first selected message */
1171 !(account = compose_guess_forward_account_from_msginfo
1172 (msginfo_list->data)))
1173 account = cur_account;
1175 g_return_val_if_fail(account != NULL, NULL);
1177 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1178 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1179 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1182 compose = compose_create(account, COMPOSE_FORWARD);
1184 text = GTK_STEXT(compose->text);
1185 gtk_stext_freeze(text);
1187 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1188 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1189 if (!is_file_exist(msgfile))
1190 g_warning("%s: file not exist\n", msgfile);
1192 compose_attach_append(compose, msgfile, msgfile,
1197 if (account->auto_sig)
1198 compose_insert_sig(compose, FALSE);
1200 if (prefs_common.linewrap_quote)
1201 compose_wrap_line_all(compose);
1203 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1204 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1206 gtk_stext_thaw(text);
1207 gtk_widget_grab_focus(compose->header_last->entry);
1209 #if 0 /* NEW COMPOSE GUI */
1210 if (account->protocol != A_NNTP)
1211 gtk_widget_grab_focus(compose->to_entry);
1213 gtk_widget_grab_focus(compose->newsgroups_entry);
1219 void compose_reedit(MsgInfo *msginfo)
1222 PrefsAccount *account = NULL;
1225 gchar buf[BUFFSIZE];
1226 gboolean use_signing = FALSE;
1227 gboolean use_encryption = FALSE;
1228 gchar *privacy_system = NULL;
1230 g_return_if_fail(msginfo != NULL);
1231 g_return_if_fail(msginfo->folder != NULL);
1233 if (compose_put_existing_to_front(msginfo))
1236 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1237 gchar queueheader_buf[BUFFSIZE];
1240 /* Select Account from queue headers */
1241 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1242 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1243 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1244 account = account_find_from_id(id);
1246 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1247 sizeof(queueheader_buf), "NAID:")) {
1248 id = atoi(&queueheader_buf[strlen("NAID:")]);
1249 account = account_find_from_id(id);
1251 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1252 sizeof(queueheader_buf), "MAID:")) {
1253 id = atoi(&queueheader_buf[strlen("MAID:")]);
1254 account = account_find_from_id(id);
1256 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1257 sizeof(queueheader_buf), "S:")) {
1258 account = account_find_from_address(queueheader_buf);
1260 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1261 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1262 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1263 use_signing = param;
1266 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1267 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1268 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1269 use_encryption = param;
1271 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1272 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1273 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1275 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1276 sizeof(queueheader_buf), "X-Priority: ")) {
1277 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1278 compose->priority = param;
1281 account = msginfo->folder->folder->account;
1283 if (!account && prefs_common.reedit_account_autosel) {
1284 gchar from[BUFFSIZE];
1285 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1286 extract_address(from);
1287 account = account_find_from_address(from);
1290 if (!account) account = cur_account;
1291 g_return_if_fail(account != NULL);
1293 compose = compose_create(account, COMPOSE_REEDIT);
1294 compose->privacy_system = privacy_system;
1295 compose_use_signing(compose, use_signing);
1296 compose_use_encryption(compose, use_encryption);
1297 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1299 if (msginfo->folder->stype == F_QUEUE
1300 || msginfo->folder->stype == F_DRAFT) {
1301 gchar queueheader_buf[BUFFSIZE];
1303 /* Set message save folder */
1304 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1307 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1308 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1309 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1313 if (compose_parse_header(compose, msginfo) < 0) return;
1314 compose_reedit_set_entry(compose, msginfo);
1316 text = GTK_STEXT(compose->text);
1317 gtk_stext_freeze(text);
1319 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1320 g_warning("Can't get text part\n");
1322 while (fgets(buf, sizeof(buf), fp) != NULL) {
1324 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1328 compose_attach_parts(compose, msginfo);
1330 gtk_stext_thaw(text);
1331 gtk_widget_grab_focus(compose->text);
1333 if (prefs_common.auto_exteditor)
1334 compose_exec_ext_editor(compose);
1337 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1341 GtkItemFactory *ifactory;
1344 g_return_val_if_fail(msginfo != NULL, NULL);
1347 account = account_get_reply_account(msginfo,
1348 prefs_common.reply_account_autosel);
1349 g_return_val_if_fail(account != NULL, NULL);
1351 compose = compose_create(account, COMPOSE_REDIRECT);
1352 ifactory = gtk_item_factory_from_widget(compose->menubar);
1354 compose->replyinfo = NULL;
1355 compose->fwdinfo = NULL;
1357 compose_show_first_last_header(compose, TRUE);
1359 gtk_widget_grab_focus(compose->header_last->entry);
1361 filename = procmsg_get_message_file_path(msginfo);
1362 if (filename == NULL)
1365 compose->redirect_filename = filename;
1367 /* Set save folder */
1368 item = msginfo->folder;
1369 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1370 gchar *folderidentifier;
1372 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1373 folderidentifier = folder_item_get_identifier(item);
1374 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1375 g_free(folderidentifier);
1378 compose_attach_parts(compose, msginfo);
1380 if (msginfo->subject)
1381 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1383 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1385 gtk_stext_freeze(GTK_STEXT(compose->text));
1386 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1387 gtk_editable_set_editable(GTK_EDITABLE(compose->text), FALSE);
1388 gtk_stext_thaw(GTK_STEXT(compose->text));
1390 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1391 menu_set_sensitive(ifactory, "/Add...", FALSE);
1392 menu_set_sensitive(ifactory, "/Remove", FALSE);
1393 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1395 ifactory = gtk_item_factory_from_widget(compose->menubar);
1396 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1397 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1398 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1399 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1400 menu_set_sensitive(ifactory, "/Edit", FALSE);
1401 menu_set_sensitive(ifactory, "/Options", FALSE);
1402 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1403 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1405 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1406 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1407 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1408 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1409 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1410 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1411 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1416 GList *compose_get_compose_list(void)
1418 return compose_list;
1421 void compose_entry_append(Compose *compose, const gchar *address,
1422 ComposeEntryType type)
1426 if (!address || *address == '\0') return;
1428 #if 0 /* NEW COMPOSE GUI */
1431 entry = GTK_ENTRY(compose->cc_entry);
1434 entry = GTK_ENTRY(compose->bcc_entry);
1436 case COMPOSE_NEWSGROUPS:
1437 entry = GTK_ENTRY(compose->newsgroups_entry);
1441 entry = GTK_ENTRY(compose->to_entry);
1445 text = gtk_entry_get_text(entry);
1447 gtk_entry_append_text(entry, ", ");
1448 gtk_entry_append_text(entry, address);
1456 header = N_("Bcc:");
1458 case COMPOSE_REPLYTO:
1459 header = N_("Reply-To:");
1461 case COMPOSE_NEWSGROUPS:
1462 header = N_("Newsgroups:");
1464 case COMPOSE_FOLLOWUPTO:
1465 header = N_( "Followup-To:");
1472 header = prefs_common.trans_hdr ? gettext(header) : header;
1474 compose_add_header_entry(compose, header, (gchar *)address);
1477 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1479 static GtkStyle *bold_style = NULL;
1480 static GdkColor bold_color;
1481 static GdkFont *bold_font = NULL;
1485 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1486 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1487 if (gtk_entry_get_text(entry) &&
1488 !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1489 gtk_widget_ensure_style(GTK_WIDGET(entry));
1491 gtkut_convert_int_to_gdk_color
1492 (prefs_common.color_new, &bold_color);
1493 bold_style = gtk_style_copy(gtk_widget_get_style
1494 (GTK_WIDGET(entry)));
1496 bold_font = gtkut_font_load
1497 (prefs_common.boldfont);
1499 bold_style->font = bold_font;
1500 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1502 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1507 void compose_toolbar_cb(gint action, gpointer data)
1509 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1510 Compose *compose = (Compose*)toolbar_item->parent;
1512 g_return_if_fail(compose != NULL);
1516 compose_send_cb(compose, 0, NULL);
1519 compose_send_later_cb(compose, 0, NULL);
1522 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1525 compose_insert_file_cb(compose, 0, NULL);
1528 compose_attach_cb(compose, 0, NULL);
1531 compose_insert_sig(compose, FALSE);
1534 compose_ext_editor_cb(compose, 0, NULL);
1536 case A_LINEWRAP_CURRENT:
1537 compose_wrap_line(compose);
1539 case A_LINEWRAP_ALL:
1540 compose_wrap_line_all(compose);
1543 compose_address_cb(compose, 0, NULL);
1546 case A_CHECK_SPELLING:
1547 compose_check_all(compose);
1555 static void compose_entries_set(Compose *compose, const gchar *mailto)
1560 gchar *subject = NULL;
1563 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1566 compose_entry_append(compose, to, COMPOSE_TO);
1568 compose_entry_append(compose, cc, COMPOSE_CC);
1570 compose_entry_append(compose, bcc, COMPOSE_BCC);
1572 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1574 gtk_stext_insert(GTK_STEXT(compose->text),
1575 NULL, NULL, NULL, body, -1);
1576 gtk_stext_insert(GTK_STEXT(compose->text),
1577 NULL, NULL, NULL, "\n", 1);
1587 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1589 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1590 {"Cc:", NULL, TRUE},
1591 {"References:", NULL, FALSE},
1592 {"Bcc:", NULL, TRUE},
1593 {"Newsgroups:", NULL, TRUE},
1594 {"Followup-To:", NULL, TRUE},
1595 {"List-Post:", NULL, FALSE},
1596 {"X-Priority:", NULL, FALSE},
1597 {NULL, NULL, FALSE}};
1613 g_return_val_if_fail(msginfo != NULL, -1);
1615 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1616 procheader_get_header_fields(fp, hentry);
1619 if (hentry[H_REPLY_TO].body != NULL) {
1620 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1621 compose->replyto = hentry[H_REPLY_TO].body;
1622 hentry[H_REPLY_TO].body = NULL;
1624 if (hentry[H_CC].body != NULL) {
1625 conv_unmime_header_overwrite(hentry[H_CC].body);
1626 compose->cc = hentry[H_CC].body;
1627 hentry[H_CC].body = NULL;
1629 if (hentry[H_REFERENCES].body != NULL) {
1630 if (compose->mode == COMPOSE_REEDIT)
1631 compose->references = hentry[H_REFERENCES].body;
1633 compose->references = compose_parse_references
1634 (hentry[H_REFERENCES].body, msginfo->msgid);
1635 g_free(hentry[H_REFERENCES].body);
1637 hentry[H_REFERENCES].body = NULL;
1639 if (hentry[H_BCC].body != NULL) {
1640 if (compose->mode == COMPOSE_REEDIT) {
1641 conv_unmime_header_overwrite(hentry[H_BCC].body);
1642 compose->bcc = hentry[H_BCC].body;
1644 g_free(hentry[H_BCC].body);
1645 hentry[H_BCC].body = NULL;
1647 if (hentry[H_NEWSGROUPS].body != NULL) {
1648 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1649 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1650 hentry[H_NEWSGROUPS].body = NULL;
1652 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1653 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1654 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1655 hentry[H_FOLLOWUP_TO].body = NULL;
1657 if (hentry[H_LIST_POST].body != NULL) {
1660 extract_address(hentry[H_LIST_POST].body);
1661 if (hentry[H_LIST_POST].body[0] != '\0') {
1662 scan_mailto_url(hentry[H_LIST_POST].body,
1663 &to, NULL, NULL, NULL, NULL);
1665 g_free(compose->ml_post);
1666 compose->ml_post = to;
1669 g_free(hentry[H_LIST_POST].body);
1670 hentry[H_LIST_POST].body = NULL;
1673 /* CLAWS - X-Priority */
1674 if (compose->mode == COMPOSE_REEDIT)
1675 if (hentry[H_X_PRIORITY].body != NULL) {
1678 priority = atoi(hentry[H_X_PRIORITY].body);
1679 g_free(hentry[H_X_PRIORITY].body);
1681 hentry[H_X_PRIORITY].body = NULL;
1683 if (priority < PRIORITY_HIGHEST ||
1684 priority > PRIORITY_LOWEST)
1685 priority = PRIORITY_NORMAL;
1687 compose->priority = priority;
1690 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1691 compose->inreplyto = g_strdup(msginfo->inreplyto);
1692 else if (compose->mode != COMPOSE_REEDIT &&
1693 msginfo->msgid && *msginfo->msgid) {
1694 compose->inreplyto = g_strdup(msginfo->msgid);
1696 if (!compose->references) {
1697 if (msginfo->inreplyto && *msginfo->inreplyto)
1698 compose->references =
1699 g_strdup_printf("<%s>\n\t<%s>",
1703 compose->references =
1704 g_strconcat("<", msginfo->msgid, ">",
1712 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1714 GSList *ref_id_list, *cur;
1718 ref_id_list = references_list_append(NULL, ref);
1719 if (!ref_id_list) return NULL;
1720 if (msgid && *msgid)
1721 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1726 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1727 /* "<" + Message-ID + ">" + CR+LF+TAB */
1728 len += strlen((gchar *)cur->data) + 5;
1730 if (len > MAX_REFERENCES_LEN) {
1731 /* remove second message-ID */
1732 if (ref_id_list && ref_id_list->next &&
1733 ref_id_list->next->next) {
1734 g_free(ref_id_list->next->data);
1735 ref_id_list = g_slist_remove
1736 (ref_id_list, ref_id_list->next->data);
1738 slist_free_strings(ref_id_list);
1739 g_slist_free(ref_id_list);
1746 new_ref = g_string_new("");
1747 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1748 if (new_ref->len > 0)
1749 g_string_append(new_ref, "\n\t");
1750 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1753 slist_free_strings(ref_id_list);
1754 g_slist_free(ref_id_list);
1756 new_ref_str = new_ref->str;
1757 g_string_free(new_ref, FALSE);
1762 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1763 const gchar *fmt, const gchar *qmark,
1766 GtkSText *text = GTK_STEXT(compose->text);
1767 static MsgInfo dummyinfo;
1768 gchar *quote_str = NULL;
1772 const gchar *trimmed_body = body;
1775 msginfo = &dummyinfo;
1777 if (qmark != NULL) {
1778 quote_fmt_init(msginfo, NULL, NULL);
1779 quote_fmt_scan_string(qmark);
1782 buf = quote_fmt_get_buffer();
1784 alertpanel_error(_("Quote mark format error."));
1786 Xstrdup_a(quote_str, buf, return NULL)
1789 if (fmt && *fmt != '\0') {
1790 while (trimmed_body && strlen(trimmed_body) > 1
1791 && trimmed_body[0]=='\n')
1794 quote_fmt_init(msginfo, quote_str, trimmed_body);
1795 quote_fmt_scan_string(fmt);
1798 buf = quote_fmt_get_buffer();
1800 alertpanel_error(_("Message reply/forward format error."));
1806 gtk_stext_freeze(text);
1808 for (p = buf; *p != '\0'; ) {
1809 lastp = strchr(p, '\n');
1810 len = lastp ? lastp - p + 1 : -1;
1811 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1818 gtk_stext_thaw(text);
1823 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1824 gboolean to_all, gboolean to_ml,
1826 gboolean followup_and_reply_to)
1828 GSList *cc_list = NULL;
1831 gchar *replyto = NULL;
1832 GHashTable *to_table;
1834 g_return_if_fail(compose->account != NULL);
1835 g_return_if_fail(msginfo != NULL);
1837 if (compose->account->protocol != A_NNTP) {
1838 if (!compose->replyto && to_ml && compose->ml_post
1839 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1840 compose_entry_append(compose,
1843 else if (!(to_all || to_sender)
1845 && msginfo->folder->prefs->enable_default_reply_to) {
1846 compose_entry_append(compose,
1847 msginfo->folder->prefs->default_reply_to,
1850 compose_entry_append(compose,
1851 (compose->replyto && !to_sender)
1852 ? compose->replyto :
1853 msginfo->from ? msginfo->from : "",
1856 if (to_sender || (compose->followup_to &&
1857 !strncmp(compose->followup_to, "poster", 6)))
1858 compose_entry_append
1860 (compose->replyto ? compose->replyto :
1861 msginfo->from ? msginfo->from : ""),
1864 else if (followup_and_reply_to || to_all) {
1865 compose_entry_append
1867 (compose->replyto ? compose->replyto :
1868 msginfo->from ? msginfo->from : ""),
1871 compose_entry_append
1873 compose->followup_to ? compose->followup_to :
1874 compose->newsgroups ? compose->newsgroups : "",
1875 COMPOSE_NEWSGROUPS);
1878 compose_entry_append
1880 compose->followup_to ? compose->followup_to :
1881 compose->newsgroups ? compose->newsgroups : "",
1882 COMPOSE_NEWSGROUPS);
1885 if (msginfo->subject && *msginfo->subject) {
1889 buf = p = g_strdup(msginfo->subject);
1890 p += subject_get_prefix_length(p);
1891 memmove(buf, p, strlen(p) + 1);
1893 buf2 = g_strdup_printf("Re: %s", buf);
1894 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1899 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1901 if (to_ml && compose->ml_post) return;
1902 if (!to_all || compose->account->protocol == A_NNTP) return;
1904 if (compose->replyto) {
1905 Xstrdup_a(replyto, compose->replyto, return);
1906 extract_address(replyto);
1908 if (msginfo->from) {
1909 Xstrdup_a(from, msginfo->from, return);
1910 extract_address(from);
1913 if (replyto && from)
1914 cc_list = address_list_append_with_comments(cc_list, from);
1915 if (to_all && msginfo->folder &&
1916 msginfo->folder->prefs->enable_default_reply_to)
1917 cc_list = address_list_append_with_comments(cc_list,
1918 msginfo->folder->prefs->default_reply_to);
1919 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1920 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1922 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1924 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1925 if (compose->account)
1926 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1927 GINT_TO_POINTER(1));
1929 /* remove address on To: and that of current account */
1930 for (cur = cc_list; cur != NULL; ) {
1931 GSList *next = cur->next;
1934 addr = g_strdup(cur->data);
1935 extract_address(addr);
1937 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
1938 cc_list = g_slist_remove(cc_list, cur->data);
1940 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
1944 hash_free_strings(to_table);
1945 g_hash_table_destroy(to_table);
1948 for (cur = cc_list; cur != NULL; cur = cur->next)
1949 compose_entry_append(compose, (gchar *)cur->data,
1951 slist_free_strings(cc_list);
1952 g_slist_free(cc_list);
1957 #define SET_ENTRY(entry, str) \
1960 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1963 #define SET_ADDRESS(type, str) \
1966 compose_entry_append(compose, str, type); \
1969 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1971 g_return_if_fail(msginfo != NULL);
1973 SET_ENTRY(subject_entry, msginfo->subject);
1974 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1975 SET_ADDRESS(COMPOSE_CC, compose->cc);
1976 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1977 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1978 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
1979 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
1981 compose_update_priority_menu_item(compose);
1982 compose_update_privacy_system_menu_item(compose);
1983 compose_show_first_last_header(compose, TRUE);
1989 static void compose_insert_sig(Compose *compose, gboolean replace)
1991 GtkSText *text = GTK_STEXT(compose->text);
1995 g_return_if_fail(compose->account != NULL);
1997 cur_pos = gtk_editable_get_position(GTK_EDITABLE(text));
1999 gtk_stext_freeze(text);
2002 len = gtk_stext_get_length(text);
2003 gtk_stext_set_point(text, len);
2006 if (replace && compose->sig_str) {
2009 if (compose->sig_str[0] == '\0')
2012 pos = gtkut_stext_find(text, 0, compose->sig_str, TRUE);
2015 len = get_mbs_len(compose->sig_str);
2017 gtk_stext_set_point(text, pos);
2018 gtk_stext_forward_delete(text, len);
2023 g_free(compose->sig_str);
2024 compose->sig_str = compose_get_signature_str(compose);
2025 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2026 compose->sig_str = g_strdup("");
2028 gtk_stext_insert(text, NULL, NULL, NULL, compose->sig_str, -1);
2030 gtk_stext_thaw(text);
2032 if (cur_pos > gtk_stext_get_length(text))
2033 cur_pos = gtk_stext_get_length(text);
2035 gtk_editable_set_position(GTK_EDITABLE(text), cur_pos);
2036 gtk_stext_set_point(text, cur_pos);
2039 static gchar *compose_get_signature_str(Compose *compose)
2041 gchar *sig_body = NULL;
2042 gchar *sig_str = NULL;
2044 g_return_val_if_fail(compose->account != NULL, NULL);
2046 if (!compose->account->sig_path)
2049 if (compose->account->sig_type == SIG_FILE) {
2050 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2051 g_warning("can't open signature file: %s\n",
2052 compose->account->sig_path);
2057 if (compose->account->sig_type == SIG_COMMAND)
2058 sig_body = get_command_output(compose->account->sig_path);
2062 tmp = file_read_to_str(compose->account->sig_path);
2065 sig_body = normalize_newlines(tmp);
2069 if (compose->account->sig_sep)
2070 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2073 sig_str = g_strconcat("\n\n", sig_body, NULL);
2080 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2082 GtkSText *text = GTK_STEXT(compose->text);
2083 gchar buf[BUFFSIZE];
2086 gboolean badtxt = FALSE;
2088 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2090 if ((fp = fopen(file, "rb")) == NULL) {
2091 FILE_OP_ERROR(file, "fopen");
2092 return COMPOSE_INSERT_READ_ERROR;
2095 gtk_stext_freeze(text);
2097 while (fgets(buf, sizeof(buf), fp) != NULL) {
2098 /* strip <CR> if DOS/Windows file,
2099 replace <CR> with <LF> if Macintosh file. */
2102 if (len > 0 && buf[len - 1] != '\n') {
2104 if (buf[len] == '\r') buf[len] = '\n';
2106 if (mbstowcs(NULL, buf, 0) == -1)
2108 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
2111 gtk_stext_thaw(text);
2116 return COMPOSE_INSERT_INVALID_CHARACTER;
2118 return COMPOSE_INSERT_SUCCESS;
2121 static void compose_attach_append(Compose *compose, const gchar *file,
2122 const gchar *filename,
2123 const gchar *content_type)
2126 gchar *text[N_ATTACH_COLS];
2131 if (!is_file_exist(file)) {
2132 g_warning("File %s doesn't exist\n", file);
2135 if ((size = get_file_size(file)) < 0) {
2136 g_warning("Can't get file size of %s\n", file);
2140 alertpanel_notice(_("File %s is empty."), file);
2143 if ((fp = fopen(file, "rb")) == NULL) {
2144 alertpanel_error(_("Can't read %s."), file);
2149 #if 0 /* NEW COMPOSE GUI */
2150 if (!compose->use_attach) {
2151 GtkItemFactory *ifactory;
2153 ifactory = gtk_item_factory_from_widget(compose->menubar);
2154 menu_set_active(ifactory, "/View/Attachment", TRUE);
2157 ainfo = g_new0(AttachInfo, 1);
2158 ainfo->file = g_strdup(file);
2161 ainfo->content_type = g_strdup(content_type);
2162 if (!g_strcasecmp(content_type, "message/rfc822")) {
2164 MsgFlags flags = {0, 0};
2167 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2168 ainfo->encoding = ENC_7BIT;
2170 ainfo->encoding = ENC_8BIT;
2172 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2173 if (msginfo && msginfo->subject)
2174 name = msginfo->subject;
2176 name = g_basename(filename ? filename : file);
2178 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2180 procmsg_msginfo_free(msginfo);
2182 if (!g_strncasecmp(content_type, "text", 4))
2183 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2185 ainfo->encoding = ENC_BASE64;
2186 ainfo->name = g_strdup
2187 (g_basename(filename ? filename : file));
2190 ainfo->content_type = procmime_get_mime_type(file);
2191 if (!ainfo->content_type) {
2192 ainfo->content_type =
2193 g_strdup("application/octet-stream");
2194 ainfo->encoding = ENC_BASE64;
2195 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
2197 procmime_get_encoding_for_text_file(file);
2199 ainfo->encoding = ENC_BASE64;
2200 ainfo->name = g_strdup(g_basename(filename ? filename : file));
2203 if (!strcmp(ainfo->content_type, "unknown")) {
2204 g_free(ainfo->content_type);
2205 ainfo->content_type = g_strdup("application/octet-stream");
2210 text[COL_MIMETYPE] = ainfo->content_type;
2211 text[COL_SIZE] = to_human_readable(size);
2212 text[COL_NAME] = ainfo->name;
2214 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2215 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2218 static void compose_use_signing(Compose *compose, gboolean use_signing)
2220 GtkItemFactory *ifactory;
2221 GtkWidget *menuitem = NULL;
2223 compose->use_signing = use_signing;
2224 ifactory = gtk_item_factory_from_widget(compose->menubar);
2225 menuitem = gtk_item_factory_get_item
2226 (ifactory, "/Options/Sign");
2227 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2231 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2233 GtkItemFactory *ifactory;
2234 GtkWidget *menuitem = NULL;
2236 compose->use_encryption = use_encryption;
2237 ifactory = gtk_item_factory_from_widget(compose->menubar);
2238 menuitem = gtk_item_factory_get_item
2239 (ifactory, "/Options/Encrypt");
2241 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2245 #define NEXT_PART_NOT_CHILD(info) \
2247 node = info->node; \
2248 while (node->children) \
2249 node = g_node_last_child(node); \
2250 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2253 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2257 MimeInfo *firsttext = NULL;
2258 MimeInfo *encrypted = NULL;
2261 const gchar *partname = NULL;
2263 mimeinfo = procmime_scan_message(msginfo);
2264 if (!mimeinfo) return;
2266 if (mimeinfo->node->children == NULL) {
2267 procmime_mimeinfo_free_all(mimeinfo);
2271 /* find first content part */
2272 child = (MimeInfo *) mimeinfo->node->children->data;
2273 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2274 child = (MimeInfo *)child->node->children->data;
2276 if (child->type == MIMETYPE_TEXT) {
2278 debug_print("First text part found\n");
2279 } else if (compose->mode == COMPOSE_REEDIT &&
2280 child->type == MIMETYPE_APPLICATION &&
2281 !g_strcasecmp(child->subtype, "pgp-encrypted")) {
2283 val = alertpanel(_("Encrypted message"),
2284 _("Cannot re-edit an encrypted message. \n"
2285 "Discard encrypted part?"),
2286 _("Yes"), _("No"), NULL);
2287 if (val == G_ALERTDEFAULT)
2288 encrypted = (MimeInfo *)child->node->parent->data;
2291 child = (MimeInfo *) mimeinfo->node->children->data;
2292 while (child != NULL) {
2293 if (child == encrypted) {
2294 /* skip this part of tree */
2295 NEXT_PART_NOT_CHILD(child);
2299 if (child->type == MIMETYPE_MULTIPART) {
2300 /* get the actual content */
2301 child = procmime_mimeinfo_next(child);
2305 if (child == firsttext) {
2306 child = procmime_mimeinfo_next(child);
2310 outfile = procmime_get_tmp_file_name(child);
2311 if (procmime_get_part(outfile, child) < 0)
2312 g_warning("Can't get the part of multipart message.");
2314 gchar *content_type;
2316 content_type = procmime_get_content_type_str(child->type, child->subtype);
2317 partname = procmime_mimeinfo_get_parameter(child, "name");
2318 if (partname == NULL)
2320 compose_attach_append(compose, outfile,
2321 partname, content_type);
2322 g_free(content_type);
2325 NEXT_PART_NOT_CHILD(child);
2327 procmime_mimeinfo_free_all(mimeinfo);
2330 #undef NEXT_PART_NOT_CHILD
2332 #define GET_CHAR(pos, buf, len) \
2334 if (text->use_wchar) \
2335 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2337 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2342 #define DISP_WIDTH(len) \
2343 ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
2344 (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
2346 #define SPACE_CHARS " \t"
2348 static void compose_wrap_line(Compose *compose)
2350 GtkSText *text = GTK_STEXT(compose->text);
2351 gint ch_len, last_ch_len;
2352 gchar cbuf[MB_LEN_MAX], last_ch;
2356 gint p_start, p_end;
2357 gint line_pos, cur_pos;
2358 gint line_len, cur_len;
2360 gtk_stext_freeze(text);
2362 text_len = gtk_stext_get_length(text);
2364 /* check to see if the point is on the paragraph mark (empty line). */
2365 cur_pos = gtk_stext_get_point(text);
2366 GET_CHAR(cur_pos, cbuf, ch_len);
2367 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2369 goto compose_end; /* on the paragraph mark */
2370 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2371 if (ch_len == 1 && *cbuf == '\n')
2372 goto compose_end; /* on the paragraph mark */
2375 /* find paragraph start. */
2376 line_end = quoted = 0;
2377 for (p_start = cur_pos; p_start >= 0; --p_start) {
2378 GET_CHAR(p_start, cbuf, ch_len);
2379 if (ch_len == 1 && *cbuf == '\n') {
2381 goto compose_end; /* quoted part */
2389 && strchr(prefs_common.quote_chars, *cbuf))
2391 else if (ch_len != 1 || !isspace(*(guchar *)cbuf))
2400 /* find paragraph end. */
2402 for (p_end = cur_pos; p_end < text_len; p_end++) {
2403 GET_CHAR(p_end, cbuf, ch_len);
2404 if (ch_len == 1 && *cbuf == '\n') {
2411 if (line_end && ch_len == 1 &&
2412 strchr(prefs_common.quote_chars, *cbuf))
2413 goto compose_end; /* quoted part */
2418 if (p_end >= text_len)
2421 if (p_start >= p_end)
2424 line_len = cur_len = 0;
2428 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2431 GET_CHAR(cur_pos, cbuf, ch_len);
2438 if (ch_len == 1 && isspace(*(guchar *)cbuf))
2441 if (ch_len == 1 && *cbuf == '\n') {
2443 if (last_ch_len == 1 && !isspace((guchar)last_ch)) {
2444 if (cur_pos + 1 < p_end) {
2445 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2447 !isspace(*(guchar *)cbuf))
2451 gtk_stext_set_point(text, cur_pos + 1);
2452 gtk_stext_backward_delete(text, 1);
2454 gtk_stext_set_point(text, cur_pos);
2455 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2465 last_ch_len = ch_len;
2469 line_pos = cur_pos + 1;
2470 line_len = cur_len + ch_len;
2473 if (cur_len + DISP_WIDTH(ch_len) > prefs_common.linewrap_len &&
2477 GET_CHAR(line_pos - 1, cbuf, ch_len);
2478 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2479 gtk_stext_set_point(text, line_pos);
2480 gtk_stext_backward_delete(text, 1);
2489 gtk_stext_set_point(text, line_pos);
2490 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2494 cur_len = cur_len - line_len + DISP_WIDTH(ch_len);
2500 line_pos = cur_pos + 1;
2501 line_len = cur_len + DISP_WIDTH(ch_len);
2503 cur_len += DISP_WIDTH(ch_len);
2507 gtk_stext_thaw(text);
2512 /* Darko: used when I debug wrapping */
2513 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2516 gchar cbuf[MB_LEN_MAX];
2518 printf("%d [", pos);
2519 for (i = pos; i < tlen; i++) {
2520 GET_CHAR(i, cbuf, clen);
2521 if (clen < 0) break;
2522 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2524 fwrite(cbuf, clen, 1, stdout);
2532 WAIT_FOR_INDENT_CHAR,
2533 WAIT_FOR_INDENT_CHAR_OR_SPACE
2536 /* return indent length, we allow:
2537 > followed by spaces/tabs
2538 | followed by spaces/tabs
2539 uppercase characters immediately followed by >,
2540 and the repeating sequences of the above */
2541 /* return indent length */
2542 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2545 guint i, ch_len, alnum_cnt = 0;
2546 IndentState state = WAIT_FOR_INDENT_CHAR;
2547 gchar cbuf[MB_LEN_MAX];
2551 if (prefs_common.quote_chars == NULL) {
2555 for (i = start_pos; i < text_len; i++) {
2556 GET_CHAR(i, cbuf, ch_len);
2560 if (cbuf[0] == '\n')
2563 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2564 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2567 case WAIT_FOR_SPACE:
2568 if (is_space == FALSE)
2570 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2572 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2573 if (is_indent == FALSE && is_space == FALSE &&
2574 !isupper((guchar)cbuf[0]))
2576 if (is_space == TRUE) {
2578 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2579 } else if (is_indent == TRUE) {
2581 state = WAIT_FOR_SPACE;
2584 state = WAIT_FOR_INDENT_CHAR;
2587 case WAIT_FOR_INDENT_CHAR:
2588 if (is_indent == FALSE && !isupper((guchar)cbuf[0]))
2590 if (is_indent == TRUE) {
2592 && !strchr(prefs_common.quote_chars, cbuf[0]))
2595 state = WAIT_FOR_SPACE;
2606 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2612 /* insert quotation string when line was wrapped */
2613 static guint ins_quote(GtkSText *text, guint indent_len,
2614 guint prev_line_pos, guint text_len,
2617 guint i, ins_len = 0;
2621 for (i = 0; i < indent_len; i++) {
2622 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2623 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2625 ins_len = indent_len;
2631 /* check if we should join the next line */
2632 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2633 guint prev_ilen, gboolean autowrap)
2635 guint indent_len, ch_len;
2636 gboolean do_join = FALSE;
2637 gchar cbuf[MB_LEN_MAX];
2639 indent_len = get_indent_length(text, start_pos, tlen);
2641 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2642 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2643 if (ch_len > 0 && (cbuf[0] != '\n'))
2650 static void compose_wrap_line_all(Compose *compose)
2652 compose_wrap_line_all_full(compose, FALSE);
2655 #define STEXT_FREEZE() \
2656 if (!frozen) { gtk_stext_freeze(text); frozen = TRUE; }
2658 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2660 GtkSText *text = GTK_STEXT(compose->text);
2662 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2663 gint line_len = 0, cur_len = 0;
2665 gboolean is_new_line = TRUE, do_delete = FALSE;
2667 gboolean linewrap_quote = prefs_common.linewrap_quote;
2668 gboolean set_editable_pos = FALSE;
2669 gint editable_pos = 0;
2670 gboolean frozen = FALSE;
2671 guint linewrap_len = prefs_common.linewrap_len;
2672 gchar *qfmt = prefs_common.quotemark;
2673 gchar cbuf[MB_LEN_MAX];
2675 tlen = gtk_stext_get_length(text);
2677 for (; cur_pos < tlen; cur_pos++) {
2678 /* mark position of new line - needed for quotation wrap */
2681 i_len = get_indent_length(text, cur_pos, tlen);
2683 is_new_line = FALSE;
2686 g_print("new line i_len=%d p_pos=", i_len);
2687 dump_text(text, p_pos, tlen, 1);
2691 GET_CHAR(cur_pos, cbuf, ch_len);
2693 /* fix line length for tabs */
2694 if (ch_len == 1 && *cbuf == '\t') {
2695 guint tab_width = text->default_tab_width;
2696 guint tab_offset = line_len % tab_width;
2699 g_print("found tab at pos=%d line_len=%d ", cur_pos,
2703 line_len += tab_width - tab_offset - 1;
2707 printf("new_len=%d\n", line_len);
2711 /* we have encountered line break */
2712 if (ch_len == 1 && *cbuf == '\n') {
2714 gchar cb[MB_LEN_MAX];
2716 /* should we join the next line */
2717 if ((autowrap || i_len != cur_len) && do_delete &&
2719 (text, cur_pos + 1, tlen, i_len, autowrap))
2725 g_print("found CR at %d do_del is %d next line is ",
2726 cur_pos, do_delete);
2727 dump_text(text, cur_pos + 1, tlen, 1);
2730 /* skip delete if it is continuous URL */
2731 if (do_delete && (line_pos - p_pos <= i_len) &&
2732 gtk_stext_is_uri_string(text, line_pos, tlen))
2736 g_print("l_len=%d wrap_len=%d do_del=%d\n",
2737 line_len, linewrap_len, do_delete);
2739 if (line_len < linewrap_len && do_delete) {
2741 /* get rid of newline */
2742 gtk_stext_set_point(text, cur_pos);
2743 gtk_stext_forward_delete(text, 1);
2746 /* if text starts with quote fmt or with
2747 indent string, delete them */
2750 ilen = gtk_stext_str_compare_n
2751 (text, cur_pos, p_pos, i_len,
2754 gtk_stext_forward_delete
2760 GET_CHAR(cur_pos, cb, clen);
2761 /* insert space between the next line */
2764 gchar cb_prev[MB_LEN_MAX];
2766 GET_CHAR(cur_pos - 1, cb_prev,
2768 if ((clen_prev != clen && clen > 1) ||
2770 !isspace((guchar)cb[0]))) {
2778 /* and start over with current line */
2779 cur_pos = p_pos - 1;
2781 line_len = cur_len = 0;
2785 g_print("after delete l_pos=");
2786 dump_text(text, line_pos, tlen, 1);
2788 /* move beginning of line if we are on LF */
2789 GET_CHAR(line_pos, cb, clen);
2790 if (clen == 1 && *cb == '\n')
2793 g_print("new line_pos=%d\n", line_pos);
2799 /* mark new line beginning */
2800 line_pos = cur_pos + 1;
2801 line_len = cur_len = 0;
2812 /* possible line break */
2813 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2814 line_pos = cur_pos + 1;
2815 line_len = cur_len + ch_len;
2818 /* are we over wrapping length set in preferences ? */
2819 if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
2823 g_print("should wrap cur_pos=%d ", cur_pos);
2824 dump_text(text, p_pos, tlen, 1);
2825 dump_text(text, line_pos, tlen, 1);
2827 /* force wrapping if it is one long word but not URL */
2828 if (line_pos - p_pos <= i_len)
2829 if (!gtk_stext_is_uri_string
2830 (text, line_pos, tlen))
2831 line_pos = cur_pos - 1;
2833 g_print("new line_pos=%d\n", line_pos);
2836 GET_CHAR(line_pos - 1, cbuf, clen);
2838 /* if next character is space delete it */
2839 if (clen == 1 && isspace(*(guchar *)cbuf)) {
2840 if (p_pos + i_len != line_pos ||
2841 !gtk_stext_is_uri_string
2842 (text, line_pos, tlen)) {
2844 /* workaround for correct cursor
2846 if (set_editable_pos == FALSE) {
2847 editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2848 if (editable_pos == line_pos)
2849 set_editable_pos = TRUE;
2851 gtk_stext_set_point(text, line_pos);
2852 gtk_stext_backward_delete(text, 1);
2861 /* if it is URL at beginning of line don't wrap */
2862 if (p_pos + i_len == line_pos &&
2863 gtk_stext_is_uri_string(text, line_pos, tlen)) {
2865 g_print("found URL at ");
2866 dump_text(text, line_pos, tlen, 1);
2873 gtk_stext_set_point(text, line_pos);
2874 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2875 gtk_stext_compact_buffer(text);
2878 /* for loop will increase it */
2879 cur_pos = line_pos - 1;
2880 /* start over with current line */
2882 line_len = cur_len = 0;
2883 if (autowrap || i_len > 0)
2888 g_print("after CR insert ");
2889 dump_text(text, line_pos, tlen, 1);
2890 dump_text(text, cur_pos, tlen, 1);
2893 /* should we insert quotation ? */
2894 if (linewrap_quote && i_len) {
2895 /* only if line is not already quoted */
2896 if (!gtk_stext_str_compare
2897 (text, line_pos, tlen, qfmt)) {
2900 if (line_pos - p_pos > i_len) {
2902 (text, i_len, p_pos,
2907 g_print("after quote insert ");
2908 dump_text(text, line_pos, tlen, 1);
2916 line_pos = cur_pos + 1;
2917 line_len = cur_len + DISP_WIDTH(ch_len);
2919 /* advance to next character in buffer */
2920 cur_len += DISP_WIDTH(ch_len);
2924 gtk_stext_thaw(text);
2926 if (set_editable_pos && editable_pos <= tlen)
2927 gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
2933 static void compose_set_title(Compose *compose)
2938 edited = compose->modified ? _(" [Edited]") : "";
2939 if (compose->account && compose->account->address)
2940 str = g_strdup_printf(_("%s - Compose message%s"),
2941 compose->account->address, edited);
2943 str = g_strdup_printf(_("Compose message%s"), edited);
2944 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2949 * compose_current_mail_account:
2951 * Find a current mail account (the currently selected account, or the
2952 * default account, if a news account is currently selected). If a
2953 * mail account cannot be found, display an error message.
2955 * Return value: Mail account, or NULL if not found.
2957 static PrefsAccount *
2958 compose_current_mail_account(void)
2962 if (cur_account && cur_account->protocol != A_NNTP)
2965 ac = account_get_default();
2966 if (!ac || ac->protocol == A_NNTP) {
2967 alertpanel_error(_("Account for sending mail is not specified.\n"
2968 "Please select a mail account before sending."));
2975 static void compose_select_account(Compose *compose, PrefsAccount *account,
2978 GtkItemFactory *ifactory;
2980 g_return_if_fail(account != NULL);
2982 compose->account = account;
2984 compose_set_title(compose);
2986 ifactory = gtk_item_factory_from_widget(compose->menubar);
2988 if (account->protocol == A_NNTP) {
2989 gtk_widget_show(compose->newsgroups_hbox);
2990 gtk_widget_show(compose->newsgroups_entry);
2991 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2992 compose->use_newsgroups = TRUE;
2994 menu_set_active(ifactory, "/View/To", FALSE);
2995 menu_set_sensitive(ifactory, "/View/To", TRUE);
2996 menu_set_active(ifactory, "/View/Cc", FALSE);
2997 menu_set_sensitive(ifactory, "/View/Cc", TRUE);
2998 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
3000 gtk_widget_hide(compose->newsgroups_hbox);
3001 gtk_widget_hide(compose->newsgroups_entry);
3002 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
3003 gtk_widget_queue_resize(compose->table_vbox);
3004 compose->use_newsgroups = FALSE;
3006 menu_set_active(ifactory, "/View/To", TRUE);
3007 menu_set_sensitive(ifactory, "/View/To", FALSE);
3008 menu_set_active(ifactory, "/View/Cc", TRUE);
3009 menu_set_sensitive(ifactory, "/View/Cc", FALSE);
3010 menu_set_active(ifactory, "/View/Followup to", FALSE);
3011 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
3014 if (account->set_autocc) {
3015 compose_entry_show(compose, COMPOSE_ENTRY_CC);
3016 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
3017 compose_entry_set(compose, account->auto_cc,
3020 if (account->set_autobcc) {
3021 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
3022 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
3023 compose_entry_set(compose, account->auto_bcc,
3026 if (account->set_autoreplyto) {
3027 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
3028 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
3029 compose_entry_set(compose, account->auto_replyto,
3030 COMPOSE_ENTRY_REPLY_TO);
3035 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
3036 menu_set_active(ifactory, "/Options/Sign", TRUE);
3038 menu_set_active(ifactory, "/Options/Sign", FALSE);
3039 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
3040 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3042 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3044 activate_privacy_system(compose, account);
3046 if (!init && compose->mode != COMPOSE_REDIRECT)
3047 compose_insert_sig(compose, TRUE);
3050 gboolean compose_check_for_valid_recipient(Compose *compose) {
3051 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3052 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3053 gboolean recipient_found = FALSE;
3057 /* free to and newsgroup list */
3058 slist_free_strings(compose->to_list);
3059 g_slist_free(compose->to_list);
3060 compose->to_list = NULL;
3062 slist_free_strings(compose->newsgroup_list);
3063 g_slist_free(compose->newsgroup_list);
3064 compose->newsgroup_list = NULL;
3066 /* search header entries for to and newsgroup entries */
3067 for (list = compose->header_list; list; list = list->next) {
3070 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3071 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3073 if (entry[0] != '\0') {
3074 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3075 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3076 compose->to_list = address_list_append(compose->to_list, entry);
3077 recipient_found = TRUE;
3080 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3081 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3082 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3083 recipient_found = TRUE;
3090 return recipient_found;
3093 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3097 if (compose_check_for_valid_recipient(compose) == FALSE) {
3098 alertpanel_error(_("Recipient is not specified."));
3102 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3103 if (*str == '\0' && check_subject == TRUE) {
3106 aval = alertpanel(_("Send"),
3107 _("Subject is empty. Send it anyway?"),
3108 _("Yes"), _("No"), NULL);
3109 if (aval != G_ALERTDEFAULT)
3116 gint compose_send(Compose *compose)
3123 compose_allow_user_actions (compose, FALSE);
3124 compose->sending = TRUE;
3126 if (compose_check_entries(compose, TRUE) == FALSE)
3129 val = compose_queue(compose, &msgnum, &folder);
3132 alertpanel_error(_("Could not queue message for sending"));
3137 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3138 compose->sending = FALSE;
3139 compose_close(compose);
3140 /* No more compose access in the normal codepath
3141 * after this point! */
3145 alertpanel_error(_("The message was queued but could not be "
3146 "sent.\nUse \"Send queued messages\" from "
3147 "the main window to retry."));
3148 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3149 compose->sending = FALSE;
3150 compose_allow_user_actions (compose, TRUE);
3155 msgpath = folder_item_fetch_msg(folder, msgnum);
3156 val = procmsg_send_message_queue(msgpath);
3159 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3160 compose->sending = FALSE;
3161 compose_allow_user_actions (compose, TRUE);
3163 folder_item_remove_msg(folder, msgnum);
3164 folder_item_scan(folder);
3169 folder_item_remove_msg(folder, msgnum);
3170 folder_item_scan(folder);
3171 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3172 compose_close(compose);
3174 alertpanel_error(_("The message was queued but could not be "
3175 "sent.\nUse \"Send queued messages\" from "
3176 "the main window to retry."));
3177 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3178 compose_allow_user_actions (compose, TRUE);
3179 compose->sending = FALSE;
3187 compose_allow_user_actions (compose, TRUE);
3188 compose->sending = FALSE;
3193 static gboolean compose_use_attach(Compose *compose)
3195 return gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL;
3198 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3201 gchar buf[BUFFSIZE];
3203 gboolean first_to_address;
3204 gboolean first_cc_address;
3206 ComposeHeaderEntry *headerentry;
3207 gchar *headerentryname;
3211 debug_print("Writing redirect header\n");
3213 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3214 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3216 first_to_address = TRUE;
3217 first_cc_address = TRUE;
3218 for (list = compose->header_list; list; list = list->next) {
3219 headerentry = ((ComposeHeaderEntry *)list->data);
3220 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3222 if (g_strcasecmp(headerentryname, cc_hdr) == 0
3223 || g_strcasecmp(headerentryname, to_hdr) == 0) {
3224 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3225 Xstrdup_a(str, str, return -1);
3227 if (str[0] != '\0') {
3228 compose_convert_header
3229 (buf, sizeof(buf), str,
3230 strlen("Resent-To") + 2, TRUE);
3231 if (g_strcasecmp(headerentryname, to_hdr) == 0) {
3232 if (first_to_address) {
3233 fprintf(fp, "Resent-To: ");
3234 first_to_address = FALSE;
3239 if (g_strcasecmp(headerentryname, cc_hdr) == 0) {
3240 if (first_cc_address) {
3242 fprintf(fp, "Resent-Cc: ");
3243 first_cc_address = FALSE;
3249 fprintf(fp, "%s", buf);
3253 /* if (!first_address) { */
3260 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3262 gchar buf[BUFFSIZE];
3264 /* struct utsname utsbuf; */
3266 g_return_val_if_fail(fp != NULL, -1);
3267 g_return_val_if_fail(compose->account != NULL, -1);
3268 g_return_val_if_fail(compose->account->address != NULL, -1);
3271 get_rfc822_date(buf, sizeof(buf));
3272 fprintf(fp, "Resent-Date: %s\n", buf);
3275 if (compose->account->name && *compose->account->name) {
3276 compose_convert_header
3277 (buf, sizeof(buf), compose->account->name,
3278 strlen("From: "), TRUE);
3279 fprintf(fp, "Resent-From: %s <%s>\n",
3280 buf, compose->account->address);
3282 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3285 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3287 Xstrdup_a(str, str, return -1);
3290 compose_convert_header(buf, sizeof(buf), str,
3291 strlen("Subject: "), FALSE);
3292 fprintf(fp, "Subject: %s\n", buf);
3296 /* Resent-Message-ID */
3297 if (compose->account->gen_msgid) {
3298 generate_msgid(buf, sizeof(buf));
3299 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3300 compose->msgid = g_strdup(buf);
3303 compose_redirect_write_headers_from_headerlist(compose, fp);
3305 /* separator between header and body */
3311 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3315 gchar buf[BUFFSIZE];
3317 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3318 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3322 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3323 /* should filter returnpath, delivered-to */
3324 if (g_strncasecmp(buf, "Return-Path:",
3325 strlen("Return-Path:")) == 0 ||
3326 g_strncasecmp(buf, "Delivered-To:",
3327 strlen("Delivered-To:")) == 0 ||
3328 g_strncasecmp(buf, "Received:",
3329 strlen("Received:")) == 0 ||
3330 g_strncasecmp(buf, "Subject:",
3331 strlen("Subject:")) == 0 ||
3332 g_strncasecmp(buf, "X-UIDL:",
3333 strlen("X-UIDL:")) == 0)
3336 if (fputs(buf, fdest) == -1)
3339 if (!prefs_common.redirect_keep_from) {
3340 if (g_strncasecmp(buf, "From:",
3341 strlen("From:")) == 0) {
3342 fputs(" (by way of ", fdest);
3343 if (compose->account->name
3344 && *compose->account->name) {
3345 compose_convert_header
3347 compose->account->name,
3350 fprintf(fdest, "%s <%s>",
3352 compose->account->address);
3354 fprintf(fdest, "%s",
3355 compose->account->address);
3360 if (fputs("\n", fdest) == -1)
3364 compose_redirect_write_headers(compose, fdest);
3366 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3367 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
3380 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
3384 const gchar *out_codeset;
3385 EncodingType encoding;
3386 MimeInfo *mimemsg, *mimetext;
3388 /* create message MimeInfo */
3389 mimemsg = procmime_mimeinfo_new();
3390 mimemsg->type = MIMETYPE_MESSAGE;
3391 mimemsg->subtype = g_strdup("rfc822");
3392 mimemsg->content = MIMECONTENT_MEM;
3393 mimemsg->data.mem = compose_get_header(compose);
3395 /* Create text part MimeInfo */
3396 /* get all composed text */
3397 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3398 if (is_ascii_str(chars)) {
3401 out_codeset = CS_US_ASCII;
3402 encoding = ENC_7BIT;
3404 const gchar *src_codeset;
3406 out_codeset = conv_get_outgoing_charset_str();
3407 if (!g_strcasecmp(out_codeset, CS_US_ASCII))
3408 out_codeset = CS_ISO_8859_1;
3410 if (prefs_common.encoding_method == CTE_BASE64)
3411 encoding = ENC_BASE64;
3412 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3413 encoding = ENC_QUOTED_PRINTABLE;
3414 else if (prefs_common.encoding_method == CTE_8BIT)
3415 encoding = ENC_8BIT;
3417 encoding = procmime_get_encoding_for_charset(out_codeset);
3419 src_codeset = conv_get_current_charset_str();
3420 /* if current encoding is US-ASCII, set it the same as
3421 outgoing one to prevent code conversion failure */
3422 if (!g_strcasecmp(src_codeset, CS_US_ASCII))
3423 src_codeset = out_codeset;
3425 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3426 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3428 if (action == COMPOSE_WRITE_FOR_SEND) {
3429 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3435 msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
3437 "Send it anyway?"), src_codeset, out_codeset);
3438 aval = alertpanel_with_type
3439 (_("Error"), msg, _("Yes"), _("+No"), NULL, NULL, ALERT_ERROR);
3442 if (aval != G_ALERTDEFAULT) {
3447 out_codeset = src_codeset;
3453 out_codeset = src_codeset;
3459 if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
3460 if (!strncmp(buf, "From ", sizeof("From ")-1) ||
3461 strstr(buf, "\nFrom ") != NULL) {
3462 encoding = ENC_QUOTED_PRINTABLE;
3466 mimetext = procmime_mimeinfo_new();
3467 mimetext->content = MIMECONTENT_MEM;
3468 mimetext->data.mem = buf;
3469 mimetext->type = MIMETYPE_TEXT;
3470 mimetext->subtype = g_strdup("plain");
3471 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
3472 g_strdup(out_codeset));
3473 /* protect trailing spaces when signing message */
3474 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
3475 privacy_system_can_sign(compose->privacy_system))
3476 if (encoding == ENC_7BIT)
3477 encoding = ENC_QUOTED_PRINTABLE;
3478 else if (encoding == ENC_8BIT)
3479 encoding = ENC_BASE64;
3480 if (encoding != ENC_UNKNOWN)
3481 procmime_encode_content(mimetext, encoding);
3483 /* append attachment parts */
3484 if (compose_use_attach(compose)) {
3485 MimeInfo *mimempart;
3487 mimempart = procmime_mimeinfo_new();
3488 mimempart->content = MIMECONTENT_EMPTY;
3489 mimempart->type = MIMETYPE_MULTIPART;
3490 mimempart->subtype = g_strdup("mixed");
3491 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
3492 generate_mime_boundary(NULL));
3494 mimetext->disposition = DISPOSITIONTYPE_INLINE;
3496 g_node_append(mimempart->node, mimetext->node);
3497 g_node_append(mimemsg->node, mimempart->node);
3499 compose_add_attachments(compose, mimempart);
3501 g_node_append(mimemsg->node, mimetext->node);
3503 /* sign message if sending */
3504 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
3505 privacy_system_can_sign(compose->privacy_system))
3506 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
3509 procmime_write_mimeinfo(mimemsg, fp);
3511 procmime_mimeinfo_free_all(mimemsg);
3516 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3522 if ((fp = fopen(file, "wb")) == NULL) {
3523 FILE_OP_ERROR(file, "fopen");
3527 /* chmod for security */
3528 if (change_file_mode_rw(fp, file) < 0) {
3529 FILE_OP_ERROR(file, "chmod");
3530 g_warning("can't change file mode\n");
3533 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3536 len = strlen(chars);
3537 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3538 FILE_OP_ERROR(file, "fwrite");
3547 if (fclose(fp) == EOF) {
3548 FILE_OP_ERROR(file, "fclose");
3555 static gint compose_remove_reedit_target(Compose *compose)
3558 MsgInfo *msginfo = compose->targetinfo;
3560 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3561 if (!msginfo) return -1;
3563 item = msginfo->folder;
3564 g_return_val_if_fail(item != NULL, -1);
3566 if (procmsg_msg_exist(msginfo) &&
3567 (item->stype == F_DRAFT || item->stype == F_QUEUE
3568 || msginfo == compose->autosaved_draft)) {
3569 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3570 g_warning("can't remove the old message\n");
3578 void compose_remove_draft(Compose *compose)
3581 MsgInfo *msginfo = compose->targetinfo;
3582 drafts = account_get_special_folder(compose->account, F_DRAFT);
3584 if (procmsg_msg_exist(msginfo)) {
3585 folder_item_remove_msg(drafts, msginfo->msgnum);
3590 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3592 return compose_queue_sub (compose, msgnum, item, FALSE);
3594 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3601 static gboolean lock = FALSE;
3602 PrefsAccount *mailac = NULL, *newsac = NULL;
3604 debug_print("queueing message...\n");
3605 g_return_val_if_fail(compose->account != NULL, -1);
3609 if (compose_check_entries(compose, check_subject) == FALSE) {
3614 if (!compose->to_list && !compose->newsgroup_list) {
3615 g_warning("can't get recipient list.");
3620 if (compose->to_list) {
3621 if (compose->account->protocol != A_NNTP)
3622 mailac = compose->account;
3623 else if (cur_account && cur_account->protocol != A_NNTP)
3624 mailac = cur_account;
3625 else if (!(mailac = compose_current_mail_account())) {
3627 alertpanel_error(_("No account for sending mails available!"));
3632 if (compose->newsgroup_list) {
3633 if (compose->account->protocol == A_NNTP)
3634 newsac = compose->account;
3635 else if (!newsac->protocol != A_NNTP) {
3637 alertpanel_error(_("No account for posting news available!"));
3642 if (prefs_common.linewrap_at_send)
3643 compose_wrap_line_all(compose);
3645 /* write queue header */
3646 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
3647 G_DIR_SEPARATOR, compose);
3648 if ((fp = fopen(tmp, "wb")) == NULL) {
3649 FILE_OP_ERROR(tmp, "fopen");
3654 if (change_file_mode_rw(fp, tmp) < 0) {
3655 FILE_OP_ERROR(tmp, "chmod");
3656 g_warning("can't change file mode\n");
3659 /* queueing variables */
3660 fprintf(fp, "AF:\n");
3661 fprintf(fp, "NF:0\n");
3662 fprintf(fp, "PS:10\n");
3663 fprintf(fp, "SRH:1\n");
3664 fprintf(fp, "SFN:\n");
3665 fprintf(fp, "DSR:\n");
3667 fprintf(fp, "MID:<%s>\n", compose->msgid);
3669 fprintf(fp, "MID:\n");
3670 fprintf(fp, "CFG:\n");
3671 fprintf(fp, "PT:0\n");
3672 fprintf(fp, "S:%s\n", compose->account->address);
3673 fprintf(fp, "RQ:\n");
3675 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3677 fprintf(fp, "SSV:\n");
3679 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3681 fprintf(fp, "NSV:\n");
3682 fprintf(fp, "SSH:\n");
3683 /* write recepient list */
3684 if (compose->to_list) {
3685 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
3686 for (cur = compose->to_list->next; cur != NULL;
3688 fprintf(fp, ",<%s>", (gchar *)cur->data);
3691 /* write newsgroup list */
3692 if (compose->newsgroup_list) {
3694 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3695 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3696 fprintf(fp, ",%s", (gchar *)cur->data);
3699 /* Sylpheed account IDs */
3701 fprintf(fp, "MAID:%d\n", mailac->account_id);
3703 fprintf(fp, "NAID:%d\n", newsac->account_id);
3705 if (compose->privacy_system != NULL) {
3706 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
3707 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
3708 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
3709 if (compose->use_encryption) {
3712 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
3713 if (encdata != NULL)
3714 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
3720 /* Save copy folder */
3721 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3722 gchar *savefolderid;
3724 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3725 fprintf(fp, "SCF:%s\n", savefolderid);
3726 g_free(savefolderid);
3728 /* Message-ID of message replying to */
3729 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
3732 folderid = folder_item_get_identifier(compose->replyinfo->folder);
3733 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
3736 /* Message-ID of message forwarding to */
3737 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
3740 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
3741 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
3746 if (compose->redirect_filename != NULL) {
3747 if (compose_redirect_write_to_file(compose, fp) < 0) {
3755 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND) < 0) {
3764 if (fclose(fp) == EOF) {
3765 FILE_OP_ERROR(tmp, "fclose");
3771 queue = account_get_special_folder(compose->account, F_QUEUE);
3773 g_warning("can't find queue folder\n");
3778 folder_item_scan(queue);
3779 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
3780 g_warning("can't queue the message\n");
3788 if (compose->mode == COMPOSE_REEDIT) {
3789 compose_remove_reedit_target(compose);
3792 if ((msgnum != NULL) && (item != NULL)) {
3800 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
3803 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3806 struct stat statbuf;
3807 gchar *type, *subtype;
3809 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3811 mimepart = procmime_mimeinfo_new();
3812 mimepart->content = MIMECONTENT_FILE;
3813 mimepart->data.filename = g_strdup(ainfo->file);
3814 mimepart->offset = 0;
3816 stat(ainfo->file, &statbuf);
3817 mimepart->length = statbuf.st_size;
3819 type = g_strdup(ainfo->content_type);
3821 if (!strchr(type, '/')) {
3823 type = g_strdup("application/octet-stream");
3826 subtype = strchr(type, '/') + 1;
3827 *(subtype - 1) = '\0';
3828 mimepart->type = procmime_get_media_type(type);
3829 mimepart->subtype = g_strdup(subtype);
3832 if (mimepart->type == MIMETYPE_MESSAGE &&
3833 !g_strcasecmp(mimepart->subtype, "rfc822")) {
3834 mimepart->disposition = DISPOSITIONTYPE_INLINE;
3836 g_hash_table_insert(mimepart->typeparameters,
3837 g_strdup("name"), g_strdup(ainfo->name));
3838 g_hash_table_insert(mimepart->dispositionparameters,
3839 g_strdup("filename"), g_strdup(ainfo->name));
3840 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
3843 if (compose->use_signing) {
3844 if (ainfo->encoding == ENC_7BIT)
3845 ainfo->encoding = ENC_QUOTED_PRINTABLE;
3846 else if (ainfo->encoding == ENC_8BIT)
3847 ainfo->encoding = ENC_BASE64;
3850 procmime_encode_content(mimepart, ainfo->encoding);
3852 g_node_append(parent->node, mimepart->node);
3856 #define QUOTE_IF_REQUIRED(out, str) \
3858 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3862 len = strlen(str) + 3; \
3863 if ((__tmp = alloca(len)) == NULL) { \
3864 g_warning("can't allocate memory\n"); \
3865 g_string_free(header, TRUE); \
3868 g_snprintf(__tmp, len, "\"%s\"", str); \
3873 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3874 g_warning("can't allocate memory\n"); \
3875 g_string_free(header, TRUE); \
3878 strcpy(__tmp, str); \
3884 #define IS_IN_CUSTOM_HEADER(header) \
3885 (compose->account->add_customhdr && \
3886 custom_header_find(compose->account->customhdr_list, header) != NULL)
3888 static void compose_add_headerfield_from_headerlist(Compose *compose,
3890 const gchar *fieldname,
3891 const gchar *seperator)
3893 gchar *str, *fieldname_w_colon, *trans_fieldname;
3894 gboolean add_field = FALSE;
3896 ComposeHeaderEntry *headerentry;
3897 gchar * headerentryname;
3900 if (IS_IN_CUSTOM_HEADER(fieldname))
3903 debug_print("Adding %s-fields\n", fieldname);
3905 fieldstr = g_string_sized_new(64);
3907 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
3908 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
3910 for (list = compose->header_list; list; list = list->next) {
3911 headerentry = ((ComposeHeaderEntry *)list->data);
3912 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3914 if (!g_strcasecmp(trans_fieldname, headerentryname)) {
3915 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
3917 if (str[0] != '\0') {
3919 g_string_append(fieldstr, seperator);
3920 g_string_append(fieldstr, str);
3929 buf = g_new0(gchar, fieldstr->len * 4 + 256);
3930 compose_convert_header
3931 (buf, fieldstr->len * 4 + 256, fieldstr->str,
3932 strlen(fieldname) + 2, TRUE);
3933 g_string_sprintfa(header, "%s: %s\n", fieldname, buf);
3937 g_free(fieldname_w_colon);
3938 g_string_free(fieldstr, TRUE);
3943 static gchar *compose_get_header(Compose *compose)
3945 gchar buf[BUFFSIZE];
3949 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3952 /* struct utsname utsbuf; */
3954 g_return_val_if_fail(compose->account != NULL, NULL);
3955 g_return_val_if_fail(compose->account->address != NULL, NULL);
3957 header = g_string_sized_new(64);
3960 if (compose->account->add_date) {
3961 get_rfc822_date(buf, sizeof(buf));
3962 g_string_sprintfa(header, "Date: %s\n", buf);
3966 if (compose->account->name && *compose->account->name) {
3967 compose_convert_header
3968 (buf, sizeof(buf), compose->account->name,
3969 strlen("From: "), TRUE);
3970 QUOTE_IF_REQUIRED(name, buf);
3971 g_string_sprintfa(header, "From: %s <%s>\n",
3972 name, compose->account->address);
3974 g_string_sprintfa(header, "From: %s\n", compose->account->address);
3977 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
3980 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
3983 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
3986 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
3989 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3990 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3993 tmpstr = g_strdup(str);
3994 if (tmpstr == NULL) {
3995 g_string_free(header, TRUE);
4000 compose_convert_header(buf, sizeof(buf), str,
4001 strlen("Subject: "), FALSE);
4002 g_string_sprintfa(header, "Subject: %s\n", buf);
4008 if (compose->account->gen_msgid) {
4009 generate_msgid(buf, sizeof(buf));
4010 g_string_sprintfa(header, "Message-ID: <%s>\n", buf);
4011 compose->msgid = g_strdup(buf);
4014 if (compose->remove_references == FALSE) {
4016 if (compose->inreplyto && compose->to_list)
4017 g_string_sprintfa(header, "In-Reply-To: <%s>\n", compose->inreplyto);
4020 if (compose->references)
4021 g_string_sprintfa(header, "References: %s\n", compose->references);
4025 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
4028 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4031 if (compose->account->organization &&
4032 !IS_IN_CUSTOM_HEADER("Organization")) {
4033 compose_convert_header(buf, sizeof(buf),
4034 compose->account->organization,
4035 strlen("Organization: "), FALSE);
4036 g_string_sprintfa(header, "Organization: %s\n", buf);
4039 /* Program version and system info */
4040 /* uname(&utsbuf); */
4041 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4042 !compose->newsgroup_list) {
4043 g_string_sprintfa(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4045 gtk_major_version, gtk_minor_version, gtk_micro_version,
4047 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4049 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4050 g_string_sprintfa(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4052 gtk_major_version, gtk_minor_version, gtk_micro_version,
4054 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4057 /* custom headers */
4058 if (compose->account->add_customhdr) {
4061 for (cur = compose->account->customhdr_list; cur != NULL;
4063 CustomHeader *chdr = (CustomHeader *)cur->data;
4065 if (custom_header_is_allowed(chdr->name)) {
4066 compose_convert_header
4068 chdr->value ? chdr->value : "",
4069 strlen(chdr->name) + 2, FALSE);
4070 g_string_sprintfa(header, "%s: %s\n", chdr->name, buf);
4076 switch (compose->priority) {
4077 case PRIORITY_HIGHEST: g_string_sprintfa(header, "Importance: high\n"
4078 "X-Priority: 1 (Highest)\n");
4080 case PRIORITY_HIGH: g_string_sprintfa(header, "Importance: high\n"
4081 "X-Priority: 2 (High)\n");
4083 case PRIORITY_NORMAL: break;
4084 case PRIORITY_LOW: g_string_sprintfa(header, "Importance: low\n"
4085 "X-Priority: 4 (Low)\n");
4087 case PRIORITY_LOWEST: g_string_sprintfa(header, "Importance: low\n"
4088 "X-Priority: 5 (Lowest)\n");
4090 default: debug_print("compose: priority unknown : %d\n",
4094 /* Request Return Receipt */
4095 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4096 if (compose->return_receipt) {
4097 if (compose->account->name
4098 && *compose->account->name) {
4099 compose_convert_header(buf, sizeof(buf),
4100 compose->account->name,
4101 strlen("Disposition-Notification-To: "),
4103 g_string_sprintfa(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4105 g_string_sprintfa(header, "Disposition-Notification-To: %s\n", compose->account->address);
4109 /* get special headers */
4110 for (list = compose->header_list; list; list = list->next) {
4111 ComposeHeaderEntry *headerentry;
4114 gchar *headername_wcolon;
4115 gchar *headername_trans;
4118 gboolean standard_header = FALSE;
4120 headerentry = ((ComposeHeaderEntry *)list->data);
4122 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4123 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4128 if (!strstr(tmp, ":")) {
4129 headername_wcolon = g_strconcat(tmp, ":", NULL);
4130 headername = g_strdup(tmp);
4132 headername_wcolon = g_strdup(tmp);
4133 headername = g_strdup(strtok(tmp, ":"));
4137 headervalue = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4138 subst_char(headervalue, '\r', ' ');
4139 subst_char(headervalue, '\n', ' ');
4140 string = std_headers;
4141 while (*string != NULL) {
4142 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4143 if (!strcmp(headername_trans,headername_wcolon))
4144 standard_header = TRUE;
4147 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4148 g_string_sprintfa(header, "%s %s\n", headername_wcolon, headervalue);
4151 g_free(headername_wcolon);
4155 g_string_free(header, FALSE);
4160 #undef IS_IN_CUSTOM_HEADER
4162 static void compose_convert_header(gchar *dest, gint len, gchar *src,
4163 gint header_len, gboolean addr_field)
4165 g_return_if_fail(src != NULL);
4166 g_return_if_fail(dest != NULL);
4168 if (len < 1) return;
4170 subst_char(src, '\n', ' ');
4171 subst_char(src, '\r', ' ');
4174 conv_encode_header(dest, len, src, header_len, addr_field);
4177 static void compose_create_header_entry(Compose *compose)
4179 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4183 GList *combo_list = NULL;
4184 gchar **string, *header = NULL;
4185 ComposeHeaderEntry *headerentry;
4186 gboolean standard_header = FALSE;
4188 headerentry = g_new0(ComposeHeaderEntry, 1);
4191 combo = gtk_combo_new();
4193 while(*string != NULL) {
4194 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4197 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4198 g_list_free(combo_list);
4199 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4200 gtk_widget_show(combo);
4201 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4202 if (compose->header_last) {
4203 gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4205 while (*string != NULL) {
4206 if (!strcmp(*string, last_header_entry))
4207 standard_header = TRUE;
4210 if (standard_header)
4211 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4213 if (!compose->header_last || !standard_header) {
4214 switch(compose->account->protocol) {
4216 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4219 header = prefs_common.trans_hdr ? _("To:") : "To:";
4224 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4227 entry = gtk_entry_new();
4228 gtk_widget_show(entry);
4229 gtk_table_attach(GTK_TABLE(compose->header_table), entry, 1, 2, compose->header_nextrow, compose->header_nextrow+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
4231 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4232 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4233 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4234 gtk_signal_connect(GTK_OBJECT(entry), "button-press-event",
4235 GTK_SIGNAL_FUNC(compose_headerentry_button_pressed),
4238 address_completion_register_entry(GTK_ENTRY(entry));
4240 headerentry->compose = compose;
4241 headerentry->combo = combo;
4242 headerentry->entry = entry;
4243 headerentry->headernum = compose->header_nextrow;
4245 compose->header_nextrow++;
4246 compose->header_last = headerentry;
4249 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4251 ComposeHeaderEntry *last_header;
4253 last_header = compose->header_last;
4255 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4256 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4259 static GtkWidget *compose_create_header(Compose *compose)
4263 GtkWidget *from_optmenu_hbox;
4264 #if 0 /* NEW COMPOSE GUI */
4265 GtkWidget *to_entry;
4267 GtkWidget *newsgroups_entry;
4268 GtkWidget *newsgroups_hbox;
4270 GtkWidget *header_scrolledwin;
4271 GtkWidget *header_table;
4272 #if 0 /* NEW COMPOSE GUI */
4273 GtkWidget *cc_entry;
4275 GtkWidget *bcc_entry;
4276 GtkWidget *bcc_hbox;
4277 GtkWidget *reply_entry;
4278 GtkWidget *reply_hbox;
4279 GtkWidget *followup_entry;
4280 GtkWidget *followup_hbox;
4285 /* header labels and entries */
4286 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4287 gtk_widget_show(header_scrolledwin);
4288 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4290 header_table = gtk_table_new(2, 2, FALSE);
4291 gtk_widget_show(header_table);
4292 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4293 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4294 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4297 /* option menu for selecting accounts */
4298 hbox = gtk_hbox_new(FALSE, 0);
4299 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4300 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4301 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4303 from_optmenu_hbox = compose_account_option_menu_create(compose);
4304 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4305 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4306 #if 0 /* NEW COMPOSE GUI */
4307 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4311 compose->header_table = header_table;
4312 compose->header_list = NULL;
4313 compose->header_nextrow = count;
4315 compose_create_header_entry(compose);
4317 #if 0 /* NEW COMPOSE GUI */
4318 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4320 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4321 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4322 &count, "Newsgroups:", FALSE);
4323 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4325 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4327 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4329 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4330 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4332 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4333 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4335 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4336 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4337 "Followup-To:", FALSE);
4338 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4340 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4342 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4343 GTK_SIGNAL_FUNC(to_activated), compose);
4344 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4345 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4346 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4347 GTK_SIGNAL_FUNC(subject_activated), compose);
4348 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4349 GTK_SIGNAL_FUNC(cc_activated), compose);
4350 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4351 GTK_SIGNAL_FUNC(bcc_activated), compose);
4352 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4353 GTK_SIGNAL_FUNC(replyto_activated), compose);
4354 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4355 GTK_SIGNAL_FUNC(followupto_activated), compose);
4357 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4358 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4359 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4360 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4361 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4362 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4363 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4364 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4365 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4366 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4367 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4368 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4369 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4370 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4373 compose->table = NULL;
4374 #if 0 /* NEW COMPOSE GUI */
4375 compose->table = table;
4376 compose->to_hbox = to_hbox;
4377 compose->to_entry = to_entry;
4378 compose->newsgroups_hbox = newsgroups_hbox;
4379 compose->newsgroups_entry = newsgroups_entry;
4381 #if 0 /* NEW COMPOSE GUI */
4382 compose->cc_hbox = cc_hbox;
4383 compose->cc_entry = cc_entry;
4384 compose->bcc_hbox = bcc_hbox;
4385 compose->bcc_entry = bcc_entry;
4386 compose->reply_hbox = reply_hbox;
4387 compose->reply_entry = reply_entry;
4388 compose->followup_hbox = followup_hbox;
4389 compose->followup_entry = followup_entry;
4392 return header_scrolledwin ;
4395 GtkWidget *compose_create_attach(Compose *compose)
4397 gchar *titles[N_ATTACH_COLS];
4400 GtkWidget *attach_scrwin;
4401 GtkWidget *attach_clist;
4403 titles[COL_MIMETYPE] = _("MIME type");
4404 titles[COL_SIZE] = _("Size");
4405 titles[COL_NAME] = _("Name");
4407 /* attachment list */
4408 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4409 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4410 GTK_POLICY_AUTOMATIC,
4412 gtk_widget_set_usize(attach_scrwin, -1, 80);
4414 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4415 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4417 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4418 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4419 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4420 GTK_SELECTION_EXTENDED);
4421 for (i = 0; i < N_ATTACH_COLS; i++)
4422 GTK_WIDGET_UNSET_FLAGS
4423 (GTK_CLIST(attach_clist)->column[i].button,
4425 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4427 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4428 GTK_SIGNAL_FUNC(attach_selected), compose);
4429 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4430 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4431 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4432 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4435 gtk_drag_dest_set(attach_clist,
4436 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4437 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4438 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4439 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4442 compose->attach_scrwin = attach_scrwin;
4443 compose->attach_clist = attach_clist;
4445 return attach_scrwin;
4448 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4449 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4451 static GtkWidget *compose_create_others(Compose *compose)
4454 GtkWidget *savemsg_checkbtn;
4455 GtkWidget *savemsg_entry;
4456 GtkWidget *savemsg_select;
4459 gchar *folderidentifier;
4461 /* Table for settings */
4462 table = gtk_table_new(3, 1, FALSE);
4463 gtk_widget_show(table);
4464 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4467 /* Save Message to folder */
4468 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4469 gtk_widget_show(savemsg_checkbtn);
4470 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4471 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4472 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4474 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4475 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4477 savemsg_entry = gtk_entry_new();
4478 gtk_widget_show(savemsg_entry);
4479 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4480 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4481 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4482 folderidentifier = folder_item_get_identifier(account_get_special_folder
4483 (compose->account, F_OUTBOX));
4484 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4485 g_free(folderidentifier);
4488 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4489 gtk_widget_show (savemsg_select);
4490 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4491 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4492 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4497 compose->savemsg_checkbtn = savemsg_checkbtn;
4498 compose->savemsg_entry = savemsg_entry;
4503 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4505 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4506 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4509 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4514 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4517 path = folder_item_get_identifier(dest);
4519 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4523 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4529 GtkWidget *handlebox;
4531 GtkWidget *notebook;
4536 GtkWidget *subject_hbox;
4537 GtkWidget *subject_frame;
4538 GtkWidget *subject_entry;
4542 GtkWidget *edit_vbox;
4543 GtkWidget *ruler_hbox;
4545 GtkWidget *scrolledwin;
4548 UndoMain *undostruct;
4550 gchar *titles[N_ATTACH_COLS];
4551 guint n_menu_entries;
4552 GtkStyle *style, *new_style;
4555 gboolean success[1];
4556 GtkWidget *popupmenu;
4557 GtkItemFactory *popupfactory;
4558 GtkItemFactory *ifactory;
4559 GtkWidget *tmpl_menu;
4563 GtkAspell * gtkaspell = NULL;
4566 static GdkGeometry geometry;
4568 g_return_val_if_fail(account != NULL, NULL);
4570 debug_print("Creating compose window...\n");
4571 compose = g_new0(Compose, 1);
4573 titles[COL_MIMETYPE] = _("MIME type");
4574 titles[COL_SIZE] = _("Size");
4575 titles[COL_NAME] = _("Name");
4577 compose->account = account;
4579 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4580 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4581 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4582 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4584 if (!geometry.max_width) {
4585 geometry.max_width = gdk_screen_width();
4586 geometry.max_height = gdk_screen_height();
4588 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4589 &geometry, GDK_HINT_MAX_SIZE);
4590 gtk_widget_set_uposition(window, prefs_common.compose_x,
4591 prefs_common.compose_y);
4592 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4593 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4594 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4595 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4596 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4597 gtk_widget_realize(window);
4599 gtkut_widget_set_composer_icon(window);
4601 vbox = gtk_vbox_new(FALSE, 0);
4602 gtk_container_add(GTK_CONTAINER(window), vbox);
4604 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4605 menubar = menubar_create(window, compose_entries,
4606 n_menu_entries, "<Compose>", compose);
4607 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4609 handlebox = gtk_handle_box_new();
4610 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4612 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
4615 vbox2 = gtk_vbox_new(FALSE, 2);
4616 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4617 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4620 notebook = gtk_notebook_new();
4621 gtk_widget_set_usize(notebook, -1, 130);
4622 gtk_widget_show(notebook);
4624 /* header labels and entries */
4625 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4626 /* attachment list */
4627 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4629 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4632 subject_hbox = gtk_hbox_new(FALSE, 0);
4633 gtk_widget_show(subject_hbox);
4635 subject_frame = gtk_frame_new(NULL);
4636 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4637 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4638 gtk_widget_show(subject_frame);
4640 subject = gtk_hbox_new(FALSE, 0);
4641 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4642 gtk_widget_show(subject);
4644 label = gtk_label_new(_("Subject:"));
4645 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4646 gtk_widget_show(label);
4648 subject_entry = gtk_entry_new();
4649 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4650 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4651 gtk_widget_show(subject_entry);
4652 compose->subject_entry = subject_entry;
4653 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4655 edit_vbox = gtk_vbox_new(FALSE, 0);
4657 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4660 ruler_hbox = gtk_hbox_new(FALSE, 0);
4661 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4663 ruler = gtk_shruler_new();
4664 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4665 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4667 gtk_widget_set_usize(ruler_hbox, 1, -1);
4670 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4671 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4672 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4673 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4674 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4676 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4677 (GTK_SCROLLED_WINDOW(scrolledwin)),
4678 gtk_scrolled_window_get_vadjustment
4679 (GTK_SCROLLED_WINDOW(scrolledwin)));
4680 GTK_STEXT(text)->default_tab_width = 8;
4681 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4683 if (prefs_common.block_cursor) {
4684 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4687 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4689 gtk_signal_connect(GTK_OBJECT(text), "changed",
4690 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4691 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4692 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4693 gtk_signal_connect(GTK_OBJECT(text), "activate",
4694 GTK_SIGNAL_FUNC(text_activated), compose);
4695 gtk_signal_connect(GTK_OBJECT(text), "insert_text",
4696 GTK_SIGNAL_FUNC(text_inserted), compose);
4697 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4698 GTK_SIGNAL_FUNC(compose_button_press_cb),
4701 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4702 GTK_SIGNAL_FUNC(compose_key_press_cb),
4705 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4706 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4710 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4711 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4712 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4713 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4715 gtk_widget_show_all(vbox);
4717 /* pane between attach clist and text */
4718 paned = gtk_vpaned_new();
4719 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4720 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4721 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4722 gtk_paned_add1(GTK_PANED(paned), notebook);
4723 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4724 gtk_widget_show_all(paned);
4726 style = gtk_widget_get_style(text);
4728 /* workaround for the slow down of GtkSText when using Pixmap theme */
4729 if (style->engine) {
4730 GtkThemeEngine *engine;
4732 engine = style->engine;
4733 style->engine = NULL;
4734 new_style = gtk_style_copy(style);
4735 style->engine = engine;
4737 new_style = gtk_style_copy(style);
4739 if (prefs_common.textfont) {
4742 if ((font = gtkut_font_load(prefs_common.textfont)) != NULL) {
4743 gdk_font_unref(new_style->font);
4744 new_style->font = font;
4748 gtk_widget_set_style(text, new_style);
4750 color[0] = quote_color;
4751 cmap = gdk_window_get_colormap(window->window);
4752 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4753 if (success[0] == FALSE) {
4754 g_warning("Compose: color allocation failed.\n");
4755 style = gtk_widget_get_style(text);
4756 quote_color = style->black;
4759 n_entries = sizeof(compose_popup_entries) /
4760 sizeof(compose_popup_entries[0]);
4761 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4762 "<Compose>", &popupfactory,
4765 ifactory = gtk_item_factory_from_widget(menubar);
4766 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4767 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4768 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
4770 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4772 undostruct = undo_init(text);
4773 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4776 address_completion_start(window);
4778 compose->window = window;
4779 compose->vbox = vbox;
4780 compose->menubar = menubar;
4781 compose->handlebox = handlebox;
4783 compose->vbox2 = vbox2;
4785 compose->paned = paned;
4787 compose->edit_vbox = edit_vbox;
4788 compose->ruler_hbox = ruler_hbox;
4789 compose->ruler = ruler;
4790 compose->scrolledwin = scrolledwin;
4791 compose->text = text;
4793 compose->focused_editable = NULL;
4795 compose->popupmenu = popupmenu;
4796 compose->popupfactory = popupfactory;
4798 compose->tmpl_menu = tmpl_menu;
4800 compose->mode = mode;
4802 compose->targetinfo = NULL;
4803 compose->replyinfo = NULL;
4804 compose->fwdinfo = NULL;
4806 compose->replyto = NULL;
4808 compose->bcc = NULL;
4809 compose->followup_to = NULL;
4811 compose->ml_post = NULL;
4813 compose->inreplyto = NULL;
4814 compose->references = NULL;
4815 compose->msgid = NULL;
4816 compose->boundary = NULL;
4818 compose->autowrap = prefs_common.autowrap;
4820 compose->use_signing = FALSE;
4821 compose->use_encryption = FALSE;
4822 compose->privacy_system = NULL;
4824 compose->modified = FALSE;
4826 compose->return_receipt = FALSE;
4828 compose->to_list = NULL;
4829 compose->newsgroup_list = NULL;
4831 compose->undostruct = undostruct;
4833 compose->sig_str = NULL;
4835 compose->exteditor_file = NULL;
4836 compose->exteditor_pid = -1;
4837 compose->exteditor_readdes = -1;
4838 compose->exteditor_tag = -1;
4839 compose->draft_timeout_tag = -1;
4842 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4843 if (mode != COMPOSE_REDIRECT) {
4844 if (prefs_common.enable_aspell && prefs_common.dictionary &&
4845 strcmp(prefs_common.dictionary, _("None"))) {
4846 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
4847 prefs_common.dictionary,
4848 conv_get_current_charset_str(),
4849 prefs_common.misspelled_col,
4850 prefs_common.check_while_typing,
4851 prefs_common.use_alternate,
4854 alertpanel_error(_("Spell checker could not "
4856 gtkaspell_checkers_strerror());
4857 gtkaspell_checkers_reset_error();
4860 GtkWidget *menuitem;
4862 if (!gtkaspell_set_sug_mode(gtkaspell,
4863 prefs_common.aspell_sugmode)) {
4864 debug_print("Aspell: could not set "
4865 "suggestion mode %s\n",
4866 gtkaspell_checkers_strerror());
4867 gtkaspell_checkers_reset_error();
4870 menuitem = gtk_item_factory_get_item(ifactory,
4871 "/Spelling/Spelling Configuration");
4872 gtkaspell_populate_submenu(gtkaspell, menuitem);
4873 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4877 compose->gtkaspell = gtkaspell;
4880 compose_select_account(compose, account, TRUE);
4882 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
4883 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
4884 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4886 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
4887 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4889 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
4890 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4893 if (account->protocol != A_NNTP)
4894 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4896 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4898 addressbook_set_target_compose(compose);
4900 if (mode != COMPOSE_REDIRECT)
4901 compose_set_template_menu(compose);
4903 GtkWidget *menuitem;
4904 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4905 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
4908 compose_list = g_list_append(compose_list, compose);
4910 if (!prefs_common.show_ruler)
4911 gtk_widget_hide(ruler_hbox);
4914 compose->priority = PRIORITY_NORMAL;
4915 compose_update_priority_menu_item(compose);
4918 compose_update_actions_menu(compose);
4920 /* Privacy Systems menu */
4921 compose_update_privacy_systems_menu(compose);
4923 activate_privacy_system(compose, account);
4924 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
4925 gtk_widget_show(window);
4930 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4936 gint num = 0, def_menu = 0;
4938 accounts = account_get_list();
4939 g_return_val_if_fail(accounts != NULL, NULL);
4941 hbox = gtk_hbox_new(FALSE, 0);
4942 optmenu = gtk_option_menu_new();
4943 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4944 menu = gtk_menu_new();
4946 for (; accounts != NULL; accounts = accounts->next, num++) {
4947 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4948 GtkWidget *menuitem;
4951 if (ac == compose->account) def_menu = num;
4954 name = g_strdup_printf("%s: %s <%s>",
4956 ac->name, ac->address);
4958 name = g_strdup_printf("%s: %s",
4959 ac->account_name, ac->address);
4960 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
4962 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4963 GTK_SIGNAL_FUNC(account_activated),
4967 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4968 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4973 static void compose_set_priority_cb(gpointer data,
4977 Compose *compose = (Compose *) data;
4978 compose->priority = action;
4981 static void compose_update_priority_menu_item(Compose * compose)
4983 GtkItemFactory *ifactory;
4984 GtkWidget *menuitem = NULL;
4986 ifactory = gtk_item_factory_from_widget(compose->menubar);
4988 switch (compose->priority) {
4989 case PRIORITY_HIGHEST:
4990 menuitem = gtk_item_factory_get_item
4991 (ifactory, "/Options/Priority/Highest");
4994 menuitem = gtk_item_factory_get_item
4995 (ifactory, "/Options/Priority/High");
4997 case PRIORITY_NORMAL:
4998 menuitem = gtk_item_factory_get_item
4999 (ifactory, "/Options/Priority/Normal");
5002 menuitem = gtk_item_factory_get_item
5003 (ifactory, "/Options/Priority/Low");
5005 case PRIORITY_LOWEST:
5006 menuitem = gtk_item_factory_get_item
5007 (ifactory, "/Options/Priority/Lowest");
5010 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5013 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
5015 Compose *compose = (Compose *) data;
5017 GtkItemFactory *ifactory;
5018 gboolean can_sign = FALSE, can_encrypt = FALSE;
5020 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
5022 if (!GTK_CHECK_MENU_ITEM(widget)->active)
5025 systemid = gtk_object_get_data(GTK_OBJECT(widget), "privacy_system");
5026 g_free(compose->privacy_system);
5027 compose->privacy_system = NULL;
5028 if (systemid != NULL) {
5029 compose->privacy_system = g_strdup(systemid);
5031 can_sign = privacy_system_can_sign(systemid);
5032 can_encrypt = privacy_system_can_encrypt(systemid);
5035 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5037 ifactory = gtk_item_factory_from_widget(compose->menubar);
5038 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5040 menu_set_active(ifactory, "/Options/Sign", FALSE);
5041 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5043 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
5046 static void compose_update_privacy_system_menu_item(Compose * compose)
5048 static gchar *branch_path = "/Options/Privacy System";
5049 GtkItemFactory *ifactory;
5050 GtkWidget *menuitem = NULL;
5052 gboolean can_sign = FALSE, can_encrypt = FALSE;
5054 ifactory = gtk_item_factory_from_widget(compose->menubar);
5056 if (compose->privacy_system != NULL) {
5059 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5060 g_return_if_fail(menuitem != NULL);
5062 amenu = GTK_MENU_SHELL(menuitem)->children;
5064 while (amenu != NULL) {
5065 GList *alist = amenu->next;
5067 systemid = gtk_object_get_data(GTK_OBJECT(amenu->data), "privacy_system");
5068 if (systemid != NULL)
5069 if (strcmp(systemid, compose->privacy_system) == 0) {
5070 menuitem = GTK_WIDGET(amenu->data);
5072 can_sign = privacy_system_can_sign(systemid);
5073 can_encrypt = privacy_system_can_encrypt(systemid);
5080 if (menuitem != NULL)
5081 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5084 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5085 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5088 static void compose_set_template_menu(Compose *compose)
5090 GSList *tmpl_list, *cur;
5094 tmpl_list = template_get_config();
5096 menu = gtk_menu_new();
5098 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5099 Template *tmpl = (Template *)cur->data;
5101 item = gtk_menu_item_new_with_label(tmpl->name);
5102 gtk_menu_append(GTK_MENU(menu), item);
5103 gtk_signal_connect(GTK_OBJECT(item), "activate",
5104 GTK_SIGNAL_FUNC(compose_template_activate_cb),
5106 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
5107 gtk_widget_show(item);
5110 gtk_widget_show(menu);
5111 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5114 void compose_update_actions_menu(Compose *compose)
5116 GtkItemFactory *ifactory;
5118 ifactory = gtk_item_factory_from_widget(compose->menubar);
5119 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5122 void compose_update_privacy_systems_menu(Compose *compose)
5124 static gchar *branch_path = "/Options/Privacy System";
5125 static gboolean connected = FALSE;
5126 GtkItemFactory *ifactory;
5127 GtkWidget *menuitem;
5128 GSList *systems, *cur;
5131 GtkWidget *system_none;
5134 ifactory = gtk_item_factory_from_widget(compose->menubar);
5136 /* remove old entries */
5137 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5138 g_return_if_fail(menuitem != NULL);
5140 amenu = GTK_MENU_SHELL(menuitem)->children->next;
5141 while (amenu != NULL) {
5142 GList *alist = amenu->next;
5143 gtk_widget_destroy(GTK_WIDGET(amenu->data));
5147 system_none = gtk_item_factory_get_widget(ifactory,
5148 "/Options/Privacy System/None");
5150 gtk_signal_connect(GTK_OBJECT(system_none), "activate",
5151 GTK_SIGNAL_FUNC(compose_set_privacy_system_cb), compose);
5155 systems = privacy_get_system_ids();
5156 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
5157 gchar *systemid = cur->data;
5159 group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(system_none));
5160 widget = gtk_radio_menu_item_new_with_label(group,
5161 privacy_system_get_name(systemid));
5162 gtk_object_set_data_full(GTK_OBJECT(widget), "privacy_system",
5163 g_strdup(systemid), g_free);
5164 gtk_signal_connect(GTK_OBJECT(widget), "activate",
5165 GTK_SIGNAL_FUNC(compose_set_privacy_system_cb), compose);
5167 gtk_menu_append(GTK_MENU(system_none->parent), widget);
5168 gtk_widget_show(widget);
5171 g_slist_free(systems);
5174 void compose_reflect_prefs_all(void)
5179 for (cur = compose_list; cur != NULL; cur = cur->next) {
5180 compose = (Compose *)cur->data;
5181 compose_set_template_menu(compose);
5185 void compose_reflect_prefs_pixmap_theme(void)
5190 for (cur = compose_list; cur != NULL; cur = cur->next) {
5191 compose = (Compose *)cur->data;
5192 toolbar_update(TOOLBAR_COMPOSE, compose);
5196 static void compose_template_apply(Compose *compose, Template *tmpl,
5202 if (!tmpl || !tmpl->value) return;
5204 gtk_stext_freeze(GTK_STEXT(compose->text));
5206 if (tmpl->subject && *tmpl->subject != '\0')
5207 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5209 if (tmpl->to && *tmpl->to != '\0')
5210 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5211 if (tmpl->cc && *tmpl->cc != '\0')
5212 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5214 if (tmpl->bcc && *tmpl->bcc != '\0')
5215 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5218 gtkut_stext_clear(GTK_STEXT(compose->text));
5220 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
5221 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5224 if (prefs_common.quotemark && *prefs_common.quotemark)
5225 qmark = prefs_common.quotemark;
5229 if (compose->replyinfo != NULL)
5230 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5231 tmpl->value, qmark, NULL);
5232 else if (compose->fwdinfo != NULL)
5233 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
5234 tmpl->value, qmark, NULL);
5239 if (replace && parsed_str && compose->account->auto_sig)
5240 compose_insert_sig(compose, FALSE);
5242 if (replace && parsed_str) {
5243 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
5244 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
5248 compose_changed_cb(NULL, compose);
5250 gtk_stext_thaw(GTK_STEXT(compose->text));
5253 static void compose_destroy(Compose *compose)
5256 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5259 /* NOTE: address_completion_end() does nothing with the window
5260 * however this may change. */
5261 address_completion_end(compose->window);
5263 slist_free_strings(compose->to_list);
5264 g_slist_free(compose->to_list);
5265 slist_free_strings(compose->newsgroup_list);
5266 g_slist_free(compose->newsgroup_list);
5267 slist_free_strings(compose->header_list);
5268 g_slist_free(compose->header_list);
5270 procmsg_msginfo_free(compose->targetinfo);
5271 procmsg_msginfo_free(compose->replyinfo);
5272 procmsg_msginfo_free(compose->fwdinfo);
5274 g_free(compose->replyto);
5275 g_free(compose->cc);
5276 g_free(compose->bcc);
5277 g_free(compose->newsgroups);
5278 g_free(compose->followup_to);
5280 g_free(compose->ml_post);
5282 g_free(compose->inreplyto);
5283 g_free(compose->references);
5284 g_free(compose->msgid);
5285 g_free(compose->boundary);
5287 if (compose->redirect_filename)
5288 g_free(compose->redirect_filename);
5289 if (compose->undostruct)
5290 undo_destroy(compose->undostruct);
5292 g_free(compose->sig_str);
5294 g_free(compose->exteditor_file);
5296 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5298 compose_attach_info_free(ainfo);
5300 if (addressbook_get_target_compose() == compose)
5301 addressbook_set_target_compose(NULL);
5304 if (compose->gtkaspell) {
5305 gtkaspell_delete(compose->gtkaspell);
5309 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5310 prefs_common.compose_height = compose->window->allocation.height;
5312 gtk_widget_destroy(compose->paned);
5314 toolbar_destroy(compose->toolbar);
5315 g_free(compose->toolbar);
5318 compose_list = g_list_remove(compose_list, compose);
5321 static void compose_attach_info_free(AttachInfo *ainfo)
5323 g_free(ainfo->file);
5324 g_free(ainfo->content_type);
5325 g_free(ainfo->name);
5329 static void compose_attach_remove_selected(Compose *compose)
5331 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5335 while (clist->selection != NULL) {
5336 row = GPOINTER_TO_INT(clist->selection->data);
5337 ainfo = gtk_clist_get_row_data(clist, row);
5338 compose_attach_info_free(ainfo);
5339 gtk_clist_remove(clist, row);
5343 static struct _AttachProperty
5346 GtkWidget *mimetype_entry;
5347 GtkWidget *encoding_optmenu;
5348 GtkWidget *path_entry;
5349 GtkWidget *filename_entry;
5351 GtkWidget *cancel_btn;
5354 static void compose_attach_property(Compose *compose)
5356 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5359 GtkOptionMenu *optmenu;
5360 static gboolean cancelled;
5362 if (!clist->selection) return;
5363 row = GPOINTER_TO_INT(clist->selection->data);
5365 ainfo = gtk_clist_get_row_data(clist, row);
5368 if (!attach_prop.window)
5369 compose_attach_property_create(&cancelled);
5370 gtk_widget_grab_focus(attach_prop.ok_btn);
5371 gtk_widget_show(attach_prop.window);
5372 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5374 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5375 if (ainfo->encoding == ENC_UNKNOWN)
5376 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5377 GINT_TO_POINTER(ENC_BASE64));
5379 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5380 GINT_TO_POINTER(ainfo->encoding));
5382 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5383 ainfo->content_type ? ainfo->content_type : "");
5384 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5385 ainfo->file ? ainfo->file : "");
5386 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5387 ainfo->name ? ainfo->name : "");
5391 gchar *cnttype = NULL;
5395 GtkWidget *menuitem;
5400 if (cancelled == TRUE) {
5401 gtk_widget_hide(attach_prop.window);
5405 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5406 if (*text != '\0') {
5409 text = g_strstrip(g_strdup(text));
5410 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5411 cnttype = g_strdup(text);
5414 alertpanel_error(_("Invalid MIME type."));
5420 menu = gtk_option_menu_get_menu(optmenu);
5421 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5422 ainfo->encoding = GPOINTER_TO_INT
5423 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5425 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5426 if (*text != '\0') {
5427 if (is_file_exist(text) &&
5428 (size = get_file_size(text)) > 0)
5429 file = g_strdup(text);
5432 (_("File doesn't exist or is empty."));
5438 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5439 if (*text != '\0') {
5440 g_free(ainfo->name);
5441 ainfo->name = g_strdup(text);
5445 g_free(ainfo->content_type);
5446 ainfo->content_type = cnttype;
5449 g_free(ainfo->file);
5455 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5456 ainfo->content_type);
5457 gtk_clist_set_text(clist, row, COL_SIZE,
5458 to_human_readable(ainfo->size));
5459 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5461 gtk_widget_hide(attach_prop.window);
5466 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5468 label = gtk_label_new(str); \
5469 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5470 GTK_FILL, 0, 0, 0); \
5471 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5473 entry = gtk_entry_new(); \
5474 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5475 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5478 static void compose_attach_property_create(gboolean *cancelled)
5484 GtkWidget *mimetype_entry;
5487 GtkWidget *optmenu_menu;
5488 GtkWidget *menuitem;
5489 GtkWidget *path_entry;
5490 GtkWidget *filename_entry;
5493 GtkWidget *cancel_btn;
5494 GList *mime_type_list, *strlist;
5496 debug_print("Creating attach_property window...\n");
5498 window = gtk_window_new(GTK_WINDOW_DIALOG);
5499 gtk_widget_set_usize(window, 480, -1);
5500 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5501 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
5502 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5503 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5504 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5505 GTK_SIGNAL_FUNC(attach_property_delete_event),
5507 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5508 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5511 vbox = gtk_vbox_new(FALSE, 8);
5512 gtk_container_add(GTK_CONTAINER(window), vbox);
5514 table = gtk_table_new(4, 2, FALSE);
5515 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5516 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5517 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5519 label = gtk_label_new(_("MIME type"));
5520 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5522 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5523 mimetype_entry = gtk_combo_new();
5524 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5525 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5527 /* stuff with list */
5528 mime_type_list = procmime_get_mime_type_list();
5530 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5531 MimeType *type = (MimeType *) mime_type_list->data;
5532 strlist = g_list_append(strlist,
5533 g_strdup_printf("%s/%s",
5534 type->type, type->sub_type));
5537 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5539 for (mime_type_list = strlist; mime_type_list != NULL;
5540 mime_type_list = mime_type_list->next)
5541 g_free(mime_type_list->data);
5542 g_list_free(strlist);
5544 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5546 label = gtk_label_new(_("Encoding"));
5547 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5549 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5551 hbox = gtk_hbox_new(FALSE, 0);
5552 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5553 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5555 optmenu = gtk_option_menu_new();
5556 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5558 optmenu_menu = gtk_menu_new();
5559 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5560 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5562 gtk_widget_set_sensitive(menuitem, FALSE);
5564 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5565 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5567 gtk_widget_set_sensitive(menuitem, FALSE);
5569 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
5570 ENC_QUOTED_PRINTABLE);
5571 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5573 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5575 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5577 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5578 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5580 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5581 &cancel_btn, _("Cancel"), NULL, NULL);
5582 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5583 gtk_widget_grab_default(ok_btn);
5585 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5586 GTK_SIGNAL_FUNC(attach_property_ok),
5588 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5589 GTK_SIGNAL_FUNC(attach_property_cancel),
5592 gtk_widget_show_all(vbox);
5594 attach_prop.window = window;
5595 attach_prop.mimetype_entry = mimetype_entry;
5596 attach_prop.encoding_optmenu = optmenu;
5597 attach_prop.path_entry = path_entry;
5598 attach_prop.filename_entry = filename_entry;
5599 attach_prop.ok_btn = ok_btn;
5600 attach_prop.cancel_btn = cancel_btn;
5603 #undef SET_LABEL_AND_ENTRY
5605 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5611 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5617 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5618 gboolean *cancelled)
5626 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5627 gboolean *cancelled)
5629 if (event && event->keyval == GDK_Escape) {
5635 static void compose_exec_ext_editor(Compose *compose)
5641 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
5642 G_DIR_SEPARATOR, compose);
5644 if (pipe(pipe_fds) < 0) {
5650 if ((pid = fork()) < 0) {
5657 /* close the write side of the pipe */
5660 compose->exteditor_file = g_strdup(tmp);
5661 compose->exteditor_pid = pid;
5662 compose->exteditor_readdes = pipe_fds[0];
5664 compose_set_ext_editor_sensitive(compose, FALSE);
5666 compose->exteditor_tag =
5667 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5668 compose_input_cb, compose);
5669 } else { /* process-monitoring process */
5675 /* close the read side of the pipe */
5678 if (compose_write_body_to_file(compose, tmp) < 0) {
5679 fd_write_all(pipe_fds[1], "2\n", 2);
5683 pid_ed = compose_exec_ext_editor_real(tmp);
5685 fd_write_all(pipe_fds[1], "1\n", 2);
5689 /* wait until editor is terminated */
5690 waitpid(pid_ed, NULL, 0);
5692 fd_write_all(pipe_fds[1], "0\n", 2);
5701 static gint compose_exec_ext_editor_real(const gchar *file)
5703 static gchar *def_cmd = "emacs %s";
5709 g_return_val_if_fail(file != NULL, -1);
5711 if ((pid = fork()) < 0) {
5716 if (pid != 0) return pid;
5718 /* grandchild process */
5720 if (setpgid(0, getppid()))
5723 if (prefs_common.ext_editor_cmd &&
5724 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5725 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5726 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5728 if (prefs_common.ext_editor_cmd)
5729 g_warning("External editor command line is invalid: `%s'\n",
5730 prefs_common.ext_editor_cmd);
5731 g_snprintf(buf, sizeof(buf), def_cmd, file);
5734 cmdline = strsplit_with_quote(buf, " ", 1024);
5735 execvp(cmdline[0], cmdline);
5738 g_strfreev(cmdline);
5743 static gboolean compose_ext_editor_kill(Compose *compose)
5745 pid_t pgid = compose->exteditor_pid * -1;
5748 ret = kill(pgid, 0);
5750 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5754 msg = g_strdup_printf
5755 (_("The external editor is still working.\n"
5756 "Force terminating the process?\n"
5757 "process group id: %d"), -pgid);
5758 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5761 if (val == G_ALERTDEFAULT) {
5762 gdk_input_remove(compose->exteditor_tag);
5763 close(compose->exteditor_readdes);
5765 if (kill(pgid, SIGTERM) < 0) perror("kill");
5766 waitpid(compose->exteditor_pid, NULL, 0);
5768 g_warning("Terminated process group id: %d", -pgid);
5769 g_warning("Temporary file: %s",
5770 compose->exteditor_file);
5772 compose_set_ext_editor_sensitive(compose, TRUE);
5774 g_free(compose->exteditor_file);
5775 compose->exteditor_file = NULL;
5776 compose->exteditor_pid = -1;
5777 compose->exteditor_readdes = -1;
5778 compose->exteditor_tag = -1;
5786 static void compose_input_cb(gpointer data, gint source,
5787 GdkInputCondition condition)
5790 Compose *compose = (Compose *)data;
5793 debug_print("Compose: input from monitoring process\n");
5795 gdk_input_remove(compose->exteditor_tag);
5798 if (read(source, &buf[i], 1) < 1) {
5802 if (buf[i] == '\n') {
5807 if (i == sizeof(buf) - 1)
5811 waitpid(compose->exteditor_pid, NULL, 0);
5813 if (buf[0] == '0') { /* success */
5814 GtkSText *text = GTK_STEXT(compose->text);
5816 gtk_stext_freeze(text);
5817 gtk_stext_set_point(text, 0);
5818 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5819 compose_insert_file(compose, compose->exteditor_file);
5820 compose_changed_cb(NULL, compose);
5821 gtk_stext_thaw(text);
5823 if (unlink(compose->exteditor_file) < 0)
5824 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5825 } else if (buf[0] == '1') { /* failed */
5826 g_warning("Couldn't exec external editor\n");
5827 if (unlink(compose->exteditor_file) < 0)
5828 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5829 } else if (buf[0] == '2') {
5830 g_warning("Couldn't write to file\n");
5831 } else if (buf[0] == '3') {
5832 g_warning("Pipe read failed\n");
5837 compose_set_ext_editor_sensitive(compose, TRUE);
5839 g_free(compose->exteditor_file);
5840 compose->exteditor_file = NULL;
5841 compose->exteditor_pid = -1;
5842 compose->exteditor_readdes = -1;
5843 compose->exteditor_tag = -1;
5846 static void compose_set_ext_editor_sensitive(Compose *compose,
5849 GtkItemFactory *ifactory;
5851 ifactory = gtk_item_factory_from_widget(compose->menubar);
5853 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5854 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5855 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
5856 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
5857 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5858 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5859 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5862 gtk_widget_set_sensitive(compose->text, sensitive);
5863 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
5864 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
5865 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
5866 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
5867 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
5868 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
5869 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
5870 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
5874 * compose_undo_state_changed:
5876 * Change the sensivity of the menuentries undo and redo
5878 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5879 gint redo_state, gpointer data)
5881 GtkWidget *widget = GTK_WIDGET(data);
5882 GtkItemFactory *ifactory;
5884 g_return_if_fail(widget != NULL);
5886 ifactory = gtk_item_factory_from_widget(widget);
5888 switch (undo_state) {
5889 case UNDO_STATE_TRUE:
5890 if (!undostruct->undo_state) {
5891 undostruct->undo_state = TRUE;
5892 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5895 case UNDO_STATE_FALSE:
5896 if (undostruct->undo_state) {
5897 undostruct->undo_state = FALSE;
5898 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5901 case UNDO_STATE_UNCHANGED:
5903 case UNDO_STATE_REFRESH:
5904 menu_set_sensitive(ifactory, "/Edit/Undo",
5905 undostruct->undo_state);
5908 g_warning("Undo state not recognized");
5912 switch (redo_state) {
5913 case UNDO_STATE_TRUE:
5914 if (!undostruct->redo_state) {
5915 undostruct->redo_state = TRUE;
5916 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5919 case UNDO_STATE_FALSE:
5920 if (undostruct->redo_state) {
5921 undostruct->redo_state = FALSE;
5922 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5925 case UNDO_STATE_UNCHANGED:
5927 case UNDO_STATE_REFRESH:
5928 menu_set_sensitive(ifactory, "/Edit/Redo",
5929 undostruct->redo_state);
5932 g_warning("Redo state not recognized");
5937 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5941 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5942 cursor_pos = MAX(cursor_pos, 0);
5947 /* callback functions */
5949 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5950 * includes "non-client" (windows-izm) in calculation, so this calculation
5951 * may not be accurate.
5953 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5954 GtkAllocation *allocation,
5955 GtkSHRuler *shruler)
5957 if (prefs_common.show_ruler) {
5959 gint line_width_in_chars;
5961 char_width = gtkut_get_font_width
5962 (GTK_WIDGET(widget)->style->font);
5963 line_width_in_chars =
5964 (allocation->width - allocation->x) / char_width;
5966 /* got the maximum */
5967 gtk_ruler_set_range(GTK_RULER(shruler),
5968 0.0, line_width_in_chars,
5969 calc_cursor_xpos(GTK_STEXT(widget),
5972 /*line_width_in_chars*/ char_width);
5978 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5980 Compose *compose = (Compose *)data;
5983 gchar *folderidentifier;
5985 ac = account_find_from_id(
5986 GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menuitem))));
5987 g_return_if_fail(ac != NULL);
5989 if (ac != compose->account)
5990 compose_select_account(compose, ac, FALSE);
5992 /* Set message save folder */
5993 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5994 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
5996 gtk_signal_connect(GTK_OBJECT(compose->savemsg_checkbtn), "toggled",
5997 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
5999 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6000 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6001 folderidentifier = folder_item_get_identifier(account_get_special_folder
6002 (compose->account, F_OUTBOX));
6003 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
6004 g_free(folderidentifier);
6008 static void attach_selected(GtkCList *clist, gint row, gint column,
6009 GdkEvent *event, gpointer data)
6011 Compose *compose = (Compose *)data;
6013 if (event && event->type == GDK_2BUTTON_PRESS)
6014 compose_attach_property(compose);
6017 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6020 Compose *compose = (Compose *)data;
6021 GtkCList *clist = GTK_CLIST(compose->attach_clist);
6026 if (event->button == 3) {
6027 if ((clist->selection && !clist->selection->next) ||
6028 !clist->selection) {
6029 gtk_clist_unselect_all(clist);
6030 if (gtk_clist_get_selection_info(clist,
6033 gtk_clist_select_row(clist, row, column);
6034 gtkut_clist_set_focus_row(clist, row);
6037 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6038 NULL, NULL, event->button, event->time);
6042 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6045 Compose *compose = (Compose *)data;
6049 switch (event->keyval) {
6051 compose_attach_remove_selected(compose);
6056 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6058 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6059 toolbar_comp_set_sensitive(compose, allow);
6060 menu_set_sensitive(ifactory, "/Message", allow);
6061 menu_set_sensitive(ifactory, "/Edit", allow);
6063 menu_set_sensitive(ifactory, "/Spelling", allow);
6065 menu_set_sensitive(ifactory, "/Options", allow);
6066 menu_set_sensitive(ifactory, "/Tools", allow);
6067 menu_set_sensitive(ifactory, "/Help", allow);
6070 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6072 Compose *compose = (Compose *)data;
6074 if (prefs_common.work_offline)
6075 if (alertpanel(_("Offline warning"),
6076 _("You're working offline. Override?"),
6077 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
6080 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
6081 gtk_timeout_remove(compose->draft_timeout_tag);
6082 compose->draft_timeout_tag = -1;
6085 compose_send(compose);
6088 static void compose_send_later_cb(gpointer data, guint action,
6091 Compose *compose = (Compose *)data;
6094 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6096 compose_close(compose);
6099 void compose_draft (gpointer data)
6101 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6104 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6106 Compose *compose = (Compose *)data;
6110 MsgFlags flag = {0, 0};
6111 static gboolean lock = FALSE;
6112 MsgInfo *newmsginfo;
6117 draft = account_get_special_folder(compose->account, F_DRAFT);
6118 g_return_if_fail(draft != NULL);
6122 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
6123 G_DIR_SEPARATOR, compose);
6124 if ((fp = fopen(tmp, "wb")) == NULL) {
6125 FILE_OP_ERROR(tmp, "fopen");
6129 /* chmod for security */
6130 if (change_file_mode_rw(fp, tmp) < 0) {
6131 FILE_OP_ERROR(tmp, "chmod");
6132 g_warning("can't change file mode\n");
6135 /* Save draft infos */
6136 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
6137 fprintf(fp, "S:%s\n", compose->account->address);
6138 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
6139 gchar *savefolderid;
6141 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6142 fprintf(fp, "SCF:%s\n", savefolderid);
6143 g_free(savefolderid);
6145 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
6146 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
6147 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
6150 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
6159 folder_item_scan(draft);
6160 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
6167 draft->mtime = 0; /* force updating */
6169 if (compose->mode == COMPOSE_REEDIT) {
6170 compose_remove_reedit_target(compose);
6173 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6175 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6176 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
6177 if (compose_use_attach(compose))
6178 procmsg_msginfo_set_flags(newmsginfo, 0,
6179 MSG_HAS_ATTACHMENT);
6181 procmsg_msginfo_free(newmsginfo);
6184 folder_item_scan(draft);
6188 if (action == COMPOSE_QUIT_EDITING)
6189 compose_close(compose);
6194 path = folder_item_fetch_msg(draft, msgnum);
6195 g_return_if_fail(path != NULL);
6196 if (stat(path, &s) < 0) {
6197 FILE_OP_ERROR(path, "stat");
6204 procmsg_msginfo_free(compose->targetinfo);
6205 compose->targetinfo = procmsg_msginfo_new();
6206 compose->targetinfo->msgnum = msgnum;
6207 compose->targetinfo->size = s.st_size;
6208 compose->targetinfo->mtime = s.st_mtime;
6209 compose->targetinfo->folder = draft;
6210 compose->mode = COMPOSE_REEDIT;
6212 if (action == COMPOSE_AUTO_SAVE) {
6213 compose->autosaved_draft = compose->targetinfo;
6218 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6220 Compose *compose = (Compose *)data;
6223 if (compose->redirect_filename != NULL)
6226 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6231 for ( tmp = file_list; tmp; tmp = tmp->next) {
6232 gchar *file = (gchar *) tmp->data;
6233 compose_attach_append(compose, file, file, NULL);
6234 compose_changed_cb(NULL, compose);
6237 g_list_free(file_list);
6241 static void compose_insert_file_cb(gpointer data, guint action,
6244 Compose *compose = (Compose *)data;
6247 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6252 for ( tmp = file_list; tmp; tmp = tmp->next) {
6253 gchar *file = (gchar *) tmp->data;
6254 gchar *filedup = g_strdup(file);
6256 ComposeInsertResult res;
6258 res = compose_insert_file(compose, file);
6259 shortfile = g_basename(filedup);
6260 if (res == COMPOSE_INSERT_READ_ERROR) {
6261 alertpanel_error(_("File '%s' could not be read."), shortfile);
6262 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
6263 alertpanel_error(_("File '%s' contained invalid characters\n"
6264 "for the current encoding, insertion may be incorrect."), shortfile);
6269 g_list_free(file_list);
6273 static void compose_insert_sig_cb(gpointer data, guint action,
6276 Compose *compose = (Compose *)data;
6278 compose_insert_sig(compose, FALSE);
6281 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6285 Compose *compose = (Compose *)data;
6287 gtkut_widget_get_uposition(widget, &x, &y);
6288 prefs_common.compose_x = x;
6289 prefs_common.compose_y = y;
6291 if (compose->sending)
6293 compose_close_cb(compose, 0, NULL);
6297 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6299 Compose *compose = (Compose *)data;
6302 if (compose->exteditor_tag != -1) {
6303 if (!compose_ext_editor_kill(compose))
6307 if (compose->modified) {
6308 val = alertpanel(_("Discard message"),
6309 _("This message has been modified. discard it?"),
6310 _("Discard"), _("to Draft"), _("Cancel"));
6313 case G_ALERTDEFAULT:
6314 if (prefs_common.autosave)
6315 compose_remove_draft(compose);
6317 case G_ALERTALTERNATE:
6318 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6325 compose_close(compose);
6328 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6330 Compose *compose = (Compose *)data;
6332 addressbook_open(compose);
6335 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6337 Compose *compose = (Compose *)data;
6342 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6343 g_return_if_fail(tmpl != NULL);
6345 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6347 val = alertpanel(_("Apply template"), msg,
6348 _("Replace"), _("Insert"), _("Cancel"));
6351 if (val == G_ALERTDEFAULT)
6352 compose_template_apply(compose, tmpl, TRUE);
6353 else if (val == G_ALERTALTERNATE)
6354 compose_template_apply(compose, tmpl, FALSE);
6357 static void compose_ext_editor_cb(gpointer data, guint action,
6360 Compose *compose = (Compose *)data;
6362 compose_exec_ext_editor(compose);
6365 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6367 if (compose->sending)
6369 compose_destroy(compose);
6372 static void compose_undo_cb(Compose *compose)
6374 undo_undo(compose->undostruct);
6377 static void compose_redo_cb(Compose *compose)
6379 undo_redo(compose->undostruct);
6382 static void compose_cut_cb(Compose *compose)
6384 if (compose->focused_editable &&
6385 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6386 gtk_editable_cut_clipboard
6387 (GTK_EDITABLE(compose->focused_editable));
6390 static void compose_copy_cb(Compose *compose)
6392 if (compose->focused_editable &&
6393 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6394 gtk_editable_copy_clipboard
6395 (GTK_EDITABLE(compose->focused_editable));
6398 static void compose_paste_cb(Compose *compose)
6400 if (compose->focused_editable &&
6401 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6402 gtk_editable_paste_clipboard
6403 (GTK_EDITABLE(compose->focused_editable));
6406 static void compose_paste_as_quote_cb(Compose *compose)
6408 if (compose->focused_editable &&
6409 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6410 /* let text_insert() (called directly or at a later time
6411 * after the gtk_editable_paste_clipboard) know that
6412 * text is to be inserted as a quotation. implemented
6413 * by using a simple refcount... */
6414 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data(
6415 GTK_OBJECT(compose->focused_editable),
6416 "paste_as_quotation"));
6417 gtk_object_set_data(GTK_OBJECT(compose->focused_editable),
6418 "paste_as_quotation",
6419 GINT_TO_POINTER(paste_as_quotation + 1));
6420 gtk_editable_paste_clipboard
6421 (GTK_EDITABLE(compose->focused_editable));
6425 static void compose_allsel_cb(Compose *compose)
6427 if (compose->focused_editable &&
6428 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6429 gtk_editable_select_region
6430 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6433 static void compose_gtk_stext_action_cb(Compose *compose,
6434 ComposeCallGtkSTextAction action)
6436 GtkSText *text = GTK_STEXT(compose->text);
6438 void (*do_action) (GtkSText *text);
6439 } action_table[] = {
6440 {gtk_stext_move_beginning_of_line},
6441 {gtk_stext_move_forward_character},
6442 {gtk_stext_move_backward_character},
6443 {gtk_stext_move_forward_word},
6444 {gtk_stext_move_backward_word},
6445 {gtk_stext_move_end_of_line},
6446 {gtk_stext_move_next_line},
6447 {gtk_stext_move_previous_line},
6448 {gtk_stext_delete_forward_character},
6449 {gtk_stext_delete_backward_character},
6450 {gtk_stext_delete_forward_word},
6451 {gtk_stext_delete_backward_word},
6452 {gtk_stext_delete_line},
6453 {gtk_stext_delete_line}, /* gtk_stext_delete_line_n */
6454 {gtk_stext_delete_to_line_end}
6457 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
6459 if (action >= COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE &&
6460 action <= COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END)
6461 action_table[action].do_action(text);
6464 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6466 if (GTK_IS_EDITABLE(widget))
6467 compose->focused_editable = widget;
6470 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6472 if (compose->modified == FALSE) {
6473 compose->modified = TRUE;
6474 compose_set_title(compose);
6478 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6481 gtk_stext_set_point(GTK_STEXT(widget),
6482 gtk_editable_get_position(GTK_EDITABLE(widget)));
6486 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6489 gtk_stext_set_point(GTK_STEXT(widget),
6490 gtk_editable_get_position(GTK_EDITABLE(widget)));
6494 static void compose_toggle_autowrap_cb(gpointer data, guint action,
6497 Compose *compose = (Compose *)data;
6499 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
6500 if (compose->autowrap)
6501 compose_wrap_line_all_full(compose, TRUE);
6504 static void compose_toggle_sign_cb(gpointer data, guint action,
6507 Compose *compose = (Compose *)data;
6509 if (GTK_CHECK_MENU_ITEM(widget)->active)
6510 compose->use_signing = TRUE;
6512 compose->use_signing = FALSE;
6515 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6518 Compose *compose = (Compose *)data;
6520 if (GTK_CHECK_MENU_ITEM(widget)->active)
6521 compose->use_encryption = TRUE;
6523 compose->use_encryption = FALSE;
6526 static void activate_privacy_system(Compose *compose, PrefsAccount *account)
6528 g_free(compose->privacy_system);
6529 compose->privacy_system = g_strdup(account->default_privacy_system);
6530 compose_update_privacy_system_menu_item(compose);
6533 static void compose_toggle_ruler_cb(gpointer data, guint action,
6536 Compose *compose = (Compose *)data;
6538 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6539 gtk_widget_show(compose->ruler_hbox);
6540 prefs_common.show_ruler = TRUE;
6542 gtk_widget_hide(compose->ruler_hbox);
6543 gtk_widget_queue_resize(compose->edit_vbox);
6544 prefs_common.show_ruler = FALSE;
6548 static void compose_attach_drag_received_cb (GtkWidget *widget,
6549 GdkDragContext *drag_context,
6552 GtkSelectionData *data,
6557 Compose *compose = (Compose *)user_data;
6560 list = uri_list_extract_filenames((const gchar *)data->data);
6561 for (tmp = list; tmp != NULL; tmp = tmp->next)
6562 compose_attach_append
6563 (compose, (const gchar *)tmp->data,
6564 (const gchar *)tmp->data, NULL);
6565 if (list) compose_changed_cb(NULL, compose);
6566 list_free_strings(list);
6570 static void compose_insert_drag_received_cb (GtkWidget *widget,
6571 GdkDragContext *drag_context,
6574 GtkSelectionData *data,
6579 Compose *compose = (Compose *)user_data;
6582 list = uri_list_extract_filenames((const gchar *)data->data);
6583 for (tmp = list; tmp != NULL; tmp = tmp->next)
6584 compose_insert_file(compose, (const gchar *)tmp->data);
6585 list_free_strings(list);
6589 #if 0 /* NEW COMPOSE GUI */
6590 static void to_activated(GtkWidget *widget, Compose *compose)
6592 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6593 gtk_widget_grab_focus(compose->newsgroups_entry);
6595 gtk_widget_grab_focus(compose->subject_entry);
6598 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6600 gtk_widget_grab_focus(compose->subject_entry);
6603 static void subject_activated(GtkWidget *widget, Compose *compose)
6605 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6606 gtk_widget_grab_focus(compose->cc_entry);
6607 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6608 gtk_widget_grab_focus(compose->bcc_entry);
6609 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6610 gtk_widget_grab_focus(compose->reply_entry);
6611 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6612 gtk_widget_grab_focus(compose->followup_entry);
6614 gtk_widget_grab_focus(compose->text);
6617 static void cc_activated(GtkWidget *widget, Compose *compose)
6619 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6620 gtk_widget_grab_focus(compose->bcc_entry);
6621 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6622 gtk_widget_grab_focus(compose->reply_entry);
6623 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6624 gtk_widget_grab_focus(compose->followup_entry);
6626 gtk_widget_grab_focus(compose->text);
6629 static void bcc_activated(GtkWidget *widget, Compose *compose)
6631 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6632 gtk_widget_grab_focus(compose->reply_entry);
6633 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6634 gtk_widget_grab_focus(compose->followup_entry);
6636 gtk_widget_grab_focus(compose->text);
6639 static void replyto_activated(GtkWidget *widget, Compose *compose)
6641 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6642 gtk_widget_grab_focus(compose->followup_entry);
6644 gtk_widget_grab_focus(compose->text);
6647 static void followupto_activated(GtkWidget *widget, Compose *compose)
6649 gtk_widget_grab_focus(compose->text);
6653 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6656 Compose *compose = (Compose *)data;
6658 if (GTK_CHECK_MENU_ITEM(widget)->active)
6659 compose->return_receipt = TRUE;
6661 compose->return_receipt = FALSE;
6664 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
6667 Compose *compose = (Compose *)data;
6669 if (GTK_CHECK_MENU_ITEM(widget)->active)
6670 compose->remove_references = TRUE;
6672 compose->remove_references = FALSE;
6675 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6677 ComposeHeaderEntry *headerentry)
6679 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6680 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6681 !(event->state & GDK_MODIFIER_MASK) &&
6682 (event->keyval == GDK_BackSpace) &&
6683 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6684 gtk_container_remove
6685 (GTK_CONTAINER(headerentry->compose->header_table),
6686 headerentry->combo);
6687 gtk_container_remove
6688 (GTK_CONTAINER(headerentry->compose->header_table),
6689 headerentry->entry);
6690 headerentry->compose->header_list =
6691 g_slist_remove(headerentry->compose->header_list,
6693 g_free(headerentry);
6694 } else if (event->keyval == GDK_Tab) {
6695 if (headerentry->compose->header_last == headerentry) {
6696 /* Override default next focus, and give it to subject_entry
6697 * instead of notebook tabs
6699 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6700 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6706 void compose_headerentry_changed_cb(GtkWidget *entry,
6707 ComposeHeaderEntry *headerentry)
6709 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6710 headerentry->compose->header_list =
6711 g_slist_append(headerentry->compose->header_list,
6713 compose_create_header_entry(headerentry->compose);
6714 gtk_signal_disconnect_by_func
6716 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6718 /* Automatically scroll down */
6719 compose_show_first_last_header(headerentry->compose, FALSE);
6724 static gboolean compose_headerentry_button_pressed
6725 (GtkWidget *entry, GdkEventButton *event, gpointer data)
6727 /* if this is a lclick, grab the focus */
6728 if (event->button == 1)
6729 gtk_widget_grab_focus(entry);
6733 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6735 GtkAdjustment *vadj;
6737 g_return_if_fail(compose);
6738 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6739 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6741 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6742 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6745 static void text_activated(GtkWidget *widget, Compose *compose)
6747 compose_send_control_enter(compose);
6750 static void text_inserted(GtkWidget *widget, const gchar *text,
6751 gint length, gint *position, Compose *compose)
6753 GtkEditable *editable = GTK_EDITABLE(widget);
6754 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data
6755 (GTK_OBJECT(widget), "paste_as_quotation"));
6757 gtk_signal_handler_block_by_func(GTK_OBJECT(widget),
6758 GTK_SIGNAL_FUNC(text_inserted),
6760 if (paste_as_quotation) {
6765 new_text = g_strndup(text, length);
6766 if (prefs_common.quotemark && *prefs_common.quotemark)
6767 qmark = prefs_common.quotemark;
6770 gtk_stext_set_point(GTK_STEXT(widget), *position);
6771 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
6772 pos = gtk_stext_get_point(GTK_STEXT(widget));
6773 gtk_editable_set_position(editable, pos);
6776 gtk_object_set_data(GTK_OBJECT(widget), "paste_as_quotation",
6777 GINT_TO_POINTER(paste_as_quotation - 1));
6779 gtk_editable_insert_text(editable, text, length, position);
6781 if (compose->autowrap)
6782 compose_wrap_line_all_full(compose, TRUE);
6784 gtk_signal_handler_unblock_by_func(GTK_OBJECT(widget),
6785 GTK_SIGNAL_FUNC(text_inserted),
6787 gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
6789 if (prefs_common.autosave &&
6790 gtk_stext_get_length(GTK_STEXT(widget)) % prefs_common.autosave_length == 0)
6791 compose->draft_timeout_tag = gtk_timeout_add
6792 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
6795 static gint compose_defer_auto_save_draft(Compose *compose)
6797 compose->draft_timeout_tag = -1;
6798 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
6802 static gboolean compose_send_control_enter(Compose *compose)
6806 GtkItemFactory *ifactory;
6807 GtkAccelEntry *accel;
6808 GtkWidget *send_menu;
6810 GdkModifierType ignored_mods =
6811 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
6812 GDK_MOD4_MASK | GDK_MOD5_MASK);
6814 ev = gtk_get_current_event();
6815 if (ev->type != GDK_KEY_PRESS) return FALSE;
6817 kev = (GdkEventKey *)ev;
6818 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6821 if (compose->exteditor_tag != -1)
6824 ifactory = gtk_item_factory_from_widget(compose->menubar);
6825 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6826 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6830 accel = (GtkAccelEntry *)list->data;
6831 if (accel && accel->accelerator_key == kev->keyval &&
6832 (accel->accelerator_mods & ~ignored_mods) ==
6833 (kev->state & ~ignored_mods)) {
6834 compose_send_cb(compose, 0, NULL);
6842 static void compose_check_all(Compose *compose)
6844 if (compose->gtkaspell)
6845 gtkaspell_check_all(compose->gtkaspell);
6848 static void compose_highlight_all(Compose *compose)
6850 if (compose->gtkaspell)
6851 gtkaspell_highlight_all(compose->gtkaspell);
6854 static void compose_check_backwards(Compose *compose)
6856 if (compose->gtkaspell)
6857 gtkaspell_check_backwards(compose->gtkaspell);
6859 GtkItemFactory *ifactory;
6860 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6861 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6862 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6866 static void compose_check_forwards_go(Compose *compose)
6868 if (compose->gtkaspell)
6869 gtkaspell_check_forwards_go(compose->gtkaspell);
6871 GtkItemFactory *ifactory;
6872 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6873 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6874 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6880 *\brief Guess originating forward account from MsgInfo and several
6881 * "common preference" settings. Return NULL if no guess.
6883 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
6885 PrefsAccount *account = NULL;
6887 g_return_val_if_fail(msginfo, NULL);
6888 g_return_val_if_fail(msginfo->folder, NULL);
6889 g_return_val_if_fail(msginfo->folder->prefs, NULL);
6891 if (msginfo->folder->prefs->enable_default_account)
6892 account = account_find_from_id(msginfo->folder->prefs->default_account);
6895 account = msginfo->folder->folder->account;
6897 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
6899 Xstrdup_a(to, msginfo->to, return NULL);
6900 extract_address(to);
6901 account = account_find_from_address(to);
6904 if (!account && prefs_common.forward_account_autosel) {
6906 if (!procheader_get_header_from_msginfo
6907 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
6908 extract_address(cc);
6909 account = account_find_from_address(cc);
6916 static void compose_close(Compose *compose)
6920 g_return_if_fail(compose);
6921 gtkut_widget_get_uposition(compose->window, &x, &y);
6922 prefs_common.compose_x = x;
6923 prefs_common.compose_y = y;
6924 gtk_widget_destroy(compose->window);
6928 * Add entry field for each address in list.
6929 * \param compose E-Mail composition object.
6930 * \param listAddress List of (formatted) E-Mail addresses.
6932 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
6937 addr = ( gchar * ) node->data;
6938 compose_entry_append( compose, addr, COMPOSE_TO );
6939 node = g_list_next( node );
6943 void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list,
6947 GSList *new_msglist = NULL;
6948 MsgInfo *tmp_msginfo = NULL;
6950 g_return_if_fail(msgview != NULL);
6952 g_return_if_fail(msginfo_list != NULL);
6954 if (g_slist_length(msginfo_list) == 1) {
6955 MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
6956 MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
6958 if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE &&
6959 !g_strcasecmp(mimeinfo->subtype, "rfc822")) {
6961 tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
6962 orig_msginfo, mimeinfo);
6963 if (tmp_msginfo != NULL) {
6964 new_msglist = g_slist_append(NULL, tmp_msginfo);
6969 body = messageview_get_selection(msgview);
6972 compose_reply_mode((ComposeMode)action, new_msglist, body);
6973 procmsg_msginfo_free(tmp_msginfo);
6974 g_slist_free(new_msglist);
6976 compose_reply_mode((ComposeMode)action, msginfo_list, body);