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,
177 static void compose_reply_set_entry (Compose *compose,
182 followup_and_reply_to);
183 static void compose_reedit_set_entry (Compose *compose,
185 static void compose_insert_sig (Compose *compose);
186 static void compose_insert_file (Compose *compose,
188 static void compose_attach_append (Compose *compose,
190 ContentType cnttype);
191 static void compose_attach_append_with_type(Compose *compose,
194 ContentType cnttype);
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 gint compose_write_to_file (Compose *compose,
204 static gint compose_write_body_to_file (Compose *compose,
206 static gint compose_save_to_outbox (Compose *compose,
208 static gint compose_remove_reedit_target (Compose *compose);
209 static gint compose_queue (Compose *compose,
212 static void compose_write_attach (Compose *compose,
214 static gint compose_write_headers (Compose *compose,
216 const gchar *charset,
217 EncodingType encoding,
220 static void compose_convert_header (gchar *dest,
224 static void compose_generate_msgid (Compose *compose,
228 static void compose_attach_info_free (AttachInfo *ainfo);
229 static void compose_attach_remove_selected (Compose *compose);
231 static void compose_attach_property (Compose *compose);
232 static void compose_attach_property_create (gboolean *cancelled);
233 static void attach_property_ok (GtkWidget *widget,
234 gboolean *cancelled);
235 static void attach_property_cancel (GtkWidget *widget,
236 gboolean *cancelled);
237 static gint attach_property_delete_event (GtkWidget *widget,
239 gboolean *cancelled);
240 static void attach_property_key_pressed (GtkWidget *widget,
242 gboolean *cancelled);
244 static void compose_exec_ext_editor (Compose *compose);
245 static gint compose_exec_ext_editor_real (const gchar *file);
246 static gboolean compose_ext_editor_kill (Compose *compose);
247 static void compose_input_cb (gpointer data,
249 GdkInputCondition condition);
250 static void compose_set_ext_editor_sensitive (Compose *compose,
253 static void compose_undo_state_changed (UndoMain *undostruct,
258 static gint calc_cursor_xpos (GtkSText *text,
262 static void compose_create_header_entry (Compose *compose);
263 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
265 /* callback functions */
267 static gboolean compose_edit_size_alloc (GtkEditable *widget,
268 GtkAllocation *allocation,
269 GtkSHRuler *shruler);
271 static void toolbar_send_cb (GtkWidget *widget,
273 static void toolbar_send_later_cb (GtkWidget *widget,
275 static void toolbar_draft_cb (GtkWidget *widget,
277 static void toolbar_insert_cb (GtkWidget *widget,
279 static void toolbar_attach_cb (GtkWidget *widget,
281 static void toolbar_sig_cb (GtkWidget *widget,
283 static void toolbar_ext_editor_cb (GtkWidget *widget,
285 static void toolbar_linewrap_cb (GtkWidget *widget,
287 static void toolbar_address_cb (GtkWidget *widget,
290 static void select_account (Compose *compose,
293 static void account_activated (GtkMenuItem *menuitem,
296 static void attach_selected (GtkCList *clist,
301 static void attach_button_pressed (GtkWidget *widget,
302 GdkEventButton *event,
304 static void attach_key_pressed (GtkWidget *widget,
308 static void compose_send_cb (gpointer data,
311 static void compose_send_later_cb (gpointer data,
315 static void compose_draft_cb (gpointer data,
319 static void compose_attach_cb (gpointer data,
322 static void compose_insert_file_cb (gpointer data,
326 static void compose_close_cb (gpointer data,
330 static void compose_address_cb (gpointer data,
333 static void compose_template_activate_cb(GtkWidget *widget,
336 static void compose_ext_editor_cb (gpointer data,
340 static gint compose_delete_cb (GtkWidget *widget,
343 static void compose_destroy_cb (GtkWidget *widget,
346 static void compose_undo_cb (Compose *compose);
347 static void compose_redo_cb (Compose *compose);
348 static void compose_cut_cb (Compose *compose);
349 static void compose_copy_cb (Compose *compose);
350 static void compose_paste_cb (Compose *compose);
351 static void compose_allsel_cb (Compose *compose);
353 static void compose_gtk_stext_action_cb (Compose *compose,
354 ComposeCallGtkSTextAction action);
356 static void compose_grab_focus_cb (GtkWidget *widget,
359 static void compose_changed_cb (GtkEditable *editable,
361 static void compose_button_press_cb (GtkWidget *widget,
362 GdkEventButton *event,
365 static void compose_key_press_cb (GtkWidget *widget,
371 static void compose_toggle_to_cb (gpointer data,
374 static void compose_toggle_cc_cb (gpointer data,
377 static void compose_toggle_bcc_cb (gpointer data,
380 static void compose_toggle_replyto_cb (gpointer data,
383 static void compose_toggle_followupto_cb(gpointer data,
386 static void compose_toggle_attach_cb (gpointer data,
390 static void compose_toggle_ruler_cb (gpointer data,
394 static void compose_toggle_sign_cb (gpointer data,
397 static void compose_toggle_encrypt_cb (gpointer data,
401 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
404 static void compose_attach_drag_received_cb (GtkWidget *widget,
405 GdkDragContext *drag_context,
408 GtkSelectionData *data,
412 static void compose_insert_drag_received_cb (GtkWidget *widget,
413 GdkDragContext *drag_context,
416 GtkSelectionData *data,
422 static void to_activated (GtkWidget *widget,
424 static void newsgroups_activated (GtkWidget *widget,
426 static void subject_activated (GtkWidget *widget,
428 static void cc_activated (GtkWidget *widget,
430 static void bcc_activated (GtkWidget *widget,
432 static void replyto_activated (GtkWidget *widget,
434 static void followupto_activated (GtkWidget *widget,
438 static void compose_attach_parts (Compose *compose,
441 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
443 gboolean ignore_replyto,
444 gboolean followup_and_reply_to);
446 void compose_headerentry_changed_cb (GtkWidget *entry,
447 ComposeHeaderEntry *headerentry);
448 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
450 ComposeHeaderEntry *headerentry);
452 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
455 static void compose_check_all (Compose *compose);
456 static void compose_highlight_all (Compose *compose);
457 static void compose_check_backwards (Compose *compose);
458 static void compose_check_forwards_go (Compose *compose);
461 static gboolean compose_send_control_enter (Compose *compose);
462 static void text_activated (GtkWidget *widget,
465 static GtkItemFactoryEntry compose_popup_entries[] =
467 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
468 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
469 {N_("/---"), NULL, NULL, 0, "<Separator>"},
470 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
473 static GtkItemFactoryEntry compose_entries[] =
475 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
476 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
477 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
478 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
479 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
480 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
482 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
483 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
484 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
485 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
486 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
487 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
488 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
489 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
490 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
491 {N_("/_Edit/A_dvanced/Move a character backward"),
493 compose_gtk_stext_action_cb,
494 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
496 {N_("/_Edit/A_dvanced/Move a character forward"),
498 compose_gtk_stext_action_cb,
499 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
501 {N_("/_Edit/A_dvanced/Move a word backward"),
503 compose_gtk_stext_action_cb,
504 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
506 {N_("/_Edit/A_dvanced/Move a word forward"),
508 compose_gtk_stext_action_cb,
509 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
511 {N_("/_Edit/A_dvanced/Move to beginning of line"),
512 NULL, /* "<control>A" */
513 compose_gtk_stext_action_cb,
514 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
516 {N_("/_Edit/A_dvanced/Move to end of line"),
518 compose_gtk_stext_action_cb,
519 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
521 {N_("/_Edit/A_dvanced/Move to previous line"),
523 compose_gtk_stext_action_cb,
524 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
526 {N_("/_Edit/A_dvanced/Move to next line"),
528 compose_gtk_stext_action_cb,
529 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
531 {N_("/_Edit/A_dvanced/Delete a character backward"),
533 compose_gtk_stext_action_cb,
534 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
536 {N_("/_Edit/A_dvanced/Delete a character forward"),
538 compose_gtk_stext_action_cb,
539 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
541 {N_("/_Edit/A_dvanced/Delete a word backward"),
542 NULL, /* "<control>W" */
543 compose_gtk_stext_action_cb,
544 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
546 {N_("/_Edit/A_dvanced/Delete a word forward"),
547 NULL, /* "<alt>D", */
548 compose_gtk_stext_action_cb,
549 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
551 {N_("/_Edit/A_dvanced/Delete line"),
553 compose_gtk_stext_action_cb,
554 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
556 {N_("/_Edit/A_dvanced/Delete entire line"),
558 compose_gtk_stext_action_cb,
559 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
561 {N_("/_Edit/A_dvanced/Delete to end of line"),
563 compose_gtk_stext_action_cb,
564 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
566 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
567 {N_("/_Edit/_Wrap current paragraph"),
568 "<control>L", compose_wrap_line, 0, NULL},
569 {N_("/_Edit/Wrap all long _lines"),
570 "<control><alt>L", compose_wrap_line_all, 0, NULL},
571 {N_("/_Edit/Edit with e_xternal editor"),
572 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
573 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
574 {N_("/_Edit/Actio_ns"), NULL, NULL, 0, "<Branch>"},
576 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
577 {N_("/_Spelling/_Check all or check selection"),
578 NULL, compose_check_all, 0, NULL},
579 {N_("/_Spelling/_Highlight all misspelled words"),
580 NULL, compose_highlight_all, 0, NULL},
581 {N_("/_Spelling/Check _backwards misspelled word"),
582 NULL, compose_check_backwards , 0, NULL},
583 {N_("/_Spelling/_Forward to next misspelled word"),
584 NULL, compose_check_forwards_go, 0, NULL},
585 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
586 {N_("/_Spelling/_Spelling Configuration"),
587 NULL, NULL, 0, "<Branch>"},
589 #if 0 /* NEW COMPOSE GUI */
590 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
591 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
592 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
593 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
594 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
595 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
596 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
597 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
598 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
599 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
600 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
602 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
603 {N_("/_Message/_Send"), "<control>Return",
604 compose_send_cb, 0, NULL},
605 {N_("/_Message/Send _later"), "<shift><control>S",
606 compose_send_later_cb, 0, NULL},
607 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
608 {N_("/_Message/Save to _draft folder"),
609 "<shift><control>D", compose_draft_cb, 0, NULL},
610 {N_("/_Message/Save and _keep editing"),
611 "<control>S", compose_draft_cb, 1, NULL},
612 #if 0 /* NEW COMPOSE GUI */
613 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
614 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
615 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
616 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
617 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
618 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
619 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
620 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
621 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
624 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
625 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
626 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
627 #endif /* USE_GPGME */
628 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
629 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
630 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
631 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
632 {N_("/_Tool/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
633 {N_("/_Tool/_Template"), NULL, NULL, 0, "<Branch>"},
634 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
635 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
638 static GtkTargetEntry compose_mime_types[] =
640 {"text/uri-list", 0, 0}
643 Compose *compose_new(PrefsAccount *account)
645 return compose_generic_new(account, NULL, NULL);
648 Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
652 GtkItemFactory *ifactory;
654 c = compose_generic_new(account, NULL, NULL);
656 filename = procmsg_get_message_file(msginfo);
657 if (filename == NULL)
660 c->bounce_filename = filename;
662 if (msginfo->subject)
663 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
665 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
667 compose_quote_fmt(c, msginfo, "%M", NULL);
668 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
670 ifactory = gtk_item_factory_from_widget(c->popupmenu);
671 menu_set_sensitive(ifactory, "/Add...", FALSE);
672 menu_set_sensitive(ifactory, "/Remove", FALSE);
673 menu_set_sensitive(ifactory, "/Property...", FALSE);
675 ifactory = gtk_item_factory_from_widget(c->menubar);
676 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
677 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
678 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
679 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
680 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
681 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
682 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
683 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
685 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
686 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
688 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
689 menu_set_sensitive(ifactory, "/Tool/Template", FALSE);
691 gtk_widget_set_sensitive(c->insert_btn, FALSE);
692 gtk_widget_set_sensitive(c->attach_btn, FALSE);
693 gtk_widget_set_sensitive(c->sig_btn, FALSE);
694 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
695 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
700 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
702 return compose_generic_new(account, mailto, NULL);
705 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
707 return compose_generic_new(account, NULL, item);
710 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
714 if (item && item->prefs && item->prefs->enable_default_account)
715 account = account_find_from_id(item->prefs->default_account);
717 if (!account) account = cur_account;
718 g_return_val_if_fail(account != NULL, NULL);
720 compose = compose_create(account, COMPOSE_NEW);
721 compose->replyinfo = NULL;
723 if (prefs_common.auto_sig)
724 compose_insert_sig(compose);
725 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
726 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
728 if (account->protocol != A_NNTP) {
730 compose_entries_set(compose, mailto);
732 } else if(item && item->prefs->enable_default_to) {
733 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
735 if (item && item->ret_rcpt) {
736 GtkItemFactory *ifactory;
738 ifactory = gtk_item_factory_from_widget(compose->menubar);
739 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
743 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
746 compose_show_first_last_header(compose, TRUE);
748 /* Set save folder */
749 if(item && item->prefs && item->prefs->save_copy_to_folder) {
750 gchar *folderidentifier;
752 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
753 folderidentifier = folder_item_get_identifier(item);
754 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
755 g_free(folderidentifier);
758 gtk_widget_grab_focus(compose->header_last->entry);
760 if (prefs_common.auto_exteditor)
761 compose_exec_ext_editor(compose);
766 #define CHANGE_FLAGS(msginfo) \
768 if (msginfo->folder->folder->change_flags != NULL) \
769 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
775 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
776 const gchar *followupto, gchar * to)
780 if (!account) account = cur_account;
781 g_return_val_if_fail(account != NULL, NULL);
782 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
784 compose = compose_create(account, COMPOSE_NEW);
786 if (prefs_common.auto_sig)
787 compose_insert_sig(compose);
788 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
789 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
791 compose_entry_append(compose, to, COMPOSE_TO);
792 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
793 gtk_widget_grab_focus(compose->subject_entry);
799 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
800 gboolean ignore_replyto)
802 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
805 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
807 gboolean ignore_replyto)
809 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
812 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
814 gboolean ignore_replyto,
815 gboolean followup_and_reply_to)
818 PrefsAccount *account;
819 PrefsAccount *reply_account;
822 g_return_if_fail(msginfo != NULL);
823 g_return_if_fail(msginfo->folder != NULL);
826 /* select the account set in folderitem's property (if enabled) */
827 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
828 account = account_find_from_id(msginfo->folder->prefs->default_account);
830 /* select the account for the whole folder (IMAP / NNTP) */
832 /* FIXME: this is not right, because folder may be nested. we should
833 * ascend the tree until we find a parent with proper account
835 account = msginfo->folder->folder->account;
837 /* select account by to: and cc: header if enabled */
838 if (prefs_common.reply_account_autosel) {
839 if (!account && msginfo->to) {
841 Xstrdup_a(to, msginfo->to, return);
843 account = account_find_from_address(to);
847 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
849 account = account_find_from_address(cc);
854 /* select current account */
855 if (!account) account = cur_account;
856 g_return_if_fail(account != NULL);
858 if (ignore_replyto && account->protocol == A_NNTP &&
859 !followup_and_reply_to) {
861 account_find_from_address(account->address);
863 reply_account = compose_current_mail_account();
867 reply_account = account;
869 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
870 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
871 if (MSG_IS_IMAP(msginfo->flags))
872 imap_msg_set_perm_flags(msginfo, MSG_REPLIED);
873 CHANGE_FLAGS(msginfo);
875 compose = compose_create(account, COMPOSE_REPLY);
876 compose->replyinfo = procmsg_msginfo_copy(msginfo);
878 #if 0 /* NEW COMPOSE GUI */
879 if (followup_and_reply_to) {
880 gtk_widget_show(compose->to_hbox);
881 gtk_widget_show(compose->to_entry);
882 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
883 compose->use_to = TRUE;
886 if (msginfo->folder && msginfo->folder->ret_rcpt) {
887 GtkItemFactory *ifactory;
889 ifactory = gtk_item_factory_from_widget(compose->menubar);
890 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
893 /* Set save folder */
894 if(msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
895 gchar *folderidentifier;
897 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
898 folderidentifier = folder_item_get_identifier(msginfo->folder);
899 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
900 g_free(folderidentifier);
903 if (compose_parse_header(compose, msginfo) < 0) return;
904 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
905 followup_and_reply_to);
906 compose_show_first_last_header(compose, TRUE);
908 text = GTK_STEXT(compose->text);
909 gtk_stext_freeze(text);
915 if (prefs_common.quotemark && *prefs_common.quotemark)
916 qmark = prefs_common.quotemark;
920 quote_str = compose_quote_fmt(compose, msginfo,
921 prefs_common.quotefmt,
925 if (prefs_common.auto_sig)
926 compose_insert_sig(compose);
928 if (quote && prefs_common.linewrap_quote)
929 compose_wrap_line_all(compose);
931 gtk_editable_set_position(GTK_EDITABLE(text), 0);
932 gtk_stext_set_point(text, 0);
934 gtk_stext_thaw(text);
935 gtk_widget_grab_focus(compose->text);
937 if (prefs_common.auto_exteditor)
938 compose_exec_ext_editor(compose);
942 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
947 g_return_val_if_fail(mimeinfo != NULL, NULL);
949 base = mimeinfo->filename ? mimeinfo->filename
950 : mimeinfo->name ? mimeinfo->name : NULL;
952 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
953 filename = g_strdup_printf("%s%smimetmp.%08x.html",
960 base = base ? base : "";
961 base = g_basename(base);
963 filename = g_strdup_printf("%s%smimetmp.%08x",
971 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
977 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
981 if (!partinfo) return NULL;
983 filename = procmime_get_file_name(partinfo);
985 if (procmime_get_part(filename, source, partinfo) < 0)
987 (_("Can't get the part of multipart message."));
992 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
1000 gint boundary_len = 0;
1001 gchar buf[BUFFSIZE];
1002 glong fpos, prev_fpos;
1007 g_return_if_fail(msginfo != NULL);
1011 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
1012 mimeinfo = procmime_scan_mime_header(fp, MIME_TEXT);
1013 if (!mimeinfo) break;
1015 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
1016 rfc2015_is_encrypted(mimeinfo)) {
1017 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
1019 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
1020 !msginfo->plaintext_file &&
1021 !msginfo->decryption_failed) {
1022 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
1023 if (msginfo->plaintext_file &&
1024 !msginfo->decryption_failed) {
1032 #else /* !USE_GPGME */
1033 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
1034 mimeinfo = procmime_scan_mime_header(fp, MIME_TEXT);
1035 #endif /* USE_GPGME */
1038 if (!mimeinfo) return;
1039 if (mimeinfo->mime_type == MIME_TEXT)
1042 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
1044 g_return_if_fail(mimeinfo != NULL);
1045 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
1047 if (mimeinfo->mime_type == MIME_MULTIPART) {
1048 g_return_if_fail(mimeinfo->boundary != NULL);
1049 g_return_if_fail(mimeinfo->sub == NULL);
1051 g_return_if_fail(fp != NULL);
1053 boundary = mimeinfo->boundary;
1056 boundary_len = strlen(boundary);
1058 /* look for first boundary */
1059 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
1060 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
1067 if ((fpos = ftell(fp)) < 0) {
1073 for (npart = 0;; npart++) {
1075 gboolean eom = FALSE;
1079 partinfo = procmime_scan_mime_header(fp, MIME_TEXT);
1080 if (!partinfo) break;
1083 procmime_mimeinfo_insert(mimeinfo, partinfo);
1085 procmime_mimeinfo_free(partinfo);
1087 /* look for next boundary */
1089 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
1090 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
1091 if (buf[2 + boundary_len] == '-' &&
1092 buf[2 + boundary_len + 1] == '-')
1098 eom = TRUE; /* broken MIME message */
1101 partinfo->size = fpos - prev_fpos - strlen(buf);
1106 source = procmsg_get_message_file_path(msginfo);
1108 g_return_if_fail(mimeinfo != NULL);
1110 if (!mimeinfo->main && mimeinfo->parent)
1112 filename = mime_extract_file(source, mimeinfo);
1114 compose_attach_append_with_type(compose, filename,
1115 mimeinfo->content_type,
1116 mimeinfo->mime_type);
1121 if (mimeinfo->sub && mimeinfo->sub->children)
1123 filename = mime_extract_file(source, mimeinfo->sub);
1125 compose_attach_append_with_type(compose, filename,
1126 mimeinfo->content_type,
1127 mimeinfo->sub->mime_type);
1132 if (mimeinfo->children) {
1135 child = mimeinfo->children;
1137 filename = mime_extract_file(source, child);
1139 compose_attach_append_with_type(compose, filename,
1140 child->content_type,
1145 child = child->next;
1151 procmime_mimeinfo_free_all(mimeinfo);
1155 #define INSERT_FW_HEADER(var, hdr) \
1156 if (msginfo->var && *msginfo->var) { \
1157 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1158 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1159 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1162 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1166 /* PrefsAccount *account; */
1169 g_return_val_if_fail(msginfo != NULL, NULL);
1170 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1172 account = msginfo->folder->folder->account;
1173 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1175 Xstrdup_a(to, msginfo->to, return NULL);
1176 extract_address(to);
1177 account = account_find_from_address(to);
1180 if(!account && prefs_common.forward_account_autosel) {
1182 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1183 extract_address(cc);
1184 account = account_find_from_address(cc);
1188 if (account == NULL) {
1189 account = cur_account;
1191 account = msginfo->folder->folder->account;
1192 if (!account) account = cur_account;
1195 g_return_val_if_fail(account != NULL, NULL);
1197 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1198 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1199 if (MSG_IS_IMAP(msginfo->flags))
1200 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1201 CHANGE_FLAGS(msginfo);
1203 compose = compose_create(account, COMPOSE_FORWARD);
1205 if (msginfo->subject && *msginfo->subject) {
1206 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1207 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1211 text = GTK_STEXT(compose->text);
1212 gtk_stext_freeze(text);
1217 msgfile = procmsg_get_message_file_path(msginfo);
1218 if (!is_file_exist(msgfile))
1219 g_warning(_("%s: file not exist\n"), msgfile);
1221 compose_attach_append(compose, msgfile,
1222 MIME_MESSAGE_RFC822);
1229 if (prefs_common.fw_quotemark && *prefs_common.fw_quotemark)
1230 qmark = prefs_common.fw_quotemark;
1234 quote_str = compose_quote_fmt(compose, msginfo,
1235 prefs_common.fw_quotefmt, qmark);
1236 compose_attach_parts(compose, msginfo);
1239 if (prefs_common.auto_sig)
1240 compose_insert_sig(compose);
1242 if (prefs_common.linewrap_quote)
1243 compose_wrap_line_all(compose);
1245 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1246 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1248 gtk_stext_thaw(text);
1249 #if 0 /* NEW COMPOSE GUI */
1250 if (account->protocol != A_NNTP)
1251 gtk_widget_grab_focus(compose->to_entry);
1253 gtk_widget_grab_focus(compose->newsgroups_entry);
1255 gtk_widget_grab_focus(compose->header_last->entry);
1257 if (prefs_common.auto_exteditor)
1258 compose_exec_ext_editor(compose);
1263 #undef INSERT_FW_HEADER
1265 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1272 g_return_val_if_fail(msginfo_list != NULL, NULL);
1274 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1275 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1279 if (account == NULL) {
1280 account = cur_account;
1282 account = msginfo->folder->folder->account;
1283 if (!account) account = cur_account;
1286 g_return_val_if_fail(account != NULL, NULL);
1288 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1289 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1290 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1291 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1294 compose = compose_create(account, COMPOSE_FORWARD);
1296 text = GTK_STEXT(compose->text);
1297 gtk_stext_freeze(text);
1299 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1300 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1301 if (!is_file_exist(msgfile))
1302 g_warning(_("%s: file not exist\n"), msgfile);
1304 compose_attach_append(compose, msgfile,
1305 MIME_MESSAGE_RFC822);
1309 if (prefs_common.auto_sig)
1310 compose_insert_sig(compose);
1312 if (prefs_common.linewrap_quote)
1313 compose_wrap_line_all(compose);
1315 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1316 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1318 gtk_stext_thaw(text);
1319 #if 0 /* NEW COMPOSE GUI */
1320 if (account->protocol != A_NNTP)
1321 gtk_widget_grab_focus(compose->to_entry);
1323 gtk_widget_grab_focus(compose->newsgroups_entry);
1329 void compose_reedit(MsgInfo *msginfo)
1332 PrefsAccount *account = NULL;
1335 gchar buf[BUFFSIZE];
1337 g_return_if_fail(msginfo != NULL);
1338 g_return_if_fail(msginfo->folder != NULL);
1340 if (msginfo->folder->stype == F_QUEUE) {
1341 gchar queueheader_buf[BUFFSIZE];
1344 /* Select Account from queue headers */
1345 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1346 sizeof(queueheader_buf), "NAID:")) {
1347 id = atoi(&queueheader_buf[5]);
1348 account = account_find_from_id(id);
1350 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1351 sizeof(queueheader_buf), "MAID:")) {
1352 id = atoi(&queueheader_buf[5]);
1353 account = account_find_from_id(id);
1355 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1356 sizeof(queueheader_buf), "S:")) {
1357 account = account_find_from_address(queueheader_buf);
1360 account = msginfo->folder->folder->account;
1362 if (!account && prefs_common.reedit_account_autosel) {
1363 gchar from[BUFFSIZE];
1364 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1365 extract_address(from);
1366 account = account_find_from_address(from);
1369 if (!account) account = cur_account;
1370 g_return_if_fail(account != NULL);
1372 compose = compose_create(account, COMPOSE_REEDIT);
1373 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1375 if (msginfo->folder->stype == F_QUEUE) {
1376 gchar queueheader_buf[BUFFSIZE];
1378 /* Set message save folder */
1379 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1382 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1383 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1384 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1388 if (compose_parse_header(compose, msginfo) < 0) return;
1389 compose_reedit_set_entry(compose, msginfo);
1391 text = GTK_STEXT(compose->text);
1392 gtk_stext_freeze(text);
1394 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1395 g_warning(_("Can't get text part\n"));
1397 while (fgets(buf, sizeof(buf), fp) != NULL)
1398 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1401 compose_attach_parts(compose, msginfo);
1403 gtk_stext_thaw(text);
1404 gtk_widget_grab_focus(compose->text);
1406 if (prefs_common.auto_exteditor)
1407 compose_exec_ext_editor(compose);
1410 GList *compose_get_compose_list(void)
1412 return compose_list;
1415 void compose_entry_append(Compose *compose, const gchar *address,
1416 ComposeEntryType type)
1422 if (!address || *address == '\0') return;
1424 #if 0 /* NEW COMPOSE GUI */
1427 entry = GTK_ENTRY(compose->cc_entry);
1430 entry = GTK_ENTRY(compose->bcc_entry);
1432 case COMPOSE_NEWSGROUPS:
1433 entry = GTK_ENTRY(compose->newsgroups_entry);
1437 entry = GTK_ENTRY(compose->to_entry);
1441 text = gtk_entry_get_text(entry);
1443 gtk_entry_append_text(entry, ", ");
1444 gtk_entry_append_text(entry, address);
1452 header = N_("Bcc:");
1454 case COMPOSE_REPLYTO:
1455 header = N_("Reply-To:");
1457 case COMPOSE_NEWSGROUPS:
1458 header = N_("Newsgroups:");
1460 case COMPOSE_FOLLOWUPTO:
1461 header = N_( "Followup-To:");
1468 header = prefs_common.trans_hdr ? gettext(header) : header;
1470 compose_add_header_entry(compose, header, (gchar *)address);
1473 static void compose_entries_set(Compose *compose, const gchar *mailto)
1475 gchar *subject = NULL;
1483 Xstrdup_a(tmp_mailto, mailto, return);
1487 p = strchr(tmp_mailto, '?');
1494 gchar *field, *value;
1511 if (*value == '\0') continue;
1513 if (!g_strcasecmp(field, "subject")) {
1514 Xalloca(subject, strlen(value) + 1, return);
1515 decode_uri(subject, value);
1516 } else if (!g_strcasecmp(field, "cc")) {
1518 } else if (!g_strcasecmp(field, "bcc")) {
1520 } else if (!g_strcasecmp(field, "body")) {
1521 Xalloca(body, strlen(value) + 1, return);
1522 decode_uri(body, value);
1527 compose_entry_append(compose, to, COMPOSE_TO);
1529 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1531 compose_entry_append(compose, cc, COMPOSE_CC);
1533 compose_entry_append(compose, bcc, COMPOSE_BCC);
1535 gtk_stext_insert(GTK_STEXT(compose->text),
1536 NULL, NULL, NULL, body, -1);
1537 gtk_stext_insert(GTK_STEXT(compose->text),
1538 NULL, NULL, NULL, "\n", 1);
1542 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1544 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1545 {"Cc:", NULL, FALSE},
1546 {"References:", NULL, FALSE},
1547 {"Bcc:", NULL, FALSE},
1548 {"Newsgroups:", NULL, FALSE},
1549 {"Followup-To:", NULL, FALSE},
1550 {"X-Mailing-List:", NULL, FALSE},
1551 {"X-BeenThere:", NULL, FALSE},
1552 {NULL, NULL, FALSE}};
1562 H_X_MAILING_LIST = 6,
1568 g_return_val_if_fail(msginfo != NULL, -1);
1570 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1571 procheader_get_header_fields(fp, hentry);
1574 if (hentry[H_REPLY_TO].body != NULL) {
1575 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1576 compose->replyto = hentry[H_REPLY_TO].body;
1577 hentry[H_REPLY_TO].body = NULL;
1579 if (hentry[H_CC].body != NULL) {
1580 conv_unmime_header_overwrite(hentry[H_CC].body);
1581 compose->cc = hentry[H_CC].body;
1582 hentry[H_CC].body = NULL;
1584 if (hentry[H_X_MAILING_LIST].body != NULL) {
1585 /* this is good enough to parse debian-devel */
1586 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1587 g_return_val_if_fail(buf != NULL, -1 );
1588 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1589 compose->mailinglist = g_strdup(buf);
1591 g_free(hentry[H_X_MAILING_LIST].body);
1592 hentry[H_X_MAILING_LIST].body = NULL ;
1594 if (hentry[H_X_BEENTHERE].body != NULL) {
1595 /* this is good enough to parse the sylpheed-claws lists */
1596 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1597 g_return_val_if_fail(buf != NULL, -1 );
1598 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1599 compose->mailinglist = g_strdup(buf);
1601 g_free(hentry[H_X_BEENTHERE].body);
1602 hentry[H_X_BEENTHERE].body = NULL ;
1604 if (hentry[H_REFERENCES].body != NULL) {
1605 if (compose->mode == COMPOSE_REEDIT)
1606 compose->references = hentry[H_REFERENCES].body;
1608 compose->references = compose_parse_references
1609 (hentry[H_REFERENCES].body, msginfo->msgid);
1610 g_free(hentry[H_REFERENCES].body);
1612 hentry[H_REFERENCES].body = NULL;
1614 if (hentry[H_BCC].body != NULL) {
1615 if (compose->mode == COMPOSE_REEDIT) {
1616 conv_unmime_header_overwrite(hentry[H_BCC].body);
1617 compose->bcc = hentry[H_BCC].body;
1619 g_free(hentry[H_BCC].body);
1620 hentry[H_BCC].body = NULL;
1622 if (hentry[H_NEWSGROUPS].body != NULL) {
1623 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1624 hentry[H_NEWSGROUPS].body = NULL;
1626 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1627 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1628 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1629 hentry[H_FOLLOWUP_TO].body = NULL;
1632 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1633 compose->inreplyto = g_strdup(msginfo->inreplyto);
1634 else if (compose->mode != COMPOSE_REEDIT &&
1635 msginfo->msgid && *msginfo->msgid) {
1636 compose->inreplyto = g_strdup(msginfo->msgid);
1638 if (!compose->references) {
1639 if (msginfo->inreplyto && *msginfo->inreplyto)
1640 compose->references =
1641 g_strdup_printf("<%s>\n\t<%s>",
1645 compose->references =
1646 g_strconcat("<", msginfo->msgid, ">",
1654 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1656 GSList *ref_id_list, *cur;
1660 ref_id_list = references_list_append(NULL, ref);
1661 if (!ref_id_list) return NULL;
1662 if (msgid && *msgid)
1663 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1668 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1669 /* "<" + Message-ID + ">" + CR+LF+TAB */
1670 len += strlen((gchar *)cur->data) + 5;
1672 if (len > MAX_REFERENCES_LEN) {
1673 /* remove second message-ID */
1674 if (ref_id_list && ref_id_list->next &&
1675 ref_id_list->next->next) {
1676 g_free(ref_id_list->next->data);
1677 ref_id_list = g_slist_remove
1678 (ref_id_list, ref_id_list->next->data);
1680 slist_free_strings(ref_id_list);
1681 g_slist_free(ref_id_list);
1688 new_ref = g_string_new("");
1689 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1690 if (new_ref->len > 0)
1691 g_string_append(new_ref, "\n\t");
1692 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1695 slist_free_strings(ref_id_list);
1696 g_slist_free(ref_id_list);
1698 new_ref_str = new_ref->str;
1699 g_string_free(new_ref, FALSE);
1704 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1705 const gchar *fmt, const gchar *qmark)
1707 GtkSText *text = GTK_STEXT(compose->text);
1708 gchar *quote_str = NULL;
1713 if (qmark != NULL) {
1714 quote_fmt_init(msginfo, NULL);
1715 quote_fmt_scan_string(qmark);
1718 buf = quote_fmt_get_buffer();
1720 alertpanel_error(_("Quote mark format error."));
1722 Xstrdup_a(quote_str, buf, return NULL)
1725 if (fmt && *fmt != '\0') {
1726 quote_fmt_init(msginfo, quote_str);
1727 quote_fmt_scan_string(fmt);
1730 buf = quote_fmt_get_buffer();
1732 alertpanel_error(_("Message reply/forward format error."));
1738 gtk_stext_freeze(text);
1740 for (p = buf; *p != '\0'; ) {
1741 lastp = strchr(p, '\n');
1742 len = lastp ? lastp - p + 1 : -1;
1743 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1750 gtk_stext_thaw(text);
1755 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1756 gboolean to_all, gboolean ignore_replyto,
1757 gboolean followup_and_reply_to)
1762 GHashTable *to_table;
1764 g_return_if_fail(compose->account != NULL);
1765 g_return_if_fail(msginfo != NULL);
1767 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1768 compose_entry_append(compose,
1769 ((compose->replyto && !ignore_replyto)
1771 : (compose->mailinglist && !ignore_replyto)
1772 ? compose->mailinglist
1773 : msginfo->from ? msginfo->from : ""),
1776 if (compose->replyto && to_all)
1777 compose_entry_append
1778 (compose, compose->replyto, COMPOSE_CC);
1781 if (compose->account->protocol == A_NNTP) {
1783 compose_entry_append
1784 (compose, msginfo->from ? msginfo->from : "",
1787 compose_entry_append
1789 compose->followup_to ? compose->followup_to
1790 : compose->newsgroups ? compose->newsgroups
1792 COMPOSE_NEWSGROUPS);
1795 if (msginfo->subject && *msginfo->subject) {
1796 gchar *buf, *buf2, *p;
1798 buf = g_strdup(msginfo->subject);
1799 while (!strncasecmp(buf, "Re:", 3)) {
1801 while (isspace(*p)) p++;
1802 memmove(buf, p, strlen(p) + 1);
1805 buf2 = g_strdup_printf("Re: %s", buf);
1806 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1810 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1812 if (!to_all || compose->account->protocol == A_NNTP) return;
1814 from = g_strdup(compose->replyto ? compose->replyto :
1815 msginfo->from ? msginfo->from : "");
1816 extract_address(from);
1818 cc_list = address_list_append(NULL, msginfo->to);
1819 cc_list = address_list_append(cc_list, compose->cc);
1821 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1822 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1823 if (compose->account)
1824 g_hash_table_insert(to_table, compose->account->address,
1825 GINT_TO_POINTER(1));
1827 /* remove address on To: and that of current account */
1828 for (cur = cc_list; cur != NULL; ) {
1829 GSList *next = cur->next;
1831 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1832 cc_list = g_slist_remove(cc_list, cur->data);
1834 g_hash_table_insert(to_table, cur->data, cur);
1838 g_hash_table_destroy(to_table);
1842 for (cur = cc_list; cur != NULL; cur = cur->next)
1843 compose_entry_append(compose, (gchar *)cur->data,
1845 slist_free_strings(cc_list);
1846 g_slist_free(cc_list);
1850 #define SET_ENTRY(entry, str) \
1853 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1856 #define SET_ADDRESS(type, str) \
1859 compose_entry_append(compose, str, type); \
1862 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1864 g_return_if_fail(msginfo != NULL);
1866 SET_ENTRY(subject_entry, msginfo->subject);
1867 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1868 SET_ADDRESS(COMPOSE_CC, compose->cc);
1869 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1870 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1872 compose_show_first_last_header(compose, TRUE);
1874 #if 0 /* NEW COMPOSE GUI */
1876 GtkItemFactory *ifactory;
1877 GtkWidget *menuitem;
1879 ifactory = gtk_item_factory_from_widget(compose->menubar);
1880 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1881 gtk_check_menu_item_set_active
1882 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1884 if (compose->replyto) {
1885 GtkItemFactory *ifactory;
1886 GtkWidget *menuitem;
1888 ifactory = gtk_item_factory_from_widget(compose->menubar);
1889 menuitem = gtk_item_factory_get_item
1890 (ifactory, "/View/Reply to");
1891 gtk_check_menu_item_set_active
1892 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1900 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1907 size_t buf_len = 128;
1909 if (strlen(sigfile) < 2)
1912 sigprg = popen(sigfile+1, "r");
1915 buf = g_malloc(buf_len);
1918 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1919 "Unable to insert signature (malloc failed)\n", -1);
1925 while (!feof(sigprg)) {
1926 bzero(buf, buf_len);
1927 fread(buf, buf_len-1, 1, sigprg);
1928 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1936 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1937 "Can't exec file: ", -1);
1938 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1943 static void compose_insert_sig(Compose *compose)
1947 if (compose->account && compose->account->sig_path)
1948 sigfile = g_strdup(compose->account->sig_path);
1950 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1951 DEFAULT_SIGNATURE, NULL);
1953 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1958 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1959 if (prefs_common.sig_sep) {
1960 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1961 prefs_common.sig_sep, -1);
1962 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1966 if (sigfile[0] == '|')
1967 compose_exec_sig(compose, sigfile);
1969 compose_insert_file(compose, sigfile);
1973 static void compose_insert_file(Compose *compose, const gchar *file)
1975 GtkSText *text = GTK_STEXT(compose->text);
1976 gchar buf[BUFFSIZE];
1980 g_return_if_fail(file != NULL);
1982 if ((fp = fopen(file, "r")) == NULL) {
1983 FILE_OP_ERROR(file, "fopen");
1987 gtk_stext_freeze(text);
1989 while (fgets(buf, sizeof(buf), fp) != NULL) {
1990 /* strip <CR> if DOS/Windows file,
1991 replace <CR> with <LF> if Macintosh file. */
1994 if (len > 0 && buf[len - 1] != '\n') {
1996 if (buf[len] == '\r') buf[len] = '\n';
1998 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
2001 gtk_stext_thaw(text);
2006 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
2007 ContentType cnttype)
2009 gchar *text[N_ATTACH_COLS];
2012 text[COL_MIMETYPE] = ainfo->content_type;
2013 text[COL_SIZE] = to_human_readable(ainfo->size);
2014 text[COL_NAME] = ainfo->name;
2016 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2017 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2019 if (cnttype != MIME_MESSAGE_RFC822)
2020 compose_changed_cb(NULL, compose);
2023 static void compose_attach_append_with_type(Compose *compose,
2026 ContentType cnttype)
2031 if (!is_file_exist(file)) {
2032 g_warning(_("File %s doesn't exist\n"), file);
2035 if ((size = get_file_size(file)) < 0) {
2036 g_warning(_("Can't get file size of %s\n"), file);
2040 alertpanel_notice(_("File %s is empty\n"), file);
2043 #if 0 /* NEW COMPOSE GUI */
2044 if (!compose->use_attach) {
2045 GtkItemFactory *ifactory;
2046 GtkWidget *menuitem;
2048 ifactory = gtk_item_factory_from_widget(compose->menubar);
2049 menuitem = gtk_item_factory_get_item(ifactory,
2051 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2055 ainfo = g_new0(AttachInfo, 1);
2056 ainfo->file = g_strdup(file);
2058 if (cnttype == MIME_MESSAGE_RFC822) {
2059 ainfo->encoding = ENC_7BIT;
2060 ainfo->name = g_strdup_printf(_("Message: %s"),
2063 ainfo->encoding = ENC_BASE64;
2064 ainfo->name = g_strdup(g_basename(file));
2067 ainfo->content_type = g_strdup(type);
2070 compose_attach_info(compose, ainfo, cnttype);
2073 static void compose_attach_append(Compose *compose, const gchar *file,
2074 ContentType cnttype)
2077 gchar *text[N_ATTACH_COLS];
2081 if (!is_file_exist(file)) {
2082 g_warning(_("File %s doesn't exist\n"), file);
2085 if ((size = get_file_size(file)) < 0) {
2086 g_warning(_("Can't get file size of %s\n"), file);
2090 alertpanel_notice(_("File %s is empty\n"), file);
2093 #if 0 /* NEW COMPOSE GUI */
2094 if (!compose->use_attach) {
2095 GtkItemFactory *ifactory;
2096 GtkWidget *menuitem;
2098 ifactory = gtk_item_factory_from_widget(compose->menubar);
2099 menuitem = gtk_item_factory_get_item(ifactory,
2100 "/View/Attachment");
2101 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2105 ainfo = g_new0(AttachInfo, 1);
2106 ainfo->file = g_strdup(file);
2108 if (cnttype == MIME_MESSAGE_RFC822) {
2109 ainfo->content_type = g_strdup("message/rfc822");
2110 ainfo->encoding = ENC_7BIT;
2111 ainfo->name = g_strdup_printf(_("Message: %s"),
2114 ainfo->content_type = procmime_get_mime_type(file);
2115 if (!ainfo->content_type)
2116 ainfo->content_type =
2117 g_strdup("application/octet-stream");
2118 ainfo->encoding = ENC_BASE64;
2119 ainfo->name = g_strdup(g_basename(file));
2123 compose_attach_info(compose, ainfo, cnttype);
2126 #define GET_CHAR(pos, buf, len) \
2128 if (text->use_wchar) \
2129 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2131 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2136 static void compose_wrap_line(Compose *compose)
2138 GtkSText *text = GTK_STEXT(compose->text);
2139 gint ch_len, last_ch_len;
2140 gchar cbuf[MB_LEN_MAX], last_ch;
2144 gint p_start, p_end;
2145 gint line_pos, cur_pos;
2146 gint line_len, cur_len;
2148 gtk_stext_freeze(text);
2150 text_len = gtk_stext_get_length(text);
2152 /* check to see if the point is on the paragraph mark (empty line). */
2153 cur_pos = gtk_stext_get_point(text);
2154 GET_CHAR(cur_pos, cbuf, ch_len);
2155 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2157 goto compose_end; /* on the paragraph mark */
2158 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2159 if (ch_len == 1 && *cbuf == '\n')
2160 goto compose_end; /* on the paragraph mark */
2163 /* find paragraph start. */
2164 line_end = quoted = 0;
2165 for (p_start = cur_pos; p_start >= 0; --p_start) {
2166 GET_CHAR(p_start, cbuf, ch_len);
2167 if (ch_len == 1 && *cbuf == '\n') {
2169 goto compose_end; /* quoted part */
2176 if (ch_len == 1 && strchr(">:#", *cbuf))
2178 else if (ch_len != 1 || !isspace(*cbuf))
2187 /* find paragraph end. */
2189 for (p_end = cur_pos; p_end < text_len; p_end++) {
2190 GET_CHAR(p_end, cbuf, ch_len);
2191 if (ch_len == 1 && *cbuf == '\n') {
2198 if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
2199 goto compose_end; /* quoted part */
2204 if (p_end >= text_len)
2207 if (p_start >= p_end)
2210 line_len = cur_len = 0;
2214 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2217 GET_CHAR(cur_pos, cbuf, ch_len);
2224 if (ch_len == 1 && isspace(*cbuf))
2227 if (ch_len == 1 && *cbuf == '\n') {
2229 if (last_ch_len == 1 && !isspace(last_ch)) {
2230 if (cur_pos + 1 < p_end) {
2231 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2232 if (ch_len == 1 && !isspace(*cbuf))
2236 gtk_stext_set_point(text, cur_pos + 1);
2237 gtk_stext_backward_delete(text, 1);
2239 gtk_stext_set_point(text, cur_pos);
2240 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2250 last_ch_len = ch_len;
2254 line_pos = cur_pos + 1;
2255 line_len = cur_len + ch_len;
2258 if (cur_len + ch_len > prefs_common.linewrap_len &&
2262 GET_CHAR(line_pos - 1, cbuf, ch_len);
2263 if (ch_len == 1 && isspace(*cbuf)) {
2264 gtk_stext_set_point(text, line_pos);
2265 gtk_stext_backward_delete(text, 1);
2274 gtk_stext_set_point(text, line_pos);
2275 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2279 cur_len = cur_len - line_len + ch_len;
2285 line_pos = cur_pos + 1;
2286 line_len = cur_len + ch_len;
2292 gtk_stext_thaw(text);
2295 /* return indent length */
2296 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2298 gint indent_len = 0;
2300 gchar cbuf[MB_LEN_MAX];
2302 for (i = start_pos; i < text_len; i++) {
2303 GET_CHAR(i, cbuf, ch_len);
2306 /* allow space, tab, > or | */
2307 if (cbuf[0] != ' ' && cbuf[0] != '\t' &&
2308 cbuf[0] != '>' && cbuf[0] != '|')
2316 /* insert quotation string when line was wrapped */
2317 static guint ins_quote(GtkSText *text, guint quote_len, guint indent_len,
2318 guint prev_line_pos, guint text_len,
2325 for (i = 0; i < indent_len; i++) {
2326 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2327 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2329 ins_len = indent_len;
2331 gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
2332 ins_len = quote_len;
2340 /* Darko: used when I debug wrapping */
2341 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2346 printf("%d [", pos);
2347 for (i = pos; i < tlen; i++) {
2348 ch = GTK_STEXT_INDEX(text, i);
2349 if (breakoncr && ch == '\n')
2357 static void compose_wrap_line_all(Compose *compose)
2359 GtkSText *text = GTK_STEXT(compose->text);
2361 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2362 gint line_len = 0, cur_len = 0;
2364 gboolean is_new_line = TRUE, do_delete = FALSE;
2365 guint qlen = 0, i_len = 0;
2366 gboolean linewrap_quote = TRUE;
2367 guint linewrap_len = prefs_common.linewrap_len;
2368 gchar *qfmt = prefs_common.quotemark;
2369 gchar cbuf[MB_LEN_MAX];
2371 gtk_stext_freeze(text);
2373 /* make text buffer contiguous */
2374 /* gtk_stext_compact_buffer(text); */
2376 tlen = gtk_stext_get_length(text);
2378 for (; cur_pos < tlen; cur_pos++) {
2379 /* mark position of new line - needed for quotation wrap */
2381 if (linewrap_quote) {
2382 qlen = gtkut_stext_str_compare
2383 (text, cur_pos, tlen, qfmt);
2385 i_len = get_indent_length
2386 (text, cur_pos, tlen);
2390 is_new_line = FALSE;
2393 printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
2394 dump_text(text, p_pos, tlen, 1);
2398 GET_CHAR(cur_pos, cbuf, ch_len);
2400 /* fix line length for tabs */
2401 if (ch_len == 1 && *cbuf == '\t') {
2402 guint tab_width = text->default_tab_width;
2403 guint tab_offset = line_len % tab_width;
2406 printf("found tab at pos=%d line_len=%d ", cur_pos,
2410 line_len += tab_width - tab_offset - 1;
2414 printf("new_len=%d\n", line_len);
2418 /* we have encountered line break */
2419 if (ch_len == 1 && *cbuf == '\n') {
2422 gchar cb[MB_CUR_MAX];
2425 printf("found CR at %d next line is ", cur_pos);
2426 dump_text(text, cur_pos + 1, tlen, 1);
2428 /* if it's just quotation + newline skip it */
2429 if (i_len && (cur_pos + 1 < tlen)) {
2430 /* check if text at new line matches indent */
2431 ilen = gtkut_stext_str_compare_n
2432 (text, cur_pos + 1, p_pos, i_len, tlen);
2433 if (cur_pos + ilen < tlen) {
2434 GET_CHAR(cur_pos + ilen + 1, cb, clen);
2435 /* no need to join the lines */
2436 if (clen == 1 && cb[0] == '\n')
2439 /* if it's just newline skip it */
2440 } else if (do_delete && (cur_pos + 1 < tlen)) {
2441 GET_CHAR(cur_pos + 1, cb, clen);
2442 /* no need to join the lines */
2443 if (clen == 1 && cb[0] == '\n')
2447 /* skip delete if it is continuous URL */
2448 if (do_delete && (line_pos - p_pos <= i_len) &&
2449 gtkut_stext_is_uri_string(text, line_pos, tlen))
2453 printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
2454 qlen, line_len, linewrap_len, do_delete);
2456 /* should we delete to perform smart wrapping */
2457 if (line_len < linewrap_len && do_delete) {
2458 /* get rid of newline */
2459 gtk_stext_set_point(text, cur_pos);
2460 gtk_stext_forward_delete(text, 1);
2463 /* if text starts with quote fmt or with
2464 indent string, delete them */
2466 ilen = gtkut_stext_str_compare_n
2467 (text, cur_pos, p_pos, i_len,
2470 gtk_stext_forward_delete
2475 if (gtkut_stext_str_compare
2476 (text, cur_pos, tlen, qfmt)) {
2477 gtk_stext_forward_delete
2483 GET_CHAR(cur_pos, cb, clen);
2485 /* insert space if it's alphanumeric */
2486 if ((cur_pos != line_pos) &&
2487 ((clen > 1) || isalnum(cb[0]))) {
2488 gtk_stext_insert(text, NULL, NULL,
2490 /* gtk_stext_compact_buffer(text); */
2494 /* and start over with current line */
2495 cur_pos = p_pos - 1;
2497 line_len = cur_len = 0;
2502 printf("after delete l_pos=");
2503 dump_text(text, line_pos, tlen, 1);
2508 /* mark new line beginning */
2509 line_pos = cur_pos + 1;
2510 line_len = cur_len = 0;
2522 /* possible line break */
2523 if (ch_len == 1 && isspace(*cbuf)) {
2524 line_pos = cur_pos + 1;
2525 line_len = cur_len + ch_len;
2528 /* are we over wrapping length set in preferences ? */
2529 if (cur_len + ch_len > linewrap_len) {
2533 printf("should wrap cur_pos=%d ", cur_pos);
2534 dump_text(text, p_pos, tlen, 1);
2535 dump_text(text, line_pos, tlen, 1);
2537 /* force wrapping if it is one long word but not URL */
2538 if (line_pos - p_pos <= i_len)
2539 if (!gtkut_stext_is_uri_string
2540 (text, line_pos, tlen))
2541 line_pos = cur_pos - 1;
2543 printf("new line_pos=%d\n", line_pos);
2546 GET_CHAR(line_pos - 1, cbuf, clen);
2548 /* if next character is space delete it */
2549 if (clen == 1 && isspace(*cbuf)) {
2550 if (p_pos + i_len != line_pos ||
2551 !gtkut_stext_is_uri_string
2552 (text, line_pos, tlen)) {
2553 gtk_stext_set_point(text, line_pos);
2554 gtk_stext_backward_delete(text, 1);
2563 /* if it is URL at beginning of line don't wrap */
2564 if (p_pos + i_len == line_pos &&
2565 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2567 printf("found URL at ");
2568 dump_text(text, line_pos, tlen, 1);
2574 gtk_stext_set_point(text, line_pos);
2575 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2576 /* gtk_stext_compact_buffer(text); */
2579 /* for loop will increase it */
2580 cur_pos = line_pos - 1;
2581 /* start over with current line */
2587 printf("after CR insert ");
2588 dump_text(text, line_pos, tlen, 1);
2589 dump_text(text, cur_pos, tlen, 1);
2592 /* should we insert quotation ? */
2593 if (linewrap_quote && qlen) {
2594 /* only if line is not already quoted */
2595 if (!gtkut_stext_str_compare
2596 (text, line_pos, tlen, qfmt)) {
2599 if (line_pos - p_pos > i_len) {
2604 /* gtk_stext_compact_buffer(text); */
2608 printf("after quote insert ");
2609 dump_text(text, line_pos, tlen, 1);
2617 line_pos = cur_pos + 1;
2618 line_len = cur_len + ch_len;
2620 /* advance to next character in buffer */
2624 gtk_stext_thaw(text);
2629 static void compose_set_title(Compose *compose)
2634 edited = compose->modified ? _(" [Edited]") : "";
2635 if (compose->account && compose->account->address)
2636 str = g_strdup_printf(_("%s - Compose message%s"),
2637 compose->account->address, edited);
2639 str = g_strdup_printf(_("Compose message%s"), edited);
2640 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2645 * compose_current_mail_account:
2647 * Find a current mail account (the currently selected account, or the
2648 * default account, if a news account is currently selected). If a
2649 * mail account cannot be found, display an error message.
2651 * Return value: Mail account, or NULL if not found.
2653 static PrefsAccount *
2654 compose_current_mail_account(void)
2658 if (cur_account && cur_account->protocol != A_NNTP)
2661 ac = account_get_default();
2662 if (!ac || ac->protocol == A_NNTP) {
2663 alertpanel_error(_("Account for sending mail is not specified.\n"
2664 "Please select a mail account before sending."));
2671 gboolean compose_check_for_valid_recipient(Compose *compose) {
2672 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2673 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2674 gboolean recipient_found = FALSE;
2678 /* free to and newsgroup list */
2679 slist_free_strings(compose->to_list);
2680 g_slist_free(compose->to_list);
2681 compose->to_list = NULL;
2683 slist_free_strings(compose->newsgroup_list);
2684 g_slist_free(compose->newsgroup_list);
2685 compose->newsgroup_list = NULL;
2687 /* search header entries for to and newsgroup entries */
2688 for(list = compose->header_list; list; list = list->next) {
2691 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2692 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2694 if(entry[0] != '\0') {
2695 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2696 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2697 compose->to_list = address_list_append(compose->to_list, entry);
2698 recipient_found = TRUE;
2701 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2702 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2703 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2704 recipient_found = TRUE;
2710 return recipient_found;
2713 gint compose_send(Compose *compose)
2719 val = compose_queue(compose, &msgnum, &folder);
2721 alertpanel_error(_("Could not queue message for sending"));
2725 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2727 folder_item_remove_msg(folder, msgnum);
2728 folderview_update_item(folder, TRUE);
2734 #if 0 /* compose restructure */
2735 gint compose_send(Compose *compose)
2737 gchar tmp[MAXPATHLEN + 1];
2739 static gboolean lock = FALSE;
2743 g_return_val_if_fail(compose->account != NULL, -1);
2744 g_return_val_if_fail(compose->orig_account != NULL, -1);
2748 if(!compose_check_for_valid_recipient(compose)) {
2749 alertpanel_error(_("Recipient is not specified."));
2754 /* write to temporary file */
2755 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2756 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2758 if (prefs_common.linewrap_at_send)
2759 compose_wrap_line_all(compose);
2761 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2766 if (!compose->to_list && !compose->newsgroup_list) {
2767 g_warning(_("can't get recipient list."));
2773 if (compose->to_list) {
2776 #if 0 /* NEW COMPOSE GUI */
2777 if (compose->account->protocol != A_NNTP)
2778 ac = compose->account;
2779 else if (compose->orig_account->protocol != A_NNTP)
2780 ac = compose->orig_account;
2781 else if (cur_account && cur_account->protocol != A_NNTP)
2784 ac = compose_current_mail_account();
2792 ac = compose->account;
2794 ok = send_message(tmp, ac, compose->to_list);
2795 statusbar_pop_all();
2798 if (ok == 0 && compose->newsgroup_list) {
2801 if (compose->account->protocol == A_NNTP)
2802 folder = FOLDER(compose->account->folder);
2804 folder = FOLDER(compose->orig_account->folder);
2806 ok = news_post(folder, tmp);
2808 alertpanel_error(_("Error occurred while posting the message to %s ."),
2809 compose->account->nntp_server);
2816 /* queue message if failed to send */
2818 if (prefs_common.queue_msg) {
2823 _("Error occurred while sending the message.\n"
2824 "Put this message into queue folder?"),
2825 _("OK"), _("Cancel"), NULL);
2826 if (G_ALERTDEFAULT == val) {
2827 ok = compose_queue(compose, tmp);
2829 alertpanel_error(_("Can't queue the message."));
2832 alertpanel_error(_("Error occurred while sending the message."));
2834 if (compose->mode == COMPOSE_REEDIT) {
2835 compose_remove_reedit_target(compose);
2836 if (compose->targetinfo)
2837 folderview_update_item
2838 (compose->targetinfo->folder, TRUE);
2842 /* save message to outbox */
2843 if (ok == 0 && prefs_common.savemsg) {
2844 if (compose_save_to_outbox(compose, tmp) < 0)
2846 (_("Can't save the message to outbox."));
2855 static gboolean compose_use_attach(Compose *compose) {
2856 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2859 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2862 gchar buf[BUFFSIZE];
2864 gboolean first_address;
2866 ComposeHeaderEntry *headerentry;
2867 gchar *headerentryname;
2868 gchar *header_w_colon;
2872 debug_print(_("Writing bounce header\n"));
2874 header_w_colon = g_strconcat("To:", NULL);
2875 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2876 header_w_colon = g_strconcat("Cc:", NULL);
2877 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2879 first_address = TRUE;
2880 for(list = compose->header_list; list; list = list->next) {
2881 headerentry = ((ComposeHeaderEntry *)list->data);
2882 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2884 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2885 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2886 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2887 Xstrdup_a(str, str, return -1);
2889 if(str[0] != '\0') {
2890 compose_convert_header
2891 (buf, sizeof(buf), str,
2892 strlen("Resent-To") + 2);
2894 fprintf(fp, "Resent-To: ");
2895 first_address = FALSE;
2899 fprintf(fp, "%s", buf);
2903 /* if(!first_address) { */
2910 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2912 gchar buf[BUFFSIZE];
2914 /* struct utsname utsbuf; */
2916 g_return_val_if_fail(fp != NULL, -1);
2917 g_return_val_if_fail(compose->account != NULL, -1);
2918 g_return_val_if_fail(compose->account->address != NULL, -1);
2921 get_rfc822_date(buf, sizeof(buf));
2922 fprintf(fp, "Resent-Date: %s\n", buf);
2925 if (compose->account->name && *compose->account->name) {
2926 compose_convert_header
2927 (buf, sizeof(buf), compose->account->name,
2929 fprintf(fp, "Resent-From: %s <%s>\n",
2930 buf, compose->account->address);
2932 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2935 compose_bounce_write_headers_from_headerlist(compose, fp);
2937 /* separator between header and body */
2943 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2948 gchar buf[BUFFSIZE];
2950 if ((fp = fopen(compose->bounce_filename, "r")) == NULL) {
2951 FILE_OP_ERROR(file, "fopen");
2955 if ((fdest = fopen(file, "w")) == NULL) {
2956 FILE_OP_ERROR(file, "fopen");
2961 /* chmod for security */
2962 if (change_file_mode_rw(fdest, file) < 0) {
2963 FILE_OP_ERROR(file, "chmod");
2964 g_warning(_("can't change file mode\n"));
2967 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2968 /* should filter returnpath, delivered-to */
2969 if ((g_strncasecmp(buf, "Return-Path:",
2970 strlen("Return-Path:")) == 0)
2971 || (g_strncasecmp(buf, "Delivered-To:",
2972 strlen("Delivered-To:")) == 0))
2975 if (fputs(buf, fdest) == -1)
2978 if (g_strncasecmp(buf, "From:", strlen("From:")) == 0) {
2979 fputs(" (by way of ", fdest);
2980 if (compose->account->name
2981 && *compose->account->name) {
2982 compose_convert_header
2984 compose->account->name,
2986 fprintf(fdest, "%s <%s>",
2987 buf, compose->account->address);
2989 fprintf(fdest, "%s",
2990 compose->account->address);
2994 if (fputs("\n", fdest) == -1)
2998 compose_bounce_write_headers(compose, fdest);
3000 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
3001 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
3019 * interfaces to rfc2015 to keep out the prefs stuff there.
3020 * returns 0 on success and -1 on error. */
3021 static int compose_create_signers_list (Compose *compose, GSList **pkey_list)
3023 const char *keyid = NULL;
3026 switch (compose->account->sign_key) {
3027 case SIGN_KEY_DEFAULT:
3029 return 0; /* nothing to do */
3031 case SIGN_KEY_BY_FROM:
3032 keyid = compose->account->address;
3035 case SIGN_KEY_CUSTOM:
3036 keyid = compose->account->sign_key_id;
3040 g_assert_not_reached ();
3043 key_list = rfc2015_create_signers_list(keyid);
3046 alertpanel_error("Could not find any key associated with currently "
3047 "selected keyid `%s'!", keyid);
3051 *pkey_list = key_list;
3054 #endif /* USE_GPGME */
3056 static gint compose_write_to_file(Compose *compose, const gchar *file,
3063 const gchar *out_codeset;
3064 EncodingType encoding;
3066 if ((fp = fopen(file, "w")) == NULL) {
3067 FILE_OP_ERROR(file, "fopen");
3071 /* chmod for security */
3072 if (change_file_mode_rw(fp, file) < 0) {
3073 FILE_OP_ERROR(file, "chmod");
3074 g_warning(_("can't change file mode\n"));
3077 /* get all composed text */
3078 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3079 len = strlen(chars);
3080 if (is_ascii_str(chars)) {
3081 buf = g_strdup(chars);
3082 out_codeset = CS_US_ASCII;
3083 encoding = ENC_7BIT;
3085 const gchar *src_codeset;
3087 out_codeset = conv_get_outgoing_charset_str();
3088 if (!strcasecmp(out_codeset, CS_US_ASCII))
3089 out_codeset = CS_ISO_8859_1;
3090 encoding = procmime_get_encoding_for_charset(out_codeset);
3092 src_codeset = conv_get_current_charset_str();
3093 /* if current encoding is US-ASCII, set it the same as
3094 outgoing one to prevent code conversion failure */
3095 if (!strcasecmp(src_codeset, CS_US_ASCII))
3096 src_codeset = out_codeset;
3098 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3099 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3101 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3106 alertpanel_error(_("Can't convert the codeset of the message."));
3113 if (compose_write_headers
3114 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3115 g_warning(_("can't write headers\n"));
3122 if (compose_use_attach(compose)) {
3124 /* This prolog message is ignored by mime software and
3125 * because it would make our signing/encryption task
3126 * tougher, we don't emit it in that case */
3127 if (!compose->use_signing && !compose->use_encryption)
3129 fputs("This is a multi-part message in MIME format.\n", fp);
3131 fprintf(fp, "\n--%s\n", compose->boundary);
3132 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3134 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3135 procmime_get_encoding_str(encoding));
3141 if (encoding == ENC_BASE64) {
3142 gchar outbuf[B64_BUFFSIZE];
3145 for (i = 0; i < len; i += B64_LINE_SIZE) {
3146 l = MIN(B64_LINE_SIZE, len - i);
3147 to64frombits(outbuf, buf + i, l);
3151 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3152 FILE_OP_ERROR(file, "fwrite");
3160 if (compose_use_attach(compose))
3161 compose_write_attach(compose, fp);
3163 if (fclose(fp) == EOF) {
3164 FILE_OP_ERROR(file, "fclose");
3170 if (compose->use_signing) {
3173 if (compose_create_signers_list(compose, &key_list) == -1 ||
3174 rfc2015_sign(file, key_list) < 0) {
3180 if (compose->use_encryption) {
3181 if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) {
3186 #endif /* USE_GPGME */
3191 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3197 if ((fp = fopen(file, "w")) == NULL) {
3198 FILE_OP_ERROR(file, "fopen");
3202 /* chmod for security */
3203 if (change_file_mode_rw(fp, file) < 0) {
3204 FILE_OP_ERROR(file, "chmod");
3205 g_warning(_("can't change file mode\n"));
3208 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3211 len = strlen(chars);
3212 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3213 FILE_OP_ERROR(file, "fwrite");
3222 if (fclose(fp) == EOF) {
3223 FILE_OP_ERROR(file, "fclose");
3230 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
3237 debug_print(_("saving sent message...\n"));
3239 outbox = folder_get_default_outbox();
3240 path = folder_item_get_path(outbox);
3241 if (!is_dir_exist(path))
3242 make_dir_hier(path);
3244 folder_item_scan(outbox);
3245 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
3247 g_warning(_("can't save message\n"));
3251 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
3252 g_warning(_("can't open mark file\n"));
3256 newmsginfo.msgnum = num;
3257 newmsginfo.flags.perm_flags = 0;
3258 newmsginfo.flags.tmp_flags = 0;
3259 procmsg_write_flags(&newmsginfo, fp);
3267 static gint compose_remove_reedit_target(Compose *compose)
3270 MsgInfo *msginfo = compose->targetinfo;
3272 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3273 if (!msginfo) return -1;
3275 item = msginfo->folder;
3276 g_return_val_if_fail(item != NULL, -1);
3278 folder_item_scan(item);
3279 if (procmsg_msg_exist(msginfo) &&
3280 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3281 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3282 g_warning(_("can't remove the old message\n"));
3291 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3294 gchar *tmp, *tmp2, *queue_path;
3297 gchar buf[BUFFSIZE];
3299 static gboolean lock = FALSE;
3300 PrefsAccount *mailac = NULL, *newsac = NULL;
3302 debug_print(_("queueing message...\n"));
3303 g_return_val_if_fail(compose->account != NULL, -1);
3304 g_return_val_if_fail(compose->orig_account != NULL, -1);
3308 if(!compose_check_for_valid_recipient(compose)) {
3309 alertpanel_error(_("Recipient is not specified."));
3314 if (!compose->to_list && !compose->newsgroup_list) {
3315 g_warning(_("can't get recipient list."));
3320 if(compose->to_list) {
3321 if (compose->account->protocol != A_NNTP)
3322 mailac = compose->account;
3323 else if (compose->orig_account->protocol != A_NNTP)
3324 mailac = compose->orig_account;
3325 else if (cur_account && cur_account->protocol != A_NNTP)
3326 mailac = cur_account;
3327 else if (!(mailac = compose_current_mail_account())) {
3329 alertpanel_error(_("No account for sending mails available!"));
3334 if(compose->newsgroup_list) {
3335 if (compose->account->protocol == A_NNTP)
3336 newsac = compose->account;
3337 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3339 alertpanel_error(_("No account for posting news available!"));
3344 if (prefs_common.linewrap_at_send)
3345 compose_wrap_line_all(compose);
3347 /* write to temporary file */
3348 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3349 G_DIR_SEPARATOR, (gint)compose);
3351 if (compose->bounce_filename != NULL) {
3352 if (compose_bounce_write_to_file(compose, tmp2) < 0) {
3359 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3366 /* add queue header */
3367 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3368 G_DIR_SEPARATOR, (gint)compose);
3369 if ((fp = fopen(tmp, "w")) == NULL) {
3370 FILE_OP_ERROR(tmp, "fopen");
3374 if ((src_fp = fopen(tmp2, "r")) == NULL) {
3375 FILE_OP_ERROR(tmp2, "fopen");
3383 if (change_file_mode_rw(fp, tmp) < 0) {
3384 FILE_OP_ERROR(tmp, "chmod");
3385 g_warning(_("can't change file mode\n"));
3388 /* queueing variables */
3389 fprintf(fp, "AF:\n");
3390 fprintf(fp, "NF:0\n");
3391 fprintf(fp, "PS:10\n");
3392 fprintf(fp, "SRH:1\n");
3393 fprintf(fp, "SFN:\n");
3394 fprintf(fp, "DSR:\n");
3396 fprintf(fp, "MID:<%s>\n", compose->msgid);
3398 fprintf(fp, "MID:\n");
3399 fprintf(fp, "CFG:\n");
3400 fprintf(fp, "PT:0\n");
3401 fprintf(fp, "S:%s\n", compose->account->address);
3402 fprintf(fp, "RQ:\n");
3404 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3406 fprintf(fp, "SSV:\n");
3408 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3410 fprintf(fp, "NSV:\n");
3411 fprintf(fp, "SSH:\n");
3412 /* write recepient list */
3414 if(compose->to_list) {
3415 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3416 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3417 fprintf(fp, ",<%s>", (gchar *)cur->data);
3420 /* write newsgroup list */
3422 if(compose->newsgroup_list) {
3423 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3424 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3425 fprintf(fp, ",%s", (gchar *)cur->data);
3428 /* Sylpheed account IDs */
3430 fprintf(fp, "MAID:%d\n", mailac->account_id);
3433 fprintf(fp, "NAID:%d\n", newsac->account_id);
3435 /* Save copy folder */
3436 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3439 str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3440 fprintf(fp, "SCF:%s\n", str);
3445 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3446 if (fputs(buf, fp) == EOF) {
3447 FILE_OP_ERROR(tmp, "fputs");
3458 if (fclose(fp) == EOF) {
3459 FILE_OP_ERROR(tmp, "fclose");
3468 queue = folder_get_default_queue();
3470 folder_item_scan(queue);
3471 queue_path = folder_item_get_path(queue);
3472 if (!is_dir_exist(queue_path))
3473 make_dir_hier(queue_path);
3474 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3475 g_warning(_("can't queue the message\n"));
3486 if (compose->mode == COMPOSE_REEDIT) {
3487 compose_remove_reedit_target(compose);
3488 if (compose->targetinfo &&
3489 compose->targetinfo->folder != queue)
3490 folderview_update_item
3491 (compose->targetinfo->folder, TRUE);
3494 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
3495 g_warning(_("can't open mark file\n"));
3499 newmsginfo.msgnum = num;
3500 newmsginfo.flags.perm_flags = 0;
3501 newmsginfo.flags.tmp_flags = 0;
3502 procmsg_write_flags(&newmsginfo, fp);
3507 folder_item_scan(queue);
3508 folderview_update_item(queue, TRUE);
3510 if((msgnum != NULL) && (item != NULL)) {
3518 static void compose_write_attach(Compose *compose, FILE *fp)
3521 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3524 gchar filename[BUFFSIZE];
3527 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3529 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
3530 g_warning(_("Can't open file %s\n"), ainfo->file);
3534 fprintf(fp, "\n--%s\n", compose->boundary);
3536 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3537 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3538 fprintf(fp, "Content-Disposition: inline\n");
3540 conv_encode_header(filename, sizeof(filename),
3542 fprintf(fp, "Content-Type: %s;\n"
3544 ainfo->content_type, filename);
3545 fprintf(fp, "Content-Disposition: attachment;\n"
3546 " filename=\"%s\"\n", filename);
3549 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3550 procmime_get_encoding_str(ainfo->encoding));
3552 if (ainfo->encoding == ENC_7BIT) {
3553 gchar buf[BUFFSIZE];
3555 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3560 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3562 while ((len = fread(inbuf, sizeof(gchar),
3563 B64_LINE_SIZE, attach_fp))
3565 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3569 if (len > 0 && feof(attach_fp)) {
3570 to64frombits(outbuf, inbuf, len);
3579 fprintf(fp, "\n--%s--\n", compose->boundary);
3582 #define IS_IN_CUSTOM_HEADER(header) \
3583 (compose->account->add_customhdr && \
3584 custom_header_find(compose->account->customhdr_list, header) != NULL)
3586 static gint compose_write_headers_from_headerlist(Compose *compose,
3590 gchar buf[BUFFSIZE];
3591 gchar *str, *header_w_colon, *trans_hdr;
3592 gboolean first_address;
3594 ComposeHeaderEntry *headerentry;
3595 gchar * headerentryname;
3597 if (IS_IN_CUSTOM_HEADER(header)) {
3601 debug_print(_("Writing %s-header\n"), header);
3603 header_w_colon = g_strconcat(header, ":", NULL);
3604 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3606 first_address = TRUE;
3607 for(list = compose->header_list; list; list = list->next) {
3608 headerentry = ((ComposeHeaderEntry *)list->data);
3609 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3611 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3612 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3613 Xstrdup_a(str, str, return -1);
3615 if(str[0] != '\0') {
3616 compose_convert_header
3617 (buf, sizeof(buf), str,
3618 strlen(header) + 2);
3620 fprintf(fp, "%s: ", header);
3621 first_address = FALSE;
3625 fprintf(fp, "%s", buf);
3629 if(!first_address) {
3633 g_free(header_w_colon);
3638 static gint compose_write_headers(Compose *compose, FILE *fp,
3639 const gchar *charset, EncodingType encoding,
3642 gchar buf[BUFFSIZE];
3644 /* struct utsname utsbuf; */
3646 g_return_val_if_fail(fp != NULL, -1);
3647 g_return_val_if_fail(charset != NULL, -1);
3648 g_return_val_if_fail(compose->account != NULL, -1);
3649 g_return_val_if_fail(compose->account->address != NULL, -1);
3652 if (compose->account->add_date) {
3653 get_rfc822_date(buf, sizeof(buf));
3654 fprintf(fp, "Date: %s\n", buf);
3658 if (!IS_IN_CUSTOM_HEADER("From")) {
3659 if (compose->account->name && *compose->account->name) {
3660 compose_convert_header
3661 (buf, sizeof(buf), compose->account->name,
3663 fprintf(fp, "From: %s <%s>\n",
3664 buf, compose->account->address);
3666 fprintf(fp, "From: %s\n", compose->account->address);
3670 compose_write_headers_from_headerlist(compose, fp, "To");
3671 #if 0 /* NEW COMPOSE GUI */
3672 if (compose->use_to) {
3673 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3675 Xstrdup_a(str, str, return -1);
3678 compose->to_list = address_list_append
3679 (compose->to_list, str);
3680 if (!IS_IN_CUSTOM_HEADER("To")) {
3681 compose_convert_header
3682 (buf, sizeof(buf), str,
3684 fprintf(fp, "To: %s\n", buf);
3692 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3693 #if 0 /* NEW COMPOSE GUI */
3694 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3696 Xstrdup_a(str, str, return -1);
3700 compose->newsgroup_list =
3701 newsgroup_list_append(compose->newsgroup_list,
3703 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3704 compose_convert_header(buf, sizeof(buf), str,
3705 strlen("Newsgroups: "));
3706 fprintf(fp, "Newsgroups: %s\n", buf);
3712 compose_write_headers_from_headerlist(compose, fp, "Cc");
3713 #if 0 /* NEW COMPOSE GUI */
3714 if (compose->use_cc) {
3715 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3717 Xstrdup_a(str, str, return -1);
3720 compose->to_list = address_list_append
3721 (compose->to_list, str);
3722 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3723 compose_convert_header
3724 (buf, sizeof(buf), str,
3726 fprintf(fp, "Cc: %s\n", buf);
3733 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3734 #if 0 /* NEW COMPOSE GUI */
3735 if (compose->use_bcc) {
3736 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3738 Xstrdup_a(str, str, return -1);
3741 compose->to_list = address_list_append
3742 (compose->to_list, str);
3743 compose_convert_header(buf, sizeof(buf), str,
3745 fprintf(fp, "Bcc: %s\n", buf);
3752 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3753 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3754 Xstrdup_a(str, str, return -1);
3757 compose_convert_header(buf, sizeof(buf), str,
3758 strlen("Subject: "));
3759 fprintf(fp, "Subject: %s\n", buf);
3764 if (compose->account->gen_msgid) {
3765 compose_generate_msgid(compose, buf, sizeof(buf));
3766 fprintf(fp, "Message-Id: <%s>\n", buf);
3767 compose->msgid = g_strdup(buf);
3771 if (compose->inreplyto && compose->to_list)
3772 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3775 if (compose->references)
3776 fprintf(fp, "References: %s\n", compose->references);
3779 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3780 #if 0 /* NEW COMPOSE GUI */
3781 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3782 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3784 Xstrdup_a(str, str, return -1);
3788 compose_convert_header(buf, sizeof(buf), str,
3789 strlen("Followup-To: "));
3790 fprintf(fp, "Followup-To: %s\n", buf);
3796 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3797 #if 0 /* NEW COMPOSE GUI */
3798 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3799 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3801 Xstrdup_a(str, str, return -1);
3804 compose_convert_header(buf, sizeof(buf), str,
3805 strlen("Reply-To: "));
3806 fprintf(fp, "Reply-To: %s\n", buf);
3812 if (compose->account->organization &&
3813 !IS_IN_CUSTOM_HEADER("Organization")) {
3814 compose_convert_header(buf, sizeof(buf),
3815 compose->account->organization,
3816 strlen("Organization: "));
3817 fprintf(fp, "Organization: %s\n", buf);
3820 /* Program version and system info */
3821 /* uname(&utsbuf); */
3822 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3823 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3825 gtk_major_version, gtk_minor_version, gtk_micro_version,
3827 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3829 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3830 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3832 gtk_major_version, gtk_minor_version, gtk_micro_version,
3834 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3837 /* custom headers */
3838 if (compose->account->add_customhdr) {
3841 for (cur = compose->account->customhdr_list; cur != NULL;
3843 CustomHeader *chdr = (CustomHeader *)cur->data;
3845 if (strcasecmp(chdr->name, "Date") != 0 &&
3846 strcasecmp(chdr->name, "From") != 0 &&
3847 strcasecmp(chdr->name, "To") != 0 &&
3848 /* strcasecmp(chdr->name, "Sender") != 0 && */
3849 strcasecmp(chdr->name, "Message-Id") != 0 &&
3850 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3851 strcasecmp(chdr->name, "References") != 0 &&
3852 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3853 strcasecmp(chdr->name, "Content-Type") != 0 &&
3854 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3856 compose_convert_header
3858 chdr->value ? chdr->value : "",
3859 strlen(chdr->name) + 2);
3860 fprintf(fp, "%s: %s\n", chdr->name, buf);
3866 fprintf(fp, "Mime-Version: 1.0\n");
3867 if (compose_use_attach(compose)) {
3868 get_rfc822_date(buf, sizeof(buf));
3869 subst_char(buf, ' ', '_');
3870 subst_char(buf, ',', '_');
3871 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3872 buf, (guint)compose);
3874 "Content-Type: multipart/mixed;\n"
3875 " boundary=\"%s\"\n", compose->boundary);
3877 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3878 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3879 procmime_get_encoding_str(encoding));
3882 /* Request Return Receipt */
3883 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3884 if (compose->return_receipt) {
3885 if (compose->account->name
3886 && *compose->account->name) {
3887 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3888 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3890 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3894 /* separator between header and body */
3900 #undef IS_IN_CUSTOM_HEADER
3902 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3905 g_return_if_fail(src != NULL);
3906 g_return_if_fail(dest != NULL);
3908 if (len < 1) return;
3912 if (is_ascii_str(src)) {
3913 strncpy2(dest, src, len);
3914 dest[len - 1] = '\0';
3917 conv_encode_header(dest, len, src, header_len);
3920 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3929 if (compose->account && compose->account->address &&
3930 *compose->account->address) {
3931 if (strchr(compose->account->address, '@'))
3932 addr = g_strdup(compose->account->address);
3934 addr = g_strconcat(compose->account->address, "@",
3935 get_domain_name(), NULL);
3937 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3940 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3941 lt->tm_year + 1900, lt->tm_mon + 1,
3942 lt->tm_mday, lt->tm_hour,
3943 lt->tm_min, lt->tm_sec,
3944 (guint)random(), addr);
3946 debug_print(_("generated Message-ID: %s\n"), buf);
3951 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3952 GtkWidget **entry, gint *count,
3953 const gchar *label_str,
3954 gboolean is_addr_entry)
3958 if (GTK_TABLE(table)->nrows < (*count) + 1)
3959 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3961 *hbox = gtk_hbox_new(FALSE, 0);
3962 label = gtk_label_new
3963 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3964 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3965 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3967 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3969 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3970 #if 0 /* NEW COMPOSE GUI */
3971 if (GTK_TABLE(table)->nrows > (*count) + 1)
3972 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3976 address_completion_register_entry(GTK_ENTRY(*entry));
3981 static void compose_create_header_entry(Compose *compose)
3983 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3987 GList *combo_list = NULL;
3988 gchar **string, *header;
3989 ComposeHeaderEntry *headerentry;
3991 headerentry = g_new0(ComposeHeaderEntry, 1);
3994 combo = gtk_combo_new();
3996 while(*string != NULL) {
3997 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4000 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4001 g_list_free(combo_list);
4002 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
4003 gtk_widget_show(combo);
4004 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4005 if(compose->header_last) {
4006 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4008 switch(compose->account->protocol) {
4010 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4013 header = prefs_common.trans_hdr ? _("To:") : "To:";
4017 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4020 entry = gtk_entry_new();
4021 gtk_widget_show(entry);
4022 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);
4024 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4025 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4026 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4028 address_completion_register_entry(GTK_ENTRY(entry));
4030 headerentry->compose = compose;
4031 headerentry->combo = combo;
4032 headerentry->entry = entry;
4033 headerentry->headernum = compose->header_nextrow;
4035 compose->header_nextrow++;
4036 compose->header_last = headerentry;
4039 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4041 ComposeHeaderEntry *last_header;
4043 last_header = compose->header_last;
4045 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4046 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4049 static GtkWidget *compose_create_header(Compose *compose)
4053 GtkWidget *from_optmenu_hbox;
4054 #if 0 /* NEW COMPOSE GUI */
4055 GtkWidget *to_entry;
4057 GtkWidget *newsgroups_entry;
4058 GtkWidget *newsgroups_hbox;
4060 GtkWidget *header_scrolledwin;
4061 GtkWidget *header_table;
4062 #if 0 /* NEW COMPOSE GUI */
4063 GtkWidget *cc_entry;
4065 GtkWidget *bcc_entry;
4066 GtkWidget *bcc_hbox;
4067 GtkWidget *reply_entry;
4068 GtkWidget *reply_hbox;
4069 GtkWidget *followup_entry;
4070 GtkWidget *followup_hbox;
4075 /* header labels and entries */
4076 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4077 gtk_widget_show(header_scrolledwin);
4078 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4080 header_table = gtk_table_new(2, 2, FALSE);
4081 gtk_widget_show(header_table);
4082 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4083 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4084 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4087 /* option menu for selecting accounts */
4088 hbox = gtk_hbox_new(FALSE, 0);
4089 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4090 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4091 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4093 from_optmenu_hbox = compose_account_option_menu_create(compose);
4094 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4095 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4096 #if 0 /* NEW COMPOSE GUI */
4097 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4101 compose->header_table = header_table;
4102 compose->header_list = NULL;
4103 compose->header_nextrow = count;
4105 compose_create_header_entry(compose);
4107 #if 0 /* NEW COMPOSE GUI */
4108 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4110 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4111 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4112 &count, "Newsgroups:", FALSE);
4113 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4115 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4117 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4119 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4120 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4122 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4123 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4125 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4126 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4127 "Followup-To:", FALSE);
4128 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4130 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4132 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4133 GTK_SIGNAL_FUNC(to_activated), compose);
4134 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4135 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4136 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4137 GTK_SIGNAL_FUNC(subject_activated), compose);
4138 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4139 GTK_SIGNAL_FUNC(cc_activated), compose);
4140 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4141 GTK_SIGNAL_FUNC(bcc_activated), compose);
4142 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4143 GTK_SIGNAL_FUNC(replyto_activated), compose);
4144 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4145 GTK_SIGNAL_FUNC(followupto_activated), compose);
4147 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4148 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4149 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4150 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4151 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4152 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4153 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4154 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4155 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4156 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4157 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4158 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4159 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4160 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4163 compose->table = NULL;
4164 #if 0 /* NEW COMPOSE GUI */
4165 compose->table = table;
4166 compose->to_hbox = to_hbox;
4167 compose->to_entry = to_entry;
4168 compose->newsgroups_hbox = newsgroups_hbox;
4169 compose->newsgroups_entry = newsgroups_entry;
4171 #if 0 /* NEW COMPOSE GUI */
4172 compose->cc_hbox = cc_hbox;
4173 compose->cc_entry = cc_entry;
4174 compose->bcc_hbox = bcc_hbox;
4175 compose->bcc_entry = bcc_entry;
4176 compose->reply_hbox = reply_hbox;
4177 compose->reply_entry = reply_entry;
4178 compose->followup_hbox = followup_hbox;
4179 compose->followup_entry = followup_entry;
4182 return header_scrolledwin ;
4185 GtkWidget *compose_create_attach(Compose *compose)
4187 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
4190 GtkWidget *attach_scrwin;
4191 GtkWidget *attach_clist;
4193 /* attachment list */
4194 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4195 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4196 GTK_POLICY_AUTOMATIC,
4198 gtk_widget_set_usize(attach_scrwin, -1, 80);
4200 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4201 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4203 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4204 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4205 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4206 GTK_SELECTION_EXTENDED);
4207 for (i = 0; i < N_ATTACH_COLS; i++)
4208 GTK_WIDGET_UNSET_FLAGS
4209 (GTK_CLIST(attach_clist)->column[i].button,
4211 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4213 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4214 GTK_SIGNAL_FUNC(attach_selected), compose);
4215 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4216 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4217 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4218 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4221 gtk_drag_dest_set(attach_clist,
4222 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4224 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4225 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4228 compose->attach_scrwin = attach_scrwin;
4229 compose->attach_clist = attach_clist;
4231 return attach_scrwin;
4234 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4235 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4237 static GtkWidget *compose_create_others(Compose *compose)
4240 GtkWidget *savemsg_checkbtn;
4241 GtkWidget *savemsg_entry;
4242 GtkWidget *savemsg_select;
4245 gchar *folderidentifier;
4247 /* Table for settings */
4248 table = gtk_table_new(3, 1, FALSE);
4249 gtk_widget_show(table);
4250 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4253 /* Save Message to folder */
4254 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4255 gtk_widget_show(savemsg_checkbtn);
4256 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4257 if(folder_get_default_outbox()) {
4258 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4260 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4261 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4263 savemsg_entry = gtk_entry_new();
4264 gtk_widget_show(savemsg_entry);
4265 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4266 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4267 if(folder_get_default_outbox()) {
4268 folderidentifier = folder_item_get_identifier(folder_get_default_outbox());
4269 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4270 g_free(folderidentifier);
4273 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4274 gtk_widget_show (savemsg_select);
4275 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4276 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4277 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4282 compose->savemsg_checkbtn = savemsg_checkbtn;
4283 compose->savemsg_entry = savemsg_entry;
4288 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4290 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4291 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4294 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4299 dest = foldersel_folder_sel(NULL, NULL);
4302 path = folder_item_get_identifier(dest);
4304 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4308 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4314 GtkWidget *handlebox;
4316 GtkWidget *notebook;
4321 GtkWidget *subject_hbox;
4322 GtkWidget *subject_frame;
4323 GtkWidget *subject_entry;
4327 GtkWidget *edit_vbox;
4328 GtkWidget *ruler_hbox;
4330 GtkWidget *scrolledwin;
4335 UndoMain *undostruct;
4337 guint n_menu_entries;
4338 GtkStyle *style, *new_style;
4341 gboolean success[1];
4343 GtkWidget *popupmenu;
4344 GtkWidget *menuitem;
4345 GtkItemFactory *popupfactory;
4346 GtkItemFactory *ifactory;
4347 GtkWidget *tmpl_menu;
4351 GtkPspell * gtkpspell = NULL;
4354 g_return_val_if_fail(account != NULL, NULL);
4356 debug_print(_("Creating compose window...\n"));
4357 compose = g_new0(Compose, 1);
4359 compose->account = account;
4360 compose->orig_account = account;
4362 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4363 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4364 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4365 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4366 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4367 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4368 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4369 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4370 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
4371 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
4372 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
4373 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
4374 gtk_widget_realize(window);
4376 gtkut_widget_set_composer_icon(window);
4378 vbox = gtk_vbox_new(FALSE, 0);
4379 gtk_container_add(GTK_CONTAINER(window), vbox);
4381 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4382 menubar = menubar_create(window, compose_entries,
4383 n_menu_entries, "<Compose>", compose);
4384 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4386 handlebox = gtk_handle_box_new();
4387 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4389 compose_toolbar_create(compose, handlebox);
4391 vbox2 = gtk_vbox_new(FALSE, 2);
4392 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4393 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4396 notebook = gtk_notebook_new();
4397 gtk_widget_set_usize(notebook, -1, 130);
4398 gtk_widget_show(notebook);
4400 /* header labels and entries */
4401 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4402 /* attachment list */
4403 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4405 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4408 subject_hbox = gtk_hbox_new(FALSE, 0);
4409 gtk_widget_show(subject_hbox);
4411 subject_frame = gtk_frame_new(NULL);
4412 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4413 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4414 gtk_widget_show(subject_frame);
4416 subject = gtk_hbox_new(FALSE, 0);
4417 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4418 gtk_widget_show(subject);
4420 label = gtk_label_new(_("Subject:"));
4421 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4422 gtk_widget_show(label);
4424 subject_entry = gtk_entry_new();
4425 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4426 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4427 gtk_widget_show(subject_entry);
4428 compose->subject_entry = subject_entry;
4429 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4431 edit_vbox = gtk_vbox_new(FALSE, 0);
4432 #if 0 /* NEW COMPOSE GUI */
4433 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4436 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4439 ruler_hbox = gtk_hbox_new(FALSE, 0);
4440 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4442 ruler = gtk_shruler_new();
4443 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4444 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4446 gtk_widget_set_usize(ruler_hbox, 1, -1);
4449 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4450 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4451 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4452 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4453 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4455 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4456 (GTK_SCROLLED_WINDOW(scrolledwin)),
4457 gtk_scrolled_window_get_vadjustment
4458 (GTK_SCROLLED_WINDOW(scrolledwin)));
4459 GTK_STEXT(text)->default_tab_width = 8;
4460 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4462 if (prefs_common.block_cursor) {
4463 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4466 if (prefs_common.smart_wrapping) {
4467 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4468 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4471 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4473 gtk_signal_connect(GTK_OBJECT(text), "changed",
4474 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4475 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4476 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4477 gtk_signal_connect(GTK_OBJECT(text), "activate",
4478 GTK_SIGNAL_FUNC(text_activated), compose);
4479 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4480 GTK_SIGNAL_FUNC(compose_button_press_cb),
4483 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4484 GTK_SIGNAL_FUNC(compose_key_press_cb),
4487 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4488 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4492 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4494 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4495 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4497 gtk_widget_show_all(vbox);
4499 /* pane between attach clist and text */
4500 paned = gtk_vpaned_new();
4501 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4502 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4503 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4504 gtk_paned_add1(GTK_PANED(paned), notebook);
4505 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4506 gtk_widget_show_all(paned);
4508 style = gtk_widget_get_style(text);
4510 /* workaround for the slow down of GtkSText when using Pixmap theme */
4511 if (style->engine) {
4512 GtkThemeEngine *engine;
4514 engine = style->engine;
4515 style->engine = NULL;
4516 new_style = gtk_style_copy(style);
4517 style->engine = engine;
4519 new_style = gtk_style_copy(style);
4521 if (prefs_common.textfont) {
4524 charset = conv_get_current_charset();
4525 if (MB_CUR_MAX == 1) {
4528 Xstrdup_a(fontstr, prefs_common.textfont, );
4529 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4531 font = gdk_font_load(fontstr);
4533 font = gdk_fontset_load(prefs_common.textfont);
4535 gdk_font_unref(new_style->font);
4536 new_style->font = font;
4540 gtk_widget_set_style(text, new_style);
4542 color[0] = quote_color;
4543 cmap = gdk_window_get_colormap(window->window);
4544 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4545 if (success[0] == FALSE) {
4546 g_warning("Compose: color allocation failed.\n");
4547 style = gtk_widget_get_style(text);
4548 quote_color = style->black;
4551 n_entries = sizeof(compose_popup_entries) /
4552 sizeof(compose_popup_entries[0]);
4553 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4554 "<Compose>", &popupfactory,
4557 ifactory = gtk_item_factory_from_widget(menubar);
4558 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4559 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4561 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tool/Template");
4562 #if 0 /* NEW COMPOSE GUI */
4563 gtk_widget_hide(bcc_hbox);
4564 gtk_widget_hide(bcc_entry);
4565 gtk_widget_hide(reply_hbox);
4566 gtk_widget_hide(reply_entry);
4567 gtk_widget_hide(followup_hbox);
4568 gtk_widget_hide(followup_entry);
4569 gtk_widget_hide(ruler_hbox);
4570 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4571 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4572 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4574 if (account->protocol == A_NNTP) {
4575 gtk_widget_hide(to_hbox);
4576 gtk_widget_hide(to_entry);
4577 gtk_widget_hide(cc_hbox);
4578 gtk_widget_hide(cc_entry);
4579 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4580 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4582 gtk_widget_hide(newsgroups_hbox);
4583 gtk_widget_hide(newsgroups_entry);
4584 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4585 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
4589 update_compose_actions_menu(ifactory, "/Edit/Actions", compose);
4591 switch (prefs_common.toolbar_style) {
4593 gtk_widget_hide(handlebox);
4596 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4600 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4604 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4609 undostruct = undo_init(text);
4610 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4613 gtk_widget_show(window);
4615 address_completion_start(window);
4617 compose->window = window;
4618 compose->vbox = vbox;
4619 compose->menubar = menubar;
4620 compose->handlebox = handlebox;
4622 compose->vbox2 = vbox2;
4624 compose->paned = paned;
4626 compose->edit_vbox = edit_vbox;
4627 compose->ruler_hbox = ruler_hbox;
4628 compose->ruler = ruler;
4629 compose->scrolledwin = scrolledwin;
4630 compose->text = text;
4632 compose->focused_editable = NULL;
4634 compose->popupmenu = popupmenu;
4635 compose->popupfactory = popupfactory;
4637 compose->tmpl_menu = tmpl_menu;
4639 compose->mode = mode;
4641 compose->targetinfo = NULL;
4642 compose->replyinfo = NULL;
4644 compose->replyto = NULL;
4645 compose->mailinglist = NULL;
4647 compose->bcc = NULL;
4648 compose->followup_to = NULL;
4649 compose->inreplyto = NULL;
4650 compose->references = NULL;
4651 compose->msgid = NULL;
4652 compose->boundary = NULL;
4655 compose->use_signing = FALSE;
4656 compose->use_encryption = FALSE;
4657 #endif /* USE_GPGME */
4659 compose->modified = FALSE;
4661 compose->return_receipt = FALSE;
4663 compose->to_list = NULL;
4664 compose->newsgroup_list = NULL;
4666 compose->exteditor_file = NULL;
4667 compose->exteditor_pid = -1;
4668 compose->exteditor_readdes = -1;
4669 compose->exteditor_tag = -1;
4671 compose->bounce_filename = NULL;
4672 compose->undostruct = undostruct;
4675 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4676 if (prefs_common.enable_pspell) {
4677 gtkpspell = gtkpspell_new((const gchar*)prefs_common.dictionary,
4678 conv_get_current_charset_str(),
4679 prefs_common.misspelled_col,
4680 prefs_common.check_while_typing,
4683 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkpspellcheckers->error_message);
4684 gtkpspell_checkers_reset_error();
4687 GtkWidget *menuitem;
4689 if (!gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode)) {
4690 debug_print(_("Pspell: could not set suggestion mode %s"),
4691 gtkpspellcheckers->error_message);
4692 gtkpspell_checkers_reset_error();
4695 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
4696 gtkpspell_populate_submenu(gtkpspell, menuitem);
4697 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4702 compose_set_title(compose);
4704 #if 0 /* NEW COMPOSE GUI */
4705 compose->use_bcc = FALSE;
4706 compose->use_replyto = FALSE;
4707 compose->use_followupto = FALSE;
4711 compose->gtkpspell = gtkpspell;
4714 #if 0 /* NEW COMPOSE GUI */
4715 if (account->protocol != A_NNTP) {
4716 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
4717 gtk_check_menu_item_set_active
4718 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4719 gtk_widget_set_sensitive(menuitem, FALSE);
4720 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4721 gtk_check_menu_item_set_active
4722 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4723 gtk_widget_set_sensitive(menuitem, FALSE);
4726 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4727 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4728 #if 0 /* NEW COMPOSE GUI */
4729 compose->use_cc = TRUE;
4730 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4731 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4732 gtk_check_menu_item_set_active
4733 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4736 if (account->set_autobcc) {
4737 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4738 #if 0 /* NEW COMPOSE GUI */
4739 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
4740 gtk_check_menu_item_set_active
4741 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4742 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4743 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4747 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4748 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4749 #if 0 /* NEW COMPOSE GUI */
4750 compose->use_replyto = TRUE;
4751 menuitem = gtk_item_factory_get_item(ifactory,
4753 gtk_check_menu_item_set_active
4754 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4755 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4756 account->auto_replyto);
4760 if (account->protocol != A_NNTP) {
4761 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4763 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4766 #if 0 /* NEW COMPOSE GUI */
4767 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
4768 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4769 prefs_common.show_ruler);
4773 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4774 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4775 account->default_sign);
4776 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4777 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4778 account->default_encrypt);
4779 #endif /* USE_GPGME */
4781 addressbook_set_target_compose(compose);
4782 compose_set_template_menu(compose);
4784 compose_list = g_list_append(compose_list, compose);
4786 #if 0 /* NEW COMPOSE GUI */
4787 compose->use_to = FALSE;
4788 compose->use_cc = FALSE;
4789 compose->use_attach = TRUE;
4792 #if 0 /* NEW COMPOSE GUI */
4793 if (!compose->use_bcc) {
4794 gtk_widget_hide(bcc_hbox);
4795 gtk_widget_hide(bcc_entry);
4796 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4798 if (!compose->use_replyto) {
4799 gtk_widget_hide(reply_hbox);
4800 gtk_widget_hide(reply_entry);
4801 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4803 if (!compose->use_followupto) {
4804 gtk_widget_hide(followup_hbox);
4805 gtk_widget_hide(followup_entry);
4806 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4809 if (!prefs_common.show_ruler)
4810 gtk_widget_hide(ruler_hbox);
4812 select_account(compose, account);
4817 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4820 GtkWidget *icon_wid;
4821 GtkWidget *send_btn;
4822 GtkWidget *sendl_btn;
4823 GtkWidget *draft_btn;
4824 GtkWidget *insert_btn;
4825 GtkWidget *attach_btn;
4827 GtkWidget *exteditor_btn;
4828 GtkWidget *linewrap_btn;
4829 GtkWidget *addrbook_btn;
4831 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4833 gtk_container_add(GTK_CONTAINER(container), toolbar);
4834 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4835 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4836 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4837 GTK_TOOLBAR_SPACE_LINE);
4839 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
4840 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4844 icon_wid, toolbar_send_cb, compose);
4846 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND_QUEUE);
4847 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4849 _("Put into queue folder and send later"),
4851 icon_wid, toolbar_send_later_cb,
4854 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4855 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4857 _("Save to draft folder"),
4859 icon_wid, toolbar_draft_cb,
4862 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4864 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_PASTE);
4865 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4869 icon_wid, toolbar_insert_cb,
4872 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_ATTACH);
4873 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4877 icon_wid, toolbar_attach_cb,
4880 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4882 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4883 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4885 _("Insert signature"),
4887 icon_wid, toolbar_sig_cb, compose);
4889 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4891 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_COMPOSE);
4892 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4894 _("Edit with external editor"),
4897 toolbar_ext_editor_cb,
4900 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_LINEWRAP);
4901 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4903 _("Wrap all long lines"),
4906 toolbar_linewrap_cb,
4909 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4911 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_ADDRESS_BOOK);
4912 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4916 icon_wid, toolbar_address_cb,
4919 compose->toolbar = toolbar;
4920 compose->send_btn = send_btn;
4921 compose->sendl_btn = sendl_btn;
4922 compose->draft_btn = draft_btn;
4923 compose->insert_btn = insert_btn;
4924 compose->attach_btn = attach_btn;
4925 compose->sig_btn = sig_btn;
4926 compose->exteditor_btn = exteditor_btn;
4927 compose->linewrap_btn = linewrap_btn;
4928 compose->addrbook_btn = addrbook_btn;
4930 gtk_widget_show_all(toolbar);
4933 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4939 gint num = 0, def_menu = 0;
4941 accounts = account_get_list();
4942 g_return_val_if_fail(accounts != NULL, NULL);
4944 hbox = gtk_hbox_new(FALSE, 0);
4945 optmenu = gtk_option_menu_new();
4946 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4947 menu = gtk_menu_new();
4949 for (; accounts != NULL; accounts = accounts->next, num++) {
4950 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4951 GtkWidget *menuitem;
4954 if (ac == compose->account) def_menu = num;
4956 name = g_strdup_printf("%s: %s <%s>",
4957 ac->account_name, ac->name, ac->address);
4958 MENUITEM_ADD(menu, menuitem, name, ac);
4960 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4961 GTK_SIGNAL_FUNC(account_activated),
4965 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4966 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4971 static void compose_set_template_menu(Compose *compose)
4973 GSList *tmpl_list, *cur;
4977 tmpl_list = template_get_config();
4979 menu = gtk_menu_new();
4981 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4982 Template *tmpl = (Template *)cur->data;
4984 item = gtk_menu_item_new_with_label(tmpl->name);
4985 gtk_menu_append(GTK_MENU(menu), item);
4986 gtk_signal_connect(GTK_OBJECT(item), "activate",
4987 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4989 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4990 gtk_widget_show(item);
4993 gtk_widget_show(menu);
4994 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4997 void compose_reflect_prefs_all(void)
5002 for (cur = compose_list; cur != NULL; cur = cur->next) {
5003 compose = (Compose *)cur->data;
5004 compose_set_template_menu(compose);
5008 static void compose_template_apply(Compose *compose, Template *tmpl)
5013 if (!tmpl || !tmpl->value) return;
5015 gtk_stext_freeze(GTK_STEXT(compose->text));
5017 if (tmpl->subject && *tmpl->subject != '\0')
5018 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5020 if (tmpl->to && *tmpl->to != '\0')
5021 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5023 gtk_stext_clear(GTK_STEXT(compose->text));
5025 if (compose->replyinfo == NULL) {
5028 memset(&dummyinfo, 0, sizeof(MsgInfo));
5029 parsed_str = compose_quote_fmt(compose, &dummyinfo,
5032 if (prefs_common.quotemark && *prefs_common.quotemark)
5033 qmark = prefs_common.quotemark;
5037 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5038 tmpl->value, qmark);
5041 if (parsed_str && prefs_common.auto_sig)
5042 compose_insert_sig(compose);
5044 gtk_stext_thaw(GTK_STEXT(compose->text));
5047 static void compose_destroy(Compose *compose)
5050 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5053 /* NOTE: address_completion_end() does nothing with the window
5054 * however this may change. */
5055 address_completion_end(compose->window);
5057 slist_free_strings(compose->to_list);
5058 g_slist_free(compose->to_list);
5059 slist_free_strings(compose->newsgroup_list);
5060 g_slist_free(compose->newsgroup_list);
5061 slist_free_strings(compose->header_list);
5062 g_slist_free(compose->header_list);
5064 procmsg_msginfo_free(compose->targetinfo);
5065 procmsg_msginfo_free(compose->replyinfo);
5067 g_free(compose->replyto);
5068 g_free(compose->cc);
5069 g_free(compose->bcc);
5070 g_free(compose->newsgroups);
5071 g_free(compose->followup_to);
5073 g_free(compose->inreplyto);
5074 g_free(compose->references);
5075 g_free(compose->msgid);
5076 g_free(compose->boundary);
5078 if (compose->bounce_filename)
5079 g_free(compose->bounce_filename);
5081 g_free(compose->exteditor_file);
5083 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5085 compose_attach_info_free(ainfo);
5087 if (addressbook_get_target_compose() == compose)
5088 addressbook_set_target_compose(NULL);
5091 if (compose->gtkpspell) {
5092 gtkpspell_delete(compose->gtkpspell);
5096 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5097 prefs_common.compose_height = compose->window->allocation.height;
5099 gtk_widget_destroy(compose->paned);
5103 compose_list = g_list_remove(compose_list, compose);
5106 static void compose_attach_info_free(AttachInfo *ainfo)
5108 g_free(ainfo->file);
5109 g_free(ainfo->content_type);
5110 g_free(ainfo->name);
5114 static void compose_attach_remove_selected(Compose *compose)
5116 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5120 while (clist->selection != NULL) {
5121 row = GPOINTER_TO_INT(clist->selection->data);
5122 ainfo = gtk_clist_get_row_data(clist, row);
5123 compose_attach_info_free(ainfo);
5124 gtk_clist_remove(clist, row);
5128 static struct _AttachProperty
5131 GtkWidget *mimetype_entry;
5132 GtkWidget *encoding_optmenu;
5133 GtkWidget *path_entry;
5134 GtkWidget *filename_entry;
5136 GtkWidget *cancel_btn;
5139 static void compose_attach_property(Compose *compose)
5141 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5144 GtkOptionMenu *optmenu;
5145 static gboolean cancelled;
5147 if (!clist->selection) return;
5148 row = GPOINTER_TO_INT(clist->selection->data);
5150 ainfo = gtk_clist_get_row_data(clist, row);
5153 if (!attach_prop.window)
5154 compose_attach_property_create(&cancelled);
5155 gtk_widget_grab_focus(attach_prop.ok_btn);
5156 gtk_widget_show(attach_prop.window);
5157 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5159 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5160 if (ainfo->encoding == ENC_UNKNOWN)
5161 gtk_option_menu_set_history(optmenu, ENC_BASE64);
5163 gtk_option_menu_set_history(optmenu, ainfo->encoding);
5165 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5166 ainfo->content_type ? ainfo->content_type : "");
5167 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5168 ainfo->file ? ainfo->file : "");
5169 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5170 ainfo->name ? ainfo->name : "");
5174 gchar *cnttype = NULL;
5178 GtkWidget *menuitem;
5183 if (cancelled == TRUE) {
5184 gtk_widget_hide(attach_prop.window);
5188 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5189 if (*text != '\0') {
5192 text = g_strstrip(g_strdup(text));
5193 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5194 cnttype = g_strdup(text);
5197 alertpanel_error(_("Invalid MIME type."));
5203 menu = gtk_option_menu_get_menu(optmenu);
5204 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5205 ainfo->encoding = GPOINTER_TO_INT
5206 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5208 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5209 if (*text != '\0') {
5210 if (is_file_exist(text) &&
5211 (size = get_file_size(text)) > 0)
5212 file = g_strdup(text);
5215 (_("File doesn't exist or is empty."));
5221 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5222 if (*text != '\0') {
5223 g_free(ainfo->name);
5224 ainfo->name = g_strdup(text);
5228 g_free(ainfo->content_type);
5229 ainfo->content_type = cnttype;
5232 g_free(ainfo->file);
5238 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5239 ainfo->content_type);
5240 gtk_clist_set_text(clist, row, COL_SIZE,
5241 to_human_readable(ainfo->size));
5242 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5244 gtk_widget_hide(attach_prop.window);
5249 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5251 label = gtk_label_new(str); \
5252 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5253 GTK_FILL, 0, 0, 0); \
5254 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5256 entry = gtk_entry_new(); \
5257 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5258 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5261 static void compose_attach_property_create(gboolean *cancelled)
5267 GtkWidget *mimetype_entry;
5270 GtkWidget *optmenu_menu;
5271 GtkWidget *menuitem;
5272 GtkWidget *path_entry;
5273 GtkWidget *filename_entry;
5276 GtkWidget *cancel_btn;
5277 GList *mime_type_list, *strlist;
5279 debug_print("Creating attach_property window...\n");
5281 window = gtk_window_new(GTK_WINDOW_DIALOG);
5282 gtk_widget_set_usize(window, 480, -1);
5283 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5284 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
5285 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5286 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5287 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5288 GTK_SIGNAL_FUNC(attach_property_delete_event),
5290 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5291 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5294 vbox = gtk_vbox_new(FALSE, 8);
5295 gtk_container_add(GTK_CONTAINER(window), vbox);
5297 table = gtk_table_new(4, 2, FALSE);
5298 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5299 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5300 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5302 label = gtk_label_new(_("MIME type"));
5303 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5305 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5306 mimetype_entry = gtk_combo_new();
5307 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5308 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5310 /* stuff with list */
5311 mime_type_list = procmime_get_mime_type_list();
5313 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5314 MimeType *type = (MimeType *) mime_type_list->data;
5315 strlist = g_list_append(strlist,
5316 g_strdup_printf("%s/%s",
5317 type->type, type->sub_type));
5320 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5322 for (mime_type_list = strlist; mime_type_list != NULL;
5323 mime_type_list = mime_type_list->next)
5324 g_free(mime_type_list->data);
5325 g_list_free(strlist);
5327 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5329 label = gtk_label_new(_("Encoding"));
5330 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5332 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5334 hbox = gtk_hbox_new(FALSE, 0);
5335 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5336 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5338 optmenu = gtk_option_menu_new();
5339 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5341 optmenu_menu = gtk_menu_new();
5342 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5343 gtk_widget_set_sensitive(menuitem, FALSE);
5344 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5345 gtk_widget_set_sensitive(menuitem, FALSE);
5346 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5347 gtk_widget_set_sensitive(menuitem, FALSE);
5348 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5350 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5352 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5353 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5355 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5356 &cancel_btn, _("Cancel"), NULL, NULL);
5357 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5358 gtk_widget_grab_default(ok_btn);
5360 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5361 GTK_SIGNAL_FUNC(attach_property_ok),
5363 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5364 GTK_SIGNAL_FUNC(attach_property_cancel),
5367 gtk_widget_show_all(vbox);
5369 attach_prop.window = window;
5370 attach_prop.mimetype_entry = mimetype_entry;
5371 attach_prop.encoding_optmenu = optmenu;
5372 attach_prop.path_entry = path_entry;
5373 attach_prop.filename_entry = filename_entry;
5374 attach_prop.ok_btn = ok_btn;
5375 attach_prop.cancel_btn = cancel_btn;
5378 #undef SET_LABEL_AND_ENTRY
5380 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5386 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5392 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5393 gboolean *cancelled)
5401 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5402 gboolean *cancelled)
5404 if (event && event->keyval == GDK_Escape) {
5410 static void compose_exec_ext_editor(Compose *compose)
5416 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5417 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5419 if (pipe(pipe_fds) < 0) {
5424 if ((pid = fork()) < 0) {
5430 /* close the write side of the pipe */
5433 compose->exteditor_file = g_strdup(tmp);
5434 compose->exteditor_pid = pid;
5435 compose->exteditor_readdes = pipe_fds[0];
5437 compose_set_ext_editor_sensitive(compose, FALSE);
5439 compose->exteditor_tag =
5440 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5441 compose_input_cb, compose);
5442 } else { /* process-monitoring process */
5448 /* close the read side of the pipe */
5451 if (compose_write_body_to_file(compose, tmp) < 0) {
5452 fd_write(pipe_fds[1], "2\n", 2);
5456 pid_ed = compose_exec_ext_editor_real(tmp);
5458 fd_write(pipe_fds[1], "1\n", 2);
5462 /* wait until editor is terminated */
5463 waitpid(pid_ed, NULL, 0);
5465 fd_write(pipe_fds[1], "0\n", 2);
5472 static gint compose_exec_ext_editor_real(const gchar *file)
5474 static gchar *def_cmd = "emacs %s";
5480 g_return_val_if_fail(file != NULL, -1);
5482 if ((pid = fork()) < 0) {
5487 if (pid != 0) return pid;
5489 /* grandchild process */
5491 if (setpgid(0, getppid()))
5494 if (prefs_common.ext_editor_cmd &&
5495 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5496 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5497 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5499 if (prefs_common.ext_editor_cmd)
5500 g_warning(_("External editor command line is invalid: `%s'\n"),
5501 prefs_common.ext_editor_cmd);
5502 g_snprintf(buf, sizeof(buf), def_cmd, file);
5505 cmdline = strsplit_with_quote(buf, " ", 1024);
5506 execvp(cmdline[0], cmdline);
5509 g_strfreev(cmdline);
5514 static gboolean compose_ext_editor_kill(Compose *compose)
5516 pid_t pgid = compose->exteditor_pid * -1;
5519 ret = kill(pgid, 0);
5521 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5525 msg = g_strdup_printf
5526 (_("The external editor is still working.\n"
5527 "Force terminating the process?\n"
5528 "process group id: %d"), -pgid);
5529 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5532 if (val == G_ALERTDEFAULT) {
5533 gdk_input_remove(compose->exteditor_tag);
5534 close(compose->exteditor_readdes);
5536 if (kill(pgid, SIGTERM) < 0) perror("kill");
5537 waitpid(compose->exteditor_pid, NULL, 0);
5539 g_warning(_("Terminated process group id: %d"), -pgid);
5540 g_warning(_("Temporary file: %s"),
5541 compose->exteditor_file);
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;
5557 static void compose_input_cb(gpointer data, gint source,
5558 GdkInputCondition condition)
5561 Compose *compose = (Compose *)data;
5564 debug_print(_("Compose: input from monitoring process\n"));
5566 gdk_input_remove(compose->exteditor_tag);
5569 if (read(source, &buf[i], 1) < 1) {
5573 if (buf[i] == '\n') {
5578 if (i == sizeof(buf) - 1)
5582 waitpid(compose->exteditor_pid, NULL, 0);
5584 if (buf[0] == '0') { /* success */
5585 GtkSText *text = GTK_STEXT(compose->text);
5587 gtk_stext_freeze(text);
5588 gtk_stext_set_point(text, 0);
5589 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5590 compose_insert_file(compose, compose->exteditor_file);
5591 compose_changed_cb(NULL, compose);
5592 gtk_stext_thaw(text);
5594 if (unlink(compose->exteditor_file) < 0)
5595 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5596 } else if (buf[0] == '1') { /* failed */
5597 g_warning(_("Couldn't exec external editor\n"));
5598 if (unlink(compose->exteditor_file) < 0)
5599 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5600 } else if (buf[0] == '2') {
5601 g_warning(_("Couldn't write to file\n"));
5602 } else if (buf[0] == '3') {
5603 g_warning(_("Pipe read failed\n"));
5608 compose_set_ext_editor_sensitive(compose, TRUE);
5610 g_free(compose->exteditor_file);
5611 compose->exteditor_file = NULL;
5612 compose->exteditor_pid = -1;
5613 compose->exteditor_readdes = -1;
5614 compose->exteditor_tag = -1;
5617 static void compose_set_ext_editor_sensitive(Compose *compose,
5620 GtkItemFactory *ifactory;
5622 ifactory = gtk_item_factory_from_widget(compose->menubar);
5624 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5625 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5626 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5628 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5629 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5630 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5631 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5632 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5635 gtk_widget_set_sensitive(compose->text, sensitive);
5636 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5637 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5638 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5639 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5640 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5641 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5642 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5646 * compose_undo_state_changed:
5648 * Change the sensivity of the menuentries undo and redo
5650 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5651 gint redo_state, gpointer data)
5653 GtkWidget *widget = GTK_WIDGET(data);
5654 GtkItemFactory *ifactory;
5656 g_return_if_fail(widget != NULL);
5658 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
5660 ifactory = gtk_item_factory_from_widget(widget);
5662 switch (undo_state) {
5663 case UNDO_STATE_TRUE:
5664 if (!undostruct->undo_state) {
5665 debug_print ("Set_undo - Testpoint\n");
5666 undostruct->undo_state = TRUE;
5667 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5670 case UNDO_STATE_FALSE:
5671 if (undostruct->undo_state) {
5672 undostruct->undo_state = FALSE;
5673 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5676 case UNDO_STATE_UNCHANGED:
5678 case UNDO_STATE_REFRESH:
5679 menu_set_sensitive(ifactory, "/Edit/Undo",
5680 undostruct->undo_state);
5683 g_warning("Undo state not recognized");
5687 switch (redo_state) {
5688 case UNDO_STATE_TRUE:
5689 if (!undostruct->redo_state) {
5690 undostruct->redo_state = TRUE;
5691 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5694 case UNDO_STATE_FALSE:
5695 if (undostruct->redo_state) {
5696 undostruct->redo_state = FALSE;
5697 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5700 case UNDO_STATE_UNCHANGED:
5702 case UNDO_STATE_REFRESH:
5703 menu_set_sensitive(ifactory, "/Edit/Redo",
5704 undostruct->redo_state);
5707 g_warning("Redo state not recognized");
5712 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5716 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5717 cursor_pos = MAX(cursor_pos, 0);
5722 /* callback functions */
5724 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5725 * includes "non-client" (windows-izm) in calculation, so this calculation
5726 * may not be accurate.
5728 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5729 GtkAllocation *allocation,
5730 GtkSHRuler *shruler)
5732 if (prefs_common.show_ruler) {
5734 gint line_width_in_chars;
5736 char_width = gtkut_get_font_width
5737 (GTK_WIDGET(widget)->style->font);
5738 line_width_in_chars =
5739 (allocation->width - allocation->x) / char_width;
5741 /* got the maximum */
5742 gtk_ruler_set_range(GTK_RULER(shruler),
5743 0.0, line_width_in_chars,
5744 calc_cursor_xpos(GTK_STEXT(widget),
5747 /*line_width_in_chars*/ char_width);
5753 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5755 compose_send_cb(data, 0, NULL);
5758 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5760 compose_send_later_cb(data, 0, NULL);
5763 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5765 compose_draft_cb(data, 0, NULL);
5768 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5770 compose_insert_file_cb(data, 0, NULL);
5773 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5775 compose_attach_cb(data, 0, NULL);
5778 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5780 Compose *compose = (Compose *)data;
5782 compose_insert_sig(compose);
5785 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5787 Compose *compose = (Compose *)data;
5789 compose_exec_ext_editor(compose);
5792 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5794 Compose *compose = (Compose *)data;
5796 compose_wrap_line(compose);
5799 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5801 compose_address_cb(data, 0, NULL);
5804 static void select_account(Compose * compose, PrefsAccount * ac)
5806 compose->account = ac;
5807 compose_set_title(compose);
5809 #if 0 /* NEW COMPOSE GUI */
5810 if (ac->protocol == A_NNTP) {
5811 GtkItemFactory *ifactory;
5812 GtkWidget *menuitem;
5814 ifactory = gtk_item_factory_from_widget(compose->menubar);
5815 menu_set_sensitive(ifactory,
5816 "/Message/Followup to", TRUE);
5817 gtk_widget_show(compose->newsgroups_hbox);
5818 gtk_widget_show(compose->newsgroups_entry);
5819 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5822 compose->use_to = FALSE;
5823 compose->use_cc = FALSE;
5825 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5826 gtk_check_menu_item_set_active
5827 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5829 menu_set_sensitive(ifactory,
5830 "/Message/To", TRUE);
5831 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5832 gtk_check_menu_item_set_active
5833 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5835 gtk_widget_hide(compose->to_hbox);
5836 gtk_widget_hide(compose->to_entry);
5837 gtk_widget_hide(compose->cc_hbox);
5838 gtk_widget_hide(compose->cc_entry);
5839 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5841 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5845 GtkItemFactory *ifactory;
5846 GtkWidget *menuitem;
5848 ifactory = gtk_item_factory_from_widget(compose->menubar);
5849 menu_set_sensitive(ifactory,
5850 "/Message/Followup to", FALSE);
5851 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5852 gtk_widget_hide(compose->newsgroups_hbox);
5853 gtk_widget_hide(compose->newsgroups_entry);
5854 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5857 compose->use_to = TRUE;
5858 compose->use_cc = TRUE;
5860 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5861 gtk_check_menu_item_set_active
5862 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5863 menu_set_sensitive(ifactory,
5864 "/Message/To", FALSE);
5865 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5866 gtk_check_menu_item_set_active
5867 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5868 gtk_widget_show(compose->to_hbox);
5869 gtk_widget_show(compose->to_entry);
5870 gtk_widget_show(compose->cc_hbox);
5871 gtk_widget_show(compose->cc_entry);
5873 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5875 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5878 gtk_widget_queue_resize(compose->table_vbox);
5882 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5884 Compose *compose = (Compose *)data;
5888 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5889 g_return_if_fail(ac != NULL);
5891 if (ac != compose->account)
5892 select_account(compose, ac);
5895 static void attach_selected(GtkCList *clist, gint row, gint column,
5896 GdkEvent *event, gpointer data)
5898 Compose *compose = (Compose *)data;
5900 if (event && event->type == GDK_2BUTTON_PRESS)
5901 compose_attach_property(compose);
5904 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5907 Compose *compose = (Compose *)data;
5908 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5913 if (event->button == 3) {
5914 if ((clist->selection && !clist->selection->next) ||
5915 !clist->selection) {
5916 gtk_clist_unselect_all(clist);
5917 if (gtk_clist_get_selection_info(clist,
5920 gtk_clist_select_row(clist, row, column);
5921 gtkut_clist_set_focus_row(clist, row);
5924 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5925 NULL, NULL, event->button, event->time);
5929 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5932 Compose *compose = (Compose *)data;
5936 switch (event->keyval) {
5938 compose_attach_remove_selected(compose);
5943 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5945 Compose *compose = (Compose *)data;
5948 val = compose_send(compose);
5950 if (val == 0) gtk_widget_destroy(compose->window);
5953 static void compose_send_later_cb(gpointer data, guint action,
5956 Compose *compose = (Compose *)data;
5959 val = compose_queue(compose, NULL, NULL);
5960 if (!val) gtk_widget_destroy(compose->window);
5963 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5965 Compose *compose = (Compose *)data;
5969 static gboolean lock = FALSE;
5973 draft = folder_get_default_draft();
5974 g_return_if_fail(draft != NULL);
5978 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5979 G_DIR_SEPARATOR, (gint)compose);
5981 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5987 folder_item_scan(draft);
5988 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) <= 0) {
5995 draft->mtime = 0; /* force updating */
5997 if (compose->mode == COMPOSE_REEDIT) {
5998 compose_remove_reedit_target(compose);
5999 if (compose->targetinfo &&
6000 compose->targetinfo->folder != draft)
6001 folderview_update_item(compose->targetinfo->folder,
6005 folder_item_scan(draft);
6006 folderview_update_item(draft, TRUE);
6010 /* 0: quit editing 1: keep editing */
6012 gtk_widget_destroy(compose->window);
6017 path = folder_item_fetch_msg(draft, msgnum);
6018 g_return_if_fail(path != NULL);
6019 if (stat(path, &s) < 0) {
6020 FILE_OP_ERROR(path, "stat");
6027 procmsg_msginfo_free(compose->targetinfo);
6028 compose->targetinfo = g_new0(MsgInfo, 1);
6029 compose->targetinfo->msgnum = msgnum;
6030 compose->targetinfo->size = s.st_size;
6031 compose->targetinfo->mtime = s.st_mtime;
6032 compose->targetinfo->folder = draft;
6033 compose->mode = COMPOSE_REEDIT;
6037 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6039 Compose *compose = (Compose *)data;
6042 if (compose->bounce_filename != NULL)
6045 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6050 for ( tmp = file_list; tmp; tmp = tmp->next) {
6051 gchar *file = (gchar *) tmp->data;
6052 compose_attach_append(compose, file, MIME_UNKNOWN);
6055 g_list_free(file_list);
6059 static void compose_insert_file_cb(gpointer data, guint action,
6062 Compose *compose = (Compose *)data;
6065 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6070 for ( tmp = file_list; tmp; tmp = tmp->next) {
6071 gchar *file = (gchar *) tmp->data;
6072 compose_insert_file(compose, file);
6075 g_list_free(file_list);
6079 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6082 compose_close_cb(data, 0, NULL);
6086 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6088 Compose *compose = (Compose *)data;
6091 if (compose->exteditor_tag != -1) {
6092 if (!compose_ext_editor_kill(compose))
6096 if (compose->modified) {
6097 val = alertpanel(_("Discard message"),
6098 _("This message has been modified. discard it?"),
6099 _("Discard"), _("to Draft"), _("Cancel"));
6102 case G_ALERTDEFAULT:
6104 case G_ALERTALTERNATE:
6105 compose_draft_cb(data, 0, NULL);
6111 gtk_widget_destroy(compose->window);
6114 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6116 Compose *compose = (Compose *)data;
6118 addressbook_open(compose);
6121 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6123 Compose *compose = (Compose *)data;
6126 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6127 g_return_if_fail(tmpl != NULL);
6129 compose_template_apply(compose, tmpl);
6132 static void compose_ext_editor_cb(gpointer data, guint action,
6135 Compose *compose = (Compose *)data;
6137 compose_exec_ext_editor(compose);
6140 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6142 compose_destroy(compose);
6145 static void compose_undo_cb(Compose *compose)
6147 undo_undo(compose->undostruct);
6150 static void compose_redo_cb(Compose *compose)
6152 undo_redo(compose->undostruct);
6155 static void compose_cut_cb(Compose *compose)
6157 if (compose->focused_editable &&
6158 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6159 gtk_editable_cut_clipboard
6160 (GTK_EDITABLE(compose->focused_editable));
6163 static void compose_copy_cb(Compose *compose)
6165 if (compose->focused_editable &&
6166 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6167 gtk_editable_copy_clipboard
6168 (GTK_EDITABLE(compose->focused_editable));
6171 static void compose_paste_cb(Compose *compose)
6173 if (compose->focused_editable &&
6174 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6175 gtk_editable_paste_clipboard
6176 (GTK_EDITABLE(compose->focused_editable));
6179 static void compose_allsel_cb(Compose *compose)
6181 if (compose->focused_editable &&
6182 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6183 gtk_editable_select_region
6184 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6187 static void compose_move_beginning_of_line_cb(Compose *compose)
6189 if (compose->focused_editable &&
6190 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6191 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6194 static void compose_gtk_stext_action_cb(Compose *compose, ComposeCallGtkSTextAction action)
6196 if (!(compose->focused_editable && GTK_WIDGET_HAS_FOCUS(compose->focused_editable))) return;
6199 case COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE:
6200 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6202 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER:
6203 gtk_stext_move_forward_character(GTK_STEXT(compose->focused_editable));
6205 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER:
6206 gtk_stext_move_backward_character(GTK_STEXT(compose->focused_editable));
6208 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD:
6209 gtk_stext_move_forward_word(GTK_STEXT(compose->focused_editable));
6211 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD:
6212 gtk_stext_move_backward_word(GTK_STEXT(compose->focused_editable));
6214 case COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE:
6215 gtk_stext_move_end_of_line(GTK_STEXT(compose->focused_editable));
6217 case COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE:
6218 gtk_stext_move_next_line(GTK_STEXT(compose->focused_editable));
6220 case COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE:
6221 gtk_stext_move_previous_line(GTK_STEXT(compose->focused_editable));
6223 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER:
6224 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6226 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER:
6227 gtk_stext_delete_backward_character(GTK_STEXT(compose->focused_editable));
6229 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD:
6230 gtk_stext_delete_forward_word(GTK_STEXT(compose->focused_editable));
6232 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD:
6233 gtk_stext_delete_backward_word(GTK_STEXT(compose->focused_editable));
6235 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE:
6236 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6238 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N:
6239 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6240 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6242 case COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END:
6243 gtk_stext_delete_to_line_end(GTK_STEXT(compose->focused_editable));
6250 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6252 if (GTK_IS_EDITABLE(widget))
6253 compose->focused_editable = widget;
6256 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6258 if (compose->modified == FALSE) {
6259 compose->modified = TRUE;
6260 compose_set_title(compose);
6264 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6267 gtk_stext_set_point(GTK_STEXT(widget),
6268 gtk_editable_get_position(GTK_EDITABLE(widget)));
6272 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6275 gtk_stext_set_point(GTK_STEXT(widget),
6276 gtk_editable_get_position(GTK_EDITABLE(widget)));
6280 #if 0 /* NEW COMPOSE GUI */
6281 static void compose_toggle_to_cb(gpointer data, guint action,
6284 Compose *compose = (Compose *)data;
6286 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6287 gtk_widget_show(compose->to_hbox);
6288 gtk_widget_show(compose->to_entry);
6289 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6290 compose->use_to = TRUE;
6292 gtk_widget_hide(compose->to_hbox);
6293 gtk_widget_hide(compose->to_entry);
6294 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6295 gtk_widget_queue_resize(compose->table_vbox);
6296 compose->use_to = FALSE;
6299 if (addressbook_get_target_compose() == compose)
6300 addressbook_set_target_compose(compose);
6303 static void compose_toggle_cc_cb(gpointer data, guint action,
6306 Compose *compose = (Compose *)data;
6308 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6309 gtk_widget_show(compose->cc_hbox);
6310 gtk_widget_show(compose->cc_entry);
6311 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6312 compose->use_cc = TRUE;
6314 gtk_widget_hide(compose->cc_hbox);
6315 gtk_widget_hide(compose->cc_entry);
6316 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6317 gtk_widget_queue_resize(compose->table_vbox);
6318 compose->use_cc = FALSE;
6321 if (addressbook_get_target_compose() == compose)
6322 addressbook_set_target_compose(compose);
6325 static void compose_toggle_bcc_cb(gpointer data, guint action,
6328 Compose *compose = (Compose *)data;
6330 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6331 gtk_widget_show(compose->bcc_hbox);
6332 gtk_widget_show(compose->bcc_entry);
6333 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6334 compose->use_bcc = TRUE;
6336 gtk_widget_hide(compose->bcc_hbox);
6337 gtk_widget_hide(compose->bcc_entry);
6338 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6339 gtk_widget_queue_resize(compose->table_vbox);
6340 compose->use_bcc = FALSE;
6343 if (addressbook_get_target_compose() == compose)
6344 addressbook_set_target_compose(compose);
6347 static void compose_toggle_replyto_cb(gpointer data, guint action,
6350 Compose *compose = (Compose *)data;
6352 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6353 gtk_widget_show(compose->reply_hbox);
6354 gtk_widget_show(compose->reply_entry);
6355 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6356 compose->use_replyto = TRUE;
6358 gtk_widget_hide(compose->reply_hbox);
6359 gtk_widget_hide(compose->reply_entry);
6360 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6361 gtk_widget_queue_resize(compose->table_vbox);
6362 compose->use_replyto = FALSE;
6366 static void compose_toggle_followupto_cb(gpointer data, guint action,
6369 Compose *compose = (Compose *)data;
6371 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6372 gtk_widget_show(compose->followup_hbox);
6373 gtk_widget_show(compose->followup_entry);
6374 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6375 compose->use_followupto = TRUE;
6377 gtk_widget_hide(compose->followup_hbox);
6378 gtk_widget_hide(compose->followup_entry);
6379 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6380 gtk_widget_queue_resize(compose->table_vbox);
6381 compose->use_followupto = FALSE;
6385 static void compose_toggle_attach_cb(gpointer data, guint action,
6388 Compose *compose = (Compose *)data;
6390 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6391 gtk_widget_ref(compose->edit_vbox);
6393 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6394 compose->edit_vbox);
6395 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6396 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6398 gtk_widget_show(compose->paned);
6400 gtk_widget_unref(compose->edit_vbox);
6401 gtk_widget_unref(compose->paned);
6403 compose->use_attach = TRUE;
6405 gtk_widget_ref(compose->paned);
6406 gtk_widget_ref(compose->edit_vbox);
6408 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6410 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6411 compose->edit_vbox);
6412 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6413 compose->edit_vbox, TRUE, TRUE, 0);
6415 gtk_widget_unref(compose->edit_vbox);
6417 compose->use_attach = FALSE;
6423 static void compose_toggle_sign_cb(gpointer data, guint action,
6426 Compose *compose = (Compose *)data;
6428 if (GTK_CHECK_MENU_ITEM(widget)->active)
6429 compose->use_signing = TRUE;
6431 compose->use_signing = FALSE;
6434 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6437 Compose *compose = (Compose *)data;
6439 if (GTK_CHECK_MENU_ITEM(widget)->active)
6440 compose->use_encryption = TRUE;
6442 compose->use_encryption = FALSE;
6444 #endif /* USE_GPGME */
6446 static void compose_toggle_ruler_cb(gpointer data, guint action,
6449 Compose *compose = (Compose *)data;
6451 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6452 gtk_widget_show(compose->ruler_hbox);
6453 prefs_common.show_ruler = TRUE;
6455 gtk_widget_hide(compose->ruler_hbox);
6456 gtk_widget_queue_resize(compose->edit_vbox);
6457 prefs_common.show_ruler = FALSE;
6461 static void compose_attach_drag_received_cb (GtkWidget *widget,
6462 GdkDragContext *drag_context,
6465 GtkSelectionData *data,
6470 Compose *compose = (Compose *)user_data;
6473 list = uri_list_extract_filenames((const gchar *)data->data);
6474 for (tmp = list; tmp != NULL; tmp = tmp->next)
6475 compose_attach_append(compose, (const gchar *)tmp->data,
6477 list_free_strings(list);
6481 static void compose_insert_drag_received_cb (GtkWidget *widget,
6482 GdkDragContext *drag_context,
6485 GtkSelectionData *data,
6490 Compose *compose = (Compose *)user_data;
6493 list = uri_list_extract_filenames((const gchar *)data->data);
6494 for (tmp = list; tmp != NULL; tmp = tmp->next)
6495 compose_insert_file(compose, (const gchar *)tmp->data);
6496 list_free_strings(list);
6500 #if 0 /* NEW COMPOSE GUI */
6501 static void to_activated(GtkWidget *widget, Compose *compose)
6503 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6504 gtk_widget_grab_focus(compose->newsgroups_entry);
6506 gtk_widget_grab_focus(compose->subject_entry);
6509 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6511 gtk_widget_grab_focus(compose->subject_entry);
6514 static void subject_activated(GtkWidget *widget, Compose *compose)
6516 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6517 gtk_widget_grab_focus(compose->cc_entry);
6518 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6519 gtk_widget_grab_focus(compose->bcc_entry);
6520 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6521 gtk_widget_grab_focus(compose->reply_entry);
6522 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6523 gtk_widget_grab_focus(compose->followup_entry);
6525 gtk_widget_grab_focus(compose->text);
6528 static void cc_activated(GtkWidget *widget, Compose *compose)
6530 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6531 gtk_widget_grab_focus(compose->bcc_entry);
6532 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6533 gtk_widget_grab_focus(compose->reply_entry);
6534 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6535 gtk_widget_grab_focus(compose->followup_entry);
6537 gtk_widget_grab_focus(compose->text);
6540 static void bcc_activated(GtkWidget *widget, Compose *compose)
6542 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6543 gtk_widget_grab_focus(compose->reply_entry);
6544 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6545 gtk_widget_grab_focus(compose->followup_entry);
6547 gtk_widget_grab_focus(compose->text);
6550 static void replyto_activated(GtkWidget *widget, Compose *compose)
6552 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6553 gtk_widget_grab_focus(compose->followup_entry);
6555 gtk_widget_grab_focus(compose->text);
6558 static void followupto_activated(GtkWidget *widget, Compose *compose)
6560 gtk_widget_grab_focus(compose->text);
6564 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6567 Compose *compose = (Compose *)data;
6569 if (GTK_CHECK_MENU_ITEM(widget)->active)
6570 compose->return_receipt = TRUE;
6572 compose->return_receipt = FALSE;
6575 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6577 ComposeHeaderEntry *headerentry)
6579 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6580 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6581 !(event->state & GDK_MODIFIER_MASK) &&
6582 (event->keyval == GDK_BackSpace) &&
6583 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6584 gtk_container_remove
6585 (GTK_CONTAINER(headerentry->compose->header_table),
6586 headerentry->combo);
6587 gtk_container_remove
6588 (GTK_CONTAINER(headerentry->compose->header_table),
6589 headerentry->entry);
6590 headerentry->compose->header_list =
6591 g_slist_remove(headerentry->compose->header_list,
6593 g_free(headerentry);
6594 } else if (event->keyval == GDK_Tab) {
6595 if (headerentry->compose->header_last == headerentry) {
6596 /* Override default next focus, and give it to subject_entry
6597 * instead of notebook tabs
6599 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6600 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6606 void compose_headerentry_changed_cb(GtkWidget *entry,
6607 ComposeHeaderEntry *headerentry)
6609 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6610 headerentry->compose->header_list =
6611 g_slist_append(headerentry->compose->header_list,
6613 compose_create_header_entry(headerentry->compose);
6614 gtk_signal_disconnect_by_func
6616 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6618 /* Automatically scroll down */
6619 compose_show_first_last_header(headerentry->compose, FALSE);
6624 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6626 GtkAdjustment *vadj;
6628 g_return_if_fail(compose);
6629 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6630 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6632 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6633 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6636 static void text_activated(GtkWidget *widget, Compose *compose)
6638 compose_send_control_enter(compose);
6641 static gboolean compose_send_control_enter(Compose *compose)
6645 GtkItemFactory *ifactory;
6646 GtkAccelEntry *accel;
6647 GtkWidget *send_menu;
6650 ev = gtk_get_current_event();
6651 if (ev->type != GDK_KEY_PRESS) return FALSE;
6653 kev = (GdkEventKey *)ev;
6654 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6657 ifactory = gtk_item_factory_from_widget(compose->menubar);
6658 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6659 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6660 accel = (GtkAccelEntry *)list->data;
6661 if (accel->accelerator_key == kev->keyval &&
6662 accel->accelerator_mods == kev->state) {
6663 compose_send_cb(compose, 0, NULL);
6671 static void compose_check_all(Compose *compose)
6673 if (compose->gtkpspell)
6674 gtkpspell_check_all(compose->gtkpspell);
6677 static void compose_highlight_all(Compose *compose)
6679 if (compose->gtkpspell)
6680 gtkpspell_highlight_all(compose->gtkpspell);
6683 static void compose_check_backwards(Compose *compose)
6685 if (compose->gtkpspell)
6686 gtkpspell_check_backwards(compose->gtkpspell);
6688 GtkItemFactory *ifactory;
6689 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6690 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6691 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6695 static void compose_check_forwards_go(Compose *compose)
6697 if (compose->gtkpspell)
6698 gtkpspell_check_forwards_go(compose->gtkpspell);
6700 GtkItemFactory *ifactory;
6701 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6702 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6703 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);