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 to end of line"),
557 compose_gtk_stext_action_cb,
558 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
560 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
561 {N_("/_Edit/_Wrap current paragraph"),
562 "<control>L", compose_wrap_line, 0, NULL},
563 {N_("/_Edit/Wrap all long _lines"),
564 "<control><alt>L", compose_wrap_line_all, 0, NULL},
565 {N_("/_Edit/Edit with e_xternal editor"),
566 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
568 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
569 {N_("/_Spelling/_Check all or check selection"),
570 NULL, compose_check_all, 0, NULL},
571 {N_("/_Spelling/_Highlight all misspelled words"),
572 NULL, compose_highlight_all, 0, NULL},
573 {N_("/_Spelling/Check _backwards misspelled word"),
574 NULL, compose_check_backwards , 0, NULL},
575 {N_("/_Spelling/_Forward to next misspelled word"),
576 NULL, compose_check_forwards_go, 0, NULL},
577 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
578 {N_("/_Spelling/_Spelling Configuration"),
579 NULL, NULL, 0, "<Branch>"},
581 #if 0 /* NEW COMPOSE GUI */
582 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
583 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
584 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
585 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
586 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
587 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
588 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
589 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
590 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
591 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
592 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
594 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
595 {N_("/_Message/_Send"), "<control>Return",
596 compose_send_cb, 0, NULL},
597 {N_("/_Message/Send _later"), "<shift><control>S",
598 compose_send_later_cb, 0, NULL},
599 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
600 {N_("/_Message/Save to _draft folder"),
601 "<shift><control>D", compose_draft_cb, 0, NULL},
602 {N_("/_Message/Save and _keep editing"),
603 "<control>S", compose_draft_cb, 1, NULL},
604 #if 0 /* NEW COMPOSE GUI */
605 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
606 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
607 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
608 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
609 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
610 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
611 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
612 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
613 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
616 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
617 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
618 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
619 #endif /* USE_GPGME */
620 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
621 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
622 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
623 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
624 {N_("/_Tool/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
625 {N_("/_Tool/_Template"), NULL, NULL, 0, "<Branch>"},
626 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
627 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
630 static GtkTargetEntry compose_mime_types[] =
632 {"text/uri-list", 0, 0}
635 Compose *compose_new(PrefsAccount *account)
637 return compose_generic_new(account, NULL, NULL);
640 Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
644 GtkItemFactory *ifactory;
646 c = compose_generic_new(account, NULL, NULL);
648 filename = procmsg_get_message_file(msginfo);
649 if (filename == NULL)
652 c->bounce_filename = filename;
654 if (msginfo->subject)
655 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
657 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
659 compose_quote_fmt(c, msginfo, "%M", NULL);
660 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
662 ifactory = gtk_item_factory_from_widget(c->popupmenu);
663 menu_set_sensitive(ifactory, "/Add...", FALSE);
664 menu_set_sensitive(ifactory, "/Remove", FALSE);
665 menu_set_sensitive(ifactory, "/Property...", FALSE);
667 ifactory = gtk_item_factory_from_widget(c->menubar);
668 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
669 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
670 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
671 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
672 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
673 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
674 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
675 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
677 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
678 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
680 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
681 menu_set_sensitive(ifactory, "/Tool/Template", FALSE);
683 gtk_widget_set_sensitive(c->insert_btn, FALSE);
684 gtk_widget_set_sensitive(c->attach_btn, FALSE);
685 gtk_widget_set_sensitive(c->sig_btn, FALSE);
686 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
687 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
692 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
694 return compose_generic_new(account, mailto, NULL);
697 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
699 return compose_generic_new(account, NULL, item);
702 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
706 if (item && item->prefs && item->prefs->enable_default_account)
707 account = account_find_from_id(item->prefs->default_account);
709 if (!account) account = cur_account;
710 g_return_val_if_fail(account != NULL, NULL);
712 compose = compose_create(account, COMPOSE_NEW);
713 compose->replyinfo = NULL;
715 if (prefs_common.auto_sig)
716 compose_insert_sig(compose);
717 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
718 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
720 if (account->protocol != A_NNTP) {
722 compose_entries_set(compose, mailto);
724 } else if(item && item->prefs->enable_default_to) {
725 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
727 if (item && item->ret_rcpt) {
728 GtkItemFactory *ifactory;
730 ifactory = gtk_item_factory_from_widget(compose->menubar);
731 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
735 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
738 compose_show_first_last_header(compose, TRUE);
740 /* Set save folder */
741 if(item && item->prefs && item->prefs->save_copy_to_folder) {
742 gchar *folderidentifier;
744 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
745 folderidentifier = folder_item_get_identifier(item);
746 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
747 g_free(folderidentifier);
750 gtk_widget_grab_focus(compose->header_last->entry);
752 if (prefs_common.auto_exteditor)
753 compose_exec_ext_editor(compose);
758 #define CHANGE_FLAGS(msginfo) \
760 if (msginfo->folder->folder->change_flags != NULL) \
761 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
767 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
768 const gchar *followupto, gchar * to)
772 if (!account) account = cur_account;
773 g_return_val_if_fail(account != NULL, NULL);
774 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
776 compose = compose_create(account, COMPOSE_NEW);
778 if (prefs_common.auto_sig)
779 compose_insert_sig(compose);
780 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
781 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
783 compose_entry_append(compose, to, COMPOSE_TO);
784 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
785 gtk_widget_grab_focus(compose->subject_entry);
791 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
792 gboolean ignore_replyto)
794 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
797 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
799 gboolean ignore_replyto)
801 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
804 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
806 gboolean ignore_replyto,
807 gboolean followup_and_reply_to)
810 PrefsAccount *account;
811 PrefsAccount *reply_account;
814 g_return_if_fail(msginfo != NULL);
815 g_return_if_fail(msginfo->folder != NULL);
818 /* select the account set in folderitem's property (if enabled) */
819 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
820 account = account_find_from_id(msginfo->folder->prefs->default_account);
822 /* select the account for the whole folder (IMAP / NNTP) */
824 /* FIXME: this is not right, because folder may be nested. we should
825 * ascend the tree until we find a parent with proper account
827 account = msginfo->folder->folder->account;
829 /* select account by to: and cc: header if enabled */
830 if (prefs_common.reply_account_autosel) {
831 if (!account && msginfo->to) {
833 Xstrdup_a(to, msginfo->to, return);
835 account = account_find_from_address(to);
839 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
841 account = account_find_from_address(cc);
846 /* select current account */
847 if (!account) account = cur_account;
848 g_return_if_fail(account != NULL);
850 if (ignore_replyto && account->protocol == A_NNTP &&
851 !followup_and_reply_to) {
853 account_find_from_address(account->address);
855 reply_account = compose_current_mail_account();
859 reply_account = account;
861 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
862 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
863 if (MSG_IS_IMAP(msginfo->flags))
864 imap_msg_set_perm_flags(msginfo, MSG_REPLIED);
865 CHANGE_FLAGS(msginfo);
867 compose = compose_create(account, COMPOSE_REPLY);
868 compose->replyinfo = procmsg_msginfo_copy(msginfo);
870 #if 0 /* NEW COMPOSE GUI */
871 if (followup_and_reply_to) {
872 gtk_widget_show(compose->to_hbox);
873 gtk_widget_show(compose->to_entry);
874 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
875 compose->use_to = TRUE;
878 if (msginfo->folder && msginfo->folder->ret_rcpt) {
879 GtkItemFactory *ifactory;
881 ifactory = gtk_item_factory_from_widget(compose->menubar);
882 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
885 /* Set save folder */
886 if(msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
887 gchar *folderidentifier;
889 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
890 folderidentifier = folder_item_get_identifier(msginfo->folder);
891 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
892 g_free(folderidentifier);
895 if (compose_parse_header(compose, msginfo) < 0) return;
896 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
897 followup_and_reply_to);
898 compose_show_first_last_header(compose, TRUE);
900 text = GTK_STEXT(compose->text);
901 gtk_stext_freeze(text);
907 if (prefs_common.quotemark && *prefs_common.quotemark)
908 qmark = prefs_common.quotemark;
912 quote_str = compose_quote_fmt(compose, msginfo,
913 prefs_common.quotefmt,
917 if (prefs_common.auto_sig)
918 compose_insert_sig(compose);
920 if (quote && prefs_common.linewrap_quote)
921 compose_wrap_line_all(compose);
923 gtk_editable_set_position(GTK_EDITABLE(text), 0);
924 gtk_stext_set_point(text, 0);
926 gtk_stext_thaw(text);
927 gtk_widget_grab_focus(compose->text);
929 if (prefs_common.auto_exteditor)
930 compose_exec_ext_editor(compose);
934 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
939 g_return_val_if_fail(mimeinfo != NULL, NULL);
941 base = mimeinfo->filename ? mimeinfo->filename
942 : mimeinfo->name ? mimeinfo->name : NULL;
944 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
945 filename = g_strdup_printf("%s%smimetmp.%08x.html",
952 base = base ? base : "";
953 base = g_basename(base);
955 filename = g_strdup_printf("%s%smimetmp.%08x",
963 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
969 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
973 if (!partinfo) return NULL;
975 filename = procmime_get_file_name(partinfo);
977 if (procmime_get_part(filename, source, partinfo) < 0)
979 (_("Can't get the part of multipart message."));
984 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
992 gint boundary_len = 0;
994 glong fpos, prev_fpos;
999 g_return_if_fail(msginfo != NULL);
1003 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
1004 mimeinfo = procmime_scan_mime_header(fp, MIME_TEXT);
1005 if (!mimeinfo) break;
1007 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
1008 rfc2015_is_encrypted(mimeinfo)) {
1009 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
1011 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
1012 !msginfo->plaintext_file &&
1013 !msginfo->decryption_failed) {
1014 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
1015 if (msginfo->plaintext_file &&
1016 !msginfo->decryption_failed) {
1024 #else /* !USE_GPGME */
1025 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
1026 mimeinfo = procmime_scan_mime_header(fp, MIME_TEXT);
1027 #endif /* USE_GPGME */
1030 if (!mimeinfo) return;
1031 if (mimeinfo->mime_type == MIME_TEXT)
1034 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
1036 g_return_if_fail(mimeinfo != NULL);
1037 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
1039 if (mimeinfo->mime_type == MIME_MULTIPART) {
1040 g_return_if_fail(mimeinfo->boundary != NULL);
1041 g_return_if_fail(mimeinfo->sub == NULL);
1043 g_return_if_fail(fp != NULL);
1045 boundary = mimeinfo->boundary;
1048 boundary_len = strlen(boundary);
1050 /* look for first boundary */
1051 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
1052 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
1059 if ((fpos = ftell(fp)) < 0) {
1065 for (npart = 0;; npart++) {
1067 gboolean eom = FALSE;
1071 partinfo = procmime_scan_mime_header(fp, MIME_TEXT);
1072 if (!partinfo) break;
1075 procmime_mimeinfo_insert(mimeinfo, partinfo);
1077 procmime_mimeinfo_free(partinfo);
1079 /* look for next boundary */
1081 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
1082 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
1083 if (buf[2 + boundary_len] == '-' &&
1084 buf[2 + boundary_len + 1] == '-')
1090 eom = TRUE; /* broken MIME message */
1093 partinfo->size = fpos - prev_fpos - strlen(buf);
1098 source = procmsg_get_message_file_path(msginfo);
1100 g_return_if_fail(mimeinfo != NULL);
1102 if (!mimeinfo->main && mimeinfo->parent)
1104 filename = mime_extract_file(source, mimeinfo);
1106 compose_attach_append_with_type(compose, filename,
1107 mimeinfo->content_type,
1108 mimeinfo->mime_type);
1113 if (mimeinfo->sub && mimeinfo->sub->children)
1115 filename = mime_extract_file(source, mimeinfo->sub);
1117 compose_attach_append_with_type(compose, filename,
1118 mimeinfo->content_type,
1119 mimeinfo->sub->mime_type);
1124 if (mimeinfo->children) {
1127 child = mimeinfo->children;
1129 filename = mime_extract_file(source, child);
1131 compose_attach_append_with_type(compose, filename,
1132 child->content_type,
1137 child = child->next;
1143 procmime_mimeinfo_free_all(mimeinfo);
1147 #define INSERT_FW_HEADER(var, hdr) \
1148 if (msginfo->var && *msginfo->var) { \
1149 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1150 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1151 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1154 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1158 /* PrefsAccount *account; */
1161 g_return_val_if_fail(msginfo != NULL, NULL);
1162 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1164 account = msginfo->folder->folder->account;
1165 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1167 Xstrdup_a(to, msginfo->to, return NULL);
1168 extract_address(to);
1169 account = account_find_from_address(to);
1172 if(!account && prefs_common.forward_account_autosel) {
1174 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1175 extract_address(cc);
1176 account = account_find_from_address(cc);
1180 if (account == NULL) {
1181 account = cur_account;
1183 account = msginfo->folder->folder->account;
1184 if (!account) account = cur_account;
1187 g_return_val_if_fail(account != NULL, NULL);
1189 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1190 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1191 if (MSG_IS_IMAP(msginfo->flags))
1192 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1193 CHANGE_FLAGS(msginfo);
1195 compose = compose_create(account, COMPOSE_FORWARD);
1197 if (msginfo->subject && *msginfo->subject) {
1198 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1199 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1203 text = GTK_STEXT(compose->text);
1204 gtk_stext_freeze(text);
1209 msgfile = procmsg_get_message_file_path(msginfo);
1210 if (!is_file_exist(msgfile))
1211 g_warning(_("%s: file not exist\n"), msgfile);
1213 compose_attach_append(compose, msgfile,
1214 MIME_MESSAGE_RFC822);
1221 if (prefs_common.fw_quotemark && *prefs_common.fw_quotemark)
1222 qmark = prefs_common.fw_quotemark;
1226 quote_str = compose_quote_fmt(compose, msginfo,
1227 prefs_common.fw_quotefmt, qmark);
1228 compose_attach_parts(compose, msginfo);
1231 if (prefs_common.auto_sig)
1232 compose_insert_sig(compose);
1234 if (prefs_common.linewrap_quote)
1235 compose_wrap_line_all(compose);
1237 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1238 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1240 gtk_stext_thaw(text);
1241 #if 0 /* NEW COMPOSE GUI */
1242 if (account->protocol != A_NNTP)
1243 gtk_widget_grab_focus(compose->to_entry);
1245 gtk_widget_grab_focus(compose->newsgroups_entry);
1247 gtk_widget_grab_focus(compose->header_last->entry);
1249 if (prefs_common.auto_exteditor)
1250 compose_exec_ext_editor(compose);
1255 #undef INSERT_FW_HEADER
1257 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1264 g_return_val_if_fail(msginfo_list != NULL, NULL);
1266 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1267 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1271 if (account == NULL) {
1272 account = cur_account;
1274 account = msginfo->folder->folder->account;
1275 if (!account) account = cur_account;
1278 g_return_val_if_fail(account != NULL, NULL);
1280 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1281 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1282 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1283 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1286 compose = compose_create(account, COMPOSE_FORWARD);
1288 text = GTK_STEXT(compose->text);
1289 gtk_stext_freeze(text);
1291 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1292 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1293 if (!is_file_exist(msgfile))
1294 g_warning(_("%s: file not exist\n"), msgfile);
1296 compose_attach_append(compose, msgfile,
1297 MIME_MESSAGE_RFC822);
1301 if (prefs_common.auto_sig)
1302 compose_insert_sig(compose);
1304 if (prefs_common.linewrap_quote)
1305 compose_wrap_line_all(compose);
1307 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1308 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1310 gtk_stext_thaw(text);
1311 #if 0 /* NEW COMPOSE GUI */
1312 if (account->protocol != A_NNTP)
1313 gtk_widget_grab_focus(compose->to_entry);
1315 gtk_widget_grab_focus(compose->newsgroups_entry);
1321 void compose_reedit(MsgInfo *msginfo)
1324 PrefsAccount *account = NULL;
1327 gchar buf[BUFFSIZE];
1329 g_return_if_fail(msginfo != NULL);
1330 g_return_if_fail(msginfo->folder != NULL);
1332 if (msginfo->folder->stype == F_QUEUE) {
1333 gchar queueheader_buf[BUFFSIZE];
1336 /* Select Account from queue headers */
1337 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1338 sizeof(queueheader_buf), "NAID:")) {
1339 id = atoi(&queueheader_buf[5]);
1340 account = account_find_from_id(id);
1342 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1343 sizeof(queueheader_buf), "MAID:")) {
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), "S:")) {
1349 account = account_find_from_address(queueheader_buf);
1352 account = msginfo->folder->folder->account;
1354 if (!account && prefs_common.reedit_account_autosel) {
1355 gchar from[BUFFSIZE];
1356 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1357 extract_address(from);
1358 account = account_find_from_address(from);
1361 if (!account) account = cur_account;
1362 g_return_if_fail(account != NULL);
1364 compose = compose_create(account, COMPOSE_REEDIT);
1365 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1367 if (msginfo->folder->stype == F_QUEUE) {
1368 gchar queueheader_buf[BUFFSIZE];
1370 /* Set message save folder */
1371 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1374 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1375 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1376 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1380 if (compose_parse_header(compose, msginfo) < 0) return;
1381 compose_reedit_set_entry(compose, msginfo);
1383 text = GTK_STEXT(compose->text);
1384 gtk_stext_freeze(text);
1386 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1387 g_warning(_("Can't get text part\n"));
1389 while (fgets(buf, sizeof(buf), fp) != NULL)
1390 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1393 compose_attach_parts(compose, msginfo);
1395 gtk_stext_thaw(text);
1396 gtk_widget_grab_focus(compose->text);
1398 if (prefs_common.auto_exteditor)
1399 compose_exec_ext_editor(compose);
1402 GList *compose_get_compose_list(void)
1404 return compose_list;
1407 void compose_entry_append(Compose *compose, const gchar *address,
1408 ComposeEntryType type)
1414 if (!address || *address == '\0') return;
1416 #if 0 /* NEW COMPOSE GUI */
1419 entry = GTK_ENTRY(compose->cc_entry);
1422 entry = GTK_ENTRY(compose->bcc_entry);
1424 case COMPOSE_NEWSGROUPS:
1425 entry = GTK_ENTRY(compose->newsgroups_entry);
1429 entry = GTK_ENTRY(compose->to_entry);
1433 text = gtk_entry_get_text(entry);
1435 gtk_entry_append_text(entry, ", ");
1436 gtk_entry_append_text(entry, address);
1444 header = N_("Bcc:");
1446 case COMPOSE_REPLYTO:
1447 header = N_("Reply-To:");
1449 case COMPOSE_NEWSGROUPS:
1450 header = N_("Newsgroups:");
1452 case COMPOSE_FOLLOWUPTO:
1453 header = N_( "Followup-To:");
1460 header = prefs_common.trans_hdr ? gettext(header) : header;
1462 compose_add_header_entry(compose, header, (gchar *)address);
1465 static void compose_entries_set(Compose *compose, const gchar *mailto)
1467 gchar *subject = NULL;
1475 Xstrdup_a(tmp_mailto, mailto, return);
1479 p = strchr(tmp_mailto, '?');
1486 gchar *field, *value;
1503 if (*value == '\0') continue;
1505 if (!g_strcasecmp(field, "subject")) {
1506 Xalloca(subject, strlen(value) + 1, return);
1507 decode_uri(subject, value);
1508 } else if (!g_strcasecmp(field, "cc")) {
1510 } else if (!g_strcasecmp(field, "bcc")) {
1512 } else if (!g_strcasecmp(field, "body")) {
1513 Xalloca(body, strlen(value) + 1, return);
1514 decode_uri(body, value);
1519 compose_entry_append(compose, to, COMPOSE_TO);
1521 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1523 compose_entry_append(compose, cc, COMPOSE_CC);
1525 compose_entry_append(compose, bcc, COMPOSE_BCC);
1527 gtk_stext_insert(GTK_STEXT(compose->text),
1528 NULL, NULL, NULL, body, -1);
1529 gtk_stext_insert(GTK_STEXT(compose->text),
1530 NULL, NULL, NULL, "\n", 1);
1534 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1536 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1537 {"Cc:", NULL, FALSE},
1538 {"References:", NULL, FALSE},
1539 {"Bcc:", NULL, FALSE},
1540 {"Newsgroups:", NULL, FALSE},
1541 {"Followup-To:", NULL, FALSE},
1542 {"X-Mailing-List:", NULL, FALSE},
1543 {"X-BeenThere:", NULL, FALSE},
1544 {NULL, NULL, FALSE}};
1554 H_X_MAILING_LIST = 6,
1560 g_return_val_if_fail(msginfo != NULL, -1);
1562 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1563 procheader_get_header_fields(fp, hentry);
1566 if (hentry[H_REPLY_TO].body != NULL) {
1567 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1568 compose->replyto = hentry[H_REPLY_TO].body;
1569 hentry[H_REPLY_TO].body = NULL;
1571 if (hentry[H_CC].body != NULL) {
1572 conv_unmime_header_overwrite(hentry[H_CC].body);
1573 compose->cc = hentry[H_CC].body;
1574 hentry[H_CC].body = NULL;
1576 if (hentry[H_X_MAILING_LIST].body != NULL) {
1577 /* this is good enough to parse debian-devel */
1578 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1579 g_return_val_if_fail(buf != NULL, -1 );
1580 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1581 compose->mailinglist = g_strdup(buf);
1583 g_free(hentry[H_X_MAILING_LIST].body);
1584 hentry[H_X_MAILING_LIST].body = NULL ;
1586 if (hentry[H_X_BEENTHERE].body != NULL) {
1587 /* this is good enough to parse the sylpheed-claws lists */
1588 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1589 g_return_val_if_fail(buf != NULL, -1 );
1590 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1591 compose->mailinglist = g_strdup(buf);
1593 g_free(hentry[H_X_BEENTHERE].body);
1594 hentry[H_X_BEENTHERE].body = NULL ;
1596 if (hentry[H_REFERENCES].body != NULL) {
1597 if (compose->mode == COMPOSE_REEDIT)
1598 compose->references = hentry[H_REFERENCES].body;
1600 compose->references = compose_parse_references
1601 (hentry[H_REFERENCES].body, msginfo->msgid);
1602 g_free(hentry[H_REFERENCES].body);
1604 hentry[H_REFERENCES].body = NULL;
1606 if (hentry[H_BCC].body != NULL) {
1607 if (compose->mode == COMPOSE_REEDIT) {
1608 conv_unmime_header_overwrite(hentry[H_BCC].body);
1609 compose->bcc = hentry[H_BCC].body;
1611 g_free(hentry[H_BCC].body);
1612 hentry[H_BCC].body = NULL;
1614 if (hentry[H_NEWSGROUPS].body != NULL) {
1615 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1616 hentry[H_NEWSGROUPS].body = NULL;
1618 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1619 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1620 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1621 hentry[H_FOLLOWUP_TO].body = NULL;
1624 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1625 compose->inreplyto = g_strdup(msginfo->inreplyto);
1626 else if (compose->mode != COMPOSE_REEDIT &&
1627 msginfo->msgid && *msginfo->msgid) {
1628 compose->inreplyto = g_strdup(msginfo->msgid);
1630 if (!compose->references) {
1631 if (msginfo->inreplyto && *msginfo->inreplyto)
1632 compose->references =
1633 g_strdup_printf("<%s>\n\t<%s>",
1637 compose->references =
1638 g_strconcat("<", msginfo->msgid, ">",
1646 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1648 GSList *ref_id_list, *cur;
1652 ref_id_list = references_list_append(NULL, ref);
1653 if (!ref_id_list) return NULL;
1654 if (msgid && *msgid)
1655 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1660 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1661 /* "<" + Message-ID + ">" + CR+LF+TAB */
1662 len += strlen((gchar *)cur->data) + 5;
1664 if (len > MAX_REFERENCES_LEN) {
1665 /* remove second message-ID */
1666 if (ref_id_list && ref_id_list->next &&
1667 ref_id_list->next->next) {
1668 g_free(ref_id_list->next->data);
1669 ref_id_list = g_slist_remove
1670 (ref_id_list, ref_id_list->next->data);
1672 slist_free_strings(ref_id_list);
1673 g_slist_free(ref_id_list);
1680 new_ref = g_string_new("");
1681 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1682 if (new_ref->len > 0)
1683 g_string_append(new_ref, "\n\t");
1684 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1687 slist_free_strings(ref_id_list);
1688 g_slist_free(ref_id_list);
1690 new_ref_str = new_ref->str;
1691 g_string_free(new_ref, FALSE);
1696 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1697 const gchar *fmt, const gchar *qmark)
1699 GtkSText *text = GTK_STEXT(compose->text);
1700 gchar *quote_str = NULL;
1705 if (qmark != NULL) {
1706 quote_fmt_init(msginfo, NULL);
1707 quote_fmt_scan_string(qmark);
1710 buf = quote_fmt_get_buffer();
1712 alertpanel_error(_("Quote mark format error."));
1714 Xstrdup_a(quote_str, buf, return NULL)
1717 if (fmt && *fmt != '\0') {
1718 quote_fmt_init(msginfo, quote_str);
1719 quote_fmt_scan_string(fmt);
1722 buf = quote_fmt_get_buffer();
1724 alertpanel_error(_("Message reply/forward format error."));
1730 gtk_stext_freeze(text);
1732 for (p = buf; *p != '\0'; ) {
1733 lastp = strchr(p, '\n');
1734 len = lastp ? lastp - p + 1 : -1;
1735 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1742 gtk_stext_thaw(text);
1747 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1748 gboolean to_all, gboolean ignore_replyto,
1749 gboolean followup_and_reply_to)
1754 GHashTable *to_table;
1756 g_return_if_fail(compose->account != NULL);
1757 g_return_if_fail(msginfo != NULL);
1759 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1760 compose_entry_append(compose,
1761 ((compose->replyto && !ignore_replyto)
1763 : (compose->mailinglist && !ignore_replyto)
1764 ? compose->mailinglist
1765 : msginfo->from ? msginfo->from : ""),
1767 if (compose->account->protocol == A_NNTP) {
1769 compose_entry_append
1770 (compose, msginfo->from ? msginfo->from : "",
1773 compose_entry_append
1775 compose->followup_to ? compose->followup_to
1776 : compose->newsgroups ? compose->newsgroups
1778 COMPOSE_NEWSGROUPS);
1781 if (msginfo->subject && *msginfo->subject) {
1782 gchar *buf, *buf2, *p;
1784 buf = g_strdup(msginfo->subject);
1785 while (!strncasecmp(buf, "Re:", 3)) {
1787 while (isspace(*p)) p++;
1788 memmove(buf, p, strlen(p) + 1);
1791 buf2 = g_strdup_printf("Re: %s", buf);
1792 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1796 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1798 if (!to_all || compose->account->protocol == A_NNTP) return;
1800 from = g_strdup(compose->replyto ? compose->replyto :
1801 msginfo->from ? msginfo->from : "");
1802 extract_address(from);
1804 cc_list = address_list_append(NULL, msginfo->to);
1805 cc_list = address_list_append(cc_list, compose->cc);
1807 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1808 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1809 if (compose->account)
1810 g_hash_table_insert(to_table, compose->account->address,
1811 GINT_TO_POINTER(1));
1813 /* remove address on To: and that of current account */
1814 for (cur = cc_list; cur != NULL; ) {
1815 GSList *next = cur->next;
1817 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1818 cc_list = g_slist_remove(cc_list, cur->data);
1820 g_hash_table_insert(to_table, cur->data, cur);
1824 g_hash_table_destroy(to_table);
1828 for (cur = cc_list; cur != NULL; cur = cur->next)
1829 compose_entry_append(compose, (gchar *)cur->data,
1831 slist_free_strings(cc_list);
1832 g_slist_free(cc_list);
1836 #define SET_ENTRY(entry, str) \
1839 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1842 #define SET_ADDRESS(type, str) \
1845 compose_entry_append(compose, str, type); \
1848 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1850 g_return_if_fail(msginfo != NULL);
1852 SET_ENTRY(subject_entry, msginfo->subject);
1853 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1854 SET_ADDRESS(COMPOSE_CC, compose->cc);
1855 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1856 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1858 compose_show_first_last_header(compose, TRUE);
1860 #if 0 /* NEW COMPOSE GUI */
1862 GtkItemFactory *ifactory;
1863 GtkWidget *menuitem;
1865 ifactory = gtk_item_factory_from_widget(compose->menubar);
1866 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1867 gtk_check_menu_item_set_active
1868 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1870 if (compose->replyto) {
1871 GtkItemFactory *ifactory;
1872 GtkWidget *menuitem;
1874 ifactory = gtk_item_factory_from_widget(compose->menubar);
1875 menuitem = gtk_item_factory_get_item
1876 (ifactory, "/View/Reply to");
1877 gtk_check_menu_item_set_active
1878 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1886 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1893 size_t buf_len = 128;
1895 if (strlen(sigfile) < 2)
1898 sigprg = popen(sigfile+1, "r");
1901 buf = g_malloc(buf_len);
1904 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1905 "Unable to insert signature (malloc failed)\n", -1);
1911 while (!feof(sigprg)) {
1912 bzero(buf, buf_len);
1913 fread(buf, buf_len-1, 1, sigprg);
1914 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1922 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1923 "Can't exec file: ", -1);
1924 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1929 static void compose_insert_sig(Compose *compose)
1933 if (compose->account && compose->account->sig_path)
1934 sigfile = g_strdup(compose->account->sig_path);
1936 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1937 DEFAULT_SIGNATURE, NULL);
1939 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1944 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1945 if (prefs_common.sig_sep) {
1946 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1947 prefs_common.sig_sep, -1);
1948 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1952 if (sigfile[0] == '|')
1953 compose_exec_sig(compose, sigfile);
1955 compose_insert_file(compose, sigfile);
1959 static void compose_insert_file(Compose *compose, const gchar *file)
1961 GtkSText *text = GTK_STEXT(compose->text);
1962 gchar buf[BUFFSIZE];
1966 g_return_if_fail(file != NULL);
1968 if ((fp = fopen(file, "r")) == NULL) {
1969 FILE_OP_ERROR(file, "fopen");
1973 gtk_stext_freeze(text);
1975 while (fgets(buf, sizeof(buf), fp) != NULL) {
1976 /* strip <CR> if DOS/Windows file,
1977 replace <CR> with <LF> if Macintosh file. */
1980 if (len > 0 && buf[len - 1] != '\n') {
1982 if (buf[len] == '\r') buf[len] = '\n';
1984 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1987 gtk_stext_thaw(text);
1992 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1993 ContentType cnttype)
1995 gchar *text[N_ATTACH_COLS];
1998 text[COL_MIMETYPE] = ainfo->content_type;
1999 text[COL_SIZE] = to_human_readable(ainfo->size);
2000 text[COL_NAME] = ainfo->name;
2002 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2003 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2005 if (cnttype != MIME_MESSAGE_RFC822)
2006 compose_changed_cb(NULL, compose);
2009 static void compose_attach_append_with_type(Compose *compose,
2012 ContentType cnttype)
2017 if (!is_file_exist(file)) {
2018 g_warning(_("File %s doesn't exist\n"), file);
2021 if ((size = get_file_size(file)) < 0) {
2022 g_warning(_("Can't get file size of %s\n"), file);
2026 alertpanel_notice(_("File %s is empty\n"), file);
2029 #if 0 /* NEW COMPOSE GUI */
2030 if (!compose->use_attach) {
2031 GtkItemFactory *ifactory;
2032 GtkWidget *menuitem;
2034 ifactory = gtk_item_factory_from_widget(compose->menubar);
2035 menuitem = gtk_item_factory_get_item(ifactory,
2037 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2041 ainfo = g_new0(AttachInfo, 1);
2042 ainfo->file = g_strdup(file);
2044 if (cnttype == MIME_MESSAGE_RFC822) {
2045 ainfo->encoding = ENC_7BIT;
2046 ainfo->name = g_strdup_printf(_("Message: %s"),
2049 ainfo->encoding = ENC_BASE64;
2050 ainfo->name = g_strdup(g_basename(file));
2053 ainfo->content_type = g_strdup(type);
2056 compose_attach_info(compose, ainfo, cnttype);
2059 static void compose_attach_append(Compose *compose, const gchar *file,
2060 ContentType cnttype)
2063 gchar *text[N_ATTACH_COLS];
2067 if (!is_file_exist(file)) {
2068 g_warning(_("File %s doesn't exist\n"), file);
2071 if ((size = get_file_size(file)) < 0) {
2072 g_warning(_("Can't get file size of %s\n"), file);
2076 alertpanel_notice(_("File %s is empty\n"), file);
2079 #if 0 /* NEW COMPOSE GUI */
2080 if (!compose->use_attach) {
2081 GtkItemFactory *ifactory;
2082 GtkWidget *menuitem;
2084 ifactory = gtk_item_factory_from_widget(compose->menubar);
2085 menuitem = gtk_item_factory_get_item(ifactory,
2086 "/View/Attachment");
2087 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2091 ainfo = g_new0(AttachInfo, 1);
2092 ainfo->file = g_strdup(file);
2094 if (cnttype == MIME_MESSAGE_RFC822) {
2095 ainfo->content_type = g_strdup("message/rfc822");
2096 ainfo->encoding = ENC_7BIT;
2097 ainfo->name = g_strdup_printf(_("Message: %s"),
2100 ainfo->content_type = procmime_get_mime_type(file);
2101 if (!ainfo->content_type)
2102 ainfo->content_type =
2103 g_strdup("application/octet-stream");
2104 ainfo->encoding = ENC_BASE64;
2105 ainfo->name = g_strdup(g_basename(file));
2109 compose_attach_info(compose, ainfo, cnttype);
2112 #define GET_CHAR(pos, buf, len) \
2114 if (text->use_wchar) \
2115 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2117 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2122 static void compose_wrap_line(Compose *compose)
2124 GtkSText *text = GTK_STEXT(compose->text);
2125 gint ch_len, last_ch_len;
2126 gchar cbuf[MB_LEN_MAX], last_ch;
2130 gint p_start, p_end;
2131 gint line_pos, cur_pos;
2132 gint line_len, cur_len;
2134 gtk_stext_freeze(text);
2136 text_len = gtk_stext_get_length(text);
2138 /* check to see if the point is on the paragraph mark (empty line). */
2139 cur_pos = gtk_stext_get_point(text);
2140 GET_CHAR(cur_pos, cbuf, ch_len);
2141 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2143 goto compose_end; /* on the paragraph mark */
2144 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2145 if (ch_len == 1 && *cbuf == '\n')
2146 goto compose_end; /* on the paragraph mark */
2149 /* find paragraph start. */
2150 line_end = quoted = 0;
2151 for (p_start = cur_pos; p_start >= 0; --p_start) {
2152 GET_CHAR(p_start, cbuf, ch_len);
2153 if (ch_len == 1 && *cbuf == '\n') {
2155 goto compose_end; /* quoted part */
2162 if (ch_len == 1 && strchr(">:#", *cbuf))
2164 else if (ch_len != 1 || !isspace(*cbuf))
2173 /* find paragraph end. */
2175 for (p_end = cur_pos; p_end < text_len; p_end++) {
2176 GET_CHAR(p_end, cbuf, ch_len);
2177 if (ch_len == 1 && *cbuf == '\n') {
2184 if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
2185 goto compose_end; /* quoted part */
2190 if (p_end >= text_len)
2193 if (p_start >= p_end)
2196 line_len = cur_len = 0;
2200 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2203 GET_CHAR(cur_pos, cbuf, ch_len);
2210 if (ch_len == 1 && isspace(*cbuf))
2213 if (ch_len == 1 && *cbuf == '\n') {
2215 if (last_ch_len == 1 && !isspace(last_ch)) {
2216 if (cur_pos + 1 < p_end) {
2217 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2218 if (ch_len == 1 && !isspace(*cbuf))
2222 gtk_stext_set_point(text, cur_pos + 1);
2223 gtk_stext_backward_delete(text, 1);
2225 gtk_stext_set_point(text, cur_pos);
2226 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2236 last_ch_len = ch_len;
2240 line_pos = cur_pos + 1;
2241 line_len = cur_len + ch_len;
2244 if (cur_len + ch_len > prefs_common.linewrap_len &&
2248 GET_CHAR(line_pos - 1, cbuf, ch_len);
2249 if (ch_len == 1 && isspace(*cbuf)) {
2250 gtk_stext_set_point(text, line_pos);
2251 gtk_stext_backward_delete(text, 1);
2260 gtk_stext_set_point(text, line_pos);
2261 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2265 cur_len = cur_len - line_len + ch_len;
2271 line_pos = cur_pos + 1;
2272 line_len = cur_len + ch_len;
2278 gtk_stext_thaw(text);
2281 /* return indent length */
2282 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2284 gint indent_len = 0;
2286 gchar cbuf[MB_LEN_MAX];
2288 for (i = start_pos; i < text_len; i++) {
2289 GET_CHAR(i, cbuf, ch_len);
2292 /* allow space, tab, > or | */
2293 if (cbuf[0] != ' ' && cbuf[0] != '\t' &&
2294 cbuf[0] != '>' && cbuf[0] != '|')
2302 /* insert quotation string when line was wrapped */
2303 static guint ins_quote(GtkSText *text, guint quote_len, guint indent_len,
2304 guint prev_line_pos, guint text_len,
2311 for (i = 0; i < indent_len; i++) {
2312 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2313 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2315 ins_len = indent_len;
2317 gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
2318 ins_len = quote_len;
2326 /* Darko: used when I debug wrapping */
2327 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2332 printf("%d [", pos);
2333 for (i = pos; i < tlen; i++) {
2334 ch = GTK_STEXT_INDEX(text, i);
2335 if (breakoncr && ch == '\n')
2343 static void compose_wrap_line_all(Compose *compose)
2345 GtkSText *text = GTK_STEXT(compose->text);
2347 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2348 gint line_len = 0, cur_len = 0;
2350 gboolean is_new_line = TRUE, do_delete = FALSE;
2351 guint qlen = 0, i_len = 0;
2352 gboolean linewrap_quote = TRUE;
2353 guint linewrap_len = prefs_common.linewrap_len;
2354 gchar *qfmt = prefs_common.quotemark;
2355 gchar cbuf[MB_LEN_MAX];
2357 gtk_stext_freeze(text);
2359 /* make text buffer contiguous */
2360 /* gtk_stext_compact_buffer(text); */
2362 tlen = gtk_stext_get_length(text);
2364 for (; cur_pos < tlen; cur_pos++) {
2365 /* mark position of new line - needed for quotation wrap */
2367 if (linewrap_quote) {
2368 qlen = gtkut_stext_str_compare
2369 (text, cur_pos, tlen, qfmt);
2371 i_len = get_indent_length
2372 (text, cur_pos, tlen);
2376 is_new_line = FALSE;
2379 printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
2380 dump_text(text, p_pos, tlen, 1);
2384 GET_CHAR(cur_pos, cbuf, ch_len);
2386 /* fix line length for tabs */
2387 if (ch_len == 1 && *cbuf == '\t') {
2388 guint tab_width = text->default_tab_width;
2389 guint tab_offset = line_len % tab_width;
2392 printf("found tab at pos=%d line_len=%d ", cur_pos,
2396 line_len += tab_width - tab_offset - 1;
2400 printf("new_len=%d\n", line_len);
2404 /* we have encountered line break */
2405 if (ch_len == 1 && *cbuf == '\n') {
2408 gchar cb[MB_CUR_MAX];
2411 printf("found CR at %d next line is ", cur_pos);
2412 dump_text(text, cur_pos + 1, tlen, 1);
2414 /* if it's just quotation + newline skip it */
2415 if (i_len && (cur_pos + 1 < tlen)) {
2416 /* check if text at new line matches indent */
2417 ilen = gtkut_stext_str_compare_n
2418 (text, cur_pos + 1, p_pos, i_len, tlen);
2419 if (cur_pos + ilen < tlen) {
2420 GET_CHAR(cur_pos + ilen + 1, cb, clen);
2421 /* no need to join the lines */
2422 if (clen == 1 && cb[0] == '\n')
2425 /* if it's just newline skip it */
2426 } else if (do_delete && (cur_pos + 1 < tlen)) {
2427 GET_CHAR(cur_pos + 1, cb, clen);
2428 /* no need to join the lines */
2429 if (clen == 1 && cb[0] == '\n')
2433 /* skip delete if it is continuous URL */
2434 if (do_delete && (line_pos - p_pos <= i_len) &&
2435 gtkut_stext_is_uri_string(text, line_pos, tlen))
2439 printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
2440 qlen, line_len, linewrap_len, do_delete);
2442 /* should we delete to perform smart wrapping */
2443 if (line_len < linewrap_len && do_delete) {
2444 /* get rid of newline */
2445 gtk_stext_set_point(text, cur_pos);
2446 gtk_stext_forward_delete(text, 1);
2449 /* if text starts with quote fmt or with
2450 indent string, delete them */
2452 ilen = gtkut_stext_str_compare_n
2453 (text, cur_pos, p_pos, i_len,
2456 gtk_stext_forward_delete
2461 if (gtkut_stext_str_compare
2462 (text, cur_pos, tlen, qfmt)) {
2463 gtk_stext_forward_delete
2469 GET_CHAR(cur_pos, cb, clen);
2471 /* insert space if it's alphanumeric */
2472 if ((cur_pos != line_pos) &&
2473 ((clen > 1) || isalnum(cb[0]))) {
2474 gtk_stext_insert(text, NULL, NULL,
2476 /* gtk_stext_compact_buffer(text); */
2480 /* and start over with current line */
2481 cur_pos = p_pos - 1;
2483 line_len = cur_len = 0;
2488 printf("after delete l_pos=");
2489 dump_text(text, line_pos, tlen, 1);
2494 /* mark new line beginning */
2495 line_pos = cur_pos + 1;
2496 line_len = cur_len = 0;
2508 /* possible line break */
2509 if (ch_len == 1 && isspace(*cbuf)) {
2510 line_pos = cur_pos + 1;
2511 line_len = cur_len + ch_len;
2514 /* are we over wrapping length set in preferences ? */
2515 if (cur_len + ch_len > linewrap_len) {
2519 printf("should wrap cur_pos=%d ", cur_pos);
2520 dump_text(text, p_pos, tlen, 1);
2521 dump_text(text, line_pos, tlen, 1);
2523 /* force wrapping if it is one long word but not URL */
2524 if (line_pos - p_pos <= i_len)
2525 if (!gtkut_stext_is_uri_string
2526 (text, line_pos, tlen))
2527 line_pos = cur_pos - 1;
2529 printf("new line_pos=%d\n", line_pos);
2532 GET_CHAR(line_pos - 1, cbuf, clen);
2534 /* if next character is space delete it */
2535 if (clen == 1 && isspace(*cbuf)) {
2536 if (p_pos + i_len != line_pos ||
2537 !gtkut_stext_is_uri_string
2538 (text, line_pos, tlen)) {
2539 gtk_stext_set_point(text, line_pos);
2540 gtk_stext_backward_delete(text, 1);
2549 /* if it is URL at beginning of line don't wrap */
2550 if (p_pos + i_len == line_pos &&
2551 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2553 printf("found URL at ");
2554 dump_text(text, line_pos, tlen, 1);
2560 gtk_stext_set_point(text, line_pos);
2561 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2562 /* gtk_stext_compact_buffer(text); */
2565 /* for loop will increase it */
2566 cur_pos = line_pos - 1;
2567 /* start over with current line */
2573 printf("after CR insert ");
2574 dump_text(text, line_pos, tlen, 1);
2575 dump_text(text, cur_pos, tlen, 1);
2578 /* should we insert quotation ? */
2579 if (linewrap_quote && qlen) {
2580 /* only if line is not already quoted */
2581 if (!gtkut_stext_str_compare
2582 (text, line_pos, tlen, qfmt)) {
2585 if (line_pos - p_pos > i_len) {
2590 /* gtk_stext_compact_buffer(text); */
2594 printf("after quote insert ");
2595 dump_text(text, line_pos, tlen, 1);
2603 line_pos = cur_pos + 1;
2604 line_len = cur_len + ch_len;
2606 /* advance to next character in buffer */
2610 gtk_stext_thaw(text);
2615 static void compose_set_title(Compose *compose)
2620 edited = compose->modified ? _(" [Edited]") : "";
2621 if (compose->account && compose->account->address)
2622 str = g_strdup_printf(_("%s - Compose message%s"),
2623 compose->account->address, edited);
2625 str = g_strdup_printf(_("Compose message%s"), edited);
2626 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2631 * compose_current_mail_account:
2633 * Find a current mail account (the currently selected account, or the
2634 * default account, if a news account is currently selected). If a
2635 * mail account cannot be found, display an error message.
2637 * Return value: Mail account, or NULL if not found.
2639 static PrefsAccount *
2640 compose_current_mail_account(void)
2644 if (cur_account && cur_account->protocol != A_NNTP)
2647 ac = account_get_default();
2648 if (!ac || ac->protocol == A_NNTP) {
2649 alertpanel_error(_("Account for sending mail is not specified.\n"
2650 "Please select a mail account before sending."));
2657 gboolean compose_check_for_valid_recipient(Compose *compose) {
2658 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2659 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2660 gboolean recipient_found = FALSE;
2664 /* free to and newsgroup list */
2665 slist_free_strings(compose->to_list);
2666 g_slist_free(compose->to_list);
2667 compose->to_list = NULL;
2669 slist_free_strings(compose->newsgroup_list);
2670 g_slist_free(compose->newsgroup_list);
2671 compose->newsgroup_list = NULL;
2673 /* search header entries for to and newsgroup entries */
2674 for(list = compose->header_list; list; list = list->next) {
2677 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2678 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2680 if(entry[0] != '\0') {
2681 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2682 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2683 compose->to_list = address_list_append(compose->to_list, entry);
2684 recipient_found = TRUE;
2687 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2688 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2689 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2690 recipient_found = TRUE;
2696 return recipient_found;
2699 gint compose_send(Compose *compose)
2705 val = compose_queue(compose, &msgnum, &folder);
2707 alertpanel_error(_("Could not queue message for sending"));
2711 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2713 folder_item_remove_msg(folder, msgnum);
2714 folderview_update_item(folder, TRUE);
2720 #if 0 /* compose restructure */
2721 gint compose_send(Compose *compose)
2723 gchar tmp[MAXPATHLEN + 1];
2725 static gboolean lock = FALSE;
2729 g_return_val_if_fail(compose->account != NULL, -1);
2730 g_return_val_if_fail(compose->orig_account != NULL, -1);
2734 if(!compose_check_for_valid_recipient(compose)) {
2735 alertpanel_error(_("Recipient is not specified."));
2740 /* write to temporary file */
2741 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2742 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2744 if (prefs_common.linewrap_at_send)
2745 compose_wrap_line_all(compose);
2747 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2752 if (!compose->to_list && !compose->newsgroup_list) {
2753 g_warning(_("can't get recipient list."));
2759 if (compose->to_list) {
2762 #if 0 /* NEW COMPOSE GUI */
2763 if (compose->account->protocol != A_NNTP)
2764 ac = compose->account;
2765 else if (compose->orig_account->protocol != A_NNTP)
2766 ac = compose->orig_account;
2767 else if (cur_account && cur_account->protocol != A_NNTP)
2770 ac = compose_current_mail_account();
2778 ac = compose->account;
2780 ok = send_message(tmp, ac, compose->to_list);
2781 statusbar_pop_all();
2784 if (ok == 0 && compose->newsgroup_list) {
2787 if (compose->account->protocol == A_NNTP)
2788 folder = FOLDER(compose->account->folder);
2790 folder = FOLDER(compose->orig_account->folder);
2792 ok = news_post(folder, tmp);
2794 alertpanel_error(_("Error occurred while posting the message to %s ."),
2795 compose->account->nntp_server);
2802 /* queue message if failed to send */
2804 if (prefs_common.queue_msg) {
2809 _("Error occurred while sending the message.\n"
2810 "Put this message into queue folder?"),
2811 _("OK"), _("Cancel"), NULL);
2812 if (G_ALERTDEFAULT == val) {
2813 ok = compose_queue(compose, tmp);
2815 alertpanel_error(_("Can't queue the message."));
2818 alertpanel_error(_("Error occurred while sending the message."));
2820 if (compose->mode == COMPOSE_REEDIT) {
2821 compose_remove_reedit_target(compose);
2822 if (compose->targetinfo)
2823 folderview_update_item
2824 (compose->targetinfo->folder, TRUE);
2828 /* save message to outbox */
2829 if (ok == 0 && prefs_common.savemsg) {
2830 if (compose_save_to_outbox(compose, tmp) < 0)
2832 (_("Can't save the message to outbox."));
2841 static gboolean compose_use_attach(Compose *compose) {
2842 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2845 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2848 gchar buf[BUFFSIZE];
2850 gboolean first_address;
2852 ComposeHeaderEntry *headerentry;
2853 gchar *headerentryname;
2854 gchar *header_w_colon;
2858 debug_print(_("Writing bounce header\n"));
2860 header_w_colon = g_strconcat("To:", NULL);
2861 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2862 header_w_colon = g_strconcat("Cc:", NULL);
2863 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2865 first_address = TRUE;
2866 for(list = compose->header_list; list; list = list->next) {
2867 headerentry = ((ComposeHeaderEntry *)list->data);
2868 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2870 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2871 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2872 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2873 Xstrdup_a(str, str, return -1);
2875 if(str[0] != '\0') {
2876 compose_convert_header
2877 (buf, sizeof(buf), str,
2878 strlen("Resent-To") + 2);
2880 fprintf(fp, "Resent-To: ");
2881 first_address = FALSE;
2885 fprintf(fp, "%s", buf);
2889 /* if(!first_address) { */
2896 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2898 gchar buf[BUFFSIZE];
2900 /* struct utsname utsbuf; */
2902 g_return_val_if_fail(fp != NULL, -1);
2903 g_return_val_if_fail(compose->account != NULL, -1);
2904 g_return_val_if_fail(compose->account->address != NULL, -1);
2907 get_rfc822_date(buf, sizeof(buf));
2908 fprintf(fp, "Resent-Date: %s\n", buf);
2911 if (compose->account->name && *compose->account->name) {
2912 compose_convert_header
2913 (buf, sizeof(buf), compose->account->name,
2915 fprintf(fp, "Resent-From: %s <%s>\n",
2916 buf, compose->account->address);
2918 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2921 compose_bounce_write_headers_from_headerlist(compose, fp);
2923 /* separator between header and body */
2929 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2934 gchar buf[BUFFSIZE];
2936 if ((fp = fopen(compose->bounce_filename, "r")) == NULL) {
2937 FILE_OP_ERROR(file, "fopen");
2941 if ((fdest = fopen(file, "w")) == NULL) {
2942 FILE_OP_ERROR(file, "fopen");
2947 /* chmod for security */
2948 if (change_file_mode_rw(fdest, file) < 0) {
2949 FILE_OP_ERROR(file, "chmod");
2950 g_warning(_("can't change file mode\n"));
2953 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2954 /* should filter returnpath, delivered-to */
2955 if ((g_strncasecmp(buf, "Return-Path:",
2956 strlen("Return-Path:")) == 0)
2957 || (g_strncasecmp(buf, "Delivered-To:",
2958 strlen("Delivered-To:")) == 0))
2961 if (fputs(buf, fdest) == -1)
2964 if (g_strncasecmp(buf, "From:", strlen("From:")) == 0) {
2965 fputs(" (by way of ", fdest);
2966 if (compose->account->name
2967 && *compose->account->name) {
2968 compose_convert_header
2970 compose->account->name,
2972 fprintf(fdest, "%s <%s>",
2973 buf, compose->account->address);
2975 fprintf(fdest, "%s",
2976 compose->account->address);
2980 if (fputs("\n", fdest) == -1)
2984 compose_bounce_write_headers(compose, fdest);
2986 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
2987 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
3005 * interfaces to rfc2015 to keep out the prefs stuff there.
3006 * returns 0 on success and -1 on error. */
3007 static int compose_create_signers_list (Compose *compose, GSList **pkey_list)
3009 const char *keyid = NULL;
3012 switch (compose->account->sign_key) {
3013 case SIGN_KEY_DEFAULT:
3015 return 0; /* nothing to do */
3017 case SIGN_KEY_BY_FROM:
3018 keyid = compose->account->address;
3021 case SIGN_KEY_CUSTOM:
3022 keyid = compose->account->sign_key_id;
3026 g_assert_not_reached ();
3029 key_list = rfc2015_create_signers_list(keyid);
3032 alertpanel_error("Could not find any key associated with currently "
3033 "selected keyid `%s'!", keyid);
3037 *pkey_list = key_list;
3040 #endif /* USE_GPGME */
3042 static gint compose_write_to_file(Compose *compose, const gchar *file,
3049 const gchar *out_codeset;
3050 EncodingType encoding;
3052 if ((fp = fopen(file, "w")) == NULL) {
3053 FILE_OP_ERROR(file, "fopen");
3057 /* chmod for security */
3058 if (change_file_mode_rw(fp, file) < 0) {
3059 FILE_OP_ERROR(file, "chmod");
3060 g_warning(_("can't change file mode\n"));
3063 /* get all composed text */
3064 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3065 len = strlen(chars);
3066 if (is_ascii_str(chars)) {
3067 buf = g_strdup(chars);
3068 out_codeset = CS_US_ASCII;
3069 encoding = ENC_7BIT;
3071 const gchar *src_codeset;
3073 out_codeset = conv_get_outgoing_charset_str();
3074 if (!strcasecmp(out_codeset, CS_US_ASCII))
3075 out_codeset = CS_ISO_8859_1;
3076 encoding = procmime_get_encoding_for_charset(out_codeset);
3078 src_codeset = conv_get_current_charset_str();
3079 /* if current encoding is US-ASCII, set it the same as
3080 outgoing one to prevent code conversion failure */
3081 if (!strcasecmp(src_codeset, CS_US_ASCII))
3082 src_codeset = out_codeset;
3084 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3085 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3087 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3092 alertpanel_error(_("Can't convert the codeset of the message."));
3099 if (compose_write_headers
3100 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3101 g_warning(_("can't write headers\n"));
3108 if (compose_use_attach(compose)) {
3110 /* This prolog message is ignored by mime software and
3111 * because it would make our signing/encryption task
3112 * tougher, we don't emit it in that case */
3113 if (!compose->use_signing && !compose->use_encryption)
3115 fputs("This is a multi-part message in MIME format.\n", fp);
3117 fprintf(fp, "\n--%s\n", compose->boundary);
3118 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3120 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3121 procmime_get_encoding_str(encoding));
3127 if (encoding == ENC_BASE64) {
3128 gchar outbuf[B64_BUFFSIZE];
3131 for (i = 0; i < len; i += B64_LINE_SIZE) {
3132 l = MIN(B64_LINE_SIZE, len - i);
3133 to64frombits(outbuf, buf + i, l);
3137 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3138 FILE_OP_ERROR(file, "fwrite");
3146 if (compose_use_attach(compose))
3147 compose_write_attach(compose, fp);
3149 if (fclose(fp) == EOF) {
3150 FILE_OP_ERROR(file, "fclose");
3156 if (compose->use_signing) {
3159 if (compose_create_signers_list(compose, &key_list) == -1 ||
3160 rfc2015_sign(file, key_list) < 0) {
3166 if (compose->use_encryption) {
3167 if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) {
3172 #endif /* USE_GPGME */
3177 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3183 if ((fp = fopen(file, "w")) == NULL) {
3184 FILE_OP_ERROR(file, "fopen");
3188 /* chmod for security */
3189 if (change_file_mode_rw(fp, file) < 0) {
3190 FILE_OP_ERROR(file, "chmod");
3191 g_warning(_("can't change file mode\n"));
3194 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3197 len = strlen(chars);
3198 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3199 FILE_OP_ERROR(file, "fwrite");
3208 if (fclose(fp) == EOF) {
3209 FILE_OP_ERROR(file, "fclose");
3216 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
3223 debug_print(_("saving sent message...\n"));
3225 outbox = folder_get_default_outbox();
3226 path = folder_item_get_path(outbox);
3227 if (!is_dir_exist(path))
3228 make_dir_hier(path);
3230 folder_item_scan(outbox);
3231 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
3233 g_warning(_("can't save message\n"));
3237 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
3238 g_warning(_("can't open mark file\n"));
3242 newmsginfo.msgnum = num;
3243 newmsginfo.flags.perm_flags = 0;
3244 newmsginfo.flags.tmp_flags = 0;
3245 procmsg_write_flags(&newmsginfo, fp);
3253 static gint compose_remove_reedit_target(Compose *compose)
3256 MsgInfo *msginfo = compose->targetinfo;
3258 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3259 if (!msginfo) return -1;
3261 item = msginfo->folder;
3262 g_return_val_if_fail(item != NULL, -1);
3264 folder_item_scan(item);
3265 if (procmsg_msg_exist(msginfo) &&
3266 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3267 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3268 g_warning(_("can't remove the old message\n"));
3277 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3280 gchar *tmp, *tmp2, *queue_path;
3283 gchar buf[BUFFSIZE];
3285 static gboolean lock = FALSE;
3286 PrefsAccount *mailac = NULL, *newsac = NULL;
3288 debug_print(_("queueing message...\n"));
3289 g_return_val_if_fail(compose->account != NULL, -1);
3290 g_return_val_if_fail(compose->orig_account != NULL, -1);
3294 if(!compose_check_for_valid_recipient(compose)) {
3295 alertpanel_error(_("Recipient is not specified."));
3300 if (!compose->to_list && !compose->newsgroup_list) {
3301 g_warning(_("can't get recipient list."));
3306 if(compose->to_list) {
3307 if (compose->account->protocol != A_NNTP)
3308 mailac = compose->account;
3309 else if (compose->orig_account->protocol != A_NNTP)
3310 mailac = compose->orig_account;
3311 else if (cur_account && cur_account->protocol != A_NNTP)
3312 mailac = cur_account;
3313 else if (!(mailac = compose_current_mail_account())) {
3315 alertpanel_error(_("No account for sending mails available!"));
3320 if(compose->newsgroup_list) {
3321 if (compose->account->protocol == A_NNTP)
3322 newsac = compose->account;
3323 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3325 alertpanel_error(_("No account for posting news available!"));
3330 if (prefs_common.linewrap_at_send)
3331 compose_wrap_line_all(compose);
3333 /* write to temporary file */
3334 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3335 G_DIR_SEPARATOR, (gint)compose);
3337 if (compose->bounce_filename != NULL) {
3338 if (compose_bounce_write_to_file(compose, tmp2) < 0) {
3345 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3352 /* add queue header */
3353 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3354 G_DIR_SEPARATOR, (gint)compose);
3355 if ((fp = fopen(tmp, "w")) == NULL) {
3356 FILE_OP_ERROR(tmp, "fopen");
3360 if ((src_fp = fopen(tmp2, "r")) == NULL) {
3361 FILE_OP_ERROR(tmp2, "fopen");
3369 if (change_file_mode_rw(fp, tmp) < 0) {
3370 FILE_OP_ERROR(tmp, "chmod");
3371 g_warning(_("can't change file mode\n"));
3374 /* queueing variables */
3375 fprintf(fp, "AF:\n");
3376 fprintf(fp, "NF:0\n");
3377 fprintf(fp, "PS:10\n");
3378 fprintf(fp, "SRH:1\n");
3379 fprintf(fp, "SFN:\n");
3380 fprintf(fp, "DSR:\n");
3382 fprintf(fp, "MID:<%s>\n", compose->msgid);
3384 fprintf(fp, "MID:\n");
3385 fprintf(fp, "CFG:\n");
3386 fprintf(fp, "PT:0\n");
3387 fprintf(fp, "S:%s\n", compose->account->address);
3388 fprintf(fp, "RQ:\n");
3390 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3392 fprintf(fp, "SSV:\n");
3394 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3396 fprintf(fp, "NSV:\n");
3397 fprintf(fp, "SSH:\n");
3398 /* write recepient list */
3400 if(compose->to_list) {
3401 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3402 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3403 fprintf(fp, ",<%s>", (gchar *)cur->data);
3406 /* write newsgroup list */
3408 if(compose->newsgroup_list) {
3409 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3410 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3411 fprintf(fp, ",%s", (gchar *)cur->data);
3414 /* Sylpheed account IDs */
3416 fprintf(fp, "MAID:%d\n", mailac->account_id);
3419 fprintf(fp, "NAID:%d\n", newsac->account_id);
3421 /* Save copy folder */
3422 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3425 str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3426 fprintf(fp, "SCF:%s\n", str);
3431 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3432 if (fputs(buf, fp) == EOF) {
3433 FILE_OP_ERROR(tmp, "fputs");
3444 if (fclose(fp) == EOF) {
3445 FILE_OP_ERROR(tmp, "fclose");
3454 queue = folder_get_default_queue();
3456 folder_item_scan(queue);
3457 queue_path = folder_item_get_path(queue);
3458 if (!is_dir_exist(queue_path))
3459 make_dir_hier(queue_path);
3460 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3461 g_warning(_("can't queue the message\n"));
3472 if (compose->mode == COMPOSE_REEDIT) {
3473 compose_remove_reedit_target(compose);
3474 if (compose->targetinfo &&
3475 compose->targetinfo->folder != queue)
3476 folderview_update_item
3477 (compose->targetinfo->folder, TRUE);
3480 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
3481 g_warning(_("can't open mark file\n"));
3485 newmsginfo.msgnum = num;
3486 newmsginfo.flags.perm_flags = 0;
3487 newmsginfo.flags.tmp_flags = 0;
3488 procmsg_write_flags(&newmsginfo, fp);
3493 folder_item_scan(queue);
3494 folderview_update_item(queue, TRUE);
3496 if((msgnum != NULL) && (item != NULL)) {
3504 static void compose_write_attach(Compose *compose, FILE *fp)
3507 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3510 gchar filename[BUFFSIZE];
3513 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3515 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
3516 g_warning(_("Can't open file %s\n"), ainfo->file);
3520 fprintf(fp, "\n--%s\n", compose->boundary);
3522 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3523 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3524 fprintf(fp, "Content-Disposition: inline\n");
3526 conv_encode_header(filename, sizeof(filename),
3528 fprintf(fp, "Content-Type: %s;\n"
3530 ainfo->content_type, filename);
3531 fprintf(fp, "Content-Disposition: attachment;\n"
3532 " filename=\"%s\"\n", filename);
3535 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3536 procmime_get_encoding_str(ainfo->encoding));
3538 if (ainfo->encoding == ENC_7BIT) {
3539 gchar buf[BUFFSIZE];
3541 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3546 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3548 while ((len = fread(inbuf, sizeof(gchar),
3549 B64_LINE_SIZE, attach_fp))
3551 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3555 if (len > 0 && feof(attach_fp)) {
3556 to64frombits(outbuf, inbuf, len);
3565 fprintf(fp, "\n--%s--\n", compose->boundary);
3568 #define IS_IN_CUSTOM_HEADER(header) \
3569 (compose->account->add_customhdr && \
3570 custom_header_find(compose->account->customhdr_list, header) != NULL)
3572 static gint compose_write_headers_from_headerlist(Compose *compose,
3576 gchar buf[BUFFSIZE];
3577 gchar *str, *header_w_colon, *trans_hdr;
3578 gboolean first_address;
3580 ComposeHeaderEntry *headerentry;
3581 gchar * headerentryname;
3583 if (IS_IN_CUSTOM_HEADER(header)) {
3587 debug_print(_("Writing %s-header\n"), header);
3589 header_w_colon = g_strconcat(header, ":", NULL);
3590 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3592 first_address = TRUE;
3593 for(list = compose->header_list; list; list = list->next) {
3594 headerentry = ((ComposeHeaderEntry *)list->data);
3595 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3597 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3598 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3599 Xstrdup_a(str, str, return -1);
3601 if(str[0] != '\0') {
3602 compose_convert_header
3603 (buf, sizeof(buf), str,
3604 strlen(header) + 2);
3606 fprintf(fp, "%s: ", header);
3607 first_address = FALSE;
3611 fprintf(fp, "%s", buf);
3615 if(!first_address) {
3619 g_free(header_w_colon);
3624 static gint compose_write_headers(Compose *compose, FILE *fp,
3625 const gchar *charset, EncodingType encoding,
3628 gchar buf[BUFFSIZE];
3630 /* struct utsname utsbuf; */
3632 g_return_val_if_fail(fp != NULL, -1);
3633 g_return_val_if_fail(charset != NULL, -1);
3634 g_return_val_if_fail(compose->account != NULL, -1);
3635 g_return_val_if_fail(compose->account->address != NULL, -1);
3638 if (compose->account->add_date) {
3639 get_rfc822_date(buf, sizeof(buf));
3640 fprintf(fp, "Date: %s\n", buf);
3644 if (!IS_IN_CUSTOM_HEADER("From")) {
3645 if (compose->account->name && *compose->account->name) {
3646 compose_convert_header
3647 (buf, sizeof(buf), compose->account->name,
3649 fprintf(fp, "From: %s <%s>\n",
3650 buf, compose->account->address);
3652 fprintf(fp, "From: %s\n", compose->account->address);
3656 compose_write_headers_from_headerlist(compose, fp, "To");
3657 #if 0 /* NEW COMPOSE GUI */
3658 if (compose->use_to) {
3659 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3661 Xstrdup_a(str, str, return -1);
3664 compose->to_list = address_list_append
3665 (compose->to_list, str);
3666 if (!IS_IN_CUSTOM_HEADER("To")) {
3667 compose_convert_header
3668 (buf, sizeof(buf), str,
3670 fprintf(fp, "To: %s\n", buf);
3678 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3679 #if 0 /* NEW COMPOSE GUI */
3680 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3682 Xstrdup_a(str, str, return -1);
3686 compose->newsgroup_list =
3687 newsgroup_list_append(compose->newsgroup_list,
3689 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3690 compose_convert_header(buf, sizeof(buf), str,
3691 strlen("Newsgroups: "));
3692 fprintf(fp, "Newsgroups: %s\n", buf);
3698 compose_write_headers_from_headerlist(compose, fp, "Cc");
3699 #if 0 /* NEW COMPOSE GUI */
3700 if (compose->use_cc) {
3701 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3703 Xstrdup_a(str, str, return -1);
3706 compose->to_list = address_list_append
3707 (compose->to_list, str);
3708 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3709 compose_convert_header
3710 (buf, sizeof(buf), str,
3712 fprintf(fp, "Cc: %s\n", buf);
3719 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3720 #if 0 /* NEW COMPOSE GUI */
3721 if (compose->use_bcc) {
3722 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3724 Xstrdup_a(str, str, return -1);
3727 compose->to_list = address_list_append
3728 (compose->to_list, str);
3729 compose_convert_header(buf, sizeof(buf), str,
3731 fprintf(fp, "Bcc: %s\n", buf);
3738 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3739 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3740 Xstrdup_a(str, str, return -1);
3743 compose_convert_header(buf, sizeof(buf), str,
3744 strlen("Subject: "));
3745 fprintf(fp, "Subject: %s\n", buf);
3750 if (compose->account->gen_msgid) {
3751 compose_generate_msgid(compose, buf, sizeof(buf));
3752 fprintf(fp, "Message-Id: <%s>\n", buf);
3753 compose->msgid = g_strdup(buf);
3757 if (compose->inreplyto && compose->to_list)
3758 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3761 if (compose->references)
3762 fprintf(fp, "References: %s\n", compose->references);
3765 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3766 #if 0 /* NEW COMPOSE GUI */
3767 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3768 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3770 Xstrdup_a(str, str, return -1);
3774 compose_convert_header(buf, sizeof(buf), str,
3775 strlen("Followup-To: "));
3776 fprintf(fp, "Followup-To: %s\n", buf);
3782 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3783 #if 0 /* NEW COMPOSE GUI */
3784 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3785 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3787 Xstrdup_a(str, str, return -1);
3790 compose_convert_header(buf, sizeof(buf), str,
3791 strlen("Reply-To: "));
3792 fprintf(fp, "Reply-To: %s\n", buf);
3798 if (compose->account->organization &&
3799 !IS_IN_CUSTOM_HEADER("Organization")) {
3800 compose_convert_header(buf, sizeof(buf),
3801 compose->account->organization,
3802 strlen("Organization: "));
3803 fprintf(fp, "Organization: %s\n", buf);
3806 /* Program version and system info */
3807 /* uname(&utsbuf); */
3808 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3809 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3811 gtk_major_version, gtk_minor_version, gtk_micro_version,
3813 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3815 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3816 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3818 gtk_major_version, gtk_minor_version, gtk_micro_version,
3820 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3823 /* custom headers */
3824 if (compose->account->add_customhdr) {
3827 for (cur = compose->account->customhdr_list; cur != NULL;
3829 CustomHeader *chdr = (CustomHeader *)cur->data;
3831 if (strcasecmp(chdr->name, "Date") != 0 &&
3832 strcasecmp(chdr->name, "From") != 0 &&
3833 strcasecmp(chdr->name, "To") != 0 &&
3834 /* strcasecmp(chdr->name, "Sender") != 0 && */
3835 strcasecmp(chdr->name, "Message-Id") != 0 &&
3836 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3837 strcasecmp(chdr->name, "References") != 0 &&
3838 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3839 strcasecmp(chdr->name, "Content-Type") != 0 &&
3840 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3842 compose_convert_header
3844 chdr->value ? chdr->value : "",
3845 strlen(chdr->name) + 2);
3846 fprintf(fp, "%s: %s\n", chdr->name, buf);
3852 fprintf(fp, "Mime-Version: 1.0\n");
3853 if (compose_use_attach(compose)) {
3854 get_rfc822_date(buf, sizeof(buf));
3855 subst_char(buf, ' ', '_');
3856 subst_char(buf, ',', '_');
3857 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3858 buf, (guint)compose);
3860 "Content-Type: multipart/mixed;\n"
3861 " boundary=\"%s\"\n", compose->boundary);
3863 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3864 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3865 procmime_get_encoding_str(encoding));
3868 /* Request Return Receipt */
3869 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3870 if (compose->return_receipt) {
3871 if (compose->account->name
3872 && *compose->account->name) {
3873 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3874 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3876 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3880 /* separator between header and body */
3886 #undef IS_IN_CUSTOM_HEADER
3888 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3891 g_return_if_fail(src != NULL);
3892 g_return_if_fail(dest != NULL);
3894 if (len < 1) return;
3898 if (is_ascii_str(src)) {
3899 strncpy2(dest, src, len);
3900 dest[len - 1] = '\0';
3903 conv_encode_header(dest, len, src, header_len);
3906 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3915 if (compose->account && compose->account->address &&
3916 *compose->account->address) {
3917 if (strchr(compose->account->address, '@'))
3918 addr = g_strdup(compose->account->address);
3920 addr = g_strconcat(compose->account->address, "@",
3921 get_domain_name(), NULL);
3923 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3926 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3927 lt->tm_year + 1900, lt->tm_mon + 1,
3928 lt->tm_mday, lt->tm_hour,
3929 lt->tm_min, lt->tm_sec,
3930 (guint)random(), addr);
3932 debug_print(_("generated Message-ID: %s\n"), buf);
3937 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3938 GtkWidget **entry, gint *count,
3939 const gchar *label_str,
3940 gboolean is_addr_entry)
3944 if (GTK_TABLE(table)->nrows < (*count) + 1)
3945 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3947 *hbox = gtk_hbox_new(FALSE, 0);
3948 label = gtk_label_new
3949 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3950 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3951 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3953 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3955 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3956 #if 0 /* NEW COMPOSE GUI */
3957 if (GTK_TABLE(table)->nrows > (*count) + 1)
3958 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3962 address_completion_register_entry(GTK_ENTRY(*entry));
3967 static void compose_create_header_entry(Compose *compose)
3969 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3973 GList *combo_list = NULL;
3974 gchar **string, *header;
3975 ComposeHeaderEntry *headerentry;
3977 headerentry = g_new0(ComposeHeaderEntry, 1);
3980 combo = gtk_combo_new();
3982 while(*string != NULL) {
3983 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3986 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3987 g_list_free(combo_list);
3988 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3989 gtk_widget_show(combo);
3990 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3991 if(compose->header_last) {
3992 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3994 switch(compose->account->protocol) {
3996 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
3999 header = prefs_common.trans_hdr ? _("To:") : "To:";
4003 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4006 entry = gtk_entry_new();
4007 gtk_widget_show(entry);
4008 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);
4010 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4011 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4012 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4014 address_completion_register_entry(GTK_ENTRY(entry));
4016 headerentry->compose = compose;
4017 headerentry->combo = combo;
4018 headerentry->entry = entry;
4019 headerentry->headernum = compose->header_nextrow;
4021 compose->header_nextrow++;
4022 compose->header_last = headerentry;
4025 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4027 ComposeHeaderEntry *last_header;
4029 last_header = compose->header_last;
4031 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4032 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4035 static GtkWidget *compose_create_header(Compose *compose)
4039 GtkWidget *from_optmenu_hbox;
4040 #if 0 /* NEW COMPOSE GUI */
4041 GtkWidget *to_entry;
4043 GtkWidget *newsgroups_entry;
4044 GtkWidget *newsgroups_hbox;
4046 GtkWidget *header_scrolledwin;
4047 GtkWidget *header_table;
4048 #if 0 /* NEW COMPOSE GUI */
4049 GtkWidget *cc_entry;
4051 GtkWidget *bcc_entry;
4052 GtkWidget *bcc_hbox;
4053 GtkWidget *reply_entry;
4054 GtkWidget *reply_hbox;
4055 GtkWidget *followup_entry;
4056 GtkWidget *followup_hbox;
4061 /* header labels and entries */
4062 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4063 gtk_widget_show(header_scrolledwin);
4064 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4066 header_table = gtk_table_new(2, 2, FALSE);
4067 gtk_widget_show(header_table);
4068 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4069 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4070 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4073 /* option menu for selecting accounts */
4074 hbox = gtk_hbox_new(FALSE, 0);
4075 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4076 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4077 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4079 from_optmenu_hbox = compose_account_option_menu_create(compose);
4080 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4081 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4082 #if 0 /* NEW COMPOSE GUI */
4083 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4087 compose->header_table = header_table;
4088 compose->header_list = NULL;
4089 compose->header_nextrow = count;
4091 compose_create_header_entry(compose);
4093 #if 0 /* NEW COMPOSE GUI */
4094 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4096 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4097 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4098 &count, "Newsgroups:", FALSE);
4099 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4101 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4103 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4105 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4106 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4108 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4109 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4111 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4112 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4113 "Followup-To:", FALSE);
4114 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4116 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4118 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4119 GTK_SIGNAL_FUNC(to_activated), compose);
4120 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4121 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4122 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4123 GTK_SIGNAL_FUNC(subject_activated), compose);
4124 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4125 GTK_SIGNAL_FUNC(cc_activated), compose);
4126 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4127 GTK_SIGNAL_FUNC(bcc_activated), compose);
4128 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4129 GTK_SIGNAL_FUNC(replyto_activated), compose);
4130 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4131 GTK_SIGNAL_FUNC(followupto_activated), compose);
4133 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4134 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4135 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4136 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4137 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4138 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4139 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4140 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4141 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4142 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4143 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4144 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4145 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4146 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4149 compose->table = NULL;
4150 #if 0 /* NEW COMPOSE GUI */
4151 compose->table = table;
4152 compose->to_hbox = to_hbox;
4153 compose->to_entry = to_entry;
4154 compose->newsgroups_hbox = newsgroups_hbox;
4155 compose->newsgroups_entry = newsgroups_entry;
4157 #if 0 /* NEW COMPOSE GUI */
4158 compose->cc_hbox = cc_hbox;
4159 compose->cc_entry = cc_entry;
4160 compose->bcc_hbox = bcc_hbox;
4161 compose->bcc_entry = bcc_entry;
4162 compose->reply_hbox = reply_hbox;
4163 compose->reply_entry = reply_entry;
4164 compose->followup_hbox = followup_hbox;
4165 compose->followup_entry = followup_entry;
4168 return header_scrolledwin ;
4171 GtkWidget *compose_create_attach(Compose *compose)
4173 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
4176 GtkWidget *attach_scrwin;
4177 GtkWidget *attach_clist;
4179 /* attachment list */
4180 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4181 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4182 GTK_POLICY_AUTOMATIC,
4184 gtk_widget_set_usize(attach_scrwin, -1, 80);
4186 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4187 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4189 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4190 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4191 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4192 GTK_SELECTION_EXTENDED);
4193 for (i = 0; i < N_ATTACH_COLS; i++)
4194 GTK_WIDGET_UNSET_FLAGS
4195 (GTK_CLIST(attach_clist)->column[i].button,
4197 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4199 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4200 GTK_SIGNAL_FUNC(attach_selected), compose);
4201 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4202 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4203 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4204 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4207 gtk_drag_dest_set(attach_clist,
4208 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4210 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4211 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4214 compose->attach_scrwin = attach_scrwin;
4215 compose->attach_clist = attach_clist;
4217 return attach_scrwin;
4220 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4221 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4223 static GtkWidget *compose_create_others(Compose *compose)
4226 GtkWidget *savemsg_checkbtn;
4227 GtkWidget *savemsg_entry;
4228 GtkWidget *savemsg_select;
4231 gchar *folderidentifier;
4233 /* Table for settings */
4234 table = gtk_table_new(3, 1, FALSE);
4235 gtk_widget_show(table);
4236 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4239 /* Save Message to folder */
4240 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4241 gtk_widget_show(savemsg_checkbtn);
4242 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4243 if(folder_get_default_outbox()) {
4244 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4246 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4247 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4249 savemsg_entry = gtk_entry_new();
4250 gtk_widget_show(savemsg_entry);
4251 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4252 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4253 if(folder_get_default_outbox()) {
4254 folderidentifier = folder_item_get_identifier(folder_get_default_outbox());
4255 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4256 g_free(folderidentifier);
4259 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4260 gtk_widget_show (savemsg_select);
4261 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4262 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4263 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4268 compose->savemsg_checkbtn = savemsg_checkbtn;
4269 compose->savemsg_entry = savemsg_entry;
4274 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4276 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4277 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4280 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4285 dest = foldersel_folder_sel(NULL, NULL);
4288 path = folder_item_get_identifier(dest);
4290 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4294 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4300 GtkWidget *handlebox;
4302 GtkWidget *notebook;
4307 GtkWidget *subject_hbox;
4308 GtkWidget *subject_frame;
4309 GtkWidget *subject_entry;
4313 GtkWidget *edit_vbox;
4314 GtkWidget *ruler_hbox;
4316 GtkWidget *scrolledwin;
4321 UndoMain *undostruct;
4323 guint n_menu_entries;
4324 GtkStyle *style, *new_style;
4327 gboolean success[1];
4329 GtkWidget *popupmenu;
4330 GtkWidget *menuitem;
4331 GtkItemFactory *popupfactory;
4332 GtkItemFactory *ifactory;
4333 GtkWidget *tmpl_menu;
4337 GtkPspell * gtkpspell = NULL;
4340 g_return_val_if_fail(account != NULL, NULL);
4342 debug_print(_("Creating compose window...\n"));
4343 compose = g_new0(Compose, 1);
4345 compose->account = account;
4346 compose->orig_account = account;
4348 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4349 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4350 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4351 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4352 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4353 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4354 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4355 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4356 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
4357 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
4358 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
4359 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
4360 gtk_widget_realize(window);
4362 gtkut_widget_set_composer_icon(window);
4364 vbox = gtk_vbox_new(FALSE, 0);
4365 gtk_container_add(GTK_CONTAINER(window), vbox);
4367 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4368 menubar = menubar_create(window, compose_entries,
4369 n_menu_entries, "<Compose>", compose);
4370 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4372 handlebox = gtk_handle_box_new();
4373 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4375 compose_toolbar_create(compose, handlebox);
4377 vbox2 = gtk_vbox_new(FALSE, 2);
4378 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4379 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4382 notebook = gtk_notebook_new();
4383 gtk_widget_set_usize(notebook, -1, 130);
4384 gtk_widget_show(notebook);
4386 /* header labels and entries */
4387 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4388 /* attachment list */
4389 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4391 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4394 subject_hbox = gtk_hbox_new(FALSE, 0);
4395 gtk_widget_show(subject_hbox);
4397 subject_frame = gtk_frame_new(NULL);
4398 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4399 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4400 gtk_widget_show(subject_frame);
4402 subject = gtk_hbox_new(FALSE, 0);
4403 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4404 gtk_widget_show(subject);
4406 label = gtk_label_new(_("Subject:"));
4407 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4408 gtk_widget_show(label);
4410 subject_entry = gtk_entry_new();
4411 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4412 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4413 gtk_widget_show(subject_entry);
4414 compose->subject_entry = subject_entry;
4415 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4417 edit_vbox = gtk_vbox_new(FALSE, 0);
4418 #if 0 /* NEW COMPOSE GUI */
4419 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4422 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4425 ruler_hbox = gtk_hbox_new(FALSE, 0);
4426 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4428 ruler = gtk_shruler_new();
4429 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4430 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4432 gtk_widget_set_usize(ruler_hbox, 1, -1);
4435 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4436 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4437 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4438 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4439 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4441 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4442 (GTK_SCROLLED_WINDOW(scrolledwin)),
4443 gtk_scrolled_window_get_vadjustment
4444 (GTK_SCROLLED_WINDOW(scrolledwin)));
4445 GTK_STEXT(text)->default_tab_width = 8;
4446 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4448 if (prefs_common.block_cursor) {
4449 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4452 if (prefs_common.smart_wrapping) {
4453 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4454 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4457 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4459 gtk_signal_connect(GTK_OBJECT(text), "changed",
4460 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4461 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4462 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4463 gtk_signal_connect(GTK_OBJECT(text), "activate",
4464 GTK_SIGNAL_FUNC(text_activated), compose);
4465 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4466 GTK_SIGNAL_FUNC(compose_button_press_cb),
4469 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4470 GTK_SIGNAL_FUNC(compose_key_press_cb),
4473 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4474 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4478 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4480 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4481 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4483 gtk_widget_show_all(vbox);
4485 /* pane between attach clist and text */
4486 paned = gtk_vpaned_new();
4487 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4488 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4489 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4490 gtk_paned_add1(GTK_PANED(paned), notebook);
4491 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4492 gtk_widget_show_all(paned);
4494 style = gtk_widget_get_style(text);
4496 /* workaround for the slow down of GtkSText when using Pixmap theme */
4497 if (style->engine) {
4498 GtkThemeEngine *engine;
4500 engine = style->engine;
4501 style->engine = NULL;
4502 new_style = gtk_style_copy(style);
4503 style->engine = engine;
4505 new_style = gtk_style_copy(style);
4507 if (prefs_common.textfont) {
4510 charset = conv_get_current_charset();
4511 if (MB_CUR_MAX == 1) {
4514 Xstrdup_a(fontstr, prefs_common.textfont, );
4515 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4517 font = gdk_font_load(fontstr);
4519 font = gdk_fontset_load(prefs_common.textfont);
4521 gdk_font_unref(new_style->font);
4522 new_style->font = font;
4526 gtk_widget_set_style(text, new_style);
4528 color[0] = quote_color;
4529 cmap = gdk_window_get_colormap(window->window);
4530 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4531 if (success[0] == FALSE) {
4532 g_warning("Compose: color allocation failed.\n");
4533 style = gtk_widget_get_style(text);
4534 quote_color = style->black;
4537 n_entries = sizeof(compose_popup_entries) /
4538 sizeof(compose_popup_entries[0]);
4539 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4540 "<Compose>", &popupfactory,
4543 ifactory = gtk_item_factory_from_widget(menubar);
4544 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4545 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4547 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tool/Template");
4548 #if 0 /* NEW COMPOSE GUI */
4549 gtk_widget_hide(bcc_hbox);
4550 gtk_widget_hide(bcc_entry);
4551 gtk_widget_hide(reply_hbox);
4552 gtk_widget_hide(reply_entry);
4553 gtk_widget_hide(followup_hbox);
4554 gtk_widget_hide(followup_entry);
4555 gtk_widget_hide(ruler_hbox);
4556 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4557 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4558 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4560 if (account->protocol == A_NNTP) {
4561 gtk_widget_hide(to_hbox);
4562 gtk_widget_hide(to_entry);
4563 gtk_widget_hide(cc_hbox);
4564 gtk_widget_hide(cc_entry);
4565 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4566 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4568 gtk_widget_hide(newsgroups_hbox);
4569 gtk_widget_hide(newsgroups_entry);
4570 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4571 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
4575 switch (prefs_common.toolbar_style) {
4577 gtk_widget_hide(handlebox);
4580 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4584 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4588 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4593 undostruct = undo_init(text);
4594 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4597 gtk_widget_show(window);
4599 address_completion_start(window);
4601 compose->window = window;
4602 compose->vbox = vbox;
4603 compose->menubar = menubar;
4604 compose->handlebox = handlebox;
4606 compose->vbox2 = vbox2;
4608 compose->paned = paned;
4610 compose->edit_vbox = edit_vbox;
4611 compose->ruler_hbox = ruler_hbox;
4612 compose->ruler = ruler;
4613 compose->scrolledwin = scrolledwin;
4614 compose->text = text;
4616 compose->focused_editable = NULL;
4618 compose->popupmenu = popupmenu;
4619 compose->popupfactory = popupfactory;
4621 compose->tmpl_menu = tmpl_menu;
4623 compose->mode = mode;
4625 compose->targetinfo = NULL;
4626 compose->replyinfo = NULL;
4628 compose->replyto = NULL;
4629 compose->mailinglist = NULL;
4631 compose->bcc = NULL;
4632 compose->followup_to = NULL;
4633 compose->inreplyto = NULL;
4634 compose->references = NULL;
4635 compose->msgid = NULL;
4636 compose->boundary = NULL;
4639 compose->use_signing = FALSE;
4640 compose->use_encryption = FALSE;
4641 #endif /* USE_GPGME */
4643 compose->modified = FALSE;
4645 compose->return_receipt = FALSE;
4647 compose->to_list = NULL;
4648 compose->newsgroup_list = NULL;
4650 compose->exteditor_file = NULL;
4651 compose->exteditor_pid = -1;
4652 compose->exteditor_readdes = -1;
4653 compose->exteditor_tag = -1;
4655 compose->bounce_filename = NULL;
4656 compose->undostruct = undostruct;
4659 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4660 if (prefs_common.enable_pspell) {
4661 gtkpspell = gtkpspell_new((const gchar*)prefs_common.dictionary,
4662 conv_get_current_charset_str(),
4663 prefs_common.misspelled_col,
4664 prefs_common.check_while_typing,
4667 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkpspellcheckers->error_message);
4668 gtkpspell_checkers_reset_error();
4671 GtkWidget *menuitem;
4673 if (!gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode)) {
4674 debug_print(_("Pspell: could not set suggestion mode %s"),
4675 gtkpspellcheckers->error_message);
4676 gtkpspell_checkers_reset_error();
4679 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
4680 gtkpspell_populate_submenu(gtkpspell, menuitem);
4681 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4686 compose_set_title(compose);
4688 #if 0 /* NEW COMPOSE GUI */
4689 compose->use_bcc = FALSE;
4690 compose->use_replyto = FALSE;
4691 compose->use_followupto = FALSE;
4695 compose->gtkpspell = gtkpspell;
4698 #if 0 /* NEW COMPOSE GUI */
4699 if (account->protocol != A_NNTP) {
4700 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
4701 gtk_check_menu_item_set_active
4702 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4703 gtk_widget_set_sensitive(menuitem, FALSE);
4704 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4705 gtk_check_menu_item_set_active
4706 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4707 gtk_widget_set_sensitive(menuitem, FALSE);
4710 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4711 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4712 #if 0 /* NEW COMPOSE GUI */
4713 compose->use_cc = TRUE;
4714 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4715 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4716 gtk_check_menu_item_set_active
4717 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4720 if (account->set_autobcc) {
4721 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4722 #if 0 /* NEW COMPOSE GUI */
4723 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
4724 gtk_check_menu_item_set_active
4725 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4726 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4727 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4731 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4732 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4733 #if 0 /* NEW COMPOSE GUI */
4734 compose->use_replyto = TRUE;
4735 menuitem = gtk_item_factory_get_item(ifactory,
4737 gtk_check_menu_item_set_active
4738 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4739 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4740 account->auto_replyto);
4744 if (account->protocol != A_NNTP) {
4745 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4747 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4750 #if 0 /* NEW COMPOSE GUI */
4751 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
4752 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4753 prefs_common.show_ruler);
4757 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4758 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4759 account->default_sign);
4760 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4761 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4762 account->default_encrypt);
4763 #endif /* USE_GPGME */
4765 addressbook_set_target_compose(compose);
4766 compose_set_template_menu(compose);
4768 compose_list = g_list_append(compose_list, compose);
4770 #if 0 /* NEW COMPOSE GUI */
4771 compose->use_to = FALSE;
4772 compose->use_cc = FALSE;
4773 compose->use_attach = TRUE;
4776 #if 0 /* NEW COMPOSE GUI */
4777 if (!compose->use_bcc) {
4778 gtk_widget_hide(bcc_hbox);
4779 gtk_widget_hide(bcc_entry);
4780 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4782 if (!compose->use_replyto) {
4783 gtk_widget_hide(reply_hbox);
4784 gtk_widget_hide(reply_entry);
4785 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4787 if (!compose->use_followupto) {
4788 gtk_widget_hide(followup_hbox);
4789 gtk_widget_hide(followup_entry);
4790 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4793 if (!prefs_common.show_ruler)
4794 gtk_widget_hide(ruler_hbox);
4796 select_account(compose, account);
4801 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4804 GtkWidget *icon_wid;
4805 GtkWidget *send_btn;
4806 GtkWidget *sendl_btn;
4807 GtkWidget *draft_btn;
4808 GtkWidget *insert_btn;
4809 GtkWidget *attach_btn;
4811 GtkWidget *exteditor_btn;
4812 GtkWidget *linewrap_btn;
4813 GtkWidget *addrbook_btn;
4815 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4817 gtk_container_add(GTK_CONTAINER(container), toolbar);
4818 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4819 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4820 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4821 GTK_TOOLBAR_SPACE_LINE);
4823 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
4824 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4828 icon_wid, toolbar_send_cb, compose);
4830 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND_QUEUE);
4831 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4833 _("Put into queue folder and send later"),
4835 icon_wid, toolbar_send_later_cb,
4838 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4839 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4841 _("Save to draft folder"),
4843 icon_wid, toolbar_draft_cb,
4846 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4848 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_PASTE);
4849 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4853 icon_wid, toolbar_insert_cb,
4856 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_ATTACH);
4857 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4861 icon_wid, toolbar_attach_cb,
4864 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4866 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4867 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4869 _("Insert signature"),
4871 icon_wid, toolbar_sig_cb, compose);
4873 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4875 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_COMPOSE);
4876 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4878 _("Edit with external editor"),
4881 toolbar_ext_editor_cb,
4884 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_LINEWRAP);
4885 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4887 _("Wrap all long lines"),
4890 toolbar_linewrap_cb,
4893 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4895 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_ADDRESS_BOOK);
4896 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4900 icon_wid, toolbar_address_cb,
4903 compose->toolbar = toolbar;
4904 compose->send_btn = send_btn;
4905 compose->sendl_btn = sendl_btn;
4906 compose->draft_btn = draft_btn;
4907 compose->insert_btn = insert_btn;
4908 compose->attach_btn = attach_btn;
4909 compose->sig_btn = sig_btn;
4910 compose->exteditor_btn = exteditor_btn;
4911 compose->linewrap_btn = linewrap_btn;
4912 compose->addrbook_btn = addrbook_btn;
4914 gtk_widget_show_all(toolbar);
4917 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4923 gint num = 0, def_menu = 0;
4925 accounts = account_get_list();
4926 g_return_val_if_fail(accounts != NULL, NULL);
4928 hbox = gtk_hbox_new(FALSE, 0);
4929 optmenu = gtk_option_menu_new();
4930 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4931 menu = gtk_menu_new();
4933 for (; accounts != NULL; accounts = accounts->next, num++) {
4934 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4935 GtkWidget *menuitem;
4938 if (ac == compose->account) def_menu = num;
4940 name = g_strdup_printf("%s: %s <%s>",
4941 ac->account_name, ac->name, ac->address);
4942 MENUITEM_ADD(menu, menuitem, name, ac);
4944 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4945 GTK_SIGNAL_FUNC(account_activated),
4949 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4950 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4955 static void compose_set_template_menu(Compose *compose)
4957 GSList *tmpl_list, *cur;
4961 tmpl_list = template_get_config();
4963 menu = gtk_menu_new();
4965 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4966 Template *tmpl = (Template *)cur->data;
4968 item = gtk_menu_item_new_with_label(tmpl->name);
4969 gtk_menu_append(GTK_MENU(menu), item);
4970 gtk_signal_connect(GTK_OBJECT(item), "activate",
4971 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4973 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4974 gtk_widget_show(item);
4977 gtk_widget_show(menu);
4978 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4981 void compose_reflect_prefs_all(void)
4986 for (cur = compose_list; cur != NULL; cur = cur->next) {
4987 compose = (Compose *)cur->data;
4988 compose_set_template_menu(compose);
4992 static void compose_template_apply(Compose *compose, Template *tmpl)
4997 if (!tmpl || !tmpl->value) return;
4999 gtk_stext_freeze(GTK_STEXT(compose->text));
5001 if (tmpl->subject && *tmpl->subject != '\0')
5002 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5004 if (tmpl->to && *tmpl->to != '\0')
5005 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5007 gtk_stext_clear(GTK_STEXT(compose->text));
5009 if (compose->replyinfo == NULL) {
5012 memset(&dummyinfo, 0, sizeof(MsgInfo));
5013 parsed_str = compose_quote_fmt(compose, &dummyinfo,
5016 if (prefs_common.quotemark && *prefs_common.quotemark)
5017 qmark = prefs_common.quotemark;
5021 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5022 tmpl->value, qmark);
5025 if (parsed_str && prefs_common.auto_sig)
5026 compose_insert_sig(compose);
5028 gtk_stext_thaw(GTK_STEXT(compose->text));
5031 static void compose_destroy(Compose *compose)
5034 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5037 /* NOTE: address_completion_end() does nothing with the window
5038 * however this may change. */
5039 address_completion_end(compose->window);
5041 slist_free_strings(compose->to_list);
5042 g_slist_free(compose->to_list);
5043 slist_free_strings(compose->newsgroup_list);
5044 g_slist_free(compose->newsgroup_list);
5045 slist_free_strings(compose->header_list);
5046 g_slist_free(compose->header_list);
5048 procmsg_msginfo_free(compose->targetinfo);
5049 procmsg_msginfo_free(compose->replyinfo);
5051 g_free(compose->replyto);
5052 g_free(compose->cc);
5053 g_free(compose->bcc);
5054 g_free(compose->newsgroups);
5055 g_free(compose->followup_to);
5057 g_free(compose->inreplyto);
5058 g_free(compose->references);
5059 g_free(compose->msgid);
5060 g_free(compose->boundary);
5062 if (compose->bounce_filename)
5063 g_free(compose->bounce_filename);
5065 g_free(compose->exteditor_file);
5067 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5069 compose_attach_info_free(ainfo);
5071 if (addressbook_get_target_compose() == compose)
5072 addressbook_set_target_compose(NULL);
5075 if (compose->gtkpspell) {
5076 gtkpspell_delete(compose->gtkpspell);
5080 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5081 prefs_common.compose_height = compose->window->allocation.height;
5083 gtk_widget_destroy(compose->paned);
5087 compose_list = g_list_remove(compose_list, compose);
5090 static void compose_attach_info_free(AttachInfo *ainfo)
5092 g_free(ainfo->file);
5093 g_free(ainfo->content_type);
5094 g_free(ainfo->name);
5098 static void compose_attach_remove_selected(Compose *compose)
5100 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5104 while (clist->selection != NULL) {
5105 row = GPOINTER_TO_INT(clist->selection->data);
5106 ainfo = gtk_clist_get_row_data(clist, row);
5107 compose_attach_info_free(ainfo);
5108 gtk_clist_remove(clist, row);
5112 static struct _AttachProperty
5115 GtkWidget *mimetype_entry;
5116 GtkWidget *encoding_optmenu;
5117 GtkWidget *path_entry;
5118 GtkWidget *filename_entry;
5120 GtkWidget *cancel_btn;
5123 static void compose_attach_property(Compose *compose)
5125 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5128 GtkOptionMenu *optmenu;
5129 static gboolean cancelled;
5131 if (!clist->selection) return;
5132 row = GPOINTER_TO_INT(clist->selection->data);
5134 ainfo = gtk_clist_get_row_data(clist, row);
5137 if (!attach_prop.window)
5138 compose_attach_property_create(&cancelled);
5139 gtk_widget_grab_focus(attach_prop.ok_btn);
5140 gtk_widget_show(attach_prop.window);
5141 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5143 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5144 if (ainfo->encoding == ENC_UNKNOWN)
5145 gtk_option_menu_set_history(optmenu, ENC_BASE64);
5147 gtk_option_menu_set_history(optmenu, ainfo->encoding);
5149 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5150 ainfo->content_type ? ainfo->content_type : "");
5151 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5152 ainfo->file ? ainfo->file : "");
5153 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5154 ainfo->name ? ainfo->name : "");
5158 gchar *cnttype = NULL;
5162 GtkWidget *menuitem;
5167 if (cancelled == TRUE) {
5168 gtk_widget_hide(attach_prop.window);
5172 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5173 if (*text != '\0') {
5176 text = g_strstrip(g_strdup(text));
5177 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5178 cnttype = g_strdup(text);
5181 alertpanel_error(_("Invalid MIME type."));
5187 menu = gtk_option_menu_get_menu(optmenu);
5188 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5189 ainfo->encoding = GPOINTER_TO_INT
5190 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5192 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5193 if (*text != '\0') {
5194 if (is_file_exist(text) &&
5195 (size = get_file_size(text)) > 0)
5196 file = g_strdup(text);
5199 (_("File doesn't exist or is empty."));
5205 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5206 if (*text != '\0') {
5207 g_free(ainfo->name);
5208 ainfo->name = g_strdup(text);
5212 g_free(ainfo->content_type);
5213 ainfo->content_type = cnttype;
5216 g_free(ainfo->file);
5222 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5223 ainfo->content_type);
5224 gtk_clist_set_text(clist, row, COL_SIZE,
5225 to_human_readable(ainfo->size));
5226 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5228 gtk_widget_hide(attach_prop.window);
5233 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5235 label = gtk_label_new(str); \
5236 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5237 GTK_FILL, 0, 0, 0); \
5238 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5240 entry = gtk_entry_new(); \
5241 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5242 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5245 static void compose_attach_property_create(gboolean *cancelled)
5251 GtkWidget *mimetype_entry;
5254 GtkWidget *optmenu_menu;
5255 GtkWidget *menuitem;
5256 GtkWidget *path_entry;
5257 GtkWidget *filename_entry;
5260 GtkWidget *cancel_btn;
5261 GList *mime_type_list, *strlist;
5263 debug_print("Creating attach_property window...\n");
5265 window = gtk_window_new(GTK_WINDOW_DIALOG);
5266 gtk_widget_set_usize(window, 480, -1);
5267 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5268 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
5269 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5270 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5271 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5272 GTK_SIGNAL_FUNC(attach_property_delete_event),
5274 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5275 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5278 vbox = gtk_vbox_new(FALSE, 8);
5279 gtk_container_add(GTK_CONTAINER(window), vbox);
5281 table = gtk_table_new(4, 2, FALSE);
5282 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5283 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5284 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5286 label = gtk_label_new(_("MIME type"));
5287 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5289 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5290 mimetype_entry = gtk_combo_new();
5291 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5292 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5294 /* stuff with list */
5295 mime_type_list = procmime_get_mime_type_list();
5297 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5298 MimeType *type = (MimeType *) mime_type_list->data;
5299 strlist = g_list_append(strlist,
5300 g_strdup_printf("%s/%s",
5301 type->type, type->sub_type));
5304 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5306 for (mime_type_list = strlist; mime_type_list != NULL;
5307 mime_type_list = mime_type_list->next)
5308 g_free(mime_type_list->data);
5309 g_list_free(strlist);
5311 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5313 label = gtk_label_new(_("Encoding"));
5314 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5316 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5318 hbox = gtk_hbox_new(FALSE, 0);
5319 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5320 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5322 optmenu = gtk_option_menu_new();
5323 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5325 optmenu_menu = gtk_menu_new();
5326 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5327 gtk_widget_set_sensitive(menuitem, FALSE);
5328 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5329 gtk_widget_set_sensitive(menuitem, FALSE);
5330 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5331 gtk_widget_set_sensitive(menuitem, FALSE);
5332 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5334 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5336 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5337 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5339 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5340 &cancel_btn, _("Cancel"), NULL, NULL);
5341 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5342 gtk_widget_grab_default(ok_btn);
5344 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5345 GTK_SIGNAL_FUNC(attach_property_ok),
5347 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5348 GTK_SIGNAL_FUNC(attach_property_cancel),
5351 gtk_widget_show_all(vbox);
5353 attach_prop.window = window;
5354 attach_prop.mimetype_entry = mimetype_entry;
5355 attach_prop.encoding_optmenu = optmenu;
5356 attach_prop.path_entry = path_entry;
5357 attach_prop.filename_entry = filename_entry;
5358 attach_prop.ok_btn = ok_btn;
5359 attach_prop.cancel_btn = cancel_btn;
5362 #undef SET_LABEL_AND_ENTRY
5364 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5370 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5376 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5377 gboolean *cancelled)
5385 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5386 gboolean *cancelled)
5388 if (event && event->keyval == GDK_Escape) {
5394 static void compose_exec_ext_editor(Compose *compose)
5400 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5401 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5403 if (pipe(pipe_fds) < 0) {
5408 if ((pid = fork()) < 0) {
5414 /* close the write side of the pipe */
5417 compose->exteditor_file = g_strdup(tmp);
5418 compose->exteditor_pid = pid;
5419 compose->exteditor_readdes = pipe_fds[0];
5421 compose_set_ext_editor_sensitive(compose, FALSE);
5423 compose->exteditor_tag =
5424 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5425 compose_input_cb, compose);
5426 } else { /* process-monitoring process */
5432 /* close the read side of the pipe */
5435 if (compose_write_body_to_file(compose, tmp) < 0) {
5436 fd_write(pipe_fds[1], "2\n", 2);
5440 pid_ed = compose_exec_ext_editor_real(tmp);
5442 fd_write(pipe_fds[1], "1\n", 2);
5446 /* wait until editor is terminated */
5447 waitpid(pid_ed, NULL, 0);
5449 fd_write(pipe_fds[1], "0\n", 2);
5456 static gint compose_exec_ext_editor_real(const gchar *file)
5458 static gchar *def_cmd = "emacs %s";
5464 g_return_val_if_fail(file != NULL, -1);
5466 if ((pid = fork()) < 0) {
5471 if (pid != 0) return pid;
5473 /* grandchild process */
5475 if (setpgid(0, getppid()))
5478 if (prefs_common.ext_editor_cmd &&
5479 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5480 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5481 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5483 if (prefs_common.ext_editor_cmd)
5484 g_warning(_("External editor command line is invalid: `%s'\n"),
5485 prefs_common.ext_editor_cmd);
5486 g_snprintf(buf, sizeof(buf), def_cmd, file);
5489 cmdline = g_strsplit(buf, " ", 1024);
5490 execvp(cmdline[0], cmdline);
5493 g_strfreev(cmdline);
5498 static gboolean compose_ext_editor_kill(Compose *compose)
5500 pid_t pgid = compose->exteditor_pid * -1;
5503 ret = kill(pgid, 0);
5505 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5509 msg = g_strdup_printf
5510 (_("The external editor is still working.\n"
5511 "Force terminating the process?\n"
5512 "process group id: %d"), -pgid);
5513 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5516 if (val == G_ALERTDEFAULT) {
5517 gdk_input_remove(compose->exteditor_tag);
5518 close(compose->exteditor_readdes);
5520 if (kill(pgid, SIGTERM) < 0) perror("kill");
5521 waitpid(compose->exteditor_pid, NULL, 0);
5523 g_warning(_("Terminated process group id: %d"), -pgid);
5524 g_warning(_("Temporary file: %s"),
5525 compose->exteditor_file);
5527 compose_set_ext_editor_sensitive(compose, TRUE);
5529 g_free(compose->exteditor_file);
5530 compose->exteditor_file = NULL;
5531 compose->exteditor_pid = -1;
5532 compose->exteditor_readdes = -1;
5533 compose->exteditor_tag = -1;
5541 static void compose_input_cb(gpointer data, gint source,
5542 GdkInputCondition condition)
5545 Compose *compose = (Compose *)data;
5548 debug_print(_("Compose: input from monitoring process\n"));
5550 gdk_input_remove(compose->exteditor_tag);
5553 if (read(source, &buf[i], 1) < 1) {
5557 if (buf[i] == '\n') {
5562 if (i == sizeof(buf) - 1)
5566 waitpid(compose->exteditor_pid, NULL, 0);
5568 if (buf[0] == '0') { /* success */
5569 GtkSText *text = GTK_STEXT(compose->text);
5571 gtk_stext_freeze(text);
5572 gtk_stext_set_point(text, 0);
5573 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5574 compose_insert_file(compose, compose->exteditor_file);
5575 compose_changed_cb(NULL, compose);
5576 gtk_stext_thaw(text);
5578 if (unlink(compose->exteditor_file) < 0)
5579 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5580 } else if (buf[0] == '1') { /* failed */
5581 g_warning(_("Couldn't exec external editor\n"));
5582 if (unlink(compose->exteditor_file) < 0)
5583 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5584 } else if (buf[0] == '2') {
5585 g_warning(_("Couldn't write to file\n"));
5586 } else if (buf[0] == '3') {
5587 g_warning(_("Pipe read failed\n"));
5592 compose_set_ext_editor_sensitive(compose, TRUE);
5594 g_free(compose->exteditor_file);
5595 compose->exteditor_file = NULL;
5596 compose->exteditor_pid = -1;
5597 compose->exteditor_readdes = -1;
5598 compose->exteditor_tag = -1;
5601 static void compose_set_ext_editor_sensitive(Compose *compose,
5604 GtkItemFactory *ifactory;
5606 ifactory = gtk_item_factory_from_widget(compose->menubar);
5608 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5609 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5610 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5612 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5613 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5614 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5615 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5616 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5619 gtk_widget_set_sensitive(compose->text, sensitive);
5620 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5621 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5622 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5623 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5624 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5625 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5626 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5630 * compose_undo_state_changed:
5632 * Change the sensivity of the menuentries undo and redo
5634 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5635 gint redo_state, gpointer data)
5637 GtkWidget *widget = GTK_WIDGET(data);
5638 GtkItemFactory *ifactory;
5640 g_return_if_fail(widget != NULL);
5642 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
5644 ifactory = gtk_item_factory_from_widget(widget);
5646 switch (undo_state) {
5647 case UNDO_STATE_TRUE:
5648 if (!undostruct->undo_state) {
5649 debug_print ("Set_undo - Testpoint\n");
5650 undostruct->undo_state = TRUE;
5651 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5654 case UNDO_STATE_FALSE:
5655 if (undostruct->undo_state) {
5656 undostruct->undo_state = FALSE;
5657 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5660 case UNDO_STATE_UNCHANGED:
5662 case UNDO_STATE_REFRESH:
5663 menu_set_sensitive(ifactory, "/Edit/Undo",
5664 undostruct->undo_state);
5667 g_warning("Undo state not recognized");
5671 switch (redo_state) {
5672 case UNDO_STATE_TRUE:
5673 if (!undostruct->redo_state) {
5674 undostruct->redo_state = TRUE;
5675 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5678 case UNDO_STATE_FALSE:
5679 if (undostruct->redo_state) {
5680 undostruct->redo_state = FALSE;
5681 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5684 case UNDO_STATE_UNCHANGED:
5686 case UNDO_STATE_REFRESH:
5687 menu_set_sensitive(ifactory, "/Edit/Redo",
5688 undostruct->redo_state);
5691 g_warning("Redo state not recognized");
5696 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5700 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5701 cursor_pos = MAX(cursor_pos, 0);
5706 /* callback functions */
5708 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5709 * includes "non-client" (windows-izm) in calculation, so this calculation
5710 * may not be accurate.
5712 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5713 GtkAllocation *allocation,
5714 GtkSHRuler *shruler)
5716 if (prefs_common.show_ruler) {
5718 gint line_width_in_chars;
5720 char_width = gtkut_get_font_width
5721 (GTK_WIDGET(widget)->style->font);
5722 line_width_in_chars =
5723 (allocation->width - allocation->x) / char_width;
5725 /* got the maximum */
5726 gtk_ruler_set_range(GTK_RULER(shruler),
5727 0.0, line_width_in_chars,
5728 calc_cursor_xpos(GTK_STEXT(widget),
5731 /*line_width_in_chars*/ char_width);
5737 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5739 compose_send_cb(data, 0, NULL);
5742 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5744 compose_send_later_cb(data, 0, NULL);
5747 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5749 compose_draft_cb(data, 0, NULL);
5752 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5754 compose_insert_file_cb(data, 0, NULL);
5757 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5759 compose_attach_cb(data, 0, NULL);
5762 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5764 Compose *compose = (Compose *)data;
5766 compose_insert_sig(compose);
5769 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5771 Compose *compose = (Compose *)data;
5773 compose_exec_ext_editor(compose);
5776 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5778 Compose *compose = (Compose *)data;
5780 compose_wrap_line(compose);
5783 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5785 compose_address_cb(data, 0, NULL);
5788 static void select_account(Compose * compose, PrefsAccount * ac)
5790 compose->account = ac;
5791 compose_set_title(compose);
5793 #if 0 /* NEW COMPOSE GUI */
5794 if (ac->protocol == A_NNTP) {
5795 GtkItemFactory *ifactory;
5796 GtkWidget *menuitem;
5798 ifactory = gtk_item_factory_from_widget(compose->menubar);
5799 menu_set_sensitive(ifactory,
5800 "/Message/Followup to", TRUE);
5801 gtk_widget_show(compose->newsgroups_hbox);
5802 gtk_widget_show(compose->newsgroups_entry);
5803 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5806 compose->use_to = FALSE;
5807 compose->use_cc = FALSE;
5809 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5810 gtk_check_menu_item_set_active
5811 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5813 menu_set_sensitive(ifactory,
5814 "/Message/To", TRUE);
5815 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5816 gtk_check_menu_item_set_active
5817 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5819 gtk_widget_hide(compose->to_hbox);
5820 gtk_widget_hide(compose->to_entry);
5821 gtk_widget_hide(compose->cc_hbox);
5822 gtk_widget_hide(compose->cc_entry);
5823 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5825 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5829 GtkItemFactory *ifactory;
5830 GtkWidget *menuitem;
5832 ifactory = gtk_item_factory_from_widget(compose->menubar);
5833 menu_set_sensitive(ifactory,
5834 "/Message/Followup to", FALSE);
5835 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5836 gtk_widget_hide(compose->newsgroups_hbox);
5837 gtk_widget_hide(compose->newsgroups_entry);
5838 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5841 compose->use_to = TRUE;
5842 compose->use_cc = TRUE;
5844 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5845 gtk_check_menu_item_set_active
5846 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5847 menu_set_sensitive(ifactory,
5848 "/Message/To", FALSE);
5849 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5850 gtk_check_menu_item_set_active
5851 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5852 gtk_widget_show(compose->to_hbox);
5853 gtk_widget_show(compose->to_entry);
5854 gtk_widget_show(compose->cc_hbox);
5855 gtk_widget_show(compose->cc_entry);
5857 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5859 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5862 gtk_widget_queue_resize(compose->table_vbox);
5866 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5868 Compose *compose = (Compose *)data;
5872 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5873 g_return_if_fail(ac != NULL);
5875 if (ac != compose->account)
5876 select_account(compose, ac);
5879 static void attach_selected(GtkCList *clist, gint row, gint column,
5880 GdkEvent *event, gpointer data)
5882 Compose *compose = (Compose *)data;
5884 if (event && event->type == GDK_2BUTTON_PRESS)
5885 compose_attach_property(compose);
5888 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5891 Compose *compose = (Compose *)data;
5892 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5897 if (event->button == 3) {
5898 if ((clist->selection && !clist->selection->next) ||
5899 !clist->selection) {
5900 gtk_clist_unselect_all(clist);
5901 if (gtk_clist_get_selection_info(clist,
5904 gtk_clist_select_row(clist, row, column);
5905 gtkut_clist_set_focus_row(clist, row);
5908 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5909 NULL, NULL, event->button, event->time);
5913 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5916 Compose *compose = (Compose *)data;
5920 switch (event->keyval) {
5922 compose_attach_remove_selected(compose);
5927 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5929 Compose *compose = (Compose *)data;
5932 val = compose_send(compose);
5934 if (val == 0) gtk_widget_destroy(compose->window);
5937 static void compose_send_later_cb(gpointer data, guint action,
5940 Compose *compose = (Compose *)data;
5943 val = compose_queue(compose, NULL, NULL);
5944 if (!val) gtk_widget_destroy(compose->window);
5947 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5949 Compose *compose = (Compose *)data;
5953 static gboolean lock = FALSE;
5957 draft = folder_get_default_draft();
5958 g_return_if_fail(draft != NULL);
5962 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5963 G_DIR_SEPARATOR, (gint)compose);
5965 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5971 folder_item_scan(draft);
5972 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) <= 0) {
5979 draft->mtime = 0; /* force updating */
5981 if (compose->mode == COMPOSE_REEDIT) {
5982 compose_remove_reedit_target(compose);
5983 if (compose->targetinfo &&
5984 compose->targetinfo->folder != draft)
5985 folderview_update_item(compose->targetinfo->folder,
5989 folder_item_scan(draft);
5990 folderview_update_item(draft, TRUE);
5994 /* 0: quit editing 1: keep editing */
5996 gtk_widget_destroy(compose->window);
6001 path = folder_item_fetch_msg(draft, msgnum);
6002 g_return_if_fail(path != NULL);
6003 if (stat(path, &s) < 0) {
6004 FILE_OP_ERROR(path, "stat");
6011 procmsg_msginfo_free(compose->targetinfo);
6012 compose->targetinfo = g_new0(MsgInfo, 1);
6013 compose->targetinfo->msgnum = msgnum;
6014 compose->targetinfo->size = s.st_size;
6015 compose->targetinfo->mtime = s.st_mtime;
6016 compose->targetinfo->folder = draft;
6017 compose->mode = COMPOSE_REEDIT;
6021 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6023 Compose *compose = (Compose *)data;
6026 if (compose->bounce_filename != NULL)
6029 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6034 for ( tmp = file_list; tmp; tmp = tmp->next) {
6035 gchar *file = (gchar *) tmp->data;
6036 compose_attach_append(compose, file, MIME_UNKNOWN);
6039 g_list_free(file_list);
6043 static void compose_insert_file_cb(gpointer data, guint action,
6046 Compose *compose = (Compose *)data;
6049 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6054 for ( tmp = file_list; tmp; tmp = tmp->next) {
6055 gchar *file = (gchar *) tmp->data;
6056 compose_insert_file(compose, file);
6059 g_list_free(file_list);
6063 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6066 compose_close_cb(data, 0, NULL);
6070 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6072 Compose *compose = (Compose *)data;
6075 if (compose->exteditor_tag != -1) {
6076 if (!compose_ext_editor_kill(compose))
6080 if (compose->modified) {
6081 val = alertpanel(_("Discard message"),
6082 _("This message has been modified. discard it?"),
6083 _("Discard"), _("to Draft"), _("Cancel"));
6086 case G_ALERTDEFAULT:
6088 case G_ALERTALTERNATE:
6089 compose_draft_cb(data, 0, NULL);
6095 gtk_widget_destroy(compose->window);
6098 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6100 Compose *compose = (Compose *)data;
6102 addressbook_open(compose);
6105 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6107 Compose *compose = (Compose *)data;
6110 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6111 g_return_if_fail(tmpl != NULL);
6113 compose_template_apply(compose, tmpl);
6116 static void compose_ext_editor_cb(gpointer data, guint action,
6119 Compose *compose = (Compose *)data;
6121 compose_exec_ext_editor(compose);
6124 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6126 compose_destroy(compose);
6129 static void compose_undo_cb(Compose *compose)
6131 undo_undo(compose->undostruct);
6134 static void compose_redo_cb(Compose *compose)
6136 undo_redo(compose->undostruct);
6139 static void compose_cut_cb(Compose *compose)
6141 if (compose->focused_editable &&
6142 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6143 gtk_editable_cut_clipboard
6144 (GTK_EDITABLE(compose->focused_editable));
6147 static void compose_copy_cb(Compose *compose)
6149 if (compose->focused_editable &&
6150 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6151 gtk_editable_copy_clipboard
6152 (GTK_EDITABLE(compose->focused_editable));
6155 static void compose_paste_cb(Compose *compose)
6157 if (compose->focused_editable &&
6158 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6159 gtk_editable_paste_clipboard
6160 (GTK_EDITABLE(compose->focused_editable));
6163 static void compose_allsel_cb(Compose *compose)
6165 if (compose->focused_editable &&
6166 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6167 gtk_editable_select_region
6168 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6171 static void compose_move_beginning_of_line_cb(Compose *compose)
6173 if (compose->focused_editable &&
6174 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6175 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6178 static void compose_gtk_stext_action_cb(Compose *compose, ComposeCallGtkSTextAction action)
6180 if (!(compose->focused_editable && GTK_WIDGET_HAS_FOCUS(compose->focused_editable))) return;
6183 case COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE:
6184 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6186 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER:
6187 gtk_stext_move_forward_character(GTK_STEXT(compose->focused_editable));
6189 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER:
6190 gtk_stext_move_backward_character(GTK_STEXT(compose->focused_editable));
6192 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD:
6193 gtk_stext_move_forward_word(GTK_STEXT(compose->focused_editable));
6195 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD:
6196 gtk_stext_move_backward_word(GTK_STEXT(compose->focused_editable));
6198 case COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE:
6199 gtk_stext_move_end_of_line(GTK_STEXT(compose->focused_editable));
6201 case COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE:
6202 gtk_stext_move_next_line(GTK_STEXT(compose->focused_editable));
6204 case COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE:
6205 gtk_stext_move_previous_line(GTK_STEXT(compose->focused_editable));
6207 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER:
6208 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6210 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER:
6211 gtk_stext_delete_backward_character(GTK_STEXT(compose->focused_editable));
6213 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD:
6214 gtk_stext_delete_forward_word(GTK_STEXT(compose->focused_editable));
6216 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD:
6217 gtk_stext_delete_backward_word(GTK_STEXT(compose->focused_editable));
6219 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE:
6220 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6222 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N:
6223 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6224 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6226 case COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END:
6227 gtk_stext_delete_to_line_end(GTK_STEXT(compose->focused_editable));
6234 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6236 if (GTK_IS_EDITABLE(widget))
6237 compose->focused_editable = widget;
6240 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6242 if (compose->modified == FALSE) {
6243 compose->modified = TRUE;
6244 compose_set_title(compose);
6248 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6251 gtk_stext_set_point(GTK_STEXT(widget),
6252 gtk_editable_get_position(GTK_EDITABLE(widget)));
6256 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6259 gtk_stext_set_point(GTK_STEXT(widget),
6260 gtk_editable_get_position(GTK_EDITABLE(widget)));
6264 #if 0 /* NEW COMPOSE GUI */
6265 static void compose_toggle_to_cb(gpointer data, guint action,
6268 Compose *compose = (Compose *)data;
6270 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6271 gtk_widget_show(compose->to_hbox);
6272 gtk_widget_show(compose->to_entry);
6273 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6274 compose->use_to = TRUE;
6276 gtk_widget_hide(compose->to_hbox);
6277 gtk_widget_hide(compose->to_entry);
6278 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6279 gtk_widget_queue_resize(compose->table_vbox);
6280 compose->use_to = FALSE;
6283 if (addressbook_get_target_compose() == compose)
6284 addressbook_set_target_compose(compose);
6287 static void compose_toggle_cc_cb(gpointer data, guint action,
6290 Compose *compose = (Compose *)data;
6292 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6293 gtk_widget_show(compose->cc_hbox);
6294 gtk_widget_show(compose->cc_entry);
6295 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6296 compose->use_cc = TRUE;
6298 gtk_widget_hide(compose->cc_hbox);
6299 gtk_widget_hide(compose->cc_entry);
6300 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6301 gtk_widget_queue_resize(compose->table_vbox);
6302 compose->use_cc = FALSE;
6305 if (addressbook_get_target_compose() == compose)
6306 addressbook_set_target_compose(compose);
6309 static void compose_toggle_bcc_cb(gpointer data, guint action,
6312 Compose *compose = (Compose *)data;
6314 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6315 gtk_widget_show(compose->bcc_hbox);
6316 gtk_widget_show(compose->bcc_entry);
6317 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6318 compose->use_bcc = TRUE;
6320 gtk_widget_hide(compose->bcc_hbox);
6321 gtk_widget_hide(compose->bcc_entry);
6322 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6323 gtk_widget_queue_resize(compose->table_vbox);
6324 compose->use_bcc = FALSE;
6327 if (addressbook_get_target_compose() == compose)
6328 addressbook_set_target_compose(compose);
6331 static void compose_toggle_replyto_cb(gpointer data, guint action,
6334 Compose *compose = (Compose *)data;
6336 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6337 gtk_widget_show(compose->reply_hbox);
6338 gtk_widget_show(compose->reply_entry);
6339 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6340 compose->use_replyto = TRUE;
6342 gtk_widget_hide(compose->reply_hbox);
6343 gtk_widget_hide(compose->reply_entry);
6344 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6345 gtk_widget_queue_resize(compose->table_vbox);
6346 compose->use_replyto = FALSE;
6350 static void compose_toggle_followupto_cb(gpointer data, guint action,
6353 Compose *compose = (Compose *)data;
6355 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6356 gtk_widget_show(compose->followup_hbox);
6357 gtk_widget_show(compose->followup_entry);
6358 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6359 compose->use_followupto = TRUE;
6361 gtk_widget_hide(compose->followup_hbox);
6362 gtk_widget_hide(compose->followup_entry);
6363 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6364 gtk_widget_queue_resize(compose->table_vbox);
6365 compose->use_followupto = FALSE;
6369 static void compose_toggle_attach_cb(gpointer data, guint action,
6372 Compose *compose = (Compose *)data;
6374 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6375 gtk_widget_ref(compose->edit_vbox);
6377 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6378 compose->edit_vbox);
6379 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6380 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6382 gtk_widget_show(compose->paned);
6384 gtk_widget_unref(compose->edit_vbox);
6385 gtk_widget_unref(compose->paned);
6387 compose->use_attach = TRUE;
6389 gtk_widget_ref(compose->paned);
6390 gtk_widget_ref(compose->edit_vbox);
6392 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6394 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6395 compose->edit_vbox);
6396 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6397 compose->edit_vbox, TRUE, TRUE, 0);
6399 gtk_widget_unref(compose->edit_vbox);
6401 compose->use_attach = FALSE;
6407 static void compose_toggle_sign_cb(gpointer data, guint action,
6410 Compose *compose = (Compose *)data;
6412 if (GTK_CHECK_MENU_ITEM(widget)->active)
6413 compose->use_signing = TRUE;
6415 compose->use_signing = FALSE;
6418 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6421 Compose *compose = (Compose *)data;
6423 if (GTK_CHECK_MENU_ITEM(widget)->active)
6424 compose->use_encryption = TRUE;
6426 compose->use_encryption = FALSE;
6428 #endif /* USE_GPGME */
6430 static void compose_toggle_ruler_cb(gpointer data, guint action,
6433 Compose *compose = (Compose *)data;
6435 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6436 gtk_widget_show(compose->ruler_hbox);
6437 prefs_common.show_ruler = TRUE;
6439 gtk_widget_hide(compose->ruler_hbox);
6440 gtk_widget_queue_resize(compose->edit_vbox);
6441 prefs_common.show_ruler = FALSE;
6445 static void compose_attach_drag_received_cb (GtkWidget *widget,
6446 GdkDragContext *drag_context,
6449 GtkSelectionData *data,
6454 Compose *compose = (Compose *)user_data;
6457 list = uri_list_extract_filenames((const gchar *)data->data);
6458 for (tmp = list; tmp != NULL; tmp = tmp->next)
6459 compose_attach_append(compose, (const gchar *)tmp->data,
6461 list_free_strings(list);
6465 static void compose_insert_drag_received_cb (GtkWidget *widget,
6466 GdkDragContext *drag_context,
6469 GtkSelectionData *data,
6474 Compose *compose = (Compose *)user_data;
6477 list = uri_list_extract_filenames((const gchar *)data->data);
6478 for (tmp = list; tmp != NULL; tmp = tmp->next)
6479 compose_insert_file(compose, (const gchar *)tmp->data);
6480 list_free_strings(list);
6484 #if 0 /* NEW COMPOSE GUI */
6485 static void to_activated(GtkWidget *widget, Compose *compose)
6487 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6488 gtk_widget_grab_focus(compose->newsgroups_entry);
6490 gtk_widget_grab_focus(compose->subject_entry);
6493 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6495 gtk_widget_grab_focus(compose->subject_entry);
6498 static void subject_activated(GtkWidget *widget, Compose *compose)
6500 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6501 gtk_widget_grab_focus(compose->cc_entry);
6502 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6503 gtk_widget_grab_focus(compose->bcc_entry);
6504 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6505 gtk_widget_grab_focus(compose->reply_entry);
6506 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6507 gtk_widget_grab_focus(compose->followup_entry);
6509 gtk_widget_grab_focus(compose->text);
6512 static void cc_activated(GtkWidget *widget, Compose *compose)
6514 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6515 gtk_widget_grab_focus(compose->bcc_entry);
6516 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6517 gtk_widget_grab_focus(compose->reply_entry);
6518 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6519 gtk_widget_grab_focus(compose->followup_entry);
6521 gtk_widget_grab_focus(compose->text);
6524 static void bcc_activated(GtkWidget *widget, Compose *compose)
6526 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6527 gtk_widget_grab_focus(compose->reply_entry);
6528 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6529 gtk_widget_grab_focus(compose->followup_entry);
6531 gtk_widget_grab_focus(compose->text);
6534 static void replyto_activated(GtkWidget *widget, Compose *compose)
6536 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6537 gtk_widget_grab_focus(compose->followup_entry);
6539 gtk_widget_grab_focus(compose->text);
6542 static void followupto_activated(GtkWidget *widget, Compose *compose)
6544 gtk_widget_grab_focus(compose->text);
6548 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6551 Compose *compose = (Compose *)data;
6553 if (GTK_CHECK_MENU_ITEM(widget)->active)
6554 compose->return_receipt = TRUE;
6556 compose->return_receipt = FALSE;
6559 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6561 ComposeHeaderEntry *headerentry)
6563 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6564 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6565 !(event->state & GDK_MODIFIER_MASK) &&
6566 (event->keyval == GDK_BackSpace) &&
6567 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6568 gtk_container_remove
6569 (GTK_CONTAINER(headerentry->compose->header_table),
6570 headerentry->combo);
6571 gtk_container_remove
6572 (GTK_CONTAINER(headerentry->compose->header_table),
6573 headerentry->entry);
6574 headerentry->compose->header_list =
6575 g_slist_remove(headerentry->compose->header_list,
6577 g_free(headerentry);
6578 } else if (event->keyval == GDK_Tab) {
6579 if (headerentry->compose->header_last == headerentry) {
6580 /* Override default next focus, and give it to subject_entry
6581 * instead of notebook tabs
6583 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6584 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6590 void compose_headerentry_changed_cb(GtkWidget *entry,
6591 ComposeHeaderEntry *headerentry)
6593 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6594 headerentry->compose->header_list =
6595 g_slist_append(headerentry->compose->header_list,
6597 compose_create_header_entry(headerentry->compose);
6598 gtk_signal_disconnect_by_func
6600 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6602 /* Automatically scroll down */
6603 compose_show_first_last_header(headerentry->compose, FALSE);
6608 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6610 GtkAdjustment *vadj;
6612 g_return_if_fail(compose);
6613 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6614 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6616 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6617 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6620 static void text_activated(GtkWidget *widget, Compose *compose)
6622 compose_send_control_enter(compose);
6625 static gboolean compose_send_control_enter(Compose *compose)
6629 GtkItemFactory *ifactory;
6630 GtkAccelEntry *accel;
6631 GtkWidget *send_menu;
6634 ev = gtk_get_current_event();
6635 if (ev->type != GDK_KEY_PRESS) return FALSE;
6637 kev = (GdkEventKey *)ev;
6638 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6641 ifactory = gtk_item_factory_from_widget(compose->menubar);
6642 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6643 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6644 accel = (GtkAccelEntry *)list->data;
6645 if (accel->accelerator_key == kev->keyval &&
6646 accel->accelerator_mods == kev->state) {
6647 compose_send_cb(compose, 0, NULL);
6655 static void compose_check_all(Compose *compose)
6657 if (compose->gtkpspell)
6658 gtkpspell_check_all(compose->gtkpspell);
6661 static void compose_highlight_all(Compose *compose)
6663 if (compose->gtkpspell)
6664 gtkpspell_highlight_all(compose->gtkpspell);
6667 static void compose_check_backwards(Compose *compose)
6669 if (compose->gtkpspell)
6670 gtkpspell_check_backwards(compose->gtkpspell);
6672 GtkItemFactory *ifactory;
6673 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6674 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6675 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6679 static void compose_check_forwards_go(Compose *compose)
6681 if (compose->gtkpspell)
6682 gtkpspell_check_forwards_go(compose->gtkpspell);
6684 GtkItemFactory *ifactory;
6685 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6686 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6687 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);