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"
109 # include "rfc2015.h"
119 #define N_ATTACH_COLS 3
123 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
124 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
125 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
126 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
127 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
128 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
129 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
130 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
131 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
132 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
133 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
134 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
135 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
136 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
137 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
138 } ComposeCallGtkSTextAction;
140 #define B64_LINE_SIZE 57
141 #define B64_BUFFSIZE 77
143 #define MAX_REFERENCES_LEN 999
145 static GdkColor quote_color = {0, 0, 0, 0xbfff};
147 static GList *compose_list = NULL;
149 Compose *compose_generic_new (PrefsAccount *account,
153 static Compose *compose_create (PrefsAccount *account,
155 static void compose_toolbar_create (Compose *compose,
156 GtkWidget *container);
157 static GtkWidget *compose_account_option_menu_create
159 static void compose_set_template_menu (Compose *compose);
160 static void compose_template_apply (Compose *compose,
162 static void compose_destroy (Compose *compose);
164 static void compose_entries_set (Compose *compose,
165 const gchar *mailto);
166 static gint compose_parse_header (Compose *compose,
168 static gchar *compose_parse_references (const gchar *ref,
171 static gchar *compose_quote_fmt (Compose *compose,
176 static void compose_reply_set_entry (Compose *compose,
181 followup_and_reply_to);
182 static void compose_reedit_set_entry (Compose *compose,
184 static void compose_insert_sig (Compose *compose);
185 static void compose_insert_file (Compose *compose,
187 static void compose_attach_append (Compose *compose,
189 ContentType cnttype);
190 static void compose_attach_append_with_type(Compose *compose,
193 ContentType cnttype);
194 static void compose_wrap_line (Compose *compose);
195 static void compose_wrap_line_all (Compose *compose);
196 static void compose_set_title (Compose *compose);
198 static PrefsAccount *compose_current_mail_account(void);
199 /* static gint compose_send (Compose *compose); */
200 static gint compose_write_to_file (Compose *compose,
203 static gint compose_write_body_to_file (Compose *compose,
205 static gint compose_save_to_outbox (Compose *compose,
207 static gint compose_remove_reedit_target (Compose *compose);
208 static gint compose_queue (Compose *compose,
211 static void compose_write_attach (Compose *compose,
213 static gint compose_write_headers (Compose *compose,
215 const gchar *charset,
216 EncodingType encoding,
219 static void compose_convert_header (gchar *dest,
223 static void compose_generate_msgid (Compose *compose,
227 static void compose_attach_info_free (AttachInfo *ainfo);
228 static void compose_attach_remove_selected (Compose *compose);
230 static void compose_attach_property (Compose *compose);
231 static void compose_attach_property_create (gboolean *cancelled);
232 static void attach_property_ok (GtkWidget *widget,
233 gboolean *cancelled);
234 static void attach_property_cancel (GtkWidget *widget,
235 gboolean *cancelled);
236 static gint attach_property_delete_event (GtkWidget *widget,
238 gboolean *cancelled);
239 static void attach_property_key_pressed (GtkWidget *widget,
241 gboolean *cancelled);
243 static void compose_exec_ext_editor (Compose *compose);
244 static gint compose_exec_ext_editor_real (const gchar *file);
245 static gboolean compose_ext_editor_kill (Compose *compose);
246 static void compose_input_cb (gpointer data,
248 GdkInputCondition condition);
249 static void compose_set_ext_editor_sensitive (Compose *compose,
252 static void compose_undo_state_changed (UndoMain *undostruct,
257 static gint calc_cursor_xpos (GtkSText *text,
261 static void compose_create_header_entry (Compose *compose);
262 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
264 /* callback functions */
266 static gboolean compose_edit_size_alloc (GtkEditable *widget,
267 GtkAllocation *allocation,
268 GtkSHRuler *shruler);
270 static void toolbar_send_cb (GtkWidget *widget,
272 static void toolbar_send_later_cb (GtkWidget *widget,
274 static void toolbar_draft_cb (GtkWidget *widget,
276 static void toolbar_insert_cb (GtkWidget *widget,
278 static void toolbar_attach_cb (GtkWidget *widget,
280 static void toolbar_sig_cb (GtkWidget *widget,
282 static void toolbar_ext_editor_cb (GtkWidget *widget,
284 static void toolbar_linewrap_cb (GtkWidget *widget,
286 static void toolbar_address_cb (GtkWidget *widget,
289 static void select_account (Compose *compose,
292 static void account_activated (GtkMenuItem *menuitem,
295 static void attach_selected (GtkCList *clist,
300 static void attach_button_pressed (GtkWidget *widget,
301 GdkEventButton *event,
303 static void attach_key_pressed (GtkWidget *widget,
307 static void compose_send_cb (gpointer data,
310 static void compose_send_later_cb (gpointer data,
314 static void compose_draft_cb (gpointer data,
318 static void compose_attach_cb (gpointer data,
321 static void compose_insert_file_cb (gpointer data,
325 static void compose_close_cb (gpointer data,
329 static void compose_address_cb (gpointer data,
332 static void compose_template_activate_cb(GtkWidget *widget,
335 static void compose_ext_editor_cb (gpointer data,
339 static gint compose_delete_cb (GtkWidget *widget,
342 static void compose_destroy_cb (GtkWidget *widget,
345 static void compose_undo_cb (Compose *compose);
346 static void compose_redo_cb (Compose *compose);
347 static void compose_cut_cb (Compose *compose);
348 static void compose_copy_cb (Compose *compose);
349 static void compose_paste_cb (Compose *compose);
350 static void compose_allsel_cb (Compose *compose);
352 static void compose_gtk_stext_action_cb (Compose *compose,
353 ComposeCallGtkSTextAction action);
355 static void compose_grab_focus_cb (GtkWidget *widget,
358 static void compose_changed_cb (GtkEditable *editable,
360 static void compose_button_press_cb (GtkWidget *widget,
361 GdkEventButton *event,
364 static void compose_key_press_cb (GtkWidget *widget,
370 static void compose_toggle_to_cb (gpointer data,
373 static void compose_toggle_cc_cb (gpointer data,
376 static void compose_toggle_bcc_cb (gpointer data,
379 static void compose_toggle_replyto_cb (gpointer data,
382 static void compose_toggle_followupto_cb(gpointer data,
385 static void compose_toggle_attach_cb (gpointer data,
389 static void compose_toggle_ruler_cb (gpointer data,
393 static void compose_toggle_sign_cb (gpointer data,
396 static void compose_toggle_encrypt_cb (gpointer data,
400 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
403 static void compose_attach_drag_received_cb (GtkWidget *widget,
404 GdkDragContext *drag_context,
407 GtkSelectionData *data,
411 static void compose_insert_drag_received_cb (GtkWidget *widget,
412 GdkDragContext *drag_context,
415 GtkSelectionData *data,
421 static void to_activated (GtkWidget *widget,
423 static void newsgroups_activated (GtkWidget *widget,
425 static void subject_activated (GtkWidget *widget,
427 static void cc_activated (GtkWidget *widget,
429 static void bcc_activated (GtkWidget *widget,
431 static void replyto_activated (GtkWidget *widget,
433 static void followupto_activated (GtkWidget *widget,
437 static void compose_attach_parts (Compose *compose,
440 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
442 gboolean ignore_replyto,
443 gboolean followup_and_reply_to);
445 void compose_headerentry_changed_cb (GtkWidget *entry,
446 ComposeHeaderEntry *headerentry);
447 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
449 ComposeHeaderEntry *headerentry);
451 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
455 static void compose_check_all (Compose *compose);
456 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,
466 static GtkItemFactoryEntry compose_popup_entries[] =
468 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
469 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
470 {N_("/---"), NULL, NULL, 0, "<Separator>"},
471 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
474 static GtkItemFactoryEntry compose_entries[] =
476 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
477 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
478 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
479 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
480 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
481 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
483 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
484 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
485 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
486 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
487 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
488 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
489 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
490 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
491 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
492 {N_("/_Edit/A_dvanced/Move a character backward"),
494 compose_gtk_stext_action_cb,
495 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
497 {N_("/_Edit/A_dvanced/Move a character forward"),
499 compose_gtk_stext_action_cb,
500 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
502 {N_("/_Edit/A_dvanced/Move a word backward"),
504 compose_gtk_stext_action_cb,
505 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
507 {N_("/_Edit/A_dvanced/Move a word forward"),
509 compose_gtk_stext_action_cb,
510 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
512 {N_("/_Edit/A_dvanced/Move to beginning of line"),
513 NULL, /* "<control>A" */
514 compose_gtk_stext_action_cb,
515 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
517 {N_("/_Edit/A_dvanced/Move to end of line"),
519 compose_gtk_stext_action_cb,
520 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
522 {N_("/_Edit/A_dvanced/Move to previous line"),
524 compose_gtk_stext_action_cb,
525 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
527 {N_("/_Edit/A_dvanced/Move to next line"),
529 compose_gtk_stext_action_cb,
530 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
532 {N_("/_Edit/A_dvanced/Delete a character backward"),
534 compose_gtk_stext_action_cb,
535 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
537 {N_("/_Edit/A_dvanced/Delete a character forward"),
539 compose_gtk_stext_action_cb,
540 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
542 {N_("/_Edit/A_dvanced/Delete a word backward"),
543 NULL, /* "<control>W" */
544 compose_gtk_stext_action_cb,
545 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
547 {N_("/_Edit/A_dvanced/Delete a word forward"),
549 compose_gtk_stext_action_cb,
550 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
552 {N_("/_Edit/A_dvanced/Delete line"),
554 compose_gtk_stext_action_cb,
555 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
557 {N_("/_Edit/A_dvanced/Delete to end of line"),
559 compose_gtk_stext_action_cb,
560 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
562 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
563 {N_("/_Edit/_Wrap current paragraph"),
564 "<control>L", compose_wrap_line, 0, NULL},
565 {N_("/_Edit/Wrap all long _lines"),
566 "<control><alt>L", compose_wrap_line_all, 0, NULL},
567 {N_("/_Edit/Edit with e_xternal editor"),
568 "<control>X", compose_ext_editor_cb, 0, NULL},
570 {N_("/_Spelling/Check all or selection"),NULL, compose_check_all, 0, NULL},
571 {N_("/_Spelling/Check backwards misspelled word"), NULL, compose_check_backwards , 0, NULL},
572 {N_("/_Spelling/Forward to next misspelled word"), NULL, compose_check_forwards_go, 0, NULL},
573 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
574 {N_("/_Spelling/Spelling Configuration"),NULL, NULL, 0, "<Branch>"},
576 #if 0 /* NEW COMPOSE GUI */
577 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
578 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
579 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
580 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
581 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
582 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
583 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
584 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
585 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
586 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
587 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
589 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
590 {N_("/_Message/_Send"), "<control>Return",
591 compose_send_cb, 0, NULL},
592 {N_("/_Message/Send _later"), "<shift><alt>S",
593 compose_send_later_cb, 0, NULL},
594 {N_("/_Message/Save to _draft folder"),
595 "<alt>D", compose_draft_cb, 0, NULL},
596 {N_("/_Message/Save and _keep editing"),
597 "<control>S", compose_draft_cb, 1, NULL},
598 #if 0 /* NEW COMPOSE GUI */
599 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
600 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
601 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
602 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
603 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
604 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
605 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
606 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
607 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
610 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
611 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
612 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
613 #endif /* USE_GPGME */
614 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
615 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
616 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
617 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
618 {N_("/_Tool/_Address book"), "<control><alt>A", compose_address_cb , 0, NULL},
619 {N_("/_Tool/_Template"), NULL, NULL, 0, "<Branch>"},
620 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
621 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
624 static GtkTargetEntry compose_mime_types[] =
626 {"text/uri-list", 0, 0}
629 Compose *compose_new(PrefsAccount *account)
631 return compose_generic_new(account, NULL, NULL);
634 Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
638 GtkItemFactory *ifactory;
640 c = compose_generic_new(account, NULL, NULL);
642 filename = procmsg_get_message_file(msginfo);
643 if (filename == NULL)
646 c->bounce_filename = filename;
648 if (msginfo->subject)
649 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
651 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
653 compose_quote_fmt(c, msginfo, "%M", NULL);
654 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
656 ifactory = gtk_item_factory_from_widget(c->popupmenu);
657 menu_set_sensitive(ifactory, "/Add...", FALSE);
658 menu_set_sensitive(ifactory, "/Remove", FALSE);
659 menu_set_sensitive(ifactory, "/Property...", FALSE);
661 ifactory = gtk_item_factory_from_widget(c->menubar);
662 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
663 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
664 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
665 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
666 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
667 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
668 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
669 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
671 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
672 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
674 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
675 menu_set_sensitive(ifactory, "/Tool/Template", FALSE);
677 gtk_widget_set_sensitive(c->insert_btn, FALSE);
678 gtk_widget_set_sensitive(c->attach_btn, FALSE);
679 gtk_widget_set_sensitive(c->sig_btn, FALSE);
680 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
681 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
686 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
688 return compose_generic_new(account, mailto, NULL);
691 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
693 return compose_generic_new(account, NULL, item);
696 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
700 if (item && item->prefs && item->prefs->enable_default_account)
701 account = account_find_from_id(item->prefs->default_account);
703 if (!account) account = cur_account;
704 g_return_val_if_fail(account != NULL, NULL);
706 compose = compose_create(account, COMPOSE_NEW);
707 compose->replyinfo = NULL;
709 if (prefs_common.auto_sig)
710 compose_insert_sig(compose);
711 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
712 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
714 if (account->protocol != A_NNTP) {
716 compose_entries_set(compose, mailto);
718 } else if(item && item->prefs->enable_default_to) {
719 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
721 if (item && item->ret_rcpt) {
722 GtkItemFactory *ifactory;
724 ifactory = gtk_item_factory_from_widget(compose->menubar);
725 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
729 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
732 compose_show_first_last_header(compose, TRUE);
734 /* Set save folder */
735 if(item && item->prefs && item->prefs->save_copy_to_folder) {
736 gchar *folderidentifier;
738 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
739 folderidentifier = folder_item_get_identifier(item);
740 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
741 g_free(folderidentifier);
744 gtk_widget_grab_focus(compose->header_last->entry);
746 if (prefs_common.auto_exteditor)
747 compose_exec_ext_editor(compose);
752 #define CHANGE_FLAGS(msginfo) \
754 if (msginfo->folder->folder->change_flags != NULL) \
755 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
761 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
762 const gchar *followupto, gchar * to)
766 if (!account) account = cur_account;
767 g_return_val_if_fail(account != NULL, NULL);
768 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
770 compose = compose_create(account, COMPOSE_NEW);
772 if (prefs_common.auto_sig)
773 compose_insert_sig(compose);
774 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
775 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
777 compose_entry_append(compose, to, COMPOSE_TO);
778 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
779 gtk_widget_grab_focus(compose->subject_entry);
785 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
786 gboolean ignore_replyto)
788 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
791 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
793 gboolean ignore_replyto)
795 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
798 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
800 gboolean ignore_replyto,
801 gboolean followup_and_reply_to)
804 PrefsAccount *account;
805 PrefsAccount *reply_account;
808 g_return_if_fail(msginfo != NULL);
809 g_return_if_fail(msginfo->folder != NULL);
812 /* select the account set in folderitem's property (if enabled) */
813 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
814 account = account_find_from_id(msginfo->folder->prefs->default_account);
816 /* select the account for the whole folder (IMAP / NNTP) */
818 /* FIXME: this is not right, because folder may be nested. we should
819 * ascend the tree until we find a parent with proper account
821 account = msginfo->folder->folder->account;
823 /* select account by to: and cc: header if enabled */
824 if (prefs_common.reply_account_autosel) {
825 if (!account && msginfo->to) {
827 Xstrdup_a(to, msginfo->to, return);
829 account = account_find_from_address(to);
833 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
835 account = account_find_from_address(cc);
840 /* select current account */
841 if (!account) account = cur_account;
842 g_return_if_fail(account != NULL);
844 if (ignore_replyto && account->protocol == A_NNTP &&
845 !followup_and_reply_to) {
847 account_find_from_address(account->address);
849 reply_account = compose_current_mail_account();
853 reply_account = account;
855 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
856 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
857 if (MSG_IS_IMAP(msginfo->flags))
858 imap_msg_set_perm_flags(msginfo, MSG_REPLIED);
859 CHANGE_FLAGS(msginfo);
861 compose = compose_create(account, COMPOSE_REPLY);
862 compose->replyinfo = procmsg_msginfo_copy(msginfo);
864 #if 0 /* NEW COMPOSE GUI */
865 if (followup_and_reply_to) {
866 gtk_widget_show(compose->to_hbox);
867 gtk_widget_show(compose->to_entry);
868 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
869 compose->use_to = TRUE;
872 if (msginfo->folder && msginfo->folder->ret_rcpt) {
873 GtkItemFactory *ifactory;
875 ifactory = gtk_item_factory_from_widget(compose->menubar);
876 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
879 /* Set save folder */
880 if(msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
881 gchar *folderidentifier;
883 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
884 folderidentifier = folder_item_get_identifier(msginfo->folder);
885 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
886 g_free(folderidentifier);
889 if (compose_parse_header(compose, msginfo) < 0) return;
890 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
891 followup_and_reply_to);
892 compose_show_first_last_header(compose, TRUE);
894 text = GTK_STEXT(compose->text);
895 gtk_stext_freeze(text);
901 if (prefs_common.quotemark && *prefs_common.quotemark)
902 qmark = prefs_common.quotemark;
906 quote_str = compose_quote_fmt(compose, msginfo,
907 prefs_common.quotefmt,
911 if (prefs_common.auto_sig)
912 compose_insert_sig(compose);
914 if (quote && prefs_common.linewrap_quote)
915 compose_wrap_line_all(compose);
917 gtk_editable_set_position(GTK_EDITABLE(text), 0);
918 gtk_stext_set_point(text, 0);
920 gtk_stext_thaw(text);
921 gtk_widget_grab_focus(compose->text);
923 if (prefs_common.auto_exteditor)
924 compose_exec_ext_editor(compose);
928 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
933 g_return_val_if_fail(mimeinfo != NULL, NULL);
935 base = mimeinfo->filename ? mimeinfo->filename
936 : mimeinfo->name ? mimeinfo->name : NULL;
938 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
939 filename = g_strdup_printf("%s%smimetmp.%08x.html",
946 base = base ? base : "";
947 base = g_basename(base);
949 filename = g_strdup_printf("%s%smimetmp.%08x",
957 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
963 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
967 if (!partinfo) return NULL;
969 filename = procmime_get_file_name(partinfo);
971 if (procmime_get_part(filename, source, partinfo) < 0)
973 (_("Can't get the part of multipart message."));
978 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
986 gint boundary_len = 0;
988 glong fpos, prev_fpos;
993 g_return_if_fail(msginfo != NULL);
997 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
998 mimeinfo = procmime_scan_mime_header(fp, MIME_TEXT);
999 if (!mimeinfo) break;
1001 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
1002 rfc2015_is_encrypted(mimeinfo)) {
1003 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
1005 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
1006 !msginfo->plaintext_file &&
1007 !msginfo->decryption_failed) {
1008 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
1009 if (msginfo->plaintext_file &&
1010 !msginfo->decryption_failed) {
1018 #else /* !USE_GPGME */
1019 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
1020 mimeinfo = procmime_scan_mime_header(fp, MIME_TEXT);
1021 #endif /* USE_GPGME */
1024 if (!mimeinfo) return;
1025 if (mimeinfo->mime_type == MIME_TEXT)
1028 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
1030 g_return_if_fail(mimeinfo != NULL);
1031 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
1033 if (mimeinfo->mime_type == MIME_MULTIPART) {
1034 g_return_if_fail(mimeinfo->boundary != NULL);
1035 g_return_if_fail(mimeinfo->sub == NULL);
1037 g_return_if_fail(fp != NULL);
1039 boundary = mimeinfo->boundary;
1042 boundary_len = strlen(boundary);
1044 /* look for first boundary */
1045 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
1046 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
1053 if ((fpos = ftell(fp)) < 0) {
1059 for (npart = 0;; npart++) {
1061 gboolean eom = FALSE;
1065 partinfo = procmime_scan_mime_header(fp, MIME_TEXT);
1066 if (!partinfo) break;
1069 procmime_mimeinfo_insert(mimeinfo, partinfo);
1071 procmime_mimeinfo_free(partinfo);
1073 /* look for next boundary */
1075 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
1076 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
1077 if (buf[2 + boundary_len] == '-' &&
1078 buf[2 + boundary_len + 1] == '-')
1084 eom = TRUE; /* broken MIME message */
1087 partinfo->size = fpos - prev_fpos - strlen(buf);
1092 source = procmsg_get_message_file_path(msginfo);
1094 g_return_if_fail(mimeinfo != NULL);
1096 if (!mimeinfo->main && mimeinfo->parent)
1098 filename = mime_extract_file(source, mimeinfo);
1100 compose_attach_append_with_type(compose, filename,
1101 mimeinfo->content_type,
1102 mimeinfo->mime_type);
1107 if (mimeinfo->sub && mimeinfo->sub->children)
1109 filename = mime_extract_file(source, mimeinfo->sub);
1111 compose_attach_append_with_type(compose, filename,
1112 mimeinfo->content_type,
1113 mimeinfo->sub->mime_type);
1118 if (mimeinfo->children) {
1121 child = mimeinfo->children;
1123 filename = mime_extract_file(source, child);
1125 compose_attach_append_with_type(compose, filename,
1126 child->content_type,
1131 child = child->next;
1137 procmime_mimeinfo_free_all(mimeinfo);
1141 #define INSERT_FW_HEADER(var, hdr) \
1142 if (msginfo->var && *msginfo->var) { \
1143 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1144 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1145 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1148 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1152 /* PrefsAccount *account; */
1155 g_return_val_if_fail(msginfo != NULL, NULL);
1156 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1158 account = msginfo->folder->folder->account;
1159 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1161 Xstrdup_a(to, msginfo->to, return NULL);
1162 extract_address(to);
1163 account = account_find_from_address(to);
1166 if(!account && prefs_common.forward_account_autosel) {
1168 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1169 extract_address(cc);
1170 account = account_find_from_address(cc);
1174 if (account == NULL) {
1175 account = cur_account;
1177 account = msginfo->folder->folder->account;
1178 if (!account) account = cur_account;
1181 g_return_val_if_fail(account != NULL, NULL);
1183 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1184 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1185 if (MSG_IS_IMAP(msginfo->flags))
1186 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1187 CHANGE_FLAGS(msginfo);
1189 compose = compose_create(account, COMPOSE_FORWARD);
1191 if (msginfo->subject && *msginfo->subject) {
1192 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1193 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1197 text = GTK_STEXT(compose->text);
1198 gtk_stext_freeze(text);
1203 msgfile = procmsg_get_message_file_path(msginfo);
1204 if (!is_file_exist(msgfile))
1205 g_warning(_("%s: file not exist\n"), msgfile);
1207 compose_attach_append(compose, msgfile,
1208 MIME_MESSAGE_RFC822);
1215 if (prefs_common.fw_quotemark && *prefs_common.fw_quotemark)
1216 qmark = prefs_common.fw_quotemark;
1220 quote_str = compose_quote_fmt(compose, msginfo,
1221 prefs_common.fw_quotefmt, qmark);
1222 compose_attach_parts(compose, msginfo);
1225 if (prefs_common.auto_sig)
1226 compose_insert_sig(compose);
1228 if (prefs_common.linewrap_quote)
1229 compose_wrap_line_all(compose);
1231 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1232 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1234 gtk_stext_thaw(text);
1235 #if 0 /* NEW COMPOSE GUI */
1236 if (account->protocol != A_NNTP)
1237 gtk_widget_grab_focus(compose->to_entry);
1239 gtk_widget_grab_focus(compose->newsgroups_entry);
1241 gtk_widget_grab_focus(compose->header_last->entry);
1243 if (prefs_common.auto_exteditor)
1244 compose_exec_ext_editor(compose);
1249 #undef INSERT_FW_HEADER
1251 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1258 g_return_val_if_fail(msginfo_list != NULL, NULL);
1260 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1261 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1265 if (account == NULL) {
1266 account = cur_account;
1268 account = msginfo->folder->folder->account;
1269 if (!account) account = cur_account;
1272 g_return_val_if_fail(account != NULL, NULL);
1274 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1275 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1276 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1277 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1280 compose = compose_create(account, COMPOSE_FORWARD);
1282 text = GTK_STEXT(compose->text);
1283 gtk_stext_freeze(text);
1285 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1286 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1287 if (!is_file_exist(msgfile))
1288 g_warning(_("%s: file not exist\n"), msgfile);
1290 compose_attach_append(compose, msgfile,
1291 MIME_MESSAGE_RFC822);
1295 if (prefs_common.auto_sig)
1296 compose_insert_sig(compose);
1298 if (prefs_common.linewrap_quote)
1299 compose_wrap_line_all(compose);
1301 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1302 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1304 gtk_stext_thaw(text);
1305 #if 0 /* NEW COMPOSE GUI */
1306 if (account->protocol != A_NNTP)
1307 gtk_widget_grab_focus(compose->to_entry);
1309 gtk_widget_grab_focus(compose->newsgroups_entry);
1315 void compose_reedit(MsgInfo *msginfo)
1318 PrefsAccount *account = NULL;
1321 gchar buf[BUFFSIZE];
1323 g_return_if_fail(msginfo != NULL);
1324 g_return_if_fail(msginfo->folder != NULL);
1326 if (msginfo->folder->stype == F_QUEUE) {
1327 gchar queueheader_buf[BUFFSIZE];
1330 /* Select Account from queue headers */
1331 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1332 sizeof(queueheader_buf), "NAID:")) {
1333 id = atoi(&queueheader_buf[5]);
1334 account = account_find_from_id(id);
1336 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1337 sizeof(queueheader_buf), "MAID:")) {
1338 id = atoi(&queueheader_buf[5]);
1339 account = account_find_from_id(id);
1341 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1342 sizeof(queueheader_buf), "S:")) {
1343 account = account_find_from_address(queueheader_buf);
1346 account = msginfo->folder->folder->account;
1348 if (!account && prefs_common.reedit_account_autosel) {
1349 gchar from[BUFFSIZE];
1350 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1351 extract_address(from);
1352 account = account_find_from_address(from);
1355 if (!account) account = cur_account;
1356 g_return_if_fail(account != NULL);
1358 compose = compose_create(account, COMPOSE_REEDIT);
1359 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1361 if (msginfo->folder->stype == F_QUEUE) {
1362 gchar queueheader_buf[BUFFSIZE];
1364 /* Set message save folder */
1365 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1368 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1369 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1370 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1374 if (compose_parse_header(compose, msginfo) < 0) return;
1375 compose_reedit_set_entry(compose, msginfo);
1377 text = GTK_STEXT(compose->text);
1378 gtk_stext_freeze(text);
1380 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1381 g_warning(_("Can't get text part\n"));
1383 while (fgets(buf, sizeof(buf), fp) != NULL)
1384 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1387 compose_attach_parts(compose, msginfo);
1389 gtk_stext_thaw(text);
1390 gtk_widget_grab_focus(compose->text);
1392 if (prefs_common.auto_exteditor)
1393 compose_exec_ext_editor(compose);
1396 GList *compose_get_compose_list(void)
1398 return compose_list;
1401 void compose_entry_append(Compose *compose, const gchar *address,
1402 ComposeEntryType type)
1408 if (!address || *address == '\0') return;
1410 #if 0 /* NEW COMPOSE GUI */
1413 entry = GTK_ENTRY(compose->cc_entry);
1416 entry = GTK_ENTRY(compose->bcc_entry);
1418 case COMPOSE_NEWSGROUPS:
1419 entry = GTK_ENTRY(compose->newsgroups_entry);
1423 entry = GTK_ENTRY(compose->to_entry);
1427 text = gtk_entry_get_text(entry);
1429 gtk_entry_append_text(entry, ", ");
1430 gtk_entry_append_text(entry, address);
1438 header = N_("Bcc:");
1440 case COMPOSE_REPLYTO:
1441 header = N_("Reply-To:");
1443 case COMPOSE_NEWSGROUPS:
1444 header = N_("Newsgroups:");
1446 case COMPOSE_FOLLOWUPTO:
1447 header = N_( "Followup-To:");
1454 header = prefs_common.trans_hdr ? gettext(header) : header;
1456 compose_add_header_entry(compose, header, (gchar *)address);
1459 static void compose_entries_set(Compose *compose, const gchar *mailto)
1461 gchar *subject = NULL;
1469 Xstrdup_a(tmp_mailto, mailto, return);
1473 p = strchr(tmp_mailto, '?');
1480 gchar *field, *value;
1497 if (*value == '\0') continue;
1499 if (!g_strcasecmp(field, "subject")) {
1500 Xalloca(subject, strlen(value) + 1, return);
1501 decode_uri(subject, value);
1502 } else if (!g_strcasecmp(field, "cc")) {
1504 } else if (!g_strcasecmp(field, "bcc")) {
1506 } else if (!g_strcasecmp(field, "body")) {
1507 Xalloca(body, strlen(value) + 1, return);
1508 decode_uri(body, value);
1513 compose_entry_append(compose, to, COMPOSE_TO);
1515 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1517 compose_entry_append(compose, cc, COMPOSE_CC);
1519 compose_entry_append(compose, bcc, COMPOSE_BCC);
1521 gtk_stext_insert(GTK_STEXT(compose->text),
1522 NULL, NULL, NULL, body, -1);
1523 gtk_stext_insert(GTK_STEXT(compose->text),
1524 NULL, NULL, NULL, "\n", 1);
1528 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1530 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1531 {"Cc:", NULL, FALSE},
1532 {"References:", NULL, FALSE},
1533 {"Bcc:", NULL, FALSE},
1534 {"Newsgroups:", NULL, FALSE},
1535 {"Followup-To:", NULL, FALSE},
1536 {"X-Mailing-List:", NULL, FALSE},
1537 {"X-BeenThere:", NULL, FALSE},
1538 {NULL, NULL, FALSE}};
1548 H_X_MAILING_LIST = 6,
1554 g_return_val_if_fail(msginfo != NULL, -1);
1556 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1557 procheader_get_header_fields(fp, hentry);
1560 if (hentry[H_REPLY_TO].body != NULL) {
1561 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1562 compose->replyto = hentry[H_REPLY_TO].body;
1563 hentry[H_REPLY_TO].body = NULL;
1565 if (hentry[H_CC].body != NULL) {
1566 conv_unmime_header_overwrite(hentry[H_CC].body);
1567 compose->cc = hentry[H_CC].body;
1568 hentry[H_CC].body = NULL;
1570 if (hentry[H_X_MAILING_LIST].body != NULL) {
1571 /* this is good enough to parse debian-devel */
1572 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1573 g_return_val_if_fail(buf != NULL, -1 );
1574 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1575 compose->mailinglist = g_strdup(buf);
1577 g_free(hentry[H_X_MAILING_LIST].body);
1578 hentry[H_X_MAILING_LIST].body = NULL ;
1580 if (hentry[H_X_BEENTHERE].body != NULL) {
1581 /* this is good enough to parse the sylpheed-claws lists */
1582 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1583 g_return_val_if_fail(buf != NULL, -1 );
1584 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1585 compose->mailinglist = g_strdup(buf);
1587 g_free(hentry[H_X_BEENTHERE].body);
1588 hentry[H_X_BEENTHERE].body = NULL ;
1590 if (hentry[H_REFERENCES].body != NULL) {
1591 if (compose->mode == COMPOSE_REEDIT)
1592 compose->references = hentry[H_REFERENCES].body;
1594 compose->references = compose_parse_references
1595 (hentry[H_REFERENCES].body, msginfo->msgid);
1596 g_free(hentry[H_REFERENCES].body);
1598 hentry[H_REFERENCES].body = NULL;
1600 if (hentry[H_BCC].body != NULL) {
1601 if (compose->mode == COMPOSE_REEDIT) {
1602 conv_unmime_header_overwrite(hentry[H_BCC].body);
1603 compose->bcc = hentry[H_BCC].body;
1605 g_free(hentry[H_BCC].body);
1606 hentry[H_BCC].body = NULL;
1608 if (hentry[H_NEWSGROUPS].body != NULL) {
1609 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1610 hentry[H_NEWSGROUPS].body = NULL;
1612 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1613 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1614 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1615 hentry[H_FOLLOWUP_TO].body = NULL;
1618 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1619 compose->inreplyto = g_strdup(msginfo->inreplyto);
1620 else if (compose->mode != COMPOSE_REEDIT &&
1621 msginfo->msgid && *msginfo->msgid) {
1622 compose->inreplyto = g_strdup(msginfo->msgid);
1624 if (!compose->references) {
1625 if (msginfo->inreplyto && *msginfo->inreplyto)
1626 compose->references =
1627 g_strdup_printf("<%s>\n\t<%s>",
1631 compose->references =
1632 g_strconcat("<", msginfo->msgid, ">",
1640 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1642 GSList *ref_id_list, *cur;
1646 ref_id_list = references_list_append(NULL, ref);
1647 if (!ref_id_list) return NULL;
1648 if (msgid && *msgid)
1649 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1654 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1655 /* "<" + Message-ID + ">" + CR+LF+TAB */
1656 len += strlen((gchar *)cur->data) + 5;
1658 if (len > MAX_REFERENCES_LEN) {
1659 /* remove second message-ID */
1660 if (ref_id_list && ref_id_list->next &&
1661 ref_id_list->next->next) {
1662 g_free(ref_id_list->next->data);
1663 ref_id_list = g_slist_remove
1664 (ref_id_list, ref_id_list->next->data);
1666 slist_free_strings(ref_id_list);
1667 g_slist_free(ref_id_list);
1674 new_ref = g_string_new("");
1675 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1676 if (new_ref->len > 0)
1677 g_string_append(new_ref, "\n\t");
1678 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1681 slist_free_strings(ref_id_list);
1682 g_slist_free(ref_id_list);
1684 new_ref_str = new_ref->str;
1685 g_string_free(new_ref, FALSE);
1690 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1691 const gchar *fmt, const gchar *qmark)
1693 GtkSText *text = GTK_STEXT(compose->text);
1694 gchar *quote_str = NULL;
1699 if (qmark != NULL) {
1700 quote_fmt_init(msginfo, NULL);
1701 quote_fmt_scan_string(qmark);
1704 buf = quote_fmt_get_buffer();
1706 alertpanel_error(_("Quote mark format error."));
1708 Xstrdup_a(quote_str, buf, return NULL)
1711 if (fmt && *fmt != '\0') {
1712 quote_fmt_init(msginfo, quote_str);
1713 quote_fmt_scan_string(fmt);
1716 buf = quote_fmt_get_buffer();
1718 alertpanel_error(_("Message reply/forward format error."));
1724 gtk_stext_freeze(text);
1725 gtk_stext_set_point(text, 0);
1726 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
1728 for (p = buf; *p != '\0'; ) {
1729 lastp = strchr(p, '\n');
1730 len = lastp ? lastp - p + 1 : -1;
1731 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1738 gtk_stext_thaw(text);
1743 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1744 gboolean to_all, gboolean ignore_replyto,
1745 gboolean followup_and_reply_to)
1750 GHashTable *to_table;
1752 g_return_if_fail(compose->account != NULL);
1753 g_return_if_fail(msginfo != NULL);
1755 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1756 compose_entry_append(compose,
1757 ((compose->replyto && !ignore_replyto)
1759 : (compose->mailinglist && !ignore_replyto)
1760 ? compose->mailinglist
1761 : msginfo->from ? msginfo->from : ""),
1763 if (compose->account->protocol == A_NNTP) {
1765 compose_entry_append
1766 (compose, msginfo->from ? msginfo->from : "",
1769 compose_entry_append
1771 compose->followup_to ? compose->followup_to
1772 : compose->newsgroups ? compose->newsgroups
1774 COMPOSE_NEWSGROUPS);
1777 if (msginfo->subject && *msginfo->subject) {
1778 gchar *buf, *buf2, *p;
1780 buf = g_strdup(msginfo->subject);
1781 while (!strncasecmp(buf, "Re:", 3)) {
1783 while (isspace(*p)) p++;
1784 memmove(buf, p, strlen(p) + 1);
1787 buf2 = g_strdup_printf("Re: %s", buf);
1788 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1792 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1794 if (!to_all || compose->account->protocol == A_NNTP) return;
1796 from = g_strdup(compose->replyto ? compose->replyto :
1797 msginfo->from ? msginfo->from : "");
1798 extract_address(from);
1800 cc_list = address_list_append(NULL, msginfo->to);
1801 cc_list = address_list_append(cc_list, compose->cc);
1803 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1804 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1805 if (compose->account)
1806 g_hash_table_insert(to_table, compose->account->address,
1807 GINT_TO_POINTER(1));
1809 /* remove address on To: and that of current account */
1810 for (cur = cc_list; cur != NULL; ) {
1811 GSList *next = cur->next;
1813 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1814 cc_list = g_slist_remove(cc_list, cur->data);
1816 g_hash_table_insert(to_table, cur->data, cur);
1820 g_hash_table_destroy(to_table);
1824 for (cur = cc_list; cur != NULL; cur = cur->next)
1825 compose_entry_append(compose, (gchar *)cur->data,
1827 slist_free_strings(cc_list);
1828 g_slist_free(cc_list);
1832 #define SET_ENTRY(entry, str) \
1835 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1838 #define SET_ADDRESS(type, str) \
1841 compose_entry_append(compose, str, type); \
1844 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1846 g_return_if_fail(msginfo != NULL);
1848 SET_ENTRY(subject_entry, msginfo->subject);
1849 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1850 SET_ADDRESS(COMPOSE_CC, compose->cc);
1851 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1852 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1854 compose_show_first_last_header(compose, TRUE);
1856 #if 0 /* NEW COMPOSE GUI */
1858 GtkItemFactory *ifactory;
1859 GtkWidget *menuitem;
1861 ifactory = gtk_item_factory_from_widget(compose->menubar);
1862 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1863 gtk_check_menu_item_set_active
1864 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1866 if (compose->replyto) {
1867 GtkItemFactory *ifactory;
1868 GtkWidget *menuitem;
1870 ifactory = gtk_item_factory_from_widget(compose->menubar);
1871 menuitem = gtk_item_factory_get_item
1872 (ifactory, "/View/Reply to");
1873 gtk_check_menu_item_set_active
1874 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1882 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1889 size_t buf_len = 128;
1891 if (strlen(sigfile) < 2)
1894 sigprg = popen(sigfile+1, "r");
1897 buf = g_malloc(buf_len);
1900 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1901 "Unable to insert signature (malloc failed)\n", -1);
1907 while (!feof(sigprg)) {
1908 bzero(buf, buf_len);
1909 fread(buf, buf_len-1, 1, sigprg);
1910 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1918 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1919 "Can't exec file: ", -1);
1920 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1925 static void compose_insert_sig(Compose *compose)
1929 if (compose->account && compose->account->sig_path)
1930 sigfile = g_strdup(compose->account->sig_path);
1932 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1933 DEFAULT_SIGNATURE, NULL);
1935 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1940 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1941 if (prefs_common.sig_sep) {
1942 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1943 prefs_common.sig_sep, -1);
1944 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1948 if (sigfile[0] == '|')
1949 compose_exec_sig(compose, sigfile);
1951 compose_insert_file(compose, sigfile);
1955 static void compose_insert_file(Compose *compose, const gchar *file)
1957 GtkSText *text = GTK_STEXT(compose->text);
1958 gchar buf[BUFFSIZE];
1962 g_return_if_fail(file != NULL);
1964 if ((fp = fopen(file, "r")) == NULL) {
1965 FILE_OP_ERROR(file, "fopen");
1969 gtk_stext_freeze(text);
1971 while (fgets(buf, sizeof(buf), fp) != NULL) {
1972 /* strip <CR> if DOS/Windows file,
1973 replace <CR> with <LF> if Macintosh file. */
1976 if (len > 0 && buf[len - 1] != '\n') {
1978 if (buf[len] == '\r') buf[len] = '\n';
1980 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1983 gtk_stext_thaw(text);
1988 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1989 ContentType cnttype)
1991 gchar *text[N_ATTACH_COLS];
1994 text[COL_MIMETYPE] = ainfo->content_type;
1995 text[COL_SIZE] = to_human_readable(ainfo->size);
1996 text[COL_NAME] = ainfo->name;
1998 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1999 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2001 if (cnttype != MIME_MESSAGE_RFC822)
2002 compose_changed_cb(NULL, compose);
2005 static void compose_attach_append_with_type(Compose *compose,
2008 ContentType cnttype)
2013 if (!is_file_exist(file)) {
2014 g_warning(_("File %s doesn't exist\n"), file);
2017 if ((size = get_file_size(file)) < 0) {
2018 g_warning(_("Can't get file size of %s\n"), file);
2022 alertpanel_notice(_("File %s is empty\n"), file);
2025 #if 0 /* NEW COMPOSE GUI */
2026 if (!compose->use_attach) {
2027 GtkItemFactory *ifactory;
2028 GtkWidget *menuitem;
2030 ifactory = gtk_item_factory_from_widget(compose->menubar);
2031 menuitem = gtk_item_factory_get_item(ifactory,
2033 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2037 ainfo = g_new0(AttachInfo, 1);
2038 ainfo->file = g_strdup(file);
2040 if (cnttype == MIME_MESSAGE_RFC822) {
2041 ainfo->encoding = ENC_7BIT;
2042 ainfo->name = g_strdup_printf(_("Message: %s"),
2045 ainfo->encoding = ENC_BASE64;
2046 ainfo->name = g_strdup(g_basename(file));
2049 ainfo->content_type = g_strdup(type);
2052 compose_attach_info(compose, ainfo, cnttype);
2055 static void compose_attach_append(Compose *compose, const gchar *file,
2056 ContentType cnttype)
2059 gchar *text[N_ATTACH_COLS];
2063 if (!is_file_exist(file)) {
2064 g_warning(_("File %s doesn't exist\n"), file);
2067 if ((size = get_file_size(file)) < 0) {
2068 g_warning(_("Can't get file size of %s\n"), file);
2072 alertpanel_notice(_("File %s is empty\n"), file);
2075 #if 0 /* NEW COMPOSE GUI */
2076 if (!compose->use_attach) {
2077 GtkItemFactory *ifactory;
2078 GtkWidget *menuitem;
2080 ifactory = gtk_item_factory_from_widget(compose->menubar);
2081 menuitem = gtk_item_factory_get_item(ifactory,
2082 "/View/Attachment");
2083 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2087 ainfo = g_new0(AttachInfo, 1);
2088 ainfo->file = g_strdup(file);
2090 if (cnttype == MIME_MESSAGE_RFC822) {
2091 ainfo->content_type = g_strdup("message/rfc822");
2092 ainfo->encoding = ENC_7BIT;
2093 ainfo->name = g_strdup_printf(_("Message: %s"),
2096 ainfo->content_type = procmime_get_mime_type(file);
2097 if (!ainfo->content_type)
2098 ainfo->content_type =
2099 g_strdup("application/octet-stream");
2100 ainfo->encoding = ENC_BASE64;
2101 ainfo->name = g_strdup(g_basename(file));
2105 compose_attach_info(compose, ainfo, cnttype);
2108 #define GET_CHAR(pos, buf, len) \
2110 if (text->use_wchar) \
2111 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2113 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2118 static void compose_wrap_line(Compose *compose)
2120 GtkSText *text = GTK_STEXT(compose->text);
2121 gint ch_len, last_ch_len;
2122 gchar cbuf[MB_LEN_MAX], last_ch;
2126 gint p_start, p_end;
2127 gint line_pos, cur_pos;
2128 gint line_len, cur_len;
2130 gtk_stext_freeze(text);
2132 text_len = gtk_stext_get_length(text);
2134 /* check to see if the point is on the paragraph mark (empty line). */
2135 cur_pos = gtk_stext_get_point(text);
2136 GET_CHAR(cur_pos, cbuf, ch_len);
2137 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2139 goto compose_end; /* on the paragraph mark */
2140 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2141 if (ch_len == 1 && *cbuf == '\n')
2142 goto compose_end; /* on the paragraph mark */
2145 /* find paragraph start. */
2146 line_end = quoted = 0;
2147 for (p_start = cur_pos; p_start >= 0; --p_start) {
2148 GET_CHAR(p_start, cbuf, ch_len);
2149 if (ch_len == 1 && *cbuf == '\n') {
2151 goto compose_end; /* quoted part */
2158 if (ch_len == 1 && strchr(">:#", *cbuf))
2160 else if (ch_len != 1 || !isspace(*cbuf))
2169 /* find paragraph end. */
2171 for (p_end = cur_pos; p_end < text_len; p_end++) {
2172 GET_CHAR(p_end, cbuf, ch_len);
2173 if (ch_len == 1 && *cbuf == '\n') {
2180 if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
2181 goto compose_end; /* quoted part */
2186 if (p_end >= text_len)
2189 if (p_start >= p_end)
2192 line_len = cur_len = 0;
2196 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2199 GET_CHAR(cur_pos, cbuf, ch_len);
2206 if (ch_len == 1 && isspace(*cbuf))
2209 if (ch_len == 1 && *cbuf == '\n') {
2211 if (last_ch_len == 1 && !isspace(last_ch)) {
2212 if (cur_pos + 1 < p_end) {
2213 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2214 if (ch_len == 1 && !isspace(*cbuf))
2218 gtk_stext_set_point(text, cur_pos + 1);
2219 gtk_stext_backward_delete(text, 1);
2221 gtk_stext_set_point(text, cur_pos);
2222 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2232 last_ch_len = ch_len;
2236 line_pos = cur_pos + 1;
2237 line_len = cur_len + ch_len;
2240 if (cur_len + ch_len > prefs_common.linewrap_len &&
2244 GET_CHAR(line_pos - 1, cbuf, ch_len);
2245 if (ch_len == 1 && isspace(*cbuf)) {
2246 gtk_stext_set_point(text, line_pos);
2247 gtk_stext_backward_delete(text, 1);
2256 gtk_stext_set_point(text, line_pos);
2257 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2261 cur_len = cur_len - line_len + ch_len;
2267 line_pos = cur_pos + 1;
2268 line_len = cur_len + ch_len;
2274 gtk_stext_thaw(text);
2277 /* return indent length */
2278 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2280 gint indent_len = 0;
2282 gchar cbuf[MB_LEN_MAX];
2284 for (i = start_pos; i < text_len; i++) {
2285 GET_CHAR(i, cbuf, ch_len);
2288 /* allow space, tab, > or | */
2289 if (cbuf[0] != ' ' && cbuf[0] != '\t' &&
2290 cbuf[0] != '>' && cbuf[0] != '|')
2298 /* insert quotation string when line was wrapped */
2299 static guint ins_quote(GtkSText *text, guint quote_len, guint indent_len,
2300 guint prev_line_pos, guint text_len,
2307 for (i = 0; i < indent_len; i++) {
2308 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2309 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2311 ins_len = indent_len;
2313 gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
2314 ins_len = quote_len;
2322 /* Darko: used when I debug wrapping */
2323 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2328 printf("%d [", pos);
2329 for (i = pos; i < tlen; i++) {
2330 ch = GTK_STEXT_INDEX(text, i);
2331 if (breakoncr && ch == '\n')
2339 static void compose_wrap_line_all(Compose *compose)
2341 GtkSText *text = GTK_STEXT(compose->text);
2343 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2344 gint line_len = 0, cur_len = 0;
2346 gboolean is_new_line = TRUE, do_delete = FALSE;
2347 guint qlen = 0, i_len = 0;
2348 guint linewrap_quote = prefs_common.linewrap_quote;
2349 guint linewrap_len = prefs_common.linewrap_len;
2350 gchar *qfmt = prefs_common.quotemark;
2351 gchar cbuf[MB_LEN_MAX];
2353 gtk_stext_freeze(text);
2355 /* make text buffer contiguous */
2356 /* gtk_stext_compact_buffer(text); */
2358 tlen = gtk_stext_get_length(text);
2360 for (; cur_pos < tlen; cur_pos++) {
2361 /* mark position of new line - needed for quotation wrap */
2363 if (linewrap_quote) {
2364 qlen = gtkut_stext_str_compare
2365 (text, cur_pos, tlen, qfmt);
2367 i_len = get_indent_length
2368 (text, cur_pos, tlen);
2372 is_new_line = FALSE;
2375 printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
2376 dump_text(text, p_pos, tlen, 1);
2380 GET_CHAR(cur_pos, cbuf, ch_len);
2382 /* fix line length for tabs */
2383 if (ch_len == 1 && *cbuf == '\t') {
2384 guint tab_width = text->default_tab_width;
2385 guint tab_offset = line_len % tab_width;
2388 printf("found tab at pos=%d line_len=%d ", cur_pos,
2392 line_len += tab_width - tab_offset - 1;
2396 printf("new_len=%d\n", line_len);
2400 /* we have encountered line break */
2401 if (ch_len == 1 && *cbuf == '\n') {
2404 gchar cb[MB_CUR_MAX];
2407 printf("found CR at %d next line is ", cur_pos);
2408 dump_text(text, cur_pos + 1, tlen, 1);
2410 /* if it's just quotation + newline skip it */
2411 if (i_len && (cur_pos + 1 < tlen)) {
2412 /* check if text at new line matches indent */
2413 ilen = gtkut_stext_str_compare_n
2414 (text, cur_pos + 1, p_pos, i_len, tlen);
2415 if (cur_pos + ilen < tlen) {
2416 GET_CHAR(cur_pos + ilen + 1, cb, clen);
2417 /* no need to join the lines */
2418 if (clen == 1 && cb[0] == '\n')
2421 /* if it's just newline skip it */
2422 } else if (do_delete && (cur_pos + 1 < tlen)) {
2423 GET_CHAR(cur_pos + 1, cb, clen);
2424 /* no need to join the lines */
2425 if (clen == 1 && cb[0] == '\n')
2429 /* skip delete if it is continuous URL */
2430 if (do_delete && (line_pos - p_pos <= i_len) &&
2431 gtkut_stext_is_uri_string(text, line_pos, tlen))
2435 printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
2436 qlen, line_len, linewrap_len, do_delete);
2438 /* should we delete to perform smart wrapping */
2439 if (line_len < linewrap_len && do_delete) {
2440 /* get rid of newline */
2441 gtk_stext_set_point(text, cur_pos);
2442 gtk_stext_forward_delete(text, 1);
2445 /* if text starts with quote fmt or with
2446 indent string, delete them */
2448 ilen = gtkut_stext_str_compare_n
2449 (text, cur_pos, p_pos, i_len,
2452 gtk_stext_forward_delete
2457 if (gtkut_stext_str_compare
2458 (text, cur_pos, tlen, qfmt)) {
2459 gtk_stext_forward_delete
2465 GET_CHAR(cur_pos, cb, clen);
2467 /* insert space if it's alphanumeric */
2468 if ((cur_pos != line_pos) &&
2469 ((clen > 1) || isalnum(cb[0]))) {
2470 gtk_stext_insert(text, NULL, NULL,
2472 /* gtk_stext_compact_buffer(text); */
2476 /* and start over with current line */
2477 cur_pos = p_pos - 1;
2479 line_len = cur_len = 0;
2484 printf("after delete l_pos=");
2485 dump_text(text, line_pos, tlen, 1);
2490 /* mark new line beginning */
2491 line_pos = cur_pos + 1;
2492 line_len = cur_len = 0;
2504 /* possible line break */
2505 if (ch_len == 1 && isspace(*cbuf)) {
2506 line_pos = cur_pos + 1;
2507 line_len = cur_len + ch_len;
2510 /* are we over wrapping length set in preferences ? */
2511 if (cur_len + ch_len > linewrap_len) {
2515 printf("should wrap cur_pos=%d ", cur_pos);
2516 dump_text(text, p_pos, tlen, 1);
2517 dump_text(text, line_pos, tlen, 1);
2519 /* force wrapping if it is one long word but not URL */
2520 if (line_pos - p_pos <= i_len)
2521 if (!gtkut_stext_is_uri_string
2522 (text, line_pos, tlen))
2523 line_pos = cur_pos - 1;
2525 printf("new line_pos=%d\n", line_pos);
2528 GET_CHAR(line_pos - 1, cbuf, clen);
2530 /* if next character is space delete it */
2531 if (clen == 1 && isspace(*cbuf)) {
2532 if (p_pos + i_len != line_pos ||
2533 !gtkut_stext_is_uri_string
2534 (text, line_pos, tlen)) {
2535 gtk_stext_set_point(text, line_pos);
2536 gtk_stext_backward_delete(text, 1);
2545 /* if it is URL at beginning of line don't wrap */
2546 if (p_pos + i_len == line_pos &&
2547 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2549 printf("found URL at ");
2550 dump_text(text, line_pos, tlen, 1);
2556 gtk_stext_set_point(text, line_pos);
2557 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2558 /* gtk_stext_compact_buffer(text); */
2561 /* for loop will increase it */
2562 cur_pos = line_pos - 1;
2563 /* start over with current line */
2569 printf("after CR insert ");
2570 dump_text(text, line_pos, tlen, 1);
2571 dump_text(text, cur_pos, tlen, 1);
2574 /* should we insert quotation ? */
2575 if (linewrap_quote && qlen) {
2576 /* only if line is not already quoted */
2577 if (!gtkut_stext_str_compare
2578 (text, line_pos, tlen, qfmt)) {
2581 if (line_pos - p_pos > i_len) {
2586 /* gtk_stext_compact_buffer(text); */
2590 printf("after quote insert ");
2591 dump_text(text, line_pos, tlen, 1);
2599 line_pos = cur_pos + 1;
2600 line_len = cur_len + ch_len;
2602 /* advance to next character in buffer */
2606 gtk_stext_thaw(text);
2611 static void compose_set_title(Compose *compose)
2616 edited = compose->modified ? _(" [Edited]") : "";
2617 if (compose->account && compose->account->address)
2618 str = g_strdup_printf(_("%s - Compose message%s"),
2619 compose->account->address, edited);
2621 str = g_strdup_printf(_("Compose message%s"), edited);
2622 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2627 * compose_current_mail_account:
2629 * Find a current mail account (the currently selected account, or the
2630 * default account, if a news account is currently selected). If a
2631 * mail account cannot be found, display an error message.
2633 * Return value: Mail account, or NULL if not found.
2635 static PrefsAccount *
2636 compose_current_mail_account(void)
2640 if (cur_account && cur_account->protocol != A_NNTP)
2643 ac = account_get_default();
2644 if (!ac || ac->protocol == A_NNTP) {
2645 alertpanel_error(_("Account for sending mail is not specified.\n"
2646 "Please select a mail account before sending."));
2653 gboolean compose_check_for_valid_recipient(Compose *compose) {
2654 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2655 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2656 gboolean recipient_found = FALSE;
2660 /* free to and newsgroup list */
2661 slist_free_strings(compose->to_list);
2662 g_slist_free(compose->to_list);
2663 compose->to_list = NULL;
2665 slist_free_strings(compose->newsgroup_list);
2666 g_slist_free(compose->newsgroup_list);
2667 compose->newsgroup_list = NULL;
2669 /* search header entries for to and newsgroup entries */
2670 for(list = compose->header_list; list; list = list->next) {
2673 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2674 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2676 if(entry[0] != '\0') {
2677 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2678 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2679 compose->to_list = address_list_append(compose->to_list, entry);
2680 recipient_found = TRUE;
2683 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2684 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2685 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2686 recipient_found = TRUE;
2692 return recipient_found;
2695 gint compose_send(Compose *compose)
2701 val = compose_queue(compose, &msgnum, &folder);
2703 alertpanel_error(_("Could not queue message for sending"));
2707 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2709 folder_item_remove_msg(folder, msgnum);
2710 folderview_update_item(folder, TRUE);
2716 #if 0 /* compose restructure */
2717 gint compose_send(Compose *compose)
2719 gchar tmp[MAXPATHLEN + 1];
2721 static gboolean lock = FALSE;
2725 g_return_val_if_fail(compose->account != NULL, -1);
2726 g_return_val_if_fail(compose->orig_account != NULL, -1);
2730 if(!compose_check_for_valid_recipient(compose)) {
2731 alertpanel_error(_("Recipient is not specified."));
2736 /* write to temporary file */
2737 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2738 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2740 if (prefs_common.linewrap_at_send)
2741 compose_wrap_line_all(compose);
2743 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2748 if (!compose->to_list && !compose->newsgroup_list) {
2749 g_warning(_("can't get recipient list."));
2755 if (compose->to_list) {
2758 #if 0 /* NEW COMPOSE GUI */
2759 if (compose->account->protocol != A_NNTP)
2760 ac = compose->account;
2761 else if (compose->orig_account->protocol != A_NNTP)
2762 ac = compose->orig_account;
2763 else if (cur_account && cur_account->protocol != A_NNTP)
2766 ac = compose_current_mail_account();
2774 ac = compose->account;
2776 ok = send_message(tmp, ac, compose->to_list);
2777 statusbar_pop_all();
2780 if (ok == 0 && compose->newsgroup_list) {
2783 if (compose->account->protocol == A_NNTP)
2784 folder = FOLDER(compose->account->folder);
2786 folder = FOLDER(compose->orig_account->folder);
2788 ok = news_post(folder, tmp);
2790 alertpanel_error(_("Error occurred while posting the message to %s ."),
2791 compose->account->nntp_server);
2798 /* queue message if failed to send */
2800 if (prefs_common.queue_msg) {
2805 _("Error occurred while sending the message.\n"
2806 "Put this message into queue folder?"),
2807 _("OK"), _("Cancel"), NULL);
2808 if (G_ALERTDEFAULT == val) {
2809 ok = compose_queue(compose, tmp);
2811 alertpanel_error(_("Can't queue the message."));
2814 alertpanel_error(_("Error occurred while sending the message."));
2816 if (compose->mode == COMPOSE_REEDIT) {
2817 compose_remove_reedit_target(compose);
2818 if (compose->targetinfo)
2819 folderview_update_item
2820 (compose->targetinfo->folder, TRUE);
2824 /* save message to outbox */
2825 if (ok == 0 && prefs_common.savemsg) {
2826 if (compose_save_to_outbox(compose, tmp) < 0)
2828 (_("Can't save the message to outbox."));
2837 static gboolean compose_use_attach(Compose *compose) {
2838 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2841 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2844 gchar buf[BUFFSIZE];
2846 gboolean first_address;
2848 ComposeHeaderEntry *headerentry;
2849 gchar *headerentryname;
2850 gchar *header_w_colon;
2854 debug_print(_("Writing bounce header\n"));
2856 header_w_colon = g_strconcat("To:", NULL);
2857 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2858 header_w_colon = g_strconcat("Cc:", NULL);
2859 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2861 first_address = TRUE;
2862 for(list = compose->header_list; list; list = list->next) {
2863 headerentry = ((ComposeHeaderEntry *)list->data);
2864 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2866 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2867 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2868 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2869 Xstrdup_a(str, str, return -1);
2871 if(str[0] != '\0') {
2872 compose_convert_header
2873 (buf, sizeof(buf), str,
2874 strlen("Resent-To") + 2);
2876 fprintf(fp, "Resent-To: ");
2877 first_address = FALSE;
2881 fprintf(fp, "%s", buf);
2885 /* if(!first_address) { */
2892 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2894 gchar buf[BUFFSIZE];
2896 /* struct utsname utsbuf; */
2898 g_return_val_if_fail(fp != NULL, -1);
2899 g_return_val_if_fail(compose->account != NULL, -1);
2900 g_return_val_if_fail(compose->account->address != NULL, -1);
2903 get_rfc822_date(buf, sizeof(buf));
2904 fprintf(fp, "Resent-Date: %s\n", buf);
2907 if (compose->account->name && *compose->account->name) {
2908 compose_convert_header
2909 (buf, sizeof(buf), compose->account->name,
2911 fprintf(fp, "Resent-From: %s <%s>\n",
2912 buf, compose->account->address);
2914 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2917 compose_bounce_write_headers_from_headerlist(compose, fp);
2919 /* separator between header and body */
2925 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2930 gchar buf[BUFFSIZE];
2932 if ((fp = fopen(compose->bounce_filename, "r")) == NULL) {
2933 FILE_OP_ERROR(file, "fopen");
2937 if ((fdest = fopen(file, "w")) == NULL) {
2938 FILE_OP_ERROR(file, "fopen");
2943 /* chmod for security */
2944 if (change_file_mode_rw(fdest, file) < 0) {
2945 FILE_OP_ERROR(file, "chmod");
2946 g_warning(_("can't change file mode\n"));
2949 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2950 /* should filter returnpath, delivered-to */
2951 if ((g_strncasecmp(buf, "Return-Path:",
2952 strlen("Return-Path:")) == 0)
2953 || (g_strncasecmp(buf, "Delivered-To:",
2954 strlen("Delivered-To:")) == 0))
2957 if (fputs(buf, fdest) == -1)
2960 if (g_strncasecmp(buf, "From:", strlen("From:")) == 0) {
2961 fputs(" (by way of ", fdest);
2962 if (compose->account->name
2963 && *compose->account->name) {
2964 compose_convert_header
2966 compose->account->name,
2968 fprintf(fdest, "%s <%s>",
2969 buf, compose->account->address);
2971 fprintf(fdest, "%s",
2972 compose->account->address);
2976 if (fputs("\n", fdest) == -1)
2980 compose_bounce_write_headers(compose, fdest);
2982 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
2983 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
3001 * interfaces to rfc2015 to keep out the prefs stuff there.
3002 * returns 0 on success and -1 on error. */
3003 static int compose_create_signers_list (Compose *compose, GSList **pkey_list)
3005 const char *keyid = NULL;
3008 switch (compose->account->sign_key) {
3009 case SIGN_KEY_DEFAULT:
3011 return 0; /* nothing to do */
3013 case SIGN_KEY_BY_FROM:
3014 keyid = compose->account->address;
3017 case SIGN_KEY_CUSTOM:
3018 keyid = compose->account->sign_key_id;
3022 g_assert_not_reached ();
3025 key_list = rfc2015_create_signers_list(keyid);
3028 alertpanel_error("Could not find any key associated with currently "
3029 "selected keyid `%s'!", keyid);
3033 *pkey_list = key_list;
3036 #endif /* USE_GPGME */
3038 static gint compose_write_to_file(Compose *compose, const gchar *file,
3045 const gchar *out_codeset;
3046 EncodingType encoding;
3048 if ((fp = fopen(file, "w")) == NULL) {
3049 FILE_OP_ERROR(file, "fopen");
3053 /* chmod for security */
3054 if (change_file_mode_rw(fp, file) < 0) {
3055 FILE_OP_ERROR(file, "chmod");
3056 g_warning(_("can't change file mode\n"));
3059 /* get all composed text */
3060 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3061 len = strlen(chars);
3062 if (is_ascii_str(chars)) {
3063 buf = g_strdup(chars);
3064 out_codeset = CS_US_ASCII;
3065 encoding = ENC_7BIT;
3067 const gchar *src_codeset;
3069 out_codeset = conv_get_outgoing_charset_str();
3070 if (!strcasecmp(out_codeset, CS_US_ASCII))
3071 out_codeset = CS_ISO_8859_1;
3072 encoding = procmime_get_encoding_for_charset(out_codeset);
3074 src_codeset = conv_get_current_charset_str();
3075 /* if current encoding is US-ASCII, set it the same as
3076 outgoing one to prevent code conversion failure */
3077 if (!strcasecmp(src_codeset, CS_US_ASCII))
3078 src_codeset = out_codeset;
3080 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3081 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3083 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3088 alertpanel_error(_("Can't convert the codeset of the message."));
3095 if (compose_write_headers
3096 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3097 g_warning(_("can't write headers\n"));
3104 if (compose_use_attach(compose)) {
3106 /* This prolog message is ignored by mime software and
3107 * because it would make our signing/encryption task
3108 * tougher, we don't emit it in that case */
3109 if (!compose->use_signing && !compose->use_encryption)
3111 fputs("This is a multi-part message in MIME format.\n", fp);
3113 fprintf(fp, "\n--%s\n", compose->boundary);
3114 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3116 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3117 procmime_get_encoding_str(encoding));
3123 if (encoding == ENC_BASE64) {
3124 gchar outbuf[B64_BUFFSIZE];
3127 for (i = 0; i < len; i += B64_LINE_SIZE) {
3128 l = MIN(B64_LINE_SIZE, len - i);
3129 to64frombits(outbuf, buf + i, l);
3133 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3134 FILE_OP_ERROR(file, "fwrite");
3142 if (compose_use_attach(compose))
3143 compose_write_attach(compose, fp);
3145 if (fclose(fp) == EOF) {
3146 FILE_OP_ERROR(file, "fclose");
3152 if (compose->use_signing) {
3155 if (compose_create_signers_list(compose, &key_list) == -1 ||
3156 rfc2015_sign(file, key_list) < 0) {
3162 if (compose->use_encryption) {
3163 if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) {
3168 #endif /* USE_GPGME */
3173 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3179 if ((fp = fopen(file, "w")) == NULL) {
3180 FILE_OP_ERROR(file, "fopen");
3184 /* chmod for security */
3185 if (change_file_mode_rw(fp, file) < 0) {
3186 FILE_OP_ERROR(file, "chmod");
3187 g_warning(_("can't change file mode\n"));
3190 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3193 len = strlen(chars);
3194 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3195 FILE_OP_ERROR(file, "fwrite");
3204 if (fclose(fp) == EOF) {
3205 FILE_OP_ERROR(file, "fclose");
3212 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
3219 debug_print(_("saving sent message...\n"));
3221 outbox = folder_get_default_outbox();
3222 path = folder_item_get_path(outbox);
3223 if (!is_dir_exist(path))
3224 make_dir_hier(path);
3226 folder_item_scan(outbox);
3227 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
3229 g_warning(_("can't save message\n"));
3233 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
3234 g_warning(_("can't open mark file\n"));
3238 newmsginfo.msgnum = num;
3239 newmsginfo.flags.perm_flags = 0;
3240 newmsginfo.flags.tmp_flags = 0;
3241 procmsg_write_flags(&newmsginfo, fp);
3249 static gint compose_remove_reedit_target(Compose *compose)
3252 MsgInfo *msginfo = compose->targetinfo;
3254 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3255 if (!msginfo) return -1;
3257 item = msginfo->folder;
3258 g_return_val_if_fail(item != NULL, -1);
3260 folder_item_scan(item);
3261 if (procmsg_msg_exist(msginfo) &&
3262 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3263 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3264 g_warning(_("can't remove the old message\n"));
3273 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3276 gchar *tmp, *tmp2, *queue_path;
3279 gchar buf[BUFFSIZE];
3281 static gboolean lock = FALSE;
3282 PrefsAccount *mailac = NULL, *newsac = NULL;
3284 debug_print(_("queueing message...\n"));
3285 g_return_val_if_fail(compose->account != NULL, -1);
3286 g_return_val_if_fail(compose->orig_account != NULL, -1);
3290 if(!compose_check_for_valid_recipient(compose)) {
3291 alertpanel_error(_("Recipient is not specified."));
3296 if (!compose->to_list && !compose->newsgroup_list) {
3297 g_warning(_("can't get recipient list."));
3302 if(compose->to_list) {
3303 if (compose->account->protocol != A_NNTP)
3304 mailac = compose->account;
3305 else if (compose->orig_account->protocol != A_NNTP)
3306 mailac = compose->orig_account;
3307 else if (cur_account && cur_account->protocol != A_NNTP)
3308 mailac = cur_account;
3309 else if (!(mailac = compose_current_mail_account())) {
3311 alertpanel_error(_("No account for sending mails available!"));
3316 if(compose->newsgroup_list) {
3317 if (compose->account->protocol == A_NNTP)
3318 newsac = compose->account;
3319 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3321 alertpanel_error(_("No account for posting news available!"));
3326 if (prefs_common.linewrap_at_send)
3327 compose_wrap_line_all(compose);
3329 /* write to temporary file */
3330 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3331 G_DIR_SEPARATOR, (gint)compose);
3333 if (compose->bounce_filename != NULL) {
3334 if (compose_bounce_write_to_file(compose, tmp2) < 0) {
3341 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3348 /* add queue header */
3349 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3350 G_DIR_SEPARATOR, (gint)compose);
3351 if ((fp = fopen(tmp, "w")) == NULL) {
3352 FILE_OP_ERROR(tmp, "fopen");
3356 if ((src_fp = fopen(tmp2, "r")) == NULL) {
3357 FILE_OP_ERROR(tmp2, "fopen");
3365 if (change_file_mode_rw(fp, tmp) < 0) {
3366 FILE_OP_ERROR(tmp, "chmod");
3367 g_warning(_("can't change file mode\n"));
3370 /* queueing variables */
3371 fprintf(fp, "AF:\n");
3372 fprintf(fp, "NF:0\n");
3373 fprintf(fp, "PS:10\n");
3374 fprintf(fp, "SRH:1\n");
3375 fprintf(fp, "SFN:\n");
3376 fprintf(fp, "DSR:\n");
3378 fprintf(fp, "MID:<%s>\n", compose->msgid);
3380 fprintf(fp, "MID:\n");
3381 fprintf(fp, "CFG:\n");
3382 fprintf(fp, "PT:0\n");
3383 fprintf(fp, "S:%s\n", compose->account->address);
3384 fprintf(fp, "RQ:\n");
3386 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3388 fprintf(fp, "SSV:\n");
3390 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3392 fprintf(fp, "NSV:\n");
3393 fprintf(fp, "SSH:\n");
3394 /* write recepient list */
3396 if(compose->to_list) {
3397 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3398 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3399 fprintf(fp, ",<%s>", (gchar *)cur->data);
3402 /* write newsgroup list */
3404 if(compose->newsgroup_list) {
3405 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3406 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3407 fprintf(fp, ",%s", (gchar *)cur->data);
3410 /* Sylpheed account IDs */
3412 fprintf(fp, "MAID:%d\n", mailac->account_id);
3415 fprintf(fp, "NAID:%d\n", newsac->account_id);
3417 /* Save copy folder */
3418 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3421 str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3422 fprintf(fp, "SCF:%s\n", str);
3427 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3428 if (fputs(buf, fp) == EOF) {
3429 FILE_OP_ERROR(tmp, "fputs");
3440 if (fclose(fp) == EOF) {
3441 FILE_OP_ERROR(tmp, "fclose");
3450 queue = folder_get_default_queue();
3452 folder_item_scan(queue);
3453 queue_path = folder_item_get_path(queue);
3454 if (!is_dir_exist(queue_path))
3455 make_dir_hier(queue_path);
3456 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3457 g_warning(_("can't queue the message\n"));
3468 if (compose->mode == COMPOSE_REEDIT) {
3469 compose_remove_reedit_target(compose);
3470 if (compose->targetinfo &&
3471 compose->targetinfo->folder != queue)
3472 folderview_update_item
3473 (compose->targetinfo->folder, TRUE);
3476 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
3477 g_warning(_("can't open mark file\n"));
3481 newmsginfo.msgnum = num;
3482 newmsginfo.flags.perm_flags = 0;
3483 newmsginfo.flags.tmp_flags = 0;
3484 procmsg_write_flags(&newmsginfo, fp);
3489 folder_item_scan(queue);
3490 folderview_update_item(queue, TRUE);
3492 if((msgnum != NULL) && (item != NULL)) {
3500 static void compose_write_attach(Compose *compose, FILE *fp)
3503 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3506 gchar filename[BUFFSIZE];
3509 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3511 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
3512 g_warning(_("Can't open file %s\n"), ainfo->file);
3516 fprintf(fp, "\n--%s\n", compose->boundary);
3518 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3519 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3520 fprintf(fp, "Content-Disposition: inline\n");
3522 conv_encode_header(filename, sizeof(filename),
3524 fprintf(fp, "Content-Type: %s;\n"
3526 ainfo->content_type, filename);
3527 fprintf(fp, "Content-Disposition: attachment;\n"
3528 " filename=\"%s\"\n", filename);
3531 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3532 procmime_get_encoding_str(ainfo->encoding));
3534 if (ainfo->encoding == ENC_7BIT) {
3535 gchar buf[BUFFSIZE];
3537 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3542 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3544 while ((len = fread(inbuf, sizeof(gchar),
3545 B64_LINE_SIZE, attach_fp))
3547 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3551 if (len > 0 && feof(attach_fp)) {
3552 to64frombits(outbuf, inbuf, len);
3561 fprintf(fp, "\n--%s--\n", compose->boundary);
3564 #define IS_IN_CUSTOM_HEADER(header) \
3565 (compose->account->add_customhdr && \
3566 custom_header_find(compose->account->customhdr_list, header) != NULL)
3568 static gint compose_write_headers_from_headerlist(Compose *compose,
3572 gchar buf[BUFFSIZE];
3573 gchar *str, *header_w_colon, *trans_hdr;
3574 gboolean first_address;
3576 ComposeHeaderEntry *headerentry;
3577 gchar * headerentryname;
3579 if (IS_IN_CUSTOM_HEADER(header)) {
3583 debug_print(_("Writing %s-header\n"), header);
3585 header_w_colon = g_strconcat(header, ":", NULL);
3586 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3588 first_address = TRUE;
3589 for(list = compose->header_list; list; list = list->next) {
3590 headerentry = ((ComposeHeaderEntry *)list->data);
3591 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3593 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3594 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3595 Xstrdup_a(str, str, return -1);
3597 if(str[0] != '\0') {
3598 compose_convert_header
3599 (buf, sizeof(buf), str,
3600 strlen(header) + 2);
3602 fprintf(fp, "%s: ", header);
3603 first_address = FALSE;
3607 fprintf(fp, "%s", buf);
3611 if(!first_address) {
3615 g_free(header_w_colon);
3620 static gint compose_write_headers(Compose *compose, FILE *fp,
3621 const gchar *charset, EncodingType encoding,
3624 gchar buf[BUFFSIZE];
3626 /* struct utsname utsbuf; */
3628 g_return_val_if_fail(fp != NULL, -1);
3629 g_return_val_if_fail(charset != NULL, -1);
3630 g_return_val_if_fail(compose->account != NULL, -1);
3631 g_return_val_if_fail(compose->account->address != NULL, -1);
3634 if (compose->account->add_date) {
3635 get_rfc822_date(buf, sizeof(buf));
3636 fprintf(fp, "Date: %s\n", buf);
3640 if (!IS_IN_CUSTOM_HEADER("From")) {
3641 if (compose->account->name && *compose->account->name) {
3642 compose_convert_header
3643 (buf, sizeof(buf), compose->account->name,
3645 fprintf(fp, "From: %s <%s>\n",
3646 buf, compose->account->address);
3648 fprintf(fp, "From: %s\n", compose->account->address);
3652 compose_write_headers_from_headerlist(compose, fp, "To");
3653 #if 0 /* NEW COMPOSE GUI */
3654 if (compose->use_to) {
3655 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3657 Xstrdup_a(str, str, return -1);
3660 compose->to_list = address_list_append
3661 (compose->to_list, str);
3662 if (!IS_IN_CUSTOM_HEADER("To")) {
3663 compose_convert_header
3664 (buf, sizeof(buf), str,
3666 fprintf(fp, "To: %s\n", buf);
3674 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3675 #if 0 /* NEW COMPOSE GUI */
3676 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3678 Xstrdup_a(str, str, return -1);
3682 compose->newsgroup_list =
3683 newsgroup_list_append(compose->newsgroup_list,
3685 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3686 compose_convert_header(buf, sizeof(buf), str,
3687 strlen("Newsgroups: "));
3688 fprintf(fp, "Newsgroups: %s\n", buf);
3694 compose_write_headers_from_headerlist(compose, fp, "Cc");
3695 #if 0 /* NEW COMPOSE GUI */
3696 if (compose->use_cc) {
3697 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3699 Xstrdup_a(str, str, return -1);
3702 compose->to_list = address_list_append
3703 (compose->to_list, str);
3704 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3705 compose_convert_header
3706 (buf, sizeof(buf), str,
3708 fprintf(fp, "Cc: %s\n", buf);
3715 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3716 #if 0 /* NEW COMPOSE GUI */
3717 if (compose->use_bcc) {
3718 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3720 Xstrdup_a(str, str, return -1);
3723 compose->to_list = address_list_append
3724 (compose->to_list, str);
3725 compose_convert_header(buf, sizeof(buf), str,
3727 fprintf(fp, "Bcc: %s\n", buf);
3734 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3735 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3736 Xstrdup_a(str, str, return -1);
3739 compose_convert_header(buf, sizeof(buf), str,
3740 strlen("Subject: "));
3741 fprintf(fp, "Subject: %s\n", buf);
3746 if (compose->account->gen_msgid) {
3747 compose_generate_msgid(compose, buf, sizeof(buf));
3748 fprintf(fp, "Message-Id: <%s>\n", buf);
3749 compose->msgid = g_strdup(buf);
3753 if (compose->inreplyto && compose->to_list)
3754 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3757 if (compose->references)
3758 fprintf(fp, "References: %s\n", compose->references);
3761 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3762 #if 0 /* NEW COMPOSE GUI */
3763 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3764 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3766 Xstrdup_a(str, str, return -1);
3770 compose_convert_header(buf, sizeof(buf), str,
3771 strlen("Followup-To: "));
3772 fprintf(fp, "Followup-To: %s\n", buf);
3778 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3779 #if 0 /* NEW COMPOSE GUI */
3780 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3781 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3783 Xstrdup_a(str, str, return -1);
3786 compose_convert_header(buf, sizeof(buf), str,
3787 strlen("Reply-To: "));
3788 fprintf(fp, "Reply-To: %s\n", buf);
3794 if (compose->account->organization &&
3795 !IS_IN_CUSTOM_HEADER("Organization")) {
3796 compose_convert_header(buf, sizeof(buf),
3797 compose->account->organization,
3798 strlen("Organization: "));
3799 fprintf(fp, "Organization: %s\n", buf);
3802 /* Program version and system info */
3803 /* uname(&utsbuf); */
3804 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3805 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3807 gtk_major_version, gtk_minor_version, gtk_micro_version,
3809 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3811 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3812 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3814 gtk_major_version, gtk_minor_version, gtk_micro_version,
3816 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3819 /* custom headers */
3820 if (compose->account->add_customhdr) {
3823 for (cur = compose->account->customhdr_list; cur != NULL;
3825 CustomHeader *chdr = (CustomHeader *)cur->data;
3827 if (strcasecmp(chdr->name, "Date") != 0 &&
3828 strcasecmp(chdr->name, "From") != 0 &&
3829 strcasecmp(chdr->name, "To") != 0 &&
3830 /* strcasecmp(chdr->name, "Sender") != 0 && */
3831 strcasecmp(chdr->name, "Message-Id") != 0 &&
3832 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3833 strcasecmp(chdr->name, "References") != 0 &&
3834 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3835 strcasecmp(chdr->name, "Content-Type") != 0 &&
3836 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3838 compose_convert_header
3840 chdr->value ? chdr->value : "",
3841 strlen(chdr->name) + 2);
3842 fprintf(fp, "%s: %s\n", chdr->name, buf);
3848 fprintf(fp, "Mime-Version: 1.0\n");
3849 if (compose_use_attach(compose)) {
3850 get_rfc822_date(buf, sizeof(buf));
3851 subst_char(buf, ' ', '_');
3852 subst_char(buf, ',', '_');
3853 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3854 buf, (guint)compose);
3856 "Content-Type: multipart/mixed;\n"
3857 " boundary=\"%s\"\n", compose->boundary);
3859 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3860 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3861 procmime_get_encoding_str(encoding));
3864 /* Request Return Receipt */
3865 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3866 if (compose->return_receipt) {
3867 if (compose->account->name
3868 && *compose->account->name) {
3869 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3870 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3872 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3876 /* separator between header and body */
3882 #undef IS_IN_CUSTOM_HEADER
3884 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3887 g_return_if_fail(src != NULL);
3888 g_return_if_fail(dest != NULL);
3890 if (len < 1) return;
3894 if (is_ascii_str(src)) {
3895 strncpy2(dest, src, len);
3896 dest[len - 1] = '\0';
3899 conv_encode_header(dest, len, src, header_len);
3902 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3911 if (compose->account && compose->account->address &&
3912 *compose->account->address) {
3913 if (strchr(compose->account->address, '@'))
3914 addr = g_strdup(compose->account->address);
3916 addr = g_strconcat(compose->account->address, "@",
3917 get_domain_name(), NULL);
3919 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3922 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3923 lt->tm_year + 1900, lt->tm_mon + 1,
3924 lt->tm_mday, lt->tm_hour,
3925 lt->tm_min, lt->tm_sec,
3926 (guint)random(), addr);
3928 debug_print(_("generated Message-ID: %s\n"), buf);
3933 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3934 GtkWidget **entry, gint *count,
3935 const gchar *label_str,
3936 gboolean is_addr_entry)
3940 if (GTK_TABLE(table)->nrows < (*count) + 1)
3941 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3943 *hbox = gtk_hbox_new(FALSE, 0);
3944 label = gtk_label_new
3945 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3946 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3947 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3949 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3951 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3952 #if 0 /* NEW COMPOSE GUI */
3953 if (GTK_TABLE(table)->nrows > (*count) + 1)
3954 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3958 address_completion_register_entry(GTK_ENTRY(*entry));
3963 static void compose_create_header_entry(Compose *compose)
3965 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3969 GList *combo_list = NULL;
3970 gchar **string, *header;
3971 ComposeHeaderEntry *headerentry;
3973 headerentry = g_new0(ComposeHeaderEntry, 1);
3976 combo = gtk_combo_new();
3978 while(*string != NULL) {
3979 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3982 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3983 g_list_free(combo_list);
3984 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3985 gtk_widget_show(combo);
3986 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3987 if(compose->header_last) {
3988 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3990 switch(compose->account->protocol) {
3992 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
3995 header = prefs_common.trans_hdr ? _("To:") : "To:";
3999 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4002 entry = gtk_entry_new();
4003 gtk_widget_show(entry);
4004 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);
4006 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4007 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4008 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4010 address_completion_register_entry(GTK_ENTRY(entry));
4012 headerentry->compose = compose;
4013 headerentry->combo = combo;
4014 headerentry->entry = entry;
4015 headerentry->headernum = compose->header_nextrow;
4017 compose->header_nextrow++;
4018 compose->header_last = headerentry;
4021 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4023 ComposeHeaderEntry *last_header;
4025 last_header = compose->header_last;
4027 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4028 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4031 static GtkWidget *compose_create_header(Compose *compose)
4035 GtkWidget *from_optmenu_hbox;
4036 #if 0 /* NEW COMPOSE GUI */
4037 GtkWidget *to_entry;
4039 GtkWidget *newsgroups_entry;
4040 GtkWidget *newsgroups_hbox;
4042 GtkWidget *header_scrolledwin;
4043 GtkWidget *header_table;
4044 #if 0 /* NEW COMPOSE GUI */
4045 GtkWidget *cc_entry;
4047 GtkWidget *bcc_entry;
4048 GtkWidget *bcc_hbox;
4049 GtkWidget *reply_entry;
4050 GtkWidget *reply_hbox;
4051 GtkWidget *followup_entry;
4052 GtkWidget *followup_hbox;
4057 /* header labels and entries */
4058 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4059 gtk_widget_show(header_scrolledwin);
4060 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4062 header_table = gtk_table_new(2, 2, FALSE);
4063 gtk_widget_show(header_table);
4064 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4065 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4066 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4069 /* option menu for selecting accounts */
4070 hbox = gtk_hbox_new(FALSE, 0);
4071 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4072 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4073 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4075 from_optmenu_hbox = compose_account_option_menu_create(compose);
4076 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4077 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4078 #if 0 /* NEW COMPOSE GUI */
4079 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4083 compose->header_table = header_table;
4084 compose->header_list = NULL;
4085 compose->header_nextrow = count;
4087 compose_create_header_entry(compose);
4089 #if 0 /* NEW COMPOSE GUI */
4090 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4092 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4093 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4094 &count, "Newsgroups:", FALSE);
4095 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4097 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4099 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4101 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4102 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4104 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4105 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4107 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4108 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4109 "Followup-To:", FALSE);
4110 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4112 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4114 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4115 GTK_SIGNAL_FUNC(to_activated), compose);
4116 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4117 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4118 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4119 GTK_SIGNAL_FUNC(subject_activated), compose);
4120 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4121 GTK_SIGNAL_FUNC(cc_activated), compose);
4122 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4123 GTK_SIGNAL_FUNC(bcc_activated), compose);
4124 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4125 GTK_SIGNAL_FUNC(replyto_activated), compose);
4126 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4127 GTK_SIGNAL_FUNC(followupto_activated), compose);
4129 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4130 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4131 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4132 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4133 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4134 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4135 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4136 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4137 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4138 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4139 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4140 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4141 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4142 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4145 compose->table = NULL;
4146 #if 0 /* NEW COMPOSE GUI */
4147 compose->table = table;
4148 compose->to_hbox = to_hbox;
4149 compose->to_entry = to_entry;
4150 compose->newsgroups_hbox = newsgroups_hbox;
4151 compose->newsgroups_entry = newsgroups_entry;
4153 #if 0 /* NEW COMPOSE GUI */
4154 compose->cc_hbox = cc_hbox;
4155 compose->cc_entry = cc_entry;
4156 compose->bcc_hbox = bcc_hbox;
4157 compose->bcc_entry = bcc_entry;
4158 compose->reply_hbox = reply_hbox;
4159 compose->reply_entry = reply_entry;
4160 compose->followup_hbox = followup_hbox;
4161 compose->followup_entry = followup_entry;
4164 return header_scrolledwin ;
4167 GtkWidget *compose_create_attach(Compose *compose)
4169 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
4172 GtkWidget *attach_scrwin;
4173 GtkWidget *attach_clist;
4175 /* attachment list */
4176 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4177 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4178 GTK_POLICY_AUTOMATIC,
4180 gtk_widget_set_usize(attach_scrwin, -1, 80);
4182 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4183 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4185 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4186 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4187 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4188 GTK_SELECTION_EXTENDED);
4189 for (i = 0; i < N_ATTACH_COLS; i++)
4190 GTK_WIDGET_UNSET_FLAGS
4191 (GTK_CLIST(attach_clist)->column[i].button,
4193 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4195 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4196 GTK_SIGNAL_FUNC(attach_selected), compose);
4197 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4198 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4199 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4200 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4203 gtk_drag_dest_set(attach_clist,
4204 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4206 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4207 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4210 compose->attach_scrwin = attach_scrwin;
4211 compose->attach_clist = attach_clist;
4213 return attach_scrwin;
4216 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4217 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4219 static GtkWidget *compose_create_others(Compose *compose)
4222 GtkWidget *savemsg_checkbtn;
4223 GtkWidget *savemsg_entry;
4224 GtkWidget *savemsg_select;
4227 gchar *folderidentifier;
4229 /* Table for settings */
4230 table = gtk_table_new(3, 1, FALSE);
4231 gtk_widget_show(table);
4232 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4235 /* Save Message to folder */
4236 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4237 gtk_widget_show(savemsg_checkbtn);
4238 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4239 if(folder_get_default_outbox()) {
4240 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4242 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4243 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4245 savemsg_entry = gtk_entry_new();
4246 gtk_widget_show(savemsg_entry);
4247 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4248 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4249 if(folder_get_default_outbox()) {
4250 folderidentifier = folder_item_get_identifier(folder_get_default_outbox());
4251 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4252 g_free(folderidentifier);
4255 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4256 gtk_widget_show (savemsg_select);
4257 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4258 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4259 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4264 compose->savemsg_checkbtn = savemsg_checkbtn;
4265 compose->savemsg_entry = savemsg_entry;
4270 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4272 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4273 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4276 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4281 dest = foldersel_folder_sel(NULL, NULL);
4284 path = folder_item_get_identifier(dest);
4286 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4290 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4296 GtkWidget *handlebox;
4298 GtkWidget *notebook;
4303 GtkWidget *subject_hbox;
4304 GtkWidget *subject_frame;
4305 GtkWidget *subject_entry;
4309 GtkWidget *edit_vbox;
4310 GtkWidget *ruler_hbox;
4312 GtkWidget *scrolledwin;
4317 UndoMain *undostruct;
4319 guint n_menu_entries;
4320 GtkStyle *style, *new_style;
4323 gboolean success[1];
4325 GtkWidget *popupmenu;
4326 GtkWidget *menuitem;
4327 GtkItemFactory *popupfactory;
4328 GtkItemFactory *ifactory;
4329 GtkWidget *tmpl_menu;
4333 GtkPspell * gtkpspell = NULL;
4336 g_return_val_if_fail(account != NULL, NULL);
4338 debug_print(_("Creating compose window...\n"));
4339 compose = g_new0(Compose, 1);
4341 compose->account = account;
4342 compose->orig_account = account;
4344 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4345 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4346 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4347 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4348 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4349 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4350 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4351 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4352 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
4353 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
4354 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
4355 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
4356 gtk_widget_realize(window);
4358 gtkut_widget_set_composer_icon(window);
4360 vbox = gtk_vbox_new(FALSE, 0);
4361 gtk_container_add(GTK_CONTAINER(window), vbox);
4363 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4364 menubar = menubar_create(window, compose_entries,
4365 n_menu_entries, "<Compose>", compose);
4366 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4368 handlebox = gtk_handle_box_new();
4369 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4371 compose_toolbar_create(compose, handlebox);
4373 vbox2 = gtk_vbox_new(FALSE, 2);
4374 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4375 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4378 notebook = gtk_notebook_new();
4379 gtk_widget_set_usize(notebook, -1, 130);
4380 gtk_widget_show(notebook);
4382 /* header labels and entries */
4383 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4384 /* attachment list */
4385 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4387 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4390 subject_hbox = gtk_hbox_new(FALSE, 0);
4391 gtk_widget_show(subject_hbox);
4393 subject_frame = gtk_frame_new(NULL);
4394 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4395 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4396 gtk_widget_show(subject_frame);
4398 subject = gtk_hbox_new(FALSE, 0);
4399 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4400 gtk_widget_show(subject);
4402 label = gtk_label_new(_("Subject:"));
4403 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4404 gtk_widget_show(label);
4406 subject_entry = gtk_entry_new();
4407 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4408 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4409 gtk_widget_show(subject_entry);
4410 compose->subject_entry = subject_entry;
4411 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4413 edit_vbox = gtk_vbox_new(FALSE, 0);
4414 #if 0 /* NEW COMPOSE GUI */
4415 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4418 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4421 ruler_hbox = gtk_hbox_new(FALSE, 0);
4422 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4424 ruler = gtk_shruler_new();
4425 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4426 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4428 gtk_widget_set_usize(ruler_hbox, 1, -1);
4431 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4432 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4433 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4434 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4435 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4437 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4438 (GTK_SCROLLED_WINDOW(scrolledwin)),
4439 gtk_scrolled_window_get_vadjustment
4440 (GTK_SCROLLED_WINDOW(scrolledwin)));
4441 GTK_STEXT(text)->default_tab_width = 8;
4442 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4444 if (prefs_common.block_cursor) {
4445 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4448 if (prefs_common.smart_wrapping) {
4449 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4450 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4453 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4455 gtk_signal_connect(GTK_OBJECT(text), "changed",
4456 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4457 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4458 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4459 gtk_signal_connect(GTK_OBJECT(text), "activate",
4460 GTK_SIGNAL_FUNC(text_activated), compose);
4461 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4462 GTK_SIGNAL_FUNC(compose_button_press_cb),
4465 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4466 GTK_SIGNAL_FUNC(compose_key_press_cb),
4469 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4470 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4474 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4476 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4477 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4479 gtk_widget_show_all(vbox);
4481 /* pane between attach clist and text */
4482 paned = gtk_vpaned_new();
4483 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4484 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4485 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4486 gtk_paned_add1(GTK_PANED(paned), notebook);
4487 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4488 gtk_widget_show_all(paned);
4490 style = gtk_widget_get_style(text);
4492 /* workaround for the slow down of GtkSText when using Pixmap theme */
4493 if (style->engine) {
4494 GtkThemeEngine *engine;
4496 engine = style->engine;
4497 style->engine = NULL;
4498 new_style = gtk_style_copy(style);
4499 style->engine = engine;
4501 new_style = gtk_style_copy(style);
4503 if (prefs_common.textfont) {
4506 charset = conv_get_current_charset();
4507 if (MB_CUR_MAX == 1) {
4510 Xstrdup_a(fontstr, prefs_common.textfont, );
4511 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4513 font = gdk_font_load(fontstr);
4515 font = gdk_fontset_load(prefs_common.textfont);
4517 gdk_font_unref(new_style->font);
4518 new_style->font = font;
4522 gtk_widget_set_style(text, new_style);
4524 color[0] = quote_color;
4525 cmap = gdk_window_get_colormap(window->window);
4526 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4527 if (success[0] == FALSE) {
4528 g_warning("Compose: color allocation failed.\n");
4529 style = gtk_widget_get_style(text);
4530 quote_color = style->black;
4533 n_entries = sizeof(compose_popup_entries) /
4534 sizeof(compose_popup_entries[0]);
4535 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4536 "<Compose>", &popupfactory,
4539 ifactory = gtk_item_factory_from_widget(menubar);
4540 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4541 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4543 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tool/Template");
4544 #if 0 /* NEW COMPOSE GUI */
4545 gtk_widget_hide(bcc_hbox);
4546 gtk_widget_hide(bcc_entry);
4547 gtk_widget_hide(reply_hbox);
4548 gtk_widget_hide(reply_entry);
4549 gtk_widget_hide(followup_hbox);
4550 gtk_widget_hide(followup_entry);
4551 gtk_widget_hide(ruler_hbox);
4552 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4553 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4554 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4556 if (account->protocol == A_NNTP) {
4557 gtk_widget_hide(to_hbox);
4558 gtk_widget_hide(to_entry);
4559 gtk_widget_hide(cc_hbox);
4560 gtk_widget_hide(cc_entry);
4561 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4562 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4564 gtk_widget_hide(newsgroups_hbox);
4565 gtk_widget_hide(newsgroups_entry);
4566 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4567 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
4571 switch (prefs_common.toolbar_style) {
4573 gtk_widget_hide(handlebox);
4576 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4580 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4584 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4589 undostruct = undo_init(text);
4590 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4593 gtk_widget_show(window);
4595 address_completion_start(window);
4597 compose->window = window;
4598 compose->vbox = vbox;
4599 compose->menubar = menubar;
4600 compose->handlebox = handlebox;
4602 compose->vbox2 = vbox2;
4604 compose->paned = paned;
4606 compose->edit_vbox = edit_vbox;
4607 compose->ruler_hbox = ruler_hbox;
4608 compose->ruler = ruler;
4609 compose->scrolledwin = scrolledwin;
4610 compose->text = text;
4612 compose->focused_editable = NULL;
4614 compose->popupmenu = popupmenu;
4615 compose->popupfactory = popupfactory;
4617 compose->tmpl_menu = tmpl_menu;
4619 compose->mode = mode;
4621 compose->targetinfo = NULL;
4622 compose->replyinfo = NULL;
4624 compose->replyto = NULL;
4625 compose->mailinglist = NULL;
4627 compose->bcc = NULL;
4628 compose->followup_to = NULL;
4629 compose->inreplyto = NULL;
4630 compose->references = NULL;
4631 compose->msgid = NULL;
4632 compose->boundary = NULL;
4635 compose->use_signing = FALSE;
4636 compose->use_encryption = FALSE;
4637 #endif /* USE_GPGME */
4639 compose->modified = FALSE;
4641 compose->return_receipt = FALSE;
4643 compose->to_list = NULL;
4644 compose->newsgroup_list = NULL;
4646 compose->exteditor_file = NULL;
4647 compose->exteditor_pid = -1;
4648 compose->exteditor_readdes = -1;
4649 compose->exteditor_tag = -1;
4651 compose->bounce_filename = NULL;
4652 compose->undostruct = undostruct;
4655 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4656 if (prefs_common.enable_pspell) {
4657 gtkpspell = gtkpspell_new((const gchar*)prefs_common.dictionary,
4658 conv_get_current_charset_str(),
4659 prefs_common.check_while_typing,
4662 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkpspellcheckers->error_message);
4663 gtkpspell_checkers_reset();
4666 GtkWidget *menuitem;
4668 gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode);
4669 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
4670 gtkpspell_populate_submenu(gtkpspell, menuitem);
4671 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4676 compose_set_title(compose);
4678 #if 0 /* NEW COMPOSE GUI */
4679 compose->use_bcc = FALSE;
4680 compose->use_replyto = FALSE;
4681 compose->use_followupto = FALSE;
4685 compose->gtkpspell = gtkpspell;
4688 #if 0 /* NEW COMPOSE GUI */
4689 if (account->protocol != A_NNTP) {
4690 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
4691 gtk_check_menu_item_set_active
4692 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4693 gtk_widget_set_sensitive(menuitem, FALSE);
4694 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4695 gtk_check_menu_item_set_active
4696 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4697 gtk_widget_set_sensitive(menuitem, FALSE);
4700 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4701 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4702 #if 0 /* NEW COMPOSE GUI */
4703 compose->use_cc = TRUE;
4704 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4705 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4706 gtk_check_menu_item_set_active
4707 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4710 if (account->set_autobcc) {
4711 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4712 #if 0 /* NEW COMPOSE GUI */
4713 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
4714 gtk_check_menu_item_set_active
4715 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4716 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4717 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4721 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4722 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4723 #if 0 /* NEW COMPOSE GUI */
4724 compose->use_replyto = TRUE;
4725 menuitem = gtk_item_factory_get_item(ifactory,
4727 gtk_check_menu_item_set_active
4728 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4729 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4730 account->auto_replyto);
4734 if (account->protocol != A_NNTP) {
4735 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4737 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4740 #if 0 /* NEW COMPOSE GUI */
4741 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
4742 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4743 prefs_common.show_ruler);
4747 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4748 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4749 account->default_sign);
4750 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4751 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4752 account->default_encrypt);
4753 #endif /* USE_GPGME */
4755 addressbook_set_target_compose(compose);
4756 compose_set_template_menu(compose);
4758 compose_list = g_list_append(compose_list, compose);
4760 #if 0 /* NEW COMPOSE GUI */
4761 compose->use_to = FALSE;
4762 compose->use_cc = FALSE;
4763 compose->use_attach = TRUE;
4766 #if 0 /* NEW COMPOSE GUI */
4767 if (!compose->use_bcc) {
4768 gtk_widget_hide(bcc_hbox);
4769 gtk_widget_hide(bcc_entry);
4770 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4772 if (!compose->use_replyto) {
4773 gtk_widget_hide(reply_hbox);
4774 gtk_widget_hide(reply_entry);
4775 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4777 if (!compose->use_followupto) {
4778 gtk_widget_hide(followup_hbox);
4779 gtk_widget_hide(followup_entry);
4780 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4783 if (!prefs_common.show_ruler)
4784 gtk_widget_hide(ruler_hbox);
4786 select_account(compose, account);
4791 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4794 GtkWidget *icon_wid;
4795 GtkWidget *send_btn;
4796 GtkWidget *sendl_btn;
4797 GtkWidget *draft_btn;
4798 GtkWidget *insert_btn;
4799 GtkWidget *attach_btn;
4801 GtkWidget *exteditor_btn;
4802 GtkWidget *linewrap_btn;
4803 GtkWidget *addrbook_btn;
4805 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4807 gtk_container_add(GTK_CONTAINER(container), toolbar);
4808 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4809 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4810 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4811 GTK_TOOLBAR_SPACE_LINE);
4813 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
4814 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4818 icon_wid, toolbar_send_cb, compose);
4820 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND_QUEUE);
4821 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4823 _("Put into queue folder and send later"),
4825 icon_wid, toolbar_send_later_cb,
4828 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4829 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4831 _("Save to draft folder"),
4833 icon_wid, toolbar_draft_cb,
4836 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4838 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_PASTE);
4839 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4843 icon_wid, toolbar_insert_cb,
4846 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_ATTACH);
4847 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4851 icon_wid, toolbar_attach_cb,
4854 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4856 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4857 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4859 _("Insert signature"),
4861 icon_wid, toolbar_sig_cb, compose);
4863 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4865 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_COMPOSE);
4866 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4868 _("Edit with external editor"),
4871 toolbar_ext_editor_cb,
4874 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_LINEWRAP);
4875 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4877 _("Wrap all long lines"),
4880 toolbar_linewrap_cb,
4883 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4885 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_ADDRESS_BOOK);
4886 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4890 icon_wid, toolbar_address_cb,
4893 compose->toolbar = toolbar;
4894 compose->send_btn = send_btn;
4895 compose->sendl_btn = sendl_btn;
4896 compose->draft_btn = draft_btn;
4897 compose->insert_btn = insert_btn;
4898 compose->attach_btn = attach_btn;
4899 compose->sig_btn = sig_btn;
4900 compose->exteditor_btn = exteditor_btn;
4901 compose->linewrap_btn = linewrap_btn;
4902 compose->addrbook_btn = addrbook_btn;
4904 gtk_widget_show_all(toolbar);
4907 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4913 gint num = 0, def_menu = 0;
4915 accounts = account_get_list();
4916 g_return_val_if_fail(accounts != NULL, NULL);
4918 hbox = gtk_hbox_new(FALSE, 0);
4919 optmenu = gtk_option_menu_new();
4920 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4921 menu = gtk_menu_new();
4923 for (; accounts != NULL; accounts = accounts->next, num++) {
4924 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4925 GtkWidget *menuitem;
4928 if (ac == compose->account) def_menu = num;
4930 name = g_strdup_printf("%s: %s <%s>",
4931 ac->account_name, ac->name, ac->address);
4932 MENUITEM_ADD(menu, menuitem, name, ac);
4934 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4935 GTK_SIGNAL_FUNC(account_activated),
4939 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4940 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4945 static void compose_set_template_menu(Compose *compose)
4947 GSList *tmpl_list, *cur;
4951 tmpl_list = template_get_config();
4953 menu = gtk_menu_new();
4955 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4956 Template *tmpl = (Template *)cur->data;
4958 item = gtk_menu_item_new_with_label(tmpl->name);
4959 gtk_menu_append(GTK_MENU(menu), item);
4960 gtk_signal_connect(GTK_OBJECT(item), "activate",
4961 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4963 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4964 gtk_widget_show(item);
4967 gtk_widget_show(menu);
4968 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4971 void compose_reflect_prefs_all(void)
4976 for (cur = compose_list; cur != NULL; cur = cur->next) {
4977 compose = (Compose *)cur->data;
4978 compose_set_template_menu(compose);
4982 static void compose_template_apply(Compose *compose, Template *tmpl)
4987 if (!tmpl || !tmpl->value) return;
4989 gtk_stext_freeze(GTK_STEXT(compose->text));
4991 if (tmpl->subject && *tmpl->subject != '\0')
4992 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
4994 if (tmpl->to && *tmpl->to != '\0')
4995 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
4997 if (compose->replyinfo == NULL) {
5000 memset(&dummyinfo, 0, sizeof(MsgInfo));
5001 parsed_str = compose_quote_fmt(compose, &dummyinfo,
5004 if (prefs_common.quotemark && *prefs_common.quotemark)
5005 qmark = prefs_common.quotemark;
5009 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5010 tmpl->value, qmark);
5013 if (parsed_str && prefs_common.auto_sig)
5014 compose_insert_sig(compose);
5016 gtk_stext_thaw(GTK_STEXT(compose->text));
5019 static void compose_destroy(Compose *compose)
5022 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5025 /* NOTE: address_completion_end() does nothing with the window
5026 * however this may change. */
5027 address_completion_end(compose->window);
5029 slist_free_strings(compose->to_list);
5030 g_slist_free(compose->to_list);
5031 slist_free_strings(compose->newsgroup_list);
5032 g_slist_free(compose->newsgroup_list);
5033 slist_free_strings(compose->header_list);
5034 g_slist_free(compose->header_list);
5036 procmsg_msginfo_free(compose->targetinfo);
5037 procmsg_msginfo_free(compose->replyinfo);
5039 g_free(compose->replyto);
5040 g_free(compose->cc);
5041 g_free(compose->bcc);
5042 g_free(compose->newsgroups);
5043 g_free(compose->followup_to);
5045 g_free(compose->inreplyto);
5046 g_free(compose->references);
5047 g_free(compose->msgid);
5048 g_free(compose->boundary);
5050 if (compose->bounce_filename)
5051 g_free(compose->bounce_filename);
5053 g_free(compose->exteditor_file);
5055 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5057 compose_attach_info_free(ainfo);
5059 if (addressbook_get_target_compose() == compose)
5060 addressbook_set_target_compose(NULL);
5063 if (compose->gtkpspell) {
5064 gtkpspell_delete(compose->gtkpspell);
5068 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5069 prefs_common.compose_height = compose->window->allocation.height;
5071 gtk_widget_destroy(compose->paned);
5075 compose_list = g_list_remove(compose_list, compose);
5078 static void compose_attach_info_free(AttachInfo *ainfo)
5080 g_free(ainfo->file);
5081 g_free(ainfo->content_type);
5082 g_free(ainfo->name);
5086 static void compose_attach_remove_selected(Compose *compose)
5088 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5092 while (clist->selection != NULL) {
5093 row = GPOINTER_TO_INT(clist->selection->data);
5094 ainfo = gtk_clist_get_row_data(clist, row);
5095 compose_attach_info_free(ainfo);
5096 gtk_clist_remove(clist, row);
5100 static struct _AttachProperty
5103 GtkWidget *mimetype_entry;
5104 GtkWidget *encoding_optmenu;
5105 GtkWidget *path_entry;
5106 GtkWidget *filename_entry;
5108 GtkWidget *cancel_btn;
5111 static void compose_attach_property(Compose *compose)
5113 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5116 GtkOptionMenu *optmenu;
5117 static gboolean cancelled;
5119 if (!clist->selection) return;
5120 row = GPOINTER_TO_INT(clist->selection->data);
5122 ainfo = gtk_clist_get_row_data(clist, row);
5125 if (!attach_prop.window)
5126 compose_attach_property_create(&cancelled);
5127 gtk_widget_grab_focus(attach_prop.ok_btn);
5128 gtk_widget_show(attach_prop.window);
5129 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5131 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5132 if (ainfo->encoding == ENC_UNKNOWN)
5133 gtk_option_menu_set_history(optmenu, ENC_BASE64);
5135 gtk_option_menu_set_history(optmenu, ainfo->encoding);
5137 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5138 ainfo->content_type ? ainfo->content_type : "");
5139 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5140 ainfo->file ? ainfo->file : "");
5141 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5142 ainfo->name ? ainfo->name : "");
5146 gchar *cnttype = NULL;
5150 GtkWidget *menuitem;
5155 if (cancelled == TRUE) {
5156 gtk_widget_hide(attach_prop.window);
5160 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5161 if (*text != '\0') {
5164 text = g_strstrip(g_strdup(text));
5165 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5166 cnttype = g_strdup(text);
5169 alertpanel_error(_("Invalid MIME type."));
5175 menu = gtk_option_menu_get_menu(optmenu);
5176 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5177 ainfo->encoding = GPOINTER_TO_INT
5178 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5180 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5181 if (*text != '\0') {
5182 if (is_file_exist(text) &&
5183 (size = get_file_size(text)) > 0)
5184 file = g_strdup(text);
5187 (_("File doesn't exist or is empty."));
5193 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5194 if (*text != '\0') {
5195 g_free(ainfo->name);
5196 ainfo->name = g_strdup(text);
5200 g_free(ainfo->content_type);
5201 ainfo->content_type = cnttype;
5204 g_free(ainfo->file);
5210 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5211 ainfo->content_type);
5212 gtk_clist_set_text(clist, row, COL_SIZE,
5213 to_human_readable(ainfo->size));
5214 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5216 gtk_widget_hide(attach_prop.window);
5221 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5223 label = gtk_label_new(str); \
5224 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5225 GTK_FILL, 0, 0, 0); \
5226 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5228 entry = gtk_entry_new(); \
5229 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5230 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5233 static void compose_attach_property_create(gboolean *cancelled)
5239 GtkWidget *mimetype_entry;
5242 GtkWidget *optmenu_menu;
5243 GtkWidget *menuitem;
5244 GtkWidget *path_entry;
5245 GtkWidget *filename_entry;
5248 GtkWidget *cancel_btn;
5249 GList *mime_type_list, *strlist;
5251 debug_print("Creating attach_property window...\n");
5253 window = gtk_window_new(GTK_WINDOW_DIALOG);
5254 gtk_widget_set_usize(window, 480, -1);
5255 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5256 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
5257 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5258 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5259 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5260 GTK_SIGNAL_FUNC(attach_property_delete_event),
5262 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5263 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5266 vbox = gtk_vbox_new(FALSE, 8);
5267 gtk_container_add(GTK_CONTAINER(window), vbox);
5269 table = gtk_table_new(4, 2, FALSE);
5270 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5271 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5272 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5274 label = gtk_label_new(_("MIME type"));
5275 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5277 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5278 mimetype_entry = gtk_combo_new();
5279 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5280 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5282 /* stuff with list */
5283 mime_type_list = procmime_get_mime_type_list();
5285 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5286 MimeType *type = (MimeType *) mime_type_list->data;
5287 strlist = g_list_append(strlist,
5288 g_strdup_printf("%s/%s",
5289 type->type, type->sub_type));
5292 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5294 for (mime_type_list = strlist; mime_type_list != NULL;
5295 mime_type_list = mime_type_list->next)
5296 g_free(mime_type_list->data);
5297 g_list_free(strlist);
5299 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5301 label = gtk_label_new(_("Encoding"));
5302 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5304 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5306 hbox = gtk_hbox_new(FALSE, 0);
5307 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5308 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5310 optmenu = gtk_option_menu_new();
5311 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5313 optmenu_menu = gtk_menu_new();
5314 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5315 gtk_widget_set_sensitive(menuitem, FALSE);
5316 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5317 gtk_widget_set_sensitive(menuitem, FALSE);
5318 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5319 gtk_widget_set_sensitive(menuitem, FALSE);
5320 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5322 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5324 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5325 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5327 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5328 &cancel_btn, _("Cancel"), NULL, NULL);
5329 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5330 gtk_widget_grab_default(ok_btn);
5332 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5333 GTK_SIGNAL_FUNC(attach_property_ok),
5335 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5336 GTK_SIGNAL_FUNC(attach_property_cancel),
5339 gtk_widget_show_all(vbox);
5341 attach_prop.window = window;
5342 attach_prop.mimetype_entry = mimetype_entry;
5343 attach_prop.encoding_optmenu = optmenu;
5344 attach_prop.path_entry = path_entry;
5345 attach_prop.filename_entry = filename_entry;
5346 attach_prop.ok_btn = ok_btn;
5347 attach_prop.cancel_btn = cancel_btn;
5350 #undef SET_LABEL_AND_ENTRY
5352 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5358 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5364 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5365 gboolean *cancelled)
5373 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5374 gboolean *cancelled)
5376 if (event && event->keyval == GDK_Escape) {
5382 static void compose_exec_ext_editor(Compose *compose)
5388 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5389 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5391 if (pipe(pipe_fds) < 0) {
5396 if ((pid = fork()) < 0) {
5402 /* close the write side of the pipe */
5405 compose->exteditor_file = g_strdup(tmp);
5406 compose->exteditor_pid = pid;
5407 compose->exteditor_readdes = pipe_fds[0];
5409 compose_set_ext_editor_sensitive(compose, FALSE);
5411 compose->exteditor_tag =
5412 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5413 compose_input_cb, compose);
5414 } else { /* process-monitoring process */
5420 /* close the read side of the pipe */
5423 if (compose_write_body_to_file(compose, tmp) < 0) {
5424 fd_write(pipe_fds[1], "2\n", 2);
5428 pid_ed = compose_exec_ext_editor_real(tmp);
5430 fd_write(pipe_fds[1], "1\n", 2);
5434 /* wait until editor is terminated */
5435 waitpid(pid_ed, NULL, 0);
5437 fd_write(pipe_fds[1], "0\n", 2);
5444 static gint compose_exec_ext_editor_real(const gchar *file)
5446 static gchar *def_cmd = "emacs %s";
5452 g_return_val_if_fail(file != NULL, -1);
5454 if ((pid = fork()) < 0) {
5459 if (pid != 0) return pid;
5461 /* grandchild process */
5463 if (setpgid(0, getppid()))
5466 if (prefs_common.ext_editor_cmd &&
5467 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5468 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5469 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5471 if (prefs_common.ext_editor_cmd)
5472 g_warning(_("External editor command line is invalid: `%s'\n"),
5473 prefs_common.ext_editor_cmd);
5474 g_snprintf(buf, sizeof(buf), def_cmd, file);
5477 cmdline = g_strsplit(buf, " ", 1024);
5478 execvp(cmdline[0], cmdline);
5481 g_strfreev(cmdline);
5486 static gboolean compose_ext_editor_kill(Compose *compose)
5488 pid_t pgid = compose->exteditor_pid * -1;
5491 ret = kill(pgid, 0);
5493 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5497 msg = g_strdup_printf
5498 (_("The external editor is still working.\n"
5499 "Force terminating the process?\n"
5500 "process group id: %d"), -pgid);
5501 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5504 if (val == G_ALERTDEFAULT) {
5505 gdk_input_remove(compose->exteditor_tag);
5506 close(compose->exteditor_readdes);
5508 if (kill(pgid, SIGTERM) < 0) perror("kill");
5509 waitpid(compose->exteditor_pid, NULL, 0);
5511 g_warning(_("Terminated process group id: %d"), -pgid);
5512 g_warning(_("Temporary file: %s"),
5513 compose->exteditor_file);
5515 compose_set_ext_editor_sensitive(compose, TRUE);
5517 g_free(compose->exteditor_file);
5518 compose->exteditor_file = NULL;
5519 compose->exteditor_pid = -1;
5520 compose->exteditor_readdes = -1;
5521 compose->exteditor_tag = -1;
5529 static void compose_input_cb(gpointer data, gint source,
5530 GdkInputCondition condition)
5533 Compose *compose = (Compose *)data;
5536 debug_print(_("Compose: input from monitoring process\n"));
5538 gdk_input_remove(compose->exteditor_tag);
5541 if (read(source, &buf[i], 1) < 1) {
5545 if (buf[i] == '\n') {
5550 if (i == sizeof(buf) - 1)
5554 waitpid(compose->exteditor_pid, NULL, 0);
5556 if (buf[0] == '0') { /* success */
5557 GtkSText *text = GTK_STEXT(compose->text);
5559 gtk_stext_freeze(text);
5560 gtk_stext_set_point(text, 0);
5561 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5562 compose_insert_file(compose, compose->exteditor_file);
5563 compose_changed_cb(NULL, compose);
5564 gtk_stext_thaw(text);
5566 if (unlink(compose->exteditor_file) < 0)
5567 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5568 } else if (buf[0] == '1') { /* failed */
5569 g_warning(_("Couldn't exec external editor\n"));
5570 if (unlink(compose->exteditor_file) < 0)
5571 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5572 } else if (buf[0] == '2') {
5573 g_warning(_("Couldn't write to file\n"));
5574 } else if (buf[0] == '3') {
5575 g_warning(_("Pipe read failed\n"));
5580 compose_set_ext_editor_sensitive(compose, TRUE);
5582 g_free(compose->exteditor_file);
5583 compose->exteditor_file = NULL;
5584 compose->exteditor_pid = -1;
5585 compose->exteditor_readdes = -1;
5586 compose->exteditor_tag = -1;
5589 static void compose_set_ext_editor_sensitive(Compose *compose,
5592 GtkItemFactory *ifactory;
5594 ifactory = gtk_item_factory_from_widget(compose->menubar);
5596 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5597 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5598 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5600 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5601 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5602 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5603 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5604 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5607 gtk_widget_set_sensitive(compose->text, sensitive);
5608 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5609 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5610 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5611 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5612 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5613 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5614 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5618 * compose_undo_state_changed:
5620 * Change the sensivity of the menuentries undo and redo
5622 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5623 gint redo_state, gpointer data)
5625 GtkWidget *widget = GTK_WIDGET(data);
5626 GtkItemFactory *ifactory;
5628 g_return_if_fail(widget != NULL);
5630 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
5632 ifactory = gtk_item_factory_from_widget(widget);
5634 switch (undo_state) {
5635 case UNDO_STATE_TRUE:
5636 if (!undostruct->undo_state) {
5637 debug_print ("Set_undo - Testpoint\n");
5638 undostruct->undo_state = TRUE;
5639 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5642 case UNDO_STATE_FALSE:
5643 if (undostruct->undo_state) {
5644 undostruct->undo_state = FALSE;
5645 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5648 case UNDO_STATE_UNCHANGED:
5650 case UNDO_STATE_REFRESH:
5651 menu_set_sensitive(ifactory, "/Edit/Undo",
5652 undostruct->undo_state);
5655 g_warning("Undo state not recognized");
5659 switch (redo_state) {
5660 case UNDO_STATE_TRUE:
5661 if (!undostruct->redo_state) {
5662 undostruct->redo_state = TRUE;
5663 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5666 case UNDO_STATE_FALSE:
5667 if (undostruct->redo_state) {
5668 undostruct->redo_state = FALSE;
5669 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5672 case UNDO_STATE_UNCHANGED:
5674 case UNDO_STATE_REFRESH:
5675 menu_set_sensitive(ifactory, "/Edit/Redo",
5676 undostruct->redo_state);
5679 g_warning("Redo state not recognized");
5684 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5688 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5689 cursor_pos = MAX(cursor_pos, 0);
5694 /* callback functions */
5696 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5697 * includes "non-client" (windows-izm) in calculation, so this calculation
5698 * may not be accurate.
5700 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5701 GtkAllocation *allocation,
5702 GtkSHRuler *shruler)
5704 if (prefs_common.show_ruler) {
5706 gint line_width_in_chars;
5708 char_width = gtkut_get_font_width
5709 (GTK_WIDGET(widget)->style->font);
5710 line_width_in_chars =
5711 (allocation->width - allocation->x) / char_width;
5713 /* got the maximum */
5714 gtk_ruler_set_range(GTK_RULER(shruler),
5715 0.0, line_width_in_chars,
5716 calc_cursor_xpos(GTK_STEXT(widget),
5719 /*line_width_in_chars*/ char_width);
5725 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5727 compose_send_cb(data, 0, NULL);
5730 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5732 compose_send_later_cb(data, 0, NULL);
5735 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5737 compose_draft_cb(data, 0, NULL);
5740 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5742 compose_insert_file_cb(data, 0, NULL);
5745 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5747 compose_attach_cb(data, 0, NULL);
5750 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5752 Compose *compose = (Compose *)data;
5754 compose_insert_sig(compose);
5757 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5759 Compose *compose = (Compose *)data;
5761 compose_exec_ext_editor(compose);
5764 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5766 Compose *compose = (Compose *)data;
5768 compose_wrap_line(compose);
5771 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5773 compose_address_cb(data, 0, NULL);
5776 static void select_account(Compose * compose, PrefsAccount * ac)
5778 compose->account = ac;
5779 compose_set_title(compose);
5781 #if 0 /* NEW COMPOSE GUI */
5782 if (ac->protocol == A_NNTP) {
5783 GtkItemFactory *ifactory;
5784 GtkWidget *menuitem;
5786 ifactory = gtk_item_factory_from_widget(compose->menubar);
5787 menu_set_sensitive(ifactory,
5788 "/Message/Followup to", TRUE);
5789 gtk_widget_show(compose->newsgroups_hbox);
5790 gtk_widget_show(compose->newsgroups_entry);
5791 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5794 compose->use_to = FALSE;
5795 compose->use_cc = FALSE;
5797 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5798 gtk_check_menu_item_set_active
5799 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5801 menu_set_sensitive(ifactory,
5802 "/Message/To", TRUE);
5803 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5804 gtk_check_menu_item_set_active
5805 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5807 gtk_widget_hide(compose->to_hbox);
5808 gtk_widget_hide(compose->to_entry);
5809 gtk_widget_hide(compose->cc_hbox);
5810 gtk_widget_hide(compose->cc_entry);
5811 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5813 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5817 GtkItemFactory *ifactory;
5818 GtkWidget *menuitem;
5820 ifactory = gtk_item_factory_from_widget(compose->menubar);
5821 menu_set_sensitive(ifactory,
5822 "/Message/Followup to", FALSE);
5823 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5824 gtk_widget_hide(compose->newsgroups_hbox);
5825 gtk_widget_hide(compose->newsgroups_entry);
5826 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5829 compose->use_to = TRUE;
5830 compose->use_cc = TRUE;
5832 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5833 gtk_check_menu_item_set_active
5834 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5835 menu_set_sensitive(ifactory,
5836 "/Message/To", FALSE);
5837 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5838 gtk_check_menu_item_set_active
5839 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5840 gtk_widget_show(compose->to_hbox);
5841 gtk_widget_show(compose->to_entry);
5842 gtk_widget_show(compose->cc_hbox);
5843 gtk_widget_show(compose->cc_entry);
5845 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5847 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5850 gtk_widget_queue_resize(compose->table_vbox);
5854 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5856 Compose *compose = (Compose *)data;
5860 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5861 g_return_if_fail(ac != NULL);
5863 if (ac != compose->account)
5864 select_account(compose, ac);
5867 static void attach_selected(GtkCList *clist, gint row, gint column,
5868 GdkEvent *event, gpointer data)
5870 Compose *compose = (Compose *)data;
5872 if (event && event->type == GDK_2BUTTON_PRESS)
5873 compose_attach_property(compose);
5876 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5879 Compose *compose = (Compose *)data;
5880 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5885 if (event->button == 3) {
5886 if ((clist->selection && !clist->selection->next) ||
5887 !clist->selection) {
5888 gtk_clist_unselect_all(clist);
5889 if (gtk_clist_get_selection_info(clist,
5892 gtk_clist_select_row(clist, row, column);
5893 gtkut_clist_set_focus_row(clist, row);
5896 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5897 NULL, NULL, event->button, event->time);
5901 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5904 Compose *compose = (Compose *)data;
5908 switch (event->keyval) {
5910 compose_attach_remove_selected(compose);
5915 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5917 Compose *compose = (Compose *)data;
5920 val = compose_send(compose);
5922 if (val == 0) gtk_widget_destroy(compose->window);
5925 static void compose_send_later_cb(gpointer data, guint action,
5928 Compose *compose = (Compose *)data;
5931 val = compose_queue(compose, NULL, NULL);
5932 if (!val) gtk_widget_destroy(compose->window);
5935 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5937 Compose *compose = (Compose *)data;
5941 static gboolean lock = FALSE;
5945 draft = folder_get_default_draft();
5946 g_return_if_fail(draft != NULL);
5950 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5951 G_DIR_SEPARATOR, (gint)compose);
5953 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5959 folder_item_scan(draft);
5960 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) <= 0) {
5967 draft->mtime = 0; /* force updating */
5969 if (compose->mode == COMPOSE_REEDIT) {
5970 compose_remove_reedit_target(compose);
5971 if (compose->targetinfo &&
5972 compose->targetinfo->folder != draft)
5973 folderview_update_item(compose->targetinfo->folder,
5977 folder_item_scan(draft);
5978 folderview_update_item(draft, TRUE);
5982 /* 0: quit editing 1: keep editing */
5984 gtk_widget_destroy(compose->window);
5989 path = folder_item_fetch_msg(draft, msgnum);
5990 g_return_if_fail(path != NULL);
5991 if (stat(path, &s) < 0) {
5992 FILE_OP_ERROR(path, "stat");
5999 procmsg_msginfo_free(compose->targetinfo);
6000 compose->targetinfo = g_new0(MsgInfo, 1);
6001 compose->targetinfo->msgnum = msgnum;
6002 compose->targetinfo->size = s.st_size;
6003 compose->targetinfo->mtime = s.st_mtime;
6004 compose->targetinfo->folder = draft;
6005 compose->mode = COMPOSE_REEDIT;
6009 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6011 Compose *compose = (Compose *)data;
6014 if (compose->bounce_filename != NULL)
6017 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6022 for ( tmp = file_list; tmp; tmp = tmp->next) {
6023 gchar *file = (gchar *) tmp->data;
6024 compose_attach_append(compose, file, MIME_UNKNOWN);
6027 g_list_free(file_list);
6031 static void compose_insert_file_cb(gpointer data, guint action,
6034 Compose *compose = (Compose *)data;
6037 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6042 for ( tmp = file_list; tmp; tmp = tmp->next) {
6043 gchar *file = (gchar *) tmp->data;
6044 compose_insert_file(compose, file);
6047 g_list_free(file_list);
6051 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6054 compose_close_cb(data, 0, NULL);
6058 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6060 Compose *compose = (Compose *)data;
6063 if (compose->exteditor_tag != -1) {
6064 if (!compose_ext_editor_kill(compose))
6068 if (compose->modified) {
6069 val = alertpanel(_("Discard message"),
6070 _("This message has been modified. discard it?"),
6071 _("Discard"), _("to Draft"), _("Cancel"));
6074 case G_ALERTDEFAULT:
6076 case G_ALERTALTERNATE:
6077 compose_draft_cb(data, 0, NULL);
6083 gtk_widget_destroy(compose->window);
6086 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6088 Compose *compose = (Compose *)data;
6090 addressbook_open(compose);
6093 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6095 Compose *compose = (Compose *)data;
6098 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6099 g_return_if_fail(tmpl != NULL);
6101 compose_template_apply(compose, tmpl);
6104 static void compose_ext_editor_cb(gpointer data, guint action,
6107 Compose *compose = (Compose *)data;
6109 compose_exec_ext_editor(compose);
6112 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6114 compose_destroy(compose);
6117 static void compose_undo_cb(Compose *compose)
6119 undo_undo(compose->undostruct);
6122 static void compose_redo_cb(Compose *compose)
6124 undo_redo(compose->undostruct);
6127 static void compose_cut_cb(Compose *compose)
6129 if (compose->focused_editable &&
6130 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6131 gtk_editable_cut_clipboard
6132 (GTK_EDITABLE(compose->focused_editable));
6135 static void compose_copy_cb(Compose *compose)
6137 if (compose->focused_editable &&
6138 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6139 gtk_editable_copy_clipboard
6140 (GTK_EDITABLE(compose->focused_editable));
6143 static void compose_paste_cb(Compose *compose)
6145 if (compose->focused_editable &&
6146 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6147 gtk_editable_paste_clipboard
6148 (GTK_EDITABLE(compose->focused_editable));
6151 static void compose_allsel_cb(Compose *compose)
6153 if (compose->focused_editable &&
6154 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6155 gtk_editable_select_region
6156 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6159 static void compose_move_beginning_of_line_cb(Compose *compose)
6161 if (compose->focused_editable &&
6162 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6163 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6166 static void compose_gtk_stext_action_cb(Compose *compose, ComposeCallGtkSTextAction action)
6168 if (!(compose->focused_editable && GTK_WIDGET_HAS_FOCUS(compose->focused_editable))) return;
6171 case COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE:
6172 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6174 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER:
6175 gtk_stext_move_forward_character(GTK_STEXT(compose->focused_editable));
6177 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER:
6178 gtk_stext_move_backward_character(GTK_STEXT(compose->focused_editable));
6180 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD:
6181 gtk_stext_move_forward_word(GTK_STEXT(compose->focused_editable));
6183 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD:
6184 gtk_stext_move_backward_word(GTK_STEXT(compose->focused_editable));
6186 case COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE:
6187 gtk_stext_move_end_of_line(GTK_STEXT(compose->focused_editable));
6189 case COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE:
6190 gtk_stext_move_next_line(GTK_STEXT(compose->focused_editable));
6192 case COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE:
6193 gtk_stext_move_previous_line(GTK_STEXT(compose->focused_editable));
6195 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER:
6196 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6198 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER:
6199 gtk_stext_delete_backward_character(GTK_STEXT(compose->focused_editable));
6201 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD:
6202 gtk_stext_delete_forward_word(GTK_STEXT(compose->focused_editable));
6204 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD:
6205 gtk_stext_delete_backward_word(GTK_STEXT(compose->focused_editable));
6207 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE:
6208 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6210 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N:
6211 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6212 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6214 case COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END:
6215 gtk_stext_delete_to_line_end(GTK_STEXT(compose->focused_editable));
6222 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6224 if (GTK_IS_EDITABLE(widget))
6225 compose->focused_editable = widget;
6228 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6230 if (compose->modified == FALSE) {
6231 compose->modified = TRUE;
6232 compose_set_title(compose);
6236 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6239 gtk_stext_set_point(GTK_STEXT(widget),
6240 gtk_editable_get_position(GTK_EDITABLE(widget)));
6244 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6247 gtk_stext_set_point(GTK_STEXT(widget),
6248 gtk_editable_get_position(GTK_EDITABLE(widget)));
6252 #if 0 /* NEW COMPOSE GUI */
6253 static void compose_toggle_to_cb(gpointer data, guint action,
6256 Compose *compose = (Compose *)data;
6258 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6259 gtk_widget_show(compose->to_hbox);
6260 gtk_widget_show(compose->to_entry);
6261 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6262 compose->use_to = TRUE;
6264 gtk_widget_hide(compose->to_hbox);
6265 gtk_widget_hide(compose->to_entry);
6266 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6267 gtk_widget_queue_resize(compose->table_vbox);
6268 compose->use_to = FALSE;
6271 if (addressbook_get_target_compose() == compose)
6272 addressbook_set_target_compose(compose);
6275 static void compose_toggle_cc_cb(gpointer data, guint action,
6278 Compose *compose = (Compose *)data;
6280 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6281 gtk_widget_show(compose->cc_hbox);
6282 gtk_widget_show(compose->cc_entry);
6283 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6284 compose->use_cc = TRUE;
6286 gtk_widget_hide(compose->cc_hbox);
6287 gtk_widget_hide(compose->cc_entry);
6288 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6289 gtk_widget_queue_resize(compose->table_vbox);
6290 compose->use_cc = FALSE;
6293 if (addressbook_get_target_compose() == compose)
6294 addressbook_set_target_compose(compose);
6297 static void compose_toggle_bcc_cb(gpointer data, guint action,
6300 Compose *compose = (Compose *)data;
6302 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6303 gtk_widget_show(compose->bcc_hbox);
6304 gtk_widget_show(compose->bcc_entry);
6305 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6306 compose->use_bcc = TRUE;
6308 gtk_widget_hide(compose->bcc_hbox);
6309 gtk_widget_hide(compose->bcc_entry);
6310 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6311 gtk_widget_queue_resize(compose->table_vbox);
6312 compose->use_bcc = FALSE;
6315 if (addressbook_get_target_compose() == compose)
6316 addressbook_set_target_compose(compose);
6319 static void compose_toggle_replyto_cb(gpointer data, guint action,
6322 Compose *compose = (Compose *)data;
6324 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6325 gtk_widget_show(compose->reply_hbox);
6326 gtk_widget_show(compose->reply_entry);
6327 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6328 compose->use_replyto = TRUE;
6330 gtk_widget_hide(compose->reply_hbox);
6331 gtk_widget_hide(compose->reply_entry);
6332 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6333 gtk_widget_queue_resize(compose->table_vbox);
6334 compose->use_replyto = FALSE;
6338 static void compose_toggle_followupto_cb(gpointer data, guint action,
6341 Compose *compose = (Compose *)data;
6343 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6344 gtk_widget_show(compose->followup_hbox);
6345 gtk_widget_show(compose->followup_entry);
6346 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6347 compose->use_followupto = TRUE;
6349 gtk_widget_hide(compose->followup_hbox);
6350 gtk_widget_hide(compose->followup_entry);
6351 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6352 gtk_widget_queue_resize(compose->table_vbox);
6353 compose->use_followupto = FALSE;
6357 static void compose_toggle_attach_cb(gpointer data, guint action,
6360 Compose *compose = (Compose *)data;
6362 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6363 gtk_widget_ref(compose->edit_vbox);
6365 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6366 compose->edit_vbox);
6367 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6368 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6370 gtk_widget_show(compose->paned);
6372 gtk_widget_unref(compose->edit_vbox);
6373 gtk_widget_unref(compose->paned);
6375 compose->use_attach = TRUE;
6377 gtk_widget_ref(compose->paned);
6378 gtk_widget_ref(compose->edit_vbox);
6380 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6382 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6383 compose->edit_vbox);
6384 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6385 compose->edit_vbox, TRUE, TRUE, 0);
6387 gtk_widget_unref(compose->edit_vbox);
6389 compose->use_attach = FALSE;
6395 static void compose_toggle_sign_cb(gpointer data, guint action,
6398 Compose *compose = (Compose *)data;
6400 if (GTK_CHECK_MENU_ITEM(widget)->active)
6401 compose->use_signing = TRUE;
6403 compose->use_signing = FALSE;
6406 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6409 Compose *compose = (Compose *)data;
6411 if (GTK_CHECK_MENU_ITEM(widget)->active)
6412 compose->use_encryption = TRUE;
6414 compose->use_encryption = FALSE;
6416 #endif /* USE_GPGME */
6418 static void compose_toggle_ruler_cb(gpointer data, guint action,
6421 Compose *compose = (Compose *)data;
6423 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6424 gtk_widget_show(compose->ruler_hbox);
6425 prefs_common.show_ruler = TRUE;
6427 gtk_widget_hide(compose->ruler_hbox);
6428 gtk_widget_queue_resize(compose->edit_vbox);
6429 prefs_common.show_ruler = FALSE;
6433 static void compose_attach_drag_received_cb (GtkWidget *widget,
6434 GdkDragContext *drag_context,
6437 GtkSelectionData *data,
6442 Compose *compose = (Compose *)user_data;
6445 list = uri_list_extract_filenames((const gchar *)data->data);
6446 for (tmp = list; tmp != NULL; tmp = tmp->next)
6447 compose_attach_append(compose, (const gchar *)tmp->data,
6449 list_free_strings(list);
6453 static void compose_insert_drag_received_cb (GtkWidget *widget,
6454 GdkDragContext *drag_context,
6457 GtkSelectionData *data,
6462 Compose *compose = (Compose *)user_data;
6465 list = uri_list_extract_filenames((const gchar *)data->data);
6466 for (tmp = list; tmp != NULL; tmp = tmp->next)
6467 compose_insert_file(compose, (const gchar *)tmp->data);
6468 list_free_strings(list);
6472 #if 0 /* NEW COMPOSE GUI */
6473 static void to_activated(GtkWidget *widget, Compose *compose)
6475 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6476 gtk_widget_grab_focus(compose->newsgroups_entry);
6478 gtk_widget_grab_focus(compose->subject_entry);
6481 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6483 gtk_widget_grab_focus(compose->subject_entry);
6486 static void subject_activated(GtkWidget *widget, Compose *compose)
6488 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6489 gtk_widget_grab_focus(compose->cc_entry);
6490 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6491 gtk_widget_grab_focus(compose->bcc_entry);
6492 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6493 gtk_widget_grab_focus(compose->reply_entry);
6494 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6495 gtk_widget_grab_focus(compose->followup_entry);
6497 gtk_widget_grab_focus(compose->text);
6500 static void cc_activated(GtkWidget *widget, Compose *compose)
6502 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6503 gtk_widget_grab_focus(compose->bcc_entry);
6504 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6505 gtk_widget_grab_focus(compose->reply_entry);
6506 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6507 gtk_widget_grab_focus(compose->followup_entry);
6509 gtk_widget_grab_focus(compose->text);
6512 static void bcc_activated(GtkWidget *widget, Compose *compose)
6514 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6515 gtk_widget_grab_focus(compose->reply_entry);
6516 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6517 gtk_widget_grab_focus(compose->followup_entry);
6519 gtk_widget_grab_focus(compose->text);
6522 static void replyto_activated(GtkWidget *widget, Compose *compose)
6524 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6525 gtk_widget_grab_focus(compose->followup_entry);
6527 gtk_widget_grab_focus(compose->text);
6530 static void followupto_activated(GtkWidget *widget, Compose *compose)
6532 gtk_widget_grab_focus(compose->text);
6536 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6539 Compose *compose = (Compose *)data;
6541 if (GTK_CHECK_MENU_ITEM(widget)->active)
6542 compose->return_receipt = TRUE;
6544 compose->return_receipt = FALSE;
6547 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6549 ComposeHeaderEntry *headerentry)
6551 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6552 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6553 !(event->state & GDK_MODIFIER_MASK) &&
6554 (event->keyval == GDK_BackSpace) &&
6555 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6556 gtk_container_remove
6557 (GTK_CONTAINER(headerentry->compose->header_table),
6558 headerentry->combo);
6559 gtk_container_remove
6560 (GTK_CONTAINER(headerentry->compose->header_table),
6561 headerentry->entry);
6562 headerentry->compose->header_list =
6563 g_slist_remove(headerentry->compose->header_list,
6565 g_free(headerentry);
6566 } else if (event->keyval == GDK_Tab) {
6567 if (headerentry->compose->header_last == headerentry) {
6568 /* Override default next focus, and give it to subject_entry
6569 * instead of notebook tabs
6571 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6572 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6578 void compose_headerentry_changed_cb(GtkWidget *entry,
6579 ComposeHeaderEntry *headerentry)
6581 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6582 headerentry->compose->header_list =
6583 g_slist_append(headerentry->compose->header_list,
6585 compose_create_header_entry(headerentry->compose);
6586 gtk_signal_disconnect_by_func
6588 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6590 /* Automatically scroll down */
6591 compose_show_first_last_header(headerentry->compose, FALSE);
6596 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6598 GtkAdjustment *vadj;
6600 g_return_if_fail(compose);
6601 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6602 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6604 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6605 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6608 static void text_activated(GtkWidget *widget, Compose *compose)
6610 compose_send_control_enter(compose);
6613 static gboolean compose_send_control_enter(Compose *compose)
6617 GtkItemFactory *ifactory;
6618 GtkAccelEntry *accel;
6619 GtkWidget *send_menu;
6622 ev = gtk_get_current_event();
6623 if (ev->type != GDK_KEY_PRESS) return FALSE;
6625 kev = (GdkEventKey *)ev;
6626 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6629 ifactory = gtk_item_factory_from_widget(compose->menubar);
6630 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6631 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6632 accel = (GtkAccelEntry *)list->data;
6633 if (accel->accelerator_key == kev->keyval &&
6634 accel->accelerator_mods == kev->state) {
6635 compose_send_cb(compose, 0, NULL);
6643 static void compose_check_all(Compose *compose)
6645 if (compose->gtkpspell)
6646 gtkpspell_check_all(compose->gtkpspell);
6649 static void compose_check_backwards(Compose *compose)
6651 if (compose->gtkpspell)
6652 gtkpspell_check_backwards(compose->gtkpspell);
6654 GtkItemFactory *ifactory;
6655 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6656 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6657 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6661 static void compose_check_forwards_go(Compose *compose)
6663 if (compose->gtkpspell)
6664 gtkpspell_check_forwards_go(compose->gtkpspell);
6666 GtkItemFactory *ifactory;
6667 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6668 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6669 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);