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;
141 #define B64_LINE_SIZE 57
142 #define B64_BUFFSIZE 77
144 #define MAX_REFERENCES_LEN 999
146 static GdkColor quote_color = {0, 0, 0, 0xbfff};
148 static GList *compose_list = NULL;
150 Compose *compose_generic_new (PrefsAccount *account,
154 static Compose *compose_create (PrefsAccount *account,
156 static void compose_toolbar_create (Compose *compose,
157 GtkWidget *container);
158 static GtkWidget *compose_account_option_menu_create
160 static void compose_set_template_menu (Compose *compose);
161 static void compose_template_apply (Compose *compose,
164 static void compose_destroy (Compose *compose);
166 static void compose_entries_set (Compose *compose,
167 const gchar *mailto);
168 static gint compose_parse_header (Compose *compose,
170 static gchar *compose_parse_references (const gchar *ref,
173 static gchar *compose_quote_fmt (Compose *compose,
179 static void compose_reply_set_entry (Compose *compose,
184 followup_and_reply_to);
185 static void compose_reedit_set_entry (Compose *compose,
187 static void compose_insert_sig (Compose *compose);
188 static void compose_insert_file (Compose *compose,
190 static void compose_attach_append (Compose *compose,
193 const gchar *content_type);
194 static void compose_attach_parts (Compose *compose,
196 static void compose_wrap_line (Compose *compose);
197 static void compose_wrap_line_all (Compose *compose);
198 static void compose_set_title (Compose *compose);
200 static PrefsAccount *compose_current_mail_account(void);
201 /* static gint compose_send (Compose *compose); */
202 static gboolean compose_check_for_valid_recipient
204 static gboolean compose_check_entries (Compose *compose,
205 gboolean check_subject);
206 static gint compose_write_to_file (Compose *compose,
209 static gint compose_write_body_to_file (Compose *compose,
211 static gint compose_remove_reedit_target (Compose *compose);
212 static gint compose_queue (Compose *compose,
215 static gint compose_queue_sub (Compose *compose,
218 gboolean check_subject);
219 static void compose_write_attach (Compose *compose,
221 static gint compose_write_headers (Compose *compose,
223 const gchar *charset,
224 EncodingType encoding,
227 static void compose_convert_header (gchar *dest,
231 static void compose_generate_msgid (Compose *compose,
235 static void compose_attach_info_free (AttachInfo *ainfo);
236 static void compose_attach_remove_selected (Compose *compose);
238 static void compose_attach_property (Compose *compose);
239 static void compose_attach_property_create (gboolean *cancelled);
240 static void attach_property_ok (GtkWidget *widget,
241 gboolean *cancelled);
242 static void attach_property_cancel (GtkWidget *widget,
243 gboolean *cancelled);
244 static gint attach_property_delete_event (GtkWidget *widget,
246 gboolean *cancelled);
247 static void attach_property_key_pressed (GtkWidget *widget,
249 gboolean *cancelled);
251 static void compose_exec_ext_editor (Compose *compose);
252 static gint compose_exec_ext_editor_real (const gchar *file);
253 static gboolean compose_ext_editor_kill (Compose *compose);
254 static void compose_input_cb (gpointer data,
256 GdkInputCondition condition);
257 static void compose_set_ext_editor_sensitive (Compose *compose,
260 static void compose_undo_state_changed (UndoMain *undostruct,
265 static gint calc_cursor_xpos (GtkSText *text,
269 static void compose_create_header_entry (Compose *compose);
270 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
272 /* callback functions */
274 static gboolean compose_edit_size_alloc (GtkEditable *widget,
275 GtkAllocation *allocation,
276 GtkSHRuler *shruler);
278 static void toolbar_send_cb (GtkWidget *widget,
280 static void toolbar_send_later_cb (GtkWidget *widget,
282 static void toolbar_draft_cb (GtkWidget *widget,
284 static void toolbar_insert_cb (GtkWidget *widget,
286 static void toolbar_attach_cb (GtkWidget *widget,
288 static void toolbar_sig_cb (GtkWidget *widget,
290 static void toolbar_ext_editor_cb (GtkWidget *widget,
292 static void toolbar_linewrap_cb (GtkWidget *widget,
294 static void toolbar_address_cb (GtkWidget *widget,
297 static void select_account (Compose *compose,
300 static void account_activated (GtkMenuItem *menuitem,
303 static void attach_selected (GtkCList *clist,
308 static void attach_button_pressed (GtkWidget *widget,
309 GdkEventButton *event,
311 static void attach_key_pressed (GtkWidget *widget,
315 static void compose_send_cb (gpointer data,
318 static void compose_send_later_cb (gpointer data,
322 static void compose_draft_cb (gpointer data,
326 static void compose_attach_cb (gpointer data,
329 static void compose_insert_file_cb (gpointer data,
333 static void compose_close_cb (gpointer data,
337 static void compose_address_cb (gpointer data,
340 static void compose_template_activate_cb(GtkWidget *widget,
343 static void compose_ext_editor_cb (gpointer data,
347 static gint compose_delete_cb (GtkWidget *widget,
350 static void compose_destroy_cb (GtkWidget *widget,
353 static void compose_undo_cb (Compose *compose);
354 static void compose_redo_cb (Compose *compose);
355 static void compose_cut_cb (Compose *compose);
356 static void compose_copy_cb (Compose *compose);
357 static void compose_paste_cb (Compose *compose);
358 static void compose_allsel_cb (Compose *compose);
360 static void compose_gtk_stext_action_cb (Compose *compose,
361 ComposeCallGtkSTextAction action);
363 static void compose_grab_focus_cb (GtkWidget *widget,
366 static void compose_changed_cb (GtkEditable *editable,
368 static void compose_button_press_cb (GtkWidget *widget,
369 GdkEventButton *event,
372 static void compose_key_press_cb (GtkWidget *widget,
378 static void compose_toggle_to_cb (gpointer data,
381 static void compose_toggle_cc_cb (gpointer data,
384 static void compose_toggle_bcc_cb (gpointer data,
387 static void compose_toggle_replyto_cb (gpointer data,
390 static void compose_toggle_followupto_cb(gpointer data,
393 static void compose_toggle_attach_cb (gpointer data,
397 static void compose_toggle_ruler_cb (gpointer data,
401 static void compose_toggle_sign_cb (gpointer data,
404 static void compose_toggle_encrypt_cb (gpointer data,
408 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
411 static void compose_attach_drag_received_cb (GtkWidget *widget,
412 GdkDragContext *drag_context,
415 GtkSelectionData *data,
419 static void compose_insert_drag_received_cb (GtkWidget *widget,
420 GdkDragContext *drag_context,
423 GtkSelectionData *data,
429 static void to_activated (GtkWidget *widget,
431 static void newsgroups_activated (GtkWidget *widget,
433 static void subject_activated (GtkWidget *widget,
435 static void cc_activated (GtkWidget *widget,
437 static void bcc_activated (GtkWidget *widget,
439 static void replyto_activated (GtkWidget *widget,
441 static void followupto_activated (GtkWidget *widget,
445 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
447 gboolean ignore_replyto,
448 gboolean followup_and_reply_to,
451 void compose_headerentry_changed_cb (GtkWidget *entry,
452 ComposeHeaderEntry *headerentry);
453 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
455 ComposeHeaderEntry *headerentry);
457 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
460 static void compose_check_all (Compose *compose);
461 static void compose_highlight_all (Compose *compose);
462 static void compose_check_backwards (Compose *compose);
463 static void compose_check_forwards_go (Compose *compose);
466 static gboolean compose_send_control_enter (Compose *compose);
467 static void text_activated (GtkWidget *widget,
470 static GtkItemFactoryEntry compose_popup_entries[] =
472 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
473 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
474 {N_("/---"), NULL, NULL, 0, "<Separator>"},
475 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
478 static GtkItemFactoryEntry compose_entries[] =
480 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
481 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
482 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
483 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
484 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
485 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
487 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
488 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
489 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
490 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
491 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
492 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
493 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
494 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
495 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
496 {N_("/_Edit/A_dvanced/Move a character backward"),
498 compose_gtk_stext_action_cb,
499 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
501 {N_("/_Edit/A_dvanced/Move a character forward"),
503 compose_gtk_stext_action_cb,
504 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
506 {N_("/_Edit/A_dvanced/Move a word backward"),
508 compose_gtk_stext_action_cb,
509 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
511 {N_("/_Edit/A_dvanced/Move a word forward"),
513 compose_gtk_stext_action_cb,
514 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
516 {N_("/_Edit/A_dvanced/Move to beginning of line"),
517 NULL, /* "<control>A" */
518 compose_gtk_stext_action_cb,
519 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
521 {N_("/_Edit/A_dvanced/Move to end of line"),
523 compose_gtk_stext_action_cb,
524 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
526 {N_("/_Edit/A_dvanced/Move to previous line"),
528 compose_gtk_stext_action_cb,
529 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
531 {N_("/_Edit/A_dvanced/Move to next line"),
533 compose_gtk_stext_action_cb,
534 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
536 {N_("/_Edit/A_dvanced/Delete a character backward"),
538 compose_gtk_stext_action_cb,
539 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
541 {N_("/_Edit/A_dvanced/Delete a character forward"),
543 compose_gtk_stext_action_cb,
544 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
546 {N_("/_Edit/A_dvanced/Delete a word backward"),
547 NULL, /* "<control>W" */
548 compose_gtk_stext_action_cb,
549 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
551 {N_("/_Edit/A_dvanced/Delete a word forward"),
552 NULL, /* "<alt>D", */
553 compose_gtk_stext_action_cb,
554 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
556 {N_("/_Edit/A_dvanced/Delete line"),
558 compose_gtk_stext_action_cb,
559 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
561 {N_("/_Edit/A_dvanced/Delete entire line"),
563 compose_gtk_stext_action_cb,
564 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
566 {N_("/_Edit/A_dvanced/Delete to end of line"),
568 compose_gtk_stext_action_cb,
569 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
571 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
572 {N_("/_Edit/_Wrap current paragraph"),
573 "<control>L", compose_wrap_line, 0, NULL},
574 {N_("/_Edit/Wrap all long _lines"),
575 "<control><alt>L", compose_wrap_line_all, 0, NULL},
576 {N_("/_Edit/Edit with e_xternal editor"),
577 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
579 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
580 {N_("/_Spelling/_Check all or check selection"),
581 NULL, compose_check_all, 0, NULL},
582 {N_("/_Spelling/_Highlight all misspelled words"),
583 NULL, compose_highlight_all, 0, NULL},
584 {N_("/_Spelling/Check _backwards misspelled word"),
585 NULL, compose_check_backwards , 0, NULL},
586 {N_("/_Spelling/_Forward to next misspelled word"),
587 NULL, compose_check_forwards_go, 0, NULL},
588 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
589 {N_("/_Spelling/_Spelling Configuration"),
590 NULL, NULL, 0, "<Branch>"},
592 #if 0 /* NEW COMPOSE GUI */
593 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
594 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
595 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
596 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
597 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
598 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
599 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
600 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
601 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
602 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
603 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
605 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
606 {N_("/_Message/_Send"), "<control>Return",
607 compose_send_cb, 0, NULL},
608 {N_("/_Message/Send _later"), "<shift><control>S",
609 compose_send_later_cb, 0, NULL},
610 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
611 {N_("/_Message/Save to _draft folder"),
612 "<shift><control>D", compose_draft_cb, 0, NULL},
613 {N_("/_Message/Save and _keep editing"),
614 "<control>S", compose_draft_cb, 1, NULL},
615 #if 0 /* NEW COMPOSE GUI */
616 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
617 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
618 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
619 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
620 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
621 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
622 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
623 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
624 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
627 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
628 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
629 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
630 #endif /* USE_GPGME */
631 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
632 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
633 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
634 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
635 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
636 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
637 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
638 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
639 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
642 static GtkTargetEntry compose_mime_types[] =
644 {"text/uri-list", 0, 0}
647 Compose *compose_new(PrefsAccount *account)
649 return compose_generic_new(account, NULL, NULL);
652 Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
656 GtkItemFactory *ifactory;
658 c = compose_generic_new(account, NULL, NULL);
660 filename = procmsg_get_message_file(msginfo);
661 if (filename == NULL)
664 c->bounce_filename = filename;
666 if (msginfo->subject)
667 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
669 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
671 compose_quote_fmt(c, msginfo, "%M", NULL, NULL);
672 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
674 ifactory = gtk_item_factory_from_widget(c->popupmenu);
675 menu_set_sensitive(ifactory, "/Add...", FALSE);
676 menu_set_sensitive(ifactory, "/Remove", FALSE);
677 menu_set_sensitive(ifactory, "/Property...", FALSE);
679 ifactory = gtk_item_factory_from_widget(c->menubar);
680 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
681 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
682 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
683 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
684 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
685 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
686 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
687 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
689 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
690 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
692 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
693 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
695 gtk_widget_set_sensitive(c->insert_btn, FALSE);
696 gtk_widget_set_sensitive(c->attach_btn, FALSE);
697 gtk_widget_set_sensitive(c->sig_btn, FALSE);
698 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
699 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
704 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
706 return compose_generic_new(account, mailto, NULL);
709 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
711 return compose_generic_new(account, NULL, item);
714 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
718 if (item && item->prefs && item->prefs->enable_default_account)
719 account = account_find_from_id(item->prefs->default_account);
721 if (!account) account = cur_account;
722 g_return_val_if_fail(account != NULL, NULL);
724 compose = compose_create(account, COMPOSE_NEW);
725 compose->replyinfo = NULL;
727 if (prefs_common.auto_sig)
728 compose_insert_sig(compose);
729 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
730 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
732 if (account->protocol != A_NNTP) {
734 compose_entries_set(compose, mailto);
736 } else if(item && item->prefs->enable_default_to) {
737 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
739 if (item && item->ret_rcpt) {
740 GtkItemFactory *ifactory;
742 ifactory = gtk_item_factory_from_widget(compose->menubar);
743 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
747 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
750 compose_show_first_last_header(compose, TRUE);
752 /* Set save folder */
753 if(item && item->prefs && item->prefs->save_copy_to_folder) {
754 gchar *folderidentifier;
756 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
757 folderidentifier = folder_item_get_identifier(item);
758 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
759 g_free(folderidentifier);
762 gtk_widget_grab_focus(compose->header_last->entry);
764 if (prefs_common.auto_exteditor)
765 compose_exec_ext_editor(compose);
770 #define CHANGE_FLAGS(msginfo) \
772 if (msginfo->folder->folder->change_flags != NULL) \
773 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
779 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
780 const gchar *followupto, gchar * to)
784 if (!account) account = cur_account;
785 g_return_val_if_fail(account != NULL, NULL);
786 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
788 compose = compose_create(account, COMPOSE_NEW);
790 if (prefs_common.auto_sig)
791 compose_insert_sig(compose);
792 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
793 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
795 compose_entry_append(compose, to, COMPOSE_TO);
796 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
797 gtk_widget_grab_focus(compose->subject_entry);
803 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
804 gboolean ignore_replyto, const gchar *body)
806 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE,
810 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
812 gboolean ignore_replyto,
815 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE,
819 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
821 gboolean ignore_replyto,
822 gboolean followup_and_reply_to,
826 PrefsAccount *account;
827 PrefsAccount *reply_account;
830 g_return_if_fail(msginfo != NULL);
831 g_return_if_fail(msginfo->folder != NULL);
834 /* select the account set in folderitem's property (if enabled) */
835 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
836 account = account_find_from_id(msginfo->folder->prefs->default_account);
838 /* select the account for the whole folder (IMAP / NNTP) */
840 /* FIXME: this is not right, because folder may be nested. we should
841 * ascend the tree until we find a parent with proper account
843 account = msginfo->folder->folder->account;
845 /* select account by to: and cc: header if enabled */
846 if (prefs_common.reply_account_autosel) {
847 if (!account && msginfo->to) {
849 Xstrdup_a(to, msginfo->to, return);
851 account = account_find_from_address(to);
855 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
857 account = account_find_from_address(cc);
862 /* select current account */
863 if (!account) account = cur_account;
864 g_return_if_fail(account != NULL);
866 if (ignore_replyto && account->protocol == A_NNTP &&
867 !followup_and_reply_to) {
869 account_find_from_address(account->address);
871 reply_account = compose_current_mail_account();
875 reply_account = account;
877 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
878 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
879 if (MSG_IS_IMAP(msginfo->flags))
880 imap_msg_set_perm_flags(msginfo, MSG_REPLIED);
881 CHANGE_FLAGS(msginfo);
883 compose = compose_create(account, COMPOSE_REPLY);
884 compose->replyinfo = procmsg_msginfo_copy(msginfo);
886 #if 0 /* NEW COMPOSE GUI */
887 if (followup_and_reply_to) {
888 gtk_widget_show(compose->to_hbox);
889 gtk_widget_show(compose->to_entry);
890 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
891 compose->use_to = TRUE;
894 if (msginfo->folder && msginfo->folder->ret_rcpt) {
895 GtkItemFactory *ifactory;
897 ifactory = gtk_item_factory_from_widget(compose->menubar);
898 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
901 /* Set save folder */
902 if(msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
903 gchar *folderidentifier;
905 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
906 folderidentifier = folder_item_get_identifier(msginfo->folder);
907 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
908 g_free(folderidentifier);
911 if (compose_parse_header(compose, msginfo) < 0) return;
912 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
913 followup_and_reply_to);
914 compose_show_first_last_header(compose, TRUE);
916 text = GTK_STEXT(compose->text);
917 gtk_stext_freeze(text);
923 if (prefs_common.quotemark && *prefs_common.quotemark)
924 qmark = prefs_common.quotemark;
928 quote_str = compose_quote_fmt(compose, msginfo,
929 prefs_common.quotefmt,
933 if (prefs_common.auto_sig)
934 compose_insert_sig(compose);
936 if (quote && prefs_common.linewrap_quote)
937 compose_wrap_line_all(compose);
939 gtk_editable_set_position(GTK_EDITABLE(text), 0);
940 gtk_stext_set_point(text, 0);
942 gtk_stext_thaw(text);
943 gtk_widget_grab_focus(compose->text);
945 if (prefs_common.auto_exteditor)
946 compose_exec_ext_editor(compose);
949 static void set_toolbar_style(Compose *compose);
951 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
956 g_return_val_if_fail(mimeinfo != NULL, NULL);
958 base = mimeinfo->filename ? mimeinfo->filename
959 : mimeinfo->name ? mimeinfo->name : NULL;
961 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
962 filename = g_strdup_printf("%s%smimetmp.%08x.html",
969 base = base ? base : "";
970 base = g_basename(base);
972 filename = g_strdup_printf("%s%smimetmp.%08x",
980 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
986 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
990 if (!partinfo) return NULL;
992 filename = procmime_get_file_name(partinfo);
994 if (procmime_get_part(filename, source, partinfo) < 0)
996 (_("Can't get the part of multipart message."));
1003 #define INSERT_FW_HEADER(var, hdr) \
1004 if (msginfo->var && *msginfo->var) { \
1005 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1006 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1007 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1010 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1011 gboolean as_attach, const gchar *body)
1014 /* PrefsAccount *account; */
1017 g_return_val_if_fail(msginfo != NULL, NULL);
1018 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1020 account = msginfo->folder->folder->account;
1021 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1023 Xstrdup_a(to, msginfo->to, return NULL);
1024 extract_address(to);
1025 account = account_find_from_address(to);
1028 if(!account && prefs_common.forward_account_autosel) {
1030 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1031 extract_address(cc);
1032 account = account_find_from_address(cc);
1036 if (account == NULL) {
1037 account = cur_account;
1039 account = msginfo->folder->folder->account;
1040 if (!account) account = cur_account;
1043 g_return_val_if_fail(account != NULL, NULL);
1045 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1046 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1047 if (MSG_IS_IMAP(msginfo->flags))
1048 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1049 CHANGE_FLAGS(msginfo);
1051 compose = compose_create(account, COMPOSE_FORWARD);
1053 if (msginfo->subject && *msginfo->subject) {
1054 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1055 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1059 text = GTK_STEXT(compose->text);
1060 gtk_stext_freeze(text);
1066 msgfile = procmsg_get_message_file_path(msginfo);
1067 if (!is_file_exist(msgfile))
1068 g_warning(_("%s: file not exist\n"), msgfile);
1070 compose_attach_append(compose, msgfile, msgfile,
1078 if (prefs_common.fw_quotemark &&
1079 *prefs_common.fw_quotemark)
1080 qmark = prefs_common.fw_quotemark;
1084 quote_str = compose_quote_fmt(compose, msginfo,
1085 prefs_common.fw_quotefmt,
1087 compose_attach_parts(compose, msginfo);
1090 if (prefs_common.auto_sig)
1091 compose_insert_sig(compose);
1093 if (prefs_common.linewrap_quote)
1094 compose_wrap_line_all(compose);
1096 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1097 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1099 gtk_stext_thaw(text);
1100 #if 0 /* NEW COMPOSE GUI */
1101 if (account->protocol != A_NNTP)
1102 gtk_widget_grab_focus(compose->to_entry);
1104 gtk_widget_grab_focus(compose->newsgroups_entry);
1106 gtk_widget_grab_focus(compose->header_last->entry);
1108 if (prefs_common.auto_exteditor)
1109 compose_exec_ext_editor(compose);
1114 #undef INSERT_FW_HEADER
1116 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1123 g_return_val_if_fail(msginfo_list != NULL, NULL);
1125 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1126 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1130 if (account == NULL) {
1131 account = cur_account;
1133 account = msginfo->folder->folder->account;
1134 if (!account) account = cur_account;
1137 g_return_val_if_fail(account != NULL, NULL);
1139 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1140 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1141 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1142 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1145 compose = compose_create(account, COMPOSE_FORWARD);
1147 text = GTK_STEXT(compose->text);
1148 gtk_stext_freeze(text);
1150 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1151 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1152 if (!is_file_exist(msgfile))
1153 g_warning(_("%s: file not exist\n"), msgfile);
1155 compose_attach_append(compose, msgfile, msgfile,
1160 if (prefs_common.auto_sig)
1161 compose_insert_sig(compose);
1163 if (prefs_common.linewrap_quote)
1164 compose_wrap_line_all(compose);
1166 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1167 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1169 gtk_stext_thaw(text);
1170 #if 0 /* NEW COMPOSE GUI */
1171 if (account->protocol != A_NNTP)
1172 gtk_widget_grab_focus(compose->to_entry);
1174 gtk_widget_grab_focus(compose->newsgroups_entry);
1180 void compose_reedit(MsgInfo *msginfo)
1183 PrefsAccount *account = NULL;
1186 gchar buf[BUFFSIZE];
1188 g_return_if_fail(msginfo != NULL);
1189 g_return_if_fail(msginfo->folder != NULL);
1191 if (msginfo->folder->stype == F_QUEUE) {
1192 gchar queueheader_buf[BUFFSIZE];
1195 /* Select Account from queue headers */
1196 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1197 sizeof(queueheader_buf), "NAID:")) {
1198 id = atoi(&queueheader_buf[5]);
1199 account = account_find_from_id(id);
1201 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1202 sizeof(queueheader_buf), "MAID:")) {
1203 id = atoi(&queueheader_buf[5]);
1204 account = account_find_from_id(id);
1206 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1207 sizeof(queueheader_buf), "S:")) {
1208 account = account_find_from_address(queueheader_buf);
1211 account = msginfo->folder->folder->account;
1213 if (!account && prefs_common.reedit_account_autosel) {
1214 gchar from[BUFFSIZE];
1215 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1216 extract_address(from);
1217 account = account_find_from_address(from);
1220 if (!account) account = cur_account;
1221 g_return_if_fail(account != NULL);
1223 compose = compose_create(account, COMPOSE_REEDIT);
1224 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1226 if (msginfo->folder->stype == F_QUEUE) {
1227 gchar queueheader_buf[BUFFSIZE];
1229 /* Set message save folder */
1230 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1233 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1234 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1235 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1239 if (compose_parse_header(compose, msginfo) < 0) return;
1240 compose_reedit_set_entry(compose, msginfo);
1242 text = GTK_STEXT(compose->text);
1243 gtk_stext_freeze(text);
1245 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1246 g_warning(_("Can't get text part\n"));
1248 while (fgets(buf, sizeof(buf), fp) != NULL)
1249 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1252 compose_attach_parts(compose, msginfo);
1254 gtk_stext_thaw(text);
1255 gtk_widget_grab_focus(compose->text);
1257 if (prefs_common.auto_exteditor)
1258 compose_exec_ext_editor(compose);
1261 GList *compose_get_compose_list(void)
1263 return compose_list;
1266 void compose_entry_append(Compose *compose, const gchar *address,
1267 ComposeEntryType type)
1273 if (!address || *address == '\0') return;
1275 #if 0 /* NEW COMPOSE GUI */
1278 entry = GTK_ENTRY(compose->cc_entry);
1281 entry = GTK_ENTRY(compose->bcc_entry);
1283 case COMPOSE_NEWSGROUPS:
1284 entry = GTK_ENTRY(compose->newsgroups_entry);
1288 entry = GTK_ENTRY(compose->to_entry);
1292 text = gtk_entry_get_text(entry);
1294 gtk_entry_append_text(entry, ", ");
1295 gtk_entry_append_text(entry, address);
1303 header = N_("Bcc:");
1305 case COMPOSE_REPLYTO:
1306 header = N_("Reply-To:");
1308 case COMPOSE_NEWSGROUPS:
1309 header = N_("Newsgroups:");
1311 case COMPOSE_FOLLOWUPTO:
1312 header = N_( "Followup-To:");
1319 header = prefs_common.trans_hdr ? gettext(header) : header;
1321 compose_add_header_entry(compose, header, (gchar *)address);
1324 static void compose_entries_set(Compose *compose, const gchar *mailto)
1326 gchar *subject = NULL;
1334 Xstrdup_a(tmp_mailto, mailto, return);
1338 p = strchr(tmp_mailto, '?');
1345 gchar *field, *value;
1362 if (*value == '\0') continue;
1364 if (!g_strcasecmp(field, "subject")) {
1365 Xalloca(subject, strlen(value) + 1, return);
1366 decode_uri(subject, value);
1367 } else if (!g_strcasecmp(field, "cc")) {
1369 } else if (!g_strcasecmp(field, "bcc")) {
1371 } else if (!g_strcasecmp(field, "body")) {
1372 Xalloca(body, strlen(value) + 1, return);
1373 decode_uri(body, value);
1378 compose_entry_append(compose, to, COMPOSE_TO);
1380 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1382 compose_entry_append(compose, cc, COMPOSE_CC);
1384 compose_entry_append(compose, bcc, COMPOSE_BCC);
1386 gtk_stext_insert(GTK_STEXT(compose->text),
1387 NULL, NULL, NULL, body, -1);
1388 gtk_stext_insert(GTK_STEXT(compose->text),
1389 NULL, NULL, NULL, "\n", 1);
1393 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1395 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1396 {"Cc:", NULL, FALSE},
1397 {"References:", NULL, FALSE},
1398 {"Bcc:", NULL, FALSE},
1399 {"Newsgroups:", NULL, FALSE},
1400 {"Followup-To:", NULL, FALSE},
1401 {"X-Mailing-List:", NULL, FALSE},
1402 {"X-BeenThere:", NULL, FALSE},
1403 {NULL, NULL, FALSE}};
1413 H_X_MAILING_LIST = 6,
1419 g_return_val_if_fail(msginfo != NULL, -1);
1421 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1422 procheader_get_header_fields(fp, hentry);
1425 if (hentry[H_REPLY_TO].body != NULL) {
1426 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1427 compose->replyto = hentry[H_REPLY_TO].body;
1428 hentry[H_REPLY_TO].body = NULL;
1430 if (hentry[H_CC].body != NULL) {
1431 conv_unmime_header_overwrite(hentry[H_CC].body);
1432 compose->cc = hentry[H_CC].body;
1433 hentry[H_CC].body = NULL;
1435 if (hentry[H_X_MAILING_LIST].body != NULL) {
1436 /* this is good enough to parse debian-devel */
1437 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1438 g_return_val_if_fail(buf != NULL, -1 );
1439 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1440 compose->mailinglist = g_strdup(buf);
1442 g_free(hentry[H_X_MAILING_LIST].body);
1443 hentry[H_X_MAILING_LIST].body = NULL ;
1445 if (hentry[H_X_BEENTHERE].body != NULL) {
1446 /* this is good enough to parse the sylpheed-claws lists */
1447 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1448 g_return_val_if_fail(buf != NULL, -1 );
1449 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1450 compose->mailinglist = g_strdup(buf);
1452 g_free(hentry[H_X_BEENTHERE].body);
1453 hentry[H_X_BEENTHERE].body = NULL ;
1455 if (hentry[H_REFERENCES].body != NULL) {
1456 if (compose->mode == COMPOSE_REEDIT)
1457 compose->references = hentry[H_REFERENCES].body;
1459 compose->references = compose_parse_references
1460 (hentry[H_REFERENCES].body, msginfo->msgid);
1461 g_free(hentry[H_REFERENCES].body);
1463 hentry[H_REFERENCES].body = NULL;
1465 if (hentry[H_BCC].body != NULL) {
1466 if (compose->mode == COMPOSE_REEDIT) {
1467 conv_unmime_header_overwrite(hentry[H_BCC].body);
1468 compose->bcc = hentry[H_BCC].body;
1470 g_free(hentry[H_BCC].body);
1471 hentry[H_BCC].body = NULL;
1473 if (hentry[H_NEWSGROUPS].body != NULL) {
1474 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1475 hentry[H_NEWSGROUPS].body = NULL;
1477 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1478 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1479 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1480 hentry[H_FOLLOWUP_TO].body = NULL;
1483 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1484 compose->inreplyto = g_strdup(msginfo->inreplyto);
1485 else if (compose->mode != COMPOSE_REEDIT &&
1486 msginfo->msgid && *msginfo->msgid) {
1487 compose->inreplyto = g_strdup(msginfo->msgid);
1489 if (!compose->references) {
1490 if (msginfo->inreplyto && *msginfo->inreplyto)
1491 compose->references =
1492 g_strdup_printf("<%s>\n\t<%s>",
1496 compose->references =
1497 g_strconcat("<", msginfo->msgid, ">",
1505 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1507 GSList *ref_id_list, *cur;
1511 ref_id_list = references_list_append(NULL, ref);
1512 if (!ref_id_list) return NULL;
1513 if (msgid && *msgid)
1514 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1519 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1520 /* "<" + Message-ID + ">" + CR+LF+TAB */
1521 len += strlen((gchar *)cur->data) + 5;
1523 if (len > MAX_REFERENCES_LEN) {
1524 /* remove second message-ID */
1525 if (ref_id_list && ref_id_list->next &&
1526 ref_id_list->next->next) {
1527 g_free(ref_id_list->next->data);
1528 ref_id_list = g_slist_remove
1529 (ref_id_list, ref_id_list->next->data);
1531 slist_free_strings(ref_id_list);
1532 g_slist_free(ref_id_list);
1539 new_ref = g_string_new("");
1540 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1541 if (new_ref->len > 0)
1542 g_string_append(new_ref, "\n\t");
1543 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1546 slist_free_strings(ref_id_list);
1547 g_slist_free(ref_id_list);
1549 new_ref_str = new_ref->str;
1550 g_string_free(new_ref, FALSE);
1555 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1556 const gchar *fmt, const gchar *qmark,
1559 GtkSText *text = GTK_STEXT(compose->text);
1560 gchar *quote_str = NULL;
1565 if (qmark != NULL) {
1566 quote_fmt_init(msginfo, NULL, NULL);
1567 quote_fmt_scan_string(qmark);
1570 buf = quote_fmt_get_buffer();
1572 alertpanel_error(_("Quote mark format error."));
1574 Xstrdup_a(quote_str, buf, return NULL)
1577 if (fmt && *fmt != '\0') {
1578 quote_fmt_init(msginfo, quote_str, body);
1579 quote_fmt_scan_string(fmt);
1582 buf = quote_fmt_get_buffer();
1584 alertpanel_error(_("Message reply/forward format error."));
1590 gtk_stext_freeze(text);
1592 for (p = buf; *p != '\0'; ) {
1593 lastp = strchr(p, '\n');
1594 len = lastp ? lastp - p + 1 : -1;
1595 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1602 gtk_stext_thaw(text);
1607 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1608 gboolean to_all, gboolean ignore_replyto,
1609 gboolean followup_and_reply_to)
1611 GSList *cc_list = NULL;
1614 gchar *replyto = NULL;
1615 GHashTable *to_table;
1617 g_return_if_fail(compose->account != NULL);
1618 g_return_if_fail(msginfo != NULL);
1620 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1621 compose_entry_append(compose,
1622 ((compose->replyto && !ignore_replyto)
1624 : (compose->mailinglist && !ignore_replyto)
1625 ? compose->mailinglist
1626 : msginfo->from ? msginfo->from : ""),
1629 if (compose->account->protocol == A_NNTP) {
1631 compose_entry_append
1632 (compose, msginfo->from ? msginfo->from : "",
1635 compose_entry_append
1637 compose->followup_to ? compose->followup_to
1638 : compose->newsgroups ? compose->newsgroups
1640 COMPOSE_NEWSGROUPS);
1643 if (msginfo->subject && *msginfo->subject) {
1644 gchar *buf, *buf2, *p;
1646 buf = g_strdup(msginfo->subject);
1647 while (!strncasecmp(buf, "Re:", 3)) {
1649 while (isspace(*p)) p++;
1650 memmove(buf, p, strlen(p) + 1);
1653 buf2 = g_strdup_printf("Re: %s", buf);
1654 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1658 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1660 if (!to_all || compose->account->protocol == A_NNTP) return;
1662 if (compose->replyto) {
1663 Xstrdup_a(replyto, compose->replyto, return);
1664 extract_address(replyto);
1666 if (msginfo->from) {
1667 Xstrdup_a(from, msginfo->from, return);
1668 extract_address(from);
1671 if (compose->mailinglist && from) {
1672 cc_list = address_list_append(cc_list, from);
1675 if (replyto && from)
1676 cc_list = address_list_append(cc_list, from);
1678 if (!compose->mailinglist)
1679 cc_list = address_list_append(cc_list, msginfo->to);
1681 cc_list = address_list_append(cc_list, compose->cc);
1683 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1685 g_hash_table_insert(to_table, replyto, GINT_TO_POINTER(1));
1686 if (compose->account)
1687 g_hash_table_insert(to_table, compose->account->address,
1688 GINT_TO_POINTER(1));
1690 /* remove address on To: and that of current account */
1691 for (cur = cc_list; cur != NULL; ) {
1692 GSList *next = cur->next;
1694 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1695 cc_list = g_slist_remove(cc_list, cur->data);
1697 g_hash_table_insert(to_table, cur->data, cur);
1701 g_hash_table_destroy(to_table);
1704 for (cur = cc_list; cur != NULL; cur = cur->next)
1705 compose_entry_append(compose, (gchar *)cur->data,
1707 slist_free_strings(cc_list);
1708 g_slist_free(cc_list);
1712 #define SET_ENTRY(entry, str) \
1715 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1718 #define SET_ADDRESS(type, str) \
1721 compose_entry_append(compose, str, type); \
1724 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1726 g_return_if_fail(msginfo != NULL);
1728 SET_ENTRY(subject_entry, msginfo->subject);
1729 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1730 SET_ADDRESS(COMPOSE_CC, compose->cc);
1731 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1732 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1734 compose_show_first_last_header(compose, TRUE);
1736 #if 0 /* NEW COMPOSE GUI */
1738 GtkItemFactory *ifactory;
1739 GtkWidget *menuitem;
1741 ifactory = gtk_item_factory_from_widget(compose->menubar);
1742 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1743 gtk_check_menu_item_set_active
1744 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1746 if (compose->replyto) {
1747 GtkItemFactory *ifactory;
1748 GtkWidget *menuitem;
1750 ifactory = gtk_item_factory_from_widget(compose->menubar);
1751 menuitem = gtk_item_factory_get_item
1752 (ifactory, "/View/Reply to");
1753 gtk_check_menu_item_set_active
1754 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1762 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1769 size_t buf_len = 128;
1771 if (strlen(sigfile) < 2)
1774 sigprg = popen(sigfile+1, "r");
1777 buf = g_malloc(buf_len);
1780 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1781 "Unable to insert signature (malloc failed)\n", -1);
1787 while (!feof(sigprg)) {
1788 bzero(buf, buf_len);
1789 fread(buf, buf_len-1, 1, sigprg);
1790 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1798 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1799 "Can't exec file: ", -1);
1800 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1805 static void compose_insert_sig(Compose *compose)
1809 if (compose->account && compose->account->sig_path)
1810 sigfile = g_strdup(compose->account->sig_path);
1812 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1813 DEFAULT_SIGNATURE, NULL);
1815 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1820 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1821 if (prefs_common.sig_sep) {
1822 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1823 prefs_common.sig_sep, -1);
1824 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1828 if (sigfile[0] == '|')
1829 compose_exec_sig(compose, sigfile);
1831 compose_insert_file(compose, sigfile);
1835 static void compose_insert_file(Compose *compose, const gchar *file)
1837 GtkSText *text = GTK_STEXT(compose->text);
1838 gchar buf[BUFFSIZE];
1842 g_return_if_fail(file != NULL);
1844 if ((fp = fopen(file, "rb")) == NULL) {
1845 FILE_OP_ERROR(file, "fopen");
1849 gtk_stext_freeze(text);
1851 while (fgets(buf, sizeof(buf), fp) != NULL) {
1852 /* strip <CR> if DOS/Windows file,
1853 replace <CR> with <LF> if Macintosh file. */
1856 if (len > 0 && buf[len - 1] != '\n') {
1858 if (buf[len] == '\r') buf[len] = '\n';
1860 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1863 gtk_stext_thaw(text);
1868 static void compose_attach_append(Compose *compose, const gchar *file,
1869 const gchar *filename,
1870 const gchar *content_type)
1873 gchar *text[N_ATTACH_COLS];
1878 if (!is_file_exist(file)) {
1879 g_warning(_("File %s doesn't exist\n"), file);
1882 if ((size = get_file_size(file)) < 0) {
1883 g_warning(_("Can't get file size of %s\n"), file);
1887 alertpanel_notice(_("File %s is empty."), file);
1890 if ((fp = fopen(file, "rb")) == NULL) {
1891 alertpanel_error(_("Can't read %s."), file);
1896 #if 0 /* NEW COMPOSE GUI */
1897 if (!compose->use_attach) {
1898 GtkItemFactory *ifactory;
1899 GtkWidget *menuitem;
1901 ifactory = gtk_item_factory_from_widget(compose->menubar);
1902 menuitem = gtk_item_factory_get_item(ifactory,
1903 "/View/Attachment");
1904 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1908 ainfo = g_new0(AttachInfo, 1);
1909 ainfo->file = g_strdup(file);
1912 ainfo->content_type = g_strdup(content_type);
1913 if (!strcasecmp(content_type, "message/rfc822")) {
1914 ainfo->encoding = ENC_7BIT;
1915 ainfo->name = g_strdup_printf
1917 g_basename(filename ? filename : file));
1919 ainfo->encoding = ENC_BASE64;
1920 ainfo->name = g_strdup
1921 (g_basename(filename ? filename : file));
1924 ainfo->content_type = procmime_get_mime_type(file);
1925 if (!ainfo->content_type)
1926 ainfo->content_type =
1927 g_strdup("application/octet-stream");
1928 ainfo->encoding = ENC_BASE64;
1929 ainfo->name = g_strdup(g_basename(filename ? filename : file));
1933 text[COL_MIMETYPE] = ainfo->content_type;
1934 text[COL_SIZE] = to_human_readable(size);
1935 text[COL_NAME] = ainfo->name;
1937 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1938 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1941 #define IS_FIRST_PART_TEXT(info) \
1942 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
1943 info->mime_type == MIME_TEXT_ENRICHED) || \
1944 (info->mime_type == MIME_MULTIPART && info->content_type && \
1945 !strcasecmp(info->content_type, "multipart/alternative") && \
1946 (info->children && \
1947 (info->children->mime_type == MIME_TEXT || \
1948 info->children->mime_type == MIME_TEXT_HTML || \
1949 info->children->mime_type == MIME_TEXT_ENRICHED))))
1951 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
1958 mimeinfo = procmime_scan_message(msginfo);
1959 if (!mimeinfo) return;
1961 /* skip first text (presumably message body) */
1962 child = mimeinfo->children;
1963 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
1964 procmime_mimeinfo_free_all(mimeinfo);
1967 if (IS_FIRST_PART_TEXT(child))
1968 child = child->next;
1970 infile = procmsg_get_message_file_path(msginfo);
1972 while (child != NULL) {
1973 if (child->children || child->mime_type == MIME_MULTIPART) {
1974 child = procmime_mimeinfo_next(child);
1978 outfile = procmime_get_tmp_file_name(child);
1979 if (procmime_get_part(outfile, infile, child) < 0)
1980 g_warning(_("Can't get the part of multipart message."));
1982 compose_attach_append
1984 child->filename ? child->filename : child->name,
1985 child->content_type);
1987 child = child->next;
1991 procmime_mimeinfo_free_all(mimeinfo);
1994 #undef IS_FIRST_PART_TEXT
1996 #define GET_CHAR(pos, buf, len) \
1998 if (text->use_wchar) \
1999 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2001 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2006 #define INDENT_CHARS ">|#"
2007 #define SPACE_CHARS " \t"
2009 static void compose_wrap_line(Compose *compose)
2011 GtkSText *text = GTK_STEXT(compose->text);
2012 gint ch_len, last_ch_len;
2013 gchar cbuf[MB_LEN_MAX], last_ch;
2017 gint p_start, p_end;
2018 gint line_pos, cur_pos;
2019 gint line_len, cur_len;
2021 gtk_stext_freeze(text);
2023 text_len = gtk_stext_get_length(text);
2025 /* check to see if the point is on the paragraph mark (empty line). */
2026 cur_pos = gtk_stext_get_point(text);
2027 GET_CHAR(cur_pos, cbuf, ch_len);
2028 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2030 goto compose_end; /* on the paragraph mark */
2031 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2032 if (ch_len == 1 && *cbuf == '\n')
2033 goto compose_end; /* on the paragraph mark */
2036 /* find paragraph start. */
2037 line_end = quoted = 0;
2038 for (p_start = cur_pos; p_start >= 0; --p_start) {
2039 GET_CHAR(p_start, cbuf, ch_len);
2040 if (ch_len == 1 && *cbuf == '\n') {
2042 goto compose_end; /* quoted part */
2050 && strchr(prefs_common.quote_chars, *cbuf))
2052 else if (ch_len != 1 || !isspace(*cbuf))
2061 /* find paragraph end. */
2063 for (p_end = cur_pos; p_end < text_len; p_end++) {
2064 GET_CHAR(p_end, cbuf, ch_len);
2065 if (ch_len == 1 && *cbuf == '\n') {
2072 if (line_end && ch_len == 1 &&
2073 strchr(prefs_common.quote_chars, *cbuf))
2074 goto compose_end; /* quoted part */
2079 if (p_end >= text_len)
2082 if (p_start >= p_end)
2085 line_len = cur_len = 0;
2089 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2092 GET_CHAR(cur_pos, cbuf, ch_len);
2099 if (ch_len == 1 && isspace(*cbuf))
2102 if (ch_len == 1 && *cbuf == '\n') {
2104 if (last_ch_len == 1 && !isspace(last_ch)) {
2105 if (cur_pos + 1 < p_end) {
2106 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2107 if (ch_len == 1 && !isspace(*cbuf))
2111 gtk_stext_set_point(text, cur_pos + 1);
2112 gtk_stext_backward_delete(text, 1);
2114 gtk_stext_set_point(text, cur_pos);
2115 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2125 last_ch_len = ch_len;
2129 line_pos = cur_pos + 1;
2130 line_len = cur_len + ch_len;
2133 if (cur_len + ch_len > prefs_common.linewrap_len &&
2137 GET_CHAR(line_pos - 1, cbuf, ch_len);
2138 if (ch_len == 1 && isspace(*cbuf)) {
2139 gtk_stext_set_point(text, line_pos);
2140 gtk_stext_backward_delete(text, 1);
2149 gtk_stext_set_point(text, line_pos);
2150 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2154 cur_len = cur_len - line_len + ch_len;
2160 line_pos = cur_pos + 1;
2161 line_len = cur_len + ch_len;
2167 gtk_stext_thaw(text);
2172 /* Darko: used when I debug wrapping */
2173 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2178 printf("%d [", pos);
2179 for (i = pos; i < tlen; i++) {
2180 ch = GTK_STEXT_INDEX(text, i);
2181 if (breakoncr && ch == '\n')
2191 WAIT_FOR_INDENT_CHAR,
2192 WAIT_FOR_INDENT_CHAR_OR_SPACE
2195 /* return indent length, we allow:
2196 > followed by spaces/tabs
2197 | followed by spaces/tabs
2198 uppercase characters immediately followed by >,
2199 and the repeating sequences of the above */
2200 /* return indent length */
2201 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2204 guint i, ch_len, alnum_cnt = 0;
2205 IndentState state = WAIT_FOR_INDENT_CHAR;
2206 gchar cbuf[MB_LEN_MAX];
2210 for (i = start_pos; i < text_len; i++) {
2211 GET_CHAR(i, cbuf, ch_len);
2215 if (cbuf[0] == '\n')
2218 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2219 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2222 case WAIT_FOR_SPACE:
2223 if (is_space == FALSE)
2225 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2227 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2228 if (is_indent == FALSE && is_space == FALSE &&
2231 if (is_space == TRUE) {
2233 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2234 } else if (is_indent == TRUE) {
2236 state = WAIT_FOR_SPACE;
2239 state = WAIT_FOR_INDENT_CHAR;
2242 case WAIT_FOR_INDENT_CHAR:
2243 if (is_indent == FALSE && !isupper(cbuf[0]))
2245 if (is_indent == TRUE) {
2247 && !strchr(prefs_common.quote_chars, cbuf[0]))
2250 state = WAIT_FOR_SPACE;
2261 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2267 /* insert quotation string when line was wrapped */
2268 static guint ins_quote(GtkSText *text, guint indent_len,
2269 guint prev_line_pos, guint text_len,
2276 for (i = 0; i < indent_len; i++) {
2277 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2278 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2280 ins_len = indent_len;
2286 /* check if we should join the next line */
2287 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2290 guint indent_len, ch_len;
2291 gboolean do_join = FALSE;
2292 gchar cbuf[MB_LEN_MAX];
2294 indent_len = get_indent_length(text, start_pos, tlen);
2296 if ((indent_len > 0) && (indent_len == prev_ilen)) {
2297 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2298 if (ch_len > 0 && (cbuf[0] != '\n'))
2305 static void compose_wrap_line_all(Compose *compose)
2307 GtkSText *text = GTK_STEXT(compose->text);
2309 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2310 gint line_len = 0, cur_len = 0;
2312 gboolean is_new_line = TRUE, do_delete = FALSE;
2314 gboolean linewrap_quote = TRUE;
2315 guint linewrap_len = prefs_common.linewrap_len;
2316 gchar *qfmt = prefs_common.quotemark;
2317 gchar cbuf[MB_LEN_MAX];
2319 gtk_stext_freeze(text);
2321 /* make text buffer contiguous */
2322 /* gtk_stext_compact_buffer(text); */
2324 tlen = gtk_stext_get_length(text);
2326 for (; cur_pos < tlen; cur_pos++) {
2327 /* mark position of new line - needed for quotation wrap */
2330 i_len = get_indent_length(text, cur_pos, tlen);
2332 is_new_line = FALSE;
2335 printf("new line i_len=%d p_pos=", i_len);
2336 dump_text(text, p_pos, tlen, 1);
2340 GET_CHAR(cur_pos, cbuf, ch_len);
2342 /* fix line length for tabs */
2343 if (ch_len == 1 && *cbuf == '\t') {
2344 guint tab_width = text->default_tab_width;
2345 guint tab_offset = line_len % tab_width;
2348 printf("found tab at pos=%d line_len=%d ", cur_pos,
2352 line_len += tab_width - tab_offset - 1;
2356 printf("new_len=%d\n", line_len);
2360 /* we have encountered line break */
2361 if (ch_len == 1 && *cbuf == '\n') {
2363 gchar cb[MB_CUR_MAX];
2365 /* should we join the next line */
2366 if ((i_len != cur_len) && do_delete &&
2367 join_next_line(text, cur_pos + 1, tlen, i_len))
2373 printf("found CR at %d do_del is %d next line is ",
2374 cur_pos, do_delete);
2375 dump_text(text, cur_pos + 1, tlen, 1);
2378 /* skip delete if it is continuous URL */
2379 if (do_delete && (line_pos - p_pos <= i_len) &&
2380 gtkut_stext_is_uri_string(text, line_pos, tlen))
2384 printf("l_len=%d wrap_len=%d do_del=%d\n",
2385 line_len, linewrap_len, do_delete);
2387 /* should we delete to perform smart wrapping */
2388 if (line_len < linewrap_len && do_delete) {
2389 /* get rid of newline */
2390 gtk_stext_set_point(text, cur_pos);
2391 gtk_stext_forward_delete(text, 1);
2394 /* if text starts with quote fmt or with
2395 indent string, delete them */
2398 ilen = gtkut_stext_str_compare_n
2399 (text, cur_pos, p_pos, i_len,
2402 gtk_stext_forward_delete
2408 GET_CHAR(cur_pos, cb, clen);
2410 /* insert space if it's alphanumeric */
2411 if ((cur_pos != line_pos) &&
2412 ((clen > 1) || isalnum(cb[0]))) {
2413 gtk_stext_insert(text, NULL, NULL,
2415 /* gtk_stext_compact_buffer(text); */
2419 /* and start over with current line */
2420 cur_pos = p_pos - 1;
2422 line_len = cur_len = 0;
2426 printf("after delete l_pos=");
2427 dump_text(text, line_pos, tlen, 1);
2432 /* mark new line beginning */
2433 line_pos = cur_pos + 1;
2434 line_len = cur_len = 0;
2445 /* possible line break */
2446 if (ch_len == 1 && isspace(*cbuf)) {
2447 line_pos = cur_pos + 1;
2448 line_len = cur_len + ch_len;
2451 /* are we over wrapping length set in preferences ? */
2452 if (cur_len + ch_len > linewrap_len) {
2456 printf("should wrap cur_pos=%d ", cur_pos);
2457 dump_text(text, p_pos, tlen, 1);
2458 dump_text(text, line_pos, tlen, 1);
2460 /* force wrapping if it is one long word but not URL */
2461 if (line_pos - p_pos <= i_len)
2462 if (!gtkut_stext_is_uri_string
2463 (text, line_pos, tlen))
2464 line_pos = cur_pos - 1;
2466 printf("new line_pos=%d\n", line_pos);
2469 GET_CHAR(line_pos - 1, cbuf, clen);
2471 /* if next character is space delete it */
2472 if (clen == 1 && isspace(*cbuf)) {
2473 if (p_pos + i_len != line_pos ||
2474 !gtkut_stext_is_uri_string
2475 (text, line_pos, tlen)) {
2476 gtk_stext_set_point(text, line_pos);
2477 gtk_stext_backward_delete(text, 1);
2486 /* if it is URL at beginning of line don't wrap */
2487 if (p_pos + i_len == line_pos &&
2488 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2490 printf("found URL at ");
2491 dump_text(text, line_pos, tlen, 1);
2497 gtk_stext_set_point(text, line_pos);
2498 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2499 /* gtk_stext_compact_buffer(text); */
2502 /* for loop will increase it */
2503 cur_pos = line_pos - 1;
2504 /* start over with current line */
2513 printf("after CR insert ");
2514 dump_text(text, line_pos, tlen, 1);
2515 dump_text(text, cur_pos, tlen, 1);
2518 /* should we insert quotation ? */
2519 if (linewrap_quote && i_len) {
2520 /* only if line is not already quoted */
2521 if (!gtkut_stext_str_compare
2522 (text, line_pos, tlen, qfmt)) {
2525 if (line_pos - p_pos > i_len) {
2527 (text, i_len, p_pos,
2530 /* gtk_stext_compact_buffer(text); */
2534 printf("after quote insert ");
2535 dump_text(text, line_pos, tlen, 1);
2543 line_pos = cur_pos + 1;
2544 line_len = cur_len + ch_len;
2546 /* advance to next character in buffer */
2550 gtk_stext_thaw(text);
2555 static void compose_set_title(Compose *compose)
2560 edited = compose->modified ? _(" [Edited]") : "";
2561 if (compose->account && compose->account->address)
2562 str = g_strdup_printf(_("%s - Compose message%s"),
2563 compose->account->address, edited);
2565 str = g_strdup_printf(_("Compose message%s"), edited);
2566 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2571 * compose_current_mail_account:
2573 * Find a current mail account (the currently selected account, or the
2574 * default account, if a news account is currently selected). If a
2575 * mail account cannot be found, display an error message.
2577 * Return value: Mail account, or NULL if not found.
2579 static PrefsAccount *
2580 compose_current_mail_account(void)
2584 if (cur_account && cur_account->protocol != A_NNTP)
2587 ac = account_get_default();
2588 if (!ac || ac->protocol == A_NNTP) {
2589 alertpanel_error(_("Account for sending mail is not specified.\n"
2590 "Please select a mail account before sending."));
2597 gboolean compose_check_for_valid_recipient(Compose *compose) {
2598 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2599 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2600 gboolean recipient_found = FALSE;
2604 /* free to and newsgroup list */
2605 slist_free_strings(compose->to_list);
2606 g_slist_free(compose->to_list);
2607 compose->to_list = NULL;
2609 slist_free_strings(compose->newsgroup_list);
2610 g_slist_free(compose->newsgroup_list);
2611 compose->newsgroup_list = NULL;
2613 /* search header entries for to and newsgroup entries */
2614 for(list = compose->header_list; list; list = list->next) {
2617 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2618 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2620 if(entry[0] != '\0') {
2621 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2622 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2623 compose->to_list = address_list_append(compose->to_list, entry);
2624 recipient_found = TRUE;
2627 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2628 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2629 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2630 recipient_found = TRUE;
2636 return recipient_found;
2639 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
2643 if (compose_check_for_valid_recipient(compose) == FALSE) {
2644 alertpanel_error(_("Recipient is not specified."));
2648 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2649 if (*str == '\0' && check_subject == TRUE) {
2652 aval = alertpanel(_("Send"),
2653 _("Subject is empty. Send it anyway?"),
2654 _("Yes"), _("No"), NULL);
2655 if (aval != G_ALERTDEFAULT)
2662 gint compose_send(Compose *compose)
2668 if (compose_check_entries(compose, TRUE) == FALSE)
2671 val = compose_queue(compose, &msgnum, &folder);
2673 alertpanel_error(_("Could not queue message for sending"));
2677 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2679 folder_item_remove_msg(folder, msgnum);
2680 folderview_update_item(folder, TRUE);
2685 #if 0 /* compose restructure */
2686 gint compose_send(Compose *compose)
2688 gchar tmp[MAXPATHLEN + 1];
2690 static gboolean lock = FALSE;
2694 g_return_val_if_fail(compose->account != NULL, -1);
2695 g_return_val_if_fail(compose->orig_account != NULL, -1);
2699 if (compose_check_entries(compose, TRUE) == FALSE) {
2704 /* write to temporary file */
2705 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2706 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2708 if (prefs_common.linewrap_at_send)
2709 compose_wrap_line_all(compose);
2711 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2716 if (!compose->to_list && !compose->newsgroup_list) {
2717 g_warning(_("can't get recipient list."));
2723 if (compose->to_list) {
2726 #if 0 /* NEW COMPOSE GUI */
2727 if (compose->account->protocol != A_NNTP)
2728 ac = compose->account;
2729 else if (compose->orig_account->protocol != A_NNTP)
2730 ac = compose->orig_account;
2731 else if (cur_account && cur_account->protocol != A_NNTP)
2734 ac = compose_current_mail_account();
2742 ac = compose->account;
2744 ok = send_message(tmp, ac, compose->to_list);
2745 statusbar_pop_all();
2748 if (ok == 0 && compose->newsgroup_list) {
2751 if (compose->account->protocol == A_NNTP)
2752 folder = FOLDER(compose->account->folder);
2754 folder = FOLDER(compose->orig_account->folder);
2756 ok = news_post(folder, tmp);
2758 alertpanel_error(_("Error occurred while posting the message to %s ."),
2759 compose->account->nntp_server);
2766 /* queue message if failed to send */
2768 if (prefs_common.queue_msg) {
2773 _("Error occurred while sending the message.\n"
2774 "Put this message into queue folder?"),
2775 _("OK"), _("Cancel"), NULL);
2776 if (G_ALERTDEFAULT == val) {
2777 ok = compose_queue(compose, tmp);
2779 alertpanel_error(_("Can't queue the message."));
2782 alertpanel_error(_("Error occurred while sending the message."));
2784 if (compose->mode == COMPOSE_REEDIT) {
2785 compose_remove_reedit_target(compose);
2786 if (compose->targetinfo)
2787 folderview_update_item
2788 (compose->targetinfo->folder, TRUE);
2790 /* save message to outbox */
2791 if (prefs_common.savemsg) {
2794 outbox = account_get_special_folder
2795 (compose->account, F_OUTBOX);
2796 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
2798 (_("Can't save the message to outbox."));
2800 folderview_update_item(outbox, TRUE);
2810 static gboolean compose_use_attach(Compose *compose) {
2811 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2814 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2817 gchar buf[BUFFSIZE];
2819 gboolean first_address;
2821 ComposeHeaderEntry *headerentry;
2822 gchar *headerentryname;
2823 gchar *header_w_colon;
2827 debug_print(_("Writing bounce header\n"));
2829 header_w_colon = g_strconcat("To:", NULL);
2830 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2831 header_w_colon = g_strconcat("Cc:", NULL);
2832 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2834 first_address = TRUE;
2835 for(list = compose->header_list; list; list = list->next) {
2836 headerentry = ((ComposeHeaderEntry *)list->data);
2837 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2839 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2840 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2841 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2842 Xstrdup_a(str, str, return -1);
2844 if(str[0] != '\0') {
2845 compose_convert_header
2846 (buf, sizeof(buf), str,
2847 strlen("Resent-To") + 2);
2849 fprintf(fp, "Resent-To: ");
2850 first_address = FALSE;
2854 fprintf(fp, "%s", buf);
2858 /* if(!first_address) { */
2865 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2867 gchar buf[BUFFSIZE];
2869 /* struct utsname utsbuf; */
2871 g_return_val_if_fail(fp != NULL, -1);
2872 g_return_val_if_fail(compose->account != NULL, -1);
2873 g_return_val_if_fail(compose->account->address != NULL, -1);
2876 get_rfc822_date(buf, sizeof(buf));
2877 fprintf(fp, "Resent-Date: %s\n", buf);
2880 if (compose->account->name && *compose->account->name) {
2881 compose_convert_header
2882 (buf, sizeof(buf), compose->account->name,
2884 fprintf(fp, "Resent-From: %s <%s>\n",
2885 buf, compose->account->address);
2887 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2890 compose_bounce_write_headers_from_headerlist(compose, fp);
2892 /* separator between header and body */
2898 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2903 gchar buf[BUFFSIZE];
2905 if ((fp = fopen(compose->bounce_filename, "rb")) == NULL) {
2906 FILE_OP_ERROR(file, "fopen");
2910 if ((fdest = fopen(file, "wb")) == NULL) {
2911 FILE_OP_ERROR(file, "fopen");
2916 /* chmod for security */
2917 if (change_file_mode_rw(fdest, file) < 0) {
2918 FILE_OP_ERROR(file, "chmod");
2919 g_warning(_("can't change file mode\n"));
2922 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2923 /* should filter returnpath, delivered-to */
2924 if ((g_strncasecmp(buf, "Return-Path:",
2925 strlen("Return-Path:")) == 0)
2926 || (g_strncasecmp(buf, "Delivered-To:",
2927 strlen("Delivered-To:")) == 0))
2930 if (fputs(buf, fdest) == -1)
2933 if (!prefs_common.bounce_keep_from) {
2934 if (g_strncasecmp(buf, "From:",
2935 strlen("From:")) == 0) {
2936 fputs(" (by way of ", fdest);
2937 if (compose->account->name
2938 && *compose->account->name) {
2939 compose_convert_header
2941 compose->account->name,
2943 fprintf(fdest, "%s <%s>",
2945 compose->account->address);
2947 fprintf(fdest, "%s",
2948 compose->account->address);
2953 if (fputs("\n", fdest) == -1)
2957 compose_bounce_write_headers(compose, fdest);
2959 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
2960 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
2978 * interfaces to rfc2015 to keep out the prefs stuff there.
2979 * returns 0 on success and -1 on error. */
2980 static int compose_create_signers_list (Compose *compose, GSList **pkey_list)
2982 const char *keyid = NULL;
2985 switch (compose->account->sign_key) {
2986 case SIGN_KEY_DEFAULT:
2988 return 0; /* nothing to do */
2990 case SIGN_KEY_BY_FROM:
2991 keyid = compose->account->address;
2994 case SIGN_KEY_CUSTOM:
2995 keyid = compose->account->sign_key_id;
2999 g_assert_not_reached ();
3002 key_list = rfc2015_create_signers_list(keyid);
3005 alertpanel_error("Could not find any key associated with currently "
3006 "selected keyid `%s'!", keyid);
3010 *pkey_list = key_list;
3013 #endif /* USE_GPGME */
3015 static gint compose_write_to_file(Compose *compose, const gchar *file,
3022 const gchar *out_codeset;
3023 EncodingType encoding;
3025 if ((fp = fopen(file, "wb")) == NULL) {
3026 FILE_OP_ERROR(file, "fopen");
3030 /* chmod for security */
3031 if (change_file_mode_rw(fp, file) < 0) {
3032 FILE_OP_ERROR(file, "chmod");
3033 g_warning(_("can't change file mode\n"));
3036 /* get all composed text */
3037 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3038 len = strlen(chars);
3039 if (is_ascii_str(chars)) {
3040 buf = g_strdup(chars);
3041 out_codeset = CS_US_ASCII;
3042 encoding = ENC_7BIT;
3044 const gchar *src_codeset;
3046 out_codeset = conv_get_outgoing_charset_str();
3047 if (!strcasecmp(out_codeset, CS_US_ASCII))
3048 out_codeset = CS_ISO_8859_1;
3049 encoding = procmime_get_encoding_for_charset(out_codeset);
3051 src_codeset = conv_get_current_charset_str();
3052 /* if current encoding is US-ASCII, set it the same as
3053 outgoing one to prevent code conversion failure */
3054 if (!strcasecmp(src_codeset, CS_US_ASCII))
3055 src_codeset = out_codeset;
3057 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3058 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3060 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3066 _("Can't convert the character encoding of the message.\n"
3067 "Send it anyway?"), _("Yes"), _("+No"), NULL);
3068 if (aval != G_ALERTDEFAULT) {
3074 buf = g_strdup(chars);
3081 if (compose_write_headers
3082 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3083 g_warning(_("can't write headers\n"));
3090 if (compose_use_attach(compose)) {
3092 /* This prolog message is ignored by mime software and
3093 * because it would make our signing/encryption task
3094 * tougher, we don't emit it in that case */
3095 if (!compose->use_signing && !compose->use_encryption)
3097 fputs("This is a multi-part message in MIME format.\n", fp);
3099 fprintf(fp, "\n--%s\n", compose->boundary);
3100 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3102 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3103 procmime_get_encoding_str(encoding));
3109 if (encoding == ENC_BASE64) {
3110 gchar outbuf[B64_BUFFSIZE];
3113 for (i = 0; i < len; i += B64_LINE_SIZE) {
3114 l = MIN(B64_LINE_SIZE, len - i);
3115 to64frombits(outbuf, buf + i, l);
3119 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3120 FILE_OP_ERROR(file, "fwrite");
3128 if (compose_use_attach(compose))
3129 compose_write_attach(compose, fp);
3131 if (fclose(fp) == EOF) {
3132 FILE_OP_ERROR(file, "fclose");
3138 if (compose->use_signing) {
3141 if (compose_create_signers_list(compose, &key_list) == -1 ||
3142 rfc2015_sign(file, key_list) < 0) {
3148 if (compose->use_encryption) {
3149 if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) {
3154 #endif /* USE_GPGME */
3159 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3165 if ((fp = fopen(file, "wb")) == NULL) {
3166 FILE_OP_ERROR(file, "fopen");
3170 /* chmod for security */
3171 if (change_file_mode_rw(fp, file) < 0) {
3172 FILE_OP_ERROR(file, "chmod");
3173 g_warning(_("can't change file mode\n"));
3176 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3179 len = strlen(chars);
3180 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3181 FILE_OP_ERROR(file, "fwrite");
3190 if (fclose(fp) == EOF) {
3191 FILE_OP_ERROR(file, "fclose");
3198 static gint compose_remove_reedit_target(Compose *compose)
3201 MsgInfo *msginfo = compose->targetinfo;
3203 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3204 if (!msginfo) return -1;
3206 item = msginfo->folder;
3207 g_return_val_if_fail(item != NULL, -1);
3209 folder_item_scan(item);
3210 if (procmsg_msg_exist(msginfo) &&
3211 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3212 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3213 g_warning(_("can't remove the old message\n"));
3221 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3223 return compose_queue_sub (compose, msgnum, item, FALSE);
3225 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3231 gchar buf[BUFFSIZE];
3233 MsgFlags flag = {0, 0};
3234 static gboolean lock = FALSE;
3235 PrefsAccount *mailac = NULL, *newsac = NULL;
3237 debug_print(_("queueing message...\n"));
3238 g_return_val_if_fail(compose->account != NULL, -1);
3239 g_return_val_if_fail(compose->orig_account != NULL, -1);
3243 if (compose_check_entries(compose, check_subject) == FALSE) {
3248 if (!compose->to_list && !compose->newsgroup_list) {
3249 g_warning(_("can't get recipient list."));
3254 if(compose->to_list) {
3255 if (compose->account->protocol != A_NNTP)
3256 mailac = compose->account;
3257 else if (compose->orig_account->protocol != A_NNTP)
3258 mailac = compose->orig_account;
3259 else if (cur_account && cur_account->protocol != A_NNTP)
3260 mailac = cur_account;
3261 else if (!(mailac = compose_current_mail_account())) {
3263 alertpanel_error(_("No account for sending mails available!"));
3268 if(compose->newsgroup_list) {
3269 if (compose->account->protocol == A_NNTP)
3270 newsac = compose->account;
3271 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3273 alertpanel_error(_("No account for posting news available!"));
3278 if (prefs_common.linewrap_at_send)
3279 compose_wrap_line_all(compose);
3281 /* write to temporary file */
3282 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3283 G_DIR_SEPARATOR, (gint)compose);
3285 if (compose->bounce_filename != NULL) {
3286 if (compose_bounce_write_to_file(compose, tmp2) < 0) {
3293 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3300 /* add queue header */
3301 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3302 G_DIR_SEPARATOR, (gint)compose);
3303 if ((fp = fopen(tmp, "wb")) == NULL) {
3304 FILE_OP_ERROR(tmp, "fopen");
3308 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3309 FILE_OP_ERROR(tmp2, "fopen");
3317 if (change_file_mode_rw(fp, tmp) < 0) {
3318 FILE_OP_ERROR(tmp, "chmod");
3319 g_warning(_("can't change file mode\n"));
3322 /* queueing variables */
3323 fprintf(fp, "AF:\n");
3324 fprintf(fp, "NF:0\n");
3325 fprintf(fp, "PS:10\n");
3326 fprintf(fp, "SRH:1\n");
3327 fprintf(fp, "SFN:\n");
3328 fprintf(fp, "DSR:\n");
3330 fprintf(fp, "MID:<%s>\n", compose->msgid);
3332 fprintf(fp, "MID:\n");
3333 fprintf(fp, "CFG:\n");
3334 fprintf(fp, "PT:0\n");
3335 fprintf(fp, "S:%s\n", compose->account->address);
3336 fprintf(fp, "RQ:\n");
3338 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3340 fprintf(fp, "SSV:\n");
3342 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3344 fprintf(fp, "NSV:\n");
3345 fprintf(fp, "SSH:\n");
3346 /* write recepient list */
3348 if(compose->to_list) {
3349 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3350 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3351 fprintf(fp, ",<%s>", (gchar *)cur->data);
3354 /* write newsgroup list */
3356 if(compose->newsgroup_list) {
3357 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3358 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3359 fprintf(fp, ",%s", (gchar *)cur->data);
3362 /* Sylpheed account IDs */
3364 fprintf(fp, "MAID:%d\n", mailac->account_id);
3367 fprintf(fp, "NAID:%d\n", newsac->account_id);
3369 /* Save copy folder */
3370 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3373 str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3374 fprintf(fp, "SCF:%s\n", str);
3379 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3380 if (fputs(buf, fp) == EOF) {
3381 FILE_OP_ERROR(tmp, "fputs");
3392 if (fclose(fp) == EOF) {
3393 FILE_OP_ERROR(tmp, "fclose");
3401 queue = account_get_special_folder(compose->account, F_QUEUE);
3403 g_warning(_("can't find queue folder\n"));
3408 folder_item_scan(queue);
3409 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3410 g_warning(_("can't queue the message\n"));
3420 if (compose->mode == COMPOSE_REEDIT) {
3421 compose_remove_reedit_target(compose);
3422 if (compose->targetinfo &&
3423 compose->targetinfo->folder != queue)
3424 folderview_update_item
3425 (compose->targetinfo->folder, TRUE);
3428 procmsg_add_flags(queue, num, flag);
3429 folder_item_scan(queue);
3430 folderview_update_item(queue, TRUE);
3432 if((msgnum != NULL) && (item != NULL)) {
3440 static void compose_write_attach(Compose *compose, FILE *fp)
3443 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3446 gchar filename[BUFFSIZE];
3449 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3451 gchar buf[BUFFSIZE];
3452 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3454 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
3455 g_warning(_("Can't open file %s\n"), ainfo->file);
3459 fprintf(fp, "\n--%s\n", compose->boundary);
3461 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3462 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3463 fprintf(fp, "Content-Disposition: inline\n");
3465 conv_encode_header(filename, sizeof(filename),
3467 fprintf(fp, "Content-Type: %s;\n"
3469 ainfo->content_type, filename);
3470 fprintf(fp, "Content-Disposition: attachment;\n"
3471 " filename=\"%s\"\n", filename);
3474 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3475 procmime_get_encoding_str(ainfo->encoding));
3477 switch (ainfo->encoding) {
3481 /* if (ainfo->encoding == ENC_7BIT) { */
3483 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3491 while ((len = fread(inbuf, sizeof(gchar),
3492 B64_LINE_SIZE, attach_fp))
3494 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3498 if (len > 0 && feof(attach_fp)) {
3499 to64frombits(outbuf, inbuf, len);
3509 fprintf(fp, "\n--%s--\n", compose->boundary);
3512 #define IS_IN_CUSTOM_HEADER(header) \
3513 (compose->account->add_customhdr && \
3514 custom_header_find(compose->account->customhdr_list, header) != NULL)
3516 static gint compose_write_headers_from_headerlist(Compose *compose,
3520 gchar buf[BUFFSIZE];
3521 gchar *str, *header_w_colon, *trans_hdr;
3522 gboolean first_address;
3524 ComposeHeaderEntry *headerentry;
3525 gchar * headerentryname;
3527 if (IS_IN_CUSTOM_HEADER(header)) {
3531 debug_print(_("Writing %s-header\n"), header);
3533 header_w_colon = g_strconcat(header, ":", NULL);
3534 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3536 first_address = TRUE;
3537 for(list = compose->header_list; list; list = list->next) {
3538 headerentry = ((ComposeHeaderEntry *)list->data);
3539 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3541 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3542 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3543 Xstrdup_a(str, str, return -1);
3545 if(str[0] != '\0') {
3546 compose_convert_header
3547 (buf, sizeof(buf), str,
3548 strlen(header) + 2);
3550 fprintf(fp, "%s: ", header);
3551 first_address = FALSE;
3555 fprintf(fp, "%s", buf);
3559 if(!first_address) {
3563 g_free(header_w_colon);
3568 static gint compose_write_headers(Compose *compose, FILE *fp,
3569 const gchar *charset, EncodingType encoding,
3572 gchar buf[BUFFSIZE];
3574 /* struct utsname utsbuf; */
3576 g_return_val_if_fail(fp != NULL, -1);
3577 g_return_val_if_fail(charset != NULL, -1);
3578 g_return_val_if_fail(compose->account != NULL, -1);
3579 g_return_val_if_fail(compose->account->address != NULL, -1);
3582 if (compose->account->add_date) {
3583 get_rfc822_date(buf, sizeof(buf));
3584 fprintf(fp, "Date: %s\n", buf);
3588 if (!IS_IN_CUSTOM_HEADER("From")) {
3589 if (compose->account->name && *compose->account->name) {
3590 compose_convert_header
3591 (buf, sizeof(buf), compose->account->name,
3593 fprintf(fp, "From: %s <%s>\n",
3594 buf, compose->account->address);
3596 fprintf(fp, "From: %s\n", compose->account->address);
3600 compose_write_headers_from_headerlist(compose, fp, "To");
3601 #if 0 /* NEW COMPOSE GUI */
3602 if (compose->use_to) {
3603 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3605 Xstrdup_a(str, str, return -1);
3608 compose->to_list = address_list_append
3609 (compose->to_list, str);
3610 if (!IS_IN_CUSTOM_HEADER("To")) {
3611 compose_convert_header
3612 (buf, sizeof(buf), str,
3614 fprintf(fp, "To: %s\n", buf);
3622 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3623 #if 0 /* NEW COMPOSE GUI */
3624 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3626 Xstrdup_a(str, str, return -1);
3630 compose->newsgroup_list =
3631 newsgroup_list_append(compose->newsgroup_list,
3633 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3634 compose_convert_header(buf, sizeof(buf), str,
3635 strlen("Newsgroups: "));
3636 fprintf(fp, "Newsgroups: %s\n", buf);
3642 compose_write_headers_from_headerlist(compose, fp, "Cc");
3643 #if 0 /* NEW COMPOSE GUI */
3644 if (compose->use_cc) {
3645 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3647 Xstrdup_a(str, str, return -1);
3650 compose->to_list = address_list_append
3651 (compose->to_list, str);
3652 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3653 compose_convert_header
3654 (buf, sizeof(buf), str,
3656 fprintf(fp, "Cc: %s\n", buf);
3663 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3664 #if 0 /* NEW COMPOSE GUI */
3665 if (compose->use_bcc) {
3666 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3668 Xstrdup_a(str, str, return -1);
3671 compose->to_list = address_list_append
3672 (compose->to_list, str);
3673 compose_convert_header(buf, sizeof(buf), str,
3675 fprintf(fp, "Bcc: %s\n", buf);
3682 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3683 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3684 Xstrdup_a(str, str, return -1);
3687 compose_convert_header(buf, sizeof(buf), str,
3688 strlen("Subject: "));
3689 fprintf(fp, "Subject: %s\n", buf);
3694 if (compose->account->gen_msgid) {
3695 compose_generate_msgid(compose, buf, sizeof(buf));
3696 fprintf(fp, "Message-Id: <%s>\n", buf);
3697 compose->msgid = g_strdup(buf);
3701 if (compose->inreplyto && compose->to_list)
3702 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3705 if (compose->references)
3706 fprintf(fp, "References: %s\n", compose->references);
3709 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3710 #if 0 /* NEW COMPOSE GUI */
3711 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3712 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3714 Xstrdup_a(str, str, return -1);
3718 compose_convert_header(buf, sizeof(buf), str,
3719 strlen("Followup-To: "));
3720 fprintf(fp, "Followup-To: %s\n", buf);
3726 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3727 #if 0 /* NEW COMPOSE GUI */
3728 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3729 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3731 Xstrdup_a(str, str, return -1);
3734 compose_convert_header(buf, sizeof(buf), str,
3735 strlen("Reply-To: "));
3736 fprintf(fp, "Reply-To: %s\n", buf);
3742 if (compose->account->organization &&
3743 !IS_IN_CUSTOM_HEADER("Organization")) {
3744 compose_convert_header(buf, sizeof(buf),
3745 compose->account->organization,
3746 strlen("Organization: "));
3747 fprintf(fp, "Organization: %s\n", buf);
3750 /* Program version and system info */
3751 /* uname(&utsbuf); */
3752 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3753 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3755 gtk_major_version, gtk_minor_version, gtk_micro_version,
3757 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3759 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3760 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3762 gtk_major_version, gtk_minor_version, gtk_micro_version,
3764 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3767 /* custom headers */
3768 if (compose->account->add_customhdr) {
3771 for (cur = compose->account->customhdr_list; cur != NULL;
3773 CustomHeader *chdr = (CustomHeader *)cur->data;
3775 if (strcasecmp(chdr->name, "Date") != 0 &&
3776 strcasecmp(chdr->name, "From") != 0 &&
3777 strcasecmp(chdr->name, "To") != 0 &&
3778 /* strcasecmp(chdr->name, "Sender") != 0 && */
3779 strcasecmp(chdr->name, "Message-Id") != 0 &&
3780 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3781 strcasecmp(chdr->name, "References") != 0 &&
3782 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3783 strcasecmp(chdr->name, "Content-Type") != 0 &&
3784 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3786 compose_convert_header
3788 chdr->value ? chdr->value : "",
3789 strlen(chdr->name) + 2);
3790 fprintf(fp, "%s: %s\n", chdr->name, buf);
3796 fprintf(fp, "Mime-Version: 1.0\n");
3797 if (compose_use_attach(compose)) {
3798 get_rfc822_date(buf, sizeof(buf));
3799 subst_char(buf, ' ', '_');
3800 subst_char(buf, ',', '_');
3801 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3802 buf, (guint)compose);
3804 "Content-Type: multipart/mixed;\n"
3805 " boundary=\"%s\"\n", compose->boundary);
3807 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3808 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3809 procmime_get_encoding_str(encoding));
3812 /* Request Return Receipt */
3813 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3814 if (compose->return_receipt) {
3815 if (compose->account->name
3816 && *compose->account->name) {
3817 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3818 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3820 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3824 /* separator between header and body */
3830 #undef IS_IN_CUSTOM_HEADER
3832 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3835 g_return_if_fail(src != NULL);
3836 g_return_if_fail(dest != NULL);
3838 if (len < 1) return;
3842 if (is_ascii_str(src)) {
3843 strncpy2(dest, src, len);
3844 dest[len - 1] = '\0';
3847 conv_encode_header(dest, len, src, header_len);
3850 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3859 if (compose->account && compose->account->address &&
3860 *compose->account->address) {
3861 if (strchr(compose->account->address, '@'))
3862 addr = g_strdup(compose->account->address);
3864 addr = g_strconcat(compose->account->address, "@",
3865 get_domain_name(), NULL);
3867 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3870 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3871 lt->tm_year + 1900, lt->tm_mon + 1,
3872 lt->tm_mday, lt->tm_hour,
3873 lt->tm_min, lt->tm_sec,
3874 (guint)random(), addr);
3876 debug_print(_("generated Message-ID: %s\n"), buf);
3881 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3882 GtkWidget **entry, gint *count,
3883 const gchar *label_str,
3884 gboolean is_addr_entry)
3888 if (GTK_TABLE(table)->nrows < (*count) + 1)
3889 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3891 *hbox = gtk_hbox_new(FALSE, 0);
3892 label = gtk_label_new
3893 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3894 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3895 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3897 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3899 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3900 #if 0 /* NEW COMPOSE GUI */
3901 if (GTK_TABLE(table)->nrows > (*count) + 1)
3902 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3906 address_completion_register_entry(GTK_ENTRY(*entry));
3911 static void compose_create_header_entry(Compose *compose)
3913 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3917 GList *combo_list = NULL;
3918 gchar **string, *header;
3919 ComposeHeaderEntry *headerentry;
3921 headerentry = g_new0(ComposeHeaderEntry, 1);
3924 combo = gtk_combo_new();
3926 while(*string != NULL) {
3927 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3930 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3931 g_list_free(combo_list);
3932 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3933 gtk_widget_show(combo);
3934 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3935 if(compose->header_last) {
3936 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3938 switch(compose->account->protocol) {
3940 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
3943 header = prefs_common.trans_hdr ? _("To:") : "To:";
3947 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
3950 entry = gtk_entry_new();
3951 gtk_widget_show(entry);
3952 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);
3954 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
3955 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
3956 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
3958 address_completion_register_entry(GTK_ENTRY(entry));
3960 headerentry->compose = compose;
3961 headerentry->combo = combo;
3962 headerentry->entry = entry;
3963 headerentry->headernum = compose->header_nextrow;
3965 compose->header_nextrow++;
3966 compose->header_last = headerentry;
3969 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
3971 ComposeHeaderEntry *last_header;
3973 last_header = compose->header_last;
3975 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
3976 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
3979 static GtkWidget *compose_create_header(Compose *compose)
3983 GtkWidget *from_optmenu_hbox;
3984 #if 0 /* NEW COMPOSE GUI */
3985 GtkWidget *to_entry;
3987 GtkWidget *newsgroups_entry;
3988 GtkWidget *newsgroups_hbox;
3990 GtkWidget *header_scrolledwin;
3991 GtkWidget *header_table;
3992 #if 0 /* NEW COMPOSE GUI */
3993 GtkWidget *cc_entry;
3995 GtkWidget *bcc_entry;
3996 GtkWidget *bcc_hbox;
3997 GtkWidget *reply_entry;
3998 GtkWidget *reply_hbox;
3999 GtkWidget *followup_entry;
4000 GtkWidget *followup_hbox;
4005 /* header labels and entries */
4006 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4007 gtk_widget_show(header_scrolledwin);
4008 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4010 header_table = gtk_table_new(2, 2, FALSE);
4011 gtk_widget_show(header_table);
4012 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4013 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4014 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4017 /* option menu for selecting accounts */
4018 hbox = gtk_hbox_new(FALSE, 0);
4019 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4020 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4021 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4023 from_optmenu_hbox = compose_account_option_menu_create(compose);
4024 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4025 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4026 #if 0 /* NEW COMPOSE GUI */
4027 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4031 compose->header_table = header_table;
4032 compose->header_list = NULL;
4033 compose->header_nextrow = count;
4035 compose_create_header_entry(compose);
4037 #if 0 /* NEW COMPOSE GUI */
4038 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4040 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4041 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4042 &count, "Newsgroups:", FALSE);
4043 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4045 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4047 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4049 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4050 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4052 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4053 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4055 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4056 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4057 "Followup-To:", FALSE);
4058 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4060 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4062 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4063 GTK_SIGNAL_FUNC(to_activated), compose);
4064 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4065 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4066 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4067 GTK_SIGNAL_FUNC(subject_activated), compose);
4068 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4069 GTK_SIGNAL_FUNC(cc_activated), compose);
4070 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4071 GTK_SIGNAL_FUNC(bcc_activated), compose);
4072 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4073 GTK_SIGNAL_FUNC(replyto_activated), compose);
4074 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4075 GTK_SIGNAL_FUNC(followupto_activated), compose);
4077 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4078 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4079 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4080 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4081 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4082 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4083 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4084 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4085 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4086 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4087 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4088 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4089 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4090 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4093 compose->table = NULL;
4094 #if 0 /* NEW COMPOSE GUI */
4095 compose->table = table;
4096 compose->to_hbox = to_hbox;
4097 compose->to_entry = to_entry;
4098 compose->newsgroups_hbox = newsgroups_hbox;
4099 compose->newsgroups_entry = newsgroups_entry;
4101 #if 0 /* NEW COMPOSE GUI */
4102 compose->cc_hbox = cc_hbox;
4103 compose->cc_entry = cc_entry;
4104 compose->bcc_hbox = bcc_hbox;
4105 compose->bcc_entry = bcc_entry;
4106 compose->reply_hbox = reply_hbox;
4107 compose->reply_entry = reply_entry;
4108 compose->followup_hbox = followup_hbox;
4109 compose->followup_entry = followup_entry;
4112 return header_scrolledwin ;
4115 GtkWidget *compose_create_attach(Compose *compose)
4117 gchar *titles[N_ATTACH_COLS];
4120 GtkWidget *attach_scrwin;
4121 GtkWidget *attach_clist;
4123 titles[COL_MIMETYPE] = _("MIME type");
4124 titles[COL_SIZE] = _("Size");
4125 titles[COL_NAME] = _("Name");
4127 /* attachment list */
4128 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4129 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4130 GTK_POLICY_AUTOMATIC,
4132 gtk_widget_set_usize(attach_scrwin, -1, 80);
4134 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4135 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4137 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4138 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4139 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4140 GTK_SELECTION_EXTENDED);
4141 for (i = 0; i < N_ATTACH_COLS; i++)
4142 GTK_WIDGET_UNSET_FLAGS
4143 (GTK_CLIST(attach_clist)->column[i].button,
4145 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4147 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4148 GTK_SIGNAL_FUNC(attach_selected), compose);
4149 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4150 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4151 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4152 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4155 gtk_drag_dest_set(attach_clist,
4156 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4158 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4159 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4162 compose->attach_scrwin = attach_scrwin;
4163 compose->attach_clist = attach_clist;
4165 return attach_scrwin;
4168 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4169 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4171 static GtkWidget *compose_create_others(Compose *compose)
4174 GtkWidget *savemsg_checkbtn;
4175 GtkWidget *savemsg_entry;
4176 GtkWidget *savemsg_select;
4179 gchar *folderidentifier;
4181 /* Table for settings */
4182 table = gtk_table_new(3, 1, FALSE);
4183 gtk_widget_show(table);
4184 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4187 /* Save Message to folder */
4188 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4189 gtk_widget_show(savemsg_checkbtn);
4190 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4191 if(folder_get_default_outbox()) {
4192 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4194 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4195 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4197 savemsg_entry = gtk_entry_new();
4198 gtk_widget_show(savemsg_entry);
4199 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4200 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4201 if(folder_get_default_outbox()) {
4202 folderidentifier = folder_item_get_identifier(folder_get_default_outbox());
4203 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4204 g_free(folderidentifier);
4207 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4208 gtk_widget_show (savemsg_select);
4209 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4210 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4211 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4216 compose->savemsg_checkbtn = savemsg_checkbtn;
4217 compose->savemsg_entry = savemsg_entry;
4222 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4224 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4225 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4228 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4233 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4236 path = folder_item_get_identifier(dest);
4238 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4242 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4248 GtkWidget *handlebox;
4250 GtkWidget *notebook;
4255 GtkWidget *subject_hbox;
4256 GtkWidget *subject_frame;
4257 GtkWidget *subject_entry;
4261 GtkWidget *edit_vbox;
4262 GtkWidget *ruler_hbox;
4264 GtkWidget *scrolledwin;
4269 UndoMain *undostruct;
4271 gchar *titles[N_ATTACH_COLS];
4272 guint n_menu_entries;
4273 GtkStyle *style, *new_style;
4276 gboolean success[1];
4278 GtkWidget *popupmenu;
4279 GtkWidget *menuitem;
4280 GtkItemFactory *popupfactory;
4281 GtkItemFactory *ifactory;
4282 GtkWidget *tmpl_menu;
4286 GtkPspell * gtkpspell = NULL;
4289 static GdkGeometry geometry;
4291 g_return_val_if_fail(account != NULL, NULL);
4293 debug_print(_("Creating compose window...\n"));
4294 compose = g_new0(Compose, 1);
4296 titles[COL_MIMETYPE] = _("MIME type");
4297 titles[COL_SIZE] = _("Size");
4298 titles[COL_NAME] = _("Name");
4300 compose->account = account;
4301 compose->orig_account = account;
4303 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4304 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4305 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4306 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4308 if (!geometry.max_width) {
4309 geometry.max_width = gdk_screen_width();
4310 geometry.max_height = gdk_screen_height();
4312 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4313 &geometry, GDK_HINT_MAX_SIZE);
4315 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4316 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4317 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4318 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4319 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4320 gtk_widget_realize(window);
4322 gtkut_widget_set_composer_icon(window);
4324 vbox = gtk_vbox_new(FALSE, 0);
4325 gtk_container_add(GTK_CONTAINER(window), vbox);
4327 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4328 menubar = menubar_create(window, compose_entries,
4329 n_menu_entries, "<Compose>", compose);
4330 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4332 handlebox = gtk_handle_box_new();
4333 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4335 compose_toolbar_create(compose, handlebox);
4337 vbox2 = gtk_vbox_new(FALSE, 2);
4338 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4339 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4342 notebook = gtk_notebook_new();
4343 gtk_widget_set_usize(notebook, -1, 130);
4344 gtk_widget_show(notebook);
4346 /* header labels and entries */
4347 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4348 /* attachment list */
4349 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4351 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4354 subject_hbox = gtk_hbox_new(FALSE, 0);
4355 gtk_widget_show(subject_hbox);
4357 subject_frame = gtk_frame_new(NULL);
4358 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4359 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4360 gtk_widget_show(subject_frame);
4362 subject = gtk_hbox_new(FALSE, 0);
4363 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4364 gtk_widget_show(subject);
4366 label = gtk_label_new(_("Subject:"));
4367 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4368 gtk_widget_show(label);
4370 subject_entry = gtk_entry_new();
4371 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4372 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4373 gtk_widget_show(subject_entry);
4374 compose->subject_entry = subject_entry;
4375 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4377 edit_vbox = gtk_vbox_new(FALSE, 0);
4378 #if 0 /* NEW COMPOSE GUI */
4379 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4382 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4385 ruler_hbox = gtk_hbox_new(FALSE, 0);
4386 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4388 ruler = gtk_shruler_new();
4389 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4390 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4392 gtk_widget_set_usize(ruler_hbox, 1, -1);
4395 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4396 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4397 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4398 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4399 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4401 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4402 (GTK_SCROLLED_WINDOW(scrolledwin)),
4403 gtk_scrolled_window_get_vadjustment
4404 (GTK_SCROLLED_WINDOW(scrolledwin)));
4405 GTK_STEXT(text)->default_tab_width = 8;
4406 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4408 if (prefs_common.block_cursor) {
4409 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4412 if (prefs_common.smart_wrapping) {
4413 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4414 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4417 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4419 gtk_signal_connect(GTK_OBJECT(text), "changed",
4420 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4421 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4422 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4423 gtk_signal_connect(GTK_OBJECT(text), "activate",
4424 GTK_SIGNAL_FUNC(text_activated), compose);
4425 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4426 GTK_SIGNAL_FUNC(compose_button_press_cb),
4429 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4430 GTK_SIGNAL_FUNC(compose_key_press_cb),
4433 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4434 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4438 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4440 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4441 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4443 gtk_widget_show_all(vbox);
4445 /* pane between attach clist and text */
4446 paned = gtk_vpaned_new();
4447 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4448 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4449 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4450 gtk_paned_add1(GTK_PANED(paned), notebook);
4451 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4452 gtk_widget_show_all(paned);
4454 style = gtk_widget_get_style(text);
4456 /* workaround for the slow down of GtkSText when using Pixmap theme */
4457 if (style->engine) {
4458 GtkThemeEngine *engine;
4460 engine = style->engine;
4461 style->engine = NULL;
4462 new_style = gtk_style_copy(style);
4463 style->engine = engine;
4465 new_style = gtk_style_copy(style);
4467 if (prefs_common.textfont) {
4470 charset = conv_get_current_charset();
4471 if (MB_CUR_MAX == 1) {
4474 Xstrdup_a(fontstr, prefs_common.textfont, );
4475 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4477 font = gdk_font_load(fontstr);
4479 font = gdk_fontset_load(prefs_common.textfont);
4481 gdk_font_unref(new_style->font);
4482 new_style->font = font;
4486 gtk_widget_set_style(text, new_style);
4488 color[0] = quote_color;
4489 cmap = gdk_window_get_colormap(window->window);
4490 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4491 if (success[0] == FALSE) {
4492 g_warning("Compose: color allocation failed.\n");
4493 style = gtk_widget_get_style(text);
4494 quote_color = style->black;
4497 n_entries = sizeof(compose_popup_entries) /
4498 sizeof(compose_popup_entries[0]);
4499 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4500 "<Compose>", &popupfactory,
4503 ifactory = gtk_item_factory_from_widget(menubar);
4504 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4505 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4507 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4508 #if 0 /* NEW COMPOSE GUI */
4509 gtk_widget_hide(bcc_hbox);
4510 gtk_widget_hide(bcc_entry);
4511 gtk_widget_hide(reply_hbox);
4512 gtk_widget_hide(reply_entry);
4513 gtk_widget_hide(followup_hbox);
4514 gtk_widget_hide(followup_entry);
4515 gtk_widget_hide(ruler_hbox);
4516 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4517 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4518 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4520 if (account->protocol == A_NNTP) {
4521 gtk_widget_hide(to_hbox);
4522 gtk_widget_hide(to_entry);
4523 gtk_widget_hide(cc_hbox);
4524 gtk_widget_hide(cc_entry);
4525 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4526 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4528 gtk_widget_hide(newsgroups_hbox);
4529 gtk_widget_hide(newsgroups_entry);
4530 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4531 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
4535 update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
4538 undostruct = undo_init(text);
4539 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4542 gtk_widget_show(window);
4544 address_completion_start(window);
4546 compose->window = window;
4547 compose->vbox = vbox;
4548 compose->menubar = menubar;
4549 compose->handlebox = handlebox;
4551 compose->vbox2 = vbox2;
4553 compose->paned = paned;
4555 compose->edit_vbox = edit_vbox;
4556 compose->ruler_hbox = ruler_hbox;
4557 compose->ruler = ruler;
4558 compose->scrolledwin = scrolledwin;
4559 compose->text = text;
4561 compose->focused_editable = NULL;
4563 compose->popupmenu = popupmenu;
4564 compose->popupfactory = popupfactory;
4566 compose->tmpl_menu = tmpl_menu;
4568 compose->mode = mode;
4570 compose->targetinfo = NULL;
4571 compose->replyinfo = NULL;
4573 compose->replyto = NULL;
4574 compose->mailinglist = NULL;
4576 compose->bcc = NULL;
4577 compose->followup_to = NULL;
4578 compose->inreplyto = NULL;
4579 compose->references = NULL;
4580 compose->msgid = NULL;
4581 compose->boundary = NULL;
4584 compose->use_signing = FALSE;
4585 compose->use_encryption = FALSE;
4586 #endif /* USE_GPGME */
4588 compose->modified = FALSE;
4590 compose->return_receipt = FALSE;
4592 compose->to_list = NULL;
4593 compose->newsgroup_list = NULL;
4595 compose->exteditor_file = NULL;
4596 compose->exteditor_pid = -1;
4597 compose->exteditor_readdes = -1;
4598 compose->exteditor_tag = -1;
4600 compose->bounce_filename = NULL;
4601 compose->undostruct = undostruct;
4604 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4605 if (prefs_common.enable_pspell) {
4606 gtkpspell = gtkpspell_new((const gchar*)prefs_common.dictionary,
4607 conv_get_current_charset_str(),
4608 prefs_common.misspelled_col,
4609 prefs_common.check_while_typing,
4610 prefs_common.use_alternate,
4613 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkpspellcheckers->error_message);
4614 gtkpspell_checkers_reset_error();
4617 GtkWidget *menuitem;
4619 if (!gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode)) {
4620 debug_print(_("Pspell: could not set suggestion mode %s"),
4621 gtkpspellcheckers->error_message);
4622 gtkpspell_checkers_reset_error();
4625 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
4626 gtkpspell_populate_submenu(gtkpspell, menuitem);
4627 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4632 compose_set_title(compose);
4634 #if 0 /* NEW COMPOSE GUI */
4635 compose->use_bcc = FALSE;
4636 compose->use_replyto = FALSE;
4637 compose->use_followupto = FALSE;
4641 compose->gtkpspell = gtkpspell;
4644 #if 0 /* NEW COMPOSE GUI */
4645 if (account->protocol != A_NNTP) {
4646 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
4647 gtk_check_menu_item_set_active
4648 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4649 gtk_widget_set_sensitive(menuitem, FALSE);
4650 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4651 gtk_check_menu_item_set_active
4652 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4653 gtk_widget_set_sensitive(menuitem, FALSE);
4656 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4657 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4658 #if 0 /* NEW COMPOSE GUI */
4659 compose->use_cc = TRUE;
4660 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4661 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4662 gtk_check_menu_item_set_active
4663 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4666 if (account->set_autobcc) {
4667 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4668 #if 0 /* NEW COMPOSE GUI */
4669 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
4670 gtk_check_menu_item_set_active
4671 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4672 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4673 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4677 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4678 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4679 #if 0 /* NEW COMPOSE GUI */
4680 compose->use_replyto = TRUE;
4681 menuitem = gtk_item_factory_get_item(ifactory,
4683 gtk_check_menu_item_set_active
4684 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4685 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4686 account->auto_replyto);
4690 if (account->protocol != A_NNTP) {
4691 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4693 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4696 #if 0 /* NEW COMPOSE GUI */
4697 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
4698 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4699 prefs_common.show_ruler);
4703 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4704 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4705 account->default_sign);
4706 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4707 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4708 account->default_encrypt);
4709 #endif /* USE_GPGME */
4711 addressbook_set_target_compose(compose);
4712 compose_set_template_menu(compose);
4714 compose_list = g_list_append(compose_list, compose);
4716 #if 0 /* NEW COMPOSE GUI */
4717 compose->use_to = FALSE;
4718 compose->use_cc = FALSE;
4719 compose->use_attach = TRUE;
4722 #if 0 /* NEW COMPOSE GUI */
4723 if (!compose->use_bcc) {
4724 gtk_widget_hide(bcc_hbox);
4725 gtk_widget_hide(bcc_entry);
4726 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4728 if (!compose->use_replyto) {
4729 gtk_widget_hide(reply_hbox);
4730 gtk_widget_hide(reply_entry);
4731 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4733 if (!compose->use_followupto) {
4734 gtk_widget_hide(followup_hbox);
4735 gtk_widget_hide(followup_entry);
4736 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4739 if (!prefs_common.show_ruler)
4740 gtk_widget_hide(ruler_hbox);
4742 select_account(compose, account);
4743 set_toolbar_style(compose);
4748 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4751 GtkWidget *icon_wid;
4752 GtkWidget *send_btn;
4753 GtkWidget *sendl_btn;
4754 GtkWidget *draft_btn;
4755 GtkWidget *insert_btn;
4756 GtkWidget *attach_btn;
4758 GtkWidget *exteditor_btn;
4759 GtkWidget *linewrap_btn;
4760 GtkWidget *addrbook_btn;
4762 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4764 gtk_container_add(GTK_CONTAINER(container), toolbar);
4765 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4766 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4767 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4768 GTK_TOOLBAR_SPACE_LINE);
4770 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
4771 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4775 icon_wid, toolbar_send_cb, compose);
4777 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND_QUEUE);
4778 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4780 _("Put into queue folder and send later"),
4782 icon_wid, toolbar_send_later_cb,
4785 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4786 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4788 _("Save to draft folder"),
4790 icon_wid, toolbar_draft_cb,
4793 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4795 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_INSERT_FILE);
4796 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4800 icon_wid, toolbar_insert_cb,
4803 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_ATTACH);
4804 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4808 icon_wid, toolbar_attach_cb,
4811 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4813 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SIGN);
4814 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4816 _("Insert signature"),
4818 icon_wid, toolbar_sig_cb, compose);
4820 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4822 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_EDIT_EXTERN);
4823 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4825 _("Edit with external editor"),
4828 toolbar_ext_editor_cb,
4831 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_LINEWRAP);
4832 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4834 _("Wrap all long lines"),
4837 toolbar_linewrap_cb,
4840 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4842 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_ADDRESS_BOOK);
4843 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4847 icon_wid, toolbar_address_cb,
4850 compose->toolbar = toolbar;
4851 compose->send_btn = send_btn;
4852 compose->sendl_btn = sendl_btn;
4853 compose->draft_btn = draft_btn;
4854 compose->insert_btn = insert_btn;
4855 compose->attach_btn = attach_btn;
4856 compose->sig_btn = sig_btn;
4857 compose->exteditor_btn = exteditor_btn;
4858 compose->linewrap_btn = linewrap_btn;
4859 compose->addrbook_btn = addrbook_btn;
4861 gtk_widget_show_all(toolbar);
4864 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4870 gint num = 0, def_menu = 0;
4872 accounts = account_get_list();
4873 g_return_val_if_fail(accounts != NULL, NULL);
4875 hbox = gtk_hbox_new(FALSE, 0);
4876 optmenu = gtk_option_menu_new();
4877 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4878 menu = gtk_menu_new();
4880 for (; accounts != NULL; accounts = accounts->next, num++) {
4881 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4882 GtkWidget *menuitem;
4885 if (ac == compose->account) def_menu = num;
4887 name = g_strdup_printf("%s: %s <%s>",
4888 ac->account_name, ac->name, ac->address);
4889 MENUITEM_ADD(menu, menuitem, name, ac);
4891 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4892 GTK_SIGNAL_FUNC(account_activated),
4896 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4897 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4902 static void compose_set_template_menu(Compose *compose)
4904 GSList *tmpl_list, *cur;
4908 tmpl_list = template_get_config();
4910 menu = gtk_menu_new();
4912 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4913 Template *tmpl = (Template *)cur->data;
4915 item = gtk_menu_item_new_with_label(tmpl->name);
4916 gtk_menu_append(GTK_MENU(menu), item);
4917 gtk_signal_connect(GTK_OBJECT(item), "activate",
4918 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4920 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4921 gtk_widget_show(item);
4924 gtk_widget_show(menu);
4925 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4928 void compose_reflect_prefs_all(void)
4933 for (cur = compose_list; cur != NULL; cur = cur->next) {
4934 compose = (Compose *)cur->data;
4935 compose_set_template_menu(compose);
4939 void compose_reflect_prefs_pixmap_theme(void)
4944 for (cur = compose_list; cur != NULL; cur = cur->next) {
4945 compose = (Compose *)cur->data;
4946 gtk_container_remove(GTK_CONTAINER(compose->handlebox), GTK_WIDGET(compose->toolbar));
4947 compose->toolbar = NULL;
4948 compose_toolbar_create(compose, compose->handlebox);
4949 set_toolbar_style(compose);
4953 static void compose_template_apply(Compose *compose, Template *tmpl,
4959 if (!tmpl || !tmpl->value) return;
4961 gtk_stext_freeze(GTK_STEXT(compose->text));
4963 if (tmpl->subject && *tmpl->subject != '\0')
4964 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
4966 if (tmpl->to && *tmpl->to != '\0')
4967 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
4970 gtk_stext_clear(GTK_STEXT(compose->text));
4972 if (compose->replyinfo == NULL) {
4975 memset(&dummyinfo, 0, sizeof(MsgInfo));
4976 parsed_str = compose_quote_fmt(compose, &dummyinfo,
4977 tmpl->value, NULL, NULL);
4979 if (prefs_common.quotemark && *prefs_common.quotemark)
4980 qmark = prefs_common.quotemark;
4984 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
4985 tmpl->value, qmark, NULL);
4988 if (replace && parsed_str && prefs_common.auto_sig)
4989 compose_insert_sig(compose);
4991 if (replace && parsed_str) {
4992 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
4993 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
4997 compose_changed_cb(NULL, compose);
4999 gtk_stext_thaw(GTK_STEXT(compose->text));
5002 static void compose_destroy(Compose *compose)
5005 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5008 /* NOTE: address_completion_end() does nothing with the window
5009 * however this may change. */
5010 address_completion_end(compose->window);
5012 slist_free_strings(compose->to_list);
5013 g_slist_free(compose->to_list);
5014 slist_free_strings(compose->newsgroup_list);
5015 g_slist_free(compose->newsgroup_list);
5016 slist_free_strings(compose->header_list);
5017 g_slist_free(compose->header_list);
5019 procmsg_msginfo_free(compose->targetinfo);
5020 procmsg_msginfo_free(compose->replyinfo);
5022 g_free(compose->replyto);
5023 g_free(compose->cc);
5024 g_free(compose->bcc);
5025 g_free(compose->newsgroups);
5026 g_free(compose->followup_to);
5028 g_free(compose->inreplyto);
5029 g_free(compose->references);
5030 g_free(compose->msgid);
5031 g_free(compose->boundary);
5033 if (compose->bounce_filename)
5034 g_free(compose->bounce_filename);
5036 g_free(compose->exteditor_file);
5038 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5040 compose_attach_info_free(ainfo);
5042 if (addressbook_get_target_compose() == compose)
5043 addressbook_set_target_compose(NULL);
5046 if (compose->gtkpspell) {
5047 gtkpspell_delete(compose->gtkpspell);
5051 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5052 prefs_common.compose_height = compose->window->allocation.height;
5054 gtk_widget_destroy(compose->paned);
5058 compose_list = g_list_remove(compose_list, compose);
5061 static void compose_attach_info_free(AttachInfo *ainfo)
5063 g_free(ainfo->file);
5064 g_free(ainfo->content_type);
5065 g_free(ainfo->name);
5069 static void compose_attach_remove_selected(Compose *compose)
5071 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5075 while (clist->selection != NULL) {
5076 row = GPOINTER_TO_INT(clist->selection->data);
5077 ainfo = gtk_clist_get_row_data(clist, row);
5078 compose_attach_info_free(ainfo);
5079 gtk_clist_remove(clist, row);
5083 static struct _AttachProperty
5086 GtkWidget *mimetype_entry;
5087 GtkWidget *encoding_optmenu;
5088 GtkWidget *path_entry;
5089 GtkWidget *filename_entry;
5091 GtkWidget *cancel_btn;
5094 static void compose_attach_property(Compose *compose)
5096 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5099 GtkOptionMenu *optmenu;
5100 static gboolean cancelled;
5102 if (!clist->selection) return;
5103 row = GPOINTER_TO_INT(clist->selection->data);
5105 ainfo = gtk_clist_get_row_data(clist, row);
5108 if (!attach_prop.window)
5109 compose_attach_property_create(&cancelled);
5110 gtk_widget_grab_focus(attach_prop.ok_btn);
5111 gtk_widget_show(attach_prop.window);
5112 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5114 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5115 if (ainfo->encoding == ENC_UNKNOWN)
5116 gtk_option_menu_set_history(optmenu, ENC_BASE64);
5118 gtk_option_menu_set_history(optmenu, ainfo->encoding);
5120 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5121 ainfo->content_type ? ainfo->content_type : "");
5122 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5123 ainfo->file ? ainfo->file : "");
5124 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5125 ainfo->name ? ainfo->name : "");
5129 gchar *cnttype = NULL;
5133 GtkWidget *menuitem;
5138 if (cancelled == TRUE) {
5139 gtk_widget_hide(attach_prop.window);
5143 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5144 if (*text != '\0') {
5147 text = g_strstrip(g_strdup(text));
5148 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5149 cnttype = g_strdup(text);
5152 alertpanel_error(_("Invalid MIME type."));
5158 menu = gtk_option_menu_get_menu(optmenu);
5159 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5160 ainfo->encoding = GPOINTER_TO_INT
5161 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5163 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5164 if (*text != '\0') {
5165 if (is_file_exist(text) &&
5166 (size = get_file_size(text)) > 0)
5167 file = g_strdup(text);
5170 (_("File doesn't exist or is empty."));
5176 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5177 if (*text != '\0') {
5178 g_free(ainfo->name);
5179 ainfo->name = g_strdup(text);
5183 g_free(ainfo->content_type);
5184 ainfo->content_type = cnttype;
5187 g_free(ainfo->file);
5193 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5194 ainfo->content_type);
5195 gtk_clist_set_text(clist, row, COL_SIZE,
5196 to_human_readable(ainfo->size));
5197 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5199 gtk_widget_hide(attach_prop.window);
5204 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5206 label = gtk_label_new(str); \
5207 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5208 GTK_FILL, 0, 0, 0); \
5209 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5211 entry = gtk_entry_new(); \
5212 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5213 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5216 static void compose_attach_property_create(gboolean *cancelled)
5222 GtkWidget *mimetype_entry;
5225 GtkWidget *optmenu_menu;
5226 GtkWidget *menuitem;
5227 GtkWidget *path_entry;
5228 GtkWidget *filename_entry;
5231 GtkWidget *cancel_btn;
5232 GList *mime_type_list, *strlist;
5234 debug_print("Creating attach_property window...\n");
5236 window = gtk_window_new(GTK_WINDOW_DIALOG);
5237 gtk_widget_set_usize(window, 480, -1);
5238 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5239 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
5240 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5241 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5242 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5243 GTK_SIGNAL_FUNC(attach_property_delete_event),
5245 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5246 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5249 vbox = gtk_vbox_new(FALSE, 8);
5250 gtk_container_add(GTK_CONTAINER(window), vbox);
5252 table = gtk_table_new(4, 2, FALSE);
5253 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5254 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5255 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5257 label = gtk_label_new(_("MIME type"));
5258 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5260 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5261 mimetype_entry = gtk_combo_new();
5262 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5263 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5265 /* stuff with list */
5266 mime_type_list = procmime_get_mime_type_list();
5268 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5269 MimeType *type = (MimeType *) mime_type_list->data;
5270 strlist = g_list_append(strlist,
5271 g_strdup_printf("%s/%s",
5272 type->type, type->sub_type));
5275 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5277 for (mime_type_list = strlist; mime_type_list != NULL;
5278 mime_type_list = mime_type_list->next)
5279 g_free(mime_type_list->data);
5280 g_list_free(strlist);
5282 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5284 label = gtk_label_new(_("Encoding"));
5285 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5287 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5289 hbox = gtk_hbox_new(FALSE, 0);
5290 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5291 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5293 optmenu = gtk_option_menu_new();
5294 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5296 optmenu_menu = gtk_menu_new();
5297 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5298 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5300 gtk_widget_set_sensitive(menuitem, FALSE);
5302 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5303 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5305 gtk_widget_set_sensitive(menuitem, FALSE);
5307 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5308 gtk_widget_set_sensitive(menuitem, FALSE);
5309 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5311 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5313 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5314 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5316 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5317 &cancel_btn, _("Cancel"), NULL, NULL);
5318 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5319 gtk_widget_grab_default(ok_btn);
5321 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5322 GTK_SIGNAL_FUNC(attach_property_ok),
5324 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5325 GTK_SIGNAL_FUNC(attach_property_cancel),
5328 gtk_widget_show_all(vbox);
5330 attach_prop.window = window;
5331 attach_prop.mimetype_entry = mimetype_entry;
5332 attach_prop.encoding_optmenu = optmenu;
5333 attach_prop.path_entry = path_entry;
5334 attach_prop.filename_entry = filename_entry;
5335 attach_prop.ok_btn = ok_btn;
5336 attach_prop.cancel_btn = cancel_btn;
5339 #undef SET_LABEL_AND_ENTRY
5341 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5347 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5353 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5354 gboolean *cancelled)
5362 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5363 gboolean *cancelled)
5365 if (event && event->keyval == GDK_Escape) {
5371 static void compose_exec_ext_editor(Compose *compose)
5377 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5378 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5380 if (pipe(pipe_fds) < 0) {
5385 if ((pid = fork()) < 0) {
5391 /* close the write side of the pipe */
5394 compose->exteditor_file = g_strdup(tmp);
5395 compose->exteditor_pid = pid;
5396 compose->exteditor_readdes = pipe_fds[0];
5398 compose_set_ext_editor_sensitive(compose, FALSE);
5400 compose->exteditor_tag =
5401 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5402 compose_input_cb, compose);
5403 } else { /* process-monitoring process */
5409 /* close the read side of the pipe */
5412 if (compose_write_body_to_file(compose, tmp) < 0) {
5413 fd_write(pipe_fds[1], "2\n", 2);
5417 pid_ed = compose_exec_ext_editor_real(tmp);
5419 fd_write(pipe_fds[1], "1\n", 2);
5423 /* wait until editor is terminated */
5424 waitpid(pid_ed, NULL, 0);
5426 fd_write(pipe_fds[1], "0\n", 2);
5433 static gint compose_exec_ext_editor_real(const gchar *file)
5435 static gchar *def_cmd = "emacs %s";
5441 g_return_val_if_fail(file != NULL, -1);
5443 if ((pid = fork()) < 0) {
5448 if (pid != 0) return pid;
5450 /* grandchild process */
5452 if (setpgid(0, getppid()))
5455 if (prefs_common.ext_editor_cmd &&
5456 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5457 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5458 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5460 if (prefs_common.ext_editor_cmd)
5461 g_warning(_("External editor command line is invalid: `%s'\n"),
5462 prefs_common.ext_editor_cmd);
5463 g_snprintf(buf, sizeof(buf), def_cmd, file);
5466 cmdline = strsplit_with_quote(buf, " ", 1024);
5467 execvp(cmdline[0], cmdline);
5470 g_strfreev(cmdline);
5475 static gboolean compose_ext_editor_kill(Compose *compose)
5477 pid_t pgid = compose->exteditor_pid * -1;
5480 ret = kill(pgid, 0);
5482 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5486 msg = g_strdup_printf
5487 (_("The external editor is still working.\n"
5488 "Force terminating the process?\n"
5489 "process group id: %d"), -pgid);
5490 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5493 if (val == G_ALERTDEFAULT) {
5494 gdk_input_remove(compose->exteditor_tag);
5495 close(compose->exteditor_readdes);
5497 if (kill(pgid, SIGTERM) < 0) perror("kill");
5498 waitpid(compose->exteditor_pid, NULL, 0);
5500 g_warning(_("Terminated process group id: %d"), -pgid);
5501 g_warning(_("Temporary file: %s"),
5502 compose->exteditor_file);
5504 compose_set_ext_editor_sensitive(compose, TRUE);
5506 g_free(compose->exteditor_file);
5507 compose->exteditor_file = NULL;
5508 compose->exteditor_pid = -1;
5509 compose->exteditor_readdes = -1;
5510 compose->exteditor_tag = -1;
5518 static void compose_input_cb(gpointer data, gint source,
5519 GdkInputCondition condition)
5522 Compose *compose = (Compose *)data;
5525 debug_print(_("Compose: input from monitoring process\n"));
5527 gdk_input_remove(compose->exteditor_tag);
5530 if (read(source, &buf[i], 1) < 1) {
5534 if (buf[i] == '\n') {
5539 if (i == sizeof(buf) - 1)
5543 waitpid(compose->exteditor_pid, NULL, 0);
5545 if (buf[0] == '0') { /* success */
5546 GtkSText *text = GTK_STEXT(compose->text);
5548 gtk_stext_freeze(text);
5549 gtk_stext_set_point(text, 0);
5550 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5551 compose_insert_file(compose, compose->exteditor_file);
5552 compose_changed_cb(NULL, compose);
5553 gtk_stext_thaw(text);
5555 if (unlink(compose->exteditor_file) < 0)
5556 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5557 } else if (buf[0] == '1') { /* failed */
5558 g_warning(_("Couldn't exec external editor\n"));
5559 if (unlink(compose->exteditor_file) < 0)
5560 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5561 } else if (buf[0] == '2') {
5562 g_warning(_("Couldn't write to file\n"));
5563 } else if (buf[0] == '3') {
5564 g_warning(_("Pipe read failed\n"));
5569 compose_set_ext_editor_sensitive(compose, TRUE);
5571 g_free(compose->exteditor_file);
5572 compose->exteditor_file = NULL;
5573 compose->exteditor_pid = -1;
5574 compose->exteditor_readdes = -1;
5575 compose->exteditor_tag = -1;
5578 static void compose_set_ext_editor_sensitive(Compose *compose,
5581 GtkItemFactory *ifactory;
5583 ifactory = gtk_item_factory_from_widget(compose->menubar);
5585 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5586 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5587 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5589 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5590 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5591 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5592 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5593 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5596 gtk_widget_set_sensitive(compose->text, sensitive);
5597 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5598 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5599 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5600 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5601 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5602 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5603 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5607 * compose_undo_state_changed:
5609 * Change the sensivity of the menuentries undo and redo
5611 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5612 gint redo_state, gpointer data)
5614 GtkWidget *widget = GTK_WIDGET(data);
5615 GtkItemFactory *ifactory;
5617 g_return_if_fail(widget != NULL);
5619 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
5621 ifactory = gtk_item_factory_from_widget(widget);
5623 switch (undo_state) {
5624 case UNDO_STATE_TRUE:
5625 if (!undostruct->undo_state) {
5626 debug_print ("Set_undo - Testpoint\n");
5627 undostruct->undo_state = TRUE;
5628 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5631 case UNDO_STATE_FALSE:
5632 if (undostruct->undo_state) {
5633 undostruct->undo_state = FALSE;
5634 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5637 case UNDO_STATE_UNCHANGED:
5639 case UNDO_STATE_REFRESH:
5640 menu_set_sensitive(ifactory, "/Edit/Undo",
5641 undostruct->undo_state);
5644 g_warning("Undo state not recognized");
5648 switch (redo_state) {
5649 case UNDO_STATE_TRUE:
5650 if (!undostruct->redo_state) {
5651 undostruct->redo_state = TRUE;
5652 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5655 case UNDO_STATE_FALSE:
5656 if (undostruct->redo_state) {
5657 undostruct->redo_state = FALSE;
5658 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5661 case UNDO_STATE_UNCHANGED:
5663 case UNDO_STATE_REFRESH:
5664 menu_set_sensitive(ifactory, "/Edit/Redo",
5665 undostruct->redo_state);
5668 g_warning("Redo state not recognized");
5673 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5677 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5678 cursor_pos = MAX(cursor_pos, 0);
5683 /* callback functions */
5685 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5686 * includes "non-client" (windows-izm) in calculation, so this calculation
5687 * may not be accurate.
5689 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5690 GtkAllocation *allocation,
5691 GtkSHRuler *shruler)
5693 if (prefs_common.show_ruler) {
5695 gint line_width_in_chars;
5697 char_width = gtkut_get_font_width
5698 (GTK_WIDGET(widget)->style->font);
5699 line_width_in_chars =
5700 (allocation->width - allocation->x) / char_width;
5702 /* got the maximum */
5703 gtk_ruler_set_range(GTK_RULER(shruler),
5704 0.0, line_width_in_chars,
5705 calc_cursor_xpos(GTK_STEXT(widget),
5708 /*line_width_in_chars*/ char_width);
5714 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5716 compose_send_cb(data, 0, NULL);
5719 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5721 compose_send_later_cb(data, 0, NULL);
5724 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5726 compose_draft_cb(data, 0, NULL);
5729 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5731 compose_insert_file_cb(data, 0, NULL);
5734 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5736 compose_attach_cb(data, 0, NULL);
5739 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5741 Compose *compose = (Compose *)data;
5743 compose_insert_sig(compose);
5746 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5748 Compose *compose = (Compose *)data;
5750 compose_exec_ext_editor(compose);
5753 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5755 Compose *compose = (Compose *)data;
5757 compose_wrap_line(compose);
5760 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5762 compose_address_cb(data, 0, NULL);
5765 static void select_account(Compose * compose, PrefsAccount * ac)
5768 GtkItemFactory *ifactory;
5769 GtkWidget *menuitem;
5770 #endif /* USE_GPGME */
5771 compose->account = ac;
5772 compose_set_title(compose);
5774 #if 0 /* NEW COMPOSE GUI */
5775 if (ac->protocol == A_NNTP) {
5776 GtkItemFactory *ifactory;
5777 GtkWidget *menuitem;
5779 ifactory = gtk_item_factory_from_widget(compose->menubar);
5780 menu_set_sensitive(ifactory,
5781 "/Message/Followup to", TRUE);
5782 gtk_widget_show(compose->newsgroups_hbox);
5783 gtk_widget_show(compose->newsgroups_entry);
5784 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5787 compose->use_to = FALSE;
5788 compose->use_cc = FALSE;
5790 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5791 gtk_check_menu_item_set_active
5792 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5794 menu_set_sensitive(ifactory,
5795 "/Message/To", TRUE);
5796 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5797 gtk_check_menu_item_set_active
5798 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5800 gtk_widget_hide(compose->to_hbox);
5801 gtk_widget_hide(compose->to_entry);
5802 gtk_widget_hide(compose->cc_hbox);
5803 gtk_widget_hide(compose->cc_entry);
5804 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5806 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5810 GtkItemFactory *ifactory;
5811 GtkWidget *menuitem;
5813 ifactory = gtk_item_factory_from_widget(compose->menubar);
5814 menu_set_sensitive(ifactory,
5815 "/Message/Followup to", FALSE);
5816 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5817 gtk_widget_hide(compose->newsgroups_hbox);
5818 gtk_widget_hide(compose->newsgroups_entry);
5819 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5822 compose->use_to = TRUE;
5823 compose->use_cc = TRUE;
5825 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5826 gtk_check_menu_item_set_active
5827 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5828 menu_set_sensitive(ifactory,
5829 "/Message/To", FALSE);
5830 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5831 gtk_check_menu_item_set_active
5832 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5833 gtk_widget_show(compose->to_hbox);
5834 gtk_widget_show(compose->to_entry);
5835 gtk_widget_show(compose->cc_hbox);
5836 gtk_widget_show(compose->cc_entry);
5838 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5840 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5843 gtk_widget_queue_resize(compose->table_vbox);
5846 ifactory = gtk_item_factory_from_widget(compose->menubar);
5847 menu_set_sensitive(ifactory,
5848 "/Message/Sign", TRUE);
5849 menu_set_sensitive(ifactory,
5850 "/Message/Encrypt", TRUE);
5852 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
5853 if (ac->default_sign)
5854 gtk_check_menu_item_set_active
5855 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5857 gtk_check_menu_item_set_active
5858 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5860 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
5861 if (ac->default_encrypt)
5862 gtk_check_menu_item_set_active
5863 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5865 gtk_check_menu_item_set_active
5866 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5867 #endif /* USE_GPGME */
5871 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5873 Compose *compose = (Compose *)data;
5877 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5878 g_return_if_fail(ac != NULL);
5880 if (ac != compose->account)
5881 select_account(compose, ac);
5884 static void attach_selected(GtkCList *clist, gint row, gint column,
5885 GdkEvent *event, gpointer data)
5887 Compose *compose = (Compose *)data;
5889 if (event && event->type == GDK_2BUTTON_PRESS)
5890 compose_attach_property(compose);
5893 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5896 Compose *compose = (Compose *)data;
5897 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5902 if (event->button == 3) {
5903 if ((clist->selection && !clist->selection->next) ||
5904 !clist->selection) {
5905 gtk_clist_unselect_all(clist);
5906 if (gtk_clist_get_selection_info(clist,
5909 gtk_clist_select_row(clist, row, column);
5910 gtkut_clist_set_focus_row(clist, row);
5913 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5914 NULL, NULL, event->button, event->time);
5918 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5921 Compose *compose = (Compose *)data;
5925 switch (event->keyval) {
5927 compose_attach_remove_selected(compose);
5932 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5934 Compose *compose = (Compose *)data;
5937 if (prefs_common.work_offline)
5938 if (alertpanel(_("Offline warning"),
5939 _("You're working offline. Override?"),
5940 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
5943 val = compose_send(compose);
5945 if (val == 0) gtk_widget_destroy(compose->window);
5948 static void compose_send_later_cb(gpointer data, guint action,
5951 Compose *compose = (Compose *)data;
5954 val = compose_queue_sub(compose, NULL, NULL, TRUE);
5955 if (!val) gtk_widget_destroy(compose->window);
5958 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5960 Compose *compose = (Compose *)data;
5964 MsgFlags flag = {0, 0};
5965 static gboolean lock = FALSE;
5969 draft = account_get_special_folder(compose->account, F_DRAFT);
5970 g_return_if_fail(draft != NULL);
5974 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5975 G_DIR_SEPARATOR, (gint)compose);
5977 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5983 folder_item_scan(draft);
5984 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) < 0) {
5991 draft->mtime = 0; /* force updating */
5993 if (compose->mode == COMPOSE_REEDIT) {
5994 compose_remove_reedit_target(compose);
5995 if (compose->targetinfo &&
5996 compose->targetinfo->folder != draft)
5997 folderview_update_item(compose->targetinfo->folder,
6001 procmsg_add_flags(draft, msgnum, flag);
6002 folder_item_scan(draft);
6003 folderview_update_item(draft, TRUE);
6007 /* 0: quit editing 1: keep editing */
6009 gtk_widget_destroy(compose->window);
6014 path = folder_item_fetch_msg(draft, msgnum);
6015 g_return_if_fail(path != NULL);
6016 if (stat(path, &s) < 0) {
6017 FILE_OP_ERROR(path, "stat");
6024 procmsg_msginfo_free(compose->targetinfo);
6025 compose->targetinfo = g_new0(MsgInfo, 1);
6026 compose->targetinfo->msgnum = msgnum;
6027 compose->targetinfo->size = s.st_size;
6028 compose->targetinfo->mtime = s.st_mtime;
6029 compose->targetinfo->folder = draft;
6030 compose->mode = COMPOSE_REEDIT;
6034 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6036 Compose *compose = (Compose *)data;
6039 if (compose->bounce_filename != NULL)
6042 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6047 for ( tmp = file_list; tmp; tmp = tmp->next) {
6048 gchar *file = (gchar *) tmp->data;
6049 compose_attach_append(compose, file, file, NULL);
6050 compose_changed_cb(NULL, compose);
6053 g_list_free(file_list);
6057 static void compose_insert_file_cb(gpointer data, guint action,
6060 Compose *compose = (Compose *)data;
6063 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6068 for ( tmp = file_list; tmp; tmp = tmp->next) {
6069 gchar *file = (gchar *) tmp->data;
6070 compose_insert_file(compose, file);
6073 g_list_free(file_list);
6077 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6080 compose_close_cb(data, 0, NULL);
6084 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6086 Compose *compose = (Compose *)data;
6089 if (compose->exteditor_tag != -1) {
6090 if (!compose_ext_editor_kill(compose))
6094 if (compose->modified) {
6095 val = alertpanel(_("Discard message"),
6096 _("This message has been modified. discard it?"),
6097 _("Discard"), _("to Draft"), _("Cancel"));
6100 case G_ALERTDEFAULT:
6102 case G_ALERTALTERNATE:
6103 compose_draft_cb(data, 0, NULL);
6109 gtk_widget_destroy(compose->window);
6112 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6114 Compose *compose = (Compose *)data;
6116 addressbook_open(compose);
6119 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6121 Compose *compose = (Compose *)data;
6126 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6127 g_return_if_fail(tmpl != NULL);
6129 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6131 val = alertpanel(_("Apply template"), msg,
6132 _("Replace"), _("Insert"), _("Cancel"));
6135 if (val == G_ALERTDEFAULT)
6136 compose_template_apply(compose, tmpl, TRUE);
6137 else if (val == G_ALERTALTERNATE)
6138 compose_template_apply(compose, tmpl, FALSE);
6141 static void compose_ext_editor_cb(gpointer data, guint action,
6144 Compose *compose = (Compose *)data;
6146 compose_exec_ext_editor(compose);
6149 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6151 compose_destroy(compose);
6154 static void compose_undo_cb(Compose *compose)
6156 undo_undo(compose->undostruct);
6159 static void compose_redo_cb(Compose *compose)
6161 undo_redo(compose->undostruct);
6164 static void compose_cut_cb(Compose *compose)
6166 if (compose->focused_editable &&
6167 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6168 gtk_editable_cut_clipboard
6169 (GTK_EDITABLE(compose->focused_editable));
6172 static void compose_copy_cb(Compose *compose)
6174 if (compose->focused_editable &&
6175 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6176 gtk_editable_copy_clipboard
6177 (GTK_EDITABLE(compose->focused_editable));
6180 static void compose_paste_cb(Compose *compose)
6182 if (compose->focused_editable &&
6183 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6184 gtk_editable_paste_clipboard
6185 (GTK_EDITABLE(compose->focused_editable));
6188 static void compose_allsel_cb(Compose *compose)
6190 if (compose->focused_editable &&
6191 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6192 gtk_editable_select_region
6193 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6196 static void compose_move_beginning_of_line_cb(Compose *compose)
6198 if (compose->focused_editable &&
6199 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6200 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6203 static void compose_gtk_stext_action_cb(Compose *compose, ComposeCallGtkSTextAction action)
6205 if (!(compose->focused_editable && GTK_WIDGET_HAS_FOCUS(compose->focused_editable))) return;
6208 case COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE:
6209 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6211 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER:
6212 gtk_stext_move_forward_character(GTK_STEXT(compose->focused_editable));
6214 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER:
6215 gtk_stext_move_backward_character(GTK_STEXT(compose->focused_editable));
6217 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD:
6218 gtk_stext_move_forward_word(GTK_STEXT(compose->focused_editable));
6220 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD:
6221 gtk_stext_move_backward_word(GTK_STEXT(compose->focused_editable));
6223 case COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE:
6224 gtk_stext_move_end_of_line(GTK_STEXT(compose->focused_editable));
6226 case COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE:
6227 gtk_stext_move_next_line(GTK_STEXT(compose->focused_editable));
6229 case COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE:
6230 gtk_stext_move_previous_line(GTK_STEXT(compose->focused_editable));
6232 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER:
6233 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6235 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER:
6236 gtk_stext_delete_backward_character(GTK_STEXT(compose->focused_editable));
6238 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD:
6239 gtk_stext_delete_forward_word(GTK_STEXT(compose->focused_editable));
6241 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD:
6242 gtk_stext_delete_backward_word(GTK_STEXT(compose->focused_editable));
6244 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE:
6245 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6247 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N:
6248 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6249 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6251 case COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END:
6252 gtk_stext_delete_to_line_end(GTK_STEXT(compose->focused_editable));
6259 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6261 if (GTK_IS_EDITABLE(widget))
6262 compose->focused_editable = widget;
6265 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6267 if (compose->modified == FALSE) {
6268 compose->modified = TRUE;
6269 compose_set_title(compose);
6273 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6276 gtk_stext_set_point(GTK_STEXT(widget),
6277 gtk_editable_get_position(GTK_EDITABLE(widget)));
6281 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6284 gtk_stext_set_point(GTK_STEXT(widget),
6285 gtk_editable_get_position(GTK_EDITABLE(widget)));
6289 #if 0 /* NEW COMPOSE GUI */
6290 static void compose_toggle_to_cb(gpointer data, guint action,
6293 Compose *compose = (Compose *)data;
6295 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6296 gtk_widget_show(compose->to_hbox);
6297 gtk_widget_show(compose->to_entry);
6298 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6299 compose->use_to = TRUE;
6301 gtk_widget_hide(compose->to_hbox);
6302 gtk_widget_hide(compose->to_entry);
6303 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6304 gtk_widget_queue_resize(compose->table_vbox);
6305 compose->use_to = FALSE;
6308 if (addressbook_get_target_compose() == compose)
6309 addressbook_set_target_compose(compose);
6312 static void compose_toggle_cc_cb(gpointer data, guint action,
6315 Compose *compose = (Compose *)data;
6317 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6318 gtk_widget_show(compose->cc_hbox);
6319 gtk_widget_show(compose->cc_entry);
6320 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6321 compose->use_cc = TRUE;
6323 gtk_widget_hide(compose->cc_hbox);
6324 gtk_widget_hide(compose->cc_entry);
6325 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6326 gtk_widget_queue_resize(compose->table_vbox);
6327 compose->use_cc = FALSE;
6330 if (addressbook_get_target_compose() == compose)
6331 addressbook_set_target_compose(compose);
6334 static void compose_toggle_bcc_cb(gpointer data, guint action,
6337 Compose *compose = (Compose *)data;
6339 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6340 gtk_widget_show(compose->bcc_hbox);
6341 gtk_widget_show(compose->bcc_entry);
6342 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6343 compose->use_bcc = TRUE;
6345 gtk_widget_hide(compose->bcc_hbox);
6346 gtk_widget_hide(compose->bcc_entry);
6347 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6348 gtk_widget_queue_resize(compose->table_vbox);
6349 compose->use_bcc = FALSE;
6352 if (addressbook_get_target_compose() == compose)
6353 addressbook_set_target_compose(compose);
6356 static void compose_toggle_replyto_cb(gpointer data, guint action,
6359 Compose *compose = (Compose *)data;
6361 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6362 gtk_widget_show(compose->reply_hbox);
6363 gtk_widget_show(compose->reply_entry);
6364 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6365 compose->use_replyto = TRUE;
6367 gtk_widget_hide(compose->reply_hbox);
6368 gtk_widget_hide(compose->reply_entry);
6369 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6370 gtk_widget_queue_resize(compose->table_vbox);
6371 compose->use_replyto = FALSE;
6375 static void compose_toggle_followupto_cb(gpointer data, guint action,
6378 Compose *compose = (Compose *)data;
6380 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6381 gtk_widget_show(compose->followup_hbox);
6382 gtk_widget_show(compose->followup_entry);
6383 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6384 compose->use_followupto = TRUE;
6386 gtk_widget_hide(compose->followup_hbox);
6387 gtk_widget_hide(compose->followup_entry);
6388 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6389 gtk_widget_queue_resize(compose->table_vbox);
6390 compose->use_followupto = FALSE;
6394 static void compose_toggle_attach_cb(gpointer data, guint action,
6397 Compose *compose = (Compose *)data;
6399 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6400 gtk_widget_ref(compose->edit_vbox);
6402 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6403 compose->edit_vbox);
6404 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6405 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6407 gtk_widget_show(compose->paned);
6409 gtk_widget_unref(compose->edit_vbox);
6410 gtk_widget_unref(compose->paned);
6412 compose->use_attach = TRUE;
6414 gtk_widget_ref(compose->paned);
6415 gtk_widget_ref(compose->edit_vbox);
6417 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6419 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6420 compose->edit_vbox);
6421 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6422 compose->edit_vbox, TRUE, TRUE, 0);
6424 gtk_widget_unref(compose->edit_vbox);
6426 compose->use_attach = FALSE;
6432 static void compose_toggle_sign_cb(gpointer data, guint action,
6435 Compose *compose = (Compose *)data;
6437 if (GTK_CHECK_MENU_ITEM(widget)->active)
6438 compose->use_signing = TRUE;
6440 compose->use_signing = FALSE;
6443 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6446 Compose *compose = (Compose *)data;
6448 if (GTK_CHECK_MENU_ITEM(widget)->active)
6449 compose->use_encryption = TRUE;
6451 compose->use_encryption = FALSE;
6453 #endif /* USE_GPGME */
6455 static void compose_toggle_ruler_cb(gpointer data, guint action,
6458 Compose *compose = (Compose *)data;
6460 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6461 gtk_widget_show(compose->ruler_hbox);
6462 prefs_common.show_ruler = TRUE;
6464 gtk_widget_hide(compose->ruler_hbox);
6465 gtk_widget_queue_resize(compose->edit_vbox);
6466 prefs_common.show_ruler = FALSE;
6470 static void compose_attach_drag_received_cb (GtkWidget *widget,
6471 GdkDragContext *drag_context,
6474 GtkSelectionData *data,
6479 Compose *compose = (Compose *)user_data;
6482 list = uri_list_extract_filenames((const gchar *)data->data);
6483 for (tmp = list; tmp != NULL; tmp = tmp->next)
6484 compose_attach_append
6485 (compose, (const gchar *)tmp->data,
6486 (const gchar *)tmp->data, NULL);
6487 if (list) compose_changed_cb(NULL, compose);
6488 list_free_strings(list);
6492 static void compose_insert_drag_received_cb (GtkWidget *widget,
6493 GdkDragContext *drag_context,
6496 GtkSelectionData *data,
6501 Compose *compose = (Compose *)user_data;
6504 list = uri_list_extract_filenames((const gchar *)data->data);
6505 for (tmp = list; tmp != NULL; tmp = tmp->next)
6506 compose_insert_file(compose, (const gchar *)tmp->data);
6507 list_free_strings(list);
6511 #if 0 /* NEW COMPOSE GUI */
6512 static void to_activated(GtkWidget *widget, Compose *compose)
6514 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6515 gtk_widget_grab_focus(compose->newsgroups_entry);
6517 gtk_widget_grab_focus(compose->subject_entry);
6520 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6522 gtk_widget_grab_focus(compose->subject_entry);
6525 static void subject_activated(GtkWidget *widget, Compose *compose)
6527 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6528 gtk_widget_grab_focus(compose->cc_entry);
6529 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6530 gtk_widget_grab_focus(compose->bcc_entry);
6531 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6532 gtk_widget_grab_focus(compose->reply_entry);
6533 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6534 gtk_widget_grab_focus(compose->followup_entry);
6536 gtk_widget_grab_focus(compose->text);
6539 static void cc_activated(GtkWidget *widget, Compose *compose)
6541 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6542 gtk_widget_grab_focus(compose->bcc_entry);
6543 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6544 gtk_widget_grab_focus(compose->reply_entry);
6545 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6546 gtk_widget_grab_focus(compose->followup_entry);
6548 gtk_widget_grab_focus(compose->text);
6551 static void bcc_activated(GtkWidget *widget, Compose *compose)
6553 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6554 gtk_widget_grab_focus(compose->reply_entry);
6555 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6556 gtk_widget_grab_focus(compose->followup_entry);
6558 gtk_widget_grab_focus(compose->text);
6561 static void replyto_activated(GtkWidget *widget, Compose *compose)
6563 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6564 gtk_widget_grab_focus(compose->followup_entry);
6566 gtk_widget_grab_focus(compose->text);
6569 static void followupto_activated(GtkWidget *widget, Compose *compose)
6571 gtk_widget_grab_focus(compose->text);
6575 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6578 Compose *compose = (Compose *)data;
6580 if (GTK_CHECK_MENU_ITEM(widget)->active)
6581 compose->return_receipt = TRUE;
6583 compose->return_receipt = FALSE;
6586 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6588 ComposeHeaderEntry *headerentry)
6590 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6591 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6592 !(event->state & GDK_MODIFIER_MASK) &&
6593 (event->keyval == GDK_BackSpace) &&
6594 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6595 gtk_container_remove
6596 (GTK_CONTAINER(headerentry->compose->header_table),
6597 headerentry->combo);
6598 gtk_container_remove
6599 (GTK_CONTAINER(headerentry->compose->header_table),
6600 headerentry->entry);
6601 headerentry->compose->header_list =
6602 g_slist_remove(headerentry->compose->header_list,
6604 g_free(headerentry);
6605 } else if (event->keyval == GDK_Tab) {
6606 if (headerentry->compose->header_last == headerentry) {
6607 /* Override default next focus, and give it to subject_entry
6608 * instead of notebook tabs
6610 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6611 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6617 void compose_headerentry_changed_cb(GtkWidget *entry,
6618 ComposeHeaderEntry *headerentry)
6620 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6621 headerentry->compose->header_list =
6622 g_slist_append(headerentry->compose->header_list,
6624 compose_create_header_entry(headerentry->compose);
6625 gtk_signal_disconnect_by_func
6627 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6629 /* Automatically scroll down */
6630 compose_show_first_last_header(headerentry->compose, FALSE);
6635 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6637 GtkAdjustment *vadj;
6639 g_return_if_fail(compose);
6640 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6641 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6643 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6644 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6647 static void text_activated(GtkWidget *widget, Compose *compose)
6649 compose_send_control_enter(compose);
6652 static gboolean compose_send_control_enter(Compose *compose)
6656 GtkItemFactory *ifactory;
6657 GtkAccelEntry *accel;
6658 GtkWidget *send_menu;
6660 GdkModifierType ignored_mods =
6661 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
6662 GDK_MOD4_MASK | GDK_MOD5_MASK);
6664 ev = gtk_get_current_event();
6665 if (ev->type != GDK_KEY_PRESS) return FALSE;
6667 kev = (GdkEventKey *)ev;
6668 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6671 ifactory = gtk_item_factory_from_widget(compose->menubar);
6672 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6673 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6674 accel = (GtkAccelEntry *)list->data;
6675 if (accel->accelerator_key == kev->keyval &&
6676 (accel->accelerator_mods & ~ignored_mods) ==
6677 (kev->state & ~ignored_mods)) {
6678 compose_send_cb(compose, 0, NULL);
6686 static void compose_check_all(Compose *compose)
6688 if (compose->gtkpspell)
6689 gtkpspell_check_all(compose->gtkpspell);
6692 static void compose_highlight_all(Compose *compose)
6694 if (compose->gtkpspell)
6695 gtkpspell_highlight_all(compose->gtkpspell);
6698 static void compose_check_backwards(Compose *compose)
6700 if (compose->gtkpspell)
6701 gtkpspell_check_backwards(compose->gtkpspell);
6703 GtkItemFactory *ifactory;
6704 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6705 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6706 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6710 static void compose_check_forwards_go(Compose *compose)
6712 if (compose->gtkpspell)
6713 gtkpspell_check_forwards_go(compose->gtkpspell);
6715 GtkItemFactory *ifactory;
6716 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6717 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6718 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6723 static void set_toolbar_style(Compose *compose)
6725 switch (prefs_common.toolbar_style) {
6727 gtk_widget_hide(compose->handlebox);
6730 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6734 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6738 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6743 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
6744 gtk_widget_show(compose->handlebox);
6745 gtk_widget_queue_resize(compose->handlebox);