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> */
67 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
74 #include "mainwindow.h"
77 #include "addressbook.h"
78 #include "folderview.h"
81 #include "stock_pixmap.h"
82 #include "send_message.h"
85 #include "customheader.h"
86 #include "prefs_common.h"
87 #include "prefs_account.h"
91 #include "procheader.h"
93 #include "statusbar.h"
96 #include "quoted-printable.h"
101 #include "alertpanel.h"
102 #include "manage_window.h"
103 #include "gtkshruler.h"
105 #include "addr_compl.h"
106 #include "quote_fmt.h"
107 #include "template.h"
109 #include "foldersel.h"
113 # include "rfc2015.h"
123 #define N_ATTACH_COLS 3
127 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
128 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
129 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
130 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
131 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
132 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
133 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
134 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
135 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
136 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
137 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
138 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
139 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
140 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
141 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
142 } ComposeCallGtkSTextAction;
146 PRIORITY_HIGHEST = 1,
155 COMPOSE_INSERT_SUCCESS,
156 COMPOSE_INSERT_READ_ERROR,
157 COMPOSE_INSERT_INVALID_CHARACTER,
158 COMPOSE_INSERT_NO_FILE
159 } ComposeInsertResult;
161 #define B64_LINE_SIZE 57
162 #define B64_BUFFSIZE 77
164 #define MAX_REFERENCES_LEN 999
166 static GdkColor quote_color = {0, 0, 0, 0xbfff};
168 static GList *compose_list = NULL;
170 Compose *compose_generic_new (PrefsAccount *account,
173 GPtrArray *attach_files);
175 static Compose *compose_create (PrefsAccount *account,
178 static GtkWidget *compose_account_option_menu_create
180 static void compose_set_template_menu (Compose *compose);
181 static void compose_template_apply (Compose *compose,
184 static void compose_destroy (Compose *compose);
186 static void compose_entries_set (Compose *compose,
187 const gchar *mailto);
188 static gint compose_parse_header (Compose *compose,
190 static gchar *compose_parse_references (const gchar *ref,
193 static gchar *compose_quote_fmt (Compose *compose,
199 static void compose_reply_set_entry (Compose *compose,
205 followup_and_reply_to);
206 static void compose_reedit_set_entry (Compose *compose,
208 static void compose_insert_sig (Compose *compose,
210 static gchar *compose_get_signature_str (Compose *compose);
211 static ComposeInsertResult compose_insert_file (Compose *compose,
213 static void compose_attach_append (Compose *compose,
216 const gchar *content_type);
217 static void compose_attach_parts (Compose *compose,
219 static void compose_wrap_line (Compose *compose);
220 static void compose_wrap_line_all (Compose *compose);
221 static void compose_wrap_line_all_full (Compose *compose,
223 static void compose_set_title (Compose *compose);
224 static void compose_select_account (Compose *compose,
225 PrefsAccount *account,
228 static PrefsAccount *compose_current_mail_account(void);
229 /* static gint compose_send (Compose *compose); */
230 static gboolean compose_check_for_valid_recipient
232 static gboolean compose_check_entries (Compose *compose,
233 gboolean check_subject);
234 static gint compose_write_to_file (Compose *compose,
237 static gint compose_write_body_to_file (Compose *compose,
239 static gint compose_remove_reedit_target (Compose *compose);
240 void compose_remove_draft (Compose *compose);
241 static gint compose_queue (Compose *compose,
244 static gint compose_queue_sub (Compose *compose,
247 gboolean check_subject);
248 static void compose_write_attach (Compose *compose,
250 static gint compose_write_headers (Compose *compose,
252 const gchar *charset,
253 EncodingType encoding,
256 static void compose_convert_header (gchar *dest,
260 gboolean addr_field);
261 static void compose_generate_msgid (gchar *buf,
264 static void compose_attach_info_free (AttachInfo *ainfo);
265 static void compose_attach_remove_selected (Compose *compose);
267 static void compose_attach_property (Compose *compose);
268 static void compose_attach_property_create (gboolean *cancelled);
269 static void attach_property_ok (GtkWidget *widget,
270 gboolean *cancelled);
271 static void attach_property_cancel (GtkWidget *widget,
272 gboolean *cancelled);
273 static gint attach_property_delete_event (GtkWidget *widget,
275 gboolean *cancelled);
276 static void attach_property_key_pressed (GtkWidget *widget,
278 gboolean *cancelled);
280 static void compose_exec_ext_editor (Compose *compose);
281 static gint compose_exec_ext_editor_real (const gchar *file);
282 static gboolean compose_ext_editor_kill (Compose *compose);
283 static void compose_input_cb (gpointer data,
285 GdkInputCondition condition);
286 static void compose_set_ext_editor_sensitive (Compose *compose,
289 static void compose_undo_state_changed (UndoMain *undostruct,
294 static gint calc_cursor_xpos (GtkSText *text,
298 static void compose_create_header_entry (Compose *compose);
299 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
300 static void compose_update_priority_menu_item(Compose * compose);
302 /* callback functions */
304 static gboolean compose_edit_size_alloc (GtkEditable *widget,
305 GtkAllocation *allocation,
306 GtkSHRuler *shruler);
307 static void account_activated (GtkMenuItem *menuitem,
309 static void attach_selected (GtkCList *clist,
314 static void attach_button_pressed (GtkWidget *widget,
315 GdkEventButton *event,
317 static void attach_key_pressed (GtkWidget *widget,
321 static void compose_send_cb (gpointer data,
324 static void compose_send_later_cb (gpointer data,
328 static void compose_draft_cb (gpointer data,
332 static void compose_attach_cb (gpointer data,
335 static void compose_insert_file_cb (gpointer data,
338 static void compose_insert_sig_cb (gpointer data,
342 static void compose_close_cb (gpointer data,
346 static void compose_address_cb (gpointer data,
349 static void compose_template_activate_cb(GtkWidget *widget,
352 static void compose_ext_editor_cb (gpointer data,
356 static gint compose_delete_cb (GtkWidget *widget,
359 static void compose_destroy_cb (GtkWidget *widget,
362 static void compose_undo_cb (Compose *compose);
363 static void compose_redo_cb (Compose *compose);
364 static void compose_cut_cb (Compose *compose);
365 static void compose_copy_cb (Compose *compose);
366 static void compose_paste_cb (Compose *compose);
367 static void compose_paste_as_quote_cb (Compose *compose);
368 static void compose_allsel_cb (Compose *compose);
370 static void compose_gtk_stext_action_cb (Compose *compose,
371 ComposeCallGtkSTextAction action);
373 static void compose_grab_focus_cb (GtkWidget *widget,
376 static void compose_changed_cb (GtkEditable *editable,
378 static void compose_button_press_cb (GtkWidget *widget,
379 GdkEventButton *event,
382 static void compose_key_press_cb (GtkWidget *widget,
388 static void compose_toggle_to_cb (gpointer data,
391 static void compose_toggle_cc_cb (gpointer data,
394 static void compose_toggle_bcc_cb (gpointer data,
397 static void compose_toggle_replyto_cb (gpointer data,
400 static void compose_toggle_followupto_cb(gpointer data,
403 static void compose_toggle_attach_cb (gpointer data,
407 static void compose_toggle_ruler_cb (gpointer data,
411 static void compose_toggle_sign_cb (gpointer data,
414 static void compose_toggle_encrypt_cb (gpointer data,
417 static void compose_set_gnupg_mode_cb (gpointer data,
420 static void compose_update_gnupg_mode_menu_item(Compose * compose);
421 static void activate_gnupg_mode (Compose *compose,
422 PrefsAccount *account);
424 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
426 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
428 static void compose_set_priority_cb (gpointer data,
432 static void compose_attach_drag_received_cb (GtkWidget *widget,
433 GdkDragContext *drag_context,
436 GtkSelectionData *data,
440 static void compose_insert_drag_received_cb (GtkWidget *widget,
441 GdkDragContext *drag_context,
444 GtkSelectionData *data,
450 static void to_activated (GtkWidget *widget,
452 static void newsgroups_activated (GtkWidget *widget,
454 static void cc_activated (GtkWidget *widget,
456 static void bcc_activated (GtkWidget *widget,
458 static void replyto_activated (GtkWidget *widget,
460 static void followupto_activated (GtkWidget *widget,
462 static void subject_activated (GtkWidget *widget,
466 static void text_activated (GtkWidget *widget,
468 static void text_inserted (GtkWidget *widget,
473 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
474 gboolean to_all, gboolean to_ml,
476 gboolean followup_and_reply_to,
479 void compose_headerentry_changed_cb (GtkWidget *entry,
480 ComposeHeaderEntry *headerentry);
481 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
483 ComposeHeaderEntry *headerentry);
484 static gboolean compose_headerentry_button_pressed (GtkWidget *entry,
485 GdkEventButton *event,
488 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
491 static void compose_check_all (Compose *compose);
492 static void compose_highlight_all (Compose *compose);
493 static void compose_check_backwards (Compose *compose);
494 static void compose_check_forwards_go (Compose *compose);
497 static gboolean compose_send_control_enter (Compose *compose);
498 static gint compose_defer_auto_save_draft (Compose *compose);
500 static GtkItemFactoryEntry compose_popup_entries[] =
502 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
503 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
504 {N_("/---"), NULL, NULL, 0, "<Separator>"},
505 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
508 static GtkItemFactoryEntry compose_entries[] =
510 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
511 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
512 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
513 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
514 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
515 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
517 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
518 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
519 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
520 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
521 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
522 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
523 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
524 {N_("/_Edit/Paste as _quotation"),
525 NULL, compose_paste_as_quote_cb, 0, NULL},
526 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
527 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
528 {N_("/_Edit/A_dvanced/Move a character backward"),
530 compose_gtk_stext_action_cb,
531 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
533 {N_("/_Edit/A_dvanced/Move a character forward"),
535 compose_gtk_stext_action_cb,
536 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
538 {N_("/_Edit/A_dvanced/Move a word backward"),
540 compose_gtk_stext_action_cb,
541 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
543 {N_("/_Edit/A_dvanced/Move a word forward"),
545 compose_gtk_stext_action_cb,
546 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
548 {N_("/_Edit/A_dvanced/Move to beginning of line"),
549 NULL, /* "<control>A" */
550 compose_gtk_stext_action_cb,
551 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
553 {N_("/_Edit/A_dvanced/Move to end of line"),
555 compose_gtk_stext_action_cb,
556 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
558 {N_("/_Edit/A_dvanced/Move to previous line"),
560 compose_gtk_stext_action_cb,
561 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
563 {N_("/_Edit/A_dvanced/Move to next line"),
565 compose_gtk_stext_action_cb,
566 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
568 {N_("/_Edit/A_dvanced/Delete a character backward"),
570 compose_gtk_stext_action_cb,
571 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
573 {N_("/_Edit/A_dvanced/Delete a character forward"),
575 compose_gtk_stext_action_cb,
576 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
578 {N_("/_Edit/A_dvanced/Delete a word backward"),
579 NULL, /* "<control>W" */
580 compose_gtk_stext_action_cb,
581 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
583 {N_("/_Edit/A_dvanced/Delete a word forward"),
584 NULL, /* "<alt>D", */
585 compose_gtk_stext_action_cb,
586 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
588 {N_("/_Edit/A_dvanced/Delete line"),
590 compose_gtk_stext_action_cb,
591 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
593 {N_("/_Edit/A_dvanced/Delete entire line"),
595 compose_gtk_stext_action_cb,
596 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
598 {N_("/_Edit/A_dvanced/Delete to end of line"),
600 compose_gtk_stext_action_cb,
601 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
603 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
604 {N_("/_Edit/_Wrap current paragraph"),
605 "<control>L", compose_wrap_line, 0, NULL},
606 {N_("/_Edit/Wrap all long _lines"),
607 "<control><alt>L", compose_wrap_line_all, 0, NULL},
608 {N_("/_Edit/Edit with e_xternal editor"),
609 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
611 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
612 {N_("/_Spelling/_Check all or check selection"),
613 NULL, compose_check_all, 0, NULL},
614 {N_("/_Spelling/_Highlight all misspelled words"),
615 NULL, compose_highlight_all, 0, NULL},
616 {N_("/_Spelling/Check _backwards misspelled word"),
617 NULL, compose_check_backwards , 0, NULL},
618 {N_("/_Spelling/_Forward to next misspelled word"),
619 NULL, compose_check_forwards_go, 0, NULL},
620 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
621 {N_("/_Spelling/_Spelling Configuration"),
622 NULL, NULL, 0, "<Branch>"},
624 #if 0 /* NEW COMPOSE GUI */
625 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
626 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
627 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
628 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
629 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
630 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
631 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
632 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
633 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
634 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
635 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
637 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
638 {N_("/_Message/_Send"), "<control>Return",
639 compose_send_cb, 0, NULL},
640 {N_("/_Message/Send _later"), "<shift><control>S",
641 compose_send_later_cb, 0, NULL},
642 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
643 {N_("/_Message/Save to _draft folder"),
644 "<shift><control>D", compose_draft_cb, 0, NULL},
645 {N_("/_Message/Save and _keep editing"),
646 "<control>S", compose_draft_cb, 1, NULL},
647 #if 0 /* NEW COMPOSE GUI */
648 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
649 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
650 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
651 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
652 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
653 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
654 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
655 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
656 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
659 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
660 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
661 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
662 {N_("/_Message/Mode/MIME"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_DETACH, "<RadioItem>"},
663 {N_("/_Message/Mode/Inline"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_INLINE, "/Message/Mode/MIME"},
664 #endif /* USE_GPGME */
665 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
666 {N_("/_Message/_Priority"), NULL, NULL, 0, "<Branch>"},
667 {N_("/_Message/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
668 {N_("/_Message/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
669 {N_("/_Message/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
670 {N_("/_Message/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
671 {N_("/_Message/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
672 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
673 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
674 {N_("/_Message/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
675 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
676 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
677 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
678 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
679 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
680 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
681 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
684 static GtkTargetEntry compose_mime_types[] =
686 {"text/uri-list", 0, 0}
689 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
690 GPtrArray *attach_files)
692 return compose_generic_new(account, mailto, NULL, attach_files);
695 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
697 return compose_generic_new(account, NULL, item, NULL);
700 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
701 GPtrArray *attach_files)
705 GtkItemFactory *ifactory;
706 gboolean grab_focus_on_last = TRUE;
708 if (item && item->prefs && item->prefs->enable_default_account)
709 account = account_find_from_id(item->prefs->default_account);
711 if (!account) account = cur_account;
712 g_return_val_if_fail(account != NULL, NULL);
714 compose = compose_create(account, COMPOSE_NEW);
715 ifactory = gtk_item_factory_from_widget(compose->menubar);
717 compose->replyinfo = NULL;
718 compose->fwdinfo = NULL;
720 text = GTK_STEXT(compose->text);
721 gtk_stext_freeze(text);
724 if (item && item->prefs && item->prefs->enable_default_dictionary &&
726 gtkaspell_change_dict(compose->gtkaspell,
727 item->prefs->default_dictionary);
730 if (account->auto_sig)
731 compose_insert_sig(compose, FALSE);
732 gtk_editable_set_position(GTK_EDITABLE(text), 0);
733 gtk_stext_set_point(text, 0);
735 gtk_stext_thaw(text);
737 if (account->protocol != A_NNTP) {
738 if (mailto && *mailto != '\0') {
739 compose_entries_set(compose, mailto);
741 } else if (item && item->prefs->enable_default_to) {
742 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
743 compose_entry_select(compose, item->prefs->default_to);
744 grab_focus_on_last = FALSE;
746 if (item && item->ret_rcpt) {
747 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
751 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
754 * CLAWS: just don't allow return receipt request, even if the user
755 * may want to send an email. simple but foolproof.
757 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
764 for (i = 0; i < attach_files->len; i++) {
765 file = g_ptr_array_index(attach_files, i);
766 compose_attach_append(compose, file, file, NULL);
770 compose_show_first_last_header(compose, TRUE);
772 /* Set save folder */
773 if (item && item->prefs && item->prefs->save_copy_to_folder) {
774 gchar *folderidentifier;
776 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
777 folderidentifier = folder_item_get_identifier(item);
778 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
779 g_free(folderidentifier);
782 /* Grab focus on last header only if no default_to was set */
783 if (grab_focus_on_last)
784 gtk_widget_grab_focus(compose->header_last->entry);
786 if (prefs_common.auto_exteditor)
787 compose_exec_ext_editor(compose);
793 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
794 const gchar *followupto, gchar * to)
798 if (!account) account = cur_account;
799 g_return_val_if_fail(account != NULL, NULL);
800 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
802 compose = compose_create(account, COMPOSE_NEW);
804 if (prefs_common.auto_sig)
805 compose_insert_sig(compose);
806 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
807 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
809 compose_entry_append(compose, to, COMPOSE_TO);
810 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
811 gtk_widget_grab_focus(compose->subject_entry);
817 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
822 g_return_if_fail(msginfo_list != NULL);
824 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
825 g_return_if_fail(msginfo != NULL);
827 list_len = g_slist_length(msginfo_list);
831 compose_reply(msginfo, prefs_common.reply_with_quote,
832 FALSE, prefs_common.default_reply_list, FALSE, body);
834 case COMPOSE_REPLY_WITH_QUOTE:
835 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
837 case COMPOSE_REPLY_WITHOUT_QUOTE:
838 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
840 case COMPOSE_REPLY_TO_SENDER:
841 compose_reply(msginfo, prefs_common.reply_with_quote,
842 FALSE, FALSE, TRUE, body);
844 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
845 compose_followup_and_reply_to(msginfo,
846 prefs_common.reply_with_quote,
849 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
850 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
852 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
853 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
855 case COMPOSE_REPLY_TO_ALL:
856 compose_reply(msginfo, prefs_common.reply_with_quote,
857 TRUE, FALSE, FALSE, body);
859 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
860 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
862 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
863 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
865 case COMPOSE_REPLY_TO_LIST:
866 compose_reply(msginfo, prefs_common.reply_with_quote,
867 FALSE, TRUE, FALSE, body);
869 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
870 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
872 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
873 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
875 case COMPOSE_FORWARD:
876 if (prefs_common.forward_as_attachment) {
877 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
880 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
884 case COMPOSE_FORWARD_INLINE:
885 /* check if we reply to more than one Message */
887 compose_forward(NULL, msginfo, FALSE, body, FALSE);
890 /* more messages FALL THROUGH */
891 case COMPOSE_FORWARD_AS_ATTACH:
892 compose_forward_multiple(NULL, msginfo_list);
894 case COMPOSE_REDIRECT:
895 compose_redirect(NULL, msginfo);
898 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
902 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
903 gboolean to_ml, gboolean to_sender,
906 compose_generic_reply(msginfo, quote, to_all, to_ml,
907 to_sender, FALSE, body);
910 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
915 compose_generic_reply(msginfo, quote, to_all, FALSE,
916 to_sender, TRUE, body);
919 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
920 gboolean to_all, gboolean to_ml,
922 gboolean followup_and_reply_to,
925 GtkItemFactory *ifactory;
927 PrefsAccount *account = NULL;
928 PrefsAccount *reply_account;
931 g_return_if_fail(msginfo != NULL);
932 g_return_if_fail(msginfo->folder != NULL);
934 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
936 g_return_if_fail(account != NULL);
938 if (to_sender && account->protocol == A_NNTP &&
939 !followup_and_reply_to) {
941 account_find_from_address(account->address);
943 reply_account = compose_current_mail_account();
947 reply_account = account;
949 compose = compose_create(account, COMPOSE_REPLY);
950 ifactory = gtk_item_factory_from_widget(compose->menubar);
952 menu_set_toggle(ifactory, "/Message/Remove references", FALSE);
953 menu_set_sensitive(ifactory, "/Message/Remove references", TRUE);
955 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
956 if (!compose->replyinfo)
957 compose->replyinfo = procmsg_msginfo_copy(msginfo);
959 if (msginfo->folder && msginfo->folder->ret_rcpt)
960 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
962 /* Set save folder */
963 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
964 gchar *folderidentifier;
966 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
967 folderidentifier = folder_item_get_identifier(msginfo->folder);
968 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
969 g_free(folderidentifier);
972 if (compose_parse_header(compose, msginfo) < 0) return;
973 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
974 to_sender, followup_and_reply_to);
975 compose_show_first_last_header(compose, TRUE);
977 text = GTK_STEXT(compose->text);
978 gtk_stext_freeze(text);
981 if (msginfo->folder && msginfo->folder->prefs &&
982 msginfo->folder->prefs &&
983 msginfo->folder->prefs->enable_default_dictionary &&
985 gtkaspell_change_dict(compose->gtkaspell,
986 msginfo->folder->prefs->default_dictionary);
992 if (prefs_common.quotemark && *prefs_common.quotemark)
993 qmark = prefs_common.quotemark;
997 compose_quote_fmt(compose, compose->replyinfo,
998 prefs_common.quotefmt,
1002 if (account->auto_sig)
1003 compose_insert_sig(compose, FALSE);
1005 if (quote && prefs_common.linewrap_quote)
1006 compose_wrap_line_all(compose);
1008 gtk_editable_set_position(GTK_EDITABLE(text), 0);
1009 gtk_stext_set_point(text, 0);
1011 gtk_stext_thaw(text);
1012 gtk_widget_grab_focus(compose->text);
1014 if (prefs_common.auto_exteditor)
1015 compose_exec_ext_editor(compose);
1018 #define INSERT_FW_HEADER(var, hdr) \
1019 if (msginfo->var && *msginfo->var) { \
1020 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1021 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1022 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1025 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1026 gboolean as_attach, const gchar *body,
1027 gboolean no_extedit)
1032 g_return_val_if_fail(msginfo != NULL, NULL);
1033 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1035 if (msginfo->folder->prefs->enable_default_account)
1036 account = account_find_from_id(msginfo->folder->prefs->default_account);
1038 account = msginfo->folder->folder->account;
1039 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1041 Xstrdup_a(to, msginfo->to, return NULL);
1042 extract_address(to);
1043 account = account_find_from_address(to);
1046 if (!account && prefs_common.forward_account_autosel) {
1048 if (!procheader_get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1049 extract_address(cc);
1050 account = account_find_from_address(cc);
1054 if (account == NULL) {
1055 account = cur_account;
1057 account = msginfo->folder->folder->account;
1058 if (!account) account = cur_account;
1061 g_return_val_if_fail(account != NULL, NULL);
1063 compose = compose_create(account, COMPOSE_FORWARD);
1065 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1066 if (!compose->fwdinfo)
1067 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1069 if (msginfo->subject && *msginfo->subject) {
1070 gchar *buf, *buf2, *p;
1072 buf = p = g_strdup(msginfo->subject);
1073 p += subject_get_prefix_length(p);
1074 memmove(buf, p, strlen(p) + 1);
1076 buf2 = g_strdup_printf("Fw: %s", buf);
1077 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1083 text = GTK_STEXT(compose->text);
1084 gtk_stext_freeze(text);
1089 msgfile = procmsg_get_message_file_path(msginfo);
1090 if (!is_file_exist(msgfile))
1091 g_warning("%s: file not exist\n", msgfile);
1093 compose_attach_append(compose, msgfile, msgfile,
1099 MsgInfo *full_msginfo;
1101 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1103 full_msginfo = procmsg_msginfo_copy(msginfo);
1105 if (prefs_common.fw_quotemark &&
1106 *prefs_common.fw_quotemark)
1107 qmark = prefs_common.fw_quotemark;
1111 compose_quote_fmt(compose, full_msginfo,
1112 prefs_common.fw_quotefmt,
1114 compose_attach_parts(compose, msginfo);
1116 procmsg_msginfo_free(full_msginfo);
1119 if (account->auto_sig)
1120 compose_insert_sig(compose, FALSE);
1122 if (prefs_common.linewrap_quote)
1123 compose_wrap_line_all(compose);
1125 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1126 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1128 gtk_stext_thaw(text);
1129 #if 0 /* NEW COMPOSE GUI */
1130 if (account->protocol != A_NNTP)
1131 gtk_widget_grab_focus(compose->to_entry);
1133 gtk_widget_grab_focus(compose->newsgroups_entry);
1135 gtk_widget_grab_focus(compose->header_last->entry);
1137 if (!no_extedit && prefs_common.auto_exteditor)
1138 compose_exec_ext_editor(compose);
1141 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1142 gchar *folderidentifier;
1144 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1145 folderidentifier = folder_item_get_identifier(msginfo->folder);
1146 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1147 g_free(folderidentifier);
1153 #undef INSERT_FW_HEADER
1155 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1162 g_return_val_if_fail(msginfo_list != NULL, NULL);
1164 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1165 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1169 if (account == NULL) {
1170 account = cur_account;
1172 account = msginfo->folder->folder->account;
1173 if (!account) account = cur_account;
1176 g_return_val_if_fail(account != NULL, NULL);
1178 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1179 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1180 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1183 compose = compose_create(account, COMPOSE_FORWARD);
1185 text = GTK_STEXT(compose->text);
1186 gtk_stext_freeze(text);
1188 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1189 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1190 if (!is_file_exist(msgfile))
1191 g_warning("%s: file not exist\n", msgfile);
1193 compose_attach_append(compose, msgfile, msgfile,
1198 if (account->auto_sig)
1199 compose_insert_sig(compose, FALSE);
1201 if (prefs_common.linewrap_quote)
1202 compose_wrap_line_all(compose);
1204 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1205 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1207 gtk_stext_thaw(text);
1208 gtk_widget_grab_focus(compose->header_last->entry);
1210 #if 0 /* NEW COMPOSE GUI */
1211 if (account->protocol != A_NNTP)
1212 gtk_widget_grab_focus(compose->to_entry);
1214 gtk_widget_grab_focus(compose->newsgroups_entry);
1220 void compose_reedit(MsgInfo *msginfo)
1223 PrefsAccount *account = NULL;
1226 gchar buf[BUFFSIZE];
1228 g_return_if_fail(msginfo != NULL);
1229 g_return_if_fail(msginfo->folder != NULL);
1231 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1232 gchar queueheader_buf[BUFFSIZE];
1235 /* Select Account from queue headers */
1236 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1237 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1238 id = atoi(&queueheader_buf[22]);
1239 account = account_find_from_id(id);
1241 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1242 sizeof(queueheader_buf), "NAID:")) {
1243 id = atoi(&queueheader_buf[5]);
1244 account = account_find_from_id(id);
1246 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1247 sizeof(queueheader_buf), "MAID:")) {
1248 id = atoi(&queueheader_buf[5]);
1249 account = account_find_from_id(id);
1251 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1252 sizeof(queueheader_buf), "S:")) {
1253 account = account_find_from_address(queueheader_buf);
1256 account = msginfo->folder->folder->account;
1258 if (!account && prefs_common.reedit_account_autosel) {
1259 gchar from[BUFFSIZE];
1260 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1261 extract_address(from);
1262 account = account_find_from_address(from);
1265 if (!account) account = cur_account;
1266 g_return_if_fail(account != NULL);
1268 compose = compose_create(account, COMPOSE_REEDIT);
1269 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1271 if (msginfo->folder->stype == F_QUEUE
1272 || msginfo->folder->stype == F_DRAFT) {
1273 gchar queueheader_buf[BUFFSIZE];
1275 /* Set message save folder */
1276 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1279 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1280 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1281 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1285 if (compose_parse_header(compose, msginfo) < 0) return;
1286 compose_reedit_set_entry(compose, msginfo);
1288 text = GTK_STEXT(compose->text);
1289 gtk_stext_freeze(text);
1291 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1292 g_warning("Can't get text part\n");
1294 while (fgets(buf, sizeof(buf), fp) != NULL) {
1296 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1300 compose_attach_parts(compose, msginfo);
1302 gtk_stext_thaw(text);
1303 gtk_widget_grab_focus(compose->text);
1305 if (prefs_common.auto_exteditor)
1306 compose_exec_ext_editor(compose);
1309 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1313 GtkItemFactory *ifactory;
1316 g_return_val_if_fail(msginfo != NULL, NULL);
1319 account = account_get_reply_account(msginfo,
1320 prefs_common.reply_account_autosel);
1321 g_return_val_if_fail(account != NULL, NULL);
1323 compose = compose_create(account, COMPOSE_REDIRECT);
1324 ifactory = gtk_item_factory_from_widget(compose->menubar);
1326 compose->replyinfo = NULL;
1327 compose->fwdinfo = NULL;
1329 compose_show_first_last_header(compose, TRUE);
1331 gtk_widget_grab_focus(compose->header_last->entry);
1333 filename = procmsg_get_message_file(msginfo);
1334 if (filename == NULL)
1337 compose->redirect_filename = filename;
1339 /* Set save folder */
1340 item = msginfo->folder;
1341 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1342 gchar *folderidentifier;
1344 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1345 folderidentifier = folder_item_get_identifier(item);
1346 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1347 g_free(folderidentifier);
1350 compose_attach_parts(compose, msginfo);
1352 if (msginfo->subject)
1353 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1355 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1357 gtk_stext_freeze(GTK_STEXT(compose->text));
1358 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1359 gtk_editable_set_editable(GTK_EDITABLE(compose->text), FALSE);
1360 gtk_stext_thaw(GTK_STEXT(compose->text));
1362 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1363 menu_set_sensitive(ifactory, "/Add...", FALSE);
1364 menu_set_sensitive(ifactory, "/Remove", FALSE);
1365 menu_set_sensitive(ifactory, "/Property...", FALSE);
1367 ifactory = gtk_item_factory_from_widget(compose->menubar);
1368 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
1369 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
1370 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
1371 menu_set_sensitive(ifactory, "/Edit", FALSE);
1372 menu_set_sensitive(ifactory, "/Message/Save to draft folder", FALSE);
1373 menu_set_sensitive(ifactory, "/Message/Save and keep editing", FALSE);
1375 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
1376 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
1377 menu_set_sensitive(ifactory, "/Message/Mode/MIME", FALSE);
1378 menu_set_sensitive(ifactory, "/Message/Mode/Inline", FALSE);
1380 menu_set_sensitive(ifactory, "/Message/Priority", FALSE);
1381 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
1382 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1383 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1385 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1386 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1387 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1388 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1389 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1390 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, FALSE);
1395 GList *compose_get_compose_list(void)
1397 return compose_list;
1400 void compose_entry_append(Compose *compose, const gchar *address,
1401 ComposeEntryType type)
1405 if (!address || *address == '\0') return;
1407 #if 0 /* NEW COMPOSE GUI */
1410 entry = GTK_ENTRY(compose->cc_entry);
1413 entry = GTK_ENTRY(compose->bcc_entry);
1415 case COMPOSE_NEWSGROUPS:
1416 entry = GTK_ENTRY(compose->newsgroups_entry);
1420 entry = GTK_ENTRY(compose->to_entry);
1424 text = gtk_entry_get_text(entry);
1426 gtk_entry_append_text(entry, ", ");
1427 gtk_entry_append_text(entry, address);
1435 header = N_("Bcc:");
1437 case COMPOSE_REPLYTO:
1438 header = N_("Reply-To:");
1440 case COMPOSE_NEWSGROUPS:
1441 header = N_("Newsgroups:");
1443 case COMPOSE_FOLLOWUPTO:
1444 header = N_( "Followup-To:");
1451 header = prefs_common.trans_hdr ? gettext(header) : header;
1453 compose_add_header_entry(compose, header, (gchar *)address);
1456 void compose_entry_select (Compose *compose, const gchar *mailto)
1458 GSList *header_list;
1460 for (header_list = compose->header_list; header_list != NULL; header_list = header_list->next) {
1461 GtkEntry * entry = GTK_ENTRY(((ComposeHeaderEntry *)header_list->data)->entry);
1463 if (gtk_entry_get_text(entry) && !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1464 gtk_entry_select_region(entry, 0, -1);
1465 gtk_widget_grab_focus(GTK_WIDGET(entry));
1470 void compose_toolbar_cb(gint action, gpointer data)
1472 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1473 Compose *compose = (Compose*)toolbar_item->parent;
1475 g_return_if_fail(compose != NULL);
1479 compose_send_cb(compose, 0, NULL);
1482 compose_send_later_cb(compose, 0, NULL);
1485 compose_draft_cb(compose, 0, NULL);
1488 compose_insert_file_cb(compose, 0, NULL);
1491 compose_attach_cb(compose, 0, NULL);
1494 compose_insert_sig(compose, FALSE);
1497 compose_ext_editor_cb(compose, 0, NULL);
1500 compose_wrap_line_all(compose);
1503 compose_address_cb(compose, 0, NULL);
1506 case A_CHECK_SPELLING:
1507 compose_check_all(compose);
1515 static void compose_entries_set(Compose *compose, const gchar *mailto)
1520 gchar *subject = NULL;
1523 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1526 compose_entry_append(compose, to, COMPOSE_TO);
1528 compose_entry_append(compose, cc, COMPOSE_CC);
1530 compose_entry_append(compose, bcc, COMPOSE_BCC);
1532 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1534 gtk_stext_insert(GTK_STEXT(compose->text),
1535 NULL, NULL, NULL, body, -1);
1536 gtk_stext_insert(GTK_STEXT(compose->text),
1537 NULL, NULL, NULL, "\n", 1);
1547 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1549 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1550 {"Cc:", NULL, TRUE},
1551 {"References:", NULL, FALSE},
1552 {"Bcc:", NULL, TRUE},
1553 {"Newsgroups:", NULL, TRUE},
1554 {"Followup-To:", NULL, TRUE},
1555 {"List-Post:", NULL, FALSE},
1556 {"X-Priority:", NULL, FALSE},
1557 {NULL, NULL, FALSE}};
1573 g_return_val_if_fail(msginfo != NULL, -1);
1575 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1576 procheader_get_header_fields(fp, hentry);
1579 if (hentry[H_REPLY_TO].body != NULL) {
1580 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1581 compose->replyto = hentry[H_REPLY_TO].body;
1582 hentry[H_REPLY_TO].body = NULL;
1584 if (hentry[H_CC].body != NULL) {
1585 conv_unmime_header_overwrite(hentry[H_CC].body);
1586 compose->cc = hentry[H_CC].body;
1587 hentry[H_CC].body = NULL;
1589 if (hentry[H_REFERENCES].body != NULL) {
1590 if (compose->mode == COMPOSE_REEDIT)
1591 compose->references = hentry[H_REFERENCES].body;
1593 compose->references = compose_parse_references
1594 (hentry[H_REFERENCES].body, msginfo->msgid);
1595 g_free(hentry[H_REFERENCES].body);
1597 hentry[H_REFERENCES].body = NULL;
1599 if (hentry[H_BCC].body != NULL) {
1600 if (compose->mode == COMPOSE_REEDIT) {
1601 conv_unmime_header_overwrite(hentry[H_BCC].body);
1602 compose->bcc = hentry[H_BCC].body;
1604 g_free(hentry[H_BCC].body);
1605 hentry[H_BCC].body = NULL;
1607 if (hentry[H_NEWSGROUPS].body != NULL) {
1608 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1609 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1610 hentry[H_NEWSGROUPS].body = NULL;
1612 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1613 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1614 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1615 hentry[H_FOLLOWUP_TO].body = NULL;
1617 if (hentry[H_LIST_POST].body != NULL) {
1620 extract_address(hentry[H_LIST_POST].body);
1621 if (hentry[H_LIST_POST].body[0] != '\0') {
1622 scan_mailto_url(hentry[H_LIST_POST].body,
1623 &to, NULL, NULL, NULL, NULL);
1625 g_free(compose->ml_post);
1626 compose->ml_post = to;
1629 g_free(hentry[H_LIST_POST].body);
1630 hentry[H_LIST_POST].body = NULL;
1633 /* CLAWS - X-Priority */
1634 if (compose->mode == COMPOSE_REEDIT)
1635 if (hentry[H_X_PRIORITY].body != NULL) {
1638 priority = atoi(hentry[H_X_PRIORITY].body);
1639 g_free(hentry[H_X_PRIORITY].body);
1641 hentry[H_X_PRIORITY].body = NULL;
1643 if (priority < PRIORITY_HIGHEST ||
1644 priority > PRIORITY_LOWEST)
1645 priority = PRIORITY_NORMAL;
1647 compose->priority = priority;
1650 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1651 compose->inreplyto = g_strdup(msginfo->inreplyto);
1652 else if (compose->mode != COMPOSE_REEDIT &&
1653 msginfo->msgid && *msginfo->msgid) {
1654 compose->inreplyto = g_strdup(msginfo->msgid);
1656 if (!compose->references) {
1657 if (msginfo->inreplyto && *msginfo->inreplyto)
1658 compose->references =
1659 g_strdup_printf("<%s>\n\t<%s>",
1663 compose->references =
1664 g_strconcat("<", msginfo->msgid, ">",
1672 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1674 GSList *ref_id_list, *cur;
1678 ref_id_list = references_list_append(NULL, ref);
1679 if (!ref_id_list) return NULL;
1680 if (msgid && *msgid)
1681 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1686 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1687 /* "<" + Message-ID + ">" + CR+LF+TAB */
1688 len += strlen((gchar *)cur->data) + 5;
1690 if (len > MAX_REFERENCES_LEN) {
1691 /* remove second message-ID */
1692 if (ref_id_list && ref_id_list->next &&
1693 ref_id_list->next->next) {
1694 g_free(ref_id_list->next->data);
1695 ref_id_list = g_slist_remove
1696 (ref_id_list, ref_id_list->next->data);
1698 slist_free_strings(ref_id_list);
1699 g_slist_free(ref_id_list);
1706 new_ref = g_string_new("");
1707 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1708 if (new_ref->len > 0)
1709 g_string_append(new_ref, "\n\t");
1710 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1713 slist_free_strings(ref_id_list);
1714 g_slist_free(ref_id_list);
1716 new_ref_str = new_ref->str;
1717 g_string_free(new_ref, FALSE);
1722 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1723 const gchar *fmt, const gchar *qmark,
1726 GtkSText *text = GTK_STEXT(compose->text);
1727 static MsgInfo dummyinfo;
1728 gchar *quote_str = NULL;
1732 const gchar *trimmed_body = body;
1735 msginfo = &dummyinfo;
1737 if (qmark != NULL) {
1738 quote_fmt_init(msginfo, NULL, NULL);
1739 quote_fmt_scan_string(qmark);
1742 buf = quote_fmt_get_buffer();
1744 alertpanel_error(_("Quote mark format error."));
1746 Xstrdup_a(quote_str, buf, return NULL)
1749 if (fmt && *fmt != '\0') {
1750 while (trimmed_body && strlen(trimmed_body) > 1
1751 && trimmed_body[0]=='\n')
1754 quote_fmt_init(msginfo, quote_str, trimmed_body);
1755 quote_fmt_scan_string(fmt);
1758 buf = quote_fmt_get_buffer();
1760 alertpanel_error(_("Message reply/forward format error."));
1766 gtk_stext_freeze(text);
1768 for (p = buf; *p != '\0'; ) {
1769 lastp = strchr(p, '\n');
1770 len = lastp ? lastp - p + 1 : -1;
1771 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1778 gtk_stext_thaw(text);
1783 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1784 gboolean to_all, gboolean to_ml,
1786 gboolean followup_and_reply_to)
1788 GSList *cc_list = NULL;
1791 gchar *replyto = NULL;
1792 GHashTable *to_table;
1794 g_return_if_fail(compose->account != NULL);
1795 g_return_if_fail(msginfo != NULL);
1797 if (compose->account->protocol != A_NNTP) {
1798 if (!compose->replyto && to_ml && compose->ml_post
1799 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1800 compose_entry_append(compose,
1803 else if (!(to_all || to_sender)
1805 && msginfo->folder->prefs->enable_default_reply_to) {
1806 compose_entry_append(compose,
1807 msginfo->folder->prefs->default_reply_to,
1810 compose_entry_append(compose,
1811 (compose->replyto && !to_sender)
1812 ? compose->replyto :
1813 msginfo->from ? msginfo->from : "",
1816 if (to_sender || (compose->followup_to &&
1817 !strncmp(compose->followup_to, "poster", 6)))
1818 compose_entry_append
1820 (compose->replyto ? compose->replyto :
1821 msginfo->from ? msginfo->from : ""),
1824 else if (followup_and_reply_to || to_all) {
1825 compose_entry_append
1827 (compose->replyto ? compose->replyto :
1828 msginfo->from ? msginfo->from : ""),
1831 compose_entry_append
1833 compose->followup_to ? compose->followup_to :
1834 compose->newsgroups ? compose->newsgroups : "",
1835 COMPOSE_NEWSGROUPS);
1838 compose_entry_append
1840 compose->followup_to ? compose->followup_to :
1841 compose->newsgroups ? compose->newsgroups : "",
1842 COMPOSE_NEWSGROUPS);
1845 if (msginfo->subject && *msginfo->subject) {
1849 buf = p = g_strdup(msginfo->subject);
1850 p += subject_get_prefix_length(p);
1851 memmove(buf, p, strlen(p) + 1);
1853 buf2 = g_strdup_printf("Re: %s", buf);
1854 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1859 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1861 if (to_ml && compose->ml_post) return;
1862 if (!to_all || compose->account->protocol == A_NNTP) return;
1864 if (compose->replyto) {
1865 Xstrdup_a(replyto, compose->replyto, return);
1866 extract_address(replyto);
1868 if (msginfo->from) {
1869 Xstrdup_a(from, msginfo->from, return);
1870 extract_address(from);
1873 if (replyto && from)
1874 cc_list = address_list_append_with_comments(cc_list, from);
1875 if (to_all && msginfo->folder &&
1876 msginfo->folder->prefs->enable_default_reply_to)
1877 cc_list = address_list_append_with_comments(cc_list,
1878 msginfo->folder->prefs->default_reply_to);
1879 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1880 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1882 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1884 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1885 if (compose->account)
1886 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1887 GINT_TO_POINTER(1));
1889 /* remove address on To: and that of current account */
1890 for (cur = cc_list; cur != NULL; ) {
1891 GSList *next = cur->next;
1894 addr = g_strdup(cur->data);
1895 extract_address(addr);
1897 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
1898 cc_list = g_slist_remove(cc_list, cur->data);
1900 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
1904 hash_free_strings(to_table);
1905 g_hash_table_destroy(to_table);
1908 for (cur = cc_list; cur != NULL; cur = cur->next)
1909 compose_entry_append(compose, (gchar *)cur->data,
1911 slist_free_strings(cc_list);
1912 g_slist_free(cc_list);
1917 #define SET_ENTRY(entry, str) \
1920 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1923 #define SET_ADDRESS(type, str) \
1926 compose_entry_append(compose, str, type); \
1929 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1931 g_return_if_fail(msginfo != NULL);
1933 SET_ENTRY(subject_entry, msginfo->subject);
1934 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1935 SET_ADDRESS(COMPOSE_CC, compose->cc);
1936 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1937 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1938 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
1939 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
1941 compose_update_priority_menu_item(compose);
1943 compose_update_gnupg_mode_menu_item(compose);
1945 compose_show_first_last_header(compose, TRUE);
1952 static void compose_insert_sig(Compose *compose, gboolean replace)
1954 GtkSText *text = GTK_STEXT(compose->text);
1958 g_return_if_fail(compose->account != NULL);
1960 cur_pos = gtk_editable_get_position(GTK_EDITABLE(text));
1962 gtk_stext_freeze(text);
1965 len = gtk_stext_get_length(text);
1966 gtk_stext_set_point(text, len);
1969 if (replace && compose->sig_str) {
1972 if (compose->sig_str[0] == '\0')
1975 pos = gtkut_stext_find(text, 0, compose->sig_str, TRUE);
1978 len = get_mbs_len(compose->sig_str);
1980 gtk_stext_set_point(text, pos);
1981 gtk_stext_forward_delete(text, len);
1986 g_free(compose->sig_str);
1987 compose->sig_str = compose_get_signature_str(compose);
1988 if (!compose->sig_str || (replace && !compose->account->auto_sig))
1989 compose->sig_str = g_strdup("");
1991 gtk_stext_insert(text, NULL, NULL, NULL, compose->sig_str, -1);
1993 gtk_stext_thaw(text);
1995 if (cur_pos > gtk_stext_get_length(text))
1996 cur_pos = gtk_stext_get_length(text);
1998 gtk_editable_set_position(GTK_EDITABLE(text), cur_pos);
1999 gtk_stext_set_point(text, cur_pos);
2002 static gchar *compose_get_signature_str(Compose *compose)
2004 gchar *sig_body = NULL;
2005 gchar *sig_str = NULL;
2007 g_return_val_if_fail(compose->account != NULL, NULL);
2009 if (!compose->account->sig_path)
2012 if (compose->account->sig_type == SIG_FILE) {
2013 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2014 g_warning("can't open signature file: %s\n",
2015 compose->account->sig_path);
2020 if (compose->account->sig_type == SIG_COMMAND)
2021 sig_body = get_command_output(compose->account->sig_path);
2025 tmp = file_read_to_str(compose->account->sig_path);
2028 sig_body = normalize_newlines(tmp);
2032 if (compose->account->sig_sep)
2033 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2036 sig_str = g_strconcat("\n\n", sig_body, NULL);
2043 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2045 GtkSText *text = GTK_STEXT(compose->text);
2046 gchar buf[BUFFSIZE];
2049 gboolean badtxt = FALSE;
2051 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2053 if ((fp = fopen(file, "rb")) == NULL) {
2054 FILE_OP_ERROR(file, "fopen");
2055 return COMPOSE_INSERT_READ_ERROR;
2058 gtk_stext_freeze(text);
2060 while (fgets(buf, sizeof(buf), fp) != NULL) {
2061 /* strip <CR> if DOS/Windows file,
2062 replace <CR> with <LF> if Macintosh file. */
2065 if (len > 0 && buf[len - 1] != '\n') {
2067 if (buf[len] == '\r') buf[len] = '\n';
2069 if (mbstowcs(NULL, buf, 0) == -1)
2071 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
2074 gtk_stext_thaw(text);
2079 return COMPOSE_INSERT_INVALID_CHARACTER;
2081 return COMPOSE_INSERT_SUCCESS;
2084 static void compose_attach_append(Compose *compose, const gchar *file,
2085 const gchar *filename,
2086 const gchar *content_type)
2089 gchar *text[N_ATTACH_COLS];
2094 if (!is_file_exist(file)) {
2095 g_warning("File %s doesn't exist\n", file);
2098 if ((size = get_file_size(file)) < 0) {
2099 g_warning("Can't get file size of %s\n", file);
2103 alertpanel_notice(_("File %s is empty."), file);
2106 if ((fp = fopen(file, "rb")) == NULL) {
2107 alertpanel_error(_("Can't read %s."), file);
2112 #if 0 /* NEW COMPOSE GUI */
2113 if (!compose->use_attach) {
2114 GtkItemFactory *ifactory;
2115 GtkWidget *menuitem;
2117 ifactory = gtk_item_factory_from_widget(compose->menubar);
2118 menuitem = gtk_item_factory_get_item(ifactory,
2119 "/View/Attachment");
2120 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2124 ainfo = g_new0(AttachInfo, 1);
2125 ainfo->file = g_strdup(file);
2128 ainfo->content_type = g_strdup(content_type);
2129 if (!strcasecmp(content_type, "message/rfc822")) {
2131 MsgFlags flags = {0, 0};
2134 if (procmime_get_encoding_for_file(file) == ENC_7BIT)
2135 ainfo->encoding = ENC_7BIT;
2137 ainfo->encoding = ENC_8BIT;
2139 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2140 if (msginfo && msginfo->subject)
2141 name = msginfo->subject;
2143 name = g_basename(filename ? filename : file);
2145 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2147 procmsg_msginfo_free(msginfo);
2149 if (!g_strncasecmp(content_type, "text", 4))
2151 procmime_get_encoding_for_file(file);
2153 ainfo->encoding = ENC_BASE64;
2154 ainfo->name = g_strdup
2155 (g_basename(filename ? filename : file));
2158 ainfo->content_type = procmime_get_mime_type(file);
2159 if (!ainfo->content_type) {
2160 ainfo->content_type =
2161 g_strdup("application/octet-stream");
2162 ainfo->encoding = ENC_BASE64;
2163 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
2164 ainfo->encoding = procmime_get_encoding_for_file(file);
2166 ainfo->encoding = ENC_BASE64;
2167 ainfo->name = g_strdup(g_basename(filename ? filename : file));
2171 text[COL_MIMETYPE] = ainfo->content_type;
2172 text[COL_SIZE] = to_human_readable(size);
2173 text[COL_NAME] = ainfo->name;
2175 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2176 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2180 static void compose_use_signing(Compose *compose, gboolean use_signing)
2182 GtkItemFactory *ifactory;
2183 GtkWidget *menuitem = NULL;
2185 compose->use_signing = use_signing;
2186 ifactory = gtk_item_factory_from_widget(compose->menubar);
2187 menuitem = gtk_item_factory_get_item
2188 (ifactory, "/Message/Sign");
2189 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2191 compose_update_gnupg_mode_menu_item(compose);
2193 #endif /* USE_GPGME */
2195 #define NEXT_PART_NOT_CHILD(info) \
2197 node = info->node; \
2198 while (node->children) \
2199 node = g_node_last_child(node); \
2200 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2203 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2207 MimeInfo *firsttext = NULL;
2208 MimeInfo *encrypted = NULL;
2211 const gchar *partname = NULL;
2213 mimeinfo = procmime_scan_message(msginfo);
2214 if (!mimeinfo) return;
2216 if (mimeinfo->node->children == NULL) {
2217 procmime_mimeinfo_free_all(mimeinfo);
2221 /* find first content part */
2222 child = (MimeInfo *) mimeinfo->node->children->data;
2223 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2224 child = (MimeInfo *)child->node->children->data;
2226 if (child->type == MIMETYPE_TEXT) {
2228 debug_print("First text part found\n");
2229 } else if (compose->mode == COMPOSE_REEDIT &&
2230 child->type == MIMETYPE_APPLICATION &&
2231 !strcasecmp(child->subtype, "pgp-encrypted")) {
2233 val = alertpanel(_("Encrypted message"),
2234 _("Cannot re-edit an encrypted message. \n"
2235 "Discard encrypted part?"),
2236 _("Yes"), _("No"), NULL);
2237 if (val == G_ALERTDEFAULT)
2238 encrypted = (MimeInfo *)child->node->parent->data;
2241 child = (MimeInfo *) mimeinfo->node->children->data;
2242 while (child != NULL) {
2243 if (child == encrypted) {
2244 /* skip this part of tree */
2245 NEXT_PART_NOT_CHILD(child);
2249 if (child->type == MIMETYPE_MULTIPART) {
2250 /* get the actual content */
2251 child = procmime_mimeinfo_next(child);
2255 if (child == firsttext) {
2256 child = procmime_mimeinfo_next(child);
2260 if ((compose->mode == COMPOSE_REEDIT ||
2261 compose->mode == COMPOSE_FORWARD_INLINE ||
2262 compose->mode == COMPOSE_FORWARD ) &&
2263 (child->type == MIMETYPE_APPLICATION) &&
2264 !strcmp(child->subtype, "pgp-signature")) {
2266 if (compose->mode == COMPOSE_REEDIT) {
2267 compose->gnupg_mode = GNUPG_MODE_DETACH;
2268 compose_use_signing(compose, TRUE);
2271 child = procmime_mimeinfo_next(child);
2274 outfile = procmime_get_tmp_file_name(child);
2275 if (procmime_get_part(outfile, child) < 0)
2276 g_warning("Can't get the part of multipart message.");
2278 gchar *content_type;
2280 content_type = g_strdup_printf("%s/%s", procmime_get_type_str(child->type), child->subtype);
2281 partname = procmime_mimeinfo_get_parameter(child, "name");
2282 if (partname == NULL)
2284 compose_attach_append(compose, outfile,
2285 partname, content_type);
2286 g_free(content_type);
2289 NEXT_PART_NOT_CHILD(child);
2291 procmime_mimeinfo_free_all(mimeinfo);
2294 #undef NEXT_PART_NOT_CHILD
2296 #define GET_CHAR(pos, buf, len) \
2298 if (text->use_wchar) \
2299 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2301 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2306 #define DISP_WIDTH(len) \
2307 ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
2308 (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
2310 #define SPACE_CHARS " \t"
2312 static void compose_wrap_line(Compose *compose)
2314 GtkSText *text = GTK_STEXT(compose->text);
2315 gint ch_len, last_ch_len;
2316 gchar cbuf[MB_LEN_MAX], last_ch;
2320 gint p_start, p_end;
2321 gint line_pos, cur_pos;
2322 gint line_len, cur_len;
2324 gtk_stext_freeze(text);
2326 text_len = gtk_stext_get_length(text);
2328 /* check to see if the point is on the paragraph mark (empty line). */
2329 cur_pos = gtk_stext_get_point(text);
2330 GET_CHAR(cur_pos, cbuf, ch_len);
2331 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2333 goto compose_end; /* on the paragraph mark */
2334 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2335 if (ch_len == 1 && *cbuf == '\n')
2336 goto compose_end; /* on the paragraph mark */
2339 /* find paragraph start. */
2340 line_end = quoted = 0;
2341 for (p_start = cur_pos; p_start >= 0; --p_start) {
2342 GET_CHAR(p_start, cbuf, ch_len);
2343 if (ch_len == 1 && *cbuf == '\n') {
2345 goto compose_end; /* quoted part */
2353 && strchr(prefs_common.quote_chars, *cbuf))
2355 else if (ch_len != 1 || !isspace(*(guchar *)cbuf))
2364 /* find paragraph end. */
2366 for (p_end = cur_pos; p_end < text_len; p_end++) {
2367 GET_CHAR(p_end, cbuf, ch_len);
2368 if (ch_len == 1 && *cbuf == '\n') {
2375 if (line_end && ch_len == 1 &&
2376 strchr(prefs_common.quote_chars, *cbuf))
2377 goto compose_end; /* quoted part */
2382 if (p_end >= text_len)
2385 if (p_start >= p_end)
2388 line_len = cur_len = 0;
2392 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2395 GET_CHAR(cur_pos, cbuf, ch_len);
2402 if (ch_len == 1 && isspace(*(guchar *)cbuf))
2405 if (ch_len == 1 && *cbuf == '\n') {
2407 if (last_ch_len == 1 && !isspace((guchar)last_ch)) {
2408 if (cur_pos + 1 < p_end) {
2409 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2411 !isspace(*(guchar *)cbuf))
2415 gtk_stext_set_point(text, cur_pos + 1);
2416 gtk_stext_backward_delete(text, 1);
2418 gtk_stext_set_point(text, cur_pos);
2419 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2429 last_ch_len = ch_len;
2433 line_pos = cur_pos + 1;
2434 line_len = cur_len + ch_len;
2437 if (cur_len + DISP_WIDTH(ch_len) > prefs_common.linewrap_len &&
2441 GET_CHAR(line_pos - 1, cbuf, ch_len);
2442 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2443 gtk_stext_set_point(text, line_pos);
2444 gtk_stext_backward_delete(text, 1);
2453 gtk_stext_set_point(text, line_pos);
2454 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2458 cur_len = cur_len - line_len + DISP_WIDTH(ch_len);
2464 line_pos = cur_pos + 1;
2465 line_len = cur_len + DISP_WIDTH(ch_len);
2467 cur_len += DISP_WIDTH(ch_len);
2471 gtk_stext_thaw(text);
2476 /* Darko: used when I debug wrapping */
2477 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2480 gchar cbuf[MB_LEN_MAX];
2482 printf("%d [", pos);
2483 for (i = pos; i < tlen; i++) {
2484 GET_CHAR(i, cbuf, clen);
2485 if (clen < 0) break;
2486 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2488 fwrite(cbuf, clen, 1, stdout);
2496 WAIT_FOR_INDENT_CHAR,
2497 WAIT_FOR_INDENT_CHAR_OR_SPACE
2500 /* return indent length, we allow:
2501 > followed by spaces/tabs
2502 | followed by spaces/tabs
2503 uppercase characters immediately followed by >,
2504 and the repeating sequences of the above */
2505 /* return indent length */
2506 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2509 guint i, ch_len, alnum_cnt = 0;
2510 IndentState state = WAIT_FOR_INDENT_CHAR;
2511 gchar cbuf[MB_LEN_MAX];
2515 if (prefs_common.quote_chars == NULL) {
2519 for (i = start_pos; i < text_len; i++) {
2520 GET_CHAR(i, cbuf, ch_len);
2524 if (cbuf[0] == '\n')
2527 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2528 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2531 case WAIT_FOR_SPACE:
2532 if (is_space == FALSE)
2534 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2536 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2537 if (is_indent == FALSE && is_space == FALSE &&
2538 !isupper((guchar)cbuf[0]))
2540 if (is_space == TRUE) {
2542 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2543 } else if (is_indent == TRUE) {
2545 state = WAIT_FOR_SPACE;
2548 state = WAIT_FOR_INDENT_CHAR;
2551 case WAIT_FOR_INDENT_CHAR:
2552 if (is_indent == FALSE && !isupper((guchar)cbuf[0]))
2554 if (is_indent == TRUE) {
2556 && !strchr(prefs_common.quote_chars, cbuf[0]))
2559 state = WAIT_FOR_SPACE;
2570 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2576 /* insert quotation string when line was wrapped */
2577 static guint ins_quote(GtkSText *text, guint indent_len,
2578 guint prev_line_pos, guint text_len,
2581 guint i, ins_len = 0;
2585 for (i = 0; i < indent_len; i++) {
2586 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2587 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2589 ins_len = indent_len;
2595 /* check if we should join the next line */
2596 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2597 guint prev_ilen, gboolean autowrap)
2599 guint indent_len, ch_len;
2600 gboolean do_join = FALSE;
2601 gchar cbuf[MB_LEN_MAX];
2603 indent_len = get_indent_length(text, start_pos, tlen);
2605 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2606 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2607 if (ch_len > 0 && (cbuf[0] != '\n'))
2614 static void compose_wrap_line_all(Compose *compose)
2616 compose_wrap_line_all_full(compose, FALSE);
2619 #define STEXT_FREEZE() \
2620 if (!frozen) { gtk_stext_freeze(text); frozen = TRUE; }
2622 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2624 GtkSText *text = GTK_STEXT(compose->text);
2626 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2627 gint line_len = 0, cur_len = 0;
2629 gboolean is_new_line = TRUE, do_delete = FALSE;
2631 gboolean linewrap_quote = TRUE;
2632 gboolean set_editable_pos = FALSE;
2633 gint editable_pos = 0;
2634 gboolean frozen = FALSE;
2635 guint linewrap_len = prefs_common.linewrap_len;
2636 gchar *qfmt = prefs_common.quotemark;
2637 gchar cbuf[MB_LEN_MAX];
2639 tlen = gtk_stext_get_length(text);
2641 for (; cur_pos < tlen; cur_pos++) {
2642 /* mark position of new line - needed for quotation wrap */
2645 i_len = get_indent_length(text, cur_pos, tlen);
2647 is_new_line = FALSE;
2650 g_print("new line i_len=%d p_pos=", i_len);
2651 dump_text(text, p_pos, tlen, 1);
2655 GET_CHAR(cur_pos, cbuf, ch_len);
2657 /* fix line length for tabs */
2658 if (ch_len == 1 && *cbuf == '\t') {
2659 guint tab_width = text->default_tab_width;
2660 guint tab_offset = line_len % tab_width;
2663 g_print("found tab at pos=%d line_len=%d ", cur_pos,
2667 line_len += tab_width - tab_offset - 1;
2671 printf("new_len=%d\n", line_len);
2675 /* we have encountered line break */
2676 if (ch_len == 1 && *cbuf == '\n') {
2678 gchar cb[MB_LEN_MAX];
2680 /* should we join the next line */
2681 if ((autowrap || i_len != cur_len) && do_delete &&
2683 (text, cur_pos + 1, tlen, i_len, autowrap))
2689 g_print("found CR at %d do_del is %d next line is ",
2690 cur_pos, do_delete);
2691 dump_text(text, cur_pos + 1, tlen, 1);
2694 /* skip delete if it is continuous URL */
2695 if (do_delete && (line_pos - p_pos <= i_len) &&
2696 gtk_stext_is_uri_string(text, line_pos, tlen))
2700 g_print("l_len=%d wrap_len=%d do_del=%d\n",
2701 line_len, linewrap_len, do_delete);
2703 /* should we delete to perform smart wrapping */
2704 if (line_len < linewrap_len && do_delete) {
2706 /* get rid of newline */
2707 gtk_stext_set_point(text, cur_pos);
2708 gtk_stext_forward_delete(text, 1);
2711 /* if text starts with quote fmt or with
2712 indent string, delete them */
2715 ilen = gtk_stext_str_compare_n
2716 (text, cur_pos, p_pos, i_len,
2719 gtk_stext_forward_delete
2725 GET_CHAR(cur_pos, cb, clen);
2727 /* insert space if it's alphanumeric */
2728 if ((cur_pos != line_pos) &&
2729 ((clen > 1) || isalnum((guchar)cb[0]))) {
2730 gtk_stext_insert(text, NULL, NULL,
2735 /* and start over with current line */
2736 cur_pos = p_pos - 1;
2738 line_len = cur_len = 0;
2742 g_print("after delete l_pos=");
2743 dump_text(text, line_pos, tlen, 1);
2745 /* move beginning of line if we are on LF */
2746 GET_CHAR(line_pos, cb, clen);
2747 if (clen == 1 && *cb == '\n')
2750 g_print("new line_pos=%d\n", line_pos);
2756 /* mark new line beginning */
2757 line_pos = cur_pos + 1;
2758 line_len = cur_len = 0;
2769 /* possible line break */
2770 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2771 line_pos = cur_pos + 1;
2772 line_len = cur_len + ch_len;
2775 /* are we over wrapping length set in preferences ? */
2776 if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
2780 g_print("should wrap cur_pos=%d ", cur_pos);
2781 dump_text(text, p_pos, tlen, 1);
2782 dump_text(text, line_pos, tlen, 1);
2784 /* force wrapping if it is one long word but not URL */
2785 if (line_pos - p_pos <= i_len)
2786 if (!gtk_stext_is_uri_string
2787 (text, line_pos, tlen))
2788 line_pos = cur_pos - 1;
2790 g_print("new line_pos=%d\n", line_pos);
2793 GET_CHAR(line_pos - 1, cbuf, clen);
2795 /* if next character is space delete it */
2796 if (clen == 1 && isspace(*(guchar *)cbuf)) {
2797 if (p_pos + i_len != line_pos ||
2798 !gtk_stext_is_uri_string
2799 (text, line_pos, tlen)) {
2801 /* workaround for correct cursor
2803 if (set_editable_pos == FALSE) {
2804 editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2805 if (editable_pos == line_pos)
2806 set_editable_pos = TRUE;
2808 gtk_stext_set_point(text, line_pos);
2809 gtk_stext_backward_delete(text, 1);
2818 /* if it is URL at beginning of line don't wrap */
2819 if (p_pos + i_len == line_pos &&
2820 gtk_stext_is_uri_string(text, line_pos, tlen)) {
2822 g_print("found URL at ");
2823 dump_text(text, line_pos, tlen, 1);
2830 gtk_stext_set_point(text, line_pos);
2831 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2832 gtk_stext_compact_buffer(text);
2835 /* for loop will increase it */
2836 cur_pos = line_pos - 1;
2837 /* start over with current line */
2839 line_len = cur_len = 0;
2840 if (autowrap || i_len > 0)
2845 g_print("after CR insert ");
2846 dump_text(text, line_pos, tlen, 1);
2847 dump_text(text, cur_pos, tlen, 1);
2850 /* should we insert quotation ? */
2851 if (linewrap_quote && i_len) {
2852 /* only if line is not already quoted */
2853 if (!gtk_stext_str_compare
2854 (text, line_pos, tlen, qfmt)) {
2857 if (line_pos - p_pos > i_len) {
2859 (text, i_len, p_pos,
2864 g_print("after quote insert ");
2865 dump_text(text, line_pos, tlen, 1);
2873 line_pos = cur_pos + 1;
2874 line_len = cur_len + DISP_WIDTH(ch_len);
2876 /* advance to next character in buffer */
2877 cur_len += DISP_WIDTH(ch_len);
2881 gtk_stext_thaw(text);
2883 if (set_editable_pos && editable_pos <= tlen)
2884 gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
2890 static void compose_set_title(Compose *compose)
2895 edited = compose->modified ? _(" [Edited]") : "";
2896 if (compose->account && compose->account->address)
2897 str = g_strdup_printf(_("%s - Compose message%s"),
2898 compose->account->address, edited);
2900 str = g_strdup_printf(_("Compose message%s"), edited);
2901 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2906 * compose_current_mail_account:
2908 * Find a current mail account (the currently selected account, or the
2909 * default account, if a news account is currently selected). If a
2910 * mail account cannot be found, display an error message.
2912 * Return value: Mail account, or NULL if not found.
2914 static PrefsAccount *
2915 compose_current_mail_account(void)
2919 if (cur_account && cur_account->protocol != A_NNTP)
2922 ac = account_get_default();
2923 if (!ac || ac->protocol == A_NNTP) {
2924 alertpanel_error(_("Account for sending mail is not specified.\n"
2925 "Please select a mail account before sending."));
2932 static void compose_select_account(Compose *compose, PrefsAccount *account,
2935 GtkWidget *menuitem;
2936 GtkItemFactory *ifactory;
2938 g_return_if_fail(account != NULL);
2940 compose->account = account;
2942 compose_set_title(compose);
2944 ifactory = gtk_item_factory_from_widget(compose->menubar);
2946 if (account->protocol == A_NNTP) {
2947 gtk_widget_show(compose->newsgroups_hbox);
2948 gtk_widget_show(compose->newsgroups_entry);
2949 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2950 compose->use_newsgroups = TRUE;
2952 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2953 gtk_check_menu_item_set_active
2954 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2955 gtk_widget_set_sensitive(menuitem, TRUE);
2956 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2957 gtk_check_menu_item_set_active
2958 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2959 gtk_widget_set_sensitive(menuitem, TRUE);
2961 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
2963 gtk_widget_hide(compose->newsgroups_hbox);
2964 gtk_widget_hide(compose->newsgroups_entry);
2965 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
2966 gtk_widget_queue_resize(compose->table_vbox);
2967 compose->use_newsgroups = FALSE;
2969 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2970 gtk_check_menu_item_set_active
2971 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2972 gtk_widget_set_sensitive(menuitem, FALSE);
2973 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2974 gtk_check_menu_item_set_active
2975 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2976 gtk_widget_set_sensitive(menuitem, FALSE);
2978 menuitem = gtk_item_factory_get_item(ifactory, "/View/Followup to");
2979 gtk_check_menu_item_set_active
2980 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2981 gtk_widget_set_sensitive(menuitem, FALSE);
2984 if (account->set_autocc) {
2985 compose_entry_show(compose, COMPOSE_ENTRY_CC);
2986 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
2987 compose_entry_set(compose, account->auto_cc,
2990 if (account->set_autobcc) {
2991 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
2992 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
2993 compose_entry_set(compose, account->auto_bcc,
2996 if (account->set_autoreplyto) {
2997 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
2998 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
2999 compose_entry_set(compose, account->auto_replyto,
3000 COMPOSE_ENTRY_REPLY_TO);
3003 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
3004 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3005 prefs_common.show_ruler);
3009 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
3010 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3011 account->default_sign);
3012 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
3013 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3014 account->default_encrypt);
3016 activate_gnupg_mode(compose, account);
3017 #endif /* USE_GPGME */
3019 if (!init && compose->mode != COMPOSE_REDIRECT)
3020 compose_insert_sig(compose, TRUE);
3023 gboolean compose_check_for_valid_recipient(Compose *compose) {
3024 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3025 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3026 gboolean recipient_found = FALSE;
3030 /* free to and newsgroup list */
3031 slist_free_strings(compose->to_list);
3032 g_slist_free(compose->to_list);
3033 compose->to_list = NULL;
3035 slist_free_strings(compose->newsgroup_list);
3036 g_slist_free(compose->newsgroup_list);
3037 compose->newsgroup_list = NULL;
3039 /* search header entries for to and newsgroup entries */
3040 for (list = compose->header_list; list; list = list->next) {
3043 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3044 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3046 if (entry[0] != '\0') {
3047 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3048 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3049 compose->to_list = address_list_append(compose->to_list, entry);
3050 recipient_found = TRUE;
3053 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3054 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3055 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3056 recipient_found = TRUE;
3063 return recipient_found;
3066 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3070 if (compose_check_for_valid_recipient(compose) == FALSE) {
3071 alertpanel_error(_("Recipient is not specified."));
3075 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3076 if (*str == '\0' && check_subject == TRUE) {
3079 aval = alertpanel(_("Send"),
3080 _("Subject is empty. Send it anyway?"),
3081 _("Yes"), _("No"), NULL);
3082 if (aval != G_ALERTDEFAULT)
3089 gint compose_send(Compose *compose)
3096 if (compose_check_entries(compose, TRUE) == FALSE)
3099 val = compose_queue(compose, &msgnum, &folder);
3101 alertpanel_error(_("Could not queue message for sending"));
3106 alertpanel_error(_("The message was queued but could not be sent.\nUse \"Send queued messages\" from the main window to retry."));
3110 msgpath = folder_item_fetch_msg(folder, msgnum);
3111 val = procmsg_send_message_queue(msgpath);
3114 folder_item_remove_msg(folder, msgnum);
3116 folder_item_scan(folder);
3121 #if 0 /* compose restructure */
3122 gint compose_send(Compose *compose)
3124 gchar tmp[MAXPATHLEN + 1];
3126 static gboolean lock = FALSE;
3130 g_return_val_if_fail(compose->account != NULL, -1);
3134 if (compose_check_entries(compose, TRUE) == FALSE) {
3139 /* write to temporary file */
3140 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
3141 get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3143 if (prefs_common.linewrap_at_send)
3144 compose_wrap_line_all(compose);
3146 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
3151 if (!compose->to_list && !compose->newsgroup_list) {
3152 g_warning("can't get recipient list.");
3158 if (compose->to_list) {
3161 #if 0 /* NEW COMPOSE GUI */
3162 if (compose->account->protocol != A_NNTP)
3163 ac = compose->account;
3165 ac = account_find_from_address(compose->account->address);
3167 if (cur_account && cur_account->protocol != A_NNTP)
3170 ac = account_get_default();
3172 if (!ac || ac->protocol == A_NNTP) {
3173 alertpanel_error(_("Account for sending mail is not specified.\n"
3174 "Please select a mail account before sending."));
3181 ac = compose->account;
3183 ok = send_message(tmp, ac, compose->to_list);
3186 if (ok == 0 && compose->newsgroup_list) {
3187 ok = news_post(FOLDER(compose->account->folder), tmp);
3189 alertpanel_error(_("Error occurred while posting the message to %s ."),
3190 compose->account->nntp_server);
3197 /* queue message if failed to send */
3199 if (prefs_common.queue_msg) {
3204 _("Error occurred while sending the message.\n"
3205 "Put this message into queue folder?"),
3206 _("OK"), _("Cancel"), NULL);
3207 if (G_ALERTDEFAULT == val) {
3208 ok = compose_queue(compose, tmp);
3210 alertpanel_error(_("Can't queue the message."));
3213 alertpanel_error_log(_("Error occurred while sending the message."));
3215 if (compose->mode == COMPOSE_REEDIT) {
3216 compose_remove_reedit_target(compose);
3218 /* save message to outbox */
3219 if (prefs_common.savemsg) {
3222 outbox = account_get_special_folder
3223 (compose->account, F_OUTBOX);
3224 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
3226 (_("Can't save the message to Sent."));
3236 static gboolean compose_use_attach(Compose *compose)
3238 return gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL;
3241 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3244 gchar buf[BUFFSIZE];
3246 gboolean first_to_address;
3247 gboolean first_cc_address;
3249 ComposeHeaderEntry *headerentry;
3250 gchar *headerentryname;
3254 debug_print("Writing redirect header\n");
3256 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3257 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3259 first_to_address = TRUE;
3260 first_cc_address = TRUE;
3261 for (list = compose->header_list; list; list = list->next) {
3262 headerentry = ((ComposeHeaderEntry *)list->data);
3263 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3265 if (g_strcasecmp(headerentryname, cc_hdr) == 0
3266 || g_strcasecmp(headerentryname, to_hdr) == 0) {
3267 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3268 Xstrdup_a(str, str, return -1);
3270 if (str[0] != '\0') {
3271 compose_convert_header
3272 (buf, sizeof(buf), str,
3273 strlen("Resent-To") + 2, TRUE);
3274 if (g_strcasecmp(headerentryname, to_hdr) == 0) {
3275 if (first_to_address) {
3276 fprintf(fp, "Resent-To: ");
3277 first_to_address = FALSE;
3282 if (g_strcasecmp(headerentryname, cc_hdr) == 0) {
3283 if (first_cc_address) {
3285 fprintf(fp, "Resent-Cc: ");
3286 first_cc_address = FALSE;
3292 fprintf(fp, "%s", buf);
3296 /* if (!first_address) { */
3303 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3305 gchar buf[BUFFSIZE];
3307 /* struct utsname utsbuf; */
3309 g_return_val_if_fail(fp != NULL, -1);
3310 g_return_val_if_fail(compose->account != NULL, -1);
3311 g_return_val_if_fail(compose->account->address != NULL, -1);
3314 get_rfc822_date(buf, sizeof(buf));
3315 fprintf(fp, "Resent-Date: %s\n", buf);
3318 if (compose->account->name && *compose->account->name) {
3319 compose_convert_header
3320 (buf, sizeof(buf), compose->account->name,
3321 strlen("From: "), TRUE);
3322 fprintf(fp, "Resent-From: %s <%s>\n",
3323 buf, compose->account->address);
3325 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3328 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3330 Xstrdup_a(str, str, return -1);
3333 compose_convert_header(buf, sizeof(buf), str,
3334 strlen("Subject: "), FALSE);
3335 fprintf(fp, "Subject: %s\n", buf);
3339 /* Resent-Message-ID */
3340 if (compose->account->gen_msgid) {
3341 compose_generate_msgid(buf, sizeof(buf));
3342 fprintf(fp, "Resent-Message-Id: <%s>\n", buf);
3343 compose->msgid = g_strdup(buf);
3346 compose_redirect_write_headers_from_headerlist(compose, fp);
3348 /* separator between header and body */
3354 static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
3359 gchar buf[BUFFSIZE];
3361 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3362 FILE_OP_ERROR(file, "fopen");
3366 if ((fdest = fopen(file, "wb")) == NULL) {
3367 FILE_OP_ERROR(file, "fopen");
3372 /* chmod for security */
3373 if (change_file_mode_rw(fdest, file) < 0) {
3374 FILE_OP_ERROR(file, "chmod");
3375 g_warning("can't change file mode\n");
3378 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3379 /* should filter returnpath, delivered-to */
3380 if (g_strncasecmp(buf, "Return-Path:",
3381 strlen("Return-Path:")) == 0 ||
3382 g_strncasecmp(buf, "Delivered-To:",
3383 strlen("Delivered-To:")) == 0 ||
3384 g_strncasecmp(buf, "Received:",
3385 strlen("Received:")) == 0 ||
3386 g_strncasecmp(buf, "Subject:",
3387 strlen("Subject:")) == 0 ||
3388 g_strncasecmp(buf, "X-UIDL:",
3389 strlen("X-UIDL:")) == 0)
3392 if (fputs(buf, fdest) == -1)
3395 if (!prefs_common.redirect_keep_from) {
3396 if (g_strncasecmp(buf, "From:",
3397 strlen("From:")) == 0) {
3398 fputs(" (by way of ", fdest);
3399 if (compose->account->name
3400 && *compose->account->name) {
3401 compose_convert_header
3403 compose->account->name,
3406 fprintf(fdest, "%s <%s>",
3408 compose->account->address);
3410 fprintf(fdest, "%s",
3411 compose->account->address);
3416 if (fputs("\n", fdest) == -1)
3420 compose_redirect_write_headers(compose, fdest);
3422 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3423 if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
3424 FILE_OP_ERROR(file, "fwrite");
3430 if (fclose(fdest) == EOF) {
3431 FILE_OP_ERROR(file, "fclose");
3447 /* interfaces to rfc2015 to keep out the prefs stuff there.
3448 * returns 0 on success and -1 on error. */
3449 static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
3451 const gchar *key_id = NULL;
3454 switch (compose->account->sign_key) {
3455 case SIGN_KEY_DEFAULT:
3458 case SIGN_KEY_BY_FROM:
3459 key_id = compose->account->address;
3461 case SIGN_KEY_CUSTOM:
3462 key_id = compose->account->sign_key_id;
3468 key_list = rfc2015_create_signers_list(key_id);
3471 alertpanel_error(_("Could not find any key associated with "
3472 "currently selected key id `%s'."), key_id);
3476 *pkey_list = key_list;
3480 /* clearsign message body text */
3481 static gint compose_clearsign_text(Compose *compose, gchar **text)
3486 tmp_file = get_tmp_file();
3487 if (str_write_to_file(*text, tmp_file) < 0) {
3492 if (compose_create_signers_list(compose, &key_list) < 0 ||
3493 rfc2015_clearsign(tmp_file, key_list) < 0) {
3500 *text = file_read_to_str(tmp_file);
3508 #endif /* USE_GPGME */
3510 static gint compose_write_to_file(Compose *compose, const gchar *file,
3518 const gchar *out_codeset;
3519 EncodingType encoding;
3521 if ((fp = fopen(file, "wb")) == NULL) {
3522 FILE_OP_ERROR(file, "fopen");
3526 /* chmod for security */
3527 if (change_file_mode_rw(fp, file) < 0) {
3528 FILE_OP_ERROR(file, "chmod");
3529 g_warning("can't change file mode\n");
3532 /* get all composed text */
3533 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3534 len = strlen(chars);
3535 if (is_ascii_str(chars)) {
3538 out_codeset = CS_US_ASCII;
3539 encoding = ENC_7BIT;
3541 const gchar *src_codeset;
3543 out_codeset = conv_get_outgoing_charset_str();
3544 if (!strcasecmp(out_codeset, CS_US_ASCII))
3545 out_codeset = CS_ISO_8859_1;
3547 if (prefs_common.encoding_method == CTE_BASE64)
3548 encoding = ENC_BASE64;
3549 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3550 encoding = ENC_QUOTED_PRINTABLE;
3551 else if (prefs_common.encoding_method == CTE_8BIT)
3552 encoding = ENC_8BIT;
3554 encoding = procmime_get_encoding_for_charset(out_codeset);
3558 compose->use_signing && !compose->gnupg_mode &&
3559 encoding == ENC_8BIT)
3560 encoding = ENC_BASE64;
3563 src_codeset = conv_get_current_charset_str();
3564 /* if current encoding is US-ASCII, set it the same as
3565 outgoing one to prevent code conversion failure */
3566 if (!strcasecmp(src_codeset, CS_US_ASCII))
3567 src_codeset = out_codeset;
3569 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3570 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3572 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3577 msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
3579 "Send it anyway?"), src_codeset, out_codeset);
3581 (_("Error"), msg, _("Yes"), _("+No"), NULL);
3584 if (aval != G_ALERTDEFAULT) {
3591 out_codeset = src_codeset;
3598 canon_buf = canonicalize_str(buf);
3603 if (!is_draft && compose->use_signing && compose->gnupg_mode) {
3604 if (compose_clearsign_text(compose, &buf) < 0) {
3605 g_warning("clearsign failed\n");
3615 if (compose_write_headers
3616 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3617 g_warning("can't write headers\n");
3624 if (compose_use_attach(compose)) {
3626 /* This prolog message is ignored by mime software and
3627 * because it would make our signing/encryption task
3628 * tougher, we don't emit it in that case */
3629 if (!compose->use_signing && !compose->use_encryption)
3631 fputs("This is a multi-part message in MIME format.\n", fp);
3633 fprintf(fp, "\n--%s\n", compose->boundary);
3634 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3637 if (compose->use_signing && !compose->gnupg_mode)
3638 fprintf(fp, "Content-Disposition: inline\n");
3640 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3641 procmime_get_encoding_str(encoding));
3647 if (encoding == ENC_BASE64) {
3648 gchar outbuf[B64_BUFFSIZE];
3651 for (i = 0; i < len; i += B64_LINE_SIZE) {
3652 l = MIN(B64_LINE_SIZE, len - i);
3653 base64_encode(outbuf, buf + i, l);
3657 } else if (encoding == ENC_QUOTED_PRINTABLE) {
3661 outbuf = g_malloc(len * 4);
3662 qp_encode_line(outbuf, buf);
3663 outlen = strlen(outbuf);
3664 if (fwrite(outbuf, sizeof(gchar), outlen, fp) != outlen) {
3665 FILE_OP_ERROR(file, "fwrite");
3673 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3674 FILE_OP_ERROR(file, "fwrite");
3682 if (compose_use_attach(compose))
3683 compose_write_attach(compose, fp);
3685 if (fclose(fp) == EOF) {
3686 FILE_OP_ERROR(file, "fclose");
3693 uncanonicalize_file_replace(file);
3697 if ((compose->use_signing && !compose->gnupg_mode) ||
3698 compose->use_encryption) {
3699 if (canonicalize_file_replace(file) < 0) {
3705 if (compose->use_signing && !compose->gnupg_mode) {
3708 if (compose_create_signers_list(compose, &key_list) < 0 ||
3709 rfc2015_sign(file, key_list) < 0) {
3714 if (compose->use_encryption) {
3715 if (rfc2015_encrypt(file, compose->to_list,
3716 compose->gnupg_mode) < 0) {
3721 #endif /* USE_GPGME */
3723 uncanonicalize_file_replace(file);
3728 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3734 if ((fp = fopen(file, "wb")) == NULL) {
3735 FILE_OP_ERROR(file, "fopen");
3739 /* chmod for security */
3740 if (change_file_mode_rw(fp, file) < 0) {
3741 FILE_OP_ERROR(file, "chmod");
3742 g_warning("can't change file mode\n");
3745 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3748 len = strlen(chars);
3749 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3750 FILE_OP_ERROR(file, "fwrite");
3759 if (fclose(fp) == EOF) {
3760 FILE_OP_ERROR(file, "fclose");
3767 static gint compose_remove_reedit_target(Compose *compose)
3770 MsgInfo *msginfo = compose->targetinfo;
3772 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3773 if (!msginfo) return -1;
3775 item = msginfo->folder;
3776 g_return_val_if_fail(item != NULL, -1);
3778 if (procmsg_msg_exist(msginfo) &&
3779 (item->stype == F_DRAFT || item->stype == F_QUEUE
3780 || msginfo == compose->autosaved_draft)) {
3781 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3782 g_warning("can't remove the old message\n");
3790 void compose_remove_draft(Compose *compose)
3793 MsgInfo *msginfo = compose->targetinfo;
3794 drafts = account_get_special_folder(compose->account, F_DRAFT);
3796 if (procmsg_msg_exist(msginfo)) {
3797 folder_item_remove_msg(drafts, msginfo->msgnum);
3802 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3804 return compose_queue_sub (compose, msgnum, item, FALSE);
3806 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3812 gchar buf[BUFFSIZE];
3814 static gboolean lock = FALSE;
3815 PrefsAccount *mailac = NULL, *newsac = NULL;
3817 debug_print("queueing message...\n");
3818 g_return_val_if_fail(compose->account != NULL, -1);
3822 if (compose_check_entries(compose, check_subject) == FALSE) {
3827 if (!compose->to_list && !compose->newsgroup_list) {
3828 g_warning("can't get recipient list.");
3833 if (compose->to_list) {
3834 if (compose->account->protocol != A_NNTP)
3835 mailac = compose->account;
3836 else if (cur_account && cur_account->protocol != A_NNTP)
3837 mailac = cur_account;
3838 else if (!(mailac = compose_current_mail_account())) {
3840 alertpanel_error(_("No account for sending mails available!"));
3845 if (compose->newsgroup_list) {
3846 if (compose->account->protocol == A_NNTP)
3847 newsac = compose->account;
3848 else if (!newsac->protocol != A_NNTP) {
3850 alertpanel_error(_("No account for posting news available!"));
3855 if (prefs_common.linewrap_at_send)
3856 compose_wrap_line_all(compose);
3858 /* write to temporary file */
3859 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3860 G_DIR_SEPARATOR, (gint)compose);
3862 if (compose->redirect_filename != NULL) {
3863 if (compose_redirect_write_to_file(compose, tmp2) < 0) {
3870 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3877 /* add queue header */
3878 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3879 G_DIR_SEPARATOR, (gint)compose);
3880 if ((fp = fopen(tmp, "wb")) == NULL) {
3881 FILE_OP_ERROR(tmp, "fopen");
3885 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3886 FILE_OP_ERROR(tmp2, "fopen");
3894 if (change_file_mode_rw(fp, tmp) < 0) {
3895 FILE_OP_ERROR(tmp, "chmod");
3896 g_warning("can't change file mode\n");
3899 /* queueing variables */
3900 fprintf(fp, "AF:\n");
3901 fprintf(fp, "NF:0\n");
3902 fprintf(fp, "PS:10\n");
3903 fprintf(fp, "SRH:1\n");
3904 fprintf(fp, "SFN:\n");
3905 fprintf(fp, "DSR:\n");
3907 fprintf(fp, "MID:<%s>\n", compose->msgid);
3909 fprintf(fp, "MID:\n");
3910 fprintf(fp, "CFG:\n");
3911 fprintf(fp, "PT:0\n");
3912 fprintf(fp, "S:%s\n", compose->account->address);
3913 fprintf(fp, "RQ:\n");
3915 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3917 fprintf(fp, "SSV:\n");
3919 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3921 fprintf(fp, "NSV:\n");
3922 fprintf(fp, "SSH:\n");
3923 /* write recepient list */
3924 if (compose->to_list) {
3925 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
3926 for (cur = compose->to_list->next; cur != NULL;
3928 fprintf(fp, ",<%s>", (gchar *)cur->data);
3931 /* write newsgroup list */
3932 if (compose->newsgroup_list) {
3934 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3935 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3936 fprintf(fp, ",%s", (gchar *)cur->data);
3939 /* Sylpheed account IDs */
3941 fprintf(fp, "MAID:%d\n", mailac->account_id);
3944 fprintf(fp, "NAID:%d\n", newsac->account_id);
3946 /* Save copy folder */
3947 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3948 gchar *savefolderid;
3950 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3951 fprintf(fp, "SCF:%s\n", savefolderid);
3952 g_free(savefolderid);
3954 /* Message-ID of message replying to */
3955 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
3958 folderid = folder_item_get_identifier(compose->replyinfo->folder);
3959 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
3962 /* Message-ID of message forwarding to */
3963 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
3966 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
3967 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
3972 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3973 if (fputs(buf, fp) == EOF) {
3974 FILE_OP_ERROR(tmp, "fputs");
3985 if (fclose(fp) == EOF) {
3986 FILE_OP_ERROR(tmp, "fclose");
3994 queue = account_get_special_folder(compose->account, F_QUEUE);
3996 g_warning("can't find queue folder\n");
4001 folder_item_scan(queue);
4002 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
4003 g_warning("can't queue the message\n");
4013 if (compose->mode == COMPOSE_REEDIT) {
4014 compose_remove_reedit_target(compose);
4017 if ((msgnum != NULL) && (item != NULL)) {
4025 static void compose_write_attach(Compose *compose, FILE *fp)
4028 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4031 gchar filename[BUFFSIZE];
4034 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
4036 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
4037 g_warning("Can't open file %s\n", ainfo->file);
4041 fprintf(fp, "\n--%s\n", compose->boundary);
4043 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
4044 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
4045 fprintf(fp, "Content-Disposition: inline\n");
4047 compose_convert_header(filename, sizeof(filename),
4048 ainfo->name, 12, FALSE);
4049 fprintf(fp, "Content-Type: %s;\n"
4051 ainfo->content_type, filename);
4052 fprintf(fp, "Content-Disposition: attachment;\n"
4053 " filename=\"%s\"\n", filename);
4056 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
4057 procmime_get_encoding_str(ainfo->encoding));
4059 if (ainfo->encoding == ENC_BASE64) {
4060 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
4062 while ((len = fread(inbuf, sizeof(gchar),
4063 B64_LINE_SIZE, attach_fp))
4065 base64_encode(outbuf, inbuf, B64_LINE_SIZE);
4069 if (len > 0 && feof(attach_fp)) {
4070 base64_encode(outbuf, inbuf, len);
4074 } else if (ainfo->encoding == ENC_QUOTED_PRINTABLE) {
4075 gchar inbuf[BUFFSIZE], outbuf[BUFFSIZE * 4];
4077 while (fgets(inbuf, sizeof(inbuf), attach_fp) != NULL) {
4078 qp_encode_line(outbuf, inbuf);
4082 gchar buf[BUFFSIZE];
4084 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
4093 fprintf(fp, "\n--%s--\n", compose->boundary);
4096 #define QUOTE_IF_REQUIRED(out, str) \
4098 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4102 len = strlen(str) + 3; \
4103 Xalloca(__tmp, len, return -1); \
4104 g_snprintf(__tmp, len, "\"%s\"", str); \
4107 Xstrdup_a(out, str, return -1); \
4111 #define PUT_RECIPIENT_HEADER(header, str) \
4113 if (*str != '\0') { \
4114 Xstrdup_a(str, str, return -1); \
4116 if (*str != '\0') { \
4117 compose->to_list = address_list_append \
4118 (compose->to_list, str); \
4119 compose_convert_header \
4120 (buf, sizeof(buf), str, strlen(header) + 2, \
4122 fprintf(fp, "%s: %s\n", header, buf); \
4127 #define IS_IN_CUSTOM_HEADER(header) \
4128 (compose->account->add_customhdr && \
4129 custom_header_find(compose->account->customhdr_list, header) != NULL)
4131 static gint compose_write_headers_from_headerlist(Compose *compose,
4133 const gchar *header,
4134 const gchar *seperator)
4136 gchar *str, *header_w_colon, *trans_hdr;
4137 gboolean write_header = FALSE;
4139 ComposeHeaderEntry *headerentry;
4140 gchar * headerentryname;
4143 if (IS_IN_CUSTOM_HEADER(header)) {
4147 debug_print("Writing %s-header\n", header);
4149 headerstr = g_string_sized_new(64);
4151 header_w_colon = g_strconcat(header, ":", NULL);
4152 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
4154 for (list = compose->header_list; list; list = list->next) {
4155 headerentry = ((ComposeHeaderEntry *)list->data);
4156 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4158 if (!g_strcasecmp(trans_hdr, headerentryname)) {
4159 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4160 Xstrdup_a(str, str, return -1);
4162 if (str[0] != '\0') {
4164 g_string_append(headerstr, seperator);
4165 g_string_append(headerstr, str);
4166 write_header = TRUE;
4173 buf = g_new0(gchar, headerstr->len * 4 + 256);
4174 compose_convert_header
4175 (buf, headerstr->len * 4 + 256, headerstr->str,
4176 strlen(header) + 2, TRUE);
4177 fprintf(fp, "%s: %s\n", header, buf);
4181 g_free(header_w_colon);
4182 g_string_free(headerstr, TRUE);
4187 static gint compose_write_headers(Compose *compose, FILE *fp,
4188 const gchar *charset, EncodingType encoding,
4191 gchar buf[BUFFSIZE];
4195 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4197 /* struct utsname utsbuf; */
4199 g_return_val_if_fail(fp != NULL, -1);
4200 g_return_val_if_fail(charset != NULL, -1);
4201 g_return_val_if_fail(compose->account != NULL, -1);
4202 g_return_val_if_fail(compose->account->address != NULL, -1);
4204 /* Save draft infos */
4206 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
4207 fprintf(fp, "S:%s\n", compose->account->address);
4208 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4209 gchar *savefolderid;
4211 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4212 fprintf(fp, "SCF:%s\n", savefolderid);
4213 g_free(savefolderid);
4219 if (compose->account->add_date) {
4220 get_rfc822_date(buf, sizeof(buf));
4221 fprintf(fp, "Date: %s\n", buf);
4225 if (compose->account->name && *compose->account->name) {
4226 compose_convert_header
4227 (buf, sizeof(buf), compose->account->name,
4228 strlen("From: "), TRUE);
4229 QUOTE_IF_REQUIRED(name, buf);
4230 fprintf(fp, "From: %s <%s>\n",
4231 name, compose->account->address);
4233 fprintf(fp, "From: %s\n", compose->account->address);
4236 compose_write_headers_from_headerlist(compose, fp, "To", ", ");
4237 #if 0 /* NEW COMPOSE GUI */
4238 if (compose->use_to) {
4239 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
4240 PUT_RECIPIENT_HEADER("To", str);
4245 compose_write_headers_from_headerlist(compose, fp, "Newsgroups", ",");
4246 #if 0 /* NEW COMPOSE GUI */
4247 if (compose->use_newsgroups) {
4248 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
4250 Xstrdup_a(str, str, return -1);
4254 compose->newsgroup_list =
4255 newsgroup_list_append
4256 (compose->newsgroup_list, str);
4257 compose_convert_header(buf, sizeof(buf), str,
4258 strlen("Newsgroups: "),
4260 fprintf(fp, "Newsgroups: %s\n", buf);
4266 compose_write_headers_from_headerlist(compose, fp, "Cc", ", ");
4267 #if 0 /* NEW COMPOSE GUI */
4268 if (compose->use_cc) {
4269 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
4270 PUT_RECIPIENT_HEADER("Cc", str);
4274 compose_write_headers_from_headerlist(compose, fp, "Bcc", ", ");
4275 #if 0 /* NEW COMPOSE GUI */
4276 if (compose->use_bcc) {
4277 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
4278 PUT_RECIPIENT_HEADER("Bcc", str);
4283 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4284 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4285 Xstrdup_a(str, str, return -1);
4288 compose_convert_header(buf, sizeof(buf), str,
4289 strlen("Subject: "), FALSE);
4290 fprintf(fp, "Subject: %s\n", buf);
4295 if (compose->account->gen_msgid) {
4296 compose_generate_msgid(buf, sizeof(buf));
4297 fprintf(fp, "Message-Id: <%s>\n", buf);
4298 compose->msgid = g_strdup(buf);
4301 if (compose->remove_references == FALSE) {
4303 if (compose->inreplyto && compose->to_list)
4304 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
4307 if (compose->references)
4308 fprintf(fp, "References: %s\n", compose->references);
4312 compose_write_headers_from_headerlist(compose, fp, "Followup-To", ",");
4313 #if 0 /* NEW COMPOSE GUI */
4314 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
4315 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
4317 Xstrdup_a(str, str, return -1);
4321 compose_convert_header(buf, sizeof(buf), str,
4322 strlen("Followup-To: "),
4324 fprintf(fp, "Followup-To: %s\n", buf);
4330 compose_write_headers_from_headerlist(compose, fp, "Reply-To", ", ");
4331 #if 0 /* NEW COMPOSE GUI */
4332 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
4333 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
4335 Xstrdup_a(str, str, return -1);
4338 compose_convert_header(buf, sizeof(buf), str,
4339 strlen("Reply-To: "),
4341 fprintf(fp, "Reply-To: %s\n", buf);
4347 if (compose->account->organization &&
4348 !IS_IN_CUSTOM_HEADER("Organization")) {
4349 compose_convert_header(buf, sizeof(buf),
4350 compose->account->organization,
4351 strlen("Organization: "), FALSE);
4352 fprintf(fp, "Organization: %s\n", buf);
4355 /* Program version and system info */
4356 /* uname(&utsbuf); */
4357 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4358 !compose->newsgroup_list) {
4359 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4361 gtk_major_version, gtk_minor_version, gtk_micro_version,
4363 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4365 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4366 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4368 gtk_major_version, gtk_minor_version, gtk_micro_version,
4370 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4373 /* custom headers */
4374 if (compose->account->add_customhdr) {
4377 for (cur = compose->account->customhdr_list; cur != NULL;
4379 CustomHeader *chdr = (CustomHeader *)cur->data;
4381 if (custom_header_is_allowed(chdr->name)) {
4382 compose_convert_header
4384 chdr->value ? chdr->value : "",
4385 strlen(chdr->name) + 2, FALSE);
4386 fprintf(fp, "%s: %s\n", chdr->name, buf);
4392 fprintf(fp, "Mime-Version: 1.0\n");
4393 if (compose_use_attach(compose)) {
4394 compose->boundary = generate_mime_boundary(NULL);
4396 "Content-Type: multipart/mixed;\n"
4397 " boundary=\"%s\"\n", compose->boundary);
4399 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
4401 if (compose->use_signing && !compose->gnupg_mode)
4402 fprintf(fp, "Content-Disposition: inline\n");
4404 fprintf(fp, "Content-Transfer-Encoding: %s\n",
4405 procmime_get_encoding_str(encoding));
4409 switch (compose->priority) {
4410 case PRIORITY_HIGHEST: fprintf(fp, "Importance: high\n"
4411 "X-Priority: 1 (Highest)\n");
4413 case PRIORITY_HIGH: fprintf(fp, "Importance: high\n"
4414 "X-Priority: 2 (High)\n");
4416 case PRIORITY_NORMAL: break;
4417 case PRIORITY_LOW: fprintf(fp, "Importance: low\n"
4418 "X-Priority: 4 (Low)\n");
4420 case PRIORITY_LOWEST: fprintf(fp, "Importance: low\n"
4421 "X-Priority: 5 (Lowest)\n");
4423 default: debug_print("compose: priority unknown : %d\n",
4427 /* Request Return Receipt */
4428 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4429 if (compose->return_receipt) {
4430 if (compose->account->name
4431 && *compose->account->name) {
4432 compose_convert_header(buf, sizeof(buf),
4433 compose->account->name,
4434 strlen("Disposition-Notification-To: "),
4436 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4438 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
4442 /* get special headers */
4443 for (list = compose->header_list; list; list = list->next) {
4444 ComposeHeaderEntry *headerentry;
4447 gchar *headername_wcolon;
4448 gchar *headername_trans;
4451 gboolean standard_header = FALSE;
4453 headerentry = ((ComposeHeaderEntry *)list->data);
4455 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4456 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4461 if (!strstr(tmp, ":")) {
4462 headername_wcolon = g_strconcat(tmp, ":", NULL);
4463 headername = g_strdup(tmp);
4465 headername_wcolon = g_strdup(tmp);
4466 headername = g_strdup(strtok(tmp, ":"));
4470 headervalue = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4471 subst_char(headervalue, '\r', ' ');
4472 subst_char(headervalue, '\n', ' ');
4473 string = std_headers;
4474 while (*string != NULL) {
4475 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4476 if (!strcmp(headername_trans,headername_wcolon))
4477 standard_header = TRUE;
4480 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4481 fprintf(fp, "%s %s\n", headername_wcolon, headervalue);
4484 g_free(headername_wcolon);
4487 /* separator between header and body */
4493 #undef IS_IN_CUSTOM_HEADER
4495 static void compose_convert_header(gchar *dest, gint len, gchar *src,
4496 gint header_len, gboolean addr_field)
4498 g_return_if_fail(src != NULL);
4499 g_return_if_fail(dest != NULL);
4501 if (len < 1) return;
4503 subst_char(src, '\n', ' ');
4504 subst_char(src, '\r', ' ');
4507 conv_encode_header(dest, len, src, header_len, addr_field);
4510 static void compose_generate_msgid(gchar *buf, gint len)
4519 addr = g_strconcat("@", get_domain_name(), NULL);
4521 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x%s",
4522 lt->tm_year + 1900, lt->tm_mon + 1,
4523 lt->tm_mday, lt->tm_hour,
4524 lt->tm_min, lt->tm_sec,
4525 (guint)random(), addr);
4527 debug_print("generated Message-ID: %s\n", buf);
4532 static void compose_create_header_entry(Compose *compose)
4534 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4538 GList *combo_list = NULL;
4539 gchar **string, *header = NULL;
4540 ComposeHeaderEntry *headerentry;
4541 gboolean standard_header = FALSE;
4543 headerentry = g_new0(ComposeHeaderEntry, 1);
4546 combo = gtk_combo_new();
4548 while(*string != NULL) {
4549 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4552 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4553 g_list_free(combo_list);
4554 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4555 gtk_widget_show(combo);
4556 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4557 if (compose->header_last) {
4558 gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4560 while (*string != NULL) {
4561 if (!strcmp(*string, last_header_entry))
4562 standard_header = TRUE;
4565 if (standard_header)
4566 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4568 if (!compose->header_last || !standard_header) {
4569 switch(compose->account->protocol) {
4571 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4574 header = prefs_common.trans_hdr ? _("To:") : "To:";
4579 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4582 entry = gtk_entry_new();
4583 gtk_widget_show(entry);
4584 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);
4586 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4587 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4588 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4589 gtk_signal_connect(GTK_OBJECT(entry), "button-press-event",
4590 GTK_SIGNAL_FUNC(compose_headerentry_button_pressed),
4593 address_completion_register_entry(GTK_ENTRY(entry));
4595 headerentry->compose = compose;
4596 headerentry->combo = combo;
4597 headerentry->entry = entry;
4598 headerentry->headernum = compose->header_nextrow;
4600 compose->header_nextrow++;
4601 compose->header_last = headerentry;
4604 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4606 ComposeHeaderEntry *last_header;
4608 last_header = compose->header_last;
4610 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4611 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4614 static GtkWidget *compose_create_header(Compose *compose)
4618 GtkWidget *from_optmenu_hbox;
4619 #if 0 /* NEW COMPOSE GUI */
4620 GtkWidget *to_entry;
4622 GtkWidget *newsgroups_entry;
4623 GtkWidget *newsgroups_hbox;
4625 GtkWidget *header_scrolledwin;
4626 GtkWidget *header_table;
4627 #if 0 /* NEW COMPOSE GUI */
4628 GtkWidget *cc_entry;
4630 GtkWidget *bcc_entry;
4631 GtkWidget *bcc_hbox;
4632 GtkWidget *reply_entry;
4633 GtkWidget *reply_hbox;
4634 GtkWidget *followup_entry;
4635 GtkWidget *followup_hbox;
4640 /* header labels and entries */
4641 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4642 gtk_widget_show(header_scrolledwin);
4643 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4645 header_table = gtk_table_new(2, 2, FALSE);
4646 gtk_widget_show(header_table);
4647 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4648 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4649 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4652 /* option menu for selecting accounts */
4653 hbox = gtk_hbox_new(FALSE, 0);
4654 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4655 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4656 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4658 from_optmenu_hbox = compose_account_option_menu_create(compose);
4659 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4660 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4661 #if 0 /* NEW COMPOSE GUI */
4662 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4666 compose->header_table = header_table;
4667 compose->header_list = NULL;
4668 compose->header_nextrow = count;
4670 compose_create_header_entry(compose);
4672 #if 0 /* NEW COMPOSE GUI */
4673 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4675 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4676 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4677 &count, "Newsgroups:", FALSE);
4678 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4680 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4682 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4684 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4685 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4687 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4688 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4690 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4691 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4692 "Followup-To:", FALSE);
4693 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4695 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4697 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4698 GTK_SIGNAL_FUNC(to_activated), compose);
4699 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4700 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4701 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4702 GTK_SIGNAL_FUNC(subject_activated), compose);
4703 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4704 GTK_SIGNAL_FUNC(cc_activated), compose);
4705 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4706 GTK_SIGNAL_FUNC(bcc_activated), compose);
4707 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4708 GTK_SIGNAL_FUNC(replyto_activated), compose);
4709 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4710 GTK_SIGNAL_FUNC(followupto_activated), compose);
4712 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4713 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4714 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4715 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4716 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4717 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4718 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4719 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4720 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4721 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4722 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4723 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4724 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4725 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4728 compose->table = NULL;
4729 #if 0 /* NEW COMPOSE GUI */
4730 compose->table = table;
4731 compose->to_hbox = to_hbox;
4732 compose->to_entry = to_entry;
4733 compose->newsgroups_hbox = newsgroups_hbox;
4734 compose->newsgroups_entry = newsgroups_entry;
4736 #if 0 /* NEW COMPOSE GUI */
4737 compose->cc_hbox = cc_hbox;
4738 compose->cc_entry = cc_entry;
4739 compose->bcc_hbox = bcc_hbox;
4740 compose->bcc_entry = bcc_entry;
4741 compose->reply_hbox = reply_hbox;
4742 compose->reply_entry = reply_entry;
4743 compose->followup_hbox = followup_hbox;
4744 compose->followup_entry = followup_entry;
4747 return header_scrolledwin ;
4750 GtkWidget *compose_create_attach(Compose *compose)
4752 gchar *titles[N_ATTACH_COLS];
4755 GtkWidget *attach_scrwin;
4756 GtkWidget *attach_clist;
4758 titles[COL_MIMETYPE] = _("MIME type");
4759 titles[COL_SIZE] = _("Size");
4760 titles[COL_NAME] = _("Name");
4762 /* attachment list */
4763 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4764 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4765 GTK_POLICY_AUTOMATIC,
4767 gtk_widget_set_usize(attach_scrwin, -1, 80);
4769 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4770 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4772 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4773 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4774 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4775 GTK_SELECTION_EXTENDED);
4776 for (i = 0; i < N_ATTACH_COLS; i++)
4777 GTK_WIDGET_UNSET_FLAGS
4778 (GTK_CLIST(attach_clist)->column[i].button,
4780 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4782 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4783 GTK_SIGNAL_FUNC(attach_selected), compose);
4784 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4785 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4786 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4787 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4790 gtk_drag_dest_set(attach_clist,
4791 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4792 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4793 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4794 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4797 compose->attach_scrwin = attach_scrwin;
4798 compose->attach_clist = attach_clist;
4800 return attach_scrwin;
4803 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4804 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4806 static GtkWidget *compose_create_others(Compose *compose)
4809 GtkWidget *savemsg_checkbtn;
4810 GtkWidget *savemsg_entry;
4811 GtkWidget *savemsg_select;
4814 gchar *folderidentifier;
4816 /* Table for settings */
4817 table = gtk_table_new(3, 1, FALSE);
4818 gtk_widget_show(table);
4819 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4822 /* Save Message to folder */
4823 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4824 gtk_widget_show(savemsg_checkbtn);
4825 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4826 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4827 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4829 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4830 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4832 savemsg_entry = gtk_entry_new();
4833 gtk_widget_show(savemsg_entry);
4834 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4835 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4836 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4837 folderidentifier = folder_item_get_identifier(account_get_special_folder
4838 (compose->account, F_OUTBOX));
4839 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4840 g_free(folderidentifier);
4843 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4844 gtk_widget_show (savemsg_select);
4845 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4846 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4847 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4852 compose->savemsg_checkbtn = savemsg_checkbtn;
4853 compose->savemsg_entry = savemsg_entry;
4858 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4860 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4861 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4864 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4869 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4872 path = folder_item_get_identifier(dest);
4874 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4878 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4884 GtkWidget *handlebox;
4886 GtkWidget *notebook;
4891 GtkWidget *subject_hbox;
4892 GtkWidget *subject_frame;
4893 GtkWidget *subject_entry;
4897 GtkWidget *edit_vbox;
4898 GtkWidget *ruler_hbox;
4900 GtkWidget *scrolledwin;
4903 UndoMain *undostruct;
4905 gchar *titles[N_ATTACH_COLS];
4906 guint n_menu_entries;
4907 GtkStyle *style, *new_style;
4910 gboolean success[1];
4911 GtkWidget *popupmenu;
4912 GtkItemFactory *popupfactory;
4913 GtkItemFactory *ifactory;
4914 GtkWidget *tmpl_menu;
4918 GtkAspell * gtkaspell = NULL;
4921 static GdkGeometry geometry;
4923 g_return_val_if_fail(account != NULL, NULL);
4925 debug_print("Creating compose window...\n");
4926 compose = g_new0(Compose, 1);
4928 titles[COL_MIMETYPE] = _("MIME type");
4929 titles[COL_SIZE] = _("Size");
4930 titles[COL_NAME] = _("Name");
4932 compose->account = account;
4934 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4935 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4936 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4937 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4939 if (!geometry.max_width) {
4940 geometry.max_width = gdk_screen_width();
4941 geometry.max_height = gdk_screen_height();
4943 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4944 &geometry, GDK_HINT_MAX_SIZE);
4945 gtk_widget_set_uposition(window, prefs_common.compose_x,
4946 prefs_common.compose_y);
4947 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4948 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4949 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4950 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4951 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4952 gtk_widget_realize(window);
4954 gtkut_widget_set_composer_icon(window);
4956 vbox = gtk_vbox_new(FALSE, 0);
4957 gtk_container_add(GTK_CONTAINER(window), vbox);
4959 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4960 menubar = menubar_create(window, compose_entries,
4961 n_menu_entries, "<Compose>", compose);
4962 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4964 handlebox = gtk_handle_box_new();
4965 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4967 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
4970 vbox2 = gtk_vbox_new(FALSE, 2);
4971 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4972 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4975 notebook = gtk_notebook_new();
4976 gtk_widget_set_usize(notebook, -1, 130);
4977 gtk_widget_show(notebook);
4979 /* header labels and entries */
4980 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4981 /* attachment list */
4982 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4984 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4987 subject_hbox = gtk_hbox_new(FALSE, 0);
4988 gtk_widget_show(subject_hbox);
4990 subject_frame = gtk_frame_new(NULL);
4991 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4992 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4993 gtk_widget_show(subject_frame);
4995 subject = gtk_hbox_new(FALSE, 0);
4996 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4997 gtk_widget_show(subject);
4999 label = gtk_label_new(_("Subject:"));
5000 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
5001 gtk_widget_show(label);
5003 subject_entry = gtk_entry_new();
5004 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
5005 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
5006 gtk_widget_show(subject_entry);
5007 compose->subject_entry = subject_entry;
5008 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5010 edit_vbox = gtk_vbox_new(FALSE, 0);
5011 #if 0 /* NEW COMPOSE GUI */
5012 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
5015 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5018 ruler_hbox = gtk_hbox_new(FALSE, 0);
5019 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5021 ruler = gtk_shruler_new();
5022 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5023 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5025 gtk_widget_set_usize(ruler_hbox, 1, -1);
5028 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5029 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5030 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
5031 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5032 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
5034 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
5035 (GTK_SCROLLED_WINDOW(scrolledwin)),
5036 gtk_scrolled_window_get_vadjustment
5037 (GTK_SCROLLED_WINDOW(scrolledwin)));
5038 GTK_STEXT(text)->default_tab_width = 8;
5039 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
5041 if (prefs_common.block_cursor) {
5042 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
5045 if (prefs_common.smart_wrapping) {
5046 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
5047 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
5050 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5052 gtk_signal_connect(GTK_OBJECT(text), "changed",
5053 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
5054 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
5055 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
5056 gtk_signal_connect(GTK_OBJECT(text), "activate",
5057 GTK_SIGNAL_FUNC(text_activated), compose);
5058 gtk_signal_connect(GTK_OBJECT(text), "insert_text",
5059 GTK_SIGNAL_FUNC(text_inserted), compose);
5060 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
5061 GTK_SIGNAL_FUNC(compose_button_press_cb),
5064 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
5065 GTK_SIGNAL_FUNC(compose_key_press_cb),
5068 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
5069 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
5073 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
5074 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5075 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
5076 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
5078 gtk_widget_show_all(vbox);
5080 /* pane between attach clist and text */
5081 paned = gtk_vpaned_new();
5082 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5083 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
5084 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5085 gtk_paned_add1(GTK_PANED(paned), notebook);
5086 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5087 gtk_widget_show_all(paned);
5089 style = gtk_widget_get_style(text);
5091 /* workaround for the slow down of GtkSText when using Pixmap theme */
5092 if (style->engine) {
5093 GtkThemeEngine *engine;
5095 engine = style->engine;
5096 style->engine = NULL;
5097 new_style = gtk_style_copy(style);
5098 style->engine = engine;
5100 new_style = gtk_style_copy(style);
5102 if (prefs_common.textfont) {
5105 if ((font = gtkut_font_load(prefs_common.textfont)) != NULL) {
5106 gdk_font_unref(new_style->font);
5107 new_style->font = font;
5111 gtk_widget_set_style(text, new_style);
5113 color[0] = quote_color;
5114 cmap = gdk_window_get_colormap(window->window);
5115 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5116 if (success[0] == FALSE) {
5117 g_warning("Compose: color allocation failed.\n");
5118 style = gtk_widget_get_style(text);
5119 quote_color = style->black;
5122 n_entries = sizeof(compose_popup_entries) /
5123 sizeof(compose_popup_entries[0]);
5124 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5125 "<Compose>", &popupfactory,
5128 ifactory = gtk_item_factory_from_widget(menubar);
5129 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5130 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5131 menu_set_sensitive(ifactory, "/Message/Remove references", FALSE);
5133 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5134 #if 0 /* NEW COMPOSE GUI */
5135 gtk_widget_hide(bcc_hbox);
5136 gtk_widget_hide(bcc_entry);
5137 gtk_widget_hide(reply_hbox);
5138 gtk_widget_hide(reply_entry);
5139 gtk_widget_hide(followup_hbox);
5140 gtk_widget_hide(followup_entry);
5141 gtk_widget_hide(ruler_hbox);
5142 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
5143 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
5144 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
5146 if (account->protocol == A_NNTP) {
5147 gtk_widget_hide(to_hbox);
5148 gtk_widget_hide(to_entry);
5149 gtk_widget_hide(cc_hbox);
5150 gtk_widget_hide(cc_entry);
5151 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
5152 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
5154 gtk_widget_hide(newsgroups_hbox);
5155 gtk_widget_hide(newsgroups_entry);
5156 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
5160 undostruct = undo_init(text);
5161 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5164 address_completion_start(window);
5166 compose->window = window;
5167 compose->vbox = vbox;
5168 compose->menubar = menubar;
5169 compose->handlebox = handlebox;
5171 compose->vbox2 = vbox2;
5173 compose->paned = paned;
5175 compose->edit_vbox = edit_vbox;
5176 compose->ruler_hbox = ruler_hbox;
5177 compose->ruler = ruler;
5178 compose->scrolledwin = scrolledwin;
5179 compose->text = text;
5181 compose->focused_editable = NULL;
5183 compose->popupmenu = popupmenu;
5184 compose->popupfactory = popupfactory;
5186 compose->tmpl_menu = tmpl_menu;
5188 compose->mode = mode;
5190 compose->targetinfo = NULL;
5191 compose->replyinfo = NULL;
5192 compose->fwdinfo = NULL;
5194 compose->replyto = NULL;
5196 compose->bcc = NULL;
5197 compose->followup_to = NULL;
5199 compose->ml_post = NULL;
5201 compose->inreplyto = NULL;
5202 compose->references = NULL;
5203 compose->msgid = NULL;
5204 compose->boundary = NULL;
5207 compose->use_signing = FALSE;
5208 compose->use_encryption = FALSE;
5209 #endif /* USE_GPGME */
5211 compose->modified = FALSE;
5213 compose->return_receipt = FALSE;
5215 compose->to_list = NULL;
5216 compose->newsgroup_list = NULL;
5218 compose->undostruct = undostruct;
5220 compose->sig_str = NULL;
5222 compose->exteditor_file = NULL;
5223 compose->exteditor_pid = -1;
5224 compose->exteditor_readdes = -1;
5225 compose->exteditor_tag = -1;
5228 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5229 if (mode != COMPOSE_REDIRECT) {
5230 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5231 strcmp(prefs_common.dictionary, _("None"))) {
5232 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5233 prefs_common.dictionary,
5234 conv_get_current_charset_str(),
5235 prefs_common.misspelled_col,
5236 prefs_common.check_while_typing,
5237 prefs_common.use_alternate,
5240 alertpanel_error(_("Spell checker could not "
5242 gtkaspell_checkers_strerror());
5243 gtkaspell_checkers_reset_error();
5246 GtkWidget *menuitem;
5248 if (!gtkaspell_set_sug_mode(gtkaspell,
5249 prefs_common.aspell_sugmode)) {
5250 debug_print("Aspell: could not set "
5251 "suggestion mode %s\n",
5252 gtkaspell_checkers_strerror());
5253 gtkaspell_checkers_reset_error();
5256 menuitem = gtk_item_factory_get_item(ifactory,
5257 "/Spelling/Spelling Configuration");
5258 gtkaspell_populate_submenu(gtkaspell, menuitem);
5259 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5263 compose->gtkaspell = gtkaspell;
5266 compose_select_account(compose, account, TRUE);
5268 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5269 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5271 if (account->set_autobcc)
5272 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5274 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5275 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5278 if (account->protocol != A_NNTP)
5279 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5281 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5283 addressbook_set_target_compose(compose);
5285 if (mode != COMPOSE_REDIRECT)
5286 compose_set_template_menu(compose);
5288 GtkWidget *menuitem;
5289 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5290 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5293 compose_list = g_list_append(compose_list, compose);
5295 if (!prefs_common.show_ruler)
5296 gtk_widget_hide(ruler_hbox);
5299 compose->priority = PRIORITY_NORMAL;
5300 compose_update_priority_menu_item(compose);
5303 compose_update_actions_menu(compose);
5306 activate_gnupg_mode(compose, account);
5308 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5309 gtk_widget_show(window);
5314 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5320 gint num = 0, def_menu = 0;
5322 accounts = account_get_list();
5323 g_return_val_if_fail(accounts != NULL, NULL);
5325 hbox = gtk_hbox_new(FALSE, 0);
5326 optmenu = gtk_option_menu_new();
5327 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5328 menu = gtk_menu_new();
5330 for (; accounts != NULL; accounts = accounts->next, num++) {
5331 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5332 GtkWidget *menuitem;
5335 if (ac == compose->account) def_menu = num;
5338 name = g_strdup_printf("%s: %s <%s>",
5340 ac->name, ac->address);
5342 name = g_strdup_printf("%s: %s",
5343 ac->account_name, ac->address);
5344 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5346 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
5347 GTK_SIGNAL_FUNC(account_activated),
5351 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5352 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5357 static void compose_set_priority_cb(gpointer data,
5361 Compose *compose = (Compose *) data;
5362 compose->priority = action;
5365 static void compose_update_priority_menu_item(Compose * compose)
5367 GtkItemFactory *ifactory;
5368 GtkWidget *menuitem = NULL;
5370 ifactory = gtk_item_factory_from_widget(compose->menubar);
5372 switch (compose->priority) {
5373 case PRIORITY_HIGHEST:
5374 menuitem = gtk_item_factory_get_item
5375 (ifactory, "/Message/Priority/Highest");
5378 menuitem = gtk_item_factory_get_item
5379 (ifactory, "/Message/Priority/High");
5381 case PRIORITY_NORMAL:
5382 menuitem = gtk_item_factory_get_item
5383 (ifactory, "/Message/Priority/Normal");
5386 menuitem = gtk_item_factory_get_item
5387 (ifactory, "/Message/Priority/Low");
5389 case PRIORITY_LOWEST:
5390 menuitem = gtk_item_factory_get_item
5391 (ifactory, "/Message/Priority/Lowest");
5394 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5398 static void compose_set_gnupg_mode_cb(gpointer data,
5402 Compose *compose = (Compose *) data;
5403 compose->gnupg_mode = action;
5406 static void compose_update_gnupg_mode_menu_item(Compose * compose)
5408 GtkItemFactory *ifactory;
5409 GtkWidget *menuitem = NULL;
5411 ifactory = gtk_item_factory_from_widget(compose->menubar);
5413 switch (compose->gnupg_mode) {
5414 case GNUPG_MODE_DETACH:
5415 menuitem = gtk_item_factory_get_item
5416 (ifactory, "/Message/Mode/MIME");
5418 case GNUPG_MODE_INLINE:
5419 menuitem = gtk_item_factory_get_item
5420 (ifactory, "/Message/Mode/Inline");
5423 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5425 if (compose->use_encryption == TRUE || compose->use_signing == TRUE)
5426 menu_set_sensitive(ifactory, "/Message/Mode", TRUE);
5428 menu_set_sensitive(ifactory, "/Message/Mode", FALSE);
5432 static void compose_set_template_menu(Compose *compose)
5434 GSList *tmpl_list, *cur;
5438 tmpl_list = template_get_config();
5440 menu = gtk_menu_new();
5442 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5443 Template *tmpl = (Template *)cur->data;
5445 item = gtk_menu_item_new_with_label(tmpl->name);
5446 gtk_menu_append(GTK_MENU(menu), item);
5447 gtk_signal_connect(GTK_OBJECT(item), "activate",
5448 GTK_SIGNAL_FUNC(compose_template_activate_cb),
5450 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
5451 gtk_widget_show(item);
5454 gtk_widget_show(menu);
5455 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5458 void compose_update_actions_menu(Compose *compose)
5460 GtkItemFactory *ifactory;
5462 ifactory = gtk_item_factory_from_widget(compose->menubar);
5463 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5466 void compose_reflect_prefs_all(void)
5471 for (cur = compose_list; cur != NULL; cur = cur->next) {
5472 compose = (Compose *)cur->data;
5473 compose_set_template_menu(compose);
5477 void compose_reflect_prefs_pixmap_theme(void)
5482 for (cur = compose_list; cur != NULL; cur = cur->next) {
5483 compose = (Compose *)cur->data;
5484 toolbar_update(TOOLBAR_COMPOSE, compose);
5488 static void compose_template_apply(Compose *compose, Template *tmpl,
5494 if (!tmpl || !tmpl->value) return;
5496 gtk_stext_freeze(GTK_STEXT(compose->text));
5498 if (tmpl->subject && *tmpl->subject != '\0')
5499 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5501 if (tmpl->to && *tmpl->to != '\0')
5502 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5503 if (tmpl->cc && *tmpl->cc != '\0')
5504 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5506 if (tmpl->bcc && *tmpl->bcc != '\0')
5507 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5510 gtkut_stext_clear(GTK_STEXT(compose->text));
5512 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
5513 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5516 if (prefs_common.quotemark && *prefs_common.quotemark)
5517 qmark = prefs_common.quotemark;
5521 if (compose->replyinfo != NULL)
5522 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5523 tmpl->value, qmark, NULL);
5524 else if (compose->fwdinfo != NULL)
5525 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
5526 tmpl->value, qmark, NULL);
5531 if (replace && parsed_str && compose->account->auto_sig)
5532 compose_insert_sig(compose, FALSE);
5534 if (replace && parsed_str) {
5535 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
5536 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
5540 compose_changed_cb(NULL, compose);
5542 gtk_stext_thaw(GTK_STEXT(compose->text));
5545 static void compose_destroy(Compose *compose)
5548 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5551 /* NOTE: address_completion_end() does nothing with the window
5552 * however this may change. */
5553 address_completion_end(compose->window);
5555 slist_free_strings(compose->to_list);
5556 g_slist_free(compose->to_list);
5557 slist_free_strings(compose->newsgroup_list);
5558 g_slist_free(compose->newsgroup_list);
5559 slist_free_strings(compose->header_list);
5560 g_slist_free(compose->header_list);
5562 procmsg_msginfo_free(compose->targetinfo);
5563 procmsg_msginfo_free(compose->replyinfo);
5564 procmsg_msginfo_free(compose->fwdinfo);
5566 g_free(compose->replyto);
5567 g_free(compose->cc);
5568 g_free(compose->bcc);
5569 g_free(compose->newsgroups);
5570 g_free(compose->followup_to);
5572 g_free(compose->ml_post);
5574 g_free(compose->inreplyto);
5575 g_free(compose->references);
5576 g_free(compose->msgid);
5577 g_free(compose->boundary);
5579 if (compose->redirect_filename)
5580 g_free(compose->redirect_filename);
5581 if (compose->undostruct)
5582 undo_destroy(compose->undostruct);
5584 g_free(compose->sig_str);
5586 g_free(compose->exteditor_file);
5588 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5590 compose_attach_info_free(ainfo);
5592 if (addressbook_get_target_compose() == compose)
5593 addressbook_set_target_compose(NULL);
5596 if (compose->gtkaspell) {
5597 gtkaspell_delete(compose->gtkaspell);
5601 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5602 prefs_common.compose_height = compose->window->allocation.height;
5604 gtk_widget_destroy(compose->paned);
5606 toolbar_destroy(compose->toolbar);
5607 g_free(compose->toolbar);
5610 compose_list = g_list_remove(compose_list, compose);
5613 static void compose_attach_info_free(AttachInfo *ainfo)
5615 g_free(ainfo->file);
5616 g_free(ainfo->content_type);
5617 g_free(ainfo->name);
5621 static void compose_attach_remove_selected(Compose *compose)
5623 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5627 while (clist->selection != NULL) {
5628 row = GPOINTER_TO_INT(clist->selection->data);
5629 ainfo = gtk_clist_get_row_data(clist, row);
5630 compose_attach_info_free(ainfo);
5631 gtk_clist_remove(clist, row);
5635 static struct _AttachProperty
5638 GtkWidget *mimetype_entry;
5639 GtkWidget *encoding_optmenu;
5640 GtkWidget *path_entry;
5641 GtkWidget *filename_entry;
5643 GtkWidget *cancel_btn;
5646 static void compose_attach_property(Compose *compose)
5648 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5651 GtkOptionMenu *optmenu;
5652 static gboolean cancelled;
5654 if (!clist->selection) return;
5655 row = GPOINTER_TO_INT(clist->selection->data);
5657 ainfo = gtk_clist_get_row_data(clist, row);
5660 if (!attach_prop.window)
5661 compose_attach_property_create(&cancelled);
5662 gtk_widget_grab_focus(attach_prop.ok_btn);
5663 gtk_widget_show(attach_prop.window);
5664 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5666 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5667 if (ainfo->encoding == ENC_UNKNOWN)
5668 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5669 GINT_TO_POINTER(ENC_BASE64));
5671 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5672 GINT_TO_POINTER(ainfo->encoding));
5674 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5675 ainfo->content_type ? ainfo->content_type : "");
5676 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5677 ainfo->file ? ainfo->file : "");
5678 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5679 ainfo->name ? ainfo->name : "");
5683 gchar *cnttype = NULL;
5687 GtkWidget *menuitem;
5692 if (cancelled == TRUE) {
5693 gtk_widget_hide(attach_prop.window);
5697 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5698 if (*text != '\0') {
5701 text = g_strstrip(g_strdup(text));
5702 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5703 cnttype = g_strdup(text);
5706 alertpanel_error(_("Invalid MIME type."));
5712 menu = gtk_option_menu_get_menu(optmenu);
5713 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5714 ainfo->encoding = GPOINTER_TO_INT
5715 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5717 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5718 if (*text != '\0') {
5719 if (is_file_exist(text) &&
5720 (size = get_file_size(text)) > 0)
5721 file = g_strdup(text);
5724 (_("File doesn't exist or is empty."));
5730 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5731 if (*text != '\0') {
5732 g_free(ainfo->name);
5733 ainfo->name = g_strdup(text);
5737 g_free(ainfo->content_type);
5738 ainfo->content_type = cnttype;
5741 g_free(ainfo->file);
5747 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5748 ainfo->content_type);
5749 gtk_clist_set_text(clist, row, COL_SIZE,
5750 to_human_readable(ainfo->size));
5751 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5753 gtk_widget_hide(attach_prop.window);
5758 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5760 label = gtk_label_new(str); \
5761 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5762 GTK_FILL, 0, 0, 0); \
5763 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5765 entry = gtk_entry_new(); \
5766 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5767 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5770 static void compose_attach_property_create(gboolean *cancelled)
5776 GtkWidget *mimetype_entry;
5779 GtkWidget *optmenu_menu;
5780 GtkWidget *menuitem;
5781 GtkWidget *path_entry;
5782 GtkWidget *filename_entry;
5785 GtkWidget *cancel_btn;
5786 GList *mime_type_list, *strlist;
5788 debug_print("Creating attach_property window...\n");
5790 window = gtk_window_new(GTK_WINDOW_DIALOG);
5791 gtk_widget_set_usize(window, 480, -1);
5792 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5793 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
5794 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5795 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5796 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5797 GTK_SIGNAL_FUNC(attach_property_delete_event),
5799 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5800 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5803 vbox = gtk_vbox_new(FALSE, 8);
5804 gtk_container_add(GTK_CONTAINER(window), vbox);
5806 table = gtk_table_new(4, 2, FALSE);
5807 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5808 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5809 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5811 label = gtk_label_new(_("MIME type"));
5812 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5814 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5815 mimetype_entry = gtk_combo_new();
5816 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5817 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5819 /* stuff with list */
5820 mime_type_list = procmime_get_mime_type_list();
5822 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5823 MimeType *type = (MimeType *) mime_type_list->data;
5824 strlist = g_list_append(strlist,
5825 g_strdup_printf("%s/%s",
5826 type->type, type->sub_type));
5829 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5831 for (mime_type_list = strlist; mime_type_list != NULL;
5832 mime_type_list = mime_type_list->next)
5833 g_free(mime_type_list->data);
5834 g_list_free(strlist);
5836 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5838 label = gtk_label_new(_("Encoding"));
5839 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5841 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5843 hbox = gtk_hbox_new(FALSE, 0);
5844 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5845 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5847 optmenu = gtk_option_menu_new();
5848 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5850 optmenu_menu = gtk_menu_new();
5851 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5852 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5854 gtk_widget_set_sensitive(menuitem, FALSE);
5856 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5857 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5859 gtk_widget_set_sensitive(menuitem, FALSE);
5861 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
5862 ENC_QUOTED_PRINTABLE);
5863 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5865 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5867 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5869 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5870 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5872 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5873 &cancel_btn, _("Cancel"), NULL, NULL);
5874 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5875 gtk_widget_grab_default(ok_btn);
5877 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5878 GTK_SIGNAL_FUNC(attach_property_ok),
5880 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5881 GTK_SIGNAL_FUNC(attach_property_cancel),
5884 gtk_widget_show_all(vbox);
5886 attach_prop.window = window;
5887 attach_prop.mimetype_entry = mimetype_entry;
5888 attach_prop.encoding_optmenu = optmenu;
5889 attach_prop.path_entry = path_entry;
5890 attach_prop.filename_entry = filename_entry;
5891 attach_prop.ok_btn = ok_btn;
5892 attach_prop.cancel_btn = cancel_btn;
5895 #undef SET_LABEL_AND_ENTRY
5897 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5903 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5909 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5910 gboolean *cancelled)
5918 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5919 gboolean *cancelled)
5921 if (event && event->keyval == GDK_Escape) {
5927 static void compose_exec_ext_editor(Compose *compose)
5933 tmp = g_strdup_printf("%s%ctmpmsg.%08x", get_tmp_dir(),
5934 G_DIR_SEPARATOR, (gint)compose);
5936 if (pipe(pipe_fds) < 0) {
5942 if ((pid = fork()) < 0) {
5949 /* close the write side of the pipe */
5952 compose->exteditor_file = g_strdup(tmp);
5953 compose->exteditor_pid = pid;
5954 compose->exteditor_readdes = pipe_fds[0];
5956 compose_set_ext_editor_sensitive(compose, FALSE);
5958 compose->exteditor_tag =
5959 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5960 compose_input_cb, compose);
5961 } else { /* process-monitoring process */
5967 /* close the read side of the pipe */
5970 if (compose_write_body_to_file(compose, tmp) < 0) {
5971 fd_write_all(pipe_fds[1], "2\n", 2);
5975 pid_ed = compose_exec_ext_editor_real(tmp);
5977 fd_write_all(pipe_fds[1], "1\n", 2);
5981 /* wait until editor is terminated */
5982 waitpid(pid_ed, NULL, 0);
5984 fd_write_all(pipe_fds[1], "0\n", 2);
5993 static gint compose_exec_ext_editor_real(const gchar *file)
5995 static gchar *def_cmd = "emacs %s";
6001 g_return_val_if_fail(file != NULL, -1);
6003 if ((pid = fork()) < 0) {
6008 if (pid != 0) return pid;
6010 /* grandchild process */
6012 if (setpgid(0, getppid()))
6015 if (prefs_common.ext_editor_cmd &&
6016 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6017 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6018 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6020 if (prefs_common.ext_editor_cmd)
6021 g_warning("External editor command line is invalid: `%s'\n",
6022 prefs_common.ext_editor_cmd);
6023 g_snprintf(buf, sizeof(buf), def_cmd, file);
6026 cmdline = strsplit_with_quote(buf, " ", 1024);
6027 execvp(cmdline[0], cmdline);
6030 g_strfreev(cmdline);
6035 static gboolean compose_ext_editor_kill(Compose *compose)
6037 pid_t pgid = compose->exteditor_pid * -1;
6040 ret = kill(pgid, 0);
6042 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6046 msg = g_strdup_printf
6047 (_("The external editor is still working.\n"
6048 "Force terminating the process?\n"
6049 "process group id: %d"), -pgid);
6050 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
6053 if (val == G_ALERTDEFAULT) {
6054 gdk_input_remove(compose->exteditor_tag);
6055 close(compose->exteditor_readdes);
6057 if (kill(pgid, SIGTERM) < 0) perror("kill");
6058 waitpid(compose->exteditor_pid, NULL, 0);
6060 g_warning("Terminated process group id: %d", -pgid);
6061 g_warning("Temporary file: %s",
6062 compose->exteditor_file);
6064 compose_set_ext_editor_sensitive(compose, TRUE);
6066 g_free(compose->exteditor_file);
6067 compose->exteditor_file = NULL;
6068 compose->exteditor_pid = -1;
6069 compose->exteditor_readdes = -1;
6070 compose->exteditor_tag = -1;
6078 static void compose_input_cb(gpointer data, gint source,
6079 GdkInputCondition condition)
6082 Compose *compose = (Compose *)data;
6085 debug_print("Compose: input from monitoring process\n");
6087 gdk_input_remove(compose->exteditor_tag);
6090 if (read(source, &buf[i], 1) < 1) {
6094 if (buf[i] == '\n') {
6099 if (i == sizeof(buf) - 1)
6103 waitpid(compose->exteditor_pid, NULL, 0);
6105 if (buf[0] == '0') { /* success */
6106 GtkSText *text = GTK_STEXT(compose->text);
6108 gtk_stext_freeze(text);
6109 gtk_stext_set_point(text, 0);
6110 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
6111 compose_insert_file(compose, compose->exteditor_file);
6112 compose_changed_cb(NULL, compose);
6113 gtk_stext_thaw(text);
6115 if (unlink(compose->exteditor_file) < 0)
6116 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6117 } else if (buf[0] == '1') { /* failed */
6118 g_warning("Couldn't exec external editor\n");
6119 if (unlink(compose->exteditor_file) < 0)
6120 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6121 } else if (buf[0] == '2') {
6122 g_warning("Couldn't write to file\n");
6123 } else if (buf[0] == '3') {
6124 g_warning("Pipe read failed\n");
6129 compose_set_ext_editor_sensitive(compose, TRUE);
6131 g_free(compose->exteditor_file);
6132 compose->exteditor_file = NULL;
6133 compose->exteditor_pid = -1;
6134 compose->exteditor_readdes = -1;
6135 compose->exteditor_tag = -1;
6138 static void compose_set_ext_editor_sensitive(Compose *compose,
6141 GtkItemFactory *ifactory;
6143 ifactory = gtk_item_factory_from_widget(compose->menubar);
6145 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6146 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6147 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
6149 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
6150 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
6151 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6152 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6153 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6156 gtk_widget_set_sensitive(compose->text, sensitive);
6157 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6158 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6159 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6160 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6161 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6162 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6163 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
6167 * compose_undo_state_changed:
6169 * Change the sensivity of the menuentries undo and redo
6171 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6172 gint redo_state, gpointer data)
6174 GtkWidget *widget = GTK_WIDGET(data);
6175 GtkItemFactory *ifactory;
6177 g_return_if_fail(widget != NULL);
6179 ifactory = gtk_item_factory_from_widget(widget);
6181 switch (undo_state) {
6182 case UNDO_STATE_TRUE:
6183 if (!undostruct->undo_state) {
6184 undostruct->undo_state = TRUE;
6185 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6188 case UNDO_STATE_FALSE:
6189 if (undostruct->undo_state) {
6190 undostruct->undo_state = FALSE;
6191 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6194 case UNDO_STATE_UNCHANGED:
6196 case UNDO_STATE_REFRESH:
6197 menu_set_sensitive(ifactory, "/Edit/Undo",
6198 undostruct->undo_state);
6201 g_warning("Undo state not recognized");
6205 switch (redo_state) {
6206 case UNDO_STATE_TRUE:
6207 if (!undostruct->redo_state) {
6208 undostruct->redo_state = TRUE;
6209 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6212 case UNDO_STATE_FALSE:
6213 if (undostruct->redo_state) {
6214 undostruct->redo_state = FALSE;
6215 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6218 case UNDO_STATE_UNCHANGED:
6220 case UNDO_STATE_REFRESH:
6221 menu_set_sensitive(ifactory, "/Edit/Redo",
6222 undostruct->redo_state);
6225 g_warning("Redo state not recognized");
6230 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
6234 cursor_pos = (text->cursor_pos_x - extra) / char_width;
6235 cursor_pos = MAX(cursor_pos, 0);
6240 /* callback functions */
6242 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6243 * includes "non-client" (windows-izm) in calculation, so this calculation
6244 * may not be accurate.
6246 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6247 GtkAllocation *allocation,
6248 GtkSHRuler *shruler)
6250 if (prefs_common.show_ruler) {
6252 gint line_width_in_chars;
6254 char_width = gtkut_get_font_width
6255 (GTK_WIDGET(widget)->style->font);
6256 line_width_in_chars =
6257 (allocation->width - allocation->x) / char_width;
6259 /* got the maximum */
6260 gtk_ruler_set_range(GTK_RULER(shruler),
6261 0.0, line_width_in_chars,
6262 calc_cursor_xpos(GTK_STEXT(widget),
6265 /*line_width_in_chars*/ char_width);
6271 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6273 Compose *compose = (Compose *)data;
6276 gchar *folderidentifier;
6278 ac = account_find_from_id(
6279 GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menuitem))));
6280 g_return_if_fail(ac != NULL);
6282 if (ac != compose->account)
6283 compose_select_account(compose, ac, FALSE);
6285 /* Set message save folder */
6286 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6287 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
6289 gtk_signal_connect(GTK_OBJECT(compose->savemsg_checkbtn), "toggled",
6290 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
6292 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6293 if (account_get_special_folder(compose->account, F_OUTBOX)) {
6294 folderidentifier = folder_item_get_identifier(account_get_special_folder
6295 (compose->account, F_OUTBOX));
6296 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
6297 g_free(folderidentifier);
6301 static void attach_selected(GtkCList *clist, gint row, gint column,
6302 GdkEvent *event, gpointer data)
6304 Compose *compose = (Compose *)data;
6306 if (event && event->type == GDK_2BUTTON_PRESS)
6307 compose_attach_property(compose);
6310 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6313 Compose *compose = (Compose *)data;
6314 GtkCList *clist = GTK_CLIST(compose->attach_clist);
6319 if (event->button == 3) {
6320 if ((clist->selection && !clist->selection->next) ||
6321 !clist->selection) {
6322 gtk_clist_unselect_all(clist);
6323 if (gtk_clist_get_selection_info(clist,
6326 gtk_clist_select_row(clist, row, column);
6327 gtkut_clist_set_focus_row(clist, row);
6330 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6331 NULL, NULL, event->button, event->time);
6335 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6338 Compose *compose = (Compose *)data;
6342 switch (event->keyval) {
6344 compose_attach_remove_selected(compose);
6349 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6351 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6352 toolbar_comp_set_sensitive(compose, allow);
6353 menu_set_sensitive(ifactory, "/File", allow);
6354 menu_set_sensitive(ifactory, "/Edit", allow);
6356 menu_set_sensitive(ifactory, "/Spelling", allow);
6358 menu_set_sensitive(ifactory, "/Message", allow);
6359 menu_set_sensitive(ifactory, "/Tools", allow);
6360 menu_set_sensitive(ifactory, "/Help", allow);
6363 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6365 Compose *compose = (Compose *)data;
6368 if (prefs_common.work_offline)
6369 if (alertpanel(_("Offline warning"),
6370 _("You're working offline. Override?"),
6371 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
6374 compose_allow_user_actions (compose, FALSE);
6375 compose->sending = TRUE;
6376 val = compose_send(compose);
6377 compose_allow_user_actions (compose, TRUE);
6378 compose->sending = FALSE;
6380 if (val == 0) gtk_widget_destroy(compose->window);
6383 static void compose_send_later_cb(gpointer data, guint action,
6386 Compose *compose = (Compose *)data;
6389 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6390 if (!val) gtk_widget_destroy(compose->window);
6393 void compose_draft (gpointer data)
6395 compose_draft_cb(data, 0, NULL);
6398 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6400 Compose *compose = (Compose *)data;
6404 MsgFlags flag = {0, 0};
6405 static gboolean lock = FALSE;
6406 MsgInfo *newmsginfo;
6410 draft = account_get_special_folder(compose->account, F_DRAFT);
6411 g_return_if_fail(draft != NULL);
6415 tmp = g_strdup_printf("%s%cdraft.%08x", get_tmp_dir(),
6416 G_DIR_SEPARATOR, (gint)compose);
6418 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
6424 folder_item_scan(draft);
6425 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
6432 draft->mtime = 0; /* force updating */
6434 if (compose->mode == COMPOSE_REEDIT) {
6435 compose_remove_reedit_target(compose);
6438 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6440 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6441 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
6442 procmsg_msginfo_free(newmsginfo);
6445 folder_item_scan(draft);
6449 /* 0: quit editing 1: keep editing 2: keep editing (autosave) */
6451 gtk_widget_destroy(compose->window);
6456 path = folder_item_fetch_msg(draft, msgnum);
6457 g_return_if_fail(path != NULL);
6458 if (stat(path, &s) < 0) {
6459 FILE_OP_ERROR(path, "stat");
6466 procmsg_msginfo_free(compose->targetinfo);
6467 compose->targetinfo = procmsg_msginfo_new();
6468 compose->targetinfo->msgnum = msgnum;
6469 compose->targetinfo->size = s.st_size;
6470 compose->targetinfo->mtime = s.st_mtime;
6471 compose->targetinfo->folder = draft;
6472 compose->mode = COMPOSE_REEDIT;
6475 compose->autosaved_draft = compose->targetinfo;
6480 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6482 Compose *compose = (Compose *)data;
6485 if (compose->redirect_filename != NULL)
6488 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6493 for ( tmp = file_list; tmp; tmp = tmp->next) {
6494 gchar *file = (gchar *) tmp->data;
6495 compose_attach_append(compose, file, file, NULL);
6496 compose_changed_cb(NULL, compose);
6499 g_list_free(file_list);
6503 static void compose_insert_file_cb(gpointer data, guint action,
6506 Compose *compose = (Compose *)data;
6509 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6514 for ( tmp = file_list; tmp; tmp = tmp->next) {
6515 gchar *file = (gchar *) tmp->data;
6516 gchar *filedup = g_strdup(file);
6518 ComposeInsertResult res;
6520 res = compose_insert_file(compose, file);
6521 shortfile = g_basename(filedup);
6522 if (res == COMPOSE_INSERT_READ_ERROR) {
6523 alertpanel_error(_("File '%s' could not be read."), shortfile);
6524 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
6525 alertpanel_error(_("File '%s' contained invalid characters\n"
6526 "for the current encoding, insertion may be incorrect."), shortfile);
6531 g_list_free(file_list);
6535 static void compose_insert_sig_cb(gpointer data, guint action,
6538 Compose *compose = (Compose *)data;
6540 compose_insert_sig(compose, FALSE);
6543 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6547 Compose *compose = (Compose *)data;
6549 gtkut_widget_get_uposition(widget, &x, &y);
6550 prefs_common.compose_x = x;
6551 prefs_common.compose_y = y;
6553 if (compose->sending)
6555 compose_close_cb(compose, 0, NULL);
6559 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6561 Compose *compose = (Compose *)data;
6564 if (compose->exteditor_tag != -1) {
6565 if (!compose_ext_editor_kill(compose))
6569 if (compose->modified) {
6570 val = alertpanel(_("Discard message"),
6571 _("This message has been modified. discard it?"),
6572 _("Discard"), _("to Draft"), _("Cancel"));
6575 case G_ALERTDEFAULT:
6576 if (prefs_common.autosave)
6577 compose_remove_draft(compose);
6579 case G_ALERTALTERNATE:
6580 compose_draft_cb(data, 0, NULL);
6587 gtk_widget_destroy(compose->window);
6590 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6592 Compose *compose = (Compose *)data;
6594 addressbook_open(compose);
6597 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6599 Compose *compose = (Compose *)data;
6604 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6605 g_return_if_fail(tmpl != NULL);
6607 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6609 val = alertpanel(_("Apply template"), msg,
6610 _("Replace"), _("Insert"), _("Cancel"));
6613 if (val == G_ALERTDEFAULT)
6614 compose_template_apply(compose, tmpl, TRUE);
6615 else if (val == G_ALERTALTERNATE)
6616 compose_template_apply(compose, tmpl, FALSE);
6619 static void compose_ext_editor_cb(gpointer data, guint action,
6622 Compose *compose = (Compose *)data;
6624 compose_exec_ext_editor(compose);
6627 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6629 if (compose->sending)
6631 compose_destroy(compose);
6634 static void compose_undo_cb(Compose *compose)
6636 undo_undo(compose->undostruct);
6639 static void compose_redo_cb(Compose *compose)
6641 undo_redo(compose->undostruct);
6644 static void compose_cut_cb(Compose *compose)
6646 if (compose->focused_editable &&
6647 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6648 gtk_editable_cut_clipboard
6649 (GTK_EDITABLE(compose->focused_editable));
6652 static void compose_copy_cb(Compose *compose)
6654 if (compose->focused_editable &&
6655 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6656 gtk_editable_copy_clipboard
6657 (GTK_EDITABLE(compose->focused_editable));
6660 static void compose_paste_cb(Compose *compose)
6662 if (compose->focused_editable &&
6663 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6664 gtk_editable_paste_clipboard
6665 (GTK_EDITABLE(compose->focused_editable));
6668 static void compose_paste_as_quote_cb(Compose *compose)
6670 if (compose->focused_editable &&
6671 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6672 /* let text_insert() (called directly or at a later time
6673 * after the gtk_editable_paste_clipboard) know that
6674 * text is to be inserted as a quotation. implemented
6675 * by using a simple refcount... */
6676 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data(
6677 GTK_OBJECT(compose->focused_editable),
6678 "paste_as_quotation"));
6679 gtk_object_set_data(GTK_OBJECT(compose->focused_editable),
6680 "paste_as_quotation",
6681 GINT_TO_POINTER(paste_as_quotation + 1));
6682 gtk_editable_paste_clipboard
6683 (GTK_EDITABLE(compose->focused_editable));
6687 static void compose_allsel_cb(Compose *compose)
6689 if (compose->focused_editable &&
6690 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6691 gtk_editable_select_region
6692 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6695 static void compose_gtk_stext_action_cb(Compose *compose,
6696 ComposeCallGtkSTextAction action)
6698 GtkSText *text = GTK_STEXT(compose->text);
6700 void (*do_action) (GtkSText *text);
6701 } action_table[] = {
6702 {gtk_stext_move_beginning_of_line},
6703 {gtk_stext_move_forward_character},
6704 {gtk_stext_move_backward_character},
6705 {gtk_stext_move_forward_word},
6706 {gtk_stext_move_backward_word},
6707 {gtk_stext_move_end_of_line},
6708 {gtk_stext_move_next_line},
6709 {gtk_stext_move_previous_line},
6710 {gtk_stext_delete_forward_character},
6711 {gtk_stext_delete_backward_character},
6712 {gtk_stext_delete_forward_word},
6713 {gtk_stext_delete_backward_word},
6714 {gtk_stext_delete_line},
6715 {gtk_stext_delete_line}, /* gtk_stext_delete_line_n */
6716 {gtk_stext_delete_to_line_end}
6719 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
6721 if (action >= COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE &&
6722 action <= COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END)
6723 action_table[action].do_action(text);
6726 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6728 if (GTK_IS_EDITABLE(widget))
6729 compose->focused_editable = widget;
6732 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6734 if (compose->modified == FALSE) {
6735 compose->modified = TRUE;
6736 compose_set_title(compose);
6740 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6743 gtk_stext_set_point(GTK_STEXT(widget),
6744 gtk_editable_get_position(GTK_EDITABLE(widget)));
6748 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6751 gtk_stext_set_point(GTK_STEXT(widget),
6752 gtk_editable_get_position(GTK_EDITABLE(widget)));
6756 #if 0 /* NEW COMPOSE GUI */
6757 static void compose_toggle_to_cb(gpointer data, guint action,
6760 Compose *compose = (Compose *)data;
6762 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6763 gtk_widget_show(compose->to_hbox);
6764 gtk_widget_show(compose->to_entry);
6765 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6766 compose->use_to = TRUE;
6768 gtk_widget_hide(compose->to_hbox);
6769 gtk_widget_hide(compose->to_entry);
6770 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6771 gtk_widget_queue_resize(compose->table_vbox);
6772 compose->use_to = FALSE;
6775 if (addressbook_get_target_compose() == compose)
6776 addressbook_set_target_compose(compose);
6779 static void compose_toggle_cc_cb(gpointer data, guint action,
6782 Compose *compose = (Compose *)data;
6784 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6785 gtk_widget_show(compose->cc_hbox);
6786 gtk_widget_show(compose->cc_entry);
6787 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6788 compose->use_cc = TRUE;
6790 gtk_widget_hide(compose->cc_hbox);
6791 gtk_widget_hide(compose->cc_entry);
6792 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6793 gtk_widget_queue_resize(compose->table_vbox);
6794 compose->use_cc = FALSE;
6797 if (addressbook_get_target_compose() == compose)
6798 addressbook_set_target_compose(compose);
6801 static void compose_toggle_bcc_cb(gpointer data, guint action,
6804 Compose *compose = (Compose *)data;
6806 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6807 gtk_widget_show(compose->bcc_hbox);
6808 gtk_widget_show(compose->bcc_entry);
6809 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6810 compose->use_bcc = TRUE;
6812 gtk_widget_hide(compose->bcc_hbox);
6813 gtk_widget_hide(compose->bcc_entry);
6814 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6815 gtk_widget_queue_resize(compose->table_vbox);
6816 compose->use_bcc = FALSE;
6819 if (addressbook_get_target_compose() == compose)
6820 addressbook_set_target_compose(compose);
6823 static void compose_toggle_replyto_cb(gpointer data, guint action,
6826 Compose *compose = (Compose *)data;
6828 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6829 gtk_widget_show(compose->reply_hbox);
6830 gtk_widget_show(compose->reply_entry);
6831 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6832 compose->use_replyto = TRUE;
6834 gtk_widget_hide(compose->reply_hbox);
6835 gtk_widget_hide(compose->reply_entry);
6836 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6837 gtk_widget_queue_resize(compose->table_vbox);
6838 compose->use_replyto = FALSE;
6842 static void compose_toggle_followupto_cb(gpointer data, guint action,
6845 Compose *compose = (Compose *)data;
6847 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6848 gtk_widget_show(compose->followup_hbox);
6849 gtk_widget_show(compose->followup_entry);
6850 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6851 compose->use_followupto = TRUE;
6853 gtk_widget_hide(compose->followup_hbox);
6854 gtk_widget_hide(compose->followup_entry);
6855 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6856 gtk_widget_queue_resize(compose->table_vbox);
6857 compose->use_followupto = FALSE;
6861 static void compose_toggle_attach_cb(gpointer data, guint action,
6864 Compose *compose = (Compose *)data;
6866 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6867 gtk_widget_ref(compose->edit_vbox);
6869 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6870 compose->edit_vbox);
6871 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6872 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6874 gtk_widget_show(compose->paned);
6876 gtk_widget_unref(compose->edit_vbox);
6877 gtk_widget_unref(compose->paned);
6879 compose->use_attach = TRUE;
6881 gtk_widget_ref(compose->paned);
6882 gtk_widget_ref(compose->edit_vbox);
6884 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6886 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6887 compose->edit_vbox);
6888 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6889 compose->edit_vbox, TRUE, TRUE, 0);
6891 gtk_widget_unref(compose->edit_vbox);
6893 compose->use_attach = FALSE;
6899 static void compose_toggle_sign_cb(gpointer data, guint action,
6902 Compose *compose = (Compose *)data;
6904 if (GTK_CHECK_MENU_ITEM(widget)->active)
6905 compose->use_signing = TRUE;
6907 compose->use_signing = FALSE;
6909 compose_update_gnupg_mode_menu_item(compose);
6912 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6915 Compose *compose = (Compose *)data;
6917 if (GTK_CHECK_MENU_ITEM(widget)->active)
6918 compose->use_encryption = TRUE;
6920 compose->use_encryption = FALSE;
6922 compose_update_gnupg_mode_menu_item(compose);
6925 static void activate_gnupg_mode (Compose *compose, PrefsAccount *account)
6927 if (account->default_gnupg_mode)
6928 compose->gnupg_mode = GNUPG_MODE_INLINE;
6930 compose->gnupg_mode = GNUPG_MODE_DETACH;
6932 compose_update_gnupg_mode_menu_item(compose);
6934 #endif /* USE_GPGME */
6936 static void compose_toggle_ruler_cb(gpointer data, guint action,
6939 Compose *compose = (Compose *)data;
6941 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6942 gtk_widget_show(compose->ruler_hbox);
6943 prefs_common.show_ruler = TRUE;
6945 gtk_widget_hide(compose->ruler_hbox);
6946 gtk_widget_queue_resize(compose->edit_vbox);
6947 prefs_common.show_ruler = FALSE;
6951 static void compose_attach_drag_received_cb (GtkWidget *widget,
6952 GdkDragContext *drag_context,
6955 GtkSelectionData *data,
6960 Compose *compose = (Compose *)user_data;
6963 list = uri_list_extract_filenames((const gchar *)data->data);
6964 for (tmp = list; tmp != NULL; tmp = tmp->next)
6965 compose_attach_append
6966 (compose, (const gchar *)tmp->data,
6967 (const gchar *)tmp->data, NULL);
6968 if (list) compose_changed_cb(NULL, compose);
6969 list_free_strings(list);
6973 static void compose_insert_drag_received_cb (GtkWidget *widget,
6974 GdkDragContext *drag_context,
6977 GtkSelectionData *data,
6982 Compose *compose = (Compose *)user_data;
6985 list = uri_list_extract_filenames((const gchar *)data->data);
6986 for (tmp = list; tmp != NULL; tmp = tmp->next)
6987 compose_insert_file(compose, (const gchar *)tmp->data);
6988 list_free_strings(list);
6992 #if 0 /* NEW COMPOSE GUI */
6993 static void to_activated(GtkWidget *widget, Compose *compose)
6995 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6996 gtk_widget_grab_focus(compose->newsgroups_entry);
6998 gtk_widget_grab_focus(compose->subject_entry);
7001 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
7003 gtk_widget_grab_focus(compose->subject_entry);
7006 static void subject_activated(GtkWidget *widget, Compose *compose)
7008 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
7009 gtk_widget_grab_focus(compose->cc_entry);
7010 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
7011 gtk_widget_grab_focus(compose->bcc_entry);
7012 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
7013 gtk_widget_grab_focus(compose->reply_entry);
7014 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
7015 gtk_widget_grab_focus(compose->followup_entry);
7017 gtk_widget_grab_focus(compose->text);
7020 static void cc_activated(GtkWidget *widget, Compose *compose)
7022 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
7023 gtk_widget_grab_focus(compose->bcc_entry);
7024 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
7025 gtk_widget_grab_focus(compose->reply_entry);
7026 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
7027 gtk_widget_grab_focus(compose->followup_entry);
7029 gtk_widget_grab_focus(compose->text);
7032 static void bcc_activated(GtkWidget *widget, Compose *compose)
7034 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
7035 gtk_widget_grab_focus(compose->reply_entry);
7036 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
7037 gtk_widget_grab_focus(compose->followup_entry);
7039 gtk_widget_grab_focus(compose->text);
7042 static void replyto_activated(GtkWidget *widget, Compose *compose)
7044 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
7045 gtk_widget_grab_focus(compose->followup_entry);
7047 gtk_widget_grab_focus(compose->text);
7050 static void followupto_activated(GtkWidget *widget, Compose *compose)
7052 gtk_widget_grab_focus(compose->text);
7056 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
7059 Compose *compose = (Compose *)data;
7061 if (GTK_CHECK_MENU_ITEM(widget)->active)
7062 compose->return_receipt = TRUE;
7064 compose->return_receipt = FALSE;
7067 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
7070 Compose *compose = (Compose *)data;
7072 if (GTK_CHECK_MENU_ITEM(widget)->active)
7073 compose->remove_references = TRUE;
7075 compose->remove_references = FALSE;
7078 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
7080 ComposeHeaderEntry *headerentry)
7082 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
7083 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
7084 !(event->state & GDK_MODIFIER_MASK) &&
7085 (event->keyval == GDK_BackSpace) &&
7086 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
7087 gtk_container_remove
7088 (GTK_CONTAINER(headerentry->compose->header_table),
7089 headerentry->combo);
7090 gtk_container_remove
7091 (GTK_CONTAINER(headerentry->compose->header_table),
7092 headerentry->entry);
7093 headerentry->compose->header_list =
7094 g_slist_remove(headerentry->compose->header_list,
7096 g_free(headerentry);
7097 } else if (event->keyval == GDK_Tab) {
7098 if (headerentry->compose->header_last == headerentry) {
7099 /* Override default next focus, and give it to subject_entry
7100 * instead of notebook tabs
7102 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
7103 gtk_widget_grab_focus(headerentry->compose->subject_entry);
7109 void compose_headerentry_changed_cb(GtkWidget *entry,
7110 ComposeHeaderEntry *headerentry)
7112 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
7113 headerentry->compose->header_list =
7114 g_slist_append(headerentry->compose->header_list,
7116 compose_create_header_entry(headerentry->compose);
7117 gtk_signal_disconnect_by_func
7119 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
7121 /* Automatically scroll down */
7122 compose_show_first_last_header(headerentry->compose, FALSE);
7127 static gboolean compose_headerentry_button_pressed
7128 (GtkWidget *entry, GdkEventButton *event, gpointer data)
7130 /* if this is a lclick, grab the focus */
7131 if (event->button == 1)
7132 gtk_widget_grab_focus(entry);
7136 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
7138 GtkAdjustment *vadj;
7140 g_return_if_fail(compose);
7141 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
7142 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
7144 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
7145 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
7148 static void text_activated(GtkWidget *widget, Compose *compose)
7150 compose_send_control_enter(compose);
7153 static void text_inserted(GtkWidget *widget, const gchar *text,
7154 gint length, gint *position, Compose *compose)
7156 GtkEditable *editable = GTK_EDITABLE(widget);
7157 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data
7158 (GTK_OBJECT(widget), "paste_as_quotation"));
7160 gtk_signal_handler_block_by_func(GTK_OBJECT(widget),
7161 GTK_SIGNAL_FUNC(text_inserted),
7163 if (paste_as_quotation) {
7168 new_text = g_strndup(text, length);
7169 if (prefs_common.quotemark && *prefs_common.quotemark)
7170 qmark = prefs_common.quotemark;
7173 gtk_stext_set_point(GTK_STEXT(widget), *position);
7174 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
7175 pos = gtk_stext_get_point(GTK_STEXT(widget));
7176 gtk_editable_set_position(editable, pos);
7179 gtk_object_set_data(GTK_OBJECT(widget), "paste_as_quotation",
7180 GINT_TO_POINTER(paste_as_quotation - 1));
7182 gtk_editable_insert_text(editable, text, length, position);
7184 if (prefs_common.autowrap)
7185 compose_wrap_line_all_full(compose, TRUE);
7187 gtk_signal_handler_unblock_by_func(GTK_OBJECT(widget),
7188 GTK_SIGNAL_FUNC(text_inserted),
7190 gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
7192 if (prefs_common.autosave &&
7193 gtk_stext_get_length(GTK_STEXT(widget)) % prefs_common.autosave_length == 0)
7194 gtk_timeout_add(500, (GtkFunction) compose_defer_auto_save_draft, compose);
7197 static gint compose_defer_auto_save_draft(Compose *compose)
7199 compose_draft_cb((gpointer)compose, 2, NULL);
7203 static gboolean compose_send_control_enter(Compose *compose)
7207 GtkItemFactory *ifactory;
7208 GtkAccelEntry *accel;
7209 GtkWidget *send_menu;
7211 GdkModifierType ignored_mods =
7212 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
7213 GDK_MOD4_MASK | GDK_MOD5_MASK);
7215 ev = gtk_get_current_event();
7216 if (ev->type != GDK_KEY_PRESS) return FALSE;
7218 kev = (GdkEventKey *)ev;
7219 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
7222 if (compose->exteditor_tag != -1)
7225 ifactory = gtk_item_factory_from_widget(compose->menubar);
7226 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
7227 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
7231 accel = (GtkAccelEntry *)list->data;
7232 if (accel && accel->accelerator_key == kev->keyval &&
7233 (accel->accelerator_mods & ~ignored_mods) ==
7234 (kev->state & ~ignored_mods)) {
7235 compose_send_cb(compose, 0, NULL);
7243 static void compose_check_all(Compose *compose)
7245 if (compose->gtkaspell)
7246 gtkaspell_check_all(compose->gtkaspell);
7249 static void compose_highlight_all(Compose *compose)
7251 if (compose->gtkaspell)
7252 gtkaspell_highlight_all(compose->gtkaspell);
7255 static void compose_check_backwards(Compose *compose)
7257 if (compose->gtkaspell)
7258 gtkaspell_check_backwards(compose->gtkaspell);
7260 GtkItemFactory *ifactory;
7261 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7262 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7263 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
7267 static void compose_check_forwards_go(Compose *compose)
7269 if (compose->gtkaspell)
7270 gtkaspell_check_forwards_go(compose->gtkaspell);
7272 GtkItemFactory *ifactory;
7273 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7274 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7275 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);