2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
31 #include <gtk/gtkitemfactory.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkclist.h>
36 #include <gtk/gtkctree.h>
37 #include <gtk/gtkvpaned.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkeditable.h>
40 #include <gtk/gtkwindow.h>
41 #include <gtk/gtksignal.h>
42 #include <gtk/gtkvbox.h>
43 #include <gtk/gtkcontainer.h>
44 #include <gtk/gtkhandlebox.h>
45 #include <gtk/gtktoolbar.h>
46 #include <gtk/gtktable.h>
47 #include <gtk/gtkhbox.h>
48 #include <gtk/gtklabel.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtkthemes.h>
51 #include <gtk/gtkdnd.h>
56 #include <sys/types.h>
60 /* #include <sys/utsname.h> */
66 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
73 #include "mainwindow.h"
76 #include "addressbook.h"
77 #include "folderview.h"
80 #include "stock_pixmap.h"
84 #include "customheader.h"
85 #include "prefs_common.h"
86 #include "prefs_account.h"
89 #include "procheader.h"
91 #include "statusbar.h"
98 #include "alertpanel.h"
99 #include "manage_window.h"
100 #include "gtkshruler.h"
102 #include "addr_compl.h"
103 #include "quote_fmt.h"
104 #include "template.h"
106 #include "foldersel.h"
107 #include "prefs_actions.h"
110 # include "rfc2015.h"
120 #define N_ATTACH_COLS 3
124 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
125 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
126 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
127 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
128 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
129 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
130 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
131 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
132 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
133 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
134 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
135 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
136 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
137 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
138 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
139 } ComposeCallGtkSTextAction;
143 PRIORITY_HIGHEST = 1,
150 #define B64_LINE_SIZE 57
151 #define B64_BUFFSIZE 77
153 #define MAX_REFERENCES_LEN 999
155 static GdkColor quote_color = {0, 0, 0, 0xbfff};
157 static GList *compose_list = NULL;
159 Compose *compose_generic_new (PrefsAccount *account,
163 static Compose *compose_create (PrefsAccount *account,
165 static void compose_toolbar_create (Compose *compose,
166 GtkWidget *container);
167 static GtkWidget *compose_account_option_menu_create
169 static void compose_set_template_menu (Compose *compose);
170 static void compose_template_apply (Compose *compose,
173 static void compose_destroy (Compose *compose);
175 static void compose_entries_set (Compose *compose,
176 const gchar *mailto);
177 static gint compose_parse_header (Compose *compose,
179 static gchar *compose_parse_references (const gchar *ref,
182 static gchar *compose_quote_fmt (Compose *compose,
188 static void compose_reply_set_entry (Compose *compose,
193 followup_and_reply_to);
194 static void compose_reedit_set_entry (Compose *compose,
196 static void compose_insert_sig (Compose *compose);
197 static void compose_insert_file (Compose *compose,
199 static void compose_attach_append (Compose *compose,
202 const gchar *content_type);
203 static void compose_attach_parts (Compose *compose,
205 static void compose_wrap_line (Compose *compose);
206 static void compose_wrap_line_all (Compose *compose);
207 static void compose_set_title (Compose *compose);
209 static PrefsAccount *compose_current_mail_account(void);
210 /* static gint compose_send (Compose *compose); */
211 static gboolean compose_check_for_valid_recipient
213 static gboolean compose_check_entries (Compose *compose,
214 gboolean check_subject);
215 static gint compose_write_to_file (Compose *compose,
218 static gint compose_write_body_to_file (Compose *compose,
220 static gint compose_remove_reedit_target (Compose *compose);
221 static gint compose_queue (Compose *compose,
224 static gint compose_queue_sub (Compose *compose,
227 gboolean check_subject);
228 static void compose_write_attach (Compose *compose,
230 static gint compose_write_headers (Compose *compose,
232 const gchar *charset,
233 EncodingType encoding,
236 static void compose_convert_header (gchar *dest,
240 static void compose_generate_msgid (Compose *compose,
244 static void compose_attach_info_free (AttachInfo *ainfo);
245 static void compose_attach_remove_selected (Compose *compose);
247 static void compose_attach_property (Compose *compose);
248 static void compose_attach_property_create (gboolean *cancelled);
249 static void attach_property_ok (GtkWidget *widget,
250 gboolean *cancelled);
251 static void attach_property_cancel (GtkWidget *widget,
252 gboolean *cancelled);
253 static gint attach_property_delete_event (GtkWidget *widget,
255 gboolean *cancelled);
256 static void attach_property_key_pressed (GtkWidget *widget,
258 gboolean *cancelled);
260 static void compose_exec_ext_editor (Compose *compose);
261 static gint compose_exec_ext_editor_real (const gchar *file);
262 static gboolean compose_ext_editor_kill (Compose *compose);
263 static void compose_input_cb (gpointer data,
265 GdkInputCondition condition);
266 static void compose_set_ext_editor_sensitive (Compose *compose,
269 static void compose_undo_state_changed (UndoMain *undostruct,
274 static gint calc_cursor_xpos (GtkSText *text,
278 static void compose_create_header_entry (Compose *compose);
279 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
280 static void compose_update_priority_menu_item(Compose * compose);
282 /* callback functions */
284 static gboolean compose_edit_size_alloc (GtkEditable *widget,
285 GtkAllocation *allocation,
286 GtkSHRuler *shruler);
288 static void toolbar_send_cb (GtkWidget *widget,
290 static void toolbar_send_later_cb (GtkWidget *widget,
292 static void toolbar_draft_cb (GtkWidget *widget,
294 static void toolbar_insert_cb (GtkWidget *widget,
296 static void toolbar_attach_cb (GtkWidget *widget,
298 static void toolbar_sig_cb (GtkWidget *widget,
300 static void toolbar_ext_editor_cb (GtkWidget *widget,
302 static void toolbar_linewrap_cb (GtkWidget *widget,
304 static void toolbar_address_cb (GtkWidget *widget,
307 static void select_account (Compose *compose,
310 static void account_activated (GtkMenuItem *menuitem,
313 static void attach_selected (GtkCList *clist,
318 static void attach_button_pressed (GtkWidget *widget,
319 GdkEventButton *event,
321 static void attach_key_pressed (GtkWidget *widget,
325 static void compose_send_cb (gpointer data,
328 static void compose_send_later_cb (gpointer data,
332 static void compose_draft_cb (gpointer data,
336 static void compose_attach_cb (gpointer data,
339 static void compose_insert_file_cb (gpointer data,
343 static void compose_close_cb (gpointer data,
347 static void compose_address_cb (gpointer data,
350 static void compose_template_activate_cb(GtkWidget *widget,
353 static void compose_ext_editor_cb (gpointer data,
357 static gint compose_delete_cb (GtkWidget *widget,
360 static void compose_destroy_cb (GtkWidget *widget,
363 static void compose_undo_cb (Compose *compose);
364 static void compose_redo_cb (Compose *compose);
365 static void compose_cut_cb (Compose *compose);
366 static void compose_copy_cb (Compose *compose);
367 static void compose_paste_cb (Compose *compose);
368 static void compose_allsel_cb (Compose *compose);
370 static void compose_gtk_stext_action_cb (Compose *compose,
371 ComposeCallGtkSTextAction action);
373 static void compose_grab_focus_cb (GtkWidget *widget,
376 static void compose_changed_cb (GtkEditable *editable,
378 static void compose_button_press_cb (GtkWidget *widget,
379 GdkEventButton *event,
382 static void compose_key_press_cb (GtkWidget *widget,
388 static void compose_toggle_to_cb (gpointer data,
391 static void compose_toggle_cc_cb (gpointer data,
394 static void compose_toggle_bcc_cb (gpointer data,
397 static void compose_toggle_replyto_cb (gpointer data,
400 static void compose_toggle_followupto_cb(gpointer data,
403 static void compose_toggle_attach_cb (gpointer data,
407 static void compose_toggle_ruler_cb (gpointer data,
411 static void compose_toggle_sign_cb (gpointer data,
414 static void compose_toggle_encrypt_cb (gpointer data,
418 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
420 static void compose_set_priority_cb (gpointer data,
424 static void compose_attach_drag_received_cb (GtkWidget *widget,
425 GdkDragContext *drag_context,
428 GtkSelectionData *data,
432 static void compose_insert_drag_received_cb (GtkWidget *widget,
433 GdkDragContext *drag_context,
436 GtkSelectionData *data,
442 static void to_activated (GtkWidget *widget,
444 static void newsgroups_activated (GtkWidget *widget,
446 static void subject_activated (GtkWidget *widget,
448 static void cc_activated (GtkWidget *widget,
450 static void bcc_activated (GtkWidget *widget,
452 static void replyto_activated (GtkWidget *widget,
454 static void followupto_activated (GtkWidget *widget,
458 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
460 gboolean ignore_replyto,
461 gboolean followup_and_reply_to,
464 void compose_headerentry_changed_cb (GtkWidget *entry,
465 ComposeHeaderEntry *headerentry);
466 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
468 ComposeHeaderEntry *headerentry);
470 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
473 static void compose_check_all (Compose *compose);
474 static void compose_highlight_all (Compose *compose);
475 static void compose_check_backwards (Compose *compose);
476 static void compose_check_forwards_go (Compose *compose);
479 static gboolean compose_send_control_enter (Compose *compose);
480 static void text_activated (GtkWidget *widget,
483 static GtkItemFactoryEntry compose_popup_entries[] =
485 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
486 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
487 {N_("/---"), NULL, NULL, 0, "<Separator>"},
488 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
491 static GtkItemFactoryEntry compose_entries[] =
493 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
494 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
495 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
496 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
497 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
498 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
500 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
501 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
502 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
503 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
504 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
505 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
506 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
507 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
508 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
509 {N_("/_Edit/A_dvanced/Move a character backward"),
511 compose_gtk_stext_action_cb,
512 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
514 {N_("/_Edit/A_dvanced/Move a character forward"),
516 compose_gtk_stext_action_cb,
517 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
519 {N_("/_Edit/A_dvanced/Move a word backward"),
521 compose_gtk_stext_action_cb,
522 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
524 {N_("/_Edit/A_dvanced/Move a word forward"),
526 compose_gtk_stext_action_cb,
527 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
529 {N_("/_Edit/A_dvanced/Move to beginning of line"),
530 NULL, /* "<control>A" */
531 compose_gtk_stext_action_cb,
532 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
534 {N_("/_Edit/A_dvanced/Move to end of line"),
536 compose_gtk_stext_action_cb,
537 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
539 {N_("/_Edit/A_dvanced/Move to previous line"),
541 compose_gtk_stext_action_cb,
542 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
544 {N_("/_Edit/A_dvanced/Move to next line"),
546 compose_gtk_stext_action_cb,
547 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
549 {N_("/_Edit/A_dvanced/Delete a character backward"),
551 compose_gtk_stext_action_cb,
552 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
554 {N_("/_Edit/A_dvanced/Delete a character forward"),
556 compose_gtk_stext_action_cb,
557 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
559 {N_("/_Edit/A_dvanced/Delete a word backward"),
560 NULL, /* "<control>W" */
561 compose_gtk_stext_action_cb,
562 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
564 {N_("/_Edit/A_dvanced/Delete a word forward"),
565 NULL, /* "<alt>D", */
566 compose_gtk_stext_action_cb,
567 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
569 {N_("/_Edit/A_dvanced/Delete line"),
571 compose_gtk_stext_action_cb,
572 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
574 {N_("/_Edit/A_dvanced/Delete entire line"),
576 compose_gtk_stext_action_cb,
577 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
579 {N_("/_Edit/A_dvanced/Delete to end of line"),
581 compose_gtk_stext_action_cb,
582 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
584 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
585 {N_("/_Edit/_Wrap current paragraph"),
586 "<control>L", compose_wrap_line, 0, NULL},
587 {N_("/_Edit/Wrap all long _lines"),
588 "<control><alt>L", compose_wrap_line_all, 0, NULL},
589 {N_("/_Edit/Edit with e_xternal editor"),
590 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
592 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
593 {N_("/_Spelling/_Check all or check selection"),
594 NULL, compose_check_all, 0, NULL},
595 {N_("/_Spelling/_Highlight all misspelled words"),
596 NULL, compose_highlight_all, 0, NULL},
597 {N_("/_Spelling/Check _backwards misspelled word"),
598 NULL, compose_check_backwards , 0, NULL},
599 {N_("/_Spelling/_Forward to next misspelled word"),
600 NULL, compose_check_forwards_go, 0, NULL},
601 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
602 {N_("/_Spelling/_Spelling Configuration"),
603 NULL, NULL, 0, "<Branch>"},
605 #if 0 /* NEW COMPOSE GUI */
606 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
607 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
608 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
609 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
610 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
611 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
612 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
613 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
614 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
615 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
616 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
618 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
619 {N_("/_Message/_Send"), "<control>Return",
620 compose_send_cb, 0, NULL},
621 {N_("/_Message/Send _later"), "<shift><control>S",
622 compose_send_later_cb, 0, NULL},
623 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
624 {N_("/_Message/Save to _draft folder"),
625 "<shift><control>D", compose_draft_cb, 0, NULL},
626 {N_("/_Message/Save and _keep editing"),
627 "<control>S", compose_draft_cb, 1, NULL},
628 #if 0 /* NEW COMPOSE GUI */
629 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
630 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
631 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
632 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
633 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
634 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
635 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
636 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
637 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
640 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
641 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
642 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
643 #endif /* USE_GPGME */
644 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
645 {N_("/_Message/Priority"), NULL, NULL, 0, "<Branch>"},
646 {N_("/_Message/Priority/Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
647 {N_("/_Message/Priority/High"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
648 {N_("/_Message/Priority/Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
649 {N_("/_Message/Priority/Low"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
650 {N_("/_Message/Priority/Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
651 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
652 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
653 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
654 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
655 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
656 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
657 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
658 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
659 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
662 static GtkTargetEntry compose_mime_types[] =
664 {"text/uri-list", 0, 0}
667 Compose *compose_new(PrefsAccount *account)
669 return compose_generic_new(account, NULL, NULL);
672 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
676 GtkItemFactory *ifactory;
678 c = compose_generic_new(account, NULL, NULL);
680 filename = procmsg_get_message_file(msginfo);
681 if (filename == NULL)
684 c->redirect_filename = filename;
686 if (msginfo->subject)
687 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
689 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
691 compose_quote_fmt(c, msginfo, "%M", NULL, NULL);
692 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
694 ifactory = gtk_item_factory_from_widget(c->popupmenu);
695 menu_set_sensitive(ifactory, "/Add...", FALSE);
696 menu_set_sensitive(ifactory, "/Remove", FALSE);
697 menu_set_sensitive(ifactory, "/Property...", FALSE);
699 ifactory = gtk_item_factory_from_widget(c->menubar);
700 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
701 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
702 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
703 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
704 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
705 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
706 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
707 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
709 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
710 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
712 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
713 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
715 gtk_widget_set_sensitive(c->insert_btn, FALSE);
716 gtk_widget_set_sensitive(c->attach_btn, FALSE);
717 gtk_widget_set_sensitive(c->sig_btn, FALSE);
718 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
719 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
724 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
726 return compose_generic_new(account, mailto, NULL);
729 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
731 return compose_generic_new(account, NULL, item);
734 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
739 if (item && item->prefs && item->prefs->enable_default_account)
740 account = account_find_from_id(item->prefs->default_account);
742 if (!account) account = cur_account;
743 g_return_val_if_fail(account != NULL, NULL);
745 compose = compose_create(account, COMPOSE_NEW);
746 compose->replyinfo = NULL;
748 text = GTK_STEXT(compose->text);
749 gtk_stext_freeze(text);
751 if (prefs_common.auto_sig)
752 compose_insert_sig(compose);
753 gtk_editable_set_position(GTK_EDITABLE(text), 0);
754 gtk_stext_set_point(text, 0);
756 gtk_stext_thaw(text);
758 /* workaround for initial XIM problem */
759 gtk_widget_grab_focus(compose->text);
760 gtkut_widget_wait_for_draw(compose->text);
762 if (account->protocol != A_NNTP) {
764 compose_entries_set(compose, mailto);
766 } else if(item && item->prefs->enable_default_to) {
767 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
769 if (item && item->ret_rcpt) {
770 GtkItemFactory *ifactory;
772 ifactory = gtk_item_factory_from_widget(compose->menubar);
773 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
777 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
780 compose_show_first_last_header(compose, TRUE);
782 /* Set save folder */
783 if(item && item->prefs && item->prefs->save_copy_to_folder) {
784 gchar *folderidentifier;
786 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
787 folderidentifier = folder_item_get_identifier(item);
788 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
789 g_free(folderidentifier);
792 gtk_widget_grab_focus(compose->header_last->entry);
794 if (prefs_common.auto_exteditor)
795 compose_exec_ext_editor(compose);
800 #define CHANGE_FLAGS(msginfo) \
802 if (msginfo->folder->folder->change_flags != NULL) \
803 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
809 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
810 const gchar *followupto, gchar * to)
814 if (!account) account = cur_account;
815 g_return_val_if_fail(account != NULL, NULL);
816 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
818 compose = compose_create(account, COMPOSE_NEW);
820 if (prefs_common.auto_sig)
821 compose_insert_sig(compose);
822 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
823 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
825 compose_entry_append(compose, to, COMPOSE_TO);
826 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
827 gtk_widget_grab_focus(compose->subject_entry);
833 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
834 gboolean ignore_replyto, const gchar *body)
836 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE,
840 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
842 gboolean ignore_replyto,
845 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE,
849 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
851 gboolean ignore_replyto,
852 gboolean followup_and_reply_to,
856 PrefsAccount *account;
857 PrefsAccount *reply_account;
860 g_return_if_fail(msginfo != NULL);
861 g_return_if_fail(msginfo->folder != NULL);
864 /* select the account set in folderitem's property (if enabled) */
865 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
866 account = account_find_from_id(msginfo->folder->prefs->default_account);
868 /* select the account for the whole folder (IMAP / NNTP) */
870 /* FIXME: this is not right, because folder may be nested. we should
871 * ascend the tree until we find a parent with proper account
873 account = msginfo->folder->folder->account;
875 /* select account by to: and cc: header if enabled */
876 if (prefs_common.reply_account_autosel) {
877 if (!account && msginfo->to) {
879 Xstrdup_a(to, msginfo->to, return);
881 account = account_find_from_address(to);
885 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
887 account = account_find_from_address(cc);
892 /* select current account */
893 if (!account) account = cur_account;
894 g_return_if_fail(account != NULL);
896 if (ignore_replyto && account->protocol == A_NNTP &&
897 !followup_and_reply_to) {
899 account_find_from_address(account->address);
901 reply_account = compose_current_mail_account();
905 reply_account = account;
907 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
908 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
909 if (MSG_IS_IMAP(msginfo->flags))
910 imap_msg_set_perm_flags(msginfo, MSG_REPLIED);
911 CHANGE_FLAGS(msginfo);
913 compose = compose_create(account, COMPOSE_REPLY);
914 compose->replyinfo = procmsg_msginfo_copy(msginfo);
916 #if 0 /* NEW COMPOSE GUI */
917 if (followup_and_reply_to) {
918 gtk_widget_show(compose->to_hbox);
919 gtk_widget_show(compose->to_entry);
920 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
921 compose->use_to = TRUE;
924 if (msginfo->folder && msginfo->folder->ret_rcpt) {
925 GtkItemFactory *ifactory;
927 ifactory = gtk_item_factory_from_widget(compose->menubar);
928 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
931 /* Set save folder */
932 if(msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
933 gchar *folderidentifier;
935 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
936 folderidentifier = folder_item_get_identifier(msginfo->folder);
937 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
938 g_free(folderidentifier);
941 if (compose_parse_header(compose, msginfo) < 0) return;
942 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
943 followup_and_reply_to);
944 compose_show_first_last_header(compose, TRUE);
946 text = GTK_STEXT(compose->text);
947 gtk_stext_freeze(text);
953 if (prefs_common.quotemark && *prefs_common.quotemark)
954 qmark = prefs_common.quotemark;
958 quote_str = compose_quote_fmt(compose, msginfo,
959 prefs_common.quotefmt,
963 if (prefs_common.auto_sig)
964 compose_insert_sig(compose);
966 if (quote && prefs_common.linewrap_quote)
967 compose_wrap_line_all(compose);
969 gtk_editable_set_position(GTK_EDITABLE(text), 0);
970 gtk_stext_set_point(text, 0);
972 gtk_stext_thaw(text);
973 gtk_widget_grab_focus(compose->text);
975 if (prefs_common.auto_exteditor)
976 compose_exec_ext_editor(compose);
979 static void set_toolbar_style(Compose *compose);
981 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
986 g_return_val_if_fail(mimeinfo != NULL, NULL);
988 base = mimeinfo->filename ? mimeinfo->filename
989 : mimeinfo->name ? mimeinfo->name : NULL;
991 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
992 filename = g_strdup_printf("%s%smimetmp.%08x.html",
999 base = base ? base : "";
1000 base = g_basename(base);
1001 if (*base == '\0') {
1002 filename = g_strdup_printf("%s%smimetmp.%08x",
1010 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
1016 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
1020 if (!partinfo) return NULL;
1022 filename = procmime_get_file_name(partinfo);
1024 if (procmime_get_part(filename, source, partinfo) < 0)
1026 (_("Can't get the part of multipart message."));
1033 #define INSERT_FW_HEADER(var, hdr) \
1034 if (msginfo->var && *msginfo->var) { \
1035 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1036 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1037 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1040 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1041 gboolean as_attach, const gchar *body)
1044 /* PrefsAccount *account; */
1047 g_return_val_if_fail(msginfo != NULL, NULL);
1048 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1050 account = msginfo->folder->folder->account;
1051 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1053 Xstrdup_a(to, msginfo->to, return NULL);
1054 extract_address(to);
1055 account = account_find_from_address(to);
1058 if(!account && prefs_common.forward_account_autosel) {
1060 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1061 extract_address(cc);
1062 account = account_find_from_address(cc);
1066 if (account == NULL) {
1067 account = cur_account;
1069 account = msginfo->folder->folder->account;
1070 if (!account) account = cur_account;
1073 g_return_val_if_fail(account != NULL, NULL);
1075 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1076 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1077 if (MSG_IS_IMAP(msginfo->flags))
1078 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1079 CHANGE_FLAGS(msginfo);
1081 compose = compose_create(account, COMPOSE_FORWARD);
1083 if (msginfo->subject && *msginfo->subject) {
1084 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1085 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1089 text = GTK_STEXT(compose->text);
1090 gtk_stext_freeze(text);
1096 msgfile = procmsg_get_message_file_path(msginfo);
1097 if (!is_file_exist(msgfile))
1098 g_warning(_("%s: file not exist\n"), msgfile);
1100 compose_attach_append(compose, msgfile, msgfile,
1108 if (prefs_common.fw_quotemark &&
1109 *prefs_common.fw_quotemark)
1110 qmark = prefs_common.fw_quotemark;
1114 quote_str = compose_quote_fmt(compose, msginfo,
1115 prefs_common.fw_quotefmt,
1117 compose_attach_parts(compose, msginfo);
1120 if (prefs_common.auto_sig)
1121 compose_insert_sig(compose);
1123 if (prefs_common.linewrap_quote)
1124 compose_wrap_line_all(compose);
1126 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1127 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1129 gtk_stext_thaw(text);
1130 #if 0 /* NEW COMPOSE GUI */
1131 if (account->protocol != A_NNTP)
1132 gtk_widget_grab_focus(compose->to_entry);
1134 gtk_widget_grab_focus(compose->newsgroups_entry);
1136 gtk_widget_grab_focus(compose->header_last->entry);
1138 if (prefs_common.auto_exteditor)
1139 compose_exec_ext_editor(compose);
1144 #undef INSERT_FW_HEADER
1146 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1153 g_return_val_if_fail(msginfo_list != NULL, NULL);
1155 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1156 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1160 if (account == NULL) {
1161 account = cur_account;
1163 account = msginfo->folder->folder->account;
1164 if (!account) account = cur_account;
1167 g_return_val_if_fail(account != NULL, NULL);
1169 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1170 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1171 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1172 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1175 compose = compose_create(account, COMPOSE_FORWARD);
1177 text = GTK_STEXT(compose->text);
1178 gtk_stext_freeze(text);
1180 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1181 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1182 if (!is_file_exist(msgfile))
1183 g_warning(_("%s: file not exist\n"), msgfile);
1185 compose_attach_append(compose, msgfile, msgfile,
1190 if (prefs_common.auto_sig)
1191 compose_insert_sig(compose);
1193 if (prefs_common.linewrap_quote)
1194 compose_wrap_line_all(compose);
1196 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1197 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1199 gtk_stext_thaw(text);
1200 #if 0 /* NEW COMPOSE GUI */
1201 if (account->protocol != A_NNTP)
1202 gtk_widget_grab_focus(compose->to_entry);
1204 gtk_widget_grab_focus(compose->newsgroups_entry);
1210 void compose_reedit(MsgInfo *msginfo)
1213 PrefsAccount *account = NULL;
1216 gchar buf[BUFFSIZE];
1218 g_return_if_fail(msginfo != NULL);
1219 g_return_if_fail(msginfo->folder != NULL);
1221 if (msginfo->folder->stype == F_QUEUE) {
1222 gchar queueheader_buf[BUFFSIZE];
1225 /* Select Account from queue headers */
1226 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1227 sizeof(queueheader_buf), "NAID:")) {
1228 id = atoi(&queueheader_buf[5]);
1229 account = account_find_from_id(id);
1231 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1232 sizeof(queueheader_buf), "MAID:")) {
1233 id = atoi(&queueheader_buf[5]);
1234 account = account_find_from_id(id);
1236 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1237 sizeof(queueheader_buf), "S:")) {
1238 account = account_find_from_address(queueheader_buf);
1241 account = msginfo->folder->folder->account;
1243 if (!account && prefs_common.reedit_account_autosel) {
1244 gchar from[BUFFSIZE];
1245 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1246 extract_address(from);
1247 account = account_find_from_address(from);
1250 if (!account) account = cur_account;
1251 g_return_if_fail(account != NULL);
1253 compose = compose_create(account, COMPOSE_REEDIT);
1254 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1256 if (msginfo->folder->stype == F_QUEUE) {
1257 gchar queueheader_buf[BUFFSIZE];
1259 /* Set message save folder */
1260 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1263 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1264 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1265 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1269 if (compose_parse_header(compose, msginfo) < 0) return;
1270 compose_reedit_set_entry(compose, msginfo);
1272 text = GTK_STEXT(compose->text);
1273 gtk_stext_freeze(text);
1275 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1276 g_warning(_("Can't get text part\n"));
1278 while (fgets(buf, sizeof(buf), fp) != NULL)
1279 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1282 compose_attach_parts(compose, msginfo);
1284 gtk_stext_thaw(text);
1285 gtk_widget_grab_focus(compose->text);
1287 if (prefs_common.auto_exteditor)
1288 compose_exec_ext_editor(compose);
1291 GList *compose_get_compose_list(void)
1293 return compose_list;
1296 void compose_entry_append(Compose *compose, const gchar *address,
1297 ComposeEntryType type)
1303 if (!address || *address == '\0') return;
1305 #if 0 /* NEW COMPOSE GUI */
1308 entry = GTK_ENTRY(compose->cc_entry);
1311 entry = GTK_ENTRY(compose->bcc_entry);
1313 case COMPOSE_NEWSGROUPS:
1314 entry = GTK_ENTRY(compose->newsgroups_entry);
1318 entry = GTK_ENTRY(compose->to_entry);
1322 text = gtk_entry_get_text(entry);
1324 gtk_entry_append_text(entry, ", ");
1325 gtk_entry_append_text(entry, address);
1333 header = N_("Bcc:");
1335 case COMPOSE_REPLYTO:
1336 header = N_("Reply-To:");
1338 case COMPOSE_NEWSGROUPS:
1339 header = N_("Newsgroups:");
1341 case COMPOSE_FOLLOWUPTO:
1342 header = N_( "Followup-To:");
1349 header = prefs_common.trans_hdr ? gettext(header) : header;
1351 compose_add_header_entry(compose, header, (gchar *)address);
1354 static void compose_entries_set(Compose *compose, const gchar *mailto)
1356 gchar *subject = NULL;
1364 Xstrdup_a(tmp_mailto, mailto, return);
1368 p = strchr(tmp_mailto, '?');
1375 gchar *field, *value;
1392 if (*value == '\0') continue;
1394 if (!g_strcasecmp(field, "subject")) {
1395 Xalloca(subject, strlen(value) + 1, return);
1396 decode_uri(subject, value);
1397 } else if (!g_strcasecmp(field, "cc")) {
1399 } else if (!g_strcasecmp(field, "bcc")) {
1401 } else if (!g_strcasecmp(field, "body")) {
1402 Xalloca(body, strlen(value) + 1, return);
1403 decode_uri(body, value);
1408 compose_entry_append(compose, to, COMPOSE_TO);
1410 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1412 compose_entry_append(compose, cc, COMPOSE_CC);
1414 compose_entry_append(compose, bcc, COMPOSE_BCC);
1416 gtk_stext_insert(GTK_STEXT(compose->text),
1417 NULL, NULL, NULL, body, -1);
1418 gtk_stext_insert(GTK_STEXT(compose->text),
1419 NULL, NULL, NULL, "\n", 1);
1423 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1425 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1426 {"Cc:", NULL, FALSE},
1427 {"References:", NULL, FALSE},
1428 {"Bcc:", NULL, FALSE},
1429 {"Newsgroups:", NULL, FALSE},
1430 {"Followup-To:", NULL, FALSE},
1431 {"X-Mailing-List:", NULL, FALSE},
1432 {"X-BeenThere:", NULL, FALSE},
1433 {"X-Priority:", NULL, FALSE},
1434 {NULL, NULL, FALSE}};
1444 H_X_MAILING_LIST = 6,
1451 g_return_val_if_fail(msginfo != NULL, -1);
1453 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1454 procheader_get_header_fields(fp, hentry);
1457 if (hentry[H_REPLY_TO].body != NULL) {
1458 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1459 compose->replyto = hentry[H_REPLY_TO].body;
1460 hentry[H_REPLY_TO].body = NULL;
1462 if (hentry[H_CC].body != NULL) {
1463 conv_unmime_header_overwrite(hentry[H_CC].body);
1464 compose->cc = hentry[H_CC].body;
1465 hentry[H_CC].body = NULL;
1467 if (hentry[H_X_MAILING_LIST].body != NULL) {
1468 /* this is good enough to parse debian-devel */
1469 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1470 g_return_val_if_fail(buf != NULL, -1 );
1471 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1472 compose->mailinglist = g_strdup(buf);
1474 g_free(hentry[H_X_MAILING_LIST].body);
1475 hentry[H_X_MAILING_LIST].body = NULL ;
1477 if (hentry[H_X_BEENTHERE].body != NULL) {
1478 /* this is good enough to parse the sylpheed-claws lists */
1479 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1480 g_return_val_if_fail(buf != NULL, -1 );
1481 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1482 compose->mailinglist = g_strdup(buf);
1484 g_free(hentry[H_X_BEENTHERE].body);
1485 hentry[H_X_BEENTHERE].body = NULL ;
1487 if (hentry[H_REFERENCES].body != NULL) {
1488 if (compose->mode == COMPOSE_REEDIT)
1489 compose->references = hentry[H_REFERENCES].body;
1491 compose->references = compose_parse_references
1492 (hentry[H_REFERENCES].body, msginfo->msgid);
1493 g_free(hentry[H_REFERENCES].body);
1495 hentry[H_REFERENCES].body = NULL;
1497 if (hentry[H_BCC].body != NULL) {
1498 if (compose->mode == COMPOSE_REEDIT) {
1499 conv_unmime_header_overwrite(hentry[H_BCC].body);
1500 compose->bcc = hentry[H_BCC].body;
1502 g_free(hentry[H_BCC].body);
1503 hentry[H_BCC].body = NULL;
1505 if (hentry[H_NEWSGROUPS].body != NULL) {
1506 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1507 hentry[H_NEWSGROUPS].body = NULL;
1509 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1510 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1511 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1512 hentry[H_FOLLOWUP_TO].body = NULL;
1515 if (compose->mode == COMPOSE_REEDIT)
1516 if (hentry[H_X_PRIORITY].body != NULL) {
1519 priority = atoi(hentry[H_X_PRIORITY].body);
1520 g_free(hentry[H_X_PRIORITY].body);
1522 hentry[H_X_PRIORITY].body = NULL;
1524 if (priority < PRIORITY_HIGHEST ||
1525 priority > PRIORITY_LOWEST)
1526 priority = PRIORITY_NORMAL;
1528 compose->priority = priority;
1531 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1532 compose->inreplyto = g_strdup(msginfo->inreplyto);
1533 else if (compose->mode != COMPOSE_REEDIT &&
1534 msginfo->msgid && *msginfo->msgid) {
1535 compose->inreplyto = g_strdup(msginfo->msgid);
1537 if (!compose->references) {
1538 if (msginfo->inreplyto && *msginfo->inreplyto)
1539 compose->references =
1540 g_strdup_printf("<%s>\n\t<%s>",
1544 compose->references =
1545 g_strconcat("<", msginfo->msgid, ">",
1553 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1555 GSList *ref_id_list, *cur;
1559 ref_id_list = references_list_append(NULL, ref);
1560 if (!ref_id_list) return NULL;
1561 if (msgid && *msgid)
1562 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1567 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1568 /* "<" + Message-ID + ">" + CR+LF+TAB */
1569 len += strlen((gchar *)cur->data) + 5;
1571 if (len > MAX_REFERENCES_LEN) {
1572 /* remove second message-ID */
1573 if (ref_id_list && ref_id_list->next &&
1574 ref_id_list->next->next) {
1575 g_free(ref_id_list->next->data);
1576 ref_id_list = g_slist_remove
1577 (ref_id_list, ref_id_list->next->data);
1579 slist_free_strings(ref_id_list);
1580 g_slist_free(ref_id_list);
1587 new_ref = g_string_new("");
1588 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1589 if (new_ref->len > 0)
1590 g_string_append(new_ref, "\n\t");
1591 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1594 slist_free_strings(ref_id_list);
1595 g_slist_free(ref_id_list);
1597 new_ref_str = new_ref->str;
1598 g_string_free(new_ref, FALSE);
1603 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1604 const gchar *fmt, const gchar *qmark,
1607 GtkSText *text = GTK_STEXT(compose->text);
1608 gchar *quote_str = NULL;
1613 if (qmark != NULL) {
1614 quote_fmt_init(msginfo, NULL, NULL);
1615 quote_fmt_scan_string(qmark);
1618 buf = quote_fmt_get_buffer();
1620 alertpanel_error(_("Quote mark format error."));
1622 Xstrdup_a(quote_str, buf, return NULL)
1625 if (fmt && *fmt != '\0') {
1626 quote_fmt_init(msginfo, quote_str, body);
1627 quote_fmt_scan_string(fmt);
1630 buf = quote_fmt_get_buffer();
1632 alertpanel_error(_("Message reply/forward format error."));
1638 gtk_stext_freeze(text);
1640 for (p = buf; *p != '\0'; ) {
1641 lastp = strchr(p, '\n');
1642 len = lastp ? lastp - p + 1 : -1;
1643 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1650 gtk_stext_thaw(text);
1655 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1656 gboolean to_all, gboolean ignore_replyto,
1657 gboolean followup_and_reply_to)
1659 GSList *cc_list = NULL;
1662 gchar *replyto = NULL;
1663 GHashTable *to_table;
1665 g_return_if_fail(compose->account != NULL);
1666 g_return_if_fail(msginfo != NULL);
1668 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1669 compose_entry_append(compose,
1670 ((compose->replyto && !ignore_replyto)
1672 : (compose->mailinglist && !ignore_replyto)
1673 ? compose->mailinglist
1674 : msginfo->from ? msginfo->from : ""),
1677 if (compose->account->protocol == A_NNTP) {
1679 compose_entry_append
1680 (compose, msginfo->from ? msginfo->from : "",
1683 compose_entry_append
1685 compose->followup_to ? compose->followup_to
1686 : compose->newsgroups ? compose->newsgroups
1688 COMPOSE_NEWSGROUPS);
1691 if (msginfo->subject && *msginfo->subject) {
1692 gchar *buf, *buf2, *p;
1694 buf = g_strdup(msginfo->subject);
1695 while (!strncasecmp(buf, "Re:", 3)) {
1697 while (isspace(*p)) p++;
1698 memmove(buf, p, strlen(p) + 1);
1701 buf2 = g_strdup_printf("Re: %s", buf);
1702 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1706 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1708 if (!to_all || compose->account->protocol == A_NNTP) return;
1710 if (compose->replyto) {
1711 Xstrdup_a(replyto, compose->replyto, return);
1712 extract_address(replyto);
1714 if (msginfo->from) {
1715 Xstrdup_a(from, msginfo->from, return);
1716 extract_address(from);
1719 if (compose->mailinglist && from) {
1720 cc_list = address_list_append(cc_list, from);
1723 if (replyto && from)
1724 cc_list = address_list_append(cc_list, from);
1726 if (!compose->mailinglist)
1727 cc_list = address_list_append(cc_list, msginfo->to);
1729 cc_list = address_list_append(cc_list, compose->cc);
1731 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1733 g_hash_table_insert(to_table, replyto, GINT_TO_POINTER(1));
1734 if (compose->account)
1735 g_hash_table_insert(to_table, compose->account->address,
1736 GINT_TO_POINTER(1));
1738 /* remove address on To: and that of current account */
1739 for (cur = cc_list; cur != NULL; ) {
1740 GSList *next = cur->next;
1742 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1743 cc_list = g_slist_remove(cc_list, cur->data);
1745 g_hash_table_insert(to_table, cur->data, cur);
1749 g_hash_table_destroy(to_table);
1752 for (cur = cc_list; cur != NULL; cur = cur->next)
1753 compose_entry_append(compose, (gchar *)cur->data,
1755 slist_free_strings(cc_list);
1756 g_slist_free(cc_list);
1760 #define SET_ENTRY(entry, str) \
1763 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1766 #define SET_ADDRESS(type, str) \
1769 compose_entry_append(compose, str, type); \
1772 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1774 g_return_if_fail(msginfo != NULL);
1776 SET_ENTRY(subject_entry, msginfo->subject);
1777 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1778 SET_ADDRESS(COMPOSE_CC, compose->cc);
1779 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1780 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1782 compose_update_priority_menu_item(compose);
1784 compose_show_first_last_header(compose, TRUE);
1786 #if 0 /* NEW COMPOSE GUI */
1788 GtkItemFactory *ifactory;
1789 GtkWidget *menuitem;
1791 ifactory = gtk_item_factory_from_widget(compose->menubar);
1792 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1793 gtk_check_menu_item_set_active
1794 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1796 if (compose->replyto) {
1797 GtkItemFactory *ifactory;
1798 GtkWidget *menuitem;
1800 ifactory = gtk_item_factory_from_widget(compose->menubar);
1801 menuitem = gtk_item_factory_get_item
1802 (ifactory, "/View/Reply to");
1803 gtk_check_menu_item_set_active
1804 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1812 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1819 size_t buf_len = 128;
1821 if (strlen(sigfile) < 2)
1824 sigprg = popen(sigfile+1, "r");
1827 buf = g_malloc(buf_len);
1830 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1831 "Unable to insert signature (malloc failed)\n", -1);
1837 while (!feof(sigprg)) {
1838 bzero(buf, buf_len);
1839 fread(buf, buf_len-1, 1, sigprg);
1840 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1848 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1849 "Can't exec file: ", -1);
1850 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1855 static void compose_insert_sig(Compose *compose)
1859 if (compose->account && compose->account->sig_path)
1860 sigfile = g_strdup(compose->account->sig_path);
1862 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1863 DEFAULT_SIGNATURE, NULL);
1865 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1870 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1871 if (prefs_common.sig_sep) {
1872 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1873 prefs_common.sig_sep, -1);
1874 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1878 if (sigfile[0] == '|')
1879 compose_exec_sig(compose, sigfile);
1881 compose_insert_file(compose, sigfile);
1885 static void compose_insert_file(Compose *compose, const gchar *file)
1887 GtkSText *text = GTK_STEXT(compose->text);
1888 gchar buf[BUFFSIZE];
1892 g_return_if_fail(file != NULL);
1894 if ((fp = fopen(file, "rb")) == NULL) {
1895 FILE_OP_ERROR(file, "fopen");
1899 gtk_stext_freeze(text);
1901 while (fgets(buf, sizeof(buf), fp) != NULL) {
1902 /* strip <CR> if DOS/Windows file,
1903 replace <CR> with <LF> if Macintosh file. */
1906 if (len > 0 && buf[len - 1] != '\n') {
1908 if (buf[len] == '\r') buf[len] = '\n';
1910 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1913 gtk_stext_thaw(text);
1918 static void compose_attach_append(Compose *compose, const gchar *file,
1919 const gchar *filename,
1920 const gchar *content_type)
1923 gchar *text[N_ATTACH_COLS];
1928 if (!is_file_exist(file)) {
1929 g_warning(_("File %s doesn't exist\n"), file);
1932 if ((size = get_file_size(file)) < 0) {
1933 g_warning(_("Can't get file size of %s\n"), file);
1937 alertpanel_notice(_("File %s is empty."), file);
1940 if ((fp = fopen(file, "rb")) == NULL) {
1941 alertpanel_error(_("Can't read %s."), file);
1946 #if 0 /* NEW COMPOSE GUI */
1947 if (!compose->use_attach) {
1948 GtkItemFactory *ifactory;
1949 GtkWidget *menuitem;
1951 ifactory = gtk_item_factory_from_widget(compose->menubar);
1952 menuitem = gtk_item_factory_get_item(ifactory,
1953 "/View/Attachment");
1954 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1958 ainfo = g_new0(AttachInfo, 1);
1959 ainfo->file = g_strdup(file);
1962 ainfo->content_type = g_strdup(content_type);
1963 if (!strcasecmp(content_type, "message/rfc822")) {
1964 ainfo->encoding = ENC_7BIT;
1965 ainfo->name = g_strdup_printf
1967 g_basename(filename ? filename : file));
1969 if (!g_strncasecmp(content_type, "text", 4))
1971 procmime_get_encoding_for_file(file);
1973 ainfo->encoding = ENC_BASE64;
1974 ainfo->name = g_strdup
1975 (g_basename(filename ? filename : file));
1978 ainfo->content_type = procmime_get_mime_type(file);
1979 if (!ainfo->content_type) {
1980 ainfo->content_type =
1981 g_strdup("application/octet-stream");
1982 ainfo->encoding = ENC_BASE64;
1983 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
1984 ainfo->encoding = procmime_get_encoding_for_file(file);
1986 ainfo->encoding = ENC_BASE64;
1987 ainfo->name = g_strdup(g_basename(filename ? filename : file));
1991 text[COL_MIMETYPE] = ainfo->content_type;
1992 text[COL_SIZE] = to_human_readable(size);
1993 text[COL_NAME] = ainfo->name;
1995 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1996 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1999 #define IS_FIRST_PART_TEXT(info) \
2000 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
2001 info->mime_type == MIME_TEXT_ENRICHED) || \
2002 (info->mime_type == MIME_MULTIPART && info->content_type && \
2003 !strcasecmp(info->content_type, "multipart/alternative") && \
2004 (info->children && \
2005 (info->children->mime_type == MIME_TEXT || \
2006 info->children->mime_type == MIME_TEXT_HTML || \
2007 info->children->mime_type == MIME_TEXT_ENRICHED))))
2009 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2016 mimeinfo = procmime_scan_message(msginfo);
2017 if (!mimeinfo) return;
2019 /* skip first text (presumably message body) */
2020 child = mimeinfo->children;
2021 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
2022 procmime_mimeinfo_free_all(mimeinfo);
2025 if (IS_FIRST_PART_TEXT(child))
2026 child = child->next;
2028 infile = procmsg_get_message_file_path(msginfo);
2030 while (child != NULL) {
2031 if (child->children || child->mime_type == MIME_MULTIPART) {
2032 child = procmime_mimeinfo_next(child);
2036 outfile = procmime_get_tmp_file_name(child);
2037 if (procmime_get_part(outfile, infile, child) < 0)
2038 g_warning(_("Can't get the part of multipart message."));
2040 compose_attach_append
2042 child->filename ? child->filename : child->name,
2043 child->content_type);
2045 child = child->next;
2049 procmime_mimeinfo_free_all(mimeinfo);
2052 #undef IS_FIRST_PART_TEXT
2054 #define GET_CHAR(pos, buf, len) \
2056 if (text->use_wchar) \
2057 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2059 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2064 #define INDENT_CHARS ">|#"
2065 #define SPACE_CHARS " \t"
2067 static void compose_wrap_line(Compose *compose)
2069 GtkSText *text = GTK_STEXT(compose->text);
2070 gint ch_len, last_ch_len;
2071 gchar cbuf[MB_LEN_MAX], last_ch;
2075 gint p_start, p_end;
2076 gint line_pos, cur_pos;
2077 gint line_len, cur_len;
2079 gtk_stext_freeze(text);
2081 text_len = gtk_stext_get_length(text);
2083 /* check to see if the point is on the paragraph mark (empty line). */
2084 cur_pos = gtk_stext_get_point(text);
2085 GET_CHAR(cur_pos, cbuf, ch_len);
2086 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2088 goto compose_end; /* on the paragraph mark */
2089 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2090 if (ch_len == 1 && *cbuf == '\n')
2091 goto compose_end; /* on the paragraph mark */
2094 /* find paragraph start. */
2095 line_end = quoted = 0;
2096 for (p_start = cur_pos; p_start >= 0; --p_start) {
2097 GET_CHAR(p_start, cbuf, ch_len);
2098 if (ch_len == 1 && *cbuf == '\n') {
2100 goto compose_end; /* quoted part */
2108 && strchr(prefs_common.quote_chars, *cbuf))
2110 else if (ch_len != 1 || !isspace(*cbuf))
2119 /* find paragraph end. */
2121 for (p_end = cur_pos; p_end < text_len; p_end++) {
2122 GET_CHAR(p_end, cbuf, ch_len);
2123 if (ch_len == 1 && *cbuf == '\n') {
2130 if (line_end && ch_len == 1 &&
2131 strchr(prefs_common.quote_chars, *cbuf))
2132 goto compose_end; /* quoted part */
2137 if (p_end >= text_len)
2140 if (p_start >= p_end)
2143 line_len = cur_len = 0;
2147 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2150 GET_CHAR(cur_pos, cbuf, ch_len);
2157 if (ch_len == 1 && isspace(*cbuf))
2160 if (ch_len == 1 && *cbuf == '\n') {
2162 if (last_ch_len == 1 && !isspace(last_ch)) {
2163 if (cur_pos + 1 < p_end) {
2164 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2165 if (ch_len == 1 && !isspace(*cbuf))
2169 gtk_stext_set_point(text, cur_pos + 1);
2170 gtk_stext_backward_delete(text, 1);
2172 gtk_stext_set_point(text, cur_pos);
2173 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2183 last_ch_len = ch_len;
2187 line_pos = cur_pos + 1;
2188 line_len = cur_len + ch_len;
2191 if (cur_len + ch_len > prefs_common.linewrap_len &&
2195 GET_CHAR(line_pos - 1, cbuf, ch_len);
2196 if (ch_len == 1 && isspace(*cbuf)) {
2197 gtk_stext_set_point(text, line_pos);
2198 gtk_stext_backward_delete(text, 1);
2207 gtk_stext_set_point(text, line_pos);
2208 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2212 cur_len = cur_len - line_len + ch_len;
2218 line_pos = cur_pos + 1;
2219 line_len = cur_len + ch_len;
2225 gtk_stext_thaw(text);
2230 /* Darko: used when I debug wrapping */
2231 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2236 printf("%d [", pos);
2237 for (i = pos; i < tlen; i++) {
2238 ch = GTK_STEXT_INDEX(text, i);
2239 if (breakoncr && ch == '\n')
2249 WAIT_FOR_INDENT_CHAR,
2250 WAIT_FOR_INDENT_CHAR_OR_SPACE
2253 /* return indent length, we allow:
2254 > followed by spaces/tabs
2255 | followed by spaces/tabs
2256 uppercase characters immediately followed by >,
2257 and the repeating sequences of the above */
2258 /* return indent length */
2259 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2262 guint i, ch_len, alnum_cnt = 0;
2263 IndentState state = WAIT_FOR_INDENT_CHAR;
2264 gchar cbuf[MB_LEN_MAX];
2268 for (i = start_pos; i < text_len; i++) {
2269 GET_CHAR(i, cbuf, ch_len);
2273 if (cbuf[0] == '\n')
2276 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2277 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2280 case WAIT_FOR_SPACE:
2281 if (is_space == FALSE)
2283 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2285 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2286 if (is_indent == FALSE && is_space == FALSE &&
2289 if (is_space == TRUE) {
2291 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2292 } else if (is_indent == TRUE) {
2294 state = WAIT_FOR_SPACE;
2297 state = WAIT_FOR_INDENT_CHAR;
2300 case WAIT_FOR_INDENT_CHAR:
2301 if (is_indent == FALSE && !isupper(cbuf[0]))
2303 if (is_indent == TRUE) {
2305 && !strchr(prefs_common.quote_chars, cbuf[0]))
2308 state = WAIT_FOR_SPACE;
2319 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2325 /* insert quotation string when line was wrapped */
2326 static guint ins_quote(GtkSText *text, guint indent_len,
2327 guint prev_line_pos, guint text_len,
2334 for (i = 0; i < indent_len; i++) {
2335 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2336 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2338 ins_len = indent_len;
2344 /* check if we should join the next line */
2345 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2348 guint indent_len, ch_len;
2349 gboolean do_join = FALSE;
2350 gchar cbuf[MB_LEN_MAX];
2352 indent_len = get_indent_length(text, start_pos, tlen);
2354 if ((indent_len > 0) && (indent_len == prev_ilen)) {
2355 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2356 if (ch_len > 0 && (cbuf[0] != '\n'))
2363 static void compose_wrap_line_all(Compose *compose)
2365 GtkSText *text = GTK_STEXT(compose->text);
2367 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2368 gint line_len = 0, cur_len = 0;
2370 gboolean is_new_line = TRUE, do_delete = FALSE;
2372 gboolean linewrap_quote = TRUE;
2373 guint linewrap_len = prefs_common.linewrap_len;
2374 gchar *qfmt = prefs_common.quotemark;
2375 gchar cbuf[MB_LEN_MAX];
2377 gtk_stext_freeze(text);
2379 /* make text buffer contiguous */
2380 /* gtk_stext_compact_buffer(text); */
2382 tlen = gtk_stext_get_length(text);
2384 for (; cur_pos < tlen; cur_pos++) {
2385 /* mark position of new line - needed for quotation wrap */
2388 i_len = get_indent_length(text, cur_pos, tlen);
2390 is_new_line = FALSE;
2393 printf("new line i_len=%d p_pos=", i_len);
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') {
2421 gchar cb[MB_CUR_MAX];
2423 /* should we join the next line */
2424 if ((i_len != cur_len) && do_delete &&
2425 join_next_line(text, cur_pos + 1, tlen, i_len))
2431 printf("found CR at %d do_del is %d next line is ",
2432 cur_pos, do_delete);
2433 dump_text(text, cur_pos + 1, tlen, 1);
2436 /* skip delete if it is continuous URL */
2437 if (do_delete && (line_pos - p_pos <= i_len) &&
2438 gtkut_stext_is_uri_string(text, line_pos, tlen))
2442 printf("l_len=%d wrap_len=%d do_del=%d\n",
2443 line_len, linewrap_len, do_delete);
2445 /* should we delete to perform smart wrapping */
2446 if (line_len < linewrap_len && do_delete) {
2447 /* get rid of newline */
2448 gtk_stext_set_point(text, cur_pos);
2449 gtk_stext_forward_delete(text, 1);
2452 /* if text starts with quote fmt or with
2453 indent string, delete them */
2456 ilen = gtkut_stext_str_compare_n
2457 (text, cur_pos, p_pos, i_len,
2460 gtk_stext_forward_delete
2466 GET_CHAR(cur_pos, cb, clen);
2468 /* insert space if it's alphanumeric */
2469 if ((cur_pos != line_pos) &&
2470 ((clen > 1) || isalnum(cb[0]))) {
2471 gtk_stext_insert(text, NULL, NULL,
2473 /* gtk_stext_compact_buffer(text); */
2477 /* and start over with current line */
2478 cur_pos = p_pos - 1;
2480 line_len = cur_len = 0;
2484 printf("after delete l_pos=");
2485 dump_text(text, line_pos, tlen, 1);
2490 /* mark new line beginning */
2491 line_pos = cur_pos + 1;
2492 line_len = cur_len = 0;
2503 /* possible line break */
2504 if (ch_len == 1 && isspace(*cbuf)) {
2505 line_pos = cur_pos + 1;
2506 line_len = cur_len + ch_len;
2509 /* are we over wrapping length set in preferences ? */
2510 if (cur_len + ch_len > linewrap_len) {
2514 printf("should wrap cur_pos=%d ", cur_pos);
2515 dump_text(text, p_pos, tlen, 1);
2516 dump_text(text, line_pos, tlen, 1);
2518 /* force wrapping if it is one long word but not URL */
2519 if (line_pos - p_pos <= i_len)
2520 if (!gtkut_stext_is_uri_string
2521 (text, line_pos, tlen))
2522 line_pos = cur_pos - 1;
2524 printf("new line_pos=%d\n", line_pos);
2527 GET_CHAR(line_pos - 1, cbuf, clen);
2529 /* if next character is space delete it */
2530 if (clen == 1 && isspace(*cbuf)) {
2531 if (p_pos + i_len != line_pos ||
2532 !gtkut_stext_is_uri_string
2533 (text, line_pos, tlen)) {
2534 gtk_stext_set_point(text, line_pos);
2535 gtk_stext_backward_delete(text, 1);
2544 /* if it is URL at beginning of line don't wrap */
2545 if (p_pos + i_len == line_pos &&
2546 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2548 printf("found URL at ");
2549 dump_text(text, line_pos, tlen, 1);
2555 gtk_stext_set_point(text, line_pos);
2556 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2557 /* gtk_stext_compact_buffer(text); */
2560 /* for loop will increase it */
2561 cur_pos = line_pos - 1;
2562 /* start over with current line */
2571 printf("after CR insert ");
2572 dump_text(text, line_pos, tlen, 1);
2573 dump_text(text, cur_pos, tlen, 1);
2576 /* should we insert quotation ? */
2577 if (linewrap_quote && i_len) {
2578 /* only if line is not already quoted */
2579 if (!gtkut_stext_str_compare
2580 (text, line_pos, tlen, qfmt)) {
2583 if (line_pos - p_pos > i_len) {
2585 (text, i_len, p_pos,
2588 /* gtk_stext_compact_buffer(text); */
2592 printf("after quote insert ");
2593 dump_text(text, line_pos, tlen, 1);
2601 line_pos = cur_pos + 1;
2602 line_len = cur_len + ch_len;
2604 /* advance to next character in buffer */
2608 gtk_stext_thaw(text);
2613 static void compose_set_title(Compose *compose)
2618 edited = compose->modified ? _(" [Edited]") : "";
2619 if (compose->account && compose->account->address)
2620 str = g_strdup_printf(_("%s - Compose message%s"),
2621 compose->account->address, edited);
2623 str = g_strdup_printf(_("Compose message%s"), edited);
2624 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2629 * compose_current_mail_account:
2631 * Find a current mail account (the currently selected account, or the
2632 * default account, if a news account is currently selected). If a
2633 * mail account cannot be found, display an error message.
2635 * Return value: Mail account, or NULL if not found.
2637 static PrefsAccount *
2638 compose_current_mail_account(void)
2642 if (cur_account && cur_account->protocol != A_NNTP)
2645 ac = account_get_default();
2646 if (!ac || ac->protocol == A_NNTP) {
2647 alertpanel_error(_("Account for sending mail is not specified.\n"
2648 "Please select a mail account before sending."));
2655 gboolean compose_check_for_valid_recipient(Compose *compose) {
2656 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2657 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2658 gboolean recipient_found = FALSE;
2662 /* free to and newsgroup list */
2663 slist_free_strings(compose->to_list);
2664 g_slist_free(compose->to_list);
2665 compose->to_list = NULL;
2667 slist_free_strings(compose->newsgroup_list);
2668 g_slist_free(compose->newsgroup_list);
2669 compose->newsgroup_list = NULL;
2671 /* search header entries for to and newsgroup entries */
2672 for(list = compose->header_list; list; list = list->next) {
2675 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2676 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2678 if(entry[0] != '\0') {
2679 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2680 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2681 compose->to_list = address_list_append(compose->to_list, entry);
2682 recipient_found = TRUE;
2685 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2686 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2687 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2688 recipient_found = TRUE;
2694 return recipient_found;
2697 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
2701 if (compose_check_for_valid_recipient(compose) == FALSE) {
2702 alertpanel_error(_("Recipient is not specified."));
2706 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2707 if (*str == '\0' && check_subject == TRUE) {
2710 aval = alertpanel(_("Send"),
2711 _("Subject is empty. Send it anyway?"),
2712 _("Yes"), _("No"), NULL);
2713 if (aval != G_ALERTDEFAULT)
2720 gint compose_send(Compose *compose)
2726 if (compose_check_entries(compose, TRUE) == FALSE)
2729 val = compose_queue(compose, &msgnum, &folder);
2731 alertpanel_error(_("Could not queue message for sending"));
2735 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2737 folder_item_remove_msg(folder, msgnum);
2738 folderview_update_item(folder, TRUE);
2743 #if 0 /* compose restructure */
2744 gint compose_send(Compose *compose)
2746 gchar tmp[MAXPATHLEN + 1];
2748 static gboolean lock = FALSE;
2752 g_return_val_if_fail(compose->account != NULL, -1);
2753 g_return_val_if_fail(compose->orig_account != NULL, -1);
2757 if (compose_check_entries(compose, TRUE) == FALSE) {
2762 /* write to temporary file */
2763 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2764 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2766 if (prefs_common.linewrap_at_send)
2767 compose_wrap_line_all(compose);
2769 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2774 if (!compose->to_list && !compose->newsgroup_list) {
2775 g_warning(_("can't get recipient list."));
2781 if (compose->to_list) {
2784 #if 0 /* NEW COMPOSE GUI */
2785 if (compose->account->protocol != A_NNTP)
2786 ac = compose->account;
2787 else if (compose->orig_account->protocol != A_NNTP)
2788 ac = compose->orig_account;
2789 else if (cur_account && cur_account->protocol != A_NNTP)
2792 ac = compose_current_mail_account();
2800 ac = compose->account;
2802 ok = send_message(tmp, ac, compose->to_list);
2803 statusbar_pop_all();
2806 if (ok == 0 && compose->newsgroup_list) {
2809 if (compose->account->protocol == A_NNTP)
2810 folder = FOLDER(compose->account->folder);
2812 folder = FOLDER(compose->orig_account->folder);
2814 ok = news_post(folder, tmp);
2816 alertpanel_error(_("Error occurred while posting the message to %s ."),
2817 compose->account->nntp_server);
2824 /* queue message if failed to send */
2826 if (prefs_common.queue_msg) {
2831 _("Error occurred while sending the message.\n"
2832 "Put this message into queue folder?"),
2833 _("OK"), _("Cancel"), NULL);
2834 if (G_ALERTDEFAULT == val) {
2835 ok = compose_queue(compose, tmp);
2837 alertpanel_error(_("Can't queue the message."));
2840 alertpanel_error(_("Error occurred while sending the message."));
2842 if (compose->mode == COMPOSE_REEDIT) {
2843 compose_remove_reedit_target(compose);
2844 if (compose->targetinfo)
2845 folderview_update_item
2846 (compose->targetinfo->folder, TRUE);
2848 /* save message to outbox */
2849 if (prefs_common.savemsg) {
2852 outbox = account_get_special_folder
2853 (compose->account, F_OUTBOX);
2854 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
2856 (_("Can't save the message to Sent."));
2858 folderview_update_item(outbox, TRUE);
2868 static gboolean compose_use_attach(Compose *compose) {
2869 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2872 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
2875 gchar buf[BUFFSIZE];
2877 gboolean first_address;
2879 ComposeHeaderEntry *headerentry;
2880 gchar *headerentryname;
2884 debug_print(_("Writing redirect header\n"));
2886 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
2887 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
2889 first_address = TRUE;
2890 for(list = compose->header_list; list; list = list->next) {
2891 headerentry = ((ComposeHeaderEntry *)list->data);
2892 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2894 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2895 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2896 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2897 Xstrdup_a(str, str, return -1);
2899 if(str[0] != '\0') {
2900 compose_convert_header
2901 (buf, sizeof(buf), str,
2902 strlen("Resent-To") + 2);
2904 fprintf(fp, "Resent-To: ");
2905 first_address = FALSE;
2909 fprintf(fp, "%s", buf);
2913 /* if(!first_address) { */
2920 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
2922 gchar buf[BUFFSIZE];
2924 /* struct utsname utsbuf; */
2926 g_return_val_if_fail(fp != NULL, -1);
2927 g_return_val_if_fail(compose->account != NULL, -1);
2928 g_return_val_if_fail(compose->account->address != NULL, -1);
2931 get_rfc822_date(buf, sizeof(buf));
2932 fprintf(fp, "Resent-Date: %s\n", buf);
2935 if (compose->account->name && *compose->account->name) {
2936 compose_convert_header
2937 (buf, sizeof(buf), compose->account->name,
2939 fprintf(fp, "Resent-From: %s <%s>\n",
2940 buf, compose->account->address);
2942 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2945 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2947 Xstrdup_a(str, str, return -1);
2950 compose_convert_header(buf, sizeof(buf), str,
2951 strlen("Subject: "));
2952 fprintf(fp, "Subject: %s\n", buf);
2956 /* Resent-Message-ID */
2957 if (compose->account->gen_msgid) {
2958 compose_generate_msgid(compose, buf, sizeof(buf));
2959 fprintf(fp, "Resent-Message-Id: <%s>\n", buf);
2960 compose->msgid = g_strdup(buf);
2963 compose_redirect_write_headers_from_headerlist(compose, fp);
2965 /* separator between header and body */
2971 static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
2976 gchar buf[BUFFSIZE];
2978 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
2979 FILE_OP_ERROR(file, "fopen");
2983 if ((fdest = fopen(file, "wb")) == NULL) {
2984 FILE_OP_ERROR(file, "fopen");
2989 /* chmod for security */
2990 if (change_file_mode_rw(fdest, file) < 0) {
2991 FILE_OP_ERROR(file, "chmod");
2992 g_warning(_("can't change file mode\n"));
2995 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2996 /* should filter returnpath, delivered-to */
2997 if (g_strncasecmp(buf, "Return-Path:",
2998 strlen("Return-Path:")) == 0 ||
2999 g_strncasecmp(buf, "Delivered-To:",
3000 strlen("Delivered-To:")) == 0 ||
3001 g_strncasecmp(buf, "Received:",
3002 strlen("Received:")) == 0 ||
3003 g_strncasecmp(buf, "Subject:",
3004 strlen("Subject:")) == 0 ||
3005 g_strncasecmp(buf, "X-UIDL:",
3006 strlen("X-UIDL:")) == 0)
3009 if (fputs(buf, fdest) == -1)
3012 if (!prefs_common.redirect_keep_from) {
3013 if (g_strncasecmp(buf, "From:",
3014 strlen("From:")) == 0) {
3015 fputs(" (by way of ", fdest);
3016 if (compose->account->name
3017 && *compose->account->name) {
3018 compose_convert_header
3020 compose->account->name,
3022 fprintf(fdest, "%s <%s>",
3024 compose->account->address);
3026 fprintf(fdest, "%s",
3027 compose->account->address);
3032 if (fputs("\n", fdest) == -1)
3036 compose_redirect_write_headers(compose, fdest);
3038 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3039 if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
3040 FILE_OP_ERROR(file, "fwrite");
3046 if (fclose(fdest) == EOF) {
3047 FILE_OP_ERROR(file, "fclose");
3064 * interfaces to rfc2015 to keep out the prefs stuff there.
3065 * returns 0 on success and -1 on error. */
3066 static int compose_create_signers_list (Compose *compose, GSList **pkey_list)
3068 const char *keyid = NULL;
3071 switch (compose->account->sign_key) {
3072 case SIGN_KEY_DEFAULT:
3074 return 0; /* nothing to do */
3076 case SIGN_KEY_BY_FROM:
3077 keyid = compose->account->address;
3080 case SIGN_KEY_CUSTOM:
3081 keyid = compose->account->sign_key_id;
3085 g_assert_not_reached ();
3088 key_list = rfc2015_create_signers_list(keyid);
3091 alertpanel_error("Could not find any key associated with currently "
3092 "selected keyid `%s'!", keyid);
3096 *pkey_list = key_list;
3099 #endif /* USE_GPGME */
3101 static gint compose_write_to_file(Compose *compose, const gchar *file,
3108 const gchar *out_codeset;
3109 EncodingType encoding;
3111 if ((fp = fopen(file, "wb")) == NULL) {
3112 FILE_OP_ERROR(file, "fopen");
3116 /* chmod for security */
3117 if (change_file_mode_rw(fp, file) < 0) {
3118 FILE_OP_ERROR(file, "chmod");
3119 g_warning(_("can't change file mode\n"));
3122 /* get all composed text */
3123 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3124 len = strlen(chars);
3125 if (is_ascii_str(chars)) {
3126 buf = g_strdup(chars);
3127 out_codeset = CS_US_ASCII;
3128 encoding = ENC_7BIT;
3130 const gchar *src_codeset;
3132 out_codeset = conv_get_outgoing_charset_str();
3133 if (!strcasecmp(out_codeset, CS_US_ASCII))
3134 out_codeset = CS_ISO_8859_1;
3135 encoding = procmime_get_encoding_for_charset(out_codeset);
3137 src_codeset = conv_get_current_charset_str();
3138 /* if current encoding is US-ASCII, set it the same as
3139 outgoing one to prevent code conversion failure */
3140 if (!strcasecmp(src_codeset, CS_US_ASCII))
3141 src_codeset = out_codeset;
3143 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3144 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3146 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3152 _("Can't convert the character encoding of the message.\n"
3153 "Send it anyway?"), _("Yes"), _("+No"), NULL);
3154 if (aval != G_ALERTDEFAULT) {
3160 buf = g_strdup(chars);
3167 if (compose_write_headers
3168 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3169 g_warning(_("can't write headers\n"));
3176 if (compose_use_attach(compose)) {
3178 /* This prolog message is ignored by mime software and
3179 * because it would make our signing/encryption task
3180 * tougher, we don't emit it in that case */
3181 if (!compose->use_signing && !compose->use_encryption)
3183 fputs("This is a multi-part message in MIME format.\n", fp);
3185 fprintf(fp, "\n--%s\n", compose->boundary);
3186 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3188 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3189 procmime_get_encoding_str(encoding));
3195 if (encoding == ENC_BASE64) {
3196 gchar outbuf[B64_BUFFSIZE];
3199 for (i = 0; i < len; i += B64_LINE_SIZE) {
3200 l = MIN(B64_LINE_SIZE, len - i);
3201 to64frombits(outbuf, buf + i, l);
3205 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3206 FILE_OP_ERROR(file, "fwrite");
3214 if (compose_use_attach(compose))
3215 compose_write_attach(compose, fp);
3217 if (fclose(fp) == EOF) {
3218 FILE_OP_ERROR(file, "fclose");
3224 if (compose->use_signing) {
3227 if (compose_create_signers_list(compose, &key_list) == -1 ||
3228 rfc2015_sign(file, key_list) < 0) {
3234 if (compose->use_encryption) {
3235 if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) {
3240 #endif /* USE_GPGME */
3245 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3251 if ((fp = fopen(file, "wb")) == NULL) {
3252 FILE_OP_ERROR(file, "fopen");
3256 /* chmod for security */
3257 if (change_file_mode_rw(fp, file) < 0) {
3258 FILE_OP_ERROR(file, "chmod");
3259 g_warning(_("can't change file mode\n"));
3262 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3265 len = strlen(chars);
3266 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3267 FILE_OP_ERROR(file, "fwrite");
3276 if (fclose(fp) == EOF) {
3277 FILE_OP_ERROR(file, "fclose");
3284 static gint compose_remove_reedit_target(Compose *compose)
3287 MsgInfo *msginfo = compose->targetinfo;
3289 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3290 if (!msginfo) return -1;
3292 item = msginfo->folder;
3293 g_return_val_if_fail(item != NULL, -1);
3295 folder_item_scan(item);
3296 if (procmsg_msg_exist(msginfo) &&
3297 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3298 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3299 g_warning(_("can't remove the old message\n"));
3307 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3309 return compose_queue_sub (compose, msgnum, item, FALSE);
3311 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3317 gchar buf[BUFFSIZE];
3319 MsgFlags flag = {0, 0};
3320 static gboolean lock = FALSE;
3321 PrefsAccount *mailac = NULL, *newsac = NULL;
3323 debug_print(_("queueing message...\n"));
3324 g_return_val_if_fail(compose->account != NULL, -1);
3325 g_return_val_if_fail(compose->orig_account != NULL, -1);
3329 if (compose_check_entries(compose, check_subject) == FALSE) {
3334 if (!compose->to_list && !compose->newsgroup_list) {
3335 g_warning(_("can't get recipient list."));
3340 if(compose->to_list) {
3341 if (compose->account->protocol != A_NNTP)
3342 mailac = compose->account;
3343 else if (compose->orig_account->protocol != A_NNTP)
3344 mailac = compose->orig_account;
3345 else if (cur_account && cur_account->protocol != A_NNTP)
3346 mailac = cur_account;
3347 else if (!(mailac = compose_current_mail_account())) {
3349 alertpanel_error(_("No account for sending mails available!"));
3354 if(compose->newsgroup_list) {
3355 if (compose->account->protocol == A_NNTP)
3356 newsac = compose->account;
3357 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3359 alertpanel_error(_("No account for posting news available!"));
3364 if (prefs_common.linewrap_at_send)
3365 compose_wrap_line_all(compose);
3367 /* write to temporary file */
3368 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3369 G_DIR_SEPARATOR, (gint)compose);
3371 if (compose->redirect_filename != NULL) {
3372 if (compose_redirect_write_to_file(compose, tmp2) < 0) {
3379 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3386 /* add queue header */
3387 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3388 G_DIR_SEPARATOR, (gint)compose);
3389 if ((fp = fopen(tmp, "wb")) == NULL) {
3390 FILE_OP_ERROR(tmp, "fopen");
3394 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3395 FILE_OP_ERROR(tmp2, "fopen");
3403 if (change_file_mode_rw(fp, tmp) < 0) {
3404 FILE_OP_ERROR(tmp, "chmod");
3405 g_warning(_("can't change file mode\n"));
3408 /* queueing variables */
3409 fprintf(fp, "AF:\n");
3410 fprintf(fp, "NF:0\n");
3411 fprintf(fp, "PS:10\n");
3412 fprintf(fp, "SRH:1\n");
3413 fprintf(fp, "SFN:\n");
3414 fprintf(fp, "DSR:\n");
3416 fprintf(fp, "MID:<%s>\n", compose->msgid);
3418 fprintf(fp, "MID:\n");
3419 fprintf(fp, "CFG:\n");
3420 fprintf(fp, "PT:0\n");
3421 fprintf(fp, "S:%s\n", compose->account->address);
3422 fprintf(fp, "RQ:\n");
3424 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3426 fprintf(fp, "SSV:\n");
3428 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3430 fprintf(fp, "NSV:\n");
3431 fprintf(fp, "SSH:\n");
3432 /* write recepient list */
3434 if(compose->to_list) {
3435 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3436 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3437 fprintf(fp, ",<%s>", (gchar *)cur->data);
3440 /* write newsgroup list */
3442 if(compose->newsgroup_list) {
3443 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3444 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3445 fprintf(fp, ",%s", (gchar *)cur->data);
3448 /* Sylpheed account IDs */
3450 fprintf(fp, "MAID:%d\n", mailac->account_id);
3453 fprintf(fp, "NAID:%d\n", newsac->account_id);
3455 /* Save copy folder */
3456 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3459 str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3460 fprintf(fp, "SCF:%s\n", str);
3465 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3466 if (fputs(buf, fp) == EOF) {
3467 FILE_OP_ERROR(tmp, "fputs");
3478 if (fclose(fp) == EOF) {
3479 FILE_OP_ERROR(tmp, "fclose");
3487 queue = account_get_special_folder(compose->account, F_QUEUE);
3489 g_warning(_("can't find queue folder\n"));
3494 folder_item_scan(queue);
3495 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3496 g_warning(_("can't queue the message\n"));
3506 if (compose->mode == COMPOSE_REEDIT) {
3507 compose_remove_reedit_target(compose);
3508 if (compose->targetinfo &&
3509 compose->targetinfo->folder != queue)
3510 folderview_update_item
3511 (compose->targetinfo->folder, TRUE);
3514 procmsg_add_flags(queue, num, flag);
3515 folder_item_scan(queue);
3516 folderview_update_item(queue, TRUE);
3518 if((msgnum != NULL) && (item != NULL)) {
3526 static void compose_write_attach(Compose *compose, FILE *fp)
3529 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3532 gchar filename[BUFFSIZE];
3535 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3537 gchar buf[BUFFSIZE];
3538 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3540 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
3541 g_warning(_("Can't open file %s\n"), ainfo->file);
3545 fprintf(fp, "\n--%s\n", compose->boundary);
3547 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3548 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3549 fprintf(fp, "Content-Disposition: inline\n");
3551 conv_encode_header(filename, sizeof(filename),
3553 fprintf(fp, "Content-Type: %s;\n"
3555 ainfo->content_type, filename);
3556 fprintf(fp, "Content-Disposition: attachment;\n"
3557 " filename=\"%s\"\n", filename);
3560 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3561 procmime_get_encoding_str(ainfo->encoding));
3563 switch (ainfo->encoding) {
3567 /* if (ainfo->encoding == ENC_7BIT) { */
3569 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3577 while ((len = fread(inbuf, sizeof(gchar),
3578 B64_LINE_SIZE, attach_fp))
3580 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3584 if (len > 0 && feof(attach_fp)) {
3585 to64frombits(outbuf, inbuf, len);
3595 fprintf(fp, "\n--%s--\n", compose->boundary);
3598 #define QUOTE_IF_REQUIRED(out, str) \
3600 if (*str != '"' && strchr(str, ',')) { \
3604 len = strlen(str) + 3; \
3605 Xalloca(__tmp, len, return -1); \
3606 g_snprintf(__tmp, len, "\"%s\"", str); \
3609 Xstrdup_a(out, str, return -1); \
3613 #define PUT_RECIPIENT_HEADER(header, str) \
3615 if (*str != '\0') { \
3616 Xstrdup_a(str, str, return -1); \
3618 if (*str != '\0') { \
3619 compose->to_list = address_list_append \
3620 (compose->to_list, str); \
3621 compose_convert_header \
3622 (buf, sizeof(buf), str, strlen(header) + 2); \
3623 fprintf(fp, "%s: %s\n", header, buf); \
3628 #define IS_IN_CUSTOM_HEADER(header) \
3629 (compose->account->add_customhdr && \
3630 custom_header_find(compose->account->customhdr_list, header) != NULL)
3632 static gint compose_write_headers_from_headerlist(Compose *compose,
3636 gchar buf[BUFFSIZE];
3637 gchar *str, *header_w_colon, *trans_hdr;
3638 gboolean first_address;
3640 ComposeHeaderEntry *headerentry;
3641 gchar * headerentryname;
3643 if (IS_IN_CUSTOM_HEADER(header)) {
3647 debug_print(_("Writing %s-header\n"), header);
3649 header_w_colon = g_strconcat(header, ":", NULL);
3650 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3652 first_address = TRUE;
3653 for(list = compose->header_list; list; list = list->next) {
3654 headerentry = ((ComposeHeaderEntry *)list->data);
3655 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3657 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3658 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3659 Xstrdup_a(str, str, return -1);
3661 if(str[0] != '\0') {
3662 compose_convert_header
3663 (buf, sizeof(buf), str,
3664 strlen(header) + 2);
3666 fprintf(fp, "%s: ", header);
3667 first_address = FALSE;
3671 fprintf(fp, "%s", buf);
3675 if(!first_address) {
3679 g_free(header_w_colon);
3684 static gint compose_write_headers(Compose *compose, FILE *fp,
3685 const gchar *charset, EncodingType encoding,
3688 gchar buf[BUFFSIZE];
3691 /* struct utsname utsbuf; */
3693 g_return_val_if_fail(fp != NULL, -1);
3694 g_return_val_if_fail(charset != NULL, -1);
3695 g_return_val_if_fail(compose->account != NULL, -1);
3696 g_return_val_if_fail(compose->account->address != NULL, -1);
3699 if (compose->account->add_date) {
3700 get_rfc822_date(buf, sizeof(buf));
3701 fprintf(fp, "Date: %s\n", buf);
3705 if (!IS_IN_CUSTOM_HEADER("From")) {
3706 if (compose->account->name && *compose->account->name) {
3707 compose_convert_header
3708 (buf, sizeof(buf), compose->account->name,
3710 QUOTE_IF_REQUIRED(name, buf);
3711 fprintf(fp, "From: %s <%s>\n",
3712 name, compose->account->address);
3714 fprintf(fp, "From: %s\n", compose->account->address);
3718 compose_write_headers_from_headerlist(compose, fp, "To");
3719 #if 0 /* NEW COMPOSE GUI */
3720 if (compose->use_to) {
3721 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3722 PUT_RECIPIENT_HEADER("To", str);
3727 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3728 #if 0 /* NEW COMPOSE GUI */
3729 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3731 Xstrdup_a(str, str, return -1);
3735 compose->newsgroup_list =
3736 newsgroup_list_append(compose->newsgroup_list,
3738 compose_convert_header(buf, sizeof(buf), str,
3739 strlen("Newsgroups: "));
3740 fprintf(fp, "Newsgroups: %s\n", buf);
3745 compose_write_headers_from_headerlist(compose, fp, "Cc");
3746 #if 0 /* NEW COMPOSE GUI */
3747 if (compose->use_cc) {
3748 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3749 PUT_RECIPIENT_HEADER("Cc", str);
3753 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3754 #if 0 /* NEW COMPOSE GUI */
3755 if (compose->use_bcc) {
3756 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3757 PUT_RECIPIENT_HEADER("Bcc", str);
3762 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3763 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3764 Xstrdup_a(str, str, return -1);
3767 compose_convert_header(buf, sizeof(buf), str,
3768 strlen("Subject: "));
3769 fprintf(fp, "Subject: %s\n", buf);
3774 if (compose->account->gen_msgid) {
3775 compose_generate_msgid(compose, buf, sizeof(buf));
3776 fprintf(fp, "Message-Id: <%s>\n", buf);
3777 compose->msgid = g_strdup(buf);
3781 if (compose->inreplyto && compose->to_list)
3782 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3785 if (compose->references)
3786 fprintf(fp, "References: %s\n", compose->references);
3789 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3790 #if 0 /* NEW COMPOSE GUI */
3791 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3792 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3794 Xstrdup_a(str, str, return -1);
3798 compose_convert_header(buf, sizeof(buf), str,
3799 strlen("Followup-To: "));
3800 fprintf(fp, "Followup-To: %s\n", buf);
3806 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3807 #if 0 /* NEW COMPOSE GUI */
3808 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3809 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3811 Xstrdup_a(str, str, return -1);
3814 compose_convert_header(buf, sizeof(buf), str,
3815 strlen("Reply-To: "));
3816 fprintf(fp, "Reply-To: %s\n", buf);
3822 if (compose->account->organization &&
3823 !IS_IN_CUSTOM_HEADER("Organization")) {
3824 compose_convert_header(buf, sizeof(buf),
3825 compose->account->organization,
3826 strlen("Organization: "));
3827 fprintf(fp, "Organization: %s\n", buf);
3830 /* Program version and system info */
3831 /* uname(&utsbuf); */
3832 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3833 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3835 gtk_major_version, gtk_minor_version, gtk_micro_version,
3837 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3839 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3840 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3842 gtk_major_version, gtk_minor_version, gtk_micro_version,
3844 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3847 /* custom headers */
3848 if (compose->account->add_customhdr) {
3851 for (cur = compose->account->customhdr_list; cur != NULL;
3853 CustomHeader *chdr = (CustomHeader *)cur->data;
3855 if (strcasecmp(chdr->name, "Date") != 0 &&
3856 strcasecmp(chdr->name, "From") != 0 &&
3857 strcasecmp(chdr->name, "To") != 0 &&
3858 /* strcasecmp(chdr->name, "Sender") != 0 && */
3859 strcasecmp(chdr->name, "Message-Id") != 0 &&
3860 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3861 strcasecmp(chdr->name, "References") != 0 &&
3862 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3863 strcasecmp(chdr->name, "Content-Type") != 0 &&
3864 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3866 compose_convert_header
3868 chdr->value ? chdr->value : "",
3869 strlen(chdr->name) + 2);
3870 fprintf(fp, "%s: %s\n", chdr->name, buf);
3876 fprintf(fp, "Mime-Version: 1.0\n");
3877 if (compose_use_attach(compose)) {
3878 get_rfc822_date(buf, sizeof(buf));
3879 subst_char(buf, ' ', '_');
3880 subst_char(buf, ',', '_');
3881 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3882 buf, (guint)compose);
3884 "Content-Type: multipart/mixed;\n"
3885 " boundary=\"%s\"\n", compose->boundary);
3887 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3888 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3889 procmime_get_encoding_str(encoding));
3893 switch (compose->priority) {
3894 case PRIORITY_HIGHEST: fprintf(fp, "Importance: high\n"
3895 "X-Priority: 1 (Highest)\n");
3897 case PRIORITY_HIGH: fprintf(fp, "Importance: high\n"
3898 "X-Priority: 2 (High)\n");
3900 case PRIORITY_NORMAL: break;
3901 case PRIORITY_LOW: fprintf(fp, "Importance: low\n"
3902 "X-Priority: 4 (Low)\n");
3904 case PRIORITY_LOWEST: fprintf(fp, "Importance: low\n"
3905 "X-Priority: 5 (Lowest)\n");
3907 default: debug_print(_("compose: priority unknown : %d\n"),
3911 /* Request Return Receipt */
3912 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3913 if (compose->return_receipt) {
3914 if (compose->account->name
3915 && *compose->account->name) {
3916 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3917 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3919 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3923 /* separator between header and body */
3929 #undef IS_IN_CUSTOM_HEADER
3931 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3934 g_return_if_fail(src != NULL);
3935 g_return_if_fail(dest != NULL);
3937 if (len < 1) return;
3941 if (is_ascii_str(src)) {
3942 strncpy2(dest, src, len);
3943 dest[len - 1] = '\0';
3946 conv_encode_header(dest, len, src, header_len);
3949 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3958 if (compose->account && compose->account->address &&
3959 *compose->account->address) {
3960 if (strchr(compose->account->address, '@'))
3961 addr = g_strdup(compose->account->address);
3963 addr = g_strconcat(compose->account->address, "@",
3964 get_domain_name(), NULL);
3966 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3969 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3970 lt->tm_year + 1900, lt->tm_mon + 1,
3971 lt->tm_mday, lt->tm_hour,
3972 lt->tm_min, lt->tm_sec,
3973 (guint)random(), addr);
3975 debug_print(_("generated Message-ID: %s\n"), buf);
3980 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3981 GtkWidget **entry, gint *count,
3982 const gchar *label_str,
3983 gboolean is_addr_entry)
3987 if (GTK_TABLE(table)->nrows < (*count) + 1)
3988 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3990 *hbox = gtk_hbox_new(FALSE, 0);
3991 label = gtk_label_new
3992 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3993 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3994 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3996 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3998 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3999 #if 0 /* NEW COMPOSE GUI */
4000 if (GTK_TABLE(table)->nrows > (*count) + 1)
4001 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
4005 address_completion_register_entry(GTK_ENTRY(*entry));
4010 static void compose_create_header_entry(Compose *compose)
4012 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4016 GList *combo_list = NULL;
4017 gchar **string, *header;
4018 ComposeHeaderEntry *headerentry;
4020 headerentry = g_new0(ComposeHeaderEntry, 1);
4023 combo = gtk_combo_new();
4025 while(*string != NULL) {
4026 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4029 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4030 g_list_free(combo_list);
4031 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
4032 gtk_widget_show(combo);
4033 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4034 if(compose->header_last) {
4035 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4037 switch(compose->account->protocol) {
4039 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4042 header = prefs_common.trans_hdr ? _("To:") : "To:";
4046 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4049 entry = gtk_entry_new();
4050 gtk_widget_show(entry);
4051 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);
4053 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4054 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4055 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4057 address_completion_register_entry(GTK_ENTRY(entry));
4059 headerentry->compose = compose;
4060 headerentry->combo = combo;
4061 headerentry->entry = entry;
4062 headerentry->headernum = compose->header_nextrow;
4064 compose->header_nextrow++;
4065 compose->header_last = headerentry;
4068 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4070 ComposeHeaderEntry *last_header;
4072 last_header = compose->header_last;
4074 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4075 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4078 static GtkWidget *compose_create_header(Compose *compose)
4082 GtkWidget *from_optmenu_hbox;
4083 #if 0 /* NEW COMPOSE GUI */
4084 GtkWidget *to_entry;
4086 GtkWidget *newsgroups_entry;
4087 GtkWidget *newsgroups_hbox;
4089 GtkWidget *header_scrolledwin;
4090 GtkWidget *header_table;
4091 #if 0 /* NEW COMPOSE GUI */
4092 GtkWidget *cc_entry;
4094 GtkWidget *bcc_entry;
4095 GtkWidget *bcc_hbox;
4096 GtkWidget *reply_entry;
4097 GtkWidget *reply_hbox;
4098 GtkWidget *followup_entry;
4099 GtkWidget *followup_hbox;
4104 /* header labels and entries */
4105 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4106 gtk_widget_show(header_scrolledwin);
4107 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4109 header_table = gtk_table_new(2, 2, FALSE);
4110 gtk_widget_show(header_table);
4111 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4112 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4113 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4116 /* option menu for selecting accounts */
4117 hbox = gtk_hbox_new(FALSE, 0);
4118 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4119 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4120 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4122 from_optmenu_hbox = compose_account_option_menu_create(compose);
4123 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4124 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4125 #if 0 /* NEW COMPOSE GUI */
4126 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4130 compose->header_table = header_table;
4131 compose->header_list = NULL;
4132 compose->header_nextrow = count;
4134 compose_create_header_entry(compose);
4136 #if 0 /* NEW COMPOSE GUI */
4137 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4139 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4140 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4141 &count, "Newsgroups:", FALSE);
4142 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4144 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4146 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4148 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4149 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4151 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4152 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4154 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4155 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4156 "Followup-To:", FALSE);
4157 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4159 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4161 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4162 GTK_SIGNAL_FUNC(to_activated), compose);
4163 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4164 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4165 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4166 GTK_SIGNAL_FUNC(subject_activated), compose);
4167 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4168 GTK_SIGNAL_FUNC(cc_activated), compose);
4169 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4170 GTK_SIGNAL_FUNC(bcc_activated), compose);
4171 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4172 GTK_SIGNAL_FUNC(replyto_activated), compose);
4173 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4174 GTK_SIGNAL_FUNC(followupto_activated), compose);
4176 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4177 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4178 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4179 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4180 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4181 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4182 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4183 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4184 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4185 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4186 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4187 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4188 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4189 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4192 compose->table = NULL;
4193 #if 0 /* NEW COMPOSE GUI */
4194 compose->table = table;
4195 compose->to_hbox = to_hbox;
4196 compose->to_entry = to_entry;
4197 compose->newsgroups_hbox = newsgroups_hbox;
4198 compose->newsgroups_entry = newsgroups_entry;
4200 #if 0 /* NEW COMPOSE GUI */
4201 compose->cc_hbox = cc_hbox;
4202 compose->cc_entry = cc_entry;
4203 compose->bcc_hbox = bcc_hbox;
4204 compose->bcc_entry = bcc_entry;
4205 compose->reply_hbox = reply_hbox;
4206 compose->reply_entry = reply_entry;
4207 compose->followup_hbox = followup_hbox;
4208 compose->followup_entry = followup_entry;
4211 return header_scrolledwin ;
4214 GtkWidget *compose_create_attach(Compose *compose)
4216 gchar *titles[N_ATTACH_COLS];
4219 GtkWidget *attach_scrwin;
4220 GtkWidget *attach_clist;
4222 titles[COL_MIMETYPE] = _("MIME type");
4223 titles[COL_SIZE] = _("Size");
4224 titles[COL_NAME] = _("Name");
4226 /* attachment list */
4227 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4228 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4229 GTK_POLICY_AUTOMATIC,
4231 gtk_widget_set_usize(attach_scrwin, -1, 80);
4233 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4234 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4236 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4237 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4238 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4239 GTK_SELECTION_EXTENDED);
4240 for (i = 0; i < N_ATTACH_COLS; i++)
4241 GTK_WIDGET_UNSET_FLAGS
4242 (GTK_CLIST(attach_clist)->column[i].button,
4244 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4246 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4247 GTK_SIGNAL_FUNC(attach_selected), compose);
4248 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4249 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4250 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4251 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4254 gtk_drag_dest_set(attach_clist,
4255 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4257 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4258 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4261 compose->attach_scrwin = attach_scrwin;
4262 compose->attach_clist = attach_clist;
4264 return attach_scrwin;
4267 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4268 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4270 static GtkWidget *compose_create_others(Compose *compose)
4273 GtkWidget *savemsg_checkbtn;
4274 GtkWidget *savemsg_entry;
4275 GtkWidget *savemsg_select;
4278 gchar *folderidentifier;
4280 /* Table for settings */
4281 table = gtk_table_new(3, 1, FALSE);
4282 gtk_widget_show(table);
4283 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4286 /* Save Message to folder */
4287 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4288 gtk_widget_show(savemsg_checkbtn);
4289 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4290 if(account_get_special_folder(compose->account, F_OUTBOX)) {
4291 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4293 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4294 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4296 savemsg_entry = gtk_entry_new();
4297 gtk_widget_show(savemsg_entry);
4298 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4299 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4300 if(account_get_special_folder(compose->account, F_OUTBOX)) {
4301 folderidentifier = folder_item_get_identifier(account_get_special_folder
4302 (compose->account, F_OUTBOX));
4303 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4304 g_free(folderidentifier);
4307 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4308 gtk_widget_show (savemsg_select);
4309 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4310 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4311 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4316 compose->savemsg_checkbtn = savemsg_checkbtn;
4317 compose->savemsg_entry = savemsg_entry;
4322 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4324 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4325 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4328 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4333 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4336 path = folder_item_get_identifier(dest);
4338 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4342 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4348 GtkWidget *handlebox;
4350 GtkWidget *notebook;
4355 GtkWidget *subject_hbox;
4356 GtkWidget *subject_frame;
4357 GtkWidget *subject_entry;
4361 GtkWidget *edit_vbox;
4362 GtkWidget *ruler_hbox;
4364 GtkWidget *scrolledwin;
4369 UndoMain *undostruct;
4371 gchar *titles[N_ATTACH_COLS];
4372 guint n_menu_entries;
4373 GtkStyle *style, *new_style;
4376 gboolean success[1];
4378 GtkWidget *popupmenu;
4379 GtkWidget *menuitem;
4380 GtkItemFactory *popupfactory;
4381 GtkItemFactory *ifactory;
4382 GtkWidget *tmpl_menu;
4386 GtkPspell * gtkpspell = NULL;
4389 static GdkGeometry geometry;
4391 g_return_val_if_fail(account != NULL, NULL);
4393 debug_print(_("Creating compose window...\n"));
4394 compose = g_new0(Compose, 1);
4396 titles[COL_MIMETYPE] = _("MIME type");
4397 titles[COL_SIZE] = _("Size");
4398 titles[COL_NAME] = _("Name");
4400 compose->account = account;
4401 compose->orig_account = account;
4403 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4404 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4405 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4406 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4408 if (!geometry.max_width) {
4409 geometry.max_width = gdk_screen_width();
4410 geometry.max_height = gdk_screen_height();
4412 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4413 &geometry, GDK_HINT_MAX_SIZE);
4415 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4416 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4417 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4418 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4419 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4420 gtk_widget_realize(window);
4422 gtkut_widget_set_composer_icon(window);
4424 vbox = gtk_vbox_new(FALSE, 0);
4425 gtk_container_add(GTK_CONTAINER(window), vbox);
4427 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4428 menubar = menubar_create(window, compose_entries,
4429 n_menu_entries, "<Compose>", compose);
4430 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4432 handlebox = gtk_handle_box_new();
4433 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4435 compose_toolbar_create(compose, handlebox);
4437 vbox2 = gtk_vbox_new(FALSE, 2);
4438 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4439 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4442 notebook = gtk_notebook_new();
4443 gtk_widget_set_usize(notebook, -1, 130);
4444 gtk_widget_show(notebook);
4446 /* header labels and entries */
4447 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4448 /* attachment list */
4449 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4451 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4454 subject_hbox = gtk_hbox_new(FALSE, 0);
4455 gtk_widget_show(subject_hbox);
4457 subject_frame = gtk_frame_new(NULL);
4458 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4459 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4460 gtk_widget_show(subject_frame);
4462 subject = gtk_hbox_new(FALSE, 0);
4463 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4464 gtk_widget_show(subject);
4466 label = gtk_label_new(_("Subject:"));
4467 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4468 gtk_widget_show(label);
4470 subject_entry = gtk_entry_new();
4471 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4472 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4473 gtk_widget_show(subject_entry);
4474 compose->subject_entry = subject_entry;
4475 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4477 edit_vbox = gtk_vbox_new(FALSE, 0);
4478 #if 0 /* NEW COMPOSE GUI */
4479 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4482 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4485 ruler_hbox = gtk_hbox_new(FALSE, 0);
4486 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4488 ruler = gtk_shruler_new();
4489 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4490 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4492 gtk_widget_set_usize(ruler_hbox, 1, -1);
4495 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4496 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4497 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4498 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4499 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4501 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4502 (GTK_SCROLLED_WINDOW(scrolledwin)),
4503 gtk_scrolled_window_get_vadjustment
4504 (GTK_SCROLLED_WINDOW(scrolledwin)));
4505 GTK_STEXT(text)->default_tab_width = 8;
4506 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4508 if (prefs_common.block_cursor) {
4509 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4512 if (prefs_common.smart_wrapping) {
4513 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4514 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4517 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4519 gtk_signal_connect(GTK_OBJECT(text), "changed",
4520 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4521 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4522 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4523 gtk_signal_connect(GTK_OBJECT(text), "activate",
4524 GTK_SIGNAL_FUNC(text_activated), compose);
4525 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4526 GTK_SIGNAL_FUNC(compose_button_press_cb),
4529 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4530 GTK_SIGNAL_FUNC(compose_key_press_cb),
4533 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4534 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4538 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4540 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4541 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4543 gtk_widget_show_all(vbox);
4545 /* pane between attach clist and text */
4546 paned = gtk_vpaned_new();
4547 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4548 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4549 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4550 gtk_paned_add1(GTK_PANED(paned), notebook);
4551 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4552 gtk_widget_show_all(paned);
4554 style = gtk_widget_get_style(text);
4556 /* workaround for the slow down of GtkSText when using Pixmap theme */
4557 if (style->engine) {
4558 GtkThemeEngine *engine;
4560 engine = style->engine;
4561 style->engine = NULL;
4562 new_style = gtk_style_copy(style);
4563 style->engine = engine;
4565 new_style = gtk_style_copy(style);
4567 if (prefs_common.textfont) {
4568 if (MB_CUR_MAX == 1) {
4571 Xstrdup_a(fontstr, prefs_common.textfont, );
4572 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4574 font = gdk_font_load(fontstr);
4576 font = gdk_fontset_load(prefs_common.textfont);
4578 gdk_font_unref(new_style->font);
4579 new_style->font = font;
4583 gtk_widget_set_style(text, new_style);
4585 color[0] = quote_color;
4586 cmap = gdk_window_get_colormap(window->window);
4587 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4588 if (success[0] == FALSE) {
4589 g_warning("Compose: color allocation failed.\n");
4590 style = gtk_widget_get_style(text);
4591 quote_color = style->black;
4594 n_entries = sizeof(compose_popup_entries) /
4595 sizeof(compose_popup_entries[0]);
4596 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4597 "<Compose>", &popupfactory,
4600 ifactory = gtk_item_factory_from_widget(menubar);
4601 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4602 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4604 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4605 #if 0 /* NEW COMPOSE GUI */
4606 gtk_widget_hide(bcc_hbox);
4607 gtk_widget_hide(bcc_entry);
4608 gtk_widget_hide(reply_hbox);
4609 gtk_widget_hide(reply_entry);
4610 gtk_widget_hide(followup_hbox);
4611 gtk_widget_hide(followup_entry);
4612 gtk_widget_hide(ruler_hbox);
4613 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4614 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4615 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4617 if (account->protocol == A_NNTP) {
4618 gtk_widget_hide(to_hbox);
4619 gtk_widget_hide(to_entry);
4620 gtk_widget_hide(cc_hbox);
4621 gtk_widget_hide(cc_entry);
4622 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4623 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4625 gtk_widget_hide(newsgroups_hbox);
4626 gtk_widget_hide(newsgroups_entry);
4627 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4628 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
4632 update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
4635 undostruct = undo_init(text);
4636 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4639 gtk_widget_show(window);
4641 address_completion_start(window);
4643 compose->window = window;
4644 compose->vbox = vbox;
4645 compose->menubar = menubar;
4646 compose->handlebox = handlebox;
4648 compose->vbox2 = vbox2;
4650 compose->paned = paned;
4652 compose->edit_vbox = edit_vbox;
4653 compose->ruler_hbox = ruler_hbox;
4654 compose->ruler = ruler;
4655 compose->scrolledwin = scrolledwin;
4656 compose->text = text;
4658 compose->focused_editable = NULL;
4660 compose->popupmenu = popupmenu;
4661 compose->popupfactory = popupfactory;
4663 compose->tmpl_menu = tmpl_menu;
4665 compose->mode = mode;
4667 compose->targetinfo = NULL;
4668 compose->replyinfo = NULL;
4670 compose->replyto = NULL;
4671 compose->mailinglist = NULL;
4673 compose->bcc = NULL;
4674 compose->followup_to = NULL;
4675 compose->inreplyto = NULL;
4676 compose->references = NULL;
4677 compose->msgid = NULL;
4678 compose->boundary = NULL;
4681 compose->use_signing = FALSE;
4682 compose->use_encryption = FALSE;
4683 #endif /* USE_GPGME */
4685 compose->modified = FALSE;
4687 compose->return_receipt = FALSE;
4689 compose->to_list = NULL;
4690 compose->newsgroup_list = NULL;
4692 compose->exteditor_file = NULL;
4693 compose->exteditor_pid = -1;
4694 compose->exteditor_readdes = -1;
4695 compose->exteditor_tag = -1;
4697 compose->redirect_filename = NULL;
4698 compose->undostruct = undostruct;
4701 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4702 if (prefs_common.enable_pspell) {
4703 gtkpspell = gtkpspell_new((const gchar*)prefs_common.dictionary,
4704 conv_get_current_charset_str(),
4705 prefs_common.misspelled_col,
4706 prefs_common.check_while_typing,
4707 prefs_common.use_alternate,
4710 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkpspellcheckers->error_message);
4711 gtkpspell_checkers_reset_error();
4714 GtkWidget *menuitem;
4716 if (!gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode)) {
4717 debug_print(_("Pspell: could not set suggestion mode %s"),
4718 gtkpspellcheckers->error_message);
4719 gtkpspell_checkers_reset_error();
4722 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
4723 gtkpspell_populate_submenu(gtkpspell, menuitem);
4724 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4729 compose_set_title(compose);
4731 #if 0 /* NEW COMPOSE GUI */
4732 compose->use_bcc = FALSE;
4733 compose->use_replyto = FALSE;
4734 compose->use_followupto = FALSE;
4738 compose->gtkpspell = gtkpspell;
4741 #if 0 /* NEW COMPOSE GUI */
4742 if (account->protocol != A_NNTP) {
4743 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
4744 gtk_check_menu_item_set_active
4745 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4746 gtk_widget_set_sensitive(menuitem, FALSE);
4747 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4748 gtk_check_menu_item_set_active
4749 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4750 gtk_widget_set_sensitive(menuitem, FALSE);
4753 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4754 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4755 #if 0 /* NEW COMPOSE GUI */
4756 compose->use_cc = TRUE;
4757 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4758 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4759 gtk_check_menu_item_set_active
4760 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4763 if (account->set_autobcc) {
4764 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4765 #if 0 /* NEW COMPOSE GUI */
4766 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
4767 gtk_check_menu_item_set_active
4768 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4769 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4770 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4774 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4775 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4776 #if 0 /* NEW COMPOSE GUI */
4777 compose->use_replyto = TRUE;
4778 menuitem = gtk_item_factory_get_item(ifactory,
4780 gtk_check_menu_item_set_active
4781 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4782 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4783 account->auto_replyto);
4787 if (account->protocol != A_NNTP) {
4788 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4790 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4793 #if 0 /* NEW COMPOSE GUI */
4794 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
4795 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4796 prefs_common.show_ruler);
4800 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4801 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4802 account->default_sign);
4803 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4804 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4805 account->default_encrypt);
4806 #endif /* USE_GPGME */
4808 addressbook_set_target_compose(compose);
4809 compose_set_template_menu(compose);
4811 compose_list = g_list_append(compose_list, compose);
4813 #if 0 /* NEW COMPOSE GUI */
4814 compose->use_to = FALSE;
4815 compose->use_cc = FALSE;
4816 compose->use_attach = TRUE;
4819 #if 0 /* NEW COMPOSE GUI */
4820 if (!compose->use_bcc) {
4821 gtk_widget_hide(bcc_hbox);
4822 gtk_widget_hide(bcc_entry);
4823 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4825 if (!compose->use_replyto) {
4826 gtk_widget_hide(reply_hbox);
4827 gtk_widget_hide(reply_entry);
4828 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4830 if (!compose->use_followupto) {
4831 gtk_widget_hide(followup_hbox);
4832 gtk_widget_hide(followup_entry);
4833 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4836 if (!prefs_common.show_ruler)
4837 gtk_widget_hide(ruler_hbox);
4840 compose->priority = PRIORITY_NORMAL;
4841 compose_update_priority_menu_item(compose);
4843 select_account(compose, account);
4844 set_toolbar_style(compose);
4849 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4852 GtkWidget *icon_wid;
4853 GtkWidget *send_btn;
4854 GtkWidget *sendl_btn;
4855 GtkWidget *draft_btn;
4856 GtkWidget *insert_btn;
4857 GtkWidget *attach_btn;
4859 GtkWidget *exteditor_btn;
4860 GtkWidget *linewrap_btn;
4861 GtkWidget *addrbook_btn;
4863 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4865 gtk_container_add(GTK_CONTAINER(container), toolbar);
4866 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4867 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4868 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4869 GTK_TOOLBAR_SPACE_LINE);
4871 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
4872 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4876 icon_wid, toolbar_send_cb, compose);
4878 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND_QUEUE);
4879 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4881 _("Put into queue folder and send later"),
4883 icon_wid, toolbar_send_later_cb,
4886 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4887 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4889 _("Save to draft folder"),
4891 icon_wid, toolbar_draft_cb,
4894 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4896 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_INSERT_FILE);
4897 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4901 icon_wid, toolbar_insert_cb,
4904 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_ATTACH);
4905 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4909 icon_wid, toolbar_attach_cb,
4912 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4914 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SIGN);
4915 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4917 _("Insert signature"),
4919 icon_wid, toolbar_sig_cb, compose);
4921 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4923 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_EDIT_EXTERN);
4924 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4926 _("Edit with external editor"),
4929 toolbar_ext_editor_cb,
4932 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_LINEWRAP);
4933 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4935 _("Wrap all long lines"),
4938 toolbar_linewrap_cb,
4941 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4943 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_ADDRESS_BOOK);
4944 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4948 icon_wid, toolbar_address_cb,
4951 compose->toolbar = toolbar;
4952 compose->send_btn = send_btn;
4953 compose->sendl_btn = sendl_btn;
4954 compose->draft_btn = draft_btn;
4955 compose->insert_btn = insert_btn;
4956 compose->attach_btn = attach_btn;
4957 compose->sig_btn = sig_btn;
4958 compose->exteditor_btn = exteditor_btn;
4959 compose->linewrap_btn = linewrap_btn;
4960 compose->addrbook_btn = addrbook_btn;
4962 gtk_widget_show_all(toolbar);
4965 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4971 gint num = 0, def_menu = 0;
4973 accounts = account_get_list();
4974 g_return_val_if_fail(accounts != NULL, NULL);
4976 hbox = gtk_hbox_new(FALSE, 0);
4977 optmenu = gtk_option_menu_new();
4978 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4979 menu = gtk_menu_new();
4981 for (; accounts != NULL; accounts = accounts->next, num++) {
4982 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4983 GtkWidget *menuitem;
4986 if (ac == compose->account) def_menu = num;
4989 name = g_strdup_printf("%s: %s <%s>",
4991 ac->name, ac->address);
4993 name = g_strdup_printf("%s: %s",
4994 ac->account_name, ac->address);
4995 MENUITEM_ADD(menu, menuitem, name, ac);
4997 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4998 GTK_SIGNAL_FUNC(account_activated),
5002 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5003 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5008 static void compose_set_priority_cb(gpointer data,
5012 Compose *compose = (Compose *) data;
5013 compose->priority = action;
5016 static void compose_update_priority_menu_item(Compose * compose)
5018 GtkItemFactory *ifactory;
5019 GtkWidget *menuitem;
5021 ifactory = gtk_item_factory_from_widget(compose->menubar);
5023 switch (compose->priority) {
5024 case PRIORITY_HIGHEST:
5025 menuitem = gtk_item_factory_get_item
5026 (ifactory, "/Message/Priority/Highest");
5029 menuitem = gtk_item_factory_get_item
5030 (ifactory, "/Message/Priority/High");
5032 case PRIORITY_NORMAL:
5033 menuitem = gtk_item_factory_get_item
5034 (ifactory, "/Message/Priority/Normal");
5037 menuitem = gtk_item_factory_get_item
5038 (ifactory, "/Message/Priority/Low");
5040 case PRIORITY_LOWEST:
5041 menuitem = gtk_item_factory_get_item
5042 (ifactory, "/Message/Priority/Lowest");
5045 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5048 static void compose_set_template_menu(Compose *compose)
5050 GSList *tmpl_list, *cur;
5054 tmpl_list = template_get_config();
5056 menu = gtk_menu_new();
5058 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5059 Template *tmpl = (Template *)cur->data;
5061 item = gtk_menu_item_new_with_label(tmpl->name);
5062 gtk_menu_append(GTK_MENU(menu), item);
5063 gtk_signal_connect(GTK_OBJECT(item), "activate",
5064 GTK_SIGNAL_FUNC(compose_template_activate_cb),
5066 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
5067 gtk_widget_show(item);
5070 gtk_widget_show(menu);
5071 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5074 void compose_reflect_prefs_all(void)
5079 for (cur = compose_list; cur != NULL; cur = cur->next) {
5080 compose = (Compose *)cur->data;
5081 compose_set_template_menu(compose);
5085 void compose_reflect_prefs_pixmap_theme(void)
5090 for (cur = compose_list; cur != NULL; cur = cur->next) {
5091 compose = (Compose *)cur->data;
5092 gtk_container_remove(GTK_CONTAINER(compose->handlebox), GTK_WIDGET(compose->toolbar));
5093 compose->toolbar = NULL;
5094 compose_toolbar_create(compose, compose->handlebox);
5095 set_toolbar_style(compose);
5099 static void compose_template_apply(Compose *compose, Template *tmpl,
5105 if (!tmpl || !tmpl->value) return;
5107 gtk_stext_freeze(GTK_STEXT(compose->text));
5109 if (tmpl->subject && *tmpl->subject != '\0')
5110 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5112 if (tmpl->to && *tmpl->to != '\0')
5113 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5116 gtk_stext_clear(GTK_STEXT(compose->text));
5118 if (compose->replyinfo == NULL) {
5121 memset(&dummyinfo, 0, sizeof(MsgInfo));
5122 parsed_str = compose_quote_fmt(compose, &dummyinfo,
5123 tmpl->value, NULL, NULL);
5125 if (prefs_common.quotemark && *prefs_common.quotemark)
5126 qmark = prefs_common.quotemark;
5130 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5131 tmpl->value, qmark, NULL);
5134 if (replace && parsed_str && prefs_common.auto_sig)
5135 compose_insert_sig(compose);
5137 if (replace && parsed_str) {
5138 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
5139 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
5143 compose_changed_cb(NULL, compose);
5145 gtk_stext_thaw(GTK_STEXT(compose->text));
5148 static void compose_destroy(Compose *compose)
5151 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5154 /* NOTE: address_completion_end() does nothing with the window
5155 * however this may change. */
5156 address_completion_end(compose->window);
5158 slist_free_strings(compose->to_list);
5159 g_slist_free(compose->to_list);
5160 slist_free_strings(compose->newsgroup_list);
5161 g_slist_free(compose->newsgroup_list);
5162 slist_free_strings(compose->header_list);
5163 g_slist_free(compose->header_list);
5165 procmsg_msginfo_free(compose->targetinfo);
5166 procmsg_msginfo_free(compose->replyinfo);
5168 g_free(compose->replyto);
5169 g_free(compose->cc);
5170 g_free(compose->bcc);
5171 g_free(compose->newsgroups);
5172 g_free(compose->followup_to);
5174 g_free(compose->inreplyto);
5175 g_free(compose->references);
5176 g_free(compose->msgid);
5177 g_free(compose->boundary);
5179 if (compose->redirect_filename)
5180 g_free(compose->redirect_filename);
5182 g_free(compose->exteditor_file);
5184 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5186 compose_attach_info_free(ainfo);
5188 if (addressbook_get_target_compose() == compose)
5189 addressbook_set_target_compose(NULL);
5192 if (compose->gtkpspell) {
5193 gtkpspell_delete(compose->gtkpspell);
5197 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5198 prefs_common.compose_height = compose->window->allocation.height;
5200 gtk_widget_destroy(compose->paned);
5204 compose_list = g_list_remove(compose_list, compose);
5207 static void compose_attach_info_free(AttachInfo *ainfo)
5209 g_free(ainfo->file);
5210 g_free(ainfo->content_type);
5211 g_free(ainfo->name);
5215 static void compose_attach_remove_selected(Compose *compose)
5217 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5221 while (clist->selection != NULL) {
5222 row = GPOINTER_TO_INT(clist->selection->data);
5223 ainfo = gtk_clist_get_row_data(clist, row);
5224 compose_attach_info_free(ainfo);
5225 gtk_clist_remove(clist, row);
5229 static struct _AttachProperty
5232 GtkWidget *mimetype_entry;
5233 GtkWidget *encoding_optmenu;
5234 GtkWidget *path_entry;
5235 GtkWidget *filename_entry;
5237 GtkWidget *cancel_btn;
5240 static void compose_attach_property(Compose *compose)
5242 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5245 GtkOptionMenu *optmenu;
5246 static gboolean cancelled;
5248 if (!clist->selection) return;
5249 row = GPOINTER_TO_INT(clist->selection->data);
5251 ainfo = gtk_clist_get_row_data(clist, row);
5254 if (!attach_prop.window)
5255 compose_attach_property_create(&cancelled);
5256 gtk_widget_grab_focus(attach_prop.ok_btn);
5257 gtk_widget_show(attach_prop.window);
5258 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5260 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5261 if (ainfo->encoding == ENC_UNKNOWN)
5262 gtk_option_menu_set_history(optmenu, ENC_BASE64);
5264 gtk_option_menu_set_history(optmenu, ainfo->encoding);
5266 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5267 ainfo->content_type ? ainfo->content_type : "");
5268 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5269 ainfo->file ? ainfo->file : "");
5270 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5271 ainfo->name ? ainfo->name : "");
5275 gchar *cnttype = NULL;
5279 GtkWidget *menuitem;
5284 if (cancelled == TRUE) {
5285 gtk_widget_hide(attach_prop.window);
5289 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5290 if (*text != '\0') {
5293 text = g_strstrip(g_strdup(text));
5294 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5295 cnttype = g_strdup(text);
5298 alertpanel_error(_("Invalid MIME type."));
5304 menu = gtk_option_menu_get_menu(optmenu);
5305 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5306 ainfo->encoding = GPOINTER_TO_INT
5307 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5309 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5310 if (*text != '\0') {
5311 if (is_file_exist(text) &&
5312 (size = get_file_size(text)) > 0)
5313 file = g_strdup(text);
5316 (_("File doesn't exist or is empty."));
5322 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5323 if (*text != '\0') {
5324 g_free(ainfo->name);
5325 ainfo->name = g_strdup(text);
5329 g_free(ainfo->content_type);
5330 ainfo->content_type = cnttype;
5333 g_free(ainfo->file);
5339 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5340 ainfo->content_type);
5341 gtk_clist_set_text(clist, row, COL_SIZE,
5342 to_human_readable(ainfo->size));
5343 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5345 gtk_widget_hide(attach_prop.window);
5350 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5352 label = gtk_label_new(str); \
5353 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5354 GTK_FILL, 0, 0, 0); \
5355 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5357 entry = gtk_entry_new(); \
5358 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5359 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5362 static void compose_attach_property_create(gboolean *cancelled)
5368 GtkWidget *mimetype_entry;
5371 GtkWidget *optmenu_menu;
5372 GtkWidget *menuitem;
5373 GtkWidget *path_entry;
5374 GtkWidget *filename_entry;
5377 GtkWidget *cancel_btn;
5378 GList *mime_type_list, *strlist;
5380 debug_print("Creating attach_property window...\n");
5382 window = gtk_window_new(GTK_WINDOW_DIALOG);
5383 gtk_widget_set_usize(window, 480, -1);
5384 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5385 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
5386 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5387 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5388 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5389 GTK_SIGNAL_FUNC(attach_property_delete_event),
5391 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5392 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5395 vbox = gtk_vbox_new(FALSE, 8);
5396 gtk_container_add(GTK_CONTAINER(window), vbox);
5398 table = gtk_table_new(4, 2, FALSE);
5399 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5400 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5401 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5403 label = gtk_label_new(_("MIME type"));
5404 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5406 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5407 mimetype_entry = gtk_combo_new();
5408 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5409 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5411 /* stuff with list */
5412 mime_type_list = procmime_get_mime_type_list();
5414 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5415 MimeType *type = (MimeType *) mime_type_list->data;
5416 strlist = g_list_append(strlist,
5417 g_strdup_printf("%s/%s",
5418 type->type, type->sub_type));
5421 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5423 for (mime_type_list = strlist; mime_type_list != NULL;
5424 mime_type_list = mime_type_list->next)
5425 g_free(mime_type_list->data);
5426 g_list_free(strlist);
5428 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5430 label = gtk_label_new(_("Encoding"));
5431 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5433 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5435 hbox = gtk_hbox_new(FALSE, 0);
5436 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5437 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5439 optmenu = gtk_option_menu_new();
5440 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5442 optmenu_menu = gtk_menu_new();
5443 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5444 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5446 gtk_widget_set_sensitive(menuitem, FALSE);
5448 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5449 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5451 gtk_widget_set_sensitive(menuitem, FALSE);
5453 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5454 gtk_widget_set_sensitive(menuitem, FALSE);
5455 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5457 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5459 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5460 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5462 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5463 &cancel_btn, _("Cancel"), NULL, NULL);
5464 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5465 gtk_widget_grab_default(ok_btn);
5467 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5468 GTK_SIGNAL_FUNC(attach_property_ok),
5470 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5471 GTK_SIGNAL_FUNC(attach_property_cancel),
5474 gtk_widget_show_all(vbox);
5476 attach_prop.window = window;
5477 attach_prop.mimetype_entry = mimetype_entry;
5478 attach_prop.encoding_optmenu = optmenu;
5479 attach_prop.path_entry = path_entry;
5480 attach_prop.filename_entry = filename_entry;
5481 attach_prop.ok_btn = ok_btn;
5482 attach_prop.cancel_btn = cancel_btn;
5485 #undef SET_LABEL_AND_ENTRY
5487 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5493 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5499 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5500 gboolean *cancelled)
5508 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5509 gboolean *cancelled)
5511 if (event && event->keyval == GDK_Escape) {
5517 static void compose_exec_ext_editor(Compose *compose)
5523 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5524 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5526 if (pipe(pipe_fds) < 0) {
5531 if ((pid = fork()) < 0) {
5537 /* close the write side of the pipe */
5540 compose->exteditor_file = g_strdup(tmp);
5541 compose->exteditor_pid = pid;
5542 compose->exteditor_readdes = pipe_fds[0];
5544 compose_set_ext_editor_sensitive(compose, FALSE);
5546 compose->exteditor_tag =
5547 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5548 compose_input_cb, compose);
5549 } else { /* process-monitoring process */
5555 /* close the read side of the pipe */
5558 if (compose_write_body_to_file(compose, tmp) < 0) {
5559 fd_write(pipe_fds[1], "2\n", 2);
5563 pid_ed = compose_exec_ext_editor_real(tmp);
5565 fd_write(pipe_fds[1], "1\n", 2);
5569 /* wait until editor is terminated */
5570 waitpid(pid_ed, NULL, 0);
5572 fd_write(pipe_fds[1], "0\n", 2);
5579 static gint compose_exec_ext_editor_real(const gchar *file)
5581 static gchar *def_cmd = "emacs %s";
5587 g_return_val_if_fail(file != NULL, -1);
5589 if ((pid = fork()) < 0) {
5594 if (pid != 0) return pid;
5596 /* grandchild process */
5598 if (setpgid(0, getppid()))
5601 if (prefs_common.ext_editor_cmd &&
5602 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5603 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5604 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5606 if (prefs_common.ext_editor_cmd)
5607 g_warning(_("External editor command line is invalid: `%s'\n"),
5608 prefs_common.ext_editor_cmd);
5609 g_snprintf(buf, sizeof(buf), def_cmd, file);
5612 cmdline = strsplit_with_quote(buf, " ", 1024);
5613 execvp(cmdline[0], cmdline);
5616 g_strfreev(cmdline);
5621 static gboolean compose_ext_editor_kill(Compose *compose)
5623 pid_t pgid = compose->exteditor_pid * -1;
5626 ret = kill(pgid, 0);
5628 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5632 msg = g_strdup_printf
5633 (_("The external editor is still working.\n"
5634 "Force terminating the process?\n"
5635 "process group id: %d"), -pgid);
5636 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5639 if (val == G_ALERTDEFAULT) {
5640 gdk_input_remove(compose->exteditor_tag);
5641 close(compose->exteditor_readdes);
5643 if (kill(pgid, SIGTERM) < 0) perror("kill");
5644 waitpid(compose->exteditor_pid, NULL, 0);
5646 g_warning(_("Terminated process group id: %d"), -pgid);
5647 g_warning(_("Temporary file: %s"),
5648 compose->exteditor_file);
5650 compose_set_ext_editor_sensitive(compose, TRUE);
5652 g_free(compose->exteditor_file);
5653 compose->exteditor_file = NULL;
5654 compose->exteditor_pid = -1;
5655 compose->exteditor_readdes = -1;
5656 compose->exteditor_tag = -1;
5664 static void compose_input_cb(gpointer data, gint source,
5665 GdkInputCondition condition)
5668 Compose *compose = (Compose *)data;
5671 debug_print(_("Compose: input from monitoring process\n"));
5673 gdk_input_remove(compose->exteditor_tag);
5676 if (read(source, &buf[i], 1) < 1) {
5680 if (buf[i] == '\n') {
5685 if (i == sizeof(buf) - 1)
5689 waitpid(compose->exteditor_pid, NULL, 0);
5691 if (buf[0] == '0') { /* success */
5692 GtkSText *text = GTK_STEXT(compose->text);
5694 gtk_stext_freeze(text);
5695 gtk_stext_set_point(text, 0);
5696 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5697 compose_insert_file(compose, compose->exteditor_file);
5698 compose_changed_cb(NULL, compose);
5699 gtk_stext_thaw(text);
5701 if (unlink(compose->exteditor_file) < 0)
5702 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5703 } else if (buf[0] == '1') { /* failed */
5704 g_warning(_("Couldn't exec external editor\n"));
5705 if (unlink(compose->exteditor_file) < 0)
5706 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5707 } else if (buf[0] == '2') {
5708 g_warning(_("Couldn't write to file\n"));
5709 } else if (buf[0] == '3') {
5710 g_warning(_("Pipe read failed\n"));
5715 compose_set_ext_editor_sensitive(compose, TRUE);
5717 g_free(compose->exteditor_file);
5718 compose->exteditor_file = NULL;
5719 compose->exteditor_pid = -1;
5720 compose->exteditor_readdes = -1;
5721 compose->exteditor_tag = -1;
5724 static void compose_set_ext_editor_sensitive(Compose *compose,
5727 GtkItemFactory *ifactory;
5729 ifactory = gtk_item_factory_from_widget(compose->menubar);
5731 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5732 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5733 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5735 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5736 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5737 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5738 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5739 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5742 gtk_widget_set_sensitive(compose->text, sensitive);
5743 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5744 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5745 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5746 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5747 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5748 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5749 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5753 * compose_undo_state_changed:
5755 * Change the sensivity of the menuentries undo and redo
5757 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5758 gint redo_state, gpointer data)
5760 GtkWidget *widget = GTK_WIDGET(data);
5761 GtkItemFactory *ifactory;
5763 g_return_if_fail(widget != NULL);
5765 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
5767 ifactory = gtk_item_factory_from_widget(widget);
5769 switch (undo_state) {
5770 case UNDO_STATE_TRUE:
5771 if (!undostruct->undo_state) {
5772 debug_print ("Set_undo - Testpoint\n");
5773 undostruct->undo_state = TRUE;
5774 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5777 case UNDO_STATE_FALSE:
5778 if (undostruct->undo_state) {
5779 undostruct->undo_state = FALSE;
5780 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5783 case UNDO_STATE_UNCHANGED:
5785 case UNDO_STATE_REFRESH:
5786 menu_set_sensitive(ifactory, "/Edit/Undo",
5787 undostruct->undo_state);
5790 g_warning("Undo state not recognized");
5794 switch (redo_state) {
5795 case UNDO_STATE_TRUE:
5796 if (!undostruct->redo_state) {
5797 undostruct->redo_state = TRUE;
5798 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5801 case UNDO_STATE_FALSE:
5802 if (undostruct->redo_state) {
5803 undostruct->redo_state = FALSE;
5804 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5807 case UNDO_STATE_UNCHANGED:
5809 case UNDO_STATE_REFRESH:
5810 menu_set_sensitive(ifactory, "/Edit/Redo",
5811 undostruct->redo_state);
5814 g_warning("Redo state not recognized");
5819 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5823 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5824 cursor_pos = MAX(cursor_pos, 0);
5829 /* callback functions */
5831 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5832 * includes "non-client" (windows-izm) in calculation, so this calculation
5833 * may not be accurate.
5835 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5836 GtkAllocation *allocation,
5837 GtkSHRuler *shruler)
5839 if (prefs_common.show_ruler) {
5841 gint line_width_in_chars;
5843 char_width = gtkut_get_font_width
5844 (GTK_WIDGET(widget)->style->font);
5845 line_width_in_chars =
5846 (allocation->width - allocation->x) / char_width;
5848 /* got the maximum */
5849 gtk_ruler_set_range(GTK_RULER(shruler),
5850 0.0, line_width_in_chars,
5851 calc_cursor_xpos(GTK_STEXT(widget),
5854 /*line_width_in_chars*/ char_width);
5860 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5862 compose_send_cb(data, 0, NULL);
5865 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5867 compose_send_later_cb(data, 0, NULL);
5870 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5872 compose_draft_cb(data, 0, NULL);
5875 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5877 compose_insert_file_cb(data, 0, NULL);
5880 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5882 compose_attach_cb(data, 0, NULL);
5885 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5887 Compose *compose = (Compose *)data;
5889 compose_insert_sig(compose);
5892 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5894 Compose *compose = (Compose *)data;
5896 compose_exec_ext_editor(compose);
5899 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5901 Compose *compose = (Compose *)data;
5903 compose_wrap_line(compose);
5906 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5908 compose_address_cb(data, 0, NULL);
5911 static void select_account(Compose * compose, PrefsAccount * ac)
5914 GtkItemFactory *ifactory;
5915 GtkWidget *menuitem;
5916 #endif /* USE_GPGME */
5917 compose->account = ac;
5918 compose_set_title(compose);
5920 #if 0 /* NEW COMPOSE GUI */
5921 if (ac->protocol == A_NNTP) {
5922 GtkItemFactory *ifactory;
5923 GtkWidget *menuitem;
5925 ifactory = gtk_item_factory_from_widget(compose->menubar);
5926 menu_set_sensitive(ifactory,
5927 "/Message/Followup to", TRUE);
5928 gtk_widget_show(compose->newsgroups_hbox);
5929 gtk_widget_show(compose->newsgroups_entry);
5930 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5933 compose->use_to = FALSE;
5934 compose->use_cc = FALSE;
5936 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5937 gtk_check_menu_item_set_active
5938 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5940 menu_set_sensitive(ifactory,
5941 "/Message/To", TRUE);
5942 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5943 gtk_check_menu_item_set_active
5944 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5946 gtk_widget_hide(compose->to_hbox);
5947 gtk_widget_hide(compose->to_entry);
5948 gtk_widget_hide(compose->cc_hbox);
5949 gtk_widget_hide(compose->cc_entry);
5950 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5952 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5956 GtkItemFactory *ifactory;
5957 GtkWidget *menuitem;
5959 ifactory = gtk_item_factory_from_widget(compose->menubar);
5960 menu_set_sensitive(ifactory,
5961 "/Message/Followup to", FALSE);
5962 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5963 gtk_widget_hide(compose->newsgroups_hbox);
5964 gtk_widget_hide(compose->newsgroups_entry);
5965 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5968 compose->use_to = TRUE;
5969 compose->use_cc = TRUE;
5971 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5972 gtk_check_menu_item_set_active
5973 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5974 menu_set_sensitive(ifactory,
5975 "/Message/To", FALSE);
5976 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5977 gtk_check_menu_item_set_active
5978 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5979 gtk_widget_show(compose->to_hbox);
5980 gtk_widget_show(compose->to_entry);
5981 gtk_widget_show(compose->cc_hbox);
5982 gtk_widget_show(compose->cc_entry);
5984 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5986 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5989 gtk_widget_queue_resize(compose->table_vbox);
5992 ifactory = gtk_item_factory_from_widget(compose->menubar);
5993 menu_set_sensitive(ifactory,
5994 "/Message/Sign", TRUE);
5995 menu_set_sensitive(ifactory,
5996 "/Message/Encrypt", TRUE);
5998 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
5999 if (ac->default_sign)
6000 gtk_check_menu_item_set_active
6001 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6003 gtk_check_menu_item_set_active
6004 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
6006 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
6007 if (ac->default_encrypt)
6008 gtk_check_menu_item_set_active
6009 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6011 gtk_check_menu_item_set_active
6012 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
6013 #endif /* USE_GPGME */
6017 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6019 Compose *compose = (Compose *)data;
6023 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
6024 g_return_if_fail(ac != NULL);
6026 if (ac != compose->account)
6027 select_account(compose, ac);
6030 static void attach_selected(GtkCList *clist, gint row, gint column,
6031 GdkEvent *event, gpointer data)
6033 Compose *compose = (Compose *)data;
6035 if (event && event->type == GDK_2BUTTON_PRESS)
6036 compose_attach_property(compose);
6039 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6042 Compose *compose = (Compose *)data;
6043 GtkCList *clist = GTK_CLIST(compose->attach_clist);
6048 if (event->button == 3) {
6049 if ((clist->selection && !clist->selection->next) ||
6050 !clist->selection) {
6051 gtk_clist_unselect_all(clist);
6052 if (gtk_clist_get_selection_info(clist,
6055 gtk_clist_select_row(clist, row, column);
6056 gtkut_clist_set_focus_row(clist, row);
6059 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6060 NULL, NULL, event->button, event->time);
6064 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6067 Compose *compose = (Compose *)data;
6071 switch (event->keyval) {
6073 compose_attach_remove_selected(compose);
6078 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6080 Compose *compose = (Compose *)data;
6083 if (prefs_common.work_offline)
6084 if (alertpanel(_("Offline warning"),
6085 _("You're working offline. Override?"),
6086 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
6089 val = compose_send(compose);
6091 if (val == 0) gtk_widget_destroy(compose->window);
6094 static void compose_send_later_cb(gpointer data, guint action,
6097 Compose *compose = (Compose *)data;
6100 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6101 if (!val) gtk_widget_destroy(compose->window);
6104 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6106 Compose *compose = (Compose *)data;
6110 MsgFlags flag = {0, 0};
6111 static gboolean lock = FALSE;
6115 draft = account_get_special_folder(compose->account, F_DRAFT);
6116 g_return_if_fail(draft != NULL);
6120 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
6121 G_DIR_SEPARATOR, (gint)compose);
6123 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
6129 folder_item_scan(draft);
6130 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) < 0) {
6137 draft->mtime = 0; /* force updating */
6139 if (compose->mode == COMPOSE_REEDIT) {
6140 compose_remove_reedit_target(compose);
6141 if (compose->targetinfo &&
6142 compose->targetinfo->folder != draft)
6143 folderview_update_item(compose->targetinfo->folder,
6147 procmsg_add_flags(draft, msgnum, flag);
6148 folder_item_scan(draft);
6149 folderview_update_item(draft, TRUE);
6153 /* 0: quit editing 1: keep editing */
6155 gtk_widget_destroy(compose->window);
6160 path = folder_item_fetch_msg(draft, msgnum);
6161 g_return_if_fail(path != NULL);
6162 if (stat(path, &s) < 0) {
6163 FILE_OP_ERROR(path, "stat");
6170 procmsg_msginfo_free(compose->targetinfo);
6171 compose->targetinfo = g_new0(MsgInfo, 1);
6172 compose->targetinfo->msgnum = msgnum;
6173 compose->targetinfo->size = s.st_size;
6174 compose->targetinfo->mtime = s.st_mtime;
6175 compose->targetinfo->folder = draft;
6176 compose->mode = COMPOSE_REEDIT;
6180 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6182 Compose *compose = (Compose *)data;
6185 if (compose->redirect_filename != NULL)
6188 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6193 for ( tmp = file_list; tmp; tmp = tmp->next) {
6194 gchar *file = (gchar *) tmp->data;
6195 compose_attach_append(compose, file, file, NULL);
6196 compose_changed_cb(NULL, compose);
6199 g_list_free(file_list);
6203 static void compose_insert_file_cb(gpointer data, guint action,
6206 Compose *compose = (Compose *)data;
6209 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6214 for ( tmp = file_list; tmp; tmp = tmp->next) {
6215 gchar *file = (gchar *) tmp->data;
6216 compose_insert_file(compose, file);
6219 g_list_free(file_list);
6223 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6226 compose_close_cb(data, 0, NULL);
6230 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6232 Compose *compose = (Compose *)data;
6235 if (compose->exteditor_tag != -1) {
6236 if (!compose_ext_editor_kill(compose))
6240 if (compose->modified) {
6241 val = alertpanel(_("Discard message"),
6242 _("This message has been modified. discard it?"),
6243 _("Discard"), _("to Draft"), _("Cancel"));
6246 case G_ALERTDEFAULT:
6248 case G_ALERTALTERNATE:
6249 compose_draft_cb(data, 0, NULL);
6255 gtk_widget_destroy(compose->window);
6258 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6260 Compose *compose = (Compose *)data;
6262 addressbook_open(compose);
6265 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6267 Compose *compose = (Compose *)data;
6272 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6273 g_return_if_fail(tmpl != NULL);
6275 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6277 val = alertpanel(_("Apply template"), msg,
6278 _("Replace"), _("Insert"), _("Cancel"));
6281 if (val == G_ALERTDEFAULT)
6282 compose_template_apply(compose, tmpl, TRUE);
6283 else if (val == G_ALERTALTERNATE)
6284 compose_template_apply(compose, tmpl, FALSE);
6287 static void compose_ext_editor_cb(gpointer data, guint action,
6290 Compose *compose = (Compose *)data;
6292 compose_exec_ext_editor(compose);
6295 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6297 compose_destroy(compose);
6300 static void compose_undo_cb(Compose *compose)
6302 undo_undo(compose->undostruct);
6305 static void compose_redo_cb(Compose *compose)
6307 undo_redo(compose->undostruct);
6310 static void compose_cut_cb(Compose *compose)
6312 if (compose->focused_editable &&
6313 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6314 gtk_editable_cut_clipboard
6315 (GTK_EDITABLE(compose->focused_editable));
6318 static void compose_copy_cb(Compose *compose)
6320 if (compose->focused_editable &&
6321 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6322 gtk_editable_copy_clipboard
6323 (GTK_EDITABLE(compose->focused_editable));
6326 static void compose_paste_cb(Compose *compose)
6328 if (compose->focused_editable &&
6329 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6330 gtk_editable_paste_clipboard
6331 (GTK_EDITABLE(compose->focused_editable));
6334 static void compose_allsel_cb(Compose *compose)
6336 if (compose->focused_editable &&
6337 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6338 gtk_editable_select_region
6339 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6342 static void compose_move_beginning_of_line_cb(Compose *compose)
6344 if (compose->focused_editable &&
6345 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6346 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6349 static void compose_gtk_stext_action_cb(Compose *compose, ComposeCallGtkSTextAction action)
6351 if (!(compose->focused_editable && GTK_WIDGET_HAS_FOCUS(compose->focused_editable))) return;
6354 case COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE:
6355 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6357 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER:
6358 gtk_stext_move_forward_character(GTK_STEXT(compose->focused_editable));
6360 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER:
6361 gtk_stext_move_backward_character(GTK_STEXT(compose->focused_editable));
6363 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD:
6364 gtk_stext_move_forward_word(GTK_STEXT(compose->focused_editable));
6366 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD:
6367 gtk_stext_move_backward_word(GTK_STEXT(compose->focused_editable));
6369 case COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE:
6370 gtk_stext_move_end_of_line(GTK_STEXT(compose->focused_editable));
6372 case COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE:
6373 gtk_stext_move_next_line(GTK_STEXT(compose->focused_editable));
6375 case COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE:
6376 gtk_stext_move_previous_line(GTK_STEXT(compose->focused_editable));
6378 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER:
6379 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6381 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER:
6382 gtk_stext_delete_backward_character(GTK_STEXT(compose->focused_editable));
6384 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD:
6385 gtk_stext_delete_forward_word(GTK_STEXT(compose->focused_editable));
6387 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD:
6388 gtk_stext_delete_backward_word(GTK_STEXT(compose->focused_editable));
6390 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE:
6391 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6393 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N:
6394 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6395 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6397 case COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END:
6398 gtk_stext_delete_to_line_end(GTK_STEXT(compose->focused_editable));
6405 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6407 if (GTK_IS_EDITABLE(widget))
6408 compose->focused_editable = widget;
6411 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6413 if (compose->modified == FALSE) {
6414 compose->modified = TRUE;
6415 compose_set_title(compose);
6419 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6422 gtk_stext_set_point(GTK_STEXT(widget),
6423 gtk_editable_get_position(GTK_EDITABLE(widget)));
6427 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6430 gtk_stext_set_point(GTK_STEXT(widget),
6431 gtk_editable_get_position(GTK_EDITABLE(widget)));
6435 #if 0 /* NEW COMPOSE GUI */
6436 static void compose_toggle_to_cb(gpointer data, guint action,
6439 Compose *compose = (Compose *)data;
6441 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6442 gtk_widget_show(compose->to_hbox);
6443 gtk_widget_show(compose->to_entry);
6444 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6445 compose->use_to = TRUE;
6447 gtk_widget_hide(compose->to_hbox);
6448 gtk_widget_hide(compose->to_entry);
6449 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6450 gtk_widget_queue_resize(compose->table_vbox);
6451 compose->use_to = FALSE;
6454 if (addressbook_get_target_compose() == compose)
6455 addressbook_set_target_compose(compose);
6458 static void compose_toggle_cc_cb(gpointer data, guint action,
6461 Compose *compose = (Compose *)data;
6463 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6464 gtk_widget_show(compose->cc_hbox);
6465 gtk_widget_show(compose->cc_entry);
6466 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6467 compose->use_cc = TRUE;
6469 gtk_widget_hide(compose->cc_hbox);
6470 gtk_widget_hide(compose->cc_entry);
6471 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6472 gtk_widget_queue_resize(compose->table_vbox);
6473 compose->use_cc = FALSE;
6476 if (addressbook_get_target_compose() == compose)
6477 addressbook_set_target_compose(compose);
6480 static void compose_toggle_bcc_cb(gpointer data, guint action,
6483 Compose *compose = (Compose *)data;
6485 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6486 gtk_widget_show(compose->bcc_hbox);
6487 gtk_widget_show(compose->bcc_entry);
6488 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6489 compose->use_bcc = TRUE;
6491 gtk_widget_hide(compose->bcc_hbox);
6492 gtk_widget_hide(compose->bcc_entry);
6493 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6494 gtk_widget_queue_resize(compose->table_vbox);
6495 compose->use_bcc = FALSE;
6498 if (addressbook_get_target_compose() == compose)
6499 addressbook_set_target_compose(compose);
6502 static void compose_toggle_replyto_cb(gpointer data, guint action,
6505 Compose *compose = (Compose *)data;
6507 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6508 gtk_widget_show(compose->reply_hbox);
6509 gtk_widget_show(compose->reply_entry);
6510 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6511 compose->use_replyto = TRUE;
6513 gtk_widget_hide(compose->reply_hbox);
6514 gtk_widget_hide(compose->reply_entry);
6515 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6516 gtk_widget_queue_resize(compose->table_vbox);
6517 compose->use_replyto = FALSE;
6521 static void compose_toggle_followupto_cb(gpointer data, guint action,
6524 Compose *compose = (Compose *)data;
6526 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6527 gtk_widget_show(compose->followup_hbox);
6528 gtk_widget_show(compose->followup_entry);
6529 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6530 compose->use_followupto = TRUE;
6532 gtk_widget_hide(compose->followup_hbox);
6533 gtk_widget_hide(compose->followup_entry);
6534 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6535 gtk_widget_queue_resize(compose->table_vbox);
6536 compose->use_followupto = FALSE;
6540 static void compose_toggle_attach_cb(gpointer data, guint action,
6543 Compose *compose = (Compose *)data;
6545 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6546 gtk_widget_ref(compose->edit_vbox);
6548 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6549 compose->edit_vbox);
6550 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6551 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6553 gtk_widget_show(compose->paned);
6555 gtk_widget_unref(compose->edit_vbox);
6556 gtk_widget_unref(compose->paned);
6558 compose->use_attach = TRUE;
6560 gtk_widget_ref(compose->paned);
6561 gtk_widget_ref(compose->edit_vbox);
6563 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6565 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6566 compose->edit_vbox);
6567 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6568 compose->edit_vbox, TRUE, TRUE, 0);
6570 gtk_widget_unref(compose->edit_vbox);
6572 compose->use_attach = FALSE;
6578 static void compose_toggle_sign_cb(gpointer data, guint action,
6581 Compose *compose = (Compose *)data;
6583 if (GTK_CHECK_MENU_ITEM(widget)->active)
6584 compose->use_signing = TRUE;
6586 compose->use_signing = FALSE;
6589 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6592 Compose *compose = (Compose *)data;
6594 if (GTK_CHECK_MENU_ITEM(widget)->active)
6595 compose->use_encryption = TRUE;
6597 compose->use_encryption = FALSE;
6599 #endif /* USE_GPGME */
6601 static void compose_toggle_ruler_cb(gpointer data, guint action,
6604 Compose *compose = (Compose *)data;
6606 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6607 gtk_widget_show(compose->ruler_hbox);
6608 prefs_common.show_ruler = TRUE;
6610 gtk_widget_hide(compose->ruler_hbox);
6611 gtk_widget_queue_resize(compose->edit_vbox);
6612 prefs_common.show_ruler = FALSE;
6616 static void compose_attach_drag_received_cb (GtkWidget *widget,
6617 GdkDragContext *drag_context,
6620 GtkSelectionData *data,
6625 Compose *compose = (Compose *)user_data;
6628 list = uri_list_extract_filenames((const gchar *)data->data);
6629 for (tmp = list; tmp != NULL; tmp = tmp->next)
6630 compose_attach_append
6631 (compose, (const gchar *)tmp->data,
6632 (const gchar *)tmp->data, NULL);
6633 if (list) compose_changed_cb(NULL, compose);
6634 list_free_strings(list);
6638 static void compose_insert_drag_received_cb (GtkWidget *widget,
6639 GdkDragContext *drag_context,
6642 GtkSelectionData *data,
6647 Compose *compose = (Compose *)user_data;
6650 list = uri_list_extract_filenames((const gchar *)data->data);
6651 for (tmp = list; tmp != NULL; tmp = tmp->next)
6652 compose_insert_file(compose, (const gchar *)tmp->data);
6653 list_free_strings(list);
6657 #if 0 /* NEW COMPOSE GUI */
6658 static void to_activated(GtkWidget *widget, Compose *compose)
6660 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6661 gtk_widget_grab_focus(compose->newsgroups_entry);
6663 gtk_widget_grab_focus(compose->subject_entry);
6666 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6668 gtk_widget_grab_focus(compose->subject_entry);
6671 static void subject_activated(GtkWidget *widget, Compose *compose)
6673 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6674 gtk_widget_grab_focus(compose->cc_entry);
6675 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6676 gtk_widget_grab_focus(compose->bcc_entry);
6677 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6678 gtk_widget_grab_focus(compose->reply_entry);
6679 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6680 gtk_widget_grab_focus(compose->followup_entry);
6682 gtk_widget_grab_focus(compose->text);
6685 static void cc_activated(GtkWidget *widget, Compose *compose)
6687 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6688 gtk_widget_grab_focus(compose->bcc_entry);
6689 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6690 gtk_widget_grab_focus(compose->reply_entry);
6691 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6692 gtk_widget_grab_focus(compose->followup_entry);
6694 gtk_widget_grab_focus(compose->text);
6697 static void bcc_activated(GtkWidget *widget, Compose *compose)
6699 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6700 gtk_widget_grab_focus(compose->reply_entry);
6701 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6702 gtk_widget_grab_focus(compose->followup_entry);
6704 gtk_widget_grab_focus(compose->text);
6707 static void replyto_activated(GtkWidget *widget, Compose *compose)
6709 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6710 gtk_widget_grab_focus(compose->followup_entry);
6712 gtk_widget_grab_focus(compose->text);
6715 static void followupto_activated(GtkWidget *widget, Compose *compose)
6717 gtk_widget_grab_focus(compose->text);
6721 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6724 Compose *compose = (Compose *)data;
6726 if (GTK_CHECK_MENU_ITEM(widget)->active)
6727 compose->return_receipt = TRUE;
6729 compose->return_receipt = FALSE;
6732 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6734 ComposeHeaderEntry *headerentry)
6736 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6737 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6738 !(event->state & GDK_MODIFIER_MASK) &&
6739 (event->keyval == GDK_BackSpace) &&
6740 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6741 gtk_container_remove
6742 (GTK_CONTAINER(headerentry->compose->header_table),
6743 headerentry->combo);
6744 gtk_container_remove
6745 (GTK_CONTAINER(headerentry->compose->header_table),
6746 headerentry->entry);
6747 headerentry->compose->header_list =
6748 g_slist_remove(headerentry->compose->header_list,
6750 g_free(headerentry);
6751 } else if (event->keyval == GDK_Tab) {
6752 if (headerentry->compose->header_last == headerentry) {
6753 /* Override default next focus, and give it to subject_entry
6754 * instead of notebook tabs
6756 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6757 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6763 void compose_headerentry_changed_cb(GtkWidget *entry,
6764 ComposeHeaderEntry *headerentry)
6766 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6767 headerentry->compose->header_list =
6768 g_slist_append(headerentry->compose->header_list,
6770 compose_create_header_entry(headerentry->compose);
6771 gtk_signal_disconnect_by_func
6773 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6775 /* Automatically scroll down */
6776 compose_show_first_last_header(headerentry->compose, FALSE);
6781 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6783 GtkAdjustment *vadj;
6785 g_return_if_fail(compose);
6786 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6787 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6789 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6790 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6793 static void text_activated(GtkWidget *widget, Compose *compose)
6795 compose_send_control_enter(compose);
6798 static gboolean compose_send_control_enter(Compose *compose)
6802 GtkItemFactory *ifactory;
6803 GtkAccelEntry *accel;
6804 GtkWidget *send_menu;
6806 GdkModifierType ignored_mods =
6807 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
6808 GDK_MOD4_MASK | GDK_MOD5_MASK);
6810 ev = gtk_get_current_event();
6811 if (ev->type != GDK_KEY_PRESS) return FALSE;
6813 kev = (GdkEventKey *)ev;
6814 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6817 ifactory = gtk_item_factory_from_widget(compose->menubar);
6818 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6819 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6820 accel = (GtkAccelEntry *)list->data;
6821 if (accel->accelerator_key == kev->keyval &&
6822 (accel->accelerator_mods & ~ignored_mods) ==
6823 (kev->state & ~ignored_mods)) {
6824 compose_send_cb(compose, 0, NULL);
6832 static void compose_check_all(Compose *compose)
6834 if (compose->gtkpspell)
6835 gtkpspell_check_all(compose->gtkpspell);
6838 static void compose_highlight_all(Compose *compose)
6840 if (compose->gtkpspell)
6841 gtkpspell_highlight_all(compose->gtkpspell);
6844 static void compose_check_backwards(Compose *compose)
6846 if (compose->gtkpspell)
6847 gtkpspell_check_backwards(compose->gtkpspell);
6849 GtkItemFactory *ifactory;
6850 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6851 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6852 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6856 static void compose_check_forwards_go(Compose *compose)
6858 if (compose->gtkpspell)
6859 gtkpspell_check_forwards_go(compose->gtkpspell);
6861 GtkItemFactory *ifactory;
6862 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6863 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6864 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6869 static void set_toolbar_style(Compose *compose)
6871 switch (prefs_common.toolbar_style) {
6873 gtk_widget_hide(compose->handlebox);
6876 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6880 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6884 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6889 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
6890 gtk_widget_show(compose->handlebox);
6891 gtk_widget_queue_resize(compose->handlebox);