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 GtkItemFactoryEntry compose_popup_entries[] =
516 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
517 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
518 {N_("/---"), NULL, NULL, 0, "<Separator>"},
519 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
522 static GtkItemFactoryEntry compose_entries[] =
524 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
525 {N_("/_Message/_Send"), "<control>Return",
526 compose_send_cb, 0, NULL},
527 {N_("/_Message/Send _later"), "<shift><control>S",
528 compose_send_later_cb, 0, NULL},
529 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
530 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
531 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
532 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
533 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
534 {N_("/_Message/_Save"),
535 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
536 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
537 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
539 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
540 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
541 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
542 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
543 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
544 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
545 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
546 {N_("/_Edit/Paste as _quotation"),
547 NULL, compose_paste_as_quote_cb, 0, NULL},
548 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
549 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
550 {N_("/_Edit/A_dvanced/Move a character backward"),
552 compose_gtk_stext_action_cb,
553 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
555 {N_("/_Edit/A_dvanced/Move a character forward"),
557 compose_gtk_stext_action_cb,
558 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
560 {N_("/_Edit/A_dvanced/Move a word backward"),
562 compose_gtk_stext_action_cb,
563 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
565 {N_("/_Edit/A_dvanced/Move a word forward"),
567 compose_gtk_stext_action_cb,
568 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
570 {N_("/_Edit/A_dvanced/Move to beginning of line"),
571 NULL, /* "<control>A" */
572 compose_gtk_stext_action_cb,
573 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
575 {N_("/_Edit/A_dvanced/Move to end of line"),
577 compose_gtk_stext_action_cb,
578 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
580 {N_("/_Edit/A_dvanced/Move to previous line"),
582 compose_gtk_stext_action_cb,
583 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
585 {N_("/_Edit/A_dvanced/Move to next line"),
587 compose_gtk_stext_action_cb,
588 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
590 {N_("/_Edit/A_dvanced/Delete a character backward"),
592 compose_gtk_stext_action_cb,
593 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
595 {N_("/_Edit/A_dvanced/Delete a character forward"),
597 compose_gtk_stext_action_cb,
598 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
600 {N_("/_Edit/A_dvanced/Delete a word backward"),
601 NULL, /* "<control>W" */
602 compose_gtk_stext_action_cb,
603 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
605 {N_("/_Edit/A_dvanced/Delete a word forward"),
606 NULL, /* "<alt>D", */
607 compose_gtk_stext_action_cb,
608 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
610 {N_("/_Edit/A_dvanced/Delete line"),
612 compose_gtk_stext_action_cb,
613 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
615 {N_("/_Edit/A_dvanced/Delete entire line"),
617 compose_gtk_stext_action_cb,
618 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
620 {N_("/_Edit/A_dvanced/Delete to end of line"),
622 compose_gtk_stext_action_cb,
623 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
625 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
626 {N_("/_Edit/_Wrap current paragraph"),
627 "<control>L", compose_wrap_line, 0, NULL},
628 {N_("/_Edit/Wrap all long _lines"),
629 "<control><alt>L", compose_wrap_line_all, 0, NULL},
630 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
631 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
632 {N_("/_Edit/Edit with e_xternal editor"),
633 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
635 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
636 {N_("/_Spelling/_Check all or check selection"),
637 NULL, compose_check_all, 0, NULL},
638 {N_("/_Spelling/_Highlight all misspelled words"),
639 NULL, compose_highlight_all, 0, NULL},
640 {N_("/_Spelling/Check _backwards misspelled word"),
641 NULL, compose_check_backwards , 0, NULL},
642 {N_("/_Spelling/_Forward to next misspelled word"),
643 NULL, compose_check_forwards_go, 0, NULL},
644 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
645 {N_("/_Spelling/_Spelling Configuration"),
646 NULL, NULL, 0, "<Branch>"},
648 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
649 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
650 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
651 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
652 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
653 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
654 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
655 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
656 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
657 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
658 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
659 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
660 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
661 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
662 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
663 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
664 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
665 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
666 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
667 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
668 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
669 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
672 static GtkTargetEntry compose_mime_types[] =
674 {"text/uri-list", 0, 0}
677 static gboolean compose_put_existing_to_front(MsgInfo *info)
679 GList *compose_list = compose_get_compose_list();
683 for (elem = compose_list; elem != NULL && elem->data != NULL;
685 Compose *c = (Compose*)elem->data;
687 if (!c->targetinfo || !c->targetinfo->msgid ||
691 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
692 gtkut_window_popup(c->window);
700 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
701 GPtrArray *attach_files)
703 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
706 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
708 return compose_generic_new(account, NULL, item, NULL, NULL);
711 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
713 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
716 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
717 GPtrArray *attach_files, GList *listAddress )
721 GtkItemFactory *ifactory;
723 if (item && item->prefs && item->prefs->enable_default_account)
724 account = account_find_from_id(item->prefs->default_account);
726 if (!account) account = cur_account;
727 g_return_val_if_fail(account != NULL, NULL);
729 compose = compose_create(account, COMPOSE_NEW);
730 ifactory = gtk_item_factory_from_widget(compose->menubar);
732 compose->replyinfo = NULL;
733 compose->fwdinfo = NULL;
735 text = GTK_STEXT(compose->text);
736 gtk_stext_freeze(text);
739 if (item && item->prefs && item->prefs->enable_default_dictionary &&
741 gtkaspell_change_dict(compose->gtkaspell,
742 item->prefs->default_dictionary);
745 if (account->auto_sig)
746 compose_insert_sig(compose, FALSE);
747 gtk_editable_set_position(GTK_EDITABLE(text), 0);
748 gtk_stext_set_point(text, 0);
750 gtk_stext_thaw(text);
752 if (account->protocol != A_NNTP) {
753 if (mailto && *mailto != '\0') {
754 compose_entries_set(compose, mailto);
756 } else if (item && item->prefs->enable_default_to) {
757 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
758 compose_entry_mark_default_to(compose, item->prefs->default_to);
760 if (item && item->ret_rcpt) {
761 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
765 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
768 * CLAWS: just don't allow return receipt request, even if the user
769 * may want to send an email. simple but foolproof.
771 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
773 compose_add_field_list( compose, listAddress );
779 for (i = 0; i < attach_files->len; i++) {
780 file = g_ptr_array_index(attach_files, i);
781 compose_attach_append(compose, file, file, NULL);
785 compose_show_first_last_header(compose, TRUE);
787 /* Set save folder */
788 if (item && item->prefs && item->prefs->save_copy_to_folder) {
789 gchar *folderidentifier;
791 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
792 folderidentifier = folder_item_get_identifier(item);
793 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
794 g_free(folderidentifier);
797 gtk_widget_grab_focus(compose->header_last->entry);
799 if (prefs_common.auto_exteditor)
800 compose_exec_ext_editor(compose);
806 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
807 const gchar *followupto, gchar * to)
811 if (!account) account = cur_account;
812 g_return_val_if_fail(account != NULL, NULL);
813 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
815 compose = compose_create(account, COMPOSE_NEW);
817 if (prefs_common.auto_sig)
818 compose_insert_sig(compose);
819 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
820 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
822 compose_entry_append(compose, to, COMPOSE_TO);
823 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
824 gtk_widget_grab_focus(compose->subject_entry);
830 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
835 g_return_if_fail(msginfo_list != NULL);
837 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
838 g_return_if_fail(msginfo != NULL);
840 list_len = g_slist_length(msginfo_list);
844 compose_reply(msginfo, prefs_common.reply_with_quote,
845 FALSE, prefs_common.default_reply_list, FALSE, body);
847 case COMPOSE_REPLY_WITH_QUOTE:
848 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
850 case COMPOSE_REPLY_WITHOUT_QUOTE:
851 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
853 case COMPOSE_REPLY_TO_SENDER:
854 compose_reply(msginfo, prefs_common.reply_with_quote,
855 FALSE, FALSE, TRUE, body);
857 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
858 compose_followup_and_reply_to(msginfo,
859 prefs_common.reply_with_quote,
862 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
863 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
865 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
866 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
868 case COMPOSE_REPLY_TO_ALL:
869 compose_reply(msginfo, prefs_common.reply_with_quote,
870 TRUE, FALSE, FALSE, body);
872 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
873 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
875 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
876 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
878 case COMPOSE_REPLY_TO_LIST:
879 compose_reply(msginfo, prefs_common.reply_with_quote,
880 FALSE, TRUE, FALSE, body);
882 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
883 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
885 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
886 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
888 case COMPOSE_FORWARD:
889 if (prefs_common.forward_as_attachment) {
890 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
893 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
897 case COMPOSE_FORWARD_INLINE:
898 /* check if we reply to more than one Message */
900 compose_forward(NULL, msginfo, FALSE, body, FALSE);
903 /* more messages FALL THROUGH */
904 case COMPOSE_FORWARD_AS_ATTACH:
905 compose_forward_multiple(NULL, msginfo_list);
907 case COMPOSE_REDIRECT:
908 compose_redirect(NULL, msginfo);
911 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
915 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
916 gboolean to_ml, gboolean to_sender,
919 compose_generic_reply(msginfo, quote, to_all, to_ml,
920 to_sender, FALSE, body);
923 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
928 compose_generic_reply(msginfo, quote, to_all, FALSE,
929 to_sender, TRUE, body);
932 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
933 gboolean to_all, gboolean to_ml,
935 gboolean followup_and_reply_to,
938 GtkItemFactory *ifactory;
940 PrefsAccount *account = NULL;
941 PrefsAccount *reply_account;
944 g_return_if_fail(msginfo != NULL);
945 g_return_if_fail(msginfo->folder != NULL);
947 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
949 g_return_if_fail(account != NULL);
951 if (to_sender && account->protocol == A_NNTP &&
952 !followup_and_reply_to) {
954 account_find_from_address(account->address);
956 reply_account = compose_current_mail_account();
960 reply_account = account;
962 compose = compose_create(account, COMPOSE_REPLY);
963 ifactory = gtk_item_factory_from_widget(compose->menubar);
965 menu_set_active(ifactory, "/Options/Remove references", FALSE);
966 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
968 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
969 if (!compose->replyinfo)
970 compose->replyinfo = procmsg_msginfo_copy(msginfo);
972 if (msginfo->folder && msginfo->folder->ret_rcpt)
973 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
975 /* Set save folder */
976 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
977 gchar *folderidentifier;
979 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
980 folderidentifier = folder_item_get_identifier(msginfo->folder);
981 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
982 g_free(folderidentifier);
985 if (compose_parse_header(compose, msginfo) < 0) return;
986 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
987 to_sender, followup_and_reply_to);
988 compose_show_first_last_header(compose, TRUE);
990 text = GTK_STEXT(compose->text);
991 gtk_stext_freeze(text);
994 if (msginfo->folder && msginfo->folder->prefs &&
995 msginfo->folder->prefs &&
996 msginfo->folder->prefs->enable_default_dictionary &&
998 gtkaspell_change_dict(compose->gtkaspell,
999 msginfo->folder->prefs->default_dictionary);
1005 if (prefs_common.quotemark && *prefs_common.quotemark)
1006 qmark = prefs_common.quotemark;
1010 compose_quote_fmt(compose, compose->replyinfo,
1011 prefs_common.quotefmt,
1015 if (account->auto_sig)
1016 compose_insert_sig(compose, FALSE);
1018 /* Must thaw here, otherwise the GtkSTextEdit will become confused
1019 * when positioning cursor */
1020 gtk_stext_thaw(text);
1023 gtk_editable_set_position
1024 (GTK_EDITABLE(text), quote_fmt_get_cursor_pos());
1025 gtk_stext_set_point(text, quote_fmt_get_cursor_pos());
1028 if (quote && prefs_common.linewrap_quote) {
1029 gtk_stext_freeze(text);
1030 compose_wrap_line_all(compose);
1031 gtk_stext_thaw(text);
1034 gtk_widget_grab_focus(compose->text);
1036 if (prefs_common.auto_exteditor)
1037 compose_exec_ext_editor(compose);
1040 #define INSERT_FW_HEADER(var, hdr) \
1041 if (msginfo->var && *msginfo->var) { \
1042 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1043 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1044 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1047 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1048 gboolean as_attach, const gchar *body,
1049 gboolean no_extedit)
1054 g_return_val_if_fail(msginfo != NULL, NULL);
1055 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1058 !(account = compose_guess_forward_account_from_msginfo
1060 account = cur_account;
1062 compose = compose_create(account, COMPOSE_FORWARD);
1064 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1065 if (!compose->fwdinfo)
1066 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1068 if (msginfo->subject && *msginfo->subject) {
1069 gchar *buf, *buf2, *p;
1071 buf = p = g_strdup(msginfo->subject);
1072 p += subject_get_prefix_length(p);
1073 memmove(buf, p, strlen(p) + 1);
1075 buf2 = g_strdup_printf("Fw: %s", buf);
1076 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1082 text = GTK_STEXT(compose->text);
1083 gtk_stext_freeze(text);
1088 msgfile = procmsg_get_message_file_path(msginfo);
1089 if (!is_file_exist(msgfile))
1090 g_warning("%s: file not exist\n", msgfile);
1092 compose_attach_append(compose, msgfile, msgfile,
1098 MsgInfo *full_msginfo;
1100 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1102 full_msginfo = procmsg_msginfo_copy(msginfo);
1104 if (prefs_common.fw_quotemark &&
1105 *prefs_common.fw_quotemark)
1106 qmark = prefs_common.fw_quotemark;
1110 compose_quote_fmt(compose, full_msginfo,
1111 prefs_common.fw_quotefmt,
1113 compose_attach_parts(compose, msginfo);
1115 procmsg_msginfo_free(full_msginfo);
1118 if (account->auto_sig)
1119 compose_insert_sig(compose, FALSE);
1121 if (prefs_common.linewrap_quote)
1122 compose_wrap_line_all(compose);
1124 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1125 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1127 gtk_stext_thaw(text);
1128 #if 0 /* NEW COMPOSE GUI */
1129 if (account->protocol != A_NNTP)
1130 gtk_widget_grab_focus(compose->to_entry);
1132 gtk_widget_grab_focus(compose->newsgroups_entry);
1134 gtk_widget_grab_focus(compose->header_last->entry);
1136 if (!no_extedit && prefs_common.auto_exteditor)
1137 compose_exec_ext_editor(compose);
1140 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1141 gchar *folderidentifier;
1143 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1144 folderidentifier = folder_item_get_identifier(msginfo->folder);
1145 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1146 g_free(folderidentifier);
1152 #undef INSERT_FW_HEADER
1154 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1161 g_return_val_if_fail(msginfo_list != NULL, NULL);
1163 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1164 if (((MsgInfo *)msginfo->data)->folder == NULL)
1167 /* guess account from first selected message */
1169 !(account = compose_guess_forward_account_from_msginfo
1170 (msginfo_list->data)))
1171 account = cur_account;
1173 g_return_val_if_fail(account != NULL, NULL);
1175 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1176 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1177 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1180 compose = compose_create(account, COMPOSE_FORWARD);
1182 text = GTK_STEXT(compose->text);
1183 gtk_stext_freeze(text);
1185 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1186 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1187 if (!is_file_exist(msgfile))
1188 g_warning("%s: file not exist\n", msgfile);
1190 compose_attach_append(compose, msgfile, msgfile,
1195 if (account->auto_sig)
1196 compose_insert_sig(compose, FALSE);
1198 if (prefs_common.linewrap_quote)
1199 compose_wrap_line_all(compose);
1201 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1202 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1204 gtk_stext_thaw(text);
1205 gtk_widget_grab_focus(compose->header_last->entry);
1207 #if 0 /* NEW COMPOSE GUI */
1208 if (account->protocol != A_NNTP)
1209 gtk_widget_grab_focus(compose->to_entry);
1211 gtk_widget_grab_focus(compose->newsgroups_entry);
1217 void compose_reedit(MsgInfo *msginfo)
1220 PrefsAccount *account = NULL;
1223 gchar buf[BUFFSIZE];
1224 gboolean use_signing = FALSE;
1225 gboolean use_encryption = FALSE;
1226 gchar *privacy_system = NULL;
1228 g_return_if_fail(msginfo != NULL);
1229 g_return_if_fail(msginfo->folder != NULL);
1231 if (compose_put_existing_to_front(msginfo))
1234 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1235 gchar queueheader_buf[BUFFSIZE];
1238 /* Select Account from queue headers */
1239 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1240 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1241 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1242 account = account_find_from_id(id);
1244 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1245 sizeof(queueheader_buf), "NAID:")) {
1246 id = atoi(&queueheader_buf[strlen("NAID:")]);
1247 account = account_find_from_id(id);
1249 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1250 sizeof(queueheader_buf), "MAID:")) {
1251 id = atoi(&queueheader_buf[strlen("MAID:")]);
1252 account = account_find_from_id(id);
1254 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1255 sizeof(queueheader_buf), "S:")) {
1256 account = account_find_from_address(queueheader_buf);
1258 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1259 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1260 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1261 use_signing = param;
1264 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1265 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1266 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1267 use_encryption = param;
1269 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1270 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1271 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1273 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1274 sizeof(queueheader_buf), "X-Priority: ")) {
1275 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1276 compose->priority = param;
1279 account = msginfo->folder->folder->account;
1281 if (!account && prefs_common.reedit_account_autosel) {
1282 gchar from[BUFFSIZE];
1283 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1284 extract_address(from);
1285 account = account_find_from_address(from);
1288 if (!account) account = cur_account;
1289 g_return_if_fail(account != NULL);
1291 compose = compose_create(account, COMPOSE_REEDIT);
1292 compose->privacy_system = privacy_system;
1293 compose_use_signing(compose, use_signing);
1294 compose_use_encryption(compose, use_encryption);
1295 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1297 if (msginfo->folder->stype == F_QUEUE
1298 || msginfo->folder->stype == F_DRAFT) {
1299 gchar queueheader_buf[BUFFSIZE];
1301 /* Set message save folder */
1302 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1305 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1306 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1307 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1311 if (compose_parse_header(compose, msginfo) < 0) return;
1312 compose_reedit_set_entry(compose, msginfo);
1314 text = GTK_STEXT(compose->text);
1315 gtk_stext_freeze(text);
1317 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1318 g_warning("Can't get text part\n");
1320 while (fgets(buf, sizeof(buf), fp) != NULL) {
1322 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1326 compose_attach_parts(compose, msginfo);
1328 gtk_stext_thaw(text);
1329 gtk_widget_grab_focus(compose->text);
1331 if (prefs_common.auto_exteditor)
1332 compose_exec_ext_editor(compose);
1335 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1339 GtkItemFactory *ifactory;
1342 g_return_val_if_fail(msginfo != NULL, NULL);
1345 account = account_get_reply_account(msginfo,
1346 prefs_common.reply_account_autosel);
1347 g_return_val_if_fail(account != NULL, NULL);
1349 compose = compose_create(account, COMPOSE_REDIRECT);
1350 ifactory = gtk_item_factory_from_widget(compose->menubar);
1352 compose->replyinfo = NULL;
1353 compose->fwdinfo = NULL;
1355 compose_show_first_last_header(compose, TRUE);
1357 gtk_widget_grab_focus(compose->header_last->entry);
1359 filename = procmsg_get_message_file(msginfo);
1360 if (filename == NULL)
1363 compose->redirect_filename = filename;
1365 /* Set save folder */
1366 item = msginfo->folder;
1367 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1368 gchar *folderidentifier;
1370 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1371 folderidentifier = folder_item_get_identifier(item);
1372 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1373 g_free(folderidentifier);
1376 compose_attach_parts(compose, msginfo);
1378 if (msginfo->subject)
1379 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1381 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1383 gtk_stext_freeze(GTK_STEXT(compose->text));
1384 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1385 gtk_editable_set_editable(GTK_EDITABLE(compose->text), FALSE);
1386 gtk_stext_thaw(GTK_STEXT(compose->text));
1388 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1389 menu_set_sensitive(ifactory, "/Add...", FALSE);
1390 menu_set_sensitive(ifactory, "/Remove", FALSE);
1391 menu_set_sensitive(ifactory, "/Property...", FALSE);
1393 ifactory = gtk_item_factory_from_widget(compose->menubar);
1394 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1395 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1396 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1397 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1398 menu_set_sensitive(ifactory, "/Edit", FALSE);
1399 menu_set_sensitive(ifactory, "/Options/Sign", FALSE);
1400 menu_set_sensitive(ifactory, "/Options/Encrypt", FALSE);
1401 menu_set_sensitive(ifactory, "/Options/Priority", FALSE);
1402 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
1403 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1404 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1406 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1407 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1408 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1409 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1410 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1411 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1412 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1417 GList *compose_get_compose_list(void)
1419 return compose_list;
1422 void compose_entry_append(Compose *compose, const gchar *address,
1423 ComposeEntryType type)
1427 if (!address || *address == '\0') return;
1429 #if 0 /* NEW COMPOSE GUI */
1432 entry = GTK_ENTRY(compose->cc_entry);
1435 entry = GTK_ENTRY(compose->bcc_entry);
1437 case COMPOSE_NEWSGROUPS:
1438 entry = GTK_ENTRY(compose->newsgroups_entry);
1442 entry = GTK_ENTRY(compose->to_entry);
1446 text = gtk_entry_get_text(entry);
1448 gtk_entry_append_text(entry, ", ");
1449 gtk_entry_append_text(entry, address);
1457 header = N_("Bcc:");
1459 case COMPOSE_REPLYTO:
1460 header = N_("Reply-To:");
1462 case COMPOSE_NEWSGROUPS:
1463 header = N_("Newsgroups:");
1465 case COMPOSE_FOLLOWUPTO:
1466 header = N_( "Followup-To:");
1473 header = prefs_common.trans_hdr ? gettext(header) : header;
1475 compose_add_header_entry(compose, header, (gchar *)address);
1478 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1480 static GtkStyle *bold_style = NULL;
1481 static GdkColor bold_color;
1482 static GdkFont *bold_font = NULL;
1486 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1487 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1488 if (gtk_entry_get_text(entry) &&
1489 !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1490 gtk_widget_ensure_style(GTK_WIDGET(entry));
1492 gtkut_convert_int_to_gdk_color
1493 (prefs_common.color_new, &bold_color);
1494 bold_style = gtk_style_copy(gtk_widget_get_style
1495 (GTK_WIDGET(entry)));
1497 bold_font = gtkut_font_load
1498 (prefs_common.boldfont);
1500 bold_style->font = bold_font;
1501 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1503 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1508 void compose_toolbar_cb(gint action, gpointer data)
1510 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1511 Compose *compose = (Compose*)toolbar_item->parent;
1513 g_return_if_fail(compose != NULL);
1517 compose_send_cb(compose, 0, NULL);
1520 compose_send_later_cb(compose, 0, NULL);
1523 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1526 compose_insert_file_cb(compose, 0, NULL);
1529 compose_attach_cb(compose, 0, NULL);
1532 compose_insert_sig(compose, FALSE);
1535 compose_ext_editor_cb(compose, 0, NULL);
1537 case A_LINEWRAP_CURRENT:
1538 compose_wrap_line(compose);
1540 case A_LINEWRAP_ALL:
1541 compose_wrap_line_all(compose);
1544 compose_address_cb(compose, 0, NULL);
1547 case A_CHECK_SPELLING:
1548 compose_check_all(compose);
1556 static void compose_entries_set(Compose *compose, const gchar *mailto)
1561 gchar *subject = NULL;
1564 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1567 compose_entry_append(compose, to, COMPOSE_TO);
1569 compose_entry_append(compose, cc, COMPOSE_CC);
1571 compose_entry_append(compose, bcc, COMPOSE_BCC);
1573 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1575 gtk_stext_insert(GTK_STEXT(compose->text),
1576 NULL, NULL, NULL, body, -1);
1577 gtk_stext_insert(GTK_STEXT(compose->text),
1578 NULL, NULL, NULL, "\n", 1);
1588 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1590 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1591 {"Cc:", NULL, TRUE},
1592 {"References:", NULL, FALSE},
1593 {"Bcc:", NULL, TRUE},
1594 {"Newsgroups:", NULL, TRUE},
1595 {"Followup-To:", NULL, TRUE},
1596 {"List-Post:", NULL, FALSE},
1597 {"X-Priority:", NULL, FALSE},
1598 {NULL, NULL, FALSE}};
1614 g_return_val_if_fail(msginfo != NULL, -1);
1616 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1617 procheader_get_header_fields(fp, hentry);
1620 if (hentry[H_REPLY_TO].body != NULL) {
1621 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1622 compose->replyto = hentry[H_REPLY_TO].body;
1623 hentry[H_REPLY_TO].body = NULL;
1625 if (hentry[H_CC].body != NULL) {
1626 conv_unmime_header_overwrite(hentry[H_CC].body);
1627 compose->cc = hentry[H_CC].body;
1628 hentry[H_CC].body = NULL;
1630 if (hentry[H_REFERENCES].body != NULL) {
1631 if (compose->mode == COMPOSE_REEDIT)
1632 compose->references = hentry[H_REFERENCES].body;
1634 compose->references = compose_parse_references
1635 (hentry[H_REFERENCES].body, msginfo->msgid);
1636 g_free(hentry[H_REFERENCES].body);
1638 hentry[H_REFERENCES].body = NULL;
1640 if (hentry[H_BCC].body != NULL) {
1641 if (compose->mode == COMPOSE_REEDIT) {
1642 conv_unmime_header_overwrite(hentry[H_BCC].body);
1643 compose->bcc = hentry[H_BCC].body;
1645 g_free(hentry[H_BCC].body);
1646 hentry[H_BCC].body = NULL;
1648 if (hentry[H_NEWSGROUPS].body != NULL) {
1649 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1650 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1651 hentry[H_NEWSGROUPS].body = NULL;
1653 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1654 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1655 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1656 hentry[H_FOLLOWUP_TO].body = NULL;
1658 if (hentry[H_LIST_POST].body != NULL) {
1661 extract_address(hentry[H_LIST_POST].body);
1662 if (hentry[H_LIST_POST].body[0] != '\0') {
1663 scan_mailto_url(hentry[H_LIST_POST].body,
1664 &to, NULL, NULL, NULL, NULL);
1666 g_free(compose->ml_post);
1667 compose->ml_post = to;
1670 g_free(hentry[H_LIST_POST].body);
1671 hentry[H_LIST_POST].body = NULL;
1674 /* CLAWS - X-Priority */
1675 if (compose->mode == COMPOSE_REEDIT)
1676 if (hentry[H_X_PRIORITY].body != NULL) {
1679 priority = atoi(hentry[H_X_PRIORITY].body);
1680 g_free(hentry[H_X_PRIORITY].body);
1682 hentry[H_X_PRIORITY].body = NULL;
1684 if (priority < PRIORITY_HIGHEST ||
1685 priority > PRIORITY_LOWEST)
1686 priority = PRIORITY_NORMAL;
1688 compose->priority = priority;
1691 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1692 compose->inreplyto = g_strdup(msginfo->inreplyto);
1693 else if (compose->mode != COMPOSE_REEDIT &&
1694 msginfo->msgid && *msginfo->msgid) {
1695 compose->inreplyto = g_strdup(msginfo->msgid);
1697 if (!compose->references) {
1698 if (msginfo->inreplyto && *msginfo->inreplyto)
1699 compose->references =
1700 g_strdup_printf("<%s>\n\t<%s>",
1704 compose->references =
1705 g_strconcat("<", msginfo->msgid, ">",
1713 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1715 GSList *ref_id_list, *cur;
1719 ref_id_list = references_list_append(NULL, ref);
1720 if (!ref_id_list) return NULL;
1721 if (msgid && *msgid)
1722 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1727 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1728 /* "<" + Message-ID + ">" + CR+LF+TAB */
1729 len += strlen((gchar *)cur->data) + 5;
1731 if (len > MAX_REFERENCES_LEN) {
1732 /* remove second message-ID */
1733 if (ref_id_list && ref_id_list->next &&
1734 ref_id_list->next->next) {
1735 g_free(ref_id_list->next->data);
1736 ref_id_list = g_slist_remove
1737 (ref_id_list, ref_id_list->next->data);
1739 slist_free_strings(ref_id_list);
1740 g_slist_free(ref_id_list);
1747 new_ref = g_string_new("");
1748 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1749 if (new_ref->len > 0)
1750 g_string_append(new_ref, "\n\t");
1751 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1754 slist_free_strings(ref_id_list);
1755 g_slist_free(ref_id_list);
1757 new_ref_str = new_ref->str;
1758 g_string_free(new_ref, FALSE);
1763 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1764 const gchar *fmt, const gchar *qmark,
1767 GtkSText *text = GTK_STEXT(compose->text);
1768 static MsgInfo dummyinfo;
1769 gchar *quote_str = NULL;
1773 const gchar *trimmed_body = body;
1776 msginfo = &dummyinfo;
1778 if (qmark != NULL) {
1779 quote_fmt_init(msginfo, NULL, NULL);
1780 quote_fmt_scan_string(qmark);
1783 buf = quote_fmt_get_buffer();
1785 alertpanel_error(_("Quote mark format error."));
1787 Xstrdup_a(quote_str, buf, return NULL)
1790 if (fmt && *fmt != '\0') {
1791 while (trimmed_body && strlen(trimmed_body) > 1
1792 && trimmed_body[0]=='\n')
1795 quote_fmt_init(msginfo, quote_str, trimmed_body);
1796 quote_fmt_scan_string(fmt);
1799 buf = quote_fmt_get_buffer();
1801 alertpanel_error(_("Message reply/forward format error."));
1807 gtk_stext_freeze(text);
1809 for (p = buf; *p != '\0'; ) {
1810 lastp = strchr(p, '\n');
1811 len = lastp ? lastp - p + 1 : -1;
1812 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1819 gtk_stext_thaw(text);
1824 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1825 gboolean to_all, gboolean to_ml,
1827 gboolean followup_and_reply_to)
1829 GSList *cc_list = NULL;
1832 gchar *replyto = NULL;
1833 GHashTable *to_table;
1835 g_return_if_fail(compose->account != NULL);
1836 g_return_if_fail(msginfo != NULL);
1838 if (compose->account->protocol != A_NNTP) {
1839 if (!compose->replyto && to_ml && compose->ml_post
1840 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1841 compose_entry_append(compose,
1844 else if (!(to_all || to_sender)
1846 && msginfo->folder->prefs->enable_default_reply_to) {
1847 compose_entry_append(compose,
1848 msginfo->folder->prefs->default_reply_to,
1851 compose_entry_append(compose,
1852 (compose->replyto && !to_sender)
1853 ? compose->replyto :
1854 msginfo->from ? msginfo->from : "",
1857 if (to_sender || (compose->followup_to &&
1858 !strncmp(compose->followup_to, "poster", 6)))
1859 compose_entry_append
1861 (compose->replyto ? compose->replyto :
1862 msginfo->from ? msginfo->from : ""),
1865 else if (followup_and_reply_to || to_all) {
1866 compose_entry_append
1868 (compose->replyto ? compose->replyto :
1869 msginfo->from ? msginfo->from : ""),
1872 compose_entry_append
1874 compose->followup_to ? compose->followup_to :
1875 compose->newsgroups ? compose->newsgroups : "",
1876 COMPOSE_NEWSGROUPS);
1879 compose_entry_append
1881 compose->followup_to ? compose->followup_to :
1882 compose->newsgroups ? compose->newsgroups : "",
1883 COMPOSE_NEWSGROUPS);
1886 if (msginfo->subject && *msginfo->subject) {
1890 buf = p = g_strdup(msginfo->subject);
1891 p += subject_get_prefix_length(p);
1892 memmove(buf, p, strlen(p) + 1);
1894 buf2 = g_strdup_printf("Re: %s", buf);
1895 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1900 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1902 if (to_ml && compose->ml_post) return;
1903 if (!to_all || compose->account->protocol == A_NNTP) return;
1905 if (compose->replyto) {
1906 Xstrdup_a(replyto, compose->replyto, return);
1907 extract_address(replyto);
1909 if (msginfo->from) {
1910 Xstrdup_a(from, msginfo->from, return);
1911 extract_address(from);
1914 if (replyto && from)
1915 cc_list = address_list_append_with_comments(cc_list, from);
1916 if (to_all && msginfo->folder &&
1917 msginfo->folder->prefs->enable_default_reply_to)
1918 cc_list = address_list_append_with_comments(cc_list,
1919 msginfo->folder->prefs->default_reply_to);
1920 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1921 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1923 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1925 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1926 if (compose->account)
1927 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1928 GINT_TO_POINTER(1));
1930 /* remove address on To: and that of current account */
1931 for (cur = cc_list; cur != NULL; ) {
1932 GSList *next = cur->next;
1935 addr = g_strdup(cur->data);
1936 extract_address(addr);
1938 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
1939 cc_list = g_slist_remove(cc_list, cur->data);
1941 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
1945 hash_free_strings(to_table);
1946 g_hash_table_destroy(to_table);
1949 for (cur = cc_list; cur != NULL; cur = cur->next)
1950 compose_entry_append(compose, (gchar *)cur->data,
1952 slist_free_strings(cc_list);
1953 g_slist_free(cc_list);
1958 #define SET_ENTRY(entry, str) \
1961 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1964 #define SET_ADDRESS(type, str) \
1967 compose_entry_append(compose, str, type); \
1970 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1972 g_return_if_fail(msginfo != NULL);
1974 SET_ENTRY(subject_entry, msginfo->subject);
1975 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1976 SET_ADDRESS(COMPOSE_CC, compose->cc);
1977 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1978 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1979 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
1980 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
1982 compose_update_priority_menu_item(compose);
1983 compose_update_privacy_system_menu_item(compose);
1984 compose_show_first_last_header(compose, TRUE);
1990 static void compose_insert_sig(Compose *compose, gboolean replace)
1992 GtkSText *text = GTK_STEXT(compose->text);
1996 g_return_if_fail(compose->account != NULL);
1998 cur_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2000 gtk_stext_freeze(text);
2003 len = gtk_stext_get_length(text);
2004 gtk_stext_set_point(text, len);
2007 if (replace && compose->sig_str) {
2010 if (compose->sig_str[0] == '\0')
2013 pos = gtkut_stext_find(text, 0, compose->sig_str, TRUE);
2016 len = get_mbs_len(compose->sig_str);
2018 gtk_stext_set_point(text, pos);
2019 gtk_stext_forward_delete(text, len);
2024 g_free(compose->sig_str);
2025 compose->sig_str = compose_get_signature_str(compose);
2026 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2027 compose->sig_str = g_strdup("");
2029 gtk_stext_insert(text, NULL, NULL, NULL, compose->sig_str, -1);
2031 gtk_stext_thaw(text);
2033 if (cur_pos > gtk_stext_get_length(text))
2034 cur_pos = gtk_stext_get_length(text);
2036 gtk_editable_set_position(GTK_EDITABLE(text), cur_pos);
2037 gtk_stext_set_point(text, cur_pos);
2040 static gchar *compose_get_signature_str(Compose *compose)
2042 gchar *sig_body = NULL;
2043 gchar *sig_str = NULL;
2045 g_return_val_if_fail(compose->account != NULL, NULL);
2047 if (!compose->account->sig_path)
2050 if (compose->account->sig_type == SIG_FILE) {
2051 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2052 g_warning("can't open signature file: %s\n",
2053 compose->account->sig_path);
2058 if (compose->account->sig_type == SIG_COMMAND)
2059 sig_body = get_command_output(compose->account->sig_path);
2063 tmp = file_read_to_str(compose->account->sig_path);
2066 sig_body = normalize_newlines(tmp);
2070 if (compose->account->sig_sep)
2071 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2074 sig_str = g_strconcat("\n\n", sig_body, NULL);
2081 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2083 GtkSText *text = GTK_STEXT(compose->text);
2084 gchar buf[BUFFSIZE];
2087 gboolean badtxt = FALSE;
2089 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2091 if ((fp = fopen(file, "rb")) == NULL) {
2092 FILE_OP_ERROR(file, "fopen");
2093 return COMPOSE_INSERT_READ_ERROR;
2096 gtk_stext_freeze(text);
2098 while (fgets(buf, sizeof(buf), fp) != NULL) {
2099 /* strip <CR> if DOS/Windows file,
2100 replace <CR> with <LF> if Macintosh file. */
2103 if (len > 0 && buf[len - 1] != '\n') {
2105 if (buf[len] == '\r') buf[len] = '\n';
2107 if (mbstowcs(NULL, buf, 0) == -1)
2109 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
2112 gtk_stext_thaw(text);
2117 return COMPOSE_INSERT_INVALID_CHARACTER;
2119 return COMPOSE_INSERT_SUCCESS;
2122 static void compose_attach_append(Compose *compose, const gchar *file,
2123 const gchar *filename,
2124 const gchar *content_type)
2127 gchar *text[N_ATTACH_COLS];
2132 if (!is_file_exist(file)) {
2133 g_warning("File %s doesn't exist\n", file);
2136 if ((size = get_file_size(file)) < 0) {
2137 g_warning("Can't get file size of %s\n", file);
2141 alertpanel_notice(_("File %s is empty."), file);
2144 if ((fp = fopen(file, "rb")) == NULL) {
2145 alertpanel_error(_("Can't read %s."), file);
2150 #if 0 /* NEW COMPOSE GUI */
2151 if (!compose->use_attach) {
2152 GtkItemFactory *ifactory;
2154 ifactory = gtk_item_factory_from_widget(compose->menubar);
2155 menu_set_active(ifactory, "/View/Attachment", TRUE);
2158 ainfo = g_new0(AttachInfo, 1);
2159 ainfo->file = g_strdup(file);
2162 ainfo->content_type = g_strdup(content_type);
2163 if (!g_strcasecmp(content_type, "message/rfc822")) {
2165 MsgFlags flags = {0, 0};
2168 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2169 ainfo->encoding = ENC_7BIT;
2171 ainfo->encoding = ENC_8BIT;
2173 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2174 if (msginfo && msginfo->subject)
2175 name = msginfo->subject;
2177 name = g_basename(filename ? filename : file);
2179 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2181 procmsg_msginfo_free(msginfo);
2183 if (!g_strncasecmp(content_type, "text", 4))
2184 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2186 ainfo->encoding = ENC_BASE64;
2187 ainfo->name = g_strdup
2188 (g_basename(filename ? filename : file));
2191 ainfo->content_type = procmime_get_mime_type(file);
2192 if (!ainfo->content_type) {
2193 ainfo->content_type =
2194 g_strdup("application/octet-stream");
2195 ainfo->encoding = ENC_BASE64;
2196 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
2198 procmime_get_encoding_for_text_file(file);
2200 ainfo->encoding = ENC_BASE64;
2201 ainfo->name = g_strdup(g_basename(filename ? filename : file));
2204 if (!strcmp(ainfo->content_type, "unknown")) {
2205 g_free(ainfo->content_type);
2206 ainfo->content_type = g_strdup("application/octet-stream");
2211 text[COL_MIMETYPE] = ainfo->content_type;
2212 text[COL_SIZE] = to_human_readable(size);
2213 text[COL_NAME] = ainfo->name;
2215 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2216 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2219 static void compose_use_signing(Compose *compose, gboolean use_signing)
2221 GtkItemFactory *ifactory;
2222 GtkWidget *menuitem = NULL;
2224 compose->use_signing = use_signing;
2225 ifactory = gtk_item_factory_from_widget(compose->menubar);
2226 menuitem = gtk_item_factory_get_item
2227 (ifactory, "/Options/Sign");
2228 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2232 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2234 GtkItemFactory *ifactory;
2235 GtkWidget *menuitem = NULL;
2237 compose->use_encryption = use_encryption;
2238 ifactory = gtk_item_factory_from_widget(compose->menubar);
2239 menuitem = gtk_item_factory_get_item
2240 (ifactory, "/Options/Encrypt");
2242 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2246 #define NEXT_PART_NOT_CHILD(info) \
2248 node = info->node; \
2249 while (node->children) \
2250 node = g_node_last_child(node); \
2251 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2254 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2258 MimeInfo *firsttext = NULL;
2259 MimeInfo *encrypted = NULL;
2262 const gchar *partname = NULL;
2264 mimeinfo = procmime_scan_message(msginfo);
2265 if (!mimeinfo) return;
2267 if (mimeinfo->node->children == NULL) {
2268 procmime_mimeinfo_free_all(mimeinfo);
2272 /* find first content part */
2273 child = (MimeInfo *) mimeinfo->node->children->data;
2274 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2275 child = (MimeInfo *)child->node->children->data;
2277 if (child->type == MIMETYPE_TEXT) {
2279 debug_print("First text part found\n");
2280 } else if (compose->mode == COMPOSE_REEDIT &&
2281 child->type == MIMETYPE_APPLICATION &&
2282 !g_strcasecmp(child->subtype, "pgp-encrypted")) {
2284 val = alertpanel(_("Encrypted message"),
2285 _("Cannot re-edit an encrypted message. \n"
2286 "Discard encrypted part?"),
2287 _("Yes"), _("No"), NULL);
2288 if (val == G_ALERTDEFAULT)
2289 encrypted = (MimeInfo *)child->node->parent->data;
2292 child = (MimeInfo *) mimeinfo->node->children->data;
2293 while (child != NULL) {
2294 if (child == encrypted) {
2295 /* skip this part of tree */
2296 NEXT_PART_NOT_CHILD(child);
2300 if (child->type == MIMETYPE_MULTIPART) {
2301 /* get the actual content */
2302 child = procmime_mimeinfo_next(child);
2306 if (child == firsttext) {
2307 child = procmime_mimeinfo_next(child);
2311 outfile = procmime_get_tmp_file_name(child);
2312 if (procmime_get_part(outfile, child) < 0)
2313 g_warning("Can't get the part of multipart message.");
2315 gchar *content_type;
2317 content_type = procmime_get_content_type_str(child->type, child->subtype);
2318 partname = procmime_mimeinfo_get_parameter(child, "name");
2319 if (partname == NULL)
2321 compose_attach_append(compose, outfile,
2322 partname, content_type);
2323 g_free(content_type);
2326 NEXT_PART_NOT_CHILD(child);
2328 procmime_mimeinfo_free_all(mimeinfo);
2331 #undef NEXT_PART_NOT_CHILD
2333 #define GET_CHAR(pos, buf, len) \
2335 if (text->use_wchar) \
2336 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2338 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2343 #define DISP_WIDTH(len) \
2344 ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
2345 (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
2347 #define SPACE_CHARS " \t"
2349 static void compose_wrap_line(Compose *compose)
2351 GtkSText *text = GTK_STEXT(compose->text);
2352 gint ch_len, last_ch_len;
2353 gchar cbuf[MB_LEN_MAX], last_ch;
2357 gint p_start, p_end;
2358 gint line_pos, cur_pos;
2359 gint line_len, cur_len;
2361 gtk_stext_freeze(text);
2363 text_len = gtk_stext_get_length(text);
2365 /* check to see if the point is on the paragraph mark (empty line). */
2366 cur_pos = gtk_stext_get_point(text);
2367 GET_CHAR(cur_pos, cbuf, ch_len);
2368 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2370 goto compose_end; /* on the paragraph mark */
2371 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2372 if (ch_len == 1 && *cbuf == '\n')
2373 goto compose_end; /* on the paragraph mark */
2376 /* find paragraph start. */
2377 line_end = quoted = 0;
2378 for (p_start = cur_pos; p_start >= 0; --p_start) {
2379 GET_CHAR(p_start, cbuf, ch_len);
2380 if (ch_len == 1 && *cbuf == '\n') {
2382 goto compose_end; /* quoted part */
2390 && strchr(prefs_common.quote_chars, *cbuf))
2392 else if (ch_len != 1 || !isspace(*(guchar *)cbuf))
2401 /* find paragraph end. */
2403 for (p_end = cur_pos; p_end < text_len; p_end++) {
2404 GET_CHAR(p_end, cbuf, ch_len);
2405 if (ch_len == 1 && *cbuf == '\n') {
2412 if (line_end && ch_len == 1 &&
2413 strchr(prefs_common.quote_chars, *cbuf))
2414 goto compose_end; /* quoted part */
2419 if (p_end >= text_len)
2422 if (p_start >= p_end)
2425 line_len = cur_len = 0;
2429 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2432 GET_CHAR(cur_pos, cbuf, ch_len);
2439 if (ch_len == 1 && isspace(*(guchar *)cbuf))
2442 if (ch_len == 1 && *cbuf == '\n') {
2444 if (last_ch_len == 1 && !isspace((guchar)last_ch)) {
2445 if (cur_pos + 1 < p_end) {
2446 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2448 !isspace(*(guchar *)cbuf))
2452 gtk_stext_set_point(text, cur_pos + 1);
2453 gtk_stext_backward_delete(text, 1);
2455 gtk_stext_set_point(text, cur_pos);
2456 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2466 last_ch_len = ch_len;
2470 line_pos = cur_pos + 1;
2471 line_len = cur_len + ch_len;
2474 if (cur_len + DISP_WIDTH(ch_len) > prefs_common.linewrap_len &&
2478 GET_CHAR(line_pos - 1, cbuf, ch_len);
2479 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2480 gtk_stext_set_point(text, line_pos);
2481 gtk_stext_backward_delete(text, 1);
2490 gtk_stext_set_point(text, line_pos);
2491 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2495 cur_len = cur_len - line_len + DISP_WIDTH(ch_len);
2501 line_pos = cur_pos + 1;
2502 line_len = cur_len + DISP_WIDTH(ch_len);
2504 cur_len += DISP_WIDTH(ch_len);
2508 gtk_stext_thaw(text);
2513 /* Darko: used when I debug wrapping */
2514 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2517 gchar cbuf[MB_LEN_MAX];
2519 printf("%d [", pos);
2520 for (i = pos; i < tlen; i++) {
2521 GET_CHAR(i, cbuf, clen);
2522 if (clen < 0) break;
2523 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2525 fwrite(cbuf, clen, 1, stdout);
2533 WAIT_FOR_INDENT_CHAR,
2534 WAIT_FOR_INDENT_CHAR_OR_SPACE
2537 /* return indent length, we allow:
2538 > followed by spaces/tabs
2539 | followed by spaces/tabs
2540 uppercase characters immediately followed by >,
2541 and the repeating sequences of the above */
2542 /* return indent length */
2543 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2546 guint i, ch_len, alnum_cnt = 0;
2547 IndentState state = WAIT_FOR_INDENT_CHAR;
2548 gchar cbuf[MB_LEN_MAX];
2552 if (prefs_common.quote_chars == NULL) {
2556 for (i = start_pos; i < text_len; i++) {
2557 GET_CHAR(i, cbuf, ch_len);
2561 if (cbuf[0] == '\n')
2564 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2565 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2568 case WAIT_FOR_SPACE:
2569 if (is_space == FALSE)
2571 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2573 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2574 if (is_indent == FALSE && is_space == FALSE &&
2575 !isupper((guchar)cbuf[0]))
2577 if (is_space == TRUE) {
2579 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2580 } else if (is_indent == TRUE) {
2582 state = WAIT_FOR_SPACE;
2585 state = WAIT_FOR_INDENT_CHAR;
2588 case WAIT_FOR_INDENT_CHAR:
2589 if (is_indent == FALSE && !isupper((guchar)cbuf[0]))
2591 if (is_indent == TRUE) {
2593 && !strchr(prefs_common.quote_chars, cbuf[0]))
2596 state = WAIT_FOR_SPACE;
2607 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2613 /* insert quotation string when line was wrapped */
2614 static guint ins_quote(GtkSText *text, guint indent_len,
2615 guint prev_line_pos, guint text_len,
2618 guint i, ins_len = 0;
2622 for (i = 0; i < indent_len; i++) {
2623 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2624 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2626 ins_len = indent_len;
2632 /* check if we should join the next line */
2633 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2634 guint prev_ilen, gboolean autowrap)
2636 guint indent_len, ch_len;
2637 gboolean do_join = FALSE;
2638 gchar cbuf[MB_LEN_MAX];
2640 indent_len = get_indent_length(text, start_pos, tlen);
2642 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2643 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2644 if (ch_len > 0 && (cbuf[0] != '\n'))
2651 static void compose_wrap_line_all(Compose *compose)
2653 compose_wrap_line_all_full(compose, FALSE);
2656 #define STEXT_FREEZE() \
2657 if (!frozen) { gtk_stext_freeze(text); frozen = TRUE; }
2659 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2661 GtkSText *text = GTK_STEXT(compose->text);
2663 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2664 gint line_len = 0, cur_len = 0;
2666 gboolean is_new_line = TRUE, do_delete = FALSE;
2668 gboolean linewrap_quote = prefs_common.linewrap_quote;
2669 gboolean set_editable_pos = FALSE;
2670 gint editable_pos = 0;
2671 gboolean frozen = FALSE;
2672 guint linewrap_len = prefs_common.linewrap_len;
2673 gchar *qfmt = prefs_common.quotemark;
2674 gchar cbuf[MB_LEN_MAX];
2676 tlen = gtk_stext_get_length(text);
2678 for (; cur_pos < tlen; cur_pos++) {
2679 /* mark position of new line - needed for quotation wrap */
2682 i_len = get_indent_length(text, cur_pos, tlen);
2684 is_new_line = FALSE;
2687 g_print("new line i_len=%d p_pos=", i_len);
2688 dump_text(text, p_pos, tlen, 1);
2692 GET_CHAR(cur_pos, cbuf, ch_len);
2694 /* fix line length for tabs */
2695 if (ch_len == 1 && *cbuf == '\t') {
2696 guint tab_width = text->default_tab_width;
2697 guint tab_offset = line_len % tab_width;
2700 g_print("found tab at pos=%d line_len=%d ", cur_pos,
2704 line_len += tab_width - tab_offset - 1;
2708 printf("new_len=%d\n", line_len);
2712 /* we have encountered line break */
2713 if (ch_len == 1 && *cbuf == '\n') {
2715 gchar cb[MB_LEN_MAX];
2717 /* should we join the next line */
2718 if ((autowrap || i_len != cur_len) && do_delete &&
2720 (text, cur_pos + 1, tlen, i_len, autowrap))
2726 g_print("found CR at %d do_del is %d next line is ",
2727 cur_pos, do_delete);
2728 dump_text(text, cur_pos + 1, tlen, 1);
2731 /* skip delete if it is continuous URL */
2732 if (do_delete && (line_pos - p_pos <= i_len) &&
2733 gtk_stext_is_uri_string(text, line_pos, tlen))
2737 g_print("l_len=%d wrap_len=%d do_del=%d\n",
2738 line_len, linewrap_len, do_delete);
2740 if (line_len < linewrap_len && do_delete) {
2742 /* get rid of newline */
2743 gtk_stext_set_point(text, cur_pos);
2744 gtk_stext_forward_delete(text, 1);
2747 /* if text starts with quote fmt or with
2748 indent string, delete them */
2751 ilen = gtk_stext_str_compare_n
2752 (text, cur_pos, p_pos, i_len,
2755 gtk_stext_forward_delete
2761 GET_CHAR(cur_pos, cb, clen);
2763 /* insert space if it's alphanumeric */
2764 if ((cur_pos != line_pos) &&
2765 ((clen > 1) || isalnum((guchar)cb[0]))) {
2766 gtk_stext_insert(text, NULL, NULL,
2771 /* and start over with current line */
2772 cur_pos = p_pos - 1;
2774 line_len = cur_len = 0;
2778 g_print("after delete l_pos=");
2779 dump_text(text, line_pos, tlen, 1);
2781 /* move beginning of line if we are on LF */
2782 GET_CHAR(line_pos, cb, clen);
2783 if (clen == 1 && *cb == '\n')
2786 g_print("new line_pos=%d\n", line_pos);
2792 /* mark new line beginning */
2793 line_pos = cur_pos + 1;
2794 line_len = cur_len = 0;
2805 /* possible line break */
2806 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2807 line_pos = cur_pos + 1;
2808 line_len = cur_len + ch_len;
2811 /* are we over wrapping length set in preferences ? */
2812 if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
2816 g_print("should wrap cur_pos=%d ", cur_pos);
2817 dump_text(text, p_pos, tlen, 1);
2818 dump_text(text, line_pos, tlen, 1);
2820 /* force wrapping if it is one long word but not URL */
2821 if (line_pos - p_pos <= i_len)
2822 if (!gtk_stext_is_uri_string
2823 (text, line_pos, tlen))
2824 line_pos = cur_pos - 1;
2826 g_print("new line_pos=%d\n", line_pos);
2829 GET_CHAR(line_pos - 1, cbuf, clen);
2831 /* if next character is space delete it */
2832 if (clen == 1 && isspace(*(guchar *)cbuf)) {
2833 if (p_pos + i_len != line_pos ||
2834 !gtk_stext_is_uri_string
2835 (text, line_pos, tlen)) {
2837 /* workaround for correct cursor
2839 if (set_editable_pos == FALSE) {
2840 editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2841 if (editable_pos == line_pos)
2842 set_editable_pos = TRUE;
2844 gtk_stext_set_point(text, line_pos);
2845 gtk_stext_backward_delete(text, 1);
2854 /* if it is URL at beginning of line don't wrap */
2855 if (p_pos + i_len == line_pos &&
2856 gtk_stext_is_uri_string(text, line_pos, tlen)) {
2858 g_print("found URL at ");
2859 dump_text(text, line_pos, tlen, 1);
2866 gtk_stext_set_point(text, line_pos);
2867 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2868 gtk_stext_compact_buffer(text);
2871 /* for loop will increase it */
2872 cur_pos = line_pos - 1;
2873 /* start over with current line */
2875 line_len = cur_len = 0;
2876 if (autowrap || i_len > 0)
2881 g_print("after CR insert ");
2882 dump_text(text, line_pos, tlen, 1);
2883 dump_text(text, cur_pos, tlen, 1);
2886 /* should we insert quotation ? */
2887 if (linewrap_quote && i_len) {
2888 /* only if line is not already quoted */
2889 if (!gtk_stext_str_compare
2890 (text, line_pos, tlen, qfmt)) {
2893 if (line_pos - p_pos > i_len) {
2895 (text, i_len, p_pos,
2900 g_print("after quote insert ");
2901 dump_text(text, line_pos, tlen, 1);
2909 line_pos = cur_pos + 1;
2910 line_len = cur_len + DISP_WIDTH(ch_len);
2912 /* advance to next character in buffer */
2913 cur_len += DISP_WIDTH(ch_len);
2917 gtk_stext_thaw(text);
2919 if (set_editable_pos && editable_pos <= tlen)
2920 gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
2926 static void compose_set_title(Compose *compose)
2931 edited = compose->modified ? _(" [Edited]") : "";
2932 if (compose->account && compose->account->address)
2933 str = g_strdup_printf(_("%s - Compose message%s"),
2934 compose->account->address, edited);
2936 str = g_strdup_printf(_("Compose message%s"), edited);
2937 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2942 * compose_current_mail_account:
2944 * Find a current mail account (the currently selected account, or the
2945 * default account, if a news account is currently selected). If a
2946 * mail account cannot be found, display an error message.
2948 * Return value: Mail account, or NULL if not found.
2950 static PrefsAccount *
2951 compose_current_mail_account(void)
2955 if (cur_account && cur_account->protocol != A_NNTP)
2958 ac = account_get_default();
2959 if (!ac || ac->protocol == A_NNTP) {
2960 alertpanel_error(_("Account for sending mail is not specified.\n"
2961 "Please select a mail account before sending."));
2968 static void compose_select_account(Compose *compose, PrefsAccount *account,
2971 GtkItemFactory *ifactory;
2973 g_return_if_fail(account != NULL);
2975 compose->account = account;
2977 compose_set_title(compose);
2979 ifactory = gtk_item_factory_from_widget(compose->menubar);
2981 if (account->protocol == A_NNTP) {
2982 gtk_widget_show(compose->newsgroups_hbox);
2983 gtk_widget_show(compose->newsgroups_entry);
2984 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2985 compose->use_newsgroups = TRUE;
2987 menu_set_active(ifactory, "/View/To", FALSE);
2988 menu_set_sensitive(ifactory, "/View/To", TRUE);
2989 menu_set_active(ifactory, "/View/Cc", FALSE);
2990 menu_set_sensitive(ifactory, "/View/Cc", TRUE);
2991 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
2993 gtk_widget_hide(compose->newsgroups_hbox);
2994 gtk_widget_hide(compose->newsgroups_entry);
2995 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
2996 gtk_widget_queue_resize(compose->table_vbox);
2997 compose->use_newsgroups = FALSE;
2999 menu_set_active(ifactory, "/View/To", TRUE);
3000 menu_set_sensitive(ifactory, "/View/To", FALSE);
3001 menu_set_active(ifactory, "/View/Cc", TRUE);
3002 menu_set_sensitive(ifactory, "/View/Cc", FALSE);
3003 menu_set_active(ifactory, "/View/Followup to", FALSE);
3004 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
3007 if (account->set_autocc) {
3008 compose_entry_show(compose, COMPOSE_ENTRY_CC);
3009 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
3010 compose_entry_set(compose, account->auto_cc,
3013 if (account->set_autobcc) {
3014 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
3015 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
3016 compose_entry_set(compose, account->auto_bcc,
3019 if (account->set_autoreplyto) {
3020 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
3021 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
3022 compose_entry_set(compose, account->auto_replyto,
3023 COMPOSE_ENTRY_REPLY_TO);
3028 if (account->default_sign)
3029 menu_set_active(ifactory, "/Options/Sign", TRUE);
3031 menu_set_active(ifactory, "/Options/Sign", FALSE);
3032 if (account->default_encrypt)
3033 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3035 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3037 activate_privacy_system(compose, account);
3039 if (!init && compose->mode != COMPOSE_REDIRECT)
3040 compose_insert_sig(compose, TRUE);
3043 gboolean compose_check_for_valid_recipient(Compose *compose) {
3044 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3045 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3046 gboolean recipient_found = FALSE;
3050 /* free to and newsgroup list */
3051 slist_free_strings(compose->to_list);
3052 g_slist_free(compose->to_list);
3053 compose->to_list = NULL;
3055 slist_free_strings(compose->newsgroup_list);
3056 g_slist_free(compose->newsgroup_list);
3057 compose->newsgroup_list = NULL;
3059 /* search header entries for to and newsgroup entries */
3060 for (list = compose->header_list; list; list = list->next) {
3063 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3064 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3066 if (entry[0] != '\0') {
3067 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3068 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3069 compose->to_list = address_list_append(compose->to_list, entry);
3070 recipient_found = TRUE;
3073 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3074 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3075 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3076 recipient_found = TRUE;
3083 return recipient_found;
3086 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3090 if (compose_check_for_valid_recipient(compose) == FALSE) {
3091 alertpanel_error(_("Recipient is not specified."));
3095 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3096 if (*str == '\0' && check_subject == TRUE) {
3099 aval = alertpanel(_("Send"),
3100 _("Subject is empty. Send it anyway?"),
3101 _("Yes"), _("No"), NULL);
3102 if (aval != G_ALERTDEFAULT)
3109 gint compose_send(Compose *compose)
3116 compose_allow_user_actions (compose, FALSE);
3117 compose->sending = TRUE;
3119 if (compose_check_entries(compose, TRUE) == FALSE)
3122 val = compose_queue(compose, &msgnum, &folder);
3125 alertpanel_error(_("Could not queue message for sending"));
3130 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3131 compose->sending = FALSE;
3132 gtk_widget_destroy(compose->window);
3133 /* No more compose access in the normal codepath
3134 * after this point! */
3138 alertpanel_error(_("The message was queued but could not be "
3139 "sent.\nUse \"Send queued messages\" from "
3140 "the main window to retry."));
3141 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3142 compose->sending = FALSE;
3143 compose_allow_user_actions (compose, TRUE);
3148 msgpath = folder_item_fetch_msg(folder, msgnum);
3149 val = procmsg_send_message_queue(msgpath);
3152 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3153 compose->sending = FALSE;
3154 compose_allow_user_actions (compose, TRUE);
3156 folder_item_remove_msg(folder, msgnum);
3157 folder_item_scan(folder);
3162 folder_item_remove_msg(folder, msgnum);
3163 folder_item_scan(folder);
3164 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3165 gtk_widget_destroy(compose->window);
3167 alertpanel_error(_("The message was queued but could not be "
3168 "sent.\nUse \"Send queued messages\" from "
3169 "the main window to retry."));
3170 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3171 compose_allow_user_actions (compose, TRUE);
3172 compose->sending = FALSE;
3180 compose_allow_user_actions (compose, TRUE);
3181 compose->sending = FALSE;
3186 static gboolean compose_use_attach(Compose *compose)
3188 return gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL;
3191 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3194 gchar buf[BUFFSIZE];
3196 gboolean first_to_address;
3197 gboolean first_cc_address;
3199 ComposeHeaderEntry *headerentry;
3200 gchar *headerentryname;
3204 debug_print("Writing redirect header\n");
3206 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3207 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3209 first_to_address = TRUE;
3210 first_cc_address = TRUE;
3211 for (list = compose->header_list; list; list = list->next) {
3212 headerentry = ((ComposeHeaderEntry *)list->data);
3213 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3215 if (g_strcasecmp(headerentryname, cc_hdr) == 0
3216 || g_strcasecmp(headerentryname, to_hdr) == 0) {
3217 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3218 Xstrdup_a(str, str, return -1);
3220 if (str[0] != '\0') {
3221 compose_convert_header
3222 (buf, sizeof(buf), str,
3223 strlen("Resent-To") + 2, TRUE);
3224 if (g_strcasecmp(headerentryname, to_hdr) == 0) {
3225 if (first_to_address) {
3226 fprintf(fp, "Resent-To: ");
3227 first_to_address = FALSE;
3232 if (g_strcasecmp(headerentryname, cc_hdr) == 0) {
3233 if (first_cc_address) {
3235 fprintf(fp, "Resent-Cc: ");
3236 first_cc_address = FALSE;
3242 fprintf(fp, "%s", buf);
3246 /* if (!first_address) { */
3253 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3255 gchar buf[BUFFSIZE];
3257 /* struct utsname utsbuf; */
3259 g_return_val_if_fail(fp != NULL, -1);
3260 g_return_val_if_fail(compose->account != NULL, -1);
3261 g_return_val_if_fail(compose->account->address != NULL, -1);
3264 get_rfc822_date(buf, sizeof(buf));
3265 fprintf(fp, "Resent-Date: %s\n", buf);
3268 if (compose->account->name && *compose->account->name) {
3269 compose_convert_header
3270 (buf, sizeof(buf), compose->account->name,
3271 strlen("From: "), TRUE);
3272 fprintf(fp, "Resent-From: %s <%s>\n",
3273 buf, compose->account->address);
3275 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3278 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3280 Xstrdup_a(str, str, return -1);
3283 compose_convert_header(buf, sizeof(buf), str,
3284 strlen("Subject: "), FALSE);
3285 fprintf(fp, "Subject: %s\n", buf);
3289 /* Resent-Message-ID */
3290 if (compose->account->gen_msgid) {
3291 generate_msgid(buf, sizeof(buf));
3292 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3293 compose->msgid = g_strdup(buf);
3296 compose_redirect_write_headers_from_headerlist(compose, fp);
3298 /* separator between header and body */
3304 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3308 gchar buf[BUFFSIZE];
3310 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3311 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3315 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3316 /* should filter returnpath, delivered-to */
3317 if (g_strncasecmp(buf, "Return-Path:",
3318 strlen("Return-Path:")) == 0 ||
3319 g_strncasecmp(buf, "Delivered-To:",
3320 strlen("Delivered-To:")) == 0 ||
3321 g_strncasecmp(buf, "Received:",
3322 strlen("Received:")) == 0 ||
3323 g_strncasecmp(buf, "Subject:",
3324 strlen("Subject:")) == 0 ||
3325 g_strncasecmp(buf, "X-UIDL:",
3326 strlen("X-UIDL:")) == 0)
3329 if (fputs(buf, fdest) == -1)
3332 if (!prefs_common.redirect_keep_from) {
3333 if (g_strncasecmp(buf, "From:",
3334 strlen("From:")) == 0) {
3335 fputs(" (by way of ", fdest);
3336 if (compose->account->name
3337 && *compose->account->name) {
3338 compose_convert_header
3340 compose->account->name,
3343 fprintf(fdest, "%s <%s>",
3345 compose->account->address);
3347 fprintf(fdest, "%s",
3348 compose->account->address);
3353 if (fputs("\n", fdest) == -1)
3357 compose_redirect_write_headers(compose, fdest);
3359 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3360 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
3373 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
3377 const gchar *out_codeset;
3378 EncodingType encoding;
3379 MimeInfo *mimemsg, *mimetext;
3381 /* create message MimeInfo */
3382 mimemsg = procmime_mimeinfo_new();
3383 mimemsg->type = MIMETYPE_MESSAGE;
3384 mimemsg->subtype = g_strdup("rfc822");
3385 mimemsg->content = MIMECONTENT_MEM;
3386 mimemsg->data.mem = compose_get_header(compose);
3388 /* Create text part MimeInfo */
3389 /* get all composed text */
3390 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3391 if (is_ascii_str(chars)) {
3394 out_codeset = CS_US_ASCII;
3395 encoding = ENC_7BIT;
3397 const gchar *src_codeset;
3399 out_codeset = conv_get_outgoing_charset_str();
3400 if (!g_strcasecmp(out_codeset, CS_US_ASCII))
3401 out_codeset = CS_ISO_8859_1;
3403 if (prefs_common.encoding_method == CTE_BASE64)
3404 encoding = ENC_BASE64;
3405 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3406 encoding = ENC_QUOTED_PRINTABLE;
3407 else if (prefs_common.encoding_method == CTE_8BIT)
3408 encoding = ENC_8BIT;
3410 encoding = procmime_get_encoding_for_charset(out_codeset);
3412 src_codeset = conv_get_current_charset_str();
3413 /* if current encoding is US-ASCII, set it the same as
3414 outgoing one to prevent code conversion failure */
3415 if (!g_strcasecmp(src_codeset, CS_US_ASCII))
3416 src_codeset = out_codeset;
3418 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3419 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3421 if (action == COMPOSE_WRITE_FOR_SEND) {
3422 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3427 msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
3429 "Send it anyway?"), src_codeset, out_codeset);
3430 aval = alertpanel_with_type
3431 (_("Error"), msg, _("Yes"), _("+No"), NULL, NULL, ALERT_ERROR);
3434 if (aval != G_ALERTDEFAULT) {
3439 out_codeset = src_codeset;
3445 out_codeset = src_codeset;
3451 mimetext = procmime_mimeinfo_new();
3452 mimetext->content = MIMECONTENT_MEM;
3453 mimetext->data.mem = buf;
3454 mimetext->type = MIMETYPE_TEXT;
3455 mimetext->subtype = g_strdup("plain");
3456 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
3457 g_strdup(out_codeset));
3458 if (encoding != ENC_UNKNOWN)
3459 procmime_encode_content(mimetext, encoding);
3461 /* append attachment parts */
3462 if (compose_use_attach(compose)) {
3463 MimeInfo *mimempart;
3465 mimempart = procmime_mimeinfo_new();
3466 mimempart->content = MIMECONTENT_EMPTY;
3467 mimempart->type = MIMETYPE_MULTIPART;
3468 mimempart->subtype = g_strdup("mixed");
3469 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
3470 generate_mime_boundary(NULL));
3472 mimetext->disposition = DISPOSITIONTYPE_INLINE;
3474 g_node_append(mimempart->node, mimetext->node);
3475 g_node_append(mimemsg->node, mimempart->node);
3477 compose_add_attachments(compose, mimempart);
3479 g_node_append(mimemsg->node, mimetext->node);
3481 /* sign message if sending */
3482 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
3483 privacy_system_can_sign(compose->privacy_system))
3484 if (!privacy_sign(compose->privacy_system, mimemsg, compose->account))
3487 procmime_write_mimeinfo(mimemsg, fp);
3492 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3498 if ((fp = fopen(file, "wb")) == NULL) {
3499 FILE_OP_ERROR(file, "fopen");
3503 /* chmod for security */
3504 if (change_file_mode_rw(fp, file) < 0) {
3505 FILE_OP_ERROR(file, "chmod");
3506 g_warning("can't change file mode\n");
3509 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3512 len = strlen(chars);
3513 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3514 FILE_OP_ERROR(file, "fwrite");
3523 if (fclose(fp) == EOF) {
3524 FILE_OP_ERROR(file, "fclose");
3531 static gint compose_remove_reedit_target(Compose *compose)
3534 MsgInfo *msginfo = compose->targetinfo;
3536 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3537 if (!msginfo) return -1;
3539 item = msginfo->folder;
3540 g_return_val_if_fail(item != NULL, -1);
3542 if (procmsg_msg_exist(msginfo) &&
3543 (item->stype == F_DRAFT || item->stype == F_QUEUE
3544 || msginfo == compose->autosaved_draft)) {
3545 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3546 g_warning("can't remove the old message\n");
3554 void compose_remove_draft(Compose *compose)
3557 MsgInfo *msginfo = compose->targetinfo;
3558 drafts = account_get_special_folder(compose->account, F_DRAFT);
3560 if (procmsg_msg_exist(msginfo)) {
3561 folder_item_remove_msg(drafts, msginfo->msgnum);
3566 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3568 return compose_queue_sub (compose, msgnum, item, FALSE);
3570 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3577 static gboolean lock = FALSE;
3578 PrefsAccount *mailac = NULL, *newsac = NULL;
3580 debug_print("queueing message...\n");
3581 g_return_val_if_fail(compose->account != NULL, -1);
3585 if (compose_check_entries(compose, check_subject) == FALSE) {
3590 if (!compose->to_list && !compose->newsgroup_list) {
3591 g_warning("can't get recipient list.");
3596 if (compose->to_list) {
3597 if (compose->account->protocol != A_NNTP)
3598 mailac = compose->account;
3599 else if (cur_account && cur_account->protocol != A_NNTP)
3600 mailac = cur_account;
3601 else if (!(mailac = compose_current_mail_account())) {
3603 alertpanel_error(_("No account for sending mails available!"));
3608 if (compose->newsgroup_list) {
3609 if (compose->account->protocol == A_NNTP)
3610 newsac = compose->account;
3611 else if (!newsac->protocol != A_NNTP) {
3613 alertpanel_error(_("No account for posting news available!"));
3618 if (prefs_common.linewrap_at_send)
3619 compose_wrap_line_all(compose);
3621 /* write queue header */
3622 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
3623 G_DIR_SEPARATOR, compose);
3624 if ((fp = fopen(tmp, "wb")) == NULL) {
3625 FILE_OP_ERROR(tmp, "fopen");
3630 if (change_file_mode_rw(fp, tmp) < 0) {
3631 FILE_OP_ERROR(tmp, "chmod");
3632 g_warning("can't change file mode\n");
3635 /* queueing variables */
3636 fprintf(fp, "AF:\n");
3637 fprintf(fp, "NF:0\n");
3638 fprintf(fp, "PS:10\n");
3639 fprintf(fp, "SRH:1\n");
3640 fprintf(fp, "SFN:\n");
3641 fprintf(fp, "DSR:\n");
3643 fprintf(fp, "MID:<%s>\n", compose->msgid);
3645 fprintf(fp, "MID:\n");
3646 fprintf(fp, "CFG:\n");
3647 fprintf(fp, "PT:0\n");
3648 fprintf(fp, "S:%s\n", compose->account->address);
3649 fprintf(fp, "RQ:\n");
3651 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3653 fprintf(fp, "SSV:\n");
3655 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3657 fprintf(fp, "NSV:\n");
3658 fprintf(fp, "SSH:\n");
3659 /* write recepient list */
3660 if (compose->to_list) {
3661 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
3662 for (cur = compose->to_list->next; cur != NULL;
3664 fprintf(fp, ",<%s>", (gchar *)cur->data);
3667 /* write newsgroup list */
3668 if (compose->newsgroup_list) {
3670 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3671 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3672 fprintf(fp, ",%s", (gchar *)cur->data);
3675 /* Sylpheed account IDs */
3677 fprintf(fp, "MAID:%d\n", mailac->account_id);
3679 fprintf(fp, "NAID:%d\n", newsac->account_id);
3681 if (compose->privacy_system != NULL) {
3682 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
3683 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
3684 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
3685 if (compose->use_encryption) {
3688 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
3689 if (encdata != NULL)
3690 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n",
3696 /* Save copy folder */
3697 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3698 gchar *savefolderid;
3700 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3701 fprintf(fp, "SCF:%s\n", savefolderid);
3702 g_free(savefolderid);
3704 /* Message-ID of message replying to */
3705 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
3708 folderid = folder_item_get_identifier(compose->replyinfo->folder);
3709 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
3712 /* Message-ID of message forwarding to */
3713 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
3716 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
3717 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
3722 if (compose->redirect_filename != NULL) {
3723 if (compose_redirect_write_to_file(compose, fp) < 0) {
3731 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND) < 0) {
3740 if (fclose(fp) == EOF) {
3741 FILE_OP_ERROR(tmp, "fclose");
3747 queue = account_get_special_folder(compose->account, F_QUEUE);
3749 g_warning("can't find queue folder\n");
3754 folder_item_scan(queue);
3755 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
3756 g_warning("can't queue the message\n");
3764 if (compose->mode == COMPOSE_REEDIT) {
3765 compose_remove_reedit_target(compose);
3768 if ((msgnum != NULL) && (item != NULL)) {
3776 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
3779 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3782 struct stat statbuf;
3783 gchar *type, *subtype;
3785 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3787 mimepart = procmime_mimeinfo_new();
3788 mimepart->content = MIMECONTENT_FILE;
3789 mimepart->data.filename = g_strdup(ainfo->file);
3790 mimepart->offset = 0;
3792 stat(ainfo->file, &statbuf);
3793 mimepart->length = statbuf.st_size;
3795 type = g_strdup(ainfo->content_type);
3797 if (!strchr(type, '/')) {
3799 type = g_strdup("application/octet-stream");
3802 subtype = strchr(type, '/') + 1;
3803 *(subtype - 1) = '\0';
3804 mimepart->type = procmime_get_media_type(type);
3805 mimepart->subtype = g_strdup(subtype);
3808 if (mimepart->type == MIMETYPE_MESSAGE &&
3809 !g_strcasecmp(mimepart->subtype, "rfc822")) {
3810 mimepart->disposition = DISPOSITIONTYPE_INLINE;
3812 g_hash_table_insert(mimepart->typeparameters,
3813 g_strdup("name"), g_strdup(ainfo->name));
3814 g_hash_table_insert(mimepart->dispositionparameters,
3815 g_strdup("filename"), g_strdup(ainfo->name));
3816 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
3819 procmime_encode_content(mimepart, ainfo->encoding);
3821 g_node_append(parent->node, mimepart->node);
3825 #define QUOTE_IF_REQUIRED(out, str) \
3827 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3831 len = strlen(str) + 3; \
3832 if ((__tmp = alloca(len)) == NULL) { \
3833 g_warning("can't allocate memory\n"); \
3834 g_string_free(header, TRUE); \
3837 g_snprintf(__tmp, len, "\"%s\"", str); \
3842 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3843 g_warning("can't allocate memory\n"); \
3844 g_string_free(header, TRUE); \
3847 strcpy(__tmp, str); \
3853 #define IS_IN_CUSTOM_HEADER(header) \
3854 (compose->account->add_customhdr && \
3855 custom_header_find(compose->account->customhdr_list, header) != NULL)
3857 static void compose_add_headerfield_from_headerlist(Compose *compose,
3859 const gchar *fieldname,
3860 const gchar *seperator)
3862 gchar *str, *fieldname_w_colon, *trans_fieldname;
3863 gboolean add_field = FALSE;
3865 ComposeHeaderEntry *headerentry;
3866 gchar * headerentryname;
3869 if (IS_IN_CUSTOM_HEADER(fieldname))
3872 debug_print("Adding %s-fields\n", fieldname);
3874 fieldstr = g_string_sized_new(64);
3876 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
3877 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
3879 for (list = compose->header_list; list; list = list->next) {
3880 headerentry = ((ComposeHeaderEntry *)list->data);
3881 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3883 if (!g_strcasecmp(trans_fieldname, headerentryname)) {
3884 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
3886 if (str[0] != '\0') {
3888 g_string_append(fieldstr, seperator);
3889 g_string_append(fieldstr, str);
3898 buf = g_new0(gchar, fieldstr->len * 4 + 256);
3899 compose_convert_header
3900 (buf, fieldstr->len * 4 + 256, fieldstr->str,
3901 strlen(fieldname) + 2, TRUE);
3902 g_string_sprintfa(header, "%s: %s\n", fieldname, buf);
3906 g_free(fieldname_w_colon);
3907 g_string_free(fieldstr, TRUE);
3912 static gchar *compose_get_header(Compose *compose)
3914 gchar buf[BUFFSIZE];
3918 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3921 /* struct utsname utsbuf; */
3923 g_return_val_if_fail(compose->account != NULL, NULL);
3924 g_return_val_if_fail(compose->account->address != NULL, NULL);
3926 header = g_string_sized_new(64);
3929 if (compose->account->add_date) {
3930 get_rfc822_date(buf, sizeof(buf));
3931 g_string_sprintfa(header, "Date: %s\n", buf);
3935 if (compose->account->name && *compose->account->name) {
3936 compose_convert_header
3937 (buf, sizeof(buf), compose->account->name,
3938 strlen("From: "), TRUE);
3939 QUOTE_IF_REQUIRED(name, buf);
3940 g_string_sprintfa(header, "From: %s <%s>\n",
3941 name, compose->account->address);
3943 g_string_sprintfa(header, "From: %s\n", compose->account->address);
3946 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
3949 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
3952 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
3955 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
3958 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3959 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3962 tmpstr = g_strdup(str);
3963 if (tmpstr == NULL) {
3964 g_string_free(header, TRUE);
3969 compose_convert_header(buf, sizeof(buf), str,
3970 strlen("Subject: "), FALSE);
3971 g_string_sprintfa(header, "Subject: %s\n", buf);
3977 if (compose->account->gen_msgid) {
3978 generate_msgid(buf, sizeof(buf));
3979 g_string_sprintfa(header, "Message-ID: <%s>\n", buf);
3980 compose->msgid = g_strdup(buf);
3983 if (compose->remove_references == FALSE) {
3985 if (compose->inreplyto && compose->to_list)
3986 g_string_sprintfa(header, "In-Reply-To: <%s>\n", compose->inreplyto);
3989 if (compose->references)
3990 g_string_sprintfa(header, "References: %s\n", compose->references);
3994 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
3997 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
4000 if (compose->account->organization &&
4001 !IS_IN_CUSTOM_HEADER("Organization")) {
4002 compose_convert_header(buf, sizeof(buf),
4003 compose->account->organization,
4004 strlen("Organization: "), FALSE);
4005 g_string_sprintfa(header, "Organization: %s\n", buf);
4008 /* Program version and system info */
4009 /* uname(&utsbuf); */
4010 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4011 !compose->newsgroup_list) {
4012 g_string_sprintfa(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4014 gtk_major_version, gtk_minor_version, gtk_micro_version,
4016 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4018 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4019 g_string_sprintfa(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4021 gtk_major_version, gtk_minor_version, gtk_micro_version,
4023 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4026 /* custom headers */
4027 if (compose->account->add_customhdr) {
4030 for (cur = compose->account->customhdr_list; cur != NULL;
4032 CustomHeader *chdr = (CustomHeader *)cur->data;
4034 if (custom_header_is_allowed(chdr->name)) {
4035 compose_convert_header
4037 chdr->value ? chdr->value : "",
4038 strlen(chdr->name) + 2, FALSE);
4039 g_string_sprintfa(header, "%s: %s\n", chdr->name, buf);
4045 switch (compose->priority) {
4046 case PRIORITY_HIGHEST: g_string_sprintfa(header, "Importance: high\n"
4047 "X-Priority: 1 (Highest)\n");
4049 case PRIORITY_HIGH: g_string_sprintfa(header, "Importance: high\n"
4050 "X-Priority: 2 (High)\n");
4052 case PRIORITY_NORMAL: break;
4053 case PRIORITY_LOW: g_string_sprintfa(header, "Importance: low\n"
4054 "X-Priority: 4 (Low)\n");
4056 case PRIORITY_LOWEST: g_string_sprintfa(header, "Importance: low\n"
4057 "X-Priority: 5 (Lowest)\n");
4059 default: debug_print("compose: priority unknown : %d\n",
4063 /* Request Return Receipt */
4064 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4065 if (compose->return_receipt) {
4066 if (compose->account->name
4067 && *compose->account->name) {
4068 compose_convert_header(buf, sizeof(buf),
4069 compose->account->name,
4070 strlen("Disposition-Notification-To: "),
4072 g_string_sprintfa(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4074 g_string_sprintfa(header, "Disposition-Notification-To: %s\n", compose->account->address);
4078 /* get special headers */
4079 for (list = compose->header_list; list; list = list->next) {
4080 ComposeHeaderEntry *headerentry;
4083 gchar *headername_wcolon;
4084 gchar *headername_trans;
4087 gboolean standard_header = FALSE;
4089 headerentry = ((ComposeHeaderEntry *)list->data);
4091 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4092 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4097 if (!strstr(tmp, ":")) {
4098 headername_wcolon = g_strconcat(tmp, ":", NULL);
4099 headername = g_strdup(tmp);
4101 headername_wcolon = g_strdup(tmp);
4102 headername = g_strdup(strtok(tmp, ":"));
4106 headervalue = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4107 subst_char(headervalue, '\r', ' ');
4108 subst_char(headervalue, '\n', ' ');
4109 string = std_headers;
4110 while (*string != NULL) {
4111 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4112 if (!strcmp(headername_trans,headername_wcolon))
4113 standard_header = TRUE;
4116 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4117 g_string_sprintfa(header, "%s %s\n", headername_wcolon, headervalue);
4120 g_free(headername_wcolon);
4124 g_string_free(header, FALSE);
4129 #undef IS_IN_CUSTOM_HEADER
4131 static void compose_convert_header(gchar *dest, gint len, gchar *src,
4132 gint header_len, gboolean addr_field)
4134 g_return_if_fail(src != NULL);
4135 g_return_if_fail(dest != NULL);
4137 if (len < 1) return;
4139 subst_char(src, '\n', ' ');
4140 subst_char(src, '\r', ' ');
4143 conv_encode_header(dest, len, src, header_len, addr_field);
4146 static void compose_create_header_entry(Compose *compose)
4148 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4152 GList *combo_list = NULL;
4153 gchar **string, *header = NULL;
4154 ComposeHeaderEntry *headerentry;
4155 gboolean standard_header = FALSE;
4157 headerentry = g_new0(ComposeHeaderEntry, 1);
4160 combo = gtk_combo_new();
4162 while(*string != NULL) {
4163 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4166 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4167 g_list_free(combo_list);
4168 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4169 gtk_widget_show(combo);
4170 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4171 if (compose->header_last) {
4172 gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4174 while (*string != NULL) {
4175 if (!strcmp(*string, last_header_entry))
4176 standard_header = TRUE;
4179 if (standard_header)
4180 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4182 if (!compose->header_last || !standard_header) {
4183 switch(compose->account->protocol) {
4185 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4188 header = prefs_common.trans_hdr ? _("To:") : "To:";
4193 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4196 entry = gtk_entry_new();
4197 gtk_widget_show(entry);
4198 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);
4200 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4201 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4202 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4203 gtk_signal_connect(GTK_OBJECT(entry), "button-press-event",
4204 GTK_SIGNAL_FUNC(compose_headerentry_button_pressed),
4207 address_completion_register_entry(GTK_ENTRY(entry));
4209 headerentry->compose = compose;
4210 headerentry->combo = combo;
4211 headerentry->entry = entry;
4212 headerentry->headernum = compose->header_nextrow;
4214 compose->header_nextrow++;
4215 compose->header_last = headerentry;
4218 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4220 ComposeHeaderEntry *last_header;
4222 last_header = compose->header_last;
4224 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4225 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4228 static GtkWidget *compose_create_header(Compose *compose)
4232 GtkWidget *from_optmenu_hbox;
4233 #if 0 /* NEW COMPOSE GUI */
4234 GtkWidget *to_entry;
4236 GtkWidget *newsgroups_entry;
4237 GtkWidget *newsgroups_hbox;
4239 GtkWidget *header_scrolledwin;
4240 GtkWidget *header_table;
4241 #if 0 /* NEW COMPOSE GUI */
4242 GtkWidget *cc_entry;
4244 GtkWidget *bcc_entry;
4245 GtkWidget *bcc_hbox;
4246 GtkWidget *reply_entry;
4247 GtkWidget *reply_hbox;
4248 GtkWidget *followup_entry;
4249 GtkWidget *followup_hbox;
4254 /* header labels and entries */
4255 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4256 gtk_widget_show(header_scrolledwin);
4257 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4259 header_table = gtk_table_new(2, 2, FALSE);
4260 gtk_widget_show(header_table);
4261 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4262 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4263 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4266 /* option menu for selecting accounts */
4267 hbox = gtk_hbox_new(FALSE, 0);
4268 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4269 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4270 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4272 from_optmenu_hbox = compose_account_option_menu_create(compose);
4273 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4274 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4275 #if 0 /* NEW COMPOSE GUI */
4276 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4280 compose->header_table = header_table;
4281 compose->header_list = NULL;
4282 compose->header_nextrow = count;
4284 compose_create_header_entry(compose);
4286 #if 0 /* NEW COMPOSE GUI */
4287 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4289 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4290 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4291 &count, "Newsgroups:", FALSE);
4292 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4294 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4296 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4298 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4299 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4301 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4302 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4304 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4305 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4306 "Followup-To:", FALSE);
4307 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4309 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4311 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4312 GTK_SIGNAL_FUNC(to_activated), compose);
4313 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4314 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4315 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4316 GTK_SIGNAL_FUNC(subject_activated), compose);
4317 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4318 GTK_SIGNAL_FUNC(cc_activated), compose);
4319 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4320 GTK_SIGNAL_FUNC(bcc_activated), compose);
4321 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4322 GTK_SIGNAL_FUNC(replyto_activated), compose);
4323 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4324 GTK_SIGNAL_FUNC(followupto_activated), compose);
4326 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4327 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4328 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4329 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4330 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4331 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4332 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4333 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4334 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4335 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4336 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4337 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4338 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4339 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4342 compose->table = NULL;
4343 #if 0 /* NEW COMPOSE GUI */
4344 compose->table = table;
4345 compose->to_hbox = to_hbox;
4346 compose->to_entry = to_entry;
4347 compose->newsgroups_hbox = newsgroups_hbox;
4348 compose->newsgroups_entry = newsgroups_entry;
4350 #if 0 /* NEW COMPOSE GUI */
4351 compose->cc_hbox = cc_hbox;
4352 compose->cc_entry = cc_entry;
4353 compose->bcc_hbox = bcc_hbox;
4354 compose->bcc_entry = bcc_entry;
4355 compose->reply_hbox = reply_hbox;
4356 compose->reply_entry = reply_entry;
4357 compose->followup_hbox = followup_hbox;
4358 compose->followup_entry = followup_entry;
4361 return header_scrolledwin ;
4364 GtkWidget *compose_create_attach(Compose *compose)
4366 gchar *titles[N_ATTACH_COLS];
4369 GtkWidget *attach_scrwin;
4370 GtkWidget *attach_clist;
4372 titles[COL_MIMETYPE] = _("MIME type");
4373 titles[COL_SIZE] = _("Size");
4374 titles[COL_NAME] = _("Name");
4376 /* attachment list */
4377 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4378 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4379 GTK_POLICY_AUTOMATIC,
4381 gtk_widget_set_usize(attach_scrwin, -1, 80);
4383 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4384 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4386 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4387 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4388 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4389 GTK_SELECTION_EXTENDED);
4390 for (i = 0; i < N_ATTACH_COLS; i++)
4391 GTK_WIDGET_UNSET_FLAGS
4392 (GTK_CLIST(attach_clist)->column[i].button,
4394 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4396 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4397 GTK_SIGNAL_FUNC(attach_selected), compose);
4398 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4399 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4400 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4401 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4404 gtk_drag_dest_set(attach_clist,
4405 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4406 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4407 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4408 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4411 compose->attach_scrwin = attach_scrwin;
4412 compose->attach_clist = attach_clist;
4414 return attach_scrwin;
4417 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4418 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4420 static GtkWidget *compose_create_others(Compose *compose)
4423 GtkWidget *savemsg_checkbtn;
4424 GtkWidget *savemsg_entry;
4425 GtkWidget *savemsg_select;
4428 gchar *folderidentifier;
4430 /* Table for settings */
4431 table = gtk_table_new(3, 1, FALSE);
4432 gtk_widget_show(table);
4433 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4436 /* Save Message to folder */
4437 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4438 gtk_widget_show(savemsg_checkbtn);
4439 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4440 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4441 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4443 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4444 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4446 savemsg_entry = gtk_entry_new();
4447 gtk_widget_show(savemsg_entry);
4448 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4449 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4450 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4451 folderidentifier = folder_item_get_identifier(account_get_special_folder
4452 (compose->account, F_OUTBOX));
4453 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4454 g_free(folderidentifier);
4457 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4458 gtk_widget_show (savemsg_select);
4459 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4460 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4461 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4466 compose->savemsg_checkbtn = savemsg_checkbtn;
4467 compose->savemsg_entry = savemsg_entry;
4472 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4474 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4475 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4478 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4483 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4486 path = folder_item_get_identifier(dest);
4488 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4492 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4498 GtkWidget *handlebox;
4500 GtkWidget *notebook;
4505 GtkWidget *subject_hbox;
4506 GtkWidget *subject_frame;
4507 GtkWidget *subject_entry;
4511 GtkWidget *edit_vbox;
4512 GtkWidget *ruler_hbox;
4514 GtkWidget *scrolledwin;
4517 UndoMain *undostruct;
4519 gchar *titles[N_ATTACH_COLS];
4520 guint n_menu_entries;
4521 GtkStyle *style, *new_style;
4524 gboolean success[1];
4525 GtkWidget *popupmenu;
4526 GtkItemFactory *popupfactory;
4527 GtkItemFactory *ifactory;
4528 GtkWidget *tmpl_menu;
4532 GtkAspell * gtkaspell = NULL;
4535 static GdkGeometry geometry;
4537 g_return_val_if_fail(account != NULL, NULL);
4539 debug_print("Creating compose window...\n");
4540 compose = g_new0(Compose, 1);
4542 titles[COL_MIMETYPE] = _("MIME type");
4543 titles[COL_SIZE] = _("Size");
4544 titles[COL_NAME] = _("Name");
4546 compose->account = account;
4548 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4549 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4550 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4551 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4553 if (!geometry.max_width) {
4554 geometry.max_width = gdk_screen_width();
4555 geometry.max_height = gdk_screen_height();
4557 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4558 &geometry, GDK_HINT_MAX_SIZE);
4559 gtk_widget_set_uposition(window, prefs_common.compose_x,
4560 prefs_common.compose_y);
4561 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4562 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4563 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4564 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4565 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4566 gtk_widget_realize(window);
4568 gtkut_widget_set_composer_icon(window);
4570 vbox = gtk_vbox_new(FALSE, 0);
4571 gtk_container_add(GTK_CONTAINER(window), vbox);
4573 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4574 menubar = menubar_create(window, compose_entries,
4575 n_menu_entries, "<Compose>", compose);
4576 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4578 handlebox = gtk_handle_box_new();
4579 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4581 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
4584 vbox2 = gtk_vbox_new(FALSE, 2);
4585 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4586 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4589 notebook = gtk_notebook_new();
4590 gtk_widget_set_usize(notebook, -1, 130);
4591 gtk_widget_show(notebook);
4593 /* header labels and entries */
4594 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4595 /* attachment list */
4596 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4598 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4601 subject_hbox = gtk_hbox_new(FALSE, 0);
4602 gtk_widget_show(subject_hbox);
4604 subject_frame = gtk_frame_new(NULL);
4605 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4606 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4607 gtk_widget_show(subject_frame);
4609 subject = gtk_hbox_new(FALSE, 0);
4610 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4611 gtk_widget_show(subject);
4613 label = gtk_label_new(_("Subject:"));
4614 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4615 gtk_widget_show(label);
4617 subject_entry = gtk_entry_new();
4618 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4619 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4620 gtk_widget_show(subject_entry);
4621 compose->subject_entry = subject_entry;
4622 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4624 edit_vbox = gtk_vbox_new(FALSE, 0);
4626 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4629 ruler_hbox = gtk_hbox_new(FALSE, 0);
4630 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4632 ruler = gtk_shruler_new();
4633 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4634 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4636 gtk_widget_set_usize(ruler_hbox, 1, -1);
4639 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4640 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4641 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4642 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4643 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4645 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4646 (GTK_SCROLLED_WINDOW(scrolledwin)),
4647 gtk_scrolled_window_get_vadjustment
4648 (GTK_SCROLLED_WINDOW(scrolledwin)));
4649 GTK_STEXT(text)->default_tab_width = 8;
4650 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4652 if (prefs_common.block_cursor) {
4653 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4656 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4658 gtk_signal_connect(GTK_OBJECT(text), "changed",
4659 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4660 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4661 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4662 gtk_signal_connect(GTK_OBJECT(text), "activate",
4663 GTK_SIGNAL_FUNC(text_activated), compose);
4664 gtk_signal_connect(GTK_OBJECT(text), "insert_text",
4665 GTK_SIGNAL_FUNC(text_inserted), compose);
4666 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4667 GTK_SIGNAL_FUNC(compose_button_press_cb),
4670 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4671 GTK_SIGNAL_FUNC(compose_key_press_cb),
4674 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4675 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4679 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4680 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4681 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4682 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4684 gtk_widget_show_all(vbox);
4686 /* pane between attach clist and text */
4687 paned = gtk_vpaned_new();
4688 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4689 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4690 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4691 gtk_paned_add1(GTK_PANED(paned), notebook);
4692 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4693 gtk_widget_show_all(paned);
4695 style = gtk_widget_get_style(text);
4697 /* workaround for the slow down of GtkSText when using Pixmap theme */
4698 if (style->engine) {
4699 GtkThemeEngine *engine;
4701 engine = style->engine;
4702 style->engine = NULL;
4703 new_style = gtk_style_copy(style);
4704 style->engine = engine;
4706 new_style = gtk_style_copy(style);
4708 if (prefs_common.textfont) {
4711 if ((font = gtkut_font_load(prefs_common.textfont)) != NULL) {
4712 gdk_font_unref(new_style->font);
4713 new_style->font = font;
4717 gtk_widget_set_style(text, new_style);
4719 color[0] = quote_color;
4720 cmap = gdk_window_get_colormap(window->window);
4721 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4722 if (success[0] == FALSE) {
4723 g_warning("Compose: color allocation failed.\n");
4724 style = gtk_widget_get_style(text);
4725 quote_color = style->black;
4728 n_entries = sizeof(compose_popup_entries) /
4729 sizeof(compose_popup_entries[0]);
4730 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4731 "<Compose>", &popupfactory,
4734 ifactory = gtk_item_factory_from_widget(menubar);
4735 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4736 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4737 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
4739 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4741 undostruct = undo_init(text);
4742 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4745 address_completion_start(window);
4747 compose->window = window;
4748 compose->vbox = vbox;
4749 compose->menubar = menubar;
4750 compose->handlebox = handlebox;
4752 compose->vbox2 = vbox2;
4754 compose->paned = paned;
4756 compose->edit_vbox = edit_vbox;
4757 compose->ruler_hbox = ruler_hbox;
4758 compose->ruler = ruler;
4759 compose->scrolledwin = scrolledwin;
4760 compose->text = text;
4762 compose->focused_editable = NULL;
4764 compose->popupmenu = popupmenu;
4765 compose->popupfactory = popupfactory;
4767 compose->tmpl_menu = tmpl_menu;
4769 compose->mode = mode;
4771 compose->targetinfo = NULL;
4772 compose->replyinfo = NULL;
4773 compose->fwdinfo = NULL;
4775 compose->replyto = NULL;
4777 compose->bcc = NULL;
4778 compose->followup_to = NULL;
4780 compose->ml_post = NULL;
4782 compose->inreplyto = NULL;
4783 compose->references = NULL;
4784 compose->msgid = NULL;
4785 compose->boundary = NULL;
4787 compose->autowrap = prefs_common.autowrap;
4789 compose->use_signing = FALSE;
4790 compose->use_encryption = FALSE;
4791 compose->privacy_system = NULL;
4793 compose->modified = FALSE;
4795 compose->return_receipt = FALSE;
4797 compose->to_list = NULL;
4798 compose->newsgroup_list = NULL;
4800 compose->undostruct = undostruct;
4802 compose->sig_str = NULL;
4804 compose->exteditor_file = NULL;
4805 compose->exteditor_pid = -1;
4806 compose->exteditor_readdes = -1;
4807 compose->exteditor_tag = -1;
4808 compose->draft_timeout_tag = -1;
4811 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4812 if (mode != COMPOSE_REDIRECT) {
4813 if (prefs_common.enable_aspell && prefs_common.dictionary &&
4814 strcmp(prefs_common.dictionary, _("None"))) {
4815 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
4816 prefs_common.dictionary,
4817 conv_get_current_charset_str(),
4818 prefs_common.misspelled_col,
4819 prefs_common.check_while_typing,
4820 prefs_common.use_alternate,
4823 alertpanel_error(_("Spell checker could not "
4825 gtkaspell_checkers_strerror());
4826 gtkaspell_checkers_reset_error();
4829 GtkWidget *menuitem;
4831 if (!gtkaspell_set_sug_mode(gtkaspell,
4832 prefs_common.aspell_sugmode)) {
4833 debug_print("Aspell: could not set "
4834 "suggestion mode %s\n",
4835 gtkaspell_checkers_strerror());
4836 gtkaspell_checkers_reset_error();
4839 menuitem = gtk_item_factory_get_item(ifactory,
4840 "/Spelling/Spelling Configuration");
4841 gtkaspell_populate_submenu(gtkaspell, menuitem);
4842 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4846 compose->gtkaspell = gtkaspell;
4849 compose_select_account(compose, account, TRUE);
4851 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
4852 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
4853 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4855 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
4856 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4858 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
4859 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4862 if (account->protocol != A_NNTP)
4863 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4865 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4867 addressbook_set_target_compose(compose);
4869 if (mode != COMPOSE_REDIRECT)
4870 compose_set_template_menu(compose);
4872 GtkWidget *menuitem;
4873 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4874 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
4877 compose_list = g_list_append(compose_list, compose);
4879 if (!prefs_common.show_ruler)
4880 gtk_widget_hide(ruler_hbox);
4883 compose->priority = PRIORITY_NORMAL;
4884 compose_update_priority_menu_item(compose);
4887 compose_update_actions_menu(compose);
4889 /* Privacy Systems menu */
4890 compose_update_privacy_systems_menu(compose);
4892 activate_privacy_system(compose, account);
4893 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
4894 gtk_widget_show(window);
4899 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4905 gint num = 0, def_menu = 0;
4907 accounts = account_get_list();
4908 g_return_val_if_fail(accounts != NULL, NULL);
4910 hbox = gtk_hbox_new(FALSE, 0);
4911 optmenu = gtk_option_menu_new();
4912 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4913 menu = gtk_menu_new();
4915 for (; accounts != NULL; accounts = accounts->next, num++) {
4916 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4917 GtkWidget *menuitem;
4920 if (ac == compose->account) def_menu = num;
4923 name = g_strdup_printf("%s: %s <%s>",
4925 ac->name, ac->address);
4927 name = g_strdup_printf("%s: %s",
4928 ac->account_name, ac->address);
4929 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
4931 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4932 GTK_SIGNAL_FUNC(account_activated),
4936 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4937 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4942 static void compose_set_priority_cb(gpointer data,
4946 Compose *compose = (Compose *) data;
4947 compose->priority = action;
4950 static void compose_update_priority_menu_item(Compose * compose)
4952 GtkItemFactory *ifactory;
4953 GtkWidget *menuitem = NULL;
4955 ifactory = gtk_item_factory_from_widget(compose->menubar);
4957 switch (compose->priority) {
4958 case PRIORITY_HIGHEST:
4959 menuitem = gtk_item_factory_get_item
4960 (ifactory, "/Options/Priority/Highest");
4963 menuitem = gtk_item_factory_get_item
4964 (ifactory, "/Options/Priority/High");
4966 case PRIORITY_NORMAL:
4967 menuitem = gtk_item_factory_get_item
4968 (ifactory, "/Options/Priority/Normal");
4971 menuitem = gtk_item_factory_get_item
4972 (ifactory, "/Options/Priority/Low");
4974 case PRIORITY_LOWEST:
4975 menuitem = gtk_item_factory_get_item
4976 (ifactory, "/Options/Priority/Lowest");
4979 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4982 static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
4984 Compose *compose = (Compose *) data;
4986 GtkItemFactory *ifactory;
4987 gboolean can_sign = FALSE, can_encrypt = FALSE;
4989 g_return_if_fail(GTK_IS_CHECK_MENU_ITEM(widget));
4991 if (!GTK_CHECK_MENU_ITEM(widget)->active)
4994 systemid = gtk_object_get_data(GTK_OBJECT(widget), "privacy_system");
4995 g_free(compose->privacy_system);
4996 compose->privacy_system = NULL;
4997 if (systemid != NULL) {
4998 compose->privacy_system = g_strdup(systemid);
5000 can_sign = privacy_system_can_sign(systemid);
5001 can_encrypt = privacy_system_can_encrypt(systemid);
5004 debug_print("activated privacy system: %s\n", systemid != NULL ? systemid : "None");
5006 ifactory = gtk_item_factory_from_widget(compose->menubar);
5007 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5008 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5011 static void compose_update_privacy_system_menu_item(Compose * compose)
5013 static gchar *branch_path = "/Options/Privacy System";
5014 GtkItemFactory *ifactory;
5015 GtkWidget *menuitem = NULL;
5017 gboolean can_sign = FALSE, can_encrypt = FALSE;
5019 ifactory = gtk_item_factory_from_widget(compose->menubar);
5021 if (compose->privacy_system != NULL) {
5024 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5025 g_return_if_fail(menuitem != NULL);
5027 amenu = GTK_MENU_SHELL(menuitem)->children;
5029 while (amenu != NULL) {
5030 GList *alist = amenu->next;
5032 systemid = gtk_object_get_data(GTK_OBJECT(amenu->data), "privacy_system");
5033 if (systemid != NULL)
5034 if (strcmp(systemid, compose->privacy_system) == 0) {
5035 menuitem = GTK_WIDGET(amenu->data);
5037 can_sign = privacy_system_can_sign(systemid);
5038 can_encrypt = privacy_system_can_encrypt(systemid);
5045 if (menuitem != NULL)
5046 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5049 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5050 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5053 static void compose_set_template_menu(Compose *compose)
5055 GSList *tmpl_list, *cur;
5059 tmpl_list = template_get_config();
5061 menu = gtk_menu_new();
5063 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5064 Template *tmpl = (Template *)cur->data;
5066 item = gtk_menu_item_new_with_label(tmpl->name);
5067 gtk_menu_append(GTK_MENU(menu), item);
5068 gtk_signal_connect(GTK_OBJECT(item), "activate",
5069 GTK_SIGNAL_FUNC(compose_template_activate_cb),
5071 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
5072 gtk_widget_show(item);
5075 gtk_widget_show(menu);
5076 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5079 void compose_update_actions_menu(Compose *compose)
5081 GtkItemFactory *ifactory;
5083 ifactory = gtk_item_factory_from_widget(compose->menubar);
5084 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5087 void compose_update_privacy_systems_menu(Compose *compose)
5089 static gchar *branch_path = "/Options/Privacy System";
5090 static gboolean connected = FALSE;
5091 GtkItemFactory *ifactory;
5092 GtkWidget *menuitem;
5093 GSList *systems, *cur;
5096 GtkWidget *system_none;
5099 ifactory = gtk_item_factory_from_widget(compose->menubar);
5101 /* remove old entries */
5102 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5103 g_return_if_fail(menuitem != NULL);
5105 amenu = GTK_MENU_SHELL(menuitem)->children->next;
5106 while (amenu != NULL) {
5107 GList *alist = amenu->next;
5108 gtk_widget_destroy(GTK_WIDGET(amenu->data));
5112 system_none = gtk_item_factory_get_widget(ifactory,
5113 "/Options/Privacy System/None");
5115 gtk_signal_connect(GTK_OBJECT(system_none), "activate",
5116 GTK_SIGNAL_FUNC(compose_set_privacy_system_cb), compose);
5120 systems = privacy_get_system_ids();
5121 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
5122 gchar *systemid = cur->data;
5124 group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(system_none));
5125 widget = gtk_radio_menu_item_new_with_label(group,
5126 privacy_system_get_name(systemid));
5127 gtk_object_set_data_full(GTK_OBJECT(widget), "privacy_system",
5128 g_strdup(systemid), g_free);
5129 gtk_signal_connect(GTK_OBJECT(widget), "activate",
5130 GTK_SIGNAL_FUNC(compose_set_privacy_system_cb), compose);
5132 gtk_menu_append(GTK_MENU(system_none->parent), widget);
5133 gtk_widget_show(widget);
5136 g_slist_free(systems);
5139 void compose_reflect_prefs_all(void)
5144 for (cur = compose_list; cur != NULL; cur = cur->next) {
5145 compose = (Compose *)cur->data;
5146 compose_set_template_menu(compose);
5150 void compose_reflect_prefs_pixmap_theme(void)
5155 for (cur = compose_list; cur != NULL; cur = cur->next) {
5156 compose = (Compose *)cur->data;
5157 toolbar_update(TOOLBAR_COMPOSE, compose);
5161 static void compose_template_apply(Compose *compose, Template *tmpl,
5167 if (!tmpl || !tmpl->value) return;
5169 gtk_stext_freeze(GTK_STEXT(compose->text));
5171 if (tmpl->subject && *tmpl->subject != '\0')
5172 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5174 if (tmpl->to && *tmpl->to != '\0')
5175 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5176 if (tmpl->cc && *tmpl->cc != '\0')
5177 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5179 if (tmpl->bcc && *tmpl->bcc != '\0')
5180 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5183 gtkut_stext_clear(GTK_STEXT(compose->text));
5185 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
5186 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5189 if (prefs_common.quotemark && *prefs_common.quotemark)
5190 qmark = prefs_common.quotemark;
5194 if (compose->replyinfo != NULL)
5195 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5196 tmpl->value, qmark, NULL);
5197 else if (compose->fwdinfo != NULL)
5198 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
5199 tmpl->value, qmark, NULL);
5204 if (replace && parsed_str && compose->account->auto_sig)
5205 compose_insert_sig(compose, FALSE);
5207 if (replace && parsed_str) {
5208 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
5209 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
5213 compose_changed_cb(NULL, compose);
5215 gtk_stext_thaw(GTK_STEXT(compose->text));
5218 static void compose_destroy(Compose *compose)
5221 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5224 /* NOTE: address_completion_end() does nothing with the window
5225 * however this may change. */
5226 address_completion_end(compose->window);
5228 slist_free_strings(compose->to_list);
5229 g_slist_free(compose->to_list);
5230 slist_free_strings(compose->newsgroup_list);
5231 g_slist_free(compose->newsgroup_list);
5232 slist_free_strings(compose->header_list);
5233 g_slist_free(compose->header_list);
5235 procmsg_msginfo_free(compose->targetinfo);
5236 procmsg_msginfo_free(compose->replyinfo);
5237 procmsg_msginfo_free(compose->fwdinfo);
5239 g_free(compose->replyto);
5240 g_free(compose->cc);
5241 g_free(compose->bcc);
5242 g_free(compose->newsgroups);
5243 g_free(compose->followup_to);
5245 g_free(compose->ml_post);
5247 g_free(compose->inreplyto);
5248 g_free(compose->references);
5249 g_free(compose->msgid);
5250 g_free(compose->boundary);
5252 if (compose->redirect_filename)
5253 g_free(compose->redirect_filename);
5254 if (compose->undostruct)
5255 undo_destroy(compose->undostruct);
5257 g_free(compose->sig_str);
5259 g_free(compose->exteditor_file);
5261 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5263 compose_attach_info_free(ainfo);
5265 if (addressbook_get_target_compose() == compose)
5266 addressbook_set_target_compose(NULL);
5269 if (compose->gtkaspell) {
5270 gtkaspell_delete(compose->gtkaspell);
5274 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5275 prefs_common.compose_height = compose->window->allocation.height;
5277 gtk_widget_destroy(compose->paned);
5279 toolbar_destroy(compose->toolbar);
5280 g_free(compose->toolbar);
5283 compose_list = g_list_remove(compose_list, compose);
5286 static void compose_attach_info_free(AttachInfo *ainfo)
5288 g_free(ainfo->file);
5289 g_free(ainfo->content_type);
5290 g_free(ainfo->name);
5294 static void compose_attach_remove_selected(Compose *compose)
5296 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5300 while (clist->selection != NULL) {
5301 row = GPOINTER_TO_INT(clist->selection->data);
5302 ainfo = gtk_clist_get_row_data(clist, row);
5303 compose_attach_info_free(ainfo);
5304 gtk_clist_remove(clist, row);
5308 static struct _AttachProperty
5311 GtkWidget *mimetype_entry;
5312 GtkWidget *encoding_optmenu;
5313 GtkWidget *path_entry;
5314 GtkWidget *filename_entry;
5316 GtkWidget *cancel_btn;
5319 static void compose_attach_property(Compose *compose)
5321 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5324 GtkOptionMenu *optmenu;
5325 static gboolean cancelled;
5327 if (!clist->selection) return;
5328 row = GPOINTER_TO_INT(clist->selection->data);
5330 ainfo = gtk_clist_get_row_data(clist, row);
5333 if (!attach_prop.window)
5334 compose_attach_property_create(&cancelled);
5335 gtk_widget_grab_focus(attach_prop.ok_btn);
5336 gtk_widget_show(attach_prop.window);
5337 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5339 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5340 if (ainfo->encoding == ENC_UNKNOWN)
5341 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5342 GINT_TO_POINTER(ENC_BASE64));
5344 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5345 GINT_TO_POINTER(ainfo->encoding));
5347 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5348 ainfo->content_type ? ainfo->content_type : "");
5349 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5350 ainfo->file ? ainfo->file : "");
5351 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5352 ainfo->name ? ainfo->name : "");
5356 gchar *cnttype = NULL;
5360 GtkWidget *menuitem;
5365 if (cancelled == TRUE) {
5366 gtk_widget_hide(attach_prop.window);
5370 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5371 if (*text != '\0') {
5374 text = g_strstrip(g_strdup(text));
5375 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5376 cnttype = g_strdup(text);
5379 alertpanel_error(_("Invalid MIME type."));
5385 menu = gtk_option_menu_get_menu(optmenu);
5386 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5387 ainfo->encoding = GPOINTER_TO_INT
5388 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5390 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5391 if (*text != '\0') {
5392 if (is_file_exist(text) &&
5393 (size = get_file_size(text)) > 0)
5394 file = g_strdup(text);
5397 (_("File doesn't exist or is empty."));
5403 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5404 if (*text != '\0') {
5405 g_free(ainfo->name);
5406 ainfo->name = g_strdup(text);
5410 g_free(ainfo->content_type);
5411 ainfo->content_type = cnttype;
5414 g_free(ainfo->file);
5420 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5421 ainfo->content_type);
5422 gtk_clist_set_text(clist, row, COL_SIZE,
5423 to_human_readable(ainfo->size));
5424 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5426 gtk_widget_hide(attach_prop.window);
5431 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5433 label = gtk_label_new(str); \
5434 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5435 GTK_FILL, 0, 0, 0); \
5436 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5438 entry = gtk_entry_new(); \
5439 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5440 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5443 static void compose_attach_property_create(gboolean *cancelled)
5449 GtkWidget *mimetype_entry;
5452 GtkWidget *optmenu_menu;
5453 GtkWidget *menuitem;
5454 GtkWidget *path_entry;
5455 GtkWidget *filename_entry;
5458 GtkWidget *cancel_btn;
5459 GList *mime_type_list, *strlist;
5461 debug_print("Creating attach_property window...\n");
5463 window = gtk_window_new(GTK_WINDOW_DIALOG);
5464 gtk_widget_set_usize(window, 480, -1);
5465 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5466 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
5467 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5468 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5469 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5470 GTK_SIGNAL_FUNC(attach_property_delete_event),
5472 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5473 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5476 vbox = gtk_vbox_new(FALSE, 8);
5477 gtk_container_add(GTK_CONTAINER(window), vbox);
5479 table = gtk_table_new(4, 2, FALSE);
5480 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5481 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5482 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5484 label = gtk_label_new(_("MIME type"));
5485 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5487 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5488 mimetype_entry = gtk_combo_new();
5489 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5490 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5492 /* stuff with list */
5493 mime_type_list = procmime_get_mime_type_list();
5495 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5496 MimeType *type = (MimeType *) mime_type_list->data;
5497 strlist = g_list_append(strlist,
5498 g_strdup_printf("%s/%s",
5499 type->type, type->sub_type));
5502 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5504 for (mime_type_list = strlist; mime_type_list != NULL;
5505 mime_type_list = mime_type_list->next)
5506 g_free(mime_type_list->data);
5507 g_list_free(strlist);
5509 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5511 label = gtk_label_new(_("Encoding"));
5512 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5514 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5516 hbox = gtk_hbox_new(FALSE, 0);
5517 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5518 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5520 optmenu = gtk_option_menu_new();
5521 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5523 optmenu_menu = gtk_menu_new();
5524 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5525 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5527 gtk_widget_set_sensitive(menuitem, FALSE);
5529 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5530 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5532 gtk_widget_set_sensitive(menuitem, FALSE);
5534 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
5535 ENC_QUOTED_PRINTABLE);
5536 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5538 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5540 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5542 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5543 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5545 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5546 &cancel_btn, _("Cancel"), NULL, NULL);
5547 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5548 gtk_widget_grab_default(ok_btn);
5550 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5551 GTK_SIGNAL_FUNC(attach_property_ok),
5553 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5554 GTK_SIGNAL_FUNC(attach_property_cancel),
5557 gtk_widget_show_all(vbox);
5559 attach_prop.window = window;
5560 attach_prop.mimetype_entry = mimetype_entry;
5561 attach_prop.encoding_optmenu = optmenu;
5562 attach_prop.path_entry = path_entry;
5563 attach_prop.filename_entry = filename_entry;
5564 attach_prop.ok_btn = ok_btn;
5565 attach_prop.cancel_btn = cancel_btn;
5568 #undef SET_LABEL_AND_ENTRY
5570 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5576 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5582 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5583 gboolean *cancelled)
5591 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5592 gboolean *cancelled)
5594 if (event && event->keyval == GDK_Escape) {
5600 static void compose_exec_ext_editor(Compose *compose)
5606 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
5607 G_DIR_SEPARATOR, compose);
5609 if (pipe(pipe_fds) < 0) {
5615 if ((pid = fork()) < 0) {
5622 /* close the write side of the pipe */
5625 compose->exteditor_file = g_strdup(tmp);
5626 compose->exteditor_pid = pid;
5627 compose->exteditor_readdes = pipe_fds[0];
5629 compose_set_ext_editor_sensitive(compose, FALSE);
5631 compose->exteditor_tag =
5632 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5633 compose_input_cb, compose);
5634 } else { /* process-monitoring process */
5640 /* close the read side of the pipe */
5643 if (compose_write_body_to_file(compose, tmp) < 0) {
5644 fd_write_all(pipe_fds[1], "2\n", 2);
5648 pid_ed = compose_exec_ext_editor_real(tmp);
5650 fd_write_all(pipe_fds[1], "1\n", 2);
5654 /* wait until editor is terminated */
5655 waitpid(pid_ed, NULL, 0);
5657 fd_write_all(pipe_fds[1], "0\n", 2);
5666 static gint compose_exec_ext_editor_real(const gchar *file)
5668 static gchar *def_cmd = "emacs %s";
5674 g_return_val_if_fail(file != NULL, -1);
5676 if ((pid = fork()) < 0) {
5681 if (pid != 0) return pid;
5683 /* grandchild process */
5685 if (setpgid(0, getppid()))
5688 if (prefs_common.ext_editor_cmd &&
5689 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5690 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5691 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5693 if (prefs_common.ext_editor_cmd)
5694 g_warning("External editor command line is invalid: `%s'\n",
5695 prefs_common.ext_editor_cmd);
5696 g_snprintf(buf, sizeof(buf), def_cmd, file);
5699 cmdline = strsplit_with_quote(buf, " ", 1024);
5700 execvp(cmdline[0], cmdline);
5703 g_strfreev(cmdline);
5708 static gboolean compose_ext_editor_kill(Compose *compose)
5710 pid_t pgid = compose->exteditor_pid * -1;
5713 ret = kill(pgid, 0);
5715 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5719 msg = g_strdup_printf
5720 (_("The external editor is still working.\n"
5721 "Force terminating the process?\n"
5722 "process group id: %d"), -pgid);
5723 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5726 if (val == G_ALERTDEFAULT) {
5727 gdk_input_remove(compose->exteditor_tag);
5728 close(compose->exteditor_readdes);
5730 if (kill(pgid, SIGTERM) < 0) perror("kill");
5731 waitpid(compose->exteditor_pid, NULL, 0);
5733 g_warning("Terminated process group id: %d", -pgid);
5734 g_warning("Temporary file: %s",
5735 compose->exteditor_file);
5737 compose_set_ext_editor_sensitive(compose, TRUE);
5739 g_free(compose->exteditor_file);
5740 compose->exteditor_file = NULL;
5741 compose->exteditor_pid = -1;
5742 compose->exteditor_readdes = -1;
5743 compose->exteditor_tag = -1;
5751 static void compose_input_cb(gpointer data, gint source,
5752 GdkInputCondition condition)
5755 Compose *compose = (Compose *)data;
5758 debug_print("Compose: input from monitoring process\n");
5760 gdk_input_remove(compose->exteditor_tag);
5763 if (read(source, &buf[i], 1) < 1) {
5767 if (buf[i] == '\n') {
5772 if (i == sizeof(buf) - 1)
5776 waitpid(compose->exteditor_pid, NULL, 0);
5778 if (buf[0] == '0') { /* success */
5779 GtkSText *text = GTK_STEXT(compose->text);
5781 gtk_stext_freeze(text);
5782 gtk_stext_set_point(text, 0);
5783 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5784 compose_insert_file(compose, compose->exteditor_file);
5785 compose_changed_cb(NULL, compose);
5786 gtk_stext_thaw(text);
5788 if (unlink(compose->exteditor_file) < 0)
5789 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5790 } else if (buf[0] == '1') { /* failed */
5791 g_warning("Couldn't exec external editor\n");
5792 if (unlink(compose->exteditor_file) < 0)
5793 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5794 } else if (buf[0] == '2') {
5795 g_warning("Couldn't write to file\n");
5796 } else if (buf[0] == '3') {
5797 g_warning("Pipe read failed\n");
5802 compose_set_ext_editor_sensitive(compose, TRUE);
5804 g_free(compose->exteditor_file);
5805 compose->exteditor_file = NULL;
5806 compose->exteditor_pid = -1;
5807 compose->exteditor_readdes = -1;
5808 compose->exteditor_tag = -1;
5811 static void compose_set_ext_editor_sensitive(Compose *compose,
5814 GtkItemFactory *ifactory;
5816 ifactory = gtk_item_factory_from_widget(compose->menubar);
5818 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5819 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5820 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
5821 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
5822 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5823 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5824 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5827 gtk_widget_set_sensitive(compose->text, sensitive);
5828 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
5829 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
5830 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
5831 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
5832 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
5833 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
5834 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
5835 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
5839 * compose_undo_state_changed:
5841 * Change the sensivity of the menuentries undo and redo
5843 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5844 gint redo_state, gpointer data)
5846 GtkWidget *widget = GTK_WIDGET(data);
5847 GtkItemFactory *ifactory;
5849 g_return_if_fail(widget != NULL);
5851 ifactory = gtk_item_factory_from_widget(widget);
5853 switch (undo_state) {
5854 case UNDO_STATE_TRUE:
5855 if (!undostruct->undo_state) {
5856 undostruct->undo_state = TRUE;
5857 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5860 case UNDO_STATE_FALSE:
5861 if (undostruct->undo_state) {
5862 undostruct->undo_state = FALSE;
5863 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5866 case UNDO_STATE_UNCHANGED:
5868 case UNDO_STATE_REFRESH:
5869 menu_set_sensitive(ifactory, "/Edit/Undo",
5870 undostruct->undo_state);
5873 g_warning("Undo state not recognized");
5877 switch (redo_state) {
5878 case UNDO_STATE_TRUE:
5879 if (!undostruct->redo_state) {
5880 undostruct->redo_state = TRUE;
5881 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5884 case UNDO_STATE_FALSE:
5885 if (undostruct->redo_state) {
5886 undostruct->redo_state = FALSE;
5887 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5890 case UNDO_STATE_UNCHANGED:
5892 case UNDO_STATE_REFRESH:
5893 menu_set_sensitive(ifactory, "/Edit/Redo",
5894 undostruct->redo_state);
5897 g_warning("Redo state not recognized");
5902 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5906 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5907 cursor_pos = MAX(cursor_pos, 0);
5912 /* callback functions */
5914 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5915 * includes "non-client" (windows-izm) in calculation, so this calculation
5916 * may not be accurate.
5918 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5919 GtkAllocation *allocation,
5920 GtkSHRuler *shruler)
5922 if (prefs_common.show_ruler) {
5924 gint line_width_in_chars;
5926 char_width = gtkut_get_font_width
5927 (GTK_WIDGET(widget)->style->font);
5928 line_width_in_chars =
5929 (allocation->width - allocation->x) / char_width;
5931 /* got the maximum */
5932 gtk_ruler_set_range(GTK_RULER(shruler),
5933 0.0, line_width_in_chars,
5934 calc_cursor_xpos(GTK_STEXT(widget),
5937 /*line_width_in_chars*/ char_width);
5943 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5945 Compose *compose = (Compose *)data;
5948 gchar *folderidentifier;
5950 ac = account_find_from_id(
5951 GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menuitem))));
5952 g_return_if_fail(ac != NULL);
5954 if (ac != compose->account)
5955 compose_select_account(compose, ac, FALSE);
5957 /* Set message save folder */
5958 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5959 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
5961 gtk_signal_connect(GTK_OBJECT(compose->savemsg_checkbtn), "toggled",
5962 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
5964 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
5965 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5966 folderidentifier = folder_item_get_identifier(account_get_special_folder
5967 (compose->account, F_OUTBOX));
5968 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
5969 g_free(folderidentifier);
5973 static void attach_selected(GtkCList *clist, gint row, gint column,
5974 GdkEvent *event, gpointer data)
5976 Compose *compose = (Compose *)data;
5978 if (event && event->type == GDK_2BUTTON_PRESS)
5979 compose_attach_property(compose);
5982 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5985 Compose *compose = (Compose *)data;
5986 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5991 if (event->button == 3) {
5992 if ((clist->selection && !clist->selection->next) ||
5993 !clist->selection) {
5994 gtk_clist_unselect_all(clist);
5995 if (gtk_clist_get_selection_info(clist,
5998 gtk_clist_select_row(clist, row, column);
5999 gtkut_clist_set_focus_row(clist, row);
6002 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6003 NULL, NULL, event->button, event->time);
6007 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6010 Compose *compose = (Compose *)data;
6014 switch (event->keyval) {
6016 compose_attach_remove_selected(compose);
6021 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6023 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6024 toolbar_comp_set_sensitive(compose, allow);
6025 menu_set_sensitive(ifactory, "/Message", allow);
6026 menu_set_sensitive(ifactory, "/Edit", allow);
6028 menu_set_sensitive(ifactory, "/Spelling", allow);
6030 menu_set_sensitive(ifactory, "/Options", allow);
6031 menu_set_sensitive(ifactory, "/Tools", allow);
6032 menu_set_sensitive(ifactory, "/Help", allow);
6035 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6037 Compose *compose = (Compose *)data;
6039 if (prefs_common.work_offline)
6040 if (alertpanel(_("Offline warning"),
6041 _("You're working offline. Override?"),
6042 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
6045 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
6046 gtk_timeout_remove(compose->draft_timeout_tag);
6047 compose->draft_timeout_tag = -1;
6050 compose_send(compose);
6053 static void compose_send_later_cb(gpointer data, guint action,
6056 Compose *compose = (Compose *)data;
6059 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6060 if (!val) gtk_widget_destroy(compose->window);
6063 void compose_draft (gpointer data)
6065 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6068 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6070 Compose *compose = (Compose *)data;
6074 MsgFlags flag = {0, 0};
6075 static gboolean lock = FALSE;
6076 MsgInfo *newmsginfo;
6081 draft = account_get_special_folder(compose->account, F_DRAFT);
6082 g_return_if_fail(draft != NULL);
6086 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
6087 G_DIR_SEPARATOR, compose);
6088 if ((fp = fopen(tmp, "wb")) == NULL) {
6089 FILE_OP_ERROR(tmp, "fopen");
6093 /* chmod for security */
6094 if (change_file_mode_rw(fp, tmp) < 0) {
6095 FILE_OP_ERROR(tmp, "chmod");
6096 g_warning("can't change file mode\n");
6099 /* Save draft infos */
6100 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
6101 fprintf(fp, "S:%s\n", compose->account->address);
6102 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
6103 gchar *savefolderid;
6105 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6106 fprintf(fp, "SCF:%s\n", savefolderid);
6107 g_free(savefolderid);
6109 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
6110 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
6111 fprintf(fp, "X-Sylpheed-Gnupg-Mode:%s\n", compose->privacy_system);
6114 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
6123 folder_item_scan(draft);
6124 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
6131 draft->mtime = 0; /* force updating */
6133 if (compose->mode == COMPOSE_REEDIT) {
6134 compose_remove_reedit_target(compose);
6137 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6139 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6140 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
6141 if (compose_use_attach(compose))
6142 procmsg_msginfo_set_flags(newmsginfo, 0,
6143 MSG_HAS_ATTACHMENT);
6145 procmsg_msginfo_free(newmsginfo);
6148 folder_item_scan(draft);
6152 if (action == COMPOSE_QUIT_EDITING)
6153 gtk_widget_destroy(compose->window);
6158 path = folder_item_fetch_msg(draft, msgnum);
6159 g_return_if_fail(path != NULL);
6160 if (stat(path, &s) < 0) {
6161 FILE_OP_ERROR(path, "stat");
6168 procmsg_msginfo_free(compose->targetinfo);
6169 compose->targetinfo = procmsg_msginfo_new();
6170 compose->targetinfo->msgnum = msgnum;
6171 compose->targetinfo->size = s.st_size;
6172 compose->targetinfo->mtime = s.st_mtime;
6173 compose->targetinfo->folder = draft;
6174 compose->mode = COMPOSE_REEDIT;
6176 if (action == COMPOSE_AUTO_SAVE) {
6177 compose->autosaved_draft = compose->targetinfo;
6182 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6184 Compose *compose = (Compose *)data;
6187 if (compose->redirect_filename != NULL)
6190 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6195 for ( tmp = file_list; tmp; tmp = tmp->next) {
6196 gchar *file = (gchar *) tmp->data;
6197 compose_attach_append(compose, file, file, NULL);
6198 compose_changed_cb(NULL, compose);
6201 g_list_free(file_list);
6205 static void compose_insert_file_cb(gpointer data, guint action,
6208 Compose *compose = (Compose *)data;
6211 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6216 for ( tmp = file_list; tmp; tmp = tmp->next) {
6217 gchar *file = (gchar *) tmp->data;
6218 gchar *filedup = g_strdup(file);
6220 ComposeInsertResult res;
6222 res = compose_insert_file(compose, file);
6223 shortfile = g_basename(filedup);
6224 if (res == COMPOSE_INSERT_READ_ERROR) {
6225 alertpanel_error(_("File '%s' could not be read."), shortfile);
6226 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
6227 alertpanel_error(_("File '%s' contained invalid characters\n"
6228 "for the current encoding, insertion may be incorrect."), shortfile);
6233 g_list_free(file_list);
6237 static void compose_insert_sig_cb(gpointer data, guint action,
6240 Compose *compose = (Compose *)data;
6242 compose_insert_sig(compose, FALSE);
6245 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6249 Compose *compose = (Compose *)data;
6251 gtkut_widget_get_uposition(widget, &x, &y);
6252 prefs_common.compose_x = x;
6253 prefs_common.compose_y = y;
6255 if (compose->sending)
6257 compose_close_cb(compose, 0, NULL);
6261 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6263 Compose *compose = (Compose *)data;
6266 if (compose->exteditor_tag != -1) {
6267 if (!compose_ext_editor_kill(compose))
6271 if (compose->modified) {
6272 val = alertpanel(_("Discard message"),
6273 _("This message has been modified. discard it?"),
6274 _("Discard"), _("to Draft"), _("Cancel"));
6277 case G_ALERTDEFAULT:
6278 if (prefs_common.autosave)
6279 compose_remove_draft(compose);
6281 case G_ALERTALTERNATE:
6282 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6289 gtk_widget_destroy(compose->window);
6292 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6294 Compose *compose = (Compose *)data;
6296 addressbook_open(compose);
6299 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6301 Compose *compose = (Compose *)data;
6306 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6307 g_return_if_fail(tmpl != NULL);
6309 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6311 val = alertpanel(_("Apply template"), msg,
6312 _("Replace"), _("Insert"), _("Cancel"));
6315 if (val == G_ALERTDEFAULT)
6316 compose_template_apply(compose, tmpl, TRUE);
6317 else if (val == G_ALERTALTERNATE)
6318 compose_template_apply(compose, tmpl, FALSE);
6321 static void compose_ext_editor_cb(gpointer data, guint action,
6324 Compose *compose = (Compose *)data;
6326 compose_exec_ext_editor(compose);
6329 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6331 if (compose->sending)
6333 compose_destroy(compose);
6336 static void compose_undo_cb(Compose *compose)
6338 undo_undo(compose->undostruct);
6341 static void compose_redo_cb(Compose *compose)
6343 undo_redo(compose->undostruct);
6346 static void compose_cut_cb(Compose *compose)
6348 if (compose->focused_editable &&
6349 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6350 gtk_editable_cut_clipboard
6351 (GTK_EDITABLE(compose->focused_editable));
6354 static void compose_copy_cb(Compose *compose)
6356 if (compose->focused_editable &&
6357 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6358 gtk_editable_copy_clipboard
6359 (GTK_EDITABLE(compose->focused_editable));
6362 static void compose_paste_cb(Compose *compose)
6364 if (compose->focused_editable &&
6365 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6366 gtk_editable_paste_clipboard
6367 (GTK_EDITABLE(compose->focused_editable));
6370 static void compose_paste_as_quote_cb(Compose *compose)
6372 if (compose->focused_editable &&
6373 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6374 /* let text_insert() (called directly or at a later time
6375 * after the gtk_editable_paste_clipboard) know that
6376 * text is to be inserted as a quotation. implemented
6377 * by using a simple refcount... */
6378 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data(
6379 GTK_OBJECT(compose->focused_editable),
6380 "paste_as_quotation"));
6381 gtk_object_set_data(GTK_OBJECT(compose->focused_editable),
6382 "paste_as_quotation",
6383 GINT_TO_POINTER(paste_as_quotation + 1));
6384 gtk_editable_paste_clipboard
6385 (GTK_EDITABLE(compose->focused_editable));
6389 static void compose_allsel_cb(Compose *compose)
6391 if (compose->focused_editable &&
6392 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6393 gtk_editable_select_region
6394 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6397 static void compose_gtk_stext_action_cb(Compose *compose,
6398 ComposeCallGtkSTextAction action)
6400 GtkSText *text = GTK_STEXT(compose->text);
6402 void (*do_action) (GtkSText *text);
6403 } action_table[] = {
6404 {gtk_stext_move_beginning_of_line},
6405 {gtk_stext_move_forward_character},
6406 {gtk_stext_move_backward_character},
6407 {gtk_stext_move_forward_word},
6408 {gtk_stext_move_backward_word},
6409 {gtk_stext_move_end_of_line},
6410 {gtk_stext_move_next_line},
6411 {gtk_stext_move_previous_line},
6412 {gtk_stext_delete_forward_character},
6413 {gtk_stext_delete_backward_character},
6414 {gtk_stext_delete_forward_word},
6415 {gtk_stext_delete_backward_word},
6416 {gtk_stext_delete_line},
6417 {gtk_stext_delete_line}, /* gtk_stext_delete_line_n */
6418 {gtk_stext_delete_to_line_end}
6421 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
6423 if (action >= COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE &&
6424 action <= COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END)
6425 action_table[action].do_action(text);
6428 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6430 if (GTK_IS_EDITABLE(widget))
6431 compose->focused_editable = widget;
6434 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6436 if (compose->modified == FALSE) {
6437 compose->modified = TRUE;
6438 compose_set_title(compose);
6442 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6445 gtk_stext_set_point(GTK_STEXT(widget),
6446 gtk_editable_get_position(GTK_EDITABLE(widget)));
6450 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6453 gtk_stext_set_point(GTK_STEXT(widget),
6454 gtk_editable_get_position(GTK_EDITABLE(widget)));
6458 static void compose_toggle_autowrap_cb(gpointer data, guint action,
6461 Compose *compose = (Compose *)data;
6463 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
6464 if (compose->autowrap)
6465 compose_wrap_line_all_full(compose, TRUE);
6468 static void compose_toggle_sign_cb(gpointer data, guint action,
6471 Compose *compose = (Compose *)data;
6473 if (GTK_CHECK_MENU_ITEM(widget)->active)
6474 compose->use_signing = TRUE;
6476 compose->use_signing = FALSE;
6479 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6482 Compose *compose = (Compose *)data;
6484 if (GTK_CHECK_MENU_ITEM(widget)->active)
6485 compose->use_encryption = TRUE;
6487 compose->use_encryption = FALSE;
6490 static void activate_privacy_system(Compose *compose, PrefsAccount *account)
6492 g_free(compose->privacy_system);
6493 compose->privacy_system = g_strdup(account->default_privacy_system);
6494 compose_update_privacy_system_menu_item(compose);
6497 static void compose_toggle_ruler_cb(gpointer data, guint action,
6500 Compose *compose = (Compose *)data;
6502 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6503 gtk_widget_show(compose->ruler_hbox);
6504 prefs_common.show_ruler = TRUE;
6506 gtk_widget_hide(compose->ruler_hbox);
6507 gtk_widget_queue_resize(compose->edit_vbox);
6508 prefs_common.show_ruler = FALSE;
6512 static void compose_attach_drag_received_cb (GtkWidget *widget,
6513 GdkDragContext *drag_context,
6516 GtkSelectionData *data,
6521 Compose *compose = (Compose *)user_data;
6524 list = uri_list_extract_filenames((const gchar *)data->data);
6525 for (tmp = list; tmp != NULL; tmp = tmp->next)
6526 compose_attach_append
6527 (compose, (const gchar *)tmp->data,
6528 (const gchar *)tmp->data, NULL);
6529 if (list) compose_changed_cb(NULL, compose);
6530 list_free_strings(list);
6534 static void compose_insert_drag_received_cb (GtkWidget *widget,
6535 GdkDragContext *drag_context,
6538 GtkSelectionData *data,
6543 Compose *compose = (Compose *)user_data;
6546 list = uri_list_extract_filenames((const gchar *)data->data);
6547 for (tmp = list; tmp != NULL; tmp = tmp->next)
6548 compose_insert_file(compose, (const gchar *)tmp->data);
6549 list_free_strings(list);
6553 #if 0 /* NEW COMPOSE GUI */
6554 static void to_activated(GtkWidget *widget, Compose *compose)
6556 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6557 gtk_widget_grab_focus(compose->newsgroups_entry);
6559 gtk_widget_grab_focus(compose->subject_entry);
6562 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6564 gtk_widget_grab_focus(compose->subject_entry);
6567 static void subject_activated(GtkWidget *widget, Compose *compose)
6569 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6570 gtk_widget_grab_focus(compose->cc_entry);
6571 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6572 gtk_widget_grab_focus(compose->bcc_entry);
6573 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6574 gtk_widget_grab_focus(compose->reply_entry);
6575 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6576 gtk_widget_grab_focus(compose->followup_entry);
6578 gtk_widget_grab_focus(compose->text);
6581 static void cc_activated(GtkWidget *widget, Compose *compose)
6583 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6584 gtk_widget_grab_focus(compose->bcc_entry);
6585 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6586 gtk_widget_grab_focus(compose->reply_entry);
6587 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6588 gtk_widget_grab_focus(compose->followup_entry);
6590 gtk_widget_grab_focus(compose->text);
6593 static void bcc_activated(GtkWidget *widget, Compose *compose)
6595 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6596 gtk_widget_grab_focus(compose->reply_entry);
6597 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6598 gtk_widget_grab_focus(compose->followup_entry);
6600 gtk_widget_grab_focus(compose->text);
6603 static void replyto_activated(GtkWidget *widget, Compose *compose)
6605 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6606 gtk_widget_grab_focus(compose->followup_entry);
6608 gtk_widget_grab_focus(compose->text);
6611 static void followupto_activated(GtkWidget *widget, Compose *compose)
6613 gtk_widget_grab_focus(compose->text);
6617 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6620 Compose *compose = (Compose *)data;
6622 if (GTK_CHECK_MENU_ITEM(widget)->active)
6623 compose->return_receipt = TRUE;
6625 compose->return_receipt = FALSE;
6628 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
6631 Compose *compose = (Compose *)data;
6633 if (GTK_CHECK_MENU_ITEM(widget)->active)
6634 compose->remove_references = TRUE;
6636 compose->remove_references = FALSE;
6639 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6641 ComposeHeaderEntry *headerentry)
6643 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6644 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6645 !(event->state & GDK_MODIFIER_MASK) &&
6646 (event->keyval == GDK_BackSpace) &&
6647 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6648 gtk_container_remove
6649 (GTK_CONTAINER(headerentry->compose->header_table),
6650 headerentry->combo);
6651 gtk_container_remove
6652 (GTK_CONTAINER(headerentry->compose->header_table),
6653 headerentry->entry);
6654 headerentry->compose->header_list =
6655 g_slist_remove(headerentry->compose->header_list,
6657 g_free(headerentry);
6658 } else if (event->keyval == GDK_Tab) {
6659 if (headerentry->compose->header_last == headerentry) {
6660 /* Override default next focus, and give it to subject_entry
6661 * instead of notebook tabs
6663 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6664 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6670 void compose_headerentry_changed_cb(GtkWidget *entry,
6671 ComposeHeaderEntry *headerentry)
6673 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6674 headerentry->compose->header_list =
6675 g_slist_append(headerentry->compose->header_list,
6677 compose_create_header_entry(headerentry->compose);
6678 gtk_signal_disconnect_by_func
6680 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6682 /* Automatically scroll down */
6683 compose_show_first_last_header(headerentry->compose, FALSE);
6688 static gboolean compose_headerentry_button_pressed
6689 (GtkWidget *entry, GdkEventButton *event, gpointer data)
6691 /* if this is a lclick, grab the focus */
6692 if (event->button == 1)
6693 gtk_widget_grab_focus(entry);
6697 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6699 GtkAdjustment *vadj;
6701 g_return_if_fail(compose);
6702 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6703 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6705 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6706 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6709 static void text_activated(GtkWidget *widget, Compose *compose)
6711 compose_send_control_enter(compose);
6714 static void text_inserted(GtkWidget *widget, const gchar *text,
6715 gint length, gint *position, Compose *compose)
6717 GtkEditable *editable = GTK_EDITABLE(widget);
6718 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data
6719 (GTK_OBJECT(widget), "paste_as_quotation"));
6721 gtk_signal_handler_block_by_func(GTK_OBJECT(widget),
6722 GTK_SIGNAL_FUNC(text_inserted),
6724 if (paste_as_quotation) {
6729 new_text = g_strndup(text, length);
6730 if (prefs_common.quotemark && *prefs_common.quotemark)
6731 qmark = prefs_common.quotemark;
6734 gtk_stext_set_point(GTK_STEXT(widget), *position);
6735 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
6736 pos = gtk_stext_get_point(GTK_STEXT(widget));
6737 gtk_editable_set_position(editable, pos);
6740 gtk_object_set_data(GTK_OBJECT(widget), "paste_as_quotation",
6741 GINT_TO_POINTER(paste_as_quotation - 1));
6743 gtk_editable_insert_text(editable, text, length, position);
6745 if (compose->autowrap)
6746 compose_wrap_line_all_full(compose, TRUE);
6748 gtk_signal_handler_unblock_by_func(GTK_OBJECT(widget),
6749 GTK_SIGNAL_FUNC(text_inserted),
6751 gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
6753 if (prefs_common.autosave &&
6754 gtk_stext_get_length(GTK_STEXT(widget)) % prefs_common.autosave_length == 0)
6755 compose->draft_timeout_tag = gtk_timeout_add
6756 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
6759 static gint compose_defer_auto_save_draft(Compose *compose)
6761 compose->draft_timeout_tag = -1;
6762 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
6766 static gboolean compose_send_control_enter(Compose *compose)
6770 GtkItemFactory *ifactory;
6771 GtkAccelEntry *accel;
6772 GtkWidget *send_menu;
6774 GdkModifierType ignored_mods =
6775 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
6776 GDK_MOD4_MASK | GDK_MOD5_MASK);
6778 ev = gtk_get_current_event();
6779 if (ev->type != GDK_KEY_PRESS) return FALSE;
6781 kev = (GdkEventKey *)ev;
6782 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6785 if (compose->exteditor_tag != -1)
6788 ifactory = gtk_item_factory_from_widget(compose->menubar);
6789 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6790 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6794 accel = (GtkAccelEntry *)list->data;
6795 if (accel && accel->accelerator_key == kev->keyval &&
6796 (accel->accelerator_mods & ~ignored_mods) ==
6797 (kev->state & ~ignored_mods)) {
6798 compose_send_cb(compose, 0, NULL);
6806 static void compose_check_all(Compose *compose)
6808 if (compose->gtkaspell)
6809 gtkaspell_check_all(compose->gtkaspell);
6812 static void compose_highlight_all(Compose *compose)
6814 if (compose->gtkaspell)
6815 gtkaspell_highlight_all(compose->gtkaspell);
6818 static void compose_check_backwards(Compose *compose)
6820 if (compose->gtkaspell)
6821 gtkaspell_check_backwards(compose->gtkaspell);
6823 GtkItemFactory *ifactory;
6824 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6825 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6826 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6830 static void compose_check_forwards_go(Compose *compose)
6832 if (compose->gtkaspell)
6833 gtkaspell_check_forwards_go(compose->gtkaspell);
6835 GtkItemFactory *ifactory;
6836 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6837 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6838 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6844 *\brief Guess originating forward account from MsgInfo and several
6845 * "common preference" settings. Return NULL if no guess.
6847 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
6849 PrefsAccount *account = NULL;
6851 g_return_val_if_fail(msginfo, NULL);
6852 g_return_val_if_fail(msginfo->folder, NULL);
6853 g_return_val_if_fail(msginfo->folder->prefs, NULL);
6855 if (msginfo->folder->prefs->enable_default_account)
6856 account = account_find_from_id(msginfo->folder->prefs->default_account);
6859 account = msginfo->folder->folder->account;
6861 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
6863 Xstrdup_a(to, msginfo->to, return NULL);
6864 extract_address(to);
6865 account = account_find_from_address(to);
6868 if (!account && prefs_common.forward_account_autosel) {
6870 if (!procheader_get_header_from_msginfo
6871 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
6872 extract_address(cc);
6873 account = account_find_from_address(cc);
6881 * Add entry field for each address in list.
6882 * \param compose E-Mail composition object.
6883 * \param listAddress List of (formatted) E-Mail addresses.
6885 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
6890 addr = ( gchar * ) node->data;
6891 compose_entry_append( compose, addr, COMPOSE_TO );
6892 node = g_list_next( node );