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);
454 static void compose_check_all (Compose *compose);
455 static void compose_highlight_all (Compose *compose);
456 static void compose_check_backwards (Compose *compose);
457 static void compose_check_forwards_go (Compose *compose);
460 static gboolean compose_send_control_enter (Compose *compose);
461 static void text_activated (GtkWidget *widget,
464 static GtkItemFactoryEntry compose_popup_entries[] =
466 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
467 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
468 {N_("/---"), NULL, NULL, 0, "<Separator>"},
469 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
472 static GtkItemFactoryEntry compose_entries[] =
474 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
475 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
476 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
477 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
478 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
479 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
481 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
482 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
483 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
484 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
485 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
486 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
487 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
488 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
489 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
490 {N_("/_Edit/A_dvanced/Move a character backward"),
492 compose_gtk_stext_action_cb,
493 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
495 {N_("/_Edit/A_dvanced/Move a character forward"),
497 compose_gtk_stext_action_cb,
498 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
500 {N_("/_Edit/A_dvanced/Move a word backward"),
502 compose_gtk_stext_action_cb,
503 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
505 {N_("/_Edit/A_dvanced/Move a word forward"),
507 compose_gtk_stext_action_cb,
508 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
510 {N_("/_Edit/A_dvanced/Move to beginning of line"),
511 NULL, /* "<control>A" */
512 compose_gtk_stext_action_cb,
513 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
515 {N_("/_Edit/A_dvanced/Move to end of line"),
517 compose_gtk_stext_action_cb,
518 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
520 {N_("/_Edit/A_dvanced/Move to previous line"),
522 compose_gtk_stext_action_cb,
523 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
525 {N_("/_Edit/A_dvanced/Move to next line"),
527 compose_gtk_stext_action_cb,
528 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
530 {N_("/_Edit/A_dvanced/Delete a character backward"),
532 compose_gtk_stext_action_cb,
533 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
535 {N_("/_Edit/A_dvanced/Delete a character forward"),
537 compose_gtk_stext_action_cb,
538 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
540 {N_("/_Edit/A_dvanced/Delete a word backward"),
541 NULL, /* "<control>W" */
542 compose_gtk_stext_action_cb,
543 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
545 {N_("/_Edit/A_dvanced/Delete a word forward"),
546 NULL, /* "<alt>D", */
547 compose_gtk_stext_action_cb,
548 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
550 {N_("/_Edit/A_dvanced/Delete line"),
552 compose_gtk_stext_action_cb,
553 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
555 {N_("/_Edit/A_dvanced/Delete entire line"),
557 compose_gtk_stext_action_cb,
558 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
560 {N_("/_Edit/A_dvanced/Delete to end of line"),
562 compose_gtk_stext_action_cb,
563 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
565 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
566 {N_("/_Edit/_Wrap current paragraph"),
567 "<control>L", compose_wrap_line, 0, NULL},
568 {N_("/_Edit/Wrap all long _lines"),
569 "<control><alt>L", compose_wrap_line_all, 0, NULL},
570 {N_("/_Edit/Edit with e_xternal editor"),
571 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
573 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
574 {N_("/_Spelling/_Check all or check selection"),
575 NULL, compose_check_all, 0, NULL},
576 {N_("/_Spelling/_Highlight all misspelled words"),
577 NULL, compose_highlight_all, 0, NULL},
578 {N_("/_Spelling/Check _backwards misspelled word"),
579 NULL, compose_check_backwards , 0, NULL},
580 {N_("/_Spelling/_Forward to next misspelled word"),
581 NULL, compose_check_forwards_go, 0, NULL},
582 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
583 {N_("/_Spelling/_Spelling Configuration"),
584 NULL, NULL, 0, "<Branch>"},
586 #if 0 /* NEW COMPOSE GUI */
587 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
588 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
589 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
590 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
591 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
592 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
593 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
594 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
595 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
596 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
597 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
599 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
600 {N_("/_Message/_Send"), "<control>Return",
601 compose_send_cb, 0, NULL},
602 {N_("/_Message/Send _later"), "<shift><control>S",
603 compose_send_later_cb, 0, NULL},
604 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
605 {N_("/_Message/Save to _draft folder"),
606 "<shift><control>D", compose_draft_cb, 0, NULL},
607 {N_("/_Message/Save and _keep editing"),
608 "<control>S", compose_draft_cb, 1, NULL},
609 #if 0 /* NEW COMPOSE GUI */
610 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
611 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
612 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
613 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
614 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
615 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
616 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
617 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
618 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
621 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
622 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
623 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
624 #endif /* USE_GPGME */
625 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
626 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
627 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
628 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
629 {N_("/_Tool/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
630 {N_("/_Tool/_Template"), NULL, NULL, 0, "<Branch>"},
631 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
632 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
635 static GtkTargetEntry compose_mime_types[] =
637 {"text/uri-list", 0, 0}
640 Compose *compose_new(PrefsAccount *account)
642 return compose_generic_new(account, NULL, NULL);
645 Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
649 GtkItemFactory *ifactory;
651 c = compose_generic_new(account, NULL, NULL);
653 filename = procmsg_get_message_file(msginfo);
654 if (filename == NULL)
657 c->bounce_filename = filename;
659 if (msginfo->subject)
660 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
662 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
664 compose_quote_fmt(c, msginfo, "%M", NULL);
665 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
667 ifactory = gtk_item_factory_from_widget(c->popupmenu);
668 menu_set_sensitive(ifactory, "/Add...", FALSE);
669 menu_set_sensitive(ifactory, "/Remove", FALSE);
670 menu_set_sensitive(ifactory, "/Property...", FALSE);
672 ifactory = gtk_item_factory_from_widget(c->menubar);
673 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
674 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
675 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
676 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
677 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
678 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
679 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
680 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
682 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
683 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
685 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
686 menu_set_sensitive(ifactory, "/Tool/Template", FALSE);
688 gtk_widget_set_sensitive(c->insert_btn, FALSE);
689 gtk_widget_set_sensitive(c->attach_btn, FALSE);
690 gtk_widget_set_sensitive(c->sig_btn, FALSE);
691 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
692 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
697 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
699 return compose_generic_new(account, mailto, NULL);
702 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
704 return compose_generic_new(account, NULL, item);
707 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
711 if (item && item->prefs && item->prefs->enable_default_account)
712 account = account_find_from_id(item->prefs->default_account);
714 if (!account) account = cur_account;
715 g_return_val_if_fail(account != NULL, NULL);
717 compose = compose_create(account, COMPOSE_NEW);
718 compose->replyinfo = NULL;
720 if (prefs_common.auto_sig)
721 compose_insert_sig(compose);
722 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
723 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
725 if (account->protocol != A_NNTP) {
727 compose_entries_set(compose, mailto);
729 } else if(item && item->prefs->enable_default_to) {
730 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
732 if (item && item->ret_rcpt) {
733 GtkItemFactory *ifactory;
735 ifactory = gtk_item_factory_from_widget(compose->menubar);
736 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
740 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
743 compose_show_first_last_header(compose, TRUE);
745 /* Set save folder */
746 if(item && item->prefs && item->prefs->save_copy_to_folder) {
747 gchar *folderidentifier;
749 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
750 folderidentifier = folder_item_get_identifier(item);
751 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
752 g_free(folderidentifier);
755 gtk_widget_grab_focus(compose->header_last->entry);
757 if (prefs_common.auto_exteditor)
758 compose_exec_ext_editor(compose);
763 #define CHANGE_FLAGS(msginfo) \
765 if (msginfo->folder->folder->change_flags != NULL) \
766 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
772 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
773 const gchar *followupto, gchar * to)
777 if (!account) account = cur_account;
778 g_return_val_if_fail(account != NULL, NULL);
779 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
781 compose = compose_create(account, COMPOSE_NEW);
783 if (prefs_common.auto_sig)
784 compose_insert_sig(compose);
785 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
786 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
788 compose_entry_append(compose, to, COMPOSE_TO);
789 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
790 gtk_widget_grab_focus(compose->subject_entry);
796 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
797 gboolean ignore_replyto)
799 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
802 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
804 gboolean ignore_replyto)
806 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
809 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
811 gboolean ignore_replyto,
812 gboolean followup_and_reply_to)
815 PrefsAccount *account;
816 PrefsAccount *reply_account;
819 g_return_if_fail(msginfo != NULL);
820 g_return_if_fail(msginfo->folder != NULL);
823 /* select the account set in folderitem's property (if enabled) */
824 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
825 account = account_find_from_id(msginfo->folder->prefs->default_account);
827 /* select the account for the whole folder (IMAP / NNTP) */
829 /* FIXME: this is not right, because folder may be nested. we should
830 * ascend the tree until we find a parent with proper account
832 account = msginfo->folder->folder->account;
834 /* select account by to: and cc: header if enabled */
835 if (prefs_common.reply_account_autosel) {
836 if (!account && msginfo->to) {
838 Xstrdup_a(to, msginfo->to, return);
840 account = account_find_from_address(to);
844 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
846 account = account_find_from_address(cc);
851 /* select current account */
852 if (!account) account = cur_account;
853 g_return_if_fail(account != NULL);
855 if (ignore_replyto && account->protocol == A_NNTP &&
856 !followup_and_reply_to) {
858 account_find_from_address(account->address);
860 reply_account = compose_current_mail_account();
864 reply_account = account;
866 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
867 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
868 if (MSG_IS_IMAP(msginfo->flags))
869 imap_msg_set_perm_flags(msginfo, MSG_REPLIED);
870 CHANGE_FLAGS(msginfo);
872 compose = compose_create(account, COMPOSE_REPLY);
873 compose->replyinfo = procmsg_msginfo_copy(msginfo);
875 #if 0 /* NEW COMPOSE GUI */
876 if (followup_and_reply_to) {
877 gtk_widget_show(compose->to_hbox);
878 gtk_widget_show(compose->to_entry);
879 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
880 compose->use_to = TRUE;
883 if (msginfo->folder && msginfo->folder->ret_rcpt) {
884 GtkItemFactory *ifactory;
886 ifactory = gtk_item_factory_from_widget(compose->menubar);
887 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
890 /* Set save folder */
891 if(msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
892 gchar *folderidentifier;
894 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
895 folderidentifier = folder_item_get_identifier(msginfo->folder);
896 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
897 g_free(folderidentifier);
900 if (compose_parse_header(compose, msginfo) < 0) return;
901 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
902 followup_and_reply_to);
903 compose_show_first_last_header(compose, TRUE);
905 text = GTK_STEXT(compose->text);
906 gtk_stext_freeze(text);
912 if (prefs_common.quotemark && *prefs_common.quotemark)
913 qmark = prefs_common.quotemark;
917 quote_str = compose_quote_fmt(compose, msginfo,
918 prefs_common.quotefmt,
922 if (prefs_common.auto_sig)
923 compose_insert_sig(compose);
925 if (quote && prefs_common.linewrap_quote)
926 compose_wrap_line_all(compose);
928 gtk_editable_set_position(GTK_EDITABLE(text), 0);
929 gtk_stext_set_point(text, 0);
931 gtk_stext_thaw(text);
932 gtk_widget_grab_focus(compose->text);
934 if (prefs_common.auto_exteditor)
935 compose_exec_ext_editor(compose);
939 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
944 g_return_val_if_fail(mimeinfo != NULL, NULL);
946 base = mimeinfo->filename ? mimeinfo->filename
947 : mimeinfo->name ? mimeinfo->name : NULL;
949 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
950 filename = g_strdup_printf("%s%smimetmp.%08x.html",
957 base = base ? base : "";
958 base = g_basename(base);
960 filename = g_strdup_printf("%s%smimetmp.%08x",
968 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
974 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
978 if (!partinfo) return NULL;
980 filename = procmime_get_file_name(partinfo);
982 if (procmime_get_part(filename, source, partinfo) < 0)
984 (_("Can't get the part of multipart message."));
989 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
997 gint boundary_len = 0;
999 glong fpos, prev_fpos;
1004 g_return_if_fail(msginfo != NULL);
1008 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
1009 mimeinfo = procmime_scan_mime_header(fp, MIME_TEXT);
1010 if (!mimeinfo) break;
1012 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
1013 rfc2015_is_encrypted(mimeinfo)) {
1014 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
1016 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
1017 !msginfo->plaintext_file &&
1018 !msginfo->decryption_failed) {
1019 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
1020 if (msginfo->plaintext_file &&
1021 !msginfo->decryption_failed) {
1029 #else /* !USE_GPGME */
1030 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
1031 mimeinfo = procmime_scan_mime_header(fp, MIME_TEXT);
1032 #endif /* USE_GPGME */
1035 if (!mimeinfo) return;
1036 if (mimeinfo->mime_type == MIME_TEXT)
1039 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
1041 g_return_if_fail(mimeinfo != NULL);
1042 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
1044 if (mimeinfo->mime_type == MIME_MULTIPART) {
1045 g_return_if_fail(mimeinfo->boundary != NULL);
1046 g_return_if_fail(mimeinfo->sub == NULL);
1048 g_return_if_fail(fp != NULL);
1050 boundary = mimeinfo->boundary;
1053 boundary_len = strlen(boundary);
1055 /* look for first boundary */
1056 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
1057 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
1064 if ((fpos = ftell(fp)) < 0) {
1070 for (npart = 0;; npart++) {
1072 gboolean eom = FALSE;
1076 partinfo = procmime_scan_mime_header(fp, MIME_TEXT);
1077 if (!partinfo) break;
1080 procmime_mimeinfo_insert(mimeinfo, partinfo);
1082 procmime_mimeinfo_free(partinfo);
1084 /* look for next boundary */
1086 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
1087 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
1088 if (buf[2 + boundary_len] == '-' &&
1089 buf[2 + boundary_len + 1] == '-')
1095 eom = TRUE; /* broken MIME message */
1098 partinfo->size = fpos - prev_fpos - strlen(buf);
1103 source = procmsg_get_message_file_path(msginfo);
1105 g_return_if_fail(mimeinfo != NULL);
1107 if (!mimeinfo->main && mimeinfo->parent)
1109 filename = mime_extract_file(source, mimeinfo);
1111 compose_attach_append_with_type(compose, filename,
1112 mimeinfo->content_type,
1113 mimeinfo->mime_type);
1118 if (mimeinfo->sub && mimeinfo->sub->children)
1120 filename = mime_extract_file(source, mimeinfo->sub);
1122 compose_attach_append_with_type(compose, filename,
1123 mimeinfo->content_type,
1124 mimeinfo->sub->mime_type);
1129 if (mimeinfo->children) {
1132 child = mimeinfo->children;
1134 filename = mime_extract_file(source, child);
1136 compose_attach_append_with_type(compose, filename,
1137 child->content_type,
1142 child = child->next;
1148 procmime_mimeinfo_free_all(mimeinfo);
1152 #define INSERT_FW_HEADER(var, hdr) \
1153 if (msginfo->var && *msginfo->var) { \
1154 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1155 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1156 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1159 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1163 /* PrefsAccount *account; */
1166 g_return_val_if_fail(msginfo != NULL, NULL);
1167 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1169 account = msginfo->folder->folder->account;
1170 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1172 Xstrdup_a(to, msginfo->to, return NULL);
1173 extract_address(to);
1174 account = account_find_from_address(to);
1177 if(!account && prefs_common.forward_account_autosel) {
1179 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1180 extract_address(cc);
1181 account = account_find_from_address(cc);
1185 if (account == NULL) {
1186 account = cur_account;
1188 account = msginfo->folder->folder->account;
1189 if (!account) account = cur_account;
1192 g_return_val_if_fail(account != NULL, NULL);
1194 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1195 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1196 if (MSG_IS_IMAP(msginfo->flags))
1197 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1198 CHANGE_FLAGS(msginfo);
1200 compose = compose_create(account, COMPOSE_FORWARD);
1202 if (msginfo->subject && *msginfo->subject) {
1203 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1204 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1208 text = GTK_STEXT(compose->text);
1209 gtk_stext_freeze(text);
1214 msgfile = procmsg_get_message_file_path(msginfo);
1215 if (!is_file_exist(msgfile))
1216 g_warning(_("%s: file not exist\n"), msgfile);
1218 compose_attach_append(compose, msgfile,
1219 MIME_MESSAGE_RFC822);
1226 if (prefs_common.fw_quotemark && *prefs_common.fw_quotemark)
1227 qmark = prefs_common.fw_quotemark;
1231 quote_str = compose_quote_fmt(compose, msginfo,
1232 prefs_common.fw_quotefmt, qmark);
1233 compose_attach_parts(compose, msginfo);
1236 if (prefs_common.auto_sig)
1237 compose_insert_sig(compose);
1239 if (prefs_common.linewrap_quote)
1240 compose_wrap_line_all(compose);
1242 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1243 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1245 gtk_stext_thaw(text);
1246 #if 0 /* NEW COMPOSE GUI */
1247 if (account->protocol != A_NNTP)
1248 gtk_widget_grab_focus(compose->to_entry);
1250 gtk_widget_grab_focus(compose->newsgroups_entry);
1252 gtk_widget_grab_focus(compose->header_last->entry);
1254 if (prefs_common.auto_exteditor)
1255 compose_exec_ext_editor(compose);
1260 #undef INSERT_FW_HEADER
1262 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1269 g_return_val_if_fail(msginfo_list != NULL, NULL);
1271 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1272 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1276 if (account == NULL) {
1277 account = cur_account;
1279 account = msginfo->folder->folder->account;
1280 if (!account) account = cur_account;
1283 g_return_val_if_fail(account != NULL, NULL);
1285 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1286 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1287 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1288 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1291 compose = compose_create(account, COMPOSE_FORWARD);
1293 text = GTK_STEXT(compose->text);
1294 gtk_stext_freeze(text);
1296 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1297 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1298 if (!is_file_exist(msgfile))
1299 g_warning(_("%s: file not exist\n"), msgfile);
1301 compose_attach_append(compose, msgfile,
1302 MIME_MESSAGE_RFC822);
1306 if (prefs_common.auto_sig)
1307 compose_insert_sig(compose);
1309 if (prefs_common.linewrap_quote)
1310 compose_wrap_line_all(compose);
1312 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1313 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1315 gtk_stext_thaw(text);
1316 #if 0 /* NEW COMPOSE GUI */
1317 if (account->protocol != A_NNTP)
1318 gtk_widget_grab_focus(compose->to_entry);
1320 gtk_widget_grab_focus(compose->newsgroups_entry);
1326 void compose_reedit(MsgInfo *msginfo)
1329 PrefsAccount *account = NULL;
1332 gchar buf[BUFFSIZE];
1334 g_return_if_fail(msginfo != NULL);
1335 g_return_if_fail(msginfo->folder != NULL);
1337 if (msginfo->folder->stype == F_QUEUE) {
1338 gchar queueheader_buf[BUFFSIZE];
1341 /* Select Account from queue headers */
1342 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1343 sizeof(queueheader_buf), "NAID:")) {
1344 id = atoi(&queueheader_buf[5]);
1345 account = account_find_from_id(id);
1347 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1348 sizeof(queueheader_buf), "MAID:")) {
1349 id = atoi(&queueheader_buf[5]);
1350 account = account_find_from_id(id);
1352 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1353 sizeof(queueheader_buf), "S:")) {
1354 account = account_find_from_address(queueheader_buf);
1357 account = msginfo->folder->folder->account;
1359 if (!account && prefs_common.reedit_account_autosel) {
1360 gchar from[BUFFSIZE];
1361 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1362 extract_address(from);
1363 account = account_find_from_address(from);
1366 if (!account) account = cur_account;
1367 g_return_if_fail(account != NULL);
1369 compose = compose_create(account, COMPOSE_REEDIT);
1370 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1372 if (msginfo->folder->stype == F_QUEUE) {
1373 gchar queueheader_buf[BUFFSIZE];
1375 /* Set message save folder */
1376 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1379 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1380 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1381 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1385 if (compose_parse_header(compose, msginfo) < 0) return;
1386 compose_reedit_set_entry(compose, msginfo);
1388 text = GTK_STEXT(compose->text);
1389 gtk_stext_freeze(text);
1391 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1392 g_warning(_("Can't get text part\n"));
1394 while (fgets(buf, sizeof(buf), fp) != NULL)
1395 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1398 compose_attach_parts(compose, msginfo);
1400 gtk_stext_thaw(text);
1401 gtk_widget_grab_focus(compose->text);
1403 if (prefs_common.auto_exteditor)
1404 compose_exec_ext_editor(compose);
1407 GList *compose_get_compose_list(void)
1409 return compose_list;
1412 void compose_entry_append(Compose *compose, const gchar *address,
1413 ComposeEntryType type)
1419 if (!address || *address == '\0') return;
1421 #if 0 /* NEW COMPOSE GUI */
1424 entry = GTK_ENTRY(compose->cc_entry);
1427 entry = GTK_ENTRY(compose->bcc_entry);
1429 case COMPOSE_NEWSGROUPS:
1430 entry = GTK_ENTRY(compose->newsgroups_entry);
1434 entry = GTK_ENTRY(compose->to_entry);
1438 text = gtk_entry_get_text(entry);
1440 gtk_entry_append_text(entry, ", ");
1441 gtk_entry_append_text(entry, address);
1449 header = N_("Bcc:");
1451 case COMPOSE_REPLYTO:
1452 header = N_("Reply-To:");
1454 case COMPOSE_NEWSGROUPS:
1455 header = N_("Newsgroups:");
1457 case COMPOSE_FOLLOWUPTO:
1458 header = N_( "Followup-To:");
1465 header = prefs_common.trans_hdr ? gettext(header) : header;
1467 compose_add_header_entry(compose, header, (gchar *)address);
1470 static void compose_entries_set(Compose *compose, const gchar *mailto)
1472 gchar *subject = NULL;
1480 Xstrdup_a(tmp_mailto, mailto, return);
1484 p = strchr(tmp_mailto, '?');
1491 gchar *field, *value;
1508 if (*value == '\0') continue;
1510 if (!g_strcasecmp(field, "subject")) {
1511 Xalloca(subject, strlen(value) + 1, return);
1512 decode_uri(subject, value);
1513 } else if (!g_strcasecmp(field, "cc")) {
1515 } else if (!g_strcasecmp(field, "bcc")) {
1517 } else if (!g_strcasecmp(field, "body")) {
1518 Xalloca(body, strlen(value) + 1, return);
1519 decode_uri(body, value);
1524 compose_entry_append(compose, to, COMPOSE_TO);
1526 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1528 compose_entry_append(compose, cc, COMPOSE_CC);
1530 compose_entry_append(compose, bcc, COMPOSE_BCC);
1532 gtk_stext_insert(GTK_STEXT(compose->text),
1533 NULL, NULL, NULL, body, -1);
1534 gtk_stext_insert(GTK_STEXT(compose->text),
1535 NULL, NULL, NULL, "\n", 1);
1539 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1541 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1542 {"Cc:", NULL, FALSE},
1543 {"References:", NULL, FALSE},
1544 {"Bcc:", NULL, FALSE},
1545 {"Newsgroups:", NULL, FALSE},
1546 {"Followup-To:", NULL, FALSE},
1547 {"X-Mailing-List:", NULL, FALSE},
1548 {"X-BeenThere:", NULL, FALSE},
1549 {NULL, NULL, FALSE}};
1559 H_X_MAILING_LIST = 6,
1565 g_return_val_if_fail(msginfo != NULL, -1);
1567 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1568 procheader_get_header_fields(fp, hentry);
1571 if (hentry[H_REPLY_TO].body != NULL) {
1572 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1573 compose->replyto = hentry[H_REPLY_TO].body;
1574 hentry[H_REPLY_TO].body = NULL;
1576 if (hentry[H_CC].body != NULL) {
1577 conv_unmime_header_overwrite(hentry[H_CC].body);
1578 compose->cc = hentry[H_CC].body;
1579 hentry[H_CC].body = NULL;
1581 if (hentry[H_X_MAILING_LIST].body != NULL) {
1582 /* this is good enough to parse debian-devel */
1583 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1584 g_return_val_if_fail(buf != NULL, -1 );
1585 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1586 compose->mailinglist = g_strdup(buf);
1588 g_free(hentry[H_X_MAILING_LIST].body);
1589 hentry[H_X_MAILING_LIST].body = NULL ;
1591 if (hentry[H_X_BEENTHERE].body != NULL) {
1592 /* this is good enough to parse the sylpheed-claws lists */
1593 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1594 g_return_val_if_fail(buf != NULL, -1 );
1595 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1596 compose->mailinglist = g_strdup(buf);
1598 g_free(hentry[H_X_BEENTHERE].body);
1599 hentry[H_X_BEENTHERE].body = NULL ;
1601 if (hentry[H_REFERENCES].body != NULL) {
1602 if (compose->mode == COMPOSE_REEDIT)
1603 compose->references = hentry[H_REFERENCES].body;
1605 compose->references = compose_parse_references
1606 (hentry[H_REFERENCES].body, msginfo->msgid);
1607 g_free(hentry[H_REFERENCES].body);
1609 hentry[H_REFERENCES].body = NULL;
1611 if (hentry[H_BCC].body != NULL) {
1612 if (compose->mode == COMPOSE_REEDIT) {
1613 conv_unmime_header_overwrite(hentry[H_BCC].body);
1614 compose->bcc = hentry[H_BCC].body;
1616 g_free(hentry[H_BCC].body);
1617 hentry[H_BCC].body = NULL;
1619 if (hentry[H_NEWSGROUPS].body != NULL) {
1620 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1621 hentry[H_NEWSGROUPS].body = NULL;
1623 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1624 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1625 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1626 hentry[H_FOLLOWUP_TO].body = NULL;
1629 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1630 compose->inreplyto = g_strdup(msginfo->inreplyto);
1631 else if (compose->mode != COMPOSE_REEDIT &&
1632 msginfo->msgid && *msginfo->msgid) {
1633 compose->inreplyto = g_strdup(msginfo->msgid);
1635 if (!compose->references) {
1636 if (msginfo->inreplyto && *msginfo->inreplyto)
1637 compose->references =
1638 g_strdup_printf("<%s>\n\t<%s>",
1642 compose->references =
1643 g_strconcat("<", msginfo->msgid, ">",
1651 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1653 GSList *ref_id_list, *cur;
1657 ref_id_list = references_list_append(NULL, ref);
1658 if (!ref_id_list) return NULL;
1659 if (msgid && *msgid)
1660 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1665 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1666 /* "<" + Message-ID + ">" + CR+LF+TAB */
1667 len += strlen((gchar *)cur->data) + 5;
1669 if (len > MAX_REFERENCES_LEN) {
1670 /* remove second message-ID */
1671 if (ref_id_list && ref_id_list->next &&
1672 ref_id_list->next->next) {
1673 g_free(ref_id_list->next->data);
1674 ref_id_list = g_slist_remove
1675 (ref_id_list, ref_id_list->next->data);
1677 slist_free_strings(ref_id_list);
1678 g_slist_free(ref_id_list);
1685 new_ref = g_string_new("");
1686 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1687 if (new_ref->len > 0)
1688 g_string_append(new_ref, "\n\t");
1689 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1692 slist_free_strings(ref_id_list);
1693 g_slist_free(ref_id_list);
1695 new_ref_str = new_ref->str;
1696 g_string_free(new_ref, FALSE);
1701 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1702 const gchar *fmt, const gchar *qmark)
1704 GtkSText *text = GTK_STEXT(compose->text);
1705 gchar *quote_str = NULL;
1710 if (qmark != NULL) {
1711 quote_fmt_init(msginfo, NULL);
1712 quote_fmt_scan_string(qmark);
1715 buf = quote_fmt_get_buffer();
1717 alertpanel_error(_("Quote mark format error."));
1719 Xstrdup_a(quote_str, buf, return NULL)
1722 if (fmt && *fmt != '\0') {
1723 quote_fmt_init(msginfo, quote_str);
1724 quote_fmt_scan_string(fmt);
1727 buf = quote_fmt_get_buffer();
1729 alertpanel_error(_("Message reply/forward format error."));
1735 gtk_stext_freeze(text);
1737 for (p = buf; *p != '\0'; ) {
1738 lastp = strchr(p, '\n');
1739 len = lastp ? lastp - p + 1 : -1;
1740 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1747 gtk_stext_thaw(text);
1752 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1753 gboolean to_all, gboolean ignore_replyto,
1754 gboolean followup_and_reply_to)
1759 GHashTable *to_table;
1761 g_return_if_fail(compose->account != NULL);
1762 g_return_if_fail(msginfo != NULL);
1764 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1765 compose_entry_append(compose,
1766 ((compose->replyto && !ignore_replyto)
1768 : (compose->mailinglist && !ignore_replyto)
1769 ? compose->mailinglist
1770 : msginfo->from ? msginfo->from : ""),
1773 if (compose->replyto && to_all)
1774 compose_entry_append
1775 (compose, compose->replyto, COMPOSE_CC);
1778 if (compose->account->protocol == A_NNTP) {
1780 compose_entry_append
1781 (compose, msginfo->from ? msginfo->from : "",
1784 compose_entry_append
1786 compose->followup_to ? compose->followup_to
1787 : compose->newsgroups ? compose->newsgroups
1789 COMPOSE_NEWSGROUPS);
1792 if (msginfo->subject && *msginfo->subject) {
1793 gchar *buf, *buf2, *p;
1795 buf = g_strdup(msginfo->subject);
1796 while (!strncasecmp(buf, "Re:", 3)) {
1798 while (isspace(*p)) p++;
1799 memmove(buf, p, strlen(p) + 1);
1802 buf2 = g_strdup_printf("Re: %s", buf);
1803 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1807 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1809 if (!to_all || compose->account->protocol == A_NNTP) return;
1811 from = g_strdup(compose->replyto ? compose->replyto :
1812 msginfo->from ? msginfo->from : "");
1813 extract_address(from);
1815 cc_list = address_list_append(NULL, msginfo->to);
1816 cc_list = address_list_append(cc_list, compose->cc);
1818 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1819 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1820 if (compose->account)
1821 g_hash_table_insert(to_table, compose->account->address,
1822 GINT_TO_POINTER(1));
1824 /* remove address on To: and that of current account */
1825 for (cur = cc_list; cur != NULL; ) {
1826 GSList *next = cur->next;
1828 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1829 cc_list = g_slist_remove(cc_list, cur->data);
1831 g_hash_table_insert(to_table, cur->data, cur);
1835 g_hash_table_destroy(to_table);
1839 for (cur = cc_list; cur != NULL; cur = cur->next)
1840 compose_entry_append(compose, (gchar *)cur->data,
1842 slist_free_strings(cc_list);
1843 g_slist_free(cc_list);
1847 #define SET_ENTRY(entry, str) \
1850 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1853 #define SET_ADDRESS(type, str) \
1856 compose_entry_append(compose, str, type); \
1859 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1861 g_return_if_fail(msginfo != NULL);
1863 SET_ENTRY(subject_entry, msginfo->subject);
1864 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1865 SET_ADDRESS(COMPOSE_CC, compose->cc);
1866 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1867 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1869 compose_show_first_last_header(compose, TRUE);
1871 #if 0 /* NEW COMPOSE GUI */
1873 GtkItemFactory *ifactory;
1874 GtkWidget *menuitem;
1876 ifactory = gtk_item_factory_from_widget(compose->menubar);
1877 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1878 gtk_check_menu_item_set_active
1879 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1881 if (compose->replyto) {
1882 GtkItemFactory *ifactory;
1883 GtkWidget *menuitem;
1885 ifactory = gtk_item_factory_from_widget(compose->menubar);
1886 menuitem = gtk_item_factory_get_item
1887 (ifactory, "/View/Reply to");
1888 gtk_check_menu_item_set_active
1889 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1897 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1904 size_t buf_len = 128;
1906 if (strlen(sigfile) < 2)
1909 sigprg = popen(sigfile+1, "r");
1912 buf = g_malloc(buf_len);
1915 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1916 "Unable to insert signature (malloc failed)\n", -1);
1922 while (!feof(sigprg)) {
1923 bzero(buf, buf_len);
1924 fread(buf, buf_len-1, 1, sigprg);
1925 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1933 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1934 "Can't exec file: ", -1);
1935 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1940 static void compose_insert_sig(Compose *compose)
1944 if (compose->account && compose->account->sig_path)
1945 sigfile = g_strdup(compose->account->sig_path);
1947 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1948 DEFAULT_SIGNATURE, NULL);
1950 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1955 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1956 if (prefs_common.sig_sep) {
1957 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1958 prefs_common.sig_sep, -1);
1959 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1963 if (sigfile[0] == '|')
1964 compose_exec_sig(compose, sigfile);
1966 compose_insert_file(compose, sigfile);
1970 static void compose_insert_file(Compose *compose, const gchar *file)
1972 GtkSText *text = GTK_STEXT(compose->text);
1973 gchar buf[BUFFSIZE];
1977 g_return_if_fail(file != NULL);
1979 if ((fp = fopen(file, "r")) == NULL) {
1980 FILE_OP_ERROR(file, "fopen");
1984 gtk_stext_freeze(text);
1986 while (fgets(buf, sizeof(buf), fp) != NULL) {
1987 /* strip <CR> if DOS/Windows file,
1988 replace <CR> with <LF> if Macintosh file. */
1991 if (len > 0 && buf[len - 1] != '\n') {
1993 if (buf[len] == '\r') buf[len] = '\n';
1995 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1998 gtk_stext_thaw(text);
2003 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
2004 ContentType cnttype)
2006 gchar *text[N_ATTACH_COLS];
2009 text[COL_MIMETYPE] = ainfo->content_type;
2010 text[COL_SIZE] = to_human_readable(ainfo->size);
2011 text[COL_NAME] = ainfo->name;
2013 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2014 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2016 if (cnttype != MIME_MESSAGE_RFC822)
2017 compose_changed_cb(NULL, compose);
2020 static void compose_attach_append_with_type(Compose *compose,
2023 ContentType cnttype)
2028 if (!is_file_exist(file)) {
2029 g_warning(_("File %s doesn't exist\n"), file);
2032 if ((size = get_file_size(file)) < 0) {
2033 g_warning(_("Can't get file size of %s\n"), file);
2037 alertpanel_notice(_("File %s is empty\n"), file);
2040 #if 0 /* NEW COMPOSE GUI */
2041 if (!compose->use_attach) {
2042 GtkItemFactory *ifactory;
2043 GtkWidget *menuitem;
2045 ifactory = gtk_item_factory_from_widget(compose->menubar);
2046 menuitem = gtk_item_factory_get_item(ifactory,
2048 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2052 ainfo = g_new0(AttachInfo, 1);
2053 ainfo->file = g_strdup(file);
2055 if (cnttype == MIME_MESSAGE_RFC822) {
2056 ainfo->encoding = ENC_7BIT;
2057 ainfo->name = g_strdup_printf(_("Message: %s"),
2060 ainfo->encoding = ENC_BASE64;
2061 ainfo->name = g_strdup(g_basename(file));
2064 ainfo->content_type = g_strdup(type);
2067 compose_attach_info(compose, ainfo, cnttype);
2070 static void compose_attach_append(Compose *compose, const gchar *file,
2071 ContentType cnttype)
2074 gchar *text[N_ATTACH_COLS];
2078 if (!is_file_exist(file)) {
2079 g_warning(_("File %s doesn't exist\n"), file);
2082 if ((size = get_file_size(file)) < 0) {
2083 g_warning(_("Can't get file size of %s\n"), file);
2087 alertpanel_notice(_("File %s is empty\n"), file);
2090 #if 0 /* NEW COMPOSE GUI */
2091 if (!compose->use_attach) {
2092 GtkItemFactory *ifactory;
2093 GtkWidget *menuitem;
2095 ifactory = gtk_item_factory_from_widget(compose->menubar);
2096 menuitem = gtk_item_factory_get_item(ifactory,
2097 "/View/Attachment");
2098 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2102 ainfo = g_new0(AttachInfo, 1);
2103 ainfo->file = g_strdup(file);
2105 if (cnttype == MIME_MESSAGE_RFC822) {
2106 ainfo->content_type = g_strdup("message/rfc822");
2107 ainfo->encoding = ENC_7BIT;
2108 ainfo->name = g_strdup_printf(_("Message: %s"),
2111 ainfo->content_type = procmime_get_mime_type(file);
2112 if (!ainfo->content_type)
2113 ainfo->content_type =
2114 g_strdup("application/octet-stream");
2115 ainfo->encoding = ENC_BASE64;
2116 ainfo->name = g_strdup(g_basename(file));
2120 compose_attach_info(compose, ainfo, cnttype);
2123 #define GET_CHAR(pos, buf, len) \
2125 if (text->use_wchar) \
2126 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2128 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2133 static void compose_wrap_line(Compose *compose)
2135 GtkSText *text = GTK_STEXT(compose->text);
2136 gint ch_len, last_ch_len;
2137 gchar cbuf[MB_LEN_MAX], last_ch;
2141 gint p_start, p_end;
2142 gint line_pos, cur_pos;
2143 gint line_len, cur_len;
2145 gtk_stext_freeze(text);
2147 text_len = gtk_stext_get_length(text);
2149 /* check to see if the point is on the paragraph mark (empty line). */
2150 cur_pos = gtk_stext_get_point(text);
2151 GET_CHAR(cur_pos, cbuf, ch_len);
2152 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2154 goto compose_end; /* on the paragraph mark */
2155 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2156 if (ch_len == 1 && *cbuf == '\n')
2157 goto compose_end; /* on the paragraph mark */
2160 /* find paragraph start. */
2161 line_end = quoted = 0;
2162 for (p_start = cur_pos; p_start >= 0; --p_start) {
2163 GET_CHAR(p_start, cbuf, ch_len);
2164 if (ch_len == 1 && *cbuf == '\n') {
2166 goto compose_end; /* quoted part */
2173 if (ch_len == 1 && strchr(">:#", *cbuf))
2175 else if (ch_len != 1 || !isspace(*cbuf))
2184 /* find paragraph end. */
2186 for (p_end = cur_pos; p_end < text_len; p_end++) {
2187 GET_CHAR(p_end, cbuf, ch_len);
2188 if (ch_len == 1 && *cbuf == '\n') {
2195 if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
2196 goto compose_end; /* quoted part */
2201 if (p_end >= text_len)
2204 if (p_start >= p_end)
2207 line_len = cur_len = 0;
2211 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2214 GET_CHAR(cur_pos, cbuf, ch_len);
2221 if (ch_len == 1 && isspace(*cbuf))
2224 if (ch_len == 1 && *cbuf == '\n') {
2226 if (last_ch_len == 1 && !isspace(last_ch)) {
2227 if (cur_pos + 1 < p_end) {
2228 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2229 if (ch_len == 1 && !isspace(*cbuf))
2233 gtk_stext_set_point(text, cur_pos + 1);
2234 gtk_stext_backward_delete(text, 1);
2236 gtk_stext_set_point(text, cur_pos);
2237 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2247 last_ch_len = ch_len;
2251 line_pos = cur_pos + 1;
2252 line_len = cur_len + ch_len;
2255 if (cur_len + ch_len > prefs_common.linewrap_len &&
2259 GET_CHAR(line_pos - 1, cbuf, ch_len);
2260 if (ch_len == 1 && isspace(*cbuf)) {
2261 gtk_stext_set_point(text, line_pos);
2262 gtk_stext_backward_delete(text, 1);
2271 gtk_stext_set_point(text, line_pos);
2272 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2276 cur_len = cur_len - line_len + ch_len;
2282 line_pos = cur_pos + 1;
2283 line_len = cur_len + ch_len;
2289 gtk_stext_thaw(text);
2292 /* return indent length */
2293 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2295 gint indent_len = 0;
2297 gchar cbuf[MB_LEN_MAX];
2299 for (i = start_pos; i < text_len; i++) {
2300 GET_CHAR(i, cbuf, ch_len);
2303 /* allow space, tab, > or | */
2304 if (cbuf[0] != ' ' && cbuf[0] != '\t' &&
2305 cbuf[0] != '>' && cbuf[0] != '|')
2313 /* insert quotation string when line was wrapped */
2314 static guint ins_quote(GtkSText *text, guint quote_len, guint indent_len,
2315 guint prev_line_pos, guint text_len,
2322 for (i = 0; i < indent_len; i++) {
2323 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2324 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2326 ins_len = indent_len;
2328 gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
2329 ins_len = quote_len;
2337 /* Darko: used when I debug wrapping */
2338 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2343 printf("%d [", pos);
2344 for (i = pos; i < tlen; i++) {
2345 ch = GTK_STEXT_INDEX(text, i);
2346 if (breakoncr && ch == '\n')
2354 static void compose_wrap_line_all(Compose *compose)
2356 GtkSText *text = GTK_STEXT(compose->text);
2358 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2359 gint line_len = 0, cur_len = 0;
2361 gboolean is_new_line = TRUE, do_delete = FALSE;
2362 guint qlen = 0, i_len = 0;
2363 gboolean linewrap_quote = TRUE;
2364 guint linewrap_len = prefs_common.linewrap_len;
2365 gchar *qfmt = prefs_common.quotemark;
2366 gchar cbuf[MB_LEN_MAX];
2368 gtk_stext_freeze(text);
2370 /* make text buffer contiguous */
2371 /* gtk_stext_compact_buffer(text); */
2373 tlen = gtk_stext_get_length(text);
2375 for (; cur_pos < tlen; cur_pos++) {
2376 /* mark position of new line - needed for quotation wrap */
2378 if (linewrap_quote) {
2379 qlen = gtkut_stext_str_compare
2380 (text, cur_pos, tlen, qfmt);
2382 i_len = get_indent_length
2383 (text, cur_pos, tlen);
2387 is_new_line = FALSE;
2390 printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
2391 dump_text(text, p_pos, tlen, 1);
2395 GET_CHAR(cur_pos, cbuf, ch_len);
2397 /* fix line length for tabs */
2398 if (ch_len == 1 && *cbuf == '\t') {
2399 guint tab_width = text->default_tab_width;
2400 guint tab_offset = line_len % tab_width;
2403 printf("found tab at pos=%d line_len=%d ", cur_pos,
2407 line_len += tab_width - tab_offset - 1;
2411 printf("new_len=%d\n", line_len);
2415 /* we have encountered line break */
2416 if (ch_len == 1 && *cbuf == '\n') {
2419 gchar cb[MB_CUR_MAX];
2422 printf("found CR at %d next line is ", cur_pos);
2423 dump_text(text, cur_pos + 1, tlen, 1);
2425 /* if it's just quotation + newline skip it */
2426 if (i_len && (cur_pos + 1 < tlen)) {
2427 /* check if text at new line matches indent */
2428 ilen = gtkut_stext_str_compare_n
2429 (text, cur_pos + 1, p_pos, i_len, tlen);
2430 if (cur_pos + ilen < tlen) {
2431 GET_CHAR(cur_pos + ilen + 1, cb, clen);
2432 /* no need to join the lines */
2433 if (clen == 1 && cb[0] == '\n')
2436 /* if it's just newline skip it */
2437 } else if (do_delete && (cur_pos + 1 < tlen)) {
2438 GET_CHAR(cur_pos + 1, cb, clen);
2439 /* no need to join the lines */
2440 if (clen == 1 && cb[0] == '\n')
2444 /* skip delete if it is continuous URL */
2445 if (do_delete && (line_pos - p_pos <= i_len) &&
2446 gtkut_stext_is_uri_string(text, line_pos, tlen))
2450 printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
2451 qlen, line_len, linewrap_len, do_delete);
2453 /* should we delete to perform smart wrapping */
2454 if (line_len < linewrap_len && do_delete) {
2455 /* get rid of newline */
2456 gtk_stext_set_point(text, cur_pos);
2457 gtk_stext_forward_delete(text, 1);
2460 /* if text starts with quote fmt or with
2461 indent string, delete them */
2463 ilen = gtkut_stext_str_compare_n
2464 (text, cur_pos, p_pos, i_len,
2467 gtk_stext_forward_delete
2472 if (gtkut_stext_str_compare
2473 (text, cur_pos, tlen, qfmt)) {
2474 gtk_stext_forward_delete
2480 GET_CHAR(cur_pos, cb, clen);
2482 /* insert space if it's alphanumeric */
2483 if ((cur_pos != line_pos) &&
2484 ((clen > 1) || isalnum(cb[0]))) {
2485 gtk_stext_insert(text, NULL, NULL,
2487 /* gtk_stext_compact_buffer(text); */
2491 /* and start over with current line */
2492 cur_pos = p_pos - 1;
2494 line_len = cur_len = 0;
2499 printf("after delete l_pos=");
2500 dump_text(text, line_pos, tlen, 1);
2505 /* mark new line beginning */
2506 line_pos = cur_pos + 1;
2507 line_len = cur_len = 0;
2519 /* possible line break */
2520 if (ch_len == 1 && isspace(*cbuf)) {
2521 line_pos = cur_pos + 1;
2522 line_len = cur_len + ch_len;
2525 /* are we over wrapping length set in preferences ? */
2526 if (cur_len + ch_len > linewrap_len) {
2530 printf("should wrap cur_pos=%d ", cur_pos);
2531 dump_text(text, p_pos, tlen, 1);
2532 dump_text(text, line_pos, tlen, 1);
2534 /* force wrapping if it is one long word but not URL */
2535 if (line_pos - p_pos <= i_len)
2536 if (!gtkut_stext_is_uri_string
2537 (text, line_pos, tlen))
2538 line_pos = cur_pos - 1;
2540 printf("new line_pos=%d\n", line_pos);
2543 GET_CHAR(line_pos - 1, cbuf, clen);
2545 /* if next character is space delete it */
2546 if (clen == 1 && isspace(*cbuf)) {
2547 if (p_pos + i_len != line_pos ||
2548 !gtkut_stext_is_uri_string
2549 (text, line_pos, tlen)) {
2550 gtk_stext_set_point(text, line_pos);
2551 gtk_stext_backward_delete(text, 1);
2560 /* if it is URL at beginning of line don't wrap */
2561 if (p_pos + i_len == line_pos &&
2562 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2564 printf("found URL at ");
2565 dump_text(text, line_pos, tlen, 1);
2571 gtk_stext_set_point(text, line_pos);
2572 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2573 /* gtk_stext_compact_buffer(text); */
2576 /* for loop will increase it */
2577 cur_pos = line_pos - 1;
2578 /* start over with current line */
2584 printf("after CR insert ");
2585 dump_text(text, line_pos, tlen, 1);
2586 dump_text(text, cur_pos, tlen, 1);
2589 /* should we insert quotation ? */
2590 if (linewrap_quote && qlen) {
2591 /* only if line is not already quoted */
2592 if (!gtkut_stext_str_compare
2593 (text, line_pos, tlen, qfmt)) {
2596 if (line_pos - p_pos > i_len) {
2601 /* gtk_stext_compact_buffer(text); */
2605 printf("after quote insert ");
2606 dump_text(text, line_pos, tlen, 1);
2614 line_pos = cur_pos + 1;
2615 line_len = cur_len + ch_len;
2617 /* advance to next character in buffer */
2621 gtk_stext_thaw(text);
2626 static void compose_set_title(Compose *compose)
2631 edited = compose->modified ? _(" [Edited]") : "";
2632 if (compose->account && compose->account->address)
2633 str = g_strdup_printf(_("%s - Compose message%s"),
2634 compose->account->address, edited);
2636 str = g_strdup_printf(_("Compose message%s"), edited);
2637 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2642 * compose_current_mail_account:
2644 * Find a current mail account (the currently selected account, or the
2645 * default account, if a news account is currently selected). If a
2646 * mail account cannot be found, display an error message.
2648 * Return value: Mail account, or NULL if not found.
2650 static PrefsAccount *
2651 compose_current_mail_account(void)
2655 if (cur_account && cur_account->protocol != A_NNTP)
2658 ac = account_get_default();
2659 if (!ac || ac->protocol == A_NNTP) {
2660 alertpanel_error(_("Account for sending mail is not specified.\n"
2661 "Please select a mail account before sending."));
2668 gboolean compose_check_for_valid_recipient(Compose *compose) {
2669 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2670 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2671 gboolean recipient_found = FALSE;
2675 /* free to and newsgroup list */
2676 slist_free_strings(compose->to_list);
2677 g_slist_free(compose->to_list);
2678 compose->to_list = NULL;
2680 slist_free_strings(compose->newsgroup_list);
2681 g_slist_free(compose->newsgroup_list);
2682 compose->newsgroup_list = NULL;
2684 /* search header entries for to and newsgroup entries */
2685 for(list = compose->header_list; list; list = list->next) {
2688 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2689 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2691 if(entry[0] != '\0') {
2692 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2693 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2694 compose->to_list = address_list_append(compose->to_list, entry);
2695 recipient_found = TRUE;
2698 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2699 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2700 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2701 recipient_found = TRUE;
2707 return recipient_found;
2710 gint compose_send(Compose *compose)
2716 val = compose_queue(compose, &msgnum, &folder);
2718 alertpanel_error(_("Could not queue message for sending"));
2722 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2724 folder_item_remove_msg(folder, msgnum);
2725 folderview_update_item(folder, TRUE);
2731 #if 0 /* compose restructure */
2732 gint compose_send(Compose *compose)
2734 gchar tmp[MAXPATHLEN + 1];
2736 static gboolean lock = FALSE;
2740 g_return_val_if_fail(compose->account != NULL, -1);
2741 g_return_val_if_fail(compose->orig_account != NULL, -1);
2745 if(!compose_check_for_valid_recipient(compose)) {
2746 alertpanel_error(_("Recipient is not specified."));
2751 /* write to temporary file */
2752 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2753 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2755 if (prefs_common.linewrap_at_send)
2756 compose_wrap_line_all(compose);
2758 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2763 if (!compose->to_list && !compose->newsgroup_list) {
2764 g_warning(_("can't get recipient list."));
2770 if (compose->to_list) {
2773 #if 0 /* NEW COMPOSE GUI */
2774 if (compose->account->protocol != A_NNTP)
2775 ac = compose->account;
2776 else if (compose->orig_account->protocol != A_NNTP)
2777 ac = compose->orig_account;
2778 else if (cur_account && cur_account->protocol != A_NNTP)
2781 ac = compose_current_mail_account();
2789 ac = compose->account;
2791 ok = send_message(tmp, ac, compose->to_list);
2792 statusbar_pop_all();
2795 if (ok == 0 && compose->newsgroup_list) {
2798 if (compose->account->protocol == A_NNTP)
2799 folder = FOLDER(compose->account->folder);
2801 folder = FOLDER(compose->orig_account->folder);
2803 ok = news_post(folder, tmp);
2805 alertpanel_error(_("Error occurred while posting the message to %s ."),
2806 compose->account->nntp_server);
2813 /* queue message if failed to send */
2815 if (prefs_common.queue_msg) {
2820 _("Error occurred while sending the message.\n"
2821 "Put this message into queue folder?"),
2822 _("OK"), _("Cancel"), NULL);
2823 if (G_ALERTDEFAULT == val) {
2824 ok = compose_queue(compose, tmp);
2826 alertpanel_error(_("Can't queue the message."));
2829 alertpanel_error(_("Error occurred while sending the message."));
2831 if (compose->mode == COMPOSE_REEDIT) {
2832 compose_remove_reedit_target(compose);
2833 if (compose->targetinfo)
2834 folderview_update_item
2835 (compose->targetinfo->folder, TRUE);
2839 /* save message to outbox */
2840 if (ok == 0 && prefs_common.savemsg) {
2841 if (compose_save_to_outbox(compose, tmp) < 0)
2843 (_("Can't save the message to outbox."));
2852 static gboolean compose_use_attach(Compose *compose) {
2853 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2856 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2859 gchar buf[BUFFSIZE];
2861 gboolean first_address;
2863 ComposeHeaderEntry *headerentry;
2864 gchar *headerentryname;
2865 gchar *header_w_colon;
2869 debug_print(_("Writing bounce header\n"));
2871 header_w_colon = g_strconcat("To:", NULL);
2872 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2873 header_w_colon = g_strconcat("Cc:", NULL);
2874 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2876 first_address = TRUE;
2877 for(list = compose->header_list; list; list = list->next) {
2878 headerentry = ((ComposeHeaderEntry *)list->data);
2879 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2881 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2882 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2883 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2884 Xstrdup_a(str, str, return -1);
2886 if(str[0] != '\0') {
2887 compose_convert_header
2888 (buf, sizeof(buf), str,
2889 strlen("Resent-To") + 2);
2891 fprintf(fp, "Resent-To: ");
2892 first_address = FALSE;
2896 fprintf(fp, "%s", buf);
2900 /* if(!first_address) { */
2907 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2909 gchar buf[BUFFSIZE];
2911 /* struct utsname utsbuf; */
2913 g_return_val_if_fail(fp != NULL, -1);
2914 g_return_val_if_fail(compose->account != NULL, -1);
2915 g_return_val_if_fail(compose->account->address != NULL, -1);
2918 get_rfc822_date(buf, sizeof(buf));
2919 fprintf(fp, "Resent-Date: %s\n", buf);
2922 if (compose->account->name && *compose->account->name) {
2923 compose_convert_header
2924 (buf, sizeof(buf), compose->account->name,
2926 fprintf(fp, "Resent-From: %s <%s>\n",
2927 buf, compose->account->address);
2929 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2932 compose_bounce_write_headers_from_headerlist(compose, fp);
2934 /* separator between header and body */
2940 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2945 gchar buf[BUFFSIZE];
2947 if ((fp = fopen(compose->bounce_filename, "r")) == NULL) {
2948 FILE_OP_ERROR(file, "fopen");
2952 if ((fdest = fopen(file, "w")) == NULL) {
2953 FILE_OP_ERROR(file, "fopen");
2958 /* chmod for security */
2959 if (change_file_mode_rw(fdest, file) < 0) {
2960 FILE_OP_ERROR(file, "chmod");
2961 g_warning(_("can't change file mode\n"));
2964 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2965 /* should filter returnpath, delivered-to */
2966 if ((g_strncasecmp(buf, "Return-Path:",
2967 strlen("Return-Path:")) == 0)
2968 || (g_strncasecmp(buf, "Delivered-To:",
2969 strlen("Delivered-To:")) == 0))
2972 if (fputs(buf, fdest) == -1)
2975 if (g_strncasecmp(buf, "From:", strlen("From:")) == 0) {
2976 fputs(" (by way of ", fdest);
2977 if (compose->account->name
2978 && *compose->account->name) {
2979 compose_convert_header
2981 compose->account->name,
2983 fprintf(fdest, "%s <%s>",
2984 buf, compose->account->address);
2986 fprintf(fdest, "%s",
2987 compose->account->address);
2991 if (fputs("\n", fdest) == -1)
2995 compose_bounce_write_headers(compose, fdest);
2997 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
2998 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
3016 * interfaces to rfc2015 to keep out the prefs stuff there.
3017 * returns 0 on success and -1 on error. */
3018 static int compose_create_signers_list (Compose *compose, GSList **pkey_list)
3020 const char *keyid = NULL;
3023 switch (compose->account->sign_key) {
3024 case SIGN_KEY_DEFAULT:
3026 return 0; /* nothing to do */
3028 case SIGN_KEY_BY_FROM:
3029 keyid = compose->account->address;
3032 case SIGN_KEY_CUSTOM:
3033 keyid = compose->account->sign_key_id;
3037 g_assert_not_reached ();
3040 key_list = rfc2015_create_signers_list(keyid);
3043 alertpanel_error("Could not find any key associated with currently "
3044 "selected keyid `%s'!", keyid);
3048 *pkey_list = key_list;
3051 #endif /* USE_GPGME */
3053 static gint compose_write_to_file(Compose *compose, const gchar *file,
3060 const gchar *out_codeset;
3061 EncodingType encoding;
3063 if ((fp = fopen(file, "w")) == NULL) {
3064 FILE_OP_ERROR(file, "fopen");
3068 /* chmod for security */
3069 if (change_file_mode_rw(fp, file) < 0) {
3070 FILE_OP_ERROR(file, "chmod");
3071 g_warning(_("can't change file mode\n"));
3074 /* get all composed text */
3075 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3076 len = strlen(chars);
3077 if (is_ascii_str(chars)) {
3078 buf = g_strdup(chars);
3079 out_codeset = CS_US_ASCII;
3080 encoding = ENC_7BIT;
3082 const gchar *src_codeset;
3084 out_codeset = conv_get_outgoing_charset_str();
3085 if (!strcasecmp(out_codeset, CS_US_ASCII))
3086 out_codeset = CS_ISO_8859_1;
3087 encoding = procmime_get_encoding_for_charset(out_codeset);
3089 src_codeset = conv_get_current_charset_str();
3090 /* if current encoding is US-ASCII, set it the same as
3091 outgoing one to prevent code conversion failure */
3092 if (!strcasecmp(src_codeset, CS_US_ASCII))
3093 src_codeset = out_codeset;
3095 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3096 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3098 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3103 alertpanel_error(_("Can't convert the codeset of the message."));
3110 if (compose_write_headers
3111 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3112 g_warning(_("can't write headers\n"));
3119 if (compose_use_attach(compose)) {
3121 /* This prolog message is ignored by mime software and
3122 * because it would make our signing/encryption task
3123 * tougher, we don't emit it in that case */
3124 if (!compose->use_signing && !compose->use_encryption)
3126 fputs("This is a multi-part message in MIME format.\n", fp);
3128 fprintf(fp, "\n--%s\n", compose->boundary);
3129 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3131 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3132 procmime_get_encoding_str(encoding));
3138 if (encoding == ENC_BASE64) {
3139 gchar outbuf[B64_BUFFSIZE];
3142 for (i = 0; i < len; i += B64_LINE_SIZE) {
3143 l = MIN(B64_LINE_SIZE, len - i);
3144 to64frombits(outbuf, buf + i, l);
3148 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3149 FILE_OP_ERROR(file, "fwrite");
3157 if (compose_use_attach(compose))
3158 compose_write_attach(compose, fp);
3160 if (fclose(fp) == EOF) {
3161 FILE_OP_ERROR(file, "fclose");
3167 if (compose->use_signing) {
3170 if (compose_create_signers_list(compose, &key_list) == -1 ||
3171 rfc2015_sign(file, key_list) < 0) {
3177 if (compose->use_encryption) {
3178 if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) {
3183 #endif /* USE_GPGME */
3188 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3194 if ((fp = fopen(file, "w")) == NULL) {
3195 FILE_OP_ERROR(file, "fopen");
3199 /* chmod for security */
3200 if (change_file_mode_rw(fp, file) < 0) {
3201 FILE_OP_ERROR(file, "chmod");
3202 g_warning(_("can't change file mode\n"));
3205 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3208 len = strlen(chars);
3209 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3210 FILE_OP_ERROR(file, "fwrite");
3219 if (fclose(fp) == EOF) {
3220 FILE_OP_ERROR(file, "fclose");
3227 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
3234 debug_print(_("saving sent message...\n"));
3236 outbox = folder_get_default_outbox();
3237 path = folder_item_get_path(outbox);
3238 if (!is_dir_exist(path))
3239 make_dir_hier(path);
3241 folder_item_scan(outbox);
3242 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
3244 g_warning(_("can't save message\n"));
3248 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
3249 g_warning(_("can't open mark file\n"));
3253 newmsginfo.msgnum = num;
3254 newmsginfo.flags.perm_flags = 0;
3255 newmsginfo.flags.tmp_flags = 0;
3256 procmsg_write_flags(&newmsginfo, fp);
3264 static gint compose_remove_reedit_target(Compose *compose)
3267 MsgInfo *msginfo = compose->targetinfo;
3269 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3270 if (!msginfo) return -1;
3272 item = msginfo->folder;
3273 g_return_val_if_fail(item != NULL, -1);
3275 folder_item_scan(item);
3276 if (procmsg_msg_exist(msginfo) &&
3277 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3278 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3279 g_warning(_("can't remove the old message\n"));
3288 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3291 gchar *tmp, *tmp2, *queue_path;
3294 gchar buf[BUFFSIZE];
3296 static gboolean lock = FALSE;
3297 PrefsAccount *mailac = NULL, *newsac = NULL;
3299 debug_print(_("queueing message...\n"));
3300 g_return_val_if_fail(compose->account != NULL, -1);
3301 g_return_val_if_fail(compose->orig_account != NULL, -1);
3305 if(!compose_check_for_valid_recipient(compose)) {
3306 alertpanel_error(_("Recipient is not specified."));
3311 if (!compose->to_list && !compose->newsgroup_list) {
3312 g_warning(_("can't get recipient list."));
3317 if(compose->to_list) {
3318 if (compose->account->protocol != A_NNTP)
3319 mailac = compose->account;
3320 else if (compose->orig_account->protocol != A_NNTP)
3321 mailac = compose->orig_account;
3322 else if (cur_account && cur_account->protocol != A_NNTP)
3323 mailac = cur_account;
3324 else if (!(mailac = compose_current_mail_account())) {
3326 alertpanel_error(_("No account for sending mails available!"));
3331 if(compose->newsgroup_list) {
3332 if (compose->account->protocol == A_NNTP)
3333 newsac = compose->account;
3334 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3336 alertpanel_error(_("No account for posting news available!"));
3341 if (prefs_common.linewrap_at_send)
3342 compose_wrap_line_all(compose);
3344 /* write to temporary file */
3345 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3346 G_DIR_SEPARATOR, (gint)compose);
3348 if (compose->bounce_filename != NULL) {
3349 if (compose_bounce_write_to_file(compose, tmp2) < 0) {
3356 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3363 /* add queue header */
3364 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3365 G_DIR_SEPARATOR, (gint)compose);
3366 if ((fp = fopen(tmp, "w")) == NULL) {
3367 FILE_OP_ERROR(tmp, "fopen");
3371 if ((src_fp = fopen(tmp2, "r")) == NULL) {
3372 FILE_OP_ERROR(tmp2, "fopen");
3380 if (change_file_mode_rw(fp, tmp) < 0) {
3381 FILE_OP_ERROR(tmp, "chmod");
3382 g_warning(_("can't change file mode\n"));
3385 /* queueing variables */
3386 fprintf(fp, "AF:\n");
3387 fprintf(fp, "NF:0\n");
3388 fprintf(fp, "PS:10\n");
3389 fprintf(fp, "SRH:1\n");
3390 fprintf(fp, "SFN:\n");
3391 fprintf(fp, "DSR:\n");
3393 fprintf(fp, "MID:<%s>\n", compose->msgid);
3395 fprintf(fp, "MID:\n");
3396 fprintf(fp, "CFG:\n");
3397 fprintf(fp, "PT:0\n");
3398 fprintf(fp, "S:%s\n", compose->account->address);
3399 fprintf(fp, "RQ:\n");
3401 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3403 fprintf(fp, "SSV:\n");
3405 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3407 fprintf(fp, "NSV:\n");
3408 fprintf(fp, "SSH:\n");
3409 /* write recepient list */
3411 if(compose->to_list) {
3412 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3413 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3414 fprintf(fp, ",<%s>", (gchar *)cur->data);
3417 /* write newsgroup list */
3419 if(compose->newsgroup_list) {
3420 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3421 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3422 fprintf(fp, ",%s", (gchar *)cur->data);
3425 /* Sylpheed account IDs */
3427 fprintf(fp, "MAID:%d\n", mailac->account_id);
3430 fprintf(fp, "NAID:%d\n", newsac->account_id);
3432 /* Save copy folder */
3433 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3436 str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3437 fprintf(fp, "SCF:%s\n", str);
3442 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3443 if (fputs(buf, fp) == EOF) {
3444 FILE_OP_ERROR(tmp, "fputs");
3455 if (fclose(fp) == EOF) {
3456 FILE_OP_ERROR(tmp, "fclose");
3465 queue = folder_get_default_queue();
3467 folder_item_scan(queue);
3468 queue_path = folder_item_get_path(queue);
3469 if (!is_dir_exist(queue_path))
3470 make_dir_hier(queue_path);
3471 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3472 g_warning(_("can't queue the message\n"));
3483 if (compose->mode == COMPOSE_REEDIT) {
3484 compose_remove_reedit_target(compose);
3485 if (compose->targetinfo &&
3486 compose->targetinfo->folder != queue)
3487 folderview_update_item
3488 (compose->targetinfo->folder, TRUE);
3491 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
3492 g_warning(_("can't open mark file\n"));
3496 newmsginfo.msgnum = num;
3497 newmsginfo.flags.perm_flags = 0;
3498 newmsginfo.flags.tmp_flags = 0;
3499 procmsg_write_flags(&newmsginfo, fp);
3504 folder_item_scan(queue);
3505 folderview_update_item(queue, TRUE);
3507 if((msgnum != NULL) && (item != NULL)) {
3515 static void compose_write_attach(Compose *compose, FILE *fp)
3518 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3521 gchar filename[BUFFSIZE];
3524 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3526 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
3527 g_warning(_("Can't open file %s\n"), ainfo->file);
3531 fprintf(fp, "\n--%s\n", compose->boundary);
3533 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3534 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3535 fprintf(fp, "Content-Disposition: inline\n");
3537 conv_encode_header(filename, sizeof(filename),
3539 fprintf(fp, "Content-Type: %s;\n"
3541 ainfo->content_type, filename);
3542 fprintf(fp, "Content-Disposition: attachment;\n"
3543 " filename=\"%s\"\n", filename);
3546 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3547 procmime_get_encoding_str(ainfo->encoding));
3549 if (ainfo->encoding == ENC_7BIT) {
3550 gchar buf[BUFFSIZE];
3552 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3557 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3559 while ((len = fread(inbuf, sizeof(gchar),
3560 B64_LINE_SIZE, attach_fp))
3562 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3566 if (len > 0 && feof(attach_fp)) {
3567 to64frombits(outbuf, inbuf, len);
3576 fprintf(fp, "\n--%s--\n", compose->boundary);
3579 #define IS_IN_CUSTOM_HEADER(header) \
3580 (compose->account->add_customhdr && \
3581 custom_header_find(compose->account->customhdr_list, header) != NULL)
3583 static gint compose_write_headers_from_headerlist(Compose *compose,
3587 gchar buf[BUFFSIZE];
3588 gchar *str, *header_w_colon, *trans_hdr;
3589 gboolean first_address;
3591 ComposeHeaderEntry *headerentry;
3592 gchar * headerentryname;
3594 if (IS_IN_CUSTOM_HEADER(header)) {
3598 debug_print(_("Writing %s-header\n"), header);
3600 header_w_colon = g_strconcat(header, ":", NULL);
3601 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3603 first_address = TRUE;
3604 for(list = compose->header_list; list; list = list->next) {
3605 headerentry = ((ComposeHeaderEntry *)list->data);
3606 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3608 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3609 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3610 Xstrdup_a(str, str, return -1);
3612 if(str[0] != '\0') {
3613 compose_convert_header
3614 (buf, sizeof(buf), str,
3615 strlen(header) + 2);
3617 fprintf(fp, "%s: ", header);
3618 first_address = FALSE;
3622 fprintf(fp, "%s", buf);
3626 if(!first_address) {
3630 g_free(header_w_colon);
3635 static gint compose_write_headers(Compose *compose, FILE *fp,
3636 const gchar *charset, EncodingType encoding,
3639 gchar buf[BUFFSIZE];
3641 /* struct utsname utsbuf; */
3643 g_return_val_if_fail(fp != NULL, -1);
3644 g_return_val_if_fail(charset != NULL, -1);
3645 g_return_val_if_fail(compose->account != NULL, -1);
3646 g_return_val_if_fail(compose->account->address != NULL, -1);
3649 if (compose->account->add_date) {
3650 get_rfc822_date(buf, sizeof(buf));
3651 fprintf(fp, "Date: %s\n", buf);
3655 if (!IS_IN_CUSTOM_HEADER("From")) {
3656 if (compose->account->name && *compose->account->name) {
3657 compose_convert_header
3658 (buf, sizeof(buf), compose->account->name,
3660 fprintf(fp, "From: %s <%s>\n",
3661 buf, compose->account->address);
3663 fprintf(fp, "From: %s\n", compose->account->address);
3667 compose_write_headers_from_headerlist(compose, fp, "To");
3668 #if 0 /* NEW COMPOSE GUI */
3669 if (compose->use_to) {
3670 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3672 Xstrdup_a(str, str, return -1);
3675 compose->to_list = address_list_append
3676 (compose->to_list, str);
3677 if (!IS_IN_CUSTOM_HEADER("To")) {
3678 compose_convert_header
3679 (buf, sizeof(buf), str,
3681 fprintf(fp, "To: %s\n", buf);
3689 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3690 #if 0 /* NEW COMPOSE GUI */
3691 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3693 Xstrdup_a(str, str, return -1);
3697 compose->newsgroup_list =
3698 newsgroup_list_append(compose->newsgroup_list,
3700 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3701 compose_convert_header(buf, sizeof(buf), str,
3702 strlen("Newsgroups: "));
3703 fprintf(fp, "Newsgroups: %s\n", buf);
3709 compose_write_headers_from_headerlist(compose, fp, "Cc");
3710 #if 0 /* NEW COMPOSE GUI */
3711 if (compose->use_cc) {
3712 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3714 Xstrdup_a(str, str, return -1);
3717 compose->to_list = address_list_append
3718 (compose->to_list, str);
3719 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3720 compose_convert_header
3721 (buf, sizeof(buf), str,
3723 fprintf(fp, "Cc: %s\n", buf);
3730 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3731 #if 0 /* NEW COMPOSE GUI */
3732 if (compose->use_bcc) {
3733 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3735 Xstrdup_a(str, str, return -1);
3738 compose->to_list = address_list_append
3739 (compose->to_list, str);
3740 compose_convert_header(buf, sizeof(buf), str,
3742 fprintf(fp, "Bcc: %s\n", buf);
3749 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3750 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3751 Xstrdup_a(str, str, return -1);
3754 compose_convert_header(buf, sizeof(buf), str,
3755 strlen("Subject: "));
3756 fprintf(fp, "Subject: %s\n", buf);
3761 if (compose->account->gen_msgid) {
3762 compose_generate_msgid(compose, buf, sizeof(buf));
3763 fprintf(fp, "Message-Id: <%s>\n", buf);
3764 compose->msgid = g_strdup(buf);
3768 if (compose->inreplyto && compose->to_list)
3769 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3772 if (compose->references)
3773 fprintf(fp, "References: %s\n", compose->references);
3776 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3777 #if 0 /* NEW COMPOSE GUI */
3778 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3779 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3781 Xstrdup_a(str, str, return -1);
3785 compose_convert_header(buf, sizeof(buf), str,
3786 strlen("Followup-To: "));
3787 fprintf(fp, "Followup-To: %s\n", buf);
3793 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3794 #if 0 /* NEW COMPOSE GUI */
3795 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3796 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3798 Xstrdup_a(str, str, return -1);
3801 compose_convert_header(buf, sizeof(buf), str,
3802 strlen("Reply-To: "));
3803 fprintf(fp, "Reply-To: %s\n", buf);
3809 if (compose->account->organization &&
3810 !IS_IN_CUSTOM_HEADER("Organization")) {
3811 compose_convert_header(buf, sizeof(buf),
3812 compose->account->organization,
3813 strlen("Organization: "));
3814 fprintf(fp, "Organization: %s\n", buf);
3817 /* Program version and system info */
3818 /* uname(&utsbuf); */
3819 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3820 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3822 gtk_major_version, gtk_minor_version, gtk_micro_version,
3824 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3826 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3827 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3829 gtk_major_version, gtk_minor_version, gtk_micro_version,
3831 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3834 /* custom headers */
3835 if (compose->account->add_customhdr) {
3838 for (cur = compose->account->customhdr_list; cur != NULL;
3840 CustomHeader *chdr = (CustomHeader *)cur->data;
3842 if (strcasecmp(chdr->name, "Date") != 0 &&
3843 strcasecmp(chdr->name, "From") != 0 &&
3844 strcasecmp(chdr->name, "To") != 0 &&
3845 /* strcasecmp(chdr->name, "Sender") != 0 && */
3846 strcasecmp(chdr->name, "Message-Id") != 0 &&
3847 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3848 strcasecmp(chdr->name, "References") != 0 &&
3849 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3850 strcasecmp(chdr->name, "Content-Type") != 0 &&
3851 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3853 compose_convert_header
3855 chdr->value ? chdr->value : "",
3856 strlen(chdr->name) + 2);
3857 fprintf(fp, "%s: %s\n", chdr->name, buf);
3863 fprintf(fp, "Mime-Version: 1.0\n");
3864 if (compose_use_attach(compose)) {
3865 get_rfc822_date(buf, sizeof(buf));
3866 subst_char(buf, ' ', '_');
3867 subst_char(buf, ',', '_');
3868 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3869 buf, (guint)compose);
3871 "Content-Type: multipart/mixed;\n"
3872 " boundary=\"%s\"\n", compose->boundary);
3874 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3875 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3876 procmime_get_encoding_str(encoding));
3879 /* Request Return Receipt */
3880 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3881 if (compose->return_receipt) {
3882 if (compose->account->name
3883 && *compose->account->name) {
3884 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3885 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3887 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3891 /* separator between header and body */
3897 #undef IS_IN_CUSTOM_HEADER
3899 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3902 g_return_if_fail(src != NULL);
3903 g_return_if_fail(dest != NULL);
3905 if (len < 1) return;
3909 if (is_ascii_str(src)) {
3910 strncpy2(dest, src, len);
3911 dest[len - 1] = '\0';
3914 conv_encode_header(dest, len, src, header_len);
3917 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3926 if (compose->account && compose->account->address &&
3927 *compose->account->address) {
3928 if (strchr(compose->account->address, '@'))
3929 addr = g_strdup(compose->account->address);
3931 addr = g_strconcat(compose->account->address, "@",
3932 get_domain_name(), NULL);
3934 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3937 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3938 lt->tm_year + 1900, lt->tm_mon + 1,
3939 lt->tm_mday, lt->tm_hour,
3940 lt->tm_min, lt->tm_sec,
3941 (guint)random(), addr);
3943 debug_print(_("generated Message-ID: %s\n"), buf);
3948 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3949 GtkWidget **entry, gint *count,
3950 const gchar *label_str,
3951 gboolean is_addr_entry)
3955 if (GTK_TABLE(table)->nrows < (*count) + 1)
3956 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3958 *hbox = gtk_hbox_new(FALSE, 0);
3959 label = gtk_label_new
3960 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3961 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3962 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3964 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3966 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3967 #if 0 /* NEW COMPOSE GUI */
3968 if (GTK_TABLE(table)->nrows > (*count) + 1)
3969 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3973 address_completion_register_entry(GTK_ENTRY(*entry));
3978 static void compose_create_header_entry(Compose *compose)
3980 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3984 GList *combo_list = NULL;
3985 gchar **string, *header;
3986 ComposeHeaderEntry *headerentry;
3988 headerentry = g_new0(ComposeHeaderEntry, 1);
3991 combo = gtk_combo_new();
3993 while(*string != NULL) {
3994 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3997 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3998 g_list_free(combo_list);
3999 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
4000 gtk_widget_show(combo);
4001 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4002 if(compose->header_last) {
4003 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4005 switch(compose->account->protocol) {
4007 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4010 header = prefs_common.trans_hdr ? _("To:") : "To:";
4014 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4017 entry = gtk_entry_new();
4018 gtk_widget_show(entry);
4019 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);
4021 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4022 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4023 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4025 address_completion_register_entry(GTK_ENTRY(entry));
4027 headerentry->compose = compose;
4028 headerentry->combo = combo;
4029 headerentry->entry = entry;
4030 headerentry->headernum = compose->header_nextrow;
4032 compose->header_nextrow++;
4033 compose->header_last = headerentry;
4036 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4038 ComposeHeaderEntry *last_header;
4040 last_header = compose->header_last;
4042 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4043 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4046 static GtkWidget *compose_create_header(Compose *compose)
4050 GtkWidget *from_optmenu_hbox;
4051 #if 0 /* NEW COMPOSE GUI */
4052 GtkWidget *to_entry;
4054 GtkWidget *newsgroups_entry;
4055 GtkWidget *newsgroups_hbox;
4057 GtkWidget *header_scrolledwin;
4058 GtkWidget *header_table;
4059 #if 0 /* NEW COMPOSE GUI */
4060 GtkWidget *cc_entry;
4062 GtkWidget *bcc_entry;
4063 GtkWidget *bcc_hbox;
4064 GtkWidget *reply_entry;
4065 GtkWidget *reply_hbox;
4066 GtkWidget *followup_entry;
4067 GtkWidget *followup_hbox;
4072 /* header labels and entries */
4073 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4074 gtk_widget_show(header_scrolledwin);
4075 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4077 header_table = gtk_table_new(2, 2, FALSE);
4078 gtk_widget_show(header_table);
4079 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4080 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4081 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4084 /* option menu for selecting accounts */
4085 hbox = gtk_hbox_new(FALSE, 0);
4086 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4087 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4088 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4090 from_optmenu_hbox = compose_account_option_menu_create(compose);
4091 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4092 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4093 #if 0 /* NEW COMPOSE GUI */
4094 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4098 compose->header_table = header_table;
4099 compose->header_list = NULL;
4100 compose->header_nextrow = count;
4102 compose_create_header_entry(compose);
4104 #if 0 /* NEW COMPOSE GUI */
4105 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4107 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4108 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4109 &count, "Newsgroups:", FALSE);
4110 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4112 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4114 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4116 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4117 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4119 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4120 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4122 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4123 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4124 "Followup-To:", FALSE);
4125 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4127 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4129 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4130 GTK_SIGNAL_FUNC(to_activated), compose);
4131 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4132 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4133 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4134 GTK_SIGNAL_FUNC(subject_activated), compose);
4135 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4136 GTK_SIGNAL_FUNC(cc_activated), compose);
4137 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4138 GTK_SIGNAL_FUNC(bcc_activated), compose);
4139 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4140 GTK_SIGNAL_FUNC(replyto_activated), compose);
4141 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4142 GTK_SIGNAL_FUNC(followupto_activated), compose);
4144 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4145 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4146 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4147 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4148 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4149 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4150 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4151 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4152 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4153 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4154 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4155 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4156 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4157 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4160 compose->table = NULL;
4161 #if 0 /* NEW COMPOSE GUI */
4162 compose->table = table;
4163 compose->to_hbox = to_hbox;
4164 compose->to_entry = to_entry;
4165 compose->newsgroups_hbox = newsgroups_hbox;
4166 compose->newsgroups_entry = newsgroups_entry;
4168 #if 0 /* NEW COMPOSE GUI */
4169 compose->cc_hbox = cc_hbox;
4170 compose->cc_entry = cc_entry;
4171 compose->bcc_hbox = bcc_hbox;
4172 compose->bcc_entry = bcc_entry;
4173 compose->reply_hbox = reply_hbox;
4174 compose->reply_entry = reply_entry;
4175 compose->followup_hbox = followup_hbox;
4176 compose->followup_entry = followup_entry;
4179 return header_scrolledwin ;
4182 GtkWidget *compose_create_attach(Compose *compose)
4184 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
4187 GtkWidget *attach_scrwin;
4188 GtkWidget *attach_clist;
4190 /* attachment list */
4191 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4192 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4193 GTK_POLICY_AUTOMATIC,
4195 gtk_widget_set_usize(attach_scrwin, -1, 80);
4197 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4198 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4200 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4201 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4202 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4203 GTK_SELECTION_EXTENDED);
4204 for (i = 0; i < N_ATTACH_COLS; i++)
4205 GTK_WIDGET_UNSET_FLAGS
4206 (GTK_CLIST(attach_clist)->column[i].button,
4208 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4210 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4211 GTK_SIGNAL_FUNC(attach_selected), compose);
4212 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4213 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4214 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4215 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4218 gtk_drag_dest_set(attach_clist,
4219 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4221 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4222 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4225 compose->attach_scrwin = attach_scrwin;
4226 compose->attach_clist = attach_clist;
4228 return attach_scrwin;
4231 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4232 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4234 static GtkWidget *compose_create_others(Compose *compose)
4237 GtkWidget *savemsg_checkbtn;
4238 GtkWidget *savemsg_entry;
4239 GtkWidget *savemsg_select;
4242 gchar *folderidentifier;
4244 /* Table for settings */
4245 table = gtk_table_new(3, 1, FALSE);
4246 gtk_widget_show(table);
4247 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4250 /* Save Message to folder */
4251 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4252 gtk_widget_show(savemsg_checkbtn);
4253 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4254 if(folder_get_default_outbox()) {
4255 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4257 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4258 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4260 savemsg_entry = gtk_entry_new();
4261 gtk_widget_show(savemsg_entry);
4262 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4263 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4264 if(folder_get_default_outbox()) {
4265 folderidentifier = folder_item_get_identifier(folder_get_default_outbox());
4266 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4267 g_free(folderidentifier);
4270 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4271 gtk_widget_show (savemsg_select);
4272 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4273 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4274 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4279 compose->savemsg_checkbtn = savemsg_checkbtn;
4280 compose->savemsg_entry = savemsg_entry;
4285 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4287 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4288 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4291 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4296 dest = foldersel_folder_sel(NULL, NULL);
4299 path = folder_item_get_identifier(dest);
4301 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4305 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4311 GtkWidget *handlebox;
4313 GtkWidget *notebook;
4318 GtkWidget *subject_hbox;
4319 GtkWidget *subject_frame;
4320 GtkWidget *subject_entry;
4324 GtkWidget *edit_vbox;
4325 GtkWidget *ruler_hbox;
4327 GtkWidget *scrolledwin;
4332 UndoMain *undostruct;
4334 guint n_menu_entries;
4335 GtkStyle *style, *new_style;
4338 gboolean success[1];
4340 GtkWidget *popupmenu;
4341 GtkWidget *menuitem;
4342 GtkItemFactory *popupfactory;
4343 GtkItemFactory *ifactory;
4344 GtkWidget *tmpl_menu;
4348 GtkPspell * gtkpspell = NULL;
4351 g_return_val_if_fail(account != NULL, NULL);
4353 debug_print(_("Creating compose window...\n"));
4354 compose = g_new0(Compose, 1);
4356 compose->account = account;
4357 compose->orig_account = account;
4359 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4360 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4361 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4362 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4363 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4364 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4365 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4366 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4367 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
4368 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
4369 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
4370 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
4371 gtk_widget_realize(window);
4373 gtkut_widget_set_composer_icon(window);
4375 vbox = gtk_vbox_new(FALSE, 0);
4376 gtk_container_add(GTK_CONTAINER(window), vbox);
4378 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4379 menubar = menubar_create(window, compose_entries,
4380 n_menu_entries, "<Compose>", compose);
4381 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4383 handlebox = gtk_handle_box_new();
4384 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4386 compose_toolbar_create(compose, handlebox);
4388 vbox2 = gtk_vbox_new(FALSE, 2);
4389 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4390 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4393 notebook = gtk_notebook_new();
4394 gtk_widget_set_usize(notebook, -1, 130);
4395 gtk_widget_show(notebook);
4397 /* header labels and entries */
4398 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4399 /* attachment list */
4400 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4402 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4405 subject_hbox = gtk_hbox_new(FALSE, 0);
4406 gtk_widget_show(subject_hbox);
4408 subject_frame = gtk_frame_new(NULL);
4409 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4410 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4411 gtk_widget_show(subject_frame);
4413 subject = gtk_hbox_new(FALSE, 0);
4414 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4415 gtk_widget_show(subject);
4417 label = gtk_label_new(_("Subject:"));
4418 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4419 gtk_widget_show(label);
4421 subject_entry = gtk_entry_new();
4422 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4423 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4424 gtk_widget_show(subject_entry);
4425 compose->subject_entry = subject_entry;
4426 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4428 edit_vbox = gtk_vbox_new(FALSE, 0);
4429 #if 0 /* NEW COMPOSE GUI */
4430 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4433 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4436 ruler_hbox = gtk_hbox_new(FALSE, 0);
4437 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4439 ruler = gtk_shruler_new();
4440 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4441 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4443 gtk_widget_set_usize(ruler_hbox, 1, -1);
4446 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4447 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4448 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4449 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4450 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4452 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4453 (GTK_SCROLLED_WINDOW(scrolledwin)),
4454 gtk_scrolled_window_get_vadjustment
4455 (GTK_SCROLLED_WINDOW(scrolledwin)));
4456 GTK_STEXT(text)->default_tab_width = 8;
4457 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4459 if (prefs_common.block_cursor) {
4460 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4463 if (prefs_common.smart_wrapping) {
4464 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4465 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4468 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4470 gtk_signal_connect(GTK_OBJECT(text), "changed",
4471 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4472 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4473 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4474 gtk_signal_connect(GTK_OBJECT(text), "activate",
4475 GTK_SIGNAL_FUNC(text_activated), compose);
4476 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4477 GTK_SIGNAL_FUNC(compose_button_press_cb),
4480 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4481 GTK_SIGNAL_FUNC(compose_key_press_cb),
4484 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4485 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4489 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4491 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4492 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4494 gtk_widget_show_all(vbox);
4496 /* pane between attach clist and text */
4497 paned = gtk_vpaned_new();
4498 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4499 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4500 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4501 gtk_paned_add1(GTK_PANED(paned), notebook);
4502 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4503 gtk_widget_show_all(paned);
4505 style = gtk_widget_get_style(text);
4507 /* workaround for the slow down of GtkSText when using Pixmap theme */
4508 if (style->engine) {
4509 GtkThemeEngine *engine;
4511 engine = style->engine;
4512 style->engine = NULL;
4513 new_style = gtk_style_copy(style);
4514 style->engine = engine;
4516 new_style = gtk_style_copy(style);
4518 if (prefs_common.textfont) {
4521 charset = conv_get_current_charset();
4522 if (MB_CUR_MAX == 1) {
4525 Xstrdup_a(fontstr, prefs_common.textfont, );
4526 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4528 font = gdk_font_load(fontstr);
4530 font = gdk_fontset_load(prefs_common.textfont);
4532 gdk_font_unref(new_style->font);
4533 new_style->font = font;
4537 gtk_widget_set_style(text, new_style);
4539 color[0] = quote_color;
4540 cmap = gdk_window_get_colormap(window->window);
4541 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4542 if (success[0] == FALSE) {
4543 g_warning("Compose: color allocation failed.\n");
4544 style = gtk_widget_get_style(text);
4545 quote_color = style->black;
4548 n_entries = sizeof(compose_popup_entries) /
4549 sizeof(compose_popup_entries[0]);
4550 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4551 "<Compose>", &popupfactory,
4554 ifactory = gtk_item_factory_from_widget(menubar);
4555 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4556 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4558 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tool/Template");
4559 #if 0 /* NEW COMPOSE GUI */
4560 gtk_widget_hide(bcc_hbox);
4561 gtk_widget_hide(bcc_entry);
4562 gtk_widget_hide(reply_hbox);
4563 gtk_widget_hide(reply_entry);
4564 gtk_widget_hide(followup_hbox);
4565 gtk_widget_hide(followup_entry);
4566 gtk_widget_hide(ruler_hbox);
4567 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4568 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4569 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4571 if (account->protocol == A_NNTP) {
4572 gtk_widget_hide(to_hbox);
4573 gtk_widget_hide(to_entry);
4574 gtk_widget_hide(cc_hbox);
4575 gtk_widget_hide(cc_entry);
4576 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4577 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4579 gtk_widget_hide(newsgroups_hbox);
4580 gtk_widget_hide(newsgroups_entry);
4581 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4582 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
4586 switch (prefs_common.toolbar_style) {
4588 gtk_widget_hide(handlebox);
4591 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4595 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4599 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4604 undostruct = undo_init(text);
4605 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4608 gtk_widget_show(window);
4610 address_completion_start(window);
4612 compose->window = window;
4613 compose->vbox = vbox;
4614 compose->menubar = menubar;
4615 compose->handlebox = handlebox;
4617 compose->vbox2 = vbox2;
4619 compose->paned = paned;
4621 compose->edit_vbox = edit_vbox;
4622 compose->ruler_hbox = ruler_hbox;
4623 compose->ruler = ruler;
4624 compose->scrolledwin = scrolledwin;
4625 compose->text = text;
4627 compose->focused_editable = NULL;
4629 compose->popupmenu = popupmenu;
4630 compose->popupfactory = popupfactory;
4632 compose->tmpl_menu = tmpl_menu;
4634 compose->mode = mode;
4636 compose->targetinfo = NULL;
4637 compose->replyinfo = NULL;
4639 compose->replyto = NULL;
4640 compose->mailinglist = NULL;
4642 compose->bcc = NULL;
4643 compose->followup_to = NULL;
4644 compose->inreplyto = NULL;
4645 compose->references = NULL;
4646 compose->msgid = NULL;
4647 compose->boundary = NULL;
4650 compose->use_signing = FALSE;
4651 compose->use_encryption = FALSE;
4652 #endif /* USE_GPGME */
4654 compose->modified = FALSE;
4656 compose->return_receipt = FALSE;
4658 compose->to_list = NULL;
4659 compose->newsgroup_list = NULL;
4661 compose->exteditor_file = NULL;
4662 compose->exteditor_pid = -1;
4663 compose->exteditor_readdes = -1;
4664 compose->exteditor_tag = -1;
4666 compose->bounce_filename = NULL;
4667 compose->undostruct = undostruct;
4670 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4671 if (prefs_common.enable_pspell) {
4672 gtkpspell = gtkpspell_new((const gchar*)prefs_common.dictionary,
4673 conv_get_current_charset_str(),
4674 prefs_common.misspelled_col,
4675 prefs_common.check_while_typing,
4678 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkpspellcheckers->error_message);
4679 gtkpspell_checkers_reset_error();
4682 GtkWidget *menuitem;
4684 if (!gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode)) {
4685 debug_print(_("Pspell: could not set suggestion mode %s"),
4686 gtkpspellcheckers->error_message);
4687 gtkpspell_checkers_reset_error();
4690 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
4691 gtkpspell_populate_submenu(gtkpspell, menuitem);
4692 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4697 compose_set_title(compose);
4699 #if 0 /* NEW COMPOSE GUI */
4700 compose->use_bcc = FALSE;
4701 compose->use_replyto = FALSE;
4702 compose->use_followupto = FALSE;
4706 compose->gtkpspell = gtkpspell;
4709 #if 0 /* NEW COMPOSE GUI */
4710 if (account->protocol != A_NNTP) {
4711 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
4712 gtk_check_menu_item_set_active
4713 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4714 gtk_widget_set_sensitive(menuitem, FALSE);
4715 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4716 gtk_check_menu_item_set_active
4717 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4718 gtk_widget_set_sensitive(menuitem, FALSE);
4721 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4722 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4723 #if 0 /* NEW COMPOSE GUI */
4724 compose->use_cc = TRUE;
4725 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4726 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4727 gtk_check_menu_item_set_active
4728 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4731 if (account->set_autobcc) {
4732 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4733 #if 0 /* NEW COMPOSE GUI */
4734 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
4735 gtk_check_menu_item_set_active
4736 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4737 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4738 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4742 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4743 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4744 #if 0 /* NEW COMPOSE GUI */
4745 compose->use_replyto = TRUE;
4746 menuitem = gtk_item_factory_get_item(ifactory,
4748 gtk_check_menu_item_set_active
4749 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4750 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4751 account->auto_replyto);
4755 if (account->protocol != A_NNTP) {
4756 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4758 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4761 #if 0 /* NEW COMPOSE GUI */
4762 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
4763 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4764 prefs_common.show_ruler);
4768 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4769 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4770 account->default_sign);
4771 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4772 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4773 account->default_encrypt);
4774 #endif /* USE_GPGME */
4776 addressbook_set_target_compose(compose);
4777 compose_set_template_menu(compose);
4779 compose_list = g_list_append(compose_list, compose);
4781 #if 0 /* NEW COMPOSE GUI */
4782 compose->use_to = FALSE;
4783 compose->use_cc = FALSE;
4784 compose->use_attach = TRUE;
4787 #if 0 /* NEW COMPOSE GUI */
4788 if (!compose->use_bcc) {
4789 gtk_widget_hide(bcc_hbox);
4790 gtk_widget_hide(bcc_entry);
4791 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4793 if (!compose->use_replyto) {
4794 gtk_widget_hide(reply_hbox);
4795 gtk_widget_hide(reply_entry);
4796 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4798 if (!compose->use_followupto) {
4799 gtk_widget_hide(followup_hbox);
4800 gtk_widget_hide(followup_entry);
4801 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4804 if (!prefs_common.show_ruler)
4805 gtk_widget_hide(ruler_hbox);
4807 select_account(compose, account);
4812 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4815 GtkWidget *icon_wid;
4816 GtkWidget *send_btn;
4817 GtkWidget *sendl_btn;
4818 GtkWidget *draft_btn;
4819 GtkWidget *insert_btn;
4820 GtkWidget *attach_btn;
4822 GtkWidget *exteditor_btn;
4823 GtkWidget *linewrap_btn;
4824 GtkWidget *addrbook_btn;
4826 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4828 gtk_container_add(GTK_CONTAINER(container), toolbar);
4829 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4830 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4831 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4832 GTK_TOOLBAR_SPACE_LINE);
4834 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
4835 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4839 icon_wid, toolbar_send_cb, compose);
4841 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND_QUEUE);
4842 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4844 _("Put into queue folder and send later"),
4846 icon_wid, toolbar_send_later_cb,
4849 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4850 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4852 _("Save to draft folder"),
4854 icon_wid, toolbar_draft_cb,
4857 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4859 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_PASTE);
4860 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4864 icon_wid, toolbar_insert_cb,
4867 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_ATTACH);
4868 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4872 icon_wid, toolbar_attach_cb,
4875 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4877 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4878 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4880 _("Insert signature"),
4882 icon_wid, toolbar_sig_cb, compose);
4884 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4886 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_COMPOSE);
4887 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4889 _("Edit with external editor"),
4892 toolbar_ext_editor_cb,
4895 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_LINEWRAP);
4896 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4898 _("Wrap all long lines"),
4901 toolbar_linewrap_cb,
4904 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4906 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_ADDRESS_BOOK);
4907 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4911 icon_wid, toolbar_address_cb,
4914 compose->toolbar = toolbar;
4915 compose->send_btn = send_btn;
4916 compose->sendl_btn = sendl_btn;
4917 compose->draft_btn = draft_btn;
4918 compose->insert_btn = insert_btn;
4919 compose->attach_btn = attach_btn;
4920 compose->sig_btn = sig_btn;
4921 compose->exteditor_btn = exteditor_btn;
4922 compose->linewrap_btn = linewrap_btn;
4923 compose->addrbook_btn = addrbook_btn;
4925 gtk_widget_show_all(toolbar);
4928 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4934 gint num = 0, def_menu = 0;
4936 accounts = account_get_list();
4937 g_return_val_if_fail(accounts != NULL, NULL);
4939 hbox = gtk_hbox_new(FALSE, 0);
4940 optmenu = gtk_option_menu_new();
4941 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4942 menu = gtk_menu_new();
4944 for (; accounts != NULL; accounts = accounts->next, num++) {
4945 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4946 GtkWidget *menuitem;
4949 if (ac == compose->account) def_menu = num;
4951 name = g_strdup_printf("%s: %s <%s>",
4952 ac->account_name, ac->name, ac->address);
4953 MENUITEM_ADD(menu, menuitem, name, ac);
4955 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4956 GTK_SIGNAL_FUNC(account_activated),
4960 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4961 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4966 static void compose_set_template_menu(Compose *compose)
4968 GSList *tmpl_list, *cur;
4972 tmpl_list = template_get_config();
4974 menu = gtk_menu_new();
4976 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4977 Template *tmpl = (Template *)cur->data;
4979 item = gtk_menu_item_new_with_label(tmpl->name);
4980 gtk_menu_append(GTK_MENU(menu), item);
4981 gtk_signal_connect(GTK_OBJECT(item), "activate",
4982 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4984 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4985 gtk_widget_show(item);
4988 gtk_widget_show(menu);
4989 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4992 void compose_reflect_prefs_all(void)
4997 for (cur = compose_list; cur != NULL; cur = cur->next) {
4998 compose = (Compose *)cur->data;
4999 compose_set_template_menu(compose);
5003 static void compose_template_apply(Compose *compose, Template *tmpl)
5008 if (!tmpl || !tmpl->value) return;
5010 gtk_stext_freeze(GTK_STEXT(compose->text));
5012 if (tmpl->subject && *tmpl->subject != '\0')
5013 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5015 if (tmpl->to && *tmpl->to != '\0')
5016 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5018 gtk_stext_clear(GTK_STEXT(compose->text));
5020 if (compose->replyinfo == NULL) {
5023 memset(&dummyinfo, 0, sizeof(MsgInfo));
5024 parsed_str = compose_quote_fmt(compose, &dummyinfo,
5027 if (prefs_common.quotemark && *prefs_common.quotemark)
5028 qmark = prefs_common.quotemark;
5032 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5033 tmpl->value, qmark);
5036 if (parsed_str && prefs_common.auto_sig)
5037 compose_insert_sig(compose);
5039 gtk_stext_thaw(GTK_STEXT(compose->text));
5042 static void compose_destroy(Compose *compose)
5045 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5048 /* NOTE: address_completion_end() does nothing with the window
5049 * however this may change. */
5050 address_completion_end(compose->window);
5052 slist_free_strings(compose->to_list);
5053 g_slist_free(compose->to_list);
5054 slist_free_strings(compose->newsgroup_list);
5055 g_slist_free(compose->newsgroup_list);
5056 slist_free_strings(compose->header_list);
5057 g_slist_free(compose->header_list);
5059 procmsg_msginfo_free(compose->targetinfo);
5060 procmsg_msginfo_free(compose->replyinfo);
5062 g_free(compose->replyto);
5063 g_free(compose->cc);
5064 g_free(compose->bcc);
5065 g_free(compose->newsgroups);
5066 g_free(compose->followup_to);
5068 g_free(compose->inreplyto);
5069 g_free(compose->references);
5070 g_free(compose->msgid);
5071 g_free(compose->boundary);
5073 if (compose->bounce_filename)
5074 g_free(compose->bounce_filename);
5076 g_free(compose->exteditor_file);
5078 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5080 compose_attach_info_free(ainfo);
5082 if (addressbook_get_target_compose() == compose)
5083 addressbook_set_target_compose(NULL);
5086 if (compose->gtkpspell) {
5087 gtkpspell_delete(compose->gtkpspell);
5091 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5092 prefs_common.compose_height = compose->window->allocation.height;
5094 gtk_widget_destroy(compose->paned);
5098 compose_list = g_list_remove(compose_list, compose);
5101 static void compose_attach_info_free(AttachInfo *ainfo)
5103 g_free(ainfo->file);
5104 g_free(ainfo->content_type);
5105 g_free(ainfo->name);
5109 static void compose_attach_remove_selected(Compose *compose)
5111 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5115 while (clist->selection != NULL) {
5116 row = GPOINTER_TO_INT(clist->selection->data);
5117 ainfo = gtk_clist_get_row_data(clist, row);
5118 compose_attach_info_free(ainfo);
5119 gtk_clist_remove(clist, row);
5123 static struct _AttachProperty
5126 GtkWidget *mimetype_entry;
5127 GtkWidget *encoding_optmenu;
5128 GtkWidget *path_entry;
5129 GtkWidget *filename_entry;
5131 GtkWidget *cancel_btn;
5134 static void compose_attach_property(Compose *compose)
5136 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5139 GtkOptionMenu *optmenu;
5140 static gboolean cancelled;
5142 if (!clist->selection) return;
5143 row = GPOINTER_TO_INT(clist->selection->data);
5145 ainfo = gtk_clist_get_row_data(clist, row);
5148 if (!attach_prop.window)
5149 compose_attach_property_create(&cancelled);
5150 gtk_widget_grab_focus(attach_prop.ok_btn);
5151 gtk_widget_show(attach_prop.window);
5152 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5154 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5155 if (ainfo->encoding == ENC_UNKNOWN)
5156 gtk_option_menu_set_history(optmenu, ENC_BASE64);
5158 gtk_option_menu_set_history(optmenu, ainfo->encoding);
5160 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5161 ainfo->content_type ? ainfo->content_type : "");
5162 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5163 ainfo->file ? ainfo->file : "");
5164 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5165 ainfo->name ? ainfo->name : "");
5169 gchar *cnttype = NULL;
5173 GtkWidget *menuitem;
5178 if (cancelled == TRUE) {
5179 gtk_widget_hide(attach_prop.window);
5183 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5184 if (*text != '\0') {
5187 text = g_strstrip(g_strdup(text));
5188 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5189 cnttype = g_strdup(text);
5192 alertpanel_error(_("Invalid MIME type."));
5198 menu = gtk_option_menu_get_menu(optmenu);
5199 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5200 ainfo->encoding = GPOINTER_TO_INT
5201 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5203 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5204 if (*text != '\0') {
5205 if (is_file_exist(text) &&
5206 (size = get_file_size(text)) > 0)
5207 file = g_strdup(text);
5210 (_("File doesn't exist or is empty."));
5216 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5217 if (*text != '\0') {
5218 g_free(ainfo->name);
5219 ainfo->name = g_strdup(text);
5223 g_free(ainfo->content_type);
5224 ainfo->content_type = cnttype;
5227 g_free(ainfo->file);
5233 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5234 ainfo->content_type);
5235 gtk_clist_set_text(clist, row, COL_SIZE,
5236 to_human_readable(ainfo->size));
5237 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5239 gtk_widget_hide(attach_prop.window);
5244 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5246 label = gtk_label_new(str); \
5247 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5248 GTK_FILL, 0, 0, 0); \
5249 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5251 entry = gtk_entry_new(); \
5252 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5253 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5256 static void compose_attach_property_create(gboolean *cancelled)
5262 GtkWidget *mimetype_entry;
5265 GtkWidget *optmenu_menu;
5266 GtkWidget *menuitem;
5267 GtkWidget *path_entry;
5268 GtkWidget *filename_entry;
5271 GtkWidget *cancel_btn;
5272 GList *mime_type_list, *strlist;
5274 debug_print("Creating attach_property window...\n");
5276 window = gtk_window_new(GTK_WINDOW_DIALOG);
5277 gtk_widget_set_usize(window, 480, -1);
5278 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5279 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
5280 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5281 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5282 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5283 GTK_SIGNAL_FUNC(attach_property_delete_event),
5285 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5286 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5289 vbox = gtk_vbox_new(FALSE, 8);
5290 gtk_container_add(GTK_CONTAINER(window), vbox);
5292 table = gtk_table_new(4, 2, FALSE);
5293 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5294 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5295 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5297 label = gtk_label_new(_("MIME type"));
5298 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5300 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5301 mimetype_entry = gtk_combo_new();
5302 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5303 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5305 /* stuff with list */
5306 mime_type_list = procmime_get_mime_type_list();
5308 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5309 MimeType *type = (MimeType *) mime_type_list->data;
5310 strlist = g_list_append(strlist,
5311 g_strdup_printf("%s/%s",
5312 type->type, type->sub_type));
5315 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5317 for (mime_type_list = strlist; mime_type_list != NULL;
5318 mime_type_list = mime_type_list->next)
5319 g_free(mime_type_list->data);
5320 g_list_free(strlist);
5322 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5324 label = gtk_label_new(_("Encoding"));
5325 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5327 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5329 hbox = gtk_hbox_new(FALSE, 0);
5330 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5331 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5333 optmenu = gtk_option_menu_new();
5334 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5336 optmenu_menu = gtk_menu_new();
5337 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5338 gtk_widget_set_sensitive(menuitem, FALSE);
5339 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5340 gtk_widget_set_sensitive(menuitem, FALSE);
5341 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5342 gtk_widget_set_sensitive(menuitem, FALSE);
5343 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5345 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5347 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5348 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5350 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5351 &cancel_btn, _("Cancel"), NULL, NULL);
5352 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5353 gtk_widget_grab_default(ok_btn);
5355 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5356 GTK_SIGNAL_FUNC(attach_property_ok),
5358 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5359 GTK_SIGNAL_FUNC(attach_property_cancel),
5362 gtk_widget_show_all(vbox);
5364 attach_prop.window = window;
5365 attach_prop.mimetype_entry = mimetype_entry;
5366 attach_prop.encoding_optmenu = optmenu;
5367 attach_prop.path_entry = path_entry;
5368 attach_prop.filename_entry = filename_entry;
5369 attach_prop.ok_btn = ok_btn;
5370 attach_prop.cancel_btn = cancel_btn;
5373 #undef SET_LABEL_AND_ENTRY
5375 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5381 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5387 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5388 gboolean *cancelled)
5396 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5397 gboolean *cancelled)
5399 if (event && event->keyval == GDK_Escape) {
5405 static void compose_exec_ext_editor(Compose *compose)
5411 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5412 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5414 if (pipe(pipe_fds) < 0) {
5419 if ((pid = fork()) < 0) {
5425 /* close the write side of the pipe */
5428 compose->exteditor_file = g_strdup(tmp);
5429 compose->exteditor_pid = pid;
5430 compose->exteditor_readdes = pipe_fds[0];
5432 compose_set_ext_editor_sensitive(compose, FALSE);
5434 compose->exteditor_tag =
5435 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5436 compose_input_cb, compose);
5437 } else { /* process-monitoring process */
5443 /* close the read side of the pipe */
5446 if (compose_write_body_to_file(compose, tmp) < 0) {
5447 fd_write(pipe_fds[1], "2\n", 2);
5451 pid_ed = compose_exec_ext_editor_real(tmp);
5453 fd_write(pipe_fds[1], "1\n", 2);
5457 /* wait until editor is terminated */
5458 waitpid(pid_ed, NULL, 0);
5460 fd_write(pipe_fds[1], "0\n", 2);
5467 static gint compose_exec_ext_editor_real(const gchar *file)
5469 static gchar *def_cmd = "emacs %s";
5475 g_return_val_if_fail(file != NULL, -1);
5477 if ((pid = fork()) < 0) {
5482 if (pid != 0) return pid;
5484 /* grandchild process */
5486 if (setpgid(0, getppid()))
5489 if (prefs_common.ext_editor_cmd &&
5490 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5491 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5492 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5494 if (prefs_common.ext_editor_cmd)
5495 g_warning(_("External editor command line is invalid: `%s'\n"),
5496 prefs_common.ext_editor_cmd);
5497 g_snprintf(buf, sizeof(buf), def_cmd, file);
5500 cmdline = g_strsplit(buf, " ", 1024);
5501 execvp(cmdline[0], cmdline);
5504 g_strfreev(cmdline);
5509 static gboolean compose_ext_editor_kill(Compose *compose)
5511 pid_t pgid = compose->exteditor_pid * -1;
5514 ret = kill(pgid, 0);
5516 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5520 msg = g_strdup_printf
5521 (_("The external editor is still working.\n"
5522 "Force terminating the process?\n"
5523 "process group id: %d"), -pgid);
5524 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5527 if (val == G_ALERTDEFAULT) {
5528 gdk_input_remove(compose->exteditor_tag);
5529 close(compose->exteditor_readdes);
5531 if (kill(pgid, SIGTERM) < 0) perror("kill");
5532 waitpid(compose->exteditor_pid, NULL, 0);
5534 g_warning(_("Terminated process group id: %d"), -pgid);
5535 g_warning(_("Temporary file: %s"),
5536 compose->exteditor_file);
5538 compose_set_ext_editor_sensitive(compose, TRUE);
5540 g_free(compose->exteditor_file);
5541 compose->exteditor_file = NULL;
5542 compose->exteditor_pid = -1;
5543 compose->exteditor_readdes = -1;
5544 compose->exteditor_tag = -1;
5552 static void compose_input_cb(gpointer data, gint source,
5553 GdkInputCondition condition)
5556 Compose *compose = (Compose *)data;
5559 debug_print(_("Compose: input from monitoring process\n"));
5561 gdk_input_remove(compose->exteditor_tag);
5564 if (read(source, &buf[i], 1) < 1) {
5568 if (buf[i] == '\n') {
5573 if (i == sizeof(buf) - 1)
5577 waitpid(compose->exteditor_pid, NULL, 0);
5579 if (buf[0] == '0') { /* success */
5580 GtkSText *text = GTK_STEXT(compose->text);
5582 gtk_stext_freeze(text);
5583 gtk_stext_set_point(text, 0);
5584 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5585 compose_insert_file(compose, compose->exteditor_file);
5586 compose_changed_cb(NULL, compose);
5587 gtk_stext_thaw(text);
5589 if (unlink(compose->exteditor_file) < 0)
5590 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5591 } else if (buf[0] == '1') { /* failed */
5592 g_warning(_("Couldn't exec external editor\n"));
5593 if (unlink(compose->exteditor_file) < 0)
5594 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5595 } else if (buf[0] == '2') {
5596 g_warning(_("Couldn't write to file\n"));
5597 } else if (buf[0] == '3') {
5598 g_warning(_("Pipe read failed\n"));
5603 compose_set_ext_editor_sensitive(compose, TRUE);
5605 g_free(compose->exteditor_file);
5606 compose->exteditor_file = NULL;
5607 compose->exteditor_pid = -1;
5608 compose->exteditor_readdes = -1;
5609 compose->exteditor_tag = -1;
5612 static void compose_set_ext_editor_sensitive(Compose *compose,
5615 GtkItemFactory *ifactory;
5617 ifactory = gtk_item_factory_from_widget(compose->menubar);
5619 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5620 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5621 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5623 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5624 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5625 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5626 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5627 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5630 gtk_widget_set_sensitive(compose->text, sensitive);
5631 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5632 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5633 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5634 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5635 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5636 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5637 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5641 * compose_undo_state_changed:
5643 * Change the sensivity of the menuentries undo and redo
5645 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5646 gint redo_state, gpointer data)
5648 GtkWidget *widget = GTK_WIDGET(data);
5649 GtkItemFactory *ifactory;
5651 g_return_if_fail(widget != NULL);
5653 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
5655 ifactory = gtk_item_factory_from_widget(widget);
5657 switch (undo_state) {
5658 case UNDO_STATE_TRUE:
5659 if (!undostruct->undo_state) {
5660 debug_print ("Set_undo - Testpoint\n");
5661 undostruct->undo_state = TRUE;
5662 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5665 case UNDO_STATE_FALSE:
5666 if (undostruct->undo_state) {
5667 undostruct->undo_state = FALSE;
5668 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5671 case UNDO_STATE_UNCHANGED:
5673 case UNDO_STATE_REFRESH:
5674 menu_set_sensitive(ifactory, "/Edit/Undo",
5675 undostruct->undo_state);
5678 g_warning("Undo state not recognized");
5682 switch (redo_state) {
5683 case UNDO_STATE_TRUE:
5684 if (!undostruct->redo_state) {
5685 undostruct->redo_state = TRUE;
5686 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5689 case UNDO_STATE_FALSE:
5690 if (undostruct->redo_state) {
5691 undostruct->redo_state = FALSE;
5692 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5695 case UNDO_STATE_UNCHANGED:
5697 case UNDO_STATE_REFRESH:
5698 menu_set_sensitive(ifactory, "/Edit/Redo",
5699 undostruct->redo_state);
5702 g_warning("Redo state not recognized");
5707 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5711 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5712 cursor_pos = MAX(cursor_pos, 0);
5717 /* callback functions */
5719 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5720 * includes "non-client" (windows-izm) in calculation, so this calculation
5721 * may not be accurate.
5723 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5724 GtkAllocation *allocation,
5725 GtkSHRuler *shruler)
5727 if (prefs_common.show_ruler) {
5729 gint line_width_in_chars;
5731 char_width = gtkut_get_font_width
5732 (GTK_WIDGET(widget)->style->font);
5733 line_width_in_chars =
5734 (allocation->width - allocation->x) / char_width;
5736 /* got the maximum */
5737 gtk_ruler_set_range(GTK_RULER(shruler),
5738 0.0, line_width_in_chars,
5739 calc_cursor_xpos(GTK_STEXT(widget),
5742 /*line_width_in_chars*/ char_width);
5748 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5750 compose_send_cb(data, 0, NULL);
5753 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5755 compose_send_later_cb(data, 0, NULL);
5758 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5760 compose_draft_cb(data, 0, NULL);
5763 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5765 compose_insert_file_cb(data, 0, NULL);
5768 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5770 compose_attach_cb(data, 0, NULL);
5773 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5775 Compose *compose = (Compose *)data;
5777 compose_insert_sig(compose);
5780 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5782 Compose *compose = (Compose *)data;
5784 compose_exec_ext_editor(compose);
5787 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5789 Compose *compose = (Compose *)data;
5791 compose_wrap_line(compose);
5794 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5796 compose_address_cb(data, 0, NULL);
5799 static void select_account(Compose * compose, PrefsAccount * ac)
5801 compose->account = ac;
5802 compose_set_title(compose);
5804 #if 0 /* NEW COMPOSE GUI */
5805 if (ac->protocol == A_NNTP) {
5806 GtkItemFactory *ifactory;
5807 GtkWidget *menuitem;
5809 ifactory = gtk_item_factory_from_widget(compose->menubar);
5810 menu_set_sensitive(ifactory,
5811 "/Message/Followup to", TRUE);
5812 gtk_widget_show(compose->newsgroups_hbox);
5813 gtk_widget_show(compose->newsgroups_entry);
5814 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5817 compose->use_to = FALSE;
5818 compose->use_cc = FALSE;
5820 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5821 gtk_check_menu_item_set_active
5822 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5824 menu_set_sensitive(ifactory,
5825 "/Message/To", TRUE);
5826 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5827 gtk_check_menu_item_set_active
5828 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5830 gtk_widget_hide(compose->to_hbox);
5831 gtk_widget_hide(compose->to_entry);
5832 gtk_widget_hide(compose->cc_hbox);
5833 gtk_widget_hide(compose->cc_entry);
5834 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5836 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5840 GtkItemFactory *ifactory;
5841 GtkWidget *menuitem;
5843 ifactory = gtk_item_factory_from_widget(compose->menubar);
5844 menu_set_sensitive(ifactory,
5845 "/Message/Followup to", FALSE);
5846 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5847 gtk_widget_hide(compose->newsgroups_hbox);
5848 gtk_widget_hide(compose->newsgroups_entry);
5849 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5852 compose->use_to = TRUE;
5853 compose->use_cc = TRUE;
5855 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5856 gtk_check_menu_item_set_active
5857 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5858 menu_set_sensitive(ifactory,
5859 "/Message/To", FALSE);
5860 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5861 gtk_check_menu_item_set_active
5862 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5863 gtk_widget_show(compose->to_hbox);
5864 gtk_widget_show(compose->to_entry);
5865 gtk_widget_show(compose->cc_hbox);
5866 gtk_widget_show(compose->cc_entry);
5868 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5870 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5873 gtk_widget_queue_resize(compose->table_vbox);
5877 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5879 Compose *compose = (Compose *)data;
5883 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5884 g_return_if_fail(ac != NULL);
5886 if (ac != compose->account)
5887 select_account(compose, ac);
5890 static void attach_selected(GtkCList *clist, gint row, gint column,
5891 GdkEvent *event, gpointer data)
5893 Compose *compose = (Compose *)data;
5895 if (event && event->type == GDK_2BUTTON_PRESS)
5896 compose_attach_property(compose);
5899 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5902 Compose *compose = (Compose *)data;
5903 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5908 if (event->button == 3) {
5909 if ((clist->selection && !clist->selection->next) ||
5910 !clist->selection) {
5911 gtk_clist_unselect_all(clist);
5912 if (gtk_clist_get_selection_info(clist,
5915 gtk_clist_select_row(clist, row, column);
5916 gtkut_clist_set_focus_row(clist, row);
5919 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5920 NULL, NULL, event->button, event->time);
5924 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5927 Compose *compose = (Compose *)data;
5931 switch (event->keyval) {
5933 compose_attach_remove_selected(compose);
5938 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5940 Compose *compose = (Compose *)data;
5943 val = compose_send(compose);
5945 if (val == 0) gtk_widget_destroy(compose->window);
5948 static void compose_send_later_cb(gpointer data, guint action,
5951 Compose *compose = (Compose *)data;
5954 val = compose_queue(compose, NULL, NULL);
5955 if (!val) gtk_widget_destroy(compose->window);
5958 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5960 Compose *compose = (Compose *)data;
5964 static gboolean lock = FALSE;
5968 draft = folder_get_default_draft();
5969 g_return_if_fail(draft != NULL);
5973 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5974 G_DIR_SEPARATOR, (gint)compose);
5976 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5982 folder_item_scan(draft);
5983 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) <= 0) {
5990 draft->mtime = 0; /* force updating */
5992 if (compose->mode == COMPOSE_REEDIT) {
5993 compose_remove_reedit_target(compose);
5994 if (compose->targetinfo &&
5995 compose->targetinfo->folder != draft)
5996 folderview_update_item(compose->targetinfo->folder,
6000 folder_item_scan(draft);
6001 folderview_update_item(draft, TRUE);
6005 /* 0: quit editing 1: keep editing */
6007 gtk_widget_destroy(compose->window);
6012 path = folder_item_fetch_msg(draft, msgnum);
6013 g_return_if_fail(path != NULL);
6014 if (stat(path, &s) < 0) {
6015 FILE_OP_ERROR(path, "stat");
6022 procmsg_msginfo_free(compose->targetinfo);
6023 compose->targetinfo = g_new0(MsgInfo, 1);
6024 compose->targetinfo->msgnum = msgnum;
6025 compose->targetinfo->size = s.st_size;
6026 compose->targetinfo->mtime = s.st_mtime;
6027 compose->targetinfo->folder = draft;
6028 compose->mode = COMPOSE_REEDIT;
6032 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6034 Compose *compose = (Compose *)data;
6037 if (compose->bounce_filename != NULL)
6040 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6045 for ( tmp = file_list; tmp; tmp = tmp->next) {
6046 gchar *file = (gchar *) tmp->data;
6047 compose_attach_append(compose, file, MIME_UNKNOWN);
6050 g_list_free(file_list);
6054 static void compose_insert_file_cb(gpointer data, guint action,
6057 Compose *compose = (Compose *)data;
6060 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6065 for ( tmp = file_list; tmp; tmp = tmp->next) {
6066 gchar *file = (gchar *) tmp->data;
6067 compose_insert_file(compose, file);
6070 g_list_free(file_list);
6074 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6077 compose_close_cb(data, 0, NULL);
6081 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6083 Compose *compose = (Compose *)data;
6086 if (compose->exteditor_tag != -1) {
6087 if (!compose_ext_editor_kill(compose))
6091 if (compose->modified) {
6092 val = alertpanel(_("Discard message"),
6093 _("This message has been modified. discard it?"),
6094 _("Discard"), _("to Draft"), _("Cancel"));
6097 case G_ALERTDEFAULT:
6099 case G_ALERTALTERNATE:
6100 compose_draft_cb(data, 0, NULL);
6106 gtk_widget_destroy(compose->window);
6109 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6111 Compose *compose = (Compose *)data;
6113 addressbook_open(compose);
6116 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6118 Compose *compose = (Compose *)data;
6121 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6122 g_return_if_fail(tmpl != NULL);
6124 compose_template_apply(compose, tmpl);
6127 static void compose_ext_editor_cb(gpointer data, guint action,
6130 Compose *compose = (Compose *)data;
6132 compose_exec_ext_editor(compose);
6135 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6137 compose_destroy(compose);
6140 static void compose_undo_cb(Compose *compose)
6142 undo_undo(compose->undostruct);
6145 static void compose_redo_cb(Compose *compose)
6147 undo_redo(compose->undostruct);
6150 static void compose_cut_cb(Compose *compose)
6152 if (compose->focused_editable &&
6153 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6154 gtk_editable_cut_clipboard
6155 (GTK_EDITABLE(compose->focused_editable));
6158 static void compose_copy_cb(Compose *compose)
6160 if (compose->focused_editable &&
6161 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6162 gtk_editable_copy_clipboard
6163 (GTK_EDITABLE(compose->focused_editable));
6166 static void compose_paste_cb(Compose *compose)
6168 if (compose->focused_editable &&
6169 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6170 gtk_editable_paste_clipboard
6171 (GTK_EDITABLE(compose->focused_editable));
6174 static void compose_allsel_cb(Compose *compose)
6176 if (compose->focused_editable &&
6177 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6178 gtk_editable_select_region
6179 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6182 static void compose_move_beginning_of_line_cb(Compose *compose)
6184 if (compose->focused_editable &&
6185 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6186 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6189 static void compose_gtk_stext_action_cb(Compose *compose, ComposeCallGtkSTextAction action)
6191 if (!(compose->focused_editable && GTK_WIDGET_HAS_FOCUS(compose->focused_editable))) return;
6194 case COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE:
6195 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6197 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER:
6198 gtk_stext_move_forward_character(GTK_STEXT(compose->focused_editable));
6200 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER:
6201 gtk_stext_move_backward_character(GTK_STEXT(compose->focused_editable));
6203 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD:
6204 gtk_stext_move_forward_word(GTK_STEXT(compose->focused_editable));
6206 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD:
6207 gtk_stext_move_backward_word(GTK_STEXT(compose->focused_editable));
6209 case COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE:
6210 gtk_stext_move_end_of_line(GTK_STEXT(compose->focused_editable));
6212 case COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE:
6213 gtk_stext_move_next_line(GTK_STEXT(compose->focused_editable));
6215 case COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE:
6216 gtk_stext_move_previous_line(GTK_STEXT(compose->focused_editable));
6218 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER:
6219 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6221 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER:
6222 gtk_stext_delete_backward_character(GTK_STEXT(compose->focused_editable));
6224 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD:
6225 gtk_stext_delete_forward_word(GTK_STEXT(compose->focused_editable));
6227 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD:
6228 gtk_stext_delete_backward_word(GTK_STEXT(compose->focused_editable));
6230 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE:
6231 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6233 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N:
6234 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6235 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6237 case COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END:
6238 gtk_stext_delete_to_line_end(GTK_STEXT(compose->focused_editable));
6245 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6247 if (GTK_IS_EDITABLE(widget))
6248 compose->focused_editable = widget;
6251 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6253 if (compose->modified == FALSE) {
6254 compose->modified = TRUE;
6255 compose_set_title(compose);
6259 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6262 gtk_stext_set_point(GTK_STEXT(widget),
6263 gtk_editable_get_position(GTK_EDITABLE(widget)));
6267 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6270 gtk_stext_set_point(GTK_STEXT(widget),
6271 gtk_editable_get_position(GTK_EDITABLE(widget)));
6275 #if 0 /* NEW COMPOSE GUI */
6276 static void compose_toggle_to_cb(gpointer data, guint action,
6279 Compose *compose = (Compose *)data;
6281 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6282 gtk_widget_show(compose->to_hbox);
6283 gtk_widget_show(compose->to_entry);
6284 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6285 compose->use_to = TRUE;
6287 gtk_widget_hide(compose->to_hbox);
6288 gtk_widget_hide(compose->to_entry);
6289 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6290 gtk_widget_queue_resize(compose->table_vbox);
6291 compose->use_to = FALSE;
6294 if (addressbook_get_target_compose() == compose)
6295 addressbook_set_target_compose(compose);
6298 static void compose_toggle_cc_cb(gpointer data, guint action,
6301 Compose *compose = (Compose *)data;
6303 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6304 gtk_widget_show(compose->cc_hbox);
6305 gtk_widget_show(compose->cc_entry);
6306 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6307 compose->use_cc = TRUE;
6309 gtk_widget_hide(compose->cc_hbox);
6310 gtk_widget_hide(compose->cc_entry);
6311 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6312 gtk_widget_queue_resize(compose->table_vbox);
6313 compose->use_cc = FALSE;
6316 if (addressbook_get_target_compose() == compose)
6317 addressbook_set_target_compose(compose);
6320 static void compose_toggle_bcc_cb(gpointer data, guint action,
6323 Compose *compose = (Compose *)data;
6325 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6326 gtk_widget_show(compose->bcc_hbox);
6327 gtk_widget_show(compose->bcc_entry);
6328 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6329 compose->use_bcc = TRUE;
6331 gtk_widget_hide(compose->bcc_hbox);
6332 gtk_widget_hide(compose->bcc_entry);
6333 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6334 gtk_widget_queue_resize(compose->table_vbox);
6335 compose->use_bcc = FALSE;
6338 if (addressbook_get_target_compose() == compose)
6339 addressbook_set_target_compose(compose);
6342 static void compose_toggle_replyto_cb(gpointer data, guint action,
6345 Compose *compose = (Compose *)data;
6347 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6348 gtk_widget_show(compose->reply_hbox);
6349 gtk_widget_show(compose->reply_entry);
6350 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6351 compose->use_replyto = TRUE;
6353 gtk_widget_hide(compose->reply_hbox);
6354 gtk_widget_hide(compose->reply_entry);
6355 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6356 gtk_widget_queue_resize(compose->table_vbox);
6357 compose->use_replyto = FALSE;
6361 static void compose_toggle_followupto_cb(gpointer data, guint action,
6364 Compose *compose = (Compose *)data;
6366 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6367 gtk_widget_show(compose->followup_hbox);
6368 gtk_widget_show(compose->followup_entry);
6369 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6370 compose->use_followupto = TRUE;
6372 gtk_widget_hide(compose->followup_hbox);
6373 gtk_widget_hide(compose->followup_entry);
6374 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6375 gtk_widget_queue_resize(compose->table_vbox);
6376 compose->use_followupto = FALSE;
6380 static void compose_toggle_attach_cb(gpointer data, guint action,
6383 Compose *compose = (Compose *)data;
6385 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6386 gtk_widget_ref(compose->edit_vbox);
6388 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6389 compose->edit_vbox);
6390 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6391 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6393 gtk_widget_show(compose->paned);
6395 gtk_widget_unref(compose->edit_vbox);
6396 gtk_widget_unref(compose->paned);
6398 compose->use_attach = TRUE;
6400 gtk_widget_ref(compose->paned);
6401 gtk_widget_ref(compose->edit_vbox);
6403 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6405 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6406 compose->edit_vbox);
6407 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6408 compose->edit_vbox, TRUE, TRUE, 0);
6410 gtk_widget_unref(compose->edit_vbox);
6412 compose->use_attach = FALSE;
6418 static void compose_toggle_sign_cb(gpointer data, guint action,
6421 Compose *compose = (Compose *)data;
6423 if (GTK_CHECK_MENU_ITEM(widget)->active)
6424 compose->use_signing = TRUE;
6426 compose->use_signing = FALSE;
6429 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6432 Compose *compose = (Compose *)data;
6434 if (GTK_CHECK_MENU_ITEM(widget)->active)
6435 compose->use_encryption = TRUE;
6437 compose->use_encryption = FALSE;
6439 #endif /* USE_GPGME */
6441 static void compose_toggle_ruler_cb(gpointer data, guint action,
6444 Compose *compose = (Compose *)data;
6446 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6447 gtk_widget_show(compose->ruler_hbox);
6448 prefs_common.show_ruler = TRUE;
6450 gtk_widget_hide(compose->ruler_hbox);
6451 gtk_widget_queue_resize(compose->edit_vbox);
6452 prefs_common.show_ruler = FALSE;
6456 static void compose_attach_drag_received_cb (GtkWidget *widget,
6457 GdkDragContext *drag_context,
6460 GtkSelectionData *data,
6465 Compose *compose = (Compose *)user_data;
6468 list = uri_list_extract_filenames((const gchar *)data->data);
6469 for (tmp = list; tmp != NULL; tmp = tmp->next)
6470 compose_attach_append(compose, (const gchar *)tmp->data,
6472 list_free_strings(list);
6476 static void compose_insert_drag_received_cb (GtkWidget *widget,
6477 GdkDragContext *drag_context,
6480 GtkSelectionData *data,
6485 Compose *compose = (Compose *)user_data;
6488 list = uri_list_extract_filenames((const gchar *)data->data);
6489 for (tmp = list; tmp != NULL; tmp = tmp->next)
6490 compose_insert_file(compose, (const gchar *)tmp->data);
6491 list_free_strings(list);
6495 #if 0 /* NEW COMPOSE GUI */
6496 static void to_activated(GtkWidget *widget, Compose *compose)
6498 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6499 gtk_widget_grab_focus(compose->newsgroups_entry);
6501 gtk_widget_grab_focus(compose->subject_entry);
6504 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6506 gtk_widget_grab_focus(compose->subject_entry);
6509 static void subject_activated(GtkWidget *widget, Compose *compose)
6511 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6512 gtk_widget_grab_focus(compose->cc_entry);
6513 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6514 gtk_widget_grab_focus(compose->bcc_entry);
6515 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6516 gtk_widget_grab_focus(compose->reply_entry);
6517 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6518 gtk_widget_grab_focus(compose->followup_entry);
6520 gtk_widget_grab_focus(compose->text);
6523 static void cc_activated(GtkWidget *widget, Compose *compose)
6525 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6526 gtk_widget_grab_focus(compose->bcc_entry);
6527 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6528 gtk_widget_grab_focus(compose->reply_entry);
6529 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6530 gtk_widget_grab_focus(compose->followup_entry);
6532 gtk_widget_grab_focus(compose->text);
6535 static void bcc_activated(GtkWidget *widget, Compose *compose)
6537 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6538 gtk_widget_grab_focus(compose->reply_entry);
6539 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6540 gtk_widget_grab_focus(compose->followup_entry);
6542 gtk_widget_grab_focus(compose->text);
6545 static void replyto_activated(GtkWidget *widget, Compose *compose)
6547 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6548 gtk_widget_grab_focus(compose->followup_entry);
6550 gtk_widget_grab_focus(compose->text);
6553 static void followupto_activated(GtkWidget *widget, Compose *compose)
6555 gtk_widget_grab_focus(compose->text);
6559 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6562 Compose *compose = (Compose *)data;
6564 if (GTK_CHECK_MENU_ITEM(widget)->active)
6565 compose->return_receipt = TRUE;
6567 compose->return_receipt = FALSE;
6570 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6572 ComposeHeaderEntry *headerentry)
6574 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6575 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6576 !(event->state & GDK_MODIFIER_MASK) &&
6577 (event->keyval == GDK_BackSpace) &&
6578 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6579 gtk_container_remove
6580 (GTK_CONTAINER(headerentry->compose->header_table),
6581 headerentry->combo);
6582 gtk_container_remove
6583 (GTK_CONTAINER(headerentry->compose->header_table),
6584 headerentry->entry);
6585 headerentry->compose->header_list =
6586 g_slist_remove(headerentry->compose->header_list,
6588 g_free(headerentry);
6589 } else if (event->keyval == GDK_Tab) {
6590 if (headerentry->compose->header_last == headerentry) {
6591 /* Override default next focus, and give it to subject_entry
6592 * instead of notebook tabs
6594 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6595 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6601 void compose_headerentry_changed_cb(GtkWidget *entry,
6602 ComposeHeaderEntry *headerentry)
6604 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6605 headerentry->compose->header_list =
6606 g_slist_append(headerentry->compose->header_list,
6608 compose_create_header_entry(headerentry->compose);
6609 gtk_signal_disconnect_by_func
6611 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6613 /* Automatically scroll down */
6614 compose_show_first_last_header(headerentry->compose, FALSE);
6619 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6621 GtkAdjustment *vadj;
6623 g_return_if_fail(compose);
6624 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6625 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6627 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6628 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6631 static void text_activated(GtkWidget *widget, Compose *compose)
6633 compose_send_control_enter(compose);
6636 static gboolean compose_send_control_enter(Compose *compose)
6640 GtkItemFactory *ifactory;
6641 GtkAccelEntry *accel;
6642 GtkWidget *send_menu;
6645 ev = gtk_get_current_event();
6646 if (ev->type != GDK_KEY_PRESS) return FALSE;
6648 kev = (GdkEventKey *)ev;
6649 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6652 ifactory = gtk_item_factory_from_widget(compose->menubar);
6653 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6654 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6655 accel = (GtkAccelEntry *)list->data;
6656 if (accel->accelerator_key == kev->keyval &&
6657 accel->accelerator_mods == kev->state) {
6658 compose_send_cb(compose, 0, NULL);
6666 static void compose_check_all(Compose *compose)
6668 if (compose->gtkpspell)
6669 gtkpspell_check_all(compose->gtkpspell);
6672 static void compose_highlight_all(Compose *compose)
6674 if (compose->gtkpspell)
6675 gtkpspell_highlight_all(compose->gtkpspell);
6678 static void compose_check_backwards(Compose *compose)
6680 if (compose->gtkpspell)
6681 gtkpspell_check_backwards(compose->gtkpspell);
6683 GtkItemFactory *ifactory;
6684 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6685 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6686 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6690 static void compose_check_forwards_go(Compose *compose)
6692 if (compose->gtkpspell)
6693 gtkpspell_check_forwards_go(compose->gtkpspell);
6695 GtkItemFactory *ifactory;
6696 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6697 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6698 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);