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"
87 #include "prefs_actions.h"
90 #include "procheader.h"
92 #include "statusbar.h"
99 #include "alertpanel.h"
100 #include "manage_window.h"
101 #include "gtkshruler.h"
103 #include "addr_compl.h"
104 #include "quote_fmt.h"
105 #include "template.h"
107 #include "foldersel.h"
111 # include "rfc2015.h"
121 #define N_ATTACH_COLS 3
125 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
126 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
127 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
128 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
129 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
130 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
131 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
132 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
133 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
134 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
135 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
136 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
137 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
138 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
139 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
140 } ComposeCallGtkSTextAction;
144 PRIORITY_HIGHEST = 1,
151 #define B64_LINE_SIZE 57
152 #define B64_BUFFSIZE 77
154 #define MAX_REFERENCES_LEN 999
156 static GdkColor quote_color = {0, 0, 0, 0xbfff};
158 static GList *compose_list = NULL;
160 Compose *compose_generic_new (PrefsAccount *account,
163 GPtrArray *attach_files);
165 static Compose *compose_create (PrefsAccount *account,
167 static void compose_toolbar_create (Compose *compose,
168 GtkWidget *container);
169 static void compose_toolbar_update (Compose *compose);
170 static void compose_toolbar_set_sensitive (Compose *compose,
173 static GtkWidget *compose_account_option_menu_create
175 static void compose_set_template_menu (Compose *compose);
176 static void compose_template_apply (Compose *compose,
179 static void compose_destroy (Compose *compose);
181 static void compose_entries_set (Compose *compose,
182 const gchar *mailto);
183 static gint compose_parse_header (Compose *compose,
185 static gchar *compose_parse_references (const gchar *ref,
188 static gchar *compose_quote_fmt (Compose *compose,
194 static void compose_reply_set_entry (Compose *compose,
200 followup_and_reply_to);
201 static void compose_reedit_set_entry (Compose *compose,
203 static void compose_insert_sig (Compose *compose);
204 static void compose_insert_file (Compose *compose,
206 static void compose_attach_append (Compose *compose,
209 const gchar *content_type);
210 static void compose_attach_parts (Compose *compose,
212 static void compose_wrap_line (Compose *compose);
213 static void compose_wrap_line_all (Compose *compose);
214 static void compose_wrap_line_all_full (Compose *compose,
216 static void compose_set_title (Compose *compose);
217 static void compose_select_account (Compose *compose,
218 PrefsAccount *account);
220 static PrefsAccount *compose_current_mail_account(void);
221 /* static gint compose_send (Compose *compose); */
222 static gboolean compose_check_for_valid_recipient
224 static gboolean compose_check_entries (Compose *compose,
225 gboolean check_subject);
226 static gint compose_write_to_file (Compose *compose,
229 static gint compose_write_body_to_file (Compose *compose,
231 static gint compose_remove_reedit_target (Compose *compose);
232 void compose_remove_draft (Compose *compose);
233 static gint compose_queue (Compose *compose,
236 static gint compose_queue_sub (Compose *compose,
239 gboolean check_subject);
240 static void compose_write_attach (Compose *compose,
242 static gint compose_write_headers (Compose *compose,
244 const gchar *charset,
245 EncodingType encoding,
248 static void compose_convert_header (gchar *dest,
252 static void compose_generate_msgid (Compose *compose,
256 static void compose_attach_info_free (AttachInfo *ainfo);
257 static void compose_attach_remove_selected (Compose *compose);
259 static void compose_attach_property (Compose *compose);
260 static void compose_attach_property_create (gboolean *cancelled);
261 static void attach_property_ok (GtkWidget *widget,
262 gboolean *cancelled);
263 static void attach_property_cancel (GtkWidget *widget,
264 gboolean *cancelled);
265 static gint attach_property_delete_event (GtkWidget *widget,
267 gboolean *cancelled);
268 static void attach_property_key_pressed (GtkWidget *widget,
270 gboolean *cancelled);
272 static void compose_exec_ext_editor (Compose *compose);
273 static gint compose_exec_ext_editor_real (const gchar *file);
274 static gboolean compose_ext_editor_kill (Compose *compose);
275 static void compose_input_cb (gpointer data,
277 GdkInputCondition condition);
278 static void compose_set_ext_editor_sensitive (Compose *compose,
281 static void compose_undo_state_changed (UndoMain *undostruct,
286 static gint calc_cursor_xpos (GtkSText *text,
290 static void compose_create_header_entry (Compose *compose);
291 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
292 static void compose_update_priority_menu_item(Compose * compose);
294 /* callback functions */
296 static gboolean compose_edit_size_alloc (GtkEditable *widget,
297 GtkAllocation *allocation,
298 GtkSHRuler *shruler);
300 static void toolbar_send_cb (GtkWidget *widget,
302 static void toolbar_send_later_cb (GtkWidget *widget,
304 static void toolbar_draft_cb (GtkWidget *widget,
306 static void toolbar_insert_cb (GtkWidget *widget,
308 static void toolbar_attach_cb (GtkWidget *widget,
310 static void toolbar_sig_cb (GtkWidget *widget,
312 static void toolbar_ext_editor_cb (GtkWidget *widget,
314 static void toolbar_linewrap_cb (GtkWidget *widget,
316 static void toolbar_address_cb (GtkWidget *widget,
318 static void toolbar_compose_buttons_cb (GtkWidget *widget,
321 static void account_activated (GtkMenuItem *menuitem,
324 static void attach_selected (GtkCList *clist,
329 static void attach_button_pressed (GtkWidget *widget,
330 GdkEventButton *event,
332 static void attach_key_pressed (GtkWidget *widget,
336 static void compose_send_cb (gpointer data,
339 static void compose_send_later_cb (gpointer data,
343 static void compose_draft_cb (gpointer data,
347 static void compose_attach_cb (gpointer data,
350 static void compose_insert_file_cb (gpointer data,
354 static void compose_close_cb (gpointer data,
358 static void compose_address_cb (gpointer data,
361 static void compose_template_activate_cb(GtkWidget *widget,
364 static void compose_ext_editor_cb (gpointer data,
368 static gint compose_delete_cb (GtkWidget *widget,
371 static void compose_destroy_cb (GtkWidget *widget,
374 static void compose_undo_cb (Compose *compose);
375 static void compose_redo_cb (Compose *compose);
376 static void compose_cut_cb (Compose *compose);
377 static void compose_copy_cb (Compose *compose);
378 static void compose_paste_cb (Compose *compose);
379 static void compose_paste_as_quote_cb (Compose *compose);
380 static void compose_allsel_cb (Compose *compose);
382 static void compose_gtk_stext_action_cb (Compose *compose,
383 ComposeCallGtkSTextAction action);
385 static void compose_grab_focus_cb (GtkWidget *widget,
388 static void compose_changed_cb (GtkEditable *editable,
390 static void compose_button_press_cb (GtkWidget *widget,
391 GdkEventButton *event,
394 static void compose_key_press_cb (GtkWidget *widget,
400 static void compose_toggle_to_cb (gpointer data,
403 static void compose_toggle_cc_cb (gpointer data,
406 static void compose_toggle_bcc_cb (gpointer data,
409 static void compose_toggle_replyto_cb (gpointer data,
412 static void compose_toggle_followupto_cb(gpointer data,
415 static void compose_toggle_attach_cb (gpointer data,
419 static void compose_toggle_ruler_cb (gpointer data,
423 static void compose_toggle_sign_cb (gpointer data,
426 static void compose_toggle_encrypt_cb (gpointer data,
429 static void compose_set_gnupg_mode_cb (gpointer data,
432 static void compose_update_gnupg_mode_menu_item(Compose * compose);
433 static void activate_gnupg_mode (Compose *compose,
434 PrefsAccount *account);
436 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
438 static void compose_set_priority_cb (gpointer data,
442 static void compose_attach_drag_received_cb (GtkWidget *widget,
443 GdkDragContext *drag_context,
446 GtkSelectionData *data,
450 static void compose_insert_drag_received_cb (GtkWidget *widget,
451 GdkDragContext *drag_context,
454 GtkSelectionData *data,
460 static void to_activated (GtkWidget *widget,
462 static void newsgroups_activated (GtkWidget *widget,
464 static void cc_activated (GtkWidget *widget,
466 static void bcc_activated (GtkWidget *widget,
468 static void replyto_activated (GtkWidget *widget,
470 static void followupto_activated (GtkWidget *widget,
472 static void subject_activated (GtkWidget *widget,
476 static void text_activated (GtkWidget *widget,
478 static void text_inserted (GtkWidget *widget,
483 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
484 gboolean to_all, gboolean to_ml,
485 gboolean ignore_replyto,
486 gboolean followup_and_reply_to,
489 void compose_headerentry_changed_cb (GtkWidget *entry,
490 ComposeHeaderEntry *headerentry);
491 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
493 ComposeHeaderEntry *headerentry);
495 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
498 static void compose_check_all (Compose *compose);
499 static void compose_highlight_all (Compose *compose);
500 static void compose_check_backwards (Compose *compose);
501 static void compose_check_forwards_go (Compose *compose);
504 static gboolean compose_send_control_enter (Compose *compose);
506 static GtkItemFactoryEntry compose_popup_entries[] =
508 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
509 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
510 {N_("/---"), NULL, NULL, 0, "<Separator>"},
511 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
514 static GtkItemFactoryEntry compose_entries[] =
516 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
517 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
518 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
519 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
520 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
521 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
523 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
524 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
525 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
526 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
527 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
528 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
529 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
530 {N_("/_Edit/Paste as _quotation"),
531 NULL, compose_paste_as_quote_cb, 0, NULL},
532 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
533 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
534 {N_("/_Edit/A_dvanced/Move a character backward"),
536 compose_gtk_stext_action_cb,
537 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
539 {N_("/_Edit/A_dvanced/Move a character forward"),
541 compose_gtk_stext_action_cb,
542 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
544 {N_("/_Edit/A_dvanced/Move a word backward"),
546 compose_gtk_stext_action_cb,
547 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
549 {N_("/_Edit/A_dvanced/Move a word forward"),
551 compose_gtk_stext_action_cb,
552 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
554 {N_("/_Edit/A_dvanced/Move to beginning of line"),
555 NULL, /* "<control>A" */
556 compose_gtk_stext_action_cb,
557 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
559 {N_("/_Edit/A_dvanced/Move to end of line"),
561 compose_gtk_stext_action_cb,
562 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
564 {N_("/_Edit/A_dvanced/Move to previous line"),
566 compose_gtk_stext_action_cb,
567 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
569 {N_("/_Edit/A_dvanced/Move to next line"),
571 compose_gtk_stext_action_cb,
572 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
574 {N_("/_Edit/A_dvanced/Delete a character backward"),
576 compose_gtk_stext_action_cb,
577 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
579 {N_("/_Edit/A_dvanced/Delete a character forward"),
581 compose_gtk_stext_action_cb,
582 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
584 {N_("/_Edit/A_dvanced/Delete a word backward"),
585 NULL, /* "<control>W" */
586 compose_gtk_stext_action_cb,
587 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
589 {N_("/_Edit/A_dvanced/Delete a word forward"),
590 NULL, /* "<alt>D", */
591 compose_gtk_stext_action_cb,
592 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
594 {N_("/_Edit/A_dvanced/Delete line"),
596 compose_gtk_stext_action_cb,
597 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
599 {N_("/_Edit/A_dvanced/Delete entire line"),
601 compose_gtk_stext_action_cb,
602 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
604 {N_("/_Edit/A_dvanced/Delete to end of line"),
606 compose_gtk_stext_action_cb,
607 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
609 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
610 {N_("/_Edit/_Wrap current paragraph"),
611 "<control>L", compose_wrap_line, 0, NULL},
612 {N_("/_Edit/Wrap all long _lines"),
613 "<control><alt>L", compose_wrap_line_all, 0, NULL},
614 {N_("/_Edit/Edit with e_xternal editor"),
615 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
617 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
618 {N_("/_Spelling/_Check all or check selection"),
619 NULL, compose_check_all, 0, NULL},
620 {N_("/_Spelling/_Highlight all misspelled words"),
621 NULL, compose_highlight_all, 0, NULL},
622 {N_("/_Spelling/Check _backwards misspelled word"),
623 NULL, compose_check_backwards , 0, NULL},
624 {N_("/_Spelling/_Forward to next misspelled word"),
625 NULL, compose_check_forwards_go, 0, NULL},
626 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
627 {N_("/_Spelling/_Spelling Configuration"),
628 NULL, NULL, 0, "<Branch>"},
630 #if 0 /* NEW COMPOSE GUI */
631 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
632 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
633 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
634 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
635 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
636 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
637 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
638 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
639 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
640 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
641 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
643 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
644 {N_("/_Message/_Send"), "<control>Return",
645 compose_send_cb, 0, NULL},
646 {N_("/_Message/Send _later"), "<shift><control>S",
647 compose_send_later_cb, 0, NULL},
648 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
649 {N_("/_Message/Save to _draft folder"),
650 "<shift><control>D", compose_draft_cb, 0, NULL},
651 {N_("/_Message/Save and _keep editing"),
652 "<control>S", compose_draft_cb, 1, NULL},
653 #if 0 /* NEW COMPOSE GUI */
654 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
655 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
656 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
657 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
658 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
659 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
660 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
661 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
662 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
665 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
666 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
667 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
668 {N_("/_Message/Mode/MIME"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_DETACH, "<RadioItem>"},
669 {N_("/_Message/Mode/Inline"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_INLINE, "/Message/Mode/MIME"},
670 #endif /* USE_GPGME */
671 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
672 {N_("/_Message/_Priority"), NULL, NULL, 0, "<Branch>"},
673 {N_("/_Message/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
674 {N_("/_Message/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
675 {N_("/_Message/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
676 {N_("/_Message/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
677 {N_("/_Message/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
678 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
679 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
680 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
681 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
682 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
683 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
684 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
685 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
686 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
689 static GtkTargetEntry compose_mime_types[] =
691 {"text/uri-list", 0, 0}
694 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
695 GPtrArray *attach_files)
697 return compose_generic_new(account, mailto, NULL, attach_files);
700 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
702 return compose_generic_new(account, NULL, item, NULL);
705 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
706 GPtrArray *attach_files)
710 GtkItemFactory *ifactory;
711 gboolean grab_focus_on_last = TRUE;
713 if (item && item->prefs && item->prefs->enable_default_account)
714 account = account_find_from_id(item->prefs->default_account);
716 if (!account) account = cur_account;
717 g_return_val_if_fail(account != NULL, NULL);
719 compose = compose_create(account, COMPOSE_NEW);
720 ifactory = gtk_item_factory_from_widget(compose->menubar);
722 compose->replyinfo = NULL;
724 text = GTK_STEXT(compose->text);
725 gtk_stext_freeze(text);
727 if (prefs_common.auto_sig)
728 compose_insert_sig(compose);
729 gtk_editable_set_position(GTK_EDITABLE(text), 0);
730 gtk_stext_set_point(text, 0);
732 gtk_stext_thaw(text);
734 if (account->protocol != A_NNTP) {
735 if (mailto && *mailto != '\0') {
736 compose_entries_set(compose, mailto);
738 } else if (item && item->prefs->enable_default_to) {
739 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
740 compose_entry_select(compose, item->prefs->default_to);
741 grab_focus_on_last = FALSE;
743 if (item && item->ret_rcpt) {
744 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
748 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
751 * CLAWS: just don't allow return receipt request, even if the user
752 * may want to send an email. simple but foolproof.
754 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
761 for (i = 0; i < attach_files->len; i++) {
762 file = g_ptr_array_index(attach_files, i);
763 compose_attach_append(compose, file, file, NULL);
767 compose_show_first_last_header(compose, TRUE);
769 /* Set save folder */
770 if (item && item->prefs && item->prefs->save_copy_to_folder) {
771 gchar *folderidentifier;
773 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
774 folderidentifier = folder_item_get_identifier(item);
775 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
776 g_free(folderidentifier);
779 /* Grab focus on last header only if no default_to was set */
780 if (grab_focus_on_last)
781 gtk_widget_grab_focus(compose->header_last->entry);
783 if (prefs_common.auto_exteditor)
784 compose_exec_ext_editor(compose);
790 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
791 const gchar *followupto, gchar * to)
795 if (!account) account = cur_account;
796 g_return_val_if_fail(account != NULL, NULL);
797 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
799 compose = compose_create(account, COMPOSE_NEW);
801 if (prefs_common.auto_sig)
802 compose_insert_sig(compose);
803 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
804 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
806 compose_entry_append(compose, to, COMPOSE_TO);
807 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
808 gtk_widget_grab_focus(compose->subject_entry);
814 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
815 gboolean to_ml, gboolean ignore_replyto,
818 compose_generic_reply(msginfo, quote, to_all, to_ml,
819 ignore_replyto, FALSE, body);
822 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
824 gboolean ignore_replyto,
827 compose_generic_reply(msginfo, quote, to_all, FALSE,
828 ignore_replyto, TRUE, body);
831 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
832 gboolean to_all, gboolean to_ml,
833 gboolean ignore_replyto,
834 gboolean followup_and_reply_to,
838 PrefsAccount *account;
839 PrefsAccount *reply_account;
842 g_return_if_fail(msginfo != NULL);
843 g_return_if_fail(msginfo->folder != NULL);
846 /* select the account set in folderitem's property (if enabled) */
847 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
848 account = account_find_from_id(msginfo->folder->prefs->default_account);
850 /* select the account for the whole folder (IMAP / NNTP) */
852 /* FIXME: this is not right, because folder may be nested. we should
853 * ascend the tree until we find a parent with proper account
855 account = msginfo->folder->folder->account;
857 /* select account by to: and cc: header if enabled */
858 if (prefs_common.reply_account_autosel) {
859 if (!account && msginfo->to) {
861 Xstrdup_a(to, msginfo->to, return);
863 account = account_find_from_address(to);
867 if (!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
869 account = account_find_from_address(cc);
874 /* select current account */
875 if (!account) account = cur_account;
876 g_return_if_fail(account != NULL);
878 if (ignore_replyto && account->protocol == A_NNTP &&
879 !followup_and_reply_to) {
881 account_find_from_address(account->address);
883 reply_account = compose_current_mail_account();
887 reply_account = account;
889 compose = compose_create(account, COMPOSE_REPLY);
891 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
892 if (!compose->replyinfo)
893 compose->replyinfo = procmsg_msginfo_copy(msginfo);
895 if (msginfo->folder && msginfo->folder->ret_rcpt) {
896 GtkItemFactory *ifactory;
898 ifactory = gtk_item_factory_from_widget(compose->menubar);
899 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
902 /* Set save folder */
903 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
904 gchar *folderidentifier;
906 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
907 folderidentifier = folder_item_get_identifier(msginfo->folder);
908 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
909 g_free(folderidentifier);
912 if (compose_parse_header(compose, msginfo) < 0) return;
913 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
914 ignore_replyto, followup_and_reply_to);
915 compose_show_first_last_header(compose, TRUE);
917 text = GTK_STEXT(compose->text);
918 gtk_stext_freeze(text);
924 if (prefs_common.quotemark && *prefs_common.quotemark)
925 qmark = prefs_common.quotemark;
929 quote_str = compose_quote_fmt(compose, compose->replyinfo,
930 prefs_common.quotefmt,
934 if (prefs_common.auto_sig)
935 compose_insert_sig(compose);
937 if (quote && prefs_common.linewrap_quote)
938 compose_wrap_line_all(compose);
940 gtk_editable_set_position(GTK_EDITABLE(text), 0);
941 gtk_stext_set_point(text, 0);
943 gtk_stext_thaw(text);
944 gtk_widget_grab_focus(compose->text);
946 if (prefs_common.auto_exteditor)
947 compose_exec_ext_editor(compose);
950 #define INSERT_FW_HEADER(var, hdr) \
951 if (msginfo->var && *msginfo->var) { \
952 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
953 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
954 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
957 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
958 gboolean as_attach, const gchar *body)
963 g_return_val_if_fail(msginfo != NULL, NULL);
964 g_return_val_if_fail(msginfo->folder != NULL, NULL);
966 if (msginfo->folder->prefs->enable_default_account)
967 account = account_find_from_id(msginfo->folder->prefs->default_account);
969 account = msginfo->folder->folder->account;
970 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
972 Xstrdup_a(to, msginfo->to, return NULL);
974 account = account_find_from_address(to);
977 if (!account && prefs_common.forward_account_autosel) {
979 if (!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
981 account = account_find_from_address(cc);
985 if (account == NULL) {
986 account = cur_account;
988 account = msginfo->folder->folder->account;
989 if (!account) account = cur_account;
992 g_return_val_if_fail(account != NULL, NULL);
994 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
995 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
996 if (MSG_IS_IMAP(msginfo->flags))
997 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
999 compose = compose_create(account, COMPOSE_FORWARD);
1001 if (msginfo->subject && *msginfo->subject) {
1002 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1003 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1007 text = GTK_STEXT(compose->text);
1008 gtk_stext_freeze(text);
1014 msgfile = procmsg_get_message_file_path(msginfo);
1015 if (!is_file_exist(msgfile))
1016 g_warning(_("%s: file not exist\n"), msgfile);
1018 compose_attach_append(compose, msgfile, msgfile,
1025 MsgInfo *full_msginfo;
1027 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1029 full_msginfo = procmsg_msginfo_copy(msginfo);
1031 if (prefs_common.fw_quotemark &&
1032 *prefs_common.fw_quotemark)
1033 qmark = prefs_common.fw_quotemark;
1037 quote_str = compose_quote_fmt(compose, full_msginfo,
1038 prefs_common.fw_quotefmt,
1040 compose_attach_parts(compose, msginfo);
1042 procmsg_msginfo_free(full_msginfo);
1045 if (prefs_common.auto_sig)
1046 compose_insert_sig(compose);
1048 if (prefs_common.linewrap_quote)
1049 compose_wrap_line_all(compose);
1051 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1052 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1054 gtk_stext_thaw(text);
1055 #if 0 /* NEW COMPOSE GUI */
1056 if (account->protocol != A_NNTP)
1057 gtk_widget_grab_focus(compose->to_entry);
1059 gtk_widget_grab_focus(compose->newsgroups_entry);
1061 gtk_widget_grab_focus(compose->header_last->entry);
1063 if (prefs_common.auto_exteditor)
1064 compose_exec_ext_editor(compose);
1067 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1068 gchar *folderidentifier;
1070 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1071 folderidentifier = folder_item_get_identifier(msginfo->folder);
1072 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1073 g_free(folderidentifier);
1079 #undef INSERT_FW_HEADER
1081 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1088 g_return_val_if_fail(msginfo_list != NULL, NULL);
1090 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1091 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1095 if (account == NULL) {
1096 account = cur_account;
1098 account = msginfo->folder->folder->account;
1099 if (!account) account = cur_account;
1102 g_return_val_if_fail(account != NULL, NULL);
1104 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1105 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1106 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1109 compose = compose_create(account, COMPOSE_FORWARD);
1111 text = GTK_STEXT(compose->text);
1112 gtk_stext_freeze(text);
1114 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1115 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1116 if (!is_file_exist(msgfile))
1117 g_warning(_("%s: file not exist\n"), msgfile);
1119 compose_attach_append(compose, msgfile, msgfile,
1124 if (prefs_common.auto_sig)
1125 compose_insert_sig(compose);
1127 if (prefs_common.linewrap_quote)
1128 compose_wrap_line_all(compose);
1130 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1131 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1133 gtk_stext_thaw(text);
1134 gtk_widget_grab_focus(compose->header_last->entry);
1136 #if 0 /* NEW COMPOSE GUI */
1137 if (account->protocol != A_NNTP)
1138 gtk_widget_grab_focus(compose->to_entry);
1140 gtk_widget_grab_focus(compose->newsgroups_entry);
1146 void compose_reedit(MsgInfo *msginfo)
1149 PrefsAccount *account = NULL;
1152 gchar buf[BUFFSIZE];
1154 g_return_if_fail(msginfo != NULL);
1155 g_return_if_fail(msginfo->folder != NULL);
1157 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1158 gchar queueheader_buf[BUFFSIZE];
1161 /* Select Account from queue headers */
1162 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1163 sizeof(queueheader_buf), "H_X_SYLPHEED_ACCOUNT_ID:")) {
1164 id = atoi(&queueheader_buf[5]);
1165 account = account_find_from_id(id);
1167 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1168 sizeof(queueheader_buf), "NAID:")) {
1169 id = atoi(&queueheader_buf[5]);
1170 account = account_find_from_id(id);
1172 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1173 sizeof(queueheader_buf), "MAID:")) {
1174 id = atoi(&queueheader_buf[5]);
1175 account = account_find_from_id(id);
1177 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1178 sizeof(queueheader_buf), "S:")) {
1179 account = account_find_from_address(queueheader_buf);
1182 account = msginfo->folder->folder->account;
1184 if (!account && prefs_common.reedit_account_autosel) {
1185 gchar from[BUFFSIZE];
1186 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1187 extract_address(from);
1188 account = account_find_from_address(from);
1191 if (!account) account = cur_account;
1192 g_return_if_fail(account != NULL);
1194 compose = compose_create(account, COMPOSE_REEDIT);
1195 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1197 if (msginfo->folder->stype == F_QUEUE
1198 || msginfo->folder->stype == F_DRAFT) {
1199 gchar queueheader_buf[BUFFSIZE];
1201 /* Set message save folder */
1202 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1205 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1206 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1207 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1211 if (compose_parse_header(compose, msginfo) < 0) return;
1212 compose_reedit_set_entry(compose, msginfo);
1214 text = GTK_STEXT(compose->text);
1215 gtk_stext_freeze(text);
1217 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1218 g_warning(_("Can't get text part\n"));
1220 while (fgets(buf, sizeof(buf), fp) != NULL) {
1222 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1226 compose_attach_parts(compose, msginfo);
1228 gtk_stext_thaw(text);
1229 gtk_widget_grab_focus(compose->text);
1231 if (prefs_common.auto_exteditor)
1232 compose_exec_ext_editor(compose);
1235 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1239 GtkItemFactory *ifactory;
1241 g_return_val_if_fail(msginfo != NULL, NULL);
1244 account = cur_account;
1245 g_return_val_if_fail(account != NULL, NULL);
1247 compose = compose_create(account, COMPOSE_REDIRECT);
1248 ifactory = gtk_item_factory_from_widget(compose->menubar);
1250 compose->replyinfo = NULL;
1252 compose_show_first_last_header(compose, TRUE);
1254 gtk_widget_grab_focus(compose->header_last->entry);
1256 filename = procmsg_get_message_file(msginfo);
1257 if (filename == NULL)
1260 compose->redirect_filename = filename;
1262 compose_attach_parts(compose, msginfo);
1264 if (msginfo->subject)
1265 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1267 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1269 gtk_stext_freeze(GTK_STEXT(compose->text));
1270 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1271 gtk_editable_set_editable(GTK_EDITABLE(compose->text), FALSE);
1272 gtk_stext_thaw(GTK_STEXT(compose->text));
1274 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1275 menu_set_sensitive(ifactory, "/Add...", FALSE);
1276 menu_set_sensitive(ifactory, "/Remove", FALSE);
1277 menu_set_sensitive(ifactory, "/Property...", FALSE);
1279 ifactory = gtk_item_factory_from_widget(compose->menubar);
1280 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
1281 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
1282 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
1283 menu_set_sensitive(ifactory, "/Edit", FALSE);
1284 menu_set_sensitive(ifactory, "/Message/Save to draft folder", FALSE);
1285 menu_set_sensitive(ifactory, "/Message/Save and keep editing", FALSE);
1287 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
1288 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
1289 menu_set_sensitive(ifactory, "/Message/Mode/MIME", FALSE);
1290 menu_set_sensitive(ifactory, "/Message/Mode/Inline", FALSE);
1292 menu_set_sensitive(ifactory, "/Message/Priority", FALSE);
1293 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
1294 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1295 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1297 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1298 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1299 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1300 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1301 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1302 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, FALSE);
1307 GList *compose_get_compose_list(void)
1309 return compose_list;
1312 void compose_entry_append(Compose *compose, const gchar *address,
1313 ComposeEntryType type)
1317 if (!address || *address == '\0') return;
1319 #if 0 /* NEW COMPOSE GUI */
1322 entry = GTK_ENTRY(compose->cc_entry);
1325 entry = GTK_ENTRY(compose->bcc_entry);
1327 case COMPOSE_NEWSGROUPS:
1328 entry = GTK_ENTRY(compose->newsgroups_entry);
1332 entry = GTK_ENTRY(compose->to_entry);
1336 text = gtk_entry_get_text(entry);
1338 gtk_entry_append_text(entry, ", ");
1339 gtk_entry_append_text(entry, address);
1347 header = N_("Bcc:");
1349 case COMPOSE_REPLYTO:
1350 header = N_("Reply-To:");
1352 case COMPOSE_NEWSGROUPS:
1353 header = N_("Newsgroups:");
1355 case COMPOSE_FOLLOWUPTO:
1356 header = N_( "Followup-To:");
1363 header = prefs_common.trans_hdr ? gettext(header) : header;
1365 compose_add_header_entry(compose, header, (gchar *)address);
1368 void compose_entry_select (Compose *compose, const gchar *mailto)
1370 GSList *header_list;
1372 for (header_list = compose->header_list; header_list != NULL; header_list = header_list->next) {
1373 GtkEntry * entry = GTK_ENTRY(((ComposeHeaderEntry *)header_list->data)->entry);
1375 if (gtk_entry_get_text(entry) && !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1376 gtk_entry_select_region(entry, 0, -1);
1377 gtk_widget_grab_focus(GTK_WIDGET(entry));
1382 static void compose_entries_set(Compose *compose, const gchar *mailto)
1387 gchar *subject = NULL;
1390 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1393 compose_entry_append(compose, to, COMPOSE_TO);
1395 compose_entry_append(compose, cc, COMPOSE_CC);
1397 compose_entry_append(compose, bcc, COMPOSE_BCC);
1399 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1401 gtk_stext_insert(GTK_STEXT(compose->text),
1402 NULL, NULL, NULL, body, -1);
1403 gtk_stext_insert(GTK_STEXT(compose->text),
1404 NULL, NULL, NULL, "\n", 1);
1414 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1416 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1417 {"Cc:", NULL, FALSE},
1418 {"References:", NULL, FALSE},
1419 {"Bcc:", NULL, FALSE},
1420 {"Newsgroups:", NULL, FALSE},
1421 {"Followup-To:", NULL, FALSE},
1422 {"List-Post:", NULL, FALSE},
1423 {"X-Priority:", NULL, FALSE},
1424 {NULL, NULL, FALSE}};
1440 g_return_val_if_fail(msginfo != NULL, -1);
1442 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1443 procheader_get_header_fields(fp, hentry);
1446 if (hentry[H_REPLY_TO].body != NULL) {
1447 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1448 compose->replyto = hentry[H_REPLY_TO].body;
1449 hentry[H_REPLY_TO].body = NULL;
1451 if (hentry[H_CC].body != NULL) {
1452 conv_unmime_header_overwrite(hentry[H_CC].body);
1453 compose->cc = hentry[H_CC].body;
1454 hentry[H_CC].body = NULL;
1456 if (hentry[H_REFERENCES].body != NULL) {
1457 if (compose->mode == COMPOSE_REEDIT)
1458 compose->references = hentry[H_REFERENCES].body;
1460 compose->references = compose_parse_references
1461 (hentry[H_REFERENCES].body, msginfo->msgid);
1462 g_free(hentry[H_REFERENCES].body);
1464 hentry[H_REFERENCES].body = NULL;
1466 if (hentry[H_BCC].body != NULL) {
1467 if (compose->mode == COMPOSE_REEDIT) {
1468 conv_unmime_header_overwrite(hentry[H_BCC].body);
1469 compose->bcc = hentry[H_BCC].body;
1471 g_free(hentry[H_BCC].body);
1472 hentry[H_BCC].body = NULL;
1474 if (hentry[H_NEWSGROUPS].body != NULL) {
1475 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1476 hentry[H_NEWSGROUPS].body = NULL;
1478 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1479 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1480 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1481 hentry[H_FOLLOWUP_TO].body = NULL;
1483 if (hentry[H_LIST_POST].body != NULL) {
1486 extract_address(hentry[H_LIST_POST].body);
1487 if (hentry[H_LIST_POST].body[0] != '\0') {
1488 scan_mailto_url(hentry[H_LIST_POST].body,
1489 &to, NULL, NULL, NULL, NULL);
1491 g_free(compose->ml_post);
1492 compose->ml_post = to;
1495 g_free(hentry[H_LIST_POST].body);
1496 hentry[H_LIST_POST].body = NULL;
1499 /* CLAWS - X-Priority */
1500 if (compose->mode == COMPOSE_REEDIT)
1501 if (hentry[H_X_PRIORITY].body != NULL) {
1504 priority = atoi(hentry[H_X_PRIORITY].body);
1505 g_free(hentry[H_X_PRIORITY].body);
1507 hentry[H_X_PRIORITY].body = NULL;
1509 if (priority < PRIORITY_HIGHEST ||
1510 priority > PRIORITY_LOWEST)
1511 priority = PRIORITY_NORMAL;
1513 compose->priority = priority;
1516 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1517 compose->inreplyto = g_strdup(msginfo->inreplyto);
1518 else if (compose->mode != COMPOSE_REEDIT &&
1519 msginfo->msgid && *msginfo->msgid) {
1520 compose->inreplyto = g_strdup(msginfo->msgid);
1522 if (!compose->references) {
1523 if (msginfo->inreplyto && *msginfo->inreplyto)
1524 compose->references =
1525 g_strdup_printf("<%s>\n\t<%s>",
1529 compose->references =
1530 g_strconcat("<", msginfo->msgid, ">",
1538 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1540 GSList *ref_id_list, *cur;
1544 ref_id_list = references_list_append(NULL, ref);
1545 if (!ref_id_list) return NULL;
1546 if (msgid && *msgid)
1547 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1552 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1553 /* "<" + Message-ID + ">" + CR+LF+TAB */
1554 len += strlen((gchar *)cur->data) + 5;
1556 if (len > MAX_REFERENCES_LEN) {
1557 /* remove second message-ID */
1558 if (ref_id_list && ref_id_list->next &&
1559 ref_id_list->next->next) {
1560 g_free(ref_id_list->next->data);
1561 ref_id_list = g_slist_remove
1562 (ref_id_list, ref_id_list->next->data);
1564 slist_free_strings(ref_id_list);
1565 g_slist_free(ref_id_list);
1572 new_ref = g_string_new("");
1573 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1574 if (new_ref->len > 0)
1575 g_string_append(new_ref, "\n\t");
1576 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1579 slist_free_strings(ref_id_list);
1580 g_slist_free(ref_id_list);
1582 new_ref_str = new_ref->str;
1583 g_string_free(new_ref, FALSE);
1588 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1589 const gchar *fmt, const gchar *qmark,
1592 GtkSText *text = GTK_STEXT(compose->text);
1593 static MsgInfo dummyinfo;
1594 gchar *quote_str = NULL;
1600 msginfo = &dummyinfo;
1602 if (qmark != NULL) {
1603 quote_fmt_init(msginfo, NULL, NULL);
1604 quote_fmt_scan_string(qmark);
1607 buf = quote_fmt_get_buffer();
1609 alertpanel_error(_("Quote mark format error."));
1611 Xstrdup_a(quote_str, buf, return NULL)
1614 if (fmt && *fmt != '\0') {
1615 quote_fmt_init(msginfo, quote_str, body);
1616 quote_fmt_scan_string(fmt);
1619 buf = quote_fmt_get_buffer();
1621 alertpanel_error(_("Message reply/forward format error."));
1627 gtk_stext_freeze(text);
1629 for (p = buf; *p != '\0'; ) {
1630 lastp = strchr(p, '\n');
1631 len = lastp ? lastp - p + 1 : -1;
1632 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1639 gtk_stext_thaw(text);
1644 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1645 gboolean to_all, gboolean to_ml,
1646 gboolean ignore_replyto,
1647 gboolean followup_and_reply_to)
1649 GSList *cc_list = NULL;
1652 gchar *replyto = NULL;
1653 GHashTable *to_table;
1655 g_return_if_fail(compose->account != NULL);
1656 g_return_if_fail(msginfo != NULL);
1658 if (compose->account->protocol != A_NNTP || followup_and_reply_to) {
1659 if (!compose->replyto && to_ml && compose->ml_post
1660 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1661 compose_entry_append(compose,
1664 else if (!(to_all || ignore_replyto)
1666 && msginfo->folder->prefs->enable_default_reply_to) {
1667 compose_entry_append(compose,
1668 msginfo->folder->prefs->default_reply_to,
1671 compose_entry_append(compose,
1672 (compose->replyto && !ignore_replyto)
1674 : msginfo->from ? msginfo->from : "",
1678 compose_entry_append
1679 (compose, msginfo->from ? msginfo->from : "",
1682 if (compose->followup_to && !strncmp(compose->followup_to, "poster", 6)) {
1683 compose_entry_append
1685 ((compose->replyto && !ignore_replyto)
1687 : msginfo->from ? msginfo->from : ""),
1690 compose_entry_append
1692 compose->followup_to ? compose->followup_to
1693 : compose->newsgroups ? compose->newsgroups
1695 COMPOSE_NEWSGROUPS);
1700 if (msginfo->subject && *msginfo->subject) {
1701 gchar *buf, *buf2, *p;
1703 buf = g_strdup(msginfo->subject);
1704 while (!strncasecmp(buf, "Re:", 3)) {
1706 while (isspace(*p)) p++;
1707 memmove(buf, p, strlen(p) + 1);
1710 buf2 = g_strdup_printf("Re: %s", buf);
1711 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1715 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1717 if (to_ml && compose->ml_post) return;
1718 if (!to_all || compose->account->protocol == A_NNTP) return;
1720 if (compose->replyto) {
1721 Xstrdup_a(replyto, compose->replyto, return);
1722 extract_address(replyto);
1724 if (msginfo->from) {
1725 Xstrdup_a(from, msginfo->from, return);
1726 extract_address(from);
1729 if (replyto && from)
1730 cc_list = address_list_append(cc_list, from);
1731 cc_list = address_list_append(cc_list, msginfo->to);
1732 cc_list = address_list_append(cc_list, compose->cc);
1734 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1736 g_hash_table_insert(to_table, replyto, GINT_TO_POINTER(1));
1737 if (compose->account)
1738 g_hash_table_insert(to_table, compose->account->address,
1739 GINT_TO_POINTER(1));
1741 /* remove address on To: and that of current account */
1742 for (cur = cc_list; cur != NULL; ) {
1743 GSList *next = cur->next;
1745 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1746 cc_list = g_slist_remove(cc_list, cur->data);
1748 g_hash_table_insert(to_table, cur->data, cur);
1752 g_hash_table_destroy(to_table);
1755 for (cur = cc_list; cur != NULL; cur = cur->next)
1756 compose_entry_append(compose, (gchar *)cur->data,
1758 slist_free_strings(cc_list);
1759 g_slist_free(cc_list);
1763 #define SET_ENTRY(entry, str) \
1766 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1769 #define SET_ADDRESS(type, str) \
1772 compose_entry_append(compose, str, type); \
1775 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1777 g_return_if_fail(msginfo != NULL);
1779 SET_ENTRY(subject_entry, msginfo->subject);
1780 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1781 SET_ADDRESS(COMPOSE_CC, compose->cc);
1782 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1783 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1785 compose_update_priority_menu_item(compose);
1787 compose_update_gnupg_mode_menu_item(compose);
1789 compose_show_first_last_header(compose, TRUE);
1796 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1800 size_t buf_len = 128;
1802 if (strlen(sigfile) < 2)
1805 sigprg = popen(sigfile+1, "r");
1808 buf = g_malloc(buf_len);
1811 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1812 "Unable to insert signature (malloc failed)\n", -1);
1818 while (!feof(sigprg)) {
1819 bzero(buf, buf_len);
1820 fread(buf, buf_len-1, 1, sigprg);
1821 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1829 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1830 "Can't exec file: ", -1);
1831 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1836 static void compose_insert_sig(Compose *compose)
1840 if (compose->account && compose->account->sig_path)
1841 sigfile = g_strdup(compose->account->sig_path);
1843 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1844 DEFAULT_SIGNATURE, NULL);
1846 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1851 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1852 if (prefs_common.sig_sep) {
1853 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1854 prefs_common.sig_sep, -1);
1855 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1859 if (sigfile[0] == '|')
1860 compose_exec_sig(compose, sigfile);
1862 compose_insert_file(compose, sigfile);
1866 static void compose_insert_file(Compose *compose, const gchar *file)
1868 GtkSText *text = GTK_STEXT(compose->text);
1869 gchar buf[BUFFSIZE];
1873 g_return_if_fail(file != NULL);
1875 if ((fp = fopen(file, "rb")) == NULL) {
1876 FILE_OP_ERROR(file, "fopen");
1880 gtk_stext_freeze(text);
1882 while (fgets(buf, sizeof(buf), fp) != NULL) {
1883 /* strip <CR> if DOS/Windows file,
1884 replace <CR> with <LF> if Macintosh file. */
1887 if (len > 0 && buf[len - 1] != '\n') {
1889 if (buf[len] == '\r') buf[len] = '\n';
1891 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1894 gtk_stext_thaw(text);
1899 static void compose_attach_append(Compose *compose, const gchar *file,
1900 const gchar *filename,
1901 const gchar *content_type)
1904 gchar *text[N_ATTACH_COLS];
1909 if (!is_file_exist(file)) {
1910 g_warning(_("File %s doesn't exist\n"), file);
1913 if ((size = get_file_size(file)) < 0) {
1914 g_warning(_("Can't get file size of %s\n"), file);
1918 alertpanel_notice(_("File %s is empty."), file);
1921 if ((fp = fopen(file, "rb")) == NULL) {
1922 alertpanel_error(_("Can't read %s."), file);
1927 #if 0 /* NEW COMPOSE GUI */
1928 if (!compose->use_attach) {
1929 GtkItemFactory *ifactory;
1930 GtkWidget *menuitem;
1932 ifactory = gtk_item_factory_from_widget(compose->menubar);
1933 menuitem = gtk_item_factory_get_item(ifactory,
1934 "/View/Attachment");
1935 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1939 ainfo = g_new0(AttachInfo, 1);
1940 ainfo->file = g_strdup(file);
1943 ainfo->content_type = g_strdup(content_type);
1944 if (!strcasecmp(content_type, "message/rfc822")) {
1945 ainfo->encoding = ENC_7BIT;
1946 ainfo->name = g_strdup_printf
1948 g_basename(filename ? filename : file));
1950 if (!g_strncasecmp(content_type, "text", 4))
1952 procmime_get_encoding_for_file(file);
1954 ainfo->encoding = ENC_BASE64;
1955 ainfo->name = g_strdup
1956 (g_basename(filename ? filename : file));
1959 ainfo->content_type = procmime_get_mime_type(file);
1960 if (!ainfo->content_type) {
1961 ainfo->content_type =
1962 g_strdup("application/octet-stream");
1963 ainfo->encoding = ENC_BASE64;
1964 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
1965 ainfo->encoding = procmime_get_encoding_for_file(file);
1967 ainfo->encoding = ENC_BASE64;
1968 ainfo->name = g_strdup(g_basename(filename ? filename : file));
1972 text[COL_MIMETYPE] = ainfo->content_type;
1973 text[COL_SIZE] = to_human_readable(size);
1974 text[COL_NAME] = ainfo->name;
1976 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1977 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1980 #define IS_FIRST_PART_TEXT(info) \
1981 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
1982 info->mime_type == MIME_TEXT_ENRICHED) || \
1983 (info->mime_type == MIME_MULTIPART && info->content_type && \
1984 !strcasecmp(info->content_type, "multipart/alternative") && \
1985 (info->children && \
1986 (info->children->mime_type == MIME_TEXT || \
1987 info->children->mime_type == MIME_TEXT_HTML || \
1988 info->children->mime_type == MIME_TEXT_ENRICHED))))
1990 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
1997 mimeinfo = procmime_scan_message(msginfo);
1998 if (!mimeinfo) return;
2000 /* skip first text (presumably message body) */
2001 child = mimeinfo->children;
2002 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
2003 procmime_mimeinfo_free_all(mimeinfo);
2007 if (IS_FIRST_PART_TEXT(child))
2008 child = child->next;
2010 infile = procmsg_get_message_file_path(msginfo);
2012 while (child != NULL) {
2013 if (child->children || child->mime_type == MIME_MULTIPART) {
2014 child = procmime_mimeinfo_next(child);
2017 if(child->parent && child->parent->parent
2018 && !strcasecmp(child->parent->parent->content_type, "multipart/signed")
2019 && child->mime_type == MIME_TEXT) {
2020 /* this is the main text part of a signed message */
2021 child = procmime_mimeinfo_next(child);
2024 outfile = procmime_get_tmp_file_name(child);
2025 if (procmime_get_part(outfile, infile, child) < 0)
2026 g_warning(_("Can't get the part of multipart message."));
2027 else if (compose->mode != COMPOSE_REEDIT || strcmp(child->content_type, "application/pgp-signature"))
2028 compose_attach_append
2030 child->filename ? child->filename : child->name,
2031 child->content_type);
2033 child = child->next;
2037 procmime_mimeinfo_free_all(mimeinfo);
2040 #undef IS_FIRST_PART_TEXT
2042 #define GET_CHAR(pos, buf, len) \
2044 if (text->use_wchar) \
2045 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2047 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2052 #define INDENT_CHARS ">|#"
2053 #define SPACE_CHARS " \t"
2055 static void compose_wrap_line(Compose *compose)
2057 GtkSText *text = GTK_STEXT(compose->text);
2058 gint ch_len, last_ch_len;
2059 gchar cbuf[MB_LEN_MAX], last_ch;
2063 gint p_start, p_end;
2064 gint line_pos, cur_pos;
2065 gint line_len, cur_len;
2067 gtk_stext_freeze(text);
2069 text_len = gtk_stext_get_length(text);
2071 /* check to see if the point is on the paragraph mark (empty line). */
2072 cur_pos = gtk_stext_get_point(text);
2073 GET_CHAR(cur_pos, cbuf, ch_len);
2074 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2076 goto compose_end; /* on the paragraph mark */
2077 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2078 if (ch_len == 1 && *cbuf == '\n')
2079 goto compose_end; /* on the paragraph mark */
2082 /* find paragraph start. */
2083 line_end = quoted = 0;
2084 for (p_start = cur_pos; p_start >= 0; --p_start) {
2085 GET_CHAR(p_start, cbuf, ch_len);
2086 if (ch_len == 1 && *cbuf == '\n') {
2088 goto compose_end; /* quoted part */
2096 && strchr(prefs_common.quote_chars, *cbuf))
2098 else if (ch_len != 1 || !isspace(*cbuf))
2107 /* find paragraph end. */
2109 for (p_end = cur_pos; p_end < text_len; p_end++) {
2110 GET_CHAR(p_end, cbuf, ch_len);
2111 if (ch_len == 1 && *cbuf == '\n') {
2118 if (line_end && ch_len == 1 &&
2119 strchr(prefs_common.quote_chars, *cbuf))
2120 goto compose_end; /* quoted part */
2125 if (p_end >= text_len)
2128 if (p_start >= p_end)
2131 line_len = cur_len = 0;
2135 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2138 GET_CHAR(cur_pos, cbuf, ch_len);
2145 if (ch_len == 1 && isspace(*cbuf))
2148 if (ch_len == 1 && *cbuf == '\n') {
2150 if (last_ch_len == 1 && !isspace(last_ch)) {
2151 if (cur_pos + 1 < p_end) {
2152 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2153 if (ch_len == 1 && !isspace(*cbuf))
2157 gtk_stext_set_point(text, cur_pos + 1);
2158 gtk_stext_backward_delete(text, 1);
2160 gtk_stext_set_point(text, cur_pos);
2161 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2171 last_ch_len = ch_len;
2175 line_pos = cur_pos + 1;
2176 line_len = cur_len + ch_len;
2179 if (cur_len + ch_len > prefs_common.linewrap_len &&
2183 GET_CHAR(line_pos - 1, cbuf, ch_len);
2184 if (ch_len == 1 && isspace(*cbuf)) {
2185 gtk_stext_set_point(text, line_pos);
2186 gtk_stext_backward_delete(text, 1);
2195 gtk_stext_set_point(text, line_pos);
2196 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2200 cur_len = cur_len - line_len + ch_len;
2206 line_pos = cur_pos + 1;
2207 line_len = cur_len + ch_len;
2213 gtk_stext_thaw(text);
2218 /* Darko: used when I debug wrapping */
2219 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2222 gchar cbuf[MB_LEN_MAX];
2224 printf("%d [", pos);
2225 for (i = pos; i < tlen; i++) {
2226 GET_CHAR(i, cbuf, clen);
2227 if (clen < 0) break;
2228 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2230 fwrite(cbuf, clen, 1, stdout);
2238 WAIT_FOR_INDENT_CHAR,
2239 WAIT_FOR_INDENT_CHAR_OR_SPACE
2242 /* return indent length, we allow:
2243 > followed by spaces/tabs
2244 | followed by spaces/tabs
2245 uppercase characters immediately followed by >,
2246 and the repeating sequences of the above */
2247 /* return indent length */
2248 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2251 guint i, ch_len, alnum_cnt = 0;
2252 IndentState state = WAIT_FOR_INDENT_CHAR;
2253 gchar cbuf[MB_LEN_MAX];
2257 for (i = start_pos; i < text_len; i++) {
2258 GET_CHAR(i, cbuf, ch_len);
2262 if (cbuf[0] == '\n')
2265 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2266 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2269 case WAIT_FOR_SPACE:
2270 if (is_space == FALSE)
2272 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2274 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2275 if (is_indent == FALSE && is_space == FALSE &&
2278 if (is_space == TRUE) {
2280 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2281 } else if (is_indent == TRUE) {
2283 state = WAIT_FOR_SPACE;
2286 state = WAIT_FOR_INDENT_CHAR;
2289 case WAIT_FOR_INDENT_CHAR:
2290 if (is_indent == FALSE && !isupper(cbuf[0]))
2292 if (is_indent == TRUE) {
2294 && !strchr(prefs_common.quote_chars, cbuf[0]))
2297 state = WAIT_FOR_SPACE;
2308 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2314 /* insert quotation string when line was wrapped */
2315 static guint ins_quote(GtkSText *text, guint indent_len,
2316 guint prev_line_pos, guint text_len,
2319 guint i, ins_len = 0;
2323 for (i = 0; i < indent_len; i++) {
2324 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2325 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2327 ins_len = indent_len;
2333 /* check if we should join the next line */
2334 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2335 guint prev_ilen, gboolean autowrap)
2337 guint indent_len, ch_len;
2338 gboolean do_join = FALSE;
2339 gchar cbuf[MB_LEN_MAX];
2341 indent_len = get_indent_length(text, start_pos, tlen);
2343 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2344 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2345 if (ch_len > 0 && (cbuf[0] != '\n'))
2352 static void compose_wrap_line_all(Compose *compose)
2354 compose_wrap_line_all_full(compose, FALSE);
2357 #define STEXT_FREEZE() \
2358 if (!frozen) { gtk_stext_freeze(text); frozen = TRUE; }
2360 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2362 GtkSText *text = GTK_STEXT(compose->text);
2364 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2365 gint line_len = 0, cur_len = 0;
2367 gboolean is_new_line = TRUE, do_delete = FALSE;
2369 gboolean linewrap_quote = TRUE;
2370 gboolean set_editable_pos = FALSE;
2371 gint editable_pos = 0;
2372 gboolean frozen = FALSE;
2373 guint linewrap_len = prefs_common.linewrap_len;
2374 gchar *qfmt = prefs_common.quotemark;
2375 gchar cbuf[MB_LEN_MAX];
2377 tlen = gtk_stext_get_length(text);
2379 for (; cur_pos < tlen; cur_pos++) {
2380 /* mark position of new line - needed for quotation wrap */
2383 i_len = get_indent_length(text, cur_pos, tlen);
2385 is_new_line = FALSE;
2388 g_print("new line i_len=%d p_pos=", i_len);
2389 dump_text(text, p_pos, tlen, 1);
2393 GET_CHAR(cur_pos, cbuf, ch_len);
2395 /* fix line length for tabs */
2396 if (ch_len == 1 && *cbuf == '\t') {
2397 guint tab_width = text->default_tab_width;
2398 guint tab_offset = line_len % tab_width;
2401 g_print("found tab at pos=%d line_len=%d ", cur_pos,
2405 line_len += tab_width - tab_offset - 1;
2409 printf("new_len=%d\n", line_len);
2413 /* we have encountered line break */
2414 if (ch_len == 1 && *cbuf == '\n') {
2416 gchar cb[MB_LEN_MAX];
2418 /* should we join the next line */
2419 if ((autowrap || i_len != cur_len) && do_delete &&
2421 (text, cur_pos + 1, tlen, i_len, autowrap))
2427 g_print("found CR at %d do_del is %d next line is ",
2428 cur_pos, do_delete);
2429 dump_text(text, cur_pos + 1, tlen, 1);
2432 /* skip delete if it is continuous URL */
2433 if (do_delete && (line_pos - p_pos <= i_len) &&
2434 gtkut_stext_is_uri_string(text, line_pos, tlen))
2438 g_print("l_len=%d wrap_len=%d do_del=%d\n",
2439 line_len, linewrap_len, do_delete);
2441 /* should we delete to perform smart wrapping */
2442 if (line_len < linewrap_len && do_delete) {
2444 /* get rid of newline */
2445 gtk_stext_set_point(text, cur_pos);
2446 gtk_stext_forward_delete(text, 1);
2449 /* if text starts with quote fmt or with
2450 indent string, delete them */
2453 ilen = gtkut_stext_str_compare_n
2454 (text, cur_pos, p_pos, i_len,
2457 gtk_stext_forward_delete
2463 GET_CHAR(cur_pos, cb, clen);
2465 /* insert space if it's alphanumeric */
2466 if ((cur_pos != line_pos) &&
2467 ((clen > 1) || isalnum(cb[0]))) {
2468 gtk_stext_insert(text, NULL, NULL,
2473 /* and start over with current line */
2474 cur_pos = p_pos - 1;
2476 line_len = cur_len = 0;
2480 g_print("after delete l_pos=");
2481 dump_text(text, line_pos, tlen, 1);
2486 /* mark new line beginning */
2487 line_pos = cur_pos + 1;
2488 line_len = cur_len = 0;
2499 /* possible line break */
2500 if (ch_len == 1 && isspace(*cbuf)) {
2501 line_pos = cur_pos + 1;
2502 line_len = cur_len + ch_len;
2505 /* are we over wrapping length set in preferences ? */
2506 if (cur_len + ch_len > linewrap_len) {
2510 g_print("should wrap cur_pos=%d ", cur_pos);
2511 dump_text(text, p_pos, tlen, 1);
2512 dump_text(text, line_pos, tlen, 1);
2514 /* force wrapping if it is one long word but not URL */
2515 if (line_pos - p_pos <= i_len)
2516 if (!gtkut_stext_is_uri_string
2517 (text, line_pos, tlen))
2518 line_pos = cur_pos - 1;
2520 g_print("new line_pos=%d\n", line_pos);
2523 GET_CHAR(line_pos - 1, cbuf, clen);
2525 /* if next character is space delete it */
2526 if (clen == 1 && isspace(*cbuf)) {
2527 if (p_pos + i_len != line_pos ||
2528 !gtkut_stext_is_uri_string
2529 (text, line_pos, tlen)) {
2531 /* workaround for correct cursor
2533 if (set_editable_pos == FALSE) {
2534 editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2535 if (editable_pos == line_pos)
2536 set_editable_pos = TRUE;
2538 gtk_stext_set_point(text, line_pos);
2539 gtk_stext_backward_delete(text, 1);
2548 /* if it is URL at beginning of line don't wrap */
2549 if (p_pos + i_len == line_pos &&
2550 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2552 g_print("found URL at ");
2553 dump_text(text, line_pos, tlen, 1);
2560 gtk_stext_set_point(text, line_pos);
2561 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2562 /* gtk_stext_compact_buffer(text); */
2565 /* for loop will increase it */
2566 cur_pos = line_pos - 1;
2567 /* start over with current line */
2569 line_len = cur_len = 0;
2570 if (autowrap || i_len > 0)
2575 g_print("after CR insert ");
2576 dump_text(text, line_pos, tlen, 1);
2577 dump_text(text, cur_pos, tlen, 1);
2580 /* should we insert quotation ? */
2581 if (linewrap_quote && i_len) {
2582 /* only if line is not already quoted */
2583 if (!gtkut_stext_str_compare
2584 (text, line_pos, tlen, qfmt)) {
2587 if (line_pos - p_pos > i_len) {
2589 (text, i_len, p_pos,
2594 g_print("after quote insert ");
2595 dump_text(text, line_pos, tlen, 1);
2603 line_pos = cur_pos + 1;
2604 line_len = cur_len + ch_len;
2606 /* advance to next character in buffer */
2611 gtk_stext_thaw(text);
2613 if (set_editable_pos && editable_pos <= tlen)
2614 gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
2620 static void compose_set_title(Compose *compose)
2625 edited = compose->modified ? _(" [Edited]") : "";
2626 if (compose->account && compose->account->address)
2627 str = g_strdup_printf(_("%s - Compose message%s"),
2628 compose->account->address, edited);
2630 str = g_strdup_printf(_("Compose message%s"), edited);
2631 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2636 * compose_current_mail_account:
2638 * Find a current mail account (the currently selected account, or the
2639 * default account, if a news account is currently selected). If a
2640 * mail account cannot be found, display an error message.
2642 * Return value: Mail account, or NULL if not found.
2644 static PrefsAccount *
2645 compose_current_mail_account(void)
2649 if (cur_account && cur_account->protocol != A_NNTP)
2652 ac = account_get_default();
2653 if (!ac || ac->protocol == A_NNTP) {
2654 alertpanel_error(_("Account for sending mail is not specified.\n"
2655 "Please select a mail account before sending."));
2662 static void compose_select_account(Compose *compose, PrefsAccount *account)
2664 GtkWidget *menuitem;
2665 GtkItemFactory *ifactory;
2667 g_return_if_fail(account != NULL);
2669 compose->account = account;
2671 compose_set_title(compose);
2673 ifactory = gtk_item_factory_from_widget(compose->menubar);
2675 if (account->protocol == A_NNTP) {
2676 gtk_widget_show(compose->newsgroups_hbox);
2677 gtk_widget_show(compose->newsgroups_entry);
2678 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2679 compose->use_newsgroups = TRUE;
2681 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2682 gtk_check_menu_item_set_active
2683 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2684 gtk_widget_set_sensitive(menuitem, TRUE);
2685 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2686 gtk_check_menu_item_set_active
2687 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2688 gtk_widget_set_sensitive(menuitem, TRUE);
2690 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
2692 gtk_widget_hide(compose->newsgroups_hbox);
2693 gtk_widget_hide(compose->newsgroups_entry);
2694 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
2695 gtk_widget_queue_resize(compose->table_vbox);
2696 compose->use_newsgroups = FALSE;
2698 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2699 gtk_check_menu_item_set_active
2700 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2701 gtk_widget_set_sensitive(menuitem, FALSE);
2702 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2703 gtk_check_menu_item_set_active
2704 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2705 gtk_widget_set_sensitive(menuitem, FALSE);
2707 menuitem = gtk_item_factory_get_item(ifactory, "/View/Followup to");
2708 gtk_check_menu_item_set_active
2709 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2710 gtk_widget_set_sensitive(menuitem, FALSE);
2713 if (account->set_autocc) {
2714 compose_entry_show(compose, COMPOSE_ENTRY_CC);
2715 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
2716 compose_entry_set(compose, account->auto_cc,
2719 if (account->set_autobcc) {
2720 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
2721 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
2722 compose_entry_set(compose, account->auto_bcc,
2725 if (account->set_autoreplyto) {
2726 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
2727 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
2728 compose_entry_set(compose, account->auto_replyto,
2729 COMPOSE_ENTRY_REPLY_TO);
2732 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
2733 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2734 prefs_common.show_ruler);
2738 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
2739 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2740 account->default_sign);
2741 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
2742 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2743 account->default_encrypt);
2745 activate_gnupg_mode(compose, account);
2746 #endif /* USE_GPGME */
2749 gboolean compose_check_for_valid_recipient(Compose *compose) {
2750 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2751 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2752 gboolean recipient_found = FALSE;
2756 /* free to and newsgroup list */
2757 slist_free_strings(compose->to_list);
2758 g_slist_free(compose->to_list);
2759 compose->to_list = NULL;
2761 slist_free_strings(compose->newsgroup_list);
2762 g_slist_free(compose->newsgroup_list);
2763 compose->newsgroup_list = NULL;
2765 /* search header entries for to and newsgroup entries */
2766 for (list = compose->header_list; list; list = list->next) {
2769 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
2770 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2772 if (entry[0] != '\0') {
2773 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2774 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2775 compose->to_list = address_list_append(compose->to_list, entry);
2776 recipient_found = TRUE;
2779 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2780 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2781 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2782 recipient_found = TRUE;
2789 return recipient_found;
2792 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
2796 if (compose_check_for_valid_recipient(compose) == FALSE) {
2797 alertpanel_error(_("Recipient is not specified."));
2801 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2802 if (*str == '\0' && check_subject == TRUE) {
2805 aval = alertpanel(_("Send"),
2806 _("Subject is empty. Send it anyway?"),
2807 _("Yes"), _("No"), NULL);
2808 if (aval != G_ALERTDEFAULT)
2815 gint compose_send(Compose *compose)
2822 if (compose_check_entries(compose, TRUE) == FALSE)
2825 val = compose_queue(compose, &msgnum, &folder);
2827 alertpanel_error(_("Could not queue message for sending"));
2831 msgpath = folder_item_fetch_msg(folder, msgnum);
2832 val = procmsg_send_message_queue(msgpath);
2835 folder_item_remove_msg(folder, msgnum);
2836 folder_update_item(folder, TRUE);
2841 #if 0 /* compose restructure */
2842 gint compose_send(Compose *compose)
2844 gchar tmp[MAXPATHLEN + 1];
2846 static gboolean lock = FALSE;
2850 g_return_val_if_fail(compose->account != NULL, -1);
2854 if (compose_check_entries(compose, TRUE) == FALSE) {
2859 /* write to temporary file */
2860 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
2861 get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
2863 if (prefs_common.linewrap_at_send)
2864 compose_wrap_line_all(compose);
2866 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2871 if (!compose->to_list && !compose->newsgroup_list) {
2872 g_warning(_("can't get recipient list."));
2878 if (compose->to_list) {
2881 #if 0 /* NEW COMPOSE GUI */
2882 if (compose->account->protocol != A_NNTP)
2883 ac = compose->account;
2885 ac = account_find_from_address(compose->account->address);
2887 if (cur_account && cur_account->protocol != A_NNTP)
2890 ac = account_get_default();
2892 if (!ac || ac->protocol == A_NNTP) {
2893 alertpanel_error(_("Account for sending mail is not specified.\n"
2894 "Please select a mail account before sending."));
2901 ac = compose->account;
2903 ok = send_message(tmp, ac, compose->to_list);
2904 statusbar_pop_all();
2907 if (ok == 0 && compose->newsgroup_list) {
2908 ok = news_post(FOLDER(compose->account->folder), tmp);
2910 alertpanel_error(_("Error occurred while posting the message to %s ."),
2911 compose->account->nntp_server);
2918 /* queue message if failed to send */
2920 if (prefs_common.queue_msg) {
2925 _("Error occurred while sending the message.\n"
2926 "Put this message into queue folder?"),
2927 _("OK"), _("Cancel"), NULL);
2928 if (G_ALERTDEFAULT == val) {
2929 ok = compose_queue(compose, tmp);
2931 alertpanel_error(_("Can't queue the message."));
2934 alertpanel_error(_("Error occurred while sending the message."));
2936 if (compose->mode == COMPOSE_REEDIT) {
2937 compose_remove_reedit_target(compose);
2938 if (compose->targetinfo)
2940 (compose->targetinfo->folder, TRUE);
2942 /* save message to outbox */
2943 if (prefs_common.savemsg) {
2946 outbox = account_get_special_folder
2947 (compose->account, F_OUTBOX);
2948 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
2950 (_("Can't save the message to Sent."));
2952 folder_update_item(outbox, TRUE);
2962 static gboolean compose_use_attach(Compose *compose) {
2963 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2966 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
2969 gchar buf[BUFFSIZE];
2971 gboolean first_address;
2973 ComposeHeaderEntry *headerentry;
2974 gchar *headerentryname;
2978 debug_print("Writing redirect header\n");
2980 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
2981 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
2983 first_address = TRUE;
2984 for (list = compose->header_list; list; list = list->next) {
2985 headerentry = ((ComposeHeaderEntry *)list->data);
2986 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2988 if (g_strcasecmp(headerentryname, cc_hdr) == 0
2989 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2990 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2991 Xstrdup_a(str, str, return -1);
2993 if (str[0] != '\0') {
2994 compose_convert_header
2995 (buf, sizeof(buf), str,
2996 strlen("Resent-To") + 2);
2997 if (first_address) {
2998 fprintf(fp, "Resent-To: ");
2999 first_address = FALSE;
3003 fprintf(fp, "%s", buf);
3007 /* if (!first_address) { */
3014 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3016 gchar buf[BUFFSIZE];
3018 /* struct utsname utsbuf; */
3020 g_return_val_if_fail(fp != NULL, -1);
3021 g_return_val_if_fail(compose->account != NULL, -1);
3022 g_return_val_if_fail(compose->account->address != NULL, -1);
3025 get_rfc822_date(buf, sizeof(buf));
3026 fprintf(fp, "Resent-Date: %s\n", buf);
3029 if (compose->account->name && *compose->account->name) {
3030 compose_convert_header
3031 (buf, sizeof(buf), compose->account->name,
3033 fprintf(fp, "Resent-From: %s <%s>\n",
3034 buf, compose->account->address);
3036 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3039 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3041 Xstrdup_a(str, str, return -1);
3044 compose_convert_header(buf, sizeof(buf), str,
3045 strlen("Subject: "));
3046 fprintf(fp, "Subject: %s\n", buf);
3050 /* Resent-Message-ID */
3051 if (compose->account->gen_msgid) {
3052 compose_generate_msgid(compose, buf, sizeof(buf));
3053 fprintf(fp, "Resent-Message-Id: <%s>\n", buf);
3054 compose->msgid = g_strdup(buf);
3057 compose_redirect_write_headers_from_headerlist(compose, fp);
3059 /* separator between header and body */
3065 static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
3070 gchar buf[BUFFSIZE];
3072 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3073 FILE_OP_ERROR(file, "fopen");
3077 if ((fdest = fopen(file, "wb")) == NULL) {
3078 FILE_OP_ERROR(file, "fopen");
3083 /* chmod for security */
3084 if (change_file_mode_rw(fdest, file) < 0) {
3085 FILE_OP_ERROR(file, "chmod");
3086 g_warning(_("can't change file mode\n"));
3089 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
3090 /* should filter returnpath, delivered-to */
3091 if (g_strncasecmp(buf, "Return-Path:",
3092 strlen("Return-Path:")) == 0 ||
3093 g_strncasecmp(buf, "Delivered-To:",
3094 strlen("Delivered-To:")) == 0 ||
3095 g_strncasecmp(buf, "Received:",
3096 strlen("Received:")) == 0 ||
3097 g_strncasecmp(buf, "Subject:",
3098 strlen("Subject:")) == 0 ||
3099 g_strncasecmp(buf, "X-UIDL:",
3100 strlen("X-UIDL:")) == 0)
3103 if (fputs(buf, fdest) == -1)
3106 if (!prefs_common.redirect_keep_from) {
3107 if (g_strncasecmp(buf, "From:",
3108 strlen("From:")) == 0) {
3109 fputs(" (by way of ", fdest);
3110 if (compose->account->name
3111 && *compose->account->name) {
3112 compose_convert_header
3114 compose->account->name,
3116 fprintf(fdest, "%s <%s>",
3118 compose->account->address);
3120 fprintf(fdest, "%s",
3121 compose->account->address);
3126 if (fputs("\n", fdest) == -1)
3130 compose_redirect_write_headers(compose, fdest);
3132 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3133 if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
3134 FILE_OP_ERROR(file, "fwrite");
3140 if (fclose(fdest) == EOF) {
3141 FILE_OP_ERROR(file, "fclose");
3157 /* interfaces to rfc2015 to keep out the prefs stuff there.
3158 * returns 0 on success and -1 on error. */
3159 static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
3161 const gchar *key_id = NULL;
3164 switch (compose->account->sign_key) {
3165 case SIGN_KEY_DEFAULT:
3168 case SIGN_KEY_BY_FROM:
3169 key_id = compose->account->address;
3171 case SIGN_KEY_CUSTOM:
3172 key_id = compose->account->sign_key_id;
3178 key_list = rfc2015_create_signers_list(key_id);
3181 alertpanel_error(_("Could not find any key associated with "
3182 "currently selected key id `%s'."), key_id);
3186 *pkey_list = key_list;
3190 /* clearsign message body text */
3191 static gint compose_clearsign_text(Compose *compose, gchar **text)
3196 tmp_file = get_tmp_file();
3197 if (str_write_to_file(*text, tmp_file) < 0) {
3202 if (canonicalize_file_replace(tmp_file) < 0 ||
3203 compose_create_signers_list(compose, &key_list) < 0 ||
3204 rfc2015_clearsign(tmp_file, key_list) < 0) {
3211 *text = file_read_to_str(tmp_file);
3219 #endif /* USE_GPGME */
3221 static gint compose_write_to_file(Compose *compose, const gchar *file,
3228 const gchar *out_codeset;
3229 EncodingType encoding;
3231 if ((fp = fopen(file, "wb")) == NULL) {
3232 FILE_OP_ERROR(file, "fopen");
3236 /* chmod for security */
3237 if (change_file_mode_rw(fp, file) < 0) {
3238 FILE_OP_ERROR(file, "chmod");
3239 g_warning(_("can't change file mode\n"));
3242 /* get all composed text */
3243 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3244 len = strlen(chars);
3245 if (is_ascii_str(chars)) {
3248 out_codeset = CS_US_ASCII;
3249 encoding = ENC_7BIT;
3251 const gchar *src_codeset;
3253 out_codeset = conv_get_outgoing_charset_str();
3254 if (!strcasecmp(out_codeset, CS_US_ASCII))
3255 out_codeset = CS_ISO_8859_1;
3256 encoding = procmime_get_encoding_for_charset(out_codeset);
3260 compose->use_signing && !compose->gnupg_mode &&
3261 encoding == ENC_8BIT)
3262 encoding = ENC_BASE64;
3265 src_codeset = conv_get_current_charset_str();
3266 /* if current encoding is US-ASCII, set it the same as
3267 outgoing one to prevent code conversion failure */
3268 if (!strcasecmp(src_codeset, CS_US_ASCII))
3269 src_codeset = out_codeset;
3271 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3272 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3274 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3280 _("Can't convert the character encoding of the message.\n"
3281 "Send it anyway?"), _("Yes"), _("+No"), NULL);
3282 if (aval != G_ALERTDEFAULT) {
3295 /* Canonicalize line endings in the message text */
3297 gchar *canon_buf, *out;
3301 for (p = buf ; *p; ++p) {
3309 out = canon_buf = g_new(gchar, new_len + 1);
3310 for (p = buf; *p; ++p) {
3324 if (!is_draft && compose->use_signing && compose->gnupg_mode) {
3325 if (compose_clearsign_text(compose, &buf) < 0) {
3326 g_warning("clearsign failed\n");
3336 if (compose_write_headers
3337 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3338 g_warning(_("can't write headers\n"));
3345 if (compose_use_attach(compose)) {
3347 /* This prolog message is ignored by mime software and
3348 * because it would make our signing/encryption task
3349 * tougher, we don't emit it in that case */
3350 if (!compose->use_signing && !compose->use_encryption)
3352 fputs("This is a multi-part message in MIME format.\n", fp);
3354 fprintf(fp, "\n--%s\n", compose->boundary);
3355 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3357 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3358 procmime_get_encoding_str(encoding));
3364 if (encoding == ENC_BASE64) {
3365 gchar outbuf[B64_BUFFSIZE];
3368 for (i = 0; i < len; i += B64_LINE_SIZE) {
3369 l = MIN(B64_LINE_SIZE, len - i);
3370 base64_encode(outbuf, buf + i, l);
3374 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3375 FILE_OP_ERROR(file, "fwrite");
3383 if (compose_use_attach(compose))
3384 compose_write_attach(compose, fp);
3386 if (fclose(fp) == EOF) {
3387 FILE_OP_ERROR(file, "fclose");
3396 if ((compose->use_signing && !compose->gnupg_mode) ||
3397 compose->use_encryption) {
3398 if (canonicalize_file_replace(file) < 0) {
3404 if (compose->use_signing && !compose->gnupg_mode) {
3407 if (compose_create_signers_list(compose, &key_list) < 0 ||
3408 rfc2015_sign(file, key_list) < 0) {
3413 if (compose->use_encryption) {
3414 if (rfc2015_encrypt(file, compose->to_list,
3415 compose->gnupg_mode) < 0) {
3420 #endif /* USE_GPGME */
3425 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3431 if ((fp = fopen(file, "wb")) == NULL) {
3432 FILE_OP_ERROR(file, "fopen");
3436 /* chmod for security */
3437 if (change_file_mode_rw(fp, file) < 0) {
3438 FILE_OP_ERROR(file, "chmod");
3439 g_warning(_("can't change file mode\n"));
3442 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3445 len = strlen(chars);
3446 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3447 FILE_OP_ERROR(file, "fwrite");
3456 if (fclose(fp) == EOF) {
3457 FILE_OP_ERROR(file, "fclose");
3464 static gint compose_remove_reedit_target(Compose *compose)
3467 MsgInfo *msginfo = compose->targetinfo;
3469 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3470 if (!msginfo) return -1;
3472 item = msginfo->folder;
3473 g_return_val_if_fail(item != NULL, -1);
3475 if (procmsg_msg_exist(msginfo) &&
3476 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3477 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3478 g_warning(_("can't remove the old message\n"));
3486 void compose_remove_draft(Compose *compose)
3489 MsgInfo *msginfo = compose->targetinfo;
3490 drafts = account_get_special_folder(compose->account, F_DRAFT);
3492 if (procmsg_msg_exist(msginfo)) {
3493 folder_item_remove_msg(drafts, msginfo->msgnum);
3494 folder_update_item(drafts, TRUE);
3499 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3501 return compose_queue_sub (compose, msgnum, item, FALSE);
3503 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3509 gchar buf[BUFFSIZE];
3511 static gboolean lock = FALSE;
3512 PrefsAccount *mailac = NULL, *newsac = NULL;
3514 debug_print("queueing message...\n");
3515 g_return_val_if_fail(compose->account != NULL, -1);
3519 if (compose_check_entries(compose, check_subject) == FALSE) {
3524 if (!compose->to_list && !compose->newsgroup_list) {
3525 g_warning(_("can't get recipient list."));
3530 if (compose->to_list) {
3531 if (compose->account->protocol != A_NNTP)
3532 mailac = compose->account;
3533 else if (cur_account && cur_account->protocol != A_NNTP)
3534 mailac = cur_account;
3535 else if (!(mailac = compose_current_mail_account())) {
3537 alertpanel_error(_("No account for sending mails available!"));
3542 if (compose->newsgroup_list) {
3543 if (compose->account->protocol == A_NNTP)
3544 newsac = compose->account;
3545 else if (!newsac->protocol != A_NNTP) {
3547 alertpanel_error(_("No account for posting news available!"));
3552 if (prefs_common.linewrap_at_send)
3553 compose_wrap_line_all(compose);
3555 /* write to temporary file */
3556 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3557 G_DIR_SEPARATOR, (gint)compose);
3559 if (compose->redirect_filename != NULL) {
3560 if (compose_redirect_write_to_file(compose, tmp2) < 0) {
3567 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3574 /* add queue header */
3575 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3576 G_DIR_SEPARATOR, (gint)compose);
3577 if ((fp = fopen(tmp, "wb")) == NULL) {
3578 FILE_OP_ERROR(tmp, "fopen");
3582 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3583 FILE_OP_ERROR(tmp2, "fopen");
3591 if (change_file_mode_rw(fp, tmp) < 0) {
3592 FILE_OP_ERROR(tmp, "chmod");
3593 g_warning(_("can't change file mode\n"));
3596 /* queueing variables */
3597 fprintf(fp, "AF:\n");
3598 fprintf(fp, "NF:0\n");
3599 fprintf(fp, "PS:10\n");
3600 fprintf(fp, "SRH:1\n");
3601 fprintf(fp, "SFN:\n");
3602 fprintf(fp, "DSR:\n");
3604 fprintf(fp, "MID:<%s>\n", compose->msgid);
3606 fprintf(fp, "MID:\n");
3607 fprintf(fp, "CFG:\n");
3608 fprintf(fp, "PT:0\n");
3609 fprintf(fp, "S:%s\n", compose->account->address);
3610 fprintf(fp, "RQ:\n");
3612 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3614 fprintf(fp, "SSV:\n");
3616 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3618 fprintf(fp, "NSV:\n");
3619 fprintf(fp, "SSH:\n");
3620 /* write recepient list */
3621 if (compose->to_list) {
3622 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
3623 for (cur = compose->to_list->next; cur != NULL;
3625 fprintf(fp, ",<%s>", (gchar *)cur->data);
3628 /* write newsgroup list */
3629 if (compose->newsgroup_list) {
3631 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3632 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3633 fprintf(fp, ",%s", (gchar *)cur->data);
3636 /* Sylpheed account IDs */
3638 fprintf(fp, "MAID:%d\n", mailac->account_id);
3641 fprintf(fp, "NAID:%d\n", newsac->account_id);
3643 /* Save copy folder */
3644 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3645 gchar *savefolderid;
3647 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3648 fprintf(fp, "SCF:%s\n", savefolderid);
3649 g_free(savefolderid);
3651 /* Message-ID of message replying to */
3652 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
3655 folderid = folder_item_get_identifier(compose->replyinfo->folder);
3656 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
3661 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3662 if (fputs(buf, fp) == EOF) {
3663 FILE_OP_ERROR(tmp, "fputs");
3674 if (fclose(fp) == EOF) {
3675 FILE_OP_ERROR(tmp, "fclose");
3683 queue = account_get_special_folder(compose->account, F_QUEUE);
3685 g_warning(_("can't find queue folder\n"));
3690 folder_item_scan(queue);
3691 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3692 g_warning(_("can't queue the message\n"));
3702 if (compose->mode == COMPOSE_REEDIT) {
3703 compose_remove_reedit_target(compose);
3704 if (compose->targetinfo &&
3705 compose->targetinfo->folder != queue)
3707 (compose->targetinfo->folder, TRUE);
3710 folder_update_item(queue, TRUE);
3712 if ((msgnum != NULL) && (item != NULL)) {
3720 static void compose_write_attach(Compose *compose, FILE *fp)
3723 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3726 gchar filename[BUFFSIZE];
3729 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3731 gchar buf[BUFFSIZE];
3732 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3734 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
3735 g_warning(_("Can't open file %s\n"), ainfo->file);
3739 fprintf(fp, "\n--%s\n", compose->boundary);
3741 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3742 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3743 fprintf(fp, "Content-Disposition: inline\n");
3745 conv_encode_header(filename, sizeof(filename),
3747 fprintf(fp, "Content-Type: %s;\n"
3749 ainfo->content_type, filename);
3750 fprintf(fp, "Content-Disposition: attachment;\n"
3751 " filename=\"%s\"\n", filename);
3754 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3755 procmime_get_encoding_str(ainfo->encoding));
3757 switch (ainfo->encoding) {
3761 /* if (ainfo->encoding == ENC_7BIT) { */
3763 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3771 while ((len = fread(inbuf, sizeof(gchar),
3772 B64_LINE_SIZE, attach_fp))
3774 base64_encode(outbuf, inbuf, B64_LINE_SIZE);
3778 if (len > 0 && feof(attach_fp)) {
3779 base64_encode(outbuf, inbuf, len);
3785 debug_print("Tried to write attachment in unsupported encoding type\n");
3792 fprintf(fp, "\n--%s--\n", compose->boundary);
3795 #define QUOTE_IF_REQUIRED(out, str) \
3797 if (*str != '"' && (strchr(str, ',') \
3798 || strchr(str, '.'))) { \
3802 len = strlen(str) + 3; \
3803 Xalloca(__tmp, len, return -1); \
3804 g_snprintf(__tmp, len, "\"%s\"", str); \
3807 Xstrdup_a(out, str, return -1); \
3811 #define PUT_RECIPIENT_HEADER(header, str) \
3813 if (*str != '\0') { \
3814 Xstrdup_a(str, str, return -1); \
3816 if (*str != '\0') { \
3817 compose->to_list = address_list_append \
3818 (compose->to_list, str); \
3819 compose_convert_header \
3820 (buf, sizeof(buf), str, strlen(header) + 2); \
3821 fprintf(fp, "%s: %s\n", header, buf); \
3826 #define IS_IN_CUSTOM_HEADER(header) \
3827 (compose->account->add_customhdr && \
3828 custom_header_find(compose->account->customhdr_list, header) != NULL)
3830 static gint compose_write_headers_from_headerlist(Compose *compose,
3834 gchar buf[BUFFSIZE];
3835 gchar *str, *header_w_colon, *trans_hdr;
3836 gboolean first_address;
3838 ComposeHeaderEntry *headerentry;
3839 gchar * headerentryname;
3841 if (IS_IN_CUSTOM_HEADER(header)) {
3845 debug_print("Writing %s-header\n", header);
3847 header_w_colon = g_strconcat(header, ":", NULL);
3848 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3850 first_address = TRUE;
3851 for (list = compose->header_list; list; list = list->next) {
3852 headerentry = ((ComposeHeaderEntry *)list->data);
3853 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3855 if (!g_strcasecmp(trans_hdr, headerentryname)) {
3856 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3857 Xstrdup_a(str, str, return -1);
3859 if (str[0] != '\0') {
3860 compose_convert_header
3861 (buf, sizeof(buf), str,
3862 strlen(header) + 2);
3863 if (first_address) {
3864 fprintf(fp, "%s: ", header);
3865 first_address = FALSE;
3869 fprintf(fp, "%s", buf);
3873 if (!first_address) {
3877 g_free(header_w_colon);
3882 static gint compose_write_headers(Compose *compose, FILE *fp,
3883 const gchar *charset, EncodingType encoding,
3886 gchar buf[BUFFSIZE];
3890 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3892 /* struct utsname utsbuf; */
3894 g_return_val_if_fail(fp != NULL, -1);
3895 g_return_val_if_fail(charset != NULL, -1);
3896 g_return_val_if_fail(compose->account != NULL, -1);
3897 g_return_val_if_fail(compose->account->address != NULL, -1);
3899 /* Save draft infos */
3901 fprintf(fp, "S:%s\n", compose->account->address);
3902 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3903 gchar *savefolderid;
3905 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3906 fprintf(fp, "SCF:%s\n", savefolderid);
3907 g_free(savefolderid);
3913 if (compose->account->add_date) {
3914 get_rfc822_date(buf, sizeof(buf));
3915 fprintf(fp, "Date: %s\n", buf);
3919 if (!IS_IN_CUSTOM_HEADER("From")) {
3920 if (compose->account->name && *compose->account->name) {
3921 compose_convert_header
3922 (buf, sizeof(buf), compose->account->name,
3924 QUOTE_IF_REQUIRED(name, buf);
3925 fprintf(fp, "From: %s <%s>\n",
3926 name, compose->account->address);
3928 fprintf(fp, "From: %s\n", compose->account->address);
3932 compose_write_headers_from_headerlist(compose, fp, "To");
3933 #if 0 /* NEW COMPOSE GUI */
3934 if (compose->use_to) {
3935 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3936 PUT_RECIPIENT_HEADER("To", str);
3941 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3942 #if 0 /* NEW COMPOSE GUI */
3943 if (compose->use_newsgroups) {
3944 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3946 Xstrdup_a(str, str, return -1);
3950 compose->newsgroup_list =
3951 newsgroup_list_append
3952 (compose->newsgroup_list, str);
3953 compose_convert_header(buf, sizeof(buf), str,
3954 strlen("Newsgroups: "));
3955 fprintf(fp, "Newsgroups: %s\n", buf);
3961 compose_write_headers_from_headerlist(compose, fp, "Cc");
3962 #if 0 /* NEW COMPOSE GUI */
3963 if (compose->use_cc) {
3964 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3965 PUT_RECIPIENT_HEADER("Cc", str);
3969 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3970 #if 0 /* NEW COMPOSE GUI */
3971 if (compose->use_bcc) {
3972 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3973 PUT_RECIPIENT_HEADER("Bcc", str);
3978 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3979 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3980 Xstrdup_a(str, str, return -1);
3983 compose_convert_header(buf, sizeof(buf), str,
3984 strlen("Subject: "));
3985 fprintf(fp, "Subject: %s\n", buf);
3990 if (compose->account->gen_msgid) {
3991 compose_generate_msgid(compose, buf, sizeof(buf));
3992 fprintf(fp, "Message-Id: <%s>\n", buf);
3993 compose->msgid = g_strdup(buf);
3997 if (compose->inreplyto && compose->to_list)
3998 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
4001 if (compose->references)
4002 fprintf(fp, "References: %s\n", compose->references);
4005 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
4006 #if 0 /* NEW COMPOSE GUI */
4007 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
4008 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
4010 Xstrdup_a(str, str, return -1);
4014 compose_convert_header(buf, sizeof(buf), str,
4015 strlen("Followup-To: "));
4016 fprintf(fp, "Followup-To: %s\n", buf);
4022 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
4023 #if 0 /* NEW COMPOSE GUI */
4024 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
4025 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
4027 Xstrdup_a(str, str, return -1);
4030 compose_convert_header(buf, sizeof(buf), str,
4031 strlen("Reply-To: "));
4032 fprintf(fp, "Reply-To: %s\n", buf);
4038 if (compose->account->organization &&
4039 !IS_IN_CUSTOM_HEADER("Organization")) {
4040 compose_convert_header(buf, sizeof(buf),
4041 compose->account->organization,
4042 strlen("Organization: "));
4043 fprintf(fp, "Organization: %s\n", buf);
4046 /* Program version and system info */
4047 /* uname(&utsbuf); */
4048 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
4049 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4051 gtk_major_version, gtk_minor_version, gtk_micro_version,
4053 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4055 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4056 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4058 gtk_major_version, gtk_minor_version, gtk_micro_version,
4060 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4063 /* custom headers */
4064 if (compose->account->add_customhdr) {
4067 for (cur = compose->account->customhdr_list; cur != NULL;
4069 CustomHeader *chdr = (CustomHeader *)cur->data;
4071 if (strcasecmp(chdr->name, "Date") != 0 &&
4072 strcasecmp(chdr->name, "From") != 0 &&
4073 strcasecmp(chdr->name, "To") != 0 &&
4074 /* strcasecmp(chdr->name, "Sender") != 0 && */
4075 strcasecmp(chdr->name, "Message-Id") != 0 &&
4076 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
4077 strcasecmp(chdr->name, "References") != 0 &&
4078 strcasecmp(chdr->name, "Mime-Version") != 0 &&
4079 strcasecmp(chdr->name, "Content-Type") != 0 &&
4080 strcasecmp(chdr->name, "Content-Transfer-Encoding")
4082 compose_convert_header
4084 chdr->value ? chdr->value : "",
4085 strlen(chdr->name) + 2);
4086 fprintf(fp, "%s: %s\n", chdr->name, buf);
4092 fprintf(fp, "Mime-Version: 1.0\n");
4093 if (compose_use_attach(compose)) {
4094 get_rfc822_date(buf, sizeof(buf));
4095 subst_char(buf, ' ', '_');
4096 subst_char(buf, ',', '_');
4097 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
4098 buf, (guint)compose);
4100 "Content-Type: multipart/mixed;\n"
4101 " boundary=\"%s\"\n", compose->boundary);
4103 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
4104 fprintf(fp, "Content-Transfer-Encoding: %s\n",
4105 procmime_get_encoding_str(encoding));
4108 /* X-Sylpheed header */
4110 fprintf(fp, "X-Sylpheed-Account-Id: %d\n",
4111 compose->account->account_id);
4113 switch (compose->priority) {
4114 case PRIORITY_HIGHEST: fprintf(fp, "Importance: high\n"
4115 "X-Priority: 1 (Highest)\n");
4117 case PRIORITY_HIGH: fprintf(fp, "Importance: high\n"
4118 "X-Priority: 2 (High)\n");
4120 case PRIORITY_NORMAL: break;
4121 case PRIORITY_LOW: fprintf(fp, "Importance: low\n"
4122 "X-Priority: 4 (Low)\n");
4124 case PRIORITY_LOWEST: fprintf(fp, "Importance: low\n"
4125 "X-Priority: 5 (Lowest)\n");
4127 default: debug_print("compose: priority unknown : %d\n",
4131 /* Request Return Receipt */
4132 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4133 if (compose->return_receipt) {
4134 if (compose->account->name
4135 && *compose->account->name) {
4136 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
4137 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4139 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
4143 /* get special headers */
4144 for (list = compose->header_list; list; list = list->next) {
4145 ComposeHeaderEntry *headerentry;
4148 gchar *headername_wcolon;
4149 gchar *headername_trans;
4152 gboolean standard_header = FALSE;
4154 headerentry = ((ComposeHeaderEntry *)list->data);
4156 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4157 if (!strstr(tmp, ":")) {
4158 headername_wcolon = g_strconcat(tmp, ":", NULL);
4159 headername = g_strdup(tmp);
4161 headername_wcolon = g_strdup(tmp);
4162 headername = g_strdup(strtok(tmp, ":"));
4166 headervalue = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4167 string = std_headers;
4168 while (*string != NULL) {
4169 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4170 if (!strcmp(headername_trans,headername_wcolon))
4171 standard_header = TRUE;
4174 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4175 fprintf(fp, "%s %s\n", headername_wcolon, headervalue);
4178 g_free(headername_wcolon);
4182 /* separator between header and body */
4188 #undef IS_IN_CUSTOM_HEADER
4190 static void compose_convert_header(gchar *dest, gint len, gchar *src,
4193 g_return_if_fail(src != NULL);
4194 g_return_if_fail(dest != NULL);
4196 if (len < 1) return;
4200 if (is_ascii_str(src)) {
4201 strncpy2(dest, src, len);
4202 dest[len - 1] = '\0';
4205 conv_encode_header(dest, len, src, header_len);
4208 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
4217 if (compose->account && compose->account->address &&
4218 *compose->account->address) {
4219 if (strchr(compose->account->address, '@'))
4220 addr = g_strdup(compose->account->address);
4222 addr = g_strconcat(compose->account->address, "@",
4223 get_domain_name(), NULL);
4225 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
4228 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
4229 lt->tm_year + 1900, lt->tm_mon + 1,
4230 lt->tm_mday, lt->tm_hour,
4231 lt->tm_min, lt->tm_sec,
4232 (guint)random(), addr);
4234 debug_print("generated Message-ID: %s\n", buf);
4239 static void compose_create_header_entry(Compose *compose)
4241 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4245 GList *combo_list = NULL;
4246 gchar **string, *header = NULL;
4247 ComposeHeaderEntry *headerentry;
4248 gboolean standard_header = FALSE;
4250 headerentry = g_new0(ComposeHeaderEntry, 1);
4253 combo = gtk_combo_new();
4255 while(*string != NULL) {
4256 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4259 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4260 g_list_free(combo_list);
4261 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4262 gtk_widget_show(combo);
4263 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4264 if (compose->header_last) {
4265 gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4267 while (*string != NULL) {
4268 if (!strcmp(*string, last_header_entry))
4269 standard_header = TRUE;
4272 if (standard_header)
4273 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4275 if (!compose->header_last || !standard_header) {
4276 switch(compose->account->protocol) {
4278 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4281 header = prefs_common.trans_hdr ? _("To:") : "To:";
4286 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4289 entry = gtk_entry_new();
4290 gtk_widget_show(entry);
4291 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);
4293 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4294 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4295 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4297 address_completion_register_entry(GTK_ENTRY(entry));
4299 headerentry->compose = compose;
4300 headerentry->combo = combo;
4301 headerentry->entry = entry;
4302 headerentry->headernum = compose->header_nextrow;
4304 compose->header_nextrow++;
4305 compose->header_last = headerentry;
4308 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4310 ComposeHeaderEntry *last_header;
4312 last_header = compose->header_last;
4314 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4315 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4318 static GtkWidget *compose_create_header(Compose *compose)
4322 GtkWidget *from_optmenu_hbox;
4323 #if 0 /* NEW COMPOSE GUI */
4324 GtkWidget *to_entry;
4326 GtkWidget *newsgroups_entry;
4327 GtkWidget *newsgroups_hbox;
4329 GtkWidget *header_scrolledwin;
4330 GtkWidget *header_table;
4331 #if 0 /* NEW COMPOSE GUI */
4332 GtkWidget *cc_entry;
4334 GtkWidget *bcc_entry;
4335 GtkWidget *bcc_hbox;
4336 GtkWidget *reply_entry;
4337 GtkWidget *reply_hbox;
4338 GtkWidget *followup_entry;
4339 GtkWidget *followup_hbox;
4344 /* header labels and entries */
4345 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4346 gtk_widget_show(header_scrolledwin);
4347 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4349 header_table = gtk_table_new(2, 2, FALSE);
4350 gtk_widget_show(header_table);
4351 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4352 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4353 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4356 /* option menu for selecting accounts */
4357 hbox = gtk_hbox_new(FALSE, 0);
4358 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4359 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4360 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4362 from_optmenu_hbox = compose_account_option_menu_create(compose);
4363 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4364 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4365 #if 0 /* NEW COMPOSE GUI */
4366 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4370 compose->header_table = header_table;
4371 compose->header_list = NULL;
4372 compose->header_nextrow = count;
4374 compose_create_header_entry(compose);
4376 #if 0 /* NEW COMPOSE GUI */
4377 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4379 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4380 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4381 &count, "Newsgroups:", FALSE);
4382 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4384 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4386 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4388 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4389 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4391 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4392 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4394 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4395 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4396 "Followup-To:", FALSE);
4397 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4399 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4401 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4402 GTK_SIGNAL_FUNC(to_activated), compose);
4403 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4404 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4405 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4406 GTK_SIGNAL_FUNC(subject_activated), compose);
4407 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4408 GTK_SIGNAL_FUNC(cc_activated), compose);
4409 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4410 GTK_SIGNAL_FUNC(bcc_activated), compose);
4411 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4412 GTK_SIGNAL_FUNC(replyto_activated), compose);
4413 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4414 GTK_SIGNAL_FUNC(followupto_activated), compose);
4416 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4417 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4418 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4419 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4420 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4421 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4422 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4423 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4424 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4425 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4426 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4427 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4428 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4429 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4432 compose->table = NULL;
4433 #if 0 /* NEW COMPOSE GUI */
4434 compose->table = table;
4435 compose->to_hbox = to_hbox;
4436 compose->to_entry = to_entry;
4437 compose->newsgroups_hbox = newsgroups_hbox;
4438 compose->newsgroups_entry = newsgroups_entry;
4440 #if 0 /* NEW COMPOSE GUI */
4441 compose->cc_hbox = cc_hbox;
4442 compose->cc_entry = cc_entry;
4443 compose->bcc_hbox = bcc_hbox;
4444 compose->bcc_entry = bcc_entry;
4445 compose->reply_hbox = reply_hbox;
4446 compose->reply_entry = reply_entry;
4447 compose->followup_hbox = followup_hbox;
4448 compose->followup_entry = followup_entry;
4451 return header_scrolledwin ;
4454 GtkWidget *compose_create_attach(Compose *compose)
4456 gchar *titles[N_ATTACH_COLS];
4459 GtkWidget *attach_scrwin;
4460 GtkWidget *attach_clist;
4462 titles[COL_MIMETYPE] = _("MIME type");
4463 titles[COL_SIZE] = _("Size");
4464 titles[COL_NAME] = _("Name");
4466 /* attachment list */
4467 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4468 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4469 GTK_POLICY_AUTOMATIC,
4471 gtk_widget_set_usize(attach_scrwin, -1, 80);
4473 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4474 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4476 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4477 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4478 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4479 GTK_SELECTION_EXTENDED);
4480 for (i = 0; i < N_ATTACH_COLS; i++)
4481 GTK_WIDGET_UNSET_FLAGS
4482 (GTK_CLIST(attach_clist)->column[i].button,
4484 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4486 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4487 GTK_SIGNAL_FUNC(attach_selected), compose);
4488 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4489 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4490 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4491 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4494 gtk_drag_dest_set(attach_clist,
4495 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4496 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4497 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4498 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4501 compose->attach_scrwin = attach_scrwin;
4502 compose->attach_clist = attach_clist;
4504 return attach_scrwin;
4507 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4508 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4510 static GtkWidget *compose_create_others(Compose *compose)
4513 GtkWidget *savemsg_checkbtn;
4514 GtkWidget *savemsg_entry;
4515 GtkWidget *savemsg_select;
4518 gchar *folderidentifier;
4520 /* Table for settings */
4521 table = gtk_table_new(3, 1, FALSE);
4522 gtk_widget_show(table);
4523 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4526 /* Save Message to folder */
4527 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4528 gtk_widget_show(savemsg_checkbtn);
4529 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4530 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4531 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4533 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4534 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4536 savemsg_entry = gtk_entry_new();
4537 gtk_widget_show(savemsg_entry);
4538 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4539 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4540 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4541 folderidentifier = folder_item_get_identifier(account_get_special_folder
4542 (compose->account, F_OUTBOX));
4543 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4544 g_free(folderidentifier);
4547 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4548 gtk_widget_show (savemsg_select);
4549 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4550 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4551 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4556 compose->savemsg_checkbtn = savemsg_checkbtn;
4557 compose->savemsg_entry = savemsg_entry;
4562 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4564 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4565 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4568 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4573 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4576 path = folder_item_get_identifier(dest);
4578 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4582 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4588 GtkWidget *handlebox;
4590 GtkWidget *notebook;
4595 GtkWidget *subject_hbox;
4596 GtkWidget *subject_frame;
4597 GtkWidget *subject_entry;
4601 GtkWidget *edit_vbox;
4602 GtkWidget *ruler_hbox;
4604 GtkWidget *scrolledwin;
4607 UndoMain *undostruct;
4609 gchar *titles[N_ATTACH_COLS];
4610 guint n_menu_entries;
4611 GtkStyle *style, *new_style;
4614 gboolean success[1];
4615 GtkWidget *popupmenu;
4616 GtkItemFactory *popupfactory;
4617 GtkItemFactory *ifactory;
4618 GtkWidget *tmpl_menu;
4622 GtkAspell * gtkaspell = NULL;
4625 static GdkGeometry geometry;
4627 g_return_val_if_fail(account != NULL, NULL);
4629 debug_print("Creating compose window...\n");
4630 compose = g_new0(Compose, 1);
4632 titles[COL_MIMETYPE] = _("MIME type");
4633 titles[COL_SIZE] = _("Size");
4634 titles[COL_NAME] = _("Name");
4636 compose->account = account;
4638 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4639 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4640 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4641 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4643 if (!geometry.max_width) {
4644 geometry.max_width = gdk_screen_width();
4645 geometry.max_height = gdk_screen_height();
4647 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4648 &geometry, GDK_HINT_MAX_SIZE);
4650 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4651 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4652 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4653 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4654 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4655 gtk_widget_realize(window);
4657 gtkut_widget_set_composer_icon(window);
4659 vbox = gtk_vbox_new(FALSE, 0);
4660 gtk_container_add(GTK_CONTAINER(window), vbox);
4662 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4663 menubar = menubar_create(window, compose_entries,
4664 n_menu_entries, "<Compose>", compose);
4665 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4667 handlebox = gtk_handle_box_new();
4668 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4670 compose_toolbar_create(compose, handlebox);
4672 vbox2 = gtk_vbox_new(FALSE, 2);
4673 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4674 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4677 notebook = gtk_notebook_new();
4678 gtk_widget_set_usize(notebook, -1, 130);
4679 gtk_widget_show(notebook);
4681 /* header labels and entries */
4682 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4683 /* attachment list */
4684 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4686 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4689 subject_hbox = gtk_hbox_new(FALSE, 0);
4690 gtk_widget_show(subject_hbox);
4692 subject_frame = gtk_frame_new(NULL);
4693 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4694 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4695 gtk_widget_show(subject_frame);
4697 subject = gtk_hbox_new(FALSE, 0);
4698 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4699 gtk_widget_show(subject);
4701 label = gtk_label_new(_("Subject:"));
4702 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4703 gtk_widget_show(label);
4705 subject_entry = gtk_entry_new();
4706 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4707 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4708 gtk_widget_show(subject_entry);
4709 compose->subject_entry = subject_entry;
4710 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4712 edit_vbox = gtk_vbox_new(FALSE, 0);
4713 #if 0 /* NEW COMPOSE GUI */
4714 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4717 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4720 ruler_hbox = gtk_hbox_new(FALSE, 0);
4721 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4723 ruler = gtk_shruler_new();
4724 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4725 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4727 gtk_widget_set_usize(ruler_hbox, 1, -1);
4730 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4731 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4732 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4733 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4734 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4736 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4737 (GTK_SCROLLED_WINDOW(scrolledwin)),
4738 gtk_scrolled_window_get_vadjustment
4739 (GTK_SCROLLED_WINDOW(scrolledwin)));
4740 GTK_STEXT(text)->default_tab_width = 8;
4741 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4743 if (prefs_common.block_cursor) {
4744 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4747 if (prefs_common.smart_wrapping) {
4748 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4749 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4752 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4754 gtk_signal_connect(GTK_OBJECT(text), "changed",
4755 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4756 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4757 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4758 gtk_signal_connect(GTK_OBJECT(text), "activate",
4759 GTK_SIGNAL_FUNC(text_activated), compose);
4760 gtk_signal_connect(GTK_OBJECT(text), "insert_text",
4761 GTK_SIGNAL_FUNC(text_inserted), compose);
4762 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4763 GTK_SIGNAL_FUNC(compose_button_press_cb),
4766 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4767 GTK_SIGNAL_FUNC(compose_key_press_cb),
4770 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4771 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4775 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4776 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4777 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4778 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4780 gtk_widget_show_all(vbox);
4782 /* pane between attach clist and text */
4783 paned = gtk_vpaned_new();
4784 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4785 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4786 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4787 gtk_paned_add1(GTK_PANED(paned), notebook);
4788 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4789 gtk_widget_show_all(paned);
4791 style = gtk_widget_get_style(text);
4793 /* workaround for the slow down of GtkSText when using Pixmap theme */
4794 if (style->engine) {
4795 GtkThemeEngine *engine;
4797 engine = style->engine;
4798 style->engine = NULL;
4799 new_style = gtk_style_copy(style);
4800 style->engine = engine;
4802 new_style = gtk_style_copy(style);
4804 if (prefs_common.textfont) {
4807 if ((font = gtkut_font_load(prefs_common.textfont)) != NULL) {
4808 gdk_font_unref(new_style->font);
4809 new_style->font = font;
4813 gtk_widget_set_style(text, new_style);
4815 color[0] = quote_color;
4816 cmap = gdk_window_get_colormap(window->window);
4817 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4818 if (success[0] == FALSE) {
4819 g_warning("Compose: color allocation failed.\n");
4820 style = gtk_widget_get_style(text);
4821 quote_color = style->black;
4824 n_entries = sizeof(compose_popup_entries) /
4825 sizeof(compose_popup_entries[0]);
4826 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4827 "<Compose>", &popupfactory,
4830 ifactory = gtk_item_factory_from_widget(menubar);
4831 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4832 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4834 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4835 #if 0 /* NEW COMPOSE GUI */
4836 gtk_widget_hide(bcc_hbox);
4837 gtk_widget_hide(bcc_entry);
4838 gtk_widget_hide(reply_hbox);
4839 gtk_widget_hide(reply_entry);
4840 gtk_widget_hide(followup_hbox);
4841 gtk_widget_hide(followup_entry);
4842 gtk_widget_hide(ruler_hbox);
4843 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4844 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4845 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4847 if (account->protocol == A_NNTP) {
4848 gtk_widget_hide(to_hbox);
4849 gtk_widget_hide(to_entry);
4850 gtk_widget_hide(cc_hbox);
4851 gtk_widget_hide(cc_entry);
4852 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4853 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4855 gtk_widget_hide(newsgroups_hbox);
4856 gtk_widget_hide(newsgroups_entry);
4857 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4861 update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
4864 undostruct = undo_init(text);
4865 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4868 address_completion_start(window);
4870 compose->window = window;
4871 compose->vbox = vbox;
4872 compose->menubar = menubar;
4873 compose->handlebox = handlebox;
4875 compose->vbox2 = vbox2;
4877 compose->paned = paned;
4879 compose->edit_vbox = edit_vbox;
4880 compose->ruler_hbox = ruler_hbox;
4881 compose->ruler = ruler;
4882 compose->scrolledwin = scrolledwin;
4883 compose->text = text;
4885 compose->focused_editable = NULL;
4887 compose->popupmenu = popupmenu;
4888 compose->popupfactory = popupfactory;
4890 compose->tmpl_menu = tmpl_menu;
4892 compose->mode = mode;
4894 compose->targetinfo = NULL;
4895 compose->replyinfo = NULL;
4897 compose->replyto = NULL;
4899 compose->bcc = NULL;
4900 compose->followup_to = NULL;
4902 compose->ml_post = NULL;
4904 compose->inreplyto = NULL;
4905 compose->references = NULL;
4906 compose->msgid = NULL;
4907 compose->boundary = NULL;
4910 compose->use_signing = FALSE;
4911 compose->use_encryption = FALSE;
4912 #endif /* USE_GPGME */
4914 compose->modified = FALSE;
4916 compose->return_receipt = FALSE;
4917 compose->paste_as_quotation = FALSE;
4919 compose->to_list = NULL;
4920 compose->newsgroup_list = NULL;
4922 compose->exteditor_file = NULL;
4923 compose->exteditor_pid = -1;
4924 compose->exteditor_readdes = -1;
4925 compose->exteditor_tag = -1;
4927 compose->redirect_filename = NULL;
4928 compose->undostruct = undostruct;
4930 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4931 if (mode != COMPOSE_REDIRECT) {
4932 if (prefs_common.enable_aspell && prefs_common.dictionary &&
4933 strcmp(prefs_common.dictionary, _("None"))) {
4934 gtkaspell = gtkaspell_new((const gchar*)prefs_common.dictionary,
4935 conv_get_current_charset_str(),
4936 prefs_common.misspelled_col,
4937 prefs_common.check_while_typing,
4938 prefs_common.use_alternate,
4941 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkaspellcheckers->error_message);
4942 gtkaspell_checkers_reset_error();
4945 GtkWidget *menuitem;
4947 if (!gtkaspell_set_sug_mode(gtkaspell, prefs_common.aspell_sugmode)) {
4948 debug_print("Aspell: could not set suggestion mode %s\n",
4949 gtkaspellcheckers->error_message);
4950 gtkaspell_checkers_reset_error();
4953 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
4954 gtkaspell_populate_submenu(gtkaspell, menuitem);
4955 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4961 compose_select_account(compose, account);
4964 compose->gtkaspell = gtkaspell;
4967 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
4968 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4970 if (account->set_autobcc)
4971 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4973 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
4974 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4977 if (account->protocol != A_NNTP)
4978 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4980 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4982 addressbook_set_target_compose(compose);
4983 update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
4985 if (mode != COMPOSE_REDIRECT)
4986 compose_set_template_menu(compose);
4988 GtkWidget *menuitem;
4989 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4990 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
4993 compose_list = g_list_append(compose_list, compose);
4995 if (!prefs_common.show_ruler)
4996 gtk_widget_hide(ruler_hbox);
4999 compose->priority = PRIORITY_NORMAL;
5000 compose_update_priority_menu_item(compose);
5003 activate_gnupg_mode(compose, account);
5006 common_toolbar_set_style(compose, TOOLBAR_COMPOSE);
5008 gtk_widget_show(window);
5013 static void toolbar_compose_buttons_cb(GtkWidget *widget,
5018 void (*func)(GtkWidget *widget, gpointer data);
5019 } compose_action[] = {
5020 { A_SEND, toolbar_send_cb },
5021 { A_SENDL, toolbar_send_later_cb },
5022 { A_DRAFT, toolbar_draft_cb },
5023 { A_INSERT, toolbar_insert_cb },
5024 { A_ATTACH, toolbar_attach_cb },
5025 { A_SIG, toolbar_sig_cb },
5026 { A_EXTEDITOR, toolbar_ext_editor_cb },
5027 { A_LINEWRAP, toolbar_linewrap_cb },
5028 { A_ADDRBOOK, toolbar_address_cb },
5029 { A_SYL_ACTIONS, common_toolbar_actions_execute_cb }};
5032 gint num_items = sizeof(compose_action)/sizeof(compose_action[0]);
5034 for (i = 0; i < num_items; i++) {
5036 if (compose_action[i].index == item->index) {
5037 if (item->index == A_SYL_ACTIONS)
5038 compose_action[i].func(widget, (gpointer)item->parent);
5039 else /* this won`t be necessary if everything is moved to toolbar.c */
5040 compose_action[i].func(widget, (gpointer)item->parent->data);
5046 static void compose_toolbar_update(Compose *compose)
5048 gtk_container_remove(GTK_CONTAINER(compose->handlebox),
5049 GTK_WIDGET(compose->toolbar->toolbar));
5051 compose->toolbar->toolbar = NULL;
5052 compose->toolbar->send_btn = NULL;
5053 compose->toolbar->sendl_btn = NULL;
5054 compose->toolbar->draft_btn = NULL;
5055 compose->toolbar->insert_btn = NULL;
5056 compose->toolbar->attach_btn = NULL;
5057 compose->toolbar->sig_btn = NULL;
5058 compose->toolbar->exteditor_btn = NULL;
5059 compose->toolbar->linewrap_btn = NULL;
5060 compose->toolbar->addrbook_btn = NULL;
5062 TOOLBAR_DESTROY_ITEMS(compose->toolbar->item_list);
5063 TOOLBAR_DESTROY_ACTIONS(compose->toolbar->action_list);
5064 compose_toolbar_create(compose, compose->handlebox);
5067 static void compose_toolbar_create(Compose *compose,
5068 GtkWidget *container)
5070 ToolbarItem *toolbar_item;
5073 GtkWidget *icon_wid = NULL;
5075 GtkTooltips *toolbar_tips;
5076 ToolbarSylpheedActions *action_item;
5078 GSList *toolbar_list;
5080 toolbar_tips = gtk_tooltips_new();
5082 toolbar_read_config_file(TOOLBAR_COMPOSE);
5083 toolbar_list = toolbar_get_list(TOOLBAR_COMPOSE);
5085 compose->toolbar = g_new0(Toolbar, 1);
5087 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
5089 gtk_container_add(GTK_CONTAINER(container), toolbar);
5090 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
5091 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
5092 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
5093 GTK_TOOLBAR_SPACE_LINE);
5095 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
5097 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, SEPARATOR) == 0) {
5098 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
5102 toolbar_item = g_new0(ToolbarItem, 1);
5103 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
5104 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
5105 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
5107 toolbar_item->parent = g_new0(ToolbarParent, 1);
5108 toolbar_item->parent->data = (gpointer)compose;
5109 toolbar_item->parent->type = TOOLBAR_COMPOSE;
5111 /* collect toolbar items in list to keep track */
5112 compose->toolbar->item_list = g_slist_append(compose->toolbar->item_list,
5115 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
5116 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
5120 icon_wid, toolbar_compose_buttons_cb,
5123 switch (toolbar_item->index) {
5125 compose->toolbar->send_btn = item;
5126 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5127 compose->toolbar->send_btn,
5128 _("Send Message"), NULL);
5131 compose->toolbar->sendl_btn = item;
5132 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5133 compose->toolbar->sendl_btn,
5134 _("Put into queue folder and send later"), NULL);
5137 compose->toolbar->draft_btn = item;
5138 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5139 compose->toolbar->draft_btn,
5140 _("Save to draft folder"), NULL);
5143 compose->toolbar->insert_btn = item;
5144 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5145 compose->toolbar->insert_btn,
5146 _("Insert file"), NULL);
5149 compose->toolbar->attach_btn = item;
5150 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5151 compose->toolbar->attach_btn,
5152 _("Attach file"), NULL);
5155 compose->toolbar->sig_btn = item;
5156 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5157 compose->toolbar->sig_btn,
5158 _("Insert signature"), NULL);
5161 compose->toolbar->exteditor_btn = item;
5162 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5163 compose->toolbar->exteditor_btn,
5164 _("Edit with external editor"), NULL);
5167 compose->toolbar->linewrap_btn = item;
5168 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5169 compose->toolbar->linewrap_btn,
5170 _("Wrap all long lines"), NULL);
5173 compose->toolbar->addrbook_btn = item;
5174 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5175 compose->toolbar->addrbook_btn,
5176 _("Address book"), NULL);
5179 action_item = g_new0(ToolbarSylpheedActions, 1);
5180 action_item->widget = item;
5181 action_item->name = g_strdup(toolbar_item->text);
5183 compose->toolbar->action_list =
5184 g_slist_append(compose->toolbar->action_list,
5187 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5189 action_item->name, NULL);
5191 gtk_widget_show(item);
5198 compose->toolbar->toolbar = toolbar;
5200 gtk_widget_show_all(toolbar);
5203 static void compose_toolbar_set_sensitive (Compose * compose, gboolean sensitive)
5205 GSList *items = compose->toolbar->action_list;
5206 if (compose->toolbar->send_btn)
5207 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
5208 if (compose->toolbar->sendl_btn)
5209 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
5210 if (compose->toolbar->draft_btn )
5211 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
5212 if (compose->toolbar->insert_btn )
5213 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
5214 if (compose->toolbar->attach_btn)
5215 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
5216 if (compose->toolbar->sig_btn)
5217 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
5218 if (compose->toolbar->exteditor_btn)
5219 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
5220 if (compose->toolbar->linewrap_btn)
5221 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
5222 if (compose->toolbar->addrbook_btn)
5223 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
5224 for (; items != NULL; items = g_slist_next(items)) {
5225 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
5226 gtk_widget_set_sensitive(item->widget, sensitive);
5230 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5236 gint num = 0, def_menu = 0;
5238 accounts = account_get_list();
5239 g_return_val_if_fail(accounts != NULL, NULL);
5241 hbox = gtk_hbox_new(FALSE, 0);
5242 optmenu = gtk_option_menu_new();
5243 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5244 menu = gtk_menu_new();
5246 for (; accounts != NULL; accounts = accounts->next, num++) {
5247 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5248 GtkWidget *menuitem;
5251 if (ac == compose->account) def_menu = num;
5254 name = g_strdup_printf("%s: %s <%s>",
5256 ac->name, ac->address);
5258 name = g_strdup_printf("%s: %s",
5259 ac->account_name, ac->address);
5260 MENUITEM_ADD(menu, menuitem, name, ac);
5262 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
5263 GTK_SIGNAL_FUNC(account_activated),
5267 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5268 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5273 static void compose_set_priority_cb(gpointer data,
5277 Compose *compose = (Compose *) data;
5278 compose->priority = action;
5281 static void compose_update_priority_menu_item(Compose * compose)
5283 GtkItemFactory *ifactory;
5284 GtkWidget *menuitem = NULL;
5286 ifactory = gtk_item_factory_from_widget(compose->menubar);
5288 switch (compose->priority) {
5289 case PRIORITY_HIGHEST:
5290 menuitem = gtk_item_factory_get_item
5291 (ifactory, "/Message/Priority/Highest");
5294 menuitem = gtk_item_factory_get_item
5295 (ifactory, "/Message/Priority/High");
5297 case PRIORITY_NORMAL:
5298 menuitem = gtk_item_factory_get_item
5299 (ifactory, "/Message/Priority/Normal");
5302 menuitem = gtk_item_factory_get_item
5303 (ifactory, "/Message/Priority/Low");
5305 case PRIORITY_LOWEST:
5306 menuitem = gtk_item_factory_get_item
5307 (ifactory, "/Message/Priority/Lowest");
5310 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5314 static void compose_set_gnupg_mode_cb(gpointer data,
5318 Compose *compose = (Compose *) data;
5319 compose->gnupg_mode = action;
5322 static void compose_update_gnupg_mode_menu_item(Compose * compose)
5324 GtkItemFactory *ifactory;
5325 GtkWidget *menuitem = NULL;
5327 ifactory = gtk_item_factory_from_widget(compose->menubar);
5329 switch (compose->gnupg_mode) {
5330 case GNUPG_MODE_DETACH:
5331 menuitem = gtk_item_factory_get_item
5332 (ifactory, "/Message/Mode/MIME");
5334 case GNUPG_MODE_INLINE:
5335 menuitem = gtk_item_factory_get_item
5336 (ifactory, "/Message/Mode/Inline");
5339 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5341 if (compose->use_encryption == TRUE || compose->use_signing == TRUE)
5342 menu_set_sensitive(ifactory, "/Message/Mode", TRUE);
5344 menu_set_sensitive(ifactory, "/Message/Mode", FALSE);
5348 static void compose_set_template_menu(Compose *compose)
5350 GSList *tmpl_list, *cur;
5354 tmpl_list = template_get_config();
5356 menu = gtk_menu_new();
5358 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5359 Template *tmpl = (Template *)cur->data;
5361 item = gtk_menu_item_new_with_label(tmpl->name);
5362 gtk_menu_append(GTK_MENU(menu), item);
5363 gtk_signal_connect(GTK_OBJECT(item), "activate",
5364 GTK_SIGNAL_FUNC(compose_template_activate_cb),
5366 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
5367 gtk_widget_show(item);
5370 gtk_widget_show(menu);
5371 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5374 void compose_reflect_prefs_all(void)
5379 for (cur = compose_list; cur != NULL; cur = cur->next) {
5380 compose = (Compose *)cur->data;
5381 compose_set_template_menu(compose);
5385 void compose_reflect_prefs_pixmap_theme(void)
5390 for (cur = compose_list; cur != NULL; cur = cur->next) {
5391 compose = (Compose *)cur->data;
5392 compose_toolbar_update(compose);
5393 common_toolbar_set_style(compose, TOOLBAR_COMPOSE);
5397 static void compose_template_apply(Compose *compose, Template *tmpl,
5403 if (!tmpl || !tmpl->value) return;
5405 gtk_stext_freeze(GTK_STEXT(compose->text));
5407 if (tmpl->subject && *tmpl->subject != '\0')
5408 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5410 if (tmpl->to && *tmpl->to != '\0')
5411 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5412 if (tmpl->cc && *tmpl->cc != '\0')
5413 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5415 if (tmpl->bcc && *tmpl->bcc != '\0')
5416 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5419 gtk_stext_clear(GTK_STEXT(compose->text));
5421 if (compose->replyinfo == NULL) {
5422 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5425 if (prefs_common.quotemark && *prefs_common.quotemark)
5426 qmark = prefs_common.quotemark;
5430 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5431 tmpl->value, qmark, NULL);
5434 if (replace && parsed_str && prefs_common.auto_sig)
5435 compose_insert_sig(compose);
5437 if (replace && parsed_str) {
5438 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
5439 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
5443 compose_changed_cb(NULL, compose);
5445 gtk_stext_thaw(GTK_STEXT(compose->text));
5448 static void compose_destroy(Compose *compose)
5451 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5454 /* NOTE: address_completion_end() does nothing with the window
5455 * however this may change. */
5456 address_completion_end(compose->window);
5458 slist_free_strings(compose->to_list);
5459 g_slist_free(compose->to_list);
5460 slist_free_strings(compose->newsgroup_list);
5461 g_slist_free(compose->newsgroup_list);
5462 slist_free_strings(compose->header_list);
5463 g_slist_free(compose->header_list);
5465 procmsg_msginfo_free(compose->targetinfo);
5466 procmsg_msginfo_free(compose->replyinfo);
5468 g_free(compose->replyto);
5469 g_free(compose->cc);
5470 g_free(compose->bcc);
5471 g_free(compose->newsgroups);
5472 g_free(compose->followup_to);
5474 g_free(compose->ml_post);
5476 g_free(compose->inreplyto);
5477 g_free(compose->references);
5478 g_free(compose->msgid);
5479 g_free(compose->boundary);
5481 if (compose->redirect_filename)
5482 g_free(compose->redirect_filename);
5484 g_free(compose->exteditor_file);
5486 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5488 compose_attach_info_free(ainfo);
5490 if (addressbook_get_target_compose() == compose)
5491 addressbook_set_target_compose(NULL);
5494 if (compose->gtkaspell) {
5495 gtkaspell_delete(compose->gtkaspell);
5499 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5500 prefs_common.compose_height = compose->window->allocation.height;
5502 gtk_widget_destroy(compose->paned);
5504 TOOLBAR_DESTROY_ITEMS(compose->toolbar->item_list);
5505 TOOLBAR_DESTROY_ACTIONS(compose->toolbar->action_list);
5506 g_free(compose->toolbar);
5509 compose_list = g_list_remove(compose_list, compose);
5512 static void compose_attach_info_free(AttachInfo *ainfo)
5514 g_free(ainfo->file);
5515 g_free(ainfo->content_type);
5516 g_free(ainfo->name);
5520 static void compose_attach_remove_selected(Compose *compose)
5522 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5526 while (clist->selection != NULL) {
5527 row = GPOINTER_TO_INT(clist->selection->data);
5528 ainfo = gtk_clist_get_row_data(clist, row);
5529 compose_attach_info_free(ainfo);
5530 gtk_clist_remove(clist, row);
5534 static struct _AttachProperty
5537 GtkWidget *mimetype_entry;
5538 GtkWidget *encoding_optmenu;
5539 GtkWidget *path_entry;
5540 GtkWidget *filename_entry;
5542 GtkWidget *cancel_btn;
5545 static void compose_attach_property(Compose *compose)
5547 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5550 GtkOptionMenu *optmenu;
5551 static gboolean cancelled;
5553 if (!clist->selection) return;
5554 row = GPOINTER_TO_INT(clist->selection->data);
5556 ainfo = gtk_clist_get_row_data(clist, row);
5559 if (!attach_prop.window)
5560 compose_attach_property_create(&cancelled);
5561 gtk_widget_grab_focus(attach_prop.ok_btn);
5562 gtk_widget_show(attach_prop.window);
5563 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5565 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5566 if (ainfo->encoding == ENC_UNKNOWN)
5567 gtk_option_menu_set_history(optmenu, ENC_BASE64);
5569 gtk_option_menu_set_history(optmenu, ainfo->encoding);
5571 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5572 ainfo->content_type ? ainfo->content_type : "");
5573 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5574 ainfo->file ? ainfo->file : "");
5575 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5576 ainfo->name ? ainfo->name : "");
5580 gchar *cnttype = NULL;
5584 GtkWidget *menuitem;
5589 if (cancelled == TRUE) {
5590 gtk_widget_hide(attach_prop.window);
5594 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5595 if (*text != '\0') {
5598 text = g_strstrip(g_strdup(text));
5599 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5600 cnttype = g_strdup(text);
5603 alertpanel_error(_("Invalid MIME type."));
5609 menu = gtk_option_menu_get_menu(optmenu);
5610 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5611 ainfo->encoding = GPOINTER_TO_INT
5612 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5614 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5615 if (*text != '\0') {
5616 if (is_file_exist(text) &&
5617 (size = get_file_size(text)) > 0)
5618 file = g_strdup(text);
5621 (_("File doesn't exist or is empty."));
5627 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5628 if (*text != '\0') {
5629 g_free(ainfo->name);
5630 ainfo->name = g_strdup(text);
5634 g_free(ainfo->content_type);
5635 ainfo->content_type = cnttype;
5638 g_free(ainfo->file);
5644 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5645 ainfo->content_type);
5646 gtk_clist_set_text(clist, row, COL_SIZE,
5647 to_human_readable(ainfo->size));
5648 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5650 gtk_widget_hide(attach_prop.window);
5655 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5657 label = gtk_label_new(str); \
5658 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5659 GTK_FILL, 0, 0, 0); \
5660 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5662 entry = gtk_entry_new(); \
5663 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5664 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5667 static void compose_attach_property_create(gboolean *cancelled)
5673 GtkWidget *mimetype_entry;
5676 GtkWidget *optmenu_menu;
5677 GtkWidget *menuitem;
5678 GtkWidget *path_entry;
5679 GtkWidget *filename_entry;
5682 GtkWidget *cancel_btn;
5683 GList *mime_type_list, *strlist;
5685 debug_print("Creating attach_property window...\n");
5687 window = gtk_window_new(GTK_WINDOW_DIALOG);
5688 gtk_widget_set_usize(window, 480, -1);
5689 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5690 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
5691 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5692 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5693 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5694 GTK_SIGNAL_FUNC(attach_property_delete_event),
5696 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5697 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5700 vbox = gtk_vbox_new(FALSE, 8);
5701 gtk_container_add(GTK_CONTAINER(window), vbox);
5703 table = gtk_table_new(4, 2, FALSE);
5704 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5705 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5706 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5708 label = gtk_label_new(_("MIME type"));
5709 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5711 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5712 mimetype_entry = gtk_combo_new();
5713 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5714 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5716 /* stuff with list */
5717 mime_type_list = procmime_get_mime_type_list();
5719 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5720 MimeType *type = (MimeType *) mime_type_list->data;
5721 strlist = g_list_append(strlist,
5722 g_strdup_printf("%s/%s",
5723 type->type, type->sub_type));
5726 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5728 for (mime_type_list = strlist; mime_type_list != NULL;
5729 mime_type_list = mime_type_list->next)
5730 g_free(mime_type_list->data);
5731 g_list_free(strlist);
5733 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5735 label = gtk_label_new(_("Encoding"));
5736 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5738 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5740 hbox = gtk_hbox_new(FALSE, 0);
5741 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5742 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5744 optmenu = gtk_option_menu_new();
5745 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5747 optmenu_menu = gtk_menu_new();
5748 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5749 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5751 gtk_widget_set_sensitive(menuitem, FALSE);
5753 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5754 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5756 gtk_widget_set_sensitive(menuitem, FALSE);
5758 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5759 gtk_widget_set_sensitive(menuitem, FALSE);
5760 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5762 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5764 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5765 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5767 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5768 &cancel_btn, _("Cancel"), NULL, NULL);
5769 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5770 gtk_widget_grab_default(ok_btn);
5772 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5773 GTK_SIGNAL_FUNC(attach_property_ok),
5775 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5776 GTK_SIGNAL_FUNC(attach_property_cancel),
5779 gtk_widget_show_all(vbox);
5781 attach_prop.window = window;
5782 attach_prop.mimetype_entry = mimetype_entry;
5783 attach_prop.encoding_optmenu = optmenu;
5784 attach_prop.path_entry = path_entry;
5785 attach_prop.filename_entry = filename_entry;
5786 attach_prop.ok_btn = ok_btn;
5787 attach_prop.cancel_btn = cancel_btn;
5790 #undef SET_LABEL_AND_ENTRY
5792 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5798 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5804 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5805 gboolean *cancelled)
5813 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5814 gboolean *cancelled)
5816 if (event && event->keyval == GDK_Escape) {
5822 static void compose_exec_ext_editor(Compose *compose)
5828 tmp = g_strdup_printf("%s%ctmpmsg.%08x", get_tmp_dir(),
5829 G_DIR_SEPARATOR, (gint)compose);
5831 if (pipe(pipe_fds) < 0) {
5837 if ((pid = fork()) < 0) {
5844 /* close the write side of the pipe */
5847 compose->exteditor_file = g_strdup(tmp);
5848 compose->exteditor_pid = pid;
5849 compose->exteditor_readdes = pipe_fds[0];
5851 compose_set_ext_editor_sensitive(compose, FALSE);
5853 compose->exteditor_tag =
5854 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5855 compose_input_cb, compose);
5856 } else { /* process-monitoring process */
5862 /* close the read side of the pipe */
5865 if (compose_write_body_to_file(compose, tmp) < 0) {
5866 fd_write(pipe_fds[1], "2\n", 2);
5870 pid_ed = compose_exec_ext_editor_real(tmp);
5872 fd_write(pipe_fds[1], "1\n", 2);
5876 /* wait until editor is terminated */
5877 waitpid(pid_ed, NULL, 0);
5879 fd_write(pipe_fds[1], "0\n", 2);
5888 static gint compose_exec_ext_editor_real(const gchar *file)
5890 static gchar *def_cmd = "emacs %s";
5896 g_return_val_if_fail(file != NULL, -1);
5898 if ((pid = fork()) < 0) {
5903 if (pid != 0) return pid;
5905 /* grandchild process */
5907 if (setpgid(0, getppid()))
5910 if (prefs_common.ext_editor_cmd &&
5911 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5912 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5913 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5915 if (prefs_common.ext_editor_cmd)
5916 g_warning(_("External editor command line is invalid: `%s'\n"),
5917 prefs_common.ext_editor_cmd);
5918 g_snprintf(buf, sizeof(buf), def_cmd, file);
5921 cmdline = strsplit_with_quote(buf, " ", 1024);
5922 execvp(cmdline[0], cmdline);
5925 g_strfreev(cmdline);
5930 static gboolean compose_ext_editor_kill(Compose *compose)
5932 pid_t pgid = compose->exteditor_pid * -1;
5935 ret = kill(pgid, 0);
5937 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5941 msg = g_strdup_printf
5942 (_("The external editor is still working.\n"
5943 "Force terminating the process?\n"
5944 "process group id: %d"), -pgid);
5945 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5948 if (val == G_ALERTDEFAULT) {
5949 gdk_input_remove(compose->exteditor_tag);
5950 close(compose->exteditor_readdes);
5952 if (kill(pgid, SIGTERM) < 0) perror("kill");
5953 waitpid(compose->exteditor_pid, NULL, 0);
5955 g_warning(_("Terminated process group id: %d"), -pgid);
5956 g_warning(_("Temporary file: %s"),
5957 compose->exteditor_file);
5959 compose_set_ext_editor_sensitive(compose, TRUE);
5961 g_free(compose->exteditor_file);
5962 compose->exteditor_file = NULL;
5963 compose->exteditor_pid = -1;
5964 compose->exteditor_readdes = -1;
5965 compose->exteditor_tag = -1;
5973 static void compose_input_cb(gpointer data, gint source,
5974 GdkInputCondition condition)
5977 Compose *compose = (Compose *)data;
5980 debug_print("Compose: input from monitoring process\n");
5982 gdk_input_remove(compose->exteditor_tag);
5985 if (read(source, &buf[i], 1) < 1) {
5989 if (buf[i] == '\n') {
5994 if (i == sizeof(buf) - 1)
5998 waitpid(compose->exteditor_pid, NULL, 0);
6000 if (buf[0] == '0') { /* success */
6001 GtkSText *text = GTK_STEXT(compose->text);
6003 gtk_stext_freeze(text);
6004 gtk_stext_set_point(text, 0);
6005 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
6006 compose_insert_file(compose, compose->exteditor_file);
6007 compose_changed_cb(NULL, compose);
6008 gtk_stext_thaw(text);
6010 if (unlink(compose->exteditor_file) < 0)
6011 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6012 } else if (buf[0] == '1') { /* failed */
6013 g_warning(_("Couldn't exec external editor\n"));
6014 if (unlink(compose->exteditor_file) < 0)
6015 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6016 } else if (buf[0] == '2') {
6017 g_warning(_("Couldn't write to file\n"));
6018 } else if (buf[0] == '3') {
6019 g_warning(_("Pipe read failed\n"));
6024 compose_set_ext_editor_sensitive(compose, TRUE);
6026 g_free(compose->exteditor_file);
6027 compose->exteditor_file = NULL;
6028 compose->exteditor_pid = -1;
6029 compose->exteditor_readdes = -1;
6030 compose->exteditor_tag = -1;
6033 static void compose_set_ext_editor_sensitive(Compose *compose,
6036 GtkItemFactory *ifactory;
6038 ifactory = gtk_item_factory_from_widget(compose->menubar);
6040 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6041 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6042 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
6044 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
6045 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
6046 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6047 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6048 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6051 gtk_widget_set_sensitive(compose->text, sensitive);
6052 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6053 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6054 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6055 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6056 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6057 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6058 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
6062 * compose_undo_state_changed:
6064 * Change the sensivity of the menuentries undo and redo
6066 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6067 gint redo_state, gpointer data)
6069 GtkWidget *widget = GTK_WIDGET(data);
6070 GtkItemFactory *ifactory;
6072 g_return_if_fail(widget != NULL);
6074 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
6076 ifactory = gtk_item_factory_from_widget(widget);
6078 switch (undo_state) {
6079 case UNDO_STATE_TRUE:
6080 if (!undostruct->undo_state) {
6081 debug_print ("Set_undo - Testpoint\n");
6082 undostruct->undo_state = TRUE;
6083 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6086 case UNDO_STATE_FALSE:
6087 if (undostruct->undo_state) {
6088 undostruct->undo_state = FALSE;
6089 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6092 case UNDO_STATE_UNCHANGED:
6094 case UNDO_STATE_REFRESH:
6095 menu_set_sensitive(ifactory, "/Edit/Undo",
6096 undostruct->undo_state);
6099 g_warning("Undo state not recognized");
6103 switch (redo_state) {
6104 case UNDO_STATE_TRUE:
6105 if (!undostruct->redo_state) {
6106 undostruct->redo_state = TRUE;
6107 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6110 case UNDO_STATE_FALSE:
6111 if (undostruct->redo_state) {
6112 undostruct->redo_state = FALSE;
6113 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6116 case UNDO_STATE_UNCHANGED:
6118 case UNDO_STATE_REFRESH:
6119 menu_set_sensitive(ifactory, "/Edit/Redo",
6120 undostruct->redo_state);
6123 g_warning("Redo state not recognized");
6128 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
6132 cursor_pos = (text->cursor_pos_x - extra) / char_width;
6133 cursor_pos = MAX(cursor_pos, 0);
6138 /* callback functions */
6140 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6141 * includes "non-client" (windows-izm) in calculation, so this calculation
6142 * may not be accurate.
6144 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6145 GtkAllocation *allocation,
6146 GtkSHRuler *shruler)
6148 if (prefs_common.show_ruler) {
6150 gint line_width_in_chars;
6152 char_width = gtkut_get_font_width
6153 (GTK_WIDGET(widget)->style->font);
6154 line_width_in_chars =
6155 (allocation->width - allocation->x) / char_width;
6157 /* got the maximum */
6158 gtk_ruler_set_range(GTK_RULER(shruler),
6159 0.0, line_width_in_chars,
6160 calc_cursor_xpos(GTK_STEXT(widget),
6163 /*line_width_in_chars*/ char_width);
6169 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
6171 compose_send_cb(data, 0, NULL);
6174 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
6176 compose_send_later_cb(data, 0, NULL);
6179 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
6181 compose_draft_cb(data, 0, NULL);
6184 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
6186 compose_insert_file_cb(data, 0, NULL);
6189 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
6191 compose_attach_cb(data, 0, NULL);
6194 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
6196 Compose *compose = (Compose *)data;
6198 compose_insert_sig(compose);
6201 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
6203 Compose *compose = (Compose *)data;
6205 compose_exec_ext_editor(compose);
6208 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
6210 Compose *compose = (Compose *)data;
6212 compose_wrap_line(compose);
6215 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
6217 compose_address_cb(data, 0, NULL);
6220 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6222 Compose *compose = (Compose *)data;
6226 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
6227 g_return_if_fail(ac != NULL);
6229 if (ac != compose->account)
6230 compose_select_account(compose, ac);
6233 static void attach_selected(GtkCList *clist, gint row, gint column,
6234 GdkEvent *event, gpointer data)
6236 Compose *compose = (Compose *)data;
6238 if (event && event->type == GDK_2BUTTON_PRESS)
6239 compose_attach_property(compose);
6242 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6245 Compose *compose = (Compose *)data;
6246 GtkCList *clist = GTK_CLIST(compose->attach_clist);
6251 if (event->button == 3) {
6252 if ((clist->selection && !clist->selection->next) ||
6253 !clist->selection) {
6254 gtk_clist_unselect_all(clist);
6255 if (gtk_clist_get_selection_info(clist,
6258 gtk_clist_select_row(clist, row, column);
6259 gtkut_clist_set_focus_row(clist, row);
6262 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6263 NULL, NULL, event->button, event->time);
6267 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6270 Compose *compose = (Compose *)data;
6274 switch (event->keyval) {
6276 compose_attach_remove_selected(compose);
6281 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6283 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6284 compose_toolbar_set_sensitive(compose, allow);
6285 menu_set_sensitive(ifactory, "/File", allow);
6286 menu_set_sensitive(ifactory, "/Edit", allow);
6287 menu_set_sensitive(ifactory, "/Message", allow);
6288 menu_set_sensitive(ifactory, "/Tools", allow);
6289 menu_set_sensitive(ifactory, "/Help", allow);
6292 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6294 Compose *compose = (Compose *)data;
6297 if (prefs_common.work_offline)
6298 if (alertpanel(_("Offline warning"),
6299 _("You're working offline. Override?"),
6300 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
6303 compose_allow_user_actions (compose, FALSE);
6304 compose->sending = TRUE;
6305 val = compose_send(compose);
6306 compose_allow_user_actions (compose, TRUE);
6307 compose->sending = FALSE;
6309 if (val == 0) gtk_widget_destroy(compose->window);
6312 static void compose_send_later_cb(gpointer data, guint action,
6315 Compose *compose = (Compose *)data;
6318 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6319 if (!val) gtk_widget_destroy(compose->window);
6322 void compose_draft (gpointer data)
6324 compose_draft_cb(data, 0, NULL);
6327 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6329 Compose *compose = (Compose *)data;
6333 static gboolean lock = FALSE;
6334 MsgInfo *newmsginfo;
6338 draft = account_get_special_folder(compose->account, F_DRAFT);
6339 g_return_if_fail(draft != NULL);
6343 tmp = g_strdup_printf("%s%cdraft.%08x", get_tmp_dir(),
6344 G_DIR_SEPARATOR, (gint)compose);
6346 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
6352 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) < 0) {
6359 draft->mtime = 0; /* force updating */
6361 if (compose->mode == COMPOSE_REEDIT) {
6362 compose_remove_reedit_target(compose);
6363 if (compose->targetinfo &&
6364 compose->targetinfo->folder != draft)
6365 folder_update_item(compose->targetinfo->folder,
6369 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6371 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6372 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
6373 folder_update_item(draft, TRUE);
6374 procmsg_msginfo_free(newmsginfo);
6379 /* 0: quit editing 1: keep editing */
6381 gtk_widget_destroy(compose->window);
6386 path = folder_item_fetch_msg(draft, msgnum);
6387 g_return_if_fail(path != NULL);
6388 if (stat(path, &s) < 0) {
6389 FILE_OP_ERROR(path, "stat");
6396 procmsg_msginfo_free(compose->targetinfo);
6397 compose->targetinfo = procmsg_msginfo_new();
6398 compose->targetinfo->msgnum = msgnum;
6399 compose->targetinfo->size = s.st_size;
6400 compose->targetinfo->mtime = s.st_mtime;
6401 compose->targetinfo->folder = draft;
6402 compose->mode = COMPOSE_REEDIT;
6406 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6408 Compose *compose = (Compose *)data;
6411 if (compose->redirect_filename != NULL)
6414 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6419 for ( tmp = file_list; tmp; tmp = tmp->next) {
6420 gchar *file = (gchar *) tmp->data;
6421 compose_attach_append(compose, file, file, NULL);
6422 compose_changed_cb(NULL, compose);
6425 g_list_free(file_list);
6429 static void compose_insert_file_cb(gpointer data, guint action,
6432 Compose *compose = (Compose *)data;
6435 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6440 for ( tmp = file_list; tmp; tmp = tmp->next) {
6441 gchar *file = (gchar *) tmp->data;
6442 compose_insert_file(compose, file);
6445 g_list_free(file_list);
6449 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6452 Compose *compose = (Compose *)data;
6453 if (compose->sending)
6455 compose_close_cb(compose, 0, NULL);
6459 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6461 Compose *compose = (Compose *)data;
6464 if (compose->exteditor_tag != -1) {
6465 if (!compose_ext_editor_kill(compose))
6469 if (compose->modified) {
6470 val = alertpanel(_("Discard message"),
6471 _("This message has been modified. discard it?"),
6472 _("Discard"), _("to Draft"), _("Cancel"));
6475 case G_ALERTDEFAULT:
6476 if (prefs_common.autosave)
6477 compose_remove_draft(compose);
6479 case G_ALERTALTERNATE:
6480 compose_draft_cb(data, 0, NULL);
6487 gtk_widget_destroy(compose->window);
6490 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6492 Compose *compose = (Compose *)data;
6494 addressbook_open(compose);
6497 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6499 Compose *compose = (Compose *)data;
6504 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6505 g_return_if_fail(tmpl != NULL);
6507 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6509 val = alertpanel(_("Apply template"), msg,
6510 _("Replace"), _("Insert"), _("Cancel"));
6513 if (val == G_ALERTDEFAULT)
6514 compose_template_apply(compose, tmpl, TRUE);
6515 else if (val == G_ALERTALTERNATE)
6516 compose_template_apply(compose, tmpl, FALSE);
6519 static void compose_ext_editor_cb(gpointer data, guint action,
6522 Compose *compose = (Compose *)data;
6524 compose_exec_ext_editor(compose);
6527 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6529 if (compose->sending)
6531 compose_destroy(compose);
6534 static void compose_undo_cb(Compose *compose)
6536 undo_undo(compose->undostruct);
6539 static void compose_redo_cb(Compose *compose)
6541 undo_redo(compose->undostruct);
6544 static void compose_cut_cb(Compose *compose)
6546 if (compose->focused_editable &&
6547 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6548 gtk_editable_cut_clipboard
6549 (GTK_EDITABLE(compose->focused_editable));
6552 static void compose_copy_cb(Compose *compose)
6554 if (compose->focused_editable &&
6555 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6556 gtk_editable_copy_clipboard
6557 (GTK_EDITABLE(compose->focused_editable));
6560 static void compose_paste_cb(Compose *compose)
6562 if (compose->focused_editable &&
6563 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6564 gtk_editable_paste_clipboard
6565 (GTK_EDITABLE(compose->focused_editable));
6568 static void compose_paste_as_quote_cb(Compose *compose)
6570 if (compose->focused_editable &&
6571 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6572 compose->paste_as_quotation = TRUE;
6573 gtk_editable_paste_clipboard
6574 (GTK_EDITABLE(compose->focused_editable));
6575 compose->paste_as_quotation = FALSE;
6579 static void compose_allsel_cb(Compose *compose)
6581 if (compose->focused_editable &&
6582 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6583 gtk_editable_select_region
6584 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6587 static void compose_gtk_stext_action_cb(Compose *compose,
6588 ComposeCallGtkSTextAction action)
6590 GtkSText *text = GTK_STEXT(compose->text);
6592 void (*do_action) (GtkSText *text);
6593 } action_table[] = {
6594 {gtk_stext_move_beginning_of_line},
6595 {gtk_stext_move_forward_character},
6596 {gtk_stext_move_backward_character},
6597 {gtk_stext_move_forward_word},
6598 {gtk_stext_move_backward_word},
6599 {gtk_stext_move_end_of_line},
6600 {gtk_stext_move_next_line},
6601 {gtk_stext_move_previous_line},
6602 {gtk_stext_delete_forward_character},
6603 {gtk_stext_delete_backward_character},
6604 {gtk_stext_delete_forward_word},
6605 {gtk_stext_delete_backward_word},
6606 {gtk_stext_delete_line},
6607 {gtk_stext_delete_line}, /* gtk_stext_delete_line_n */
6608 {gtk_stext_delete_to_line_end}
6611 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
6613 if (action >= COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE &&
6614 action <= COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END)
6615 action_table[action].do_action(text);
6618 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6620 if (GTK_IS_EDITABLE(widget))
6621 compose->focused_editable = widget;
6624 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6626 if (compose->modified == FALSE) {
6627 compose->modified = TRUE;
6628 compose_set_title(compose);
6632 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6635 gtk_stext_set_point(GTK_STEXT(widget),
6636 gtk_editable_get_position(GTK_EDITABLE(widget)));
6640 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6643 gtk_stext_set_point(GTK_STEXT(widget),
6644 gtk_editable_get_position(GTK_EDITABLE(widget)));
6648 #if 0 /* NEW COMPOSE GUI */
6649 static void compose_toggle_to_cb(gpointer data, guint action,
6652 Compose *compose = (Compose *)data;
6654 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6655 gtk_widget_show(compose->to_hbox);
6656 gtk_widget_show(compose->to_entry);
6657 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6658 compose->use_to = TRUE;
6660 gtk_widget_hide(compose->to_hbox);
6661 gtk_widget_hide(compose->to_entry);
6662 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6663 gtk_widget_queue_resize(compose->table_vbox);
6664 compose->use_to = FALSE;
6667 if (addressbook_get_target_compose() == compose)
6668 addressbook_set_target_compose(compose);
6671 static void compose_toggle_cc_cb(gpointer data, guint action,
6674 Compose *compose = (Compose *)data;
6676 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6677 gtk_widget_show(compose->cc_hbox);
6678 gtk_widget_show(compose->cc_entry);
6679 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6680 compose->use_cc = TRUE;
6682 gtk_widget_hide(compose->cc_hbox);
6683 gtk_widget_hide(compose->cc_entry);
6684 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6685 gtk_widget_queue_resize(compose->table_vbox);
6686 compose->use_cc = FALSE;
6689 if (addressbook_get_target_compose() == compose)
6690 addressbook_set_target_compose(compose);
6693 static void compose_toggle_bcc_cb(gpointer data, guint action,
6696 Compose *compose = (Compose *)data;
6698 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6699 gtk_widget_show(compose->bcc_hbox);
6700 gtk_widget_show(compose->bcc_entry);
6701 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6702 compose->use_bcc = TRUE;
6704 gtk_widget_hide(compose->bcc_hbox);
6705 gtk_widget_hide(compose->bcc_entry);
6706 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6707 gtk_widget_queue_resize(compose->table_vbox);
6708 compose->use_bcc = FALSE;
6711 if (addressbook_get_target_compose() == compose)
6712 addressbook_set_target_compose(compose);
6715 static void compose_toggle_replyto_cb(gpointer data, guint action,
6718 Compose *compose = (Compose *)data;
6720 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6721 gtk_widget_show(compose->reply_hbox);
6722 gtk_widget_show(compose->reply_entry);
6723 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6724 compose->use_replyto = TRUE;
6726 gtk_widget_hide(compose->reply_hbox);
6727 gtk_widget_hide(compose->reply_entry);
6728 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6729 gtk_widget_queue_resize(compose->table_vbox);
6730 compose->use_replyto = FALSE;
6734 static void compose_toggle_followupto_cb(gpointer data, guint action,
6737 Compose *compose = (Compose *)data;
6739 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6740 gtk_widget_show(compose->followup_hbox);
6741 gtk_widget_show(compose->followup_entry);
6742 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6743 compose->use_followupto = TRUE;
6745 gtk_widget_hide(compose->followup_hbox);
6746 gtk_widget_hide(compose->followup_entry);
6747 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6748 gtk_widget_queue_resize(compose->table_vbox);
6749 compose->use_followupto = FALSE;
6753 static void compose_toggle_attach_cb(gpointer data, guint action,
6756 Compose *compose = (Compose *)data;
6758 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6759 gtk_widget_ref(compose->edit_vbox);
6761 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6762 compose->edit_vbox);
6763 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6764 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6766 gtk_widget_show(compose->paned);
6768 gtk_widget_unref(compose->edit_vbox);
6769 gtk_widget_unref(compose->paned);
6771 compose->use_attach = TRUE;
6773 gtk_widget_ref(compose->paned);
6774 gtk_widget_ref(compose->edit_vbox);
6776 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6778 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6779 compose->edit_vbox);
6780 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6781 compose->edit_vbox, TRUE, TRUE, 0);
6783 gtk_widget_unref(compose->edit_vbox);
6785 compose->use_attach = FALSE;
6791 static void compose_toggle_sign_cb(gpointer data, guint action,
6794 Compose *compose = (Compose *)data;
6796 if (GTK_CHECK_MENU_ITEM(widget)->active)
6797 compose->use_signing = TRUE;
6799 compose->use_signing = FALSE;
6801 compose_update_gnupg_mode_menu_item(compose);
6804 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6807 Compose *compose = (Compose *)data;
6809 if (GTK_CHECK_MENU_ITEM(widget)->active)
6810 compose->use_encryption = TRUE;
6812 compose->use_encryption = FALSE;
6814 compose_update_gnupg_mode_menu_item(compose);
6817 static void activate_gnupg_mode (Compose *compose, PrefsAccount *account)
6819 if (account->default_gnupg_mode)
6820 compose->gnupg_mode = GNUPG_MODE_INLINE;
6822 compose->gnupg_mode = GNUPG_MODE_DETACH;
6824 compose_update_gnupg_mode_menu_item(compose);
6826 #endif /* USE_GPGME */
6828 static void compose_toggle_ruler_cb(gpointer data, guint action,
6831 Compose *compose = (Compose *)data;
6833 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6834 gtk_widget_show(compose->ruler_hbox);
6835 prefs_common.show_ruler = TRUE;
6837 gtk_widget_hide(compose->ruler_hbox);
6838 gtk_widget_queue_resize(compose->edit_vbox);
6839 prefs_common.show_ruler = FALSE;
6843 static void compose_attach_drag_received_cb (GtkWidget *widget,
6844 GdkDragContext *drag_context,
6847 GtkSelectionData *data,
6852 Compose *compose = (Compose *)user_data;
6855 list = uri_list_extract_filenames((const gchar *)data->data);
6856 for (tmp = list; tmp != NULL; tmp = tmp->next)
6857 compose_attach_append
6858 (compose, (const gchar *)tmp->data,
6859 (const gchar *)tmp->data, NULL);
6860 if (list) compose_changed_cb(NULL, compose);
6861 list_free_strings(list);
6865 static void compose_insert_drag_received_cb (GtkWidget *widget,
6866 GdkDragContext *drag_context,
6869 GtkSelectionData *data,
6874 Compose *compose = (Compose *)user_data;
6877 list = uri_list_extract_filenames((const gchar *)data->data);
6878 for (tmp = list; tmp != NULL; tmp = tmp->next)
6879 compose_insert_file(compose, (const gchar *)tmp->data);
6880 list_free_strings(list);
6884 #if 0 /* NEW COMPOSE GUI */
6885 static void to_activated(GtkWidget *widget, Compose *compose)
6887 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6888 gtk_widget_grab_focus(compose->newsgroups_entry);
6890 gtk_widget_grab_focus(compose->subject_entry);
6893 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6895 gtk_widget_grab_focus(compose->subject_entry);
6898 static void subject_activated(GtkWidget *widget, Compose *compose)
6900 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6901 gtk_widget_grab_focus(compose->cc_entry);
6902 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6903 gtk_widget_grab_focus(compose->bcc_entry);
6904 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6905 gtk_widget_grab_focus(compose->reply_entry);
6906 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6907 gtk_widget_grab_focus(compose->followup_entry);
6909 gtk_widget_grab_focus(compose->text);
6912 static void cc_activated(GtkWidget *widget, Compose *compose)
6914 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6915 gtk_widget_grab_focus(compose->bcc_entry);
6916 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6917 gtk_widget_grab_focus(compose->reply_entry);
6918 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6919 gtk_widget_grab_focus(compose->followup_entry);
6921 gtk_widget_grab_focus(compose->text);
6924 static void bcc_activated(GtkWidget *widget, Compose *compose)
6926 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6927 gtk_widget_grab_focus(compose->reply_entry);
6928 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6929 gtk_widget_grab_focus(compose->followup_entry);
6931 gtk_widget_grab_focus(compose->text);
6934 static void replyto_activated(GtkWidget *widget, Compose *compose)
6936 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6937 gtk_widget_grab_focus(compose->followup_entry);
6939 gtk_widget_grab_focus(compose->text);
6942 static void followupto_activated(GtkWidget *widget, Compose *compose)
6944 gtk_widget_grab_focus(compose->text);
6948 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6951 Compose *compose = (Compose *)data;
6953 if (GTK_CHECK_MENU_ITEM(widget)->active)
6954 compose->return_receipt = TRUE;
6956 compose->return_receipt = FALSE;
6959 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6961 ComposeHeaderEntry *headerentry)
6963 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6964 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6965 !(event->state & GDK_MODIFIER_MASK) &&
6966 (event->keyval == GDK_BackSpace) &&
6967 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6968 gtk_container_remove
6969 (GTK_CONTAINER(headerentry->compose->header_table),
6970 headerentry->combo);
6971 gtk_container_remove
6972 (GTK_CONTAINER(headerentry->compose->header_table),
6973 headerentry->entry);
6974 headerentry->compose->header_list =
6975 g_slist_remove(headerentry->compose->header_list,
6977 g_free(headerentry);
6978 } else if (event->keyval == GDK_Tab) {
6979 if (headerentry->compose->header_last == headerentry) {
6980 /* Override default next focus, and give it to subject_entry
6981 * instead of notebook tabs
6983 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6984 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6990 void compose_headerentry_changed_cb(GtkWidget *entry,
6991 ComposeHeaderEntry *headerentry)
6993 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6994 headerentry->compose->header_list =
6995 g_slist_append(headerentry->compose->header_list,
6997 compose_create_header_entry(headerentry->compose);
6998 gtk_signal_disconnect_by_func
7000 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
7002 /* Automatically scroll down */
7003 compose_show_first_last_header(headerentry->compose, FALSE);
7008 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
7010 GtkAdjustment *vadj;
7012 g_return_if_fail(compose);
7013 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
7014 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
7016 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
7017 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
7020 static void text_activated(GtkWidget *widget, Compose *compose)
7022 compose_send_control_enter(compose);
7025 static void text_inserted(GtkWidget *widget, const gchar *text,
7026 gint length, gint *position, Compose *compose)
7028 GtkEditable *editable = GTK_EDITABLE(widget);
7030 gtk_signal_handler_block_by_func(GTK_OBJECT(widget),
7031 GTK_SIGNAL_FUNC(text_inserted),
7033 if (compose->paste_as_quotation) {
7038 new_text = g_strndup(text, length);
7039 if (prefs_common.quotemark && *prefs_common.quotemark)
7040 qmark = prefs_common.quotemark;
7043 gtk_stext_set_point(GTK_STEXT(widget), *position);
7044 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
7045 pos = gtk_stext_get_point(GTK_STEXT(widget));
7046 gtk_editable_set_position(editable, pos);
7050 gtk_editable_insert_text(editable, text, length, position);
7052 if (prefs_common.autowrap)
7053 compose_wrap_line_all_full(compose, TRUE);
7055 gtk_signal_handler_unblock_by_func(GTK_OBJECT(widget),
7056 GTK_SIGNAL_FUNC(text_inserted),
7058 gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
7061 if (prefs_common.autosave &&
7062 gtk_stext_get_length(GTK_STEXT(widget)) % prefs_common.autosave_length == 0)
7063 compose_draft_cb((gpointer)compose, 1, NULL);
7066 static gboolean compose_send_control_enter(Compose *compose)
7070 GtkItemFactory *ifactory;
7071 GtkAccelEntry *accel;
7072 GtkWidget *send_menu;
7074 GdkModifierType ignored_mods =
7075 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
7076 GDK_MOD4_MASK | GDK_MOD5_MASK);
7078 ev = gtk_get_current_event();
7079 if (ev->type != GDK_KEY_PRESS) return FALSE;
7081 kev = (GdkEventKey *)ev;
7082 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
7085 ifactory = gtk_item_factory_from_widget(compose->menubar);
7086 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
7087 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
7088 accel = (GtkAccelEntry *)list->data;
7089 if (accel->accelerator_key == kev->keyval &&
7090 (accel->accelerator_mods & ~ignored_mods) ==
7091 (kev->state & ~ignored_mods)) {
7092 compose_send_cb(compose, 0, NULL);
7100 static void compose_check_all(Compose *compose)
7102 if (compose->gtkaspell)
7103 gtkaspell_check_all(compose->gtkaspell);
7106 static void compose_highlight_all(Compose *compose)
7108 if (compose->gtkaspell)
7109 gtkaspell_highlight_all(compose->gtkaspell);
7112 static void compose_check_backwards(Compose *compose)
7114 if (compose->gtkaspell)
7115 gtkaspell_check_backwards(compose->gtkaspell);
7117 GtkItemFactory *ifactory;
7118 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7119 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7120 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
7124 static void compose_check_forwards_go(Compose *compose)
7126 if (compose->gtkaspell)
7127 gtkaspell_check_forwards_go(compose->gtkaspell);
7129 GtkItemFactory *ifactory;
7130 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7131 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7132 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);