2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2004 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"
119 #define N_ATTACH_COLS 3
123 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
124 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
125 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
126 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
127 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
128 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
129 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
130 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
131 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
132 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
133 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
134 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
135 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
136 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
137 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
138 } ComposeCallGtkSTextAction;
142 PRIORITY_HIGHEST = 1,
151 COMPOSE_INSERT_SUCCESS,
152 COMPOSE_INSERT_READ_ERROR,
153 COMPOSE_INSERT_INVALID_CHARACTER,
154 COMPOSE_INSERT_NO_FILE
155 } ComposeInsertResult;
159 COMPOSE_QUIT_EDITING,
160 COMPOSE_KEEP_EDITING,
162 } ComposeDraftAction;
166 COMPOSE_WRITE_FOR_SEND,
167 COMPOSE_WRITE_FOR_STORE
171 #define B64_LINE_SIZE 57
172 #define B64_BUFFSIZE 77
174 #define MAX_REFERENCES_LEN 999
176 static GdkColor quote_color = {0, 0, 0, 0xbfff};
178 static GList *compose_list = NULL;
180 Compose *compose_generic_new (PrefsAccount *account,
183 GPtrArray *attach_files,
184 GList *listAddress );
186 static Compose *compose_create (PrefsAccount *account,
189 static GtkWidget *compose_account_option_menu_create
191 static void compose_set_template_menu (Compose *compose);
192 static void compose_template_apply (Compose *compose,
195 static void compose_destroy (Compose *compose);
197 static void compose_entries_set (Compose *compose,
198 const gchar *mailto);
199 static gint compose_parse_header (Compose *compose,
201 static gchar *compose_parse_references (const gchar *ref,
204 static gchar *compose_quote_fmt (Compose *compose,
210 static void compose_reply_set_entry (Compose *compose,
216 followup_and_reply_to);
217 static void compose_reedit_set_entry (Compose *compose,
219 static void compose_insert_sig (Compose *compose,
221 static gchar *compose_get_signature_str (Compose *compose);
222 static ComposeInsertResult compose_insert_file (Compose *compose,
224 static void compose_attach_append (Compose *compose,
227 const gchar *content_type);
228 static void compose_attach_parts (Compose *compose,
230 static void compose_wrap_line (Compose *compose);
231 static void compose_wrap_line_all (Compose *compose);
232 static void compose_wrap_line_all_full (Compose *compose,
234 static void compose_set_title (Compose *compose);
235 static void compose_select_account (Compose *compose,
236 PrefsAccount *account,
239 static PrefsAccount *compose_current_mail_account(void);
240 /* static gint compose_send (Compose *compose); */
241 static gboolean compose_check_for_valid_recipient
243 static gboolean compose_check_entries (Compose *compose,
244 gboolean check_subject);
245 static gint compose_write_to_file (Compose *compose,
248 static gint compose_write_body_to_file (Compose *compose,
250 static gint compose_remove_reedit_target (Compose *compose);
251 void compose_remove_draft (Compose *compose);
252 static gint compose_queue (Compose *compose,
255 static gint compose_queue_sub (Compose *compose,
258 gboolean check_subject);
259 static void compose_add_attachments (Compose *compose,
261 static gchar *compose_get_header (Compose *compose);
263 static void compose_convert_header (gchar *dest,
267 gboolean addr_field);
269 static void compose_attach_info_free (AttachInfo *ainfo);
270 static void compose_attach_remove_selected (Compose *compose);
272 static void compose_attach_property (Compose *compose);
273 static void compose_attach_property_create (gboolean *cancelled);
274 static void attach_property_ok (GtkWidget *widget,
275 gboolean *cancelled);
276 static void attach_property_cancel (GtkWidget *widget,
277 gboolean *cancelled);
278 static gint attach_property_delete_event (GtkWidget *widget,
280 gboolean *cancelled);
281 static void attach_property_key_pressed (GtkWidget *widget,
283 gboolean *cancelled);
285 static void compose_exec_ext_editor (Compose *compose);
286 static gint compose_exec_ext_editor_real (const gchar *file);
287 static gboolean compose_ext_editor_kill (Compose *compose);
288 static void compose_input_cb (gpointer data,
290 GdkInputCondition condition);
291 static void compose_set_ext_editor_sensitive (Compose *compose,
294 static void compose_undo_state_changed (UndoMain *undostruct,
299 static gint calc_cursor_xpos (GtkSText *text,
303 static void compose_create_header_entry (Compose *compose);
304 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
305 static void compose_update_priority_menu_item(Compose * compose);
307 static void compose_add_field_list ( Compose *compose,
308 GList *listAddress );
310 /* callback functions */
312 static gboolean compose_edit_size_alloc (GtkEditable *widget,
313 GtkAllocation *allocation,
314 GtkSHRuler *shruler);
315 static void account_activated (GtkMenuItem *menuitem,
317 static void attach_selected (GtkCList *clist,
322 static void attach_button_pressed (GtkWidget *widget,
323 GdkEventButton *event,
325 static void attach_key_pressed (GtkWidget *widget,
329 static void compose_send_cb (gpointer data,
332 static void compose_send_later_cb (gpointer data,
336 static void compose_draft_cb (gpointer data,
340 static void compose_attach_cb (gpointer data,
343 static void compose_insert_file_cb (gpointer data,
346 static void compose_insert_sig_cb (gpointer data,
350 static void compose_close_cb (gpointer data,
354 static void compose_address_cb (gpointer data,
357 static void compose_template_activate_cb(GtkWidget *widget,
360 static void compose_ext_editor_cb (gpointer data,
364 static gint compose_delete_cb (GtkWidget *widget,
367 static void compose_destroy_cb (GtkWidget *widget,
370 static void compose_undo_cb (Compose *compose);
371 static void compose_redo_cb (Compose *compose);
372 static void compose_cut_cb (Compose *compose);
373 static void compose_copy_cb (Compose *compose);
374 static void compose_paste_cb (Compose *compose);
375 static void compose_paste_as_quote_cb (Compose *compose);
376 static void compose_allsel_cb (Compose *compose);
378 static void compose_gtk_stext_action_cb (Compose *compose,
379 ComposeCallGtkSTextAction action);
381 static void compose_grab_focus_cb (GtkWidget *widget,
384 static void compose_changed_cb (GtkEditable *editable,
386 static void compose_button_press_cb (GtkWidget *widget,
387 GdkEventButton *event,
390 static void compose_key_press_cb (GtkWidget *widget,
395 static void compose_toggle_autowrap_cb (gpointer data,
400 static void compose_toggle_to_cb (gpointer data,
403 static void compose_toggle_cc_cb (gpointer data,
406 static void compose_toggle_bcc_cb (gpointer data,
409 static void compose_toggle_replyto_cb (gpointer data,
412 static void compose_toggle_followupto_cb(gpointer data,
415 static void compose_toggle_attach_cb (gpointer data,
419 static void compose_toggle_ruler_cb (gpointer data,
422 static void compose_toggle_sign_cb (gpointer data,
425 static void compose_toggle_encrypt_cb (gpointer data,
428 static void compose_set_privacy_system_cb(gpointer data,
431 static void compose_update_privacy_system_menu_item(Compose * compose);
432 static void activate_privacy_system (Compose *compose,
433 PrefsAccount *account);
434 static void compose_use_signing(Compose *compose, gboolean use_signing);
435 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
436 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
438 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
440 static void compose_set_priority_cb (gpointer data,
444 static void compose_attach_drag_received_cb (GtkWidget *widget,
445 GdkDragContext *drag_context,
448 GtkSelectionData *data,
452 static void compose_insert_drag_received_cb (GtkWidget *widget,
453 GdkDragContext *drag_context,
456 GtkSelectionData *data,
462 static void to_activated (GtkWidget *widget,
464 static void newsgroups_activated (GtkWidget *widget,
466 static void cc_activated (GtkWidget *widget,
468 static void bcc_activated (GtkWidget *widget,
470 static void replyto_activated (GtkWidget *widget,
472 static void followupto_activated (GtkWidget *widget,
474 static void subject_activated (GtkWidget *widget,
478 static void text_activated (GtkWidget *widget,
480 static void text_inserted (GtkWidget *widget,
485 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
486 gboolean to_all, gboolean to_ml,
488 gboolean followup_and_reply_to,
491 void compose_headerentry_changed_cb (GtkWidget *entry,
492 ComposeHeaderEntry *headerentry);
493 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
495 ComposeHeaderEntry *headerentry);
496 static gboolean compose_headerentry_button_pressed (GtkWidget *entry,
497 GdkEventButton *event,
500 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
502 static void compose_allow_user_actions (Compose *compose, gboolean allow);
505 static void compose_check_all (Compose *compose);
506 static void compose_highlight_all (Compose *compose);
507 static void compose_check_backwards (Compose *compose);
508 static void compose_check_forwards_go (Compose *compose);
511 static gboolean compose_send_control_enter (Compose *compose);
512 static gint compose_defer_auto_save_draft (Compose *compose);
513 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
515 static GtkItemFactoryEntry compose_popup_entries[] =
517 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
518 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
519 {N_("/---"), NULL, NULL, 0, "<Separator>"},
520 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
523 static GtkItemFactoryEntry compose_entries[] =
525 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
526 {N_("/_Message/_Send"), "<control>Return",
527 compose_send_cb, 0, NULL},
528 {N_("/_Message/Send _later"), "<shift><control>S",
529 compose_send_later_cb, 0, NULL},
530 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
531 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
532 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
533 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
534 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
535 {N_("/_Message/_Save"),
536 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
537 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
538 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
540 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
541 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
542 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
543 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
544 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
545 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
546 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
547 {N_("/_Edit/Paste as _quotation"),
548 NULL, compose_paste_as_quote_cb, 0, NULL},
549 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
550 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
551 {N_("/_Edit/A_dvanced/Move a character backward"),
553 compose_gtk_stext_action_cb,
554 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
556 {N_("/_Edit/A_dvanced/Move a character forward"),
558 compose_gtk_stext_action_cb,
559 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
561 {N_("/_Edit/A_dvanced/Move a word backward"),
563 compose_gtk_stext_action_cb,
564 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
566 {N_("/_Edit/A_dvanced/Move a word forward"),
568 compose_gtk_stext_action_cb,
569 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
571 {N_("/_Edit/A_dvanced/Move to beginning of line"),
572 NULL, /* "<control>A" */
573 compose_gtk_stext_action_cb,
574 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
576 {N_("/_Edit/A_dvanced/Move to end of line"),
578 compose_gtk_stext_action_cb,
579 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
581 {N_("/_Edit/A_dvanced/Move to previous line"),
583 compose_gtk_stext_action_cb,
584 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
586 {N_("/_Edit/A_dvanced/Move to next line"),
588 compose_gtk_stext_action_cb,
589 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
591 {N_("/_Edit/A_dvanced/Delete a character backward"),
593 compose_gtk_stext_action_cb,
594 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
596 {N_("/_Edit/A_dvanced/Delete a character forward"),
598 compose_gtk_stext_action_cb,
599 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
601 {N_("/_Edit/A_dvanced/Delete a word backward"),
602 NULL, /* "<control>W" */
603 compose_gtk_stext_action_cb,
604 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
606 {N_("/_Edit/A_dvanced/Delete a word forward"),
607 NULL, /* "<alt>D", */
608 compose_gtk_stext_action_cb,
609 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
611 {N_("/_Edit/A_dvanced/Delete line"),
613 compose_gtk_stext_action_cb,
614 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
616 {N_("/_Edit/A_dvanced/Delete entire line"),
618 compose_gtk_stext_action_cb,
619 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
621 {N_("/_Edit/A_dvanced/Delete to end of line"),
623 compose_gtk_stext_action_cb,
624 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
626 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
627 {N_("/_Edit/_Wrap current paragraph"),
628 "<control>L", compose_wrap_line, 0, NULL},
629 {N_("/_Edit/Wrap all long _lines"),
630 "<control><alt>L", compose_wrap_line_all, 0, NULL},
631 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
632 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
633 {N_("/_Edit/Edit with e_xternal editor"),
634 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
636 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
637 {N_("/_Spelling/_Check all or check selection"),
638 NULL, compose_check_all, 0, NULL},
639 {N_("/_Spelling/_Highlight all misspelled words"),
640 NULL, compose_highlight_all, 0, NULL},
641 {N_("/_Spelling/Check _backwards misspelled word"),
642 NULL, compose_check_backwards , 0, NULL},
643 {N_("/_Spelling/_Forward to next misspelled word"),
644 NULL, compose_check_forwards_go, 0, NULL},
645 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
646 {N_("/_Spelling/_Spelling Configuration"),
647 NULL, NULL, 0, "<Branch>"},
649 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
650 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
651 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
652 {N_("/_Options/Privacy System/None"), NULL, compose_set_privacy_system_cb, 0, "<RadioItem>"},
653 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
654 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
655 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
656 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
657 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
658 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
659 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
660 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
661 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
662 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
663 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
664 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
665 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
666 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
667 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
668 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
669 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
670 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
671 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
674 static GtkTargetEntry compose_mime_types[] =
676 {"text/uri-list", 0, 0}
679 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
680 GPtrArray *attach_files)
682 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
685 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
687 return compose_generic_new(account, NULL, item, NULL, NULL);
690 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
692 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
695 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
696 GPtrArray *attach_files, GList *listAddress )
700 GtkItemFactory *ifactory;
702 if (item && item->prefs && item->prefs->enable_default_account)
703 account = account_find_from_id(item->prefs->default_account);
705 if (!account) account = cur_account;
706 g_return_val_if_fail(account != NULL, NULL);
708 compose = compose_create(account, COMPOSE_NEW);
709 ifactory = gtk_item_factory_from_widget(compose->menubar);
711 compose->replyinfo = NULL;
712 compose->fwdinfo = NULL;
714 text = GTK_STEXT(compose->text);
715 gtk_stext_freeze(text);
718 if (item && item->prefs && item->prefs->enable_default_dictionary &&
720 gtkaspell_change_dict(compose->gtkaspell,
721 item->prefs->default_dictionary);
724 if (account->auto_sig)
725 compose_insert_sig(compose, FALSE);
726 gtk_editable_set_position(GTK_EDITABLE(text), 0);
727 gtk_stext_set_point(text, 0);
729 gtk_stext_thaw(text);
731 if (account->protocol != A_NNTP) {
732 if (mailto && *mailto != '\0') {
733 compose_entries_set(compose, mailto);
735 } else if (item && item->prefs->enable_default_to) {
736 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
737 compose_entry_mark_default_to(compose, item->prefs->default_to);
739 if (item && item->ret_rcpt) {
740 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
744 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
747 * CLAWS: just don't allow return receipt request, even if the user
748 * may want to send an email. simple but foolproof.
750 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
752 compose_add_field_list( compose, listAddress );
758 for (i = 0; i < attach_files->len; i++) {
759 file = g_ptr_array_index(attach_files, i);
760 compose_attach_append(compose, file, file, NULL);
764 compose_show_first_last_header(compose, TRUE);
766 /* Set save folder */
767 if (item && item->prefs && item->prefs->save_copy_to_folder) {
768 gchar *folderidentifier;
770 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
771 folderidentifier = folder_item_get_identifier(item);
772 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
773 g_free(folderidentifier);
776 gtk_widget_grab_focus(compose->header_last->entry);
778 if (prefs_common.auto_exteditor)
779 compose_exec_ext_editor(compose);
785 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
786 const gchar *followupto, gchar * to)
790 if (!account) account = cur_account;
791 g_return_val_if_fail(account != NULL, NULL);
792 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
794 compose = compose_create(account, COMPOSE_NEW);
796 if (prefs_common.auto_sig)
797 compose_insert_sig(compose);
798 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
799 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
801 compose_entry_append(compose, to, COMPOSE_TO);
802 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
803 gtk_widget_grab_focus(compose->subject_entry);
809 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
814 g_return_if_fail(msginfo_list != NULL);
816 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
817 g_return_if_fail(msginfo != NULL);
819 list_len = g_slist_length(msginfo_list);
823 compose_reply(msginfo, prefs_common.reply_with_quote,
824 FALSE, prefs_common.default_reply_list, FALSE, body);
826 case COMPOSE_REPLY_WITH_QUOTE:
827 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
829 case COMPOSE_REPLY_WITHOUT_QUOTE:
830 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
832 case COMPOSE_REPLY_TO_SENDER:
833 compose_reply(msginfo, prefs_common.reply_with_quote,
834 FALSE, FALSE, TRUE, body);
836 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
837 compose_followup_and_reply_to(msginfo,
838 prefs_common.reply_with_quote,
841 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
842 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
844 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
845 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
847 case COMPOSE_REPLY_TO_ALL:
848 compose_reply(msginfo, prefs_common.reply_with_quote,
849 TRUE, FALSE, FALSE, body);
851 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
852 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
854 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
855 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
857 case COMPOSE_REPLY_TO_LIST:
858 compose_reply(msginfo, prefs_common.reply_with_quote,
859 FALSE, TRUE, FALSE, body);
861 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
862 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
864 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
865 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
867 case COMPOSE_FORWARD:
868 if (prefs_common.forward_as_attachment) {
869 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
872 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
876 case COMPOSE_FORWARD_INLINE:
877 /* check if we reply to more than one Message */
879 compose_forward(NULL, msginfo, FALSE, body, FALSE);
882 /* more messages FALL THROUGH */
883 case COMPOSE_FORWARD_AS_ATTACH:
884 compose_forward_multiple(NULL, msginfo_list);
886 case COMPOSE_REDIRECT:
887 compose_redirect(NULL, msginfo);
890 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
894 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
895 gboolean to_ml, gboolean to_sender,
898 compose_generic_reply(msginfo, quote, to_all, to_ml,
899 to_sender, FALSE, body);
902 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
907 compose_generic_reply(msginfo, quote, to_all, FALSE,
908 to_sender, TRUE, body);
911 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
912 gboolean to_all, gboolean to_ml,
914 gboolean followup_and_reply_to,
917 GtkItemFactory *ifactory;
919 PrefsAccount *account = NULL;
920 PrefsAccount *reply_account;
923 g_return_if_fail(msginfo != NULL);
924 g_return_if_fail(msginfo->folder != NULL);
926 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
928 g_return_if_fail(account != NULL);
930 if (to_sender && account->protocol == A_NNTP &&
931 !followup_and_reply_to) {
933 account_find_from_address(account->address);
935 reply_account = compose_current_mail_account();
939 reply_account = account;
941 compose = compose_create(account, COMPOSE_REPLY);
942 ifactory = gtk_item_factory_from_widget(compose->menubar);
944 menu_set_active(ifactory, "/Options/Remove references", FALSE);
945 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
947 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
948 if (!compose->replyinfo)
949 compose->replyinfo = procmsg_msginfo_copy(msginfo);
951 if (msginfo->folder && msginfo->folder->ret_rcpt)
952 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
954 /* Set save folder */
955 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
956 gchar *folderidentifier;
958 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
959 folderidentifier = folder_item_get_identifier(msginfo->folder);
960 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
961 g_free(folderidentifier);
964 if (compose_parse_header(compose, msginfo) < 0) return;
965 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
966 to_sender, followup_and_reply_to);
967 compose_show_first_last_header(compose, TRUE);
969 text = GTK_STEXT(compose->text);
970 gtk_stext_freeze(text);
973 if (msginfo->folder && msginfo->folder->prefs &&
974 msginfo->folder->prefs &&
975 msginfo->folder->prefs->enable_default_dictionary &&
977 gtkaspell_change_dict(compose->gtkaspell,
978 msginfo->folder->prefs->default_dictionary);
984 if (prefs_common.quotemark && *prefs_common.quotemark)
985 qmark = prefs_common.quotemark;
989 compose_quote_fmt(compose, compose->replyinfo,
990 prefs_common.quotefmt,
994 if (account->auto_sig)
995 compose_insert_sig(compose, FALSE);
997 /* Must thaw here, otherwise the GtkSTextEdit will become confused
998 * when positioning cursor */
999 gtk_stext_thaw(text);
1002 gtk_editable_set_position
1003 (GTK_EDITABLE(text), quote_fmt_get_cursor_pos());
1004 gtk_stext_set_point(text, quote_fmt_get_cursor_pos());
1007 if (quote && prefs_common.linewrap_quote) {
1008 gtk_stext_freeze(text);
1009 compose_wrap_line_all(compose);
1010 gtk_stext_thaw(text);
1013 gtk_widget_grab_focus(compose->text);
1015 if (prefs_common.auto_exteditor)
1016 compose_exec_ext_editor(compose);
1019 #define INSERT_FW_HEADER(var, hdr) \
1020 if (msginfo->var && *msginfo->var) { \
1021 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1022 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1023 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1026 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1027 gboolean as_attach, const gchar *body,
1028 gboolean no_extedit)
1033 g_return_val_if_fail(msginfo != NULL, NULL);
1034 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1037 !(account = compose_guess_forward_account_from_msginfo
1039 account = cur_account;
1041 compose = compose_create(account, COMPOSE_FORWARD);
1043 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1044 if (!compose->fwdinfo)
1045 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1047 if (msginfo->subject && *msginfo->subject) {
1048 gchar *buf, *buf2, *p;
1050 buf = p = g_strdup(msginfo->subject);
1051 p += subject_get_prefix_length(p);
1052 memmove(buf, p, strlen(p) + 1);
1054 buf2 = g_strdup_printf("Fw: %s", buf);
1055 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1061 text = GTK_STEXT(compose->text);
1062 gtk_stext_freeze(text);
1067 msgfile = procmsg_get_message_file_path(msginfo);
1068 if (!is_file_exist(msgfile))
1069 g_warning("%s: file not exist\n", msgfile);
1071 compose_attach_append(compose, msgfile, msgfile,
1077 MsgInfo *full_msginfo;
1079 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1081 full_msginfo = procmsg_msginfo_copy(msginfo);
1083 if (prefs_common.fw_quotemark &&
1084 *prefs_common.fw_quotemark)
1085 qmark = prefs_common.fw_quotemark;
1089 compose_quote_fmt(compose, full_msginfo,
1090 prefs_common.fw_quotefmt,
1092 compose_attach_parts(compose, msginfo);
1094 procmsg_msginfo_free(full_msginfo);
1097 if (account->auto_sig)
1098 compose_insert_sig(compose, FALSE);
1100 if (prefs_common.linewrap_quote)
1101 compose_wrap_line_all(compose);
1103 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1104 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1106 gtk_stext_thaw(text);
1107 #if 0 /* NEW COMPOSE GUI */
1108 if (account->protocol != A_NNTP)
1109 gtk_widget_grab_focus(compose->to_entry);
1111 gtk_widget_grab_focus(compose->newsgroups_entry);
1113 gtk_widget_grab_focus(compose->header_last->entry);
1115 if (!no_extedit && prefs_common.auto_exteditor)
1116 compose_exec_ext_editor(compose);
1119 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1120 gchar *folderidentifier;
1122 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1123 folderidentifier = folder_item_get_identifier(msginfo->folder);
1124 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1125 g_free(folderidentifier);
1131 #undef INSERT_FW_HEADER
1133 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1140 g_return_val_if_fail(msginfo_list != NULL, NULL);
1142 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1143 if (((MsgInfo *)msginfo->data)->folder == NULL)
1146 /* guess account from first selected message */
1148 !(account = compose_guess_forward_account_from_msginfo
1149 (msginfo_list->data)))
1150 account = cur_account;
1152 g_return_val_if_fail(account != NULL, NULL);
1154 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1155 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1156 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1159 compose = compose_create(account, COMPOSE_FORWARD);
1161 text = GTK_STEXT(compose->text);
1162 gtk_stext_freeze(text);
1164 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1165 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1166 if (!is_file_exist(msgfile))
1167 g_warning("%s: file not exist\n", msgfile);
1169 compose_attach_append(compose, msgfile, msgfile,
1174 if (account->auto_sig)
1175 compose_insert_sig(compose, FALSE);
1177 if (prefs_common.linewrap_quote)
1178 compose_wrap_line_all(compose);
1180 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1181 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1183 gtk_stext_thaw(text);
1184 gtk_widget_grab_focus(compose->header_last->entry);
1186 #if 0 /* NEW COMPOSE GUI */
1187 if (account->protocol != A_NNTP)
1188 gtk_widget_grab_focus(compose->to_entry);
1190 gtk_widget_grab_focus(compose->newsgroups_entry);
1196 void compose_reedit(MsgInfo *msginfo)
1199 PrefsAccount *account = NULL;
1202 gchar buf[BUFFSIZE];
1203 gboolean use_signing = FALSE;
1204 gboolean use_encryption = FALSE;
1205 gchar *privacy_system = NULL;
1207 g_return_if_fail(msginfo != NULL);
1208 g_return_if_fail(msginfo->folder != NULL);
1210 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1211 gchar queueheader_buf[BUFFSIZE];
1214 /* Select Account from queue headers */
1215 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1216 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1217 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1218 account = account_find_from_id(id);
1220 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1221 sizeof(queueheader_buf), "NAID:")) {
1222 id = atoi(&queueheader_buf[strlen("NAID:")]);
1223 account = account_find_from_id(id);
1225 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1226 sizeof(queueheader_buf), "MAID:")) {
1227 id = atoi(&queueheader_buf[strlen("MAID:")]);
1228 account = account_find_from_id(id);
1230 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1231 sizeof(queueheader_buf), "S:")) {
1232 account = account_find_from_address(queueheader_buf);
1234 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1235 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1236 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1237 use_signing = param;
1240 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1241 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1242 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1243 use_encryption = param;
1245 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1246 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1247 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1249 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1250 sizeof(queueheader_buf), "X-Priority: ")) {
1251 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1252 compose->priority = param;
1255 account = msginfo->folder->folder->account;
1257 if (!account && prefs_common.reedit_account_autosel) {
1258 gchar from[BUFFSIZE];
1259 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1260 extract_address(from);
1261 account = account_find_from_address(from);
1264 if (!account) account = cur_account;
1265 g_return_if_fail(account != NULL);
1267 compose = compose_create(account, COMPOSE_REEDIT);
1268 compose->privacy_system = privacy_system;
1269 compose_use_signing(compose, use_signing);
1270 compose_use_encryption(compose, use_encryption);
1271 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1273 if (msginfo->folder->stype == F_QUEUE
1274 || msginfo->folder->stype == F_DRAFT) {
1275 gchar queueheader_buf[BUFFSIZE];
1277 /* Set message save folder */
1278 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1281 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1282 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1283 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1287 if (compose_parse_header(compose, msginfo) < 0) return;
1288 compose_reedit_set_entry(compose, msginfo);
1290 text = GTK_STEXT(compose->text);
1291 gtk_stext_freeze(text);
1293 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1294 g_warning("Can't get text part\n");
1296 while (fgets(buf, sizeof(buf), fp) != NULL) {
1298 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1302 compose_attach_parts(compose, msginfo);
1304 gtk_stext_thaw(text);
1305 gtk_widget_grab_focus(compose->text);
1307 if (prefs_common.auto_exteditor)
1308 compose_exec_ext_editor(compose);
1311 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1315 GtkItemFactory *ifactory;
1318 g_return_val_if_fail(msginfo != NULL, NULL);
1321 account = account_get_reply_account(msginfo,
1322 prefs_common.reply_account_autosel);
1323 g_return_val_if_fail(account != NULL, NULL);
1325 compose = compose_create(account, COMPOSE_REDIRECT);
1326 ifactory = gtk_item_factory_from_widget(compose->menubar);
1328 compose->replyinfo = NULL;
1329 compose->fwdinfo = NULL;
1331 compose_show_first_last_header(compose, TRUE);
1333 gtk_widget_grab_focus(compose->header_last->entry);
1335 filename = procmsg_get_message_file(msginfo);
1336 if (filename == NULL)
1339 compose->redirect_filename = filename;
1341 /* Set save folder */
1342 item = msginfo->folder;
1343 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1344 gchar *folderidentifier;
1346 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1347 folderidentifier = folder_item_get_identifier(item);
1348 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1349 g_free(folderidentifier);
1352 compose_attach_parts(compose, msginfo);
1354 if (msginfo->subject)
1355 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1357 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1359 gtk_stext_freeze(GTK_STEXT(compose->text));
1360 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1361 gtk_editable_set_editable(GTK_EDITABLE(compose->text), FALSE);
1362 gtk_stext_thaw(GTK_STEXT(compose->text));
1364 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1365 menu_set_sensitive(ifactory, "/Add...", FALSE);
1366 menu_set_sensitive(ifactory, "/Remove", FALSE);
1367 menu_set_sensitive(ifactory, "/Property...", FALSE);
1369 ifactory = gtk_item_factory_from_widget(compose->menubar);
1370 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1371 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1372 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1373 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1374 menu_set_sensitive(ifactory, "/Edit", FALSE);
1375 menu_set_sensitive(ifactory, "/Options/Sign", FALSE);
1376 menu_set_sensitive(ifactory, "/Options/Encrypt", FALSE);
1377 menu_set_sensitive(ifactory, "/Options/Priority", FALSE);
1378 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
1379 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1380 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1382 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1383 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1384 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1385 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1386 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1387 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1388 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_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_mark_default_to(Compose *compose, const gchar *mailto)
1456 static GtkStyle *bold_style = NULL;
1457 static GdkColor bold_color;
1458 static GdkFont *bold_font = NULL;
1462 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1463 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1464 if (gtk_entry_get_text(entry) &&
1465 !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1466 gtk_widget_ensure_style(GTK_WIDGET(entry));
1468 gtkut_convert_int_to_gdk_color
1469 (prefs_common.color_new, &bold_color);
1470 bold_style = gtk_style_copy(gtk_widget_get_style
1471 (GTK_WIDGET(entry)));
1473 bold_font = gtkut_font_load
1474 (prefs_common.boldfont);
1476 bold_style->font = bold_font;
1477 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1479 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1484 void compose_toolbar_cb(gint action, gpointer data)
1486 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1487 Compose *compose = (Compose*)toolbar_item->parent;
1489 g_return_if_fail(compose != NULL);
1493 compose_send_cb(compose, 0, NULL);
1496 compose_send_later_cb(compose, 0, NULL);
1499 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1502 compose_insert_file_cb(compose, 0, NULL);
1505 compose_attach_cb(compose, 0, NULL);
1508 compose_insert_sig(compose, FALSE);
1511 compose_ext_editor_cb(compose, 0, NULL);
1513 case A_LINEWRAP_CURRENT:
1514 compose_wrap_line(compose);
1516 case A_LINEWRAP_ALL:
1517 compose_wrap_line_all(compose);
1520 compose_address_cb(compose, 0, NULL);
1523 case A_CHECK_SPELLING:
1524 compose_check_all(compose);
1532 static void compose_entries_set(Compose *compose, const gchar *mailto)
1537 gchar *subject = NULL;
1540 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1543 compose_entry_append(compose, to, COMPOSE_TO);
1545 compose_entry_append(compose, cc, COMPOSE_CC);
1547 compose_entry_append(compose, bcc, COMPOSE_BCC);
1549 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1551 gtk_stext_insert(GTK_STEXT(compose->text),
1552 NULL, NULL, NULL, body, -1);
1553 gtk_stext_insert(GTK_STEXT(compose->text),
1554 NULL, NULL, NULL, "\n", 1);
1564 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1566 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1567 {"Cc:", NULL, TRUE},
1568 {"References:", NULL, FALSE},
1569 {"Bcc:", NULL, TRUE},
1570 {"Newsgroups:", NULL, TRUE},
1571 {"Followup-To:", NULL, TRUE},
1572 {"List-Post:", NULL, FALSE},
1573 {"X-Priority:", NULL, FALSE},
1574 {NULL, NULL, FALSE}};
1590 g_return_val_if_fail(msginfo != NULL, -1);
1592 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1593 procheader_get_header_fields(fp, hentry);
1596 if (hentry[H_REPLY_TO].body != NULL) {
1597 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1598 compose->replyto = hentry[H_REPLY_TO].body;
1599 hentry[H_REPLY_TO].body = NULL;
1601 if (hentry[H_CC].body != NULL) {
1602 conv_unmime_header_overwrite(hentry[H_CC].body);
1603 compose->cc = hentry[H_CC].body;
1604 hentry[H_CC].body = NULL;
1606 if (hentry[H_REFERENCES].body != NULL) {
1607 if (compose->mode == COMPOSE_REEDIT)
1608 compose->references = hentry[H_REFERENCES].body;
1610 compose->references = compose_parse_references
1611 (hentry[H_REFERENCES].body, msginfo->msgid);
1612 g_free(hentry[H_REFERENCES].body);
1614 hentry[H_REFERENCES].body = NULL;
1616 if (hentry[H_BCC].body != NULL) {
1617 if (compose->mode == COMPOSE_REEDIT) {
1618 conv_unmime_header_overwrite(hentry[H_BCC].body);
1619 compose->bcc = hentry[H_BCC].body;
1621 g_free(hentry[H_BCC].body);
1622 hentry[H_BCC].body = NULL;
1624 if (hentry[H_NEWSGROUPS].body != NULL) {
1625 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1626 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1627 hentry[H_NEWSGROUPS].body = NULL;
1629 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1630 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1631 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1632 hentry[H_FOLLOWUP_TO].body = NULL;
1634 if (hentry[H_LIST_POST].body != NULL) {
1637 extract_address(hentry[H_LIST_POST].body);
1638 if (hentry[H_LIST_POST].body[0] != '\0') {
1639 scan_mailto_url(hentry[H_LIST_POST].body,
1640 &to, NULL, NULL, NULL, NULL);
1642 g_free(compose->ml_post);
1643 compose->ml_post = to;
1646 g_free(hentry[H_LIST_POST].body);
1647 hentry[H_LIST_POST].body = NULL;
1650 /* CLAWS - X-Priority */
1651 if (compose->mode == COMPOSE_REEDIT)
1652 if (hentry[H_X_PRIORITY].body != NULL) {
1655 priority = atoi(hentry[H_X_PRIORITY].body);
1656 g_free(hentry[H_X_PRIORITY].body);
1658 hentry[H_X_PRIORITY].body = NULL;
1660 if (priority < PRIORITY_HIGHEST ||
1661 priority > PRIORITY_LOWEST)
1662 priority = PRIORITY_NORMAL;
1664 compose->priority = priority;
1667 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1668 compose->inreplyto = g_strdup(msginfo->inreplyto);
1669 else if (compose->mode != COMPOSE_REEDIT &&
1670 msginfo->msgid && *msginfo->msgid) {
1671 compose->inreplyto = g_strdup(msginfo->msgid);
1673 if (!compose->references) {
1674 if (msginfo->inreplyto && *msginfo->inreplyto)
1675 compose->references =
1676 g_strdup_printf("<%s>\n\t<%s>",
1680 compose->references =
1681 g_strconcat("<", msginfo->msgid, ">",
1689 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1691 GSList *ref_id_list, *cur;
1695 ref_id_list = references_list_append(NULL, ref);
1696 if (!ref_id_list) return NULL;
1697 if (msgid && *msgid)
1698 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1703 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1704 /* "<" + Message-ID + ">" + CR+LF+TAB */
1705 len += strlen((gchar *)cur->data) + 5;
1707 if (len > MAX_REFERENCES_LEN) {
1708 /* remove second message-ID */
1709 if (ref_id_list && ref_id_list->next &&
1710 ref_id_list->next->next) {
1711 g_free(ref_id_list->next->data);
1712 ref_id_list = g_slist_remove
1713 (ref_id_list, ref_id_list->next->data);
1715 slist_free_strings(ref_id_list);
1716 g_slist_free(ref_id_list);
1723 new_ref = g_string_new("");
1724 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1725 if (new_ref->len > 0)
1726 g_string_append(new_ref, "\n\t");
1727 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1730 slist_free_strings(ref_id_list);
1731 g_slist_free(ref_id_list);
1733 new_ref_str = new_ref->str;
1734 g_string_free(new_ref, FALSE);
1739 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1740 const gchar *fmt, const gchar *qmark,
1743 GtkSText *text = GTK_STEXT(compose->text);
1744 static MsgInfo dummyinfo;
1745 gchar *quote_str = NULL;
1749 const gchar *trimmed_body = body;
1752 msginfo = &dummyinfo;
1754 if (qmark != NULL) {
1755 quote_fmt_init(msginfo, NULL, NULL);
1756 quote_fmt_scan_string(qmark);
1759 buf = quote_fmt_get_buffer();
1761 alertpanel_error(_("Quote mark format error."));
1763 Xstrdup_a(quote_str, buf, return NULL)
1766 if (fmt && *fmt != '\0') {
1767 while (trimmed_body && strlen(trimmed_body) > 1
1768 && trimmed_body[0]=='\n')
1771 quote_fmt_init(msginfo, quote_str, trimmed_body);
1772 quote_fmt_scan_string(fmt);
1775 buf = quote_fmt_get_buffer();
1777 alertpanel_error(_("Message reply/forward format error."));
1783 gtk_stext_freeze(text);
1785 for (p = buf; *p != '\0'; ) {
1786 lastp = strchr(p, '\n');
1787 len = lastp ? lastp - p + 1 : -1;
1788 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1795 gtk_stext_thaw(text);
1800 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1801 gboolean to_all, gboolean to_ml,
1803 gboolean followup_and_reply_to)
1805 GSList *cc_list = NULL;
1808 gchar *replyto = NULL;
1809 GHashTable *to_table;
1811 g_return_if_fail(compose->account != NULL);
1812 g_return_if_fail(msginfo != NULL);
1814 if (compose->account->protocol != A_NNTP) {
1815 if (!compose->replyto && to_ml && compose->ml_post
1816 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1817 compose_entry_append(compose,
1820 else if (!(to_all || to_sender)
1822 && msginfo->folder->prefs->enable_default_reply_to) {
1823 compose_entry_append(compose,
1824 msginfo->folder->prefs->default_reply_to,
1827 compose_entry_append(compose,
1828 (compose->replyto && !to_sender)
1829 ? compose->replyto :
1830 msginfo->from ? msginfo->from : "",
1833 if (to_sender || (compose->followup_to &&
1834 !strncmp(compose->followup_to, "poster", 6)))
1835 compose_entry_append
1837 (compose->replyto ? compose->replyto :
1838 msginfo->from ? msginfo->from : ""),
1841 else if (followup_and_reply_to || to_all) {
1842 compose_entry_append
1844 (compose->replyto ? compose->replyto :
1845 msginfo->from ? msginfo->from : ""),
1848 compose_entry_append
1850 compose->followup_to ? compose->followup_to :
1851 compose->newsgroups ? compose->newsgroups : "",
1852 COMPOSE_NEWSGROUPS);
1855 compose_entry_append
1857 compose->followup_to ? compose->followup_to :
1858 compose->newsgroups ? compose->newsgroups : "",
1859 COMPOSE_NEWSGROUPS);
1862 if (msginfo->subject && *msginfo->subject) {
1866 buf = p = g_strdup(msginfo->subject);
1867 p += subject_get_prefix_length(p);
1868 memmove(buf, p, strlen(p) + 1);
1870 buf2 = g_strdup_printf("Re: %s", buf);
1871 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1876 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1878 if (to_ml && compose->ml_post) return;
1879 if (!to_all || compose->account->protocol == A_NNTP) return;
1881 if (compose->replyto) {
1882 Xstrdup_a(replyto, compose->replyto, return);
1883 extract_address(replyto);
1885 if (msginfo->from) {
1886 Xstrdup_a(from, msginfo->from, return);
1887 extract_address(from);
1890 if (replyto && from)
1891 cc_list = address_list_append_with_comments(cc_list, from);
1892 if (to_all && msginfo->folder &&
1893 msginfo->folder->prefs->enable_default_reply_to)
1894 cc_list = address_list_append_with_comments(cc_list,
1895 msginfo->folder->prefs->default_reply_to);
1896 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1897 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1899 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1901 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1902 if (compose->account)
1903 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1904 GINT_TO_POINTER(1));
1906 /* remove address on To: and that of current account */
1907 for (cur = cc_list; cur != NULL; ) {
1908 GSList *next = cur->next;
1911 addr = g_strdup(cur->data);
1912 extract_address(addr);
1914 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
1915 cc_list = g_slist_remove(cc_list, cur->data);
1917 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
1921 hash_free_strings(to_table);
1922 g_hash_table_destroy(to_table);
1925 for (cur = cc_list; cur != NULL; cur = cur->next)
1926 compose_entry_append(compose, (gchar *)cur->data,
1928 slist_free_strings(cc_list);
1929 g_slist_free(cc_list);
1934 #define SET_ENTRY(entry, str) \
1937 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1940 #define SET_ADDRESS(type, str) \
1943 compose_entry_append(compose, str, type); \
1946 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1948 g_return_if_fail(msginfo != NULL);
1950 SET_ENTRY(subject_entry, msginfo->subject);
1951 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1952 SET_ADDRESS(COMPOSE_CC, compose->cc);
1953 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1954 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1955 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
1956 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
1958 compose_update_priority_menu_item(compose);
1959 compose_update_privacy_system_menu_item(compose);
1960 compose_show_first_last_header(compose, TRUE);
1966 static void compose_insert_sig(Compose *compose, gboolean replace)
1968 GtkSText *text = GTK_STEXT(compose->text);
1972 g_return_if_fail(compose->account != NULL);
1974 cur_pos = gtk_editable_get_position(GTK_EDITABLE(text));
1976 gtk_stext_freeze(text);
1979 len = gtk_stext_get_length(text);
1980 gtk_stext_set_point(text, len);
1983 if (replace && compose->sig_str) {
1986 if (compose->sig_str[0] == '\0')
1989 pos = gtkut_stext_find(text, 0, compose->sig_str, TRUE);
1992 len = get_mbs_len(compose->sig_str);
1994 gtk_stext_set_point(text, pos);
1995 gtk_stext_forward_delete(text, len);
2000 g_free(compose->sig_str);
2001 compose->sig_str = compose_get_signature_str(compose);
2002 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2003 compose->sig_str = g_strdup("");
2005 gtk_stext_insert(text, NULL, NULL, NULL, compose->sig_str, -1);
2007 gtk_stext_thaw(text);
2009 if (cur_pos > gtk_stext_get_length(text))
2010 cur_pos = gtk_stext_get_length(text);
2012 gtk_editable_set_position(GTK_EDITABLE(text), cur_pos);
2013 gtk_stext_set_point(text, cur_pos);
2016 static gchar *compose_get_signature_str(Compose *compose)
2018 gchar *sig_body = NULL;
2019 gchar *sig_str = NULL;
2021 g_return_val_if_fail(compose->account != NULL, NULL);
2023 if (!compose->account->sig_path)
2026 if (compose->account->sig_type == SIG_FILE) {
2027 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2028 g_warning("can't open signature file: %s\n",
2029 compose->account->sig_path);
2034 if (compose->account->sig_type == SIG_COMMAND)
2035 sig_body = get_command_output(compose->account->sig_path);
2039 tmp = file_read_to_str(compose->account->sig_path);
2042 sig_body = normalize_newlines(tmp);
2046 if (compose->account->sig_sep)
2047 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2050 sig_str = g_strconcat("\n\n", sig_body, NULL);
2057 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2059 GtkSText *text = GTK_STEXT(compose->text);
2060 gchar buf[BUFFSIZE];
2063 gboolean badtxt = FALSE;
2065 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2067 if ((fp = fopen(file, "rb")) == NULL) {
2068 FILE_OP_ERROR(file, "fopen");
2069 return COMPOSE_INSERT_READ_ERROR;
2072 gtk_stext_freeze(text);
2074 while (fgets(buf, sizeof(buf), fp) != NULL) {
2075 /* strip <CR> if DOS/Windows file,
2076 replace <CR> with <LF> if Macintosh file. */
2079 if (len > 0 && buf[len - 1] != '\n') {
2081 if (buf[len] == '\r') buf[len] = '\n';
2083 if (mbstowcs(NULL, buf, 0) == -1)
2085 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
2088 gtk_stext_thaw(text);
2093 return COMPOSE_INSERT_INVALID_CHARACTER;
2095 return COMPOSE_INSERT_SUCCESS;
2098 static void compose_attach_append(Compose *compose, const gchar *file,
2099 const gchar *filename,
2100 const gchar *content_type)
2103 gchar *text[N_ATTACH_COLS];
2108 if (!is_file_exist(file)) {
2109 g_warning("File %s doesn't exist\n", file);
2112 if ((size = get_file_size(file)) < 0) {
2113 g_warning("Can't get file size of %s\n", file);
2117 alertpanel_notice(_("File %s is empty."), file);
2120 if ((fp = fopen(file, "rb")) == NULL) {
2121 alertpanel_error(_("Can't read %s."), file);
2126 #if 0 /* NEW COMPOSE GUI */
2127 if (!compose->use_attach) {
2128 GtkItemFactory *ifactory;
2130 ifactory = gtk_item_factory_from_widget(compose->menubar);
2131 menu_set_active(ifactory, "/View/Attachment", TRUE);
2134 ainfo = g_new0(AttachInfo, 1);
2135 ainfo->file = g_strdup(file);
2138 ainfo->content_type = g_strdup(content_type);
2139 if (!g_strcasecmp(content_type, "message/rfc822")) {
2141 MsgFlags flags = {0, 0};
2144 if (procmime_get_encoding_for_file(file) == ENC_7BIT)
2145 ainfo->encoding = ENC_7BIT;
2147 ainfo->encoding = ENC_8BIT;
2149 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2150 if (msginfo && msginfo->subject)
2151 name = msginfo->subject;
2153 name = g_basename(filename ? filename : file);
2155 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2157 procmsg_msginfo_free(msginfo);
2159 if (!g_strncasecmp(content_type, "text", 4))
2161 procmime_get_encoding_for_file(file);
2163 ainfo->encoding = ENC_BASE64;
2164 ainfo->name = g_strdup
2165 (g_basename(filename ? filename : file));
2168 ainfo->content_type = procmime_get_mime_type(file);
2169 if (!ainfo->content_type) {
2170 ainfo->content_type =
2171 g_strdup("application/octet-stream");
2172 ainfo->encoding = ENC_BASE64;
2173 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
2174 ainfo->encoding = procmime_get_encoding_for_file(file);
2176 ainfo->encoding = ENC_BASE64;
2177 ainfo->name = g_strdup(g_basename(filename ? filename : file));
2180 if (!strcmp(ainfo->content_type, "unknown")) {
2181 g_free(ainfo->content_type);
2182 ainfo->content_type = g_strdup("application/octet-stream");
2187 text[COL_MIMETYPE] = ainfo->content_type;
2188 text[COL_SIZE] = to_human_readable(size);
2189 text[COL_NAME] = ainfo->name;
2191 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2192 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2195 static void compose_use_signing(Compose *compose, gboolean use_signing)
2197 GtkItemFactory *ifactory;
2198 GtkWidget *menuitem = NULL;
2200 compose->use_signing = use_signing;
2201 ifactory = gtk_item_factory_from_widget(compose->menubar);
2202 menuitem = gtk_item_factory_get_item
2203 (ifactory, "/Options/Sign");
2204 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2208 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2210 GtkItemFactory *ifactory;
2211 GtkWidget *menuitem = NULL;
2213 compose->use_encryption = use_encryption;
2214 ifactory = gtk_item_factory_from_widget(compose->menubar);
2215 menuitem = gtk_item_factory_get_item
2216 (ifactory, "/Options/Encrypt");
2218 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2222 #define NEXT_PART_NOT_CHILD(info) \
2224 node = info->node; \
2225 while (node->children) \
2226 node = g_node_last_child(node); \
2227 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2230 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2234 MimeInfo *firsttext = NULL;
2235 MimeInfo *encrypted = NULL;
2238 const gchar *partname = NULL;
2240 mimeinfo = procmime_scan_message(msginfo);
2241 if (!mimeinfo) return;
2243 if (mimeinfo->node->children == NULL) {
2244 procmime_mimeinfo_free_all(mimeinfo);
2248 /* find first content part */
2249 child = (MimeInfo *) mimeinfo->node->children->data;
2250 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2251 child = (MimeInfo *)child->node->children->data;
2253 if (child->type == MIMETYPE_TEXT) {
2255 debug_print("First text part found\n");
2256 } else if (compose->mode == COMPOSE_REEDIT &&
2257 child->type == MIMETYPE_APPLICATION &&
2258 !g_strcasecmp(child->subtype, "pgp-encrypted")) {
2260 val = alertpanel(_("Encrypted message"),
2261 _("Cannot re-edit an encrypted message. \n"
2262 "Discard encrypted part?"),
2263 _("Yes"), _("No"), NULL);
2264 if (val == G_ALERTDEFAULT)
2265 encrypted = (MimeInfo *)child->node->parent->data;
2268 child = (MimeInfo *) mimeinfo->node->children->data;
2269 while (child != NULL) {
2270 if (child == encrypted) {
2271 /* skip this part of tree */
2272 NEXT_PART_NOT_CHILD(child);
2276 if (child->type == MIMETYPE_MULTIPART) {
2277 /* get the actual content */
2278 child = procmime_mimeinfo_next(child);
2282 if (child == firsttext) {
2283 child = procmime_mimeinfo_next(child);
2287 outfile = procmime_get_tmp_file_name(child);
2288 if (procmime_get_part(outfile, child) < 0)
2289 g_warning("Can't get the part of multipart message.");
2291 gchar *content_type;
2293 content_type = procmime_get_content_type_str(child->type, child->subtype);
2294 partname = procmime_mimeinfo_get_parameter(child, "name");
2295 if (partname == NULL)
2297 compose_attach_append(compose, outfile,
2298 partname, content_type);
2299 g_free(content_type);
2302 NEXT_PART_NOT_CHILD(child);
2304 procmime_mimeinfo_free_all(mimeinfo);
2307 #undef NEXT_PART_NOT_CHILD
2309 #define GET_CHAR(pos, buf, len) \
2311 if (text->use_wchar) \
2312 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2314 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2319 #define DISP_WIDTH(len) \
2320 ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
2321 (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
2323 #define SPACE_CHARS " \t"
2325 static void compose_wrap_line(Compose *compose)
2327 GtkSText *text = GTK_STEXT(compose->text);
2328 gint ch_len, last_ch_len;
2329 gchar cbuf[MB_LEN_MAX], last_ch;
2333 gint p_start, p_end;
2334 gint line_pos, cur_pos;
2335 gint line_len, cur_len;
2337 gtk_stext_freeze(text);
2339 text_len = gtk_stext_get_length(text);
2341 /* check to see if the point is on the paragraph mark (empty line). */
2342 cur_pos = gtk_stext_get_point(text);
2343 GET_CHAR(cur_pos, cbuf, ch_len);
2344 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2346 goto compose_end; /* on the paragraph mark */
2347 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2348 if (ch_len == 1 && *cbuf == '\n')
2349 goto compose_end; /* on the paragraph mark */
2352 /* find paragraph start. */
2353 line_end = quoted = 0;
2354 for (p_start = cur_pos; p_start >= 0; --p_start) {
2355 GET_CHAR(p_start, cbuf, ch_len);
2356 if (ch_len == 1 && *cbuf == '\n') {
2358 goto compose_end; /* quoted part */
2366 && strchr(prefs_common.quote_chars, *cbuf))
2368 else if (ch_len != 1 || !isspace(*(guchar *)cbuf))
2377 /* find paragraph end. */
2379 for (p_end = cur_pos; p_end < text_len; p_end++) {
2380 GET_CHAR(p_end, cbuf, ch_len);
2381 if (ch_len == 1 && *cbuf == '\n') {
2388 if (line_end && ch_len == 1 &&
2389 strchr(prefs_common.quote_chars, *cbuf))
2390 goto compose_end; /* quoted part */
2395 if (p_end >= text_len)
2398 if (p_start >= p_end)
2401 line_len = cur_len = 0;
2405 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2408 GET_CHAR(cur_pos, cbuf, ch_len);
2415 if (ch_len == 1 && isspace(*(guchar *)cbuf))
2418 if (ch_len == 1 && *cbuf == '\n') {
2420 if (last_ch_len == 1 && !isspace((guchar)last_ch)) {
2421 if (cur_pos + 1 < p_end) {
2422 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2424 !isspace(*(guchar *)cbuf))
2428 gtk_stext_set_point(text, cur_pos + 1);
2429 gtk_stext_backward_delete(text, 1);
2431 gtk_stext_set_point(text, cur_pos);
2432 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2442 last_ch_len = ch_len;
2446 line_pos = cur_pos + 1;
2447 line_len = cur_len + ch_len;
2450 if (cur_len + DISP_WIDTH(ch_len) > prefs_common.linewrap_len &&
2454 GET_CHAR(line_pos - 1, cbuf, ch_len);
2455 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2456 gtk_stext_set_point(text, line_pos);
2457 gtk_stext_backward_delete(text, 1);
2466 gtk_stext_set_point(text, line_pos);
2467 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2471 cur_len = cur_len - line_len + DISP_WIDTH(ch_len);
2477 line_pos = cur_pos + 1;
2478 line_len = cur_len + DISP_WIDTH(ch_len);
2480 cur_len += DISP_WIDTH(ch_len);
2484 gtk_stext_thaw(text);
2489 /* Darko: used when I debug wrapping */
2490 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2493 gchar cbuf[MB_LEN_MAX];
2495 printf("%d [", pos);
2496 for (i = pos; i < tlen; i++) {
2497 GET_CHAR(i, cbuf, clen);
2498 if (clen < 0) break;
2499 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2501 fwrite(cbuf, clen, 1, stdout);
2509 WAIT_FOR_INDENT_CHAR,
2510 WAIT_FOR_INDENT_CHAR_OR_SPACE
2513 /* return indent length, we allow:
2514 > followed by spaces/tabs
2515 | followed by spaces/tabs
2516 uppercase characters immediately followed by >,
2517 and the repeating sequences of the above */
2518 /* return indent length */
2519 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2522 guint i, ch_len, alnum_cnt = 0;
2523 IndentState state = WAIT_FOR_INDENT_CHAR;
2524 gchar cbuf[MB_LEN_MAX];
2528 if (prefs_common.quote_chars == NULL) {
2532 for (i = start_pos; i < text_len; i++) {
2533 GET_CHAR(i, cbuf, ch_len);
2537 if (cbuf[0] == '\n')
2540 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2541 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2544 case WAIT_FOR_SPACE:
2545 if (is_space == FALSE)
2547 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2549 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2550 if (is_indent == FALSE && is_space == FALSE &&
2551 !isupper((guchar)cbuf[0]))
2553 if (is_space == TRUE) {
2555 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2556 } else if (is_indent == TRUE) {
2558 state = WAIT_FOR_SPACE;
2561 state = WAIT_FOR_INDENT_CHAR;
2564 case WAIT_FOR_INDENT_CHAR:
2565 if (is_indent == FALSE && !isupper((guchar)cbuf[0]))
2567 if (is_indent == TRUE) {
2569 && !strchr(prefs_common.quote_chars, cbuf[0]))
2572 state = WAIT_FOR_SPACE;
2583 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2589 /* insert quotation string when line was wrapped */
2590 static guint ins_quote(GtkSText *text, guint indent_len,
2591 guint prev_line_pos, guint text_len,
2594 guint i, ins_len = 0;
2598 for (i = 0; i < indent_len; i++) {
2599 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2600 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2602 ins_len = indent_len;
2608 /* check if we should join the next line */
2609 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2610 guint prev_ilen, gboolean autowrap)
2612 guint indent_len, ch_len;
2613 gboolean do_join = FALSE;
2614 gchar cbuf[MB_LEN_MAX];
2616 indent_len = get_indent_length(text, start_pos, tlen);
2618 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2619 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2620 if (ch_len > 0 && (cbuf[0] != '\n'))
2627 static void compose_wrap_line_all(Compose *compose)
2629 compose_wrap_line_all_full(compose, FALSE);
2632 #define STEXT_FREEZE() \
2633 if (!frozen) { gtk_stext_freeze(text); frozen = TRUE; }
2635 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2637 GtkSText *text = GTK_STEXT(compose->text);
2639 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2640 gint line_len = 0, cur_len = 0;
2642 gboolean is_new_line = TRUE, do_delete = FALSE;
2644 gboolean linewrap_quote = TRUE;
2645 gboolean set_editable_pos = FALSE;
2646 gint editable_pos = 0;
2647 gboolean frozen = FALSE;
2648 guint linewrap_len = prefs_common.linewrap_len;
2649 gchar *qfmt = prefs_common.quotemark;
2650 gchar cbuf[MB_LEN_MAX];
2652 tlen = gtk_stext_get_length(text);
2654 for (; cur_pos < tlen; cur_pos++) {
2655 /* mark position of new line - needed for quotation wrap */
2658 i_len = get_indent_length(text, cur_pos, tlen);
2660 is_new_line = FALSE;
2663 g_print("new line i_len=%d p_pos=", i_len);
2664 dump_text(text, p_pos, tlen, 1);
2668 GET_CHAR(cur_pos, cbuf, ch_len);
2670 /* fix line length for tabs */
2671 if (ch_len == 1 && *cbuf == '\t') {
2672 guint tab_width = text->default_tab_width;
2673 guint tab_offset = line_len % tab_width;
2676 g_print("found tab at pos=%d line_len=%d ", cur_pos,
2680 line_len += tab_width - tab_offset - 1;
2684 printf("new_len=%d\n", line_len);
2688 /* we have encountered line break */
2689 if (ch_len == 1 && *cbuf == '\n') {
2691 gchar cb[MB_LEN_MAX];
2693 /* should we join the next line */
2694 if ((autowrap || i_len != cur_len) && do_delete &&
2696 (text, cur_pos + 1, tlen, i_len, autowrap))
2702 g_print("found CR at %d do_del is %d next line is ",
2703 cur_pos, do_delete);
2704 dump_text(text, cur_pos + 1, tlen, 1);
2707 /* skip delete if it is continuous URL */
2708 if (do_delete && (line_pos - p_pos <= i_len) &&
2709 gtk_stext_is_uri_string(text, line_pos, tlen))
2713 g_print("l_len=%d wrap_len=%d do_del=%d\n",
2714 line_len, linewrap_len, do_delete);
2716 /* should we delete to perform smart wrapping */
2717 if (line_len < linewrap_len && do_delete) {
2719 /* get rid of newline */
2720 gtk_stext_set_point(text, cur_pos);
2721 gtk_stext_forward_delete(text, 1);
2724 /* if text starts with quote fmt or with
2725 indent string, delete them */
2728 ilen = gtk_stext_str_compare_n
2729 (text, cur_pos, p_pos, i_len,
2732 gtk_stext_forward_delete
2738 GET_CHAR(cur_pos, cb, clen);
2740 /* insert space if it's alphanumeric */
2741 if ((cur_pos != line_pos) &&
2742 ((clen > 1) || isalnum((guchar)cb[0]))) {
2743 gtk_stext_insert(text, NULL, NULL,
2748 /* and start over with current line */
2749 cur_pos = p_pos - 1;
2751 line_len = cur_len = 0;
2755 g_print("after delete l_pos=");
2756 dump_text(text, line_pos, tlen, 1);
2758 /* move beginning of line if we are on LF */
2759 GET_CHAR(line_pos, cb, clen);
2760 if (clen == 1 && *cb == '\n')
2763 g_print("new line_pos=%d\n", line_pos);
2769 /* mark new line beginning */
2770 line_pos = cur_pos + 1;
2771 line_len = cur_len = 0;
2782 /* possible line break */
2783 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2784 line_pos = cur_pos + 1;
2785 line_len = cur_len + ch_len;
2788 /* are we over wrapping length set in preferences ? */
2789 if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
2793 g_print("should wrap cur_pos=%d ", cur_pos);
2794 dump_text(text, p_pos, tlen, 1);
2795 dump_text(text, line_pos, tlen, 1);
2797 /* force wrapping if it is one long word but not URL */
2798 if (line_pos - p_pos <= i_len)
2799 if (!gtk_stext_is_uri_string
2800 (text, line_pos, tlen))
2801 line_pos = cur_pos - 1;
2803 g_print("new line_pos=%d\n", line_pos);
2806 GET_CHAR(line_pos - 1, cbuf, clen);
2808 /* if next character is space delete it */
2809 if (clen == 1 && isspace(*(guchar *)cbuf)) {
2810 if (p_pos + i_len != line_pos ||
2811 !gtk_stext_is_uri_string
2812 (text, line_pos, tlen)) {
2814 /* workaround for correct cursor
2816 if (set_editable_pos == FALSE) {
2817 editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2818 if (editable_pos == line_pos)
2819 set_editable_pos = TRUE;
2821 gtk_stext_set_point(text, line_pos);
2822 gtk_stext_backward_delete(text, 1);
2831 /* if it is URL at beginning of line don't wrap */
2832 if (p_pos + i_len == line_pos &&
2833 gtk_stext_is_uri_string(text, line_pos, tlen)) {
2835 g_print("found URL at ");
2836 dump_text(text, line_pos, tlen, 1);
2843 gtk_stext_set_point(text, line_pos);
2844 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2845 gtk_stext_compact_buffer(text);
2848 /* for loop will increase it */
2849 cur_pos = line_pos - 1;
2850 /* start over with current line */
2852 line_len = cur_len = 0;
2853 if (autowrap || i_len > 0)
2858 g_print("after CR insert ");
2859 dump_text(text, line_pos, tlen, 1);
2860 dump_text(text, cur_pos, tlen, 1);
2863 /* should we insert quotation ? */
2864 if (linewrap_quote && i_len) {
2865 /* only if line is not already quoted */
2866 if (!gtk_stext_str_compare
2867 (text, line_pos, tlen, qfmt)) {
2870 if (line_pos - p_pos > i_len) {
2872 (text, i_len, p_pos,
2877 g_print("after quote insert ");
2878 dump_text(text, line_pos, tlen, 1);
2886 line_pos = cur_pos + 1;
2887 line_len = cur_len + DISP_WIDTH(ch_len);
2889 /* advance to next character in buffer */
2890 cur_len += DISP_WIDTH(ch_len);
2894 gtk_stext_thaw(text);
2896 if (set_editable_pos && editable_pos <= tlen)
2897 gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
2903 static void compose_set_title(Compose *compose)
2908 edited = compose->modified ? _(" [Edited]") : "";
2909 if (compose->account && compose->account->address)
2910 str = g_strdup_printf(_("%s - Compose message%s"),
2911 compose->account->address, edited);
2913 str = g_strdup_printf(_("Compose message%s"), edited);
2914 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2919 * compose_current_mail_account:
2921 * Find a current mail account (the currently selected account, or the
2922 * default account, if a news account is currently selected). If a
2923 * mail account cannot be found, display an error message.
2925 * Return value: Mail account, or NULL if not found.
2927 static PrefsAccount *
2928 compose_current_mail_account(void)
2932 if (cur_account && cur_account->protocol != A_NNTP)
2935 ac = account_get_default();
2936 if (!ac || ac->protocol == A_NNTP) {
2937 alertpanel_error(_("Account for sending mail is not specified.\n"
2938 "Please select a mail account before sending."));
2945 static void compose_select_account(Compose *compose, PrefsAccount *account,
2948 GtkItemFactory *ifactory;
2950 g_return_if_fail(account != NULL);
2952 compose->account = account;
2954 compose_set_title(compose);
2956 ifactory = gtk_item_factory_from_widget(compose->menubar);
2958 if (account->protocol == A_NNTP) {
2959 gtk_widget_show(compose->newsgroups_hbox);
2960 gtk_widget_show(compose->newsgroups_entry);
2961 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2962 compose->use_newsgroups = TRUE;
2964 menu_set_active(ifactory, "/View/To", FALSE);
2965 menu_set_sensitive(ifactory, "/View/To", TRUE);
2966 menu_set_active(ifactory, "/View/Cc", FALSE);
2967 menu_set_sensitive(ifactory, "/View/Cc", TRUE);
2968 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
2970 gtk_widget_hide(compose->newsgroups_hbox);
2971 gtk_widget_hide(compose->newsgroups_entry);
2972 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
2973 gtk_widget_queue_resize(compose->table_vbox);
2974 compose->use_newsgroups = FALSE;
2976 menu_set_active(ifactory, "/View/To", TRUE);
2977 menu_set_sensitive(ifactory, "/View/To", FALSE);
2978 menu_set_active(ifactory, "/View/Cc", TRUE);
2979 menu_set_sensitive(ifactory, "/View/Cc", FALSE);
2980 menu_set_active(ifactory, "/View/Followup to", FALSE);
2981 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
2984 if (account->set_autocc) {
2985 compose_entry_show(compose, COMPOSE_ENTRY_CC);
2986 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
2987 compose_entry_set(compose, account->auto_cc,
2990 if (account->set_autobcc) {
2991 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
2992 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
2993 compose_entry_set(compose, account->auto_bcc,
2996 if (account->set_autoreplyto) {
2997 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
2998 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
2999 compose_entry_set(compose, account->auto_replyto,
3000 COMPOSE_ENTRY_REPLY_TO);
3005 if (account->default_sign)
3006 menu_set_active(ifactory, "/Options/Sign", TRUE);
3008 menu_set_active(ifactory, "/Options/Sign", FALSE);
3009 if (account->default_encrypt)
3010 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3012 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3014 activate_privacy_system(compose, account);
3016 if (!init && compose->mode != COMPOSE_REDIRECT)
3017 compose_insert_sig(compose, TRUE);
3020 gboolean compose_check_for_valid_recipient(Compose *compose) {
3021 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3022 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3023 gboolean recipient_found = FALSE;
3027 /* free to and newsgroup list */
3028 slist_free_strings(compose->to_list);
3029 g_slist_free(compose->to_list);
3030 compose->to_list = NULL;
3032 slist_free_strings(compose->newsgroup_list);
3033 g_slist_free(compose->newsgroup_list);
3034 compose->newsgroup_list = NULL;
3036 /* search header entries for to and newsgroup entries */
3037 for (list = compose->header_list; list; list = list->next) {
3040 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3041 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3043 if (entry[0] != '\0') {
3044 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3045 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3046 compose->to_list = address_list_append(compose->to_list, entry);
3047 recipient_found = TRUE;
3050 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3051 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3052 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3053 recipient_found = TRUE;
3060 return recipient_found;
3063 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3067 if (compose_check_for_valid_recipient(compose) == FALSE) {
3068 alertpanel_error(_("Recipient is not specified."));
3072 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3073 if (*str == '\0' && check_subject == TRUE) {
3076 aval = alertpanel(_("Send"),
3077 _("Subject is empty. Send it anyway?"),
3078 _("Yes"), _("No"), NULL);
3079 if (aval != G_ALERTDEFAULT)
3086 gint compose_send(Compose *compose)
3093 compose_allow_user_actions (compose, FALSE);
3094 compose->sending = TRUE;
3096 if (compose_check_entries(compose, TRUE) == FALSE)
3099 val = compose_queue(compose, &msgnum, &folder);
3102 alertpanel_error(_("Could not queue message for sending"));
3107 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3108 compose->sending = FALSE;
3109 gtk_widget_destroy(compose->window);
3110 /* No more compose access in the normal codepath
3111 * after this point! */
3115 alertpanel_error(_("The message was queued but could not be "
3116 "sent.\nUse \"Send queued messages\" from "
3117 "the main window to retry."));
3118 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3119 compose->sending = FALSE;
3120 compose_allow_user_actions (compose, TRUE);
3125 msgpath = folder_item_fetch_msg(folder, msgnum);
3126 val = procmsg_send_message_queue(msgpath);
3129 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3130 compose->sending = FALSE;
3131 compose_allow_user_actions (compose, TRUE);
3133 folder_item_remove_msg(folder, msgnum);
3134 folder_item_scan(folder);
3139 folder_item_remove_msg(folder, msgnum);
3140 folder_item_scan(folder);
3141 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3142 gtk_widget_destroy(compose->window);
3148 compose_allow_user_actions (compose, TRUE);
3149 compose->sending = FALSE;
3154 static gboolean compose_use_attach(Compose *compose)
3156 return gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL;
3159 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3162 gchar buf[BUFFSIZE];
3164 gboolean first_to_address;
3165 gboolean first_cc_address;
3167 ComposeHeaderEntry *headerentry;
3168 gchar *headerentryname;
3172 debug_print("Writing redirect header\n");
3174 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3175 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3177 first_to_address = TRUE;
3178 first_cc_address = TRUE;
3179 for (list = compose->header_list; list; list = list->next) {
3180 headerentry = ((ComposeHeaderEntry *)list->data);
3181 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3183 if (g_strcasecmp(headerentryname, cc_hdr) == 0
3184 || g_strcasecmp(headerentryname, to_hdr) == 0) {
3185 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3186 Xstrdup_a(str, str, return -1);
3188 if (str[0] != '\0') {
3189 compose_convert_header
3190 (buf, sizeof(buf), str,
3191 strlen("Resent-To") + 2, TRUE);
3192 if (g_strcasecmp(headerentryname, to_hdr) == 0) {
3193 if (first_to_address) {
3194 fprintf(fp, "Resent-To: ");
3195 first_to_address = FALSE;
3200 if (g_strcasecmp(headerentryname, cc_hdr) == 0) {
3201 if (first_cc_address) {
3203 fprintf(fp, "Resent-Cc: ");
3204 first_cc_address = FALSE;
3210 fprintf(fp, "%s", buf);
3214 /* if (!first_address) { */
3221 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3223 gchar buf[BUFFSIZE];
3225 /* struct utsname utsbuf; */
3227 g_return_val_if_fail(fp != NULL, -1);
3228 g_return_val_if_fail(compose->account != NULL, -1);
3229 g_return_val_if_fail(compose->account->address != NULL, -1);
3232 get_rfc822_date(buf, sizeof(buf));
3233 fprintf(fp, "Resent-Date: %s\n", buf);
3236 if (compose->account->name && *compose->account->name) {
3237 compose_convert_header
3238 (buf, sizeof(buf), compose->account->name,
3239 strlen("From: "), TRUE);
3240 fprintf(fp, "Resent-From: %s <%s>\n",
3241 buf, compose->account->address);
3243 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3246 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3248 Xstrdup_a(str, str, return -1);
3251 compose_convert_header(buf, sizeof(buf), str,
3252 strlen("Subject: "), FALSE);
3253 fprintf(fp, "Subject: %s\n", buf);
3257 /* Resent-Message-ID */
3258 if (compose->account->gen_msgid) {
3259 generate_msgid(compose->account->address, buf, sizeof(buf));
3260 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3261 compose->msgid = g_strdup(buf);
3264 compose_redirect_write_headers_from_headerlist(compose, fp);
3266 /* separator between header and body */
3272 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3276 gchar buf[BUFFSIZE];
3278 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3279 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3283 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3284 /* should filter returnpath, delivered-to */
3285 if (g_strncasecmp(buf, "Return-Path:",
3286 strlen("Return-Path:")) == 0 ||
3287 g_strncasecmp(buf, "Delivered-To:",
3288 strlen("Delivered-To:")) == 0 ||
3289 g_strncasecmp(buf, "Received:",
3290 strlen("Received:")) == 0 ||
3291 g_strncasecmp(buf, "Subject:",
3292 strlen("Subject:")) == 0 ||
3293 g_strncasecmp(buf, "X-UIDL:",
3294 strlen("X-UIDL:")) == 0)
3297 if (fputs(buf, fdest) == -1)
3300 if (!prefs_common.redirect_keep_from) {
3301 if (g_strncasecmp(buf, "From:",
3302 strlen("From:")) == 0) {
3303 fputs(" (by way of ", fdest);
3304 if (compose->account->name
3305 && *compose->account->name) {
3306 compose_convert_header
3308 compose->account->name,
3311 fprintf(fdest, "%s <%s>",
3313 compose->account->address);
3315 fprintf(fdest, "%s",
3316 compose->account->address);
3321 if (fputs("\n", fdest) == -1)
3325 compose_redirect_write_headers(compose, fdest);
3327 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3328 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
3341 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
3345 const gchar *out_codeset;
3346 EncodingType encoding;
3347 MimeInfo *mimemsg, *mimetext;
3349 /* create message MimeInfo */
3350 mimemsg = procmime_mimeinfo_new();
3351 mimemsg->type = MIMETYPE_MESSAGE;
3352 mimemsg->subtype = g_strdup("rfc822");
3353 mimemsg->content = MIMECONTENT_MEM;
3354 mimemsg->data.mem = compose_get_header(compose);
3356 /* Create text part MimeInfo */
3357 /* get all composed text */
3358 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3359 if (is_ascii_str(chars)) {
3362 out_codeset = CS_US_ASCII;
3363 encoding = ENC_7BIT;
3365 const gchar *src_codeset;
3367 out_codeset = conv_get_outgoing_charset_str();
3368 if (!g_strcasecmp(out_codeset, CS_US_ASCII))
3369 out_codeset = CS_ISO_8859_1;
3371 if (prefs_common.encoding_method == CTE_BASE64)
3372 encoding = ENC_BASE64;
3373 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3374 encoding = ENC_QUOTED_PRINTABLE;
3375 else if (prefs_common.encoding_method == CTE_8BIT)
3376 encoding = ENC_8BIT;
3378 encoding = procmime_get_encoding_for_charset(out_codeset);
3380 src_codeset = conv_get_current_charset_str();
3381 /* if current encoding is US-ASCII, set it the same as
3382 outgoing one to prevent code conversion failure */
3383 if (!g_strcasecmp(src_codeset, CS_US_ASCII))
3384 src_codeset = out_codeset;
3386 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3387 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3389 if (action == COMPOSE_WRITE_FOR_SEND) {
3390 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3395 msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
3397 "Send it anyway?"), src_codeset, out_codeset);
3398 aval = alertpanel_with_type
3399 (_("Error"), msg, _("Yes"), _("+No"), NULL, NULL, ALERT_ERROR);
3402 if (aval != G_ALERTDEFAULT) {
3407 out_codeset = src_codeset;
3413 out_codeset = src_codeset;
3419 mimetext = procmime_mimeinfo_new();
3420 mimetext->content = MIMECONTENT_MEM;
3421 mimetext->data.mem = buf;
3422 mimetext->type = MIMETYPE_TEXT;
3423 mimetext->subtype = g_strdup("plain");
3424 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
3425 g_strdup(out_codeset));
3427 /* append attachment parts */
3428 if (compose_use_attach(compose)) {
3429 MimeInfo *mimempart;
3431 mimempart = procmime_mimeinfo_new();
3432 mimempart->content = MIMECONTENT_EMPTY;
3433 mimempart->type = MIMETYPE_MULTIPART;
3434 mimempart->subtype = g_strdup("mixed");
3435 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
3436 generate_mime_boundary(NULL));
3438 mimetext->disposition = DISPOSITIONTYPE_INLINE;
3440 g_node_append(mimempart->node, mimetext->node);
3441 g_node_append(mimemsg->node, mimempart->node);
3443 compose_add_attachments(compose, mimempart);
3445 g_node_append(mimemsg->node, mimetext->node);
3448 if (compose->use_signing && privacy_system_can_sign(compose->privacy_system))
3449 if (!privacy_sign(compose->privacy_system, mimemsg))
3452 procmime_write_mimeinfo(mimemsg, fp);
3457 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3463 if ((fp = fopen(file, "wb")) == NULL) {
3464 FILE_OP_ERROR(file, "fopen");
3468 /* chmod for security */
3469 if (change_file_mode_rw(fp, file) < 0) {
3470 FILE_OP_ERROR(file, "chmod");
3471 g_warning("can't change file mode\n");
3474 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3477 len = strlen(chars);
3478 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3479 FILE_OP_ERROR(file, "fwrite");
3488 if (fclose(fp) == EOF) {
3489 FILE_OP_ERROR(file, "fclose");
3496 static gint compose_remove_reedit_target(Compose *compose)
3499 MsgInfo *msginfo = compose->targetinfo;
3501 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3502 if (!msginfo) return -1;
3504 item = msginfo->folder;
3505 g_return_val_if_fail(item != NULL, -1);
3507 if (procmsg_msg_exist(msginfo) &&
3508 (item->stype == F_DRAFT || item->stype == F_QUEUE
3509 || msginfo == compose->autosaved_draft)) {
3510 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3511 g_warning("can't remove the old message\n");
3519 void compose_remove_draft(Compose *compose)
3522 MsgInfo *msginfo = compose->targetinfo;
3523 drafts = account_get_special_folder(compose->account, F_DRAFT);
3525 if (procmsg_msg_exist(msginfo)) {
3526 folder_item_remove_msg(drafts, msginfo->msgnum);
3531 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3533 return compose_queue_sub (compose, msgnum, item, FALSE);
3535 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3542 static gboolean lock = FALSE;
3543 PrefsAccount *mailac = NULL, *newsac = NULL;
3545 debug_print("queueing message...\n");
3546 g_return_val_if_fail(compose->account != NULL, -1);
3550 if (compose_check_entries(compose, check_subject) == FALSE) {
3555 if (!compose->to_list && !compose->newsgroup_list) {
3556 g_warning("can't get recipient list.");
3561 if (compose->to_list) {
3562 if (compose->account->protocol != A_NNTP)
3563 mailac = compose->account;
3564 else if (cur_account && cur_account->protocol != A_NNTP)
3565 mailac = cur_account;
3566 else if (!(mailac = compose_current_mail_account())) {
3568 alertpanel_error(_("No account for sending mails available!"));
3573 if (compose->newsgroup_list) {
3574 if (compose->account->protocol == A_NNTP)
3575 newsac = compose->account;
3576 else if (!newsac->protocol != A_NNTP) {
3578 alertpanel_error(_("No account for posting news available!"));
3583 if (prefs_common.linewrap_at_send)
3584 compose_wrap_line_all(compose);
3586 /* write queue header */
3587 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
3588 G_DIR_SEPARATOR, compose);
3589 if ((fp = fopen(tmp, "wb")) == NULL) {
3590 FILE_OP_ERROR(tmp, "fopen");
3595 if (change_file_mode_rw(fp, tmp) < 0) {
3596 FILE_OP_ERROR(tmp, "chmod");
3597 g_warning("can't change file mode\n");
3600 /* queueing variables */
3601 fprintf(fp, "AF:\n");
3602 fprintf(fp, "NF:0\n");
3603 fprintf(fp, "PS:10\n");
3604 fprintf(fp, "SRH:1\n");
3605 fprintf(fp, "SFN:\n");
3606 fprintf(fp, "DSR:\n");
3608 fprintf(fp, "MID:<%s>\n", compose->msgid);
3610 fprintf(fp, "MID:\n");
3611 fprintf(fp, "CFG:\n");
3612 fprintf(fp, "PT:0\n");
3613 fprintf(fp, "S:%s\n", compose->account->address);
3614 fprintf(fp, "RQ:\n");
3616 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3618 fprintf(fp, "SSV:\n");
3620 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3622 fprintf(fp, "NSV:\n");
3623 fprintf(fp, "SSH:\n");
3624 /* write recepient list */
3625 if (compose->to_list) {
3626 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
3627 for (cur = compose->to_list->next; cur != NULL;
3629 fprintf(fp, ",<%s>", (gchar *)cur->data);
3632 /* write newsgroup list */
3633 if (compose->newsgroup_list) {
3635 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3636 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3637 fprintf(fp, ",%s", (gchar *)cur->data);
3640 /* Sylpheed account IDs */
3642 fprintf(fp, "MAID:%d\n", mailac->account_id);
3644 fprintf(fp, "NAID:%d\n", newsac->account_id);
3646 if (compose->privacy_system != NULL) {
3647 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
3648 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
3649 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
3650 if (compose->use_encryption) {
3653 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
3654 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n", encdata);
3659 /* Save copy folder */
3660 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3661 gchar *savefolderid;
3663 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3664 fprintf(fp, "SCF:%s\n", savefolderid);
3665 g_free(savefolderid);
3667 /* Message-ID of message replying to */
3668 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
3671 folderid = folder_item_get_identifier(compose->replyinfo->folder);
3672 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
3675 /* Message-ID of message forwarding to */
3676 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
3679 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
3680 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
3685 if (compose->redirect_filename != NULL) {
3686 if (compose_redirect_write_to_file(compose, fp) < 0) {
3694 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND) < 0) {
3703 if (fclose(fp) == EOF) {
3704 FILE_OP_ERROR(tmp, "fclose");
3710 queue = account_get_special_folder(compose->account, F_QUEUE);
3712 g_warning("can't find queue folder\n");
3717 folder_item_scan(queue);
3718 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
3719 g_warning("can't queue the message\n");
3727 if (compose->mode == COMPOSE_REEDIT) {
3728 compose_remove_reedit_target(compose);
3731 if ((msgnum != NULL) && (item != NULL)) {
3739 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
3742 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3745 struct stat statbuf;
3746 gchar *type, *subtype;
3748 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3750 mimepart = procmime_mimeinfo_new();
3751 mimepart->content = MIMECONTENT_FILE;
3752 mimepart->data.filename = g_strdup(ainfo->file);
3753 mimepart->offset = 0;
3755 stat(ainfo->file, &statbuf);
3756 mimepart->length = statbuf.st_size;
3758 type = g_strdup(ainfo->content_type);
3760 if (!strchr(type, '/')) {
3762 type = g_strdup("application/octet-stream");
3765 subtype = strchr(type, '/') + 1;
3766 *(subtype - 1) = '\0';
3767 mimepart->type = procmime_get_media_type(type);
3768 mimepart->subtype = g_strdup(subtype);
3771 if (mimepart->type == MIMETYPE_MESSAGE &&
3772 !g_strcasecmp(mimepart->subtype, "rfc822")) {
3773 mimepart->disposition = DISPOSITIONTYPE_INLINE;
3775 g_hash_table_insert(mimepart->typeparameters,
3776 g_strdup("name"), g_strdup(ainfo->name));
3777 g_hash_table_insert(mimepart->dispositionparameters,
3778 g_strdup("filename"), g_strdup(ainfo->name));
3779 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
3782 procmime_encode_content(mimepart, ainfo->encoding);
3784 g_node_append(parent->node, mimepart->node);
3788 #define QUOTE_IF_REQUIRED(out, str) \
3790 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3794 len = strlen(str) + 3; \
3795 if ((__tmp = alloca(len)) == NULL) { \
3796 g_warning("can't allocate memory\n"); \
3797 g_string_free(header, TRUE); \
3800 g_snprintf(__tmp, len, "\"%s\"", str); \
3805 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3806 g_warning("can't allocate memory\n"); \
3807 g_string_free(header, TRUE); \
3810 strcpy(__tmp, str); \
3816 #define IS_IN_CUSTOM_HEADER(header) \
3817 (compose->account->add_customhdr && \
3818 custom_header_find(compose->account->customhdr_list, header) != NULL)
3820 static void compose_add_headerfield_from_headerlist(Compose *compose,
3822 const gchar *fieldname,
3823 const gchar *seperator)
3825 gchar *str, *fieldname_w_colon, *trans_fieldname;
3826 gboolean add_field = FALSE;
3828 ComposeHeaderEntry *headerentry;
3829 gchar * headerentryname;
3832 if (IS_IN_CUSTOM_HEADER(fieldname))
3835 debug_print("Adding %s-fields\n", fieldname);
3837 fieldstr = g_string_sized_new(64);
3839 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
3840 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
3842 for (list = compose->header_list; list; list = list->next) {
3843 headerentry = ((ComposeHeaderEntry *)list->data);
3844 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3846 if (!g_strcasecmp(trans_fieldname, headerentryname)) {
3847 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
3849 if (str[0] != '\0') {
3851 g_string_append(fieldstr, seperator);
3852 g_string_append(fieldstr, str);
3861 buf = g_new0(gchar, fieldstr->len * 4 + 256);
3862 compose_convert_header
3863 (buf, fieldstr->len * 4 + 256, fieldstr->str,
3864 strlen(fieldname) + 2, TRUE);
3865 g_string_sprintfa(header, "%s: %s\n", fieldname, buf);
3869 g_free(fieldname_w_colon);
3870 g_string_free(fieldstr, TRUE);
3875 static gchar *compose_get_header(Compose *compose)
3877 gchar buf[BUFFSIZE];
3881 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3884 /* struct utsname utsbuf; */
3886 g_return_val_if_fail(compose->account != NULL, NULL);
3887 g_return_val_if_fail(compose->account->address != NULL, NULL);
3889 header = g_string_sized_new(64);
3892 if (compose->account->add_date) {
3893 get_rfc822_date(buf, sizeof(buf));
3894 g_string_sprintfa(header, "Date: %s\n", buf);
3898 if (compose->account->name && *compose->account->name) {
3899 compose_convert_header
3900 (buf, sizeof(buf), compose->account->name,
3901 strlen("From: "), TRUE);
3902 QUOTE_IF_REQUIRED(name, buf);
3903 g_string_sprintfa(header, "From: %s <%s>\n",
3904 name, compose->account->address);
3906 g_string_sprintfa(header, "From: %s\n", compose->account->address);
3909 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
3912 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
3915 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
3918 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
3921 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3922 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3925 tmpstr = g_strdup(str);
3926 if (tmpstr == NULL) {
3927 g_string_free(header, TRUE);
3932 compose_convert_header(buf, sizeof(buf), str,
3933 strlen("Subject: "), FALSE);
3934 g_string_sprintfa(header, "Subject: %s\n", buf);
3940 if (compose->account->gen_msgid) {
3941 generate_msgid(compose->account->address, buf, sizeof(buf));
3942 g_string_sprintfa(header, "Message-ID: <%s>\n", buf);
3943 compose->msgid = g_strdup(buf);
3946 if (compose->remove_references == FALSE) {
3948 if (compose->inreplyto && compose->to_list)
3949 g_string_sprintfa(header, "In-Reply-To: <%s>\n", compose->inreplyto);
3952 if (compose->references)
3953 g_string_sprintfa(header, "References: %s\n", compose->references);
3957 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
3960 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
3963 if (compose->account->organization &&
3964 !IS_IN_CUSTOM_HEADER("Organization")) {
3965 compose_convert_header(buf, sizeof(buf),
3966 compose->account->organization,
3967 strlen("Organization: "), FALSE);
3968 g_string_sprintfa(header, "Organization: %s\n", buf);
3971 /* Program version and system info */
3972 /* uname(&utsbuf); */
3973 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
3974 !compose->newsgroup_list) {
3975 g_string_sprintfa(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3977 gtk_major_version, gtk_minor_version, gtk_micro_version,
3979 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3981 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3982 g_string_sprintfa(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3984 gtk_major_version, gtk_minor_version, gtk_micro_version,
3986 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3989 /* custom headers */
3990 if (compose->account->add_customhdr) {
3993 for (cur = compose->account->customhdr_list; cur != NULL;
3995 CustomHeader *chdr = (CustomHeader *)cur->data;
3997 if (custom_header_is_allowed(chdr->name)) {
3998 compose_convert_header
4000 chdr->value ? chdr->value : "",
4001 strlen(chdr->name) + 2, FALSE);
4002 g_string_sprintfa(header, "%s: %s\n", chdr->name, buf);
4008 switch (compose->priority) {
4009 case PRIORITY_HIGHEST: g_string_sprintfa(header, "Importance: high\n"
4010 "X-Priority: 1 (Highest)\n");
4012 case PRIORITY_HIGH: g_string_sprintfa(header, "Importance: high\n"
4013 "X-Priority: 2 (High)\n");
4015 case PRIORITY_NORMAL: break;
4016 case PRIORITY_LOW: g_string_sprintfa(header, "Importance: low\n"
4017 "X-Priority: 4 (Low)\n");
4019 case PRIORITY_LOWEST: g_string_sprintfa(header, "Importance: low\n"
4020 "X-Priority: 5 (Lowest)\n");
4022 default: debug_print("compose: priority unknown : %d\n",
4026 /* Request Return Receipt */
4027 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4028 if (compose->return_receipt) {
4029 if (compose->account->name
4030 && *compose->account->name) {
4031 compose_convert_header(buf, sizeof(buf),
4032 compose->account->name,
4033 strlen("Disposition-Notification-To: "),
4035 g_string_sprintfa(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4037 g_string_sprintfa(header, "Disposition-Notification-To: %s\n", compose->account->address);
4041 /* get special headers */
4042 for (list = compose->header_list; list; list = list->next) {
4043 ComposeHeaderEntry *headerentry;
4046 gchar *headername_wcolon;
4047 gchar *headername_trans;
4050 gboolean standard_header = FALSE;
4052 headerentry = ((ComposeHeaderEntry *)list->data);
4054 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4055 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4060 if (!strstr(tmp, ":")) {
4061 headername_wcolon = g_strconcat(tmp, ":", NULL);
4062 headername = g_strdup(tmp);
4064 headername_wcolon = g_strdup(tmp);
4065 headername = g_strdup(strtok(tmp, ":"));
4069 headervalue = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4070 subst_char(headervalue, '\r', ' ');
4071 subst_char(headervalue, '\n', ' ');
4072 string = std_headers;
4073 while (*string != NULL) {
4074 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4075 if (!strcmp(headername_trans,headername_wcolon))
4076 standard_header = TRUE;
4079 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4080 g_string_sprintfa(header, "%s %s\n", headername_wcolon, headervalue);
4083 g_free(headername_wcolon);
4087 g_string_free(header, FALSE);
4092 #undef IS_IN_CUSTOM_HEADER
4094 static void compose_convert_header(gchar *dest, gint len, gchar *src,
4095 gint header_len, gboolean addr_field)
4097 g_return_if_fail(src != NULL);
4098 g_return_if_fail(dest != NULL);
4100 if (len < 1) return;
4102 subst_char(src, '\n', ' ');
4103 subst_char(src, '\r', ' ');
4106 conv_encode_header(dest, len, src, header_len, addr_field);
4109 static void compose_create_header_entry(Compose *compose)
4111 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4115 GList *combo_list = NULL;
4116 gchar **string, *header = NULL;
4117 ComposeHeaderEntry *headerentry;
4118 gboolean standard_header = FALSE;
4120 headerentry = g_new0(ComposeHeaderEntry, 1);
4123 combo = gtk_combo_new();
4125 while(*string != NULL) {
4126 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4129 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4130 g_list_free(combo_list);
4131 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4132 gtk_widget_show(combo);
4133 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4134 if (compose->header_last) {
4135 gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4137 while (*string != NULL) {
4138 if (!strcmp(*string, last_header_entry))
4139 standard_header = TRUE;
4142 if (standard_header)
4143 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4145 if (!compose->header_last || !standard_header) {
4146 switch(compose->account->protocol) {
4148 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4151 header = prefs_common.trans_hdr ? _("To:") : "To:";
4156 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4159 entry = gtk_entry_new();
4160 gtk_widget_show(entry);
4161 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);
4163 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4164 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4165 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4166 gtk_signal_connect(GTK_OBJECT(entry), "button-press-event",
4167 GTK_SIGNAL_FUNC(compose_headerentry_button_pressed),
4170 address_completion_register_entry(GTK_ENTRY(entry));
4172 headerentry->compose = compose;
4173 headerentry->combo = combo;
4174 headerentry->entry = entry;
4175 headerentry->headernum = compose->header_nextrow;
4177 compose->header_nextrow++;
4178 compose->header_last = headerentry;
4181 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4183 ComposeHeaderEntry *last_header;
4185 last_header = compose->header_last;
4187 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4188 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4191 static GtkWidget *compose_create_header(Compose *compose)
4195 GtkWidget *from_optmenu_hbox;
4196 #if 0 /* NEW COMPOSE GUI */
4197 GtkWidget *to_entry;
4199 GtkWidget *newsgroups_entry;
4200 GtkWidget *newsgroups_hbox;
4202 GtkWidget *header_scrolledwin;
4203 GtkWidget *header_table;
4204 #if 0 /* NEW COMPOSE GUI */
4205 GtkWidget *cc_entry;
4207 GtkWidget *bcc_entry;
4208 GtkWidget *bcc_hbox;
4209 GtkWidget *reply_entry;
4210 GtkWidget *reply_hbox;
4211 GtkWidget *followup_entry;
4212 GtkWidget *followup_hbox;
4217 /* header labels and entries */
4218 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4219 gtk_widget_show(header_scrolledwin);
4220 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4222 header_table = gtk_table_new(2, 2, FALSE);
4223 gtk_widget_show(header_table);
4224 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4225 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4226 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4229 /* option menu for selecting accounts */
4230 hbox = gtk_hbox_new(FALSE, 0);
4231 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4232 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4233 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4235 from_optmenu_hbox = compose_account_option_menu_create(compose);
4236 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4237 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4238 #if 0 /* NEW COMPOSE GUI */
4239 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4243 compose->header_table = header_table;
4244 compose->header_list = NULL;
4245 compose->header_nextrow = count;
4247 compose_create_header_entry(compose);
4249 #if 0 /* NEW COMPOSE GUI */
4250 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4252 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4253 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4254 &count, "Newsgroups:", FALSE);
4255 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4257 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4259 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4261 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4262 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4264 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4265 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4267 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4268 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4269 "Followup-To:", FALSE);
4270 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4272 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4274 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4275 GTK_SIGNAL_FUNC(to_activated), compose);
4276 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4277 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4278 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4279 GTK_SIGNAL_FUNC(subject_activated), compose);
4280 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4281 GTK_SIGNAL_FUNC(cc_activated), compose);
4282 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4283 GTK_SIGNAL_FUNC(bcc_activated), compose);
4284 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4285 GTK_SIGNAL_FUNC(replyto_activated), compose);
4286 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4287 GTK_SIGNAL_FUNC(followupto_activated), compose);
4289 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4290 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4291 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4292 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4293 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4294 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4295 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4296 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4297 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4298 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4299 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4300 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4301 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4302 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4305 compose->table = NULL;
4306 #if 0 /* NEW COMPOSE GUI */
4307 compose->table = table;
4308 compose->to_hbox = to_hbox;
4309 compose->to_entry = to_entry;
4310 compose->newsgroups_hbox = newsgroups_hbox;
4311 compose->newsgroups_entry = newsgroups_entry;
4313 #if 0 /* NEW COMPOSE GUI */
4314 compose->cc_hbox = cc_hbox;
4315 compose->cc_entry = cc_entry;
4316 compose->bcc_hbox = bcc_hbox;
4317 compose->bcc_entry = bcc_entry;
4318 compose->reply_hbox = reply_hbox;
4319 compose->reply_entry = reply_entry;
4320 compose->followup_hbox = followup_hbox;
4321 compose->followup_entry = followup_entry;
4324 return header_scrolledwin ;
4327 GtkWidget *compose_create_attach(Compose *compose)
4329 gchar *titles[N_ATTACH_COLS];
4332 GtkWidget *attach_scrwin;
4333 GtkWidget *attach_clist;
4335 titles[COL_MIMETYPE] = _("MIME type");
4336 titles[COL_SIZE] = _("Size");
4337 titles[COL_NAME] = _("Name");
4339 /* attachment list */
4340 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4341 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4342 GTK_POLICY_AUTOMATIC,
4344 gtk_widget_set_usize(attach_scrwin, -1, 80);
4346 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4347 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4349 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4350 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4351 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4352 GTK_SELECTION_EXTENDED);
4353 for (i = 0; i < N_ATTACH_COLS; i++)
4354 GTK_WIDGET_UNSET_FLAGS
4355 (GTK_CLIST(attach_clist)->column[i].button,
4357 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4359 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4360 GTK_SIGNAL_FUNC(attach_selected), compose);
4361 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4362 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4363 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4364 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4367 gtk_drag_dest_set(attach_clist,
4368 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4369 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4370 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4371 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4374 compose->attach_scrwin = attach_scrwin;
4375 compose->attach_clist = attach_clist;
4377 return attach_scrwin;
4380 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4381 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4383 static GtkWidget *compose_create_others(Compose *compose)
4386 GtkWidget *savemsg_checkbtn;
4387 GtkWidget *savemsg_entry;
4388 GtkWidget *savemsg_select;
4391 gchar *folderidentifier;
4393 /* Table for settings */
4394 table = gtk_table_new(3, 1, FALSE);
4395 gtk_widget_show(table);
4396 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4399 /* Save Message to folder */
4400 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4401 gtk_widget_show(savemsg_checkbtn);
4402 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4403 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4404 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4406 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4407 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4409 savemsg_entry = gtk_entry_new();
4410 gtk_widget_show(savemsg_entry);
4411 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4412 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4413 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4414 folderidentifier = folder_item_get_identifier(account_get_special_folder
4415 (compose->account, F_OUTBOX));
4416 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4417 g_free(folderidentifier);
4420 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4421 gtk_widget_show (savemsg_select);
4422 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4423 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4424 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4429 compose->savemsg_checkbtn = savemsg_checkbtn;
4430 compose->savemsg_entry = savemsg_entry;
4435 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4437 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4438 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4441 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4446 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4449 path = folder_item_get_identifier(dest);
4451 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4455 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4461 GtkWidget *handlebox;
4463 GtkWidget *notebook;
4468 GtkWidget *subject_hbox;
4469 GtkWidget *subject_frame;
4470 GtkWidget *subject_entry;
4474 GtkWidget *edit_vbox;
4475 GtkWidget *ruler_hbox;
4477 GtkWidget *scrolledwin;
4480 UndoMain *undostruct;
4482 gchar *titles[N_ATTACH_COLS];
4483 guint n_menu_entries;
4484 GtkStyle *style, *new_style;
4487 gboolean success[1];
4488 GtkWidget *popupmenu;
4489 GtkItemFactory *popupfactory;
4490 GtkItemFactory *ifactory;
4491 GtkWidget *tmpl_menu;
4495 GtkAspell * gtkaspell = NULL;
4498 static GdkGeometry geometry;
4500 g_return_val_if_fail(account != NULL, NULL);
4502 debug_print("Creating compose window...\n");
4503 compose = g_new0(Compose, 1);
4505 titles[COL_MIMETYPE] = _("MIME type");
4506 titles[COL_SIZE] = _("Size");
4507 titles[COL_NAME] = _("Name");
4509 compose->account = account;
4511 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4512 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4513 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4514 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4516 if (!geometry.max_width) {
4517 geometry.max_width = gdk_screen_width();
4518 geometry.max_height = gdk_screen_height();
4520 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4521 &geometry, GDK_HINT_MAX_SIZE);
4522 gtk_widget_set_uposition(window, prefs_common.compose_x,
4523 prefs_common.compose_y);
4524 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4525 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4526 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4527 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4528 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4529 gtk_widget_realize(window);
4531 gtkut_widget_set_composer_icon(window);
4533 vbox = gtk_vbox_new(FALSE, 0);
4534 gtk_container_add(GTK_CONTAINER(window), vbox);
4536 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4537 menubar = menubar_create(window, compose_entries,
4538 n_menu_entries, "<Compose>", compose);
4539 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4541 handlebox = gtk_handle_box_new();
4542 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4544 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
4547 vbox2 = gtk_vbox_new(FALSE, 2);
4548 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4549 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4552 notebook = gtk_notebook_new();
4553 gtk_widget_set_usize(notebook, -1, 130);
4554 gtk_widget_show(notebook);
4556 /* header labels and entries */
4557 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4558 /* attachment list */
4559 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4561 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4564 subject_hbox = gtk_hbox_new(FALSE, 0);
4565 gtk_widget_show(subject_hbox);
4567 subject_frame = gtk_frame_new(NULL);
4568 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4569 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4570 gtk_widget_show(subject_frame);
4572 subject = gtk_hbox_new(FALSE, 0);
4573 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4574 gtk_widget_show(subject);
4576 label = gtk_label_new(_("Subject:"));
4577 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4578 gtk_widget_show(label);
4580 subject_entry = gtk_entry_new();
4581 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4582 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4583 gtk_widget_show(subject_entry);
4584 compose->subject_entry = subject_entry;
4585 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4587 edit_vbox = gtk_vbox_new(FALSE, 0);
4589 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4592 ruler_hbox = gtk_hbox_new(FALSE, 0);
4593 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4595 ruler = gtk_shruler_new();
4596 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4597 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4599 gtk_widget_set_usize(ruler_hbox, 1, -1);
4602 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4603 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4604 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4605 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4606 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4608 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4609 (GTK_SCROLLED_WINDOW(scrolledwin)),
4610 gtk_scrolled_window_get_vadjustment
4611 (GTK_SCROLLED_WINDOW(scrolledwin)));
4612 GTK_STEXT(text)->default_tab_width = 8;
4613 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4615 if (prefs_common.block_cursor) {
4616 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4619 if (prefs_common.smart_wrapping) {
4620 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4621 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4624 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4626 gtk_signal_connect(GTK_OBJECT(text), "changed",
4627 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4628 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4629 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4630 gtk_signal_connect(GTK_OBJECT(text), "activate",
4631 GTK_SIGNAL_FUNC(text_activated), compose);
4632 gtk_signal_connect(GTK_OBJECT(text), "insert_text",
4633 GTK_SIGNAL_FUNC(text_inserted), compose);
4634 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4635 GTK_SIGNAL_FUNC(compose_button_press_cb),
4638 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4639 GTK_SIGNAL_FUNC(compose_key_press_cb),
4642 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4643 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4647 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4648 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4649 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4650 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4652 gtk_widget_show_all(vbox);
4654 /* pane between attach clist and text */
4655 paned = gtk_vpaned_new();
4656 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4657 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4658 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4659 gtk_paned_add1(GTK_PANED(paned), notebook);
4660 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4661 gtk_widget_show_all(paned);
4663 style = gtk_widget_get_style(text);
4665 /* workaround for the slow down of GtkSText when using Pixmap theme */
4666 if (style->engine) {
4667 GtkThemeEngine *engine;
4669 engine = style->engine;
4670 style->engine = NULL;
4671 new_style = gtk_style_copy(style);
4672 style->engine = engine;
4674 new_style = gtk_style_copy(style);
4676 if (prefs_common.textfont) {
4679 if ((font = gtkut_font_load(prefs_common.textfont)) != NULL) {
4680 gdk_font_unref(new_style->font);
4681 new_style->font = font;
4685 gtk_widget_set_style(text, new_style);
4687 color[0] = quote_color;
4688 cmap = gdk_window_get_colormap(window->window);
4689 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4690 if (success[0] == FALSE) {
4691 g_warning("Compose: color allocation failed.\n");
4692 style = gtk_widget_get_style(text);
4693 quote_color = style->black;
4696 n_entries = sizeof(compose_popup_entries) /
4697 sizeof(compose_popup_entries[0]);
4698 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4699 "<Compose>", &popupfactory,
4702 ifactory = gtk_item_factory_from_widget(menubar);
4703 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4704 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4705 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
4707 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4709 undostruct = undo_init(text);
4710 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4713 address_completion_start(window);
4715 compose->window = window;
4716 compose->vbox = vbox;
4717 compose->menubar = menubar;
4718 compose->handlebox = handlebox;
4720 compose->vbox2 = vbox2;
4722 compose->paned = paned;
4724 compose->edit_vbox = edit_vbox;
4725 compose->ruler_hbox = ruler_hbox;
4726 compose->ruler = ruler;
4727 compose->scrolledwin = scrolledwin;
4728 compose->text = text;
4730 compose->focused_editable = NULL;
4732 compose->popupmenu = popupmenu;
4733 compose->popupfactory = popupfactory;
4735 compose->tmpl_menu = tmpl_menu;
4737 compose->mode = mode;
4739 compose->targetinfo = NULL;
4740 compose->replyinfo = NULL;
4741 compose->fwdinfo = NULL;
4743 compose->replyto = NULL;
4745 compose->bcc = NULL;
4746 compose->followup_to = NULL;
4748 compose->ml_post = NULL;
4750 compose->inreplyto = NULL;
4751 compose->references = NULL;
4752 compose->msgid = NULL;
4753 compose->boundary = NULL;
4755 compose->autowrap = prefs_common.autowrap;
4757 compose->use_signing = FALSE;
4758 compose->use_encryption = FALSE;
4759 compose->privacy_system = NULL;
4761 compose->modified = FALSE;
4763 compose->return_receipt = FALSE;
4765 compose->to_list = NULL;
4766 compose->newsgroup_list = NULL;
4768 compose->undostruct = undostruct;
4770 compose->sig_str = NULL;
4772 compose->exteditor_file = NULL;
4773 compose->exteditor_pid = -1;
4774 compose->exteditor_readdes = -1;
4775 compose->exteditor_tag = -1;
4776 compose->draft_timeout_tag = -1;
4779 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4780 if (mode != COMPOSE_REDIRECT) {
4781 if (prefs_common.enable_aspell && prefs_common.dictionary &&
4782 strcmp(prefs_common.dictionary, _("None"))) {
4783 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
4784 prefs_common.dictionary,
4785 conv_get_current_charset_str(),
4786 prefs_common.misspelled_col,
4787 prefs_common.check_while_typing,
4788 prefs_common.use_alternate,
4791 alertpanel_error(_("Spell checker could not "
4793 gtkaspell_checkers_strerror());
4794 gtkaspell_checkers_reset_error();
4797 GtkWidget *menuitem;
4799 if (!gtkaspell_set_sug_mode(gtkaspell,
4800 prefs_common.aspell_sugmode)) {
4801 debug_print("Aspell: could not set "
4802 "suggestion mode %s\n",
4803 gtkaspell_checkers_strerror());
4804 gtkaspell_checkers_reset_error();
4807 menuitem = gtk_item_factory_get_item(ifactory,
4808 "/Spelling/Spelling Configuration");
4809 gtkaspell_populate_submenu(gtkaspell, menuitem);
4810 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4814 compose->gtkaspell = gtkaspell;
4817 compose_select_account(compose, account, TRUE);
4819 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
4820 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
4821 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4823 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
4824 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4826 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
4827 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4830 if (account->protocol != A_NNTP)
4831 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4833 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4835 addressbook_set_target_compose(compose);
4837 if (mode != COMPOSE_REDIRECT)
4838 compose_set_template_menu(compose);
4840 GtkWidget *menuitem;
4841 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4842 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
4845 compose_list = g_list_append(compose_list, compose);
4847 if (!prefs_common.show_ruler)
4848 gtk_widget_hide(ruler_hbox);
4851 compose->priority = PRIORITY_NORMAL;
4852 compose_update_priority_menu_item(compose);
4855 compose_update_actions_menu(compose);
4857 /* Privacy Systems menu */
4858 compose_update_privacy_systems_menu(compose);
4860 activate_privacy_system(compose, account);
4861 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
4862 gtk_widget_show(window);
4867 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4873 gint num = 0, def_menu = 0;
4875 accounts = account_get_list();
4876 g_return_val_if_fail(accounts != NULL, NULL);
4878 hbox = gtk_hbox_new(FALSE, 0);
4879 optmenu = gtk_option_menu_new();
4880 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4881 menu = gtk_menu_new();
4883 for (; accounts != NULL; accounts = accounts->next, num++) {
4884 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4885 GtkWidget *menuitem;
4888 if (ac == compose->account) def_menu = num;
4891 name = g_strdup_printf("%s: %s <%s>",
4893 ac->name, ac->address);
4895 name = g_strdup_printf("%s: %s",
4896 ac->account_name, ac->address);
4897 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
4899 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4900 GTK_SIGNAL_FUNC(account_activated),
4904 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4905 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4910 static void compose_set_priority_cb(gpointer data,
4914 Compose *compose = (Compose *) data;
4915 compose->priority = action;
4918 static void compose_update_priority_menu_item(Compose * compose)
4920 GtkItemFactory *ifactory;
4921 GtkWidget *menuitem = NULL;
4923 ifactory = gtk_item_factory_from_widget(compose->menubar);
4925 switch (compose->priority) {
4926 case PRIORITY_HIGHEST:
4927 menuitem = gtk_item_factory_get_item
4928 (ifactory, "/Options/Priority/Highest");
4931 menuitem = gtk_item_factory_get_item
4932 (ifactory, "/Options/Priority/High");
4934 case PRIORITY_NORMAL:
4935 menuitem = gtk_item_factory_get_item
4936 (ifactory, "/Options/Priority/Normal");
4939 menuitem = gtk_item_factory_get_item
4940 (ifactory, "/Options/Priority/Low");
4942 case PRIORITY_LOWEST:
4943 menuitem = gtk_item_factory_get_item
4944 (ifactory, "/Options/Priority/Lowest");
4947 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4950 static void compose_set_privacy_system_cb(gpointer data,
4954 Compose *compose = (Compose *) data;
4956 GtkItemFactory *ifactory;
4957 gboolean can_sign = FALSE, can_encrypt = FALSE;
4959 systemid = gtk_object_get_data(GTK_OBJECT(widget), "privacy_system");
4960 g_free(compose->privacy_system);
4961 compose->privacy_system = NULL;
4962 if (systemid != NULL) {
4963 compose->privacy_system = g_strdup(systemid);
4965 can_sign = privacy_system_can_sign(systemid);
4966 can_encrypt = privacy_system_can_encrypt(systemid);
4969 ifactory = gtk_item_factory_from_widget(compose->menubar);
4970 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
4971 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
4974 static void compose_update_privacy_system_menu_item(Compose * compose)
4976 static gchar *branch_path = "/Options/Privacy System";
4977 GtkItemFactory *ifactory;
4978 GtkWidget *menuitem = NULL;
4980 gboolean can_sign = FALSE, can_encrypt = FALSE;
4982 ifactory = gtk_item_factory_from_widget(compose->menubar);
4984 if (compose->privacy_system != NULL) {
4987 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
4988 g_return_if_fail(menuitem != NULL);
4990 amenu = GTK_MENU_SHELL(menuitem)->children;
4992 while (amenu != NULL) {
4993 GList *alist = amenu->next;
4995 systemid = gtk_object_get_data(GTK_OBJECT(amenu->data), "privacy_system");
4996 if (systemid != NULL)
4997 if (strcmp(systemid, compose->privacy_system) == 0) {
4998 menuitem = GTK_WIDGET(amenu->data);
5000 can_sign = privacy_system_can_sign(systemid);
5001 can_encrypt = privacy_system_can_encrypt(systemid);
5008 if (menuitem != NULL)
5009 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5012 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5013 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5016 static void compose_set_template_menu(Compose *compose)
5018 GSList *tmpl_list, *cur;
5022 tmpl_list = template_get_config();
5024 menu = gtk_menu_new();
5026 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5027 Template *tmpl = (Template *)cur->data;
5029 item = gtk_menu_item_new_with_label(tmpl->name);
5030 gtk_menu_append(GTK_MENU(menu), item);
5031 gtk_signal_connect(GTK_OBJECT(item), "activate",
5032 GTK_SIGNAL_FUNC(compose_template_activate_cb),
5034 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
5035 gtk_widget_show(item);
5038 gtk_widget_show(menu);
5039 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5042 void compose_update_actions_menu(Compose *compose)
5044 GtkItemFactory *ifactory;
5046 ifactory = gtk_item_factory_from_widget(compose->menubar);
5047 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5050 void compose_update_privacy_systems_menu(Compose *compose)
5052 static gchar *branch_path = "/Options/Privacy System";
5053 GtkItemFactory *ifactory;
5054 GtkWidget *menuitem;
5056 GSList *systems, *cur;
5058 GtkItemFactoryEntry ifentry = {NULL, NULL, NULL, 0, "<Branch>"};
5061 ifactory = gtk_item_factory_from_widget(compose->menubar);
5063 /* remove old entries */
5064 ifentry.path = branch_path;
5065 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5066 g_return_if_fail(menuitem != NULL);
5068 amenu = GTK_MENU_SHELL(menuitem)->children->next;
5069 while (amenu != NULL) {
5070 GList *alist = amenu->next;
5071 gtk_widget_destroy(GTK_WIDGET(amenu->data));
5075 ifentry.accelerator = NULL;
5076 ifentry.callback_action = 0;
5077 ifentry.callback = compose_set_privacy_system_cb;
5078 ifentry.item_type = "/Options/Privacy System/None";
5080 systems = privacy_get_system_ids();
5081 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
5082 gchar *systemid = cur->data;
5084 menu_path = g_strdup_printf("%s/%s", branch_path,
5085 privacy_system_get_name(systemid));
5086 ifentry.path = menu_path;
5087 gtk_item_factory_create_item(ifactory, &ifentry, compose, 1);
5088 widget = gtk_item_factory_get_widget(ifactory, menu_path);
5090 gtk_object_set_data_full(GTK_OBJECT(widget), "privacy_system",
5091 g_strdup(systemid), g_free);
5096 g_slist_free(systems);
5099 void compose_reflect_prefs_all(void)
5104 for (cur = compose_list; cur != NULL; cur = cur->next) {
5105 compose = (Compose *)cur->data;
5106 compose_set_template_menu(compose);
5110 void compose_reflect_prefs_pixmap_theme(void)
5115 for (cur = compose_list; cur != NULL; cur = cur->next) {
5116 compose = (Compose *)cur->data;
5117 toolbar_update(TOOLBAR_COMPOSE, compose);
5121 static void compose_template_apply(Compose *compose, Template *tmpl,
5127 if (!tmpl || !tmpl->value) return;
5129 gtk_stext_freeze(GTK_STEXT(compose->text));
5131 if (tmpl->subject && *tmpl->subject != '\0')
5132 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5134 if (tmpl->to && *tmpl->to != '\0')
5135 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5136 if (tmpl->cc && *tmpl->cc != '\0')
5137 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5139 if (tmpl->bcc && *tmpl->bcc != '\0')
5140 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5143 gtkut_stext_clear(GTK_STEXT(compose->text));
5145 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
5146 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5149 if (prefs_common.quotemark && *prefs_common.quotemark)
5150 qmark = prefs_common.quotemark;
5154 if (compose->replyinfo != NULL)
5155 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5156 tmpl->value, qmark, NULL);
5157 else if (compose->fwdinfo != NULL)
5158 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
5159 tmpl->value, qmark, NULL);
5164 if (replace && parsed_str && compose->account->auto_sig)
5165 compose_insert_sig(compose, FALSE);
5167 if (replace && parsed_str) {
5168 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
5169 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
5173 compose_changed_cb(NULL, compose);
5175 gtk_stext_thaw(GTK_STEXT(compose->text));
5178 static void compose_destroy(Compose *compose)
5181 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5184 /* NOTE: address_completion_end() does nothing with the window
5185 * however this may change. */
5186 address_completion_end(compose->window);
5188 slist_free_strings(compose->to_list);
5189 g_slist_free(compose->to_list);
5190 slist_free_strings(compose->newsgroup_list);
5191 g_slist_free(compose->newsgroup_list);
5192 slist_free_strings(compose->header_list);
5193 g_slist_free(compose->header_list);
5195 procmsg_msginfo_free(compose->targetinfo);
5196 procmsg_msginfo_free(compose->replyinfo);
5197 procmsg_msginfo_free(compose->fwdinfo);
5199 g_free(compose->replyto);
5200 g_free(compose->cc);
5201 g_free(compose->bcc);
5202 g_free(compose->newsgroups);
5203 g_free(compose->followup_to);
5205 g_free(compose->ml_post);
5207 g_free(compose->inreplyto);
5208 g_free(compose->references);
5209 g_free(compose->msgid);
5210 g_free(compose->boundary);
5212 if (compose->redirect_filename)
5213 g_free(compose->redirect_filename);
5214 if (compose->undostruct)
5215 undo_destroy(compose->undostruct);
5217 g_free(compose->sig_str);
5219 g_free(compose->exteditor_file);
5221 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5223 compose_attach_info_free(ainfo);
5225 if (addressbook_get_target_compose() == compose)
5226 addressbook_set_target_compose(NULL);
5229 if (compose->gtkaspell) {
5230 gtkaspell_delete(compose->gtkaspell);
5234 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5235 prefs_common.compose_height = compose->window->allocation.height;
5237 gtk_widget_destroy(compose->paned);
5239 toolbar_destroy(compose->toolbar);
5240 g_free(compose->toolbar);
5243 compose_list = g_list_remove(compose_list, compose);
5246 static void compose_attach_info_free(AttachInfo *ainfo)
5248 g_free(ainfo->file);
5249 g_free(ainfo->content_type);
5250 g_free(ainfo->name);
5254 static void compose_attach_remove_selected(Compose *compose)
5256 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5260 while (clist->selection != NULL) {
5261 row = GPOINTER_TO_INT(clist->selection->data);
5262 ainfo = gtk_clist_get_row_data(clist, row);
5263 compose_attach_info_free(ainfo);
5264 gtk_clist_remove(clist, row);
5268 static struct _AttachProperty
5271 GtkWidget *mimetype_entry;
5272 GtkWidget *encoding_optmenu;
5273 GtkWidget *path_entry;
5274 GtkWidget *filename_entry;
5276 GtkWidget *cancel_btn;
5279 static void compose_attach_property(Compose *compose)
5281 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5284 GtkOptionMenu *optmenu;
5285 static gboolean cancelled;
5287 if (!clist->selection) return;
5288 row = GPOINTER_TO_INT(clist->selection->data);
5290 ainfo = gtk_clist_get_row_data(clist, row);
5293 if (!attach_prop.window)
5294 compose_attach_property_create(&cancelled);
5295 gtk_widget_grab_focus(attach_prop.ok_btn);
5296 gtk_widget_show(attach_prop.window);
5297 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5299 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5300 if (ainfo->encoding == ENC_UNKNOWN)
5301 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5302 GINT_TO_POINTER(ENC_BASE64));
5304 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5305 GINT_TO_POINTER(ainfo->encoding));
5307 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5308 ainfo->content_type ? ainfo->content_type : "");
5309 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5310 ainfo->file ? ainfo->file : "");
5311 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5312 ainfo->name ? ainfo->name : "");
5316 gchar *cnttype = NULL;
5320 GtkWidget *menuitem;
5325 if (cancelled == TRUE) {
5326 gtk_widget_hide(attach_prop.window);
5330 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5331 if (*text != '\0') {
5334 text = g_strstrip(g_strdup(text));
5335 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5336 cnttype = g_strdup(text);
5339 alertpanel_error(_("Invalid MIME type."));
5345 menu = gtk_option_menu_get_menu(optmenu);
5346 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5347 ainfo->encoding = GPOINTER_TO_INT
5348 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5350 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5351 if (*text != '\0') {
5352 if (is_file_exist(text) &&
5353 (size = get_file_size(text)) > 0)
5354 file = g_strdup(text);
5357 (_("File doesn't exist or is empty."));
5363 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5364 if (*text != '\0') {
5365 g_free(ainfo->name);
5366 ainfo->name = g_strdup(text);
5370 g_free(ainfo->content_type);
5371 ainfo->content_type = cnttype;
5374 g_free(ainfo->file);
5380 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5381 ainfo->content_type);
5382 gtk_clist_set_text(clist, row, COL_SIZE,
5383 to_human_readable(ainfo->size));
5384 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5386 gtk_widget_hide(attach_prop.window);
5391 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5393 label = gtk_label_new(str); \
5394 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5395 GTK_FILL, 0, 0, 0); \
5396 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5398 entry = gtk_entry_new(); \
5399 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5400 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5403 static void compose_attach_property_create(gboolean *cancelled)
5409 GtkWidget *mimetype_entry;
5412 GtkWidget *optmenu_menu;
5413 GtkWidget *menuitem;
5414 GtkWidget *path_entry;
5415 GtkWidget *filename_entry;
5418 GtkWidget *cancel_btn;
5419 GList *mime_type_list, *strlist;
5421 debug_print("Creating attach_property window...\n");
5423 window = gtk_window_new(GTK_WINDOW_DIALOG);
5424 gtk_widget_set_usize(window, 480, -1);
5425 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5426 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
5427 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5428 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5429 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5430 GTK_SIGNAL_FUNC(attach_property_delete_event),
5432 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5433 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5436 vbox = gtk_vbox_new(FALSE, 8);
5437 gtk_container_add(GTK_CONTAINER(window), vbox);
5439 table = gtk_table_new(4, 2, FALSE);
5440 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5441 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5442 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5444 label = gtk_label_new(_("MIME type"));
5445 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5447 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5448 mimetype_entry = gtk_combo_new();
5449 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5450 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5452 /* stuff with list */
5453 mime_type_list = procmime_get_mime_type_list();
5455 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5456 MimeType *type = (MimeType *) mime_type_list->data;
5457 strlist = g_list_append(strlist,
5458 g_strdup_printf("%s/%s",
5459 type->type, type->sub_type));
5462 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5464 for (mime_type_list = strlist; mime_type_list != NULL;
5465 mime_type_list = mime_type_list->next)
5466 g_free(mime_type_list->data);
5467 g_list_free(strlist);
5469 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5471 label = gtk_label_new(_("Encoding"));
5472 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5474 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5476 hbox = gtk_hbox_new(FALSE, 0);
5477 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5478 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5480 optmenu = gtk_option_menu_new();
5481 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5483 optmenu_menu = gtk_menu_new();
5484 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5485 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5487 gtk_widget_set_sensitive(menuitem, FALSE);
5489 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5490 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5492 gtk_widget_set_sensitive(menuitem, FALSE);
5494 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
5495 ENC_QUOTED_PRINTABLE);
5496 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5498 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5500 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5502 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5503 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5505 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5506 &cancel_btn, _("Cancel"), NULL, NULL);
5507 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5508 gtk_widget_grab_default(ok_btn);
5510 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5511 GTK_SIGNAL_FUNC(attach_property_ok),
5513 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5514 GTK_SIGNAL_FUNC(attach_property_cancel),
5517 gtk_widget_show_all(vbox);
5519 attach_prop.window = window;
5520 attach_prop.mimetype_entry = mimetype_entry;
5521 attach_prop.encoding_optmenu = optmenu;
5522 attach_prop.path_entry = path_entry;
5523 attach_prop.filename_entry = filename_entry;
5524 attach_prop.ok_btn = ok_btn;
5525 attach_prop.cancel_btn = cancel_btn;
5528 #undef SET_LABEL_AND_ENTRY
5530 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5536 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5542 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5543 gboolean *cancelled)
5551 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5552 gboolean *cancelled)
5554 if (event && event->keyval == GDK_Escape) {
5560 static void compose_exec_ext_editor(Compose *compose)
5566 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
5567 G_DIR_SEPARATOR, compose);
5569 if (pipe(pipe_fds) < 0) {
5575 if ((pid = fork()) < 0) {
5582 /* close the write side of the pipe */
5585 compose->exteditor_file = g_strdup(tmp);
5586 compose->exteditor_pid = pid;
5587 compose->exteditor_readdes = pipe_fds[0];
5589 compose_set_ext_editor_sensitive(compose, FALSE);
5591 compose->exteditor_tag =
5592 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5593 compose_input_cb, compose);
5594 } else { /* process-monitoring process */
5600 /* close the read side of the pipe */
5603 if (compose_write_body_to_file(compose, tmp) < 0) {
5604 fd_write_all(pipe_fds[1], "2\n", 2);
5608 pid_ed = compose_exec_ext_editor_real(tmp);
5610 fd_write_all(pipe_fds[1], "1\n", 2);
5614 /* wait until editor is terminated */
5615 waitpid(pid_ed, NULL, 0);
5617 fd_write_all(pipe_fds[1], "0\n", 2);
5626 static gint compose_exec_ext_editor_real(const gchar *file)
5628 static gchar *def_cmd = "emacs %s";
5634 g_return_val_if_fail(file != NULL, -1);
5636 if ((pid = fork()) < 0) {
5641 if (pid != 0) return pid;
5643 /* grandchild process */
5645 if (setpgid(0, getppid()))
5648 if (prefs_common.ext_editor_cmd &&
5649 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5650 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5651 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5653 if (prefs_common.ext_editor_cmd)
5654 g_warning("External editor command line is invalid: `%s'\n",
5655 prefs_common.ext_editor_cmd);
5656 g_snprintf(buf, sizeof(buf), def_cmd, file);
5659 cmdline = strsplit_with_quote(buf, " ", 1024);
5660 execvp(cmdline[0], cmdline);
5663 g_strfreev(cmdline);
5668 static gboolean compose_ext_editor_kill(Compose *compose)
5670 pid_t pgid = compose->exteditor_pid * -1;
5673 ret = kill(pgid, 0);
5675 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5679 msg = g_strdup_printf
5680 (_("The external editor is still working.\n"
5681 "Force terminating the process?\n"
5682 "process group id: %d"), -pgid);
5683 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5686 if (val == G_ALERTDEFAULT) {
5687 gdk_input_remove(compose->exteditor_tag);
5688 close(compose->exteditor_readdes);
5690 if (kill(pgid, SIGTERM) < 0) perror("kill");
5691 waitpid(compose->exteditor_pid, NULL, 0);
5693 g_warning("Terminated process group id: %d", -pgid);
5694 g_warning("Temporary file: %s",
5695 compose->exteditor_file);
5697 compose_set_ext_editor_sensitive(compose, TRUE);
5699 g_free(compose->exteditor_file);
5700 compose->exteditor_file = NULL;
5701 compose->exteditor_pid = -1;
5702 compose->exteditor_readdes = -1;
5703 compose->exteditor_tag = -1;
5711 static void compose_input_cb(gpointer data, gint source,
5712 GdkInputCondition condition)
5715 Compose *compose = (Compose *)data;
5718 debug_print("Compose: input from monitoring process\n");
5720 gdk_input_remove(compose->exteditor_tag);
5723 if (read(source, &buf[i], 1) < 1) {
5727 if (buf[i] == '\n') {
5732 if (i == sizeof(buf) - 1)
5736 waitpid(compose->exteditor_pid, NULL, 0);
5738 if (buf[0] == '0') { /* success */
5739 GtkSText *text = GTK_STEXT(compose->text);
5741 gtk_stext_freeze(text);
5742 gtk_stext_set_point(text, 0);
5743 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5744 compose_insert_file(compose, compose->exteditor_file);
5745 compose_changed_cb(NULL, compose);
5746 gtk_stext_thaw(text);
5748 if (unlink(compose->exteditor_file) < 0)
5749 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5750 } else if (buf[0] == '1') { /* failed */
5751 g_warning("Couldn't exec external editor\n");
5752 if (unlink(compose->exteditor_file) < 0)
5753 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5754 } else if (buf[0] == '2') {
5755 g_warning("Couldn't write to file\n");
5756 } else if (buf[0] == '3') {
5757 g_warning("Pipe read failed\n");
5762 compose_set_ext_editor_sensitive(compose, TRUE);
5764 g_free(compose->exteditor_file);
5765 compose->exteditor_file = NULL;
5766 compose->exteditor_pid = -1;
5767 compose->exteditor_readdes = -1;
5768 compose->exteditor_tag = -1;
5771 static void compose_set_ext_editor_sensitive(Compose *compose,
5774 GtkItemFactory *ifactory;
5776 ifactory = gtk_item_factory_from_widget(compose->menubar);
5778 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5779 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5780 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
5781 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
5782 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5783 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5784 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5787 gtk_widget_set_sensitive(compose->text, sensitive);
5788 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
5789 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
5790 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
5791 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
5792 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
5793 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
5794 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
5795 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
5799 * compose_undo_state_changed:
5801 * Change the sensivity of the menuentries undo and redo
5803 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5804 gint redo_state, gpointer data)
5806 GtkWidget *widget = GTK_WIDGET(data);
5807 GtkItemFactory *ifactory;
5809 g_return_if_fail(widget != NULL);
5811 ifactory = gtk_item_factory_from_widget(widget);
5813 switch (undo_state) {
5814 case UNDO_STATE_TRUE:
5815 if (!undostruct->undo_state) {
5816 undostruct->undo_state = TRUE;
5817 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5820 case UNDO_STATE_FALSE:
5821 if (undostruct->undo_state) {
5822 undostruct->undo_state = FALSE;
5823 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5826 case UNDO_STATE_UNCHANGED:
5828 case UNDO_STATE_REFRESH:
5829 menu_set_sensitive(ifactory, "/Edit/Undo",
5830 undostruct->undo_state);
5833 g_warning("Undo state not recognized");
5837 switch (redo_state) {
5838 case UNDO_STATE_TRUE:
5839 if (!undostruct->redo_state) {
5840 undostruct->redo_state = TRUE;
5841 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5844 case UNDO_STATE_FALSE:
5845 if (undostruct->redo_state) {
5846 undostruct->redo_state = FALSE;
5847 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5850 case UNDO_STATE_UNCHANGED:
5852 case UNDO_STATE_REFRESH:
5853 menu_set_sensitive(ifactory, "/Edit/Redo",
5854 undostruct->redo_state);
5857 g_warning("Redo state not recognized");
5862 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5866 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5867 cursor_pos = MAX(cursor_pos, 0);
5872 /* callback functions */
5874 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5875 * includes "non-client" (windows-izm) in calculation, so this calculation
5876 * may not be accurate.
5878 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5879 GtkAllocation *allocation,
5880 GtkSHRuler *shruler)
5882 if (prefs_common.show_ruler) {
5884 gint line_width_in_chars;
5886 char_width = gtkut_get_font_width
5887 (GTK_WIDGET(widget)->style->font);
5888 line_width_in_chars =
5889 (allocation->width - allocation->x) / char_width;
5891 /* got the maximum */
5892 gtk_ruler_set_range(GTK_RULER(shruler),
5893 0.0, line_width_in_chars,
5894 calc_cursor_xpos(GTK_STEXT(widget),
5897 /*line_width_in_chars*/ char_width);
5903 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5905 Compose *compose = (Compose *)data;
5908 gchar *folderidentifier;
5910 ac = account_find_from_id(
5911 GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menuitem))));
5912 g_return_if_fail(ac != NULL);
5914 if (ac != compose->account)
5915 compose_select_account(compose, ac, FALSE);
5917 /* Set message save folder */
5918 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5919 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
5921 gtk_signal_connect(GTK_OBJECT(compose->savemsg_checkbtn), "toggled",
5922 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
5924 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
5925 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5926 folderidentifier = folder_item_get_identifier(account_get_special_folder
5927 (compose->account, F_OUTBOX));
5928 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
5929 g_free(folderidentifier);
5933 static void attach_selected(GtkCList *clist, gint row, gint column,
5934 GdkEvent *event, gpointer data)
5936 Compose *compose = (Compose *)data;
5938 if (event && event->type == GDK_2BUTTON_PRESS)
5939 compose_attach_property(compose);
5942 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5945 Compose *compose = (Compose *)data;
5946 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5951 if (event->button == 3) {
5952 if ((clist->selection && !clist->selection->next) ||
5953 !clist->selection) {
5954 gtk_clist_unselect_all(clist);
5955 if (gtk_clist_get_selection_info(clist,
5958 gtk_clist_select_row(clist, row, column);
5959 gtkut_clist_set_focus_row(clist, row);
5962 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5963 NULL, NULL, event->button, event->time);
5967 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5970 Compose *compose = (Compose *)data;
5974 switch (event->keyval) {
5976 compose_attach_remove_selected(compose);
5981 static void compose_allow_user_actions (Compose *compose, gboolean allow)
5983 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
5984 toolbar_comp_set_sensitive(compose, allow);
5985 menu_set_sensitive(ifactory, "/Message", allow);
5986 menu_set_sensitive(ifactory, "/Edit", allow);
5988 menu_set_sensitive(ifactory, "/Spelling", allow);
5990 menu_set_sensitive(ifactory, "/Options", allow);
5991 menu_set_sensitive(ifactory, "/Tools", allow);
5992 menu_set_sensitive(ifactory, "/Help", allow);
5995 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5997 Compose *compose = (Compose *)data;
5999 if (prefs_common.work_offline)
6000 if (alertpanel(_("Offline warning"),
6001 _("You're working offline. Override?"),
6002 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
6005 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
6006 gtk_timeout_remove(compose->draft_timeout_tag);
6007 compose->draft_timeout_tag = -1;
6010 compose_send(compose);
6013 static void compose_send_later_cb(gpointer data, guint action,
6016 Compose *compose = (Compose *)data;
6019 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6020 if (!val) gtk_widget_destroy(compose->window);
6023 void compose_draft (gpointer data)
6025 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6028 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6030 Compose *compose = (Compose *)data;
6034 MsgFlags flag = {0, 0};
6035 static gboolean lock = FALSE;
6036 MsgInfo *newmsginfo;
6041 draft = account_get_special_folder(compose->account, F_DRAFT);
6042 g_return_if_fail(draft != NULL);
6046 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
6047 G_DIR_SEPARATOR, compose);
6048 if ((fp = fopen(tmp, "wb")) == NULL) {
6049 FILE_OP_ERROR(tmp, "fopen");
6053 /* chmod for security */
6054 if (change_file_mode_rw(fp, tmp) < 0) {
6055 FILE_OP_ERROR(tmp, "chmod");
6056 g_warning("can't change file mode\n");
6059 /* Save draft infos */
6060 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
6061 fprintf(fp, "S:%s\n", compose->account->address);
6062 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
6063 gchar *savefolderid;
6065 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6066 fprintf(fp, "SCF:%s\n", savefolderid);
6067 g_free(savefolderid);
6069 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
6070 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
6071 fprintf(fp, "X-Sylpheed-Gnupg-Mode:%s\n", compose->privacy_system);
6074 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
6083 folder_item_scan(draft);
6084 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
6091 draft->mtime = 0; /* force updating */
6093 if (compose->mode == COMPOSE_REEDIT) {
6094 compose_remove_reedit_target(compose);
6097 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6099 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6100 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
6101 if (compose_use_attach(compose))
6102 procmsg_msginfo_set_flags(newmsginfo, 0,
6103 MSG_HAS_ATTACHMENT);
6105 procmsg_msginfo_free(newmsginfo);
6108 folder_item_scan(draft);
6112 if (action == COMPOSE_QUIT_EDITING)
6113 gtk_widget_destroy(compose->window);
6118 path = folder_item_fetch_msg(draft, msgnum);
6119 g_return_if_fail(path != NULL);
6120 if (stat(path, &s) < 0) {
6121 FILE_OP_ERROR(path, "stat");
6128 procmsg_msginfo_free(compose->targetinfo);
6129 compose->targetinfo = procmsg_msginfo_new();
6130 compose->targetinfo->msgnum = msgnum;
6131 compose->targetinfo->size = s.st_size;
6132 compose->targetinfo->mtime = s.st_mtime;
6133 compose->targetinfo->folder = draft;
6134 compose->mode = COMPOSE_REEDIT;
6136 if (action == COMPOSE_AUTO_SAVE) {
6137 compose->autosaved_draft = compose->targetinfo;
6142 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6144 Compose *compose = (Compose *)data;
6147 if (compose->redirect_filename != NULL)
6150 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6155 for ( tmp = file_list; tmp; tmp = tmp->next) {
6156 gchar *file = (gchar *) tmp->data;
6157 compose_attach_append(compose, file, file, NULL);
6158 compose_changed_cb(NULL, compose);
6161 g_list_free(file_list);
6165 static void compose_insert_file_cb(gpointer data, guint action,
6168 Compose *compose = (Compose *)data;
6171 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6176 for ( tmp = file_list; tmp; tmp = tmp->next) {
6177 gchar *file = (gchar *) tmp->data;
6178 gchar *filedup = g_strdup(file);
6180 ComposeInsertResult res;
6182 res = compose_insert_file(compose, file);
6183 shortfile = g_basename(filedup);
6184 if (res == COMPOSE_INSERT_READ_ERROR) {
6185 alertpanel_error(_("File '%s' could not be read."), shortfile);
6186 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
6187 alertpanel_error(_("File '%s' contained invalid characters\n"
6188 "for the current encoding, insertion may be incorrect."), shortfile);
6193 g_list_free(file_list);
6197 static void compose_insert_sig_cb(gpointer data, guint action,
6200 Compose *compose = (Compose *)data;
6202 compose_insert_sig(compose, FALSE);
6205 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6209 Compose *compose = (Compose *)data;
6211 gtkut_widget_get_uposition(widget, &x, &y);
6212 prefs_common.compose_x = x;
6213 prefs_common.compose_y = y;
6215 if (compose->sending)
6217 compose_close_cb(compose, 0, NULL);
6221 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6223 Compose *compose = (Compose *)data;
6226 if (compose->exteditor_tag != -1) {
6227 if (!compose_ext_editor_kill(compose))
6231 if (compose->modified) {
6232 val = alertpanel(_("Discard message"),
6233 _("This message has been modified. discard it?"),
6234 _("Discard"), _("to Draft"), _("Cancel"));
6237 case G_ALERTDEFAULT:
6238 if (prefs_common.autosave)
6239 compose_remove_draft(compose);
6241 case G_ALERTALTERNATE:
6242 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6249 gtk_widget_destroy(compose->window);
6252 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6254 Compose *compose = (Compose *)data;
6256 addressbook_open(compose);
6259 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6261 Compose *compose = (Compose *)data;
6266 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6267 g_return_if_fail(tmpl != NULL);
6269 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6271 val = alertpanel(_("Apply template"), msg,
6272 _("Replace"), _("Insert"), _("Cancel"));
6275 if (val == G_ALERTDEFAULT)
6276 compose_template_apply(compose, tmpl, TRUE);
6277 else if (val == G_ALERTALTERNATE)
6278 compose_template_apply(compose, tmpl, FALSE);
6281 static void compose_ext_editor_cb(gpointer data, guint action,
6284 Compose *compose = (Compose *)data;
6286 compose_exec_ext_editor(compose);
6289 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6291 if (compose->sending)
6293 compose_destroy(compose);
6296 static void compose_undo_cb(Compose *compose)
6298 undo_undo(compose->undostruct);
6301 static void compose_redo_cb(Compose *compose)
6303 undo_redo(compose->undostruct);
6306 static void compose_cut_cb(Compose *compose)
6308 if (compose->focused_editable &&
6309 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6310 gtk_editable_cut_clipboard
6311 (GTK_EDITABLE(compose->focused_editable));
6314 static void compose_copy_cb(Compose *compose)
6316 if (compose->focused_editable &&
6317 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6318 gtk_editable_copy_clipboard
6319 (GTK_EDITABLE(compose->focused_editable));
6322 static void compose_paste_cb(Compose *compose)
6324 if (compose->focused_editable &&
6325 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6326 gtk_editable_paste_clipboard
6327 (GTK_EDITABLE(compose->focused_editable));
6330 static void compose_paste_as_quote_cb(Compose *compose)
6332 if (compose->focused_editable &&
6333 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6334 /* let text_insert() (called directly or at a later time
6335 * after the gtk_editable_paste_clipboard) know that
6336 * text is to be inserted as a quotation. implemented
6337 * by using a simple refcount... */
6338 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data(
6339 GTK_OBJECT(compose->focused_editable),
6340 "paste_as_quotation"));
6341 gtk_object_set_data(GTK_OBJECT(compose->focused_editable),
6342 "paste_as_quotation",
6343 GINT_TO_POINTER(paste_as_quotation + 1));
6344 gtk_editable_paste_clipboard
6345 (GTK_EDITABLE(compose->focused_editable));
6349 static void compose_allsel_cb(Compose *compose)
6351 if (compose->focused_editable &&
6352 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6353 gtk_editable_select_region
6354 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6357 static void compose_gtk_stext_action_cb(Compose *compose,
6358 ComposeCallGtkSTextAction action)
6360 GtkSText *text = GTK_STEXT(compose->text);
6362 void (*do_action) (GtkSText *text);
6363 } action_table[] = {
6364 {gtk_stext_move_beginning_of_line},
6365 {gtk_stext_move_forward_character},
6366 {gtk_stext_move_backward_character},
6367 {gtk_stext_move_forward_word},
6368 {gtk_stext_move_backward_word},
6369 {gtk_stext_move_end_of_line},
6370 {gtk_stext_move_next_line},
6371 {gtk_stext_move_previous_line},
6372 {gtk_stext_delete_forward_character},
6373 {gtk_stext_delete_backward_character},
6374 {gtk_stext_delete_forward_word},
6375 {gtk_stext_delete_backward_word},
6376 {gtk_stext_delete_line},
6377 {gtk_stext_delete_line}, /* gtk_stext_delete_line_n */
6378 {gtk_stext_delete_to_line_end}
6381 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
6383 if (action >= COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE &&
6384 action <= COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END)
6385 action_table[action].do_action(text);
6388 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6390 if (GTK_IS_EDITABLE(widget))
6391 compose->focused_editable = widget;
6394 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6396 if (compose->modified == FALSE) {
6397 compose->modified = TRUE;
6398 compose_set_title(compose);
6402 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6405 gtk_stext_set_point(GTK_STEXT(widget),
6406 gtk_editable_get_position(GTK_EDITABLE(widget)));
6410 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6413 gtk_stext_set_point(GTK_STEXT(widget),
6414 gtk_editable_get_position(GTK_EDITABLE(widget)));
6418 static void compose_toggle_autowrap_cb(gpointer data, guint action,
6421 Compose *compose = (Compose *)data;
6423 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
6424 if (compose->autowrap)
6425 compose_wrap_line_all_full(compose, TRUE);
6428 static void compose_toggle_sign_cb(gpointer data, guint action,
6431 Compose *compose = (Compose *)data;
6433 if (GTK_CHECK_MENU_ITEM(widget)->active)
6434 compose->use_signing = TRUE;
6436 compose->use_signing = FALSE;
6439 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6442 Compose *compose = (Compose *)data;
6444 if (GTK_CHECK_MENU_ITEM(widget)->active)
6445 compose->use_encryption = TRUE;
6447 compose->use_encryption = FALSE;
6450 static void activate_privacy_system(Compose *compose, PrefsAccount *account)
6453 if (account->default_gnupg_mode)
6454 compose->gnupg_mode = GNUPG_MODE_INLINE;
6456 compose->gnupg_mode = GNUPG_MODE_DETACH;
6458 compose_update_privacy_system_menu_item(compose);
6461 static void compose_toggle_ruler_cb(gpointer data, guint action,
6464 Compose *compose = (Compose *)data;
6466 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6467 gtk_widget_show(compose->ruler_hbox);
6468 prefs_common.show_ruler = TRUE;
6470 gtk_widget_hide(compose->ruler_hbox);
6471 gtk_widget_queue_resize(compose->edit_vbox);
6472 prefs_common.show_ruler = FALSE;
6476 static void compose_attach_drag_received_cb (GtkWidget *widget,
6477 GdkDragContext *drag_context,
6480 GtkSelectionData *data,
6485 Compose *compose = (Compose *)user_data;
6488 list = uri_list_extract_filenames((const gchar *)data->data);
6489 for (tmp = list; tmp != NULL; tmp = tmp->next)
6490 compose_attach_append
6491 (compose, (const gchar *)tmp->data,
6492 (const gchar *)tmp->data, NULL);
6493 if (list) compose_changed_cb(NULL, compose);
6494 list_free_strings(list);
6498 static void compose_insert_drag_received_cb (GtkWidget *widget,
6499 GdkDragContext *drag_context,
6502 GtkSelectionData *data,
6507 Compose *compose = (Compose *)user_data;
6510 list = uri_list_extract_filenames((const gchar *)data->data);
6511 for (tmp = list; tmp != NULL; tmp = tmp->next)
6512 compose_insert_file(compose, (const gchar *)tmp->data);
6513 list_free_strings(list);
6517 #if 0 /* NEW COMPOSE GUI */
6518 static void to_activated(GtkWidget *widget, Compose *compose)
6520 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6521 gtk_widget_grab_focus(compose->newsgroups_entry);
6523 gtk_widget_grab_focus(compose->subject_entry);
6526 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6528 gtk_widget_grab_focus(compose->subject_entry);
6531 static void subject_activated(GtkWidget *widget, Compose *compose)
6533 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6534 gtk_widget_grab_focus(compose->cc_entry);
6535 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6536 gtk_widget_grab_focus(compose->bcc_entry);
6537 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6538 gtk_widget_grab_focus(compose->reply_entry);
6539 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6540 gtk_widget_grab_focus(compose->followup_entry);
6542 gtk_widget_grab_focus(compose->text);
6545 static void cc_activated(GtkWidget *widget, Compose *compose)
6547 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6548 gtk_widget_grab_focus(compose->bcc_entry);
6549 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6550 gtk_widget_grab_focus(compose->reply_entry);
6551 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6552 gtk_widget_grab_focus(compose->followup_entry);
6554 gtk_widget_grab_focus(compose->text);
6557 static void bcc_activated(GtkWidget *widget, Compose *compose)
6559 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6560 gtk_widget_grab_focus(compose->reply_entry);
6561 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6562 gtk_widget_grab_focus(compose->followup_entry);
6564 gtk_widget_grab_focus(compose->text);
6567 static void replyto_activated(GtkWidget *widget, Compose *compose)
6569 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6570 gtk_widget_grab_focus(compose->followup_entry);
6572 gtk_widget_grab_focus(compose->text);
6575 static void followupto_activated(GtkWidget *widget, Compose *compose)
6577 gtk_widget_grab_focus(compose->text);
6581 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6584 Compose *compose = (Compose *)data;
6586 if (GTK_CHECK_MENU_ITEM(widget)->active)
6587 compose->return_receipt = TRUE;
6589 compose->return_receipt = FALSE;
6592 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
6595 Compose *compose = (Compose *)data;
6597 if (GTK_CHECK_MENU_ITEM(widget)->active)
6598 compose->remove_references = TRUE;
6600 compose->remove_references = FALSE;
6603 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6605 ComposeHeaderEntry *headerentry)
6607 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6608 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6609 !(event->state & GDK_MODIFIER_MASK) &&
6610 (event->keyval == GDK_BackSpace) &&
6611 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6612 gtk_container_remove
6613 (GTK_CONTAINER(headerentry->compose->header_table),
6614 headerentry->combo);
6615 gtk_container_remove
6616 (GTK_CONTAINER(headerentry->compose->header_table),
6617 headerentry->entry);
6618 headerentry->compose->header_list =
6619 g_slist_remove(headerentry->compose->header_list,
6621 g_free(headerentry);
6622 } else if (event->keyval == GDK_Tab) {
6623 if (headerentry->compose->header_last == headerentry) {
6624 /* Override default next focus, and give it to subject_entry
6625 * instead of notebook tabs
6627 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6628 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6634 void compose_headerentry_changed_cb(GtkWidget *entry,
6635 ComposeHeaderEntry *headerentry)
6637 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6638 headerentry->compose->header_list =
6639 g_slist_append(headerentry->compose->header_list,
6641 compose_create_header_entry(headerentry->compose);
6642 gtk_signal_disconnect_by_func
6644 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6646 /* Automatically scroll down */
6647 compose_show_first_last_header(headerentry->compose, FALSE);
6652 static gboolean compose_headerentry_button_pressed
6653 (GtkWidget *entry, GdkEventButton *event, gpointer data)
6655 /* if this is a lclick, grab the focus */
6656 if (event->button == 1)
6657 gtk_widget_grab_focus(entry);
6661 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6663 GtkAdjustment *vadj;
6665 g_return_if_fail(compose);
6666 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6667 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6669 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6670 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6673 static void text_activated(GtkWidget *widget, Compose *compose)
6675 compose_send_control_enter(compose);
6678 static void text_inserted(GtkWidget *widget, const gchar *text,
6679 gint length, gint *position, Compose *compose)
6681 GtkEditable *editable = GTK_EDITABLE(widget);
6682 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data
6683 (GTK_OBJECT(widget), "paste_as_quotation"));
6685 gtk_signal_handler_block_by_func(GTK_OBJECT(widget),
6686 GTK_SIGNAL_FUNC(text_inserted),
6688 if (paste_as_quotation) {
6693 new_text = g_strndup(text, length);
6694 if (prefs_common.quotemark && *prefs_common.quotemark)
6695 qmark = prefs_common.quotemark;
6698 gtk_stext_set_point(GTK_STEXT(widget), *position);
6699 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
6700 pos = gtk_stext_get_point(GTK_STEXT(widget));
6701 gtk_editable_set_position(editable, pos);
6704 gtk_object_set_data(GTK_OBJECT(widget), "paste_as_quotation",
6705 GINT_TO_POINTER(paste_as_quotation - 1));
6707 gtk_editable_insert_text(editable, text, length, position);
6709 if (compose->autowrap)
6710 compose_wrap_line_all_full(compose, TRUE);
6712 gtk_signal_handler_unblock_by_func(GTK_OBJECT(widget),
6713 GTK_SIGNAL_FUNC(text_inserted),
6715 gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
6717 if (prefs_common.autosave &&
6718 gtk_stext_get_length(GTK_STEXT(widget)) % prefs_common.autosave_length == 0)
6719 compose->draft_timeout_tag = gtk_timeout_add
6720 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
6723 static gint compose_defer_auto_save_draft(Compose *compose)
6725 compose->draft_timeout_tag = -1;
6726 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
6730 static gboolean compose_send_control_enter(Compose *compose)
6734 GtkItemFactory *ifactory;
6735 GtkAccelEntry *accel;
6736 GtkWidget *send_menu;
6738 GdkModifierType ignored_mods =
6739 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
6740 GDK_MOD4_MASK | GDK_MOD5_MASK);
6742 ev = gtk_get_current_event();
6743 if (ev->type != GDK_KEY_PRESS) return FALSE;
6745 kev = (GdkEventKey *)ev;
6746 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6749 if (compose->exteditor_tag != -1)
6752 ifactory = gtk_item_factory_from_widget(compose->menubar);
6753 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6754 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6758 accel = (GtkAccelEntry *)list->data;
6759 if (accel && accel->accelerator_key == kev->keyval &&
6760 (accel->accelerator_mods & ~ignored_mods) ==
6761 (kev->state & ~ignored_mods)) {
6762 compose_send_cb(compose, 0, NULL);
6770 static void compose_check_all(Compose *compose)
6772 if (compose->gtkaspell)
6773 gtkaspell_check_all(compose->gtkaspell);
6776 static void compose_highlight_all(Compose *compose)
6778 if (compose->gtkaspell)
6779 gtkaspell_highlight_all(compose->gtkaspell);
6782 static void compose_check_backwards(Compose *compose)
6784 if (compose->gtkaspell)
6785 gtkaspell_check_backwards(compose->gtkaspell);
6787 GtkItemFactory *ifactory;
6788 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6789 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6790 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6794 static void compose_check_forwards_go(Compose *compose)
6796 if (compose->gtkaspell)
6797 gtkaspell_check_forwards_go(compose->gtkaspell);
6799 GtkItemFactory *ifactory;
6800 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6801 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6802 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6808 *\brief Guess originating forward account from MsgInfo and several
6809 * "common preference" settings. Return NULL if no guess.
6811 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
6813 PrefsAccount *account = NULL;
6815 g_return_val_if_fail(msginfo, NULL);
6816 g_return_val_if_fail(msginfo->folder, NULL);
6817 g_return_val_if_fail(msginfo->folder->prefs, NULL);
6819 if (msginfo->folder->prefs->enable_default_account)
6820 account = account_find_from_id(msginfo->folder->prefs->default_account);
6823 account = msginfo->folder->folder->account;
6825 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
6827 Xstrdup_a(to, msginfo->to, return NULL);
6828 extract_address(to);
6829 account = account_find_from_address(to);
6832 if (!account && prefs_common.forward_account_autosel) {
6834 if (!procheader_get_header_from_msginfo
6835 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
6836 extract_address(cc);
6837 account = account_find_from_address(cc);
6845 * Add entry field for each address in list.
6846 * \param compose E-Mail composition object.
6847 * \param listAddress List of (formatted) E-Mail addresses.
6849 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
6854 addr = ( gchar * ) node->data;
6855 compose_entry_append( compose, addr, COMPOSE_TO );
6856 node = g_list_next( node );