2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2004 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(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, "/Property...", 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/Sign", FALSE);
1402 menu_set_sensitive(ifactory, "/Options/Encrypt", FALSE);
1403 menu_set_sensitive(ifactory, "/Options/Priority", FALSE);
1404 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
1405 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1406 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1408 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1409 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1410 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1411 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1412 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1413 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1414 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1419 GList *compose_get_compose_list(void)
1421 return compose_list;
1424 void compose_entry_append(Compose *compose, const gchar *address,
1425 ComposeEntryType type)
1429 if (!address || *address == '\0') return;
1431 #if 0 /* NEW COMPOSE GUI */
1434 entry = GTK_ENTRY(compose->cc_entry);
1437 entry = GTK_ENTRY(compose->bcc_entry);
1439 case COMPOSE_NEWSGROUPS:
1440 entry = GTK_ENTRY(compose->newsgroups_entry);
1444 entry = GTK_ENTRY(compose->to_entry);
1448 text = gtk_entry_get_text(entry);
1450 gtk_entry_append_text(entry, ", ");
1451 gtk_entry_append_text(entry, address);
1459 header = N_("Bcc:");
1461 case COMPOSE_REPLYTO:
1462 header = N_("Reply-To:");
1464 case COMPOSE_NEWSGROUPS:
1465 header = N_("Newsgroups:");
1467 case COMPOSE_FOLLOWUPTO:
1468 header = N_( "Followup-To:");
1475 header = prefs_common.trans_hdr ? gettext(header) : header;
1477 compose_add_header_entry(compose, header, (gchar *)address);
1480 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1482 static GtkStyle *bold_style = NULL;
1483 static GdkColor bold_color;
1484 static GdkFont *bold_font = NULL;
1488 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1489 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1490 if (gtk_entry_get_text(entry) &&
1491 !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1492 gtk_widget_ensure_style(GTK_WIDGET(entry));
1494 gtkut_convert_int_to_gdk_color
1495 (prefs_common.color_new, &bold_color);
1496 bold_style = gtk_style_copy(gtk_widget_get_style
1497 (GTK_WIDGET(entry)));
1499 bold_font = gtkut_font_load
1500 (prefs_common.boldfont);
1502 bold_style->font = bold_font;
1503 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1505 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1510 void compose_toolbar_cb(gint action, gpointer data)
1512 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1513 Compose *compose = (Compose*)toolbar_item->parent;
1515 g_return_if_fail(compose != NULL);
1519 compose_send_cb(compose, 0, NULL);
1522 compose_send_later_cb(compose, 0, NULL);
1525 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1528 compose_insert_file_cb(compose, 0, NULL);
1531 compose_attach_cb(compose, 0, NULL);
1534 compose_insert_sig(compose, FALSE);
1537 compose_ext_editor_cb(compose, 0, NULL);
1539 case A_LINEWRAP_CURRENT:
1540 compose_wrap_line(compose);
1542 case A_LINEWRAP_ALL:
1543 compose_wrap_line_all(compose);
1546 compose_address_cb(compose, 0, NULL);
1549 case A_CHECK_SPELLING:
1550 compose_check_all(compose);
1558 static void compose_entries_set(Compose *compose, const gchar *mailto)
1563 gchar *subject = NULL;
1566 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1569 compose_entry_append(compose, to, COMPOSE_TO);
1571 compose_entry_append(compose, cc, COMPOSE_CC);
1573 compose_entry_append(compose, bcc, COMPOSE_BCC);
1575 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1577 gtk_stext_insert(GTK_STEXT(compose->text),
1578 NULL, NULL, NULL, body, -1);
1579 gtk_stext_insert(GTK_STEXT(compose->text),
1580 NULL, NULL, NULL, "\n", 1);
1590 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1592 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1593 {"Cc:", NULL, TRUE},
1594 {"References:", NULL, FALSE},
1595 {"Bcc:", NULL, TRUE},
1596 {"Newsgroups:", NULL, TRUE},
1597 {"Followup-To:", NULL, TRUE},
1598 {"List-Post:", NULL, FALSE},
1599 {"X-Priority:", NULL, FALSE},
1600 {NULL, NULL, FALSE}};
1616 g_return_val_if_fail(msginfo != NULL, -1);
1618 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1619 procheader_get_header_fields(fp, hentry);
1622 if (hentry[H_REPLY_TO].body != NULL) {
1623 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1624 compose->replyto = hentry[H_REPLY_TO].body;
1625 hentry[H_REPLY_TO].body = NULL;
1627 if (hentry[H_CC].body != NULL) {
1628 conv_unmime_header_overwrite(hentry[H_CC].body);
1629 compose->cc = hentry[H_CC].body;
1630 hentry[H_CC].body = NULL;
1632 if (hentry[H_REFERENCES].body != NULL) {
1633 if (compose->mode == COMPOSE_REEDIT)
1634 compose->references = hentry[H_REFERENCES].body;
1636 compose->references = compose_parse_references
1637 (hentry[H_REFERENCES].body, msginfo->msgid);
1638 g_free(hentry[H_REFERENCES].body);
1640 hentry[H_REFERENCES].body = NULL;
1642 if (hentry[H_BCC].body != NULL) {
1643 if (compose->mode == COMPOSE_REEDIT) {
1644 conv_unmime_header_overwrite(hentry[H_BCC].body);
1645 compose->bcc = hentry[H_BCC].body;
1647 g_free(hentry[H_BCC].body);
1648 hentry[H_BCC].body = NULL;
1650 if (hentry[H_NEWSGROUPS].body != NULL) {
1651 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1652 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1653 hentry[H_NEWSGROUPS].body = NULL;
1655 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1656 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1657 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1658 hentry[H_FOLLOWUP_TO].body = NULL;
1660 if (hentry[H_LIST_POST].body != NULL) {
1663 extract_address(hentry[H_LIST_POST].body);
1664 if (hentry[H_LIST_POST].body[0] != '\0') {
1665 scan_mailto_url(hentry[H_LIST_POST].body,
1666 &to, NULL, NULL, NULL, NULL);
1668 g_free(compose->ml_post);
1669 compose->ml_post = to;
1672 g_free(hentry[H_LIST_POST].body);
1673 hentry[H_LIST_POST].body = NULL;
1676 /* CLAWS - X-Priority */
1677 if (compose->mode == COMPOSE_REEDIT)
1678 if (hentry[H_X_PRIORITY].body != NULL) {
1681 priority = atoi(hentry[H_X_PRIORITY].body);
1682 g_free(hentry[H_X_PRIORITY].body);
1684 hentry[H_X_PRIORITY].body = NULL;
1686 if (priority < PRIORITY_HIGHEST ||
1687 priority > PRIORITY_LOWEST)
1688 priority = PRIORITY_NORMAL;
1690 compose->priority = priority;
1693 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1694 compose->inreplyto = g_strdup(msginfo->inreplyto);
1695 else if (compose->mode != COMPOSE_REEDIT &&
1696 msginfo->msgid && *msginfo->msgid) {
1697 compose->inreplyto = g_strdup(msginfo->msgid);
1699 if (!compose->references) {
1700 if (msginfo->inreplyto && *msginfo->inreplyto)
1701 compose->references =
1702 g_strdup_printf("<%s>\n\t<%s>",
1706 compose->references =
1707 g_strconcat("<", msginfo->msgid, ">",
1715 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1717 GSList *ref_id_list, *cur;
1721 ref_id_list = references_list_append(NULL, ref);
1722 if (!ref_id_list) return NULL;
1723 if (msgid && *msgid)
1724 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1729 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1730 /* "<" + Message-ID + ">" + CR+LF+TAB */
1731 len += strlen((gchar *)cur->data) + 5;
1733 if (len > MAX_REFERENCES_LEN) {
1734 /* remove second message-ID */
1735 if (ref_id_list && ref_id_list->next &&
1736 ref_id_list->next->next) {
1737 g_free(ref_id_list->next->data);
1738 ref_id_list = g_slist_remove
1739 (ref_id_list, ref_id_list->next->data);
1741 slist_free_strings(ref_id_list);
1742 g_slist_free(ref_id_list);
1749 new_ref = g_string_new("");
1750 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1751 if (new_ref->len > 0)
1752 g_string_append(new_ref, "\n\t");
1753 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1756 slist_free_strings(ref_id_list);
1757 g_slist_free(ref_id_list);
1759 new_ref_str = new_ref->str;
1760 g_string_free(new_ref, FALSE);
1765 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1766 const gchar *fmt, const gchar *qmark,
1769 GtkSText *text = GTK_STEXT(compose->text);
1770 static MsgInfo dummyinfo;
1771 gchar *quote_str = NULL;
1775 const gchar *trimmed_body = body;
1778 msginfo = &dummyinfo;
1780 if (qmark != NULL) {
1781 quote_fmt_init(msginfo, NULL, NULL);
1782 quote_fmt_scan_string(qmark);
1785 buf = quote_fmt_get_buffer();
1787 alertpanel_error(_("Quote mark format error."));
1789 Xstrdup_a(quote_str, buf, return NULL)
1792 if (fmt && *fmt != '\0') {
1793 while (trimmed_body && strlen(trimmed_body) > 1
1794 && trimmed_body[0]=='\n')
1797 quote_fmt_init(msginfo, quote_str, trimmed_body);
1798 quote_fmt_scan_string(fmt);
1801 buf = quote_fmt_get_buffer();
1803 alertpanel_error(_("Message reply/forward format error."));
1809 gtk_stext_freeze(text);
1811 for (p = buf; *p != '\0'; ) {
1812 lastp = strchr(p, '\n');
1813 len = lastp ? lastp - p + 1 : -1;
1814 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1821 gtk_stext_thaw(text);
1826 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1827 gboolean to_all, gboolean to_ml,
1829 gboolean followup_and_reply_to)
1831 GSList *cc_list = NULL;
1834 gchar *replyto = NULL;
1835 GHashTable *to_table;
1837 g_return_if_fail(compose->account != NULL);
1838 g_return_if_fail(msginfo != NULL);
1840 if (compose->account->protocol != A_NNTP) {
1841 if (!compose->replyto && to_ml && compose->ml_post
1842 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1843 compose_entry_append(compose,
1846 else if (!(to_all || to_sender)
1848 && msginfo->folder->prefs->enable_default_reply_to) {
1849 compose_entry_append(compose,
1850 msginfo->folder->prefs->default_reply_to,
1853 compose_entry_append(compose,
1854 (compose->replyto && !to_sender)
1855 ? compose->replyto :
1856 msginfo->from ? msginfo->from : "",
1859 if (to_sender || (compose->followup_to &&
1860 !strncmp(compose->followup_to, "poster", 6)))
1861 compose_entry_append
1863 (compose->replyto ? compose->replyto :
1864 msginfo->from ? msginfo->from : ""),
1867 else if (followup_and_reply_to || to_all) {
1868 compose_entry_append
1870 (compose->replyto ? compose->replyto :
1871 msginfo->from ? msginfo->from : ""),
1874 compose_entry_append
1876 compose->followup_to ? compose->followup_to :
1877 compose->newsgroups ? compose->newsgroups : "",
1878 COMPOSE_NEWSGROUPS);
1881 compose_entry_append
1883 compose->followup_to ? compose->followup_to :
1884 compose->newsgroups ? compose->newsgroups : "",
1885 COMPOSE_NEWSGROUPS);
1888 if (msginfo->subject && *msginfo->subject) {
1892 buf = p = g_strdup(msginfo->subject);
1893 p += subject_get_prefix_length(p);
1894 memmove(buf, p, strlen(p) + 1);
1896 buf2 = g_strdup_printf("Re: %s", buf);
1897 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1902 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1904 if (to_ml && compose->ml_post) return;
1905 if (!to_all || compose->account->protocol == A_NNTP) return;
1907 if (compose->replyto) {
1908 Xstrdup_a(replyto, compose->replyto, return);
1909 extract_address(replyto);
1911 if (msginfo->from) {
1912 Xstrdup_a(from, msginfo->from, return);
1913 extract_address(from);
1916 if (replyto && from)
1917 cc_list = address_list_append_with_comments(cc_list, from);
1918 if (to_all && msginfo->folder &&
1919 msginfo->folder->prefs->enable_default_reply_to)
1920 cc_list = address_list_append_with_comments(cc_list,
1921 msginfo->folder->prefs->default_reply_to);
1922 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1923 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1925 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1927 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1928 if (compose->account)
1929 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1930 GINT_TO_POINTER(1));
1932 /* remove address on To: and that of current account */
1933 for (cur = cc_list; cur != NULL; ) {
1934 GSList *next = cur->next;
1937 addr = g_strdup(cur->data);
1938 extract_address(addr);
1940 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
1941 cc_list = g_slist_remove(cc_list, cur->data);
1943 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
1947 hash_free_strings(to_table);
1948 g_hash_table_destroy(to_table);
1951 for (cur = cc_list; cur != NULL; cur = cur->next)
1952 compose_entry_append(compose, (gchar *)cur->data,
1954 slist_free_strings(cc_list);
1955 g_slist_free(cc_list);
1960 #define SET_ENTRY(entry, str) \
1963 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1966 #define SET_ADDRESS(type, str) \
1969 compose_entry_append(compose, str, type); \
1972 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1974 g_return_if_fail(msginfo != NULL);
1976 SET_ENTRY(subject_entry, msginfo->subject);
1977 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1978 SET_ADDRESS(COMPOSE_CC, compose->cc);
1979 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1980 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1981 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
1982 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
1984 compose_update_priority_menu_item(compose);
1985 compose_update_privacy_system_menu_item(compose);
1986 compose_show_first_last_header(compose, TRUE);
1992 static void compose_insert_sig(Compose *compose, gboolean replace)
1994 GtkSText *text = GTK_STEXT(compose->text);
1998 g_return_if_fail(compose->account != NULL);
2000 cur_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2002 gtk_stext_freeze(text);
2005 len = gtk_stext_get_length(text);
2006 gtk_stext_set_point(text, len);
2009 if (replace && compose->sig_str) {
2012 if (compose->sig_str[0] == '\0')
2015 pos = gtkut_stext_find(text, 0, compose->sig_str, TRUE);
2018 len = get_mbs_len(compose->sig_str);
2020 gtk_stext_set_point(text, pos);
2021 gtk_stext_forward_delete(text, len);
2026 g_free(compose->sig_str);
2027 compose->sig_str = compose_get_signature_str(compose);
2028 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2029 compose->sig_str = g_strdup("");
2031 gtk_stext_insert(text, NULL, NULL, NULL, compose->sig_str, -1);
2033 gtk_stext_thaw(text);
2035 if (cur_pos > gtk_stext_get_length(text))
2036 cur_pos = gtk_stext_get_length(text);
2038 gtk_editable_set_position(GTK_EDITABLE(text), cur_pos);
2039 gtk_stext_set_point(text, cur_pos);
2042 static gchar *compose_get_signature_str(Compose *compose)
2044 gchar *sig_body = NULL;
2045 gchar *sig_str = NULL;
2047 g_return_val_if_fail(compose->account != NULL, NULL);
2049 if (!compose->account->sig_path)
2052 if (compose->account->sig_type == SIG_FILE) {
2053 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2054 g_warning("can't open signature file: %s\n",
2055 compose->account->sig_path);
2060 if (compose->account->sig_type == SIG_COMMAND)
2061 sig_body = get_command_output(compose->account->sig_path);
2065 tmp = file_read_to_str(compose->account->sig_path);
2068 sig_body = normalize_newlines(tmp);
2072 if (compose->account->sig_sep)
2073 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2076 sig_str = g_strconcat("\n\n", sig_body, NULL);
2083 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2085 GtkSText *text = GTK_STEXT(compose->text);
2086 gchar buf[BUFFSIZE];
2089 gboolean badtxt = FALSE;
2091 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2093 if ((fp = fopen(file, "rb")) == NULL) {
2094 FILE_OP_ERROR(file, "fopen");
2095 return COMPOSE_INSERT_READ_ERROR;
2098 gtk_stext_freeze(text);
2100 while (fgets(buf, sizeof(buf), fp) != NULL) {
2101 /* strip <CR> if DOS/Windows file,
2102 replace <CR> with <LF> if Macintosh file. */
2105 if (len > 0 && buf[len - 1] != '\n') {
2107 if (buf[len] == '\r') buf[len] = '\n';
2109 if (mbstowcs(NULL, buf, 0) == -1)
2111 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
2114 gtk_stext_thaw(text);
2119 return COMPOSE_INSERT_INVALID_CHARACTER;
2121 return COMPOSE_INSERT_SUCCESS;
2124 static void compose_attach_append(Compose *compose, const gchar *file,
2125 const gchar *filename,
2126 const gchar *content_type)
2129 gchar *text[N_ATTACH_COLS];
2134 if (!is_file_exist(file)) {
2135 g_warning("File %s doesn't exist\n", file);
2138 if ((size = get_file_size(file)) < 0) {
2139 g_warning("Can't get file size of %s\n", file);
2143 alertpanel_notice(_("File %s is empty."), file);
2146 if ((fp = fopen(file, "rb")) == NULL) {
2147 alertpanel_error(_("Can't read %s."), file);
2152 #if 0 /* NEW COMPOSE GUI */
2153 if (!compose->use_attach) {
2154 GtkItemFactory *ifactory;
2156 ifactory = gtk_item_factory_from_widget(compose->menubar);
2157 menu_set_active(ifactory, "/View/Attachment", TRUE);
2160 ainfo = g_new0(AttachInfo, 1);
2161 ainfo->file = g_strdup(file);
2164 ainfo->content_type = g_strdup(content_type);
2165 if (!g_strcasecmp(content_type, "message/rfc822")) {
2167 MsgFlags flags = {0, 0};
2170 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2171 ainfo->encoding = ENC_7BIT;
2173 ainfo->encoding = ENC_8BIT;
2175 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2176 if (msginfo && msginfo->subject)
2177 name = msginfo->subject;
2179 name = g_basename(filename ? filename : file);
2181 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2183 procmsg_msginfo_free(msginfo);
2185 if (!g_strncasecmp(content_type, "text", 4))
2186 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2188 ainfo->encoding = ENC_BASE64;
2189 ainfo->name = g_strdup
2190 (g_basename(filename ? filename : file));
2193 ainfo->content_type = procmime_get_mime_type(file);
2194 if (!ainfo->content_type) {
2195 ainfo->content_type =
2196 g_strdup("application/octet-stream");
2197 ainfo->encoding = ENC_BASE64;
2198 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
2200 procmime_get_encoding_for_text_file(file);
2202 ainfo->encoding = ENC_BASE64;
2203 ainfo->name = g_strdup(g_basename(filename ? filename : file));
2206 if (!strcmp(ainfo->content_type, "unknown")) {
2207 g_free(ainfo->content_type);
2208 ainfo->content_type = g_strdup("application/octet-stream");
2213 text[COL_MIMETYPE] = ainfo->content_type;
2214 text[COL_SIZE] = to_human_readable(size);
2215 text[COL_NAME] = ainfo->name;
2217 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2218 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2221 static void compose_use_signing(Compose *compose, gboolean use_signing)
2223 GtkItemFactory *ifactory;
2224 GtkWidget *menuitem = NULL;
2226 compose->use_signing = use_signing;
2227 ifactory = gtk_item_factory_from_widget(compose->menubar);
2228 menuitem = gtk_item_factory_get_item
2229 (ifactory, "/Options/Sign");
2230 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2234 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2236 GtkItemFactory *ifactory;
2237 GtkWidget *menuitem = NULL;
2239 compose->use_encryption = use_encryption;
2240 ifactory = gtk_item_factory_from_widget(compose->menubar);
2241 menuitem = gtk_item_factory_get_item
2242 (ifactory, "/Options/Encrypt");
2244 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2248 #define NEXT_PART_NOT_CHILD(info) \
2250 node = info->node; \
2251 while (node->children) \
2252 node = g_node_last_child(node); \
2253 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2256 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2260 MimeInfo *firsttext = NULL;
2261 MimeInfo *encrypted = NULL;
2264 const gchar *partname = NULL;
2266 mimeinfo = procmime_scan_message(msginfo);
2267 if (!mimeinfo) return;
2269 if (mimeinfo->node->children == NULL) {
2270 procmime_mimeinfo_free_all(mimeinfo);
2274 /* find first content part */
2275 child = (MimeInfo *) mimeinfo->node->children->data;
2276 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2277 child = (MimeInfo *)child->node->children->data;
2279 if (child->type == MIMETYPE_TEXT) {
2281 debug_print("First text part found\n");
2282 } else if (compose->mode == COMPOSE_REEDIT &&
2283 child->type == MIMETYPE_APPLICATION &&
2284 !g_strcasecmp(child->subtype, "pgp-encrypted")) {
2286 val = alertpanel(_("Encrypted message"),
2287 _("Cannot re-edit an encrypted message. \n"
2288 "Discard encrypted part?"),
2289 _("Yes"), _("No"), NULL);
2290 if (val == G_ALERTDEFAULT)
2291 encrypted = (MimeInfo *)child->node->parent->data;
2294 child = (MimeInfo *) mimeinfo->node->children->data;
2295 while (child != NULL) {
2296 if (child == encrypted) {
2297 /* skip this part of tree */
2298 NEXT_PART_NOT_CHILD(child);
2302 if (child->type == MIMETYPE_MULTIPART) {
2303 /* get the actual content */
2304 child = procmime_mimeinfo_next(child);
2308 if (child == firsttext) {
2309 child = procmime_mimeinfo_next(child);
2313 outfile = procmime_get_tmp_file_name(child);
2314 if (procmime_get_part(outfile, child) < 0)
2315 g_warning("Can't get the part of multipart message.");
2317 gchar *content_type;
2319 content_type = procmime_get_content_type_str(child->type, child->subtype);
2320 partname = procmime_mimeinfo_get_parameter(child, "name");
2321 if (partname == NULL)
2323 compose_attach_append(compose, outfile,
2324 partname, content_type);
2325 g_free(content_type);
2328 NEXT_PART_NOT_CHILD(child);
2330 procmime_mimeinfo_free_all(mimeinfo);
2333 #undef NEXT_PART_NOT_CHILD
2335 #define GET_CHAR(pos, buf, len) \
2337 if (text->use_wchar) \
2338 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2340 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2345 #define DISP_WIDTH(len) \
2346 ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
2347 (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
2349 #define SPACE_CHARS " \t"
2351 static void compose_wrap_line(Compose *compose)
2353 GtkSText *text = GTK_STEXT(compose->text);
2354 gint ch_len, last_ch_len;
2355 gchar cbuf[MB_LEN_MAX], last_ch;
2359 gint p_start, p_end;
2360 gint line_pos, cur_pos;
2361 gint line_len, cur_len;
2363 gtk_stext_freeze(text);
2365 text_len = gtk_stext_get_length(text);
2367 /* check to see if the point is on the paragraph mark (empty line). */
2368 cur_pos = gtk_stext_get_point(text);
2369 GET_CHAR(cur_pos, cbuf, ch_len);
2370 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2372 goto compose_end; /* on the paragraph mark */
2373 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2374 if (ch_len == 1 && *cbuf == '\n')
2375 goto compose_end; /* on the paragraph mark */
2378 /* find paragraph start. */
2379 line_end = quoted = 0;
2380 for (p_start = cur_pos; p_start >= 0; --p_start) {
2381 GET_CHAR(p_start, cbuf, ch_len);
2382 if (ch_len == 1 && *cbuf == '\n') {
2384 goto compose_end; /* quoted part */
2392 && strchr(prefs_common.quote_chars, *cbuf))
2394 else if (ch_len != 1 || !isspace(*(guchar *)cbuf))
2403 /* find paragraph end. */
2405 for (p_end = cur_pos; p_end < text_len; p_end++) {
2406 GET_CHAR(p_end, cbuf, ch_len);
2407 if (ch_len == 1 && *cbuf == '\n') {
2414 if (line_end && ch_len == 1 &&
2415 strchr(prefs_common.quote_chars, *cbuf))
2416 goto compose_end; /* quoted part */
2421 if (p_end >= text_len)
2424 if (p_start >= p_end)
2427 line_len = cur_len = 0;
2431 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2434 GET_CHAR(cur_pos, cbuf, ch_len);
2441 if (ch_len == 1 && isspace(*(guchar *)cbuf))
2444 if (ch_len == 1 && *cbuf == '\n') {
2446 if (last_ch_len == 1 && !isspace((guchar)last_ch)) {
2447 if (cur_pos + 1 < p_end) {
2448 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2450 !isspace(*(guchar *)cbuf))
2454 gtk_stext_set_point(text, cur_pos + 1);
2455 gtk_stext_backward_delete(text, 1);
2457 gtk_stext_set_point(text, cur_pos);
2458 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2468 last_ch_len = ch_len;
2472 line_pos = cur_pos + 1;
2473 line_len = cur_len + ch_len;
2476 if (cur_len + DISP_WIDTH(ch_len) > prefs_common.linewrap_len &&
2480 GET_CHAR(line_pos - 1, cbuf, ch_len);
2481 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2482 gtk_stext_set_point(text, line_pos);
2483 gtk_stext_backward_delete(text, 1);
2492 gtk_stext_set_point(text, line_pos);
2493 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2497 cur_len = cur_len - line_len + DISP_WIDTH(ch_len);
2503 line_pos = cur_pos + 1;
2504 line_len = cur_len + DISP_WIDTH(ch_len);
2506 cur_len += DISP_WIDTH(ch_len);
2510 gtk_stext_thaw(text);
2515 /* Darko: used when I debug wrapping */
2516 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2519 gchar cbuf[MB_LEN_MAX];
2521 printf("%d [", pos);
2522 for (i = pos; i < tlen; i++) {
2523 GET_CHAR(i, cbuf, clen);
2524 if (clen < 0) break;
2525 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2527 fwrite(cbuf, clen, 1, stdout);
2535 WAIT_FOR_INDENT_CHAR,
2536 WAIT_FOR_INDENT_CHAR_OR_SPACE
2539 /* return indent length, we allow:
2540 > followed by spaces/tabs
2541 | followed by spaces/tabs
2542 uppercase characters immediately followed by >,
2543 and the repeating sequences of the above */
2544 /* return indent length */
2545 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2548 guint i, ch_len, alnum_cnt = 0;
2549 IndentState state = WAIT_FOR_INDENT_CHAR;
2550 gchar cbuf[MB_LEN_MAX];
2554 if (prefs_common.quote_chars == NULL) {
2558 for (i = start_pos; i < text_len; i++) {
2559 GET_CHAR(i, cbuf, ch_len);
2563 if (cbuf[0] == '\n')
2566 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2567 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2570 case WAIT_FOR_SPACE:
2571 if (is_space == FALSE)
2573 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2575 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2576 if (is_indent == FALSE && is_space == FALSE &&
2577 !isupper((guchar)cbuf[0]))
2579 if (is_space == TRUE) {
2581 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2582 } else if (is_indent == TRUE) {
2584 state = WAIT_FOR_SPACE;
2587 state = WAIT_FOR_INDENT_CHAR;
2590 case WAIT_FOR_INDENT_CHAR:
2591 if (is_indent == FALSE && !isupper((guchar)cbuf[0]))
2593 if (is_indent == TRUE) {
2595 && !strchr(prefs_common.quote_chars, cbuf[0]))
2598 state = WAIT_FOR_SPACE;
2609 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2615 /* insert quotation string when line was wrapped */
2616 static guint ins_quote(GtkSText *text, guint indent_len,
2617 guint prev_line_pos, guint text_len,
2620 guint i, ins_len = 0;
2624 for (i = 0; i < indent_len; i++) {
2625 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2626 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2628 ins_len = indent_len;
2634 /* check if we should join the next line */
2635 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2636 guint prev_ilen, gboolean autowrap)
2638 guint indent_len, ch_len;
2639 gboolean do_join = FALSE;
2640 gchar cbuf[MB_LEN_MAX];
2642 indent_len = get_indent_length(text, start_pos, tlen);
2644 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2645 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2646 if (ch_len > 0 && (cbuf[0] != '\n'))
2653 static void compose_wrap_line_all(Compose *compose)
2655 compose_wrap_line_all_full(compose, FALSE);
2658 #define STEXT_FREEZE() \
2659 if (!frozen) { gtk_stext_freeze(text); frozen = TRUE; }
2661 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2663 GtkSText *text = GTK_STEXT(compose->text);
2665 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2666 gint line_len = 0, cur_len = 0;
2668 gboolean is_new_line = TRUE, do_delete = FALSE;
2670 gboolean linewrap_quote = prefs_common.linewrap_quote;
2671 gboolean set_editable_pos = FALSE;
2672 gint editable_pos = 0;
2673 gboolean frozen = FALSE;
2674 guint linewrap_len = prefs_common.linewrap_len;
2675 gchar *qfmt = prefs_common.quotemark;
2676 gchar cbuf[MB_LEN_MAX];
2678 tlen = gtk_stext_get_length(text);
2680 for (; cur_pos < tlen; cur_pos++) {
2681 /* mark position of new line - needed for quotation wrap */
2684 i_len = get_indent_length(text, cur_pos, tlen);
2686 is_new_line = FALSE;
2689 g_print("new line i_len=%d p_pos=", i_len);
2690 dump_text(text, p_pos, tlen, 1);
2694 GET_CHAR(cur_pos, cbuf, ch_len);
2696 /* fix line length for tabs */
2697 if (ch_len == 1 && *cbuf == '\t') {
2698 guint tab_width = text->default_tab_width;
2699 guint tab_offset = line_len % tab_width;
2702 g_print("found tab at pos=%d line_len=%d ", cur_pos,
2706 line_len += tab_width - tab_offset - 1;
2710 printf("new_len=%d\n", line_len);
2714 /* we have encountered line break */
2715 if (ch_len == 1 && *cbuf == '\n') {
2717 gchar cb[MB_LEN_MAX];
2719 /* should we join the next line */
2720 if ((autowrap || i_len != cur_len) && do_delete &&
2722 (text, cur_pos + 1, tlen, i_len, autowrap))
2728 g_print("found CR at %d do_del is %d next line is ",
2729 cur_pos, do_delete);
2730 dump_text(text, cur_pos + 1, tlen, 1);
2733 /* skip delete if it is continuous URL */
2734 if (do_delete && (line_pos - p_pos <= i_len) &&
2735 gtk_stext_is_uri_string(text, line_pos, tlen))
2739 g_print("l_len=%d wrap_len=%d do_del=%d\n",
2740 line_len, linewrap_len, do_delete);
2742 if (line_len < linewrap_len && do_delete) {
2744 /* get rid of newline */
2745 gtk_stext_set_point(text, cur_pos);
2746 gtk_stext_forward_delete(text, 1);
2749 /* if text starts with quote fmt or with
2750 indent string, delete them */
2753 ilen = gtk_stext_str_compare_n
2754 (text, cur_pos, p_pos, i_len,
2757 gtk_stext_forward_delete
2763 GET_CHAR(cur_pos, cb, clen);
2765 /* insert space if it's alphanumeric */
2766 if ((cur_pos != line_pos) &&
2767 ((clen > 1) || isalnum((guchar)cb[0]))) {
2768 gtk_stext_insert(text, NULL, NULL,
2773 /* and start over with current line */
2774 cur_pos = p_pos - 1;
2776 line_len = cur_len = 0;
2780 g_print("after delete l_pos=");
2781 dump_text(text, line_pos, tlen, 1);
2783 /* move beginning of line if we are on LF */
2784 GET_CHAR(line_pos, cb, clen);
2785 if (clen == 1 && *cb == '\n')
2788 g_print("new line_pos=%d\n", line_pos);
2794 /* mark new line beginning */
2795 line_pos = cur_pos + 1;
2796 line_len = cur_len = 0;
2807 /* possible line break */
2808 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2809 line_pos = cur_pos + 1;
2810 line_len = cur_len + ch_len;
2813 /* are we over wrapping length set in preferences ? */
2814 if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
2818 g_print("should wrap cur_pos=%d ", cur_pos);
2819 dump_text(text, p_pos, tlen, 1);
2820 dump_text(text, line_pos, tlen, 1);
2822 /* force wrapping if it is one long word but not URL */
2823 if (line_pos - p_pos <= i_len)
2824 if (!gtk_stext_is_uri_string
2825 (text, line_pos, tlen))
2826 line_pos = cur_pos - 1;
2828 g_print("new line_pos=%d\n", line_pos);
2831 GET_CHAR(line_pos - 1, cbuf, clen);
2833 /* if next character is space delete it */
2834 if (clen == 1 && isspace(*(guchar *)cbuf)) {
2835 if (p_pos + i_len != line_pos ||
2836 !gtk_stext_is_uri_string
2837 (text, line_pos, tlen)) {
2839 /* workaround for correct cursor
2841 if (set_editable_pos == FALSE) {
2842 editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2843 if (editable_pos == line_pos)
2844 set_editable_pos = TRUE;
2846 gtk_stext_set_point(text, line_pos);
2847 gtk_stext_backward_delete(text, 1);
2856 /* if it is URL at beginning of line don't wrap */
2857 if (p_pos + i_len == line_pos &&
2858 gtk_stext_is_uri_string(text, line_pos, tlen)) {
2860 g_print("found URL at ");
2861 dump_text(text, line_pos, tlen, 1);
2868 gtk_stext_set_point(text, line_pos);
2869 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2870 gtk_stext_compact_buffer(text);
2873 /* for loop will increase it */
2874 cur_pos = line_pos - 1;
2875 /* start over with current line */
2877 line_len = cur_len = 0;
2878 if (autowrap || i_len > 0)
2883 g_print("after CR insert ");
2884 dump_text(text, line_pos, tlen, 1);
2885 dump_text(text, cur_pos, tlen, 1);
2888 /* should we insert quotation ? */
2889 if (linewrap_quote && i_len) {
2890 /* only if line is not already quoted */
2891 if (!gtk_stext_str_compare
2892 (text, line_pos, tlen, qfmt)) {
2895 if (line_pos - p_pos > i_len) {
2897 (text, i_len, p_pos,
2902 g_print("after quote insert ");
2903 dump_text(text, line_pos, tlen, 1);
2911 line_pos = cur_pos + 1;
2912 line_len = cur_len + DISP_WIDTH(ch_len);
2914 /* advance to next character in buffer */
2915 cur_len += DISP_WIDTH(ch_len);
2919 gtk_stext_thaw(text);
2921 if (set_editable_pos && editable_pos <= tlen)
2922 gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
2928 static void compose_set_title(Compose *compose)
2933 edited = compose->modified ? _(" [Edited]") : "";
2934 if (compose->account && compose->account->address)
2935 str = g_strdup_printf(_("%s - Compose message%s"),
2936 compose->account->address, edited);
2938 str = g_strdup_printf(_("Compose message%s"), edited);
2939 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2944 * compose_current_mail_account:
2946 * Find a current mail account (the currently selected account, or the
2947 * default account, if a news account is currently selected). If a
2948 * mail account cannot be found, display an error message.
2950 * Return value: Mail account, or NULL if not found.
2952 static PrefsAccount *
2953 compose_current_mail_account(void)
2957 if (cur_account && cur_account->protocol != A_NNTP)
2960 ac = account_get_default();
2961 if (!ac || ac->protocol == A_NNTP) {
2962 alertpanel_error(_("Account for sending mail is not specified.\n"
2963 "Please select a mail account before sending."));
2970 static void compose_select_account(Compose *compose, PrefsAccount *account,
2973 GtkItemFactory *ifactory;
2975 g_return_if_fail(account != NULL);
2977 compose->account = account;
2979 compose_set_title(compose);
2981 ifactory = gtk_item_factory_from_widget(compose->menubar);
2983 if (account->protocol == A_NNTP) {
2984 gtk_widget_show(compose->newsgroups_hbox);
2985 gtk_widget_show(compose->newsgroups_entry);
2986 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2987 compose->use_newsgroups = TRUE;
2989 menu_set_active(ifactory, "/View/To", FALSE);
2990 menu_set_sensitive(ifactory, "/View/To", TRUE);
2991 menu_set_active(ifactory, "/View/Cc", FALSE);
2992 menu_set_sensitive(ifactory, "/View/Cc", TRUE);
2993 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
2995 gtk_widget_hide(compose->newsgroups_hbox);
2996 gtk_widget_hide(compose->newsgroups_entry);
2997 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
2998 gtk_widget_queue_resize(compose->table_vbox);
2999 compose->use_newsgroups = FALSE;
3001 menu_set_active(ifactory, "/View/To", TRUE);
3002 menu_set_sensitive(ifactory, "/View/To", FALSE);
3003 menu_set_active(ifactory, "/View/Cc", TRUE);
3004 menu_set_sensitive(ifactory, "/View/Cc", FALSE);
3005 menu_set_active(ifactory, "/View/Followup to", FALSE);
3006 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
3009 if (account->set_autocc) {
3010 compose_entry_show(compose, COMPOSE_ENTRY_CC);
3011 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
3012 compose_entry_set(compose, account->auto_cc,
3015 if (account->set_autobcc) {
3016 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
3017 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
3018 compose_entry_set(compose, account->auto_bcc,
3021 if (account->set_autoreplyto) {
3022 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
3023 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
3024 compose_entry_set(compose, account->auto_replyto,
3025 COMPOSE_ENTRY_REPLY_TO);
3030 if (account->default_sign)
3031 menu_set_active(ifactory, "/Options/Sign", TRUE);
3033 menu_set_active(ifactory, "/Options/Sign", FALSE);
3034 if (account->default_encrypt)
3035 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3037 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3039 activate_privacy_system(compose, account);
3041 if (!init && compose->mode != COMPOSE_REDIRECT)
3042 compose_insert_sig(compose, TRUE);
3045 gboolean compose_check_for_valid_recipient(Compose *compose) {
3046 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3047 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3048 gboolean recipient_found = FALSE;
3052 /* free to and newsgroup list */
3053 slist_free_strings(compose->to_list);
3054 g_slist_free(compose->to_list);
3055 compose->to_list = NULL;
3057 slist_free_strings(compose->newsgroup_list);
3058 g_slist_free(compose->newsgroup_list);
3059 compose->newsgroup_list = NULL;
3061 /* search header entries for to and newsgroup entries */
3062 for (list = compose->header_list; list; list = list->next) {
3065 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3066 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3068 if (entry[0] != '\0') {
3069 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3070 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3071 compose->to_list = address_list_append(compose->to_list, entry);
3072 recipient_found = TRUE;
3075 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3076 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3077 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3078 recipient_found = TRUE;
3085 return recipient_found;
3088 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3092 if (compose_check_for_valid_recipient(compose) == FALSE) {
3093 alertpanel_error(_("Recipient is not specified."));
3097 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3098 if (*str == '\0' && check_subject == TRUE) {
3101 aval = alertpanel(_("Send"),
3102 _("Subject is empty. Send it anyway?"),
3103 _("Yes"), _("No"), NULL);
3104 if (aval != G_ALERTDEFAULT)
3111 gint compose_send(Compose *compose)
3118 compose_allow_user_actions (compose, FALSE);
3119 compose->sending = TRUE;
3121 if (compose_check_entries(compose, TRUE) == FALSE)
3124 val = compose_queue(compose, &msgnum, &folder);
3127 alertpanel_error(_("Could not queue message for sending"));
3132 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3133 compose->sending = FALSE;
3134 compose_close(compose);
3135 /* No more compose access in the normal codepath
3136 * after this point! */
3140 alertpanel_error(_("The message was queued but could not be "
3141 "sent.\nUse \"Send queued messages\" from "
3142 "the main window to retry."));
3143 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3144 compose->sending = FALSE;
3145 compose_allow_user_actions (compose, TRUE);
3150 msgpath = folder_item_fetch_msg(folder, msgnum);
3151 val = procmsg_send_message_queue(msgpath);
3154 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3155 compose->sending = FALSE;
3156 compose_allow_user_actions (compose, TRUE);
3158 folder_item_remove_msg(folder, msgnum);
3159 folder_item_scan(folder);
3164 folder_item_remove_msg(folder, msgnum);
3165 folder_item_scan(folder);
3166 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3167 compose_close(compose);
3169 alertpanel_error(_("The message was queued but could not be "
3170 "sent.\nUse \"Send queued messages\" from "
3171 "the main window to retry."));
3172 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3173 compose_allow_user_actions (compose, TRUE);
3174 compose->sending = FALSE;
3182 compose_allow_user_actions (compose, TRUE);
3183 compose->sending = FALSE;
3188 static gboolean compose_use_attach(Compose *compose)
3190 return gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL;
3193 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3196 gchar buf[BUFFSIZE];
3198 gboolean first_to_address;
3199 gboolean first_cc_address;
3201 ComposeHeaderEntry *headerentry;
3202 gchar *headerentryname;
3206 debug_print("Writing redirect header\n");
3208 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3209 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3211 first_to_address = TRUE;
3212 first_cc_address = TRUE;
3213 for (list = compose->header_list; list; list = list->next) {
3214 headerentry = ((ComposeHeaderEntry *)list->data);
3215 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3217 if (g_strcasecmp(headerentryname, cc_hdr) == 0
3218 || g_strcasecmp(headerentryname, to_hdr) == 0) {
3219 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3220 Xstrdup_a(str, str, return -1);
3222 if (str[0] != '\0') {
3223 compose_convert_header
3224 (buf, sizeof(buf), str,
3225 strlen("Resent-To") + 2, TRUE);
3226 if (g_strcasecmp(headerentryname, to_hdr) == 0) {
3227 if (first_to_address) {
3228 fprintf(fp, "Resent-To: ");
3229 first_to_address = FALSE;
3234 if (g_strcasecmp(headerentryname, cc_hdr) == 0) {
3235 if (first_cc_address) {
3237 fprintf(fp, "Resent-Cc: ");
3238 first_cc_address = FALSE;
3244 fprintf(fp, "%s", buf);
3248 /* if (!first_address) { */
3255 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3257 gchar buf[BUFFSIZE];
3259 /* struct utsname utsbuf; */
3261 g_return_val_if_fail(fp != NULL, -1);
3262 g_return_val_if_fail(compose->account != NULL, -1);
3263 g_return_val_if_fail(compose->account->address != NULL, -1);
3266 get_rfc822_date(buf, sizeof(buf));
3267 fprintf(fp, "Resent-Date: %s\n", buf);
3270 if (compose->account->name && *compose->account->name) {
3271 compose_convert_header
3272 (buf, sizeof(buf), compose->account->name,
3273 strlen("From: "), TRUE);
3274 fprintf(fp, "Resent-From: %s <%s>\n",
3275 buf, compose->account->address);
3277 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3280 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3282 Xstrdup_a(str, str, return -1);
3285 compose_convert_header(buf, sizeof(buf), str,
3286 strlen("Subject: "), FALSE);
3287 fprintf(fp, "Subject: %s\n", buf);
3291 /* Resent-Message-ID */
3292 if (compose->account->gen_msgid) {
3293 generate_msgid(buf, sizeof(buf));
3294 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3295 compose->msgid = g_strdup(buf);
3298 compose_redirect_write_headers_from_headerlist(compose, fp);
3300 /* separator between header and body */
3306 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3310 gchar buf[BUFFSIZE];
3312 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3313 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3317 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3318 /* should filter returnpath, delivered-to */
3319 if (g_strncasecmp(buf, "Return-Path:",
3320 strlen("Return-Path:")) == 0 ||
3321 g_strncasecmp(buf, "Delivered-To:",
3322 strlen("Delivered-To:")) == 0 ||
3323 g_strncasecmp(buf, "Received:",
3324 strlen("Received:")) == 0 ||
3325 g_strncasecmp(buf, "Subject:",
3326 strlen("Subject:")) == 0 ||
3327 g_strncasecmp(buf, "X-UIDL:",
3328 strlen("X-UIDL:")) == 0)
3331 if (fputs(buf, fdest) == -1)
3334 if (!prefs_common.redirect_keep_from) {
3335 if (g_strncasecmp(buf, "From:",
3336 strlen("From:")) == 0) {
3337 fputs(" (by way of ", fdest);
3338 if (compose->account->name
3339 && *compose->account->name) {
3340 compose_convert_header
3342 compose->account->name,
3345 fprintf(fdest, "%s <%s>",
3347 compose->account->address);
3349 fprintf(fdest, "%s",
3350 compose->account->address);
3355 if (fputs("\n", fdest) == -1)
3359 compose_redirect_write_headers(compose, fdest);
3361 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3362 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
3375 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
3379 const gchar *out_codeset;
3380 EncodingType encoding;
3381 MimeInfo *mimemsg, *mimetext;
3383 /* create message MimeInfo */
3384 mimemsg = procmime_mimeinfo_new();
3385 mimemsg->type = MIMETYPE_MESSAGE;
3386 mimemsg->subtype = g_strdup("rfc822");
3387 mimemsg->content = MIMECONTENT_MEM;
3388 mimemsg->data.mem = compose_get_header(compose);
3390 /* Create text part MimeInfo */
3391 /* get all composed text */
3392 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3393 if (is_ascii_str(chars)) {
3396 out_codeset = CS_US_ASCII;
3397 encoding = ENC_7BIT;
3399 const gchar *src_codeset;
3401 out_codeset = conv_get_outgoing_charset_str();
3402 if (!g_strcasecmp(out_codeset, CS_US_ASCII))
3403 out_codeset = CS_ISO_8859_1;
3405 if (prefs_common.encoding_method == CTE_BASE64)
3406 encoding = ENC_BASE64;
3407 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3408 encoding = ENC_QUOTED_PRINTABLE;
3409 else if (prefs_common.encoding_method == CTE_8BIT)
3410 encoding = ENC_8BIT;
3412 encoding = procmime_get_encoding_for_charset(out_codeset);
3414 src_codeset = conv_get_current_charset_str();
3415 /* if current encoding is US-ASCII, set it the same as
3416 outgoing one to prevent code conversion failure */
3417 if (!g_strcasecmp(src_codeset, CS_US_ASCII))
3418 src_codeset = out_codeset;
3420 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3421 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3423 if (action == COMPOSE_WRITE_FOR_SEND) {
3424 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3429 msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
3431 "Send it anyway?"), src_codeset, out_codeset);
3432 aval = alertpanel_with_type
3433 (_("Error"), msg, _("Yes"), _("+No"), NULL, NULL, ALERT_ERROR);
3436 if (aval != G_ALERTDEFAULT) {
3441 out_codeset = src_codeset;
3447 out_codeset = src_codeset;
3453 mimetext = procmime_mimeinfo_new();
3454 mimetext->content = MIMECONTENT_MEM;
3455 mimetext->data.mem = buf;
3456 mimetext->type = MIMETYPE_TEXT;
3457 mimetext->subtype = g_strdup("plain");
3458 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
3459 g_strdup(out_codeset));
3460 if (encoding != ENC_UNKNOWN)
3461 procmime_encode_content(mimetext, encoding);
3463 /* append attachment parts */
3464 if (compose_use_attach(compose)) {
3465 MimeInfo *mimempart;
3467 mimempart = procmime_mimeinfo_new();
3468 mimempart->content = MIMECONTENT_EMPTY;
3469 mimempart->type = MIMETYPE_MULTIPART;
3470 mimempart->subtype = g_strdup("mixed");
3471 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
3472 generate_mime_boundary(NULL));
3474 mimetext->disposition = DISPOSITIONTYPE_INLINE;
3476 g_node_append(mimempart->node, mimetext->node);
3477 g_node_append(mimemsg->node, mimempart->node);
3479 compose_add_attachments(compose, mimempart);
3481 g_node_append(mimemsg->node, mimetext->node);
3483 /* sign message if sending */
3484 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
3485 privacy_system_can_sign(compose->privacy_system))
3486 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
3489 procmime_write_mimeinfo(mimemsg, fp);
3494 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3500 if ((fp = fopen(file, "wb")) == NULL) {
3501 FILE_OP_ERROR(file, "fopen");
3505 /* chmod for security */
3506 if (change_file_mode_rw(fp, file) < 0) {
3507 FILE_OP_ERROR(file, "chmod");
3508 g_warning("can't change file mode\n");
3511 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3514 len = strlen(chars);
3515 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3516 FILE_OP_ERROR(file, "fwrite");
3525 if (fclose(fp) == EOF) {
3526 FILE_OP_ERROR(file, "fclose");
3533 static gint compose_remove_reedit_target(Compose *compose)
3536 MsgInfo *msginfo = compose->targetinfo;
3538 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3539 if (!msginfo) return -1;
3541 item = msginfo->folder;
3542 g_return_val_if_fail(item != NULL, -1);
3544 if (procmsg_msg_exist(msginfo) &&
3545 (item->stype == F_DRAFT || item->stype == F_QUEUE
3546 || msginfo == compose->autosaved_draft)) {
3547 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3548 g_warning("can't remove the old message\n");
3556 void compose_remove_draft(Compose *compose)
3559 MsgInfo *msginfo = compose->targetinfo;
3560 drafts = account_get_special_folder(compose->account, F_DRAFT);
3562 if (procmsg_msg_exist(msginfo)) {
3563 folder_item_remove_msg(drafts, msginfo->msgnum);
3568 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3570 return compose_queue_sub (compose, msgnum, item, FALSE);
3572 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3579 static gboolean lock = FALSE;
3580 PrefsAccount *mailac = NULL, *newsac = NULL;
3582 debug_print("queueing message...\n");
3583 g_return_val_if_fail(compose->account != NULL, -1);
3587 if (compose_check_entries(compose, check_subject) == FALSE) {
3592 if (!compose->to_list && !compose->newsgroup_list) {
3593 g_warning("can't get recipient list.");
3598 if (compose->to_list) {
3599 if (compose->account->protocol != A_NNTP)
3600 mailac = compose->account;
3601 else if (cur_account && cur_account->protocol != A_NNTP)
3602 mailac = cur_account;
3603 else if (!(mailac = compose_current_mail_account())) {
3605 alertpanel_error(_("No account for sending mails available!"));
3610 if (compose->newsgroup_list) {
3611 if (compose->account->protocol == A_NNTP)
3612 newsac = compose->account;
3613 else if (!newsac->protocol != A_NNTP) {
3615 alertpanel_error(_("No account for posting news available!"));
3620 if (prefs_common.linewrap_at_send)
3621 compose_wrap_line_all(compose);
3623 /* write queue header */
3624 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
3625 G_DIR_SEPARATOR, compose);
3626 if ((fp = fopen(tmp, "wb")) == NULL) {
3627 FILE_OP_ERROR(tmp, "fopen");
3632 if (change_file_mode_rw(fp, tmp) < 0) {
3633 FILE_OP_ERROR(tmp, "chmod");
3634 g_warning("can't change file mode\n");
3637 /* queueing variables */
3638 fprintf(fp, "AF:\n");
3639 fprintf(fp, "NF:0\n");
3640 fprintf(fp, "PS:10\n");
3641 fprintf(fp, "SRH:1\n");
3642 fprintf(fp, "SFN:\n");
3643 fprintf(fp, "DSR:\n");
3645 fprintf(fp, "MID:<%s>\n", compose->msgid);
3647 fprintf(fp, "MID:\n");
3648 fprintf(fp, "CFG:\n");
3649 fprintf(fp, "PT:0\n");
3650 fprintf(fp, "S:%s\n", compose->account->address);
3651 fprintf(fp, "RQ:\n");
3653 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3655 fprintf(fp, "SSV:\n");
3657 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3659 fprintf(fp, "NSV:\n");
3660 fprintf(fp, "SSH:\n");
3661 /* write recepient list */
3662 if (compose->to_list) {
3663 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
3664 for (cur = compose->to_list->next; cur != NULL;
3666 fprintf(fp, ",<%s>", (gchar *)cur->data);
3669 /* write newsgroup list */
3670 if (compose->newsgroup_list) {
3672 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3673 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3674 fprintf(fp, ",%s", (gchar *)cur->data);
3677 /* Sylpheed account IDs */
3679 fprintf(fp, "MAID:%d\n", mailac->account_id);
3681 fprintf(fp, "NAID:%d\n", newsac->account_id);
3683 if (compose->privacy_system != NULL) {
3684 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
3685 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
3686 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
3687 if (compose->use_encryption) {
3690 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
3691 if (encdata != NULL)
3692 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
3698 /* Save copy folder */
3699 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3700 gchar *savefolderid;
3702 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3703 fprintf(fp, "SCF:%s\n", savefolderid);
3704 g_free(savefolderid);
3706 /* Message-ID of message replying to */
3707 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
3710 folderid = folder_item_get_identifier(compose->replyinfo->folder);
3711 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
3714 /* Message-ID of message forwarding to */
3715 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
3718 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
3719 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
3724 if (compose->redirect_filename != NULL) {
3725 if (compose_redirect_write_to_file(compose, fp) < 0) {
3733 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND) < 0) {
3742 if (fclose(fp) == EOF) {
3743 FILE_OP_ERROR(tmp, "fclose");
3749 queue = account_get_special_folder(compose->account, F_QUEUE);
3751 g_warning("can't find queue folder\n");
3756 folder_item_scan(queue);
3757 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
3758 g_warning("can't queue the message\n");
3766 if (compose->mode == COMPOSE_REEDIT) {
3767 compose_remove_reedit_target(compose);
3770 if ((msgnum != NULL) && (item != NULL)) {
3778 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
3781 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3784 struct stat statbuf;
3785 gchar *type, *subtype;
3787 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3789 mimepart = procmime_mimeinfo_new();
3790 mimepart->content = MIMECONTENT_FILE;
3791 mimepart->data.filename = g_strdup(ainfo->file);
3792 mimepart->offset = 0;
3794 stat(ainfo->file, &statbuf);
3795 mimepart->length = statbuf.st_size;
3797 type = g_strdup(ainfo->content_type);
3799 if (!strchr(type, '/')) {
3801 type = g_strdup("application/octet-stream");
3804 subtype = strchr(type, '/') + 1;
3805 *(subtype - 1) = '\0';
3806 mimepart->type = procmime_get_media_type(type);
3807 mimepart->subtype = g_strdup(subtype);
3810 if (mimepart->type == MIMETYPE_MESSAGE &&
3811 !g_strcasecmp(mimepart->subtype, "rfc822")) {
3812 mimepart->disposition = DISPOSITIONTYPE_INLINE;
3814 g_hash_table_insert(mimepart->typeparameters,
3815 g_strdup("name"), g_strdup(ainfo->name));
3816 g_hash_table_insert(mimepart->dispositionparameters,
3817 g_strdup("filename"), g_strdup(ainfo->name));
3818 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
3821 procmime_encode_content(mimepart, ainfo->encoding);
3823 g_node_append(parent->node, mimepart->node);
3827 #define QUOTE_IF_REQUIRED(out, str) \
3829 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3833 len = strlen(str) + 3; \
3834 if ((__tmp = alloca(len)) == NULL) { \
3835 g_warning("can't allocate memory\n"); \
3836 g_string_free(header, TRUE); \
3839 g_snprintf(__tmp, len, "\"%s\"", str); \
3844 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3845 g_warning("can't allocate memory\n"); \
3846 g_string_free(header, TRUE); \
3849 strcpy(__tmp, str); \
3855 #define IS_IN_CUSTOM_HEADER(header) \
3856 (compose->account->add_customhdr && \
3857 custom_header_find(compose->account->customhdr_list, header) != NULL)
3859 static void compose_add_headerfield_from_headerlist(Compose *compose,
3861 const gchar *fieldname,
3862 const gchar *seperator)
3864 gchar *str, *fieldname_w_colon, *trans_fieldname;
3865 gboolean add_field = FALSE;
3867 ComposeHeaderEntry *headerentry;
3868 gchar * headerentryname;
3871 if (IS_IN_CUSTOM_HEADER(fieldname))
3874 debug_print("Adding %s-fields\n", fieldname);
3876 fieldstr = g_string_sized_new(64);
3878 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
3879 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
3881 for (list = compose->header_list; list; list = list->next) {
3882 headerentry = ((ComposeHeaderEntry *)list->data);
3883 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3885 if (!g_strcasecmp(trans_fieldname, headerentryname)) {
3886 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
3888 if (str[0] != '\0') {
3890 g_string_append(fieldstr, seperator);
3891 g_string_append(fieldstr, str);
3900 buf = g_new0(gchar, fieldstr->len * 4 + 256);
3901 compose_convert_header
3902 (buf, fieldstr->len * 4 + 256, fieldstr->str,
3903 strlen(fieldname) + 2, TRUE);
3904 g_string_sprintfa(header, "%s: %s\n", fieldname, buf);
3908 g_free(fieldname_w_colon);
3909 g_string_free(fieldstr, TRUE);
3914 static gchar *compose_get_header(Compose *compose)
3916 gchar buf[BUFFSIZE];
3920 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3923 /* struct utsname utsbuf; */
3925 g_return_val_if_fail(compose->account != NULL, NULL);
3926 g_return_val_if_fail(compose->account->address != NULL, NULL);
3928 header = g_string_sized_new(64);
3931 if (compose->account->add_date) {
3932 get_rfc822_date(buf, sizeof(buf));
3933 g_string_sprintfa(header, "Date: %s\n", buf);
3937 if (compose->account->name && *compose->account->name) {
3938 compose_convert_header
3939 (buf, sizeof(buf), compose->account->name,
3940 strlen("From: "), TRUE);
3941 QUOTE_IF_REQUIRED(name, buf);
3942 g_string_sprintfa(header, "From: %s <%s>\n",
3943 name, compose->account->address);
3945 g_string_sprintfa(header, "From: %s\n", compose->account->address);
3948 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
3951 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
3954 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
3957 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
3960 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3961 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3964 tmpstr = g_strdup(str);
3965 if (tmpstr == NULL) {
3966 g_string_free(header, TRUE);
3971 compose_convert_header(buf, sizeof(buf), str,
3972 strlen("Subject: "), FALSE);
3973 g_string_sprintfa(header, "Subject: %s\n", buf);
3979 if (compose->account->gen_msgid) {
3980 generate_msgid(buf, sizeof(buf));
3981 g_string_sprintfa(header, "Message-ID: <%s>\n", buf);
3982 compose->msgid = g_strdup(buf);
3985 if (compose->remove_references == FALSE) {
3987 if (compose->inreplyto && compose->to_list)
3988 g_string_sprintfa(header, "In-Reply-To: <%s>\n", compose->inreplyto);
3991 if (compose->references)
3992 g_string_sprintfa(header, "References: %s\n", compose->references);
3996 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
3999 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4002 if (compose->account->organization &&
4003 !IS_IN_CUSTOM_HEADER("Organization")) {
4004 compose_convert_header(buf, sizeof(buf),
4005 compose->account->organization,
4006 strlen("Organization: "), FALSE);
4007 g_string_sprintfa(header, "Organization: %s\n", buf);
4010 /* Program version and system info */
4011 /* uname(&utsbuf); */
4012 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4013 !compose->newsgroup_list) {
4014 g_string_sprintfa(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4016 gtk_major_version, gtk_minor_version, gtk_micro_version,
4018 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4020 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4021 g_string_sprintfa(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4023 gtk_major_version, gtk_minor_version, gtk_micro_version,
4025 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4028 /* custom headers */
4029 if (compose->account->add_customhdr) {
4032 for (cur = compose->account->customhdr_list; cur != NULL;
4034 CustomHeader *chdr = (CustomHeader *)cur->data;
4036 if (custom_header_is_allowed(chdr->name)) {
4037 compose_convert_header
4039 chdr->value ? chdr->value : "",
4040 strlen(chdr->name) + 2, FALSE);
4041 g_string_sprintfa(header, "%s: %s\n", chdr->name, buf);
4047 switch (compose->priority) {
4048 case PRIORITY_HIGHEST: g_string_sprintfa(header, "Importance: high\n"
4049 "X-Priority: 1 (Highest)\n");
4051 case PRIORITY_HIGH: g_string_sprintfa(header, "Importance: high\n"
4052 "X-Priority: 2 (High)\n");
4054 case PRIORITY_NORMAL: break;
4055 case PRIORITY_LOW: g_string_sprintfa(header, "Importance: low\n"
4056 "X-Priority: 4 (Low)\n");
4058 case PRIORITY_LOWEST: g_string_sprintfa(header, "Importance: low\n"
4059 "X-Priority: 5 (Lowest)\n");
4061 default: debug_print("compose: priority unknown : %d\n",
4065 /* Request Return Receipt */
4066 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4067 if (compose->return_receipt) {
4068 if (compose->account->name
4069 && *compose->account->name) {
4070 compose_convert_header(buf, sizeof(buf),
4071 compose->account->name,
4072 strlen("Disposition-Notification-To: "),
4074 g_string_sprintfa(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4076 g_string_sprintfa(header, "Disposition-Notification-To: %s\n", compose->account->address);
4080 /* get special headers */
4081 for (list = compose->header_list; list; list = list->next) {
4082 ComposeHeaderEntry *headerentry;
4085 gchar *headername_wcolon;
4086 gchar *headername_trans;
4089 gboolean standard_header = FALSE;
4091 headerentry = ((ComposeHeaderEntry *)list->data);
4093 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4094 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4099 if (!strstr(tmp, ":")) {
4100 headername_wcolon = g_strconcat(tmp, ":", NULL);
4101 headername = g_strdup(tmp);
4103 headername_wcolon = g_strdup(tmp);
4104 headername = g_strdup(strtok(tmp, ":"));
4108 headervalue = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4109 subst_char(headervalue, '\r', ' ');
4110 subst_char(headervalue, '\n', ' ');
4111 string = std_headers;
4112 while (*string != NULL) {
4113 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4114 if (!strcmp(headername_trans,headername_wcolon))
4115 standard_header = TRUE;
4118 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4119 g_string_sprintfa(header, "%s %s\n", headername_wcolon, headervalue);
4122 g_free(headername_wcolon);
4126 g_string_free(header, FALSE);
4131 #undef IS_IN_CUSTOM_HEADER
4133 static void compose_convert_header(gchar *dest, gint len, gchar *src,
4134 gint header_len, gboolean addr_field)
4136 g_return_if_fail(src != NULL);
4137 g_return_if_fail(dest != NULL);
4139 if (len < 1) return;
4141 subst_char(src, '\n', ' ');
4142 subst_char(src, '\r', ' ');
4145 conv_encode_header(dest, len, src, header_len, addr_field);
4148 static void compose_create_header_entry(Compose *compose)
4150 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4154 GList *combo_list = NULL;
4155 gchar **string, *header = NULL;
4156 ComposeHeaderEntry *headerentry;
4157 gboolean standard_header = FALSE;
4159 headerentry = g_new0(ComposeHeaderEntry, 1);
4162 combo = gtk_combo_new();
4164 while(*string != NULL) {
4165 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4168 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4169 g_list_free(combo_list);
4170 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4171 gtk_widget_show(combo);
4172 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4173 if (compose->header_last) {
4174 gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4176 while (*string != NULL) {
4177 if (!strcmp(*string, last_header_entry))
4178 standard_header = TRUE;
4181 if (standard_header)
4182 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4184 if (!compose->header_last || !standard_header) {
4185 switch(compose->account->protocol) {
4187 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4190 header = prefs_common.trans_hdr ? _("To:") : "To:";
4195 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4198 entry = gtk_entry_new();
4199 gtk_widget_show(entry);
4200 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);
4202 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4203 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4204 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4205 gtk_signal_connect(GTK_OBJECT(entry), "button-press-event",
4206 GTK_SIGNAL_FUNC(compose_headerentry_button_pressed),
4209 address_completion_register_entry(GTK_ENTRY(entry));
4211 headerentry->compose = compose;
4212 headerentry->combo = combo;
4213 headerentry->entry = entry;
4214 headerentry->headernum = compose->header_nextrow;
4216 compose->header_nextrow++;
4217 compose->header_last = headerentry;
4220 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4222 ComposeHeaderEntry *last_header;
4224 last_header = compose->header_last;
4226 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4227 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4230 static GtkWidget *compose_create_header(Compose *compose)
4234 GtkWidget *from_optmenu_hbox;
4235 #if 0 /* NEW COMPOSE GUI */
4236 GtkWidget *to_entry;
4238 GtkWidget *newsgroups_entry;
4239 GtkWidget *newsgroups_hbox;
4241 GtkWidget *header_scrolledwin;
4242 GtkWidget *header_table;
4243 #if 0 /* NEW COMPOSE GUI */
4244 GtkWidget *cc_entry;
4246 GtkWidget *bcc_entry;
4247 GtkWidget *bcc_hbox;
4248 GtkWidget *reply_entry;
4249 GtkWidget *reply_hbox;
4250 GtkWidget *followup_entry;
4251 GtkWidget *followup_hbox;
4256 /* header labels and entries */
4257 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4258 gtk_widget_show(header_scrolledwin);
4259 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4261 header_table = gtk_table_new(2, 2, FALSE);
4262 gtk_widget_show(header_table);
4263 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4264 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4265 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4268 /* option menu for selecting accounts */
4269 hbox = gtk_hbox_new(FALSE, 0);
4270 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4271 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4272 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4274 from_optmenu_hbox = compose_account_option_menu_create(compose);
4275 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4276 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4277 #if 0 /* NEW COMPOSE GUI */
4278 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4282 compose->header_table = header_table;
4283 compose->header_list = NULL;
4284 compose->header_nextrow = count;
4286 compose_create_header_entry(compose);
4288 #if 0 /* NEW COMPOSE GUI */
4289 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4291 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4292 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4293 &count, "Newsgroups:", FALSE);
4294 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4296 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4298 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4300 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4301 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4303 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4304 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4306 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4307 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4308 "Followup-To:", FALSE);
4309 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4311 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4313 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4314 GTK_SIGNAL_FUNC(to_activated), compose);
4315 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4316 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4317 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4318 GTK_SIGNAL_FUNC(subject_activated), compose);
4319 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4320 GTK_SIGNAL_FUNC(cc_activated), compose);
4321 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4322 GTK_SIGNAL_FUNC(bcc_activated), compose);
4323 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4324 GTK_SIGNAL_FUNC(replyto_activated), compose);
4325 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4326 GTK_SIGNAL_FUNC(followupto_activated), compose);
4328 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4329 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4330 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4331 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4332 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4333 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4334 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4335 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4336 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4337 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4338 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4339 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4340 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4341 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4344 compose->table = NULL;
4345 #if 0 /* NEW COMPOSE GUI */
4346 compose->table = table;
4347 compose->to_hbox = to_hbox;
4348 compose->to_entry = to_entry;
4349 compose->newsgroups_hbox = newsgroups_hbox;
4350 compose->newsgroups_entry = newsgroups_entry;
4352 #if 0 /* NEW COMPOSE GUI */
4353 compose->cc_hbox = cc_hbox;
4354 compose->cc_entry = cc_entry;
4355 compose->bcc_hbox = bcc_hbox;
4356 compose->bcc_entry = bcc_entry;
4357 compose->reply_hbox = reply_hbox;
4358 compose->reply_entry = reply_entry;
4359 compose->followup_hbox = followup_hbox;
4360 compose->followup_entry = followup_entry;
4363 return header_scrolledwin ;
4366 GtkWidget *compose_create_attach(Compose *compose)
4368 gchar *titles[N_ATTACH_COLS];
4371 GtkWidget *attach_scrwin;
4372 GtkWidget *attach_clist;
4374 titles[COL_MIMETYPE] = _("MIME type");
4375 titles[COL_SIZE] = _("Size");
4376 titles[COL_NAME] = _("Name");
4378 /* attachment list */
4379 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4380 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4381 GTK_POLICY_AUTOMATIC,
4383 gtk_widget_set_usize(attach_scrwin, -1, 80);
4385 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4386 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4388 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4389 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4390 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4391 GTK_SELECTION_EXTENDED);
4392 for (i = 0; i < N_ATTACH_COLS; i++)
4393 GTK_WIDGET_UNSET_FLAGS
4394 (GTK_CLIST(attach_clist)->column[i].button,
4396 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4398 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4399 GTK_SIGNAL_FUNC(attach_selected), compose);
4400 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4401 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4402 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4403 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4406 gtk_drag_dest_set(attach_clist,
4407 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4408 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4409 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4410 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4413 compose->attach_scrwin = attach_scrwin;
4414 compose->attach_clist = attach_clist;
4416 return attach_scrwin;
4419 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4420 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4422 static GtkWidget *compose_create_others(Compose *compose)
4425 GtkWidget *savemsg_checkbtn;
4426 GtkWidget *savemsg_entry;
4427 GtkWidget *savemsg_select;
4430 gchar *folderidentifier;
4432 /* Table for settings */
4433 table = gtk_table_new(3, 1, FALSE);
4434 gtk_widget_show(table);
4435 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4438 /* Save Message to folder */
4439 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4440 gtk_widget_show(savemsg_checkbtn);
4441 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4442 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4443 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4445 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4446 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4448 savemsg_entry = gtk_entry_new();
4449 gtk_widget_show(savemsg_entry);
4450 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4451 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4452 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4453 folderidentifier = folder_item_get_identifier(account_get_special_folder
4454 (compose->account, F_OUTBOX));
4455 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4456 g_free(folderidentifier);
4459 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4460 gtk_widget_show (savemsg_select);
4461 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4462 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4463 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4468 compose->savemsg_checkbtn = savemsg_checkbtn;
4469 compose->savemsg_entry = savemsg_entry;
4474 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4476 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4477 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4480 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4485 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4488 path = folder_item_get_identifier(dest);
4490 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4494 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4500 GtkWidget *handlebox;
4502 GtkWidget *notebook;
4507 GtkWidget *subject_hbox;
4508 GtkWidget *subject_frame;
4509 GtkWidget *subject_entry;
4513 GtkWidget *edit_vbox;
4514 GtkWidget *ruler_hbox;
4516 GtkWidget *scrolledwin;
4519 UndoMain *undostruct;
4521 gchar *titles[N_ATTACH_COLS];
4522 guint n_menu_entries;
4523 GtkStyle *style, *new_style;
4526 gboolean success[1];
4527 GtkWidget *popupmenu;
4528 GtkItemFactory *popupfactory;
4529 GtkItemFactory *ifactory;
4530 GtkWidget *tmpl_menu;
4534 GtkAspell * gtkaspell = NULL;
4537 static GdkGeometry geometry;
4539 g_return_val_if_fail(account != NULL, NULL);
4541 debug_print("Creating compose window...\n");
4542 compose = g_new0(Compose, 1);
4544 titles[COL_MIMETYPE] = _("MIME type");
4545 titles[COL_SIZE] = _("Size");
4546 titles[COL_NAME] = _("Name");
4548 compose->account = account;
4550 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4551 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4552 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4553 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4555 if (!geometry.max_width) {
4556 geometry.max_width = gdk_screen_width();
4557 geometry.max_height = gdk_screen_height();
4559 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4560 &geometry, GDK_HINT_MAX_SIZE);
4561 gtk_widget_set_uposition(window, prefs_common.compose_x,
4562 prefs_common.compose_y);
4563 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4564 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4565 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4566 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4567 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4568 gtk_widget_realize(window);
4570 gtkut_widget_set_composer_icon(window);
4572 vbox = gtk_vbox_new(FALSE, 0);
4573 gtk_container_add(GTK_CONTAINER(window), vbox);
4575 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4576 menubar = menubar_create(window, compose_entries,
4577 n_menu_entries, "<Compose>", compose);
4578 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4580 handlebox = gtk_handle_box_new();
4581 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4583 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
4586 vbox2 = gtk_vbox_new(FALSE, 2);
4587 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4588 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4591 notebook = gtk_notebook_new();
4592 gtk_widget_set_usize(notebook, -1, 130);
4593 gtk_widget_show(notebook);
4595 /* header labels and entries */
4596 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4597 /* attachment list */
4598 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4600 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4603 subject_hbox = gtk_hbox_new(FALSE, 0);
4604 gtk_widget_show(subject_hbox);
4606 subject_frame = gtk_frame_new(NULL);
4607 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4608 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4609 gtk_widget_show(subject_frame);
4611 subject = gtk_hbox_new(FALSE, 0);
4612 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4613 gtk_widget_show(subject);
4615 label = gtk_label_new(_("Subject:"));
4616 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4617 gtk_widget_show(label);
4619 subject_entry = gtk_entry_new();
4620 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4621 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4622 gtk_widget_show(subject_entry);
4623 compose->subject_entry = subject_entry;
4624 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4626 edit_vbox = gtk_vbox_new(FALSE, 0);
4628 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4631 ruler_hbox = gtk_hbox_new(FALSE, 0);
4632 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4634 ruler = gtk_shruler_new();
4635 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4636 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4638 gtk_widget_set_usize(ruler_hbox, 1, -1);
4641 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4642 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4643 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4644 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4645 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4647 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4648 (GTK_SCROLLED_WINDOW(scrolledwin)),
4649 gtk_scrolled_window_get_vadjustment
4650 (GTK_SCROLLED_WINDOW(scrolledwin)));
4651 GTK_STEXT(text)->default_tab_width = 8;
4652 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4654 if (prefs_common.block_cursor) {
4655 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4658 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4660 gtk_signal_connect(GTK_OBJECT(text), "changed",
4661 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4662 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4663 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4664 gtk_signal_connect(GTK_OBJECT(text), "activate",
4665 GTK_SIGNAL_FUNC(text_activated), compose);
4666 gtk_signal_connect(GTK_OBJECT(text), "insert_text",
4667 GTK_SIGNAL_FUNC(text_inserted), compose);
4668 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4669 GTK_SIGNAL_FUNC(compose_button_press_cb),
4672 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4673 GTK_SIGNAL_FUNC(compose_key_press_cb),
4676 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4677 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4681 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4682 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4683 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4684 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4686 gtk_widget_show_all(vbox);
4688 /* pane between attach clist and text */
4689 paned = gtk_vpaned_new();
4690 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4691 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4692 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4693 gtk_paned_add1(GTK_PANED(paned), notebook);
4694 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4695 gtk_widget_show_all(paned);
4697 style = gtk_widget_get_style(text);
4699 /* workaround for the slow down of GtkSText when using Pixmap theme */
4700 if (style->engine) {
4701 GtkThemeEngine *engine;
4703 engine = style->engine;
4704 style->engine = NULL;
4705 new_style = gtk_style_copy(style);
4706 style->engine = engine;
4708 new_style = gtk_style_copy(style);
4710 if (prefs_common.textfont) {
4713 if ((font = gtkut_font_load(prefs_common.textfont)) != NULL) {
4714 gdk_font_unref(new_style->font);
4715 new_style->font = font;
4719 gtk_widget_set_style(text, new_style);
4721 color[0] = quote_color;
4722 cmap = gdk_window_get_colormap(window->window);
4723 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4724 if (success[0] == FALSE) {
4725 g_warning("Compose: color allocation failed.\n");
4726 style = gtk_widget_get_style(text);
4727 quote_color = style->black;
4730 n_entries = sizeof(compose_popup_entries) /
4731 sizeof(compose_popup_entries[0]);
4732 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4733 "<Compose>", &popupfactory,
4736 ifactory = gtk_item_factory_from_widget(menubar);
4737 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4738 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4739 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
4741 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4743 undostruct = undo_init(text);
4744 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4747 address_completion_start(window);
4749 compose->window = window;
4750 compose->vbox = vbox;
4751 compose->menubar = menubar;
4752 compose->handlebox = handlebox;
4754 compose->vbox2 = vbox2;
4756 compose->paned = paned;
4758 compose->edit_vbox = edit_vbox;
4759 compose->ruler_hbox = ruler_hbox;
4760 compose->ruler = ruler;
4761 compose->scrolledwin = scrolledwin;
4762 compose->text = text;
4764 compose->focused_editable = NULL;
4766 compose->popupmenu = popupmenu;
4767 compose->popupfactory = popupfactory;
4769 compose->tmpl_menu = tmpl_menu;
4771 compose->mode = mode;
4773 compose->targetinfo = NULL;
4774 compose->replyinfo = NULL;
4775 compose->fwdinfo = NULL;
4777 compose->replyto = NULL;
4779 compose->bcc = NULL;
4780 compose->followup_to = NULL;
4782 compose->ml_post = NULL;
4784 compose->inreplyto = NULL;
4785 compose->references = NULL;
4786 compose->msgid = NULL;
4787 compose->boundary = NULL;
4789 compose->autowrap = prefs_common.autowrap;
4791 compose->use_signing = FALSE;
4792 compose->use_encryption = FALSE;
4793 compose->privacy_system = NULL;
4795 compose->modified = FALSE;
4797 compose->return_receipt = FALSE;
4799 compose->to_list = NULL;
4800 compose->newsgroup_list = NULL;
4802 compose->undostruct = undostruct;
4804 compose->sig_str = NULL;
4806 compose->exteditor_file = NULL;
4807 compose->exteditor_pid = -1;
4808 compose->exteditor_readdes = -1;
4809 compose->exteditor_tag = -1;
4810 compose->draft_timeout_tag = -1;
4813 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4814 if (mode != COMPOSE_REDIRECT) {
4815 if (prefs_common.enable_aspell && prefs_common.dictionary &&
4816 strcmp(prefs_common.dictionary, _("None"))) {
4817 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
4818 prefs_common.dictionary,
4819 conv_get_current_charset_str(),
4820 prefs_common.misspelled_col,
4821 prefs_common.check_while_typing,
4822 prefs_common.use_alternate,
4825 alertpanel_error(_("Spell checker could not "
4827 gtkaspell_checkers_strerror());
4828 gtkaspell_checkers_reset_error();
4831 GtkWidget *menuitem;
4833 if (!gtkaspell_set_sug_mode(gtkaspell,
4834 prefs_common.aspell_sugmode)) {
4835 debug_print("Aspell: could not set "
4836 "suggestion mode %s\n",
4837 gtkaspell_checkers_strerror());
4838 gtkaspell_checkers_reset_error();
4841 menuitem = gtk_item_factory_get_item(ifactory,
4842 "/Spelling/Spelling Configuration");
4843 gtkaspell_populate_submenu(gtkaspell, menuitem);
4844 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4848 compose->gtkaspell = gtkaspell;
4851 compose_select_account(compose, account, TRUE);
4853 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
4854 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
4855 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4857 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
4858 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4860 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
4861 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4864 if (account->protocol != A_NNTP)
4865 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4867 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4869 addressbook_set_target_compose(compose);
4871 if (mode != COMPOSE_REDIRECT)
4872 compose_set_template_menu(compose);
4874 GtkWidget *menuitem;
4875 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4876 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
4879 compose_list = g_list_append(compose_list, compose);
4881 if (!prefs_common.show_ruler)
4882 gtk_widget_hide(ruler_hbox);
4885 compose->priority = PRIORITY_NORMAL;
4886 compose_update_priority_menu_item(compose);
4889 compose_update_actions_menu(compose);
4891 /* Privacy Systems menu */
4892 compose_update_privacy_systems_menu(compose);
4894 activate_privacy_system(compose, account);
4895 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
4896 gtk_widget_show(window);
4901 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4907 gint num = 0, def_menu = 0;
4909 accounts = account_get_list();
4910 g_return_val_if_fail(accounts != NULL, NULL);
4912 hbox = gtk_hbox_new(FALSE, 0);
4913 optmenu = gtk_option_menu_new();
4914 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4915 menu = gtk_menu_new();
4917 for (; accounts != NULL; accounts = accounts->next, num++) {
4918 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4919 GtkWidget *menuitem;
4922 if (ac == compose->account) def_menu = num;
4925 name = g_strdup_printf("%s: %s <%s>",
4927 ac->name, ac->address);
4929 name = g_strdup_printf("%s: %s",
4930 ac->account_name, ac->address);
4931 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
4933 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4934 GTK_SIGNAL_FUNC(account_activated),
4938 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4939 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4944 static void compose_set_priority_cb(gpointer data,
4948 Compose *compose = (Compose *) data;
4949 compose->priority = action;
4952 static void compose_update_priority_menu_item(Compose * compose)
4954 GtkItemFactory *ifactory;
4955 GtkWidget *menuitem = NULL;
4957 ifactory = gtk_item_factory_from_widget(compose->menubar);
4959 switch (compose->priority) {
4960 case PRIORITY_HIGHEST:
4961 menuitem = gtk_item_factory_get_item
4962 (ifactory, "/Options/Priority/Highest");
4965 menuitem = gtk_item_factory_get_item
4966 (ifactory, "/Options/Priority/High");
4968 case PRIORITY_NORMAL:
4969 menuitem = gtk_item_factory_get_item
4970 (ifactory, "/Options/Priority/Normal");
4973 menuitem = gtk_item_factory_get_item
4974 (ifactory, "/Options/Priority/Low");
4976 case PRIORITY_LOWEST:
4977 menuitem = gtk_item_factory_get_item
4978 (ifactory, "/Options/Priority/Lowest");
4981 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4984 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
4986 Compose *compose = (Compose *) data;
4988 GtkItemFactory *ifactory;
4989 gboolean can_sign = FALSE, can_encrypt = FALSE;
4991 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
4993 if (!GTK_CHECK_MENU_ITEM(widget)->active)
4996 systemid = gtk_object_get_data(GTK_OBJECT(widget), "privacy_system");
4997 g_free(compose->privacy_system);
4998 compose->privacy_system = NULL;
4999 if (systemid != NULL) {
5000 compose->privacy_system = g_strdup(systemid);
5002 can_sign = privacy_system_can_sign(systemid);
5003 can_encrypt = privacy_system_can_encrypt(systemid);
5006 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5008 ifactory = gtk_item_factory_from_widget(compose->menubar);
5009 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5010 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5013 static void compose_update_privacy_system_menu_item(Compose * compose)
5015 static gchar *branch_path = "/Options/Privacy System";
5016 GtkItemFactory *ifactory;
5017 GtkWidget *menuitem = NULL;
5019 gboolean can_sign = FALSE, can_encrypt = FALSE;
5021 ifactory = gtk_item_factory_from_widget(compose->menubar);
5023 if (compose->privacy_system != NULL) {
5026 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5027 g_return_if_fail(menuitem != NULL);
5029 amenu = GTK_MENU_SHELL(menuitem)->children;
5031 while (amenu != NULL) {
5032 GList *alist = amenu->next;
5034 systemid = gtk_object_get_data(GTK_OBJECT(amenu->data), "privacy_system");
5035 if (systemid != NULL)
5036 if (strcmp(systemid, compose->privacy_system) == 0) {
5037 menuitem = GTK_WIDGET(amenu->data);
5039 can_sign = privacy_system_can_sign(systemid);
5040 can_encrypt = privacy_system_can_encrypt(systemid);
5047 if (menuitem != NULL)
5048 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5051 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5052 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5055 static void compose_set_template_menu(Compose *compose)
5057 GSList *tmpl_list, *cur;
5061 tmpl_list = template_get_config();
5063 menu = gtk_menu_new();
5065 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5066 Template *tmpl = (Template *)cur->data;
5068 item = gtk_menu_item_new_with_label(tmpl->name);
5069 gtk_menu_append(GTK_MENU(menu), item);
5070 gtk_signal_connect(GTK_OBJECT(item), "activate",
5071 GTK_SIGNAL_FUNC(compose_template_activate_cb),
5073 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
5074 gtk_widget_show(item);
5077 gtk_widget_show(menu);
5078 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5081 void compose_update_actions_menu(Compose *compose)
5083 GtkItemFactory *ifactory;
5085 ifactory = gtk_item_factory_from_widget(compose->menubar);
5086 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5089 void compose_update_privacy_systems_menu(Compose *compose)
5091 static gchar *branch_path = "/Options/Privacy System";
5092 static gboolean connected = FALSE;
5093 GtkItemFactory *ifactory;
5094 GtkWidget *menuitem;
5095 GSList *systems, *cur;
5098 GtkWidget *system_none;
5101 ifactory = gtk_item_factory_from_widget(compose->menubar);
5103 /* remove old entries */
5104 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5105 g_return_if_fail(menuitem != NULL);
5107 amenu = GTK_MENU_SHELL(menuitem)->children->next;
5108 while (amenu != NULL) {
5109 GList *alist = amenu->next;
5110 gtk_widget_destroy(GTK_WIDGET(amenu->data));
5114 system_none = gtk_item_factory_get_widget(ifactory,
5115 "/Options/Privacy System/None");
5117 gtk_signal_connect(GTK_OBJECT(system_none), "activate",
5118 GTK_SIGNAL_FUNC(compose_set_privacy_system_cb), compose);
5122 systems = privacy_get_system_ids();
5123 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
5124 gchar *systemid = cur->data;
5126 group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(system_none));
5127 widget = gtk_radio_menu_item_new_with_label(group,
5128 privacy_system_get_name(systemid));
5129 gtk_object_set_data_full(GTK_OBJECT(widget), "privacy_system",
5130 g_strdup(systemid), g_free);
5131 gtk_signal_connect(GTK_OBJECT(widget), "activate",
5132 GTK_SIGNAL_FUNC(compose_set_privacy_system_cb), compose);
5134 gtk_menu_append(GTK_MENU(system_none->parent), widget);
5135 gtk_widget_show(widget);
5138 g_slist_free(systems);
5141 void compose_reflect_prefs_all(void)
5146 for (cur = compose_list; cur != NULL; cur = cur->next) {
5147 compose = (Compose *)cur->data;
5148 compose_set_template_menu(compose);
5152 void compose_reflect_prefs_pixmap_theme(void)
5157 for (cur = compose_list; cur != NULL; cur = cur->next) {
5158 compose = (Compose *)cur->data;
5159 toolbar_update(TOOLBAR_COMPOSE, compose);
5163 static void compose_template_apply(Compose *compose, Template *tmpl,
5169 if (!tmpl || !tmpl->value) return;
5171 gtk_stext_freeze(GTK_STEXT(compose->text));
5173 if (tmpl->subject && *tmpl->subject != '\0')
5174 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5176 if (tmpl->to && *tmpl->to != '\0')
5177 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5178 if (tmpl->cc && *tmpl->cc != '\0')
5179 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5181 if (tmpl->bcc && *tmpl->bcc != '\0')
5182 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5185 gtkut_stext_clear(GTK_STEXT(compose->text));
5187 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
5188 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5191 if (prefs_common.quotemark && *prefs_common.quotemark)
5192 qmark = prefs_common.quotemark;
5196 if (compose->replyinfo != NULL)
5197 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5198 tmpl->value, qmark, NULL);
5199 else if (compose->fwdinfo != NULL)
5200 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
5201 tmpl->value, qmark, NULL);
5206 if (replace && parsed_str && compose->account->auto_sig)
5207 compose_insert_sig(compose, FALSE);
5209 if (replace && parsed_str) {
5210 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
5211 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
5215 compose_changed_cb(NULL, compose);
5217 gtk_stext_thaw(GTK_STEXT(compose->text));
5220 static void compose_destroy(Compose *compose)
5223 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5226 /* NOTE: address_completion_end() does nothing with the window
5227 * however this may change. */
5228 address_completion_end(compose->window);
5230 slist_free_strings(compose->to_list);
5231 g_slist_free(compose->to_list);
5232 slist_free_strings(compose->newsgroup_list);
5233 g_slist_free(compose->newsgroup_list);
5234 slist_free_strings(compose->header_list);
5235 g_slist_free(compose->header_list);
5237 procmsg_msginfo_free(compose->targetinfo);
5238 procmsg_msginfo_free(compose->replyinfo);
5239 procmsg_msginfo_free(compose->fwdinfo);
5241 g_free(compose->replyto);
5242 g_free(compose->cc);
5243 g_free(compose->bcc);
5244 g_free(compose->newsgroups);
5245 g_free(compose->followup_to);
5247 g_free(compose->ml_post);
5249 g_free(compose->inreplyto);
5250 g_free(compose->references);
5251 g_free(compose->msgid);
5252 g_free(compose->boundary);
5254 if (compose->redirect_filename)
5255 g_free(compose->redirect_filename);
5256 if (compose->undostruct)
5257 undo_destroy(compose->undostruct);
5259 g_free(compose->sig_str);
5261 g_free(compose->exteditor_file);
5263 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5265 compose_attach_info_free(ainfo);
5267 if (addressbook_get_target_compose() == compose)
5268 addressbook_set_target_compose(NULL);
5271 if (compose->gtkaspell) {
5272 gtkaspell_delete(compose->gtkaspell);
5276 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5277 prefs_common.compose_height = compose->window->allocation.height;
5279 gtk_widget_destroy(compose->paned);
5281 toolbar_destroy(compose->toolbar);
5282 g_free(compose->toolbar);
5285 compose_list = g_list_remove(compose_list, compose);
5288 static void compose_attach_info_free(AttachInfo *ainfo)
5290 g_free(ainfo->file);
5291 g_free(ainfo->content_type);
5292 g_free(ainfo->name);
5296 static void compose_attach_remove_selected(Compose *compose)
5298 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5302 while (clist->selection != NULL) {
5303 row = GPOINTER_TO_INT(clist->selection->data);
5304 ainfo = gtk_clist_get_row_data(clist, row);
5305 compose_attach_info_free(ainfo);
5306 gtk_clist_remove(clist, row);
5310 static struct _AttachProperty
5313 GtkWidget *mimetype_entry;
5314 GtkWidget *encoding_optmenu;
5315 GtkWidget *path_entry;
5316 GtkWidget *filename_entry;
5318 GtkWidget *cancel_btn;
5321 static void compose_attach_property(Compose *compose)
5323 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5326 GtkOptionMenu *optmenu;
5327 static gboolean cancelled;
5329 if (!clist->selection) return;
5330 row = GPOINTER_TO_INT(clist->selection->data);
5332 ainfo = gtk_clist_get_row_data(clist, row);
5335 if (!attach_prop.window)
5336 compose_attach_property_create(&cancelled);
5337 gtk_widget_grab_focus(attach_prop.ok_btn);
5338 gtk_widget_show(attach_prop.window);
5339 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5341 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5342 if (ainfo->encoding == ENC_UNKNOWN)
5343 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5344 GINT_TO_POINTER(ENC_BASE64));
5346 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5347 GINT_TO_POINTER(ainfo->encoding));
5349 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5350 ainfo->content_type ? ainfo->content_type : "");
5351 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5352 ainfo->file ? ainfo->file : "");
5353 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5354 ainfo->name ? ainfo->name : "");
5358 gchar *cnttype = NULL;
5362 GtkWidget *menuitem;
5367 if (cancelled == TRUE) {
5368 gtk_widget_hide(attach_prop.window);
5372 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5373 if (*text != '\0') {
5376 text = g_strstrip(g_strdup(text));
5377 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5378 cnttype = g_strdup(text);
5381 alertpanel_error(_("Invalid MIME type."));
5387 menu = gtk_option_menu_get_menu(optmenu);
5388 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5389 ainfo->encoding = GPOINTER_TO_INT
5390 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5392 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5393 if (*text != '\0') {
5394 if (is_file_exist(text) &&
5395 (size = get_file_size(text)) > 0)
5396 file = g_strdup(text);
5399 (_("File doesn't exist or is empty."));
5405 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5406 if (*text != '\0') {
5407 g_free(ainfo->name);
5408 ainfo->name = g_strdup(text);
5412 g_free(ainfo->content_type);
5413 ainfo->content_type = cnttype;
5416 g_free(ainfo->file);
5422 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5423 ainfo->content_type);
5424 gtk_clist_set_text(clist, row, COL_SIZE,
5425 to_human_readable(ainfo->size));
5426 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5428 gtk_widget_hide(attach_prop.window);
5433 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5435 label = gtk_label_new(str); \
5436 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5437 GTK_FILL, 0, 0, 0); \
5438 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5440 entry = gtk_entry_new(); \
5441 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5442 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5445 static void compose_attach_property_create(gboolean *cancelled)
5451 GtkWidget *mimetype_entry;
5454 GtkWidget *optmenu_menu;
5455 GtkWidget *menuitem;
5456 GtkWidget *path_entry;
5457 GtkWidget *filename_entry;
5460 GtkWidget *cancel_btn;
5461 GList *mime_type_list, *strlist;
5463 debug_print("Creating attach_property window...\n");
5465 window = gtk_window_new(GTK_WINDOW_DIALOG);
5466 gtk_widget_set_usize(window, 480, -1);
5467 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5468 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
5469 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5470 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5471 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5472 GTK_SIGNAL_FUNC(attach_property_delete_event),
5474 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5475 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5478 vbox = gtk_vbox_new(FALSE, 8);
5479 gtk_container_add(GTK_CONTAINER(window), vbox);
5481 table = gtk_table_new(4, 2, FALSE);
5482 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5483 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5484 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5486 label = gtk_label_new(_("MIME type"));
5487 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5489 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5490 mimetype_entry = gtk_combo_new();
5491 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5492 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5494 /* stuff with list */
5495 mime_type_list = procmime_get_mime_type_list();
5497 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5498 MimeType *type = (MimeType *) mime_type_list->data;
5499 strlist = g_list_append(strlist,
5500 g_strdup_printf("%s/%s",
5501 type->type, type->sub_type));
5504 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5506 for (mime_type_list = strlist; mime_type_list != NULL;
5507 mime_type_list = mime_type_list->next)
5508 g_free(mime_type_list->data);
5509 g_list_free(strlist);
5511 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5513 label = gtk_label_new(_("Encoding"));
5514 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5516 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5518 hbox = gtk_hbox_new(FALSE, 0);
5519 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5520 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5522 optmenu = gtk_option_menu_new();
5523 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5525 optmenu_menu = gtk_menu_new();
5526 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5527 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5529 gtk_widget_set_sensitive(menuitem, FALSE);
5531 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5532 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5534 gtk_widget_set_sensitive(menuitem, FALSE);
5536 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
5537 ENC_QUOTED_PRINTABLE);
5538 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5540 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5542 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5544 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5545 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5547 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5548 &cancel_btn, _("Cancel"), NULL, NULL);
5549 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5550 gtk_widget_grab_default(ok_btn);
5552 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5553 GTK_SIGNAL_FUNC(attach_property_ok),
5555 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5556 GTK_SIGNAL_FUNC(attach_property_cancel),
5559 gtk_widget_show_all(vbox);
5561 attach_prop.window = window;
5562 attach_prop.mimetype_entry = mimetype_entry;
5563 attach_prop.encoding_optmenu = optmenu;
5564 attach_prop.path_entry = path_entry;
5565 attach_prop.filename_entry = filename_entry;
5566 attach_prop.ok_btn = ok_btn;
5567 attach_prop.cancel_btn = cancel_btn;
5570 #undef SET_LABEL_AND_ENTRY
5572 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5578 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5584 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5585 gboolean *cancelled)
5593 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5594 gboolean *cancelled)
5596 if (event && event->keyval == GDK_Escape) {
5602 static void compose_exec_ext_editor(Compose *compose)
5608 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
5609 G_DIR_SEPARATOR, compose);
5611 if (pipe(pipe_fds) < 0) {
5617 if ((pid = fork()) < 0) {
5624 /* close the write side of the pipe */
5627 compose->exteditor_file = g_strdup(tmp);
5628 compose->exteditor_pid = pid;
5629 compose->exteditor_readdes = pipe_fds[0];
5631 compose_set_ext_editor_sensitive(compose, FALSE);
5633 compose->exteditor_tag =
5634 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5635 compose_input_cb, compose);
5636 } else { /* process-monitoring process */
5642 /* close the read side of the pipe */
5645 if (compose_write_body_to_file(compose, tmp) < 0) {
5646 fd_write_all(pipe_fds[1], "2\n", 2);
5650 pid_ed = compose_exec_ext_editor_real(tmp);
5652 fd_write_all(pipe_fds[1], "1\n", 2);
5656 /* wait until editor is terminated */
5657 waitpid(pid_ed, NULL, 0);
5659 fd_write_all(pipe_fds[1], "0\n", 2);
5668 static gint compose_exec_ext_editor_real(const gchar *file)
5670 static gchar *def_cmd = "emacs %s";
5676 g_return_val_if_fail(file != NULL, -1);
5678 if ((pid = fork()) < 0) {
5683 if (pid != 0) return pid;
5685 /* grandchild process */
5687 if (setpgid(0, getppid()))
5690 if (prefs_common.ext_editor_cmd &&
5691 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5692 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5693 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5695 if (prefs_common.ext_editor_cmd)
5696 g_warning("External editor command line is invalid: `%s'\n",
5697 prefs_common.ext_editor_cmd);
5698 g_snprintf(buf, sizeof(buf), def_cmd, file);
5701 cmdline = strsplit_with_quote(buf, " ", 1024);
5702 execvp(cmdline[0], cmdline);
5705 g_strfreev(cmdline);
5710 static gboolean compose_ext_editor_kill(Compose *compose)
5712 pid_t pgid = compose->exteditor_pid * -1;
5715 ret = kill(pgid, 0);
5717 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5721 msg = g_strdup_printf
5722 (_("The external editor is still working.\n"
5723 "Force terminating the process?\n"
5724 "process group id: %d"), -pgid);
5725 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5728 if (val == G_ALERTDEFAULT) {
5729 gdk_input_remove(compose->exteditor_tag);
5730 close(compose->exteditor_readdes);
5732 if (kill(pgid, SIGTERM) < 0) perror("kill");
5733 waitpid(compose->exteditor_pid, NULL, 0);
5735 g_warning("Terminated process group id: %d", -pgid);
5736 g_warning("Temporary file: %s",
5737 compose->exteditor_file);
5739 compose_set_ext_editor_sensitive(compose, TRUE);
5741 g_free(compose->exteditor_file);
5742 compose->exteditor_file = NULL;
5743 compose->exteditor_pid = -1;
5744 compose->exteditor_readdes = -1;
5745 compose->exteditor_tag = -1;
5753 static void compose_input_cb(gpointer data, gint source,
5754 GdkInputCondition condition)
5757 Compose *compose = (Compose *)data;
5760 debug_print("Compose: input from monitoring process\n");
5762 gdk_input_remove(compose->exteditor_tag);
5765 if (read(source, &buf[i], 1) < 1) {
5769 if (buf[i] == '\n') {
5774 if (i == sizeof(buf) - 1)
5778 waitpid(compose->exteditor_pid, NULL, 0);
5780 if (buf[0] == '0') { /* success */
5781 GtkSText *text = GTK_STEXT(compose->text);
5783 gtk_stext_freeze(text);
5784 gtk_stext_set_point(text, 0);
5785 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5786 compose_insert_file(compose, compose->exteditor_file);
5787 compose_changed_cb(NULL, compose);
5788 gtk_stext_thaw(text);
5790 if (unlink(compose->exteditor_file) < 0)
5791 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5792 } else if (buf[0] == '1') { /* failed */
5793 g_warning("Couldn't exec external editor\n");
5794 if (unlink(compose->exteditor_file) < 0)
5795 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5796 } else if (buf[0] == '2') {
5797 g_warning("Couldn't write to file\n");
5798 } else if (buf[0] == '3') {
5799 g_warning("Pipe read failed\n");
5804 compose_set_ext_editor_sensitive(compose, TRUE);
5806 g_free(compose->exteditor_file);
5807 compose->exteditor_file = NULL;
5808 compose->exteditor_pid = -1;
5809 compose->exteditor_readdes = -1;
5810 compose->exteditor_tag = -1;
5813 static void compose_set_ext_editor_sensitive(Compose *compose,
5816 GtkItemFactory *ifactory;
5818 ifactory = gtk_item_factory_from_widget(compose->menubar);
5820 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5821 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5822 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
5823 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
5824 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5825 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5826 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5829 gtk_widget_set_sensitive(compose->text, sensitive);
5830 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
5831 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
5832 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
5833 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
5834 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
5835 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
5836 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
5837 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
5841 * compose_undo_state_changed:
5843 * Change the sensivity of the menuentries undo and redo
5845 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5846 gint redo_state, gpointer data)
5848 GtkWidget *widget = GTK_WIDGET(data);
5849 GtkItemFactory *ifactory;
5851 g_return_if_fail(widget != NULL);
5853 ifactory = gtk_item_factory_from_widget(widget);
5855 switch (undo_state) {
5856 case UNDO_STATE_TRUE:
5857 if (!undostruct->undo_state) {
5858 undostruct->undo_state = TRUE;
5859 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5862 case UNDO_STATE_FALSE:
5863 if (undostruct->undo_state) {
5864 undostruct->undo_state = FALSE;
5865 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5868 case UNDO_STATE_UNCHANGED:
5870 case UNDO_STATE_REFRESH:
5871 menu_set_sensitive(ifactory, "/Edit/Undo",
5872 undostruct->undo_state);
5875 g_warning("Undo state not recognized");
5879 switch (redo_state) {
5880 case UNDO_STATE_TRUE:
5881 if (!undostruct->redo_state) {
5882 undostruct->redo_state = TRUE;
5883 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5886 case UNDO_STATE_FALSE:
5887 if (undostruct->redo_state) {
5888 undostruct->redo_state = FALSE;
5889 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5892 case UNDO_STATE_UNCHANGED:
5894 case UNDO_STATE_REFRESH:
5895 menu_set_sensitive(ifactory, "/Edit/Redo",
5896 undostruct->redo_state);
5899 g_warning("Redo state not recognized");
5904 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5908 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5909 cursor_pos = MAX(cursor_pos, 0);
5914 /* callback functions */
5916 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5917 * includes "non-client" (windows-izm) in calculation, so this calculation
5918 * may not be accurate.
5920 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5921 GtkAllocation *allocation,
5922 GtkSHRuler *shruler)
5924 if (prefs_common.show_ruler) {
5926 gint line_width_in_chars;
5928 char_width = gtkut_get_font_width
5929 (GTK_WIDGET(widget)->style->font);
5930 line_width_in_chars =
5931 (allocation->width - allocation->x) / char_width;
5933 /* got the maximum */
5934 gtk_ruler_set_range(GTK_RULER(shruler),
5935 0.0, line_width_in_chars,
5936 calc_cursor_xpos(GTK_STEXT(widget),
5939 /*line_width_in_chars*/ char_width);
5945 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5947 Compose *compose = (Compose *)data;
5950 gchar *folderidentifier;
5952 ac = account_find_from_id(
5953 GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menuitem))));
5954 g_return_if_fail(ac != NULL);
5956 if (ac != compose->account)
5957 compose_select_account(compose, ac, FALSE);
5959 /* Set message save folder */
5960 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5961 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
5963 gtk_signal_connect(GTK_OBJECT(compose->savemsg_checkbtn), "toggled",
5964 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
5966 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
5967 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5968 folderidentifier = folder_item_get_identifier(account_get_special_folder
5969 (compose->account, F_OUTBOX));
5970 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
5971 g_free(folderidentifier);
5975 static void attach_selected(GtkCList *clist, gint row, gint column,
5976 GdkEvent *event, gpointer data)
5978 Compose *compose = (Compose *)data;
5980 if (event && event->type == GDK_2BUTTON_PRESS)
5981 compose_attach_property(compose);
5984 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5987 Compose *compose = (Compose *)data;
5988 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5993 if (event->button == 3) {
5994 if ((clist->selection && !clist->selection->next) ||
5995 !clist->selection) {
5996 gtk_clist_unselect_all(clist);
5997 if (gtk_clist_get_selection_info(clist,
6000 gtk_clist_select_row(clist, row, column);
6001 gtkut_clist_set_focus_row(clist, row);
6004 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6005 NULL, NULL, event->button, event->time);
6009 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6012 Compose *compose = (Compose *)data;
6016 switch (event->keyval) {
6018 compose_attach_remove_selected(compose);
6023 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6025 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6026 toolbar_comp_set_sensitive(compose, allow);
6027 menu_set_sensitive(ifactory, "/Message", allow);
6028 menu_set_sensitive(ifactory, "/Edit", allow);
6030 menu_set_sensitive(ifactory, "/Spelling", allow);
6032 menu_set_sensitive(ifactory, "/Options", allow);
6033 menu_set_sensitive(ifactory, "/Tools", allow);
6034 menu_set_sensitive(ifactory, "/Help", allow);
6037 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6039 Compose *compose = (Compose *)data;
6041 if (prefs_common.work_offline)
6042 if (alertpanel(_("Offline warning"),
6043 _("You're working offline. Override?"),
6044 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
6047 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
6048 gtk_timeout_remove(compose->draft_timeout_tag);
6049 compose->draft_timeout_tag = -1;
6052 compose_send(compose);
6055 static void compose_send_later_cb(gpointer data, guint action,
6058 Compose *compose = (Compose *)data;
6061 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6063 compose_close(compose);
6066 void compose_draft (gpointer data)
6068 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6071 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6073 Compose *compose = (Compose *)data;
6077 MsgFlags flag = {0, 0};
6078 static gboolean lock = FALSE;
6079 MsgInfo *newmsginfo;
6084 draft = account_get_special_folder(compose->account, F_DRAFT);
6085 g_return_if_fail(draft != NULL);
6089 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
6090 G_DIR_SEPARATOR, compose);
6091 if ((fp = fopen(tmp, "wb")) == NULL) {
6092 FILE_OP_ERROR(tmp, "fopen");
6096 /* chmod for security */
6097 if (change_file_mode_rw(fp, tmp) < 0) {
6098 FILE_OP_ERROR(tmp, "chmod");
6099 g_warning("can't change file mode\n");
6102 /* Save draft infos */
6103 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
6104 fprintf(fp, "S:%s\n", compose->account->address);
6105 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
6106 gchar *savefolderid;
6108 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6109 fprintf(fp, "SCF:%s\n", savefolderid);
6110 g_free(savefolderid);
6112 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
6113 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
6114 fprintf(fp, "X-Sylpheed-Gnupg-Mode:%s\n", compose->privacy_system);
6117 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
6126 folder_item_scan(draft);
6127 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
6134 draft->mtime = 0; /* force updating */
6136 if (compose->mode == COMPOSE_REEDIT) {
6137 compose_remove_reedit_target(compose);
6140 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6142 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6143 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
6144 if (compose_use_attach(compose))
6145 procmsg_msginfo_set_flags(newmsginfo, 0,
6146 MSG_HAS_ATTACHMENT);
6148 procmsg_msginfo_free(newmsginfo);
6151 folder_item_scan(draft);
6155 if (action == COMPOSE_QUIT_EDITING)
6156 compose_close(compose);
6161 path = folder_item_fetch_msg(draft, msgnum);
6162 g_return_if_fail(path != NULL);
6163 if (stat(path, &s) < 0) {
6164 FILE_OP_ERROR(path, "stat");
6171 procmsg_msginfo_free(compose->targetinfo);
6172 compose->targetinfo = procmsg_msginfo_new();
6173 compose->targetinfo->msgnum = msgnum;
6174 compose->targetinfo->size = s.st_size;
6175 compose->targetinfo->mtime = s.st_mtime;
6176 compose->targetinfo->folder = draft;
6177 compose->mode = COMPOSE_REEDIT;
6179 if (action == COMPOSE_AUTO_SAVE) {
6180 compose->autosaved_draft = compose->targetinfo;
6185 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6187 Compose *compose = (Compose *)data;
6190 if (compose->redirect_filename != NULL)
6193 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6198 for ( tmp = file_list; tmp; tmp = tmp->next) {
6199 gchar *file = (gchar *) tmp->data;
6200 compose_attach_append(compose, file, file, NULL);
6201 compose_changed_cb(NULL, compose);
6204 g_list_free(file_list);
6208 static void compose_insert_file_cb(gpointer data, guint action,
6211 Compose *compose = (Compose *)data;
6214 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6219 for ( tmp = file_list; tmp; tmp = tmp->next) {
6220 gchar *file = (gchar *) tmp->data;
6221 gchar *filedup = g_strdup(file);
6223 ComposeInsertResult res;
6225 res = compose_insert_file(compose, file);
6226 shortfile = g_basename(filedup);
6227 if (res == COMPOSE_INSERT_READ_ERROR) {
6228 alertpanel_error(_("File '%s' could not be read."), shortfile);
6229 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
6230 alertpanel_error(_("File '%s' contained invalid characters\n"
6231 "for the current encoding, insertion may be incorrect."), shortfile);
6236 g_list_free(file_list);
6240 static void compose_insert_sig_cb(gpointer data, guint action,
6243 Compose *compose = (Compose *)data;
6245 compose_insert_sig(compose, FALSE);
6248 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6252 Compose *compose = (Compose *)data;
6254 gtkut_widget_get_uposition(widget, &x, &y);
6255 prefs_common.compose_x = x;
6256 prefs_common.compose_y = y;
6258 if (compose->sending)
6260 compose_close_cb(compose, 0, NULL);
6264 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6266 Compose *compose = (Compose *)data;
6269 if (compose->exteditor_tag != -1) {
6270 if (!compose_ext_editor_kill(compose))
6274 if (compose->modified) {
6275 val = alertpanel(_("Discard message"),
6276 _("This message has been modified. discard it?"),
6277 _("Discard"), _("to Draft"), _("Cancel"));
6280 case G_ALERTDEFAULT:
6281 if (prefs_common.autosave)
6282 compose_remove_draft(compose);
6284 case G_ALERTALTERNATE:
6285 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6292 compose_close(compose);
6295 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6297 Compose *compose = (Compose *)data;
6299 addressbook_open(compose);
6302 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6304 Compose *compose = (Compose *)data;
6309 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6310 g_return_if_fail(tmpl != NULL);
6312 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6314 val = alertpanel(_("Apply template"), msg,
6315 _("Replace"), _("Insert"), _("Cancel"));
6318 if (val == G_ALERTDEFAULT)
6319 compose_template_apply(compose, tmpl, TRUE);
6320 else if (val == G_ALERTALTERNATE)
6321 compose_template_apply(compose, tmpl, FALSE);
6324 static void compose_ext_editor_cb(gpointer data, guint action,
6327 Compose *compose = (Compose *)data;
6329 compose_exec_ext_editor(compose);
6332 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6334 if (compose->sending)
6336 compose_destroy(compose);
6339 static void compose_undo_cb(Compose *compose)
6341 undo_undo(compose->undostruct);
6344 static void compose_redo_cb(Compose *compose)
6346 undo_redo(compose->undostruct);
6349 static void compose_cut_cb(Compose *compose)
6351 if (compose->focused_editable &&
6352 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6353 gtk_editable_cut_clipboard
6354 (GTK_EDITABLE(compose->focused_editable));
6357 static void compose_copy_cb(Compose *compose)
6359 if (compose->focused_editable &&
6360 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6361 gtk_editable_copy_clipboard
6362 (GTK_EDITABLE(compose->focused_editable));
6365 static void compose_paste_cb(Compose *compose)
6367 if (compose->focused_editable &&
6368 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6369 gtk_editable_paste_clipboard
6370 (GTK_EDITABLE(compose->focused_editable));
6373 static void compose_paste_as_quote_cb(Compose *compose)
6375 if (compose->focused_editable &&
6376 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6377 /* let text_insert() (called directly or at a later time
6378 * after the gtk_editable_paste_clipboard) know that
6379 * text is to be inserted as a quotation. implemented
6380 * by using a simple refcount... */
6381 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data(
6382 GTK_OBJECT(compose->focused_editable),
6383 "paste_as_quotation"));
6384 gtk_object_set_data(GTK_OBJECT(compose->focused_editable),
6385 "paste_as_quotation",
6386 GINT_TO_POINTER(paste_as_quotation + 1));
6387 gtk_editable_paste_clipboard
6388 (GTK_EDITABLE(compose->focused_editable));
6392 static void compose_allsel_cb(Compose *compose)
6394 if (compose->focused_editable &&
6395 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6396 gtk_editable_select_region
6397 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6400 static void compose_gtk_stext_action_cb(Compose *compose,
6401 ComposeCallGtkSTextAction action)
6403 GtkSText *text = GTK_STEXT(compose->text);
6405 void (*do_action) (GtkSText *text);
6406 } action_table[] = {
6407 {gtk_stext_move_beginning_of_line},
6408 {gtk_stext_move_forward_character},
6409 {gtk_stext_move_backward_character},
6410 {gtk_stext_move_forward_word},
6411 {gtk_stext_move_backward_word},
6412 {gtk_stext_move_end_of_line},
6413 {gtk_stext_move_next_line},
6414 {gtk_stext_move_previous_line},
6415 {gtk_stext_delete_forward_character},
6416 {gtk_stext_delete_backward_character},
6417 {gtk_stext_delete_forward_word},
6418 {gtk_stext_delete_backward_word},
6419 {gtk_stext_delete_line},
6420 {gtk_stext_delete_line}, /* gtk_stext_delete_line_n */
6421 {gtk_stext_delete_to_line_end}
6424 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
6426 if (action >= COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE &&
6427 action <= COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END)
6428 action_table[action].do_action(text);
6431 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6433 if (GTK_IS_EDITABLE(widget))
6434 compose->focused_editable = widget;
6437 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6439 if (compose->modified == FALSE) {
6440 compose->modified = TRUE;
6441 compose_set_title(compose);
6445 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6448 gtk_stext_set_point(GTK_STEXT(widget),
6449 gtk_editable_get_position(GTK_EDITABLE(widget)));
6453 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6456 gtk_stext_set_point(GTK_STEXT(widget),
6457 gtk_editable_get_position(GTK_EDITABLE(widget)));
6461 static void compose_toggle_autowrap_cb(gpointer data, guint action,
6464 Compose *compose = (Compose *)data;
6466 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
6467 if (compose->autowrap)
6468 compose_wrap_line_all_full(compose, TRUE);
6471 static void compose_toggle_sign_cb(gpointer data, guint action,
6474 Compose *compose = (Compose *)data;
6476 if (GTK_CHECK_MENU_ITEM(widget)->active)
6477 compose->use_signing = TRUE;
6479 compose->use_signing = FALSE;
6482 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6485 Compose *compose = (Compose *)data;
6487 if (GTK_CHECK_MENU_ITEM(widget)->active)
6488 compose->use_encryption = TRUE;
6490 compose->use_encryption = FALSE;
6493 static void activate_privacy_system(Compose *compose, PrefsAccount *account)
6495 g_free(compose->privacy_system);
6496 compose->privacy_system = g_strdup(account->default_privacy_system);
6497 compose_update_privacy_system_menu_item(compose);
6500 static void compose_toggle_ruler_cb(gpointer data, guint action,
6503 Compose *compose = (Compose *)data;
6505 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6506 gtk_widget_show(compose->ruler_hbox);
6507 prefs_common.show_ruler = TRUE;
6509 gtk_widget_hide(compose->ruler_hbox);
6510 gtk_widget_queue_resize(compose->edit_vbox);
6511 prefs_common.show_ruler = FALSE;
6515 static void compose_attach_drag_received_cb (GtkWidget *widget,
6516 GdkDragContext *drag_context,
6519 GtkSelectionData *data,
6524 Compose *compose = (Compose *)user_data;
6527 list = uri_list_extract_filenames((const gchar *)data->data);
6528 for (tmp = list; tmp != NULL; tmp = tmp->next)
6529 compose_attach_append
6530 (compose, (const gchar *)tmp->data,
6531 (const gchar *)tmp->data, NULL);
6532 if (list) compose_changed_cb(NULL, compose);
6533 list_free_strings(list);
6537 static void compose_insert_drag_received_cb (GtkWidget *widget,
6538 GdkDragContext *drag_context,
6541 GtkSelectionData *data,
6546 Compose *compose = (Compose *)user_data;
6549 list = uri_list_extract_filenames((const gchar *)data->data);
6550 for (tmp = list; tmp != NULL; tmp = tmp->next)
6551 compose_insert_file(compose, (const gchar *)tmp->data);
6552 list_free_strings(list);
6556 #if 0 /* NEW COMPOSE GUI */
6557 static void to_activated(GtkWidget *widget, Compose *compose)
6559 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6560 gtk_widget_grab_focus(compose->newsgroups_entry);
6562 gtk_widget_grab_focus(compose->subject_entry);
6565 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6567 gtk_widget_grab_focus(compose->subject_entry);
6570 static void subject_activated(GtkWidget *widget, Compose *compose)
6572 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6573 gtk_widget_grab_focus(compose->cc_entry);
6574 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6575 gtk_widget_grab_focus(compose->bcc_entry);
6576 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6577 gtk_widget_grab_focus(compose->reply_entry);
6578 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6579 gtk_widget_grab_focus(compose->followup_entry);
6581 gtk_widget_grab_focus(compose->text);
6584 static void cc_activated(GtkWidget *widget, Compose *compose)
6586 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6587 gtk_widget_grab_focus(compose->bcc_entry);
6588 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6589 gtk_widget_grab_focus(compose->reply_entry);
6590 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6591 gtk_widget_grab_focus(compose->followup_entry);
6593 gtk_widget_grab_focus(compose->text);
6596 static void bcc_activated(GtkWidget *widget, Compose *compose)
6598 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6599 gtk_widget_grab_focus(compose->reply_entry);
6600 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6601 gtk_widget_grab_focus(compose->followup_entry);
6603 gtk_widget_grab_focus(compose->text);
6606 static void replyto_activated(GtkWidget *widget, Compose *compose)
6608 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6609 gtk_widget_grab_focus(compose->followup_entry);
6611 gtk_widget_grab_focus(compose->text);
6614 static void followupto_activated(GtkWidget *widget, Compose *compose)
6616 gtk_widget_grab_focus(compose->text);
6620 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6623 Compose *compose = (Compose *)data;
6625 if (GTK_CHECK_MENU_ITEM(widget)->active)
6626 compose->return_receipt = TRUE;
6628 compose->return_receipt = FALSE;
6631 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
6634 Compose *compose = (Compose *)data;
6636 if (GTK_CHECK_MENU_ITEM(widget)->active)
6637 compose->remove_references = TRUE;
6639 compose->remove_references = FALSE;
6642 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6644 ComposeHeaderEntry *headerentry)
6646 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6647 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6648 !(event->state & GDK_MODIFIER_MASK) &&
6649 (event->keyval == GDK_BackSpace) &&
6650 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6651 gtk_container_remove
6652 (GTK_CONTAINER(headerentry->compose->header_table),
6653 headerentry->combo);
6654 gtk_container_remove
6655 (GTK_CONTAINER(headerentry->compose->header_table),
6656 headerentry->entry);
6657 headerentry->compose->header_list =
6658 g_slist_remove(headerentry->compose->header_list,
6660 g_free(headerentry);
6661 } else if (event->keyval == GDK_Tab) {
6662 if (headerentry->compose->header_last == headerentry) {
6663 /* Override default next focus, and give it to subject_entry
6664 * instead of notebook tabs
6666 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6667 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6673 void compose_headerentry_changed_cb(GtkWidget *entry,
6674 ComposeHeaderEntry *headerentry)
6676 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6677 headerentry->compose->header_list =
6678 g_slist_append(headerentry->compose->header_list,
6680 compose_create_header_entry(headerentry->compose);
6681 gtk_signal_disconnect_by_func
6683 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6685 /* Automatically scroll down */
6686 compose_show_first_last_header(headerentry->compose, FALSE);
6691 static gboolean compose_headerentry_button_pressed
6692 (GtkWidget *entry, GdkEventButton *event, gpointer data)
6694 /* if this is a lclick, grab the focus */
6695 if (event->button == 1)
6696 gtk_widget_grab_focus(entry);
6700 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6702 GtkAdjustment *vadj;
6704 g_return_if_fail(compose);
6705 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6706 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6708 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6709 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6712 static void text_activated(GtkWidget *widget, Compose *compose)
6714 compose_send_control_enter(compose);
6717 static void text_inserted(GtkWidget *widget, const gchar *text,
6718 gint length, gint *position, Compose *compose)
6720 GtkEditable *editable = GTK_EDITABLE(widget);
6721 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data
6722 (GTK_OBJECT(widget), "paste_as_quotation"));
6724 gtk_signal_handler_block_by_func(GTK_OBJECT(widget),
6725 GTK_SIGNAL_FUNC(text_inserted),
6727 if (paste_as_quotation) {
6732 new_text = g_strndup(text, length);
6733 if (prefs_common.quotemark && *prefs_common.quotemark)
6734 qmark = prefs_common.quotemark;
6737 gtk_stext_set_point(GTK_STEXT(widget), *position);
6738 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
6739 pos = gtk_stext_get_point(GTK_STEXT(widget));
6740 gtk_editable_set_position(editable, pos);
6743 gtk_object_set_data(GTK_OBJECT(widget), "paste_as_quotation",
6744 GINT_TO_POINTER(paste_as_quotation - 1));
6746 gtk_editable_insert_text(editable, text, length, position);
6748 if (compose->autowrap)
6749 compose_wrap_line_all_full(compose, TRUE);
6751 gtk_signal_handler_unblock_by_func(GTK_OBJECT(widget),
6752 GTK_SIGNAL_FUNC(text_inserted),
6754 gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
6756 if (prefs_common.autosave &&
6757 gtk_stext_get_length(GTK_STEXT(widget)) % prefs_common.autosave_length == 0)
6758 compose->draft_timeout_tag = gtk_timeout_add
6759 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
6762 static gint compose_defer_auto_save_draft(Compose *compose)
6764 compose->draft_timeout_tag = -1;
6765 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
6769 static gboolean compose_send_control_enter(Compose *compose)
6773 GtkItemFactory *ifactory;
6774 GtkAccelEntry *accel;
6775 GtkWidget *send_menu;
6777 GdkModifierType ignored_mods =
6778 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
6779 GDK_MOD4_MASK | GDK_MOD5_MASK);
6781 ev = gtk_get_current_event();
6782 if (ev->type != GDK_KEY_PRESS) return FALSE;
6784 kev = (GdkEventKey *)ev;
6785 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6788 if (compose->exteditor_tag != -1)
6791 ifactory = gtk_item_factory_from_widget(compose->menubar);
6792 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6793 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6797 accel = (GtkAccelEntry *)list->data;
6798 if (accel && accel->accelerator_key == kev->keyval &&
6799 (accel->accelerator_mods & ~ignored_mods) ==
6800 (kev->state & ~ignored_mods)) {
6801 compose_send_cb(compose, 0, NULL);
6809 static void compose_check_all(Compose *compose)
6811 if (compose->gtkaspell)
6812 gtkaspell_check_all(compose->gtkaspell);
6815 static void compose_highlight_all(Compose *compose)
6817 if (compose->gtkaspell)
6818 gtkaspell_highlight_all(compose->gtkaspell);
6821 static void compose_check_backwards(Compose *compose)
6823 if (compose->gtkaspell)
6824 gtkaspell_check_backwards(compose->gtkaspell);
6826 GtkItemFactory *ifactory;
6827 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6828 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6829 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6833 static void compose_check_forwards_go(Compose *compose)
6835 if (compose->gtkaspell)
6836 gtkaspell_check_forwards_go(compose->gtkaspell);
6838 GtkItemFactory *ifactory;
6839 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6840 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6841 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6847 *\brief Guess originating forward account from MsgInfo and several
6848 * "common preference" settings. Return NULL if no guess.
6850 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
6852 PrefsAccount *account = NULL;
6854 g_return_val_if_fail(msginfo, NULL);
6855 g_return_val_if_fail(msginfo->folder, NULL);
6856 g_return_val_if_fail(msginfo->folder->prefs, NULL);
6858 if (msginfo->folder->prefs->enable_default_account)
6859 account = account_find_from_id(msginfo->folder->prefs->default_account);
6862 account = msginfo->folder->folder->account;
6864 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
6866 Xstrdup_a(to, msginfo->to, return NULL);
6867 extract_address(to);
6868 account = account_find_from_address(to);
6871 if (!account && prefs_common.forward_account_autosel) {
6873 if (!procheader_get_header_from_msginfo
6874 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
6875 extract_address(cc);
6876 account = account_find_from_address(cc);
6883 static void compose_close(Compose *compose)
6887 g_return_if_fail(compose);
6888 gtkut_widget_get_uposition(compose->window, &x, &y);
6889 prefs_common.compose_x = x;
6890 prefs_common.compose_y = y;
6891 gtk_widget_destroy(compose->window);
6895 * Add entry field for each address in list.
6896 * \param compose E-Mail composition object.
6897 * \param listAddress List of (formatted) E-Mail addresses.
6899 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
6904 addr = ( gchar * ) node->data;
6905 compose_entry_append( compose, addr, COMPOSE_TO );
6906 node = g_list_next( node );