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,
163 static void compose_destroy (Compose *compose);
165 static void compose_entries_set (Compose *compose,
166 const gchar *mailto);
167 static gint compose_parse_header (Compose *compose,
169 static gchar *compose_parse_references (const gchar *ref,
172 static gchar *compose_quote_fmt (Compose *compose,
178 static void compose_reply_set_entry (Compose *compose,
183 followup_and_reply_to);
184 static void compose_reedit_set_entry (Compose *compose,
186 static void compose_insert_sig (Compose *compose);
187 static void compose_insert_file (Compose *compose,
189 static void compose_attach_append (Compose *compose,
192 const gchar *content_type);
193 static void compose_attach_parts (Compose *compose,
195 static void compose_wrap_line (Compose *compose);
196 static void compose_wrap_line_all (Compose *compose);
197 static void compose_set_title (Compose *compose);
199 static PrefsAccount *compose_current_mail_account(void);
200 /* static gint compose_send (Compose *compose); */
201 static gboolean compose_check_for_valid_recipient
203 static gboolean compose_check_entries (Compose *compose);
204 static gint compose_write_to_file (Compose *compose,
207 static gint compose_write_body_to_file (Compose *compose,
209 static gint compose_remove_reedit_target (Compose *compose);
210 static gint compose_queue (Compose *compose,
213 static void compose_write_attach (Compose *compose,
215 static gint compose_write_headers (Compose *compose,
217 const gchar *charset,
218 EncodingType encoding,
221 static void compose_convert_header (gchar *dest,
225 static void compose_generate_msgid (Compose *compose,
229 static void compose_attach_info_free (AttachInfo *ainfo);
230 static void compose_attach_remove_selected (Compose *compose);
232 static void compose_attach_property (Compose *compose);
233 static void compose_attach_property_create (gboolean *cancelled);
234 static void attach_property_ok (GtkWidget *widget,
235 gboolean *cancelled);
236 static void attach_property_cancel (GtkWidget *widget,
237 gboolean *cancelled);
238 static gint attach_property_delete_event (GtkWidget *widget,
240 gboolean *cancelled);
241 static void attach_property_key_pressed (GtkWidget *widget,
243 gboolean *cancelled);
245 static void compose_exec_ext_editor (Compose *compose);
246 static gint compose_exec_ext_editor_real (const gchar *file);
247 static gboolean compose_ext_editor_kill (Compose *compose);
248 static void compose_input_cb (gpointer data,
250 GdkInputCondition condition);
251 static void compose_set_ext_editor_sensitive (Compose *compose,
254 static void compose_undo_state_changed (UndoMain *undostruct,
259 static gint calc_cursor_xpos (GtkSText *text,
263 static void compose_create_header_entry (Compose *compose);
264 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
266 /* callback functions */
268 static gboolean compose_edit_size_alloc (GtkEditable *widget,
269 GtkAllocation *allocation,
270 GtkSHRuler *shruler);
272 static void toolbar_send_cb (GtkWidget *widget,
274 static void toolbar_send_later_cb (GtkWidget *widget,
276 static void toolbar_draft_cb (GtkWidget *widget,
278 static void toolbar_insert_cb (GtkWidget *widget,
280 static void toolbar_attach_cb (GtkWidget *widget,
282 static void toolbar_sig_cb (GtkWidget *widget,
284 static void toolbar_ext_editor_cb (GtkWidget *widget,
286 static void toolbar_linewrap_cb (GtkWidget *widget,
288 static void toolbar_address_cb (GtkWidget *widget,
291 static void select_account (Compose *compose,
294 static void account_activated (GtkMenuItem *menuitem,
297 static void attach_selected (GtkCList *clist,
302 static void attach_button_pressed (GtkWidget *widget,
303 GdkEventButton *event,
305 static void attach_key_pressed (GtkWidget *widget,
309 static void compose_send_cb (gpointer data,
312 static void compose_send_later_cb (gpointer data,
316 static void compose_draft_cb (gpointer data,
320 static void compose_attach_cb (gpointer data,
323 static void compose_insert_file_cb (gpointer data,
327 static void compose_close_cb (gpointer data,
331 static void compose_address_cb (gpointer data,
334 static void compose_template_activate_cb(GtkWidget *widget,
337 static void compose_ext_editor_cb (gpointer data,
341 static gint compose_delete_cb (GtkWidget *widget,
344 static void compose_destroy_cb (GtkWidget *widget,
347 static void compose_undo_cb (Compose *compose);
348 static void compose_redo_cb (Compose *compose);
349 static void compose_cut_cb (Compose *compose);
350 static void compose_copy_cb (Compose *compose);
351 static void compose_paste_cb (Compose *compose);
352 static void compose_allsel_cb (Compose *compose);
354 static void compose_gtk_stext_action_cb (Compose *compose,
355 ComposeCallGtkSTextAction action);
357 static void compose_grab_focus_cb (GtkWidget *widget,
360 static void compose_changed_cb (GtkEditable *editable,
362 static void compose_button_press_cb (GtkWidget *widget,
363 GdkEventButton *event,
366 static void compose_key_press_cb (GtkWidget *widget,
372 static void compose_toggle_to_cb (gpointer data,
375 static void compose_toggle_cc_cb (gpointer data,
378 static void compose_toggle_bcc_cb (gpointer data,
381 static void compose_toggle_replyto_cb (gpointer data,
384 static void compose_toggle_followupto_cb(gpointer data,
387 static void compose_toggle_attach_cb (gpointer data,
391 static void compose_toggle_ruler_cb (gpointer data,
395 static void compose_toggle_sign_cb (gpointer data,
398 static void compose_toggle_encrypt_cb (gpointer data,
402 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
405 static void compose_attach_drag_received_cb (GtkWidget *widget,
406 GdkDragContext *drag_context,
409 GtkSelectionData *data,
413 static void compose_insert_drag_received_cb (GtkWidget *widget,
414 GdkDragContext *drag_context,
417 GtkSelectionData *data,
423 static void to_activated (GtkWidget *widget,
425 static void newsgroups_activated (GtkWidget *widget,
427 static void subject_activated (GtkWidget *widget,
429 static void cc_activated (GtkWidget *widget,
431 static void bcc_activated (GtkWidget *widget,
433 static void replyto_activated (GtkWidget *widget,
435 static void followupto_activated (GtkWidget *widget,
439 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
441 gboolean ignore_replyto,
442 gboolean followup_and_reply_to,
445 void compose_headerentry_changed_cb (GtkWidget *entry,
446 ComposeHeaderEntry *headerentry);
447 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
449 ComposeHeaderEntry *headerentry);
451 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
454 static void compose_check_all (Compose *compose);
455 static void compose_highlight_all (Compose *compose);
456 static void compose_check_backwards (Compose *compose);
457 static void compose_check_forwards_go (Compose *compose);
460 static gboolean compose_send_control_enter (Compose *compose);
461 static void text_activated (GtkWidget *widget,
464 static GtkItemFactoryEntry compose_popup_entries[] =
466 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
467 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
468 {N_("/---"), NULL, NULL, 0, "<Separator>"},
469 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
472 static GtkItemFactoryEntry compose_entries[] =
474 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
475 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
476 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
477 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
478 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
479 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
481 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
482 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
483 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
484 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
485 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
486 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
487 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
488 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
489 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
490 {N_("/_Edit/A_dvanced/Move a character backward"),
492 compose_gtk_stext_action_cb,
493 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
495 {N_("/_Edit/A_dvanced/Move a character forward"),
497 compose_gtk_stext_action_cb,
498 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
500 {N_("/_Edit/A_dvanced/Move a word backward"),
502 compose_gtk_stext_action_cb,
503 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
505 {N_("/_Edit/A_dvanced/Move a word forward"),
507 compose_gtk_stext_action_cb,
508 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
510 {N_("/_Edit/A_dvanced/Move to beginning of line"),
511 NULL, /* "<control>A" */
512 compose_gtk_stext_action_cb,
513 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
515 {N_("/_Edit/A_dvanced/Move to end of line"),
517 compose_gtk_stext_action_cb,
518 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
520 {N_("/_Edit/A_dvanced/Move to previous line"),
522 compose_gtk_stext_action_cb,
523 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
525 {N_("/_Edit/A_dvanced/Move to next line"),
527 compose_gtk_stext_action_cb,
528 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
530 {N_("/_Edit/A_dvanced/Delete a character backward"),
532 compose_gtk_stext_action_cb,
533 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
535 {N_("/_Edit/A_dvanced/Delete a character forward"),
537 compose_gtk_stext_action_cb,
538 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
540 {N_("/_Edit/A_dvanced/Delete a word backward"),
541 NULL, /* "<control>W" */
542 compose_gtk_stext_action_cb,
543 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
545 {N_("/_Edit/A_dvanced/Delete a word forward"),
546 NULL, /* "<alt>D", */
547 compose_gtk_stext_action_cb,
548 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
550 {N_("/_Edit/A_dvanced/Delete line"),
552 compose_gtk_stext_action_cb,
553 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
555 {N_("/_Edit/A_dvanced/Delete entire line"),
557 compose_gtk_stext_action_cb,
558 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
560 {N_("/_Edit/A_dvanced/Delete to end of line"),
562 compose_gtk_stext_action_cb,
563 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
565 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
566 {N_("/_Edit/_Wrap current paragraph"),
567 "<control>L", compose_wrap_line, 0, NULL},
568 {N_("/_Edit/Wrap all long _lines"),
569 "<control><alt>L", compose_wrap_line_all, 0, NULL},
570 {N_("/_Edit/Edit with e_xternal editor"),
571 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
573 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
574 {N_("/_Spelling/_Check all or check selection"),
575 NULL, compose_check_all, 0, NULL},
576 {N_("/_Spelling/_Highlight all misspelled words"),
577 NULL, compose_highlight_all, 0, NULL},
578 {N_("/_Spelling/Check _backwards misspelled word"),
579 NULL, compose_check_backwards , 0, NULL},
580 {N_("/_Spelling/_Forward to next misspelled word"),
581 NULL, compose_check_forwards_go, 0, NULL},
582 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
583 {N_("/_Spelling/_Spelling Configuration"),
584 NULL, NULL, 0, "<Branch>"},
586 #if 0 /* NEW COMPOSE GUI */
587 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
588 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
589 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
590 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
591 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
592 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
593 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
594 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
595 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
596 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
597 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
599 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
600 {N_("/_Message/_Send"), "<control>Return",
601 compose_send_cb, 0, NULL},
602 {N_("/_Message/Send _later"), "<shift><control>S",
603 compose_send_later_cb, 0, NULL},
604 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
605 {N_("/_Message/Save to _draft folder"),
606 "<shift><control>D", compose_draft_cb, 0, NULL},
607 {N_("/_Message/Save and _keep editing"),
608 "<control>S", compose_draft_cb, 1, NULL},
609 #if 0 /* NEW COMPOSE GUI */
610 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
611 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
612 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
613 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
614 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
615 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
616 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
617 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
618 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
621 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
622 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
623 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
624 #endif /* USE_GPGME */
625 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
626 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
627 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
628 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
629 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
630 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
631 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
632 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
633 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
636 static GtkTargetEntry compose_mime_types[] =
638 {"text/uri-list", 0, 0}
641 Compose *compose_new(PrefsAccount *account)
643 return compose_generic_new(account, NULL, NULL);
646 Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
650 GtkItemFactory *ifactory;
652 c = compose_generic_new(account, NULL, NULL);
654 filename = procmsg_get_message_file(msginfo);
655 if (filename == NULL)
658 c->bounce_filename = filename;
660 if (msginfo->subject)
661 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
663 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
665 compose_quote_fmt(c, msginfo, "%M", NULL, NULL);
666 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
668 ifactory = gtk_item_factory_from_widget(c->popupmenu);
669 menu_set_sensitive(ifactory, "/Add...", FALSE);
670 menu_set_sensitive(ifactory, "/Remove", FALSE);
671 menu_set_sensitive(ifactory, "/Property...", FALSE);
673 ifactory = gtk_item_factory_from_widget(c->menubar);
674 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
675 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
676 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
677 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
678 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
679 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
680 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
681 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
683 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
684 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
686 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
687 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
689 gtk_widget_set_sensitive(c->insert_btn, FALSE);
690 gtk_widget_set_sensitive(c->attach_btn, FALSE);
691 gtk_widget_set_sensitive(c->sig_btn, FALSE);
692 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
693 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
698 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
700 return compose_generic_new(account, mailto, NULL);
703 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
705 return compose_generic_new(account, NULL, item);
708 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
712 if (item && item->prefs && item->prefs->enable_default_account)
713 account = account_find_from_id(item->prefs->default_account);
715 if (!account) account = cur_account;
716 g_return_val_if_fail(account != NULL, NULL);
718 compose = compose_create(account, COMPOSE_NEW);
719 compose->replyinfo = NULL;
721 if (prefs_common.auto_sig)
722 compose_insert_sig(compose);
723 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
724 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
726 if (account->protocol != A_NNTP) {
728 compose_entries_set(compose, mailto);
730 } else if(item && item->prefs->enable_default_to) {
731 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
733 if (item && item->ret_rcpt) {
734 GtkItemFactory *ifactory;
736 ifactory = gtk_item_factory_from_widget(compose->menubar);
737 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
741 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
744 compose_show_first_last_header(compose, TRUE);
746 /* Set save folder */
747 if(item && item->prefs && item->prefs->save_copy_to_folder) {
748 gchar *folderidentifier;
750 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
751 folderidentifier = folder_item_get_identifier(item);
752 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
753 g_free(folderidentifier);
756 gtk_widget_grab_focus(compose->header_last->entry);
758 if (prefs_common.auto_exteditor)
759 compose_exec_ext_editor(compose);
764 #define CHANGE_FLAGS(msginfo) \
766 if (msginfo->folder->folder->change_flags != NULL) \
767 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
773 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
774 const gchar *followupto, gchar * to)
778 if (!account) account = cur_account;
779 g_return_val_if_fail(account != NULL, NULL);
780 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
782 compose = compose_create(account, COMPOSE_NEW);
784 if (prefs_common.auto_sig)
785 compose_insert_sig(compose);
786 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
787 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
789 compose_entry_append(compose, to, COMPOSE_TO);
790 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
791 gtk_widget_grab_focus(compose->subject_entry);
797 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
798 gboolean ignore_replyto, const gchar *body)
800 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE,
804 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
806 gboolean ignore_replyto,
809 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE,
813 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
815 gboolean ignore_replyto,
816 gboolean followup_and_reply_to,
820 PrefsAccount *account;
821 PrefsAccount *reply_account;
824 g_return_if_fail(msginfo != NULL);
825 g_return_if_fail(msginfo->folder != NULL);
828 /* select the account set in folderitem's property (if enabled) */
829 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
830 account = account_find_from_id(msginfo->folder->prefs->default_account);
832 /* select the account for the whole folder (IMAP / NNTP) */
834 /* FIXME: this is not right, because folder may be nested. we should
835 * ascend the tree until we find a parent with proper account
837 account = msginfo->folder->folder->account;
839 /* select account by to: and cc: header if enabled */
840 if (prefs_common.reply_account_autosel) {
841 if (!account && msginfo->to) {
843 Xstrdup_a(to, msginfo->to, return);
845 account = account_find_from_address(to);
849 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
851 account = account_find_from_address(cc);
856 /* select current account */
857 if (!account) account = cur_account;
858 g_return_if_fail(account != NULL);
860 if (ignore_replyto && account->protocol == A_NNTP &&
861 !followup_and_reply_to) {
863 account_find_from_address(account->address);
865 reply_account = compose_current_mail_account();
869 reply_account = account;
871 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
872 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
873 if (MSG_IS_IMAP(msginfo->flags))
874 imap_msg_set_perm_flags(msginfo, MSG_REPLIED);
875 CHANGE_FLAGS(msginfo);
877 compose = compose_create(account, COMPOSE_REPLY);
878 compose->replyinfo = procmsg_msginfo_copy(msginfo);
880 #if 0 /* NEW COMPOSE GUI */
881 if (followup_and_reply_to) {
882 gtk_widget_show(compose->to_hbox);
883 gtk_widget_show(compose->to_entry);
884 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
885 compose->use_to = TRUE;
888 if (msginfo->folder && msginfo->folder->ret_rcpt) {
889 GtkItemFactory *ifactory;
891 ifactory = gtk_item_factory_from_widget(compose->menubar);
892 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
895 /* Set save folder */
896 if(msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
897 gchar *folderidentifier;
899 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
900 folderidentifier = folder_item_get_identifier(msginfo->folder);
901 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
902 g_free(folderidentifier);
905 if (compose_parse_header(compose, msginfo) < 0) return;
906 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
907 followup_and_reply_to);
908 compose_show_first_last_header(compose, TRUE);
910 text = GTK_STEXT(compose->text);
911 gtk_stext_freeze(text);
917 if (prefs_common.quotemark && *prefs_common.quotemark)
918 qmark = prefs_common.quotemark;
922 quote_str = compose_quote_fmt(compose, msginfo,
923 prefs_common.quotefmt,
927 if (prefs_common.auto_sig)
928 compose_insert_sig(compose);
930 if (quote && prefs_common.linewrap_quote)
931 compose_wrap_line_all(compose);
933 gtk_editable_set_position(GTK_EDITABLE(text), 0);
934 gtk_stext_set_point(text, 0);
936 gtk_stext_thaw(text);
937 gtk_widget_grab_focus(compose->text);
939 if (prefs_common.auto_exteditor)
940 compose_exec_ext_editor(compose);
943 static void set_toolbar_style(Compose *compose);
945 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
950 g_return_val_if_fail(mimeinfo != NULL, NULL);
952 base = mimeinfo->filename ? mimeinfo->filename
953 : mimeinfo->name ? mimeinfo->name : NULL;
955 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
956 filename = g_strdup_printf("%s%smimetmp.%08x.html",
963 base = base ? base : "";
964 base = g_basename(base);
966 filename = g_strdup_printf("%s%smimetmp.%08x",
974 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
980 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
984 if (!partinfo) return NULL;
986 filename = procmime_get_file_name(partinfo);
988 if (procmime_get_part(filename, source, partinfo) < 0)
990 (_("Can't get the part of multipart message."));
997 #define INSERT_FW_HEADER(var, hdr) \
998 if (msginfo->var && *msginfo->var) { \
999 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1000 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1001 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1004 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1005 gboolean as_attach, const gchar *body)
1008 /* PrefsAccount *account; */
1011 g_return_val_if_fail(msginfo != NULL, NULL);
1012 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1014 account = msginfo->folder->folder->account;
1015 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1017 Xstrdup_a(to, msginfo->to, return NULL);
1018 extract_address(to);
1019 account = account_find_from_address(to);
1022 if(!account && prefs_common.forward_account_autosel) {
1024 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1025 extract_address(cc);
1026 account = account_find_from_address(cc);
1030 if (account == NULL) {
1031 account = cur_account;
1033 account = msginfo->folder->folder->account;
1034 if (!account) account = cur_account;
1037 g_return_val_if_fail(account != NULL, NULL);
1039 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1040 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1041 if (MSG_IS_IMAP(msginfo->flags))
1042 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1043 CHANGE_FLAGS(msginfo);
1045 compose = compose_create(account, COMPOSE_FORWARD);
1047 if (msginfo->subject && *msginfo->subject) {
1048 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1049 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1053 text = GTK_STEXT(compose->text);
1054 gtk_stext_freeze(text);
1060 msgfile = procmsg_get_message_file_path(msginfo);
1061 if (!is_file_exist(msgfile))
1062 g_warning(_("%s: file not exist\n"), msgfile);
1064 compose_attach_append(compose, msgfile, msgfile,
1072 if (prefs_common.fw_quotemark &&
1073 *prefs_common.fw_quotemark)
1074 qmark = prefs_common.fw_quotemark;
1078 quote_str = compose_quote_fmt(compose, msginfo,
1079 prefs_common.fw_quotefmt,
1081 compose_attach_parts(compose, msginfo);
1084 if (prefs_common.auto_sig)
1085 compose_insert_sig(compose);
1087 if (prefs_common.linewrap_quote)
1088 compose_wrap_line_all(compose);
1090 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1091 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1093 gtk_stext_thaw(text);
1094 #if 0 /* NEW COMPOSE GUI */
1095 if (account->protocol != A_NNTP)
1096 gtk_widget_grab_focus(compose->to_entry);
1098 gtk_widget_grab_focus(compose->newsgroups_entry);
1100 gtk_widget_grab_focus(compose->header_last->entry);
1102 if (prefs_common.auto_exteditor)
1103 compose_exec_ext_editor(compose);
1108 #undef INSERT_FW_HEADER
1110 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1117 g_return_val_if_fail(msginfo_list != NULL, NULL);
1119 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1120 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1124 if (account == NULL) {
1125 account = cur_account;
1127 account = msginfo->folder->folder->account;
1128 if (!account) account = cur_account;
1131 g_return_val_if_fail(account != NULL, NULL);
1133 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1134 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1135 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1136 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1139 compose = compose_create(account, COMPOSE_FORWARD);
1141 text = GTK_STEXT(compose->text);
1142 gtk_stext_freeze(text);
1144 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1145 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1146 if (!is_file_exist(msgfile))
1147 g_warning(_("%s: file not exist\n"), msgfile);
1149 compose_attach_append(compose, msgfile, msgfile,
1154 if (prefs_common.auto_sig)
1155 compose_insert_sig(compose);
1157 if (prefs_common.linewrap_quote)
1158 compose_wrap_line_all(compose);
1160 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1161 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1163 gtk_stext_thaw(text);
1164 #if 0 /* NEW COMPOSE GUI */
1165 if (account->protocol != A_NNTP)
1166 gtk_widget_grab_focus(compose->to_entry);
1168 gtk_widget_grab_focus(compose->newsgroups_entry);
1174 void compose_reedit(MsgInfo *msginfo)
1177 PrefsAccount *account = NULL;
1180 gchar buf[BUFFSIZE];
1182 g_return_if_fail(msginfo != NULL);
1183 g_return_if_fail(msginfo->folder != NULL);
1185 if (msginfo->folder->stype == F_QUEUE) {
1186 gchar queueheader_buf[BUFFSIZE];
1189 /* Select Account from queue headers */
1190 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1191 sizeof(queueheader_buf), "NAID:")) {
1192 id = atoi(&queueheader_buf[5]);
1193 account = account_find_from_id(id);
1195 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1196 sizeof(queueheader_buf), "MAID:")) {
1197 id = atoi(&queueheader_buf[5]);
1198 account = account_find_from_id(id);
1200 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1201 sizeof(queueheader_buf), "S:")) {
1202 account = account_find_from_address(queueheader_buf);
1205 account = msginfo->folder->folder->account;
1207 if (!account && prefs_common.reedit_account_autosel) {
1208 gchar from[BUFFSIZE];
1209 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1210 extract_address(from);
1211 account = account_find_from_address(from);
1214 if (!account) account = cur_account;
1215 g_return_if_fail(account != NULL);
1217 compose = compose_create(account, COMPOSE_REEDIT);
1218 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1220 if (msginfo->folder->stype == F_QUEUE) {
1221 gchar queueheader_buf[BUFFSIZE];
1223 /* Set message save folder */
1224 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1227 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1228 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1229 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1233 if (compose_parse_header(compose, msginfo) < 0) return;
1234 compose_reedit_set_entry(compose, msginfo);
1236 text = GTK_STEXT(compose->text);
1237 gtk_stext_freeze(text);
1239 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1240 g_warning(_("Can't get text part\n"));
1242 while (fgets(buf, sizeof(buf), fp) != NULL)
1243 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1246 compose_attach_parts(compose, msginfo);
1248 gtk_stext_thaw(text);
1249 gtk_widget_grab_focus(compose->text);
1251 if (prefs_common.auto_exteditor)
1252 compose_exec_ext_editor(compose);
1255 GList *compose_get_compose_list(void)
1257 return compose_list;
1260 void compose_entry_append(Compose *compose, const gchar *address,
1261 ComposeEntryType type)
1267 if (!address || *address == '\0') return;
1269 #if 0 /* NEW COMPOSE GUI */
1272 entry = GTK_ENTRY(compose->cc_entry);
1275 entry = GTK_ENTRY(compose->bcc_entry);
1277 case COMPOSE_NEWSGROUPS:
1278 entry = GTK_ENTRY(compose->newsgroups_entry);
1282 entry = GTK_ENTRY(compose->to_entry);
1286 text = gtk_entry_get_text(entry);
1288 gtk_entry_append_text(entry, ", ");
1289 gtk_entry_append_text(entry, address);
1297 header = N_("Bcc:");
1299 case COMPOSE_REPLYTO:
1300 header = N_("Reply-To:");
1302 case COMPOSE_NEWSGROUPS:
1303 header = N_("Newsgroups:");
1305 case COMPOSE_FOLLOWUPTO:
1306 header = N_( "Followup-To:");
1313 header = prefs_common.trans_hdr ? gettext(header) : header;
1315 compose_add_header_entry(compose, header, (gchar *)address);
1318 static void compose_entries_set(Compose *compose, const gchar *mailto)
1320 gchar *subject = NULL;
1328 Xstrdup_a(tmp_mailto, mailto, return);
1332 p = strchr(tmp_mailto, '?');
1339 gchar *field, *value;
1356 if (*value == '\0') continue;
1358 if (!g_strcasecmp(field, "subject")) {
1359 Xalloca(subject, strlen(value) + 1, return);
1360 decode_uri(subject, value);
1361 } else if (!g_strcasecmp(field, "cc")) {
1363 } else if (!g_strcasecmp(field, "bcc")) {
1365 } else if (!g_strcasecmp(field, "body")) {
1366 Xalloca(body, strlen(value) + 1, return);
1367 decode_uri(body, value);
1372 compose_entry_append(compose, to, COMPOSE_TO);
1374 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1376 compose_entry_append(compose, cc, COMPOSE_CC);
1378 compose_entry_append(compose, bcc, COMPOSE_BCC);
1380 gtk_stext_insert(GTK_STEXT(compose->text),
1381 NULL, NULL, NULL, body, -1);
1382 gtk_stext_insert(GTK_STEXT(compose->text),
1383 NULL, NULL, NULL, "\n", 1);
1387 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1389 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1390 {"Cc:", NULL, FALSE},
1391 {"References:", NULL, FALSE},
1392 {"Bcc:", NULL, FALSE},
1393 {"Newsgroups:", NULL, FALSE},
1394 {"Followup-To:", NULL, FALSE},
1395 {"X-Mailing-List:", NULL, FALSE},
1396 {"X-BeenThere:", NULL, FALSE},
1397 {NULL, NULL, FALSE}};
1407 H_X_MAILING_LIST = 6,
1413 g_return_val_if_fail(msginfo != NULL, -1);
1415 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1416 procheader_get_header_fields(fp, hentry);
1419 if (hentry[H_REPLY_TO].body != NULL) {
1420 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1421 compose->replyto = hentry[H_REPLY_TO].body;
1422 hentry[H_REPLY_TO].body = NULL;
1424 if (hentry[H_CC].body != NULL) {
1425 conv_unmime_header_overwrite(hentry[H_CC].body);
1426 compose->cc = hentry[H_CC].body;
1427 hentry[H_CC].body = NULL;
1429 if (hentry[H_X_MAILING_LIST].body != NULL) {
1430 /* this is good enough to parse debian-devel */
1431 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1432 g_return_val_if_fail(buf != NULL, -1 );
1433 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1434 compose->mailinglist = g_strdup(buf);
1436 g_free(hentry[H_X_MAILING_LIST].body);
1437 hentry[H_X_MAILING_LIST].body = NULL ;
1439 if (hentry[H_X_BEENTHERE].body != NULL) {
1440 /* this is good enough to parse the sylpheed-claws lists */
1441 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1442 g_return_val_if_fail(buf != NULL, -1 );
1443 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1444 compose->mailinglist = g_strdup(buf);
1446 g_free(hentry[H_X_BEENTHERE].body);
1447 hentry[H_X_BEENTHERE].body = NULL ;
1449 if (hentry[H_REFERENCES].body != NULL) {
1450 if (compose->mode == COMPOSE_REEDIT)
1451 compose->references = hentry[H_REFERENCES].body;
1453 compose->references = compose_parse_references
1454 (hentry[H_REFERENCES].body, msginfo->msgid);
1455 g_free(hentry[H_REFERENCES].body);
1457 hentry[H_REFERENCES].body = NULL;
1459 if (hentry[H_BCC].body != NULL) {
1460 if (compose->mode == COMPOSE_REEDIT) {
1461 conv_unmime_header_overwrite(hentry[H_BCC].body);
1462 compose->bcc = hentry[H_BCC].body;
1464 g_free(hentry[H_BCC].body);
1465 hentry[H_BCC].body = NULL;
1467 if (hentry[H_NEWSGROUPS].body != NULL) {
1468 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1469 hentry[H_NEWSGROUPS].body = NULL;
1471 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1472 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1473 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1474 hentry[H_FOLLOWUP_TO].body = NULL;
1477 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1478 compose->inreplyto = g_strdup(msginfo->inreplyto);
1479 else if (compose->mode != COMPOSE_REEDIT &&
1480 msginfo->msgid && *msginfo->msgid) {
1481 compose->inreplyto = g_strdup(msginfo->msgid);
1483 if (!compose->references) {
1484 if (msginfo->inreplyto && *msginfo->inreplyto)
1485 compose->references =
1486 g_strdup_printf("<%s>\n\t<%s>",
1490 compose->references =
1491 g_strconcat("<", msginfo->msgid, ">",
1499 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1501 GSList *ref_id_list, *cur;
1505 ref_id_list = references_list_append(NULL, ref);
1506 if (!ref_id_list) return NULL;
1507 if (msgid && *msgid)
1508 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1513 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1514 /* "<" + Message-ID + ">" + CR+LF+TAB */
1515 len += strlen((gchar *)cur->data) + 5;
1517 if (len > MAX_REFERENCES_LEN) {
1518 /* remove second message-ID */
1519 if (ref_id_list && ref_id_list->next &&
1520 ref_id_list->next->next) {
1521 g_free(ref_id_list->next->data);
1522 ref_id_list = g_slist_remove
1523 (ref_id_list, ref_id_list->next->data);
1525 slist_free_strings(ref_id_list);
1526 g_slist_free(ref_id_list);
1533 new_ref = g_string_new("");
1534 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1535 if (new_ref->len > 0)
1536 g_string_append(new_ref, "\n\t");
1537 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1540 slist_free_strings(ref_id_list);
1541 g_slist_free(ref_id_list);
1543 new_ref_str = new_ref->str;
1544 g_string_free(new_ref, FALSE);
1549 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1550 const gchar *fmt, const gchar *qmark,
1553 GtkSText *text = GTK_STEXT(compose->text);
1554 gchar *quote_str = NULL;
1559 if (qmark != NULL) {
1560 quote_fmt_init(msginfo, NULL, NULL);
1561 quote_fmt_scan_string(qmark);
1564 buf = quote_fmt_get_buffer();
1566 alertpanel_error(_("Quote mark format error."));
1568 Xstrdup_a(quote_str, buf, return NULL)
1571 if (fmt && *fmt != '\0') {
1572 quote_fmt_init(msginfo, quote_str, body);
1573 quote_fmt_scan_string(fmt);
1576 buf = quote_fmt_get_buffer();
1578 alertpanel_error(_("Message reply/forward format error."));
1584 gtk_stext_freeze(text);
1586 for (p = buf; *p != '\0'; ) {
1587 lastp = strchr(p, '\n');
1588 len = lastp ? lastp - p + 1 : -1;
1589 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1596 gtk_stext_thaw(text);
1601 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1602 gboolean to_all, gboolean ignore_replyto,
1603 gboolean followup_and_reply_to)
1605 GSList *cc_list = NULL;
1608 gchar *replyto = NULL;
1609 GHashTable *to_table;
1611 g_return_if_fail(compose->account != NULL);
1612 g_return_if_fail(msginfo != NULL);
1614 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1615 compose_entry_append(compose,
1616 ((compose->replyto && !ignore_replyto)
1618 : (compose->mailinglist && !ignore_replyto)
1619 ? compose->mailinglist
1620 : msginfo->from ? msginfo->from : ""),
1623 if (compose->account->protocol == A_NNTP) {
1625 compose_entry_append
1626 (compose, msginfo->from ? msginfo->from : "",
1629 compose_entry_append
1631 compose->followup_to ? compose->followup_to
1632 : compose->newsgroups ? compose->newsgroups
1634 COMPOSE_NEWSGROUPS);
1637 if (msginfo->subject && *msginfo->subject) {
1638 gchar *buf, *buf2, *p;
1640 buf = g_strdup(msginfo->subject);
1641 while (!strncasecmp(buf, "Re:", 3)) {
1643 while (isspace(*p)) p++;
1644 memmove(buf, p, strlen(p) + 1);
1647 buf2 = g_strdup_printf("Re: %s", buf);
1648 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1652 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1654 if (!to_all || compose->account->protocol == A_NNTP) return;
1656 if (compose->replyto) {
1657 Xstrdup_a(replyto, compose->replyto, return);
1658 extract_address(replyto);
1660 if (msginfo->from) {
1661 Xstrdup_a(from, msginfo->from, return);
1662 extract_address(from);
1665 if (compose->mailinglist && from) {
1666 cc_list = address_list_append(cc_list, from);
1669 if (replyto && from)
1670 cc_list = address_list_append(cc_list, from);
1672 if (!compose->mailinglist)
1673 cc_list = address_list_append(cc_list, msginfo->to);
1675 cc_list = address_list_append(cc_list, compose->cc);
1677 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1679 g_hash_table_insert(to_table, replyto, GINT_TO_POINTER(1));
1680 if (compose->account)
1681 g_hash_table_insert(to_table, compose->account->address,
1682 GINT_TO_POINTER(1));
1684 /* remove address on To: and that of current account */
1685 for (cur = cc_list; cur != NULL; ) {
1686 GSList *next = cur->next;
1688 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1689 cc_list = g_slist_remove(cc_list, cur->data);
1691 g_hash_table_insert(to_table, cur->data, cur);
1695 g_hash_table_destroy(to_table);
1698 for (cur = cc_list; cur != NULL; cur = cur->next)
1699 compose_entry_append(compose, (gchar *)cur->data,
1701 slist_free_strings(cc_list);
1702 g_slist_free(cc_list);
1706 #define SET_ENTRY(entry, str) \
1709 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1712 #define SET_ADDRESS(type, str) \
1715 compose_entry_append(compose, str, type); \
1718 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1720 g_return_if_fail(msginfo != NULL);
1722 SET_ENTRY(subject_entry, msginfo->subject);
1723 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1724 SET_ADDRESS(COMPOSE_CC, compose->cc);
1725 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1726 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1728 compose_show_first_last_header(compose, TRUE);
1730 #if 0 /* NEW COMPOSE GUI */
1732 GtkItemFactory *ifactory;
1733 GtkWidget *menuitem;
1735 ifactory = gtk_item_factory_from_widget(compose->menubar);
1736 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1737 gtk_check_menu_item_set_active
1738 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1740 if (compose->replyto) {
1741 GtkItemFactory *ifactory;
1742 GtkWidget *menuitem;
1744 ifactory = gtk_item_factory_from_widget(compose->menubar);
1745 menuitem = gtk_item_factory_get_item
1746 (ifactory, "/View/Reply to");
1747 gtk_check_menu_item_set_active
1748 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1756 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1763 size_t buf_len = 128;
1765 if (strlen(sigfile) < 2)
1768 sigprg = popen(sigfile+1, "r");
1771 buf = g_malloc(buf_len);
1774 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1775 "Unable to insert signature (malloc failed)\n", -1);
1781 while (!feof(sigprg)) {
1782 bzero(buf, buf_len);
1783 fread(buf, buf_len-1, 1, sigprg);
1784 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1792 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1793 "Can't exec file: ", -1);
1794 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1799 static void compose_insert_sig(Compose *compose)
1803 if (compose->account && compose->account->sig_path)
1804 sigfile = g_strdup(compose->account->sig_path);
1806 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1807 DEFAULT_SIGNATURE, NULL);
1809 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1814 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1815 if (prefs_common.sig_sep) {
1816 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1817 prefs_common.sig_sep, -1);
1818 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1822 if (sigfile[0] == '|')
1823 compose_exec_sig(compose, sigfile);
1825 compose_insert_file(compose, sigfile);
1829 static void compose_insert_file(Compose *compose, const gchar *file)
1831 GtkSText *text = GTK_STEXT(compose->text);
1832 gchar buf[BUFFSIZE];
1836 g_return_if_fail(file != NULL);
1838 if ((fp = fopen(file, "rb")) == NULL) {
1839 FILE_OP_ERROR(file, "fopen");
1843 gtk_stext_freeze(text);
1845 while (fgets(buf, sizeof(buf), fp) != NULL) {
1846 /* strip <CR> if DOS/Windows file,
1847 replace <CR> with <LF> if Macintosh file. */
1850 if (len > 0 && buf[len - 1] != '\n') {
1852 if (buf[len] == '\r') buf[len] = '\n';
1854 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1857 gtk_stext_thaw(text);
1862 static void compose_attach_append(Compose *compose, const gchar *file,
1863 const gchar *filename,
1864 const gchar *content_type)
1867 gchar *text[N_ATTACH_COLS];
1872 if (!is_file_exist(file)) {
1873 g_warning(_("File %s doesn't exist\n"), file);
1876 if ((size = get_file_size(file)) < 0) {
1877 g_warning(_("Can't get file size of %s\n"), file);
1881 alertpanel_notice(_("File %s is empty."), file);
1884 if ((fp = fopen(file, "rb")) == NULL) {
1885 alertpanel_error(_("Can't read %s."), file);
1890 #if 0 /* NEW COMPOSE GUI */
1891 if (!compose->use_attach) {
1892 GtkItemFactory *ifactory;
1893 GtkWidget *menuitem;
1895 ifactory = gtk_item_factory_from_widget(compose->menubar);
1896 menuitem = gtk_item_factory_get_item(ifactory,
1897 "/View/Attachment");
1898 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1902 ainfo = g_new0(AttachInfo, 1);
1903 ainfo->file = g_strdup(file);
1906 ainfo->content_type = g_strdup(content_type);
1907 if (!strcasecmp(content_type, "message/rfc822")) {
1908 ainfo->encoding = ENC_7BIT;
1909 ainfo->name = g_strdup_printf
1911 g_basename(filename ? filename : file));
1913 ainfo->encoding = ENC_BASE64;
1914 ainfo->name = g_strdup
1915 (g_basename(filename ? filename : file));
1918 ainfo->content_type = procmime_get_mime_type(file);
1919 if (!ainfo->content_type)
1920 ainfo->content_type =
1921 g_strdup("application/octet-stream");
1922 ainfo->encoding = ENC_BASE64;
1923 ainfo->name = g_strdup(g_basename(filename ? filename : file));
1927 text[COL_MIMETYPE] = ainfo->content_type;
1928 text[COL_SIZE] = to_human_readable(size);
1929 text[COL_NAME] = ainfo->name;
1931 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1932 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1935 #define IS_FIRST_PART_TEXT(info) \
1936 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
1937 info->mime_type == MIME_TEXT_ENRICHED) || \
1938 (info->mime_type == MIME_MULTIPART && info->content_type && \
1939 !strcasecmp(info->content_type, "multipart/alternative") && \
1940 (info->children && \
1941 (info->children->mime_type == MIME_TEXT || \
1942 info->children->mime_type == MIME_TEXT_HTML || \
1943 info->children->mime_type == MIME_TEXT_ENRICHED))))
1945 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
1952 mimeinfo = procmime_scan_message(msginfo);
1953 if (!mimeinfo) return;
1955 /* skip first text (presumably message body) */
1956 child = mimeinfo->children;
1957 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
1958 procmime_mimeinfo_free_all(mimeinfo);
1961 if (IS_FIRST_PART_TEXT(child))
1962 child = child->next;
1964 infile = procmsg_get_message_file_path(msginfo);
1966 while (child != NULL) {
1967 if (child->children || child->mime_type == MIME_MULTIPART) {
1968 child = procmime_mimeinfo_next(child);
1972 outfile = procmime_get_tmp_file_name(child);
1973 if (procmime_get_part(outfile, infile, child) < 0)
1974 g_warning(_("Can't get the part of multipart message."));
1976 compose_attach_append
1978 child->filename ? child->filename : child->name,
1979 child->content_type);
1981 child = child->next;
1985 procmime_mimeinfo_free_all(mimeinfo);
1988 #undef IS_FIRST_PART_TEXT
1990 #define GET_CHAR(pos, buf, len) \
1992 if (text->use_wchar) \
1993 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
1995 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2000 static void compose_wrap_line(Compose *compose)
2002 GtkSText *text = GTK_STEXT(compose->text);
2003 gint ch_len, last_ch_len;
2004 gchar cbuf[MB_LEN_MAX], last_ch;
2008 gint p_start, p_end;
2009 gint line_pos, cur_pos;
2010 gint line_len, cur_len;
2012 gtk_stext_freeze(text);
2014 text_len = gtk_stext_get_length(text);
2016 /* check to see if the point is on the paragraph mark (empty line). */
2017 cur_pos = gtk_stext_get_point(text);
2018 GET_CHAR(cur_pos, cbuf, ch_len);
2019 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2021 goto compose_end; /* on the paragraph mark */
2022 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2023 if (ch_len == 1 && *cbuf == '\n')
2024 goto compose_end; /* on the paragraph mark */
2027 /* find paragraph start. */
2028 line_end = quoted = 0;
2029 for (p_start = cur_pos; p_start >= 0; --p_start) {
2030 GET_CHAR(p_start, cbuf, ch_len);
2031 if (ch_len == 1 && *cbuf == '\n') {
2033 goto compose_end; /* quoted part */
2040 if (ch_len == 1 && strchr(">|:#", *cbuf))
2042 else if (ch_len != 1 || !isspace(*cbuf))
2051 /* find paragraph end. */
2053 for (p_end = cur_pos; p_end < text_len; p_end++) {
2054 GET_CHAR(p_end, cbuf, ch_len);
2055 if (ch_len == 1 && *cbuf == '\n') {
2062 if (line_end && ch_len == 1 && strchr(">|:#", *cbuf))
2063 goto compose_end; /* quoted part */
2068 if (p_end >= text_len)
2071 if (p_start >= p_end)
2074 line_len = cur_len = 0;
2078 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2081 GET_CHAR(cur_pos, cbuf, ch_len);
2088 if (ch_len == 1 && isspace(*cbuf))
2091 if (ch_len == 1 && *cbuf == '\n') {
2093 if (last_ch_len == 1 && !isspace(last_ch)) {
2094 if (cur_pos + 1 < p_end) {
2095 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2096 if (ch_len == 1 && !isspace(*cbuf))
2100 gtk_stext_set_point(text, cur_pos + 1);
2101 gtk_stext_backward_delete(text, 1);
2103 gtk_stext_set_point(text, cur_pos);
2104 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2114 last_ch_len = ch_len;
2118 line_pos = cur_pos + 1;
2119 line_len = cur_len + ch_len;
2122 if (cur_len + ch_len > prefs_common.linewrap_len &&
2126 GET_CHAR(line_pos - 1, cbuf, ch_len);
2127 if (ch_len == 1 && isspace(*cbuf)) {
2128 gtk_stext_set_point(text, line_pos);
2129 gtk_stext_backward_delete(text, 1);
2138 gtk_stext_set_point(text, line_pos);
2139 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2143 cur_len = cur_len - line_len + ch_len;
2149 line_pos = cur_pos + 1;
2150 line_len = cur_len + ch_len;
2156 gtk_stext_thaw(text);
2161 /* Darko: used when I debug wrapping */
2162 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2167 printf("%d [", pos);
2168 for (i = pos; i < tlen; i++) {
2169 ch = GTK_STEXT_INDEX(text, i);
2170 if (breakoncr && ch == '\n')
2180 WAIT_FOR_INDENTCHAR,
2181 WAIT_FOR_INDENTCHARORSPACETAB
2184 #define INDCHARS ">|:#"
2185 #define SPACECHARS " \t"
2187 /* return indent length, we allow:
2188 > followed by spaces/tabs
2189 | followed by spaces/tabs
2190 uppercase characters immediately followed by >,
2191 and the repeating sequences of the above */
2192 /* return indent length */
2193 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2196 guint i, ch_len, alnum_cnt = 0;
2197 IndentStates state = WAIT_FOR_INDENTCHAR;
2198 gchar cb[MB_LEN_MAX];
2202 for (i = start_pos; i < text_len; i++) {
2203 GET_CHAR(i, cb, ch_len);
2210 is_indent = strchr(INDCHARS, cb[0]) ? TRUE : FALSE;
2211 is_space = strchr(SPACECHARS, cb[0]) ? TRUE : FALSE;
2214 case WAIT_FOR_SPACETAB:
2215 if (is_space == FALSE)
2217 state = WAIT_FOR_INDENTCHARORSPACETAB;
2219 case WAIT_FOR_INDENTCHARORSPACETAB:
2220 if (is_indent == FALSE && is_space == FALSE &&
2223 if (is_space == TRUE) {
2225 state = WAIT_FOR_INDENTCHARORSPACETAB;
2226 } else if (is_indent == TRUE) {
2228 state = WAIT_FOR_SPACETAB;
2231 state = WAIT_FOR_INDENTCHAR;
2235 case WAIT_FOR_INDENTCHAR:
2236 if (is_indent == FALSE && !isupper(cb[0]))
2238 if (is_indent == TRUE) {
2240 state = WAIT_FOR_SPACETAB;
2251 if ((i_len > 0) && (state == WAIT_FOR_INDENTCHAR))
2257 /* insert quotation string when line was wrapped */
2258 static guint ins_quote(GtkSText *text, guint indent_len,
2259 guint prev_line_pos, guint text_len,
2266 for (i = 0; i < indent_len; i++) {
2267 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2268 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2270 ins_len = indent_len;
2276 /* check if we should join the next line */
2277 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2280 guint indent_len, ch_len;
2281 gboolean do_join = FALSE;
2282 gchar cbuf[MB_LEN_MAX];
2284 indent_len = get_indent_length(text, start_pos, tlen);
2286 if ((indent_len > 0) && (indent_len == prev_ilen)) {
2287 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2288 if (ch_len == 1 && (cbuf[0] != '\n'))
2295 static void compose_wrap_line_all(Compose *compose)
2297 GtkSText *text = GTK_STEXT(compose->text);
2299 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2300 gint line_len = 0, cur_len = 0;
2302 gboolean is_new_line = TRUE, do_delete = FALSE;
2304 gboolean linewrap_quote = TRUE;
2305 guint linewrap_len = prefs_common.linewrap_len;
2306 gchar *qfmt = prefs_common.quotemark;
2307 gchar cbuf[MB_LEN_MAX];
2309 gtk_stext_freeze(text);
2311 /* make text buffer contiguous */
2312 /* gtk_stext_compact_buffer(text); */
2314 tlen = gtk_stext_get_length(text);
2316 for (; cur_pos < tlen; cur_pos++) {
2317 /* mark position of new line - needed for quotation wrap */
2320 i_len = get_indent_length(text, cur_pos, tlen);
2322 is_new_line = FALSE;
2325 printf("new line i_len=%d p_pos=", i_len);
2326 dump_text(text, p_pos, tlen, 1);
2330 GET_CHAR(cur_pos, cbuf, ch_len);
2332 /* fix line length for tabs */
2333 if (ch_len == 1 && *cbuf == '\t') {
2334 guint tab_width = text->default_tab_width;
2335 guint tab_offset = line_len % tab_width;
2338 printf("found tab at pos=%d line_len=%d ", cur_pos,
2342 line_len += tab_width - tab_offset - 1;
2346 printf("new_len=%d\n", line_len);
2350 /* we have encountered line break */
2351 if (ch_len == 1 && *cbuf == '\n') {
2354 gchar cb[MB_CUR_MAX];
2356 /* should we join the next line */
2357 if ((i_len != cur_len) && do_delete &&
2358 join_next_line(text, cur_pos + 1, tlen, i_len))
2364 printf("found CR at %d do_del is %d next line is ",
2365 cur_pos, do_delete);
2366 dump_text(text, cur_pos + 1, tlen, 1);
2369 /* skip delete if it is continuous URL */
2370 if (do_delete && (line_pos - p_pos <= i_len) &&
2371 gtkut_stext_is_uri_string(text, line_pos, tlen))
2375 printf("l_len=%d wrap_len=%d do_del=%d\n",
2376 line_len, linewrap_len, do_delete);
2378 /* should we delete to perform smart wrapping */
2379 if (line_len < linewrap_len && do_delete) {
2380 /* get rid of newline */
2381 gtk_stext_set_point(text, cur_pos);
2382 gtk_stext_forward_delete(text, 1);
2385 /* if text starts with quote fmt or with
2386 indent string, delete them */
2388 ilen = gtkut_stext_str_compare_n
2389 (text, cur_pos, p_pos, i_len,
2392 gtk_stext_forward_delete
2398 GET_CHAR(cur_pos, cb, clen);
2400 /* insert space if it's alphanumeric */
2401 if ((cur_pos != line_pos) &&
2402 ((clen > 1) || isalnum(cb[0]))) {
2403 gtk_stext_insert(text, NULL, NULL,
2405 /* gtk_stext_compact_buffer(text); */
2409 /* and start over with current line */
2410 cur_pos = p_pos - 1;
2412 line_len = cur_len = 0;
2416 printf("after delete l_pos=");
2417 dump_text(text, line_pos, tlen, 1);
2422 /* mark new line beginning */
2423 line_pos = cur_pos + 1;
2424 line_len = cur_len = 0;
2435 /* possible line break */
2436 if (ch_len == 1 && isspace(*cbuf)) {
2437 line_pos = cur_pos + 1;
2438 line_len = cur_len + ch_len;
2441 /* are we over wrapping length set in preferences ? */
2442 if (cur_len + ch_len > linewrap_len) {
2446 printf("should wrap cur_pos=%d ", cur_pos);
2447 dump_text(text, p_pos, tlen, 1);
2448 dump_text(text, line_pos, tlen, 1);
2450 /* force wrapping if it is one long word but not URL */
2451 if (line_pos - p_pos <= i_len)
2452 if (!gtkut_stext_is_uri_string
2453 (text, line_pos, tlen))
2454 line_pos = cur_pos - 1;
2456 printf("new line_pos=%d\n", line_pos);
2459 GET_CHAR(line_pos - 1, cbuf, clen);
2461 /* if next character is space delete it */
2462 if (clen == 1 && isspace(*cbuf)) {
2463 if (p_pos + i_len != line_pos ||
2464 !gtkut_stext_is_uri_string
2465 (text, line_pos, tlen)) {
2466 gtk_stext_set_point(text, line_pos);
2467 gtk_stext_backward_delete(text, 1);
2476 /* if it is URL at beginning of line don't wrap */
2477 if (p_pos + i_len == line_pos &&
2478 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2480 printf("found URL at ");
2481 dump_text(text, line_pos, tlen, 1);
2487 gtk_stext_set_point(text, line_pos);
2488 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2489 /* gtk_stext_compact_buffer(text); */
2492 /* for loop will increase it */
2493 cur_pos = line_pos - 1;
2494 /* start over with current line */
2503 printf("after CR insert ");
2504 dump_text(text, line_pos, tlen, 1);
2505 dump_text(text, cur_pos, tlen, 1);
2508 /* should we insert quotation ? */
2509 if (linewrap_quote && i_len) {
2510 /* only if line is not already quoted */
2511 if (!gtkut_stext_str_compare
2512 (text, line_pos, tlen, qfmt)) {
2515 if (line_pos - p_pos > i_len) {
2517 (text, i_len, p_pos,
2520 /* gtk_stext_compact_buffer(text); */
2524 printf("after quote insert ");
2525 dump_text(text, line_pos, tlen, 1);
2533 line_pos = cur_pos + 1;
2534 line_len = cur_len + ch_len;
2536 /* advance to next character in buffer */
2540 gtk_stext_thaw(text);
2545 static void compose_set_title(Compose *compose)
2550 edited = compose->modified ? _(" [Edited]") : "";
2551 if (compose->account && compose->account->address)
2552 str = g_strdup_printf(_("%s - Compose message%s"),
2553 compose->account->address, edited);
2555 str = g_strdup_printf(_("Compose message%s"), edited);
2556 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2561 * compose_current_mail_account:
2563 * Find a current mail account (the currently selected account, or the
2564 * default account, if a news account is currently selected). If a
2565 * mail account cannot be found, display an error message.
2567 * Return value: Mail account, or NULL if not found.
2569 static PrefsAccount *
2570 compose_current_mail_account(void)
2574 if (cur_account && cur_account->protocol != A_NNTP)
2577 ac = account_get_default();
2578 if (!ac || ac->protocol == A_NNTP) {
2579 alertpanel_error(_("Account for sending mail is not specified.\n"
2580 "Please select a mail account before sending."));
2587 gboolean compose_check_for_valid_recipient(Compose *compose) {
2588 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2589 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2590 gboolean recipient_found = FALSE;
2594 /* free to and newsgroup list */
2595 slist_free_strings(compose->to_list);
2596 g_slist_free(compose->to_list);
2597 compose->to_list = NULL;
2599 slist_free_strings(compose->newsgroup_list);
2600 g_slist_free(compose->newsgroup_list);
2601 compose->newsgroup_list = NULL;
2603 /* search header entries for to and newsgroup entries */
2604 for(list = compose->header_list; list; list = list->next) {
2607 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2608 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2610 if(entry[0] != '\0') {
2611 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2612 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2613 compose->to_list = address_list_append(compose->to_list, entry);
2614 recipient_found = TRUE;
2617 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2618 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2619 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2620 recipient_found = TRUE;
2626 return recipient_found;
2629 static gboolean compose_check_entries(Compose *compose)
2633 if (compose_check_for_valid_recipient(compose) == FALSE) {
2634 alertpanel_error(_("Recipient is not specified."));
2638 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2642 aval = alertpanel(_("Send"),
2643 _("Subject is empty. Send it anyway?"),
2644 _("Yes"), _("No"), NULL);
2645 if (aval != G_ALERTDEFAULT)
2652 gint compose_send(Compose *compose)
2658 if (compose_check_entries(compose) == FALSE)
2661 val = compose_queue(compose, &msgnum, &folder);
2663 alertpanel_error(_("Could not queue message for sending"));
2667 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2669 folder_item_remove_msg(folder, msgnum);
2670 folderview_update_item(folder, TRUE);
2675 #if 0 /* compose restructure */
2676 gint compose_send(Compose *compose)
2678 gchar tmp[MAXPATHLEN + 1];
2680 static gboolean lock = FALSE;
2684 g_return_val_if_fail(compose->account != NULL, -1);
2685 g_return_val_if_fail(compose->orig_account != NULL, -1);
2689 if (compose_check_entries(compose) == FALSE) {
2694 /* write to temporary file */
2695 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2696 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2698 if (prefs_common.linewrap_at_send)
2699 compose_wrap_line_all(compose);
2701 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2706 if (!compose->to_list && !compose->newsgroup_list) {
2707 g_warning(_("can't get recipient list."));
2713 if (compose->to_list) {
2716 #if 0 /* NEW COMPOSE GUI */
2717 if (compose->account->protocol != A_NNTP)
2718 ac = compose->account;
2719 else if (compose->orig_account->protocol != A_NNTP)
2720 ac = compose->orig_account;
2721 else if (cur_account && cur_account->protocol != A_NNTP)
2724 ac = compose_current_mail_account();
2732 ac = compose->account;
2734 ok = send_message(tmp, ac, compose->to_list);
2735 statusbar_pop_all();
2738 if (ok == 0 && compose->newsgroup_list) {
2741 if (compose->account->protocol == A_NNTP)
2742 folder = FOLDER(compose->account->folder);
2744 folder = FOLDER(compose->orig_account->folder);
2746 ok = news_post(folder, tmp);
2748 alertpanel_error(_("Error occurred while posting the message to %s ."),
2749 compose->account->nntp_server);
2756 /* queue message if failed to send */
2758 if (prefs_common.queue_msg) {
2763 _("Error occurred while sending the message.\n"
2764 "Put this message into queue folder?"),
2765 _("OK"), _("Cancel"), NULL);
2766 if (G_ALERTDEFAULT == val) {
2767 ok = compose_queue(compose, tmp);
2769 alertpanel_error(_("Can't queue the message."));
2772 alertpanel_error(_("Error occurred while sending the message."));
2774 if (compose->mode == COMPOSE_REEDIT) {
2775 compose_remove_reedit_target(compose);
2776 if (compose->targetinfo)
2777 folderview_update_item
2778 (compose->targetinfo->folder, TRUE);
2780 /* save message to outbox */
2781 if (prefs_common.savemsg) {
2782 Folder *folder = FOLDER(compose->account->folder);
2783 FolderItem *outbox = NULL;
2786 outbox = folder->outbox;
2788 outbox = folder_get_default_outbox();
2789 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
2791 (_("Can't save the message to outbox."));
2793 folderview_update_item(outbox, TRUE);
2803 static gboolean compose_use_attach(Compose *compose) {
2804 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2807 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2810 gchar buf[BUFFSIZE];
2812 gboolean first_address;
2814 ComposeHeaderEntry *headerentry;
2815 gchar *headerentryname;
2816 gchar *header_w_colon;
2820 debug_print(_("Writing bounce header\n"));
2822 header_w_colon = g_strconcat("To:", NULL);
2823 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2824 header_w_colon = g_strconcat("Cc:", NULL);
2825 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2827 first_address = TRUE;
2828 for(list = compose->header_list; list; list = list->next) {
2829 headerentry = ((ComposeHeaderEntry *)list->data);
2830 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2832 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2833 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2834 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2835 Xstrdup_a(str, str, return -1);
2837 if(str[0] != '\0') {
2838 compose_convert_header
2839 (buf, sizeof(buf), str,
2840 strlen("Resent-To") + 2);
2842 fprintf(fp, "Resent-To: ");
2843 first_address = FALSE;
2847 fprintf(fp, "%s", buf);
2851 /* if(!first_address) { */
2858 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2860 gchar buf[BUFFSIZE];
2862 /* struct utsname utsbuf; */
2864 g_return_val_if_fail(fp != NULL, -1);
2865 g_return_val_if_fail(compose->account != NULL, -1);
2866 g_return_val_if_fail(compose->account->address != NULL, -1);
2869 get_rfc822_date(buf, sizeof(buf));
2870 fprintf(fp, "Resent-Date: %s\n", buf);
2873 if (compose->account->name && *compose->account->name) {
2874 compose_convert_header
2875 (buf, sizeof(buf), compose->account->name,
2877 fprintf(fp, "Resent-From: %s <%s>\n",
2878 buf, compose->account->address);
2880 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2883 compose_bounce_write_headers_from_headerlist(compose, fp);
2885 /* separator between header and body */
2891 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2896 gchar buf[BUFFSIZE];
2898 if ((fp = fopen(compose->bounce_filename, "rb")) == NULL) {
2899 FILE_OP_ERROR(file, "fopen");
2903 if ((fdest = fopen(file, "wb")) == NULL) {
2904 FILE_OP_ERROR(file, "fopen");
2909 /* chmod for security */
2910 if (change_file_mode_rw(fdest, file) < 0) {
2911 FILE_OP_ERROR(file, "chmod");
2912 g_warning(_("can't change file mode\n"));
2915 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2916 /* should filter returnpath, delivered-to */
2917 if ((g_strncasecmp(buf, "Return-Path:",
2918 strlen("Return-Path:")) == 0)
2919 || (g_strncasecmp(buf, "Delivered-To:",
2920 strlen("Delivered-To:")) == 0))
2923 if (fputs(buf, fdest) == -1)
2926 if (!prefs_common.bounce_keep_from) {
2927 if (g_strncasecmp(buf, "From:",
2928 strlen("From:")) == 0) {
2929 fputs(" (by way of ", fdest);
2930 if (compose->account->name
2931 && *compose->account->name) {
2932 compose_convert_header
2934 compose->account->name,
2936 fprintf(fdest, "%s <%s>",
2938 compose->account->address);
2940 fprintf(fdest, "%s",
2941 compose->account->address);
2946 if (fputs("\n", fdest) == -1)
2950 compose_bounce_write_headers(compose, fdest);
2952 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
2953 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
2971 * interfaces to rfc2015 to keep out the prefs stuff there.
2972 * returns 0 on success and -1 on error. */
2973 static int compose_create_signers_list (Compose *compose, GSList **pkey_list)
2975 const char *keyid = NULL;
2978 switch (compose->account->sign_key) {
2979 case SIGN_KEY_DEFAULT:
2981 return 0; /* nothing to do */
2983 case SIGN_KEY_BY_FROM:
2984 keyid = compose->account->address;
2987 case SIGN_KEY_CUSTOM:
2988 keyid = compose->account->sign_key_id;
2992 g_assert_not_reached ();
2995 key_list = rfc2015_create_signers_list(keyid);
2998 alertpanel_error("Could not find any key associated with currently "
2999 "selected keyid `%s'!", keyid);
3003 *pkey_list = key_list;
3006 #endif /* USE_GPGME */
3008 static gint compose_write_to_file(Compose *compose, const gchar *file,
3015 const gchar *out_codeset;
3016 EncodingType encoding;
3018 if ((fp = fopen(file, "wb")) == NULL) {
3019 FILE_OP_ERROR(file, "fopen");
3023 /* chmod for security */
3024 if (change_file_mode_rw(fp, file) < 0) {
3025 FILE_OP_ERROR(file, "chmod");
3026 g_warning(_("can't change file mode\n"));
3029 /* get all composed text */
3030 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3031 len = strlen(chars);
3032 if (is_ascii_str(chars)) {
3033 buf = g_strdup(chars);
3034 out_codeset = CS_US_ASCII;
3035 encoding = ENC_7BIT;
3037 const gchar *src_codeset;
3039 out_codeset = conv_get_outgoing_charset_str();
3040 if (!strcasecmp(out_codeset, CS_US_ASCII))
3041 out_codeset = CS_ISO_8859_1;
3042 encoding = procmime_get_encoding_for_charset(out_codeset);
3044 src_codeset = conv_get_current_charset_str();
3045 /* if current encoding is US-ASCII, set it the same as
3046 outgoing one to prevent code conversion failure */
3047 if (!strcasecmp(src_codeset, CS_US_ASCII))
3048 src_codeset = out_codeset;
3050 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3051 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3053 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3059 _("Can't convert the character encoding of the message.\n"
3060 "Send it anyway?"), _("Yes"), _("+No"), NULL);
3061 if (aval != G_ALERTDEFAULT) {
3067 buf = g_strdup(chars);
3074 if (compose_write_headers
3075 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3076 g_warning(_("can't write headers\n"));
3083 if (compose_use_attach(compose)) {
3085 /* This prolog message is ignored by mime software and
3086 * because it would make our signing/encryption task
3087 * tougher, we don't emit it in that case */
3088 if (!compose->use_signing && !compose->use_encryption)
3090 fputs("This is a multi-part message in MIME format.\n", fp);
3092 fprintf(fp, "\n--%s\n", compose->boundary);
3093 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3095 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3096 procmime_get_encoding_str(encoding));
3102 if (encoding == ENC_BASE64) {
3103 gchar outbuf[B64_BUFFSIZE];
3106 for (i = 0; i < len; i += B64_LINE_SIZE) {
3107 l = MIN(B64_LINE_SIZE, len - i);
3108 to64frombits(outbuf, buf + i, l);
3112 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3113 FILE_OP_ERROR(file, "fwrite");
3121 if (compose_use_attach(compose))
3122 compose_write_attach(compose, fp);
3124 if (fclose(fp) == EOF) {
3125 FILE_OP_ERROR(file, "fclose");
3131 if (compose->use_signing) {
3134 if (compose_create_signers_list(compose, &key_list) == -1 ||
3135 rfc2015_sign(file, key_list) < 0) {
3141 if (compose->use_encryption) {
3142 if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) {
3147 #endif /* USE_GPGME */
3152 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3158 if ((fp = fopen(file, "wb")) == NULL) {
3159 FILE_OP_ERROR(file, "fopen");
3163 /* chmod for security */
3164 if (change_file_mode_rw(fp, file) < 0) {
3165 FILE_OP_ERROR(file, "chmod");
3166 g_warning(_("can't change file mode\n"));
3169 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3172 len = strlen(chars);
3173 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3174 FILE_OP_ERROR(file, "fwrite");
3183 if (fclose(fp) == EOF) {
3184 FILE_OP_ERROR(file, "fclose");
3191 static gint compose_remove_reedit_target(Compose *compose)
3194 MsgInfo *msginfo = compose->targetinfo;
3196 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3197 if (!msginfo) return -1;
3199 item = msginfo->folder;
3200 g_return_val_if_fail(item != NULL, -1);
3202 folder_item_scan(item);
3203 if (procmsg_msg_exist(msginfo) &&
3204 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3205 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3206 g_warning(_("can't remove the old message\n"));
3215 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3218 gchar *tmp, *tmp2, *queue_path;
3221 gchar buf[BUFFSIZE];
3223 MsgFlags flag = {0, 0};
3224 static gboolean lock = FALSE;
3225 PrefsAccount *mailac = NULL, *newsac = NULL;
3227 debug_print(_("queueing message...\n"));
3228 g_return_val_if_fail(compose->account != NULL, -1);
3229 g_return_val_if_fail(compose->orig_account != NULL, -1);
3233 if (compose_check_entries(compose) == FALSE) {
3238 if (!compose->to_list && !compose->newsgroup_list) {
3239 g_warning(_("can't get recipient list."));
3244 if(compose->to_list) {
3245 if (compose->account->protocol != A_NNTP)
3246 mailac = compose->account;
3247 else if (compose->orig_account->protocol != A_NNTP)
3248 mailac = compose->orig_account;
3249 else if (cur_account && cur_account->protocol != A_NNTP)
3250 mailac = cur_account;
3251 else if (!(mailac = compose_current_mail_account())) {
3253 alertpanel_error(_("No account for sending mails available!"));
3258 if(compose->newsgroup_list) {
3259 if (compose->account->protocol == A_NNTP)
3260 newsac = compose->account;
3261 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3263 alertpanel_error(_("No account for posting news available!"));
3268 if (prefs_common.linewrap_at_send)
3269 compose_wrap_line_all(compose);
3271 /* write to temporary file */
3272 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3273 G_DIR_SEPARATOR, (gint)compose);
3275 if (compose->bounce_filename != NULL) {
3276 if (compose_bounce_write_to_file(compose, tmp2) < 0) {
3283 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3290 /* add queue header */
3291 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3292 G_DIR_SEPARATOR, (gint)compose);
3293 if ((fp = fopen(tmp, "wb")) == NULL) {
3294 FILE_OP_ERROR(tmp, "fopen");
3298 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3299 FILE_OP_ERROR(tmp2, "fopen");
3307 if (change_file_mode_rw(fp, tmp) < 0) {
3308 FILE_OP_ERROR(tmp, "chmod");
3309 g_warning(_("can't change file mode\n"));
3312 /* queueing variables */
3313 fprintf(fp, "AF:\n");
3314 fprintf(fp, "NF:0\n");
3315 fprintf(fp, "PS:10\n");
3316 fprintf(fp, "SRH:1\n");
3317 fprintf(fp, "SFN:\n");
3318 fprintf(fp, "DSR:\n");
3320 fprintf(fp, "MID:<%s>\n", compose->msgid);
3322 fprintf(fp, "MID:\n");
3323 fprintf(fp, "CFG:\n");
3324 fprintf(fp, "PT:0\n");
3325 fprintf(fp, "S:%s\n", compose->account->address);
3326 fprintf(fp, "RQ:\n");
3328 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3330 fprintf(fp, "SSV:\n");
3332 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3334 fprintf(fp, "NSV:\n");
3335 fprintf(fp, "SSH:\n");
3336 /* write recepient list */
3338 if(compose->to_list) {
3339 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3340 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3341 fprintf(fp, ",<%s>", (gchar *)cur->data);
3344 /* write newsgroup list */
3346 if(compose->newsgroup_list) {
3347 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3348 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3349 fprintf(fp, ",%s", (gchar *)cur->data);
3352 /* Sylpheed account IDs */
3354 fprintf(fp, "MAID:%d\n", mailac->account_id);
3357 fprintf(fp, "NAID:%d\n", newsac->account_id);
3359 /* Save copy folder */
3360 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3363 str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3364 fprintf(fp, "SCF:%s\n", str);
3369 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3370 if (fputs(buf, fp) == EOF) {
3371 FILE_OP_ERROR(tmp, "fputs");
3382 if (fclose(fp) == EOF) {
3383 FILE_OP_ERROR(tmp, "fclose");
3391 if (compose->account->folder &&
3392 FOLDER(compose->account->folder)->queue)
3393 queue = FOLDER(compose->account->folder)->queue;
3395 queue = folder_get_default_queue();
3397 folder_item_scan(queue);
3398 queue_path = folder_item_get_path(queue);
3399 if (!is_dir_exist(queue_path))
3400 make_dir_hier(queue_path);
3401 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3402 g_warning(_("can't queue the message\n"));
3413 if (compose->mode == COMPOSE_REEDIT) {
3414 compose_remove_reedit_target(compose);
3415 if (compose->targetinfo &&
3416 compose->targetinfo->folder != queue)
3417 folderview_update_item
3418 (compose->targetinfo->folder, TRUE);
3421 procmsg_add_flags(queue, num, flag);
3422 folder_item_scan(queue);
3423 folderview_update_item(queue, TRUE);
3425 if((msgnum != NULL) && (item != NULL)) {
3433 static void compose_write_attach(Compose *compose, FILE *fp)
3436 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3439 gchar filename[BUFFSIZE];
3442 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3444 gchar buf[BUFFSIZE];
3445 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3447 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
3448 g_warning(_("Can't open file %s\n"), ainfo->file);
3452 fprintf(fp, "\n--%s\n", compose->boundary);
3454 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3455 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3456 fprintf(fp, "Content-Disposition: inline\n");
3458 conv_encode_header(filename, sizeof(filename),
3460 fprintf(fp, "Content-Type: %s;\n"
3462 ainfo->content_type, filename);
3463 fprintf(fp, "Content-Disposition: attachment;\n"
3464 " filename=\"%s\"\n", filename);
3467 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3468 procmime_get_encoding_str(ainfo->encoding));
3470 switch (ainfo->encoding) {
3474 /* if (ainfo->encoding == ENC_7BIT) { */
3476 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3484 while ((len = fread(inbuf, sizeof(gchar),
3485 B64_LINE_SIZE, attach_fp))
3487 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3491 if (len > 0 && feof(attach_fp)) {
3492 to64frombits(outbuf, inbuf, len);
3502 fprintf(fp, "\n--%s--\n", compose->boundary);
3505 #define IS_IN_CUSTOM_HEADER(header) \
3506 (compose->account->add_customhdr && \
3507 custom_header_find(compose->account->customhdr_list, header) != NULL)
3509 static gint compose_write_headers_from_headerlist(Compose *compose,
3513 gchar buf[BUFFSIZE];
3514 gchar *str, *header_w_colon, *trans_hdr;
3515 gboolean first_address;
3517 ComposeHeaderEntry *headerentry;
3518 gchar * headerentryname;
3520 if (IS_IN_CUSTOM_HEADER(header)) {
3524 debug_print(_("Writing %s-header\n"), header);
3526 header_w_colon = g_strconcat(header, ":", NULL);
3527 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3529 first_address = TRUE;
3530 for(list = compose->header_list; list; list = list->next) {
3531 headerentry = ((ComposeHeaderEntry *)list->data);
3532 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3534 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3535 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3536 Xstrdup_a(str, str, return -1);
3538 if(str[0] != '\0') {
3539 compose_convert_header
3540 (buf, sizeof(buf), str,
3541 strlen(header) + 2);
3543 fprintf(fp, "%s: ", header);
3544 first_address = FALSE;
3548 fprintf(fp, "%s", buf);
3552 if(!first_address) {
3556 g_free(header_w_colon);
3561 static gint compose_write_headers(Compose *compose, FILE *fp,
3562 const gchar *charset, EncodingType encoding,
3565 gchar buf[BUFFSIZE];
3567 /* struct utsname utsbuf; */
3569 g_return_val_if_fail(fp != NULL, -1);
3570 g_return_val_if_fail(charset != NULL, -1);
3571 g_return_val_if_fail(compose->account != NULL, -1);
3572 g_return_val_if_fail(compose->account->address != NULL, -1);
3575 if (compose->account->add_date) {
3576 get_rfc822_date(buf, sizeof(buf));
3577 fprintf(fp, "Date: %s\n", buf);
3581 if (!IS_IN_CUSTOM_HEADER("From")) {
3582 if (compose->account->name && *compose->account->name) {
3583 compose_convert_header
3584 (buf, sizeof(buf), compose->account->name,
3586 fprintf(fp, "From: %s <%s>\n",
3587 buf, compose->account->address);
3589 fprintf(fp, "From: %s\n", compose->account->address);
3593 compose_write_headers_from_headerlist(compose, fp, "To");
3594 #if 0 /* NEW COMPOSE GUI */
3595 if (compose->use_to) {
3596 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3598 Xstrdup_a(str, str, return -1);
3601 compose->to_list = address_list_append
3602 (compose->to_list, str);
3603 if (!IS_IN_CUSTOM_HEADER("To")) {
3604 compose_convert_header
3605 (buf, sizeof(buf), str,
3607 fprintf(fp, "To: %s\n", buf);
3615 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3616 #if 0 /* NEW COMPOSE GUI */
3617 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3619 Xstrdup_a(str, str, return -1);
3623 compose->newsgroup_list =
3624 newsgroup_list_append(compose->newsgroup_list,
3626 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3627 compose_convert_header(buf, sizeof(buf), str,
3628 strlen("Newsgroups: "));
3629 fprintf(fp, "Newsgroups: %s\n", buf);
3635 compose_write_headers_from_headerlist(compose, fp, "Cc");
3636 #if 0 /* NEW COMPOSE GUI */
3637 if (compose->use_cc) {
3638 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3640 Xstrdup_a(str, str, return -1);
3643 compose->to_list = address_list_append
3644 (compose->to_list, str);
3645 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3646 compose_convert_header
3647 (buf, sizeof(buf), str,
3649 fprintf(fp, "Cc: %s\n", buf);
3656 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3657 #if 0 /* NEW COMPOSE GUI */
3658 if (compose->use_bcc) {
3659 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3661 Xstrdup_a(str, str, return -1);
3664 compose->to_list = address_list_append
3665 (compose->to_list, str);
3666 compose_convert_header(buf, sizeof(buf), str,
3668 fprintf(fp, "Bcc: %s\n", buf);
3675 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3676 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3677 Xstrdup_a(str, str, return -1);
3680 compose_convert_header(buf, sizeof(buf), str,
3681 strlen("Subject: "));
3682 fprintf(fp, "Subject: %s\n", buf);
3687 if (compose->account->gen_msgid) {
3688 compose_generate_msgid(compose, buf, sizeof(buf));
3689 fprintf(fp, "Message-Id: <%s>\n", buf);
3690 compose->msgid = g_strdup(buf);
3694 if (compose->inreplyto && compose->to_list)
3695 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3698 if (compose->references)
3699 fprintf(fp, "References: %s\n", compose->references);
3702 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3703 #if 0 /* NEW COMPOSE GUI */
3704 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3705 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3707 Xstrdup_a(str, str, return -1);
3711 compose_convert_header(buf, sizeof(buf), str,
3712 strlen("Followup-To: "));
3713 fprintf(fp, "Followup-To: %s\n", buf);
3719 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3720 #if 0 /* NEW COMPOSE GUI */
3721 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3722 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3724 Xstrdup_a(str, str, return -1);
3727 compose_convert_header(buf, sizeof(buf), str,
3728 strlen("Reply-To: "));
3729 fprintf(fp, "Reply-To: %s\n", buf);
3735 if (compose->account->organization &&
3736 !IS_IN_CUSTOM_HEADER("Organization")) {
3737 compose_convert_header(buf, sizeof(buf),
3738 compose->account->organization,
3739 strlen("Organization: "));
3740 fprintf(fp, "Organization: %s\n", buf);
3743 /* Program version and system info */
3744 /* uname(&utsbuf); */
3745 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3746 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3748 gtk_major_version, gtk_minor_version, gtk_micro_version,
3750 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3752 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3753 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3755 gtk_major_version, gtk_minor_version, gtk_micro_version,
3757 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3760 /* custom headers */
3761 if (compose->account->add_customhdr) {
3764 for (cur = compose->account->customhdr_list; cur != NULL;
3766 CustomHeader *chdr = (CustomHeader *)cur->data;
3768 if (strcasecmp(chdr->name, "Date") != 0 &&
3769 strcasecmp(chdr->name, "From") != 0 &&
3770 strcasecmp(chdr->name, "To") != 0 &&
3771 /* strcasecmp(chdr->name, "Sender") != 0 && */
3772 strcasecmp(chdr->name, "Message-Id") != 0 &&
3773 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3774 strcasecmp(chdr->name, "References") != 0 &&
3775 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3776 strcasecmp(chdr->name, "Content-Type") != 0 &&
3777 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3779 compose_convert_header
3781 chdr->value ? chdr->value : "",
3782 strlen(chdr->name) + 2);
3783 fprintf(fp, "%s: %s\n", chdr->name, buf);
3789 fprintf(fp, "Mime-Version: 1.0\n");
3790 if (compose_use_attach(compose)) {
3791 get_rfc822_date(buf, sizeof(buf));
3792 subst_char(buf, ' ', '_');
3793 subst_char(buf, ',', '_');
3794 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3795 buf, (guint)compose);
3797 "Content-Type: multipart/mixed;\n"
3798 " boundary=\"%s\"\n", compose->boundary);
3800 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3801 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3802 procmime_get_encoding_str(encoding));
3805 /* Request Return Receipt */
3806 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3807 if (compose->return_receipt) {
3808 if (compose->account->name
3809 && *compose->account->name) {
3810 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3811 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3813 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3817 /* separator between header and body */
3823 #undef IS_IN_CUSTOM_HEADER
3825 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3828 g_return_if_fail(src != NULL);
3829 g_return_if_fail(dest != NULL);
3831 if (len < 1) return;
3835 if (is_ascii_str(src)) {
3836 strncpy2(dest, src, len);
3837 dest[len - 1] = '\0';
3840 conv_encode_header(dest, len, src, header_len);
3843 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3852 if (compose->account && compose->account->address &&
3853 *compose->account->address) {
3854 if (strchr(compose->account->address, '@'))
3855 addr = g_strdup(compose->account->address);
3857 addr = g_strconcat(compose->account->address, "@",
3858 get_domain_name(), NULL);
3860 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3863 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3864 lt->tm_year + 1900, lt->tm_mon + 1,
3865 lt->tm_mday, lt->tm_hour,
3866 lt->tm_min, lt->tm_sec,
3867 (guint)random(), addr);
3869 debug_print(_("generated Message-ID: %s\n"), buf);
3874 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3875 GtkWidget **entry, gint *count,
3876 const gchar *label_str,
3877 gboolean is_addr_entry)
3881 if (GTK_TABLE(table)->nrows < (*count) + 1)
3882 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3884 *hbox = gtk_hbox_new(FALSE, 0);
3885 label = gtk_label_new
3886 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3887 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3888 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3890 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3892 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3893 #if 0 /* NEW COMPOSE GUI */
3894 if (GTK_TABLE(table)->nrows > (*count) + 1)
3895 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3899 address_completion_register_entry(GTK_ENTRY(*entry));
3904 static void compose_create_header_entry(Compose *compose)
3906 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3910 GList *combo_list = NULL;
3911 gchar **string, *header;
3912 ComposeHeaderEntry *headerentry;
3914 headerentry = g_new0(ComposeHeaderEntry, 1);
3917 combo = gtk_combo_new();
3919 while(*string != NULL) {
3920 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3923 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3924 g_list_free(combo_list);
3925 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3926 gtk_widget_show(combo);
3927 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3928 if(compose->header_last) {
3929 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3931 switch(compose->account->protocol) {
3933 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
3936 header = prefs_common.trans_hdr ? _("To:") : "To:";
3940 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
3943 entry = gtk_entry_new();
3944 gtk_widget_show(entry);
3945 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);
3947 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
3948 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
3949 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
3951 address_completion_register_entry(GTK_ENTRY(entry));
3953 headerentry->compose = compose;
3954 headerentry->combo = combo;
3955 headerentry->entry = entry;
3956 headerentry->headernum = compose->header_nextrow;
3958 compose->header_nextrow++;
3959 compose->header_last = headerentry;
3962 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
3964 ComposeHeaderEntry *last_header;
3966 last_header = compose->header_last;
3968 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
3969 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
3972 static GtkWidget *compose_create_header(Compose *compose)
3976 GtkWidget *from_optmenu_hbox;
3977 #if 0 /* NEW COMPOSE GUI */
3978 GtkWidget *to_entry;
3980 GtkWidget *newsgroups_entry;
3981 GtkWidget *newsgroups_hbox;
3983 GtkWidget *header_scrolledwin;
3984 GtkWidget *header_table;
3985 #if 0 /* NEW COMPOSE GUI */
3986 GtkWidget *cc_entry;
3988 GtkWidget *bcc_entry;
3989 GtkWidget *bcc_hbox;
3990 GtkWidget *reply_entry;
3991 GtkWidget *reply_hbox;
3992 GtkWidget *followup_entry;
3993 GtkWidget *followup_hbox;
3998 /* header labels and entries */
3999 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4000 gtk_widget_show(header_scrolledwin);
4001 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4003 header_table = gtk_table_new(2, 2, FALSE);
4004 gtk_widget_show(header_table);
4005 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4006 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4007 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4010 /* option menu for selecting accounts */
4011 hbox = gtk_hbox_new(FALSE, 0);
4012 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4013 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4014 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4016 from_optmenu_hbox = compose_account_option_menu_create(compose);
4017 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4018 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4019 #if 0 /* NEW COMPOSE GUI */
4020 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4024 compose->header_table = header_table;
4025 compose->header_list = NULL;
4026 compose->header_nextrow = count;
4028 compose_create_header_entry(compose);
4030 #if 0 /* NEW COMPOSE GUI */
4031 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4033 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4034 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4035 &count, "Newsgroups:", FALSE);
4036 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4038 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4040 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4042 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4043 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4045 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4046 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4048 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4049 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4050 "Followup-To:", FALSE);
4051 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4053 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4055 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4056 GTK_SIGNAL_FUNC(to_activated), compose);
4057 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4058 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4059 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4060 GTK_SIGNAL_FUNC(subject_activated), compose);
4061 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4062 GTK_SIGNAL_FUNC(cc_activated), compose);
4063 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4064 GTK_SIGNAL_FUNC(bcc_activated), compose);
4065 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4066 GTK_SIGNAL_FUNC(replyto_activated), compose);
4067 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4068 GTK_SIGNAL_FUNC(followupto_activated), compose);
4070 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4071 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4072 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4073 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4074 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4075 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4076 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4077 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4078 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4079 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4080 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4081 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4082 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4083 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4086 compose->table = NULL;
4087 #if 0 /* NEW COMPOSE GUI */
4088 compose->table = table;
4089 compose->to_hbox = to_hbox;
4090 compose->to_entry = to_entry;
4091 compose->newsgroups_hbox = newsgroups_hbox;
4092 compose->newsgroups_entry = newsgroups_entry;
4094 #if 0 /* NEW COMPOSE GUI */
4095 compose->cc_hbox = cc_hbox;
4096 compose->cc_entry = cc_entry;
4097 compose->bcc_hbox = bcc_hbox;
4098 compose->bcc_entry = bcc_entry;
4099 compose->reply_hbox = reply_hbox;
4100 compose->reply_entry = reply_entry;
4101 compose->followup_hbox = followup_hbox;
4102 compose->followup_entry = followup_entry;
4105 return header_scrolledwin ;
4108 GtkWidget *compose_create_attach(Compose *compose)
4110 gchar *titles[N_ATTACH_COLS];
4113 GtkWidget *attach_scrwin;
4114 GtkWidget *attach_clist;
4116 titles[COL_MIMETYPE] = _("MIME type");
4117 titles[COL_SIZE] = _("Size");
4118 titles[COL_NAME] = _("Name");
4120 /* attachment list */
4121 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4122 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4123 GTK_POLICY_AUTOMATIC,
4125 gtk_widget_set_usize(attach_scrwin, -1, 80);
4127 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4128 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4130 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4131 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4132 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4133 GTK_SELECTION_EXTENDED);
4134 for (i = 0; i < N_ATTACH_COLS; i++)
4135 GTK_WIDGET_UNSET_FLAGS
4136 (GTK_CLIST(attach_clist)->column[i].button,
4138 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4140 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4141 GTK_SIGNAL_FUNC(attach_selected), compose);
4142 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4143 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4144 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4145 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4148 gtk_drag_dest_set(attach_clist,
4149 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4151 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4152 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4155 compose->attach_scrwin = attach_scrwin;
4156 compose->attach_clist = attach_clist;
4158 return attach_scrwin;
4161 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4162 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4164 static GtkWidget *compose_create_others(Compose *compose)
4167 GtkWidget *savemsg_checkbtn;
4168 GtkWidget *savemsg_entry;
4169 GtkWidget *savemsg_select;
4172 gchar *folderidentifier;
4174 /* Table for settings */
4175 table = gtk_table_new(3, 1, FALSE);
4176 gtk_widget_show(table);
4177 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4180 /* Save Message to folder */
4181 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4182 gtk_widget_show(savemsg_checkbtn);
4183 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4184 if(folder_get_default_outbox()) {
4185 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4187 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4188 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4190 savemsg_entry = gtk_entry_new();
4191 gtk_widget_show(savemsg_entry);
4192 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4193 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4194 if(folder_get_default_outbox()) {
4195 folderidentifier = folder_item_get_identifier(folder_get_default_outbox());
4196 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4197 g_free(folderidentifier);
4200 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4201 gtk_widget_show (savemsg_select);
4202 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4203 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4204 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4209 compose->savemsg_checkbtn = savemsg_checkbtn;
4210 compose->savemsg_entry = savemsg_entry;
4215 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4217 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4218 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4221 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4226 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4229 path = folder_item_get_identifier(dest);
4231 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4235 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4241 GtkWidget *handlebox;
4243 GtkWidget *notebook;
4248 GtkWidget *subject_hbox;
4249 GtkWidget *subject_frame;
4250 GtkWidget *subject_entry;
4254 GtkWidget *edit_vbox;
4255 GtkWidget *ruler_hbox;
4257 GtkWidget *scrolledwin;
4262 UndoMain *undostruct;
4264 gchar *titles[N_ATTACH_COLS];
4265 guint n_menu_entries;
4266 GtkStyle *style, *new_style;
4269 gboolean success[1];
4271 GtkWidget *popupmenu;
4272 GtkWidget *menuitem;
4273 GtkItemFactory *popupfactory;
4274 GtkItemFactory *ifactory;
4275 GtkWidget *tmpl_menu;
4279 GtkPspell * gtkpspell = NULL;
4282 g_return_val_if_fail(account != NULL, NULL);
4284 debug_print(_("Creating compose window...\n"));
4285 compose = g_new0(Compose, 1);
4287 titles[COL_MIMETYPE] = _("MIME type");
4288 titles[COL_SIZE] = _("Size");
4289 titles[COL_NAME] = _("Name");
4291 compose->account = account;
4292 compose->orig_account = account;
4294 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4295 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4296 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4297 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4298 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4299 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4300 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4301 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4302 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4303 gtk_widget_realize(window);
4305 gtkut_widget_set_composer_icon(window);
4307 vbox = gtk_vbox_new(FALSE, 0);
4308 gtk_container_add(GTK_CONTAINER(window), vbox);
4310 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4311 menubar = menubar_create(window, compose_entries,
4312 n_menu_entries, "<Compose>", compose);
4313 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4315 handlebox = gtk_handle_box_new();
4316 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4318 compose_toolbar_create(compose, handlebox);
4320 vbox2 = gtk_vbox_new(FALSE, 2);
4321 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4322 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4325 notebook = gtk_notebook_new();
4326 gtk_widget_set_usize(notebook, -1, 130);
4327 gtk_widget_show(notebook);
4329 /* header labels and entries */
4330 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4331 /* attachment list */
4332 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4334 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4337 subject_hbox = gtk_hbox_new(FALSE, 0);
4338 gtk_widget_show(subject_hbox);
4340 subject_frame = gtk_frame_new(NULL);
4341 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4342 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4343 gtk_widget_show(subject_frame);
4345 subject = gtk_hbox_new(FALSE, 0);
4346 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4347 gtk_widget_show(subject);
4349 label = gtk_label_new(_("Subject:"));
4350 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4351 gtk_widget_show(label);
4353 subject_entry = gtk_entry_new();
4354 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4355 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4356 gtk_widget_show(subject_entry);
4357 compose->subject_entry = subject_entry;
4358 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4360 edit_vbox = gtk_vbox_new(FALSE, 0);
4361 #if 0 /* NEW COMPOSE GUI */
4362 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4365 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4368 ruler_hbox = gtk_hbox_new(FALSE, 0);
4369 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4371 ruler = gtk_shruler_new();
4372 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4373 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4375 gtk_widget_set_usize(ruler_hbox, 1, -1);
4378 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4379 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4380 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4381 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4382 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4384 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4385 (GTK_SCROLLED_WINDOW(scrolledwin)),
4386 gtk_scrolled_window_get_vadjustment
4387 (GTK_SCROLLED_WINDOW(scrolledwin)));
4388 GTK_STEXT(text)->default_tab_width = 8;
4389 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4391 if (prefs_common.block_cursor) {
4392 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4395 if (prefs_common.smart_wrapping) {
4396 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4397 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4400 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4402 gtk_signal_connect(GTK_OBJECT(text), "changed",
4403 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4404 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4405 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4406 gtk_signal_connect(GTK_OBJECT(text), "activate",
4407 GTK_SIGNAL_FUNC(text_activated), compose);
4408 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4409 GTK_SIGNAL_FUNC(compose_button_press_cb),
4412 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4413 GTK_SIGNAL_FUNC(compose_key_press_cb),
4416 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4417 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4421 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4423 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4424 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4426 gtk_widget_show_all(vbox);
4428 /* pane between attach clist and text */
4429 paned = gtk_vpaned_new();
4430 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4431 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4432 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4433 gtk_paned_add1(GTK_PANED(paned), notebook);
4434 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4435 gtk_widget_show_all(paned);
4437 style = gtk_widget_get_style(text);
4439 /* workaround for the slow down of GtkSText when using Pixmap theme */
4440 if (style->engine) {
4441 GtkThemeEngine *engine;
4443 engine = style->engine;
4444 style->engine = NULL;
4445 new_style = gtk_style_copy(style);
4446 style->engine = engine;
4448 new_style = gtk_style_copy(style);
4450 if (prefs_common.textfont) {
4453 charset = conv_get_current_charset();
4454 if (MB_CUR_MAX == 1) {
4457 Xstrdup_a(fontstr, prefs_common.textfont, );
4458 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4460 font = gdk_font_load(fontstr);
4462 font = gdk_fontset_load(prefs_common.textfont);
4464 gdk_font_unref(new_style->font);
4465 new_style->font = font;
4469 gtk_widget_set_style(text, new_style);
4471 color[0] = quote_color;
4472 cmap = gdk_window_get_colormap(window->window);
4473 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4474 if (success[0] == FALSE) {
4475 g_warning("Compose: color allocation failed.\n");
4476 style = gtk_widget_get_style(text);
4477 quote_color = style->black;
4480 n_entries = sizeof(compose_popup_entries) /
4481 sizeof(compose_popup_entries[0]);
4482 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4483 "<Compose>", &popupfactory,
4486 ifactory = gtk_item_factory_from_widget(menubar);
4487 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4488 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4490 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4491 #if 0 /* NEW COMPOSE GUI */
4492 gtk_widget_hide(bcc_hbox);
4493 gtk_widget_hide(bcc_entry);
4494 gtk_widget_hide(reply_hbox);
4495 gtk_widget_hide(reply_entry);
4496 gtk_widget_hide(followup_hbox);
4497 gtk_widget_hide(followup_entry);
4498 gtk_widget_hide(ruler_hbox);
4499 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4500 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4501 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4503 if (account->protocol == A_NNTP) {
4504 gtk_widget_hide(to_hbox);
4505 gtk_widget_hide(to_entry);
4506 gtk_widget_hide(cc_hbox);
4507 gtk_widget_hide(cc_entry);
4508 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4509 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4511 gtk_widget_hide(newsgroups_hbox);
4512 gtk_widget_hide(newsgroups_entry);
4513 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4514 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
4518 update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
4521 undostruct = undo_init(text);
4522 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4525 gtk_widget_show(window);
4527 address_completion_start(window);
4529 compose->window = window;
4530 compose->vbox = vbox;
4531 compose->menubar = menubar;
4532 compose->handlebox = handlebox;
4534 compose->vbox2 = vbox2;
4536 compose->paned = paned;
4538 compose->edit_vbox = edit_vbox;
4539 compose->ruler_hbox = ruler_hbox;
4540 compose->ruler = ruler;
4541 compose->scrolledwin = scrolledwin;
4542 compose->text = text;
4544 compose->focused_editable = NULL;
4546 compose->popupmenu = popupmenu;
4547 compose->popupfactory = popupfactory;
4549 compose->tmpl_menu = tmpl_menu;
4551 compose->mode = mode;
4553 compose->targetinfo = NULL;
4554 compose->replyinfo = NULL;
4556 compose->replyto = NULL;
4557 compose->mailinglist = NULL;
4559 compose->bcc = NULL;
4560 compose->followup_to = NULL;
4561 compose->inreplyto = NULL;
4562 compose->references = NULL;
4563 compose->msgid = NULL;
4564 compose->boundary = NULL;
4567 compose->use_signing = FALSE;
4568 compose->use_encryption = FALSE;
4569 #endif /* USE_GPGME */
4571 compose->modified = FALSE;
4573 compose->return_receipt = FALSE;
4575 compose->to_list = NULL;
4576 compose->newsgroup_list = NULL;
4578 compose->exteditor_file = NULL;
4579 compose->exteditor_pid = -1;
4580 compose->exteditor_readdes = -1;
4581 compose->exteditor_tag = -1;
4583 compose->bounce_filename = NULL;
4584 compose->undostruct = undostruct;
4587 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4588 if (prefs_common.enable_pspell) {
4589 gtkpspell = gtkpspell_new((const gchar*)prefs_common.dictionary,
4590 conv_get_current_charset_str(),
4591 prefs_common.misspelled_col,
4592 prefs_common.check_while_typing,
4593 prefs_common.use_alternate,
4596 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkpspellcheckers->error_message);
4597 gtkpspell_checkers_reset_error();
4600 GtkWidget *menuitem;
4602 if (!gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode)) {
4603 debug_print(_("Pspell: could not set suggestion mode %s"),
4604 gtkpspellcheckers->error_message);
4605 gtkpspell_checkers_reset_error();
4608 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
4609 gtkpspell_populate_submenu(gtkpspell, menuitem);
4610 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4615 compose_set_title(compose);
4617 #if 0 /* NEW COMPOSE GUI */
4618 compose->use_bcc = FALSE;
4619 compose->use_replyto = FALSE;
4620 compose->use_followupto = FALSE;
4624 compose->gtkpspell = gtkpspell;
4627 #if 0 /* NEW COMPOSE GUI */
4628 if (account->protocol != A_NNTP) {
4629 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
4630 gtk_check_menu_item_set_active
4631 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4632 gtk_widget_set_sensitive(menuitem, FALSE);
4633 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4634 gtk_check_menu_item_set_active
4635 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4636 gtk_widget_set_sensitive(menuitem, FALSE);
4639 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4640 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4641 #if 0 /* NEW COMPOSE GUI */
4642 compose->use_cc = TRUE;
4643 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4644 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4645 gtk_check_menu_item_set_active
4646 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4649 if (account->set_autobcc) {
4650 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4651 #if 0 /* NEW COMPOSE GUI */
4652 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
4653 gtk_check_menu_item_set_active
4654 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4655 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4656 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4660 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4661 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4662 #if 0 /* NEW COMPOSE GUI */
4663 compose->use_replyto = TRUE;
4664 menuitem = gtk_item_factory_get_item(ifactory,
4666 gtk_check_menu_item_set_active
4667 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4668 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4669 account->auto_replyto);
4673 if (account->protocol != A_NNTP) {
4674 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4676 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4679 #if 0 /* NEW COMPOSE GUI */
4680 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
4681 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4682 prefs_common.show_ruler);
4686 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4687 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4688 account->default_sign);
4689 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4690 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4691 account->default_encrypt);
4692 #endif /* USE_GPGME */
4694 addressbook_set_target_compose(compose);
4695 compose_set_template_menu(compose);
4697 compose_list = g_list_append(compose_list, compose);
4699 #if 0 /* NEW COMPOSE GUI */
4700 compose->use_to = FALSE;
4701 compose->use_cc = FALSE;
4702 compose->use_attach = TRUE;
4705 #if 0 /* NEW COMPOSE GUI */
4706 if (!compose->use_bcc) {
4707 gtk_widget_hide(bcc_hbox);
4708 gtk_widget_hide(bcc_entry);
4709 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4711 if (!compose->use_replyto) {
4712 gtk_widget_hide(reply_hbox);
4713 gtk_widget_hide(reply_entry);
4714 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4716 if (!compose->use_followupto) {
4717 gtk_widget_hide(followup_hbox);
4718 gtk_widget_hide(followup_entry);
4719 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4722 if (!prefs_common.show_ruler)
4723 gtk_widget_hide(ruler_hbox);
4725 select_account(compose, account);
4726 set_toolbar_style(compose);
4731 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4734 GtkWidget *icon_wid;
4735 GtkWidget *send_btn;
4736 GtkWidget *sendl_btn;
4737 GtkWidget *draft_btn;
4738 GtkWidget *insert_btn;
4739 GtkWidget *attach_btn;
4741 GtkWidget *exteditor_btn;
4742 GtkWidget *linewrap_btn;
4743 GtkWidget *addrbook_btn;
4745 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4747 gtk_container_add(GTK_CONTAINER(container), toolbar);
4748 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4749 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4750 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4751 GTK_TOOLBAR_SPACE_LINE);
4753 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
4754 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4758 icon_wid, toolbar_send_cb, compose);
4760 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND_QUEUE);
4761 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4763 _("Put into queue folder and send later"),
4765 icon_wid, toolbar_send_later_cb,
4768 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4769 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4771 _("Save to draft folder"),
4773 icon_wid, toolbar_draft_cb,
4776 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4778 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_INSERT_FILE);
4779 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4783 icon_wid, toolbar_insert_cb,
4786 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_ATTACH);
4787 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4791 icon_wid, toolbar_attach_cb,
4794 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4796 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SIGN);
4797 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4799 _("Insert signature"),
4801 icon_wid, toolbar_sig_cb, compose);
4803 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4805 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_EDIT_EXTERN);
4806 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4808 _("Edit with external editor"),
4811 toolbar_ext_editor_cb,
4814 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_LINEWRAP);
4815 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4817 _("Wrap all long lines"),
4820 toolbar_linewrap_cb,
4823 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4825 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_ADDRESS_BOOK);
4826 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4830 icon_wid, toolbar_address_cb,
4833 compose->toolbar = toolbar;
4834 compose->send_btn = send_btn;
4835 compose->sendl_btn = sendl_btn;
4836 compose->draft_btn = draft_btn;
4837 compose->insert_btn = insert_btn;
4838 compose->attach_btn = attach_btn;
4839 compose->sig_btn = sig_btn;
4840 compose->exteditor_btn = exteditor_btn;
4841 compose->linewrap_btn = linewrap_btn;
4842 compose->addrbook_btn = addrbook_btn;
4844 gtk_widget_show_all(toolbar);
4847 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4853 gint num = 0, def_menu = 0;
4855 accounts = account_get_list();
4856 g_return_val_if_fail(accounts != NULL, NULL);
4858 hbox = gtk_hbox_new(FALSE, 0);
4859 optmenu = gtk_option_menu_new();
4860 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4861 menu = gtk_menu_new();
4863 for (; accounts != NULL; accounts = accounts->next, num++) {
4864 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4865 GtkWidget *menuitem;
4868 if (ac == compose->account) def_menu = num;
4870 name = g_strdup_printf("%s: %s <%s>",
4871 ac->account_name, ac->name, ac->address);
4872 MENUITEM_ADD(menu, menuitem, name, ac);
4874 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4875 GTK_SIGNAL_FUNC(account_activated),
4879 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4880 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4885 static void compose_set_template_menu(Compose *compose)
4887 GSList *tmpl_list, *cur;
4891 tmpl_list = template_get_config();
4893 menu = gtk_menu_new();
4895 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4896 Template *tmpl = (Template *)cur->data;
4898 item = gtk_menu_item_new_with_label(tmpl->name);
4899 gtk_menu_append(GTK_MENU(menu), item);
4900 gtk_signal_connect(GTK_OBJECT(item), "activate",
4901 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4903 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4904 gtk_widget_show(item);
4907 gtk_widget_show(menu);
4908 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4911 void compose_reflect_prefs_all(void)
4916 for (cur = compose_list; cur != NULL; cur = cur->next) {
4917 compose = (Compose *)cur->data;
4918 compose_set_template_menu(compose);
4922 void compose_reflect_prefs_pixmap_theme(void)
4927 for (cur = compose_list; cur != NULL; cur = cur->next) {
4928 compose = (Compose *)cur->data;
4929 gtk_container_remove(GTK_CONTAINER(compose->handlebox), GTK_WIDGET(compose->toolbar));
4930 compose->toolbar = NULL;
4931 compose_toolbar_create(compose, compose->handlebox);
4932 set_toolbar_style(compose);
4937 static void compose_template_apply(Compose *compose, Template *tmpl)
4942 if (!tmpl || !tmpl->value) return;
4944 gtk_stext_freeze(GTK_STEXT(compose->text));
4946 if (tmpl->subject && *tmpl->subject != '\0')
4947 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
4949 if (tmpl->to && *tmpl->to != '\0')
4950 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
4952 gtk_stext_clear(GTK_STEXT(compose->text));
4954 if (compose->replyinfo == NULL) {
4957 memset(&dummyinfo, 0, sizeof(MsgInfo));
4958 parsed_str = compose_quote_fmt(compose, &dummyinfo,
4959 tmpl->value, NULL, NULL);
4961 if (prefs_common.quotemark && *prefs_common.quotemark)
4962 qmark = prefs_common.quotemark;
4966 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
4967 tmpl->value, qmark, NULL);
4970 if (parsed_str && prefs_common.auto_sig)
4971 compose_insert_sig(compose);
4973 gtk_stext_thaw(GTK_STEXT(compose->text));
4976 static void compose_destroy(Compose *compose)
4979 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4982 /* NOTE: address_completion_end() does nothing with the window
4983 * however this may change. */
4984 address_completion_end(compose->window);
4986 slist_free_strings(compose->to_list);
4987 g_slist_free(compose->to_list);
4988 slist_free_strings(compose->newsgroup_list);
4989 g_slist_free(compose->newsgroup_list);
4990 slist_free_strings(compose->header_list);
4991 g_slist_free(compose->header_list);
4993 procmsg_msginfo_free(compose->targetinfo);
4994 procmsg_msginfo_free(compose->replyinfo);
4996 g_free(compose->replyto);
4997 g_free(compose->cc);
4998 g_free(compose->bcc);
4999 g_free(compose->newsgroups);
5000 g_free(compose->followup_to);
5002 g_free(compose->inreplyto);
5003 g_free(compose->references);
5004 g_free(compose->msgid);
5005 g_free(compose->boundary);
5007 if (compose->bounce_filename)
5008 g_free(compose->bounce_filename);
5010 g_free(compose->exteditor_file);
5012 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5014 compose_attach_info_free(ainfo);
5016 if (addressbook_get_target_compose() == compose)
5017 addressbook_set_target_compose(NULL);
5020 if (compose->gtkpspell) {
5021 gtkpspell_delete(compose->gtkpspell);
5025 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5026 prefs_common.compose_height = compose->window->allocation.height;
5028 gtk_widget_destroy(compose->paned);
5032 compose_list = g_list_remove(compose_list, compose);
5035 static void compose_attach_info_free(AttachInfo *ainfo)
5037 g_free(ainfo->file);
5038 g_free(ainfo->content_type);
5039 g_free(ainfo->name);
5043 static void compose_attach_remove_selected(Compose *compose)
5045 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5049 while (clist->selection != NULL) {
5050 row = GPOINTER_TO_INT(clist->selection->data);
5051 ainfo = gtk_clist_get_row_data(clist, row);
5052 compose_attach_info_free(ainfo);
5053 gtk_clist_remove(clist, row);
5057 static struct _AttachProperty
5060 GtkWidget *mimetype_entry;
5061 GtkWidget *encoding_optmenu;
5062 GtkWidget *path_entry;
5063 GtkWidget *filename_entry;
5065 GtkWidget *cancel_btn;
5068 static void compose_attach_property(Compose *compose)
5070 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5073 GtkOptionMenu *optmenu;
5074 static gboolean cancelled;
5076 if (!clist->selection) return;
5077 row = GPOINTER_TO_INT(clist->selection->data);
5079 ainfo = gtk_clist_get_row_data(clist, row);
5082 if (!attach_prop.window)
5083 compose_attach_property_create(&cancelled);
5084 gtk_widget_grab_focus(attach_prop.ok_btn);
5085 gtk_widget_show(attach_prop.window);
5086 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5088 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5089 if (ainfo->encoding == ENC_UNKNOWN)
5090 gtk_option_menu_set_history(optmenu, ENC_BASE64);
5092 gtk_option_menu_set_history(optmenu, ainfo->encoding);
5094 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5095 ainfo->content_type ? ainfo->content_type : "");
5096 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5097 ainfo->file ? ainfo->file : "");
5098 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5099 ainfo->name ? ainfo->name : "");
5103 gchar *cnttype = NULL;
5107 GtkWidget *menuitem;
5112 if (cancelled == TRUE) {
5113 gtk_widget_hide(attach_prop.window);
5117 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5118 if (*text != '\0') {
5121 text = g_strstrip(g_strdup(text));
5122 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5123 cnttype = g_strdup(text);
5126 alertpanel_error(_("Invalid MIME type."));
5132 menu = gtk_option_menu_get_menu(optmenu);
5133 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5134 ainfo->encoding = GPOINTER_TO_INT
5135 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5137 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5138 if (*text != '\0') {
5139 if (is_file_exist(text) &&
5140 (size = get_file_size(text)) > 0)
5141 file = g_strdup(text);
5144 (_("File doesn't exist or is empty."));
5150 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5151 if (*text != '\0') {
5152 g_free(ainfo->name);
5153 ainfo->name = g_strdup(text);
5157 g_free(ainfo->content_type);
5158 ainfo->content_type = cnttype;
5161 g_free(ainfo->file);
5167 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5168 ainfo->content_type);
5169 gtk_clist_set_text(clist, row, COL_SIZE,
5170 to_human_readable(ainfo->size));
5171 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5173 gtk_widget_hide(attach_prop.window);
5178 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5180 label = gtk_label_new(str); \
5181 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5182 GTK_FILL, 0, 0, 0); \
5183 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5185 entry = gtk_entry_new(); \
5186 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5187 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5190 static void compose_attach_property_create(gboolean *cancelled)
5196 GtkWidget *mimetype_entry;
5199 GtkWidget *optmenu_menu;
5200 GtkWidget *menuitem;
5201 GtkWidget *path_entry;
5202 GtkWidget *filename_entry;
5205 GtkWidget *cancel_btn;
5206 GList *mime_type_list, *strlist;
5208 debug_print("Creating attach_property window...\n");
5210 window = gtk_window_new(GTK_WINDOW_DIALOG);
5211 gtk_widget_set_usize(window, 480, -1);
5212 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5213 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
5214 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5215 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5216 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5217 GTK_SIGNAL_FUNC(attach_property_delete_event),
5219 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5220 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5223 vbox = gtk_vbox_new(FALSE, 8);
5224 gtk_container_add(GTK_CONTAINER(window), vbox);
5226 table = gtk_table_new(4, 2, FALSE);
5227 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5228 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5229 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5231 label = gtk_label_new(_("MIME type"));
5232 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5234 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5235 mimetype_entry = gtk_combo_new();
5236 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5237 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5239 /* stuff with list */
5240 mime_type_list = procmime_get_mime_type_list();
5242 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5243 MimeType *type = (MimeType *) mime_type_list->data;
5244 strlist = g_list_append(strlist,
5245 g_strdup_printf("%s/%s",
5246 type->type, type->sub_type));
5249 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5251 for (mime_type_list = strlist; mime_type_list != NULL;
5252 mime_type_list = mime_type_list->next)
5253 g_free(mime_type_list->data);
5254 g_list_free(strlist);
5256 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5258 label = gtk_label_new(_("Encoding"));
5259 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5261 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5263 hbox = gtk_hbox_new(FALSE, 0);
5264 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5265 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5267 optmenu = gtk_option_menu_new();
5268 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5270 optmenu_menu = gtk_menu_new();
5271 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5272 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5274 gtk_widget_set_sensitive(menuitem, FALSE);
5276 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5277 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5279 gtk_widget_set_sensitive(menuitem, FALSE);
5281 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5282 gtk_widget_set_sensitive(menuitem, FALSE);
5283 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5285 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5287 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5288 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5290 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5291 &cancel_btn, _("Cancel"), NULL, NULL);
5292 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5293 gtk_widget_grab_default(ok_btn);
5295 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5296 GTK_SIGNAL_FUNC(attach_property_ok),
5298 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5299 GTK_SIGNAL_FUNC(attach_property_cancel),
5302 gtk_widget_show_all(vbox);
5304 attach_prop.window = window;
5305 attach_prop.mimetype_entry = mimetype_entry;
5306 attach_prop.encoding_optmenu = optmenu;
5307 attach_prop.path_entry = path_entry;
5308 attach_prop.filename_entry = filename_entry;
5309 attach_prop.ok_btn = ok_btn;
5310 attach_prop.cancel_btn = cancel_btn;
5313 #undef SET_LABEL_AND_ENTRY
5315 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5321 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5327 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5328 gboolean *cancelled)
5336 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5337 gboolean *cancelled)
5339 if (event && event->keyval == GDK_Escape) {
5345 static void compose_exec_ext_editor(Compose *compose)
5351 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5352 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5354 if (pipe(pipe_fds) < 0) {
5359 if ((pid = fork()) < 0) {
5365 /* close the write side of the pipe */
5368 compose->exteditor_file = g_strdup(tmp);
5369 compose->exteditor_pid = pid;
5370 compose->exteditor_readdes = pipe_fds[0];
5372 compose_set_ext_editor_sensitive(compose, FALSE);
5374 compose->exteditor_tag =
5375 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5376 compose_input_cb, compose);
5377 } else { /* process-monitoring process */
5383 /* close the read side of the pipe */
5386 if (compose_write_body_to_file(compose, tmp) < 0) {
5387 fd_write(pipe_fds[1], "2\n", 2);
5391 pid_ed = compose_exec_ext_editor_real(tmp);
5393 fd_write(pipe_fds[1], "1\n", 2);
5397 /* wait until editor is terminated */
5398 waitpid(pid_ed, NULL, 0);
5400 fd_write(pipe_fds[1], "0\n", 2);
5407 static gint compose_exec_ext_editor_real(const gchar *file)
5409 static gchar *def_cmd = "emacs %s";
5415 g_return_val_if_fail(file != NULL, -1);
5417 if ((pid = fork()) < 0) {
5422 if (pid != 0) return pid;
5424 /* grandchild process */
5426 if (setpgid(0, getppid()))
5429 if (prefs_common.ext_editor_cmd &&
5430 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5431 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5432 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5434 if (prefs_common.ext_editor_cmd)
5435 g_warning(_("External editor command line is invalid: `%s'\n"),
5436 prefs_common.ext_editor_cmd);
5437 g_snprintf(buf, sizeof(buf), def_cmd, file);
5440 cmdline = strsplit_with_quote(buf, " ", 1024);
5441 execvp(cmdline[0], cmdline);
5444 g_strfreev(cmdline);
5449 static gboolean compose_ext_editor_kill(Compose *compose)
5451 pid_t pgid = compose->exteditor_pid * -1;
5454 ret = kill(pgid, 0);
5456 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5460 msg = g_strdup_printf
5461 (_("The external editor is still working.\n"
5462 "Force terminating the process?\n"
5463 "process group id: %d"), -pgid);
5464 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5467 if (val == G_ALERTDEFAULT) {
5468 gdk_input_remove(compose->exteditor_tag);
5469 close(compose->exteditor_readdes);
5471 if (kill(pgid, SIGTERM) < 0) perror("kill");
5472 waitpid(compose->exteditor_pid, NULL, 0);
5474 g_warning(_("Terminated process group id: %d"), -pgid);
5475 g_warning(_("Temporary file: %s"),
5476 compose->exteditor_file);
5478 compose_set_ext_editor_sensitive(compose, TRUE);
5480 g_free(compose->exteditor_file);
5481 compose->exteditor_file = NULL;
5482 compose->exteditor_pid = -1;
5483 compose->exteditor_readdes = -1;
5484 compose->exteditor_tag = -1;
5492 static void compose_input_cb(gpointer data, gint source,
5493 GdkInputCondition condition)
5496 Compose *compose = (Compose *)data;
5499 debug_print(_("Compose: input from monitoring process\n"));
5501 gdk_input_remove(compose->exteditor_tag);
5504 if (read(source, &buf[i], 1) < 1) {
5508 if (buf[i] == '\n') {
5513 if (i == sizeof(buf) - 1)
5517 waitpid(compose->exteditor_pid, NULL, 0);
5519 if (buf[0] == '0') { /* success */
5520 GtkSText *text = GTK_STEXT(compose->text);
5522 gtk_stext_freeze(text);
5523 gtk_stext_set_point(text, 0);
5524 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5525 compose_insert_file(compose, compose->exteditor_file);
5526 compose_changed_cb(NULL, compose);
5527 gtk_stext_thaw(text);
5529 if (unlink(compose->exteditor_file) < 0)
5530 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5531 } else if (buf[0] == '1') { /* failed */
5532 g_warning(_("Couldn't exec external editor\n"));
5533 if (unlink(compose->exteditor_file) < 0)
5534 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5535 } else if (buf[0] == '2') {
5536 g_warning(_("Couldn't write to file\n"));
5537 } else if (buf[0] == '3') {
5538 g_warning(_("Pipe read failed\n"));
5543 compose_set_ext_editor_sensitive(compose, TRUE);
5545 g_free(compose->exteditor_file);
5546 compose->exteditor_file = NULL;
5547 compose->exteditor_pid = -1;
5548 compose->exteditor_readdes = -1;
5549 compose->exteditor_tag = -1;
5552 static void compose_set_ext_editor_sensitive(Compose *compose,
5555 GtkItemFactory *ifactory;
5557 ifactory = gtk_item_factory_from_widget(compose->menubar);
5559 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5560 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5561 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5563 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5564 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5565 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5566 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5567 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5570 gtk_widget_set_sensitive(compose->text, sensitive);
5571 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5572 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5573 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5574 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5575 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5576 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5577 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5581 * compose_undo_state_changed:
5583 * Change the sensivity of the menuentries undo and redo
5585 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5586 gint redo_state, gpointer data)
5588 GtkWidget *widget = GTK_WIDGET(data);
5589 GtkItemFactory *ifactory;
5591 g_return_if_fail(widget != NULL);
5593 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
5595 ifactory = gtk_item_factory_from_widget(widget);
5597 switch (undo_state) {
5598 case UNDO_STATE_TRUE:
5599 if (!undostruct->undo_state) {
5600 debug_print ("Set_undo - Testpoint\n");
5601 undostruct->undo_state = TRUE;
5602 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5605 case UNDO_STATE_FALSE:
5606 if (undostruct->undo_state) {
5607 undostruct->undo_state = FALSE;
5608 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5611 case UNDO_STATE_UNCHANGED:
5613 case UNDO_STATE_REFRESH:
5614 menu_set_sensitive(ifactory, "/Edit/Undo",
5615 undostruct->undo_state);
5618 g_warning("Undo state not recognized");
5622 switch (redo_state) {
5623 case UNDO_STATE_TRUE:
5624 if (!undostruct->redo_state) {
5625 undostruct->redo_state = TRUE;
5626 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5629 case UNDO_STATE_FALSE:
5630 if (undostruct->redo_state) {
5631 undostruct->redo_state = FALSE;
5632 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5635 case UNDO_STATE_UNCHANGED:
5637 case UNDO_STATE_REFRESH:
5638 menu_set_sensitive(ifactory, "/Edit/Redo",
5639 undostruct->redo_state);
5642 g_warning("Redo state not recognized");
5647 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5651 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5652 cursor_pos = MAX(cursor_pos, 0);
5657 /* callback functions */
5659 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5660 * includes "non-client" (windows-izm) in calculation, so this calculation
5661 * may not be accurate.
5663 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5664 GtkAllocation *allocation,
5665 GtkSHRuler *shruler)
5667 if (prefs_common.show_ruler) {
5669 gint line_width_in_chars;
5671 char_width = gtkut_get_font_width
5672 (GTK_WIDGET(widget)->style->font);
5673 line_width_in_chars =
5674 (allocation->width - allocation->x) / char_width;
5676 /* got the maximum */
5677 gtk_ruler_set_range(GTK_RULER(shruler),
5678 0.0, line_width_in_chars,
5679 calc_cursor_xpos(GTK_STEXT(widget),
5682 /*line_width_in_chars*/ char_width);
5688 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5690 compose_send_cb(data, 0, NULL);
5693 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5695 compose_send_later_cb(data, 0, NULL);
5698 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5700 compose_draft_cb(data, 0, NULL);
5703 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5705 compose_insert_file_cb(data, 0, NULL);
5708 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5710 compose_attach_cb(data, 0, NULL);
5713 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5715 Compose *compose = (Compose *)data;
5717 compose_insert_sig(compose);
5720 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5722 Compose *compose = (Compose *)data;
5724 compose_exec_ext_editor(compose);
5727 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5729 Compose *compose = (Compose *)data;
5731 compose_wrap_line(compose);
5734 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5736 compose_address_cb(data, 0, NULL);
5739 static void select_account(Compose * compose, PrefsAccount * ac)
5742 GtkItemFactory *ifactory;
5743 GtkWidget *menuitem;
5744 #endif /* USE_GPGME */
5745 compose->account = ac;
5746 compose_set_title(compose);
5748 #if 0 /* NEW COMPOSE GUI */
5749 if (ac->protocol == A_NNTP) {
5750 GtkItemFactory *ifactory;
5751 GtkWidget *menuitem;
5753 ifactory = gtk_item_factory_from_widget(compose->menubar);
5754 menu_set_sensitive(ifactory,
5755 "/Message/Followup to", TRUE);
5756 gtk_widget_show(compose->newsgroups_hbox);
5757 gtk_widget_show(compose->newsgroups_entry);
5758 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5761 compose->use_to = FALSE;
5762 compose->use_cc = FALSE;
5764 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5765 gtk_check_menu_item_set_active
5766 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5768 menu_set_sensitive(ifactory,
5769 "/Message/To", TRUE);
5770 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5771 gtk_check_menu_item_set_active
5772 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5774 gtk_widget_hide(compose->to_hbox);
5775 gtk_widget_hide(compose->to_entry);
5776 gtk_widget_hide(compose->cc_hbox);
5777 gtk_widget_hide(compose->cc_entry);
5778 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5780 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5784 GtkItemFactory *ifactory;
5785 GtkWidget *menuitem;
5787 ifactory = gtk_item_factory_from_widget(compose->menubar);
5788 menu_set_sensitive(ifactory,
5789 "/Message/Followup to", FALSE);
5790 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5791 gtk_widget_hide(compose->newsgroups_hbox);
5792 gtk_widget_hide(compose->newsgroups_entry);
5793 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5796 compose->use_to = TRUE;
5797 compose->use_cc = TRUE;
5799 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5800 gtk_check_menu_item_set_active
5801 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5802 menu_set_sensitive(ifactory,
5803 "/Message/To", FALSE);
5804 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5805 gtk_check_menu_item_set_active
5806 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5807 gtk_widget_show(compose->to_hbox);
5808 gtk_widget_show(compose->to_entry);
5809 gtk_widget_show(compose->cc_hbox);
5810 gtk_widget_show(compose->cc_entry);
5812 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5814 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5817 gtk_widget_queue_resize(compose->table_vbox);
5820 ifactory = gtk_item_factory_from_widget(compose->menubar);
5821 menu_set_sensitive(ifactory,
5822 "/Message/Sign", TRUE);
5823 menu_set_sensitive(ifactory,
5824 "/Message/Encrypt", TRUE);
5826 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
5827 if (ac->default_sign)
5828 gtk_check_menu_item_set_active
5829 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5831 gtk_check_menu_item_set_active
5832 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5834 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
5835 if (ac->default_encrypt)
5836 gtk_check_menu_item_set_active
5837 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5839 gtk_check_menu_item_set_active
5840 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5841 #endif /* USE_GPGME */
5845 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5847 Compose *compose = (Compose *)data;
5851 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5852 g_return_if_fail(ac != NULL);
5854 if (ac != compose->account)
5855 select_account(compose, ac);
5858 static void attach_selected(GtkCList *clist, gint row, gint column,
5859 GdkEvent *event, gpointer data)
5861 Compose *compose = (Compose *)data;
5863 if (event && event->type == GDK_2BUTTON_PRESS)
5864 compose_attach_property(compose);
5867 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5870 Compose *compose = (Compose *)data;
5871 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5876 if (event->button == 3) {
5877 if ((clist->selection && !clist->selection->next) ||
5878 !clist->selection) {
5879 gtk_clist_unselect_all(clist);
5880 if (gtk_clist_get_selection_info(clist,
5883 gtk_clist_select_row(clist, row, column);
5884 gtkut_clist_set_focus_row(clist, row);
5887 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5888 NULL, NULL, event->button, event->time);
5892 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5895 Compose *compose = (Compose *)data;
5899 switch (event->keyval) {
5901 compose_attach_remove_selected(compose);
5906 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5908 Compose *compose = (Compose *)data;
5911 val = compose_send(compose);
5913 if (val == 0) gtk_widget_destroy(compose->window);
5916 static void compose_send_later_cb(gpointer data, guint action,
5919 Compose *compose = (Compose *)data;
5922 val = compose_queue(compose, NULL, NULL);
5923 if (!val) gtk_widget_destroy(compose->window);
5926 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5928 Compose *compose = (Compose *)data;
5932 MsgFlags flag = {0, 0};
5933 static gboolean lock = FALSE;
5937 if (compose->account && compose->account->folder &&
5938 FOLDER(compose->account->folder)->draft)
5939 draft = FOLDER(compose->account->folder)->draft;
5941 draft = folder_get_default_draft();
5942 g_return_if_fail(draft != NULL);
5946 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5947 G_DIR_SEPARATOR, (gint)compose);
5949 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5955 folder_item_scan(draft);
5956 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) < 0) {
5963 draft->mtime = 0; /* force updating */
5965 if (compose->mode == COMPOSE_REEDIT) {
5966 compose_remove_reedit_target(compose);
5967 if (compose->targetinfo &&
5968 compose->targetinfo->folder != draft)
5969 folderview_update_item(compose->targetinfo->folder,
5973 procmsg_add_flags(draft, msgnum, flag);
5974 folder_item_scan(draft);
5975 folderview_update_item(draft, TRUE);
5979 /* 0: quit editing 1: keep editing */
5981 gtk_widget_destroy(compose->window);
5986 path = folder_item_fetch_msg(draft, msgnum);
5987 g_return_if_fail(path != NULL);
5988 if (stat(path, &s) < 0) {
5989 FILE_OP_ERROR(path, "stat");
5996 procmsg_msginfo_free(compose->targetinfo);
5997 compose->targetinfo = g_new0(MsgInfo, 1);
5998 compose->targetinfo->msgnum = msgnum;
5999 compose->targetinfo->size = s.st_size;
6000 compose->targetinfo->mtime = s.st_mtime;
6001 compose->targetinfo->folder = draft;
6002 compose->mode = COMPOSE_REEDIT;
6006 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6008 Compose *compose = (Compose *)data;
6011 if (compose->bounce_filename != NULL)
6014 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6019 for ( tmp = file_list; tmp; tmp = tmp->next) {
6020 gchar *file = (gchar *) tmp->data;
6021 compose_attach_append(compose, file, file, NULL);
6022 compose_changed_cb(NULL, compose);
6025 g_list_free(file_list);
6029 static void compose_insert_file_cb(gpointer data, guint action,
6032 Compose *compose = (Compose *)data;
6035 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6040 for ( tmp = file_list; tmp; tmp = tmp->next) {
6041 gchar *file = (gchar *) tmp->data;
6042 compose_insert_file(compose, file);
6045 g_list_free(file_list);
6049 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6052 compose_close_cb(data, 0, NULL);
6056 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6058 Compose *compose = (Compose *)data;
6061 if (compose->exteditor_tag != -1) {
6062 if (!compose_ext_editor_kill(compose))
6066 if (compose->modified) {
6067 val = alertpanel(_("Discard message"),
6068 _("This message has been modified. discard it?"),
6069 _("Discard"), _("to Draft"), _("Cancel"));
6072 case G_ALERTDEFAULT:
6074 case G_ALERTALTERNATE:
6075 compose_draft_cb(data, 0, NULL);
6081 gtk_widget_destroy(compose->window);
6084 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6086 Compose *compose = (Compose *)data;
6088 addressbook_open(compose);
6091 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6093 Compose *compose = (Compose *)data;
6096 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6097 g_return_if_fail(tmpl != NULL);
6099 compose_template_apply(compose, tmpl);
6102 static void compose_ext_editor_cb(gpointer data, guint action,
6105 Compose *compose = (Compose *)data;
6107 compose_exec_ext_editor(compose);
6110 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6112 compose_destroy(compose);
6115 static void compose_undo_cb(Compose *compose)
6117 undo_undo(compose->undostruct);
6120 static void compose_redo_cb(Compose *compose)
6122 undo_redo(compose->undostruct);
6125 static void compose_cut_cb(Compose *compose)
6127 if (compose->focused_editable &&
6128 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6129 gtk_editable_cut_clipboard
6130 (GTK_EDITABLE(compose->focused_editable));
6133 static void compose_copy_cb(Compose *compose)
6135 if (compose->focused_editable &&
6136 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6137 gtk_editable_copy_clipboard
6138 (GTK_EDITABLE(compose->focused_editable));
6141 static void compose_paste_cb(Compose *compose)
6143 if (compose->focused_editable &&
6144 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6145 gtk_editable_paste_clipboard
6146 (GTK_EDITABLE(compose->focused_editable));
6149 static void compose_allsel_cb(Compose *compose)
6151 if (compose->focused_editable &&
6152 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6153 gtk_editable_select_region
6154 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6157 static void compose_move_beginning_of_line_cb(Compose *compose)
6159 if (compose->focused_editable &&
6160 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6161 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6164 static void compose_gtk_stext_action_cb(Compose *compose, ComposeCallGtkSTextAction action)
6166 if (!(compose->focused_editable && GTK_WIDGET_HAS_FOCUS(compose->focused_editable))) return;
6169 case COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE:
6170 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6172 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER:
6173 gtk_stext_move_forward_character(GTK_STEXT(compose->focused_editable));
6175 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER:
6176 gtk_stext_move_backward_character(GTK_STEXT(compose->focused_editable));
6178 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD:
6179 gtk_stext_move_forward_word(GTK_STEXT(compose->focused_editable));
6181 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD:
6182 gtk_stext_move_backward_word(GTK_STEXT(compose->focused_editable));
6184 case COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE:
6185 gtk_stext_move_end_of_line(GTK_STEXT(compose->focused_editable));
6187 case COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE:
6188 gtk_stext_move_next_line(GTK_STEXT(compose->focused_editable));
6190 case COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE:
6191 gtk_stext_move_previous_line(GTK_STEXT(compose->focused_editable));
6193 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER:
6194 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6196 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER:
6197 gtk_stext_delete_backward_character(GTK_STEXT(compose->focused_editable));
6199 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD:
6200 gtk_stext_delete_forward_word(GTK_STEXT(compose->focused_editable));
6202 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD:
6203 gtk_stext_delete_backward_word(GTK_STEXT(compose->focused_editable));
6205 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE:
6206 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6208 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N:
6209 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6210 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6212 case COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END:
6213 gtk_stext_delete_to_line_end(GTK_STEXT(compose->focused_editable));
6220 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6222 if (GTK_IS_EDITABLE(widget))
6223 compose->focused_editable = widget;
6226 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6228 if (compose->modified == FALSE) {
6229 compose->modified = TRUE;
6230 compose_set_title(compose);
6234 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6237 gtk_stext_set_point(GTK_STEXT(widget),
6238 gtk_editable_get_position(GTK_EDITABLE(widget)));
6242 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6245 gtk_stext_set_point(GTK_STEXT(widget),
6246 gtk_editable_get_position(GTK_EDITABLE(widget)));
6250 #if 0 /* NEW COMPOSE GUI */
6251 static void compose_toggle_to_cb(gpointer data, guint action,
6254 Compose *compose = (Compose *)data;
6256 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6257 gtk_widget_show(compose->to_hbox);
6258 gtk_widget_show(compose->to_entry);
6259 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6260 compose->use_to = TRUE;
6262 gtk_widget_hide(compose->to_hbox);
6263 gtk_widget_hide(compose->to_entry);
6264 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6265 gtk_widget_queue_resize(compose->table_vbox);
6266 compose->use_to = FALSE;
6269 if (addressbook_get_target_compose() == compose)
6270 addressbook_set_target_compose(compose);
6273 static void compose_toggle_cc_cb(gpointer data, guint action,
6276 Compose *compose = (Compose *)data;
6278 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6279 gtk_widget_show(compose->cc_hbox);
6280 gtk_widget_show(compose->cc_entry);
6281 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6282 compose->use_cc = TRUE;
6284 gtk_widget_hide(compose->cc_hbox);
6285 gtk_widget_hide(compose->cc_entry);
6286 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6287 gtk_widget_queue_resize(compose->table_vbox);
6288 compose->use_cc = FALSE;
6291 if (addressbook_get_target_compose() == compose)
6292 addressbook_set_target_compose(compose);
6295 static void compose_toggle_bcc_cb(gpointer data, guint action,
6298 Compose *compose = (Compose *)data;
6300 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6301 gtk_widget_show(compose->bcc_hbox);
6302 gtk_widget_show(compose->bcc_entry);
6303 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6304 compose->use_bcc = TRUE;
6306 gtk_widget_hide(compose->bcc_hbox);
6307 gtk_widget_hide(compose->bcc_entry);
6308 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6309 gtk_widget_queue_resize(compose->table_vbox);
6310 compose->use_bcc = FALSE;
6313 if (addressbook_get_target_compose() == compose)
6314 addressbook_set_target_compose(compose);
6317 static void compose_toggle_replyto_cb(gpointer data, guint action,
6320 Compose *compose = (Compose *)data;
6322 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6323 gtk_widget_show(compose->reply_hbox);
6324 gtk_widget_show(compose->reply_entry);
6325 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6326 compose->use_replyto = TRUE;
6328 gtk_widget_hide(compose->reply_hbox);
6329 gtk_widget_hide(compose->reply_entry);
6330 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6331 gtk_widget_queue_resize(compose->table_vbox);
6332 compose->use_replyto = FALSE;
6336 static void compose_toggle_followupto_cb(gpointer data, guint action,
6339 Compose *compose = (Compose *)data;
6341 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6342 gtk_widget_show(compose->followup_hbox);
6343 gtk_widget_show(compose->followup_entry);
6344 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6345 compose->use_followupto = TRUE;
6347 gtk_widget_hide(compose->followup_hbox);
6348 gtk_widget_hide(compose->followup_entry);
6349 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6350 gtk_widget_queue_resize(compose->table_vbox);
6351 compose->use_followupto = FALSE;
6355 static void compose_toggle_attach_cb(gpointer data, guint action,
6358 Compose *compose = (Compose *)data;
6360 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6361 gtk_widget_ref(compose->edit_vbox);
6363 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6364 compose->edit_vbox);
6365 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6366 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6368 gtk_widget_show(compose->paned);
6370 gtk_widget_unref(compose->edit_vbox);
6371 gtk_widget_unref(compose->paned);
6373 compose->use_attach = TRUE;
6375 gtk_widget_ref(compose->paned);
6376 gtk_widget_ref(compose->edit_vbox);
6378 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6380 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6381 compose->edit_vbox);
6382 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6383 compose->edit_vbox, TRUE, TRUE, 0);
6385 gtk_widget_unref(compose->edit_vbox);
6387 compose->use_attach = FALSE;
6393 static void compose_toggle_sign_cb(gpointer data, guint action,
6396 Compose *compose = (Compose *)data;
6398 if (GTK_CHECK_MENU_ITEM(widget)->active)
6399 compose->use_signing = TRUE;
6401 compose->use_signing = FALSE;
6404 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6407 Compose *compose = (Compose *)data;
6409 if (GTK_CHECK_MENU_ITEM(widget)->active)
6410 compose->use_encryption = TRUE;
6412 compose->use_encryption = FALSE;
6414 #endif /* USE_GPGME */
6416 static void compose_toggle_ruler_cb(gpointer data, guint action,
6419 Compose *compose = (Compose *)data;
6421 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6422 gtk_widget_show(compose->ruler_hbox);
6423 prefs_common.show_ruler = TRUE;
6425 gtk_widget_hide(compose->ruler_hbox);
6426 gtk_widget_queue_resize(compose->edit_vbox);
6427 prefs_common.show_ruler = FALSE;
6431 static void compose_attach_drag_received_cb (GtkWidget *widget,
6432 GdkDragContext *drag_context,
6435 GtkSelectionData *data,
6440 Compose *compose = (Compose *)user_data;
6443 list = uri_list_extract_filenames((const gchar *)data->data);
6444 for (tmp = list; tmp != NULL; tmp = tmp->next)
6445 compose_attach_append
6446 (compose, (const gchar *)tmp->data,
6447 (const gchar *)tmp->data, NULL);
6448 if (list) compose_changed_cb(NULL, compose);
6449 list_free_strings(list);
6453 static void compose_insert_drag_received_cb (GtkWidget *widget,
6454 GdkDragContext *drag_context,
6457 GtkSelectionData *data,
6462 Compose *compose = (Compose *)user_data;
6465 list = uri_list_extract_filenames((const gchar *)data->data);
6466 for (tmp = list; tmp != NULL; tmp = tmp->next)
6467 compose_insert_file(compose, (const gchar *)tmp->data);
6468 list_free_strings(list);
6472 #if 0 /* NEW COMPOSE GUI */
6473 static void to_activated(GtkWidget *widget, Compose *compose)
6475 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6476 gtk_widget_grab_focus(compose->newsgroups_entry);
6478 gtk_widget_grab_focus(compose->subject_entry);
6481 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6483 gtk_widget_grab_focus(compose->subject_entry);
6486 static void subject_activated(GtkWidget *widget, Compose *compose)
6488 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6489 gtk_widget_grab_focus(compose->cc_entry);
6490 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6491 gtk_widget_grab_focus(compose->bcc_entry);
6492 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6493 gtk_widget_grab_focus(compose->reply_entry);
6494 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6495 gtk_widget_grab_focus(compose->followup_entry);
6497 gtk_widget_grab_focus(compose->text);
6500 static void cc_activated(GtkWidget *widget, Compose *compose)
6502 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6503 gtk_widget_grab_focus(compose->bcc_entry);
6504 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6505 gtk_widget_grab_focus(compose->reply_entry);
6506 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6507 gtk_widget_grab_focus(compose->followup_entry);
6509 gtk_widget_grab_focus(compose->text);
6512 static void bcc_activated(GtkWidget *widget, Compose *compose)
6514 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6515 gtk_widget_grab_focus(compose->reply_entry);
6516 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6517 gtk_widget_grab_focus(compose->followup_entry);
6519 gtk_widget_grab_focus(compose->text);
6522 static void replyto_activated(GtkWidget *widget, Compose *compose)
6524 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6525 gtk_widget_grab_focus(compose->followup_entry);
6527 gtk_widget_grab_focus(compose->text);
6530 static void followupto_activated(GtkWidget *widget, Compose *compose)
6532 gtk_widget_grab_focus(compose->text);
6536 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6539 Compose *compose = (Compose *)data;
6541 if (GTK_CHECK_MENU_ITEM(widget)->active)
6542 compose->return_receipt = TRUE;
6544 compose->return_receipt = FALSE;
6547 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6549 ComposeHeaderEntry *headerentry)
6551 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6552 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6553 !(event->state & GDK_MODIFIER_MASK) &&
6554 (event->keyval == GDK_BackSpace) &&
6555 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6556 gtk_container_remove
6557 (GTK_CONTAINER(headerentry->compose->header_table),
6558 headerentry->combo);
6559 gtk_container_remove
6560 (GTK_CONTAINER(headerentry->compose->header_table),
6561 headerentry->entry);
6562 headerentry->compose->header_list =
6563 g_slist_remove(headerentry->compose->header_list,
6565 g_free(headerentry);
6566 } else if (event->keyval == GDK_Tab) {
6567 if (headerentry->compose->header_last == headerentry) {
6568 /* Override default next focus, and give it to subject_entry
6569 * instead of notebook tabs
6571 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6572 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6578 void compose_headerentry_changed_cb(GtkWidget *entry,
6579 ComposeHeaderEntry *headerentry)
6581 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6582 headerentry->compose->header_list =
6583 g_slist_append(headerentry->compose->header_list,
6585 compose_create_header_entry(headerentry->compose);
6586 gtk_signal_disconnect_by_func
6588 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6590 /* Automatically scroll down */
6591 compose_show_first_last_header(headerentry->compose, FALSE);
6596 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6598 GtkAdjustment *vadj;
6600 g_return_if_fail(compose);
6601 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6602 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6604 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6605 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6608 static void text_activated(GtkWidget *widget, Compose *compose)
6610 compose_send_control_enter(compose);
6613 static gboolean compose_send_control_enter(Compose *compose)
6617 GtkItemFactory *ifactory;
6618 GtkAccelEntry *accel;
6619 GtkWidget *send_menu;
6622 ev = gtk_get_current_event();
6623 if (ev->type != GDK_KEY_PRESS) return FALSE;
6625 kev = (GdkEventKey *)ev;
6626 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6629 ifactory = gtk_item_factory_from_widget(compose->menubar);
6630 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6631 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6632 accel = (GtkAccelEntry *)list->data;
6633 if (accel->accelerator_key == kev->keyval &&
6634 accel->accelerator_mods == kev->state) {
6635 compose_send_cb(compose, 0, NULL);
6643 static void compose_check_all(Compose *compose)
6645 if (compose->gtkpspell)
6646 gtkpspell_check_all(compose->gtkpspell);
6649 static void compose_highlight_all(Compose *compose)
6651 if (compose->gtkpspell)
6652 gtkpspell_highlight_all(compose->gtkpspell);
6655 static void compose_check_backwards(Compose *compose)
6657 if (compose->gtkpspell)
6658 gtkpspell_check_backwards(compose->gtkpspell);
6660 GtkItemFactory *ifactory;
6661 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6662 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6663 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6667 static void compose_check_forwards_go(Compose *compose)
6669 if (compose->gtkpspell)
6670 gtkpspell_check_forwards_go(compose->gtkpspell);
6672 GtkItemFactory *ifactory;
6673 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6674 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6675 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6680 static void set_toolbar_style(Compose *compose)
6682 switch (prefs_common.toolbar_style) {
6684 gtk_widget_hide(compose->handlebox);
6687 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6691 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6695 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6700 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
6701 gtk_widget_show(compose->handlebox);
6702 gtk_widget_queue_resize(compose->handlebox);