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/Privacy System"), NULL, NULL, 0, "<Branch>"},
651 {N_("/_Options/Privacy System/None"), NULL, compose_set_privacy_system_cb, 0, "<RadioItem>"},
652 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
653 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
654 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
655 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
656 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
657 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
658 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
659 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
660 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
661 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
662 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
663 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
664 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
665 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
666 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
667 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
668 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
669 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
670 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
673 static GtkTargetEntry compose_mime_types[] =
675 {"text/uri-list", 0, 0}
678 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
679 GPtrArray *attach_files)
681 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
684 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
686 return compose_generic_new(account, NULL, item, NULL, NULL);
689 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
691 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
694 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
695 GPtrArray *attach_files, GList *listAddress )
699 GtkItemFactory *ifactory;
701 if (item && item->prefs && item->prefs->enable_default_account)
702 account = account_find_from_id(item->prefs->default_account);
704 if (!account) account = cur_account;
705 g_return_val_if_fail(account != NULL, NULL);
707 compose = compose_create(account, COMPOSE_NEW);
708 ifactory = gtk_item_factory_from_widget(compose->menubar);
710 compose->replyinfo = NULL;
711 compose->fwdinfo = NULL;
713 text = GTK_STEXT(compose->text);
714 gtk_stext_freeze(text);
717 if (item && item->prefs && item->prefs->enable_default_dictionary &&
719 gtkaspell_change_dict(compose->gtkaspell,
720 item->prefs->default_dictionary);
723 if (account->auto_sig)
724 compose_insert_sig(compose, FALSE);
725 gtk_editable_set_position(GTK_EDITABLE(text), 0);
726 gtk_stext_set_point(text, 0);
728 gtk_stext_thaw(text);
730 if (account->protocol != A_NNTP) {
731 if (mailto && *mailto != '\0') {
732 compose_entries_set(compose, mailto);
734 } else if (item && item->prefs->enable_default_to) {
735 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
736 compose_entry_mark_default_to(compose, item->prefs->default_to);
738 if (item && item->ret_rcpt) {
739 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
743 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
746 * CLAWS: just don't allow return receipt request, even if the user
747 * may want to send an email. simple but foolproof.
749 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
751 compose_add_field_list( compose, listAddress );
757 for (i = 0; i < attach_files->len; i++) {
758 file = g_ptr_array_index(attach_files, i);
759 compose_attach_append(compose, file, file, NULL);
763 compose_show_first_last_header(compose, TRUE);
765 /* Set save folder */
766 if (item && item->prefs && item->prefs->save_copy_to_folder) {
767 gchar *folderidentifier;
769 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
770 folderidentifier = folder_item_get_identifier(item);
771 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
772 g_free(folderidentifier);
775 gtk_widget_grab_focus(compose->header_last->entry);
777 if (prefs_common.auto_exteditor)
778 compose_exec_ext_editor(compose);
784 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
785 const gchar *followupto, gchar * to)
789 if (!account) account = cur_account;
790 g_return_val_if_fail(account != NULL, NULL);
791 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
793 compose = compose_create(account, COMPOSE_NEW);
795 if (prefs_common.auto_sig)
796 compose_insert_sig(compose);
797 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
798 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
800 compose_entry_append(compose, to, COMPOSE_TO);
801 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
802 gtk_widget_grab_focus(compose->subject_entry);
808 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
813 g_return_if_fail(msginfo_list != NULL);
815 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
816 g_return_if_fail(msginfo != NULL);
818 list_len = g_slist_length(msginfo_list);
822 compose_reply(msginfo, prefs_common.reply_with_quote,
823 FALSE, prefs_common.default_reply_list, FALSE, body);
825 case COMPOSE_REPLY_WITH_QUOTE:
826 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
828 case COMPOSE_REPLY_WITHOUT_QUOTE:
829 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
831 case COMPOSE_REPLY_TO_SENDER:
832 compose_reply(msginfo, prefs_common.reply_with_quote,
833 FALSE, FALSE, TRUE, body);
835 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
836 compose_followup_and_reply_to(msginfo,
837 prefs_common.reply_with_quote,
840 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
841 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
843 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
844 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
846 case COMPOSE_REPLY_TO_ALL:
847 compose_reply(msginfo, prefs_common.reply_with_quote,
848 TRUE, FALSE, FALSE, body);
850 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
851 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
853 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
854 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
856 case COMPOSE_REPLY_TO_LIST:
857 compose_reply(msginfo, prefs_common.reply_with_quote,
858 FALSE, TRUE, FALSE, body);
860 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
861 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
863 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
864 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
866 case COMPOSE_FORWARD:
867 if (prefs_common.forward_as_attachment) {
868 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
871 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
875 case COMPOSE_FORWARD_INLINE:
876 /* check if we reply to more than one Message */
878 compose_forward(NULL, msginfo, FALSE, body, FALSE);
881 /* more messages FALL THROUGH */
882 case COMPOSE_FORWARD_AS_ATTACH:
883 compose_forward_multiple(NULL, msginfo_list);
885 case COMPOSE_REDIRECT:
886 compose_redirect(NULL, msginfo);
889 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
893 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
894 gboolean to_ml, gboolean to_sender,
897 compose_generic_reply(msginfo, quote, to_all, to_ml,
898 to_sender, FALSE, body);
901 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
906 compose_generic_reply(msginfo, quote, to_all, FALSE,
907 to_sender, TRUE, body);
910 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
911 gboolean to_all, gboolean to_ml,
913 gboolean followup_and_reply_to,
916 GtkItemFactory *ifactory;
918 PrefsAccount *account = NULL;
919 PrefsAccount *reply_account;
922 g_return_if_fail(msginfo != NULL);
923 g_return_if_fail(msginfo->folder != NULL);
925 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
927 g_return_if_fail(account != NULL);
929 if (to_sender && account->protocol == A_NNTP &&
930 !followup_and_reply_to) {
932 account_find_from_address(account->address);
934 reply_account = compose_current_mail_account();
938 reply_account = account;
940 compose = compose_create(account, COMPOSE_REPLY);
941 ifactory = gtk_item_factory_from_widget(compose->menubar);
943 menu_set_active(ifactory, "/Options/Remove references", FALSE);
944 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
946 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
947 if (!compose->replyinfo)
948 compose->replyinfo = procmsg_msginfo_copy(msginfo);
950 if (msginfo->folder && msginfo->folder->ret_rcpt)
951 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
953 /* Set save folder */
954 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
955 gchar *folderidentifier;
957 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
958 folderidentifier = folder_item_get_identifier(msginfo->folder);
959 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
960 g_free(folderidentifier);
963 if (compose_parse_header(compose, msginfo) < 0) return;
964 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
965 to_sender, followup_and_reply_to);
966 compose_show_first_last_header(compose, TRUE);
968 text = GTK_STEXT(compose->text);
969 gtk_stext_freeze(text);
972 if (msginfo->folder && msginfo->folder->prefs &&
973 msginfo->folder->prefs &&
974 msginfo->folder->prefs->enable_default_dictionary &&
976 gtkaspell_change_dict(compose->gtkaspell,
977 msginfo->folder->prefs->default_dictionary);
983 if (prefs_common.quotemark && *prefs_common.quotemark)
984 qmark = prefs_common.quotemark;
988 compose_quote_fmt(compose, compose->replyinfo,
989 prefs_common.quotefmt,
993 if (account->auto_sig)
994 compose_insert_sig(compose, FALSE);
996 /* Must thaw here, otherwise the GtkSTextEdit will become confused
997 * when positioning cursor */
998 gtk_stext_thaw(text);
1001 gtk_editable_set_position
1002 (GTK_EDITABLE(text), quote_fmt_get_cursor_pos());
1003 gtk_stext_set_point(text, quote_fmt_get_cursor_pos());
1006 if (quote && prefs_common.linewrap_quote) {
1007 gtk_stext_freeze(text);
1008 compose_wrap_line_all(compose);
1009 gtk_stext_thaw(text);
1012 gtk_widget_grab_focus(compose->text);
1014 if (prefs_common.auto_exteditor)
1015 compose_exec_ext_editor(compose);
1018 #define INSERT_FW_HEADER(var, hdr) \
1019 if (msginfo->var && *msginfo->var) { \
1020 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1021 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1022 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1025 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1026 gboolean as_attach, const gchar *body,
1027 gboolean no_extedit)
1032 g_return_val_if_fail(msginfo != NULL, NULL);
1033 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1036 !(account = compose_guess_forward_account_from_msginfo
1038 account = cur_account;
1040 compose = compose_create(account, COMPOSE_FORWARD);
1042 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1043 if (!compose->fwdinfo)
1044 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1046 if (msginfo->subject && *msginfo->subject) {
1047 gchar *buf, *buf2, *p;
1049 buf = p = g_strdup(msginfo->subject);
1050 p += subject_get_prefix_length(p);
1051 memmove(buf, p, strlen(p) + 1);
1053 buf2 = g_strdup_printf("Fw: %s", buf);
1054 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1060 text = GTK_STEXT(compose->text);
1061 gtk_stext_freeze(text);
1066 msgfile = procmsg_get_message_file_path(msginfo);
1067 if (!is_file_exist(msgfile))
1068 g_warning("%s: file not exist\n", msgfile);
1070 compose_attach_append(compose, msgfile, msgfile,
1076 MsgInfo *full_msginfo;
1078 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1080 full_msginfo = procmsg_msginfo_copy(msginfo);
1082 if (prefs_common.fw_quotemark &&
1083 *prefs_common.fw_quotemark)
1084 qmark = prefs_common.fw_quotemark;
1088 compose_quote_fmt(compose, full_msginfo,
1089 prefs_common.fw_quotefmt,
1091 compose_attach_parts(compose, msginfo);
1093 procmsg_msginfo_free(full_msginfo);
1096 if (account->auto_sig)
1097 compose_insert_sig(compose, FALSE);
1099 if (prefs_common.linewrap_quote)
1100 compose_wrap_line_all(compose);
1102 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1103 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1105 gtk_stext_thaw(text);
1106 #if 0 /* NEW COMPOSE GUI */
1107 if (account->protocol != A_NNTP)
1108 gtk_widget_grab_focus(compose->to_entry);
1110 gtk_widget_grab_focus(compose->newsgroups_entry);
1112 gtk_widget_grab_focus(compose->header_last->entry);
1114 if (!no_extedit && prefs_common.auto_exteditor)
1115 compose_exec_ext_editor(compose);
1118 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1119 gchar *folderidentifier;
1121 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1122 folderidentifier = folder_item_get_identifier(msginfo->folder);
1123 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1124 g_free(folderidentifier);
1130 #undef INSERT_FW_HEADER
1132 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1139 g_return_val_if_fail(msginfo_list != NULL, NULL);
1141 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1142 if (((MsgInfo *)msginfo->data)->folder == NULL)
1145 /* guess account from first selected message */
1147 !(account = compose_guess_forward_account_from_msginfo
1148 (msginfo_list->data)))
1149 account = cur_account;
1151 g_return_val_if_fail(account != NULL, NULL);
1153 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1154 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1155 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1158 compose = compose_create(account, COMPOSE_FORWARD);
1160 text = GTK_STEXT(compose->text);
1161 gtk_stext_freeze(text);
1163 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1164 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1165 if (!is_file_exist(msgfile))
1166 g_warning("%s: file not exist\n", msgfile);
1168 compose_attach_append(compose, msgfile, msgfile,
1173 if (account->auto_sig)
1174 compose_insert_sig(compose, FALSE);
1176 if (prefs_common.linewrap_quote)
1177 compose_wrap_line_all(compose);
1179 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1180 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1182 gtk_stext_thaw(text);
1183 gtk_widget_grab_focus(compose->header_last->entry);
1185 #if 0 /* NEW COMPOSE GUI */
1186 if (account->protocol != A_NNTP)
1187 gtk_widget_grab_focus(compose->to_entry);
1189 gtk_widget_grab_focus(compose->newsgroups_entry);
1195 void compose_reedit(MsgInfo *msginfo)
1198 PrefsAccount *account = NULL;
1201 gchar buf[BUFFSIZE];
1202 gboolean use_signing = FALSE;
1203 gboolean use_encryption = FALSE;
1204 gchar *privacy_system = NULL;
1206 g_return_if_fail(msginfo != NULL);
1207 g_return_if_fail(msginfo->folder != NULL);
1209 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1210 gchar queueheader_buf[BUFFSIZE];
1213 /* Select Account from queue headers */
1214 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1215 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1216 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1217 account = account_find_from_id(id);
1219 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1220 sizeof(queueheader_buf), "NAID:")) {
1221 id = atoi(&queueheader_buf[strlen("NAID:")]);
1222 account = account_find_from_id(id);
1224 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1225 sizeof(queueheader_buf), "MAID:")) {
1226 id = atoi(&queueheader_buf[strlen("MAID:")]);
1227 account = account_find_from_id(id);
1229 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1230 sizeof(queueheader_buf), "S:")) {
1231 account = account_find_from_address(queueheader_buf);
1233 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1234 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1235 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1236 use_signing = param;
1239 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1240 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1241 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1242 use_encryption = param;
1244 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1245 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1246 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1248 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1249 sizeof(queueheader_buf), "X-Priority: ")) {
1250 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1251 compose->priority = param;
1254 account = msginfo->folder->folder->account;
1256 if (!account && prefs_common.reedit_account_autosel) {
1257 gchar from[BUFFSIZE];
1258 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1259 extract_address(from);
1260 account = account_find_from_address(from);
1263 if (!account) account = cur_account;
1264 g_return_if_fail(account != NULL);
1266 compose = compose_create(account, COMPOSE_REEDIT);
1267 compose->privacy_system = privacy_system;
1268 compose_use_signing(compose, use_signing);
1269 compose_use_encryption(compose, use_encryption);
1270 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1272 if (msginfo->folder->stype == F_QUEUE
1273 || msginfo->folder->stype == F_DRAFT) {
1274 gchar queueheader_buf[BUFFSIZE];
1276 /* Set message save folder */
1277 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1280 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1281 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1282 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1286 if (compose_parse_header(compose, msginfo) < 0) return;
1287 compose_reedit_set_entry(compose, msginfo);
1289 text = GTK_STEXT(compose->text);
1290 gtk_stext_freeze(text);
1292 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1293 g_warning("Can't get text part\n");
1295 while (fgets(buf, sizeof(buf), fp) != NULL) {
1297 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1301 compose_attach_parts(compose, msginfo);
1303 gtk_stext_thaw(text);
1304 gtk_widget_grab_focus(compose->text);
1306 if (prefs_common.auto_exteditor)
1307 compose_exec_ext_editor(compose);
1310 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1314 GtkItemFactory *ifactory;
1317 g_return_val_if_fail(msginfo != NULL, NULL);
1320 account = account_get_reply_account(msginfo,
1321 prefs_common.reply_account_autosel);
1322 g_return_val_if_fail(account != NULL, NULL);
1324 compose = compose_create(account, COMPOSE_REDIRECT);
1325 ifactory = gtk_item_factory_from_widget(compose->menubar);
1327 compose->replyinfo = NULL;
1328 compose->fwdinfo = NULL;
1330 compose_show_first_last_header(compose, TRUE);
1332 gtk_widget_grab_focus(compose->header_last->entry);
1334 filename = procmsg_get_message_file(msginfo);
1335 if (filename == NULL)
1338 compose->redirect_filename = filename;
1340 /* Set save folder */
1341 item = msginfo->folder;
1342 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1343 gchar *folderidentifier;
1345 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1346 folderidentifier = folder_item_get_identifier(item);
1347 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1348 g_free(folderidentifier);
1351 compose_attach_parts(compose, msginfo);
1353 if (msginfo->subject)
1354 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1356 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1358 gtk_stext_freeze(GTK_STEXT(compose->text));
1359 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1360 gtk_editable_set_editable(GTK_EDITABLE(compose->text), FALSE);
1361 gtk_stext_thaw(GTK_STEXT(compose->text));
1363 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1364 menu_set_sensitive(ifactory, "/Add...", FALSE);
1365 menu_set_sensitive(ifactory, "/Remove", FALSE);
1366 menu_set_sensitive(ifactory, "/Property...", FALSE);
1368 ifactory = gtk_item_factory_from_widget(compose->menubar);
1369 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1370 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1371 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1372 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1373 menu_set_sensitive(ifactory, "/Edit", FALSE);
1374 menu_set_sensitive(ifactory, "/Options/Sign", FALSE);
1375 menu_set_sensitive(ifactory, "/Options/Encrypt", FALSE);
1376 menu_set_sensitive(ifactory, "/Options/Priority", FALSE);
1377 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
1378 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1379 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1381 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1382 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1383 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1384 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1385 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1386 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1387 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1392 GList *compose_get_compose_list(void)
1394 return compose_list;
1397 void compose_entry_append(Compose *compose, const gchar *address,
1398 ComposeEntryType type)
1402 if (!address || *address == '\0') return;
1404 #if 0 /* NEW COMPOSE GUI */
1407 entry = GTK_ENTRY(compose->cc_entry);
1410 entry = GTK_ENTRY(compose->bcc_entry);
1412 case COMPOSE_NEWSGROUPS:
1413 entry = GTK_ENTRY(compose->newsgroups_entry);
1417 entry = GTK_ENTRY(compose->to_entry);
1421 text = gtk_entry_get_text(entry);
1423 gtk_entry_append_text(entry, ", ");
1424 gtk_entry_append_text(entry, address);
1432 header = N_("Bcc:");
1434 case COMPOSE_REPLYTO:
1435 header = N_("Reply-To:");
1437 case COMPOSE_NEWSGROUPS:
1438 header = N_("Newsgroups:");
1440 case COMPOSE_FOLLOWUPTO:
1441 header = N_( "Followup-To:");
1448 header = prefs_common.trans_hdr ? gettext(header) : header;
1450 compose_add_header_entry(compose, header, (gchar *)address);
1453 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1455 static GtkStyle *bold_style = NULL;
1456 static GdkColor bold_color;
1457 static GdkFont *bold_font = NULL;
1461 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1462 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1463 if (gtk_entry_get_text(entry) &&
1464 !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1465 gtk_widget_ensure_style(GTK_WIDGET(entry));
1467 gtkut_convert_int_to_gdk_color
1468 (prefs_common.color_new, &bold_color);
1469 bold_style = gtk_style_copy(gtk_widget_get_style
1470 (GTK_WIDGET(entry)));
1472 bold_font = gtkut_font_load
1473 (prefs_common.boldfont);
1475 bold_style->font = bold_font;
1476 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1478 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1483 void compose_toolbar_cb(gint action, gpointer data)
1485 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1486 Compose *compose = (Compose*)toolbar_item->parent;
1488 g_return_if_fail(compose != NULL);
1492 compose_send_cb(compose, 0, NULL);
1495 compose_send_later_cb(compose, 0, NULL);
1498 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1501 compose_insert_file_cb(compose, 0, NULL);
1504 compose_attach_cb(compose, 0, NULL);
1507 compose_insert_sig(compose, FALSE);
1510 compose_ext_editor_cb(compose, 0, NULL);
1512 case A_LINEWRAP_CURRENT:
1513 compose_wrap_line(compose);
1515 case A_LINEWRAP_ALL:
1516 compose_wrap_line_all(compose);
1519 compose_address_cb(compose, 0, NULL);
1522 case A_CHECK_SPELLING:
1523 compose_check_all(compose);
1531 static void compose_entries_set(Compose *compose, const gchar *mailto)
1536 gchar *subject = NULL;
1539 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1542 compose_entry_append(compose, to, COMPOSE_TO);
1544 compose_entry_append(compose, cc, COMPOSE_CC);
1546 compose_entry_append(compose, bcc, COMPOSE_BCC);
1548 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1550 gtk_stext_insert(GTK_STEXT(compose->text),
1551 NULL, NULL, NULL, body, -1);
1552 gtk_stext_insert(GTK_STEXT(compose->text),
1553 NULL, NULL, NULL, "\n", 1);
1563 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1565 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1566 {"Cc:", NULL, TRUE},
1567 {"References:", NULL, FALSE},
1568 {"Bcc:", NULL, TRUE},
1569 {"Newsgroups:", NULL, TRUE},
1570 {"Followup-To:", NULL, TRUE},
1571 {"List-Post:", NULL, FALSE},
1572 {"X-Priority:", NULL, FALSE},
1573 {NULL, NULL, FALSE}};
1589 g_return_val_if_fail(msginfo != NULL, -1);
1591 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1592 procheader_get_header_fields(fp, hentry);
1595 if (hentry[H_REPLY_TO].body != NULL) {
1596 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1597 compose->replyto = hentry[H_REPLY_TO].body;
1598 hentry[H_REPLY_TO].body = NULL;
1600 if (hentry[H_CC].body != NULL) {
1601 conv_unmime_header_overwrite(hentry[H_CC].body);
1602 compose->cc = hentry[H_CC].body;
1603 hentry[H_CC].body = NULL;
1605 if (hentry[H_REFERENCES].body != NULL) {
1606 if (compose->mode == COMPOSE_REEDIT)
1607 compose->references = hentry[H_REFERENCES].body;
1609 compose->references = compose_parse_references
1610 (hentry[H_REFERENCES].body, msginfo->msgid);
1611 g_free(hentry[H_REFERENCES].body);
1613 hentry[H_REFERENCES].body = NULL;
1615 if (hentry[H_BCC].body != NULL) {
1616 if (compose->mode == COMPOSE_REEDIT) {
1617 conv_unmime_header_overwrite(hentry[H_BCC].body);
1618 compose->bcc = hentry[H_BCC].body;
1620 g_free(hentry[H_BCC].body);
1621 hentry[H_BCC].body = NULL;
1623 if (hentry[H_NEWSGROUPS].body != NULL) {
1624 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1625 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1626 hentry[H_NEWSGROUPS].body = NULL;
1628 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1629 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1630 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1631 hentry[H_FOLLOWUP_TO].body = NULL;
1633 if (hentry[H_LIST_POST].body != NULL) {
1636 extract_address(hentry[H_LIST_POST].body);
1637 if (hentry[H_LIST_POST].body[0] != '\0') {
1638 scan_mailto_url(hentry[H_LIST_POST].body,
1639 &to, NULL, NULL, NULL, NULL);
1641 g_free(compose->ml_post);
1642 compose->ml_post = to;
1645 g_free(hentry[H_LIST_POST].body);
1646 hentry[H_LIST_POST].body = NULL;
1649 /* CLAWS - X-Priority */
1650 if (compose->mode == COMPOSE_REEDIT)
1651 if (hentry[H_X_PRIORITY].body != NULL) {
1654 priority = atoi(hentry[H_X_PRIORITY].body);
1655 g_free(hentry[H_X_PRIORITY].body);
1657 hentry[H_X_PRIORITY].body = NULL;
1659 if (priority < PRIORITY_HIGHEST ||
1660 priority > PRIORITY_LOWEST)
1661 priority = PRIORITY_NORMAL;
1663 compose->priority = priority;
1666 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1667 compose->inreplyto = g_strdup(msginfo->inreplyto);
1668 else if (compose->mode != COMPOSE_REEDIT &&
1669 msginfo->msgid && *msginfo->msgid) {
1670 compose->inreplyto = g_strdup(msginfo->msgid);
1672 if (!compose->references) {
1673 if (msginfo->inreplyto && *msginfo->inreplyto)
1674 compose->references =
1675 g_strdup_printf("<%s>\n\t<%s>",
1679 compose->references =
1680 g_strconcat("<", msginfo->msgid, ">",
1688 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1690 GSList *ref_id_list, *cur;
1694 ref_id_list = references_list_append(NULL, ref);
1695 if (!ref_id_list) return NULL;
1696 if (msgid && *msgid)
1697 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1702 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1703 /* "<" + Message-ID + ">" + CR+LF+TAB */
1704 len += strlen((gchar *)cur->data) + 5;
1706 if (len > MAX_REFERENCES_LEN) {
1707 /* remove second message-ID */
1708 if (ref_id_list && ref_id_list->next &&
1709 ref_id_list->next->next) {
1710 g_free(ref_id_list->next->data);
1711 ref_id_list = g_slist_remove
1712 (ref_id_list, ref_id_list->next->data);
1714 slist_free_strings(ref_id_list);
1715 g_slist_free(ref_id_list);
1722 new_ref = g_string_new("");
1723 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1724 if (new_ref->len > 0)
1725 g_string_append(new_ref, "\n\t");
1726 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1729 slist_free_strings(ref_id_list);
1730 g_slist_free(ref_id_list);
1732 new_ref_str = new_ref->str;
1733 g_string_free(new_ref, FALSE);
1738 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1739 const gchar *fmt, const gchar *qmark,
1742 GtkSText *text = GTK_STEXT(compose->text);
1743 static MsgInfo dummyinfo;
1744 gchar *quote_str = NULL;
1748 const gchar *trimmed_body = body;
1751 msginfo = &dummyinfo;
1753 if (qmark != NULL) {
1754 quote_fmt_init(msginfo, NULL, NULL);
1755 quote_fmt_scan_string(qmark);
1758 buf = quote_fmt_get_buffer();
1760 alertpanel_error(_("Quote mark format error."));
1762 Xstrdup_a(quote_str, buf, return NULL)
1765 if (fmt && *fmt != '\0') {
1766 while (trimmed_body && strlen(trimmed_body) > 1
1767 && trimmed_body[0]=='\n')
1770 quote_fmt_init(msginfo, quote_str, trimmed_body);
1771 quote_fmt_scan_string(fmt);
1774 buf = quote_fmt_get_buffer();
1776 alertpanel_error(_("Message reply/forward format error."));
1782 gtk_stext_freeze(text);
1784 for (p = buf; *p != '\0'; ) {
1785 lastp = strchr(p, '\n');
1786 len = lastp ? lastp - p + 1 : -1;
1787 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1794 gtk_stext_thaw(text);
1799 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1800 gboolean to_all, gboolean to_ml,
1802 gboolean followup_and_reply_to)
1804 GSList *cc_list = NULL;
1807 gchar *replyto = NULL;
1808 GHashTable *to_table;
1810 g_return_if_fail(compose->account != NULL);
1811 g_return_if_fail(msginfo != NULL);
1813 if (compose->account->protocol != A_NNTP) {
1814 if (!compose->replyto && to_ml && compose->ml_post
1815 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1816 compose_entry_append(compose,
1819 else if (!(to_all || to_sender)
1821 && msginfo->folder->prefs->enable_default_reply_to) {
1822 compose_entry_append(compose,
1823 msginfo->folder->prefs->default_reply_to,
1826 compose_entry_append(compose,
1827 (compose->replyto && !to_sender)
1828 ? compose->replyto :
1829 msginfo->from ? msginfo->from : "",
1832 if (to_sender || (compose->followup_to &&
1833 !strncmp(compose->followup_to, "poster", 6)))
1834 compose_entry_append
1836 (compose->replyto ? compose->replyto :
1837 msginfo->from ? msginfo->from : ""),
1840 else if (followup_and_reply_to || to_all) {
1841 compose_entry_append
1843 (compose->replyto ? compose->replyto :
1844 msginfo->from ? msginfo->from : ""),
1847 compose_entry_append
1849 compose->followup_to ? compose->followup_to :
1850 compose->newsgroups ? compose->newsgroups : "",
1851 COMPOSE_NEWSGROUPS);
1854 compose_entry_append
1856 compose->followup_to ? compose->followup_to :
1857 compose->newsgroups ? compose->newsgroups : "",
1858 COMPOSE_NEWSGROUPS);
1861 if (msginfo->subject && *msginfo->subject) {
1865 buf = p = g_strdup(msginfo->subject);
1866 p += subject_get_prefix_length(p);
1867 memmove(buf, p, strlen(p) + 1);
1869 buf2 = g_strdup_printf("Re: %s", buf);
1870 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1875 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1877 if (to_ml && compose->ml_post) return;
1878 if (!to_all || compose->account->protocol == A_NNTP) return;
1880 if (compose->replyto) {
1881 Xstrdup_a(replyto, compose->replyto, return);
1882 extract_address(replyto);
1884 if (msginfo->from) {
1885 Xstrdup_a(from, msginfo->from, return);
1886 extract_address(from);
1889 if (replyto && from)
1890 cc_list = address_list_append_with_comments(cc_list, from);
1891 if (to_all && msginfo->folder &&
1892 msginfo->folder->prefs->enable_default_reply_to)
1893 cc_list = address_list_append_with_comments(cc_list,
1894 msginfo->folder->prefs->default_reply_to);
1895 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1896 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1898 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1900 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1901 if (compose->account)
1902 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1903 GINT_TO_POINTER(1));
1905 /* remove address on To: and that of current account */
1906 for (cur = cc_list; cur != NULL; ) {
1907 GSList *next = cur->next;
1910 addr = g_strdup(cur->data);
1911 extract_address(addr);
1913 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
1914 cc_list = g_slist_remove(cc_list, cur->data);
1916 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
1920 hash_free_strings(to_table);
1921 g_hash_table_destroy(to_table);
1924 for (cur = cc_list; cur != NULL; cur = cur->next)
1925 compose_entry_append(compose, (gchar *)cur->data,
1927 slist_free_strings(cc_list);
1928 g_slist_free(cc_list);
1933 #define SET_ENTRY(entry, str) \
1936 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1939 #define SET_ADDRESS(type, str) \
1942 compose_entry_append(compose, str, type); \
1945 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1947 g_return_if_fail(msginfo != NULL);
1949 SET_ENTRY(subject_entry, msginfo->subject);
1950 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1951 SET_ADDRESS(COMPOSE_CC, compose->cc);
1952 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1953 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1954 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
1955 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
1957 compose_update_priority_menu_item(compose);
1958 compose_update_privacy_system_menu_item(compose);
1959 compose_show_first_last_header(compose, TRUE);
1965 static void compose_insert_sig(Compose *compose, gboolean replace)
1967 GtkSText *text = GTK_STEXT(compose->text);
1971 g_return_if_fail(compose->account != NULL);
1973 cur_pos = gtk_editable_get_position(GTK_EDITABLE(text));
1975 gtk_stext_freeze(text);
1978 len = gtk_stext_get_length(text);
1979 gtk_stext_set_point(text, len);
1982 if (replace && compose->sig_str) {
1985 if (compose->sig_str[0] == '\0')
1988 pos = gtkut_stext_find(text, 0, compose->sig_str, TRUE);
1991 len = get_mbs_len(compose->sig_str);
1993 gtk_stext_set_point(text, pos);
1994 gtk_stext_forward_delete(text, len);
1999 g_free(compose->sig_str);
2000 compose->sig_str = compose_get_signature_str(compose);
2001 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2002 compose->sig_str = g_strdup("");
2004 gtk_stext_insert(text, NULL, NULL, NULL, compose->sig_str, -1);
2006 gtk_stext_thaw(text);
2008 if (cur_pos > gtk_stext_get_length(text))
2009 cur_pos = gtk_stext_get_length(text);
2011 gtk_editable_set_position(GTK_EDITABLE(text), cur_pos);
2012 gtk_stext_set_point(text, cur_pos);
2015 static gchar *compose_get_signature_str(Compose *compose)
2017 gchar *sig_body = NULL;
2018 gchar *sig_str = NULL;
2020 g_return_val_if_fail(compose->account != NULL, NULL);
2022 if (!compose->account->sig_path)
2025 if (compose->account->sig_type == SIG_FILE) {
2026 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2027 g_warning("can't open signature file: %s\n",
2028 compose->account->sig_path);
2033 if (compose->account->sig_type == SIG_COMMAND)
2034 sig_body = get_command_output(compose->account->sig_path);
2038 tmp = file_read_to_str(compose->account->sig_path);
2041 sig_body = normalize_newlines(tmp);
2045 if (compose->account->sig_sep)
2046 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2049 sig_str = g_strconcat("\n\n", sig_body, NULL);
2056 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2058 GtkSText *text = GTK_STEXT(compose->text);
2059 gchar buf[BUFFSIZE];
2062 gboolean badtxt = FALSE;
2064 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2066 if ((fp = fopen(file, "rb")) == NULL) {
2067 FILE_OP_ERROR(file, "fopen");
2068 return COMPOSE_INSERT_READ_ERROR;
2071 gtk_stext_freeze(text);
2073 while (fgets(buf, sizeof(buf), fp) != NULL) {
2074 /* strip <CR> if DOS/Windows file,
2075 replace <CR> with <LF> if Macintosh file. */
2078 if (len > 0 && buf[len - 1] != '\n') {
2080 if (buf[len] == '\r') buf[len] = '\n';
2082 if (mbstowcs(NULL, buf, 0) == -1)
2084 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
2087 gtk_stext_thaw(text);
2092 return COMPOSE_INSERT_INVALID_CHARACTER;
2094 return COMPOSE_INSERT_SUCCESS;
2097 static void compose_attach_append(Compose *compose, const gchar *file,
2098 const gchar *filename,
2099 const gchar *content_type)
2102 gchar *text[N_ATTACH_COLS];
2107 if (!is_file_exist(file)) {
2108 g_warning("File %s doesn't exist\n", file);
2111 if ((size = get_file_size(file)) < 0) {
2112 g_warning("Can't get file size of %s\n", file);
2116 alertpanel_notice(_("File %s is empty."), file);
2119 if ((fp = fopen(file, "rb")) == NULL) {
2120 alertpanel_error(_("Can't read %s."), file);
2125 #if 0 /* NEW COMPOSE GUI */
2126 if (!compose->use_attach) {
2127 GtkItemFactory *ifactory;
2129 ifactory = gtk_item_factory_from_widget(compose->menubar);
2130 menu_set_active(ifactory, "/View/Attachment", TRUE);
2133 ainfo = g_new0(AttachInfo, 1);
2134 ainfo->file = g_strdup(file);
2137 ainfo->content_type = g_strdup(content_type);
2138 if (!g_strcasecmp(content_type, "message/rfc822")) {
2140 MsgFlags flags = {0, 0};
2143 if (procmime_get_encoding_for_file(file) == ENC_7BIT)
2144 ainfo->encoding = ENC_7BIT;
2146 ainfo->encoding = ENC_8BIT;
2148 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2149 if (msginfo && msginfo->subject)
2150 name = msginfo->subject;
2152 name = g_basename(filename ? filename : file);
2154 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2156 procmsg_msginfo_free(msginfo);
2158 if (!g_strncasecmp(content_type, "text", 4))
2160 procmime_get_encoding_for_file(file);
2162 ainfo->encoding = ENC_BASE64;
2163 ainfo->name = g_strdup
2164 (g_basename(filename ? filename : file));
2167 ainfo->content_type = procmime_get_mime_type(file);
2168 if (!ainfo->content_type) {
2169 ainfo->content_type =
2170 g_strdup("application/octet-stream");
2171 ainfo->encoding = ENC_BASE64;
2172 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
2173 ainfo->encoding = procmime_get_encoding_for_file(file);
2175 ainfo->encoding = ENC_BASE64;
2176 ainfo->name = g_strdup(g_basename(filename ? filename : file));
2179 if (!strcmp(ainfo->content_type, "unknown")) {
2180 g_free(ainfo->content_type);
2181 ainfo->content_type = g_strdup("application/octet-stream");
2186 text[COL_MIMETYPE] = ainfo->content_type;
2187 text[COL_SIZE] = to_human_readable(size);
2188 text[COL_NAME] = ainfo->name;
2190 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2191 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2194 static void compose_use_signing(Compose *compose, gboolean use_signing)
2196 GtkItemFactory *ifactory;
2197 GtkWidget *menuitem = NULL;
2199 compose->use_signing = use_signing;
2200 ifactory = gtk_item_factory_from_widget(compose->menubar);
2201 menuitem = gtk_item_factory_get_item
2202 (ifactory, "/Options/Sign");
2203 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2207 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2209 GtkItemFactory *ifactory;
2210 GtkWidget *menuitem = NULL;
2212 compose->use_encryption = use_encryption;
2213 ifactory = gtk_item_factory_from_widget(compose->menubar);
2214 menuitem = gtk_item_factory_get_item
2215 (ifactory, "/Options/Encrypt");
2217 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2221 #define NEXT_PART_NOT_CHILD(info) \
2223 node = info->node; \
2224 while (node->children) \
2225 node = g_node_last_child(node); \
2226 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2229 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2233 MimeInfo *firsttext = NULL;
2234 MimeInfo *encrypted = NULL;
2237 const gchar *partname = NULL;
2239 mimeinfo = procmime_scan_message(msginfo);
2240 if (!mimeinfo) return;
2242 if (mimeinfo->node->children == NULL) {
2243 procmime_mimeinfo_free_all(mimeinfo);
2247 /* find first content part */
2248 child = (MimeInfo *) mimeinfo->node->children->data;
2249 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2250 child = (MimeInfo *)child->node->children->data;
2252 if (child->type == MIMETYPE_TEXT) {
2254 debug_print("First text part found\n");
2255 } else if (compose->mode == COMPOSE_REEDIT &&
2256 child->type == MIMETYPE_APPLICATION &&
2257 !g_strcasecmp(child->subtype, "pgp-encrypted")) {
2259 val = alertpanel(_("Encrypted message"),
2260 _("Cannot re-edit an encrypted message. \n"
2261 "Discard encrypted part?"),
2262 _("Yes"), _("No"), NULL);
2263 if (val == G_ALERTDEFAULT)
2264 encrypted = (MimeInfo *)child->node->parent->data;
2267 child = (MimeInfo *) mimeinfo->node->children->data;
2268 while (child != NULL) {
2269 if (child == encrypted) {
2270 /* skip this part of tree */
2271 NEXT_PART_NOT_CHILD(child);
2275 if (child->type == MIMETYPE_MULTIPART) {
2276 /* get the actual content */
2277 child = procmime_mimeinfo_next(child);
2281 if (child == firsttext) {
2282 child = procmime_mimeinfo_next(child);
2286 outfile = procmime_get_tmp_file_name(child);
2287 if (procmime_get_part(outfile, child) < 0)
2288 g_warning("Can't get the part of multipart message.");
2290 gchar *content_type;
2292 content_type = procmime_get_content_type_str(child->type, child->subtype);
2293 partname = procmime_mimeinfo_get_parameter(child, "name");
2294 if (partname == NULL)
2296 compose_attach_append(compose, outfile,
2297 partname, content_type);
2298 g_free(content_type);
2301 NEXT_PART_NOT_CHILD(child);
2303 procmime_mimeinfo_free_all(mimeinfo);
2306 #undef NEXT_PART_NOT_CHILD
2308 #define GET_CHAR(pos, buf, len) \
2310 if (text->use_wchar) \
2311 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2313 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2318 #define DISP_WIDTH(len) \
2319 ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
2320 (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
2322 #define SPACE_CHARS " \t"
2324 static void compose_wrap_line(Compose *compose)
2326 GtkSText *text = GTK_STEXT(compose->text);
2327 gint ch_len, last_ch_len;
2328 gchar cbuf[MB_LEN_MAX], last_ch;
2332 gint p_start, p_end;
2333 gint line_pos, cur_pos;
2334 gint line_len, cur_len;
2336 gtk_stext_freeze(text);
2338 text_len = gtk_stext_get_length(text);
2340 /* check to see if the point is on the paragraph mark (empty line). */
2341 cur_pos = gtk_stext_get_point(text);
2342 GET_CHAR(cur_pos, cbuf, ch_len);
2343 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2345 goto compose_end; /* on the paragraph mark */
2346 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2347 if (ch_len == 1 && *cbuf == '\n')
2348 goto compose_end; /* on the paragraph mark */
2351 /* find paragraph start. */
2352 line_end = quoted = 0;
2353 for (p_start = cur_pos; p_start >= 0; --p_start) {
2354 GET_CHAR(p_start, cbuf, ch_len);
2355 if (ch_len == 1 && *cbuf == '\n') {
2357 goto compose_end; /* quoted part */
2365 && strchr(prefs_common.quote_chars, *cbuf))
2367 else if (ch_len != 1 || !isspace(*(guchar *)cbuf))
2376 /* find paragraph end. */
2378 for (p_end = cur_pos; p_end < text_len; p_end++) {
2379 GET_CHAR(p_end, cbuf, ch_len);
2380 if (ch_len == 1 && *cbuf == '\n') {
2387 if (line_end && ch_len == 1 &&
2388 strchr(prefs_common.quote_chars, *cbuf))
2389 goto compose_end; /* quoted part */
2394 if (p_end >= text_len)
2397 if (p_start >= p_end)
2400 line_len = cur_len = 0;
2404 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2407 GET_CHAR(cur_pos, cbuf, ch_len);
2414 if (ch_len == 1 && isspace(*(guchar *)cbuf))
2417 if (ch_len == 1 && *cbuf == '\n') {
2419 if (last_ch_len == 1 && !isspace((guchar)last_ch)) {
2420 if (cur_pos + 1 < p_end) {
2421 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2423 !isspace(*(guchar *)cbuf))
2427 gtk_stext_set_point(text, cur_pos + 1);
2428 gtk_stext_backward_delete(text, 1);
2430 gtk_stext_set_point(text, cur_pos);
2431 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2441 last_ch_len = ch_len;
2445 line_pos = cur_pos + 1;
2446 line_len = cur_len + ch_len;
2449 if (cur_len + DISP_WIDTH(ch_len) > prefs_common.linewrap_len &&
2453 GET_CHAR(line_pos - 1, cbuf, ch_len);
2454 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2455 gtk_stext_set_point(text, line_pos);
2456 gtk_stext_backward_delete(text, 1);
2465 gtk_stext_set_point(text, line_pos);
2466 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2470 cur_len = cur_len - line_len + DISP_WIDTH(ch_len);
2476 line_pos = cur_pos + 1;
2477 line_len = cur_len + DISP_WIDTH(ch_len);
2479 cur_len += DISP_WIDTH(ch_len);
2483 gtk_stext_thaw(text);
2488 /* Darko: used when I debug wrapping */
2489 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2492 gchar cbuf[MB_LEN_MAX];
2494 printf("%d [", pos);
2495 for (i = pos; i < tlen; i++) {
2496 GET_CHAR(i, cbuf, clen);
2497 if (clen < 0) break;
2498 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2500 fwrite(cbuf, clen, 1, stdout);
2508 WAIT_FOR_INDENT_CHAR,
2509 WAIT_FOR_INDENT_CHAR_OR_SPACE
2512 /* return indent length, we allow:
2513 > followed by spaces/tabs
2514 | followed by spaces/tabs
2515 uppercase characters immediately followed by >,
2516 and the repeating sequences of the above */
2517 /* return indent length */
2518 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2521 guint i, ch_len, alnum_cnt = 0;
2522 IndentState state = WAIT_FOR_INDENT_CHAR;
2523 gchar cbuf[MB_LEN_MAX];
2527 if (prefs_common.quote_chars == NULL) {
2531 for (i = start_pos; i < text_len; i++) {
2532 GET_CHAR(i, cbuf, ch_len);
2536 if (cbuf[0] == '\n')
2539 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2540 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2543 case WAIT_FOR_SPACE:
2544 if (is_space == FALSE)
2546 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2548 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2549 if (is_indent == FALSE && is_space == FALSE &&
2550 !isupper((guchar)cbuf[0]))
2552 if (is_space == TRUE) {
2554 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2555 } else if (is_indent == TRUE) {
2557 state = WAIT_FOR_SPACE;
2560 state = WAIT_FOR_INDENT_CHAR;
2563 case WAIT_FOR_INDENT_CHAR:
2564 if (is_indent == FALSE && !isupper((guchar)cbuf[0]))
2566 if (is_indent == TRUE) {
2568 && !strchr(prefs_common.quote_chars, cbuf[0]))
2571 state = WAIT_FOR_SPACE;
2582 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2588 /* insert quotation string when line was wrapped */
2589 static guint ins_quote(GtkSText *text, guint indent_len,
2590 guint prev_line_pos, guint text_len,
2593 guint i, ins_len = 0;
2597 for (i = 0; i < indent_len; i++) {
2598 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2599 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2601 ins_len = indent_len;
2607 /* check if we should join the next line */
2608 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2609 guint prev_ilen, gboolean autowrap)
2611 guint indent_len, ch_len;
2612 gboolean do_join = FALSE;
2613 gchar cbuf[MB_LEN_MAX];
2615 indent_len = get_indent_length(text, start_pos, tlen);
2617 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2618 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2619 if (ch_len > 0 && (cbuf[0] != '\n'))
2626 static void compose_wrap_line_all(Compose *compose)
2628 compose_wrap_line_all_full(compose, FALSE);
2631 #define STEXT_FREEZE() \
2632 if (!frozen) { gtk_stext_freeze(text); frozen = TRUE; }
2634 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2636 GtkSText *text = GTK_STEXT(compose->text);
2638 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2639 gint line_len = 0, cur_len = 0;
2641 gboolean is_new_line = TRUE, do_delete = FALSE;
2643 gboolean linewrap_quote = TRUE;
2644 gboolean set_editable_pos = FALSE;
2645 gint editable_pos = 0;
2646 gboolean frozen = FALSE;
2647 guint linewrap_len = prefs_common.linewrap_len;
2648 gchar *qfmt = prefs_common.quotemark;
2649 gchar cbuf[MB_LEN_MAX];
2651 tlen = gtk_stext_get_length(text);
2653 for (; cur_pos < tlen; cur_pos++) {
2654 /* mark position of new line - needed for quotation wrap */
2657 i_len = get_indent_length(text, cur_pos, tlen);
2659 is_new_line = FALSE;
2662 g_print("new line i_len=%d p_pos=", i_len);
2663 dump_text(text, p_pos, tlen, 1);
2667 GET_CHAR(cur_pos, cbuf, ch_len);
2669 /* fix line length for tabs */
2670 if (ch_len == 1 && *cbuf == '\t') {
2671 guint tab_width = text->default_tab_width;
2672 guint tab_offset = line_len % tab_width;
2675 g_print("found tab at pos=%d line_len=%d ", cur_pos,
2679 line_len += tab_width - tab_offset - 1;
2683 printf("new_len=%d\n", line_len);
2687 /* we have encountered line break */
2688 if (ch_len == 1 && *cbuf == '\n') {
2690 gchar cb[MB_LEN_MAX];
2692 /* should we join the next line */
2693 if ((autowrap || i_len != cur_len) && do_delete &&
2695 (text, cur_pos + 1, tlen, i_len, autowrap))
2701 g_print("found CR at %d do_del is %d next line is ",
2702 cur_pos, do_delete);
2703 dump_text(text, cur_pos + 1, tlen, 1);
2706 /* skip delete if it is continuous URL */
2707 if (do_delete && (line_pos - p_pos <= i_len) &&
2708 gtk_stext_is_uri_string(text, line_pos, tlen))
2712 g_print("l_len=%d wrap_len=%d do_del=%d\n",
2713 line_len, linewrap_len, do_delete);
2715 if (line_len < linewrap_len && do_delete) {
2717 /* get rid of newline */
2718 gtk_stext_set_point(text, cur_pos);
2719 gtk_stext_forward_delete(text, 1);
2722 /* if text starts with quote fmt or with
2723 indent string, delete them */
2726 ilen = gtk_stext_str_compare_n
2727 (text, cur_pos, p_pos, i_len,
2730 gtk_stext_forward_delete
2736 GET_CHAR(cur_pos, cb, clen);
2738 /* insert space if it's alphanumeric */
2739 if ((cur_pos != line_pos) &&
2740 ((clen > 1) || isalnum((guchar)cb[0]))) {
2741 gtk_stext_insert(text, NULL, NULL,
2746 /* and start over with current line */
2747 cur_pos = p_pos - 1;
2749 line_len = cur_len = 0;
2753 g_print("after delete l_pos=");
2754 dump_text(text, line_pos, tlen, 1);
2756 /* move beginning of line if we are on LF */
2757 GET_CHAR(line_pos, cb, clen);
2758 if (clen == 1 && *cb == '\n')
2761 g_print("new line_pos=%d\n", line_pos);
2767 /* mark new line beginning */
2768 line_pos = cur_pos + 1;
2769 line_len = cur_len = 0;
2780 /* possible line break */
2781 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2782 line_pos = cur_pos + 1;
2783 line_len = cur_len + ch_len;
2786 /* are we over wrapping length set in preferences ? */
2787 if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
2791 g_print("should wrap cur_pos=%d ", cur_pos);
2792 dump_text(text, p_pos, tlen, 1);
2793 dump_text(text, line_pos, tlen, 1);
2795 /* force wrapping if it is one long word but not URL */
2796 if (line_pos - p_pos <= i_len)
2797 if (!gtk_stext_is_uri_string
2798 (text, line_pos, tlen))
2799 line_pos = cur_pos - 1;
2801 g_print("new line_pos=%d\n", line_pos);
2804 GET_CHAR(line_pos - 1, cbuf, clen);
2806 /* if next character is space delete it */
2807 if (clen == 1 && isspace(*(guchar *)cbuf)) {
2808 if (p_pos + i_len != line_pos ||
2809 !gtk_stext_is_uri_string
2810 (text, line_pos, tlen)) {
2812 /* workaround for correct cursor
2814 if (set_editable_pos == FALSE) {
2815 editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2816 if (editable_pos == line_pos)
2817 set_editable_pos = TRUE;
2819 gtk_stext_set_point(text, line_pos);
2820 gtk_stext_backward_delete(text, 1);
2829 /* if it is URL at beginning of line don't wrap */
2830 if (p_pos + i_len == line_pos &&
2831 gtk_stext_is_uri_string(text, line_pos, tlen)) {
2833 g_print("found URL at ");
2834 dump_text(text, line_pos, tlen, 1);
2841 gtk_stext_set_point(text, line_pos);
2842 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2843 gtk_stext_compact_buffer(text);
2846 /* for loop will increase it */
2847 cur_pos = line_pos - 1;
2848 /* start over with current line */
2850 line_len = cur_len = 0;
2851 if (autowrap || i_len > 0)
2856 g_print("after CR insert ");
2857 dump_text(text, line_pos, tlen, 1);
2858 dump_text(text, cur_pos, tlen, 1);
2861 /* should we insert quotation ? */
2862 if (linewrap_quote && i_len) {
2863 /* only if line is not already quoted */
2864 if (!gtk_stext_str_compare
2865 (text, line_pos, tlen, qfmt)) {
2868 if (line_pos - p_pos > i_len) {
2870 (text, i_len, p_pos,
2875 g_print("after quote insert ");
2876 dump_text(text, line_pos, tlen, 1);
2884 line_pos = cur_pos + 1;
2885 line_len = cur_len + DISP_WIDTH(ch_len);
2887 /* advance to next character in buffer */
2888 cur_len += DISP_WIDTH(ch_len);
2892 gtk_stext_thaw(text);
2894 if (set_editable_pos && editable_pos <= tlen)
2895 gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
2901 static void compose_set_title(Compose *compose)
2906 edited = compose->modified ? _(" [Edited]") : "";
2907 if (compose->account && compose->account->address)
2908 str = g_strdup_printf(_("%s - Compose message%s"),
2909 compose->account->address, edited);
2911 str = g_strdup_printf(_("Compose message%s"), edited);
2912 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2917 * compose_current_mail_account:
2919 * Find a current mail account (the currently selected account, or the
2920 * default account, if a news account is currently selected). If a
2921 * mail account cannot be found, display an error message.
2923 * Return value: Mail account, or NULL if not found.
2925 static PrefsAccount *
2926 compose_current_mail_account(void)
2930 if (cur_account && cur_account->protocol != A_NNTP)
2933 ac = account_get_default();
2934 if (!ac || ac->protocol == A_NNTP) {
2935 alertpanel_error(_("Account for sending mail is not specified.\n"
2936 "Please select a mail account before sending."));
2943 static void compose_select_account(Compose *compose, PrefsAccount *account,
2946 GtkItemFactory *ifactory;
2948 g_return_if_fail(account != NULL);
2950 compose->account = account;
2952 compose_set_title(compose);
2954 ifactory = gtk_item_factory_from_widget(compose->menubar);
2956 if (account->protocol == A_NNTP) {
2957 gtk_widget_show(compose->newsgroups_hbox);
2958 gtk_widget_show(compose->newsgroups_entry);
2959 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2960 compose->use_newsgroups = TRUE;
2962 menu_set_active(ifactory, "/View/To", FALSE);
2963 menu_set_sensitive(ifactory, "/View/To", TRUE);
2964 menu_set_active(ifactory, "/View/Cc", FALSE);
2965 menu_set_sensitive(ifactory, "/View/Cc", TRUE);
2966 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
2968 gtk_widget_hide(compose->newsgroups_hbox);
2969 gtk_widget_hide(compose->newsgroups_entry);
2970 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
2971 gtk_widget_queue_resize(compose->table_vbox);
2972 compose->use_newsgroups = FALSE;
2974 menu_set_active(ifactory, "/View/To", TRUE);
2975 menu_set_sensitive(ifactory, "/View/To", FALSE);
2976 menu_set_active(ifactory, "/View/Cc", TRUE);
2977 menu_set_sensitive(ifactory, "/View/Cc", FALSE);
2978 menu_set_active(ifactory, "/View/Followup to", FALSE);
2979 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
2982 if (account->set_autocc) {
2983 compose_entry_show(compose, COMPOSE_ENTRY_CC);
2984 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
2985 compose_entry_set(compose, account->auto_cc,
2988 if (account->set_autobcc) {
2989 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
2990 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
2991 compose_entry_set(compose, account->auto_bcc,
2994 if (account->set_autoreplyto) {
2995 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
2996 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
2997 compose_entry_set(compose, account->auto_replyto,
2998 COMPOSE_ENTRY_REPLY_TO);
3003 if (account->default_sign)
3004 menu_set_active(ifactory, "/Options/Sign", TRUE);
3006 menu_set_active(ifactory, "/Options/Sign", FALSE);
3007 if (account->default_encrypt)
3008 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3010 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3012 activate_privacy_system(compose, account);
3014 if (!init && compose->mode != COMPOSE_REDIRECT)
3015 compose_insert_sig(compose, TRUE);
3018 gboolean compose_check_for_valid_recipient(Compose *compose) {
3019 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3020 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3021 gboolean recipient_found = FALSE;
3025 /* free to and newsgroup list */
3026 slist_free_strings(compose->to_list);
3027 g_slist_free(compose->to_list);
3028 compose->to_list = NULL;
3030 slist_free_strings(compose->newsgroup_list);
3031 g_slist_free(compose->newsgroup_list);
3032 compose->newsgroup_list = NULL;
3034 /* search header entries for to and newsgroup entries */
3035 for (list = compose->header_list; list; list = list->next) {
3038 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3039 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3041 if (entry[0] != '\0') {
3042 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3043 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3044 compose->to_list = address_list_append(compose->to_list, entry);
3045 recipient_found = TRUE;
3048 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3049 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3050 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3051 recipient_found = TRUE;
3058 return recipient_found;
3061 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3065 if (compose_check_for_valid_recipient(compose) == FALSE) {
3066 alertpanel_error(_("Recipient is not specified."));
3070 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3071 if (*str == '\0' && check_subject == TRUE) {
3074 aval = alertpanel(_("Send"),
3075 _("Subject is empty. Send it anyway?"),
3076 _("Yes"), _("No"), NULL);
3077 if (aval != G_ALERTDEFAULT)
3084 gint compose_send(Compose *compose)
3091 compose_allow_user_actions (compose, FALSE);
3092 compose->sending = TRUE;
3094 if (compose_check_entries(compose, TRUE) == FALSE)
3097 val = compose_queue(compose, &msgnum, &folder);
3100 alertpanel_error(_("Could not queue message for sending"));
3105 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3106 compose->sending = FALSE;
3107 gtk_widget_destroy(compose->window);
3108 /* No more compose access in the normal codepath
3109 * after this point! */
3113 alertpanel_error(_("The message was queued but could not be "
3114 "sent.\nUse \"Send queued messages\" from "
3115 "the main window to retry."));
3116 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3117 compose->sending = FALSE;
3118 compose_allow_user_actions (compose, TRUE);
3123 msgpath = folder_item_fetch_msg(folder, msgnum);
3124 val = procmsg_send_message_queue(msgpath);
3127 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3128 compose->sending = FALSE;
3129 compose_allow_user_actions (compose, TRUE);
3131 folder_item_remove_msg(folder, msgnum);
3132 folder_item_scan(folder);
3137 folder_item_remove_msg(folder, msgnum);
3138 folder_item_scan(folder);
3139 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3140 gtk_widget_destroy(compose->window);
3146 compose_allow_user_actions (compose, TRUE);
3147 compose->sending = FALSE;
3152 static gboolean compose_use_attach(Compose *compose)
3154 return gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL;
3157 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3160 gchar buf[BUFFSIZE];
3162 gboolean first_to_address;
3163 gboolean first_cc_address;
3165 ComposeHeaderEntry *headerentry;
3166 gchar *headerentryname;
3170 debug_print("Writing redirect header\n");
3172 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3173 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3175 first_to_address = TRUE;
3176 first_cc_address = TRUE;
3177 for (list = compose->header_list; list; list = list->next) {
3178 headerentry = ((ComposeHeaderEntry *)list->data);
3179 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3181 if (g_strcasecmp(headerentryname, cc_hdr) == 0
3182 || g_strcasecmp(headerentryname, to_hdr) == 0) {
3183 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3184 Xstrdup_a(str, str, return -1);
3186 if (str[0] != '\0') {
3187 compose_convert_header
3188 (buf, sizeof(buf), str,
3189 strlen("Resent-To") + 2, TRUE);
3190 if (g_strcasecmp(headerentryname, to_hdr) == 0) {
3191 if (first_to_address) {
3192 fprintf(fp, "Resent-To: ");
3193 first_to_address = FALSE;
3198 if (g_strcasecmp(headerentryname, cc_hdr) == 0) {
3199 if (first_cc_address) {
3201 fprintf(fp, "Resent-Cc: ");
3202 first_cc_address = FALSE;
3208 fprintf(fp, "%s", buf);
3212 /* if (!first_address) { */
3219 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3221 gchar buf[BUFFSIZE];
3223 /* struct utsname utsbuf; */
3225 g_return_val_if_fail(fp != NULL, -1);
3226 g_return_val_if_fail(compose->account != NULL, -1);
3227 g_return_val_if_fail(compose->account->address != NULL, -1);
3230 get_rfc822_date(buf, sizeof(buf));
3231 fprintf(fp, "Resent-Date: %s\n", buf);
3234 if (compose->account->name && *compose->account->name) {
3235 compose_convert_header
3236 (buf, sizeof(buf), compose->account->name,
3237 strlen("From: "), TRUE);
3238 fprintf(fp, "Resent-From: %s <%s>\n",
3239 buf, compose->account->address);
3241 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3244 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3246 Xstrdup_a(str, str, return -1);
3249 compose_convert_header(buf, sizeof(buf), str,
3250 strlen("Subject: "), FALSE);
3251 fprintf(fp, "Subject: %s\n", buf);
3255 /* Resent-Message-ID */
3256 if (compose->account->gen_msgid) {
3257 generate_msgid(compose->account->address, buf, sizeof(buf));
3258 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3259 compose->msgid = g_strdup(buf);
3262 compose_redirect_write_headers_from_headerlist(compose, fp);
3264 /* separator between header and body */
3270 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3274 gchar buf[BUFFSIZE];
3276 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3277 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3281 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3282 /* should filter returnpath, delivered-to */
3283 if (g_strncasecmp(buf, "Return-Path:",
3284 strlen("Return-Path:")) == 0 ||
3285 g_strncasecmp(buf, "Delivered-To:",
3286 strlen("Delivered-To:")) == 0 ||
3287 g_strncasecmp(buf, "Received:",
3288 strlen("Received:")) == 0 ||
3289 g_strncasecmp(buf, "Subject:",
3290 strlen("Subject:")) == 0 ||
3291 g_strncasecmp(buf, "X-UIDL:",
3292 strlen("X-UIDL:")) == 0)
3295 if (fputs(buf, fdest) == -1)
3298 if (!prefs_common.redirect_keep_from) {
3299 if (g_strncasecmp(buf, "From:",
3300 strlen("From:")) == 0) {
3301 fputs(" (by way of ", fdest);
3302 if (compose->account->name
3303 && *compose->account->name) {
3304 compose_convert_header
3306 compose->account->name,
3309 fprintf(fdest, "%s <%s>",
3311 compose->account->address);
3313 fprintf(fdest, "%s",
3314 compose->account->address);
3319 if (fputs("\n", fdest) == -1)
3323 compose_redirect_write_headers(compose, fdest);
3325 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3326 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
3339 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
3343 const gchar *out_codeset;
3344 EncodingType encoding;
3345 MimeInfo *mimemsg, *mimetext;
3347 /* create message MimeInfo */
3348 mimemsg = procmime_mimeinfo_new();
3349 mimemsg->type = MIMETYPE_MESSAGE;
3350 mimemsg->subtype = g_strdup("rfc822");
3351 mimemsg->content = MIMECONTENT_MEM;
3352 mimemsg->data.mem = compose_get_header(compose);
3354 /* Create text part MimeInfo */
3355 /* get all composed text */
3356 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3357 if (is_ascii_str(chars)) {
3360 out_codeset = CS_US_ASCII;
3361 encoding = ENC_7BIT;
3363 const gchar *src_codeset;
3365 out_codeset = conv_get_outgoing_charset_str();
3366 if (!g_strcasecmp(out_codeset, CS_US_ASCII))
3367 out_codeset = CS_ISO_8859_1;
3369 if (prefs_common.encoding_method == CTE_BASE64)
3370 encoding = ENC_BASE64;
3371 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3372 encoding = ENC_QUOTED_PRINTABLE;
3373 else if (prefs_common.encoding_method == CTE_8BIT)
3374 encoding = ENC_8BIT;
3376 encoding = procmime_get_encoding_for_charset(out_codeset);
3378 src_codeset = conv_get_current_charset_str();
3379 /* if current encoding is US-ASCII, set it the same as
3380 outgoing one to prevent code conversion failure */
3381 if (!g_strcasecmp(src_codeset, CS_US_ASCII))
3382 src_codeset = out_codeset;
3384 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3385 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3387 if (action == COMPOSE_WRITE_FOR_SEND) {
3388 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3393 msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
3395 "Send it anyway?"), src_codeset, out_codeset);
3396 aval = alertpanel_with_type
3397 (_("Error"), msg, _("Yes"), _("+No"), NULL, NULL, ALERT_ERROR);
3400 if (aval != G_ALERTDEFAULT) {
3405 out_codeset = src_codeset;
3411 out_codeset = src_codeset;
3417 mimetext = procmime_mimeinfo_new();
3418 mimetext->content = MIMECONTENT_MEM;
3419 mimetext->data.mem = buf;
3420 mimetext->type = MIMETYPE_TEXT;
3421 mimetext->subtype = g_strdup("plain");
3422 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
3423 g_strdup(out_codeset));
3425 /* append attachment parts */
3426 if (compose_use_attach(compose)) {
3427 MimeInfo *mimempart;
3429 mimempart = procmime_mimeinfo_new();
3430 mimempart->content = MIMECONTENT_EMPTY;
3431 mimempart->type = MIMETYPE_MULTIPART;
3432 mimempart->subtype = g_strdup("mixed");
3433 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
3434 generate_mime_boundary(NULL));
3436 mimetext->disposition = DISPOSITIONTYPE_INLINE;
3438 g_node_append(mimempart->node, mimetext->node);
3439 g_node_append(mimemsg->node, mimempart->node);
3441 compose_add_attachments(compose, mimempart);
3443 g_node_append(mimemsg->node, mimetext->node);
3446 if (compose->use_signing && privacy_system_can_sign(compose->privacy_system))
3447 if (!privacy_sign(compose->privacy_system, mimemsg))
3450 procmime_write_mimeinfo(mimemsg, fp);
3455 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3461 if ((fp = fopen(file, "wb")) == NULL) {
3462 FILE_OP_ERROR(file, "fopen");
3466 /* chmod for security */
3467 if (change_file_mode_rw(fp, file) < 0) {
3468 FILE_OP_ERROR(file, "chmod");
3469 g_warning("can't change file mode\n");
3472 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3475 len = strlen(chars);
3476 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3477 FILE_OP_ERROR(file, "fwrite");
3486 if (fclose(fp) == EOF) {
3487 FILE_OP_ERROR(file, "fclose");
3494 static gint compose_remove_reedit_target(Compose *compose)
3497 MsgInfo *msginfo = compose->targetinfo;
3499 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3500 if (!msginfo) return -1;
3502 item = msginfo->folder;
3503 g_return_val_if_fail(item != NULL, -1);
3505 if (procmsg_msg_exist(msginfo) &&
3506 (item->stype == F_DRAFT || item->stype == F_QUEUE
3507 || msginfo == compose->autosaved_draft)) {
3508 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3509 g_warning("can't remove the old message\n");
3517 void compose_remove_draft(Compose *compose)
3520 MsgInfo *msginfo = compose->targetinfo;
3521 drafts = account_get_special_folder(compose->account, F_DRAFT);
3523 if (procmsg_msg_exist(msginfo)) {
3524 folder_item_remove_msg(drafts, msginfo->msgnum);
3529 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3531 return compose_queue_sub (compose, msgnum, item, FALSE);
3533 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3540 static gboolean lock = FALSE;
3541 PrefsAccount *mailac = NULL, *newsac = NULL;
3543 debug_print("queueing message...\n");
3544 g_return_val_if_fail(compose->account != NULL, -1);
3548 if (compose_check_entries(compose, check_subject) == FALSE) {
3553 if (!compose->to_list && !compose->newsgroup_list) {
3554 g_warning("can't get recipient list.");
3559 if (compose->to_list) {
3560 if (compose->account->protocol != A_NNTP)
3561 mailac = compose->account;
3562 else if (cur_account && cur_account->protocol != A_NNTP)
3563 mailac = cur_account;
3564 else if (!(mailac = compose_current_mail_account())) {
3566 alertpanel_error(_("No account for sending mails available!"));
3571 if (compose->newsgroup_list) {
3572 if (compose->account->protocol == A_NNTP)
3573 newsac = compose->account;
3574 else if (!newsac->protocol != A_NNTP) {
3576 alertpanel_error(_("No account for posting news available!"));
3581 if (prefs_common.linewrap_at_send)
3582 compose_wrap_line_all(compose);
3584 /* write queue header */
3585 tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
3586 G_DIR_SEPARATOR, compose);
3587 if ((fp = fopen(tmp, "wb")) == NULL) {
3588 FILE_OP_ERROR(tmp, "fopen");
3593 if (change_file_mode_rw(fp, tmp) < 0) {
3594 FILE_OP_ERROR(tmp, "chmod");
3595 g_warning("can't change file mode\n");
3598 /* queueing variables */
3599 fprintf(fp, "AF:\n");
3600 fprintf(fp, "NF:0\n");
3601 fprintf(fp, "PS:10\n");
3602 fprintf(fp, "SRH:1\n");
3603 fprintf(fp, "SFN:\n");
3604 fprintf(fp, "DSR:\n");
3606 fprintf(fp, "MID:<%s>\n", compose->msgid);
3608 fprintf(fp, "MID:\n");
3609 fprintf(fp, "CFG:\n");
3610 fprintf(fp, "PT:0\n");
3611 fprintf(fp, "S:%s\n", compose->account->address);
3612 fprintf(fp, "RQ:\n");
3614 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3616 fprintf(fp, "SSV:\n");
3618 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3620 fprintf(fp, "NSV:\n");
3621 fprintf(fp, "SSH:\n");
3622 /* write recepient list */
3623 if (compose->to_list) {
3624 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
3625 for (cur = compose->to_list->next; cur != NULL;
3627 fprintf(fp, ",<%s>", (gchar *)cur->data);
3630 /* write newsgroup list */
3631 if (compose->newsgroup_list) {
3633 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3634 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3635 fprintf(fp, ",%s", (gchar *)cur->data);
3638 /* Sylpheed account IDs */
3640 fprintf(fp, "MAID:%d\n", mailac->account_id);
3642 fprintf(fp, "NAID:%d\n", newsac->account_id);
3644 if (compose->privacy_system != NULL) {
3645 fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
3646 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
3647 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
3648 if (compose->use_encryption) {
3651 encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
3652 fprintf(fp, "X-Sylpheed-Encrypt-Data:%s\n", encdata);
3657 /* Save copy folder */
3658 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3659 gchar *savefolderid;
3661 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3662 fprintf(fp, "SCF:%s\n", savefolderid);
3663 g_free(savefolderid);
3665 /* Message-ID of message replying to */
3666 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
3669 folderid = folder_item_get_identifier(compose->replyinfo->folder);
3670 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
3673 /* Message-ID of message forwarding to */
3674 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
3677 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
3678 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
3683 if (compose->redirect_filename != NULL) {
3684 if (compose_redirect_write_to_file(compose, fp) < 0) {
3692 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND) < 0) {
3701 if (fclose(fp) == EOF) {
3702 FILE_OP_ERROR(tmp, "fclose");
3708 queue = account_get_special_folder(compose->account, F_QUEUE);
3710 g_warning("can't find queue folder\n");
3715 folder_item_scan(queue);
3716 if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
3717 g_warning("can't queue the message\n");
3725 if (compose->mode == COMPOSE_REEDIT) {
3726 compose_remove_reedit_target(compose);
3729 if ((msgnum != NULL) && (item != NULL)) {
3737 static void compose_add_attachments(Compose *compose, MimeInfo *parent)
3740 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3743 struct stat statbuf;
3744 gchar *type, *subtype;
3746 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3748 mimepart = procmime_mimeinfo_new();
3749 mimepart->content = MIMECONTENT_FILE;
3750 mimepart->data.filename = g_strdup(ainfo->file);
3751 mimepart->offset = 0;
3753 stat(ainfo->file, &statbuf);
3754 mimepart->length = statbuf.st_size;
3756 type = g_strdup(ainfo->content_type);
3758 if (!strchr(type, '/')) {
3760 type = g_strdup("application/octet-stream");
3763 subtype = strchr(type, '/') + 1;
3764 *(subtype - 1) = '\0';
3765 mimepart->type = procmime_get_media_type(type);
3766 mimepart->subtype = g_strdup(subtype);
3769 if (mimepart->type == MIMETYPE_MESSAGE &&
3770 !g_strcasecmp(mimepart->subtype, "rfc822")) {
3771 mimepart->disposition = DISPOSITIONTYPE_INLINE;
3773 g_hash_table_insert(mimepart->typeparameters,
3774 g_strdup("name"), g_strdup(ainfo->name));
3775 g_hash_table_insert(mimepart->dispositionparameters,
3776 g_strdup("filename"), g_strdup(ainfo->name));
3777 mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
3780 procmime_encode_content(mimepart, ainfo->encoding);
3782 g_node_append(parent->node, mimepart->node);
3786 #define QUOTE_IF_REQUIRED(out, str) \
3788 if (*str != '"' && strpbrk(str, ",.[]<>")) { \
3792 len = strlen(str) + 3; \
3793 if ((__tmp = alloca(len)) == NULL) { \
3794 g_warning("can't allocate memory\n"); \
3795 g_string_free(header, TRUE); \
3798 g_snprintf(__tmp, len, "\"%s\"", str); \
3803 if ((__tmp = alloca(strlen(str) + 1)) == NULL) { \
3804 g_warning("can't allocate memory\n"); \
3805 g_string_free(header, TRUE); \
3808 strcpy(__tmp, str); \
3814 #define IS_IN_CUSTOM_HEADER(header) \
3815 (compose->account->add_customhdr && \
3816 custom_header_find(compose->account->customhdr_list, header) != NULL)
3818 static void compose_add_headerfield_from_headerlist(Compose *compose,
3820 const gchar *fieldname,
3821 const gchar *seperator)
3823 gchar *str, *fieldname_w_colon, *trans_fieldname;
3824 gboolean add_field = FALSE;
3826 ComposeHeaderEntry *headerentry;
3827 gchar * headerentryname;
3830 if (IS_IN_CUSTOM_HEADER(fieldname))
3833 debug_print("Adding %s-fields\n", fieldname);
3835 fieldstr = g_string_sized_new(64);
3837 fieldname_w_colon = g_strconcat(fieldname, ":", NULL);
3838 trans_fieldname = (prefs_common.trans_hdr ? gettext(fieldname_w_colon) : fieldname_w_colon);
3840 for (list = compose->header_list; list; list = list->next) {
3841 headerentry = ((ComposeHeaderEntry *)list->data);
3842 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3844 if (!g_strcasecmp(trans_fieldname, headerentryname)) {
3845 str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
3847 if (str[0] != '\0') {
3849 g_string_append(fieldstr, seperator);
3850 g_string_append(fieldstr, str);
3859 buf = g_new0(gchar, fieldstr->len * 4 + 256);
3860 compose_convert_header
3861 (buf, fieldstr->len * 4 + 256, fieldstr->str,
3862 strlen(fieldname) + 2, TRUE);
3863 g_string_sprintfa(header, "%s: %s\n", fieldname, buf);
3867 g_free(fieldname_w_colon);
3868 g_string_free(fieldstr, TRUE);
3873 static gchar *compose_get_header(Compose *compose)
3875 gchar buf[BUFFSIZE];
3879 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3882 /* struct utsname utsbuf; */
3884 g_return_val_if_fail(compose->account != NULL, NULL);
3885 g_return_val_if_fail(compose->account->address != NULL, NULL);
3887 header = g_string_sized_new(64);
3890 if (compose->account->add_date) {
3891 get_rfc822_date(buf, sizeof(buf));
3892 g_string_sprintfa(header, "Date: %s\n", buf);
3896 if (compose->account->name && *compose->account->name) {
3897 compose_convert_header
3898 (buf, sizeof(buf), compose->account->name,
3899 strlen("From: "), TRUE);
3900 QUOTE_IF_REQUIRED(name, buf);
3901 g_string_sprintfa(header, "From: %s <%s>\n",
3902 name, compose->account->address);
3904 g_string_sprintfa(header, "From: %s\n", compose->account->address);
3907 compose_add_headerfield_from_headerlist(compose, header, "To", ", ");
3910 compose_add_headerfield_from_headerlist(compose, header, "Newsgroups", ",");
3913 compose_add_headerfield_from_headerlist(compose, header, "Cc", ", ");
3916 compose_add_headerfield_from_headerlist(compose, header, "Bcc", ", ");
3919 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3920 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3923 tmpstr = g_strdup(str);
3924 if (tmpstr == NULL) {
3925 g_string_free(header, TRUE);
3930 compose_convert_header(buf, sizeof(buf), str,
3931 strlen("Subject: "), FALSE);
3932 g_string_sprintfa(header, "Subject: %s\n", buf);
3938 if (compose->account->gen_msgid) {
3939 generate_msgid(compose->account->address, buf, sizeof(buf));
3940 g_string_sprintfa(header, "Message-ID: <%s>\n", buf);
3941 compose->msgid = g_strdup(buf);
3944 if (compose->remove_references == FALSE) {
3946 if (compose->inreplyto && compose->to_list)
3947 g_string_sprintfa(header, "In-Reply-To: <%s>\n", compose->inreplyto);
3950 if (compose->references)
3951 g_string_sprintfa(header, "References: %s\n", compose->references);
3955 compose_add_headerfield_from_headerlist(compose, header, "Followup-To", ",");
3958 compose_add_headerfield_from_headerlist(compose, header, "Reply-To", ", ");
3961 if (compose->account->organization &&
3962 !IS_IN_CUSTOM_HEADER("Organization")) {
3963 compose_convert_header(buf, sizeof(buf),
3964 compose->account->organization,
3965 strlen("Organization: "), FALSE);
3966 g_string_sprintfa(header, "Organization: %s\n", buf);
3969 /* Program version and system info */
3970 /* uname(&utsbuf); */
3971 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer") &&
3972 !compose->newsgroup_list) {
3973 g_string_sprintfa(header, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3975 gtk_major_version, gtk_minor_version, gtk_micro_version,
3977 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3979 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3980 g_string_sprintfa(header, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3982 gtk_major_version, gtk_minor_version, gtk_micro_version,
3984 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3987 /* custom headers */
3988 if (compose->account->add_customhdr) {
3991 for (cur = compose->account->customhdr_list; cur != NULL;
3993 CustomHeader *chdr = (CustomHeader *)cur->data;
3995 if (custom_header_is_allowed(chdr->name)) {
3996 compose_convert_header
3998 chdr->value ? chdr->value : "",
3999 strlen(chdr->name) + 2, FALSE);
4000 g_string_sprintfa(header, "%s: %s\n", chdr->name, buf);
4006 switch (compose->priority) {
4007 case PRIORITY_HIGHEST: g_string_sprintfa(header, "Importance: high\n"
4008 "X-Priority: 1 (Highest)\n");
4010 case PRIORITY_HIGH: g_string_sprintfa(header, "Importance: high\n"
4011 "X-Priority: 2 (High)\n");
4013 case PRIORITY_NORMAL: break;
4014 case PRIORITY_LOW: g_string_sprintfa(header, "Importance: low\n"
4015 "X-Priority: 4 (Low)\n");
4017 case PRIORITY_LOWEST: g_string_sprintfa(header, "Importance: low\n"
4018 "X-Priority: 5 (Lowest)\n");
4020 default: debug_print("compose: priority unknown : %d\n",
4024 /* Request Return Receipt */
4025 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4026 if (compose->return_receipt) {
4027 if (compose->account->name
4028 && *compose->account->name) {
4029 compose_convert_header(buf, sizeof(buf),
4030 compose->account->name,
4031 strlen("Disposition-Notification-To: "),
4033 g_string_sprintfa(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4035 g_string_sprintfa(header, "Disposition-Notification-To: %s\n", compose->account->address);
4039 /* get special headers */
4040 for (list = compose->header_list; list; list = list->next) {
4041 ComposeHeaderEntry *headerentry;
4044 gchar *headername_wcolon;
4045 gchar *headername_trans;
4048 gboolean standard_header = FALSE;
4050 headerentry = ((ComposeHeaderEntry *)list->data);
4052 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4053 if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
4058 if (!strstr(tmp, ":")) {
4059 headername_wcolon = g_strconcat(tmp, ":", NULL);
4060 headername = g_strdup(tmp);
4062 headername_wcolon = g_strdup(tmp);
4063 headername = g_strdup(strtok(tmp, ":"));
4067 headervalue = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4068 subst_char(headervalue, '\r', ' ');
4069 subst_char(headervalue, '\n', ' ');
4070 string = std_headers;
4071 while (*string != NULL) {
4072 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4073 if (!strcmp(headername_trans,headername_wcolon))
4074 standard_header = TRUE;
4077 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4078 g_string_sprintfa(header, "%s %s\n", headername_wcolon, headervalue);
4081 g_free(headername_wcolon);
4085 g_string_free(header, FALSE);
4090 #undef IS_IN_CUSTOM_HEADER
4092 static void compose_convert_header(gchar *dest, gint len, gchar *src,
4093 gint header_len, gboolean addr_field)
4095 g_return_if_fail(src != NULL);
4096 g_return_if_fail(dest != NULL);
4098 if (len < 1) return;
4100 subst_char(src, '\n', ' ');
4101 subst_char(src, '\r', ' ');
4104 conv_encode_header(dest, len, src, header_len, addr_field);
4107 static void compose_create_header_entry(Compose *compose)
4109 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4113 GList *combo_list = NULL;
4114 gchar **string, *header = NULL;
4115 ComposeHeaderEntry *headerentry;
4116 gboolean standard_header = FALSE;
4118 headerentry = g_new0(ComposeHeaderEntry, 1);
4121 combo = gtk_combo_new();
4123 while(*string != NULL) {
4124 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4127 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4128 g_list_free(combo_list);
4129 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4130 gtk_widget_show(combo);
4131 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4132 if (compose->header_last) {
4133 gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4135 while (*string != NULL) {
4136 if (!strcmp(*string, last_header_entry))
4137 standard_header = TRUE;
4140 if (standard_header)
4141 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4143 if (!compose->header_last || !standard_header) {
4144 switch(compose->account->protocol) {
4146 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4149 header = prefs_common.trans_hdr ? _("To:") : "To:";
4154 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4157 entry = gtk_entry_new();
4158 gtk_widget_show(entry);
4159 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);
4161 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4162 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4163 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4164 gtk_signal_connect(GTK_OBJECT(entry), "button-press-event",
4165 GTK_SIGNAL_FUNC(compose_headerentry_button_pressed),
4168 address_completion_register_entry(GTK_ENTRY(entry));
4170 headerentry->compose = compose;
4171 headerentry->combo = combo;
4172 headerentry->entry = entry;
4173 headerentry->headernum = compose->header_nextrow;
4175 compose->header_nextrow++;
4176 compose->header_last = headerentry;
4179 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4181 ComposeHeaderEntry *last_header;
4183 last_header = compose->header_last;
4185 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4186 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4189 static GtkWidget *compose_create_header(Compose *compose)
4193 GtkWidget *from_optmenu_hbox;
4194 #if 0 /* NEW COMPOSE GUI */
4195 GtkWidget *to_entry;
4197 GtkWidget *newsgroups_entry;
4198 GtkWidget *newsgroups_hbox;
4200 GtkWidget *header_scrolledwin;
4201 GtkWidget *header_table;
4202 #if 0 /* NEW COMPOSE GUI */
4203 GtkWidget *cc_entry;
4205 GtkWidget *bcc_entry;
4206 GtkWidget *bcc_hbox;
4207 GtkWidget *reply_entry;
4208 GtkWidget *reply_hbox;
4209 GtkWidget *followup_entry;
4210 GtkWidget *followup_hbox;
4215 /* header labels and entries */
4216 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4217 gtk_widget_show(header_scrolledwin);
4218 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4220 header_table = gtk_table_new(2, 2, FALSE);
4221 gtk_widget_show(header_table);
4222 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4223 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4224 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4227 /* option menu for selecting accounts */
4228 hbox = gtk_hbox_new(FALSE, 0);
4229 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4230 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4231 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4233 from_optmenu_hbox = compose_account_option_menu_create(compose);
4234 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4235 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4236 #if 0 /* NEW COMPOSE GUI */
4237 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4241 compose->header_table = header_table;
4242 compose->header_list = NULL;
4243 compose->header_nextrow = count;
4245 compose_create_header_entry(compose);
4247 #if 0 /* NEW COMPOSE GUI */
4248 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4250 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4251 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4252 &count, "Newsgroups:", FALSE);
4253 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4255 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4257 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4259 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4260 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4262 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4263 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4265 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4266 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4267 "Followup-To:", FALSE);
4268 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4270 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4272 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4273 GTK_SIGNAL_FUNC(to_activated), compose);
4274 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4275 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4276 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4277 GTK_SIGNAL_FUNC(subject_activated), compose);
4278 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4279 GTK_SIGNAL_FUNC(cc_activated), compose);
4280 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4281 GTK_SIGNAL_FUNC(bcc_activated), compose);
4282 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4283 GTK_SIGNAL_FUNC(replyto_activated), compose);
4284 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4285 GTK_SIGNAL_FUNC(followupto_activated), compose);
4287 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4288 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4289 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4290 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4291 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4292 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4293 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4294 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4295 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4296 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4297 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4298 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4299 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4300 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4303 compose->table = NULL;
4304 #if 0 /* NEW COMPOSE GUI */
4305 compose->table = table;
4306 compose->to_hbox = to_hbox;
4307 compose->to_entry = to_entry;
4308 compose->newsgroups_hbox = newsgroups_hbox;
4309 compose->newsgroups_entry = newsgroups_entry;
4311 #if 0 /* NEW COMPOSE GUI */
4312 compose->cc_hbox = cc_hbox;
4313 compose->cc_entry = cc_entry;
4314 compose->bcc_hbox = bcc_hbox;
4315 compose->bcc_entry = bcc_entry;
4316 compose->reply_hbox = reply_hbox;
4317 compose->reply_entry = reply_entry;
4318 compose->followup_hbox = followup_hbox;
4319 compose->followup_entry = followup_entry;
4322 return header_scrolledwin ;
4325 GtkWidget *compose_create_attach(Compose *compose)
4327 gchar *titles[N_ATTACH_COLS];
4330 GtkWidget *attach_scrwin;
4331 GtkWidget *attach_clist;
4333 titles[COL_MIMETYPE] = _("MIME type");
4334 titles[COL_SIZE] = _("Size");
4335 titles[COL_NAME] = _("Name");
4337 /* attachment list */
4338 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4339 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4340 GTK_POLICY_AUTOMATIC,
4342 gtk_widget_set_usize(attach_scrwin, -1, 80);
4344 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4345 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4347 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4348 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4349 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4350 GTK_SELECTION_EXTENDED);
4351 for (i = 0; i < N_ATTACH_COLS; i++)
4352 GTK_WIDGET_UNSET_FLAGS
4353 (GTK_CLIST(attach_clist)->column[i].button,
4355 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4357 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4358 GTK_SIGNAL_FUNC(attach_selected), compose);
4359 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4360 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4361 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4362 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4365 gtk_drag_dest_set(attach_clist,
4366 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4367 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4368 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4369 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4372 compose->attach_scrwin = attach_scrwin;
4373 compose->attach_clist = attach_clist;
4375 return attach_scrwin;
4378 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4379 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4381 static GtkWidget *compose_create_others(Compose *compose)
4384 GtkWidget *savemsg_checkbtn;
4385 GtkWidget *savemsg_entry;
4386 GtkWidget *savemsg_select;
4389 gchar *folderidentifier;
4391 /* Table for settings */
4392 table = gtk_table_new(3, 1, FALSE);
4393 gtk_widget_show(table);
4394 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4397 /* Save Message to folder */
4398 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4399 gtk_widget_show(savemsg_checkbtn);
4400 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4401 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4402 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4404 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4405 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4407 savemsg_entry = gtk_entry_new();
4408 gtk_widget_show(savemsg_entry);
4409 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4410 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4411 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4412 folderidentifier = folder_item_get_identifier(account_get_special_folder
4413 (compose->account, F_OUTBOX));
4414 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4415 g_free(folderidentifier);
4418 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4419 gtk_widget_show (savemsg_select);
4420 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4421 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4422 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4427 compose->savemsg_checkbtn = savemsg_checkbtn;
4428 compose->savemsg_entry = savemsg_entry;
4433 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4435 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4436 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4439 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4444 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4447 path = folder_item_get_identifier(dest);
4449 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4453 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4459 GtkWidget *handlebox;
4461 GtkWidget *notebook;
4466 GtkWidget *subject_hbox;
4467 GtkWidget *subject_frame;
4468 GtkWidget *subject_entry;
4472 GtkWidget *edit_vbox;
4473 GtkWidget *ruler_hbox;
4475 GtkWidget *scrolledwin;
4478 UndoMain *undostruct;
4480 gchar *titles[N_ATTACH_COLS];
4481 guint n_menu_entries;
4482 GtkStyle *style, *new_style;
4485 gboolean success[1];
4486 GtkWidget *popupmenu;
4487 GtkItemFactory *popupfactory;
4488 GtkItemFactory *ifactory;
4489 GtkWidget *tmpl_menu;
4493 GtkAspell * gtkaspell = NULL;
4496 static GdkGeometry geometry;
4498 g_return_val_if_fail(account != NULL, NULL);
4500 debug_print("Creating compose window...\n");
4501 compose = g_new0(Compose, 1);
4503 titles[COL_MIMETYPE] = _("MIME type");
4504 titles[COL_SIZE] = _("Size");
4505 titles[COL_NAME] = _("Name");
4507 compose->account = account;
4509 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4510 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4511 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4512 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4514 if (!geometry.max_width) {
4515 geometry.max_width = gdk_screen_width();
4516 geometry.max_height = gdk_screen_height();
4518 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4519 &geometry, GDK_HINT_MAX_SIZE);
4520 gtk_widget_set_uposition(window, prefs_common.compose_x,
4521 prefs_common.compose_y);
4522 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4523 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4524 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4525 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4526 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4527 gtk_widget_realize(window);
4529 gtkut_widget_set_composer_icon(window);
4531 vbox = gtk_vbox_new(FALSE, 0);
4532 gtk_container_add(GTK_CONTAINER(window), vbox);
4534 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4535 menubar = menubar_create(window, compose_entries,
4536 n_menu_entries, "<Compose>", compose);
4537 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4539 handlebox = gtk_handle_box_new();
4540 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4542 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
4545 vbox2 = gtk_vbox_new(FALSE, 2);
4546 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4547 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4550 notebook = gtk_notebook_new();
4551 gtk_widget_set_usize(notebook, -1, 130);
4552 gtk_widget_show(notebook);
4554 /* header labels and entries */
4555 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4556 /* attachment list */
4557 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4559 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4562 subject_hbox = gtk_hbox_new(FALSE, 0);
4563 gtk_widget_show(subject_hbox);
4565 subject_frame = gtk_frame_new(NULL);
4566 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4567 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4568 gtk_widget_show(subject_frame);
4570 subject = gtk_hbox_new(FALSE, 0);
4571 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4572 gtk_widget_show(subject);
4574 label = gtk_label_new(_("Subject:"));
4575 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4576 gtk_widget_show(label);
4578 subject_entry = gtk_entry_new();
4579 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4580 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4581 gtk_widget_show(subject_entry);
4582 compose->subject_entry = subject_entry;
4583 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4585 edit_vbox = gtk_vbox_new(FALSE, 0);
4587 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4590 ruler_hbox = gtk_hbox_new(FALSE, 0);
4591 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4593 ruler = gtk_shruler_new();
4594 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4595 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4597 gtk_widget_set_usize(ruler_hbox, 1, -1);
4600 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4601 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4602 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4603 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4604 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4606 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4607 (GTK_SCROLLED_WINDOW(scrolledwin)),
4608 gtk_scrolled_window_get_vadjustment
4609 (GTK_SCROLLED_WINDOW(scrolledwin)));
4610 GTK_STEXT(text)->default_tab_width = 8;
4611 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4613 if (prefs_common.block_cursor) {
4614 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4617 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4619 gtk_signal_connect(GTK_OBJECT(text), "changed",
4620 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4621 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4622 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4623 gtk_signal_connect(GTK_OBJECT(text), "activate",
4624 GTK_SIGNAL_FUNC(text_activated), compose);
4625 gtk_signal_connect(GTK_OBJECT(text), "insert_text",
4626 GTK_SIGNAL_FUNC(text_inserted), compose);
4627 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4628 GTK_SIGNAL_FUNC(compose_button_press_cb),
4631 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4632 GTK_SIGNAL_FUNC(compose_key_press_cb),
4635 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4636 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4640 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4641 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4642 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4643 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4645 gtk_widget_show_all(vbox);
4647 /* pane between attach clist and text */
4648 paned = gtk_vpaned_new();
4649 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4650 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4651 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4652 gtk_paned_add1(GTK_PANED(paned), notebook);
4653 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4654 gtk_widget_show_all(paned);
4656 style = gtk_widget_get_style(text);
4658 /* workaround for the slow down of GtkSText when using Pixmap theme */
4659 if (style->engine) {
4660 GtkThemeEngine *engine;
4662 engine = style->engine;
4663 style->engine = NULL;
4664 new_style = gtk_style_copy(style);
4665 style->engine = engine;
4667 new_style = gtk_style_copy(style);
4669 if (prefs_common.textfont) {
4672 if ((font = gtkut_font_load(prefs_common.textfont)) != NULL) {
4673 gdk_font_unref(new_style->font);
4674 new_style->font = font;
4678 gtk_widget_set_style(text, new_style);
4680 color[0] = quote_color;
4681 cmap = gdk_window_get_colormap(window->window);
4682 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4683 if (success[0] == FALSE) {
4684 g_warning("Compose: color allocation failed.\n");
4685 style = gtk_widget_get_style(text);
4686 quote_color = style->black;
4689 n_entries = sizeof(compose_popup_entries) /
4690 sizeof(compose_popup_entries[0]);
4691 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4692 "<Compose>", &popupfactory,
4695 ifactory = gtk_item_factory_from_widget(menubar);
4696 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4697 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4698 menu_set_sensitive(ifactory, "/Options/Remove references", FALSE);
4700 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4702 undostruct = undo_init(text);
4703 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4706 address_completion_start(window);
4708 compose->window = window;
4709 compose->vbox = vbox;
4710 compose->menubar = menubar;
4711 compose->handlebox = handlebox;
4713 compose->vbox2 = vbox2;
4715 compose->paned = paned;
4717 compose->edit_vbox = edit_vbox;
4718 compose->ruler_hbox = ruler_hbox;
4719 compose->ruler = ruler;
4720 compose->scrolledwin = scrolledwin;
4721 compose->text = text;
4723 compose->focused_editable = NULL;
4725 compose->popupmenu = popupmenu;
4726 compose->popupfactory = popupfactory;
4728 compose->tmpl_menu = tmpl_menu;
4730 compose->mode = mode;
4732 compose->targetinfo = NULL;
4733 compose->replyinfo = NULL;
4734 compose->fwdinfo = NULL;
4736 compose->replyto = NULL;
4738 compose->bcc = NULL;
4739 compose->followup_to = NULL;
4741 compose->ml_post = NULL;
4743 compose->inreplyto = NULL;
4744 compose->references = NULL;
4745 compose->msgid = NULL;
4746 compose->boundary = NULL;
4748 compose->autowrap = prefs_common.autowrap;
4750 compose->use_signing = FALSE;
4751 compose->use_encryption = FALSE;
4752 compose->privacy_system = NULL;
4754 compose->modified = FALSE;
4756 compose->return_receipt = FALSE;
4758 compose->to_list = NULL;
4759 compose->newsgroup_list = NULL;
4761 compose->undostruct = undostruct;
4763 compose->sig_str = NULL;
4765 compose->exteditor_file = NULL;
4766 compose->exteditor_pid = -1;
4767 compose->exteditor_readdes = -1;
4768 compose->exteditor_tag = -1;
4769 compose->draft_timeout_tag = -1;
4772 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4773 if (mode != COMPOSE_REDIRECT) {
4774 if (prefs_common.enable_aspell && prefs_common.dictionary &&
4775 strcmp(prefs_common.dictionary, _("None"))) {
4776 gtkaspell = gtkaspell_new(prefs_common.aspell_path,
4777 prefs_common.dictionary,
4778 conv_get_current_charset_str(),
4779 prefs_common.misspelled_col,
4780 prefs_common.check_while_typing,
4781 prefs_common.use_alternate,
4784 alertpanel_error(_("Spell checker could not "
4786 gtkaspell_checkers_strerror());
4787 gtkaspell_checkers_reset_error();
4790 GtkWidget *menuitem;
4792 if (!gtkaspell_set_sug_mode(gtkaspell,
4793 prefs_common.aspell_sugmode)) {
4794 debug_print("Aspell: could not set "
4795 "suggestion mode %s\n",
4796 gtkaspell_checkers_strerror());
4797 gtkaspell_checkers_reset_error();
4800 menuitem = gtk_item_factory_get_item(ifactory,
4801 "/Spelling/Spelling Configuration");
4802 gtkaspell_populate_submenu(gtkaspell, menuitem);
4803 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4807 compose->gtkaspell = gtkaspell;
4810 compose_select_account(compose, account, TRUE);
4812 menu_set_active(ifactory, "/Edit/Auto wrapping", prefs_common.autowrap);
4813 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
4814 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4816 if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT)
4817 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4819 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
4820 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4823 if (account->protocol != A_NNTP)
4824 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4826 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4828 addressbook_set_target_compose(compose);
4830 if (mode != COMPOSE_REDIRECT)
4831 compose_set_template_menu(compose);
4833 GtkWidget *menuitem;
4834 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4835 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
4838 compose_list = g_list_append(compose_list, compose);
4840 if (!prefs_common.show_ruler)
4841 gtk_widget_hide(ruler_hbox);
4844 compose->priority = PRIORITY_NORMAL;
4845 compose_update_priority_menu_item(compose);
4848 compose_update_actions_menu(compose);
4850 /* Privacy Systems menu */
4851 compose_update_privacy_systems_menu(compose);
4853 activate_privacy_system(compose, account);
4854 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
4855 gtk_widget_show(window);
4860 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4866 gint num = 0, def_menu = 0;
4868 accounts = account_get_list();
4869 g_return_val_if_fail(accounts != NULL, NULL);
4871 hbox = gtk_hbox_new(FALSE, 0);
4872 optmenu = gtk_option_menu_new();
4873 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4874 menu = gtk_menu_new();
4876 for (; accounts != NULL; accounts = accounts->next, num++) {
4877 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4878 GtkWidget *menuitem;
4881 if (ac == compose->account) def_menu = num;
4884 name = g_strdup_printf("%s: %s <%s>",
4886 ac->name, ac->address);
4888 name = g_strdup_printf("%s: %s",
4889 ac->account_name, ac->address);
4890 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
4892 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4893 GTK_SIGNAL_FUNC(account_activated),
4897 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4898 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4903 static void compose_set_priority_cb(gpointer data,
4907 Compose *compose = (Compose *) data;
4908 compose->priority = action;
4911 static void compose_update_priority_menu_item(Compose * compose)
4913 GtkItemFactory *ifactory;
4914 GtkWidget *menuitem = NULL;
4916 ifactory = gtk_item_factory_from_widget(compose->menubar);
4918 switch (compose->priority) {
4919 case PRIORITY_HIGHEST:
4920 menuitem = gtk_item_factory_get_item
4921 (ifactory, "/Options/Priority/Highest");
4924 menuitem = gtk_item_factory_get_item
4925 (ifactory, "/Options/Priority/High");
4927 case PRIORITY_NORMAL:
4928 menuitem = gtk_item_factory_get_item
4929 (ifactory, "/Options/Priority/Normal");
4932 menuitem = gtk_item_factory_get_item
4933 (ifactory, "/Options/Priority/Low");
4935 case PRIORITY_LOWEST:
4936 menuitem = gtk_item_factory_get_item
4937 (ifactory, "/Options/Priority/Lowest");
4940 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4943 static void compose_set_privacy_system_cb(gpointer data,
4947 Compose *compose = (Compose *) data;
4949 GtkItemFactory *ifactory;
4950 gboolean can_sign = FALSE, can_encrypt = FALSE;
4952 systemid = gtk_object_get_data(GTK_OBJECT(widget), "privacy_system");
4953 g_free(compose->privacy_system);
4954 compose->privacy_system = NULL;
4955 if (systemid != NULL) {
4956 compose->privacy_system = g_strdup(systemid);
4958 can_sign = privacy_system_can_sign(systemid);
4959 can_encrypt = privacy_system_can_encrypt(systemid);
4962 ifactory = gtk_item_factory_from_widget(compose->menubar);
4963 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
4964 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
4967 static void compose_update_privacy_system_menu_item(Compose * compose)
4969 static gchar *branch_path = "/Options/Privacy System";
4970 GtkItemFactory *ifactory;
4971 GtkWidget *menuitem = NULL;
4973 gboolean can_sign = FALSE, can_encrypt = FALSE;
4975 ifactory = gtk_item_factory_from_widget(compose->menubar);
4977 if (compose->privacy_system != NULL) {
4980 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
4981 g_return_if_fail(menuitem != NULL);
4983 amenu = GTK_MENU_SHELL(menuitem)->children;
4985 while (amenu != NULL) {
4986 GList *alist = amenu->next;
4988 systemid = gtk_object_get_data(GTK_OBJECT(amenu->data), "privacy_system");
4989 if (systemid != NULL)
4990 if (strcmp(systemid, compose->privacy_system) == 0) {
4991 menuitem = GTK_WIDGET(amenu->data);
4993 can_sign = privacy_system_can_sign(systemid);
4994 can_encrypt = privacy_system_can_encrypt(systemid);
5001 if (menuitem != NULL)
5002 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5005 menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
5006 menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
5009 static void compose_set_template_menu(Compose *compose)
5011 GSList *tmpl_list, *cur;
5015 tmpl_list = template_get_config();
5017 menu = gtk_menu_new();
5019 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5020 Template *tmpl = (Template *)cur->data;
5022 item = gtk_menu_item_new_with_label(tmpl->name);
5023 gtk_menu_append(GTK_MENU(menu), item);
5024 gtk_signal_connect(GTK_OBJECT(item), "activate",
5025 GTK_SIGNAL_FUNC(compose_template_activate_cb),
5027 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
5028 gtk_widget_show(item);
5031 gtk_widget_show(menu);
5032 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5035 void compose_update_actions_menu(Compose *compose)
5037 GtkItemFactory *ifactory;
5039 ifactory = gtk_item_factory_from_widget(compose->menubar);
5040 action_update_compose_menu(ifactory, "/Tools/Actions", compose);
5043 void compose_update_privacy_systems_menu(Compose *compose)
5045 static gchar *branch_path = "/Options/Privacy System";
5046 GtkItemFactory *ifactory;
5047 GtkWidget *menuitem;
5049 GSList *systems, *cur;
5051 GtkItemFactoryEntry ifentry = {NULL, NULL, NULL, 0, "<Branch>"};
5054 ifactory = gtk_item_factory_from_widget(compose->menubar);
5056 /* remove old entries */
5057 ifentry.path = branch_path;
5058 menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
5059 g_return_if_fail(menuitem != NULL);
5061 amenu = GTK_MENU_SHELL(menuitem)->children->next;
5062 while (amenu != NULL) {
5063 GList *alist = amenu->next;
5064 gtk_widget_destroy(GTK_WIDGET(amenu->data));
5068 ifentry.accelerator = NULL;
5069 ifentry.callback_action = 0;
5070 ifentry.callback = compose_set_privacy_system_cb;
5071 ifentry.item_type = "/Options/Privacy System/None";
5073 systems = privacy_get_system_ids();
5074 for (cur = systems; cur != NULL; cur = g_slist_next(cur)) {
5075 gchar *systemid = cur->data;
5077 menu_path = g_strdup_printf("%s/%s", branch_path,
5078 privacy_system_get_name(systemid));
5079 ifentry.path = menu_path;
5080 gtk_item_factory_create_item(ifactory, &ifentry, compose, 1);
5081 widget = gtk_item_factory_get_widget(ifactory, menu_path);
5083 gtk_object_set_data_full(GTK_OBJECT(widget), "privacy_system",
5084 g_strdup(systemid), g_free);
5089 g_slist_free(systems);
5092 void compose_reflect_prefs_all(void)
5097 for (cur = compose_list; cur != NULL; cur = cur->next) {
5098 compose = (Compose *)cur->data;
5099 compose_set_template_menu(compose);
5103 void compose_reflect_prefs_pixmap_theme(void)
5108 for (cur = compose_list; cur != NULL; cur = cur->next) {
5109 compose = (Compose *)cur->data;
5110 toolbar_update(TOOLBAR_COMPOSE, compose);
5114 static void compose_template_apply(Compose *compose, Template *tmpl,
5120 if (!tmpl || !tmpl->value) return;
5122 gtk_stext_freeze(GTK_STEXT(compose->text));
5124 if (tmpl->subject && *tmpl->subject != '\0')
5125 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5127 if (tmpl->to && *tmpl->to != '\0')
5128 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5129 if (tmpl->cc && *tmpl->cc != '\0')
5130 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5132 if (tmpl->bcc && *tmpl->bcc != '\0')
5133 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5136 gtkut_stext_clear(GTK_STEXT(compose->text));
5138 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
5139 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5142 if (prefs_common.quotemark && *prefs_common.quotemark)
5143 qmark = prefs_common.quotemark;
5147 if (compose->replyinfo != NULL)
5148 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5149 tmpl->value, qmark, NULL);
5150 else if (compose->fwdinfo != NULL)
5151 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
5152 tmpl->value, qmark, NULL);
5157 if (replace && parsed_str && compose->account->auto_sig)
5158 compose_insert_sig(compose, FALSE);
5160 if (replace && parsed_str) {
5161 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
5162 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
5166 compose_changed_cb(NULL, compose);
5168 gtk_stext_thaw(GTK_STEXT(compose->text));
5171 static void compose_destroy(Compose *compose)
5174 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5177 /* NOTE: address_completion_end() does nothing with the window
5178 * however this may change. */
5179 address_completion_end(compose->window);
5181 slist_free_strings(compose->to_list);
5182 g_slist_free(compose->to_list);
5183 slist_free_strings(compose->newsgroup_list);
5184 g_slist_free(compose->newsgroup_list);
5185 slist_free_strings(compose->header_list);
5186 g_slist_free(compose->header_list);
5188 procmsg_msginfo_free(compose->targetinfo);
5189 procmsg_msginfo_free(compose->replyinfo);
5190 procmsg_msginfo_free(compose->fwdinfo);
5192 g_free(compose->replyto);
5193 g_free(compose->cc);
5194 g_free(compose->bcc);
5195 g_free(compose->newsgroups);
5196 g_free(compose->followup_to);
5198 g_free(compose->ml_post);
5200 g_free(compose->inreplyto);
5201 g_free(compose->references);
5202 g_free(compose->msgid);
5203 g_free(compose->boundary);
5205 if (compose->redirect_filename)
5206 g_free(compose->redirect_filename);
5207 if (compose->undostruct)
5208 undo_destroy(compose->undostruct);
5210 g_free(compose->sig_str);
5212 g_free(compose->exteditor_file);
5214 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5216 compose_attach_info_free(ainfo);
5218 if (addressbook_get_target_compose() == compose)
5219 addressbook_set_target_compose(NULL);
5222 if (compose->gtkaspell) {
5223 gtkaspell_delete(compose->gtkaspell);
5227 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5228 prefs_common.compose_height = compose->window->allocation.height;
5230 gtk_widget_destroy(compose->paned);
5232 toolbar_destroy(compose->toolbar);
5233 g_free(compose->toolbar);
5236 compose_list = g_list_remove(compose_list, compose);
5239 static void compose_attach_info_free(AttachInfo *ainfo)
5241 g_free(ainfo->file);
5242 g_free(ainfo->content_type);
5243 g_free(ainfo->name);
5247 static void compose_attach_remove_selected(Compose *compose)
5249 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5253 while (clist->selection != NULL) {
5254 row = GPOINTER_TO_INT(clist->selection->data);
5255 ainfo = gtk_clist_get_row_data(clist, row);
5256 compose_attach_info_free(ainfo);
5257 gtk_clist_remove(clist, row);
5261 static struct _AttachProperty
5264 GtkWidget *mimetype_entry;
5265 GtkWidget *encoding_optmenu;
5266 GtkWidget *path_entry;
5267 GtkWidget *filename_entry;
5269 GtkWidget *cancel_btn;
5272 static void compose_attach_property(Compose *compose)
5274 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5277 GtkOptionMenu *optmenu;
5278 static gboolean cancelled;
5280 if (!clist->selection) return;
5281 row = GPOINTER_TO_INT(clist->selection->data);
5283 ainfo = gtk_clist_get_row_data(clist, row);
5286 if (!attach_prop.window)
5287 compose_attach_property_create(&cancelled);
5288 gtk_widget_grab_focus(attach_prop.ok_btn);
5289 gtk_widget_show(attach_prop.window);
5290 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5292 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5293 if (ainfo->encoding == ENC_UNKNOWN)
5294 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5295 GINT_TO_POINTER(ENC_BASE64));
5297 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5298 GINT_TO_POINTER(ainfo->encoding));
5300 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5301 ainfo->content_type ? ainfo->content_type : "");
5302 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5303 ainfo->file ? ainfo->file : "");
5304 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5305 ainfo->name ? ainfo->name : "");
5309 gchar *cnttype = NULL;
5313 GtkWidget *menuitem;
5318 if (cancelled == TRUE) {
5319 gtk_widget_hide(attach_prop.window);
5323 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5324 if (*text != '\0') {
5327 text = g_strstrip(g_strdup(text));
5328 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5329 cnttype = g_strdup(text);
5332 alertpanel_error(_("Invalid MIME type."));
5338 menu = gtk_option_menu_get_menu(optmenu);
5339 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5340 ainfo->encoding = GPOINTER_TO_INT
5341 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5343 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5344 if (*text != '\0') {
5345 if (is_file_exist(text) &&
5346 (size = get_file_size(text)) > 0)
5347 file = g_strdup(text);
5350 (_("File doesn't exist or is empty."));
5356 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5357 if (*text != '\0') {
5358 g_free(ainfo->name);
5359 ainfo->name = g_strdup(text);
5363 g_free(ainfo->content_type);
5364 ainfo->content_type = cnttype;
5367 g_free(ainfo->file);
5373 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5374 ainfo->content_type);
5375 gtk_clist_set_text(clist, row, COL_SIZE,
5376 to_human_readable(ainfo->size));
5377 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5379 gtk_widget_hide(attach_prop.window);
5384 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5386 label = gtk_label_new(str); \
5387 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5388 GTK_FILL, 0, 0, 0); \
5389 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5391 entry = gtk_entry_new(); \
5392 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5393 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5396 static void compose_attach_property_create(gboolean *cancelled)
5402 GtkWidget *mimetype_entry;
5405 GtkWidget *optmenu_menu;
5406 GtkWidget *menuitem;
5407 GtkWidget *path_entry;
5408 GtkWidget *filename_entry;
5411 GtkWidget *cancel_btn;
5412 GList *mime_type_list, *strlist;
5414 debug_print("Creating attach_property window...\n");
5416 window = gtk_window_new(GTK_WINDOW_DIALOG);
5417 gtk_widget_set_usize(window, 480, -1);
5418 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5419 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
5420 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5421 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5422 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5423 GTK_SIGNAL_FUNC(attach_property_delete_event),
5425 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5426 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5429 vbox = gtk_vbox_new(FALSE, 8);
5430 gtk_container_add(GTK_CONTAINER(window), vbox);
5432 table = gtk_table_new(4, 2, FALSE);
5433 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5434 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5435 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5437 label = gtk_label_new(_("MIME type"));
5438 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5440 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5441 mimetype_entry = gtk_combo_new();
5442 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5443 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5445 /* stuff with list */
5446 mime_type_list = procmime_get_mime_type_list();
5448 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5449 MimeType *type = (MimeType *) mime_type_list->data;
5450 strlist = g_list_append(strlist,
5451 g_strdup_printf("%s/%s",
5452 type->type, type->sub_type));
5455 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5457 for (mime_type_list = strlist; mime_type_list != NULL;
5458 mime_type_list = mime_type_list->next)
5459 g_free(mime_type_list->data);
5460 g_list_free(strlist);
5462 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5464 label = gtk_label_new(_("Encoding"));
5465 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5467 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5469 hbox = gtk_hbox_new(FALSE, 0);
5470 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5471 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5473 optmenu = gtk_option_menu_new();
5474 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5476 optmenu_menu = gtk_menu_new();
5477 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5478 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5480 gtk_widget_set_sensitive(menuitem, FALSE);
5482 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5483 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5485 gtk_widget_set_sensitive(menuitem, FALSE);
5487 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
5488 ENC_QUOTED_PRINTABLE);
5489 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5491 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5493 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5495 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5496 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5498 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5499 &cancel_btn, _("Cancel"), NULL, NULL);
5500 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5501 gtk_widget_grab_default(ok_btn);
5503 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5504 GTK_SIGNAL_FUNC(attach_property_ok),
5506 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5507 GTK_SIGNAL_FUNC(attach_property_cancel),
5510 gtk_widget_show_all(vbox);
5512 attach_prop.window = window;
5513 attach_prop.mimetype_entry = mimetype_entry;
5514 attach_prop.encoding_optmenu = optmenu;
5515 attach_prop.path_entry = path_entry;
5516 attach_prop.filename_entry = filename_entry;
5517 attach_prop.ok_btn = ok_btn;
5518 attach_prop.cancel_btn = cancel_btn;
5521 #undef SET_LABEL_AND_ENTRY
5523 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5529 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5535 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5536 gboolean *cancelled)
5544 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5545 gboolean *cancelled)
5547 if (event && event->keyval == GDK_Escape) {
5553 static void compose_exec_ext_editor(Compose *compose)
5559 tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
5560 G_DIR_SEPARATOR, compose);
5562 if (pipe(pipe_fds) < 0) {
5568 if ((pid = fork()) < 0) {
5575 /* close the write side of the pipe */
5578 compose->exteditor_file = g_strdup(tmp);
5579 compose->exteditor_pid = pid;
5580 compose->exteditor_readdes = pipe_fds[0];
5582 compose_set_ext_editor_sensitive(compose, FALSE);
5584 compose->exteditor_tag =
5585 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5586 compose_input_cb, compose);
5587 } else { /* process-monitoring process */
5593 /* close the read side of the pipe */
5596 if (compose_write_body_to_file(compose, tmp) < 0) {
5597 fd_write_all(pipe_fds[1], "2\n", 2);
5601 pid_ed = compose_exec_ext_editor_real(tmp);
5603 fd_write_all(pipe_fds[1], "1\n", 2);
5607 /* wait until editor is terminated */
5608 waitpid(pid_ed, NULL, 0);
5610 fd_write_all(pipe_fds[1], "0\n", 2);
5619 static gint compose_exec_ext_editor_real(const gchar *file)
5621 static gchar *def_cmd = "emacs %s";
5627 g_return_val_if_fail(file != NULL, -1);
5629 if ((pid = fork()) < 0) {
5634 if (pid != 0) return pid;
5636 /* grandchild process */
5638 if (setpgid(0, getppid()))
5641 if (prefs_common.ext_editor_cmd &&
5642 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5643 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5644 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5646 if (prefs_common.ext_editor_cmd)
5647 g_warning("External editor command line is invalid: `%s'\n",
5648 prefs_common.ext_editor_cmd);
5649 g_snprintf(buf, sizeof(buf), def_cmd, file);
5652 cmdline = strsplit_with_quote(buf, " ", 1024);
5653 execvp(cmdline[0], cmdline);
5656 g_strfreev(cmdline);
5661 static gboolean compose_ext_editor_kill(Compose *compose)
5663 pid_t pgid = compose->exteditor_pid * -1;
5666 ret = kill(pgid, 0);
5668 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5672 msg = g_strdup_printf
5673 (_("The external editor is still working.\n"
5674 "Force terminating the process?\n"
5675 "process group id: %d"), -pgid);
5676 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5679 if (val == G_ALERTDEFAULT) {
5680 gdk_input_remove(compose->exteditor_tag);
5681 close(compose->exteditor_readdes);
5683 if (kill(pgid, SIGTERM) < 0) perror("kill");
5684 waitpid(compose->exteditor_pid, NULL, 0);
5686 g_warning("Terminated process group id: %d", -pgid);
5687 g_warning("Temporary file: %s",
5688 compose->exteditor_file);
5690 compose_set_ext_editor_sensitive(compose, TRUE);
5692 g_free(compose->exteditor_file);
5693 compose->exteditor_file = NULL;
5694 compose->exteditor_pid = -1;
5695 compose->exteditor_readdes = -1;
5696 compose->exteditor_tag = -1;
5704 static void compose_input_cb(gpointer data, gint source,
5705 GdkInputCondition condition)
5708 Compose *compose = (Compose *)data;
5711 debug_print("Compose: input from monitoring process\n");
5713 gdk_input_remove(compose->exteditor_tag);
5716 if (read(source, &buf[i], 1) < 1) {
5720 if (buf[i] == '\n') {
5725 if (i == sizeof(buf) - 1)
5729 waitpid(compose->exteditor_pid, NULL, 0);
5731 if (buf[0] == '0') { /* success */
5732 GtkSText *text = GTK_STEXT(compose->text);
5734 gtk_stext_freeze(text);
5735 gtk_stext_set_point(text, 0);
5736 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5737 compose_insert_file(compose, compose->exteditor_file);
5738 compose_changed_cb(NULL, compose);
5739 gtk_stext_thaw(text);
5741 if (unlink(compose->exteditor_file) < 0)
5742 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5743 } else if (buf[0] == '1') { /* failed */
5744 g_warning("Couldn't exec external editor\n");
5745 if (unlink(compose->exteditor_file) < 0)
5746 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5747 } else if (buf[0] == '2') {
5748 g_warning("Couldn't write to file\n");
5749 } else if (buf[0] == '3') {
5750 g_warning("Pipe read failed\n");
5755 compose_set_ext_editor_sensitive(compose, TRUE);
5757 g_free(compose->exteditor_file);
5758 compose->exteditor_file = NULL;
5759 compose->exteditor_pid = -1;
5760 compose->exteditor_readdes = -1;
5761 compose->exteditor_tag = -1;
5764 static void compose_set_ext_editor_sensitive(Compose *compose,
5767 GtkItemFactory *ifactory;
5769 ifactory = gtk_item_factory_from_widget(compose->menubar);
5771 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5772 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5773 menu_set_sensitive(ifactory, "/Message/Insert file", sensitive);
5774 menu_set_sensitive(ifactory, "/Message/Insert signature", sensitive);
5775 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5776 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5777 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5780 gtk_widget_set_sensitive(compose->text, sensitive);
5781 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
5782 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
5783 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
5784 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
5785 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
5786 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
5787 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
5788 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
5792 * compose_undo_state_changed:
5794 * Change the sensivity of the menuentries undo and redo
5796 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5797 gint redo_state, gpointer data)
5799 GtkWidget *widget = GTK_WIDGET(data);
5800 GtkItemFactory *ifactory;
5802 g_return_if_fail(widget != NULL);
5804 ifactory = gtk_item_factory_from_widget(widget);
5806 switch (undo_state) {
5807 case UNDO_STATE_TRUE:
5808 if (!undostruct->undo_state) {
5809 undostruct->undo_state = TRUE;
5810 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5813 case UNDO_STATE_FALSE:
5814 if (undostruct->undo_state) {
5815 undostruct->undo_state = FALSE;
5816 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5819 case UNDO_STATE_UNCHANGED:
5821 case UNDO_STATE_REFRESH:
5822 menu_set_sensitive(ifactory, "/Edit/Undo",
5823 undostruct->undo_state);
5826 g_warning("Undo state not recognized");
5830 switch (redo_state) {
5831 case UNDO_STATE_TRUE:
5832 if (!undostruct->redo_state) {
5833 undostruct->redo_state = TRUE;
5834 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5837 case UNDO_STATE_FALSE:
5838 if (undostruct->redo_state) {
5839 undostruct->redo_state = FALSE;
5840 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5843 case UNDO_STATE_UNCHANGED:
5845 case UNDO_STATE_REFRESH:
5846 menu_set_sensitive(ifactory, "/Edit/Redo",
5847 undostruct->redo_state);
5850 g_warning("Redo state not recognized");
5855 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5859 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5860 cursor_pos = MAX(cursor_pos, 0);
5865 /* callback functions */
5867 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5868 * includes "non-client" (windows-izm) in calculation, so this calculation
5869 * may not be accurate.
5871 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5872 GtkAllocation *allocation,
5873 GtkSHRuler *shruler)
5875 if (prefs_common.show_ruler) {
5877 gint line_width_in_chars;
5879 char_width = gtkut_get_font_width
5880 (GTK_WIDGET(widget)->style->font);
5881 line_width_in_chars =
5882 (allocation->width - allocation->x) / char_width;
5884 /* got the maximum */
5885 gtk_ruler_set_range(GTK_RULER(shruler),
5886 0.0, line_width_in_chars,
5887 calc_cursor_xpos(GTK_STEXT(widget),
5890 /*line_width_in_chars*/ char_width);
5896 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5898 Compose *compose = (Compose *)data;
5901 gchar *folderidentifier;
5903 ac = account_find_from_id(
5904 GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menuitem))));
5905 g_return_if_fail(ac != NULL);
5907 if (ac != compose->account)
5908 compose_select_account(compose, ac, FALSE);
5910 /* Set message save folder */
5911 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5912 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
5914 gtk_signal_connect(GTK_OBJECT(compose->savemsg_checkbtn), "toggled",
5915 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
5917 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
5918 if (account_get_special_folder(compose->account, F_OUTBOX)) {
5919 folderidentifier = folder_item_get_identifier(account_get_special_folder
5920 (compose->account, F_OUTBOX));
5921 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
5922 g_free(folderidentifier);
5926 static void attach_selected(GtkCList *clist, gint row, gint column,
5927 GdkEvent *event, gpointer data)
5929 Compose *compose = (Compose *)data;
5931 if (event && event->type == GDK_2BUTTON_PRESS)
5932 compose_attach_property(compose);
5935 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5938 Compose *compose = (Compose *)data;
5939 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5944 if (event->button == 3) {
5945 if ((clist->selection && !clist->selection->next) ||
5946 !clist->selection) {
5947 gtk_clist_unselect_all(clist);
5948 if (gtk_clist_get_selection_info(clist,
5951 gtk_clist_select_row(clist, row, column);
5952 gtkut_clist_set_focus_row(clist, row);
5955 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5956 NULL, NULL, event->button, event->time);
5960 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5963 Compose *compose = (Compose *)data;
5967 switch (event->keyval) {
5969 compose_attach_remove_selected(compose);
5974 static void compose_allow_user_actions (Compose *compose, gboolean allow)
5976 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
5977 toolbar_comp_set_sensitive(compose, allow);
5978 menu_set_sensitive(ifactory, "/Message", allow);
5979 menu_set_sensitive(ifactory, "/Edit", allow);
5981 menu_set_sensitive(ifactory, "/Spelling", allow);
5983 menu_set_sensitive(ifactory, "/Options", allow);
5984 menu_set_sensitive(ifactory, "/Tools", allow);
5985 menu_set_sensitive(ifactory, "/Help", allow);
5988 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5990 Compose *compose = (Compose *)data;
5992 if (prefs_common.work_offline)
5993 if (alertpanel(_("Offline warning"),
5994 _("You're working offline. Override?"),
5995 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
5998 if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
5999 gtk_timeout_remove(compose->draft_timeout_tag);
6000 compose->draft_timeout_tag = -1;
6003 compose_send(compose);
6006 static void compose_send_later_cb(gpointer data, guint action,
6009 Compose *compose = (Compose *)data;
6012 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6013 if (!val) gtk_widget_destroy(compose->window);
6016 void compose_draft (gpointer data)
6018 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6021 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6023 Compose *compose = (Compose *)data;
6027 MsgFlags flag = {0, 0};
6028 static gboolean lock = FALSE;
6029 MsgInfo *newmsginfo;
6034 draft = account_get_special_folder(compose->account, F_DRAFT);
6035 g_return_if_fail(draft != NULL);
6039 tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
6040 G_DIR_SEPARATOR, compose);
6041 if ((fp = fopen(tmp, "wb")) == NULL) {
6042 FILE_OP_ERROR(tmp, "fopen");
6046 /* chmod for security */
6047 if (change_file_mode_rw(fp, tmp) < 0) {
6048 FILE_OP_ERROR(tmp, "chmod");
6049 g_warning("can't change file mode\n");
6052 /* Save draft infos */
6053 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
6054 fprintf(fp, "S:%s\n", compose->account->address);
6055 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
6056 gchar *savefolderid;
6058 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
6059 fprintf(fp, "SCF:%s\n", savefolderid);
6060 g_free(savefolderid);
6062 fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
6063 fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
6064 fprintf(fp, "X-Sylpheed-Gnupg-Mode:%s\n", compose->privacy_system);
6067 if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
6076 folder_item_scan(draft);
6077 if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
6084 draft->mtime = 0; /* force updating */
6086 if (compose->mode == COMPOSE_REEDIT) {
6087 compose_remove_reedit_target(compose);
6090 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6092 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6093 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
6094 if (compose_use_attach(compose))
6095 procmsg_msginfo_set_flags(newmsginfo, 0,
6096 MSG_HAS_ATTACHMENT);
6098 procmsg_msginfo_free(newmsginfo);
6101 folder_item_scan(draft);
6105 if (action == COMPOSE_QUIT_EDITING)
6106 gtk_widget_destroy(compose->window);
6111 path = folder_item_fetch_msg(draft, msgnum);
6112 g_return_if_fail(path != NULL);
6113 if (stat(path, &s) < 0) {
6114 FILE_OP_ERROR(path, "stat");
6121 procmsg_msginfo_free(compose->targetinfo);
6122 compose->targetinfo = procmsg_msginfo_new();
6123 compose->targetinfo->msgnum = msgnum;
6124 compose->targetinfo->size = s.st_size;
6125 compose->targetinfo->mtime = s.st_mtime;
6126 compose->targetinfo->folder = draft;
6127 compose->mode = COMPOSE_REEDIT;
6129 if (action == COMPOSE_AUTO_SAVE) {
6130 compose->autosaved_draft = compose->targetinfo;
6135 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6137 Compose *compose = (Compose *)data;
6140 if (compose->redirect_filename != NULL)
6143 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6148 for ( tmp = file_list; tmp; tmp = tmp->next) {
6149 gchar *file = (gchar *) tmp->data;
6150 compose_attach_append(compose, file, file, NULL);
6151 compose_changed_cb(NULL, compose);
6154 g_list_free(file_list);
6158 static void compose_insert_file_cb(gpointer data, guint action,
6161 Compose *compose = (Compose *)data;
6164 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6169 for ( tmp = file_list; tmp; tmp = tmp->next) {
6170 gchar *file = (gchar *) tmp->data;
6171 gchar *filedup = g_strdup(file);
6173 ComposeInsertResult res;
6175 res = compose_insert_file(compose, file);
6176 shortfile = g_basename(filedup);
6177 if (res == COMPOSE_INSERT_READ_ERROR) {
6178 alertpanel_error(_("File '%s' could not be read."), shortfile);
6179 } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
6180 alertpanel_error(_("File '%s' contained invalid characters\n"
6181 "for the current encoding, insertion may be incorrect."), shortfile);
6186 g_list_free(file_list);
6190 static void compose_insert_sig_cb(gpointer data, guint action,
6193 Compose *compose = (Compose *)data;
6195 compose_insert_sig(compose, FALSE);
6198 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6202 Compose *compose = (Compose *)data;
6204 gtkut_widget_get_uposition(widget, &x, &y);
6205 prefs_common.compose_x = x;
6206 prefs_common.compose_y = y;
6208 if (compose->sending)
6210 compose_close_cb(compose, 0, NULL);
6214 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6216 Compose *compose = (Compose *)data;
6219 if (compose->exteditor_tag != -1) {
6220 if (!compose_ext_editor_kill(compose))
6224 if (compose->modified) {
6225 val = alertpanel(_("Discard message"),
6226 _("This message has been modified. discard it?"),
6227 _("Discard"), _("to Draft"), _("Cancel"));
6230 case G_ALERTDEFAULT:
6231 if (prefs_common.autosave)
6232 compose_remove_draft(compose);
6234 case G_ALERTALTERNATE:
6235 compose_draft_cb(data, COMPOSE_QUIT_EDITING, NULL);
6242 gtk_widget_destroy(compose->window);
6245 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6247 Compose *compose = (Compose *)data;
6249 addressbook_open(compose);
6252 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6254 Compose *compose = (Compose *)data;
6259 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6260 g_return_if_fail(tmpl != NULL);
6262 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6264 val = alertpanel(_("Apply template"), msg,
6265 _("Replace"), _("Insert"), _("Cancel"));
6268 if (val == G_ALERTDEFAULT)
6269 compose_template_apply(compose, tmpl, TRUE);
6270 else if (val == G_ALERTALTERNATE)
6271 compose_template_apply(compose, tmpl, FALSE);
6274 static void compose_ext_editor_cb(gpointer data, guint action,
6277 Compose *compose = (Compose *)data;
6279 compose_exec_ext_editor(compose);
6282 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6284 if (compose->sending)
6286 compose_destroy(compose);
6289 static void compose_undo_cb(Compose *compose)
6291 undo_undo(compose->undostruct);
6294 static void compose_redo_cb(Compose *compose)
6296 undo_redo(compose->undostruct);
6299 static void compose_cut_cb(Compose *compose)
6301 if (compose->focused_editable &&
6302 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6303 gtk_editable_cut_clipboard
6304 (GTK_EDITABLE(compose->focused_editable));
6307 static void compose_copy_cb(Compose *compose)
6309 if (compose->focused_editable &&
6310 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6311 gtk_editable_copy_clipboard
6312 (GTK_EDITABLE(compose->focused_editable));
6315 static void compose_paste_cb(Compose *compose)
6317 if (compose->focused_editable &&
6318 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6319 gtk_editable_paste_clipboard
6320 (GTK_EDITABLE(compose->focused_editable));
6323 static void compose_paste_as_quote_cb(Compose *compose)
6325 if (compose->focused_editable &&
6326 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6327 /* let text_insert() (called directly or at a later time
6328 * after the gtk_editable_paste_clipboard) know that
6329 * text is to be inserted as a quotation. implemented
6330 * by using a simple refcount... */
6331 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data(
6332 GTK_OBJECT(compose->focused_editable),
6333 "paste_as_quotation"));
6334 gtk_object_set_data(GTK_OBJECT(compose->focused_editable),
6335 "paste_as_quotation",
6336 GINT_TO_POINTER(paste_as_quotation + 1));
6337 gtk_editable_paste_clipboard
6338 (GTK_EDITABLE(compose->focused_editable));
6342 static void compose_allsel_cb(Compose *compose)
6344 if (compose->focused_editable &&
6345 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6346 gtk_editable_select_region
6347 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6350 static void compose_gtk_stext_action_cb(Compose *compose,
6351 ComposeCallGtkSTextAction action)
6353 GtkSText *text = GTK_STEXT(compose->text);
6355 void (*do_action) (GtkSText *text);
6356 } action_table[] = {
6357 {gtk_stext_move_beginning_of_line},
6358 {gtk_stext_move_forward_character},
6359 {gtk_stext_move_backward_character},
6360 {gtk_stext_move_forward_word},
6361 {gtk_stext_move_backward_word},
6362 {gtk_stext_move_end_of_line},
6363 {gtk_stext_move_next_line},
6364 {gtk_stext_move_previous_line},
6365 {gtk_stext_delete_forward_character},
6366 {gtk_stext_delete_backward_character},
6367 {gtk_stext_delete_forward_word},
6368 {gtk_stext_delete_backward_word},
6369 {gtk_stext_delete_line},
6370 {gtk_stext_delete_line}, /* gtk_stext_delete_line_n */
6371 {gtk_stext_delete_to_line_end}
6374 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
6376 if (action >= COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE &&
6377 action <= COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END)
6378 action_table[action].do_action(text);
6381 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6383 if (GTK_IS_EDITABLE(widget))
6384 compose->focused_editable = widget;
6387 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6389 if (compose->modified == FALSE) {
6390 compose->modified = TRUE;
6391 compose_set_title(compose);
6395 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6398 gtk_stext_set_point(GTK_STEXT(widget),
6399 gtk_editable_get_position(GTK_EDITABLE(widget)));
6403 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6406 gtk_stext_set_point(GTK_STEXT(widget),
6407 gtk_editable_get_position(GTK_EDITABLE(widget)));
6411 static void compose_toggle_autowrap_cb(gpointer data, guint action,
6414 Compose *compose = (Compose *)data;
6416 compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
6417 if (compose->autowrap)
6418 compose_wrap_line_all_full(compose, TRUE);
6421 static void compose_toggle_sign_cb(gpointer data, guint action,
6424 Compose *compose = (Compose *)data;
6426 if (GTK_CHECK_MENU_ITEM(widget)->active)
6427 compose->use_signing = TRUE;
6429 compose->use_signing = FALSE;
6432 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6435 Compose *compose = (Compose *)data;
6437 if (GTK_CHECK_MENU_ITEM(widget)->active)
6438 compose->use_encryption = TRUE;
6440 compose->use_encryption = FALSE;
6443 static void activate_privacy_system(Compose *compose, PrefsAccount *account)
6446 if (account->default_gnupg_mode)
6447 compose->gnupg_mode = GNUPG_MODE_INLINE;
6449 compose->gnupg_mode = GNUPG_MODE_DETACH;
6451 compose_update_privacy_system_menu_item(compose);
6454 static void compose_toggle_ruler_cb(gpointer data, guint action,
6457 Compose *compose = (Compose *)data;
6459 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6460 gtk_widget_show(compose->ruler_hbox);
6461 prefs_common.show_ruler = TRUE;
6463 gtk_widget_hide(compose->ruler_hbox);
6464 gtk_widget_queue_resize(compose->edit_vbox);
6465 prefs_common.show_ruler = FALSE;
6469 static void compose_attach_drag_received_cb (GtkWidget *widget,
6470 GdkDragContext *drag_context,
6473 GtkSelectionData *data,
6478 Compose *compose = (Compose *)user_data;
6481 list = uri_list_extract_filenames((const gchar *)data->data);
6482 for (tmp = list; tmp != NULL; tmp = tmp->next)
6483 compose_attach_append
6484 (compose, (const gchar *)tmp->data,
6485 (const gchar *)tmp->data, NULL);
6486 if (list) compose_changed_cb(NULL, compose);
6487 list_free_strings(list);
6491 static void compose_insert_drag_received_cb (GtkWidget *widget,
6492 GdkDragContext *drag_context,
6495 GtkSelectionData *data,
6500 Compose *compose = (Compose *)user_data;
6503 list = uri_list_extract_filenames((const gchar *)data->data);
6504 for (tmp = list; tmp != NULL; tmp = tmp->next)
6505 compose_insert_file(compose, (const gchar *)tmp->data);
6506 list_free_strings(list);
6510 #if 0 /* NEW COMPOSE GUI */
6511 static void to_activated(GtkWidget *widget, Compose *compose)
6513 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6514 gtk_widget_grab_focus(compose->newsgroups_entry);
6516 gtk_widget_grab_focus(compose->subject_entry);
6519 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6521 gtk_widget_grab_focus(compose->subject_entry);
6524 static void subject_activated(GtkWidget *widget, Compose *compose)
6526 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6527 gtk_widget_grab_focus(compose->cc_entry);
6528 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6529 gtk_widget_grab_focus(compose->bcc_entry);
6530 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6531 gtk_widget_grab_focus(compose->reply_entry);
6532 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6533 gtk_widget_grab_focus(compose->followup_entry);
6535 gtk_widget_grab_focus(compose->text);
6538 static void cc_activated(GtkWidget *widget, Compose *compose)
6540 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6541 gtk_widget_grab_focus(compose->bcc_entry);
6542 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6543 gtk_widget_grab_focus(compose->reply_entry);
6544 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6545 gtk_widget_grab_focus(compose->followup_entry);
6547 gtk_widget_grab_focus(compose->text);
6550 static void bcc_activated(GtkWidget *widget, Compose *compose)
6552 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6553 gtk_widget_grab_focus(compose->reply_entry);
6554 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6555 gtk_widget_grab_focus(compose->followup_entry);
6557 gtk_widget_grab_focus(compose->text);
6560 static void replyto_activated(GtkWidget *widget, Compose *compose)
6562 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6563 gtk_widget_grab_focus(compose->followup_entry);
6565 gtk_widget_grab_focus(compose->text);
6568 static void followupto_activated(GtkWidget *widget, Compose *compose)
6570 gtk_widget_grab_focus(compose->text);
6574 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6577 Compose *compose = (Compose *)data;
6579 if (GTK_CHECK_MENU_ITEM(widget)->active)
6580 compose->return_receipt = TRUE;
6582 compose->return_receipt = FALSE;
6585 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
6588 Compose *compose = (Compose *)data;
6590 if (GTK_CHECK_MENU_ITEM(widget)->active)
6591 compose->remove_references = TRUE;
6593 compose->remove_references = FALSE;
6596 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6598 ComposeHeaderEntry *headerentry)
6600 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6601 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6602 !(event->state & GDK_MODIFIER_MASK) &&
6603 (event->keyval == GDK_BackSpace) &&
6604 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6605 gtk_container_remove
6606 (GTK_CONTAINER(headerentry->compose->header_table),
6607 headerentry->combo);
6608 gtk_container_remove
6609 (GTK_CONTAINER(headerentry->compose->header_table),
6610 headerentry->entry);
6611 headerentry->compose->header_list =
6612 g_slist_remove(headerentry->compose->header_list,
6614 g_free(headerentry);
6615 } else if (event->keyval == GDK_Tab) {
6616 if (headerentry->compose->header_last == headerentry) {
6617 /* Override default next focus, and give it to subject_entry
6618 * instead of notebook tabs
6620 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6621 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6627 void compose_headerentry_changed_cb(GtkWidget *entry,
6628 ComposeHeaderEntry *headerentry)
6630 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6631 headerentry->compose->header_list =
6632 g_slist_append(headerentry->compose->header_list,
6634 compose_create_header_entry(headerentry->compose);
6635 gtk_signal_disconnect_by_func
6637 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6639 /* Automatically scroll down */
6640 compose_show_first_last_header(headerentry->compose, FALSE);
6645 static gboolean compose_headerentry_button_pressed
6646 (GtkWidget *entry, GdkEventButton *event, gpointer data)
6648 /* if this is a lclick, grab the focus */
6649 if (event->button == 1)
6650 gtk_widget_grab_focus(entry);
6654 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6656 GtkAdjustment *vadj;
6658 g_return_if_fail(compose);
6659 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6660 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6662 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6663 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6666 static void text_activated(GtkWidget *widget, Compose *compose)
6668 compose_send_control_enter(compose);
6671 static void text_inserted(GtkWidget *widget, const gchar *text,
6672 gint length, gint *position, Compose *compose)
6674 GtkEditable *editable = GTK_EDITABLE(widget);
6675 gint paste_as_quotation = GPOINTER_TO_INT(gtk_object_get_data
6676 (GTK_OBJECT(widget), "paste_as_quotation"));
6678 gtk_signal_handler_block_by_func(GTK_OBJECT(widget),
6679 GTK_SIGNAL_FUNC(text_inserted),
6681 if (paste_as_quotation) {
6686 new_text = g_strndup(text, length);
6687 if (prefs_common.quotemark && *prefs_common.quotemark)
6688 qmark = prefs_common.quotemark;
6691 gtk_stext_set_point(GTK_STEXT(widget), *position);
6692 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
6693 pos = gtk_stext_get_point(GTK_STEXT(widget));
6694 gtk_editable_set_position(editable, pos);
6697 gtk_object_set_data(GTK_OBJECT(widget), "paste_as_quotation",
6698 GINT_TO_POINTER(paste_as_quotation - 1));
6700 gtk_editable_insert_text(editable, text, length, position);
6702 if (compose->autowrap)
6703 compose_wrap_line_all_full(compose, TRUE);
6705 gtk_signal_handler_unblock_by_func(GTK_OBJECT(widget),
6706 GTK_SIGNAL_FUNC(text_inserted),
6708 gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
6710 if (prefs_common.autosave &&
6711 gtk_stext_get_length(GTK_STEXT(widget)) % prefs_common.autosave_length == 0)
6712 compose->draft_timeout_tag = gtk_timeout_add
6713 (500, (GtkFunction) compose_defer_auto_save_draft, compose);
6716 static gint compose_defer_auto_save_draft(Compose *compose)
6718 compose->draft_timeout_tag = -1;
6719 compose_draft_cb((gpointer)compose, COMPOSE_AUTO_SAVE, NULL);
6723 static gboolean compose_send_control_enter(Compose *compose)
6727 GtkItemFactory *ifactory;
6728 GtkAccelEntry *accel;
6729 GtkWidget *send_menu;
6731 GdkModifierType ignored_mods =
6732 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
6733 GDK_MOD4_MASK | GDK_MOD5_MASK);
6735 ev = gtk_get_current_event();
6736 if (ev->type != GDK_KEY_PRESS) return FALSE;
6738 kev = (GdkEventKey *)ev;
6739 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6742 if (compose->exteditor_tag != -1)
6745 ifactory = gtk_item_factory_from_widget(compose->menubar);
6746 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6747 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6751 accel = (GtkAccelEntry *)list->data;
6752 if (accel && accel->accelerator_key == kev->keyval &&
6753 (accel->accelerator_mods & ~ignored_mods) ==
6754 (kev->state & ~ignored_mods)) {
6755 compose_send_cb(compose, 0, NULL);
6763 static void compose_check_all(Compose *compose)
6765 if (compose->gtkaspell)
6766 gtkaspell_check_all(compose->gtkaspell);
6769 static void compose_highlight_all(Compose *compose)
6771 if (compose->gtkaspell)
6772 gtkaspell_highlight_all(compose->gtkaspell);
6775 static void compose_check_backwards(Compose *compose)
6777 if (compose->gtkaspell)
6778 gtkaspell_check_backwards(compose->gtkaspell);
6780 GtkItemFactory *ifactory;
6781 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6782 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6783 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6787 static void compose_check_forwards_go(Compose *compose)
6789 if (compose->gtkaspell)
6790 gtkaspell_check_forwards_go(compose->gtkaspell);
6792 GtkItemFactory *ifactory;
6793 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6794 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6795 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6801 *\brief Guess originating forward account from MsgInfo and several
6802 * "common preference" settings. Return NULL if no guess.
6804 static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo)
6806 PrefsAccount *account = NULL;
6808 g_return_val_if_fail(msginfo, NULL);
6809 g_return_val_if_fail(msginfo->folder, NULL);
6810 g_return_val_if_fail(msginfo->folder->prefs, NULL);
6812 if (msginfo->folder->prefs->enable_default_account)
6813 account = account_find_from_id(msginfo->folder->prefs->default_account);
6816 account = msginfo->folder->folder->account;
6818 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
6820 Xstrdup_a(to, msginfo->to, return NULL);
6821 extract_address(to);
6822 account = account_find_from_address(to);
6825 if (!account && prefs_common.forward_account_autosel) {
6827 if (!procheader_get_header_from_msginfo
6828 (msginfo, cc,sizeof cc , "CC:")) { /* Found a CC header */
6829 extract_address(cc);
6830 account = account_find_from_address(cc);
6838 * Add entry field for each address in list.
6839 * \param compose E-Mail composition object.
6840 * \param listAddress List of (formatted) E-Mail addresses.
6842 static void compose_add_field_list( Compose *compose, GList *listAddress ) {
6847 addr = ( gchar * ) node->data;
6848 compose_entry_append( compose, addr, COMPOSE_TO );
6849 node = g_list_next( node );