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 (Compose *compose,
265 static void compose_attach_info_free (AttachInfo *ainfo);
266 static void compose_attach_remove_selected (Compose *compose);
268 static void compose_attach_property (Compose *compose);
269 static void compose_attach_property_create (gboolean *cancelled);
270 static void attach_property_ok (GtkWidget *widget,
271 gboolean *cancelled);
272 static void attach_property_cancel (GtkWidget *widget,
273 gboolean *cancelled);
274 static gint attach_property_delete_event (GtkWidget *widget,
276 gboolean *cancelled);
277 static void attach_property_key_pressed (GtkWidget *widget,
279 gboolean *cancelled);
281 static void compose_exec_ext_editor (Compose *compose);
282 static gint compose_exec_ext_editor_real (const gchar *file);
283 static gboolean compose_ext_editor_kill (Compose *compose);
284 static void compose_input_cb (gpointer data,
286 GdkInputCondition condition);
287 static void compose_set_ext_editor_sensitive (Compose *compose,
290 static void compose_undo_state_changed (UndoMain *undostruct,
295 static gint calc_cursor_xpos (GtkSText *text,
299 static void compose_create_header_entry (Compose *compose);
300 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
301 static void compose_update_priority_menu_item(Compose * compose);
303 /* callback functions */
305 static gboolean compose_edit_size_alloc (GtkEditable *widget,
306 GtkAllocation *allocation,
307 GtkSHRuler *shruler);
308 static void account_activated (GtkMenuItem *menuitem,
310 static void attach_selected (GtkCList *clist,
315 static void attach_button_pressed (GtkWidget *widget,
316 GdkEventButton *event,
318 static void attach_key_pressed (GtkWidget *widget,
322 static void compose_send_cb (gpointer data,
325 static void compose_send_later_cb (gpointer data,
329 static void compose_draft_cb (gpointer data,
333 static void compose_attach_cb (gpointer data,
336 static void compose_insert_file_cb (gpointer data,
339 static void compose_insert_sig_cb (gpointer data,
343 static void compose_close_cb (gpointer data,
347 static void compose_address_cb (gpointer data,
350 static void compose_template_activate_cb(GtkWidget *widget,
353 static void compose_ext_editor_cb (gpointer data,
357 static gint compose_delete_cb (GtkWidget *widget,
360 static void compose_destroy_cb (GtkWidget *widget,
363 static void compose_undo_cb (Compose *compose);
364 static void compose_redo_cb (Compose *compose);
365 static void compose_cut_cb (Compose *compose);
366 static void compose_copy_cb (Compose *compose);
367 static void compose_paste_cb (Compose *compose);
368 static void compose_paste_as_quote_cb (Compose *compose);
369 static void compose_allsel_cb (Compose *compose);
371 static void compose_gtk_stext_action_cb (Compose *compose,
372 ComposeCallGtkSTextAction action);
374 static void compose_grab_focus_cb (GtkWidget *widget,
377 static void compose_changed_cb (GtkEditable *editable,
379 static void compose_button_press_cb (GtkWidget *widget,
380 GdkEventButton *event,
383 static void compose_key_press_cb (GtkWidget *widget,
389 static void compose_toggle_to_cb (gpointer data,
392 static void compose_toggle_cc_cb (gpointer data,
395 static void compose_toggle_bcc_cb (gpointer data,
398 static void compose_toggle_replyto_cb (gpointer data,
401 static void compose_toggle_followupto_cb(gpointer data,
404 static void compose_toggle_attach_cb (gpointer data,
408 static void compose_toggle_ruler_cb (gpointer data,
412 static void compose_toggle_sign_cb (gpointer data,
415 static void compose_toggle_encrypt_cb (gpointer data,
418 static void compose_set_gnupg_mode_cb (gpointer data,
421 static void compose_update_gnupg_mode_menu_item(Compose * compose);
422 static void activate_gnupg_mode (Compose *compose,
423 PrefsAccount *account);
425 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
427 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
429 static void compose_set_priority_cb (gpointer data,
433 static void compose_attach_drag_received_cb (GtkWidget *widget,
434 GdkDragContext *drag_context,
437 GtkSelectionData *data,
441 static void compose_insert_drag_received_cb (GtkWidget *widget,
442 GdkDragContext *drag_context,
445 GtkSelectionData *data,
451 static void to_activated (GtkWidget *widget,
453 static void newsgroups_activated (GtkWidget *widget,
455 static void cc_activated (GtkWidget *widget,
457 static void bcc_activated (GtkWidget *widget,
459 static void replyto_activated (GtkWidget *widget,
461 static void followupto_activated (GtkWidget *widget,
463 static void subject_activated (GtkWidget *widget,
467 static void text_activated (GtkWidget *widget,
469 static void text_inserted (GtkWidget *widget,
474 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
475 gboolean to_all, gboolean to_ml,
477 gboolean followup_and_reply_to,
480 void compose_headerentry_changed_cb (GtkWidget *entry,
481 ComposeHeaderEntry *headerentry);
482 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
484 ComposeHeaderEntry *headerentry);
486 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
489 static void compose_check_all (Compose *compose);
490 static void compose_highlight_all (Compose *compose);
491 static void compose_check_backwards (Compose *compose);
492 static void compose_check_forwards_go (Compose *compose);
495 static gboolean compose_send_control_enter (Compose *compose);
496 static gint compose_defer_auto_save_draft (Compose *compose);
498 static GtkItemFactoryEntry compose_popup_entries[] =
500 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
501 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
502 {N_("/---"), NULL, NULL, 0, "<Separator>"},
503 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
506 static GtkItemFactoryEntry compose_entries[] =
508 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
509 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
510 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
511 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
512 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
513 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
515 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
516 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
517 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
518 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
519 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
520 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
521 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
522 {N_("/_Edit/Paste as _quotation"),
523 NULL, compose_paste_as_quote_cb, 0, NULL},
524 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
525 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
526 {N_("/_Edit/A_dvanced/Move a character backward"),
528 compose_gtk_stext_action_cb,
529 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
531 {N_("/_Edit/A_dvanced/Move a character forward"),
533 compose_gtk_stext_action_cb,
534 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
536 {N_("/_Edit/A_dvanced/Move a word backward"),
538 compose_gtk_stext_action_cb,
539 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
541 {N_("/_Edit/A_dvanced/Move a word forward"),
543 compose_gtk_stext_action_cb,
544 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
546 {N_("/_Edit/A_dvanced/Move to beginning of line"),
547 NULL, /* "<control>A" */
548 compose_gtk_stext_action_cb,
549 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
551 {N_("/_Edit/A_dvanced/Move to end of line"),
553 compose_gtk_stext_action_cb,
554 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
556 {N_("/_Edit/A_dvanced/Move to previous line"),
558 compose_gtk_stext_action_cb,
559 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
561 {N_("/_Edit/A_dvanced/Move to next line"),
563 compose_gtk_stext_action_cb,
564 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
566 {N_("/_Edit/A_dvanced/Delete a character backward"),
568 compose_gtk_stext_action_cb,
569 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
571 {N_("/_Edit/A_dvanced/Delete a character forward"),
573 compose_gtk_stext_action_cb,
574 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
576 {N_("/_Edit/A_dvanced/Delete a word backward"),
577 NULL, /* "<control>W" */
578 compose_gtk_stext_action_cb,
579 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
581 {N_("/_Edit/A_dvanced/Delete a word forward"),
582 NULL, /* "<alt>D", */
583 compose_gtk_stext_action_cb,
584 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
586 {N_("/_Edit/A_dvanced/Delete line"),
588 compose_gtk_stext_action_cb,
589 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
591 {N_("/_Edit/A_dvanced/Delete entire line"),
593 compose_gtk_stext_action_cb,
594 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
596 {N_("/_Edit/A_dvanced/Delete to end of line"),
598 compose_gtk_stext_action_cb,
599 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
601 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
602 {N_("/_Edit/_Wrap current paragraph"),
603 "<control>L", compose_wrap_line, 0, NULL},
604 {N_("/_Edit/Wrap all long _lines"),
605 "<control><alt>L", compose_wrap_line_all, 0, NULL},
606 {N_("/_Edit/Edit with e_xternal editor"),
607 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
609 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
610 {N_("/_Spelling/_Check all or check selection"),
611 NULL, compose_check_all, 0, NULL},
612 {N_("/_Spelling/_Highlight all misspelled words"),
613 NULL, compose_highlight_all, 0, NULL},
614 {N_("/_Spelling/Check _backwards misspelled word"),
615 NULL, compose_check_backwards , 0, NULL},
616 {N_("/_Spelling/_Forward to next misspelled word"),
617 NULL, compose_check_forwards_go, 0, NULL},
618 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
619 {N_("/_Spelling/_Spelling Configuration"),
620 NULL, NULL, 0, "<Branch>"},
622 #if 0 /* NEW COMPOSE GUI */
623 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
624 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
625 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
626 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
627 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
628 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
629 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
630 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
631 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
632 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
633 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
635 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
636 {N_("/_Message/_Send"), "<control>Return",
637 compose_send_cb, 0, NULL},
638 {N_("/_Message/Send _later"), "<shift><control>S",
639 compose_send_later_cb, 0, NULL},
640 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
641 {N_("/_Message/Save to _draft folder"),
642 "<shift><control>D", compose_draft_cb, 0, NULL},
643 {N_("/_Message/Save and _keep editing"),
644 "<control>S", compose_draft_cb, 1, NULL},
645 #if 0 /* NEW COMPOSE GUI */
646 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
647 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
648 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
649 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
650 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
651 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
652 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
653 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
654 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
657 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
658 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
659 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
660 {N_("/_Message/Mode/MIME"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_DETACH, "<RadioItem>"},
661 {N_("/_Message/Mode/Inline"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_INLINE, "/Message/Mode/MIME"},
662 #endif /* USE_GPGME */
663 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
664 {N_("/_Message/_Priority"), NULL, NULL, 0, "<Branch>"},
665 {N_("/_Message/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
666 {N_("/_Message/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
667 {N_("/_Message/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
668 {N_("/_Message/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
669 {N_("/_Message/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
670 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
671 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
672 {N_("/_Message/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
673 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
674 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
675 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
676 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
677 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
678 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
679 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
682 static GtkTargetEntry compose_mime_types[] =
684 {"text/uri-list", 0, 0}
687 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
688 GPtrArray *attach_files)
690 return compose_generic_new(account, mailto, NULL, attach_files);
693 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
695 return compose_generic_new(account, NULL, item, NULL);
698 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
699 GPtrArray *attach_files)
703 GtkItemFactory *ifactory;
704 gboolean grab_focus_on_last = TRUE;
706 if (item && item->prefs && item->prefs->enable_default_account)
707 account = account_find_from_id(item->prefs->default_account);
709 if (!account) account = cur_account;
710 g_return_val_if_fail(account != NULL, NULL);
712 compose = compose_create(account, COMPOSE_NEW);
713 ifactory = gtk_item_factory_from_widget(compose->menubar);
715 compose->replyinfo = NULL;
716 compose->fwdinfo = NULL;
718 text = GTK_STEXT(compose->text);
719 gtk_stext_freeze(text);
722 if (item && item->prefs && item->prefs->enable_default_dictionary &&
724 gtkaspell_change_dict(compose->gtkaspell,
725 item->prefs->default_dictionary);
728 if (account->auto_sig)
729 compose_insert_sig(compose, FALSE);
730 gtk_editable_set_position(GTK_EDITABLE(text), 0);
731 gtk_stext_set_point(text, 0);
733 gtk_stext_thaw(text);
735 if (account->protocol != A_NNTP) {
736 if (mailto && *mailto != '\0') {
737 compose_entries_set(compose, mailto);
739 } else if (item && item->prefs->enable_default_to) {
740 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
741 compose_entry_select(compose, item->prefs->default_to);
742 grab_focus_on_last = FALSE;
744 if (item && item->ret_rcpt) {
745 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
749 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
752 * CLAWS: just don't allow return receipt request, even if the user
753 * may want to send an email. simple but foolproof.
755 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
762 for (i = 0; i < attach_files->len; i++) {
763 file = g_ptr_array_index(attach_files, i);
764 compose_attach_append(compose, file, file, NULL);
768 compose_show_first_last_header(compose, TRUE);
770 /* Set save folder */
771 if (item && item->prefs && item->prefs->save_copy_to_folder) {
772 gchar *folderidentifier;
774 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
775 folderidentifier = folder_item_get_identifier(item);
776 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
777 g_free(folderidentifier);
780 /* Grab focus on last header only if no default_to was set */
781 if (grab_focus_on_last)
782 gtk_widget_grab_focus(compose->header_last->entry);
784 if (prefs_common.auto_exteditor)
785 compose_exec_ext_editor(compose);
791 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
792 const gchar *followupto, gchar * to)
796 if (!account) account = cur_account;
797 g_return_val_if_fail(account != NULL, NULL);
798 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
800 compose = compose_create(account, COMPOSE_NEW);
802 if (prefs_common.auto_sig)
803 compose_insert_sig(compose);
804 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
805 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
807 compose_entry_append(compose, to, COMPOSE_TO);
808 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
809 gtk_widget_grab_focus(compose->subject_entry);
815 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
820 g_return_if_fail(msginfo_list != NULL);
822 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
823 g_return_if_fail(msginfo != NULL);
825 list_len = g_slist_length(msginfo_list);
829 compose_reply(msginfo, prefs_common.reply_with_quote,
830 FALSE, prefs_common.default_reply_list, FALSE, body);
832 case COMPOSE_REPLY_WITH_QUOTE:
833 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
835 case COMPOSE_REPLY_WITHOUT_QUOTE:
836 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
838 case COMPOSE_REPLY_TO_SENDER:
839 compose_reply(msginfo, prefs_common.reply_with_quote,
840 FALSE, FALSE, TRUE, body);
842 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
843 compose_followup_and_reply_to(msginfo,
844 prefs_common.reply_with_quote,
847 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
848 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
850 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
851 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
853 case COMPOSE_REPLY_TO_ALL:
854 compose_reply(msginfo, prefs_common.reply_with_quote,
855 TRUE, FALSE, FALSE, body);
857 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
858 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
860 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
861 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
863 case COMPOSE_REPLY_TO_LIST:
864 compose_reply(msginfo, prefs_common.reply_with_quote,
865 FALSE, TRUE, FALSE, body);
867 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
868 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
870 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
871 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
873 case COMPOSE_FORWARD:
874 if (prefs_common.forward_as_attachment) {
875 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
878 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
882 case COMPOSE_FORWARD_INLINE:
883 /* check if we reply to more than one Message */
885 compose_forward(NULL, msginfo, FALSE, body, FALSE);
888 /* more messages FALL THROUGH */
889 case COMPOSE_FORWARD_AS_ATTACH:
890 compose_forward_multiple(NULL, msginfo_list);
892 case COMPOSE_REDIRECT:
893 compose_redirect(NULL, msginfo);
896 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
900 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
901 gboolean to_ml, gboolean to_sender,
904 compose_generic_reply(msginfo, quote, to_all, to_ml,
905 to_sender, FALSE, body);
908 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
913 compose_generic_reply(msginfo, quote, to_all, FALSE,
914 to_sender, TRUE, body);
917 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
918 gboolean to_all, gboolean to_ml,
920 gboolean followup_and_reply_to,
923 GtkItemFactory *ifactory;
925 PrefsAccount *account = NULL;
926 PrefsAccount *reply_account;
929 g_return_if_fail(msginfo != NULL);
930 g_return_if_fail(msginfo->folder != NULL);
932 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
934 g_return_if_fail(account != NULL);
936 if (to_sender && account->protocol == A_NNTP &&
937 !followup_and_reply_to) {
939 account_find_from_address(account->address);
941 reply_account = compose_current_mail_account();
945 reply_account = account;
947 compose = compose_create(account, COMPOSE_REPLY);
948 ifactory = gtk_item_factory_from_widget(compose->menubar);
950 menu_set_toggle(ifactory, "/Message/Remove references", FALSE);
951 menu_set_sensitive(ifactory, "/Message/Remove references", TRUE);
953 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
954 if (!compose->replyinfo)
955 compose->replyinfo = procmsg_msginfo_copy(msginfo);
957 if (msginfo->folder && msginfo->folder->ret_rcpt)
958 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
960 /* Set save folder */
961 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
962 gchar *folderidentifier;
964 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
965 folderidentifier = folder_item_get_identifier(msginfo->folder);
966 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
967 g_free(folderidentifier);
970 if (compose_parse_header(compose, msginfo) < 0) return;
971 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
972 to_sender, followup_and_reply_to);
973 compose_show_first_last_header(compose, TRUE);
975 text = GTK_STEXT(compose->text);
976 gtk_stext_freeze(text);
979 if (msginfo->folder && msginfo->folder->prefs &&
980 msginfo->folder->prefs &&
981 msginfo->folder->prefs->enable_default_dictionary &&
983 gtkaspell_change_dict(compose->gtkaspell,
984 msginfo->folder->prefs->default_dictionary);
990 if (prefs_common.quotemark && *prefs_common.quotemark)
991 qmark = prefs_common.quotemark;
995 compose_quote_fmt(compose, compose->replyinfo,
996 prefs_common.quotefmt,
1000 if (account->auto_sig)
1001 compose_insert_sig(compose, FALSE);
1003 if (quote && prefs_common.linewrap_quote)
1004 compose_wrap_line_all(compose);
1006 gtk_editable_set_position(GTK_EDITABLE(text), 0);
1007 gtk_stext_set_point(text, 0);
1009 gtk_stext_thaw(text);
1010 gtk_widget_grab_focus(compose->text);
1012 if (prefs_common.auto_exteditor)
1013 compose_exec_ext_editor(compose);
1016 #define INSERT_FW_HEADER(var, hdr) \
1017 if (msginfo->var && *msginfo->var) { \
1018 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1019 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1020 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1023 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1024 gboolean as_attach, const gchar *body,
1025 gboolean no_extedit)
1030 g_return_val_if_fail(msginfo != NULL, NULL);
1031 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1033 if (msginfo->folder->prefs->enable_default_account)
1034 account = account_find_from_id(msginfo->folder->prefs->default_account);
1036 account = msginfo->folder->folder->account;
1037 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1039 Xstrdup_a(to, msginfo->to, return NULL);
1040 extract_address(to);
1041 account = account_find_from_address(to);
1044 if (!account && prefs_common.forward_account_autosel) {
1046 if (!procheader_get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1047 extract_address(cc);
1048 account = account_find_from_address(cc);
1052 if (account == NULL) {
1053 account = cur_account;
1055 account = msginfo->folder->folder->account;
1056 if (!account) account = cur_account;
1059 g_return_val_if_fail(account != NULL, NULL);
1061 compose = compose_create(account, COMPOSE_FORWARD);
1063 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1064 if (!compose->fwdinfo)
1065 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1067 if (msginfo->subject && *msginfo->subject) {
1068 gchar *buf, *buf2, *p;
1070 buf = p = g_strdup(msginfo->subject);
1071 p += subject_get_prefix_length(p);
1072 memmove(buf, p, strlen(p) + 1);
1074 buf2 = g_strdup_printf("Fw: %s", buf);
1075 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1081 text = GTK_STEXT(compose->text);
1082 gtk_stext_freeze(text);
1087 msgfile = procmsg_get_message_file_path(msginfo);
1088 if (!is_file_exist(msgfile))
1089 g_warning("%s: file not exist\n", msgfile);
1091 compose_attach_append(compose, msgfile, msgfile,
1097 MsgInfo *full_msginfo;
1099 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1101 full_msginfo = procmsg_msginfo_copy(msginfo);
1103 if (prefs_common.fw_quotemark &&
1104 *prefs_common.fw_quotemark)
1105 qmark = prefs_common.fw_quotemark;
1109 compose_quote_fmt(compose, full_msginfo,
1110 prefs_common.fw_quotefmt,
1112 compose_attach_parts(compose, msginfo);
1114 procmsg_msginfo_free(full_msginfo);
1117 if (account->auto_sig)
1118 compose_insert_sig(compose, FALSE);
1120 if (prefs_common.linewrap_quote)
1121 compose_wrap_line_all(compose);
1123 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1124 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1126 gtk_stext_thaw(text);
1127 #if 0 /* NEW COMPOSE GUI */
1128 if (account->protocol != A_NNTP)
1129 gtk_widget_grab_focus(compose->to_entry);
1131 gtk_widget_grab_focus(compose->newsgroups_entry);
1133 gtk_widget_grab_focus(compose->header_last->entry);
1135 if (!no_extedit && prefs_common.auto_exteditor)
1136 compose_exec_ext_editor(compose);
1139 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1140 gchar *folderidentifier;
1142 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1143 folderidentifier = folder_item_get_identifier(msginfo->folder);
1144 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1145 g_free(folderidentifier);
1151 #undef INSERT_FW_HEADER
1153 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1160 g_return_val_if_fail(msginfo_list != NULL, NULL);
1162 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1163 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1167 if (account == NULL) {
1168 account = cur_account;
1170 account = msginfo->folder->folder->account;
1171 if (!account) account = cur_account;
1174 g_return_val_if_fail(account != NULL, NULL);
1176 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1177 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1178 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1181 compose = compose_create(account, COMPOSE_FORWARD);
1183 text = GTK_STEXT(compose->text);
1184 gtk_stext_freeze(text);
1186 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1187 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1188 if (!is_file_exist(msgfile))
1189 g_warning("%s: file not exist\n", msgfile);
1191 compose_attach_append(compose, msgfile, msgfile,
1196 if (account->auto_sig)
1197 compose_insert_sig(compose, FALSE);
1199 if (prefs_common.linewrap_quote)
1200 compose_wrap_line_all(compose);
1202 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1203 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1205 gtk_stext_thaw(text);
1206 gtk_widget_grab_focus(compose->header_last->entry);
1208 #if 0 /* NEW COMPOSE GUI */
1209 if (account->protocol != A_NNTP)
1210 gtk_widget_grab_focus(compose->to_entry);
1212 gtk_widget_grab_focus(compose->newsgroups_entry);
1218 void compose_reedit(MsgInfo *msginfo)
1221 PrefsAccount *account = NULL;
1224 gchar buf[BUFFSIZE];
1226 g_return_if_fail(msginfo != NULL);
1227 g_return_if_fail(msginfo->folder != NULL);
1229 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1230 gchar queueheader_buf[BUFFSIZE];
1233 /* Select Account from queue headers */
1234 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1235 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1236 id = atoi(&queueheader_buf[22]);
1237 account = account_find_from_id(id);
1239 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1240 sizeof(queueheader_buf), "NAID:")) {
1241 id = atoi(&queueheader_buf[5]);
1242 account = account_find_from_id(id);
1244 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1245 sizeof(queueheader_buf), "MAID:")) {
1246 id = atoi(&queueheader_buf[5]);
1247 account = account_find_from_id(id);
1249 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1250 sizeof(queueheader_buf), "S:")) {
1251 account = account_find_from_address(queueheader_buf);
1254 account = msginfo->folder->folder->account;
1256 if (!account && prefs_common.reedit_account_autosel) {
1257 gchar from[BUFFSIZE];
1258 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1259 extract_address(from);
1260 account = account_find_from_address(from);
1263 if (!account) account = cur_account;
1264 g_return_if_fail(account != NULL);
1266 compose = compose_create(account, COMPOSE_REEDIT);
1267 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1269 if (msginfo->folder->stype == F_QUEUE
1270 || msginfo->folder->stype == F_DRAFT) {
1271 gchar queueheader_buf[BUFFSIZE];
1273 /* Set message save folder */
1274 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1277 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1278 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1279 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1283 if (compose_parse_header(compose, msginfo) < 0) return;
1284 compose_reedit_set_entry(compose, msginfo);
1286 text = GTK_STEXT(compose->text);
1287 gtk_stext_freeze(text);
1289 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1290 g_warning("Can't get text part\n");
1292 while (fgets(buf, sizeof(buf), fp) != NULL) {
1294 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1298 compose_attach_parts(compose, msginfo);
1300 gtk_stext_thaw(text);
1301 gtk_widget_grab_focus(compose->text);
1303 if (prefs_common.auto_exteditor)
1304 compose_exec_ext_editor(compose);
1307 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1311 GtkItemFactory *ifactory;
1314 g_return_val_if_fail(msginfo != NULL, NULL);
1317 account = account_get_reply_account(msginfo,
1318 prefs_common.reply_account_autosel);
1319 g_return_val_if_fail(account != NULL, NULL);
1321 compose = compose_create(account, COMPOSE_REDIRECT);
1322 ifactory = gtk_item_factory_from_widget(compose->menubar);
1324 compose->replyinfo = NULL;
1325 compose->fwdinfo = NULL;
1327 compose_show_first_last_header(compose, TRUE);
1329 gtk_widget_grab_focus(compose->header_last->entry);
1331 filename = procmsg_get_message_file(msginfo);
1332 if (filename == NULL)
1335 compose->redirect_filename = filename;
1337 /* Set save folder */
1338 item = msginfo->folder;
1339 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1340 gchar *folderidentifier;
1342 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1343 folderidentifier = folder_item_get_identifier(item);
1344 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1345 g_free(folderidentifier);
1348 compose_attach_parts(compose, msginfo);
1350 if (msginfo->subject)
1351 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1353 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1355 gtk_stext_freeze(GTK_STEXT(compose->text));
1356 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1357 gtk_editable_set_editable(GTK_EDITABLE(compose->text), FALSE);
1358 gtk_stext_thaw(GTK_STEXT(compose->text));
1360 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1361 menu_set_sensitive(ifactory, "/Add...", FALSE);
1362 menu_set_sensitive(ifactory, "/Remove", FALSE);
1363 menu_set_sensitive(ifactory, "/Property...", FALSE);
1365 ifactory = gtk_item_factory_from_widget(compose->menubar);
1366 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
1367 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
1368 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
1369 menu_set_sensitive(ifactory, "/Edit", FALSE);
1370 menu_set_sensitive(ifactory, "/Message/Save to draft folder", FALSE);
1371 menu_set_sensitive(ifactory, "/Message/Save and keep editing", FALSE);
1373 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
1374 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
1375 menu_set_sensitive(ifactory, "/Message/Mode/MIME", FALSE);
1376 menu_set_sensitive(ifactory, "/Message/Mode/Inline", FALSE);
1378 menu_set_sensitive(ifactory, "/Message/Priority", FALSE);
1379 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
1380 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1381 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1383 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1384 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1385 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1386 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1387 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1388 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, FALSE);
1393 GList *compose_get_compose_list(void)
1395 return compose_list;
1398 void compose_entry_append(Compose *compose, const gchar *address,
1399 ComposeEntryType type)
1403 if (!address || *address == '\0') return;
1405 #if 0 /* NEW COMPOSE GUI */
1408 entry = GTK_ENTRY(compose->cc_entry);
1411 entry = GTK_ENTRY(compose->bcc_entry);
1413 case COMPOSE_NEWSGROUPS:
1414 entry = GTK_ENTRY(compose->newsgroups_entry);
1418 entry = GTK_ENTRY(compose->to_entry);
1422 text = gtk_entry_get_text(entry);
1424 gtk_entry_append_text(entry, ", ");
1425 gtk_entry_append_text(entry, address);
1433 header = N_("Bcc:");
1435 case COMPOSE_REPLYTO:
1436 header = N_("Reply-To:");
1438 case COMPOSE_NEWSGROUPS:
1439 header = N_("Newsgroups:");
1441 case COMPOSE_FOLLOWUPTO:
1442 header = N_( "Followup-To:");
1449 header = prefs_common.trans_hdr ? gettext(header) : header;
1451 compose_add_header_entry(compose, header, (gchar *)address);
1454 void compose_entry_select (Compose *compose, const gchar *mailto)
1456 GSList *header_list;
1458 for (header_list = compose->header_list; header_list != NULL; header_list = header_list->next) {
1459 GtkEntry * entry = GTK_ENTRY(((ComposeHeaderEntry *)header_list->data)->entry);
1461 if (gtk_entry_get_text(entry) && !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1462 gtk_entry_select_region(entry, 0, -1);
1463 gtk_widget_grab_focus(GTK_WIDGET(entry));
1468 void compose_toolbar_cb(gint action, gpointer data)
1470 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1471 Compose *compose = (Compose*)toolbar_item->parent;
1473 g_return_if_fail(compose != NULL);
1477 compose_send_cb(compose, 0, NULL);
1480 compose_send_later_cb(compose, 0, NULL);
1483 compose_draft_cb(compose, 0, NULL);
1486 compose_insert_file_cb(compose, 0, NULL);
1489 compose_attach_cb(compose, 0, NULL);
1492 compose_insert_sig(compose, FALSE);
1495 compose_ext_editor_cb(compose, 0, NULL);
1498 compose_wrap_line(compose);
1501 compose_address_cb(compose, 0, NULL);
1508 static void compose_entries_set(Compose *compose, const gchar *mailto)
1513 gchar *subject = NULL;
1516 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1519 compose_entry_append(compose, to, COMPOSE_TO);
1521 compose_entry_append(compose, cc, COMPOSE_CC);
1523 compose_entry_append(compose, bcc, COMPOSE_BCC);
1525 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1527 gtk_stext_insert(GTK_STEXT(compose->text),
1528 NULL, NULL, NULL, body, -1);
1529 gtk_stext_insert(GTK_STEXT(compose->text),
1530 NULL, NULL, NULL, "\n", 1);
1540 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1542 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1543 {"Cc:", NULL, TRUE},
1544 {"References:", NULL, FALSE},
1545 {"Bcc:", NULL, TRUE},
1546 {"Newsgroups:", NULL, TRUE},
1547 {"Followup-To:", NULL, TRUE},
1548 {"List-Post:", NULL, FALSE},
1549 {"X-Priority:", NULL, FALSE},
1550 {NULL, NULL, FALSE}};
1566 g_return_val_if_fail(msginfo != NULL, -1);
1568 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1569 procheader_get_header_fields(fp, hentry);
1572 if (hentry[H_REPLY_TO].body != NULL) {
1573 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1574 compose->replyto = hentry[H_REPLY_TO].body;
1575 hentry[H_REPLY_TO].body = NULL;
1577 if (hentry[H_CC].body != NULL) {
1578 conv_unmime_header_overwrite(hentry[H_CC].body);
1579 compose->cc = hentry[H_CC].body;
1580 hentry[H_CC].body = NULL;
1582 if (hentry[H_REFERENCES].body != NULL) {
1583 if (compose->mode == COMPOSE_REEDIT)
1584 compose->references = hentry[H_REFERENCES].body;
1586 compose->references = compose_parse_references
1587 (hentry[H_REFERENCES].body, msginfo->msgid);
1588 g_free(hentry[H_REFERENCES].body);
1590 hentry[H_REFERENCES].body = NULL;
1592 if (hentry[H_BCC].body != NULL) {
1593 if (compose->mode == COMPOSE_REEDIT) {
1594 conv_unmime_header_overwrite(hentry[H_BCC].body);
1595 compose->bcc = hentry[H_BCC].body;
1597 g_free(hentry[H_BCC].body);
1598 hentry[H_BCC].body = NULL;
1600 if (hentry[H_NEWSGROUPS].body != NULL) {
1601 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1602 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1603 hentry[H_NEWSGROUPS].body = NULL;
1605 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1606 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1607 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1608 hentry[H_FOLLOWUP_TO].body = NULL;
1610 if (hentry[H_LIST_POST].body != NULL) {
1613 extract_address(hentry[H_LIST_POST].body);
1614 if (hentry[H_LIST_POST].body[0] != '\0') {
1615 scan_mailto_url(hentry[H_LIST_POST].body,
1616 &to, NULL, NULL, NULL, NULL);
1618 g_free(compose->ml_post);
1619 compose->ml_post = to;
1622 g_free(hentry[H_LIST_POST].body);
1623 hentry[H_LIST_POST].body = NULL;
1626 /* CLAWS - X-Priority */
1627 if (compose->mode == COMPOSE_REEDIT)
1628 if (hentry[H_X_PRIORITY].body != NULL) {
1631 priority = atoi(hentry[H_X_PRIORITY].body);
1632 g_free(hentry[H_X_PRIORITY].body);
1634 hentry[H_X_PRIORITY].body = NULL;
1636 if (priority < PRIORITY_HIGHEST ||
1637 priority > PRIORITY_LOWEST)
1638 priority = PRIORITY_NORMAL;
1640 compose->priority = priority;
1643 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1644 compose->inreplyto = g_strdup(msginfo->inreplyto);
1645 else if (compose->mode != COMPOSE_REEDIT &&
1646 msginfo->msgid && *msginfo->msgid) {
1647 compose->inreplyto = g_strdup(msginfo->msgid);
1649 if (!compose->references) {
1650 if (msginfo->inreplyto && *msginfo->inreplyto)
1651 compose->references =
1652 g_strdup_printf("<%s>\n\t<%s>",
1656 compose->references =
1657 g_strconcat("<", msginfo->msgid, ">",
1665 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1667 GSList *ref_id_list, *cur;
1671 ref_id_list = references_list_append(NULL, ref);
1672 if (!ref_id_list) return NULL;
1673 if (msgid && *msgid)
1674 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1679 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1680 /* "<" + Message-ID + ">" + CR+LF+TAB */
1681 len += strlen((gchar *)cur->data) + 5;
1683 if (len > MAX_REFERENCES_LEN) {
1684 /* remove second message-ID */
1685 if (ref_id_list && ref_id_list->next &&
1686 ref_id_list->next->next) {
1687 g_free(ref_id_list->next->data);
1688 ref_id_list = g_slist_remove
1689 (ref_id_list, ref_id_list->next->data);
1691 slist_free_strings(ref_id_list);
1692 g_slist_free(ref_id_list);
1699 new_ref = g_string_new("");
1700 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1701 if (new_ref->len > 0)
1702 g_string_append(new_ref, "\n\t");
1703 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1706 slist_free_strings(ref_id_list);
1707 g_slist_free(ref_id_list);
1709 new_ref_str = new_ref->str;
1710 g_string_free(new_ref, FALSE);
1715 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1716 const gchar *fmt, const gchar *qmark,
1719 GtkSText *text = GTK_STEXT(compose->text);
1720 static MsgInfo dummyinfo;
1721 gchar *quote_str = NULL;
1725 const gchar *trimmed_body = body;
1728 msginfo = &dummyinfo;
1730 if (qmark != NULL) {
1731 quote_fmt_init(msginfo, NULL, NULL);
1732 quote_fmt_scan_string(qmark);
1735 buf = quote_fmt_get_buffer();
1737 alertpanel_error(_("Quote mark format error."));
1739 Xstrdup_a(quote_str, buf, return NULL)
1742 if (fmt && *fmt != '\0') {
1743 while (trimmed_body && strlen(trimmed_body) > 1
1744 && trimmed_body[0]=='\n')
1747 quote_fmt_init(msginfo, quote_str, trimmed_body);
1748 quote_fmt_scan_string(fmt);
1751 buf = quote_fmt_get_buffer();
1753 alertpanel_error(_("Message reply/forward format error."));
1759 gtk_stext_freeze(text);
1761 for (p = buf; *p != '\0'; ) {
1762 lastp = strchr(p, '\n');
1763 len = lastp ? lastp - p + 1 : -1;
1764 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1771 gtk_stext_thaw(text);
1776 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1777 gboolean to_all, gboolean to_ml,
1779 gboolean followup_and_reply_to)
1781 GSList *cc_list = NULL;
1784 gchar *replyto = NULL;
1785 GHashTable *to_table;
1787 g_return_if_fail(compose->account != NULL);
1788 g_return_if_fail(msginfo != NULL);
1790 if (compose->account->protocol != A_NNTP) {
1791 if (!compose->replyto && to_ml && compose->ml_post
1792 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1793 compose_entry_append(compose,
1796 else if (!(to_all || to_sender)
1798 && msginfo->folder->prefs->enable_default_reply_to) {
1799 compose_entry_append(compose,
1800 msginfo->folder->prefs->default_reply_to,
1803 compose_entry_append(compose,
1804 (compose->replyto && !to_sender)
1805 ? compose->replyto :
1806 msginfo->from ? msginfo->from : "",
1809 if (to_sender || (compose->followup_to &&
1810 !strncmp(compose->followup_to, "poster", 6)))
1811 compose_entry_append
1813 (compose->replyto ? compose->replyto :
1814 msginfo->from ? msginfo->from : ""),
1817 else if (followup_and_reply_to || to_all) {
1818 compose_entry_append
1820 (compose->replyto ? compose->replyto :
1821 msginfo->from ? msginfo->from : ""),
1824 compose_entry_append
1826 compose->followup_to ? compose->followup_to :
1827 compose->newsgroups ? compose->newsgroups : "",
1828 COMPOSE_NEWSGROUPS);
1831 compose_entry_append
1833 compose->followup_to ? compose->followup_to :
1834 compose->newsgroups ? compose->newsgroups : "",
1835 COMPOSE_NEWSGROUPS);
1838 if (msginfo->subject && *msginfo->subject) {
1839 gchar *buf, *buf2, *p;
1841 buf = p = g_strdup(msginfo->subject);
1842 p += subject_get_prefix_length(p);
1843 memmove(buf, p, strlen(p) + 1);
1845 buf2 = g_strdup_printf("Re: %s", buf);
1846 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1851 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1853 if (to_ml && compose->ml_post) return;
1854 if (!to_all || compose->account->protocol == A_NNTP) return;
1856 if (compose->replyto) {
1857 Xstrdup_a(replyto, compose->replyto, return);
1858 extract_address(replyto);
1860 if (msginfo->from) {
1861 Xstrdup_a(from, msginfo->from, return);
1862 extract_address(from);
1865 if (replyto && from)
1866 cc_list = address_list_append_with_comments(cc_list, from);
1867 if (to_all && msginfo->folder &&
1868 msginfo->folder->prefs->enable_default_reply_to)
1869 cc_list = address_list_append_with_comments(cc_list,
1870 msginfo->folder->prefs->default_reply_to);
1871 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1872 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1874 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1876 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1877 if (compose->account)
1878 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1879 GINT_TO_POINTER(1));
1881 /* remove address on To: and that of current account */
1882 for (cur = cc_list; cur != NULL; ) {
1883 GSList *next = cur->next;
1886 addr = g_strdup(cur->data);
1887 extract_address(addr);
1889 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
1890 cc_list = g_slist_remove(cc_list, cur->data);
1892 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
1896 hash_free_strings(to_table);
1897 g_hash_table_destroy(to_table);
1900 for (cur = cc_list; cur != NULL; cur = cur->next)
1901 compose_entry_append(compose, (gchar *)cur->data,
1903 slist_free_strings(cc_list);
1904 g_slist_free(cc_list);
1909 #define SET_ENTRY(entry, str) \
1912 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1915 #define SET_ADDRESS(type, str) \
1918 compose_entry_append(compose, str, type); \
1921 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1923 g_return_if_fail(msginfo != NULL);
1925 SET_ENTRY(subject_entry, msginfo->subject);
1926 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1927 SET_ADDRESS(COMPOSE_CC, compose->cc);
1928 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1929 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1930 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
1931 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
1933 compose_update_priority_menu_item(compose);
1935 compose_update_gnupg_mode_menu_item(compose);
1937 compose_show_first_last_header(compose, TRUE);
1944 static void compose_insert_sig(Compose *compose, gboolean replace)
1946 GtkSText *text = GTK_STEXT(compose->text);
1950 g_return_if_fail(compose->account != NULL);
1952 cur_pos = gtk_editable_get_position(GTK_EDITABLE(text));
1954 gtk_stext_freeze(text);
1957 len = gtk_stext_get_length(text);
1958 gtk_stext_set_point(text, len);
1961 if (replace && compose->sig_str) {
1964 if (compose->sig_str[0] == '\0')
1967 pos = gtkut_stext_find(text, 0, compose->sig_str, TRUE);
1970 len = get_mbs_len(compose->sig_str);
1972 gtk_stext_set_point(text, pos);
1973 gtk_stext_forward_delete(text, len);
1978 g_free(compose->sig_str);
1979 compose->sig_str = compose_get_signature_str(compose);
1980 if (!compose->sig_str || (replace && !compose->account->auto_sig))
1981 compose->sig_str = g_strdup("");
1983 gtk_stext_insert(text, NULL, NULL, NULL, compose->sig_str, -1);
1985 gtk_stext_thaw(text);
1987 if (cur_pos > gtk_stext_get_length(text))
1988 cur_pos = gtk_stext_get_length(text);
1990 gtk_editable_set_position(GTK_EDITABLE(text), cur_pos);
1991 gtk_stext_set_point(text, cur_pos);
1994 static gchar *compose_get_signature_str(Compose *compose)
1996 gchar *sig_body = NULL;
1997 gchar *sig_str = NULL;
1999 g_return_val_if_fail(compose->account != NULL, NULL);
2001 if (!compose->account->sig_path)
2004 if (compose->account->sig_type == SIG_FILE) {
2005 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2006 g_warning("can't open signature file: %s\n",
2007 compose->account->sig_path);
2012 if (compose->account->sig_type == SIG_COMMAND)
2013 sig_body = get_command_output(compose->account->sig_path);
2017 tmp = file_read_to_str(compose->account->sig_path);
2020 sig_body = normalize_newlines(tmp);
2024 if (compose->account->sig_sep)
2025 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2028 sig_str = g_strconcat("\n\n", sig_body, NULL);
2035 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2037 GtkSText *text = GTK_STEXT(compose->text);
2038 gchar buf[BUFFSIZE];
2041 gboolean badtxt = FALSE;
2043 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2045 if ((fp = fopen(file, "rb")) == NULL) {
2046 FILE_OP_ERROR(file, "fopen");
2047 return COMPOSE_INSERT_READ_ERROR;
2050 gtk_stext_freeze(text);
2052 while (fgets(buf, sizeof(buf), fp) != NULL) {
2053 /* strip <CR> if DOS/Windows file,
2054 replace <CR> with <LF> if Macintosh file. */
2057 if (len > 0 && buf[len - 1] != '\n') {
2059 if (buf[len] == '\r') buf[len] = '\n';
2061 if (mbstowcs(NULL, buf, 0) == -1)
2063 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
2066 gtk_stext_thaw(text);
2071 return COMPOSE_INSERT_INVALID_CHARACTER;
2073 return COMPOSE_INSERT_SUCCESS;
2076 static void compose_attach_append(Compose *compose, const gchar *file,
2077 const gchar *filename,
2078 const gchar *content_type)
2081 gchar *text[N_ATTACH_COLS];
2086 if (!is_file_exist(file)) {
2087 g_warning("File %s doesn't exist\n", file);
2090 if ((size = get_file_size(file)) < 0) {
2091 g_warning("Can't get file size of %s\n", file);
2095 alertpanel_notice(_("File %s is empty."), file);
2098 if ((fp = fopen(file, "rb")) == NULL) {
2099 alertpanel_error(_("Can't read %s."), file);
2104 #if 0 /* NEW COMPOSE GUI */
2105 if (!compose->use_attach) {
2106 GtkItemFactory *ifactory;
2107 GtkWidget *menuitem;
2109 ifactory = gtk_item_factory_from_widget(compose->menubar);
2110 menuitem = gtk_item_factory_get_item(ifactory,
2111 "/View/Attachment");
2112 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2116 ainfo = g_new0(AttachInfo, 1);
2117 ainfo->file = g_strdup(file);
2120 ainfo->content_type = g_strdup(content_type);
2121 if (!strcasecmp(content_type, "message/rfc822")) {
2123 MsgFlags flags = {0, 0};
2126 if (procmime_get_encoding_for_file(file) == ENC_7BIT)
2127 ainfo->encoding = ENC_7BIT;
2129 ainfo->encoding = ENC_8BIT;
2131 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2132 if (msginfo && msginfo->subject)
2133 name = msginfo->subject;
2135 name = g_basename(filename ? filename : file);
2137 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2139 procmsg_msginfo_free(msginfo);
2141 if (!g_strncasecmp(content_type, "text", 4))
2143 procmime_get_encoding_for_file(file);
2145 ainfo->encoding = ENC_BASE64;
2146 ainfo->name = g_strdup
2147 (g_basename(filename ? filename : file));
2150 ainfo->content_type = procmime_get_mime_type(file);
2151 if (!ainfo->content_type) {
2152 ainfo->content_type =
2153 g_strdup("application/octet-stream");
2154 ainfo->encoding = ENC_BASE64;
2155 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
2156 ainfo->encoding = procmime_get_encoding_for_file(file);
2158 ainfo->encoding = ENC_BASE64;
2159 ainfo->name = g_strdup(g_basename(filename ? filename : file));
2163 text[COL_MIMETYPE] = ainfo->content_type;
2164 text[COL_SIZE] = to_human_readable(size);
2165 text[COL_NAME] = ainfo->name;
2167 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2168 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2172 static void compose_use_signing(Compose *compose, gboolean use_signing)
2174 GtkItemFactory *ifactory;
2175 GtkWidget *menuitem = NULL;
2177 compose->use_signing = use_signing;
2178 ifactory = gtk_item_factory_from_widget(compose->menubar);
2179 menuitem = gtk_item_factory_get_item
2180 (ifactory, "/Message/Sign");
2181 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2183 compose_update_gnupg_mode_menu_item(compose);
2185 #endif /* USE_GPGME */
2187 #define NEXT_PART_NOT_CHILD(info) \
2189 node = info->node; \
2190 while (node->children) \
2191 node = g_node_last_child(node); \
2192 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2195 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2199 MimeInfo *firsttext = NULL;
2200 MimeInfo *encrypted = NULL;
2203 const gchar *partname = NULL;
2205 mimeinfo = procmime_scan_message(msginfo);
2206 if (!mimeinfo) return;
2208 if (mimeinfo->node->children == NULL) {
2209 procmime_mimeinfo_free_all(mimeinfo);
2213 /* find first content part */
2214 child = (MimeInfo *) mimeinfo->node->children->data;
2215 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2216 child = (MimeInfo *)child->node->children->data;
2218 if (child->type == MIMETYPE_TEXT) {
2220 debug_print("First text part found\n");
2221 } else if (compose->mode == COMPOSE_REEDIT &&
2222 child->type == MIMETYPE_APPLICATION &&
2223 !strcasecmp(child->subtype, "pgp-encrypted")) {
2225 val = alertpanel(_("Encrypted message"),
2226 _("Cannot re-edit an encrypted message. \n"
2227 "Discard encrypted part?"),
2228 _("Yes"), _("No"), NULL);
2229 if (val == G_ALERTDEFAULT)
2230 encrypted = (MimeInfo *)child->node->parent->data;
2233 child = (MimeInfo *) mimeinfo->node->children->data;
2234 while (child != NULL) {
2235 if (child == encrypted) {
2236 /* skip this part of tree */
2237 NEXT_PART_NOT_CHILD(child);
2241 if (child->type == MIMETYPE_MULTIPART) {
2242 /* get the actual content */
2243 child = procmime_mimeinfo_next(child);
2247 if (child == firsttext) {
2248 child = procmime_mimeinfo_next(child);
2252 if ((compose->mode == COMPOSE_REEDIT ||
2253 compose->mode == COMPOSE_FORWARD_INLINE ||
2254 compose->mode == COMPOSE_FORWARD ) &&
2255 (child->type == MIMETYPE_APPLICATION) &&
2256 !strcmp(child->subtype, "pgp-signature")) {
2258 if (compose->mode == COMPOSE_REEDIT) {
2259 compose->gnupg_mode = GNUPG_MODE_DETACH;
2260 compose_use_signing(compose, TRUE);
2263 child = procmime_mimeinfo_next(child);
2266 outfile = procmime_get_tmp_file_name(child);
2267 if (procmime_get_part(outfile, child) < 0)
2268 g_warning("Can't get the part of multipart message.");
2270 gchar *content_type;
2272 content_type = g_strdup_printf("%s/%s", procmime_get_type_str(child->type), child->subtype);
2273 partname = procmime_mimeinfo_get_parameter(child, "name");
2274 if (partname == NULL)
2276 compose_attach_append(compose, outfile,
2277 partname, content_type);
2278 g_free(content_type);
2281 NEXT_PART_NOT_CHILD(child);
2283 procmime_mimeinfo_free_all(mimeinfo);
2286 #undef NEXT_PART_NOT_CHILD
2288 #define GET_CHAR(pos, buf, len) \
2290 if (text->use_wchar) \
2291 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2293 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2298 #define DISP_WIDTH(len) \
2299 ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
2300 (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
2302 #define INDENT_CHARS ">|#"
2303 #define SPACE_CHARS " \t"
2305 static void compose_wrap_line(Compose *compose)
2307 GtkSText *text = GTK_STEXT(compose->text);
2308 gint ch_len, last_ch_len;
2309 gchar cbuf[MB_LEN_MAX], last_ch;
2313 gint p_start, p_end;
2314 gint line_pos, cur_pos;
2315 gint line_len, cur_len;
2317 gtk_stext_freeze(text);
2319 text_len = gtk_stext_get_length(text);
2321 /* check to see if the point is on the paragraph mark (empty line). */
2322 cur_pos = gtk_stext_get_point(text);
2323 GET_CHAR(cur_pos, cbuf, ch_len);
2324 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2326 goto compose_end; /* on the paragraph mark */
2327 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2328 if (ch_len == 1 && *cbuf == '\n')
2329 goto compose_end; /* on the paragraph mark */
2332 /* find paragraph start. */
2333 line_end = quoted = 0;
2334 for (p_start = cur_pos; p_start >= 0; --p_start) {
2335 GET_CHAR(p_start, cbuf, ch_len);
2336 if (ch_len == 1 && *cbuf == '\n') {
2338 goto compose_end; /* quoted part */
2346 && strchr(prefs_common.quote_chars, *cbuf))
2348 else if (ch_len != 1 || !isspace(*cbuf))
2357 /* find paragraph end. */
2359 for (p_end = cur_pos; p_end < text_len; p_end++) {
2360 GET_CHAR(p_end, cbuf, ch_len);
2361 if (ch_len == 1 && *cbuf == '\n') {
2368 if (line_end && ch_len == 1 &&
2369 strchr(prefs_common.quote_chars, *cbuf))
2370 goto compose_end; /* quoted part */
2375 if (p_end >= text_len)
2378 if (p_start >= p_end)
2381 line_len = cur_len = 0;
2385 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2388 GET_CHAR(cur_pos, cbuf, ch_len);
2395 if (ch_len == 1 && isspace(*cbuf))
2398 if (ch_len == 1 && *cbuf == '\n') {
2400 if (last_ch_len == 1 && !isspace(last_ch)) {
2401 if (cur_pos + 1 < p_end) {
2402 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2403 if (ch_len == 1 && !isspace(*cbuf))
2407 gtk_stext_set_point(text, cur_pos + 1);
2408 gtk_stext_backward_delete(text, 1);
2410 gtk_stext_set_point(text, cur_pos);
2411 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2421 last_ch_len = ch_len;
2425 line_pos = cur_pos + 1;
2426 line_len = cur_len + ch_len;
2429 if (cur_len + DISP_WIDTH(ch_len) > prefs_common.linewrap_len &&
2433 GET_CHAR(line_pos - 1, cbuf, ch_len);
2434 if (ch_len == 1 && isspace(*cbuf)) {
2435 gtk_stext_set_point(text, line_pos);
2436 gtk_stext_backward_delete(text, 1);
2445 gtk_stext_set_point(text, line_pos);
2446 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2450 cur_len = cur_len - line_len + DISP_WIDTH(ch_len);
2456 line_pos = cur_pos + 1;
2457 line_len = cur_len + DISP_WIDTH(ch_len);
2459 cur_len += DISP_WIDTH(ch_len);
2463 gtk_stext_thaw(text);
2468 /* Darko: used when I debug wrapping */
2469 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2472 gchar cbuf[MB_LEN_MAX];
2474 printf("%d [", pos);
2475 for (i = pos; i < tlen; i++) {
2476 GET_CHAR(i, cbuf, clen);
2477 if (clen < 0) break;
2478 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2480 fwrite(cbuf, clen, 1, stdout);
2488 WAIT_FOR_INDENT_CHAR,
2489 WAIT_FOR_INDENT_CHAR_OR_SPACE
2492 /* return indent length, we allow:
2493 > followed by spaces/tabs
2494 | followed by spaces/tabs
2495 uppercase characters immediately followed by >,
2496 and the repeating sequences of the above */
2497 /* return indent length */
2498 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2501 guint i, ch_len, alnum_cnt = 0;
2502 IndentState state = WAIT_FOR_INDENT_CHAR;
2503 gchar cbuf[MB_LEN_MAX];
2507 if (prefs_common.quote_chars == NULL) {
2511 for (i = start_pos; i < text_len; i++) {
2512 GET_CHAR(i, cbuf, ch_len);
2516 if (cbuf[0] == '\n')
2519 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2520 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2523 case WAIT_FOR_SPACE:
2524 if (is_space == FALSE)
2526 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2528 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2529 if (is_indent == FALSE && is_space == FALSE &&
2532 if (is_space == TRUE) {
2534 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2535 } else if (is_indent == TRUE) {
2537 state = WAIT_FOR_SPACE;
2540 state = WAIT_FOR_INDENT_CHAR;
2543 case WAIT_FOR_INDENT_CHAR:
2544 if (is_indent == FALSE && !isupper(cbuf[0]))
2546 if (is_indent == TRUE) {
2548 && !strchr(prefs_common.quote_chars, cbuf[0]))
2551 state = WAIT_FOR_SPACE;
2562 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2568 /* insert quotation string when line was wrapped */
2569 static guint ins_quote(GtkSText *text, guint indent_len,
2570 guint prev_line_pos, guint text_len,
2573 guint i, ins_len = 0;
2577 for (i = 0; i < indent_len; i++) {
2578 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2579 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2581 ins_len = indent_len;
2587 /* check if we should join the next line */
2588 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2589 guint prev_ilen, gboolean autowrap)
2591 guint indent_len, ch_len;
2592 gboolean do_join = FALSE;
2593 gchar cbuf[MB_LEN_MAX];
2595 indent_len = get_indent_length(text, start_pos, tlen);
2597 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2598 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2599 if (ch_len > 0 && (cbuf[0] != '\n'))
2606 static void compose_wrap_line_all(Compose *compose)
2608 compose_wrap_line_all_full(compose, FALSE);
2611 #define STEXT_FREEZE() \
2612 if (!frozen) { gtk_stext_freeze(text); frozen = TRUE; }
2614 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2616 GtkSText *text = GTK_STEXT(compose->text);
2618 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2619 gint line_len = 0, cur_len = 0;
2621 gboolean is_new_line = TRUE, do_delete = FALSE;
2623 gboolean linewrap_quote = TRUE;
2624 gboolean set_editable_pos = FALSE;
2625 gint editable_pos = 0;
2626 gboolean frozen = FALSE;
2627 guint linewrap_len = prefs_common.linewrap_len;
2628 gchar *qfmt = prefs_common.quotemark;
2629 gchar cbuf[MB_LEN_MAX];
2631 tlen = gtk_stext_get_length(text);
2633 for (; cur_pos < tlen; cur_pos++) {
2634 /* mark position of new line - needed for quotation wrap */
2637 i_len = get_indent_length(text, cur_pos, tlen);
2639 is_new_line = FALSE;
2642 g_print("new line i_len=%d p_pos=", i_len);
2643 dump_text(text, p_pos, tlen, 1);
2647 GET_CHAR(cur_pos, cbuf, ch_len);
2649 /* fix line length for tabs */
2650 if (ch_len == 1 && *cbuf == '\t') {
2651 guint tab_width = text->default_tab_width;
2652 guint tab_offset = line_len % tab_width;
2655 g_print("found tab at pos=%d line_len=%d ", cur_pos,
2659 line_len += tab_width - tab_offset - 1;
2663 printf("new_len=%d\n", line_len);
2667 /* we have encountered line break */
2668 if (ch_len == 1 && *cbuf == '\n') {
2670 gchar cb[MB_LEN_MAX];
2672 /* should we join the next line */
2673 if ((autowrap || i_len != cur_len) && do_delete &&
2675 (text, cur_pos + 1, tlen, i_len, autowrap))
2681 g_print("found CR at %d do_del is %d next line is ",
2682 cur_pos, do_delete);
2683 dump_text(text, cur_pos + 1, tlen, 1);
2686 /* skip delete if it is continuous URL */
2687 if (do_delete && (line_pos - p_pos <= i_len) &&
2688 gtk_stext_is_uri_string(text, line_pos, tlen))
2692 g_print("l_len=%d wrap_len=%d do_del=%d\n",
2693 line_len, linewrap_len, do_delete);
2695 /* should we delete to perform smart wrapping */
2696 if (line_len < linewrap_len && do_delete) {
2698 /* get rid of newline */
2699 gtk_stext_set_point(text, cur_pos);
2700 gtk_stext_forward_delete(text, 1);
2703 /* if text starts with quote fmt or with
2704 indent string, delete them */
2707 ilen = gtk_stext_str_compare_n
2708 (text, cur_pos, p_pos, i_len,
2711 gtk_stext_forward_delete
2717 GET_CHAR(cur_pos, cb, clen);
2719 /* insert space if it's alphanumeric */
2720 if ((cur_pos != line_pos) &&
2721 ((clen > 1) || isalnum(cb[0]))) {
2722 gtk_stext_insert(text, NULL, NULL,
2727 /* and start over with current line */
2728 cur_pos = p_pos - 1;
2730 line_len = cur_len = 0;
2734 g_print("after delete l_pos=");
2735 dump_text(text, line_pos, tlen, 1);
2737 /* move beginning of line if we are on LF */
2738 GET_CHAR(line_pos, cb, clen);
2739 if (clen == 1 && *cb == '\n')
2742 g_print("new line_pos=%d\n", line_pos);
2748 /* mark new line beginning */
2749 line_pos = cur_pos + 1;
2750 line_len = cur_len = 0;
2761 /* possible line break */
2762 if (ch_len == 1 && isspace(*cbuf)) {
2763 line_pos = cur_pos + 1;
2764 line_len = cur_len + ch_len;
2767 /* are we over wrapping length set in preferences ? */
2768 if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
2772 g_print("should wrap cur_pos=%d ", cur_pos);
2773 dump_text(text, p_pos, tlen, 1);
2774 dump_text(text, line_pos, tlen, 1);
2776 /* force wrapping if it is one long word but not URL */
2777 if (line_pos - p_pos <= i_len)
2778 if (!gtk_stext_is_uri_string
2779 (text, line_pos, tlen))
2780 line_pos = cur_pos - 1;
2782 g_print("new line_pos=%d\n", line_pos);
2785 GET_CHAR(line_pos - 1, cbuf, clen);
2787 /* if next character is space delete it */
2788 if (clen == 1 && isspace(*cbuf)) {
2789 if (p_pos + i_len != line_pos ||
2790 !gtk_stext_is_uri_string
2791 (text, line_pos, tlen)) {
2793 /* workaround for correct cursor
2795 if (set_editable_pos == FALSE) {
2796 editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2797 if (editable_pos == line_pos)
2798 set_editable_pos = TRUE;
2800 gtk_stext_set_point(text, line_pos);
2801 gtk_stext_backward_delete(text, 1);
2810 /* if it is URL at beginning of line don't wrap */
2811 if (p_pos + i_len == line_pos &&
2812 gtk_stext_is_uri_string(text, line_pos, tlen)) {
2814 g_print("found URL at ");
2815 dump_text(text, line_pos, tlen, 1);
2822 gtk_stext_set_point(text, line_pos);
2823 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2824 gtk_stext_compact_buffer(text);
2827 /* for loop will increase it */
2828 cur_pos = line_pos - 1;
2829 /* start over with current line */
2831 line_len = cur_len = 0;
2832 if (autowrap || i_len > 0)
2837 g_print("after CR insert ");
2838 dump_text(text, line_pos, tlen, 1);
2839 dump_text(text, cur_pos, tlen, 1);
2842 /* should we insert quotation ? */
2843 if (linewrap_quote && i_len) {
2844 /* only if line is not already quoted */
2845 if (!gtk_stext_str_compare
2846 (text, line_pos, tlen, qfmt)) {
2849 if (line_pos - p_pos > i_len) {
2851 (text, i_len, p_pos,
2856 g_print("after quote insert ");
2857 dump_text(text, line_pos, tlen, 1);
2865 line_pos = cur_pos + 1;
2866 line_len = cur_len + DISP_WIDTH(ch_len);
2868 /* advance to next character in buffer */
2869 cur_len += DISP_WIDTH(ch_len);
2873 gtk_stext_thaw(text);
2875 if (set_editable_pos && editable_pos <= tlen)
2876 gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
2882 static void compose_set_title(Compose *compose)
2887 edited = compose->modified ? _(" [Edited]") : "";
2888 if (compose->account && compose->account->address)
2889 str = g_strdup_printf(_("%s - Compose message%s"),
2890 compose->account->address, edited);
2892 str = g_strdup_printf(_("Compose message%s"), edited);
2893 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2898 * compose_current_mail_account:
2900 * Find a current mail account (the currently selected account, or the
2901 * default account, if a news account is currently selected). If a
2902 * mail account cannot be found, display an error message.
2904 * Return value: Mail account, or NULL if not found.
2906 static PrefsAccount *
2907 compose_current_mail_account(void)
2911 if (cur_account && cur_account->protocol != A_NNTP)
2914 ac = account_get_default();
2915 if (!ac || ac->protocol == A_NNTP) {
2916 alertpanel_error(_("Account for sending mail is not specified.\n"
2917 "Please select a mail account before sending."));
2924 static void compose_select_account(Compose *compose, PrefsAccount *account,
2927 GtkWidget *menuitem;
2928 GtkItemFactory *ifactory;
2930 g_return_if_fail(account != NULL);
2932 compose->account = account;
2934 compose_set_title(compose);
2936 ifactory = gtk_item_factory_from_widget(compose->menubar);
2938 if (account->protocol == A_NNTP) {
2939 gtk_widget_show(compose->newsgroups_hbox);
2940 gtk_widget_show(compose->newsgroups_entry);
2941 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2942 compose->use_newsgroups = TRUE;
2944 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2945 gtk_check_menu_item_set_active
2946 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2947 gtk_widget_set_sensitive(menuitem, TRUE);
2948 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2949 gtk_check_menu_item_set_active
2950 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2951 gtk_widget_set_sensitive(menuitem, TRUE);
2953 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
2955 gtk_widget_hide(compose->newsgroups_hbox);
2956 gtk_widget_hide(compose->newsgroups_entry);
2957 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
2958 gtk_widget_queue_resize(compose->table_vbox);
2959 compose->use_newsgroups = FALSE;
2961 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2962 gtk_check_menu_item_set_active
2963 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2964 gtk_widget_set_sensitive(menuitem, FALSE);
2965 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2966 gtk_check_menu_item_set_active
2967 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2968 gtk_widget_set_sensitive(menuitem, FALSE);
2970 menuitem = gtk_item_factory_get_item(ifactory, "/View/Followup to");
2971 gtk_check_menu_item_set_active
2972 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2973 gtk_widget_set_sensitive(menuitem, FALSE);
2976 if (account->set_autocc) {
2977 compose_entry_show(compose, COMPOSE_ENTRY_CC);
2978 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
2979 compose_entry_set(compose, account->auto_cc,
2982 if (account->set_autobcc) {
2983 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
2984 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
2985 compose_entry_set(compose, account->auto_bcc,
2988 if (account->set_autoreplyto) {
2989 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
2990 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
2991 compose_entry_set(compose, account->auto_replyto,
2992 COMPOSE_ENTRY_REPLY_TO);
2995 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
2996 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2997 prefs_common.show_ruler);
3001 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
3002 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3003 account->default_sign);
3004 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
3005 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3006 account->default_encrypt);
3008 activate_gnupg_mode(compose, account);
3009 #endif /* USE_GPGME */
3011 if (!init && compose->mode != COMPOSE_REDIRECT)
3012 compose_insert_sig(compose, TRUE);
3015 gboolean compose_check_for_valid_recipient(Compose *compose) {
3016 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3017 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3018 gboolean recipient_found = FALSE;
3022 /* free to and newsgroup list */
3023 slist_free_strings(compose->to_list);
3024 g_slist_free(compose->to_list);
3025 compose->to_list = NULL;
3027 slist_free_strings(compose->newsgroup_list);
3028 g_slist_free(compose->newsgroup_list);
3029 compose->newsgroup_list = NULL;
3031 /* search header entries for to and newsgroup entries */
3032 for (list = compose->header_list; list; list = list->next) {
3035 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3036 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3038 if (entry[0] != '\0') {
3039 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3040 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3041 compose->to_list = address_list_append(compose->to_list, entry);
3042 recipient_found = TRUE;
3045 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3046 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3047 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3048 recipient_found = TRUE;
3055 return recipient_found;
3058 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3062 if (compose_check_for_valid_recipient(compose) == FALSE) {
3063 alertpanel_error(_("Recipient is not specified."));
3067 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3068 if (*str == '\0' && check_subject == TRUE) {
3071 aval = alertpanel(_("Send"),
3072 _("Subject is empty. Send it anyway?"),
3073 _("Yes"), _("No"), NULL);
3074 if (aval != G_ALERTDEFAULT)
3081 gint compose_send(Compose *compose)
3088 if (compose_check_entries(compose, TRUE) == FALSE)
3091 val = compose_queue(compose, &msgnum, &folder);
3093 alertpanel_error(_("Could not queue message for sending"));
3098 alertpanel_error(_("The message was queued but could not be sent.\nUse \"Send queued messages\" from the main window to retry."));
3102 msgpath = folder_item_fetch_msg(folder, msgnum);
3103 val = procmsg_send_message_queue(msgpath);
3106 folder_item_remove_msg(folder, msgnum);
3108 folder_item_scan(folder);
3113 #if 0 /* compose restructure */
3114 gint compose_send(Compose *compose)
3116 gchar tmp[MAXPATHLEN + 1];
3118 static gboolean lock = FALSE;
3122 g_return_val_if_fail(compose->account != NULL, -1);
3126 if (compose_check_entries(compose, TRUE) == FALSE) {
3131 /* write to temporary file */
3132 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
3133 get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3135 if (prefs_common.linewrap_at_send)
3136 compose_wrap_line_all(compose);
3138 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
3143 if (!compose->to_list && !compose->newsgroup_list) {
3144 g_warning("can't get recipient list.");
3150 if (compose->to_list) {
3153 #if 0 /* NEW COMPOSE GUI */
3154 if (compose->account->protocol != A_NNTP)
3155 ac = compose->account;
3157 ac = account_find_from_address(compose->account->address);
3159 if (cur_account && cur_account->protocol != A_NNTP)
3162 ac = account_get_default();
3164 if (!ac || ac->protocol == A_NNTP) {
3165 alertpanel_error(_("Account for sending mail is not specified.\n"
3166 "Please select a mail account before sending."));
3173 ac = compose->account;
3175 ok = send_message(tmp, ac, compose->to_list);
3178 if (ok == 0 && compose->newsgroup_list) {
3179 ok = news_post(FOLDER(compose->account->folder), tmp);
3181 alertpanel_error(_("Error occurred while posting the message to %s ."),
3182 compose->account->nntp_server);
3189 /* queue message if failed to send */
3191 if (prefs_common.queue_msg) {
3196 _("Error occurred while sending the message.\n"
3197 "Put this message into queue folder?"),
3198 _("OK"), _("Cancel"), NULL);
3199 if (G_ALERTDEFAULT == val) {
3200 ok = compose_queue(compose, tmp);
3202 alertpanel_error(_("Can't queue the message."));
3205 alertpanel_error_log(_("Error occurred while sending the message."));
3207 if (compose->mode == COMPOSE_REEDIT) {
3208 compose_remove_reedit_target(compose);
3210 /* save message to outbox */
3211 if (prefs_common.savemsg) {
3214 outbox = account_get_special_folder
3215 (compose->account, F_OUTBOX);
3216 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
3218 (_("Can't save the message to Sent."));
3228 static gboolean compose_use_attach(Compose *compose)
3230 return gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL;
3233 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3236 gchar buf[BUFFSIZE];
3238 gboolean first_address;
3240 ComposeHeaderEntry *headerentry;
3241 gchar *headerentryname;
3245 debug_print("Writing redirect header\n");
3247 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3248 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3250 first_address = TRUE;
3251 for (list = compose->header_list; list; list = list->next) {
3252 headerentry = ((ComposeHeaderEntry *)list->data);
3253 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3255 if (g_strcasecmp(headerentryname, cc_hdr) == 0
3256 || g_strcasecmp(headerentryname, to_hdr) == 0) {
3257 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3258 Xstrdup_a(str, str, return -1);
3260 if (str[0] != '\0') {
3261 compose_convert_header
3262 (buf, sizeof(buf), str,
3263 strlen("Resent-To") + 2, TRUE);
3264 if (first_address) {
3265 fprintf(fp, "Resent-To: ");
3266 first_address = FALSE;
3270 fprintf(fp, "%s", buf);
3274 /* if (!first_address) { */
3281 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3283 gchar buf[BUFFSIZE];
3285 /* struct utsname utsbuf; */
3287 g_return_val_if_fail(fp != NULL, -1);
3288 g_return_val_if_fail(compose->account != NULL, -1);
3289 g_return_val_if_fail(compose->account->address != NULL, -1);
3292 get_rfc822_date(buf, sizeof(buf));
3293 fprintf(fp, "Resent-Date: %s\n", buf);
3296 if (compose->account->name && *compose->account->name) {
3297 compose_convert_header
3298 (buf, sizeof(buf), compose->account->name,
3299 strlen("From: "), TRUE);
3300 fprintf(fp, "Resent-From: %s <%s>\n",
3301 buf, compose->account->address);
3303 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3306 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3308 Xstrdup_a(str, str, return -1);
3311 compose_convert_header(buf, sizeof(buf), str,
3312 strlen("Subject: "), FALSE);
3313 fprintf(fp, "Subject: %s\n", buf);
3317 /* Resent-Message-ID */
3318 if (compose->account->gen_msgid) {
3319 compose_generate_msgid(compose, buf, sizeof(buf));
3320 fprintf(fp, "Resent-Message-Id: <%s>\n", buf);
3321 compose->msgid = g_strdup(buf);
3324 compose_redirect_write_headers_from_headerlist(compose, fp);
3326 /* separator between header and body */
3332 static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
3337 gchar buf[BUFFSIZE];
3339 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3340 FILE_OP_ERROR(file, "fopen");
3344 if ((fdest = fopen(file, "wb")) == NULL) {
3345 FILE_OP_ERROR(file, "fopen");
3350 /* chmod for security */
3351 if (change_file_mode_rw(fdest, file) < 0) {
3352 FILE_OP_ERROR(file, "chmod");
3353 g_warning("can't change file mode\n");
3356 while (procheader_get_one_field(buf, sizeof(buf), fp, NULL) != -1) {
3357 /* should filter returnpath, delivered-to */
3358 if (g_strncasecmp(buf, "Return-Path:",
3359 strlen("Return-Path:")) == 0 ||
3360 g_strncasecmp(buf, "Delivered-To:",
3361 strlen("Delivered-To:")) == 0 ||
3362 g_strncasecmp(buf, "Received:",
3363 strlen("Received:")) == 0 ||
3364 g_strncasecmp(buf, "Subject:",
3365 strlen("Subject:")) == 0 ||
3366 g_strncasecmp(buf, "X-UIDL:",
3367 strlen("X-UIDL:")) == 0)
3370 if (fputs(buf, fdest) == -1)
3373 if (!prefs_common.redirect_keep_from) {
3374 if (g_strncasecmp(buf, "From:",
3375 strlen("From:")) == 0) {
3376 fputs(" (by way of ", fdest);
3377 if (compose->account->name
3378 && *compose->account->name) {
3379 compose_convert_header
3381 compose->account->name,
3384 fprintf(fdest, "%s <%s>",
3386 compose->account->address);
3388 fprintf(fdest, "%s",
3389 compose->account->address);
3394 if (fputs("\n", fdest) == -1)
3398 compose_redirect_write_headers(compose, fdest);
3400 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3401 if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
3402 FILE_OP_ERROR(file, "fwrite");
3408 if (fclose(fdest) == EOF) {
3409 FILE_OP_ERROR(file, "fclose");
3425 /* interfaces to rfc2015 to keep out the prefs stuff there.
3426 * returns 0 on success and -1 on error. */
3427 static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
3429 const gchar *key_id = NULL;
3432 switch (compose->account->sign_key) {
3433 case SIGN_KEY_DEFAULT:
3436 case SIGN_KEY_BY_FROM:
3437 key_id = compose->account->address;
3439 case SIGN_KEY_CUSTOM:
3440 key_id = compose->account->sign_key_id;
3446 key_list = rfc2015_create_signers_list(key_id);
3449 alertpanel_error(_("Could not find any key associated with "
3450 "currently selected key id `%s'."), key_id);
3454 *pkey_list = key_list;
3458 /* clearsign message body text */
3459 static gint compose_clearsign_text(Compose *compose, gchar **text)
3464 tmp_file = get_tmp_file();
3465 if (str_write_to_file(*text, tmp_file) < 0) {
3470 if (compose_create_signers_list(compose, &key_list) < 0 ||
3471 rfc2015_clearsign(tmp_file, key_list) < 0) {
3478 *text = file_read_to_str(tmp_file);
3486 #endif /* USE_GPGME */
3488 static gint compose_write_to_file(Compose *compose, const gchar *file,
3496 const gchar *out_codeset;
3497 EncodingType encoding;
3499 if ((fp = fopen(file, "wb")) == NULL) {
3500 FILE_OP_ERROR(file, "fopen");
3504 /* chmod for security */
3505 if (change_file_mode_rw(fp, file) < 0) {
3506 FILE_OP_ERROR(file, "chmod");
3507 g_warning("can't change file mode\n");
3510 /* get all composed text */
3511 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3512 len = strlen(chars);
3513 if (is_ascii_str(chars)) {
3516 out_codeset = CS_US_ASCII;
3517 encoding = ENC_7BIT;
3519 const gchar *src_codeset;
3521 out_codeset = conv_get_outgoing_charset_str();
3522 if (!strcasecmp(out_codeset, CS_US_ASCII))
3523 out_codeset = CS_ISO_8859_1;
3525 if (prefs_common.encoding_method == CTE_BASE64)
3526 encoding = ENC_BASE64;
3527 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3528 encoding = ENC_QUOTED_PRINTABLE;
3529 else if (prefs_common.encoding_method == CTE_8BIT)
3530 encoding = ENC_8BIT;
3532 encoding = procmime_get_encoding_for_charset(out_codeset);
3536 compose->use_signing && !compose->gnupg_mode &&
3537 encoding == ENC_8BIT)
3538 encoding = ENC_BASE64;
3541 src_codeset = conv_get_current_charset_str();
3542 /* if current encoding is US-ASCII, set it the same as
3543 outgoing one to prevent code conversion failure */
3544 if (!strcasecmp(src_codeset, CS_US_ASCII))
3545 src_codeset = out_codeset;
3547 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3548 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3550 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3555 msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
3557 "Send it anyway?"), src_codeset, out_codeset);
3559 (_("Error"), msg, _("Yes"), _("+No"), NULL);
3562 if (aval != G_ALERTDEFAULT) {
3569 out_codeset = src_codeset;
3576 canon_buf = canonicalize_str(buf);
3581 if (!is_draft && compose->use_signing && compose->gnupg_mode) {
3582 if (compose_clearsign_text(compose, &buf) < 0) {
3583 g_warning("clearsign failed\n");
3593 if (compose_write_headers
3594 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3595 g_warning("can't write headers\n");
3602 if (compose_use_attach(compose)) {
3604 /* This prolog message is ignored by mime software and
3605 * because it would make our signing/encryption task
3606 * tougher, we don't emit it in that case */
3607 if (!compose->use_signing && !compose->use_encryption)
3609 fputs("This is a multi-part message in MIME format.\n", fp);
3611 fprintf(fp, "\n--%s\n", compose->boundary);
3612 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3615 if (compose->use_signing && !compose->gnupg_mode)
3616 fprintf(fp, "Content-Disposition: inline\n");
3618 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3619 procmime_get_encoding_str(encoding));
3625 if (encoding == ENC_BASE64) {
3626 gchar outbuf[B64_BUFFSIZE];
3629 for (i = 0; i < len; i += B64_LINE_SIZE) {
3630 l = MIN(B64_LINE_SIZE, len - i);
3631 base64_encode(outbuf, buf + i, l);
3635 } else if (encoding == ENC_QUOTED_PRINTABLE) {
3639 outbuf = g_malloc(len * 4);
3640 qp_encode_line(outbuf, buf);
3641 outlen = strlen(outbuf);
3642 if (fwrite(outbuf, sizeof(gchar), outlen, fp) != outlen) {
3643 FILE_OP_ERROR(file, "fwrite");
3651 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3652 FILE_OP_ERROR(file, "fwrite");
3660 if (compose_use_attach(compose))
3661 compose_write_attach(compose, fp);
3663 if (fclose(fp) == EOF) {
3664 FILE_OP_ERROR(file, "fclose");
3671 uncanonicalize_file_replace(file);
3675 if ((compose->use_signing && !compose->gnupg_mode) ||
3676 compose->use_encryption) {
3677 if (canonicalize_file_replace(file) < 0) {
3683 if (compose->use_signing && !compose->gnupg_mode) {
3686 if (compose_create_signers_list(compose, &key_list) < 0 ||
3687 rfc2015_sign(file, key_list) < 0) {
3692 if (compose->use_encryption) {
3693 if (rfc2015_encrypt(file, compose->to_list,
3694 compose->gnupg_mode) < 0) {
3699 #endif /* USE_GPGME */
3701 uncanonicalize_file_replace(file);
3706 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3712 if ((fp = fopen(file, "wb")) == NULL) {
3713 FILE_OP_ERROR(file, "fopen");
3717 /* chmod for security */
3718 if (change_file_mode_rw(fp, file) < 0) {
3719 FILE_OP_ERROR(file, "chmod");
3720 g_warning("can't change file mode\n");
3723 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3726 len = strlen(chars);
3727 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3728 FILE_OP_ERROR(file, "fwrite");
3737 if (fclose(fp) == EOF) {
3738 FILE_OP_ERROR(file, "fclose");
3745 static gint compose_remove_reedit_target(Compose *compose)
3748 MsgInfo *msginfo = compose->targetinfo;
3750 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3751 if (!msginfo) return -1;
3753 item = msginfo->folder;
3754 g_return_val_if_fail(item != NULL, -1);
3756 if (procmsg_msg_exist(msginfo) &&
3757 (item->stype == F_DRAFT || item->stype == F_QUEUE
3758 || msginfo == compose->autosaved_draft)) {
3759 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3760 g_warning("can't remove the old message\n");
3768 void compose_remove_draft(Compose *compose)
3771 MsgInfo *msginfo = compose->targetinfo;
3772 drafts = account_get_special_folder(compose->account, F_DRAFT);
3774 if (procmsg_msg_exist(msginfo)) {
3775 folder_item_remove_msg(drafts, msginfo->msgnum);
3780 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3782 return compose_queue_sub (compose, msgnum, item, FALSE);
3784 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3790 gchar buf[BUFFSIZE];
3792 static gboolean lock = FALSE;
3793 PrefsAccount *mailac = NULL, *newsac = NULL;
3795 debug_print("queueing message...\n");
3796 g_return_val_if_fail(compose->account != NULL, -1);
3800 if (compose_check_entries(compose, check_subject) == FALSE) {
3805 if (!compose->to_list && !compose->newsgroup_list) {
3806 g_warning("can't get recipient list.");
3811 if (compose->to_list) {
3812 if (compose->account->protocol != A_NNTP)
3813 mailac = compose->account;
3814 else if (cur_account && cur_account->protocol != A_NNTP)
3815 mailac = cur_account;
3816 else if (!(mailac = compose_current_mail_account())) {
3818 alertpanel_error(_("No account for sending mails available!"));
3823 if (compose->newsgroup_list) {
3824 if (compose->account->protocol == A_NNTP)
3825 newsac = compose->account;
3826 else if (!newsac->protocol != A_NNTP) {
3828 alertpanel_error(_("No account for posting news available!"));
3833 if (prefs_common.linewrap_at_send)
3834 compose_wrap_line_all(compose);
3836 /* write to temporary file */
3837 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3838 G_DIR_SEPARATOR, (gint)compose);
3840 if (compose->redirect_filename != NULL) {
3841 if (compose_redirect_write_to_file(compose, tmp2) < 0) {
3848 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3855 /* add queue header */
3856 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3857 G_DIR_SEPARATOR, (gint)compose);
3858 if ((fp = fopen(tmp, "wb")) == NULL) {
3859 FILE_OP_ERROR(tmp, "fopen");
3863 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3864 FILE_OP_ERROR(tmp2, "fopen");
3872 if (change_file_mode_rw(fp, tmp) < 0) {
3873 FILE_OP_ERROR(tmp, "chmod");
3874 g_warning("can't change file mode\n");
3877 /* queueing variables */
3878 fprintf(fp, "AF:\n");
3879 fprintf(fp, "NF:0\n");
3880 fprintf(fp, "PS:10\n");
3881 fprintf(fp, "SRH:1\n");
3882 fprintf(fp, "SFN:\n");
3883 fprintf(fp, "DSR:\n");
3885 fprintf(fp, "MID:<%s>\n", compose->msgid);
3887 fprintf(fp, "MID:\n");
3888 fprintf(fp, "CFG:\n");
3889 fprintf(fp, "PT:0\n");
3890 fprintf(fp, "S:%s\n", compose->account->address);
3891 fprintf(fp, "RQ:\n");
3893 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3895 fprintf(fp, "SSV:\n");
3897 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3899 fprintf(fp, "NSV:\n");
3900 fprintf(fp, "SSH:\n");
3901 /* write recepient list */
3902 if (compose->to_list) {
3903 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
3904 for (cur = compose->to_list->next; cur != NULL;
3906 fprintf(fp, ",<%s>", (gchar *)cur->data);
3909 /* write newsgroup list */
3910 if (compose->newsgroup_list) {
3912 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3913 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3914 fprintf(fp, ",%s", (gchar *)cur->data);
3917 /* Sylpheed account IDs */
3919 fprintf(fp, "MAID:%d\n", mailac->account_id);
3922 fprintf(fp, "NAID:%d\n", newsac->account_id);
3924 /* Save copy folder */
3925 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3926 gchar *savefolderid;
3928 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3929 fprintf(fp, "SCF:%s\n", savefolderid);
3930 g_free(savefolderid);
3932 /* Message-ID of message replying to */
3933 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
3936 folderid = folder_item_get_identifier(compose->replyinfo->folder);
3937 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
3940 /* Message-ID of message forwarding to */
3941 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
3944 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
3945 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
3950 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3951 if (fputs(buf, fp) == EOF) {
3952 FILE_OP_ERROR(tmp, "fputs");
3963 if (fclose(fp) == EOF) {
3964 FILE_OP_ERROR(tmp, "fclose");
3972 queue = account_get_special_folder(compose->account, F_QUEUE);
3974 g_warning("can't find queue folder\n");
3979 folder_item_scan(queue);
3980 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
3981 g_warning("can't queue the message\n");
3991 if (compose->mode == COMPOSE_REEDIT) {
3992 compose_remove_reedit_target(compose);
3995 if ((msgnum != NULL) && (item != NULL)) {
4003 static void compose_write_attach(Compose *compose, FILE *fp)
4006 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4009 gchar filename[BUFFSIZE];
4012 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
4014 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
4015 g_warning("Can't open file %s\n", ainfo->file);
4019 fprintf(fp, "\n--%s\n", compose->boundary);
4021 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
4022 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
4023 fprintf(fp, "Content-Disposition: inline\n");
4025 compose_convert_header(filename, sizeof(filename),
4026 ainfo->name, 12, FALSE);
4027 fprintf(fp, "Content-Type: %s;\n"
4029 ainfo->content_type, filename);
4030 fprintf(fp, "Content-Disposition: attachment;\n"
4031 " filename=\"%s\"\n", filename);
4034 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
4035 procmime_get_encoding_str(ainfo->encoding));
4037 if (ainfo->encoding == ENC_BASE64) {
4038 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
4040 while ((len = fread(inbuf, sizeof(gchar),
4041 B64_LINE_SIZE, attach_fp))
4043 base64_encode(outbuf, inbuf, B64_LINE_SIZE);
4047 if (len > 0 && feof(attach_fp)) {
4048 base64_encode(outbuf, inbuf, len);
4052 } else if (ainfo->encoding == ENC_QUOTED_PRINTABLE) {
4053 gchar inbuf[BUFFSIZE], outbuf[BUFFSIZE * 4];
4055 while (fgets(inbuf, sizeof(inbuf), attach_fp) != NULL) {
4056 qp_encode_line(outbuf, inbuf);
4060 gchar buf[BUFFSIZE];
4062 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
4071 fprintf(fp, "\n--%s--\n", compose->boundary);
4074 #define QUOTE_IF_REQUIRED(out, str) \
4076 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
4080 len = strlen(str) + 3; \
4081 Xalloca(__tmp, len, return -1); \
4082 g_snprintf(__tmp, len, "\"%s\"", str); \
4085 Xstrdup_a(out, str, return -1); \
4089 #define PUT_RECIPIENT_HEADER(header, str) \
4091 if (*str != '\0') { \
4092 Xstrdup_a(str, str, return -1); \
4094 if (*str != '\0') { \
4095 compose->to_list = address_list_append \
4096 (compose->to_list, str); \
4097 compose_convert_header \
4098 (buf, sizeof(buf), str, strlen(header) + 2, \
4100 fprintf(fp, "%s: %s\n", header, buf); \
4105 #define IS_IN_CUSTOM_HEADER(header) \
4106 (compose->account->add_customhdr && \
4107 custom_header_find(compose->account->customhdr_list, header) != NULL)
4109 static gint compose_write_headers_from_headerlist(Compose *compose,
4111 const gchar *header,
4112 const gchar *seperator)
4114 gchar *str, *header_w_colon, *trans_hdr;
4115 gboolean write_header = FALSE;
4117 ComposeHeaderEntry *headerentry;
4118 gchar * headerentryname;
4121 if (IS_IN_CUSTOM_HEADER(header)) {
4125 debug_print("Writing %s-header\n", header);
4127 headerstr = g_string_sized_new(64);
4129 header_w_colon = g_strconcat(header, ":", NULL);
4130 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
4132 for (list = compose->header_list; list; list = list->next) {
4133 headerentry = ((ComposeHeaderEntry *)list->data);
4134 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
4136 if (!g_strcasecmp(trans_hdr, headerentryname)) {
4137 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4138 Xstrdup_a(str, str, return -1);
4140 if (str[0] != '\0') {
4142 g_string_append(headerstr, seperator);
4143 g_string_append(headerstr, str);
4144 write_header = TRUE;
4151 buf = g_new0(gchar, headerstr->len * 4 + 256);
4152 compose_convert_header
4153 (buf, headerstr->len * 4 + 256, headerstr->str,
4154 strlen(header) + 2, TRUE);
4155 fprintf(fp, "%s: %s\n", header, buf);
4159 g_free(header_w_colon);
4160 g_string_free(headerstr, TRUE);
4165 static gint compose_write_headers(Compose *compose, FILE *fp,
4166 const gchar *charset, EncodingType encoding,
4169 gchar buf[BUFFSIZE];
4173 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4175 /* struct utsname utsbuf; */
4177 g_return_val_if_fail(fp != NULL, -1);
4178 g_return_val_if_fail(charset != NULL, -1);
4179 g_return_val_if_fail(compose->account != NULL, -1);
4180 g_return_val_if_fail(compose->account->address != NULL, -1);
4182 /* Save draft infos */
4184 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
4185 fprintf(fp, "S:%s\n", compose->account->address);
4186 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
4187 gchar *savefolderid;
4189 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
4190 fprintf(fp, "SCF:%s\n", savefolderid);
4191 g_free(savefolderid);
4197 if (compose->account->add_date) {
4198 get_rfc822_date(buf, sizeof(buf));
4199 fprintf(fp, "Date: %s\n", buf);
4203 if (!IS_IN_CUSTOM_HEADER("From")) {
4204 if (compose->account->name && *compose->account->name) {
4205 compose_convert_header
4206 (buf, sizeof(buf), compose->account->name,
4207 strlen("From: "), TRUE);
4208 QUOTE_IF_REQUIRED(name, buf);
4209 fprintf(fp, "From: %s <%s>\n",
4210 name, compose->account->address);
4212 fprintf(fp, "From: %s\n", compose->account->address);
4216 compose_write_headers_from_headerlist(compose, fp, "To", ", ");
4217 #if 0 /* NEW COMPOSE GUI */
4218 if (compose->use_to) {
4219 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
4220 PUT_RECIPIENT_HEADER("To", str);
4225 compose_write_headers_from_headerlist(compose, fp, "Newsgroups", ",");
4226 #if 0 /* NEW COMPOSE GUI */
4227 if (compose->use_newsgroups) {
4228 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
4230 Xstrdup_a(str, str, return -1);
4234 compose->newsgroup_list =
4235 newsgroup_list_append
4236 (compose->newsgroup_list, str);
4237 compose_convert_header(buf, sizeof(buf), str,
4238 strlen("Newsgroups: "),
4240 fprintf(fp, "Newsgroups: %s\n", buf);
4246 compose_write_headers_from_headerlist(compose, fp, "Cc", ", ");
4247 #if 0 /* NEW COMPOSE GUI */
4248 if (compose->use_cc) {
4249 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
4250 PUT_RECIPIENT_HEADER("Cc", str);
4254 compose_write_headers_from_headerlist(compose, fp, "Bcc", ", ");
4255 #if 0 /* NEW COMPOSE GUI */
4256 if (compose->use_bcc) {
4257 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
4258 PUT_RECIPIENT_HEADER("Bcc", str);
4263 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
4264 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
4265 Xstrdup_a(str, str, return -1);
4268 compose_convert_header(buf, sizeof(buf), str,
4269 strlen("Subject: "), FALSE);
4270 fprintf(fp, "Subject: %s\n", buf);
4275 if (compose->account->gen_msgid) {
4276 compose_generate_msgid(compose, buf, sizeof(buf));
4277 fprintf(fp, "Message-Id: <%s>\n", buf);
4278 compose->msgid = g_strdup(buf);
4281 if (compose->remove_references == FALSE) {
4283 if (compose->inreplyto && compose->to_list)
4284 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
4287 if (compose->references)
4288 fprintf(fp, "References: %s\n", compose->references);
4292 compose_write_headers_from_headerlist(compose, fp, "Followup-To", ",");
4293 #if 0 /* NEW COMPOSE GUI */
4294 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
4295 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
4297 Xstrdup_a(str, str, return -1);
4301 compose_convert_header(buf, sizeof(buf), str,
4302 strlen("Followup-To: "),
4304 fprintf(fp, "Followup-To: %s\n", buf);
4310 compose_write_headers_from_headerlist(compose, fp, "Reply-To", ", ");
4311 #if 0 /* NEW COMPOSE GUI */
4312 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
4313 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
4315 Xstrdup_a(str, str, return -1);
4318 compose_convert_header(buf, sizeof(buf), str,
4319 strlen("Reply-To: "),
4321 fprintf(fp, "Reply-To: %s\n", buf);
4327 if (compose->account->organization &&
4328 !IS_IN_CUSTOM_HEADER("Organization")) {
4329 compose_convert_header(buf, sizeof(buf),
4330 compose->account->organization,
4331 strlen("Organization: "), FALSE);
4332 fprintf(fp, "Organization: %s\n", buf);
4335 /* Program version and system info */
4336 /* uname(&utsbuf); */
4337 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
4338 !compose->newsgroup_list) {
4339 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4341 gtk_major_version, gtk_minor_version, gtk_micro_version,
4343 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4345 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4346 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4348 gtk_major_version, gtk_minor_version, gtk_micro_version,
4350 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4353 /* custom headers */
4354 if (compose->account->add_customhdr) {
4357 for (cur = compose->account->customhdr_list; cur != NULL;
4359 CustomHeader *chdr = (CustomHeader *)cur->data;
4361 if (strcasecmp(chdr->name, "Date") != 0 &&
4362 strcasecmp(chdr->name, "From") != 0 &&
4363 strcasecmp(chdr->name, "To") != 0 &&
4364 /* strcasecmp(chdr->name, "Sender") != 0 && */
4365 strcasecmp(chdr->name, "Message-Id") != 0 &&
4366 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
4367 strcasecmp(chdr->name, "References") != 0 &&
4368 strcasecmp(chdr->name, "Mime-Version") != 0 &&
4369 strcasecmp(chdr->name, "Content-Type") != 0 &&
4370 strcasecmp(chdr->name, "Content-Transfer-Encoding")
4372 compose_convert_header
4374 chdr->value ? chdr->value : "",
4375 strlen(chdr->name) + 2, FALSE);
4376 fprintf(fp, "%s: %s\n", chdr->name, buf);
4382 fprintf(fp, "Mime-Version: 1.0\n");
4383 if (compose_use_attach(compose)) {
4384 compose->boundary = generate_mime_boundary(NULL);
4386 "Content-Type: multipart/mixed;\n"
4387 " boundary=\"%s\"\n", compose->boundary);
4389 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
4391 if (compose->use_signing && !compose->gnupg_mode)
4392 fprintf(fp, "Content-Disposition: inline\n");
4394 fprintf(fp, "Content-Transfer-Encoding: %s\n",
4395 procmime_get_encoding_str(encoding));
4399 switch (compose->priority) {
4400 case PRIORITY_HIGHEST: fprintf(fp, "Importance: high\n"
4401 "X-Priority: 1 (Highest)\n");
4403 case PRIORITY_HIGH: fprintf(fp, "Importance: high\n"
4404 "X-Priority: 2 (High)\n");
4406 case PRIORITY_NORMAL: break;
4407 case PRIORITY_LOW: fprintf(fp, "Importance: low\n"
4408 "X-Priority: 4 (Low)\n");
4410 case PRIORITY_LOWEST: fprintf(fp, "Importance: low\n"
4411 "X-Priority: 5 (Lowest)\n");
4413 default: debug_print("compose: priority unknown : %d\n",
4417 /* Request Return Receipt */
4418 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4419 if (compose->return_receipt) {
4420 if (compose->account->name
4421 && *compose->account->name) {
4422 compose_convert_header(buf, sizeof(buf),
4423 compose->account->name,
4424 strlen("Disposition-Notification-To: "),
4426 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4428 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
4432 /* get special headers */
4433 for (list = compose->header_list; list; list = list->next) {
4434 ComposeHeaderEntry *headerentry;
4437 gchar *headername_wcolon;
4438 gchar *headername_trans;
4441 gboolean standard_header = FALSE;
4443 headerentry = ((ComposeHeaderEntry *)list->data);
4445 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4446 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4451 if (!strstr(tmp, ":")) {
4452 headername_wcolon = g_strconcat(tmp, ":", NULL);
4453 headername = g_strdup(tmp);
4455 headername_wcolon = g_strdup(tmp);
4456 headername = g_strdup(strtok(tmp, ":"));
4460 headervalue = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4461 subst_char(headervalue, '\r', ' ');
4462 subst_char(headervalue, '\n', ' ');
4463 string = std_headers;
4464 while (*string != NULL) {
4465 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4466 if (!strcmp(headername_trans,headername_wcolon))
4467 standard_header = TRUE;
4470 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4471 fprintf(fp, "%s %s\n", headername_wcolon, headervalue);
4474 g_free(headername_wcolon);
4477 /* separator between header and body */
4483 #undef IS_IN_CUSTOM_HEADER
4485 static void compose_convert_header(gchar *dest, gint len, gchar *src,
4486 gint header_len, gboolean addr_field)
4488 g_return_if_fail(src != NULL);
4489 g_return_if_fail(dest != NULL);
4491 if (len < 1) return;
4493 subst_char(src, '\n', ' ');
4494 subst_char(src, '\r', ' ');
4497 conv_encode_header(dest, len, src, header_len, addr_field);
4500 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
4509 if (compose->account && compose->account->address &&
4510 *compose->account->address) {
4511 if (strchr(compose->account->address, '@'))
4512 addr = g_strdup(compose->account->address);
4514 addr = g_strconcat(compose->account->address, "@",
4515 get_domain_name(), NULL);
4517 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
4520 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
4521 lt->tm_year + 1900, lt->tm_mon + 1,
4522 lt->tm_mday, lt->tm_hour,
4523 lt->tm_min, lt->tm_sec,
4524 (guint)random(), addr);
4526 debug_print("generated Message-ID: %s\n", buf);
4531 static void compose_create_header_entry(Compose *compose)
4533 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4537 GList *combo_list = NULL;
4538 gchar **string, *header = NULL;
4539 ComposeHeaderEntry *headerentry;
4540 gboolean standard_header = FALSE;
4542 headerentry = g_new0(ComposeHeaderEntry, 1);
4545 combo = gtk_combo_new();
4547 while(*string != NULL) {
4548 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4551 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4552 g_list_free(combo_list);
4553 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4554 gtk_widget_show(combo);
4555 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4556 if (compose->header_last) {
4557 gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4559 while (*string != NULL) {
4560 if (!strcmp(*string, last_header_entry))
4561 standard_header = TRUE;
4564 if (standard_header)
4565 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4567 if (!compose->header_last || !standard_header) {
4568 switch(compose->account->protocol) {
4570 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4573 header = prefs_common.trans_hdr ? _("To:") : "To:";
4578 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4581 entry = gtk_entry_new();
4582 gtk_widget_show(entry);
4583 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);
4585 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4586 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4587 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4589 address_completion_register_entry(GTK_ENTRY(entry));
4591 headerentry->compose = compose;
4592 headerentry->combo = combo;
4593 headerentry->entry = entry;
4594 headerentry->headernum = compose->header_nextrow;
4596 compose->header_nextrow++;
4597 compose->header_last = headerentry;
4600 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4602 ComposeHeaderEntry *last_header;
4604 last_header = compose->header_last;
4606 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4607 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4610 static GtkWidget *compose_create_header(Compose *compose)
4614 GtkWidget *from_optmenu_hbox;
4615 #if 0 /* NEW COMPOSE GUI */
4616 GtkWidget *to_entry;
4618 GtkWidget *newsgroups_entry;
4619 GtkWidget *newsgroups_hbox;
4621 GtkWidget *header_scrolledwin;
4622 GtkWidget *header_table;
4623 #if 0 /* NEW COMPOSE GUI */
4624 GtkWidget *cc_entry;
4626 GtkWidget *bcc_entry;
4627 GtkWidget *bcc_hbox;
4628 GtkWidget *reply_entry;
4629 GtkWidget *reply_hbox;
4630 GtkWidget *followup_entry;
4631 GtkWidget *followup_hbox;
4636 /* header labels and entries */
4637 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4638 gtk_widget_show(header_scrolledwin);
4639 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4641 header_table = gtk_table_new(2, 2, FALSE);
4642 gtk_widget_show(header_table);
4643 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4644 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4645 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4648 /* option menu for selecting accounts */
4649 hbox = gtk_hbox_new(FALSE, 0);
4650 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4651 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4652 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4654 from_optmenu_hbox = compose_account_option_menu_create(compose);
4655 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4656 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4657 #if 0 /* NEW COMPOSE GUI */
4658 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4662 compose->header_table = header_table;
4663 compose->header_list = NULL;
4664 compose->header_nextrow = count;
4666 compose_create_header_entry(compose);
4668 #if 0 /* NEW COMPOSE GUI */
4669 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4671 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4672 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4673 &count, "Newsgroups:", FALSE);
4674 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4676 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4678 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4680 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4681 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4683 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4684 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4686 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4687 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4688 "Followup-To:", FALSE);
4689 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4691 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4693 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4694 GTK_SIGNAL_FUNC(to_activated), compose);
4695 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4696 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4697 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4698 GTK_SIGNAL_FUNC(subject_activated), compose);
4699 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4700 GTK_SIGNAL_FUNC(cc_activated), compose);
4701 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4702 GTK_SIGNAL_FUNC(bcc_activated), compose);
4703 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4704 GTK_SIGNAL_FUNC(replyto_activated), compose);
4705 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4706 GTK_SIGNAL_FUNC(followupto_activated), compose);
4708 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4709 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4710 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4711 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4712 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4713 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4714 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4715 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4716 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4717 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4718 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4719 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4720 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4721 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4724 compose->table = NULL;
4725 #if 0 /* NEW COMPOSE GUI */
4726 compose->table = table;
4727 compose->to_hbox = to_hbox;
4728 compose->to_entry = to_entry;
4729 compose->newsgroups_hbox = newsgroups_hbox;
4730 compose->newsgroups_entry = newsgroups_entry;
4732 #if 0 /* NEW COMPOSE GUI */
4733 compose->cc_hbox = cc_hbox;
4734 compose->cc_entry = cc_entry;
4735 compose->bcc_hbox = bcc_hbox;
4736 compose->bcc_entry = bcc_entry;
4737 compose->reply_hbox = reply_hbox;
4738 compose->reply_entry = reply_entry;
4739 compose->followup_hbox = followup_hbox;
4740 compose->followup_entry = followup_entry;
4743 return header_scrolledwin ;
4746 GtkWidget *compose_create_attach(Compose *compose)
4748 gchar *titles[N_ATTACH_COLS];
4751 GtkWidget *attach_scrwin;
4752 GtkWidget *attach_clist;
4754 titles[COL_MIMETYPE] = _("MIME type");
4755 titles[COL_SIZE] = _("Size");
4756 titles[COL_NAME] = _("Name");
4758 /* attachment list */
4759 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4760 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4761 GTK_POLICY_AUTOMATIC,
4763 gtk_widget_set_usize(attach_scrwin, -1, 80);
4765 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4766 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4768 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4769 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4770 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4771 GTK_SELECTION_EXTENDED);
4772 for (i = 0; i < N_ATTACH_COLS; i++)
4773 GTK_WIDGET_UNSET_FLAGS
4774 (GTK_CLIST(attach_clist)->column[i].button,
4776 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4778 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4779 GTK_SIGNAL_FUNC(attach_selected), compose);
4780 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4781 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4782 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4783 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4786 gtk_drag_dest_set(attach_clist,
4787 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4788 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4789 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4790 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4793 compose->attach_scrwin = attach_scrwin;
4794 compose->attach_clist = attach_clist;
4796 return attach_scrwin;
4799 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4800 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4802 static GtkWidget *compose_create_others(Compose *compose)
4805 GtkWidget *savemsg_checkbtn;
4806 GtkWidget *savemsg_entry;
4807 GtkWidget *savemsg_select;
4810 gchar *folderidentifier;
4812 /* Table for settings */
4813 table = gtk_table_new(3, 1, FALSE);
4814 gtk_widget_show(table);
4815 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4818 /* Save Message to folder */
4819 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4820 gtk_widget_show(savemsg_checkbtn);
4821 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4822 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4823 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4825 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4826 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4828 savemsg_entry = gtk_entry_new();
4829 gtk_widget_show(savemsg_entry);
4830 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4831 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4832 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4833 folderidentifier = folder_item_get_identifier(account_get_special_folder
4834 (compose->account, F_OUTBOX));
4835 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4836 g_free(folderidentifier);
4839 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4840 gtk_widget_show (savemsg_select);
4841 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4842 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4843 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4848 compose->savemsg_checkbtn = savemsg_checkbtn;
4849 compose->savemsg_entry = savemsg_entry;
4854 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4856 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4857 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4860 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4865 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4868 path = folder_item_get_identifier(dest);
4870 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4874 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4880 GtkWidget *handlebox;
4882 GtkWidget *notebook;
4887 GtkWidget *subject_hbox;
4888 GtkWidget *subject_frame;
4889 GtkWidget *subject_entry;
4893 GtkWidget *edit_vbox;
4894 GtkWidget *ruler_hbox;
4896 GtkWidget *scrolledwin;
4899 UndoMain *undostruct;
4901 gchar *titles[N_ATTACH_COLS];
4902 guint n_menu_entries;
4903 GtkStyle *style, *new_style;
4906 gboolean success[1];
4907 GtkWidget *popupmenu;
4908 GtkItemFactory *popupfactory;
4909 GtkItemFactory *ifactory;
4910 GtkWidget *tmpl_menu;
4914 GtkAspell * gtkaspell = NULL;
4917 static GdkGeometry geometry;
4919 g_return_val_if_fail(account != NULL, NULL);
4921 debug_print("Creating compose window...\n");
4922 compose = g_new0(Compose, 1);
4924 titles[COL_MIMETYPE] = _("MIME type");
4925 titles[COL_SIZE] = _("Size");
4926 titles[COL_NAME] = _("Name");
4928 compose->account = account;
4930 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4931 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4932 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4933 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4935 if (!geometry.max_width) {
4936 geometry.max_width = gdk_screen_width();
4937 geometry.max_height = gdk_screen_height();
4939 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4940 &geometry, GDK_HINT_MAX_SIZE);
4942 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4943 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4944 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4945 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4946 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4947 gtk_widget_realize(window);
4949 gtkut_widget_set_composer_icon(window);
4951 vbox = gtk_vbox_new(FALSE, 0);
4952 gtk_container_add(GTK_CONTAINER(window), vbox);
4954 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4955 menubar = menubar_create(window, compose_entries,
4956 n_menu_entries, "<Compose>", compose);
4957 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4959 handlebox = gtk_handle_box_new();
4960 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4962 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
4965 vbox2 = gtk_vbox_new(FALSE, 2);
4966 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4967 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4970 notebook = gtk_notebook_new();
4971 gtk_widget_set_usize(notebook, -1, 130);
4972 gtk_widget_show(notebook);
4974 /* header labels and entries */
4975 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4976 /* attachment list */
4977 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4979 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4982 subject_hbox = gtk_hbox_new(FALSE, 0);
4983 gtk_widget_show(subject_hbox);
4985 subject_frame = gtk_frame_new(NULL);
4986 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4987 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4988 gtk_widget_show(subject_frame);
4990 subject = gtk_hbox_new(FALSE, 0);
4991 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4992 gtk_widget_show(subject);
4994 label = gtk_label_new(_("Subject:"));
4995 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4996 gtk_widget_show(label);
4998 subject_entry = gtk_entry_new();
4999 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
5000 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
5001 gtk_widget_show(subject_entry);
5002 compose->subject_entry = subject_entry;
5003 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
5005 edit_vbox = gtk_vbox_new(FALSE, 0);
5006 #if 0 /* NEW COMPOSE GUI */
5007 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
5010 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
5013 ruler_hbox = gtk_hbox_new(FALSE, 0);
5014 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
5016 ruler = gtk_shruler_new();
5017 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
5018 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
5020 gtk_widget_set_usize(ruler_hbox, 1, -1);
5023 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
5024 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
5025 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
5026 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
5027 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
5029 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
5030 (GTK_SCROLLED_WINDOW(scrolledwin)),
5031 gtk_scrolled_window_get_vadjustment
5032 (GTK_SCROLLED_WINDOW(scrolledwin)));
5033 GTK_STEXT(text)->default_tab_width = 8;
5034 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
5036 if (prefs_common.block_cursor) {
5037 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
5040 if (prefs_common.smart_wrapping) {
5041 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
5042 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
5045 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
5047 gtk_signal_connect(GTK_OBJECT(text), "changed",
5048 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
5049 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
5050 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
5051 gtk_signal_connect(GTK_OBJECT(text), "activate",
5052 GTK_SIGNAL_FUNC(text_activated), compose);
5053 gtk_signal_connect(GTK_OBJECT(text), "insert_text",
5054 GTK_SIGNAL_FUNC(text_inserted), compose);
5055 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
5056 GTK_SIGNAL_FUNC(compose_button_press_cb),
5059 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
5060 GTK_SIGNAL_FUNC(compose_key_press_cb),
5063 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
5064 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
5068 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
5069 GDK_ACTION_COPY | GDK_ACTION_MOVE);
5070 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
5071 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
5073 gtk_widget_show_all(vbox);
5075 /* pane between attach clist and text */
5076 paned = gtk_vpaned_new();
5077 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
5078 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
5079 gtk_container_add(GTK_CONTAINER(vbox2), paned);
5080 gtk_paned_add1(GTK_PANED(paned), notebook);
5081 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
5082 gtk_widget_show_all(paned);
5084 style = gtk_widget_get_style(text);
5086 /* workaround for the slow down of GtkSText when using Pixmap theme */
5087 if (style->engine) {
5088 GtkThemeEngine *engine;
5090 engine = style->engine;
5091 style->engine = NULL;
5092 new_style = gtk_style_copy(style);
5093 style->engine = engine;
5095 new_style = gtk_style_copy(style);
5097 if (prefs_common.textfont) {
5100 if ((font = gtkut_font_load(prefs_common.textfont)) != NULL) {
5101 gdk_font_unref(new_style->font);
5102 new_style->font = font;
5106 gtk_widget_set_style(text, new_style);
5108 color[0] = quote_color;
5109 cmap = gdk_window_get_colormap(window->window);
5110 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
5111 if (success[0] == FALSE) {
5112 g_warning("Compose: color allocation failed.\n");
5113 style = gtk_widget_get_style(text);
5114 quote_color = style->black;
5117 n_entries = sizeof(compose_popup_entries) /
5118 sizeof(compose_popup_entries[0]);
5119 popupmenu = menu_create_items(compose_popup_entries, n_entries,
5120 "<Compose>", &popupfactory,
5123 ifactory = gtk_item_factory_from_widget(menubar);
5124 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5125 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5126 menu_set_sensitive(ifactory, "/Message/Remove references", FALSE);
5128 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5129 #if 0 /* NEW COMPOSE GUI */
5130 gtk_widget_hide(bcc_hbox);
5131 gtk_widget_hide(bcc_entry);
5132 gtk_widget_hide(reply_hbox);
5133 gtk_widget_hide(reply_entry);
5134 gtk_widget_hide(followup_hbox);
5135 gtk_widget_hide(followup_entry);
5136 gtk_widget_hide(ruler_hbox);
5137 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
5138 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
5139 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
5141 if (account->protocol == A_NNTP) {
5142 gtk_widget_hide(to_hbox);
5143 gtk_widget_hide(to_entry);
5144 gtk_widget_hide(cc_hbox);
5145 gtk_widget_hide(cc_entry);
5146 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
5147 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
5149 gtk_widget_hide(newsgroups_hbox);
5150 gtk_widget_hide(newsgroups_entry);
5151 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
5155 action_update_compose_menu(ifactory, compose);
5158 undostruct = undo_init(text);
5159 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
5162 address_completion_start(window);
5164 compose->window = window;
5165 compose->vbox = vbox;
5166 compose->menubar = menubar;
5167 compose->handlebox = handlebox;
5169 compose->vbox2 = vbox2;
5171 compose->paned = paned;
5173 compose->edit_vbox = edit_vbox;
5174 compose->ruler_hbox = ruler_hbox;
5175 compose->ruler = ruler;
5176 compose->scrolledwin = scrolledwin;
5177 compose->text = text;
5179 compose->focused_editable = NULL;
5181 compose->popupmenu = popupmenu;
5182 compose->popupfactory = popupfactory;
5184 compose->tmpl_menu = tmpl_menu;
5186 compose->mode = mode;
5188 compose->targetinfo = NULL;
5189 compose->replyinfo = NULL;
5190 compose->fwdinfo = NULL;
5192 compose->replyto = NULL;
5194 compose->bcc = NULL;
5195 compose->followup_to = NULL;
5197 compose->ml_post = NULL;
5199 compose->inreplyto = NULL;
5200 compose->references = NULL;
5201 compose->msgid = NULL;
5202 compose->boundary = NULL;
5205 compose->use_signing = FALSE;
5206 compose->use_encryption = FALSE;
5207 #endif /* USE_GPGME */
5209 compose->modified = FALSE;
5211 compose->return_receipt = FALSE;
5213 compose->to_list = NULL;
5214 compose->newsgroup_list = NULL;
5216 compose->undostruct = undostruct;
5218 compose->sig_str = NULL;
5220 compose->exteditor_file = NULL;
5221 compose->exteditor_pid = -1;
5222 compose->exteditor_readdes = -1;
5223 compose->exteditor_tag = -1;
5226 menu_set_sensitive(ifactory, "/Spelling", FALSE);
5227 if (mode != COMPOSE_REDIRECT) {
5228 if (prefs_common.enable_aspell && prefs_common.dictionary &&
5229 strcmp(prefs_common.dictionary, _("None"))) {
5230 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
5231 prefs_common.dictionary,
5232 conv_get_current_charset_str(),
5233 prefs_common.misspelled_col,
5234 prefs_common.check_while_typing,
5235 prefs_common.use_alternate,
5238 alertpanel_error(_("Spell checker could not "
5240 gtkaspell_checkers_strerror());
5241 gtkaspell_checkers_reset_error();
5244 GtkWidget *menuitem;
5246 if (!gtkaspell_set_sug_mode(gtkaspell,
5247 prefs_common.aspell_sugmode)) {
5248 debug_print("Aspell: could not set "
5249 "suggestion mode %s\n",
5250 gtkaspell_checkers_strerror());
5251 gtkaspell_checkers_reset_error();
5254 menuitem = gtk_item_factory_get_item(ifactory,
5255 "/Spelling/Spelling Configuration");
5256 gtkaspell_populate_submenu(gtkaspell, menuitem);
5257 menu_set_sensitive(ifactory, "/Spelling", TRUE);
5263 compose_select_account(compose, account, TRUE);
5266 compose->gtkaspell = gtkaspell;
5269 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
5270 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
5272 if (account->set_autobcc)
5273 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
5275 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
5276 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
5279 if (account->protocol != A_NNTP)
5280 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
5282 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
5284 addressbook_set_target_compose(compose);
5285 action_update_compose_menu(ifactory, compose);
5287 if (mode != COMPOSE_REDIRECT)
5288 compose_set_template_menu(compose);
5290 GtkWidget *menuitem;
5291 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
5292 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
5295 compose_list = g_list_append(compose_list, compose);
5297 if (!prefs_common.show_ruler)
5298 gtk_widget_hide(ruler_hbox);
5301 compose->priority = PRIORITY_NORMAL;
5302 compose_update_priority_menu_item(compose);
5305 activate_gnupg_mode(compose, account);
5307 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
5308 gtk_widget_show(window);
5313 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5319 gint num = 0, def_menu = 0;
5321 accounts = account_get_list();
5322 g_return_val_if_fail(accounts != NULL, NULL);
5324 hbox = gtk_hbox_new(FALSE, 0);
5325 optmenu = gtk_option_menu_new();
5326 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5327 menu = gtk_menu_new();
5329 for (; accounts != NULL; accounts = accounts->next, num++) {
5330 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5331 GtkWidget *menuitem;
5334 if (ac == compose->account) def_menu = num;
5337 name = g_strdup_printf("%s: %s <%s>",
5339 ac->name, ac->address);
5341 name = g_strdup_printf("%s: %s",
5342 ac->account_name, ac->address);
5343 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5345 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
5346 GTK_SIGNAL_FUNC(account_activated),
5350 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5351 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5356 static void compose_set_priority_cb(gpointer data,
5360 Compose *compose = (Compose *) data;
5361 compose->priority = action;
5364 static void compose_update_priority_menu_item(Compose * compose)
5366 GtkItemFactory *ifactory;
5367 GtkWidget *menuitem = NULL;
5369 ifactory = gtk_item_factory_from_widget(compose->menubar);
5371 switch (compose->priority) {
5372 case PRIORITY_HIGHEST:
5373 menuitem = gtk_item_factory_get_item
5374 (ifactory, "/Message/Priority/Highest");
5377 menuitem = gtk_item_factory_get_item
5378 (ifactory, "/Message/Priority/High");
5380 case PRIORITY_NORMAL:
5381 menuitem = gtk_item_factory_get_item
5382 (ifactory, "/Message/Priority/Normal");
5385 menuitem = gtk_item_factory_get_item
5386 (ifactory, "/Message/Priority/Low");
5388 case PRIORITY_LOWEST:
5389 menuitem = gtk_item_factory_get_item
5390 (ifactory, "/Message/Priority/Lowest");
5393 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5397 static void compose_set_gnupg_mode_cb(gpointer data,
5401 Compose *compose = (Compose *) data;
5402 compose->gnupg_mode = action;
5405 static void compose_update_gnupg_mode_menu_item(Compose * compose)
5407 GtkItemFactory *ifactory;
5408 GtkWidget *menuitem = NULL;
5410 ifactory = gtk_item_factory_from_widget(compose->menubar);
5412 switch (compose->gnupg_mode) {
5413 case GNUPG_MODE_DETACH:
5414 menuitem = gtk_item_factory_get_item
5415 (ifactory, "/Message/Mode/MIME");
5417 case GNUPG_MODE_INLINE:
5418 menuitem = gtk_item_factory_get_item
5419 (ifactory, "/Message/Mode/Inline");
5422 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5424 if (compose->use_encryption == TRUE || compose->use_signing == TRUE)
5425 menu_set_sensitive(ifactory, "/Message/Mode", TRUE);
5427 menu_set_sensitive(ifactory, "/Message/Mode", FALSE);
5431 static void compose_set_template_menu(Compose *compose)
5433 GSList *tmpl_list, *cur;
5437 tmpl_list = template_get_config();
5439 menu = gtk_menu_new();
5441 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5442 Template *tmpl = (Template *)cur->data;
5444 item = gtk_menu_item_new_with_label(tmpl->name);
5445 gtk_menu_append(GTK_MENU(menu), item);
5446 gtk_signal_connect(GTK_OBJECT(item), "activate",
5447 GTK_SIGNAL_FUNC(compose_template_activate_cb),
5449 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
5450 gtk_widget_show(item);
5453 gtk_widget_show(menu);
5454 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5457 void compose_reflect_prefs_all(void)
5462 for (cur = compose_list; cur != NULL; cur = cur->next) {
5463 compose = (Compose *)cur->data;
5464 compose_set_template_menu(compose);
5468 void compose_reflect_prefs_pixmap_theme(void)
5473 for (cur = compose_list; cur != NULL; cur = cur->next) {
5474 compose = (Compose *)cur->data;
5475 toolbar_update(TOOLBAR_COMPOSE, compose);
5479 static void compose_template_apply(Compose *compose, Template *tmpl,
5485 if (!tmpl || !tmpl->value) return;
5487 gtk_stext_freeze(GTK_STEXT(compose->text));
5489 if (tmpl->subject && *tmpl->subject != '\0')
5490 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5492 if (tmpl->to && *tmpl->to != '\0')
5493 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5494 if (tmpl->cc && *tmpl->cc != '\0')
5495 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5497 if (tmpl->bcc && *tmpl->bcc != '\0')
5498 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5501 gtkut_stext_clear(GTK_STEXT(compose->text));
5503 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
5504 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5507 if (prefs_common.quotemark && *prefs_common.quotemark)
5508 qmark = prefs_common.quotemark;
5512 if (compose->replyinfo != NULL)
5513 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5514 tmpl->value, qmark, NULL);
5515 else if (compose->fwdinfo != NULL)
5516 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
5517 tmpl->value, qmark, NULL);
5522 if (replace && parsed_str && compose->account->auto_sig)
5523 compose_insert_sig(compose, FALSE);
5525 if (replace && parsed_str) {
5526 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
5527 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
5531 compose_changed_cb(NULL, compose);
5533 gtk_stext_thaw(GTK_STEXT(compose->text));
5536 static void compose_destroy(Compose *compose)
5539 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5542 /* NOTE: address_completion_end() does nothing with the window
5543 * however this may change. */
5544 address_completion_end(compose->window);
5546 slist_free_strings(compose->to_list);
5547 g_slist_free(compose->to_list);
5548 slist_free_strings(compose->newsgroup_list);
5549 g_slist_free(compose->newsgroup_list);
5550 slist_free_strings(compose->header_list);
5551 g_slist_free(compose->header_list);
5553 procmsg_msginfo_free(compose->targetinfo);
5554 procmsg_msginfo_free(compose->replyinfo);
5555 procmsg_msginfo_free(compose->fwdinfo);
5557 g_free(compose->replyto);
5558 g_free(compose->cc);
5559 g_free(compose->bcc);
5560 g_free(compose->newsgroups);
5561 g_free(compose->followup_to);
5563 g_free(compose->ml_post);
5565 g_free(compose->inreplyto);
5566 g_free(compose->references);
5567 g_free(compose->msgid);
5568 g_free(compose->boundary);
5570 if (compose->redirect_filename)
5571 g_free(compose->redirect_filename);
5572 if (compose->undostruct)
5573 undo_destroy(compose->undostruct);
5575 g_free(compose->sig_str);
5577 g_free(compose->exteditor_file);
5579 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5581 compose_attach_info_free(ainfo);
5583 if (addressbook_get_target_compose() == compose)
5584 addressbook_set_target_compose(NULL);
5587 if (compose->gtkaspell) {
5588 gtkaspell_delete(compose->gtkaspell);
5592 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5593 prefs_common.compose_height = compose->window->allocation.height;
5595 gtk_widget_destroy(compose->paned);
5597 toolbar_destroy(compose->toolbar);
5598 g_free(compose->toolbar);
5601 compose_list = g_list_remove(compose_list, compose);
5604 static void compose_attach_info_free(AttachInfo *ainfo)
5606 g_free(ainfo->file);
5607 g_free(ainfo->content_type);
5608 g_free(ainfo->name);
5612 static void compose_attach_remove_selected(Compose *compose)
5614 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5618 while (clist->selection != NULL) {
5619 row = GPOINTER_TO_INT(clist->selection->data);
5620 ainfo = gtk_clist_get_row_data(clist, row);
5621 compose_attach_info_free(ainfo);
5622 gtk_clist_remove(clist, row);
5626 static struct _AttachProperty
5629 GtkWidget *mimetype_entry;
5630 GtkWidget *encoding_optmenu;
5631 GtkWidget *path_entry;
5632 GtkWidget *filename_entry;
5634 GtkWidget *cancel_btn;
5637 static void compose_attach_property(Compose *compose)
5639 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5642 GtkOptionMenu *optmenu;
5643 static gboolean cancelled;
5645 if (!clist->selection) return;
5646 row = GPOINTER_TO_INT(clist->selection->data);
5648 ainfo = gtk_clist_get_row_data(clist, row);
5651 if (!attach_prop.window)
5652 compose_attach_property_create(&cancelled);
5653 gtk_widget_grab_focus(attach_prop.ok_btn);
5654 gtk_widget_show(attach_prop.window);
5655 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5657 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5658 if (ainfo->encoding == ENC_UNKNOWN)
5659 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5660 GINT_TO_POINTER(ENC_BASE64));
5662 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5663 GINT_TO_POINTER(ainfo->encoding));
5665 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5666 ainfo->content_type ? ainfo->content_type : "");
5667 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5668 ainfo->file ? ainfo->file : "");
5669 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5670 ainfo->name ? ainfo->name : "");
5674 gchar *cnttype = NULL;
5678 GtkWidget *menuitem;
5683 if (cancelled == TRUE) {
5684 gtk_widget_hide(attach_prop.window);
5688 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5689 if (*text != '\0') {
5692 text = g_strstrip(g_strdup(text));
5693 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5694 cnttype = g_strdup(text);
5697 alertpanel_error(_("Invalid MIME type."));
5703 menu = gtk_option_menu_get_menu(optmenu);
5704 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5705 ainfo->encoding = GPOINTER_TO_INT
5706 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5708 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5709 if (*text != '\0') {
5710 if (is_file_exist(text) &&
5711 (size = get_file_size(text)) > 0)
5712 file = g_strdup(text);
5715 (_("File doesn't exist or is empty."));
5721 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5722 if (*text != '\0') {
5723 g_free(ainfo->name);
5724 ainfo->name = g_strdup(text);
5728 g_free(ainfo->content_type);
5729 ainfo->content_type = cnttype;
5732 g_free(ainfo->file);
5738 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5739 ainfo->content_type);
5740 gtk_clist_set_text(clist, row, COL_SIZE,
5741 to_human_readable(ainfo->size));
5742 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5744 gtk_widget_hide(attach_prop.window);
5749 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5751 label = gtk_label_new(str); \
5752 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5753 GTK_FILL, 0, 0, 0); \
5754 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5756 entry = gtk_entry_new(); \
5757 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5758 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5761 static void compose_attach_property_create(gboolean *cancelled)
5767 GtkWidget *mimetype_entry;
5770 GtkWidget *optmenu_menu;
5771 GtkWidget *menuitem;
5772 GtkWidget *path_entry;
5773 GtkWidget *filename_entry;
5776 GtkWidget *cancel_btn;
5777 GList *mime_type_list, *strlist;
5779 debug_print("Creating attach_property window...\n");
5781 window = gtk_window_new(GTK_WINDOW_DIALOG);
5782 gtk_widget_set_usize(window, 480, -1);
5783 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5784 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
5785 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5786 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5787 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5788 GTK_SIGNAL_FUNC(attach_property_delete_event),
5790 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5791 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5794 vbox = gtk_vbox_new(FALSE, 8);
5795 gtk_container_add(GTK_CONTAINER(window), vbox);
5797 table = gtk_table_new(4, 2, FALSE);
5798 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5799 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5800 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5802 label = gtk_label_new(_("MIME type"));
5803 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5805 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5806 mimetype_entry = gtk_combo_new();
5807 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5808 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5810 /* stuff with list */
5811 mime_type_list = procmime_get_mime_type_list();
5813 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5814 MimeType *type = (MimeType *) mime_type_list->data;
5815 strlist = g_list_append(strlist,
5816 g_strdup_printf("%s/%s",
5817 type->type, type->sub_type));
5820 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5822 for (mime_type_list = strlist; mime_type_list != NULL;
5823 mime_type_list = mime_type_list->next)
5824 g_free(mime_type_list->data);
5825 g_list_free(strlist);
5827 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5829 label = gtk_label_new(_("Encoding"));
5830 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5832 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5834 hbox = gtk_hbox_new(FALSE, 0);
5835 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5836 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5838 optmenu = gtk_option_menu_new();
5839 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5841 optmenu_menu = gtk_menu_new();
5842 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5843 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5845 gtk_widget_set_sensitive(menuitem, FALSE);
5847 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5848 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5850 gtk_widget_set_sensitive(menuitem, FALSE);
5852 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
5853 ENC_QUOTED_PRINTABLE);
5854 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5856 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5858 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5860 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5861 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5863 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5864 &cancel_btn, _("Cancel"), NULL, NULL);
5865 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5866 gtk_widget_grab_default(ok_btn);
5868 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5869 GTK_SIGNAL_FUNC(attach_property_ok),
5871 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5872 GTK_SIGNAL_FUNC(attach_property_cancel),
5875 gtk_widget_show_all(vbox);
5877 attach_prop.window = window;
5878 attach_prop.mimetype_entry = mimetype_entry;
5879 attach_prop.encoding_optmenu = optmenu;
5880 attach_prop.path_entry = path_entry;
5881 attach_prop.filename_entry = filename_entry;
5882 attach_prop.ok_btn = ok_btn;
5883 attach_prop.cancel_btn = cancel_btn;
5886 #undef SET_LABEL_AND_ENTRY
5888 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5894 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5900 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5901 gboolean *cancelled)
5909 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5910 gboolean *cancelled)
5912 if (event && event->keyval == GDK_Escape) {
5918 static void compose_exec_ext_editor(Compose *compose)
5924 tmp = g_strdup_printf("%s%ctmpmsg.%08x", get_tmp_dir(),
5925 G_DIR_SEPARATOR, (gint)compose);
5927 if (pipe(pipe_fds) < 0) {
5933 if ((pid = fork()) < 0) {
5940 /* close the write side of the pipe */
5943 compose->exteditor_file = g_strdup(tmp);
5944 compose->exteditor_pid = pid;
5945 compose->exteditor_readdes = pipe_fds[0];
5947 compose_set_ext_editor_sensitive(compose, FALSE);
5949 compose->exteditor_tag =
5950 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5951 compose_input_cb, compose);
5952 } else { /* process-monitoring process */
5958 /* close the read side of the pipe */
5961 if (compose_write_body_to_file(compose, tmp) < 0) {
5962 fd_write_all(pipe_fds[1], "2\n", 2);
5966 pid_ed = compose_exec_ext_editor_real(tmp);
5968 fd_write_all(pipe_fds[1], "1\n", 2);
5972 /* wait until editor is terminated */
5973 waitpid(pid_ed, NULL, 0);
5975 fd_write_all(pipe_fds[1], "0\n", 2);
5984 static gint compose_exec_ext_editor_real(const gchar *file)
5986 static gchar *def_cmd = "emacs %s";
5992 g_return_val_if_fail(file != NULL, -1);
5994 if ((pid = fork()) < 0) {
5999 if (pid != 0) return pid;
6001 /* grandchild process */
6003 if (setpgid(0, getppid()))
6006 if (prefs_common.ext_editor_cmd &&
6007 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
6008 *(p + 1) == 's' && !strchr(p + 2, '%')) {
6009 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
6011 if (prefs_common.ext_editor_cmd)
6012 g_warning("External editor command line is invalid: `%s'\n",
6013 prefs_common.ext_editor_cmd);
6014 g_snprintf(buf, sizeof(buf), def_cmd, file);
6017 cmdline = strsplit_with_quote(buf, " ", 1024);
6018 execvp(cmdline[0], cmdline);
6021 g_strfreev(cmdline);
6026 static gboolean compose_ext_editor_kill(Compose *compose)
6028 pid_t pgid = compose->exteditor_pid * -1;
6031 ret = kill(pgid, 0);
6033 if (ret == 0 || (ret == -1 && EPERM == errno)) {
6037 msg = g_strdup_printf
6038 (_("The external editor is still working.\n"
6039 "Force terminating the process?\n"
6040 "process group id: %d"), -pgid);
6041 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
6044 if (val == G_ALERTDEFAULT) {
6045 gdk_input_remove(compose->exteditor_tag);
6046 close(compose->exteditor_readdes);
6048 if (kill(pgid, SIGTERM) < 0) perror("kill");
6049 waitpid(compose->exteditor_pid, NULL, 0);
6051 g_warning("Terminated process group id: %d", -pgid);
6052 g_warning("Temporary file: %s",
6053 compose->exteditor_file);
6055 compose_set_ext_editor_sensitive(compose, TRUE);
6057 g_free(compose->exteditor_file);
6058 compose->exteditor_file = NULL;
6059 compose->exteditor_pid = -1;
6060 compose->exteditor_readdes = -1;
6061 compose->exteditor_tag = -1;
6069 static void compose_input_cb(gpointer data, gint source,
6070 GdkInputCondition condition)
6073 Compose *compose = (Compose *)data;
6076 debug_print("Compose: input from monitoring process\n");
6078 gdk_input_remove(compose->exteditor_tag);
6081 if (read(source, &buf[i], 1) < 1) {
6085 if (buf[i] == '\n') {
6090 if (i == sizeof(buf) - 1)
6094 waitpid(compose->exteditor_pid, NULL, 0);
6096 if (buf[0] == '0') { /* success */
6097 GtkSText *text = GTK_STEXT(compose->text);
6099 gtk_stext_freeze(text);
6100 gtk_stext_set_point(text, 0);
6101 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
6102 compose_insert_file(compose, compose->exteditor_file);
6103 compose_changed_cb(NULL, compose);
6104 gtk_stext_thaw(text);
6106 if (unlink(compose->exteditor_file) < 0)
6107 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6108 } else if (buf[0] == '1') { /* failed */
6109 g_warning("Couldn't exec external editor\n");
6110 if (unlink(compose->exteditor_file) < 0)
6111 FILE_OP_ERROR(compose->exteditor_file, "unlink");
6112 } else if (buf[0] == '2') {
6113 g_warning("Couldn't write to file\n");
6114 } else if (buf[0] == '3') {
6115 g_warning("Pipe read failed\n");
6120 compose_set_ext_editor_sensitive(compose, TRUE);
6122 g_free(compose->exteditor_file);
6123 compose->exteditor_file = NULL;
6124 compose->exteditor_pid = -1;
6125 compose->exteditor_readdes = -1;
6126 compose->exteditor_tag = -1;
6129 static void compose_set_ext_editor_sensitive(Compose *compose,
6132 GtkItemFactory *ifactory;
6134 ifactory = gtk_item_factory_from_widget(compose->menubar);
6136 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
6137 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
6138 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
6140 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
6141 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
6142 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
6143 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
6144 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
6147 gtk_widget_set_sensitive(compose->text, sensitive);
6148 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
6149 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
6150 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
6151 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
6152 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
6153 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
6154 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
6158 * compose_undo_state_changed:
6160 * Change the sensivity of the menuentries undo and redo
6162 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
6163 gint redo_state, gpointer data)
6165 GtkWidget *widget = GTK_WIDGET(data);
6166 GtkItemFactory *ifactory;
6168 g_return_if_fail(widget != NULL);
6170 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
6172 ifactory = gtk_item_factory_from_widget(widget);
6174 switch (undo_state) {
6175 case UNDO_STATE_TRUE:
6176 if (!undostruct->undo_state) {
6177 debug_print ("Set_undo - Testpoint\n");
6178 undostruct->undo_state = TRUE;
6179 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6182 case UNDO_STATE_FALSE:
6183 if (undostruct->undo_state) {
6184 undostruct->undo_state = FALSE;
6185 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6188 case UNDO_STATE_UNCHANGED:
6190 case UNDO_STATE_REFRESH:
6191 menu_set_sensitive(ifactory, "/Edit/Undo",
6192 undostruct->undo_state);
6195 g_warning("Undo state not recognized");
6199 switch (redo_state) {
6200 case UNDO_STATE_TRUE:
6201 if (!undostruct->redo_state) {
6202 undostruct->redo_state = TRUE;
6203 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6206 case UNDO_STATE_FALSE:
6207 if (undostruct->redo_state) {
6208 undostruct->redo_state = FALSE;
6209 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6212 case UNDO_STATE_UNCHANGED:
6214 case UNDO_STATE_REFRESH:
6215 menu_set_sensitive(ifactory, "/Edit/Redo",
6216 undostruct->redo_state);
6219 g_warning("Redo state not recognized");
6224 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
6228 cursor_pos = (text->cursor_pos_x - extra) / char_width;
6229 cursor_pos = MAX(cursor_pos, 0);
6234 /* callback functions */
6236 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
6237 * includes "non-client" (windows-izm) in calculation, so this calculation
6238 * may not be accurate.
6240 static gboolean compose_edit_size_alloc(GtkEditable *widget,
6241 GtkAllocation *allocation,
6242 GtkSHRuler *shruler)
6244 if (prefs_common.show_ruler) {
6246 gint line_width_in_chars;
6248 char_width = gtkut_get_font_width
6249 (GTK_WIDGET(widget)->style->font);
6250 line_width_in_chars =
6251 (allocation->width - allocation->x) / char_width;
6253 /* got the maximum */
6254 gtk_ruler_set_range(GTK_RULER(shruler),
6255 0.0, line_width_in_chars,
6256 calc_cursor_xpos(GTK_STEXT(widget),
6259 /*line_width_in_chars*/ char_width);
6265 static void account_activated(GtkMenuItem *menuitem, gpointer data)
6267 Compose *compose = (Compose *)data;
6271 ac = account_find_from_id(
6272 GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menuitem))));
6273 g_return_if_fail(ac != NULL);
6275 if (ac != compose->account)
6276 compose_select_account(compose, ac, FALSE);
6279 static void attach_selected(GtkCList *clist, gint row, gint column,
6280 GdkEvent *event, gpointer data)
6282 Compose *compose = (Compose *)data;
6284 if (event && event->type == GDK_2BUTTON_PRESS)
6285 compose_attach_property(compose);
6288 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
6291 Compose *compose = (Compose *)data;
6292 GtkCList *clist = GTK_CLIST(compose->attach_clist);
6297 if (event->button == 3) {
6298 if ((clist->selection && !clist->selection->next) ||
6299 !clist->selection) {
6300 gtk_clist_unselect_all(clist);
6301 if (gtk_clist_get_selection_info(clist,
6304 gtk_clist_select_row(clist, row, column);
6305 gtkut_clist_set_focus_row(clist, row);
6308 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
6309 NULL, NULL, event->button, event->time);
6313 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
6316 Compose *compose = (Compose *)data;
6320 switch (event->keyval) {
6322 compose_attach_remove_selected(compose);
6327 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6329 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6330 toolbar_comp_set_sensitive(compose, allow);
6331 menu_set_sensitive(ifactory, "/File", allow);
6332 menu_set_sensitive(ifactory, "/Edit", allow);
6334 menu_set_sensitive(ifactory, "/Spelling", allow);
6336 menu_set_sensitive(ifactory, "/Message", allow);
6337 menu_set_sensitive(ifactory, "/Tools", allow);
6338 menu_set_sensitive(ifactory, "/Help", allow);
6341 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6343 Compose *compose = (Compose *)data;
6346 if (prefs_common.work_offline)
6347 if (alertpanel(_("Offline warning"),
6348 _("You're working offline. Override?"),
6349 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
6352 compose_allow_user_actions (compose, FALSE);
6353 compose->sending = TRUE;
6354 val = compose_send(compose);
6355 compose_allow_user_actions (compose, TRUE);
6356 compose->sending = FALSE;
6358 if (val == 0) gtk_widget_destroy(compose->window);
6361 static void compose_send_later_cb(gpointer data, guint action,
6364 Compose *compose = (Compose *)data;
6367 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6368 if (!val) gtk_widget_destroy(compose->window);
6371 void compose_draft (gpointer data)
6373 compose_draft_cb(data, 0, NULL);
6376 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6378 Compose *compose = (Compose *)data;
6382 MsgFlags flag = {0, 0};
6383 static gboolean lock = FALSE;
6384 MsgInfo *newmsginfo;
6388 draft = account_get_special_folder(compose->account, F_DRAFT);
6389 g_return_if_fail(draft != NULL);
6393 tmp = g_strdup_printf("%s%cdraft.%08x", get_tmp_dir(),
6394 G_DIR_SEPARATOR, (gint)compose);
6396 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
6402 folder_item_scan(draft);
6403 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
6410 draft->mtime = 0; /* force updating */
6412 if (compose->mode == COMPOSE_REEDIT) {
6413 compose_remove_reedit_target(compose);
6416 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6418 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6419 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
6420 procmsg_msginfo_free(newmsginfo);
6423 folder_item_scan(draft);
6427 /* 0: quit editing 1: keep editing 2: keep editing (autosave) */
6429 gtk_widget_destroy(compose->window);
6434 path = folder_item_fetch_msg(draft, msgnum);
6435 g_return_if_fail(path != NULL);
6436 if (stat(path, &s) < 0) {
6437 FILE_OP_ERROR(path, "stat");
6444 procmsg_msginfo_free(compose->targetinfo);
6445 compose->targetinfo = procmsg_msginfo_new();
6446 compose->targetinfo->msgnum = msgnum;
6447 compose->targetinfo->size = s.st_size;
6448 compose->targetinfo->mtime = s.st_mtime;
6449 compose->targetinfo->folder = draft;
6450 compose->mode = COMPOSE_REEDIT;
6453 compose->autosaved_draft = compose->targetinfo;
6458 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6460 Compose *compose = (Compose *)data;
6463 if (compose->redirect_filename != NULL)
6466 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6471 for ( tmp = file_list; tmp; tmp = tmp->next) {
6472 gchar *file = (gchar *) tmp->data;
6473 compose_attach_append(compose, file, file, NULL);
6474 compose_changed_cb(NULL, compose);
6477 g_list_free(file_list);
6481 static void compose_insert_file_cb(gpointer data, guint action,
6484 Compose *compose = (Compose *)data;
6487 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6492 for ( tmp = file_list; tmp; tmp = tmp->next) {
6493 gchar *file = (gchar *) tmp->data;
6494 gchar *filedup = g_strdup(file);
6496 ComposeInsertResult res;
6498 res = compose_insert_file(compose, file);
6499 shortfile = g_basename(filedup);
6500 if (res == COMPOSE_INSERT_READ_ERROR) {
6501 alertpanel_error(_("File '%s' could not be read."), shortfile);
6502 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
6503 alertpanel_error(_("File '%s' contained invalid characters\n"
6504 "for the current encoding, insertion may be incorrect."), shortfile);
6509 g_list_free(file_list);
6513 static void compose_insert_sig_cb(gpointer data, guint action,
6516 Compose *compose = (Compose *)data;
6518 compose_insert_sig(compose, FALSE);
6521 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6524 Compose *compose = (Compose *)data;
6525 if (compose->sending)
6527 compose_close_cb(compose, 0, NULL);
6531 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6533 Compose *compose = (Compose *)data;
6536 if (compose->exteditor_tag != -1) {
6537 if (!compose_ext_editor_kill(compose))
6541 if (compose->modified) {
6542 val = alertpanel(_("Discard message"),
6543 _("This message has been modified. discard it?"),
6544 _("Discard"), _("to Draft"), _("Cancel"));
6547 case G_ALERTDEFAULT:
6548 if (prefs_common.autosave)
6549 compose_remove_draft(compose);
6551 case G_ALERTALTERNATE:
6552 compose_draft_cb(data, 0, NULL);
6559 gtk_widget_destroy(compose->window);
6562 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6564 Compose *compose = (Compose *)data;
6566 addressbook_open(compose);
6569 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6571 Compose *compose = (Compose *)data;
6576 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6577 g_return_if_fail(tmpl != NULL);
6579 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6581 val = alertpanel(_("Apply template"), msg,
6582 _("Replace"), _("Insert"), _("Cancel"));
6585 if (val == G_ALERTDEFAULT)
6586 compose_template_apply(compose, tmpl, TRUE);
6587 else if (val == G_ALERTALTERNATE)
6588 compose_template_apply(compose, tmpl, FALSE);
6591 static void compose_ext_editor_cb(gpointer data, guint action,
6594 Compose *compose = (Compose *)data;
6596 compose_exec_ext_editor(compose);
6599 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6601 if (compose->sending)
6603 compose_destroy(compose);
6606 static void compose_undo_cb(Compose *compose)
6608 undo_undo(compose->undostruct);
6611 static void compose_redo_cb(Compose *compose)
6613 undo_redo(compose->undostruct);
6616 static void compose_cut_cb(Compose *compose)
6618 if (compose->focused_editable &&
6619 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6620 gtk_editable_cut_clipboard
6621 (GTK_EDITABLE(compose->focused_editable));
6624 static void compose_copy_cb(Compose *compose)
6626 if (compose->focused_editable &&
6627 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6628 gtk_editable_copy_clipboard
6629 (GTK_EDITABLE(compose->focused_editable));
6632 static void compose_paste_cb(Compose *compose)
6634 if (compose->focused_editable &&
6635 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6636 gtk_editable_paste_clipboard
6637 (GTK_EDITABLE(compose->focused_editable));
6640 static void compose_paste_as_quote_cb(Compose *compose)
6642 if (compose->focused_editable &&
6643 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6644 /* let text_insert() (called directly or at a later time
6645 * after the gtk_editable_paste_clipboard) know that
6646 * text is to be inserted as a quotation. implemented
6647 * by using a simple refcount... */
6648 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data(
6649 GTK_OBJECT(compose->focused_editable),
6650 "paste_as_quotation"));
6651 gtk_object_set_data(GTK_OBJECT(compose->focused_editable),
6652 "paste_as_quotation",
6653 GINT_TO_POINTER(paste_as_quotation + 1));
6654 gtk_editable_paste_clipboard
6655 (GTK_EDITABLE(compose->focused_editable));
6659 static void compose_allsel_cb(Compose *compose)
6661 if (compose->focused_editable &&
6662 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6663 gtk_editable_select_region
6664 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6667 static void compose_gtk_stext_action_cb(Compose *compose,
6668 ComposeCallGtkSTextAction action)
6670 GtkSText *text = GTK_STEXT(compose->text);
6672 void (*do_action) (GtkSText *text);
6673 } action_table[] = {
6674 {gtk_stext_move_beginning_of_line},
6675 {gtk_stext_move_forward_character},
6676 {gtk_stext_move_backward_character},
6677 {gtk_stext_move_forward_word},
6678 {gtk_stext_move_backward_word},
6679 {gtk_stext_move_end_of_line},
6680 {gtk_stext_move_next_line},
6681 {gtk_stext_move_previous_line},
6682 {gtk_stext_delete_forward_character},
6683 {gtk_stext_delete_backward_character},
6684 {gtk_stext_delete_forward_word},
6685 {gtk_stext_delete_backward_word},
6686 {gtk_stext_delete_line},
6687 {gtk_stext_delete_line}, /* gtk_stext_delete_line_n */
6688 {gtk_stext_delete_to_line_end}
6691 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
6693 if (action >= COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE &&
6694 action <= COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END)
6695 action_table[action].do_action(text);
6698 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6700 if (GTK_IS_EDITABLE(widget))
6701 compose->focused_editable = widget;
6704 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6706 if (compose->modified == FALSE) {
6707 compose->modified = TRUE;
6708 compose_set_title(compose);
6712 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6715 gtk_stext_set_point(GTK_STEXT(widget),
6716 gtk_editable_get_position(GTK_EDITABLE(widget)));
6720 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6723 gtk_stext_set_point(GTK_STEXT(widget),
6724 gtk_editable_get_position(GTK_EDITABLE(widget)));
6728 #if 0 /* NEW COMPOSE GUI */
6729 static void compose_toggle_to_cb(gpointer data, guint action,
6732 Compose *compose = (Compose *)data;
6734 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6735 gtk_widget_show(compose->to_hbox);
6736 gtk_widget_show(compose->to_entry);
6737 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6738 compose->use_to = TRUE;
6740 gtk_widget_hide(compose->to_hbox);
6741 gtk_widget_hide(compose->to_entry);
6742 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6743 gtk_widget_queue_resize(compose->table_vbox);
6744 compose->use_to = FALSE;
6747 if (addressbook_get_target_compose() == compose)
6748 addressbook_set_target_compose(compose);
6751 static void compose_toggle_cc_cb(gpointer data, guint action,
6754 Compose *compose = (Compose *)data;
6756 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6757 gtk_widget_show(compose->cc_hbox);
6758 gtk_widget_show(compose->cc_entry);
6759 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6760 compose->use_cc = TRUE;
6762 gtk_widget_hide(compose->cc_hbox);
6763 gtk_widget_hide(compose->cc_entry);
6764 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6765 gtk_widget_queue_resize(compose->table_vbox);
6766 compose->use_cc = FALSE;
6769 if (addressbook_get_target_compose() == compose)
6770 addressbook_set_target_compose(compose);
6773 static void compose_toggle_bcc_cb(gpointer data, guint action,
6776 Compose *compose = (Compose *)data;
6778 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6779 gtk_widget_show(compose->bcc_hbox);
6780 gtk_widget_show(compose->bcc_entry);
6781 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6782 compose->use_bcc = TRUE;
6784 gtk_widget_hide(compose->bcc_hbox);
6785 gtk_widget_hide(compose->bcc_entry);
6786 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6787 gtk_widget_queue_resize(compose->table_vbox);
6788 compose->use_bcc = FALSE;
6791 if (addressbook_get_target_compose() == compose)
6792 addressbook_set_target_compose(compose);
6795 static void compose_toggle_replyto_cb(gpointer data, guint action,
6798 Compose *compose = (Compose *)data;
6800 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6801 gtk_widget_show(compose->reply_hbox);
6802 gtk_widget_show(compose->reply_entry);
6803 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6804 compose->use_replyto = TRUE;
6806 gtk_widget_hide(compose->reply_hbox);
6807 gtk_widget_hide(compose->reply_entry);
6808 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6809 gtk_widget_queue_resize(compose->table_vbox);
6810 compose->use_replyto = FALSE;
6814 static void compose_toggle_followupto_cb(gpointer data, guint action,
6817 Compose *compose = (Compose *)data;
6819 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6820 gtk_widget_show(compose->followup_hbox);
6821 gtk_widget_show(compose->followup_entry);
6822 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6823 compose->use_followupto = TRUE;
6825 gtk_widget_hide(compose->followup_hbox);
6826 gtk_widget_hide(compose->followup_entry);
6827 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6828 gtk_widget_queue_resize(compose->table_vbox);
6829 compose->use_followupto = FALSE;
6833 static void compose_toggle_attach_cb(gpointer data, guint action,
6836 Compose *compose = (Compose *)data;
6838 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6839 gtk_widget_ref(compose->edit_vbox);
6841 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6842 compose->edit_vbox);
6843 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6844 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6846 gtk_widget_show(compose->paned);
6848 gtk_widget_unref(compose->edit_vbox);
6849 gtk_widget_unref(compose->paned);
6851 compose->use_attach = TRUE;
6853 gtk_widget_ref(compose->paned);
6854 gtk_widget_ref(compose->edit_vbox);
6856 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6858 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6859 compose->edit_vbox);
6860 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6861 compose->edit_vbox, TRUE, TRUE, 0);
6863 gtk_widget_unref(compose->edit_vbox);
6865 compose->use_attach = FALSE;
6871 static void compose_toggle_sign_cb(gpointer data, guint action,
6874 Compose *compose = (Compose *)data;
6876 if (GTK_CHECK_MENU_ITEM(widget)->active)
6877 compose->use_signing = TRUE;
6879 compose->use_signing = FALSE;
6881 compose_update_gnupg_mode_menu_item(compose);
6884 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6887 Compose *compose = (Compose *)data;
6889 if (GTK_CHECK_MENU_ITEM(widget)->active)
6890 compose->use_encryption = TRUE;
6892 compose->use_encryption = FALSE;
6894 compose_update_gnupg_mode_menu_item(compose);
6897 static void activate_gnupg_mode (Compose *compose, PrefsAccount *account)
6899 if (account->default_gnupg_mode)
6900 compose->gnupg_mode = GNUPG_MODE_INLINE;
6902 compose->gnupg_mode = GNUPG_MODE_DETACH;
6904 compose_update_gnupg_mode_menu_item(compose);
6906 #endif /* USE_GPGME */
6908 static void compose_toggle_ruler_cb(gpointer data, guint action,
6911 Compose *compose = (Compose *)data;
6913 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6914 gtk_widget_show(compose->ruler_hbox);
6915 prefs_common.show_ruler = TRUE;
6917 gtk_widget_hide(compose->ruler_hbox);
6918 gtk_widget_queue_resize(compose->edit_vbox);
6919 prefs_common.show_ruler = FALSE;
6923 static void compose_attach_drag_received_cb (GtkWidget *widget,
6924 GdkDragContext *drag_context,
6927 GtkSelectionData *data,
6932 Compose *compose = (Compose *)user_data;
6935 list = uri_list_extract_filenames((const gchar *)data->data);
6936 for (tmp = list; tmp != NULL; tmp = tmp->next)
6937 compose_attach_append
6938 (compose, (const gchar *)tmp->data,
6939 (const gchar *)tmp->data, NULL);
6940 if (list) compose_changed_cb(NULL, compose);
6941 list_free_strings(list);
6945 static void compose_insert_drag_received_cb (GtkWidget *widget,
6946 GdkDragContext *drag_context,
6949 GtkSelectionData *data,
6954 Compose *compose = (Compose *)user_data;
6957 list = uri_list_extract_filenames((const gchar *)data->data);
6958 for (tmp = list; tmp != NULL; tmp = tmp->next)
6959 compose_insert_file(compose, (const gchar *)tmp->data);
6960 list_free_strings(list);
6964 #if 0 /* NEW COMPOSE GUI */
6965 static void to_activated(GtkWidget *widget, Compose *compose)
6967 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6968 gtk_widget_grab_focus(compose->newsgroups_entry);
6970 gtk_widget_grab_focus(compose->subject_entry);
6973 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6975 gtk_widget_grab_focus(compose->subject_entry);
6978 static void subject_activated(GtkWidget *widget, Compose *compose)
6980 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6981 gtk_widget_grab_focus(compose->cc_entry);
6982 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6983 gtk_widget_grab_focus(compose->bcc_entry);
6984 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6985 gtk_widget_grab_focus(compose->reply_entry);
6986 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6987 gtk_widget_grab_focus(compose->followup_entry);
6989 gtk_widget_grab_focus(compose->text);
6992 static void cc_activated(GtkWidget *widget, Compose *compose)
6994 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6995 gtk_widget_grab_focus(compose->bcc_entry);
6996 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6997 gtk_widget_grab_focus(compose->reply_entry);
6998 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6999 gtk_widget_grab_focus(compose->followup_entry);
7001 gtk_widget_grab_focus(compose->text);
7004 static void bcc_activated(GtkWidget *widget, Compose *compose)
7006 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
7007 gtk_widget_grab_focus(compose->reply_entry);
7008 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
7009 gtk_widget_grab_focus(compose->followup_entry);
7011 gtk_widget_grab_focus(compose->text);
7014 static void replyto_activated(GtkWidget *widget, Compose *compose)
7016 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
7017 gtk_widget_grab_focus(compose->followup_entry);
7019 gtk_widget_grab_focus(compose->text);
7022 static void followupto_activated(GtkWidget *widget, Compose *compose)
7024 gtk_widget_grab_focus(compose->text);
7028 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
7031 Compose *compose = (Compose *)data;
7033 if (GTK_CHECK_MENU_ITEM(widget)->active)
7034 compose->return_receipt = TRUE;
7036 compose->return_receipt = FALSE;
7039 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
7042 Compose *compose = (Compose *)data;
7044 if (GTK_CHECK_MENU_ITEM(widget)->active)
7045 compose->remove_references = TRUE;
7047 compose->remove_references = FALSE;
7050 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
7052 ComposeHeaderEntry *headerentry)
7054 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
7055 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
7056 !(event->state & GDK_MODIFIER_MASK) &&
7057 (event->keyval == GDK_BackSpace) &&
7058 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
7059 gtk_container_remove
7060 (GTK_CONTAINER(headerentry->compose->header_table),
7061 headerentry->combo);
7062 gtk_container_remove
7063 (GTK_CONTAINER(headerentry->compose->header_table),
7064 headerentry->entry);
7065 headerentry->compose->header_list =
7066 g_slist_remove(headerentry->compose->header_list,
7068 g_free(headerentry);
7069 } else if (event->keyval == GDK_Tab) {
7070 if (headerentry->compose->header_last == headerentry) {
7071 /* Override default next focus, and give it to subject_entry
7072 * instead of notebook tabs
7074 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
7075 gtk_widget_grab_focus(headerentry->compose->subject_entry);
7081 void compose_headerentry_changed_cb(GtkWidget *entry,
7082 ComposeHeaderEntry *headerentry)
7084 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
7085 headerentry->compose->header_list =
7086 g_slist_append(headerentry->compose->header_list,
7088 compose_create_header_entry(headerentry->compose);
7089 gtk_signal_disconnect_by_func
7091 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
7093 /* Automatically scroll down */
7094 compose_show_first_last_header(headerentry->compose, FALSE);
7099 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
7101 GtkAdjustment *vadj;
7103 g_return_if_fail(compose);
7104 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
7105 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
7107 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
7108 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
7111 static void text_activated(GtkWidget *widget, Compose *compose)
7113 compose_send_control_enter(compose);
7116 static void text_inserted(GtkWidget *widget, const gchar *text,
7117 gint length, gint *position, Compose *compose)
7119 GtkEditable *editable = GTK_EDITABLE(widget);
7120 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data
7121 (GTK_OBJECT(widget), "paste_as_quotation"));
7123 gtk_signal_handler_block_by_func(GTK_OBJECT(widget),
7124 GTK_SIGNAL_FUNC(text_inserted),
7126 if (paste_as_quotation) {
7131 new_text = g_strndup(text, length);
7132 if (prefs_common.quotemark && *prefs_common.quotemark)
7133 qmark = prefs_common.quotemark;
7136 gtk_stext_set_point(GTK_STEXT(widget), *position);
7137 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
7138 pos = gtk_stext_get_point(GTK_STEXT(widget));
7139 gtk_editable_set_position(editable, pos);
7142 gtk_object_set_data(GTK_OBJECT(widget), "paste_as_quotation",
7143 GINT_TO_POINTER(paste_as_quotation - 1));
7145 gtk_editable_insert_text(editable, text, length, position);
7147 if (prefs_common.autowrap)
7148 compose_wrap_line_all_full(compose, TRUE);
7150 gtk_signal_handler_unblock_by_func(GTK_OBJECT(widget),
7151 GTK_SIGNAL_FUNC(text_inserted),
7153 gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
7155 if (prefs_common.autosave &&
7156 gtk_stext_get_length(GTK_STEXT(widget)) % prefs_common.autosave_length == 0)
7157 gtk_timeout_add(500, (GtkFunction) compose_defer_auto_save_draft, compose);
7160 static gint compose_defer_auto_save_draft(Compose *compose)
7162 compose_draft_cb((gpointer)compose, 2, NULL);
7166 static gboolean compose_send_control_enter(Compose *compose)
7170 GtkItemFactory *ifactory;
7171 GtkAccelEntry *accel;
7172 GtkWidget *send_menu;
7174 GdkModifierType ignored_mods =
7175 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
7176 GDK_MOD4_MASK | GDK_MOD5_MASK);
7178 ev = gtk_get_current_event();
7179 if (ev->type != GDK_KEY_PRESS) return FALSE;
7181 kev = (GdkEventKey *)ev;
7182 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
7185 ifactory = gtk_item_factory_from_widget(compose->menubar);
7186 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
7187 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
7191 accel = (GtkAccelEntry *)list->data;
7192 if (accel && accel->accelerator_key == kev->keyval &&
7193 (accel->accelerator_mods & ~ignored_mods) ==
7194 (kev->state & ~ignored_mods)) {
7195 compose_send_cb(compose, 0, NULL);
7203 static void compose_check_all(Compose *compose)
7205 if (compose->gtkaspell)
7206 gtkaspell_check_all(compose->gtkaspell);
7209 static void compose_highlight_all(Compose *compose)
7211 if (compose->gtkaspell)
7212 gtkaspell_highlight_all(compose->gtkaspell);
7215 static void compose_check_backwards(Compose *compose)
7217 if (compose->gtkaspell)
7218 gtkaspell_check_backwards(compose->gtkaspell);
7220 GtkItemFactory *ifactory;
7221 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7222 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7223 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
7227 static void compose_check_forwards_go(Compose *compose)
7229 if (compose->gtkaspell)
7230 gtkaspell_check_forwards_go(compose->gtkaspell);
7232 GtkItemFactory *ifactory;
7233 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
7234 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
7235 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);