2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999,2000 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"
103 # include "rfc2015.h"
113 #define N_ATTACH_COLS 3
115 #define B64_LINE_SIZE 57
116 #define B64_BUFFSIZE 77
118 #define MAX_REFERENCES_LEN 999
120 static GdkColor quote_color = {0, 0, 0, 0xbfff};
122 static GList *compose_list = NULL;
124 static Compose *compose_create (PrefsAccount *account);
125 static void compose_toolbar_create (Compose *compose,
126 GtkWidget *container);
127 static GtkWidget *compose_account_option_menu_create
129 static void compose_destroy (Compose *compose);
131 static gint compose_parse_header (Compose *compose,
133 static gchar *compose_parse_references (const gchar *ref,
135 static void compose_quote_file (Compose *compose,
138 static gchar *compose_quote_parse_fmt (Compose *compose,
141 static void compose_reply_set_entry (Compose *compose,
144 static void compose_reedit_set_entry (Compose *compose,
146 static void compose_insert_sig (Compose *compose);
147 static void compose_insert_file (Compose *compose,
149 static void compose_attach_append (Compose *compose,
151 ContentType cnttype);
152 static void compose_wrap_line (Compose *compose);
153 static void compose_set_title (Compose *compose);
155 /* static gint compose_send (Compose *compose); */
156 static gint compose_write_to_file (Compose *compose,
159 static gint compose_write_body_to_file (Compose *compose,
161 static gint compose_save_to_outbox (Compose *compose,
163 static gint compose_queue (Compose *compose,
165 static void compose_write_attach (Compose *compose,
167 static gint compose_write_headers (Compose *compose,
169 const gchar *charset,
170 EncodingType encoding,
173 static void compose_convert_header (gchar *dest,
177 static void compose_generate_msgid (Compose *compose,
181 static void compose_attach_info_free (AttachInfo *ainfo);
182 static void compose_attach_remove_selected (Compose *compose);
184 static void compose_attach_property (Compose *compose);
185 static void compose_attach_property_create (gboolean *cancelled);
186 static void attach_property_ok (GtkWidget *widget,
187 gboolean *cancelled);
188 static void attach_property_cancel (GtkWidget *widget,
189 gboolean *cancelled);
190 static gint attach_property_delete_event (GtkWidget *widget,
192 gboolean *cancelled);
193 static void attach_property_key_pressed (GtkWidget *widget,
195 gboolean *cancelled);
197 static void compose_exec_ext_editor (Compose *compose);
198 static gint compose_exec_ext_editor_real (const gchar *file);
199 static gboolean compose_ext_editor_kill (Compose *compose);
200 static void compose_input_cb (gpointer data,
202 GdkInputCondition condition);
203 static void compose_set_ext_editor_sensitive (Compose *compose,
206 static gint calc_cursor_xpos (GtkSText *text,
210 /* callback functions */
212 static gboolean compose_edit_size_alloc (GtkEditable *widget,
213 GtkAllocation *allocation,
214 GtkSHRuler *shruler);
216 static void toolbar_send_cb (GtkWidget *widget,
218 static void toolbar_send_later_cb (GtkWidget *widget,
220 static void toolbar_draft_cb (GtkWidget *widget,
222 static void toolbar_insert_cb (GtkWidget *widget,
224 static void toolbar_attach_cb (GtkWidget *widget,
226 static void toolbar_sig_cb (GtkWidget *widget,
228 static void toolbar_ext_editor_cb (GtkWidget *widget,
230 static void toolbar_linewrap_cb (GtkWidget *widget,
232 static void toolbar_address_cb (GtkWidget *widget,
235 static void account_activated (GtkMenuItem *menuitem,
238 static void attach_selected (GtkCList *clist,
243 static void attach_button_pressed (GtkWidget *widget,
244 GdkEventButton *event,
246 static void attach_key_pressed (GtkWidget *widget,
250 static void compose_send_cb (gpointer data,
253 static void compose_send_later_cb (gpointer data,
257 static void compose_draft_cb (gpointer data,
261 static void compose_attach_cb (gpointer data,
264 static void compose_insert_file_cb (gpointer data,
268 static void compose_close_cb (gpointer data,
271 static void compose_address_cb (gpointer data,
275 static void compose_ext_editor_cb (gpointer data,
279 static gint compose_delete_cb (GtkWidget *widget,
282 static void compose_destroy_cb (GtkWidget *widget,
285 static void compose_cut_cb (Compose *compose);
286 static void compose_copy_cb (Compose *compose);
287 static void compose_paste_cb (Compose *compose);
288 static void compose_allsel_cb (Compose *compose);
290 static void compose_grab_focus_cb (GtkWidget *widget,
293 static void compose_changed_cb (GtkEditable *editable,
295 static void compose_button_press_cb (GtkWidget *widget,
296 GdkEventButton *event,
299 static void compose_key_press_cb (GtkWidget *widget,
304 static void compose_toggle_to_cb (gpointer data,
307 static void compose_toggle_cc_cb (gpointer data,
310 static void compose_toggle_bcc_cb (gpointer data,
313 static void compose_toggle_replyto_cb (gpointer data,
316 static void compose_toggle_followupto_cb(gpointer data,
319 static void compose_toggle_attach_cb (gpointer data,
322 static void compose_toggle_ruler_cb (gpointer data,
326 static void compose_toggle_sign_cb (gpointer data,
329 static void compose_toggle_encrypt_cb (gpointer data,
333 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
336 static void compose_attach_drag_received_cb (GtkWidget *widget,
337 GdkDragContext *drag_context,
340 GtkSelectionData *data,
344 static void compose_insert_drag_received_cb (GtkWidget *widget,
345 GdkDragContext *drag_context,
348 GtkSelectionData *data,
353 static void to_activated (GtkWidget *widget,
355 static void newsgroups_activated (GtkWidget *widget,
357 static void subject_activated (GtkWidget *widget,
359 static void cc_activated (GtkWidget *widget,
361 static void bcc_activated (GtkWidget *widget,
363 static void replyto_activated (GtkWidget *widget,
365 static void followupto_activated (GtkWidget *widget,
368 static GtkItemFactoryEntry compose_popup_entries[] =
370 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
371 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
372 {N_("/---"), NULL, NULL, 0, "<Separator>"},
373 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
376 static GtkItemFactoryEntry compose_entries[] =
378 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
379 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
380 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
381 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
382 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
383 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
385 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
386 {N_("/_Edit/_Undo"), "<control>Z", NULL, 0, NULL},
387 {N_("/_Edit/_Redo"), "<control>Y", NULL, 0, NULL},
388 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
389 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
390 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
391 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
392 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
393 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
394 {N_("/_Edit/Wrap long _lines"), "<alt>L", compose_wrap_line, 0, NULL},
395 {N_("/_Edit/Edit with e_xternal editor"), "<alt>X",
396 compose_ext_editor_cb, 0, NULL},
398 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
399 {N_("/_Message/_Send"), "<shift><control>S",
400 compose_send_cb, 0, NULL},
401 {N_("/_Message/Send _later"), "<shift><alt>S",
402 compose_send_later_cb, 0, NULL},
403 {N_("/_Message/Save to _draft folder"),
404 "<alt>D", compose_draft_cb, 0, NULL},
405 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
406 {N_("/_Message/_To"), NULL, compose_toggle_to_cb, 0, "<ToggleItem>"},
407 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb, 0, "<ToggleItem>"},
408 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb, 0, "<ToggleItem>"},
409 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
410 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
411 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
412 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
413 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
415 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
416 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb, 0, "<ToggleItem>"},
417 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
418 #endif /* USE_GPGME */
419 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
420 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
421 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
422 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
423 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb, 0, NULL},
424 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
425 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
428 static GtkTargetEntry compose_mime_types[] =
430 {"text/uri-list", 0, 0}
433 Compose * compose_new(PrefsAccount *account)
435 return compose_new_with_recipient(account, NULL);
438 Compose * compose_new_with_recipient(PrefsAccount *account, const gchar *to)
442 if (!account) account = cur_account;
443 g_return_if_fail(account != NULL);
445 compose = compose_create(account);
446 compose->mode = COMPOSE_NEW;
448 if (prefs_common.auto_sig)
449 compose_insert_sig(compose);
450 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
451 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
453 if (account->protocol != A_NNTP) {
455 compose_entry_append(compose, to, COMPOSE_TO);
456 gtk_widget_grab_focus(compose->subject_entry);
458 gtk_widget_grab_focus(compose->to_entry);
460 gtk_widget_grab_focus(compose->newsgroups_entry);
465 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all)
468 PrefsAccount *account;
471 g_return_if_fail(msginfo != NULL);
472 g_return_if_fail(msginfo->folder != NULL);
474 account = msginfo->folder->folder->account;
475 if (!account) account = cur_account;
476 g_return_if_fail(account != NULL);
478 MSG_UNSET_FLAGS(msginfo->flags, MSG_FORWARDED);
479 MSG_SET_FLAGS(msginfo->flags, MSG_REPLIED);
481 compose = compose_create(account);
482 compose->mode = COMPOSE_REPLY;
484 if (compose_parse_header(compose, msginfo) < 0) return;
485 compose_reply_set_entry(compose, msginfo, to_all);
487 text = GTK_STEXT(compose->text);
488 gtk_stext_freeze(text);
494 if ((fp = procmime_get_text_part(msginfo)) == NULL)
495 g_warning(_("Can't get text part\n"));
497 quote_str = compose_quote_parse_fmt
498 (compose, msginfo, prefs_common.quotefmt);
499 gtk_stext_insert(text, NULL, NULL, NULL, quote_str, -1);
501 compose_quote_file(compose, msginfo, fp);
506 if (prefs_common.auto_sig)
507 compose_insert_sig(compose);
508 gtk_editable_set_position(GTK_EDITABLE(text), 0);
509 gtk_stext_set_point(text, 0);
511 gtk_stext_thaw(text);
512 gtk_widget_grab_focus(compose->text);
515 #define INSERT_FW_HEADER(var, hdr) \
516 if (msginfo->var && *msginfo->var) { \
517 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
518 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
519 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
522 Compose * compose_forward(PrefsAccount * account, MsgInfo *msginfo,
526 /* PrefsAccount *account; */
531 g_return_if_fail(msginfo != NULL);
532 g_return_if_fail(msginfo->folder != NULL);
534 if (account == NULL) {
535 account = msginfo->folder->folder->account;
536 if (!account) account = cur_account;
538 g_return_if_fail(account != NULL);
540 MSG_UNSET_FLAGS(msginfo->flags, MSG_REPLIED);
541 MSG_SET_FLAGS(msginfo->flags, MSG_FORWARDED);
543 compose = compose_create(account);
544 compose->mode = COMPOSE_FORWARD;
546 if (msginfo->subject && *msginfo->subject) {
547 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
548 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
552 text = GTK_STEXT(compose->text);
553 gtk_stext_freeze(text);
558 msgfile = procmsg_get_message_file_path(msginfo);
559 if (!is_file_exist(msgfile))
560 g_warning(_("%s: file not exist\n"), msgfile);
562 compose_attach_append(compose, msgfile,
563 MIME_MESSAGE_RFC822);
567 if ((fp = procmime_get_text_part(msginfo)) == NULL)
568 g_warning(_("Can't get text part\n"));
571 gtk_stext_insert(text, NULL, NULL, NULL,
572 _("\n\nBegin forwarded message:\n\n"), -1);
573 INSERT_FW_HEADER(date, "Date: ");
574 INSERT_FW_HEADER(from, "From: ");
575 INSERT_FW_HEADER(to, "To: ");
576 INSERT_FW_HEADER(newsgroups, "Newsgroups: ");
577 INSERT_FW_HEADER(subject, "Subject: ");
578 gtk_stext_insert(text, NULL, NULL, NULL, "\n\n", 2);
581 while (fgets(buf, sizeof(buf), fp) != NULL)
582 gtk_stext_insert(text, NULL, NULL, NULL,
588 if (prefs_common.auto_sig)
589 compose_insert_sig(compose);
590 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
591 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
593 gtk_stext_thaw(text);
594 if (account->protocol != A_NNTP)
595 gtk_widget_grab_focus(compose->to_entry);
597 gtk_widget_grab_focus(compose->newsgroups_entry);
602 #undef INSERT_FW_HEADER
604 void compose_reedit(MsgInfo *msginfo)
607 PrefsAccount *account;
612 g_return_if_fail(msginfo != NULL);
613 g_return_if_fail(msginfo->folder != NULL);
615 account = msginfo->folder->folder->account;
616 if (!account) account = cur_account;
617 g_return_if_fail(account != NULL);
619 compose = compose_create(account);
620 compose->mode = COMPOSE_REEDIT_DRAFT;
621 compose->targetinfo = procmsg_msginfo_copy(msginfo);
623 if (compose_parse_header(compose, msginfo) < 0) return;
624 compose_reedit_set_entry(compose, msginfo);
626 text = GTK_STEXT(compose->text);
627 gtk_stext_freeze(text);
629 if ((fp = procmime_get_text_part(msginfo)) == NULL)
630 g_warning(_("Can't get text part\n"));
632 while (fgets(buf, sizeof(buf), fp) != NULL)
633 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
637 gtk_stext_thaw(text);
638 gtk_widget_grab_focus(compose->text);
641 GList *compose_get_compose_list(void)
646 void compose_entry_append(Compose *compose, const gchar *address,
647 ComposeEntryType type)
652 if (!address || *address == '\0') return;
656 entry = GTK_ENTRY(compose->cc_entry);
659 entry = GTK_ENTRY(compose->bcc_entry);
661 case COMPOSE_NEWSGROUPS:
662 entry = GTK_ENTRY(compose->newsgroups_entry);
666 entry = GTK_ENTRY(compose->to_entry);
670 text = gtk_entry_get_text(entry);
672 gtk_entry_append_text(entry, ", ");
673 gtk_entry_append_text(entry, address);
676 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
678 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
679 {"Cc:", NULL, FALSE},
680 {"References:", NULL, FALSE},
681 {"Bcc:", NULL, FALSE},
682 {"Newsgroups:", NULL, FALSE},
683 {"Followup-To:", NULL, FALSE},
684 {NULL, NULL, FALSE}};
698 g_return_val_if_fail(msginfo != NULL, -1);
700 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
701 procheader_get_header_fields(fp, hentry);
704 if (hentry[H_REPLY_TO].body != NULL) {
705 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
706 compose->replyto = hentry[H_REPLY_TO].body;
707 hentry[H_REPLY_TO].body = NULL;
709 if (hentry[H_CC].body != NULL) {
710 conv_unmime_header_overwrite(hentry[H_CC].body);
711 compose->cc = hentry[H_CC].body;
712 hentry[H_CC].body = NULL;
714 if (hentry[H_REFERENCES].body != NULL) {
715 if (compose->mode == COMPOSE_REEDIT_DRAFT)
716 compose->references = hentry[H_REFERENCES].body;
718 compose->references = compose_parse_references
719 (hentry[H_REFERENCES].body, msginfo->msgid);
720 g_free(hentry[H_REFERENCES].body);
722 hentry[H_REFERENCES].body = NULL;
724 if (hentry[H_BCC].body != NULL) {
725 if (compose->mode == COMPOSE_REEDIT_DRAFT) {
726 conv_unmime_header_overwrite(hentry[H_BCC].body);
727 compose->bcc = hentry[H_BCC].body;
729 g_free(hentry[H_BCC].body);
730 hentry[H_BCC].body = NULL;
732 if (hentry[H_NEWSGROUPS].body != NULL) {
733 compose->newsgroups = hentry[H_NEWSGROUPS].body;
734 hentry[H_NEWSGROUPS].body = NULL;
736 if (hentry[H_FOLLOWUP_TO].body != NULL) {
737 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
738 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
739 hentry[H_FOLLOWUP_TO].body = NULL;
742 if (compose->mode == COMPOSE_REEDIT_DRAFT && msginfo->inreplyto)
743 compose->inreplyto = g_strdup(msginfo->inreplyto);
744 else if (compose->mode != COMPOSE_REEDIT_DRAFT &&
745 msginfo->msgid && *msginfo->msgid) {
746 compose->inreplyto = g_strdup(msginfo->msgid);
748 if (!compose->references) {
749 if (msginfo->inreplyto && *msginfo->inreplyto)
750 compose->references =
751 g_strdup_printf("<%s>\n\t<%s>",
755 compose->references =
756 g_strconcat("<", msginfo->msgid, ">",
764 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
766 GSList *ref_id_list, *cur;
770 ref_id_list = references_list_append(NULL, ref);
771 if (!ref_id_list) return NULL;
773 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
778 for (cur = ref_id_list; cur != NULL; cur = cur->next)
779 /* "<" + Message-ID + ">" + CR+LF+TAB */
780 len += strlen((gchar *)cur->data) + 5;
782 if (len > MAX_REFERENCES_LEN) {
783 /* remove second message-ID */
784 if (ref_id_list && ref_id_list->next &&
785 ref_id_list->next->next) {
786 g_free(ref_id_list->next->data);
787 ref_id_list = g_slist_remove
788 (ref_id_list, ref_id_list->next->data);
790 slist_free_strings(ref_id_list);
791 g_slist_free(ref_id_list);
798 new_ref = g_string_new("");
799 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
800 if (new_ref->len > 0)
801 g_string_append(new_ref, "\n\t");
802 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
805 slist_free_strings(ref_id_list);
806 g_slist_free(ref_id_list);
808 new_ref_str = new_ref->str;
809 g_string_free(new_ref, FALSE);
814 static void compose_quote_file(Compose *compose, MsgInfo *msginfo, FILE *fp)
816 GtkSText *text = GTK_STEXT(compose->text);
819 GdkColor *qcolor = NULL;
822 gchar *linep, *cur, *leftp;
823 gint line_len, cur_len;
828 /* if (prefs_common.enable_color) qcolor = "e_color; */
829 if (prefs_common.quotemark && *prefs_common.quotemark)
830 qmark = prefs_common.quotemark;
833 quote_str = compose_quote_parse_fmt(compose, msginfo, qmark);
834 g_return_if_fail(quote_str != NULL);
835 qlen = strlen(quote_str);
837 if (!prefs_common.linewrap_quote ||
838 prefs_common.linewrap_len <= qlen) {
839 while (fgets(buf, sizeof(buf), fp) != NULL) {
840 gtk_stext_insert(text, NULL, qcolor, NULL,
842 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
848 wrap_len = prefs_common.linewrap_len - qlen;
850 while (fgets(buf, sizeof(buf), fp) != NULL) {
852 str_len = strlen(buf);
854 if (str_len <= wrap_len) {
855 gtk_stext_insert(text, NULL, qcolor, NULL,
857 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
858 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
862 linep = cur = leftp = buf;
863 line_len = cur_len = 0;
865 while (*cur != '\0') {
866 ch_len = mblen(cur, MB_CUR_MAX);
867 if (ch_len < 0) ch_len = 1;
869 if (ch_len == 1 && isspace(*cur)) {
870 linep = cur + ch_len;
871 line_len = cur_len + ch_len;
874 if (cur_len + ch_len > wrap_len && line_len > 0) {
875 gtk_stext_insert(text, NULL, qcolor, NULL,
878 if (isspace(*(linep - 1)))
879 gtk_stext_insert(text, NULL,
881 leftp, line_len - 1);
883 gtk_stext_insert(text, NULL,
886 gtk_stext_insert(text, NULL, NULL, NULL,
890 cur_len = cur_len - line_len + ch_len;
897 linep = cur + ch_len;
898 line_len = cur_len + ch_len;
905 gtk_stext_insert(text, NULL, qcolor, NULL,
907 gtk_stext_insert(text, NULL, qcolor, NULL, leftp, -1);
908 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
915 static gchar *compose_quote_parse_fmt(Compose *compose, MsgInfo *msginfo,
919 size_t buf_len = 1024;
927 if (!fmt || *fmt == '\0') return 0;
929 Xalloca(mbs, sizeof(wchar_t) + 1, return 0);
930 Xalloca(wcsfmt, (strlen(fmt) + 1) * sizeof(wchar_t), return 0);
931 mbstowcs(wcsfmt, fmt, strlen(fmt) + 1);
934 ext_str = g_malloc(sizeof(gchar) * buf_len);
935 g_return_val_if_fail(ext_str != NULL, NULL);
940 len = wctomb(mbs, *sp);
946 wctomb(mbs, *(++sp));
958 case 'I': /* initial */
959 if (!msginfo->fromname) {sp++; break;}
960 p = msginfo->fromname;
961 tmp[0] = tmp[1] = tmp[2] = '\0';
963 if (*p && isalnum(*p))
964 tmp[0] = toupper(*p);
971 while (*p && !isspace(*p)) p++;
972 while (*p && isspace(*p)) p++;
973 if (*p && isalnum(*p))
974 tmp[1] = toupper(*p);
977 if (tmp[1]) str = tmp;
981 str = msginfo->fromname;
985 if (!msginfo->fromname) {sp++; break;}
986 Xstrdup_a(str, msginfo->fromname,
989 while (*p && !isspace(*p)) p++;
994 str = msginfo->subject;
1002 if (!msginfo->msgid) {sp++; break;}
1003 Xalloca(str, strlen(msginfo->msgid) + 3,
1005 g_snprintf(str, strlen(msginfo->msgid) + 3,
1006 "<%s>", msginfo->msgid);
1018 while (ext_len + strlen(str) + 1 > buf_len)
1020 ext_str = g_realloc(ext_str,
1021 sizeof(gchar) * buf_len);
1022 g_return_val_if_fail(ext_str != NULL, NULL);
1023 strcpy(ext_str + ext_len, str);
1024 ext_len += strlen(str);
1026 } else if (*mbs == '\\') {
1027 wctomb(mbs, *(++sp));
1045 while (ext_len + strlen(str) + 1 > buf_len)
1047 ext_str = g_realloc(ext_str,
1048 sizeof(gchar) * buf_len);
1049 g_return_val_if_fail(ext_str != NULL, NULL);
1050 strcpy(ext_str + ext_len, str);
1051 ext_len += strlen(str);
1055 while (ext_len + len + 1 > buf_len) buf_len += 1024;
1056 ext_str = g_realloc(ext_str, sizeof(gchar) * buf_len);
1057 g_return_val_if_fail(ext_str != NULL, NULL);
1058 strcpy(ext_str + ext_len, mbs);
1065 ext_str = g_realloc(ext_str, strlen(ext_str) + 1);
1070 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1076 GHashTable *to_table;
1078 g_return_if_fail(compose->account != NULL);
1079 g_return_if_fail(msginfo != NULL);
1081 if (compose->account->protocol != A_NNTP)
1082 gtk_entry_set_text(GTK_ENTRY(compose->to_entry),
1083 compose->replyto ? compose->replyto
1084 : msginfo->from ? msginfo->from : "");
1085 if (compose->account->protocol == A_NNTP)
1086 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry),
1087 compose->followup_to ? compose->followup_to
1088 : compose->newsgroups ? compose->newsgroups
1091 if (msginfo->subject && *msginfo->subject) {
1092 gchar *buf, *buf2, *p;
1094 buf = g_strdup(msginfo->subject);
1095 while (!strncasecmp(buf, "Re:", 3)) {
1097 while (isspace(*p)) p++;
1098 memmove(buf, p, strlen(p) + 1);
1101 buf2 = g_strdup_printf("Re: %s", buf);
1102 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1106 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1108 if (!to_all || compose->account->protocol == A_NNTP) return;
1110 from = g_strdup(compose->replyto ? compose->replyto :
1111 msginfo->from ? msginfo->from : "");
1112 extract_address(from);
1114 cc_list = address_list_append(NULL, msginfo->to);
1115 cc_list = address_list_append(cc_list, compose->cc);
1117 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1118 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1119 if (compose->account)
1120 g_hash_table_insert(to_table, compose->account->address,
1121 GINT_TO_POINTER(1));
1123 /* remove address on To: and that of current account */
1124 for (cur = cc_list; cur != NULL; ) {
1125 GSList *next = cur->next;
1127 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1128 cc_list = g_slist_remove(cc_list, cur->data);
1130 g_hash_table_insert(to_table, cur->data, cur);
1134 g_hash_table_destroy(to_table);
1138 for (cur = cc_list; cur != NULL; cur = cur->next)
1139 compose_entry_append(compose, (gchar *)cur->data,
1141 slist_free_strings(cc_list);
1142 g_slist_free(cc_list);
1146 #define SET_ENTRY(entry, str) \
1149 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1152 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1154 g_return_if_fail(msginfo != NULL);
1156 SET_ENTRY(to_entry, msginfo->to);
1157 SET_ENTRY(subject_entry, msginfo->subject);
1158 SET_ENTRY(cc_entry, compose->cc);
1159 SET_ENTRY(bcc_entry, compose->bcc);
1160 SET_ENTRY(reply_entry, compose->replyto);
1163 GtkItemFactory *ifactory;
1164 GtkWidget *menuitem;
1166 ifactory = gtk_item_factory_from_widget(compose->menubar);
1167 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1168 gtk_check_menu_item_set_active
1169 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1171 if (compose->replyto) {
1172 GtkItemFactory *ifactory;
1173 GtkWidget *menuitem;
1175 ifactory = gtk_item_factory_from_widget(compose->menubar);
1176 menuitem = gtk_item_factory_get_item
1177 (ifactory, "/Message/Reply to");
1178 gtk_check_menu_item_set_active
1179 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1185 static void compose_insert_sig(Compose *compose)
1189 if (compose->account && compose->account->sig_path)
1190 sigfile = g_strdup(compose->account->sig_path);
1192 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1193 DEFAULT_SIGNATURE, NULL);
1196 if (!is_file_or_fifo_exist(sigfile)) {
1201 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1202 if (prefs_common.sig_sep) {
1203 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1204 prefs_common.sig_sep, -1);
1205 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1209 compose_insert_file(compose, sigfile);
1213 static void compose_insert_file(Compose *compose, const gchar *file)
1215 GtkSText *text = GTK_STEXT(compose->text);
1216 gchar buf[BUFFSIZE];
1219 g_return_if_fail(file != NULL);
1221 if ((fp = fopen(file, "r")) == NULL) {
1222 FILE_OP_ERROR(file, "fopen");
1226 gtk_stext_freeze(text);
1228 while (fgets(buf, sizeof(buf), fp) != NULL)
1229 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1231 gtk_stext_thaw(text);
1236 static void compose_attach_append(Compose *compose, const gchar *file,
1237 ContentType cnttype)
1240 gchar *text[N_ATTACH_COLS];
1244 if (!is_file_exist(file)) {
1245 g_warning(_("File %s doesn't exist\n"), file);
1248 if ((size = get_file_size(file)) < 0) {
1249 g_warning(_("Can't get file size of %s\n"), file);
1253 alertpanel_notice(_("File %s is empty\n"), file);
1257 if (!compose->use_attach) {
1258 GtkItemFactory *ifactory;
1259 GtkWidget *menuitem;
1261 ifactory = gtk_item_factory_from_widget(compose->menubar);
1262 menuitem = gtk_item_factory_get_item(ifactory,
1264 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1268 ainfo = g_new0(AttachInfo, 1);
1269 ainfo->file = g_strdup(file);
1271 if (cnttype == MIME_MESSAGE_RFC822) {
1272 ainfo->content_type = g_strdup("message/rfc822");
1273 ainfo->encoding = ENC_7BIT;
1274 ainfo->name = g_strdup_printf(_("Message: %s"),
1277 ainfo->content_type = procmime_get_mime_type(file);
1278 if (!ainfo->content_type)
1279 ainfo->content_type =
1280 g_strdup("application/octet-stream");
1281 ainfo->encoding = ENC_BASE64;
1282 ainfo->name = g_strdup(g_basename(file));
1286 text[COL_MIMETYPE] = ainfo->content_type;
1287 text[COL_SIZE] = to_human_readable(size);
1288 text[COL_NAME] = ainfo->name;
1290 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1291 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1293 if (cnttype != MIME_MESSAGE_RFC822)
1294 compose_changed_cb(NULL, compose);
1297 static void compose_wrap_line(Compose *compose)
1299 GtkSText *text = GTK_STEXT(compose->text);
1301 guint line_pos = 0, cur_pos = 0;
1302 gint line_len = 0, cur_len = 0;
1304 gchar cbuf[MB_CUR_MAX];
1306 gtk_stext_freeze(text);
1308 text_len = gtk_stext_get_length(text);
1310 for (; cur_pos < text_len; cur_pos++) {
1311 if (text->use_wchar)
1313 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
1315 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
1319 if (ch_len == 1 && *cbuf == '\n') {
1320 line_pos = cur_pos + 1;
1321 line_len = cur_len = 0;
1330 if (ch_len == 1 && isspace(*cbuf)) {
1331 line_pos = cur_pos + 1;
1332 line_len = cur_len + ch_len;
1335 if (cur_len + ch_len > prefs_common.linewrap_len &&
1339 if (text->use_wchar)
1340 tlen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
1342 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
1345 if (tlen == 1 && isspace(*cbuf)) {
1346 gtk_stext_set_point(text, line_pos);
1347 gtk_stext_backward_delete(text, 1);
1355 gtk_stext_set_point(text, line_pos);
1356 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1360 cur_len = cur_len - line_len + ch_len;
1366 line_pos = cur_pos + 1;
1367 line_len = cur_len + ch_len;
1372 gtk_stext_thaw(text);
1375 static void compose_set_title(Compose *compose)
1380 edited = compose->modified ? _(" [Edited]") : "";
1381 if (compose->account && compose->account->address)
1382 str = g_strdup_printf(_("%s - Compose message%s"),
1383 compose->account->address, edited);
1385 str = g_strdup_printf(_("Compose message%s"), edited);
1386 gtk_window_set_title(GTK_WINDOW(compose->window), str);
1390 gint compose_send(Compose *compose)
1392 gchar tmp[MAXPATHLEN + 1];
1393 gchar *to, *newsgroups;
1395 static gboolean lock = FALSE;
1399 g_return_val_if_fail(compose->account != NULL, -1);
1400 g_return_val_if_fail(compose->orig_account != NULL, -1);
1404 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
1405 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
1406 if (*to == '\0' && *newsgroups == '\0') {
1407 alertpanel_error(_("Recipient is not specified."));
1412 /* write to temporary file */
1413 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
1414 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
1416 if (prefs_common.linewrap_at_send)
1417 compose_wrap_line(compose);
1419 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
1424 if (!compose->to_list && !compose->newsgroup_list) {
1425 g_warning(_("can't get recipient list."));
1431 if (compose->to_list) {
1434 if (compose->account->protocol != A_NNTP)
1435 ac = compose->account;
1436 else if (compose->orig_account->protocol != A_NNTP)
1437 ac = compose->orig_account;
1438 else if (cur_account && cur_account->protocol != A_NNTP)
1441 ac = account_get_default();
1442 if (!ac || ac->protocol == A_NNTP) {
1443 alertpanel_error(_("Account for sending mail is not specified.\n"
1444 "Please select a mail account before sending."));
1450 ok = send_message(tmp, ac, compose->to_list);
1451 statusbar_pop_all();
1454 if (ok == 0 && compose->newsgroup_list) {
1457 if (compose->account->protocol == A_NNTP)
1458 folder = FOLDER(compose->account->folder);
1460 folder = FOLDER(compose->orig_account->folder);
1462 ok = news_post(folder, tmp);
1464 alertpanel_error(_("Error occurred while posting the message to %s ."),
1465 compose->account->nntp_server);
1472 /* queue message if failed to send */
1474 if (prefs_common.queue_msg) {
1479 _("Error occurred while sending the message.\n"
1480 "Put this message into queue folder?"),
1481 _("OK"), _("Cancel"), NULL);
1482 if (G_ALERTDEFAULT == val) {
1483 ok = compose_queue(compose, tmp);
1485 alertpanel_error(_("Can't queue the message."));
1488 alertpanel_error(_("Error occurred while sending the message."));
1491 /* save message to outbox */
1492 if (ok == 0 && prefs_common.savemsg) {
1493 if (compose_save_to_outbox(compose, tmp) < 0)
1495 (_("Can't save the message to outbox."));
1503 static gint compose_write_to_file(Compose *compose, const gchar *file,
1510 const gchar *out_codeset;
1511 EncodingType encoding;
1513 if ((fp = fopen(file, "w")) == NULL) {
1514 FILE_OP_ERROR(file, "fopen");
1518 /* chmod for security */
1519 if (change_file_mode_rw(fp, file) < 0) {
1520 FILE_OP_ERROR(file, "chmod");
1521 g_warning(_("can't change file mode\n"));
1524 /* get all composed text */
1525 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
1526 len = strlen(chars);
1527 if (is_ascii_str(chars)) {
1528 buf = g_strdup(chars);
1529 out_codeset = "US-ASCII";
1530 encoding = ENC_7BIT;
1532 const gchar *src_codeset;
1534 out_codeset = conv_get_outgoing_charset_str();
1535 if (!strcasecmp(out_codeset, "US-ASCII"))
1536 out_codeset = "ISO-8859-1";
1537 encoding = procmime_get_encoding_for_charset(out_codeset);
1538 debug_print("charset = %s, encoding = %s\n",
1539 out_codeset, procmime_get_encoding_str(encoding));
1541 src_codeset = conv_get_current_charset_str();
1542 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
1547 alertpanel_error(_("Can't convert the codeset of the message."));
1554 if (compose_write_headers
1555 (compose, fp, out_codeset, encoding, is_draft) < 0) {
1556 g_warning(_("can't write headers\n"));
1563 if (compose->use_attach) {
1565 /* This prolog message is ignored by mime software and
1566 * because it would make our signing/encryption task
1567 * tougher, we don't emit it in that case */
1568 if (!compose->use_signing && !compose->use_encryption)
1570 fputs("This is a multi-part message in MIME format.\n", fp);
1572 fprintf(fp, "\n--%s\n", compose->boundary);
1573 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
1575 fprintf(fp, "Content-Transfer-Encoding: %s\n",
1576 procmime_get_encoding_str(encoding));
1582 if (encoding == ENC_BASE64) {
1583 gchar outbuf[B64_BUFFSIZE];
1586 for (i = 0; i < len; i += B64_LINE_SIZE) {
1587 l = MIN(B64_LINE_SIZE, len - i);
1588 to64frombits(outbuf, buf + i, l);
1592 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
1593 FILE_OP_ERROR(file, "fwrite");
1601 if (compose->use_attach)
1602 compose_write_attach(compose, fp);
1604 if (fclose(fp) == EOF) {
1605 FILE_OP_ERROR(file, "fclose");
1611 if (compose->use_signing) {
1612 if (rfc2015_sign(file, compose->account) < 0) {
1617 if (compose->use_encryption) {
1618 if (rfc2015_encrypt(file, compose->to_list) < 0) {
1623 #endif /* USE_GPGME */
1628 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
1634 if ((fp = fopen(file, "w")) == NULL) {
1635 FILE_OP_ERROR(file, "fopen");
1639 /* chmod for security */
1640 if (change_file_mode_rw(fp, file) < 0) {
1641 FILE_OP_ERROR(file, "chmod");
1642 g_warning(_("can't change file mode\n"));
1645 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
1648 len = strlen(chars);
1649 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
1650 FILE_OP_ERROR(file, "fwrite");
1659 if (fclose(fp) == EOF) {
1660 FILE_OP_ERROR(file, "fclose");
1667 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
1674 debug_print(_("saving sent message...\n"));
1676 outbox = folder_get_default_outbox();
1677 folder_item_scan(outbox);
1678 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
1679 g_warning(_("can't save message\n"));
1683 path = folder_item_get_path(outbox);
1684 if (!is_dir_exist(path))
1685 make_dir_hier(path);
1687 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
1688 g_warning(_("can't open mark file\n"));
1692 newmsginfo.msgnum = num;
1693 newmsginfo.flags = 0;
1694 procmsg_write_flags(&newmsginfo, fp);
1702 static gint compose_queue(Compose *compose, const gchar *file)
1705 gchar *tmp, *queue_path;
1708 gchar buf[BUFFSIZE];
1711 debug_print(_("queueing message...\n"));
1712 g_return_val_if_fail(compose->to_list != NULL, -1);
1713 g_return_val_if_fail(compose->account != NULL, -1);
1715 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
1716 G_DIR_SEPARATOR, (gint)compose);
1717 if ((fp = fopen(tmp, "w")) == NULL) {
1718 FILE_OP_ERROR(tmp, "fopen");
1722 if ((src_fp = fopen(file, "r")) == NULL) {
1723 FILE_OP_ERROR(file, "fopen");
1729 if (change_file_mode_rw(fp, tmp) < 0) {
1730 FILE_OP_ERROR(tmp, "chmod");
1731 g_warning(_("can't change file mode\n"));
1734 /* queueing variables */
1735 fprintf(fp, "AF:\n");
1736 fprintf(fp, "NF:0\n");
1737 fprintf(fp, "PS:10\n");
1738 fprintf(fp, "SRH:1\n");
1739 fprintf(fp, "SFN:\n");
1740 fprintf(fp, "DSR:\n");
1742 fprintf(fp, "MID:<%s>\n", compose->msgid);
1744 fprintf(fp, "MID:\n");
1745 fprintf(fp, "CFG:\n");
1746 fprintf(fp, "PT:0\n");
1747 fprintf(fp, "S:%s\n", compose->account->address);
1748 fprintf(fp, "RQ:\n");
1749 if (compose->account->smtp_server)
1750 fprintf(fp, "SSV:%s\n", compose->account->smtp_server);
1752 fprintf(fp, "SSV:\n");
1753 if (compose->account->nntp_server)
1754 fprintf(fp, "NSV:%s\n", compose->account->nntp_server);
1756 fprintf(fp, "NSV:\n");
1757 fprintf(fp, "SSH:\n");
1758 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
1759 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
1760 fprintf(fp, ",<%s>", (gchar *)cur->data);
1764 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
1765 if (fputs(buf, fp) == EOF) {
1766 FILE_OP_ERROR(tmp, "fputs");
1776 if (fclose(fp) == EOF) {
1777 FILE_OP_ERROR(tmp, "fclose");
1783 queue = folder_get_default_queue();
1784 folder_item_scan(queue);
1785 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
1786 g_warning(_("can't queue the message\n"));
1793 queue_path = folder_item_get_path(queue);
1794 if (!is_dir_exist(queue_path))
1795 make_dir_hier(queue_path);
1797 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
1798 g_warning(_("can't open mark file\n"));
1802 newmsginfo.msgnum = num;
1803 newmsginfo.flags = 0;
1804 procmsg_write_flags(&newmsginfo, fp);
1809 folder_item_scan(queue);
1810 folderview_update_item(queue, TRUE);
1815 static void compose_write_attach(Compose *compose, FILE *fp)
1818 GtkCList *clist = GTK_CLIST(compose->attach_clist);
1821 gchar filename[BUFFSIZE];
1824 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
1826 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
1827 g_warning(_("Can't open file %s\n"), ainfo->file);
1831 fprintf(fp, "\n--%s\n", compose->boundary);
1833 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
1834 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
1835 fprintf(fp, "Content-Disposition: inline\n");
1837 conv_encode_header(filename, sizeof(filename),
1839 fprintf(fp, "Content-Type: %s;\n"
1841 ainfo->content_type, filename);
1842 fprintf(fp, "Content-Disposition: attachment;\n"
1843 " filename=\"%s\"\n", filename);
1846 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
1847 procmime_get_encoding_str(ainfo->encoding));
1849 if (ainfo->encoding == ENC_7BIT) {
1850 gchar buf[BUFFSIZE];
1852 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
1854 if (len > 1 && buf[len - 1] == '\n' &&
1855 buf[len - 2] == '\r') {
1856 buf[len - 2] = '\n';
1857 buf[len - 1] = '\0';
1862 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
1864 while ((len = fread(inbuf, sizeof(gchar),
1865 B64_LINE_SIZE, attach_fp))
1867 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
1871 if (len > 0 && feof(attach_fp)) {
1872 to64frombits(outbuf, inbuf, len);
1881 fprintf(fp, "\n--%s--\n", compose->boundary);
1884 #define IS_IN_CUSTOM_HEADER(header) \
1885 (compose->account->add_customhdr && \
1886 custom_header_find(compose->account->customhdr_list, header) != NULL)
1888 static gint compose_write_headers(Compose *compose, FILE *fp,
1889 const gchar *charset, EncodingType encoding,
1892 gchar buf[BUFFSIZE];
1894 /* struct utsname utsbuf; */
1896 g_return_val_if_fail(fp != NULL, -1);
1897 g_return_val_if_fail(charset != NULL, -1);
1898 g_return_val_if_fail(compose->account != NULL, -1);
1899 g_return_val_if_fail(compose->account->address != NULL, -1);
1902 if (compose->account->add_date) {
1903 get_rfc822_date(buf, sizeof(buf));
1904 fprintf(fp, "Date: %s\n", buf);
1908 if (!IS_IN_CUSTOM_HEADER("From")) {
1909 if (compose->account->name && *compose->account->name) {
1910 compose_convert_header
1911 (buf, sizeof(buf), compose->account->name,
1913 fprintf(fp, "From: %s <%s>\n",
1914 buf, compose->account->address);
1916 fprintf(fp, "From: %s\n", compose->account->address);
1919 slist_free_strings(compose->to_list);
1920 g_slist_free(compose->to_list);
1921 compose->to_list = NULL;
1924 if (compose->use_to) {
1925 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
1927 Xstrdup_a(str, str, return -1);
1930 compose->to_list = address_list_append
1931 (compose->to_list, str);
1932 if (!IS_IN_CUSTOM_HEADER("To")) {
1933 compose_convert_header
1934 (buf, sizeof(buf), str,
1936 fprintf(fp, "To: %s\n", buf);
1942 slist_free_strings(compose->newsgroup_list);
1943 g_slist_free(compose->newsgroup_list);
1944 compose->newsgroup_list = NULL;
1947 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
1949 Xstrdup_a(str, str, return -1);
1953 compose->newsgroup_list =
1954 newsgroup_list_append(compose->newsgroup_list,
1956 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
1957 compose_convert_header(buf, sizeof(buf), str,
1958 strlen("Newsgroups: "));
1959 fprintf(fp, "Newsgroups: %s\n", buf);
1964 if (!is_draft && !compose->to_list && !compose->newsgroup_list)
1968 if (compose->use_cc) {
1969 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
1971 Xstrdup_a(str, str, return -1);
1974 compose->to_list = address_list_append
1975 (compose->to_list, str);
1976 if (!IS_IN_CUSTOM_HEADER("Cc")) {
1977 compose_convert_header
1978 (buf, sizeof(buf), str,
1980 fprintf(fp, "Cc: %s\n", buf);
1987 if (compose->use_bcc) {
1988 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
1990 Xstrdup_a(str, str, return -1);
1993 compose->to_list = address_list_append
1994 (compose->to_list, str);
1996 compose_convert_header
1997 (buf, sizeof(buf), str,
1999 fprintf(fp, "Bcc: %s\n", buf);
2006 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2007 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
2008 Xstrdup_a(str, str, return -1);
2011 compose_convert_header(buf, sizeof(buf), str,
2012 strlen("Subject: "));
2013 fprintf(fp, "Subject: %s\n", buf);
2018 if (compose->account->gen_msgid) {
2019 compose_generate_msgid(compose, buf, sizeof(buf));
2020 fprintf(fp, "Message-Id: <%s>\n", buf);
2021 compose->msgid = g_strdup(buf);
2025 if (compose->inreplyto && compose->to_list)
2026 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
2029 if (compose->references)
2030 fprintf(fp, "References: %s\n", compose->references);
2033 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
2034 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
2036 Xstrdup_a(str, str, return -1);
2040 compose_convert_header(buf, sizeof(buf), str,
2041 strlen("Followup-To: "));
2042 fprintf(fp, "Followup-To: %s\n", buf);
2048 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
2049 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
2051 Xstrdup_a(str, str, return -1);
2054 compose_convert_header(buf, sizeof(buf), str,
2055 strlen("Reply-To: "));
2056 fprintf(fp, "Reply-To: %s\n", buf);
2062 if (compose->account->organization &&
2063 !IS_IN_CUSTOM_HEADER("Organization")) {
2064 compose_convert_header(buf, sizeof(buf),
2065 compose->account->organization,
2066 strlen("Organization: "));
2067 fprintf(fp, "Organization: %s\n", buf);
2070 /* Program version and system info */
2071 /* uname(&utsbuf); */
2072 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2073 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
2074 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
2076 gtk_major_version, gtk_minor_version, gtk_micro_version,
2078 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2080 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2081 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
2082 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
2084 gtk_major_version, gtk_minor_version, gtk_micro_version,
2086 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2089 /* custom headers */
2090 if (compose->account->add_customhdr) {
2093 for (cur = compose->account->customhdr_list; cur != NULL;
2095 CustomHeader *chdr = (CustomHeader *)cur->data;
2097 if (strcasecmp(chdr->name, "Date") != 0 &&
2098 strcasecmp(chdr->name, "From") != 0 &&
2099 strcasecmp(chdr->name, "To") != 0 &&
2100 strcasecmp(chdr->name, "Sender") != 0 &&
2101 strcasecmp(chdr->name, "Message-Id") != 0 &&
2102 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
2103 strcasecmp(chdr->name, "References") != 0 &&
2104 strcasecmp(chdr->name, "Mime-Version") != 0 &&
2105 strcasecmp(chdr->name, "Content-Type") != 0 &&
2106 strcasecmp(chdr->name, "Content-Transfer-Encoding")
2108 compose_convert_header
2110 chdr->value ? chdr->value : "",
2111 strlen(chdr->name) + 2);
2112 fprintf(fp, "%s: %s\n", chdr->name, buf);
2117 fprintf(fp, "Mime-Version: 1.0\n");
2118 if (compose->use_attach) {
2119 get_rfc822_date(buf, sizeof(buf));
2120 subst_char(buf, ' ', '_');
2121 subst_char(buf, ',', '_');
2122 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
2123 buf, (guint)compose);
2125 "Content-Type: multipart/mixed;\n"
2126 " boundary=\"%s\"\n", compose->boundary);
2128 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
2129 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2130 procmime_get_encoding_str(encoding));
2133 /* Request Return Receipt */
2134 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
2135 if (compose->return_receipt) {
2136 if (compose->account->name
2137 && *compose->account->name) {
2138 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
2139 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
2141 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
2145 /* separator between header and body */
2151 #undef IS_IN_CUSTOM_HEADER
2153 static void compose_convert_header(gchar *dest, gint len, gchar *src,
2156 g_return_if_fail(src != NULL);
2157 g_return_if_fail(dest != NULL);
2159 if (len < 1) return;
2163 if (is_ascii_str(src)) {
2164 strncpy2(dest, src, len);
2165 dest[len - 1] = '\0';
2168 conv_encode_header(dest, len, src, header_len);
2171 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
2180 if (compose->account && compose->account->address &&
2181 *compose->account->address) {
2182 if (strchr(compose->account->address, '@'))
2183 addr = g_strdup(compose->account->address);
2185 addr = g_strconcat(compose->account->address, "@",
2186 get_domain_name(), NULL);
2188 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
2191 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
2192 lt->tm_year + 1900, lt->tm_mon + 1,
2193 lt->tm_mday, lt->tm_hour,
2194 lt->tm_min, lt->tm_sec,
2195 (guint)random(), addr);
2197 debug_print(_("generated Message-ID: %s\n"), buf);
2202 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
2203 GtkWidget **entry, gint *count,
2204 const gchar *label_str,
2205 gboolean is_addr_entry)
2209 if (GTK_TABLE(table)->nrows < (*count) + 1)
2210 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
2212 *hbox = gtk_hbox_new(FALSE, 0);
2213 label = gtk_label_new
2214 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
2215 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
2216 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
2218 *entry = gtk_entry_new();
2219 gtk_table_attach_defaults
2220 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1);
2221 if (GTK_TABLE(table)->nrows > (*count) + 1)
2222 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
2225 address_completion_register_entry(GTK_ENTRY(*entry));
2230 static Compose *compose_create(PrefsAccount *account)
2236 GtkWidget *handlebox;
2240 GtkWidget *table_vbox;
2242 GtkWidget *from_optmenu_hbox;
2243 GtkWidget *to_entry;
2245 GtkWidget *newsgroups_entry;
2246 GtkWidget *newsgroups_hbox;
2247 GtkWidget *subject_entry;
2248 GtkWidget *cc_entry;
2250 GtkWidget *bcc_entry;
2251 GtkWidget *bcc_hbox;
2252 GtkWidget *reply_entry;
2253 GtkWidget *reply_hbox;
2254 GtkWidget *followup_entry;
2255 GtkWidget *followup_hbox;
2259 GtkWidget *attach_scrwin;
2260 GtkWidget *attach_clist;
2262 GtkWidget *edit_vbox;
2263 GtkWidget *ruler_hbox;
2265 GtkWidget *scrolledwin;
2271 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
2272 guint n_menu_entries;
2273 GtkStyle *style, *new_style;
2276 gboolean success[1];
2278 GtkWidget *popupmenu;
2279 GtkWidget *menuitem;
2280 GtkItemFactory *popupfactory;
2281 GtkItemFactory *ifactory;
2286 g_return_val_if_fail(account != NULL, NULL);
2288 debug_print(_("Creating compose window...\n"));
2289 compose = g_new0(Compose, 1);
2291 compose->account = account;
2292 compose->orig_account = account;
2294 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2295 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
2296 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
2297 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
2298 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
2299 gtk_signal_connect(GTK_OBJECT(window), "destroy",
2300 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
2301 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
2302 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
2303 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
2304 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
2305 gtk_widget_realize(window);
2307 vbox = gtk_vbox_new(FALSE, 0);
2308 gtk_container_add(GTK_CONTAINER(window), vbox);
2310 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
2311 menubar = menubar_create(window, compose_entries,
2312 n_menu_entries, "<Compose>", compose);
2313 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
2315 handlebox = gtk_handle_box_new();
2316 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
2318 compose_toolbar_create(compose, handlebox);
2320 vbox2 = gtk_vbox_new(FALSE, 2);
2321 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
2322 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
2324 table_vbox = gtk_vbox_new(FALSE, 0);
2325 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
2326 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
2329 table = gtk_table_new(8, 2, FALSE);
2330 gtk_box_pack_start(GTK_BOX(table_vbox), table, FALSE, TRUE, 0);
2332 /* option menu for selecting accounts */
2333 hbox = gtk_hbox_new(FALSE, 0);
2334 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
2335 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
2336 gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, count, count + 1,
2338 from_optmenu_hbox = compose_account_option_menu_create(compose);
2339 gtk_table_attach_defaults(GTK_TABLE(table), from_optmenu_hbox,
2340 1, 2, count, count + 1);
2341 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
2344 /* header labels and entries */
2345 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
2347 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
2348 &count, "Newsgroups:", FALSE);
2349 compose_add_entry_field(table, &hbox, &subject_entry, &count,
2351 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
2353 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
2355 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
2357 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
2358 "Followup-To:", FALSE);
2360 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
2362 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
2363 GTK_SIGNAL_FUNC(to_activated), compose);
2364 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
2365 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
2366 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
2367 GTK_SIGNAL_FUNC(subject_activated), compose);
2368 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
2369 GTK_SIGNAL_FUNC(cc_activated), compose);
2370 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
2371 GTK_SIGNAL_FUNC(bcc_activated), compose);
2372 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
2373 GTK_SIGNAL_FUNC(replyto_activated), compose);
2374 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
2375 GTK_SIGNAL_FUNC(followupto_activated), compose);
2377 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
2378 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2379 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
2380 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2381 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
2382 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2383 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
2384 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2385 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
2386 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2387 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
2388 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2389 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
2390 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2392 /* attachment list */
2393 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
2394 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
2395 GTK_POLICY_AUTOMATIC,
2397 gtk_widget_set_usize(attach_scrwin, -1, 80);
2399 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
2400 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
2402 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
2403 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
2404 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
2405 GTK_SELECTION_EXTENDED);
2406 for (i = 0; i < N_ATTACH_COLS; i++)
2407 GTK_WIDGET_UNSET_FLAGS
2408 (GTK_CLIST(attach_clist)->column[i].button,
2410 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
2412 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
2413 GTK_SIGNAL_FUNC(attach_selected), compose);
2414 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
2415 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
2416 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
2417 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
2420 gtk_drag_dest_set(attach_clist,
2421 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
2423 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
2424 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
2427 /* pane between attach clist and text */
2428 paned = gtk_vpaned_new();
2429 gtk_paned_add1(GTK_PANED(paned), attach_scrwin);
2430 gtk_widget_ref(paned);
2431 gtk_widget_show_all(paned);
2433 edit_vbox = gtk_vbox_new(FALSE, 0);
2434 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
2437 ruler_hbox = gtk_hbox_new(FALSE, 0);
2438 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
2440 ruler = gtk_shruler_new();
2441 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
2442 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
2444 gtk_widget_set_usize(ruler_hbox, 1, -1);
2447 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
2448 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
2449 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
2450 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
2451 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
2453 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
2454 (GTK_SCROLLED_WINDOW(scrolledwin)),
2455 gtk_scrolled_window_get_vadjustment
2456 (GTK_SCROLLED_WINDOW(scrolledwin)));
2457 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
2458 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
2459 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
2461 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
2463 gtk_signal_connect(GTK_OBJECT(text), "changed",
2464 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
2465 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
2466 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2467 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
2468 GTK_SIGNAL_FUNC(compose_button_press_cb),
2471 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
2472 GTK_SIGNAL_FUNC(compose_key_press_cb),
2475 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
2476 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
2480 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
2482 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
2483 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
2486 gtk_widget_show_all(vbox);
2488 style = gtk_widget_get_style(text);
2490 /* workaround for the slow down of GtkSText when using Pixmap theme */
2491 if (style->engine) {
2492 GtkThemeEngine *engine;
2494 engine = style->engine;
2495 style->engine = NULL;
2496 new_style = gtk_style_copy(style);
2497 style->engine = engine;
2499 new_style = gtk_style_copy(style);
2501 if (prefs_common.textfont) {
2504 charset = conv_get_current_charset();
2505 if (MB_CUR_MAX == 1) {
2508 Xstrdup_a(fontstr, prefs_common.textfont, );
2509 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
2511 font = gdk_font_load(fontstr);
2513 font = gdk_fontset_load(prefs_common.textfont);
2515 gdk_font_unref(new_style->font);
2516 new_style->font = font;
2520 gtk_widget_set_style(text, new_style);
2522 color[0] = quote_color;
2523 cmap = gdk_window_get_colormap(window->window);
2524 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
2525 if (success[0] == FALSE) {
2526 g_warning("Compose: color allocation failed.\n");
2527 style = gtk_widget_get_style(text);
2528 quote_color = style->black;
2531 n_entries = sizeof(compose_popup_entries) /
2532 sizeof(compose_popup_entries[0]);
2533 popupmenu = menu_create_items(compose_popup_entries, n_entries,
2534 "<Compose>", &popupfactory,
2537 ifactory = gtk_item_factory_from_widget(menubar);
2538 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
2539 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
2541 gtk_widget_hide(bcc_hbox);
2542 gtk_widget_hide(bcc_entry);
2543 gtk_widget_hide(reply_hbox);
2544 gtk_widget_hide(reply_entry);
2545 gtk_widget_hide(followup_hbox);
2546 gtk_widget_hide(followup_entry);
2547 gtk_widget_hide(ruler_hbox);
2548 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
2549 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
2550 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
2552 if (account->protocol == A_NNTP) {
2553 gtk_widget_hide(to_hbox);
2554 gtk_widget_hide(to_entry);
2555 gtk_widget_hide(cc_hbox);
2556 gtk_widget_hide(cc_entry);
2557 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
2558 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
2560 gtk_widget_hide(newsgroups_hbox);
2561 gtk_widget_hide(newsgroups_entry);
2562 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
2563 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
2566 switch (prefs_common.toolbar_style) {
2568 gtk_widget_hide(handlebox);
2571 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
2575 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
2579 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
2584 gtk_widget_show(window);
2586 address_completion_start(window);
2588 compose->window = window;
2589 compose->vbox = vbox;
2590 compose->menubar = menubar;
2591 compose->handlebox = handlebox;
2593 compose->vbox2 = vbox2;
2595 compose->table_vbox = table_vbox;
2596 compose->table = table;
2597 compose->to_hbox = to_hbox;
2598 compose->to_entry = to_entry;
2599 compose->newsgroups_hbox = newsgroups_hbox;
2600 compose->newsgroups_entry = newsgroups_entry;
2601 compose->subject_entry = subject_entry;
2602 compose->cc_hbox = cc_hbox;
2603 compose->cc_entry = cc_entry;
2604 compose->bcc_hbox = bcc_hbox;
2605 compose->bcc_entry = bcc_entry;
2606 compose->reply_hbox = reply_hbox;
2607 compose->reply_entry = reply_entry;
2608 compose->followup_hbox = followup_hbox;
2609 compose->followup_entry = followup_entry;
2611 compose->paned = paned;
2613 compose->attach_scrwin = attach_scrwin;
2614 compose->attach_clist = attach_clist;
2616 compose->edit_vbox = edit_vbox;
2617 compose->ruler_hbox = ruler_hbox;
2618 compose->ruler = ruler;
2619 compose->scrolledwin = scrolledwin;
2620 compose->text = text;
2622 compose->focused_editable = NULL;
2624 compose->popupmenu = popupmenu;
2625 compose->popupfactory = popupfactory;
2627 compose->mode = COMPOSE_NEW;
2629 compose->replyto = NULL;
2631 compose->bcc = NULL;
2632 compose->followup_to = NULL;
2633 compose->inreplyto = NULL;
2634 compose->references = NULL;
2635 compose->msgid = NULL;
2636 compose->boundary = NULL;
2638 compose->use_to = FALSE;
2639 compose->use_cc = FALSE;
2640 compose->use_bcc = FALSE;
2641 compose->use_replyto = FALSE;
2642 compose->use_followupto = FALSE;
2643 compose->use_attach = FALSE;
2646 compose->use_signing = FALSE;
2647 compose->use_encryption = FALSE;
2648 #endif /* USE_GPGME */
2650 compose->modified = FALSE;
2652 compose->return_receipt = FALSE;
2654 compose->to_list = NULL;
2655 compose->newsgroup_list = NULL;
2657 compose->exteditor_file = NULL;
2658 compose->exteditor_pid = -1;
2659 compose->exteditor_readdes = -1;
2660 compose->exteditor_tag = -1;
2662 compose_set_title(compose);
2664 if (account->protocol != A_NNTP) {
2665 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
2666 gtk_check_menu_item_set_active
2667 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2668 gtk_widget_set_sensitive(menuitem, FALSE);
2669 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
2670 gtk_check_menu_item_set_active
2671 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2672 gtk_widget_set_sensitive(menuitem, FALSE);
2674 if (account->set_autocc && account->auto_cc) {
2675 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
2676 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
2677 gtk_check_menu_item_set_active
2678 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2680 if (account->set_autobcc) {
2681 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
2682 gtk_check_menu_item_set_active
2683 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2684 if (account->auto_bcc)
2685 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
2688 if (account->set_autoreplyto) {
2689 menuitem = gtk_item_factory_get_item(ifactory,
2690 "/Message/Reply to");
2691 gtk_check_menu_item_set_active
2692 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2693 if (account->auto_replyto)
2694 gtk_entry_set_text(GTK_ENTRY(reply_entry),
2695 account->auto_replyto);
2698 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
2699 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2700 prefs_common.show_ruler);
2703 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
2704 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2705 prefs_common.default_sign);
2706 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
2707 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2708 prefs_common.default_encrypt);
2709 #endif /* USE_GPGME */
2711 addressbook_set_target_compose(compose);
2713 compose_list = g_list_append(compose_list, compose);
2718 #include "pixmaps/stock_mail_send.xpm"
2719 #include "pixmaps/stock_mail.xpm"
2720 #include "pixmaps/stock_paste.xpm"
2721 #include "pixmaps/stock_mail_attach.xpm"
2722 #include "pixmaps/stock_mail_compose.xpm"
2723 #include "pixmaps/linewrap.xpm"
2724 //#include "pixmaps/tb_mail_queue_send.xpm"
2725 #include "pixmaps/tb_address_book.xpm"
2727 #define CREATE_TOOLBAR_ICON(xpm_d) \
2729 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
2730 &container->style->white, \
2732 icon_wid = gtk_pixmap_new(icon, mask); \
2735 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
2740 GtkWidget *icon_wid;
2741 GtkWidget *send_btn;
2742 GtkWidget *sendl_btn;
2743 GtkWidget *draft_btn;
2744 GtkWidget *insert_btn;
2745 GtkWidget *attach_btn;
2747 GtkWidget *exteditor_btn;
2748 GtkWidget *linewrap_btn;
2749 GtkWidget *addrbook_btn;
2751 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
2753 gtk_container_add(GTK_CONTAINER(container), toolbar);
2754 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2755 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
2756 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
2757 GTK_TOOLBAR_SPACE_LINE);
2759 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
2760 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2764 icon_wid, toolbar_send_cb, compose);
2766 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
2767 //CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm);
2768 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2770 _("Put into queue folder and send later"),
2772 icon_wid, toolbar_send_later_cb,
2775 CREATE_TOOLBAR_ICON(stock_mail_xpm);
2776 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2778 _("Save to draft folder"),
2780 icon_wid, toolbar_draft_cb,
2783 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
2785 CREATE_TOOLBAR_ICON(stock_paste_xpm);
2786 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2790 icon_wid, toolbar_insert_cb,
2793 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
2794 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2798 icon_wid, toolbar_attach_cb,
2801 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
2803 CREATE_TOOLBAR_ICON(stock_mail_xpm);
2804 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2806 _("Insert signature"),
2808 icon_wid, toolbar_sig_cb, compose);
2810 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
2812 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
2813 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2815 _("Edit with external editor"),
2818 toolbar_ext_editor_cb,
2821 CREATE_TOOLBAR_ICON(linewrap_xpm);
2822 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2824 _("Wrap long lines"),
2827 toolbar_linewrap_cb,
2830 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
2832 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
2833 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2837 icon_wid, toolbar_address_cb,
2840 compose->toolbar = toolbar;
2841 compose->send_btn = send_btn;
2842 compose->sendl_btn = sendl_btn;
2843 compose->draft_btn = draft_btn;
2844 compose->insert_btn = insert_btn;
2845 compose->attach_btn = attach_btn;
2846 compose->sig_btn = sig_btn;
2847 compose->exteditor_btn = exteditor_btn;
2848 compose->linewrap_btn = linewrap_btn;
2849 compose->addrbook_btn = addrbook_btn;
2851 gtk_widget_show_all(toolbar);
2854 #undef CREATE_TOOLBAR_ICON
2856 static GtkWidget *compose_account_option_menu_create(Compose *compose)
2862 gint num = 0, def_menu = 0;
2864 accounts = account_get_list();
2865 g_return_val_if_fail(accounts != NULL, NULL);
2867 hbox = gtk_hbox_new(FALSE, 0);
2868 optmenu = gtk_option_menu_new();
2869 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
2870 menu = gtk_menu_new();
2872 for (; accounts != NULL; accounts = accounts->next, num++) {
2873 PrefsAccount *ac = (PrefsAccount *)accounts->data;
2874 GtkWidget *menuitem;
2877 if (ac == compose->account) def_menu = num;
2879 name = g_strdup_printf("%s <%s> (%s)",
2880 ac->name, ac->address, ac->account_name);
2881 MENUITEM_ADD(menu, menuitem, name, ac);
2883 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
2884 GTK_SIGNAL_FUNC(account_activated),
2888 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
2889 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
2894 static void compose_destroy(Compose *compose)
2897 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2900 /* NOTE: address_completion_end() does nothing with the window
2901 * however this may change. */
2902 address_completion_end(compose->window);
2904 slist_free_strings(compose->to_list);
2905 g_slist_free(compose->to_list);
2906 slist_free_strings(compose->newsgroup_list);
2907 g_slist_free(compose->newsgroup_list);
2909 procmsg_msginfo_free(compose->targetinfo);
2911 g_free(compose->replyto);
2912 g_free(compose->cc);
2913 g_free(compose->bcc);
2914 g_free(compose->newsgroups);
2915 g_free(compose->followup_to);
2917 g_free(compose->inreplyto);
2918 g_free(compose->references);
2919 g_free(compose->msgid);
2920 g_free(compose->boundary);
2922 g_free(compose->exteditor_file);
2924 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
2926 compose_attach_info_free(ainfo);
2928 if (addressbook_get_target_compose() == compose)
2929 addressbook_set_target_compose(NULL);
2931 prefs_common.compose_width = compose->scrolledwin->allocation.width;
2932 prefs_common.compose_height = compose->window->allocation.height;
2934 gtk_widget_destroy(compose->paned);
2938 compose_list = g_list_remove(compose_list, compose);
2941 static void compose_attach_info_free(AttachInfo *ainfo)
2943 g_free(ainfo->file);
2944 g_free(ainfo->content_type);
2945 g_free(ainfo->name);
2949 static void compose_attach_remove_selected(Compose *compose)
2951 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2955 while (clist->selection != NULL) {
2956 row = GPOINTER_TO_INT(clist->selection->data);
2957 ainfo = gtk_clist_get_row_data(clist, row);
2958 compose_attach_info_free(ainfo);
2959 gtk_clist_remove(clist, row);
2963 static struct _AttachProperty
2966 GtkWidget *mimetype_entry;
2967 GtkWidget *encoding_optmenu;
2968 GtkWidget *path_entry;
2969 GtkWidget *filename_entry;
2971 GtkWidget *cancel_btn;
2974 static void compose_attach_property(Compose *compose)
2976 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2980 GtkOptionMenu *optmenu;
2982 if (!clist->selection) return;
2983 row = GPOINTER_TO_INT(clist->selection->data);
2985 ainfo = gtk_clist_get_row_data(clist, row);
2988 if (!attach_prop.window)
2989 compose_attach_property_create(&cancelled);
2990 gtk_widget_grab_focus(attach_prop.ok_btn);
2991 gtk_widget_show(attach_prop.window);
2992 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
2994 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
2995 if (ainfo->encoding == ENC_UNKNOWN)
2996 gtk_option_menu_set_history(optmenu, ENC_BASE64);
2998 gtk_option_menu_set_history(optmenu, ainfo->encoding);
3000 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
3001 ainfo->content_type ? ainfo->content_type : "");
3002 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
3003 ainfo->file ? ainfo->file : "");
3004 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
3005 ainfo->name ? ainfo->name : "");
3009 gchar *cnttype = NULL;
3013 GtkWidget *menuitem;
3017 if (cancelled == TRUE) {
3018 gtk_widget_hide(attach_prop.window);
3022 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
3023 if (*text != '\0') {
3026 text = g_strstrip(g_strdup(text));
3027 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
3028 cnttype = g_strdup(text);
3031 alertpanel_error(_("Invalid MIME type."));
3037 menu = gtk_option_menu_get_menu(optmenu);
3038 menuitem = gtk_menu_get_active(GTK_MENU(menu));
3039 ainfo->encoding = GPOINTER_TO_INT
3040 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
3042 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
3043 if (*text != '\0') {
3044 if (is_file_exist(text) &&
3045 (size = get_file_size(text)) > 0)
3046 file = g_strdup(text);
3049 (_("File doesn't exist or is empty."));
3055 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
3056 if (*text != '\0') {
3057 g_free(ainfo->name);
3058 ainfo->name = g_strdup(text);
3062 g_free(ainfo->content_type);
3063 ainfo->content_type = cnttype;
3066 g_free(ainfo->file);
3072 gtk_clist_set_text(clist, row, COL_MIMETYPE,
3073 ainfo->content_type);
3074 gtk_clist_set_text(clist, row, COL_SIZE,
3075 to_human_readable(ainfo->size));
3076 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
3078 gtk_widget_hide(attach_prop.window);
3083 #define SET_LABEL_AND_ENTRY(str, entry, top) \
3085 label = gtk_label_new(str); \
3086 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
3087 GTK_FILL, 0, 0, 0); \
3088 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
3090 entry = gtk_entry_new(); \
3091 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
3092 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
3095 static void compose_attach_property_create(gboolean *cancelled)
3101 GtkWidget *mimetype_entry;
3104 GtkWidget *optmenu_menu;
3105 GtkWidget *menuitem;
3106 GtkWidget *path_entry;
3107 GtkWidget *filename_entry;
3110 GtkWidget *cancel_btn;
3112 debug_print("Creating attach_property window...\n");
3114 window = gtk_window_new(GTK_WINDOW_DIALOG);
3115 gtk_widget_set_usize(window, 480, -1);
3116 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
3117 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
3118 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
3119 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
3120 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3121 GTK_SIGNAL_FUNC(attach_property_delete_event),
3123 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
3124 GTK_SIGNAL_FUNC(attach_property_key_pressed),
3127 vbox = gtk_vbox_new(FALSE, 8);
3128 gtk_container_add(GTK_CONTAINER(window), vbox);
3130 table = gtk_table_new(4, 2, FALSE);
3131 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
3132 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
3133 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
3135 SET_LABEL_AND_ENTRY(_("MIME type"), mimetype_entry, 0);
3137 label = gtk_label_new(_("Encoding"));
3138 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
3140 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3142 hbox = gtk_hbox_new(FALSE, 0);
3143 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
3144 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3146 optmenu = gtk_option_menu_new();
3147 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3149 optmenu_menu = gtk_menu_new();
3150 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
3151 gtk_widget_set_sensitive(menuitem, FALSE);
3152 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
3153 gtk_widget_set_sensitive(menuitem, FALSE);
3154 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
3155 gtk_widget_set_sensitive(menuitem, FALSE);
3156 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
3158 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
3160 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
3161 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
3163 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
3164 &cancel_btn, _("Cancel"), NULL, NULL);
3165 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
3166 gtk_widget_grab_default(ok_btn);
3168 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
3169 GTK_SIGNAL_FUNC(attach_property_ok),
3171 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
3172 GTK_SIGNAL_FUNC(attach_property_cancel),
3175 gtk_widget_show_all(vbox);
3177 attach_prop.window = window;
3178 attach_prop.mimetype_entry = mimetype_entry;
3179 attach_prop.encoding_optmenu = optmenu;
3180 attach_prop.path_entry = path_entry;
3181 attach_prop.filename_entry = filename_entry;
3182 attach_prop.ok_btn = ok_btn;
3183 attach_prop.cancel_btn = cancel_btn;
3186 #undef SET_LABEL_AND_ENTRY
3188 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
3194 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
3200 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
3201 gboolean *cancelled)
3209 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
3210 gboolean *cancelled)
3212 if (event && event->keyval == GDK_Escape) {
3218 static void compose_exec_ext_editor(Compose *compose)
3224 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
3225 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3227 if (pipe(pipe_fds) < 0) {
3232 if ((pid = fork()) < 0) {
3238 /* close the write side of the pipe */
3241 compose->exteditor_file = g_strdup(tmp);
3242 compose->exteditor_pid = pid;
3243 compose->exteditor_readdes = pipe_fds[0];
3245 compose_set_ext_editor_sensitive(compose, FALSE);
3247 compose->exteditor_tag =
3248 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
3249 compose_input_cb, compose);
3250 } else { /* process-monitoring process */
3256 /* close the read side of the pipe */
3259 if (compose_write_body_to_file(compose, tmp) < 0) {
3260 fd_write(pipe_fds[1], "2\n", 2);
3264 pid_ed = compose_exec_ext_editor_real(tmp);
3266 fd_write(pipe_fds[1], "1\n", 2);
3270 /* wait until editor is terminated */
3271 waitpid(pid_ed, NULL, 0);