2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
31 #include <gtk/gtkitemfactory.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkclist.h>
36 #include <gtk/gtkctree.h>
37 #include <gtk/gtkvpaned.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkeditable.h>
40 #include <gtk/gtkwindow.h>
41 #include <gtk/gtksignal.h>
42 #include <gtk/gtkvbox.h>
43 #include <gtk/gtkcontainer.h>
44 #include <gtk/gtkhandlebox.h>
45 #include <gtk/gtktoolbar.h>
46 #include <gtk/gtktable.h>
47 #include <gtk/gtkhbox.h>
48 #include <gtk/gtklabel.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtkthemes.h>
51 #include <gtk/gtkdnd.h>
56 #include <sys/types.h>
60 /* #include <sys/utsname.h> */
66 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
73 #include "mainwindow.h"
76 #include "addressbook.h"
77 #include "folderview.h"
80 #include "stock_pixmap.h"
84 #include "customheader.h"
85 #include "prefs_common.h"
86 #include "prefs_account.h"
89 #include "procheader.h"
91 #include "statusbar.h"
98 #include "alertpanel.h"
99 #include "manage_window.h"
100 #include "gtkshruler.h"
102 #include "addr_compl.h"
103 #include "quote_fmt.h"
104 #include "template.h"
106 #include "foldersel.h"
107 #include "prefs_actions.h"
110 # include "rfc2015.h"
120 #define N_ATTACH_COLS 3
124 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
125 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
126 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
127 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
128 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
129 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
130 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
131 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
132 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
133 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
134 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
135 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
136 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
137 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
138 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
139 } ComposeCallGtkSTextAction;
141 #define B64_LINE_SIZE 57
142 #define B64_BUFFSIZE 77
144 #define MAX_REFERENCES_LEN 999
146 static GdkColor quote_color = {0, 0, 0, 0xbfff};
148 static GList *compose_list = NULL;
150 Compose *compose_generic_new (PrefsAccount *account,
154 static Compose *compose_create (PrefsAccount *account,
156 static void compose_toolbar_create (Compose *compose,
157 GtkWidget *container);
158 static GtkWidget *compose_account_option_menu_create
160 static void compose_set_template_menu (Compose *compose);
161 static void compose_template_apply (Compose *compose,
164 static void compose_destroy (Compose *compose);
166 static void compose_entries_set (Compose *compose,
167 const gchar *mailto);
168 static gint compose_parse_header (Compose *compose,
170 static gchar *compose_parse_references (const gchar *ref,
173 static gchar *compose_quote_fmt (Compose *compose,
179 static void compose_reply_set_entry (Compose *compose,
184 followup_and_reply_to);
185 static void compose_reedit_set_entry (Compose *compose,
187 static void compose_insert_sig (Compose *compose);
188 static void compose_insert_file (Compose *compose,
190 static void compose_attach_append (Compose *compose,
193 const gchar *content_type);
194 static void compose_attach_parts (Compose *compose,
196 static void compose_wrap_line (Compose *compose);
197 static void compose_wrap_line_all (Compose *compose);
198 static void compose_set_title (Compose *compose);
200 static PrefsAccount *compose_current_mail_account(void);
201 /* static gint compose_send (Compose *compose); */
202 static gboolean compose_check_for_valid_recipient
204 static gboolean compose_check_entries (Compose *compose);
205 static gint compose_write_to_file (Compose *compose,
208 static gint compose_write_body_to_file (Compose *compose,
210 static gint compose_remove_reedit_target (Compose *compose);
211 static gint compose_queue (Compose *compose,
214 static void compose_write_attach (Compose *compose,
216 static gint compose_write_headers (Compose *compose,
218 const gchar *charset,
219 EncodingType encoding,
222 static void compose_convert_header (gchar *dest,
226 static void compose_generate_msgid (Compose *compose,
230 static void compose_attach_info_free (AttachInfo *ainfo);
231 static void compose_attach_remove_selected (Compose *compose);
233 static void compose_attach_property (Compose *compose);
234 static void compose_attach_property_create (gboolean *cancelled);
235 static void attach_property_ok (GtkWidget *widget,
236 gboolean *cancelled);
237 static void attach_property_cancel (GtkWidget *widget,
238 gboolean *cancelled);
239 static gint attach_property_delete_event (GtkWidget *widget,
241 gboolean *cancelled);
242 static void attach_property_key_pressed (GtkWidget *widget,
244 gboolean *cancelled);
246 static void compose_exec_ext_editor (Compose *compose);
247 static gint compose_exec_ext_editor_real (const gchar *file);
248 static gboolean compose_ext_editor_kill (Compose *compose);
249 static void compose_input_cb (gpointer data,
251 GdkInputCondition condition);
252 static void compose_set_ext_editor_sensitive (Compose *compose,
255 static void compose_undo_state_changed (UndoMain *undostruct,
260 static gint calc_cursor_xpos (GtkSText *text,
264 static void compose_create_header_entry (Compose *compose);
265 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
267 /* callback functions */
269 static gboolean compose_edit_size_alloc (GtkEditable *widget,
270 GtkAllocation *allocation,
271 GtkSHRuler *shruler);
273 static void toolbar_send_cb (GtkWidget *widget,
275 static void toolbar_send_later_cb (GtkWidget *widget,
277 static void toolbar_draft_cb (GtkWidget *widget,
279 static void toolbar_insert_cb (GtkWidget *widget,
281 static void toolbar_attach_cb (GtkWidget *widget,
283 static void toolbar_sig_cb (GtkWidget *widget,
285 static void toolbar_ext_editor_cb (GtkWidget *widget,
287 static void toolbar_linewrap_cb (GtkWidget *widget,
289 static void toolbar_address_cb (GtkWidget *widget,
292 static void select_account (Compose *compose,
295 static void account_activated (GtkMenuItem *menuitem,
298 static void attach_selected (GtkCList *clist,
303 static void attach_button_pressed (GtkWidget *widget,
304 GdkEventButton *event,
306 static void attach_key_pressed (GtkWidget *widget,
310 static void compose_send_cb (gpointer data,
313 static void compose_send_later_cb (gpointer data,
317 static void compose_draft_cb (gpointer data,
321 static void compose_attach_cb (gpointer data,
324 static void compose_insert_file_cb (gpointer data,
328 static void compose_close_cb (gpointer data,
332 static void compose_address_cb (gpointer data,
335 static void compose_template_activate_cb(GtkWidget *widget,
338 static void compose_ext_editor_cb (gpointer data,
342 static gint compose_delete_cb (GtkWidget *widget,
345 static void compose_destroy_cb (GtkWidget *widget,
348 static void compose_undo_cb (Compose *compose);
349 static void compose_redo_cb (Compose *compose);
350 static void compose_cut_cb (Compose *compose);
351 static void compose_copy_cb (Compose *compose);
352 static void compose_paste_cb (Compose *compose);
353 static void compose_allsel_cb (Compose *compose);
355 static void compose_gtk_stext_action_cb (Compose *compose,
356 ComposeCallGtkSTextAction action);
358 static void compose_grab_focus_cb (GtkWidget *widget,
361 static void compose_changed_cb (GtkEditable *editable,
363 static void compose_button_press_cb (GtkWidget *widget,
364 GdkEventButton *event,
367 static void compose_key_press_cb (GtkWidget *widget,
373 static void compose_toggle_to_cb (gpointer data,
376 static void compose_toggle_cc_cb (gpointer data,
379 static void compose_toggle_bcc_cb (gpointer data,
382 static void compose_toggle_replyto_cb (gpointer data,
385 static void compose_toggle_followupto_cb(gpointer data,
388 static void compose_toggle_attach_cb (gpointer data,
392 static void compose_toggle_ruler_cb (gpointer data,
396 static void compose_toggle_sign_cb (gpointer data,
399 static void compose_toggle_encrypt_cb (gpointer data,
403 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
406 static void compose_attach_drag_received_cb (GtkWidget *widget,
407 GdkDragContext *drag_context,
410 GtkSelectionData *data,
414 static void compose_insert_drag_received_cb (GtkWidget *widget,
415 GdkDragContext *drag_context,
418 GtkSelectionData *data,
424 static void to_activated (GtkWidget *widget,
426 static void newsgroups_activated (GtkWidget *widget,
428 static void subject_activated (GtkWidget *widget,
430 static void cc_activated (GtkWidget *widget,
432 static void bcc_activated (GtkWidget *widget,
434 static void replyto_activated (GtkWidget *widget,
436 static void followupto_activated (GtkWidget *widget,
440 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
442 gboolean ignore_replyto,
443 gboolean followup_and_reply_to,
446 void compose_headerentry_changed_cb (GtkWidget *entry,
447 ComposeHeaderEntry *headerentry);
448 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
450 ComposeHeaderEntry *headerentry);
452 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
455 static void compose_check_all (Compose *compose);
456 static void compose_highlight_all (Compose *compose);
457 static void compose_check_backwards (Compose *compose);
458 static void compose_check_forwards_go (Compose *compose);
461 static gboolean compose_send_control_enter (Compose *compose);
462 static void text_activated (GtkWidget *widget,
465 static GtkItemFactoryEntry compose_popup_entries[] =
467 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
468 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
469 {N_("/---"), NULL, NULL, 0, "<Separator>"},
470 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
473 static GtkItemFactoryEntry compose_entries[] =
475 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
476 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
477 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
478 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
479 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
480 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
482 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
483 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
484 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
485 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
486 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
487 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
488 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
489 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
490 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
491 {N_("/_Edit/A_dvanced/Move a character backward"),
493 compose_gtk_stext_action_cb,
494 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
496 {N_("/_Edit/A_dvanced/Move a character forward"),
498 compose_gtk_stext_action_cb,
499 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
501 {N_("/_Edit/A_dvanced/Move a word backward"),
503 compose_gtk_stext_action_cb,
504 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
506 {N_("/_Edit/A_dvanced/Move a word forward"),
508 compose_gtk_stext_action_cb,
509 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
511 {N_("/_Edit/A_dvanced/Move to beginning of line"),
512 NULL, /* "<control>A" */
513 compose_gtk_stext_action_cb,
514 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
516 {N_("/_Edit/A_dvanced/Move to end of line"),
518 compose_gtk_stext_action_cb,
519 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
521 {N_("/_Edit/A_dvanced/Move to previous line"),
523 compose_gtk_stext_action_cb,
524 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
526 {N_("/_Edit/A_dvanced/Move to next line"),
528 compose_gtk_stext_action_cb,
529 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
531 {N_("/_Edit/A_dvanced/Delete a character backward"),
533 compose_gtk_stext_action_cb,
534 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
536 {N_("/_Edit/A_dvanced/Delete a character forward"),
538 compose_gtk_stext_action_cb,
539 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
541 {N_("/_Edit/A_dvanced/Delete a word backward"),
542 NULL, /* "<control>W" */
543 compose_gtk_stext_action_cb,
544 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
546 {N_("/_Edit/A_dvanced/Delete a word forward"),
547 NULL, /* "<alt>D", */
548 compose_gtk_stext_action_cb,
549 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
551 {N_("/_Edit/A_dvanced/Delete line"),
553 compose_gtk_stext_action_cb,
554 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
556 {N_("/_Edit/A_dvanced/Delete entire line"),
558 compose_gtk_stext_action_cb,
559 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
561 {N_("/_Edit/A_dvanced/Delete to end of line"),
563 compose_gtk_stext_action_cb,
564 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
566 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
567 {N_("/_Edit/_Wrap current paragraph"),
568 "<control>L", compose_wrap_line, 0, NULL},
569 {N_("/_Edit/Wrap all long _lines"),
570 "<control><alt>L", compose_wrap_line_all, 0, NULL},
571 {N_("/_Edit/Edit with e_xternal editor"),
572 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
574 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
575 {N_("/_Spelling/_Check all or check selection"),
576 NULL, compose_check_all, 0, NULL},
577 {N_("/_Spelling/_Highlight all misspelled words"),
578 NULL, compose_highlight_all, 0, NULL},
579 {N_("/_Spelling/Check _backwards misspelled word"),
580 NULL, compose_check_backwards , 0, NULL},
581 {N_("/_Spelling/_Forward to next misspelled word"),
582 NULL, compose_check_forwards_go, 0, NULL},
583 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
584 {N_("/_Spelling/_Spelling Configuration"),
585 NULL, NULL, 0, "<Branch>"},
587 #if 0 /* NEW COMPOSE GUI */
588 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
589 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
590 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
591 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
592 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
593 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
594 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
595 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
596 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
597 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
598 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
600 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
601 {N_("/_Message/_Send"), "<control>Return",
602 compose_send_cb, 0, NULL},
603 {N_("/_Message/Send _later"), "<shift><control>S",
604 compose_send_later_cb, 0, NULL},
605 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
606 {N_("/_Message/Save to _draft folder"),
607 "<shift><control>D", compose_draft_cb, 0, NULL},
608 {N_("/_Message/Save and _keep editing"),
609 "<control>S", compose_draft_cb, 1, NULL},
610 #if 0 /* NEW COMPOSE GUI */
611 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
612 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
613 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
614 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
615 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
616 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
617 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
618 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
619 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
622 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
623 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
624 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
625 #endif /* USE_GPGME */
626 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
627 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
628 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
629 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
630 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
631 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
632 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
633 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
634 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
637 static GtkTargetEntry compose_mime_types[] =
639 {"text/uri-list", 0, 0}
642 Compose *compose_new(PrefsAccount *account)
644 return compose_generic_new(account, NULL, NULL);
647 Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
651 GtkItemFactory *ifactory;
653 c = compose_generic_new(account, NULL, NULL);
655 filename = procmsg_get_message_file(msginfo);
656 if (filename == NULL)
659 c->bounce_filename = filename;
661 if (msginfo->subject)
662 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
664 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
666 compose_quote_fmt(c, msginfo, "%M", NULL, NULL);
667 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
669 ifactory = gtk_item_factory_from_widget(c->popupmenu);
670 menu_set_sensitive(ifactory, "/Add...", FALSE);
671 menu_set_sensitive(ifactory, "/Remove", FALSE);
672 menu_set_sensitive(ifactory, "/Property...", FALSE);
674 ifactory = gtk_item_factory_from_widget(c->menubar);
675 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
676 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
677 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
678 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
679 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
680 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
681 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
682 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
684 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
685 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
687 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
688 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
690 gtk_widget_set_sensitive(c->insert_btn, FALSE);
691 gtk_widget_set_sensitive(c->attach_btn, FALSE);
692 gtk_widget_set_sensitive(c->sig_btn, FALSE);
693 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
694 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
699 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
701 return compose_generic_new(account, mailto, NULL);
704 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
706 return compose_generic_new(account, NULL, item);
709 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
713 if (item && item->prefs && item->prefs->enable_default_account)
714 account = account_find_from_id(item->prefs->default_account);
716 if (!account) account = cur_account;
717 g_return_val_if_fail(account != NULL, NULL);
719 compose = compose_create(account, COMPOSE_NEW);
720 compose->replyinfo = NULL;
722 if (prefs_common.auto_sig)
723 compose_insert_sig(compose);
724 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
725 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
727 if (account->protocol != A_NNTP) {
729 compose_entries_set(compose, mailto);
731 } else if(item && item->prefs->enable_default_to) {
732 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
734 if (item && item->ret_rcpt) {
735 GtkItemFactory *ifactory;
737 ifactory = gtk_item_factory_from_widget(compose->menubar);
738 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
742 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
745 compose_show_first_last_header(compose, TRUE);
747 /* Set save folder */
748 if(item && item->prefs && item->prefs->save_copy_to_folder) {
749 gchar *folderidentifier;
751 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
752 folderidentifier = folder_item_get_identifier(item);
753 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
754 g_free(folderidentifier);
757 gtk_widget_grab_focus(compose->header_last->entry);
759 if (prefs_common.auto_exteditor)
760 compose_exec_ext_editor(compose);
765 #define CHANGE_FLAGS(msginfo) \
767 if (msginfo->folder->folder->change_flags != NULL) \
768 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
774 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
775 const gchar *followupto, gchar * to)
779 if (!account) account = cur_account;
780 g_return_val_if_fail(account != NULL, NULL);
781 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
783 compose = compose_create(account, COMPOSE_NEW);
785 if (prefs_common.auto_sig)
786 compose_insert_sig(compose);
787 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
788 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
790 compose_entry_append(compose, to, COMPOSE_TO);
791 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
792 gtk_widget_grab_focus(compose->subject_entry);
798 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
799 gboolean ignore_replyto, const gchar *body)
801 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE,
805 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
807 gboolean ignore_replyto,
810 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE,
814 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
816 gboolean ignore_replyto,
817 gboolean followup_and_reply_to,
821 PrefsAccount *account;
822 PrefsAccount *reply_account;
825 g_return_if_fail(msginfo != NULL);
826 g_return_if_fail(msginfo->folder != NULL);
829 /* select the account set in folderitem's property (if enabled) */
830 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
831 account = account_find_from_id(msginfo->folder->prefs->default_account);
833 /* select the account for the whole folder (IMAP / NNTP) */
835 /* FIXME: this is not right, because folder may be nested. we should
836 * ascend the tree until we find a parent with proper account
838 account = msginfo->folder->folder->account;
840 /* select account by to: and cc: header if enabled */
841 if (prefs_common.reply_account_autosel) {
842 if (!account && msginfo->to) {
844 Xstrdup_a(to, msginfo->to, return);
846 account = account_find_from_address(to);
850 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
852 account = account_find_from_address(cc);
857 /* select current account */
858 if (!account) account = cur_account;
859 g_return_if_fail(account != NULL);
861 if (ignore_replyto && account->protocol == A_NNTP &&
862 !followup_and_reply_to) {
864 account_find_from_address(account->address);
866 reply_account = compose_current_mail_account();
870 reply_account = account;
872 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
873 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
874 if (MSG_IS_IMAP(msginfo->flags))
875 imap_msg_set_perm_flags(msginfo, MSG_REPLIED);
876 CHANGE_FLAGS(msginfo);
878 compose = compose_create(account, COMPOSE_REPLY);
879 compose->replyinfo = procmsg_msginfo_copy(msginfo);
881 #if 0 /* NEW COMPOSE GUI */
882 if (followup_and_reply_to) {
883 gtk_widget_show(compose->to_hbox);
884 gtk_widget_show(compose->to_entry);
885 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
886 compose->use_to = TRUE;
889 if (msginfo->folder && msginfo->folder->ret_rcpt) {
890 GtkItemFactory *ifactory;
892 ifactory = gtk_item_factory_from_widget(compose->menubar);
893 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
896 /* Set save folder */
897 if(msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
898 gchar *folderidentifier;
900 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
901 folderidentifier = folder_item_get_identifier(msginfo->folder);
902 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
903 g_free(folderidentifier);
906 if (compose_parse_header(compose, msginfo) < 0) return;
907 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
908 followup_and_reply_to);
909 compose_show_first_last_header(compose, TRUE);
911 text = GTK_STEXT(compose->text);
912 gtk_stext_freeze(text);
918 if (prefs_common.quotemark && *prefs_common.quotemark)
919 qmark = prefs_common.quotemark;
923 quote_str = compose_quote_fmt(compose, msginfo,
924 prefs_common.quotefmt,
928 if (prefs_common.auto_sig)
929 compose_insert_sig(compose);
931 if (quote && prefs_common.linewrap_quote)
932 compose_wrap_line_all(compose);
934 gtk_editable_set_position(GTK_EDITABLE(text), 0);
935 gtk_stext_set_point(text, 0);
937 gtk_stext_thaw(text);
938 gtk_widget_grab_focus(compose->text);
940 if (prefs_common.auto_exteditor)
941 compose_exec_ext_editor(compose);
944 static void set_toolbar_style(Compose *compose);
946 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
951 g_return_val_if_fail(mimeinfo != NULL, NULL);
953 base = mimeinfo->filename ? mimeinfo->filename
954 : mimeinfo->name ? mimeinfo->name : NULL;
956 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
957 filename = g_strdup_printf("%s%smimetmp.%08x.html",
964 base = base ? base : "";
965 base = g_basename(base);
967 filename = g_strdup_printf("%s%smimetmp.%08x",
975 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
981 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
985 if (!partinfo) return NULL;
987 filename = procmime_get_file_name(partinfo);
989 if (procmime_get_part(filename, source, partinfo) < 0)
991 (_("Can't get the part of multipart message."));
998 #define INSERT_FW_HEADER(var, hdr) \
999 if (msginfo->var && *msginfo->var) { \
1000 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1001 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1002 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1005 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1006 gboolean as_attach, const gchar *body)
1009 /* PrefsAccount *account; */
1012 g_return_val_if_fail(msginfo != NULL, NULL);
1013 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1015 account = msginfo->folder->folder->account;
1016 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1018 Xstrdup_a(to, msginfo->to, return NULL);
1019 extract_address(to);
1020 account = account_find_from_address(to);
1023 if(!account && prefs_common.forward_account_autosel) {
1025 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1026 extract_address(cc);
1027 account = account_find_from_address(cc);
1031 if (account == NULL) {
1032 account = cur_account;
1034 account = msginfo->folder->folder->account;
1035 if (!account) account = cur_account;
1038 g_return_val_if_fail(account != NULL, NULL);
1040 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1041 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1042 if (MSG_IS_IMAP(msginfo->flags))
1043 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1044 CHANGE_FLAGS(msginfo);
1046 compose = compose_create(account, COMPOSE_FORWARD);
1048 if (msginfo->subject && *msginfo->subject) {
1049 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1050 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1054 text = GTK_STEXT(compose->text);
1055 gtk_stext_freeze(text);
1061 msgfile = procmsg_get_message_file_path(msginfo);
1062 if (!is_file_exist(msgfile))
1063 g_warning(_("%s: file not exist\n"), msgfile);
1065 compose_attach_append(compose, msgfile, msgfile,
1073 if (prefs_common.fw_quotemark &&
1074 *prefs_common.fw_quotemark)
1075 qmark = prefs_common.fw_quotemark;
1079 quote_str = compose_quote_fmt(compose, msginfo,
1080 prefs_common.fw_quotefmt,
1082 compose_attach_parts(compose, msginfo);
1085 if (prefs_common.auto_sig)
1086 compose_insert_sig(compose);
1088 if (prefs_common.linewrap_quote)
1089 compose_wrap_line_all(compose);
1091 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1092 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1094 gtk_stext_thaw(text);
1095 #if 0 /* NEW COMPOSE GUI */
1096 if (account->protocol != A_NNTP)
1097 gtk_widget_grab_focus(compose->to_entry);
1099 gtk_widget_grab_focus(compose->newsgroups_entry);
1101 gtk_widget_grab_focus(compose->header_last->entry);
1103 if (prefs_common.auto_exteditor)
1104 compose_exec_ext_editor(compose);
1109 #undef INSERT_FW_HEADER
1111 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1118 g_return_val_if_fail(msginfo_list != NULL, NULL);
1120 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1121 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1125 if (account == NULL) {
1126 account = cur_account;
1128 account = msginfo->folder->folder->account;
1129 if (!account) account = cur_account;
1132 g_return_val_if_fail(account != NULL, NULL);
1134 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1135 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1136 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1137 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1140 compose = compose_create(account, COMPOSE_FORWARD);
1142 text = GTK_STEXT(compose->text);
1143 gtk_stext_freeze(text);
1145 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1146 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1147 if (!is_file_exist(msgfile))
1148 g_warning(_("%s: file not exist\n"), msgfile);
1150 compose_attach_append(compose, msgfile, msgfile,
1155 if (prefs_common.auto_sig)
1156 compose_insert_sig(compose);
1158 if (prefs_common.linewrap_quote)
1159 compose_wrap_line_all(compose);
1161 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1162 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1164 gtk_stext_thaw(text);
1165 #if 0 /* NEW COMPOSE GUI */
1166 if (account->protocol != A_NNTP)
1167 gtk_widget_grab_focus(compose->to_entry);
1169 gtk_widget_grab_focus(compose->newsgroups_entry);
1175 void compose_reedit(MsgInfo *msginfo)
1178 PrefsAccount *account = NULL;
1181 gchar buf[BUFFSIZE];
1183 g_return_if_fail(msginfo != NULL);
1184 g_return_if_fail(msginfo->folder != NULL);
1186 if (msginfo->folder->stype == F_QUEUE) {
1187 gchar queueheader_buf[BUFFSIZE];
1190 /* Select Account from queue headers */
1191 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1192 sizeof(queueheader_buf), "NAID:")) {
1193 id = atoi(&queueheader_buf[5]);
1194 account = account_find_from_id(id);
1196 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1197 sizeof(queueheader_buf), "MAID:")) {
1198 id = atoi(&queueheader_buf[5]);
1199 account = account_find_from_id(id);
1201 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1202 sizeof(queueheader_buf), "S:")) {
1203 account = account_find_from_address(queueheader_buf);
1206 account = msginfo->folder->folder->account;
1208 if (!account && prefs_common.reedit_account_autosel) {
1209 gchar from[BUFFSIZE];
1210 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1211 extract_address(from);
1212 account = account_find_from_address(from);
1215 if (!account) account = cur_account;
1216 g_return_if_fail(account != NULL);
1218 compose = compose_create(account, COMPOSE_REEDIT);
1219 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1221 if (msginfo->folder->stype == F_QUEUE) {
1222 gchar queueheader_buf[BUFFSIZE];
1224 /* Set message save folder */
1225 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1228 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1229 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1230 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1234 if (compose_parse_header(compose, msginfo) < 0) return;
1235 compose_reedit_set_entry(compose, msginfo);
1237 text = GTK_STEXT(compose->text);
1238 gtk_stext_freeze(text);
1240 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1241 g_warning(_("Can't get text part\n"));
1243 while (fgets(buf, sizeof(buf), fp) != NULL)
1244 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1247 compose_attach_parts(compose, msginfo);
1249 gtk_stext_thaw(text);
1250 gtk_widget_grab_focus(compose->text);
1252 if (prefs_common.auto_exteditor)
1253 compose_exec_ext_editor(compose);
1256 GList *compose_get_compose_list(void)
1258 return compose_list;
1261 void compose_entry_append(Compose *compose, const gchar *address,
1262 ComposeEntryType type)
1268 if (!address || *address == '\0') return;
1270 #if 0 /* NEW COMPOSE GUI */
1273 entry = GTK_ENTRY(compose->cc_entry);
1276 entry = GTK_ENTRY(compose->bcc_entry);
1278 case COMPOSE_NEWSGROUPS:
1279 entry = GTK_ENTRY(compose->newsgroups_entry);
1283 entry = GTK_ENTRY(compose->to_entry);
1287 text = gtk_entry_get_text(entry);
1289 gtk_entry_append_text(entry, ", ");
1290 gtk_entry_append_text(entry, address);
1298 header = N_("Bcc:");
1300 case COMPOSE_REPLYTO:
1301 header = N_("Reply-To:");
1303 case COMPOSE_NEWSGROUPS:
1304 header = N_("Newsgroups:");
1306 case COMPOSE_FOLLOWUPTO:
1307 header = N_( "Followup-To:");
1314 header = prefs_common.trans_hdr ? gettext(header) : header;
1316 compose_add_header_entry(compose, header, (gchar *)address);
1319 static void compose_entries_set(Compose *compose, const gchar *mailto)
1321 gchar *subject = NULL;
1329 Xstrdup_a(tmp_mailto, mailto, return);
1333 p = strchr(tmp_mailto, '?');
1340 gchar *field, *value;
1357 if (*value == '\0') continue;
1359 if (!g_strcasecmp(field, "subject")) {
1360 Xalloca(subject, strlen(value) + 1, return);
1361 decode_uri(subject, value);
1362 } else if (!g_strcasecmp(field, "cc")) {
1364 } else if (!g_strcasecmp(field, "bcc")) {
1366 } else if (!g_strcasecmp(field, "body")) {
1367 Xalloca(body, strlen(value) + 1, return);
1368 decode_uri(body, value);
1373 compose_entry_append(compose, to, COMPOSE_TO);
1375 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1377 compose_entry_append(compose, cc, COMPOSE_CC);
1379 compose_entry_append(compose, bcc, COMPOSE_BCC);
1381 gtk_stext_insert(GTK_STEXT(compose->text),
1382 NULL, NULL, NULL, body, -1);
1383 gtk_stext_insert(GTK_STEXT(compose->text),
1384 NULL, NULL, NULL, "\n", 1);
1388 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1390 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1391 {"Cc:", NULL, FALSE},
1392 {"References:", NULL, FALSE},
1393 {"Bcc:", NULL, FALSE},
1394 {"Newsgroups:", NULL, FALSE},
1395 {"Followup-To:", NULL, FALSE},
1396 {"X-Mailing-List:", NULL, FALSE},
1397 {"X-BeenThere:", NULL, FALSE},
1398 {NULL, NULL, FALSE}};
1408 H_X_MAILING_LIST = 6,
1414 g_return_val_if_fail(msginfo != NULL, -1);
1416 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1417 procheader_get_header_fields(fp, hentry);
1420 if (hentry[H_REPLY_TO].body != NULL) {
1421 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1422 compose->replyto = hentry[H_REPLY_TO].body;
1423 hentry[H_REPLY_TO].body = NULL;
1425 if (hentry[H_CC].body != NULL) {
1426 conv_unmime_header_overwrite(hentry[H_CC].body);
1427 compose->cc = hentry[H_CC].body;
1428 hentry[H_CC].body = NULL;
1430 if (hentry[H_X_MAILING_LIST].body != NULL) {
1431 /* this is good enough to parse debian-devel */
1432 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1433 g_return_val_if_fail(buf != NULL, -1 );
1434 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1435 compose->mailinglist = g_strdup(buf);
1437 g_free(hentry[H_X_MAILING_LIST].body);
1438 hentry[H_X_MAILING_LIST].body = NULL ;
1440 if (hentry[H_X_BEENTHERE].body != NULL) {
1441 /* this is good enough to parse the sylpheed-claws lists */
1442 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1443 g_return_val_if_fail(buf != NULL, -1 );
1444 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1445 compose->mailinglist = g_strdup(buf);
1447 g_free(hentry[H_X_BEENTHERE].body);
1448 hentry[H_X_BEENTHERE].body = NULL ;
1450 if (hentry[H_REFERENCES].body != NULL) {
1451 if (compose->mode == COMPOSE_REEDIT)
1452 compose->references = hentry[H_REFERENCES].body;
1454 compose->references = compose_parse_references
1455 (hentry[H_REFERENCES].body, msginfo->msgid);
1456 g_free(hentry[H_REFERENCES].body);
1458 hentry[H_REFERENCES].body = NULL;
1460 if (hentry[H_BCC].body != NULL) {
1461 if (compose->mode == COMPOSE_REEDIT) {
1462 conv_unmime_header_overwrite(hentry[H_BCC].body);
1463 compose->bcc = hentry[H_BCC].body;
1465 g_free(hentry[H_BCC].body);
1466 hentry[H_BCC].body = NULL;
1468 if (hentry[H_NEWSGROUPS].body != NULL) {
1469 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1470 hentry[H_NEWSGROUPS].body = NULL;
1472 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1473 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1474 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1475 hentry[H_FOLLOWUP_TO].body = NULL;
1478 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1479 compose->inreplyto = g_strdup(msginfo->inreplyto);
1480 else if (compose->mode != COMPOSE_REEDIT &&
1481 msginfo->msgid && *msginfo->msgid) {
1482 compose->inreplyto = g_strdup(msginfo->msgid);
1484 if (!compose->references) {
1485 if (msginfo->inreplyto && *msginfo->inreplyto)
1486 compose->references =
1487 g_strdup_printf("<%s>\n\t<%s>",
1491 compose->references =
1492 g_strconcat("<", msginfo->msgid, ">",
1500 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1502 GSList *ref_id_list, *cur;
1506 ref_id_list = references_list_append(NULL, ref);
1507 if (!ref_id_list) return NULL;
1508 if (msgid && *msgid)
1509 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1514 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1515 /* "<" + Message-ID + ">" + CR+LF+TAB */
1516 len += strlen((gchar *)cur->data) + 5;
1518 if (len > MAX_REFERENCES_LEN) {
1519 /* remove second message-ID */
1520 if (ref_id_list && ref_id_list->next &&
1521 ref_id_list->next->next) {
1522 g_free(ref_id_list->next->data);
1523 ref_id_list = g_slist_remove
1524 (ref_id_list, ref_id_list->next->data);
1526 slist_free_strings(ref_id_list);
1527 g_slist_free(ref_id_list);
1534 new_ref = g_string_new("");
1535 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1536 if (new_ref->len > 0)
1537 g_string_append(new_ref, "\n\t");
1538 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1541 slist_free_strings(ref_id_list);
1542 g_slist_free(ref_id_list);
1544 new_ref_str = new_ref->str;
1545 g_string_free(new_ref, FALSE);
1550 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1551 const gchar *fmt, const gchar *qmark,
1554 GtkSText *text = GTK_STEXT(compose->text);
1555 gchar *quote_str = NULL;
1560 if (qmark != NULL) {
1561 quote_fmt_init(msginfo, NULL, NULL);
1562 quote_fmt_scan_string(qmark);
1565 buf = quote_fmt_get_buffer();
1567 alertpanel_error(_("Quote mark format error."));
1569 Xstrdup_a(quote_str, buf, return NULL)
1572 if (fmt && *fmt != '\0') {
1573 quote_fmt_init(msginfo, quote_str, body);
1574 quote_fmt_scan_string(fmt);
1577 buf = quote_fmt_get_buffer();
1579 alertpanel_error(_("Message reply/forward format error."));
1585 gtk_stext_freeze(text);
1587 for (p = buf; *p != '\0'; ) {
1588 lastp = strchr(p, '\n');
1589 len = lastp ? lastp - p + 1 : -1;
1590 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1597 gtk_stext_thaw(text);
1602 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1603 gboolean to_all, gboolean ignore_replyto,
1604 gboolean followup_and_reply_to)
1606 GSList *cc_list = NULL;
1609 gchar *replyto = NULL;
1610 GHashTable *to_table;
1612 g_return_if_fail(compose->account != NULL);
1613 g_return_if_fail(msginfo != NULL);
1615 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1616 compose_entry_append(compose,
1617 ((compose->replyto && !ignore_replyto)
1619 : (compose->mailinglist && !ignore_replyto)
1620 ? compose->mailinglist
1621 : msginfo->from ? msginfo->from : ""),
1624 if (compose->account->protocol == A_NNTP) {
1626 compose_entry_append
1627 (compose, msginfo->from ? msginfo->from : "",
1630 compose_entry_append
1632 compose->followup_to ? compose->followup_to
1633 : compose->newsgroups ? compose->newsgroups
1635 COMPOSE_NEWSGROUPS);
1638 if (msginfo->subject && *msginfo->subject) {
1639 gchar *buf, *buf2, *p;
1641 buf = g_strdup(msginfo->subject);
1642 while (!strncasecmp(buf, "Re:", 3)) {
1644 while (isspace(*p)) p++;
1645 memmove(buf, p, strlen(p) + 1);
1648 buf2 = g_strdup_printf("Re: %s", buf);
1649 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1653 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1655 if (!to_all || compose->account->protocol == A_NNTP) return;
1657 if (compose->replyto) {
1658 Xstrdup_a(replyto, compose->replyto, return);
1659 extract_address(replyto);
1661 if (msginfo->from) {
1662 Xstrdup_a(from, msginfo->from, return);
1663 extract_address(from);
1666 if (compose->mailinglist && from) {
1667 cc_list = address_list_append(cc_list, from);
1670 if (replyto && from)
1671 cc_list = address_list_append(cc_list, from);
1673 if (!compose->mailinglist)
1674 cc_list = address_list_append(cc_list, msginfo->to);
1676 cc_list = address_list_append(cc_list, compose->cc);
1678 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1680 g_hash_table_insert(to_table, replyto, GINT_TO_POINTER(1));
1681 if (compose->account)
1682 g_hash_table_insert(to_table, compose->account->address,
1683 GINT_TO_POINTER(1));
1685 /* remove address on To: and that of current account */
1686 for (cur = cc_list; cur != NULL; ) {
1687 GSList *next = cur->next;
1689 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1690 cc_list = g_slist_remove(cc_list, cur->data);
1692 g_hash_table_insert(to_table, cur->data, cur);
1696 g_hash_table_destroy(to_table);
1699 for (cur = cc_list; cur != NULL; cur = cur->next)
1700 compose_entry_append(compose, (gchar *)cur->data,
1702 slist_free_strings(cc_list);
1703 g_slist_free(cc_list);
1707 #define SET_ENTRY(entry, str) \
1710 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1713 #define SET_ADDRESS(type, str) \
1716 compose_entry_append(compose, str, type); \
1719 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1721 g_return_if_fail(msginfo != NULL);
1723 SET_ENTRY(subject_entry, msginfo->subject);
1724 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1725 SET_ADDRESS(COMPOSE_CC, compose->cc);
1726 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1727 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1729 compose_show_first_last_header(compose, TRUE);
1731 #if 0 /* NEW COMPOSE GUI */
1733 GtkItemFactory *ifactory;
1734 GtkWidget *menuitem;
1736 ifactory = gtk_item_factory_from_widget(compose->menubar);
1737 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1738 gtk_check_menu_item_set_active
1739 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1741 if (compose->replyto) {
1742 GtkItemFactory *ifactory;
1743 GtkWidget *menuitem;
1745 ifactory = gtk_item_factory_from_widget(compose->menubar);
1746 menuitem = gtk_item_factory_get_item
1747 (ifactory, "/View/Reply to");
1748 gtk_check_menu_item_set_active
1749 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1757 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1764 size_t buf_len = 128;
1766 if (strlen(sigfile) < 2)
1769 sigprg = popen(sigfile+1, "r");
1772 buf = g_malloc(buf_len);
1775 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1776 "Unable to insert signature (malloc failed)\n", -1);
1782 while (!feof(sigprg)) {
1783 bzero(buf, buf_len);
1784 fread(buf, buf_len-1, 1, sigprg);
1785 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1793 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1794 "Can't exec file: ", -1);
1795 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1800 static void compose_insert_sig(Compose *compose)
1804 if (compose->account && compose->account->sig_path)
1805 sigfile = g_strdup(compose->account->sig_path);
1807 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1808 DEFAULT_SIGNATURE, NULL);
1810 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1815 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1816 if (prefs_common.sig_sep) {
1817 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1818 prefs_common.sig_sep, -1);
1819 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1823 if (sigfile[0] == '|')
1824 compose_exec_sig(compose, sigfile);
1826 compose_insert_file(compose, sigfile);
1830 static void compose_insert_file(Compose *compose, const gchar *file)
1832 GtkSText *text = GTK_STEXT(compose->text);
1833 gchar buf[BUFFSIZE];
1837 g_return_if_fail(file != NULL);
1839 if ((fp = fopen(file, "rb")) == NULL) {
1840 FILE_OP_ERROR(file, "fopen");
1844 gtk_stext_freeze(text);
1846 while (fgets(buf, sizeof(buf), fp) != NULL) {
1847 /* strip <CR> if DOS/Windows file,
1848 replace <CR> with <LF> if Macintosh file. */
1851 if (len > 0 && buf[len - 1] != '\n') {
1853 if (buf[len] == '\r') buf[len] = '\n';
1855 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1858 gtk_stext_thaw(text);
1863 static void compose_attach_append(Compose *compose, const gchar *file,
1864 const gchar *filename,
1865 const gchar *content_type)
1868 gchar *text[N_ATTACH_COLS];
1873 if (!is_file_exist(file)) {
1874 g_warning(_("File %s doesn't exist\n"), file);
1877 if ((size = get_file_size(file)) < 0) {
1878 g_warning(_("Can't get file size of %s\n"), file);
1882 alertpanel_notice(_("File %s is empty."), file);
1885 if ((fp = fopen(file, "rb")) == NULL) {
1886 alertpanel_error(_("Can't read %s."), file);
1891 #if 0 /* NEW COMPOSE GUI */
1892 if (!compose->use_attach) {
1893 GtkItemFactory *ifactory;
1894 GtkWidget *menuitem;
1896 ifactory = gtk_item_factory_from_widget(compose->menubar);
1897 menuitem = gtk_item_factory_get_item(ifactory,
1898 "/View/Attachment");
1899 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1903 ainfo = g_new0(AttachInfo, 1);
1904 ainfo->file = g_strdup(file);
1907 ainfo->content_type = g_strdup(content_type);
1908 if (!strcasecmp(content_type, "message/rfc822")) {
1909 ainfo->encoding = ENC_7BIT;
1910 ainfo->name = g_strdup_printf
1912 g_basename(filename ? filename : file));
1914 ainfo->encoding = ENC_BASE64;
1915 ainfo->name = g_strdup
1916 (g_basename(filename ? filename : file));
1919 ainfo->content_type = procmime_get_mime_type(file);
1920 if (!ainfo->content_type)
1921 ainfo->content_type =
1922 g_strdup("application/octet-stream");
1923 ainfo->encoding = ENC_BASE64;
1924 ainfo->name = g_strdup(g_basename(filename ? filename : file));
1928 text[COL_MIMETYPE] = ainfo->content_type;
1929 text[COL_SIZE] = to_human_readable(size);
1930 text[COL_NAME] = ainfo->name;
1932 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1933 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1936 #define IS_FIRST_PART_TEXT(info) \
1937 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
1938 info->mime_type == MIME_TEXT_ENRICHED) || \
1939 (info->mime_type == MIME_MULTIPART && info->content_type && \
1940 !strcasecmp(info->content_type, "multipart/alternative") && \
1941 (info->children && \
1942 (info->children->mime_type == MIME_TEXT || \
1943 info->children->mime_type == MIME_TEXT_HTML || \
1944 info->children->mime_type == MIME_TEXT_ENRICHED))))
1946 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
1953 mimeinfo = procmime_scan_message(msginfo);
1954 if (!mimeinfo) return;
1956 /* skip first text (presumably message body) */
1957 child = mimeinfo->children;
1958 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
1959 procmime_mimeinfo_free_all(mimeinfo);
1962 if (IS_FIRST_PART_TEXT(child))
1963 child = child->next;
1965 infile = procmsg_get_message_file_path(msginfo);
1967 while (child != NULL) {
1968 if (child->children || child->mime_type == MIME_MULTIPART) {
1969 child = procmime_mimeinfo_next(child);
1973 outfile = procmime_get_tmp_file_name(child);
1974 if (procmime_get_part(outfile, infile, child) < 0)
1975 g_warning(_("Can't get the part of multipart message."));
1977 compose_attach_append
1979 child->filename ? child->filename : child->name,
1980 child->content_type);
1982 child = child->next;
1986 procmime_mimeinfo_free_all(mimeinfo);
1989 #undef IS_FIRST_PART_TEXT
1991 #define GET_CHAR(pos, buf, len) \
1993 if (text->use_wchar) \
1994 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
1996 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2001 #define INDENT_CHARS ">|#"
2002 #define SPACE_CHARS " \t"
2004 static void compose_wrap_line(Compose *compose)
2006 GtkSText *text = GTK_STEXT(compose->text);
2007 gint ch_len, last_ch_len;
2008 gchar cbuf[MB_LEN_MAX], last_ch;
2012 gint p_start, p_end;
2013 gint line_pos, cur_pos;
2014 gint line_len, cur_len;
2016 gtk_stext_freeze(text);
2018 text_len = gtk_stext_get_length(text);
2020 /* check to see if the point is on the paragraph mark (empty line). */
2021 cur_pos = gtk_stext_get_point(text);
2022 GET_CHAR(cur_pos, cbuf, ch_len);
2023 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2025 goto compose_end; /* on the paragraph mark */
2026 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2027 if (ch_len == 1 && *cbuf == '\n')
2028 goto compose_end; /* on the paragraph mark */
2031 /* find paragraph start. */
2032 line_end = quoted = 0;
2033 for (p_start = cur_pos; p_start >= 0; --p_start) {
2034 GET_CHAR(p_start, cbuf, ch_len);
2035 if (ch_len == 1 && *cbuf == '\n') {
2037 goto compose_end; /* quoted part */
2044 if (ch_len == 1 && strchr(INDENT_CHARS, *cbuf))
2046 else if (ch_len != 1 || !isspace(*cbuf))
2055 /* find paragraph end. */
2057 for (p_end = cur_pos; p_end < text_len; p_end++) {
2058 GET_CHAR(p_end, cbuf, ch_len);
2059 if (ch_len == 1 && *cbuf == '\n') {
2066 if (line_end && ch_len == 1 &&
2067 strchr(INDENT_CHARS, *cbuf))
2068 goto compose_end; /* quoted part */
2073 if (p_end >= text_len)
2076 if (p_start >= p_end)
2079 line_len = cur_len = 0;
2083 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2086 GET_CHAR(cur_pos, cbuf, ch_len);
2093 if (ch_len == 1 && isspace(*cbuf))
2096 if (ch_len == 1 && *cbuf == '\n') {
2098 if (last_ch_len == 1 && !isspace(last_ch)) {
2099 if (cur_pos + 1 < p_end) {
2100 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2101 if (ch_len == 1 && !isspace(*cbuf))
2105 gtk_stext_set_point(text, cur_pos + 1);
2106 gtk_stext_backward_delete(text, 1);
2108 gtk_stext_set_point(text, cur_pos);
2109 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2119 last_ch_len = ch_len;
2123 line_pos = cur_pos + 1;
2124 line_len = cur_len + ch_len;
2127 if (cur_len + ch_len > prefs_common.linewrap_len &&
2131 GET_CHAR(line_pos - 1, cbuf, ch_len);
2132 if (ch_len == 1 && isspace(*cbuf)) {
2133 gtk_stext_set_point(text, line_pos);
2134 gtk_stext_backward_delete(text, 1);
2143 gtk_stext_set_point(text, line_pos);
2144 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2148 cur_len = cur_len - line_len + ch_len;
2154 line_pos = cur_pos + 1;
2155 line_len = cur_len + ch_len;
2161 gtk_stext_thaw(text);
2166 /* Darko: used when I debug wrapping */
2167 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2172 printf("%d [", pos);
2173 for (i = pos; i < tlen; i++) {
2174 ch = GTK_STEXT_INDEX(text, i);
2175 if (breakoncr && ch == '\n')
2185 WAIT_FOR_INDENT_CHAR,
2186 WAIT_FOR_INDENT_CHAR_OR_SPACE
2189 /* return indent length, we allow:
2190 > followed by spaces/tabs
2191 | followed by spaces/tabs
2192 uppercase characters immediately followed by >,
2193 and the repeating sequences of the above */
2194 /* return indent length */
2195 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2198 guint i, ch_len, alnum_cnt = 0;
2199 IndentState state = WAIT_FOR_INDENT_CHAR;
2200 gchar cbuf[MB_LEN_MAX];
2204 for (i = start_pos; i < text_len; i++) {
2205 GET_CHAR(i, cbuf, ch_len);
2209 if (cbuf[0] == '\n')
2212 is_indent = strchr(INDENT_CHARS, cbuf[0]) ? TRUE : FALSE;
2213 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2216 case WAIT_FOR_SPACE:
2217 if (is_space == FALSE)
2219 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2221 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2222 if (is_indent == FALSE && is_space == FALSE &&
2225 if (is_space == TRUE) {
2227 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2228 } else if (is_indent == TRUE) {
2230 state = WAIT_FOR_SPACE;
2233 state = WAIT_FOR_INDENT_CHAR;
2236 case WAIT_FOR_INDENT_CHAR:
2237 if (is_indent == FALSE && !isupper(cbuf[0]))
2239 if (is_indent == TRUE) {
2240 if (alnum_cnt > 0 && cbuf[0] != '>')
2243 state = WAIT_FOR_SPACE;
2254 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2260 /* insert quotation string when line was wrapped */
2261 static guint ins_quote(GtkSText *text, guint indent_len,
2262 guint prev_line_pos, guint text_len,
2269 for (i = 0; i < indent_len; i++) {
2270 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2271 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2273 ins_len = indent_len;
2279 /* check if we should join the next line */
2280 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2283 guint indent_len, ch_len;
2284 gboolean do_join = FALSE;
2285 gchar cbuf[MB_LEN_MAX];
2287 indent_len = get_indent_length(text, start_pos, tlen);
2289 if ((indent_len > 0) && (indent_len == prev_ilen)) {
2290 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2291 if (ch_len > 0 && (cbuf[0] != '\n'))
2298 static void compose_wrap_line_all(Compose *compose)
2300 GtkSText *text = GTK_STEXT(compose->text);
2302 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2303 gint line_len = 0, cur_len = 0;
2305 gboolean is_new_line = TRUE, do_delete = FALSE;
2307 gboolean linewrap_quote = TRUE;
2308 guint linewrap_len = prefs_common.linewrap_len;
2309 gchar *qfmt = prefs_common.quotemark;
2310 gchar cbuf[MB_LEN_MAX];
2312 gtk_stext_freeze(text);
2314 /* make text buffer contiguous */
2315 /* gtk_stext_compact_buffer(text); */
2317 tlen = gtk_stext_get_length(text);
2319 for (; cur_pos < tlen; cur_pos++) {
2320 /* mark position of new line - needed for quotation wrap */
2323 i_len = get_indent_length(text, cur_pos, tlen);
2325 is_new_line = FALSE;
2328 printf("new line i_len=%d p_pos=", i_len);
2329 dump_text(text, p_pos, tlen, 1);
2333 GET_CHAR(cur_pos, cbuf, ch_len);
2335 /* fix line length for tabs */
2336 if (ch_len == 1 && *cbuf == '\t') {
2337 guint tab_width = text->default_tab_width;
2338 guint tab_offset = line_len % tab_width;
2341 printf("found tab at pos=%d line_len=%d ", cur_pos,
2345 line_len += tab_width - tab_offset - 1;
2349 printf("new_len=%d\n", line_len);
2353 /* we have encountered line break */
2354 if (ch_len == 1 && *cbuf == '\n') {
2356 gchar cb[MB_CUR_MAX];
2358 /* should we join the next line */
2359 if ((i_len != cur_len) && do_delete &&
2360 join_next_line(text, cur_pos + 1, tlen, i_len))
2366 printf("found CR at %d do_del is %d next line is ",
2367 cur_pos, do_delete);
2368 dump_text(text, cur_pos + 1, tlen, 1);
2371 /* skip delete if it is continuous URL */
2372 if (do_delete && (line_pos - p_pos <= i_len) &&
2373 gtkut_stext_is_uri_string(text, line_pos, tlen))
2377 printf("l_len=%d wrap_len=%d do_del=%d\n",
2378 line_len, linewrap_len, do_delete);
2380 /* should we delete to perform smart wrapping */
2381 if (line_len < linewrap_len && do_delete) {
2382 /* get rid of newline */
2383 gtk_stext_set_point(text, cur_pos);
2384 gtk_stext_forward_delete(text, 1);
2387 /* if text starts with quote fmt or with
2388 indent string, delete them */
2391 ilen = gtkut_stext_str_compare_n
2392 (text, cur_pos, p_pos, i_len,
2395 gtk_stext_forward_delete
2401 GET_CHAR(cur_pos, cb, clen);
2403 /* insert space if it's alphanumeric */
2404 if ((cur_pos != line_pos) &&
2405 ((clen > 1) || isalnum(cb[0]))) {
2406 gtk_stext_insert(text, NULL, NULL,
2408 /* gtk_stext_compact_buffer(text); */
2412 /* and start over with current line */
2413 cur_pos = p_pos - 1;
2415 line_len = cur_len = 0;
2419 printf("after delete l_pos=");
2420 dump_text(text, line_pos, tlen, 1);
2425 /* mark new line beginning */
2426 line_pos = cur_pos + 1;
2427 line_len = cur_len = 0;
2438 /* possible line break */
2439 if (ch_len == 1 && isspace(*cbuf)) {
2440 line_pos = cur_pos + 1;
2441 line_len = cur_len + ch_len;
2444 /* are we over wrapping length set in preferences ? */
2445 if (cur_len + ch_len > linewrap_len) {
2449 printf("should wrap cur_pos=%d ", cur_pos);
2450 dump_text(text, p_pos, tlen, 1);
2451 dump_text(text, line_pos, tlen, 1);
2453 /* force wrapping if it is one long word but not URL */
2454 if (line_pos - p_pos <= i_len)
2455 if (!gtkut_stext_is_uri_string
2456 (text, line_pos, tlen))
2457 line_pos = cur_pos - 1;
2459 printf("new line_pos=%d\n", line_pos);
2462 GET_CHAR(line_pos - 1, cbuf, clen);
2464 /* if next character is space delete it */
2465 if (clen == 1 && isspace(*cbuf)) {
2466 if (p_pos + i_len != line_pos ||
2467 !gtkut_stext_is_uri_string
2468 (text, line_pos, tlen)) {
2469 gtk_stext_set_point(text, line_pos);
2470 gtk_stext_backward_delete(text, 1);
2479 /* if it is URL at beginning of line don't wrap */
2480 if (p_pos + i_len == line_pos &&
2481 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2483 printf("found URL at ");
2484 dump_text(text, line_pos, tlen, 1);
2490 gtk_stext_set_point(text, line_pos);
2491 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2492 /* gtk_stext_compact_buffer(text); */
2495 /* for loop will increase it */
2496 cur_pos = line_pos - 1;
2497 /* start over with current line */
2506 printf("after CR insert ");
2507 dump_text(text, line_pos, tlen, 1);
2508 dump_text(text, cur_pos, tlen, 1);
2511 /* should we insert quotation ? */
2512 if (linewrap_quote && i_len) {
2513 /* only if line is not already quoted */
2514 if (!gtkut_stext_str_compare
2515 (text, line_pos, tlen, qfmt)) {
2518 if (line_pos - p_pos > i_len) {
2520 (text, i_len, p_pos,
2523 /* gtk_stext_compact_buffer(text); */
2527 printf("after quote insert ");
2528 dump_text(text, line_pos, tlen, 1);
2536 line_pos = cur_pos + 1;
2537 line_len = cur_len + ch_len;
2539 /* advance to next character in buffer */
2543 gtk_stext_thaw(text);
2548 static void compose_set_title(Compose *compose)
2553 edited = compose->modified ? _(" [Edited]") : "";
2554 if (compose->account && compose->account->address)
2555 str = g_strdup_printf(_("%s - Compose message%s"),
2556 compose->account->address, edited);
2558 str = g_strdup_printf(_("Compose message%s"), edited);
2559 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2564 * compose_current_mail_account:
2566 * Find a current mail account (the currently selected account, or the
2567 * default account, if a news account is currently selected). If a
2568 * mail account cannot be found, display an error message.
2570 * Return value: Mail account, or NULL if not found.
2572 static PrefsAccount *
2573 compose_current_mail_account(void)
2577 if (cur_account && cur_account->protocol != A_NNTP)
2580 ac = account_get_default();
2581 if (!ac || ac->protocol == A_NNTP) {
2582 alertpanel_error(_("Account for sending mail is not specified.\n"
2583 "Please select a mail account before sending."));
2590 gboolean compose_check_for_valid_recipient(Compose *compose) {
2591 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2592 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2593 gboolean recipient_found = FALSE;
2597 /* free to and newsgroup list */
2598 slist_free_strings(compose->to_list);
2599 g_slist_free(compose->to_list);
2600 compose->to_list = NULL;
2602 slist_free_strings(compose->newsgroup_list);
2603 g_slist_free(compose->newsgroup_list);
2604 compose->newsgroup_list = NULL;
2606 /* search header entries for to and newsgroup entries */
2607 for(list = compose->header_list; list; list = list->next) {
2610 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2611 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2613 if(entry[0] != '\0') {
2614 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2615 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2616 compose->to_list = address_list_append(compose->to_list, entry);
2617 recipient_found = TRUE;
2620 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2621 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2622 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2623 recipient_found = TRUE;
2629 return recipient_found;
2632 static gboolean compose_check_entries(Compose *compose)
2636 if (compose_check_for_valid_recipient(compose) == FALSE) {
2637 alertpanel_error(_("Recipient is not specified."));
2641 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2645 aval = alertpanel(_("Send"),
2646 _("Subject is empty. Send it anyway?"),
2647 _("Yes"), _("No"), NULL);
2648 if (aval != G_ALERTDEFAULT)
2655 gint compose_send(Compose *compose)
2661 if (compose_check_entries(compose) == FALSE)
2664 val = compose_queue(compose, &msgnum, &folder);
2666 alertpanel_error(_("Could not queue message for sending"));
2670 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2672 folder_item_remove_msg(folder, msgnum);
2673 folderview_update_item(folder, TRUE);
2678 #if 0 /* compose restructure */
2679 gint compose_send(Compose *compose)
2681 gchar tmp[MAXPATHLEN + 1];
2683 static gboolean lock = FALSE;
2687 g_return_val_if_fail(compose->account != NULL, -1);
2688 g_return_val_if_fail(compose->orig_account != NULL, -1);
2692 if (compose_check_entries(compose) == FALSE) {
2697 /* write to temporary file */
2698 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2699 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2701 if (prefs_common.linewrap_at_send)
2702 compose_wrap_line_all(compose);
2704 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2709 if (!compose->to_list && !compose->newsgroup_list) {
2710 g_warning(_("can't get recipient list."));
2716 if (compose->to_list) {
2719 #if 0 /* NEW COMPOSE GUI */
2720 if (compose->account->protocol != A_NNTP)
2721 ac = compose->account;
2722 else if (compose->orig_account->protocol != A_NNTP)
2723 ac = compose->orig_account;
2724 else if (cur_account && cur_account->protocol != A_NNTP)
2727 ac = compose_current_mail_account();
2735 ac = compose->account;
2737 ok = send_message(tmp, ac, compose->to_list);
2738 statusbar_pop_all();
2741 if (ok == 0 && compose->newsgroup_list) {
2744 if (compose->account->protocol == A_NNTP)
2745 folder = FOLDER(compose->account->folder);
2747 folder = FOLDER(compose->orig_account->folder);
2749 ok = news_post(folder, tmp);
2751 alertpanel_error(_("Error occurred while posting the message to %s ."),
2752 compose->account->nntp_server);
2759 /* queue message if failed to send */
2761 if (prefs_common.queue_msg) {
2766 _("Error occurred while sending the message.\n"
2767 "Put this message into queue folder?"),
2768 _("OK"), _("Cancel"), NULL);
2769 if (G_ALERTDEFAULT == val) {
2770 ok = compose_queue(compose, tmp);
2772 alertpanel_error(_("Can't queue the message."));
2775 alertpanel_error(_("Error occurred while sending the message."));
2777 if (compose->mode == COMPOSE_REEDIT) {
2778 compose_remove_reedit_target(compose);
2779 if (compose->targetinfo)
2780 folderview_update_item
2781 (compose->targetinfo->folder, TRUE);
2783 /* save message to outbox */
2784 if (prefs_common.savemsg) {
2787 outbox = account_get_special_folder
2788 (compose->account, F_OUTBOX);
2789 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
2791 (_("Can't save the message to outbox."));
2793 folderview_update_item(outbox, TRUE);
2803 static gboolean compose_use_attach(Compose *compose) {
2804 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2807 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2810 gchar buf[BUFFSIZE];
2812 gboolean first_address;
2814 ComposeHeaderEntry *headerentry;
2815 gchar *headerentryname;
2816 gchar *header_w_colon;
2820 debug_print(_("Writing bounce header\n"));
2822 header_w_colon = g_strconcat("To:", NULL);
2823 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2824 header_w_colon = g_strconcat("Cc:", NULL);
2825 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2827 first_address = TRUE;
2828 for(list = compose->header_list; list; list = list->next) {
2829 headerentry = ((ComposeHeaderEntry *)list->data);
2830 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2832 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2833 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2834 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2835 Xstrdup_a(str, str, return -1);
2837 if(str[0] != '\0') {
2838 compose_convert_header
2839 (buf, sizeof(buf), str,
2840 strlen("Resent-To") + 2);
2842 fprintf(fp, "Resent-To: ");
2843 first_address = FALSE;
2847 fprintf(fp, "%s", buf);
2851 /* if(!first_address) { */
2858 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2860 gchar buf[BUFFSIZE];
2862 /* struct utsname utsbuf; */
2864 g_return_val_if_fail(fp != NULL, -1);
2865 g_return_val_if_fail(compose->account != NULL, -1);
2866 g_return_val_if_fail(compose->account->address != NULL, -1);
2869 get_rfc822_date(buf, sizeof(buf));
2870 fprintf(fp, "Resent-Date: %s\n", buf);
2873 if (compose->account->name && *compose->account->name) {
2874 compose_convert_header
2875 (buf, sizeof(buf), compose->account->name,
2877 fprintf(fp, "Resent-From: %s <%s>\n",
2878 buf, compose->account->address);
2880 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2883 compose_bounce_write_headers_from_headerlist(compose, fp);
2885 /* separator between header and body */
2891 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2896 gchar buf[BUFFSIZE];
2898 if ((fp = fopen(compose->bounce_filename, "rb")) == NULL) {
2899 FILE_OP_ERROR(file, "fopen");
2903 if ((fdest = fopen(file, "wb")) == NULL) {
2904 FILE_OP_ERROR(file, "fopen");
2909 /* chmod for security */
2910 if (change_file_mode_rw(fdest, file) < 0) {
2911 FILE_OP_ERROR(file, "chmod");
2912 g_warning(_("can't change file mode\n"));
2915 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2916 /* should filter returnpath, delivered-to */
2917 if ((g_strncasecmp(buf, "Return-Path:",
2918 strlen("Return-Path:")) == 0)
2919 || (g_strncasecmp(buf, "Delivered-To:",
2920 strlen("Delivered-To:")) == 0))
2923 if (fputs(buf, fdest) == -1)
2926 if (!prefs_common.bounce_keep_from) {
2927 if (g_strncasecmp(buf, "From:",
2928 strlen("From:")) == 0) {
2929 fputs(" (by way of ", fdest);
2930 if (compose->account->name
2931 && *compose->account->name) {
2932 compose_convert_header
2934 compose->account->name,
2936 fprintf(fdest, "%s <%s>",
2938 compose->account->address);
2940 fprintf(fdest, "%s",
2941 compose->account->address);
2946 if (fputs("\n", fdest) == -1)
2950 compose_bounce_write_headers(compose, fdest);
2952 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
2953 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
2971 * interfaces to rfc2015 to keep out the prefs stuff there.
2972 * returns 0 on success and -1 on error. */
2973 static int compose_create_signers_list (Compose *compose, GSList **pkey_list)
2975 const char *keyid = NULL;
2978 switch (compose->account->sign_key) {
2979 case SIGN_KEY_DEFAULT:
2981 return 0; /* nothing to do */
2983 case SIGN_KEY_BY_FROM:
2984 keyid = compose->account->address;
2987 case SIGN_KEY_CUSTOM:
2988 keyid = compose->account->sign_key_id;
2992 g_assert_not_reached ();
2995 key_list = rfc2015_create_signers_list(keyid);
2998 alertpanel_error("Could not find any key associated with currently "
2999 "selected keyid `%s'!", keyid);
3003 *pkey_list = key_list;
3006 #endif /* USE_GPGME */
3008 static gint compose_write_to_file(Compose *compose, const gchar *file,
3015 const gchar *out_codeset;
3016 EncodingType encoding;
3018 if ((fp = fopen(file, "wb")) == NULL) {
3019 FILE_OP_ERROR(file, "fopen");
3023 /* chmod for security */
3024 if (change_file_mode_rw(fp, file) < 0) {
3025 FILE_OP_ERROR(file, "chmod");
3026 g_warning(_("can't change file mode\n"));
3029 /* get all composed text */
3030 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3031 len = strlen(chars);
3032 if (is_ascii_str(chars)) {
3033 buf = g_strdup(chars);
3034 out_codeset = CS_US_ASCII;
3035 encoding = ENC_7BIT;
3037 const gchar *src_codeset;
3039 out_codeset = conv_get_outgoing_charset_str();
3040 if (!strcasecmp(out_codeset, CS_US_ASCII))
3041 out_codeset = CS_ISO_8859_1;
3042 encoding = procmime_get_encoding_for_charset(out_codeset);
3044 src_codeset = conv_get_current_charset_str();
3045 /* if current encoding is US-ASCII, set it the same as
3046 outgoing one to prevent code conversion failure */
3047 if (!strcasecmp(src_codeset, CS_US_ASCII))
3048 src_codeset = out_codeset;
3050 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3051 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3053 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3059 _("Can't convert the character encoding of the message.\n"
3060 "Send it anyway?"), _("Yes"), _("+No"), NULL);
3061 if (aval != G_ALERTDEFAULT) {
3067 buf = g_strdup(chars);
3074 if (compose_write_headers
3075 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3076 g_warning(_("can't write headers\n"));
3083 if (compose_use_attach(compose)) {
3085 /* This prolog message is ignored by mime software and
3086 * because it would make our signing/encryption task
3087 * tougher, we don't emit it in that case */
3088 if (!compose->use_signing && !compose->use_encryption)
3090 fputs("This is a multi-part message in MIME format.\n", fp);
3092 fprintf(fp, "\n--%s\n", compose->boundary);
3093 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3095 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3096 procmime_get_encoding_str(encoding));
3102 if (encoding == ENC_BASE64) {
3103 gchar outbuf[B64_BUFFSIZE];
3106 for (i = 0; i < len; i += B64_LINE_SIZE) {
3107 l = MIN(B64_LINE_SIZE, len - i);
3108 to64frombits(outbuf, buf + i, l);
3112 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3113 FILE_OP_ERROR(file, "fwrite");
3121 if (compose_use_attach(compose))
3122 compose_write_attach(compose, fp);
3124 if (fclose(fp) == EOF) {
3125 FILE_OP_ERROR(file, "fclose");
3131 if (compose->use_signing) {
3134 if (compose_create_signers_list(compose, &key_list) == -1 ||
3135 rfc2015_sign(file, key_list) < 0) {
3141 if (compose->use_encryption) {
3142 if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) {
3147 #endif /* USE_GPGME */
3152 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3158 if ((fp = fopen(file, "wb")) == NULL) {
3159 FILE_OP_ERROR(file, "fopen");
3163 /* chmod for security */
3164 if (change_file_mode_rw(fp, file) < 0) {
3165 FILE_OP_ERROR(file, "chmod");
3166 g_warning(_("can't change file mode\n"));
3169 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3172 len = strlen(chars);
3173 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3174 FILE_OP_ERROR(file, "fwrite");
3183 if (fclose(fp) == EOF) {
3184 FILE_OP_ERROR(file, "fclose");
3191 static gint compose_remove_reedit_target(Compose *compose)
3194 MsgInfo *msginfo = compose->targetinfo;
3196 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3197 if (!msginfo) return -1;
3199 item = msginfo->folder;
3200 g_return_val_if_fail(item != NULL, -1);
3202 folder_item_scan(item);
3203 if (procmsg_msg_exist(msginfo) &&
3204 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3205 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3206 g_warning(_("can't remove the old message\n"));
3215 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3218 gchar *tmp, *tmp2, *queue_path;
3221 gchar buf[BUFFSIZE];
3223 MsgFlags flag = {0, 0};
3224 static gboolean lock = FALSE;
3225 PrefsAccount *mailac = NULL, *newsac = NULL;
3227 debug_print(_("queueing message...\n"));
3228 g_return_val_if_fail(compose->account != NULL, -1);
3229 g_return_val_if_fail(compose->orig_account != NULL, -1);
3233 if (compose_check_entries(compose) == FALSE) {
3238 if (!compose->to_list && !compose->newsgroup_list) {
3239 g_warning(_("can't get recipient list."));
3244 if(compose->to_list) {
3245 if (compose->account->protocol != A_NNTP)
3246 mailac = compose->account;
3247 else if (compose->orig_account->protocol != A_NNTP)
3248 mailac = compose->orig_account;
3249 else if (cur_account && cur_account->protocol != A_NNTP)
3250 mailac = cur_account;
3251 else if (!(mailac = compose_current_mail_account())) {
3253 alertpanel_error(_("No account for sending mails available!"));
3258 if(compose->newsgroup_list) {
3259 if (compose->account->protocol == A_NNTP)
3260 newsac = compose->account;
3261 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3263 alertpanel_error(_("No account for posting news available!"));
3268 if (prefs_common.linewrap_at_send)
3269 compose_wrap_line_all(compose);
3271 /* write to temporary file */
3272 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3273 G_DIR_SEPARATOR, (gint)compose);
3275 if (compose->bounce_filename != NULL) {
3276 if (compose_bounce_write_to_file(compose, tmp2) < 0) {
3283 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3290 /* add queue header */
3291 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3292 G_DIR_SEPARATOR, (gint)compose);
3293 if ((fp = fopen(tmp, "wb")) == NULL) {
3294 FILE_OP_ERROR(tmp, "fopen");
3298 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3299 FILE_OP_ERROR(tmp2, "fopen");
3307 if (change_file_mode_rw(fp, tmp) < 0) {
3308 FILE_OP_ERROR(tmp, "chmod");
3309 g_warning(_("can't change file mode\n"));
3312 /* queueing variables */
3313 fprintf(fp, "AF:\n");
3314 fprintf(fp, "NF:0\n");
3315 fprintf(fp, "PS:10\n");
3316 fprintf(fp, "SRH:1\n");
3317 fprintf(fp, "SFN:\n");
3318 fprintf(fp, "DSR:\n");
3320 fprintf(fp, "MID:<%s>\n", compose->msgid);
3322 fprintf(fp, "MID:\n");
3323 fprintf(fp, "CFG:\n");
3324 fprintf(fp, "PT:0\n");
3325 fprintf(fp, "S:%s\n", compose->account->address);
3326 fprintf(fp, "RQ:\n");
3328 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3330 fprintf(fp, "SSV:\n");
3332 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3334 fprintf(fp, "NSV:\n");
3335 fprintf(fp, "SSH:\n");
3336 /* write recepient list */
3338 if(compose->to_list) {
3339 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3340 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3341 fprintf(fp, ",<%s>", (gchar *)cur->data);
3344 /* write newsgroup list */
3346 if(compose->newsgroup_list) {
3347 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3348 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3349 fprintf(fp, ",%s", (gchar *)cur->data);
3352 /* Sylpheed account IDs */
3354 fprintf(fp, "MAID:%d\n", mailac->account_id);
3357 fprintf(fp, "NAID:%d\n", newsac->account_id);
3359 /* Save copy folder */
3360 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3363 str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3364 fprintf(fp, "SCF:%s\n", str);
3369 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3370 if (fputs(buf, fp) == EOF) {
3371 FILE_OP_ERROR(tmp, "fputs");
3382 if (fclose(fp) == EOF) {
3383 FILE_OP_ERROR(tmp, "fclose");
3391 queue = account_get_special_folder(compose->account, F_QUEUE);
3392 folder_item_scan(queue);
3393 queue_path = folder_item_get_path(queue);
3394 if (!is_dir_exist(queue_path))
3395 make_dir_hier(queue_path);
3396 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3397 g_warning(_("can't queue the message\n"));
3408 if (compose->mode == COMPOSE_REEDIT) {
3409 compose_remove_reedit_target(compose);
3410 if (compose->targetinfo &&
3411 compose->targetinfo->folder != queue)
3412 folderview_update_item
3413 (compose->targetinfo->folder, TRUE);
3416 procmsg_add_flags(queue, num, flag);
3417 folder_item_scan(queue);
3418 folderview_update_item(queue, TRUE);
3420 if((msgnum != NULL) && (item != NULL)) {
3428 static void compose_write_attach(Compose *compose, FILE *fp)
3431 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3434 gchar filename[BUFFSIZE];
3437 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3439 gchar buf[BUFFSIZE];
3440 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3442 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
3443 g_warning(_("Can't open file %s\n"), ainfo->file);
3447 fprintf(fp, "\n--%s\n", compose->boundary);
3449 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3450 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3451 fprintf(fp, "Content-Disposition: inline\n");
3453 conv_encode_header(filename, sizeof(filename),
3455 fprintf(fp, "Content-Type: %s;\n"
3457 ainfo->content_type, filename);
3458 fprintf(fp, "Content-Disposition: attachment;\n"
3459 " filename=\"%s\"\n", filename);
3462 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3463 procmime_get_encoding_str(ainfo->encoding));
3465 switch (ainfo->encoding) {
3469 /* if (ainfo->encoding == ENC_7BIT) { */
3471 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3479 while ((len = fread(inbuf, sizeof(gchar),
3480 B64_LINE_SIZE, attach_fp))
3482 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3486 if (len > 0 && feof(attach_fp)) {
3487 to64frombits(outbuf, inbuf, len);
3497 fprintf(fp, "\n--%s--\n", compose->boundary);
3500 #define IS_IN_CUSTOM_HEADER(header) \
3501 (compose->account->add_customhdr && \
3502 custom_header_find(compose->account->customhdr_list, header) != NULL)
3504 static gint compose_write_headers_from_headerlist(Compose *compose,
3508 gchar buf[BUFFSIZE];
3509 gchar *str, *header_w_colon, *trans_hdr;
3510 gboolean first_address;
3512 ComposeHeaderEntry *headerentry;
3513 gchar * headerentryname;
3515 if (IS_IN_CUSTOM_HEADER(header)) {
3519 debug_print(_("Writing %s-header\n"), header);
3521 header_w_colon = g_strconcat(header, ":", NULL);
3522 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3524 first_address = TRUE;
3525 for(list = compose->header_list; list; list = list->next) {
3526 headerentry = ((ComposeHeaderEntry *)list->data);
3527 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3529 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3530 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3531 Xstrdup_a(str, str, return -1);
3533 if(str[0] != '\0') {
3534 compose_convert_header
3535 (buf, sizeof(buf), str,
3536 strlen(header) + 2);
3538 fprintf(fp, "%s: ", header);
3539 first_address = FALSE;
3543 fprintf(fp, "%s", buf);
3547 if(!first_address) {
3551 g_free(header_w_colon);
3556 static gint compose_write_headers(Compose *compose, FILE *fp,
3557 const gchar *charset, EncodingType encoding,
3560 gchar buf[BUFFSIZE];
3562 /* struct utsname utsbuf; */
3564 g_return_val_if_fail(fp != NULL, -1);
3565 g_return_val_if_fail(charset != NULL, -1);
3566 g_return_val_if_fail(compose->account != NULL, -1);
3567 g_return_val_if_fail(compose->account->address != NULL, -1);
3570 if (compose->account->add_date) {
3571 get_rfc822_date(buf, sizeof(buf));
3572 fprintf(fp, "Date: %s\n", buf);
3576 if (!IS_IN_CUSTOM_HEADER("From")) {
3577 if (compose->account->name && *compose->account->name) {
3578 compose_convert_header
3579 (buf, sizeof(buf), compose->account->name,
3581 fprintf(fp, "From: %s <%s>\n",
3582 buf, compose->account->address);
3584 fprintf(fp, "From: %s\n", compose->account->address);
3588 compose_write_headers_from_headerlist(compose, fp, "To");
3589 #if 0 /* NEW COMPOSE GUI */
3590 if (compose->use_to) {
3591 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3593 Xstrdup_a(str, str, return -1);
3596 compose->to_list = address_list_append
3597 (compose->to_list, str);
3598 if (!IS_IN_CUSTOM_HEADER("To")) {
3599 compose_convert_header
3600 (buf, sizeof(buf), str,
3602 fprintf(fp, "To: %s\n", buf);
3610 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3611 #if 0 /* NEW COMPOSE GUI */
3612 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3614 Xstrdup_a(str, str, return -1);
3618 compose->newsgroup_list =
3619 newsgroup_list_append(compose->newsgroup_list,
3621 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3622 compose_convert_header(buf, sizeof(buf), str,
3623 strlen("Newsgroups: "));
3624 fprintf(fp, "Newsgroups: %s\n", buf);
3630 compose_write_headers_from_headerlist(compose, fp, "Cc");
3631 #if 0 /* NEW COMPOSE GUI */
3632 if (compose->use_cc) {
3633 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3635 Xstrdup_a(str, str, return -1);
3638 compose->to_list = address_list_append
3639 (compose->to_list, str);
3640 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3641 compose_convert_header
3642 (buf, sizeof(buf), str,
3644 fprintf(fp, "Cc: %s\n", buf);
3651 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3652 #if 0 /* NEW COMPOSE GUI */
3653 if (compose->use_bcc) {
3654 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3656 Xstrdup_a(str, str, return -1);
3659 compose->to_list = address_list_append
3660 (compose->to_list, str);
3661 compose_convert_header(buf, sizeof(buf), str,
3663 fprintf(fp, "Bcc: %s\n", buf);
3670 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3671 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3672 Xstrdup_a(str, str, return -1);
3675 compose_convert_header(buf, sizeof(buf), str,
3676 strlen("Subject: "));
3677 fprintf(fp, "Subject: %s\n", buf);
3682 if (compose->account->gen_msgid) {
3683 compose_generate_msgid(compose, buf, sizeof(buf));
3684 fprintf(fp, "Message-Id: <%s>\n", buf);
3685 compose->msgid = g_strdup(buf);
3689 if (compose->inreplyto && compose->to_list)
3690 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3693 if (compose->references)
3694 fprintf(fp, "References: %s\n", compose->references);
3697 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3698 #if 0 /* NEW COMPOSE GUI */
3699 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3700 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3702 Xstrdup_a(str, str, return -1);
3706 compose_convert_header(buf, sizeof(buf), str,
3707 strlen("Followup-To: "));
3708 fprintf(fp, "Followup-To: %s\n", buf);
3714 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3715 #if 0 /* NEW COMPOSE GUI */
3716 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3717 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3719 Xstrdup_a(str, str, return -1);
3722 compose_convert_header(buf, sizeof(buf), str,
3723 strlen("Reply-To: "));
3724 fprintf(fp, "Reply-To: %s\n", buf);
3730 if (compose->account->organization &&
3731 !IS_IN_CUSTOM_HEADER("Organization")) {
3732 compose_convert_header(buf, sizeof(buf),
3733 compose->account->organization,
3734 strlen("Organization: "));
3735 fprintf(fp, "Organization: %s\n", buf);
3738 /* Program version and system info */
3739 /* uname(&utsbuf); */
3740 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3741 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3743 gtk_major_version, gtk_minor_version, gtk_micro_version,
3745 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3747 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3748 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3750 gtk_major_version, gtk_minor_version, gtk_micro_version,
3752 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3755 /* custom headers */
3756 if (compose->account->add_customhdr) {
3759 for (cur = compose->account->customhdr_list; cur != NULL;
3761 CustomHeader *chdr = (CustomHeader *)cur->data;
3763 if (strcasecmp(chdr->name, "Date") != 0 &&
3764 strcasecmp(chdr->name, "From") != 0 &&
3765 strcasecmp(chdr->name, "To") != 0 &&
3766 /* strcasecmp(chdr->name, "Sender") != 0 && */
3767 strcasecmp(chdr->name, "Message-Id") != 0 &&
3768 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3769 strcasecmp(chdr->name, "References") != 0 &&
3770 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3771 strcasecmp(chdr->name, "Content-Type") != 0 &&
3772 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3774 compose_convert_header
3776 chdr->value ? chdr->value : "",
3777 strlen(chdr->name) + 2);
3778 fprintf(fp, "%s: %s\n", chdr->name, buf);
3784 fprintf(fp, "Mime-Version: 1.0\n");
3785 if (compose_use_attach(compose)) {
3786 get_rfc822_date(buf, sizeof(buf));
3787 subst_char(buf, ' ', '_');
3788 subst_char(buf, ',', '_');
3789 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3790 buf, (guint)compose);
3792 "Content-Type: multipart/mixed;\n"
3793 " boundary=\"%s\"\n", compose->boundary);
3795 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3796 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3797 procmime_get_encoding_str(encoding));
3800 /* Request Return Receipt */
3801 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3802 if (compose->return_receipt) {
3803 if (compose->account->name
3804 && *compose->account->name) {
3805 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3806 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3808 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3812 /* separator between header and body */
3818 #undef IS_IN_CUSTOM_HEADER
3820 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3823 g_return_if_fail(src != NULL);
3824 g_return_if_fail(dest != NULL);
3826 if (len < 1) return;
3830 if (is_ascii_str(src)) {
3831 strncpy2(dest, src, len);
3832 dest[len - 1] = '\0';
3835 conv_encode_header(dest, len, src, header_len);
3838 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3847 if (compose->account && compose->account->address &&
3848 *compose->account->address) {
3849 if (strchr(compose->account->address, '@'))
3850 addr = g_strdup(compose->account->address);
3852 addr = g_strconcat(compose->account->address, "@",
3853 get_domain_name(), NULL);
3855 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3858 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3859 lt->tm_year + 1900, lt->tm_mon + 1,
3860 lt->tm_mday, lt->tm_hour,
3861 lt->tm_min, lt->tm_sec,
3862 (guint)random(), addr);
3864 debug_print(_("generated Message-ID: %s\n"), buf);
3869 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3870 GtkWidget **entry, gint *count,
3871 const gchar *label_str,
3872 gboolean is_addr_entry)
3876 if (GTK_TABLE(table)->nrows < (*count) + 1)
3877 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3879 *hbox = gtk_hbox_new(FALSE, 0);
3880 label = gtk_label_new
3881 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3882 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3883 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3885 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3887 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3888 #if 0 /* NEW COMPOSE GUI */
3889 if (GTK_TABLE(table)->nrows > (*count) + 1)
3890 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3894 address_completion_register_entry(GTK_ENTRY(*entry));
3899 static void compose_create_header_entry(Compose *compose)
3901 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3905 GList *combo_list = NULL;
3906 gchar **string, *header;
3907 ComposeHeaderEntry *headerentry;
3909 headerentry = g_new0(ComposeHeaderEntry, 1);
3912 combo = gtk_combo_new();
3914 while(*string != NULL) {
3915 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3918 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3919 g_list_free(combo_list);
3920 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3921 gtk_widget_show(combo);
3922 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3923 if(compose->header_last) {
3924 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3926 switch(compose->account->protocol) {
3928 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
3931 header = prefs_common.trans_hdr ? _("To:") : "To:";
3935 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
3938 entry = gtk_entry_new();
3939 gtk_widget_show(entry);
3940 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);
3942 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
3943 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
3944 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
3946 address_completion_register_entry(GTK_ENTRY(entry));
3948 headerentry->compose = compose;
3949 headerentry->combo = combo;
3950 headerentry->entry = entry;
3951 headerentry->headernum = compose->header_nextrow;
3953 compose->header_nextrow++;
3954 compose->header_last = headerentry;
3957 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
3959 ComposeHeaderEntry *last_header;
3961 last_header = compose->header_last;
3963 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
3964 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
3967 static GtkWidget *compose_create_header(Compose *compose)
3971 GtkWidget *from_optmenu_hbox;
3972 #if 0 /* NEW COMPOSE GUI */
3973 GtkWidget *to_entry;
3975 GtkWidget *newsgroups_entry;
3976 GtkWidget *newsgroups_hbox;
3978 GtkWidget *header_scrolledwin;
3979 GtkWidget *header_table;
3980 #if 0 /* NEW COMPOSE GUI */
3981 GtkWidget *cc_entry;
3983 GtkWidget *bcc_entry;
3984 GtkWidget *bcc_hbox;
3985 GtkWidget *reply_entry;
3986 GtkWidget *reply_hbox;
3987 GtkWidget *followup_entry;
3988 GtkWidget *followup_hbox;
3993 /* header labels and entries */
3994 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3995 gtk_widget_show(header_scrolledwin);
3996 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
3998 header_table = gtk_table_new(2, 2, FALSE);
3999 gtk_widget_show(header_table);
4000 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4001 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4002 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4005 /* option menu for selecting accounts */
4006 hbox = gtk_hbox_new(FALSE, 0);
4007 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4008 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4009 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4011 from_optmenu_hbox = compose_account_option_menu_create(compose);
4012 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4013 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4014 #if 0 /* NEW COMPOSE GUI */
4015 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4019 compose->header_table = header_table;
4020 compose->header_list = NULL;
4021 compose->header_nextrow = count;
4023 compose_create_header_entry(compose);
4025 #if 0 /* NEW COMPOSE GUI */
4026 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4028 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4029 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4030 &count, "Newsgroups:", FALSE);
4031 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4033 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4035 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4037 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4038 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4040 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4041 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4043 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4044 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4045 "Followup-To:", FALSE);
4046 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4048 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4050 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4051 GTK_SIGNAL_FUNC(to_activated), compose);
4052 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4053 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4054 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4055 GTK_SIGNAL_FUNC(subject_activated), compose);
4056 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4057 GTK_SIGNAL_FUNC(cc_activated), compose);
4058 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4059 GTK_SIGNAL_FUNC(bcc_activated), compose);
4060 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4061 GTK_SIGNAL_FUNC(replyto_activated), compose);
4062 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4063 GTK_SIGNAL_FUNC(followupto_activated), compose);
4065 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4066 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4067 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4068 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4069 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4070 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4071 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4072 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4073 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4074 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4075 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4076 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4077 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4078 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4081 compose->table = NULL;
4082 #if 0 /* NEW COMPOSE GUI */
4083 compose->table = table;
4084 compose->to_hbox = to_hbox;
4085 compose->to_entry = to_entry;
4086 compose->newsgroups_hbox = newsgroups_hbox;
4087 compose->newsgroups_entry = newsgroups_entry;
4089 #if 0 /* NEW COMPOSE GUI */
4090 compose->cc_hbox = cc_hbox;
4091 compose->cc_entry = cc_entry;
4092 compose->bcc_hbox = bcc_hbox;
4093 compose->bcc_entry = bcc_entry;
4094 compose->reply_hbox = reply_hbox;
4095 compose->reply_entry = reply_entry;
4096 compose->followup_hbox = followup_hbox;
4097 compose->followup_entry = followup_entry;
4100 return header_scrolledwin ;
4103 GtkWidget *compose_create_attach(Compose *compose)
4105 gchar *titles[N_ATTACH_COLS];
4108 GtkWidget *attach_scrwin;
4109 GtkWidget *attach_clist;
4111 titles[COL_MIMETYPE] = _("MIME type");
4112 titles[COL_SIZE] = _("Size");
4113 titles[COL_NAME] = _("Name");
4115 /* attachment list */
4116 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4117 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4118 GTK_POLICY_AUTOMATIC,
4120 gtk_widget_set_usize(attach_scrwin, -1, 80);
4122 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4123 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4125 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4126 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4127 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4128 GTK_SELECTION_EXTENDED);
4129 for (i = 0; i < N_ATTACH_COLS; i++)
4130 GTK_WIDGET_UNSET_FLAGS
4131 (GTK_CLIST(attach_clist)->column[i].button,
4133 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4135 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4136 GTK_SIGNAL_FUNC(attach_selected), compose);
4137 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4138 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4139 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4140 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4143 gtk_drag_dest_set(attach_clist,
4144 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4146 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4147 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4150 compose->attach_scrwin = attach_scrwin;
4151 compose->attach_clist = attach_clist;
4153 return attach_scrwin;
4156 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4157 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4159 static GtkWidget *compose_create_others(Compose *compose)
4162 GtkWidget *savemsg_checkbtn;
4163 GtkWidget *savemsg_entry;
4164 GtkWidget *savemsg_select;
4167 gchar *folderidentifier;
4169 /* Table for settings */
4170 table = gtk_table_new(3, 1, FALSE);
4171 gtk_widget_show(table);
4172 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4175 /* Save Message to folder */
4176 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4177 gtk_widget_show(savemsg_checkbtn);
4178 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4179 if(folder_get_default_outbox()) {
4180 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4182 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4183 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4185 savemsg_entry = gtk_entry_new();
4186 gtk_widget_show(savemsg_entry);
4187 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4188 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4189 if(folder_get_default_outbox()) {
4190 folderidentifier = folder_item_get_identifier(folder_get_default_outbox());
4191 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4192 g_free(folderidentifier);
4195 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4196 gtk_widget_show (savemsg_select);
4197 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4198 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4199 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4204 compose->savemsg_checkbtn = savemsg_checkbtn;
4205 compose->savemsg_entry = savemsg_entry;
4210 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4212 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4213 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4216 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4221 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4224 path = folder_item_get_identifier(dest);
4226 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4230 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4236 GtkWidget *handlebox;
4238 GtkWidget *notebook;
4243 GtkWidget *subject_hbox;
4244 GtkWidget *subject_frame;
4245 GtkWidget *subject_entry;
4249 GtkWidget *edit_vbox;
4250 GtkWidget *ruler_hbox;
4252 GtkWidget *scrolledwin;
4257 UndoMain *undostruct;
4259 gchar *titles[N_ATTACH_COLS];
4260 guint n_menu_entries;
4261 GtkStyle *style, *new_style;
4264 gboolean success[1];
4266 GtkWidget *popupmenu;
4267 GtkWidget *menuitem;
4268 GtkItemFactory *popupfactory;
4269 GtkItemFactory *ifactory;
4270 GtkWidget *tmpl_menu;
4274 GtkPspell * gtkpspell = NULL;
4277 static GdkGeometry geometry;
4279 g_return_val_if_fail(account != NULL, NULL);
4281 debug_print(_("Creating compose window...\n"));
4282 compose = g_new0(Compose, 1);
4284 titles[COL_MIMETYPE] = _("MIME type");
4285 titles[COL_SIZE] = _("Size");
4286 titles[COL_NAME] = _("Name");
4288 compose->account = account;
4289 compose->orig_account = account;
4291 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4292 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4293 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4294 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4296 if (!geometry.max_width) {
4297 geometry.max_width = gdk_screen_width();
4298 geometry.max_height = gdk_screen_height();
4300 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4301 &geometry, GDK_HINT_MAX_SIZE);
4303 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4304 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4305 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4306 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4307 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4308 gtk_widget_realize(window);
4310 gtkut_widget_set_composer_icon(window);
4312 vbox = gtk_vbox_new(FALSE, 0);
4313 gtk_container_add(GTK_CONTAINER(window), vbox);
4315 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4316 menubar = menubar_create(window, compose_entries,
4317 n_menu_entries, "<Compose>", compose);
4318 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4320 handlebox = gtk_handle_box_new();
4321 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4323 compose_toolbar_create(compose, handlebox);
4325 vbox2 = gtk_vbox_new(FALSE, 2);
4326 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4327 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4330 notebook = gtk_notebook_new();
4331 gtk_widget_set_usize(notebook, -1, 130);
4332 gtk_widget_show(notebook);
4334 /* header labels and entries */
4335 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4336 /* attachment list */
4337 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4339 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4342 subject_hbox = gtk_hbox_new(FALSE, 0);
4343 gtk_widget_show(subject_hbox);
4345 subject_frame = gtk_frame_new(NULL);
4346 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4347 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4348 gtk_widget_show(subject_frame);
4350 subject = gtk_hbox_new(FALSE, 0);
4351 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4352 gtk_widget_show(subject);
4354 label = gtk_label_new(_("Subject:"));
4355 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4356 gtk_widget_show(label);
4358 subject_entry = gtk_entry_new();
4359 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4360 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4361 gtk_widget_show(subject_entry);
4362 compose->subject_entry = subject_entry;
4363 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4365 edit_vbox = gtk_vbox_new(FALSE, 0);
4366 #if 0 /* NEW COMPOSE GUI */
4367 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4370 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4373 ruler_hbox = gtk_hbox_new(FALSE, 0);
4374 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4376 ruler = gtk_shruler_new();
4377 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4378 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4380 gtk_widget_set_usize(ruler_hbox, 1, -1);
4383 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4384 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4385 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4386 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4387 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4389 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4390 (GTK_SCROLLED_WINDOW(scrolledwin)),
4391 gtk_scrolled_window_get_vadjustment
4392 (GTK_SCROLLED_WINDOW(scrolledwin)));
4393 GTK_STEXT(text)->default_tab_width = 8;
4394 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4396 if (prefs_common.block_cursor) {
4397 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4400 if (prefs_common.smart_wrapping) {
4401 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4402 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4405 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4407 gtk_signal_connect(GTK_OBJECT(text), "changed",
4408 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4409 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4410 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4411 gtk_signal_connect(GTK_OBJECT(text), "activate",
4412 GTK_SIGNAL_FUNC(text_activated), compose);
4413 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4414 GTK_SIGNAL_FUNC(compose_button_press_cb),
4417 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4418 GTK_SIGNAL_FUNC(compose_key_press_cb),
4421 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4422 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4426 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4428 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4429 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4431 gtk_widget_show_all(vbox);
4433 /* pane between attach clist and text */
4434 paned = gtk_vpaned_new();
4435 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4436 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4437 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4438 gtk_paned_add1(GTK_PANED(paned), notebook);
4439 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4440 gtk_widget_show_all(paned);
4442 style = gtk_widget_get_style(text);
4444 /* workaround for the slow down of GtkSText when using Pixmap theme */
4445 if (style->engine) {
4446 GtkThemeEngine *engine;
4448 engine = style->engine;
4449 style->engine = NULL;
4450 new_style = gtk_style_copy(style);
4451 style->engine = engine;
4453 new_style = gtk_style_copy(style);
4455 if (prefs_common.textfont) {
4458 charset = conv_get_current_charset();
4459 if (MB_CUR_MAX == 1) {
4462 Xstrdup_a(fontstr, prefs_common.textfont, );
4463 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4465 font = gdk_font_load(fontstr);
4467 font = gdk_fontset_load(prefs_common.textfont);
4469 gdk_font_unref(new_style->font);
4470 new_style->font = font;
4474 gtk_widget_set_style(text, new_style);
4476 color[0] = quote_color;
4477 cmap = gdk_window_get_colormap(window->window);
4478 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4479 if (success[0] == FALSE) {
4480 g_warning("Compose: color allocation failed.\n");
4481 style = gtk_widget_get_style(text);
4482 quote_color = style->black;
4485 n_entries = sizeof(compose_popup_entries) /
4486 sizeof(compose_popup_entries[0]);
4487 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4488 "<Compose>", &popupfactory,
4491 ifactory = gtk_item_factory_from_widget(menubar);
4492 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4493 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4495 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4496 #if 0 /* NEW COMPOSE GUI */
4497 gtk_widget_hide(bcc_hbox);
4498 gtk_widget_hide(bcc_entry);
4499 gtk_widget_hide(reply_hbox);
4500 gtk_widget_hide(reply_entry);
4501 gtk_widget_hide(followup_hbox);
4502 gtk_widget_hide(followup_entry);
4503 gtk_widget_hide(ruler_hbox);
4504 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4505 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4506 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4508 if (account->protocol == A_NNTP) {
4509 gtk_widget_hide(to_hbox);
4510 gtk_widget_hide(to_entry);
4511 gtk_widget_hide(cc_hbox);
4512 gtk_widget_hide(cc_entry);
4513 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4514 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4516 gtk_widget_hide(newsgroups_hbox);
4517 gtk_widget_hide(newsgroups_entry);
4518 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4519 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
4523 update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
4526 undostruct = undo_init(text);
4527 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4530 gtk_widget_show(window);
4532 address_completion_start(window);
4534 compose->window = window;
4535 compose->vbox = vbox;
4536 compose->menubar = menubar;
4537 compose->handlebox = handlebox;
4539 compose->vbox2 = vbox2;
4541 compose->paned = paned;
4543 compose->edit_vbox = edit_vbox;
4544 compose->ruler_hbox = ruler_hbox;
4545 compose->ruler = ruler;
4546 compose->scrolledwin = scrolledwin;
4547 compose->text = text;
4549 compose->focused_editable = NULL;
4551 compose->popupmenu = popupmenu;
4552 compose->popupfactory = popupfactory;
4554 compose->tmpl_menu = tmpl_menu;
4556 compose->mode = mode;
4558 compose->targetinfo = NULL;
4559 compose->replyinfo = NULL;
4561 compose->replyto = NULL;
4562 compose->mailinglist = NULL;
4564 compose->bcc = NULL;
4565 compose->followup_to = NULL;
4566 compose->inreplyto = NULL;
4567 compose->references = NULL;
4568 compose->msgid = NULL;
4569 compose->boundary = NULL;
4572 compose->use_signing = FALSE;
4573 compose->use_encryption = FALSE;
4574 #endif /* USE_GPGME */
4576 compose->modified = FALSE;
4578 compose->return_receipt = FALSE;
4580 compose->to_list = NULL;
4581 compose->newsgroup_list = NULL;
4583 compose->exteditor_file = NULL;
4584 compose->exteditor_pid = -1;
4585 compose->exteditor_readdes = -1;
4586 compose->exteditor_tag = -1;
4588 compose->bounce_filename = NULL;
4589 compose->undostruct = undostruct;
4592 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4593 if (prefs_common.enable_pspell) {
4594 gtkpspell = gtkpspell_new((const gchar*)prefs_common.dictionary,
4595 conv_get_current_charset_str(),
4596 prefs_common.misspelled_col,
4597 prefs_common.check_while_typing,
4598 prefs_common.use_alternate,
4601 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkpspellcheckers->error_message);
4602 gtkpspell_checkers_reset_error();
4605 GtkWidget *menuitem;
4607 if (!gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode)) {
4608 debug_print(_("Pspell: could not set suggestion mode %s"),
4609 gtkpspellcheckers->error_message);
4610 gtkpspell_checkers_reset_error();
4613 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
4614 gtkpspell_populate_submenu(gtkpspell, menuitem);
4615 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4620 compose_set_title(compose);
4622 #if 0 /* NEW COMPOSE GUI */
4623 compose->use_bcc = FALSE;
4624 compose->use_replyto = FALSE;
4625 compose->use_followupto = FALSE;
4629 compose->gtkpspell = gtkpspell;
4632 #if 0 /* NEW COMPOSE GUI */
4633 if (account->protocol != A_NNTP) {
4634 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
4635 gtk_check_menu_item_set_active
4636 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4637 gtk_widget_set_sensitive(menuitem, FALSE);
4638 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4639 gtk_check_menu_item_set_active
4640 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4641 gtk_widget_set_sensitive(menuitem, FALSE);
4644 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4645 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4646 #if 0 /* NEW COMPOSE GUI */
4647 compose->use_cc = TRUE;
4648 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4649 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4650 gtk_check_menu_item_set_active
4651 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4654 if (account->set_autobcc) {
4655 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4656 #if 0 /* NEW COMPOSE GUI */
4657 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
4658 gtk_check_menu_item_set_active
4659 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4660 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4661 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4665 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4666 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4667 #if 0 /* NEW COMPOSE GUI */
4668 compose->use_replyto = TRUE;
4669 menuitem = gtk_item_factory_get_item(ifactory,
4671 gtk_check_menu_item_set_active
4672 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4673 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4674 account->auto_replyto);
4678 if (account->protocol != A_NNTP) {
4679 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4681 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4684 #if 0 /* NEW COMPOSE GUI */
4685 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
4686 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4687 prefs_common.show_ruler);
4691 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4692 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4693 account->default_sign);
4694 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4695 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4696 account->default_encrypt);
4697 #endif /* USE_GPGME */
4699 addressbook_set_target_compose(compose);
4700 compose_set_template_menu(compose);
4702 compose_list = g_list_append(compose_list, compose);
4704 #if 0 /* NEW COMPOSE GUI */
4705 compose->use_to = FALSE;
4706 compose->use_cc = FALSE;
4707 compose->use_attach = TRUE;
4710 #if 0 /* NEW COMPOSE GUI */
4711 if (!compose->use_bcc) {
4712 gtk_widget_hide(bcc_hbox);
4713 gtk_widget_hide(bcc_entry);
4714 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4716 if (!compose->use_replyto) {
4717 gtk_widget_hide(reply_hbox);
4718 gtk_widget_hide(reply_entry);
4719 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4721 if (!compose->use_followupto) {
4722 gtk_widget_hide(followup_hbox);
4723 gtk_widget_hide(followup_entry);
4724 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4727 if (!prefs_common.show_ruler)
4728 gtk_widget_hide(ruler_hbox);
4730 select_account(compose, account);
4731 set_toolbar_style(compose);
4736 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4739 GtkWidget *icon_wid;
4740 GtkWidget *send_btn;
4741 GtkWidget *sendl_btn;
4742 GtkWidget *draft_btn;
4743 GtkWidget *insert_btn;
4744 GtkWidget *attach_btn;
4746 GtkWidget *exteditor_btn;
4747 GtkWidget *linewrap_btn;
4748 GtkWidget *addrbook_btn;
4750 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4752 gtk_container_add(GTK_CONTAINER(container), toolbar);
4753 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4754 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4755 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4756 GTK_TOOLBAR_SPACE_LINE);
4758 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
4759 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4763 icon_wid, toolbar_send_cb, compose);
4765 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND_QUEUE);
4766 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4768 _("Put into queue folder and send later"),
4770 icon_wid, toolbar_send_later_cb,
4773 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4774 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4776 _("Save to draft folder"),
4778 icon_wid, toolbar_draft_cb,
4781 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4783 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_INSERT_FILE);
4784 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4788 icon_wid, toolbar_insert_cb,
4791 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_ATTACH);
4792 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4796 icon_wid, toolbar_attach_cb,
4799 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4801 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SIGN);
4802 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4804 _("Insert signature"),
4806 icon_wid, toolbar_sig_cb, compose);
4808 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4810 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_EDIT_EXTERN);
4811 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4813 _("Edit with external editor"),
4816 toolbar_ext_editor_cb,
4819 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_LINEWRAP);
4820 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4822 _("Wrap all long lines"),
4825 toolbar_linewrap_cb,
4828 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4830 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_ADDRESS_BOOK);
4831 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4835 icon_wid, toolbar_address_cb,
4838 compose->toolbar = toolbar;
4839 compose->send_btn = send_btn;
4840 compose->sendl_btn = sendl_btn;
4841 compose->draft_btn = draft_btn;
4842 compose->insert_btn = insert_btn;
4843 compose->attach_btn = attach_btn;
4844 compose->sig_btn = sig_btn;
4845 compose->exteditor_btn = exteditor_btn;
4846 compose->linewrap_btn = linewrap_btn;
4847 compose->addrbook_btn = addrbook_btn;
4849 gtk_widget_show_all(toolbar);
4852 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4858 gint num = 0, def_menu = 0;
4860 accounts = account_get_list();
4861 g_return_val_if_fail(accounts != NULL, NULL);
4863 hbox = gtk_hbox_new(FALSE, 0);
4864 optmenu = gtk_option_menu_new();
4865 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4866 menu = gtk_menu_new();
4868 for (; accounts != NULL; accounts = accounts->next, num++) {
4869 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4870 GtkWidget *menuitem;
4873 if (ac == compose->account) def_menu = num;
4875 name = g_strdup_printf("%s: %s <%s>",
4876 ac->account_name, ac->name, ac->address);
4877 MENUITEM_ADD(menu, menuitem, name, ac);
4879 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4880 GTK_SIGNAL_FUNC(account_activated),
4884 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4885 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4890 static void compose_set_template_menu(Compose *compose)
4892 GSList *tmpl_list, *cur;
4896 tmpl_list = template_get_config();
4898 menu = gtk_menu_new();
4900 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4901 Template *tmpl = (Template *)cur->data;
4903 item = gtk_menu_item_new_with_label(tmpl->name);
4904 gtk_menu_append(GTK_MENU(menu), item);
4905 gtk_signal_connect(GTK_OBJECT(item), "activate",
4906 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4908 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4909 gtk_widget_show(item);
4912 gtk_widget_show(menu);
4913 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4916 void compose_reflect_prefs_all(void)
4921 for (cur = compose_list; cur != NULL; cur = cur->next) {
4922 compose = (Compose *)cur->data;
4923 compose_set_template_menu(compose);
4927 void compose_reflect_prefs_pixmap_theme(void)
4932 for (cur = compose_list; cur != NULL; cur = cur->next) {
4933 compose = (Compose *)cur->data;
4934 gtk_container_remove(GTK_CONTAINER(compose->handlebox), GTK_WIDGET(compose->toolbar));
4935 compose->toolbar = NULL;
4936 compose_toolbar_create(compose, compose->handlebox);
4937 set_toolbar_style(compose);
4941 static void compose_template_apply(Compose *compose, Template *tmpl,
4947 if (!tmpl || !tmpl->value) return;
4949 gtk_stext_freeze(GTK_STEXT(compose->text));
4951 if (tmpl->subject && *tmpl->subject != '\0')
4952 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
4954 if (tmpl->to && *tmpl->to != '\0')
4955 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
4958 gtk_stext_clear(GTK_STEXT(compose->text));
4960 if (compose->replyinfo == NULL) {
4963 memset(&dummyinfo, 0, sizeof(MsgInfo));
4964 parsed_str = compose_quote_fmt(compose, &dummyinfo,
4965 tmpl->value, NULL, NULL);
4967 if (prefs_common.quotemark && *prefs_common.quotemark)
4968 qmark = prefs_common.quotemark;
4972 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
4973 tmpl->value, qmark, NULL);
4976 if (replace && parsed_str && prefs_common.auto_sig)
4977 compose_insert_sig(compose);
4979 if (replace && parsed_str) {
4980 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
4981 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
4985 compose_changed_cb(NULL, compose);
4987 gtk_stext_thaw(GTK_STEXT(compose->text));
4990 static void compose_destroy(Compose *compose)
4993 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4996 /* NOTE: address_completion_end() does nothing with the window
4997 * however this may change. */
4998 address_completion_end(compose->window);
5000 slist_free_strings(compose->to_list);
5001 g_slist_free(compose->to_list);
5002 slist_free_strings(compose->newsgroup_list);
5003 g_slist_free(compose->newsgroup_list);
5004 slist_free_strings(compose->header_list);
5005 g_slist_free(compose->header_list);
5007 procmsg_msginfo_free(compose->targetinfo);
5008 procmsg_msginfo_free(compose->replyinfo);
5010 g_free(compose->replyto);
5011 g_free(compose->cc);
5012 g_free(compose->bcc);
5013 g_free(compose->newsgroups);
5014 g_free(compose->followup_to);
5016 g_free(compose->inreplyto);
5017 g_free(compose->references);
5018 g_free(compose->msgid);
5019 g_free(compose->boundary);
5021 if (compose->bounce_filename)
5022 g_free(compose->bounce_filename);
5024 g_free(compose->exteditor_file);
5026 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5028 compose_attach_info_free(ainfo);
5030 if (addressbook_get_target_compose() == compose)
5031 addressbook_set_target_compose(NULL);
5034 if (compose->gtkpspell) {
5035 gtkpspell_delete(compose->gtkpspell);
5039 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5040 prefs_common.compose_height = compose->window->allocation.height;
5042 gtk_widget_destroy(compose->paned);
5046 compose_list = g_list_remove(compose_list, compose);
5049 static void compose_attach_info_free(AttachInfo *ainfo)
5051 g_free(ainfo->file);
5052 g_free(ainfo->content_type);
5053 g_free(ainfo->name);
5057 static void compose_attach_remove_selected(Compose *compose)
5059 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5063 while (clist->selection != NULL) {
5064 row = GPOINTER_TO_INT(clist->selection->data);
5065 ainfo = gtk_clist_get_row_data(clist, row);
5066 compose_attach_info_free(ainfo);
5067 gtk_clist_remove(clist, row);
5071 static struct _AttachProperty
5074 GtkWidget *mimetype_entry;
5075 GtkWidget *encoding_optmenu;
5076 GtkWidget *path_entry;
5077 GtkWidget *filename_entry;
5079 GtkWidget *cancel_btn;
5082 static void compose_attach_property(Compose *compose)
5084 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5087 GtkOptionMenu *optmenu;
5088 static gboolean cancelled;
5090 if (!clist->selection) return;
5091 row = GPOINTER_TO_INT(clist->selection->data);
5093 ainfo = gtk_clist_get_row_data(clist, row);
5096 if (!attach_prop.window)
5097 compose_attach_property_create(&cancelled);
5098 gtk_widget_grab_focus(attach_prop.ok_btn);
5099 gtk_widget_show(attach_prop.window);
5100 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5102 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5103 if (ainfo->encoding == ENC_UNKNOWN)
5104 gtk_option_menu_set_history(optmenu, ENC_BASE64);
5106 gtk_option_menu_set_history(optmenu, ainfo->encoding);
5108 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5109 ainfo->content_type ? ainfo->content_type : "");
5110 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5111 ainfo->file ? ainfo->file : "");
5112 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5113 ainfo->name ? ainfo->name : "");
5117 gchar *cnttype = NULL;
5121 GtkWidget *menuitem;
5126 if (cancelled == TRUE) {
5127 gtk_widget_hide(attach_prop.window);
5131 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5132 if (*text != '\0') {
5135 text = g_strstrip(g_strdup(text));
5136 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5137 cnttype = g_strdup(text);
5140 alertpanel_error(_("Invalid MIME type."));
5146 menu = gtk_option_menu_get_menu(optmenu);
5147 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5148 ainfo->encoding = GPOINTER_TO_INT
5149 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5151 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5152 if (*text != '\0') {
5153 if (is_file_exist(text) &&
5154 (size = get_file_size(text)) > 0)
5155 file = g_strdup(text);
5158 (_("File doesn't exist or is empty."));
5164 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5165 if (*text != '\0') {
5166 g_free(ainfo->name);
5167 ainfo->name = g_strdup(text);
5171 g_free(ainfo->content_type);
5172 ainfo->content_type = cnttype;
5175 g_free(ainfo->file);
5181 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5182 ainfo->content_type);
5183 gtk_clist_set_text(clist, row, COL_SIZE,
5184 to_human_readable(ainfo->size));
5185 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5187 gtk_widget_hide(attach_prop.window);
5192 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5194 label = gtk_label_new(str); \
5195 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5196 GTK_FILL, 0, 0, 0); \
5197 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5199 entry = gtk_entry_new(); \
5200 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5201 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5204 static void compose_attach_property_create(gboolean *cancelled)
5210 GtkWidget *mimetype_entry;
5213 GtkWidget *optmenu_menu;
5214 GtkWidget *menuitem;
5215 GtkWidget *path_entry;
5216 GtkWidget *filename_entry;
5219 GtkWidget *cancel_btn;
5220 GList *mime_type_list, *strlist;
5222 debug_print("Creating attach_property window...\n");
5224 window = gtk_window_new(GTK_WINDOW_DIALOG);
5225 gtk_widget_set_usize(window, 480, -1);
5226 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5227 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
5228 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5229 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5230 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5231 GTK_SIGNAL_FUNC(attach_property_delete_event),
5233 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5234 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5237 vbox = gtk_vbox_new(FALSE, 8);
5238 gtk_container_add(GTK_CONTAINER(window), vbox);
5240 table = gtk_table_new(4, 2, FALSE);
5241 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5242 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5243 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5245 label = gtk_label_new(_("MIME type"));
5246 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5248 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5249 mimetype_entry = gtk_combo_new();
5250 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5251 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5253 /* stuff with list */
5254 mime_type_list = procmime_get_mime_type_list();
5256 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5257 MimeType *type = (MimeType *) mime_type_list->data;
5258 strlist = g_list_append(strlist,
5259 g_strdup_printf("%s/%s",
5260 type->type, type->sub_type));
5263 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5265 for (mime_type_list = strlist; mime_type_list != NULL;
5266 mime_type_list = mime_type_list->next)
5267 g_free(mime_type_list->data);
5268 g_list_free(strlist);
5270 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5272 label = gtk_label_new(_("Encoding"));
5273 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5275 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5277 hbox = gtk_hbox_new(FALSE, 0);
5278 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5279 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5281 optmenu = gtk_option_menu_new();
5282 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5284 optmenu_menu = gtk_menu_new();
5285 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5286 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5288 gtk_widget_set_sensitive(menuitem, FALSE);
5290 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5291 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5293 gtk_widget_set_sensitive(menuitem, FALSE);
5295 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5296 gtk_widget_set_sensitive(menuitem, FALSE);
5297 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5299 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5301 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5302 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5304 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5305 &cancel_btn, _("Cancel"), NULL, NULL);
5306 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5307 gtk_widget_grab_default(ok_btn);
5309 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5310 GTK_SIGNAL_FUNC(attach_property_ok),
5312 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5313 GTK_SIGNAL_FUNC(attach_property_cancel),
5316 gtk_widget_show_all(vbox);
5318 attach_prop.window = window;
5319 attach_prop.mimetype_entry = mimetype_entry;
5320 attach_prop.encoding_optmenu = optmenu;
5321 attach_prop.path_entry = path_entry;
5322 attach_prop.filename_entry = filename_entry;
5323 attach_prop.ok_btn = ok_btn;
5324 attach_prop.cancel_btn = cancel_btn;
5327 #undef SET_LABEL_AND_ENTRY
5329 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5335 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5341 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5342 gboolean *cancelled)
5350 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5351 gboolean *cancelled)
5353 if (event && event->keyval == GDK_Escape) {
5359 static void compose_exec_ext_editor(Compose *compose)
5365 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5366 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5368 if (pipe(pipe_fds) < 0) {
5373 if ((pid = fork()) < 0) {
5379 /* close the write side of the pipe */
5382 compose->exteditor_file = g_strdup(tmp);
5383 compose->exteditor_pid = pid;
5384 compose->exteditor_readdes = pipe_fds[0];
5386 compose_set_ext_editor_sensitive(compose, FALSE);
5388 compose->exteditor_tag =
5389 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5390 compose_input_cb, compose);
5391 } else { /* process-monitoring process */
5397 /* close the read side of the pipe */
5400 if (compose_write_body_to_file(compose, tmp) < 0) {
5401 fd_write(pipe_fds[1], "2\n", 2);
5405 pid_ed = compose_exec_ext_editor_real(tmp);
5407 fd_write(pipe_fds[1], "1\n", 2);
5411 /* wait until editor is terminated */
5412 waitpid(pid_ed, NULL, 0);
5414 fd_write(pipe_fds[1], "0\n", 2);
5421 static gint compose_exec_ext_editor_real(const gchar *file)
5423 static gchar *def_cmd = "emacs %s";
5429 g_return_val_if_fail(file != NULL, -1);
5431 if ((pid = fork()) < 0) {
5436 if (pid != 0) return pid;
5438 /* grandchild process */
5440 if (setpgid(0, getppid()))
5443 if (prefs_common.ext_editor_cmd &&
5444 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5445 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5446 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5448 if (prefs_common.ext_editor_cmd)
5449 g_warning(_("External editor command line is invalid: `%s'\n"),
5450 prefs_common.ext_editor_cmd);
5451 g_snprintf(buf, sizeof(buf), def_cmd, file);
5454 cmdline = strsplit_with_quote(buf, " ", 1024);
5455 execvp(cmdline[0], cmdline);
5458 g_strfreev(cmdline);
5463 static gboolean compose_ext_editor_kill(Compose *compose)
5465 pid_t pgid = compose->exteditor_pid * -1;
5468 ret = kill(pgid, 0);
5470 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5474 msg = g_strdup_printf
5475 (_("The external editor is still working.\n"
5476 "Force terminating the process?\n"
5477 "process group id: %d"), -pgid);
5478 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5481 if (val == G_ALERTDEFAULT) {
5482 gdk_input_remove(compose->exteditor_tag);
5483 close(compose->exteditor_readdes);
5485 if (kill(pgid, SIGTERM) < 0) perror("kill");
5486 waitpid(compose->exteditor_pid, NULL, 0);
5488 g_warning(_("Terminated process group id: %d"), -pgid);
5489 g_warning(_("Temporary file: %s"),
5490 compose->exteditor_file);
5492 compose_set_ext_editor_sensitive(compose, TRUE);
5494 g_free(compose->exteditor_file);
5495 compose->exteditor_file = NULL;
5496 compose->exteditor_pid = -1;
5497 compose->exteditor_readdes = -1;
5498 compose->exteditor_tag = -1;
5506 static void compose_input_cb(gpointer data, gint source,
5507 GdkInputCondition condition)
5510 Compose *compose = (Compose *)data;
5513 debug_print(_("Compose: input from monitoring process\n"));
5515 gdk_input_remove(compose->exteditor_tag);
5518 if (read(source, &buf[i], 1) < 1) {
5522 if (buf[i] == '\n') {
5527 if (i == sizeof(buf) - 1)
5531 waitpid(compose->exteditor_pid, NULL, 0);
5533 if (buf[0] == '0') { /* success */
5534 GtkSText *text = GTK_STEXT(compose->text);
5536 gtk_stext_freeze(text);
5537 gtk_stext_set_point(text, 0);
5538 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5539 compose_insert_file(compose, compose->exteditor_file);
5540 compose_changed_cb(NULL, compose);
5541 gtk_stext_thaw(text);
5543 if (unlink(compose->exteditor_file) < 0)
5544 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5545 } else if (buf[0] == '1') { /* failed */
5546 g_warning(_("Couldn't exec external editor\n"));
5547 if (unlink(compose->exteditor_file) < 0)
5548 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5549 } else if (buf[0] == '2') {
5550 g_warning(_("Couldn't write to file\n"));
5551 } else if (buf[0] == '3') {
5552 g_warning(_("Pipe read failed\n"));
5557 compose_set_ext_editor_sensitive(compose, TRUE);
5559 g_free(compose->exteditor_file);
5560 compose->exteditor_file = NULL;
5561 compose->exteditor_pid = -1;
5562 compose->exteditor_readdes = -1;
5563 compose->exteditor_tag = -1;
5566 static void compose_set_ext_editor_sensitive(Compose *compose,
5569 GtkItemFactory *ifactory;
5571 ifactory = gtk_item_factory_from_widget(compose->menubar);
5573 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5574 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5575 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5577 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5578 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5579 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5580 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5581 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5584 gtk_widget_set_sensitive(compose->text, sensitive);
5585 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5586 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5587 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5588 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5589 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5590 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5591 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5595 * compose_undo_state_changed:
5597 * Change the sensivity of the menuentries undo and redo
5599 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5600 gint redo_state, gpointer data)
5602 GtkWidget *widget = GTK_WIDGET(data);
5603 GtkItemFactory *ifactory;
5605 g_return_if_fail(widget != NULL);
5607 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
5609 ifactory = gtk_item_factory_from_widget(widget);
5611 switch (undo_state) {
5612 case UNDO_STATE_TRUE:
5613 if (!undostruct->undo_state) {
5614 debug_print ("Set_undo - Testpoint\n");
5615 undostruct->undo_state = TRUE;
5616 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5619 case UNDO_STATE_FALSE:
5620 if (undostruct->undo_state) {
5621 undostruct->undo_state = FALSE;
5622 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5625 case UNDO_STATE_UNCHANGED:
5627 case UNDO_STATE_REFRESH:
5628 menu_set_sensitive(ifactory, "/Edit/Undo",
5629 undostruct->undo_state);
5632 g_warning("Undo state not recognized");
5636 switch (redo_state) {
5637 case UNDO_STATE_TRUE:
5638 if (!undostruct->redo_state) {
5639 undostruct->redo_state = TRUE;
5640 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5643 case UNDO_STATE_FALSE:
5644 if (undostruct->redo_state) {
5645 undostruct->redo_state = FALSE;
5646 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5649 case UNDO_STATE_UNCHANGED:
5651 case UNDO_STATE_REFRESH:
5652 menu_set_sensitive(ifactory, "/Edit/Redo",
5653 undostruct->redo_state);
5656 g_warning("Redo state not recognized");
5661 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5665 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5666 cursor_pos = MAX(cursor_pos, 0);
5671 /* callback functions */
5673 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5674 * includes "non-client" (windows-izm) in calculation, so this calculation
5675 * may not be accurate.
5677 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5678 GtkAllocation *allocation,
5679 GtkSHRuler *shruler)
5681 if (prefs_common.show_ruler) {
5683 gint line_width_in_chars;
5685 char_width = gtkut_get_font_width
5686 (GTK_WIDGET(widget)->style->font);
5687 line_width_in_chars =
5688 (allocation->width - allocation->x) / char_width;
5690 /* got the maximum */
5691 gtk_ruler_set_range(GTK_RULER(shruler),
5692 0.0, line_width_in_chars,
5693 calc_cursor_xpos(GTK_STEXT(widget),
5696 /*line_width_in_chars*/ char_width);
5702 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5704 compose_send_cb(data, 0, NULL);
5707 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5709 compose_send_later_cb(data, 0, NULL);
5712 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5714 compose_draft_cb(data, 0, NULL);
5717 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5719 compose_insert_file_cb(data, 0, NULL);
5722 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5724 compose_attach_cb(data, 0, NULL);
5727 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5729 Compose *compose = (Compose *)data;
5731 compose_insert_sig(compose);
5734 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5736 Compose *compose = (Compose *)data;
5738 compose_exec_ext_editor(compose);
5741 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5743 Compose *compose = (Compose *)data;
5745 compose_wrap_line(compose);
5748 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5750 compose_address_cb(data, 0, NULL);
5753 static void select_account(Compose * compose, PrefsAccount * ac)
5756 GtkItemFactory *ifactory;
5757 GtkWidget *menuitem;
5758 #endif /* USE_GPGME */
5759 compose->account = ac;
5760 compose_set_title(compose);
5762 #if 0 /* NEW COMPOSE GUI */
5763 if (ac->protocol == A_NNTP) {
5764 GtkItemFactory *ifactory;
5765 GtkWidget *menuitem;
5767 ifactory = gtk_item_factory_from_widget(compose->menubar);
5768 menu_set_sensitive(ifactory,
5769 "/Message/Followup to", TRUE);
5770 gtk_widget_show(compose->newsgroups_hbox);
5771 gtk_widget_show(compose->newsgroups_entry);
5772 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5775 compose->use_to = FALSE;
5776 compose->use_cc = FALSE;
5778 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5779 gtk_check_menu_item_set_active
5780 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5782 menu_set_sensitive(ifactory,
5783 "/Message/To", TRUE);
5784 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5785 gtk_check_menu_item_set_active
5786 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5788 gtk_widget_hide(compose->to_hbox);
5789 gtk_widget_hide(compose->to_entry);
5790 gtk_widget_hide(compose->cc_hbox);
5791 gtk_widget_hide(compose->cc_entry);
5792 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5794 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5798 GtkItemFactory *ifactory;
5799 GtkWidget *menuitem;
5801 ifactory = gtk_item_factory_from_widget(compose->menubar);
5802 menu_set_sensitive(ifactory,
5803 "/Message/Followup to", FALSE);
5804 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5805 gtk_widget_hide(compose->newsgroups_hbox);
5806 gtk_widget_hide(compose->newsgroups_entry);
5807 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5810 compose->use_to = TRUE;
5811 compose->use_cc = TRUE;
5813 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5814 gtk_check_menu_item_set_active
5815 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5816 menu_set_sensitive(ifactory,
5817 "/Message/To", FALSE);
5818 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5819 gtk_check_menu_item_set_active
5820 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5821 gtk_widget_show(compose->to_hbox);
5822 gtk_widget_show(compose->to_entry);
5823 gtk_widget_show(compose->cc_hbox);
5824 gtk_widget_show(compose->cc_entry);
5826 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5828 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5831 gtk_widget_queue_resize(compose->table_vbox);
5834 ifactory = gtk_item_factory_from_widget(compose->menubar);
5835 menu_set_sensitive(ifactory,
5836 "/Message/Sign", TRUE);
5837 menu_set_sensitive(ifactory,
5838 "/Message/Encrypt", TRUE);
5840 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
5841 if (ac->default_sign)
5842 gtk_check_menu_item_set_active
5843 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5845 gtk_check_menu_item_set_active
5846 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5848 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
5849 if (ac->default_encrypt)
5850 gtk_check_menu_item_set_active
5851 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5853 gtk_check_menu_item_set_active
5854 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5855 #endif /* USE_GPGME */
5859 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5861 Compose *compose = (Compose *)data;
5865 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5866 g_return_if_fail(ac != NULL);
5868 if (ac != compose->account)
5869 select_account(compose, ac);
5872 static void attach_selected(GtkCList *clist, gint row, gint column,
5873 GdkEvent *event, gpointer data)
5875 Compose *compose = (Compose *)data;
5877 if (event && event->type == GDK_2BUTTON_PRESS)
5878 compose_attach_property(compose);
5881 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5884 Compose *compose = (Compose *)data;
5885 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5890 if (event->button == 3) {
5891 if ((clist->selection && !clist->selection->next) ||
5892 !clist->selection) {
5893 gtk_clist_unselect_all(clist);
5894 if (gtk_clist_get_selection_info(clist,
5897 gtk_clist_select_row(clist, row, column);
5898 gtkut_clist_set_focus_row(clist, row);
5901 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5902 NULL, NULL, event->button, event->time);
5906 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5909 Compose *compose = (Compose *)data;
5913 switch (event->keyval) {
5915 compose_attach_remove_selected(compose);
5920 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5922 Compose *compose = (Compose *)data;
5925 if (prefs_common.work_offline)
5926 if (alertpanel(_("Offline warning"),
5927 _("You're working offline. Override?"),
5928 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
5931 val = compose_send(compose);
5933 if (val == 0) gtk_widget_destroy(compose->window);
5936 static void compose_send_later_cb(gpointer data, guint action,
5939 Compose *compose = (Compose *)data;
5942 val = compose_queue(compose, NULL, NULL);
5943 if (!val) gtk_widget_destroy(compose->window);
5946 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5948 Compose *compose = (Compose *)data;
5952 MsgFlags flag = {0, 0};
5953 static gboolean lock = FALSE;
5957 draft = account_get_special_folder(compose->account, F_DRAFT);
5958 g_return_if_fail(draft != NULL);
5962 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5963 G_DIR_SEPARATOR, (gint)compose);
5965 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5971 folder_item_scan(draft);
5972 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) < 0) {
5979 draft->mtime = 0; /* force updating */
5981 if (compose->mode == COMPOSE_REEDIT) {
5982 compose_remove_reedit_target(compose);
5983 if (compose->targetinfo &&
5984 compose->targetinfo->folder != draft)
5985 folderview_update_item(compose->targetinfo->folder,
5989 procmsg_add_flags(draft, msgnum, flag);
5990 folder_item_scan(draft);
5991 folderview_update_item(draft, TRUE);
5995 /* 0: quit editing 1: keep editing */
5997 gtk_widget_destroy(compose->window);
6002 path = folder_item_fetch_msg(draft, msgnum);
6003 g_return_if_fail(path != NULL);
6004 if (stat(path, &s) < 0) {
6005 FILE_OP_ERROR(path, "stat");
6012 procmsg_msginfo_free(compose->targetinfo);
6013 compose->targetinfo = g_new0(MsgInfo, 1);
6014 compose->targetinfo->msgnum = msgnum;
6015 compose->targetinfo->size = s.st_size;
6016 compose->targetinfo->mtime = s.st_mtime;
6017 compose->targetinfo->folder = draft;
6018 compose->mode = COMPOSE_REEDIT;
6022 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6024 Compose *compose = (Compose *)data;
6027 if (compose->bounce_filename != NULL)
6030 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6035 for ( tmp = file_list; tmp; tmp = tmp->next) {
6036 gchar *file = (gchar *) tmp->data;
6037 compose_attach_append(compose, file, file, NULL);
6038 compose_changed_cb(NULL, compose);
6041 g_list_free(file_list);
6045 static void compose_insert_file_cb(gpointer data, guint action,
6048 Compose *compose = (Compose *)data;
6051 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6056 for ( tmp = file_list; tmp; tmp = tmp->next) {
6057 gchar *file = (gchar *) tmp->data;
6058 compose_insert_file(compose, file);
6061 g_list_free(file_list);
6065 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6068 compose_close_cb(data, 0, NULL);
6072 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6074 Compose *compose = (Compose *)data;
6077 if (compose->exteditor_tag != -1) {
6078 if (!compose_ext_editor_kill(compose))
6082 if (compose->modified) {
6083 val = alertpanel(_("Discard message"),
6084 _("This message has been modified. discard it?"),
6085 _("Discard"), _("to Draft"), _("Cancel"));
6088 case G_ALERTDEFAULT:
6090 case G_ALERTALTERNATE:
6091 compose_draft_cb(data, 0, NULL);
6097 gtk_widget_destroy(compose->window);
6100 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6102 Compose *compose = (Compose *)data;
6104 addressbook_open(compose);
6107 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6109 Compose *compose = (Compose *)data;
6114 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6115 g_return_if_fail(tmpl != NULL);
6117 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6119 val = alertpanel(_("Apply template"), msg,
6120 _("Replace"), _("Insert"), _("Cancel"));
6123 if (val == G_ALERTDEFAULT)
6124 compose_template_apply(compose, tmpl, TRUE);
6125 else if (val == G_ALERTALTERNATE)
6126 compose_template_apply(compose, tmpl, FALSE);
6129 static void compose_ext_editor_cb(gpointer data, guint action,
6132 Compose *compose = (Compose *)data;
6134 compose_exec_ext_editor(compose);
6137 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6139 compose_destroy(compose);
6142 static void compose_undo_cb(Compose *compose)
6144 undo_undo(compose->undostruct);
6147 static void compose_redo_cb(Compose *compose)
6149 undo_redo(compose->undostruct);
6152 static void compose_cut_cb(Compose *compose)
6154 if (compose->focused_editable &&
6155 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6156 gtk_editable_cut_clipboard
6157 (GTK_EDITABLE(compose->focused_editable));
6160 static void compose_copy_cb(Compose *compose)
6162 if (compose->focused_editable &&
6163 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6164 gtk_editable_copy_clipboard
6165 (GTK_EDITABLE(compose->focused_editable));
6168 static void compose_paste_cb(Compose *compose)
6170 if (compose->focused_editable &&
6171 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6172 gtk_editable_paste_clipboard
6173 (GTK_EDITABLE(compose->focused_editable));
6176 static void compose_allsel_cb(Compose *compose)
6178 if (compose->focused_editable &&
6179 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6180 gtk_editable_select_region
6181 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6184 static void compose_move_beginning_of_line_cb(Compose *compose)
6186 if (compose->focused_editable &&
6187 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6188 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6191 static void compose_gtk_stext_action_cb(Compose *compose, ComposeCallGtkSTextAction action)
6193 if (!(compose->focused_editable && GTK_WIDGET_HAS_FOCUS(compose->focused_editable))) return;
6196 case COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE:
6197 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6199 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER:
6200 gtk_stext_move_forward_character(GTK_STEXT(compose->focused_editable));
6202 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER:
6203 gtk_stext_move_backward_character(GTK_STEXT(compose->focused_editable));
6205 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD:
6206 gtk_stext_move_forward_word(GTK_STEXT(compose->focused_editable));
6208 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD:
6209 gtk_stext_move_backward_word(GTK_STEXT(compose->focused_editable));
6211 case COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE:
6212 gtk_stext_move_end_of_line(GTK_STEXT(compose->focused_editable));
6214 case COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE:
6215 gtk_stext_move_next_line(GTK_STEXT(compose->focused_editable));
6217 case COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE:
6218 gtk_stext_move_previous_line(GTK_STEXT(compose->focused_editable));
6220 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER:
6221 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6223 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER:
6224 gtk_stext_delete_backward_character(GTK_STEXT(compose->focused_editable));
6226 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD:
6227 gtk_stext_delete_forward_word(GTK_STEXT(compose->focused_editable));
6229 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD:
6230 gtk_stext_delete_backward_word(GTK_STEXT(compose->focused_editable));
6232 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE:
6233 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6235 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N:
6236 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6237 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6239 case COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END:
6240 gtk_stext_delete_to_line_end(GTK_STEXT(compose->focused_editable));
6247 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6249 if (GTK_IS_EDITABLE(widget))
6250 compose->focused_editable = widget;
6253 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6255 if (compose->modified == FALSE) {
6256 compose->modified = TRUE;
6257 compose_set_title(compose);
6261 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6264 gtk_stext_set_point(GTK_STEXT(widget),
6265 gtk_editable_get_position(GTK_EDITABLE(widget)));
6269 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6272 gtk_stext_set_point(GTK_STEXT(widget),
6273 gtk_editable_get_position(GTK_EDITABLE(widget)));
6277 #if 0 /* NEW COMPOSE GUI */
6278 static void compose_toggle_to_cb(gpointer data, guint action,
6281 Compose *compose = (Compose *)data;
6283 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6284 gtk_widget_show(compose->to_hbox);
6285 gtk_widget_show(compose->to_entry);
6286 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6287 compose->use_to = TRUE;
6289 gtk_widget_hide(compose->to_hbox);
6290 gtk_widget_hide(compose->to_entry);
6291 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6292 gtk_widget_queue_resize(compose->table_vbox);
6293 compose->use_to = FALSE;
6296 if (addressbook_get_target_compose() == compose)
6297 addressbook_set_target_compose(compose);
6300 static void compose_toggle_cc_cb(gpointer data, guint action,
6303 Compose *compose = (Compose *)data;
6305 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6306 gtk_widget_show(compose->cc_hbox);
6307 gtk_widget_show(compose->cc_entry);
6308 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6309 compose->use_cc = TRUE;
6311 gtk_widget_hide(compose->cc_hbox);
6312 gtk_widget_hide(compose->cc_entry);
6313 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6314 gtk_widget_queue_resize(compose->table_vbox);
6315 compose->use_cc = FALSE;
6318 if (addressbook_get_target_compose() == compose)
6319 addressbook_set_target_compose(compose);
6322 static void compose_toggle_bcc_cb(gpointer data, guint action,
6325 Compose *compose = (Compose *)data;
6327 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6328 gtk_widget_show(compose->bcc_hbox);
6329 gtk_widget_show(compose->bcc_entry);
6330 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6331 compose->use_bcc = TRUE;
6333 gtk_widget_hide(compose->bcc_hbox);
6334 gtk_widget_hide(compose->bcc_entry);
6335 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6336 gtk_widget_queue_resize(compose->table_vbox);
6337 compose->use_bcc = FALSE;
6340 if (addressbook_get_target_compose() == compose)
6341 addressbook_set_target_compose(compose);
6344 static void compose_toggle_replyto_cb(gpointer data, guint action,
6347 Compose *compose = (Compose *)data;
6349 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6350 gtk_widget_show(compose->reply_hbox);
6351 gtk_widget_show(compose->reply_entry);
6352 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6353 compose->use_replyto = TRUE;
6355 gtk_widget_hide(compose->reply_hbox);
6356 gtk_widget_hide(compose->reply_entry);
6357 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6358 gtk_widget_queue_resize(compose->table_vbox);
6359 compose->use_replyto = FALSE;
6363 static void compose_toggle_followupto_cb(gpointer data, guint action,
6366 Compose *compose = (Compose *)data;
6368 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6369 gtk_widget_show(compose->followup_hbox);
6370 gtk_widget_show(compose->followup_entry);
6371 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6372 compose->use_followupto = TRUE;
6374 gtk_widget_hide(compose->followup_hbox);
6375 gtk_widget_hide(compose->followup_entry);
6376 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6377 gtk_widget_queue_resize(compose->table_vbox);
6378 compose->use_followupto = FALSE;
6382 static void compose_toggle_attach_cb(gpointer data, guint action,
6385 Compose *compose = (Compose *)data;
6387 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6388 gtk_widget_ref(compose->edit_vbox);
6390 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6391 compose->edit_vbox);
6392 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6393 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6395 gtk_widget_show(compose->paned);
6397 gtk_widget_unref(compose->edit_vbox);
6398 gtk_widget_unref(compose->paned);
6400 compose->use_attach = TRUE;
6402 gtk_widget_ref(compose->paned);
6403 gtk_widget_ref(compose->edit_vbox);
6405 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6407 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6408 compose->edit_vbox);
6409 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6410 compose->edit_vbox, TRUE, TRUE, 0);
6412 gtk_widget_unref(compose->edit_vbox);
6414 compose->use_attach = FALSE;
6420 static void compose_toggle_sign_cb(gpointer data, guint action,
6423 Compose *compose = (Compose *)data;
6425 if (GTK_CHECK_MENU_ITEM(widget)->active)
6426 compose->use_signing = TRUE;
6428 compose->use_signing = FALSE;
6431 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6434 Compose *compose = (Compose *)data;
6436 if (GTK_CHECK_MENU_ITEM(widget)->active)
6437 compose->use_encryption = TRUE;
6439 compose->use_encryption = FALSE;
6441 #endif /* USE_GPGME */
6443 static void compose_toggle_ruler_cb(gpointer data, guint action,
6446 Compose *compose = (Compose *)data;
6448 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6449 gtk_widget_show(compose->ruler_hbox);
6450 prefs_common.show_ruler = TRUE;
6452 gtk_widget_hide(compose->ruler_hbox);
6453 gtk_widget_queue_resize(compose->edit_vbox);
6454 prefs_common.show_ruler = FALSE;
6458 static void compose_attach_drag_received_cb (GtkWidget *widget,
6459 GdkDragContext *drag_context,
6462 GtkSelectionData *data,
6467 Compose *compose = (Compose *)user_data;
6470 list = uri_list_extract_filenames((const gchar *)data->data);
6471 for (tmp = list; tmp != NULL; tmp = tmp->next)
6472 compose_attach_append
6473 (compose, (const gchar *)tmp->data,
6474 (const gchar *)tmp->data, NULL);
6475 if (list) compose_changed_cb(NULL, compose);
6476 list_free_strings(list);
6480 static void compose_insert_drag_received_cb (GtkWidget *widget,
6481 GdkDragContext *drag_context,
6484 GtkSelectionData *data,
6489 Compose *compose = (Compose *)user_data;
6492 list = uri_list_extract_filenames((const gchar *)data->data);
6493 for (tmp = list; tmp != NULL; tmp = tmp->next)
6494 compose_insert_file(compose, (const gchar *)tmp->data);
6495 list_free_strings(list);
6499 #if 0 /* NEW COMPOSE GUI */
6500 static void to_activated(GtkWidget *widget, Compose *compose)
6502 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6503 gtk_widget_grab_focus(compose->newsgroups_entry);
6505 gtk_widget_grab_focus(compose->subject_entry);
6508 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6510 gtk_widget_grab_focus(compose->subject_entry);
6513 static void subject_activated(GtkWidget *widget, Compose *compose)
6515 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6516 gtk_widget_grab_focus(compose->cc_entry);
6517 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6518 gtk_widget_grab_focus(compose->bcc_entry);
6519 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6520 gtk_widget_grab_focus(compose->reply_entry);
6521 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6522 gtk_widget_grab_focus(compose->followup_entry);
6524 gtk_widget_grab_focus(compose->text);
6527 static void cc_activated(GtkWidget *widget, Compose *compose)
6529 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6530 gtk_widget_grab_focus(compose->bcc_entry);
6531 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6532 gtk_widget_grab_focus(compose->reply_entry);
6533 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6534 gtk_widget_grab_focus(compose->followup_entry);
6536 gtk_widget_grab_focus(compose->text);
6539 static void bcc_activated(GtkWidget *widget, Compose *compose)
6541 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6542 gtk_widget_grab_focus(compose->reply_entry);
6543 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6544 gtk_widget_grab_focus(compose->followup_entry);
6546 gtk_widget_grab_focus(compose->text);
6549 static void replyto_activated(GtkWidget *widget, Compose *compose)
6551 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6552 gtk_widget_grab_focus(compose->followup_entry);
6554 gtk_widget_grab_focus(compose->text);
6557 static void followupto_activated(GtkWidget *widget, Compose *compose)
6559 gtk_widget_grab_focus(compose->text);
6563 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6566 Compose *compose = (Compose *)data;
6568 if (GTK_CHECK_MENU_ITEM(widget)->active)
6569 compose->return_receipt = TRUE;
6571 compose->return_receipt = FALSE;
6574 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6576 ComposeHeaderEntry *headerentry)
6578 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6579 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6580 !(event->state & GDK_MODIFIER_MASK) &&
6581 (event->keyval == GDK_BackSpace) &&
6582 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6583 gtk_container_remove
6584 (GTK_CONTAINER(headerentry->compose->header_table),
6585 headerentry->combo);
6586 gtk_container_remove
6587 (GTK_CONTAINER(headerentry->compose->header_table),
6588 headerentry->entry);
6589 headerentry->compose->header_list =
6590 g_slist_remove(headerentry->compose->header_list,
6592 g_free(headerentry);
6593 } else if (event->keyval == GDK_Tab) {
6594 if (headerentry->compose->header_last == headerentry) {
6595 /* Override default next focus, and give it to subject_entry
6596 * instead of notebook tabs
6598 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6599 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6605 void compose_headerentry_changed_cb(GtkWidget *entry,
6606 ComposeHeaderEntry *headerentry)
6608 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6609 headerentry->compose->header_list =
6610 g_slist_append(headerentry->compose->header_list,
6612 compose_create_header_entry(headerentry->compose);
6613 gtk_signal_disconnect_by_func
6615 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6617 /* Automatically scroll down */
6618 compose_show_first_last_header(headerentry->compose, FALSE);
6623 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6625 GtkAdjustment *vadj;
6627 g_return_if_fail(compose);
6628 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6629 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6631 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6632 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6635 static void text_activated(GtkWidget *widget, Compose *compose)
6637 compose_send_control_enter(compose);
6640 static gboolean compose_send_control_enter(Compose *compose)
6644 GtkItemFactory *ifactory;
6645 GtkAccelEntry *accel;
6646 GtkWidget *send_menu;
6648 GdkModifierType ignored_mods =
6649 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
6650 GDK_MOD4_MASK | GDK_MOD5_MASK);
6652 ev = gtk_get_current_event();
6653 if (ev->type != GDK_KEY_PRESS) return FALSE;
6655 kev = (GdkEventKey *)ev;
6656 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6659 ifactory = gtk_item_factory_from_widget(compose->menubar);
6660 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6661 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6662 accel = (GtkAccelEntry *)list->data;
6663 if (accel->accelerator_key == kev->keyval &&
6664 (accel->accelerator_mods & ~ignored_mods) ==
6665 (kev->state & ~ignored_mods)) {
6666 compose_send_cb(compose, 0, NULL);
6674 static void compose_check_all(Compose *compose)
6676 if (compose->gtkpspell)
6677 gtkpspell_check_all(compose->gtkpspell);
6680 static void compose_highlight_all(Compose *compose)
6682 if (compose->gtkpspell)
6683 gtkpspell_highlight_all(compose->gtkpspell);
6686 static void compose_check_backwards(Compose *compose)
6688 if (compose->gtkpspell)
6689 gtkpspell_check_backwards(compose->gtkpspell);
6691 GtkItemFactory *ifactory;
6692 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6693 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6694 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6698 static void compose_check_forwards_go(Compose *compose)
6700 if (compose->gtkpspell)
6701 gtkpspell_check_forwards_go(compose->gtkpspell);
6703 GtkItemFactory *ifactory;
6704 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6705 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6706 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6711 static void set_toolbar_style(Compose *compose)
6713 switch (prefs_common.toolbar_style) {
6715 gtk_widget_hide(compose->handlebox);
6718 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6722 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6726 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6731 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
6732 gtk_widget_show(compose->handlebox);
6733 gtk_widget_queue_resize(compose->handlebox);