2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2003 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
31 #include <gtk/gtkitemfactory.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkclist.h>
36 #include <gtk/gtkctree.h>
37 #include <gtk/gtkvpaned.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkeditable.h>
40 #include <gtk/gtkwindow.h>
41 #include <gtk/gtksignal.h>
42 #include <gtk/gtkvbox.h>
43 #include <gtk/gtkcontainer.h>
44 #include <gtk/gtkhandlebox.h>
45 #include <gtk/gtktoolbar.h>
46 #include <gtk/gtktable.h>
47 #include <gtk/gtkhbox.h>
48 #include <gtk/gtklabel.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtkthemes.h>
51 #include <gtk/gtkdnd.h>
56 #include <sys/types.h>
60 /* #include <sys/utsname.h> */
66 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
73 #include "mainwindow.h"
76 #include "addressbook.h"
77 #include "folderview.h"
80 #include "stock_pixmap.h"
84 #include "customheader.h"
85 #include "prefs_common.h"
86 #include "prefs_account.h"
87 #include "prefs_actions.h"
90 #include "procheader.h"
92 #include "statusbar.h"
95 #include "quoted-printable.h"
100 #include "alertpanel.h"
101 #include "manage_window.h"
102 #include "gtkshruler.h"
104 #include "addr_compl.h"
105 #include "quote_fmt.h"
106 #include "template.h"
108 #include "foldersel.h"
112 # include "rfc2015.h"
122 #define N_ATTACH_COLS 3
126 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
127 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
128 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
129 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
130 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
131 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
132 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
133 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
134 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
135 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
136 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
137 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
138 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
139 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
140 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
141 } ComposeCallGtkSTextAction;
145 PRIORITY_HIGHEST = 1,
152 #define B64_LINE_SIZE 57
153 #define B64_BUFFSIZE 77
155 #define MAX_REFERENCES_LEN 999
157 static GdkColor quote_color = {0, 0, 0, 0xbfff};
159 static GList *compose_list = NULL;
161 Compose *compose_generic_new (PrefsAccount *account,
164 GPtrArray *attach_files);
166 static Compose *compose_create (PrefsAccount *account,
169 static GtkWidget *compose_account_option_menu_create
171 static void compose_set_template_menu (Compose *compose);
172 static void compose_template_apply (Compose *compose,
175 static void compose_destroy (Compose *compose);
177 static void compose_entries_set (Compose *compose,
178 const gchar *mailto);
179 static gint compose_parse_header (Compose *compose,
181 static gchar *compose_parse_references (const gchar *ref,
184 static gchar *compose_quote_fmt (Compose *compose,
190 static void compose_reply_set_entry (Compose *compose,
196 followup_and_reply_to);
197 static void compose_reedit_set_entry (Compose *compose,
199 static void compose_insert_sig (Compose *compose);
200 static void compose_insert_file (Compose *compose,
202 static void compose_attach_append (Compose *compose,
205 const gchar *content_type);
206 static void compose_attach_parts (Compose *compose,
208 static void compose_wrap_line (Compose *compose);
209 static void compose_wrap_line_all (Compose *compose);
210 static void compose_wrap_line_all_full (Compose *compose,
212 static void compose_set_title (Compose *compose);
213 static void compose_select_account (Compose *compose,
214 PrefsAccount *account);
216 static PrefsAccount *compose_current_mail_account(void);
217 /* static gint compose_send (Compose *compose); */
218 static gboolean compose_check_for_valid_recipient
220 static gboolean compose_check_entries (Compose *compose,
221 gboolean check_subject);
222 static gint compose_write_to_file (Compose *compose,
225 static gint compose_write_body_to_file (Compose *compose,
227 static gint compose_remove_reedit_target (Compose *compose);
228 void compose_remove_draft (Compose *compose);
229 static gint compose_queue (Compose *compose,
232 static gint compose_queue_sub (Compose *compose,
235 gboolean check_subject);
236 static void compose_write_attach (Compose *compose,
238 static gint compose_write_headers (Compose *compose,
240 const gchar *charset,
241 EncodingType encoding,
244 static void compose_convert_header (gchar *dest,
248 static void compose_generate_msgid (Compose *compose,
252 static void compose_attach_info_free (AttachInfo *ainfo);
253 static void compose_attach_remove_selected (Compose *compose);
255 static void compose_attach_property (Compose *compose);
256 static void compose_attach_property_create (gboolean *cancelled);
257 static void attach_property_ok (GtkWidget *widget,
258 gboolean *cancelled);
259 static void attach_property_cancel (GtkWidget *widget,
260 gboolean *cancelled);
261 static gint attach_property_delete_event (GtkWidget *widget,
263 gboolean *cancelled);
264 static void attach_property_key_pressed (GtkWidget *widget,
266 gboolean *cancelled);
268 static void compose_exec_ext_editor (Compose *compose);
269 static gint compose_exec_ext_editor_real (const gchar *file);
270 static gboolean compose_ext_editor_kill (Compose *compose);
271 static void compose_input_cb (gpointer data,
273 GdkInputCondition condition);
274 static void compose_set_ext_editor_sensitive (Compose *compose,
277 static void compose_undo_state_changed (UndoMain *undostruct,
282 static gint calc_cursor_xpos (GtkSText *text,
286 static void compose_create_header_entry (Compose *compose);
287 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
288 static void compose_update_priority_menu_item(Compose * compose);
290 /* callback functions */
292 static gboolean compose_edit_size_alloc (GtkEditable *widget,
293 GtkAllocation *allocation,
294 GtkSHRuler *shruler);
295 static void account_activated (GtkMenuItem *menuitem,
297 static void attach_selected (GtkCList *clist,
302 static void attach_button_pressed (GtkWidget *widget,
303 GdkEventButton *event,
305 static void attach_key_pressed (GtkWidget *widget,
309 static void compose_send_cb (gpointer data,
312 static void compose_send_later_cb (gpointer data,
316 static void compose_draft_cb (gpointer data,
320 static void compose_attach_cb (gpointer data,
323 static void compose_insert_file_cb (gpointer data,
327 static void compose_close_cb (gpointer data,
331 static void compose_address_cb (gpointer data,
334 static void compose_template_activate_cb(GtkWidget *widget,
337 static void compose_ext_editor_cb (gpointer data,
341 static gint compose_delete_cb (GtkWidget *widget,
344 static void compose_destroy_cb (GtkWidget *widget,
347 static void compose_undo_cb (Compose *compose);
348 static void compose_redo_cb (Compose *compose);
349 static void compose_cut_cb (Compose *compose);
350 static void compose_copy_cb (Compose *compose);
351 static void compose_paste_cb (Compose *compose);
352 static void compose_paste_as_quote_cb (Compose *compose);
353 static void compose_allsel_cb (Compose *compose);
355 static void compose_gtk_stext_action_cb (Compose *compose,
356 ComposeCallGtkSTextAction action);
358 static void compose_grab_focus_cb (GtkWidget *widget,
361 static void compose_changed_cb (GtkEditable *editable,
363 static void compose_button_press_cb (GtkWidget *widget,
364 GdkEventButton *event,
367 static void compose_key_press_cb (GtkWidget *widget,
373 static void compose_toggle_to_cb (gpointer data,
376 static void compose_toggle_cc_cb (gpointer data,
379 static void compose_toggle_bcc_cb (gpointer data,
382 static void compose_toggle_replyto_cb (gpointer data,
385 static void compose_toggle_followupto_cb(gpointer data,
388 static void compose_toggle_attach_cb (gpointer data,
392 static void compose_toggle_ruler_cb (gpointer data,
396 static void compose_toggle_sign_cb (gpointer data,
399 static void compose_toggle_encrypt_cb (gpointer data,
402 static void compose_set_gnupg_mode_cb (gpointer data,
405 static void compose_update_gnupg_mode_menu_item(Compose * compose);
406 static void activate_gnupg_mode (Compose *compose,
407 PrefsAccount *account);
409 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
411 static void compose_set_priority_cb (gpointer data,
415 static void compose_attach_drag_received_cb (GtkWidget *widget,
416 GdkDragContext *drag_context,
419 GtkSelectionData *data,
423 static void compose_insert_drag_received_cb (GtkWidget *widget,
424 GdkDragContext *drag_context,
427 GtkSelectionData *data,
433 static void to_activated (GtkWidget *widget,
435 static void newsgroups_activated (GtkWidget *widget,
437 static void cc_activated (GtkWidget *widget,
439 static void bcc_activated (GtkWidget *widget,
441 static void replyto_activated (GtkWidget *widget,
443 static void followupto_activated (GtkWidget *widget,
445 static void subject_activated (GtkWidget *widget,
449 static void text_activated (GtkWidget *widget,
451 static void text_inserted (GtkWidget *widget,
456 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
457 gboolean to_all, gboolean to_ml,
458 gboolean ignore_replyto,
459 gboolean followup_and_reply_to,
462 void compose_headerentry_changed_cb (GtkWidget *entry,
463 ComposeHeaderEntry *headerentry);
464 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
466 ComposeHeaderEntry *headerentry);
468 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
471 static void compose_check_all (Compose *compose);
472 static void compose_highlight_all (Compose *compose);
473 static void compose_check_backwards (Compose *compose);
474 static void compose_check_forwards_go (Compose *compose);
477 static gboolean compose_send_control_enter (Compose *compose);
479 static GtkItemFactoryEntry compose_popup_entries[] =
481 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
482 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
483 {N_("/---"), NULL, NULL, 0, "<Separator>"},
484 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
487 static GtkItemFactoryEntry compose_entries[] =
489 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
490 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
491 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
492 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
493 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
494 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
496 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
497 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
498 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
499 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
500 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
501 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
502 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
503 {N_("/_Edit/Paste as _quotation"),
504 NULL, compose_paste_as_quote_cb, 0, NULL},
505 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
506 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
507 {N_("/_Edit/A_dvanced/Move a character backward"),
509 compose_gtk_stext_action_cb,
510 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
512 {N_("/_Edit/A_dvanced/Move a character forward"),
514 compose_gtk_stext_action_cb,
515 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
517 {N_("/_Edit/A_dvanced/Move a word backward"),
519 compose_gtk_stext_action_cb,
520 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
522 {N_("/_Edit/A_dvanced/Move a word forward"),
524 compose_gtk_stext_action_cb,
525 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
527 {N_("/_Edit/A_dvanced/Move to beginning of line"),
528 NULL, /* "<control>A" */
529 compose_gtk_stext_action_cb,
530 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
532 {N_("/_Edit/A_dvanced/Move to end of line"),
534 compose_gtk_stext_action_cb,
535 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
537 {N_("/_Edit/A_dvanced/Move to previous line"),
539 compose_gtk_stext_action_cb,
540 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
542 {N_("/_Edit/A_dvanced/Move to next line"),
544 compose_gtk_stext_action_cb,
545 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
547 {N_("/_Edit/A_dvanced/Delete a character backward"),
549 compose_gtk_stext_action_cb,
550 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
552 {N_("/_Edit/A_dvanced/Delete a character forward"),
554 compose_gtk_stext_action_cb,
555 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
557 {N_("/_Edit/A_dvanced/Delete a word backward"),
558 NULL, /* "<control>W" */
559 compose_gtk_stext_action_cb,
560 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
562 {N_("/_Edit/A_dvanced/Delete a word forward"),
563 NULL, /* "<alt>D", */
564 compose_gtk_stext_action_cb,
565 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
567 {N_("/_Edit/A_dvanced/Delete line"),
569 compose_gtk_stext_action_cb,
570 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
572 {N_("/_Edit/A_dvanced/Delete entire line"),
574 compose_gtk_stext_action_cb,
575 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
577 {N_("/_Edit/A_dvanced/Delete to end of line"),
579 compose_gtk_stext_action_cb,
580 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
582 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
583 {N_("/_Edit/_Wrap current paragraph"),
584 "<control>L", compose_wrap_line, 0, NULL},
585 {N_("/_Edit/Wrap all long _lines"),
586 "<control><alt>L", compose_wrap_line_all, 0, NULL},
587 {N_("/_Edit/Edit with e_xternal editor"),
588 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
590 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
591 {N_("/_Spelling/_Check all or check selection"),
592 NULL, compose_check_all, 0, NULL},
593 {N_("/_Spelling/_Highlight all misspelled words"),
594 NULL, compose_highlight_all, 0, NULL},
595 {N_("/_Spelling/Check _backwards misspelled word"),
596 NULL, compose_check_backwards , 0, NULL},
597 {N_("/_Spelling/_Forward to next misspelled word"),
598 NULL, compose_check_forwards_go, 0, NULL},
599 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
600 {N_("/_Spelling/_Spelling Configuration"),
601 NULL, NULL, 0, "<Branch>"},
603 #if 0 /* NEW COMPOSE GUI */
604 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
605 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
606 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
607 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
608 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
609 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
610 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
611 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
612 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
613 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
614 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
616 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
617 {N_("/_Message/_Send"), "<control>Return",
618 compose_send_cb, 0, NULL},
619 {N_("/_Message/Send _later"), "<shift><control>S",
620 compose_send_later_cb, 0, NULL},
621 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
622 {N_("/_Message/Save to _draft folder"),
623 "<shift><control>D", compose_draft_cb, 0, NULL},
624 {N_("/_Message/Save and _keep editing"),
625 "<control>S", compose_draft_cb, 1, NULL},
626 #if 0 /* NEW COMPOSE GUI */
627 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
628 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
629 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
630 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
631 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
632 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
633 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
634 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
635 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
638 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
639 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
640 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
641 {N_("/_Message/Mode/MIME"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_DETACH, "<RadioItem>"},
642 {N_("/_Message/Mode/Inline"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_INLINE, "/Message/Mode/MIME"},
643 #endif /* USE_GPGME */
644 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
645 {N_("/_Message/_Priority"), NULL, NULL, 0, "<Branch>"},
646 {N_("/_Message/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
647 {N_("/_Message/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
648 {N_("/_Message/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
649 {N_("/_Message/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
650 {N_("/_Message/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
651 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
652 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
653 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
654 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
655 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
656 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
657 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
658 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
659 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
662 static GtkTargetEntry compose_mime_types[] =
664 {"text/uri-list", 0, 0}
667 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
668 GPtrArray *attach_files)
670 return compose_generic_new(account, mailto, NULL, attach_files);
673 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
675 return compose_generic_new(account, NULL, item, NULL);
678 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
679 GPtrArray *attach_files)
683 GtkItemFactory *ifactory;
684 gboolean grab_focus_on_last = TRUE;
686 if (item && item->prefs && item->prefs->enable_default_account)
687 account = account_find_from_id(item->prefs->default_account);
689 if (!account) account = cur_account;
690 g_return_val_if_fail(account != NULL, NULL);
692 compose = compose_create(account, COMPOSE_NEW);
693 ifactory = gtk_item_factory_from_widget(compose->menubar);
695 compose->replyinfo = NULL;
696 compose->fwdinfo = NULL;
698 text = GTK_STEXT(compose->text);
699 gtk_stext_freeze(text);
701 if (prefs_common.auto_sig)
702 compose_insert_sig(compose);
703 gtk_editable_set_position(GTK_EDITABLE(text), 0);
704 gtk_stext_set_point(text, 0);
706 gtk_stext_thaw(text);
708 if (account->protocol != A_NNTP) {
709 if (mailto && *mailto != '\0') {
710 compose_entries_set(compose, mailto);
712 } else if (item && item->prefs->enable_default_to) {
713 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
714 compose_entry_select(compose, item->prefs->default_to);
715 grab_focus_on_last = FALSE;
717 if (item && item->ret_rcpt) {
718 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
722 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
725 * CLAWS: just don't allow return receipt request, even if the user
726 * may want to send an email. simple but foolproof.
728 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
735 for (i = 0; i < attach_files->len; i++) {
736 file = g_ptr_array_index(attach_files, i);
737 compose_attach_append(compose, file, file, NULL);
741 compose_show_first_last_header(compose, TRUE);
743 /* Set save folder */
744 if (item && item->prefs && item->prefs->save_copy_to_folder) {
745 gchar *folderidentifier;
747 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
748 folderidentifier = folder_item_get_identifier(item);
749 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
750 g_free(folderidentifier);
753 /* Grab focus on last header only if no default_to was set */
754 if (grab_focus_on_last)
755 gtk_widget_grab_focus(compose->header_last->entry);
757 if (prefs_common.auto_exteditor)
758 compose_exec_ext_editor(compose);
764 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
765 const gchar *followupto, gchar * to)
769 if (!account) account = cur_account;
770 g_return_val_if_fail(account != NULL, NULL);
771 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
773 compose = compose_create(account, COMPOSE_NEW);
775 if (prefs_common.auto_sig)
776 compose_insert_sig(compose);
777 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
778 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
780 compose_entry_append(compose, to, COMPOSE_TO);
781 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
782 gtk_widget_grab_focus(compose->subject_entry);
788 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
789 gboolean to_ml, gboolean ignore_replyto,
792 compose_generic_reply(msginfo, quote, to_all, to_ml,
793 ignore_replyto, FALSE, body);
796 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
798 gboolean ignore_replyto,
801 compose_generic_reply(msginfo, quote, to_all, FALSE,
802 ignore_replyto, TRUE, body);
805 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
806 gboolean to_all, gboolean to_ml,
807 gboolean ignore_replyto,
808 gboolean followup_and_reply_to,
812 PrefsAccount *account = NULL;
813 PrefsAccount *reply_account;
816 g_return_if_fail(msginfo != NULL);
817 g_return_if_fail(msginfo->folder != NULL);
819 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
821 g_return_if_fail(account != NULL);
823 if (ignore_replyto && account->protocol == A_NNTP &&
824 !followup_and_reply_to) {
826 account_find_from_address(account->address);
828 reply_account = compose_current_mail_account();
832 reply_account = account;
834 compose = compose_create(account, COMPOSE_REPLY);
836 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
837 if (!compose->replyinfo)
838 compose->replyinfo = procmsg_msginfo_copy(msginfo);
840 if (msginfo->folder && msginfo->folder->ret_rcpt) {
841 GtkItemFactory *ifactory;
843 ifactory = gtk_item_factory_from_widget(compose->menubar);
844 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
847 /* Set save folder */
848 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
849 gchar *folderidentifier;
851 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
852 folderidentifier = folder_item_get_identifier(msginfo->folder);
853 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
854 g_free(folderidentifier);
857 if (compose_parse_header(compose, msginfo) < 0) return;
858 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
859 ignore_replyto, followup_and_reply_to);
860 compose_show_first_last_header(compose, TRUE);
862 text = GTK_STEXT(compose->text);
863 gtk_stext_freeze(text);
869 if (prefs_common.quotemark && *prefs_common.quotemark)
870 qmark = prefs_common.quotemark;
874 quote_str = compose_quote_fmt(compose, compose->replyinfo,
875 prefs_common.quotefmt,
879 if (prefs_common.auto_sig)
880 compose_insert_sig(compose);
882 if (quote && prefs_common.linewrap_quote)
883 compose_wrap_line_all(compose);
885 gtk_editable_set_position(GTK_EDITABLE(text), 0);
886 gtk_stext_set_point(text, 0);
888 gtk_stext_thaw(text);
889 gtk_widget_grab_focus(compose->text);
891 if (prefs_common.auto_exteditor)
892 compose_exec_ext_editor(compose);
895 #define INSERT_FW_HEADER(var, hdr) \
896 if (msginfo->var && *msginfo->var) { \
897 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
898 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
899 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
902 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
903 gboolean as_attach, const gchar *body)
908 g_return_val_if_fail(msginfo != NULL, NULL);
909 g_return_val_if_fail(msginfo->folder != NULL, NULL);
911 if (msginfo->folder->prefs->enable_default_account)
912 account = account_find_from_id(msginfo->folder->prefs->default_account);
914 account = msginfo->folder->folder->account;
915 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
917 Xstrdup_a(to, msginfo->to, return NULL);
919 account = account_find_from_address(to);
922 if (!account && prefs_common.forward_account_autosel) {
924 if (!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
926 account = account_find_from_address(cc);
930 if (account == NULL) {
931 account = cur_account;
933 account = msginfo->folder->folder->account;
934 if (!account) account = cur_account;
937 g_return_val_if_fail(account != NULL, NULL);
939 compose = compose_create(account, COMPOSE_FORWARD);
941 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
942 if (!compose->fwdinfo)
943 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
945 if (msginfo->subject && *msginfo->subject) {
946 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
947 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
951 text = GTK_STEXT(compose->text);
952 gtk_stext_freeze(text);
958 msgfile = procmsg_get_message_file_path(msginfo);
959 if (!is_file_exist(msgfile))
960 g_warning("%s: file not exist\n", msgfile);
962 compose_attach_append(compose, msgfile, msgfile,
969 MsgInfo *full_msginfo;
971 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
973 full_msginfo = procmsg_msginfo_copy(msginfo);
975 if (prefs_common.fw_quotemark &&
976 *prefs_common.fw_quotemark)
977 qmark = prefs_common.fw_quotemark;
981 quote_str = compose_quote_fmt(compose, full_msginfo,
982 prefs_common.fw_quotefmt,
984 compose_attach_parts(compose, msginfo);
986 procmsg_msginfo_free(full_msginfo);
989 if (prefs_common.auto_sig)
990 compose_insert_sig(compose);
992 if (prefs_common.linewrap_quote)
993 compose_wrap_line_all(compose);
995 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
996 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
998 gtk_stext_thaw(text);
999 #if 0 /* NEW COMPOSE GUI */
1000 if (account->protocol != A_NNTP)
1001 gtk_widget_grab_focus(compose->to_entry);
1003 gtk_widget_grab_focus(compose->newsgroups_entry);
1005 gtk_widget_grab_focus(compose->header_last->entry);
1007 if (prefs_common.auto_exteditor)
1008 compose_exec_ext_editor(compose);
1011 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1012 gchar *folderidentifier;
1014 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1015 folderidentifier = folder_item_get_identifier(msginfo->folder);
1016 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1017 g_free(folderidentifier);
1023 #undef INSERT_FW_HEADER
1025 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1032 g_return_val_if_fail(msginfo_list != NULL, NULL);
1034 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1035 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1039 if (account == NULL) {
1040 account = cur_account;
1042 account = msginfo->folder->folder->account;
1043 if (!account) account = cur_account;
1046 g_return_val_if_fail(account != NULL, NULL);
1048 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1049 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1050 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1053 compose = compose_create(account, COMPOSE_FORWARD);
1055 text = GTK_STEXT(compose->text);
1056 gtk_stext_freeze(text);
1058 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1059 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1060 if (!is_file_exist(msgfile))
1061 g_warning("%s: file not exist\n", msgfile);
1063 compose_attach_append(compose, msgfile, msgfile,
1068 if (prefs_common.auto_sig)
1069 compose_insert_sig(compose);
1071 if (prefs_common.linewrap_quote)
1072 compose_wrap_line_all(compose);
1074 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1075 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1077 gtk_stext_thaw(text);
1078 gtk_widget_grab_focus(compose->header_last->entry);
1080 #if 0 /* NEW COMPOSE GUI */
1081 if (account->protocol != A_NNTP)
1082 gtk_widget_grab_focus(compose->to_entry);
1084 gtk_widget_grab_focus(compose->newsgroups_entry);
1090 void compose_reedit(MsgInfo *msginfo)
1093 PrefsAccount *account = NULL;
1096 gchar buf[BUFFSIZE];
1098 g_return_if_fail(msginfo != NULL);
1099 g_return_if_fail(msginfo->folder != NULL);
1101 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1102 gchar queueheader_buf[BUFFSIZE];
1105 /* Select Account from queue headers */
1106 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1107 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1108 id = atoi(&queueheader_buf[22]);
1109 account = account_find_from_id(id);
1111 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1112 sizeof(queueheader_buf), "NAID:")) {
1113 id = atoi(&queueheader_buf[5]);
1114 account = account_find_from_id(id);
1116 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1117 sizeof(queueheader_buf), "MAID:")) {
1118 id = atoi(&queueheader_buf[5]);
1119 account = account_find_from_id(id);
1121 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1122 sizeof(queueheader_buf), "S:")) {
1123 account = account_find_from_address(queueheader_buf);
1126 account = msginfo->folder->folder->account;
1128 if (!account && prefs_common.reedit_account_autosel) {
1129 gchar from[BUFFSIZE];
1130 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1131 extract_address(from);
1132 account = account_find_from_address(from);
1135 if (!account) account = cur_account;
1136 g_return_if_fail(account != NULL);
1138 compose = compose_create(account, COMPOSE_REEDIT);
1139 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1141 if (msginfo->folder->stype == F_QUEUE
1142 || msginfo->folder->stype == F_DRAFT) {
1143 gchar queueheader_buf[BUFFSIZE];
1145 /* Set message save folder */
1146 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1149 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1150 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1151 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1155 if (compose_parse_header(compose, msginfo) < 0) return;
1156 compose_reedit_set_entry(compose, msginfo);
1158 text = GTK_STEXT(compose->text);
1159 gtk_stext_freeze(text);
1161 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1162 g_warning("Can't get text part\n");
1164 while (fgets(buf, sizeof(buf), fp) != NULL) {
1166 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1170 compose_attach_parts(compose, msginfo);
1172 gtk_stext_thaw(text);
1173 gtk_widget_grab_focus(compose->text);
1175 if (prefs_common.auto_exteditor)
1176 compose_exec_ext_editor(compose);
1179 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1183 GtkItemFactory *ifactory;
1185 g_return_val_if_fail(msginfo != NULL, NULL);
1188 account = cur_account;
1189 g_return_val_if_fail(account != NULL, NULL);
1191 compose = compose_create(account, COMPOSE_REDIRECT);
1192 ifactory = gtk_item_factory_from_widget(compose->menubar);
1194 compose->replyinfo = NULL;
1195 compose->fwdinfo = NULL;
1197 compose_show_first_last_header(compose, TRUE);
1199 gtk_widget_grab_focus(compose->header_last->entry);
1201 filename = procmsg_get_message_file(msginfo);
1202 if (filename == NULL)
1205 compose->redirect_filename = filename;
1207 compose_attach_parts(compose, msginfo);
1209 if (msginfo->subject)
1210 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1212 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1214 gtk_stext_freeze(GTK_STEXT(compose->text));
1215 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1216 gtk_editable_set_editable(GTK_EDITABLE(compose->text), FALSE);
1217 gtk_stext_thaw(GTK_STEXT(compose->text));
1219 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1220 menu_set_sensitive(ifactory, "/Add...", FALSE);
1221 menu_set_sensitive(ifactory, "/Remove", FALSE);
1222 menu_set_sensitive(ifactory, "/Property...", FALSE);
1224 ifactory = gtk_item_factory_from_widget(compose->menubar);
1225 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
1226 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
1227 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
1228 menu_set_sensitive(ifactory, "/Edit", FALSE);
1229 menu_set_sensitive(ifactory, "/Message/Save to draft folder", FALSE);
1230 menu_set_sensitive(ifactory, "/Message/Save and keep editing", FALSE);
1232 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
1233 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
1234 menu_set_sensitive(ifactory, "/Message/Mode/MIME", FALSE);
1235 menu_set_sensitive(ifactory, "/Message/Mode/Inline", FALSE);
1237 menu_set_sensitive(ifactory, "/Message/Priority", FALSE);
1238 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
1239 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1240 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1242 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1243 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1244 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1245 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1246 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1247 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, FALSE);
1252 GList *compose_get_compose_list(void)
1254 return compose_list;
1257 void compose_entry_append(Compose *compose, const gchar *address,
1258 ComposeEntryType type)
1262 if (!address || *address == '\0') return;
1264 #if 0 /* NEW COMPOSE GUI */
1267 entry = GTK_ENTRY(compose->cc_entry);
1270 entry = GTK_ENTRY(compose->bcc_entry);
1272 case COMPOSE_NEWSGROUPS:
1273 entry = GTK_ENTRY(compose->newsgroups_entry);
1277 entry = GTK_ENTRY(compose->to_entry);
1281 text = gtk_entry_get_text(entry);
1283 gtk_entry_append_text(entry, ", ");
1284 gtk_entry_append_text(entry, address);
1292 header = N_("Bcc:");
1294 case COMPOSE_REPLYTO:
1295 header = N_("Reply-To:");
1297 case COMPOSE_NEWSGROUPS:
1298 header = N_("Newsgroups:");
1300 case COMPOSE_FOLLOWUPTO:
1301 header = N_( "Followup-To:");
1308 header = prefs_common.trans_hdr ? gettext(header) : header;
1310 compose_add_header_entry(compose, header, (gchar *)address);
1313 void compose_entry_select (Compose *compose, const gchar *mailto)
1315 GSList *header_list;
1317 for (header_list = compose->header_list; header_list != NULL; header_list = header_list->next) {
1318 GtkEntry * entry = GTK_ENTRY(((ComposeHeaderEntry *)header_list->data)->entry);
1320 if (gtk_entry_get_text(entry) && !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1321 gtk_entry_select_region(entry, 0, -1);
1322 gtk_widget_grab_focus(GTK_WIDGET(entry));
1327 void compose_toolbar_cb(gint action, gpointer data)
1329 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1330 Compose *compose = (Compose*)toolbar_item->parent;
1332 g_return_if_fail(compose != NULL);
1336 compose_send_cb(compose, 0, NULL);
1339 compose_send_later_cb(compose, 0, NULL);
1342 compose_draft_cb(compose, 0, NULL);
1345 compose_insert_file_cb(compose, 0, NULL);
1348 compose_attach_cb(compose, 0, NULL);
1351 compose_insert_sig(compose);
1354 compose_ext_editor_cb(compose, 0, NULL);
1357 compose_wrap_line(compose);
1360 compose_address_cb(compose, 0, NULL);
1367 static void compose_entries_set(Compose *compose, const gchar *mailto)
1372 gchar *subject = NULL;
1375 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1378 compose_entry_append(compose, to, COMPOSE_TO);
1380 compose_entry_append(compose, cc, COMPOSE_CC);
1382 compose_entry_append(compose, bcc, COMPOSE_BCC);
1384 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1386 gtk_stext_insert(GTK_STEXT(compose->text),
1387 NULL, NULL, NULL, body, -1);
1388 gtk_stext_insert(GTK_STEXT(compose->text),
1389 NULL, NULL, NULL, "\n", 1);
1399 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1401 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1402 {"Cc:", NULL, FALSE},
1403 {"References:", NULL, FALSE},
1404 {"Bcc:", NULL, FALSE},
1405 {"Newsgroups:", NULL, FALSE},
1406 {"Followup-To:", NULL, FALSE},
1407 {"List-Post:", NULL, FALSE},
1408 {"X-Priority:", NULL, FALSE},
1409 {NULL, NULL, FALSE}};
1425 g_return_val_if_fail(msginfo != NULL, -1);
1427 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1428 procheader_get_header_fields(fp, hentry);
1431 if (hentry[H_REPLY_TO].body != NULL) {
1432 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1433 compose->replyto = hentry[H_REPLY_TO].body;
1434 hentry[H_REPLY_TO].body = NULL;
1436 if (hentry[H_CC].body != NULL) {
1437 conv_unmime_header_overwrite(hentry[H_CC].body);
1438 compose->cc = hentry[H_CC].body;
1439 hentry[H_CC].body = NULL;
1441 if (hentry[H_REFERENCES].body != NULL) {
1442 if (compose->mode == COMPOSE_REEDIT)
1443 compose->references = hentry[H_REFERENCES].body;
1445 compose->references = compose_parse_references
1446 (hentry[H_REFERENCES].body, msginfo->msgid);
1447 g_free(hentry[H_REFERENCES].body);
1449 hentry[H_REFERENCES].body = NULL;
1451 if (hentry[H_BCC].body != NULL) {
1452 if (compose->mode == COMPOSE_REEDIT) {
1453 conv_unmime_header_overwrite(hentry[H_BCC].body);
1454 compose->bcc = hentry[H_BCC].body;
1456 g_free(hentry[H_BCC].body);
1457 hentry[H_BCC].body = NULL;
1459 if (hentry[H_NEWSGROUPS].body != NULL) {
1460 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1461 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1462 hentry[H_NEWSGROUPS].body = NULL;
1464 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1465 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1466 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1467 hentry[H_FOLLOWUP_TO].body = NULL;
1469 if (hentry[H_LIST_POST].body != NULL) {
1472 extract_address(hentry[H_LIST_POST].body);
1473 if (hentry[H_LIST_POST].body[0] != '\0') {
1474 scan_mailto_url(hentry[H_LIST_POST].body,
1475 &to, NULL, NULL, NULL, NULL);
1477 g_free(compose->ml_post);
1478 compose->ml_post = to;
1481 g_free(hentry[H_LIST_POST].body);
1482 hentry[H_LIST_POST].body = NULL;
1485 /* CLAWS - X-Priority */
1486 if (compose->mode == COMPOSE_REEDIT)
1487 if (hentry[H_X_PRIORITY].body != NULL) {
1490 priority = atoi(hentry[H_X_PRIORITY].body);
1491 g_free(hentry[H_X_PRIORITY].body);
1493 hentry[H_X_PRIORITY].body = NULL;
1495 if (priority < PRIORITY_HIGHEST ||
1496 priority > PRIORITY_LOWEST)
1497 priority = PRIORITY_NORMAL;
1499 compose->priority = priority;
1502 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1503 compose->inreplyto = g_strdup(msginfo->inreplyto);
1504 else if (compose->mode != COMPOSE_REEDIT &&
1505 msginfo->msgid && *msginfo->msgid) {
1506 compose->inreplyto = g_strdup(msginfo->msgid);
1508 if (!compose->references) {
1509 if (msginfo->inreplyto && *msginfo->inreplyto)
1510 compose->references =
1511 g_strdup_printf("<%s>\n\t<%s>",
1515 compose->references =
1516 g_strconcat("<", msginfo->msgid, ">",
1524 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1526 GSList *ref_id_list, *cur;
1530 ref_id_list = references_list_append(NULL, ref);
1531 if (!ref_id_list) return NULL;
1532 if (msgid && *msgid)
1533 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1538 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1539 /* "<" + Message-ID + ">" + CR+LF+TAB */
1540 len += strlen((gchar *)cur->data) + 5;
1542 if (len > MAX_REFERENCES_LEN) {
1543 /* remove second message-ID */
1544 if (ref_id_list && ref_id_list->next &&
1545 ref_id_list->next->next) {
1546 g_free(ref_id_list->next->data);
1547 ref_id_list = g_slist_remove
1548 (ref_id_list, ref_id_list->next->data);
1550 slist_free_strings(ref_id_list);
1551 g_slist_free(ref_id_list);
1558 new_ref = g_string_new("");
1559 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1560 if (new_ref->len > 0)
1561 g_string_append(new_ref, "\n\t");
1562 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1565 slist_free_strings(ref_id_list);
1566 g_slist_free(ref_id_list);
1568 new_ref_str = new_ref->str;
1569 g_string_free(new_ref, FALSE);
1574 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1575 const gchar *fmt, const gchar *qmark,
1578 GtkSText *text = GTK_STEXT(compose->text);
1579 static MsgInfo dummyinfo;
1580 gchar *quote_str = NULL;
1586 msginfo = &dummyinfo;
1588 if (qmark != NULL) {
1589 quote_fmt_init(msginfo, NULL, NULL);
1590 quote_fmt_scan_string(qmark);
1593 buf = quote_fmt_get_buffer();
1595 alertpanel_error(_("Quote mark format error."));
1597 Xstrdup_a(quote_str, buf, return NULL)
1600 if (fmt && *fmt != '\0') {
1601 quote_fmt_init(msginfo, quote_str, body);
1602 quote_fmt_scan_string(fmt);
1605 buf = quote_fmt_get_buffer();
1607 alertpanel_error(_("Message reply/forward format error."));
1613 gtk_stext_freeze(text);
1615 for (p = buf; *p != '\0'; ) {
1616 lastp = strchr(p, '\n');
1617 len = lastp ? lastp - p + 1 : -1;
1618 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1625 gtk_stext_thaw(text);
1630 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1631 gboolean to_all, gboolean to_ml,
1632 gboolean ignore_replyto,
1633 gboolean followup_and_reply_to)
1635 GSList *cc_list = NULL;
1638 gchar *replyto = NULL;
1639 GHashTable *to_table;
1641 g_return_if_fail(compose->account != NULL);
1642 g_return_if_fail(msginfo != NULL);
1644 if (compose->account->protocol != A_NNTP || followup_and_reply_to) {
1645 if (!compose->replyto && to_ml && compose->ml_post
1646 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1647 compose_entry_append(compose,
1650 else if (!(to_all || ignore_replyto)
1652 && msginfo->folder->prefs->enable_default_reply_to) {
1653 compose_entry_append(compose,
1654 msginfo->folder->prefs->default_reply_to,
1657 compose_entry_append(compose,
1658 (compose->replyto && !ignore_replyto)
1660 : msginfo->from ? msginfo->from : "",
1664 compose_entry_append
1665 (compose, msginfo->from ? msginfo->from : "",
1668 if (compose->followup_to && !strncmp(compose->followup_to, "poster", 6)) {
1669 compose_entry_append
1671 ((compose->replyto && !ignore_replyto)
1673 : msginfo->from ? msginfo->from : ""),
1676 compose_entry_append
1678 compose->followup_to ? compose->followup_to
1679 : compose->newsgroups ? compose->newsgroups
1681 COMPOSE_NEWSGROUPS);
1686 if (msginfo->subject && *msginfo->subject) {
1687 gchar *buf, *buf2, *p;
1689 buf = g_strdup(msginfo->subject);
1690 while (!strncasecmp(buf, "Re:", 3)) {
1692 while (isspace(*p)) p++;
1693 memmove(buf, p, strlen(p) + 1);
1696 buf2 = g_strdup_printf("Re: %s", buf);
1697 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1701 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1703 if (to_ml && compose->ml_post) return;
1704 if (!to_all || compose->account->protocol == A_NNTP) return;
1706 if (compose->replyto) {
1707 Xstrdup_a(replyto, compose->replyto, return);
1708 extract_address(replyto);
1710 if (msginfo->from) {
1711 Xstrdup_a(from, msginfo->from, return);
1712 extract_address(from);
1715 if (replyto && from)
1716 cc_list = address_list_append(cc_list, from);
1717 cc_list = address_list_append(cc_list, msginfo->to);
1718 cc_list = address_list_append(cc_list, compose->cc);
1720 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1722 g_hash_table_insert(to_table, replyto, GINT_TO_POINTER(1));
1723 if (compose->account)
1724 g_hash_table_insert(to_table, compose->account->address,
1725 GINT_TO_POINTER(1));
1727 /* remove address on To: and that of current account */
1728 for (cur = cc_list; cur != NULL; ) {
1729 GSList *next = cur->next;
1731 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1732 cc_list = g_slist_remove(cc_list, cur->data);
1734 g_hash_table_insert(to_table, cur->data, cur);
1738 g_hash_table_destroy(to_table);
1741 for (cur = cc_list; cur != NULL; cur = cur->next)
1742 compose_entry_append(compose, (gchar *)cur->data,
1744 slist_free_strings(cc_list);
1745 g_slist_free(cc_list);
1749 #define SET_ENTRY(entry, str) \
1752 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1755 #define SET_ADDRESS(type, str) \
1758 compose_entry_append(compose, str, type); \
1761 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1763 g_return_if_fail(msginfo != NULL);
1765 SET_ENTRY(subject_entry, msginfo->subject);
1766 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1767 SET_ADDRESS(COMPOSE_CC, compose->cc);
1768 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1769 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1770 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
1771 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
1773 compose_update_priority_menu_item(compose);
1775 compose_update_gnupg_mode_menu_item(compose);
1777 compose_show_first_last_header(compose, TRUE);
1784 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1788 size_t buf_len = 128;
1790 if (strlen(sigfile) < 2)
1793 sigprg = popen(sigfile+1, "r");
1796 buf = g_malloc(buf_len);
1799 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1800 "Unable to insert signature (malloc failed)\n", -1);
1806 while (!feof(sigprg)) {
1807 bzero(buf, buf_len);
1808 fread(buf, buf_len-1, 1, sigprg);
1809 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1817 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1818 "Can't exec file: ", -1);
1819 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1824 static void compose_insert_sig(Compose *compose)
1828 if (compose->account && compose->account->sig_path)
1829 sigfile = g_strdup(compose->account->sig_path);
1831 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1832 DEFAULT_SIGNATURE, NULL);
1834 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1839 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1840 if (prefs_common.sig_sep) {
1841 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1842 prefs_common.sig_sep, -1);
1843 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1847 if (sigfile[0] == '|')
1848 compose_exec_sig(compose, sigfile);
1850 compose_insert_file(compose, sigfile);
1854 static void compose_insert_file(Compose *compose, const gchar *file)
1856 GtkSText *text = GTK_STEXT(compose->text);
1857 gchar buf[BUFFSIZE];
1861 g_return_if_fail(file != NULL);
1863 if ((fp = fopen(file, "rb")) == NULL) {
1864 FILE_OP_ERROR(file, "fopen");
1868 gtk_stext_freeze(text);
1870 while (fgets(buf, sizeof(buf), fp) != NULL) {
1871 /* strip <CR> if DOS/Windows file,
1872 replace <CR> with <LF> if Macintosh file. */
1875 if (len > 0 && buf[len - 1] != '\n') {
1877 if (buf[len] == '\r') buf[len] = '\n';
1879 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1882 gtk_stext_thaw(text);
1887 static void compose_attach_append(Compose *compose, const gchar *file,
1888 const gchar *filename,
1889 const gchar *content_type)
1892 gchar *text[N_ATTACH_COLS];
1897 if (!is_file_exist(file)) {
1898 g_warning("File %s doesn't exist\n", file);
1901 if ((size = get_file_size(file)) < 0) {
1902 g_warning("Can't get file size of %s\n", file);
1906 alertpanel_notice(_("File %s is empty."), file);
1909 if ((fp = fopen(file, "rb")) == NULL) {
1910 alertpanel_error(_("Can't read %s."), file);
1915 #if 0 /* NEW COMPOSE GUI */
1916 if (!compose->use_attach) {
1917 GtkItemFactory *ifactory;
1918 GtkWidget *menuitem;
1920 ifactory = gtk_item_factory_from_widget(compose->menubar);
1921 menuitem = gtk_item_factory_get_item(ifactory,
1922 "/View/Attachment");
1923 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1927 ainfo = g_new0(AttachInfo, 1);
1928 ainfo->file = g_strdup(file);
1931 ainfo->content_type = g_strdup(content_type);
1932 if (!strcasecmp(content_type, "message/rfc822")) {
1933 if (procmime_get_encoding_for_file(file) == ENC_7BIT)
1934 ainfo->encoding = ENC_7BIT;
1936 ainfo->encoding = ENC_8BIT;
1937 ainfo->name = g_strdup_printf
1939 g_basename(filename ? filename : file));
1941 if (!g_strncasecmp(content_type, "text", 4))
1943 procmime_get_encoding_for_file(file);
1945 ainfo->encoding = ENC_BASE64;
1946 ainfo->name = g_strdup
1947 (g_basename(filename ? filename : file));
1950 ainfo->content_type = procmime_get_mime_type(file);
1951 if (!ainfo->content_type) {
1952 ainfo->content_type =
1953 g_strdup("application/octet-stream");
1954 ainfo->encoding = ENC_BASE64;
1955 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
1956 ainfo->encoding = procmime_get_encoding_for_file(file);
1958 ainfo->encoding = ENC_BASE64;
1959 ainfo->name = g_strdup(g_basename(filename ? filename : file));
1963 text[COL_MIMETYPE] = ainfo->content_type;
1964 text[COL_SIZE] = to_human_readable(size);
1965 text[COL_NAME] = ainfo->name;
1967 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1968 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1971 #define IS_FIRST_PART_TEXT(info) \
1972 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
1973 info->mime_type == MIME_TEXT_ENRICHED) || \
1974 (info->mime_type == MIME_MULTIPART && info->content_type && \
1975 !strcasecmp(info->content_type, "multipart/alternative") && \
1976 (info->children && \
1977 (info->children->mime_type == MIME_TEXT || \
1978 info->children->mime_type == MIME_TEXT_HTML || \
1979 info->children->mime_type == MIME_TEXT_ENRICHED))))
1981 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
1988 mimeinfo = procmime_scan_message(msginfo);
1989 if (!mimeinfo) return;
1991 /* skip first text (presumably message body) */
1992 child = mimeinfo->children;
1993 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
1994 procmime_mimeinfo_free_all(mimeinfo);
1998 if (IS_FIRST_PART_TEXT(child))
1999 child = child->next;
2001 infile = procmsg_get_message_file_path(msginfo);
2003 while (child != NULL) {
2004 if (child->children || child->mime_type == MIME_MULTIPART) {
2005 child = procmime_mimeinfo_next(child);
2008 if(child->parent && child->parent->parent
2009 && !strcasecmp(child->parent->parent->content_type, "multipart/signed")
2010 && child->mime_type == MIME_TEXT) {
2011 /* this is the main text part of a signed message */
2012 child = procmime_mimeinfo_next(child);
2015 outfile = procmime_get_tmp_file_name(child);
2016 if (procmime_get_part(outfile, infile, child) < 0)
2017 g_warning("Can't get the part of multipart message.");
2018 else if (compose->mode != COMPOSE_REEDIT || strcmp(child->content_type, "application/pgp-signature"))
2019 compose_attach_append
2021 child->filename ? child->filename : child->name,
2022 child->content_type);
2024 child = child->next;
2028 procmime_mimeinfo_free_all(mimeinfo);
2031 #undef IS_FIRST_PART_TEXT
2033 #define GET_CHAR(pos, buf, len) \
2035 if (text->use_wchar) \
2036 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2038 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2043 #define INDENT_CHARS ">|#"
2044 #define SPACE_CHARS " \t"
2046 static void compose_wrap_line(Compose *compose)
2048 GtkSText *text = GTK_STEXT(compose->text);
2049 gint ch_len, last_ch_len;
2050 gchar cbuf[MB_LEN_MAX], last_ch;
2054 gint p_start, p_end;
2055 gint line_pos, cur_pos;
2056 gint line_len, cur_len;
2058 gtk_stext_freeze(text);
2060 text_len = gtk_stext_get_length(text);
2062 /* check to see if the point is on the paragraph mark (empty line). */
2063 cur_pos = gtk_stext_get_point(text);
2064 GET_CHAR(cur_pos, cbuf, ch_len);
2065 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2067 goto compose_end; /* on the paragraph mark */
2068 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2069 if (ch_len == 1 && *cbuf == '\n')
2070 goto compose_end; /* on the paragraph mark */
2073 /* find paragraph start. */
2074 line_end = quoted = 0;
2075 for (p_start = cur_pos; p_start >= 0; --p_start) {
2076 GET_CHAR(p_start, cbuf, ch_len);
2077 if (ch_len == 1 && *cbuf == '\n') {
2079 goto compose_end; /* quoted part */
2087 && strchr(prefs_common.quote_chars, *cbuf))
2089 else if (ch_len != 1 || !isspace(*cbuf))
2098 /* find paragraph end. */
2100 for (p_end = cur_pos; p_end < text_len; p_end++) {
2101 GET_CHAR(p_end, cbuf, ch_len);
2102 if (ch_len == 1 && *cbuf == '\n') {
2109 if (line_end && ch_len == 1 &&
2110 strchr(prefs_common.quote_chars, *cbuf))
2111 goto compose_end; /* quoted part */
2116 if (p_end >= text_len)
2119 if (p_start >= p_end)
2122 line_len = cur_len = 0;
2126 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2129 GET_CHAR(cur_pos, cbuf, ch_len);
2136 if (ch_len == 1 && isspace(*cbuf))
2139 if (ch_len == 1 && *cbuf == '\n') {
2141 if (last_ch_len == 1 && !isspace(last_ch)) {
2142 if (cur_pos + 1 < p_end) {
2143 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2144 if (ch_len == 1 && !isspace(*cbuf))
2148 gtk_stext_set_point(text, cur_pos + 1);
2149 gtk_stext_backward_delete(text, 1);
2151 gtk_stext_set_point(text, cur_pos);
2152 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2162 last_ch_len = ch_len;
2166 line_pos = cur_pos + 1;
2167 line_len = cur_len + ch_len;
2170 if (cur_len + ch_len > prefs_common.linewrap_len &&
2174 GET_CHAR(line_pos - 1, cbuf, ch_len);
2175 if (ch_len == 1 && isspace(*cbuf)) {
2176 gtk_stext_set_point(text, line_pos);
2177 gtk_stext_backward_delete(text, 1);
2186 gtk_stext_set_point(text, line_pos);
2187 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2191 cur_len = cur_len - line_len + ch_len;
2197 line_pos = cur_pos + 1;
2198 line_len = cur_len + ch_len;
2204 gtk_stext_thaw(text);
2209 /* Darko: used when I debug wrapping */
2210 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2213 gchar cbuf[MB_LEN_MAX];
2215 printf("%d [", pos);
2216 for (i = pos; i < tlen; i++) {
2217 GET_CHAR(i, cbuf, clen);
2218 if (clen < 0) break;
2219 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2221 fwrite(cbuf, clen, 1, stdout);
2229 WAIT_FOR_INDENT_CHAR,
2230 WAIT_FOR_INDENT_CHAR_OR_SPACE
2233 /* return indent length, we allow:
2234 > followed by spaces/tabs
2235 | followed by spaces/tabs
2236 uppercase characters immediately followed by >,
2237 and the repeating sequences of the above */
2238 /* return indent length */
2239 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2242 guint i, ch_len, alnum_cnt = 0;
2243 IndentState state = WAIT_FOR_INDENT_CHAR;
2244 gchar cbuf[MB_LEN_MAX];
2248 for (i = start_pos; i < text_len; i++) {
2249 GET_CHAR(i, cbuf, ch_len);
2253 if (cbuf[0] == '\n')
2256 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2257 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2260 case WAIT_FOR_SPACE:
2261 if (is_space == FALSE)
2263 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2265 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2266 if (is_indent == FALSE && is_space == FALSE &&
2269 if (is_space == TRUE) {
2271 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2272 } else if (is_indent == TRUE) {
2274 state = WAIT_FOR_SPACE;
2277 state = WAIT_FOR_INDENT_CHAR;
2280 case WAIT_FOR_INDENT_CHAR:
2281 if (is_indent == FALSE && !isupper(cbuf[0]))
2283 if (is_indent == TRUE) {
2285 && !strchr(prefs_common.quote_chars, cbuf[0]))
2288 state = WAIT_FOR_SPACE;
2299 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2305 /* insert quotation string when line was wrapped */
2306 static guint ins_quote(GtkSText *text, guint indent_len,
2307 guint prev_line_pos, guint text_len,
2310 guint i, ins_len = 0;
2314 for (i = 0; i < indent_len; i++) {
2315 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2316 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2318 ins_len = indent_len;
2324 /* check if we should join the next line */
2325 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2326 guint prev_ilen, gboolean autowrap)
2328 guint indent_len, ch_len;
2329 gboolean do_join = FALSE;
2330 gchar cbuf[MB_LEN_MAX];
2332 indent_len = get_indent_length(text, start_pos, tlen);
2334 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2335 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2336 if (ch_len > 0 && (cbuf[0] != '\n'))
2343 static void compose_wrap_line_all(Compose *compose)
2345 compose_wrap_line_all_full(compose, FALSE);
2348 #define STEXT_FREEZE() \
2349 if (!frozen) { gtk_stext_freeze(text); frozen = TRUE; }
2351 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2353 GtkSText *text = GTK_STEXT(compose->text);
2355 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2356 gint line_len = 0, cur_len = 0;
2358 gboolean is_new_line = TRUE, do_delete = FALSE;
2360 gboolean linewrap_quote = TRUE;
2361 gboolean set_editable_pos = FALSE;
2362 gint editable_pos = 0;
2363 gboolean frozen = FALSE;
2364 guint linewrap_len = prefs_common.linewrap_len;
2365 gchar *qfmt = prefs_common.quotemark;
2366 gchar cbuf[MB_LEN_MAX];
2368 tlen = gtk_stext_get_length(text);
2370 for (; cur_pos < tlen; cur_pos++) {
2371 /* mark position of new line - needed for quotation wrap */
2374 i_len = get_indent_length(text, cur_pos, tlen);
2376 is_new_line = FALSE;
2379 g_print("new line i_len=%d p_pos=", i_len);
2380 dump_text(text, p_pos, tlen, 1);
2384 GET_CHAR(cur_pos, cbuf, ch_len);
2386 /* fix line length for tabs */
2387 if (ch_len == 1 && *cbuf == '\t') {
2388 guint tab_width = text->default_tab_width;
2389 guint tab_offset = line_len % tab_width;
2392 g_print("found tab at pos=%d line_len=%d ", cur_pos,
2396 line_len += tab_width - tab_offset - 1;
2400 printf("new_len=%d\n", line_len);
2404 /* we have encountered line break */
2405 if (ch_len == 1 && *cbuf == '\n') {
2407 gchar cb[MB_LEN_MAX];
2409 /* should we join the next line */
2410 if ((autowrap || i_len != cur_len) && do_delete &&
2412 (text, cur_pos + 1, tlen, i_len, autowrap))
2418 g_print("found CR at %d do_del is %d next line is ",
2419 cur_pos, do_delete);
2420 dump_text(text, cur_pos + 1, tlen, 1);
2423 /* skip delete if it is continuous URL */
2424 if (do_delete && (line_pos - p_pos <= i_len) &&
2425 gtk_stext_is_uri_string(text, line_pos, tlen))
2429 g_print("l_len=%d wrap_len=%d do_del=%d\n",
2430 line_len, linewrap_len, do_delete);
2432 /* should we delete to perform smart wrapping */
2433 if (line_len < linewrap_len && do_delete) {
2435 /* get rid of newline */
2436 gtk_stext_set_point(text, cur_pos);
2437 gtk_stext_forward_delete(text, 1);
2440 /* if text starts with quote fmt or with
2441 indent string, delete them */
2444 ilen = gtk_stext_str_compare_n
2445 (text, cur_pos, p_pos, i_len,
2448 gtk_stext_forward_delete
2454 GET_CHAR(cur_pos, cb, clen);
2456 /* insert space if it's alphanumeric */
2457 if ((cur_pos != line_pos) &&
2458 ((clen > 1) || isalnum(cb[0]))) {
2459 gtk_stext_insert(text, NULL, NULL,
2464 /* and start over with current line */
2465 cur_pos = p_pos - 1;
2467 line_len = cur_len = 0;
2471 g_print("after delete l_pos=");
2472 dump_text(text, line_pos, tlen, 1);
2477 /* mark new line beginning */
2478 line_pos = cur_pos + 1;
2479 line_len = cur_len = 0;
2490 /* possible line break */
2491 if (ch_len == 1 && isspace(*cbuf)) {
2492 line_pos = cur_pos + 1;
2493 line_len = cur_len + ch_len;
2496 /* are we over wrapping length set in preferences ? */
2497 if (cur_len + ch_len > linewrap_len) {
2501 g_print("should wrap cur_pos=%d ", cur_pos);
2502 dump_text(text, p_pos, tlen, 1);
2503 dump_text(text, line_pos, tlen, 1);
2505 /* force wrapping if it is one long word but not URL */
2506 if (line_pos - p_pos <= i_len)
2507 if (!gtk_stext_is_uri_string
2508 (text, line_pos, tlen))
2509 line_pos = cur_pos - 1;
2511 g_print("new line_pos=%d\n", line_pos);
2514 GET_CHAR(line_pos - 1, cbuf, clen);
2516 /* if next character is space delete it */
2517 if (clen == 1 && isspace(*cbuf)) {
2518 if (p_pos + i_len != line_pos ||
2519 !gtk_stext_is_uri_string
2520 (text, line_pos, tlen)) {
2522 /* workaround for correct cursor
2524 if (set_editable_pos == FALSE) {
2525 editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2526 if (editable_pos == line_pos)
2527 set_editable_pos = TRUE;
2529 gtk_stext_set_point(text, line_pos);
2530 gtk_stext_backward_delete(text, 1);
2539 /* if it is URL at beginning of line don't wrap */
2540 if (p_pos + i_len == line_pos &&
2541 gtk_stext_is_uri_string(text, line_pos, tlen)) {
2543 g_print("found URL at ");
2544 dump_text(text, line_pos, tlen, 1);
2551 gtk_stext_set_point(text, line_pos);
2552 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2553 /* gtk_stext_compact_buffer(text); */
2556 /* for loop will increase it */
2557 cur_pos = line_pos - 1;
2558 /* start over with current line */
2560 line_len = cur_len = 0;
2561 if (autowrap || i_len > 0)
2566 g_print("after CR insert ");
2567 dump_text(text, line_pos, tlen, 1);
2568 dump_text(text, cur_pos, tlen, 1);
2571 /* should we insert quotation ? */
2572 if (linewrap_quote && i_len) {
2573 /* only if line is not already quoted */
2574 if (!gtk_stext_str_compare
2575 (text, line_pos, tlen, qfmt)) {
2578 if (line_pos - p_pos > i_len) {
2580 (text, i_len, p_pos,
2585 g_print("after quote insert ");
2586 dump_text(text, line_pos, tlen, 1);
2594 line_pos = cur_pos + 1;
2595 line_len = cur_len + ch_len;
2597 /* advance to next character in buffer */
2602 gtk_stext_thaw(text);
2604 if (set_editable_pos && editable_pos <= tlen)
2605 gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
2611 static void compose_set_title(Compose *compose)
2616 edited = compose->modified ? _(" [Edited]") : "";
2617 if (compose->account && compose->account->address)
2618 str = g_strdup_printf(_("%s - Compose message%s"),
2619 compose->account->address, edited);
2621 str = g_strdup_printf(_("Compose message%s"), edited);
2622 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2627 * compose_current_mail_account:
2629 * Find a current mail account (the currently selected account, or the
2630 * default account, if a news account is currently selected). If a
2631 * mail account cannot be found, display an error message.
2633 * Return value: Mail account, or NULL if not found.
2635 static PrefsAccount *
2636 compose_current_mail_account(void)
2640 if (cur_account && cur_account->protocol != A_NNTP)
2643 ac = account_get_default();
2644 if (!ac || ac->protocol == A_NNTP) {
2645 alertpanel_error(_("Account for sending mail is not specified.\n"
2646 "Please select a mail account before sending."));
2653 static void compose_select_account(Compose *compose, PrefsAccount *account)
2655 GtkWidget *menuitem;
2656 GtkItemFactory *ifactory;
2658 g_return_if_fail(account != NULL);
2660 compose->account = account;
2662 compose_set_title(compose);
2664 ifactory = gtk_item_factory_from_widget(compose->menubar);
2666 if (account->protocol == A_NNTP) {
2667 gtk_widget_show(compose->newsgroups_hbox);
2668 gtk_widget_show(compose->newsgroups_entry);
2669 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2670 compose->use_newsgroups = TRUE;
2672 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2673 gtk_check_menu_item_set_active
2674 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2675 gtk_widget_set_sensitive(menuitem, TRUE);
2676 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2677 gtk_check_menu_item_set_active
2678 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2679 gtk_widget_set_sensitive(menuitem, TRUE);
2681 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
2683 gtk_widget_hide(compose->newsgroups_hbox);
2684 gtk_widget_hide(compose->newsgroups_entry);
2685 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
2686 gtk_widget_queue_resize(compose->table_vbox);
2687 compose->use_newsgroups = FALSE;
2689 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2690 gtk_check_menu_item_set_active
2691 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2692 gtk_widget_set_sensitive(menuitem, FALSE);
2693 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2694 gtk_check_menu_item_set_active
2695 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2696 gtk_widget_set_sensitive(menuitem, FALSE);
2698 menuitem = gtk_item_factory_get_item(ifactory, "/View/Followup to");
2699 gtk_check_menu_item_set_active
2700 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2701 gtk_widget_set_sensitive(menuitem, FALSE);
2704 if (account->set_autocc) {
2705 compose_entry_show(compose, COMPOSE_ENTRY_CC);
2706 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
2707 compose_entry_set(compose, account->auto_cc,
2710 if (account->set_autobcc) {
2711 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
2712 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
2713 compose_entry_set(compose, account->auto_bcc,
2716 if (account->set_autoreplyto) {
2717 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
2718 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
2719 compose_entry_set(compose, account->auto_replyto,
2720 COMPOSE_ENTRY_REPLY_TO);
2723 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
2724 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2725 prefs_common.show_ruler);
2729 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
2730 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2731 account->default_sign);
2732 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
2733 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2734 account->default_encrypt);
2736 activate_gnupg_mode(compose, account);
2737 #endif /* USE_GPGME */
2740 gboolean compose_check_for_valid_recipient(Compose *compose) {
2741 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2742 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2743 gboolean recipient_found = FALSE;
2747 /* free to and newsgroup list */
2748 slist_free_strings(compose->to_list);
2749 g_slist_free(compose->to_list);
2750 compose->to_list = NULL;
2752 slist_free_strings(compose->newsgroup_list);
2753 g_slist_free(compose->newsgroup_list);
2754 compose->newsgroup_list = NULL;
2756 /* search header entries for to and newsgroup entries */
2757 for (list = compose->header_list; list; list = list->next) {
2760 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
2761 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2763 if (entry[0] != '\0') {
2764 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2765 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2766 compose->to_list = address_list_append(compose->to_list, entry);
2767 recipient_found = TRUE;
2770 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2771 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2772 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2773 recipient_found = TRUE;
2780 return recipient_found;
2783 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
2787 if (compose_check_for_valid_recipient(compose) == FALSE) {
2788 alertpanel_error(_("Recipient is not specified."));
2792 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2793 if (*str == '\0' && check_subject == TRUE) {
2796 aval = alertpanel(_("Send"),
2797 _("Subject is empty. Send it anyway?"),
2798 _("Yes"), _("No"), NULL);
2799 if (aval != G_ALERTDEFAULT)
2806 gint compose_send(Compose *compose)
2813 if (compose_check_entries(compose, TRUE) == FALSE)
2816 val = compose_queue(compose, &msgnum, &folder);
2818 alertpanel_error(_("Could not queue message for sending"));
2823 alertpanel_error(_("The message was queue but could not be send.\nUse \"Send queued messages\" from the main window to send it"));
2827 msgpath = folder_item_fetch_msg(folder, msgnum);
2828 val = procmsg_send_message_queue(msgpath);
2831 folder_item_remove_msg(folder, msgnum);
2836 #if 0 /* compose restructure */
2837 gint compose_send(Compose *compose)
2839 gchar tmp[MAXPATHLEN + 1];
2841 static gboolean lock = FALSE;
2845 g_return_val_if_fail(compose->account != NULL, -1);
2849 if (compose_check_entries(compose, TRUE) == FALSE) {
2854 /* write to temporary file */
2855 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
2856 get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
2858 if (prefs_common.linewrap_at_send)
2859 compose_wrap_line_all(compose);
2861 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2866 if (!compose->to_list && !compose->newsgroup_list) {
2867 g_warning("can't get recipient list.");
2873 if (compose->to_list) {
2876 #if 0 /* NEW COMPOSE GUI */
2877 if (compose->account->protocol != A_NNTP)
2878 ac = compose->account;
2880 ac = account_find_from_address(compose->account->address);
2882 if (cur_account && cur_account->protocol != A_NNTP)
2885 ac = account_get_default();
2887 if (!ac || ac->protocol == A_NNTP) {
2888 alertpanel_error(_("Account for sending mail is not specified.\n"
2889 "Please select a mail account before sending."));
2896 ac = compose->account;
2898 ok = send_message(tmp, ac, compose->to_list);
2901 if (ok == 0 && compose->newsgroup_list) {
2902 ok = news_post(FOLDER(compose->account->folder), tmp);
2904 alertpanel_error(_("Error occurred while posting the message to %s ."),
2905 compose->account->nntp_server);
2912 /* queue message if failed to send */
2914 if (prefs_common.queue_msg) {
2919 _("Error occurred while sending the message.\n"
2920 "Put this message into queue folder?"),
2921 _("OK"), _("Cancel"), NULL);
2922 if (G_ALERTDEFAULT == val) {
2923 ok = compose_queue(compose, tmp);
2925 alertpanel_error(_("Can't queue the message."));
2928 alertpanel_error_log(_("Error occurred while sending the message."));
2930 if (compose->mode == COMPOSE_REEDIT) {
2931 compose_remove_reedit_target(compose);
2933 /* save message to outbox */
2934 if (prefs_common.savemsg) {
2937 outbox = account_get_special_folder
2938 (compose->account, F_OUTBOX);
2939 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
2941 (_("Can't save the message to Sent."));
2951 static gboolean compose_use_attach(Compose *compose) {
2952 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2955 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
2958 gchar buf[BUFFSIZE];
2960 gboolean first_address;
2962 ComposeHeaderEntry *headerentry;
2963 gchar *headerentryname;
2967 debug_print("Writing redirect header\n");
2969 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
2970 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
2972 first_address = TRUE;
2973 for (list = compose->header_list; list; list = list->next) {
2974 headerentry = ((ComposeHeaderEntry *)list->data);
2975 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2977 if (g_strcasecmp(headerentryname, cc_hdr) == 0
2978 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2979 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2980 Xstrdup_a(str, str, return -1);
2982 if (str[0] != '\0') {
2983 compose_convert_header
2984 (buf, sizeof(buf), str,
2985 strlen("Resent-To") + 2);
2986 if (first_address) {
2987 fprintf(fp, "Resent-To: ");
2988 first_address = FALSE;
2992 fprintf(fp, "%s", buf);
2996 /* if (!first_address) { */
3003 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3005 gchar buf[BUFFSIZE];
3007 /* struct utsname utsbuf; */
3009 g_return_val_if_fail(fp != NULL, -1);
3010 g_return_val_if_fail(compose->account != NULL, -1);
3011 g_return_val_if_fail(compose->account->address != NULL, -1);
3014 get_rfc822_date(buf, sizeof(buf));
3015 fprintf(fp, "Resent-Date: %s\n", buf);
3018 if (compose->account->name && *compose->account->name) {
3019 compose_convert_header
3020 (buf, sizeof(buf), compose->account->name,
3022 fprintf(fp, "Resent-From: %s <%s>\n",
3023 buf, compose->account->address);
3025 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3028 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3030 Xstrdup_a(str, str, return -1);
3033 compose_convert_header(buf, sizeof(buf), str,
3034 strlen("Subject: "));
3035 fprintf(fp, "Subject: %s\n", buf);
3039 /* Resent-Message-ID */
3040 if (compose->account->gen_msgid) {
3041 compose_generate_msgid(compose, buf, sizeof(buf));
3042 fprintf(fp, "Resent-Message-Id: <%s>\n", buf);
3043 compose->msgid = g_strdup(buf);
3046 compose_redirect_write_headers_from_headerlist(compose, fp);
3048 /* separator between header and body */
3054 static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
3059 gchar buf[BUFFSIZE];
3061 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3062 FILE_OP_ERROR(file, "fopen");
3066 if ((fdest = fopen(file, "wb")) == NULL) {
3067 FILE_OP_ERROR(file, "fopen");
3072 /* chmod for security */
3073 if (change_file_mode_rw(fdest, file) < 0) {
3074 FILE_OP_ERROR(file, "chmod");
3075 g_warning("can't change file mode\n");
3078 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
3079 /* should filter returnpath, delivered-to */
3080 if (g_strncasecmp(buf, "Return-Path:",
3081 strlen("Return-Path:")) == 0 ||
3082 g_strncasecmp(buf, "Delivered-To:",
3083 strlen("Delivered-To:")) == 0 ||
3084 g_strncasecmp(buf, "Received:",
3085 strlen("Received:")) == 0 ||
3086 g_strncasecmp(buf, "Subject:",
3087 strlen("Subject:")) == 0 ||
3088 g_strncasecmp(buf, "X-UIDL:",
3089 strlen("X-UIDL:")) == 0)
3092 if (fputs(buf, fdest) == -1)
3095 if (!prefs_common.redirect_keep_from) {
3096 if (g_strncasecmp(buf, "From:",
3097 strlen("From:")) == 0) {
3098 fputs(" (by way of ", fdest);
3099 if (compose->account->name
3100 && *compose->account->name) {
3101 compose_convert_header
3103 compose->account->name,
3105 fprintf(fdest, "%s <%s>",
3107 compose->account->address);
3109 fprintf(fdest, "%s",
3110 compose->account->address);
3115 if (fputs("\n", fdest) == -1)
3119 compose_redirect_write_headers(compose, fdest);
3121 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3122 if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
3123 FILE_OP_ERROR(file, "fwrite");
3129 if (fclose(fdest) == EOF) {
3130 FILE_OP_ERROR(file, "fclose");
3146 /* interfaces to rfc2015 to keep out the prefs stuff there.
3147 * returns 0 on success and -1 on error. */
3148 static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
3150 const gchar *key_id = NULL;
3153 switch (compose->account->sign_key) {
3154 case SIGN_KEY_DEFAULT:
3157 case SIGN_KEY_BY_FROM:
3158 key_id = compose->account->address;
3160 case SIGN_KEY_CUSTOM:
3161 key_id = compose->account->sign_key_id;
3167 key_list = rfc2015_create_signers_list(key_id);
3170 alertpanel_error(_("Could not find any key associated with "
3171 "currently selected key id `%s'."), key_id);
3175 *pkey_list = key_list;
3179 /* clearsign message body text */
3180 static gint compose_clearsign_text(Compose *compose, gchar **text)
3185 tmp_file = get_tmp_file();
3186 if (str_write_to_file(*text, tmp_file) < 0) {
3191 if (compose_create_signers_list(compose, &key_list) < 0 ||
3192 rfc2015_clearsign(tmp_file, key_list) < 0) {
3199 *text = file_read_to_str(tmp_file);
3207 #endif /* USE_GPGME */
3209 static gint compose_write_to_file(Compose *compose, const gchar *file,
3217 const gchar *out_codeset;
3218 EncodingType encoding;
3220 if ((fp = fopen(file, "wb")) == NULL) {
3221 FILE_OP_ERROR(file, "fopen");
3225 /* chmod for security */
3226 if (change_file_mode_rw(fp, file) < 0) {
3227 FILE_OP_ERROR(file, "chmod");
3228 g_warning("can't change file mode\n");
3231 /* get all composed text */
3232 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3233 len = strlen(chars);
3234 if (is_ascii_str(chars)) {
3237 out_codeset = CS_US_ASCII;
3238 encoding = ENC_7BIT;
3240 const gchar *src_codeset;
3242 out_codeset = conv_get_outgoing_charset_str();
3243 if (!strcasecmp(out_codeset, CS_US_ASCII))
3244 out_codeset = CS_ISO_8859_1;
3246 if (prefs_common.encoding_method == CTE_BASE64)
3247 encoding = ENC_BASE64;
3248 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3249 encoding = ENC_QUOTED_PRINTABLE;
3250 else if (prefs_common.encoding_method == CTE_8BIT)
3251 encoding = ENC_8BIT;
3253 encoding = procmime_get_encoding_for_charset(out_codeset);
3257 compose->use_signing && !compose->gnupg_mode &&
3258 encoding == ENC_8BIT)
3259 encoding = ENC_BASE64;
3262 src_codeset = conv_get_current_charset_str();
3263 /* if current encoding is US-ASCII, set it the same as
3264 outgoing one to prevent code conversion failure */
3265 if (!strcasecmp(src_codeset, CS_US_ASCII))
3266 src_codeset = out_codeset;
3268 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3269 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3271 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3277 _("Can't convert the character encoding of the message.\n"
3278 "Send it anyway?"), _("Yes"), _("+No"), NULL);
3279 if (aval != G_ALERTDEFAULT) {
3292 canon_buf = canonicalize_str(buf);
3297 if (!is_draft && compose->use_signing && compose->gnupg_mode) {
3298 if (compose_clearsign_text(compose, &buf) < 0) {
3299 g_warning("clearsign failed\n");
3309 if (compose_write_headers
3310 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3311 g_warning("can't write headers\n");
3318 if (compose_use_attach(compose)) {
3320 /* This prolog message is ignored by mime software and
3321 * because it would make our signing/encryption task
3322 * tougher, we don't emit it in that case */
3323 if (!compose->use_signing && !compose->use_encryption)
3325 fputs("This is a multi-part message in MIME format.\n", fp);
3327 fprintf(fp, "\n--%s\n", compose->boundary);
3328 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3330 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3331 procmime_get_encoding_str(encoding));
3337 if (encoding == ENC_BASE64) {
3338 gchar outbuf[B64_BUFFSIZE];
3341 for (i = 0; i < len; i += B64_LINE_SIZE) {
3342 l = MIN(B64_LINE_SIZE, len - i);
3343 base64_encode(outbuf, buf + i, l);
3347 } else if (encoding == ENC_QUOTED_PRINTABLE) {
3351 outbuf = g_malloc(len * 4);
3352 qp_encode_line(outbuf, buf);
3353 outlen = strlen(outbuf);
3354 if (fwrite(outbuf, sizeof(gchar), outlen, fp) != outlen) {
3355 FILE_OP_ERROR(file, "fwrite");
3363 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3364 FILE_OP_ERROR(file, "fwrite");
3372 if (compose_use_attach(compose))
3373 compose_write_attach(compose, fp);
3375 if (fclose(fp) == EOF) {
3376 FILE_OP_ERROR(file, "fclose");
3383 uncanonicalize_file_replace(file);
3387 if ((compose->use_signing && !compose->gnupg_mode) ||
3388 compose->use_encryption) {
3389 if (canonicalize_file_replace(file) < 0) {
3395 if (compose->use_signing && !compose->gnupg_mode) {
3398 if (compose_create_signers_list(compose, &key_list) < 0 ||
3399 rfc2015_sign(file, key_list) < 0) {
3404 if (compose->use_encryption) {
3405 if (rfc2015_encrypt(file, compose->to_list,
3406 compose->gnupg_mode) < 0) {
3411 #endif /* USE_GPGME */
3413 uncanonicalize_file_replace(file);
3418 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3424 if ((fp = fopen(file, "wb")) == NULL) {
3425 FILE_OP_ERROR(file, "fopen");
3429 /* chmod for security */
3430 if (change_file_mode_rw(fp, file) < 0) {
3431 FILE_OP_ERROR(file, "chmod");
3432 g_warning("can't change file mode\n");
3435 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3438 len = strlen(chars);
3439 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3440 FILE_OP_ERROR(file, "fwrite");
3449 if (fclose(fp) == EOF) {
3450 FILE_OP_ERROR(file, "fclose");
3457 static gint compose_remove_reedit_target(Compose *compose)
3460 MsgInfo *msginfo = compose->targetinfo;
3462 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3463 if (!msginfo) return -1;
3465 item = msginfo->folder;
3466 g_return_val_if_fail(item != NULL, -1);
3468 if (procmsg_msg_exist(msginfo) &&
3469 (item->stype == F_DRAFT || item->stype == F_QUEUE
3470 || msginfo == compose->autosaved_draft)) {
3471 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3472 g_warning("can't remove the old message\n");
3480 void compose_remove_draft(Compose *compose)
3483 MsgInfo *msginfo = compose->targetinfo;
3484 drafts = account_get_special_folder(compose->account, F_DRAFT);
3486 if (procmsg_msg_exist(msginfo)) {
3487 folder_item_remove_msg(drafts, msginfo->msgnum);
3492 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3494 return compose_queue_sub (compose, msgnum, item, FALSE);
3496 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3502 gchar buf[BUFFSIZE];
3504 static gboolean lock = FALSE;
3505 PrefsAccount *mailac = NULL, *newsac = NULL;
3507 debug_print("queueing message...\n");
3508 g_return_val_if_fail(compose->account != NULL, -1);
3512 if (compose_check_entries(compose, check_subject) == FALSE) {
3517 if (!compose->to_list && !compose->newsgroup_list) {
3518 g_warning("can't get recipient list.");
3523 if (compose->to_list) {
3524 if (compose->account->protocol != A_NNTP)
3525 mailac = compose->account;
3526 else if (cur_account && cur_account->protocol != A_NNTP)
3527 mailac = cur_account;
3528 else if (!(mailac = compose_current_mail_account())) {
3530 alertpanel_error(_("No account for sending mails available!"));
3535 if (compose->newsgroup_list) {
3536 if (compose->account->protocol == A_NNTP)
3537 newsac = compose->account;
3538 else if (!newsac->protocol != A_NNTP) {
3540 alertpanel_error(_("No account for posting news available!"));
3545 if (prefs_common.linewrap_at_send)
3546 compose_wrap_line_all(compose);
3548 /* write to temporary file */
3549 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3550 G_DIR_SEPARATOR, (gint)compose);
3552 if (compose->redirect_filename != NULL) {
3553 if (compose_redirect_write_to_file(compose, tmp2) < 0) {
3560 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3567 /* add queue header */
3568 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3569 G_DIR_SEPARATOR, (gint)compose);
3570 if ((fp = fopen(tmp, "wb")) == NULL) {
3571 FILE_OP_ERROR(tmp, "fopen");
3575 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3576 FILE_OP_ERROR(tmp2, "fopen");
3584 if (change_file_mode_rw(fp, tmp) < 0) {
3585 FILE_OP_ERROR(tmp, "chmod");
3586 g_warning("can't change file mode\n");
3589 /* queueing variables */
3590 fprintf(fp, "AF:\n");
3591 fprintf(fp, "NF:0\n");
3592 fprintf(fp, "PS:10\n");
3593 fprintf(fp, "SRH:1\n");
3594 fprintf(fp, "SFN:\n");
3595 fprintf(fp, "DSR:\n");
3597 fprintf(fp, "MID:<%s>\n", compose->msgid);
3599 fprintf(fp, "MID:\n");
3600 fprintf(fp, "CFG:\n");
3601 fprintf(fp, "PT:0\n");
3602 fprintf(fp, "S:%s\n", compose->account->address);
3603 fprintf(fp, "RQ:\n");
3605 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3607 fprintf(fp, "SSV:\n");
3609 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3611 fprintf(fp, "NSV:\n");
3612 fprintf(fp, "SSH:\n");
3613 /* write recepient list */
3614 if (compose->to_list) {
3615 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
3616 for (cur = compose->to_list->next; cur != NULL;
3618 fprintf(fp, ",<%s>", (gchar *)cur->data);
3621 /* write newsgroup list */
3622 if (compose->newsgroup_list) {
3624 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3625 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3626 fprintf(fp, ",%s", (gchar *)cur->data);
3629 /* Sylpheed account IDs */
3631 fprintf(fp, "MAID:%d\n", mailac->account_id);
3634 fprintf(fp, "NAID:%d\n", newsac->account_id);
3636 /* Save copy folder */
3637 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3638 gchar *savefolderid;
3640 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3641 fprintf(fp, "SCF:%s\n", savefolderid);
3642 g_free(savefolderid);
3644 /* Message-ID of message replying to */
3645 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
3648 folderid = folder_item_get_identifier(compose->replyinfo->folder);
3649 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
3652 /* Message-ID of message forwarding to */
3653 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
3656 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
3657 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
3662 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3663 if (fputs(buf, fp) == EOF) {
3664 FILE_OP_ERROR(tmp, "fputs");
3675 if (fclose(fp) == EOF) {
3676 FILE_OP_ERROR(tmp, "fclose");
3684 queue = account_get_special_folder(compose->account, F_QUEUE);
3686 g_warning("can't find queue folder\n");
3691 folder_item_scan(queue);
3692 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3693 g_warning("can't queue the message\n");
3703 if (compose->mode == COMPOSE_REEDIT) {
3704 compose_remove_reedit_target(compose);
3707 if ((msgnum != NULL) && (item != NULL)) {
3715 static void compose_write_attach(Compose *compose, FILE *fp)
3718 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3721 gchar filename[BUFFSIZE];
3724 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3726 gchar buf[BUFFSIZE];
3727 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3729 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
3730 g_warning("Can't open file %s\n", ainfo->file);
3734 fprintf(fp, "\n--%s\n", compose->boundary);
3736 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3737 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3738 fprintf(fp, "Content-Disposition: inline\n");
3740 compose_convert_header(filename, sizeof(filename),
3742 fprintf(fp, "Content-Type: %s;\n"
3744 ainfo->content_type, filename);
3745 fprintf(fp, "Content-Disposition: attachment;\n"
3746 " filename=\"%s\"\n", filename);
3749 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3750 procmime_get_encoding_str(ainfo->encoding));
3752 if (ainfo->encoding == ENC_BASE64) {
3753 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3755 while ((len = fread(inbuf, sizeof(gchar),
3756 B64_LINE_SIZE, attach_fp))
3758 base64_encode(outbuf, inbuf, B64_LINE_SIZE);
3762 if (len > 0 && feof(attach_fp)) {
3763 base64_encode(outbuf, inbuf, len);
3767 } else if (ainfo->encoding == ENC_QUOTED_PRINTABLE) {
3768 gchar inbuf[BUFFSIZE], outbuf[BUFFSIZE * 4];
3770 while (fgets(inbuf, sizeof(inbuf), attach_fp) != NULL) {
3771 qp_encode_line(outbuf, inbuf);
3775 gchar buf[BUFFSIZE];
3777 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3786 fprintf(fp, "\n--%s--\n", compose->boundary);
3789 #define QUOTE_IF_REQUIRED(out, str) \
3791 if (*str != '"' && (strchr(str, ',') \
3792 || strchr(str, '.'))) { \
3796 len = strlen(str) + 3; \
3797 Xalloca(__tmp, len, return -1); \
3798 g_snprintf(__tmp, len, "\"%s\"", str); \
3801 Xstrdup_a(out, str, return -1); \
3805 #define PUT_RECIPIENT_HEADER(header, str) \
3807 if (*str != '\0') { \
3808 Xstrdup_a(str, str, return -1); \
3810 if (*str != '\0') { \
3811 compose->to_list = address_list_append \
3812 (compose->to_list, str); \
3813 compose_convert_header \
3814 (buf, sizeof(buf), str, strlen(header) + 2); \
3815 fprintf(fp, "%s: %s\n", header, buf); \
3820 #define IS_IN_CUSTOM_HEADER(header) \
3821 (compose->account->add_customhdr && \
3822 custom_header_find(compose->account->customhdr_list, header) != NULL)
3824 static gint compose_write_headers_from_headerlist(Compose *compose,
3828 gchar buf[BUFFSIZE];
3829 gchar *str, *header_w_colon, *trans_hdr;
3830 gboolean first_address;
3832 ComposeHeaderEntry *headerentry;
3833 gchar * headerentryname;
3835 if (IS_IN_CUSTOM_HEADER(header)) {
3839 debug_print("Writing %s-header\n", header);
3841 header_w_colon = g_strconcat(header, ":", NULL);
3842 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3844 first_address = TRUE;
3845 for (list = compose->header_list; list; list = list->next) {
3846 headerentry = ((ComposeHeaderEntry *)list->data);
3847 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3849 if (!g_strcasecmp(trans_hdr, headerentryname)) {
3850 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3851 Xstrdup_a(str, str, return -1);
3853 if (str[0] != '\0') {
3854 compose_convert_header
3855 (buf, sizeof(buf), str,
3856 strlen(header) + 2);
3857 if (first_address) {
3858 fprintf(fp, "%s: ", header);
3859 first_address = FALSE;
3863 fprintf(fp, "%s", buf);
3867 if (!first_address) {
3871 g_free(header_w_colon);
3876 static gint compose_write_headers(Compose *compose, FILE *fp,
3877 const gchar *charset, EncodingType encoding,
3880 gchar buf[BUFFSIZE];
3884 gchar *std_headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3886 /* struct utsname utsbuf; */
3888 g_return_val_if_fail(fp != NULL, -1);
3889 g_return_val_if_fail(charset != NULL, -1);
3890 g_return_val_if_fail(compose->account != NULL, -1);
3891 g_return_val_if_fail(compose->account->address != NULL, -1);
3893 /* Save draft infos */
3895 fprintf(fp, "X-Sylpheed-Account-Id:%d\n", compose->account->account_id);
3896 fprintf(fp, "S:%s\n", compose->account->address);
3897 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3898 gchar *savefolderid;
3900 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3901 fprintf(fp, "SCF:%s\n", savefolderid);
3902 g_free(savefolderid);
3908 if (compose->account->add_date) {
3909 get_rfc822_date(buf, sizeof(buf));
3910 fprintf(fp, "Date: %s\n", buf);
3914 if (!IS_IN_CUSTOM_HEADER("From")) {
3915 if (compose->account->name && *compose->account->name) {
3916 compose_convert_header
3917 (buf, sizeof(buf), compose->account->name,
3919 QUOTE_IF_REQUIRED(name, buf);
3920 fprintf(fp, "From: %s <%s>\n",
3921 name, compose->account->address);
3923 fprintf(fp, "From: %s\n", compose->account->address);
3927 compose_write_headers_from_headerlist(compose, fp, "To");
3928 #if 0 /* NEW COMPOSE GUI */
3929 if (compose->use_to) {
3930 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3931 PUT_RECIPIENT_HEADER("To", str);
3936 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3937 #if 0 /* NEW COMPOSE GUI */
3938 if (compose->use_newsgroups) {
3939 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3941 Xstrdup_a(str, str, return -1);
3945 compose->newsgroup_list =
3946 newsgroup_list_append
3947 (compose->newsgroup_list, str);
3948 compose_convert_header(buf, sizeof(buf), str,
3949 strlen("Newsgroups: "));
3950 fprintf(fp, "Newsgroups: %s\n", buf);
3956 compose_write_headers_from_headerlist(compose, fp, "Cc");
3957 #if 0 /* NEW COMPOSE GUI */
3958 if (compose->use_cc) {
3959 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3960 PUT_RECIPIENT_HEADER("Cc", str);
3964 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3965 #if 0 /* NEW COMPOSE GUI */
3966 if (compose->use_bcc) {
3967 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3968 PUT_RECIPIENT_HEADER("Bcc", str);
3973 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3974 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3975 Xstrdup_a(str, str, return -1);
3978 compose_convert_header(buf, sizeof(buf), str,
3979 strlen("Subject: "));
3980 fprintf(fp, "Subject: %s\n", buf);
3985 if (compose->account->gen_msgid) {
3986 compose_generate_msgid(compose, buf, sizeof(buf));
3987 fprintf(fp, "Message-Id: <%s>\n", buf);
3988 compose->msgid = g_strdup(buf);
3992 if (compose->inreplyto && compose->to_list)
3993 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3996 if (compose->references)
3997 fprintf(fp, "References: %s\n", compose->references);
4000 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
4001 #if 0 /* NEW COMPOSE GUI */
4002 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
4003 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
4005 Xstrdup_a(str, str, return -1);
4009 compose_convert_header(buf, sizeof(buf), str,
4010 strlen("Followup-To: "));
4011 fprintf(fp, "Followup-To: %s\n", buf);
4017 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
4018 #if 0 /* NEW COMPOSE GUI */
4019 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
4020 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
4022 Xstrdup_a(str, str, return -1);
4025 compose_convert_header(buf, sizeof(buf), str,
4026 strlen("Reply-To: "));
4027 fprintf(fp, "Reply-To: %s\n", buf);
4033 if (compose->account->organization &&
4034 !IS_IN_CUSTOM_HEADER("Organization")) {
4035 compose_convert_header(buf, sizeof(buf),
4036 compose->account->organization,
4037 strlen("Organization: "));
4038 fprintf(fp, "Organization: %s\n", buf);
4041 /* Program version and system info */
4042 /* uname(&utsbuf); */
4043 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
4044 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
4046 gtk_major_version, gtk_minor_version, gtk_micro_version,
4048 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4050 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
4051 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
4053 gtk_major_version, gtk_minor_version, gtk_micro_version,
4055 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
4058 /* custom headers */
4059 if (compose->account->add_customhdr) {
4062 for (cur = compose->account->customhdr_list; cur != NULL;
4064 CustomHeader *chdr = (CustomHeader *)cur->data;
4066 if (strcasecmp(chdr->name, "Date") != 0 &&
4067 strcasecmp(chdr->name, "From") != 0 &&
4068 strcasecmp(chdr->name, "To") != 0 &&
4069 /* strcasecmp(chdr->name, "Sender") != 0 && */
4070 strcasecmp(chdr->name, "Message-Id") != 0 &&
4071 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
4072 strcasecmp(chdr->name, "References") != 0 &&
4073 strcasecmp(chdr->name, "Mime-Version") != 0 &&
4074 strcasecmp(chdr->name, "Content-Type") != 0 &&
4075 strcasecmp(chdr->name, "Content-Transfer-Encoding")
4077 compose_convert_header
4079 chdr->value ? chdr->value : "",
4080 strlen(chdr->name) + 2);
4081 fprintf(fp, "%s: %s\n", chdr->name, buf);
4087 fprintf(fp, "Mime-Version: 1.0\n");
4088 if (compose_use_attach(compose)) {
4089 get_rfc822_date(buf, sizeof(buf));
4090 subst_char(buf, ' ', '_');
4091 subst_char(buf, ',', '_');
4092 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
4093 buf, (guint)compose);
4095 "Content-Type: multipart/mixed;\n"
4096 " boundary=\"%s\"\n", compose->boundary);
4098 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
4099 fprintf(fp, "Content-Transfer-Encoding: %s\n",
4100 procmime_get_encoding_str(encoding));
4104 switch (compose->priority) {
4105 case PRIORITY_HIGHEST: fprintf(fp, "Importance: high\n"
4106 "X-Priority: 1 (Highest)\n");
4108 case PRIORITY_HIGH: fprintf(fp, "Importance: high\n"
4109 "X-Priority: 2 (High)\n");
4111 case PRIORITY_NORMAL: break;
4112 case PRIORITY_LOW: fprintf(fp, "Importance: low\n"
4113 "X-Priority: 4 (Low)\n");
4115 case PRIORITY_LOWEST: fprintf(fp, "Importance: low\n"
4116 "X-Priority: 5 (Lowest)\n");
4118 default: debug_print("compose: priority unknown : %d\n",
4122 /* Request Return Receipt */
4123 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
4124 if (compose->return_receipt) {
4125 if (compose->account->name
4126 && *compose->account->name) {
4127 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
4128 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
4130 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
4134 /* get special headers */
4135 for (list = compose->header_list; list; list = list->next) {
4136 ComposeHeaderEntry *headerentry;
4139 gchar *headername_wcolon;
4140 gchar *headername_trans;
4143 gboolean standard_header = FALSE;
4145 headerentry = ((ComposeHeaderEntry *)list->data);
4147 tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
4148 if (!strstr(tmp, ":")) {
4149 headername_wcolon = g_strconcat(tmp, ":", NULL);
4150 headername = g_strdup(tmp);
4152 headername_wcolon = g_strdup(tmp);
4153 headername = g_strdup(strtok(tmp, ":"));
4157 headervalue = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
4158 string = std_headers;
4159 while (*string != NULL) {
4160 headername_trans = prefs_common.trans_hdr ? gettext(*string) : *string;
4161 if (!strcmp(headername_trans,headername_wcolon))
4162 standard_header = TRUE;
4165 if (!standard_header && !IS_IN_CUSTOM_HEADER(headername))
4166 fprintf(fp, "%s %s\n", headername_wcolon, headervalue);
4169 g_free(headername_wcolon);
4173 /* separator between header and body */
4179 #undef IS_IN_CUSTOM_HEADER
4181 static void compose_convert_header(gchar *dest, gint len, gchar *src,
4184 g_return_if_fail(src != NULL);
4185 g_return_if_fail(dest != NULL);
4187 if (len < 1) return;
4191 conv_encode_header(dest, len, src, header_len);
4194 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
4203 if (compose->account && compose->account->address &&
4204 *compose->account->address) {
4205 if (strchr(compose->account->address, '@'))
4206 addr = g_strdup(compose->account->address);
4208 addr = g_strconcat(compose->account->address, "@",
4209 get_domain_name(), NULL);
4211 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
4214 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
4215 lt->tm_year + 1900, lt->tm_mon + 1,
4216 lt->tm_mday, lt->tm_hour,
4217 lt->tm_min, lt->tm_sec,
4218 (guint)random(), addr);
4220 debug_print("generated Message-ID: %s\n", buf);
4225 static void compose_create_header_entry(Compose *compose)
4227 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
4231 GList *combo_list = NULL;
4232 gchar **string, *header = NULL;
4233 ComposeHeaderEntry *headerentry;
4234 gboolean standard_header = FALSE;
4236 headerentry = g_new0(ComposeHeaderEntry, 1);
4239 combo = gtk_combo_new();
4241 while(*string != NULL) {
4242 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
4245 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
4246 g_list_free(combo_list);
4247 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
4248 gtk_widget_show(combo);
4249 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
4250 if (compose->header_last) {
4251 gchar *last_header_entry = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4253 while (*string != NULL) {
4254 if (!strcmp(*string, last_header_entry))
4255 standard_header = TRUE;
4258 if (standard_header)
4259 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
4261 if (!compose->header_last || !standard_header) {
4262 switch(compose->account->protocol) {
4264 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
4267 header = prefs_common.trans_hdr ? _("To:") : "To:";
4272 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
4275 entry = gtk_entry_new();
4276 gtk_widget_show(entry);
4277 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);
4279 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
4280 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
4281 gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4283 address_completion_register_entry(GTK_ENTRY(entry));
4285 headerentry->compose = compose;
4286 headerentry->combo = combo;
4287 headerentry->entry = entry;
4288 headerentry->headernum = compose->header_nextrow;
4290 compose->header_nextrow++;
4291 compose->header_last = headerentry;
4294 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
4296 ComposeHeaderEntry *last_header;
4298 last_header = compose->header_last;
4300 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
4301 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
4304 static GtkWidget *compose_create_header(Compose *compose)
4308 GtkWidget *from_optmenu_hbox;
4309 #if 0 /* NEW COMPOSE GUI */
4310 GtkWidget *to_entry;
4312 GtkWidget *newsgroups_entry;
4313 GtkWidget *newsgroups_hbox;
4315 GtkWidget *header_scrolledwin;
4316 GtkWidget *header_table;
4317 #if 0 /* NEW COMPOSE GUI */
4318 GtkWidget *cc_entry;
4320 GtkWidget *bcc_entry;
4321 GtkWidget *bcc_hbox;
4322 GtkWidget *reply_entry;
4323 GtkWidget *reply_hbox;
4324 GtkWidget *followup_entry;
4325 GtkWidget *followup_hbox;
4330 /* header labels and entries */
4331 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4332 gtk_widget_show(header_scrolledwin);
4333 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
4335 header_table = gtk_table_new(2, 2, FALSE);
4336 gtk_widget_show(header_table);
4337 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4338 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4339 gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
4342 /* option menu for selecting accounts */
4343 hbox = gtk_hbox_new(FALSE, 0);
4344 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4345 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4346 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4348 from_optmenu_hbox = compose_account_option_menu_create(compose);
4349 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4350 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4351 #if 0 /* NEW COMPOSE GUI */
4352 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4356 compose->header_table = header_table;
4357 compose->header_list = NULL;
4358 compose->header_nextrow = count;
4360 compose_create_header_entry(compose);
4362 #if 0 /* NEW COMPOSE GUI */
4363 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4365 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4366 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4367 &count, "Newsgroups:", FALSE);
4368 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4370 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4372 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4374 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4375 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4377 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4378 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4380 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4381 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4382 "Followup-To:", FALSE);
4383 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4385 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4387 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4388 GTK_SIGNAL_FUNC(to_activated), compose);
4389 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4390 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4391 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4392 GTK_SIGNAL_FUNC(subject_activated), compose);
4393 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4394 GTK_SIGNAL_FUNC(cc_activated), compose);
4395 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4396 GTK_SIGNAL_FUNC(bcc_activated), compose);
4397 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4398 GTK_SIGNAL_FUNC(replyto_activated), compose);
4399 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4400 GTK_SIGNAL_FUNC(followupto_activated), compose);
4402 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4403 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4404 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4405 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4406 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4407 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4408 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4409 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4410 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4411 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4412 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4413 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4414 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4415 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4418 compose->table = NULL;
4419 #if 0 /* NEW COMPOSE GUI */
4420 compose->table = table;
4421 compose->to_hbox = to_hbox;
4422 compose->to_entry = to_entry;
4423 compose->newsgroups_hbox = newsgroups_hbox;
4424 compose->newsgroups_entry = newsgroups_entry;
4426 #if 0 /* NEW COMPOSE GUI */
4427 compose->cc_hbox = cc_hbox;
4428 compose->cc_entry = cc_entry;
4429 compose->bcc_hbox = bcc_hbox;
4430 compose->bcc_entry = bcc_entry;
4431 compose->reply_hbox = reply_hbox;
4432 compose->reply_entry = reply_entry;
4433 compose->followup_hbox = followup_hbox;
4434 compose->followup_entry = followup_entry;
4437 return header_scrolledwin ;
4440 GtkWidget *compose_create_attach(Compose *compose)
4442 gchar *titles[N_ATTACH_COLS];
4445 GtkWidget *attach_scrwin;
4446 GtkWidget *attach_clist;
4448 titles[COL_MIMETYPE] = _("MIME type");
4449 titles[COL_SIZE] = _("Size");
4450 titles[COL_NAME] = _("Name");
4452 /* attachment list */
4453 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4454 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4455 GTK_POLICY_AUTOMATIC,
4457 gtk_widget_set_usize(attach_scrwin, -1, 80);
4459 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4460 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4462 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4463 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4464 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4465 GTK_SELECTION_EXTENDED);
4466 for (i = 0; i < N_ATTACH_COLS; i++)
4467 GTK_WIDGET_UNSET_FLAGS
4468 (GTK_CLIST(attach_clist)->column[i].button,
4470 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4472 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4473 GTK_SIGNAL_FUNC(attach_selected), compose);
4474 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4475 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4476 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4477 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4480 gtk_drag_dest_set(attach_clist,
4481 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4482 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4483 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4484 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4487 compose->attach_scrwin = attach_scrwin;
4488 compose->attach_clist = attach_clist;
4490 return attach_scrwin;
4493 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
4494 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
4496 static GtkWidget *compose_create_others(Compose *compose)
4499 GtkWidget *savemsg_checkbtn;
4500 GtkWidget *savemsg_entry;
4501 GtkWidget *savemsg_select;
4504 gchar *folderidentifier;
4506 /* Table for settings */
4507 table = gtk_table_new(3, 1, FALSE);
4508 gtk_widget_show(table);
4509 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4512 /* Save Message to folder */
4513 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4514 gtk_widget_show(savemsg_checkbtn);
4515 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4516 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4517 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4519 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4520 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4522 savemsg_entry = gtk_entry_new();
4523 gtk_widget_show(savemsg_entry);
4524 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4525 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4526 if (account_get_special_folder(compose->account, F_OUTBOX)) {
4527 folderidentifier = folder_item_get_identifier(account_get_special_folder
4528 (compose->account, F_OUTBOX));
4529 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4530 g_free(folderidentifier);
4533 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4534 gtk_widget_show (savemsg_select);
4535 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4536 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4537 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4542 compose->savemsg_checkbtn = savemsg_checkbtn;
4543 compose->savemsg_entry = savemsg_entry;
4548 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4550 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4551 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4554 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4559 dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
4562 path = folder_item_get_identifier(dest);
4564 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4568 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4574 GtkWidget *handlebox;
4576 GtkWidget *notebook;
4581 GtkWidget *subject_hbox;
4582 GtkWidget *subject_frame;
4583 GtkWidget *subject_entry;
4587 GtkWidget *edit_vbox;
4588 GtkWidget *ruler_hbox;
4590 GtkWidget *scrolledwin;
4593 UndoMain *undostruct;
4595 gchar *titles[N_ATTACH_COLS];
4596 guint n_menu_entries;
4597 GtkStyle *style, *new_style;
4600 gboolean success[1];
4601 GtkWidget *popupmenu;
4602 GtkItemFactory *popupfactory;
4603 GtkItemFactory *ifactory;
4604 GtkWidget *tmpl_menu;
4608 GtkAspell * gtkaspell = NULL;
4611 static GdkGeometry geometry;
4613 g_return_val_if_fail(account != NULL, NULL);
4615 debug_print("Creating compose window...\n");
4616 compose = g_new0(Compose, 1);
4618 titles[COL_MIMETYPE] = _("MIME type");
4619 titles[COL_SIZE] = _("Size");
4620 titles[COL_NAME] = _("Name");
4622 compose->account = account;
4624 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4625 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4626 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4627 gtk_window_set_wmclass(GTK_WINDOW(window), "compose window", "Sylpheed");
4629 if (!geometry.max_width) {
4630 geometry.max_width = gdk_screen_width();
4631 geometry.max_height = gdk_screen_height();
4633 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL,
4634 &geometry, GDK_HINT_MAX_SIZE);
4636 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4637 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4638 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4639 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4640 MANAGE_WINDOW_SIGNALS_CONNECT(window);
4641 gtk_widget_realize(window);
4643 gtkut_widget_set_composer_icon(window);
4645 vbox = gtk_vbox_new(FALSE, 0);
4646 gtk_container_add(GTK_CONTAINER(window), vbox);
4648 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4649 menubar = menubar_create(window, compose_entries,
4650 n_menu_entries, "<Compose>", compose);
4651 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4653 handlebox = gtk_handle_box_new();
4654 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4656 compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
4659 vbox2 = gtk_vbox_new(FALSE, 2);
4660 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4661 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4664 notebook = gtk_notebook_new();
4665 gtk_widget_set_usize(notebook, -1, 130);
4666 gtk_widget_show(notebook);
4668 /* header labels and entries */
4669 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4670 /* attachment list */
4671 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4673 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4676 subject_hbox = gtk_hbox_new(FALSE, 0);
4677 gtk_widget_show(subject_hbox);
4679 subject_frame = gtk_frame_new(NULL);
4680 gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
4681 gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
4682 gtk_widget_show(subject_frame);
4684 subject = gtk_hbox_new(FALSE, 0);
4685 gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
4686 gtk_widget_show(subject);
4688 label = gtk_label_new(_("Subject:"));
4689 gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
4690 gtk_widget_show(label);
4692 subject_entry = gtk_entry_new();
4693 gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
4694 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(text_activated), compose);
4695 gtk_widget_show(subject_entry);
4696 compose->subject_entry = subject_entry;
4697 gtk_container_add(GTK_CONTAINER(subject_frame), subject);
4699 edit_vbox = gtk_vbox_new(FALSE, 0);
4700 #if 0 /* NEW COMPOSE GUI */
4701 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4704 gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
4707 ruler_hbox = gtk_hbox_new(FALSE, 0);
4708 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4710 ruler = gtk_shruler_new();
4711 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4712 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4714 gtk_widget_set_usize(ruler_hbox, 1, -1);
4717 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4718 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4719 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4720 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4721 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4723 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4724 (GTK_SCROLLED_WINDOW(scrolledwin)),
4725 gtk_scrolled_window_get_vadjustment
4726 (GTK_SCROLLED_WINDOW(scrolledwin)));
4727 GTK_STEXT(text)->default_tab_width = 8;
4728 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4730 if (prefs_common.block_cursor) {
4731 GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
4734 if (prefs_common.smart_wrapping) {
4735 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4736 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4739 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4741 gtk_signal_connect(GTK_OBJECT(text), "changed",
4742 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4743 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4744 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4745 gtk_signal_connect(GTK_OBJECT(text), "activate",
4746 GTK_SIGNAL_FUNC(text_activated), compose);
4747 gtk_signal_connect(GTK_OBJECT(text), "insert_text",
4748 GTK_SIGNAL_FUNC(text_inserted), compose);
4749 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4750 GTK_SIGNAL_FUNC(compose_button_press_cb),
4753 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4754 GTK_SIGNAL_FUNC(compose_key_press_cb),
4757 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4758 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4762 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4763 GDK_ACTION_COPY | GDK_ACTION_MOVE);
4764 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4765 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4767 gtk_widget_show_all(vbox);
4769 /* pane between attach clist and text */
4770 paned = gtk_vpaned_new();
4771 gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
4772 gtk_paned_set_handle_size(GTK_PANED(paned), 12);
4773 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4774 gtk_paned_add1(GTK_PANED(paned), notebook);
4775 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4776 gtk_widget_show_all(paned);
4778 style = gtk_widget_get_style(text);
4780 /* workaround for the slow down of GtkSText when using Pixmap theme */
4781 if (style->engine) {
4782 GtkThemeEngine *engine;
4784 engine = style->engine;
4785 style->engine = NULL;
4786 new_style = gtk_style_copy(style);
4787 style->engine = engine;
4789 new_style = gtk_style_copy(style);
4791 if (prefs_common.textfont) {
4794 if ((font = gtkut_font_load(prefs_common.textfont)) != NULL) {
4795 gdk_font_unref(new_style->font);
4796 new_style->font = font;
4800 gtk_widget_set_style(text, new_style);
4802 color[0] = quote_color;
4803 cmap = gdk_window_get_colormap(window->window);
4804 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4805 if (success[0] == FALSE) {
4806 g_warning("Compose: color allocation failed.\n");
4807 style = gtk_widget_get_style(text);
4808 quote_color = style->black;
4811 n_entries = sizeof(compose_popup_entries) /
4812 sizeof(compose_popup_entries[0]);
4813 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4814 "<Compose>", &popupfactory,
4817 ifactory = gtk_item_factory_from_widget(menubar);
4818 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4819 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4821 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4822 #if 0 /* NEW COMPOSE GUI */
4823 gtk_widget_hide(bcc_hbox);
4824 gtk_widget_hide(bcc_entry);
4825 gtk_widget_hide(reply_hbox);
4826 gtk_widget_hide(reply_entry);
4827 gtk_widget_hide(followup_hbox);
4828 gtk_widget_hide(followup_entry);
4829 gtk_widget_hide(ruler_hbox);
4830 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4831 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4832 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4834 if (account->protocol == A_NNTP) {
4835 gtk_widget_hide(to_hbox);
4836 gtk_widget_hide(to_entry);
4837 gtk_widget_hide(cc_hbox);
4838 gtk_widget_hide(cc_entry);
4839 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4840 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4842 gtk_widget_hide(newsgroups_hbox);
4843 gtk_widget_hide(newsgroups_entry);
4844 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4848 update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
4851 undostruct = undo_init(text);
4852 undo_set_change_state_func(undostruct, &compose_undo_state_changed,
4855 address_completion_start(window);
4857 compose->window = window;
4858 compose->vbox = vbox;
4859 compose->menubar = menubar;
4860 compose->handlebox = handlebox;
4862 compose->vbox2 = vbox2;
4864 compose->paned = paned;
4866 compose->edit_vbox = edit_vbox;
4867 compose->ruler_hbox = ruler_hbox;
4868 compose->ruler = ruler;
4869 compose->scrolledwin = scrolledwin;
4870 compose->text = text;
4872 compose->focused_editable = NULL;
4874 compose->popupmenu = popupmenu;
4875 compose->popupfactory = popupfactory;
4877 compose->tmpl_menu = tmpl_menu;
4879 compose->mode = mode;
4881 compose->targetinfo = NULL;
4882 compose->replyinfo = NULL;
4883 compose->fwdinfo = NULL;
4885 compose->replyto = NULL;
4887 compose->bcc = NULL;
4888 compose->followup_to = NULL;
4890 compose->ml_post = NULL;
4892 compose->inreplyto = NULL;
4893 compose->references = NULL;
4894 compose->msgid = NULL;
4895 compose->boundary = NULL;
4898 compose->use_signing = FALSE;
4899 compose->use_encryption = FALSE;
4900 #endif /* USE_GPGME */
4902 compose->modified = FALSE;
4904 compose->return_receipt = FALSE;
4905 compose->paste_as_quotation = FALSE;
4907 compose->to_list = NULL;
4908 compose->newsgroup_list = NULL;
4910 compose->exteditor_file = NULL;
4911 compose->exteditor_pid = -1;
4912 compose->exteditor_readdes = -1;
4913 compose->exteditor_tag = -1;
4915 compose->redirect_filename = NULL;
4916 compose->undostruct = undostruct;
4918 menu_set_sensitive(ifactory, "/Spelling", FALSE);
4919 if (mode != COMPOSE_REDIRECT) {
4920 if (prefs_common.enable_aspell && prefs_common.dictionary &&
4921 strcmp(prefs_common.dictionary, _("None"))) {
4922 gtkaspell = gtkaspell_new((const gchar*)prefs_common.dictionary,
4923 conv_get_current_charset_str(),
4924 prefs_common.misspelled_col,
4925 prefs_common.check_while_typing,
4926 prefs_common.use_alternate,
4929 alertpanel_error(_("Spell checker could not be started.\n%s"), gtkaspellcheckers->error_message);
4930 gtkaspell_checkers_reset_error();
4933 GtkWidget *menuitem;
4935 if (!gtkaspell_set_sug_mode(gtkaspell, prefs_common.aspell_sugmode)) {
4936 debug_print("Aspell: could not set suggestion mode %s\n",
4937 gtkaspellcheckers->error_message);
4938 gtkaspell_checkers_reset_error();
4941 menuitem = gtk_item_factory_get_item(ifactory, "/Spelling/Spelling Configuration");
4942 gtkaspell_populate_submenu(gtkaspell, menuitem);
4943 menu_set_sensitive(ifactory, "/Spelling", TRUE);
4949 compose_select_account(compose, account);
4952 compose->gtkaspell = gtkaspell;
4955 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT)
4956 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4958 if (account->set_autobcc)
4959 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4961 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT)
4962 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4965 if (account->protocol != A_NNTP)
4966 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("To:") : "To:");
4968 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
4970 addressbook_set_target_compose(compose);
4971 update_compose_actions_menu(ifactory, "/Tools/Actions", compose);
4973 if (mode != COMPOSE_REDIRECT)
4974 compose_set_template_menu(compose);
4976 GtkWidget *menuitem;
4977 menuitem = gtk_item_factory_get_item(ifactory, "/Tools/Template");
4978 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
4981 compose_list = g_list_append(compose_list, compose);
4983 if (!prefs_common.show_ruler)
4984 gtk_widget_hide(ruler_hbox);
4987 compose->priority = PRIORITY_NORMAL;
4988 compose_update_priority_menu_item(compose);
4991 activate_gnupg_mode(compose, account);
4993 toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
4994 gtk_widget_show(window);
4999 static GtkWidget *compose_account_option_menu_create(Compose *compose)
5005 gint num = 0, def_menu = 0;
5007 accounts = account_get_list();
5008 g_return_val_if_fail(accounts != NULL, NULL);
5010 hbox = gtk_hbox_new(FALSE, 0);
5011 optmenu = gtk_option_menu_new();
5012 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5013 menu = gtk_menu_new();
5015 for (; accounts != NULL; accounts = accounts->next, num++) {
5016 PrefsAccount *ac = (PrefsAccount *)accounts->data;
5017 GtkWidget *menuitem;
5020 if (ac == compose->account) def_menu = num;
5023 name = g_strdup_printf("%s: %s <%s>",
5025 ac->name, ac->address);
5027 name = g_strdup_printf("%s: %s",
5028 ac->account_name, ac->address);
5029 MENUITEM_ADD(menu, menuitem, name, ac->account_id);
5031 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
5032 GTK_SIGNAL_FUNC(account_activated),
5036 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
5037 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
5042 static void compose_set_priority_cb(gpointer data,
5046 Compose *compose = (Compose *) data;
5047 compose->priority = action;
5050 static void compose_update_priority_menu_item(Compose * compose)
5052 GtkItemFactory *ifactory;
5053 GtkWidget *menuitem = NULL;
5055 ifactory = gtk_item_factory_from_widget(compose->menubar);
5057 switch (compose->priority) {
5058 case PRIORITY_HIGHEST:
5059 menuitem = gtk_item_factory_get_item
5060 (ifactory, "/Message/Priority/Highest");
5063 menuitem = gtk_item_factory_get_item
5064 (ifactory, "/Message/Priority/High");
5066 case PRIORITY_NORMAL:
5067 menuitem = gtk_item_factory_get_item
5068 (ifactory, "/Message/Priority/Normal");
5071 menuitem = gtk_item_factory_get_item
5072 (ifactory, "/Message/Priority/Low");
5074 case PRIORITY_LOWEST:
5075 menuitem = gtk_item_factory_get_item
5076 (ifactory, "/Message/Priority/Lowest");
5079 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5083 static void compose_set_gnupg_mode_cb(gpointer data,
5087 Compose *compose = (Compose *) data;
5088 compose->gnupg_mode = action;
5091 static void compose_update_gnupg_mode_menu_item(Compose * compose)
5093 GtkItemFactory *ifactory;
5094 GtkWidget *menuitem = NULL;
5096 ifactory = gtk_item_factory_from_widget(compose->menubar);
5098 switch (compose->gnupg_mode) {
5099 case GNUPG_MODE_DETACH:
5100 menuitem = gtk_item_factory_get_item
5101 (ifactory, "/Message/Mode/MIME");
5103 case GNUPG_MODE_INLINE:
5104 menuitem = gtk_item_factory_get_item
5105 (ifactory, "/Message/Mode/Inline");
5108 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5110 if (compose->use_encryption == TRUE || compose->use_signing == TRUE)
5111 menu_set_sensitive(ifactory, "/Message/Mode", TRUE);
5113 menu_set_sensitive(ifactory, "/Message/Mode", FALSE);
5117 static void compose_set_template_menu(Compose *compose)
5119 GSList *tmpl_list, *cur;
5123 tmpl_list = template_get_config();
5125 menu = gtk_menu_new();
5127 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
5128 Template *tmpl = (Template *)cur->data;
5130 item = gtk_menu_item_new_with_label(tmpl->name);
5131 gtk_menu_append(GTK_MENU(menu), item);
5132 gtk_signal_connect(GTK_OBJECT(item), "activate",
5133 GTK_SIGNAL_FUNC(compose_template_activate_cb),
5135 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
5136 gtk_widget_show(item);
5139 gtk_widget_show(menu);
5140 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
5143 void compose_reflect_prefs_all(void)
5148 for (cur = compose_list; cur != NULL; cur = cur->next) {
5149 compose = (Compose *)cur->data;
5150 compose_set_template_menu(compose);
5154 void compose_reflect_prefs_pixmap_theme(void)
5159 for (cur = compose_list; cur != NULL; cur = cur->next) {
5160 compose = (Compose *)cur->data;
5161 toolbar_update(TOOLBAR_COMPOSE, compose);
5165 static void compose_template_apply(Compose *compose, Template *tmpl,
5171 if (!tmpl || !tmpl->value) return;
5173 gtk_stext_freeze(GTK_STEXT(compose->text));
5175 if (tmpl->subject && *tmpl->subject != '\0')
5176 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
5178 if (tmpl->to && *tmpl->to != '\0')
5179 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
5180 if (tmpl->cc && *tmpl->cc != '\0')
5181 compose_entry_append(compose, tmpl->cc, COMPOSE_CC);
5183 if (tmpl->bcc && *tmpl->bcc != '\0')
5184 compose_entry_append(compose, tmpl->bcc, COMPOSE_BCC);
5187 gtk_stext_clear(GTK_STEXT(compose->text));
5189 if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
5190 parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
5193 if (prefs_common.quotemark && *prefs_common.quotemark)
5194 qmark = prefs_common.quotemark;
5198 if (compose->replyinfo != NULL)
5199 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
5200 tmpl->value, qmark, NULL);
5201 else if (compose->fwdinfo != NULL)
5202 parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
5203 tmpl->value, qmark, NULL);
5208 if (replace && parsed_str && prefs_common.auto_sig)
5209 compose_insert_sig(compose);
5211 if (replace && parsed_str) {
5212 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
5213 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
5217 compose_changed_cb(NULL, compose);
5219 gtk_stext_thaw(GTK_STEXT(compose->text));
5222 static void compose_destroy(Compose *compose)
5225 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5228 /* NOTE: address_completion_end() does nothing with the window
5229 * however this may change. */
5230 address_completion_end(compose->window);
5232 slist_free_strings(compose->to_list);
5233 g_slist_free(compose->to_list);
5234 slist_free_strings(compose->newsgroup_list);
5235 g_slist_free(compose->newsgroup_list);
5236 slist_free_strings(compose->header_list);
5237 g_slist_free(compose->header_list);
5239 procmsg_msginfo_free(compose->targetinfo);
5240 procmsg_msginfo_free(compose->replyinfo);
5241 procmsg_msginfo_free(compose->fwdinfo);
5243 g_free(compose->replyto);
5244 g_free(compose->cc);
5245 g_free(compose->bcc);
5246 g_free(compose->newsgroups);
5247 g_free(compose->followup_to);
5249 g_free(compose->ml_post);
5251 g_free(compose->inreplyto);
5252 g_free(compose->references);
5253 g_free(compose->msgid);
5254 g_free(compose->boundary);
5256 if (compose->redirect_filename)
5257 g_free(compose->redirect_filename);
5259 g_free(compose->exteditor_file);
5261 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
5263 compose_attach_info_free(ainfo);
5265 if (addressbook_get_target_compose() == compose)
5266 addressbook_set_target_compose(NULL);
5269 if (compose->gtkaspell) {
5270 gtkaspell_delete(compose->gtkaspell);
5274 prefs_common.compose_width = compose->scrolledwin->allocation.width;
5275 prefs_common.compose_height = compose->window->allocation.height;
5277 gtk_widget_destroy(compose->paned);
5279 toolbar_destroy(compose->toolbar);
5280 g_free(compose->toolbar);
5283 compose_list = g_list_remove(compose_list, compose);
5286 static void compose_attach_info_free(AttachInfo *ainfo)
5288 g_free(ainfo->file);
5289 g_free(ainfo->content_type);
5290 g_free(ainfo->name);
5294 static void compose_attach_remove_selected(Compose *compose)
5296 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5300 while (clist->selection != NULL) {
5301 row = GPOINTER_TO_INT(clist->selection->data);
5302 ainfo = gtk_clist_get_row_data(clist, row);
5303 compose_attach_info_free(ainfo);
5304 gtk_clist_remove(clist, row);
5308 static struct _AttachProperty
5311 GtkWidget *mimetype_entry;
5312 GtkWidget *encoding_optmenu;
5313 GtkWidget *path_entry;
5314 GtkWidget *filename_entry;
5316 GtkWidget *cancel_btn;
5319 static void compose_attach_property(Compose *compose)
5321 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5324 GtkOptionMenu *optmenu;
5325 static gboolean cancelled;
5327 if (!clist->selection) return;
5328 row = GPOINTER_TO_INT(clist->selection->data);
5330 ainfo = gtk_clist_get_row_data(clist, row);
5333 if (!attach_prop.window)
5334 compose_attach_property_create(&cancelled);
5335 gtk_widget_grab_focus(attach_prop.ok_btn);
5336 gtk_widget_show(attach_prop.window);
5337 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
5339 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
5340 if (ainfo->encoding == ENC_UNKNOWN)
5341 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5342 GINT_TO_POINTER(ENC_BASE64));
5344 menu_select_by_data(GTK_MENU(gtk_option_menu_get_menu(optmenu)),
5345 GINT_TO_POINTER(ainfo->encoding));
5347 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
5348 ainfo->content_type ? ainfo->content_type : "");
5349 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
5350 ainfo->file ? ainfo->file : "");
5351 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
5352 ainfo->name ? ainfo->name : "");
5356 gchar *cnttype = NULL;
5360 GtkWidget *menuitem;
5365 if (cancelled == TRUE) {
5366 gtk_widget_hide(attach_prop.window);
5370 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
5371 if (*text != '\0') {
5374 text = g_strstrip(g_strdup(text));
5375 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
5376 cnttype = g_strdup(text);
5379 alertpanel_error(_("Invalid MIME type."));
5385 menu = gtk_option_menu_get_menu(optmenu);
5386 menuitem = gtk_menu_get_active(GTK_MENU(menu));
5387 ainfo->encoding = GPOINTER_TO_INT
5388 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
5390 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
5391 if (*text != '\0') {
5392 if (is_file_exist(text) &&
5393 (size = get_file_size(text)) > 0)
5394 file = g_strdup(text);
5397 (_("File doesn't exist or is empty."));
5403 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
5404 if (*text != '\0') {
5405 g_free(ainfo->name);
5406 ainfo->name = g_strdup(text);
5410 g_free(ainfo->content_type);
5411 ainfo->content_type = cnttype;
5414 g_free(ainfo->file);
5420 gtk_clist_set_text(clist, row, COL_MIMETYPE,
5421 ainfo->content_type);
5422 gtk_clist_set_text(clist, row, COL_SIZE,
5423 to_human_readable(ainfo->size));
5424 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
5426 gtk_widget_hide(attach_prop.window);
5431 #define SET_LABEL_AND_ENTRY(str, entry, top) \
5433 label = gtk_label_new(str); \
5434 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
5435 GTK_FILL, 0, 0, 0); \
5436 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
5438 entry = gtk_entry_new(); \
5439 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
5440 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
5443 static void compose_attach_property_create(gboolean *cancelled)
5449 GtkWidget *mimetype_entry;
5452 GtkWidget *optmenu_menu;
5453 GtkWidget *menuitem;
5454 GtkWidget *path_entry;
5455 GtkWidget *filename_entry;
5458 GtkWidget *cancel_btn;
5459 GList *mime_type_list, *strlist;
5461 debug_print("Creating attach_property window...\n");
5463 window = gtk_window_new(GTK_WINDOW_DIALOG);
5464 gtk_widget_set_usize(window, 480, -1);
5465 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
5466 gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
5467 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
5468 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
5469 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
5470 GTK_SIGNAL_FUNC(attach_property_delete_event),
5472 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
5473 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5476 vbox = gtk_vbox_new(FALSE, 8);
5477 gtk_container_add(GTK_CONTAINER(window), vbox);
5479 table = gtk_table_new(4, 2, FALSE);
5480 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5481 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5482 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5484 label = gtk_label_new(_("MIME type"));
5485 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5487 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5488 mimetype_entry = gtk_combo_new();
5489 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5490 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5492 /* stuff with list */
5493 mime_type_list = procmime_get_mime_type_list();
5495 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5496 MimeType *type = (MimeType *) mime_type_list->data;
5497 strlist = g_list_append(strlist,
5498 g_strdup_printf("%s/%s",
5499 type->type, type->sub_type));
5502 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5504 for (mime_type_list = strlist; mime_type_list != NULL;
5505 mime_type_list = mime_type_list->next)
5506 g_free(mime_type_list->data);
5507 g_list_free(strlist);
5509 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5511 label = gtk_label_new(_("Encoding"));
5512 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5514 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5516 hbox = gtk_hbox_new(FALSE, 0);
5517 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5518 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5520 optmenu = gtk_option_menu_new();
5521 gtk_box_pack_start(GTK_BOX(hbox), optmenu, TRUE, TRUE, 0);
5523 optmenu_menu = gtk_menu_new();
5524 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5525 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5527 gtk_widget_set_sensitive(menuitem, FALSE);
5529 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5530 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5532 gtk_widget_set_sensitive(menuitem, FALSE);
5534 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable",
5535 ENC_QUOTED_PRINTABLE);
5536 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5538 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5540 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5542 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5543 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5545 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5546 &cancel_btn, _("Cancel"), NULL, NULL);
5547 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5548 gtk_widget_grab_default(ok_btn);
5550 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5551 GTK_SIGNAL_FUNC(attach_property_ok),
5553 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5554 GTK_SIGNAL_FUNC(attach_property_cancel),
5557 gtk_widget_show_all(vbox);
5559 attach_prop.window = window;
5560 attach_prop.mimetype_entry = mimetype_entry;
5561 attach_prop.encoding_optmenu = optmenu;
5562 attach_prop.path_entry = path_entry;
5563 attach_prop.filename_entry = filename_entry;
5564 attach_prop.ok_btn = ok_btn;
5565 attach_prop.cancel_btn = cancel_btn;
5568 #undef SET_LABEL_AND_ENTRY
5570 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5576 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5582 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5583 gboolean *cancelled)
5591 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5592 gboolean *cancelled)
5594 if (event && event->keyval == GDK_Escape) {
5600 static void compose_exec_ext_editor(Compose *compose)
5606 tmp = g_strdup_printf("%s%ctmpmsg.%08x", get_tmp_dir(),
5607 G_DIR_SEPARATOR, (gint)compose);
5609 if (pipe(pipe_fds) < 0) {
5615 if ((pid = fork()) < 0) {
5622 /* close the write side of the pipe */
5625 compose->exteditor_file = g_strdup(tmp);
5626 compose->exteditor_pid = pid;
5627 compose->exteditor_readdes = pipe_fds[0];
5629 compose_set_ext_editor_sensitive(compose, FALSE);
5631 compose->exteditor_tag =
5632 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5633 compose_input_cb, compose);
5634 } else { /* process-monitoring process */
5640 /* close the read side of the pipe */
5643 if (compose_write_body_to_file(compose, tmp) < 0) {
5644 fd_write(pipe_fds[1], "2\n", 2);
5648 pid_ed = compose_exec_ext_editor_real(tmp);
5650 fd_write(pipe_fds[1], "1\n", 2);
5654 /* wait until editor is terminated */
5655 waitpid(pid_ed, NULL, 0);
5657 fd_write(pipe_fds[1], "0\n", 2);
5666 static gint compose_exec_ext_editor_real(const gchar *file)
5668 static gchar *def_cmd = "emacs %s";
5674 g_return_val_if_fail(file != NULL, -1);
5676 if ((pid = fork()) < 0) {
5681 if (pid != 0) return pid;
5683 /* grandchild process */
5685 if (setpgid(0, getppid()))
5688 if (prefs_common.ext_editor_cmd &&
5689 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5690 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5691 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5693 if (prefs_common.ext_editor_cmd)
5694 g_warning("External editor command line is invalid: `%s'\n",
5695 prefs_common.ext_editor_cmd);
5696 g_snprintf(buf, sizeof(buf), def_cmd, file);
5699 cmdline = strsplit_with_quote(buf, " ", 1024);
5700 execvp(cmdline[0], cmdline);
5703 g_strfreev(cmdline);
5708 static gboolean compose_ext_editor_kill(Compose *compose)
5710 pid_t pgid = compose->exteditor_pid * -1;
5713 ret = kill(pgid, 0);
5715 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5719 msg = g_strdup_printf
5720 (_("The external editor is still working.\n"
5721 "Force terminating the process?\n"
5722 "process group id: %d"), -pgid);
5723 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5726 if (val == G_ALERTDEFAULT) {
5727 gdk_input_remove(compose->exteditor_tag);
5728 close(compose->exteditor_readdes);
5730 if (kill(pgid, SIGTERM) < 0) perror("kill");
5731 waitpid(compose->exteditor_pid, NULL, 0);
5733 g_warning("Terminated process group id: %d", -pgid);
5734 g_warning("Temporary file: %s",
5735 compose->exteditor_file);
5737 compose_set_ext_editor_sensitive(compose, TRUE);
5739 g_free(compose->exteditor_file);
5740 compose->exteditor_file = NULL;
5741 compose->exteditor_pid = -1;
5742 compose->exteditor_readdes = -1;
5743 compose->exteditor_tag = -1;
5751 static void compose_input_cb(gpointer data, gint source,
5752 GdkInputCondition condition)
5755 Compose *compose = (Compose *)data;
5758 debug_print("Compose: input from monitoring process\n");
5760 gdk_input_remove(compose->exteditor_tag);
5763 if (read(source, &buf[i], 1) < 1) {
5767 if (buf[i] == '\n') {
5772 if (i == sizeof(buf) - 1)
5776 waitpid(compose->exteditor_pid, NULL, 0);
5778 if (buf[0] == '0') { /* success */
5779 GtkSText *text = GTK_STEXT(compose->text);
5781 gtk_stext_freeze(text);
5782 gtk_stext_set_point(text, 0);
5783 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5784 compose_insert_file(compose, compose->exteditor_file);
5785 compose_changed_cb(NULL, compose);
5786 gtk_stext_thaw(text);
5788 if (unlink(compose->exteditor_file) < 0)
5789 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5790 } else if (buf[0] == '1') { /* failed */
5791 g_warning("Couldn't exec external editor\n");
5792 if (unlink(compose->exteditor_file) < 0)
5793 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5794 } else if (buf[0] == '2') {
5795 g_warning("Couldn't write to file\n");
5796 } else if (buf[0] == '3') {
5797 g_warning("Pipe read failed\n");
5802 compose_set_ext_editor_sensitive(compose, TRUE);
5804 g_free(compose->exteditor_file);
5805 compose->exteditor_file = NULL;
5806 compose->exteditor_pid = -1;
5807 compose->exteditor_readdes = -1;
5808 compose->exteditor_tag = -1;
5811 static void compose_set_ext_editor_sensitive(Compose *compose,
5814 GtkItemFactory *ifactory;
5816 ifactory = gtk_item_factory_from_widget(compose->menubar);
5818 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5819 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5820 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5822 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5823 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5824 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5825 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5826 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5829 gtk_widget_set_sensitive(compose->text, sensitive);
5830 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
5831 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
5832 gtk_widget_set_sensitive(compose->toolbar->draft_btn, sensitive);
5833 gtk_widget_set_sensitive(compose->toolbar->insert_btn, sensitive);
5834 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
5835 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
5836 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
5840 * compose_undo_state_changed:
5842 * Change the sensivity of the menuentries undo and redo
5844 static void compose_undo_state_changed(UndoMain *undostruct, gint undo_state,
5845 gint redo_state, gpointer data)
5847 GtkWidget *widget = GTK_WIDGET(data);
5848 GtkItemFactory *ifactory;
5850 g_return_if_fail(widget != NULL);
5852 debug_print("Set_undo. UNDO:%i REDO:%i\n", undo_state, redo_state);
5854 ifactory = gtk_item_factory_from_widget(widget);
5856 switch (undo_state) {
5857 case UNDO_STATE_TRUE:
5858 if (!undostruct->undo_state) {
5859 debug_print ("Set_undo - Testpoint\n");
5860 undostruct->undo_state = TRUE;
5861 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
5864 case UNDO_STATE_FALSE:
5865 if (undostruct->undo_state) {
5866 undostruct->undo_state = FALSE;
5867 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
5870 case UNDO_STATE_UNCHANGED:
5872 case UNDO_STATE_REFRESH:
5873 menu_set_sensitive(ifactory, "/Edit/Undo",
5874 undostruct->undo_state);
5877 g_warning("Undo state not recognized");
5881 switch (redo_state) {
5882 case UNDO_STATE_TRUE:
5883 if (!undostruct->redo_state) {
5884 undostruct->redo_state = TRUE;
5885 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
5888 case UNDO_STATE_FALSE:
5889 if (undostruct->redo_state) {
5890 undostruct->redo_state = FALSE;
5891 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
5894 case UNDO_STATE_UNCHANGED:
5896 case UNDO_STATE_REFRESH:
5897 menu_set_sensitive(ifactory, "/Edit/Redo",
5898 undostruct->redo_state);
5901 g_warning("Redo state not recognized");
5906 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5910 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5911 cursor_pos = MAX(cursor_pos, 0);
5916 /* callback functions */
5918 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5919 * includes "non-client" (windows-izm) in calculation, so this calculation
5920 * may not be accurate.
5922 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5923 GtkAllocation *allocation,
5924 GtkSHRuler *shruler)
5926 if (prefs_common.show_ruler) {
5928 gint line_width_in_chars;
5930 char_width = gtkut_get_font_width
5931 (GTK_WIDGET(widget)->style->font);
5932 line_width_in_chars =
5933 (allocation->width - allocation->x) / char_width;
5935 /* got the maximum */
5936 gtk_ruler_set_range(GTK_RULER(shruler),
5937 0.0, line_width_in_chars,
5938 calc_cursor_xpos(GTK_STEXT(widget),
5941 /*line_width_in_chars*/ char_width);
5947 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5949 Compose *compose = (Compose *)data;
5953 ac = account_find_from_id(
5954 GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menuitem))));
5955 g_return_if_fail(ac != NULL);
5957 if (ac != compose->account)
5958 compose_select_account(compose, ac);
5961 static void attach_selected(GtkCList *clist, gint row, gint column,
5962 GdkEvent *event, gpointer data)
5964 Compose *compose = (Compose *)data;
5966 if (event && event->type == GDK_2BUTTON_PRESS)
5967 compose_attach_property(compose);
5970 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5973 Compose *compose = (Compose *)data;
5974 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5979 if (event->button == 3) {
5980 if ((clist->selection && !clist->selection->next) ||
5981 !clist->selection) {
5982 gtk_clist_unselect_all(clist);
5983 if (gtk_clist_get_selection_info(clist,
5986 gtk_clist_select_row(clist, row, column);
5987 gtkut_clist_set_focus_row(clist, row);
5990 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5991 NULL, NULL, event->button, event->time);
5995 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5998 Compose *compose = (Compose *)data;
6002 switch (event->keyval) {
6004 compose_attach_remove_selected(compose);
6009 static void compose_allow_user_actions (Compose *compose, gboolean allow)
6011 GtkItemFactory *ifactory = gtk_item_factory_from_widget(compose->menubar);
6012 toolbar_comp_set_sensitive(compose, allow);
6013 menu_set_sensitive(ifactory, "/File", allow);
6014 menu_set_sensitive(ifactory, "/Edit", allow);
6015 menu_set_sensitive(ifactory, "/Spelling", allow);
6016 menu_set_sensitive(ifactory, "/Message", allow);
6017 menu_set_sensitive(ifactory, "/Tools", allow);
6018 menu_set_sensitive(ifactory, "/Help", allow);
6021 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
6023 Compose *compose = (Compose *)data;
6026 if (prefs_common.work_offline)
6027 if (alertpanel(_("Offline warning"),
6028 _("You're working offline. Override?"),
6029 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
6032 compose_allow_user_actions (compose, FALSE);
6033 compose->sending = TRUE;
6034 val = compose_send(compose);
6035 compose_allow_user_actions (compose, TRUE);
6036 compose->sending = FALSE;
6038 if (val == 0) gtk_widget_destroy(compose->window);
6041 static void compose_send_later_cb(gpointer data, guint action,
6044 Compose *compose = (Compose *)data;
6047 val = compose_queue_sub(compose, NULL, NULL, TRUE);
6048 if (!val) gtk_widget_destroy(compose->window);
6051 void compose_draft (gpointer data)
6053 compose_draft_cb(data, 0, NULL);
6056 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
6058 Compose *compose = (Compose *)data;
6062 static gboolean lock = FALSE;
6063 MsgInfo *newmsginfo;
6067 draft = account_get_special_folder(compose->account, F_DRAFT);
6068 g_return_if_fail(draft != NULL);
6072 tmp = g_strdup_printf("%s%cdraft.%08x", get_tmp_dir(),
6073 G_DIR_SEPARATOR, (gint)compose);
6075 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
6081 if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) < 0) {
6088 draft->mtime = 0; /* force updating */
6090 if (compose->mode == COMPOSE_REEDIT) {
6091 compose_remove_reedit_target(compose);
6094 newmsginfo = folder_item_get_msginfo(draft, msgnum);
6096 procmsg_msginfo_unset_flags(newmsginfo, ~0, ~0);
6097 procmsg_msginfo_set_flags(newmsginfo, 0, MSG_DRAFT);
6098 procmsg_msginfo_free(newmsginfo);
6103 /* 0: quit editing 1: keep editing 2: keep editing (autosave) */
6105 gtk_widget_destroy(compose->window);
6110 path = folder_item_fetch_msg(draft, msgnum);
6111 g_return_if_fail(path != NULL);
6112 if (stat(path, &s) < 0) {
6113 FILE_OP_ERROR(path, "stat");
6120 procmsg_msginfo_free(compose->targetinfo);
6121 compose->targetinfo = procmsg_msginfo_new();
6122 compose->targetinfo->msgnum = msgnum;
6123 compose->targetinfo->size = s.st_size;
6124 compose->targetinfo->mtime = s.st_mtime;
6125 compose->targetinfo->folder = draft;
6126 compose->mode = COMPOSE_REEDIT;
6129 compose->autosaved_draft = compose->targetinfo;
6134 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
6136 Compose *compose = (Compose *)data;
6139 if (compose->redirect_filename != NULL)
6142 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6147 for ( tmp = file_list; tmp; tmp = tmp->next) {
6148 gchar *file = (gchar *) tmp->data;
6149 compose_attach_append(compose, file, file, NULL);
6150 compose_changed_cb(NULL, compose);
6153 g_list_free(file_list);
6157 static void compose_insert_file_cb(gpointer data, guint action,
6160 Compose *compose = (Compose *)data;
6163 file_list = filesel_select_multiple_files(_("Select file"), NULL);
6168 for ( tmp = file_list; tmp; tmp = tmp->next) {
6169 gchar *file = (gchar *) tmp->data;
6170 compose_insert_file(compose, file);
6173 g_list_free(file_list);
6177 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
6180 Compose *compose = (Compose *)data;
6181 if (compose->sending)
6183 compose_close_cb(compose, 0, NULL);
6187 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
6189 Compose *compose = (Compose *)data;
6192 if (compose->exteditor_tag != -1) {
6193 if (!compose_ext_editor_kill(compose))
6197 if (compose->modified) {
6198 val = alertpanel(_("Discard message"),
6199 _("This message has been modified. discard it?"),
6200 _("Discard"), _("to Draft"), _("Cancel"));
6203 case G_ALERTDEFAULT:
6204 if (prefs_common.autosave)
6205 compose_remove_draft(compose);
6207 case G_ALERTALTERNATE:
6208 compose_draft_cb(data, 0, NULL);
6215 gtk_widget_destroy(compose->window);
6218 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
6220 Compose *compose = (Compose *)data;
6222 addressbook_open(compose);
6225 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
6227 Compose *compose = (Compose *)data;
6232 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
6233 g_return_if_fail(tmpl != NULL);
6235 msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
6237 val = alertpanel(_("Apply template"), msg,
6238 _("Replace"), _("Insert"), _("Cancel"));
6241 if (val == G_ALERTDEFAULT)
6242 compose_template_apply(compose, tmpl, TRUE);
6243 else if (val == G_ALERTALTERNATE)
6244 compose_template_apply(compose, tmpl, FALSE);
6247 static void compose_ext_editor_cb(gpointer data, guint action,
6250 Compose *compose = (Compose *)data;
6252 compose_exec_ext_editor(compose);
6255 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
6257 if (compose->sending)
6259 compose_destroy(compose);
6262 static void compose_undo_cb(Compose *compose)
6264 undo_undo(compose->undostruct);
6267 static void compose_redo_cb(Compose *compose)
6269 undo_redo(compose->undostruct);
6272 static void compose_cut_cb(Compose *compose)
6274 if (compose->focused_editable &&
6275 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6276 gtk_editable_cut_clipboard
6277 (GTK_EDITABLE(compose->focused_editable));
6280 static void compose_copy_cb(Compose *compose)
6282 if (compose->focused_editable &&
6283 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6284 gtk_editable_copy_clipboard
6285 (GTK_EDITABLE(compose->focused_editable));
6288 static void compose_paste_cb(Compose *compose)
6290 if (compose->focused_editable &&
6291 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6292 gtk_editable_paste_clipboard
6293 (GTK_EDITABLE(compose->focused_editable));
6296 static void compose_paste_as_quote_cb(Compose *compose)
6298 if (compose->focused_editable &&
6299 GTK_WIDGET_HAS_FOCUS(compose->focused_editable)) {
6300 compose->paste_as_quotation = TRUE;
6301 gtk_editable_paste_clipboard
6302 (GTK_EDITABLE(compose->focused_editable));
6303 compose->paste_as_quotation = FALSE;
6307 static void compose_allsel_cb(Compose *compose)
6309 if (compose->focused_editable &&
6310 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
6311 gtk_editable_select_region
6312 (GTK_EDITABLE(compose->focused_editable), 0, -1);
6315 static void compose_gtk_stext_action_cb(Compose *compose,
6316 ComposeCallGtkSTextAction action)
6318 GtkSText *text = GTK_STEXT(compose->text);
6320 void (*do_action) (GtkSText *text);
6321 } action_table[] = {
6322 {gtk_stext_move_beginning_of_line},
6323 {gtk_stext_move_forward_character},
6324 {gtk_stext_move_backward_character},
6325 {gtk_stext_move_forward_word},
6326 {gtk_stext_move_backward_word},
6327 {gtk_stext_move_end_of_line},
6328 {gtk_stext_move_next_line},
6329 {gtk_stext_move_previous_line},
6330 {gtk_stext_delete_forward_character},
6331 {gtk_stext_delete_backward_character},
6332 {gtk_stext_delete_forward_word},
6333 {gtk_stext_delete_backward_word},
6334 {gtk_stext_delete_line},
6335 {gtk_stext_delete_line}, /* gtk_stext_delete_line_n */
6336 {gtk_stext_delete_to_line_end}
6339 if (!GTK_WIDGET_HAS_FOCUS(text)) return;
6341 if (action >= COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE &&
6342 action <= COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END)
6343 action_table[action].do_action(text);
6346 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
6348 if (GTK_IS_EDITABLE(widget))
6349 compose->focused_editable = widget;
6352 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
6354 if (compose->modified == FALSE) {
6355 compose->modified = TRUE;
6356 compose_set_title(compose);
6360 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
6363 gtk_stext_set_point(GTK_STEXT(widget),
6364 gtk_editable_get_position(GTK_EDITABLE(widget)));
6368 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
6371 gtk_stext_set_point(GTK_STEXT(widget),
6372 gtk_editable_get_position(GTK_EDITABLE(widget)));
6376 #if 0 /* NEW COMPOSE GUI */
6377 static void compose_toggle_to_cb(gpointer data, guint action,
6380 Compose *compose = (Compose *)data;
6382 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6383 gtk_widget_show(compose->to_hbox);
6384 gtk_widget_show(compose->to_entry);
6385 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
6386 compose->use_to = TRUE;
6388 gtk_widget_hide(compose->to_hbox);
6389 gtk_widget_hide(compose->to_entry);
6390 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
6391 gtk_widget_queue_resize(compose->table_vbox);
6392 compose->use_to = FALSE;
6395 if (addressbook_get_target_compose() == compose)
6396 addressbook_set_target_compose(compose);
6399 static void compose_toggle_cc_cb(gpointer data, guint action,
6402 Compose *compose = (Compose *)data;
6404 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6405 gtk_widget_show(compose->cc_hbox);
6406 gtk_widget_show(compose->cc_entry);
6407 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
6408 compose->use_cc = TRUE;
6410 gtk_widget_hide(compose->cc_hbox);
6411 gtk_widget_hide(compose->cc_entry);
6412 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
6413 gtk_widget_queue_resize(compose->table_vbox);
6414 compose->use_cc = FALSE;
6417 if (addressbook_get_target_compose() == compose)
6418 addressbook_set_target_compose(compose);
6421 static void compose_toggle_bcc_cb(gpointer data, guint action,
6424 Compose *compose = (Compose *)data;
6426 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6427 gtk_widget_show(compose->bcc_hbox);
6428 gtk_widget_show(compose->bcc_entry);
6429 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
6430 compose->use_bcc = TRUE;
6432 gtk_widget_hide(compose->bcc_hbox);
6433 gtk_widget_hide(compose->bcc_entry);
6434 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
6435 gtk_widget_queue_resize(compose->table_vbox);
6436 compose->use_bcc = FALSE;
6439 if (addressbook_get_target_compose() == compose)
6440 addressbook_set_target_compose(compose);
6443 static void compose_toggle_replyto_cb(gpointer data, guint action,
6446 Compose *compose = (Compose *)data;
6448 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6449 gtk_widget_show(compose->reply_hbox);
6450 gtk_widget_show(compose->reply_entry);
6451 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
6452 compose->use_replyto = TRUE;
6454 gtk_widget_hide(compose->reply_hbox);
6455 gtk_widget_hide(compose->reply_entry);
6456 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
6457 gtk_widget_queue_resize(compose->table_vbox);
6458 compose->use_replyto = FALSE;
6462 static void compose_toggle_followupto_cb(gpointer data, guint action,
6465 Compose *compose = (Compose *)data;
6467 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6468 gtk_widget_show(compose->followup_hbox);
6469 gtk_widget_show(compose->followup_entry);
6470 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
6471 compose->use_followupto = TRUE;
6473 gtk_widget_hide(compose->followup_hbox);
6474 gtk_widget_hide(compose->followup_entry);
6475 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
6476 gtk_widget_queue_resize(compose->table_vbox);
6477 compose->use_followupto = FALSE;
6481 static void compose_toggle_attach_cb(gpointer data, guint action,
6484 Compose *compose = (Compose *)data;
6486 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6487 gtk_widget_ref(compose->edit_vbox);
6489 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6490 compose->edit_vbox);
6491 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
6492 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
6494 gtk_widget_show(compose->paned);
6496 gtk_widget_unref(compose->edit_vbox);
6497 gtk_widget_unref(compose->paned);
6499 compose->use_attach = TRUE;
6501 gtk_widget_ref(compose->paned);
6502 gtk_widget_ref(compose->edit_vbox);
6504 gtkut_container_remove(GTK_CONTAINER(compose->vbox2),
6506 gtkut_container_remove(GTK_CONTAINER(compose->paned),
6507 compose->edit_vbox);
6508 gtk_box_pack_start(GTK_BOX(compose->vbox2),
6509 compose->edit_vbox, TRUE, TRUE, 0);
6511 gtk_widget_unref(compose->edit_vbox);
6513 compose->use_attach = FALSE;
6519 static void compose_toggle_sign_cb(gpointer data, guint action,
6522 Compose *compose = (Compose *)data;
6524 if (GTK_CHECK_MENU_ITEM(widget)->active)
6525 compose->use_signing = TRUE;
6527 compose->use_signing = FALSE;
6529 compose_update_gnupg_mode_menu_item(compose);
6532 static void compose_toggle_encrypt_cb(gpointer data, guint action,
6535 Compose *compose = (Compose *)data;
6537 if (GTK_CHECK_MENU_ITEM(widget)->active)
6538 compose->use_encryption = TRUE;
6540 compose->use_encryption = FALSE;
6542 compose_update_gnupg_mode_menu_item(compose);
6545 static void activate_gnupg_mode (Compose *compose, PrefsAccount *account)
6547 if (account->default_gnupg_mode)
6548 compose->gnupg_mode = GNUPG_MODE_INLINE;
6550 compose->gnupg_mode = GNUPG_MODE_DETACH;
6552 compose_update_gnupg_mode_menu_item(compose);
6554 #endif /* USE_GPGME */
6556 static void compose_toggle_ruler_cb(gpointer data, guint action,
6559 Compose *compose = (Compose *)data;
6561 if (GTK_CHECK_MENU_ITEM(widget)->active) {
6562 gtk_widget_show(compose->ruler_hbox);
6563 prefs_common.show_ruler = TRUE;
6565 gtk_widget_hide(compose->ruler_hbox);
6566 gtk_widget_queue_resize(compose->edit_vbox);
6567 prefs_common.show_ruler = FALSE;
6571 static void compose_attach_drag_received_cb (GtkWidget *widget,
6572 GdkDragContext *drag_context,
6575 GtkSelectionData *data,
6580 Compose *compose = (Compose *)user_data;
6583 list = uri_list_extract_filenames((const gchar *)data->data);
6584 for (tmp = list; tmp != NULL; tmp = tmp->next)
6585 compose_attach_append
6586 (compose, (const gchar *)tmp->data,
6587 (const gchar *)tmp->data, NULL);
6588 if (list) compose_changed_cb(NULL, compose);
6589 list_free_strings(list);
6593 static void compose_insert_drag_received_cb (GtkWidget *widget,
6594 GdkDragContext *drag_context,
6597 GtkSelectionData *data,
6602 Compose *compose = (Compose *)user_data;
6605 list = uri_list_extract_filenames((const gchar *)data->data);
6606 for (tmp = list; tmp != NULL; tmp = tmp->next)
6607 compose_insert_file(compose, (const gchar *)tmp->data);
6608 list_free_strings(list);
6612 #if 0 /* NEW COMPOSE GUI */
6613 static void to_activated(GtkWidget *widget, Compose *compose)
6615 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6616 gtk_widget_grab_focus(compose->newsgroups_entry);
6618 gtk_widget_grab_focus(compose->subject_entry);
6621 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6623 gtk_widget_grab_focus(compose->subject_entry);
6626 static void subject_activated(GtkWidget *widget, Compose *compose)
6628 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6629 gtk_widget_grab_focus(compose->cc_entry);
6630 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6631 gtk_widget_grab_focus(compose->bcc_entry);
6632 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6633 gtk_widget_grab_focus(compose->reply_entry);
6634 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6635 gtk_widget_grab_focus(compose->followup_entry);
6637 gtk_widget_grab_focus(compose->text);
6640 static void cc_activated(GtkWidget *widget, Compose *compose)
6642 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6643 gtk_widget_grab_focus(compose->bcc_entry);
6644 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6645 gtk_widget_grab_focus(compose->reply_entry);
6646 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6647 gtk_widget_grab_focus(compose->followup_entry);
6649 gtk_widget_grab_focus(compose->text);
6652 static void bcc_activated(GtkWidget *widget, Compose *compose)
6654 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6655 gtk_widget_grab_focus(compose->reply_entry);
6656 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6657 gtk_widget_grab_focus(compose->followup_entry);
6659 gtk_widget_grab_focus(compose->text);
6662 static void replyto_activated(GtkWidget *widget, Compose *compose)
6664 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6665 gtk_widget_grab_focus(compose->followup_entry);
6667 gtk_widget_grab_focus(compose->text);
6670 static void followupto_activated(GtkWidget *widget, Compose *compose)
6672 gtk_widget_grab_focus(compose->text);
6676 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6679 Compose *compose = (Compose *)data;
6681 if (GTK_CHECK_MENU_ITEM(widget)->active)
6682 compose->return_receipt = TRUE;
6684 compose->return_receipt = FALSE;
6687 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6689 ComposeHeaderEntry *headerentry)
6691 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6692 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6693 !(event->state & GDK_MODIFIER_MASK) &&
6694 (event->keyval == GDK_BackSpace) &&
6695 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6696 gtk_container_remove
6697 (GTK_CONTAINER(headerentry->compose->header_table),
6698 headerentry->combo);
6699 gtk_container_remove
6700 (GTK_CONTAINER(headerentry->compose->header_table),
6701 headerentry->entry);
6702 headerentry->compose->header_list =
6703 g_slist_remove(headerentry->compose->header_list,
6705 g_free(headerentry);
6706 } else if (event->keyval == GDK_Tab) {
6707 if (headerentry->compose->header_last == headerentry) {
6708 /* Override default next focus, and give it to subject_entry
6709 * instead of notebook tabs
6711 gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event");
6712 gtk_widget_grab_focus(headerentry->compose->subject_entry);
6718 void compose_headerentry_changed_cb(GtkWidget *entry,
6719 ComposeHeaderEntry *headerentry)
6721 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6722 headerentry->compose->header_list =
6723 g_slist_append(headerentry->compose->header_list,
6725 compose_create_header_entry(headerentry->compose);
6726 gtk_signal_disconnect_by_func
6728 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6730 /* Automatically scroll down */
6731 compose_show_first_last_header(headerentry->compose, FALSE);
6736 static void compose_show_first_last_header(Compose *compose, gboolean show_first)
6738 GtkAdjustment *vadj;
6740 g_return_if_fail(compose);
6741 g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
6742 g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
6744 vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
6745 gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
6748 static void text_activated(GtkWidget *widget, Compose *compose)
6750 compose_send_control_enter(compose);
6753 static void text_inserted(GtkWidget *widget, const gchar *text,
6754 gint length, gint *position, Compose *compose)
6756 GtkEditable *editable = GTK_EDITABLE(widget);
6758 gtk_signal_handler_block_by_func(GTK_OBJECT(widget),
6759 GTK_SIGNAL_FUNC(text_inserted),
6761 if (compose->paste_as_quotation) {
6766 new_text = g_strndup(text, length);
6767 if (prefs_common.quotemark && *prefs_common.quotemark)
6768 qmark = prefs_common.quotemark;
6771 gtk_stext_set_point(GTK_STEXT(widget), *position);
6772 compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
6773 pos = gtk_stext_get_point(GTK_STEXT(widget));
6774 gtk_editable_set_position(editable, pos);
6778 gtk_editable_insert_text(editable, text, length, position);
6780 if (prefs_common.autowrap)
6781 compose_wrap_line_all_full(compose, TRUE);
6783 gtk_signal_handler_unblock_by_func(GTK_OBJECT(widget),
6784 GTK_SIGNAL_FUNC(text_inserted),
6786 gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
6789 if (prefs_common.autosave &&
6790 gtk_stext_get_length(GTK_STEXT(widget)) % prefs_common.autosave_length == 0)
6791 compose_draft_cb((gpointer)compose, 2, NULL);
6794 static gboolean compose_send_control_enter(Compose *compose)
6798 GtkItemFactory *ifactory;
6799 GtkAccelEntry *accel;
6800 GtkWidget *send_menu;
6802 GdkModifierType ignored_mods =
6803 (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
6804 GDK_MOD4_MASK | GDK_MOD5_MASK);
6806 ev = gtk_get_current_event();
6807 if (ev->type != GDK_KEY_PRESS) return FALSE;
6809 kev = (GdkEventKey *)ev;
6810 if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
6813 ifactory = gtk_item_factory_from_widget(compose->menubar);
6814 send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
6815 list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_menu));
6819 accel = (GtkAccelEntry *)list->data;
6820 if (accel && accel->accelerator_key == kev->keyval &&
6821 (accel->accelerator_mods & ~ignored_mods) ==
6822 (kev->state & ~ignored_mods)) {
6823 compose_send_cb(compose, 0, NULL);
6831 static void compose_check_all(Compose *compose)
6833 if (compose->gtkaspell)
6834 gtkaspell_check_all(compose->gtkaspell);
6837 static void compose_highlight_all(Compose *compose)
6839 if (compose->gtkaspell)
6840 gtkaspell_highlight_all(compose->gtkaspell);
6843 static void compose_check_backwards(Compose *compose)
6845 if (compose->gtkaspell)
6846 gtkaspell_check_backwards(compose->gtkaspell);
6848 GtkItemFactory *ifactory;
6849 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6850 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6851 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);
6855 static void compose_check_forwards_go(Compose *compose)
6857 if (compose->gtkaspell)
6858 gtkaspell_check_forwards_go(compose->gtkaspell);
6860 GtkItemFactory *ifactory;
6861 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
6862 menu_set_sensitive(ifactory, "/Edit/Check backwards misspelled word", FALSE);
6863 menu_set_sensitive(ifactory, "/Edit/Forward to next misspelled word", FALSE);