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_actions_execute_cb (GtkWidget *widget,
320 static void toolbar_compose_buttons_cb (GtkWidget *widget,
322 ToolbarItem *t_item);
323 static void account_activated (GtkMenuItem *menuitem,
326 static void attach_selected (GtkCList *clist,
331 static void attach_button_pressed (GtkWidget *widget,
332 GdkEventButton *event,
334 static void attach_key_pressed (GtkWidget *widget,
338 static void compose_send_cb (gpointer data,
341 static void compose_send_later_cb (gpointer data,
345 static void compose_draft_cb (gpointer data,
349 static void compose_attach_cb (gpointer data,
352 static void compose_insert_file_cb (gpointer data,
356 static void compose_close_cb (gpointer data,
360 static void compose_address_cb (gpointer data,
363 static void compose_template_activate_cb(GtkWidget *widget,
366 static void compose_ext_editor_cb (gpointer data,
370 static gint compose_delete_cb (GtkWidget *widget,
373 static void compose_destroy_cb (GtkWidget *widget,
376 static void compose_undo_cb (Compose *compose);
377 static void compose_redo_cb (Compose *compose);
378 static void compose_cut_cb (Compose *compose);
379 static void compose_copy_cb (Compose *compose);
380 static void compose_paste_cb (Compose *compose);
381 static void compose_paste_as_quote_cb (Compose *compose);
382 static void compose_allsel_cb (Compose *compose);
384 static void compose_gtk_stext_action_cb (Compose *compose,
385 ComposeCallGtkSTextAction action);
387 static void compose_grab_focus_cb (GtkWidget *widget,
390 static void compose_changed_cb (GtkEditable *editable,
392 static void compose_button_press_cb (GtkWidget *widget,
393 GdkEventButton *event,
396 static void compose_key_press_cb (GtkWidget *widget,
402 static void compose_toggle_to_cb (gpointer data,
405 static void compose_toggle_cc_cb (gpointer data,
408 static void compose_toggle_bcc_cb (gpointer data,
411 static void compose_toggle_replyto_cb (gpointer data,
414 static void compose_toggle_followupto_cb(gpointer data,
417 static void compose_toggle_attach_cb (gpointer data,
421 static void compose_toggle_ruler_cb (gpointer data,
425 static void compose_toggle_sign_cb (gpointer data,
428 static void compose_toggle_encrypt_cb (gpointer data,
431 static void compose_set_gnupg_mode_cb (gpointer data,
434 static void compose_update_gnupg_mode_menu_item(Compose * compose);
435 static void activate_gnupg_mode (Compose *compose,
436 PrefsAccount *account);
438 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
440 static void compose_set_priority_cb (gpointer data,
444 static void compose_attach_drag_received_cb (GtkWidget *widget,
445 GdkDragContext *drag_context,
448 GtkSelectionData *data,
452 static void compose_insert_drag_received_cb (GtkWidget *widget,
453 GdkDragContext *drag_context,
456 GtkSelectionData *data,
462 static void to_activated (GtkWidget *widget,
464 static void newsgroups_activated (GtkWidget *widget,
466 static void cc_activated (GtkWidget *widget,
468 static void bcc_activated (GtkWidget *widget,
470 static void replyto_activated (GtkWidget *widget,
472 static void followupto_activated (GtkWidget *widget,
474 static void subject_activated (GtkWidget *widget,
478 static void text_activated (GtkWidget *widget,
480 static void text_inserted (GtkWidget *widget,
485 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
486 gboolean to_all, gboolean to_ml,
487 gboolean ignore_replyto,
488 gboolean followup_and_reply_to,
491 void compose_headerentry_changed_cb (GtkWidget *entry,
492 ComposeHeaderEntry *headerentry);
493 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
495 ComposeHeaderEntry *headerentry);
497 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
500 static void compose_check_all (Compose *compose);
501 static void compose_highlight_all (Compose *compose);
502 static void compose_check_backwards (Compose *compose);
503 static void compose_check_forwards_go (Compose *compose);
506 static gboolean compose_send_control_enter (Compose *compose);
508 static GtkItemFactoryEntry compose_popup_entries[] =
510 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
511 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
512 {N_("/---"), NULL, NULL, 0, "<Separator>"},
513 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
516 static GtkItemFactoryEntry compose_entries[] =
518 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
519 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
520 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
521 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
522 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
523 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
525 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
526 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
527 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
528 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
529 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
530 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
531 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
532 {N_("/_Edit/Paste as _quotation"),
533 NULL, compose_paste_as_quote_cb, 0, NULL},
534 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
535 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
536 {N_("/_Edit/A_dvanced/Move a character backward"),
538 compose_gtk_stext_action_cb,
539 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
541 {N_("/_Edit/A_dvanced/Move a character forward"),
543 compose_gtk_stext_action_cb,
544 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
546 {N_("/_Edit/A_dvanced/Move a word backward"),
548 compose_gtk_stext_action_cb,
549 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
551 {N_("/_Edit/A_dvanced/Move a word forward"),
553 compose_gtk_stext_action_cb,
554 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
556 {N_("/_Edit/A_dvanced/Move to beginning of line"),
557 NULL, /* "<control>A" */
558 compose_gtk_stext_action_cb,
559 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
561 {N_("/_Edit/A_dvanced/Move to end of line"),
563 compose_gtk_stext_action_cb,
564 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
566 {N_("/_Edit/A_dvanced/Move to previous line"),
568 compose_gtk_stext_action_cb,
569 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
571 {N_("/_Edit/A_dvanced/Move to next line"),
573 compose_gtk_stext_action_cb,
574 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
576 {N_("/_Edit/A_dvanced/Delete a character backward"),
578 compose_gtk_stext_action_cb,
579 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
581 {N_("/_Edit/A_dvanced/Delete a character forward"),
583 compose_gtk_stext_action_cb,
584 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
586 {N_("/_Edit/A_dvanced/Delete a word backward"),
587 NULL, /* "<control>W" */
588 compose_gtk_stext_action_cb,
589 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
591 {N_("/_Edit/A_dvanced/Delete a word forward"),
592 NULL, /* "<alt>D", */
593 compose_gtk_stext_action_cb,
594 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
596 {N_("/_Edit/A_dvanced/Delete line"),
598 compose_gtk_stext_action_cb,
599 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
601 {N_("/_Edit/A_dvanced/Delete entire line"),
603 compose_gtk_stext_action_cb,
604 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
606 {N_("/_Edit/A_dvanced/Delete to end of line"),
608 compose_gtk_stext_action_cb,
609 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
611 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
612 {N_("/_Edit/_Wrap current paragraph"),
613 "<control>L", compose_wrap_line, 0, NULL},
614 {N_("/_Edit/Wrap all long _lines"),
615 "<control><alt>L", compose_wrap_line_all, 0, NULL},
616 {N_("/_Edit/Edit with e_xternal editor"),
617 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
619 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
620 {N_("/_Spelling/_Check all or check selection"),
621 NULL, compose_check_all, 0, NULL},
622 {N_("/_Spelling/_Highlight all misspelled words"),
623 NULL, compose_highlight_all, 0, NULL},
624 {N_("/_Spelling/Check _backwards misspelled word"),
625 NULL, compose_check_backwards , 0, NULL},
626 {N_("/_Spelling/_Forward to next misspelled word"),
627 NULL, compose_check_forwards_go, 0, NULL},
628 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
629 {N_("/_Spelling/_Spelling Configuration"),
630 NULL, NULL, 0, "<Branch>"},
632 #if 0 /* NEW COMPOSE GUI */
633 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
634 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
635 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
636 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
637 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
638 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
639 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
640 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
641 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
642 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
643 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
645 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
646 {N_("/_Message/_Send"), "<control>Return",
647 compose_send_cb, 0, NULL},
648 {N_("/_Message/Send _later"), "<shift><control>S",
649 compose_send_later_cb, 0, NULL},
650 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
651 {N_("/_Message/Save to _draft folder"),
652 "<shift><control>D", compose_draft_cb, 0, NULL},
653 {N_("/_Message/Save and _keep editing"),
654 "<control>S", compose_draft_cb, 1, NULL},
655 #if 0 /* NEW COMPOSE GUI */
656 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
657 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
658 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
659 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
660 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
661 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
662 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
663 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
664 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
667 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
668 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
669 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
670 {N_("/_Message/Mode/MIME"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_DETACH, "<RadioItem>"},
671 {N_("/_Message/Mode/Inline"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_INLINE, "/Message/Mode/MIME"},
672 #endif /* USE_GPGME */
673 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
674 {N_("/_Message/_Priority"), NULL, NULL, 0, "<Branch>"},
675 {N_("/_Message/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
676 {N_("/_Message/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
677 {N_("/_Message/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
678 {N_("/_Message/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
679 {N_("/_Message/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
680 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
681 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
682 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
683 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
684 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
685 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
686 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
687 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
688 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
691 static GtkTargetEntry compose_mime_types[] =
693 {"text/uri-list", 0, 0}
696 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
697 GPtrArray *attach_files)
699 return compose_generic_new(account, mailto, NULL, attach_files);
702 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
704 return compose_generic_new(account, NULL, item, NULL);
707 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
708 GPtrArray *attach_files)
712 GtkItemFactory *ifactory;
713 gboolean grab_focus_on_last = TRUE;
715 if (item && item->prefs && item->prefs->enable_default_account)
716 account = account_find_from_id(item->prefs->default_account);
718 if (!account) account = cur_account;
719 g_return_val_if_fail(account != NULL, NULL);
721 compose = compose_create(account, COMPOSE_NEW);
722 ifactory = gtk_item_factory_from_widget(compose->menubar);
724 compose->replyinfo = NULL;
726 text = GTK_STEXT(compose->text);
727 gtk_stext_freeze(text);
729 if (prefs_common.auto_sig)
730 compose_insert_sig(compose);
731 gtk_editable_set_position(GTK_EDITABLE(text), 0);
732 gtk_stext_set_point(text, 0);
734 gtk_stext_thaw(text);
736 if (account->protocol != A_NNTP) {
737 if (mailto && *mailto != '\0') {
738 compose_entries_set(compose, mailto);
740 } else if (item && item->prefs->enable_default_to) {
741 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
742 compose_entry_select(compose, item->prefs->default_to);
743 grab_focus_on_last = FALSE;
745 if (item && item->ret_rcpt) {
746 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
750 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
753 * CLAWS: just don't allow return receipt request, even if the user
754 * may want to send an email. simple but foolproof.
756 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
763 for (i = 0; i < attach_files->len; i++) {
764 file = g_ptr_array_index(attach_files, i);
765 compose_attach_append(compose, file, file, NULL);
769 compose_show_first_last_header(compose, TRUE);
771 /* Set save folder */
772 if (item && item->prefs && item->prefs->save_copy_to_folder) {
773 gchar *folderidentifier;
775 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
776 folderidentifier = folder_item_get_identifier(item);
777 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
778 g_free(folderidentifier);
781 /* Grab focus on last header only if no default_to was set */
782 if (grab_focus_on_last)
783 gtk_widget_grab_focus(compose->header_last->entry);
785 if (prefs_common.auto_exteditor)
786 compose_exec_ext_editor(compose);
792 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
793 const gchar *followupto, gchar * to)
797 if (!account) account = cur_account;
798 g_return_val_if_fail(account != NULL, NULL);
799 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
801 compose = compose_create(account, COMPOSE_NEW);
803 if (prefs_common.auto_sig)
804 compose_insert_sig(compose);
805 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
806 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
808 compose_entry_append(compose, to, COMPOSE_TO);
809 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
810 gtk_widget_grab_focus(compose->subject_entry);
816 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
817 gboolean to_ml, gboolean ignore_replyto,
820 compose_generic_reply(msginfo, quote, to_all, to_ml,
821 ignore_replyto, FALSE, body);
824 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
826 gboolean ignore_replyto,
829 compose_generic_reply(msginfo, quote, to_all, FALSE,
830 ignore_replyto, TRUE, body);
833 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
834 gboolean to_all, gboolean to_ml,
835 gboolean ignore_replyto,
836 gboolean followup_and_reply_to,
840 PrefsAccount *account;
841 PrefsAccount *reply_account;
844 g_return_if_fail(msginfo != NULL);
845 g_return_if_fail(msginfo->folder != NULL);
848 /* select the account set in folderitem's property (if enabled) */
849 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
850 account = account_find_from_id(msginfo->folder->prefs->default_account);
852 /* select the account for the whole folder (IMAP / NNTP) */
854 /* FIXME: this is not right, because folder may be nested. we should
855 * ascend the tree until we find a parent with proper account
857 account = msginfo->folder->folder->account;
859 /* select account by to: and cc: header if enabled */
860 if (prefs_common.reply_account_autosel) {
861 if (!account && msginfo->to) {
863 Xstrdup_a(to, msginfo->to, return);
865 account = account_find_from_address(to);
869 if (!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
871 account = account_find_from_address(cc);
876 /* select current account */
877 if (!account) account = cur_account;
878 g_return_if_fail(account != NULL);
880 if (ignore_replyto && account->protocol == A_NNTP &&
881 !followup_and_reply_to) {
883 account_find_from_address(account->address);
885 reply_account = compose_current_mail_account();
889 reply_account = account;
891 compose = compose_create(account, COMPOSE_REPLY);
893 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
894 if (!compose->replyinfo)
895 compose->replyinfo = procmsg_msginfo_copy(msginfo);
897 if (msginfo->folder && msginfo->folder->ret_rcpt) {
898 GtkItemFactory *ifactory;
900 ifactory = gtk_item_factory_from_widget(compose->menubar);
901 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
904 /* Set save folder */
905 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
906 gchar *folderidentifier;
908 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
909 folderidentifier = folder_item_get_identifier(msginfo->folder);
910 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
911 g_free(folderidentifier);
914 if (compose_parse_header(compose, msginfo) < 0) return;
915 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
916 ignore_replyto, followup_and_reply_to);
917 compose_show_first_last_header(compose, TRUE);
919 text = GTK_STEXT(compose->text);
920 gtk_stext_freeze(text);
926 if (prefs_common.quotemark && *prefs_common.quotemark)
927 qmark = prefs_common.quotemark;
931 quote_str = compose_quote_fmt(compose, compose->replyinfo,
932 prefs_common.quotefmt,
936 if (prefs_common.auto_sig)
937 compose_insert_sig(compose);
939 if (quote && prefs_common.linewrap_quote)
940 compose_wrap_line_all(compose);
942 gtk_editable_set_position(GTK_EDITABLE(text), 0);
943 gtk_stext_set_point(text, 0);
945 gtk_stext_thaw(text);
946 gtk_widget_grab_focus(compose->text);
948 if (prefs_common.auto_exteditor)
949 compose_exec_ext_editor(compose);
952 static void set_toolbar_style(Compose *compose);
954 #define INSERT_FW_HEADER(var, hdr) \
955 if (msginfo->var && *msginfo->var) { \
956 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
957 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
958 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
961 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
962 gboolean as_attach, const gchar *body)
967 g_return_val_if_fail(msginfo != NULL, NULL);
968 g_return_val_if_fail(msginfo->folder != NULL, NULL);
971 account = msginfo->folder->folder->account;
972 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
974 Xstrdup_a(to, msginfo->to, return NULL);
976 account = account_find_from_address(to);
979 if (!account && prefs_common.forward_account_autosel) {
981 if (!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
983 account = account_find_from_address(cc);
987 if (account == NULL) {
988 account = cur_account;
990 account = msginfo->folder->folder->account;
991 if (!account) account = cur_account;
994 g_return_val_if_fail(account != NULL, NULL);
996 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
997 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
998 if (MSG_IS_IMAP(msginfo->flags))
999 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1001 compose = compose_create(account, COMPOSE_FORWARD);
1003 if (msginfo->subject && *msginfo->subject) {
1004 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1005 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1009 text = GTK_STEXT(compose->text);
1010 gtk_stext_freeze(text);
1016 msgfile = procmsg_get_message_file_path(msginfo);
1017 if (!is_file_exist(msgfile))
1018 g_warning(_("%s: file not exist\n"), msgfile);
1020 compose_attach_append(compose, msgfile, msgfile,
1027 MsgInfo *full_msginfo;
1029 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1031 full_msginfo = procmsg_msginfo_copy(msginfo);
1033 if (prefs_common.fw_quotemark &&
1034 *prefs_common.fw_quotemark)
1035 qmark = prefs_common.fw_quotemark;
1039 quote_str = compose_quote_fmt(compose, full_msginfo,
1040 prefs_common.fw_quotefmt,
1042 compose_attach_parts(compose, msginfo);
1044 procmsg_msginfo_free(full_msginfo);
1047 if (prefs_common.auto_sig)
1048 compose_insert_sig(compose);
1050 if (prefs_common.linewrap_quote)
1051 compose_wrap_line_all(compose);
1053 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1054 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1056 gtk_stext_thaw(text);
1057 #if 0 /* NEW COMPOSE GUI */
1058 if (account->protocol != A_NNTP)
1059 gtk_widget_grab_focus(compose->to_entry);
1061 gtk_widget_grab_focus(compose->newsgroups_entry);
1063 gtk_widget_grab_focus(compose->header_last->entry);
1065 if (prefs_common.auto_exteditor)
1066 compose_exec_ext_editor(compose);
1071 #undef INSERT_FW_HEADER
1073 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1080 g_return_val_if_fail(msginfo_list != NULL, NULL);
1082 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1083 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1087 if (account == NULL) {
1088 account = cur_account;
1090 account = msginfo->folder->folder->account;
1091 if (!account) account = cur_account;
1094 g_return_val_if_fail(account != NULL, NULL);
1096 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1097 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1098 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1101 compose = compose_create(account, COMPOSE_FORWARD);
1103 text = GTK_STEXT(compose->text);
1104 gtk_stext_freeze(text);
1106 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1107 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1108 if (!is_file_exist(msgfile))
1109 g_warning(_("%s: file not exist\n"), msgfile);
1111 compose_attach_append(compose, msgfile, msgfile,
1116 if (prefs_common.auto_sig)
1117 compose_insert_sig(compose);
1119 if (prefs_common.linewrap_quote)
1120 compose_wrap_line_all(compose);
1122 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1123 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1125 gtk_stext_thaw(text);
1126 gtk_widget_grab_focus(compose->header_last->entry);
1128 #if 0 /* NEW COMPOSE GUI */
1129 if (account->protocol != A_NNTP)
1130 gtk_widget_grab_focus(compose->to_entry);
1132 gtk_widget_grab_focus(compose->newsgroups_entry);
1138 void compose_reedit(MsgInfo *msginfo)
1141 PrefsAccount *account = NULL;
1144 gchar buf[BUFFSIZE];
1146 g_return_if_fail(msginfo != NULL);
1147 g_return_if_fail(msginfo->folder != NULL);
1149 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1150 gchar queueheader_buf[BUFFSIZE];
1153 /* Select Account from queue headers */
1154 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1155 sizeof(queueheader_buf), "NAID:")) {
1156 id = atoi(&queueheader_buf[5]);
1157 account = account_find_from_id(id);
1159 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1160 sizeof(queueheader_buf), "MAID:")) {
1161 id = atoi(&queueheader_buf[5]);
1162 account = account_find_from_id(id);
1164 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1165 sizeof(queueheader_buf), "S:")) {
1166 account = account_find_from_address(queueheader_buf);
1169 account = msginfo->folder->folder->account;
1171 if (!account && prefs_common.reedit_account_autosel) {
1172 gchar from[BUFFSIZE];
1173 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1174 extract_address(from);
1175 account = account_find_from_address(from);
1178 if (!account) account = cur_account;
1179 g_return_if_fail(account != NULL);
1181 compose = compose_create(account, COMPOSE_REEDIT);
1182 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1184 if (msginfo->folder->stype == F_QUEUE
1185 || msginfo->folder->stype == F_DRAFT) {
1186 gchar queueheader_buf[BUFFSIZE];
1188 /* Set message save folder */
1189 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1192 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1193 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1194 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1198 if (compose_parse_header(compose, msginfo) < 0) return;
1199 compose_reedit_set_entry(compose, msginfo);
1201 text = GTK_STEXT(compose->text);
1202 gtk_stext_freeze(text);
1204 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1205 g_warning(_("Can't get text part\n"));
1207 while (fgets(buf, sizeof(buf), fp) != NULL) {
1209 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1213 compose_attach_parts(compose, msginfo);
1215 gtk_stext_thaw(text);
1216 gtk_widget_grab_focus(compose->text);
1218 if (prefs_common.auto_exteditor)
1219 compose_exec_ext_editor(compose);
1222 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1226 GtkItemFactory *ifactory;
1228 g_return_val_if_fail(msginfo != NULL, NULL);
1231 account = cur_account;
1232 g_return_val_if_fail(account != NULL, NULL);
1234 compose = compose_create(account, COMPOSE_REDIRECT);
1235 ifactory = gtk_item_factory_from_widget(compose->menubar);
1237 compose->replyinfo = NULL;
1239 compose_show_first_last_header(compose, TRUE);
1241 gtk_widget_grab_focus(compose->header_last->entry);
1243 filename = procmsg_get_message_file(msginfo);
1244 if (filename == NULL)
1247 compose->redirect_filename = filename;
1249 if (msginfo->subject)
1250 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1252 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1254 gtk_stext_freeze(GTK_STEXT(compose->text));
1255 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1256 gtk_editable_set_editable(GTK_EDITABLE(compose->text), FALSE);
1257 gtk_stext_thaw(GTK_STEXT(compose->text));
1259 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1260 menu_set_sensitive(ifactory, "/Add...", FALSE);
1261 menu_set_sensitive(ifactory, "/Remove", FALSE);
1262 menu_set_sensitive(ifactory, "/Property...", FALSE);
1264 ifactory = gtk_item_factory_from_widget(compose->menubar);
1265 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
1266 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
1267 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
1268 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
1269 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
1270 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
1271 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
1272 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
1274 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
1275 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
1276 menu_set_sensitive(ifactory, "/Message/Mode/MIME", FALSE);
1277 menu_set_sensitive(ifactory, "/Message/Mode/Inline", FALSE);
1279 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
1280 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
1282 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1283 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1284 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1285 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1286 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, FALSE);
1291 GList *compose_get_compose_list(void)
1293 return compose_list;
1296 void compose_entry_append(Compose *compose, const gchar *address,
1297 ComposeEntryType type)
1301 if (!address || *address == '\0') return;
1303 #if 0 /* NEW COMPOSE GUI */
1306 entry = GTK_ENTRY(compose->cc_entry);
1309 entry = GTK_ENTRY(compose->bcc_entry);
1311 case COMPOSE_NEWSGROUPS:
1312 entry = GTK_ENTRY(compose->newsgroups_entry);
1316 entry = GTK_ENTRY(compose->to_entry);
1320 text = gtk_entry_get_text(entry);
1322 gtk_entry_append_text(entry, ", ");
1323 gtk_entry_append_text(entry, address);
1331 header = N_("Bcc:");
1333 case COMPOSE_REPLYTO:
1334 header = N_("Reply-To:");
1336 case COMPOSE_NEWSGROUPS:
1337 header = N_("Newsgroups:");
1339 case COMPOSE_FOLLOWUPTO:
1340 header = N_( "Followup-To:");
1347 header = prefs_common.trans_hdr ? gettext(header) : header;
1349 compose_add_header_entry(compose, header, (gchar *)address);
1352 void compose_entry_select (Compose *compose, const gchar *mailto)
1354 GSList *header_list;
1356 for (header_list = compose->header_list; header_list != NULL; header_list = header_list->next) {
1357 GtkEntry * entry = GTK_ENTRY(((ComposeHeaderEntry *)header_list->data)->entry);
1359 if (gtk_entry_get_text(entry) && !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1360 gtk_entry_select_region(entry, 0, -1);
1361 gtk_widget_grab_focus(GTK_WIDGET(entry));
1366 static void compose_entries_set(Compose *compose, const gchar *mailto)
1371 gchar *subject = NULL;
1374 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1377 compose_entry_append(compose, to, COMPOSE_TO);
1379 compose_entry_append(compose, cc, COMPOSE_CC);
1381 compose_entry_append(compose, bcc, COMPOSE_BCC);
1383 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1385 gtk_stext_insert(GTK_STEXT(compose->text),
1386 NULL, NULL, NULL, body, -1);
1387 gtk_stext_insert(GTK_STEXT(compose->text),
1388 NULL, NULL, NULL, "\n", 1);
1398 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1400 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1401 {"Cc:", NULL, FALSE},
1402 {"References:", NULL, FALSE},
1403 {"Bcc:", NULL, FALSE},
1404 {"Newsgroups:", NULL, FALSE},
1405 {"Followup-To:", NULL, FALSE},
1406 {"List-Post:", NULL, FALSE},
1407 {"X-Priority:", NULL, FALSE},
1408 {NULL, NULL, FALSE}};
1424 g_return_val_if_fail(msginfo != NULL, -1);
1426 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1427 procheader_get_header_fields(fp, hentry);
1430 if (hentry[H_REPLY_TO].body != NULL) {
1431 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1432 compose->replyto = hentry[H_REPLY_TO].body;
1433 hentry[H_REPLY_TO].body = NULL;
1435 if (hentry[H_CC].body != NULL) {
1436 conv_unmime_header_overwrite(hentry[H_CC].body);
1437 compose->cc = hentry[H_CC].body;
1438 hentry[H_CC].body = NULL;
1440 if (hentry[H_REFERENCES].body != NULL) {
1441 if (compose->mode == COMPOSE_REEDIT)
1442 compose->references = hentry[H_REFERENCES].body;
1444 compose->references = compose_parse_references
1445 (hentry[H_REFERENCES].body, msginfo->msgid);
1446 g_free(hentry[H_REFERENCES].body);
1448 hentry[H_REFERENCES].body = NULL;
1450 if (hentry[H_BCC].body != NULL) {
1451 if (compose->mode == COMPOSE_REEDIT) {
1452 conv_unmime_header_overwrite(hentry[H_BCC].body);
1453 compose->bcc = hentry[H_BCC].body;
1455 g_free(hentry[H_BCC].body);
1456 hentry[H_BCC].body = NULL;
1458 if (hentry[H_NEWSGROUPS].body != NULL) {
1459 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1460 hentry[H_NEWSGROUPS].body = NULL;
1462 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1463 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1464 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1465 hentry[H_FOLLOWUP_TO].body = NULL;
1467 if (hentry[H_LIST_POST].body != NULL) {
1470 extract_address(hentry[H_LIST_POST].body);
1471 if (hentry[H_LIST_POST].body[0] != '\0') {
1472 scan_mailto_url(hentry[H_LIST_POST].body,
1473 &to, NULL, NULL, NULL, NULL);
1475 g_free(compose->ml_post);
1476 compose->ml_post = to;
1479 g_free(hentry[H_LIST_POST].body);
1480 hentry[H_LIST_POST].body = NULL;
1483 /* CLAWS - X-Priority */
1484 if (compose->mode == COMPOSE_REEDIT)
1485 if (hentry[H_X_PRIORITY].body != NULL) {
1488 priority = atoi(hentry[H_X_PRIORITY].body);
1489 g_free(hentry[H_X_PRIORITY].body);
1491 hentry[H_X_PRIORITY].body = NULL;
1493 if (priority < PRIORITY_HIGHEST ||
1494 priority > PRIORITY_LOWEST)
1495 priority = PRIORITY_NORMAL;
1497 compose->priority = priority;
1500 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1501 compose->inreplyto = g_strdup(msginfo->inreplyto);
1502 else if (compose->mode != COMPOSE_REEDIT &&
1503 msginfo->msgid && *msginfo->msgid) {
1504 compose->inreplyto = g_strdup(msginfo->msgid);
1506 if (!compose->references) {
1507 if (msginfo->inreplyto && *msginfo->inreplyto)
1508 compose->references =
1509 g_strdup_printf("<%s>\n\t<%s>",
1513 compose->references =
1514 g_strconcat("<", msginfo->msgid, ">",
1522 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1524 GSList *ref_id_list, *cur;
1528 ref_id_list = references_list_append(NULL, ref);
1529 if (!ref_id_list) return NULL;
1530 if (msgid && *msgid)
1531 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1536 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1537 /* "<" + Message-ID + ">" + CR+LF+TAB */
1538 len += strlen((gchar *)cur->data) + 5;
1540 if (len > MAX_REFERENCES_LEN) {
1541 /* remove second message-ID */
1542 if (ref_id_list && ref_id_list->next &&
1543 ref_id_list->next->next) {
1544 g_free(ref_id_list->next->data);
1545 ref_id_list = g_slist_remove
1546 (ref_id_list, ref_id_list->next->data);
1548 slist_free_strings(ref_id_list);
1549 g_slist_free(ref_id_list);
1556 new_ref = g_string_new("");
1557 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1558 if (new_ref->len > 0)
1559 g_string_append(new_ref, "\n\t");
1560 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1563 slist_free_strings(ref_id_list);
1564 g_slist_free(ref_id_list);
1566 new_ref_str = new_ref->str;
1567 g_string_free(new_ref, FALSE);
1572 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1573 const gchar *fmt, const gchar *qmark,
1576 GtkSText *text = GTK_STEXT(compose->text);
1577 static MsgInfo dummyinfo;
1578 gchar *quote_str = NULL;
1584 msginfo = &dummyinfo;
1586 if (qmark != NULL) {
1587 quote_fmt_init(msginfo, NULL, NULL);
1588 quote_fmt_scan_string(qmark);
1591 buf = quote_fmt_get_buffer();
1593 alertpanel_error(_("Quote mark format error."));
1595 Xstrdup_a(quote_str, buf, return NULL)
1598 if (fmt && *fmt != '\0') {
1599 quote_fmt_init(msginfo, quote_str, body);
1600 quote_fmt_scan_string(fmt);
1603 buf = quote_fmt_get_buffer();
1605 alertpanel_error(_("Message reply/forward format error."));
1611 gtk_stext_freeze(text);
1613 for (p = buf; *p != '\0'; ) {
1614 lastp = strchr(p, '\n');
1615 len = lastp ? lastp - p + 1 : -1;
1616 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1623 gtk_stext_thaw(text);
1628 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1629 gboolean to_all, gboolean to_ml,
1630 gboolean ignore_replyto,
1631 gboolean followup_and_reply_to)
1633 GSList *cc_list = NULL;
1636 gchar *replyto = NULL;
1637 GHashTable *to_table;
1639 g_return_if_fail(compose->account != NULL);
1640 g_return_if_fail(msginfo != NULL);
1642 if (compose->account->protocol != A_NNTP || followup_and_reply_to) {
1643 if (!compose->replyto && to_ml && compose->ml_post)
1644 compose_entry_append(compose,
1647 else if (!(to_all || ignore_replyto)
1649 && msginfo->folder->prefs->enable_default_reply_to) {
1650 compose_entry_append(compose,
1651 msginfo->folder->prefs->default_reply_to,
1654 compose_entry_append(compose,
1655 (compose->replyto && !ignore_replyto)
1657 : msginfo->from ? msginfo->from : "",
1661 compose_entry_append
1662 (compose, msginfo->from ? msginfo->from : "",
1665 if (compose->followup_to && !strncmp(compose->followup_to, "poster", 6)) {
1666 compose_entry_append
1668 ((compose->replyto && !ignore_replyto)
1670 : msginfo->from ? msginfo->from : ""),
1673 compose_entry_append
1675 compose->followup_to ? compose->followup_to
1676 : compose->newsgroups ? compose->newsgroups
1678 COMPOSE_NEWSGROUPS);
1683 if (msginfo->subject && *msginfo->subject) {
1684 gchar *buf, *buf2, *p;
1686 buf = g_strdup(msginfo->subject);
1687 while (!strncasecmp(buf, "Re:", 3)) {
1689 while (isspace(*p)) p++;
1690 memmove(buf, p, strlen(p) + 1);
1693 buf2 = g_strdup_printf("Re: %s", buf);
1694 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1698 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1700 if (to_ml && compose->ml_post) return;
1701 if (!to_all || compose->account->protocol == A_NNTP) return;
1703 if (compose->replyto) {
1704 Xstrdup_a(replyto, compose->replyto, return);
1705 extract_address(replyto);
1707 if (msginfo->from) {
1708 Xstrdup_a(from, msginfo->from, return);
1709 extract_address(from);
1712 if (replyto && from)
1713 cc_list = address_list_append(cc_list, from);
1714 cc_list = address_list_append(cc_list, msginfo->to);
1715 cc_list = address_list_append(cc_list, compose->cc);
1717 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1719 g_hash_table_insert(to_table, replyto, GINT_TO_POINTER(1));
1720 if (compose->account)
1721 g_hash_table_insert(to_table, compose->account->address,
1722 GINT_TO_POINTER(1));
1724 /* remove address on To: and that of current account */
1725 for (cur = cc_list; cur != NULL; ) {
1726 GSList *next = cur->next;
1728 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1729 cc_list = g_slist_remove(cc_list, cur->data);
1731 g_hash_table_insert(to_table, cur->data, cur);
1735 g_hash_table_destroy(to_table);
1738 for (cur = cc_list; cur != NULL; cur = cur->next)
1739 compose_entry_append(compose, (gchar *)cur->data,
1741 slist_free_strings(cc_list);
1742 g_slist_free(cc_list);
1746 #define SET_ENTRY(entry, str) \
1749 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1752 #define SET_ADDRESS(type, str) \
1755 compose_entry_append(compose, str, type); \
1758 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1760 g_return_if_fail(msginfo != NULL);
1762 SET_ENTRY(subject_entry, msginfo->subject);
1763 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1764 SET_ADDRESS(COMPOSE_CC, compose->cc);
1765 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1766 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1768 compose_update_priority_menu_item(compose);
1770 compose_update_gnupg_mode_menu_item(compose);
1772 compose_show_first_last_header(compose, TRUE);
1774 #if 0 /* NEW COMPOSE GUI */
1776 GtkItemFactory *ifactory;
1777 GtkWidget *menuitem;
1779 ifactory = gtk_item_factory_from_widget(compose->menubar);
1780 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1781 gtk_check_menu_item_set_active
1782 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1784 if (compose->replyto) {
1785 GtkItemFactory *ifactory;
1786 GtkWidget *menuitem;
1788 ifactory = gtk_item_factory_from_widget(compose->menubar);
1789 menuitem = gtk_item_factory_get_item
1790 (ifactory, "/View/Reply to");
1791 gtk_check_menu_item_set_active
1792 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1800 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1804 size_t buf_len = 128;
1806 if (strlen(sigfile) < 2)
1809 sigprg = popen(sigfile+1, "r");
1812 buf = g_malloc(buf_len);
1815 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1816 "Unable to insert signature (malloc failed)\n", -1);
1822 while (!feof(sigprg)) {
1823 bzero(buf, buf_len);
1824 fread(buf, buf_len-1, 1, sigprg);
1825 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1833 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1834 "Can't exec file: ", -1);
1835 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1840 static void compose_insert_sig(Compose *compose)
1844 if (compose->account && compose->account->sig_path)
1845 sigfile = g_strdup(compose->account->sig_path);
1847 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1848 DEFAULT_SIGNATURE, NULL);
1850 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1855 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1856 if (prefs_common.sig_sep) {
1857 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1858 prefs_common.sig_sep, -1);
1859 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1863 if (sigfile[0] == '|')
1864 compose_exec_sig(compose, sigfile);
1866 compose_insert_file(compose, sigfile);
1870 static void compose_insert_file(Compose *compose, const gchar *file)
1872 GtkSText *text = GTK_STEXT(compose->text);
1873 gchar buf[BUFFSIZE];
1877 g_return_if_fail(file != NULL);
1879 if ((fp = fopen(file, "rb")) == NULL) {
1880 FILE_OP_ERROR(file, "fopen");
1884 gtk_stext_freeze(text);
1886 while (fgets(buf, sizeof(buf), fp) != NULL) {
1887 /* strip <CR> if DOS/Windows file,
1888 replace <CR> with <LF> if Macintosh file. */
1891 if (len > 0 && buf[len - 1] != '\n') {
1893 if (buf[len] == '\r') buf[len] = '\n';
1895 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1898 gtk_stext_thaw(text);
1903 static void compose_attach_append(Compose *compose, const gchar *file,
1904 const gchar *filename,
1905 const gchar *content_type)
1908 gchar *text[N_ATTACH_COLS];
1913 if (!is_file_exist(file)) {
1914 g_warning(_("File %s doesn't exist\n"), file);
1917 if ((size = get_file_size(file)) < 0) {
1918 g_warning(_("Can't get file size of %s\n"), file);
1922 alertpanel_notice(_("File %s is empty."), file);
1925 if ((fp = fopen(file, "rb")) == NULL) {
1926 alertpanel_error(_("Can't read %s."), file);
1931 #if 0 /* NEW COMPOSE GUI */
1932 if (!compose->use_attach) {
1933 GtkItemFactory *ifactory;
1934 GtkWidget *menuitem;
1936 ifactory = gtk_item_factory_from_widget(compose->menubar);
1937 menuitem = gtk_item_factory_get_item(ifactory,
1938 "/View/Attachment");
1939 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1943 ainfo = g_new0(AttachInfo, 1);
1944 ainfo->file = g_strdup(file);
1947 ainfo->content_type = g_strdup(content_type);
1948 if (!strcasecmp(content_type, "message/rfc822")) {
1949 ainfo->encoding = ENC_7BIT;
1950 ainfo->name = g_strdup_printf
1952 g_basename(filename ? filename : file));
1954 if (!g_strncasecmp(content_type, "text", 4))
1956 procmime_get_encoding_for_file(file);
1958 ainfo->encoding = ENC_BASE64;
1959 ainfo->name = g_strdup
1960 (g_basename(filename ? filename : file));
1963 ainfo->content_type = procmime_get_mime_type(file);
1964 if (!ainfo->content_type) {
1965 ainfo->content_type =
1966 g_strdup("application/octet-stream");
1967 ainfo->encoding = ENC_BASE64;
1968 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
1969 ainfo->encoding = procmime_get_encoding_for_file(file);
1971 ainfo->encoding = ENC_BASE64;
1972 ainfo->name = g_strdup(g_basename(filename ? filename : file));
1976 text[COL_MIMETYPE] = ainfo->content_type;
1977 text[COL_SIZE] = to_human_readable(size);
1978 text[COL_NAME] = ainfo->name;
1980 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1981 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1984 #define IS_FIRST_PART_TEXT(info) \
1985 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
1986 info->mime_type == MIME_TEXT_ENRICHED) || \
1987 (info->mime_type == MIME_MULTIPART && info->content_type && \
1988 !strcasecmp(info->content_type, "multipart/alternative") && \
1989 (info->children && \
1990 (info->children->mime_type == MIME_TEXT || \
1991 info->children->mime_type == MIME_TEXT_HTML || \
1992 info->children->mime_type == MIME_TEXT_ENRICHED))))
1994 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2001 mimeinfo = procmime_scan_message(msginfo);
2002 if (!mimeinfo) return;
2004 /* skip first text (presumably message body) */
2005 child = mimeinfo->children;
2006 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
2007 procmime_mimeinfo_free_all(mimeinfo);
2011 if (IS_FIRST_PART_TEXT(child))
2012 child = child->next;
2014 infile = procmsg_get_message_file_path(msginfo);
2016 while (child != NULL) {
2017 if (child->children || child->mime_type == MIME_MULTIPART) {
2018 child = procmime_mimeinfo_next(child);
2021 if(child->parent && child->parent->parent
2022 && !strcasecmp(child->parent->parent->content_type, "multipart/signed")
2023 && child->mime_type == MIME_TEXT) {
2024 /* this is the main text part of a signed message */
2025 child = procmime_mimeinfo_next(child);
2028 outfile = procmime_get_tmp_file_name(child);
2029 if (procmime_get_part(outfile, infile, child) < 0)
2030 g_warning(_("Can't get the part of multipart message."));
2031 else if (compose->mode != COMPOSE_REEDIT || strcmp(child->content_type, "application/pgp-signature"))
2032 compose_attach_append
2034 child->filename ? child->filename : child->name,
2035 child->content_type);
2037 child = child->next;
2041 procmime_mimeinfo_free_all(mimeinfo);
2044 #undef IS_FIRST_PART_TEXT
2046 #define GET_CHAR(pos, buf, len) \
2048 if (text->use_wchar) \
2049 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2051 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2056 #define INDENT_CHARS ">|#"
2057 #define SPACE_CHARS " \t"
2059 static void compose_wrap_line(Compose *compose)
2061 GtkSText *text = GTK_STEXT(compose->text);
2062 gint ch_len, last_ch_len;
2063 gchar cbuf[MB_LEN_MAX], last_ch;
2067 gint p_start, p_end;
2068 gint line_pos, cur_pos;
2069 gint line_len, cur_len;
2071 gtk_stext_freeze(text);
2073 text_len = gtk_stext_get_length(text);
2075 /* check to see if the point is on the paragraph mark (empty line). */
2076 cur_pos = gtk_stext_get_point(text);
2077 GET_CHAR(cur_pos, cbuf, ch_len);
2078 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2080 goto compose_end; /* on the paragraph mark */
2081 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2082 if (ch_len == 1 && *cbuf == '\n')
2083 goto compose_end; /* on the paragraph mark */
2086 /* find paragraph start. */
2087 line_end = quoted = 0;
2088 for (p_start = cur_pos; p_start >= 0; --p_start) {
2089 GET_CHAR(p_start, cbuf, ch_len);
2090 if (ch_len == 1 && *cbuf == '\n') {
2092 goto compose_end; /* quoted part */
2100 && strchr(prefs_common.quote_chars, *cbuf))
2102 else if (ch_len != 1 || !isspace(*cbuf))
2111 /* find paragraph end. */
2113 for (p_end = cur_pos; p_end < text_len; p_end++) {
2114 GET_CHAR(p_end, cbuf, ch_len);
2115 if (ch_len == 1 && *cbuf == '\n') {
2122 if (line_end && ch_len == 1 &&
2123 strchr(prefs_common.quote_chars, *cbuf))
2124 goto compose_end; /* quoted part */
2129 if (p_end >= text_len)
2132 if (p_start >= p_end)
2135 line_len = cur_len = 0;
2139 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2142 GET_CHAR(cur_pos, cbuf, ch_len);
2149 if (ch_len == 1 && isspace(*cbuf))
2152 if (ch_len == 1 && *cbuf == '\n') {
2154 if (last_ch_len == 1 && !isspace(last_ch)) {
2155 if (cur_pos + 1 < p_end) {
2156 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2157 if (ch_len == 1 && !isspace(*cbuf))
2161 gtk_stext_set_point(text, cur_pos + 1);
2162 gtk_stext_backward_delete(text, 1);
2164 gtk_stext_set_point(text, cur_pos);
2165 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2175 last_ch_len = ch_len;
2179 line_pos = cur_pos + 1;
2180 line_len = cur_len + ch_len;
2183 if (cur_len + ch_len > prefs_common.linewrap_len &&
2187 GET_CHAR(line_pos - 1, cbuf, ch_len);
2188 if (ch_len == 1 && isspace(*cbuf)) {
2189 gtk_stext_set_point(text, line_pos);
2190 gtk_stext_backward_delete(text, 1);
2199 gtk_stext_set_point(text, line_pos);
2200 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2204 cur_len = cur_len - line_len + ch_len;
2210 line_pos = cur_pos + 1;
2211 line_len = cur_len + ch_len;
2217 gtk_stext_thaw(text);
2222 /* Darko: used when I debug wrapping */
2223 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2226 gchar cbuf[MB_LEN_MAX];
2228 printf("%d [", pos);
2229 for (i = pos; i < tlen; i++) {
2230 GET_CHAR(i, cbuf, clen);
2231 if (clen < 0) break;
2232 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2234 fwrite(cbuf, clen, 1, stdout);
2242 WAIT_FOR_INDENT_CHAR,
2243 WAIT_FOR_INDENT_CHAR_OR_SPACE
2246 /* return indent length, we allow:
2247 > followed by spaces/tabs
2248 | followed by spaces/tabs
2249 uppercase characters immediately followed by >,
2250 and the repeating sequences of the above */
2251 /* return indent length */
2252 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2255 guint i, ch_len, alnum_cnt = 0;
2256 IndentState state = WAIT_FOR_INDENT_CHAR;
2257 gchar cbuf[MB_LEN_MAX];
2261 for (i = start_pos; i < text_len; i++) {
2262 GET_CHAR(i, cbuf, ch_len);
2266 if (cbuf[0] == '\n')
2269 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2270 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2273 case WAIT_FOR_SPACE:
2274 if (is_space == FALSE)
2276 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2278 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2279 if (is_indent == FALSE && is_space == FALSE &&
2282 if (is_space == TRUE) {
2284 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2285 } else if (is_indent == TRUE) {
2287 state = WAIT_FOR_SPACE;
2290 state = WAIT_FOR_INDENT_CHAR;
2293 case WAIT_FOR_INDENT_CHAR:
2294 if (is_indent == FALSE && !isupper(cbuf[0]))
2296 if (is_indent == TRUE) {
2298 && !strchr(prefs_common.quote_chars, cbuf[0]))
2301 state = WAIT_FOR_SPACE;
2312 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2318 /* insert quotation string when line was wrapped */
2319 static guint ins_quote(GtkSText *text, guint indent_len,
2320 guint prev_line_pos, guint text_len,
2323 guint i, ins_len = 0;
2327 for (i = 0; i < indent_len; i++) {
2328 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2329 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2331 ins_len = indent_len;
2337 /* check if we should join the next line */
2338 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2339 guint prev_ilen, gboolean autowrap)
2341 guint indent_len, ch_len;
2342 gboolean do_join = FALSE;
2343 gchar cbuf[MB_LEN_MAX];
2345 indent_len = get_indent_length(text, start_pos, tlen);
2347 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2348 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2349 if (ch_len > 0 && (cbuf[0] != '\n'))
2356 static void compose_wrap_line_all(Compose *compose)
2358 compose_wrap_line_all_full(compose, FALSE);
2361 #define STEXT_FREEZE() \
2362 if (!frozen) { gtk_stext_freeze(text); frozen = TRUE; }
2364 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2366 GtkSText *text = GTK_STEXT(compose->text);
2368 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2369 gint line_len = 0, cur_len = 0;
2371 gboolean is_new_line = TRUE, do_delete = FALSE;
2373 gboolean linewrap_quote = TRUE;
2374 gboolean set_editable_pos = FALSE;
2375 gint editable_pos = 0;
2376 gboolean frozen = FALSE;
2377 guint linewrap_len = prefs_common.linewrap_len;
2378 gchar *qfmt = prefs_common.quotemark;
2379 gchar cbuf[MB_LEN_MAX];
2381 tlen = gtk_stext_get_length(text);
2383 for (; cur_pos < tlen; cur_pos++) {
2384 /* mark position of new line - needed for quotation wrap */
2387 i_len = get_indent_length(text, cur_pos, tlen);
2389 is_new_line = FALSE;
2392 g_print("new line i_len=%d p_pos=", i_len);
2393 dump_text(text, p_pos, tlen, 1);
2397 GET_CHAR(cur_pos, cbuf, ch_len);
2399 /* fix line length for tabs */
2400 if (ch_len == 1 && *cbuf == '\t') {
2401 guint tab_width = text->default_tab_width;
2402 guint tab_offset = line_len % tab_width;
2405 g_print("found tab at pos=%d line_len=%d ", cur_pos,
2409 line_len += tab_width - tab_offset - 1;
2413 printf("new_len=%d\n", line_len);
2417 /* we have encountered line break */
2418 if (ch_len == 1 && *cbuf == '\n') {
2420 gchar cb[MB_LEN_MAX];
2422 /* should we join the next line */
2423 if ((autowrap || i_len != cur_len) && do_delete &&
2425 (text, cur_pos + 1, tlen, i_len, autowrap))
2431 g_print("found CR at %d do_del is %d next line is ",
2432 cur_pos, do_delete);
2433 dump_text(text, cur_pos + 1, tlen, 1);
2436 /* skip delete if it is continuous URL */
2437 if (do_delete && (line_pos - p_pos <= i_len) &&
2438 gtkut_stext_is_uri_string(text, line_pos, tlen))
2442 g_print("l_len=%d wrap_len=%d do_del=%d\n",
2443 line_len, linewrap_len, do_delete);
2445 /* should we delete to perform smart wrapping */
2446 if (line_len < linewrap_len && do_delete) {
2448 /* get rid of newline */
2449 gtk_stext_set_point(text, cur_pos);
2450 gtk_stext_forward_delete(text, 1);
2453 /* if text starts with quote fmt or with
2454 indent string, delete them */
2457 ilen = gtkut_stext_str_compare_n
2458 (text, cur_pos, p_pos, i_len,
2461 gtk_stext_forward_delete
2467 GET_CHAR(cur_pos, cb, clen);
2469 /* insert space if it's alphanumeric */
2470 if ((cur_pos != line_pos) &&
2471 ((clen > 1) || isalnum(cb[0]))) {
2472 gtk_stext_insert(text, NULL, NULL,
2477 /* and start over with current line */
2478 cur_pos = p_pos - 1;
2480 line_len = cur_len = 0;
2484 g_print("after delete l_pos=");
2485 dump_text(text, line_pos, tlen, 1);
2490 /* mark new line beginning */
2491 line_pos = cur_pos + 1;
2492 line_len = cur_len = 0;
2503 /* possible line break */
2504 if (ch_len == 1 && isspace(*cbuf)) {
2505 line_pos = cur_pos + 1;
2506 line_len = cur_len + ch_len;
2509 /* are we over wrapping length set in preferences ? */
2510 if (cur_len + ch_len > linewrap_len) {
2514 g_print("should wrap cur_pos=%d ", cur_pos);
2515 dump_text(text, p_pos, tlen, 1);
2516 dump_text(text, line_pos, tlen, 1);
2518 /* force wrapping if it is one long word but not URL */
2519 if (line_pos - p_pos <= i_len)
2520 if (!gtkut_stext_is_uri_string
2521 (text, line_pos, tlen))
2522 line_pos = cur_pos - 1;
2524 g_print("new line_pos=%d\n", line_pos);
2527 GET_CHAR(line_pos - 1, cbuf, clen);
2529 /* if next character is space delete it */
2530 if (clen == 1 && isspace(*cbuf)) {
2531 if (p_pos + i_len != line_pos ||
2532 !gtkut_stext_is_uri_string
2533 (text, line_pos, tlen)) {
2535 /* workaround for correct cursor
2537 if (set_editable_pos == FALSE) {
2538 editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2539 if (editable_pos == line_pos)
2540 set_editable_pos = TRUE;
2542 gtk_stext_set_point(text, line_pos);
2543 gtk_stext_backward_delete(text, 1);
2552 /* if it is URL at beginning of line don't wrap */
2553 if (p_pos + i_len == line_pos &&
2554 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2556 g_print("found URL at ");
2557 dump_text(text, line_pos, tlen, 1);
2564 gtk_stext_set_point(text, line_pos);
2565 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2566 /* gtk_stext_compact_buffer(text); */
2569 /* for loop will increase it */
2570 cur_pos = line_pos - 1;
2571 /* start over with current line */
2573 line_len = cur_len = 0;
2574 if (autowrap || i_len > 0)
2579 g_print("after CR insert ");
2580 dump_text(text, line_pos, tlen, 1);
2581 dump_text(text, cur_pos, tlen, 1);
2584 /* should we insert quotation ? */
2585 if (linewrap_quote && i_len) {
2586 /* only if line is not already quoted */
2587 if (!gtkut_stext_str_compare
2588 (text, line_pos, tlen, qfmt)) {
2591 if (line_pos - p_pos > i_len) {
2593 (text, i_len, p_pos,
2598 g_print("after quote insert ");
2599 dump_text(text, line_pos, tlen, 1);
2607 line_pos = cur_pos + 1;
2608 line_len = cur_len + ch_len;
2610 /* advance to next character in buffer */
2615 gtk_stext_thaw(text);
2617 if (set_editable_pos && editable_pos <= tlen)
2618 gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
2624 static void compose_set_title(Compose *compose)
2629 edited = compose->modified ? _(" [Edited]") : "";
2630 if (compose->account && compose->account->address)
2631 str = g_strdup_printf(_("%s - Compose message%s"),
2632 compose->account->address, edited);
2634 str = g_strdup_printf(_("Compose message%s"), edited);
2635 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2640 * compose_current_mail_account:
2642 * Find a current mail account (the currently selected account, or the
2643 * default account, if a news account is currently selected). If a
2644 * mail account cannot be found, display an error message.
2646 * Return value: Mail account, or NULL if not found.
2648 static PrefsAccount *
2649 compose_current_mail_account(void)
2653 if (cur_account && cur_account->protocol != A_NNTP)
2656 ac = account_get_default();
2657 if (!ac || ac->protocol == A_NNTP) {
2658 alertpanel_error(_("Account for sending mail is not specified.\n"
2659 "Please select a mail account before sending."));
2666 static void compose_select_account(Compose *compose, PrefsAccount *account)
2668 GtkWidget *menuitem;
2669 GtkItemFactory *ifactory;
2671 g_return_if_fail(account != NULL);
2673 compose->account = account;
2675 compose_set_title(compose);
2677 ifactory = gtk_item_factory_from_widget(compose->menubar);
2679 if (account->protocol == A_NNTP) {
2680 gtk_widget_show(compose->newsgroups_hbox);
2681 gtk_widget_show(compose->newsgroups_entry);
2682 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2683 compose->use_newsgroups = TRUE;
2685 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2686 gtk_check_menu_item_set_active
2687 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2688 gtk_widget_set_sensitive(menuitem, TRUE);
2689 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2690 gtk_check_menu_item_set_active
2691 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2692 gtk_widget_set_sensitive(menuitem, TRUE);
2694 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
2696 gtk_widget_hide(compose->newsgroups_hbox);
2697 gtk_widget_hide(compose->newsgroups_entry);
2698 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
2699 gtk_widget_queue_resize(compose->table_vbox);
2700 compose->use_newsgroups = FALSE;
2702 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2703 gtk_check_menu_item_set_active
2704 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2705 gtk_widget_set_sensitive(menuitem, FALSE);
2706 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2707 gtk_check_menu_item_set_active
2708 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2709 gtk_widget_set_sensitive(menuitem, FALSE);
2711 menuitem = gtk_item_factory_get_item(ifactory, "/View/Followup to");
2712 gtk_check_menu_item_set_active
2713 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2714 gtk_widget_set_sensitive(menuitem, FALSE);
2717 if (account->set_autocc && account->auto_cc &&
2718 compose->mode != COMPOSE_REEDIT) {
2720 (GTK_ENTRY(compose->cc_entry), account->auto_cc);
2721 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2722 gtk_check_menu_item_set_active
2723 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2725 if (account->set_autobcc) {
2726 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
2727 gtk_check_menu_item_set_active
2728 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2729 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
2730 gtk_entry_set_text(GTK_ENTRY(compose->bcc_entry),
2733 if (account->set_autoreplyto) {
2734 menuitem = gtk_item_factory_get_item(ifactory,
2736 gtk_check_menu_item_set_active
2737 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2738 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
2739 gtk_entry_set_text(GTK_ENTRY(compose->reply_entry),
2740 account->auto_replyto);
2743 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
2744 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2745 prefs_common.show_ruler);
2749 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
2750 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2751 account->default_sign);
2752 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
2753 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2754 account->default_encrypt);
2756 activate_gnupg_mode(compose, account);
2757 #endif /* USE_GPGME */
2760 gboolean compose_check_for_valid_recipient(Compose *compose) {
2761 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2762 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2763 gboolean recipient_found = FALSE;
2767 /* free to and newsgroup list */
2768 slist_free_strings(compose->to_list);
2769 g_slist_free(compose->to_list);
2770 compose->to_list = NULL;
2772 slist_free_strings(compose->newsgroup_list);
2773 g_slist_free(compose->newsgroup_list);
2774 compose->newsgroup_list = NULL;
2776 /* search header entries for to and newsgroup entries */
2777 for (list = compose->header_list; list; list = list->next) {
2780 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
2781 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2783 if (entry[0] != '\0') {
2784 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2785 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2786 compose->to_list = address_list_append(compose->to_list, entry);
2787 recipient_found = TRUE;
2790 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2791 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2792 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2793 recipient_found = TRUE;
2800 return recipient_found;
2803 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
2807 if (compose_check_for_valid_recipient(compose) == FALSE) {
2808 alertpanel_error(_("Recipient is not specified."));
2812 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2813 if (*str == '\0' && check_subject == TRUE) {
2816 aval = alertpanel(_("Send"),
2817 _("Subject is empty. Send it anyway?"),
2818 _("Yes"), _("No"), NULL);
2819 if (aval != G_ALERTDEFAULT)
2826 gint compose_send(Compose *compose)
2833 if (compose_check_entries(compose, TRUE) == FALSE)
2836 val = compose_queue(compose, &msgnum, &folder);
2838 alertpanel_error(_("Could not queue message for sending"));
2842 msgpath = folder_item_fetch_msg(folder, msgnum);
2843 val = procmsg_send_message_queue(msgpath);
2846 folder_item_remove_msg(folder, msgnum);
2847 folder_update_item(folder, TRUE);
2852 #if 0 /* compose restructure */
2853 gint compose_send(Compose *compose)
2855 gchar tmp[MAXPATHLEN + 1];
2857 static gboolean lock = FALSE;
2861 g_return_val_if_fail(compose->account != NULL, -1);
2865 if (compose_check_entries(compose, TRUE) == FALSE) {
2870 /* write to temporary file */
2871 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
2872 get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
2874 if (prefs_common.linewrap_at_send)
2875 compose_wrap_line_all(compose);
2877 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2882 if (!compose->to_list && !compose->newsgroup_list) {
2883 g_warning(_("can't get recipient list."));
2889 if (compose->to_list) {
2892 #if 0 /* NEW COMPOSE GUI */
2893 if (compose->account->protocol != A_NNTP)
2894 ac = compose->account;
2896 ac = account_find_from_address(compose->account->address);
2898 if (cur_account && cur_account->protocol != A_NNTP)
2901 ac = account_get_default();
2903 if (!ac || ac->protocol == A_NNTP) {
2904 alertpanel_error(_("Account for sending mail is not specified.\n"
2905 "Please select a mail account before sending."));
2912 ac = compose->account;
2914 ok = send_message(tmp, ac, compose->to_list);
2915 statusbar_pop_all();
2918 if (ok == 0 && compose->newsgroup_list) {
2919 ok = news_post(FOLDER(compose->account->folder), tmp);
2921 alertpanel_error(_("Error occurred while posting the message to %s ."),
2922 compose->account->nntp_server);
2929 /* queue message if failed to send */
2931 if (prefs_common.queue_msg) {
2936 _("Error occurred while sending the message.\n"
2937 "Put this message into queue folder?"),
2938 _("OK"), _("Cancel"), NULL);
2939 if (G_ALERTDEFAULT == val) {
2940 ok = compose_queue(compose, tmp);
2942 alertpanel_error(_("Can't queue the message."));
2945 alertpanel_error(_("Error occurred while sending the message."));
2947 if (compose->mode == COMPOSE_REEDIT) {
2948 compose_remove_reedit_target(compose);
2949 if (compose->targetinfo)
2951 (compose->targetinfo->folder, TRUE);
2953 /* save message to outbox */
2954 if (prefs_common.savemsg) {
2957 outbox = account_get_special_folder
2958 (compose->account, F_OUTBOX);
2959 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
2961 (_("Can't save the message to Sent."));
2963 folder_update_item(outbox, TRUE);
2973 static gboolean compose_use_attach(Compose *compose) {
2974 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2977 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
2980 gchar buf[BUFFSIZE];
2982 gboolean first_address;
2984 ComposeHeaderEntry *headerentry;
2985 gchar *headerentryname;
2989 debug_print("Writing redirect header\n");
2991 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
2992 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
2994 first_address = TRUE;
2995 for (list = compose->header_list; list; list = list->next) {
2996 headerentry = ((ComposeHeaderEntry *)list->data);
2997 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2999 if (g_strcasecmp(headerentryname, cc_hdr) == 0
3000 || g_strcasecmp(headerentryname, to_hdr) == 0) {
3001 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3002 Xstrdup_a(str, str, return -1);
3004 if (str[0] != '\0') {
3005 compose_convert_header
3006 (buf, sizeof(buf), str,
3007 strlen("Resent-To") + 2);
3008 if (first_address) {
3009 fprintf(fp, "Resent-To: ");
3010 first_address = FALSE;
3014 fprintf(fp, "%s", buf);
3018 /* if (!first_address) { */
3025 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3027 gchar buf[BUFFSIZE];
3029 /* struct utsname utsbuf; */
3031 g_return_val_if_fail(fp != NULL, -1);
3032 g_return_val_if_fail(compose->account != NULL, -1);
3033 g_return_val_if_fail(compose->account->address != NULL, -1);
3036 get_rfc822_date(buf, sizeof(buf));
3037 fprintf(fp, "Resent-Date: %s\n", buf);
3040 if (compose->account->name && *compose->account->name) {
3041 compose_convert_header
3042 (buf, sizeof(buf), compose->account->name,
3044 fprintf(fp, "Resent-From: %s <%s>\n",
3045 buf, compose->account->address);
3047 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3050 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3052 Xstrdup_a(str, str, return -1);
3055 compose_convert_header(buf, sizeof(buf), str,
3056 strlen("Subject: "));
3057 fprintf(fp, "Subject: %s\n", buf);
3061 /* Resent-Message-ID */
3062 if (compose->account->gen_msgid) {
3063 compose_generate_msgid(compose, buf, sizeof(buf));
3064 fprintf(fp, "Resent-Message-Id: <%s>\n", buf);
3065 compose->msgid = g_strdup(buf);
3068 compose_redirect_write_headers_from_headerlist(compose, fp);
3070 /* separator between header and body */
3076 static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
3081 gchar buf[BUFFSIZE];
3083 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3084 FILE_OP_ERROR(file, "fopen");
3088 if ((fdest = fopen(file, "wb")) == NULL) {
3089 FILE_OP_ERROR(file, "fopen");
3094 /* chmod for security */
3095 if (change_file_mode_rw(fdest, file) < 0) {
3096 FILE_OP_ERROR(file, "chmod");
3097 g_warning(_("can't change file mode\n"));
3100 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
3101 /* should filter returnpath, delivered-to */
3102 if (g_strncasecmp(buf, "Return-Path:",
3103 strlen("Return-Path:")) == 0 ||
3104 g_strncasecmp(buf, "Delivered-To:",
3105 strlen("Delivered-To:")) == 0 ||
3106 g_strncasecmp(buf, "Received:",
3107 strlen("Received:")) == 0 ||
3108 g_strncasecmp(buf, "Subject:",
3109 strlen("Subject:")) == 0 ||
3110 g_strncasecmp(buf, "X-UIDL:",
3111 strlen("X-UIDL:")) == 0)
3114 if (fputs(buf, fdest) == -1)
3117 if (!prefs_common.redirect_keep_from) {
3118 if (g_strncasecmp(buf, "From:",
3119 strlen("From:")) == 0) {
3120 fputs(" (by way of ", fdest);
3121 if (compose->account->name
3122 && *compose->account->name) {
3123 compose_convert_header
3125 compose->account->name,
3127 fprintf(fdest, "%s <%s>",
3129 compose->account->address);
3131 fprintf(fdest, "%s",
3132 compose->account->address);
3137 if (fputs("\n", fdest) == -1)
3141 compose_redirect_write_headers(compose, fdest);
3143 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3144 if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
3145 FILE_OP_ERROR(file, "fwrite");
3151 if (fclose(fdest) == EOF) {
3152 FILE_OP_ERROR(file, "fclose");
3168 /* interfaces to rfc2015 to keep out the prefs stuff there.
3169 * returns 0 on success and -1 on error. */
3170 static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
3172 const gchar *key_id = NULL;
3175 switch (compose->account->sign_key) {
3176 case SIGN_KEY_DEFAULT:
3179 case SIGN_KEY_BY_FROM:
3180 key_id = compose->account->address;
3182 case SIGN_KEY_CUSTOM:
3183 key_id = compose->account->sign_key_id;
3189 key_list = rfc2015_create_signers_list(key_id);
3192 alertpanel_error(_("Could not find any key associated with "
3193 "currently selected key id `%s'."), key_id);
3197 *pkey_list = key_list;
3201 /* clearsign message body text */
3202 static gint compose_clearsign_text(Compose *compose, gchar **text)
3207 tmp_file = get_tmp_file();
3208 if (str_write_to_file(*text, tmp_file) < 0) {
3213 if (canonicalize_file_replace(tmp_file) < 0 ||
3214 compose_create_signers_list(compose, &key_list) < 0 ||
3215 rfc2015_clearsign(tmp_file, key_list) < 0) {
3222 *text = file_read_to_str(tmp_file);
3230 #endif /* USE_GPGME */
3232 static gint compose_write_to_file(Compose *compose, const gchar *file,
3239 const gchar *out_codeset;
3240 EncodingType encoding;
3242 if ((fp = fopen(file, "wb")) == NULL) {
3243 FILE_OP_ERROR(file, "fopen");
3247 /* chmod for security */
3248 if (change_file_mode_rw(fp, file) < 0) {
3249 FILE_OP_ERROR(file, "chmod");
3250 g_warning(_("can't change file mode\n"));
3253 /* get all composed text */
3254 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3255 len = strlen(chars);
3256 if (is_ascii_str(chars)) {
3259 out_codeset = CS_US_ASCII;
3260 encoding = ENC_7BIT;
3262 const gchar *src_codeset;
3264 out_codeset = conv_get_outgoing_charset_str();
3265 if (!strcasecmp(out_codeset, CS_US_ASCII))
3266 out_codeset = CS_ISO_8859_1;
3267 encoding = procmime_get_encoding_for_charset(out_codeset);
3271 compose->use_signing && !compose->gnupg_mode &&
3272 encoding == ENC_8BIT)
3273 encoding = ENC_BASE64;
3276 src_codeset = conv_get_current_charset_str();
3277 /* if current encoding is US-ASCII, set it the same as
3278 outgoing one to prevent code conversion failure */
3279 if (!strcasecmp(src_codeset, CS_US_ASCII))
3280 src_codeset = out_codeset;
3282 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3283 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3285 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3291 _("Can't convert the character encoding of the message.\n"
3292 "Send it anyway?"), _("Yes"), _("+No"), NULL);
3293 if (aval != G_ALERTDEFAULT) {
3306 /* Canonicalize line endings in the message text */
3308 gchar *canon_buf, *out;
3312 for (p = buf ; *p; ++p) {
3320 out = canon_buf = g_new(gchar, new_len + 1);
3321 for (p = buf; *p; ++p) {
3335 if (!is_draft && compose->use_signing && compose->gnupg_mode) {
3336 if (compose_clearsign_text(compose, &buf) < 0) {
3337 g_warning("clearsign failed\n");
3347 if (compose_write_headers
3348 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3349 g_warning(_("can't write headers\n"));
3356 if (compose_use_attach(compose)) {
3358 /* This prolog message is ignored by mime software and
3359 * because it would make our signing/encryption task
3360 * tougher, we don't emit it in that case */
3361 if (!compose->use_signing && !compose->use_encryption)
3363 fputs("This is a multi-part message in MIME format.\n", fp);
3365 fprintf(fp, "\n--%s\n", compose->boundary);
3366 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3368 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3369 procmime_get_encoding_str(encoding));
3375 if (encoding == ENC_BASE64) {
3376 gchar outbuf[B64_BUFFSIZE];
3379 for (i = 0; i < len; i += B64_LINE_SIZE) {
3380 l = MIN(B64_LINE_SIZE, len - i);
3381 base64_encode(outbuf, buf + i, l);
3385 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3386 FILE_OP_ERROR(file, "fwrite");
3394 if (compose_use_attach(compose))
3395 compose_write_attach(compose, fp);
3397 if (fclose(fp) == EOF) {
3398 FILE_OP_ERROR(file, "fclose");
3407 if ((compose->use_signing && !compose->gnupg_mode) ||
3408 compose->use_encryption) {
3409 if (canonicalize_file_replace(file) < 0) {
3415 if (compose->use_signing && !compose->gnupg_mode) {
3418 if (compose_create_signers_list(compose, &key_list) < 0 ||
3419 rfc2015_sign(file, key_list) < 0) {
3424 if (compose->use_encryption) {
3425 if (rfc2015_encrypt(file, compose->to_list,
3426 compose->gnupg_mode) < 0) {
3431 #endif /* USE_GPGME */
3436 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3442 if ((fp = fopen(file, "wb")) == NULL) {
3443 FILE_OP_ERROR(file, "fopen");
3447 /* chmod for security */
3448 if (change_file_mode_rw(fp, file) < 0) {
3449 FILE_OP_ERROR(file, "chmod");
3450 g_warning(_("can't change file mode\n"));
3453 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3456 len = strlen(chars);
3457 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3458 FILE_OP_ERROR(file, "fwrite");
3467 if (fclose(fp) == EOF) {
3468 FILE_OP_ERROR(file, "fclose");
3475 static gint compose_remove_reedit_target(Compose *compose)
3478 MsgInfo *msginfo = compose->targetinfo;
3480 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3481 if (!msginfo) return -1;
3483 item = msginfo->folder;
3484 g_return_val_if_fail(item != NULL, -1);
3486 if (procmsg_msg_exist(msginfo) &&
3487 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3488 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3489 g_warning(_("can't remove the old message\n"));
3497 void compose_remove_draft(Compose *compose)
3500 MsgInfo *msginfo = compose->targetinfo;
3501 drafts = account_get_special_folder(compose->account, F_DRAFT);
3503 if (procmsg_msg_exist(msginfo)) {
3504 folder_item_remove_msg(drafts, msginfo->msgnum);
3505 folder_update_item(drafts, TRUE);
3510 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3512 return compose_queue_sub (compose, msgnum, item, FALSE);
3514 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3520 gchar buf[BUFFSIZE];
3522 static gboolean lock = FALSE;
3523 PrefsAccount *mailac = NULL, *newsac = NULL;
3525 debug_print("queueing message...\n");
3526 g_return_val_if_fail(compose->account != NULL, -1);
3530 if (compose_check_entries(compose, check_subject) == FALSE) {
3535 if (!compose->to_list && !compose->newsgroup_list) {
3536 g_warning(_("can't get recipient list."));
3541 if (compose->to_list) {
3542 if (compose->account->protocol != A_NNTP)
3543 mailac = compose->account;
3544 else if (cur_account && cur_account->protocol != A_NNTP)
3545 mailac = cur_account;
3546 else if (!(mailac = compose_current_mail_account())) {
3548 alertpanel_error(_("No account for sending mails available!"));
3553 if (compose->newsgroup_list) {
3554 if (compose->account->protocol == A_NNTP)
3555 newsac = compose->account;
3556 else if (!newsac->protocol != A_NNTP) {
3558 alertpanel_error(_("No account for posting news available!"));
3563 if (prefs_common.linewrap_at_send)
3564 compose_wrap_line_all(compose);
3566 /* write to temporary file */
3567 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3568 G_DIR_SEPARATOR, (gint)compose);
3570 if (compose->redirect_filename != NULL) {
3571 if (compose_redirect_write_to_file(compose, tmp2) < 0) {
3578 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3585 /* add queue header */
3586 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3587 G_DIR_SEPARATOR, (gint)compose);
3588 if ((fp = fopen(tmp, "wb")) == NULL) {
3589 FILE_OP_ERROR(tmp, "fopen");
3593 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3594 FILE_OP_ERROR(tmp2, "fopen");
3602 if (change_file_mode_rw(fp, tmp) < 0) {
3603 FILE_OP_ERROR(tmp, "chmod");
3604 g_warning(_("can't change file mode\n"));
3607 /* queueing variables */
3608 fprintf(fp, "AF:\n");
3609 fprintf(fp, "NF:0\n");
3610 fprintf(fp, "PS:10\n");
3611 fprintf(fp, "SRH:1\n");
3612 fprintf(fp, "SFN:\n");
3613 fprintf(fp, "DSR:\n");
3615 fprintf(fp, "MID:<%s>\n", compose->msgid);
3617 fprintf(fp, "MID:\n");
3618 fprintf(fp, "CFG:\n");
3619 fprintf(fp, "PT:0\n");
3620 fprintf(fp, "S:%s\n", compose->account->address);
3621 fprintf(fp, "RQ:\n");
3623 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3625 fprintf(fp, "SSV:\n");
3627 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3629 fprintf(fp, "NSV:\n");
3630 fprintf(fp, "SSH:\n");
3631 /* write recepient list */
3632 if (compose->to_list) {
3633 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
3634 for (cur = compose->to_list->next; cur != NULL;
3636 fprintf(fp, ",<%s>", (gchar *)cur->data);
3639 /* write newsgroup list */
3640 if (compose->newsgroup_list) {
3642 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3643 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3644 fprintf(fp, ",%s", (gchar *)cur->data);
3647 /* Sylpheed account IDs */
3649 fprintf(fp, "MAID:%d\n", mailac->account_id);
3652 fprintf(fp, "NAID:%d\n", newsac->account_id);
3654 /* Save copy folder */
3655 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3656 gchar *savefolderid;
3658 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3659 fprintf(fp, "SCF:%s\n", savefolderid);
3660 g_free(savefolderid);
3662 /* Message-ID of message replying to */
3663 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
3666 folderid = folder_item_get_identifier(compose->replyinfo->folder);
3667 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
3672 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3673 if (fputs(buf, fp) == EOF) {
3674 FILE_OP_ERROR(tmp, "fputs");
3685 if (fclose(fp) == EOF) {
3686 FILE_OP_ERROR(tmp, "fclose");
3694 queue = account_get_special_folder(compose->account, F_QUEUE);
3696 g_warning(_("can't find queue folder\n"));
3701 folder_item_scan(queue);
3702 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3703 g_warning(_("can't queue the message\n"));
3713 if (compose->mode == COMPOSE_REEDIT) {
3714 compose_remove_reedit_target(compose);
3715 if (compose->targetinfo &&
3716 compose->targetinfo->folder != queue)
3718 (compose->targetinfo->folder, TRUE);
3721 folder_update_item(queue, TRUE);
3723 if ((msgnum != NULL) && (item != NULL)) {
3731 static void compose_write_attach(Compose *compose, FILE *fp)
3734 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3737 gchar filename[BUFFSIZE];
3740 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3742 gchar buf[BUFFSIZE];
3743 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3745 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
3746 g_warning(_("Can't open file %s\n"), ainfo->file);
3750 fprintf(fp, "\n--%s\n", compose->boundary);
3752 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3753 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3754 fprintf(fp, "Content-Disposition: inline\n");
3756 conv_encode_header(filename, sizeof(filename),
3758 fprintf(fp, "Content-Type: %s;\n"
3760 ainfo->content_type, filename);
3761 fprintf(fp, "Content-Disposition: attachment;\n"
3762 " filename=\"%s\"\n", filename);
3765 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3766 procmime_get_encoding_str(ainfo->encoding));
3768 switch (ainfo->encoding) {
3772 /* if (ainfo->encoding == ENC_7BIT) { */
3774 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3782 while ((len = fread(inbuf, sizeof(gchar),
3783 B64_LINE_SIZE, attach_fp))
3785 base64_encode(outbuf, inbuf, B64_LINE_SIZE);
3789 if (len > 0 && feof(attach_fp)) {
3790 base64_encode(outbuf, inbuf, len);
3796 debug_print("Tried to write attachment in unsupported encoding type\n");
3803 fprintf(fp, "\n--%s--\n", compose->boundary);
3806 #define QUOTE_IF_REQUIRED(out, str) \
3808 if (*str != '"' && (strchr(str, ',') \
3809 || strchr(str, '.'))) { \
3813 len = strlen(str) + 3; \
3814 Xalloca(__tmp, len, return -1); \
3815 g_snprintf(__tmp, len, "\"%s\"", str); \
3818 Xstrdup_a(out, str, return -1); \
3822 #define PUT_RECIPIENT_HEADER(header, str) \
3824 if (*str != '\0') { \
3825 Xstrdup_a(str, str, return -1); \
3827 if (*str != '\0') { \
3828 compose->to_list = address_list_append \
3829 (compose->to_list, str); \
3830 compose_convert_header \
3831 (buf, sizeof(buf), str, strlen(header) + 2); \
3832 fprintf(fp, "%s: %s\n", header, buf); \
3837 #define IS_IN_CUSTOM_HEADER(header) \
3838 (compose->account->add_customhdr && \
3839 custom_header_find(compose->account->customhdr_list, header) != NULL)
3841 static gint compose_write_headers_from_headerlist(Compose *compose,
3845 gchar buf[BUFFSIZE];
3846 gchar *str, *header_w_colon, *trans_hdr;
3847 gboolean first_address;
3849 ComposeHeaderEntry *headerentry;
3850 gchar * headerentryname;
3852 if (IS_IN_CUSTOM_HEADER(header)) {
3856 debug_print("Writing %s-header\n", header);
3858 header_w_colon = g_strconcat(header, ":", NULL);
3859 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3861 first_address = TRUE;
3862 for (list = compose->header_list; list; list = list->next) {
3863 headerentry = ((ComposeHeaderEntry *)list->data);
3864 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3866 if (!g_strcasecmp(trans_hdr, headerentryname)) {
3867 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3868 Xstrdup_a(str, str, return -1);
3870 if (str[0] != '\0') {
3871 compose_convert_header
3872 (buf, sizeof(buf), str,
3873 strlen(header) + 2);
3874 if (first_address) {
3875 fprintf(fp, "%s: ", header);
3876 first_address = FALSE;
3880 fprintf(fp, "%s", buf);
3884 if (!first_address) {
3888 g_free(header_w_colon);
3893 static gint compose_write_headers(Compose *compose, FILE *fp,
3894 const gchar *charset, EncodingType encoding,
3897 gchar buf[BUFFSIZE];
3901 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3903 /* struct utsname utsbuf; */
3905 g_return_val_if_fail(fp != NULL, -1);
3906 g_return_val_if_fail(charset != NULL, -1);
3907 g_return_val_if_fail(compose->account != NULL, -1);
3908 g_return_val_if_fail(compose->account->address != NULL, -1);
3910 /* Save draft infos */
3912 fprintf(fp, "S:%s\n", compose->account->address);
3913 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3914 gchar *savefolderid;
3916 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3917 fprintf(fp, "SCF:%s\n", savefolderid);
3918 g_free(savefolderid);
3924 if (compose->account->add_date) {
3925 get_rfc822_date(buf, sizeof(buf));
3926 fprintf(fp, "Date: %s\n", buf);
3930 if (!IS_IN_CUSTOM_HEADER("From")) {
3931 if (compose->account->name && *compose->account->name) {
3932 compose_convert_header
3933 (buf, sizeof(buf), compose->account->name,
3935 QUOTE_IF_REQUIRED(name, buf);
3936 fprintf(fp, "From: %s <%s>\n",
3937 name, compose->account->address);
3939 fprintf(fp, "From: %s\n", compose->account->address);
3943 compose_write_headers_from_headerlist(compose, fp, "To");
3944 #if 0 /* NEW COMPOSE GUI */
3945 if (compose->use_to) {
3946 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3947 PUT_RECIPIENT_HEADER("To", str);
3952 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3953 #if 0 /* NEW COMPOSE GUI */
3954 if (compose->use_newsgroups) {
3955 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3957 Xstrdup_a(str, str, return -1);
3961 compose->newsgroup_list =
3962 newsgroup_list_append
3963 (compose->newsgroup_list, str);
3964 compose_convert_header(buf, sizeof(buf), str,
3965 strlen("Newsgroups: "));
3966 fprintf(fp, "Newsgroups: %s\n", buf);
3972 compose_write_headers_from_headerlist(compose, fp, "Cc");
3973 #if 0 /* NEW COMPOSE GUI */
3974 if (compose->use_cc) {
3975 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3976 PUT_RECIPIENT_HEADER("Cc", str);
3980 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3981 #if 0 /* NEW COMPOSE GUI */
3982 if (compose->use_bcc) {
3983 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3984 PUT_RECIPIENT_HEADER("Bcc", str);
3989 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3990 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3991 Xstrdup_a(str, str, return -1);
3994 compose_convert_header(buf, sizeof(buf), str,
3995 strlen("Subject: "));
3996 fprintf(fp, "Subject: %s\n", buf);
4001 if (compose->account->gen_msgid) {
4002 compose_generate_msgid(compose, buf, sizeof(buf));
4003 fprintf(fp, "Message-Id: <%s>\n", buf);
4004 compose->msgid = g_strdup(buf);
4008 if (compose->inreplyto && compose->to_list)
4009 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
4012 if (compose->references)
4013 fprintf(fp, "References: %s\n", compose->references);
4016 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
4017 #if 0 /* NEW COMPOSE GUI */
4018 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
4019 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
4021 Xstrdup_a(str, str, return -1);
4025 compose_convert_header(buf, sizeof(buf), str,
4026 strlen("Followup-To: "));
4027 fprintf(fp, "Followup-To: %s\n", buf);
4033 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
4034 #if 0 /* NEW COMPOSE GUI */
4035 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
4036 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
4038 Xstrdup_a(str, str, return -1);
4041 compose_convert_header(buf, sizeof(buf), str,
4042 strlen("Reply-To: "));
4043 fprintf(fp, "Reply-To: %s\n", buf);
4049 if (compose->account->organization &&
4050 !IS_IN_CUSTOM_HEADER("Organization")) {
4051 compose_convert_header(buf, sizeof(buf),
4052 compose->account->organization,
4053 strlen("Organization: "));
4054 fprintf(fp, "Organization: %s\n", buf);
4057 /* Program version and system info */
4058 /* uname(&utsbuf); */
4059 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
4060 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4062 gtk_major_version, gtk_minor_version, gtk_micro_version,
4064 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4066 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4067 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4069 gtk_major_version, gtk_minor_version, gtk_micro_version,
4071 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4074 /* custom headers */
4075 if (compose->account->add_customhdr) {
4078 for (cur = compose->account->customhdr_list; cur != NULL;
4080 CustomHeader *chdr = (CustomHeader *)cur->data;
4082 if (strcasecmp(chdr->name, "Date") != 0 &&
4083 strcasecmp(chdr->name, "From") != 0 &&
4084 strcasecmp(chdr->name, "To") != 0 &&
4085 /* strcasecmp(chdr->name, "Sender") != 0 && */
4086 strcasecmp(chdr->name, "Message-Id") != 0 &&
4087 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
4088 strcasecmp(chdr->name, "References") != 0 &&
4089 strcasecmp(chdr->name, "Mime-Version") != 0 &&
4090 strcasecmp(chdr->name, "Content-Type") != 0 &&
4091 strcasecmp(chdr->name, "Content-Transfer-Encoding")
4093 compose_convert_header
4095 chdr->value ? chdr->value : "",
4096 strlen(chdr->name) + 2);
4097 fprintf(fp, "%s: %s\n", chdr->name, buf);
4103 fprintf(fp, "Mime-Version: 1.0\n");
4104 if (compose_use_attach(compose)) {
4105 get_rfc822_date(buf, sizeof(buf));
4106 subst_char(buf, ' ', '_');
4107 subst_char(buf, ',', '_');
4108 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
4109 buf, (guint)compose);
4111 "Content-Type: multipart/mixed;\n"
4112 " boundary=\"%s\"\n", compose->boundary);
4114 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
4115 fprintf(fp, "Content-Transfer-Encoding: %s\n",
4116 procmime_get_encoding_str(encoding));
4120 switch (compose->priority) {
4121 case PRIORITY_HIGHEST: fprintf(fp, "Importance: high\n"
4122 "X-Priority: 1 (Highest)\n");
4124 case PRIORITY_HIGH: fprintf(fp, "Importance: high\n"
4125 "X-Priority: 2 (High)\n");
4127 case PRIORITY_NORMAL: break;
4128 case PRIORITY_LOW: fprintf(fp, "Importance: low\n"
4129 "X-Priority: 4 (Low)\n");
4131 case PRIORITY_LOWEST: fprintf(fp, "Importance: low\n"
4132 "X-Priority: 5 (Lowest)\n");
4134 default: debug_print("compose: priority unknown : %d\n",
4138 /* Request Return Receipt */
4139 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4140 if (compose->return_receipt) {
4141 if (compose->account->name
4142 && *compose->account->name) {
4143 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
4144 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4146 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
4150 /* get special headers */
4151 for (list = compose->header_list; list; list = list->next) {
4152 ComposeHeaderEntry *headerentry;
4155 gchar *headername_wcolon;
4156 gchar *headername_trans;
4159 gboolean standard_header = FALSE;
4161 headerentry = ((ComposeHeaderEntry *)list->data);
4163 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4164 if (!strstr(tmp, ":")) {
4165 headername_wcolon = g_strconcat(tmp, ":", NULL);
4166 headername = g_strdup(tmp);
4168 headername_wcolon = g_strdup(tmp);
4169 headername = g_strdup(strtok(tmp, ":"));
4173 headervalue = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4174 string = std_headers;
4175 while (*string != NULL) {
4176 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4177 if (!strcmp(headername_trans,headername_wcolon))
4178 standard_header = TRUE;
4181 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4182 fprintf(fp, "%s %s\n", headername_wcolon, headervalue);
4185 g_free(headername_wcolon);
4189 /* separator between header and body */
4195 #undef IS_IN_CUSTOM_HEADER
4197 static void compose_convert_header(gchar *dest, gint len, gchar *src,
4200 g_return_if_fail(src != NULL);
4201 g_return_if_fail(dest != NULL);
4203 if (len < 1) return;
4207 if (is_ascii_str(src)) {
4208 strncpy2(dest, src, len);
4209 dest[len - 1] = '\0';
4212 conv_encode_header(dest, len, src, header_len);
4215 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
4224 if (compose->account && compose->account->address &&
4225 *compose->account->address) {
4226 if (strchr(compose->account->address, '@'))
4227 addr = g_strdup(compose->account->address);
4229 addr = g_strconcat(compose->account->address, "@",
4230 get_domain_name(), NULL);
4232 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
4235 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
4236 lt->tm_year + 1900, lt->tm_mon + 1,
4237 lt->tm_mday, lt->tm_hour,
4238 lt->tm_min, lt->tm_sec,
4239 (guint)random(), addr);
4241 debug_print("generated Message-ID: %s\n", buf);
4246 static void compose_create_header_entry(Compose *compose)
4248 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4252 GList *combo_list = NULL;
4253 gchar **string, *header;
4254 ComposeHeaderEntry *headerentry;
4255 gboolean standard_header = FALSE;
4257 headerentry = g_new0(ComposeHeaderEntry, 1);
4260 combo = gtk_combo_new();
4262 while(*string != NULL) {
4263 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4266 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4267 g_list_free(combo_list);
4268 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4269 gtk_widget_show(combo);
4270 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4271 if (compose->header_last) {
4272 gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4274 while (*string != NULL) {
4275 if (!strcmp(*string, last_header_entry))
4276 standard_header = TRUE;
4279 if (standard_header)
4280 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4282 if (!compose->header_last || !standard_header) {
4283 switch(compose->account->protocol) {
4285 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4288 header = prefs_common.trans_hdr ? _("To:") : "To:";
4292 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4295 entry = gtk_entry_new();
4296 gtk_widget_show(entry);
4297 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);
4299 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4300 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4301 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4303 address_completion_register_entry(GTK_ENTRY(entry));
4305 headerentry->compose = compose;
4306 headerentry->combo = combo;
4307 headerentry->entry = entry;
4308 headerentry->headernum = compose->header_nextrow;
4310 compose->header_nextrow++;
4311 compose->header_last = headerentry;
4314 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4316 ComposeHeaderEntry *last_header;
4318 last_header = compose->header_last;
4320 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4321 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4324 static GtkWidget *compose_create_header(Compose *compose)
4328 GtkWidget *from_optmenu_hbox;
4329 #if 0 /* NEW COMPOSE GUI */
4330 GtkWidget *to_entry;
4332 GtkWidget *newsgroups_entry;
4333 GtkWidget *newsgroups_hbox;
4335 GtkWidget *header_scrolledwin;
4336 GtkWidget *header_table;
4337 #if 0 /* NEW COMPOSE GUI */
4338 GtkWidget *cc_entry;
4340 GtkWidget *bcc_entry;
4341 GtkWidget *bcc_hbox;
4342 GtkWidget *reply_entry;
4343 GtkWidget *reply_hbox;
4344 GtkWidget *followup_entry;
4345 GtkWidget *followup_hbox;
4350 /* header labels and entries */
4351 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4352 gtk_widget_show(header_scrolledwin);
4353 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4355 header_table = gtk_table_new(2, 2, FALSE);
4356 gtk_widget_show(header_table);
4357 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4358 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4359 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4362 /* option menu for selecting accounts */
4363 hbox = gtk_hbox_new(FALSE, 0);
4364 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4365 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4366 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4368 from_optmenu_hbox = compose_account_option_menu_create(compose);
4369 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4370 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4371 #if 0 /* NEW COMPOSE GUI */
4372 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4376 compose->header_table = header_table;
4377 compose->header_list = NULL;
4378 compose->header_nextrow = count;
4380 compose_create_header_entry(compose);
4382 #if 0 /* NEW COMPOSE GUI */
4383 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4385 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4386 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4387 &count, "Newsgroups:", FALSE);
4388 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4390 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4392 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4394 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4395 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4397 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4398 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4400 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4401 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4402 "Followup-To:", FALSE);
4403 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4405 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4407 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4408 GTK_SIGNAL_FUNC(to_activated), compose);
4409 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4410 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4411 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4412 GTK_SIGNAL_FUNC(subject_activated), compose);
4413 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4414 GTK_SIGNAL_FUNC(cc_activated), compose);
4415 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4416 GTK_SIGNAL_FUNC(bcc_activated), compose);
4417 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4418 GTK_SIGNAL_FUNC(replyto_activated), compose);
4419 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4420 GTK_SIGNAL_FUNC(followupto_activated), compose);
4422 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4423 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4424 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4425 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4426 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4427 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4428 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4429 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4430 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4431 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4432 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4433 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4434 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4435 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4438 compose->table = NULL;
4439 #if 0 /* NEW COMPOSE GUI */
4440 compose->table = table;
4441 compose->to_hbox = to_hbox;
4442 compose->to_entry = to_entry;
4443 compose->newsgroups_hbox = newsgroups_hbox;
4444 compose->newsgroups_entry = newsgroups_entry;
4446 #if 0 /* NEW COMPOSE GUI */
4447 compose->cc_hbox = cc_hbox;
4448 compose->cc_entry = cc_entry;
4449 compose->bcc_hbox = bcc_hbox;
4450 compose->bcc_entry = bcc_entry;
4451 compose->reply_hbox = reply_hbox;
4452 compose->reply_entry = reply_entry;
4453 compose->followup_hbox = followup_hbox;
4454 compose->followup_entry = followup_entry;
4457 return header_scrolledwin ;
4460 GtkWidget *compose_create_attach(Compose *compose)
4462 gchar *titles[N_ATTACH_COLS];
4465 GtkWidget *attach_scrwin;
4466 GtkWidget *attach_clist;
4468 titles[COL_MIMETYPE] = _("MIME type");
4469 titles[COL_SIZE] = _("Size");
4470 titles[COL_NAME] = _("Name");
4472 /* attachment list */
4473 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4474 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4475 GTK_POLICY_AUTOMATIC,
4477 gtk_widget_set_usize(attach_scrwin, -1, 80);
4479 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4480 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4482 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4483 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4484 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4485 GTK_SELECTION_EXTENDED);
4486 for (i = 0; i < N_ATTACH_COLS; i++)
4487 GTK_WIDGET_UNSET_FLAGS
4488 (GTK_CLIST(attach_clist)->column[i].button,
4490 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4492 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4493 GTK_SIGNAL_FUNC(attach_selected), compose);
4494 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4495 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4496 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4497 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4500 gtk_drag_dest_set(attach_clist,
4501 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4502 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4503 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4504 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4507 compose->attach_scrwin = attach_scrwin;
4508 compose->attach_clist = attach_clist;
4510 return attach_scrwin;
4513 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4514 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4516 static GtkWidget *compose_create_others(Compose *compose)
4519 GtkWidget *savemsg_checkbtn;
4520 GtkWidget *savemsg_entry;
4521 GtkWidget *savemsg_select;
4524 gchar *folderidentifier;
4526 /* Table for settings */
4527 table = gtk_table_new(3, 1, FALSE);
4528 gtk_widget_show(table);
4529 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4532 /* Save Message to folder */
4533 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4534 gtk_widget_show(savemsg_checkbtn);
4535 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4536 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4537 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4539 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4540 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4542 savemsg_entry = gtk_entry_new();
4543 gtk_widget_show(savemsg_entry);
4544 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4545 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4546 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4547 folderidentifier = folder_item_get_identifier(account_get_special_folder
4548 (compose->account, F_OUTBOX));
4549 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4550 g_free(folderidentifier);
4553 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4554 gtk_widget_show (savemsg_select);
4555 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4556 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4557 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4562 compose->savemsg_checkbtn = savemsg_checkbtn;
4563 compose->savemsg_entry = savemsg_entry;
4568 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4570 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4571 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4574 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4579 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4582 path = folder_item_get_identifier(dest);
4584 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4588 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4594 GtkWidget *handlebox;
4596 GtkWidget *notebook;
4601 GtkWidget *subject_hbox;
4602 GtkWidget *subject_frame;
4603 GtkWidget *subject_entry;
4607 GtkWidget *edit_vbox;
4608 GtkWidget *ruler_hbox;
4610 GtkWidget *scrolledwin;
4613 UndoMain *undostruct;
4615 gchar *titles[N_ATTACH_COLS];
4616 guint n_menu_entries;
4617 GtkStyle *style, *new_style;
4620 gboolean success[1];
4621 GtkWidget *popupmenu;
4622 GtkItemFactory *popupfactory;
4623 GtkItemFactory *ifactory;
4624 GtkWidget *tmpl_menu;
4628 GtkAspell * gtkaspell = NULL;
4631 static GdkGeometry geometry;
4633 g_return_val_if_fail(account != NULL, NULL);
4635 debug_print("Creating compose window...\n");
4636 compose = g_new0(Compose, 1);
4638 titles[COL_MIMETYPE] = _("MIME type");
4639 titles[COL_SIZE] = _("Size");
4640 titles[COL_NAME] = _("Name");
4642 compose->account = account;
4644 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4645 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4646 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4647 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4649 if (!geometry.max_width) {
4650 geometry.max_width = gdk_screen_width();
4651 geometry.max_height = gdk_screen_height();
4653 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4654 &geometry, GDK_HINT_MAX_SIZE);
4656 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4657 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4658 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4659 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4660 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4661 gtk_widget_realize(window);
4663 gtkut_widget_set_composer_icon(window);
4665 vbox = gtk_vbox_new(FALSE, 0);
4666 gtk_container_add(GTK_CONTAINER(window), vbox);
4668 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4669 menubar = menubar_create(window, compose_entries,
4670 n_menu_entries, "<Compose>", compose);
4671 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4673 handlebox = gtk_handle_box_new();
4674 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4676 compose_toolbar_create(compose, handlebox);
4678 vbox2 = gtk_vbox_new(FALSE, 2);
4679 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4680 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4683 notebook = gtk_notebook_new();
4684 gtk_widget_set_usize(notebook, -1, 130);
4685 gtk_widget_show(notebook);
4687 /* header labels and entries */
4688 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4689 /* attachment list */
4690 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4692 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4695 subject_hbox = gtk_hbox_new(FALSE, 0);
4696 gtk_widget_show(subject_hbox);
4698 subject_frame = gtk_frame_new(NULL);
4699 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4700 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4701 gtk_widget_show(subject_frame);
4703 subject = gtk_hbox_new(FALSE, 0);
4704 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4705 gtk_widget_show(subject);
4707 label = gtk_label_new(_("Subject:"));
4708 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4709 gtk_widget_show(label);
4711 subject_entry = gtk_entry_new();
4712 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4713 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4714 gtk_widget_show(subject_entry);
4715 compose->subject_entry = subject_entry;
4716 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4718 edit_vbox = gtk_vbox_new(FALSE, 0);
4719 #if 0 /* NEW COMPOSE GUI */
4720 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4723 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4726 ruler_hbox = gtk_hbox_new(FALSE, 0);
4727 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4729 ruler = gtk_shruler_new();
4730 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4731 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4733 gtk_widget_set_usize(ruler_hbox, 1, -1);
4736 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4737 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4738 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4739 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4740 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4742 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4743 (GTK_SCROLLED_WINDOW(scrolledwin)),
4744 gtk_scrolled_window_get_vadjustment
4745 (GTK_SCROLLED_WINDOW(scrolledwin)));
4746 GTK_STEXT(text)->default_tab_width = 8;
4747 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4749 if (prefs_common.block_cursor) {
4750 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4753 if (prefs_common.smart_wrapping) {
4754 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4755 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4758 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4760 gtk_signal_connect(GTK_OBJECT(text), "changed",
4761 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4762 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4763 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4764 gtk_signal_connect(GTK_OBJECT(text), "activate",
4765 GTK_SIGNAL_FUNC(text_activated), compose);
4766 gtk_signal_connect(GTK_OBJECT(text), "insert_text",
4767 GTK_SIGNAL_FUNC(text_inserted), compose);
4768 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4769 GTK_SIGNAL_FUNC(compose_button_press_cb),
4772 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4773 GTK_SIGNAL_FUNC(compose_key_press_cb),
4776 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4777 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4781 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4782 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4783 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4784 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4786 gtk_widget_show_all(vbox);
4788 /* pane between attach clist and text */
4789 paned = gtk_vpaned_new();
4790 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4791 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4792 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4793 gtk_paned_add1(GTK_PANED(paned), notebook);
4794 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4795 gtk_widget_show_all(paned);
4797 style = gtk_widget_get_style(text);
4799 /* workaround for the slow down of GtkSText when using Pixmap theme */
4800 if (style->engine) {
4801 GtkThemeEngine *engine;
4803 engine = style->engine;
4804 style->engine = NULL;
4805 new_style = gtk_style_copy(style);
4806 style->engine = engine;
4808 new_style = gtk_style_copy(style);
4810 if (prefs_common.textfont) {
4813 if ((font = gtkut_font_load(prefs_common.textfont)) != NULL) {
4814 gdk_font_unref(new_style->font);
4815 new_style->font = font;
4819 gtk_widget_set_style(text, new_style);
4821 color[0] = quote_color;
4822 cmap = gdk_window_get_colormap(window->window);
4823 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4824 if (success[0] == FALSE) {
4825 g_warning("Compose: color allocation failed.\n");
4826 style = gtk_widget_get_style(text);
4827 quote_color = style->black;
4830 n_entries = sizeof(compose_popup_entries) /
4831 sizeof(compose_popup_entries[0]);
4832 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4833 "<Compose>", &popupfactory,
4836 ifactory = gtk_item_factory_from_widget(menubar);
4837 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4838 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4840 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4841 #if 0 /* NEW COMPOSE GUI */
4842 gtk_widget_hide(bcc_hbox);
4843 gtk_widget_hide(bcc_entry);
4844 gtk_widget_hide(reply_hbox);
4845 gtk_widget_hide(reply_entry);
4846 gtk_widget_hide(followup_hbox);
4847 gtk_widget_hide(followup_entry);
4848 gtk_widget_hide(ruler_hbox);
4849 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4850 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4851 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4853 if (account->protocol == A_NNTP) {
4854 gtk_widget_hide(to_hbox);
4855 gtk_widget_hide(to_entry);
4856 gtk_widget_hide(cc_hbox);
4857 gtk_widget_hide(cc_entry);
4858 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4859 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4861 gtk_widget_hide(newsgroups_hbox);
4862 gtk_widget_hide(newsgroups_entry);
4863 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4867 update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
4870 undostruct = undo_init(text);
4871 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4874 address_completion_start(window);
4876 compose->window = window;
4877 compose->vbox = vbox;
4878 compose->menubar = menubar;
4879 compose->handlebox = handlebox;
4881 compose->vbox2 = vbox2;
4883 compose->paned = paned;
4885 compose->edit_vbox = edit_vbox;
4886 compose->ruler_hbox = ruler_hbox;
4887 compose->ruler = ruler;
4888 compose->scrolledwin = scrolledwin;
4889 compose->text = text;
4891 compose->focused_editable = NULL;
4893 compose->popupmenu = popupmenu;
4894 compose->popupfactory = popupfactory;
4896 compose->tmpl_menu = tmpl_menu;
4898 compose->mode = mode;
4900 compose->targetinfo = NULL;
4901 compose->replyinfo = NULL;
4903 compose->replyto = NULL;
4905 compose->bcc = NULL;
4906 compose->followup_to = NULL;
4908 compose->ml_post = NULL;
4910 compose->inreplyto = NULL;
4911 compose->references = NULL;
4912 compose->msgid = NULL;
4913 compose->boundary = NULL;
4916 compose->use_signing = FALSE;
4917 compose->use_encryption = FALSE;
4918 #endif /* USE_GPGME */
4920 compose->modified = FALSE;
4922 compose->return_receipt = FALSE;
4923 compose->paste_as_quotation = FALSE;
4925 compose->to_list = NULL;
4926 compose->newsgroup_list = NULL;
4928 compose->exteditor_file = NULL;
4929 compose->exteditor_pid = -1;
4930 compose->exteditor_readdes = -1;
4931 compose->exteditor_tag = -1;
4933 compose->redirect_filename = NULL;
4934 compose->undostruct = undostruct;
4937 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4938 if (prefs_common.enable_aspell &&
4939 strcmp(prefs_common.dictionary, _("None"))) {
4940 gtkaspell = gtkaspell_new((const gchar*)prefs_common.dictionary,
4941 conv_get_current_charset_str(),
4942 prefs_common.misspelled_col,
4943 prefs_common.check_while_typing,
4944 prefs_common.use_alternate,
4947 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkaspellcheckers->error_message);
4948 gtkaspell_checkers_reset_error();
4951 GtkWidget *menuitem;
4953 if (!gtkaspell_set_sug_mode(gtkaspell, prefs_common.aspell_sugmode)) {
4954 debug_print("Aspell: could not set suggestion mode %s\n",
4955 gtkaspellcheckers->error_message);
4956 gtkaspell_checkers_reset_error();
4959 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
4960 gtkaspell_populate_submenu(gtkaspell, menuitem);
4961 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4966 compose_select_account(compose, account);
4969 compose->gtkaspell = gtkaspell;
4972 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
4973 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4975 if (account->set_autobcc)
4976 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4978 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
4979 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4982 if (account->protocol != A_NNTP)
4983 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4985 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4987 addressbook_set_target_compose(compose);
4988 update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
4989 compose_set_template_menu(compose);
4991 compose_list = g_list_append(compose_list, compose);
4993 if (!prefs_common.show_ruler)
4994 gtk_widget_hide(ruler_hbox);
4997 compose->priority = PRIORITY_NORMAL;
4998 compose_update_priority_menu_item(compose);
5001 activate_gnupg_mode(compose, account);
5004 set_toolbar_style(compose);
5006 gtk_widget_show(window);
5011 static void toolbar_compose_buttons_cb(GtkWidget *widget,
5012 ToolbarItem *t_item)
5016 void (*func)(GtkWidget *widget, gpointer data);
5017 } compose_action[] = {
5018 { A_SEND, toolbar_send_cb },
5019 { A_SENDL, toolbar_send_later_cb },
5020 { A_DRAFT, toolbar_draft_cb },
5021 { A_INSERT, toolbar_insert_cb },
5022 { A_ATTACH, toolbar_attach_cb },
5023 { A_SIG, toolbar_sig_cb },
5024 { A_EXTEDITOR, toolbar_ext_editor_cb },
5025 { A_LINEWRAP, toolbar_linewrap_cb },
5026 { A_ADDRBOOK, toolbar_address_cb },
5027 { A_SYL_ACTIONS, toolbar_actions_execute_cb }};
5030 gint num_items = sizeof(compose_action)/sizeof(compose_action[0]);
5032 debug_print("_buttons: index: %i \n", t_item->index);
5033 for (i = 0; i < num_items; i++) {
5035 if (compose_action[i].index == t_item->index) {
5036 Compose *compose = (Compose*)t_item->parent;
5037 debug_print("_buttons: compose: %p toolbar: %p\n", compose, compose->toolbar); compose_action[i].func(widget, compose);
5043 static void compose_toolbar_update(Compose *compose)
5045 gtk_container_remove(GTK_CONTAINER(compose->handlebox),
5046 GTK_WIDGET(compose->toolbar->toolbar));
5048 compose->toolbar->toolbar = NULL;
5049 compose->toolbar->send_btn = NULL;
5050 compose->toolbar->sendl_btn = NULL;
5051 compose->toolbar->draft_btn = NULL;
5052 compose->toolbar->insert_btn = NULL;
5053 compose->toolbar->attach_btn = NULL;
5054 compose->toolbar->sig_btn = NULL;
5055 compose->toolbar->exteditor_btn = NULL;
5056 compose->toolbar->linewrap_btn = NULL;
5057 compose->toolbar->addrbook_btn = NULL;
5059 TOOLBAR_DESTROY_ITEMS(compose->toolbar->t_item_list);
5060 TOOLBAR_DESTROY_ACTIONS(compose->toolbar->t_action_list);
5061 compose_toolbar_create(compose, compose->handlebox);
5064 static void compose_toolbar_create(Compose *compose,
5065 GtkWidget *container)
5067 ToolbarItem *toolbar_item;
5070 GtkWidget *icon_wid = NULL;
5072 GtkTooltips *toolbar_tips;
5073 ToolbarSylpheedActions *t_action_item;
5075 GSList *toolbar_list;
5077 toolbar_tips = gtk_tooltips_new();
5079 toolbar_read_config_file(TOOLBAR_COMPOSE);
5080 toolbar_list = toolbar_get_list(TOOLBAR_COMPOSE);
5082 compose->toolbar = g_new0(ComposeToolbar, 1);
5084 for (elem = compose_list; elem != NULL; elem = elem->next) {
5085 Compose *c = (Compose*)elem->data;
5086 debug_print("toolbar_create: compose: %p toolbar: %p\n",
5090 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
5092 gtk_container_add(GTK_CONTAINER(container), toolbar);
5093 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
5094 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
5095 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
5096 GTK_TOOLBAR_SPACE_LINE);
5098 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
5100 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, SEPARATOR) == 0) {
5101 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
5105 toolbar_item = g_new0(ToolbarItem, 1);
5106 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
5107 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
5108 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
5110 toolbar_item->parent = (gpointer)compose;
5112 /* collect toolbar items in list to keep track */
5113 compose->toolbar->t_item_list = g_slist_append(compose->toolbar->t_item_list,
5116 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
5117 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
5121 icon_wid, toolbar_compose_buttons_cb,
5124 switch (toolbar_item->index) {
5126 compose->toolbar->send_btn = item;
5127 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5128 compose->toolbar->send_btn,
5129 _("Send Message"), NULL);
5132 compose->toolbar->sendl_btn = item;
5133 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5134 compose->toolbar->sendl_btn,
5135 _("Put into queue folder and send later"), NULL);
5138 compose->toolbar->draft_btn = item;
5139 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5140 compose->toolbar->draft_btn,
5141 _("Save to draft folder"), NULL);
5144 compose->toolbar->insert_btn = item;
5145 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5146 compose->toolbar->insert_btn,
5147 _("Insert file"), NULL);
5150 compose->toolbar->attach_btn = item;
5151 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5152 compose->toolbar->attach_btn,
5153 _("Attach file"), NULL);
5156 compose->toolbar->sig_btn = item;
5157 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5158 compose->toolbar->sig_btn,
5159 _("Insert signature"), NULL);
5162 compose->toolbar->exteditor_btn = item;
5163 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5164 compose->toolbar->exteditor_btn,
5165 _("Edit with external editor"), NULL);
5168 compose->toolbar->linewrap_btn = item;
5169 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5170 compose->toolbar->linewrap_btn,
5171 _("Wrap all long lines"), NULL);
5174 compose->toolbar->addrbook_btn = item;
5175 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5176 compose->toolbar->addrbook_btn,
5177 _("Address book"), NULL);
5180 t_action_item = g_new0(ToolbarSylpheedActions, 1);
5181 t_action_item->widget = item;
5182 t_action_item->name = g_strdup(toolbar_item->text);
5184 compose->toolbar->t_action_list =
5185 g_slist_append(compose->toolbar->t_action_list,
5188 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
5190 t_action_item->name, NULL);
5192 gtk_widget_show(item);
5199 compose->toolbar->toolbar = toolbar;
5201 gtk_widget_show_all(toolbar);
5204 static void compose_toolbar_set_sensitive (Compose * compose, gboolean sensitive)
5206 GSList *items = compose->toolbar->t_action_list;
5207 if (compose->toolbar->send_btn)
5208 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
5209 if (compose->toolbar->sendl_btn)
5210 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
5211 if (compose->toolbar->draft_btn )
5212 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
5213 if (compose->toolbar->insert_btn )
5214 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
5215 if (compose->toolbar->attach_btn)
5216 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
5217 if (compose->toolbar->sig_btn)
5218 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
5219 if (compose->toolbar->exteditor_btn)
5220 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
5221 if (compose->toolbar->linewrap_btn)
5222 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
5223 if (compose->toolbar->addrbook_btn)
5224 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
5225 for (; items != NULL; items = g_slist_next(items)) {
5226 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
5227 gtk_widget_set_sensitive(item->widget, sensitive);
5231 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5237 gint num = 0, def_menu = 0;
5239 accounts = account_get_list();
5240 g_return_val_if_fail(accounts != NULL, NULL);
5242 hbox = gtk_hbox_new(FALSE, 0);
5243 optmenu = gtk_option_menu_new();
5244 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5245 menu = gtk_menu_new();
5247 for (; accounts != NULL; accounts = accounts->next, num++) {
5248 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5249 GtkWidget *menuitem;
5252 if (ac == compose->account) def_menu = num;
5255 name = g_strdup_printf("%s: %s <%s>",
5257 ac->name, ac->address);
5259 name = g_strdup_printf("%s: %s",
5260 ac->account_name, ac->address);
5261 MENUITEM_ADD(menu, menuitem, name, ac);
5263 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
5264 GTK_SIGNAL_FUNC(account_activated),
5268 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5269 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5274 static void compose_set_priority_cb(gpointer data,
5278 Compose *compose = (Compose *) data;
5279 compose->priority = action;
5282 static void compose_update_priority_menu_item(Compose * compose)
5284 GtkItemFactory *ifactory;
5285 GtkWidget *menuitem = NULL;
5287 ifactory = gtk_item_factory_from_widget(compose->menubar);
5289 switch (compose->priority) {
5290 case PRIORITY_HIGHEST:
5291 menuitem = gtk_item_factory_get_item
5292 (ifactory, "/Message/Priority/Highest");
5295 menuitem = gtk_item_factory_get_item
5296 (ifactory, "/Message/Priority/High");
5298 case PRIORITY_NORMAL:
5299 menuitem = gtk_item_factory_get_item
5300 (ifactory, "/Message/Priority/Normal");
5303 menuitem = gtk_item_factory_get_item
5304 (ifactory, "/Message/Priority/Low");
5306 case PRIORITY_LOWEST:
5307 menuitem = gtk_item_factory_get_item
5308 (ifactory, "/Message/Priority/Lowest");
5311 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5315 static void compose_set_gnupg_mode_cb(gpointer data,
5319 Compose *compose = (Compose *) data;
5320 compose->gnupg_mode = action;
5323 static void compose_update_gnupg_mode_menu_item(Compose * compose)
5325 GtkItemFactory *ifactory;
5326 GtkWidget *menuitem = NULL;
5328 ifactory = gtk_item_factory_from_widget(compose->menubar);
5330 switch (compose->gnupg_mode) {
5331 case GNUPG_MODE_DETACH:
5332 menuitem = gtk_item_factory_get_item
5333 (ifactory, "/Message/Mode/MIME");
5335 case GNUPG_MODE_INLINE:
5336 menuitem = gtk_item_factory_get_item
5337 (ifactory, "/Message/Mode/Inline");
5340 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5342 if (compose->use_encryption == TRUE || compose->use_signing == TRUE)
5343 menu_set_sensitive(ifactory, "/Message/Mode", TRUE);
5345 menu_set_sensitive(ifactory, "/Message/Mode", FALSE);
5349 static void compose_set_template_menu(Compose *compose)
5351 GSList *tmpl_list, *cur;
5355 tmpl_list = template_get_config();
5357 menu = gtk_menu_new();
5359 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5360 Template *tmpl = (Template *)cur->data;
5362 item = gtk_menu_item_new_with_label(tmpl->name);
5363 gtk_menu_append(GTK_MENU(menu), item);
5364 gtk_signal_connect(GTK_OBJECT(item), "activate",
5365 GTK_SIGNAL_FUNC(compose_template_activate_cb),
5367 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
5368 gtk_widget_show(item);
5371 gtk_widget_show(menu);
5372 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5375 void compose_reflect_prefs_all(void)
5380 for (cur = compose_list; cur != NULL; cur = cur->next) {
5381 compose = (Compose *)cur->data;
5382 compose_set_template_menu(compose);
5386 void compose_reflect_prefs_pixmap_theme(void)
5391 for (cur = compose_list; cur != NULL; cur = cur->next) {
5392 compose = (Compose *)cur->data;
5393 compose_toolbar_update(compose);
5394 set_toolbar_style(compose);
5398 static void compose_template_apply(Compose *compose, Template *tmpl,
5404 if (!tmpl || !tmpl->value) return;
5406 gtk_stext_freeze(GTK_STEXT(compose->text));
5408 if (tmpl->subject && *tmpl->subject != '\0')
5409 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5411 if (tmpl->to && *tmpl->to != '\0')
5412 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5413 if (tmpl->cc && *tmpl->cc != '\0')
5414 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5416 if (tmpl->bcc && *tmpl->bcc != '\0')
5417 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5420 gtk_stext_clear(GTK_STEXT(compose->text));
5422 if (compose->replyinfo == NULL) {
5423 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5426 if (prefs_common.quotemark && *prefs_common.quotemark)
5427 qmark = prefs_common.quotemark;
5431 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5432 tmpl->value, qmark, NULL);
5435 if (replace && parsed_str && prefs_common.auto_sig)
5436 compose_insert_sig(compose);
5438 if (replace && parsed_str) {
5439 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
5440 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
5444 compose_changed_cb(NULL, compose);
5446 gtk_stext_thaw(GTK_STEXT(compose->text));
5449 static void compose_destroy(Compose *compose)
5452 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5455 /* NOTE: address_completion_end() does nothing with the window
5456 * however this may change. */
5457 address_completion_end(compose->window);
5459 slist_free_strings(compose->to_list);
5460 g_slist_free(compose->to_list);
5461 slist_free_strings(compose->newsgroup_list);
5462 g_slist_free(compose->newsgroup_list);
5463 slist_free_strings(compose->header_list);
5464 g_slist_free(compose->header_list);
5466 procmsg_msginfo_free(compose->targetinfo);
5467 procmsg_msginfo_free(compose->replyinfo);
5469 g_free(compose->replyto);
5470 g_free(compose->cc);
5471 g_free(compose->bcc);
5472 g_free(compose->newsgroups);
5473 g_free(compose->followup_to);
5475 g_free(compose->ml_post);
5477 g_free(compose->inreplyto);
5478 g_free(compose->references);
5479 g_free(compose->msgid);
5480 g_free(compose->boundary);
5482 if (compose->redirect_filename)
5483 g_free(compose->redirect_filename);
5485 g_free(compose->exteditor_file);
5487 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5489 compose_attach_info_free(ainfo);
5491 if (addressbook_get_target_compose() == compose)
5492 addressbook_set_target_compose(NULL);
5495 if (compose->gtkaspell) {
5496 gtkaspell_delete(compose->gtkaspell);
5500 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5501 prefs_common.compose_height = compose->window->allocation.height;
5503 gtk_widget_destroy(compose->paned);
5505 TOOLBAR_DESTROY_ITEMS(compose->toolbar->t_item_list);
5506 TOOLBAR_DESTROY_ACTIONS(compose->toolbar->t_action_list);
5507 g_free(compose->toolbar);
5510 compose_list = g_list_remove(compose_list, compose);
5513 static void compose_attach_info_free(AttachInfo *ainfo)
5515 g_free(ainfo->file);
5516 g_free(ainfo->content_type);
5517 g_free(ainfo->name);
5521 static void compose_attach_remove_selected(Compose *compose)
5523 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5527 while (clist->selection != NULL) {
5528 row = GPOINTER_TO_INT(clist->selection->data);
5529 ainfo = gtk_clist_get_row_data(clist, row);
5530 compose_attach_info_free(ainfo);
5531 gtk_clist_remove(clist, row);
5535 static struct _AttachProperty
5538 GtkWidget *mimetype_entry;
5539 GtkWidget *encoding_optmenu;
5540 GtkWidget *path_entry;
5541 GtkWidget *filename_entry;
5543 GtkWidget *cancel_btn;
5546 static void compose_attach_property(Compose *compose)
5548 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5551 GtkOptionMenu *optmenu;
5552 static gboolean cancelled;
5554 if (!clist->selection) return;
5555 row = GPOINTER_TO_INT(clist->selection->data);
5557 ainfo = gtk_clist_get_row_data(clist, row);
5560 if (!attach_prop.window)
5561 compose_attach_property_create(&cancelled);
5562 gtk_widget_grab_focus(attach_prop.ok_btn);
5563 gtk_widget_show(attach_prop.window);
5564 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5566 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5567 if (ainfo->encoding == ENC_UNKNOWN)
5568 gtk_option_menu_set_history(optmenu, ENC_BASE64);
5570 gtk_option_menu_set_history(optmenu, ainfo->encoding);
5572 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5573 ainfo->content_type ? ainfo->content_type : "");
5574 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5575 ainfo->file ? ainfo->file : "");
5576 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5577 ainfo->name ? ainfo->name : "");
5581 gchar *cnttype = NULL;
5585 GtkWidget *menuitem;
5590 if (cancelled == TRUE) {
5591 gtk_widget_hide(attach_prop.window);
5595 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5596 if (*text != '\0') {
5599 text = g_strstrip(g_strdup(text));
5600 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5601 cnttype = g_strdup(text);
5604 alertpanel_error(_("Invalid MIME type."));
5610 menu = gtk_option_menu_get_menu(optmenu);
5611 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5612 ainfo->encoding = GPOINTER_TO_INT
5613 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5615 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5616 if (*text != '\0') {
5617 if (is_file_exist(text) &&
5618 (size = get_file_size(text)) > 0)
5619 file = g_strdup(text);
5622 (_("File doesn't exist or is empty."));
5628 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5629 if (*text != '\0') {
5630 g_free(ainfo->name);
5631 ainfo->name = g_strdup(text);
5635 g_free(ainfo->content_type);
5636 ainfo->content_type = cnttype;
5639 g_free(ainfo->file);
5645 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5646 ainfo->content_type);
5647 gtk_clist_set_text(clist, row, COL_SIZE,
5648 to_human_readable(ainfo->size));
5649 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5651 gtk_widget_hide(attach_prop.window);
5656 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5658 label = gtk_label_new(str); \
5659 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5660 GTK_FILL, 0, 0, 0); \
5661 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5663 entry = gtk_entry_new(); \
5664 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5665 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5668 static void compose_attach_property_create(gboolean *cancelled)
5674 GtkWidget *mimetype_entry;
5677 GtkWidget *optmenu_menu;
5678 GtkWidget *menuitem;
5679 GtkWidget *path_entry;
5680 GtkWidget *filename_entry;
5683 GtkWidget *cancel_btn;
5684 GList *mime_type_list, *strlist;
5686 debug_print("Creating attach_property window...\n");
5688 window = gtk_window_new(GTK_WINDOW_DIALOG);
5689 gtk_widget_set_usize(window, 480, -1);
5690 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5691 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
5692 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5693 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5694 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5695 GTK_SIGNAL_FUNC(attach_property_delete_event),
5697 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5698 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5701 vbox = gtk_vbox_new(FALSE, 8);
5702 gtk_container_add(GTK_CONTAINER(window), vbox);
5704 table = gtk_table_new(4, 2, FALSE);
5705 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5706 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5707 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5709 label = gtk_label_new(_("MIME type"));
5710 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5712 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5713 mimetype_entry = gtk_combo_new();
5714 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5715 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5717 /* stuff with list */
5718 mime_type_list = procmime_get_mime_type_list();
5720 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5721 MimeType *type = (MimeType *) mime_type_list->data;
5722 strlist = g_list_append(strlist,
5723 g_strdup_printf("%s/%s",
5724 type->type, type->sub_type));
5727 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5729 for (mime_type_list = strlist; mime_type_list != NULL;
5730 mime_type_list = mime_type_list->next)
5731 g_free(mime_type_list->data);
5732 g_list_free(strlist);
5734 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5736 label = gtk_label_new(_("Encoding"));
5737 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5739 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5741 hbox = gtk_hbox_new(FALSE, 0);
5742 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5743 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5745 optmenu = gtk_option_menu_new();
5746 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5748 optmenu_menu = gtk_menu_new();
5749 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5750 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5752 gtk_widget_set_sensitive(menuitem, FALSE);
5754 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5755 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5757 gtk_widget_set_sensitive(menuitem, FALSE);
5759 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5760 gtk_widget_set_sensitive(menuitem, FALSE);
5761 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5763 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5765 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5766 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5768 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5769 &cancel_btn, _("Cancel"), NULL, NULL);
5770 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5771 gtk_widget_grab_default(ok_btn);
5773 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5774 GTK_SIGNAL_FUNC(attach_property_ok),
5776 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5777 GTK_SIGNAL_FUNC(attach_property_cancel),
5780 gtk_widget_show_all(vbox);
5782 attach_prop.window = window;
5783 attach_prop.mimetype_entry = mimetype_entry;
5784 attach_prop.encoding_optmenu = optmenu;
5785 attach_prop.path_entry = path_entry;
5786 attach_prop.filename_entry = filename_entry;
5787 attach_prop.ok_btn = ok_btn;
5788 attach_prop.cancel_btn = cancel_btn;
5791 #undef SET_LABEL_AND_ENTRY
5793 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5799 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5805 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5806 gboolean *cancelled)
5814 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5815 gboolean *cancelled)
5817 if (event && event->keyval == GDK_Escape) {
5823 static void compose_exec_ext_editor(Compose *compose)
5829 tmp = g_strdup_printf("%s%ctmpmsg.%08x", get_tmp_dir(),
5830 G_DIR_SEPARATOR, (gint)compose);
5832 if (pipe(pipe_fds) < 0) {
5838 if ((pid = fork()) < 0) {
5845 /* close the write side of the pipe */
5848 compose->exteditor_file = g_strdup(tmp);
5849 compose->exteditor_pid = pid;
5850 compose->exteditor_readdes = pipe_fds[0];
5852 compose_set_ext_editor_sensitive(compose, FALSE);
5854 compose->exteditor_tag =
5855 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5856 compose_input_cb, compose);
5857 } else { /* process-monitoring process */
5863 /* close the read side of the pipe */
5866 if (compose_write_body_to_file(compose, tmp) < 0) {
5867 fd_write(pipe_fds[1], "2\n", 2);
5871 pid_ed = compose_exec_ext_editor_real(tmp);
5873 fd_write(pipe_fds[1], "1\n", 2);
5877 /* wait until editor is terminated */
5878 waitpid(pid_ed, NULL, 0);
5880 fd_write(pipe_fds[1], "0\n", 2);
5889 static gint compose_exec_ext_editor_real(const gchar *file)
5891 static gchar *def_cmd = "emacs %s";
5897 g_return_val_if_fail(file != NULL, -1);
5899 if ((pid = fork()) < 0) {
5904 if (pid != 0) return pid;
5906 /* grandchild process */
5908 if (setpgid(0, getppid()))
5911 if (prefs_common.ext_editor_cmd &&
5912 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5913 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5914 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5916 if (prefs_common.ext_editor_cmd)
5917 g_warning(_("External editor command line is invalid: `%s'\n"),
5918 prefs_common.ext_editor_cmd);
5919 g_snprintf(buf, sizeof(buf), def_cmd, file);
5922 cmdline = strsplit_with_quote(buf, " ", 1024);
5923 execvp(cmdline[0], cmdline);
5926 g_strfreev(cmdline);
5931 static gboolean compose_ext_editor_kill(Compose *compose)
5933 pid_t pgid = compose->exteditor_pid * -1;
5936 ret = kill(pgid, 0);
5938 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5942 msg = g_strdup_printf
5943 (_("The external editor is still working.\n"
5944 "Force terminating the process?\n"
5945 "process group id: %d"), -pgid);
5946 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5949 if (val == G_ALERTDEFAULT) {
5950 gdk_input_remove(compose->exteditor_tag);
5951 close(compose->exteditor_readdes);
5953 if (kill(pgid, SIGTERM) < 0) perror("kill");
5954 waitpid(compose->exteditor_pid, NULL, 0);
5956 g_warning(_("Terminated process group id: %d"), -pgid);
5957 g_warning(_("Temporary file: %s"),
5958 compose->exteditor_file);
5960 compose_set_ext_editor_sensitive(compose, TRUE);
5962 g_free(compose->exteditor_file);
5963 compose->exteditor_file = NULL;
5964 compose->exteditor_pid = -1;
5965 compose->exteditor_readdes = -1;
5966 compose->exteditor_tag = -1;
5974 static void compose_input_cb(gpointer data, gint source,
5975 GdkInputCondition condition)
5978 Compose *compose = (Compose *)data;
5981 debug_print("Compose: input from monitoring process\n");
5983 gdk_input_remove(compose->exteditor_tag);
5986 if (read(source, &buf[i], 1) < 1) {
5990 if (buf[i] == '\n') {
5995 if (i == sizeof(buf) - 1)
5999 waitpid(compose->exteditor_pid, NULL, 0);
6001 if (buf[0] == '0') { /* success */
6002 GtkSText *text = GTK_STEXT(compose->text);
6004 gtk_stext_freeze(text);
6005 gtk_stext_set_point(text, 0);
6006 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
6007 compose_insert_file(compose, compose->exteditor_file);
6008 compose_changed_cb(NULL, compose);
6009 gtk_stext_thaw(text);
6011 if (unlink(compose->exteditor_file) < 0)
6012 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6013 } else if (buf[0] == '1') { /* failed */
6014 g_warning(_("Couldn't exec external editor\n"));
6015 if (unlink(compose->exteditor_file) < 0)
6016 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6017 } else if (buf[0] == '2') {
6018 g_warning(_("Couldn't write to file\n"));
6019 } else if (buf[0] == '3') {
6020 g_warning(_("Pipe read failed\n"));
6025 compose_set_ext_editor_sensitive(compose, TRUE);
6027 g_free(compose->exteditor_file);
6028 compose->exteditor_file = NULL;
6029 compose->exteditor_pid = -1;
6030 compose->exteditor_readdes = -1;
6031 compose->exteditor_tag = -1;
6034 static void compose_set_ext_editor_sensitive(Compose *compose,
6037 GtkItemFactory *ifactory;
6039 ifactory = gtk_item_factory_from_widget(compose->menubar);
6041 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6042 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6043 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
6045 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
6046 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
6047 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6048 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6049 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6052 gtk_widget_set_sensitive(compose->text, sensitive);
6053 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6054 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6055 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6056 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6057 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6058 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6059 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
6063 * compose_undo_state_changed:
6065 * Change the sensivity of the menuentries undo and redo
6067 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6068 gint redo_state, gpointer data)
6070 GtkWidget *widget = GTK_WIDGET(data);
6071 GtkItemFactory *ifactory;
6073 g_return_if_fail(widget != NULL);
6075 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
6077 ifactory = gtk_item_factory_from_widget(widget);
6079 switch (undo_state) {
6080 case UNDO_STATE_TRUE:
6081 if (!undostruct->undo_state) {
6082 debug_print ("Set_undo - Testpoint\n");
6083 undostruct->undo_state = TRUE;
6084 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6087 case UNDO_STATE_FALSE:
6088 if (undostruct->undo_state) {
6089 undostruct->undo_state = FALSE;
6090 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6093 case UNDO_STATE_UNCHANGED:
6095 case UNDO_STATE_REFRESH:
6096 menu_set_sensitive(ifactory, "/Edit/Undo",
6097 undostruct->undo_state);
6100 g_warning("Undo state not recognized");
6104 switch (redo_state) {
6105 case UNDO_STATE_TRUE:
6106 if (!undostruct->redo_state) {
6107 undostruct->redo_state = TRUE;
6108 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6111 case UNDO_STATE_FALSE:
6112 if (undostruct->redo_state) {
6113 undostruct->redo_state = FALSE;
6114 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6117 case UNDO_STATE_UNCHANGED:
6119 case UNDO_STATE_REFRESH:
6120 menu_set_sensitive(ifactory, "/Edit/Redo",
6121 undostruct->redo_state);
6124 g_warning("Redo state not recognized");
6129 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
6133 cursor_pos = (text->cursor_pos_x - extra) / char_width;
6134 cursor_pos = MAX(cursor_pos, 0);
6139 /* callback functions */
6141 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6142 * includes "non-client" (windows-izm) in calculation, so this calculation
6143 * may not be accurate.
6145 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6146 GtkAllocation *allocation,
6147 GtkSHRuler *shruler)
6149 if (prefs_common.show_ruler) {
6151 gint line_width_in_chars;
6153 char_width = gtkut_get_font_width
6154 (GTK_WIDGET(widget)->style->font);
6155 line_width_in_chars =
6156 (allocation->width - allocation->x) / char_width;
6158 /* got the maximum */
6159 gtk_ruler_set_range(GTK_RULER(shruler),
6160 0.0, line_width_in_chars,
6161 calc_cursor_xpos(GTK_STEXT(widget),
6164 /*line_width_in_chars*/ char_width);
6170 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
6172 compose_send_cb(data, 0, NULL);
6175 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
6177 compose_send_later_cb(data, 0, NULL);
6180 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
6182 compose_draft_cb(data, 0, NULL);
6185 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
6187 compose_insert_file_cb(data, 0, NULL);
6190 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
6192 compose_attach_cb(data, 0, NULL);
6195 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
6197 Compose *compose = (Compose *)data;
6199 compose_insert_sig(compose);
6202 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
6204 Compose *compose = (Compose *)data;
6206 compose_exec_ext_editor(compose);
6209 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
6211 Compose *compose = (Compose *)data;
6213 compose_wrap_line(compose);
6216 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
6218 compose_address_cb(data, 0, NULL);
6221 static void toolbar_actions_execute_cb(GtkWidget *widget,
6224 Compose *compose = (Compose*)data;
6226 toolbar_action_execute(widget, compose->toolbar->t_action_list, data, TOOLBAR_COMPOSE);
6229 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6231 Compose *compose = (Compose *)data;
6235 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
6236 g_return_if_fail(ac != NULL);
6238 if (ac != compose->account)
6239 compose_select_account(compose, ac);
6242 static void attach_selected(GtkCList *clist, gint row, gint column,
6243 GdkEvent *event, gpointer data)
6245 Compose *compose = (Compose *)data;
6247 if (event && event->type == GDK_2BUTTON_PRESS)
6248 compose_attach_property(compose);
6251 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6254 Compose *compose = (Compose *)data;
6255 GtkCList *clist = GTK_CLIST(compose->attach_clist);
6260 if (event->button == 3) {
6261 if ((clist->selection && !clist->selection->next) ||
6262 !clist->selection) {
6263 gtk_clist_unselect_all(clist);
6264 if (gtk_clist_get_selection_info(clist,
6267 gtk_clist_select_row(clist, row, column);
6268 gtkut_clist_set_focus_row(clist, row);
6271 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6272 NULL, NULL, event->button, event->time);
6276 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6279 Compose *compose = (Compose *)data;
6283 switch (event->keyval) {
6285 compose_attach_remove_selected(compose);
6290 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6292 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6293 compose_toolbar_set_sensitive(compose, allow);
6294 menu_set_sensitive(ifactory, "/File", allow);
6295 menu_set_sensitive(ifactory, "/Edit", allow);
6296 menu_set_sensitive(ifactory, "/Message", allow);
6297 menu_set_sensitive(ifactory, "/Tools", allow);
6298 menu_set_sensitive(ifactory, "/Help", allow);
6301 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6303 Compose *compose = (Compose *)data;
6306 if (prefs_common.work_offline)
6307 if (alertpanel(_("Offline warning"),
6308 _("You're working offline. Override?"),
6309 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
6312 compose_allow_user_actions (compose, FALSE);
6313 compose->sending = TRUE;
6314 val = compose_send(compose);
6315 compose_allow_user_actions (compose, TRUE);
6316 compose->sending = FALSE;
6318 if (val == 0) gtk_widget_destroy(compose->window);
6321 static void compose_send_later_cb(gpointer data, guint action,
6324 Compose *compose = (Compose *)data;
6327 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6328 if (!val) gtk_widget_destroy(compose->window);
6331 void compose_draft (gpointer data)
6333 compose_draft_cb(data, 0, NULL);
6336 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6338 Compose *compose = (Compose *)data;
6342 static gboolean lock = FALSE;
6343 MsgInfo *newmsginfo;
6347 draft = account_get_special_folder(compose->account, F_DRAFT);
6348 g_return_if_fail(draft != NULL);
6352 tmp = g_strdup_printf("%s%cdraft.%08x", get_tmp_dir(),
6353 G_DIR_SEPARATOR, (gint)compose);
6355 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
6361 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) < 0) {
6368 draft->mtime = 0; /* force updating */
6370 if (compose->mode == COMPOSE_REEDIT) {
6371 compose_remove_reedit_target(compose);
6372 if (compose->targetinfo &&
6373 compose->targetinfo->folder != draft)
6374 folder_update_item(compose->targetinfo->folder,
6378 newmsginfo = folder_item_fetch_msginfo(draft, msgnum);
6379 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6380 MSG_SET_TMP_FLAGS(newmsginfo->flags, MSG_DRAFT);
6381 folder_update_item(draft, TRUE);
6382 procmsg_msginfo_free(newmsginfo);
6386 /* 0: quit editing 1: keep editing */
6388 gtk_widget_destroy(compose->window);
6393 path = folder_item_fetch_msg(draft, msgnum);
6394 g_return_if_fail(path != NULL);
6395 if (stat(path, &s) < 0) {
6396 FILE_OP_ERROR(path, "stat");
6403 procmsg_msginfo_free(compose->targetinfo);
6404 compose->targetinfo = procmsg_msginfo_new();
6405 compose->targetinfo->msgnum = msgnum;
6406 compose->targetinfo->size = s.st_size;
6407 compose->targetinfo->mtime = s.st_mtime;
6408 compose->targetinfo->folder = draft;
6409 compose->mode = COMPOSE_REEDIT;
6413 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6415 Compose *compose = (Compose *)data;
6418 if (compose->redirect_filename != NULL)
6421 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6426 for ( tmp = file_list; tmp; tmp = tmp->next) {
6427 gchar *file = (gchar *) tmp->data;
6428 compose_attach_append(compose, file, file, NULL);
6429 compose_changed_cb(NULL, compose);
6432 g_list_free(file_list);
6436 static void compose_insert_file_cb(gpointer data, guint action,
6439 Compose *compose = (Compose *)data;
6442 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6447 for ( tmp = file_list; tmp; tmp = tmp->next) {
6448 gchar *file = (gchar *) tmp->data;
6449 compose_insert_file(compose, file);
6452 g_list_free(file_list);
6456 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6459 Compose *compose = (Compose *)data;
6460 if (compose->sending)
6462 compose_close_cb(compose, 0, NULL);
6466 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6468 Compose *compose = (Compose *)data;
6471 if (compose->exteditor_tag != -1) {
6472 if (!compose_ext_editor_kill(compose))
6476 if (compose->modified) {
6477 val = alertpanel(_("Discard message"),
6478 _("This message has been modified. discard it?"),
6479 _("Discard"), _("to Draft"), _("Cancel"));
6482 case G_ALERTDEFAULT:
6483 if (prefs_common.autosave)
6484 compose_remove_draft(compose);
6486 case G_ALERTALTERNATE:
6487 compose_draft_cb(data, 0, NULL);
6494 gtk_widget_destroy(compose->window);
6497 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6499 Compose *compose = (Compose *)data;
6501 addressbook_open(compose);
6504 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6506 Compose *compose = (Compose *)data;
6511 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6512 g_return_if_fail(tmpl != NULL);
6514 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6516 val = alertpanel(_("Apply template"), msg,
6517 _("Replace"), _("Insert"), _("Cancel"));
6520 if (val == G_ALERTDEFAULT)
6521 compose_template_apply(compose, tmpl, TRUE);
6522 else if (val == G_ALERTALTERNATE)
6523 compose_template_apply(compose, tmpl, FALSE);
6526 static void compose_ext_editor_cb(gpointer data, guint action,
6529 Compose *compose = (Compose *)data;
6531 compose_exec_ext_editor(compose);
6534 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6536 if (compose->sending)
6538 compose_destroy(compose);
6541 static void compose_undo_cb(Compose *compose)
6543 undo_undo(compose->undostruct);
6546 static void compose_redo_cb(Compose *compose)
6548 undo_redo(compose->undostruct);
6551 static void compose_cut_cb(Compose *compose)
6553 if (compose->focused_editable &&
6554 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6555 gtk_editable_cut_clipboard
6556 (GTK_EDITABLE(compose->focused_editable));
6559 static void compose_copy_cb(Compose *compose)
6561 if (compose->focused_editable &&
6562 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6563 gtk_editable_copy_clipboard
6564 (GTK_EDITABLE(compose->focused_editable));
6567 static void compose_paste_cb(Compose *compose)
6569 if (compose->focused_editable &&
6570 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6571 gtk_editable_paste_clipboard
6572 (GTK_EDITABLE(compose->focused_editable));
6575 static void compose_paste_as_quote_cb(Compose *compose)
6577 if (compose->focused_editable &&
6578 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6579 compose->paste_as_quotation = TRUE;
6580 gtk_editable_paste_clipboard
6581 (GTK_EDITABLE(compose->focused_editable));
6582 compose->paste_as_quotation = FALSE;
6586 static void compose_allsel_cb(Compose *compose)
6588 if (compose->focused_editable &&
6589 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6590 gtk_editable_select_region
6591 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6594 static void compose_gtk_stext_action_cb(Compose *compose,
6595 ComposeCallGtkSTextAction action)
6597 GtkSText *text = GTK_STEXT(compose->text);
6599 void (*do_action) (GtkSText *text);
6600 } action_table[] = {
6601 {gtk_stext_move_beginning_of_line},
6602 {gtk_stext_move_forward_character},
6603 {gtk_stext_move_backward_character},
6604 {gtk_stext_move_forward_word},
6605 {gtk_stext_move_backward_word},
6606 {gtk_stext_move_end_of_line},
6607 {gtk_stext_move_next_line},
6608 {gtk_stext_move_previous_line},
6609 {gtk_stext_delete_forward_character},
6610 {gtk_stext_delete_backward_character},
6611 {gtk_stext_delete_forward_word},
6612 {gtk_stext_delete_backward_word},
6613 {gtk_stext_delete_line},
6614 {gtk_stext_delete_line}, /* gtk_stext_delete_line_n */
6615 {gtk_stext_delete_to_line_end}
6618 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
6620 if (action >= COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE &&
6621 action <= COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END)
6622 action_table[action].do_action(text);
6625 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6627 if (GTK_IS_EDITABLE(widget))
6628 compose->focused_editable = widget;
6631 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6633 if (compose->modified == FALSE) {
6634 compose->modified = TRUE;
6635 compose_set_title(compose);
6639 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6642 gtk_stext_set_point(GTK_STEXT(widget),
6643 gtk_editable_get_position(GTK_EDITABLE(widget)));
6647 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6650 gtk_stext_set_point(GTK_STEXT(widget),
6651 gtk_editable_get_position(GTK_EDITABLE(widget)));
6655 #if 0 /* NEW COMPOSE GUI */
6656 static void compose_toggle_to_cb(gpointer data, guint action,
6659 Compose *compose = (Compose *)data;
6661 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6662 gtk_widget_show(compose->to_hbox);
6663 gtk_widget_show(compose->to_entry);
6664 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6665 compose->use_to = TRUE;
6667 gtk_widget_hide(compose->to_hbox);
6668 gtk_widget_hide(compose->to_entry);
6669 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6670 gtk_widget_queue_resize(compose->table_vbox);
6671 compose->use_to = FALSE;
6674 if (addressbook_get_target_compose() == compose)
6675 addressbook_set_target_compose(compose);
6678 static void compose_toggle_cc_cb(gpointer data, guint action,
6681 Compose *compose = (Compose *)data;
6683 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6684 gtk_widget_show(compose->cc_hbox);
6685 gtk_widget_show(compose->cc_entry);
6686 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6687 compose->use_cc = TRUE;
6689 gtk_widget_hide(compose->cc_hbox);
6690 gtk_widget_hide(compose->cc_entry);
6691 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6692 gtk_widget_queue_resize(compose->table_vbox);
6693 compose->use_cc = FALSE;
6696 if (addressbook_get_target_compose() == compose)
6697 addressbook_set_target_compose(compose);
6700 static void compose_toggle_bcc_cb(gpointer data, guint action,
6703 Compose *compose = (Compose *)data;
6705 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6706 gtk_widget_show(compose->bcc_hbox);
6707 gtk_widget_show(compose->bcc_entry);
6708 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6709 compose->use_bcc = TRUE;
6711 gtk_widget_hide(compose->bcc_hbox);
6712 gtk_widget_hide(compose->bcc_entry);
6713 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6714 gtk_widget_queue_resize(compose->table_vbox);
6715 compose->use_bcc = FALSE;
6718 if (addressbook_get_target_compose() == compose)
6719 addressbook_set_target_compose(compose);
6722 static void compose_toggle_replyto_cb(gpointer data, guint action,
6725 Compose *compose = (Compose *)data;
6727 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6728 gtk_widget_show(compose->reply_hbox);
6729 gtk_widget_show(compose->reply_entry);
6730 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6731 compose->use_replyto = TRUE;
6733 gtk_widget_hide(compose->reply_hbox);
6734 gtk_widget_hide(compose->reply_entry);
6735 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6736 gtk_widget_queue_resize(compose->table_vbox);
6737 compose->use_replyto = FALSE;
6741 static void compose_toggle_followupto_cb(gpointer data, guint action,
6744 Compose *compose = (Compose *)data;
6746 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6747 gtk_widget_show(compose->followup_hbox);
6748 gtk_widget_show(compose->followup_entry);
6749 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6750 compose->use_followupto = TRUE;
6752 gtk_widget_hide(compose->followup_hbox);
6753 gtk_widget_hide(compose->followup_entry);
6754 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6755 gtk_widget_queue_resize(compose->table_vbox);
6756 compose->use_followupto = FALSE;
6760 static void compose_toggle_attach_cb(gpointer data, guint action,
6763 Compose *compose = (Compose *)data;
6765 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6766 gtk_widget_ref(compose->edit_vbox);
6768 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6769 compose->edit_vbox);
6770 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6771 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6773 gtk_widget_show(compose->paned);
6775 gtk_widget_unref(compose->edit_vbox);
6776 gtk_widget_unref(compose->paned);
6778 compose->use_attach = TRUE;
6780 gtk_widget_ref(compose->paned);
6781 gtk_widget_ref(compose->edit_vbox);
6783 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6785 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6786 compose->edit_vbox);
6787 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6788 compose->edit_vbox, TRUE, TRUE, 0);
6790 gtk_widget_unref(compose->edit_vbox);
6792 compose->use_attach = FALSE;
6798 static void compose_toggle_sign_cb(gpointer data, guint action,
6801 Compose *compose = (Compose *)data;
6803 if (GTK_CHECK_MENU_ITEM(widget)->active)
6804 compose->use_signing = TRUE;
6806 compose->use_signing = FALSE;
6808 compose_update_gnupg_mode_menu_item(compose);
6811 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6814 Compose *compose = (Compose *)data;
6816 if (GTK_CHECK_MENU_ITEM(widget)->active)
6817 compose->use_encryption = TRUE;
6819 compose->use_encryption = FALSE;
6821 compose_update_gnupg_mode_menu_item(compose);
6824 static void activate_gnupg_mode (Compose *compose, PrefsAccount *account)
6826 if (account->default_gnupg_mode)
6827 compose->gnupg_mode = GNUPG_MODE_INLINE;
6829 compose->gnupg_mode = GNUPG_MODE_DETACH;
6831 compose_update_gnupg_mode_menu_item(compose);
6833 #endif /* USE_GPGME */
6835 static void compose_toggle_ruler_cb(gpointer data, guint action,
6838 Compose *compose = (Compose *)data;
6840 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6841 gtk_widget_show(compose->ruler_hbox);
6842 prefs_common.show_ruler = TRUE;
6844 gtk_widget_hide(compose->ruler_hbox);
6845 gtk_widget_queue_resize(compose->edit_vbox);
6846 prefs_common.show_ruler = FALSE;
6850 static void compose_attach_drag_received_cb (GtkWidget *widget,
6851 GdkDragContext *drag_context,
6854 GtkSelectionData *data,
6859 Compose *compose = (Compose *)user_data;
6862 list = uri_list_extract_filenames((const gchar *)data->data);
6863 for (tmp = list; tmp != NULL; tmp = tmp->next)
6864 compose_attach_append
6865 (compose, (const gchar *)tmp->data,
6866 (const gchar *)tmp->data, NULL);
6867 if (list) compose_changed_cb(NULL, compose);
6868 list_free_strings(list);
6872 static void compose_insert_drag_received_cb (GtkWidget *widget,
6873 GdkDragContext *drag_context,
6876 GtkSelectionData *data,
6881 Compose *compose = (Compose *)user_data;
6884 list = uri_list_extract_filenames((const gchar *)data->data);
6885 for (tmp = list; tmp != NULL; tmp = tmp->next)
6886 compose_insert_file(compose, (const gchar *)tmp->data);
6887 list_free_strings(list);
6891 #if 0 /* NEW COMPOSE GUI */
6892 static void to_activated(GtkWidget *widget, Compose *compose)
6894 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6895 gtk_widget_grab_focus(compose->newsgroups_entry);
6897 gtk_widget_grab_focus(compose->subject_entry);
6900 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6902 gtk_widget_grab_focus(compose->subject_entry);
6905 static void subject_activated(GtkWidget *widget, Compose *compose)
6907 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6908 gtk_widget_grab_focus(compose->cc_entry);
6909 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6910 gtk_widget_grab_focus(compose->bcc_entry);
6911 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6912 gtk_widget_grab_focus(compose->reply_entry);
6913 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6914 gtk_widget_grab_focus(compose->followup_entry);
6916 gtk_widget_grab_focus(compose->text);
6919 static void cc_activated(GtkWidget *widget, Compose *compose)
6921 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6922 gtk_widget_grab_focus(compose->bcc_entry);
6923 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6924 gtk_widget_grab_focus(compose->reply_entry);
6925 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6926 gtk_widget_grab_focus(compose->followup_entry);
6928 gtk_widget_grab_focus(compose->text);
6931 static void bcc_activated(GtkWidget *widget, Compose *compose)
6933 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6934 gtk_widget_grab_focus(compose->reply_entry);
6935 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6936 gtk_widget_grab_focus(compose->followup_entry);
6938 gtk_widget_grab_focus(compose->text);
6941 static void replyto_activated(GtkWidget *widget, Compose *compose)
6943 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6944 gtk_widget_grab_focus(compose->followup_entry);
6946 gtk_widget_grab_focus(compose->text);
6949 static void followupto_activated(GtkWidget *widget, Compose *compose)
6951 gtk_widget_grab_focus(compose->text);
6955 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6958 Compose *compose = (Compose *)data;
6960 if (GTK_CHECK_MENU_ITEM(widget)->active)
6961 compose->return_receipt = TRUE;
6963 compose->return_receipt = FALSE;
6966 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6968 ComposeHeaderEntry *headerentry)
6970 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6971 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6972 !(event->state & GDK_MODIFIER_MASK) &&
6973 (event->keyval == GDK_BackSpace) &&
6974 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6975 gtk_container_remove
6976 (GTK_CONTAINER(headerentry->compose->header_table),
6977 headerentry->combo);
6978 gtk_container_remove
6979 (GTK_CONTAINER(headerentry->compose->header_table),
6980 headerentry->entry);
6981 headerentry->compose->header_list =
6982 g_slist_remove(headerentry->compose->header_list,
6984 g_free(headerentry);
6985 } else if (event->keyval == GDK_Tab) {
6986 if (headerentry->compose->header_last == headerentry) {
6987 /* Override default next focus, and give it to subject_entry
6988 * instead of notebook tabs
6990 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6991 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6997 void compose_headerentry_changed_cb(GtkWidget *entry,
6998 ComposeHeaderEntry *headerentry)
7000 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
7001 headerentry->compose->header_list =
7002 g_slist_append(headerentry->compose->header_list,
7004 compose_create_header_entry(headerentry->compose);
7005 gtk_signal_disconnect_by_func
7007 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
7009 /* Automatically scroll down */
7010 compose_show_first_last_header(headerentry->compose, FALSE);
7015 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
7017 GtkAdjustment *vadj;
7019 g_return_if_fail(compose);
7020 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
7021 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
7023 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
7024 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
7027 static void text_activated(GtkWidget *widget, Compose *compose)
7029 compose_send_control_enter(compose);
7032 static void text_inserted(GtkWidget *widget, const gchar *text,
7033 gint length, gint *position, Compose *compose)
7035 GtkEditable *editable = GTK_EDITABLE(widget);
7037 gtk_signal_handler_block_by_func(GTK_OBJECT(widget),
7038 GTK_SIGNAL_FUNC(text_inserted),
7040 if (compose->paste_as_quotation) {
7045 new_text = g_strndup(text, length);
7046 if (prefs_common.quotemark && *prefs_common.quotemark)
7047 qmark = prefs_common.quotemark;
7050 gtk_stext_set_point(GTK_STEXT(widget), *position);
7051 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
7052 pos = gtk_stext_get_point(GTK_STEXT(widget));
7053 gtk_editable_set_position(editable, pos);
7057 gtk_editable_insert_text(editable, text, length, position);
7059 if (prefs_common.autowrap)
7060 compose_wrap_line_all_full(compose, TRUE);
7062 gtk_signal_handler_unblock_by_func(GTK_OBJECT(widget),
7063 GTK_SIGNAL_FUNC(text_inserted),
7065 gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
7068 if (prefs_common.autosave &&
7069 gtk_stext_get_length(GTK_STEXT(widget)) % prefs_common.autosave_length == 0)
7070 compose_draft_cb((gpointer)compose, 1, NULL);
7073 static gboolean compose_send_control_enter(Compose *compose)
7077 GtkItemFactory *ifactory;
7078 GtkAccelEntry *accel;
7079 GtkWidget *send_menu;
7081 GdkModifierType ignored_mods =
7082 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
7083 GDK_MOD4_MASK | GDK_MOD5_MASK);
7085 ev = gtk_get_current_event();
7086 if (ev->type != GDK_KEY_PRESS) return FALSE;
7088 kev = (GdkEventKey *)ev;
7089 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
7092 ifactory = gtk_item_factory_from_widget(compose->menubar);
7093 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
7094 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
7095 accel = (GtkAccelEntry *)list->data;
7096 if (accel->accelerator_key == kev->keyval &&
7097 (accel->accelerator_mods & ~ignored_mods) ==
7098 (kev->state & ~ignored_mods)) {
7099 compose_send_cb(compose, 0, NULL);
7107 static void compose_check_all(Compose *compose)
7109 if (compose->gtkaspell)
7110 gtkaspell_check_all(compose->gtkaspell);
7113 static void compose_highlight_all(Compose *compose)
7115 if (compose->gtkaspell)
7116 gtkaspell_highlight_all(compose->gtkaspell);
7119 static void compose_check_backwards(Compose *compose)
7121 if (compose->gtkaspell)
7122 gtkaspell_check_backwards(compose->gtkaspell);
7124 GtkItemFactory *ifactory;
7125 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7126 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7127 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
7131 static void compose_check_forwards_go(Compose *compose)
7133 if (compose->gtkaspell)
7134 gtkaspell_check_forwards_go(compose->gtkaspell);
7136 GtkItemFactory *ifactory;
7137 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7138 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7139 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
7144 static void set_toolbar_style(Compose *compose)
7146 switch (prefs_common.toolbar_style) {
7148 gtk_widget_hide(compose->handlebox);
7151 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar->toolbar),
7155 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar->toolbar),
7159 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar->toolbar),
7164 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
7165 gtk_widget_show(compose->handlebox);
7166 gtk_widget_queue_resize(compose->handlebox);