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"
87 #include "prefs_actions.h"
90 #include "procheader.h"
92 #include "statusbar.h"
99 #include "alertpanel.h"
100 #include "manage_window.h"
101 #include "gtkshruler.h"
103 #include "addr_compl.h"
104 #include "quote_fmt.h"
105 #include "template.h"
107 #include "foldersel.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,
162 GPtrArray *attach_files);
164 static Compose *compose_create (PrefsAccount *account,
166 static void compose_toolbar_create (Compose *compose,
167 GtkWidget *container);
168 static GtkWidget *compose_account_option_menu_create
170 static void compose_set_template_menu (Compose *compose);
171 static void compose_template_apply (Compose *compose,
174 static void compose_destroy (Compose *compose);
176 static void compose_entries_set (Compose *compose,
177 const gchar *mailto);
178 static gint compose_parse_header (Compose *compose,
180 static gchar *compose_parse_references (const gchar *ref,
183 static gchar *compose_quote_fmt (Compose *compose,
189 static void compose_reply_set_entry (Compose *compose,
194 followup_and_reply_to);
195 static void compose_reedit_set_entry (Compose *compose,
197 static void compose_insert_sig (Compose *compose);
198 static void compose_insert_file (Compose *compose,
200 static void compose_attach_append (Compose *compose,
203 const gchar *content_type);
204 static void compose_attach_parts (Compose *compose,
206 static void compose_wrap_line (Compose *compose);
207 static void compose_wrap_line_all (Compose *compose);
208 static void compose_set_title (Compose *compose);
210 static PrefsAccount *compose_current_mail_account(void);
211 /* static gint compose_send (Compose *compose); */
212 static gboolean compose_check_for_valid_recipient
214 static gboolean compose_check_entries (Compose *compose,
215 gboolean check_subject);
216 static gint compose_write_to_file (Compose *compose,
219 static gint compose_write_body_to_file (Compose *compose,
221 static gint compose_remove_reedit_target (Compose *compose);
222 static gint compose_queue (Compose *compose,
225 static gint compose_queue_sub (Compose *compose,
228 gboolean check_subject);
229 static void compose_write_attach (Compose *compose,
231 static gint compose_write_headers (Compose *compose,
233 const gchar *charset,
234 EncodingType encoding,
237 static void compose_convert_header (gchar *dest,
241 static void compose_generate_msgid (Compose *compose,
245 static void compose_attach_info_free (AttachInfo *ainfo);
246 static void compose_attach_remove_selected (Compose *compose);
248 static void compose_attach_property (Compose *compose);
249 static void compose_attach_property_create (gboolean *cancelled);
250 static void attach_property_ok (GtkWidget *widget,
251 gboolean *cancelled);
252 static void attach_property_cancel (GtkWidget *widget,
253 gboolean *cancelled);
254 static gint attach_property_delete_event (GtkWidget *widget,
256 gboolean *cancelled);
257 static void attach_property_key_pressed (GtkWidget *widget,
259 gboolean *cancelled);
261 static void compose_exec_ext_editor (Compose *compose);
262 static gint compose_exec_ext_editor_real (const gchar *file);
263 static gboolean compose_ext_editor_kill (Compose *compose);
264 static void compose_input_cb (gpointer data,
266 GdkInputCondition condition);
267 static void compose_set_ext_editor_sensitive (Compose *compose,
270 static void compose_undo_state_changed (UndoMain *undostruct,
275 static gint calc_cursor_xpos (GtkSText *text,
279 static void compose_create_header_entry (Compose *compose);
280 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
281 static void compose_update_priority_menu_item(Compose * compose);
283 /* callback functions */
285 static gboolean compose_edit_size_alloc (GtkEditable *widget,
286 GtkAllocation *allocation,
287 GtkSHRuler *shruler);
289 static void toolbar_send_cb (GtkWidget *widget,
291 static void toolbar_send_later_cb (GtkWidget *widget,
293 static void toolbar_draft_cb (GtkWidget *widget,
295 static void toolbar_insert_cb (GtkWidget *widget,
297 static void toolbar_attach_cb (GtkWidget *widget,
299 static void toolbar_sig_cb (GtkWidget *widget,
301 static void toolbar_ext_editor_cb (GtkWidget *widget,
303 static void toolbar_linewrap_cb (GtkWidget *widget,
305 static void toolbar_address_cb (GtkWidget *widget,
308 static void select_account (Compose *compose,
311 static void account_activated (GtkMenuItem *menuitem,
314 static void attach_selected (GtkCList *clist,
319 static void attach_button_pressed (GtkWidget *widget,
320 GdkEventButton *event,
322 static void attach_key_pressed (GtkWidget *widget,
326 static void compose_send_cb (gpointer data,
329 static void compose_send_later_cb (gpointer data,
333 static void compose_draft_cb (gpointer data,
337 static void compose_attach_cb (gpointer data,
340 static void compose_insert_file_cb (gpointer data,
344 static void compose_close_cb (gpointer data,
348 static void compose_address_cb (gpointer data,
351 static void compose_template_activate_cb(GtkWidget *widget,
354 static void compose_ext_editor_cb (gpointer data,
358 static gint compose_delete_cb (GtkWidget *widget,
361 static void compose_destroy_cb (GtkWidget *widget,
364 static void compose_undo_cb (Compose *compose);
365 static void compose_redo_cb (Compose *compose);
366 static void compose_cut_cb (Compose *compose);
367 static void compose_copy_cb (Compose *compose);
368 static void compose_paste_cb (Compose *compose);
369 static void compose_paste_as_quote_cb (Compose *compose);
370 static void compose_allsel_cb (Compose *compose);
372 static void compose_gtk_stext_action_cb (Compose *compose,
373 ComposeCallGtkSTextAction action);
375 static void compose_grab_focus_cb (GtkWidget *widget,
378 static void compose_changed_cb (GtkEditable *editable,
380 static void compose_button_press_cb (GtkWidget *widget,
381 GdkEventButton *event,
384 static void compose_key_press_cb (GtkWidget *widget,
390 static void compose_toggle_to_cb (gpointer data,
393 static void compose_toggle_cc_cb (gpointer data,
396 static void compose_toggle_bcc_cb (gpointer data,
399 static void compose_toggle_replyto_cb (gpointer data,
402 static void compose_toggle_followupto_cb(gpointer data,
405 static void compose_toggle_attach_cb (gpointer data,
409 static void compose_toggle_ruler_cb (gpointer data,
413 static void compose_toggle_sign_cb (gpointer data,
416 static void compose_toggle_encrypt_cb (gpointer data,
420 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
422 static void compose_set_priority_cb (gpointer data,
426 static void compose_attach_drag_received_cb (GtkWidget *widget,
427 GdkDragContext *drag_context,
430 GtkSelectionData *data,
434 static void compose_insert_drag_received_cb (GtkWidget *widget,
435 GdkDragContext *drag_context,
438 GtkSelectionData *data,
444 static void to_activated (GtkWidget *widget,
446 static void newsgroups_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,
456 static void subject_activated (GtkWidget *widget,
460 static void text_activated (GtkWidget *widget,
462 static void text_inserted (GtkWidget *widget,
467 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
469 gboolean ignore_replyto,
470 gboolean followup_and_reply_to,
473 void compose_headerentry_changed_cb (GtkWidget *entry,
474 ComposeHeaderEntry *headerentry);
475 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
477 ComposeHeaderEntry *headerentry);
479 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
482 static void compose_check_all (Compose *compose);
483 static void compose_highlight_all (Compose *compose);
484 static void compose_check_backwards (Compose *compose);
485 static void compose_check_forwards_go (Compose *compose);
488 static gboolean compose_send_control_enter (Compose *compose);
490 static GtkItemFactoryEntry compose_popup_entries[] =
492 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
493 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
494 {N_("/---"), NULL, NULL, 0, "<Separator>"},
495 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
498 static GtkItemFactoryEntry compose_entries[] =
500 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
501 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
502 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
503 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
504 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
505 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
507 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
508 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
509 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
510 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
511 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
512 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
513 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
514 {N_("/_Edit/Paste as _quotation"),
515 NULL, compose_paste_as_quote_cb, 0, NULL},
516 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
517 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
518 {N_("/_Edit/A_dvanced/Move a character backward"),
520 compose_gtk_stext_action_cb,
521 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
523 {N_("/_Edit/A_dvanced/Move a character forward"),
525 compose_gtk_stext_action_cb,
526 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
528 {N_("/_Edit/A_dvanced/Move a word backward"),
530 compose_gtk_stext_action_cb,
531 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
533 {N_("/_Edit/A_dvanced/Move a word forward"),
535 compose_gtk_stext_action_cb,
536 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
538 {N_("/_Edit/A_dvanced/Move to beginning of line"),
539 NULL, /* "<control>A" */
540 compose_gtk_stext_action_cb,
541 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
543 {N_("/_Edit/A_dvanced/Move to end of line"),
545 compose_gtk_stext_action_cb,
546 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
548 {N_("/_Edit/A_dvanced/Move to previous line"),
550 compose_gtk_stext_action_cb,
551 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
553 {N_("/_Edit/A_dvanced/Move to next line"),
555 compose_gtk_stext_action_cb,
556 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
558 {N_("/_Edit/A_dvanced/Delete a character backward"),
560 compose_gtk_stext_action_cb,
561 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
563 {N_("/_Edit/A_dvanced/Delete a character forward"),
565 compose_gtk_stext_action_cb,
566 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
568 {N_("/_Edit/A_dvanced/Delete a word backward"),
569 NULL, /* "<control>W" */
570 compose_gtk_stext_action_cb,
571 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
573 {N_("/_Edit/A_dvanced/Delete a word forward"),
574 NULL, /* "<alt>D", */
575 compose_gtk_stext_action_cb,
576 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
578 {N_("/_Edit/A_dvanced/Delete line"),
580 compose_gtk_stext_action_cb,
581 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
583 {N_("/_Edit/A_dvanced/Delete entire line"),
585 compose_gtk_stext_action_cb,
586 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
588 {N_("/_Edit/A_dvanced/Delete to end of line"),
590 compose_gtk_stext_action_cb,
591 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
593 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
594 {N_("/_Edit/_Wrap current paragraph"),
595 "<control>L", compose_wrap_line, 0, NULL},
596 {N_("/_Edit/Wrap all long _lines"),
597 "<control><alt>L", compose_wrap_line_all, 0, NULL},
598 {N_("/_Edit/Edit with e_xternal editor"),
599 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
601 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
602 {N_("/_Spelling/_Check all or check selection"),
603 NULL, compose_check_all, 0, NULL},
604 {N_("/_Spelling/_Highlight all misspelled words"),
605 NULL, compose_highlight_all, 0, NULL},
606 {N_("/_Spelling/Check _backwards misspelled word"),
607 NULL, compose_check_backwards , 0, NULL},
608 {N_("/_Spelling/_Forward to next misspelled word"),
609 NULL, compose_check_forwards_go, 0, NULL},
610 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
611 {N_("/_Spelling/_Spelling Configuration"),
612 NULL, NULL, 0, "<Branch>"},
614 #if 0 /* NEW COMPOSE GUI */
615 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
616 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
617 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
618 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
619 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
620 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
621 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
622 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
623 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
624 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
625 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
627 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
628 {N_("/_Message/_Send"), "<control>Return",
629 compose_send_cb, 0, NULL},
630 {N_("/_Message/Send _later"), "<shift><control>S",
631 compose_send_later_cb, 0, NULL},
632 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
633 {N_("/_Message/Save to _draft folder"),
634 "<shift><control>D", compose_draft_cb, 0, NULL},
635 {N_("/_Message/Save and _keep editing"),
636 "<control>S", compose_draft_cb, 1, NULL},
637 #if 0 /* NEW COMPOSE GUI */
638 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
639 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
640 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
641 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
642 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
643 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
644 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
645 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
646 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
649 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
650 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
651 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
652 #endif /* USE_GPGME */
653 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
654 {N_("/_Message/_Priority"), NULL, NULL, 0, "<Branch>"},
655 {N_("/_Message/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
656 {N_("/_Message/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
657 {N_("/_Message/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
658 {N_("/_Message/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
659 {N_("/_Message/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
660 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
661 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
662 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
663 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
664 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
665 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
666 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
667 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
668 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
671 static GtkTargetEntry compose_mime_types[] =
673 {"text/uri-list", 0, 0}
676 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
680 GtkItemFactory *ifactory;
682 c = compose_generic_new(account, NULL, NULL, NULL);
684 filename = procmsg_get_message_file(msginfo);
685 if (filename == NULL)
688 c->redirect_filename = filename;
690 if (msginfo->subject)
691 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
693 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
695 compose_quote_fmt(c, msginfo, "%M", NULL, NULL);
696 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
698 ifactory = gtk_item_factory_from_widget(c->popupmenu);
699 menu_set_sensitive(ifactory, "/Add...", FALSE);
700 menu_set_sensitive(ifactory, "/Remove", FALSE);
701 menu_set_sensitive(ifactory, "/Property...", FALSE);
703 ifactory = gtk_item_factory_from_widget(c->menubar);
704 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
705 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
706 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
707 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
708 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
709 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
710 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
711 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
713 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
714 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
716 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
717 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
719 gtk_widget_set_sensitive(c->insert_btn, FALSE);
720 gtk_widget_set_sensitive(c->attach_btn, FALSE);
721 gtk_widget_set_sensitive(c->sig_btn, FALSE);
722 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
723 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
728 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
729 GPtrArray *attach_files)
731 return compose_generic_new(account, mailto, NULL, attach_files);
734 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
736 return compose_generic_new(account, NULL, item, NULL);
739 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
740 GPtrArray *attach_files)
744 GtkItemFactory *ifactory;
745 gboolean grab_focus_on_last = TRUE;
747 if (item && item->prefs && item->prefs->enable_default_account)
748 account = account_find_from_id(item->prefs->default_account);
750 if (!account) account = cur_account;
751 g_return_val_if_fail(account != NULL, NULL);
753 compose = compose_create(account, COMPOSE_NEW);
754 ifactory = gtk_item_factory_from_widget(compose->menubar);
756 compose->replyinfo = NULL;
758 text = GTK_STEXT(compose->text);
759 gtk_stext_freeze(text);
761 if (prefs_common.auto_sig)
762 compose_insert_sig(compose);
763 gtk_editable_set_position(GTK_EDITABLE(text), 0);
764 gtk_stext_set_point(text, 0);
766 gtk_stext_thaw(text);
768 /* workaround for initial XIM problem */
769 gtk_widget_grab_focus(compose->text);
770 gtkut_widget_wait_for_draw(compose->text);
772 if (account->protocol != A_NNTP) {
773 if (mailto && *mailto != '\0') {
774 compose_entries_set(compose, mailto);
776 } else if(item && item->prefs->enable_default_to) {
777 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
778 compose_entry_select(compose, item->prefs->default_to);
779 grab_focus_on_last = FALSE;
781 if (item && item->ret_rcpt) {
782 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
786 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
789 * CLAWS: just don't allow return receipt request, even if the user
790 * may want to send an email. simple but foolproof.
792 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
799 for (i = 0; i < attach_files->len; i++) {
800 file = g_ptr_array_index(attach_files, i);
801 compose_attach_append(compose, file, file, NULL);
805 compose_show_first_last_header(compose, TRUE);
807 /* Set save folder */
808 if(item && item->prefs && item->prefs->save_copy_to_folder) {
809 gchar *folderidentifier;
811 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
812 folderidentifier = folder_item_get_identifier(item);
813 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
814 g_free(folderidentifier);
817 /* Grab focus on last header only if no default_to was set */
818 if(grab_focus_on_last)
819 gtk_widget_grab_focus(compose->header_last->entry);
821 if (prefs_common.auto_exteditor)
822 compose_exec_ext_editor(compose);
827 #define CHANGE_FLAGS(msginfo) \
829 if (msginfo->folder->folder->change_flags != NULL) \
830 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
836 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
837 const gchar *followupto, gchar * to)
841 if (!account) account = cur_account;
842 g_return_val_if_fail(account != NULL, NULL);
843 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
845 compose = compose_create(account, COMPOSE_NEW);
847 if (prefs_common.auto_sig)
848 compose_insert_sig(compose);
849 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
850 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
852 compose_entry_append(compose, to, COMPOSE_TO);
853 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
854 gtk_widget_grab_focus(compose->subject_entry);
860 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
861 gboolean ignore_replyto, const gchar *body)
863 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE,
867 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
869 gboolean ignore_replyto,
872 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE,
876 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
878 gboolean ignore_replyto,
879 gboolean followup_and_reply_to,
883 PrefsAccount *account;
884 PrefsAccount *reply_account;
887 g_return_if_fail(msginfo != NULL);
888 g_return_if_fail(msginfo->folder != NULL);
891 /* select the account set in folderitem's property (if enabled) */
892 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
893 account = account_find_from_id(msginfo->folder->prefs->default_account);
895 /* select the account for the whole folder (IMAP / NNTP) */
897 /* FIXME: this is not right, because folder may be nested. we should
898 * ascend the tree until we find a parent with proper account
900 account = msginfo->folder->folder->account;
902 /* select account by to: and cc: header if enabled */
903 if (prefs_common.reply_account_autosel) {
904 if (!account && msginfo->to) {
906 Xstrdup_a(to, msginfo->to, return);
908 account = account_find_from_address(to);
912 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
914 account = account_find_from_address(cc);
919 /* select current account */
920 if (!account) account = cur_account;
921 g_return_if_fail(account != NULL);
923 if (ignore_replyto && account->protocol == A_NNTP &&
924 !followup_and_reply_to) {
926 account_find_from_address(account->address);
928 reply_account = compose_current_mail_account();
932 reply_account = account;
934 compose = compose_create(account, COMPOSE_REPLY);
935 compose->replyinfo = procmsg_msginfo_new_ref(msginfo);
937 #if 0 /* NEW COMPOSE GUI */
938 if (followup_and_reply_to) {
939 gtk_widget_show(compose->to_hbox);
940 gtk_widget_show(compose->to_entry);
941 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
942 compose->use_to = TRUE;
945 if (msginfo->folder && msginfo->folder->ret_rcpt) {
946 GtkItemFactory *ifactory;
948 ifactory = gtk_item_factory_from_widget(compose->menubar);
949 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
952 /* Set save folder */
953 if(msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
954 gchar *folderidentifier;
956 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
957 folderidentifier = folder_item_get_identifier(msginfo->folder);
958 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
959 g_free(folderidentifier);
962 if (compose_parse_header(compose, msginfo) < 0) return;
963 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
964 followup_and_reply_to);
965 compose_show_first_last_header(compose, TRUE);
967 text = GTK_STEXT(compose->text);
968 gtk_stext_freeze(text);
974 if (prefs_common.quotemark && *prefs_common.quotemark)
975 qmark = prefs_common.quotemark;
979 quote_str = compose_quote_fmt(compose, msginfo,
980 prefs_common.quotefmt,
984 if (prefs_common.auto_sig)
985 compose_insert_sig(compose);
987 if (quote && prefs_common.linewrap_quote)
988 compose_wrap_line_all(compose);
990 gtk_editable_set_position(GTK_EDITABLE(text), 0);
991 gtk_stext_set_point(text, 0);
993 gtk_stext_thaw(text);
994 gtk_widget_grab_focus(compose->text);
996 if (prefs_common.auto_exteditor)
997 compose_exec_ext_editor(compose);
1000 static void set_toolbar_style(Compose *compose);
1002 #define INSERT_FW_HEADER(var, hdr) \
1003 if (msginfo->var && *msginfo->var) { \
1004 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1005 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1006 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1009 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1010 gboolean as_attach, const gchar *body)
1013 /* PrefsAccount *account; */
1016 g_return_val_if_fail(msginfo != NULL, NULL);
1017 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1019 account = msginfo->folder->folder->account;
1020 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1022 Xstrdup_a(to, msginfo->to, return NULL);
1023 extract_address(to);
1024 account = account_find_from_address(to);
1027 if(!account && prefs_common.forward_account_autosel) {
1029 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1030 extract_address(cc);
1031 account = account_find_from_address(cc);
1035 if (account == NULL) {
1036 account = cur_account;
1038 account = msginfo->folder->folder->account;
1039 if (!account) account = cur_account;
1042 g_return_val_if_fail(account != NULL, NULL);
1044 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1045 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1046 if (MSG_IS_IMAP(msginfo->flags))
1047 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1048 CHANGE_FLAGS(msginfo);
1050 compose = compose_create(account, COMPOSE_FORWARD);
1052 if (msginfo->subject && *msginfo->subject) {
1053 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1054 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1058 text = GTK_STEXT(compose->text);
1059 gtk_stext_freeze(text);
1065 msgfile = procmsg_get_message_file_path(msginfo);
1066 if (!is_file_exist(msgfile))
1067 g_warning(_("%s: file not exist\n"), msgfile);
1069 compose_attach_append(compose, msgfile, msgfile,
1077 if (prefs_common.fw_quotemark &&
1078 *prefs_common.fw_quotemark)
1079 qmark = prefs_common.fw_quotemark;
1083 quote_str = compose_quote_fmt(compose, msginfo,
1084 prefs_common.fw_quotefmt,
1086 compose_attach_parts(compose, msginfo);
1089 if (prefs_common.auto_sig)
1090 compose_insert_sig(compose);
1092 if (prefs_common.linewrap_quote)
1093 compose_wrap_line_all(compose);
1095 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1096 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1098 gtk_stext_thaw(text);
1099 #if 0 /* NEW COMPOSE GUI */
1100 if (account->protocol != A_NNTP)
1101 gtk_widget_grab_focus(compose->to_entry);
1103 gtk_widget_grab_focus(compose->newsgroups_entry);
1105 gtk_widget_grab_focus(compose->header_last->entry);
1107 if (prefs_common.auto_exteditor)
1108 compose_exec_ext_editor(compose);
1113 #undef INSERT_FW_HEADER
1115 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1122 g_return_val_if_fail(msginfo_list != NULL, NULL);
1124 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1125 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1129 if (account == NULL) {
1130 account = cur_account;
1132 account = msginfo->folder->folder->account;
1133 if (!account) account = cur_account;
1136 g_return_val_if_fail(account != NULL, NULL);
1138 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1139 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1140 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1141 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1144 compose = compose_create(account, COMPOSE_FORWARD);
1146 text = GTK_STEXT(compose->text);
1147 gtk_stext_freeze(text);
1149 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1150 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1151 if (!is_file_exist(msgfile))
1152 g_warning(_("%s: file not exist\n"), msgfile);
1154 compose_attach_append(compose, msgfile, msgfile,
1159 if (prefs_common.auto_sig)
1160 compose_insert_sig(compose);
1162 if (prefs_common.linewrap_quote)
1163 compose_wrap_line_all(compose);
1165 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1166 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1168 gtk_stext_thaw(text);
1169 #if 0 /* NEW COMPOSE GUI */
1170 if (account->protocol != A_NNTP)
1171 gtk_widget_grab_focus(compose->to_entry);
1173 gtk_widget_grab_focus(compose->newsgroups_entry);
1179 void compose_reedit(MsgInfo *msginfo)
1182 PrefsAccount *account = NULL;
1185 gchar buf[BUFFSIZE];
1187 g_return_if_fail(msginfo != NULL);
1188 g_return_if_fail(msginfo->folder != NULL);
1190 if (msginfo->folder->stype == F_QUEUE) {
1191 gchar queueheader_buf[BUFFSIZE];
1194 /* Select Account from queue headers */
1195 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1196 sizeof(queueheader_buf), "NAID:")) {
1197 id = atoi(&queueheader_buf[5]);
1198 account = account_find_from_id(id);
1200 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1201 sizeof(queueheader_buf), "MAID:")) {
1202 id = atoi(&queueheader_buf[5]);
1203 account = account_find_from_id(id);
1205 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1206 sizeof(queueheader_buf), "S:")) {
1207 account = account_find_from_address(queueheader_buf);
1210 account = msginfo->folder->folder->account;
1212 if (!account && prefs_common.reedit_account_autosel) {
1213 gchar from[BUFFSIZE];
1214 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1215 extract_address(from);
1216 account = account_find_from_address(from);
1219 if (!account) account = cur_account;
1220 g_return_if_fail(account != NULL);
1222 compose = compose_create(account, COMPOSE_REEDIT);
1223 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1225 if (msginfo->folder->stype == F_QUEUE) {
1226 gchar queueheader_buf[BUFFSIZE];
1228 /* Set message save folder */
1229 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1232 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1233 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1234 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1238 if (compose_parse_header(compose, msginfo) < 0) return;
1239 compose_reedit_set_entry(compose, msginfo);
1241 text = GTK_STEXT(compose->text);
1242 gtk_stext_freeze(text);
1244 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1245 g_warning(_("Can't get text part\n"));
1247 while (fgets(buf, sizeof(buf), fp) != NULL)
1248 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1251 compose_attach_parts(compose, msginfo);
1253 gtk_stext_thaw(text);
1254 gtk_widget_grab_focus(compose->text);
1256 if (prefs_common.auto_exteditor)
1257 compose_exec_ext_editor(compose);
1260 GList *compose_get_compose_list(void)
1262 return compose_list;
1265 void compose_entry_append(Compose *compose, const gchar *address,
1266 ComposeEntryType type)
1270 if (!address || *address == '\0') return;
1272 #if 0 /* NEW COMPOSE GUI */
1275 entry = GTK_ENTRY(compose->cc_entry);
1278 entry = GTK_ENTRY(compose->bcc_entry);
1280 case COMPOSE_NEWSGROUPS:
1281 entry = GTK_ENTRY(compose->newsgroups_entry);
1285 entry = GTK_ENTRY(compose->to_entry);
1289 text = gtk_entry_get_text(entry);
1291 gtk_entry_append_text(entry, ", ");
1292 gtk_entry_append_text(entry, address);
1300 header = N_("Bcc:");
1302 case COMPOSE_REPLYTO:
1303 header = N_("Reply-To:");
1305 case COMPOSE_NEWSGROUPS:
1306 header = N_("Newsgroups:");
1308 case COMPOSE_FOLLOWUPTO:
1309 header = N_( "Followup-To:");
1316 header = prefs_common.trans_hdr ? gettext(header) : header;
1318 compose_add_header_entry(compose, header, (gchar *)address);
1321 void compose_entry_select (Compose *compose, const gchar *mailto)
1323 GSList *header_list;
1325 for (header_list = compose->header_list; header_list != NULL; header_list = header_list->next) {
1326 GtkEntry * entry = GTK_ENTRY(((ComposeHeaderEntry *)header_list->data)->entry);
1328 if (gtk_entry_get_text(entry) && !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1329 gtk_entry_select_region(entry, 0, -1);
1330 gtk_widget_grab_focus(GTK_WIDGET(entry));
1335 static void compose_entries_set(Compose *compose, const gchar *mailto)
1337 gchar *subject = NULL;
1345 Xstrdup_a(tmp_mailto, mailto, return);
1349 p = strchr(tmp_mailto, '?');
1356 gchar *field, *value;
1373 if (*value == '\0') continue;
1375 if (!g_strcasecmp(field, "subject")) {
1376 Xalloca(subject, strlen(value) + 1, return);
1377 decode_uri(subject, value);
1378 } else if (!g_strcasecmp(field, "cc")) {
1380 } else if (!g_strcasecmp(field, "bcc")) {
1382 } else if (!g_strcasecmp(field, "body")) {
1383 Xalloca(body, strlen(value) + 1, return);
1384 decode_uri(body, value);
1389 compose_entry_append(compose, to, COMPOSE_TO);
1391 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1393 compose_entry_append(compose, cc, COMPOSE_CC);
1395 compose_entry_append(compose, bcc, COMPOSE_BCC);
1397 gtk_stext_insert(GTK_STEXT(compose->text),
1398 NULL, NULL, NULL, body, -1);
1399 gtk_stext_insert(GTK_STEXT(compose->text),
1400 NULL, NULL, NULL, "\n", 1);
1404 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1406 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1407 {"Cc:", NULL, FALSE},
1408 {"References:", NULL, FALSE},
1409 {"Bcc:", NULL, FALSE},
1410 {"Newsgroups:", NULL, FALSE},
1411 {"Followup-To:", NULL, FALSE},
1412 {"X-Mailing-List:", NULL, FALSE},
1413 {"X-BeenThere:", NULL, FALSE},
1414 {"X-Priority:", NULL, FALSE},
1415 {NULL, NULL, FALSE}};
1425 H_X_MAILING_LIST = 6,
1432 g_return_val_if_fail(msginfo != NULL, -1);
1434 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1435 procheader_get_header_fields(fp, hentry);
1438 if (hentry[H_REPLY_TO].body != NULL) {
1439 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1440 compose->replyto = hentry[H_REPLY_TO].body;
1441 hentry[H_REPLY_TO].body = NULL;
1443 if (hentry[H_CC].body != NULL) {
1444 conv_unmime_header_overwrite(hentry[H_CC].body);
1445 compose->cc = hentry[H_CC].body;
1446 hentry[H_CC].body = NULL;
1448 if (hentry[H_X_MAILING_LIST].body != NULL) {
1449 /* this is good enough to parse debian-devel */
1450 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1451 g_return_val_if_fail(buf != NULL, -1 );
1452 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1453 compose->mailinglist = g_strdup(buf);
1455 g_free(hentry[H_X_MAILING_LIST].body);
1456 hentry[H_X_MAILING_LIST].body = NULL ;
1458 if (hentry[H_X_BEENTHERE].body != NULL) {
1459 /* this is good enough to parse the sylpheed-claws lists */
1460 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1461 g_return_val_if_fail(buf != NULL, -1 );
1462 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1463 compose->mailinglist = g_strdup(buf);
1465 g_free(hentry[H_X_BEENTHERE].body);
1466 hentry[H_X_BEENTHERE].body = NULL ;
1468 if (hentry[H_REFERENCES].body != NULL) {
1469 if (compose->mode == COMPOSE_REEDIT)
1470 compose->references = hentry[H_REFERENCES].body;
1472 compose->references = compose_parse_references
1473 (hentry[H_REFERENCES].body, msginfo->msgid);
1474 g_free(hentry[H_REFERENCES].body);
1476 hentry[H_REFERENCES].body = NULL;
1478 if (hentry[H_BCC].body != NULL) {
1479 if (compose->mode == COMPOSE_REEDIT) {
1480 conv_unmime_header_overwrite(hentry[H_BCC].body);
1481 compose->bcc = hentry[H_BCC].body;
1483 g_free(hentry[H_BCC].body);
1484 hentry[H_BCC].body = NULL;
1486 if (hentry[H_NEWSGROUPS].body != NULL) {
1487 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1488 hentry[H_NEWSGROUPS].body = NULL;
1490 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1491 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1492 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1493 hentry[H_FOLLOWUP_TO].body = NULL;
1496 if (compose->mode == COMPOSE_REEDIT)
1497 if (hentry[H_X_PRIORITY].body != NULL) {
1500 priority = atoi(hentry[H_X_PRIORITY].body);
1501 g_free(hentry[H_X_PRIORITY].body);
1503 hentry[H_X_PRIORITY].body = NULL;
1505 if (priority < PRIORITY_HIGHEST ||
1506 priority > PRIORITY_LOWEST)
1507 priority = PRIORITY_NORMAL;
1509 compose->priority = priority;
1512 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1513 compose->inreplyto = g_strdup(msginfo->inreplyto);
1514 else if (compose->mode != COMPOSE_REEDIT &&
1515 msginfo->msgid && *msginfo->msgid) {
1516 compose->inreplyto = g_strdup(msginfo->msgid);
1518 if (!compose->references) {
1519 if (msginfo->inreplyto && *msginfo->inreplyto)
1520 compose->references =
1521 g_strdup_printf("<%s>\n\t<%s>",
1525 compose->references =
1526 g_strconcat("<", msginfo->msgid, ">",
1534 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1536 GSList *ref_id_list, *cur;
1540 ref_id_list = references_list_append(NULL, ref);
1541 if (!ref_id_list) return NULL;
1542 if (msgid && *msgid)
1543 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1548 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1549 /* "<" + Message-ID + ">" + CR+LF+TAB */
1550 len += strlen((gchar *)cur->data) + 5;
1552 if (len > MAX_REFERENCES_LEN) {
1553 /* remove second message-ID */
1554 if (ref_id_list && ref_id_list->next &&
1555 ref_id_list->next->next) {
1556 g_free(ref_id_list->next->data);
1557 ref_id_list = g_slist_remove
1558 (ref_id_list, ref_id_list->next->data);
1560 slist_free_strings(ref_id_list);
1561 g_slist_free(ref_id_list);
1568 new_ref = g_string_new("");
1569 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1570 if (new_ref->len > 0)
1571 g_string_append(new_ref, "\n\t");
1572 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1575 slist_free_strings(ref_id_list);
1576 g_slist_free(ref_id_list);
1578 new_ref_str = new_ref->str;
1579 g_string_free(new_ref, FALSE);
1584 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1585 const gchar *fmt, const gchar *qmark,
1588 GtkSText *text = GTK_STEXT(compose->text);
1589 static MsgInfo dummyinfo;
1590 gchar *quote_str = NULL;
1596 msginfo = &dummyinfo;
1598 if (qmark != NULL) {
1599 quote_fmt_init(msginfo, NULL, NULL);
1600 quote_fmt_scan_string(qmark);
1603 buf = quote_fmt_get_buffer();
1605 alertpanel_error(_("Quote mark format error."));
1607 Xstrdup_a(quote_str, buf, return NULL)
1610 if (fmt && *fmt != '\0') {
1611 quote_fmt_init(msginfo, quote_str, body);
1612 quote_fmt_scan_string(fmt);
1615 buf = quote_fmt_get_buffer();
1617 alertpanel_error(_("Message reply/forward format error."));
1623 gtk_stext_freeze(text);
1625 for (p = buf; *p != '\0'; ) {
1626 lastp = strchr(p, '\n');
1627 len = lastp ? lastp - p + 1 : -1;
1628 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1635 gtk_stext_thaw(text);
1640 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1641 gboolean to_all, gboolean ignore_replyto,
1642 gboolean followup_and_reply_to)
1644 GSList *cc_list = NULL;
1647 gchar *replyto = NULL;
1648 GHashTable *to_table;
1650 g_return_if_fail(compose->account != NULL);
1651 g_return_if_fail(msginfo != NULL);
1653 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1654 compose_entry_append(compose,
1655 ((compose->replyto && !ignore_replyto)
1657 : (compose->mailinglist && !ignore_replyto)
1658 ? compose->mailinglist
1659 : msginfo->from ? msginfo->from : ""),
1662 if (compose->account->protocol == A_NNTP) {
1664 compose_entry_append
1665 (compose, msginfo->from ? msginfo->from : "",
1668 compose_entry_append
1670 compose->followup_to ? compose->followup_to
1671 : compose->newsgroups ? compose->newsgroups
1673 COMPOSE_NEWSGROUPS);
1676 if (msginfo->subject && *msginfo->subject) {
1677 gchar *buf, *buf2, *p;
1679 buf = g_strdup(msginfo->subject);
1680 while (!strncasecmp(buf, "Re:", 3)) {
1682 while (isspace(*p)) p++;
1683 memmove(buf, p, strlen(p) + 1);
1686 buf2 = g_strdup_printf("Re: %s", buf);
1687 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1691 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1693 if (!to_all || compose->account->protocol == A_NNTP) return;
1695 if (compose->replyto) {
1696 Xstrdup_a(replyto, compose->replyto, return);
1697 extract_address(replyto);
1699 if (msginfo->from) {
1700 Xstrdup_a(from, msginfo->from, return);
1701 extract_address(from);
1704 if (compose->mailinglist && from) {
1705 cc_list = address_list_append(cc_list, from);
1708 if (replyto && from)
1709 cc_list = address_list_append(cc_list, from);
1711 if (!compose->mailinglist)
1712 cc_list = address_list_append(cc_list, msginfo->to);
1714 cc_list = address_list_append(cc_list, compose->cc);
1716 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1718 g_hash_table_insert(to_table, replyto, GINT_TO_POINTER(1));
1719 if (compose->account)
1720 g_hash_table_insert(to_table, compose->account->address,
1721 GINT_TO_POINTER(1));
1723 /* remove address on To: and that of current account */
1724 for (cur = cc_list; cur != NULL; ) {
1725 GSList *next = cur->next;
1727 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1728 cc_list = g_slist_remove(cc_list, cur->data);
1730 g_hash_table_insert(to_table, cur->data, cur);
1734 g_hash_table_destroy(to_table);
1737 for (cur = cc_list; cur != NULL; cur = cur->next)
1738 compose_entry_append(compose, (gchar *)cur->data,
1740 slist_free_strings(cc_list);
1741 g_slist_free(cc_list);
1745 #define SET_ENTRY(entry, str) \
1748 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1751 #define SET_ADDRESS(type, str) \
1754 compose_entry_append(compose, str, type); \
1757 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1759 g_return_if_fail(msginfo != NULL);
1761 SET_ENTRY(subject_entry, msginfo->subject);
1762 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1763 SET_ADDRESS(COMPOSE_CC, compose->cc);
1764 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1765 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1767 compose_update_priority_menu_item(compose);
1769 compose_show_first_last_header(compose, TRUE);
1771 #if 0 /* NEW COMPOSE GUI */
1773 GtkItemFactory *ifactory;
1774 GtkWidget *menuitem;
1776 ifactory = gtk_item_factory_from_widget(compose->menubar);
1777 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1778 gtk_check_menu_item_set_active
1779 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1781 if (compose->replyto) {
1782 GtkItemFactory *ifactory;
1783 GtkWidget *menuitem;
1785 ifactory = gtk_item_factory_from_widget(compose->menubar);
1786 menuitem = gtk_item_factory_get_item
1787 (ifactory, "/View/Reply to");
1788 gtk_check_menu_item_set_active
1789 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1797 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1801 size_t buf_len = 128;
1803 if (strlen(sigfile) < 2)
1806 sigprg = popen(sigfile+1, "r");
1809 buf = g_malloc(buf_len);
1812 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1813 "Unable to insert signature (malloc failed)\n", -1);
1819 while (!feof(sigprg)) {
1820 bzero(buf, buf_len);
1821 fread(buf, buf_len-1, 1, sigprg);
1822 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1830 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1831 "Can't exec file: ", -1);
1832 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1837 static void compose_insert_sig(Compose *compose)
1841 if (compose->account && compose->account->sig_path)
1842 sigfile = g_strdup(compose->account->sig_path);
1844 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1845 DEFAULT_SIGNATURE, NULL);
1847 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1852 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1853 if (prefs_common.sig_sep) {
1854 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1855 prefs_common.sig_sep, -1);
1856 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1860 if (sigfile[0] == '|')
1861 compose_exec_sig(compose, sigfile);
1863 compose_insert_file(compose, sigfile);
1867 static void compose_insert_file(Compose *compose, const gchar *file)
1869 GtkSText *text = GTK_STEXT(compose->text);
1870 gchar buf[BUFFSIZE];
1874 g_return_if_fail(file != NULL);
1876 if ((fp = fopen(file, "rb")) == NULL) {
1877 FILE_OP_ERROR(file, "fopen");
1881 gtk_stext_freeze(text);
1883 while (fgets(buf, sizeof(buf), fp) != NULL) {
1884 /* strip <CR> if DOS/Windows file,
1885 replace <CR> with <LF> if Macintosh file. */
1888 if (len > 0 && buf[len - 1] != '\n') {
1890 if (buf[len] == '\r') buf[len] = '\n';
1892 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1895 gtk_stext_thaw(text);
1900 static void compose_attach_append(Compose *compose, const gchar *file,
1901 const gchar *filename,
1902 const gchar *content_type)
1905 gchar *text[N_ATTACH_COLS];
1910 if (!is_file_exist(file)) {
1911 g_warning(_("File %s doesn't exist\n"), file);
1914 if ((size = get_file_size(file)) < 0) {
1915 g_warning(_("Can't get file size of %s\n"), file);
1919 alertpanel_notice(_("File %s is empty."), file);
1922 if ((fp = fopen(file, "rb")) == NULL) {
1923 alertpanel_error(_("Can't read %s."), file);
1928 #if 0 /* NEW COMPOSE GUI */
1929 if (!compose->use_attach) {
1930 GtkItemFactory *ifactory;
1931 GtkWidget *menuitem;
1933 ifactory = gtk_item_factory_from_widget(compose->menubar);
1934 menuitem = gtk_item_factory_get_item(ifactory,
1935 "/View/Attachment");
1936 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1940 ainfo = g_new0(AttachInfo, 1);
1941 ainfo->file = g_strdup(file);
1944 ainfo->content_type = g_strdup(content_type);
1945 if (!strcasecmp(content_type, "message/rfc822")) {
1946 ainfo->encoding = ENC_7BIT;
1947 ainfo->name = g_strdup_printf
1949 g_basename(filename ? filename : file));
1951 if (!g_strncasecmp(content_type, "text", 4))
1953 procmime_get_encoding_for_file(file);
1955 ainfo->encoding = ENC_BASE64;
1956 ainfo->name = g_strdup
1957 (g_basename(filename ? filename : file));
1960 ainfo->content_type = procmime_get_mime_type(file);
1961 if (!ainfo->content_type) {
1962 ainfo->content_type =
1963 g_strdup("application/octet-stream");
1964 ainfo->encoding = ENC_BASE64;
1965 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
1966 ainfo->encoding = procmime_get_encoding_for_file(file);
1968 ainfo->encoding = ENC_BASE64;
1969 ainfo->name = g_strdup(g_basename(filename ? filename : file));
1973 text[COL_MIMETYPE] = ainfo->content_type;
1974 text[COL_SIZE] = to_human_readable(size);
1975 text[COL_NAME] = ainfo->name;
1977 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1978 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1981 #define IS_FIRST_PART_TEXT(info) \
1982 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
1983 info->mime_type == MIME_TEXT_ENRICHED) || \
1984 (info->mime_type == MIME_MULTIPART && info->content_type && \
1985 !strcasecmp(info->content_type, "multipart/alternative") && \
1986 (info->children && \
1987 (info->children->mime_type == MIME_TEXT || \
1988 info->children->mime_type == MIME_TEXT_HTML || \
1989 info->children->mime_type == MIME_TEXT_ENRICHED))))
1991 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
1998 mimeinfo = procmime_scan_message(msginfo);
1999 if (!mimeinfo) return;
2001 /* skip first text (presumably message body) */
2002 child = mimeinfo->children;
2003 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
2004 procmime_mimeinfo_free_all(mimeinfo);
2007 if (IS_FIRST_PART_TEXT(child))
2008 child = child->next;
2010 infile = procmsg_get_message_file_path(msginfo);
2012 while (child != NULL) {
2013 if (child->children || child->mime_type == MIME_MULTIPART) {
2014 child = procmime_mimeinfo_next(child);
2018 outfile = procmime_get_tmp_file_name(child);
2019 if (procmime_get_part(outfile, infile, child) < 0)
2020 g_warning(_("Can't get the part of multipart message."));
2022 compose_attach_append
2024 child->filename ? child->filename : child->name,
2025 child->content_type);
2027 child = child->next;
2031 procmime_mimeinfo_free_all(mimeinfo);
2034 #undef IS_FIRST_PART_TEXT
2036 #define GET_CHAR(pos, buf, len) \
2038 if (text->use_wchar) \
2039 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2041 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2046 #define INDENT_CHARS ">|#"
2047 #define SPACE_CHARS " \t"
2049 static void compose_wrap_line(Compose *compose)
2051 GtkSText *text = GTK_STEXT(compose->text);
2052 gint ch_len, last_ch_len;
2053 gchar cbuf[MB_LEN_MAX], last_ch;
2057 gint p_start, p_end;
2058 gint line_pos, cur_pos;
2059 gint line_len, cur_len;
2061 gtk_stext_freeze(text);
2063 text_len = gtk_stext_get_length(text);
2065 /* check to see if the point is on the paragraph mark (empty line). */
2066 cur_pos = gtk_stext_get_point(text);
2067 GET_CHAR(cur_pos, cbuf, ch_len);
2068 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2070 goto compose_end; /* on the paragraph mark */
2071 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2072 if (ch_len == 1 && *cbuf == '\n')
2073 goto compose_end; /* on the paragraph mark */
2076 /* find paragraph start. */
2077 line_end = quoted = 0;
2078 for (p_start = cur_pos; p_start >= 0; --p_start) {
2079 GET_CHAR(p_start, cbuf, ch_len);
2080 if (ch_len == 1 && *cbuf == '\n') {
2082 goto compose_end; /* quoted part */
2090 && strchr(prefs_common.quote_chars, *cbuf))
2092 else if (ch_len != 1 || !isspace(*cbuf))
2101 /* find paragraph end. */
2103 for (p_end = cur_pos; p_end < text_len; p_end++) {
2104 GET_CHAR(p_end, cbuf, ch_len);
2105 if (ch_len == 1 && *cbuf == '\n') {
2112 if (line_end && ch_len == 1 &&
2113 strchr(prefs_common.quote_chars, *cbuf))
2114 goto compose_end; /* quoted part */
2119 if (p_end >= text_len)
2122 if (p_start >= p_end)
2125 line_len = cur_len = 0;
2129 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2132 GET_CHAR(cur_pos, cbuf, ch_len);
2139 if (ch_len == 1 && isspace(*cbuf))
2142 if (ch_len == 1 && *cbuf == '\n') {
2144 if (last_ch_len == 1 && !isspace(last_ch)) {
2145 if (cur_pos + 1 < p_end) {
2146 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2147 if (ch_len == 1 && !isspace(*cbuf))
2151 gtk_stext_set_point(text, cur_pos + 1);
2152 gtk_stext_backward_delete(text, 1);
2154 gtk_stext_set_point(text, cur_pos);
2155 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2165 last_ch_len = ch_len;
2169 line_pos = cur_pos + 1;
2170 line_len = cur_len + ch_len;
2173 if (cur_len + ch_len > prefs_common.linewrap_len &&
2177 GET_CHAR(line_pos - 1, cbuf, ch_len);
2178 if (ch_len == 1 && isspace(*cbuf)) {
2179 gtk_stext_set_point(text, line_pos);
2180 gtk_stext_backward_delete(text, 1);
2189 gtk_stext_set_point(text, line_pos);
2190 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2194 cur_len = cur_len - line_len + ch_len;
2200 line_pos = cur_pos + 1;
2201 line_len = cur_len + ch_len;
2207 gtk_stext_thaw(text);
2212 /* Darko: used when I debug wrapping */
2213 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2218 printf("%d [", pos);
2219 for (i = pos; i < tlen; i++) {
2220 ch = GTK_STEXT_INDEX(text, i);
2221 if (breakoncr && ch == '\n')
2231 WAIT_FOR_INDENT_CHAR,
2232 WAIT_FOR_INDENT_CHAR_OR_SPACE
2235 /* return indent length, we allow:
2236 > followed by spaces/tabs
2237 | followed by spaces/tabs
2238 uppercase characters immediately followed by >,
2239 and the repeating sequences of the above */
2240 /* return indent length */
2241 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2244 guint i, ch_len, alnum_cnt = 0;
2245 IndentState state = WAIT_FOR_INDENT_CHAR;
2246 gchar cbuf[MB_LEN_MAX];
2250 for (i = start_pos; i < text_len; i++) {
2251 GET_CHAR(i, cbuf, ch_len);
2255 if (cbuf[0] == '\n')
2258 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2259 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2262 case WAIT_FOR_SPACE:
2263 if (is_space == FALSE)
2265 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2267 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2268 if (is_indent == FALSE && is_space == FALSE &&
2271 if (is_space == TRUE) {
2273 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2274 } else if (is_indent == TRUE) {
2276 state = WAIT_FOR_SPACE;
2279 state = WAIT_FOR_INDENT_CHAR;
2282 case WAIT_FOR_INDENT_CHAR:
2283 if (is_indent == FALSE && !isupper(cbuf[0]))
2285 if (is_indent == TRUE) {
2287 && !strchr(prefs_common.quote_chars, cbuf[0]))
2290 state = WAIT_FOR_SPACE;
2301 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2307 /* insert quotation string when line was wrapped */
2308 static guint ins_quote(GtkSText *text, guint indent_len,
2309 guint prev_line_pos, guint text_len,
2312 guint i, ins_len = 0;
2316 for (i = 0; i < indent_len; i++) {
2317 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2318 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2320 ins_len = indent_len;
2326 /* check if we should join the next line */
2327 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2330 guint indent_len, ch_len;
2331 gboolean do_join = FALSE;
2332 gchar cbuf[MB_LEN_MAX];
2334 indent_len = get_indent_length(text, start_pos, tlen);
2336 if ((indent_len > 0) && (indent_len == prev_ilen)) {
2337 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2338 if (ch_len > 0 && (cbuf[0] != '\n'))
2345 static void compose_wrap_line_all(Compose *compose)
2347 GtkSText *text = GTK_STEXT(compose->text);
2349 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2350 gint line_len = 0, cur_len = 0;
2352 gboolean is_new_line = TRUE, do_delete = FALSE;
2354 gboolean linewrap_quote = TRUE;
2355 guint linewrap_len = prefs_common.linewrap_len;
2356 gchar *qfmt = prefs_common.quotemark;
2357 gchar cbuf[MB_LEN_MAX];
2359 gtk_stext_freeze(text);
2361 /* make text buffer contiguous */
2362 /* gtk_stext_compact_buffer(text); */
2364 tlen = gtk_stext_get_length(text);
2366 for (; cur_pos < tlen; cur_pos++) {
2367 /* mark position of new line - needed for quotation wrap */
2370 i_len = get_indent_length(text, cur_pos, tlen);
2372 is_new_line = FALSE;
2375 printf("new line i_len=%d p_pos=", i_len);
2376 dump_text(text, p_pos, tlen, 1);
2380 GET_CHAR(cur_pos, cbuf, ch_len);
2382 /* fix line length for tabs */
2383 if (ch_len == 1 && *cbuf == '\t') {
2384 guint tab_width = text->default_tab_width;
2385 guint tab_offset = line_len % tab_width;
2388 printf("found tab at pos=%d line_len=%d ", cur_pos,
2392 line_len += tab_width - tab_offset - 1;
2396 printf("new_len=%d\n", line_len);
2400 /* we have encountered line break */
2401 if (ch_len == 1 && *cbuf == '\n') {
2403 gchar cb[MB_LEN_MAX];
2405 /* should we join the next line */
2406 if ((i_len != cur_len) && do_delete &&
2407 join_next_line(text, cur_pos + 1, tlen, i_len))
2413 printf("found CR at %d do_del is %d next line is ",
2414 cur_pos, do_delete);
2415 dump_text(text, cur_pos + 1, tlen, 1);
2418 /* skip delete if it is continuous URL */
2419 if (do_delete && (line_pos - p_pos <= i_len) &&
2420 gtkut_stext_is_uri_string(text, line_pos, tlen))
2424 printf("l_len=%d wrap_len=%d do_del=%d\n",
2425 line_len, linewrap_len, do_delete);
2427 /* should we delete to perform smart wrapping */
2428 if (line_len < linewrap_len && do_delete) {
2429 /* get rid of newline */
2430 gtk_stext_set_point(text, cur_pos);
2431 gtk_stext_forward_delete(text, 1);
2434 /* if text starts with quote fmt or with
2435 indent string, delete them */
2438 ilen = gtkut_stext_str_compare_n
2439 (text, cur_pos, p_pos, i_len,
2442 gtk_stext_forward_delete
2448 GET_CHAR(cur_pos, cb, clen);
2450 /* insert space if it's alphanumeric */
2451 if ((cur_pos != line_pos) &&
2452 ((clen > 1) || isalnum(cb[0]))) {
2453 gtk_stext_insert(text, NULL, NULL,
2455 /* gtk_stext_compact_buffer(text); */
2459 /* and start over with current line */
2460 cur_pos = p_pos - 1;
2462 line_len = cur_len = 0;
2466 printf("after delete l_pos=");
2467 dump_text(text, line_pos, tlen, 1);
2472 /* mark new line beginning */
2473 line_pos = cur_pos + 1;
2474 line_len = cur_len = 0;
2485 /* possible line break */
2486 if (ch_len == 1 && isspace(*cbuf)) {
2487 line_pos = cur_pos + 1;
2488 line_len = cur_len + ch_len;
2491 /* are we over wrapping length set in preferences ? */
2492 if (cur_len + ch_len > linewrap_len) {
2496 printf("should wrap cur_pos=%d ", cur_pos);
2497 dump_text(text, p_pos, tlen, 1);
2498 dump_text(text, line_pos, tlen, 1);
2500 /* force wrapping if it is one long word but not URL */
2501 if (line_pos - p_pos <= i_len)
2502 if (!gtkut_stext_is_uri_string
2503 (text, line_pos, tlen))
2504 line_pos = cur_pos - 1;
2506 printf("new line_pos=%d\n", line_pos);
2509 GET_CHAR(line_pos - 1, cbuf, clen);
2511 /* if next character is space delete it */
2512 if (clen == 1 && isspace(*cbuf)) {
2513 if (p_pos + i_len != line_pos ||
2514 !gtkut_stext_is_uri_string
2515 (text, line_pos, tlen)) {
2516 gtk_stext_set_point(text, line_pos);
2517 gtk_stext_backward_delete(text, 1);
2526 /* if it is URL at beginning of line don't wrap */
2527 if (p_pos + i_len == line_pos &&
2528 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2530 printf("found URL at ");
2531 dump_text(text, line_pos, tlen, 1);
2537 gtk_stext_set_point(text, line_pos);
2538 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2539 /* gtk_stext_compact_buffer(text); */
2542 /* for loop will increase it */
2543 cur_pos = line_pos - 1;
2544 /* start over with current line */
2553 printf("after CR insert ");
2554 dump_text(text, line_pos, tlen, 1);
2555 dump_text(text, cur_pos, tlen, 1);
2558 /* should we insert quotation ? */
2559 if (linewrap_quote && i_len) {
2560 /* only if line is not already quoted */
2561 if (!gtkut_stext_str_compare
2562 (text, line_pos, tlen, qfmt)) {
2565 if (line_pos - p_pos > i_len) {
2567 (text, i_len, p_pos,
2570 /* gtk_stext_compact_buffer(text); */
2574 printf("after quote insert ");
2575 dump_text(text, line_pos, tlen, 1);
2583 line_pos = cur_pos + 1;
2584 line_len = cur_len + ch_len;
2586 /* advance to next character in buffer */
2590 gtk_stext_thaw(text);
2595 static void compose_set_title(Compose *compose)
2600 edited = compose->modified ? _(" [Edited]") : "";
2601 if (compose->account && compose->account->address)
2602 str = g_strdup_printf(_("%s - Compose message%s"),
2603 compose->account->address, edited);
2605 str = g_strdup_printf(_("Compose message%s"), edited);
2606 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2611 * compose_current_mail_account:
2613 * Find a current mail account (the currently selected account, or the
2614 * default account, if a news account is currently selected). If a
2615 * mail account cannot be found, display an error message.
2617 * Return value: Mail account, or NULL if not found.
2619 static PrefsAccount *
2620 compose_current_mail_account(void)
2624 if (cur_account && cur_account->protocol != A_NNTP)
2627 ac = account_get_default();
2628 if (!ac || ac->protocol == A_NNTP) {
2629 alertpanel_error(_("Account for sending mail is not specified.\n"
2630 "Please select a mail account before sending."));
2637 gboolean compose_check_for_valid_recipient(Compose *compose) {
2638 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2639 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2640 gboolean recipient_found = FALSE;
2644 /* free to and newsgroup list */
2645 slist_free_strings(compose->to_list);
2646 g_slist_free(compose->to_list);
2647 compose->to_list = NULL;
2649 slist_free_strings(compose->newsgroup_list);
2650 g_slist_free(compose->newsgroup_list);
2651 compose->newsgroup_list = NULL;
2653 /* search header entries for to and newsgroup entries */
2654 for(list = compose->header_list; list; list = list->next) {
2657 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
2658 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2660 if(entry[0] != '\0') {
2661 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2662 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2663 compose->to_list = address_list_append(compose->to_list, entry);
2664 recipient_found = TRUE;
2667 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2668 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2669 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2670 recipient_found = TRUE;
2677 return recipient_found;
2680 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
2684 if (compose_check_for_valid_recipient(compose) == FALSE) {
2685 alertpanel_error(_("Recipient is not specified."));
2689 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2690 if (*str == '\0' && check_subject == TRUE) {
2693 aval = alertpanel(_("Send"),
2694 _("Subject is empty. Send it anyway?"),
2695 _("Yes"), _("No"), NULL);
2696 if (aval != G_ALERTDEFAULT)
2703 gint compose_send(Compose *compose)
2709 if (compose_check_entries(compose, TRUE) == FALSE)
2712 val = compose_queue(compose, &msgnum, &folder);
2714 alertpanel_error(_("Could not queue message for sending"));
2718 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2720 folder_item_remove_msg(folder, msgnum);
2721 folderview_update_item(folder, TRUE);
2726 #if 0 /* compose restructure */
2727 gint compose_send(Compose *compose)
2729 gchar tmp[MAXPATHLEN + 1];
2731 static gboolean lock = FALSE;
2735 g_return_val_if_fail(compose->account != NULL, -1);
2736 g_return_val_if_fail(compose->orig_account != NULL, -1);
2740 if (compose_check_entries(compose, TRUE) == FALSE) {
2745 /* write to temporary file */
2746 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2747 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2749 if (prefs_common.linewrap_at_send)
2750 compose_wrap_line_all(compose);
2752 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2757 if (!compose->to_list && !compose->newsgroup_list) {
2758 g_warning(_("can't get recipient list."));
2764 if (compose->to_list) {
2767 #if 0 /* NEW COMPOSE GUI */
2768 if (compose->account->protocol != A_NNTP)
2769 ac = compose->account;
2770 else if (compose->orig_account->protocol != A_NNTP)
2771 ac = compose->orig_account;
2772 else if (cur_account && cur_account->protocol != A_NNTP)
2775 ac = compose_current_mail_account();
2783 ac = compose->account;
2785 ok = send_message(tmp, ac, compose->to_list);
2786 statusbar_pop_all();
2789 if (ok == 0 && compose->newsgroup_list) {
2792 if (compose->account->protocol == A_NNTP)
2793 folder = FOLDER(compose->account->folder);
2795 folder = FOLDER(compose->orig_account->folder);
2797 ok = news_post(folder, tmp);
2799 alertpanel_error(_("Error occurred while posting the message to %s ."),
2800 compose->account->nntp_server);
2807 /* queue message if failed to send */
2809 if (prefs_common.queue_msg) {
2814 _("Error occurred while sending the message.\n"
2815 "Put this message into queue folder?"),
2816 _("OK"), _("Cancel"), NULL);
2817 if (G_ALERTDEFAULT == val) {
2818 ok = compose_queue(compose, tmp);
2820 alertpanel_error(_("Can't queue the message."));
2823 alertpanel_error(_("Error occurred while sending the message."));
2825 if (compose->mode == COMPOSE_REEDIT) {
2826 compose_remove_reedit_target(compose);
2827 if (compose->targetinfo)
2828 folderview_update_item
2829 (compose->targetinfo->folder, TRUE);
2831 /* save message to outbox */
2832 if (prefs_common.savemsg) {
2835 outbox = account_get_special_folder
2836 (compose->account, F_OUTBOX);
2837 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
2839 (_("Can't save the message to Sent."));
2841 folderview_update_item(outbox, TRUE);
2851 static gboolean compose_use_attach(Compose *compose) {
2852 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2855 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
2858 gchar buf[BUFFSIZE];
2860 gboolean first_address;
2862 ComposeHeaderEntry *headerentry;
2863 gchar *headerentryname;
2867 debug_print(_("Writing redirect header\n"));
2869 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
2870 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
2872 first_address = TRUE;
2873 for(list = compose->header_list; list; list = list->next) {
2874 headerentry = ((ComposeHeaderEntry *)list->data);
2875 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2877 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2878 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2879 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2880 Xstrdup_a(str, str, return -1);
2882 if(str[0] != '\0') {
2883 compose_convert_header
2884 (buf, sizeof(buf), str,
2885 strlen("Resent-To") + 2);
2887 fprintf(fp, "Resent-To: ");
2888 first_address = FALSE;
2892 fprintf(fp, "%s", buf);
2896 /* if(!first_address) { */
2903 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
2905 gchar buf[BUFFSIZE];
2907 /* struct utsname utsbuf; */
2909 g_return_val_if_fail(fp != NULL, -1);
2910 g_return_val_if_fail(compose->account != NULL, -1);
2911 g_return_val_if_fail(compose->account->address != NULL, -1);
2914 get_rfc822_date(buf, sizeof(buf));
2915 fprintf(fp, "Resent-Date: %s\n", buf);
2918 if (compose->account->name && *compose->account->name) {
2919 compose_convert_header
2920 (buf, sizeof(buf), compose->account->name,
2922 fprintf(fp, "Resent-From: %s <%s>\n",
2923 buf, compose->account->address);
2925 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2928 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2930 Xstrdup_a(str, str, return -1);
2933 compose_convert_header(buf, sizeof(buf), str,
2934 strlen("Subject: "));
2935 fprintf(fp, "Subject: %s\n", buf);
2939 /* Resent-Message-ID */
2940 if (compose->account->gen_msgid) {
2941 compose_generate_msgid(compose, buf, sizeof(buf));
2942 fprintf(fp, "Resent-Message-Id: <%s>\n", buf);
2943 compose->msgid = g_strdup(buf);
2946 compose_redirect_write_headers_from_headerlist(compose, fp);
2948 /* separator between header and body */
2954 static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
2959 gchar buf[BUFFSIZE];
2961 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
2962 FILE_OP_ERROR(file, "fopen");
2966 if ((fdest = fopen(file, "wb")) == NULL) {
2967 FILE_OP_ERROR(file, "fopen");
2972 /* chmod for security */
2973 if (change_file_mode_rw(fdest, file) < 0) {
2974 FILE_OP_ERROR(file, "chmod");
2975 g_warning(_("can't change file mode\n"));
2978 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2979 /* should filter returnpath, delivered-to */
2980 if (g_strncasecmp(buf, "Return-Path:",
2981 strlen("Return-Path:")) == 0 ||
2982 g_strncasecmp(buf, "Delivered-To:",
2983 strlen("Delivered-To:")) == 0 ||
2984 g_strncasecmp(buf, "Received:",
2985 strlen("Received:")) == 0 ||
2986 g_strncasecmp(buf, "Subject:",
2987 strlen("Subject:")) == 0 ||
2988 g_strncasecmp(buf, "X-UIDL:",
2989 strlen("X-UIDL:")) == 0)
2992 if (fputs(buf, fdest) == -1)
2995 if (!prefs_common.redirect_keep_from) {
2996 if (g_strncasecmp(buf, "From:",
2997 strlen("From:")) == 0) {
2998 fputs(" (by way of ", fdest);
2999 if (compose->account->name
3000 && *compose->account->name) {
3001 compose_convert_header
3003 compose->account->name,
3005 fprintf(fdest, "%s <%s>",
3007 compose->account->address);
3009 fprintf(fdest, "%s",
3010 compose->account->address);
3015 if (fputs("\n", fdest) == -1)
3019 compose_redirect_write_headers(compose, fdest);
3021 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3022 if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
3023 FILE_OP_ERROR(file, "fwrite");
3029 if (fclose(fdest) == EOF) {
3030 FILE_OP_ERROR(file, "fclose");
3046 /* interfaces to rfc2015 to keep out the prefs stuff there.
3047 * returns 0 on success and -1 on error. */
3048 static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
3050 const gchar *key_id = NULL;
3053 switch (compose->account->sign_key) {
3054 case SIGN_KEY_DEFAULT:
3057 case SIGN_KEY_BY_FROM:
3058 key_id = compose->account->address;
3060 case SIGN_KEY_CUSTOM:
3061 key_id = compose->account->sign_key_id;
3067 key_list = rfc2015_create_signers_list(key_id);
3070 alertpanel_error(_("Could not find any key associated with "
3071 "currently selected key id `%s'."), key_id);
3075 *pkey_list = key_list;
3078 #endif /* USE_GPGME */
3080 static gint compose_write_to_file(Compose *compose, const gchar *file,
3087 const gchar *out_codeset;
3088 EncodingType encoding;
3090 if ((fp = fopen(file, "wb")) == NULL) {
3091 FILE_OP_ERROR(file, "fopen");
3095 /* chmod for security */
3096 if (change_file_mode_rw(fp, file) < 0) {
3097 FILE_OP_ERROR(file, "chmod");
3098 g_warning(_("can't change file mode\n"));
3101 /* get all composed text */
3102 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3103 len = strlen(chars);
3104 if (is_ascii_str(chars)) {
3107 out_codeset = CS_US_ASCII;
3108 encoding = ENC_7BIT;
3110 const gchar *src_codeset;
3112 out_codeset = conv_get_outgoing_charset_str();
3113 if (!strcasecmp(out_codeset, CS_US_ASCII))
3114 out_codeset = CS_ISO_8859_1;
3115 encoding = procmime_get_encoding_for_charset(out_codeset);
3117 src_codeset = conv_get_current_charset_str();
3118 /* if current encoding is US-ASCII, set it the same as
3119 outgoing one to prevent code conversion failure */
3120 if (!strcasecmp(src_codeset, CS_US_ASCII))
3121 src_codeset = out_codeset;
3123 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3124 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3126 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3132 _("Can't convert the character encoding of the message.\n"
3133 "Send it anyway?"), _("Yes"), _("+No"), NULL);
3134 if (aval != G_ALERTDEFAULT) {
3148 if (compose_write_headers
3149 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3150 g_warning(_("can't write headers\n"));
3157 if (compose_use_attach(compose)) {
3159 /* This prolog message is ignored by mime software and
3160 * because it would make our signing/encryption task
3161 * tougher, we don't emit it in that case */
3162 if (!compose->use_signing && !compose->use_encryption)
3164 fputs("This is a multi-part message in MIME format.\n", fp);
3166 fprintf(fp, "\n--%s\n", compose->boundary);
3167 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3169 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3170 procmime_get_encoding_str(encoding));
3176 if (encoding == ENC_BASE64) {
3177 gchar outbuf[B64_BUFFSIZE];
3180 for (i = 0; i < len; i += B64_LINE_SIZE) {
3181 l = MIN(B64_LINE_SIZE, len - i);
3182 base64_encode(outbuf, buf + i, l);
3186 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3187 FILE_OP_ERROR(file, "fwrite");
3195 if (compose_use_attach(compose))
3196 compose_write_attach(compose, fp);
3198 if (fclose(fp) == EOF) {
3199 FILE_OP_ERROR(file, "fclose");
3208 if (compose->use_signing || compose->use_encryption) {
3209 if (canonicalize_file_replace(file) < 0) {
3215 if (compose->use_signing) {
3218 if (compose_create_signers_list(compose, &key_list) < 0 ||
3219 rfc2015_sign(file, key_list) < 0) {
3224 if (compose->use_encryption) {
3225 if (rfc2015_encrypt(file, compose->to_list,
3226 compose->account->ascii_armored) < 0) {
3231 #endif /* USE_GPGME */
3236 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3242 if ((fp = fopen(file, "wb")) == NULL) {
3243 FILE_OP_ERROR(file, "fopen");
3247 /* chmod for security */
3248 if (change_file_mode_rw(fp, file) < 0) {
3249 FILE_OP_ERROR(file, "chmod");
3250 g_warning(_("can't change file mode\n"));
3253 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3256 len = strlen(chars);
3257 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3258 FILE_OP_ERROR(file, "fwrite");
3267 if (fclose(fp) == EOF) {
3268 FILE_OP_ERROR(file, "fclose");
3275 static gint compose_remove_reedit_target(Compose *compose)
3278 MsgInfo *msginfo = compose->targetinfo;
3280 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3281 if (!msginfo) return -1;
3283 item = msginfo->folder;
3284 g_return_val_if_fail(item != NULL, -1);
3286 if (procmsg_msg_exist(msginfo) &&
3287 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3288 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3289 g_warning(_("can't remove the old message\n"));
3297 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3299 return compose_queue_sub (compose, msgnum, item, FALSE);
3301 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3307 gchar buf[BUFFSIZE];
3309 static gboolean lock = FALSE;
3310 PrefsAccount *mailac = NULL, *newsac = NULL;
3312 debug_print(_("queueing message...\n"));
3313 g_return_val_if_fail(compose->account != NULL, -1);
3314 g_return_val_if_fail(compose->orig_account != NULL, -1);
3318 if (compose_check_entries(compose, check_subject) == FALSE) {
3323 if (!compose->to_list && !compose->newsgroup_list) {
3324 g_warning(_("can't get recipient list."));
3329 if(compose->to_list) {
3330 if (compose->account->protocol != A_NNTP)
3331 mailac = compose->account;
3332 else if (compose->orig_account->protocol != A_NNTP)
3333 mailac = compose->orig_account;
3334 else if (cur_account && cur_account->protocol != A_NNTP)
3335 mailac = cur_account;
3336 else if (!(mailac = compose_current_mail_account())) {
3338 alertpanel_error(_("No account for sending mails available!"));
3343 if(compose->newsgroup_list) {
3344 if (compose->account->protocol == A_NNTP)
3345 newsac = compose->account;
3346 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3348 alertpanel_error(_("No account for posting news available!"));
3353 if (prefs_common.linewrap_at_send)
3354 compose_wrap_line_all(compose);
3356 /* write to temporary file */
3357 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3358 G_DIR_SEPARATOR, (gint)compose);
3360 if (compose->redirect_filename != NULL) {
3361 if (compose_redirect_write_to_file(compose, tmp2) < 0) {
3368 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3375 /* add queue header */
3376 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3377 G_DIR_SEPARATOR, (gint)compose);
3378 if ((fp = fopen(tmp, "wb")) == NULL) {
3379 FILE_OP_ERROR(tmp, "fopen");
3383 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3384 FILE_OP_ERROR(tmp2, "fopen");
3392 if (change_file_mode_rw(fp, tmp) < 0) {
3393 FILE_OP_ERROR(tmp, "chmod");
3394 g_warning(_("can't change file mode\n"));
3397 /* queueing variables */
3398 fprintf(fp, "AF:\n");
3399 fprintf(fp, "NF:0\n");
3400 fprintf(fp, "PS:10\n");
3401 fprintf(fp, "SRH:1\n");
3402 fprintf(fp, "SFN:\n");
3403 fprintf(fp, "DSR:\n");
3405 fprintf(fp, "MID:<%s>\n", compose->msgid);
3407 fprintf(fp, "MID:\n");
3408 fprintf(fp, "CFG:\n");
3409 fprintf(fp, "PT:0\n");
3410 fprintf(fp, "S:%s\n", compose->account->address);
3411 fprintf(fp, "RQ:\n");
3413 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3415 fprintf(fp, "SSV:\n");
3417 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3419 fprintf(fp, "NSV:\n");
3420 fprintf(fp, "SSH:\n");
3421 /* write recepient list */
3423 if(compose->to_list) {
3424 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3425 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3426 fprintf(fp, ",<%s>", (gchar *)cur->data);
3429 /* write newsgroup list */
3431 if(compose->newsgroup_list) {
3432 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3433 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3434 fprintf(fp, ",%s", (gchar *)cur->data);
3437 /* Sylpheed account IDs */
3439 fprintf(fp, "MAID:%d\n", mailac->account_id);
3442 fprintf(fp, "NAID:%d\n", newsac->account_id);
3444 /* Save copy folder */
3445 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3446 gchar *savefolderid;
3448 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3449 fprintf(fp, "SCF:%s\n", savefolderid);
3450 g_free(savefolderid);
3452 /* Message-ID of message replying to */
3453 if((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
3456 folderid = folder_item_get_identifier(compose->replyinfo->folder);
3457 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
3462 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3463 if (fputs(buf, fp) == EOF) {
3464 FILE_OP_ERROR(tmp, "fputs");
3475 if (fclose(fp) == EOF) {
3476 FILE_OP_ERROR(tmp, "fclose");
3484 queue = account_get_special_folder(compose->account, F_QUEUE);
3486 g_warning(_("can't find queue folder\n"));
3491 folder_item_scan(queue);
3492 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3493 g_warning(_("can't queue the message\n"));
3503 if (compose->mode == COMPOSE_REEDIT) {
3504 compose_remove_reedit_target(compose);
3505 if (compose->targetinfo &&
3506 compose->targetinfo->folder != queue)
3507 folderview_update_item
3508 (compose->targetinfo->folder, TRUE);
3511 folderview_update_item(queue, TRUE);
3513 if((msgnum != NULL) && (item != NULL)) {
3521 static void compose_write_attach(Compose *compose, FILE *fp)
3524 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3527 gchar filename[BUFFSIZE];
3530 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3532 gchar buf[BUFFSIZE];
3533 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3535 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
3536 g_warning(_("Can't open file %s\n"), ainfo->file);
3540 fprintf(fp, "\n--%s\n", compose->boundary);
3542 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3543 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3544 fprintf(fp, "Content-Disposition: inline\n");
3546 conv_encode_header(filename, sizeof(filename),
3548 fprintf(fp, "Content-Type: %s;\n"
3550 ainfo->content_type, filename);
3551 fprintf(fp, "Content-Disposition: attachment;\n"
3552 " filename=\"%s\"\n", filename);
3555 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3556 procmime_get_encoding_str(ainfo->encoding));
3558 switch (ainfo->encoding) {
3562 /* if (ainfo->encoding == ENC_7BIT) { */
3564 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3572 while ((len = fread(inbuf, sizeof(gchar),
3573 B64_LINE_SIZE, attach_fp))
3575 base64_encode(outbuf, inbuf, B64_LINE_SIZE);
3579 if (len > 0 && feof(attach_fp)) {
3580 base64_encode(outbuf, inbuf, len);
3590 fprintf(fp, "\n--%s--\n", compose->boundary);
3593 #define QUOTE_IF_REQUIRED(out, str) \
3595 if (*str != '"' && strchr(str, ',')) { \
3599 len = strlen(str) + 3; \
3600 Xalloca(__tmp, len, return -1); \
3601 g_snprintf(__tmp, len, "\"%s\"", str); \
3604 Xstrdup_a(out, str, return -1); \
3608 #define PUT_RECIPIENT_HEADER(header, str) \
3610 if (*str != '\0') { \
3611 Xstrdup_a(str, str, return -1); \
3613 if (*str != '\0') { \
3614 compose->to_list = address_list_append \
3615 (compose->to_list, str); \
3616 compose_convert_header \
3617 (buf, sizeof(buf), str, strlen(header) + 2); \
3618 fprintf(fp, "%s: %s\n", header, buf); \
3623 #define IS_IN_CUSTOM_HEADER(header) \
3624 (compose->account->add_customhdr && \
3625 custom_header_find(compose->account->customhdr_list, header) != NULL)
3627 static gint compose_write_headers_from_headerlist(Compose *compose,
3631 gchar buf[BUFFSIZE];
3632 gchar *str, *header_w_colon, *trans_hdr;
3633 gboolean first_address;
3635 ComposeHeaderEntry *headerentry;
3636 gchar * headerentryname;
3638 if (IS_IN_CUSTOM_HEADER(header)) {
3642 debug_print(_("Writing %s-header\n"), header);
3644 header_w_colon = g_strconcat(header, ":", NULL);
3645 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3647 first_address = TRUE;
3648 for(list = compose->header_list; list; list = list->next) {
3649 headerentry = ((ComposeHeaderEntry *)list->data);
3650 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3652 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3653 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3654 Xstrdup_a(str, str, return -1);
3656 if(str[0] != '\0') {
3657 compose_convert_header
3658 (buf, sizeof(buf), str,
3659 strlen(header) + 2);
3661 fprintf(fp, "%s: ", header);
3662 first_address = FALSE;
3666 fprintf(fp, "%s", buf);
3670 if(!first_address) {
3674 g_free(header_w_colon);
3679 static gint compose_write_headers(Compose *compose, FILE *fp,
3680 const gchar *charset, EncodingType encoding,
3683 gchar buf[BUFFSIZE];
3686 /* struct utsname utsbuf; */
3688 g_return_val_if_fail(fp != NULL, -1);
3689 g_return_val_if_fail(charset != NULL, -1);
3690 g_return_val_if_fail(compose->account != NULL, -1);
3691 g_return_val_if_fail(compose->account->address != NULL, -1);
3694 if (compose->account->add_date) {
3695 get_rfc822_date(buf, sizeof(buf));
3696 fprintf(fp, "Date: %s\n", buf);
3700 if (!IS_IN_CUSTOM_HEADER("From")) {
3701 if (compose->account->name && *compose->account->name) {
3702 compose_convert_header
3703 (buf, sizeof(buf), compose->account->name,
3705 QUOTE_IF_REQUIRED(name, buf);
3706 fprintf(fp, "From: %s <%s>\n",
3707 name, compose->account->address);
3709 fprintf(fp, "From: %s\n", compose->account->address);
3713 compose_write_headers_from_headerlist(compose, fp, "To");
3714 #if 0 /* NEW COMPOSE GUI */
3715 if (compose->use_to) {
3716 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3717 PUT_RECIPIENT_HEADER("To", str);
3722 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3723 #if 0 /* NEW COMPOSE GUI */
3724 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3726 Xstrdup_a(str, str, return -1);
3730 compose->newsgroup_list =
3731 newsgroup_list_append(compose->newsgroup_list,
3733 compose_convert_header(buf, sizeof(buf), str,
3734 strlen("Newsgroups: "));
3735 fprintf(fp, "Newsgroups: %s\n", buf);
3740 compose_write_headers_from_headerlist(compose, fp, "Cc");
3741 #if 0 /* NEW COMPOSE GUI */
3742 if (compose->use_cc) {
3743 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3744 PUT_RECIPIENT_HEADER("Cc", str);
3748 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3749 #if 0 /* NEW COMPOSE GUI */
3750 if (compose->use_bcc) {
3751 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3752 PUT_RECIPIENT_HEADER("Bcc", str);
3757 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3758 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3759 Xstrdup_a(str, str, return -1);
3762 compose_convert_header(buf, sizeof(buf), str,
3763 strlen("Subject: "));
3764 fprintf(fp, "Subject: %s\n", buf);
3769 if (compose->account->gen_msgid) {
3770 compose_generate_msgid(compose, buf, sizeof(buf));
3771 fprintf(fp, "Message-Id: <%s>\n", buf);
3772 compose->msgid = g_strdup(buf);
3776 if (compose->inreplyto && compose->to_list)
3777 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3780 if (compose->references)
3781 fprintf(fp, "References: %s\n", compose->references);
3784 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3785 #if 0 /* NEW COMPOSE GUI */
3786 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3787 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3789 Xstrdup_a(str, str, return -1);
3793 compose_convert_header(buf, sizeof(buf), str,
3794 strlen("Followup-To: "));
3795 fprintf(fp, "Followup-To: %s\n", buf);
3801 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3802 #if 0 /* NEW COMPOSE GUI */
3803 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3804 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3806 Xstrdup_a(str, str, return -1);
3809 compose_convert_header(buf, sizeof(buf), str,
3810 strlen("Reply-To: "));
3811 fprintf(fp, "Reply-To: %s\n", buf);
3817 if (compose->account->organization &&
3818 !IS_IN_CUSTOM_HEADER("Organization")) {
3819 compose_convert_header(buf, sizeof(buf),
3820 compose->account->organization,
3821 strlen("Organization: "));
3822 fprintf(fp, "Organization: %s\n", buf);
3825 /* Program version and system info */
3826 /* uname(&utsbuf); */
3827 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3828 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3830 gtk_major_version, gtk_minor_version, gtk_micro_version,
3832 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3834 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3835 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3837 gtk_major_version, gtk_minor_version, gtk_micro_version,
3839 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3842 /* custom headers */
3843 if (compose->account->add_customhdr) {
3846 for (cur = compose->account->customhdr_list; cur != NULL;
3848 CustomHeader *chdr = (CustomHeader *)cur->data;
3850 if (strcasecmp(chdr->name, "Date") != 0 &&
3851 strcasecmp(chdr->name, "From") != 0 &&
3852 strcasecmp(chdr->name, "To") != 0 &&
3853 /* strcasecmp(chdr->name, "Sender") != 0 && */
3854 strcasecmp(chdr->name, "Message-Id") != 0 &&
3855 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3856 strcasecmp(chdr->name, "References") != 0 &&
3857 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3858 strcasecmp(chdr->name, "Content-Type") != 0 &&
3859 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3861 compose_convert_header
3863 chdr->value ? chdr->value : "",
3864 strlen(chdr->name) + 2);
3865 fprintf(fp, "%s: %s\n", chdr->name, buf);
3871 fprintf(fp, "Mime-Version: 1.0\n");
3872 if (compose_use_attach(compose)) {
3873 get_rfc822_date(buf, sizeof(buf));
3874 subst_char(buf, ' ', '_');
3875 subst_char(buf, ',', '_');
3876 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3877 buf, (guint)compose);
3879 "Content-Type: multipart/mixed;\n"
3880 " boundary=\"%s\"\n", compose->boundary);
3882 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3883 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3884 procmime_get_encoding_str(encoding));
3888 switch (compose->priority) {
3889 case PRIORITY_HIGHEST: fprintf(fp, "Importance: high\n"
3890 "X-Priority: 1 (Highest)\n");
3892 case PRIORITY_HIGH: fprintf(fp, "Importance: high\n"
3893 "X-Priority: 2 (High)\n");
3895 case PRIORITY_NORMAL: break;
3896 case PRIORITY_LOW: fprintf(fp, "Importance: low\n"
3897 "X-Priority: 4 (Low)\n");
3899 case PRIORITY_LOWEST: fprintf(fp, "Importance: low\n"
3900 "X-Priority: 5 (Lowest)\n");
3902 default: debug_print(_("compose: priority unknown : %d\n"),
3906 /* Request Return Receipt */
3907 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3908 if (compose->return_receipt) {
3909 if (compose->account->name
3910 && *compose->account->name) {
3911 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3912 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3914 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3918 /* separator between header and body */
3924 #undef IS_IN_CUSTOM_HEADER
3926 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3929 g_return_if_fail(src != NULL);
3930 g_return_if_fail(dest != NULL);
3932 if (len < 1) return;
3936 if (is_ascii_str(src)) {
3937 strncpy2(dest, src, len);
3938 dest[len - 1] = '\0';
3941 conv_encode_header(dest, len, src, header_len);
3944 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3953 if (compose->account && compose->account->address &&
3954 *compose->account->address) {
3955 if (strchr(compose->account->address, '@'))
3956 addr = g_strdup(compose->account->address);
3958 addr = g_strconcat(compose->account->address, "@",
3959 get_domain_name(), NULL);
3961 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3964 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3965 lt->tm_year + 1900, lt->tm_mon + 1,
3966 lt->tm_mday, lt->tm_hour,
3967 lt->tm_min, lt->tm_sec,
3968 (guint)random(), addr);
3970 debug_print(_("generated Message-ID: %s\n"), buf);
3975 static void compose_create_header_entry(Compose *compose)
3977 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3981 GList *combo_list = NULL;
3982 gchar **string, *header;
3983 ComposeHeaderEntry *headerentry;
3985 headerentry = g_new0(ComposeHeaderEntry, 1);
3988 combo = gtk_combo_new();
3990 while(*string != NULL) {
3991 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3994 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3995 g_list_free(combo_list);
3996 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3997 gtk_widget_show(combo);
3998 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3999 if(compose->header_last) {
4000 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4002 switch(compose->account->protocol) {
4004 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4007 header = prefs_common.trans_hdr ? _("To:") : "To:";
4011 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4014 entry = gtk_entry_new();
4015 gtk_widget_show(entry);
4016 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);
4018 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4019 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4020 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4022 address_completion_register_entry(GTK_ENTRY(entry));
4024 headerentry->compose = compose;
4025 headerentry->combo = combo;
4026 headerentry->entry = entry;
4027 headerentry->headernum = compose->header_nextrow;
4029 compose->header_nextrow++;
4030 compose->header_last = headerentry;
4033 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4035 ComposeHeaderEntry *last_header;
4037 last_header = compose->header_last;
4039 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4040 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4043 static GtkWidget *compose_create_header(Compose *compose)
4047 GtkWidget *from_optmenu_hbox;
4048 #if 0 /* NEW COMPOSE GUI */
4049 GtkWidget *to_entry;
4051 GtkWidget *newsgroups_entry;
4052 GtkWidget *newsgroups_hbox;
4054 GtkWidget *header_scrolledwin;
4055 GtkWidget *header_table;
4056 #if 0 /* NEW COMPOSE GUI */
4057 GtkWidget *cc_entry;
4059 GtkWidget *bcc_entry;
4060 GtkWidget *bcc_hbox;
4061 GtkWidget *reply_entry;
4062 GtkWidget *reply_hbox;
4063 GtkWidget *followup_entry;
4064 GtkWidget *followup_hbox;
4069 /* header labels and entries */
4070 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4071 gtk_widget_show(header_scrolledwin);
4072 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4074 header_table = gtk_table_new(2, 2, FALSE);
4075 gtk_widget_show(header_table);
4076 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4077 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4078 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4081 /* option menu for selecting accounts */
4082 hbox = gtk_hbox_new(FALSE, 0);
4083 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4084 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4085 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4087 from_optmenu_hbox = compose_account_option_menu_create(compose);
4088 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4089 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4090 #if 0 /* NEW COMPOSE GUI */
4091 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4095 compose->header_table = header_table;
4096 compose->header_list = NULL;
4097 compose->header_nextrow = count;
4099 compose_create_header_entry(compose);
4101 #if 0 /* NEW COMPOSE GUI */
4102 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4104 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4105 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4106 &count, "Newsgroups:", FALSE);
4107 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4109 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4111 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4113 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4114 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4116 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4117 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4119 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4120 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4121 "Followup-To:", FALSE);
4122 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4124 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4126 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4127 GTK_SIGNAL_FUNC(to_activated), compose);
4128 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4129 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4130 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4131 GTK_SIGNAL_FUNC(subject_activated), compose);
4132 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4133 GTK_SIGNAL_FUNC(cc_activated), compose);
4134 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4135 GTK_SIGNAL_FUNC(bcc_activated), compose);
4136 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4137 GTK_SIGNAL_FUNC(replyto_activated), compose);
4138 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4139 GTK_SIGNAL_FUNC(followupto_activated), compose);
4141 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4142 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4143 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4144 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4145 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4146 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4147 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4148 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4149 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4150 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4151 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4152 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4153 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4154 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4157 compose->table = NULL;
4158 #if 0 /* NEW COMPOSE GUI */
4159 compose->table = table;
4160 compose->to_hbox = to_hbox;
4161 compose->to_entry = to_entry;
4162 compose->newsgroups_hbox = newsgroups_hbox;
4163 compose->newsgroups_entry = newsgroups_entry;
4165 #if 0 /* NEW COMPOSE GUI */
4166 compose->cc_hbox = cc_hbox;
4167 compose->cc_entry = cc_entry;
4168 compose->bcc_hbox = bcc_hbox;
4169 compose->bcc_entry = bcc_entry;
4170 compose->reply_hbox = reply_hbox;
4171 compose->reply_entry = reply_entry;
4172 compose->followup_hbox = followup_hbox;
4173 compose->followup_entry = followup_entry;
4176 return header_scrolledwin ;
4179 GtkWidget *compose_create_attach(Compose *compose)
4181 gchar *titles[N_ATTACH_COLS];
4184 GtkWidget *attach_scrwin;
4185 GtkWidget *attach_clist;
4187 titles[COL_MIMETYPE] = _("MIME type");
4188 titles[COL_SIZE] = _("Size");
4189 titles[COL_NAME] = _("Name");
4191 /* attachment list */
4192 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4193 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4194 GTK_POLICY_AUTOMATIC,
4196 gtk_widget_set_usize(attach_scrwin, -1, 80);
4198 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4199 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4201 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4202 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4203 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4204 GTK_SELECTION_EXTENDED);
4205 for (i = 0; i < N_ATTACH_COLS; i++)
4206 GTK_WIDGET_UNSET_FLAGS
4207 (GTK_CLIST(attach_clist)->column[i].button,
4209 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4211 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4212 GTK_SIGNAL_FUNC(attach_selected), compose);
4213 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4214 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4215 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4216 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4219 gtk_drag_dest_set(attach_clist,
4220 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4222 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4223 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4226 compose->attach_scrwin = attach_scrwin;
4227 compose->attach_clist = attach_clist;
4229 return attach_scrwin;
4232 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4233 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4235 static GtkWidget *compose_create_others(Compose *compose)
4238 GtkWidget *savemsg_checkbtn;
4239 GtkWidget *savemsg_entry;
4240 GtkWidget *savemsg_select;
4243 gchar *folderidentifier;
4245 /* Table for settings */
4246 table = gtk_table_new(3, 1, FALSE);
4247 gtk_widget_show(table);
4248 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4251 /* Save Message to folder */
4252 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4253 gtk_widget_show(savemsg_checkbtn);
4254 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4255 if(account_get_special_folder(compose->account, F_OUTBOX)) {
4256 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4258 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4259 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4261 savemsg_entry = gtk_entry_new();
4262 gtk_widget_show(savemsg_entry);
4263 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4264 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4265 if(account_get_special_folder(compose->account, F_OUTBOX)) {
4266 folderidentifier = folder_item_get_identifier(account_get_special_folder
4267 (compose->account, F_OUTBOX));
4268 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4269 g_free(folderidentifier);
4272 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4273 gtk_widget_show (savemsg_select);
4274 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4275 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4276 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4281 compose->savemsg_checkbtn = savemsg_checkbtn;
4282 compose->savemsg_entry = savemsg_entry;
4287 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4289 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4290 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4293 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4298 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4301 path = folder_item_get_identifier(dest);
4303 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4307 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4313 GtkWidget *handlebox;
4315 GtkWidget *notebook;
4320 GtkWidget *subject_hbox;
4321 GtkWidget *subject_frame;
4322 GtkWidget *subject_entry;
4326 GtkWidget *edit_vbox;
4327 GtkWidget *ruler_hbox;
4329 GtkWidget *scrolledwin;
4332 UndoMain *undostruct;
4334 gchar *titles[N_ATTACH_COLS];
4335 guint n_menu_entries;
4336 GtkStyle *style, *new_style;
4339 gboolean success[1];
4341 GtkWidget *popupmenu;
4342 GtkWidget *menuitem;
4343 GtkItemFactory *popupfactory;
4344 GtkItemFactory *ifactory;
4345 GtkWidget *tmpl_menu;
4349 GtkPspell * gtkpspell = NULL;
4352 static GdkGeometry geometry;
4354 g_return_val_if_fail(account != NULL, NULL);
4356 debug_print(_("Creating compose window...\n"));
4357 compose = g_new0(Compose, 1);
4359 titles[COL_MIMETYPE] = _("MIME type");
4360 titles[COL_SIZE] = _("Size");
4361 titles[COL_NAME] = _("Name");
4363 compose->account = account;
4364 compose->orig_account = account;
4366 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4367 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4368 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4369 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4371 if (!geometry.max_width) {
4372 geometry.max_width = gdk_screen_width();
4373 geometry.max_height = gdk_screen_height();
4375 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4376 &geometry, GDK_HINT_MAX_SIZE);
4378 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4379 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4380 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4381 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4382 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4383 gtk_widget_realize(window);
4385 gtkut_widget_set_composer_icon(window);
4387 vbox = gtk_vbox_new(FALSE, 0);
4388 gtk_container_add(GTK_CONTAINER(window), vbox);
4390 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4391 menubar = menubar_create(window, compose_entries,
4392 n_menu_entries, "<Compose>", compose);
4393 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4395 handlebox = gtk_handle_box_new();
4396 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4398 compose_toolbar_create(compose, handlebox);
4400 vbox2 = gtk_vbox_new(FALSE, 2);
4401 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4402 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4405 notebook = gtk_notebook_new();
4406 gtk_widget_set_usize(notebook, -1, 130);
4407 gtk_widget_show(notebook);
4409 /* header labels and entries */
4410 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4411 /* attachment list */
4412 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4414 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4417 subject_hbox = gtk_hbox_new(FALSE, 0);
4418 gtk_widget_show(subject_hbox);
4420 subject_frame = gtk_frame_new(NULL);
4421 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4422 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4423 gtk_widget_show(subject_frame);
4425 subject = gtk_hbox_new(FALSE, 0);
4426 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4427 gtk_widget_show(subject);
4429 label = gtk_label_new(_("Subject:"));
4430 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4431 gtk_widget_show(label);
4433 subject_entry = gtk_entry_new();
4434 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4435 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4436 gtk_widget_show(subject_entry);
4437 compose->subject_entry = subject_entry;
4438 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4440 edit_vbox = gtk_vbox_new(FALSE, 0);
4441 #if 0 /* NEW COMPOSE GUI */
4442 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4445 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4448 ruler_hbox = gtk_hbox_new(FALSE, 0);
4449 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4451 ruler = gtk_shruler_new();
4452 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4453 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4455 gtk_widget_set_usize(ruler_hbox, 1, -1);
4458 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4459 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4460 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4461 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4462 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4464 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4465 (GTK_SCROLLED_WINDOW(scrolledwin)),
4466 gtk_scrolled_window_get_vadjustment
4467 (GTK_SCROLLED_WINDOW(scrolledwin)));
4468 GTK_STEXT(text)->default_tab_width = 8;
4469 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4471 if (prefs_common.block_cursor) {
4472 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4475 if (prefs_common.smart_wrapping) {
4476 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4477 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4480 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4482 gtk_signal_connect(GTK_OBJECT(text), "changed",
4483 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4484 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4485 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4486 gtk_signal_connect(GTK_OBJECT(text), "activate",
4487 GTK_SIGNAL_FUNC(text_activated), compose);
4488 gtk_signal_connect(GTK_OBJECT(text), "insert_text",
4489 GTK_SIGNAL_FUNC(text_inserted), compose);
4490 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4491 GTK_SIGNAL_FUNC(compose_button_press_cb),
4494 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4495 GTK_SIGNAL_FUNC(compose_key_press_cb),
4498 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4499 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4503 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4505 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4506 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4508 gtk_widget_show_all(vbox);
4510 /* pane between attach clist and text */
4511 paned = gtk_vpaned_new();
4512 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4513 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4514 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4515 gtk_paned_add1(GTK_PANED(paned), notebook);
4516 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4517 gtk_widget_show_all(paned);
4519 style = gtk_widget_get_style(text);
4521 /* workaround for the slow down of GtkSText when using Pixmap theme */
4522 if (style->engine) {
4523 GtkThemeEngine *engine;
4525 engine = style->engine;
4526 style->engine = NULL;
4527 new_style = gtk_style_copy(style);
4528 style->engine = engine;
4530 new_style = gtk_style_copy(style);
4532 if (prefs_common.textfont) {
4533 if (MB_CUR_MAX == 1) {
4536 Xstrdup_a(fontstr, prefs_common.textfont, );
4537 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4539 font = gdk_font_load(fontstr);
4541 font = gdk_fontset_load(prefs_common.textfont);
4543 gdk_font_unref(new_style->font);
4544 new_style->font = font;
4548 gtk_widget_set_style(text, new_style);
4550 color[0] = quote_color;
4551 cmap = gdk_window_get_colormap(window->window);
4552 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4553 if (success[0] == FALSE) {
4554 g_warning("Compose: color allocation failed.\n");
4555 style = gtk_widget_get_style(text);
4556 quote_color = style->black;
4559 n_entries = sizeof(compose_popup_entries) /
4560 sizeof(compose_popup_entries[0]);
4561 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4562 "<Compose>", &popupfactory,
4565 ifactory = gtk_item_factory_from_widget(menubar);
4566 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4567 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4569 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4570 #if 0 /* NEW COMPOSE GUI */
4571 gtk_widget_hide(bcc_hbox);
4572 gtk_widget_hide(bcc_entry);
4573 gtk_widget_hide(reply_hbox);
4574 gtk_widget_hide(reply_entry);
4575 gtk_widget_hide(followup_hbox);
4576 gtk_widget_hide(followup_entry);
4577 gtk_widget_hide(ruler_hbox);
4578 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4579 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4580 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4582 if (account->protocol == A_NNTP) {
4583 gtk_widget_hide(to_hbox);
4584 gtk_widget_hide(to_entry);
4585 gtk_widget_hide(cc_hbox);
4586 gtk_widget_hide(cc_entry);
4587 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4588 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4590 gtk_widget_hide(newsgroups_hbox);
4591 gtk_widget_hide(newsgroups_entry);
4592 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4593 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
4597 update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
4600 undostruct = undo_init(text);
4601 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4604 gtk_widget_show(window);
4606 address_completion_start(window);
4608 compose->window = window;
4609 compose->vbox = vbox;
4610 compose->menubar = menubar;
4611 compose->handlebox = handlebox;
4613 compose->vbox2 = vbox2;
4615 compose->paned = paned;
4617 compose->edit_vbox = edit_vbox;
4618 compose->ruler_hbox = ruler_hbox;
4619 compose->ruler = ruler;
4620 compose->scrolledwin = scrolledwin;
4621 compose->text = text;
4623 compose->focused_editable = NULL;
4625 compose->popupmenu = popupmenu;
4626 compose->popupfactory = popupfactory;
4628 compose->tmpl_menu = tmpl_menu;
4630 compose->mode = mode;
4632 compose->targetinfo = NULL;
4633 compose->replyinfo = NULL;
4635 compose->replyto = NULL;
4636 compose->mailinglist = NULL;
4638 compose->bcc = NULL;
4639 compose->followup_to = NULL;
4640 compose->inreplyto = NULL;
4641 compose->references = NULL;
4642 compose->msgid = NULL;
4643 compose->boundary = NULL;
4646 compose->use_signing = FALSE;
4647 compose->use_encryption = FALSE;
4648 #endif /* USE_GPGME */
4650 compose->modified = FALSE;
4652 compose->return_receipt = FALSE;
4653 compose->paste_as_quotation = FALSE;
4655 compose->to_list = NULL;
4656 compose->newsgroup_list = NULL;
4658 compose->exteditor_file = NULL;
4659 compose->exteditor_pid = -1;
4660 compose->exteditor_readdes = -1;
4661 compose->exteditor_tag = -1;
4663 compose->redirect_filename = NULL;
4664 compose->undostruct = undostruct;
4667 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4668 if (prefs_common.enable_pspell) {
4669 gtkpspell = gtkpspell_new((const gchar*)prefs_common.dictionary,
4670 conv_get_current_charset_str(),
4671 prefs_common.misspelled_col,
4672 prefs_common.check_while_typing,
4673 prefs_common.use_alternate,
4676 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkpspellcheckers->error_message);
4677 gtkpspell_checkers_reset_error();
4680 GtkWidget *menuitem;
4682 if (!gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode)) {
4683 debug_print(_("Pspell: could not set suggestion mode %s\n"),
4684 gtkpspellcheckers->error_message);
4685 gtkpspell_checkers_reset_error();
4688 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
4689 gtkpspell_populate_submenu(gtkpspell, menuitem);
4690 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4695 compose_set_title(compose);
4697 #if 0 /* NEW COMPOSE GUI */
4698 compose->use_bcc = FALSE;
4699 compose->use_replyto = FALSE;
4700 compose->use_followupto = FALSE;
4704 compose->gtkpspell = gtkpspell;
4707 #if 0 /* NEW COMPOSE GUI */
4708 if (account->protocol != A_NNTP) {
4709 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
4710 gtk_check_menu_item_set_active
4711 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4712 gtk_widget_set_sensitive(menuitem, FALSE);
4713 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4714 gtk_check_menu_item_set_active
4715 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4716 gtk_widget_set_sensitive(menuitem, FALSE);
4719 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4720 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4721 #if 0 /* NEW COMPOSE GUI */
4722 compose->use_cc = TRUE;
4723 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4724 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4725 gtk_check_menu_item_set_active
4726 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4729 if (account->set_autobcc) {
4730 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4731 #if 0 /* NEW COMPOSE GUI */
4732 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
4733 gtk_check_menu_item_set_active
4734 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4735 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4736 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4740 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4741 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4742 #if 0 /* NEW COMPOSE GUI */
4743 compose->use_replyto = TRUE;
4744 menuitem = gtk_item_factory_get_item(ifactory,
4746 gtk_check_menu_item_set_active
4747 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4748 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4749 account->auto_replyto);
4753 if (account->protocol != A_NNTP) {
4754 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4756 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4759 #if 0 /* NEW COMPOSE GUI */
4760 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
4761 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4762 prefs_common.show_ruler);
4766 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4767 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4768 account->default_sign);
4769 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4770 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4771 account->default_encrypt);
4772 #endif /* USE_GPGME */
4774 addressbook_set_target_compose(compose);
4775 compose_set_template_menu(compose);
4777 compose_list = g_list_append(compose_list, compose);
4779 #if 0 /* NEW COMPOSE GUI */
4780 compose->use_to = FALSE;
4781 compose->use_cc = FALSE;
4782 compose->use_attach = TRUE;
4785 #if 0 /* NEW COMPOSE GUI */
4786 if (!compose->use_bcc) {
4787 gtk_widget_hide(bcc_hbox);
4788 gtk_widget_hide(bcc_entry);
4789 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4791 if (!compose->use_replyto) {
4792 gtk_widget_hide(reply_hbox);
4793 gtk_widget_hide(reply_entry);
4794 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4796 if (!compose->use_followupto) {
4797 gtk_widget_hide(followup_hbox);
4798 gtk_widget_hide(followup_entry);
4799 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4802 if (!prefs_common.show_ruler)
4803 gtk_widget_hide(ruler_hbox);
4806 compose->priority = PRIORITY_NORMAL;
4807 compose_update_priority_menu_item(compose);
4809 select_account(compose, account);
4810 set_toolbar_style(compose);
4815 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4818 GtkWidget *icon_wid;
4819 GtkWidget *send_btn;
4820 GtkWidget *sendl_btn;
4821 GtkWidget *draft_btn;
4822 GtkWidget *insert_btn;
4823 GtkWidget *attach_btn;
4825 GtkWidget *exteditor_btn;
4826 GtkWidget *linewrap_btn;
4827 GtkWidget *addrbook_btn;
4829 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4831 gtk_container_add(GTK_CONTAINER(container), toolbar);
4832 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4833 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4834 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4835 GTK_TOOLBAR_SPACE_LINE);
4837 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
4838 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4842 icon_wid, toolbar_send_cb, compose);
4844 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND_QUEUE);
4845 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4847 _("Put into queue folder and send later"),
4849 icon_wid, toolbar_send_later_cb,
4852 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4853 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4855 _("Save to draft folder"),
4857 icon_wid, toolbar_draft_cb,
4860 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4862 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_INSERT_FILE);
4863 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4867 icon_wid, toolbar_insert_cb,
4870 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_ATTACH);
4871 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4875 icon_wid, toolbar_attach_cb,
4878 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4880 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SIGN);
4881 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4883 _("Insert signature"),
4885 icon_wid, toolbar_sig_cb, compose);
4887 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4889 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_EDIT_EXTERN);
4890 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4892 _("Edit with external editor"),
4895 toolbar_ext_editor_cb,
4898 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_LINEWRAP);
4899 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4901 _("Wrap all long lines"),
4904 toolbar_linewrap_cb,
4907 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4909 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_ADDRESS_BOOK);
4910 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4914 icon_wid, toolbar_address_cb,
4917 compose->toolbar = toolbar;
4918 compose->send_btn = send_btn;
4919 compose->sendl_btn = sendl_btn;
4920 compose->draft_btn = draft_btn;
4921 compose->insert_btn = insert_btn;
4922 compose->attach_btn = attach_btn;
4923 compose->sig_btn = sig_btn;
4924 compose->exteditor_btn = exteditor_btn;
4925 compose->linewrap_btn = linewrap_btn;
4926 compose->addrbook_btn = addrbook_btn;
4928 gtk_widget_show_all(toolbar);
4931 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4937 gint num = 0, def_menu = 0;
4939 accounts = account_get_list();
4940 g_return_val_if_fail(accounts != NULL, NULL);
4942 hbox = gtk_hbox_new(FALSE, 0);
4943 optmenu = gtk_option_menu_new();
4944 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4945 menu = gtk_menu_new();
4947 for (; accounts != NULL; accounts = accounts->next, num++) {
4948 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4949 GtkWidget *menuitem;
4952 if (ac == compose->account) def_menu = num;
4955 name = g_strdup_printf("%s: %s <%s>",
4957 ac->name, ac->address);
4959 name = g_strdup_printf("%s: %s",
4960 ac->account_name, ac->address);
4961 MENUITEM_ADD(menu, menuitem, name, ac);
4963 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4964 GTK_SIGNAL_FUNC(account_activated),
4968 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4969 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4974 static void compose_set_priority_cb(gpointer data,
4978 Compose *compose = (Compose *) data;
4979 compose->priority = action;
4982 static void compose_update_priority_menu_item(Compose * compose)
4984 GtkItemFactory *ifactory;
4985 GtkWidget *menuitem = NULL;
4987 ifactory = gtk_item_factory_from_widget(compose->menubar);
4989 switch (compose->priority) {
4990 case PRIORITY_HIGHEST:
4991 menuitem = gtk_item_factory_get_item
4992 (ifactory, "/Message/Priority/Highest");
4995 menuitem = gtk_item_factory_get_item
4996 (ifactory, "/Message/Priority/High");
4998 case PRIORITY_NORMAL:
4999 menuitem = gtk_item_factory_get_item
5000 (ifactory, "/Message/Priority/Normal");
5003 menuitem = gtk_item_factory_get_item
5004 (ifactory, "/Message/Priority/Low");
5006 case PRIORITY_LOWEST:
5007 menuitem = gtk_item_factory_get_item
5008 (ifactory, "/Message/Priority/Lowest");
5011 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5014 static void compose_set_template_menu(Compose *compose)
5016 GSList *tmpl_list, *cur;
5020 tmpl_list = template_get_config();
5022 menu = gtk_menu_new();
5024 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5025 Template *tmpl = (Template *)cur->data;
5027 item = gtk_menu_item_new_with_label(tmpl->name);
5028 gtk_menu_append(GTK_MENU(menu), item);
5029 gtk_signal_connect(GTK_OBJECT(item), "activate",
5030 GTK_SIGNAL_FUNC(compose_template_activate_cb),
5032 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
5033 gtk_widget_show(item);
5036 gtk_widget_show(menu);
5037 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5040 void compose_reflect_prefs_all(void)
5045 for (cur = compose_list; cur != NULL; cur = cur->next) {
5046 compose = (Compose *)cur->data;
5047 compose_set_template_menu(compose);
5051 void compose_reflect_prefs_pixmap_theme(void)
5056 for (cur = compose_list; cur != NULL; cur = cur->next) {
5057 compose = (Compose *)cur->data;
5058 gtk_container_remove(GTK_CONTAINER(compose->handlebox), GTK_WIDGET(compose->toolbar));
5059 compose->toolbar = NULL;
5060 compose_toolbar_create(compose, compose->handlebox);
5061 set_toolbar_style(compose);
5065 static void compose_template_apply(Compose *compose, Template *tmpl,
5071 if (!tmpl || !tmpl->value) return;
5073 gtk_stext_freeze(GTK_STEXT(compose->text));
5075 if (tmpl->subject && *tmpl->subject != '\0')
5076 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5078 if (tmpl->to && *tmpl->to != '\0')
5079 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5082 gtk_stext_clear(GTK_STEXT(compose->text));
5084 if (compose->replyinfo == NULL) {
5085 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5088 if (prefs_common.quotemark && *prefs_common.quotemark)
5089 qmark = prefs_common.quotemark;
5093 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5094 tmpl->value, qmark, NULL);
5097 if (replace && parsed_str && prefs_common.auto_sig)
5098 compose_insert_sig(compose);
5100 if (replace && parsed_str) {
5101 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
5102 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
5106 compose_changed_cb(NULL, compose);
5108 gtk_stext_thaw(GTK_STEXT(compose->text));
5111 static void compose_destroy(Compose *compose)
5114 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5117 /* NOTE: address_completion_end() does nothing with the window
5118 * however this may change. */
5119 address_completion_end(compose->window);
5121 slist_free_strings(compose->to_list);
5122 g_slist_free(compose->to_list);
5123 slist_free_strings(compose->newsgroup_list);
5124 g_slist_free(compose->newsgroup_list);
5125 slist_free_strings(compose->header_list);
5126 g_slist_free(compose->header_list);
5128 procmsg_msginfo_free(compose->targetinfo);
5129 procmsg_msginfo_free(compose->replyinfo);
5131 g_free(compose->replyto);
5132 g_free(compose->cc);
5133 g_free(compose->bcc);
5134 g_free(compose->newsgroups);
5135 g_free(compose->followup_to);
5137 g_free(compose->inreplyto);
5138 g_free(compose->references);
5139 g_free(compose->msgid);
5140 g_free(compose->boundary);
5142 if (compose->redirect_filename)
5143 g_free(compose->redirect_filename);
5145 g_free(compose->exteditor_file);
5147 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5149 compose_attach_info_free(ainfo);
5151 if (addressbook_get_target_compose() == compose)
5152 addressbook_set_target_compose(NULL);
5155 if (compose->gtkpspell) {
5156 gtkpspell_delete(compose->gtkpspell);
5160 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5161 prefs_common.compose_height = compose->window->allocation.height;
5163 gtk_widget_destroy(compose->paned);
5167 compose_list = g_list_remove(compose_list, compose);
5170 static void compose_attach_info_free(AttachInfo *ainfo)
5172 g_free(ainfo->file);
5173 g_free(ainfo->content_type);
5174 g_free(ainfo->name);
5178 static void compose_attach_remove_selected(Compose *compose)
5180 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5184 while (clist->selection != NULL) {
5185 row = GPOINTER_TO_INT(clist->selection->data);
5186 ainfo = gtk_clist_get_row_data(clist, row);
5187 compose_attach_info_free(ainfo);
5188 gtk_clist_remove(clist, row);
5192 static struct _AttachProperty
5195 GtkWidget *mimetype_entry;
5196 GtkWidget *encoding_optmenu;
5197 GtkWidget *path_entry;
5198 GtkWidget *filename_entry;
5200 GtkWidget *cancel_btn;
5203 static void compose_attach_property(Compose *compose)
5205 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5208 GtkOptionMenu *optmenu;
5209 static gboolean cancelled;
5211 if (!clist->selection) return;
5212 row = GPOINTER_TO_INT(clist->selection->data);
5214 ainfo = gtk_clist_get_row_data(clist, row);
5217 if (!attach_prop.window)
5218 compose_attach_property_create(&cancelled);
5219 gtk_widget_grab_focus(attach_prop.ok_btn);
5220 gtk_widget_show(attach_prop.window);
5221 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5223 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5224 if (ainfo->encoding == ENC_UNKNOWN)
5225 gtk_option_menu_set_history(optmenu, ENC_BASE64);
5227 gtk_option_menu_set_history(optmenu, ainfo->encoding);
5229 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5230 ainfo->content_type ? ainfo->content_type : "");
5231 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5232 ainfo->file ? ainfo->file : "");
5233 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5234 ainfo->name ? ainfo->name : "");
5238 gchar *cnttype = NULL;
5242 GtkWidget *menuitem;
5247 if (cancelled == TRUE) {
5248 gtk_widget_hide(attach_prop.window);
5252 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5253 if (*text != '\0') {
5256 text = g_strstrip(g_strdup(text));
5257 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5258 cnttype = g_strdup(text);
5261 alertpanel_error(_("Invalid MIME type."));
5267 menu = gtk_option_menu_get_menu(optmenu);
5268 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5269 ainfo->encoding = GPOINTER_TO_INT
5270 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5272 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5273 if (*text != '\0') {
5274 if (is_file_exist(text) &&
5275 (size = get_file_size(text)) > 0)
5276 file = g_strdup(text);
5279 (_("File doesn't exist or is empty."));
5285 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5286 if (*text != '\0') {
5287 g_free(ainfo->name);
5288 ainfo->name = g_strdup(text);
5292 g_free(ainfo->content_type);
5293 ainfo->content_type = cnttype;
5296 g_free(ainfo->file);
5302 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5303 ainfo->content_type);
5304 gtk_clist_set_text(clist, row, COL_SIZE,
5305 to_human_readable(ainfo->size));
5306 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5308 gtk_widget_hide(attach_prop.window);
5313 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5315 label = gtk_label_new(str); \
5316 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5317 GTK_FILL, 0, 0, 0); \
5318 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5320 entry = gtk_entry_new(); \
5321 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5322 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5325 static void compose_attach_property_create(gboolean *cancelled)
5331 GtkWidget *mimetype_entry;
5334 GtkWidget *optmenu_menu;
5335 GtkWidget *menuitem;
5336 GtkWidget *path_entry;
5337 GtkWidget *filename_entry;
5340 GtkWidget *cancel_btn;
5341 GList *mime_type_list, *strlist;
5343 debug_print("Creating attach_property window...\n");
5345 window = gtk_window_new(GTK_WINDOW_DIALOG);
5346 gtk_widget_set_usize(window, 480, -1);
5347 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5348 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
5349 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5350 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5351 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5352 GTK_SIGNAL_FUNC(attach_property_delete_event),
5354 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5355 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5358 vbox = gtk_vbox_new(FALSE, 8);
5359 gtk_container_add(GTK_CONTAINER(window), vbox);
5361 table = gtk_table_new(4, 2, FALSE);
5362 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5363 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5364 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5366 label = gtk_label_new(_("MIME type"));
5367 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5369 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5370 mimetype_entry = gtk_combo_new();
5371 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5372 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5374 /* stuff with list */
5375 mime_type_list = procmime_get_mime_type_list();
5377 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5378 MimeType *type = (MimeType *) mime_type_list->data;
5379 strlist = g_list_append(strlist,
5380 g_strdup_printf("%s/%s",
5381 type->type, type->sub_type));
5384 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5386 for (mime_type_list = strlist; mime_type_list != NULL;
5387 mime_type_list = mime_type_list->next)
5388 g_free(mime_type_list->data);
5389 g_list_free(strlist);
5391 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5393 label = gtk_label_new(_("Encoding"));
5394 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5396 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5398 hbox = gtk_hbox_new(FALSE, 0);
5399 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5400 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5402 optmenu = gtk_option_menu_new();
5403 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5405 optmenu_menu = gtk_menu_new();
5406 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5407 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5409 gtk_widget_set_sensitive(menuitem, FALSE);
5411 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5412 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5414 gtk_widget_set_sensitive(menuitem, FALSE);
5416 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5417 gtk_widget_set_sensitive(menuitem, FALSE);
5418 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5420 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5422 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5423 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5425 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5426 &cancel_btn, _("Cancel"), NULL, NULL);
5427 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5428 gtk_widget_grab_default(ok_btn);
5430 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5431 GTK_SIGNAL_FUNC(attach_property_ok),
5433 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5434 GTK_SIGNAL_FUNC(attach_property_cancel),
5437 gtk_widget_show_all(vbox);
5439 attach_prop.window = window;
5440 attach_prop.mimetype_entry = mimetype_entry;
5441 attach_prop.encoding_optmenu = optmenu;
5442 attach_prop.path_entry = path_entry;
5443 attach_prop.filename_entry = filename_entry;
5444 attach_prop.ok_btn = ok_btn;
5445 attach_prop.cancel_btn = cancel_btn;
5448 #undef SET_LABEL_AND_ENTRY
5450 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5456 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5462 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5463 gboolean *cancelled)
5471 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5472 gboolean *cancelled)
5474 if (event && event->keyval == GDK_Escape) {
5480 static void compose_exec_ext_editor(Compose *compose)
5486 tmp = g_strdup_printf("%s%ctmpmsg.%08x", get_tmp_dir(),
5487 G_DIR_SEPARATOR, (gint)compose);
5489 if (pipe(pipe_fds) < 0) {
5495 if ((pid = fork()) < 0) {
5502 /* close the write side of the pipe */
5505 compose->exteditor_file = g_strdup(tmp);
5506 compose->exteditor_pid = pid;
5507 compose->exteditor_readdes = pipe_fds[0];
5509 compose_set_ext_editor_sensitive(compose, FALSE);
5511 compose->exteditor_tag =
5512 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5513 compose_input_cb, compose);
5514 } else { /* process-monitoring process */
5520 /* close the read side of the pipe */
5523 if (compose_write_body_to_file(compose, tmp) < 0) {
5524 fd_write(pipe_fds[1], "2\n", 2);
5528 pid_ed = compose_exec_ext_editor_real(tmp);
5530 fd_write(pipe_fds[1], "1\n", 2);
5534 /* wait until editor is terminated */
5535 waitpid(pid_ed, NULL, 0);
5537 fd_write(pipe_fds[1], "0\n", 2);
5546 static gint compose_exec_ext_editor_real(const gchar *file)
5548 static gchar *def_cmd = "emacs %s";
5554 g_return_val_if_fail(file != NULL, -1);
5556 if ((pid = fork()) < 0) {
5561 if (pid != 0) return pid;
5563 /* grandchild process */
5565 if (setpgid(0, getppid()))
5568 if (prefs_common.ext_editor_cmd &&
5569 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5570 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5571 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5573 if (prefs_common.ext_editor_cmd)
5574 g_warning(_("External editor command line is invalid: `%s'\n"),
5575 prefs_common.ext_editor_cmd);
5576 g_snprintf(buf, sizeof(buf), def_cmd, file);
5579 cmdline = strsplit_with_quote(buf, " ", 1024);
5580 execvp(cmdline[0], cmdline);
5583 g_strfreev(cmdline);
5588 static gboolean compose_ext_editor_kill(Compose *compose)
5590 pid_t pgid = compose->exteditor_pid * -1;
5593 ret = kill(pgid, 0);
5595 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5599 msg = g_strdup_printf
5600 (_("The external editor is still working.\n"
5601 "Force terminating the process?\n"
5602 "process group id: %d"), -pgid);
5603 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5606 if (val == G_ALERTDEFAULT) {
5607 gdk_input_remove(compose->exteditor_tag);
5608 close(compose->exteditor_readdes);
5610 if (kill(pgid, SIGTERM) < 0) perror("kill");
5611 waitpid(compose->exteditor_pid, NULL, 0);
5613 g_warning(_("Terminated process group id: %d"), -pgid);
5614 g_warning(_("Temporary file: %s"),
5615 compose->exteditor_file);
5617 compose_set_ext_editor_sensitive(compose, TRUE);
5619 g_free(compose->exteditor_file);
5620 compose->exteditor_file = NULL;
5621 compose->exteditor_pid = -1;
5622 compose->exteditor_readdes = -1;
5623 compose->exteditor_tag = -1;
5631 static void compose_input_cb(gpointer data, gint source,
5632 GdkInputCondition condition)
5635 Compose *compose = (Compose *)data;
5638 debug_print(_("Compose: input from monitoring process\n"));
5640 gdk_input_remove(compose->exteditor_tag);
5643 if (read(source, &buf[i], 1) < 1) {
5647 if (buf[i] == '\n') {
5652 if (i == sizeof(buf) - 1)
5656 waitpid(compose->exteditor_pid, NULL, 0);
5658 if (buf[0] == '0') { /* success */
5659 GtkSText *text = GTK_STEXT(compose->text);
5661 gtk_stext_freeze(text);
5662 gtk_stext_set_point(text, 0);
5663 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5664 compose_insert_file(compose, compose->exteditor_file);
5665 compose_changed_cb(NULL, compose);
5666 gtk_stext_thaw(text);
5668 if (unlink(compose->exteditor_file) < 0)
5669 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5670 } else if (buf[0] == '1') { /* failed */
5671 g_warning(_("Couldn't exec external editor\n"));
5672 if (unlink(compose->exteditor_file) < 0)
5673 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5674 } else if (buf[0] == '2') {
5675 g_warning(_("Couldn't write to file\n"));
5676 } else if (buf[0] == '3') {
5677 g_warning(_("Pipe read failed\n"));
5682 compose_set_ext_editor_sensitive(compose, TRUE);
5684 g_free(compose->exteditor_file);
5685 compose->exteditor_file = NULL;
5686 compose->exteditor_pid = -1;
5687 compose->exteditor_readdes = -1;
5688 compose->exteditor_tag = -1;
5691 static void compose_set_ext_editor_sensitive(Compose *compose,
5694 GtkItemFactory *ifactory;
5696 ifactory = gtk_item_factory_from_widget(compose->menubar);
5698 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5699 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5700 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5702 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5703 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5704 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5705 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5706 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5709 gtk_widget_set_sensitive(compose->text, sensitive);
5710 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5711 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5712 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5713 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5714 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5715 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5716 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5720 * compose_undo_state_changed:
5722 * Change the sensivity of the menuentries undo and redo
5724 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5725 gint redo_state, gpointer data)
5727 GtkWidget *widget = GTK_WIDGET(data);
5728 GtkItemFactory *ifactory;
5730 g_return_if_fail(widget != NULL);
5732 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
5734 ifactory = gtk_item_factory_from_widget(widget);
5736 switch (undo_state) {
5737 case UNDO_STATE_TRUE:
5738 if (!undostruct->undo_state) {
5739 debug_print ("Set_undo - Testpoint\n");
5740 undostruct->undo_state = TRUE;
5741 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5744 case UNDO_STATE_FALSE:
5745 if (undostruct->undo_state) {
5746 undostruct->undo_state = FALSE;
5747 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5750 case UNDO_STATE_UNCHANGED:
5752 case UNDO_STATE_REFRESH:
5753 menu_set_sensitive(ifactory, "/Edit/Undo",
5754 undostruct->undo_state);
5757 g_warning("Undo state not recognized");
5761 switch (redo_state) {
5762 case UNDO_STATE_TRUE:
5763 if (!undostruct->redo_state) {
5764 undostruct->redo_state = TRUE;
5765 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5768 case UNDO_STATE_FALSE:
5769 if (undostruct->redo_state) {
5770 undostruct->redo_state = FALSE;
5771 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5774 case UNDO_STATE_UNCHANGED:
5776 case UNDO_STATE_REFRESH:
5777 menu_set_sensitive(ifactory, "/Edit/Redo",
5778 undostruct->redo_state);
5781 g_warning("Redo state not recognized");
5786 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5790 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5791 cursor_pos = MAX(cursor_pos, 0);
5796 /* callback functions */
5798 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5799 * includes "non-client" (windows-izm) in calculation, so this calculation
5800 * may not be accurate.
5802 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5803 GtkAllocation *allocation,
5804 GtkSHRuler *shruler)
5806 if (prefs_common.show_ruler) {
5808 gint line_width_in_chars;
5810 char_width = gtkut_get_font_width
5811 (GTK_WIDGET(widget)->style->font);
5812 line_width_in_chars =
5813 (allocation->width - allocation->x) / char_width;
5815 /* got the maximum */
5816 gtk_ruler_set_range(GTK_RULER(shruler),
5817 0.0, line_width_in_chars,
5818 calc_cursor_xpos(GTK_STEXT(widget),
5821 /*line_width_in_chars*/ char_width);
5827 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5829 compose_send_cb(data, 0, NULL);
5832 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5834 compose_send_later_cb(data, 0, NULL);
5837 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5839 compose_draft_cb(data, 0, NULL);
5842 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5844 compose_insert_file_cb(data, 0, NULL);
5847 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5849 compose_attach_cb(data, 0, NULL);
5852 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5854 Compose *compose = (Compose *)data;
5856 compose_insert_sig(compose);
5859 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5861 Compose *compose = (Compose *)data;
5863 compose_exec_ext_editor(compose);
5866 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5868 Compose *compose = (Compose *)data;
5870 compose_wrap_line(compose);
5873 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5875 compose_address_cb(data, 0, NULL);
5878 static void select_account(Compose * compose, PrefsAccount * ac)
5881 GtkItemFactory *ifactory;
5882 GtkWidget *menuitem;
5883 #endif /* USE_GPGME */
5884 compose->account = ac;
5885 compose_set_title(compose);
5887 #if 0 /* NEW COMPOSE GUI */
5888 if (ac->protocol == A_NNTP) {
5889 GtkItemFactory *ifactory;
5890 GtkWidget *menuitem;
5892 ifactory = gtk_item_factory_from_widget(compose->menubar);
5893 menu_set_sensitive(ifactory,
5894 "/Message/Followup to", TRUE);
5895 gtk_widget_show(compose->newsgroups_hbox);
5896 gtk_widget_show(compose->newsgroups_entry);
5897 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5900 compose->use_to = FALSE;
5901 compose->use_cc = FALSE;
5903 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5904 gtk_check_menu_item_set_active
5905 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5907 menu_set_sensitive(ifactory,
5908 "/Message/To", TRUE);
5909 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5910 gtk_check_menu_item_set_active
5911 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5913 gtk_widget_hide(compose->to_hbox);
5914 gtk_widget_hide(compose->to_entry);
5915 gtk_widget_hide(compose->cc_hbox);
5916 gtk_widget_hide(compose->cc_entry);
5917 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5919 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5923 GtkItemFactory *ifactory;
5924 GtkWidget *menuitem;
5926 ifactory = gtk_item_factory_from_widget(compose->menubar);
5927 menu_set_sensitive(ifactory,
5928 "/Message/Followup to", FALSE);
5929 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5930 gtk_widget_hide(compose->newsgroups_hbox);
5931 gtk_widget_hide(compose->newsgroups_entry);
5932 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5935 compose->use_to = TRUE;
5936 compose->use_cc = TRUE;
5938 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5939 gtk_check_menu_item_set_active
5940 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5941 menu_set_sensitive(ifactory,
5942 "/Message/To", FALSE);
5943 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5944 gtk_check_menu_item_set_active
5945 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5946 gtk_widget_show(compose->to_hbox);
5947 gtk_widget_show(compose->to_entry);
5948 gtk_widget_show(compose->cc_hbox);
5949 gtk_widget_show(compose->cc_entry);
5951 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5953 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5956 gtk_widget_queue_resize(compose->table_vbox);
5959 ifactory = gtk_item_factory_from_widget(compose->menubar);
5960 menu_set_sensitive(ifactory,
5961 "/Message/Sign", TRUE);
5962 menu_set_sensitive(ifactory,
5963 "/Message/Encrypt", TRUE);
5965 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
5966 if (ac->default_sign)
5967 gtk_check_menu_item_set_active
5968 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5970 gtk_check_menu_item_set_active
5971 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5973 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
5974 if (ac->default_encrypt)
5975 gtk_check_menu_item_set_active
5976 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5978 gtk_check_menu_item_set_active
5979 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5980 #endif /* USE_GPGME */
5984 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5986 Compose *compose = (Compose *)data;
5990 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5991 g_return_if_fail(ac != NULL);
5993 if (ac != compose->account)
5994 select_account(compose, ac);
5997 static void attach_selected(GtkCList *clist, gint row, gint column,
5998 GdkEvent *event, gpointer data)
6000 Compose *compose = (Compose *)data;
6002 if (event && event->type == GDK_2BUTTON_PRESS)
6003 compose_attach_property(compose);
6006 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6009 Compose *compose = (Compose *)data;
6010 GtkCList *clist = GTK_CLIST(compose->attach_clist);
6015 if (event->button == 3) {
6016 if ((clist->selection && !clist->selection->next) ||
6017 !clist->selection) {
6018 gtk_clist_unselect_all(clist);
6019 if (gtk_clist_get_selection_info(clist,
6022 gtk_clist_select_row(clist, row, column);
6023 gtkut_clist_set_focus_row(clist, row);
6026 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6027 NULL, NULL, event->button, event->time);
6031 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6034 Compose *compose = (Compose *)data;
6038 switch (event->keyval) {
6040 compose_attach_remove_selected(compose);
6045 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6047 Compose *compose = (Compose *)data;
6050 if (prefs_common.work_offline)
6051 if (alertpanel(_("Offline warning"),
6052 _("You're working offline. Override?"),
6053 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
6056 val = compose_send(compose);
6058 if (val == 0) gtk_widget_destroy(compose->window);
6061 static void compose_send_later_cb(gpointer data, guint action,
6064 Compose *compose = (Compose *)data;
6067 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6068 if (!val) gtk_widget_destroy(compose->window);
6071 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6073 Compose *compose = (Compose *)data;
6077 static gboolean lock = FALSE;
6078 MsgInfo *newmsginfo;
6082 draft = account_get_special_folder(compose->account, F_DRAFT);
6083 g_return_if_fail(draft != NULL);
6087 tmp = g_strdup_printf("%s%cdraft.%08x", get_tmp_dir(),
6088 G_DIR_SEPARATOR, (gint)compose);
6090 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
6096 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) < 0) {
6103 draft->mtime = 0; /* force updating */
6105 if (compose->mode == COMPOSE_REEDIT) {
6106 compose_remove_reedit_target(compose);
6107 if (compose->targetinfo &&
6108 compose->targetinfo->folder != draft)
6109 folderview_update_item(compose->targetinfo->folder,
6113 newmsginfo = folder_item_fetch_msginfo(draft, msgnum);
6114 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6115 folderview_update_item(draft, TRUE);
6116 procmsg_msginfo_free(newmsginfo);
6120 /* 0: quit editing 1: keep editing */
6122 gtk_widget_destroy(compose->window);
6127 path = folder_item_fetch_msg(draft, msgnum);
6128 g_return_if_fail(path != NULL);
6129 if (stat(path, &s) < 0) {
6130 FILE_OP_ERROR(path, "stat");
6137 procmsg_msginfo_free(compose->targetinfo);
6138 compose->targetinfo = procmsg_msginfo_new();
6139 compose->targetinfo->msgnum = msgnum;
6140 compose->targetinfo->size = s.st_size;
6141 compose->targetinfo->mtime = s.st_mtime;
6142 compose->targetinfo->folder = draft;
6143 compose->mode = COMPOSE_REEDIT;
6147 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6149 Compose *compose = (Compose *)data;
6152 if (compose->redirect_filename != NULL)
6155 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6160 for ( tmp = file_list; tmp; tmp = tmp->next) {
6161 gchar *file = (gchar *) tmp->data;
6162 compose_attach_append(compose, file, file, NULL);
6163 compose_changed_cb(NULL, compose);
6166 g_list_free(file_list);
6170 static void compose_insert_file_cb(gpointer data, guint action,
6173 Compose *compose = (Compose *)data;
6176 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6181 for ( tmp = file_list; tmp; tmp = tmp->next) {
6182 gchar *file = (gchar *) tmp->data;
6183 compose_insert_file(compose, file);
6186 g_list_free(file_list);
6190 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6193 compose_close_cb(data, 0, NULL);
6197 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6199 Compose *compose = (Compose *)data;
6202 if (compose->exteditor_tag != -1) {
6203 if (!compose_ext_editor_kill(compose))
6207 if (compose->modified) {
6208 val = alertpanel(_("Discard message"),
6209 _("This message has been modified. discard it?"),
6210 _("Discard"), _("to Draft"), _("Cancel"));
6213 case G_ALERTDEFAULT:
6215 case G_ALERTALTERNATE:
6216 compose_draft_cb(data, 0, NULL);
6222 gtk_widget_destroy(compose->window);
6225 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6227 Compose *compose = (Compose *)data;
6229 addressbook_open(compose);
6232 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6234 Compose *compose = (Compose *)data;
6239 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6240 g_return_if_fail(tmpl != NULL);
6242 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6244 val = alertpanel(_("Apply template"), msg,
6245 _("Replace"), _("Insert"), _("Cancel"));
6248 if (val == G_ALERTDEFAULT)
6249 compose_template_apply(compose, tmpl, TRUE);
6250 else if (val == G_ALERTALTERNATE)
6251 compose_template_apply(compose, tmpl, FALSE);
6254 static void compose_ext_editor_cb(gpointer data, guint action,
6257 Compose *compose = (Compose *)data;
6259 compose_exec_ext_editor(compose);
6262 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6264 compose_destroy(compose);
6267 static void compose_undo_cb(Compose *compose)
6269 undo_undo(compose->undostruct);
6272 static void compose_redo_cb(Compose *compose)
6274 undo_redo(compose->undostruct);
6277 static void compose_cut_cb(Compose *compose)
6279 if (compose->focused_editable &&
6280 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6281 gtk_editable_cut_clipboard
6282 (GTK_EDITABLE(compose->focused_editable));
6285 static void compose_copy_cb(Compose *compose)
6287 if (compose->focused_editable &&
6288 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6289 gtk_editable_copy_clipboard
6290 (GTK_EDITABLE(compose->focused_editable));
6293 static void compose_paste_cb(Compose *compose)
6295 if (compose->focused_editable &&
6296 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6297 gtk_editable_paste_clipboard
6298 (GTK_EDITABLE(compose->focused_editable));
6301 static void compose_paste_as_quote_cb(Compose *compose)
6303 if (compose->focused_editable &&
6304 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6305 compose->paste_as_quotation = TRUE;
6306 gtk_editable_paste_clipboard
6307 (GTK_EDITABLE(compose->focused_editable));
6308 compose->paste_as_quotation = FALSE;
6312 static void compose_allsel_cb(Compose *compose)
6314 if (compose->focused_editable &&
6315 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6316 gtk_editable_select_region
6317 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6320 static void compose_gtk_stext_action_cb(Compose *compose, ComposeCallGtkSTextAction action)
6322 if (!(compose->focused_editable && GTK_WIDGET_HAS_FOCUS(compose->focused_editable))) return;
6325 case COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE:
6326 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6328 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER:
6329 gtk_stext_move_forward_character(GTK_STEXT(compose->focused_editable));
6331 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER:
6332 gtk_stext_move_backward_character(GTK_STEXT(compose->focused_editable));
6334 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD:
6335 gtk_stext_move_forward_word(GTK_STEXT(compose->focused_editable));
6337 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD:
6338 gtk_stext_move_backward_word(GTK_STEXT(compose->focused_editable));
6340 case COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE:
6341 gtk_stext_move_end_of_line(GTK_STEXT(compose->focused_editable));
6343 case COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE:
6344 gtk_stext_move_next_line(GTK_STEXT(compose->focused_editable));
6346 case COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE:
6347 gtk_stext_move_previous_line(GTK_STEXT(compose->focused_editable));
6349 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER:
6350 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6352 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER:
6353 gtk_stext_delete_backward_character(GTK_STEXT(compose->focused_editable));
6355 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD:
6356 gtk_stext_delete_forward_word(GTK_STEXT(compose->focused_editable));
6358 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD:
6359 gtk_stext_delete_backward_word(GTK_STEXT(compose->focused_editable));
6361 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE:
6362 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6364 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N:
6365 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6366 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6368 case COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END:
6369 gtk_stext_delete_to_line_end(GTK_STEXT(compose->focused_editable));
6376 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6378 if (GTK_IS_EDITABLE(widget))
6379 compose->focused_editable = widget;
6382 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6384 if (compose->modified == FALSE) {
6385 compose->modified = TRUE;
6386 compose_set_title(compose);
6390 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6393 gtk_stext_set_point(GTK_STEXT(widget),
6394 gtk_editable_get_position(GTK_EDITABLE(widget)));
6398 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6401 gtk_stext_set_point(GTK_STEXT(widget),
6402 gtk_editable_get_position(GTK_EDITABLE(widget)));
6406 #if 0 /* NEW COMPOSE GUI */
6407 static void compose_toggle_to_cb(gpointer data, guint action,
6410 Compose *compose = (Compose *)data;
6412 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6413 gtk_widget_show(compose->to_hbox);
6414 gtk_widget_show(compose->to_entry);
6415 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6416 compose->use_to = TRUE;
6418 gtk_widget_hide(compose->to_hbox);
6419 gtk_widget_hide(compose->to_entry);
6420 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6421 gtk_widget_queue_resize(compose->table_vbox);
6422 compose->use_to = FALSE;
6425 if (addressbook_get_target_compose() == compose)
6426 addressbook_set_target_compose(compose);
6429 static void compose_toggle_cc_cb(gpointer data, guint action,
6432 Compose *compose = (Compose *)data;
6434 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6435 gtk_widget_show(compose->cc_hbox);
6436 gtk_widget_show(compose->cc_entry);
6437 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6438 compose->use_cc = TRUE;
6440 gtk_widget_hide(compose->cc_hbox);
6441 gtk_widget_hide(compose->cc_entry);
6442 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6443 gtk_widget_queue_resize(compose->table_vbox);
6444 compose->use_cc = FALSE;
6447 if (addressbook_get_target_compose() == compose)
6448 addressbook_set_target_compose(compose);
6451 static void compose_toggle_bcc_cb(gpointer data, guint action,
6454 Compose *compose = (Compose *)data;
6456 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6457 gtk_widget_show(compose->bcc_hbox);
6458 gtk_widget_show(compose->bcc_entry);
6459 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6460 compose->use_bcc = TRUE;
6462 gtk_widget_hide(compose->bcc_hbox);
6463 gtk_widget_hide(compose->bcc_entry);
6464 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6465 gtk_widget_queue_resize(compose->table_vbox);
6466 compose->use_bcc = FALSE;
6469 if (addressbook_get_target_compose() == compose)
6470 addressbook_set_target_compose(compose);
6473 static void compose_toggle_replyto_cb(gpointer data, guint action,
6476 Compose *compose = (Compose *)data;
6478 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6479 gtk_widget_show(compose->reply_hbox);
6480 gtk_widget_show(compose->reply_entry);
6481 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6482 compose->use_replyto = TRUE;
6484 gtk_widget_hide(compose->reply_hbox);
6485 gtk_widget_hide(compose->reply_entry);
6486 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6487 gtk_widget_queue_resize(compose->table_vbox);
6488 compose->use_replyto = FALSE;
6492 static void compose_toggle_followupto_cb(gpointer data, guint action,
6495 Compose *compose = (Compose *)data;
6497 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6498 gtk_widget_show(compose->followup_hbox);
6499 gtk_widget_show(compose->followup_entry);
6500 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6501 compose->use_followupto = TRUE;
6503 gtk_widget_hide(compose->followup_hbox);
6504 gtk_widget_hide(compose->followup_entry);
6505 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6506 gtk_widget_queue_resize(compose->table_vbox);
6507 compose->use_followupto = FALSE;
6511 static void compose_toggle_attach_cb(gpointer data, guint action,
6514 Compose *compose = (Compose *)data;
6516 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6517 gtk_widget_ref(compose->edit_vbox);
6519 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6520 compose->edit_vbox);
6521 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6522 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6524 gtk_widget_show(compose->paned);
6526 gtk_widget_unref(compose->edit_vbox);
6527 gtk_widget_unref(compose->paned);
6529 compose->use_attach = TRUE;
6531 gtk_widget_ref(compose->paned);
6532 gtk_widget_ref(compose->edit_vbox);
6534 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6536 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6537 compose->edit_vbox);
6538 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6539 compose->edit_vbox, TRUE, TRUE, 0);
6541 gtk_widget_unref(compose->edit_vbox);
6543 compose->use_attach = FALSE;
6549 static void compose_toggle_sign_cb(gpointer data, guint action,
6552 Compose *compose = (Compose *)data;
6554 if (GTK_CHECK_MENU_ITEM(widget)->active)
6555 compose->use_signing = TRUE;
6557 compose->use_signing = FALSE;
6560 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6563 Compose *compose = (Compose *)data;
6565 if (GTK_CHECK_MENU_ITEM(widget)->active)
6566 compose->use_encryption = TRUE;
6568 compose->use_encryption = FALSE;
6570 #endif /* USE_GPGME */
6572 static void compose_toggle_ruler_cb(gpointer data, guint action,
6575 Compose *compose = (Compose *)data;
6577 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6578 gtk_widget_show(compose->ruler_hbox);
6579 prefs_common.show_ruler = TRUE;
6581 gtk_widget_hide(compose->ruler_hbox);
6582 gtk_widget_queue_resize(compose->edit_vbox);
6583 prefs_common.show_ruler = FALSE;
6587 static void compose_attach_drag_received_cb (GtkWidget *widget,
6588 GdkDragContext *drag_context,
6591 GtkSelectionData *data,
6596 Compose *compose = (Compose *)user_data;
6599 list = uri_list_extract_filenames((const gchar *)data->data);
6600 for (tmp = list; tmp != NULL; tmp = tmp->next)
6601 compose_attach_append
6602 (compose, (const gchar *)tmp->data,
6603 (const gchar *)tmp->data, NULL);
6604 if (list) compose_changed_cb(NULL, compose);
6605 list_free_strings(list);
6609 static void compose_insert_drag_received_cb (GtkWidget *widget,
6610 GdkDragContext *drag_context,
6613 GtkSelectionData *data,
6618 Compose *compose = (Compose *)user_data;
6621 list = uri_list_extract_filenames((const gchar *)data->data);
6622 for (tmp = list; tmp != NULL; tmp = tmp->next)
6623 compose_insert_file(compose, (const gchar *)tmp->data);
6624 list_free_strings(list);
6628 #if 0 /* NEW COMPOSE GUI */
6629 static void to_activated(GtkWidget *widget, Compose *compose)
6631 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6632 gtk_widget_grab_focus(compose->newsgroups_entry);
6634 gtk_widget_grab_focus(compose->subject_entry);
6637 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6639 gtk_widget_grab_focus(compose->subject_entry);
6642 static void subject_activated(GtkWidget *widget, Compose *compose)
6644 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6645 gtk_widget_grab_focus(compose->cc_entry);
6646 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6647 gtk_widget_grab_focus(compose->bcc_entry);
6648 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6649 gtk_widget_grab_focus(compose->reply_entry);
6650 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6651 gtk_widget_grab_focus(compose->followup_entry);
6653 gtk_widget_grab_focus(compose->text);
6656 static void cc_activated(GtkWidget *widget, Compose *compose)
6658 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6659 gtk_widget_grab_focus(compose->bcc_entry);
6660 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6661 gtk_widget_grab_focus(compose->reply_entry);
6662 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6663 gtk_widget_grab_focus(compose->followup_entry);
6665 gtk_widget_grab_focus(compose->text);
6668 static void bcc_activated(GtkWidget *widget, Compose *compose)
6670 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6671 gtk_widget_grab_focus(compose->reply_entry);
6672 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6673 gtk_widget_grab_focus(compose->followup_entry);
6675 gtk_widget_grab_focus(compose->text);
6678 static void replyto_activated(GtkWidget *widget, Compose *compose)
6680 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6681 gtk_widget_grab_focus(compose->followup_entry);
6683 gtk_widget_grab_focus(compose->text);
6686 static void followupto_activated(GtkWidget *widget, Compose *compose)
6688 gtk_widget_grab_focus(compose->text);
6692 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6695 Compose *compose = (Compose *)data;
6697 if (GTK_CHECK_MENU_ITEM(widget)->active)
6698 compose->return_receipt = TRUE;
6700 compose->return_receipt = FALSE;
6703 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6705 ComposeHeaderEntry *headerentry)
6707 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6708 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6709 !(event->state & GDK_MODIFIER_MASK) &&
6710 (event->keyval == GDK_BackSpace) &&
6711 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6712 gtk_container_remove
6713 (GTK_CONTAINER(headerentry->compose->header_table),
6714 headerentry->combo);
6715 gtk_container_remove
6716 (GTK_CONTAINER(headerentry->compose->header_table),
6717 headerentry->entry);
6718 headerentry->compose->header_list =
6719 g_slist_remove(headerentry->compose->header_list,
6721 g_free(headerentry);
6722 } else if (event->keyval == GDK_Tab) {
6723 if (headerentry->compose->header_last == headerentry) {
6724 /* Override default next focus, and give it to subject_entry
6725 * instead of notebook tabs
6727 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6728 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6734 void compose_headerentry_changed_cb(GtkWidget *entry,
6735 ComposeHeaderEntry *headerentry)
6737 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6738 headerentry->compose->header_list =
6739 g_slist_append(headerentry->compose->header_list,
6741 compose_create_header_entry(headerentry->compose);
6742 gtk_signal_disconnect_by_func
6744 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6746 /* Automatically scroll down */
6747 compose_show_first_last_header(headerentry->compose, FALSE);
6752 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6754 GtkAdjustment *vadj;
6756 g_return_if_fail(compose);
6757 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6758 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6760 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6761 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6764 static void text_activated(GtkWidget *widget, Compose *compose)
6766 compose_send_control_enter(compose);
6769 static void text_inserted(GtkWidget *widget, const gchar *text,
6770 gint length, gint *position, Compose *compose)
6772 GtkEditable *editable = GTK_EDITABLE(widget);
6774 gtk_signal_handler_block_by_func(GTK_OBJECT(widget),
6775 GTK_SIGNAL_FUNC(text_inserted),
6777 if (compose->paste_as_quotation) {
6782 new_text = g_strndup(text, length);
6783 if (prefs_common.quotemark && *prefs_common.quotemark)
6784 qmark = prefs_common.quotemark;
6787 gtk_stext_set_point(GTK_STEXT(widget), *position);
6788 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
6789 pos = gtk_stext_get_point(GTK_STEXT(widget));
6790 gtk_editable_set_position(editable, pos);
6794 gtk_editable_insert_text(editable, text, length, position);
6796 if (prefs_common.autowrap)
6797 compose_wrap_line_all(compose);
6799 gtk_signal_handler_unblock_by_func(GTK_OBJECT(widget),
6800 GTK_SIGNAL_FUNC(text_inserted),
6802 gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
6805 static gboolean compose_send_control_enter(Compose *compose)
6809 GtkItemFactory *ifactory;
6810 GtkAccelEntry *accel;
6811 GtkWidget *send_menu;
6813 GdkModifierType ignored_mods =
6814 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
6815 GDK_MOD4_MASK | GDK_MOD5_MASK);
6817 ev = gtk_get_current_event();
6818 if (ev->type != GDK_KEY_PRESS) return FALSE;
6820 kev = (GdkEventKey *)ev;
6821 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6824 ifactory = gtk_item_factory_from_widget(compose->menubar);
6825 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6826 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6827 accel = (GtkAccelEntry *)list->data;
6828 if (accel->accelerator_key == kev->keyval &&
6829 (accel->accelerator_mods & ~ignored_mods) ==
6830 (kev->state & ~ignored_mods)) {
6831 compose_send_cb(compose, 0, NULL);
6839 static void compose_check_all(Compose *compose)
6841 if (compose->gtkpspell)
6842 gtkpspell_check_all(compose->gtkpspell);
6845 static void compose_highlight_all(Compose *compose)
6847 if (compose->gtkpspell)
6848 gtkpspell_highlight_all(compose->gtkpspell);
6851 static void compose_check_backwards(Compose *compose)
6853 if (compose->gtkpspell)
6854 gtkpspell_check_backwards(compose->gtkpspell);
6856 GtkItemFactory *ifactory;
6857 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6858 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6859 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6863 static void compose_check_forwards_go(Compose *compose)
6865 if (compose->gtkpspell)
6866 gtkpspell_check_forwards_go(compose->gtkpspell);
6868 GtkItemFactory *ifactory;
6869 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6870 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6871 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6876 static void set_toolbar_style(Compose *compose)
6878 switch (prefs_common.toolbar_style) {
6880 gtk_widget_hide(compose->handlebox);
6883 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6887 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6891 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6896 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
6897 gtk_widget_show(compose->handlebox);
6898 gtk_widget_queue_resize(compose->handlebox);