2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 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>
58 /* #include <sys/utsname.h> */
64 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
74 #include "mainwindow.h"
76 #include "addressbook.h"
77 #include "folderview.h"
82 #include "customheader.h"
83 #include "prefs_common.h"
84 #include "prefs_account.h"
87 #include "procheader.h"
89 #include "statusbar.h"
96 #include "alertpanel.h"
97 #include "manage_window.h"
98 #include "gtkshruler.h"
100 #include "addr_compl.h"
101 #include "quote_fmt.h"
102 #include "template.h"
106 # include "rfc2015.h"
116 #define N_ATTACH_COLS 3
118 #define B64_LINE_SIZE 57
119 #define B64_BUFFSIZE 77
121 #define MAX_REFERENCES_LEN 999
123 static GdkColor quote_color = {0, 0, 0, 0xbfff};
125 static GList *compose_list = NULL;
127 static void compose_set_undo (UndoMain *undostruct, gint undo_state, gint redo_state, GtkWidget *changewidget);
128 Compose *compose_generic_new (PrefsAccount *account,
132 static Compose *compose_create (PrefsAccount *account,
134 static void compose_toolbar_create (Compose *compose,
135 GtkWidget *container);
136 static GtkWidget *compose_account_option_menu_create
138 static void compose_set_template_menu (Compose *compose);
139 static void compose_template_apply (Compose *compose,
141 static void compose_destroy (Compose *compose);
143 static void compose_entries_set (Compose *compose,
144 const gchar *mailto);
145 static gint compose_parse_header (Compose *compose,
147 static gchar *compose_parse_references (const gchar *ref,
150 static gchar *compose_quote_fmt (Compose *compose,
155 static void compose_reply_set_entry (Compose *compose,
160 followup_and_reply_to);
161 static void compose_reedit_set_entry (Compose *compose,
163 static void compose_insert_sig (Compose *compose);
164 static void compose_insert_file (Compose *compose,
166 static void compose_attach_append (Compose *compose,
168 ContentType cnttype);
169 static void compose_attach_append_with_type(Compose *compose,
172 ContentType cnttype);
173 static void compose_wrap_line (Compose *compose);
174 static void compose_wrap_line_all (Compose *compose);
175 static void compose_set_title (Compose *compose);
177 static PrefsAccount *compose_current_mail_account(void);
178 /* static gint compose_send (Compose *compose); */
179 static gint compose_write_to_file (Compose *compose,
182 static gint compose_write_body_to_file (Compose *compose,
184 static gint compose_save_to_outbox (Compose *compose,
186 static gint compose_remove_reedit_target (Compose *compose);
187 static gint compose_queue (Compose *compose,
190 static void compose_write_attach (Compose *compose,
192 static gint compose_write_headers (Compose *compose,
194 const gchar *charset,
195 EncodingType encoding,
198 static void compose_convert_header (gchar *dest,
202 static void compose_generate_msgid (Compose *compose,
206 static void compose_attach_info_free (AttachInfo *ainfo);
207 static void compose_attach_remove_selected (Compose *compose);
209 static void compose_attach_property (Compose *compose);
210 static void compose_attach_property_create (gboolean *cancelled);
211 static void attach_property_ok (GtkWidget *widget,
212 gboolean *cancelled);
213 static void attach_property_cancel (GtkWidget *widget,
214 gboolean *cancelled);
215 static gint attach_property_delete_event (GtkWidget *widget,
217 gboolean *cancelled);
218 static void attach_property_key_pressed (GtkWidget *widget,
220 gboolean *cancelled);
222 static void compose_exec_ext_editor (Compose *compose);
223 static gint compose_exec_ext_editor_real (const gchar *file);
224 static gboolean compose_ext_editor_kill (Compose *compose);
225 static void compose_input_cb (gpointer data,
227 GdkInputCondition condition);
228 static void compose_set_ext_editor_sensitive (Compose *compose,
231 static gint calc_cursor_xpos (GtkSText *text,
235 static void compose_create_header_entry (Compose *compose);
236 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
238 /* callback functions */
240 static gboolean compose_edit_size_alloc (GtkEditable *widget,
241 GtkAllocation *allocation,
242 GtkSHRuler *shruler);
244 static void toolbar_send_cb (GtkWidget *widget,
246 static void toolbar_send_later_cb (GtkWidget *widget,
248 static void toolbar_draft_cb (GtkWidget *widget,
250 static void toolbar_insert_cb (GtkWidget *widget,
252 static void toolbar_attach_cb (GtkWidget *widget,
254 static void toolbar_sig_cb (GtkWidget *widget,
256 static void toolbar_ext_editor_cb (GtkWidget *widget,
258 static void toolbar_linewrap_cb (GtkWidget *widget,
260 static void toolbar_address_cb (GtkWidget *widget,
263 static void select_account (Compose *compose,
266 static void account_activated (GtkMenuItem *menuitem,
269 static void attach_selected (GtkCList *clist,
274 static void attach_button_pressed (GtkWidget *widget,
275 GdkEventButton *event,
277 static void attach_key_pressed (GtkWidget *widget,
281 static void compose_send_cb (gpointer data,
284 static void compose_send_later_cb (gpointer data,
288 static void compose_draft_cb (gpointer data,
292 static void compose_attach_cb (gpointer data,
295 static void compose_insert_file_cb (gpointer data,
299 static void compose_close_cb (gpointer data,
303 static void compose_address_cb (gpointer data,
306 static void compose_template_activate_cb(GtkWidget *widget,
309 static void compose_ext_editor_cb (gpointer data,
313 static gint compose_delete_cb (GtkWidget *widget,
316 static void compose_destroy_cb (GtkWidget *widget,
319 static void compose_undo_cb (Compose *compose);
320 static void compose_redo_cb (Compose *compose);
321 static void compose_cut_cb (Compose *compose);
322 static void compose_copy_cb (Compose *compose);
323 static void compose_paste_cb (Compose *compose);
324 static void compose_allsel_cb (Compose *compose);
326 static void compose_grab_focus_cb (GtkWidget *widget,
329 static void compose_changed_cb (GtkEditable *editable,
331 static void compose_button_press_cb (GtkWidget *widget,
332 GdkEventButton *event,
335 static void compose_key_press_cb (GtkWidget *widget,
341 static void compose_toggle_to_cb (gpointer data,
344 static void compose_toggle_cc_cb (gpointer data,
347 static void compose_toggle_bcc_cb (gpointer data,
350 static void compose_toggle_replyto_cb (gpointer data,
353 static void compose_toggle_followupto_cb(gpointer data,
356 static void compose_toggle_attach_cb (gpointer data,
360 static void compose_toggle_ruler_cb (gpointer data,
364 static void compose_toggle_sign_cb (gpointer data,
367 static void compose_toggle_encrypt_cb (gpointer data,
371 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
374 static void compose_attach_drag_received_cb (GtkWidget *widget,
375 GdkDragContext *drag_context,
378 GtkSelectionData *data,
382 static void compose_insert_drag_received_cb (GtkWidget *widget,
383 GdkDragContext *drag_context,
386 GtkSelectionData *data,
392 static void to_activated (GtkWidget *widget,
394 static void newsgroups_activated (GtkWidget *widget,
396 static void subject_activated (GtkWidget *widget,
398 static void cc_activated (GtkWidget *widget,
400 static void bcc_activated (GtkWidget *widget,
402 static void replyto_activated (GtkWidget *widget,
404 static void followupto_activated (GtkWidget *widget,
408 static void compose_attach_parts (Compose *compose,
411 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
413 gboolean ignore_replyto,
414 gboolean followup_and_reply_to);
416 void compose_headerentry_changed_cb (GtkWidget *entry,
417 ComposeHeaderEntry *headerentry);
418 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
420 ComposeHeaderEntry *headerentry);
422 static GtkItemFactoryEntry compose_popup_entries[] =
424 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
425 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
426 {N_("/---"), NULL, NULL, 0, "<Separator>"},
427 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
430 static GtkItemFactoryEntry compose_entries[] =
432 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
433 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
434 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
435 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
436 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
437 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
439 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
440 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
441 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
442 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
443 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
444 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
445 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
446 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
447 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
448 {N_("/_Edit/_Wrap current paragraph"), "<alt>L", compose_wrap_line, 0, NULL},
449 {N_("/_Edit/Wrap all long _lines"),
450 "<shift><alt>L", compose_wrap_line_all, 0, NULL},
451 {N_("/_Edit/Edit with e_xternal editor"),
452 "<alt>X", compose_ext_editor_cb, 0, NULL},
454 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
455 {N_("/_Message/_Send"), "<control>Return",
456 compose_send_cb, 0, NULL},
457 {N_("/_Message/Send _later"), "<shift><alt>S",
458 compose_send_later_cb, 0, NULL},
459 {N_("/_Message/Save to _draft folder"),
460 "<alt>D", compose_draft_cb, 0, NULL},
461 #if 0 /* NEW COMPOSE GUI */
462 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
463 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
464 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
465 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
466 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
467 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
468 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
469 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
470 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
473 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
474 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
475 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
476 #endif /* USE_GPGME */
477 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
478 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
479 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
480 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
481 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb , 0, NULL},
482 {N_("/_Tool/_Template"), NULL, NULL, 0, "<Branch>"},
483 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
484 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
487 static GtkTargetEntry compose_mime_types[] =
489 {"text/uri-list", 0, 0}
492 Compose *compose_new(PrefsAccount *account)
494 return compose_generic_new(account, NULL, NULL);
497 Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
501 GtkItemFactory *ifactory;
503 c = compose_generic_new(account, NULL, NULL);
505 filename = procmsg_get_message_file(msginfo);
506 if (filename == NULL)
509 c->bounce_filename = filename;
511 if (msginfo->subject)
512 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
514 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
516 compose_quote_fmt(c, msginfo, "%M", NULL);
517 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
519 ifactory = gtk_item_factory_from_widget(c->popupmenu);
520 menu_set_sensitive(ifactory, "/Add...", FALSE);
521 menu_set_sensitive(ifactory, "/Remove", FALSE);
522 menu_set_sensitive(ifactory, "/Property...", FALSE);
524 ifactory = gtk_item_factory_from_widget(c->menubar);
525 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
526 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
527 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
528 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
529 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
530 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
531 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
532 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
534 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
535 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
537 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
538 menu_set_sensitive(ifactory, "/Tool/Template", FALSE);
540 gtk_widget_set_sensitive(c->insert_btn, FALSE);
541 gtk_widget_set_sensitive(c->attach_btn, FALSE);
542 gtk_widget_set_sensitive(c->sig_btn, FALSE);
543 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
544 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
549 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
551 return compose_generic_new(account, mailto, NULL);
554 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
556 return compose_generic_new(account, NULL, item);
559 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
563 if (item && item->prefs && item->prefs->enable_default_account)
564 account = account_find_from_id(item->prefs->default_account);
566 if (!account) account = cur_account;
567 g_return_val_if_fail(account != NULL, NULL);
569 compose = compose_create(account, COMPOSE_NEW);
570 compose->replyinfo = NULL;
572 if (prefs_common.auto_sig)
573 compose_insert_sig(compose);
574 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
575 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
577 if (account->protocol != A_NNTP) {
579 compose_entries_set(compose, mailto);
581 } else if(item && item->prefs->enable_default_to) {
582 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
584 if (item && item->ret_rcpt) {
585 GtkItemFactory *ifactory;
587 ifactory = gtk_item_factory_from_widget(compose->menubar);
588 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
592 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
595 gtk_widget_grab_focus(compose->subject_entry);
597 if (prefs_common.auto_exteditor)
598 compose_exec_ext_editor(compose);
603 #define CHANGE_FLAGS(msginfo) \
605 if (msginfo->folder->folder->change_flags != NULL) \
606 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
612 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
613 const gchar *followupto, gchar * to)
617 if (!account) account = cur_account;
618 g_return_val_if_fail(account != NULL, NULL);
619 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
621 compose = compose_create(account, COMPOSE_NEW);
623 if (prefs_common.auto_sig)
624 compose_insert_sig(compose);
625 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
626 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
628 compose_entry_append(compose, to, COMPOSE_TO);
629 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
630 gtk_widget_grab_focus(compose->subject_entry);
636 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
637 gboolean ignore_replyto)
639 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
642 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
644 gboolean ignore_replyto)
646 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
649 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
651 gboolean ignore_replyto,
652 gboolean followup_and_reply_to)
655 PrefsAccount *account;
656 PrefsAccount *reply_account;
659 g_return_if_fail(msginfo != NULL);
660 g_return_if_fail(msginfo->folder != NULL);
663 /* select the account set in folderitem's property (if enabled) */
664 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
665 account = account_find_from_id(msginfo->folder->prefs->default_account);
667 /* select the account for the whole folder (IMAP / NNTP) */
669 account = msginfo->folder->folder->account;
671 /* select account by to: and cc: header if enabled */
672 if (prefs_common.reply_account_autosel) {
673 if (!account && msginfo->to) {
675 Xstrdup_a(to, msginfo->to, return);
677 account = account_find_from_address(to);
681 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
683 account = account_find_from_address(cc);
688 /* select current account */
689 if (!account) account = cur_account;
690 g_return_if_fail(account != NULL);
692 if (ignore_replyto && account->protocol == A_NNTP &&
693 !followup_and_reply_to) {
695 account_find_from_address(account->address);
697 reply_account = compose_current_mail_account();
701 reply_account = account;
703 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
704 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
706 CHANGE_FLAGS(msginfo);
708 compose = compose_create(account, COMPOSE_REPLY);
709 compose->replyinfo = procmsg_msginfo_copy(msginfo);
711 #if 0 /* NEW COMPOSE GUI */
712 if (followup_and_reply_to) {
713 gtk_widget_show(compose->to_hbox);
714 gtk_widget_show(compose->to_entry);
715 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
716 compose->use_to = TRUE;
719 if (msginfo->folder && msginfo->folder->ret_rcpt) {
720 GtkItemFactory *ifactory;
722 ifactory = gtk_item_factory_from_widget(compose->menubar);
723 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
726 if (compose_parse_header(compose, msginfo) < 0) return;
727 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
728 followup_and_reply_to);
730 text = GTK_STEXT(compose->text);
731 gtk_stext_freeze(text);
737 if (prefs_common.quotemark && *prefs_common.quotemark)
738 qmark = prefs_common.quotemark;
742 quote_str = compose_quote_fmt(compose, msginfo,
743 prefs_common.quotefmt,
747 if (prefs_common.auto_sig)
748 compose_insert_sig(compose);
749 gtk_editable_set_position(GTK_EDITABLE(text), 0);
750 gtk_stext_set_point(text, 0);
752 if (quote && prefs_common.linewrap_quote)
753 compose_wrap_line_all(compose);
755 gtk_stext_thaw(text);
756 gtk_widget_grab_focus(compose->text);
758 if (prefs_common.auto_exteditor)
759 compose_exec_ext_editor(compose);
763 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
768 g_return_val_if_fail(mimeinfo != NULL, NULL);
770 base = mimeinfo->filename ? mimeinfo->filename
771 : mimeinfo->name ? mimeinfo->name : NULL;
773 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
774 filename = g_strdup_printf("%s%smimetmp.%08x.html",
781 base = base ? base : "";
782 base = g_basename(base);
784 filename = g_strdup_printf("%s%smimetmp.%08x",
792 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
798 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
802 if (!partinfo) return NULL;
804 filename = procmime_get_file_name(partinfo);
806 if (procmime_get_part(filename, source, partinfo) < 0)
808 (_("Can't get the part of multipart message."));
813 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
821 gint boundary_len = 0;
823 glong fpos, prev_fpos;
828 g_return_if_fail(msginfo != NULL);
832 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
833 mimeinfo = procmime_scan_mime_header(fp);
834 if (!mimeinfo) break;
836 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
837 rfc2015_is_encrypted(mimeinfo)) {
838 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
840 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
841 !msginfo->plaintext_file &&
842 !msginfo->decryption_failed) {
843 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
844 if (msginfo->plaintext_file &&
845 !msginfo->decryption_failed) {
853 #else /* !USE_GPGME */
854 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
855 mimeinfo = procmime_scan_mime_header(fp);
856 #endif /* USE_GPGME */
859 if (!mimeinfo) return;
860 if (mimeinfo->mime_type == MIME_TEXT)
863 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
865 g_return_if_fail(mimeinfo != NULL);
866 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
868 if (mimeinfo->mime_type == MIME_MULTIPART) {
869 g_return_if_fail(mimeinfo->boundary != NULL);
870 g_return_if_fail(mimeinfo->sub == NULL);
872 g_return_if_fail(fp != NULL);
874 boundary = mimeinfo->boundary;
877 boundary_len = strlen(boundary);
879 /* look for first boundary */
880 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
881 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
888 if ((fpos = ftell(fp)) < 0) {
894 for (npart = 0;; npart++) {
896 gboolean eom = FALSE;
900 partinfo = procmime_scan_mime_header(fp);
901 if (!partinfo) break;
904 procmime_mimeinfo_insert(mimeinfo, partinfo);
906 procmime_mimeinfo_free(partinfo);
908 /* look for next boundary */
910 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
911 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
912 if (buf[2 + boundary_len] == '-' &&
913 buf[2 + boundary_len + 1] == '-')
919 eom = TRUE; /* broken MIME message */
922 partinfo->size = fpos - prev_fpos - strlen(buf);
927 source = procmsg_get_message_file_path(msginfo);
929 g_return_if_fail(mimeinfo != NULL);
931 if (!mimeinfo->main && mimeinfo->parent)
933 filename = mime_extract_file(source, mimeinfo);
935 compose_attach_append_with_type(compose, filename,
936 mimeinfo->content_type,
937 mimeinfo->mime_type);
942 if (mimeinfo->sub && mimeinfo->sub->children)
944 filename = mime_extract_file(source, mimeinfo->sub);
946 compose_attach_append_with_type(compose, filename,
947 mimeinfo->content_type,
948 mimeinfo->sub->mime_type);
953 if (mimeinfo->children) {
956 child = mimeinfo->children;
958 filename = mime_extract_file(source, child);
960 compose_attach_append_with_type(compose, filename,
972 procmime_mimeinfo_free_all(mimeinfo);
976 #define INSERT_FW_HEADER(var, hdr) \
977 if (msginfo->var && *msginfo->var) { \
978 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
979 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
980 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
983 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
987 /* PrefsAccount *account; */
990 g_return_val_if_fail(msginfo != NULL, NULL);
991 g_return_val_if_fail(msginfo->folder != NULL, NULL);
993 account = msginfo->folder->folder->account;
994 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
996 Xstrdup_a(to, msginfo->to, return NULL);
998 account = account_find_from_address(to);
1001 if(!account && prefs_common.forward_account_autosel) {
1003 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1004 extract_address(cc);
1005 account = account_find_from_address(cc);
1009 if (account == NULL) {
1010 account = cur_account;
1012 account = msginfo->folder->folder->account;
1013 if (!account) account = cur_account;
1016 g_return_val_if_fail(account != NULL, NULL);
1018 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1019 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1020 CHANGE_FLAGS(msginfo);
1022 compose = compose_create(account, COMPOSE_FORWARD);
1024 if (msginfo->subject && *msginfo->subject) {
1025 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1026 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1030 text = GTK_STEXT(compose->text);
1031 gtk_stext_freeze(text);
1036 msgfile = procmsg_get_message_file_path(msginfo);
1037 if (!is_file_exist(msgfile))
1038 g_warning(_("%s: file not exist\n"), msgfile);
1040 compose_attach_append(compose, msgfile,
1041 MIME_MESSAGE_RFC822);
1048 if (prefs_common.fw_quotemark && *prefs_common.fw_quotemark)
1049 qmark = prefs_common.fw_quotemark;
1053 quote_str = compose_quote_fmt(compose, msginfo,
1054 prefs_common.fw_quotefmt, qmark);
1055 compose_attach_parts(compose, msginfo);
1058 if (prefs_common.auto_sig)
1059 compose_insert_sig(compose);
1061 if (prefs_common.linewrap_quote)
1062 compose_wrap_line_all(compose);
1064 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1065 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1067 gtk_stext_thaw(text);
1068 #if 0 /* NEW COMPOSE GUI */
1069 if (account->protocol != A_NNTP)
1070 gtk_widget_grab_focus(compose->to_entry);
1072 gtk_widget_grab_focus(compose->newsgroups_entry);
1074 gtk_widget_grab_focus(compose->header_last->entry);
1076 if (prefs_common.auto_exteditor)
1077 compose_exec_ext_editor(compose);
1082 #undef INSERT_FW_HEADER
1084 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1091 g_return_val_if_fail(msginfo_list != NULL, NULL);
1093 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1094 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1098 if (account == NULL) {
1099 account = cur_account;
1101 account = msginfo->folder->folder->account;
1102 if (!account) account = cur_account;
1105 g_return_val_if_fail(account != NULL, NULL);
1107 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1108 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1109 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1110 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1113 compose = compose_create(account, COMPOSE_FORWARD);
1115 text = GTK_STEXT(compose->text);
1116 gtk_stext_freeze(text);
1118 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1119 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1120 if (!is_file_exist(msgfile))
1121 g_warning(_("%s: file not exist\n"), msgfile);
1123 compose_attach_append(compose, msgfile,
1124 MIME_MESSAGE_RFC822);
1128 if (prefs_common.auto_sig)
1129 compose_insert_sig(compose);
1131 if (prefs_common.linewrap_quote)
1132 compose_wrap_line_all(compose);
1134 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1135 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1137 gtk_stext_thaw(text);
1138 #if 0 /* NEW COMPOSE GUI */
1139 if (account->protocol != A_NNTP)
1140 gtk_widget_grab_focus(compose->to_entry);
1142 gtk_widget_grab_focus(compose->newsgroups_entry);
1148 void compose_reedit(MsgInfo *msginfo)
1151 PrefsAccount *account;
1154 gchar buf[BUFFSIZE];
1156 g_return_if_fail(msginfo != NULL);
1157 g_return_if_fail(msginfo->folder != NULL);
1159 account = msginfo->folder->folder->account;
1161 if(!account&& prefs_common.reedit_account_autosel) {
1162 gchar from[BUFFSIZE];
1163 if(!get_header_from_msginfo(msginfo,from,sizeof(from),"FROM:")){ /* Found a FROM header */
1164 extract_address(from);
1165 account = account_find_from_address(from);
1168 if (!account) account = cur_account;
1169 g_return_if_fail(account != NULL);
1171 compose = compose_create(account, COMPOSE_REEDIT);
1172 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1174 if (compose_parse_header(compose, msginfo) < 0) return;
1175 compose_reedit_set_entry(compose, msginfo);
1177 text = GTK_STEXT(compose->text);
1178 gtk_stext_freeze(text);
1180 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1181 g_warning(_("Can't get text part\n"));
1183 while (fgets(buf, sizeof(buf), fp) != NULL)
1184 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1187 compose_attach_parts(compose, msginfo);
1189 gtk_stext_thaw(text);
1190 gtk_widget_grab_focus(compose->text);
1192 if (prefs_common.auto_exteditor)
1193 compose_exec_ext_editor(compose);
1196 GList *compose_get_compose_list(void)
1198 return compose_list;
1201 void compose_entry_append(Compose *compose, const gchar *address,
1202 ComposeEntryType type)
1208 if (!address || *address == '\0') return;
1210 #if 0 /* NEW COMPOSE GUI */
1213 entry = GTK_ENTRY(compose->cc_entry);
1216 entry = GTK_ENTRY(compose->bcc_entry);
1218 case COMPOSE_NEWSGROUPS:
1219 entry = GTK_ENTRY(compose->newsgroups_entry);
1223 entry = GTK_ENTRY(compose->to_entry);
1227 text = gtk_entry_get_text(entry);
1229 gtk_entry_append_text(entry, ", ");
1230 gtk_entry_append_text(entry, address);
1238 header = N_("Bcc:");
1240 case COMPOSE_REPLYTO:
1241 header = N_("Reply-To:");
1243 case COMPOSE_NEWSGROUPS:
1244 header = N_("Newsgroups:");
1246 case COMPOSE_FOLLOWUPTO:
1247 header = N_( "Followup-To:");
1254 header = prefs_common.trans_hdr ? gettext(header) : header;
1256 compose_add_header_entry(compose, header, (gchar *)address);
1259 static void compose_entries_set(Compose *compose, const gchar *mailto)
1261 gchar *subject = NULL;
1269 Xstrdup_a(tmp_mailto, mailto, return);
1273 p = strchr(tmp_mailto, '?');
1280 gchar *field, *value;
1297 if (*value == '\0') continue;
1299 if (!g_strcasecmp(field, "subject")) {
1300 Xalloca(subject, strlen(value) + 1, return);
1301 decode_uri(subject, value);
1302 } else if (!g_strcasecmp(field, "cc")) {
1304 } else if (!g_strcasecmp(field, "bcc")) {
1306 } else if (!g_strcasecmp(field, "body")) {
1307 Xalloca(body, strlen(value) + 1, return);
1308 decode_uri(body, value);
1313 compose_entry_append(compose, to, COMPOSE_TO);
1315 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1317 compose_entry_append(compose, cc, COMPOSE_CC);
1319 compose_entry_append(compose, bcc, COMPOSE_BCC);
1321 gtk_stext_insert(GTK_STEXT(compose->text),
1322 NULL, NULL, NULL, body, -1);
1323 gtk_stext_insert(GTK_STEXT(compose->text),
1324 NULL, NULL, NULL, "\n", 1);
1328 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1330 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1331 {"Cc:", NULL, FALSE},
1332 {"References:", NULL, FALSE},
1333 {"Bcc:", NULL, FALSE},
1334 {"Newsgroups:", NULL, FALSE},
1335 {"Followup-To:", NULL, FALSE},
1336 {"X-Mailing-List:", NULL, FALSE},
1337 {"X-BeenThere:", NULL, FALSE},
1338 {NULL, NULL, FALSE}};
1348 H_X_MAILING_LIST = 6,
1354 g_return_val_if_fail(msginfo != NULL, -1);
1356 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1357 procheader_get_header_fields(fp, hentry);
1360 if (hentry[H_REPLY_TO].body != NULL) {
1361 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1362 compose->replyto = hentry[H_REPLY_TO].body;
1363 hentry[H_REPLY_TO].body = NULL;
1365 if (hentry[H_CC].body != NULL) {
1366 conv_unmime_header_overwrite(hentry[H_CC].body);
1367 compose->cc = hentry[H_CC].body;
1368 hentry[H_CC].body = NULL;
1370 if (hentry[H_X_MAILING_LIST].body != NULL) {
1371 /* this is good enough to parse debian-devel */
1372 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1373 g_return_val_if_fail(buf != NULL, -1 );
1374 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1375 compose->mailinglist = g_strdup(buf);
1377 g_free(hentry[H_X_MAILING_LIST].body);
1378 hentry[H_X_MAILING_LIST].body = NULL ;
1380 if (hentry[H_X_BEENTHERE].body != NULL) {
1381 /* this is good enough to parse the sylpheed-claws lists */
1382 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1383 g_return_val_if_fail(buf != NULL, -1 );
1384 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1385 compose->mailinglist = g_strdup(buf);
1387 g_free(hentry[H_X_BEENTHERE].body);
1388 hentry[H_X_BEENTHERE].body = NULL ;
1390 if (hentry[H_REFERENCES].body != NULL) {
1391 if (compose->mode == COMPOSE_REEDIT)
1392 compose->references = hentry[H_REFERENCES].body;
1394 compose->references = compose_parse_references
1395 (hentry[H_REFERENCES].body, msginfo->msgid);
1396 g_free(hentry[H_REFERENCES].body);
1398 hentry[H_REFERENCES].body = NULL;
1400 if (hentry[H_BCC].body != NULL) {
1401 if (compose->mode == COMPOSE_REEDIT) {
1402 conv_unmime_header_overwrite(hentry[H_BCC].body);
1403 compose->bcc = hentry[H_BCC].body;
1405 g_free(hentry[H_BCC].body);
1406 hentry[H_BCC].body = NULL;
1408 if (hentry[H_NEWSGROUPS].body != NULL) {
1409 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1410 hentry[H_NEWSGROUPS].body = NULL;
1412 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1413 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1414 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1415 hentry[H_FOLLOWUP_TO].body = NULL;
1418 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1419 compose->inreplyto = g_strdup(msginfo->inreplyto);
1420 else if (compose->mode != COMPOSE_REEDIT &&
1421 msginfo->msgid && *msginfo->msgid) {
1422 compose->inreplyto = g_strdup(msginfo->msgid);
1424 if (!compose->references) {
1425 if (msginfo->inreplyto && *msginfo->inreplyto)
1426 compose->references =
1427 g_strdup_printf("<%s>\n\t<%s>",
1431 compose->references =
1432 g_strconcat("<", msginfo->msgid, ">",
1440 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1442 GSList *ref_id_list, *cur;
1446 ref_id_list = references_list_append(NULL, ref);
1447 if (!ref_id_list) return NULL;
1448 if (msgid && *msgid)
1449 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1454 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1455 /* "<" + Message-ID + ">" + CR+LF+TAB */
1456 len += strlen((gchar *)cur->data) + 5;
1458 if (len > MAX_REFERENCES_LEN) {
1459 /* remove second message-ID */
1460 if (ref_id_list && ref_id_list->next &&
1461 ref_id_list->next->next) {
1462 g_free(ref_id_list->next->data);
1463 ref_id_list = g_slist_remove
1464 (ref_id_list, ref_id_list->next->data);
1466 slist_free_strings(ref_id_list);
1467 g_slist_free(ref_id_list);
1474 new_ref = g_string_new("");
1475 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1476 if (new_ref->len > 0)
1477 g_string_append(new_ref, "\n\t");
1478 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1481 slist_free_strings(ref_id_list);
1482 g_slist_free(ref_id_list);
1484 new_ref_str = new_ref->str;
1485 g_string_free(new_ref, FALSE);
1490 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1491 const gchar *fmt, const gchar *qmark)
1493 GtkSText *text = GTK_STEXT(compose->text);
1494 gchar *quote_str = NULL;
1499 if (qmark != NULL) {
1500 quote_fmt_init(msginfo, NULL);
1501 quote_fmt_scan_string(qmark);
1504 buf = quote_fmt_get_buffer();
1506 alertpanel_error(_("Quote mark format error."));
1508 Xstrdup_a(quote_str, buf, return NULL)
1511 quote_fmt_init(msginfo, quote_str);
1512 quote_fmt_scan_string(fmt);
1515 buf = quote_fmt_get_buffer();
1517 alertpanel_error(_("Message reply/forward format error."));
1521 gtk_stext_freeze(text);
1522 gtk_stext_set_point(text, 0);
1523 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
1525 for (p = buf; *p != '\0'; ) {
1526 lastp = strchr(p, '\n');
1527 len = lastp ? lastp - p + 1 : -1;
1528 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1535 gtk_stext_thaw(text);
1540 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1541 gboolean to_all, gboolean ignore_replyto,
1542 gboolean followup_and_reply_to)
1547 GHashTable *to_table;
1549 g_return_if_fail(compose->account != NULL);
1550 g_return_if_fail(msginfo != NULL);
1552 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1553 compose_entry_append(compose,
1554 ((compose->mailinglist && !ignore_replyto)
1555 ? compose->mailinglist
1556 : (compose->replyto && !ignore_replyto)
1558 : msginfo->from ? msginfo->from : ""),
1560 if (compose->account->protocol == A_NNTP) {
1562 compose_entry_append
1563 (compose, msginfo->from ? msginfo->from : "",
1566 compose_entry_append
1568 compose->followup_to ? compose->followup_to
1569 : compose->newsgroups ? compose->newsgroups
1571 COMPOSE_NEWSGROUPS);
1574 if (msginfo->subject && *msginfo->subject) {
1575 gchar *buf, *buf2, *p;
1577 buf = g_strdup(msginfo->subject);
1578 while (!strncasecmp(buf, "Re:", 3)) {
1580 while (isspace(*p)) p++;
1581 memmove(buf, p, strlen(p) + 1);
1584 buf2 = g_strdup_printf("Re: %s", buf);
1585 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1589 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1591 if (!to_all || compose->account->protocol == A_NNTP) return;
1593 from = g_strdup(compose->replyto ? compose->replyto :
1594 msginfo->from ? msginfo->from : "");
1595 extract_address(from);
1597 cc_list = address_list_append(NULL, msginfo->to);
1598 cc_list = address_list_append(cc_list, compose->cc);
1600 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1601 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1602 if (compose->account)
1603 g_hash_table_insert(to_table, compose->account->address,
1604 GINT_TO_POINTER(1));
1606 /* remove address on To: and that of current account */
1607 for (cur = cc_list; cur != NULL; ) {
1608 GSList *next = cur->next;
1610 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1611 cc_list = g_slist_remove(cc_list, cur->data);
1613 g_hash_table_insert(to_table, cur->data, cur);
1617 g_hash_table_destroy(to_table);
1621 for (cur = cc_list; cur != NULL; cur = cur->next)
1622 compose_entry_append(compose, (gchar *)cur->data,
1624 slist_free_strings(cc_list);
1625 g_slist_free(cc_list);
1629 #define SET_ENTRY(entry, str) \
1632 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1635 #define SET_ADDRESS(type, str) \
1638 compose_entry_append(compose, str, type); \
1641 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1643 g_return_if_fail(msginfo != NULL);
1645 SET_ENTRY(subject_entry, msginfo->subject);
1646 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1647 SET_ADDRESS(COMPOSE_CC, compose->cc);
1648 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1649 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1651 #if 0 /* NEW COMPOSE GUI */
1653 GtkItemFactory *ifactory;
1654 GtkWidget *menuitem;
1656 ifactory = gtk_item_factory_from_widget(compose->menubar);
1657 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1658 gtk_check_menu_item_set_active
1659 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1661 if (compose->replyto) {
1662 GtkItemFactory *ifactory;
1663 GtkWidget *menuitem;
1665 ifactory = gtk_item_factory_from_widget(compose->menubar);
1666 menuitem = gtk_item_factory_get_item
1667 (ifactory, "/Message/Reply to");
1668 gtk_check_menu_item_set_active
1669 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1677 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1684 size_t buf_len = 128;
1686 if (strlen(sigfile) < 2)
1689 sigprg = popen(sigfile+1, "r");
1692 buf = g_malloc(buf_len);
1695 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1696 "Unable to insert signature (malloc failed)\n", -1);
1702 while (!feof(sigprg)) {
1703 bzero(buf, buf_len);
1704 fread(buf, buf_len-1, 1, sigprg);
1705 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1713 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1714 "Can't exec file: ", -1);
1715 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1720 static void compose_insert_sig(Compose *compose)
1724 if (compose->account && compose->account->sig_path)
1725 sigfile = g_strdup(compose->account->sig_path);
1727 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1728 DEFAULT_SIGNATURE, NULL);
1731 if (!is_file_or_fifo_exist(sigfile) & (sigfile[0] != '|')) {
1736 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1737 if (prefs_common.sig_sep) {
1738 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1739 prefs_common.sig_sep, -1);
1740 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1744 if (sigfile[0] == '|')
1746 compose_exec_sig(compose, sigfile);
1750 compose_insert_file(compose, sigfile);
1755 static void compose_insert_file(Compose *compose, const gchar *file)
1757 GtkSText *text = GTK_STEXT(compose->text);
1758 gchar buf[BUFFSIZE];
1762 g_return_if_fail(file != NULL);
1764 if ((fp = fopen(file, "r")) == NULL) {
1765 FILE_OP_ERROR(file, "fopen");
1769 gtk_stext_freeze(text);
1771 while (fgets(buf, sizeof(buf), fp) != NULL) {
1772 /* Strip <CR> if DOS/Windoze file, replace <CR> with <LF> if MAC file */
1774 if (len > 1 && buf[len - 2] == '\r' && buf[len - 1] == '\n') {
1775 buf[len - 2] = '\n';
1776 buf[len - 1] = '\0';
1779 if (buf[len] == '\r')
1783 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1786 gtk_stext_thaw(text);
1791 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1792 ContentType cnttype)
1794 gchar *text[N_ATTACH_COLS];
1797 text[COL_MIMETYPE] = ainfo->content_type;
1798 text[COL_SIZE] = to_human_readable(ainfo->size);
1799 text[COL_NAME] = ainfo->name;
1801 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1802 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1804 if (cnttype != MIME_MESSAGE_RFC822)
1805 compose_changed_cb(NULL, compose);
1808 static void compose_attach_append_with_type(Compose *compose,
1811 ContentType cnttype)
1816 if (!is_file_exist(file)) {
1817 g_warning(_("File %s doesn't exist\n"), file);
1820 if ((size = get_file_size(file)) < 0) {
1821 g_warning(_("Can't get file size of %s\n"), file);
1825 alertpanel_notice(_("File %s is empty\n"), file);
1828 #if 0 /* NEW COMPOSE GUI */
1829 if (!compose->use_attach) {
1830 GtkItemFactory *ifactory;
1831 GtkWidget *menuitem;
1833 ifactory = gtk_item_factory_from_widget(compose->menubar);
1834 menuitem = gtk_item_factory_get_item(ifactory,
1836 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1840 ainfo = g_new0(AttachInfo, 1);
1841 ainfo->file = g_strdup(file);
1843 if (cnttype == MIME_MESSAGE_RFC822) {
1844 ainfo->encoding = ENC_7BIT;
1845 ainfo->name = g_strdup_printf(_("Message: %s"),
1848 ainfo->encoding = ENC_BASE64;
1849 ainfo->name = g_strdup(g_basename(file));
1852 ainfo->content_type = g_strdup(type);
1855 compose_attach_info(compose, ainfo, cnttype);
1858 static void compose_attach_append(Compose *compose, const gchar *file,
1859 ContentType cnttype)
1862 gchar *text[N_ATTACH_COLS];
1866 if (!is_file_exist(file)) {
1867 g_warning(_("File %s doesn't exist\n"), file);
1870 if ((size = get_file_size(file)) < 0) {
1871 g_warning(_("Can't get file size of %s\n"), file);
1875 alertpanel_notice(_("File %s is empty\n"), file);
1878 #if 0 /* NEW COMPOSE GUI */
1879 if (!compose->use_attach) {
1880 GtkItemFactory *ifactory;
1881 GtkWidget *menuitem;
1883 ifactory = gtk_item_factory_from_widget(compose->menubar);
1884 menuitem = gtk_item_factory_get_item(ifactory,
1886 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1890 ainfo = g_new0(AttachInfo, 1);
1891 ainfo->file = g_strdup(file);
1893 if (cnttype == MIME_MESSAGE_RFC822) {
1894 ainfo->content_type = g_strdup("message/rfc822");
1895 ainfo->encoding = ENC_7BIT;
1896 ainfo->name = g_strdup_printf(_("Message: %s"),
1899 ainfo->content_type = procmime_get_mime_type(file);
1900 if (!ainfo->content_type)
1901 ainfo->content_type =
1902 g_strdup("application/octet-stream");
1903 ainfo->encoding = ENC_BASE64;
1904 ainfo->name = g_strdup(g_basename(file));
1908 compose_attach_info(compose, ainfo, cnttype);
1911 static void compose_wrap_line(Compose *compose)
1913 GtkSText *text = GTK_STEXT(compose->text);
1914 gint ch_len, last_ch_len;
1915 gchar cbuf[MB_LEN_MAX], last_ch;
1919 gint p_start, p_end;
1920 gint line_pos, cur_pos;
1921 gint line_len, cur_len;
1923 #define GET_STEXT(pos) \
1924 if (text->use_wchar) \
1925 ch_len = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
1927 cbuf[0] = GTK_STEXT_INDEX(text, (pos)); \
1931 gtk_stext_freeze(text);
1933 text_len = gtk_stext_get_length(text);
1935 /* check to see if the point is on the paragraph mark (empty line). */
1936 cur_pos = gtk_stext_get_point(text);
1938 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
1940 goto compose_end; /* on the paragraph mark */
1941 GET_STEXT(cur_pos - 1);
1942 if (ch_len == 1 && *cbuf == '\n')
1943 goto compose_end; /* on the paragraph mark */
1946 /* find paragraph start. */
1947 line_end = quoted = 0;
1948 for (p_start = cur_pos; p_start >= 0; --p_start) {
1950 if (ch_len == 1 && *cbuf == '\n') {
1952 goto compose_end; /* quoted part */
1959 if (ch_len == 1 && strchr(">:#", *cbuf))
1961 else if (ch_len != 1 || !isspace(*cbuf))
1970 /* find paragraph end. */
1972 for (p_end = cur_pos; p_end < text_len; p_end++) {
1974 if (ch_len == 1 && *cbuf == '\n') {
1981 if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
1982 goto compose_end; /* quoted part */
1987 if (p_end >= text_len)
1990 if (p_start >= p_end)
1993 line_len = cur_len = 0;
1997 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2007 if (ch_len == 1 && isspace(*cbuf))
2010 if (ch_len == 1 && *cbuf == '\n') {
2012 if (last_ch_len == 1 && !isspace(last_ch)) {
2013 if (cur_pos + 1 < p_end) {
2014 GET_STEXT(cur_pos + 1);
2015 if (ch_len == 1 && !isspace(*cbuf))
2019 gtk_stext_set_point(text, cur_pos + 1);
2020 gtk_stext_backward_delete(text, 1);
2022 gtk_stext_set_point(text, cur_pos);
2023 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2033 last_ch_len = ch_len;
2037 line_pos = cur_pos + 1;
2038 line_len = cur_len + ch_len;
2041 if (cur_len + ch_len > prefs_common.linewrap_len &&
2045 GET_STEXT(line_pos - 1);
2046 if (ch_len == 1 && isspace(*cbuf)) {
2047 gtk_stext_set_point(text, line_pos);
2048 gtk_stext_backward_delete(text, 1);
2057 gtk_stext_set_point(text, line_pos);
2058 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2062 cur_len = cur_len - line_len + ch_len;
2068 line_pos = cur_pos + 1;
2069 line_len = cur_len + ch_len;
2075 gtk_stext_thaw(text);
2080 /* return indent length */
2081 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2083 gint indent_len = 0;
2085 gchar cbuf[MB_LEN_MAX];
2087 for (i = start_pos; i < text_len; i++) {
2088 if (text->use_wchar)
2090 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, i));
2092 cbuf[0] = GTK_STEXT_INDEX(text, i);
2097 /* allow space, tab, > or | */
2098 if (cbuf[0] != ' ' && cbuf[0] != '\t' &&
2099 cbuf[0] != '>' && cbuf[0] != '|')
2107 /* insert quotation string when line was wrapped */
2108 static guint ins_quote(GtkSText *text, guint quote_len, guint indent_len,
2109 guint prev_line_pos, guint text_len,
2116 for (i = 0; i < indent_len; i++) {
2117 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2118 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2120 ins_len = indent_len;
2123 gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
2124 ins_len = quote_len;
2132 /* Darko: used when I debug wrapping */
2133 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2138 printf("%d [", pos);
2139 for (i = pos; i < tlen; i++) {
2140 ch = GTK_STEXT_INDEX(text, i);
2141 if (breakoncr && ch == '\n')
2149 static void compose_wrap_line_all(Compose *compose)
2151 GtkSText *text = GTK_STEXT(compose->text);
2153 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2154 gint line_len = 0, cur_len = 0;
2156 gint is_new_line = 1, do_delete = 0;
2157 guint qlen = 0, i_len = 0;
2158 guint linewrap_quote = prefs_common.linewrap_quote;
2159 guint linewrap_len = prefs_common.linewrap_len;
2160 gchar *qfmt = prefs_common.quotemark;
2161 gchar cbuf[MB_LEN_MAX];
2163 gtk_stext_freeze(text);
2165 /* make text buffer contiguous */
2166 /* gtk_stext_compact_buffer(text); */
2168 tlen = gtk_stext_get_length(text);
2170 for (; cur_pos < tlen; cur_pos++) {
2171 /* mark position of new line - needed for quotation wrap */
2172 if (linewrap_quote && is_new_line) {
2173 qlen = gtkut_text_str_compare
2174 (text, cur_pos, tlen, qfmt);
2177 i_len = get_indent_length(text, cur_pos, tlen);
2182 printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
2183 dump_text(text, p_pos, tlen, 1);
2187 /* get character(s) at current position */
2188 if (text->use_wchar)
2190 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2192 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
2196 /* fix line length for tabs */
2197 if (ch_len == 1 && *cbuf == '\t') {
2198 guint tab_width = text->default_tab_width;
2199 guint tab_offset = line_len % tab_width;
2202 printf("found tab at pos=%d line_len=%d ", cur_pos,
2206 line_len += tab_width - tab_offset - 1;
2210 printf("new_len=%d\n", line_len);
2214 /* we have encountered line break */
2215 if (ch_len == 1 && *cbuf == '\n') {
2218 gchar cb[MB_CUR_MAX];
2221 printf("found CR at %d next line is ", cur_pos);
2222 dump_text(text, cur_pos + 1, tlen, 1);
2224 /* if it's just quotation + newline skip it */
2225 if (i_len && (cur_pos + 1 < tlen)) {
2226 /* check if text at new line matches indent */
2227 ilen = gtkut_text_str_compare_n
2228 (text, cur_pos + 1, p_pos, i_len, tlen);
2229 if (cur_pos + ilen < tlen) {
2230 if (text->use_wchar)
2231 clen = wctomb(cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos + ilen + 1));
2233 cb[0] = GTK_STEXT_INDEX(text,
2234 cur_pos + ilen + 1);
2237 /* no need to join the lines */
2238 if ((clen == 1) && (cb[0] == '\n'))
2242 /* if it's just newline skip it */
2243 else if (do_delete && (cur_pos + 1 < tlen)) {
2244 if (text->use_wchar)
2245 clen = wctomb(cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos + 1));
2247 cb[0] = GTK_STEXT_INDEX(text,
2251 /* no need to join the lines */
2252 if ((clen == 1) && (cb[0] == '\n'))
2257 printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
2258 qlen, line_len, linewrap_len, do_delete);
2260 /* should we delete to perform smart wrapping */
2261 if (line_len < linewrap_len && do_delete) {
2262 /* get rid of newline */
2263 gtk_stext_set_point(text, cur_pos);
2264 gtk_stext_forward_delete(text, 1);
2267 /* if text starts with quote fmt or with
2268 indent string, delete them */
2270 ilen = gtkut_text_str_compare_n
2271 (text, cur_pos, p_pos, i_len,
2274 gtk_stext_forward_delete(text,
2279 if (gtkut_text_str_compare
2280 (text, cur_pos, tlen, qfmt)) {
2281 gtk_stext_forward_delete
2287 if (text->use_wchar)
2289 (cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2291 cb[0] = GTK_STEXT_INDEX(text, cur_pos);
2295 /* insert space if it's alphanumeric */
2296 if ((cur_pos != line_pos) &&
2297 ((clen > 1) || isalnum(cb[0]))) {
2298 gtk_stext_insert(text, NULL, NULL,
2300 /* gtk_text_compact_buffer(text); */
2304 /* and start over with current line */
2305 cur_pos = p_pos - 1;
2307 line_len = cur_len = 0;
2312 printf("after delete l_pos=");
2313 dump_text(text, line_pos, tlen, 1);
2318 /* mark new line beginning */
2319 line_pos = cur_pos + 1;
2320 line_len = cur_len = 0;
2332 /* possible line break */
2333 if (ch_len == 1 && isspace(*cbuf)) {
2334 line_pos = cur_pos + 1;
2335 line_len = cur_len + ch_len;
2338 /* are we over wrapping length set in preferences ? */
2339 if (cur_len + ch_len > linewrap_len) {
2343 printf("should wrap cur_pos=%d ", cur_pos);
2344 dump_text(text, p_pos, tlen, 1);
2345 dump_text(text, line_pos, tlen, 1);
2347 /* force wrapping if it is one long word but not URL */
2348 if (p_pos + i_len == line_pos)
2349 if (!gtkut_text_is_uri_string
2350 (text, line_pos, tlen))
2351 line_pos = cur_pos - 1;
2353 printf("new line_pos=%d\n", line_pos);
2356 /* if next character is space delete it */
2357 if (text->use_wchar)
2358 clen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
2360 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
2363 if (clen == 1 && isspace(*cbuf)) {
2364 if (p_pos + i_len != line_pos ||
2365 !gtkut_text_is_uri_string
2366 (text, line_pos, tlen)) {
2367 gtk_stext_set_point(text, line_pos);
2368 gtk_stext_backward_delete(text, 1);
2377 /* if it is URL at beginning of line don't wrap */
2378 if (p_pos + i_len == line_pos &&
2379 gtkut_text_is_uri_string(text, line_pos, tlen)) {
2381 printf("found URL at ");
2382 dump_text(text, line_pos, tlen, 1);
2388 gtk_stext_set_point(text, line_pos);
2389 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2390 /* gtk_stext_compact_buffer(text); */
2393 /* for loop will increase it */
2394 cur_pos = line_pos - 1;
2395 /* start over with current line */
2401 printf("after CR insert ");
2402 dump_text(text, line_pos, tlen, 1);
2403 dump_text(text, cur_pos, tlen, 1);
2406 /* should we insert quotation ? */
2407 if (linewrap_quote && qlen) {
2408 /* only if line is not already quoted */
2409 if (!gtkut_text_str_compare
2410 (text, line_pos, tlen, qfmt)) {
2413 if (line_pos - p_pos > i_len) {
2418 /* gtk_stext_compact_buffer(text); */
2422 printf("after quote insert ");
2423 dump_text(text, line_pos, tlen, 1);
2431 line_pos = cur_pos + 1;
2432 line_len = cur_len + ch_len;
2434 /* advance to next character in buffer */
2438 gtk_stext_thaw(text);
2442 static void compose_wrap_line_all(Compose *compose)
2444 GtkText *text = GTK_STEXT(compose->text);
2446 guint line_pos = 0, cur_pos = 0;
2447 gint line_len = 0, cur_len = 0;
2449 gchar cbuf[MB_LEN_MAX];
2451 gtk_stext_freeze(text);
2453 text_len = gtk_stext_get_length(text);
2455 for (; cur_pos < text_len; cur_pos++) {
2456 if (text->use_wchar)
2458 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2460 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
2464 if (ch_len == 1 && *cbuf == '\n') {
2465 line_pos = cur_pos + 1;
2466 line_len = cur_len = 0;
2475 if (ch_len == 1 && isspace(*cbuf)) {
2476 line_pos = cur_pos + 1;
2477 line_len = cur_len + ch_len;
2480 if (cur_len + ch_len > prefs_common.linewrap_len &&
2484 if (text->use_wchar)
2485 tlen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
2487 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
2490 if (tlen == 1 && isspace(*cbuf)) {
2491 gtk_stext_set_point(text, line_pos);
2492 gtk_stext_backward_delete(text, 1);
2500 gtk_stext_set_point(text, line_pos);
2501 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2505 cur_len = cur_len - line_len + ch_len;
2511 line_pos = cur_pos + 1;
2512 line_len = cur_len + ch_len;
2517 gtk_stext_thaw(text);
2521 static void compose_set_title(Compose *compose)
2526 edited = compose->modified ? _(" [Edited]") : "";
2527 if (compose->account && compose->account->address)
2528 str = g_strdup_printf(_("%s - Compose message%s"),
2529 compose->account->address, edited);
2531 str = g_strdup_printf(_("Compose message%s"), edited);
2532 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2537 * compose_current_mail_account:
2539 * Find a current mail account (the currently selected account, or the
2540 * default account, if a news account is currently selected). If a
2541 * mail account cannot be found, display an error message.
2543 * Return value: Mail account, or NULL if not found.
2545 static PrefsAccount *
2546 compose_current_mail_account(void)
2550 if (cur_account && cur_account->protocol != A_NNTP)
2553 ac = account_get_default();
2554 if (!ac || ac->protocol == A_NNTP) {
2555 alertpanel_error(_("Account for sending mail is not specified.\n"
2556 "Please select a mail account before sending."));
2563 gboolean compose_check_for_valid_recipient(Compose *compose) {
2564 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2565 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2566 gboolean recipient_found = FALSE;
2570 /* free to and newsgroup list */
2571 slist_free_strings(compose->to_list);
2572 g_slist_free(compose->to_list);
2573 compose->to_list = NULL;
2575 slist_free_strings(compose->newsgroup_list);
2576 g_slist_free(compose->newsgroup_list);
2577 compose->newsgroup_list = NULL;
2579 /* search header entries for to and newsgroup entries */
2580 for(list = compose->header_list; list; list = list->next) {
2583 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2584 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2586 if(entry[0] != '\0') {
2587 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2588 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2589 compose->to_list = address_list_append(compose->to_list, entry);
2590 recipient_found = TRUE;
2593 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2594 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2595 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2596 recipient_found = TRUE;
2602 return recipient_found;
2605 gint compose_send(Compose *compose)
2611 val = compose_queue(compose, &msgnum, &folder);
2613 alertpanel_error(_("Could not queue message for sending"));
2617 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2619 folder_item_remove_msg(folder, msgnum);
2620 folderview_update_item(folder, TRUE);
2626 #if 0 /* compose restructure */
2627 gint compose_send(Compose *compose)
2629 gchar tmp[MAXPATHLEN + 1];
2631 static gboolean lock = FALSE;
2635 g_return_val_if_fail(compose->account != NULL, -1);
2636 g_return_val_if_fail(compose->orig_account != NULL, -1);
2640 if(!compose_check_for_valid_recipient(compose)) {
2641 alertpanel_error(_("Recipient is not specified."));
2646 /* write to temporary file */
2647 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2648 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2650 if (prefs_common.linewrap_at_send)
2651 compose_wrap_line_all(compose);
2653 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2658 if (!compose->to_list && !compose->newsgroup_list) {
2659 g_warning(_("can't get recipient list."));
2665 if (compose->to_list) {
2668 #if 0 /* NEW COMPOSE GUI */
2669 if (compose->account->protocol != A_NNTP)
2670 ac = compose->account;
2671 else if (compose->orig_account->protocol != A_NNTP)
2672 ac = compose->orig_account;
2673 else if (cur_account && cur_account->protocol != A_NNTP)
2676 ac = compose_current_mail_account();
2684 ac = compose->account;
2686 ok = send_message(tmp, ac, compose->to_list);
2687 statusbar_pop_all();
2690 if (ok == 0 && compose->newsgroup_list) {
2693 if (compose->account->protocol == A_NNTP)
2694 folder = FOLDER(compose->account->folder);
2696 folder = FOLDER(compose->orig_account->folder);
2698 ok = news_post(folder, tmp);
2700 alertpanel_error(_("Error occurred while posting the message to %s ."),
2701 compose->account->nntp_server);
2708 /* queue message if failed to send */
2710 if (prefs_common.queue_msg) {
2715 _("Error occurred while sending the message.\n"
2716 "Put this message into queue folder?"),
2717 _("OK"), _("Cancel"), NULL);
2718 if (G_ALERTDEFAULT == val) {
2719 ok = compose_queue(compose, tmp);
2721 alertpanel_error(_("Can't queue the message."));
2724 alertpanel_error(_("Error occurred while sending the message."));
2726 if (compose->mode == COMPOSE_REEDIT) {
2727 compose_remove_reedit_target(compose);
2728 if (compose->targetinfo)
2729 folderview_update_item
2730 (compose->targetinfo->folder, TRUE);
2734 /* save message to outbox */
2735 if (ok == 0 && prefs_common.savemsg) {
2736 if (compose_save_to_outbox(compose, tmp) < 0)
2738 (_("Can't save the message to outbox."));
2747 static gboolean compose_use_attach(Compose *compose) {
2748 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2751 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2754 gchar buf[BUFFSIZE];
2756 gboolean first_address;
2758 ComposeHeaderEntry *headerentry;
2759 gchar *headerentryname;
2760 gchar *header_w_colon;
2764 debug_print(_("Writing bounce header\n"));
2766 header_w_colon = g_strconcat("To:", NULL);
2767 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2768 header_w_colon = g_strconcat("Cc:", NULL);
2769 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2771 first_address = TRUE;
2772 for(list = compose->header_list; list; list = list->next) {
2773 headerentry = ((ComposeHeaderEntry *)list->data);
2774 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2776 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2777 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2778 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2779 Xstrdup_a(str, str, return -1);
2781 if(str[0] != '\0') {
2782 compose_convert_header
2783 (buf, sizeof(buf), str,
2784 strlen("Resent-To") + 2);
2786 fprintf(fp, "Resent-To: ");
2787 first_address = FALSE;
2791 fprintf(fp, "%s", buf);
2795 /* if(!first_address) { */
2802 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2804 gchar buf[BUFFSIZE];
2806 /* struct utsname utsbuf; */
2808 g_return_val_if_fail(fp != NULL, -1);
2809 g_return_val_if_fail(compose->account != NULL, -1);
2810 g_return_val_if_fail(compose->account->address != NULL, -1);
2813 get_rfc822_date(buf, sizeof(buf));
2814 fprintf(fp, "Resent-Date: %s\n", buf);
2817 if (compose->account->name && *compose->account->name) {
2818 compose_convert_header
2819 (buf, sizeof(buf), compose->account->name,
2821 fprintf(fp, "Resent-From: %s <%s>\n",
2822 buf, compose->account->address);
2824 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2827 compose_bounce_write_headers_from_headerlist(compose, fp);
2829 /* separator between header and body */
2835 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2840 gchar buf[BUFFSIZE];
2842 if ((fp = fopen(compose->bounce_filename, "r")) == NULL) {
2843 FILE_OP_ERROR(file, "fopen");
2847 if ((fdest = fopen(file, "w")) == NULL) {
2848 FILE_OP_ERROR(file, "fopen");
2853 /* chmod for security */
2854 if (change_file_mode_rw(fdest, file) < 0) {
2855 FILE_OP_ERROR(file, "chmod");
2856 g_warning(_("can't change file mode\n"));
2859 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2860 /* should filter returnpath, delivered-to */
2861 if ((g_strncasecmp(buf, "Return-Path:",
2862 strlen("Return-Path:")) == 0)
2863 || (g_strncasecmp(buf, "Delivered-To:",
2864 strlen("Delivered-To:")) == 0))
2866 if (fputs(buf, fdest) == -1)
2868 if (fputs("\n", fdest) == -1)
2872 compose_bounce_write_headers(compose, fdest);
2874 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
2875 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
2890 static gint compose_write_to_file(Compose *compose, const gchar *file,
2897 const gchar *out_codeset;
2898 EncodingType encoding;
2900 if ((fp = fopen(file, "w")) == NULL) {
2901 FILE_OP_ERROR(file, "fopen");
2905 /* chmod for security */
2906 if (change_file_mode_rw(fp, file) < 0) {
2907 FILE_OP_ERROR(file, "chmod");
2908 g_warning(_("can't change file mode\n"));
2911 /* get all composed text */
2912 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2913 len = strlen(chars);
2914 if (is_ascii_str(chars)) {
2915 buf = g_strdup(chars);
2916 out_codeset = CS_US_ASCII;
2917 encoding = ENC_7BIT;
2919 const gchar *src_codeset;
2921 out_codeset = conv_get_outgoing_charset_str();
2922 if (!strcasecmp(out_codeset, CS_US_ASCII))
2923 out_codeset = CS_ISO_8859_1;
2924 encoding = procmime_get_encoding_for_charset(out_codeset);
2926 src_codeset = conv_get_current_charset_str();
2927 /* if current encoding is US-ASCII, set it the same as
2928 outgoing one to prevent code conversion failure */
2929 if (!strcasecmp(src_codeset, CS_US_ASCII))
2930 src_codeset = out_codeset;
2932 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
2933 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
2935 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
2940 alertpanel_error(_("Can't convert the codeset of the message."));
2947 if (compose_write_headers
2948 (compose, fp, out_codeset, encoding, is_draft) < 0) {
2949 g_warning(_("can't write headers\n"));
2956 if (compose_use_attach(compose)) {
2958 /* This prolog message is ignored by mime software and
2959 * because it would make our signing/encryption task
2960 * tougher, we don't emit it in that case */
2961 if (!compose->use_signing && !compose->use_encryption)
2963 fputs("This is a multi-part message in MIME format.\n", fp);
2965 fprintf(fp, "\n--%s\n", compose->boundary);
2966 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
2968 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2969 procmime_get_encoding_str(encoding));
2975 if (encoding == ENC_BASE64) {
2976 gchar outbuf[B64_BUFFSIZE];
2979 for (i = 0; i < len; i += B64_LINE_SIZE) {
2980 l = MIN(B64_LINE_SIZE, len - i);
2981 to64frombits(outbuf, buf + i, l);
2985 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
2986 FILE_OP_ERROR(file, "fwrite");
2994 if (compose_use_attach(compose))
2995 compose_write_attach(compose, fp);
2997 if (fclose(fp) == EOF) {
2998 FILE_OP_ERROR(file, "fclose");
3004 if (compose->use_signing) {
3005 if (rfc2015_sign(file, compose->account) < 0) {
3010 if (compose->use_encryption) {
3011 if (rfc2015_encrypt(file, compose->to_list) < 0) {
3016 #endif /* USE_GPGME */
3021 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3027 if ((fp = fopen(file, "w")) == NULL) {
3028 FILE_OP_ERROR(file, "fopen");
3032 /* chmod for security */
3033 if (change_file_mode_rw(fp, file) < 0) {
3034 FILE_OP_ERROR(file, "chmod");
3035 g_warning(_("can't change file mode\n"));
3038 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3041 len = strlen(chars);
3042 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3043 FILE_OP_ERROR(file, "fwrite");
3052 if (fclose(fp) == EOF) {
3053 FILE_OP_ERROR(file, "fclose");
3060 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
3067 debug_print(_("saving sent message...\n"));
3069 outbox = folder_get_default_outbox();
3070 path = folder_item_get_path(outbox);
3071 if (!is_dir_exist(path))
3072 make_dir_hier(path);
3074 folder_item_scan(outbox);
3075 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
3077 g_warning(_("can't save message\n"));
3081 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
3082 g_warning(_("can't open mark file\n"));
3086 newmsginfo.msgnum = num;
3087 newmsginfo.flags.perm_flags = 0;
3088 newmsginfo.flags.tmp_flags = 0;
3089 procmsg_write_flags(&newmsginfo, fp);
3097 static gint compose_remove_reedit_target(Compose *compose)
3100 MsgInfo *msginfo = compose->targetinfo;
3102 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3103 if (!msginfo) return -1;
3105 item = msginfo->folder;
3106 g_return_val_if_fail(item != NULL, -1);
3108 folder_item_scan(item);
3109 if (procmsg_msg_exist(msginfo) &&
3110 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3111 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3112 g_warning(_("can't remove the old message\n"));
3121 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3124 gchar *tmp, *tmp2, *queue_path;
3127 gchar buf[BUFFSIZE];
3129 static gboolean lock = FALSE;
3130 PrefsAccount *mailac = NULL, *newsac = NULL;
3132 debug_print(_("queueing message...\n"));
3133 g_return_val_if_fail(compose->account != NULL, -1);
3134 g_return_val_if_fail(compose->orig_account != NULL, -1);
3138 if(!compose_check_for_valid_recipient(compose)) {
3139 alertpanel_error(_("Recipient is not specified."));
3144 if (!compose->to_list && !compose->newsgroup_list) {
3145 g_warning(_("can't get recipient list."));
3150 if(compose->to_list) {
3151 if (compose->account->protocol != A_NNTP)
3152 mailac = compose->account;
3153 else if (compose->orig_account->protocol != A_NNTP)
3154 mailac = compose->orig_account;
3155 else if (cur_account && cur_account->protocol != A_NNTP)
3156 mailac = cur_account;
3157 else if (!(mailac = compose_current_mail_account())) {
3159 alertpanel_error(_("No account for sending mails available!"));
3164 if(compose->newsgroup_list) {
3165 if (compose->account->protocol == A_NNTP)
3166 newsac = compose->account;
3167 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3169 alertpanel_error(_("No account for posting news available!"));
3174 if (prefs_common.linewrap_at_send)
3175 compose_wrap_line_all(compose);
3177 /* write to temporary file */
3178 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3179 G_DIR_SEPARATOR, (gint)compose);
3181 if (compose->bounce_filename != NULL) {
3182 if (compose_bounce_write_to_file(compose, tmp2) < 0) {
3189 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3196 /* add queue header */
3197 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3198 G_DIR_SEPARATOR, (gint)compose);
3199 if ((fp = fopen(tmp, "w")) == NULL) {
3200 FILE_OP_ERROR(tmp, "fopen");
3204 if ((src_fp = fopen(tmp2, "r")) == NULL) {
3205 FILE_OP_ERROR(tmp2, "fopen");
3213 if (change_file_mode_rw(fp, tmp) < 0) {
3214 FILE_OP_ERROR(tmp, "chmod");
3215 g_warning(_("can't change file mode\n"));
3218 /* queueing variables */
3219 fprintf(fp, "AF:\n");
3220 fprintf(fp, "NF:0\n");
3221 fprintf(fp, "PS:10\n");
3222 fprintf(fp, "SRH:1\n");
3223 fprintf(fp, "SFN:\n");
3224 fprintf(fp, "DSR:\n");
3226 fprintf(fp, "MID:<%s>\n", compose->msgid);
3228 fprintf(fp, "MID:\n");
3229 fprintf(fp, "CFG:\n");
3230 fprintf(fp, "PT:0\n");
3231 fprintf(fp, "S:%s\n", compose->account->address);
3232 fprintf(fp, "RQ:\n");
3234 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3236 fprintf(fp, "SSV:\n");
3238 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3240 fprintf(fp, "NSV:\n");
3241 fprintf(fp, "SSH:\n");
3242 /* write recepient list */
3244 if(compose->to_list) {
3245 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3246 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3247 fprintf(fp, ",<%s>", (gchar *)cur->data);
3250 /* write newsgroup list */
3252 if(compose->newsgroup_list) {
3253 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3254 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3255 fprintf(fp, ",%s", (gchar *)cur->data);
3258 /* Sylpheed account IDs */
3260 fprintf(fp, "MAID:%d\n", mailac->account_id);
3263 fprintf(fp, "NAID:%d\n", newsac->account_id);
3267 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3268 if (fputs(buf, fp) == EOF) {
3269 FILE_OP_ERROR(tmp, "fputs");
3280 if (fclose(fp) == EOF) {
3281 FILE_OP_ERROR(tmp, "fclose");
3290 queue = folder_get_default_queue();
3292 folder_item_scan(queue);
3293 queue_path = folder_item_get_path(queue);
3294 if (!is_dir_exist(queue_path))
3295 make_dir_hier(queue_path);
3296 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3297 g_warning(_("can't queue the message\n"));
3308 if (compose->mode == COMPOSE_REEDIT) {
3309 compose_remove_reedit_target(compose);
3310 if (compose->targetinfo &&
3311 compose->targetinfo->folder != queue)
3312 folderview_update_item
3313 (compose->targetinfo->folder, TRUE);
3316 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
3317 g_warning(_("can't open mark file\n"));
3321 newmsginfo.msgnum = num;
3322 newmsginfo.flags.perm_flags = 0;
3323 newmsginfo.flags.tmp_flags = 0;
3324 procmsg_write_flags(&newmsginfo, fp);
3329 folder_item_scan(queue);
3330 folderview_update_item(queue, TRUE);
3332 if((msgnum != NULL) && (item != NULL)) {
3340 static void compose_write_attach(Compose *compose, FILE *fp)
3343 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3346 gchar filename[BUFFSIZE];
3349 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3351 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
3352 g_warning(_("Can't open file %s\n"), ainfo->file);
3356 fprintf(fp, "\n--%s\n", compose->boundary);
3358 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3359 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3360 fprintf(fp, "Content-Disposition: inline\n");
3362 conv_encode_header(filename, sizeof(filename),
3364 fprintf(fp, "Content-Type: %s;\n"
3366 ainfo->content_type, filename);
3367 fprintf(fp, "Content-Disposition: attachment;\n"
3368 " filename=\"%s\"\n", filename);
3371 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3372 procmime_get_encoding_str(ainfo->encoding));
3374 if (ainfo->encoding == ENC_7BIT) {
3375 gchar buf[BUFFSIZE];
3377 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3382 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3384 while ((len = fread(inbuf, sizeof(gchar),
3385 B64_LINE_SIZE, attach_fp))
3387 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3391 if (len > 0 && feof(attach_fp)) {
3392 to64frombits(outbuf, inbuf, len);
3401 fprintf(fp, "\n--%s--\n", compose->boundary);
3404 #define IS_IN_CUSTOM_HEADER(header) \
3405 (compose->account->add_customhdr && \
3406 custom_header_find(compose->account->customhdr_list, header) != NULL)
3408 static gint compose_write_headers_from_headerlist(Compose *compose,
3412 gchar buf[BUFFSIZE];
3413 gchar *str, *header_w_colon, *trans_hdr;
3414 gboolean first_address;
3416 ComposeHeaderEntry *headerentry;
3417 gchar * headerentryname;
3419 if (IS_IN_CUSTOM_HEADER(header)) {
3423 debug_print(_("Writing %s-header\n"), header);
3425 header_w_colon = g_strconcat(header, ":", NULL);
3426 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3428 first_address = TRUE;
3429 for(list = compose->header_list; list; list = list->next) {
3430 headerentry = ((ComposeHeaderEntry *)list->data);
3431 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3433 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3434 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3435 Xstrdup_a(str, str, return -1);
3437 if(str[0] != '\0') {
3438 compose_convert_header
3439 (buf, sizeof(buf), str,
3440 strlen(header) + 2);
3442 fprintf(fp, "%s: ", header);
3443 first_address = FALSE;
3447 fprintf(fp, "%s", buf);
3451 if(!first_address) {
3455 g_free(header_w_colon);
3460 static gint compose_write_headers(Compose *compose, FILE *fp,
3461 const gchar *charset, EncodingType encoding,
3464 gchar buf[BUFFSIZE];
3466 /* struct utsname utsbuf; */
3468 g_return_val_if_fail(fp != NULL, -1);
3469 g_return_val_if_fail(charset != NULL, -1);
3470 g_return_val_if_fail(compose->account != NULL, -1);
3471 g_return_val_if_fail(compose->account->address != NULL, -1);
3474 if (compose->account->add_date) {
3475 get_rfc822_date(buf, sizeof(buf));
3476 fprintf(fp, "Date: %s\n", buf);
3480 if (!IS_IN_CUSTOM_HEADER("From")) {
3481 if (compose->account->name && *compose->account->name) {
3482 compose_convert_header
3483 (buf, sizeof(buf), compose->account->name,
3485 fprintf(fp, "From: %s <%s>\n",
3486 buf, compose->account->address);
3488 fprintf(fp, "From: %s\n", compose->account->address);
3492 compose_write_headers_from_headerlist(compose, fp, "To");
3493 #if 0 /* NEW COMPOSE GUI */
3494 if (compose->use_to) {
3495 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3497 Xstrdup_a(str, str, return -1);
3500 compose->to_list = address_list_append
3501 (compose->to_list, str);
3502 if (!IS_IN_CUSTOM_HEADER("To")) {
3503 compose_convert_header
3504 (buf, sizeof(buf), str,
3506 fprintf(fp, "To: %s\n", buf);
3514 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3515 #if 0 /* NEW COMPOSE GUI */
3516 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3518 Xstrdup_a(str, str, return -1);
3522 compose->newsgroup_list =
3523 newsgroup_list_append(compose->newsgroup_list,
3525 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3526 compose_convert_header(buf, sizeof(buf), str,
3527 strlen("Newsgroups: "));
3528 fprintf(fp, "Newsgroups: %s\n", buf);
3534 compose_write_headers_from_headerlist(compose, fp, "Cc");
3535 #if 0 /* NEW COMPOSE GUI */
3536 if (compose->use_cc) {
3537 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3539 Xstrdup_a(str, str, return -1);
3542 compose->to_list = address_list_append
3543 (compose->to_list, str);
3544 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3545 compose_convert_header
3546 (buf, sizeof(buf), str,
3548 fprintf(fp, "Cc: %s\n", buf);
3555 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3556 #if 0 /* NEW COMPOSE GUI */
3557 if (compose->use_bcc) {
3558 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3560 Xstrdup_a(str, str, return -1);
3563 compose->to_list = address_list_append
3564 (compose->to_list, str);
3565 compose_convert_header(buf, sizeof(buf), str,
3567 fprintf(fp, "Bcc: %s\n", buf);
3574 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3575 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3576 Xstrdup_a(str, str, return -1);
3579 compose_convert_header(buf, sizeof(buf), str,
3580 strlen("Subject: "));
3581 fprintf(fp, "Subject: %s\n", buf);
3586 if (compose->account->gen_msgid) {
3587 compose_generate_msgid(compose, buf, sizeof(buf));
3588 fprintf(fp, "Message-Id: <%s>\n", buf);
3589 compose->msgid = g_strdup(buf);
3593 if (compose->inreplyto && compose->to_list)
3594 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3597 if (compose->references)
3598 fprintf(fp, "References: %s\n", compose->references);
3601 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3602 #if 0 /* NEW COMPOSE GUI */
3603 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3604 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3606 Xstrdup_a(str, str, return -1);
3610 compose_convert_header(buf, sizeof(buf), str,
3611 strlen("Followup-To: "));
3612 fprintf(fp, "Followup-To: %s\n", buf);
3618 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3619 #if 0 /* NEW COMPOSE GUI */
3620 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3621 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3623 Xstrdup_a(str, str, return -1);
3626 compose_convert_header(buf, sizeof(buf), str,
3627 strlen("Reply-To: "));
3628 fprintf(fp, "Reply-To: %s\n", buf);
3634 if (compose->account->organization &&
3635 !IS_IN_CUSTOM_HEADER("Organization")) {
3636 compose_convert_header(buf, sizeof(buf),
3637 compose->account->organization,
3638 strlen("Organization: "));
3639 fprintf(fp, "Organization: %s\n", buf);
3642 /* Program version and system info */
3643 /* uname(&utsbuf); */
3644 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3645 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3647 gtk_major_version, gtk_minor_version, gtk_micro_version,
3649 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3651 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3652 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3654 gtk_major_version, gtk_minor_version, gtk_micro_version,
3656 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3659 /* custom headers */
3660 if (compose->account->add_customhdr) {
3663 for (cur = compose->account->customhdr_list; cur != NULL;
3665 CustomHeader *chdr = (CustomHeader *)cur->data;
3667 if (strcasecmp(chdr->name, "Date") != 0 &&
3668 strcasecmp(chdr->name, "From") != 0 &&
3669 strcasecmp(chdr->name, "To") != 0 &&
3670 /* strcasecmp(chdr->name, "Sender") != 0 && */
3671 strcasecmp(chdr->name, "Message-Id") != 0 &&
3672 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3673 strcasecmp(chdr->name, "References") != 0 &&
3674 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3675 strcasecmp(chdr->name, "Content-Type") != 0 &&
3676 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3678 compose_convert_header
3680 chdr->value ? chdr->value : "",
3681 strlen(chdr->name) + 2);
3682 fprintf(fp, "%s: %s\n", chdr->name, buf);
3688 fprintf(fp, "Mime-Version: 1.0\n");
3689 if (compose_use_attach(compose)) {
3690 get_rfc822_date(buf, sizeof(buf));
3691 subst_char(buf, ' ', '_');
3692 subst_char(buf, ',', '_');
3693 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3694 buf, (guint)compose);
3696 "Content-Type: multipart/mixed;\n"
3697 " boundary=\"%s\"\n", compose->boundary);
3699 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3700 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3701 procmime_get_encoding_str(encoding));
3704 /* Request Return Receipt */
3705 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3706 if (compose->return_receipt) {
3707 if (compose->account->name
3708 && *compose->account->name) {
3709 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3710 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3712 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3716 /* separator between header and body */
3722 #undef IS_IN_CUSTOM_HEADER
3724 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3727 g_return_if_fail(src != NULL);
3728 g_return_if_fail(dest != NULL);
3730 if (len < 1) return;
3734 if (is_ascii_str(src)) {
3735 strncpy2(dest, src, len);
3736 dest[len - 1] = '\0';
3739 conv_encode_header(dest, len, src, header_len);
3742 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3751 if (compose->account && compose->account->address &&
3752 *compose->account->address) {
3753 if (strchr(compose->account->address, '@'))
3754 addr = g_strdup(compose->account->address);
3756 addr = g_strconcat(compose->account->address, "@",
3757 get_domain_name(), NULL);
3759 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3762 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3763 lt->tm_year + 1900, lt->tm_mon + 1,
3764 lt->tm_mday, lt->tm_hour,
3765 lt->tm_min, lt->tm_sec,
3766 (guint)random(), addr);
3768 debug_print(_("generated Message-ID: %s\n"), buf);
3774 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3775 GtkWidget **entry, gint *count,
3776 const gchar *label_str,
3777 gboolean is_addr_entry)
3781 if (GTK_TABLE(table)->nrows < (*count) + 1)
3782 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3784 *hbox = gtk_hbox_new(FALSE, 0);
3785 label = gtk_label_new
3786 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3787 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3788 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3790 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3792 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3793 #if 0 /* NEW COMPOSE GUI */
3794 if (GTK_TABLE(table)->nrows > (*count) + 1)
3795 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3799 address_completion_register_entry(GTK_ENTRY(*entry));
3804 static void compose_create_header_entry(Compose *compose) {
3805 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3809 GList *combo_list = NULL;
3810 gchar **string, *header;
3811 ComposeHeaderEntry *headerentry;
3813 headerentry = g_new0(ComposeHeaderEntry, 1);
3816 combo = gtk_combo_new();
3818 while(*string != NULL) {
3819 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3822 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3823 g_list_free(combo_list);
3824 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3825 gtk_widget_show(combo);
3826 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3827 if(compose->header_last) {
3828 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3830 switch(compose->account->protocol) {
3832 header = _("Newsgroups:");
3839 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
3842 entry = gtk_entry_new();
3843 gtk_widget_show(entry);
3844 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);
3846 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
3847 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
3849 address_completion_register_entry(GTK_ENTRY(entry));
3851 headerentry->compose = compose;
3852 headerentry->combo = combo;
3853 headerentry->entry = entry;
3854 headerentry->headernum = compose->header_nextrow;
3856 compose->header_nextrow++;
3857 compose->header_last = headerentry;
3860 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text) {
3861 ComposeHeaderEntry *last_header;
3863 last_header = compose->header_last;
3865 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
3866 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
3869 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
3875 GtkWidget *handlebox;
3877 GtkWidget *notebook;
3881 GtkWidget *table_vbox;
3883 GtkWidget *from_optmenu_hbox;
3884 #if 0 /* NEW COMPOSE GUI */
3885 GtkWidget *to_entry;
3887 GtkWidget *newsgroups_entry;
3888 GtkWidget *newsgroups_hbox;
3890 GtkWidget *header_scrolledwin;
3891 GtkWidget *header_table;
3892 GtkWidget *subject_entry;
3893 #if 0 /* NEW COMPOSE GUI */
3894 GtkWidget *cc_entry;
3896 GtkWidget *bcc_entry;
3897 GtkWidget *bcc_hbox;
3898 GtkWidget *reply_entry;
3899 GtkWidget *reply_hbox;
3900 GtkWidget *followup_entry;
3901 GtkWidget *followup_hbox;
3905 GtkWidget *attach_scrwin;
3906 GtkWidget *attach_clist;
3908 GtkWidget *edit_vbox;
3909 GtkWidget *ruler_hbox;
3911 GtkWidget *scrolledwin;
3917 UndoMain *undostruct;
3919 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
3920 guint n_menu_entries;
3921 GtkStyle *style, *new_style;
3924 gboolean success[1];
3926 GtkWidget *popupmenu;
3927 GtkWidget *menuitem;
3928 GtkItemFactory *popupfactory;
3929 GtkItemFactory *ifactory;
3930 GtkWidget *tmpl_menu;
3936 GtkPspell * gtkpspell = NULL;
3939 g_return_val_if_fail(account != NULL, NULL);
3941 debug_print(_("Creating compose window...\n"));
3942 compose = g_new0(Compose, 1);
3944 compose->account = account;
3945 compose->orig_account = account;
3947 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
3948 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
3949 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
3950 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3951 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
3952 gtk_signal_connect(GTK_OBJECT(window), "destroy",
3953 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
3954 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
3955 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
3956 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
3957 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
3958 gtk_widget_realize(window);
3960 gtkut_widget_set_composer_icon(window);
3962 vbox = gtk_vbox_new(FALSE, 0);
3963 gtk_container_add(GTK_CONTAINER(window), vbox);
3965 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
3966 menubar = menubar_create(window, compose_entries,
3967 n_menu_entries, "<Compose>", compose);
3968 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
3970 handlebox = gtk_handle_box_new();
3971 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
3973 compose_toolbar_create(compose, handlebox);
3975 vbox2 = gtk_vbox_new(FALSE, 2);
3976 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
3977 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
3979 table_vbox = gtk_vbox_new(FALSE, 0);
3980 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
3981 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
3985 notebook = gtk_notebook_new();
3986 gtk_widget_set_usize(notebook, -1, 180);
3987 gtk_widget_show(notebook);
3989 /* header labels and entries */
3990 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3991 gtk_widget_show(header_scrolledwin);
3992 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
3993 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), header_scrolledwin, gtk_label_new(_("Header")));
3995 header_table = gtk_table_new(2, 2, FALSE);
3996 gtk_widget_show(header_table);
3997 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
3998 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4001 /* option menu for selecting accounts */
4002 hbox = gtk_hbox_new(FALSE, 0);
4003 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4004 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4005 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4007 from_optmenu_hbox = compose_account_option_menu_create(compose);
4008 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4009 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4010 #if 0 /* NEW COMPOSE GUI */
4011 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4016 compose_add_entry_field(header_table, &hbox, &subject_entry, &count,
4019 compose->header_table = header_table;
4020 compose->header_list = NULL;
4021 compose->header_nextrow = count;
4023 compose_create_header_entry(compose);
4025 #if 0 /* NEW COMPOSE GUI */
4026 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4028 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4029 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4030 &count, "Newsgroups:", FALSE);
4031 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4033 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4035 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4037 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4038 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4040 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4041 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4043 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4044 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4045 "Followup-To:", FALSE);
4046 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4048 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4050 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4051 GTK_SIGNAL_FUNC(to_activated), compose);
4052 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4053 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4054 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4055 GTK_SIGNAL_FUNC(subject_activated), compose);
4056 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4057 GTK_SIGNAL_FUNC(cc_activated), compose);
4058 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4059 GTK_SIGNAL_FUNC(bcc_activated), compose);
4060 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4061 GTK_SIGNAL_FUNC(replyto_activated), compose);
4062 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4063 GTK_SIGNAL_FUNC(followupto_activated), compose);
4065 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4066 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4067 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4068 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4069 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4070 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4071 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4072 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4073 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4074 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4075 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4076 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4077 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4078 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4081 /* attachment list */
4082 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4083 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), attach_scrwin, gtk_label_new(_("Attachments")));
4084 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4085 GTK_POLICY_AUTOMATIC,
4087 gtk_widget_set_usize(attach_scrwin, -1, 80);
4089 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4090 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4092 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4093 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4094 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4095 GTK_SELECTION_EXTENDED);
4096 for (i = 0; i < N_ATTACH_COLS; i++)
4097 GTK_WIDGET_UNSET_FLAGS
4098 (GTK_CLIST(attach_clist)->column[i].button,
4100 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4102 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4103 GTK_SIGNAL_FUNC(attach_selected), compose);
4104 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4105 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4106 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4107 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4110 gtk_drag_dest_set(attach_clist,
4111 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4113 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4114 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4118 edit_vbox = gtk_vbox_new(FALSE, 0);
4119 #if 0 /* NEW COMPOSE GUI */
4120 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4124 ruler_hbox = gtk_hbox_new(FALSE, 0);
4125 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4127 ruler = gtk_shruler_new();
4128 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4129 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4131 gtk_widget_set_usize(ruler_hbox, 1, -1);
4134 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4135 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4136 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4137 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4138 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4140 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4141 (GTK_SCROLLED_WINDOW(scrolledwin)),
4142 gtk_scrolled_window_get_vadjustment
4143 (GTK_SCROLLED_WINDOW(scrolledwin)));
4144 GTK_STEXT(text)->default_tab_width = 8;
4145 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4147 if (prefs_common.block_cursor) {
4148 GTK_STEXT(text)->cursor_type = STEXT_CURSOR_BLOCK;
4151 if (prefs_common.smart_wrapping) {
4152 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4153 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4156 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4158 gtk_signal_connect(GTK_OBJECT(text), "changed",
4159 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4160 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4161 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4162 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4163 GTK_SIGNAL_FUNC(compose_button_press_cb),
4166 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4167 GTK_SIGNAL_FUNC(compose_key_press_cb),
4170 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4171 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4175 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4177 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4178 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4181 if (prefs_common.enable_pspell) {
4182 gtkpspell = gtkpspell_new_with_config(gtkpspellconfig,
4183 prefs_common.pspell_path,
4184 prefs_common.dictionary,
4186 conv_get_current_charset_str());
4187 if (gtkpspell == NULL)
4188 prefs_common.enable_pspell = FALSE;
4190 gtkpspell_attach(gtkpspell, GTK_STEXT(text));
4193 gtk_widget_show_all(vbox);
4195 /* pane between attach clist and text */
4196 paned = gtk_vpaned_new();
4197 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4198 gtk_paned_add1(GTK_PANED(paned), notebook);
4199 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4200 gtk_widget_show_all(paned);
4202 style = gtk_widget_get_style(text);
4204 /* workaround for the slow down of GtkText when using Pixmap theme */
4205 if (style->engine) {
4206 GtkThemeEngine *engine;
4208 engine = style->engine;
4209 style->engine = NULL;
4210 new_style = gtk_style_copy(style);
4211 style->engine = engine;
4213 new_style = gtk_style_copy(style);
4215 if (prefs_common.textfont) {
4218 charset = conv_get_current_charset();
4219 if (MB_CUR_MAX == 1) {
4222 Xstrdup_a(fontstr, prefs_common.textfont, );
4223 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4225 font = gdk_font_load(fontstr);
4227 font = gdk_fontset_load(prefs_common.textfont);
4229 gdk_font_unref(new_style->font);
4230 new_style->font = font;
4234 gtk_widget_set_style(text, new_style);
4236 color[0] = quote_color;
4237 cmap = gdk_window_get_colormap(window->window);
4238 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4239 if (success[0] == FALSE) {
4240 g_warning("Compose: color allocation failed.\n");
4241 style = gtk_widget_get_style(text);
4242 quote_color = style->black;
4245 n_entries = sizeof(compose_popup_entries) /
4246 sizeof(compose_popup_entries[0]);
4247 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4248 "<Compose>", &popupfactory,
4251 ifactory = gtk_item_factory_from_widget(menubar);
4252 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4253 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4255 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tool/Template");
4256 #if 0 /* NEW COMPOSE GUI */
4257 if (account->protocol == A_NNTP) {
4258 gtk_widget_hide(to_hbox);
4259 gtk_widget_hide(to_entry);
4260 gtk_widget_hide(cc_hbox);
4261 gtk_widget_hide(cc_entry);
4262 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4263 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4265 gtk_widget_hide(newsgroups_hbox);
4266 gtk_widget_hide(newsgroups_entry);
4267 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4269 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
4273 switch (prefs_common.toolbar_style) {
4275 gtk_widget_hide(handlebox);
4278 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4282 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4286 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4291 gtk_widget_show(window);
4293 address_completion_start(window);
4295 compose->window = window;
4296 compose->vbox = vbox;
4297 compose->menubar = menubar;
4298 compose->handlebox = handlebox;
4300 compose->vbox2 = vbox2;
4302 compose->table_vbox = table_vbox;
4303 compose->table = NULL;
4304 #if 0 /* NEW COMPOSE GUI */
4305 compose->table = table;
4306 compose->to_hbox = to_hbox;
4307 compose->to_entry = to_entry;
4308 compose->newsgroups_hbox = newsgroups_hbox;
4309 compose->newsgroups_entry = newsgroups_entry;
4311 compose->subject_entry = subject_entry;
4312 #if 0 /* NEW COMPOSE GUI */
4313 compose->cc_hbox = cc_hbox;
4314 compose->cc_entry = cc_entry;
4315 compose->bcc_hbox = bcc_hbox;
4316 compose->bcc_entry = bcc_entry;
4317 compose->reply_hbox = reply_hbox;
4318 compose->reply_entry = reply_entry;
4319 compose->followup_hbox = followup_hbox;
4320 compose->followup_entry = followup_entry;
4322 compose->paned = paned;
4324 compose->attach_scrwin = attach_scrwin;
4325 compose->attach_clist = attach_clist;
4327 compose->edit_vbox = edit_vbox;
4328 compose->ruler_hbox = ruler_hbox;
4329 compose->ruler = ruler;
4330 compose->scrolledwin = scrolledwin;
4331 compose->text = text;
4333 compose->focused_editable = NULL;
4335 compose->popupmenu = popupmenu;
4336 compose->popupfactory = popupfactory;
4338 compose->tmpl_menu = tmpl_menu;
4340 compose->mode = mode;
4342 compose->targetinfo = NULL;
4343 compose->replyinfo = NULL;
4345 compose->replyto = NULL;
4346 compose->mailinglist = NULL;
4348 compose->bcc = NULL;
4349 compose->followup_to = NULL;
4350 compose->inreplyto = NULL;
4351 compose->references = NULL;
4352 compose->msgid = NULL;
4353 compose->boundary = NULL;
4356 compose->use_signing = FALSE;
4357 compose->use_encryption = FALSE;
4358 #endif /* USE_GPGME */
4360 compose->modified = FALSE;
4362 compose->return_receipt = FALSE;
4364 compose->to_list = NULL;
4365 compose->newsgroup_list = NULL;
4367 compose->exteditor_file = NULL;
4368 compose->exteditor_pid = -1;
4369 compose->exteditor_readdes = -1;
4370 compose->exteditor_tag = -1;
4372 compose->bounce_filename = NULL;
4374 compose_set_title(compose);
4376 #if 0 /* NEW COMPOSE GUI */
4377 compose->use_bcc = FALSE;
4378 compose->use_replyto = FALSE;
4379 compose->use_followupto = FALSE;
4383 compose->gtkpspell = gtkpspell;
4386 undostruct = undo_init(text);
4388 compose->undostruct = undostruct;
4389 undo_set_undo_change_funct(undostruct, &compose_set_undo, GTK_WIDGET(compose->menubar));
4391 #if 0 /* NEW COMPOSE GUI */
4392 if (account->protocol != A_NNTP) {
4393 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4394 gtk_check_menu_item_set_active
4395 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4396 gtk_widget_set_sensitive(menuitem, FALSE);
4397 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4398 gtk_check_menu_item_set_active
4399 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4400 gtk_widget_set_sensitive(menuitem, FALSE);
4403 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4404 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4405 #if 0 /* NEW COMPOSE GUI */
4406 compose->use_cc = TRUE;
4407 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4408 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4409 gtk_check_menu_item_set_active
4410 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4413 if (account->set_autobcc) {
4414 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4415 #if 0 /* NEW COMPOSE GUI */
4416 compose->use_bcc = TRUE;
4417 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
4418 gtk_check_menu_item_set_active
4419 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4420 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4421 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4425 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4426 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4427 #if 0 /* NEW COMPOSE GUI */
4428 compose->use_replyto = TRUE;
4429 menuitem = gtk_item_factory_get_item(ifactory,
4430 "/Message/Reply to");
4431 gtk_check_menu_item_set_active
4432 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4433 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4434 account->auto_replyto);
4437 if (account->protocol != A_NNTP) {
4438 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("To:"));
4440 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("Newsgroups:"));
4443 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
4444 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4445 prefs_common.show_ruler);
4448 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4449 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4450 prefs_common.default_sign);
4451 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4452 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4453 prefs_common.default_encrypt);
4454 #endif /* USE_GPGME */
4456 addressbook_set_target_compose(compose);
4457 compose_set_template_menu(compose);
4459 compose_list = g_list_append(compose_list, compose);
4461 #if 0 /* NEW COMPOSE GUI */
4462 compose->use_to = FALSE;
4463 compose->use_cc = FALSE;
4464 compose->use_attach = TRUE;
4467 #if 0 /* NEW COMPOSE GUI */
4468 if (!compose->use_bcc) {
4469 gtk_widget_hide(bcc_hbox);
4470 gtk_widget_hide(bcc_entry);
4471 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4473 if (!compose->use_replyto) {
4474 gtk_widget_hide(reply_hbox);
4475 gtk_widget_hide(reply_entry);
4476 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4478 if (!compose->use_followupto) {
4479 gtk_widget_hide(followup_hbox);
4480 gtk_widget_hide(followup_entry);
4481 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4484 if (!prefs_common.show_ruler)
4485 gtk_widget_hide(ruler_hbox);
4487 select_account(compose, account);
4492 #include "pixmaps/stock_mail_send.xpm"
4493 #include "pixmaps/stock_mail_send_queue.xpm"
4494 #include "pixmaps/stock_mail.xpm"
4495 #include "pixmaps/stock_paste.xpm"
4496 #include "pixmaps/stock_mail_attach.xpm"
4497 #include "pixmaps/stock_mail_compose.xpm"
4498 #include "pixmaps/linewrap.xpm"
4499 #include "pixmaps/tb_address_book.xpm"
4501 #define CREATE_TOOLBAR_ICON(xpm_d) \
4503 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
4504 &container->style->white, \
4506 icon_wid = gtk_pixmap_new(icon, mask); \
4509 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4514 GtkWidget *icon_wid;
4515 GtkWidget *send_btn;
4516 GtkWidget *sendl_btn;
4517 GtkWidget *draft_btn;
4518 GtkWidget *insert_btn;
4519 GtkWidget *attach_btn;
4521 GtkWidget *exteditor_btn;
4522 GtkWidget *linewrap_btn;
4523 GtkWidget *addrbook_btn;
4525 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4527 gtk_container_add(GTK_CONTAINER(container), toolbar);
4528 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4529 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4530 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4531 GTK_TOOLBAR_SPACE_LINE);
4533 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
4534 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4538 icon_wid, toolbar_send_cb, compose);
4540 CREATE_TOOLBAR_ICON(stock_mail_send_queue_xpm);
4541 /* CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm); */
4542 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4544 _("Put into queue folder and send later"),
4546 icon_wid, toolbar_send_later_cb,
4549 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4550 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4552 _("Save to draft folder"),
4554 icon_wid, toolbar_draft_cb,
4557 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4559 CREATE_TOOLBAR_ICON(stock_paste_xpm);
4560 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4564 icon_wid, toolbar_insert_cb,
4567 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
4568 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4572 icon_wid, toolbar_attach_cb,
4575 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4577 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4578 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4580 _("Insert signature"),
4582 icon_wid, toolbar_sig_cb, compose);
4584 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4586 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
4587 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4589 _("Edit with external editor"),
4592 toolbar_ext_editor_cb,
4595 CREATE_TOOLBAR_ICON(linewrap_xpm);
4596 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4598 _("Wrap current paragraph"),
4601 toolbar_linewrap_cb,
4604 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4606 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
4607 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4611 icon_wid, toolbar_address_cb,
4614 compose->toolbar = toolbar;
4615 compose->send_btn = send_btn;
4616 compose->sendl_btn = sendl_btn;
4617 compose->draft_btn = draft_btn;
4618 compose->insert_btn = insert_btn;
4619 compose->attach_btn = attach_btn;
4620 compose->sig_btn = sig_btn;
4621 compose->exteditor_btn = exteditor_btn;
4622 compose->linewrap_btn = linewrap_btn;
4623 compose->addrbook_btn = addrbook_btn;
4625 gtk_widget_show_all(toolbar);
4628 #undef CREATE_TOOLBAR_ICON
4630 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4636 gint num = 0, def_menu = 0;
4638 accounts = account_get_list();
4639 g_return_val_if_fail(accounts != NULL, NULL);
4641 hbox = gtk_hbox_new(FALSE, 0);
4642 optmenu = gtk_option_menu_new();
4643 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4644 menu = gtk_menu_new();
4646 for (; accounts != NULL; accounts = accounts->next, num++) {
4647 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4648 GtkWidget *menuitem;
4651 if (ac == compose->account) def_menu = num;
4653 name = g_strdup_printf("%s: %s <%s>",
4654 ac->account_name, ac->name, ac->address);
4655 MENUITEM_ADD(menu, menuitem, name, ac);
4657 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4658 GTK_SIGNAL_FUNC(account_activated),
4662 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4663 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4668 static void compose_set_template_menu(Compose *compose)
4670 GSList *tmpl_list, *cur;
4674 tmpl_list = template_get_config();
4676 menu = gtk_menu_new();
4678 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4679 Template *tmpl = (Template *)cur->data;
4681 item = gtk_menu_item_new_with_label(tmpl->name);
4682 gtk_menu_append(GTK_MENU(menu), item);
4683 gtk_signal_connect(GTK_OBJECT(item), "activate",
4684 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4686 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4687 gtk_widget_show(item);
4690 gtk_widget_show(menu);
4691 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4694 void compose_reflect_prefs_all(void)
4699 for (cur = compose_list; cur != NULL; cur = cur->next) {
4700 compose = (Compose *)cur->data;
4701 compose_set_template_menu(compose);
4705 static void compose_template_apply(Compose *compose, Template *tmpl)
4710 if (!tmpl || !tmpl->value) return;
4712 gtk_stext_freeze(GTK_STEXT(compose->text));
4715 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
4718 if (compose->replyinfo == NULL) {
4721 memset(&dummyinfo, 0, sizeof(MsgInfo));
4722 parsed_str = compose_quote_fmt(compose, &dummyinfo,
4725 if (prefs_common.quotemark && *prefs_common.quotemark)
4726 qmark = prefs_common.quotemark;
4730 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
4731 tmpl->value, qmark);
4734 if (parsed_str && prefs_common.auto_sig)
4735 compose_insert_sig(compose);
4737 gtk_stext_thaw(GTK_STEXT(compose->text));
4740 static void compose_destroy(Compose *compose)
4743 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4746 /* NOTE: address_completion_end() does nothing with the window
4747 * however this may change. */
4748 address_completion_end(compose->window);
4750 slist_free_strings(compose->to_list);
4751 g_slist_free(compose->to_list);
4752 slist_free_strings(compose->newsgroup_list);
4753 g_slist_free(compose->newsgroup_list);
4754 slist_free_strings(compose->header_list);
4755 g_slist_free(compose->header_list);
4757 procmsg_msginfo_free(compose->targetinfo);
4758 procmsg_msginfo_free(compose->replyinfo);
4760 g_free(compose->replyto);
4761 g_free(compose->cc);
4762 g_free(compose->bcc);
4763 g_free(compose->newsgroups);
4764 g_free(compose->followup_to);
4766 g_free(compose->inreplyto);
4767 g_free(compose->references);
4768 g_free(compose->msgid);
4769 g_free(compose->boundary);
4771 if (compose->bounce_filename)
4772 g_free(compose->bounce_filename);
4774 g_free(compose->exteditor_file);
4776 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
4778 compose_attach_info_free(ainfo);
4780 if (addressbook_get_target_compose() == compose)
4781 addressbook_set_target_compose(NULL);
4783 prefs_common.compose_width = compose->scrolledwin->allocation.width;
4784 prefs_common.compose_height = compose->window->allocation.height;
4786 gtk_widget_destroy(compose->paned);
4790 compose_list = g_list_remove(compose_list, compose);
4793 static void compose_attach_info_free(AttachInfo *ainfo)
4795 g_free(ainfo->file);
4796 g_free(ainfo->content_type);
4797 g_free(ainfo->name);
4801 static void compose_attach_remove_selected(Compose *compose)
4803 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4807 while (clist->selection != NULL) {
4808 row = GPOINTER_TO_INT(clist->selection->data);
4809 ainfo = gtk_clist_get_row_data(clist, row);
4810 compose_attach_info_free(ainfo);
4811 gtk_clist_remove(clist, row);
4815 static struct _AttachProperty
4818 GtkWidget *mimetype_entry;
4819 GtkWidget *encoding_optmenu;
4820 GtkWidget *path_entry;
4821 GtkWidget *filename_entry;
4823 GtkWidget *cancel_btn;
4826 static void compose_attach_property(Compose *compose)
4828 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4831 GtkOptionMenu *optmenu;
4832 static gboolean cancelled;
4834 if (!clist->selection) return;
4835 row = GPOINTER_TO_INT(clist->selection->data);
4837 ainfo = gtk_clist_get_row_data(clist, row);
4840 if (!attach_prop.window)
4841 compose_attach_property_create(&cancelled);
4842 gtk_widget_grab_focus(attach_prop.ok_btn);
4843 gtk_widget_show(attach_prop.window);
4844 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
4846 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
4847 if (ainfo->encoding == ENC_UNKNOWN)
4848 gtk_option_menu_set_history(optmenu, ENC_BASE64);
4850 gtk_option_menu_set_history(optmenu, ainfo->encoding);
4852 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
4853 ainfo->content_type ? ainfo->content_type : "");
4854 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
4855 ainfo->file ? ainfo->file : "");
4856 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
4857 ainfo->name ? ainfo->name : "");
4861 gchar *cnttype = NULL;
4865 GtkWidget *menuitem;
4870 if (cancelled == TRUE) {
4871 gtk_widget_hide(attach_prop.window);
4875 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
4876 if (*text != '\0') {
4879 text = g_strstrip(g_strdup(text));
4880 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
4881 cnttype = g_strdup(text);
4884 alertpanel_error(_("Invalid MIME type."));
4890 menu = gtk_option_menu_get_menu(optmenu);
4891 menuitem = gtk_menu_get_active(GTK_MENU(menu));
4892 ainfo->encoding = GPOINTER_TO_INT
4893 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
4895 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
4896 if (*text != '\0') {
4897 if (is_file_exist(text) &&
4898 (size = get_file_size(text)) > 0)
4899 file = g_strdup(text);
4902 (_("File doesn't exist or is empty."));
4908 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
4909 if (*text != '\0') {
4910 g_free(ainfo->name);
4911 ainfo->name = g_strdup(text);
4915 g_free(ainfo->content_type);
4916 ainfo->content_type = cnttype;
4919 g_free(ainfo->file);
4925 gtk_clist_set_text(clist, row, COL_MIMETYPE,
4926 ainfo->content_type);
4927 gtk_clist_set_text(clist, row, COL_SIZE,
4928 to_human_readable(ainfo->size));
4929 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
4931 gtk_widget_hide(attach_prop.window);
4936 #define SET_LABEL_AND_ENTRY(str, entry, top) \
4938 label = gtk_label_new(str); \
4939 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
4940 GTK_FILL, 0, 0, 0); \
4941 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
4943 entry = gtk_entry_new(); \
4944 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
4945 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
4948 static void compose_attach_property_create(gboolean *cancelled)
4954 GtkWidget *mimetype_entry;
4957 GtkWidget *optmenu_menu;
4958 GtkWidget *menuitem;
4959 GtkWidget *path_entry;
4960 GtkWidget *filename_entry;
4963 GtkWidget *cancel_btn;
4964 GList *mime_type_list, *strlist;
4966 debug_print("Creating attach_property window...\n");
4968 window = gtk_window_new(GTK_WINDOW_DIALOG);
4969 gtk_widget_set_usize(window, 480, -1);
4970 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
4971 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
4972 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
4973 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
4974 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4975 GTK_SIGNAL_FUNC(attach_property_delete_event),
4977 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
4978 GTK_SIGNAL_FUNC(attach_property_key_pressed),
4981 vbox = gtk_vbox_new(FALSE, 8);
4982 gtk_container_add(GTK_CONTAINER(window), vbox);
4984 table = gtk_table_new(4, 2, FALSE);
4985 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
4986 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
4987 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
4989 label = gtk_label_new(_("MIME type"));
4990 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
4992 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
4993 mimetype_entry = gtk_combo_new();
4994 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
4995 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
4997 /* stuff with list */
4998 mime_type_list = procmime_get_mime_type_list();
5000 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5001 MimeType *type = (MimeType *) mime_type_list->data;
5002 strlist = g_list_append(strlist,
5003 g_strdup_printf("%s/%s",
5004 type->type, type->sub_type));
5007 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5009 for (mime_type_list = strlist; mime_type_list != NULL;
5010 mime_type_list = mime_type_list->next)
5011 g_free(mime_type_list->data);
5012 g_list_free(strlist);
5014 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5016 label = gtk_label_new(_("Encoding"));
5017 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5019 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5021 hbox = gtk_hbox_new(FALSE, 0);
5022 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5023 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5025 optmenu = gtk_option_menu_new();
5026 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5028 optmenu_menu = gtk_menu_new();
5029 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5030 gtk_widget_set_sensitive(menuitem, FALSE);
5031 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5032 gtk_widget_set_sensitive(menuitem, FALSE);
5033 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5034 gtk_widget_set_sensitive(menuitem, FALSE);
5035 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5037 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5039 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5040 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5042 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5043 &cancel_btn, _("Cancel"), NULL, NULL);
5044 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5045 gtk_widget_grab_default(ok_btn);
5047 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5048 GTK_SIGNAL_FUNC(attach_property_ok),
5050 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5051 GTK_SIGNAL_FUNC(attach_property_cancel),
5054 gtk_widget_show_all(vbox);
5056 attach_prop.window = window;
5057 attach_prop.mimetype_entry = mimetype_entry;
5058 attach_prop.encoding_optmenu = optmenu;
5059 attach_prop.path_entry = path_entry;
5060 attach_prop.filename_entry = filename_entry;
5061 attach_prop.ok_btn = ok_btn;
5062 attach_prop.cancel_btn = cancel_btn;
5065 #undef SET_LABEL_AND_ENTRY
5067 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5073 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5079 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5080 gboolean *cancelled)
5088 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5089 gboolean *cancelled)
5091 if (event && event->keyval == GDK_Escape) {
5097 static void compose_exec_ext_editor(Compose *compose)
5103 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5104 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5106 if (pipe(pipe_fds) < 0) {
5111 if ((pid = fork()) < 0) {
5117 /* close the write side of the pipe */
5120 compose->exteditor_file = g_strdup(tmp);
5121 compose->exteditor_pid = pid;
5122 compose->exteditor_readdes = pipe_fds[0];
5124 compose_set_ext_editor_sensitive(compose, FALSE);
5126 compose->exteditor_tag =
5127 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5128 compose_input_cb, compose);
5129 } else { /* process-monitoring process */
5135 /* close the read side of the pipe */
5138 if (compose_write_body_to_file(compose, tmp) < 0) {
5139 fd_write(pipe_fds[1], "2\n", 2);
5143 pid_ed = compose_exec_ext_editor_real(tmp);
5145 fd_write(pipe_fds[1], "1\n", 2);
5149 /* wait until editor is terminated */
5150 waitpid(pid_ed, NULL, 0);
5152 fd_write(pipe_fds[1], "0\n", 2);
5159 static gint compose_exec_ext_editor_real(const gchar *file)
5161 static gchar *def_cmd = "emacs %s";
5167 g_return_val_if_fail(file != NULL, -1);
5169 if ((pid = fork()) < 0) {
5174 if (pid != 0) return pid;
5176 /* grandchild process */
5178 if (setpgid(0, getppid()))
5181 if (prefs_common.ext_editor_cmd &&
5182 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5183 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5184 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5186 if (prefs_common.ext_editor_cmd)
5187 g_warning(_("External editor command line is invalid: `%s'\n"),
5188 prefs_common.ext_editor_cmd);
5189 g_snprintf(buf, sizeof(buf), def_cmd, file);
5192 cmdline = g_strsplit(buf, " ", 1024);
5193 execvp(cmdline[0], cmdline);
5196 g_strfreev(cmdline);
5201 static gboolean compose_ext_editor_kill(Compose *compose)
5203 pid_t pgid = compose->exteditor_pid * -1;
5206 ret = kill(pgid, 0);
5208 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5212 msg = g_strdup_printf
5213 (_("The external editor is still working.\n"
5214 "Force terminating the process?\n"
5215 "process group id: %d"), -pgid);
5216 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5219 if (val == G_ALERTDEFAULT) {
5220 gdk_input_remove(compose->exteditor_tag);
5221 close(compose->exteditor_readdes);
5223 if (kill(pgid, SIGTERM) < 0) perror("kill");
5224 waitpid(compose->exteditor_pid, NULL, 0);
5226 g_warning(_("Terminated process group id: %d"), -pgid);
5227 g_warning(_("Temporary file: %s"),
5228 compose->exteditor_file);
5230 compose_set_ext_editor_sensitive(compose, TRUE);
5232 g_free(compose->exteditor_file);
5233 compose->exteditor_file = NULL;
5234 compose->exteditor_pid = -1;
5235 compose->exteditor_readdes = -1;
5236 compose->exteditor_tag = -1;
5244 static void compose_input_cb(gpointer data, gint source,
5245 GdkInputCondition condition)
5248 Compose *compose = (Compose *)data;
5251 debug_print(_("Compose: input from monitoring process\n"));
5253 gdk_input_remove(compose->exteditor_tag);
5256 if (read(source, &buf[i], 1) < 1) {
5260 if (buf[i] == '\n') {
5265 if (i == sizeof(buf) - 1)
5269 waitpid(compose->exteditor_pid, NULL, 0);
5271 if (buf[0] == '0') { /* success */
5272 GtkSText *text = GTK_STEXT(compose->text);
5274 gtk_stext_freeze(text);
5275 gtk_stext_set_point(text, 0);
5276 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5277 compose_insert_file(compose, compose->exteditor_file);
5278 compose_changed_cb(NULL, compose);
5279 gtk_stext_thaw(text);
5281 if (unlink(compose->exteditor_file) < 0)
5282 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5283 } else if (buf[0] == '1') { /* failed */
5284 g_warning(_("Couldn't exec external editor\n"));
5285 if (unlink(compose->exteditor_file) < 0)
5286 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5287 } else if (buf[0] == '2') {
5288 g_warning(_("Couldn't write to file\n"));
5289 } else if (buf[0] == '3') {
5290 g_warning(_("Pipe read failed\n"));
5295 compose_set_ext_editor_sensitive(compose, TRUE);
5297 g_free(compose->exteditor_file);
5298 compose->exteditor_file = NULL;
5299 compose->exteditor_pid = -1;
5300 compose->exteditor_readdes = -1;
5301 compose->exteditor_tag = -1;
5304 static void compose_set_ext_editor_sensitive(Compose *compose,
5307 GtkItemFactory *ifactory;
5309 ifactory = gtk_item_factory_from_widget(compose->menubar);
5311 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5312 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5313 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5315 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5316 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5317 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5318 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5319 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5322 gtk_widget_set_sensitive(compose->text, sensitive);
5323 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5324 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5325 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5326 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5327 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5328 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5329 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5332 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5336 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5337 cursor_pos = MAX(cursor_pos, 0);
5342 /* callback functions */
5344 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5345 * includes "non-client" (windows-izm) in calculation, so this calculation
5346 * may not be accurate.
5348 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5349 GtkAllocation *allocation,
5350 GtkSHRuler *shruler)
5352 if (prefs_common.show_ruler) {
5354 gint line_width_in_chars;
5356 char_width = gtkut_get_font_width
5357 (GTK_WIDGET(widget)->style->font);
5358 line_width_in_chars =
5359 (allocation->width - allocation->x) / char_width;
5361 /* got the maximum */
5362 gtk_ruler_set_range(GTK_RULER(shruler),
5363 0.0, line_width_in_chars,
5364 calc_cursor_xpos(GTK_STEXT(widget),
5367 /*line_width_in_chars*/ char_width);
5373 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5375 compose_send_cb(data, 0, NULL);
5378 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5380 compose_send_later_cb(data, 0, NULL);
5383 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5385 compose_draft_cb(data, 0, NULL);
5388 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5390 compose_insert_file_cb(data, 0, NULL);
5393 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5395 compose_attach_cb(data, 0, NULL);
5398 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5400 Compose *compose = (Compose *)data;
5402 compose_insert_sig(compose);
5405 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5407 Compose *compose = (Compose *)data;
5409 compose_exec_ext_editor(compose);
5412 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5414 Compose *compose = (Compose *)data;
5416 compose_wrap_line(compose);
5419 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5421 compose_address_cb(data, 0, NULL);
5424 static void select_account(Compose * compose, PrefsAccount * ac)
5426 compose->account = ac;
5427 compose_set_title(compose);
5429 #if 0 /* NEW COMPOSE GUI */
5430 if (ac->protocol == A_NNTP) {
5431 GtkItemFactory *ifactory;
5432 GtkWidget *menuitem;
5434 ifactory = gtk_item_factory_from_widget(compose->menubar);
5435 menu_set_sensitive(ifactory,
5436 "/Message/Followup to", TRUE);
5437 gtk_widget_show(compose->newsgroups_hbox);
5438 gtk_widget_show(compose->newsgroups_entry);
5439 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5442 compose->use_to = FALSE;
5443 compose->use_cc = FALSE;
5445 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5446 gtk_check_menu_item_set_active
5447 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5449 menu_set_sensitive(ifactory,
5450 "/Message/To", TRUE);
5451 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5452 gtk_check_menu_item_set_active
5453 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5455 gtk_widget_hide(compose->to_hbox);
5456 gtk_widget_hide(compose->to_entry);
5457 gtk_widget_hide(compose->cc_hbox);
5458 gtk_widget_hide(compose->cc_entry);
5459 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5461 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5465 GtkItemFactory *ifactory;
5466 GtkWidget *menuitem;
5468 ifactory = gtk_item_factory_from_widget(compose->menubar);
5469 menu_set_sensitive(ifactory,
5470 "/Message/Followup to", FALSE);
5471 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5472 gtk_widget_hide(compose->newsgroups_hbox);
5473 gtk_widget_hide(compose->newsgroups_entry);
5474 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5477 compose->use_to = TRUE;
5478 compose->use_cc = TRUE;
5480 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5481 gtk_check_menu_item_set_active
5482 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5483 menu_set_sensitive(ifactory,
5484 "/Message/To", FALSE);
5485 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5486 gtk_check_menu_item_set_active
5487 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5488 gtk_widget_show(compose->to_hbox);
5489 gtk_widget_show(compose->to_entry);
5490 gtk_widget_show(compose->cc_hbox);
5491 gtk_widget_show(compose->cc_entry);
5493 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5495 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5498 gtk_widget_queue_resize(compose->table_vbox);
5502 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5504 Compose *compose = (Compose *)data;
5508 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5509 g_return_if_fail(ac != NULL);
5511 if (ac != compose->account)
5512 select_account(compose, ac);
5515 static void attach_selected(GtkCList *clist, gint row, gint column,
5516 GdkEvent *event, gpointer data)
5518 Compose *compose = (Compose *)data;
5520 if (event && event->type == GDK_2BUTTON_PRESS)
5521 compose_attach_property(compose);
5524 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5527 Compose *compose = (Compose *)data;
5528 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5533 if (event->button == 3) {
5534 if ((clist->selection && !clist->selection->next) ||
5535 !clist->selection) {
5536 gtk_clist_unselect_all(clist);
5537 if (gtk_clist_get_selection_info(clist,
5540 gtk_clist_select_row(clist, row, column);
5541 gtkut_clist_set_focus_row(clist, row);
5544 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5545 NULL, NULL, event->button, event->time);
5549 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5552 Compose *compose = (Compose *)data;
5556 switch (event->keyval) {
5558 compose_attach_remove_selected(compose);
5563 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5565 Compose *compose = (Compose *)data;
5568 val = compose_send(compose);
5569 if (val == 0) gtk_widget_destroy(compose->window);
5572 static void compose_send_later_cb(gpointer data, guint action,
5575 Compose *compose = (Compose *)data;
5578 val = compose_queue(compose, NULL, NULL);
5579 if (!val) gtk_widget_destroy(compose->window);
5582 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5584 Compose *compose = (Compose *)data;
5588 draft = folder_get_default_draft();
5590 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5591 G_DIR_SEPARATOR, (gint)compose);
5593 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5598 folder_item_scan(draft);
5599 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
5606 if (compose->mode == COMPOSE_REEDIT) {
5607 compose_remove_reedit_target(compose);
5608 if (compose->targetinfo &&
5609 compose->targetinfo->folder != draft)
5610 folderview_update_item(compose->targetinfo->folder,
5614 folder_item_scan(draft);
5615 folderview_update_item(draft, TRUE);
5617 gtk_widget_destroy(compose->window);
5620 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
5622 Compose *compose = (Compose *)data;
5625 if (compose->bounce_filename != NULL)
5628 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5633 for ( tmp = file_list; tmp; tmp = tmp->next) {
5634 gchar *file = (gchar *) tmp->data;
5635 compose_attach_append(compose, file, MIME_UNKNOWN);
5638 g_list_free(file_list);
5642 static void compose_insert_file_cb(gpointer data, guint action,
5645 Compose *compose = (Compose *)data;
5648 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5653 for ( tmp = file_list; tmp; tmp = tmp->next) {
5654 gchar *file = (gchar *) tmp->data;
5655 compose_insert_file(compose, file);
5658 g_list_free(file_list);
5662 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
5665 compose_close_cb(data, 0, NULL);
5669 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
5671 Compose *compose = (Compose *)data;
5674 if (compose->exteditor_tag != -1) {
5675 if (!compose_ext_editor_kill(compose))
5679 if (compose->modified) {
5680 val = alertpanel(_("Discard message"),
5681 _("This message has been modified. discard it?"),
5682 _("Discard"), _("to Draft"), _("Cancel"));
5685 case G_ALERTDEFAULT:
5687 case G_ALERTALTERNATE:
5688 compose_draft_cb(data, 0, NULL);
5695 if (compose->gtkpspell) {
5696 gtkpspell_detach(compose->gtkpspell);
5697 compose->gtkpspell = gtkpspell_delete(compose->gtkpspell);
5700 gtk_widget_destroy(compose->window);
5703 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
5705 Compose *compose = (Compose *)data;
5707 addressbook_open(compose);
5710 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
5712 Compose *compose = (Compose *)data;
5715 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
5716 g_return_if_fail(tmpl != NULL);
5718 compose_template_apply(compose, tmpl);
5721 static void compose_ext_editor_cb(gpointer data, guint action,
5724 Compose *compose = (Compose *)data;
5726 compose_exec_ext_editor(compose);
5729 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
5731 compose_destroy(compose);
5734 static void compose_undo_cb(Compose *compose)
5736 undo_undo(compose->undostruct);
5739 static void compose_redo_cb(Compose *compose)
5741 undo_redo(compose->undostruct);
5744 static void compose_cut_cb(Compose *compose)
5746 if (compose->focused_editable &&
5747 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5748 gtk_editable_cut_clipboard
5749 (GTK_EDITABLE(compose->focused_editable));
5752 static void compose_copy_cb(Compose *compose)
5754 if (compose->focused_editable &&
5755 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5756 gtk_editable_copy_clipboard
5757 (GTK_EDITABLE(compose->focused_editable));
5760 static void compose_paste_cb(Compose *compose)
5762 if (compose->focused_editable &&
5763 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5764 gtk_editable_paste_clipboard
5765 (GTK_EDITABLE(compose->focused_editable));
5768 static void compose_allsel_cb(Compose *compose)
5770 if (compose->focused_editable &&
5771 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5772 gtk_editable_select_region
5773 (GTK_EDITABLE(compose->focused_editable), 0, -1);
5776 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
5778 if (GTK_IS_EDITABLE(widget))
5779 compose->focused_editable = widget;
5782 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
5784 if (compose->modified == FALSE) {
5785 compose->modified = TRUE;
5786 compose_set_title(compose);
5790 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
5793 gtk_stext_set_point(GTK_STEXT(widget),
5794 gtk_editable_get_position(GTK_EDITABLE(widget)));
5798 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
5801 gtk_stext_set_point(GTK_STEXT(widget),
5802 gtk_editable_get_position(GTK_EDITABLE(widget)));
5806 #if 0 /* NEW COMPOSE GUI */
5807 static void compose_toggle_to_cb(gpointer data, guint action,
5810 Compose *compose = (Compose *)data;
5812 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5813 gtk_widget_show(compose->to_hbox);
5814 gtk_widget_show(compose->to_entry);
5815 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
5816 compose->use_to = TRUE;
5818 gtk_widget_hide(compose->to_hbox);
5819 gtk_widget_hide(compose->to_entry);
5820 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
5821 gtk_widget_queue_resize(compose->table_vbox);
5822 compose->use_to = FALSE;
5825 if (addressbook_get_target_compose() == compose)
5826 addressbook_set_target_compose(compose);
5829 static void compose_toggle_cc_cb(gpointer data, guint action,
5832 Compose *compose = (Compose *)data;
5834 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5835 gtk_widget_show(compose->cc_hbox);
5836 gtk_widget_show(compose->cc_entry);
5837 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
5838 compose->use_cc = TRUE;
5840 gtk_widget_hide(compose->cc_hbox);
5841 gtk_widget_hide(compose->cc_entry);
5842 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
5843 gtk_widget_queue_resize(compose->table_vbox);
5844 compose->use_cc = FALSE;
5847 if (addressbook_get_target_compose() == compose)
5848 addressbook_set_target_compose(compose);
5851 static void compose_toggle_bcc_cb(gpointer data, guint action,
5854 Compose *compose = (Compose *)data;
5856 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5857 gtk_widget_show(compose->bcc_hbox);
5858 gtk_widget_show(compose->bcc_entry);
5859 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
5860 compose->use_bcc = TRUE;
5862 gtk_widget_hide(compose->bcc_hbox);
5863 gtk_widget_hide(compose->bcc_entry);
5864 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
5865 gtk_widget_queue_resize(compose->table_vbox);
5866 compose->use_bcc = FALSE;
5869 if (addressbook_get_target_compose() == compose)
5870 addressbook_set_target_compose(compose);
5873 static void compose_toggle_replyto_cb(gpointer data, guint action,
5876 Compose *compose = (Compose *)data;
5878 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5879 gtk_widget_show(compose->reply_hbox);
5880 gtk_widget_show(compose->reply_entry);
5881 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
5882 compose->use_replyto = TRUE;
5884 gtk_widget_hide(compose->reply_hbox);
5885 gtk_widget_hide(compose->reply_entry);
5886 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
5887 gtk_widget_queue_resize(compose->table_vbox);
5888 compose->use_replyto = FALSE;
5892 static void compose_toggle_followupto_cb(gpointer data, guint action,
5895 Compose *compose = (Compose *)data;
5897 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5898 gtk_widget_show(compose->followup_hbox);
5899 gtk_widget_show(compose->followup_entry);
5900 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
5901 compose->use_followupto = TRUE;
5903 gtk_widget_hide(compose->followup_hbox);
5904 gtk_widget_hide(compose->followup_entry);
5905 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
5906 gtk_widget_queue_resize(compose->table_vbox);
5907 compose->use_followupto = FALSE;
5911 static void compose_toggle_attach_cb(gpointer data, guint action,
5914 Compose *compose = (Compose *)data;
5916 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5917 gtk_widget_ref(compose->edit_vbox);
5919 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5920 compose->edit_vbox);
5921 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
5922 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
5924 gtk_widget_show(compose->paned);
5926 gtk_widget_unref(compose->edit_vbox);
5927 gtk_widget_unref(compose->paned);
5929 compose->use_attach = TRUE;
5931 gtk_widget_ref(compose->paned);
5932 gtk_widget_ref(compose->edit_vbox);
5934 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5936 gtk_container_remove(GTK_CONTAINER(compose->paned),
5937 compose->edit_vbox);
5938 gtk_box_pack_start(GTK_BOX(compose->vbox2),
5939 compose->edit_vbox, TRUE, TRUE, 0);
5941 gtk_widget_unref(compose->edit_vbox);
5943 compose->use_attach = FALSE;
5949 static void compose_toggle_sign_cb(gpointer data, guint action,
5952 Compose *compose = (Compose *)data;
5954 if (GTK_CHECK_MENU_ITEM(widget)->active)
5955 compose->use_signing = TRUE;
5957 compose->use_signing = FALSE;
5960 static void compose_toggle_encrypt_cb(gpointer data, guint action,
5963 Compose *compose = (Compose *)data;
5965 if (GTK_CHECK_MENU_ITEM(widget)->active)
5966 compose->use_encryption = TRUE;
5968 compose->use_encryption = FALSE;
5970 #endif /* USE_GPGME */
5972 static void compose_toggle_ruler_cb(gpointer data, guint action,
5975 Compose *compose = (Compose *)data;
5977 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5978 gtk_widget_show(compose->ruler_hbox);
5979 prefs_common.show_ruler = TRUE;
5981 gtk_widget_hide(compose->ruler_hbox);
5982 gtk_widget_queue_resize(compose->edit_vbox);
5983 prefs_common.show_ruler = FALSE;
5987 static void compose_attach_drag_received_cb (GtkWidget *widget,
5988 GdkDragContext *drag_context,
5991 GtkSelectionData *data,
5996 Compose *compose = (Compose *)user_data;
5999 list = uri_list_extract_filenames((const gchar *)data->data);
6000 for (tmp = list; tmp != NULL; tmp = tmp->next)
6001 compose_attach_append(compose, (const gchar *)tmp->data,
6003 list_free_strings(list);
6007 static void compose_insert_drag_received_cb (GtkWidget *widget,
6008 GdkDragContext *drag_context,
6011 GtkSelectionData *data,
6016 Compose *compose = (Compose *)user_data;
6019 list = uri_list_extract_filenames((const gchar *)data->data);
6020 for (tmp = list; tmp != NULL; tmp = tmp->next)
6021 compose_insert_file(compose, (const gchar *)tmp->data);
6022 list_free_strings(list);
6026 #if 0 /* NEW COMPOSE GUI */
6027 static void to_activated(GtkWidget *widget, Compose *compose)
6029 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6030 gtk_widget_grab_focus(compose->newsgroups_entry);
6032 gtk_widget_grab_focus(compose->subject_entry);
6035 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6037 gtk_widget_grab_focus(compose->subject_entry);
6040 static void subject_activated(GtkWidget *widget, Compose *compose)
6042 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6043 gtk_widget_grab_focus(compose->cc_entry);
6044 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6045 gtk_widget_grab_focus(compose->bcc_entry);
6046 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6047 gtk_widget_grab_focus(compose->reply_entry);
6048 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6049 gtk_widget_grab_focus(compose->followup_entry);
6051 gtk_widget_grab_focus(compose->text);
6054 static void cc_activated(GtkWidget *widget, Compose *compose)
6056 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6057 gtk_widget_grab_focus(compose->bcc_entry);
6058 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6059 gtk_widget_grab_focus(compose->reply_entry);
6060 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6061 gtk_widget_grab_focus(compose->followup_entry);
6063 gtk_widget_grab_focus(compose->text);
6066 static void bcc_activated(GtkWidget *widget, Compose *compose)
6068 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6069 gtk_widget_grab_focus(compose->reply_entry);
6070 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6071 gtk_widget_grab_focus(compose->followup_entry);
6073 gtk_widget_grab_focus(compose->text);
6076 static void replyto_activated(GtkWidget *widget, Compose *compose)
6078 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6079 gtk_widget_grab_focus(compose->followup_entry);
6081 gtk_widget_grab_focus(compose->text);
6084 static void followupto_activated(GtkWidget *widget, Compose *compose)
6086 gtk_widget_grab_focus(compose->text);
6090 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6093 Compose *compose = (Compose *)data;
6095 if (GTK_CHECK_MENU_ITEM(widget)->active)
6096 compose->return_receipt = TRUE;
6098 compose->return_receipt = FALSE;
6101 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6103 ComposeHeaderEntry *headerentry)
6105 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6106 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6107 !(event->state & GDK_MODIFIER_MASK) &&
6108 (event->keyval == GDK_BackSpace) &&
6109 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6110 gtk_container_remove
6111 (GTK_CONTAINER(headerentry->compose->header_table),
6112 headerentry->combo);
6113 gtk_container_remove
6114 (GTK_CONTAINER(headerentry->compose->header_table),
6115 headerentry->entry);
6116 headerentry->compose->header_list =
6117 g_slist_remove(headerentry->compose->header_list,
6119 g_free(headerentry);
6123 void compose_headerentry_changed_cb(GtkWidget *entry,
6124 ComposeHeaderEntry *headerentry)
6126 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6127 headerentry->compose->header_list =
6128 g_slist_append(headerentry->compose->header_list,
6130 compose_create_header_entry(headerentry->compose);
6131 gtk_signal_disconnect_by_func
6133 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6141 * Change the sensivity of the menuentries undo and redo
6143 static void compose_set_undo (UndoMain *undostruct, gint undo_state, gint redo_state, GtkWidget *changewidget) {
6144 GtkItemFactory *ifactory;
6145 debug_print ("Set_undo. UNDO:%i REDO:%i\n",
6149 g_return_if_fail (changewidget != NULL);
6151 ifactory = gtk_item_factory_from_widget(changewidget);
6154 switch (undo_state) {
6155 case UNDO_STATE_TRUE:
6156 if (!undostruct->undo_state) {
6157 debug_print ("Set_undo - Testpoint\n");
6158 undostruct->undo_state = TRUE;
6159 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6162 case UNDO_STATE_FALSE:
6163 if (undostruct->undo_state) {
6164 undostruct->undo_state = FALSE;
6165 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6168 case UNDO_STATE_UNCHANGED:
6170 case UNDO_STATE_REFRESH:
6171 menu_set_sensitive(ifactory, "/Edit/Undo", undostruct->undo_state);
6174 g_warning ("Undo state not recognized");
6178 switch (redo_state) {
6179 case UNDO_STATE_TRUE:
6180 if (!undostruct->redo_state) {
6181 undostruct->redo_state = TRUE;
6182 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6185 case UNDO_STATE_FALSE:
6186 if (undostruct->redo_state) {
6187 undostruct->redo_state = FALSE;
6188 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6191 case UNDO_STATE_UNCHANGED:
6193 case UNDO_STATE_REFRESH:
6194 menu_set_sensitive(ifactory, "/Edit/Redo", undostruct->redo_state);
6197 g_warning ("Redo state not recognized");