2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 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> */
66 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
73 #include "mainwindow.h"
76 #include "addressbook.h"
77 #include "folderview.h"
80 #include "stock_pixmap.h"
84 #include "customheader.h"
85 #include "prefs_common.h"
86 #include "prefs_account.h"
89 #include "procheader.h"
91 #include "statusbar.h"
98 #include "alertpanel.h"
99 #include "manage_window.h"
100 #include "gtkshruler.h"
102 #include "addr_compl.h"
103 #include "quote_fmt.h"
104 #include "template.h"
106 #include "foldersel.h"
107 #include "prefs_actions.h"
110 # include "rfc2015.h"
120 #define N_ATTACH_COLS 3
124 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
125 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
126 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
127 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
128 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
129 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
130 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
131 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
132 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
133 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
134 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
135 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
136 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
137 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
138 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
139 } ComposeCallGtkSTextAction;
143 PRIORITY_HIGHEST = 1,
150 #define B64_LINE_SIZE 57
151 #define B64_BUFFSIZE 77
153 #define MAX_REFERENCES_LEN 999
155 static GdkColor quote_color = {0, 0, 0, 0xbfff};
157 static GList *compose_list = NULL;
159 Compose *compose_generic_new (PrefsAccount *account,
163 static Compose *compose_create (PrefsAccount *account,
165 static void compose_toolbar_create (Compose *compose,
166 GtkWidget *container);
167 static GtkWidget *compose_account_option_menu_create
169 static void compose_set_template_menu (Compose *compose);
170 static void compose_template_apply (Compose *compose,
173 static void compose_destroy (Compose *compose);
175 static void compose_entries_set (Compose *compose,
176 const gchar *mailto);
177 static gint compose_parse_header (Compose *compose,
179 static gchar *compose_parse_references (const gchar *ref,
182 static gchar *compose_quote_fmt (Compose *compose,
188 static void compose_reply_set_entry (Compose *compose,
193 followup_and_reply_to);
194 static void compose_reedit_set_entry (Compose *compose,
196 static void compose_insert_sig (Compose *compose);
197 static void compose_insert_file (Compose *compose,
199 static void compose_attach_append (Compose *compose,
202 const gchar *content_type);
203 static void compose_attach_parts (Compose *compose,
205 static void compose_wrap_line (Compose *compose);
206 static void compose_wrap_line_all (Compose *compose);
207 static void compose_set_title (Compose *compose);
209 static PrefsAccount *compose_current_mail_account(void);
210 /* static gint compose_send (Compose *compose); */
211 static gboolean compose_check_for_valid_recipient
213 static gboolean compose_check_entries (Compose *compose,
214 gboolean check_subject);
215 static gint compose_write_to_file (Compose *compose,
218 static gint compose_write_body_to_file (Compose *compose,
220 static gint compose_remove_reedit_target (Compose *compose);
221 static gint compose_queue (Compose *compose,
224 static gint compose_queue_sub (Compose *compose,
227 gboolean check_subject);
228 static void compose_write_attach (Compose *compose,
230 static gint compose_write_headers (Compose *compose,
232 const gchar *charset,
233 EncodingType encoding,
236 static void compose_convert_header (gchar *dest,
240 static void compose_generate_msgid (Compose *compose,
244 static void compose_attach_info_free (AttachInfo *ainfo);
245 static void compose_attach_remove_selected (Compose *compose);
247 static void compose_attach_property (Compose *compose);
248 static void compose_attach_property_create (gboolean *cancelled);
249 static void attach_property_ok (GtkWidget *widget,
250 gboolean *cancelled);
251 static void attach_property_cancel (GtkWidget *widget,
252 gboolean *cancelled);
253 static gint attach_property_delete_event (GtkWidget *widget,
255 gboolean *cancelled);
256 static void attach_property_key_pressed (GtkWidget *widget,
258 gboolean *cancelled);
260 static void compose_exec_ext_editor (Compose *compose);
261 static gint compose_exec_ext_editor_real (const gchar *file);
262 static gboolean compose_ext_editor_kill (Compose *compose);
263 static void compose_input_cb (gpointer data,
265 GdkInputCondition condition);
266 static void compose_set_ext_editor_sensitive (Compose *compose,
269 static void compose_undo_state_changed (UndoMain *undostruct,
274 static gint calc_cursor_xpos (GtkSText *text,
278 static void compose_create_header_entry (Compose *compose);
279 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
280 static void compose_update_priority_menu_item(Compose * compose);
282 /* callback functions */
284 static gboolean compose_edit_size_alloc (GtkEditable *widget,
285 GtkAllocation *allocation,
286 GtkSHRuler *shruler);
288 static void toolbar_send_cb (GtkWidget *widget,
290 static void toolbar_send_later_cb (GtkWidget *widget,
292 static void toolbar_draft_cb (GtkWidget *widget,
294 static void toolbar_insert_cb (GtkWidget *widget,
296 static void toolbar_attach_cb (GtkWidget *widget,
298 static void toolbar_sig_cb (GtkWidget *widget,
300 static void toolbar_ext_editor_cb (GtkWidget *widget,
302 static void toolbar_linewrap_cb (GtkWidget *widget,
304 static void toolbar_address_cb (GtkWidget *widget,
307 static void select_account (Compose *compose,
310 static void account_activated (GtkMenuItem *menuitem,
313 static void attach_selected (GtkCList *clist,
318 static void attach_button_pressed (GtkWidget *widget,
319 GdkEventButton *event,
321 static void attach_key_pressed (GtkWidget *widget,
325 static void compose_send_cb (gpointer data,
328 static void compose_send_later_cb (gpointer data,
332 static void compose_draft_cb (gpointer data,
336 static void compose_attach_cb (gpointer data,
339 static void compose_insert_file_cb (gpointer data,
343 static void compose_close_cb (gpointer data,
347 static void compose_address_cb (gpointer data,
350 static void compose_template_activate_cb(GtkWidget *widget,
353 static void compose_ext_editor_cb (gpointer data,
357 static gint compose_delete_cb (GtkWidget *widget,
360 static void compose_destroy_cb (GtkWidget *widget,
363 static void compose_undo_cb (Compose *compose);
364 static void compose_redo_cb (Compose *compose);
365 static void compose_cut_cb (Compose *compose);
366 static void compose_copy_cb (Compose *compose);
367 static void compose_paste_cb (Compose *compose);
368 static void compose_allsel_cb (Compose *compose);
370 static void compose_gtk_stext_action_cb (Compose *compose,
371 ComposeCallGtkSTextAction action);
373 static void compose_grab_focus_cb (GtkWidget *widget,
376 static void compose_changed_cb (GtkEditable *editable,
378 static void compose_button_press_cb (GtkWidget *widget,
379 GdkEventButton *event,
382 static void compose_key_press_cb (GtkWidget *widget,
388 static void compose_toggle_to_cb (gpointer data,
391 static void compose_toggle_cc_cb (gpointer data,
394 static void compose_toggle_bcc_cb (gpointer data,
397 static void compose_toggle_replyto_cb (gpointer data,
400 static void compose_toggle_followupto_cb(gpointer data,
403 static void compose_toggle_attach_cb (gpointer data,
407 static void compose_toggle_ruler_cb (gpointer data,
411 static void compose_toggle_sign_cb (gpointer data,
414 static void compose_toggle_encrypt_cb (gpointer data,
418 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
420 static void compose_set_priority_cb (gpointer data,
424 static void compose_attach_drag_received_cb (GtkWidget *widget,
425 GdkDragContext *drag_context,
428 GtkSelectionData *data,
432 static void compose_insert_drag_received_cb (GtkWidget *widget,
433 GdkDragContext *drag_context,
436 GtkSelectionData *data,
442 static void to_activated (GtkWidget *widget,
444 static void newsgroups_activated (GtkWidget *widget,
446 static void subject_activated (GtkWidget *widget,
448 static void cc_activated (GtkWidget *widget,
450 static void bcc_activated (GtkWidget *widget,
452 static void replyto_activated (GtkWidget *widget,
454 static void followupto_activated (GtkWidget *widget,
458 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
460 gboolean ignore_replyto,
461 gboolean followup_and_reply_to,
464 void compose_headerentry_changed_cb (GtkWidget *entry,
465 ComposeHeaderEntry *headerentry);
466 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
468 ComposeHeaderEntry *headerentry);
470 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
473 static void compose_check_all (Compose *compose);
474 static void compose_highlight_all (Compose *compose);
475 static void compose_check_backwards (Compose *compose);
476 static void compose_check_forwards_go (Compose *compose);
479 static gboolean compose_send_control_enter (Compose *compose);
480 static void text_activated (GtkWidget *widget,
483 static GtkItemFactoryEntry compose_popup_entries[] =
485 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
486 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
487 {N_("/---"), NULL, NULL, 0, "<Separator>"},
488 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
491 static GtkItemFactoryEntry compose_entries[] =
493 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
494 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
495 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
496 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
497 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
498 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
500 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
501 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
502 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
503 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
504 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
505 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
506 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
507 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
508 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
509 {N_("/_Edit/A_dvanced/Move a character backward"),
511 compose_gtk_stext_action_cb,
512 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
514 {N_("/_Edit/A_dvanced/Move a character forward"),
516 compose_gtk_stext_action_cb,
517 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
519 {N_("/_Edit/A_dvanced/Move a word backward"),
521 compose_gtk_stext_action_cb,
522 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
524 {N_("/_Edit/A_dvanced/Move a word forward"),
526 compose_gtk_stext_action_cb,
527 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
529 {N_("/_Edit/A_dvanced/Move to beginning of line"),
530 NULL, /* "<control>A" */
531 compose_gtk_stext_action_cb,
532 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
534 {N_("/_Edit/A_dvanced/Move to end of line"),
536 compose_gtk_stext_action_cb,
537 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
539 {N_("/_Edit/A_dvanced/Move to previous line"),
541 compose_gtk_stext_action_cb,
542 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
544 {N_("/_Edit/A_dvanced/Move to next line"),
546 compose_gtk_stext_action_cb,
547 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
549 {N_("/_Edit/A_dvanced/Delete a character backward"),
551 compose_gtk_stext_action_cb,
552 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
554 {N_("/_Edit/A_dvanced/Delete a character forward"),
556 compose_gtk_stext_action_cb,
557 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
559 {N_("/_Edit/A_dvanced/Delete a word backward"),
560 NULL, /* "<control>W" */
561 compose_gtk_stext_action_cb,
562 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
564 {N_("/_Edit/A_dvanced/Delete a word forward"),
565 NULL, /* "<alt>D", */
566 compose_gtk_stext_action_cb,
567 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
569 {N_("/_Edit/A_dvanced/Delete line"),
571 compose_gtk_stext_action_cb,
572 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
574 {N_("/_Edit/A_dvanced/Delete entire line"),
576 compose_gtk_stext_action_cb,
577 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
579 {N_("/_Edit/A_dvanced/Delete to end of line"),
581 compose_gtk_stext_action_cb,
582 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
584 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
585 {N_("/_Edit/_Wrap current paragraph"),
586 "<control>L", compose_wrap_line, 0, NULL},
587 {N_("/_Edit/Wrap all long _lines"),
588 "<control><alt>L", compose_wrap_line_all, 0, NULL},
589 {N_("/_Edit/Edit with e_xternal editor"),
590 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
592 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
593 {N_("/_Spelling/_Check all or check selection"),
594 NULL, compose_check_all, 0, NULL},
595 {N_("/_Spelling/_Highlight all misspelled words"),
596 NULL, compose_highlight_all, 0, NULL},
597 {N_("/_Spelling/Check _backwards misspelled word"),
598 NULL, compose_check_backwards , 0, NULL},
599 {N_("/_Spelling/_Forward to next misspelled word"),
600 NULL, compose_check_forwards_go, 0, NULL},
601 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
602 {N_("/_Spelling/_Spelling Configuration"),
603 NULL, NULL, 0, "<Branch>"},
605 #if 0 /* NEW COMPOSE GUI */
606 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
607 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
608 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
609 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
610 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
611 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
612 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
613 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
614 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
615 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
616 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
618 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
619 {N_("/_Message/_Send"), "<control>Return",
620 compose_send_cb, 0, NULL},
621 {N_("/_Message/Send _later"), "<shift><control>S",
622 compose_send_later_cb, 0, NULL},
623 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
624 {N_("/_Message/Save to _draft folder"),
625 "<shift><control>D", compose_draft_cb, 0, NULL},
626 {N_("/_Message/Save and _keep editing"),
627 "<control>S", compose_draft_cb, 1, NULL},
628 #if 0 /* NEW COMPOSE GUI */
629 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
630 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
631 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
632 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
633 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
634 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
635 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
636 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
637 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
640 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
641 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
642 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
643 #endif /* USE_GPGME */
644 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
645 {N_("/_Message/Priority"), NULL, NULL, 0, "<Branch>"},
646 {N_("/_Message/Priority/Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
647 {N_("/_Message/Priority/High"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
648 {N_("/_Message/Priority/Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
649 {N_("/_Message/Priority/Low"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
650 {N_("/_Message/Priority/Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
651 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
652 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
653 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
654 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
655 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
656 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
657 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
658 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
659 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
662 static GtkTargetEntry compose_mime_types[] =
664 {"text/uri-list", 0, 0}
667 Compose *compose_new(PrefsAccount *account)
669 return compose_generic_new(account, NULL, NULL);
672 Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
676 GtkItemFactory *ifactory;
678 c = compose_generic_new(account, NULL, NULL);
680 filename = procmsg_get_message_file(msginfo);
681 if (filename == NULL)
684 c->bounce_filename = filename;
686 if (msginfo->subject)
687 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
689 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
691 compose_quote_fmt(c, msginfo, "%M", NULL, NULL);
692 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
694 ifactory = gtk_item_factory_from_widget(c->popupmenu);
695 menu_set_sensitive(ifactory, "/Add...", FALSE);
696 menu_set_sensitive(ifactory, "/Remove", FALSE);
697 menu_set_sensitive(ifactory, "/Property...", FALSE);
699 ifactory = gtk_item_factory_from_widget(c->menubar);
700 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
701 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
702 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
703 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
704 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
705 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
706 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
707 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
709 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
710 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
712 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
713 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
715 gtk_widget_set_sensitive(c->insert_btn, FALSE);
716 gtk_widget_set_sensitive(c->attach_btn, FALSE);
717 gtk_widget_set_sensitive(c->sig_btn, FALSE);
718 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
719 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
724 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
726 return compose_generic_new(account, mailto, NULL);
729 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
731 return compose_generic_new(account, NULL, item);
734 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
738 if (item && item->prefs && item->prefs->enable_default_account)
739 account = account_find_from_id(item->prefs->default_account);
741 if (!account) account = cur_account;
742 g_return_val_if_fail(account != NULL, NULL);
744 compose = compose_create(account, COMPOSE_NEW);
745 compose->replyinfo = NULL;
747 if (prefs_common.auto_sig)
748 compose_insert_sig(compose);
749 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
750 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
752 if (account->protocol != A_NNTP) {
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);
759 if (item && item->ret_rcpt) {
760 GtkItemFactory *ifactory;
762 ifactory = gtk_item_factory_from_widget(compose->menubar);
763 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
767 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
770 compose_show_first_last_header(compose, TRUE);
772 /* Set save folder */
773 if(item && item->prefs && item->prefs->save_copy_to_folder) {
774 gchar *folderidentifier;
776 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
777 folderidentifier = folder_item_get_identifier(item);
778 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
779 g_free(folderidentifier);
782 gtk_widget_grab_focus(compose->header_last->entry);
784 if (prefs_common.auto_exteditor)
785 compose_exec_ext_editor(compose);
790 #define CHANGE_FLAGS(msginfo) \
792 if (msginfo->folder->folder->change_flags != NULL) \
793 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
799 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
800 const gchar *followupto, gchar * to)
804 if (!account) account = cur_account;
805 g_return_val_if_fail(account != NULL, NULL);
806 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
808 compose = compose_create(account, COMPOSE_NEW);
810 if (prefs_common.auto_sig)
811 compose_insert_sig(compose);
812 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
813 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
815 compose_entry_append(compose, to, COMPOSE_TO);
816 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
817 gtk_widget_grab_focus(compose->subject_entry);
823 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
824 gboolean ignore_replyto, const gchar *body)
826 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE,
830 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
832 gboolean ignore_replyto,
835 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE,
839 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
841 gboolean ignore_replyto,
842 gboolean followup_and_reply_to,
846 PrefsAccount *account;
847 PrefsAccount *reply_account;
850 g_return_if_fail(msginfo != NULL);
851 g_return_if_fail(msginfo->folder != NULL);
854 /* select the account set in folderitem's property (if enabled) */
855 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
856 account = account_find_from_id(msginfo->folder->prefs->default_account);
858 /* select the account for the whole folder (IMAP / NNTP) */
860 /* FIXME: this is not right, because folder may be nested. we should
861 * ascend the tree until we find a parent with proper account
863 account = msginfo->folder->folder->account;
865 /* select account by to: and cc: header if enabled */
866 if (prefs_common.reply_account_autosel) {
867 if (!account && msginfo->to) {
869 Xstrdup_a(to, msginfo->to, return);
871 account = account_find_from_address(to);
875 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
877 account = account_find_from_address(cc);
882 /* select current account */
883 if (!account) account = cur_account;
884 g_return_if_fail(account != NULL);
886 if (ignore_replyto && account->protocol == A_NNTP &&
887 !followup_and_reply_to) {
889 account_find_from_address(account->address);
891 reply_account = compose_current_mail_account();
895 reply_account = account;
897 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
898 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
899 if (MSG_IS_IMAP(msginfo->flags))
900 imap_msg_set_perm_flags(msginfo, MSG_REPLIED);
901 CHANGE_FLAGS(msginfo);
903 compose = compose_create(account, COMPOSE_REPLY);
904 compose->replyinfo = procmsg_msginfo_copy(msginfo);
906 #if 0 /* NEW COMPOSE GUI */
907 if (followup_and_reply_to) {
908 gtk_widget_show(compose->to_hbox);
909 gtk_widget_show(compose->to_entry);
910 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
911 compose->use_to = TRUE;
914 if (msginfo->folder && msginfo->folder->ret_rcpt) {
915 GtkItemFactory *ifactory;
917 ifactory = gtk_item_factory_from_widget(compose->menubar);
918 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
921 /* Set save folder */
922 if(msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
923 gchar *folderidentifier;
925 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
926 folderidentifier = folder_item_get_identifier(msginfo->folder);
927 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
928 g_free(folderidentifier);
931 if (compose_parse_header(compose, msginfo) < 0) return;
932 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
933 followup_and_reply_to);
934 compose_show_first_last_header(compose, TRUE);
936 text = GTK_STEXT(compose->text);
937 gtk_stext_freeze(text);
943 if (prefs_common.quotemark && *prefs_common.quotemark)
944 qmark = prefs_common.quotemark;
948 quote_str = compose_quote_fmt(compose, msginfo,
949 prefs_common.quotefmt,
953 if (prefs_common.auto_sig)
954 compose_insert_sig(compose);
956 if (quote && prefs_common.linewrap_quote)
957 compose_wrap_line_all(compose);
959 gtk_editable_set_position(GTK_EDITABLE(text), 0);
960 gtk_stext_set_point(text, 0);
962 gtk_stext_thaw(text);
963 gtk_widget_grab_focus(compose->text);
965 if (prefs_common.auto_exteditor)
966 compose_exec_ext_editor(compose);
969 static void set_toolbar_style(Compose *compose);
971 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
976 g_return_val_if_fail(mimeinfo != NULL, NULL);
978 base = mimeinfo->filename ? mimeinfo->filename
979 : mimeinfo->name ? mimeinfo->name : NULL;
981 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
982 filename = g_strdup_printf("%s%smimetmp.%08x.html",
989 base = base ? base : "";
990 base = g_basename(base);
992 filename = g_strdup_printf("%s%smimetmp.%08x",
1000 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
1006 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
1010 if (!partinfo) return NULL;
1012 filename = procmime_get_file_name(partinfo);
1014 if (procmime_get_part(filename, source, partinfo) < 0)
1016 (_("Can't get the part of multipart message."));
1023 #define INSERT_FW_HEADER(var, hdr) \
1024 if (msginfo->var && *msginfo->var) { \
1025 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1026 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1027 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1030 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1031 gboolean as_attach, const gchar *body)
1034 /* PrefsAccount *account; */
1037 g_return_val_if_fail(msginfo != NULL, NULL);
1038 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1040 account = msginfo->folder->folder->account;
1041 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1043 Xstrdup_a(to, msginfo->to, return NULL);
1044 extract_address(to);
1045 account = account_find_from_address(to);
1048 if(!account && prefs_common.forward_account_autosel) {
1050 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1051 extract_address(cc);
1052 account = account_find_from_address(cc);
1056 if (account == NULL) {
1057 account = cur_account;
1059 account = msginfo->folder->folder->account;
1060 if (!account) account = cur_account;
1063 g_return_val_if_fail(account != NULL, NULL);
1065 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1066 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1067 if (MSG_IS_IMAP(msginfo->flags))
1068 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1069 CHANGE_FLAGS(msginfo);
1071 compose = compose_create(account, COMPOSE_FORWARD);
1073 if (msginfo->subject && *msginfo->subject) {
1074 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1075 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1079 text = GTK_STEXT(compose->text);
1080 gtk_stext_freeze(text);
1086 msgfile = procmsg_get_message_file_path(msginfo);
1087 if (!is_file_exist(msgfile))
1088 g_warning(_("%s: file not exist\n"), msgfile);
1090 compose_attach_append(compose, msgfile, msgfile,
1098 if (prefs_common.fw_quotemark &&
1099 *prefs_common.fw_quotemark)
1100 qmark = prefs_common.fw_quotemark;
1104 quote_str = compose_quote_fmt(compose, msginfo,
1105 prefs_common.fw_quotefmt,
1107 compose_attach_parts(compose, msginfo);
1110 if (prefs_common.auto_sig)
1111 compose_insert_sig(compose);
1113 if (prefs_common.linewrap_quote)
1114 compose_wrap_line_all(compose);
1116 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1117 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1119 gtk_stext_thaw(text);
1120 #if 0 /* NEW COMPOSE GUI */
1121 if (account->protocol != A_NNTP)
1122 gtk_widget_grab_focus(compose->to_entry);
1124 gtk_widget_grab_focus(compose->newsgroups_entry);
1126 gtk_widget_grab_focus(compose->header_last->entry);
1128 if (prefs_common.auto_exteditor)
1129 compose_exec_ext_editor(compose);
1134 #undef INSERT_FW_HEADER
1136 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1143 g_return_val_if_fail(msginfo_list != NULL, NULL);
1145 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1146 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1150 if (account == NULL) {
1151 account = cur_account;
1153 account = msginfo->folder->folder->account;
1154 if (!account) account = cur_account;
1157 g_return_val_if_fail(account != NULL, NULL);
1159 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1160 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1161 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1162 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1165 compose = compose_create(account, COMPOSE_FORWARD);
1167 text = GTK_STEXT(compose->text);
1168 gtk_stext_freeze(text);
1170 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1171 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1172 if (!is_file_exist(msgfile))
1173 g_warning(_("%s: file not exist\n"), msgfile);
1175 compose_attach_append(compose, msgfile, msgfile,
1180 if (prefs_common.auto_sig)
1181 compose_insert_sig(compose);
1183 if (prefs_common.linewrap_quote)
1184 compose_wrap_line_all(compose);
1186 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1187 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1189 gtk_stext_thaw(text);
1190 #if 0 /* NEW COMPOSE GUI */
1191 if (account->protocol != A_NNTP)
1192 gtk_widget_grab_focus(compose->to_entry);
1194 gtk_widget_grab_focus(compose->newsgroups_entry);
1200 void compose_reedit(MsgInfo *msginfo)
1203 PrefsAccount *account = NULL;
1206 gchar buf[BUFFSIZE];
1208 g_return_if_fail(msginfo != NULL);
1209 g_return_if_fail(msginfo->folder != NULL);
1211 if (msginfo->folder->stype == F_QUEUE) {
1212 gchar queueheader_buf[BUFFSIZE];
1215 /* Select Account from queue headers */
1216 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1217 sizeof(queueheader_buf), "NAID:")) {
1218 id = atoi(&queueheader_buf[5]);
1219 account = account_find_from_id(id);
1221 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1222 sizeof(queueheader_buf), "MAID:")) {
1223 id = atoi(&queueheader_buf[5]);
1224 account = account_find_from_id(id);
1226 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1227 sizeof(queueheader_buf), "S:")) {
1228 account = account_find_from_address(queueheader_buf);
1231 account = msginfo->folder->folder->account;
1233 if (!account && prefs_common.reedit_account_autosel) {
1234 gchar from[BUFFSIZE];
1235 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1236 extract_address(from);
1237 account = account_find_from_address(from);
1240 if (!account) account = cur_account;
1241 g_return_if_fail(account != NULL);
1243 compose = compose_create(account, COMPOSE_REEDIT);
1244 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1246 if (msginfo->folder->stype == F_QUEUE) {
1247 gchar queueheader_buf[BUFFSIZE];
1249 /* Set message save folder */
1250 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1253 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1254 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1255 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1259 if (compose_parse_header(compose, msginfo) < 0) return;
1260 compose_reedit_set_entry(compose, msginfo);
1262 text = GTK_STEXT(compose->text);
1263 gtk_stext_freeze(text);
1265 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1266 g_warning(_("Can't get text part\n"));
1268 while (fgets(buf, sizeof(buf), fp) != NULL)
1269 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1272 compose_attach_parts(compose, msginfo);
1274 gtk_stext_thaw(text);
1275 gtk_widget_grab_focus(compose->text);
1277 if (prefs_common.auto_exteditor)
1278 compose_exec_ext_editor(compose);
1281 GList *compose_get_compose_list(void)
1283 return compose_list;
1286 void compose_entry_append(Compose *compose, const gchar *address,
1287 ComposeEntryType type)
1293 if (!address || *address == '\0') return;
1295 #if 0 /* NEW COMPOSE GUI */
1298 entry = GTK_ENTRY(compose->cc_entry);
1301 entry = GTK_ENTRY(compose->bcc_entry);
1303 case COMPOSE_NEWSGROUPS:
1304 entry = GTK_ENTRY(compose->newsgroups_entry);
1308 entry = GTK_ENTRY(compose->to_entry);
1312 text = gtk_entry_get_text(entry);
1314 gtk_entry_append_text(entry, ", ");
1315 gtk_entry_append_text(entry, address);
1323 header = N_("Bcc:");
1325 case COMPOSE_REPLYTO:
1326 header = N_("Reply-To:");
1328 case COMPOSE_NEWSGROUPS:
1329 header = N_("Newsgroups:");
1331 case COMPOSE_FOLLOWUPTO:
1332 header = N_( "Followup-To:");
1339 header = prefs_common.trans_hdr ? gettext(header) : header;
1341 compose_add_header_entry(compose, header, (gchar *)address);
1344 static void compose_entries_set(Compose *compose, const gchar *mailto)
1346 gchar *subject = NULL;
1354 Xstrdup_a(tmp_mailto, mailto, return);
1358 p = strchr(tmp_mailto, '?');
1365 gchar *field, *value;
1382 if (*value == '\0') continue;
1384 if (!g_strcasecmp(field, "subject")) {
1385 Xalloca(subject, strlen(value) + 1, return);
1386 decode_uri(subject, value);
1387 } else if (!g_strcasecmp(field, "cc")) {
1389 } else if (!g_strcasecmp(field, "bcc")) {
1391 } else if (!g_strcasecmp(field, "body")) {
1392 Xalloca(body, strlen(value) + 1, return);
1393 decode_uri(body, value);
1398 compose_entry_append(compose, to, COMPOSE_TO);
1400 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1402 compose_entry_append(compose, cc, COMPOSE_CC);
1404 compose_entry_append(compose, bcc, COMPOSE_BCC);
1406 gtk_stext_insert(GTK_STEXT(compose->text),
1407 NULL, NULL, NULL, body, -1);
1408 gtk_stext_insert(GTK_STEXT(compose->text),
1409 NULL, NULL, NULL, "\n", 1);
1413 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1415 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1416 {"Cc:", NULL, FALSE},
1417 {"References:", NULL, FALSE},
1418 {"Bcc:", NULL, FALSE},
1419 {"Newsgroups:", NULL, FALSE},
1420 {"Followup-To:", NULL, FALSE},
1421 {"X-Mailing-List:", NULL, FALSE},
1422 {"X-BeenThere:", NULL, FALSE},
1423 {"X-Priority:", NULL, FALSE},
1424 {NULL, NULL, FALSE}};
1434 H_X_MAILING_LIST = 6,
1441 g_return_val_if_fail(msginfo != NULL, -1);
1443 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1444 procheader_get_header_fields(fp, hentry);
1447 if (hentry[H_REPLY_TO].body != NULL) {
1448 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1449 compose->replyto = hentry[H_REPLY_TO].body;
1450 hentry[H_REPLY_TO].body = NULL;
1452 if (hentry[H_CC].body != NULL) {
1453 conv_unmime_header_overwrite(hentry[H_CC].body);
1454 compose->cc = hentry[H_CC].body;
1455 hentry[H_CC].body = NULL;
1457 if (hentry[H_X_MAILING_LIST].body != NULL) {
1458 /* this is good enough to parse debian-devel */
1459 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1460 g_return_val_if_fail(buf != NULL, -1 );
1461 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1462 compose->mailinglist = g_strdup(buf);
1464 g_free(hentry[H_X_MAILING_LIST].body);
1465 hentry[H_X_MAILING_LIST].body = NULL ;
1467 if (hentry[H_X_BEENTHERE].body != NULL) {
1468 /* this is good enough to parse the sylpheed-claws lists */
1469 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1470 g_return_val_if_fail(buf != NULL, -1 );
1471 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1472 compose->mailinglist = g_strdup(buf);
1474 g_free(hentry[H_X_BEENTHERE].body);
1475 hentry[H_X_BEENTHERE].body = NULL ;
1477 if (hentry[H_REFERENCES].body != NULL) {
1478 if (compose->mode == COMPOSE_REEDIT)
1479 compose->references = hentry[H_REFERENCES].body;
1481 compose->references = compose_parse_references
1482 (hentry[H_REFERENCES].body, msginfo->msgid);
1483 g_free(hentry[H_REFERENCES].body);
1485 hentry[H_REFERENCES].body = NULL;
1487 if (hentry[H_BCC].body != NULL) {
1488 if (compose->mode == COMPOSE_REEDIT) {
1489 conv_unmime_header_overwrite(hentry[H_BCC].body);
1490 compose->bcc = hentry[H_BCC].body;
1492 g_free(hentry[H_BCC].body);
1493 hentry[H_BCC].body = NULL;
1495 if (hentry[H_NEWSGROUPS].body != NULL) {
1496 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1497 hentry[H_NEWSGROUPS].body = NULL;
1499 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1500 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1501 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1502 hentry[H_FOLLOWUP_TO].body = NULL;
1505 if (compose->mode == COMPOSE_REEDIT)
1506 if (hentry[H_X_PRIORITY].body != NULL) {
1509 priority = atoi(hentry[H_X_PRIORITY].body);
1510 g_free(hentry[H_X_PRIORITY].body);
1512 hentry[H_X_PRIORITY].body = NULL;
1514 if (priority < PRIORITY_HIGHEST ||
1515 priority > PRIORITY_LOWEST)
1516 priority = PRIORITY_NORMAL;
1518 compose->priority = priority;
1521 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1522 compose->inreplyto = g_strdup(msginfo->inreplyto);
1523 else if (compose->mode != COMPOSE_REEDIT &&
1524 msginfo->msgid && *msginfo->msgid) {
1525 compose->inreplyto = g_strdup(msginfo->msgid);
1527 if (!compose->references) {
1528 if (msginfo->inreplyto && *msginfo->inreplyto)
1529 compose->references =
1530 g_strdup_printf("<%s>\n\t<%s>",
1534 compose->references =
1535 g_strconcat("<", msginfo->msgid, ">",
1543 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1545 GSList *ref_id_list, *cur;
1549 ref_id_list = references_list_append(NULL, ref);
1550 if (!ref_id_list) return NULL;
1551 if (msgid && *msgid)
1552 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1557 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1558 /* "<" + Message-ID + ">" + CR+LF+TAB */
1559 len += strlen((gchar *)cur->data) + 5;
1561 if (len > MAX_REFERENCES_LEN) {
1562 /* remove second message-ID */
1563 if (ref_id_list && ref_id_list->next &&
1564 ref_id_list->next->next) {
1565 g_free(ref_id_list->next->data);
1566 ref_id_list = g_slist_remove
1567 (ref_id_list, ref_id_list->next->data);
1569 slist_free_strings(ref_id_list);
1570 g_slist_free(ref_id_list);
1577 new_ref = g_string_new("");
1578 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1579 if (new_ref->len > 0)
1580 g_string_append(new_ref, "\n\t");
1581 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1584 slist_free_strings(ref_id_list);
1585 g_slist_free(ref_id_list);
1587 new_ref_str = new_ref->str;
1588 g_string_free(new_ref, FALSE);
1593 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1594 const gchar *fmt, const gchar *qmark,
1597 GtkSText *text = GTK_STEXT(compose->text);
1598 gchar *quote_str = NULL;
1603 if (qmark != NULL) {
1604 quote_fmt_init(msginfo, NULL, NULL);
1605 quote_fmt_scan_string(qmark);
1608 buf = quote_fmt_get_buffer();
1610 alertpanel_error(_("Quote mark format error."));
1612 Xstrdup_a(quote_str, buf, return NULL)
1615 if (fmt && *fmt != '\0') {
1616 quote_fmt_init(msginfo, quote_str, body);
1617 quote_fmt_scan_string(fmt);
1620 buf = quote_fmt_get_buffer();
1622 alertpanel_error(_("Message reply/forward format error."));
1628 gtk_stext_freeze(text);
1630 for (p = buf; *p != '\0'; ) {
1631 lastp = strchr(p, '\n');
1632 len = lastp ? lastp - p + 1 : -1;
1633 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1640 gtk_stext_thaw(text);
1645 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1646 gboolean to_all, gboolean ignore_replyto,
1647 gboolean followup_and_reply_to)
1649 GSList *cc_list = NULL;
1652 gchar *replyto = NULL;
1653 GHashTable *to_table;
1655 g_return_if_fail(compose->account != NULL);
1656 g_return_if_fail(msginfo != NULL);
1658 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1659 compose_entry_append(compose,
1660 ((compose->replyto && !ignore_replyto)
1662 : (compose->mailinglist && !ignore_replyto)
1663 ? compose->mailinglist
1664 : msginfo->from ? msginfo->from : ""),
1667 if (compose->account->protocol == A_NNTP) {
1669 compose_entry_append
1670 (compose, msginfo->from ? msginfo->from : "",
1673 compose_entry_append
1675 compose->followup_to ? compose->followup_to
1676 : compose->newsgroups ? compose->newsgroups
1678 COMPOSE_NEWSGROUPS);
1681 if (msginfo->subject && *msginfo->subject) {
1682 gchar *buf, *buf2, *p;
1684 buf = g_strdup(msginfo->subject);
1685 while (!strncasecmp(buf, "Re:", 3)) {
1687 while (isspace(*p)) p++;
1688 memmove(buf, p, strlen(p) + 1);
1691 buf2 = g_strdup_printf("Re: %s", buf);
1692 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1696 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1698 if (!to_all || compose->account->protocol == A_NNTP) return;
1700 if (compose->replyto) {
1701 Xstrdup_a(replyto, compose->replyto, return);
1702 extract_address(replyto);
1704 if (msginfo->from) {
1705 Xstrdup_a(from, msginfo->from, return);
1706 extract_address(from);
1709 if (compose->mailinglist && from) {
1710 cc_list = address_list_append(cc_list, from);
1713 if (replyto && from)
1714 cc_list = address_list_append(cc_list, from);
1716 if (!compose->mailinglist)
1717 cc_list = address_list_append(cc_list, msginfo->to);
1719 cc_list = address_list_append(cc_list, compose->cc);
1721 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1723 g_hash_table_insert(to_table, replyto, GINT_TO_POINTER(1));
1724 if (compose->account)
1725 g_hash_table_insert(to_table, compose->account->address,
1726 GINT_TO_POINTER(1));
1728 /* remove address on To: and that of current account */
1729 for (cur = cc_list; cur != NULL; ) {
1730 GSList *next = cur->next;
1732 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1733 cc_list = g_slist_remove(cc_list, cur->data);
1735 g_hash_table_insert(to_table, cur->data, cur);
1739 g_hash_table_destroy(to_table);
1742 for (cur = cc_list; cur != NULL; cur = cur->next)
1743 compose_entry_append(compose, (gchar *)cur->data,
1745 slist_free_strings(cc_list);
1746 g_slist_free(cc_list);
1750 #define SET_ENTRY(entry, str) \
1753 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1756 #define SET_ADDRESS(type, str) \
1759 compose_entry_append(compose, str, type); \
1762 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1764 g_return_if_fail(msginfo != NULL);
1766 SET_ENTRY(subject_entry, msginfo->subject);
1767 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1768 SET_ADDRESS(COMPOSE_CC, compose->cc);
1769 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1770 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1772 compose_update_priority_menu_item(compose);
1774 compose_show_first_last_header(compose, TRUE);
1776 #if 0 /* NEW COMPOSE GUI */
1778 GtkItemFactory *ifactory;
1779 GtkWidget *menuitem;
1781 ifactory = gtk_item_factory_from_widget(compose->menubar);
1782 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1783 gtk_check_menu_item_set_active
1784 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1786 if (compose->replyto) {
1787 GtkItemFactory *ifactory;
1788 GtkWidget *menuitem;
1790 ifactory = gtk_item_factory_from_widget(compose->menubar);
1791 menuitem = gtk_item_factory_get_item
1792 (ifactory, "/View/Reply to");
1793 gtk_check_menu_item_set_active
1794 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1802 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1809 size_t buf_len = 128;
1811 if (strlen(sigfile) < 2)
1814 sigprg = popen(sigfile+1, "r");
1817 buf = g_malloc(buf_len);
1820 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1821 "Unable to insert signature (malloc failed)\n", -1);
1827 while (!feof(sigprg)) {
1828 bzero(buf, buf_len);
1829 fread(buf, buf_len-1, 1, sigprg);
1830 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1838 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1839 "Can't exec file: ", -1);
1840 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1845 static void compose_insert_sig(Compose *compose)
1849 if (compose->account && compose->account->sig_path)
1850 sigfile = g_strdup(compose->account->sig_path);
1852 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1853 DEFAULT_SIGNATURE, NULL);
1855 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1860 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1861 if (prefs_common.sig_sep) {
1862 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1863 prefs_common.sig_sep, -1);
1864 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1868 if (sigfile[0] == '|')
1869 compose_exec_sig(compose, sigfile);
1871 compose_insert_file(compose, sigfile);
1875 static void compose_insert_file(Compose *compose, const gchar *file)
1877 GtkSText *text = GTK_STEXT(compose->text);
1878 gchar buf[BUFFSIZE];
1882 g_return_if_fail(file != NULL);
1884 if ((fp = fopen(file, "rb")) == NULL) {
1885 FILE_OP_ERROR(file, "fopen");
1889 gtk_stext_freeze(text);
1891 while (fgets(buf, sizeof(buf), fp) != NULL) {
1892 /* strip <CR> if DOS/Windows file,
1893 replace <CR> with <LF> if Macintosh file. */
1896 if (len > 0 && buf[len - 1] != '\n') {
1898 if (buf[len] == '\r') buf[len] = '\n';
1900 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1903 gtk_stext_thaw(text);
1908 static void compose_attach_append(Compose *compose, const gchar *file,
1909 const gchar *filename,
1910 const gchar *content_type)
1913 gchar *text[N_ATTACH_COLS];
1918 if (!is_file_exist(file)) {
1919 g_warning(_("File %s doesn't exist\n"), file);
1922 if ((size = get_file_size(file)) < 0) {
1923 g_warning(_("Can't get file size of %s\n"), file);
1927 alertpanel_notice(_("File %s is empty."), file);
1930 if ((fp = fopen(file, "rb")) == NULL) {
1931 alertpanel_error(_("Can't read %s."), file);
1936 #if 0 /* NEW COMPOSE GUI */
1937 if (!compose->use_attach) {
1938 GtkItemFactory *ifactory;
1939 GtkWidget *menuitem;
1941 ifactory = gtk_item_factory_from_widget(compose->menubar);
1942 menuitem = gtk_item_factory_get_item(ifactory,
1943 "/View/Attachment");
1944 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1948 ainfo = g_new0(AttachInfo, 1);
1949 ainfo->file = g_strdup(file);
1952 ainfo->content_type = g_strdup(content_type);
1953 if (!strcasecmp(content_type, "message/rfc822")) {
1954 ainfo->encoding = ENC_7BIT;
1955 ainfo->name = g_strdup_printf
1957 g_basename(filename ? filename : file));
1959 ainfo->encoding = ENC_BASE64;
1960 ainfo->name = g_strdup
1961 (g_basename(filename ? filename : file));
1964 ainfo->content_type = procmime_get_mime_type(file);
1965 if (!ainfo->content_type)
1966 ainfo->content_type =
1967 g_strdup("application/octet-stream");
1968 ainfo->encoding = ENC_BASE64;
1969 ainfo->name = g_strdup(g_basename(filename ? filename : file));
1973 text[COL_MIMETYPE] = ainfo->content_type;
1974 text[COL_SIZE] = to_human_readable(size);
1975 text[COL_NAME] = ainfo->name;
1977 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1978 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1981 #define IS_FIRST_PART_TEXT(info) \
1982 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
1983 info->mime_type == MIME_TEXT_ENRICHED) || \
1984 (info->mime_type == MIME_MULTIPART && info->content_type && \
1985 !strcasecmp(info->content_type, "multipart/alternative") && \
1986 (info->children && \
1987 (info->children->mime_type == MIME_TEXT || \
1988 info->children->mime_type == MIME_TEXT_HTML || \
1989 info->children->mime_type == MIME_TEXT_ENRICHED))))
1991 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
1998 mimeinfo = procmime_scan_message(msginfo);
1999 if (!mimeinfo) return;
2001 /* skip first text (presumably message body) */
2002 child = mimeinfo->children;
2003 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
2004 procmime_mimeinfo_free_all(mimeinfo);
2007 if (IS_FIRST_PART_TEXT(child))
2008 child = child->next;
2010 infile = procmsg_get_message_file_path(msginfo);
2012 while (child != NULL) {
2013 if (child->children || child->mime_type == MIME_MULTIPART) {
2014 child = procmime_mimeinfo_next(child);
2018 outfile = procmime_get_tmp_file_name(child);
2019 if (procmime_get_part(outfile, infile, child) < 0)
2020 g_warning(_("Can't get the part of multipart message."));
2022 compose_attach_append
2024 child->filename ? child->filename : child->name,
2025 child->content_type);
2027 child = child->next;
2031 procmime_mimeinfo_free_all(mimeinfo);
2034 #undef IS_FIRST_PART_TEXT
2036 #define GET_CHAR(pos, buf, len) \
2038 if (text->use_wchar) \
2039 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2041 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2046 #define INDENT_CHARS ">|#"
2047 #define SPACE_CHARS " \t"
2049 static void compose_wrap_line(Compose *compose)
2051 GtkSText *text = GTK_STEXT(compose->text);
2052 gint ch_len, last_ch_len;
2053 gchar cbuf[MB_LEN_MAX], last_ch;
2057 gint p_start, p_end;
2058 gint line_pos, cur_pos;
2059 gint line_len, cur_len;
2061 gtk_stext_freeze(text);
2063 text_len = gtk_stext_get_length(text);
2065 /* check to see if the point is on the paragraph mark (empty line). */
2066 cur_pos = gtk_stext_get_point(text);
2067 GET_CHAR(cur_pos, cbuf, ch_len);
2068 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2070 goto compose_end; /* on the paragraph mark */
2071 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2072 if (ch_len == 1 && *cbuf == '\n')
2073 goto compose_end; /* on the paragraph mark */
2076 /* find paragraph start. */
2077 line_end = quoted = 0;
2078 for (p_start = cur_pos; p_start >= 0; --p_start) {
2079 GET_CHAR(p_start, cbuf, ch_len);
2080 if (ch_len == 1 && *cbuf == '\n') {
2082 goto compose_end; /* quoted part */
2090 && strchr(prefs_common.quote_chars, *cbuf))
2092 else if (ch_len != 1 || !isspace(*cbuf))
2101 /* find paragraph end. */
2103 for (p_end = cur_pos; p_end < text_len; p_end++) {
2104 GET_CHAR(p_end, cbuf, ch_len);
2105 if (ch_len == 1 && *cbuf == '\n') {
2112 if (line_end && ch_len == 1 &&
2113 strchr(prefs_common.quote_chars, *cbuf))
2114 goto compose_end; /* quoted part */
2119 if (p_end >= text_len)
2122 if (p_start >= p_end)
2125 line_len = cur_len = 0;
2129 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2132 GET_CHAR(cur_pos, cbuf, ch_len);
2139 if (ch_len == 1 && isspace(*cbuf))
2142 if (ch_len == 1 && *cbuf == '\n') {
2144 if (last_ch_len == 1 && !isspace(last_ch)) {
2145 if (cur_pos + 1 < p_end) {
2146 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2147 if (ch_len == 1 && !isspace(*cbuf))
2151 gtk_stext_set_point(text, cur_pos + 1);
2152 gtk_stext_backward_delete(text, 1);
2154 gtk_stext_set_point(text, cur_pos);
2155 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2165 last_ch_len = ch_len;
2169 line_pos = cur_pos + 1;
2170 line_len = cur_len + ch_len;
2173 if (cur_len + ch_len > prefs_common.linewrap_len &&
2177 GET_CHAR(line_pos - 1, cbuf, ch_len);
2178 if (ch_len == 1 && isspace(*cbuf)) {
2179 gtk_stext_set_point(text, line_pos);
2180 gtk_stext_backward_delete(text, 1);
2189 gtk_stext_set_point(text, line_pos);
2190 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2194 cur_len = cur_len - line_len + ch_len;
2200 line_pos = cur_pos + 1;
2201 line_len = cur_len + ch_len;
2207 gtk_stext_thaw(text);
2212 /* Darko: used when I debug wrapping */
2213 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2218 printf("%d [", pos);
2219 for (i = pos; i < tlen; i++) {
2220 ch = GTK_STEXT_INDEX(text, i);
2221 if (breakoncr && ch == '\n')
2231 WAIT_FOR_INDENT_CHAR,
2232 WAIT_FOR_INDENT_CHAR_OR_SPACE
2235 /* return indent length, we allow:
2236 > followed by spaces/tabs
2237 | followed by spaces/tabs
2238 uppercase characters immediately followed by >,
2239 and the repeating sequences of the above */
2240 /* return indent length */
2241 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2244 guint i, ch_len, alnum_cnt = 0;
2245 IndentState state = WAIT_FOR_INDENT_CHAR;
2246 gchar cbuf[MB_LEN_MAX];
2250 for (i = start_pos; i < text_len; i++) {
2251 GET_CHAR(i, cbuf, ch_len);
2255 if (cbuf[0] == '\n')
2258 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2259 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2262 case WAIT_FOR_SPACE:
2263 if (is_space == FALSE)
2265 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2267 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2268 if (is_indent == FALSE && is_space == FALSE &&
2271 if (is_space == TRUE) {
2273 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2274 } else if (is_indent == TRUE) {
2276 state = WAIT_FOR_SPACE;
2279 state = WAIT_FOR_INDENT_CHAR;
2282 case WAIT_FOR_INDENT_CHAR:
2283 if (is_indent == FALSE && !isupper(cbuf[0]))
2285 if (is_indent == TRUE) {
2287 && !strchr(prefs_common.quote_chars, cbuf[0]))
2290 state = WAIT_FOR_SPACE;
2301 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2307 /* insert quotation string when line was wrapped */
2308 static guint ins_quote(GtkSText *text, guint indent_len,
2309 guint prev_line_pos, guint text_len,
2316 for (i = 0; i < indent_len; i++) {
2317 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2318 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2320 ins_len = indent_len;
2326 /* check if we should join the next line */
2327 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2330 guint indent_len, ch_len;
2331 gboolean do_join = FALSE;
2332 gchar cbuf[MB_LEN_MAX];
2334 indent_len = get_indent_length(text, start_pos, tlen);
2336 if ((indent_len > 0) && (indent_len == prev_ilen)) {
2337 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2338 if (ch_len > 0 && (cbuf[0] != '\n'))
2345 static void compose_wrap_line_all(Compose *compose)
2347 GtkSText *text = GTK_STEXT(compose->text);
2349 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2350 gint line_len = 0, cur_len = 0;
2352 gboolean is_new_line = TRUE, do_delete = FALSE;
2354 gboolean linewrap_quote = TRUE;
2355 guint linewrap_len = prefs_common.linewrap_len;
2356 gchar *qfmt = prefs_common.quotemark;
2357 gchar cbuf[MB_LEN_MAX];
2359 gtk_stext_freeze(text);
2361 /* make text buffer contiguous */
2362 /* gtk_stext_compact_buffer(text); */
2364 tlen = gtk_stext_get_length(text);
2366 for (; cur_pos < tlen; cur_pos++) {
2367 /* mark position of new line - needed for quotation wrap */
2370 i_len = get_indent_length(text, cur_pos, tlen);
2372 is_new_line = FALSE;
2375 printf("new line i_len=%d p_pos=", i_len);
2376 dump_text(text, p_pos, tlen, 1);
2380 GET_CHAR(cur_pos, cbuf, ch_len);
2382 /* fix line length for tabs */
2383 if (ch_len == 1 && *cbuf == '\t') {
2384 guint tab_width = text->default_tab_width;
2385 guint tab_offset = line_len % tab_width;
2388 printf("found tab at pos=%d line_len=%d ", cur_pos,
2392 line_len += tab_width - tab_offset - 1;
2396 printf("new_len=%d\n", line_len);
2400 /* we have encountered line break */
2401 if (ch_len == 1 && *cbuf == '\n') {
2403 gchar cb[MB_CUR_MAX];
2405 /* should we join the next line */
2406 if ((i_len != cur_len) && do_delete &&
2407 join_next_line(text, cur_pos + 1, tlen, i_len))
2413 printf("found CR at %d do_del is %d next line is ",
2414 cur_pos, do_delete);
2415 dump_text(text, cur_pos + 1, tlen, 1);
2418 /* skip delete if it is continuous URL */
2419 if (do_delete && (line_pos - p_pos <= i_len) &&
2420 gtkut_stext_is_uri_string(text, line_pos, tlen))
2424 printf("l_len=%d wrap_len=%d do_del=%d\n",
2425 line_len, linewrap_len, do_delete);
2427 /* should we delete to perform smart wrapping */
2428 if (line_len < linewrap_len && do_delete) {
2429 /* get rid of newline */
2430 gtk_stext_set_point(text, cur_pos);
2431 gtk_stext_forward_delete(text, 1);
2434 /* if text starts with quote fmt or with
2435 indent string, delete them */
2438 ilen = gtkut_stext_str_compare_n
2439 (text, cur_pos, p_pos, i_len,
2442 gtk_stext_forward_delete
2448 GET_CHAR(cur_pos, cb, clen);
2450 /* insert space if it's alphanumeric */
2451 if ((cur_pos != line_pos) &&
2452 ((clen > 1) || isalnum(cb[0]))) {
2453 gtk_stext_insert(text, NULL, NULL,
2455 /* gtk_stext_compact_buffer(text); */
2459 /* and start over with current line */
2460 cur_pos = p_pos - 1;
2462 line_len = cur_len = 0;
2466 printf("after delete l_pos=");
2467 dump_text(text, line_pos, tlen, 1);
2472 /* mark new line beginning */
2473 line_pos = cur_pos + 1;
2474 line_len = cur_len = 0;
2485 /* possible line break */
2486 if (ch_len == 1 && isspace(*cbuf)) {
2487 line_pos = cur_pos + 1;
2488 line_len = cur_len + ch_len;
2491 /* are we over wrapping length set in preferences ? */
2492 if (cur_len + ch_len > linewrap_len) {
2496 printf("should wrap cur_pos=%d ", cur_pos);
2497 dump_text(text, p_pos, tlen, 1);
2498 dump_text(text, line_pos, tlen, 1);
2500 /* force wrapping if it is one long word but not URL */
2501 if (line_pos - p_pos <= i_len)
2502 if (!gtkut_stext_is_uri_string
2503 (text, line_pos, tlen))
2504 line_pos = cur_pos - 1;
2506 printf("new line_pos=%d\n", line_pos);
2509 GET_CHAR(line_pos - 1, cbuf, clen);
2511 /* if next character is space delete it */
2512 if (clen == 1 && isspace(*cbuf)) {
2513 if (p_pos + i_len != line_pos ||
2514 !gtkut_stext_is_uri_string
2515 (text, line_pos, tlen)) {
2516 gtk_stext_set_point(text, line_pos);
2517 gtk_stext_backward_delete(text, 1);
2526 /* if it is URL at beginning of line don't wrap */
2527 if (p_pos + i_len == line_pos &&
2528 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2530 printf("found URL at ");
2531 dump_text(text, line_pos, tlen, 1);
2537 gtk_stext_set_point(text, line_pos);
2538 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2539 /* gtk_stext_compact_buffer(text); */
2542 /* for loop will increase it */
2543 cur_pos = line_pos - 1;
2544 /* start over with current line */
2553 printf("after CR insert ");
2554 dump_text(text, line_pos, tlen, 1);
2555 dump_text(text, cur_pos, tlen, 1);
2558 /* should we insert quotation ? */
2559 if (linewrap_quote && i_len) {
2560 /* only if line is not already quoted */
2561 if (!gtkut_stext_str_compare
2562 (text, line_pos, tlen, qfmt)) {
2565 if (line_pos - p_pos > i_len) {
2567 (text, i_len, p_pos,
2570 /* gtk_stext_compact_buffer(text); */
2574 printf("after quote insert ");
2575 dump_text(text, line_pos, tlen, 1);
2583 line_pos = cur_pos + 1;
2584 line_len = cur_len + ch_len;
2586 /* advance to next character in buffer */
2590 gtk_stext_thaw(text);
2595 static void compose_set_title(Compose *compose)
2600 edited = compose->modified ? _(" [Edited]") : "";
2601 if (compose->account && compose->account->address)
2602 str = g_strdup_printf(_("%s - Compose message%s"),
2603 compose->account->address, edited);
2605 str = g_strdup_printf(_("Compose message%s"), edited);
2606 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2611 * compose_current_mail_account:
2613 * Find a current mail account (the currently selected account, or the
2614 * default account, if a news account is currently selected). If a
2615 * mail account cannot be found, display an error message.
2617 * Return value: Mail account, or NULL if not found.
2619 static PrefsAccount *
2620 compose_current_mail_account(void)
2624 if (cur_account && cur_account->protocol != A_NNTP)
2627 ac = account_get_default();
2628 if (!ac || ac->protocol == A_NNTP) {
2629 alertpanel_error(_("Account for sending mail is not specified.\n"
2630 "Please select a mail account before sending."));
2637 gboolean compose_check_for_valid_recipient(Compose *compose) {
2638 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2639 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2640 gboolean recipient_found = FALSE;
2644 /* free to and newsgroup list */
2645 slist_free_strings(compose->to_list);
2646 g_slist_free(compose->to_list);
2647 compose->to_list = NULL;
2649 slist_free_strings(compose->newsgroup_list);
2650 g_slist_free(compose->newsgroup_list);
2651 compose->newsgroup_list = NULL;
2653 /* search header entries for to and newsgroup entries */
2654 for(list = compose->header_list; list; list = list->next) {
2657 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2658 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2660 if(entry[0] != '\0') {
2661 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2662 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2663 compose->to_list = address_list_append(compose->to_list, entry);
2664 recipient_found = TRUE;
2667 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2668 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2669 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2670 recipient_found = TRUE;
2676 return recipient_found;
2679 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
2683 if (compose_check_for_valid_recipient(compose) == FALSE) {
2684 alertpanel_error(_("Recipient is not specified."));
2688 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2689 if (*str == '\0' && check_subject == TRUE) {
2692 aval = alertpanel(_("Send"),
2693 _("Subject is empty. Send it anyway?"),
2694 _("Yes"), _("No"), NULL);
2695 if (aval != G_ALERTDEFAULT)
2702 gint compose_send(Compose *compose)
2708 if (compose_check_entries(compose, TRUE) == FALSE)
2711 val = compose_queue(compose, &msgnum, &folder);
2713 alertpanel_error(_("Could not queue message for sending"));
2717 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2719 folder_item_remove_msg(folder, msgnum);
2720 folderview_update_item(folder, TRUE);
2725 #if 0 /* compose restructure */
2726 gint compose_send(Compose *compose)
2728 gchar tmp[MAXPATHLEN + 1];
2730 static gboolean lock = FALSE;
2734 g_return_val_if_fail(compose->account != NULL, -1);
2735 g_return_val_if_fail(compose->orig_account != NULL, -1);
2739 if (compose_check_entries(compose, TRUE) == FALSE) {
2744 /* write to temporary file */
2745 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2746 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2748 if (prefs_common.linewrap_at_send)
2749 compose_wrap_line_all(compose);
2751 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2756 if (!compose->to_list && !compose->newsgroup_list) {
2757 g_warning(_("can't get recipient list."));
2763 if (compose->to_list) {
2766 #if 0 /* NEW COMPOSE GUI */
2767 if (compose->account->protocol != A_NNTP)
2768 ac = compose->account;
2769 else if (compose->orig_account->protocol != A_NNTP)
2770 ac = compose->orig_account;
2771 else if (cur_account && cur_account->protocol != A_NNTP)
2774 ac = compose_current_mail_account();
2782 ac = compose->account;
2784 ok = send_message(tmp, ac, compose->to_list);
2785 statusbar_pop_all();
2788 if (ok == 0 && compose->newsgroup_list) {
2791 if (compose->account->protocol == A_NNTP)
2792 folder = FOLDER(compose->account->folder);
2794 folder = FOLDER(compose->orig_account->folder);
2796 ok = news_post(folder, tmp);
2798 alertpanel_error(_("Error occurred while posting the message to %s ."),
2799 compose->account->nntp_server);
2806 /* queue message if failed to send */
2808 if (prefs_common.queue_msg) {
2813 _("Error occurred while sending the message.\n"
2814 "Put this message into queue folder?"),
2815 _("OK"), _("Cancel"), NULL);
2816 if (G_ALERTDEFAULT == val) {
2817 ok = compose_queue(compose, tmp);
2819 alertpanel_error(_("Can't queue the message."));
2822 alertpanel_error(_("Error occurred while sending the message."));
2824 if (compose->mode == COMPOSE_REEDIT) {
2825 compose_remove_reedit_target(compose);
2826 if (compose->targetinfo)
2827 folderview_update_item
2828 (compose->targetinfo->folder, TRUE);
2830 /* save message to outbox */
2831 if (prefs_common.savemsg) {
2834 outbox = account_get_special_folder
2835 (compose->account, F_OUTBOX);
2836 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
2838 (_("Can't save the message to Sent."));
2840 folderview_update_item(outbox, TRUE);
2850 static gboolean compose_use_attach(Compose *compose) {
2851 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2854 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2857 gchar buf[BUFFSIZE];
2859 gboolean first_address;
2861 ComposeHeaderEntry *headerentry;
2862 gchar *headerentryname;
2863 gchar *header_w_colon;
2867 debug_print(_("Writing bounce header\n"));
2869 header_w_colon = g_strconcat("To:", NULL);
2870 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2871 header_w_colon = g_strconcat("Cc:", NULL);
2872 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2874 first_address = TRUE;
2875 for(list = compose->header_list; list; list = list->next) {
2876 headerentry = ((ComposeHeaderEntry *)list->data);
2877 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2879 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2880 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2881 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2882 Xstrdup_a(str, str, return -1);
2884 if(str[0] != '\0') {
2885 compose_convert_header
2886 (buf, sizeof(buf), str,
2887 strlen("Resent-To") + 2);
2889 fprintf(fp, "Resent-To: ");
2890 first_address = FALSE;
2894 fprintf(fp, "%s", buf);
2898 /* if(!first_address) { */
2905 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2907 gchar buf[BUFFSIZE];
2909 /* struct utsname utsbuf; */
2911 g_return_val_if_fail(fp != NULL, -1);
2912 g_return_val_if_fail(compose->account != NULL, -1);
2913 g_return_val_if_fail(compose->account->address != NULL, -1);
2916 get_rfc822_date(buf, sizeof(buf));
2917 fprintf(fp, "Resent-Date: %s\n", buf);
2920 if (compose->account->name && *compose->account->name) {
2921 compose_convert_header
2922 (buf, sizeof(buf), compose->account->name,
2924 fprintf(fp, "Resent-From: %s <%s>\n",
2925 buf, compose->account->address);
2927 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2930 compose_bounce_write_headers_from_headerlist(compose, fp);
2932 /* separator between header and body */
2938 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2943 gchar buf[BUFFSIZE];
2945 if ((fp = fopen(compose->bounce_filename, "rb")) == NULL) {
2946 FILE_OP_ERROR(file, "fopen");
2950 if ((fdest = fopen(file, "wb")) == NULL) {
2951 FILE_OP_ERROR(file, "fopen");
2956 /* chmod for security */
2957 if (change_file_mode_rw(fdest, file) < 0) {
2958 FILE_OP_ERROR(file, "chmod");
2959 g_warning(_("can't change file mode\n"));
2962 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2963 /* should filter returnpath, delivered-to */
2964 if ((g_strncasecmp(buf, "Return-Path:",
2965 strlen("Return-Path:")) == 0)
2966 || (g_strncasecmp(buf, "Delivered-To:",
2967 strlen("Delivered-To:")) == 0))
2970 if (fputs(buf, fdest) == -1)
2973 if (!prefs_common.bounce_keep_from) {
2974 if (g_strncasecmp(buf, "From:",
2975 strlen("From:")) == 0) {
2976 fputs(" (by way of ", fdest);
2977 if (compose->account->name
2978 && *compose->account->name) {
2979 compose_convert_header
2981 compose->account->name,
2983 fprintf(fdest, "%s <%s>",
2985 compose->account->address);
2987 fprintf(fdest, "%s",
2988 compose->account->address);
2993 if (fputs("\n", fdest) == -1)
2997 compose_bounce_write_headers(compose, fdest);
2999 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3000 if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
3001 FILE_OP_ERROR(file, "fwrite");
3007 if (fclose(fdest) == EOF) {
3008 FILE_OP_ERROR(file, "fclose");
3025 * interfaces to rfc2015 to keep out the prefs stuff there.
3026 * returns 0 on success and -1 on error. */
3027 static int compose_create_signers_list (Compose *compose, GSList **pkey_list)
3029 const char *keyid = NULL;
3032 switch (compose->account->sign_key) {
3033 case SIGN_KEY_DEFAULT:
3035 return 0; /* nothing to do */
3037 case SIGN_KEY_BY_FROM:
3038 keyid = compose->account->address;
3041 case SIGN_KEY_CUSTOM:
3042 keyid = compose->account->sign_key_id;
3046 g_assert_not_reached ();
3049 key_list = rfc2015_create_signers_list(keyid);
3052 alertpanel_error("Could not find any key associated with currently "
3053 "selected keyid `%s'!", keyid);
3057 *pkey_list = key_list;
3060 #endif /* USE_GPGME */
3062 static gint compose_write_to_file(Compose *compose, const gchar *file,
3069 const gchar *out_codeset;
3070 EncodingType encoding;
3072 if ((fp = fopen(file, "wb")) == NULL) {
3073 FILE_OP_ERROR(file, "fopen");
3077 /* chmod for security */
3078 if (change_file_mode_rw(fp, file) < 0) {
3079 FILE_OP_ERROR(file, "chmod");
3080 g_warning(_("can't change file mode\n"));
3083 /* get all composed text */
3084 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3085 len = strlen(chars);
3086 if (is_ascii_str(chars)) {
3087 buf = g_strdup(chars);
3088 out_codeset = CS_US_ASCII;
3089 encoding = ENC_7BIT;
3091 const gchar *src_codeset;
3093 out_codeset = conv_get_outgoing_charset_str();
3094 if (!strcasecmp(out_codeset, CS_US_ASCII))
3095 out_codeset = CS_ISO_8859_1;
3096 encoding = procmime_get_encoding_for_charset(out_codeset);
3098 src_codeset = conv_get_current_charset_str();
3099 /* if current encoding is US-ASCII, set it the same as
3100 outgoing one to prevent code conversion failure */
3101 if (!strcasecmp(src_codeset, CS_US_ASCII))
3102 src_codeset = out_codeset;
3104 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3105 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3107 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3113 _("Can't convert the character encoding of the message.\n"
3114 "Send it anyway?"), _("Yes"), _("+No"), NULL);
3115 if (aval != G_ALERTDEFAULT) {
3121 buf = g_strdup(chars);
3128 if (compose_write_headers
3129 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3130 g_warning(_("can't write headers\n"));
3137 if (compose_use_attach(compose)) {
3139 /* This prolog message is ignored by mime software and
3140 * because it would make our signing/encryption task
3141 * tougher, we don't emit it in that case */
3142 if (!compose->use_signing && !compose->use_encryption)
3144 fputs("This is a multi-part message in MIME format.\n", fp);
3146 fprintf(fp, "\n--%s\n", compose->boundary);
3147 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3149 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3150 procmime_get_encoding_str(encoding));
3156 if (encoding == ENC_BASE64) {
3157 gchar outbuf[B64_BUFFSIZE];
3160 for (i = 0; i < len; i += B64_LINE_SIZE) {
3161 l = MIN(B64_LINE_SIZE, len - i);
3162 to64frombits(outbuf, buf + i, l);
3166 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3167 FILE_OP_ERROR(file, "fwrite");
3175 if (compose_use_attach(compose))
3176 compose_write_attach(compose, fp);
3178 if (fclose(fp) == EOF) {
3179 FILE_OP_ERROR(file, "fclose");
3185 if (compose->use_signing) {
3188 if (compose_create_signers_list(compose, &key_list) == -1 ||
3189 rfc2015_sign(file, key_list) < 0) {
3195 if (compose->use_encryption) {
3196 if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) {
3201 #endif /* USE_GPGME */
3206 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3212 if ((fp = fopen(file, "wb")) == NULL) {
3213 FILE_OP_ERROR(file, "fopen");
3217 /* chmod for security */
3218 if (change_file_mode_rw(fp, file) < 0) {
3219 FILE_OP_ERROR(file, "chmod");
3220 g_warning(_("can't change file mode\n"));
3223 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3226 len = strlen(chars);
3227 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3228 FILE_OP_ERROR(file, "fwrite");
3237 if (fclose(fp) == EOF) {
3238 FILE_OP_ERROR(file, "fclose");
3245 static gint compose_remove_reedit_target(Compose *compose)
3248 MsgInfo *msginfo = compose->targetinfo;
3250 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3251 if (!msginfo) return -1;
3253 item = msginfo->folder;
3254 g_return_val_if_fail(item != NULL, -1);
3256 folder_item_scan(item);
3257 if (procmsg_msg_exist(msginfo) &&
3258 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3259 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3260 g_warning(_("can't remove the old message\n"));
3268 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3270 return compose_queue_sub (compose, msgnum, item, FALSE);
3272 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3278 gchar buf[BUFFSIZE];
3280 MsgFlags flag = {0, 0};
3281 static gboolean lock = FALSE;
3282 PrefsAccount *mailac = NULL, *newsac = NULL;
3284 debug_print(_("queueing message...\n"));
3285 g_return_val_if_fail(compose->account != NULL, -1);
3286 g_return_val_if_fail(compose->orig_account != NULL, -1);
3290 if (compose_check_entries(compose, check_subject) == FALSE) {
3295 if (!compose->to_list && !compose->newsgroup_list) {
3296 g_warning(_("can't get recipient list."));
3301 if(compose->to_list) {
3302 if (compose->account->protocol != A_NNTP)
3303 mailac = compose->account;
3304 else if (compose->orig_account->protocol != A_NNTP)
3305 mailac = compose->orig_account;
3306 else if (cur_account && cur_account->protocol != A_NNTP)
3307 mailac = cur_account;
3308 else if (!(mailac = compose_current_mail_account())) {
3310 alertpanel_error(_("No account for sending mails available!"));
3315 if(compose->newsgroup_list) {
3316 if (compose->account->protocol == A_NNTP)
3317 newsac = compose->account;
3318 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3320 alertpanel_error(_("No account for posting news available!"));
3325 if (prefs_common.linewrap_at_send)
3326 compose_wrap_line_all(compose);
3328 /* write to temporary file */
3329 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3330 G_DIR_SEPARATOR, (gint)compose);
3332 if (compose->bounce_filename != NULL) {
3333 if (compose_bounce_write_to_file(compose, tmp2) < 0) {
3340 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3347 /* add queue header */
3348 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3349 G_DIR_SEPARATOR, (gint)compose);
3350 if ((fp = fopen(tmp, "wb")) == NULL) {
3351 FILE_OP_ERROR(tmp, "fopen");
3355 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3356 FILE_OP_ERROR(tmp2, "fopen");
3364 if (change_file_mode_rw(fp, tmp) < 0) {
3365 FILE_OP_ERROR(tmp, "chmod");
3366 g_warning(_("can't change file mode\n"));
3369 /* queueing variables */
3370 fprintf(fp, "AF:\n");
3371 fprintf(fp, "NF:0\n");
3372 fprintf(fp, "PS:10\n");
3373 fprintf(fp, "SRH:1\n");
3374 fprintf(fp, "SFN:\n");
3375 fprintf(fp, "DSR:\n");
3377 fprintf(fp, "MID:<%s>\n", compose->msgid);
3379 fprintf(fp, "MID:\n");
3380 fprintf(fp, "CFG:\n");
3381 fprintf(fp, "PT:0\n");
3382 fprintf(fp, "S:%s\n", compose->account->address);
3383 fprintf(fp, "RQ:\n");
3385 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3387 fprintf(fp, "SSV:\n");
3389 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3391 fprintf(fp, "NSV:\n");
3392 fprintf(fp, "SSH:\n");
3393 /* write recepient list */
3395 if(compose->to_list) {
3396 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3397 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3398 fprintf(fp, ",<%s>", (gchar *)cur->data);
3401 /* write newsgroup list */
3403 if(compose->newsgroup_list) {
3404 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3405 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3406 fprintf(fp, ",%s", (gchar *)cur->data);
3409 /* Sylpheed account IDs */
3411 fprintf(fp, "MAID:%d\n", mailac->account_id);
3414 fprintf(fp, "NAID:%d\n", newsac->account_id);
3416 /* Save copy folder */
3417 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3420 str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3421 fprintf(fp, "SCF:%s\n", str);
3426 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3427 if (fputs(buf, fp) == EOF) {
3428 FILE_OP_ERROR(tmp, "fputs");
3439 if (fclose(fp) == EOF) {
3440 FILE_OP_ERROR(tmp, "fclose");
3448 queue = account_get_special_folder(compose->account, F_QUEUE);
3450 g_warning(_("can't find queue folder\n"));
3455 folder_item_scan(queue);
3456 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3457 g_warning(_("can't queue the message\n"));
3467 if (compose->mode == COMPOSE_REEDIT) {
3468 compose_remove_reedit_target(compose);
3469 if (compose->targetinfo &&
3470 compose->targetinfo->folder != queue)
3471 folderview_update_item
3472 (compose->targetinfo->folder, TRUE);
3475 procmsg_add_flags(queue, num, flag);
3476 folder_item_scan(queue);
3477 folderview_update_item(queue, TRUE);
3479 if((msgnum != NULL) && (item != NULL)) {
3487 static void compose_write_attach(Compose *compose, FILE *fp)
3490 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3493 gchar filename[BUFFSIZE];
3496 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3498 gchar buf[BUFFSIZE];
3499 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3501 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
3502 g_warning(_("Can't open file %s\n"), ainfo->file);
3506 fprintf(fp, "\n--%s\n", compose->boundary);
3508 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3509 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3510 fprintf(fp, "Content-Disposition: inline\n");
3512 conv_encode_header(filename, sizeof(filename),
3514 fprintf(fp, "Content-Type: %s;\n"
3516 ainfo->content_type, filename);
3517 fprintf(fp, "Content-Disposition: attachment;\n"
3518 " filename=\"%s\"\n", filename);
3521 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3522 procmime_get_encoding_str(ainfo->encoding));
3524 switch (ainfo->encoding) {
3528 /* if (ainfo->encoding == ENC_7BIT) { */
3530 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3538 while ((len = fread(inbuf, sizeof(gchar),
3539 B64_LINE_SIZE, attach_fp))
3541 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3545 if (len > 0 && feof(attach_fp)) {
3546 to64frombits(outbuf, inbuf, len);
3556 fprintf(fp, "\n--%s--\n", compose->boundary);
3559 #define QUOTE_IF_REQUIRED(out, str) \
3561 if (*str != '"' && strchr(str, ',')) { \
3565 len = strlen(str) + 3; \
3566 Xalloca(__tmp, len, return -1); \
3567 g_snprintf(__tmp, len, "\"%s\"", str); \
3570 Xstrdup_a(out, str, return -1); \
3574 #define PUT_RECIPIENT_HEADER(header, str) \
3576 if (*str != '\0') { \
3577 Xstrdup_a(str, str, return -1); \
3579 if (*str != '\0') { \
3580 compose->to_list = address_list_append \
3581 (compose->to_list, str); \
3582 compose_convert_header \
3583 (buf, sizeof(buf), str, strlen(header) + 2); \
3584 fprintf(fp, "%s: %s\n", header, buf); \
3589 #define IS_IN_CUSTOM_HEADER(header) \
3590 (compose->account->add_customhdr && \
3591 custom_header_find(compose->account->customhdr_list, header) != NULL)
3593 static gint compose_write_headers_from_headerlist(Compose *compose,
3597 gchar buf[BUFFSIZE];
3598 gchar *str, *header_w_colon, *trans_hdr;
3599 gboolean first_address;
3601 ComposeHeaderEntry *headerentry;
3602 gchar * headerentryname;
3604 if (IS_IN_CUSTOM_HEADER(header)) {
3608 debug_print(_("Writing %s-header\n"), header);
3610 header_w_colon = g_strconcat(header, ":", NULL);
3611 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3613 first_address = TRUE;
3614 for(list = compose->header_list; list; list = list->next) {
3615 headerentry = ((ComposeHeaderEntry *)list->data);
3616 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3618 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3619 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3620 Xstrdup_a(str, str, return -1);
3622 if(str[0] != '\0') {
3623 compose_convert_header
3624 (buf, sizeof(buf), str,
3625 strlen(header) + 2);
3627 fprintf(fp, "%s: ", header);
3628 first_address = FALSE;
3632 fprintf(fp, "%s", buf);
3636 if(!first_address) {
3640 g_free(header_w_colon);
3645 static gint compose_write_headers(Compose *compose, FILE *fp,
3646 const gchar *charset, EncodingType encoding,
3649 gchar buf[BUFFSIZE];
3652 /* struct utsname utsbuf; */
3654 g_return_val_if_fail(fp != NULL, -1);
3655 g_return_val_if_fail(charset != NULL, -1);
3656 g_return_val_if_fail(compose->account != NULL, -1);
3657 g_return_val_if_fail(compose->account->address != NULL, -1);
3660 if (compose->account->add_date) {
3661 get_rfc822_date(buf, sizeof(buf));
3662 fprintf(fp, "Date: %s\n", buf);
3666 if (!IS_IN_CUSTOM_HEADER("From")) {
3667 if (compose->account->name && *compose->account->name) {
3668 compose_convert_header
3669 (buf, sizeof(buf), compose->account->name,
3671 QUOTE_IF_REQUIRED(name, buf);
3672 fprintf(fp, "From: %s <%s>\n",
3673 name, compose->account->address);
3675 fprintf(fp, "From: %s\n", compose->account->address);
3679 compose_write_headers_from_headerlist(compose, fp, "To");
3680 #if 0 /* NEW COMPOSE GUI */
3681 if (compose->use_to) {
3682 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3683 PUT_RECIPIENT_HEADER("To", str);
3688 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3689 #if 0 /* NEW COMPOSE GUI */
3690 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3692 Xstrdup_a(str, str, return -1);
3696 compose->newsgroup_list =
3697 newsgroup_list_append(compose->newsgroup_list,
3699 compose_convert_header(buf, sizeof(buf), str,
3700 strlen("Newsgroups: "));
3701 fprintf(fp, "Newsgroups: %s\n", buf);
3706 compose_write_headers_from_headerlist(compose, fp, "Cc");
3707 #if 0 /* NEW COMPOSE GUI */
3708 if (compose->use_cc) {
3709 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3710 PUT_RECIPIENT_HEADER("Cc", str);
3714 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3715 #if 0 /* NEW COMPOSE GUI */
3716 if (compose->use_bcc) {
3717 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3718 PUT_RECIPIENT_HEADER("Bcc", str);
3723 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3724 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3725 Xstrdup_a(str, str, return -1);
3728 compose_convert_header(buf, sizeof(buf), str,
3729 strlen("Subject: "));
3730 fprintf(fp, "Subject: %s\n", buf);
3735 if (compose->account->gen_msgid) {
3736 compose_generate_msgid(compose, buf, sizeof(buf));
3737 fprintf(fp, "Message-Id: <%s>\n", buf);
3738 compose->msgid = g_strdup(buf);
3742 if (compose->inreplyto && compose->to_list)
3743 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3746 if (compose->references)
3747 fprintf(fp, "References: %s\n", compose->references);
3750 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3751 #if 0 /* NEW COMPOSE GUI */
3752 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3753 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3755 Xstrdup_a(str, str, return -1);
3759 compose_convert_header(buf, sizeof(buf), str,
3760 strlen("Followup-To: "));
3761 fprintf(fp, "Followup-To: %s\n", buf);
3767 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3768 #if 0 /* NEW COMPOSE GUI */
3769 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3770 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3772 Xstrdup_a(str, str, return -1);
3775 compose_convert_header(buf, sizeof(buf), str,
3776 strlen("Reply-To: "));
3777 fprintf(fp, "Reply-To: %s\n", buf);
3783 if (compose->account->organization &&
3784 !IS_IN_CUSTOM_HEADER("Organization")) {
3785 compose_convert_header(buf, sizeof(buf),
3786 compose->account->organization,
3787 strlen("Organization: "));
3788 fprintf(fp, "Organization: %s\n", buf);
3791 /* Program version and system info */
3792 /* uname(&utsbuf); */
3793 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3794 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3796 gtk_major_version, gtk_minor_version, gtk_micro_version,
3798 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3800 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3801 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3803 gtk_major_version, gtk_minor_version, gtk_micro_version,
3805 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3808 /* custom headers */
3809 if (compose->account->add_customhdr) {
3812 for (cur = compose->account->customhdr_list; cur != NULL;
3814 CustomHeader *chdr = (CustomHeader *)cur->data;
3816 if (strcasecmp(chdr->name, "Date") != 0 &&
3817 strcasecmp(chdr->name, "From") != 0 &&
3818 strcasecmp(chdr->name, "To") != 0 &&
3819 /* strcasecmp(chdr->name, "Sender") != 0 && */
3820 strcasecmp(chdr->name, "Message-Id") != 0 &&
3821 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3822 strcasecmp(chdr->name, "References") != 0 &&
3823 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3824 strcasecmp(chdr->name, "Content-Type") != 0 &&
3825 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3827 compose_convert_header
3829 chdr->value ? chdr->value : "",
3830 strlen(chdr->name) + 2);
3831 fprintf(fp, "%s: %s\n", chdr->name, buf);
3837 fprintf(fp, "Mime-Version: 1.0\n");
3838 if (compose_use_attach(compose)) {
3839 get_rfc822_date(buf, sizeof(buf));
3840 subst_char(buf, ' ', '_');
3841 subst_char(buf, ',', '_');
3842 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3843 buf, (guint)compose);
3845 "Content-Type: multipart/mixed;\n"
3846 " boundary=\"%s\"\n", compose->boundary);
3848 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3849 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3850 procmime_get_encoding_str(encoding));
3854 switch (compose->priority) {
3855 case PRIORITY_HIGHEST: fprintf(fp, "Importance: high\n"
3856 "X-Priority: 1 (Highest)\n");
3858 case PRIORITY_HIGH: fprintf(fp, "Importance: high\n"
3859 "X-Priority: 2 (High)\n");
3861 case PRIORITY_NORMAL: break;
3862 case PRIORITY_LOW: fprintf(fp, "Importance: low\n"
3863 "X-Priority: 4 (Low)\n");
3865 case PRIORITY_LOWEST: fprintf(fp, "Importance: low\n"
3866 "X-Priority: 5 (Lowest)\n");
3868 default: debug_print(_("compose: priority unknown : %d\n"),
3872 /* Request Return Receipt */
3873 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3874 if (compose->return_receipt) {
3875 if (compose->account->name
3876 && *compose->account->name) {
3877 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3878 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3880 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3884 /* separator between header and body */
3890 #undef IS_IN_CUSTOM_HEADER
3892 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3895 g_return_if_fail(src != NULL);
3896 g_return_if_fail(dest != NULL);
3898 if (len < 1) return;
3902 if (is_ascii_str(src)) {
3903 strncpy2(dest, src, len);
3904 dest[len - 1] = '\0';
3907 conv_encode_header(dest, len, src, header_len);
3910 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3919 if (compose->account && compose->account->address &&
3920 *compose->account->address) {
3921 if (strchr(compose->account->address, '@'))
3922 addr = g_strdup(compose->account->address);
3924 addr = g_strconcat(compose->account->address, "@",
3925 get_domain_name(), NULL);
3927 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3930 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3931 lt->tm_year + 1900, lt->tm_mon + 1,
3932 lt->tm_mday, lt->tm_hour,
3933 lt->tm_min, lt->tm_sec,
3934 (guint)random(), addr);
3936 debug_print(_("generated Message-ID: %s\n"), buf);
3941 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3942 GtkWidget **entry, gint *count,
3943 const gchar *label_str,
3944 gboolean is_addr_entry)
3948 if (GTK_TABLE(table)->nrows < (*count) + 1)
3949 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3951 *hbox = gtk_hbox_new(FALSE, 0);
3952 label = gtk_label_new
3953 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3954 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3955 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3957 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3959 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3960 #if 0 /* NEW COMPOSE GUI */
3961 if (GTK_TABLE(table)->nrows > (*count) + 1)
3962 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3966 address_completion_register_entry(GTK_ENTRY(*entry));
3971 static void compose_create_header_entry(Compose *compose)
3973 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3977 GList *combo_list = NULL;
3978 gchar **string, *header;
3979 ComposeHeaderEntry *headerentry;
3981 headerentry = g_new0(ComposeHeaderEntry, 1);
3984 combo = gtk_combo_new();
3986 while(*string != NULL) {
3987 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3990 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3991 g_list_free(combo_list);
3992 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3993 gtk_widget_show(combo);
3994 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3995 if(compose->header_last) {
3996 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3998 switch(compose->account->protocol) {
4000 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4003 header = prefs_common.trans_hdr ? _("To:") : "To:";
4007 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4010 entry = gtk_entry_new();
4011 gtk_widget_show(entry);
4012 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);
4014 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4015 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4016 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4018 address_completion_register_entry(GTK_ENTRY(entry));
4020 headerentry->compose = compose;
4021 headerentry->combo = combo;
4022 headerentry->entry = entry;
4023 headerentry->headernum = compose->header_nextrow;
4025 compose->header_nextrow++;
4026 compose->header_last = headerentry;
4029 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4031 ComposeHeaderEntry *last_header;
4033 last_header = compose->header_last;
4035 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4036 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4039 static GtkWidget *compose_create_header(Compose *compose)
4043 GtkWidget *from_optmenu_hbox;
4044 #if 0 /* NEW COMPOSE GUI */
4045 GtkWidget *to_entry;
4047 GtkWidget *newsgroups_entry;
4048 GtkWidget *newsgroups_hbox;
4050 GtkWidget *header_scrolledwin;
4051 GtkWidget *header_table;
4052 #if 0 /* NEW COMPOSE GUI */
4053 GtkWidget *cc_entry;
4055 GtkWidget *bcc_entry;
4056 GtkWidget *bcc_hbox;
4057 GtkWidget *reply_entry;
4058 GtkWidget *reply_hbox;
4059 GtkWidget *followup_entry;
4060 GtkWidget *followup_hbox;
4065 /* header labels and entries */
4066 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4067 gtk_widget_show(header_scrolledwin);
4068 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4070 header_table = gtk_table_new(2, 2, FALSE);
4071 gtk_widget_show(header_table);
4072 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4073 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4074 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4077 /* option menu for selecting accounts */
4078 hbox = gtk_hbox_new(FALSE, 0);
4079 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4080 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4081 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4083 from_optmenu_hbox = compose_account_option_menu_create(compose);
4084 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4085 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4086 #if 0 /* NEW COMPOSE GUI */
4087 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4091 compose->header_table = header_table;
4092 compose->header_list = NULL;
4093 compose->header_nextrow = count;
4095 compose_create_header_entry(compose);
4097 #if 0 /* NEW COMPOSE GUI */
4098 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4100 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4101 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4102 &count, "Newsgroups:", FALSE);
4103 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4105 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4107 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4109 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4110 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4112 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4113 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4115 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4116 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4117 "Followup-To:", FALSE);
4118 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4120 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4122 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4123 GTK_SIGNAL_FUNC(to_activated), compose);
4124 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4125 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4126 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4127 GTK_SIGNAL_FUNC(subject_activated), compose);
4128 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4129 GTK_SIGNAL_FUNC(cc_activated), compose);
4130 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4131 GTK_SIGNAL_FUNC(bcc_activated), compose);
4132 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4133 GTK_SIGNAL_FUNC(replyto_activated), compose);
4134 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4135 GTK_SIGNAL_FUNC(followupto_activated), compose);
4137 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4138 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4139 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4140 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4141 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4142 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4143 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4144 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4145 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4146 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4147 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4148 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4149 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4150 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4153 compose->table = NULL;
4154 #if 0 /* NEW COMPOSE GUI */
4155 compose->table = table;
4156 compose->to_hbox = to_hbox;
4157 compose->to_entry = to_entry;
4158 compose->newsgroups_hbox = newsgroups_hbox;
4159 compose->newsgroups_entry = newsgroups_entry;
4161 #if 0 /* NEW COMPOSE GUI */
4162 compose->cc_hbox = cc_hbox;
4163 compose->cc_entry = cc_entry;
4164 compose->bcc_hbox = bcc_hbox;
4165 compose->bcc_entry = bcc_entry;
4166 compose->reply_hbox = reply_hbox;
4167 compose->reply_entry = reply_entry;
4168 compose->followup_hbox = followup_hbox;
4169 compose->followup_entry = followup_entry;
4172 return header_scrolledwin ;
4175 GtkWidget *compose_create_attach(Compose *compose)
4177 gchar *titles[N_ATTACH_COLS];
4180 GtkWidget *attach_scrwin;
4181 GtkWidget *attach_clist;
4183 titles[COL_MIMETYPE] = _("MIME type");
4184 titles[COL_SIZE] = _("Size");
4185 titles[COL_NAME] = _("Name");
4187 /* attachment list */
4188 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4189 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4190 GTK_POLICY_AUTOMATIC,
4192 gtk_widget_set_usize(attach_scrwin, -1, 80);
4194 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4195 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4197 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4198 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4199 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4200 GTK_SELECTION_EXTENDED);
4201 for (i = 0; i < N_ATTACH_COLS; i++)
4202 GTK_WIDGET_UNSET_FLAGS
4203 (GTK_CLIST(attach_clist)->column[i].button,
4205 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4207 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4208 GTK_SIGNAL_FUNC(attach_selected), compose);
4209 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4210 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4211 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4212 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4215 gtk_drag_dest_set(attach_clist,
4216 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4218 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4219 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4222 compose->attach_scrwin = attach_scrwin;
4223 compose->attach_clist = attach_clist;
4225 return attach_scrwin;
4228 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4229 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4231 static GtkWidget *compose_create_others(Compose *compose)
4234 GtkWidget *savemsg_checkbtn;
4235 GtkWidget *savemsg_entry;
4236 GtkWidget *savemsg_select;
4239 gchar *folderidentifier;
4241 /* Table for settings */
4242 table = gtk_table_new(3, 1, FALSE);
4243 gtk_widget_show(table);
4244 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4247 /* Save Message to folder */
4248 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4249 gtk_widget_show(savemsg_checkbtn);
4250 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4251 if(account_get_special_folder(compose->account, F_OUTBOX)) {
4252 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4254 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4255 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4257 savemsg_entry = gtk_entry_new();
4258 gtk_widget_show(savemsg_entry);
4259 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4260 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4261 if(account_get_special_folder(compose->account, F_OUTBOX)) {
4262 folderidentifier = folder_item_get_identifier(account_get_special_folder
4263 (compose->account, F_OUTBOX));
4264 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4265 g_free(folderidentifier);
4268 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4269 gtk_widget_show (savemsg_select);
4270 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4271 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4272 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4277 compose->savemsg_checkbtn = savemsg_checkbtn;
4278 compose->savemsg_entry = savemsg_entry;
4283 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4285 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4286 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4289 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4294 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4297 path = folder_item_get_identifier(dest);
4299 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4303 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4309 GtkWidget *handlebox;
4311 GtkWidget *notebook;
4316 GtkWidget *subject_hbox;
4317 GtkWidget *subject_frame;
4318 GtkWidget *subject_entry;
4322 GtkWidget *edit_vbox;
4323 GtkWidget *ruler_hbox;
4325 GtkWidget *scrolledwin;
4330 UndoMain *undostruct;
4332 gchar *titles[N_ATTACH_COLS];
4333 guint n_menu_entries;
4334 GtkStyle *style, *new_style;
4337 gboolean success[1];
4339 GtkWidget *popupmenu;
4340 GtkWidget *menuitem;
4341 GtkItemFactory *popupfactory;
4342 GtkItemFactory *ifactory;
4343 GtkWidget *tmpl_menu;
4347 GtkPspell * gtkpspell = NULL;
4350 static GdkGeometry geometry;
4352 g_return_val_if_fail(account != NULL, NULL);
4354 debug_print(_("Creating compose window...\n"));
4355 compose = g_new0(Compose, 1);
4357 titles[COL_MIMETYPE] = _("MIME type");
4358 titles[COL_SIZE] = _("Size");
4359 titles[COL_NAME] = _("Name");
4361 compose->account = account;
4362 compose->orig_account = account;
4364 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4365 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4366 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4367 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4369 if (!geometry.max_width) {
4370 geometry.max_width = gdk_screen_width();
4371 geometry.max_height = gdk_screen_height();
4373 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4374 &geometry, GDK_HINT_MAX_SIZE);
4376 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4377 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4378 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4379 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4380 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4381 gtk_widget_realize(window);
4383 gtkut_widget_set_composer_icon(window);
4385 vbox = gtk_vbox_new(FALSE, 0);
4386 gtk_container_add(GTK_CONTAINER(window), vbox);
4388 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4389 menubar = menubar_create(window, compose_entries,
4390 n_menu_entries, "<Compose>", compose);
4391 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4393 handlebox = gtk_handle_box_new();
4394 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4396 compose_toolbar_create(compose, handlebox);
4398 vbox2 = gtk_vbox_new(FALSE, 2);
4399 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4400 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4403 notebook = gtk_notebook_new();
4404 gtk_widget_set_usize(notebook, -1, 130);
4405 gtk_widget_show(notebook);
4407 /* header labels and entries */
4408 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4409 /* attachment list */
4410 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4412 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4415 subject_hbox = gtk_hbox_new(FALSE, 0);
4416 gtk_widget_show(subject_hbox);
4418 subject_frame = gtk_frame_new(NULL);
4419 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4420 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4421 gtk_widget_show(subject_frame);
4423 subject = gtk_hbox_new(FALSE, 0);
4424 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4425 gtk_widget_show(subject);
4427 label = gtk_label_new(_("Subject:"));
4428 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4429 gtk_widget_show(label);
4431 subject_entry = gtk_entry_new();
4432 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4433 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4434 gtk_widget_show(subject_entry);
4435 compose->subject_entry = subject_entry;
4436 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4438 edit_vbox = gtk_vbox_new(FALSE, 0);
4439 #if 0 /* NEW COMPOSE GUI */
4440 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4443 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4446 ruler_hbox = gtk_hbox_new(FALSE, 0);
4447 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4449 ruler = gtk_shruler_new();
4450 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4451 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4453 gtk_widget_set_usize(ruler_hbox, 1, -1);
4456 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4457 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4458 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4459 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4460 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4462 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4463 (GTK_SCROLLED_WINDOW(scrolledwin)),
4464 gtk_scrolled_window_get_vadjustment
4465 (GTK_SCROLLED_WINDOW(scrolledwin)));
4466 GTK_STEXT(text)->default_tab_width = 8;
4467 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4469 if (prefs_common.block_cursor) {
4470 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4473 if (prefs_common.smart_wrapping) {
4474 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4475 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4478 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4480 gtk_signal_connect(GTK_OBJECT(text), "changed",
4481 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4482 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4483 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4484 gtk_signal_connect(GTK_OBJECT(text), "activate",
4485 GTK_SIGNAL_FUNC(text_activated), compose);
4486 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4487 GTK_SIGNAL_FUNC(compose_button_press_cb),
4490 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4491 GTK_SIGNAL_FUNC(compose_key_press_cb),
4494 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4495 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4499 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4501 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4502 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4504 gtk_widget_show_all(vbox);
4506 /* pane between attach clist and text */
4507 paned = gtk_vpaned_new();
4508 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4509 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4510 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4511 gtk_paned_add1(GTK_PANED(paned), notebook);
4512 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4513 gtk_widget_show_all(paned);
4515 style = gtk_widget_get_style(text);
4517 /* workaround for the slow down of GtkSText when using Pixmap theme */
4518 if (style->engine) {
4519 GtkThemeEngine *engine;
4521 engine = style->engine;
4522 style->engine = NULL;
4523 new_style = gtk_style_copy(style);
4524 style->engine = engine;
4526 new_style = gtk_style_copy(style);
4528 if (prefs_common.textfont) {
4531 charset = conv_get_current_charset();
4532 if (MB_CUR_MAX == 1) {
4535 Xstrdup_a(fontstr, prefs_common.textfont, );
4536 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4538 font = gdk_font_load(fontstr);
4540 font = gdk_fontset_load(prefs_common.textfont);
4542 gdk_font_unref(new_style->font);
4543 new_style->font = font;
4547 gtk_widget_set_style(text, new_style);
4549 color[0] = quote_color;
4550 cmap = gdk_window_get_colormap(window->window);
4551 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4552 if (success[0] == FALSE) {
4553 g_warning("Compose: color allocation failed.\n");
4554 style = gtk_widget_get_style(text);
4555 quote_color = style->black;
4558 n_entries = sizeof(compose_popup_entries) /
4559 sizeof(compose_popup_entries[0]);
4560 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4561 "<Compose>", &popupfactory,
4564 ifactory = gtk_item_factory_from_widget(menubar);
4565 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4566 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4568 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4569 #if 0 /* NEW COMPOSE GUI */
4570 gtk_widget_hide(bcc_hbox);
4571 gtk_widget_hide(bcc_entry);
4572 gtk_widget_hide(reply_hbox);
4573 gtk_widget_hide(reply_entry);
4574 gtk_widget_hide(followup_hbox);
4575 gtk_widget_hide(followup_entry);
4576 gtk_widget_hide(ruler_hbox);
4577 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4578 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4579 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4581 if (account->protocol == A_NNTP) {
4582 gtk_widget_hide(to_hbox);
4583 gtk_widget_hide(to_entry);
4584 gtk_widget_hide(cc_hbox);
4585 gtk_widget_hide(cc_entry);
4586 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4587 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4589 gtk_widget_hide(newsgroups_hbox);
4590 gtk_widget_hide(newsgroups_entry);
4591 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4592 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
4596 update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
4599 undostruct = undo_init(text);
4600 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4603 gtk_widget_show(window);
4605 address_completion_start(window);
4607 compose->window = window;
4608 compose->vbox = vbox;
4609 compose->menubar = menubar;
4610 compose->handlebox = handlebox;
4612 compose->vbox2 = vbox2;
4614 compose->paned = paned;
4616 compose->edit_vbox = edit_vbox;
4617 compose->ruler_hbox = ruler_hbox;
4618 compose->ruler = ruler;
4619 compose->scrolledwin = scrolledwin;
4620 compose->text = text;
4622 compose->focused_editable = NULL;
4624 compose->popupmenu = popupmenu;
4625 compose->popupfactory = popupfactory;
4627 compose->tmpl_menu = tmpl_menu;
4629 compose->mode = mode;
4631 compose->targetinfo = NULL;
4632 compose->replyinfo = NULL;
4634 compose->replyto = NULL;
4635 compose->mailinglist = NULL;
4637 compose->bcc = NULL;
4638 compose->followup_to = NULL;
4639 compose->inreplyto = NULL;
4640 compose->references = NULL;
4641 compose->msgid = NULL;
4642 compose->boundary = NULL;
4645 compose->use_signing = FALSE;
4646 compose->use_encryption = FALSE;
4647 #endif /* USE_GPGME */
4649 compose->modified = FALSE;
4651 compose->return_receipt = FALSE;
4653 compose->to_list = NULL;
4654 compose->newsgroup_list = NULL;
4656 compose->exteditor_file = NULL;
4657 compose->exteditor_pid = -1;
4658 compose->exteditor_readdes = -1;
4659 compose->exteditor_tag = -1;
4661 compose->bounce_filename = NULL;
4662 compose->undostruct = undostruct;
4665 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4666 if (prefs_common.enable_pspell) {
4667 gtkpspell = gtkpspell_new((const gchar*)prefs_common.dictionary,
4668 conv_get_current_charset_str(),
4669 prefs_common.misspelled_col,
4670 prefs_common.check_while_typing,
4671 prefs_common.use_alternate,
4674 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkpspellcheckers->error_message);
4675 gtkpspell_checkers_reset_error();
4678 GtkWidget *menuitem;
4680 if (!gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode)) {
4681 debug_print(_("Pspell: could not set suggestion mode %s"),
4682 gtkpspellcheckers->error_message);
4683 gtkpspell_checkers_reset_error();
4686 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
4687 gtkpspell_populate_submenu(gtkpspell, menuitem);
4688 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4693 compose_set_title(compose);
4695 #if 0 /* NEW COMPOSE GUI */
4696 compose->use_bcc = FALSE;
4697 compose->use_replyto = FALSE;
4698 compose->use_followupto = FALSE;
4702 compose->gtkpspell = gtkpspell;
4705 #if 0 /* NEW COMPOSE GUI */
4706 if (account->protocol != A_NNTP) {
4707 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
4708 gtk_check_menu_item_set_active
4709 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4710 gtk_widget_set_sensitive(menuitem, FALSE);
4711 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4712 gtk_check_menu_item_set_active
4713 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4714 gtk_widget_set_sensitive(menuitem, FALSE);
4717 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4718 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4719 #if 0 /* NEW COMPOSE GUI */
4720 compose->use_cc = TRUE;
4721 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4722 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4723 gtk_check_menu_item_set_active
4724 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4727 if (account->set_autobcc) {
4728 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4729 #if 0 /* NEW COMPOSE GUI */
4730 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
4731 gtk_check_menu_item_set_active
4732 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4733 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4734 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4738 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4739 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4740 #if 0 /* NEW COMPOSE GUI */
4741 compose->use_replyto = TRUE;
4742 menuitem = gtk_item_factory_get_item(ifactory,
4744 gtk_check_menu_item_set_active
4745 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4746 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4747 account->auto_replyto);
4751 if (account->protocol != A_NNTP) {
4752 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4754 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4757 #if 0 /* NEW COMPOSE GUI */
4758 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
4759 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4760 prefs_common.show_ruler);
4764 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4765 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4766 account->default_sign);
4767 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4768 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4769 account->default_encrypt);
4770 #endif /* USE_GPGME */
4772 addressbook_set_target_compose(compose);
4773 compose_set_template_menu(compose);
4775 compose_list = g_list_append(compose_list, compose);
4777 #if 0 /* NEW COMPOSE GUI */
4778 compose->use_to = FALSE;
4779 compose->use_cc = FALSE;
4780 compose->use_attach = TRUE;
4783 #if 0 /* NEW COMPOSE GUI */
4784 if (!compose->use_bcc) {
4785 gtk_widget_hide(bcc_hbox);
4786 gtk_widget_hide(bcc_entry);
4787 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4789 if (!compose->use_replyto) {
4790 gtk_widget_hide(reply_hbox);
4791 gtk_widget_hide(reply_entry);
4792 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4794 if (!compose->use_followupto) {
4795 gtk_widget_hide(followup_hbox);
4796 gtk_widget_hide(followup_entry);
4797 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4800 if (!prefs_common.show_ruler)
4801 gtk_widget_hide(ruler_hbox);
4804 compose->priority = PRIORITY_NORMAL;
4805 compose_update_priority_menu_item(compose);
4807 select_account(compose, account);
4808 set_toolbar_style(compose);
4813 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4816 GtkWidget *icon_wid;
4817 GtkWidget *send_btn;
4818 GtkWidget *sendl_btn;
4819 GtkWidget *draft_btn;
4820 GtkWidget *insert_btn;
4821 GtkWidget *attach_btn;
4823 GtkWidget *exteditor_btn;
4824 GtkWidget *linewrap_btn;
4825 GtkWidget *addrbook_btn;
4827 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4829 gtk_container_add(GTK_CONTAINER(container), toolbar);
4830 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4831 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4832 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4833 GTK_TOOLBAR_SPACE_LINE);
4835 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
4836 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4840 icon_wid, toolbar_send_cb, compose);
4842 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND_QUEUE);
4843 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4845 _("Put into queue folder and send later"),
4847 icon_wid, toolbar_send_later_cb,
4850 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4851 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4853 _("Save to draft folder"),
4855 icon_wid, toolbar_draft_cb,
4858 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4860 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_INSERT_FILE);
4861 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4865 icon_wid, toolbar_insert_cb,
4868 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_ATTACH);
4869 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4873 icon_wid, toolbar_attach_cb,
4876 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4878 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SIGN);
4879 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4881 _("Insert signature"),
4883 icon_wid, toolbar_sig_cb, compose);
4885 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4887 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_EDIT_EXTERN);
4888 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4890 _("Edit with external editor"),
4893 toolbar_ext_editor_cb,
4896 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_LINEWRAP);
4897 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4899 _("Wrap all long lines"),
4902 toolbar_linewrap_cb,
4905 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4907 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_ADDRESS_BOOK);
4908 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4912 icon_wid, toolbar_address_cb,
4915 compose->toolbar = toolbar;
4916 compose->send_btn = send_btn;
4917 compose->sendl_btn = sendl_btn;
4918 compose->draft_btn = draft_btn;
4919 compose->insert_btn = insert_btn;
4920 compose->attach_btn = attach_btn;
4921 compose->sig_btn = sig_btn;
4922 compose->exteditor_btn = exteditor_btn;
4923 compose->linewrap_btn = linewrap_btn;
4924 compose->addrbook_btn = addrbook_btn;
4926 gtk_widget_show_all(toolbar);
4929 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4935 gint num = 0, def_menu = 0;
4937 accounts = account_get_list();
4938 g_return_val_if_fail(accounts != NULL, NULL);
4940 hbox = gtk_hbox_new(FALSE, 0);
4941 optmenu = gtk_option_menu_new();
4942 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4943 menu = gtk_menu_new();
4945 for (; accounts != NULL; accounts = accounts->next, num++) {
4946 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4947 GtkWidget *menuitem;
4950 if (ac == compose->account) def_menu = num;
4953 name = g_strdup_printf("%s: %s <%s>",
4955 ac->name, ac->address);
4957 name = g_strdup_printf("%s: %s",
4958 ac->account_name, ac->address);
4959 MENUITEM_ADD(menu, menuitem, name, ac);
4961 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4962 GTK_SIGNAL_FUNC(account_activated),
4966 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4967 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4972 static void compose_set_priority_cb(gpointer data,
4976 Compose *compose = (Compose *) data;
4977 compose->priority = action;
4980 static void compose_update_priority_menu_item(Compose * compose)
4982 GtkItemFactory *ifactory;
4983 GtkWidget *menuitem;
4985 ifactory = gtk_item_factory_from_widget(compose->menubar);
4987 switch (compose->priority) {
4988 case PRIORITY_HIGHEST:
4989 menuitem = gtk_item_factory_get_item
4990 (ifactory, "/Message/Priority/Highest");
4993 menuitem = gtk_item_factory_get_item
4994 (ifactory, "/Message/Priority/High");
4996 case PRIORITY_NORMAL:
4997 menuitem = gtk_item_factory_get_item
4998 (ifactory, "/Message/Priority/Normal");
5001 menuitem = gtk_item_factory_get_item
5002 (ifactory, "/Message/Priority/Low");
5004 case PRIORITY_LOWEST:
5005 menuitem = gtk_item_factory_get_item
5006 (ifactory, "/Message/Priority/Lowest");
5009 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5012 static void compose_set_template_menu(Compose *compose)
5014 GSList *tmpl_list, *cur;
5018 tmpl_list = template_get_config();
5020 menu = gtk_menu_new();
5022 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5023 Template *tmpl = (Template *)cur->data;
5025 item = gtk_menu_item_new_with_label(tmpl->name);
5026 gtk_menu_append(GTK_MENU(menu), item);
5027 gtk_signal_connect(GTK_OBJECT(item), "activate",
5028 GTK_SIGNAL_FUNC(compose_template_activate_cb),
5030 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
5031 gtk_widget_show(item);
5034 gtk_widget_show(menu);
5035 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5038 void compose_reflect_prefs_all(void)
5043 for (cur = compose_list; cur != NULL; cur = cur->next) {
5044 compose = (Compose *)cur->data;
5045 compose_set_template_menu(compose);
5049 void compose_reflect_prefs_pixmap_theme(void)
5054 for (cur = compose_list; cur != NULL; cur = cur->next) {
5055 compose = (Compose *)cur->data;
5056 gtk_container_remove(GTK_CONTAINER(compose->handlebox), GTK_WIDGET(compose->toolbar));
5057 compose->toolbar = NULL;
5058 compose_toolbar_create(compose, compose->handlebox);
5059 set_toolbar_style(compose);
5063 static void compose_template_apply(Compose *compose, Template *tmpl,
5069 if (!tmpl || !tmpl->value) return;
5071 gtk_stext_freeze(GTK_STEXT(compose->text));
5073 if (tmpl->subject && *tmpl->subject != '\0')
5074 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5076 if (tmpl->to && *tmpl->to != '\0')
5077 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5080 gtk_stext_clear(GTK_STEXT(compose->text));
5082 if (compose->replyinfo == NULL) {
5085 memset(&dummyinfo, 0, sizeof(MsgInfo));
5086 parsed_str = compose_quote_fmt(compose, &dummyinfo,
5087 tmpl->value, NULL, NULL);
5089 if (prefs_common.quotemark && *prefs_common.quotemark)
5090 qmark = prefs_common.quotemark;
5094 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5095 tmpl->value, qmark, NULL);
5098 if (replace && parsed_str && prefs_common.auto_sig)
5099 compose_insert_sig(compose);
5101 if (replace && parsed_str) {
5102 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
5103 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
5107 compose_changed_cb(NULL, compose);
5109 gtk_stext_thaw(GTK_STEXT(compose->text));
5112 static void compose_destroy(Compose *compose)
5115 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5118 /* NOTE: address_completion_end() does nothing with the window
5119 * however this may change. */
5120 address_completion_end(compose->window);
5122 slist_free_strings(compose->to_list);
5123 g_slist_free(compose->to_list);
5124 slist_free_strings(compose->newsgroup_list);
5125 g_slist_free(compose->newsgroup_list);
5126 slist_free_strings(compose->header_list);
5127 g_slist_free(compose->header_list);
5129 procmsg_msginfo_free(compose->targetinfo);
5130 procmsg_msginfo_free(compose->replyinfo);
5132 g_free(compose->replyto);
5133 g_free(compose->cc);
5134 g_free(compose->bcc);
5135 g_free(compose->newsgroups);
5136 g_free(compose->followup_to);
5138 g_free(compose->inreplyto);
5139 g_free(compose->references);
5140 g_free(compose->msgid);
5141 g_free(compose->boundary);
5143 if (compose->bounce_filename)
5144 g_free(compose->bounce_filename);
5146 g_free(compose->exteditor_file);
5148 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5150 compose_attach_info_free(ainfo);
5152 if (addressbook_get_target_compose() == compose)
5153 addressbook_set_target_compose(NULL);
5156 if (compose->gtkpspell) {
5157 gtkpspell_delete(compose->gtkpspell);
5161 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5162 prefs_common.compose_height = compose->window->allocation.height;
5164 gtk_widget_destroy(compose->paned);
5168 compose_list = g_list_remove(compose_list, compose);
5171 static void compose_attach_info_free(AttachInfo *ainfo)
5173 g_free(ainfo->file);
5174 g_free(ainfo->content_type);
5175 g_free(ainfo->name);
5179 static void compose_attach_remove_selected(Compose *compose)
5181 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5185 while (clist->selection != NULL) {
5186 row = GPOINTER_TO_INT(clist->selection->data);
5187 ainfo = gtk_clist_get_row_data(clist, row);
5188 compose_attach_info_free(ainfo);
5189 gtk_clist_remove(clist, row);
5193 static struct _AttachProperty
5196 GtkWidget *mimetype_entry;
5197 GtkWidget *encoding_optmenu;
5198 GtkWidget *path_entry;
5199 GtkWidget *filename_entry;
5201 GtkWidget *cancel_btn;
5204 static void compose_attach_property(Compose *compose)
5206 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5209 GtkOptionMenu *optmenu;
5210 static gboolean cancelled;
5212 if (!clist->selection) return;
5213 row = GPOINTER_TO_INT(clist->selection->data);
5215 ainfo = gtk_clist_get_row_data(clist, row);
5218 if (!attach_prop.window)
5219 compose_attach_property_create(&cancelled);
5220 gtk_widget_grab_focus(attach_prop.ok_btn);
5221 gtk_widget_show(attach_prop.window);
5222 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5224 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5225 if (ainfo->encoding == ENC_UNKNOWN)
5226 gtk_option_menu_set_history(optmenu, ENC_BASE64);
5228 gtk_option_menu_set_history(optmenu, ainfo->encoding);
5230 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5231 ainfo->content_type ? ainfo->content_type : "");
5232 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5233 ainfo->file ? ainfo->file : "");
5234 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5235 ainfo->name ? ainfo->name : "");
5239 gchar *cnttype = NULL;
5243 GtkWidget *menuitem;
5248 if (cancelled == TRUE) {
5249 gtk_widget_hide(attach_prop.window);
5253 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5254 if (*text != '\0') {
5257 text = g_strstrip(g_strdup(text));
5258 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5259 cnttype = g_strdup(text);
5262 alertpanel_error(_("Invalid MIME type."));
5268 menu = gtk_option_menu_get_menu(optmenu);
5269 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5270 ainfo->encoding = GPOINTER_TO_INT
5271 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5273 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5274 if (*text != '\0') {
5275 if (is_file_exist(text) &&
5276 (size = get_file_size(text)) > 0)
5277 file = g_strdup(text);
5280 (_("File doesn't exist or is empty."));
5286 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5287 if (*text != '\0') {
5288 g_free(ainfo->name);
5289 ainfo->name = g_strdup(text);
5293 g_free(ainfo->content_type);
5294 ainfo->content_type = cnttype;
5297 g_free(ainfo->file);
5303 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5304 ainfo->content_type);
5305 gtk_clist_set_text(clist, row, COL_SIZE,
5306 to_human_readable(ainfo->size));
5307 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5309 gtk_widget_hide(attach_prop.window);
5314 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5316 label = gtk_label_new(str); \
5317 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5318 GTK_FILL, 0, 0, 0); \
5319 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5321 entry = gtk_entry_new(); \
5322 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5323 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5326 static void compose_attach_property_create(gboolean *cancelled)
5332 GtkWidget *mimetype_entry;
5335 GtkWidget *optmenu_menu;
5336 GtkWidget *menuitem;
5337 GtkWidget *path_entry;
5338 GtkWidget *filename_entry;
5341 GtkWidget *cancel_btn;
5342 GList *mime_type_list, *strlist;
5344 debug_print("Creating attach_property window...\n");
5346 window = gtk_window_new(GTK_WINDOW_DIALOG);
5347 gtk_widget_set_usize(window, 480, -1);
5348 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5349 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
5350 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5351 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5352 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5353 GTK_SIGNAL_FUNC(attach_property_delete_event),
5355 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5356 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5359 vbox = gtk_vbox_new(FALSE, 8);
5360 gtk_container_add(GTK_CONTAINER(window), vbox);
5362 table = gtk_table_new(4, 2, FALSE);
5363 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5364 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5365 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5367 label = gtk_label_new(_("MIME type"));
5368 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5370 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5371 mimetype_entry = gtk_combo_new();
5372 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5373 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5375 /* stuff with list */
5376 mime_type_list = procmime_get_mime_type_list();
5378 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5379 MimeType *type = (MimeType *) mime_type_list->data;
5380 strlist = g_list_append(strlist,
5381 g_strdup_printf("%s/%s",
5382 type->type, type->sub_type));
5385 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5387 for (mime_type_list = strlist; mime_type_list != NULL;
5388 mime_type_list = mime_type_list->next)
5389 g_free(mime_type_list->data);
5390 g_list_free(strlist);
5392 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5394 label = gtk_label_new(_("Encoding"));
5395 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5397 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5399 hbox = gtk_hbox_new(FALSE, 0);
5400 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5401 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5403 optmenu = gtk_option_menu_new();
5404 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5406 optmenu_menu = gtk_menu_new();
5407 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5408 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5410 gtk_widget_set_sensitive(menuitem, FALSE);
5412 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5413 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5415 gtk_widget_set_sensitive(menuitem, FALSE);
5417 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5418 gtk_widget_set_sensitive(menuitem, FALSE);
5419 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5421 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5423 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5424 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5426 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5427 &cancel_btn, _("Cancel"), NULL, NULL);
5428 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5429 gtk_widget_grab_default(ok_btn);
5431 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5432 GTK_SIGNAL_FUNC(attach_property_ok),
5434 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5435 GTK_SIGNAL_FUNC(attach_property_cancel),
5438 gtk_widget_show_all(vbox);
5440 attach_prop.window = window;
5441 attach_prop.mimetype_entry = mimetype_entry;
5442 attach_prop.encoding_optmenu = optmenu;
5443 attach_prop.path_entry = path_entry;
5444 attach_prop.filename_entry = filename_entry;
5445 attach_prop.ok_btn = ok_btn;
5446 attach_prop.cancel_btn = cancel_btn;
5449 #undef SET_LABEL_AND_ENTRY
5451 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5457 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5463 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5464 gboolean *cancelled)
5472 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5473 gboolean *cancelled)
5475 if (event && event->keyval == GDK_Escape) {
5481 static void compose_exec_ext_editor(Compose *compose)
5487 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5488 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5490 if (pipe(pipe_fds) < 0) {
5495 if ((pid = fork()) < 0) {
5501 /* close the write side of the pipe */
5504 compose->exteditor_file = g_strdup(tmp);
5505 compose->exteditor_pid = pid;
5506 compose->exteditor_readdes = pipe_fds[0];
5508 compose_set_ext_editor_sensitive(compose, FALSE);
5510 compose->exteditor_tag =
5511 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5512 compose_input_cb, compose);
5513 } else { /* process-monitoring process */
5519 /* close the read side of the pipe */
5522 if (compose_write_body_to_file(compose, tmp) < 0) {
5523 fd_write(pipe_fds[1], "2\n", 2);
5527 pid_ed = compose_exec_ext_editor_real(tmp);
5529 fd_write(pipe_fds[1], "1\n", 2);
5533 /* wait until editor is terminated */
5534 waitpid(pid_ed, NULL, 0);
5536 fd_write(pipe_fds[1], "0\n", 2);
5543 static gint compose_exec_ext_editor_real(const gchar *file)
5545 static gchar *def_cmd = "emacs %s";
5551 g_return_val_if_fail(file != NULL, -1);
5553 if ((pid = fork()) < 0) {
5558 if (pid != 0) return pid;
5560 /* grandchild process */
5562 if (setpgid(0, getppid()))
5565 if (prefs_common.ext_editor_cmd &&
5566 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5567 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5568 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5570 if (prefs_common.ext_editor_cmd)
5571 g_warning(_("External editor command line is invalid: `%s'\n"),
5572 prefs_common.ext_editor_cmd);
5573 g_snprintf(buf, sizeof(buf), def_cmd, file);
5576 cmdline = strsplit_with_quote(buf, " ", 1024);
5577 execvp(cmdline[0], cmdline);
5580 g_strfreev(cmdline);
5585 static gboolean compose_ext_editor_kill(Compose *compose)
5587 pid_t pgid = compose->exteditor_pid * -1;
5590 ret = kill(pgid, 0);
5592 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5596 msg = g_strdup_printf
5597 (_("The external editor is still working.\n"
5598 "Force terminating the process?\n"
5599 "process group id: %d"), -pgid);
5600 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5603 if (val == G_ALERTDEFAULT) {
5604 gdk_input_remove(compose->exteditor_tag);
5605 close(compose->exteditor_readdes);
5607 if (kill(pgid, SIGTERM) < 0) perror("kill");
5608 waitpid(compose->exteditor_pid, NULL, 0);
5610 g_warning(_("Terminated process group id: %d"), -pgid);
5611 g_warning(_("Temporary file: %s"),
5612 compose->exteditor_file);
5614 compose_set_ext_editor_sensitive(compose, TRUE);
5616 g_free(compose->exteditor_file);
5617 compose->exteditor_file = NULL;
5618 compose->exteditor_pid = -1;
5619 compose->exteditor_readdes = -1;
5620 compose->exteditor_tag = -1;
5628 static void compose_input_cb(gpointer data, gint source,
5629 GdkInputCondition condition)
5632 Compose *compose = (Compose *)data;
5635 debug_print(_("Compose: input from monitoring process\n"));
5637 gdk_input_remove(compose->exteditor_tag);
5640 if (read(source, &buf[i], 1) < 1) {
5644 if (buf[i] == '\n') {
5649 if (i == sizeof(buf) - 1)
5653 waitpid(compose->exteditor_pid, NULL, 0);
5655 if (buf[0] == '0') { /* success */
5656 GtkSText *text = GTK_STEXT(compose->text);
5658 gtk_stext_freeze(text);
5659 gtk_stext_set_point(text, 0);
5660 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5661 compose_insert_file(compose, compose->exteditor_file);
5662 compose_changed_cb(NULL, compose);
5663 gtk_stext_thaw(text);
5665 if (unlink(compose->exteditor_file) < 0)
5666 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5667 } else if (buf[0] == '1') { /* failed */
5668 g_warning(_("Couldn't exec external editor\n"));
5669 if (unlink(compose->exteditor_file) < 0)
5670 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5671 } else if (buf[0] == '2') {
5672 g_warning(_("Couldn't write to file\n"));
5673 } else if (buf[0] == '3') {
5674 g_warning(_("Pipe read failed\n"));
5679 compose_set_ext_editor_sensitive(compose, TRUE);
5681 g_free(compose->exteditor_file);
5682 compose->exteditor_file = NULL;
5683 compose->exteditor_pid = -1;
5684 compose->exteditor_readdes = -1;
5685 compose->exteditor_tag = -1;
5688 static void compose_set_ext_editor_sensitive(Compose *compose,
5691 GtkItemFactory *ifactory;
5693 ifactory = gtk_item_factory_from_widget(compose->menubar);
5695 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5696 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5697 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5699 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5700 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5701 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5702 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5703 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5706 gtk_widget_set_sensitive(compose->text, sensitive);
5707 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5708 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5709 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5710 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5711 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5712 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5713 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5717 * compose_undo_state_changed:
5719 * Change the sensivity of the menuentries undo and redo
5721 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5722 gint redo_state, gpointer data)
5724 GtkWidget *widget = GTK_WIDGET(data);
5725 GtkItemFactory *ifactory;
5727 g_return_if_fail(widget != NULL);
5729 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
5731 ifactory = gtk_item_factory_from_widget(widget);
5733 switch (undo_state) {
5734 case UNDO_STATE_TRUE:
5735 if (!undostruct->undo_state) {
5736 debug_print ("Set_undo - Testpoint\n");
5737 undostruct->undo_state = TRUE;
5738 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5741 case UNDO_STATE_FALSE:
5742 if (undostruct->undo_state) {
5743 undostruct->undo_state = FALSE;
5744 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5747 case UNDO_STATE_UNCHANGED:
5749 case UNDO_STATE_REFRESH:
5750 menu_set_sensitive(ifactory, "/Edit/Undo",
5751 undostruct->undo_state);
5754 g_warning("Undo state not recognized");
5758 switch (redo_state) {
5759 case UNDO_STATE_TRUE:
5760 if (!undostruct->redo_state) {
5761 undostruct->redo_state = TRUE;
5762 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5765 case UNDO_STATE_FALSE:
5766 if (undostruct->redo_state) {
5767 undostruct->redo_state = FALSE;
5768 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5771 case UNDO_STATE_UNCHANGED:
5773 case UNDO_STATE_REFRESH:
5774 menu_set_sensitive(ifactory, "/Edit/Redo",
5775 undostruct->redo_state);
5778 g_warning("Redo state not recognized");
5783 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5787 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5788 cursor_pos = MAX(cursor_pos, 0);
5793 /* callback functions */
5795 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5796 * includes "non-client" (windows-izm) in calculation, so this calculation
5797 * may not be accurate.
5799 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5800 GtkAllocation *allocation,
5801 GtkSHRuler *shruler)
5803 if (prefs_common.show_ruler) {
5805 gint line_width_in_chars;
5807 char_width = gtkut_get_font_width
5808 (GTK_WIDGET(widget)->style->font);
5809 line_width_in_chars =
5810 (allocation->width - allocation->x) / char_width;
5812 /* got the maximum */
5813 gtk_ruler_set_range(GTK_RULER(shruler),
5814 0.0, line_width_in_chars,
5815 calc_cursor_xpos(GTK_STEXT(widget),
5818 /*line_width_in_chars*/ char_width);
5824 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5826 compose_send_cb(data, 0, NULL);
5829 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5831 compose_send_later_cb(data, 0, NULL);
5834 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5836 compose_draft_cb(data, 0, NULL);
5839 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5841 compose_insert_file_cb(data, 0, NULL);
5844 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5846 compose_attach_cb(data, 0, NULL);
5849 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5851 Compose *compose = (Compose *)data;
5853 compose_insert_sig(compose);
5856 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5858 Compose *compose = (Compose *)data;
5860 compose_exec_ext_editor(compose);
5863 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5865 Compose *compose = (Compose *)data;
5867 compose_wrap_line(compose);
5870 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5872 compose_address_cb(data, 0, NULL);
5875 static void select_account(Compose * compose, PrefsAccount * ac)
5878 GtkItemFactory *ifactory;
5879 GtkWidget *menuitem;
5880 #endif /* USE_GPGME */
5881 compose->account = ac;
5882 compose_set_title(compose);
5884 #if 0 /* NEW COMPOSE GUI */
5885 if (ac->protocol == A_NNTP) {
5886 GtkItemFactory *ifactory;
5887 GtkWidget *menuitem;
5889 ifactory = gtk_item_factory_from_widget(compose->menubar);
5890 menu_set_sensitive(ifactory,
5891 "/Message/Followup to", TRUE);
5892 gtk_widget_show(compose->newsgroups_hbox);
5893 gtk_widget_show(compose->newsgroups_entry);
5894 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5897 compose->use_to = FALSE;
5898 compose->use_cc = FALSE;
5900 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5901 gtk_check_menu_item_set_active
5902 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5904 menu_set_sensitive(ifactory,
5905 "/Message/To", TRUE);
5906 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5907 gtk_check_menu_item_set_active
5908 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5910 gtk_widget_hide(compose->to_hbox);
5911 gtk_widget_hide(compose->to_entry);
5912 gtk_widget_hide(compose->cc_hbox);
5913 gtk_widget_hide(compose->cc_entry);
5914 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5916 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5920 GtkItemFactory *ifactory;
5921 GtkWidget *menuitem;
5923 ifactory = gtk_item_factory_from_widget(compose->menubar);
5924 menu_set_sensitive(ifactory,
5925 "/Message/Followup to", FALSE);
5926 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5927 gtk_widget_hide(compose->newsgroups_hbox);
5928 gtk_widget_hide(compose->newsgroups_entry);
5929 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5932 compose->use_to = TRUE;
5933 compose->use_cc = TRUE;
5935 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5936 gtk_check_menu_item_set_active
5937 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5938 menu_set_sensitive(ifactory,
5939 "/Message/To", FALSE);
5940 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5941 gtk_check_menu_item_set_active
5942 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5943 gtk_widget_show(compose->to_hbox);
5944 gtk_widget_show(compose->to_entry);
5945 gtk_widget_show(compose->cc_hbox);
5946 gtk_widget_show(compose->cc_entry);
5948 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5950 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5953 gtk_widget_queue_resize(compose->table_vbox);
5956 ifactory = gtk_item_factory_from_widget(compose->menubar);
5957 menu_set_sensitive(ifactory,
5958 "/Message/Sign", TRUE);
5959 menu_set_sensitive(ifactory,
5960 "/Message/Encrypt", TRUE);
5962 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
5963 if (ac->default_sign)
5964 gtk_check_menu_item_set_active
5965 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5967 gtk_check_menu_item_set_active
5968 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5970 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
5971 if (ac->default_encrypt)
5972 gtk_check_menu_item_set_active
5973 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5975 gtk_check_menu_item_set_active
5976 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5977 #endif /* USE_GPGME */
5981 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5983 Compose *compose = (Compose *)data;
5987 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5988 g_return_if_fail(ac != NULL);
5990 if (ac != compose->account)
5991 select_account(compose, ac);
5994 static void attach_selected(GtkCList *clist, gint row, gint column,
5995 GdkEvent *event, gpointer data)
5997 Compose *compose = (Compose *)data;
5999 if (event && event->type == GDK_2BUTTON_PRESS)
6000 compose_attach_property(compose);
6003 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6006 Compose *compose = (Compose *)data;
6007 GtkCList *clist = GTK_CLIST(compose->attach_clist);
6012 if (event->button == 3) {
6013 if ((clist->selection && !clist->selection->next) ||
6014 !clist->selection) {
6015 gtk_clist_unselect_all(clist);
6016 if (gtk_clist_get_selection_info(clist,
6019 gtk_clist_select_row(clist, row, column);
6020 gtkut_clist_set_focus_row(clist, row);
6023 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6024 NULL, NULL, event->button, event->time);
6028 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6031 Compose *compose = (Compose *)data;
6035 switch (event->keyval) {
6037 compose_attach_remove_selected(compose);
6042 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6044 Compose *compose = (Compose *)data;
6047 if (prefs_common.work_offline)
6048 if (alertpanel(_("Offline warning"),
6049 _("You're working offline. Override?"),
6050 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
6053 val = compose_send(compose);
6055 if (val == 0) gtk_widget_destroy(compose->window);
6058 static void compose_send_later_cb(gpointer data, guint action,
6061 Compose *compose = (Compose *)data;
6064 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6065 if (!val) gtk_widget_destroy(compose->window);
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;
6079 draft = account_get_special_folder(compose->account, F_DRAFT);
6080 g_return_if_fail(draft != NULL);
6084 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
6085 G_DIR_SEPARATOR, (gint)compose);
6087 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
6093 folder_item_scan(draft);
6094 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) < 0) {
6101 draft->mtime = 0; /* force updating */
6103 if (compose->mode == COMPOSE_REEDIT) {
6104 compose_remove_reedit_target(compose);
6105 if (compose->targetinfo &&
6106 compose->targetinfo->folder != draft)
6107 folderview_update_item(compose->targetinfo->folder,
6111 procmsg_add_flags(draft, msgnum, flag);
6112 folder_item_scan(draft);
6113 folderview_update_item(draft, TRUE);
6117 /* 0: quit editing 1: keep editing */
6119 gtk_widget_destroy(compose->window);
6124 path = folder_item_fetch_msg(draft, msgnum);
6125 g_return_if_fail(path != NULL);
6126 if (stat(path, &s) < 0) {
6127 FILE_OP_ERROR(path, "stat");
6134 procmsg_msginfo_free(compose->targetinfo);
6135 compose->targetinfo = g_new0(MsgInfo, 1);
6136 compose->targetinfo->msgnum = msgnum;
6137 compose->targetinfo->size = s.st_size;
6138 compose->targetinfo->mtime = s.st_mtime;
6139 compose->targetinfo->folder = draft;
6140 compose->mode = COMPOSE_REEDIT;
6144 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6146 Compose *compose = (Compose *)data;
6149 if (compose->bounce_filename != NULL)
6152 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6157 for ( tmp = file_list; tmp; tmp = tmp->next) {
6158 gchar *file = (gchar *) tmp->data;
6159 compose_attach_append(compose, file, file, NULL);
6160 compose_changed_cb(NULL, compose);
6163 g_list_free(file_list);
6167 static void compose_insert_file_cb(gpointer data, guint action,
6170 Compose *compose = (Compose *)data;
6173 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6178 for ( tmp = file_list; tmp; tmp = tmp->next) {
6179 gchar *file = (gchar *) tmp->data;
6180 compose_insert_file(compose, file);
6183 g_list_free(file_list);
6187 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6190 compose_close_cb(data, 0, NULL);
6194 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6196 Compose *compose = (Compose *)data;
6199 if (compose->exteditor_tag != -1) {
6200 if (!compose_ext_editor_kill(compose))
6204 if (compose->modified) {
6205 val = alertpanel(_("Discard message"),
6206 _("This message has been modified. discard it?"),
6207 _("Discard"), _("to Draft"), _("Cancel"));
6210 case G_ALERTDEFAULT:
6212 case G_ALERTALTERNATE:
6213 compose_draft_cb(data, 0, NULL);
6219 gtk_widget_destroy(compose->window);
6222 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6224 Compose *compose = (Compose *)data;
6226 addressbook_open(compose);
6229 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6231 Compose *compose = (Compose *)data;
6236 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6237 g_return_if_fail(tmpl != NULL);
6239 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6241 val = alertpanel(_("Apply template"), msg,
6242 _("Replace"), _("Insert"), _("Cancel"));
6245 if (val == G_ALERTDEFAULT)
6246 compose_template_apply(compose, tmpl, TRUE);
6247 else if (val == G_ALERTALTERNATE)
6248 compose_template_apply(compose, tmpl, FALSE);
6251 static void compose_ext_editor_cb(gpointer data, guint action,
6254 Compose *compose = (Compose *)data;
6256 compose_exec_ext_editor(compose);
6259 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6261 compose_destroy(compose);
6264 static void compose_undo_cb(Compose *compose)
6266 undo_undo(compose->undostruct);
6269 static void compose_redo_cb(Compose *compose)
6271 undo_redo(compose->undostruct);
6274 static void compose_cut_cb(Compose *compose)
6276 if (compose->focused_editable &&
6277 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6278 gtk_editable_cut_clipboard
6279 (GTK_EDITABLE(compose->focused_editable));
6282 static void compose_copy_cb(Compose *compose)
6284 if (compose->focused_editable &&
6285 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6286 gtk_editable_copy_clipboard
6287 (GTK_EDITABLE(compose->focused_editable));
6290 static void compose_paste_cb(Compose *compose)
6292 if (compose->focused_editable &&
6293 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6294 gtk_editable_paste_clipboard
6295 (GTK_EDITABLE(compose->focused_editable));
6298 static void compose_allsel_cb(Compose *compose)
6300 if (compose->focused_editable &&
6301 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6302 gtk_editable_select_region
6303 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6306 static void compose_move_beginning_of_line_cb(Compose *compose)
6308 if (compose->focused_editable &&
6309 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6310 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6313 static void compose_gtk_stext_action_cb(Compose *compose, ComposeCallGtkSTextAction action)
6315 if (!(compose->focused_editable && GTK_WIDGET_HAS_FOCUS(compose->focused_editable))) return;
6318 case COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE:
6319 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6321 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER:
6322 gtk_stext_move_forward_character(GTK_STEXT(compose->focused_editable));
6324 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER:
6325 gtk_stext_move_backward_character(GTK_STEXT(compose->focused_editable));
6327 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD:
6328 gtk_stext_move_forward_word(GTK_STEXT(compose->focused_editable));
6330 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD:
6331 gtk_stext_move_backward_word(GTK_STEXT(compose->focused_editable));
6333 case COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE:
6334 gtk_stext_move_end_of_line(GTK_STEXT(compose->focused_editable));
6336 case COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE:
6337 gtk_stext_move_next_line(GTK_STEXT(compose->focused_editable));
6339 case COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE:
6340 gtk_stext_move_previous_line(GTK_STEXT(compose->focused_editable));
6342 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER:
6343 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6345 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER:
6346 gtk_stext_delete_backward_character(GTK_STEXT(compose->focused_editable));
6348 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD:
6349 gtk_stext_delete_forward_word(GTK_STEXT(compose->focused_editable));
6351 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD:
6352 gtk_stext_delete_backward_word(GTK_STEXT(compose->focused_editable));
6354 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE:
6355 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6357 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N:
6358 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6359 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6361 case COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END:
6362 gtk_stext_delete_to_line_end(GTK_STEXT(compose->focused_editable));
6369 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6371 if (GTK_IS_EDITABLE(widget))
6372 compose->focused_editable = widget;
6375 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6377 if (compose->modified == FALSE) {
6378 compose->modified = TRUE;
6379 compose_set_title(compose);
6383 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6386 gtk_stext_set_point(GTK_STEXT(widget),
6387 gtk_editable_get_position(GTK_EDITABLE(widget)));
6391 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6394 gtk_stext_set_point(GTK_STEXT(widget),
6395 gtk_editable_get_position(GTK_EDITABLE(widget)));
6399 #if 0 /* NEW COMPOSE GUI */
6400 static void compose_toggle_to_cb(gpointer data, guint action,
6403 Compose *compose = (Compose *)data;
6405 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6406 gtk_widget_show(compose->to_hbox);
6407 gtk_widget_show(compose->to_entry);
6408 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6409 compose->use_to = TRUE;
6411 gtk_widget_hide(compose->to_hbox);
6412 gtk_widget_hide(compose->to_entry);
6413 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6414 gtk_widget_queue_resize(compose->table_vbox);
6415 compose->use_to = FALSE;
6418 if (addressbook_get_target_compose() == compose)
6419 addressbook_set_target_compose(compose);
6422 static void compose_toggle_cc_cb(gpointer data, guint action,
6425 Compose *compose = (Compose *)data;
6427 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6428 gtk_widget_show(compose->cc_hbox);
6429 gtk_widget_show(compose->cc_entry);
6430 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6431 compose->use_cc = TRUE;
6433 gtk_widget_hide(compose->cc_hbox);
6434 gtk_widget_hide(compose->cc_entry);
6435 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6436 gtk_widget_queue_resize(compose->table_vbox);
6437 compose->use_cc = FALSE;
6440 if (addressbook_get_target_compose() == compose)
6441 addressbook_set_target_compose(compose);
6444 static void compose_toggle_bcc_cb(gpointer data, guint action,
6447 Compose *compose = (Compose *)data;
6449 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6450 gtk_widget_show(compose->bcc_hbox);
6451 gtk_widget_show(compose->bcc_entry);
6452 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6453 compose->use_bcc = TRUE;
6455 gtk_widget_hide(compose->bcc_hbox);
6456 gtk_widget_hide(compose->bcc_entry);
6457 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6458 gtk_widget_queue_resize(compose->table_vbox);
6459 compose->use_bcc = FALSE;
6462 if (addressbook_get_target_compose() == compose)
6463 addressbook_set_target_compose(compose);
6466 static void compose_toggle_replyto_cb(gpointer data, guint action,
6469 Compose *compose = (Compose *)data;
6471 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6472 gtk_widget_show(compose->reply_hbox);
6473 gtk_widget_show(compose->reply_entry);
6474 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6475 compose->use_replyto = TRUE;
6477 gtk_widget_hide(compose->reply_hbox);
6478 gtk_widget_hide(compose->reply_entry);
6479 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6480 gtk_widget_queue_resize(compose->table_vbox);
6481 compose->use_replyto = FALSE;
6485 static void compose_toggle_followupto_cb(gpointer data, guint action,
6488 Compose *compose = (Compose *)data;
6490 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6491 gtk_widget_show(compose->followup_hbox);
6492 gtk_widget_show(compose->followup_entry);
6493 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6494 compose->use_followupto = TRUE;
6496 gtk_widget_hide(compose->followup_hbox);
6497 gtk_widget_hide(compose->followup_entry);
6498 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6499 gtk_widget_queue_resize(compose->table_vbox);
6500 compose->use_followupto = FALSE;
6504 static void compose_toggle_attach_cb(gpointer data, guint action,
6507 Compose *compose = (Compose *)data;
6509 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6510 gtk_widget_ref(compose->edit_vbox);
6512 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6513 compose->edit_vbox);
6514 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6515 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6517 gtk_widget_show(compose->paned);
6519 gtk_widget_unref(compose->edit_vbox);
6520 gtk_widget_unref(compose->paned);
6522 compose->use_attach = TRUE;
6524 gtk_widget_ref(compose->paned);
6525 gtk_widget_ref(compose->edit_vbox);
6527 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6529 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6530 compose->edit_vbox);
6531 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6532 compose->edit_vbox, TRUE, TRUE, 0);
6534 gtk_widget_unref(compose->edit_vbox);
6536 compose->use_attach = FALSE;
6542 static void compose_toggle_sign_cb(gpointer data, guint action,
6545 Compose *compose = (Compose *)data;
6547 if (GTK_CHECK_MENU_ITEM(widget)->active)
6548 compose->use_signing = TRUE;
6550 compose->use_signing = FALSE;
6553 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6556 Compose *compose = (Compose *)data;
6558 if (GTK_CHECK_MENU_ITEM(widget)->active)
6559 compose->use_encryption = TRUE;
6561 compose->use_encryption = FALSE;
6563 #endif /* USE_GPGME */
6565 static void compose_toggle_ruler_cb(gpointer data, guint action,
6568 Compose *compose = (Compose *)data;
6570 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6571 gtk_widget_show(compose->ruler_hbox);
6572 prefs_common.show_ruler = TRUE;
6574 gtk_widget_hide(compose->ruler_hbox);
6575 gtk_widget_queue_resize(compose->edit_vbox);
6576 prefs_common.show_ruler = FALSE;
6580 static void compose_attach_drag_received_cb (GtkWidget *widget,
6581 GdkDragContext *drag_context,
6584 GtkSelectionData *data,
6589 Compose *compose = (Compose *)user_data;
6592 list = uri_list_extract_filenames((const gchar *)data->data);
6593 for (tmp = list; tmp != NULL; tmp = tmp->next)
6594 compose_attach_append
6595 (compose, (const gchar *)tmp->data,
6596 (const gchar *)tmp->data, NULL);
6597 if (list) compose_changed_cb(NULL, compose);
6598 list_free_strings(list);
6602 static void compose_insert_drag_received_cb (GtkWidget *widget,
6603 GdkDragContext *drag_context,
6606 GtkSelectionData *data,
6611 Compose *compose = (Compose *)user_data;
6614 list = uri_list_extract_filenames((const gchar *)data->data);
6615 for (tmp = list; tmp != NULL; tmp = tmp->next)
6616 compose_insert_file(compose, (const gchar *)tmp->data);
6617 list_free_strings(list);
6621 #if 0 /* NEW COMPOSE GUI */
6622 static void to_activated(GtkWidget *widget, Compose *compose)
6624 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6625 gtk_widget_grab_focus(compose->newsgroups_entry);
6627 gtk_widget_grab_focus(compose->subject_entry);
6630 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6632 gtk_widget_grab_focus(compose->subject_entry);
6635 static void subject_activated(GtkWidget *widget, Compose *compose)
6637 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6638 gtk_widget_grab_focus(compose->cc_entry);
6639 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6640 gtk_widget_grab_focus(compose->bcc_entry);
6641 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6642 gtk_widget_grab_focus(compose->reply_entry);
6643 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6644 gtk_widget_grab_focus(compose->followup_entry);
6646 gtk_widget_grab_focus(compose->text);
6649 static void cc_activated(GtkWidget *widget, Compose *compose)
6651 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6652 gtk_widget_grab_focus(compose->bcc_entry);
6653 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6654 gtk_widget_grab_focus(compose->reply_entry);
6655 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6656 gtk_widget_grab_focus(compose->followup_entry);
6658 gtk_widget_grab_focus(compose->text);
6661 static void bcc_activated(GtkWidget *widget, Compose *compose)
6663 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6664 gtk_widget_grab_focus(compose->reply_entry);
6665 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6666 gtk_widget_grab_focus(compose->followup_entry);
6668 gtk_widget_grab_focus(compose->text);
6671 static void replyto_activated(GtkWidget *widget, Compose *compose)
6673 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6674 gtk_widget_grab_focus(compose->followup_entry);
6676 gtk_widget_grab_focus(compose->text);
6679 static void followupto_activated(GtkWidget *widget, Compose *compose)
6681 gtk_widget_grab_focus(compose->text);
6685 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6688 Compose *compose = (Compose *)data;
6690 if (GTK_CHECK_MENU_ITEM(widget)->active)
6691 compose->return_receipt = TRUE;
6693 compose->return_receipt = FALSE;
6696 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6698 ComposeHeaderEntry *headerentry)
6700 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6701 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6702 !(event->state & GDK_MODIFIER_MASK) &&
6703 (event->keyval == GDK_BackSpace) &&
6704 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6705 gtk_container_remove
6706 (GTK_CONTAINER(headerentry->compose->header_table),
6707 headerentry->combo);
6708 gtk_container_remove
6709 (GTK_CONTAINER(headerentry->compose->header_table),
6710 headerentry->entry);
6711 headerentry->compose->header_list =
6712 g_slist_remove(headerentry->compose->header_list,
6714 g_free(headerentry);
6715 } else if (event->keyval == GDK_Tab) {
6716 if (headerentry->compose->header_last == headerentry) {
6717 /* Override default next focus, and give it to subject_entry
6718 * instead of notebook tabs
6720 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6721 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6727 void compose_headerentry_changed_cb(GtkWidget *entry,
6728 ComposeHeaderEntry *headerentry)
6730 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6731 headerentry->compose->header_list =
6732 g_slist_append(headerentry->compose->header_list,
6734 compose_create_header_entry(headerentry->compose);
6735 gtk_signal_disconnect_by_func
6737 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6739 /* Automatically scroll down */
6740 compose_show_first_last_header(headerentry->compose, FALSE);
6745 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6747 GtkAdjustment *vadj;
6749 g_return_if_fail(compose);
6750 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6751 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6753 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6754 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6757 static void text_activated(GtkWidget *widget, Compose *compose)
6759 compose_send_control_enter(compose);
6762 static gboolean compose_send_control_enter(Compose *compose)
6766 GtkItemFactory *ifactory;
6767 GtkAccelEntry *accel;
6768 GtkWidget *send_menu;
6770 GdkModifierType ignored_mods =
6771 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
6772 GDK_MOD4_MASK | GDK_MOD5_MASK);
6774 ev = gtk_get_current_event();
6775 if (ev->type != GDK_KEY_PRESS) return FALSE;
6777 kev = (GdkEventKey *)ev;
6778 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6781 ifactory = gtk_item_factory_from_widget(compose->menubar);
6782 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6783 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6784 accel = (GtkAccelEntry *)list->data;
6785 if (accel->accelerator_key == kev->keyval &&
6786 (accel->accelerator_mods & ~ignored_mods) ==
6787 (kev->state & ~ignored_mods)) {
6788 compose_send_cb(compose, 0, NULL);
6796 static void compose_check_all(Compose *compose)
6798 if (compose->gtkpspell)
6799 gtkpspell_check_all(compose->gtkpspell);
6802 static void compose_highlight_all(Compose *compose)
6804 if (compose->gtkpspell)
6805 gtkpspell_highlight_all(compose->gtkpspell);
6808 static void compose_check_backwards(Compose *compose)
6810 if (compose->gtkpspell)
6811 gtkpspell_check_backwards(compose->gtkpspell);
6813 GtkItemFactory *ifactory;
6814 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6815 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6816 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6820 static void compose_check_forwards_go(Compose *compose)
6822 if (compose->gtkpspell)
6823 gtkpspell_check_forwards_go(compose->gtkpspell);
6825 GtkItemFactory *ifactory;
6826 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6827 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6828 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6833 static void set_toolbar_style(Compose *compose)
6835 switch (prefs_common.toolbar_style) {
6837 gtk_widget_hide(compose->handlebox);
6840 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6844 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6848 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6853 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
6854 gtk_widget_show(compose->handlebox);
6855 gtk_widget_queue_resize(compose->handlebox);