2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2003 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"
81 #include "send_message.h"
84 #include "customheader.h"
85 #include "prefs_common.h"
86 #include "prefs_account.h"
90 #include "procheader.h"
92 #include "statusbar.h"
95 #include "quoted-printable.h"
100 #include "alertpanel.h"
101 #include "manage_window.h"
102 #include "gtkshruler.h"
104 #include "addr_compl.h"
105 #include "quote_fmt.h"
106 #include "template.h"
108 #include "foldersel.h"
112 # include "rfc2015.h"
122 #define N_ATTACH_COLS 3
126 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
127 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
128 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
129 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
130 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
131 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
132 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
133 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
134 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
135 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
136 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
137 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
138 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
139 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
140 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
141 } ComposeCallGtkSTextAction;
145 PRIORITY_HIGHEST = 1,
152 #define B64_LINE_SIZE 57
153 #define B64_BUFFSIZE 77
155 #define MAX_REFERENCES_LEN 999
157 static GdkColor quote_color = {0, 0, 0, 0xbfff};
159 static GList *compose_list = NULL;
161 Compose *compose_generic_new (PrefsAccount *account,
164 GPtrArray *attach_files);
166 static Compose *compose_create (PrefsAccount *account,
169 static GtkWidget *compose_account_option_menu_create
171 static void compose_set_template_menu (Compose *compose);
172 static void compose_template_apply (Compose *compose,
175 static void compose_destroy (Compose *compose);
177 static void compose_entries_set (Compose *compose,
178 const gchar *mailto);
179 static gint compose_parse_header (Compose *compose,
181 static gchar *compose_parse_references (const gchar *ref,
184 static gchar *compose_quote_fmt (Compose *compose,
190 static void compose_reply_set_entry (Compose *compose,
196 followup_and_reply_to);
197 static void compose_reedit_set_entry (Compose *compose,
199 static void compose_insert_sig (Compose *compose,
201 static gchar *compose_get_signature_str (Compose *compose);
202 static void compose_insert_file (Compose *compose,
204 static void compose_attach_append (Compose *compose,
207 const gchar *content_type);
208 static void compose_attach_parts (Compose *compose,
210 static void compose_wrap_line (Compose *compose);
211 static void compose_wrap_line_all (Compose *compose);
212 static void compose_wrap_line_all_full (Compose *compose,
214 static void compose_set_title (Compose *compose);
215 static void compose_select_account (Compose *compose,
216 PrefsAccount *account,
219 static PrefsAccount *compose_current_mail_account(void);
220 /* static gint compose_send (Compose *compose); */
221 static gboolean compose_check_for_valid_recipient
223 static gboolean compose_check_entries (Compose *compose,
224 gboolean check_subject);
225 static gint compose_write_to_file (Compose *compose,
228 static gint compose_write_body_to_file (Compose *compose,
230 static gint compose_remove_reedit_target (Compose *compose);
231 void compose_remove_draft (Compose *compose);
232 static gint compose_queue (Compose *compose,
235 static gint compose_queue_sub (Compose *compose,
238 gboolean check_subject);
239 static void compose_write_attach (Compose *compose,
241 static gint compose_write_headers (Compose *compose,
243 const gchar *charset,
244 EncodingType encoding,
247 static void compose_convert_header (gchar *dest,
251 gboolean addr_field);
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);
299 static void account_activated (GtkMenuItem *menuitem,
301 static void attach_selected (GtkCList *clist,
306 static void attach_button_pressed (GtkWidget *widget,
307 GdkEventButton *event,
309 static void attach_key_pressed (GtkWidget *widget,
313 static void compose_send_cb (gpointer data,
316 static void compose_send_later_cb (gpointer data,
320 static void compose_draft_cb (gpointer data,
324 static void compose_attach_cb (gpointer data,
327 static void compose_insert_file_cb (gpointer data,
330 static void compose_insert_sig_cb (gpointer data,
334 static void compose_close_cb (gpointer data,
338 static void compose_address_cb (gpointer data,
341 static void compose_template_activate_cb(GtkWidget *widget,
344 static void compose_ext_editor_cb (gpointer data,
348 static gint compose_delete_cb (GtkWidget *widget,
351 static void compose_destroy_cb (GtkWidget *widget,
354 static void compose_undo_cb (Compose *compose);
355 static void compose_redo_cb (Compose *compose);
356 static void compose_cut_cb (Compose *compose);
357 static void compose_copy_cb (Compose *compose);
358 static void compose_paste_cb (Compose *compose);
359 static void compose_paste_as_quote_cb (Compose *compose);
360 static void compose_allsel_cb (Compose *compose);
362 static void compose_gtk_stext_action_cb (Compose *compose,
363 ComposeCallGtkSTextAction action);
365 static void compose_grab_focus_cb (GtkWidget *widget,
368 static void compose_changed_cb (GtkEditable *editable,
370 static void compose_button_press_cb (GtkWidget *widget,
371 GdkEventButton *event,
374 static void compose_key_press_cb (GtkWidget *widget,
380 static void compose_toggle_to_cb (gpointer data,
383 static void compose_toggle_cc_cb (gpointer data,
386 static void compose_toggle_bcc_cb (gpointer data,
389 static void compose_toggle_replyto_cb (gpointer data,
392 static void compose_toggle_followupto_cb(gpointer data,
395 static void compose_toggle_attach_cb (gpointer data,
399 static void compose_toggle_ruler_cb (gpointer data,
403 static void compose_toggle_sign_cb (gpointer data,
406 static void compose_toggle_encrypt_cb (gpointer data,
409 static void compose_set_gnupg_mode_cb (gpointer data,
412 static void compose_update_gnupg_mode_menu_item(Compose * compose);
413 static void activate_gnupg_mode (Compose *compose,
414 PrefsAccount *account);
416 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
418 static void compose_set_priority_cb (gpointer data,
422 static void compose_attach_drag_received_cb (GtkWidget *widget,
423 GdkDragContext *drag_context,
426 GtkSelectionData *data,
430 static void compose_insert_drag_received_cb (GtkWidget *widget,
431 GdkDragContext *drag_context,
434 GtkSelectionData *data,
440 static void to_activated (GtkWidget *widget,
442 static void newsgroups_activated (GtkWidget *widget,
444 static void cc_activated (GtkWidget *widget,
446 static void bcc_activated (GtkWidget *widget,
448 static void replyto_activated (GtkWidget *widget,
450 static void followupto_activated (GtkWidget *widget,
452 static void subject_activated (GtkWidget *widget,
456 static void text_activated (GtkWidget *widget,
458 static void text_inserted (GtkWidget *widget,
463 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
464 gboolean to_all, gboolean to_ml,
466 gboolean followup_and_reply_to,
469 void compose_headerentry_changed_cb (GtkWidget *entry,
470 ComposeHeaderEntry *headerentry);
471 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
473 ComposeHeaderEntry *headerentry);
475 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
478 static void compose_check_all (Compose *compose);
479 static void compose_highlight_all (Compose *compose);
480 static void compose_check_backwards (Compose *compose);
481 static void compose_check_forwards_go (Compose *compose);
484 static gboolean compose_send_control_enter (Compose *compose);
486 static GtkItemFactoryEntry compose_popup_entries[] =
488 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
489 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
490 {N_("/---"), NULL, NULL, 0, "<Separator>"},
491 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
494 static GtkItemFactoryEntry compose_entries[] =
496 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
497 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
498 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
499 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
500 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
501 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
503 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
504 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
505 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
506 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
507 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
508 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
509 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
510 {N_("/_Edit/Paste as _quotation"),
511 NULL, compose_paste_as_quote_cb, 0, NULL},
512 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
513 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
514 {N_("/_Edit/A_dvanced/Move a character backward"),
516 compose_gtk_stext_action_cb,
517 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
519 {N_("/_Edit/A_dvanced/Move a character forward"),
521 compose_gtk_stext_action_cb,
522 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
524 {N_("/_Edit/A_dvanced/Move a word backward"),
526 compose_gtk_stext_action_cb,
527 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
529 {N_("/_Edit/A_dvanced/Move a word forward"),
531 compose_gtk_stext_action_cb,
532 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
534 {N_("/_Edit/A_dvanced/Move to beginning of line"),
535 NULL, /* "<control>A" */
536 compose_gtk_stext_action_cb,
537 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
539 {N_("/_Edit/A_dvanced/Move to end of line"),
541 compose_gtk_stext_action_cb,
542 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
544 {N_("/_Edit/A_dvanced/Move to previous line"),
546 compose_gtk_stext_action_cb,
547 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
549 {N_("/_Edit/A_dvanced/Move to next line"),
551 compose_gtk_stext_action_cb,
552 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
554 {N_("/_Edit/A_dvanced/Delete a character backward"),
556 compose_gtk_stext_action_cb,
557 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
559 {N_("/_Edit/A_dvanced/Delete a character forward"),
561 compose_gtk_stext_action_cb,
562 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
564 {N_("/_Edit/A_dvanced/Delete a word backward"),
565 NULL, /* "<control>W" */
566 compose_gtk_stext_action_cb,
567 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
569 {N_("/_Edit/A_dvanced/Delete a word forward"),
570 NULL, /* "<alt>D", */
571 compose_gtk_stext_action_cb,
572 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
574 {N_("/_Edit/A_dvanced/Delete line"),
576 compose_gtk_stext_action_cb,
577 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
579 {N_("/_Edit/A_dvanced/Delete entire line"),
581 compose_gtk_stext_action_cb,
582 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
584 {N_("/_Edit/A_dvanced/Delete to end of line"),
586 compose_gtk_stext_action_cb,
587 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
589 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
590 {N_("/_Edit/_Wrap current paragraph"),
591 "<control>L", compose_wrap_line, 0, NULL},
592 {N_("/_Edit/Wrap all long _lines"),
593 "<control><alt>L", compose_wrap_line_all, 0, NULL},
594 {N_("/_Edit/Edit with e_xternal editor"),
595 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
597 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
598 {N_("/_Spelling/_Check all or check selection"),
599 NULL, compose_check_all, 0, NULL},
600 {N_("/_Spelling/_Highlight all misspelled words"),
601 NULL, compose_highlight_all, 0, NULL},
602 {N_("/_Spelling/Check _backwards misspelled word"),
603 NULL, compose_check_backwards , 0, NULL},
604 {N_("/_Spelling/_Forward to next misspelled word"),
605 NULL, compose_check_forwards_go, 0, NULL},
606 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
607 {N_("/_Spelling/_Spelling Configuration"),
608 NULL, NULL, 0, "<Branch>"},
610 #if 0 /* NEW COMPOSE GUI */
611 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
612 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
613 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
614 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
615 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
616 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
617 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
618 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
619 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
620 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
621 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
623 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
624 {N_("/_Message/_Send"), "<control>Return",
625 compose_send_cb, 0, NULL},
626 {N_("/_Message/Send _later"), "<shift><control>S",
627 compose_send_later_cb, 0, NULL},
628 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
629 {N_("/_Message/Save to _draft folder"),
630 "<shift><control>D", compose_draft_cb, 0, NULL},
631 {N_("/_Message/Save and _keep editing"),
632 "<control>S", compose_draft_cb, 1, NULL},
633 #if 0 /* NEW COMPOSE GUI */
634 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
635 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
636 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
637 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
638 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
639 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
640 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
641 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
642 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
645 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
646 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
647 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
648 {N_("/_Message/Mode/MIME"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_DETACH, "<RadioItem>"},
649 {N_("/_Message/Mode/Inline"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_INLINE, "/Message/Mode/MIME"},
650 #endif /* USE_GPGME */
651 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
652 {N_("/_Message/_Priority"), NULL, NULL, 0, "<Branch>"},
653 {N_("/_Message/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
654 {N_("/_Message/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
655 {N_("/_Message/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
656 {N_("/_Message/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
657 {N_("/_Message/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
658 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
659 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
660 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
661 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
662 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
663 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
664 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
665 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
666 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
669 static GtkTargetEntry compose_mime_types[] =
671 {"text/uri-list", 0, 0}
674 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
675 GPtrArray *attach_files)
677 return compose_generic_new(account, mailto, NULL, attach_files);
680 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
682 return compose_generic_new(account, NULL, item, NULL);
685 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
686 GPtrArray *attach_files)
690 GtkItemFactory *ifactory;
691 gboolean grab_focus_on_last = TRUE;
693 if (item && item->prefs && item->prefs->enable_default_account)
694 account = account_find_from_id(item->prefs->default_account);
696 if (!account) account = cur_account;
697 g_return_val_if_fail(account != NULL, NULL);
699 compose = compose_create(account, COMPOSE_NEW);
700 ifactory = gtk_item_factory_from_widget(compose->menubar);
702 compose->replyinfo = NULL;
703 compose->fwdinfo = NULL;
705 text = GTK_STEXT(compose->text);
706 gtk_stext_freeze(text);
708 if (account->auto_sig)
709 compose_insert_sig(compose, FALSE);
710 gtk_editable_set_position(GTK_EDITABLE(text), 0);
711 gtk_stext_set_point(text, 0);
713 gtk_stext_thaw(text);
715 if (account->protocol != A_NNTP) {
716 if (mailto && *mailto != '\0') {
717 compose_entries_set(compose, mailto);
719 } else if (item && item->prefs->enable_default_to) {
720 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
721 compose_entry_select(compose, item->prefs->default_to);
722 grab_focus_on_last = FALSE;
724 if (item && item->ret_rcpt) {
725 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
729 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
732 * CLAWS: just don't allow return receipt request, even if the user
733 * may want to send an email. simple but foolproof.
735 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
742 for (i = 0; i < attach_files->len; i++) {
743 file = g_ptr_array_index(attach_files, i);
744 compose_attach_append(compose, file, file, NULL);
748 compose_show_first_last_header(compose, TRUE);
750 /* Set save folder */
751 if (item && item->prefs && item->prefs->save_copy_to_folder) {
752 gchar *folderidentifier;
754 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
755 folderidentifier = folder_item_get_identifier(item);
756 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
757 g_free(folderidentifier);
760 /* Grab focus on last header only if no default_to was set */
761 if (grab_focus_on_last)
762 gtk_widget_grab_focus(compose->header_last->entry);
764 if (prefs_common.auto_exteditor)
765 compose_exec_ext_editor(compose);
771 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
772 const gchar *followupto, gchar * to)
776 if (!account) account = cur_account;
777 g_return_val_if_fail(account != NULL, NULL);
778 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
780 compose = compose_create(account, COMPOSE_NEW);
782 if (prefs_common.auto_sig)
783 compose_insert_sig(compose);
784 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
785 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
787 compose_entry_append(compose, to, COMPOSE_TO);
788 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
789 gtk_widget_grab_focus(compose->subject_entry);
795 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
800 g_return_if_fail(msginfo_list != NULL);
802 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
803 g_return_if_fail(msginfo != NULL);
805 list_len = g_slist_length(msginfo_list);
809 compose_reply(msginfo, prefs_common.reply_with_quote,
810 FALSE, prefs_common.default_reply_list, FALSE, body);
812 case COMPOSE_REPLY_WITH_QUOTE:
813 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
815 case COMPOSE_REPLY_WITHOUT_QUOTE:
816 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
818 case COMPOSE_REPLY_TO_SENDER:
819 compose_reply(msginfo, prefs_common.reply_with_quote,
820 FALSE, FALSE, TRUE, body);
822 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
823 compose_followup_and_reply_to(msginfo,
824 prefs_common.reply_with_quote,
827 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
828 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
830 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
831 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
833 case COMPOSE_REPLY_TO_ALL:
834 compose_reply(msginfo, prefs_common.reply_with_quote,
835 TRUE, FALSE, FALSE, body);
837 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
838 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
840 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
841 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
843 case COMPOSE_REPLY_TO_LIST:
844 compose_reply(msginfo, prefs_common.reply_with_quote,
845 FALSE, TRUE, FALSE, body);
847 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
848 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
850 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
851 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
853 case COMPOSE_FORWARD:
854 if (prefs_common.forward_as_attachment) {
855 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
858 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
862 case COMPOSE_FORWARD_INLINE:
863 /* check if we reply to more than one Message */
865 compose_forward(NULL, msginfo, FALSE, body);
868 /* more messages FALL THROUGH */
869 case COMPOSE_FORWARD_AS_ATTACH:
870 compose_forward_multiple(NULL, msginfo_list);
872 case COMPOSE_REDIRECT:
873 compose_redirect(NULL, msginfo);
876 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
880 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
881 gboolean to_ml, gboolean to_sender,
884 compose_generic_reply(msginfo, quote, to_all, to_ml,
885 to_sender, FALSE, body);
888 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
893 compose_generic_reply(msginfo, quote, to_all, FALSE,
894 to_sender, TRUE, body);
897 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
898 gboolean to_all, gboolean to_ml,
900 gboolean followup_and_reply_to,
904 PrefsAccount *account = NULL;
905 PrefsAccount *reply_account;
908 g_return_if_fail(msginfo != NULL);
909 g_return_if_fail(msginfo->folder != NULL);
911 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
913 g_return_if_fail(account != NULL);
915 if (to_sender && account->protocol == A_NNTP &&
916 !followup_and_reply_to) {
918 account_find_from_address(account->address);
920 reply_account = compose_current_mail_account();
924 reply_account = account;
926 compose = compose_create(account, COMPOSE_REPLY);
928 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
929 if (!compose->replyinfo)
930 compose->replyinfo = procmsg_msginfo_copy(msginfo);
932 if (msginfo->folder && msginfo->folder->ret_rcpt) {
933 GtkItemFactory *ifactory;
935 ifactory = gtk_item_factory_from_widget(compose->menubar);
936 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
939 /* Set save folder */
940 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
941 gchar *folderidentifier;
943 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
944 folderidentifier = folder_item_get_identifier(msginfo->folder);
945 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
946 g_free(folderidentifier);
949 if (compose_parse_header(compose, msginfo) < 0) return;
950 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
951 to_sender, followup_and_reply_to);
952 compose_show_first_last_header(compose, TRUE);
954 text = GTK_STEXT(compose->text);
955 gtk_stext_freeze(text);
961 if (prefs_common.quotemark && *prefs_common.quotemark)
962 qmark = prefs_common.quotemark;
966 quote_str = compose_quote_fmt(compose, compose->replyinfo,
967 prefs_common.quotefmt,
971 if (account->auto_sig)
972 compose_insert_sig(compose, FALSE);
974 if (quote && prefs_common.linewrap_quote)
975 compose_wrap_line_all(compose);
977 gtk_editable_set_position(GTK_EDITABLE(text), 0);
978 gtk_stext_set_point(text, 0);
980 gtk_stext_thaw(text);
981 gtk_widget_grab_focus(compose->text);
983 if (prefs_common.auto_exteditor)
984 compose_exec_ext_editor(compose);
987 #define INSERT_FW_HEADER(var, hdr) \
988 if (msginfo->var && *msginfo->var) { \
989 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
990 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
991 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
994 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
995 gboolean as_attach, const gchar *body)
1000 g_return_val_if_fail(msginfo != NULL, NULL);
1001 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1003 if (msginfo->folder->prefs->enable_default_account)
1004 account = account_find_from_id(msginfo->folder->prefs->default_account);
1006 account = msginfo->folder->folder->account;
1007 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1009 Xstrdup_a(to, msginfo->to, return NULL);
1010 extract_address(to);
1011 account = account_find_from_address(to);
1014 if (!account && prefs_common.forward_account_autosel) {
1016 if (!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1017 extract_address(cc);
1018 account = account_find_from_address(cc);
1022 if (account == NULL) {
1023 account = cur_account;
1025 account = msginfo->folder->folder->account;
1026 if (!account) account = cur_account;
1029 g_return_val_if_fail(account != NULL, NULL);
1031 compose = compose_create(account, COMPOSE_FORWARD);
1033 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1034 if (!compose->fwdinfo)
1035 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1037 if (msginfo->subject && *msginfo->subject) {
1038 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1039 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1043 text = GTK_STEXT(compose->text);
1044 gtk_stext_freeze(text);
1050 msgfile = procmsg_get_message_file_path(msginfo);
1051 if (!is_file_exist(msgfile))
1052 g_warning("%s: file not exist\n", msgfile);
1054 compose_attach_append(compose, msgfile, msgfile,
1061 MsgInfo *full_msginfo;
1063 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1065 full_msginfo = procmsg_msginfo_copy(msginfo);
1067 if (prefs_common.fw_quotemark &&
1068 *prefs_common.fw_quotemark)
1069 qmark = prefs_common.fw_quotemark;
1073 quote_str = compose_quote_fmt(compose, full_msginfo,
1074 prefs_common.fw_quotefmt,
1076 compose_attach_parts(compose, msginfo);
1078 procmsg_msginfo_free(full_msginfo);
1081 if (account->auto_sig)
1082 compose_insert_sig(compose, FALSE);
1084 if (prefs_common.linewrap_quote)
1085 compose_wrap_line_all(compose);
1087 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1088 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1090 gtk_stext_thaw(text);
1091 #if 0 /* NEW COMPOSE GUI */
1092 if (account->protocol != A_NNTP)
1093 gtk_widget_grab_focus(compose->to_entry);
1095 gtk_widget_grab_focus(compose->newsgroups_entry);
1097 gtk_widget_grab_focus(compose->header_last->entry);
1099 if (prefs_common.auto_exteditor)
1100 compose_exec_ext_editor(compose);
1103 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1104 gchar *folderidentifier;
1106 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1107 folderidentifier = folder_item_get_identifier(msginfo->folder);
1108 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1109 g_free(folderidentifier);
1115 #undef INSERT_FW_HEADER
1117 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1124 g_return_val_if_fail(msginfo_list != NULL, NULL);
1126 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1127 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1131 if (account == NULL) {
1132 account = cur_account;
1134 account = msginfo->folder->folder->account;
1135 if (!account) account = cur_account;
1138 g_return_val_if_fail(account != NULL, NULL);
1140 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1141 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1142 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1145 compose = compose_create(account, COMPOSE_FORWARD);
1147 text = GTK_STEXT(compose->text);
1148 gtk_stext_freeze(text);
1150 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1151 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1152 if (!is_file_exist(msgfile))
1153 g_warning("%s: file not exist\n", msgfile);
1155 compose_attach_append(compose, msgfile, msgfile,
1160 if (account->auto_sig)
1161 compose_insert_sig(compose, FALSE);
1163 if (prefs_common.linewrap_quote)
1164 compose_wrap_line_all(compose);
1166 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1167 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1169 gtk_stext_thaw(text);
1170 gtk_widget_grab_focus(compose->header_last->entry);
1172 #if 0 /* NEW COMPOSE GUI */
1173 if (account->protocol != A_NNTP)
1174 gtk_widget_grab_focus(compose->to_entry);
1176 gtk_widget_grab_focus(compose->newsgroups_entry);
1182 void compose_reedit(MsgInfo *msginfo)
1185 PrefsAccount *account = NULL;
1188 gchar buf[BUFFSIZE];
1190 g_return_if_fail(msginfo != NULL);
1191 g_return_if_fail(msginfo->folder != NULL);
1193 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1194 gchar queueheader_buf[BUFFSIZE];
1197 /* Select Account from queue headers */
1198 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1199 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1200 id = atoi(&queueheader_buf[22]);
1201 account = account_find_from_id(id);
1203 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1204 sizeof(queueheader_buf), "NAID:")) {
1205 id = atoi(&queueheader_buf[5]);
1206 account = account_find_from_id(id);
1208 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1209 sizeof(queueheader_buf), "MAID:")) {
1210 id = atoi(&queueheader_buf[5]);
1211 account = account_find_from_id(id);
1213 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1214 sizeof(queueheader_buf), "S:")) {
1215 account = account_find_from_address(queueheader_buf);
1218 account = msginfo->folder->folder->account;
1220 if (!account && prefs_common.reedit_account_autosel) {
1221 gchar from[BUFFSIZE];
1222 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1223 extract_address(from);
1224 account = account_find_from_address(from);
1227 if (!account) account = cur_account;
1228 g_return_if_fail(account != NULL);
1230 compose = compose_create(account, COMPOSE_REEDIT);
1231 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1233 if (msginfo->folder->stype == F_QUEUE
1234 || msginfo->folder->stype == F_DRAFT) {
1235 gchar queueheader_buf[BUFFSIZE];
1237 /* Set message save folder */
1238 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1241 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1242 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1243 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1247 if (compose_parse_header(compose, msginfo) < 0) return;
1248 compose_reedit_set_entry(compose, msginfo);
1250 text = GTK_STEXT(compose->text);
1251 gtk_stext_freeze(text);
1253 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1254 g_warning("Can't get text part\n");
1256 while (fgets(buf, sizeof(buf), fp) != NULL) {
1258 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1262 compose_attach_parts(compose, msginfo);
1264 gtk_stext_thaw(text);
1265 gtk_widget_grab_focus(compose->text);
1267 if (prefs_common.auto_exteditor)
1268 compose_exec_ext_editor(compose);
1271 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1275 GtkItemFactory *ifactory;
1277 g_return_val_if_fail(msginfo != NULL, NULL);
1280 account = cur_account;
1281 g_return_val_if_fail(account != NULL, NULL);
1283 compose = compose_create(account, COMPOSE_REDIRECT);
1284 ifactory = gtk_item_factory_from_widget(compose->menubar);
1286 compose->replyinfo = NULL;
1287 compose->fwdinfo = NULL;
1289 compose_show_first_last_header(compose, TRUE);
1291 gtk_widget_grab_focus(compose->header_last->entry);
1293 filename = procmsg_get_message_file(msginfo);
1294 if (filename == NULL)
1297 compose->redirect_filename = filename;
1299 compose_attach_parts(compose, msginfo);
1301 if (msginfo->subject)
1302 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1304 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1306 gtk_stext_freeze(GTK_STEXT(compose->text));
1307 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1308 gtk_editable_set_editable(GTK_EDITABLE(compose->text), FALSE);
1309 gtk_stext_thaw(GTK_STEXT(compose->text));
1311 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1312 menu_set_sensitive(ifactory, "/Add...", FALSE);
1313 menu_set_sensitive(ifactory, "/Remove", FALSE);
1314 menu_set_sensitive(ifactory, "/Property...", FALSE);
1316 ifactory = gtk_item_factory_from_widget(compose->menubar);
1317 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
1318 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
1319 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
1320 menu_set_sensitive(ifactory, "/Edit", FALSE);
1321 menu_set_sensitive(ifactory, "/Message/Save to draft folder", FALSE);
1322 menu_set_sensitive(ifactory, "/Message/Save and keep editing", FALSE);
1324 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
1325 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
1326 menu_set_sensitive(ifactory, "/Message/Mode/MIME", FALSE);
1327 menu_set_sensitive(ifactory, "/Message/Mode/Inline", FALSE);
1329 menu_set_sensitive(ifactory, "/Message/Priority", FALSE);
1330 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
1331 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1332 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1334 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1335 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1336 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1337 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1338 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1339 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, FALSE);
1344 GList *compose_get_compose_list(void)
1346 return compose_list;
1349 void compose_entry_append(Compose *compose, const gchar *address,
1350 ComposeEntryType type)
1354 if (!address || *address == '\0') return;
1356 #if 0 /* NEW COMPOSE GUI */
1359 entry = GTK_ENTRY(compose->cc_entry);
1362 entry = GTK_ENTRY(compose->bcc_entry);
1364 case COMPOSE_NEWSGROUPS:
1365 entry = GTK_ENTRY(compose->newsgroups_entry);
1369 entry = GTK_ENTRY(compose->to_entry);
1373 text = gtk_entry_get_text(entry);
1375 gtk_entry_append_text(entry, ", ");
1376 gtk_entry_append_text(entry, address);
1384 header = N_("Bcc:");
1386 case COMPOSE_REPLYTO:
1387 header = N_("Reply-To:");
1389 case COMPOSE_NEWSGROUPS:
1390 header = N_("Newsgroups:");
1392 case COMPOSE_FOLLOWUPTO:
1393 header = N_( "Followup-To:");
1400 header = prefs_common.trans_hdr ? gettext(header) : header;
1402 compose_add_header_entry(compose, header, (gchar *)address);
1405 void compose_entry_select (Compose *compose, const gchar *mailto)
1407 GSList *header_list;
1409 for (header_list = compose->header_list; header_list != NULL; header_list = header_list->next) {
1410 GtkEntry * entry = GTK_ENTRY(((ComposeHeaderEntry *)header_list->data)->entry);
1412 if (gtk_entry_get_text(entry) && !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1413 gtk_entry_select_region(entry, 0, -1);
1414 gtk_widget_grab_focus(GTK_WIDGET(entry));
1419 void compose_toolbar_cb(gint action, gpointer data)
1421 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1422 Compose *compose = (Compose*)toolbar_item->parent;
1424 g_return_if_fail(compose != NULL);
1428 compose_send_cb(compose, 0, NULL);
1431 compose_send_later_cb(compose, 0, NULL);
1434 compose_draft_cb(compose, 0, NULL);
1437 compose_insert_file_cb(compose, 0, NULL);
1440 compose_attach_cb(compose, 0, NULL);
1443 compose_insert_sig(compose, FALSE);
1446 compose_ext_editor_cb(compose, 0, NULL);
1449 compose_wrap_line(compose);
1452 compose_address_cb(compose, 0, NULL);
1459 static void compose_entries_set(Compose *compose, const gchar *mailto)
1464 gchar *subject = NULL;
1467 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1470 compose_entry_append(compose, to, COMPOSE_TO);
1472 compose_entry_append(compose, cc, COMPOSE_CC);
1474 compose_entry_append(compose, bcc, COMPOSE_BCC);
1476 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1478 gtk_stext_insert(GTK_STEXT(compose->text),
1479 NULL, NULL, NULL, body, -1);
1480 gtk_stext_insert(GTK_STEXT(compose->text),
1481 NULL, NULL, NULL, "\n", 1);
1491 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1493 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1494 {"Cc:", NULL, TRUE},
1495 {"References:", NULL, FALSE},
1496 {"Bcc:", NULL, TRUE},
1497 {"Newsgroups:", NULL, TRUE},
1498 {"Followup-To:", NULL, TRUE},
1499 {"List-Post:", NULL, FALSE},
1500 {"X-Priority:", NULL, FALSE},
1501 {NULL, NULL, FALSE}};
1517 g_return_val_if_fail(msginfo != NULL, -1);
1519 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1520 procheader_get_header_fields(fp, hentry);
1523 if (hentry[H_REPLY_TO].body != NULL) {
1524 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1525 compose->replyto = hentry[H_REPLY_TO].body;
1526 hentry[H_REPLY_TO].body = NULL;
1528 if (hentry[H_CC].body != NULL) {
1529 conv_unmime_header_overwrite(hentry[H_CC].body);
1530 compose->cc = hentry[H_CC].body;
1531 hentry[H_CC].body = NULL;
1533 if (hentry[H_REFERENCES].body != NULL) {
1534 if (compose->mode == COMPOSE_REEDIT)
1535 compose->references = hentry[H_REFERENCES].body;
1537 compose->references = compose_parse_references
1538 (hentry[H_REFERENCES].body, msginfo->msgid);
1539 g_free(hentry[H_REFERENCES].body);
1541 hentry[H_REFERENCES].body = NULL;
1543 if (hentry[H_BCC].body != NULL) {
1544 if (compose->mode == COMPOSE_REEDIT) {
1545 conv_unmime_header_overwrite(hentry[H_BCC].body);
1546 compose->bcc = hentry[H_BCC].body;
1548 g_free(hentry[H_BCC].body);
1549 hentry[H_BCC].body = NULL;
1551 if (hentry[H_NEWSGROUPS].body != NULL) {
1552 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1553 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1554 hentry[H_NEWSGROUPS].body = NULL;
1556 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1557 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1558 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1559 hentry[H_FOLLOWUP_TO].body = NULL;
1561 if (hentry[H_LIST_POST].body != NULL) {
1564 extract_address(hentry[H_LIST_POST].body);
1565 if (hentry[H_LIST_POST].body[0] != '\0') {
1566 scan_mailto_url(hentry[H_LIST_POST].body,
1567 &to, NULL, NULL, NULL, NULL);
1569 g_free(compose->ml_post);
1570 compose->ml_post = to;
1573 g_free(hentry[H_LIST_POST].body);
1574 hentry[H_LIST_POST].body = NULL;
1577 /* CLAWS - X-Priority */
1578 if (compose->mode == COMPOSE_REEDIT)
1579 if (hentry[H_X_PRIORITY].body != NULL) {
1582 priority = atoi(hentry[H_X_PRIORITY].body);
1583 g_free(hentry[H_X_PRIORITY].body);
1585 hentry[H_X_PRIORITY].body = NULL;
1587 if (priority < PRIORITY_HIGHEST ||
1588 priority > PRIORITY_LOWEST)
1589 priority = PRIORITY_NORMAL;
1591 compose->priority = priority;
1594 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1595 compose->inreplyto = g_strdup(msginfo->inreplyto);
1596 else if (compose->mode != COMPOSE_REEDIT &&
1597 msginfo->msgid && *msginfo->msgid) {
1598 compose->inreplyto = g_strdup(msginfo->msgid);
1600 if (!compose->references) {
1601 if (msginfo->inreplyto && *msginfo->inreplyto)
1602 compose->references =
1603 g_strdup_printf("<%s>\n\t<%s>",
1607 compose->references =
1608 g_strconcat("<", msginfo->msgid, ">",
1616 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1618 GSList *ref_id_list, *cur;
1622 ref_id_list = references_list_append(NULL, ref);
1623 if (!ref_id_list) return NULL;
1624 if (msgid && *msgid)
1625 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1630 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1631 /* "<" + Message-ID + ">" + CR+LF+TAB */
1632 len += strlen((gchar *)cur->data) + 5;
1634 if (len > MAX_REFERENCES_LEN) {
1635 /* remove second message-ID */
1636 if (ref_id_list && ref_id_list->next &&
1637 ref_id_list->next->next) {
1638 g_free(ref_id_list->next->data);
1639 ref_id_list = g_slist_remove
1640 (ref_id_list, ref_id_list->next->data);
1642 slist_free_strings(ref_id_list);
1643 g_slist_free(ref_id_list);
1650 new_ref = g_string_new("");
1651 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1652 if (new_ref->len > 0)
1653 g_string_append(new_ref, "\n\t");
1654 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1657 slist_free_strings(ref_id_list);
1658 g_slist_free(ref_id_list);
1660 new_ref_str = new_ref->str;
1661 g_string_free(new_ref, FALSE);
1666 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1667 const gchar *fmt, const gchar *qmark,
1670 GtkSText *text = GTK_STEXT(compose->text);
1671 static MsgInfo dummyinfo;
1672 gchar *quote_str = NULL;
1676 gchar *trimmed_body = body;
1679 msginfo = &dummyinfo;
1681 if (qmark != NULL) {
1682 quote_fmt_init(msginfo, NULL, NULL);
1683 quote_fmt_scan_string(qmark);
1686 buf = quote_fmt_get_buffer();
1688 alertpanel_error(_("Quote mark format error."));
1690 Xstrdup_a(quote_str, buf, return NULL)
1693 if (fmt && *fmt != '\0') {
1694 while (trimmed_body && strlen(trimmed_body) > 1
1695 && trimmed_body[0]=='\n')
1698 quote_fmt_init(msginfo, quote_str, trimmed_body);
1699 quote_fmt_scan_string(fmt);
1702 buf = quote_fmt_get_buffer();
1704 alertpanel_error(_("Message reply/forward format error."));
1710 gtk_stext_freeze(text);
1712 for (p = buf; *p != '\0'; ) {
1713 lastp = strchr(p, '\n');
1714 len = lastp ? lastp - p + 1 : -1;
1715 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1722 gtk_stext_thaw(text);
1727 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1728 gboolean to_all, gboolean to_ml,
1730 gboolean followup_and_reply_to)
1732 GSList *cc_list = NULL;
1735 gchar *replyto = NULL;
1736 GHashTable *to_table;
1738 g_return_if_fail(compose->account != NULL);
1739 g_return_if_fail(msginfo != NULL);
1741 if (compose->account->protocol != A_NNTP) {
1742 if (!compose->replyto && to_ml && compose->ml_post
1743 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1744 compose_entry_append(compose,
1747 else if (!(to_all || to_sender)
1749 && msginfo->folder->prefs->enable_default_reply_to) {
1750 compose_entry_append(compose,
1751 msginfo->folder->prefs->default_reply_to,
1754 compose_entry_append(compose,
1755 (compose->replyto && !to_sender)
1756 ? compose->replyto :
1757 msginfo->from ? msginfo->from : "",
1760 if (to_sender || (compose->followup_to &&
1761 !strncmp(compose->followup_to, "poster", 6)))
1762 compose_entry_append
1764 (compose->replyto ? compose->replyto :
1765 msginfo->from ? msginfo->from : ""),
1768 else if (followup_and_reply_to || to_all) {
1769 compose_entry_append
1771 (compose->replyto ? compose->replyto :
1772 msginfo->from ? msginfo->from : ""),
1775 compose_entry_append
1777 compose->followup_to ? compose->followup_to :
1778 compose->newsgroups ? compose->newsgroups : "",
1779 COMPOSE_NEWSGROUPS);
1782 compose_entry_append
1784 compose->followup_to ? compose->followup_to :
1785 compose->newsgroups ? compose->newsgroups : "",
1786 COMPOSE_NEWSGROUPS);
1789 if (msginfo->subject && *msginfo->subject) {
1790 gchar *buf, *buf2, *p;
1792 buf = g_strdup(msginfo->subject);
1793 while (!strncasecmp(buf, "Re:", 3)) {
1795 while (isspace(*p)) p++;
1796 memmove(buf, p, strlen(p) + 1);
1799 buf2 = g_strdup_printf("Re: %s", buf);
1800 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1804 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1806 if (to_ml && compose->ml_post) return;
1807 if (!to_all || compose->account->protocol == A_NNTP) return;
1809 if (compose->replyto) {
1810 Xstrdup_a(replyto, compose->replyto, return);
1811 extract_address(replyto);
1813 if (msginfo->from) {
1814 Xstrdup_a(from, msginfo->from, return);
1815 extract_address(from);
1818 if (replyto && from)
1819 cc_list = address_list_append_with_comments(cc_list, from);
1820 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1821 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1823 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1825 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1826 if (compose->account)
1827 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1828 GINT_TO_POINTER(1));
1830 /* remove address on To: and that of current account */
1831 for (cur = cc_list; cur != NULL; ) {
1832 GSList *next = cur->next;
1835 addr = g_strdup(cur->data);
1836 extract_address(addr);
1838 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
1839 cc_list = g_slist_remove(cc_list, cur->data);
1841 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
1845 hash_free_strings(to_table);
1846 g_hash_table_destroy(to_table);
1849 for (cur = cc_list; cur != NULL; cur = cur->next)
1850 compose_entry_append(compose, (gchar *)cur->data,
1852 slist_free_strings(cc_list);
1853 g_slist_free(cc_list);
1857 #define SET_ENTRY(entry, str) \
1860 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1863 #define SET_ADDRESS(type, str) \
1866 compose_entry_append(compose, str, type); \
1869 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1871 g_return_if_fail(msginfo != NULL);
1873 SET_ENTRY(subject_entry, msginfo->subject);
1874 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1875 SET_ADDRESS(COMPOSE_CC, compose->cc);
1876 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1877 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1878 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
1879 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
1881 compose_update_priority_menu_item(compose);
1883 compose_update_gnupg_mode_menu_item(compose);
1885 compose_show_first_last_header(compose, TRUE);
1892 static void compose_insert_sig(Compose *compose, gboolean replace)
1894 GtkSText *text = GTK_STEXT(compose->text);
1897 g_return_if_fail(compose->account != NULL);
1899 cur_pos = gtk_editable_get_position(GTK_EDITABLE(text));
1901 gtk_stext_freeze(text);
1903 if (replace && compose->sig_str) {
1908 if (compose->account->sig_sep)
1909 tmp = g_strconcat(compose->account->sig_sep, "\n",
1910 compose->sig_str, NULL);
1912 tmp = g_strdup(compose->sig_str);
1914 pos = gtkut_stext_find(text, 0, tmp, TRUE);
1916 len = get_mbs_len(tmp);
1918 gtk_stext_set_point(text, pos);
1919 gtk_stext_forward_delete(text, len);
1921 len = gtk_stext_get_length(text);
1922 gtk_stext_set_point(text, len);
1925 len = gtk_stext_get_length(text);
1926 gtk_stext_set_point(text, len);
1931 gtk_stext_insert(text, NULL, NULL, NULL, "\n\n", 2);
1933 if (compose->account->sig_sep) {
1934 gtk_stext_insert(text, NULL, NULL, NULL,
1935 compose->account->sig_sep, -1);
1936 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1939 g_free(compose->sig_str);
1940 compose->sig_str = compose_get_signature_str(compose);
1942 gtk_stext_insert(text, NULL, NULL, NULL, compose->sig_str, -1);
1944 gtk_stext_thaw(text);
1946 if (cur_pos > gtk_stext_get_length(text))
1947 cur_pos = gtk_stext_get_length(text);
1949 gtk_editable_set_position(GTK_EDITABLE(text), cur_pos);
1950 gtk_stext_set_point(text, cur_pos);
1953 static gchar *compose_get_signature_str(Compose *compose)
1955 static gchar *default_sigfile;
1956 gchar *sig_file = NULL;
1957 gchar *sig_str = NULL;
1959 g_return_val_if_fail(compose->account != NULL, NULL);
1961 if (compose->account->sig_type == SIG_FILE) {
1962 if (compose->account->sig_path)
1963 sig_file = compose->account->sig_path;
1965 if (!default_sigfile)
1966 default_sigfile = g_strconcat
1967 (get_home_dir(), G_DIR_SEPARATOR_S,
1968 DEFAULT_SIGNATURE, NULL);
1969 sig_file = default_sigfile;
1972 if (!is_file_or_fifo_exist(sig_file)) {
1973 g_warning("can't open signature file: %s\n", sig_file);
1978 if (compose->account->sig_type == SIG_COMMAND) {
1979 if (compose->account->sig_path)
1980 sig_str = get_command_output
1981 (compose->account->sig_path);
1985 tmp = file_read_to_str(sig_file);
1986 sig_str = normalize_newlines(tmp);
1993 static void compose_insert_file(Compose *compose, const gchar *file)
1995 GtkSText *text = GTK_STEXT(compose->text);
1996 gchar buf[BUFFSIZE];
2000 g_return_if_fail(file != NULL);
2002 if ((fp = fopen(file, "rb")) == NULL) {
2003 FILE_OP_ERROR(file, "fopen");
2007 gtk_stext_freeze(text);
2009 while (fgets(buf, sizeof(buf), fp) != NULL) {
2010 /* strip <CR> if DOS/Windows file,
2011 replace <CR> with <LF> if Macintosh file. */
2014 if (len > 0 && buf[len - 1] != '\n') {
2016 if (buf[len] == '\r') buf[len] = '\n';
2018 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
2021 gtk_stext_thaw(text);
2026 static void compose_attach_append(Compose *compose, const gchar *file,
2027 const gchar *filename,
2028 const gchar *content_type)
2031 gchar *text[N_ATTACH_COLS];
2036 if (!is_file_exist(file)) {
2037 g_warning("File %s doesn't exist\n", file);
2040 if ((size = get_file_size(file)) < 0) {
2041 g_warning("Can't get file size of %s\n", file);
2045 alertpanel_notice(_("File %s is empty."), file);
2048 if ((fp = fopen(file, "rb")) == NULL) {
2049 alertpanel_error(_("Can't read %s."), file);
2054 #if 0 /* NEW COMPOSE GUI */
2055 if (!compose->use_attach) {
2056 GtkItemFactory *ifactory;
2057 GtkWidget *menuitem;
2059 ifactory = gtk_item_factory_from_widget(compose->menubar);
2060 menuitem = gtk_item_factory_get_item(ifactory,
2061 "/View/Attachment");
2062 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2066 ainfo = g_new0(AttachInfo, 1);
2067 ainfo->file = g_strdup(file);
2070 ainfo->content_type = g_strdup(content_type);
2071 if (!strcasecmp(content_type, "message/rfc822")) {
2072 if (procmime_get_encoding_for_file(file) == ENC_7BIT)
2073 ainfo->encoding = ENC_7BIT;
2075 ainfo->encoding = ENC_8BIT;
2076 ainfo->name = g_strdup_printf
2078 g_basename(filename ? filename : file));
2080 if (!g_strncasecmp(content_type, "text", 4))
2082 procmime_get_encoding_for_file(file);
2084 ainfo->encoding = ENC_BASE64;
2085 ainfo->name = g_strdup
2086 (g_basename(filename ? filename : file));
2089 ainfo->content_type = procmime_get_mime_type(file);
2090 if (!ainfo->content_type) {
2091 ainfo->content_type =
2092 g_strdup("application/octet-stream");
2093 ainfo->encoding = ENC_BASE64;
2094 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
2095 ainfo->encoding = procmime_get_encoding_for_file(file);
2097 ainfo->encoding = ENC_BASE64;
2098 ainfo->name = g_strdup(g_basename(filename ? filename : file));
2102 text[COL_MIMETYPE] = ainfo->content_type;
2103 text[COL_SIZE] = to_human_readable(size);
2104 text[COL_NAME] = ainfo->name;
2106 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2107 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2110 #define IS_FIRST_PART_TEXT(info) \
2111 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
2112 info->mime_type == MIME_TEXT_ENRICHED) || \
2113 (info->mime_type == MIME_MULTIPART && info->content_type && \
2114 !strcasecmp(info->content_type, "multipart/alternative") && \
2115 (info->children && \
2116 (info->children->mime_type == MIME_TEXT || \
2117 info->children->mime_type == MIME_TEXT_HTML || \
2118 info->children->mime_type == MIME_TEXT_ENRICHED))))
2120 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2127 mimeinfo = procmime_scan_message(msginfo);
2128 if (!mimeinfo) return;
2130 /* skip first text (presumably message body) */
2131 child = mimeinfo->children;
2132 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
2133 procmime_mimeinfo_free_all(mimeinfo);
2137 if (IS_FIRST_PART_TEXT(child))
2138 child = child->next;
2140 infile = procmsg_get_message_file_path(msginfo);
2142 while (child != NULL) {
2143 if (child->children || child->mime_type == MIME_MULTIPART) {
2144 child = procmime_mimeinfo_next(child);
2147 if(child->parent && child->parent->parent
2148 && !strcasecmp(child->parent->parent->content_type, "multipart/signed")
2149 && child->mime_type == MIME_TEXT) {
2150 /* this is the main text part of a signed message */
2151 child = procmime_mimeinfo_next(child);
2154 outfile = procmime_get_tmp_file_name(child);
2155 if (procmime_get_part(outfile, infile, child) < 0)
2156 g_warning("Can't get the part of multipart message.");
2157 else if (compose->mode != COMPOSE_REEDIT || strcmp(child->content_type, "application/pgp-signature"))
2158 compose_attach_append
2160 child->filename ? child->filename : child->name,
2161 child->content_type);
2163 child = child->next;
2167 procmime_mimeinfo_free_all(mimeinfo);
2170 #undef IS_FIRST_PART_TEXT
2172 #define GET_CHAR(pos, buf, len) \
2174 if (text->use_wchar) \
2175 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2177 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2182 #define DISP_WIDTH(len) \
2183 ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
2184 (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
2186 #define INDENT_CHARS ">|#"
2187 #define SPACE_CHARS " \t"
2189 static void compose_wrap_line(Compose *compose)
2191 GtkSText *text = GTK_STEXT(compose->text);
2192 gint ch_len, last_ch_len;
2193 gchar cbuf[MB_LEN_MAX], last_ch;
2197 gint p_start, p_end;
2198 gint line_pos, cur_pos;
2199 gint line_len, cur_len;
2201 gtk_stext_freeze(text);
2203 text_len = gtk_stext_get_length(text);
2205 /* check to see if the point is on the paragraph mark (empty line). */
2206 cur_pos = gtk_stext_get_point(text);
2207 GET_CHAR(cur_pos, cbuf, ch_len);
2208 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2210 goto compose_end; /* on the paragraph mark */
2211 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2212 if (ch_len == 1 && *cbuf == '\n')
2213 goto compose_end; /* on the paragraph mark */
2216 /* find paragraph start. */
2217 line_end = quoted = 0;
2218 for (p_start = cur_pos; p_start >= 0; --p_start) {
2219 GET_CHAR(p_start, cbuf, ch_len);
2220 if (ch_len == 1 && *cbuf == '\n') {
2222 goto compose_end; /* quoted part */
2230 && strchr(prefs_common.quote_chars, *cbuf))
2232 else if (ch_len != 1 || !isspace(*cbuf))
2241 /* find paragraph end. */
2243 for (p_end = cur_pos; p_end < text_len; p_end++) {
2244 GET_CHAR(p_end, cbuf, ch_len);
2245 if (ch_len == 1 && *cbuf == '\n') {
2252 if (line_end && ch_len == 1 &&
2253 strchr(prefs_common.quote_chars, *cbuf))
2254 goto compose_end; /* quoted part */
2259 if (p_end >= text_len)
2262 if (p_start >= p_end)
2265 line_len = cur_len = 0;
2269 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2272 GET_CHAR(cur_pos, cbuf, ch_len);
2279 if (ch_len == 1 && isspace(*cbuf))
2282 if (ch_len == 1 && *cbuf == '\n') {
2284 if (last_ch_len == 1 && !isspace(last_ch)) {
2285 if (cur_pos + 1 < p_end) {
2286 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2287 if (ch_len == 1 && !isspace(*cbuf))
2291 gtk_stext_set_point(text, cur_pos + 1);
2292 gtk_stext_backward_delete(text, 1);
2294 gtk_stext_set_point(text, cur_pos);
2295 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2305 last_ch_len = ch_len;
2309 line_pos = cur_pos + 1;
2310 line_len = cur_len + ch_len;
2313 if (cur_len + DISP_WIDTH(ch_len) > prefs_common.linewrap_len &&
2317 GET_CHAR(line_pos - 1, cbuf, ch_len);
2318 if (ch_len == 1 && isspace(*cbuf)) {
2319 gtk_stext_set_point(text, line_pos);
2320 gtk_stext_backward_delete(text, 1);
2329 gtk_stext_set_point(text, line_pos);
2330 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2334 cur_len = cur_len - line_len + DISP_WIDTH(ch_len);
2340 line_pos = cur_pos + 1;
2341 line_len = cur_len + DISP_WIDTH(ch_len);
2343 cur_len += DISP_WIDTH(ch_len);
2347 gtk_stext_thaw(text);
2352 /* Darko: used when I debug wrapping */
2353 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2356 gchar cbuf[MB_LEN_MAX];
2358 printf("%d [", pos);
2359 for (i = pos; i < tlen; i++) {
2360 GET_CHAR(i, cbuf, clen);
2361 if (clen < 0) break;
2362 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2364 fwrite(cbuf, clen, 1, stdout);
2372 WAIT_FOR_INDENT_CHAR,
2373 WAIT_FOR_INDENT_CHAR_OR_SPACE
2376 /* return indent length, we allow:
2377 > followed by spaces/tabs
2378 | followed by spaces/tabs
2379 uppercase characters immediately followed by >,
2380 and the repeating sequences of the above */
2381 /* return indent length */
2382 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2385 guint i, ch_len, alnum_cnt = 0;
2386 IndentState state = WAIT_FOR_INDENT_CHAR;
2387 gchar cbuf[MB_LEN_MAX];
2391 for (i = start_pos; i < text_len; i++) {
2392 GET_CHAR(i, cbuf, ch_len);
2396 if (cbuf[0] == '\n')
2399 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2400 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2403 case WAIT_FOR_SPACE:
2404 if (is_space == FALSE)
2406 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2408 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2409 if (is_indent == FALSE && is_space == FALSE &&
2412 if (is_space == TRUE) {
2414 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2415 } else if (is_indent == TRUE) {
2417 state = WAIT_FOR_SPACE;
2420 state = WAIT_FOR_INDENT_CHAR;
2423 case WAIT_FOR_INDENT_CHAR:
2424 if (is_indent == FALSE && !isupper(cbuf[0]))
2426 if (is_indent == TRUE) {
2428 && !strchr(prefs_common.quote_chars, cbuf[0]))
2431 state = WAIT_FOR_SPACE;
2442 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2448 /* insert quotation string when line was wrapped */
2449 static guint ins_quote(GtkSText *text, guint indent_len,
2450 guint prev_line_pos, guint text_len,
2453 guint i, ins_len = 0;
2457 for (i = 0; i < indent_len; i++) {
2458 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2459 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2461 ins_len = indent_len;
2467 /* check if we should join the next line */
2468 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2469 guint prev_ilen, gboolean autowrap)
2471 guint indent_len, ch_len;
2472 gboolean do_join = FALSE;
2473 gchar cbuf[MB_LEN_MAX];
2475 indent_len = get_indent_length(text, start_pos, tlen);
2477 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2478 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2479 if (ch_len > 0 && (cbuf[0] != '\n'))
2486 static void compose_wrap_line_all(Compose *compose)
2488 compose_wrap_line_all_full(compose, FALSE);
2491 #define STEXT_FREEZE() \
2492 if (!frozen) { gtk_stext_freeze(text); frozen = TRUE; }
2494 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2496 GtkSText *text = GTK_STEXT(compose->text);
2498 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2499 gint line_len = 0, cur_len = 0;
2501 gboolean is_new_line = TRUE, do_delete = FALSE;
2503 gboolean linewrap_quote = TRUE;
2504 gboolean set_editable_pos = FALSE;
2505 gint editable_pos = 0;
2506 gboolean frozen = FALSE;
2507 guint linewrap_len = prefs_common.linewrap_len;
2508 gchar *qfmt = prefs_common.quotemark;
2509 gchar cbuf[MB_LEN_MAX];
2511 tlen = gtk_stext_get_length(text);
2513 for (; cur_pos < tlen; cur_pos++) {
2514 /* mark position of new line - needed for quotation wrap */
2517 i_len = get_indent_length(text, cur_pos, tlen);
2519 is_new_line = FALSE;
2522 g_print("new line i_len=%d p_pos=", i_len);
2523 dump_text(text, p_pos, tlen, 1);
2527 GET_CHAR(cur_pos, cbuf, ch_len);
2529 /* fix line length for tabs */
2530 if (ch_len == 1 && *cbuf == '\t') {
2531 guint tab_width = text->default_tab_width;
2532 guint tab_offset = line_len % tab_width;
2535 g_print("found tab at pos=%d line_len=%d ", cur_pos,
2539 line_len += tab_width - tab_offset - 1;
2543 printf("new_len=%d\n", line_len);
2547 /* we have encountered line break */
2548 if (ch_len == 1 && *cbuf == '\n') {
2550 gchar cb[MB_LEN_MAX];
2552 /* should we join the next line */
2553 if ((autowrap || i_len != cur_len) && do_delete &&
2555 (text, cur_pos + 1, tlen, i_len, autowrap))
2561 g_print("found CR at %d do_del is %d next line is ",
2562 cur_pos, do_delete);
2563 dump_text(text, cur_pos + 1, tlen, 1);
2566 /* skip delete if it is continuous URL */
2567 if (do_delete && (line_pos - p_pos <= i_len) &&
2568 gtk_stext_is_uri_string(text, line_pos, tlen))
2572 g_print("l_len=%d wrap_len=%d do_del=%d\n",
2573 line_len, linewrap_len, do_delete);
2575 /* should we delete to perform smart wrapping */
2576 if (line_len < linewrap_len && do_delete) {
2578 /* get rid of newline */
2579 gtk_stext_set_point(text, cur_pos);
2580 gtk_stext_forward_delete(text, 1);
2583 /* if text starts with quote fmt or with
2584 indent string, delete them */
2587 ilen = gtk_stext_str_compare_n
2588 (text, cur_pos, p_pos, i_len,
2591 gtk_stext_forward_delete
2597 GET_CHAR(cur_pos, cb, clen);
2599 /* insert space if it's alphanumeric */
2600 if ((cur_pos != line_pos) &&
2601 ((clen > 1) || isalnum(cb[0]))) {
2602 gtk_stext_insert(text, NULL, NULL,
2607 /* and start over with current line */
2608 cur_pos = p_pos - 1;
2610 line_len = cur_len = 0;
2614 g_print("after delete l_pos=");
2615 dump_text(text, line_pos, tlen, 1);
2617 /* move beginning of line if we are on LF */
2618 GET_CHAR(line_pos, cb, clen);
2619 if (clen == 1 && *cb == '\n')
2622 g_print("new line_pos=%d\n", line_pos);
2628 /* mark new line beginning */
2629 line_pos = cur_pos + 1;
2630 line_len = cur_len = 0;
2641 /* possible line break */
2642 if (ch_len == 1 && isspace(*cbuf)) {
2643 line_pos = cur_pos + 1;
2644 line_len = cur_len + ch_len;
2647 /* are we over wrapping length set in preferences ? */
2648 if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
2652 g_print("should wrap cur_pos=%d ", cur_pos);
2653 dump_text(text, p_pos, tlen, 1);
2654 dump_text(text, line_pos, tlen, 1);
2656 /* force wrapping if it is one long word but not URL */
2657 if (line_pos - p_pos <= i_len)
2658 if (!gtk_stext_is_uri_string
2659 (text, line_pos, tlen))
2660 line_pos = cur_pos - 1;
2662 g_print("new line_pos=%d\n", line_pos);
2665 GET_CHAR(line_pos - 1, cbuf, clen);
2667 /* if next character is space delete it */
2668 if (clen == 1 && isspace(*cbuf)) {
2669 if (p_pos + i_len != line_pos ||
2670 !gtk_stext_is_uri_string
2671 (text, line_pos, tlen)) {
2673 /* workaround for correct cursor
2675 if (set_editable_pos == FALSE) {
2676 editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2677 if (editable_pos == line_pos)
2678 set_editable_pos = TRUE;
2680 gtk_stext_set_point(text, line_pos);
2681 gtk_stext_backward_delete(text, 1);
2690 /* if it is URL at beginning of line don't wrap */
2691 if (p_pos + i_len == line_pos &&
2692 gtk_stext_is_uri_string(text, line_pos, tlen)) {
2694 g_print("found URL at ");
2695 dump_text(text, line_pos, tlen, 1);
2702 gtk_stext_set_point(text, line_pos);
2703 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2704 /* gtk_stext_compact_buffer(text); */
2707 /* for loop will increase it */
2708 cur_pos = line_pos - 1;
2709 /* start over with current line */
2711 line_len = cur_len = 0;
2712 if (autowrap || i_len > 0)
2717 g_print("after CR insert ");
2718 dump_text(text, line_pos, tlen, 1);
2719 dump_text(text, cur_pos, tlen, 1);
2722 /* should we insert quotation ? */
2723 if (linewrap_quote && i_len) {
2724 /* only if line is not already quoted */
2725 if (!gtk_stext_str_compare
2726 (text, line_pos, tlen, qfmt)) {
2729 if (line_pos - p_pos > i_len) {
2731 (text, i_len, p_pos,
2736 g_print("after quote insert ");
2737 dump_text(text, line_pos, tlen, 1);
2745 line_pos = cur_pos + 1;
2746 line_len = cur_len + DISP_WIDTH(ch_len);
2748 /* advance to next character in buffer */
2749 cur_len += DISP_WIDTH(ch_len);
2753 gtk_stext_thaw(text);
2755 if (set_editable_pos && editable_pos <= tlen)
2756 gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
2762 static void compose_set_title(Compose *compose)
2767 edited = compose->modified ? _(" [Edited]") : "";
2768 if (compose->account && compose->account->address)
2769 str = g_strdup_printf(_("%s - Compose message%s"),
2770 compose->account->address, edited);
2772 str = g_strdup_printf(_("Compose message%s"), edited);
2773 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2778 * compose_current_mail_account:
2780 * Find a current mail account (the currently selected account, or the
2781 * default account, if a news account is currently selected). If a
2782 * mail account cannot be found, display an error message.
2784 * Return value: Mail account, or NULL if not found.
2786 static PrefsAccount *
2787 compose_current_mail_account(void)
2791 if (cur_account && cur_account->protocol != A_NNTP)
2794 ac = account_get_default();
2795 if (!ac || ac->protocol == A_NNTP) {
2796 alertpanel_error(_("Account for sending mail is not specified.\n"
2797 "Please select a mail account before sending."));
2804 static void compose_select_account(Compose *compose, PrefsAccount *account,
2807 GtkWidget *menuitem;
2808 GtkItemFactory *ifactory;
2810 g_return_if_fail(account != NULL);
2812 compose->account = account;
2814 compose_set_title(compose);
2816 ifactory = gtk_item_factory_from_widget(compose->menubar);
2818 if (account->protocol == A_NNTP) {
2819 gtk_widget_show(compose->newsgroups_hbox);
2820 gtk_widget_show(compose->newsgroups_entry);
2821 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2822 compose->use_newsgroups = TRUE;
2824 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2825 gtk_check_menu_item_set_active
2826 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2827 gtk_widget_set_sensitive(menuitem, TRUE);
2828 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2829 gtk_check_menu_item_set_active
2830 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2831 gtk_widget_set_sensitive(menuitem, TRUE);
2833 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
2835 gtk_widget_hide(compose->newsgroups_hbox);
2836 gtk_widget_hide(compose->newsgroups_entry);
2837 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
2838 gtk_widget_queue_resize(compose->table_vbox);
2839 compose->use_newsgroups = FALSE;
2841 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2842 gtk_check_menu_item_set_active
2843 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2844 gtk_widget_set_sensitive(menuitem, FALSE);
2845 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2846 gtk_check_menu_item_set_active
2847 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2848 gtk_widget_set_sensitive(menuitem, FALSE);
2850 menuitem = gtk_item_factory_get_item(ifactory, "/View/Followup to");
2851 gtk_check_menu_item_set_active
2852 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2853 gtk_widget_set_sensitive(menuitem, FALSE);
2856 if (account->set_autocc) {
2857 compose_entry_show(compose, COMPOSE_ENTRY_CC);
2858 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
2859 compose_entry_set(compose, account->auto_cc,
2862 if (account->set_autobcc) {
2863 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
2864 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
2865 compose_entry_set(compose, account->auto_bcc,
2868 if (account->set_autoreplyto) {
2869 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
2870 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
2871 compose_entry_set(compose, account->auto_replyto,
2872 COMPOSE_ENTRY_REPLY_TO);
2875 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
2876 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2877 prefs_common.show_ruler);
2881 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
2882 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2883 account->default_sign);
2884 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
2885 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2886 account->default_encrypt);
2888 activate_gnupg_mode(compose, account);
2889 #endif /* USE_GPGME */
2891 if (!init && account->auto_sig)
2892 compose_insert_sig(compose, TRUE);
2895 gboolean compose_check_for_valid_recipient(Compose *compose) {
2896 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2897 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2898 gboolean recipient_found = FALSE;
2902 /* free to and newsgroup list */
2903 slist_free_strings(compose->to_list);
2904 g_slist_free(compose->to_list);
2905 compose->to_list = NULL;
2907 slist_free_strings(compose->newsgroup_list);
2908 g_slist_free(compose->newsgroup_list);
2909 compose->newsgroup_list = NULL;
2911 /* search header entries for to and newsgroup entries */
2912 for (list = compose->header_list; list; list = list->next) {
2915 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
2916 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2918 if (entry[0] != '\0') {
2919 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2920 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2921 compose->to_list = address_list_append(compose->to_list, entry);
2922 recipient_found = TRUE;
2925 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2926 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2927 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2928 recipient_found = TRUE;
2935 return recipient_found;
2938 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
2942 if (compose_check_for_valid_recipient(compose) == FALSE) {
2943 alertpanel_error(_("Recipient is not specified."));
2947 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2948 if (*str == '\0' && check_subject == TRUE) {
2951 aval = alertpanel(_("Send"),
2952 _("Subject is empty. Send it anyway?"),
2953 _("Yes"), _("No"), NULL);
2954 if (aval != G_ALERTDEFAULT)
2961 gint compose_send(Compose *compose)
2968 if (compose_check_entries(compose, TRUE) == FALSE)
2971 val = compose_queue(compose, &msgnum, &folder);
2973 alertpanel_error(_("Could not queue message for sending"));
2978 alertpanel_error(_("The message was queued but could not be sent.\nUse \"Send queued messages\" from the main window to retry."));
2982 msgpath = folder_item_fetch_msg(folder, msgnum);
2983 val = procmsg_send_message_queue(msgpath);
2986 folder_item_remove_msg(folder, msgnum);
2991 #if 0 /* compose restructure */
2992 gint compose_send(Compose *compose)
2994 gchar tmp[MAXPATHLEN + 1];
2996 static gboolean lock = FALSE;
3000 g_return_val_if_fail(compose->account != NULL, -1);
3004 if (compose_check_entries(compose, TRUE) == FALSE) {
3009 /* write to temporary file */
3010 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
3011 get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3013 if (prefs_common.linewrap_at_send)
3014 compose_wrap_line_all(compose);
3016 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
3021 if (!compose->to_list && !compose->newsgroup_list) {
3022 g_warning("can't get recipient list.");
3028 if (compose->to_list) {
3031 #if 0 /* NEW COMPOSE GUI */
3032 if (compose->account->protocol != A_NNTP)
3033 ac = compose->account;
3035 ac = account_find_from_address(compose->account->address);
3037 if (cur_account && cur_account->protocol != A_NNTP)
3040 ac = account_get_default();
3042 if (!ac || ac->protocol == A_NNTP) {
3043 alertpanel_error(_("Account for sending mail is not specified.\n"
3044 "Please select a mail account before sending."));
3051 ac = compose->account;
3053 ok = send_message(tmp, ac, compose->to_list);
3056 if (ok == 0 && compose->newsgroup_list) {
3057 ok = news_post(FOLDER(compose->account->folder), tmp);
3059 alertpanel_error(_("Error occurred while posting the message to %s ."),
3060 compose->account->nntp_server);
3067 /* queue message if failed to send */
3069 if (prefs_common.queue_msg) {
3074 _("Error occurred while sending the message.\n"
3075 "Put this message into queue folder?"),
3076 _("OK"), _("Cancel"), NULL);
3077 if (G_ALERTDEFAULT == val) {
3078 ok = compose_queue(compose, tmp);
3080 alertpanel_error(_("Can't queue the message."));
3083 alertpanel_error_log(_("Error occurred while sending the message."));
3085 if (compose->mode == COMPOSE_REEDIT) {
3086 compose_remove_reedit_target(compose);
3088 /* save message to outbox */
3089 if (prefs_common.savemsg) {
3092 outbox = account_get_special_folder
3093 (compose->account, F_OUTBOX);
3094 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
3096 (_("Can't save the message to Sent."));
3106 static gboolean compose_use_attach(Compose *compose) {
3107 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
3110 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3113 gchar buf[BUFFSIZE];
3115 gboolean first_address;
3117 ComposeHeaderEntry *headerentry;
3118 gchar *headerentryname;
3122 debug_print("Writing redirect header\n");
3124 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3125 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3127 first_address = TRUE;
3128 for (list = compose->header_list; list; list = list->next) {
3129 headerentry = ((ComposeHeaderEntry *)list->data);
3130 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3132 if (g_strcasecmp(headerentryname, cc_hdr) == 0
3133 || g_strcasecmp(headerentryname, to_hdr) == 0) {
3134 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3135 Xstrdup_a(str, str, return -1);
3137 if (str[0] != '\0') {
3138 compose_convert_header
3139 (buf, sizeof(buf), str,
3140 strlen("Resent-To") + 2, TRUE);
3141 if (first_address) {
3142 fprintf(fp, "Resent-To: ");
3143 first_address = FALSE;
3147 fprintf(fp, "%s", buf);
3151 /* if (!first_address) { */
3158 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3160 gchar buf[BUFFSIZE];
3162 /* struct utsname utsbuf; */
3164 g_return_val_if_fail(fp != NULL, -1);
3165 g_return_val_if_fail(compose->account != NULL, -1);
3166 g_return_val_if_fail(compose->account->address != NULL, -1);
3169 get_rfc822_date(buf, sizeof(buf));
3170 fprintf(fp, "Resent-Date: %s\n", buf);
3173 if (compose->account->name && *compose->account->name) {
3174 compose_convert_header
3175 (buf, sizeof(buf), compose->account->name,
3176 strlen("From: "), TRUE);
3177 fprintf(fp, "Resent-From: %s <%s>\n",
3178 buf, compose->account->address);
3180 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3183 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3185 Xstrdup_a(str, str, return -1);
3188 compose_convert_header(buf, sizeof(buf), str,
3189 strlen("Subject: "), FALSE);
3190 fprintf(fp, "Subject: %s\n", buf);
3194 /* Resent-Message-ID */
3195 if (compose->account->gen_msgid) {
3196 compose_generate_msgid(compose, buf, sizeof(buf));
3197 fprintf(fp, "Resent-Message-Id: <%s>\n", buf);
3198 compose->msgid = g_strdup(buf);
3201 compose_redirect_write_headers_from_headerlist(compose, fp);
3203 /* separator between header and body */
3209 static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
3214 gchar buf[BUFFSIZE];
3216 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3217 FILE_OP_ERROR(file, "fopen");
3221 if ((fdest = fopen(file, "wb")) == NULL) {
3222 FILE_OP_ERROR(file, "fopen");
3227 /* chmod for security */
3228 if (change_file_mode_rw(fdest, file) < 0) {
3229 FILE_OP_ERROR(file, "chmod");
3230 g_warning("can't change file mode\n");
3233 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
3234 /* should filter returnpath, delivered-to */
3235 if (g_strncasecmp(buf, "Return-Path:",
3236 strlen("Return-Path:")) == 0 ||
3237 g_strncasecmp(buf, "Delivered-To:",
3238 strlen("Delivered-To:")) == 0 ||
3239 g_strncasecmp(buf, "Received:",
3240 strlen("Received:")) == 0 ||
3241 g_strncasecmp(buf, "Subject:",
3242 strlen("Subject:")) == 0 ||
3243 g_strncasecmp(buf, "X-UIDL:",
3244 strlen("X-UIDL:")) == 0)
3247 if (fputs(buf, fdest) == -1)
3250 if (!prefs_common.redirect_keep_from) {
3251 if (g_strncasecmp(buf, "From:",
3252 strlen("From:")) == 0) {
3253 fputs(" (by way of ", fdest);
3254 if (compose->account->name
3255 && *compose->account->name) {
3256 compose_convert_header
3258 compose->account->name,
3261 fprintf(fdest, "%s <%s>",
3263 compose->account->address);
3265 fprintf(fdest, "%s",
3266 compose->account->address);
3271 if (fputs("\n", fdest) == -1)
3275 compose_redirect_write_headers(compose, fdest);
3277 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3278 if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
3279 FILE_OP_ERROR(file, "fwrite");
3285 if (fclose(fdest) == EOF) {
3286 FILE_OP_ERROR(file, "fclose");
3302 /* interfaces to rfc2015 to keep out the prefs stuff there.
3303 * returns 0 on success and -1 on error. */
3304 static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
3306 const gchar *key_id = NULL;
3309 switch (compose->account->sign_key) {
3310 case SIGN_KEY_DEFAULT:
3313 case SIGN_KEY_BY_FROM:
3314 key_id = compose->account->address;
3316 case SIGN_KEY_CUSTOM:
3317 key_id = compose->account->sign_key_id;
3323 key_list = rfc2015_create_signers_list(key_id);
3326 alertpanel_error(_("Could not find any key associated with "
3327 "currently selected key id `%s'."), key_id);
3331 *pkey_list = key_list;
3335 /* clearsign message body text */
3336 static gint compose_clearsign_text(Compose *compose, gchar **text)
3341 tmp_file = get_tmp_file();
3342 if (str_write_to_file(*text, tmp_file) < 0) {
3347 if (compose_create_signers_list(compose, &key_list) < 0 ||
3348 rfc2015_clearsign(tmp_file, key_list) < 0) {
3355 *text = file_read_to_str(tmp_file);
3363 #endif /* USE_GPGME */
3365 static gint compose_write_to_file(Compose *compose, const gchar *file,
3373 const gchar *out_codeset;
3374 EncodingType encoding;
3376 if ((fp = fopen(file, "wb")) == NULL) {
3377 FILE_OP_ERROR(file, "fopen");
3381 /* chmod for security */
3382 if (change_file_mode_rw(fp, file) < 0) {
3383 FILE_OP_ERROR(file, "chmod");
3384 g_warning("can't change file mode\n");
3387 /* get all composed text */
3388 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3389 len = strlen(chars);
3390 if (is_ascii_str(chars)) {
3393 out_codeset = CS_US_ASCII;
3394 encoding = ENC_7BIT;
3396 const gchar *src_codeset;
3398 out_codeset = conv_get_outgoing_charset_str();
3399 if (!strcasecmp(out_codeset, CS_US_ASCII))
3400 out_codeset = CS_ISO_8859_1;
3402 if (prefs_common.encoding_method == CTE_BASE64)
3403 encoding = ENC_BASE64;
3404 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3405 encoding = ENC_QUOTED_PRINTABLE;
3406 else if (prefs_common.encoding_method == CTE_8BIT)
3407 encoding = ENC_8BIT;
3409 encoding = procmime_get_encoding_for_charset(out_codeset);
3413 compose->use_signing && !compose->gnupg_mode &&
3414 encoding == ENC_8BIT)
3415 encoding = ENC_BASE64;
3418 src_codeset = conv_get_current_charset_str();
3419 /* if current encoding is US-ASCII, set it the same as
3420 outgoing one to prevent code conversion failure */
3421 if (!strcasecmp(src_codeset, CS_US_ASCII))
3422 src_codeset = out_codeset;
3424 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3425 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3427 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3432 msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
3434 "Send it anyway?"), src_codeset, out_codeset);
3436 (_("Error"), msg, _("Yes"), _("+No"), NULL);
3439 if (aval != G_ALERTDEFAULT) {
3446 out_codeset = src_codeset;
3453 canon_buf = canonicalize_str(buf);
3458 if (!is_draft && compose->use_signing && compose->gnupg_mode) {
3459 if (compose_clearsign_text(compose, &buf) < 0) {
3460 g_warning("clearsign failed\n");
3470 if (compose_write_headers
3471 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3472 g_warning("can't write headers\n");
3479 if (compose_use_attach(compose)) {
3481 /* This prolog message is ignored by mime software and
3482 * because it would make our signing/encryption task
3483 * tougher, we don't emit it in that case */
3484 if (!compose->use_signing && !compose->use_encryption)
3486 fputs("This is a multi-part message in MIME format.\n", fp);
3488 fprintf(fp, "\n--%s\n", compose->boundary);
3489 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3491 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3492 procmime_get_encoding_str(encoding));
3498 if (encoding == ENC_BASE64) {
3499 gchar outbuf[B64_BUFFSIZE];
3502 for (i = 0; i < len; i += B64_LINE_SIZE) {
3503 l = MIN(B64_LINE_SIZE, len - i);
3504 base64_encode(outbuf, buf + i, l);
3508 } else if (encoding == ENC_QUOTED_PRINTABLE) {
3512 outbuf = g_malloc(len * 4);
3513 qp_encode_line(outbuf, buf);
3514 outlen = strlen(outbuf);
3515 if (fwrite(outbuf, sizeof(gchar), outlen, fp) != outlen) {
3516 FILE_OP_ERROR(file, "fwrite");
3524 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3525 FILE_OP_ERROR(file, "fwrite");
3533 if (compose_use_attach(compose))
3534 compose_write_attach(compose, fp);
3536 if (fclose(fp) == EOF) {
3537 FILE_OP_ERROR(file, "fclose");
3544 uncanonicalize_file_replace(file);
3548 if ((compose->use_signing && !compose->gnupg_mode) ||
3549 compose->use_encryption) {
3550 if (canonicalize_file_replace(file) < 0) {
3556 if (compose->use_signing && !compose->gnupg_mode) {
3559 if (compose_create_signers_list(compose, &key_list) < 0 ||
3560 rfc2015_sign(file, key_list) < 0) {
3565 if (compose->use_encryption) {
3566 if (rfc2015_encrypt(file, compose->to_list,
3567 compose->gnupg_mode) < 0) {
3572 #endif /* USE_GPGME */
3574 uncanonicalize_file_replace(file);
3579 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3585 if ((fp = fopen(file, "wb")) == NULL) {
3586 FILE_OP_ERROR(file, "fopen");
3590 /* chmod for security */
3591 if (change_file_mode_rw(fp, file) < 0) {
3592 FILE_OP_ERROR(file, "chmod");
3593 g_warning("can't change file mode\n");
3596 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3599 len = strlen(chars);
3600 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3601 FILE_OP_ERROR(file, "fwrite");
3610 if (fclose(fp) == EOF) {
3611 FILE_OP_ERROR(file, "fclose");
3618 static gint compose_remove_reedit_target(Compose *compose)
3621 MsgInfo *msginfo = compose->targetinfo;
3623 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3624 if (!msginfo) return -1;
3626 item = msginfo->folder;
3627 g_return_val_if_fail(item != NULL, -1);
3629 if (procmsg_msg_exist(msginfo) &&
3630 (item->stype == F_DRAFT || item->stype == F_QUEUE
3631 || msginfo == compose->autosaved_draft)) {
3632 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3633 g_warning("can't remove the old message\n");
3641 void compose_remove_draft(Compose *compose)
3644 MsgInfo *msginfo = compose->targetinfo;
3645 drafts = account_get_special_folder(compose->account, F_DRAFT);
3647 if (procmsg_msg_exist(msginfo)) {
3648 folder_item_remove_msg(drafts, msginfo->msgnum);
3653 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3655 return compose_queue_sub (compose, msgnum, item, FALSE);
3657 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3663 gchar buf[BUFFSIZE];
3665 static gboolean lock = FALSE;
3666 PrefsAccount *mailac = NULL, *newsac = NULL;
3668 debug_print("queueing message...\n");
3669 g_return_val_if_fail(compose->account != NULL, -1);
3673 if (compose_check_entries(compose, check_subject) == FALSE) {
3678 if (!compose->to_list && !compose->newsgroup_list) {
3679 g_warning("can't get recipient list.");
3684 if (compose->to_list) {
3685 if (compose->account->protocol != A_NNTP)
3686 mailac = compose->account;
3687 else if (cur_account && cur_account->protocol != A_NNTP)
3688 mailac = cur_account;
3689 else if (!(mailac = compose_current_mail_account())) {
3691 alertpanel_error(_("No account for sending mails available!"));
3696 if (compose->newsgroup_list) {
3697 if (compose->account->protocol == A_NNTP)
3698 newsac = compose->account;
3699 else if (!newsac->protocol != A_NNTP) {
3701 alertpanel_error(_("No account for posting news available!"));
3706 if (prefs_common.linewrap_at_send)
3707 compose_wrap_line_all(compose);
3709 /* write to temporary file */
3710 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3711 G_DIR_SEPARATOR, (gint)compose);
3713 if (compose->redirect_filename != NULL) {
3714 if (compose_redirect_write_to_file(compose, tmp2) < 0) {
3721 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3728 /* add queue header */
3729 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3730 G_DIR_SEPARATOR, (gint)compose);
3731 if ((fp = fopen(tmp, "wb")) == NULL) {
3732 FILE_OP_ERROR(tmp, "fopen");
3736 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3737 FILE_OP_ERROR(tmp2, "fopen");
3745 if (change_file_mode_rw(fp, tmp) < 0) {
3746 FILE_OP_ERROR(tmp, "chmod");
3747 g_warning("can't change file mode\n");
3750 /* queueing variables */
3751 fprintf(fp, "AF:\n");
3752 fprintf(fp, "NF:0\n");
3753 fprintf(fp, "PS:10\n");
3754 fprintf(fp, "SRH:1\n");
3755 fprintf(fp, "SFN:\n");
3756 fprintf(fp, "DSR:\n");
3758 fprintf(fp, "MID:<%s>\n", compose->msgid);
3760 fprintf(fp, "MID:\n");
3761 fprintf(fp, "CFG:\n");
3762 fprintf(fp, "PT:0\n");
3763 fprintf(fp, "S:%s\n", compose->account->address);
3764 fprintf(fp, "RQ:\n");
3766 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3768 fprintf(fp, "SSV:\n");
3770 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3772 fprintf(fp, "NSV:\n");
3773 fprintf(fp, "SSH:\n");
3774 /* write recepient list */
3775 if (compose->to_list) {
3776 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
3777 for (cur = compose->to_list->next; cur != NULL;
3779 fprintf(fp, ",<%s>", (gchar *)cur->data);
3782 /* write newsgroup list */
3783 if (compose->newsgroup_list) {
3785 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3786 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3787 fprintf(fp, ",%s", (gchar *)cur->data);
3790 /* Sylpheed account IDs */
3792 fprintf(fp, "MAID:%d\n", mailac->account_id);
3795 fprintf(fp, "NAID:%d\n", newsac->account_id);
3797 /* Save copy folder */
3798 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3799 gchar *savefolderid;
3801 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3802 fprintf(fp, "SCF:%s\n", savefolderid);
3803 g_free(savefolderid);
3805 /* Message-ID of message replying to */
3806 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
3809 folderid = folder_item_get_identifier(compose->replyinfo->folder);
3810 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
3813 /* Message-ID of message forwarding to */
3814 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
3817 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
3818 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
3823 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3824 if (fputs(buf, fp) == EOF) {
3825 FILE_OP_ERROR(tmp, "fputs");
3836 if (fclose(fp) == EOF) {
3837 FILE_OP_ERROR(tmp, "fclose");
3845 queue = account_get_special_folder(compose->account, F_QUEUE);
3847 g_warning("can't find queue folder\n");
3852 folder_item_scan(queue);
3853 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3854 g_warning("can't queue the message\n");
3864 if (compose->mode == COMPOSE_REEDIT) {
3865 compose_remove_reedit_target(compose);
3868 if ((msgnum != NULL) && (item != NULL)) {
3876 static void compose_write_attach(Compose *compose, FILE *fp)
3879 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3882 gchar filename[BUFFSIZE];
3885 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3887 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
3888 g_warning("Can't open file %s\n", ainfo->file);
3892 fprintf(fp, "\n--%s\n", compose->boundary);
3894 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3895 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3896 fprintf(fp, "Content-Disposition: inline\n");
3898 compose_convert_header(filename, sizeof(filename),
3899 ainfo->name, 12, FALSE);
3900 fprintf(fp, "Content-Type: %s;\n"
3902 ainfo->content_type, filename);
3903 fprintf(fp, "Content-Disposition: attachment;\n"
3904 " filename=\"%s\"\n", filename);
3907 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3908 procmime_get_encoding_str(ainfo->encoding));
3910 if (ainfo->encoding == ENC_BASE64) {
3911 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3913 while ((len = fread(inbuf, sizeof(gchar),
3914 B64_LINE_SIZE, attach_fp))
3916 base64_encode(outbuf, inbuf, B64_LINE_SIZE);
3920 if (len > 0 && feof(attach_fp)) {
3921 base64_encode(outbuf, inbuf, len);
3925 } else if (ainfo->encoding == ENC_QUOTED_PRINTABLE) {
3926 gchar inbuf[BUFFSIZE], outbuf[BUFFSIZE * 4];
3928 while (fgets(inbuf, sizeof(inbuf), attach_fp) != NULL) {
3929 qp_encode_line(outbuf, inbuf);
3933 gchar buf[BUFFSIZE];
3935 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3944 fprintf(fp, "\n--%s--\n", compose->boundary);
3947 #define QUOTE_IF_REQUIRED(out, str) \
3949 if (*str != '"' && (strchr(str, ',') \
3950 || strchr(str, '.'))) { \
3954 len = strlen(str) + 3; \
3955 Xalloca(__tmp, len, return -1); \
3956 g_snprintf(__tmp, len, "\"%s\"", str); \
3959 Xstrdup_a(out, str, return -1); \
3963 #define PUT_RECIPIENT_HEADER(header, str) \
3965 if (*str != '\0') { \
3966 Xstrdup_a(str, str, return -1); \
3968 if (*str != '\0') { \
3969 compose->to_list = address_list_append \
3970 (compose->to_list, str); \
3971 compose_convert_header \
3972 (buf, sizeof(buf), str, strlen(header) + 2, \
3974 fprintf(fp, "%s: %s\n", header, buf); \
3979 #define IS_IN_CUSTOM_HEADER(header) \
3980 (compose->account->add_customhdr && \
3981 custom_header_find(compose->account->customhdr_list, header) != NULL)
3983 static gint compose_write_headers_from_headerlist(Compose *compose,
3987 gchar buf[BUFFSIZE];
3988 gchar *str, *header_w_colon, *trans_hdr;
3989 gboolean first_address;
3991 ComposeHeaderEntry *headerentry;
3992 gchar * headerentryname;
3994 if (IS_IN_CUSTOM_HEADER(header)) {
3998 debug_print("Writing %s-header\n", header);
4000 header_w_colon = g_strconcat(header, ":", NULL);
4001 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
4003 first_address = TRUE;
4004 for (list = compose->header_list; list; list = list->next) {
4005 headerentry = ((ComposeHeaderEntry *)list->data);
4006 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4008 if (!g_strcasecmp(trans_hdr, headerentryname)) {
4009 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4010 Xstrdup_a(str, str, return -1);
4012 if (str[0] != '\0') {
4013 compose_convert_header
4014 (buf, sizeof(buf), str,
4015 strlen(header) + 2, TRUE);
4016 if (first_address) {
4017 fprintf(fp, "%s: ", header);
4018 first_address = FALSE;
4022 fprintf(fp, "%s", buf);
4026 if (!first_address) {
4030 g_free(header_w_colon);
4035 static gint compose_write_headers(Compose *compose, FILE *fp,
4036 const gchar *charset, EncodingType encoding,
4039 gchar buf[BUFFSIZE];
4043 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4045 /* struct utsname utsbuf; */
4047 g_return_val_if_fail(fp != NULL, -1);
4048 g_return_val_if_fail(charset != NULL, -1);
4049 g_return_val_if_fail(compose->account != NULL, -1);
4050 g_return_val_if_fail(compose->account->address != NULL, -1);
4052 /* Save draft infos */
4054 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
4055 fprintf(fp, "S:%s\n", compose->account->address);
4056 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4057 gchar *savefolderid;
4059 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4060 fprintf(fp, "SCF:%s\n", savefolderid);
4061 g_free(savefolderid);
4067 if (compose->account->add_date) {
4068 get_rfc822_date(buf, sizeof(buf));
4069 fprintf(fp, "Date: %s\n", buf);
4073 if (!IS_IN_CUSTOM_HEADER("From")) {
4074 if (compose->account->name && *compose->account->name) {
4075 compose_convert_header
4076 (buf, sizeof(buf), compose->account->name,
4077 strlen("From: "), TRUE);
4078 QUOTE_IF_REQUIRED(name, buf);
4079 fprintf(fp, "From: %s <%s>\n",
4080 name, compose->account->address);
4082 fprintf(fp, "From: %s\n", compose->account->address);
4086 compose_write_headers_from_headerlist(compose, fp, "To");
4087 #if 0 /* NEW COMPOSE GUI */
4088 if (compose->use_to) {
4089 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
4090 PUT_RECIPIENT_HEADER("To", str);
4095 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
4096 #if 0 /* NEW COMPOSE GUI */
4097 if (compose->use_newsgroups) {
4098 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
4100 Xstrdup_a(str, str, return -1);
4104 compose->newsgroup_list =
4105 newsgroup_list_append
4106 (compose->newsgroup_list, str);
4107 compose_convert_header(buf, sizeof(buf), str,
4108 strlen("Newsgroups: "),
4110 fprintf(fp, "Newsgroups: %s\n", buf);
4116 compose_write_headers_from_headerlist(compose, fp, "Cc");
4117 #if 0 /* NEW COMPOSE GUI */
4118 if (compose->use_cc) {
4119 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
4120 PUT_RECIPIENT_HEADER("Cc", str);
4124 compose_write_headers_from_headerlist(compose, fp, "Bcc");
4125 #if 0 /* NEW COMPOSE GUI */
4126 if (compose->use_bcc) {
4127 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
4128 PUT_RECIPIENT_HEADER("Bcc", str);
4133 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4134 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4135 Xstrdup_a(str, str, return -1);
4138 compose_convert_header(buf, sizeof(buf), str,
4139 strlen("Subject: "), FALSE);
4140 fprintf(fp, "Subject: %s\n", buf);
4145 if (compose->account->gen_msgid) {
4146 compose_generate_msgid(compose, buf, sizeof(buf));
4147 fprintf(fp, "Message-Id: <%s>\n", buf);
4148 compose->msgid = g_strdup(buf);
4152 if (compose->inreplyto && compose->to_list)
4153 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
4156 if (compose->references)
4157 fprintf(fp, "References: %s\n", compose->references);
4160 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
4161 #if 0 /* NEW COMPOSE GUI */
4162 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
4163 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
4165 Xstrdup_a(str, str, return -1);
4169 compose_convert_header(buf, sizeof(buf), str,
4170 strlen("Followup-To: "),
4172 fprintf(fp, "Followup-To: %s\n", buf);
4178 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
4179 #if 0 /* NEW COMPOSE GUI */
4180 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
4181 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
4183 Xstrdup_a(str, str, return -1);
4186 compose_convert_header(buf, sizeof(buf), str,
4187 strlen("Reply-To: "),
4189 fprintf(fp, "Reply-To: %s\n", buf);
4195 if (compose->account->organization &&
4196 !IS_IN_CUSTOM_HEADER("Organization")) {
4197 compose_convert_header(buf, sizeof(buf),
4198 compose->account->organization,
4199 strlen("Organization: "), FALSE);
4200 fprintf(fp, "Organization: %s\n", buf);
4203 /* Program version and system info */
4204 /* uname(&utsbuf); */
4205 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4206 !compose->newsgroup_list) {
4207 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4209 gtk_major_version, gtk_minor_version, gtk_micro_version,
4211 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4213 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4214 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4216 gtk_major_version, gtk_minor_version, gtk_micro_version,
4218 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4221 /* custom headers */
4222 if (compose->account->add_customhdr) {
4225 for (cur = compose->account->customhdr_list; cur != NULL;
4227 CustomHeader *chdr = (CustomHeader *)cur->data;
4229 if (strcasecmp(chdr->name, "Date") != 0 &&
4230 strcasecmp(chdr->name, "From") != 0 &&
4231 strcasecmp(chdr->name, "To") != 0 &&
4232 /* strcasecmp(chdr->name, "Sender") != 0 && */
4233 strcasecmp(chdr->name, "Message-Id") != 0 &&
4234 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
4235 strcasecmp(chdr->name, "References") != 0 &&
4236 strcasecmp(chdr->name, "Mime-Version") != 0 &&
4237 strcasecmp(chdr->name, "Content-Type") != 0 &&
4238 strcasecmp(chdr->name, "Content-Transfer-Encoding")
4240 compose_convert_header
4242 chdr->value ? chdr->value : "",
4243 strlen(chdr->name) + 2, FALSE);
4244 fprintf(fp, "%s: %s\n", chdr->name, buf);
4250 fprintf(fp, "Mime-Version: 1.0\n");
4251 if (compose_use_attach(compose)) {
4252 get_rfc822_date(buf, sizeof(buf));
4253 subst_char(buf, ' ', '_');
4254 subst_char(buf, ',', '_');
4255 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
4256 buf, (guint)compose);
4258 "Content-Type: multipart/mixed;\n"
4259 " boundary=\"%s\"\n", compose->boundary);
4261 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
4262 fprintf(fp, "Content-Transfer-Encoding: %s\n",
4263 procmime_get_encoding_str(encoding));
4267 switch (compose->priority) {
4268 case PRIORITY_HIGHEST: fprintf(fp, "Importance: high\n"
4269 "X-Priority: 1 (Highest)\n");
4271 case PRIORITY_HIGH: fprintf(fp, "Importance: high\n"
4272 "X-Priority: 2 (High)\n");
4274 case PRIORITY_NORMAL: break;
4275 case PRIORITY_LOW: fprintf(fp, "Importance: low\n"
4276 "X-Priority: 4 (Low)\n");
4278 case PRIORITY_LOWEST: fprintf(fp, "Importance: low\n"
4279 "X-Priority: 5 (Lowest)\n");
4281 default: debug_print("compose: priority unknown : %d\n",
4285 /* Request Return Receipt */
4286 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4287 if (compose->return_receipt) {
4288 if (compose->account->name
4289 && *compose->account->name) {
4290 compose_convert_header(buf, sizeof(buf),
4291 compose->account->name,
4292 strlen("Disposition-Notification-To: "),
4294 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4296 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
4300 /* get special headers */
4301 for (list = compose->header_list; list; list = list->next) {
4302 ComposeHeaderEntry *headerentry;
4305 gchar *headername_wcolon;
4306 gchar *headername_trans;
4309 gboolean standard_header = FALSE;
4311 headerentry = ((ComposeHeaderEntry *)list->data);
4313 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4314 if (!strstr(tmp, ":")) {
4315 headername_wcolon = g_strconcat(tmp, ":", NULL);
4316 headername = g_strdup(tmp);
4318 headername_wcolon = g_strdup(tmp);
4319 headername = g_strdup(strtok(tmp, ":"));
4323 headervalue = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4324 string = std_headers;
4325 while (*string != NULL) {
4326 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4327 if (!strcmp(headername_trans,headername_wcolon))
4328 standard_header = TRUE;
4331 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4332 fprintf(fp, "%s %s\n", headername_wcolon, headervalue);
4335 g_free(headername_wcolon);
4339 /* separator between header and body */
4345 #undef IS_IN_CUSTOM_HEADER
4347 static void compose_convert_header(gchar *dest, gint len, gchar *src,
4348 gint header_len, gboolean addr_field)
4350 g_return_if_fail(src != NULL);
4351 g_return_if_fail(dest != NULL);
4353 if (len < 1) return;
4357 conv_encode_header(dest, len, src, header_len, addr_field);
4360 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
4369 if (compose->account && compose->account->address &&
4370 *compose->account->address) {
4371 if (strchr(compose->account->address, '@'))
4372 addr = g_strdup(compose->account->address);
4374 addr = g_strconcat(compose->account->address, "@",
4375 get_domain_name(), NULL);
4377 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
4380 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
4381 lt->tm_year + 1900, lt->tm_mon + 1,
4382 lt->tm_mday, lt->tm_hour,
4383 lt->tm_min, lt->tm_sec,
4384 (guint)random(), addr);
4386 debug_print("generated Message-ID: %s\n", buf);
4391 static void compose_create_header_entry(Compose *compose)
4393 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4397 GList *combo_list = NULL;
4398 gchar **string, *header = NULL;
4399 ComposeHeaderEntry *headerentry;
4400 gboolean standard_header = FALSE;
4402 headerentry = g_new0(ComposeHeaderEntry, 1);
4405 combo = gtk_combo_new();
4407 while(*string != NULL) {
4408 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4411 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4412 g_list_free(combo_list);
4413 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4414 gtk_widget_show(combo);
4415 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4416 if (compose->header_last) {
4417 gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4419 while (*string != NULL) {
4420 if (!strcmp(*string, last_header_entry))
4421 standard_header = TRUE;
4424 if (standard_header)
4425 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4427 if (!compose->header_last || !standard_header) {
4428 switch(compose->account->protocol) {
4430 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4433 header = prefs_common.trans_hdr ? _("To:") : "To:";
4438 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4441 entry = gtk_entry_new();
4442 gtk_widget_show(entry);
4443 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);
4445 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4446 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4447 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4449 address_completion_register_entry(GTK_ENTRY(entry));
4451 headerentry->compose = compose;
4452 headerentry->combo = combo;
4453 headerentry->entry = entry;
4454 headerentry->headernum = compose->header_nextrow;
4456 compose->header_nextrow++;
4457 compose->header_last = headerentry;
4460 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4462 ComposeHeaderEntry *last_header;
4464 last_header = compose->header_last;
4466 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4467 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4470 static GtkWidget *compose_create_header(Compose *compose)
4474 GtkWidget *from_optmenu_hbox;
4475 #if 0 /* NEW COMPOSE GUI */
4476 GtkWidget *to_entry;
4478 GtkWidget *newsgroups_entry;
4479 GtkWidget *newsgroups_hbox;
4481 GtkWidget *header_scrolledwin;
4482 GtkWidget *header_table;
4483 #if 0 /* NEW COMPOSE GUI */
4484 GtkWidget *cc_entry;
4486 GtkWidget *bcc_entry;
4487 GtkWidget *bcc_hbox;
4488 GtkWidget *reply_entry;
4489 GtkWidget *reply_hbox;
4490 GtkWidget *followup_entry;
4491 GtkWidget *followup_hbox;
4496 /* header labels and entries */
4497 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4498 gtk_widget_show(header_scrolledwin);
4499 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4501 header_table = gtk_table_new(2, 2, FALSE);
4502 gtk_widget_show(header_table);
4503 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4504 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4505 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4508 /* option menu for selecting accounts */
4509 hbox = gtk_hbox_new(FALSE, 0);
4510 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4511 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4512 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4514 from_optmenu_hbox = compose_account_option_menu_create(compose);
4515 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4516 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4517 #if 0 /* NEW COMPOSE GUI */
4518 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4522 compose->header_table = header_table;
4523 compose->header_list = NULL;
4524 compose->header_nextrow = count;
4526 compose_create_header_entry(compose);
4528 #if 0 /* NEW COMPOSE GUI */
4529 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4531 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4532 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4533 &count, "Newsgroups:", FALSE);
4534 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4536 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4538 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4540 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4541 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4543 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4544 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4546 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4547 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4548 "Followup-To:", FALSE);
4549 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4551 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4553 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4554 GTK_SIGNAL_FUNC(to_activated), compose);
4555 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4556 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4557 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4558 GTK_SIGNAL_FUNC(subject_activated), compose);
4559 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4560 GTK_SIGNAL_FUNC(cc_activated), compose);
4561 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4562 GTK_SIGNAL_FUNC(bcc_activated), compose);
4563 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4564 GTK_SIGNAL_FUNC(replyto_activated), compose);
4565 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4566 GTK_SIGNAL_FUNC(followupto_activated), compose);
4568 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4569 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4570 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4571 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4572 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4573 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4574 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4575 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4576 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4577 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4578 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4579 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4580 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4581 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4584 compose->table = NULL;
4585 #if 0 /* NEW COMPOSE GUI */
4586 compose->table = table;
4587 compose->to_hbox = to_hbox;
4588 compose->to_entry = to_entry;
4589 compose->newsgroups_hbox = newsgroups_hbox;
4590 compose->newsgroups_entry = newsgroups_entry;
4592 #if 0 /* NEW COMPOSE GUI */
4593 compose->cc_hbox = cc_hbox;
4594 compose->cc_entry = cc_entry;
4595 compose->bcc_hbox = bcc_hbox;
4596 compose->bcc_entry = bcc_entry;
4597 compose->reply_hbox = reply_hbox;
4598 compose->reply_entry = reply_entry;
4599 compose->followup_hbox = followup_hbox;
4600 compose->followup_entry = followup_entry;
4603 return header_scrolledwin ;
4606 GtkWidget *compose_create_attach(Compose *compose)
4608 gchar *titles[N_ATTACH_COLS];
4611 GtkWidget *attach_scrwin;
4612 GtkWidget *attach_clist;
4614 titles[COL_MIMETYPE] = _("MIME type");
4615 titles[COL_SIZE] = _("Size");
4616 titles[COL_NAME] = _("Name");
4618 /* attachment list */
4619 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4620 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4621 GTK_POLICY_AUTOMATIC,
4623 gtk_widget_set_usize(attach_scrwin, -1, 80);
4625 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4626 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4628 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4629 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4630 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4631 GTK_SELECTION_EXTENDED);
4632 for (i = 0; i < N_ATTACH_COLS; i++)
4633 GTK_WIDGET_UNSET_FLAGS
4634 (GTK_CLIST(attach_clist)->column[i].button,
4636 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4638 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4639 GTK_SIGNAL_FUNC(attach_selected), compose);
4640 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4641 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4642 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4643 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4646 gtk_drag_dest_set(attach_clist,
4647 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4648 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4649 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4650 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4653 compose->attach_scrwin = attach_scrwin;
4654 compose->attach_clist = attach_clist;
4656 return attach_scrwin;
4659 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4660 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4662 static GtkWidget *compose_create_others(Compose *compose)
4665 GtkWidget *savemsg_checkbtn;
4666 GtkWidget *savemsg_entry;
4667 GtkWidget *savemsg_select;
4670 gchar *folderidentifier;
4672 /* Table for settings */
4673 table = gtk_table_new(3, 1, FALSE);
4674 gtk_widget_show(table);
4675 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4678 /* Save Message to folder */
4679 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4680 gtk_widget_show(savemsg_checkbtn);
4681 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4682 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4683 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4685 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4686 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4688 savemsg_entry = gtk_entry_new();
4689 gtk_widget_show(savemsg_entry);
4690 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4691 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4692 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4693 folderidentifier = folder_item_get_identifier(account_get_special_folder
4694 (compose->account, F_OUTBOX));
4695 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4696 g_free(folderidentifier);
4699 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4700 gtk_widget_show (savemsg_select);
4701 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4702 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4703 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4708 compose->savemsg_checkbtn = savemsg_checkbtn;
4709 compose->savemsg_entry = savemsg_entry;
4714 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4716 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4717 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4720 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4725 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4728 path = folder_item_get_identifier(dest);
4730 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4734 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4740 GtkWidget *handlebox;
4742 GtkWidget *notebook;
4747 GtkWidget *subject_hbox;
4748 GtkWidget *subject_frame;
4749 GtkWidget *subject_entry;
4753 GtkWidget *edit_vbox;
4754 GtkWidget *ruler_hbox;
4756 GtkWidget *scrolledwin;
4759 UndoMain *undostruct;
4761 gchar *titles[N_ATTACH_COLS];
4762 guint n_menu_entries;
4763 GtkStyle *style, *new_style;
4766 gboolean success[1];
4767 GtkWidget *popupmenu;
4768 GtkItemFactory *popupfactory;
4769 GtkItemFactory *ifactory;
4770 GtkWidget *tmpl_menu;
4774 GtkAspell * gtkaspell = NULL;
4777 static GdkGeometry geometry;
4779 g_return_val_if_fail(account != NULL, NULL);
4781 debug_print("Creating compose window...\n");
4782 compose = g_new0(Compose, 1);
4784 titles[COL_MIMETYPE] = _("MIME type");
4785 titles[COL_SIZE] = _("Size");
4786 titles[COL_NAME] = _("Name");
4788 compose->account = account;
4790 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4791 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4792 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4793 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4795 if (!geometry.max_width) {
4796 geometry.max_width = gdk_screen_width();
4797 geometry.max_height = gdk_screen_height();
4799 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4800 &geometry, GDK_HINT_MAX_SIZE);
4802 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4803 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4804 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4805 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4806 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4807 gtk_widget_realize(window);
4809 gtkut_widget_set_composer_icon(window);
4811 vbox = gtk_vbox_new(FALSE, 0);
4812 gtk_container_add(GTK_CONTAINER(window), vbox);
4814 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4815 menubar = menubar_create(window, compose_entries,
4816 n_menu_entries, "<Compose>", compose);
4817 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4819 handlebox = gtk_handle_box_new();
4820 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4822 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
4825 vbox2 = gtk_vbox_new(FALSE, 2);
4826 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4827 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4830 notebook = gtk_notebook_new();
4831 gtk_widget_set_usize(notebook, -1, 130);
4832 gtk_widget_show(notebook);
4834 /* header labels and entries */
4835 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4836 /* attachment list */
4837 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4839 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4842 subject_hbox = gtk_hbox_new(FALSE, 0);
4843 gtk_widget_show(subject_hbox);
4845 subject_frame = gtk_frame_new(NULL);
4846 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4847 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4848 gtk_widget_show(subject_frame);
4850 subject = gtk_hbox_new(FALSE, 0);
4851 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4852 gtk_widget_show(subject);
4854 label = gtk_label_new(_("Subject:"));
4855 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4856 gtk_widget_show(label);
4858 subject_entry = gtk_entry_new();
4859 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4860 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4861 gtk_widget_show(subject_entry);
4862 compose->subject_entry = subject_entry;
4863 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4865 edit_vbox = gtk_vbox_new(FALSE, 0);
4866 #if 0 /* NEW COMPOSE GUI */
4867 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4870 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4873 ruler_hbox = gtk_hbox_new(FALSE, 0);
4874 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4876 ruler = gtk_shruler_new();
4877 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4878 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4880 gtk_widget_set_usize(ruler_hbox, 1, -1);
4883 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4884 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4885 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4886 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4887 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4889 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4890 (GTK_SCROLLED_WINDOW(scrolledwin)),
4891 gtk_scrolled_window_get_vadjustment
4892 (GTK_SCROLLED_WINDOW(scrolledwin)));
4893 GTK_STEXT(text)->default_tab_width = 8;
4894 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4896 if (prefs_common.block_cursor) {
4897 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4900 if (prefs_common.smart_wrapping) {
4901 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4902 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4905 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4907 gtk_signal_connect(GTK_OBJECT(text), "changed",
4908 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4909 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4910 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4911 gtk_signal_connect(GTK_OBJECT(text), "activate",
4912 GTK_SIGNAL_FUNC(text_activated), compose);
4913 gtk_signal_connect(GTK_OBJECT(text), "insert_text",
4914 GTK_SIGNAL_FUNC(text_inserted), compose);
4915 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4916 GTK_SIGNAL_FUNC(compose_button_press_cb),
4919 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4920 GTK_SIGNAL_FUNC(compose_key_press_cb),
4923 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4924 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4928 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4929 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4930 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4931 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4933 gtk_widget_show_all(vbox);
4935 /* pane between attach clist and text */
4936 paned = gtk_vpaned_new();
4937 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4938 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4939 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4940 gtk_paned_add1(GTK_PANED(paned), notebook);
4941 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4942 gtk_widget_show_all(paned);
4944 style = gtk_widget_get_style(text);
4946 /* workaround for the slow down of GtkSText when using Pixmap theme */
4947 if (style->engine) {
4948 GtkThemeEngine *engine;
4950 engine = style->engine;
4951 style->engine = NULL;
4952 new_style = gtk_style_copy(style);
4953 style->engine = engine;
4955 new_style = gtk_style_copy(style);
4957 if (prefs_common.textfont) {
4960 if ((font = gtkut_font_load(prefs_common.textfont)) != NULL) {
4961 gdk_font_unref(new_style->font);
4962 new_style->font = font;
4966 gtk_widget_set_style(text, new_style);
4968 color[0] = quote_color;
4969 cmap = gdk_window_get_colormap(window->window);
4970 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4971 if (success[0] == FALSE) {
4972 g_warning("Compose: color allocation failed.\n");
4973 style = gtk_widget_get_style(text);
4974 quote_color = style->black;
4977 n_entries = sizeof(compose_popup_entries) /
4978 sizeof(compose_popup_entries[0]);
4979 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4980 "<Compose>", &popupfactory,
4983 ifactory = gtk_item_factory_from_widget(menubar);
4984 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4985 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4987 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4988 #if 0 /* NEW COMPOSE GUI */
4989 gtk_widget_hide(bcc_hbox);
4990 gtk_widget_hide(bcc_entry);
4991 gtk_widget_hide(reply_hbox);
4992 gtk_widget_hide(reply_entry);
4993 gtk_widget_hide(followup_hbox);
4994 gtk_widget_hide(followup_entry);
4995 gtk_widget_hide(ruler_hbox);
4996 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4997 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4998 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
5000 if (account->protocol == A_NNTP) {
5001 gtk_widget_hide(to_hbox);
5002 gtk_widget_hide(to_entry);
5003 gtk_widget_hide(cc_hbox);
5004 gtk_widget_hide(cc_entry);
5005 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
5006 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
5008 gtk_widget_hide(newsgroups_hbox);
5009 gtk_widget_hide(newsgroups_entry);
5010 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
5014 action_update_compose_menu(ifactory, compose);
5017 undostruct = undo_init(text);
5018 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5021 address_completion_start(window);
5023 compose->window = window;
5024 compose->vbox = vbox;
5025 compose->menubar = menubar;
5026 compose->handlebox = handlebox;
5028 compose->vbox2 = vbox2;
5030 compose->paned = paned;
5032 compose->edit_vbox = edit_vbox;
5033 compose->ruler_hbox = ruler_hbox;
5034 compose->ruler = ruler;
5035 compose->scrolledwin = scrolledwin;
5036 compose->text = text;
5038 compose->focused_editable = NULL;
5040 compose->popupmenu = popupmenu;
5041 compose->popupfactory = popupfactory;
5043 compose->tmpl_menu = tmpl_menu;
5045 compose->mode = mode;
5047 compose->targetinfo = NULL;
5048 compose->replyinfo = NULL;
5049 compose->fwdinfo = NULL;
5051 compose->replyto = NULL;
5053 compose->bcc = NULL;
5054 compose->followup_to = NULL;
5056 compose->ml_post = NULL;
5058 compose->inreplyto = NULL;
5059 compose->references = NULL;
5060 compose->msgid = NULL;
5061 compose->boundary = NULL;
5064 compose->use_signing = FALSE;
5065 compose->use_encryption = FALSE;
5066 #endif /* USE_GPGME */
5068 compose->modified = FALSE;
5070 compose->return_receipt = FALSE;
5072 compose->to_list = NULL;
5073 compose->newsgroup_list = NULL;
5075 compose->undostruct = undostruct;
5077 compose->sig_str = NULL;
5079 compose->exteditor_file = NULL;
5080 compose->exteditor_pid = -1;
5081 compose->exteditor_readdes = -1;
5082 compose->exteditor_tag = -1;
5085 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5086 if (mode != COMPOSE_REDIRECT) {
5087 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5088 strcmp(prefs_common.dictionary, _("None"))) {
5089 gtkaspell = gtkaspell_new((const gchar*)prefs_common.dictionary,
5090 conv_get_current_charset_str(),
5091 prefs_common.misspelled_col,
5092 prefs_common.check_while_typing,
5093 prefs_common.use_alternate,
5096 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkaspellcheckers->error_message);
5097 gtkaspell_checkers_reset_error();
5100 GtkWidget *menuitem;
5102 if (!gtkaspell_set_sug_mode(gtkaspell, prefs_common.aspell_sugmode)) {
5103 debug_print("Aspell: could not set suggestion mode %s\n",
5104 gtkaspellcheckers->error_message);
5105 gtkaspell_checkers_reset_error();
5108 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
5109 gtkaspell_populate_submenu(gtkaspell, menuitem);
5110 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5116 compose_select_account(compose, account, TRUE);
5119 compose->gtkaspell = gtkaspell;
5122 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5123 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5125 if (account->set_autobcc)
5126 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5128 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5129 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5132 if (account->protocol != A_NNTP)
5133 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5135 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5137 addressbook_set_target_compose(compose);
5138 action_update_compose_menu(ifactory, compose);
5140 if (mode != COMPOSE_REDIRECT)
5141 compose_set_template_menu(compose);
5143 GtkWidget *menuitem;
5144 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5145 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5148 compose_list = g_list_append(compose_list, compose);
5150 if (!prefs_common.show_ruler)
5151 gtk_widget_hide(ruler_hbox);
5154 compose->priority = PRIORITY_NORMAL;
5155 compose_update_priority_menu_item(compose);
5158 activate_gnupg_mode(compose, account);
5160 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5161 gtk_widget_show(window);
5166 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5172 gint num = 0, def_menu = 0;
5174 accounts = account_get_list();
5175 g_return_val_if_fail(accounts != NULL, NULL);
5177 hbox = gtk_hbox_new(FALSE, 0);
5178 optmenu = gtk_option_menu_new();
5179 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5180 menu = gtk_menu_new();
5182 for (; accounts != NULL; accounts = accounts->next, num++) {
5183 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5184 GtkWidget *menuitem;
5187 if (ac == compose->account) def_menu = num;
5190 name = g_strdup_printf("%s: %s <%s>",
5192 ac->name, ac->address);
5194 name = g_strdup_printf("%s: %s",
5195 ac->account_name, ac->address);
5196 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5198 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
5199 GTK_SIGNAL_FUNC(account_activated),
5203 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5204 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5209 static void compose_set_priority_cb(gpointer data,
5213 Compose *compose = (Compose *) data;
5214 compose->priority = action;
5217 static void compose_update_priority_menu_item(Compose * compose)
5219 GtkItemFactory *ifactory;
5220 GtkWidget *menuitem = NULL;
5222 ifactory = gtk_item_factory_from_widget(compose->menubar);
5224 switch (compose->priority) {
5225 case PRIORITY_HIGHEST:
5226 menuitem = gtk_item_factory_get_item
5227 (ifactory, "/Message/Priority/Highest");
5230 menuitem = gtk_item_factory_get_item
5231 (ifactory, "/Message/Priority/High");
5233 case PRIORITY_NORMAL:
5234 menuitem = gtk_item_factory_get_item
5235 (ifactory, "/Message/Priority/Normal");
5238 menuitem = gtk_item_factory_get_item
5239 (ifactory, "/Message/Priority/Low");
5241 case PRIORITY_LOWEST:
5242 menuitem = gtk_item_factory_get_item
5243 (ifactory, "/Message/Priority/Lowest");
5246 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5250 static void compose_set_gnupg_mode_cb(gpointer data,
5254 Compose *compose = (Compose *) data;
5255 compose->gnupg_mode = action;
5258 static void compose_update_gnupg_mode_menu_item(Compose * compose)
5260 GtkItemFactory *ifactory;
5261 GtkWidget *menuitem = NULL;
5263 ifactory = gtk_item_factory_from_widget(compose->menubar);
5265 switch (compose->gnupg_mode) {
5266 case GNUPG_MODE_DETACH:
5267 menuitem = gtk_item_factory_get_item
5268 (ifactory, "/Message/Mode/MIME");
5270 case GNUPG_MODE_INLINE:
5271 menuitem = gtk_item_factory_get_item
5272 (ifactory, "/Message/Mode/Inline");
5275 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5277 if (compose->use_encryption == TRUE || compose->use_signing == TRUE)
5278 menu_set_sensitive(ifactory, "/Message/Mode", TRUE);
5280 menu_set_sensitive(ifactory, "/Message/Mode", FALSE);
5284 static void compose_set_template_menu(Compose *compose)
5286 GSList *tmpl_list, *cur;
5290 tmpl_list = template_get_config();
5292 menu = gtk_menu_new();
5294 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5295 Template *tmpl = (Template *)cur->data;
5297 item = gtk_menu_item_new_with_label(tmpl->name);
5298 gtk_menu_append(GTK_MENU(menu), item);
5299 gtk_signal_connect(GTK_OBJECT(item), "activate",
5300 GTK_SIGNAL_FUNC(compose_template_activate_cb),
5302 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
5303 gtk_widget_show(item);
5306 gtk_widget_show(menu);
5307 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5310 void compose_reflect_prefs_all(void)
5315 for (cur = compose_list; cur != NULL; cur = cur->next) {
5316 compose = (Compose *)cur->data;
5317 compose_set_template_menu(compose);
5321 void compose_reflect_prefs_pixmap_theme(void)
5326 for (cur = compose_list; cur != NULL; cur = cur->next) {
5327 compose = (Compose *)cur->data;
5328 toolbar_update(TOOLBAR_COMPOSE, compose);
5332 static void compose_template_apply(Compose *compose, Template *tmpl,
5338 if (!tmpl || !tmpl->value) return;
5340 gtk_stext_freeze(GTK_STEXT(compose->text));
5342 if (tmpl->subject && *tmpl->subject != '\0')
5343 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5345 if (tmpl->to && *tmpl->to != '\0')
5346 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5347 if (tmpl->cc && *tmpl->cc != '\0')
5348 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5350 if (tmpl->bcc && *tmpl->bcc != '\0')
5351 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5354 gtkut_stext_clear(GTK_STEXT(compose->text));
5356 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
5357 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5360 if (prefs_common.quotemark && *prefs_common.quotemark)
5361 qmark = prefs_common.quotemark;
5365 if (compose->replyinfo != NULL)
5366 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5367 tmpl->value, qmark, NULL);
5368 else if (compose->fwdinfo != NULL)
5369 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
5370 tmpl->value, qmark, NULL);
5375 if (replace && parsed_str && compose->account->auto_sig)
5376 compose_insert_sig(compose, FALSE);
5378 if (replace && parsed_str) {
5379 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
5380 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
5384 compose_changed_cb(NULL, compose);
5386 gtk_stext_thaw(GTK_STEXT(compose->text));
5389 static void compose_destroy(Compose *compose)
5392 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5395 /* NOTE: address_completion_end() does nothing with the window
5396 * however this may change. */
5397 address_completion_end(compose->window);
5399 slist_free_strings(compose->to_list);
5400 g_slist_free(compose->to_list);
5401 slist_free_strings(compose->newsgroup_list);
5402 g_slist_free(compose->newsgroup_list);
5403 slist_free_strings(compose->header_list);
5404 g_slist_free(compose->header_list);
5406 procmsg_msginfo_free(compose->targetinfo);
5407 procmsg_msginfo_free(compose->replyinfo);
5408 procmsg_msginfo_free(compose->fwdinfo);
5410 g_free(compose->replyto);
5411 g_free(compose->cc);
5412 g_free(compose->bcc);
5413 g_free(compose->newsgroups);
5414 g_free(compose->followup_to);
5416 g_free(compose->ml_post);
5418 g_free(compose->inreplyto);
5419 g_free(compose->references);
5420 g_free(compose->msgid);
5421 g_free(compose->boundary);
5423 if (compose->redirect_filename)
5424 g_free(compose->redirect_filename);
5425 if (compose->undostruct)
5426 undo_destroy(compose->undostruct);
5428 g_free(compose->sig_str);
5430 g_free(compose->exteditor_file);
5432 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5434 compose_attach_info_free(ainfo);
5436 if (addressbook_get_target_compose() == compose)
5437 addressbook_set_target_compose(NULL);
5440 if (compose->gtkaspell) {
5441 gtkaspell_delete(compose->gtkaspell);
5445 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5446 prefs_common.compose_height = compose->window->allocation.height;
5448 gtk_widget_destroy(compose->paned);
5450 toolbar_destroy(compose->toolbar);
5451 g_free(compose->toolbar);
5454 compose_list = g_list_remove(compose_list, compose);
5457 static void compose_attach_info_free(AttachInfo *ainfo)
5459 g_free(ainfo->file);
5460 g_free(ainfo->content_type);
5461 g_free(ainfo->name);
5465 static void compose_attach_remove_selected(Compose *compose)
5467 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5471 while (clist->selection != NULL) {
5472 row = GPOINTER_TO_INT(clist->selection->data);
5473 ainfo = gtk_clist_get_row_data(clist, row);
5474 compose_attach_info_free(ainfo);
5475 gtk_clist_remove(clist, row);
5479 static struct _AttachProperty
5482 GtkWidget *mimetype_entry;
5483 GtkWidget *encoding_optmenu;
5484 GtkWidget *path_entry;
5485 GtkWidget *filename_entry;
5487 GtkWidget *cancel_btn;
5490 static void compose_attach_property(Compose *compose)
5492 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5495 GtkOptionMenu *optmenu;
5496 static gboolean cancelled;
5498 if (!clist->selection) return;
5499 row = GPOINTER_TO_INT(clist->selection->data);
5501 ainfo = gtk_clist_get_row_data(clist, row);
5504 if (!attach_prop.window)
5505 compose_attach_property_create(&cancelled);
5506 gtk_widget_grab_focus(attach_prop.ok_btn);
5507 gtk_widget_show(attach_prop.window);
5508 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5510 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5511 if (ainfo->encoding == ENC_UNKNOWN)
5512 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5513 GINT_TO_POINTER(ENC_BASE64));
5515 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5516 GINT_TO_POINTER(ainfo->encoding));
5518 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5519 ainfo->content_type ? ainfo->content_type : "");
5520 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5521 ainfo->file ? ainfo->file : "");
5522 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5523 ainfo->name ? ainfo->name : "");
5527 gchar *cnttype = NULL;
5531 GtkWidget *menuitem;
5536 if (cancelled == TRUE) {
5537 gtk_widget_hide(attach_prop.window);
5541 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5542 if (*text != '\0') {
5545 text = g_strstrip(g_strdup(text));
5546 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5547 cnttype = g_strdup(text);
5550 alertpanel_error(_("Invalid MIME type."));
5556 menu = gtk_option_menu_get_menu(optmenu);
5557 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5558 ainfo->encoding = GPOINTER_TO_INT
5559 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5561 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5562 if (*text != '\0') {
5563 if (is_file_exist(text) &&
5564 (size = get_file_size(text)) > 0)
5565 file = g_strdup(text);
5568 (_("File doesn't exist or is empty."));
5574 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5575 if (*text != '\0') {
5576 g_free(ainfo->name);
5577 ainfo->name = g_strdup(text);
5581 g_free(ainfo->content_type);
5582 ainfo->content_type = cnttype;
5585 g_free(ainfo->file);
5591 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5592 ainfo->content_type);
5593 gtk_clist_set_text(clist, row, COL_SIZE,
5594 to_human_readable(ainfo->size));
5595 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5597 gtk_widget_hide(attach_prop.window);
5602 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5604 label = gtk_label_new(str); \
5605 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5606 GTK_FILL, 0, 0, 0); \
5607 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5609 entry = gtk_entry_new(); \
5610 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5611 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5614 static void compose_attach_property_create(gboolean *cancelled)
5620 GtkWidget *mimetype_entry;
5623 GtkWidget *optmenu_menu;
5624 GtkWidget *menuitem;
5625 GtkWidget *path_entry;
5626 GtkWidget *filename_entry;
5629 GtkWidget *cancel_btn;
5630 GList *mime_type_list, *strlist;
5632 debug_print("Creating attach_property window...\n");
5634 window = gtk_window_new(GTK_WINDOW_DIALOG);
5635 gtk_widget_set_usize(window, 480, -1);
5636 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5637 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
5638 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5639 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5640 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5641 GTK_SIGNAL_FUNC(attach_property_delete_event),
5643 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5644 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5647 vbox = gtk_vbox_new(FALSE, 8);
5648 gtk_container_add(GTK_CONTAINER(window), vbox);
5650 table = gtk_table_new(4, 2, FALSE);
5651 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5652 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5653 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5655 label = gtk_label_new(_("MIME type"));
5656 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5658 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5659 mimetype_entry = gtk_combo_new();
5660 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5661 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5663 /* stuff with list */
5664 mime_type_list = procmime_get_mime_type_list();
5666 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5667 MimeType *type = (MimeType *) mime_type_list->data;
5668 strlist = g_list_append(strlist,
5669 g_strdup_printf("%s/%s",
5670 type->type, type->sub_type));
5673 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5675 for (mime_type_list = strlist; mime_type_list != NULL;
5676 mime_type_list = mime_type_list->next)
5677 g_free(mime_type_list->data);
5678 g_list_free(strlist);
5680 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5682 label = gtk_label_new(_("Encoding"));
5683 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5685 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5687 hbox = gtk_hbox_new(FALSE, 0);
5688 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5689 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5691 optmenu = gtk_option_menu_new();
5692 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5694 optmenu_menu = gtk_menu_new();
5695 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5696 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5698 gtk_widget_set_sensitive(menuitem, FALSE);
5700 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5701 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5703 gtk_widget_set_sensitive(menuitem, FALSE);
5705 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
5706 ENC_QUOTED_PRINTABLE);
5707 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5709 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5711 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5713 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5714 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5716 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5717 &cancel_btn, _("Cancel"), NULL, NULL);
5718 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5719 gtk_widget_grab_default(ok_btn);
5721 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5722 GTK_SIGNAL_FUNC(attach_property_ok),
5724 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5725 GTK_SIGNAL_FUNC(attach_property_cancel),
5728 gtk_widget_show_all(vbox);
5730 attach_prop.window = window;
5731 attach_prop.mimetype_entry = mimetype_entry;
5732 attach_prop.encoding_optmenu = optmenu;
5733 attach_prop.path_entry = path_entry;
5734 attach_prop.filename_entry = filename_entry;
5735 attach_prop.ok_btn = ok_btn;
5736 attach_prop.cancel_btn = cancel_btn;
5739 #undef SET_LABEL_AND_ENTRY
5741 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5747 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5753 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5754 gboolean *cancelled)
5762 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5763 gboolean *cancelled)
5765 if (event && event->keyval == GDK_Escape) {
5771 static void compose_exec_ext_editor(Compose *compose)
5777 tmp = g_strdup_printf("%s%ctmpmsg.%08x", get_tmp_dir(),
5778 G_DIR_SEPARATOR, (gint)compose);
5780 if (pipe(pipe_fds) < 0) {
5786 if ((pid = fork()) < 0) {
5793 /* close the write side of the pipe */
5796 compose->exteditor_file = g_strdup(tmp);
5797 compose->exteditor_pid = pid;
5798 compose->exteditor_readdes = pipe_fds[0];
5800 compose_set_ext_editor_sensitive(compose, FALSE);
5802 compose->exteditor_tag =
5803 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5804 compose_input_cb, compose);
5805 } else { /* process-monitoring process */
5811 /* close the read side of the pipe */
5814 if (compose_write_body_to_file(compose, tmp) < 0) {
5815 fd_write_all(pipe_fds[1], "2\n", 2);
5819 pid_ed = compose_exec_ext_editor_real(tmp);
5821 fd_write_all(pipe_fds[1], "1\n", 2);
5825 /* wait until editor is terminated */
5826 waitpid(pid_ed, NULL, 0);
5828 fd_write_all(pipe_fds[1], "0\n", 2);
5837 static gint compose_exec_ext_editor_real(const gchar *file)
5839 static gchar *def_cmd = "emacs %s";
5845 g_return_val_if_fail(file != NULL, -1);
5847 if ((pid = fork()) < 0) {
5852 if (pid != 0) return pid;
5854 /* grandchild process */
5856 if (setpgid(0, getppid()))
5859 if (prefs_common.ext_editor_cmd &&
5860 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5861 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5862 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5864 if (prefs_common.ext_editor_cmd)
5865 g_warning("External editor command line is invalid: `%s'\n",
5866 prefs_common.ext_editor_cmd);
5867 g_snprintf(buf, sizeof(buf), def_cmd, file);
5870 cmdline = strsplit_with_quote(buf, " ", 1024);
5871 execvp(cmdline[0], cmdline);
5874 g_strfreev(cmdline);
5879 static gboolean compose_ext_editor_kill(Compose *compose)
5881 pid_t pgid = compose->exteditor_pid * -1;
5884 ret = kill(pgid, 0);
5886 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5890 msg = g_strdup_printf
5891 (_("The external editor is still working.\n"
5892 "Force terminating the process?\n"
5893 "process group id: %d"), -pgid);
5894 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5897 if (val == G_ALERTDEFAULT) {
5898 gdk_input_remove(compose->exteditor_tag);
5899 close(compose->exteditor_readdes);
5901 if (kill(pgid, SIGTERM) < 0) perror("kill");
5902 waitpid(compose->exteditor_pid, NULL, 0);
5904 g_warning("Terminated process group id: %d", -pgid);
5905 g_warning("Temporary file: %s",
5906 compose->exteditor_file);
5908 compose_set_ext_editor_sensitive(compose, TRUE);
5910 g_free(compose->exteditor_file);
5911 compose->exteditor_file = NULL;
5912 compose->exteditor_pid = -1;
5913 compose->exteditor_readdes = -1;
5914 compose->exteditor_tag = -1;
5922 static void compose_input_cb(gpointer data, gint source,
5923 GdkInputCondition condition)
5926 Compose *compose = (Compose *)data;
5929 debug_print("Compose: input from monitoring process\n");
5931 gdk_input_remove(compose->exteditor_tag);
5934 if (read(source, &buf[i], 1) < 1) {
5938 if (buf[i] == '\n') {
5943 if (i == sizeof(buf) - 1)
5947 waitpid(compose->exteditor_pid, NULL, 0);
5949 if (buf[0] == '0') { /* success */
5950 GtkSText *text = GTK_STEXT(compose->text);
5952 gtk_stext_freeze(text);
5953 gtk_stext_set_point(text, 0);
5954 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5955 compose_insert_file(compose, compose->exteditor_file);
5956 compose_changed_cb(NULL, compose);
5957 gtk_stext_thaw(text);
5959 if (unlink(compose->exteditor_file) < 0)
5960 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5961 } else if (buf[0] == '1') { /* failed */
5962 g_warning("Couldn't exec external editor\n");
5963 if (unlink(compose->exteditor_file) < 0)
5964 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5965 } else if (buf[0] == '2') {
5966 g_warning("Couldn't write to file\n");
5967 } else if (buf[0] == '3') {
5968 g_warning("Pipe read failed\n");
5973 compose_set_ext_editor_sensitive(compose, TRUE);
5975 g_free(compose->exteditor_file);
5976 compose->exteditor_file = NULL;
5977 compose->exteditor_pid = -1;
5978 compose->exteditor_readdes = -1;
5979 compose->exteditor_tag = -1;
5982 static void compose_set_ext_editor_sensitive(Compose *compose,
5985 GtkItemFactory *ifactory;
5987 ifactory = gtk_item_factory_from_widget(compose->menubar);
5989 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5990 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5991 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5993 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5994 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5995 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5996 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5997 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6000 gtk_widget_set_sensitive(compose->text, sensitive);
6001 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6002 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6003 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6004 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6005 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6006 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6007 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
6011 * compose_undo_state_changed:
6013 * Change the sensivity of the menuentries undo and redo
6015 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6016 gint redo_state, gpointer data)
6018 GtkWidget *widget = GTK_WIDGET(data);
6019 GtkItemFactory *ifactory;
6021 g_return_if_fail(widget != NULL);
6023 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
6025 ifactory = gtk_item_factory_from_widget(widget);
6027 switch (undo_state) {
6028 case UNDO_STATE_TRUE:
6029 if (!undostruct->undo_state) {
6030 debug_print ("Set_undo - Testpoint\n");
6031 undostruct->undo_state = TRUE;
6032 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6035 case UNDO_STATE_FALSE:
6036 if (undostruct->undo_state) {
6037 undostruct->undo_state = FALSE;
6038 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6041 case UNDO_STATE_UNCHANGED:
6043 case UNDO_STATE_REFRESH:
6044 menu_set_sensitive(ifactory, "/Edit/Undo",
6045 undostruct->undo_state);
6048 g_warning("Undo state not recognized");
6052 switch (redo_state) {
6053 case UNDO_STATE_TRUE:
6054 if (!undostruct->redo_state) {
6055 undostruct->redo_state = TRUE;
6056 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6059 case UNDO_STATE_FALSE:
6060 if (undostruct->redo_state) {
6061 undostruct->redo_state = FALSE;
6062 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6065 case UNDO_STATE_UNCHANGED:
6067 case UNDO_STATE_REFRESH:
6068 menu_set_sensitive(ifactory, "/Edit/Redo",
6069 undostruct->redo_state);
6072 g_warning("Redo state not recognized");
6077 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
6081 cursor_pos = (text->cursor_pos_x - extra) / char_width;
6082 cursor_pos = MAX(cursor_pos, 0);
6087 /* callback functions */
6089 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6090 * includes "non-client" (windows-izm) in calculation, so this calculation
6091 * may not be accurate.
6093 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6094 GtkAllocation *allocation,
6095 GtkSHRuler *shruler)
6097 if (prefs_common.show_ruler) {
6099 gint line_width_in_chars;
6101 char_width = gtkut_get_font_width
6102 (GTK_WIDGET(widget)->style->font);
6103 line_width_in_chars =
6104 (allocation->width - allocation->x) / char_width;
6106 /* got the maximum */
6107 gtk_ruler_set_range(GTK_RULER(shruler),
6108 0.0, line_width_in_chars,
6109 calc_cursor_xpos(GTK_STEXT(widget),
6112 /*line_width_in_chars*/ char_width);
6118 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6120 Compose *compose = (Compose *)data;
6124 ac = account_find_from_id(
6125 GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menuitem))));
6126 g_return_if_fail(ac != NULL);
6128 if (ac != compose->account)
6129 compose_select_account(compose, ac, FALSE);
6132 static void attach_selected(GtkCList *clist, gint row, gint column,
6133 GdkEvent *event, gpointer data)
6135 Compose *compose = (Compose *)data;
6137 if (event && event->type == GDK_2BUTTON_PRESS)
6138 compose_attach_property(compose);
6141 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6144 Compose *compose = (Compose *)data;
6145 GtkCList *clist = GTK_CLIST(compose->attach_clist);
6150 if (event->button == 3) {
6151 if ((clist->selection && !clist->selection->next) ||
6152 !clist->selection) {
6153 gtk_clist_unselect_all(clist);
6154 if (gtk_clist_get_selection_info(clist,
6157 gtk_clist_select_row(clist, row, column);
6158 gtkut_clist_set_focus_row(clist, row);
6161 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6162 NULL, NULL, event->button, event->time);
6166 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6169 Compose *compose = (Compose *)data;
6173 switch (event->keyval) {
6175 compose_attach_remove_selected(compose);
6180 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6182 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6183 toolbar_comp_set_sensitive(compose, allow);
6184 menu_set_sensitive(ifactory, "/File", allow);
6185 menu_set_sensitive(ifactory, "/Edit", allow);
6186 menu_set_sensitive(ifactory, "/Spelling", allow);
6187 menu_set_sensitive(ifactory, "/Message", allow);
6188 menu_set_sensitive(ifactory, "/Tools", allow);
6189 menu_set_sensitive(ifactory, "/Help", allow);
6192 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6194 Compose *compose = (Compose *)data;
6197 if (prefs_common.work_offline)
6198 if (alertpanel(_("Offline warning"),
6199 _("You're working offline. Override?"),
6200 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
6203 compose_allow_user_actions (compose, FALSE);
6204 compose->sending = TRUE;
6205 val = compose_send(compose);
6206 compose_allow_user_actions (compose, TRUE);
6207 compose->sending = FALSE;
6209 if (val == 0) gtk_widget_destroy(compose->window);
6212 static void compose_send_later_cb(gpointer data, guint action,
6215 Compose *compose = (Compose *)data;
6218 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6219 if (!val) gtk_widget_destroy(compose->window);
6222 void compose_draft (gpointer data)
6224 compose_draft_cb(data, 0, NULL);
6227 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6229 Compose *compose = (Compose *)data;
6233 static gboolean lock = FALSE;
6234 MsgInfo *newmsginfo;
6238 draft = account_get_special_folder(compose->account, F_DRAFT);
6239 g_return_if_fail(draft != NULL);
6243 tmp = g_strdup_printf("%s%cdraft.%08x", get_tmp_dir(),
6244 G_DIR_SEPARATOR, (gint)compose);
6246 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
6252 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) < 0) {
6259 draft->mtime = 0; /* force updating */
6261 if (compose->mode == COMPOSE_REEDIT) {
6262 compose_remove_reedit_target(compose);
6265 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6267 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6268 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
6269 procmsg_msginfo_free(newmsginfo);
6274 /* 0: quit editing 1: keep editing 2: keep editing (autosave) */
6276 gtk_widget_destroy(compose->window);
6281 path = folder_item_fetch_msg(draft, msgnum);
6282 g_return_if_fail(path != NULL);
6283 if (stat(path, &s) < 0) {
6284 FILE_OP_ERROR(path, "stat");
6291 procmsg_msginfo_free(compose->targetinfo);
6292 compose->targetinfo = procmsg_msginfo_new();
6293 compose->targetinfo->msgnum = msgnum;
6294 compose->targetinfo->size = s.st_size;
6295 compose->targetinfo->mtime = s.st_mtime;
6296 compose->targetinfo->folder = draft;
6297 compose->mode = COMPOSE_REEDIT;
6300 compose->autosaved_draft = compose->targetinfo;
6305 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6307 Compose *compose = (Compose *)data;
6310 if (compose->redirect_filename != NULL)
6313 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6318 for ( tmp = file_list; tmp; tmp = tmp->next) {
6319 gchar *file = (gchar *) tmp->data;
6320 compose_attach_append(compose, file, file, NULL);
6321 compose_changed_cb(NULL, compose);
6324 g_list_free(file_list);
6328 static void compose_insert_file_cb(gpointer data, guint action,
6331 Compose *compose = (Compose *)data;
6334 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6339 for ( tmp = file_list; tmp; tmp = tmp->next) {
6340 gchar *file = (gchar *) tmp->data;
6341 compose_insert_file(compose, file);
6344 g_list_free(file_list);
6348 static void compose_insert_sig_cb(gpointer data, guint action,
6351 Compose *compose = (Compose *)data;
6353 compose_insert_sig(compose, FALSE);
6356 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6359 Compose *compose = (Compose *)data;
6360 if (compose->sending)
6362 compose_close_cb(compose, 0, NULL);
6366 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6368 Compose *compose = (Compose *)data;
6371 if (compose->exteditor_tag != -1) {
6372 if (!compose_ext_editor_kill(compose))
6376 if (compose->modified) {
6377 val = alertpanel(_("Discard message"),
6378 _("This message has been modified. discard it?"),
6379 _("Discard"), _("to Draft"), _("Cancel"));
6382 case G_ALERTDEFAULT:
6383 if (prefs_common.autosave)
6384 compose_remove_draft(compose);
6386 case G_ALERTALTERNATE:
6387 compose_draft_cb(data, 0, NULL);
6394 gtk_widget_destroy(compose->window);
6397 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6399 Compose *compose = (Compose *)data;
6401 addressbook_open(compose);
6404 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6406 Compose *compose = (Compose *)data;
6411 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6412 g_return_if_fail(tmpl != NULL);
6414 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6416 val = alertpanel(_("Apply template"), msg,
6417 _("Replace"), _("Insert"), _("Cancel"));
6420 if (val == G_ALERTDEFAULT)
6421 compose_template_apply(compose, tmpl, TRUE);
6422 else if (val == G_ALERTALTERNATE)
6423 compose_template_apply(compose, tmpl, FALSE);
6426 static void compose_ext_editor_cb(gpointer data, guint action,
6429 Compose *compose = (Compose *)data;
6431 compose_exec_ext_editor(compose);
6434 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6436 if (compose->sending)
6438 compose_destroy(compose);
6441 static void compose_undo_cb(Compose *compose)
6443 undo_undo(compose->undostruct);
6446 static void compose_redo_cb(Compose *compose)
6448 undo_redo(compose->undostruct);
6451 static void compose_cut_cb(Compose *compose)
6453 if (compose->focused_editable &&
6454 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6455 gtk_editable_cut_clipboard
6456 (GTK_EDITABLE(compose->focused_editable));
6459 static void compose_copy_cb(Compose *compose)
6461 if (compose->focused_editable &&
6462 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6463 gtk_editable_copy_clipboard
6464 (GTK_EDITABLE(compose->focused_editable));
6467 static void compose_paste_cb(Compose *compose)
6469 if (compose->focused_editable &&
6470 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6471 gtk_editable_paste_clipboard
6472 (GTK_EDITABLE(compose->focused_editable));
6475 static void compose_paste_as_quote_cb(Compose *compose)
6477 if (compose->focused_editable &&
6478 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6479 /* let text_insert() (called directly or at a later time
6480 * after the gtk_editable_paste_clipboard) know that
6481 * text is to be inserted as a quotation. implemented
6482 * by using a simple refcount... */
6483 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data(
6484 GTK_OBJECT(compose->focused_editable),
6485 "paste_as_quotation"));
6486 gtk_object_set_data(GTK_OBJECT(compose->focused_editable),
6487 "paste_as_quotation",
6488 GINT_TO_POINTER(paste_as_quotation + 1));
6489 gtk_editable_paste_clipboard
6490 (GTK_EDITABLE(compose->focused_editable));
6494 static void compose_allsel_cb(Compose *compose)
6496 if (compose->focused_editable &&
6497 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6498 gtk_editable_select_region
6499 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6502 static void compose_gtk_stext_action_cb(Compose *compose,
6503 ComposeCallGtkSTextAction action)
6505 GtkSText *text = GTK_STEXT(compose->text);
6507 void (*do_action) (GtkSText *text);
6508 } action_table[] = {
6509 {gtk_stext_move_beginning_of_line},
6510 {gtk_stext_move_forward_character},
6511 {gtk_stext_move_backward_character},
6512 {gtk_stext_move_forward_word},
6513 {gtk_stext_move_backward_word},
6514 {gtk_stext_move_end_of_line},
6515 {gtk_stext_move_next_line},
6516 {gtk_stext_move_previous_line},
6517 {gtk_stext_delete_forward_character},
6518 {gtk_stext_delete_backward_character},
6519 {gtk_stext_delete_forward_word},
6520 {gtk_stext_delete_backward_word},
6521 {gtk_stext_delete_line},
6522 {gtk_stext_delete_line}, /* gtk_stext_delete_line_n */
6523 {gtk_stext_delete_to_line_end}
6526 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
6528 if (action >= COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE &&
6529 action <= COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END)
6530 action_table[action].do_action(text);
6533 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6535 if (GTK_IS_EDITABLE(widget))
6536 compose->focused_editable = widget;
6539 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6541 if (compose->modified == FALSE) {
6542 compose->modified = TRUE;
6543 compose_set_title(compose);
6547 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6550 gtk_stext_set_point(GTK_STEXT(widget),
6551 gtk_editable_get_position(GTK_EDITABLE(widget)));
6555 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6558 gtk_stext_set_point(GTK_STEXT(widget),
6559 gtk_editable_get_position(GTK_EDITABLE(widget)));
6563 #if 0 /* NEW COMPOSE GUI */
6564 static void compose_toggle_to_cb(gpointer data, guint action,
6567 Compose *compose = (Compose *)data;
6569 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6570 gtk_widget_show(compose->to_hbox);
6571 gtk_widget_show(compose->to_entry);
6572 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6573 compose->use_to = TRUE;
6575 gtk_widget_hide(compose->to_hbox);
6576 gtk_widget_hide(compose->to_entry);
6577 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6578 gtk_widget_queue_resize(compose->table_vbox);
6579 compose->use_to = FALSE;
6582 if (addressbook_get_target_compose() == compose)
6583 addressbook_set_target_compose(compose);
6586 static void compose_toggle_cc_cb(gpointer data, guint action,
6589 Compose *compose = (Compose *)data;
6591 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6592 gtk_widget_show(compose->cc_hbox);
6593 gtk_widget_show(compose->cc_entry);
6594 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6595 compose->use_cc = TRUE;
6597 gtk_widget_hide(compose->cc_hbox);
6598 gtk_widget_hide(compose->cc_entry);
6599 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6600 gtk_widget_queue_resize(compose->table_vbox);
6601 compose->use_cc = FALSE;
6604 if (addressbook_get_target_compose() == compose)
6605 addressbook_set_target_compose(compose);
6608 static void compose_toggle_bcc_cb(gpointer data, guint action,
6611 Compose *compose = (Compose *)data;
6613 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6614 gtk_widget_show(compose->bcc_hbox);
6615 gtk_widget_show(compose->bcc_entry);
6616 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6617 compose->use_bcc = TRUE;
6619 gtk_widget_hide(compose->bcc_hbox);
6620 gtk_widget_hide(compose->bcc_entry);
6621 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6622 gtk_widget_queue_resize(compose->table_vbox);
6623 compose->use_bcc = FALSE;
6626 if (addressbook_get_target_compose() == compose)
6627 addressbook_set_target_compose(compose);
6630 static void compose_toggle_replyto_cb(gpointer data, guint action,
6633 Compose *compose = (Compose *)data;
6635 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6636 gtk_widget_show(compose->reply_hbox);
6637 gtk_widget_show(compose->reply_entry);
6638 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6639 compose->use_replyto = TRUE;
6641 gtk_widget_hide(compose->reply_hbox);
6642 gtk_widget_hide(compose->reply_entry);
6643 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6644 gtk_widget_queue_resize(compose->table_vbox);
6645 compose->use_replyto = FALSE;
6649 static void compose_toggle_followupto_cb(gpointer data, guint action,
6652 Compose *compose = (Compose *)data;
6654 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6655 gtk_widget_show(compose->followup_hbox);
6656 gtk_widget_show(compose->followup_entry);
6657 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6658 compose->use_followupto = TRUE;
6660 gtk_widget_hide(compose->followup_hbox);
6661 gtk_widget_hide(compose->followup_entry);
6662 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6663 gtk_widget_queue_resize(compose->table_vbox);
6664 compose->use_followupto = FALSE;
6668 static void compose_toggle_attach_cb(gpointer data, guint action,
6671 Compose *compose = (Compose *)data;
6673 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6674 gtk_widget_ref(compose->edit_vbox);
6676 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6677 compose->edit_vbox);
6678 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6679 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6681 gtk_widget_show(compose->paned);
6683 gtk_widget_unref(compose->edit_vbox);
6684 gtk_widget_unref(compose->paned);
6686 compose->use_attach = TRUE;
6688 gtk_widget_ref(compose->paned);
6689 gtk_widget_ref(compose->edit_vbox);
6691 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6693 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6694 compose->edit_vbox);
6695 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6696 compose->edit_vbox, TRUE, TRUE, 0);
6698 gtk_widget_unref(compose->edit_vbox);
6700 compose->use_attach = FALSE;
6706 static void compose_toggle_sign_cb(gpointer data, guint action,
6709 Compose *compose = (Compose *)data;
6711 if (GTK_CHECK_MENU_ITEM(widget)->active)
6712 compose->use_signing = TRUE;
6714 compose->use_signing = FALSE;
6716 compose_update_gnupg_mode_menu_item(compose);
6719 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6722 Compose *compose = (Compose *)data;
6724 if (GTK_CHECK_MENU_ITEM(widget)->active)
6725 compose->use_encryption = TRUE;
6727 compose->use_encryption = FALSE;
6729 compose_update_gnupg_mode_menu_item(compose);
6732 static void activate_gnupg_mode (Compose *compose, PrefsAccount *account)
6734 if (account->default_gnupg_mode)
6735 compose->gnupg_mode = GNUPG_MODE_INLINE;
6737 compose->gnupg_mode = GNUPG_MODE_DETACH;
6739 compose_update_gnupg_mode_menu_item(compose);
6741 #endif /* USE_GPGME */
6743 static void compose_toggle_ruler_cb(gpointer data, guint action,
6746 Compose *compose = (Compose *)data;
6748 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6749 gtk_widget_show(compose->ruler_hbox);
6750 prefs_common.show_ruler = TRUE;
6752 gtk_widget_hide(compose->ruler_hbox);
6753 gtk_widget_queue_resize(compose->edit_vbox);
6754 prefs_common.show_ruler = FALSE;
6758 static void compose_attach_drag_received_cb (GtkWidget *widget,
6759 GdkDragContext *drag_context,
6762 GtkSelectionData *data,
6767 Compose *compose = (Compose *)user_data;
6770 list = uri_list_extract_filenames((const gchar *)data->data);
6771 for (tmp = list; tmp != NULL; tmp = tmp->next)
6772 compose_attach_append
6773 (compose, (const gchar *)tmp->data,
6774 (const gchar *)tmp->data, NULL);
6775 if (list) compose_changed_cb(NULL, compose);
6776 list_free_strings(list);
6780 static void compose_insert_drag_received_cb (GtkWidget *widget,
6781 GdkDragContext *drag_context,
6784 GtkSelectionData *data,
6789 Compose *compose = (Compose *)user_data;
6792 list = uri_list_extract_filenames((const gchar *)data->data);
6793 for (tmp = list; tmp != NULL; tmp = tmp->next)
6794 compose_insert_file(compose, (const gchar *)tmp->data);
6795 list_free_strings(list);
6799 #if 0 /* NEW COMPOSE GUI */
6800 static void to_activated(GtkWidget *widget, Compose *compose)
6802 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6803 gtk_widget_grab_focus(compose->newsgroups_entry);
6805 gtk_widget_grab_focus(compose->subject_entry);
6808 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6810 gtk_widget_grab_focus(compose->subject_entry);
6813 static void subject_activated(GtkWidget *widget, Compose *compose)
6815 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6816 gtk_widget_grab_focus(compose->cc_entry);
6817 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6818 gtk_widget_grab_focus(compose->bcc_entry);
6819 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6820 gtk_widget_grab_focus(compose->reply_entry);
6821 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6822 gtk_widget_grab_focus(compose->followup_entry);
6824 gtk_widget_grab_focus(compose->text);
6827 static void cc_activated(GtkWidget *widget, Compose *compose)
6829 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6830 gtk_widget_grab_focus(compose->bcc_entry);
6831 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6832 gtk_widget_grab_focus(compose->reply_entry);
6833 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6834 gtk_widget_grab_focus(compose->followup_entry);
6836 gtk_widget_grab_focus(compose->text);
6839 static void bcc_activated(GtkWidget *widget, Compose *compose)
6841 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6842 gtk_widget_grab_focus(compose->reply_entry);
6843 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6844 gtk_widget_grab_focus(compose->followup_entry);
6846 gtk_widget_grab_focus(compose->text);
6849 static void replyto_activated(GtkWidget *widget, Compose *compose)
6851 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6852 gtk_widget_grab_focus(compose->followup_entry);
6854 gtk_widget_grab_focus(compose->text);
6857 static void followupto_activated(GtkWidget *widget, Compose *compose)
6859 gtk_widget_grab_focus(compose->text);
6863 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6866 Compose *compose = (Compose *)data;
6868 if (GTK_CHECK_MENU_ITEM(widget)->active)
6869 compose->return_receipt = TRUE;
6871 compose->return_receipt = FALSE;
6874 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6876 ComposeHeaderEntry *headerentry)
6878 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6879 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6880 !(event->state & GDK_MODIFIER_MASK) &&
6881 (event->keyval == GDK_BackSpace) &&
6882 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6883 gtk_container_remove
6884 (GTK_CONTAINER(headerentry->compose->header_table),
6885 headerentry->combo);
6886 gtk_container_remove
6887 (GTK_CONTAINER(headerentry->compose->header_table),
6888 headerentry->entry);
6889 headerentry->compose->header_list =
6890 g_slist_remove(headerentry->compose->header_list,
6892 g_free(headerentry);
6893 } else if (event->keyval == GDK_Tab) {
6894 if (headerentry->compose->header_last == headerentry) {
6895 /* Override default next focus, and give it to subject_entry
6896 * instead of notebook tabs
6898 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6899 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6905 void compose_headerentry_changed_cb(GtkWidget *entry,
6906 ComposeHeaderEntry *headerentry)
6908 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6909 headerentry->compose->header_list =
6910 g_slist_append(headerentry->compose->header_list,
6912 compose_create_header_entry(headerentry->compose);
6913 gtk_signal_disconnect_by_func
6915 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6917 /* Automatically scroll down */
6918 compose_show_first_last_header(headerentry->compose, FALSE);
6923 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6925 GtkAdjustment *vadj;
6927 g_return_if_fail(compose);
6928 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6929 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6931 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6932 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6935 static void text_activated(GtkWidget *widget, Compose *compose)
6937 compose_send_control_enter(compose);
6940 static void text_inserted(GtkWidget *widget, const gchar *text,
6941 gint length, gint *position, Compose *compose)
6943 GtkEditable *editable = GTK_EDITABLE(widget);
6944 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data
6945 (GTK_OBJECT(widget), "paste_as_quotation"));
6947 gtk_signal_handler_block_by_func(GTK_OBJECT(widget),
6948 GTK_SIGNAL_FUNC(text_inserted),
6950 if (paste_as_quotation) {
6955 new_text = g_strndup(text, length);
6956 if (prefs_common.quotemark && *prefs_common.quotemark)
6957 qmark = prefs_common.quotemark;
6960 gtk_stext_set_point(GTK_STEXT(widget), *position);
6961 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
6962 pos = gtk_stext_get_point(GTK_STEXT(widget));
6963 gtk_editable_set_position(editable, pos);
6966 gtk_object_set_data(GTK_OBJECT(widget), "paste_as_quotation",
6967 GINT_TO_POINTER(paste_as_quotation - 1));
6969 gtk_editable_insert_text(editable, text, length, position);
6971 if (prefs_common.autowrap)
6972 compose_wrap_line_all_full(compose, TRUE);
6974 gtk_signal_handler_unblock_by_func(GTK_OBJECT(widget),
6975 GTK_SIGNAL_FUNC(text_inserted),
6977 gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
6980 if (prefs_common.autosave &&
6981 gtk_stext_get_length(GTK_STEXT(widget)) % prefs_common.autosave_length == 0)
6982 compose_draft_cb((gpointer)compose, 2, NULL);
6985 static gboolean compose_send_control_enter(Compose *compose)
6989 GtkItemFactory *ifactory;
6990 GtkAccelEntry *accel;
6991 GtkWidget *send_menu;
6993 GdkModifierType ignored_mods =
6994 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
6995 GDK_MOD4_MASK | GDK_MOD5_MASK);
6997 ev = gtk_get_current_event();
6998 if (ev->type != GDK_KEY_PRESS) return FALSE;
7000 kev = (GdkEventKey *)ev;
7001 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
7004 ifactory = gtk_item_factory_from_widget(compose->menubar);
7005 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
7006 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
7010 accel = (GtkAccelEntry *)list->data;
7011 if (accel && accel->accelerator_key == kev->keyval &&
7012 (accel->accelerator_mods & ~ignored_mods) ==
7013 (kev->state & ~ignored_mods)) {
7014 compose_send_cb(compose, 0, NULL);
7022 static void compose_check_all(Compose *compose)
7024 if (compose->gtkaspell)
7025 gtkaspell_check_all(compose->gtkaspell);
7028 static void compose_highlight_all(Compose *compose)
7030 if (compose->gtkaspell)
7031 gtkaspell_highlight_all(compose->gtkaspell);
7034 static void compose_check_backwards(Compose *compose)
7036 if (compose->gtkaspell)
7037 gtkaspell_check_backwards(compose->gtkaspell);
7039 GtkItemFactory *ifactory;
7040 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7041 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7042 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
7046 static void compose_check_forwards_go(Compose *compose)
7048 if (compose->gtkaspell)
7049 gtkaspell_check_forwards_go(compose->gtkaspell);
7051 GtkItemFactory *ifactory;
7052 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7053 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7054 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);