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;
143 PRIORITY_HIGHEST = 1,
150 #define B64_LINE_SIZE 57
151 #define B64_BUFFSIZE 77
153 #define MAX_REFERENCES_LEN 999
155 static GdkColor quote_color = {0, 0, 0, 0xbfff};
157 static GList *compose_list = NULL;
159 Compose *compose_generic_new (PrefsAccount *account,
163 static Compose *compose_create (PrefsAccount *account,
165 static void compose_toolbar_create (Compose *compose,
166 GtkWidget *container);
167 static GtkWidget *compose_account_option_menu_create
169 static void compose_set_template_menu (Compose *compose);
170 static void compose_template_apply (Compose *compose,
173 static void compose_destroy (Compose *compose);
175 static void compose_entries_set (Compose *compose,
176 const gchar *mailto);
177 static gint compose_parse_header (Compose *compose,
179 static gchar *compose_parse_references (const gchar *ref,
182 static gchar *compose_quote_fmt (Compose *compose,
188 static void compose_reply_set_entry (Compose *compose,
193 followup_and_reply_to);
194 static void compose_reedit_set_entry (Compose *compose,
196 static void compose_insert_sig (Compose *compose);
197 static void compose_insert_file (Compose *compose,
199 static void compose_attach_append (Compose *compose,
202 const gchar *content_type);
203 static void compose_attach_parts (Compose *compose,
205 static void compose_wrap_line (Compose *compose);
206 static void compose_wrap_line_all (Compose *compose);
207 static void compose_set_title (Compose *compose);
209 static PrefsAccount *compose_current_mail_account(void);
210 /* static gint compose_send (Compose *compose); */
211 static gboolean compose_check_for_valid_recipient
213 static gboolean compose_check_entries (Compose *compose,
214 gboolean check_subject);
215 static gint compose_write_to_file (Compose *compose,
218 static gint compose_write_body_to_file (Compose *compose,
220 static gint compose_remove_reedit_target (Compose *compose);
221 static gint compose_queue (Compose *compose,
224 static gint compose_queue_sub (Compose *compose,
227 gboolean check_subject);
228 static void compose_write_attach (Compose *compose,
230 static gint compose_write_headers (Compose *compose,
232 const gchar *charset,
233 EncodingType encoding,
236 static void compose_convert_header (gchar *dest,
240 static void compose_generate_msgid (Compose *compose,
244 static void compose_attach_info_free (AttachInfo *ainfo);
245 static void compose_attach_remove_selected (Compose *compose);
247 static void compose_attach_property (Compose *compose);
248 static void compose_attach_property_create (gboolean *cancelled);
249 static void attach_property_ok (GtkWidget *widget,
250 gboolean *cancelled);
251 static void attach_property_cancel (GtkWidget *widget,
252 gboolean *cancelled);
253 static gint attach_property_delete_event (GtkWidget *widget,
255 gboolean *cancelled);
256 static void attach_property_key_pressed (GtkWidget *widget,
258 gboolean *cancelled);
260 static void compose_exec_ext_editor (Compose *compose);
261 static gint compose_exec_ext_editor_real (const gchar *file);
262 static gboolean compose_ext_editor_kill (Compose *compose);
263 static void compose_input_cb (gpointer data,
265 GdkInputCondition condition);
266 static void compose_set_ext_editor_sensitive (Compose *compose,
269 static void compose_undo_state_changed (UndoMain *undostruct,
274 static gint calc_cursor_xpos (GtkSText *text,
278 static void compose_create_header_entry (Compose *compose);
279 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
280 static void compose_update_priority_menu_item(Compose * compose);
282 /* callback functions */
284 static gboolean compose_edit_size_alloc (GtkEditable *widget,
285 GtkAllocation *allocation,
286 GtkSHRuler *shruler);
288 static void toolbar_send_cb (GtkWidget *widget,
290 static void toolbar_send_later_cb (GtkWidget *widget,
292 static void toolbar_draft_cb (GtkWidget *widget,
294 static void toolbar_insert_cb (GtkWidget *widget,
296 static void toolbar_attach_cb (GtkWidget *widget,
298 static void toolbar_sig_cb (GtkWidget *widget,
300 static void toolbar_ext_editor_cb (GtkWidget *widget,
302 static void toolbar_linewrap_cb (GtkWidget *widget,
304 static void toolbar_address_cb (GtkWidget *widget,
307 static void select_account (Compose *compose,
310 static void account_activated (GtkMenuItem *menuitem,
313 static void attach_selected (GtkCList *clist,
318 static void attach_button_pressed (GtkWidget *widget,
319 GdkEventButton *event,
321 static void attach_key_pressed (GtkWidget *widget,
325 static void compose_send_cb (gpointer data,
328 static void compose_send_later_cb (gpointer data,
332 static void compose_draft_cb (gpointer data,
336 static void compose_attach_cb (gpointer data,
339 static void compose_insert_file_cb (gpointer data,
343 static void compose_close_cb (gpointer data,
347 static void compose_address_cb (gpointer data,
350 static void compose_template_activate_cb(GtkWidget *widget,
353 static void compose_ext_editor_cb (gpointer data,
357 static gint compose_delete_cb (GtkWidget *widget,
360 static void compose_destroy_cb (GtkWidget *widget,
363 static void compose_undo_cb (Compose *compose);
364 static void compose_redo_cb (Compose *compose);
365 static void compose_cut_cb (Compose *compose);
366 static void compose_copy_cb (Compose *compose);
367 static void compose_paste_cb (Compose *compose);
368 static void compose_paste_as_quote_cb (Compose *compose);
369 static void compose_allsel_cb (Compose *compose);
371 static void compose_gtk_stext_action_cb (Compose *compose,
372 ComposeCallGtkSTextAction action);
374 static void compose_grab_focus_cb (GtkWidget *widget,
377 static void compose_changed_cb (GtkEditable *editable,
379 static void compose_button_press_cb (GtkWidget *widget,
380 GdkEventButton *event,
383 static void compose_key_press_cb (GtkWidget *widget,
389 static void compose_toggle_to_cb (gpointer data,
392 static void compose_toggle_cc_cb (gpointer data,
395 static void compose_toggle_bcc_cb (gpointer data,
398 static void compose_toggle_replyto_cb (gpointer data,
401 static void compose_toggle_followupto_cb(gpointer data,
404 static void compose_toggle_attach_cb (gpointer data,
408 static void compose_toggle_ruler_cb (gpointer data,
412 static void compose_toggle_sign_cb (gpointer data,
415 static void compose_toggle_encrypt_cb (gpointer data,
419 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
421 static void compose_set_priority_cb (gpointer data,
425 static void compose_attach_drag_received_cb (GtkWidget *widget,
426 GdkDragContext *drag_context,
429 GtkSelectionData *data,
433 static void compose_insert_drag_received_cb (GtkWidget *widget,
434 GdkDragContext *drag_context,
437 GtkSelectionData *data,
443 static void to_activated (GtkWidget *widget,
445 static void newsgroups_activated (GtkWidget *widget,
447 static void cc_activated (GtkWidget *widget,
449 static void bcc_activated (GtkWidget *widget,
451 static void replyto_activated (GtkWidget *widget,
453 static void followupto_activated (GtkWidget *widget,
455 static void subject_activated (GtkWidget *widget,
459 static void text_activated (GtkWidget *widget,
461 static void text_inserted (GtkWidget *widget,
466 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
468 gboolean ignore_replyto,
469 gboolean followup_and_reply_to,
472 void compose_headerentry_changed_cb (GtkWidget *entry,
473 ComposeHeaderEntry *headerentry);
474 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
476 ComposeHeaderEntry *headerentry);
478 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
481 static void compose_check_all (Compose *compose);
482 static void compose_highlight_all (Compose *compose);
483 static void compose_check_backwards (Compose *compose);
484 static void compose_check_forwards_go (Compose *compose);
487 static gboolean compose_send_control_enter (Compose *compose);
489 static GtkItemFactoryEntry compose_popup_entries[] =
491 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
492 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
493 {N_("/---"), NULL, NULL, 0, "<Separator>"},
494 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
497 static GtkItemFactoryEntry compose_entries[] =
499 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
500 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
501 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
502 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
503 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
504 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
506 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
507 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
508 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
509 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
510 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
511 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
512 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
513 {N_("/_Edit/Paste as _quotation"),
514 NULL, compose_paste_as_quote_cb, 0, NULL},
515 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
516 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
517 {N_("/_Edit/A_dvanced/Move a character backward"),
519 compose_gtk_stext_action_cb,
520 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
522 {N_("/_Edit/A_dvanced/Move a character forward"),
524 compose_gtk_stext_action_cb,
525 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
527 {N_("/_Edit/A_dvanced/Move a word backward"),
529 compose_gtk_stext_action_cb,
530 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
532 {N_("/_Edit/A_dvanced/Move a word forward"),
534 compose_gtk_stext_action_cb,
535 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
537 {N_("/_Edit/A_dvanced/Move to beginning of line"),
538 NULL, /* "<control>A" */
539 compose_gtk_stext_action_cb,
540 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
542 {N_("/_Edit/A_dvanced/Move to end of line"),
544 compose_gtk_stext_action_cb,
545 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
547 {N_("/_Edit/A_dvanced/Move to previous line"),
549 compose_gtk_stext_action_cb,
550 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
552 {N_("/_Edit/A_dvanced/Move to next line"),
554 compose_gtk_stext_action_cb,
555 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
557 {N_("/_Edit/A_dvanced/Delete a character backward"),
559 compose_gtk_stext_action_cb,
560 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
562 {N_("/_Edit/A_dvanced/Delete a character forward"),
564 compose_gtk_stext_action_cb,
565 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
567 {N_("/_Edit/A_dvanced/Delete a word backward"),
568 NULL, /* "<control>W" */
569 compose_gtk_stext_action_cb,
570 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
572 {N_("/_Edit/A_dvanced/Delete a word forward"),
573 NULL, /* "<alt>D", */
574 compose_gtk_stext_action_cb,
575 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
577 {N_("/_Edit/A_dvanced/Delete line"),
579 compose_gtk_stext_action_cb,
580 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
582 {N_("/_Edit/A_dvanced/Delete entire line"),
584 compose_gtk_stext_action_cb,
585 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
587 {N_("/_Edit/A_dvanced/Delete to end of line"),
589 compose_gtk_stext_action_cb,
590 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
592 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
593 {N_("/_Edit/_Wrap current paragraph"),
594 "<control>L", compose_wrap_line, 0, NULL},
595 {N_("/_Edit/Wrap all long _lines"),
596 "<control><alt>L", compose_wrap_line_all, 0, NULL},
597 {N_("/_Edit/Edit with e_xternal editor"),
598 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
600 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
601 {N_("/_Spelling/_Check all or check selection"),
602 NULL, compose_check_all, 0, NULL},
603 {N_("/_Spelling/_Highlight all misspelled words"),
604 NULL, compose_highlight_all, 0, NULL},
605 {N_("/_Spelling/Check _backwards misspelled word"),
606 NULL, compose_check_backwards , 0, NULL},
607 {N_("/_Spelling/_Forward to next misspelled word"),
608 NULL, compose_check_forwards_go, 0, NULL},
609 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
610 {N_("/_Spelling/_Spelling Configuration"),
611 NULL, NULL, 0, "<Branch>"},
613 #if 0 /* NEW COMPOSE GUI */
614 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
615 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
616 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
617 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
618 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
619 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
620 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
621 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
622 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
623 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
624 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
626 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
627 {N_("/_Message/_Send"), "<control>Return",
628 compose_send_cb, 0, NULL},
629 {N_("/_Message/Send _later"), "<shift><control>S",
630 compose_send_later_cb, 0, NULL},
631 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
632 {N_("/_Message/Save to _draft folder"),
633 "<shift><control>D", compose_draft_cb, 0, NULL},
634 {N_("/_Message/Save and _keep editing"),
635 "<control>S", compose_draft_cb, 1, NULL},
636 #if 0 /* NEW COMPOSE GUI */
637 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
638 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
639 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
640 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
641 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
642 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
643 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
644 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
645 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
648 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
649 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
650 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
651 #endif /* USE_GPGME */
652 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
653 {N_("/_Message/Priority"), NULL, NULL, 0, "<Branch>"},
654 {N_("/_Message/Priority/Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
655 {N_("/_Message/Priority/High"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
656 {N_("/_Message/Priority/Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
657 {N_("/_Message/Priority/Low"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
658 {N_("/_Message/Priority/Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
659 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
660 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
661 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
662 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
663 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
664 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
665 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
666 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
667 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
670 static GtkTargetEntry compose_mime_types[] =
672 {"text/uri-list", 0, 0}
675 Compose *compose_new(PrefsAccount *account)
677 return compose_generic_new(account, NULL, NULL);
680 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
684 GtkItemFactory *ifactory;
686 c = compose_generic_new(account, NULL, NULL);
688 filename = procmsg_get_message_file(msginfo);
689 if (filename == NULL)
692 c->redirect_filename = filename;
694 if (msginfo->subject)
695 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
697 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
699 compose_quote_fmt(c, msginfo, "%M", NULL, NULL);
700 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
702 ifactory = gtk_item_factory_from_widget(c->popupmenu);
703 menu_set_sensitive(ifactory, "/Add...", FALSE);
704 menu_set_sensitive(ifactory, "/Remove", FALSE);
705 menu_set_sensitive(ifactory, "/Property...", FALSE);
707 ifactory = gtk_item_factory_from_widget(c->menubar);
708 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
709 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
710 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
711 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
712 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
713 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
714 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
715 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
717 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
718 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
720 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
721 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
723 gtk_widget_set_sensitive(c->insert_btn, FALSE);
724 gtk_widget_set_sensitive(c->attach_btn, FALSE);
725 gtk_widget_set_sensitive(c->sig_btn, FALSE);
726 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
727 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
732 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
734 return compose_generic_new(account, mailto, NULL);
737 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
739 return compose_generic_new(account, NULL, item);
742 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
747 if (item && item->prefs && item->prefs->enable_default_account)
748 account = account_find_from_id(item->prefs->default_account);
750 if (!account) account = cur_account;
751 g_return_val_if_fail(account != NULL, NULL);
753 compose = compose_create(account, COMPOSE_NEW);
754 compose->replyinfo = NULL;
756 text = GTK_STEXT(compose->text);
757 gtk_stext_freeze(text);
759 if (prefs_common.auto_sig)
760 compose_insert_sig(compose);
761 gtk_editable_set_position(GTK_EDITABLE(text), 0);
762 gtk_stext_set_point(text, 0);
764 gtk_stext_thaw(text);
766 /* workaround for initial XIM problem */
767 gtk_widget_grab_focus(compose->text);
768 gtkut_widget_wait_for_draw(compose->text);
770 if (account->protocol != A_NNTP) {
772 compose_entries_set(compose, mailto);
774 } else if(item && item->prefs->enable_default_to) {
775 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
777 if (item && item->ret_rcpt) {
778 GtkItemFactory *ifactory;
780 ifactory = gtk_item_factory_from_widget(compose->menubar);
781 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
785 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
788 compose_show_first_last_header(compose, TRUE);
790 /* Set save folder */
791 if(item && item->prefs && item->prefs->save_copy_to_folder) {
792 gchar *folderidentifier;
794 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
795 folderidentifier = folder_item_get_identifier(item);
796 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
797 g_free(folderidentifier);
800 gtk_widget_grab_focus(compose->header_last->entry);
802 if (prefs_common.auto_exteditor)
803 compose_exec_ext_editor(compose);
808 #define CHANGE_FLAGS(msginfo) \
810 if (msginfo->folder->folder->change_flags != NULL) \
811 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
817 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
818 const gchar *followupto, gchar * to)
822 if (!account) account = cur_account;
823 g_return_val_if_fail(account != NULL, NULL);
824 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
826 compose = compose_create(account, COMPOSE_NEW);
828 if (prefs_common.auto_sig)
829 compose_insert_sig(compose);
830 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
831 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
833 compose_entry_append(compose, to, COMPOSE_TO);
834 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
835 gtk_widget_grab_focus(compose->subject_entry);
841 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
842 gboolean ignore_replyto, const gchar *body)
844 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE,
848 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
850 gboolean ignore_replyto,
853 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE,
857 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
859 gboolean ignore_replyto,
860 gboolean followup_and_reply_to,
864 PrefsAccount *account;
865 PrefsAccount *reply_account;
868 g_return_if_fail(msginfo != NULL);
869 g_return_if_fail(msginfo->folder != NULL);
872 /* select the account set in folderitem's property (if enabled) */
873 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
874 account = account_find_from_id(msginfo->folder->prefs->default_account);
876 /* select the account for the whole folder (IMAP / NNTP) */
878 /* FIXME: this is not right, because folder may be nested. we should
879 * ascend the tree until we find a parent with proper account
881 account = msginfo->folder->folder->account;
883 /* select account by to: and cc: header if enabled */
884 if (prefs_common.reply_account_autosel) {
885 if (!account && msginfo->to) {
887 Xstrdup_a(to, msginfo->to, return);
889 account = account_find_from_address(to);
893 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
895 account = account_find_from_address(cc);
900 /* select current account */
901 if (!account) account = cur_account;
902 g_return_if_fail(account != NULL);
904 if (ignore_replyto && account->protocol == A_NNTP &&
905 !followup_and_reply_to) {
907 account_find_from_address(account->address);
909 reply_account = compose_current_mail_account();
913 reply_account = account;
915 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
916 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
917 if (MSG_IS_IMAP(msginfo->flags))
918 imap_msg_set_perm_flags(msginfo, MSG_REPLIED);
919 CHANGE_FLAGS(msginfo);
921 compose = compose_create(account, COMPOSE_REPLY);
922 compose->replyinfo = procmsg_msginfo_copy(msginfo);
924 #if 0 /* NEW COMPOSE GUI */
925 if (followup_and_reply_to) {
926 gtk_widget_show(compose->to_hbox);
927 gtk_widget_show(compose->to_entry);
928 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
929 compose->use_to = TRUE;
932 if (msginfo->folder && msginfo->folder->ret_rcpt) {
933 GtkItemFactory *ifactory;
935 ifactory = gtk_item_factory_from_widget(compose->menubar);
936 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
939 /* Set save folder */
940 if(msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
941 gchar *folderidentifier;
943 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
944 folderidentifier = folder_item_get_identifier(msginfo->folder);
945 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
946 g_free(folderidentifier);
949 if (compose_parse_header(compose, msginfo) < 0) return;
950 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
951 followup_and_reply_to);
952 compose_show_first_last_header(compose, TRUE);
954 text = GTK_STEXT(compose->text);
955 gtk_stext_freeze(text);
961 if (prefs_common.quotemark && *prefs_common.quotemark)
962 qmark = prefs_common.quotemark;
966 quote_str = compose_quote_fmt(compose, msginfo,
967 prefs_common.quotefmt,
971 if (prefs_common.auto_sig)
972 compose_insert_sig(compose);
974 if (quote && prefs_common.linewrap_quote)
975 compose_wrap_line_all(compose);
977 gtk_editable_set_position(GTK_EDITABLE(text), 0);
978 gtk_stext_set_point(text, 0);
980 gtk_stext_thaw(text);
981 gtk_widget_grab_focus(compose->text);
983 if (prefs_common.auto_exteditor)
984 compose_exec_ext_editor(compose);
987 static void set_toolbar_style(Compose *compose);
989 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
994 g_return_val_if_fail(mimeinfo != NULL, NULL);
996 base = mimeinfo->filename ? mimeinfo->filename
997 : mimeinfo->name ? mimeinfo->name : NULL;
999 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
1000 filename = g_strdup_printf("%s%smimetmp.%08x.html",
1007 base = base ? base : "";
1008 base = g_basename(base);
1009 if (*base == '\0') {
1010 filename = g_strdup_printf("%s%smimetmp.%08x",
1018 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
1024 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
1028 if (!partinfo) return NULL;
1030 filename = procmime_get_file_name(partinfo);
1032 if (procmime_get_part(filename, source, partinfo) < 0)
1034 (_("Can't get the part of multipart message."));
1041 #define INSERT_FW_HEADER(var, hdr) \
1042 if (msginfo->var && *msginfo->var) { \
1043 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1044 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1045 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1048 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1049 gboolean as_attach, const gchar *body)
1052 /* PrefsAccount *account; */
1055 g_return_val_if_fail(msginfo != NULL, NULL);
1056 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1058 account = msginfo->folder->folder->account;
1059 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1061 Xstrdup_a(to, msginfo->to, return NULL);
1062 extract_address(to);
1063 account = account_find_from_address(to);
1066 if(!account && prefs_common.forward_account_autosel) {
1068 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1069 extract_address(cc);
1070 account = account_find_from_address(cc);
1074 if (account == NULL) {
1075 account = cur_account;
1077 account = msginfo->folder->folder->account;
1078 if (!account) account = cur_account;
1081 g_return_val_if_fail(account != NULL, NULL);
1083 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1084 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1085 if (MSG_IS_IMAP(msginfo->flags))
1086 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1087 CHANGE_FLAGS(msginfo);
1089 compose = compose_create(account, COMPOSE_FORWARD);
1091 if (msginfo->subject && *msginfo->subject) {
1092 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1093 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1097 text = GTK_STEXT(compose->text);
1098 gtk_stext_freeze(text);
1104 msgfile = procmsg_get_message_file_path(msginfo);
1105 if (!is_file_exist(msgfile))
1106 g_warning(_("%s: file not exist\n"), msgfile);
1108 compose_attach_append(compose, msgfile, msgfile,
1116 if (prefs_common.fw_quotemark &&
1117 *prefs_common.fw_quotemark)
1118 qmark = prefs_common.fw_quotemark;
1122 quote_str = compose_quote_fmt(compose, msginfo,
1123 prefs_common.fw_quotefmt,
1125 compose_attach_parts(compose, msginfo);
1128 if (prefs_common.auto_sig)
1129 compose_insert_sig(compose);
1131 if (prefs_common.linewrap_quote)
1132 compose_wrap_line_all(compose);
1134 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1135 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1137 gtk_stext_thaw(text);
1138 #if 0 /* NEW COMPOSE GUI */
1139 if (account->protocol != A_NNTP)
1140 gtk_widget_grab_focus(compose->to_entry);
1142 gtk_widget_grab_focus(compose->newsgroups_entry);
1144 gtk_widget_grab_focus(compose->header_last->entry);
1146 if (prefs_common.auto_exteditor)
1147 compose_exec_ext_editor(compose);
1152 #undef INSERT_FW_HEADER
1154 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1161 g_return_val_if_fail(msginfo_list != NULL, NULL);
1163 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1164 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1168 if (account == NULL) {
1169 account = cur_account;
1171 account = msginfo->folder->folder->account;
1172 if (!account) account = cur_account;
1175 g_return_val_if_fail(account != NULL, NULL);
1177 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1178 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1179 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1180 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1183 compose = compose_create(account, COMPOSE_FORWARD);
1185 text = GTK_STEXT(compose->text);
1186 gtk_stext_freeze(text);
1188 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1189 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1190 if (!is_file_exist(msgfile))
1191 g_warning(_("%s: file not exist\n"), msgfile);
1193 compose_attach_append(compose, msgfile, msgfile,
1198 if (prefs_common.auto_sig)
1199 compose_insert_sig(compose);
1201 if (prefs_common.linewrap_quote)
1202 compose_wrap_line_all(compose);
1204 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1205 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1207 gtk_stext_thaw(text);
1208 #if 0 /* NEW COMPOSE GUI */
1209 if (account->protocol != A_NNTP)
1210 gtk_widget_grab_focus(compose->to_entry);
1212 gtk_widget_grab_focus(compose->newsgroups_entry);
1218 void compose_reedit(MsgInfo *msginfo)
1221 PrefsAccount *account = NULL;
1224 gchar buf[BUFFSIZE];
1226 g_return_if_fail(msginfo != NULL);
1227 g_return_if_fail(msginfo->folder != NULL);
1229 if (msginfo->folder->stype == F_QUEUE) {
1230 gchar queueheader_buf[BUFFSIZE];
1233 /* Select Account from queue headers */
1234 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1235 sizeof(queueheader_buf), "NAID:")) {
1236 id = atoi(&queueheader_buf[5]);
1237 account = account_find_from_id(id);
1239 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1240 sizeof(queueheader_buf), "MAID:")) {
1241 id = atoi(&queueheader_buf[5]);
1242 account = account_find_from_id(id);
1244 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1245 sizeof(queueheader_buf), "S:")) {
1246 account = account_find_from_address(queueheader_buf);
1249 account = msginfo->folder->folder->account;
1251 if (!account && prefs_common.reedit_account_autosel) {
1252 gchar from[BUFFSIZE];
1253 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1254 extract_address(from);
1255 account = account_find_from_address(from);
1258 if (!account) account = cur_account;
1259 g_return_if_fail(account != NULL);
1261 compose = compose_create(account, COMPOSE_REEDIT);
1262 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1264 if (msginfo->folder->stype == F_QUEUE) {
1265 gchar queueheader_buf[BUFFSIZE];
1267 /* Set message save folder */
1268 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1271 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1272 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1273 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1277 if (compose_parse_header(compose, msginfo) < 0) return;
1278 compose_reedit_set_entry(compose, msginfo);
1280 text = GTK_STEXT(compose->text);
1281 gtk_stext_freeze(text);
1283 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1284 g_warning(_("Can't get text part\n"));
1286 while (fgets(buf, sizeof(buf), fp) != NULL)
1287 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1290 compose_attach_parts(compose, msginfo);
1292 gtk_stext_thaw(text);
1293 gtk_widget_grab_focus(compose->text);
1295 if (prefs_common.auto_exteditor)
1296 compose_exec_ext_editor(compose);
1299 GList *compose_get_compose_list(void)
1301 return compose_list;
1304 void compose_entry_append(Compose *compose, const gchar *address,
1305 ComposeEntryType type)
1311 if (!address || *address == '\0') return;
1313 #if 0 /* NEW COMPOSE GUI */
1316 entry = GTK_ENTRY(compose->cc_entry);
1319 entry = GTK_ENTRY(compose->bcc_entry);
1321 case COMPOSE_NEWSGROUPS:
1322 entry = GTK_ENTRY(compose->newsgroups_entry);
1326 entry = GTK_ENTRY(compose->to_entry);
1330 text = gtk_entry_get_text(entry);
1332 gtk_entry_append_text(entry, ", ");
1333 gtk_entry_append_text(entry, address);
1341 header = N_("Bcc:");
1343 case COMPOSE_REPLYTO:
1344 header = N_("Reply-To:");
1346 case COMPOSE_NEWSGROUPS:
1347 header = N_("Newsgroups:");
1349 case COMPOSE_FOLLOWUPTO:
1350 header = N_( "Followup-To:");
1357 header = prefs_common.trans_hdr ? gettext(header) : header;
1359 compose_add_header_entry(compose, header, (gchar *)address);
1362 static void compose_entries_set(Compose *compose, const gchar *mailto)
1364 gchar *subject = NULL;
1372 Xstrdup_a(tmp_mailto, mailto, return);
1376 p = strchr(tmp_mailto, '?');
1383 gchar *field, *value;
1400 if (*value == '\0') continue;
1402 if (!g_strcasecmp(field, "subject")) {
1403 Xalloca(subject, strlen(value) + 1, return);
1404 decode_uri(subject, value);
1405 } else if (!g_strcasecmp(field, "cc")) {
1407 } else if (!g_strcasecmp(field, "bcc")) {
1409 } else if (!g_strcasecmp(field, "body")) {
1410 Xalloca(body, strlen(value) + 1, return);
1411 decode_uri(body, value);
1416 compose_entry_append(compose, to, COMPOSE_TO);
1418 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1420 compose_entry_append(compose, cc, COMPOSE_CC);
1422 compose_entry_append(compose, bcc, COMPOSE_BCC);
1424 gtk_stext_insert(GTK_STEXT(compose->text),
1425 NULL, NULL, NULL, body, -1);
1426 gtk_stext_insert(GTK_STEXT(compose->text),
1427 NULL, NULL, NULL, "\n", 1);
1431 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1433 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1434 {"Cc:", NULL, FALSE},
1435 {"References:", NULL, FALSE},
1436 {"Bcc:", NULL, FALSE},
1437 {"Newsgroups:", NULL, FALSE},
1438 {"Followup-To:", NULL, FALSE},
1439 {"X-Mailing-List:", NULL, FALSE},
1440 {"X-BeenThere:", NULL, FALSE},
1441 {"X-Priority:", NULL, FALSE},
1442 {NULL, NULL, FALSE}};
1452 H_X_MAILING_LIST = 6,
1459 g_return_val_if_fail(msginfo != NULL, -1);
1461 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1462 procheader_get_header_fields(fp, hentry);
1465 if (hentry[H_REPLY_TO].body != NULL) {
1466 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1467 compose->replyto = hentry[H_REPLY_TO].body;
1468 hentry[H_REPLY_TO].body = NULL;
1470 if (hentry[H_CC].body != NULL) {
1471 conv_unmime_header_overwrite(hentry[H_CC].body);
1472 compose->cc = hentry[H_CC].body;
1473 hentry[H_CC].body = NULL;
1475 if (hentry[H_X_MAILING_LIST].body != NULL) {
1476 /* this is good enough to parse debian-devel */
1477 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1478 g_return_val_if_fail(buf != NULL, -1 );
1479 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1480 compose->mailinglist = g_strdup(buf);
1482 g_free(hentry[H_X_MAILING_LIST].body);
1483 hentry[H_X_MAILING_LIST].body = NULL ;
1485 if (hentry[H_X_BEENTHERE].body != NULL) {
1486 /* this is good enough to parse the sylpheed-claws lists */
1487 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1488 g_return_val_if_fail(buf != NULL, -1 );
1489 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1490 compose->mailinglist = g_strdup(buf);
1492 g_free(hentry[H_X_BEENTHERE].body);
1493 hentry[H_X_BEENTHERE].body = NULL ;
1495 if (hentry[H_REFERENCES].body != NULL) {
1496 if (compose->mode == COMPOSE_REEDIT)
1497 compose->references = hentry[H_REFERENCES].body;
1499 compose->references = compose_parse_references
1500 (hentry[H_REFERENCES].body, msginfo->msgid);
1501 g_free(hentry[H_REFERENCES].body);
1503 hentry[H_REFERENCES].body = NULL;
1505 if (hentry[H_BCC].body != NULL) {
1506 if (compose->mode == COMPOSE_REEDIT) {
1507 conv_unmime_header_overwrite(hentry[H_BCC].body);
1508 compose->bcc = hentry[H_BCC].body;
1510 g_free(hentry[H_BCC].body);
1511 hentry[H_BCC].body = NULL;
1513 if (hentry[H_NEWSGROUPS].body != NULL) {
1514 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1515 hentry[H_NEWSGROUPS].body = NULL;
1517 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1518 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1519 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1520 hentry[H_FOLLOWUP_TO].body = NULL;
1523 if (compose->mode == COMPOSE_REEDIT)
1524 if (hentry[H_X_PRIORITY].body != NULL) {
1527 priority = atoi(hentry[H_X_PRIORITY].body);
1528 g_free(hentry[H_X_PRIORITY].body);
1530 hentry[H_X_PRIORITY].body = NULL;
1532 if (priority < PRIORITY_HIGHEST ||
1533 priority > PRIORITY_LOWEST)
1534 priority = PRIORITY_NORMAL;
1536 compose->priority = priority;
1539 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1540 compose->inreplyto = g_strdup(msginfo->inreplyto);
1541 else if (compose->mode != COMPOSE_REEDIT &&
1542 msginfo->msgid && *msginfo->msgid) {
1543 compose->inreplyto = g_strdup(msginfo->msgid);
1545 if (!compose->references) {
1546 if (msginfo->inreplyto && *msginfo->inreplyto)
1547 compose->references =
1548 g_strdup_printf("<%s>\n\t<%s>",
1552 compose->references =
1553 g_strconcat("<", msginfo->msgid, ">",
1561 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1563 GSList *ref_id_list, *cur;
1567 ref_id_list = references_list_append(NULL, ref);
1568 if (!ref_id_list) return NULL;
1569 if (msgid && *msgid)
1570 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1575 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1576 /* "<" + Message-ID + ">" + CR+LF+TAB */
1577 len += strlen((gchar *)cur->data) + 5;
1579 if (len > MAX_REFERENCES_LEN) {
1580 /* remove second message-ID */
1581 if (ref_id_list && ref_id_list->next &&
1582 ref_id_list->next->next) {
1583 g_free(ref_id_list->next->data);
1584 ref_id_list = g_slist_remove
1585 (ref_id_list, ref_id_list->next->data);
1587 slist_free_strings(ref_id_list);
1588 g_slist_free(ref_id_list);
1595 new_ref = g_string_new("");
1596 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1597 if (new_ref->len > 0)
1598 g_string_append(new_ref, "\n\t");
1599 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1602 slist_free_strings(ref_id_list);
1603 g_slist_free(ref_id_list);
1605 new_ref_str = new_ref->str;
1606 g_string_free(new_ref, FALSE);
1611 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1612 const gchar *fmt, const gchar *qmark,
1615 GtkSText *text = GTK_STEXT(compose->text);
1616 static MsgInfo dummyinfo;
1617 gchar *quote_str = NULL;
1623 msginfo = &dummyinfo;
1625 if (qmark != NULL) {
1626 quote_fmt_init(msginfo, NULL, NULL);
1627 quote_fmt_scan_string(qmark);
1630 buf = quote_fmt_get_buffer();
1632 alertpanel_error(_("Quote mark format error."));
1634 Xstrdup_a(quote_str, buf, return NULL)
1637 if (fmt && *fmt != '\0') {
1638 quote_fmt_init(msginfo, quote_str, body);
1639 quote_fmt_scan_string(fmt);
1642 buf = quote_fmt_get_buffer();
1644 alertpanel_error(_("Message reply/forward format error."));
1650 gtk_stext_freeze(text);
1652 for (p = buf; *p != '\0'; ) {
1653 lastp = strchr(p, '\n');
1654 len = lastp ? lastp - p + 1 : -1;
1655 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1662 gtk_stext_thaw(text);
1667 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1668 gboolean to_all, gboolean ignore_replyto,
1669 gboolean followup_and_reply_to)
1671 GSList *cc_list = NULL;
1674 gchar *replyto = NULL;
1675 GHashTable *to_table;
1677 g_return_if_fail(compose->account != NULL);
1678 g_return_if_fail(msginfo != NULL);
1680 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1681 compose_entry_append(compose,
1682 ((compose->replyto && !ignore_replyto)
1684 : (compose->mailinglist && !ignore_replyto)
1685 ? compose->mailinglist
1686 : msginfo->from ? msginfo->from : ""),
1689 if (compose->account->protocol == A_NNTP) {
1691 compose_entry_append
1692 (compose, msginfo->from ? msginfo->from : "",
1695 compose_entry_append
1697 compose->followup_to ? compose->followup_to
1698 : compose->newsgroups ? compose->newsgroups
1700 COMPOSE_NEWSGROUPS);
1703 if (msginfo->subject && *msginfo->subject) {
1704 gchar *buf, *buf2, *p;
1706 buf = g_strdup(msginfo->subject);
1707 while (!strncasecmp(buf, "Re:", 3)) {
1709 while (isspace(*p)) p++;
1710 memmove(buf, p, strlen(p) + 1);
1713 buf2 = g_strdup_printf("Re: %s", buf);
1714 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1718 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1720 if (!to_all || compose->account->protocol == A_NNTP) return;
1722 if (compose->replyto) {
1723 Xstrdup_a(replyto, compose->replyto, return);
1724 extract_address(replyto);
1726 if (msginfo->from) {
1727 Xstrdup_a(from, msginfo->from, return);
1728 extract_address(from);
1731 if (compose->mailinglist && from) {
1732 cc_list = address_list_append(cc_list, from);
1735 if (replyto && from)
1736 cc_list = address_list_append(cc_list, from);
1738 if (!compose->mailinglist)
1739 cc_list = address_list_append(cc_list, msginfo->to);
1741 cc_list = address_list_append(cc_list, compose->cc);
1743 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1745 g_hash_table_insert(to_table, replyto, GINT_TO_POINTER(1));
1746 if (compose->account)
1747 g_hash_table_insert(to_table, compose->account->address,
1748 GINT_TO_POINTER(1));
1750 /* remove address on To: and that of current account */
1751 for (cur = cc_list; cur != NULL; ) {
1752 GSList *next = cur->next;
1754 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1755 cc_list = g_slist_remove(cc_list, cur->data);
1757 g_hash_table_insert(to_table, cur->data, cur);
1761 g_hash_table_destroy(to_table);
1764 for (cur = cc_list; cur != NULL; cur = cur->next)
1765 compose_entry_append(compose, (gchar *)cur->data,
1767 slist_free_strings(cc_list);
1768 g_slist_free(cc_list);
1772 #define SET_ENTRY(entry, str) \
1775 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1778 #define SET_ADDRESS(type, str) \
1781 compose_entry_append(compose, str, type); \
1784 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1786 g_return_if_fail(msginfo != NULL);
1788 SET_ENTRY(subject_entry, msginfo->subject);
1789 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1790 SET_ADDRESS(COMPOSE_CC, compose->cc);
1791 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1792 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1794 compose_update_priority_menu_item(compose);
1796 compose_show_first_last_header(compose, TRUE);
1798 #if 0 /* NEW COMPOSE GUI */
1800 GtkItemFactory *ifactory;
1801 GtkWidget *menuitem;
1803 ifactory = gtk_item_factory_from_widget(compose->menubar);
1804 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1805 gtk_check_menu_item_set_active
1806 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1808 if (compose->replyto) {
1809 GtkItemFactory *ifactory;
1810 GtkWidget *menuitem;
1812 ifactory = gtk_item_factory_from_widget(compose->menubar);
1813 menuitem = gtk_item_factory_get_item
1814 (ifactory, "/View/Reply to");
1815 gtk_check_menu_item_set_active
1816 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1824 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1831 size_t buf_len = 128;
1833 if (strlen(sigfile) < 2)
1836 sigprg = popen(sigfile+1, "r");
1839 buf = g_malloc(buf_len);
1842 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1843 "Unable to insert signature (malloc failed)\n", -1);
1849 while (!feof(sigprg)) {
1850 bzero(buf, buf_len);
1851 fread(buf, buf_len-1, 1, sigprg);
1852 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1860 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1861 "Can't exec file: ", -1);
1862 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1867 static void compose_insert_sig(Compose *compose)
1871 if (compose->account && compose->account->sig_path)
1872 sigfile = g_strdup(compose->account->sig_path);
1874 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1875 DEFAULT_SIGNATURE, NULL);
1877 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1882 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1883 if (prefs_common.sig_sep) {
1884 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1885 prefs_common.sig_sep, -1);
1886 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1890 if (sigfile[0] == '|')
1891 compose_exec_sig(compose, sigfile);
1893 compose_insert_file(compose, sigfile);
1897 static void compose_insert_file(Compose *compose, const gchar *file)
1899 GtkSText *text = GTK_STEXT(compose->text);
1900 gchar buf[BUFFSIZE];
1904 g_return_if_fail(file != NULL);
1906 if ((fp = fopen(file, "rb")) == NULL) {
1907 FILE_OP_ERROR(file, "fopen");
1911 gtk_stext_freeze(text);
1913 while (fgets(buf, sizeof(buf), fp) != NULL) {
1914 /* strip <CR> if DOS/Windows file,
1915 replace <CR> with <LF> if Macintosh file. */
1918 if (len > 0 && buf[len - 1] != '\n') {
1920 if (buf[len] == '\r') buf[len] = '\n';
1922 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1925 gtk_stext_thaw(text);
1930 static void compose_attach_append(Compose *compose, const gchar *file,
1931 const gchar *filename,
1932 const gchar *content_type)
1935 gchar *text[N_ATTACH_COLS];
1940 if (!is_file_exist(file)) {
1941 g_warning(_("File %s doesn't exist\n"), file);
1944 if ((size = get_file_size(file)) < 0) {
1945 g_warning(_("Can't get file size of %s\n"), file);
1949 alertpanel_notice(_("File %s is empty."), file);
1952 if ((fp = fopen(file, "rb")) == NULL) {
1953 alertpanel_error(_("Can't read %s."), file);
1958 #if 0 /* NEW COMPOSE GUI */
1959 if (!compose->use_attach) {
1960 GtkItemFactory *ifactory;
1961 GtkWidget *menuitem;
1963 ifactory = gtk_item_factory_from_widget(compose->menubar);
1964 menuitem = gtk_item_factory_get_item(ifactory,
1965 "/View/Attachment");
1966 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1970 ainfo = g_new0(AttachInfo, 1);
1971 ainfo->file = g_strdup(file);
1974 ainfo->content_type = g_strdup(content_type);
1975 if (!strcasecmp(content_type, "message/rfc822")) {
1976 ainfo->encoding = ENC_7BIT;
1977 ainfo->name = g_strdup_printf
1979 g_basename(filename ? filename : file));
1981 if (!g_strncasecmp(content_type, "text", 4))
1983 procmime_get_encoding_for_file(file);
1985 ainfo->encoding = ENC_BASE64;
1986 ainfo->name = g_strdup
1987 (g_basename(filename ? filename : file));
1990 ainfo->content_type = procmime_get_mime_type(file);
1991 if (!ainfo->content_type) {
1992 ainfo->content_type =
1993 g_strdup("application/octet-stream");
1994 ainfo->encoding = ENC_BASE64;
1995 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
1996 ainfo->encoding = procmime_get_encoding_for_file(file);
1998 ainfo->encoding = ENC_BASE64;
1999 ainfo->name = g_strdup(g_basename(filename ? filename : file));
2003 text[COL_MIMETYPE] = ainfo->content_type;
2004 text[COL_SIZE] = to_human_readable(size);
2005 text[COL_NAME] = ainfo->name;
2007 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2008 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2011 #define IS_FIRST_PART_TEXT(info) \
2012 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
2013 info->mime_type == MIME_TEXT_ENRICHED) || \
2014 (info->mime_type == MIME_MULTIPART && info->content_type && \
2015 !strcasecmp(info->content_type, "multipart/alternative") && \
2016 (info->children && \
2017 (info->children->mime_type == MIME_TEXT || \
2018 info->children->mime_type == MIME_TEXT_HTML || \
2019 info->children->mime_type == MIME_TEXT_ENRICHED))))
2021 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2028 mimeinfo = procmime_scan_message(msginfo);
2029 if (!mimeinfo) return;
2031 /* skip first text (presumably message body) */
2032 child = mimeinfo->children;
2033 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
2034 procmime_mimeinfo_free_all(mimeinfo);
2037 if (IS_FIRST_PART_TEXT(child))
2038 child = child->next;
2040 infile = procmsg_get_message_file_path(msginfo);
2042 while (child != NULL) {
2043 if (child->children || child->mime_type == MIME_MULTIPART) {
2044 child = procmime_mimeinfo_next(child);
2048 outfile = procmime_get_tmp_file_name(child);
2049 if (procmime_get_part(outfile, infile, child) < 0)
2050 g_warning(_("Can't get the part of multipart message."));
2052 compose_attach_append
2054 child->filename ? child->filename : child->name,
2055 child->content_type);
2057 child = child->next;
2061 procmime_mimeinfo_free_all(mimeinfo);
2064 #undef IS_FIRST_PART_TEXT
2066 #define GET_CHAR(pos, buf, len) \
2068 if (text->use_wchar) \
2069 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2071 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2076 #define INDENT_CHARS ">|#"
2077 #define SPACE_CHARS " \t"
2079 static void compose_wrap_line(Compose *compose)
2081 GtkSText *text = GTK_STEXT(compose->text);
2082 gint ch_len, last_ch_len;
2083 gchar cbuf[MB_LEN_MAX], last_ch;
2087 gint p_start, p_end;
2088 gint line_pos, cur_pos;
2089 gint line_len, cur_len;
2091 gtk_stext_freeze(text);
2093 text_len = gtk_stext_get_length(text);
2095 /* check to see if the point is on the paragraph mark (empty line). */
2096 cur_pos = gtk_stext_get_point(text);
2097 GET_CHAR(cur_pos, cbuf, ch_len);
2098 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2100 goto compose_end; /* on the paragraph mark */
2101 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2102 if (ch_len == 1 && *cbuf == '\n')
2103 goto compose_end; /* on the paragraph mark */
2106 /* find paragraph start. */
2107 line_end = quoted = 0;
2108 for (p_start = cur_pos; p_start >= 0; --p_start) {
2109 GET_CHAR(p_start, cbuf, ch_len);
2110 if (ch_len == 1 && *cbuf == '\n') {
2112 goto compose_end; /* quoted part */
2120 && strchr(prefs_common.quote_chars, *cbuf))
2122 else if (ch_len != 1 || !isspace(*cbuf))
2131 /* find paragraph end. */
2133 for (p_end = cur_pos; p_end < text_len; p_end++) {
2134 GET_CHAR(p_end, cbuf, ch_len);
2135 if (ch_len == 1 && *cbuf == '\n') {
2142 if (line_end && ch_len == 1 &&
2143 strchr(prefs_common.quote_chars, *cbuf))
2144 goto compose_end; /* quoted part */
2149 if (p_end >= text_len)
2152 if (p_start >= p_end)
2155 line_len = cur_len = 0;
2159 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2162 GET_CHAR(cur_pos, cbuf, ch_len);
2169 if (ch_len == 1 && isspace(*cbuf))
2172 if (ch_len == 1 && *cbuf == '\n') {
2174 if (last_ch_len == 1 && !isspace(last_ch)) {
2175 if (cur_pos + 1 < p_end) {
2176 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2177 if (ch_len == 1 && !isspace(*cbuf))
2181 gtk_stext_set_point(text, cur_pos + 1);
2182 gtk_stext_backward_delete(text, 1);
2184 gtk_stext_set_point(text, cur_pos);
2185 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2195 last_ch_len = ch_len;
2199 line_pos = cur_pos + 1;
2200 line_len = cur_len + ch_len;
2203 if (cur_len + ch_len > prefs_common.linewrap_len &&
2207 GET_CHAR(line_pos - 1, cbuf, ch_len);
2208 if (ch_len == 1 && isspace(*cbuf)) {
2209 gtk_stext_set_point(text, line_pos);
2210 gtk_stext_backward_delete(text, 1);
2219 gtk_stext_set_point(text, line_pos);
2220 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2224 cur_len = cur_len - line_len + ch_len;
2230 line_pos = cur_pos + 1;
2231 line_len = cur_len + ch_len;
2237 gtk_stext_thaw(text);
2242 /* Darko: used when I debug wrapping */
2243 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2248 printf("%d [", pos);
2249 for (i = pos; i < tlen; i++) {
2250 ch = GTK_STEXT_INDEX(text, i);
2251 if (breakoncr && ch == '\n')
2261 WAIT_FOR_INDENT_CHAR,
2262 WAIT_FOR_INDENT_CHAR_OR_SPACE
2265 /* return indent length, we allow:
2266 > followed by spaces/tabs
2267 | followed by spaces/tabs
2268 uppercase characters immediately followed by >,
2269 and the repeating sequences of the above */
2270 /* return indent length */
2271 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2274 guint i, ch_len, alnum_cnt = 0;
2275 IndentState state = WAIT_FOR_INDENT_CHAR;
2276 gchar cbuf[MB_LEN_MAX];
2280 for (i = start_pos; i < text_len; i++) {
2281 GET_CHAR(i, cbuf, ch_len);
2285 if (cbuf[0] == '\n')
2288 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2289 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2292 case WAIT_FOR_SPACE:
2293 if (is_space == FALSE)
2295 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2297 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2298 if (is_indent == FALSE && is_space == FALSE &&
2301 if (is_space == TRUE) {
2303 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2304 } else if (is_indent == TRUE) {
2306 state = WAIT_FOR_SPACE;
2309 state = WAIT_FOR_INDENT_CHAR;
2312 case WAIT_FOR_INDENT_CHAR:
2313 if (is_indent == FALSE && !isupper(cbuf[0]))
2315 if (is_indent == TRUE) {
2317 && !strchr(prefs_common.quote_chars, cbuf[0]))
2320 state = WAIT_FOR_SPACE;
2331 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2337 /* insert quotation string when line was wrapped */
2338 static guint ins_quote(GtkSText *text, guint indent_len,
2339 guint prev_line_pos, guint text_len,
2346 for (i = 0; i < indent_len; i++) {
2347 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2348 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2350 ins_len = indent_len;
2356 /* check if we should join the next line */
2357 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2360 guint indent_len, ch_len;
2361 gboolean do_join = FALSE;
2362 gchar cbuf[MB_LEN_MAX];
2364 indent_len = get_indent_length(text, start_pos, tlen);
2366 if ((indent_len > 0) && (indent_len == prev_ilen)) {
2367 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2368 if (ch_len > 0 && (cbuf[0] != '\n'))
2375 static void compose_wrap_line_all(Compose *compose)
2377 GtkSText *text = GTK_STEXT(compose->text);
2379 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2380 gint line_len = 0, cur_len = 0;
2382 gboolean is_new_line = TRUE, do_delete = FALSE;
2384 gboolean linewrap_quote = TRUE;
2385 guint linewrap_len = prefs_common.linewrap_len;
2386 gchar *qfmt = prefs_common.quotemark;
2387 gchar cbuf[MB_LEN_MAX];
2389 gtk_stext_freeze(text);
2391 /* make text buffer contiguous */
2392 /* gtk_stext_compact_buffer(text); */
2394 tlen = gtk_stext_get_length(text);
2396 for (; cur_pos < tlen; cur_pos++) {
2397 /* mark position of new line - needed for quotation wrap */
2400 i_len = get_indent_length(text, cur_pos, tlen);
2402 is_new_line = FALSE;
2405 printf("new line i_len=%d p_pos=", i_len);
2406 dump_text(text, p_pos, tlen, 1);
2410 GET_CHAR(cur_pos, cbuf, ch_len);
2412 /* fix line length for tabs */
2413 if (ch_len == 1 && *cbuf == '\t') {
2414 guint tab_width = text->default_tab_width;
2415 guint tab_offset = line_len % tab_width;
2418 printf("found tab at pos=%d line_len=%d ", cur_pos,
2422 line_len += tab_width - tab_offset - 1;
2426 printf("new_len=%d\n", line_len);
2430 /* we have encountered line break */
2431 if (ch_len == 1 && *cbuf == '\n') {
2433 gchar cb[MB_CUR_MAX];
2435 /* should we join the next line */
2436 if ((i_len != cur_len) && do_delete &&
2437 join_next_line(text, cur_pos + 1, tlen, i_len))
2443 printf("found CR at %d do_del is %d next line is ",
2444 cur_pos, do_delete);
2445 dump_text(text, cur_pos + 1, tlen, 1);
2448 /* skip delete if it is continuous URL */
2449 if (do_delete && (line_pos - p_pos <= i_len) &&
2450 gtkut_stext_is_uri_string(text, line_pos, tlen))
2454 printf("l_len=%d wrap_len=%d do_del=%d\n",
2455 line_len, linewrap_len, do_delete);
2457 /* should we delete to perform smart wrapping */
2458 if (line_len < linewrap_len && do_delete) {
2459 /* get rid of newline */
2460 gtk_stext_set_point(text, cur_pos);
2461 gtk_stext_forward_delete(text, 1);
2464 /* if text starts with quote fmt or with
2465 indent string, delete them */
2468 ilen = gtkut_stext_str_compare_n
2469 (text, cur_pos, p_pos, i_len,
2472 gtk_stext_forward_delete
2478 GET_CHAR(cur_pos, cb, clen);
2480 /* insert space if it's alphanumeric */
2481 if ((cur_pos != line_pos) &&
2482 ((clen > 1) || isalnum(cb[0]))) {
2483 gtk_stext_insert(text, NULL, NULL,
2485 /* gtk_stext_compact_buffer(text); */
2489 /* and start over with current line */
2490 cur_pos = p_pos - 1;
2492 line_len = cur_len = 0;
2496 printf("after delete l_pos=");
2497 dump_text(text, line_pos, tlen, 1);
2502 /* mark new line beginning */
2503 line_pos = cur_pos + 1;
2504 line_len = cur_len = 0;
2515 /* possible line break */
2516 if (ch_len == 1 && isspace(*cbuf)) {
2517 line_pos = cur_pos + 1;
2518 line_len = cur_len + ch_len;
2521 /* are we over wrapping length set in preferences ? */
2522 if (cur_len + ch_len > linewrap_len) {
2526 printf("should wrap cur_pos=%d ", cur_pos);
2527 dump_text(text, p_pos, tlen, 1);
2528 dump_text(text, line_pos, tlen, 1);
2530 /* force wrapping if it is one long word but not URL */
2531 if (line_pos - p_pos <= i_len)
2532 if (!gtkut_stext_is_uri_string
2533 (text, line_pos, tlen))
2534 line_pos = cur_pos - 1;
2536 printf("new line_pos=%d\n", line_pos);
2539 GET_CHAR(line_pos - 1, cbuf, clen);
2541 /* if next character is space delete it */
2542 if (clen == 1 && isspace(*cbuf)) {
2543 if (p_pos + i_len != line_pos ||
2544 !gtkut_stext_is_uri_string
2545 (text, line_pos, tlen)) {
2546 gtk_stext_set_point(text, line_pos);
2547 gtk_stext_backward_delete(text, 1);
2556 /* if it is URL at beginning of line don't wrap */
2557 if (p_pos + i_len == line_pos &&
2558 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2560 printf("found URL at ");
2561 dump_text(text, line_pos, tlen, 1);
2567 gtk_stext_set_point(text, line_pos);
2568 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2569 /* gtk_stext_compact_buffer(text); */
2572 /* for loop will increase it */
2573 cur_pos = line_pos - 1;
2574 /* start over with current line */
2583 printf("after CR insert ");
2584 dump_text(text, line_pos, tlen, 1);
2585 dump_text(text, cur_pos, tlen, 1);
2588 /* should we insert quotation ? */
2589 if (linewrap_quote && i_len) {
2590 /* only if line is not already quoted */
2591 if (!gtkut_stext_str_compare
2592 (text, line_pos, tlen, qfmt)) {
2595 if (line_pos - p_pos > i_len) {
2597 (text, i_len, p_pos,
2600 /* gtk_stext_compact_buffer(text); */
2604 printf("after quote insert ");
2605 dump_text(text, line_pos, tlen, 1);
2613 line_pos = cur_pos + 1;
2614 line_len = cur_len + ch_len;
2616 /* advance to next character in buffer */
2620 gtk_stext_thaw(text);
2625 static void compose_set_title(Compose *compose)
2630 edited = compose->modified ? _(" [Edited]") : "";
2631 if (compose->account && compose->account->address)
2632 str = g_strdup_printf(_("%s - Compose message%s"),
2633 compose->account->address, edited);
2635 str = g_strdup_printf(_("Compose message%s"), edited);
2636 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2641 * compose_current_mail_account:
2643 * Find a current mail account (the currently selected account, or the
2644 * default account, if a news account is currently selected). If a
2645 * mail account cannot be found, display an error message.
2647 * Return value: Mail account, or NULL if not found.
2649 static PrefsAccount *
2650 compose_current_mail_account(void)
2654 if (cur_account && cur_account->protocol != A_NNTP)
2657 ac = account_get_default();
2658 if (!ac || ac->protocol == A_NNTP) {
2659 alertpanel_error(_("Account for sending mail is not specified.\n"
2660 "Please select a mail account before sending."));
2667 gboolean compose_check_for_valid_recipient(Compose *compose) {
2668 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2669 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2670 gboolean recipient_found = FALSE;
2674 /* free to and newsgroup list */
2675 slist_free_strings(compose->to_list);
2676 g_slist_free(compose->to_list);
2677 compose->to_list = NULL;
2679 slist_free_strings(compose->newsgroup_list);
2680 g_slist_free(compose->newsgroup_list);
2681 compose->newsgroup_list = NULL;
2683 /* search header entries for to and newsgroup entries */
2684 for(list = compose->header_list; list; list = list->next) {
2687 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2688 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2690 if(entry[0] != '\0') {
2691 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2692 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2693 compose->to_list = address_list_append(compose->to_list, entry);
2694 recipient_found = TRUE;
2697 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2698 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2699 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2700 recipient_found = TRUE;
2706 return recipient_found;
2709 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
2713 if (compose_check_for_valid_recipient(compose) == FALSE) {
2714 alertpanel_error(_("Recipient is not specified."));
2718 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2719 if (*str == '\0' && check_subject == TRUE) {
2722 aval = alertpanel(_("Send"),
2723 _("Subject is empty. Send it anyway?"),
2724 _("Yes"), _("No"), NULL);
2725 if (aval != G_ALERTDEFAULT)
2732 gint compose_send(Compose *compose)
2738 if (compose_check_entries(compose, TRUE) == FALSE)
2741 val = compose_queue(compose, &msgnum, &folder);
2743 alertpanel_error(_("Could not queue message for sending"));
2747 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2749 folder_item_remove_msg(folder, msgnum);
2750 folderview_update_item(folder, TRUE);
2755 #if 0 /* compose restructure */
2756 gint compose_send(Compose *compose)
2758 gchar tmp[MAXPATHLEN + 1];
2760 static gboolean lock = FALSE;
2764 g_return_val_if_fail(compose->account != NULL, -1);
2765 g_return_val_if_fail(compose->orig_account != NULL, -1);
2769 if (compose_check_entries(compose, TRUE) == FALSE) {
2774 /* write to temporary file */
2775 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2776 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2778 if (prefs_common.linewrap_at_send)
2779 compose_wrap_line_all(compose);
2781 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2786 if (!compose->to_list && !compose->newsgroup_list) {
2787 g_warning(_("can't get recipient list."));
2793 if (compose->to_list) {
2796 #if 0 /* NEW COMPOSE GUI */
2797 if (compose->account->protocol != A_NNTP)
2798 ac = compose->account;
2799 else if (compose->orig_account->protocol != A_NNTP)
2800 ac = compose->orig_account;
2801 else if (cur_account && cur_account->protocol != A_NNTP)
2804 ac = compose_current_mail_account();
2812 ac = compose->account;
2814 ok = send_message(tmp, ac, compose->to_list);
2815 statusbar_pop_all();
2818 if (ok == 0 && compose->newsgroup_list) {
2821 if (compose->account->protocol == A_NNTP)
2822 folder = FOLDER(compose->account->folder);
2824 folder = FOLDER(compose->orig_account->folder);
2826 ok = news_post(folder, tmp);
2828 alertpanel_error(_("Error occurred while posting the message to %s ."),
2829 compose->account->nntp_server);
2836 /* queue message if failed to send */
2838 if (prefs_common.queue_msg) {
2843 _("Error occurred while sending the message.\n"
2844 "Put this message into queue folder?"),
2845 _("OK"), _("Cancel"), NULL);
2846 if (G_ALERTDEFAULT == val) {
2847 ok = compose_queue(compose, tmp);
2849 alertpanel_error(_("Can't queue the message."));
2852 alertpanel_error(_("Error occurred while sending the message."));
2854 if (compose->mode == COMPOSE_REEDIT) {
2855 compose_remove_reedit_target(compose);
2856 if (compose->targetinfo)
2857 folderview_update_item
2858 (compose->targetinfo->folder, TRUE);
2860 /* save message to outbox */
2861 if (prefs_common.savemsg) {
2864 outbox = account_get_special_folder
2865 (compose->account, F_OUTBOX);
2866 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
2868 (_("Can't save the message to Sent."));
2870 folderview_update_item(outbox, TRUE);
2880 static gboolean compose_use_attach(Compose *compose) {
2881 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2884 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
2887 gchar buf[BUFFSIZE];
2889 gboolean first_address;
2891 ComposeHeaderEntry *headerentry;
2892 gchar *headerentryname;
2896 debug_print(_("Writing redirect header\n"));
2898 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
2899 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
2901 first_address = TRUE;
2902 for(list = compose->header_list; list; list = list->next) {
2903 headerentry = ((ComposeHeaderEntry *)list->data);
2904 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2906 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2907 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2908 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2909 Xstrdup_a(str, str, return -1);
2911 if(str[0] != '\0') {
2912 compose_convert_header
2913 (buf, sizeof(buf), str,
2914 strlen("Resent-To") + 2);
2916 fprintf(fp, "Resent-To: ");
2917 first_address = FALSE;
2921 fprintf(fp, "%s", buf);
2925 /* if(!first_address) { */
2932 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
2934 gchar buf[BUFFSIZE];
2936 /* struct utsname utsbuf; */
2938 g_return_val_if_fail(fp != NULL, -1);
2939 g_return_val_if_fail(compose->account != NULL, -1);
2940 g_return_val_if_fail(compose->account->address != NULL, -1);
2943 get_rfc822_date(buf, sizeof(buf));
2944 fprintf(fp, "Resent-Date: %s\n", buf);
2947 if (compose->account->name && *compose->account->name) {
2948 compose_convert_header
2949 (buf, sizeof(buf), compose->account->name,
2951 fprintf(fp, "Resent-From: %s <%s>\n",
2952 buf, compose->account->address);
2954 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2957 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2959 Xstrdup_a(str, str, return -1);
2962 compose_convert_header(buf, sizeof(buf), str,
2963 strlen("Subject: "));
2964 fprintf(fp, "Subject: %s\n", buf);
2968 /* Resent-Message-ID */
2969 if (compose->account->gen_msgid) {
2970 compose_generate_msgid(compose, buf, sizeof(buf));
2971 fprintf(fp, "Resent-Message-Id: <%s>\n", buf);
2972 compose->msgid = g_strdup(buf);
2975 compose_redirect_write_headers_from_headerlist(compose, fp);
2977 /* separator between header and body */
2983 static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
2988 gchar buf[BUFFSIZE];
2990 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
2991 FILE_OP_ERROR(file, "fopen");
2995 if ((fdest = fopen(file, "wb")) == NULL) {
2996 FILE_OP_ERROR(file, "fopen");
3001 /* chmod for security */
3002 if (change_file_mode_rw(fdest, file) < 0) {
3003 FILE_OP_ERROR(file, "chmod");
3004 g_warning(_("can't change file mode\n"));
3007 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
3008 /* should filter returnpath, delivered-to */
3009 if (g_strncasecmp(buf, "Return-Path:",
3010 strlen("Return-Path:")) == 0 ||
3011 g_strncasecmp(buf, "Delivered-To:",
3012 strlen("Delivered-To:")) == 0 ||
3013 g_strncasecmp(buf, "Received:",
3014 strlen("Received:")) == 0 ||
3015 g_strncasecmp(buf, "Subject:",
3016 strlen("Subject:")) == 0 ||
3017 g_strncasecmp(buf, "X-UIDL:",
3018 strlen("X-UIDL:")) == 0)
3021 if (fputs(buf, fdest) == -1)
3024 if (!prefs_common.redirect_keep_from) {
3025 if (g_strncasecmp(buf, "From:",
3026 strlen("From:")) == 0) {
3027 fputs(" (by way of ", fdest);
3028 if (compose->account->name
3029 && *compose->account->name) {
3030 compose_convert_header
3032 compose->account->name,
3034 fprintf(fdest, "%s <%s>",
3036 compose->account->address);
3038 fprintf(fdest, "%s",
3039 compose->account->address);
3044 if (fputs("\n", fdest) == -1)
3048 compose_redirect_write_headers(compose, fdest);
3050 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3051 if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
3052 FILE_OP_ERROR(file, "fwrite");
3058 if (fclose(fdest) == EOF) {
3059 FILE_OP_ERROR(file, "fclose");
3076 * interfaces to rfc2015 to keep out the prefs stuff there.
3077 * returns 0 on success and -1 on error. */
3078 static int compose_create_signers_list (Compose *compose, GSList **pkey_list)
3080 const char *keyid = NULL;
3083 switch (compose->account->sign_key) {
3084 case SIGN_KEY_DEFAULT:
3086 return 0; /* nothing to do */
3088 case SIGN_KEY_BY_FROM:
3089 keyid = compose->account->address;
3092 case SIGN_KEY_CUSTOM:
3093 keyid = compose->account->sign_key_id;
3097 g_assert_not_reached ();
3100 key_list = rfc2015_create_signers_list(keyid);
3103 alertpanel_error("Could not find any key associated with currently "
3104 "selected keyid `%s'!", keyid);
3108 *pkey_list = key_list;
3111 #endif /* USE_GPGME */
3113 static gint compose_write_to_file(Compose *compose, const gchar *file,
3120 const gchar *out_codeset;
3121 EncodingType encoding;
3123 if ((fp = fopen(file, "wb")) == NULL) {
3124 FILE_OP_ERROR(file, "fopen");
3128 /* chmod for security */
3129 if (change_file_mode_rw(fp, file) < 0) {
3130 FILE_OP_ERROR(file, "chmod");
3131 g_warning(_("can't change file mode\n"));
3134 /* get all composed text */
3135 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3136 len = strlen(chars);
3137 if (is_ascii_str(chars)) {
3138 buf = g_strdup(chars);
3139 out_codeset = CS_US_ASCII;
3140 encoding = ENC_7BIT;
3142 const gchar *src_codeset;
3144 out_codeset = conv_get_outgoing_charset_str();
3145 if (!strcasecmp(out_codeset, CS_US_ASCII))
3146 out_codeset = CS_ISO_8859_1;
3147 encoding = procmime_get_encoding_for_charset(out_codeset);
3149 src_codeset = conv_get_current_charset_str();
3150 /* if current encoding is US-ASCII, set it the same as
3151 outgoing one to prevent code conversion failure */
3152 if (!strcasecmp(src_codeset, CS_US_ASCII))
3153 src_codeset = out_codeset;
3155 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3156 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3158 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3164 _("Can't convert the character encoding of the message.\n"
3165 "Send it anyway?"), _("Yes"), _("+No"), NULL);
3166 if (aval != G_ALERTDEFAULT) {
3172 buf = g_strdup(chars);
3179 if (compose_write_headers
3180 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3181 g_warning(_("can't write headers\n"));
3188 if (compose_use_attach(compose)) {
3190 /* This prolog message is ignored by mime software and
3191 * because it would make our signing/encryption task
3192 * tougher, we don't emit it in that case */
3193 if (!compose->use_signing && !compose->use_encryption)
3195 fputs("This is a multi-part message in MIME format.\n", fp);
3197 fprintf(fp, "\n--%s\n", compose->boundary);
3198 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3200 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3201 procmime_get_encoding_str(encoding));
3207 if (encoding == ENC_BASE64) {
3208 gchar outbuf[B64_BUFFSIZE];
3211 for (i = 0; i < len; i += B64_LINE_SIZE) {
3212 l = MIN(B64_LINE_SIZE, len - i);
3213 to64frombits(outbuf, buf + i, l);
3217 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3218 FILE_OP_ERROR(file, "fwrite");
3226 if (compose_use_attach(compose))
3227 compose_write_attach(compose, fp);
3229 if (fclose(fp) == EOF) {
3230 FILE_OP_ERROR(file, "fclose");
3236 if (compose->use_signing) {
3239 if (compose_create_signers_list(compose, &key_list) == -1 ||
3240 rfc2015_sign(file, key_list) < 0) {
3246 if (compose->use_encryption) {
3247 if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) {
3252 #endif /* USE_GPGME */
3257 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3263 if ((fp = fopen(file, "wb")) == NULL) {
3264 FILE_OP_ERROR(file, "fopen");
3268 /* chmod for security */
3269 if (change_file_mode_rw(fp, file) < 0) {
3270 FILE_OP_ERROR(file, "chmod");
3271 g_warning(_("can't change file mode\n"));
3274 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3277 len = strlen(chars);
3278 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3279 FILE_OP_ERROR(file, "fwrite");
3288 if (fclose(fp) == EOF) {
3289 FILE_OP_ERROR(file, "fclose");
3296 static gint compose_remove_reedit_target(Compose *compose)
3299 MsgInfo *msginfo = compose->targetinfo;
3301 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3302 if (!msginfo) return -1;
3304 item = msginfo->folder;
3305 g_return_val_if_fail(item != NULL, -1);
3307 folder_item_scan(item);
3308 if (procmsg_msg_exist(msginfo) &&
3309 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3310 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3311 g_warning(_("can't remove the old message\n"));
3319 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3321 return compose_queue_sub (compose, msgnum, item, FALSE);
3323 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3329 gchar buf[BUFFSIZE];
3331 MsgFlags flag = {0, 0};
3332 static gboolean lock = FALSE;
3333 PrefsAccount *mailac = NULL, *newsac = NULL;
3335 debug_print(_("queueing message...\n"));
3336 g_return_val_if_fail(compose->account != NULL, -1);
3337 g_return_val_if_fail(compose->orig_account != NULL, -1);
3341 if (compose_check_entries(compose, check_subject) == FALSE) {
3346 if (!compose->to_list && !compose->newsgroup_list) {
3347 g_warning(_("can't get recipient list."));
3352 if(compose->to_list) {
3353 if (compose->account->protocol != A_NNTP)
3354 mailac = compose->account;
3355 else if (compose->orig_account->protocol != A_NNTP)
3356 mailac = compose->orig_account;
3357 else if (cur_account && cur_account->protocol != A_NNTP)
3358 mailac = cur_account;
3359 else if (!(mailac = compose_current_mail_account())) {
3361 alertpanel_error(_("No account for sending mails available!"));
3366 if(compose->newsgroup_list) {
3367 if (compose->account->protocol == A_NNTP)
3368 newsac = compose->account;
3369 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3371 alertpanel_error(_("No account for posting news available!"));
3376 if (prefs_common.linewrap_at_send)
3377 compose_wrap_line_all(compose);
3379 /* write to temporary file */
3380 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3381 G_DIR_SEPARATOR, (gint)compose);
3383 if (compose->redirect_filename != NULL) {
3384 if (compose_redirect_write_to_file(compose, tmp2) < 0) {
3391 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3398 /* add queue header */
3399 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3400 G_DIR_SEPARATOR, (gint)compose);
3401 if ((fp = fopen(tmp, "wb")) == NULL) {
3402 FILE_OP_ERROR(tmp, "fopen");
3406 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3407 FILE_OP_ERROR(tmp2, "fopen");
3415 if (change_file_mode_rw(fp, tmp) < 0) {
3416 FILE_OP_ERROR(tmp, "chmod");
3417 g_warning(_("can't change file mode\n"));
3420 /* queueing variables */
3421 fprintf(fp, "AF:\n");
3422 fprintf(fp, "NF:0\n");
3423 fprintf(fp, "PS:10\n");
3424 fprintf(fp, "SRH:1\n");
3425 fprintf(fp, "SFN:\n");
3426 fprintf(fp, "DSR:\n");
3428 fprintf(fp, "MID:<%s>\n", compose->msgid);
3430 fprintf(fp, "MID:\n");
3431 fprintf(fp, "CFG:\n");
3432 fprintf(fp, "PT:0\n");
3433 fprintf(fp, "S:%s\n", compose->account->address);
3434 fprintf(fp, "RQ:\n");
3436 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3438 fprintf(fp, "SSV:\n");
3440 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3442 fprintf(fp, "NSV:\n");
3443 fprintf(fp, "SSH:\n");
3444 /* write recepient list */
3446 if(compose->to_list) {
3447 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3448 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3449 fprintf(fp, ",<%s>", (gchar *)cur->data);
3452 /* write newsgroup list */
3454 if(compose->newsgroup_list) {
3455 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3456 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3457 fprintf(fp, ",%s", (gchar *)cur->data);
3460 /* Sylpheed account IDs */
3462 fprintf(fp, "MAID:%d\n", mailac->account_id);
3465 fprintf(fp, "NAID:%d\n", newsac->account_id);
3467 /* Save copy folder */
3468 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3471 str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3472 fprintf(fp, "SCF:%s\n", str);
3477 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3478 if (fputs(buf, fp) == EOF) {
3479 FILE_OP_ERROR(tmp, "fputs");
3490 if (fclose(fp) == EOF) {
3491 FILE_OP_ERROR(tmp, "fclose");
3499 queue = account_get_special_folder(compose->account, F_QUEUE);
3501 g_warning(_("can't find queue folder\n"));
3506 folder_item_scan(queue);
3507 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3508 g_warning(_("can't queue the message\n"));
3518 if (compose->mode == COMPOSE_REEDIT) {
3519 compose_remove_reedit_target(compose);
3520 if (compose->targetinfo &&
3521 compose->targetinfo->folder != queue)
3522 folderview_update_item
3523 (compose->targetinfo->folder, TRUE);
3526 procmsg_add_flags(queue, num, flag);
3527 folder_item_scan(queue);
3528 folderview_update_item(queue, TRUE);
3530 if((msgnum != NULL) && (item != NULL)) {
3538 static void compose_write_attach(Compose *compose, FILE *fp)
3541 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3544 gchar filename[BUFFSIZE];
3547 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3549 gchar buf[BUFFSIZE];
3550 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3552 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
3553 g_warning(_("Can't open file %s\n"), ainfo->file);
3557 fprintf(fp, "\n--%s\n", compose->boundary);
3559 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3560 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3561 fprintf(fp, "Content-Disposition: inline\n");
3563 conv_encode_header(filename, sizeof(filename),
3565 fprintf(fp, "Content-Type: %s;\n"
3567 ainfo->content_type, filename);
3568 fprintf(fp, "Content-Disposition: attachment;\n"
3569 " filename=\"%s\"\n", filename);
3572 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3573 procmime_get_encoding_str(ainfo->encoding));
3575 switch (ainfo->encoding) {
3579 /* if (ainfo->encoding == ENC_7BIT) { */
3581 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3589 while ((len = fread(inbuf, sizeof(gchar),
3590 B64_LINE_SIZE, attach_fp))
3592 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3596 if (len > 0 && feof(attach_fp)) {
3597 to64frombits(outbuf, inbuf, len);
3607 fprintf(fp, "\n--%s--\n", compose->boundary);
3610 #define QUOTE_IF_REQUIRED(out, str) \
3612 if (*str != '"' && strchr(str, ',')) { \
3616 len = strlen(str) + 3; \
3617 Xalloca(__tmp, len, return -1); \
3618 g_snprintf(__tmp, len, "\"%s\"", str); \
3621 Xstrdup_a(out, str, return -1); \
3625 #define PUT_RECIPIENT_HEADER(header, str) \
3627 if (*str != '\0') { \
3628 Xstrdup_a(str, str, return -1); \
3630 if (*str != '\0') { \
3631 compose->to_list = address_list_append \
3632 (compose->to_list, str); \
3633 compose_convert_header \
3634 (buf, sizeof(buf), str, strlen(header) + 2); \
3635 fprintf(fp, "%s: %s\n", header, buf); \
3640 #define IS_IN_CUSTOM_HEADER(header) \
3641 (compose->account->add_customhdr && \
3642 custom_header_find(compose->account->customhdr_list, header) != NULL)
3644 static gint compose_write_headers_from_headerlist(Compose *compose,
3648 gchar buf[BUFFSIZE];
3649 gchar *str, *header_w_colon, *trans_hdr;
3650 gboolean first_address;
3652 ComposeHeaderEntry *headerentry;
3653 gchar * headerentryname;
3655 if (IS_IN_CUSTOM_HEADER(header)) {
3659 debug_print(_("Writing %s-header\n"), header);
3661 header_w_colon = g_strconcat(header, ":", NULL);
3662 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3664 first_address = TRUE;
3665 for(list = compose->header_list; list; list = list->next) {
3666 headerentry = ((ComposeHeaderEntry *)list->data);
3667 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3669 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3670 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3671 Xstrdup_a(str, str, return -1);
3673 if(str[0] != '\0') {
3674 compose_convert_header
3675 (buf, sizeof(buf), str,
3676 strlen(header) + 2);
3678 fprintf(fp, "%s: ", header);
3679 first_address = FALSE;
3683 fprintf(fp, "%s", buf);
3687 if(!first_address) {
3691 g_free(header_w_colon);
3696 static gint compose_write_headers(Compose *compose, FILE *fp,
3697 const gchar *charset, EncodingType encoding,
3700 gchar buf[BUFFSIZE];
3703 /* struct utsname utsbuf; */
3705 g_return_val_if_fail(fp != NULL, -1);
3706 g_return_val_if_fail(charset != NULL, -1);
3707 g_return_val_if_fail(compose->account != NULL, -1);
3708 g_return_val_if_fail(compose->account->address != NULL, -1);
3711 if (compose->account->add_date) {
3712 get_rfc822_date(buf, sizeof(buf));
3713 fprintf(fp, "Date: %s\n", buf);
3717 if (!IS_IN_CUSTOM_HEADER("From")) {
3718 if (compose->account->name && *compose->account->name) {
3719 compose_convert_header
3720 (buf, sizeof(buf), compose->account->name,
3722 QUOTE_IF_REQUIRED(name, buf);
3723 fprintf(fp, "From: %s <%s>\n",
3724 name, compose->account->address);
3726 fprintf(fp, "From: %s\n", compose->account->address);
3730 compose_write_headers_from_headerlist(compose, fp, "To");
3731 #if 0 /* NEW COMPOSE GUI */
3732 if (compose->use_to) {
3733 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3734 PUT_RECIPIENT_HEADER("To", str);
3739 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3740 #if 0 /* NEW COMPOSE GUI */
3741 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3743 Xstrdup_a(str, str, return -1);
3747 compose->newsgroup_list =
3748 newsgroup_list_append(compose->newsgroup_list,
3750 compose_convert_header(buf, sizeof(buf), str,
3751 strlen("Newsgroups: "));
3752 fprintf(fp, "Newsgroups: %s\n", buf);
3757 compose_write_headers_from_headerlist(compose, fp, "Cc");
3758 #if 0 /* NEW COMPOSE GUI */
3759 if (compose->use_cc) {
3760 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3761 PUT_RECIPIENT_HEADER("Cc", str);
3765 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3766 #if 0 /* NEW COMPOSE GUI */
3767 if (compose->use_bcc) {
3768 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3769 PUT_RECIPIENT_HEADER("Bcc", str);
3774 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3775 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3776 Xstrdup_a(str, str, return -1);
3779 compose_convert_header(buf, sizeof(buf), str,
3780 strlen("Subject: "));
3781 fprintf(fp, "Subject: %s\n", buf);
3786 if (compose->account->gen_msgid) {
3787 compose_generate_msgid(compose, buf, sizeof(buf));
3788 fprintf(fp, "Message-Id: <%s>\n", buf);
3789 compose->msgid = g_strdup(buf);
3793 if (compose->inreplyto && compose->to_list)
3794 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3797 if (compose->references)
3798 fprintf(fp, "References: %s\n", compose->references);
3801 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3802 #if 0 /* NEW COMPOSE GUI */
3803 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3804 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3806 Xstrdup_a(str, str, return -1);
3810 compose_convert_header(buf, sizeof(buf), str,
3811 strlen("Followup-To: "));
3812 fprintf(fp, "Followup-To: %s\n", buf);
3818 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3819 #if 0 /* NEW COMPOSE GUI */
3820 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3821 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3823 Xstrdup_a(str, str, return -1);
3826 compose_convert_header(buf, sizeof(buf), str,
3827 strlen("Reply-To: "));
3828 fprintf(fp, "Reply-To: %s\n", buf);
3834 if (compose->account->organization &&
3835 !IS_IN_CUSTOM_HEADER("Organization")) {
3836 compose_convert_header(buf, sizeof(buf),
3837 compose->account->organization,
3838 strlen("Organization: "));
3839 fprintf(fp, "Organization: %s\n", buf);
3842 /* Program version and system info */
3843 /* uname(&utsbuf); */
3844 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3845 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3847 gtk_major_version, gtk_minor_version, gtk_micro_version,
3849 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3851 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3852 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3854 gtk_major_version, gtk_minor_version, gtk_micro_version,
3856 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3859 /* custom headers */
3860 if (compose->account->add_customhdr) {
3863 for (cur = compose->account->customhdr_list; cur != NULL;
3865 CustomHeader *chdr = (CustomHeader *)cur->data;
3867 if (strcasecmp(chdr->name, "Date") != 0 &&
3868 strcasecmp(chdr->name, "From") != 0 &&
3869 strcasecmp(chdr->name, "To") != 0 &&
3870 /* strcasecmp(chdr->name, "Sender") != 0 && */
3871 strcasecmp(chdr->name, "Message-Id") != 0 &&
3872 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3873 strcasecmp(chdr->name, "References") != 0 &&
3874 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3875 strcasecmp(chdr->name, "Content-Type") != 0 &&
3876 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3878 compose_convert_header
3880 chdr->value ? chdr->value : "",
3881 strlen(chdr->name) + 2);
3882 fprintf(fp, "%s: %s\n", chdr->name, buf);
3888 fprintf(fp, "Mime-Version: 1.0\n");
3889 if (compose_use_attach(compose)) {
3890 get_rfc822_date(buf, sizeof(buf));
3891 subst_char(buf, ' ', '_');
3892 subst_char(buf, ',', '_');
3893 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3894 buf, (guint)compose);
3896 "Content-Type: multipart/mixed;\n"
3897 " boundary=\"%s\"\n", compose->boundary);
3899 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3900 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3901 procmime_get_encoding_str(encoding));
3905 switch (compose->priority) {
3906 case PRIORITY_HIGHEST: fprintf(fp, "Importance: high\n"
3907 "X-Priority: 1 (Highest)\n");
3909 case PRIORITY_HIGH: fprintf(fp, "Importance: high\n"
3910 "X-Priority: 2 (High)\n");
3912 case PRIORITY_NORMAL: break;
3913 case PRIORITY_LOW: fprintf(fp, "Importance: low\n"
3914 "X-Priority: 4 (Low)\n");
3916 case PRIORITY_LOWEST: fprintf(fp, "Importance: low\n"
3917 "X-Priority: 5 (Lowest)\n");
3919 default: debug_print(_("compose: priority unknown : %d\n"),
3923 /* Request Return Receipt */
3924 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3925 if (compose->return_receipt) {
3926 if (compose->account->name
3927 && *compose->account->name) {
3928 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3929 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3931 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3935 /* separator between header and body */
3941 #undef IS_IN_CUSTOM_HEADER
3943 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3946 g_return_if_fail(src != NULL);
3947 g_return_if_fail(dest != NULL);
3949 if (len < 1) return;
3953 if (is_ascii_str(src)) {
3954 strncpy2(dest, src, len);
3955 dest[len - 1] = '\0';
3958 conv_encode_header(dest, len, src, header_len);
3961 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3970 if (compose->account && compose->account->address &&
3971 *compose->account->address) {
3972 if (strchr(compose->account->address, '@'))
3973 addr = g_strdup(compose->account->address);
3975 addr = g_strconcat(compose->account->address, "@",
3976 get_domain_name(), NULL);
3978 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3981 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3982 lt->tm_year + 1900, lt->tm_mon + 1,
3983 lt->tm_mday, lt->tm_hour,
3984 lt->tm_min, lt->tm_sec,
3985 (guint)random(), addr);
3987 debug_print(_("generated Message-ID: %s\n"), buf);
3992 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3993 GtkWidget **entry, gint *count,
3994 const gchar *label_str,
3995 gboolean is_addr_entry)
3999 if (GTK_TABLE(table)->nrows < (*count) + 1)
4000 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
4002 *hbox = gtk_hbox_new(FALSE, 0);
4003 label = gtk_label_new
4004 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
4005 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
4006 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
4008 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
4010 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
4011 #if 0 /* NEW COMPOSE GUI */
4012 if (GTK_TABLE(table)->nrows > (*count) + 1)
4013 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
4017 address_completion_register_entry(GTK_ENTRY(*entry));
4022 static void compose_create_header_entry(Compose *compose)
4024 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4028 GList *combo_list = NULL;
4029 gchar **string, *header;
4030 ComposeHeaderEntry *headerentry;
4032 headerentry = g_new0(ComposeHeaderEntry, 1);
4035 combo = gtk_combo_new();
4037 while(*string != NULL) {
4038 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4041 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4042 g_list_free(combo_list);
4043 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
4044 gtk_widget_show(combo);
4045 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4046 if(compose->header_last) {
4047 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4049 switch(compose->account->protocol) {
4051 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4054 header = prefs_common.trans_hdr ? _("To:") : "To:";
4058 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4061 entry = gtk_entry_new();
4062 gtk_widget_show(entry);
4063 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);
4065 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4066 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4067 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4069 address_completion_register_entry(GTK_ENTRY(entry));
4071 headerentry->compose = compose;
4072 headerentry->combo = combo;
4073 headerentry->entry = entry;
4074 headerentry->headernum = compose->header_nextrow;
4076 compose->header_nextrow++;
4077 compose->header_last = headerentry;
4080 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4082 ComposeHeaderEntry *last_header;
4084 last_header = compose->header_last;
4086 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4087 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4090 static GtkWidget *compose_create_header(Compose *compose)
4094 GtkWidget *from_optmenu_hbox;
4095 #if 0 /* NEW COMPOSE GUI */
4096 GtkWidget *to_entry;
4098 GtkWidget *newsgroups_entry;
4099 GtkWidget *newsgroups_hbox;
4101 GtkWidget *header_scrolledwin;
4102 GtkWidget *header_table;
4103 #if 0 /* NEW COMPOSE GUI */
4104 GtkWidget *cc_entry;
4106 GtkWidget *bcc_entry;
4107 GtkWidget *bcc_hbox;
4108 GtkWidget *reply_entry;
4109 GtkWidget *reply_hbox;
4110 GtkWidget *followup_entry;
4111 GtkWidget *followup_hbox;
4116 /* header labels and entries */
4117 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4118 gtk_widget_show(header_scrolledwin);
4119 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4121 header_table = gtk_table_new(2, 2, FALSE);
4122 gtk_widget_show(header_table);
4123 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4124 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4125 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4128 /* option menu for selecting accounts */
4129 hbox = gtk_hbox_new(FALSE, 0);
4130 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4131 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4132 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4134 from_optmenu_hbox = compose_account_option_menu_create(compose);
4135 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4136 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4137 #if 0 /* NEW COMPOSE GUI */
4138 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4142 compose->header_table = header_table;
4143 compose->header_list = NULL;
4144 compose->header_nextrow = count;
4146 compose_create_header_entry(compose);
4148 #if 0 /* NEW COMPOSE GUI */
4149 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4151 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4152 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4153 &count, "Newsgroups:", FALSE);
4154 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4156 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4158 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4160 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4161 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4163 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4164 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4166 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4167 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4168 "Followup-To:", FALSE);
4169 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4171 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4173 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4174 GTK_SIGNAL_FUNC(to_activated), compose);
4175 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4176 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4177 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4178 GTK_SIGNAL_FUNC(subject_activated), compose);
4179 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4180 GTK_SIGNAL_FUNC(cc_activated), compose);
4181 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4182 GTK_SIGNAL_FUNC(bcc_activated), compose);
4183 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4184 GTK_SIGNAL_FUNC(replyto_activated), compose);
4185 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4186 GTK_SIGNAL_FUNC(followupto_activated), compose);
4188 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4189 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4190 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4191 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4192 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4193 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4194 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4195 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4196 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4197 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4198 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4199 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4200 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4201 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4204 compose->table = NULL;
4205 #if 0 /* NEW COMPOSE GUI */
4206 compose->table = table;
4207 compose->to_hbox = to_hbox;
4208 compose->to_entry = to_entry;
4209 compose->newsgroups_hbox = newsgroups_hbox;
4210 compose->newsgroups_entry = newsgroups_entry;
4212 #if 0 /* NEW COMPOSE GUI */
4213 compose->cc_hbox = cc_hbox;
4214 compose->cc_entry = cc_entry;
4215 compose->bcc_hbox = bcc_hbox;
4216 compose->bcc_entry = bcc_entry;
4217 compose->reply_hbox = reply_hbox;
4218 compose->reply_entry = reply_entry;
4219 compose->followup_hbox = followup_hbox;
4220 compose->followup_entry = followup_entry;
4223 return header_scrolledwin ;
4226 GtkWidget *compose_create_attach(Compose *compose)
4228 gchar *titles[N_ATTACH_COLS];
4231 GtkWidget *attach_scrwin;
4232 GtkWidget *attach_clist;
4234 titles[COL_MIMETYPE] = _("MIME type");
4235 titles[COL_SIZE] = _("Size");
4236 titles[COL_NAME] = _("Name");
4238 /* attachment list */
4239 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4240 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4241 GTK_POLICY_AUTOMATIC,
4243 gtk_widget_set_usize(attach_scrwin, -1, 80);
4245 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4246 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4248 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4249 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4250 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4251 GTK_SELECTION_EXTENDED);
4252 for (i = 0; i < N_ATTACH_COLS; i++)
4253 GTK_WIDGET_UNSET_FLAGS
4254 (GTK_CLIST(attach_clist)->column[i].button,
4256 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4258 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4259 GTK_SIGNAL_FUNC(attach_selected), compose);
4260 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4261 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4262 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4263 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4266 gtk_drag_dest_set(attach_clist,
4267 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4269 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4270 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4273 compose->attach_scrwin = attach_scrwin;
4274 compose->attach_clist = attach_clist;
4276 return attach_scrwin;
4279 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4280 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4282 static GtkWidget *compose_create_others(Compose *compose)
4285 GtkWidget *savemsg_checkbtn;
4286 GtkWidget *savemsg_entry;
4287 GtkWidget *savemsg_select;
4290 gchar *folderidentifier;
4292 /* Table for settings */
4293 table = gtk_table_new(3, 1, FALSE);
4294 gtk_widget_show(table);
4295 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4298 /* Save Message to folder */
4299 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4300 gtk_widget_show(savemsg_checkbtn);
4301 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4302 if(account_get_special_folder(compose->account, F_OUTBOX)) {
4303 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4305 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4306 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4308 savemsg_entry = gtk_entry_new();
4309 gtk_widget_show(savemsg_entry);
4310 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4311 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4312 if(account_get_special_folder(compose->account, F_OUTBOX)) {
4313 folderidentifier = folder_item_get_identifier(account_get_special_folder
4314 (compose->account, F_OUTBOX));
4315 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4316 g_free(folderidentifier);
4319 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4320 gtk_widget_show (savemsg_select);
4321 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4322 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4323 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4328 compose->savemsg_checkbtn = savemsg_checkbtn;
4329 compose->savemsg_entry = savemsg_entry;
4334 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4336 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4337 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4340 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4345 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4348 path = folder_item_get_identifier(dest);
4350 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4354 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4360 GtkWidget *handlebox;
4362 GtkWidget *notebook;
4367 GtkWidget *subject_hbox;
4368 GtkWidget *subject_frame;
4369 GtkWidget *subject_entry;
4373 GtkWidget *edit_vbox;
4374 GtkWidget *ruler_hbox;
4376 GtkWidget *scrolledwin;
4381 UndoMain *undostruct;
4383 gchar *titles[N_ATTACH_COLS];
4384 guint n_menu_entries;
4385 GtkStyle *style, *new_style;
4388 gboolean success[1];
4390 GtkWidget *popupmenu;
4391 GtkWidget *menuitem;
4392 GtkItemFactory *popupfactory;
4393 GtkItemFactory *ifactory;
4394 GtkWidget *tmpl_menu;
4398 GtkPspell * gtkpspell = NULL;
4401 static GdkGeometry geometry;
4403 g_return_val_if_fail(account != NULL, NULL);
4405 debug_print(_("Creating compose window...\n"));
4406 compose = g_new0(Compose, 1);
4408 titles[COL_MIMETYPE] = _("MIME type");
4409 titles[COL_SIZE] = _("Size");
4410 titles[COL_NAME] = _("Name");
4412 compose->account = account;
4413 compose->orig_account = account;
4415 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4416 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4417 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4418 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4420 if (!geometry.max_width) {
4421 geometry.max_width = gdk_screen_width();
4422 geometry.max_height = gdk_screen_height();
4424 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4425 &geometry, GDK_HINT_MAX_SIZE);
4427 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4428 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4429 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4430 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4431 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4432 gtk_widget_realize(window);
4434 gtkut_widget_set_composer_icon(window);
4436 vbox = gtk_vbox_new(FALSE, 0);
4437 gtk_container_add(GTK_CONTAINER(window), vbox);
4439 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4440 menubar = menubar_create(window, compose_entries,
4441 n_menu_entries, "<Compose>", compose);
4442 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4444 handlebox = gtk_handle_box_new();
4445 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4447 compose_toolbar_create(compose, handlebox);
4449 vbox2 = gtk_vbox_new(FALSE, 2);
4450 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4451 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4454 notebook = gtk_notebook_new();
4455 gtk_widget_set_usize(notebook, -1, 130);
4456 gtk_widget_show(notebook);
4458 /* header labels and entries */
4459 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4460 /* attachment list */
4461 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4463 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4466 subject_hbox = gtk_hbox_new(FALSE, 0);
4467 gtk_widget_show(subject_hbox);
4469 subject_frame = gtk_frame_new(NULL);
4470 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4471 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4472 gtk_widget_show(subject_frame);
4474 subject = gtk_hbox_new(FALSE, 0);
4475 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4476 gtk_widget_show(subject);
4478 label = gtk_label_new(_("Subject:"));
4479 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4480 gtk_widget_show(label);
4482 subject_entry = gtk_entry_new();
4483 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4484 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4485 gtk_widget_show(subject_entry);
4486 compose->subject_entry = subject_entry;
4487 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4489 edit_vbox = gtk_vbox_new(FALSE, 0);
4490 #if 0 /* NEW COMPOSE GUI */
4491 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4494 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4497 ruler_hbox = gtk_hbox_new(FALSE, 0);
4498 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4500 ruler = gtk_shruler_new();
4501 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4502 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4504 gtk_widget_set_usize(ruler_hbox, 1, -1);
4507 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4508 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4509 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4510 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4511 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4513 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4514 (GTK_SCROLLED_WINDOW(scrolledwin)),
4515 gtk_scrolled_window_get_vadjustment
4516 (GTK_SCROLLED_WINDOW(scrolledwin)));
4517 GTK_STEXT(text)->default_tab_width = 8;
4518 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4520 if (prefs_common.block_cursor) {
4521 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4524 if (prefs_common.smart_wrapping) {
4525 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4526 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4529 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4531 gtk_signal_connect(GTK_OBJECT(text), "changed",
4532 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4533 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4534 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4535 gtk_signal_connect(GTK_OBJECT(text), "activate",
4536 GTK_SIGNAL_FUNC(text_activated), compose);
4537 gtk_signal_connect(GTK_OBJECT(text), "insert_text",
4538 GTK_SIGNAL_FUNC(text_inserted), compose);
4539 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4540 GTK_SIGNAL_FUNC(compose_button_press_cb),
4543 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4544 GTK_SIGNAL_FUNC(compose_key_press_cb),
4547 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4548 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4552 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4554 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4555 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4557 gtk_widget_show_all(vbox);
4559 /* pane between attach clist and text */
4560 paned = gtk_vpaned_new();
4561 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4562 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4563 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4564 gtk_paned_add1(GTK_PANED(paned), notebook);
4565 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4566 gtk_widget_show_all(paned);
4568 style = gtk_widget_get_style(text);
4570 /* workaround for the slow down of GtkSText when using Pixmap theme */
4571 if (style->engine) {
4572 GtkThemeEngine *engine;
4574 engine = style->engine;
4575 style->engine = NULL;
4576 new_style = gtk_style_copy(style);
4577 style->engine = engine;
4579 new_style = gtk_style_copy(style);
4581 if (prefs_common.textfont) {
4582 if (MB_CUR_MAX == 1) {
4585 Xstrdup_a(fontstr, prefs_common.textfont, );
4586 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4588 font = gdk_font_load(fontstr);
4590 font = gdk_fontset_load(prefs_common.textfont);
4592 gdk_font_unref(new_style->font);
4593 new_style->font = font;
4597 gtk_widget_set_style(text, new_style);
4599 color[0] = quote_color;
4600 cmap = gdk_window_get_colormap(window->window);
4601 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4602 if (success[0] == FALSE) {
4603 g_warning("Compose: color allocation failed.\n");
4604 style = gtk_widget_get_style(text);
4605 quote_color = style->black;
4608 n_entries = sizeof(compose_popup_entries) /
4609 sizeof(compose_popup_entries[0]);
4610 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4611 "<Compose>", &popupfactory,
4614 ifactory = gtk_item_factory_from_widget(menubar);
4615 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4616 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4618 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4619 #if 0 /* NEW COMPOSE GUI */
4620 gtk_widget_hide(bcc_hbox);
4621 gtk_widget_hide(bcc_entry);
4622 gtk_widget_hide(reply_hbox);
4623 gtk_widget_hide(reply_entry);
4624 gtk_widget_hide(followup_hbox);
4625 gtk_widget_hide(followup_entry);
4626 gtk_widget_hide(ruler_hbox);
4627 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4628 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4629 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4631 if (account->protocol == A_NNTP) {
4632 gtk_widget_hide(to_hbox);
4633 gtk_widget_hide(to_entry);
4634 gtk_widget_hide(cc_hbox);
4635 gtk_widget_hide(cc_entry);
4636 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4637 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4639 gtk_widget_hide(newsgroups_hbox);
4640 gtk_widget_hide(newsgroups_entry);
4641 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4642 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
4646 update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
4649 undostruct = undo_init(text);
4650 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4653 gtk_widget_show(window);
4655 address_completion_start(window);
4657 compose->window = window;
4658 compose->vbox = vbox;
4659 compose->menubar = menubar;
4660 compose->handlebox = handlebox;
4662 compose->vbox2 = vbox2;
4664 compose->paned = paned;
4666 compose->edit_vbox = edit_vbox;
4667 compose->ruler_hbox = ruler_hbox;
4668 compose->ruler = ruler;
4669 compose->scrolledwin = scrolledwin;
4670 compose->text = text;
4672 compose->focused_editable = NULL;
4674 compose->popupmenu = popupmenu;
4675 compose->popupfactory = popupfactory;
4677 compose->tmpl_menu = tmpl_menu;
4679 compose->mode = mode;
4681 compose->targetinfo = NULL;
4682 compose->replyinfo = NULL;
4684 compose->replyto = NULL;
4685 compose->mailinglist = NULL;
4687 compose->bcc = NULL;
4688 compose->followup_to = NULL;
4689 compose->inreplyto = NULL;
4690 compose->references = NULL;
4691 compose->msgid = NULL;
4692 compose->boundary = NULL;
4695 compose->use_signing = FALSE;
4696 compose->use_encryption = FALSE;
4697 #endif /* USE_GPGME */
4699 compose->modified = FALSE;
4701 compose->return_receipt = FALSE;
4702 compose->paste_as_quotation = FALSE;
4704 compose->to_list = NULL;
4705 compose->newsgroup_list = NULL;
4707 compose->exteditor_file = NULL;
4708 compose->exteditor_pid = -1;
4709 compose->exteditor_readdes = -1;
4710 compose->exteditor_tag = -1;
4712 compose->redirect_filename = NULL;
4713 compose->undostruct = undostruct;
4716 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4717 if (prefs_common.enable_pspell) {
4718 gtkpspell = gtkpspell_new((const gchar*)prefs_common.dictionary,
4719 conv_get_current_charset_str(),
4720 prefs_common.misspelled_col,
4721 prefs_common.check_while_typing,
4722 prefs_common.use_alternate,
4725 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkpspellcheckers->error_message);
4726 gtkpspell_checkers_reset_error();
4729 GtkWidget *menuitem;
4731 if (!gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode)) {
4732 debug_print(_("Pspell: could not set suggestion mode %s"),
4733 gtkpspellcheckers->error_message);
4734 gtkpspell_checkers_reset_error();
4737 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
4738 gtkpspell_populate_submenu(gtkpspell, menuitem);
4739 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4744 compose_set_title(compose);
4746 #if 0 /* NEW COMPOSE GUI */
4747 compose->use_bcc = FALSE;
4748 compose->use_replyto = FALSE;
4749 compose->use_followupto = FALSE;
4753 compose->gtkpspell = gtkpspell;
4756 #if 0 /* NEW COMPOSE GUI */
4757 if (account->protocol != A_NNTP) {
4758 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
4759 gtk_check_menu_item_set_active
4760 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4761 gtk_widget_set_sensitive(menuitem, FALSE);
4762 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4763 gtk_check_menu_item_set_active
4764 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4765 gtk_widget_set_sensitive(menuitem, FALSE);
4768 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4769 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4770 #if 0 /* NEW COMPOSE GUI */
4771 compose->use_cc = TRUE;
4772 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4773 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
4774 gtk_check_menu_item_set_active
4775 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4778 if (account->set_autobcc) {
4779 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4780 #if 0 /* NEW COMPOSE GUI */
4781 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
4782 gtk_check_menu_item_set_active
4783 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4784 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4785 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4789 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4790 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4791 #if 0 /* NEW COMPOSE GUI */
4792 compose->use_replyto = TRUE;
4793 menuitem = gtk_item_factory_get_item(ifactory,
4795 gtk_check_menu_item_set_active
4796 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4797 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4798 account->auto_replyto);
4802 if (account->protocol != A_NNTP) {
4803 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4805 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4808 #if 0 /* NEW COMPOSE GUI */
4809 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
4810 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4811 prefs_common.show_ruler);
4815 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4816 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4817 account->default_sign);
4818 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4819 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4820 account->default_encrypt);
4821 #endif /* USE_GPGME */
4823 addressbook_set_target_compose(compose);
4824 compose_set_template_menu(compose);
4826 compose_list = g_list_append(compose_list, compose);
4828 #if 0 /* NEW COMPOSE GUI */
4829 compose->use_to = FALSE;
4830 compose->use_cc = FALSE;
4831 compose->use_attach = TRUE;
4834 #if 0 /* NEW COMPOSE GUI */
4835 if (!compose->use_bcc) {
4836 gtk_widget_hide(bcc_hbox);
4837 gtk_widget_hide(bcc_entry);
4838 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4840 if (!compose->use_replyto) {
4841 gtk_widget_hide(reply_hbox);
4842 gtk_widget_hide(reply_entry);
4843 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4845 if (!compose->use_followupto) {
4846 gtk_widget_hide(followup_hbox);
4847 gtk_widget_hide(followup_entry);
4848 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4851 if (!prefs_common.show_ruler)
4852 gtk_widget_hide(ruler_hbox);
4855 compose->priority = PRIORITY_NORMAL;
4856 compose_update_priority_menu_item(compose);
4858 select_account(compose, account);
4859 set_toolbar_style(compose);
4864 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4867 GtkWidget *icon_wid;
4868 GtkWidget *send_btn;
4869 GtkWidget *sendl_btn;
4870 GtkWidget *draft_btn;
4871 GtkWidget *insert_btn;
4872 GtkWidget *attach_btn;
4874 GtkWidget *exteditor_btn;
4875 GtkWidget *linewrap_btn;
4876 GtkWidget *addrbook_btn;
4878 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4880 gtk_container_add(GTK_CONTAINER(container), toolbar);
4881 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4882 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4883 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4884 GTK_TOOLBAR_SPACE_LINE);
4886 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
4887 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4891 icon_wid, toolbar_send_cb, compose);
4893 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND_QUEUE);
4894 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4896 _("Put into queue folder and send later"),
4898 icon_wid, toolbar_send_later_cb,
4901 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL);
4902 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4904 _("Save to draft folder"),
4906 icon_wid, toolbar_draft_cb,
4909 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4911 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_INSERT_FILE);
4912 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4916 icon_wid, toolbar_insert_cb,
4919 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_ATTACH);
4920 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4924 icon_wid, toolbar_attach_cb,
4927 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4929 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SIGN);
4930 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4932 _("Insert signature"),
4934 icon_wid, toolbar_sig_cb, compose);
4936 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4938 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_EDIT_EXTERN);
4939 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4941 _("Edit with external editor"),
4944 toolbar_ext_editor_cb,
4947 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_LINEWRAP);
4948 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4950 _("Wrap all long lines"),
4953 toolbar_linewrap_cb,
4956 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4958 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_ADDRESS_BOOK);
4959 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4963 icon_wid, toolbar_address_cb,
4966 compose->toolbar = toolbar;
4967 compose->send_btn = send_btn;
4968 compose->sendl_btn = sendl_btn;
4969 compose->draft_btn = draft_btn;
4970 compose->insert_btn = insert_btn;
4971 compose->attach_btn = attach_btn;
4972 compose->sig_btn = sig_btn;
4973 compose->exteditor_btn = exteditor_btn;
4974 compose->linewrap_btn = linewrap_btn;
4975 compose->addrbook_btn = addrbook_btn;
4977 gtk_widget_show_all(toolbar);
4980 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4986 gint num = 0, def_menu = 0;
4988 accounts = account_get_list();
4989 g_return_val_if_fail(accounts != NULL, NULL);
4991 hbox = gtk_hbox_new(FALSE, 0);
4992 optmenu = gtk_option_menu_new();
4993 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4994 menu = gtk_menu_new();
4996 for (; accounts != NULL; accounts = accounts->next, num++) {
4997 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4998 GtkWidget *menuitem;
5001 if (ac == compose->account) def_menu = num;
5004 name = g_strdup_printf("%s: %s <%s>",
5006 ac->name, ac->address);
5008 name = g_strdup_printf("%s: %s",
5009 ac->account_name, ac->address);
5010 MENUITEM_ADD(menu, menuitem, name, ac);
5012 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
5013 GTK_SIGNAL_FUNC(account_activated),
5017 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5018 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5023 static void compose_set_priority_cb(gpointer data,
5027 Compose *compose = (Compose *) data;
5028 compose->priority = action;
5031 static void compose_update_priority_menu_item(Compose * compose)
5033 GtkItemFactory *ifactory;
5034 GtkWidget *menuitem;
5036 ifactory = gtk_item_factory_from_widget(compose->menubar);
5038 switch (compose->priority) {
5039 case PRIORITY_HIGHEST:
5040 menuitem = gtk_item_factory_get_item
5041 (ifactory, "/Message/Priority/Highest");
5044 menuitem = gtk_item_factory_get_item
5045 (ifactory, "/Message/Priority/High");
5047 case PRIORITY_NORMAL:
5048 menuitem = gtk_item_factory_get_item
5049 (ifactory, "/Message/Priority/Normal");
5052 menuitem = gtk_item_factory_get_item
5053 (ifactory, "/Message/Priority/Low");
5055 case PRIORITY_LOWEST:
5056 menuitem = gtk_item_factory_get_item
5057 (ifactory, "/Message/Priority/Lowest");
5060 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5063 static void compose_set_template_menu(Compose *compose)
5065 GSList *tmpl_list, *cur;
5069 tmpl_list = template_get_config();
5071 menu = gtk_menu_new();
5073 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5074 Template *tmpl = (Template *)cur->data;
5076 item = gtk_menu_item_new_with_label(tmpl->name);
5077 gtk_menu_append(GTK_MENU(menu), item);
5078 gtk_signal_connect(GTK_OBJECT(item), "activate",
5079 GTK_SIGNAL_FUNC(compose_template_activate_cb),
5081 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
5082 gtk_widget_show(item);
5085 gtk_widget_show(menu);
5086 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5089 void compose_reflect_prefs_all(void)
5094 for (cur = compose_list; cur != NULL; cur = cur->next) {
5095 compose = (Compose *)cur->data;
5096 compose_set_template_menu(compose);
5100 void compose_reflect_prefs_pixmap_theme(void)
5105 for (cur = compose_list; cur != NULL; cur = cur->next) {
5106 compose = (Compose *)cur->data;
5107 gtk_container_remove(GTK_CONTAINER(compose->handlebox), GTK_WIDGET(compose->toolbar));
5108 compose->toolbar = NULL;
5109 compose_toolbar_create(compose, compose->handlebox);
5110 set_toolbar_style(compose);
5114 static void compose_template_apply(Compose *compose, Template *tmpl,
5120 if (!tmpl || !tmpl->value) return;
5122 gtk_stext_freeze(GTK_STEXT(compose->text));
5124 if (tmpl->subject && *tmpl->subject != '\0')
5125 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5127 if (tmpl->to && *tmpl->to != '\0')
5128 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5131 gtk_stext_clear(GTK_STEXT(compose->text));
5133 if (compose->replyinfo == NULL) {
5134 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5137 if (prefs_common.quotemark && *prefs_common.quotemark)
5138 qmark = prefs_common.quotemark;
5142 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5143 tmpl->value, qmark, NULL);
5146 if (replace && parsed_str && prefs_common.auto_sig)
5147 compose_insert_sig(compose);
5149 if (replace && parsed_str) {
5150 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
5151 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
5155 compose_changed_cb(NULL, compose);
5157 gtk_stext_thaw(GTK_STEXT(compose->text));
5160 static void compose_destroy(Compose *compose)
5163 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5166 /* NOTE: address_completion_end() does nothing with the window
5167 * however this may change. */
5168 address_completion_end(compose->window);
5170 slist_free_strings(compose->to_list);
5171 g_slist_free(compose->to_list);
5172 slist_free_strings(compose->newsgroup_list);
5173 g_slist_free(compose->newsgroup_list);
5174 slist_free_strings(compose->header_list);
5175 g_slist_free(compose->header_list);
5177 procmsg_msginfo_free(compose->targetinfo);
5178 procmsg_msginfo_free(compose->replyinfo);
5180 g_free(compose->replyto);
5181 g_free(compose->cc);
5182 g_free(compose->bcc);
5183 g_free(compose->newsgroups);
5184 g_free(compose->followup_to);
5186 g_free(compose->inreplyto);
5187 g_free(compose->references);
5188 g_free(compose->msgid);
5189 g_free(compose->boundary);
5191 if (compose->redirect_filename)
5192 g_free(compose->redirect_filename);
5194 g_free(compose->exteditor_file);
5196 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5198 compose_attach_info_free(ainfo);
5200 if (addressbook_get_target_compose() == compose)
5201 addressbook_set_target_compose(NULL);
5204 if (compose->gtkpspell) {
5205 gtkpspell_delete(compose->gtkpspell);
5209 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5210 prefs_common.compose_height = compose->window->allocation.height;
5212 gtk_widget_destroy(compose->paned);
5216 compose_list = g_list_remove(compose_list, compose);
5219 static void compose_attach_info_free(AttachInfo *ainfo)
5221 g_free(ainfo->file);
5222 g_free(ainfo->content_type);
5223 g_free(ainfo->name);
5227 static void compose_attach_remove_selected(Compose *compose)
5229 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5233 while (clist->selection != NULL) {
5234 row = GPOINTER_TO_INT(clist->selection->data);
5235 ainfo = gtk_clist_get_row_data(clist, row);
5236 compose_attach_info_free(ainfo);
5237 gtk_clist_remove(clist, row);
5241 static struct _AttachProperty
5244 GtkWidget *mimetype_entry;
5245 GtkWidget *encoding_optmenu;
5246 GtkWidget *path_entry;
5247 GtkWidget *filename_entry;
5249 GtkWidget *cancel_btn;
5252 static void compose_attach_property(Compose *compose)
5254 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5257 GtkOptionMenu *optmenu;
5258 static gboolean cancelled;
5260 if (!clist->selection) return;
5261 row = GPOINTER_TO_INT(clist->selection->data);
5263 ainfo = gtk_clist_get_row_data(clist, row);
5266 if (!attach_prop.window)
5267 compose_attach_property_create(&cancelled);
5268 gtk_widget_grab_focus(attach_prop.ok_btn);
5269 gtk_widget_show(attach_prop.window);
5270 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5272 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5273 if (ainfo->encoding == ENC_UNKNOWN)
5274 gtk_option_menu_set_history(optmenu, ENC_BASE64);
5276 gtk_option_menu_set_history(optmenu, ainfo->encoding);
5278 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5279 ainfo->content_type ? ainfo->content_type : "");
5280 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5281 ainfo->file ? ainfo->file : "");
5282 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5283 ainfo->name ? ainfo->name : "");
5287 gchar *cnttype = NULL;
5291 GtkWidget *menuitem;
5296 if (cancelled == TRUE) {
5297 gtk_widget_hide(attach_prop.window);
5301 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5302 if (*text != '\0') {
5305 text = g_strstrip(g_strdup(text));
5306 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5307 cnttype = g_strdup(text);
5310 alertpanel_error(_("Invalid MIME type."));
5316 menu = gtk_option_menu_get_menu(optmenu);
5317 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5318 ainfo->encoding = GPOINTER_TO_INT
5319 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5321 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5322 if (*text != '\0') {
5323 if (is_file_exist(text) &&
5324 (size = get_file_size(text)) > 0)
5325 file = g_strdup(text);
5328 (_("File doesn't exist or is empty."));
5334 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5335 if (*text != '\0') {
5336 g_free(ainfo->name);
5337 ainfo->name = g_strdup(text);
5341 g_free(ainfo->content_type);
5342 ainfo->content_type = cnttype;
5345 g_free(ainfo->file);
5351 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5352 ainfo->content_type);
5353 gtk_clist_set_text(clist, row, COL_SIZE,
5354 to_human_readable(ainfo->size));
5355 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5357 gtk_widget_hide(attach_prop.window);
5362 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5364 label = gtk_label_new(str); \
5365 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5366 GTK_FILL, 0, 0, 0); \
5367 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5369 entry = gtk_entry_new(); \
5370 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5371 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5374 static void compose_attach_property_create(gboolean *cancelled)
5380 GtkWidget *mimetype_entry;
5383 GtkWidget *optmenu_menu;
5384 GtkWidget *menuitem;
5385 GtkWidget *path_entry;
5386 GtkWidget *filename_entry;
5389 GtkWidget *cancel_btn;
5390 GList *mime_type_list, *strlist;
5392 debug_print("Creating attach_property window...\n");
5394 window = gtk_window_new(GTK_WINDOW_DIALOG);
5395 gtk_widget_set_usize(window, 480, -1);
5396 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5397 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
5398 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5399 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5400 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5401 GTK_SIGNAL_FUNC(attach_property_delete_event),
5403 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5404 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5407 vbox = gtk_vbox_new(FALSE, 8);
5408 gtk_container_add(GTK_CONTAINER(window), vbox);
5410 table = gtk_table_new(4, 2, FALSE);
5411 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5412 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5413 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5415 label = gtk_label_new(_("MIME type"));
5416 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5418 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5419 mimetype_entry = gtk_combo_new();
5420 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5421 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5423 /* stuff with list */
5424 mime_type_list = procmime_get_mime_type_list();
5426 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5427 MimeType *type = (MimeType *) mime_type_list->data;
5428 strlist = g_list_append(strlist,
5429 g_strdup_printf("%s/%s",
5430 type->type, type->sub_type));
5433 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5435 for (mime_type_list = strlist; mime_type_list != NULL;
5436 mime_type_list = mime_type_list->next)
5437 g_free(mime_type_list->data);
5438 g_list_free(strlist);
5440 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5442 label = gtk_label_new(_("Encoding"));
5443 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5445 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5447 hbox = gtk_hbox_new(FALSE, 0);
5448 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5449 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5451 optmenu = gtk_option_menu_new();
5452 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5454 optmenu_menu = gtk_menu_new();
5455 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5456 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5458 gtk_widget_set_sensitive(menuitem, FALSE);
5460 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5461 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5463 gtk_widget_set_sensitive(menuitem, FALSE);
5465 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5466 gtk_widget_set_sensitive(menuitem, FALSE);
5467 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5469 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5471 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5472 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5474 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5475 &cancel_btn, _("Cancel"), NULL, NULL);
5476 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5477 gtk_widget_grab_default(ok_btn);
5479 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5480 GTK_SIGNAL_FUNC(attach_property_ok),
5482 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5483 GTK_SIGNAL_FUNC(attach_property_cancel),
5486 gtk_widget_show_all(vbox);
5488 attach_prop.window = window;
5489 attach_prop.mimetype_entry = mimetype_entry;
5490 attach_prop.encoding_optmenu = optmenu;
5491 attach_prop.path_entry = path_entry;
5492 attach_prop.filename_entry = filename_entry;
5493 attach_prop.ok_btn = ok_btn;
5494 attach_prop.cancel_btn = cancel_btn;
5497 #undef SET_LABEL_AND_ENTRY
5499 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5505 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5511 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5512 gboolean *cancelled)
5520 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5521 gboolean *cancelled)
5523 if (event && event->keyval == GDK_Escape) {
5529 static void compose_exec_ext_editor(Compose *compose)
5535 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5536 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5538 if (pipe(pipe_fds) < 0) {
5543 if ((pid = fork()) < 0) {
5549 /* close the write side of the pipe */
5552 compose->exteditor_file = g_strdup(tmp);
5553 compose->exteditor_pid = pid;
5554 compose->exteditor_readdes = pipe_fds[0];
5556 compose_set_ext_editor_sensitive(compose, FALSE);
5558 compose->exteditor_tag =
5559 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5560 compose_input_cb, compose);
5561 } else { /* process-monitoring process */
5567 /* close the read side of the pipe */
5570 if (compose_write_body_to_file(compose, tmp) < 0) {
5571 fd_write(pipe_fds[1], "2\n", 2);
5575 pid_ed = compose_exec_ext_editor_real(tmp);
5577 fd_write(pipe_fds[1], "1\n", 2);
5581 /* wait until editor is terminated */
5582 waitpid(pid_ed, NULL, 0);
5584 fd_write(pipe_fds[1], "0\n", 2);
5591 static gint compose_exec_ext_editor_real(const gchar *file)
5593 static gchar *def_cmd = "emacs %s";
5599 g_return_val_if_fail(file != NULL, -1);
5601 if ((pid = fork()) < 0) {
5606 if (pid != 0) return pid;
5608 /* grandchild process */
5610 if (setpgid(0, getppid()))
5613 if (prefs_common.ext_editor_cmd &&
5614 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5615 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5616 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5618 if (prefs_common.ext_editor_cmd)
5619 g_warning(_("External editor command line is invalid: `%s'\n"),
5620 prefs_common.ext_editor_cmd);
5621 g_snprintf(buf, sizeof(buf), def_cmd, file);
5624 cmdline = strsplit_with_quote(buf, " ", 1024);
5625 execvp(cmdline[0], cmdline);
5628 g_strfreev(cmdline);
5633 static gboolean compose_ext_editor_kill(Compose *compose)
5635 pid_t pgid = compose->exteditor_pid * -1;
5638 ret = kill(pgid, 0);
5640 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5644 msg = g_strdup_printf
5645 (_("The external editor is still working.\n"
5646 "Force terminating the process?\n"
5647 "process group id: %d"), -pgid);
5648 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5651 if (val == G_ALERTDEFAULT) {
5652 gdk_input_remove(compose->exteditor_tag);
5653 close(compose->exteditor_readdes);
5655 if (kill(pgid, SIGTERM) < 0) perror("kill");
5656 waitpid(compose->exteditor_pid, NULL, 0);
5658 g_warning(_("Terminated process group id: %d"), -pgid);
5659 g_warning(_("Temporary file: %s"),
5660 compose->exteditor_file);
5662 compose_set_ext_editor_sensitive(compose, TRUE);
5664 g_free(compose->exteditor_file);
5665 compose->exteditor_file = NULL;
5666 compose->exteditor_pid = -1;
5667 compose->exteditor_readdes = -1;
5668 compose->exteditor_tag = -1;
5676 static void compose_input_cb(gpointer data, gint source,
5677 GdkInputCondition condition)
5680 Compose *compose = (Compose *)data;
5683 debug_print(_("Compose: input from monitoring process\n"));
5685 gdk_input_remove(compose->exteditor_tag);
5688 if (read(source, &buf[i], 1) < 1) {
5692 if (buf[i] == '\n') {
5697 if (i == sizeof(buf) - 1)
5701 waitpid(compose->exteditor_pid, NULL, 0);
5703 if (buf[0] == '0') { /* success */
5704 GtkSText *text = GTK_STEXT(compose->text);
5706 gtk_stext_freeze(text);
5707 gtk_stext_set_point(text, 0);
5708 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5709 compose_insert_file(compose, compose->exteditor_file);
5710 compose_changed_cb(NULL, compose);
5711 gtk_stext_thaw(text);
5713 if (unlink(compose->exteditor_file) < 0)
5714 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5715 } else if (buf[0] == '1') { /* failed */
5716 g_warning(_("Couldn't exec external editor\n"));
5717 if (unlink(compose->exteditor_file) < 0)
5718 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5719 } else if (buf[0] == '2') {
5720 g_warning(_("Couldn't write to file\n"));
5721 } else if (buf[0] == '3') {
5722 g_warning(_("Pipe read failed\n"));
5727 compose_set_ext_editor_sensitive(compose, TRUE);
5729 g_free(compose->exteditor_file);
5730 compose->exteditor_file = NULL;
5731 compose->exteditor_pid = -1;
5732 compose->exteditor_readdes = -1;
5733 compose->exteditor_tag = -1;
5736 static void compose_set_ext_editor_sensitive(Compose *compose,
5739 GtkItemFactory *ifactory;
5741 ifactory = gtk_item_factory_from_widget(compose->menubar);
5743 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5744 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5745 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5747 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5748 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5749 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5750 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5751 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5754 gtk_widget_set_sensitive(compose->text, sensitive);
5755 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5756 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5757 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5758 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5759 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5760 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5761 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5765 * compose_undo_state_changed:
5767 * Change the sensivity of the menuentries undo and redo
5769 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5770 gint redo_state, gpointer data)
5772 GtkWidget *widget = GTK_WIDGET(data);
5773 GtkItemFactory *ifactory;
5775 g_return_if_fail(widget != NULL);
5777 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
5779 ifactory = gtk_item_factory_from_widget(widget);
5781 switch (undo_state) {
5782 case UNDO_STATE_TRUE:
5783 if (!undostruct->undo_state) {
5784 debug_print ("Set_undo - Testpoint\n");
5785 undostruct->undo_state = TRUE;
5786 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5789 case UNDO_STATE_FALSE:
5790 if (undostruct->undo_state) {
5791 undostruct->undo_state = FALSE;
5792 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5795 case UNDO_STATE_UNCHANGED:
5797 case UNDO_STATE_REFRESH:
5798 menu_set_sensitive(ifactory, "/Edit/Undo",
5799 undostruct->undo_state);
5802 g_warning("Undo state not recognized");
5806 switch (redo_state) {
5807 case UNDO_STATE_TRUE:
5808 if (!undostruct->redo_state) {
5809 undostruct->redo_state = TRUE;
5810 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5813 case UNDO_STATE_FALSE:
5814 if (undostruct->redo_state) {
5815 undostruct->redo_state = FALSE;
5816 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5819 case UNDO_STATE_UNCHANGED:
5821 case UNDO_STATE_REFRESH:
5822 menu_set_sensitive(ifactory, "/Edit/Redo",
5823 undostruct->redo_state);
5826 g_warning("Redo state not recognized");
5831 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5835 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5836 cursor_pos = MAX(cursor_pos, 0);
5841 /* callback functions */
5843 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5844 * includes "non-client" (windows-izm) in calculation, so this calculation
5845 * may not be accurate.
5847 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5848 GtkAllocation *allocation,
5849 GtkSHRuler *shruler)
5851 if (prefs_common.show_ruler) {
5853 gint line_width_in_chars;
5855 char_width = gtkut_get_font_width
5856 (GTK_WIDGET(widget)->style->font);
5857 line_width_in_chars =
5858 (allocation->width - allocation->x) / char_width;
5860 /* got the maximum */
5861 gtk_ruler_set_range(GTK_RULER(shruler),
5862 0.0, line_width_in_chars,
5863 calc_cursor_xpos(GTK_STEXT(widget),
5866 /*line_width_in_chars*/ char_width);
5872 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5874 compose_send_cb(data, 0, NULL);
5877 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5879 compose_send_later_cb(data, 0, NULL);
5882 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5884 compose_draft_cb(data, 0, NULL);
5887 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5889 compose_insert_file_cb(data, 0, NULL);
5892 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5894 compose_attach_cb(data, 0, NULL);
5897 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5899 Compose *compose = (Compose *)data;
5901 compose_insert_sig(compose);
5904 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5906 Compose *compose = (Compose *)data;
5908 compose_exec_ext_editor(compose);
5911 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5913 Compose *compose = (Compose *)data;
5915 compose_wrap_line(compose);
5918 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5920 compose_address_cb(data, 0, NULL);
5923 static void select_account(Compose * compose, PrefsAccount * ac)
5926 GtkItemFactory *ifactory;
5927 GtkWidget *menuitem;
5928 #endif /* USE_GPGME */
5929 compose->account = ac;
5930 compose_set_title(compose);
5932 #if 0 /* NEW COMPOSE GUI */
5933 if (ac->protocol == A_NNTP) {
5934 GtkItemFactory *ifactory;
5935 GtkWidget *menuitem;
5937 ifactory = gtk_item_factory_from_widget(compose->menubar);
5938 menu_set_sensitive(ifactory,
5939 "/Message/Followup to", TRUE);
5940 gtk_widget_show(compose->newsgroups_hbox);
5941 gtk_widget_show(compose->newsgroups_entry);
5942 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5945 compose->use_to = FALSE;
5946 compose->use_cc = FALSE;
5948 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5949 gtk_check_menu_item_set_active
5950 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5952 menu_set_sensitive(ifactory,
5953 "/Message/To", TRUE);
5954 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5955 gtk_check_menu_item_set_active
5956 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5958 gtk_widget_hide(compose->to_hbox);
5959 gtk_widget_hide(compose->to_entry);
5960 gtk_widget_hide(compose->cc_hbox);
5961 gtk_widget_hide(compose->cc_entry);
5962 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5964 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5968 GtkItemFactory *ifactory;
5969 GtkWidget *menuitem;
5971 ifactory = gtk_item_factory_from_widget(compose->menubar);
5972 menu_set_sensitive(ifactory,
5973 "/Message/Followup to", FALSE);
5974 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5975 gtk_widget_hide(compose->newsgroups_hbox);
5976 gtk_widget_hide(compose->newsgroups_entry);
5977 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5980 compose->use_to = TRUE;
5981 compose->use_cc = TRUE;
5983 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5984 gtk_check_menu_item_set_active
5985 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5986 menu_set_sensitive(ifactory,
5987 "/Message/To", FALSE);
5988 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5989 gtk_check_menu_item_set_active
5990 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5991 gtk_widget_show(compose->to_hbox);
5992 gtk_widget_show(compose->to_entry);
5993 gtk_widget_show(compose->cc_hbox);
5994 gtk_widget_show(compose->cc_entry);
5996 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5998 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
6001 gtk_widget_queue_resize(compose->table_vbox);
6004 ifactory = gtk_item_factory_from_widget(compose->menubar);
6005 menu_set_sensitive(ifactory,
6006 "/Message/Sign", TRUE);
6007 menu_set_sensitive(ifactory,
6008 "/Message/Encrypt", TRUE);
6010 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
6011 if (ac->default_sign)
6012 gtk_check_menu_item_set_active
6013 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6015 gtk_check_menu_item_set_active
6016 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
6018 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
6019 if (ac->default_encrypt)
6020 gtk_check_menu_item_set_active
6021 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
6023 gtk_check_menu_item_set_active
6024 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
6025 #endif /* USE_GPGME */
6029 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6031 Compose *compose = (Compose *)data;
6035 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
6036 g_return_if_fail(ac != NULL);
6038 if (ac != compose->account)
6039 select_account(compose, ac);
6042 static void attach_selected(GtkCList *clist, gint row, gint column,
6043 GdkEvent *event, gpointer data)
6045 Compose *compose = (Compose *)data;
6047 if (event && event->type == GDK_2BUTTON_PRESS)
6048 compose_attach_property(compose);
6051 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6054 Compose *compose = (Compose *)data;
6055 GtkCList *clist = GTK_CLIST(compose->attach_clist);
6060 if (event->button == 3) {
6061 if ((clist->selection && !clist->selection->next) ||
6062 !clist->selection) {
6063 gtk_clist_unselect_all(clist);
6064 if (gtk_clist_get_selection_info(clist,
6067 gtk_clist_select_row(clist, row, column);
6068 gtkut_clist_set_focus_row(clist, row);
6071 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6072 NULL, NULL, event->button, event->time);
6076 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6079 Compose *compose = (Compose *)data;
6083 switch (event->keyval) {
6085 compose_attach_remove_selected(compose);
6090 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6092 Compose *compose = (Compose *)data;
6095 if (prefs_common.work_offline)
6096 if (alertpanel(_("Offline warning"),
6097 _("You're working offline. Override?"),
6098 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
6101 val = compose_send(compose);
6103 if (val == 0) gtk_widget_destroy(compose->window);
6106 static void compose_send_later_cb(gpointer data, guint action,
6109 Compose *compose = (Compose *)data;
6112 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6113 if (!val) gtk_widget_destroy(compose->window);
6116 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6118 Compose *compose = (Compose *)data;
6122 MsgFlags flag = {0, 0};
6123 static gboolean lock = FALSE;
6127 draft = account_get_special_folder(compose->account, F_DRAFT);
6128 g_return_if_fail(draft != NULL);
6132 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
6133 G_DIR_SEPARATOR, (gint)compose);
6135 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
6141 folder_item_scan(draft);
6142 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) < 0) {
6149 draft->mtime = 0; /* force updating */
6151 if (compose->mode == COMPOSE_REEDIT) {
6152 compose_remove_reedit_target(compose);
6153 if (compose->targetinfo &&
6154 compose->targetinfo->folder != draft)
6155 folderview_update_item(compose->targetinfo->folder,
6159 procmsg_add_flags(draft, msgnum, flag);
6160 folder_item_scan(draft);
6161 folderview_update_item(draft, TRUE);
6165 /* 0: quit editing 1: keep editing */
6167 gtk_widget_destroy(compose->window);
6172 path = folder_item_fetch_msg(draft, msgnum);
6173 g_return_if_fail(path != NULL);
6174 if (stat(path, &s) < 0) {
6175 FILE_OP_ERROR(path, "stat");
6182 procmsg_msginfo_free(compose->targetinfo);
6183 compose->targetinfo = g_new0(MsgInfo, 1);
6184 compose->targetinfo->msgnum = msgnum;
6185 compose->targetinfo->size = s.st_size;
6186 compose->targetinfo->mtime = s.st_mtime;
6187 compose->targetinfo->folder = draft;
6188 compose->mode = COMPOSE_REEDIT;
6192 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6194 Compose *compose = (Compose *)data;
6197 if (compose->redirect_filename != NULL)
6200 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6205 for ( tmp = file_list; tmp; tmp = tmp->next) {
6206 gchar *file = (gchar *) tmp->data;
6207 compose_attach_append(compose, file, file, NULL);
6208 compose_changed_cb(NULL, compose);
6211 g_list_free(file_list);
6215 static void compose_insert_file_cb(gpointer data, guint action,
6218 Compose *compose = (Compose *)data;
6221 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6226 for ( tmp = file_list; tmp; tmp = tmp->next) {
6227 gchar *file = (gchar *) tmp->data;
6228 compose_insert_file(compose, file);
6231 g_list_free(file_list);
6235 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6238 compose_close_cb(data, 0, NULL);
6242 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6244 Compose *compose = (Compose *)data;
6247 if (compose->exteditor_tag != -1) {
6248 if (!compose_ext_editor_kill(compose))
6252 if (compose->modified) {
6253 val = alertpanel(_("Discard message"),
6254 _("This message has been modified. discard it?"),
6255 _("Discard"), _("to Draft"), _("Cancel"));
6258 case G_ALERTDEFAULT:
6260 case G_ALERTALTERNATE:
6261 compose_draft_cb(data, 0, NULL);
6267 gtk_widget_destroy(compose->window);
6270 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6272 Compose *compose = (Compose *)data;
6274 addressbook_open(compose);
6277 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6279 Compose *compose = (Compose *)data;
6284 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6285 g_return_if_fail(tmpl != NULL);
6287 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6289 val = alertpanel(_("Apply template"), msg,
6290 _("Replace"), _("Insert"), _("Cancel"));
6293 if (val == G_ALERTDEFAULT)
6294 compose_template_apply(compose, tmpl, TRUE);
6295 else if (val == G_ALERTALTERNATE)
6296 compose_template_apply(compose, tmpl, FALSE);
6299 static void compose_ext_editor_cb(gpointer data, guint action,
6302 Compose *compose = (Compose *)data;
6304 compose_exec_ext_editor(compose);
6307 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6309 compose_destroy(compose);
6312 static void compose_undo_cb(Compose *compose)
6314 undo_undo(compose->undostruct);
6317 static void compose_redo_cb(Compose *compose)
6319 undo_redo(compose->undostruct);
6322 static void compose_cut_cb(Compose *compose)
6324 if (compose->focused_editable &&
6325 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6326 gtk_editable_cut_clipboard
6327 (GTK_EDITABLE(compose->focused_editable));
6330 static void compose_copy_cb(Compose *compose)
6332 if (compose->focused_editable &&
6333 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6334 gtk_editable_copy_clipboard
6335 (GTK_EDITABLE(compose->focused_editable));
6338 static void compose_paste_cb(Compose *compose)
6340 if (compose->focused_editable &&
6341 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6342 gtk_editable_paste_clipboard
6343 (GTK_EDITABLE(compose->focused_editable));
6346 static void compose_paste_as_quote_cb(Compose *compose)
6348 if (compose->focused_editable &&
6349 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6350 compose->paste_as_quotation = TRUE;
6351 gtk_editable_paste_clipboard
6352 (GTK_EDITABLE(compose->focused_editable));
6353 compose->paste_as_quotation = FALSE;
6357 static void compose_allsel_cb(Compose *compose)
6359 if (compose->focused_editable &&
6360 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6361 gtk_editable_select_region
6362 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6365 static void compose_move_beginning_of_line_cb(Compose *compose)
6367 if (compose->focused_editable &&
6368 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6369 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6372 static void compose_gtk_stext_action_cb(Compose *compose, ComposeCallGtkSTextAction action)
6374 if (!(compose->focused_editable && GTK_WIDGET_HAS_FOCUS(compose->focused_editable))) return;
6377 case COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE:
6378 gtk_stext_move_beginning_of_line(GTK_STEXT(compose->focused_editable));
6380 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER:
6381 gtk_stext_move_forward_character(GTK_STEXT(compose->focused_editable));
6383 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER:
6384 gtk_stext_move_backward_character(GTK_STEXT(compose->focused_editable));
6386 case COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD:
6387 gtk_stext_move_forward_word(GTK_STEXT(compose->focused_editable));
6389 case COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD:
6390 gtk_stext_move_backward_word(GTK_STEXT(compose->focused_editable));
6392 case COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE:
6393 gtk_stext_move_end_of_line(GTK_STEXT(compose->focused_editable));
6395 case COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE:
6396 gtk_stext_move_next_line(GTK_STEXT(compose->focused_editable));
6398 case COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE:
6399 gtk_stext_move_previous_line(GTK_STEXT(compose->focused_editable));
6401 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER:
6402 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6404 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER:
6405 gtk_stext_delete_backward_character(GTK_STEXT(compose->focused_editable));
6407 case COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD:
6408 gtk_stext_delete_forward_word(GTK_STEXT(compose->focused_editable));
6410 case COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD:
6411 gtk_stext_delete_backward_word(GTK_STEXT(compose->focused_editable));
6413 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE:
6414 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6416 case COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N:
6417 gtk_stext_delete_line(GTK_STEXT(compose->focused_editable));
6418 gtk_stext_delete_forward_character(GTK_STEXT(compose->focused_editable));
6420 case COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END:
6421 gtk_stext_delete_to_line_end(GTK_STEXT(compose->focused_editable));
6428 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6430 if (GTK_IS_EDITABLE(widget))
6431 compose->focused_editable = widget;
6434 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6436 if (compose->modified == FALSE) {
6437 compose->modified = TRUE;
6438 compose_set_title(compose);
6442 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6445 gtk_stext_set_point(GTK_STEXT(widget),
6446 gtk_editable_get_position(GTK_EDITABLE(widget)));
6450 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6453 gtk_stext_set_point(GTK_STEXT(widget),
6454 gtk_editable_get_position(GTK_EDITABLE(widget)));
6458 #if 0 /* NEW COMPOSE GUI */
6459 static void compose_toggle_to_cb(gpointer data, guint action,
6462 Compose *compose = (Compose *)data;
6464 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6465 gtk_widget_show(compose->to_hbox);
6466 gtk_widget_show(compose->to_entry);
6467 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6468 compose->use_to = TRUE;
6470 gtk_widget_hide(compose->to_hbox);
6471 gtk_widget_hide(compose->to_entry);
6472 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6473 gtk_widget_queue_resize(compose->table_vbox);
6474 compose->use_to = FALSE;
6477 if (addressbook_get_target_compose() == compose)
6478 addressbook_set_target_compose(compose);
6481 static void compose_toggle_cc_cb(gpointer data, guint action,
6484 Compose *compose = (Compose *)data;
6486 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6487 gtk_widget_show(compose->cc_hbox);
6488 gtk_widget_show(compose->cc_entry);
6489 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6490 compose->use_cc = TRUE;
6492 gtk_widget_hide(compose->cc_hbox);
6493 gtk_widget_hide(compose->cc_entry);
6494 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6495 gtk_widget_queue_resize(compose->table_vbox);
6496 compose->use_cc = FALSE;
6499 if (addressbook_get_target_compose() == compose)
6500 addressbook_set_target_compose(compose);
6503 static void compose_toggle_bcc_cb(gpointer data, guint action,
6506 Compose *compose = (Compose *)data;
6508 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6509 gtk_widget_show(compose->bcc_hbox);
6510 gtk_widget_show(compose->bcc_entry);
6511 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6512 compose->use_bcc = TRUE;
6514 gtk_widget_hide(compose->bcc_hbox);
6515 gtk_widget_hide(compose->bcc_entry);
6516 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6517 gtk_widget_queue_resize(compose->table_vbox);
6518 compose->use_bcc = FALSE;
6521 if (addressbook_get_target_compose() == compose)
6522 addressbook_set_target_compose(compose);
6525 static void compose_toggle_replyto_cb(gpointer data, guint action,
6528 Compose *compose = (Compose *)data;
6530 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6531 gtk_widget_show(compose->reply_hbox);
6532 gtk_widget_show(compose->reply_entry);
6533 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6534 compose->use_replyto = TRUE;
6536 gtk_widget_hide(compose->reply_hbox);
6537 gtk_widget_hide(compose->reply_entry);
6538 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6539 gtk_widget_queue_resize(compose->table_vbox);
6540 compose->use_replyto = FALSE;
6544 static void compose_toggle_followupto_cb(gpointer data, guint action,
6547 Compose *compose = (Compose *)data;
6549 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6550 gtk_widget_show(compose->followup_hbox);
6551 gtk_widget_show(compose->followup_entry);
6552 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6553 compose->use_followupto = TRUE;
6555 gtk_widget_hide(compose->followup_hbox);
6556 gtk_widget_hide(compose->followup_entry);
6557 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6558 gtk_widget_queue_resize(compose->table_vbox);
6559 compose->use_followupto = FALSE;
6563 static void compose_toggle_attach_cb(gpointer data, guint action,
6566 Compose *compose = (Compose *)data;
6568 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6569 gtk_widget_ref(compose->edit_vbox);
6571 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6572 compose->edit_vbox);
6573 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6574 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6576 gtk_widget_show(compose->paned);
6578 gtk_widget_unref(compose->edit_vbox);
6579 gtk_widget_unref(compose->paned);
6581 compose->use_attach = TRUE;
6583 gtk_widget_ref(compose->paned);
6584 gtk_widget_ref(compose->edit_vbox);
6586 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6588 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6589 compose->edit_vbox);
6590 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6591 compose->edit_vbox, TRUE, TRUE, 0);
6593 gtk_widget_unref(compose->edit_vbox);
6595 compose->use_attach = FALSE;
6601 static void compose_toggle_sign_cb(gpointer data, guint action,
6604 Compose *compose = (Compose *)data;
6606 if (GTK_CHECK_MENU_ITEM(widget)->active)
6607 compose->use_signing = TRUE;
6609 compose->use_signing = FALSE;
6612 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6615 Compose *compose = (Compose *)data;
6617 if (GTK_CHECK_MENU_ITEM(widget)->active)
6618 compose->use_encryption = TRUE;
6620 compose->use_encryption = FALSE;
6622 #endif /* USE_GPGME */
6624 static void compose_toggle_ruler_cb(gpointer data, guint action,
6627 Compose *compose = (Compose *)data;
6629 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6630 gtk_widget_show(compose->ruler_hbox);
6631 prefs_common.show_ruler = TRUE;
6633 gtk_widget_hide(compose->ruler_hbox);
6634 gtk_widget_queue_resize(compose->edit_vbox);
6635 prefs_common.show_ruler = FALSE;
6639 static void compose_attach_drag_received_cb (GtkWidget *widget,
6640 GdkDragContext *drag_context,
6643 GtkSelectionData *data,
6648 Compose *compose = (Compose *)user_data;
6651 list = uri_list_extract_filenames((const gchar *)data->data);
6652 for (tmp = list; tmp != NULL; tmp = tmp->next)
6653 compose_attach_append
6654 (compose, (const gchar *)tmp->data,
6655 (const gchar *)tmp->data, NULL);
6656 if (list) compose_changed_cb(NULL, compose);
6657 list_free_strings(list);
6661 static void compose_insert_drag_received_cb (GtkWidget *widget,
6662 GdkDragContext *drag_context,
6665 GtkSelectionData *data,
6670 Compose *compose = (Compose *)user_data;
6673 list = uri_list_extract_filenames((const gchar *)data->data);
6674 for (tmp = list; tmp != NULL; tmp = tmp->next)
6675 compose_insert_file(compose, (const gchar *)tmp->data);
6676 list_free_strings(list);
6680 #if 0 /* NEW COMPOSE GUI */
6681 static void to_activated(GtkWidget *widget, Compose *compose)
6683 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6684 gtk_widget_grab_focus(compose->newsgroups_entry);
6686 gtk_widget_grab_focus(compose->subject_entry);
6689 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6691 gtk_widget_grab_focus(compose->subject_entry);
6694 static void subject_activated(GtkWidget *widget, Compose *compose)
6696 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6697 gtk_widget_grab_focus(compose->cc_entry);
6698 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6699 gtk_widget_grab_focus(compose->bcc_entry);
6700 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6701 gtk_widget_grab_focus(compose->reply_entry);
6702 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6703 gtk_widget_grab_focus(compose->followup_entry);
6705 gtk_widget_grab_focus(compose->text);
6708 static void cc_activated(GtkWidget *widget, Compose *compose)
6710 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6711 gtk_widget_grab_focus(compose->bcc_entry);
6712 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6713 gtk_widget_grab_focus(compose->reply_entry);
6714 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6715 gtk_widget_grab_focus(compose->followup_entry);
6717 gtk_widget_grab_focus(compose->text);
6720 static void bcc_activated(GtkWidget *widget, Compose *compose)
6722 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6723 gtk_widget_grab_focus(compose->reply_entry);
6724 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6725 gtk_widget_grab_focus(compose->followup_entry);
6727 gtk_widget_grab_focus(compose->text);
6730 static void replyto_activated(GtkWidget *widget, Compose *compose)
6732 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6733 gtk_widget_grab_focus(compose->followup_entry);
6735 gtk_widget_grab_focus(compose->text);
6738 static void followupto_activated(GtkWidget *widget, Compose *compose)
6740 gtk_widget_grab_focus(compose->text);
6744 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6747 Compose *compose = (Compose *)data;
6749 if (GTK_CHECK_MENU_ITEM(widget)->active)
6750 compose->return_receipt = TRUE;
6752 compose->return_receipt = FALSE;
6755 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6757 ComposeHeaderEntry *headerentry)
6759 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6760 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6761 !(event->state & GDK_MODIFIER_MASK) &&
6762 (event->keyval == GDK_BackSpace) &&
6763 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6764 gtk_container_remove
6765 (GTK_CONTAINER(headerentry->compose->header_table),
6766 headerentry->combo);
6767 gtk_container_remove
6768 (GTK_CONTAINER(headerentry->compose->header_table),
6769 headerentry->entry);
6770 headerentry->compose->header_list =
6771 g_slist_remove(headerentry->compose->header_list,
6773 g_free(headerentry);
6774 } else if (event->keyval == GDK_Tab) {
6775 if (headerentry->compose->header_last == headerentry) {
6776 /* Override default next focus, and give it to subject_entry
6777 * instead of notebook tabs
6779 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6780 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6786 void compose_headerentry_changed_cb(GtkWidget *entry,
6787 ComposeHeaderEntry *headerentry)
6789 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6790 headerentry->compose->header_list =
6791 g_slist_append(headerentry->compose->header_list,
6793 compose_create_header_entry(headerentry->compose);
6794 gtk_signal_disconnect_by_func
6796 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6798 /* Automatically scroll down */
6799 compose_show_first_last_header(headerentry->compose, FALSE);
6804 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6806 GtkAdjustment *vadj;
6808 g_return_if_fail(compose);
6809 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6810 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6812 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6813 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6816 static void text_activated(GtkWidget *widget, Compose *compose)
6818 compose_send_control_enter(compose);
6821 static void text_inserted(GtkWidget *widget, const gchar *text,
6822 gint length, gint *position, Compose *compose)
6824 GtkEditable *editable = GTK_EDITABLE(widget);
6826 gtk_signal_handler_block_by_func(GTK_OBJECT(widget),
6827 GTK_SIGNAL_FUNC(text_inserted),
6829 if (compose->paste_as_quotation) {
6834 new_text = g_strndup(text, length);
6835 if (prefs_common.quotemark && *prefs_common.quotemark)
6836 qmark = prefs_common.quotemark;
6839 gtk_stext_set_point(GTK_STEXT(widget), *position);
6840 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
6841 pos = gtk_stext_get_point(GTK_STEXT(widget));
6842 gtk_editable_set_position(editable, pos);
6846 gtk_editable_insert_text(editable, text, length, position);
6847 gtk_signal_handler_unblock_by_func(GTK_OBJECT(widget),
6848 GTK_SIGNAL_FUNC(text_inserted),
6850 gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
6853 static gboolean compose_send_control_enter(Compose *compose)
6857 GtkItemFactory *ifactory;
6858 GtkAccelEntry *accel;
6859 GtkWidget *send_menu;
6861 GdkModifierType ignored_mods =
6862 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
6863 GDK_MOD4_MASK | GDK_MOD5_MASK);
6865 ev = gtk_get_current_event();
6866 if (ev->type != GDK_KEY_PRESS) return FALSE;
6868 kev = (GdkEventKey *)ev;
6869 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6872 ifactory = gtk_item_factory_from_widget(compose->menubar);
6873 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6874 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6875 accel = (GtkAccelEntry *)list->data;
6876 if (accel->accelerator_key == kev->keyval &&
6877 (accel->accelerator_mods & ~ignored_mods) ==
6878 (kev->state & ~ignored_mods)) {
6879 compose_send_cb(compose, 0, NULL);
6887 static void compose_check_all(Compose *compose)
6889 if (compose->gtkpspell)
6890 gtkpspell_check_all(compose->gtkpspell);
6893 static void compose_highlight_all(Compose *compose)
6895 if (compose->gtkpspell)
6896 gtkpspell_highlight_all(compose->gtkpspell);
6899 static void compose_check_backwards(Compose *compose)
6901 if (compose->gtkpspell)
6902 gtkpspell_check_backwards(compose->gtkpspell);
6904 GtkItemFactory *ifactory;
6905 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6906 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6907 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6911 static void compose_check_forwards_go(Compose *compose)
6913 if (compose->gtkpspell)
6914 gtkpspell_check_forwards_go(compose->gtkpspell);
6916 GtkItemFactory *ifactory;
6917 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6918 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6919 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6924 static void set_toolbar_style(Compose *compose)
6926 switch (prefs_common.toolbar_style) {
6928 gtk_widget_hide(compose->handlebox);
6931 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6935 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6939 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
6944 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
6945 gtk_widget_show(compose->handlebox);
6946 gtk_widget_queue_resize(compose->handlebox);