2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
31 #include <gtk/gtkitemfactory.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkclist.h>
36 #include <gtk/gtkctree.h>
37 #include <gtk/gtkvpaned.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkeditable.h>
40 #include <gtk/gtkwindow.h>
41 #include <gtk/gtksignal.h>
42 #include <gtk/gtkvbox.h>
43 #include <gtk/gtkcontainer.h>
44 #include <gtk/gtkhandlebox.h>
45 #include <gtk/gtktoolbar.h>
46 #include <gtk/gtktable.h>
47 #include <gtk/gtkhbox.h>
48 #include <gtk/gtklabel.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtkthemes.h>
51 #include <gtk/gtkdnd.h>
56 #include <sys/types.h>
60 /* #include <sys/utsname.h> */
66 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
73 #include "mainwindow.h"
76 #include "addressbook.h"
77 #include "folderview.h"
80 #include "stock_pixmap.h"
84 #include "customheader.h"
85 #include "prefs_common.h"
86 #include "prefs_account.h"
89 #include "procheader.h"
91 #include "statusbar.h"
98 #include "alertpanel.h"
99 #include "manage_window.h"
100 #include "gtkshruler.h"
102 #include "addr_compl.h"
103 #include "quote_fmt.h"
104 #include "template.h"
106 #include "foldersel.h"
107 #include "prefs_actions.h"
110 # include "rfc2015.h"
120 #define N_ATTACH_COLS 3
124 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
125 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
126 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
127 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
128 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
129 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
130 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
131 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
132 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
133 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
134 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
135 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
136 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
137 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
138 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
139 } ComposeCallGtkSTextAction;
141 #define B64_LINE_SIZE 57
142 #define B64_BUFFSIZE 77
144 #define MAX_REFERENCES_LEN 999
146 static GdkColor quote_color = {0, 0, 0, 0xbfff};
148 static GList *compose_list = NULL;
150 Compose *compose_generic_new (PrefsAccount *account,
154 static Compose *compose_create (PrefsAccount *account,
156 static void compose_toolbar_create (Compose *compose,
157 GtkWidget *container);
158 static GtkWidget *compose_account_option_menu_create
160 static void compose_set_template_menu (Compose *compose);
161 static void compose_template_apply (Compose *compose,
163 static void compose_destroy (Compose *compose);
165 static void compose_entries_set (Compose *compose,
166 const gchar *mailto);
167 static gint compose_parse_header (Compose *compose,
169 static gchar *compose_parse_references (const gchar *ref,
172 static gchar *compose_quote_fmt (Compose *compose,
178 static void compose_reply_set_entry (Compose *compose,
183 followup_and_reply_to);
184 static void compose_reedit_set_entry (Compose *compose,
186 static void compose_insert_sig (Compose *compose);
187 static void compose_insert_file (Compose *compose,
189 static void compose_attach_append (Compose *compose,
192 const gchar *content_type);
193 static void compose_attach_parts (Compose *compose,
195 static void compose_wrap_line (Compose *compose);
196 static void compose_wrap_line_all (Compose *compose);
197 static void compose_set_title (Compose *compose);
199 static PrefsAccount *compose_current_mail_account(void);
200 /* static gint compose_send (Compose *compose); */
201 static gint compose_write_to_file (Compose *compose,
204 static gint compose_write_body_to_file (Compose *compose,
206 static gint compose_save_to_outbox (Compose *compose,
208 static gint compose_remove_reedit_target (Compose *compose);
209 static gint compose_queue (Compose *compose,
212 static void compose_write_attach (Compose *compose,
214 static gint compose_write_headers (Compose *compose,
216 const gchar *charset,
217 EncodingType encoding,
220 static void compose_convert_header (gchar *dest,
224 static void compose_generate_msgid (Compose *compose,
228 static void compose_attach_info_free (AttachInfo *ainfo);
229 static void compose_attach_remove_selected (Compose *compose);
231 static void compose_attach_property (Compose *compose);
232 static void compose_attach_property_create (gboolean *cancelled);
233 static void attach_property_ok (GtkWidget *widget,
234 gboolean *cancelled);
235 static void attach_property_cancel (GtkWidget *widget,
236 gboolean *cancelled);
237 static gint attach_property_delete_event (GtkWidget *widget,
239 gboolean *cancelled);
240 static void attach_property_key_pressed (GtkWidget *widget,
242 gboolean *cancelled);
244 static void compose_exec_ext_editor (Compose *compose);
245 static gint compose_exec_ext_editor_real (const gchar *file);
246 static gboolean compose_ext_editor_kill (Compose *compose);
247 static void compose_input_cb (gpointer data,
249 GdkInputCondition condition);
250 static void compose_set_ext_editor_sensitive (Compose *compose,
253 static void compose_undo_state_changed (UndoMain *undostruct,
258 static gint calc_cursor_xpos (GtkSText *text,
262 static void compose_create_header_entry (Compose *compose);
263 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
265 /* callback functions */
267 static gboolean compose_edit_size_alloc (GtkEditable *widget,
268 GtkAllocation *allocation,
269 GtkSHRuler *shruler);
271 static void toolbar_send_cb (GtkWidget *widget,
273 static void toolbar_send_later_cb (GtkWidget *widget,
275 static void toolbar_draft_cb (GtkWidget *widget,
277 static void toolbar_insert_cb (GtkWidget *widget,
279 static void toolbar_attach_cb (GtkWidget *widget,
281 static void toolbar_sig_cb (GtkWidget *widget,
283 static void toolbar_ext_editor_cb (GtkWidget *widget,
285 static void toolbar_linewrap_cb (GtkWidget *widget,
287 static void toolbar_address_cb (GtkWidget *widget,
290 static void select_account (Compose *compose,
293 static void account_activated (GtkMenuItem *menuitem,
296 static void attach_selected (GtkCList *clist,
301 static void attach_button_pressed (GtkWidget *widget,
302 GdkEventButton *event,
304 static void attach_key_pressed (GtkWidget *widget,
308 static void compose_send_cb (gpointer data,
311 static void compose_send_later_cb (gpointer data,
315 static void compose_draft_cb (gpointer data,
319 static void compose_attach_cb (gpointer data,
322 static void compose_insert_file_cb (gpointer data,
326 static void compose_close_cb (gpointer data,
330 static void compose_address_cb (gpointer data,
333 static void compose_template_activate_cb(GtkWidget *widget,
336 static void compose_ext_editor_cb (gpointer data,
340 static gint compose_delete_cb (GtkWidget *widget,
343 static void compose_destroy_cb (GtkWidget *widget,
346 static void compose_undo_cb (Compose *compose);
347 static void compose_redo_cb (Compose *compose);
348 static void compose_cut_cb (Compose *compose);
349 static void compose_copy_cb (Compose *compose);
350 static void compose_paste_cb (Compose *compose);
351 static void compose_allsel_cb (Compose *compose);
353 static void compose_gtk_stext_action_cb (Compose *compose,
354 ComposeCallGtkSTextAction action);
356 static void compose_grab_focus_cb (GtkWidget *widget,
359 static void compose_changed_cb (GtkEditable *editable,
361 static void compose_button_press_cb (GtkWidget *widget,
362 GdkEventButton *event,
365 static void compose_key_press_cb (GtkWidget *widget,
371 static void compose_toggle_to_cb (gpointer data,
374 static void compose_toggle_cc_cb (gpointer data,
377 static void compose_toggle_bcc_cb (gpointer data,
380 static void compose_toggle_replyto_cb (gpointer data,
383 static void compose_toggle_followupto_cb(gpointer data,
386 static void compose_toggle_attach_cb (gpointer data,
390 static void compose_toggle_ruler_cb (gpointer data,
394 static void compose_toggle_sign_cb (gpointer data,
397 static void compose_toggle_encrypt_cb (gpointer data,
401 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
404 static void compose_attach_drag_received_cb (GtkWidget *widget,
405 GdkDragContext *drag_context,
408 GtkSelectionData *data,
412 static void compose_insert_drag_received_cb (GtkWidget *widget,
413 GdkDragContext *drag_context,
416 GtkSelectionData *data,
422 static void to_activated (GtkWidget *widget,
424 static void newsgroups_activated (GtkWidget *widget,
426 static void subject_activated (GtkWidget *widget,
428 static void cc_activated (GtkWidget *widget,
430 static void bcc_activated (GtkWidget *widget,
432 static void replyto_activated (GtkWidget *widget,
434 static void followupto_activated (GtkWidget *widget,
438 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
440 gboolean ignore_replyto,
441 gboolean followup_and_reply_to,
444 void compose_headerentry_changed_cb (GtkWidget *entry,
445 ComposeHeaderEntry *headerentry);
446 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
448 ComposeHeaderEntry *headerentry);
450 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
453 static void compose_check_all (Compose *compose);
454 static void compose_highlight_all (Compose *compose);
455 static void compose_check_backwards (Compose *compose);
456 static void compose_check_forwards_go (Compose *compose);
459 static gboolean compose_send_control_enter (Compose *compose);
460 static void text_activated (GtkWidget *widget,
463 static GtkItemFactoryEntry compose_popup_entries[] =
465 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
466 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
467 {N_("/---"), NULL, NULL, 0, "<Separator>"},
468 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
471 static GtkItemFactoryEntry compose_entries[] =
473 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
474 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
475 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
476 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
477 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
478 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
480 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
481 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
482 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
483 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
484 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
485 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
486 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
487 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
488 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
489 {N_("/_Edit/A_dvanced/Move a character backward"),
491 compose_gtk_stext_action_cb,
492 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
494 {N_("/_Edit/A_dvanced/Move a character forward"),
496 compose_gtk_stext_action_cb,
497 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
499 {N_("/_Edit/A_dvanced/Move a word backward"),
501 compose_gtk_stext_action_cb,
502 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
504 {N_("/_Edit/A_dvanced/Move a word forward"),
506 compose_gtk_stext_action_cb,
507 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
509 {N_("/_Edit/A_dvanced/Move to beginning of line"),
510 NULL, /* "<control>A" */
511 compose_gtk_stext_action_cb,
512 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
514 {N_("/_Edit/A_dvanced/Move to end of line"),
516 compose_gtk_stext_action_cb,
517 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
519 {N_("/_Edit/A_dvanced/Move to previous line"),
521 compose_gtk_stext_action_cb,
522 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
524 {N_("/_Edit/A_dvanced/Move to next line"),
526 compose_gtk_stext_action_cb,
527 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
529 {N_("/_Edit/A_dvanced/Delete a character backward"),
531 compose_gtk_stext_action_cb,
532 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
534 {N_("/_Edit/A_dvanced/Delete a character forward"),
536 compose_gtk_stext_action_cb,
537 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
539 {N_("/_Edit/A_dvanced/Delete a word backward"),
540 NULL, /* "<control>W" */
541 compose_gtk_stext_action_cb,
542 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
544 {N_("/_Edit/A_dvanced/Delete a word forward"),
545 NULL, /* "<alt>D", */
546 compose_gtk_stext_action_cb,
547 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
549 {N_("/_Edit/A_dvanced/Delete line"),
551 compose_gtk_stext_action_cb,
552 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
554 {N_("/_Edit/A_dvanced/Delete entire line"),
556 compose_gtk_stext_action_cb,
557 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
559 {N_("/_Edit/A_dvanced/Delete to end of line"),
561 compose_gtk_stext_action_cb,
562 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
564 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
565 {N_("/_Edit/_Wrap current paragraph"),
566 "<control>L", compose_wrap_line, 0, NULL},
567 {N_("/_Edit/Wrap all long _lines"),
568 "<control><alt>L", compose_wrap_line_all, 0, NULL},
569 {N_("/_Edit/Edit with e_xternal editor"),
570 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
572 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
573 {N_("/_Spelling/_Check all or check selection"),
574 NULL, compose_check_all, 0, NULL},
575 {N_("/_Spelling/_Highlight all misspelled words"),
576 NULL, compose_highlight_all, 0, NULL},
577 {N_("/_Spelling/Check _backwards misspelled word"),
578 NULL, compose_check_backwards , 0, NULL},
579 {N_("/_Spelling/_Forward to next misspelled word"),
580 NULL, compose_check_forwards_go, 0, NULL},
581 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
582 {N_("/_Spelling/_Spelling Configuration"),
583 NULL, NULL, 0, "<Branch>"},
585 #if 0 /* NEW COMPOSE GUI */
586 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
587 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
588 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
589 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
590 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
591 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
592 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
593 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
594 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
595 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
596 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
598 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
599 {N_("/_Message/_Send"), "<control>Return",
600 compose_send_cb, 0, NULL},
601 {N_("/_Message/Send _later"), "<shift><control>S",
602 compose_send_later_cb, 0, NULL},
603 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
604 {N_("/_Message/Save to _draft folder"),
605 "<shift><control>D", compose_draft_cb, 0, NULL},
606 {N_("/_Message/Save and _keep editing"),
607 "<control>S", compose_draft_cb, 1, NULL},
608 #if 0 /* NEW COMPOSE GUI */
609 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
610 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
611 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
612 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
613 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
614 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
615 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
616 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
617 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
620 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
621 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
622 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
623 #endif /* USE_GPGME */
624 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
625 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
626 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
627 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
628 {N_("/_Tool/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
629 {N_("/_Tool/_Template"), NULL, NULL, 0, "<Branch>"},
630 {N_("/_Tool/Actio_ns"), NULL, NULL, 0, "<Branch>"},
631 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
632 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
635 static GtkTargetEntry compose_mime_types[] =
637 {"text/uri-list", 0, 0}
640 Compose *compose_new(PrefsAccount *account)
642 return compose_generic_new(account, NULL, NULL);
645 Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
649 GtkItemFactory *ifactory;
651 c = compose_generic_new(account, NULL, NULL);
653 filename = procmsg_get_message_file(msginfo);
654 if (filename == NULL)
657 c->bounce_filename = filename;
659 if (msginfo->subject)
660 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
662 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
664 compose_quote_fmt(c, msginfo, "%M", NULL, NULL);
665 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
667 ifactory = gtk_item_factory_from_widget(c->popupmenu);
668 menu_set_sensitive(ifactory, "/Add...", FALSE);
669 menu_set_sensitive(ifactory, "/Remove", FALSE);
670 menu_set_sensitive(ifactory, "/Property...", FALSE);
672 ifactory = gtk_item_factory_from_widget(c->menubar);
673 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
674 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
675 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
676 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
677 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
678 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
679 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
680 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
682 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
683 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
685 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
686 menu_set_sensitive(ifactory, "/Tool/Template", FALSE);
688 gtk_widget_set_sensitive(c->insert_btn, FALSE);
689 gtk_widget_set_sensitive(c->attach_btn, FALSE);
690 gtk_widget_set_sensitive(c->sig_btn, FALSE);
691 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
692 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
697 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
699 return compose_generic_new(account, mailto, NULL);
702 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
704 return compose_generic_new(account, NULL, item);
707 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
711 if (item && item->prefs && item->prefs->enable_default_account)
712 account = account_find_from_id(item->prefs->default_account);
714 if (!account) account = cur_account;
715 g_return_val_if_fail(account != NULL, NULL);
717 compose = compose_create(account, COMPOSE_NEW);
718 compose->replyinfo = NULL;
720 if (prefs_common.auto_sig)
721 compose_insert_sig(compose);
722 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
723 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
725 if (account->protocol != A_NNTP) {
727 compose_entries_set(compose, mailto);
729 } else if(item && item->prefs->enable_default_to) {
730 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
732 if (item && item->ret_rcpt) {
733 GtkItemFactory *ifactory;
735 ifactory = gtk_item_factory_from_widget(compose->menubar);
736 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
740 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
743 compose_show_first_last_header(compose, TRUE);
745 /* Set save folder */
746 if(item && item->prefs && item->prefs->save_copy_to_folder) {
747 gchar *folderidentifier;
749 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
750 folderidentifier = folder_item_get_identifier(item);
751 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
752 g_free(folderidentifier);
755 gtk_widget_grab_focus(compose->header_last->entry);
757 if (prefs_common.auto_exteditor)
758 compose_exec_ext_editor(compose);
763 #define CHANGE_FLAGS(msginfo) \
765 if (msginfo->folder->folder->change_flags != NULL) \
766 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
772 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
773 const gchar *followupto, gchar * to)
777 if (!account) account = cur_account;
778 g_return_val_if_fail(account != NULL, NULL);
779 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
781 compose = compose_create(account, COMPOSE_NEW);
783 if (prefs_common.auto_sig)
784 compose_insert_sig(compose);
785 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
786 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
788 compose_entry_append(compose, to, COMPOSE_TO);
789 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
790 gtk_widget_grab_focus(compose->subject_entry);
796 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
797 gboolean ignore_replyto, const gchar *body)
799 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE,
803 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
805 gboolean ignore_replyto,
808 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE,
812 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
814 gboolean ignore_replyto,
815 gboolean followup_and_reply_to,
819 PrefsAccount *account;
820 PrefsAccount *reply_account;
823 g_return_if_fail(msginfo != NULL);
824 g_return_if_fail(msginfo->folder != NULL);
827 /* select the account set in folderitem's property (if enabled) */
828 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
829 account = account_find_from_id(msginfo->folder->prefs->default_account);
831 /* select the account for the whole folder (IMAP / NNTP) */
833 /* FIXME: this is not right, because folder may be nested. we should
834 * ascend the tree until we find a parent with proper account
836 account = msginfo->folder->folder->account;
838 /* select account by to: and cc: header if enabled */
839 if (prefs_common.reply_account_autosel) {
840 if (!account && msginfo->to) {
842 Xstrdup_a(to, msginfo->to, return);
844 account = account_find_from_address(to);
848 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
850 account = account_find_from_address(cc);
855 /* select current account */
856 if (!account) account = cur_account;
857 g_return_if_fail(account != NULL);
859 if (ignore_replyto && account->protocol == A_NNTP &&
860 !followup_and_reply_to) {
862 account_find_from_address(account->address);
864 reply_account = compose_current_mail_account();
868 reply_account = account;
870 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
871 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
872 if (MSG_IS_IMAP(msginfo->flags))
873 imap_msg_set_perm_flags(msginfo, MSG_REPLIED);
874 CHANGE_FLAGS(msginfo);
876 compose = compose_create(account, COMPOSE_REPLY);
877 compose->replyinfo = procmsg_msginfo_copy(msginfo);
879 #if 0 /* NEW COMPOSE GUI */
880 if (followup_and_reply_to) {
881 gtk_widget_show(compose->to_hbox);
882 gtk_widget_show(compose->to_entry);
883 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
884 compose->use_to = TRUE;
887 if (msginfo->folder && msginfo->folder->ret_rcpt) {
888 GtkItemFactory *ifactory;
890 ifactory = gtk_item_factory_from_widget(compose->menubar);
891 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
894 /* Set save folder */
895 if(msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
896 gchar *folderidentifier;
898 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
899 folderidentifier = folder_item_get_identifier(msginfo->folder);
900 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
901 g_free(folderidentifier);
904 if (compose_parse_header(compose, msginfo) < 0) return;
905 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
906 followup_and_reply_to);
907 compose_show_first_last_header(compose, TRUE);
909 text = GTK_STEXT(compose->text);
910 gtk_stext_freeze(text);
916 if (prefs_common.quotemark && *prefs_common.quotemark)
917 qmark = prefs_common.quotemark;
921 quote_str = compose_quote_fmt(compose, msginfo,
922 prefs_common.quotefmt,
926 if (prefs_common.auto_sig)
927 compose_insert_sig(compose);
929 if (quote && prefs_common.linewrap_quote)
930 compose_wrap_line_all(compose);
932 gtk_editable_set_position(GTK_EDITABLE(text), 0);
933 gtk_stext_set_point(text, 0);
935 gtk_stext_thaw(text);
936 gtk_widget_grab_focus(compose->text);
938 if (prefs_common.auto_exteditor)
939 compose_exec_ext_editor(compose);
942 static void set_toolbar_style(Compose *compose);
944 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
949 g_return_val_if_fail(mimeinfo != NULL, NULL);
951 base = mimeinfo->filename ? mimeinfo->filename
952 : mimeinfo->name ? mimeinfo->name : NULL;
954 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
955 filename = g_strdup_printf("%s%smimetmp.%08x.html",
962 base = base ? base : "";
963 base = g_basename(base);
965 filename = g_strdup_printf("%s%smimetmp.%08x",
973 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
979 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
983 if (!partinfo) return NULL;
985 filename = procmime_get_file_name(partinfo);
987 if (procmime_get_part(filename, source, partinfo) < 0)
989 (_("Can't get the part of multipart message."));
996 #define INSERT_FW_HEADER(var, hdr) \
997 if (msginfo->var && *msginfo->var) { \
998 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
999 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1000 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1003 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1004 gboolean as_attach, const gchar *body)
1007 /* PrefsAccount *account; */
1010 g_return_val_if_fail(msginfo != NULL, NULL);
1011 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1013 account = msginfo->folder->folder->account;
1014 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1016 Xstrdup_a(to, msginfo->to, return NULL);
1017 extract_address(to);
1018 account = account_find_from_address(to);
1021 if(!account && prefs_common.forward_account_autosel) {
1023 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1024 extract_address(cc);
1025 account = account_find_from_address(cc);
1029 if (account == NULL) {
1030 account = cur_account;
1032 account = msginfo->folder->folder->account;
1033 if (!account) account = cur_account;
1036 g_return_val_if_fail(account != NULL, NULL);
1038 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1039 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1040 if (MSG_IS_IMAP(msginfo->flags))
1041 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1042 CHANGE_FLAGS(msginfo);
1044 compose = compose_create(account, COMPOSE_FORWARD);
1046 if (msginfo->subject && *msginfo->subject) {
1047 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1048 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1052 text = GTK_STEXT(compose->text);
1053 gtk_stext_freeze(text);
1059 msgfile = procmsg_get_message_file_path(msginfo);
1060 if (!is_file_exist(msgfile))
1061 g_warning(_("%s: file not exist\n"), msgfile);
1063 compose_attach_append(compose, msgfile, msgfile,
1071 if (prefs_common.fw_quotemark &&
1072 *prefs_common.fw_quotemark)
1073 qmark = prefs_common.fw_quotemark;
1077 quote_str = compose_quote_fmt(compose, msginfo,
1078 prefs_common.fw_quotefmt,
1080 compose_attach_parts(compose, msginfo);
1083 if (prefs_common.auto_sig)
1084 compose_insert_sig(compose);
1086 if (prefs_common.linewrap_quote)
1087 compose_wrap_line_all(compose);
1089 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1090 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1092 gtk_stext_thaw(text);
1093 #if 0 /* NEW COMPOSE GUI */
1094 if (account->protocol != A_NNTP)
1095 gtk_widget_grab_focus(compose->to_entry);
1097 gtk_widget_grab_focus(compose->newsgroups_entry);
1099 gtk_widget_grab_focus(compose->header_last->entry);
1101 if (prefs_common.auto_exteditor)
1102 compose_exec_ext_editor(compose);
1107 #undef INSERT_FW_HEADER
1109 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1116 g_return_val_if_fail(msginfo_list != NULL, NULL);
1118 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1119 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1123 if (account == NULL) {
1124 account = cur_account;
1126 account = msginfo->folder->folder->account;
1127 if (!account) account = cur_account;
1130 g_return_val_if_fail(account != NULL, NULL);
1132 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1133 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1134 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1135 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1138 compose = compose_create(account, COMPOSE_FORWARD);
1140 text = GTK_STEXT(compose->text);
1141 gtk_stext_freeze(text);
1143 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1144 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1145 if (!is_file_exist(msgfile))
1146 g_warning(_("%s: file not exist\n"), msgfile);
1148 compose_attach_append(compose, msgfile, msgfile,
1153 if (prefs_common.auto_sig)
1154 compose_insert_sig(compose);
1156 if (prefs_common.linewrap_quote)
1157 compose_wrap_line_all(compose);
1159 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1160 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1162 gtk_stext_thaw(text);
1163 #if 0 /* NEW COMPOSE GUI */
1164 if (account->protocol != A_NNTP)
1165 gtk_widget_grab_focus(compose->to_entry);
1167 gtk_widget_grab_focus(compose->newsgroups_entry);
1173 void compose_reedit(MsgInfo *msginfo)
1176 PrefsAccount *account = NULL;
1179 gchar buf[BUFFSIZE];
1181 g_return_if_fail(msginfo != NULL);
1182 g_return_if_fail(msginfo->folder != NULL);
1184 if (msginfo->folder->stype == F_QUEUE) {
1185 gchar queueheader_buf[BUFFSIZE];
1188 /* Select Account from queue headers */
1189 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1190 sizeof(queueheader_buf), "NAID:")) {
1191 id = atoi(&queueheader_buf[5]);
1192 account = account_find_from_id(id);
1194 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1195 sizeof(queueheader_buf), "MAID:")) {
1196 id = atoi(&queueheader_buf[5]);
1197 account = account_find_from_id(id);
1199 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1200 sizeof(queueheader_buf), "S:")) {
1201 account = account_find_from_address(queueheader_buf);
1204 account = msginfo->folder->folder->account;
1206 if (!account && prefs_common.reedit_account_autosel) {
1207 gchar from[BUFFSIZE];
1208 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1209 extract_address(from);
1210 account = account_find_from_address(from);
1213 if (!account) account = cur_account;
1214 g_return_if_fail(account != NULL);
1216 compose = compose_create(account, COMPOSE_REEDIT);
1217 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1219 if (msginfo->folder->stype == F_QUEUE) {
1220 gchar queueheader_buf[BUFFSIZE];
1222 /* Set message save folder */
1223 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1226 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1227 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1228 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1232 if (compose_parse_header(compose, msginfo) < 0) return;
1233 compose_reedit_set_entry(compose, msginfo);
1235 text = GTK_STEXT(compose->text);
1236 gtk_stext_freeze(text);
1238 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1239 g_warning(_("Can't get text part\n"));
1241 while (fgets(buf, sizeof(buf), fp) != NULL)
1242 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1245 compose_attach_parts(compose, msginfo);
1247 gtk_stext_thaw(text);
1248 gtk_widget_grab_focus(compose->text);
1250 if (prefs_common.auto_exteditor)
1251 compose_exec_ext_editor(compose);
1254 GList *compose_get_compose_list(void)
1256 return compose_list;
1259 void compose_entry_append(Compose *compose, const gchar *address,
1260 ComposeEntryType type)
1266 if (!address || *address == '\0') return;
1268 #if 0 /* NEW COMPOSE GUI */
1271 entry = GTK_ENTRY(compose->cc_entry);
1274 entry = GTK_ENTRY(compose->bcc_entry);
1276 case COMPOSE_NEWSGROUPS:
1277 entry = GTK_ENTRY(compose->newsgroups_entry);
1281 entry = GTK_ENTRY(compose->to_entry);
1285 text = gtk_entry_get_text(entry);
1287 gtk_entry_append_text(entry, ", ");
1288 gtk_entry_append_text(entry, address);
1296 header = N_("Bcc:");
1298 case COMPOSE_REPLYTO:
1299 header = N_("Reply-To:");
1301 case COMPOSE_NEWSGROUPS:
1302 header = N_("Newsgroups:");
1304 case COMPOSE_FOLLOWUPTO:
1305 header = N_( "Followup-To:");
1312 header = prefs_common.trans_hdr ? gettext(header) : header;
1314 compose_add_header_entry(compose, header, (gchar *)address);
1317 static void compose_entries_set(Compose *compose, const gchar *mailto)
1319 gchar *subject = NULL;
1327 Xstrdup_a(tmp_mailto, mailto, return);
1331 p = strchr(tmp_mailto, '?');
1338 gchar *field, *value;
1355 if (*value == '\0') continue;
1357 if (!g_strcasecmp(field, "subject")) {
1358 Xalloca(subject, strlen(value) + 1, return);
1359 decode_uri(subject, value);
1360 } else if (!g_strcasecmp(field, "cc")) {
1362 } else if (!g_strcasecmp(field, "bcc")) {
1364 } else if (!g_strcasecmp(field, "body")) {
1365 Xalloca(body, strlen(value) + 1, return);
1366 decode_uri(body, value);
1371 compose_entry_append(compose, to, COMPOSE_TO);
1373 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1375 compose_entry_append(compose, cc, COMPOSE_CC);
1377 compose_entry_append(compose, bcc, COMPOSE_BCC);
1379 gtk_stext_insert(GTK_STEXT(compose->text),
1380 NULL, NULL, NULL, body, -1);
1381 gtk_stext_insert(GTK_STEXT(compose->text),
1382 NULL, NULL, NULL, "\n", 1);
1386 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1388 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1389 {"Cc:", NULL, FALSE},
1390 {"References:", NULL, FALSE},
1391 {"Bcc:", NULL, FALSE},
1392 {"Newsgroups:", NULL, FALSE},
1393 {"Followup-To:", NULL, FALSE},
1394 {"X-Mailing-List:", NULL, FALSE},
1395 {"X-BeenThere:", NULL, FALSE},
1396 {NULL, NULL, FALSE}};
1406 H_X_MAILING_LIST = 6,
1412 g_return_val_if_fail(msginfo != NULL, -1);
1414 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1415 procheader_get_header_fields(fp, hentry);
1418 if (hentry[H_REPLY_TO].body != NULL) {
1419 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1420 compose->replyto = hentry[H_REPLY_TO].body;
1421 hentry[H_REPLY_TO].body = NULL;
1423 if (hentry[H_CC].body != NULL) {
1424 conv_unmime_header_overwrite(hentry[H_CC].body);
1425 compose->cc = hentry[H_CC].body;
1426 hentry[H_CC].body = NULL;
1428 if (hentry[H_X_MAILING_LIST].body != NULL) {
1429 /* this is good enough to parse debian-devel */
1430 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1431 g_return_val_if_fail(buf != NULL, -1 );
1432 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1433 compose->mailinglist = g_strdup(buf);
1435 g_free(hentry[H_X_MAILING_LIST].body);
1436 hentry[H_X_MAILING_LIST].body = NULL ;
1438 if (hentry[H_X_BEENTHERE].body != NULL) {
1439 /* this is good enough to parse the sylpheed-claws lists */
1440 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1441 g_return_val_if_fail(buf != NULL, -1 );
1442 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1443 compose->mailinglist = g_strdup(buf);
1445 g_free(hentry[H_X_BEENTHERE].body);
1446 hentry[H_X_BEENTHERE].body = NULL ;
1448 if (hentry[H_REFERENCES].body != NULL) {
1449 if (compose->mode == COMPOSE_REEDIT)
1450 compose->references = hentry[H_REFERENCES].body;
1452 compose->references = compose_parse_references
1453 (hentry[H_REFERENCES].body, msginfo->msgid);
1454 g_free(hentry[H_REFERENCES].body);
1456 hentry[H_REFERENCES].body = NULL;
1458 if (hentry[H_BCC].body != NULL) {
1459 if (compose->mode == COMPOSE_REEDIT) {
1460 conv_unmime_header_overwrite(hentry[H_BCC].body);
1461 compose->bcc = hentry[H_BCC].body;
1463 g_free(hentry[H_BCC].body);
1464 hentry[H_BCC].body = NULL;
1466 if (hentry[H_NEWSGROUPS].body != NULL) {
1467 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1468 hentry[H_NEWSGROUPS].body = NULL;
1470 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1471 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1472 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1473 hentry[H_FOLLOWUP_TO].body = NULL;
1476 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1477 compose->inreplyto = g_strdup(msginfo->inreplyto);
1478 else if (compose->mode != COMPOSE_REEDIT &&
1479 msginfo->msgid && *msginfo->msgid) {
1480 compose->inreplyto = g_strdup(msginfo->msgid);
1482 if (!compose->references) {
1483 if (msginfo->inreplyto && *msginfo->inreplyto)
1484 compose->references =
1485 g_strdup_printf("<%s>\n\t<%s>",
1489 compose->references =
1490 g_strconcat("<", msginfo->msgid, ">",
1498 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1500 GSList *ref_id_list, *cur;
1504 ref_id_list = references_list_append(NULL, ref);
1505 if (!ref_id_list) return NULL;
1506 if (msgid && *msgid)
1507 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1512 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1513 /* "<" + Message-ID + ">" + CR+LF+TAB */
1514 len += strlen((gchar *)cur->data) + 5;
1516 if (len > MAX_REFERENCES_LEN) {
1517 /* remove second message-ID */
1518 if (ref_id_list && ref_id_list->next &&
1519 ref_id_list->next->next) {
1520 g_free(ref_id_list->next->data);
1521 ref_id_list = g_slist_remove
1522 (ref_id_list, ref_id_list->next->data);
1524 slist_free_strings(ref_id_list);
1525 g_slist_free(ref_id_list);
1532 new_ref = g_string_new("");
1533 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1534 if (new_ref->len > 0)
1535 g_string_append(new_ref, "\n\t");
1536 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1539 slist_free_strings(ref_id_list);
1540 g_slist_free(ref_id_list);
1542 new_ref_str = new_ref->str;
1543 g_string_free(new_ref, FALSE);
1548 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1549 const gchar *fmt, const gchar *qmark,
1552 GtkSText *text = GTK_STEXT(compose->text);
1553 gchar *quote_str = NULL;
1558 if (qmark != NULL) {
1559 quote_fmt_init(msginfo, NULL, NULL);
1560 quote_fmt_scan_string(qmark);
1563 buf = quote_fmt_get_buffer();
1565 alertpanel_error(_("Quote mark format error."));
1567 Xstrdup_a(quote_str, buf, return NULL)
1570 if (fmt && *fmt != '\0') {
1571 quote_fmt_init(msginfo, quote_str, body);
1572 quote_fmt_scan_string(fmt);
1575 buf = quote_fmt_get_buffer();
1577 alertpanel_error(_("Message reply/forward format error."));
1583 gtk_stext_freeze(text);
1585 for (p = buf; *p != '\0'; ) {
1586 lastp = strchr(p, '\n');
1587 len = lastp ? lastp - p + 1 : -1;
1588 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1595 gtk_stext_thaw(text);
1600 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1601 gboolean to_all, gboolean ignore_replyto,
1602 gboolean followup_and_reply_to)
1604 GSList *cc_list = NULL;
1607 gchar *replyto = NULL;
1608 GHashTable *to_table;
1610 g_return_if_fail(compose->account != NULL);
1611 g_return_if_fail(msginfo != NULL);
1613 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1614 compose_entry_append(compose,
1615 ((compose->replyto && !ignore_replyto)
1617 : (compose->mailinglist && !ignore_replyto)
1618 ? compose->mailinglist
1619 : msginfo->from ? msginfo->from : ""),
1622 if (compose->account->protocol == A_NNTP) {
1624 compose_entry_append
1625 (compose, msginfo->from ? msginfo->from : "",
1628 compose_entry_append
1630 compose->followup_to ? compose->followup_to
1631 : compose->newsgroups ? compose->newsgroups
1633 COMPOSE_NEWSGROUPS);
1636 if (msginfo->subject && *msginfo->subject) {
1637 gchar *buf, *buf2, *p;
1639 buf = g_strdup(msginfo->subject);
1640 while (!strncasecmp(buf, "Re:", 3)) {
1642 while (isspace(*p)) p++;
1643 memmove(buf, p, strlen(p) + 1);
1646 buf2 = g_strdup_printf("Re: %s", buf);
1647 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1651 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1653 if (!to_all || compose->account->protocol == A_NNTP) return;
1655 if (compose->replyto) {
1656 Xstrdup_a(replyto, compose->replyto, return);
1657 extract_address(replyto);
1659 if (msginfo->from) {
1660 Xstrdup_a(from, msginfo->from, return);
1661 extract_address(from);
1664 if (compose->mailinglist && from) {
1665 cc_list = address_list_append(cc_list, from);
1668 if (replyto && from)
1669 cc_list = address_list_append(cc_list, from);
1671 if (!compose->mailinglist)
1672 cc_list = address_list_append(cc_list, msginfo->to);
1674 cc_list = address_list_append(cc_list, compose->cc);
1676 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1678 g_hash_table_insert(to_table, replyto, GINT_TO_POINTER(1));
1679 if (compose->account)
1680 g_hash_table_insert(to_table, compose->account->address,
1681 GINT_TO_POINTER(1));
1683 /* remove address on To: and that of current account */
1684 for (cur = cc_list; cur != NULL; ) {
1685 GSList *next = cur->next;
1687 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1688 cc_list = g_slist_remove(cc_list, cur->data);
1690 g_hash_table_insert(to_table, cur->data, cur);
1694 g_hash_table_destroy(to_table);
1697 for (cur = cc_list; cur != NULL; cur = cur->next)
1698 compose_entry_append(compose, (gchar *)cur->data,
1700 slist_free_strings(cc_list);
1701 g_slist_free(cc_list);
1705 #define SET_ENTRY(entry, str) \
1708 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1711 #define SET_ADDRESS(type, str) \
1714 compose_entry_append(compose, str, type); \
1717 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1719 g_return_if_fail(msginfo != NULL);
1721 SET_ENTRY(subject_entry, msginfo->subject);
1722 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1723 SET_ADDRESS(COMPOSE_CC, compose->cc);
1724 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1725 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1727 compose_show_first_last_header(compose, TRUE);
1729 #if 0 /* NEW COMPOSE GUI */
1731 GtkItemFactory *ifactory;
1732 GtkWidget *menuitem;
1734 ifactory = gtk_item_factory_from_widget(compose->menubar);
1735 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1736 gtk_check_menu_item_set_active
1737 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1739 if (compose->replyto) {
1740 GtkItemFactory *ifactory;
1741 GtkWidget *menuitem;
1743 ifactory = gtk_item_factory_from_widget(compose->menubar);
1744 menuitem = gtk_item_factory_get_item
1745 (ifactory, "/View/Reply to");
1746 gtk_check_menu_item_set_active
1747 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1755 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1762 size_t buf_len = 128;
1764 if (strlen(sigfile) < 2)
1767 sigprg = popen(sigfile+1, "r");
1770 buf = g_malloc(buf_len);
1773 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1774 "Unable to insert signature (malloc failed)\n", -1);
1780 while (!feof(sigprg)) {
1781 bzero(buf, buf_len);
1782 fread(buf, buf_len-1, 1, sigprg);
1783 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1791 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1792 "Can't exec file: ", -1);
1793 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1798 static void compose_insert_sig(Compose *compose)
1802 if (compose->account && compose->account->sig_path)
1803 sigfile = g_strdup(compose->account->sig_path);
1805 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1806 DEFAULT_SIGNATURE, NULL);
1808 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1813 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1814 if (prefs_common.sig_sep) {
1815 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1816 prefs_common.sig_sep, -1);
1817 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1821 if (sigfile[0] == '|')
1822 compose_exec_sig(compose, sigfile);
1824 compose_insert_file(compose, sigfile);
1828 static void compose_insert_file(Compose *compose, const gchar *file)
1830 GtkSText *text = GTK_STEXT(compose->text);
1831 gchar buf[BUFFSIZE];
1835 g_return_if_fail(file != NULL);
1837 if ((fp = fopen(file, "rb")) == NULL) {
1838 FILE_OP_ERROR(file, "fopen");
1842 gtk_stext_freeze(text);
1844 while (fgets(buf, sizeof(buf), fp) != NULL) {
1845 /* strip <CR> if DOS/Windows file,
1846 replace <CR> with <LF> if Macintosh file. */
1849 if (len > 0 && buf[len - 1] != '\n') {
1851 if (buf[len] == '\r') buf[len] = '\n';
1853 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1856 gtk_stext_thaw(text);
1861 static void compose_attach_append(Compose *compose, const gchar *file,
1862 const gchar *filename,
1863 const gchar *content_type)
1866 gchar *text[N_ATTACH_COLS];
1871 if (!is_file_exist(file)) {
1872 g_warning(_("File %s doesn't exist\n"), file);
1875 if ((size = get_file_size(file)) < 0) {
1876 g_warning(_("Can't get file size of %s\n"), file);
1880 alertpanel_notice(_("File %s is empty."), file);
1883 if ((fp = fopen(file, "rb")) == NULL) {
1884 alertpanel_error(_("Can't read %s."), file);
1889 #if 0 /* NEW COMPOSE GUI */
1890 if (!compose->use_attach) {
1891 GtkItemFactory *ifactory;
1892 GtkWidget *menuitem;
1894 ifactory = gtk_item_factory_from_widget(compose->menubar);
1895 menuitem = gtk_item_factory_get_item(ifactory,
1896 "/View/Attachment");
1897 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1901 ainfo = g_new0(AttachInfo, 1);
1902 ainfo->file = g_strdup(file);
1905 ainfo->content_type = g_strdup(content_type);
1906 if (!strcasecmp(content_type, "message/rfc822")) {
1907 ainfo->encoding = ENC_7BIT;
1908 ainfo->name = g_strdup_printf
1910 g_basename(filename ? filename : file));
1912 ainfo->encoding = ENC_BASE64;
1913 ainfo->name = g_strdup
1914 (g_basename(filename ? filename : file));
1917 ainfo->content_type = procmime_get_mime_type(file);
1918 if (!ainfo->content_type)
1919 ainfo->content_type =
1920 g_strdup("application/octet-stream");
1921 ainfo->encoding = ENC_BASE64;
1922 ainfo->name = g_strdup(g_basename(filename ? filename : file));
1926 text[COL_MIMETYPE] = ainfo->content_type;
1927 text[COL_SIZE] = to_human_readable(size);
1928 text[COL_NAME] = ainfo->name;
1930 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1931 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1934 #define IS_FIRST_PART_TEXT(info) \
1935 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
1936 info->mime_type == MIME_TEXT_ENRICHED) || \
1937 (info->mime_type == MIME_MULTIPART && info->content_type && \
1938 !strcasecmp(info->content_type, "multipart/alternative") && \
1939 (info->children && \
1940 (info->children->mime_type == MIME_TEXT || \
1941 info->children->mime_type == MIME_TEXT_HTML || \
1942 info->children->mime_type == MIME_TEXT_ENRICHED))))
1944 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
1951 mimeinfo = procmime_scan_message(msginfo);
1952 if (!mimeinfo) return;
1954 /* skip first text (presumably message body) */
1955 child = mimeinfo->children;
1956 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
1957 procmime_mimeinfo_free_all(mimeinfo);
1960 if (IS_FIRST_PART_TEXT(child))
1961 child = child->next;
1963 infile = procmsg_get_message_file_path(msginfo);
1965 while (child != NULL) {
1966 if (child->children || child->mime_type == MIME_MULTIPART) {
1967 child = procmime_mimeinfo_next(child);
1971 outfile = procmime_get_tmp_file_name(child);
1972 if (procmime_get_part(outfile, infile, child) < 0)
1973 g_warning(_("Can't get the part of multipart message."));
1975 compose_attach_append
1977 child->filename ? child->filename : child->name,
1978 child->content_type);
1980 child = child->next;
1984 procmime_mimeinfo_free_all(mimeinfo);
1987 #undef IS_FIRST_PART_TEXT
1989 #define GET_CHAR(pos, buf, len) \
1991 if (text->use_wchar) \
1992 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
1994 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
1999 static void compose_wrap_line(Compose *compose)
2001 GtkSText *text = GTK_STEXT(compose->text);
2002 gint ch_len, last_ch_len;
2003 gchar cbuf[MB_LEN_MAX], last_ch;
2007 gint p_start, p_end;
2008 gint line_pos, cur_pos;
2009 gint line_len, cur_len;
2011 gtk_stext_freeze(text);
2013 text_len = gtk_stext_get_length(text);
2015 /* check to see if the point is on the paragraph mark (empty line). */
2016 cur_pos = gtk_stext_get_point(text);
2017 GET_CHAR(cur_pos, cbuf, ch_len);
2018 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2020 goto compose_end; /* on the paragraph mark */
2021 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2022 if (ch_len == 1 && *cbuf == '\n')
2023 goto compose_end; /* on the paragraph mark */
2026 /* find paragraph start. */
2027 line_end = quoted = 0;
2028 for (p_start = cur_pos; p_start >= 0; --p_start) {
2029 GET_CHAR(p_start, cbuf, ch_len);
2030 if (ch_len == 1 && *cbuf == '\n') {
2032 goto compose_end; /* quoted part */
2039 if (ch_len == 1 && strchr(">:#", *cbuf))
2041 else if (ch_len != 1 || !isspace(*cbuf))
2050 /* find paragraph end. */
2052 for (p_end = cur_pos; p_end < text_len; p_end++) {
2053 GET_CHAR(p_end, cbuf, ch_len);
2054 if (ch_len == 1 && *cbuf == '\n') {
2061 if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
2062 goto compose_end; /* quoted part */
2067 if (p_end >= text_len)
2070 if (p_start >= p_end)
2073 line_len = cur_len = 0;
2077 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2080 GET_CHAR(cur_pos, cbuf, ch_len);
2087 if (ch_len == 1 && isspace(*cbuf))
2090 if (ch_len == 1 && *cbuf == '\n') {
2092 if (last_ch_len == 1 && !isspace(last_ch)) {
2093 if (cur_pos + 1 < p_end) {
2094 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2095 if (ch_len == 1 && !isspace(*cbuf))
2099 gtk_stext_set_point(text, cur_pos + 1);
2100 gtk_stext_backward_delete(text, 1);
2102 gtk_stext_set_point(text, cur_pos);
2103 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2113 last_ch_len = ch_len;
2117 line_pos = cur_pos + 1;
2118 line_len = cur_len + ch_len;
2121 if (cur_len + ch_len > prefs_common.linewrap_len &&
2125 GET_CHAR(line_pos - 1, cbuf, ch_len);
2126 if (ch_len == 1 && isspace(*cbuf)) {
2127 gtk_stext_set_point(text, line_pos);
2128 gtk_stext_backward_delete(text, 1);
2137 gtk_stext_set_point(text, line_pos);
2138 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2142 cur_len = cur_len - line_len + ch_len;
2148 line_pos = cur_pos + 1;
2149 line_len = cur_len + ch_len;
2155 gtk_stext_thaw(text);
2158 /* return indent length */
2159 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2161 gint indent_len = 0;
2163 gchar cbuf[MB_LEN_MAX];
2165 for (i = start_pos; i < text_len; i++) {
2166 GET_CHAR(i, cbuf, ch_len);
2169 /* allow space, tab, > or | */
2170 if (cbuf[0] != ' ' && cbuf[0] != '\t' &&
2171 cbuf[0] != '>' && cbuf[0] != '|')
2179 /* insert quotation string when line was wrapped */
2180 static guint ins_quote(GtkSText *text, guint quote_len, guint indent_len,
2181 guint prev_line_pos, guint text_len,
2188 for (i = 0; i < indent_len; i++) {
2189 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2190 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2192 ins_len = indent_len;
2194 gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
2195 ins_len = quote_len;
2203 /* Darko: used when I debug wrapping */
2204 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2209 printf("%d [", pos);
2210 for (i = pos; i < tlen; i++) {
2211 ch = GTK_STEXT_INDEX(text, i);
2212 if (breakoncr && ch == '\n')
2220 static void compose_wrap_line_all(Compose *compose)
2222 GtkSText *text = GTK_STEXT(compose->text);
2224 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2225 gint line_len = 0, cur_len = 0;
2227 gboolean is_new_line = TRUE, do_delete = FALSE;
2228 guint qlen = 0, i_len = 0;
2229 gboolean linewrap_quote = TRUE;
2230 guint linewrap_len = prefs_common.linewrap_len;
2231 gchar *qfmt = prefs_common.quotemark;
2232 gchar cbuf[MB_LEN_MAX];
2234 gtk_stext_freeze(text);
2236 /* make text buffer contiguous */
2237 /* gtk_stext_compact_buffer(text); */
2239 tlen = gtk_stext_get_length(text);
2241 for (; cur_pos < tlen; cur_pos++) {
2242 /* mark position of new line - needed for quotation wrap */
2244 if (linewrap_quote) {
2245 qlen = gtkut_stext_str_compare
2246 (text, cur_pos, tlen, qfmt);
2248 i_len = get_indent_length
2249 (text, cur_pos, tlen);
2253 is_new_line = FALSE;
2256 printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
2257 dump_text(text, p_pos, tlen, 1);
2261 GET_CHAR(cur_pos, cbuf, ch_len);
2263 /* fix line length for tabs */
2264 if (ch_len == 1 && *cbuf == '\t') {
2265 guint tab_width = text->default_tab_width;
2266 guint tab_offset = line_len % tab_width;
2269 printf("found tab at pos=%d line_len=%d ", cur_pos,
2273 line_len += tab_width - tab_offset - 1;
2277 printf("new_len=%d\n", line_len);
2281 /* we have encountered line break */
2282 if (ch_len == 1 && *cbuf == '\n') {
2285 gchar cb[MB_CUR_MAX];
2288 printf("found CR at %d next line is ", cur_pos);
2289 dump_text(text, cur_pos + 1, tlen, 1);
2291 /* if it's just quotation + newline skip it */
2292 if (i_len && (cur_pos + 1 < tlen)) {
2293 /* check if text at new line matches indent */
2294 ilen = gtkut_stext_str_compare_n
2295 (text, cur_pos + 1, p_pos, i_len, tlen);
2296 if (cur_pos + ilen < tlen) {
2297 GET_CHAR(cur_pos + ilen + 1, cb, clen);
2298 /* no need to join the lines */
2299 if (clen == 1 && cb[0] == '\n')
2302 /* if it's just newline skip it */
2303 } else if (do_delete && (cur_pos + 1 < tlen)) {
2304 GET_CHAR(cur_pos + 1, cb, clen);
2305 /* no need to join the lines */
2306 if (clen == 1 && cb[0] == '\n')
2310 /* skip delete if it is continuous URL */
2311 if (do_delete && (line_pos - p_pos <= i_len) &&
2312 gtkut_stext_is_uri_string(text, line_pos, tlen))
2316 printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
2317 qlen, line_len, linewrap_len, do_delete);
2319 /* should we delete to perform smart wrapping */
2320 if (line_len < linewrap_len && do_delete) {
2321 /* get rid of newline */
2322 gtk_stext_set_point(text, cur_pos);
2323 gtk_stext_forward_delete(text, 1);
2326 /* if text starts with quote fmt or with
2327 indent string, delete them */
2329 ilen = gtkut_stext_str_compare_n
2330 (text, cur_pos, p_pos, i_len,
2333 gtk_stext_forward_delete
2338 if (gtkut_stext_str_compare
2339 (text, cur_pos, tlen, qfmt)) {
2340 gtk_stext_forward_delete
2346 GET_CHAR(cur_pos, cb, clen);
2348 /* insert space if it's alphanumeric */
2349 if ((cur_pos != line_pos) &&
2350 ((clen > 1) || isalnum(cb[0]))) {
2351 gtk_stext_insert(text, NULL, NULL,
2353 /* gtk_stext_compact_buffer(text); */
2357 /* and start over with current line */
2358 cur_pos = p_pos - 1;
2360 line_len = cur_len = 0;
2365 printf("after delete l_pos=");
2366 dump_text(text, line_pos, tlen, 1);
2371 /* mark new line beginning */
2372 line_pos = cur_pos + 1;
2373 line_len = cur_len = 0;
2385 /* possible line break */
2386 if (ch_len == 1 && isspace(*cbuf)) {
2387 line_pos = cur_pos + 1;
2388 line_len = cur_len + ch_len;
2391 /* are we over wrapping length set in preferences ? */
2392 if (cur_len + ch_len > linewrap_len) {
2396 printf("should wrap cur_pos=%d ", cur_pos);
2397 dump_text(text, p_pos, tlen, 1);
2398 dump_text(text, line_pos, tlen, 1);
2400 /* force wrapping if it is one long word but not URL */
2401 if (line_pos - p_pos <= i_len)
2402 if (!gtkut_stext_is_uri_string
2403 (text, line_pos, tlen))
2404 line_pos = cur_pos - 1;
2406 printf("new line_pos=%d\n", line_pos);
2409 GET_CHAR(line_pos - 1, cbuf, clen);
2411 /* if next character is space delete it */
2412 if (clen == 1 && isspace(*cbuf)) {
2413 if (p_pos + i_len != line_pos ||
2414 !gtkut_stext_is_uri_string
2415 (text, line_pos, tlen)) {
2416 gtk_stext_set_point(text, line_pos);
2417 gtk_stext_backward_delete(text, 1);
2426 /* if it is URL at beginning of line don't wrap */
2427 if (p_pos + i_len == line_pos &&
2428 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2430 printf("found URL at ");
2431 dump_text(text, line_pos, tlen, 1);
2437 gtk_stext_set_point(text, line_pos);
2438 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2439 /* gtk_stext_compact_buffer(text); */
2442 /* for loop will increase it */
2443 cur_pos = line_pos - 1;
2444 /* start over with current line */
2450 printf("after CR insert ");
2451 dump_text(text, line_pos, tlen, 1);
2452 dump_text(text, cur_pos, tlen, 1);
2455 /* should we insert quotation ? */
2456 if (linewrap_quote && qlen) {
2457 /* only if line is not already quoted */
2458 if (!gtkut_stext_str_compare
2459 (text, line_pos, tlen, qfmt)) {
2462 if (line_pos - p_pos > i_len) {
2467 /* gtk_stext_compact_buffer(text); */
2471 printf("after quote insert ");
2472 dump_text(text, line_pos, tlen, 1);
2480 line_pos = cur_pos + 1;
2481 line_len = cur_len + ch_len;
2483 /* advance to next character in buffer */
2487 gtk_stext_thaw(text);
2492 static void compose_set_title(Compose *compose)
2497 edited = compose->modified ? _(" [Edited]") : "";
2498 if (compose->account && compose->account->address)
2499 str = g_strdup_printf(_("%s - Compose message%s"),
2500 compose->account->address, edited);
2502 str = g_strdup_printf(_("Compose message%s"), edited);
2503 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2508 * compose_current_mail_account:
2510 * Find a current mail account (the currently selected account, or the
2511 * default account, if a news account is currently selected). If a
2512 * mail account cannot be found, display an error message.
2514 * Return value: Mail account, or NULL if not found.
2516 static PrefsAccount *
2517 compose_current_mail_account(void)
2521 if (cur_account && cur_account->protocol != A_NNTP)
2524 ac = account_get_default();
2525 if (!ac || ac->protocol == A_NNTP) {
2526 alertpanel_error(_("Account for sending mail is not specified.\n"
2527 "Please select a mail account before sending."));
2534 gboolean compose_check_for_valid_recipient(Compose *compose) {
2535 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2536 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2537 gboolean recipient_found = FALSE;
2541 /* free to and newsgroup list */
2542 slist_free_strings(compose->to_list);
2543 g_slist_free(compose->to_list);
2544 compose->to_list = NULL;
2546 slist_free_strings(compose->newsgroup_list);
2547 g_slist_free(compose->newsgroup_list);
2548 compose->newsgroup_list = NULL;
2550 /* search header entries for to and newsgroup entries */
2551 for(list = compose->header_list; list; list = list->next) {
2554 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2555 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2557 if(entry[0] != '\0') {
2558 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2559 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2560 compose->to_list = address_list_append(compose->to_list, entry);
2561 recipient_found = TRUE;
2564 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2565 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2566 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2567 recipient_found = TRUE;
2573 return recipient_found;
2576 gint compose_send(Compose *compose)
2582 val = compose_queue(compose, &msgnum, &folder);
2584 alertpanel_error(_("Could not queue message for sending"));
2588 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2590 folder_item_remove_msg(folder, msgnum);
2591 folderview_update_item(folder, TRUE);
2596 #if 0 /* compose restructure */
2597 gint compose_send(Compose *compose)
2599 gchar tmp[MAXPATHLEN + 1];
2601 static gboolean lock = FALSE;
2605 g_return_val_if_fail(compose->account != NULL, -1);
2606 g_return_val_if_fail(compose->orig_account != NULL, -1);
2610 if(!compose_check_for_valid_recipient(compose)) {
2611 alertpanel_error(_("Recipient is not specified."));
2616 /* write to temporary file */
2617 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2618 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2620 if (prefs_common.linewrap_at_send)
2621 compose_wrap_line_all(compose);
2623 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2628 if (!compose->to_list && !compose->newsgroup_list) {
2629 g_warning(_("can't get recipient list."));
2635 if (compose->to_list) {
2638 #if 0 /* NEW COMPOSE GUI */
2639 if (compose->account->protocol != A_NNTP)
2640 ac = compose->account;
2641 else if (compose->orig_account->protocol != A_NNTP)
2642 ac = compose->orig_account;
2643 else if (cur_account && cur_account->protocol != A_NNTP)
2646 ac = compose_current_mail_account();
2654 ac = compose->account;
2656 ok = send_message(tmp, ac, compose->to_list);
2657 statusbar_pop_all();
2660 if (ok == 0 && compose->newsgroup_list) {
2663 if (compose->account->protocol == A_NNTP)
2664 folder = FOLDER(compose->account->folder);
2666 folder = FOLDER(compose->orig_account->folder);
2668 ok = news_post(folder, tmp);
2670 alertpanel_error(_("Error occurred while posting the message to %s ."),
2671 compose->account->nntp_server);
2678 /* queue message if failed to send */
2680 if (prefs_common.queue_msg) {
2685 _("Error occurred while sending the message.\n"
2686 "Put this message into queue folder?"),
2687 _("OK"), _("Cancel"), NULL);
2688 if (G_ALERTDEFAULT == val) {
2689 ok = compose_queue(compose, tmp);
2691 alertpanel_error(_("Can't queue the message."));
2694 alertpanel_error(_("Error occurred while sending the message."));
2696 if (compose->mode == COMPOSE_REEDIT) {
2697 compose_remove_reedit_target(compose);
2698 if (compose->targetinfo)
2699 folderview_update_item
2700 (compose->targetinfo->folder, TRUE);
2704 /* save message to outbox */
2705 if (ok == 0 && prefs_common.savemsg) {
2706 if (compose_save_to_outbox(compose, tmp) < 0)
2708 (_("Can't save the message to outbox."));
2717 static gboolean compose_use_attach(Compose *compose) {
2718 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2721 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2724 gchar buf[BUFFSIZE];
2726 gboolean first_address;
2728 ComposeHeaderEntry *headerentry;
2729 gchar *headerentryname;
2730 gchar *header_w_colon;
2734 debug_print(_("Writing bounce header\n"));
2736 header_w_colon = g_strconcat("To:", NULL);
2737 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2738 header_w_colon = g_strconcat("Cc:", NULL);
2739 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2741 first_address = TRUE;
2742 for(list = compose->header_list; list; list = list->next) {
2743 headerentry = ((ComposeHeaderEntry *)list->data);
2744 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2746 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2747 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2748 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2749 Xstrdup_a(str, str, return -1);
2751 if(str[0] != '\0') {
2752 compose_convert_header
2753 (buf, sizeof(buf), str,
2754 strlen("Resent-To") + 2);
2756 fprintf(fp, "Resent-To: ");
2757 first_address = FALSE;
2761 fprintf(fp, "%s", buf);
2765 /* if(!first_address) { */
2772 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2774 gchar buf[BUFFSIZE];
2776 /* struct utsname utsbuf; */
2778 g_return_val_if_fail(fp != NULL, -1);
2779 g_return_val_if_fail(compose->account != NULL, -1);
2780 g_return_val_if_fail(compose->account->address != NULL, -1);
2783 get_rfc822_date(buf, sizeof(buf));
2784 fprintf(fp, "Resent-Date: %s\n", buf);
2787 if (compose->account->name && *compose->account->name) {
2788 compose_convert_header
2789 (buf, sizeof(buf), compose->account->name,
2791 fprintf(fp, "Resent-From: %s <%s>\n",
2792 buf, compose->account->address);
2794 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2797 compose_bounce_write_headers_from_headerlist(compose, fp);
2799 /* separator between header and body */
2805 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2810 gchar buf[BUFFSIZE];
2812 if ((fp = fopen(compose->bounce_filename, "rb")) == NULL) {
2813 FILE_OP_ERROR(file, "fopen");
2817 if ((fdest = fopen(file, "wb")) == NULL) {
2818 FILE_OP_ERROR(file, "fopen");
2823 /* chmod for security */
2824 if (change_file_mode_rw(fdest, file) < 0) {
2825 FILE_OP_ERROR(file, "chmod");
2826 g_warning(_("can't change file mode\n"));
2829 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2830 /* should filter returnpath, delivered-to */
2831 if ((g_strncasecmp(buf, "Return-Path:",
2832 strlen("Return-Path:")) == 0)
2833 || (g_strncasecmp(buf, "Delivered-To:",
2834 strlen("Delivered-To:")) == 0))
2837 if (fputs(buf, fdest) == -1)
2840 if (g_strncasecmp(buf, "From:", strlen("From:")) == 0) {
2841 fputs(" (by way of ", fdest);
2842 if (compose->account->name
2843 && *compose->account->name) {
2844 compose_convert_header
2846 compose->account->name,
2848 fprintf(fdest, "%s <%s>",
2849 buf, compose->account->address);
2851 fprintf(fdest, "%s",
2852 compose->account->address);
2856 if (fputs("\n", fdest) == -1)
2860 compose_bounce_write_headers(compose, fdest);
2862 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
2863 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
2881 * interfaces to rfc2015 to keep out the prefs stuff there.
2882 * returns 0 on success and -1 on error. */
2883 static int compose_create_signers_list (Compose *compose, GSList **pkey_list)
2885 const char *keyid = NULL;
2888 switch (compose->account->sign_key) {
2889 case SIGN_KEY_DEFAULT:
2891 return 0; /* nothing to do */
2893 case SIGN_KEY_BY_FROM:
2894 keyid = compose->account->address;
2897 case SIGN_KEY_CUSTOM:
2898 keyid = compose->account->sign_key_id;
2902 g_assert_not_reached ();
2905 key_list = rfc2015_create_signers_list(keyid);
2908 alertpanel_error("Could not find any key associated with currently "
2909 "selected keyid `%s'!", keyid);
2913 *pkey_list = key_list;
2916 #endif /* USE_GPGME */
2918 static gint compose_write_to_file(Compose *compose, const gchar *file,
2925 const gchar *out_codeset;
2926 EncodingType encoding;
2928 if ((fp = fopen(file, "wb")) == NULL) {
2929 FILE_OP_ERROR(file, "fopen");
2933 /* chmod for security */
2934 if (change_file_mode_rw(fp, file) < 0) {
2935 FILE_OP_ERROR(file, "chmod");
2936 g_warning(_("can't change file mode\n"));
2939 /* get all composed text */
2940 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2941 len = strlen(chars);
2942 if (is_ascii_str(chars)) {
2943 buf = g_strdup(chars);
2944 out_codeset = CS_US_ASCII;
2945 encoding = ENC_7BIT;
2947 const gchar *src_codeset;
2949 out_codeset = conv_get_outgoing_charset_str();
2950 if (!strcasecmp(out_codeset, CS_US_ASCII))
2951 out_codeset = CS_ISO_8859_1;
2952 encoding = procmime_get_encoding_for_charset(out_codeset);
2954 src_codeset = conv_get_current_charset_str();
2955 /* if current encoding is US-ASCII, set it the same as
2956 outgoing one to prevent code conversion failure */
2957 if (!strcasecmp(src_codeset, CS_US_ASCII))
2958 src_codeset = out_codeset;
2960 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
2961 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
2963 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
2969 _("Can't convert the character encoding of the message.\n"
2970 "Send it anyway?"), _("Yes"), _("+No"), NULL);
2971 if (aval != G_ALERTDEFAULT) {
2977 buf = g_strdup(chars);
2984 if (compose_write_headers
2985 (compose, fp, out_codeset, encoding, is_draft) < 0) {
2986 g_warning(_("can't write headers\n"));
2993 if (compose_use_attach(compose)) {
2995 /* This prolog message is ignored by mime software and
2996 * because it would make our signing/encryption task
2997 * tougher, we don't emit it in that case */
2998 if (!compose->use_signing && !compose->use_encryption)
3000 fputs("This is a multi-part message in MIME format.\n", fp);
3002 fprintf(fp, "\n--%s\n", compose->boundary);
3003 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3005 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3006 procmime_get_encoding_str(encoding));
3012 if (encoding == ENC_BASE64) {
3013 gchar outbuf[B64_BUFFSIZE];
3016 for (i = 0; i < len; i += B64_LINE_SIZE) {
3017 l = MIN(B64_LINE_SIZE, len - i);
3018 to64frombits(outbuf, buf + i, l);
3022 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3023 FILE_OP_ERROR(file, "fwrite");
3031 if (compose_use_attach(compose))
3032 compose_write_attach(compose, fp);
3034 if (fclose(fp) == EOF) {
3035 FILE_OP_ERROR(file, "fclose");
3041 if (compose->use_signing) {
3044 if (compose_create_signers_list(compose, &key_list) == -1 ||
3045 rfc2015_sign(file, key_list) < 0) {
3051 if (compose->use_encryption) {
3052 if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) {
3057 #endif /* USE_GPGME */
3062 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3068 if ((fp = fopen(file, "wb")) == NULL) {
3069 FILE_OP_ERROR(file, "fopen");
3073 /* chmod for security */
3074 if (change_file_mode_rw(fp, file) < 0) {
3075 FILE_OP_ERROR(file, "chmod");
3076 g_warning(_("can't change file mode\n"));
3079 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3082 len = strlen(chars);
3083 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3084 FILE_OP_ERROR(file, "fwrite");
3093 if (fclose(fp) == EOF) {
3094 FILE_OP_ERROR(file, "fclose");
3101 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
3108 debug_print(_("saving sent message...\n"));
3110 outbox = folder_get_default_outbox();
3111 path = folder_item_get_path(outbox);
3112 if (!is_dir_exist(path))
3113 make_dir_hier(path);
3115 folder_item_scan(outbox);
3116 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
3118 g_warning(_("can't save message\n"));
3122 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
3123 g_warning(_("can't open mark file\n"));
3127 newmsginfo.msgnum = num;
3128 newmsginfo.flags.perm_flags = 0;
3129 newmsginfo.flags.tmp_flags = 0;
3130 procmsg_write_flags(&newmsginfo, fp);
3138 static gint compose_remove_reedit_target(Compose *compose)
3141 MsgInfo *msginfo = compose->targetinfo;
3143 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3144 if (!msginfo) return -1;
3146 item = msginfo->folder;
3147 g_return_val_if_fail(item != NULL, -1);
3149 folder_item_scan(item);
3150 if (procmsg_msg_exist(msginfo) &&
3151 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3152 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3153 g_warning(_("can't remove the old message\n"));
3162 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3165 gchar *tmp, *tmp2, *queue_path;
3168 gchar buf[BUFFSIZE];
3170 static gboolean lock = FALSE;
3171 PrefsAccount *mailac = NULL, *newsac = NULL;
3173 debug_print(_("queueing message...\n"));
3174 g_return_val_if_fail(compose->account != NULL, -1);
3175 g_return_val_if_fail(compose->orig_account != NULL, -1);
3179 if(!compose_check_for_valid_recipient(compose)) {
3180 alertpanel_error(_("Recipient is not specified."));
3185 if (!compose->to_list && !compose->newsgroup_list) {
3186 g_warning(_("can't get recipient list."));
3191 if(compose->to_list) {
3192 if (compose->account->protocol != A_NNTP)
3193 mailac = compose->account;
3194 else if (compose->orig_account->protocol != A_NNTP)
3195 mailac = compose->orig_account;
3196 else if (cur_account && cur_account->protocol != A_NNTP)
3197 mailac = cur_account;
3198 else if (!(mailac = compose_current_mail_account())) {
3200 alertpanel_error(_("No account for sending mails available!"));
3205 if(compose->newsgroup_list) {
3206 if (compose->account->protocol == A_NNTP)
3207 newsac = compose->account;
3208 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3210 alertpanel_error(_("No account for posting news available!"));
3215 if (prefs_common.linewrap_at_send)
3216 compose_wrap_line_all(compose);
3218 /* write to temporary file */
3219 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3220 G_DIR_SEPARATOR, (gint)compose);
3222 if (compose->bounce_filename != NULL) {
3223 if (compose_bounce_write_to_file(compose, tmp2) < 0) {
3230 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3237 /* add queue header */
3238 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3239 G_DIR_SEPARATOR, (gint)compose);
3240 if ((fp = fopen(tmp, "wb")) == NULL) {
3241 FILE_OP_ERROR(tmp, "fopen");
3245 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3246 FILE_OP_ERROR(tmp2, "fopen");
3254 if (change_file_mode_rw(fp, tmp) < 0) {
3255 FILE_OP_ERROR(tmp, "chmod");
3256 g_warning(_("can't change file mode\n"));
3259 /* queueing variables */
3260 fprintf(fp, "AF:\n");
3261 fprintf(fp, "NF:0\n");
3262 fprintf(fp, "PS:10\n");
3263 fprintf(fp, "SRH:1\n");
3264 fprintf(fp, "SFN:\n");
3265 fprintf(fp, "DSR:\n");
3267 fprintf(fp, "MID:<%s>\n", compose->msgid);
3269 fprintf(fp, "MID:\n");
3270 fprintf(fp, "CFG:\n");
3271 fprintf(fp, "PT:0\n");
3272 fprintf(fp, "S:%s\n", compose->account->address);
3273 fprintf(fp, "RQ:\n");
3275 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3277 fprintf(fp, "SSV:\n");
3279 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3281 fprintf(fp, "NSV:\n");
3282 fprintf(fp, "SSH:\n");
3283 /* write recepient list */
3285 if(compose->to_list) {
3286 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3287 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3288 fprintf(fp, ",<%s>", (gchar *)cur->data);
3291 /* write newsgroup list */
3293 if(compose->newsgroup_list) {
3294 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3295 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3296 fprintf(fp, ",%s", (gchar *)cur->data);
3299 /* Sylpheed account IDs */
3301 fprintf(fp, "MAID:%d\n", mailac->account_id);
3304 fprintf(fp, "NAID:%d\n", newsac->account_id);
3306 /* Save copy folder */
3307 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3310 str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3311 fprintf(fp, "SCF:%s\n", str);
3316 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3317 if (fputs(buf, fp) == EOF) {
3318 FILE_OP_ERROR(tmp, "fputs");
3329 if (fclose(fp) == EOF) {
3330 FILE_OP_ERROR(tmp, "fclose");
3339 queue = folder_get_default_queue();
3341 folder_item_scan(queue);
3342 queue_path = folder_item_get_path(queue);
3343 if (!is_dir_exist(queue_path))
3344 make_dir_hier(queue_path);
3345 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3346 g_warning(_("can't queue the message\n"));
3357 if (compose->mode == COMPOSE_REEDIT) {
3358 compose_remove_reedit_target(compose);
3359 if (compose->targetinfo &&
3360 compose->targetinfo->folder != queue)
3361 folderview_update_item
3362 (compose->targetinfo->folder, TRUE);
3365 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
3366 g_warning(_("can't open mark file\n"));
3370 newmsginfo.msgnum = num;
3371 newmsginfo.flags.perm_flags = 0;
3372 newmsginfo.flags.tmp_flags = 0;
3373 procmsg_write_flags(&newmsginfo, fp);
3378 folder_item_scan(queue);
3379 folderview_update_item(queue, TRUE);
3381 if((msgnum != NULL) && (item != NULL)) {
3389 static void compose_write_attach(Compose *compose, FILE *fp)
3392 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3395 gchar filename[BUFFSIZE];
3398 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3400 gchar buf[BUFFSIZE];
3401 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3403 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
3404 g_warning(_("Can't open file %s\n"), ainfo->file);
3408 fprintf(fp, "\n--%s\n", compose->boundary);
3410 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3411 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3412 fprintf(fp, "Content-Disposition: inline\n");
3414 conv_encode_header(filename, sizeof(filename),
3416 fprintf(fp, "Content-Type: %s;\n"
3418 ainfo->content_type, filename);
3419 fprintf(fp, "Content-Disposition: attachment;\n"
3420 " filename=\"%s\"\n", filename);
3423 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3424 procmime_get_encoding_str(ainfo->encoding));
3426 switch (ainfo->encoding) {
3430 /* if (ainfo->encoding == ENC_7BIT) { */
3432 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3440 while ((len = fread(inbuf, sizeof(gchar),
3441 B64_LINE_SIZE, attach_fp))
3443 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3447 if (len > 0 && feof(attach_fp)) {
3448 to64frombits(outbuf, inbuf, len);
3458 fprintf(fp, "\n--%s--\n", compose->boundary);
3461 #define IS_IN_CUSTOM_HEADER(header) \
3462 (compose->account->add_customhdr && \
3463 custom_header_find(compose->account->customhdr_list, header) != NULL)
3465 static gint compose_write_headers_from_headerlist(Compose *compose,
3469 gchar buf[BUFFSIZE];
3470 gchar *str, *header_w_colon, *trans_hdr;
3471 gboolean first_address;
3473 ComposeHeaderEntry *headerentry;
3474 gchar * headerentryname;
3476 if (IS_IN_CUSTOM_HEADER(header)) {
3480 debug_print(_("Writing %s-header\n"), header);
3482 header_w_colon = g_strconcat(header, ":", NULL);
3483 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3485 first_address = TRUE;
3486 for(list = compose->header_list; list; list = list->next) {
3487 headerentry = ((ComposeHeaderEntry *)list->data);
3488 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3490 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3491 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3492 Xstrdup_a(str, str, return -1);
3494 if(str[0] != '\0') {
3495 compose_convert_header
3496 (buf, sizeof(buf), str,
3497 strlen(header) + 2);
3499 fprintf(fp, "%s: ", header);
3500 first_address = FALSE;
3504 fprintf(fp, "%s", buf);
3508 if(!first_address) {
3512 g_free(header_w_colon);
3517 static gint compose_write_headers(Compose *compose, FILE *fp,
3518 const gchar *charset, EncodingType encoding,
3521 gchar buf[BUFFSIZE];
3523 /* struct utsname utsbuf; */
3525 g_return_val_if_fail(fp != NULL, -1);
3526 g_return_val_if_fail(charset != NULL, -1);
3527 g_return_val_if_fail(compose->account != NULL, -1);
3528 g_return_val_if_fail(compose->account->address != NULL, -1);
3531 if (compose->account->add_date) {
3532 get_rfc822_date(buf, sizeof(buf));
3533 fprintf(fp, "Date: %s\n", buf);
3537 if (!IS_IN_CUSTOM_HEADER("From")) {
3538 if (compose->account->name && *compose->account->name) {
3539 compose_convert_header
3540 (buf, sizeof(buf), compose->account->name,
3542 fprintf(fp, "From: %s <%s>\n",
3543 buf, compose->account->address);
3545 fprintf(fp, "From: %s\n", compose->account->address);
3549 compose_write_headers_from_headerlist(compose, fp, "To");
3550 #if 0 /* NEW COMPOSE GUI */
3551 if (compose->use_to) {
3552 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3554 Xstrdup_a(str, str, return -1);
3557 compose->to_list = address_list_append
3558 (compose->to_list, str);
3559 if (!IS_IN_CUSTOM_HEADER("To")) {
3560 compose_convert_header
3561 (buf, sizeof(buf), str,
3563 fprintf(fp, "To: %s\n", buf);
3571 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3572 #if 0 /* NEW COMPOSE GUI */
3573 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3575 Xstrdup_a(str, str, return -1);
3579 compose->newsgroup_list =
3580 newsgroup_list_append(compose->newsgroup_list,
3582 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3583 compose_convert_header(buf, sizeof(buf), str,
3584 strlen("Newsgroups: "));
3585 fprintf(fp, "Newsgroups: %s\n", buf);
3591 compose_write_headers_from_headerlist(compose, fp, "Cc");
3592 #if 0 /* NEW COMPOSE GUI */
3593 if (compose->use_cc) {
3594 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3596 Xstrdup_a(str, str, return -1);
3599 compose->to_list = address_list_append
3600 (compose->to_list, str);
3601 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3602 compose_convert_header
3603 (buf, sizeof(buf), str,
3605 fprintf(fp, "Cc: %s\n", buf);
3612 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3613 #if 0 /* NEW COMPOSE GUI */
3614 if (compose->use_bcc) {
3615 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3617 Xstrdup_a(str, str, return -1);
3620 compose->to_list = address_list_append
3621 (compose->to_list, str);
3622 compose_convert_header(buf, sizeof(buf), str,
3624 fprintf(fp, "Bcc: %s\n", buf);
3631 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3632 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3633 Xstrdup_a(str, str, return -1);
3636 compose_convert_header(buf, sizeof(buf), str,
3637 strlen("Subject: "));
3638 fprintf(fp, "Subject: %s\n", buf);
3643 if (compose->account->gen_msgid) {
3644 compose_generate_msgid(compose, buf, sizeof(buf));
3645 fprintf(fp, "Message-Id: <%s>\n", buf);
3646 compose->msgid = g_strdup(buf);
3650 if (compose->inreplyto && compose->to_list)
3651 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3654 if (compose->references)
3655 fprintf(fp, "References: %s\n", compose->references);
3658 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3659 #if 0 /* NEW COMPOSE GUI */
3660 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3661 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3663 Xstrdup_a(str, str, return -1);
3667 compose_convert_header(buf, sizeof(buf), str,
3668 strlen("Followup-To: "));
3669 fprintf(fp, "Followup-To: %s\n", buf);
3675 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3676 #if 0 /* NEW COMPOSE GUI */
3677 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3678 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3680 Xstrdup_a(str, str, return -1);
3683 compose_convert_header(buf, sizeof(buf), str,
3684 strlen("Reply-To: "));
3685 fprintf(fp, "Reply-To: %s\n", buf);
3691 if (compose->account->organization &&
3692 !IS_IN_CUSTOM_HEADER("Organization")) {
3693 compose_convert_header(buf, sizeof(buf),
3694 compose->account->organization,
3695 strlen("Organization: "));
3696 fprintf(fp, "Organization: %s\n", buf);
3699 /* Program version and system info */
3700 /* uname(&utsbuf); */
3701 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3702 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3704 gtk_major_version, gtk_minor_version, gtk_micro_version,
3706 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3708 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3709 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3711 gtk_major_version, gtk_minor_version, gtk_micro_version,
3713 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3716 /* custom headers */
3717 if (compose->account->add_customhdr) {
3720 for (cur = compose->account->customhdr_list; cur != NULL;
3722 CustomHeader *chdr = (CustomHeader *)cur->data;
3724 if (strcasecmp(chdr->name, "Date") != 0 &&
3725 strcasecmp(chdr->name, "From") != 0 &&
3726 strcasecmp(chdr->name, "To") != 0 &&
3727 /* strcasecmp(chdr->name, "Sender") != 0 && */
3728 strcasecmp(chdr->name, "Message-Id") != 0 &&
3729 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3730 strcasecmp(chdr->name, "References") != 0 &&
3731 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3732 strcasecmp(chdr->name, "Content-Type") != 0 &&
3733 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3735 compose_convert_header
3737 chdr->value ? chdr->value : "",
3738 strlen(chdr->name) + 2);
3739 fprintf(fp, "%s: %s\n", chdr->name, buf);
3745 fprintf(fp, "Mime-Version: 1.0\n");
3746 if (compose_use_attach(compose)) {
3747 get_rfc822_date(buf, sizeof(buf));
3748 subst_char(buf, ' ', '_');
3749 subst_char(buf, ',', '_');
3750 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3751 buf, (guint)compose);
3753 "Content-Type: multipart/mixed;\n"
3754 " boundary=\"%s\"\n", compose->boundary);
3756 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3757 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3758 procmime_get_encoding_str(encoding));
3761 /* Request Return Receipt */
3762 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3763 if (compose->return_receipt) {
3764 if (compose->account->name
3765 && *compose->account->name) {
3766 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3767 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3769 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3773 /* separator between header and body */
3779 #undef IS_IN_CUSTOM_HEADER
3781 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3784 g_return_if_fail(src != NULL);
3785 g_return_if_fail(dest != NULL);
3787 if (len < 1) return;
3791 if (is_ascii_str(src)) {
3792 strncpy2(dest, src, len);
3793 dest[len - 1] = '\0';
3796 conv_encode_header(dest, len, src, header_len);
3799 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3808 if (compose->account && compose->account->address &&
3809 *compose->account->address) {
3810 if (strchr(compose->account->address, '@'))
3811 addr = g_strdup(compose->account->address);
3813 addr = g_strconcat(compose->account->address, "@",
3814 get_domain_name(), NULL);
3816 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3819 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3820 lt->tm_year + 1900, lt->tm_mon + 1,
3821 lt->tm_mday, lt->tm_hour,
3822 lt->tm_min, lt->tm_sec,
3823 (guint)random(), addr);
3825 debug_print(_("generated Message-ID: %s\n"), buf);
3830 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3831 GtkWidget **entry, gint *count,
3832 const gchar *label_str,
3833 gboolean is_addr_entry)
3837 if (GTK_TABLE(table)->nrows < (*count) + 1)
3838 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3840 *hbox = gtk_hbox_new(FALSE, 0);
3841 label = gtk_label_new
3842 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3843 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3844 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3846 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3848 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3849 #if 0 /* NEW COMPOSE GUI */
3850 if (GTK_TABLE(table)->nrows > (*count) + 1)
3851 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3855 address_completion_register_entry(GTK_ENTRY(*entry));
3860 static void compose_create_header_entry(Compose *compose)
3862 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3866 GList *combo_list = NULL;
3867 gchar **string, *header;
3868 ComposeHeaderEntry *headerentry;
3870 headerentry = g_new0(ComposeHeaderEntry, 1);
3873 combo = gtk_combo_new();
3875 while(*string != NULL) {
3876 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3879 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3880 g_list_free(combo_list);
3881 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3882 gtk_widget_show(combo);
3883 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3884 if(compose->header_last) {
3885 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3887 switch(compose->account->protocol) {
3889 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
3892 header = prefs_common.trans_hdr ? _("To:") : "To:";
3896 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
3899 entry = gtk_entry_new();
3900 gtk_widget_show(entry);
3901 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);
3903 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
3904 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
3905 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
3907 address_completion_register_entry(GTK_ENTRY(entry));
3909 headerentry->compose = compose;
3910 headerentry->combo = combo;
3911 headerentry->entry = entry;
3912 headerentry->headernum = compose->header_nextrow;
3914 compose->header_nextrow++;
3915 compose->header_last = headerentry;
3918 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
3920 ComposeHeaderEntry *last_header;
3922 last_header = compose->header_last;
3924 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
3925 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
3928 static GtkWidget *compose_create_header(Compose *compose)
3932 GtkWidget *from_optmenu_hbox;
3933 #if 0 /* NEW COMPOSE GUI */
3934 GtkWidget *to_entry;
3936 GtkWidget *newsgroups_entry;
3937 GtkWidget *newsgroups_hbox;
3939 GtkWidget *header_scrolledwin;
3940 GtkWidget *header_table;
3941 #if 0 /* NEW COMPOSE GUI */
3942 GtkWidget *cc_entry;
3944 GtkWidget *bcc_entry;
3945 GtkWidget *bcc_hbox;
3946 GtkWidget *reply_entry;
3947 GtkWidget *reply_hbox;
3948 GtkWidget *followup_entry;
3949 GtkWidget *followup_hbox;
3954 /* header labels and entries */
3955 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3956 gtk_widget_show(header_scrolledwin);
3957 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
3959 header_table = gtk_table_new(2, 2, FALSE);
3960 gtk_widget_show(header_table);
3961 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
3962 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
3963 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
3966 /* option menu for selecting accounts */
3967 hbox = gtk_hbox_new(FALSE, 0);
3968 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
3969 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3970 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
3972 from_optmenu_hbox = compose_account_option_menu_create(compose);
3973 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
3974 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
3975 #if 0 /* NEW COMPOSE GUI */
3976 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3980 compose->header_table = header_table;
3981 compose->header_list = NULL;
3982 compose->header_nextrow = count;
3984 compose_create_header_entry(compose);
3986 #if 0 /* NEW COMPOSE GUI */
3987 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
3989 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3990 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
3991 &count, "Newsgroups:", FALSE);
3992 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
3994 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
3996 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
3998 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
3999 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4001 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4002 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4004 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4005 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4006 "Followup-To:", FALSE);
4007 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4009 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4011 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4012 GTK_SIGNAL_FUNC(to_activated), compose);
4013 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4014 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4015 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4016 GTK_SIGNAL_FUNC(subject_activated), compose);
4017 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4018 GTK_SIGNAL_FUNC(cc_activated), compose);
4019 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4020 GTK_SIGNAL_FUNC(bcc_activated), compose);
4021 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4022 GTK_SIGNAL_FUNC(replyto_activated), compose);
4023 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4024 GTK_SIGNAL_FUNC(followupto_activated), compose);
4026 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4027 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4028 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4029 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4030 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4031 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4032 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4033 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4034 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4035 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4036 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4037 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4038 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4039 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4042 compose->table = NULL;
4043 #if 0 /* NEW COMPOSE GUI */
4044 compose->table = table;
4045 compose->to_hbox = to_hbox;
4046 compose->to_entry = to_entry;
4047 compose->newsgroups_hbox = newsgroups_hbox;
4048 compose->newsgroups_entry = newsgroups_entry;
4050 #if 0 /* NEW COMPOSE GUI */
4051 compose->cc_hbox = cc_hbox;
4052 compose->cc_entry = cc_entry;
4053 compose->bcc_hbox = bcc_hbox;
4054 compose->bcc_entry = bcc_entry;
4055 compose->reply_hbox = reply_hbox;
4056 compose->reply_entry = reply_entry;
4057 compose->followup_hbox = followup_hbox;
4058 compose->followup_entry = followup_entry;
4061 return header_scrolledwin ;
4064 GtkWidget *compose_create_attach(Compose *compose)
4066 gchar *titles[N_ATTACH_COLS];
4069 GtkWidget *attach_scrwin;
4070 GtkWidget *attach_clist;
4072 titles[COL_MIMETYPE] = _("MIME type");
4073 titles[COL_SIZE] = _("Size");
4074 titles[COL_NAME] = _("Name");
4076 /* attachment list */
4077 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4078 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4079 GTK_POLICY_AUTOMATIC,
4081 gtk_widget_set_usize(attach_scrwin, -1, 80);
4083 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4084 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4086 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4087 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4088 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4089 GTK_SELECTION_EXTENDED);
4090 for (i = 0; i < N_ATTACH_COLS; i++)
4091 GTK_WIDGET_UNSET_FLAGS
4092 (GTK_CLIST(attach_clist)->column[i].button,
4094 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4096 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4097 GTK_SIGNAL_FUNC(attach_selected), compose);
4098 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4099 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4100 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4101 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4104 gtk_drag_dest_set(attach_clist,
4105 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4107 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4108 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4111 compose->attach_scrwin = attach_scrwin;
4112 compose->attach_clist = attach_clist;
4114 return attach_scrwin;
4117 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4118 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4120 static GtkWidget *compose_create_others(Compose *compose)
4123 GtkWidget *savemsg_checkbtn;
4124 GtkWidget *savemsg_entry;
4125 GtkWidget *savemsg_select;
4128 gchar *folderidentifier;
4130 /* Table for settings */
4131 table = gtk_table_new(3, 1, FALSE);
4132 gtk_widget_show(table);
4133 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4136 /* Save Message to folder */
4137 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4138 gtk_widget_show(savemsg_checkbtn);
4139 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4140 if(folder_get_default_outbox()) {
4141 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4143 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4144 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4146 savemsg_entry = gtk_entry_new();
4147 gtk_widget_show(savemsg_entry);
4148 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4149 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4150 if(folder_get_default_outbox()) {
4151 folderidentifier = folder_item_get_identifier(folder_get_default_outbox());
4152 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4153 g_free(folderidentifier);
4156 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4157 gtk_widget_show (savemsg_select);
4158 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4159 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4160 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4165 compose->savemsg_checkbtn = savemsg_checkbtn;
4166 compose->savemsg_entry = savemsg_entry;
4171 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4173 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4174 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4177 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4182 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4185 path = folder_item_get_identifier(dest);
4187 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4191 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4197 GtkWidget *handlebox;
4199 GtkWidget *notebook;
4204 GtkWidget *subject_hbox;
4205 GtkWidget *subject_frame;
4206 GtkWidget *subject_entry;
4210 GtkWidget *edit_vbox;
4211 GtkWidget *ruler_hbox;
4213 GtkWidget *scrolledwin;
4218 UndoMain *undostruct;
4220 gchar *titles[N_ATTACH_COLS];
4221 guint n_menu_entries;
4222 GtkStyle *style, *new_style;
4225 gboolean success[1];
4227 GtkWidget *popupmenu;
4228 GtkWidget *menuitem;
4229 GtkItemFactory *popupfactory;
4230 GtkItemFactory *ifactory;
4231 GtkWidget *tmpl_menu;
4235 GtkPspell * gtkpspell = NULL;
4238 g_return_val_if_fail(account != NULL, NULL);
4240 debug_print(_("Creating compose window...\n"));
4241 compose = g_new0(Compose, 1);
4243 titles[COL_MIMETYPE] = _("MIME type");
4244 titles[COL_SIZE] = _("Size");
4245 titles[COL_NAME] = _("Name");
4247 compose->account = account;
4248 compose->orig_account = account;
4250 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4251 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4252 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4253 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4254 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4255 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4256 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4257 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4258 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4259 gtk_widget_realize(window);
4261 gtkut_widget_set_composer_icon(window);
4263 vbox = gtk_vbox_new(FALSE, 0);
4264 gtk_container_add(GTK_CONTAINER(window), vbox);
4266 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4267 menubar = menubar_create(window, compose_entries,
4268 n_menu_entries, "<Compose>", compose);
4269 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4271 handlebox = gtk_handle_box_new();
4272 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4274 compose_toolbar_create(compose, handlebox);
4276 vbox2 = gtk_vbox_new(FALSE, 2);
4277 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4278 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4281 notebook = gtk_notebook_new();
4282 gtk_widget_set_usize(notebook, -1, 130);
4283 gtk_widget_show(notebook);
4285 /* header labels and entries */
4286 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4287 /* attachment list */
4288 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4290 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4293 subject_hbox = gtk_hbox_new(FALSE, 0);
4294 gtk_widget_show(subject_hbox);
4296 subject_frame = gtk_frame_new(NULL);
4297 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4298 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4299 gtk_widget_show(subject_frame);
4301 subject = gtk_hbox_new(FALSE, 0);
4302 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4303 gtk_widget_show(subject);
4305 label = gtk_label_new(_("Subject:"));
4306 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4307 gtk_widget_show(label);
4309 subject_entry = gtk_entry_new();
4310 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4311 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4312 gtk_widget_show(subject_entry);
4313 compose->subject_entry = subject_entry;
4314 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4316 edit_vbox = gtk_vbox_new(FALSE, 0);
4317 #if 0 /* NEW COMPOSE GUI */
4318 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4321 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4324 ruler_hbox = gtk_hbox_new(FALSE, 0);
4325 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4327 ruler = gtk_shruler_new();
4328 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4329 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4331 gtk_widget_set_usize(ruler_hbox, 1, -1);
4334 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4335 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4336 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4337 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4338 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4340 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4341 (GTK_SCROLLED_WINDOW(scrolledwin)),
4342 gtk_scrolled_window_get_vadjustment
4343 (GTK_SCROLLED_WINDOW(scrolledwin)));
4344 GTK_STEXT(text)->default_tab_width = 8;
4345 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4347 if (prefs_common.block_cursor) {
4348 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4351 if (prefs_common.smart_wrapping) {
4352 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4353 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4356 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4358 gtk_signal_connect(GTK_OBJECT(text), "changed",
4359 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4360 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4361 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4362 gtk_signal_connect(GTK_OBJECT(text), "activate",
4363 GTK_SIGNAL_FUNC(text_activated), compose);
4364 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4365 GTK_SIGNAL_FUNC(compose_button_press_cb),
4368 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4369 GTK_SIGNAL_FUNC(compose_key_press_cb),
4372 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4373 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4377 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4379 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4380 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4382 gtk_widget_show_all(vbox);
4384 /* pane between attach clist and text */
4385 paned = gtk_vpaned_new();
4386 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4387 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4388 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4389 gtk_paned_add1(GTK_PANED(paned), notebook);
4390 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4391 gtk_widget_show_all(paned);
4393 style = gtk_widget_get_style(text);
4395 /* workaround for the slow down of GtkSText when using Pixmap theme */
4396 if (style->engine) {
4397 GtkThemeEngine *engine;
4399 engine = style->engine;
4400 style->engine = NULL;
4401 new_style = gtk_style_copy(style);
4402 style->engine = engine;
4404 new_style = gtk_style_copy(style);
4406 if (prefs_common.textfont) {
4409 charset = conv_get_current_charset();
4410 if (MB_CUR_MAX == 1) {
4413 Xstrdup_a(fontstr, prefs_common.textfont, );
4414 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4416 font = gdk_font_load(fontstr);
4418 font = gdk_fontset_load(prefs_common.textfont);
4420 gdk_font_unref(new_style->font);
4421 new_style->font = font;
4425 gtk_widget_set_style(text, new_style);
4427 color[0] = quote_color;
4428 cmap = gdk_window_get_colormap(window->window);
4429 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4430 if (success[0] == FALSE) {
4431 g_warning("Compose: color allocation failed.\n");
4432 style = gtk_widget_get_style(text);
4433 quote_color = style->black;
4436 n_entries = sizeof(compose_popup_entries) /
4437 sizeof(compose_popup_entries[0]);
4438 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4439 "<Compose>", &popupfactory,
4442 ifactory = gtk_item_factory_from_widget(menubar);
4443 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4444 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4446 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tool/Template");
4447 #if 0 /* NEW COMPOSE GUI */
4448 gtk_widget_hide(bcc_hbox);
4449 gtk_widget_hide(bcc_entry);
4450 gtk_widget_hide(reply_hbox);
4451 gtk_widget_hide(reply_entry);
4452 gtk_widget_hide(followup_hbox);
4453 gtk_widget_hide(followup_entry);
4454 gtk_widget_hide(ruler_hbox);
4455 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4456 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4457 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4459 if (account->protocol == A_NNTP) {
4460 gtk_widget_hide(to_hbox);
4461 gtk_widget_hide(to_entry);
4462 gtk_widget_hide(cc_hbox);
4463 gtk_widget_hide(cc_entry);
4464 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4465 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4467 gtk_widget_hide(newsgroups_hbox);
4468 gtk_widget_hide(newsgroups_entry);
4469 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4470 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
4474 update_compose_actions_menu(ifactory, "/Tool/Actions", compose);
4477 undostruct = undo_init(text);
4478 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4481 gtk_widget_show(window);
4483 address_completion_start(window);
4485 compose->window = window;
4486 compose->vbox = vbox;
4487 compose->menubar = menubar;
4488 compose->handlebox = handlebox;
4490 compose->vbox2 = vbox2;
4492 compose->paned = paned;
4494 compose->edit_vbox = edit_vbox;
4495 compose->ruler_hbox = ruler_hbox;
4496 compose->ruler = ruler;
4497 compose->scrolledwin = scrolledwin;
4498 compose->text = text;
4500 compose->focused_editable = NULL;
4502 compose->popupmenu = popupmenu;
4503 compose->popupfactory = popupfactory;
4505 compose->tmpl_menu = tmpl_menu;
4507 compose->mode = mode;
4509 compose->targetinfo = NULL;
4510 compose->replyinfo = NULL;
4512 compose->replyto = NULL;
4513 compose->mailinglist = NULL;
4515 compose->bcc = NULL;
4516 compose->followup_to = NULL;
4517 compose->inreplyto = NULL;
4518 compose->references = NULL;
4519 compose->msgid = NULL;
4520 compose->boundary = NULL;
4523 compose->use_signing = FALSE;
4524 compose->use_encryption = FALSE;
4525 #endif /* USE_GPGME */
4527 compose->modified = FALSE;
4529 compose->return_receipt = FALSE;
4531 compose->to_list = NULL;
4532 compose->newsgroup_list = NULL;
4534 compose->exteditor_file = NULL;
4535 compose->exteditor_pid = -1;
4536 compose->exteditor_readdes = -1;
4537 compose->exteditor_tag = -1;
4539 compose->bounce_filename = NULL;
4540 compose->undostruct = undostruct;
4543 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4544 if (prefs_common.enable_pspell) {
4545 gtkpspell = gtkpspell_new((const gchar*)prefs_common.dictionary,
4546 conv_get_current_charset_str(),
4547 prefs_common.misspelled_col,
4548 prefs_common.check_while_typing,
4549 prefs_common.use_alternate,
4552 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkpspellcheckers->error_message);
4553 gtkpspell_checkers_reset_error();
4556 GtkWidget *menuitem;
4558 if (!gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode)) {
4559 debug_print(_("Pspell: could not set suggestion mode %s"),
4560 gtkpspellcheckers->error_message);
4561 gtkpspell_checkers_reset_error();
4564 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
4565 gtkpspell_populate_submenu(gtkpspell, menuitem);
4566 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4571 compose_set_title(compose);
4573 #if 0 /* NEW COMPOSE GUI */
4574 compose->use_bcc = FALSE;
4575 compose->use_replyto = FALSE;
4576 compose->use_followupto = FALSE;
4580 compose->gtkpspell = gtkpspell;
4583 #if 0 /* NEW COMPOSE GUI */
4584 if (account->protocol != A_NNTP) {
4585 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
4586 gtk_check_menu_item_set_active
4587 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4588 gtk_widget_set_sensitive(menuitem, FALSE);
4589 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4590 gtk_check_menu_item_set_active
4591 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4592 gtk_widget_set_sensitive(menuitem, FALSE);
4595 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4596 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4597 #if 0 /* NEW COMPOSE GUI */
4598 compose->use_cc = TRUE;
4599 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4600 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4601 gtk_check_menu_item_set_active
4602 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4605 if (account->set_autobcc) {
4606 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4607 #if 0 /* NEW COMPOSE GUI */
4608 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
4609 gtk_check_menu_item_set_active
4610 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4611 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4612 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4616 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4617 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4618 #if 0 /* NEW COMPOSE GUI */
4619 compose->use_replyto = TRUE;
4620 menuitem = gtk_item_factory_get_item(ifactory,
4622 gtk_check_menu_item_set_active
4623 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4624 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4625 account->auto_replyto);
4629 if (account->protocol != A_NNTP) {
4630 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4632 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4635 #if 0 /* NEW COMPOSE GUI */
4636 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
4637 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4638 prefs_common.show_ruler);
4642 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4643 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4644 account->default_sign);
4645 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4646 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4647 account->default_encrypt);
4648 #endif /* USE_GPGME */
4650 addressbook_set_target_compose(compose);
4651 compose_set_template_menu(compose);
4653 compose_list = g_list_append(compose_list, compose);
4655 #if 0 /* NEW COMPOSE GUI */
4656 compose->use_to = FALSE;
4657 compose->use_cc = FALSE;
4658 compose->use_attach = TRUE;
4661 #if 0 /* NEW COMPOSE GUI */
4662 if (!compose->use_bcc) {
4663 gtk_widget_hide(bcc_hbox);
4664 gtk_widget_hide(bcc_entry);
4665 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4667 if (!compose->use_replyto) {
4668 gtk_widget_hide(reply_hbox);
4669 gtk_widget_hide(reply_entry);
4670 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4672 if (!compose->use_followupto) {
4673 gtk_widget_hide(followup_hbox);
4674 gtk_widget_hide(followup_entry);
4675 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4678 if (!prefs_common.show_ruler)
4679 gtk_widget_hide(ruler_hbox);
4681 select_account(compose, account);
4682 set_toolbar_style(compose);
4687 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4690 GtkWidget *icon_wid;
4691 GtkWidget *send_btn;
4692 GtkWidget *sendl_btn;
4693 GtkWidget *draft_btn;
4694 GtkWidget *insert_btn;
4695 GtkWidget *attach_btn;
4697 GtkWidget *exteditor_btn;
4698 GtkWidget *linewrap_btn;
4699 GtkWidget *addrbook_btn;
4701 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4703 gtk_container_add(GTK_CONTAINER(container), toolbar);
4704 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4705 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4706 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4707 GTK_TOOLBAR_SPACE_LINE);
4709 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
4710 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4714 icon_wid, toolbar_send_cb, compose);
4716 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND_QUEUE);
4717 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4719 _("Put into queue folder and send later"),
4721 icon_wid, toolbar_send_later_cb,
4724 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4725 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4727 _("Save to draft folder"),
4729 icon_wid, toolbar_draft_cb,
4732 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4734 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_INSERT_FILE);
4735 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4739 icon_wid, toolbar_insert_cb,
4742 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_ATTACH);
4743 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4747 icon_wid, toolbar_attach_cb,
4750 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4752 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SIGN);
4753 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4755 _("Insert signature"),
4757 icon_wid, toolbar_sig_cb, compose);
4759 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4761 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_EDIT_EXTERN);
4762 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4764 _("Edit with external editor"),
4767 toolbar_ext_editor_cb,
4770 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_LINEWRAP);
4771 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4773 _("Wrap all long lines"),
4776 toolbar_linewrap_cb,
4779 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4781 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_ADDRESS_BOOK);
4782 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4786 icon_wid, toolbar_address_cb,
4789 compose->toolbar = toolbar;
4790 compose->send_btn = send_btn;
4791 compose->sendl_btn = sendl_btn;
4792 compose->draft_btn = draft_btn;
4793 compose->insert_btn = insert_btn;
4794 compose->attach_btn = attach_btn;
4795 compose->sig_btn = sig_btn;
4796 compose->exteditor_btn = exteditor_btn;
4797 compose->linewrap_btn = linewrap_btn;
4798 compose->addrbook_btn = addrbook_btn;
4800 gtk_widget_show_all(toolbar);
4803 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4809 gint num = 0, def_menu = 0;
4811 accounts = account_get_list();
4812 g_return_val_if_fail(accounts != NULL, NULL);
4814 hbox = gtk_hbox_new(FALSE, 0);
4815 optmenu = gtk_option_menu_new();
4816 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4817 menu = gtk_menu_new();
4819 for (; accounts != NULL; accounts = accounts->next, num++) {
4820 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4821 GtkWidget *menuitem;
4824 if (ac == compose->account) def_menu = num;
4826 name = g_strdup_printf("%s: %s <%s>",
4827 ac->account_name, ac->name, ac->address);
4828 MENUITEM_ADD(menu, menuitem, name, ac);
4830 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4831 GTK_SIGNAL_FUNC(account_activated),
4835 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4836 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4841 static void compose_set_template_menu(Compose *compose)
4843 GSList *tmpl_list, *cur;
4847 tmpl_list = template_get_config();
4849 menu = gtk_menu_new();
4851 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4852 Template *tmpl = (Template *)cur->data;
4854 item = gtk_menu_item_new_with_label(tmpl->name);
4855 gtk_menu_append(GTK_MENU(menu), item);
4856 gtk_signal_connect(GTK_OBJECT(item), "activate",
4857 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4859 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4860 gtk_widget_show(item);
4863 gtk_widget_show(menu);
4864 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4867 void compose_reflect_prefs_all(void)
4872 for (cur = compose_list; cur != NULL; cur = cur->next) {
4873 compose = (Compose *)cur->data;
4874 compose_set_template_menu(compose);
4878 void compose_reflect_prefs_pixmap_theme(void)
4883 for (cur = compose_list; cur != NULL; cur = cur->next) {
4884 compose = (Compose *)cur->data;
4885 gtk_container_remove(GTK_CONTAINER(compose->handlebox), GTK_WIDGET(compose->toolbar));
4886 compose->toolbar = NULL;
4887 compose_toolbar_create(compose, compose->handlebox);
4888 set_toolbar_style(compose);
4893 static void compose_template_apply(Compose *compose, Template *tmpl)
4898 if (!tmpl || !tmpl->value) return;
4900 gtk_stext_freeze(GTK_STEXT(compose->text));
4902 if (tmpl->subject && *tmpl->subject != '\0')
4903 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
4905 if (tmpl->to && *tmpl->to != '\0')
4906 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
4908 gtk_stext_clear(GTK_STEXT(compose->text));
4910 if (compose->replyinfo == NULL) {
4913 memset(&dummyinfo, 0, sizeof(MsgInfo));
4914 parsed_str = compose_quote_fmt(compose, &dummyinfo,
4915 tmpl->value, NULL, NULL);
4917 if (prefs_common.quotemark && *prefs_common.quotemark)
4918 qmark = prefs_common.quotemark;
4922 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
4923 tmpl->value, qmark, NULL);
4926 if (parsed_str && prefs_common.auto_sig)
4927 compose_insert_sig(compose);
4929 gtk_stext_thaw(GTK_STEXT(compose->text));
4932 static void compose_destroy(Compose *compose)
4935 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4938 /* NOTE: address_completion_end() does nothing with the window
4939 * however this may change. */
4940 address_completion_end(compose->window);
4942 slist_free_strings(compose->to_list);
4943 g_slist_free(compose->to_list);
4944 slist_free_strings(compose->newsgroup_list);
4945 g_slist_free(compose->newsgroup_list);
4946 slist_free_strings(compose->header_list);
4947 g_slist_free(compose->header_list);
4949 procmsg_msginfo_free(compose->targetinfo);
4950 procmsg_msginfo_free(compose->replyinfo);
4952 g_free(compose->replyto);
4953 g_free(compose->cc);
4954 g_free(compose->bcc);
4955 g_free(compose->newsgroups);
4956 g_free(compose->followup_to);
4958 g_free(compose->inreplyto);
4959 g_free(compose->references);
4960 g_free(compose->msgid);
4961 g_free(compose->boundary);
4963 if (compose->bounce_filename)
4964 g_free(compose->bounce_filename);
4966 g_free(compose->exteditor_file);
4968 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
4970 compose_attach_info_free(ainfo);
4972 if (addressbook_get_target_compose() == compose)
4973 addressbook_set_target_compose(NULL);
4976 if (compose->gtkpspell) {
4977 gtkpspell_delete(compose->gtkpspell);
4981 prefs_common.compose_width = compose->scrolledwin->allocation.width;
4982 prefs_common.compose_height = compose->window->allocation.height;
4984 gtk_widget_destroy(compose->paned);
4988 compose_list = g_list_remove(compose_list, compose);
4991 static void compose_attach_info_free(AttachInfo *ainfo)
4993 g_free(ainfo->file);
4994 g_free(ainfo->content_type);
4995 g_free(ainfo->name);
4999 static void compose_attach_remove_selected(Compose *compose)
5001 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5005 while (clist->selection != NULL) {
5006 row = GPOINTER_TO_INT(clist->selection->data);
5007 ainfo = gtk_clist_get_row_data(clist, row);
5008 compose_attach_info_free(ainfo);
5009 gtk_clist_remove(clist, row);
5013 static struct _AttachProperty
5016 GtkWidget *mimetype_entry;
5017 GtkWidget *encoding_optmenu;
5018 GtkWidget *path_entry;
5019 GtkWidget *filename_entry;
5021 GtkWidget *cancel_btn;
5024 static void compose_attach_property(Compose *compose)
5026 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5029 GtkOptionMenu *optmenu;
5030 static gboolean cancelled;
5032 if (!clist->selection) return;
5033 row = GPOINTER_TO_INT(clist->selection->data);
5035 ainfo = gtk_clist_get_row_data(clist, row);
5038 if (!attach_prop.window)
5039 compose_attach_property_create(&cancelled);
5040 gtk_widget_grab_focus(attach_prop.ok_btn);
5041 gtk_widget_show(attach_prop.window);
5042 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5044 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5045 if (ainfo->encoding == ENC_UNKNOWN)
5046 gtk_option_menu_set_history(optmenu, ENC_BASE64);
5048 gtk_option_menu_set_history(optmenu, ainfo->encoding);
5050 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5051 ainfo->content_type ? ainfo->content_type : "");
5052 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5053 ainfo->file ? ainfo->file : "");
5054 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5055 ainfo->name ? ainfo->name : "");
5059 gchar *cnttype = NULL;
5063 GtkWidget *menuitem;
5068 if (cancelled == TRUE) {
5069 gtk_widget_hide(attach_prop.window);
5073 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5074 if (*text != '\0') {
5077 text = g_strstrip(g_strdup(text));
5078 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5079 cnttype = g_strdup(text);
5082 alertpanel_error(_("Invalid MIME type."));
5088 menu = gtk_option_menu_get_menu(optmenu);
5089 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5090 ainfo->encoding = GPOINTER_TO_INT
5091 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5093 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5094 if (*text != '\0') {
5095 if (is_file_exist(text) &&
5096 (size = get_file_size(text)) > 0)
5097 file = g_strdup(text);
5100 (_("File doesn't exist or is empty."));
5106 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5107 if (*text != '\0') {
5108 g_free(ainfo->name);
5109 ainfo->name = g_strdup(text);
5113 g_free(ainfo->content_type);
5114 ainfo->content_type = cnttype;
5117 g_free(ainfo->file);
5123 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5124 ainfo->content_type);
5125 gtk_clist_set_text(clist, row, COL_SIZE,
5126 to_human_readable(ainfo->size));
5127 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5129 gtk_widget_hide(attach_prop.window);
5134 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5136 label = gtk_label_new(str); \
5137 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5138 GTK_FILL, 0, 0, 0); \
5139 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5141 entry = gtk_entry_new(); \
5142 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5143 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5146 static void compose_attach_property_create(gboolean *cancelled)
5152 GtkWidget *mimetype_entry;
5155 GtkWidget *optmenu_menu;
5156 GtkWidget *menuitem;
5157 GtkWidget *path_entry;
5158 GtkWidget *filename_entry;
5161 GtkWidget *cancel_btn;
5162 GList *mime_type_list, *strlist;
5164 debug_print("Creating attach_property window...\n");
5166 window = gtk_window_new(GTK_WINDOW_DIALOG);
5167 gtk_widget_set_usize(window, 480, -1);
5168 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5169 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
5170 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5171 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5172 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5173 GTK_SIGNAL_FUNC(attach_property_delete_event),
5175 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5176 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5179 vbox = gtk_vbox_new(FALSE, 8);
5180 gtk_container_add(GTK_CONTAINER(window), vbox);
5182 table = gtk_table_new(4, 2, FALSE);
5183 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5184 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5185 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5187 label = gtk_label_new(_("MIME type"));
5188 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5190 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5191 mimetype_entry = gtk_combo_new();
5192 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5193 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5195 /* stuff with list */
5196 mime_type_list = procmime_get_mime_type_list();
5198 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5199 MimeType *type = (MimeType *) mime_type_list->data;
5200 strlist = g_list_append(strlist,
5201 g_strdup_printf("%s/%s",
5202 type->type, type->sub_type));
5205 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5207 for (mime_type_list = strlist; mime_type_list != NULL;
5208 mime_type_list = mime_type_list->next)
5209 g_free(mime_type_list->data);
5210 g_list_free(strlist);
5212 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5214 label = gtk_label_new(_("Encoding"));
5215 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5217 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5219 hbox = gtk_hbox_new(FALSE, 0);
5220 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5221 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5223 optmenu = gtk_option_menu_new();
5224 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5226 optmenu_menu = gtk_menu_new();
5227 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5228 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5230 gtk_widget_set_sensitive(menuitem, FALSE);
5232 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5233 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5235 gtk_widget_set_sensitive(menuitem, FALSE);
5237 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5238 gtk_widget_set_sensitive(menuitem, FALSE);
5239 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5241 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5243 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5244 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5246 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5247 &cancel_btn, _("Cancel"), NULL, NULL);
5248 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5249 gtk_widget_grab_default(ok_btn);
5251 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5252 GTK_SIGNAL_FUNC(attach_property_ok),
5254 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5255 GTK_SIGNAL_FUNC(attach_property_cancel),
5258 gtk_widget_show_all(vbox);
5260 attach_prop.window = window;
5261 attach_prop.mimetype_entry = mimetype_entry;
5262 attach_prop.encoding_optmenu = optmenu;
5263 attach_prop.path_entry = path_entry;
5264 attach_prop.filename_entry = filename_entry;
5265 attach_prop.ok_btn = ok_btn;
5266 attach_prop.cancel_btn = cancel_btn;
5269 #undef SET_LABEL_AND_ENTRY
5271 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5277 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5283 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5284 gboolean *cancelled)
5292 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5293 gboolean *cancelled)
5295 if (event && event->keyval == GDK_Escape) {
5301 static void compose_exec_ext_editor(Compose *compose)
5307 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5308 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5310 if (pipe(pipe_fds) < 0) {
5315 if ((pid = fork()) < 0) {
5321 /* close the write side of the pipe */
5324 compose->exteditor_file = g_strdup(tmp);
5325 compose->exteditor_pid = pid;
5326 compose->exteditor_readdes = pipe_fds[0];
5328 compose_set_ext_editor_sensitive(compose, FALSE);
5330 compose->exteditor_tag =
5331 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5332 compose_input_cb, compose);
5333 } else { /* process-monitoring process */
5339 /* close the read side of the pipe */
5342 if (compose_write_body_to_file(compose, tmp) < 0) {
5343 fd_write(pipe_fds[1], "2\n", 2);
5347 pid_ed = compose_exec_ext_editor_real(tmp);
5349 fd_write(pipe_fds[1], "1\n", 2);
5353 /* wait until editor is terminated */
5354 waitpid(pid_ed, NULL, 0);
5356 fd_write(pipe_fds[1], "0\n", 2);
5363 static gint compose_exec_ext_editor_real(const gchar *file)
5365 static gchar *def_cmd = "emacs %s";
5371 g_return_val_if_fail(file != NULL, -1);
5373 if ((pid = fork()) < 0) {
5378 if (pid != 0) return pid;
5380 /* grandchild process */
5382 if (setpgid(0, getppid()))
5385 if (prefs_common.ext_editor_cmd &&
5386 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5387 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5388 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5390 if (prefs_common.ext_editor_cmd)
5391 g_warning(_("External editor command line is invalid: `%s'\n"),
5392 prefs_common.ext_editor_cmd);
5393 g_snprintf(buf, sizeof(buf), def_cmd, file);
5396 cmdline = strsplit_with_quote(buf, " ", 1024);
5397 execvp(cmdline[0], cmdline);
5400 g_strfreev(cmdline);
5405 static gboolean compose_ext_editor_kill(Compose *compose)
5407 pid_t pgid = compose->exteditor_pid * -1;
5410 ret = kill(pgid, 0);
5412 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5416 msg = g_strdup_printf
5417 (_("The external editor is still working.\n"
5418 "Force terminating the process?\n"
5419 "process group id: %d"), -pgid);
5420 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5423 if (val == G_ALERTDEFAULT) {
5424 gdk_input_remove(compose->exteditor_tag);
5425 close(compose->exteditor_readdes);
5427 if (kill(pgid, SIGTERM) < 0) perror("kill");
5428 waitpid(compose->exteditor_pid, NULL, 0);
5430 g_warning(_("Terminated process group id: %d"), -pgid);
5431 g_warning(_("Temporary file: %s"),
5432 compose->exteditor_file);
5434 compose_set_ext_editor_sensitive(compose, TRUE);
5436 g_free(compose->exteditor_file);
5437 compose->exteditor_file = NULL;
5438 compose->exteditor_pid = -1;
5439 compose->exteditor_readdes = -1;
5440 compose->exteditor_tag = -1;
5448 static void compose_input_cb(gpointer data, gint source,
5449 GdkInputCondition condition)
5452 Compose *compose = (Compose *)data;
5455 debug_print(_("Compose: input from monitoring process\n"));
5457 gdk_input_remove(compose->exteditor_tag);
5460 if (read(source, &buf[i], 1) < 1) {
5464 if (buf[i] == '\n') {
5469 if (i == sizeof(buf) - 1)
5473 waitpid(compose->exteditor_pid, NULL, 0);
5475 if (buf[0] == '0') { /* success */
5476 GtkSText *text = GTK_STEXT(compose->text);
5478 gtk_stext_freeze(text);
5479 gtk_stext_set_point(text, 0);
5480 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5481 compose_insert_file(compose, compose->exteditor_file);
5482 compose_changed_cb(NULL, compose);
5483 gtk_stext_thaw(text);
5485 if (unlink(compose->exteditor_file) < 0)
5486 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5487 } else if (buf[0] == '1') { /* failed */
5488 g_warning(_("Couldn't exec external editor\n"));
5489 if (unlink(compose->exteditor_file) < 0)
5490 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5491 } else if (buf[0] == '2') {
5492 g_warning(_("Couldn't write to file\n"));
5493 } else if (buf[0] == '3') {
5494 g_warning(_("Pipe read failed\n"));
5499 compose_set_ext_editor_sensitive(compose, TRUE);
5501 g_free(compose->exteditor_file);
5502 compose->exteditor_file = NULL;
5503 compose->exteditor_pid = -1;
5504 compose->exteditor_readdes = -1;
5505 compose->exteditor_tag = -1;
5508 static void compose_set_ext_editor_sensitive(Compose *compose,
5511 GtkItemFactory *ifactory;
5513 ifactory = gtk_item_factory_from_widget(compose->menubar);
5515 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5516 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5517 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5519 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5520 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5521 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5522 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5523 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5526 gtk_widget_set_sensitive(compose->text, sensitive);
5527 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5528 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5529 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5530 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5531 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5532 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5533 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5537 * compose_undo_state_changed:
5539 * Change the sensivity of the menuentries undo and redo
5541 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5542 gint redo_state, gpointer data)
5544 GtkWidget *widget = GTK_WIDGET(data);
5545 GtkItemFactory *ifactory;
5547 g_return_if_fail(widget != NULL);
5549 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
5551 ifactory = gtk_item_factory_from_widget(widget);
5553 switch (undo_state) {
5554 case UNDO_STATE_TRUE:
5555 if (!undostruct->undo_state) {
5556 debug_print ("Set_undo - Testpoint\n");
5557 undostruct->undo_state = TRUE;
5558 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5561 case UNDO_STATE_FALSE:
5562 if (undostruct->undo_state) {
5563 undostruct->undo_state = FALSE;
5564 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5567 case UNDO_STATE_UNCHANGED:
5569 case UNDO_STATE_REFRESH:
5570 menu_set_sensitive(ifactory, "/Edit/Undo",
5571 undostruct->undo_state);
5574 g_warning("Undo state not recognized");
5578 switch (redo_state) {
5579 case UNDO_STATE_TRUE:
5580 if (!undostruct->redo_state) {
5581 undostruct->redo_state = TRUE;
5582 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5585 case UNDO_STATE_FALSE:
5586 if (undostruct->redo_state) {
5587 undostruct->redo_state = FALSE;
5588 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5591 case UNDO_STATE_UNCHANGED:
5593 case UNDO_STATE_REFRESH:
5594 menu_set_sensitive(ifactory, "/Edit/Redo",
5595 undostruct->redo_state);
5598 g_warning("Redo state not recognized");
5603 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5607 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5608 cursor_pos = MAX(cursor_pos, 0);
5613 /* callback functions */
5615 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5616 * includes "non-client" (windows-izm) in calculation, so this calculation
5617 * may not be accurate.
5619 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5620 GtkAllocation *allocation,
5621 GtkSHRuler *shruler)
5623 if (prefs_common.show_ruler) {
5625 gint line_width_in_chars;
5627 char_width = gtkut_get_font_width
5628 (GTK_WIDGET(widget)->style->font);
5629 line_width_in_chars =
5630 (allocation->width - allocation->x) / char_width;
5632 /* got the maximum */
5633 gtk_ruler_set_range(GTK_RULER(shruler),
5634 0.0, line_width_in_chars,
5635 calc_cursor_xpos(GTK_STEXT(widget),
5638 /*line_width_in_chars*/ char_width);
5644 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5646 compose_send_cb(data, 0, NULL);
5649 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5651 compose_send_later_cb(data, 0, NULL);
5654 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5656 compose_draft_cb(data, 0, NULL);
5659 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5661 compose_insert_file_cb(data, 0, NULL);
5664 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5666 compose_attach_cb(data, 0, NULL);
5669 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5671 Compose *compose = (Compose *)data;
5673 compose_insert_sig(compose);
5676 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5678 Compose *compose = (Compose *)data;
5680 compose_exec_ext_editor(compose);
5683 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5685 Compose *compose = (Compose *)data;
5687 compose_wrap_line(compose);
5690 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5692 compose_address_cb(data, 0, NULL);
5695 static void select_account(Compose * compose, PrefsAccount * ac)
5698 GtkItemFactory *ifactory;
5699 GtkWidget *menuitem;
5700 #endif /* USE_GPGME */
5701 compose->account = ac;
5702 compose_set_title(compose);
5704 #if 0 /* NEW COMPOSE GUI */
5705 if (ac->protocol == A_NNTP) {
5706 GtkItemFactory *ifactory;
5707 GtkWidget *menuitem;
5709 ifactory = gtk_item_factory_from_widget(compose->menubar);
5710 menu_set_sensitive(ifactory,
5711 "/Message/Followup to", TRUE);
5712 gtk_widget_show(compose->newsgroups_hbox);
5713 gtk_widget_show(compose->newsgroups_entry);
5714 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5717 compose->use_to = FALSE;
5718 compose->use_cc = FALSE;
5720 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5721 gtk_check_menu_item_set_active
5722 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5724 menu_set_sensitive(ifactory,
5725 "/Message/To", TRUE);
5726 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5727 gtk_check_menu_item_set_active
5728 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5730 gtk_widget_hide(compose->to_hbox);
5731 gtk_widget_hide(compose->to_entry);
5732 gtk_widget_hide(compose->cc_hbox);
5733 gtk_widget_hide(compose->cc_entry);
5734 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5736 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5740 GtkItemFactory *ifactory;
5741 GtkWidget *menuitem;
5743 ifactory = gtk_item_factory_from_widget(compose->menubar);
5744 menu_set_sensitive(ifactory,
5745 "/Message/Followup to", FALSE);
5746 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5747 gtk_widget_hide(compose->newsgroups_hbox);
5748 gtk_widget_hide(compose->newsgroups_entry);
5749 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5752 compose->use_to = TRUE;
5753 compose->use_cc = TRUE;
5755 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5756 gtk_check_menu_item_set_active
5757 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5758 menu_set_sensitive(ifactory,
5759 "/Message/To", FALSE);
5760 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5761 gtk_check_menu_item_set_active
5762 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5763 gtk_widget_show(compose->to_hbox);
5764 gtk_widget_show(compose->to_entry);
5765 gtk_widget_show(compose->cc_hbox);
5766 gtk_widget_show(compose->cc_entry);
5768 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5770 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5773 gtk_widget_queue_resize(compose->table_vbox);
5776 ifactory = gtk_item_factory_from_widget(compose->menubar);
5777 menu_set_sensitive(ifactory,
5778 "/Message/Sign", TRUE);
5779 menu_set_sensitive(ifactory,
5780 "/Message/Encrypt", TRUE);
5782 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
5783 if (ac->default_sign)
5784 gtk_check_menu_item_set_active
5785 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5787 gtk_check_menu_item_set_active
5788 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5790 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
5791 if (ac->default_encrypt)
5792 gtk_check_menu_item_set_active
5793 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5795 gtk_check_menu_item_set_active
5796 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5797 #endif /* USE_GPGME */
5801 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5803 Compose *compose = (Compose *)data;
5807 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5808 g_return_if_fail(ac != NULL);
5810 if (ac != compose->account)
5811 select_account(compose, ac);
5814 static void attach_selected(GtkCList *clist, gint row, gint column,
5815 GdkEvent *event, gpointer data)
5817 Compose *compose = (Compose *)data;
5819 if (event && event->type == GDK_2BUTTON_PRESS)
5820 compose_attach_property(compose);
5823 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5826 Compose *compose = (Compose *)data;
5827 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5832 if (event->button == 3) {
5833 if ((clist->selection && !clist->selection->next) ||
5834 !clist->selection) {
5835 gtk_clist_unselect_all(clist);
5836 if (gtk_clist_get_selection_info(clist,
5839 gtk_clist_select_row(clist, row, column);
5840 gtkut_clist_set_focus_row(clist, row);
5843 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5844 NULL, NULL, event->button, event->time);
5848 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5851 Compose *compose = (Compose *)data;
5855 switch (event->keyval) {
5857 compose_attach_remove_selected(compose);
5862 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5864 Compose *compose = (Compose *)data;
5867 val = compose_send(compose);
5869 if (val == 0) gtk_widget_destroy(compose->window);
5872 static void compose_send_later_cb(gpointer data, guint action,
5875 Compose *compose = (Compose *)data;
5878 val = compose_queue(compose, NULL, NULL);
5879 if (!val) gtk_widget_destroy(compose->window);
5882 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5884 Compose *compose = (Compose *)data;
5888 static gboolean lock = FALSE;
5892 draft = folder_get_default_draft();
5893 g_return_if_fail(draft != NULL);
5897 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5898 G_DIR_SEPARATOR, (gint)compose);
5900 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5906 folder_item_scan(draft);
5907 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) <= 0) {
5914 draft->mtime = 0; /* force updating */
5916 if (compose->mode == COMPOSE_REEDIT) {
5917 compose_remove_reedit_target(compose);
5918 if (compose->targetinfo &&
5919 compose->targetinfo->folder != draft)
5920 folderview_update_item(compose->targetinfo->folder,
5924 folder_item_scan(draft);
5925 folderview_update_item(draft, TRUE);
5929 /* 0: quit editing 1: keep editing */
5931 gtk_widget_destroy(compose->window);
5936 path = folder_item_fetch_msg(draft, msgnum);
5937 g_return_if_fail(path != NULL);
5938 if (stat(path, &s) < 0) {
5939 FILE_OP_ERROR(path, "stat");
5946 procmsg_msginfo_free(compose->targetinfo);
5947 compose->targetinfo = g_new0(MsgInfo, 1);
5948 compose->targetinfo->msgnum = msgnum;
5949 compose->targetinfo->size = s.st_size;
5950 compose->targetinfo->mtime = s.st_mtime;
5951 compose->targetinfo->folder = draft;
5952 compose->mode = COMPOSE_REEDIT;
5956 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
5958 Compose *compose = (Compose *)data;
5961 if (compose->bounce_filename != NULL)
5964 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5969 for ( tmp = file_list; tmp; tmp = tmp->next) {
5970 gchar *file = (gchar *) tmp->data;
5971 compose_attach_append(compose, file, file, NULL);
5972 compose_changed_cb(NULL, compose);
5975 g_list_free(file_list);
5979 static void compose_insert_file_cb(gpointer data, guint action,
5982 Compose *compose = (Compose *)data;
5985 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5990 for ( tmp = file_list; tmp; tmp = tmp->next) {
5991 gchar *file = (gchar *) tmp->data;
5992 compose_insert_file(compose, file);
5995 g_list_free(file_list);
5999 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6002 compose_close_cb(data, 0, NULL);
6006 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6008 Compose *compose = (Compose *)data;
6011 if (compose->exteditor_tag != -1) {
6012 if (!compose_ext_editor_kill(compose))
6016 if (compose->modified) {
6017 val = alertpanel(_("Discard message"),
6018 _("This message has been modified. discard it?"),
6019 _("Discard"), _("to Draft"), _("Cancel"));
6022 case G_ALERTDEFAULT:
6024 case G_ALERTALTERNATE:
6025 compose_draft_cb(data, 0, NULL);
6031 gtk_widget_destroy(compose->window);
6034 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6036 Compose *compose = (Compose *)data;
6038 addressbook_open(compose);
6041 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6043 Compose *compose = (Compose *)data;
6046 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6047 g_return_if_fail(tmpl != NULL);
6049 compose_template_apply(compose, tmpl);
6052 static void compose_ext_editor_cb(gpointer data, guint action,
6055 Compose *compose = (Compose *)data;
6057 compose_exec_ext_editor(compose);
6060 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6062 compose_destroy(compose);
6065 static void compose_undo_cb(Compose *compose)
6067 undo_undo(compose->undostruct);
6070 static void compose_redo_cb(Compose *compose)
6072 undo_redo(compose->undostruct);
6075 static void compose_cut_cb(Compose *compose)
6077 if (compose->focused_editable &&
6078 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6079 gtk_editable_cut_clipboard
6080 (GTK_EDITABLE(compose->focused_editable));
6083 static void compose_copy_cb(Compose *compose)
6085 if (compose->focused_editable &&
6086 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6087 gtk_editable_copy_clipboard
6088 (GTK_EDITABLE(compose->focused_editable));
6091 static void compose_paste_cb(Compose *compose)
6093 if (compose->focused_editable &&
6094 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6095 gtk_editable_paste_clipboard
6096 (GTK_EDITABLE(compose->focused_editable));
6099 static void compose_allsel_cb(Compose *compose)
6101 if (compose->focused_editable &&
6102 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6103 gtk_editable_select_region
6104 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6107 static void compose_move_beginning_of_line_cb(Compose *compose)
6109 if (compose->focused_editable &&
6110 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6111 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6114 static void compose_gtk_stext_action_cb(Compose *compose, ComposeCallGtkSTextAction action)
6116 if (!(compose->focused_editable && GTK_WIDGET_HAS_FOCUS(compose->focused_editable))) return;
6119 case COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE:
6120 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6122 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER:
6123 gtk_stext_move_forward_character(GTK_STEXT(compose->focused_editable));
6125 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER:
6126 gtk_stext_move_backward_character(GTK_STEXT(compose->focused_editable));
6128 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD:
6129 gtk_stext_move_forward_word(GTK_STEXT(compose->focused_editable));
6131 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD:
6132 gtk_stext_move_backward_word(GTK_STEXT(compose->focused_editable));
6134 case COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE:
6135 gtk_stext_move_end_of_line(GTK_STEXT(compose->focused_editable));
6137 case COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE:
6138 gtk_stext_move_next_line(GTK_STEXT(compose->focused_editable));
6140 case COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE:
6141 gtk_stext_move_previous_line(GTK_STEXT(compose->focused_editable));
6143 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER:
6144 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6146 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER:
6147 gtk_stext_delete_backward_character(GTK_STEXT(compose->focused_editable));
6149 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD:
6150 gtk_stext_delete_forward_word(GTK_STEXT(compose->focused_editable));
6152 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD:
6153 gtk_stext_delete_backward_word(GTK_STEXT(compose->focused_editable));
6155 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE:
6156 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6158 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N:
6159 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6160 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6162 case COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END:
6163 gtk_stext_delete_to_line_end(GTK_STEXT(compose->focused_editable));
6170 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6172 if (GTK_IS_EDITABLE(widget))
6173 compose->focused_editable = widget;
6176 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6178 if (compose->modified == FALSE) {
6179 compose->modified = TRUE;
6180 compose_set_title(compose);
6184 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6187 gtk_stext_set_point(GTK_STEXT(widget),
6188 gtk_editable_get_position(GTK_EDITABLE(widget)));
6192 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6195 gtk_stext_set_point(GTK_STEXT(widget),
6196 gtk_editable_get_position(GTK_EDITABLE(widget)));
6200 #if 0 /* NEW COMPOSE GUI */
6201 static void compose_toggle_to_cb(gpointer data, guint action,
6204 Compose *compose = (Compose *)data;
6206 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6207 gtk_widget_show(compose->to_hbox);
6208 gtk_widget_show(compose->to_entry);
6209 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6210 compose->use_to = TRUE;
6212 gtk_widget_hide(compose->to_hbox);
6213 gtk_widget_hide(compose->to_entry);
6214 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6215 gtk_widget_queue_resize(compose->table_vbox);
6216 compose->use_to = FALSE;
6219 if (addressbook_get_target_compose() == compose)
6220 addressbook_set_target_compose(compose);
6223 static void compose_toggle_cc_cb(gpointer data, guint action,
6226 Compose *compose = (Compose *)data;
6228 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6229 gtk_widget_show(compose->cc_hbox);
6230 gtk_widget_show(compose->cc_entry);
6231 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6232 compose->use_cc = TRUE;
6234 gtk_widget_hide(compose->cc_hbox);
6235 gtk_widget_hide(compose->cc_entry);
6236 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6237 gtk_widget_queue_resize(compose->table_vbox);
6238 compose->use_cc = FALSE;
6241 if (addressbook_get_target_compose() == compose)
6242 addressbook_set_target_compose(compose);
6245 static void compose_toggle_bcc_cb(gpointer data, guint action,
6248 Compose *compose = (Compose *)data;
6250 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6251 gtk_widget_show(compose->bcc_hbox);
6252 gtk_widget_show(compose->bcc_entry);
6253 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6254 compose->use_bcc = TRUE;
6256 gtk_widget_hide(compose->bcc_hbox);
6257 gtk_widget_hide(compose->bcc_entry);
6258 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6259 gtk_widget_queue_resize(compose->table_vbox);
6260 compose->use_bcc = FALSE;
6263 if (addressbook_get_target_compose() == compose)
6264 addressbook_set_target_compose(compose);
6267 static void compose_toggle_replyto_cb(gpointer data, guint action,
6270 Compose *compose = (Compose *)data;
6272 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6273 gtk_widget_show(compose->reply_hbox);
6274 gtk_widget_show(compose->reply_entry);
6275 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6276 compose->use_replyto = TRUE;
6278 gtk_widget_hide(compose->reply_hbox);
6279 gtk_widget_hide(compose->reply_entry);
6280 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6281 gtk_widget_queue_resize(compose->table_vbox);
6282 compose->use_replyto = FALSE;
6286 static void compose_toggle_followupto_cb(gpointer data, guint action,
6289 Compose *compose = (Compose *)data;
6291 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6292 gtk_widget_show(compose->followup_hbox);
6293 gtk_widget_show(compose->followup_entry);
6294 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6295 compose->use_followupto = TRUE;
6297 gtk_widget_hide(compose->followup_hbox);
6298 gtk_widget_hide(compose->followup_entry);
6299 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6300 gtk_widget_queue_resize(compose->table_vbox);
6301 compose->use_followupto = FALSE;
6305 static void compose_toggle_attach_cb(gpointer data, guint action,
6308 Compose *compose = (Compose *)data;
6310 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6311 gtk_widget_ref(compose->edit_vbox);
6313 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6314 compose->edit_vbox);
6315 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6316 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6318 gtk_widget_show(compose->paned);
6320 gtk_widget_unref(compose->edit_vbox);
6321 gtk_widget_unref(compose->paned);
6323 compose->use_attach = TRUE;
6325 gtk_widget_ref(compose->paned);
6326 gtk_widget_ref(compose->edit_vbox);
6328 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6330 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6331 compose->edit_vbox);
6332 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6333 compose->edit_vbox, TRUE, TRUE, 0);
6335 gtk_widget_unref(compose->edit_vbox);
6337 compose->use_attach = FALSE;
6343 static void compose_toggle_sign_cb(gpointer data, guint action,
6346 Compose *compose = (Compose *)data;
6348 if (GTK_CHECK_MENU_ITEM(widget)->active)
6349 compose->use_signing = TRUE;
6351 compose->use_signing = FALSE;
6354 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6357 Compose *compose = (Compose *)data;
6359 if (GTK_CHECK_MENU_ITEM(widget)->active)
6360 compose->use_encryption = TRUE;
6362 compose->use_encryption = FALSE;
6364 #endif /* USE_GPGME */
6366 static void compose_toggle_ruler_cb(gpointer data, guint action,
6369 Compose *compose = (Compose *)data;
6371 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6372 gtk_widget_show(compose->ruler_hbox);
6373 prefs_common.show_ruler = TRUE;
6375 gtk_widget_hide(compose->ruler_hbox);
6376 gtk_widget_queue_resize(compose->edit_vbox);
6377 prefs_common.show_ruler = FALSE;
6381 static void compose_attach_drag_received_cb (GtkWidget *widget,
6382 GdkDragContext *drag_context,
6385 GtkSelectionData *data,
6390 Compose *compose = (Compose *)user_data;
6393 list = uri_list_extract_filenames((const gchar *)data->data);
6394 for (tmp = list; tmp != NULL; tmp = tmp->next)
6395 compose_attach_append
6396 (compose, (const gchar *)tmp->data,
6397 (const gchar *)tmp->data, NULL);
6398 if (list) compose_changed_cb(NULL, compose);
6399 list_free_strings(list);
6403 static void compose_insert_drag_received_cb (GtkWidget *widget,
6404 GdkDragContext *drag_context,
6407 GtkSelectionData *data,
6412 Compose *compose = (Compose *)user_data;
6415 list = uri_list_extract_filenames((const gchar *)data->data);
6416 for (tmp = list; tmp != NULL; tmp = tmp->next)
6417 compose_insert_file(compose, (const gchar *)tmp->data);
6418 list_free_strings(list);
6422 #if 0 /* NEW COMPOSE GUI */
6423 static void to_activated(GtkWidget *widget, Compose *compose)
6425 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6426 gtk_widget_grab_focus(compose->newsgroups_entry);
6428 gtk_widget_grab_focus(compose->subject_entry);
6431 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6433 gtk_widget_grab_focus(compose->subject_entry);
6436 static void subject_activated(GtkWidget *widget, Compose *compose)
6438 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6439 gtk_widget_grab_focus(compose->cc_entry);
6440 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6441 gtk_widget_grab_focus(compose->bcc_entry);
6442 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6443 gtk_widget_grab_focus(compose->reply_entry);
6444 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6445 gtk_widget_grab_focus(compose->followup_entry);
6447 gtk_widget_grab_focus(compose->text);
6450 static void cc_activated(GtkWidget *widget, Compose *compose)
6452 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6453 gtk_widget_grab_focus(compose->bcc_entry);
6454 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6455 gtk_widget_grab_focus(compose->reply_entry);
6456 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6457 gtk_widget_grab_focus(compose->followup_entry);
6459 gtk_widget_grab_focus(compose->text);
6462 static void bcc_activated(GtkWidget *widget, Compose *compose)
6464 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6465 gtk_widget_grab_focus(compose->reply_entry);
6466 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6467 gtk_widget_grab_focus(compose->followup_entry);
6469 gtk_widget_grab_focus(compose->text);
6472 static void replyto_activated(GtkWidget *widget, Compose *compose)
6474 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6475 gtk_widget_grab_focus(compose->followup_entry);
6477 gtk_widget_grab_focus(compose->text);
6480 static void followupto_activated(GtkWidget *widget, Compose *compose)
6482 gtk_widget_grab_focus(compose->text);
6486 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6489 Compose *compose = (Compose *)data;
6491 if (GTK_CHECK_MENU_ITEM(widget)->active)
6492 compose->return_receipt = TRUE;
6494 compose->return_receipt = FALSE;
6497 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6499 ComposeHeaderEntry *headerentry)
6501 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6502 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6503 !(event->state & GDK_MODIFIER_MASK) &&
6504 (event->keyval == GDK_BackSpace) &&
6505 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6506 gtk_container_remove
6507 (GTK_CONTAINER(headerentry->compose->header_table),
6508 headerentry->combo);
6509 gtk_container_remove
6510 (GTK_CONTAINER(headerentry->compose->header_table),
6511 headerentry->entry);
6512 headerentry->compose->header_list =
6513 g_slist_remove(headerentry->compose->header_list,
6515 g_free(headerentry);
6516 } else if (event->keyval == GDK_Tab) {
6517 if (headerentry->compose->header_last == headerentry) {
6518 /* Override default next focus, and give it to subject_entry
6519 * instead of notebook tabs
6521 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6522 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6528 void compose_headerentry_changed_cb(GtkWidget *entry,
6529 ComposeHeaderEntry *headerentry)
6531 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6532 headerentry->compose->header_list =
6533 g_slist_append(headerentry->compose->header_list,
6535 compose_create_header_entry(headerentry->compose);
6536 gtk_signal_disconnect_by_func
6538 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6540 /* Automatically scroll down */
6541 compose_show_first_last_header(headerentry->compose, FALSE);
6546 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6548 GtkAdjustment *vadj;
6550 g_return_if_fail(compose);
6551 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6552 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6554 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6555 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6558 static void text_activated(GtkWidget *widget, Compose *compose)
6560 compose_send_control_enter(compose);
6563 static gboolean compose_send_control_enter(Compose *compose)
6567 GtkItemFactory *ifactory;
6568 GtkAccelEntry *accel;
6569 GtkWidget *send_menu;
6572 ev = gtk_get_current_event();
6573 if (ev->type != GDK_KEY_PRESS) return FALSE;
6575 kev = (GdkEventKey *)ev;
6576 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6579 ifactory = gtk_item_factory_from_widget(compose->menubar);
6580 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6581 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6582 accel = (GtkAccelEntry *)list->data;
6583 if (accel->accelerator_key == kev->keyval &&
6584 accel->accelerator_mods == kev->state) {
6585 compose_send_cb(compose, 0, NULL);
6593 static void compose_check_all(Compose *compose)
6595 if (compose->gtkpspell)
6596 gtkpspell_check_all(compose->gtkpspell);
6599 static void compose_highlight_all(Compose *compose)
6601 if (compose->gtkpspell)
6602 gtkpspell_highlight_all(compose->gtkpspell);
6605 static void compose_check_backwards(Compose *compose)
6607 if (compose->gtkpspell)
6608 gtkpspell_check_backwards(compose->gtkpspell);
6610 GtkItemFactory *ifactory;
6611 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6612 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6613 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6617 static void compose_check_forwards_go(Compose *compose)
6619 if (compose->gtkpspell)
6620 gtkpspell_check_forwards_go(compose->gtkpspell);
6622 GtkItemFactory *ifactory;
6623 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6624 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6625 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6630 static void set_toolbar_style(Compose *compose)
6632 switch (prefs_common.toolbar_style) {
6634 gtk_widget_hide(compose->handlebox);
6637 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6641 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6645 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6650 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
6651 gtk_widget_show(compose->handlebox);
6652 gtk_widget_queue_resize(compose->handlebox);