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 void compose_new(PrefsAccount *account)
435 compose_new_with_recipient(account, NULL);
438 void 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);
463 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all)
466 PrefsAccount *account;
469 g_return_if_fail(msginfo != NULL);
470 g_return_if_fail(msginfo->folder != NULL);
472 account = msginfo->folder->folder->account;
473 if (!account) account = cur_account;
474 g_return_if_fail(account != NULL);
476 MSG_UNSET_FLAGS(msginfo->flags, MSG_FORWARDED);
477 MSG_SET_FLAGS(msginfo->flags, MSG_REPLIED);
479 compose = compose_create(account);
480 compose->mode = COMPOSE_REPLY;
482 if (compose_parse_header(compose, msginfo) < 0) return;
483 compose_reply_set_entry(compose, msginfo, to_all);
485 text = GTK_STEXT(compose->text);
486 gtk_stext_freeze(text);
492 if ((fp = procmime_get_text_part(msginfo)) == NULL)
493 g_warning(_("Can't get text part\n"));
495 quote_str = compose_quote_parse_fmt
496 (compose, msginfo, prefs_common.quotefmt);
497 gtk_stext_insert(text, NULL, NULL, NULL, quote_str, -1);
499 compose_quote_file(compose, msginfo, fp);
504 if (prefs_common.auto_sig)
505 compose_insert_sig(compose);
506 gtk_editable_set_position(GTK_EDITABLE(text), 0);
507 gtk_stext_set_point(text, 0);
509 gtk_stext_thaw(text);
510 gtk_widget_grab_focus(compose->text);
513 #define INSERT_FW_HEADER(var, hdr) \
514 if (msginfo->var && *msginfo->var) { \
515 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
516 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
517 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
520 void compose_forward(MsgInfo *msginfo, gboolean as_attach)
523 PrefsAccount *account;
528 g_return_if_fail(msginfo != NULL);
529 g_return_if_fail(msginfo->folder != NULL);
531 account = msginfo->folder->folder->account;
532 if (!account) account = cur_account;
533 g_return_if_fail(account != NULL);
535 MSG_UNSET_FLAGS(msginfo->flags, MSG_REPLIED);
536 MSG_SET_FLAGS(msginfo->flags, MSG_FORWARDED);
538 compose = compose_create(account);
539 compose->mode = COMPOSE_FORWARD;
541 if (msginfo->subject && *msginfo->subject) {
542 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
543 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
547 text = GTK_STEXT(compose->text);
548 gtk_stext_freeze(text);
553 msgfile = procmsg_get_message_file_path(msginfo);
554 if (!is_file_exist(msgfile))
555 g_warning(_("%s: file not exist\n"), msgfile);
557 compose_attach_append(compose, msgfile,
558 MIME_MESSAGE_RFC822);
562 if ((fp = procmime_get_text_part(msginfo)) == NULL)
563 g_warning(_("Can't get text part\n"));
566 gtk_stext_insert(text, NULL, NULL, NULL,
567 _("\n\nBegin forwarded message:\n\n"), -1);
568 INSERT_FW_HEADER(date, "Date: ");
569 INSERT_FW_HEADER(from, "From: ");
570 INSERT_FW_HEADER(to, "To: ");
571 INSERT_FW_HEADER(newsgroups, "Newsgroups: ");
572 INSERT_FW_HEADER(subject, "Subject: ");
573 gtk_stext_insert(text, NULL, NULL, NULL, "\n\n", 2);
576 while (fgets(buf, sizeof(buf), fp) != NULL)
577 gtk_stext_insert(text, NULL, NULL, NULL,
583 if (prefs_common.auto_sig)
584 compose_insert_sig(compose);
585 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
586 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
588 gtk_stext_thaw(text);
589 if (account->protocol != A_NNTP)
590 gtk_widget_grab_focus(compose->to_entry);
592 gtk_widget_grab_focus(compose->newsgroups_entry);
595 #undef INSERT_FW_HEADER
597 void compose_reedit(MsgInfo *msginfo)
600 PrefsAccount *account;
605 g_return_if_fail(msginfo != NULL);
606 g_return_if_fail(msginfo->folder != NULL);
608 account = msginfo->folder->folder->account;
609 if (!account) account = cur_account;
610 g_return_if_fail(account != NULL);
612 compose = compose_create(account);
613 compose->mode = COMPOSE_REEDIT_DRAFT;
614 compose->targetinfo = procmsg_msginfo_copy(msginfo);
616 if (compose_parse_header(compose, msginfo) < 0) return;
617 compose_reedit_set_entry(compose, msginfo);
619 text = GTK_STEXT(compose->text);
620 gtk_stext_freeze(text);
622 if ((fp = procmime_get_text_part(msginfo)) == NULL)
623 g_warning(_("Can't get text part\n"));
625 while (fgets(buf, sizeof(buf), fp) != NULL)
626 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
630 gtk_stext_thaw(text);
631 gtk_widget_grab_focus(compose->text);
634 GList *compose_get_compose_list(void)
639 void compose_entry_append(Compose *compose, const gchar *address,
640 ComposeEntryType type)
645 if (!address || *address == '\0') return;
649 entry = GTK_ENTRY(compose->cc_entry);
652 entry = GTK_ENTRY(compose->bcc_entry);
656 entry = GTK_ENTRY(compose->to_entry);
660 text = gtk_entry_get_text(entry);
662 gtk_entry_append_text(entry, ", ");
663 gtk_entry_append_text(entry, address);
666 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
668 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
669 {"Cc:", NULL, FALSE},
670 {"References:", NULL, FALSE},
671 {"Bcc:", NULL, FALSE},
672 {"Newsgroups:", NULL, FALSE},
673 {"Followup-To:", NULL, FALSE},
674 {NULL, NULL, FALSE}};
688 g_return_val_if_fail(msginfo != NULL, -1);
690 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
691 procheader_get_header_fields(fp, hentry);
694 if (hentry[H_REPLY_TO].body != NULL) {
695 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
696 compose->replyto = hentry[H_REPLY_TO].body;
697 hentry[H_REPLY_TO].body = NULL;
699 if (hentry[H_CC].body != NULL) {
700 conv_unmime_header_overwrite(hentry[H_CC].body);
701 compose->cc = hentry[H_CC].body;
702 hentry[H_CC].body = NULL;
704 if (hentry[H_REFERENCES].body != NULL) {
705 if (compose->mode == COMPOSE_REEDIT_DRAFT)
706 compose->references = hentry[H_REFERENCES].body;
708 compose->references = compose_parse_references
709 (hentry[H_REFERENCES].body, msginfo->msgid);
710 g_free(hentry[H_REFERENCES].body);
712 hentry[H_REFERENCES].body = NULL;
714 if (hentry[H_BCC].body != NULL) {
715 if (compose->mode == COMPOSE_REEDIT_DRAFT) {
716 conv_unmime_header_overwrite(hentry[H_BCC].body);
717 compose->bcc = hentry[H_BCC].body;
719 g_free(hentry[H_BCC].body);
720 hentry[H_BCC].body = NULL;
722 if (hentry[H_NEWSGROUPS].body != NULL) {
723 compose->newsgroups = hentry[H_NEWSGROUPS].body;
724 hentry[H_NEWSGROUPS].body = NULL;
726 if (hentry[H_FOLLOWUP_TO].body != NULL) {
727 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
728 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
729 hentry[H_FOLLOWUP_TO].body = NULL;
732 if (compose->mode == COMPOSE_REEDIT_DRAFT && msginfo->inreplyto)
733 compose->inreplyto = g_strdup(msginfo->inreplyto);
734 else if (compose->mode != COMPOSE_REEDIT_DRAFT &&
735 msginfo->msgid && *msginfo->msgid) {
736 compose->inreplyto = g_strdup(msginfo->msgid);
738 if (!compose->references) {
739 if (msginfo->inreplyto && *msginfo->inreplyto)
740 compose->references =
741 g_strdup_printf("<%s>\n\t<%s>",
745 compose->references =
746 g_strconcat("<", msginfo->msgid, ">",
754 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
756 GSList *ref_id_list, *cur;
760 ref_id_list = references_list_append(NULL, ref);
761 if (!ref_id_list) return NULL;
763 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
768 for (cur = ref_id_list; cur != NULL; cur = cur->next)
769 /* "<" + Message-ID + ">" + CR+LF+TAB */
770 len += strlen((gchar *)cur->data) + 5;
772 if (len > MAX_REFERENCES_LEN) {
773 /* remove second message-ID */
774 if (ref_id_list && ref_id_list->next &&
775 ref_id_list->next->next) {
776 g_free(ref_id_list->next->data);
777 ref_id_list = g_slist_remove
778 (ref_id_list, ref_id_list->next->data);
780 slist_free_strings(ref_id_list);
781 g_slist_free(ref_id_list);
788 new_ref = g_string_new("");
789 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
790 if (new_ref->len > 0)
791 g_string_append(new_ref, "\n\t");
792 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
795 slist_free_strings(ref_id_list);
796 g_slist_free(ref_id_list);
798 new_ref_str = new_ref->str;
799 g_string_free(new_ref, FALSE);
804 static void compose_quote_file(Compose *compose, MsgInfo *msginfo, FILE *fp)
806 GtkSText *text = GTK_STEXT(compose->text);
809 GdkColor *qcolor = NULL;
812 gchar *linep, *cur, *leftp;
813 gint line_len, cur_len;
818 /* if (prefs_common.enable_color) qcolor = "e_color; */
819 if (prefs_common.quotemark && *prefs_common.quotemark)
820 qmark = prefs_common.quotemark;
823 quote_str = compose_quote_parse_fmt(compose, msginfo, qmark);
824 g_return_if_fail(quote_str != NULL);
825 qlen = strlen(quote_str);
827 if (!prefs_common.linewrap_quote ||
828 prefs_common.linewrap_len <= qlen) {
829 while (fgets(buf, sizeof(buf), fp) != NULL) {
830 gtk_stext_insert(text, NULL, qcolor, NULL,
832 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
838 wrap_len = prefs_common.linewrap_len - qlen;
840 while (fgets(buf, sizeof(buf), fp) != NULL) {
842 str_len = strlen(buf);
844 if (str_len <= wrap_len) {
845 gtk_stext_insert(text, NULL, qcolor, NULL,
847 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
848 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
852 linep = cur = leftp = buf;
853 line_len = cur_len = 0;
855 while (*cur != '\0') {
856 ch_len = mblen(cur, MB_CUR_MAX);
857 if (ch_len < 0) ch_len = 1;
859 if (ch_len == 1 && isspace(*cur)) {
860 linep = cur + ch_len;
861 line_len = cur_len + ch_len;
864 if (cur_len + ch_len > wrap_len && line_len > 0) {
865 gtk_stext_insert(text, NULL, qcolor, NULL,
868 if (isspace(*(linep - 1)))
869 gtk_stext_insert(text, NULL,
871 leftp, line_len - 1);
873 gtk_stext_insert(text, NULL,
876 gtk_stext_insert(text, NULL, NULL, NULL,
880 cur_len = cur_len - line_len + ch_len;
887 linep = cur + ch_len;
888 line_len = cur_len + ch_len;
895 gtk_stext_insert(text, NULL, qcolor, NULL,
897 gtk_stext_insert(text, NULL, qcolor, NULL, leftp, -1);
898 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
905 static gchar *compose_quote_parse_fmt(Compose *compose, MsgInfo *msginfo,
909 size_t buf_len = 1024;
917 if (!fmt || *fmt == '\0') return 0;
919 Xalloca(mbs, sizeof(wchar_t) + 1, return 0);
920 Xalloca(wcsfmt, (strlen(fmt) + 1) * sizeof(wchar_t), return 0);
921 mbstowcs(wcsfmt, fmt, strlen(fmt) + 1);
924 ext_str = g_malloc(sizeof(gchar) * buf_len);
925 g_return_val_if_fail(ext_str != NULL, NULL);
930 len = wctomb(mbs, *sp);
936 wctomb(mbs, *(++sp));
948 case 'I': /* initial */
949 if (!msginfo->fromname) {sp++; break;}
950 p = msginfo->fromname;
951 tmp[0] = tmp[1] = tmp[2] = '\0';
953 if (*p && isalnum(*p))
954 tmp[0] = toupper(*p);
961 while (*p && !isspace(*p)) p++;
962 while (*p && isspace(*p)) p++;
963 if (*p && isalnum(*p))
964 tmp[1] = toupper(*p);
967 if (tmp[1]) str = tmp;
971 str = msginfo->fromname;
975 if (!msginfo->fromname) {sp++; break;}
976 Xstrdup_a(str, msginfo->fromname,
979 while (*p && !isspace(*p)) p++;
984 str = msginfo->subject;
992 if (!msginfo->msgid) {sp++; break;}
993 Xalloca(str, strlen(msginfo->msgid) + 3,
995 g_snprintf(str, strlen(msginfo->msgid) + 3,
996 "<%s>", msginfo->msgid);
1008 while (ext_len + strlen(str) + 1 > buf_len)
1010 ext_str = g_realloc(ext_str,
1011 sizeof(gchar) * buf_len);
1012 g_return_val_if_fail(ext_str != NULL, NULL);
1013 strcpy(ext_str + ext_len, str);
1014 ext_len += strlen(str);
1016 } else if (*mbs == '\\') {
1017 wctomb(mbs, *(++sp));
1035 while (ext_len + strlen(str) + 1 > buf_len)
1037 ext_str = g_realloc(ext_str,
1038 sizeof(gchar) * buf_len);
1039 g_return_val_if_fail(ext_str != NULL, NULL);
1040 strcpy(ext_str + ext_len, str);
1041 ext_len += strlen(str);
1045 while (ext_len + len + 1 > buf_len) buf_len += 1024;
1046 ext_str = g_realloc(ext_str, sizeof(gchar) * buf_len);
1047 g_return_val_if_fail(ext_str != NULL, NULL);
1048 strcpy(ext_str + ext_len, mbs);
1055 ext_str = g_realloc(ext_str, strlen(ext_str) + 1);
1060 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1066 GHashTable *to_table;
1068 g_return_if_fail(compose->account != NULL);
1069 g_return_if_fail(msginfo != NULL);
1071 if (compose->account->protocol != A_NNTP)
1072 gtk_entry_set_text(GTK_ENTRY(compose->to_entry),
1073 compose->replyto ? compose->replyto
1074 : msginfo->from ? msginfo->from : "");
1075 if (compose->account->protocol == A_NNTP)
1076 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry),
1077 compose->followup_to ? compose->followup_to
1078 : compose->newsgroups ? compose->newsgroups
1081 if (msginfo->subject && *msginfo->subject) {
1082 gchar *buf, *buf2, *p;
1084 buf = g_strdup(msginfo->subject);
1085 while (!strncasecmp(buf, "Re:", 3)) {
1087 while (isspace(*p)) p++;
1088 memmove(buf, p, strlen(p) + 1);
1091 buf2 = g_strdup_printf("Re: %s", buf);
1092 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1096 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1098 if (!to_all || compose->account->protocol == A_NNTP) return;
1100 from = g_strdup(compose->replyto ? compose->replyto :
1101 msginfo->from ? msginfo->from : "");
1102 extract_address(from);
1104 cc_list = address_list_append(NULL, msginfo->to);
1105 cc_list = address_list_append(cc_list, compose->cc);
1107 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1108 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1109 if (compose->account)
1110 g_hash_table_insert(to_table, compose->account->address,
1111 GINT_TO_POINTER(1));
1113 /* remove address on To: and that of current account */
1114 for (cur = cc_list; cur != NULL; ) {
1115 GSList *next = cur->next;
1117 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1118 cc_list = g_slist_remove(cc_list, cur->data);
1120 g_hash_table_insert(to_table, cur->data, cur);
1124 g_hash_table_destroy(to_table);
1128 for (cur = cc_list; cur != NULL; cur = cur->next)
1129 compose_entry_append(compose, (gchar *)cur->data,
1131 slist_free_strings(cc_list);
1132 g_slist_free(cc_list);
1136 #define SET_ENTRY(entry, str) \
1139 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1142 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1144 g_return_if_fail(msginfo != NULL);
1146 SET_ENTRY(to_entry, msginfo->to);
1147 SET_ENTRY(subject_entry, msginfo->subject);
1148 SET_ENTRY(cc_entry, compose->cc);
1149 SET_ENTRY(bcc_entry, compose->bcc);
1150 SET_ENTRY(reply_entry, compose->replyto);
1153 GtkItemFactory *ifactory;
1154 GtkWidget *menuitem;
1156 ifactory = gtk_item_factory_from_widget(compose->menubar);
1157 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1158 gtk_check_menu_item_set_active
1159 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1161 if (compose->replyto) {
1162 GtkItemFactory *ifactory;
1163 GtkWidget *menuitem;
1165 ifactory = gtk_item_factory_from_widget(compose->menubar);
1166 menuitem = gtk_item_factory_get_item
1167 (ifactory, "/Message/Reply to");
1168 gtk_check_menu_item_set_active
1169 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1175 static void compose_insert_sig(Compose *compose)
1179 if (compose->account && compose->account->sig_path)
1180 sigfile = g_strdup(compose->account->sig_path);
1182 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1183 DEFAULT_SIGNATURE, NULL);
1186 if (!is_file_or_fifo_exist(sigfile)) {
1191 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1192 if (prefs_common.sig_sep) {
1193 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1194 prefs_common.sig_sep, -1);
1195 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1199 compose_insert_file(compose, sigfile);
1203 static void compose_insert_file(Compose *compose, const gchar *file)
1205 GtkSText *text = GTK_STEXT(compose->text);
1206 gchar buf[BUFFSIZE];
1209 g_return_if_fail(file != NULL);
1211 if ((fp = fopen(file, "r")) == NULL) {
1212 FILE_OP_ERROR(file, "fopen");
1216 gtk_stext_freeze(text);
1218 while (fgets(buf, sizeof(buf), fp) != NULL)
1219 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1221 gtk_stext_thaw(text);
1226 static void compose_attach_append(Compose *compose, const gchar *file,
1227 ContentType cnttype)
1230 gchar *text[N_ATTACH_COLS];
1234 if (!is_file_exist(file)) {
1235 g_warning(_("File %s doesn't exist\n"), file);
1238 if ((size = get_file_size(file)) < 0) {
1239 g_warning(_("Can't get file size of %s\n"), file);
1243 alertpanel_notice(_("File %s is empty\n"), file);
1247 if (!compose->use_attach) {
1248 GtkItemFactory *ifactory;
1249 GtkWidget *menuitem;
1251 ifactory = gtk_item_factory_from_widget(compose->menubar);
1252 menuitem = gtk_item_factory_get_item(ifactory,
1254 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1258 ainfo = g_new0(AttachInfo, 1);
1259 ainfo->file = g_strdup(file);
1261 if (cnttype == MIME_MESSAGE_RFC822) {
1262 ainfo->content_type = g_strdup("message/rfc822");
1263 ainfo->encoding = ENC_7BIT;
1264 ainfo->name = g_strdup_printf(_("Message: %s"),
1267 ainfo->content_type = procmime_get_mime_type(file);
1268 if (!ainfo->content_type)
1269 ainfo->content_type =
1270 g_strdup("application/octet-stream");
1271 ainfo->encoding = ENC_BASE64;
1272 ainfo->name = g_strdup(g_basename(file));
1276 text[COL_MIMETYPE] = ainfo->content_type;
1277 text[COL_SIZE] = to_human_readable(size);
1278 text[COL_NAME] = ainfo->name;
1280 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1281 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1283 if (cnttype != MIME_MESSAGE_RFC822)
1284 compose_changed_cb(NULL, compose);
1287 static void compose_wrap_line(Compose *compose)
1289 GtkSText *text = GTK_STEXT(compose->text);
1291 guint line_pos = 0, cur_pos = 0;
1292 gint line_len = 0, cur_len = 0;
1294 gchar cbuf[MB_CUR_MAX];
1296 gtk_stext_freeze(text);
1298 text_len = gtk_stext_get_length(text);
1300 for (; cur_pos < text_len; cur_pos++) {
1301 if (text->use_wchar)
1303 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
1305 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
1309 if (ch_len == 1 && *cbuf == '\n') {
1310 line_pos = cur_pos + 1;
1311 line_len = cur_len = 0;
1320 if (ch_len == 1 && isspace(*cbuf)) {
1321 line_pos = cur_pos + 1;
1322 line_len = cur_len + ch_len;
1325 if (cur_len + ch_len > prefs_common.linewrap_len &&
1329 if (text->use_wchar)
1330 tlen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
1332 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
1335 if (tlen == 1 && isspace(*cbuf)) {
1336 gtk_stext_set_point(text, line_pos);
1337 gtk_stext_backward_delete(text, 1);
1345 gtk_stext_set_point(text, line_pos);
1346 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1350 cur_len = cur_len - line_len + ch_len;
1356 line_pos = cur_pos + 1;
1357 line_len = cur_len + ch_len;
1362 gtk_stext_thaw(text);
1365 static void compose_set_title(Compose *compose)
1370 edited = compose->modified ? _(" [Edited]") : "";
1371 if (compose->account && compose->account->address)
1372 str = g_strdup_printf(_("%s - Compose message%s"),
1373 compose->account->address, edited);
1375 str = g_strdup_printf(_("Compose message%s"), edited);
1376 gtk_window_set_title(GTK_WINDOW(compose->window), str);
1380 static gint compose_send(Compose *compose)
1382 gchar tmp[MAXPATHLEN + 1];
1383 gchar *to, *newsgroups;
1385 static gboolean lock = FALSE;
1389 g_return_val_if_fail(compose->account != NULL, -1);
1390 g_return_val_if_fail(compose->orig_account != NULL, -1);
1394 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
1395 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
1396 if (*to == '\0' && *newsgroups == '\0') {
1397 alertpanel_error(_("Recipient is not specified."));
1402 /* write to temporary file */
1403 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
1404 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
1406 if (prefs_common.linewrap_at_send)
1407 compose_wrap_line(compose);
1409 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
1414 if (!compose->to_list && !compose->newsgroup_list) {
1415 g_warning(_("can't get recipient list."));
1421 if (compose->to_list) {
1424 if (compose->account->protocol != A_NNTP)
1425 ac = compose->account;
1426 else if (compose->orig_account->protocol != A_NNTP)
1427 ac = compose->orig_account;
1428 else if (cur_account && cur_account->protocol != A_NNTP)
1431 ac = account_get_default();
1432 if (!ac || ac->protocol == A_NNTP) {
1433 alertpanel_error(_("Account for sending mail is not specified.\n"
1434 "Please select a mail account before sending."));
1440 ok = send_message(tmp, ac, compose->to_list);
1441 statusbar_pop_all();
1444 if (ok == 0 && compose->newsgroup_list) {
1447 if (compose->account->protocol == A_NNTP)
1448 folder = FOLDER(compose->account->folder);
1450 folder = FOLDER(compose->orig_account->folder);
1452 ok = news_post(folder, tmp);
1454 alertpanel_error(_("Error occurred while posting the message to %s ."),
1455 compose->account->nntp_server);
1462 /* queue message if failed to send */
1464 if (prefs_common.queue_msg) {
1469 _("Error occurred while sending the message.\n"
1470 "Put this message into queue folder?"),
1471 _("OK"), _("Cancel"), NULL);
1472 if (G_ALERTDEFAULT == val) {
1473 ok = compose_queue(compose, tmp);
1475 alertpanel_error(_("Can't queue the message."));
1478 alertpanel_error(_("Error occurred while sending the message."));
1481 /* save message to outbox */
1482 if (ok == 0 && prefs_common.savemsg) {
1483 if (compose_save_to_outbox(compose, tmp) < 0)
1485 (_("Can't save the message to outbox."));
1488 if (unlink(tmp) < 0) FILE_OP_ERROR(tmp, "unlink");
1493 static gint compose_write_to_file(Compose *compose, const gchar *file,
1500 const gchar *out_codeset;
1501 EncodingType encoding;
1503 if ((fp = fopen(file, "w")) == NULL) {
1504 FILE_OP_ERROR(file, "fopen");
1508 /* chmod for security */
1509 if (change_file_mode_rw(fp, file) < 0) {
1510 FILE_OP_ERROR(file, "chmod");
1511 g_warning(_("can't change file mode\n"));
1514 /* get all composed text */
1515 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
1516 len = strlen(chars);
1517 if (is_ascii_str(chars)) {
1518 buf = g_strdup(chars);
1519 out_codeset = "US-ASCII";
1520 encoding = ENC_7BIT;
1522 const gchar *src_codeset;
1524 out_codeset = conv_get_outgoing_charset_str();
1525 if (!strcasecmp(out_codeset, "US-ASCII"))
1526 out_codeset = "ISO-8859-1";
1527 encoding = procmime_get_encoding_for_charset(out_codeset);
1528 debug_print("charset = %s, encoding = %s\n",
1529 out_codeset, procmime_get_encoding_str(encoding));
1531 src_codeset = conv_get_current_charset_str();
1532 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
1537 alertpanel_error(_("Can't convert the codeset of the message."));
1544 if (compose_write_headers
1545 (compose, fp, out_codeset, encoding, is_draft) < 0) {
1546 g_warning(_("can't write headers\n"));
1553 if (compose->use_attach) {
1555 /* This prolog message is ignored by mime software and
1556 * because it would make our signing/encryption task
1557 * tougher, we don't emit it in that case */
1558 if (!compose->use_signing && !compose->use_encryption)
1560 fputs("This is a multi-part message in MIME format.\n", fp);
1562 fprintf(fp, "\n--%s\n", compose->boundary);
1563 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
1565 fprintf(fp, "Content-Transfer-Encoding: %s\n",
1566 procmime_get_encoding_str(encoding));
1572 if (encoding == ENC_BASE64) {
1573 gchar outbuf[B64_BUFFSIZE];
1576 for (i = 0; i < len; i += B64_LINE_SIZE) {
1577 l = MIN(B64_LINE_SIZE, len - i);
1578 to64frombits(outbuf, buf + i, l);
1582 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
1583 FILE_OP_ERROR(file, "fwrite");
1591 if (compose->use_attach)
1592 compose_write_attach(compose, fp);
1594 if (fclose(fp) == EOF) {
1595 FILE_OP_ERROR(file, "fclose");
1601 if (compose->use_signing) {
1602 if (rfc2015_sign(file, compose->account) < 0) {
1607 if (compose->use_encryption) {
1608 if (rfc2015_encrypt(file, compose->to_list) < 0) {
1613 #endif /* USE_GPGME */
1618 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
1624 if ((fp = fopen(file, "w")) == NULL) {
1625 FILE_OP_ERROR(file, "fopen");
1629 /* chmod for security */
1630 if (change_file_mode_rw(fp, file) < 0) {
1631 FILE_OP_ERROR(file, "chmod");
1632 g_warning(_("can't change file mode\n"));
1635 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
1638 len = strlen(chars);
1639 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
1640 FILE_OP_ERROR(file, "fwrite");
1649 if (fclose(fp) == EOF) {
1650 FILE_OP_ERROR(file, "fclose");
1657 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
1664 debug_print(_("saving sent message...\n"));
1666 outbox = folder_get_default_outbox();
1667 folder_item_scan(outbox);
1668 if ((num = folder_item_add_msg(outbox, file)) < 0) {
1669 g_warning(_("can't save message\n"));
1673 path = folder_item_get_path(outbox);
1674 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
1675 g_warning(_("can't open mark file\n"));
1679 newmsginfo.msgnum = num;
1680 newmsginfo.flags = 0;
1681 procmsg_write_flags(&newmsginfo, fp);
1689 static gint compose_queue(Compose *compose, const gchar *file)
1692 gchar *tmp, *queue_path;
1695 gchar buf[BUFFSIZE];
1698 debug_print(_("queueing message...\n"));
1699 g_return_val_if_fail(compose->to_list != NULL, -1);
1700 g_return_val_if_fail(compose->account != NULL, -1);
1702 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
1703 G_DIR_SEPARATOR, (gint)compose);
1704 if ((fp = fopen(tmp, "w")) == NULL) {
1705 FILE_OP_ERROR(tmp, "fopen");
1709 if ((src_fp = fopen(file, "r")) == NULL) {
1710 FILE_OP_ERROR(file, "fopen");
1716 if (change_file_mode_rw(fp, tmp) < 0) {
1717 FILE_OP_ERROR(tmp, "chmod");
1718 g_warning(_("can't change file mode\n"));
1721 /* queueing variables */
1722 fprintf(fp, "AF:\n");
1723 fprintf(fp, "NF:0\n");
1724 fprintf(fp, "PS:10\n");
1725 fprintf(fp, "SRH:1\n");
1726 fprintf(fp, "SFN:\n");
1727 fprintf(fp, "DSR:\n");
1729 fprintf(fp, "MID:<%s>\n", compose->msgid);
1731 fprintf(fp, "MID:\n");
1732 fprintf(fp, "CFG:\n");
1733 fprintf(fp, "PT:0\n");
1734 fprintf(fp, "S:%s\n", compose->account->address);
1735 fprintf(fp, "RQ:\n");
1736 if (compose->account->smtp_server)
1737 fprintf(fp, "SSV:%s\n", compose->account->smtp_server);
1739 fprintf(fp, "SSV:\n");
1740 if (compose->account->nntp_server)
1741 fprintf(fp, "NSV:%s\n", compose->account->nntp_server);
1743 fprintf(fp, "NSV:\n");
1744 fprintf(fp, "SSH:\n");
1745 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
1746 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
1747 fprintf(fp, ",<%s>", (gchar *)cur->data);
1751 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
1752 if (fputs(buf, fp) == EOF) {
1753 FILE_OP_ERROR(tmp, "fputs");
1763 if (fclose(fp) == EOF) {
1764 FILE_OP_ERROR(tmp, "fclose");
1770 queue = folder_get_default_queue();
1771 folder_item_scan(queue);
1772 if ((num = folder_item_add_msg(queue, tmp)) < 0) {
1773 g_warning(_("can't queue the message\n"));
1781 queue_path = folder_item_get_path(queue);
1782 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
1783 g_warning(_("can't open mark file\n"));
1787 newmsginfo.msgnum = num;
1788 newmsginfo.flags = 0;
1789 procmsg_write_flags(&newmsginfo, fp);
1794 folder_item_scan(queue);
1795 folderview_update_item(queue, TRUE);
1800 static void compose_write_attach(Compose *compose, FILE *fp)
1803 GtkCList *clist = GTK_CLIST(compose->attach_clist);
1806 gchar filename[BUFFSIZE];
1809 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
1811 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
1812 g_warning(_("Can't open file %s\n"), ainfo->file);
1816 fprintf(fp, "\n--%s\n", compose->boundary);
1818 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
1819 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
1820 fprintf(fp, "Content-Disposition: inline\n");
1822 conv_encode_header(filename, sizeof(filename),
1824 fprintf(fp, "Content-Type: %s;\n"
1826 ainfo->content_type, filename);
1827 fprintf(fp, "Content-Disposition: attachment;\n"
1828 " filename=\"%s\"\n", filename);
1831 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
1832 procmime_get_encoding_str(ainfo->encoding));
1834 if (ainfo->encoding == ENC_7BIT) {
1835 gchar buf[BUFFSIZE];
1837 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
1839 if (len > 1 && buf[len - 1] == '\n' &&
1840 buf[len - 2] == '\r') {
1841 buf[len - 2] = '\n';
1842 buf[len - 1] = '\0';
1847 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
1849 while ((len = fread(inbuf, sizeof(gchar),
1850 B64_LINE_SIZE, attach_fp))
1852 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
1856 if (len > 0 && feof(attach_fp)) {
1857 to64frombits(outbuf, inbuf, len);
1866 fprintf(fp, "\n--%s--\n", compose->boundary);
1869 #define IS_IN_CUSTOM_HEADER(header) \
1870 (compose->account->add_customhdr && \
1871 custom_header_find(compose->account->customhdr_list, header) != NULL)
1873 static gint compose_write_headers(Compose *compose, FILE *fp,
1874 const gchar *charset, EncodingType encoding,
1877 gchar buf[BUFFSIZE];
1879 /* struct utsname utsbuf; */
1881 g_return_val_if_fail(fp != NULL, -1);
1882 g_return_val_if_fail(charset != NULL, -1);
1883 g_return_val_if_fail(compose->account != NULL, -1);
1884 g_return_val_if_fail(compose->account->address != NULL, -1);
1887 if (compose->account->add_date) {
1888 get_rfc822_date(buf, sizeof(buf));
1889 fprintf(fp, "Date: %s\n", buf);
1893 if (!IS_IN_CUSTOM_HEADER("From")) {
1894 if (compose->account->name && *compose->account->name) {
1895 compose_convert_header
1896 (buf, sizeof(buf), compose->account->name,
1898 fprintf(fp, "From: %s <%s>\n",
1899 buf, compose->account->address);
1901 fprintf(fp, "From: %s\n", compose->account->address);
1904 slist_free_strings(compose->to_list);
1905 g_slist_free(compose->to_list);
1906 compose->to_list = NULL;
1909 if (compose->use_to) {
1910 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
1912 Xstrdup_a(str, str, return -1);
1915 compose->to_list = address_list_append
1916 (compose->to_list, str);
1917 if (!IS_IN_CUSTOM_HEADER("To")) {
1918 compose_convert_header
1919 (buf, sizeof(buf), str,
1921 fprintf(fp, "To: %s\n", buf);
1927 slist_free_strings(compose->newsgroup_list);
1928 g_slist_free(compose->newsgroup_list);
1929 compose->newsgroup_list = NULL;
1932 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
1934 Xstrdup_a(str, str, return -1);
1938 compose->newsgroup_list =
1939 newsgroup_list_append(compose->newsgroup_list,
1941 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
1942 compose_convert_header(buf, sizeof(buf), str,
1943 strlen("Newsgroups: "));
1944 fprintf(fp, "Newsgroups: %s\n", buf);
1949 if (!is_draft && !compose->to_list && !compose->newsgroup_list)
1953 if (compose->use_cc) {
1954 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
1956 Xstrdup_a(str, str, return -1);
1959 compose->to_list = address_list_append
1960 (compose->to_list, str);
1961 if (!IS_IN_CUSTOM_HEADER("Cc")) {
1962 compose_convert_header
1963 (buf, sizeof(buf), str,
1965 fprintf(fp, "Cc: %s\n", buf);
1972 if (compose->use_bcc) {
1973 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
1975 Xstrdup_a(str, str, return -1);
1978 compose->to_list = address_list_append
1979 (compose->to_list, str);
1981 compose_convert_header
1982 (buf, sizeof(buf), str,
1984 fprintf(fp, "Bcc: %s\n", buf);
1991 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
1992 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
1993 Xstrdup_a(str, str, return -1);
1996 compose_convert_header(buf, sizeof(buf), str,
1997 strlen("Subject: "));
1998 fprintf(fp, "Subject: %s\n", buf);
2003 if (compose->account->gen_msgid) {
2004 compose_generate_msgid(compose, buf, sizeof(buf));
2005 fprintf(fp, "Message-Id: <%s>\n", buf);
2006 compose->msgid = g_strdup(buf);
2010 if (compose->inreplyto && compose->to_list)
2011 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
2014 if (compose->references)
2015 fprintf(fp, "References: %s\n", compose->references);
2018 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
2019 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
2021 Xstrdup_a(str, str, return -1);
2025 compose_convert_header(buf, sizeof(buf), str,
2026 strlen("Followup-To: "));
2027 fprintf(fp, "Followup-To: %s\n", buf);
2033 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
2034 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
2036 Xstrdup_a(str, str, return -1);
2039 compose_convert_header(buf, sizeof(buf), str,
2040 strlen("Reply-To: "));
2041 fprintf(fp, "Reply-To: %s\n", buf);
2047 if (compose->account->organization &&
2048 !IS_IN_CUSTOM_HEADER("Organization")) {
2049 compose_convert_header(buf, sizeof(buf),
2050 compose->account->organization,
2051 strlen("Organization: "));
2052 fprintf(fp, "Organization: %s\n", buf);
2055 /* Program version and system info */
2056 /* uname(&utsbuf); */
2057 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2058 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
2059 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
2061 gtk_major_version, gtk_minor_version, gtk_micro_version,
2063 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2065 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2066 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
2067 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
2069 gtk_major_version, gtk_minor_version, gtk_micro_version,
2071 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2074 /* custom headers */
2075 if (compose->account->add_customhdr) {
2078 for (cur = compose->account->customhdr_list; cur != NULL;
2080 CustomHeader *chdr = (CustomHeader *)cur->data;
2082 if (strcasecmp(chdr->name, "Date") != 0 &&
2083 strcasecmp(chdr->name, "Message-Id") != 0 &&
2084 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
2085 strcasecmp(chdr->name, "References") != 0 &&
2086 strcasecmp(chdr->name, "Mime-Version") != 0 &&
2087 strcasecmp(chdr->name, "Content-Type") != 0 &&
2088 strcasecmp(chdr->name, "Content-Transfer-Encoding")
2090 compose_convert_header
2092 chdr->value ? chdr->value : "",
2093 strlen(chdr->name) + 2);
2094 fprintf(fp, "%s: %s\n", chdr->name, buf);
2099 fprintf(fp, "Mime-Version: 1.0\n");
2100 if (compose->use_attach) {
2101 get_rfc822_date(buf, sizeof(buf));
2102 subst_char(buf, ' ', '_');
2103 subst_char(buf, ',', '_');
2104 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
2105 buf, (guint)compose);
2107 "Content-Type: multipart/mixed;\n"
2108 " boundary=\"%s\"\n", compose->boundary);
2110 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
2111 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2112 procmime_get_encoding_str(encoding));
2115 /* Request Return Receipt */
2116 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
2117 if (compose->return_receipt) {
2118 if (compose->account->name
2119 && *compose->account->name) {
2120 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
2121 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
2123 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
2127 /* separator between header and body */
2133 #undef IS_IN_CUSTOM_HEADER
2135 static void compose_convert_header(gchar *dest, gint len, gchar *src,
2138 g_return_if_fail(src != NULL);
2139 g_return_if_fail(dest != NULL);
2141 if (len < 1) return;
2145 if (is_ascii_str(src)) {
2146 strncpy2(dest, src, len);
2147 dest[len - 1] = '\0';
2150 conv_encode_header(dest, len, src, header_len);
2153 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
2162 if (compose->account && compose->account->address &&
2163 *compose->account->address) {
2164 if (strchr(compose->account->address, '@'))
2165 addr = g_strdup(compose->account->address);
2167 addr = g_strconcat(compose->account->address, "@",
2168 get_domain_name(), NULL);
2170 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
2173 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
2174 lt->tm_year + 1900, lt->tm_mon + 1,
2175 lt->tm_mday, lt->tm_hour,
2176 lt->tm_min, lt->tm_sec,
2177 (guint)random(), addr);
2179 debug_print(_("generated Message-ID: %s\n"), buf);
2184 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
2185 GtkWidget **entry, gint *count,
2186 const gchar *label_str,
2187 gboolean is_addr_entry)
2191 if (GTK_TABLE(table)->nrows < (*count) + 1)
2192 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
2194 *hbox = gtk_hbox_new(FALSE, 0);
2195 label = gtk_label_new
2196 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
2197 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
2198 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
2200 *entry = gtk_entry_new();
2201 gtk_table_attach_defaults
2202 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1);
2203 if (GTK_TABLE(table)->nrows > (*count) + 1)
2204 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
2207 address_completion_register_entry(GTK_ENTRY(*entry));
2212 static Compose *compose_create(PrefsAccount *account)
2218 GtkWidget *handlebox;
2222 GtkWidget *table_vbox;
2224 GtkWidget *from_optmenu_hbox;
2225 GtkWidget *to_entry;
2227 GtkWidget *newsgroups_entry;
2228 GtkWidget *newsgroups_hbox;
2229 GtkWidget *subject_entry;
2230 GtkWidget *cc_entry;
2232 GtkWidget *bcc_entry;
2233 GtkWidget *bcc_hbox;
2234 GtkWidget *reply_entry;
2235 GtkWidget *reply_hbox;
2236 GtkWidget *followup_entry;
2237 GtkWidget *followup_hbox;
2241 GtkWidget *attach_scrwin;
2242 GtkWidget *attach_clist;
2244 GtkWidget *edit_vbox;
2245 GtkWidget *ruler_hbox;
2247 GtkWidget *scrolledwin;
2253 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
2254 guint n_menu_entries;
2255 GtkStyle *style, *new_style;
2258 gboolean success[1];
2260 GtkWidget *popupmenu;
2261 GtkWidget *menuitem;
2262 GtkItemFactory *popupfactory;
2263 GtkItemFactory *ifactory;
2268 g_return_val_if_fail(account != NULL, NULL);
2270 debug_print(_("Creating compose window...\n"));
2271 compose = g_new0(Compose, 1);
2273 compose->account = account;
2274 compose->orig_account = account;
2276 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2277 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
2278 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
2279 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
2280 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
2281 gtk_signal_connect(GTK_OBJECT(window), "destroy",
2282 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
2283 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
2284 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
2285 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
2286 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
2287 gtk_widget_realize(window);
2289 vbox = gtk_vbox_new(FALSE, 0);
2290 gtk_container_add(GTK_CONTAINER(window), vbox);
2292 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
2293 menubar = menubar_create(window, compose_entries,
2294 n_menu_entries, "<Compose>", compose);
2295 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
2297 handlebox = gtk_handle_box_new();
2298 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
2300 compose_toolbar_create(compose, handlebox);
2302 vbox2 = gtk_vbox_new(FALSE, 2);
2303 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
2304 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
2306 table_vbox = gtk_vbox_new(FALSE, 0);
2307 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
2308 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
2311 table = gtk_table_new(8, 2, FALSE);
2312 gtk_box_pack_start(GTK_BOX(table_vbox), table, FALSE, TRUE, 0);
2314 /* option menu for selecting accounts */
2315 hbox = gtk_hbox_new(FALSE, 0);
2316 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
2317 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
2318 gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, count, count + 1,
2320 from_optmenu_hbox = compose_account_option_menu_create(compose);
2321 gtk_table_attach_defaults(GTK_TABLE(table), from_optmenu_hbox,
2322 1, 2, count, count + 1);
2323 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
2326 /* header labels and entries */
2327 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
2329 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
2330 &count, "Newsgroups:", FALSE);
2331 compose_add_entry_field(table, &hbox, &subject_entry, &count,
2333 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
2335 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
2337 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
2339 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
2340 "Followup-To:", FALSE);
2342 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
2344 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
2345 GTK_SIGNAL_FUNC(to_activated), compose);
2346 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
2347 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
2348 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
2349 GTK_SIGNAL_FUNC(subject_activated), compose);
2350 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
2351 GTK_SIGNAL_FUNC(cc_activated), compose);
2352 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
2353 GTK_SIGNAL_FUNC(bcc_activated), compose);
2354 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
2355 GTK_SIGNAL_FUNC(replyto_activated), compose);
2356 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
2357 GTK_SIGNAL_FUNC(followupto_activated), compose);
2359 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
2360 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2361 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
2362 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2363 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
2364 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2365 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
2366 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2367 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
2368 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2369 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
2370 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2371 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
2372 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2374 /* attachment list */
2375 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
2376 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
2377 GTK_POLICY_AUTOMATIC,
2379 gtk_widget_set_usize(attach_scrwin, -1, 80);
2381 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
2382 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
2384 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
2385 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
2386 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
2387 GTK_SELECTION_EXTENDED);
2388 for (i = 0; i < N_ATTACH_COLS; i++)
2389 GTK_WIDGET_UNSET_FLAGS
2390 (GTK_CLIST(attach_clist)->column[i].button,
2392 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
2394 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
2395 GTK_SIGNAL_FUNC(attach_selected), compose);
2396 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
2397 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
2398 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
2399 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
2402 gtk_drag_dest_set(attach_clist,
2403 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
2405 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
2406 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
2409 /* pane between attach clist and text */
2410 paned = gtk_vpaned_new();
2411 gtk_paned_add1(GTK_PANED(paned), attach_scrwin);
2412 gtk_widget_ref(paned);
2413 gtk_widget_show_all(paned);
2415 edit_vbox = gtk_vbox_new(FALSE, 0);
2416 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
2419 ruler_hbox = gtk_hbox_new(FALSE, 0);
2420 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
2422 ruler = gtk_shruler_new();
2423 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
2424 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
2426 gtk_widget_set_usize(ruler_hbox, 1, -1);
2429 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
2430 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
2431 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
2432 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
2433 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
2435 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
2436 (GTK_SCROLLED_WINDOW(scrolledwin)),
2437 gtk_scrolled_window_get_vadjustment
2438 (GTK_SCROLLED_WINDOW(scrolledwin)));
2439 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
2440 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
2441 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
2443 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
2445 gtk_signal_connect(GTK_OBJECT(text), "changed",
2446 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
2447 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
2448 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2449 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
2450 GTK_SIGNAL_FUNC(compose_button_press_cb),
2453 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
2454 GTK_SIGNAL_FUNC(compose_key_press_cb),
2457 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
2458 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
2462 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
2464 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
2465 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
2468 gtk_widget_show_all(vbox);
2470 style = gtk_widget_get_style(text);
2472 /* workaround for the slow down of GtkSText when using Pixmap theme */
2473 if (style->engine) {
2474 GtkThemeEngine *engine;
2476 engine = style->engine;
2477 style->engine = NULL;
2478 new_style = gtk_style_copy(style);
2479 style->engine = engine;
2481 new_style = gtk_style_copy(style);
2483 if (prefs_common.textfont) {
2486 charset = conv_get_current_charset();
2487 if (MB_CUR_MAX == 1) {
2490 Xstrdup_a(fontstr, prefs_common.textfont, );
2491 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
2493 font = gdk_font_load(fontstr);
2495 font = gdk_fontset_load(prefs_common.textfont);
2497 gdk_font_unref(new_style->font);
2498 new_style->font = font;
2502 gtk_widget_set_style(text, new_style);
2504 color[0] = quote_color;
2505 cmap = gdk_window_get_colormap(window->window);
2506 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
2507 if (success[0] == FALSE) {
2508 g_warning("Compose: color allocation failed.\n");
2509 style = gtk_widget_get_style(text);
2510 quote_color = style->black;
2513 n_entries = sizeof(compose_popup_entries) /
2514 sizeof(compose_popup_entries[0]);
2515 popupmenu = menu_create_items(compose_popup_entries, n_entries,
2516 "<Compose>", &popupfactory,
2519 ifactory = gtk_item_factory_from_widget(menubar);
2520 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
2521 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
2523 gtk_widget_hide(bcc_hbox);
2524 gtk_widget_hide(bcc_entry);
2525 gtk_widget_hide(reply_hbox);
2526 gtk_widget_hide(reply_entry);
2527 gtk_widget_hide(followup_hbox);
2528 gtk_widget_hide(followup_entry);
2529 gtk_widget_hide(ruler_hbox);
2530 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
2531 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
2532 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
2534 if (account->protocol == A_NNTP) {
2535 gtk_widget_hide(to_hbox);
2536 gtk_widget_hide(to_entry);
2537 gtk_widget_hide(cc_hbox);
2538 gtk_widget_hide(cc_entry);
2539 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
2540 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
2542 gtk_widget_hide(newsgroups_hbox);
2543 gtk_widget_hide(newsgroups_entry);
2544 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
2545 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
2548 switch (prefs_common.toolbar_style) {
2550 gtk_widget_hide(handlebox);
2553 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
2557 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
2561 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
2566 gtk_widget_show(window);
2568 address_completion_start(window);
2570 compose->window = window;
2571 compose->vbox = vbox;
2572 compose->menubar = menubar;
2573 compose->handlebox = handlebox;
2575 compose->vbox2 = vbox2;
2577 compose->table_vbox = table_vbox;
2578 compose->table = table;
2579 compose->to_hbox = to_hbox;
2580 compose->to_entry = to_entry;
2581 compose->newsgroups_hbox = newsgroups_hbox;
2582 compose->newsgroups_entry = newsgroups_entry;
2583 compose->subject_entry = subject_entry;
2584 compose->cc_hbox = cc_hbox;
2585 compose->cc_entry = cc_entry;
2586 compose->bcc_hbox = bcc_hbox;
2587 compose->bcc_entry = bcc_entry;
2588 compose->reply_hbox = reply_hbox;
2589 compose->reply_entry = reply_entry;
2590 compose->followup_hbox = followup_hbox;
2591 compose->followup_entry = followup_entry;
2593 compose->paned = paned;
2595 compose->attach_scrwin = attach_scrwin;
2596 compose->attach_clist = attach_clist;
2598 compose->edit_vbox = edit_vbox;
2599 compose->ruler_hbox = ruler_hbox;
2600 compose->ruler = ruler;
2601 compose->scrolledwin = scrolledwin;
2602 compose->text = text;
2604 compose->focused_editable = NULL;
2606 compose->popupmenu = popupmenu;
2607 compose->popupfactory = popupfactory;
2609 compose->mode = COMPOSE_NEW;
2611 compose->replyto = NULL;
2613 compose->bcc = NULL;
2614 compose->followup_to = NULL;
2615 compose->inreplyto = NULL;
2616 compose->references = NULL;
2617 compose->msgid = NULL;
2618 compose->boundary = NULL;
2620 compose->use_to = FALSE;
2621 compose->use_cc = FALSE;
2622 compose->use_bcc = FALSE;
2623 compose->use_replyto = FALSE;
2624 compose->use_followupto = FALSE;
2625 compose->use_attach = FALSE;
2628 compose->use_signing = FALSE;
2629 compose->use_encryption = FALSE;
2630 #endif /* USE_GPGME */
2632 compose->modified = FALSE;
2634 compose->return_receipt = FALSE;
2636 compose->to_list = NULL;
2637 compose->newsgroup_list = NULL;
2639 compose->exteditor_file = NULL;
2640 compose->exteditor_pid = -1;
2641 compose->exteditor_readdes = -1;
2642 compose->exteditor_tag = -1;
2644 compose_set_title(compose);
2646 if (account->protocol != A_NNTP) {
2647 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
2648 gtk_check_menu_item_set_active
2649 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2650 gtk_widget_set_sensitive(menuitem, FALSE);
2651 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
2652 gtk_check_menu_item_set_active
2653 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2654 gtk_widget_set_sensitive(menuitem, FALSE);
2656 if (account->set_autocc && account->auto_cc) {
2657 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
2658 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
2659 gtk_check_menu_item_set_active
2660 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2662 if (account->set_autobcc) {
2663 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
2664 gtk_check_menu_item_set_active
2665 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2666 if (account->auto_bcc)
2667 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
2670 if (account->set_autoreplyto) {
2671 menuitem = gtk_item_factory_get_item(ifactory,
2672 "/Message/Reply to");
2673 gtk_check_menu_item_set_active
2674 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2675 if (account->auto_replyto)
2676 gtk_entry_set_text(GTK_ENTRY(reply_entry),
2677 account->auto_replyto);
2680 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
2681 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2682 prefs_common.show_ruler);
2685 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
2686 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2687 prefs_common.default_sign);
2688 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
2689 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2690 prefs_common.default_encrypt);
2691 #endif /* USE_GPGME */
2693 addressbook_set_target_compose(compose);
2695 compose_list = g_list_append(compose_list, compose);
2700 #include "pixmaps/stock_mail_send.xpm"
2701 #include "pixmaps/stock_mail.xpm"
2702 #include "pixmaps/stock_paste.xpm"
2703 #include "pixmaps/stock_mail_attach.xpm"
2704 #include "pixmaps/stock_mail_compose.xpm"
2705 #include "pixmaps/linewrap.xpm"
2706 //#include "pixmaps/tb_mail_queue_send.xpm"
2707 #include "pixmaps/tb_address_book.xpm"
2709 #define CREATE_TOOLBAR_ICON(xpm_d) \
2711 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
2712 &container->style->white, \
2714 icon_wid = gtk_pixmap_new(icon, mask); \
2717 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
2722 GtkWidget *icon_wid;
2723 GtkWidget *send_btn;
2724 GtkWidget *sendl_btn;
2725 GtkWidget *draft_btn;
2726 GtkWidget *insert_btn;
2727 GtkWidget *attach_btn;
2729 GtkWidget *exteditor_btn;
2730 GtkWidget *linewrap_btn;
2731 GtkWidget *addrbook_btn;
2733 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
2735 gtk_container_add(GTK_CONTAINER(container), toolbar);
2736 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2737 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
2738 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
2739 GTK_TOOLBAR_SPACE_LINE);
2741 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
2742 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2746 icon_wid, toolbar_send_cb, compose);
2748 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
2749 //CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm);
2750 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2752 _("Put into queue folder and send later"),
2754 icon_wid, toolbar_send_later_cb,
2757 CREATE_TOOLBAR_ICON(stock_mail_xpm);
2758 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2760 _("Save to draft folder"),
2762 icon_wid, toolbar_draft_cb,
2765 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
2767 CREATE_TOOLBAR_ICON(stock_paste_xpm);
2768 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2772 icon_wid, toolbar_insert_cb,
2775 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
2776 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2780 icon_wid, toolbar_attach_cb,
2783 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
2785 CREATE_TOOLBAR_ICON(stock_mail_xpm);
2786 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2788 _("Insert signature"),
2790 icon_wid, toolbar_sig_cb, compose);
2792 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
2794 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
2795 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2797 _("Edit with external editor"),
2800 toolbar_ext_editor_cb,
2803 CREATE_TOOLBAR_ICON(linewrap_xpm);
2804 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2806 _("Wrap long lines"),
2809 toolbar_linewrap_cb,
2812 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
2814 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
2815 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2819 icon_wid, toolbar_address_cb,
2822 compose->toolbar = toolbar;
2823 compose->send_btn = send_btn;
2824 compose->sendl_btn = sendl_btn;
2825 compose->draft_btn = draft_btn;
2826 compose->insert_btn = insert_btn;
2827 compose->attach_btn = attach_btn;
2828 compose->sig_btn = sig_btn;
2829 compose->exteditor_btn = exteditor_btn;
2830 compose->linewrap_btn = linewrap_btn;
2831 compose->addrbook_btn = addrbook_btn;
2833 gtk_widget_show_all(toolbar);
2836 #undef CREATE_TOOLBAR_ICON
2838 static GtkWidget *compose_account_option_menu_create(Compose *compose)
2844 gint num = 0, def_menu = 0;
2846 accounts = account_get_list();
2847 g_return_val_if_fail(accounts != NULL, NULL);
2849 hbox = gtk_hbox_new(FALSE, 0);
2850 optmenu = gtk_option_menu_new();
2851 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
2852 menu = gtk_menu_new();
2854 for (; accounts != NULL; accounts = accounts->next, num++) {
2855 PrefsAccount *ac = (PrefsAccount *)accounts->data;
2856 GtkWidget *menuitem;
2859 if (ac == compose->account) def_menu = num;
2861 name = g_strdup_printf("%s <%s> (%s)",
2862 ac->name, ac->address, ac->account_name);
2863 MENUITEM_ADD(menu, menuitem, name, ac);
2865 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
2866 GTK_SIGNAL_FUNC(account_activated),
2870 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
2871 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
2876 static void compose_destroy(Compose *compose)
2879 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2882 /* NOTE: address_completion_end() does nothing with the window
2883 * however this may change. */
2884 address_completion_end(compose->window);
2886 slist_free_strings(compose->to_list);
2887 g_slist_free(compose->to_list);
2888 slist_free_strings(compose->newsgroup_list);
2889 g_slist_free(compose->newsgroup_list);
2891 procmsg_msginfo_free(compose->targetinfo);
2893 g_free(compose->replyto);
2894 g_free(compose->cc);
2895 g_free(compose->bcc);
2896 g_free(compose->newsgroups);
2897 g_free(compose->followup_to);
2899 g_free(compose->inreplyto);
2900 g_free(compose->references);
2901 g_free(compose->msgid);
2902 g_free(compose->boundary);
2904 g_free(compose->exteditor_file);
2906 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
2908 compose_attach_info_free(ainfo);
2910 if (addressbook_get_target_compose() == compose)
2911 addressbook_set_target_compose(NULL);
2913 prefs_common.compose_width = compose->scrolledwin->allocation.width;
2914 prefs_common.compose_height = compose->window->allocation.height;
2916 gtk_widget_destroy(compose->paned);
2920 compose_list = g_list_remove(compose_list, compose);
2923 static void compose_attach_info_free(AttachInfo *ainfo)
2925 g_free(ainfo->file);
2926 g_free(ainfo->content_type);
2927 g_free(ainfo->name);
2931 static void compose_attach_remove_selected(Compose *compose)
2933 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2937 while (clist->selection != NULL) {
2938 row = GPOINTER_TO_INT(clist->selection->data);
2939 ainfo = gtk_clist_get_row_data(clist, row);
2940 compose_attach_info_free(ainfo);
2941 gtk_clist_remove(clist, row);
2945 static struct _AttachProperty
2948 GtkWidget *mimetype_entry;
2949 GtkWidget *encoding_optmenu;
2950 GtkWidget *path_entry;
2951 GtkWidget *filename_entry;
2953 GtkWidget *cancel_btn;
2956 static void compose_attach_property(Compose *compose)
2958 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2962 GtkOptionMenu *optmenu;
2964 if (!clist->selection) return;
2965 row = GPOINTER_TO_INT(clist->selection->data);
2967 ainfo = gtk_clist_get_row_data(clist, row);
2970 if (!attach_prop.window)
2971 compose_attach_property_create(&cancelled);
2972 gtk_widget_grab_focus(attach_prop.ok_btn);
2973 gtk_widget_show(attach_prop.window);
2974 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
2976 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
2977 if (ainfo->encoding == ENC_UNKNOWN)
2978 gtk_option_menu_set_history(optmenu, ENC_BASE64);
2980 gtk_option_menu_set_history(optmenu, ainfo->encoding);
2982 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
2983 ainfo->content_type ? ainfo->content_type : "");
2984 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
2985 ainfo->file ? ainfo->file : "");
2986 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
2987 ainfo->name ? ainfo->name : "");
2991 gchar *cnttype = NULL;
2995 GtkWidget *menuitem;
2999 if (cancelled == TRUE) {
3000 gtk_widget_hide(attach_prop.window);
3004 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
3005 if (*text != '\0') {
3008 text = g_strstrip(g_strdup(text));
3009 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
3010 cnttype = g_strdup(text);
3013 alertpanel_error(_("Invalid MIME type."));
3019 menu = gtk_option_menu_get_menu(optmenu);
3020 menuitem = gtk_menu_get_active(GTK_MENU(menu));
3021 ainfo->encoding = GPOINTER_TO_INT
3022 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
3024 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
3025 if (*text != '\0') {
3026 if (is_file_exist(text) &&
3027 (size = get_file_size(text)) > 0)
3028 file = g_strdup(text);
3031 (_("File doesn't exist or is empty."));
3037 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
3038 if (*text != '\0') {
3039 g_free(ainfo->name);
3040 ainfo->name = g_strdup(text);
3044 g_free(ainfo->content_type);
3045 ainfo->content_type = cnttype;
3048 g_free(ainfo->file);
3054 gtk_clist_set_text(clist, row, COL_MIMETYPE,
3055 ainfo->content_type);
3056 gtk_clist_set_text(clist, row, COL_SIZE,
3057 to_human_readable(ainfo->size));
3058 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
3060 gtk_widget_hide(attach_prop.window);
3065 #define SET_LABEL_AND_ENTRY(str, entry, top) \
3067 label = gtk_label_new(str); \
3068 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
3069 GTK_FILL, 0, 0, 0); \
3070 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
3072 entry = gtk_entry_new(); \
3073 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
3074 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
3077 static void compose_attach_property_create(gboolean *cancelled)
3083 GtkWidget *mimetype_entry;
3086 GtkWidget *optmenu_menu;
3087 GtkWidget *menuitem;
3088 GtkWidget *path_entry;
3089 GtkWidget *filename_entry;
3092 GtkWidget *cancel_btn;
3094 debug_print("Creating attach_property window...\n");
3096 window = gtk_window_new(GTK_WINDOW_DIALOG);
3097 gtk_widget_set_usize(window, 480, -1);
3098 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
3099 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
3100 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
3101 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
3102 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3103 GTK_SIGNAL_FUNC(attach_property_delete_event),
3105 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
3106 GTK_SIGNAL_FUNC(attach_property_key_pressed),
3109 vbox = gtk_vbox_new(FALSE, 8);
3110 gtk_container_add(GTK_CONTAINER(window), vbox);
3112 table = gtk_table_new(4, 2, FALSE);
3113 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
3114 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
3115 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
3117 SET_LABEL_AND_ENTRY(_("MIME type"), mimetype_entry, 0);
3119 label = gtk_label_new(_("Encoding"));
3120 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
3122 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3124 hbox = gtk_hbox_new(FALSE, 0);
3125 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
3126 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3128 optmenu = gtk_option_menu_new();
3129 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3131 optmenu_menu = gtk_menu_new();
3132 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
3133 gtk_widget_set_sensitive(menuitem, FALSE);
3134 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
3135 gtk_widget_set_sensitive(menuitem, FALSE);
3136 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
3137 gtk_widget_set_sensitive(menuitem, FALSE);
3138 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
3140 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
3142 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
3143 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
3145 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
3146 &cancel_btn, _("Cancel"), NULL, NULL);
3147 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
3148 gtk_widget_grab_default(ok_btn);
3150 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
3151 GTK_SIGNAL_FUNC(attach_property_ok),
3153 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
3154 GTK_SIGNAL_FUNC(attach_property_cancel),
3157 gtk_widget_show_all(vbox);
3159 attach_prop.window = window;
3160 attach_prop.mimetype_entry = mimetype_entry;
3161 attach_prop.encoding_optmenu = optmenu;
3162 attach_prop.path_entry = path_entry;
3163 attach_prop.filename_entry = filename_entry;
3164 attach_prop.ok_btn = ok_btn;
3165 attach_prop.cancel_btn = cancel_btn;
3168 #undef SET_LABEL_AND_ENTRY
3170 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
3176 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
3182 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
3183 gboolean *cancelled)
3191 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
3192 gboolean *cancelled)
3194 if (event && event->keyval == GDK_Escape) {
3200 static void compose_exec_ext_editor(Compose *compose)
3206 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
3207 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3209 if (pipe(pipe_fds) < 0) {
3214 if ((pid = fork()) < 0) {
3220 /* close the write side of the pipe */
3223 compose->exteditor_file = g_strdup(tmp);
3224 compose->exteditor_pid = pid;
3225 compose->exteditor_readdes = pipe_fds[0];
3227 compose_set_ext_editor_sensitive(compose, FALSE);
3229 compose->exteditor_tag =
3230 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
3231 compose_input_cb, compose);
3232 } else { /* process-monitoring process */
3238 /* close the read side of the pipe */
3241 if (compose_write_body_to_file(compose, tmp) < 0) {
3242 fd_write(pipe_fds[1], "2\n", 2);
3246 pid_ed = compose_exec_ext_editor_real(tmp);
3248 fd_write(pipe_fds[1], "1\n", 2);
3252 /* wait until editor is terminated */
3253 waitpid(pid_ed, NULL, 0);
3255 fd_write(pipe_fds[1], "0\n", 2);
3262 static gint compose_exec_ext_editor_real(const gchar *file)
3264 static gchar *def_cmd = "emacs %s";
3270 g_return_val_if_fail(file != NULL, -1);
3272 if ((pid = fork()) < 0) {
3277 if (pid != 0) return pid;
3279 /* grandchild process */
3281 if (setpgid(0, getppid()))
3284 if (prefs_common.ext_editor_cmd &&
3285 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
3286 *(p + 1) == 's' && !strchr(p + 2, '%')) {
3287 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
3289 if (prefs_common.ext_editor_cmd)
3290 g_warning(_("External editor command line is invalid: `%s'\n"),
3291 prefs_common.ext_editor_cmd);
3292 g_snprintf(buf, sizeof(buf), def_cmd, file);
3295 cmdline = g_strsplit(buf, " ", 1024);
3296 execvp(cmdline[0], cmdline);
3299 g_strfreev(cmdline);
3304 static gboolean compose_ext_editor_kill(Compose *compose)
3306 pid_t pgid = compose->exteditor_pid * -1;
3309 ret = kill(pgid, 0);
3311 if (ret == 0 || (ret == -1 && EPERM == errno)) {
3315 msg = g_strdup_printf
3316 (_("The external editor is still working.\n"
3317 "Force terminating the process?\n"
3318 "process group id: %d"), -pgid);
3319 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
3322 if (val == G_ALERTDEFAULT) {
3323 gdk_input_remove(compose->exteditor_tag);
3324 close(compose->exteditor_readdes);
3326 if (kill(pgid, SIGTERM) < 0) perror("kill");
3327 waitpid(compose->exteditor_pid, NULL, 0);
3329 g_warning(_("Terminated process group id: %d"), -pgid);
3330 g_warning(_("Temporary file: %s"),
3331 compose->exteditor_file);
3333 compose_set_ext_editor_sensitive(compose, TRUE);
3335 g_free(compose->exteditor_file);
3336 compose->exteditor_file = NULL;
3337 compose->exteditor_pid = -1;
3338 compose->exteditor_readdes = -1;
3339 compose->exteditor_tag = -1;
3347 static void compose_input_cb(gpointer data, gint source,
3348 GdkInputCondition condition)
3351 Compose *compose = (Compose *)data;
3354 debug_print(_("Compose: input from monitoring process\n"));
3356 gdk_input_remove(compose->exteditor_tag);
3359 if (read(source, &buf[i], 1) < 1) {
3363 if (buf[i] == '\n') {
3368 if (i == sizeof(buf) - 1)
3372 waitpid(compose->exteditor_pid, NULL, 0);
3374 if (buf[0] == '0') { /* success */
3375 GtkSText *text = GTK_STEXT(compose->text);
3377 gtk_stext_freeze(text);
3378 gtk_stext_set_point(text, 0);
3379 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
3380 compose_insert_file(compose, compose->exteditor_file);
3381 compose_changed_cb(NULL, compose);
3382 gtk_stext_thaw(text);
3384 if (unlink(compose->exteditor_file) < 0)
3385 FILE_OP_ERROR(compose->exteditor_file, "unlink");
3386 } else if (buf[0] == '1') { /* failed */
3387 g_warning(_("Couldn't exec external editor\n"));
3388 if (unlink(compose->exteditor_file) < 0)
3389 FILE_OP_ERROR(compose->exteditor_file, "unlink");
3390 } else if (buf[0] == '2') {
3391 g_warning(_("Couldn't write to file\n"));
3392 } else if (buf[0] == '3') {
3393 g_warning(_("Pipe read failed\n"));
3398 compose_set_ext_editor_sensitive(compose, TRUE);
3400 g_free(compose->exteditor_file);
3401 compose->exteditor_file = NULL;
3402 compose->exteditor_pid = -1;
3403 compose->exteditor_readdes = -1;
3404 compose->exteditor_tag = -1;
3407 static void compose_set_ext_editor_sensitive(Compose *compose,
3410 GtkItemFactory *ifactory;
3412 ifactory = gtk_item_factory_from_widget(compose->menubar);
3414 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
3415 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
3416 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
3418 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
3419 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
3420 menu_set_sensitive(ifactory, "/Edit/Wrap long lines", sensitive);
3421 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
3424 gtk_widget_set_sensitive(compose->text, sensitive);
3425 gtk_widget_set_sensitive(compose->send_btn, sensitive);
3426 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
3427 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
3428 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
3429 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
3430 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
3431 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
3434 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
3438 cursor_pos = (text->cursor_pos_x - extra) / char_width;
3439 cursor_pos = MAX(cursor_pos, 0);
3444 /* callback functions */
3446 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
3447 * includes "non-client" (windows-izm) in calculation, so this calculation
3448 * may not be accurate.
3450 static gboolean compose_edit_size_alloc(GtkEditable *widget,
3451 GtkAllocation *allocation,
3452 GtkSHRuler *shruler)
3454 if (prefs_common.show_ruler) {
3456 gint line_width_in_chars;
3458 char_width = gtkut_get_font_width
3459 (GTK_WIDGET(widget)->style->font);
3460 line_width_in_chars =
3461 (allocation->width - allocation->x) / char_width;
3463 /* got the maximum */
3464 gtk_ruler_set_range(GTK_RULER(shruler),
3465 0.0, line_width_in_chars,
3466 calc_cursor_xpos(GTK_STEXT(widget),
3469 /*line_width_in_chars*/ char_width);
3475 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
3477 compose_send_cb(data, 0, NULL);
3480 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
3482 compose_send_later_cb(data, 0, NULL);
3485 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
3487 compose_draft_cb(data, 0, NULL);
3490 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
3492 compose_insert_file_cb(data, 0, NULL);
3495 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
3497 compose_attach_cb(data, 0, NULL);
3500 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
3502 Compose *compose = (Compose *)data;
3504 compose_insert_sig(compose);
3507 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
3509 Compose *compose = (Compose *)data;
3511 compose_exec_ext_editor(compose);
3514 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
3516 Compose *compose = (Compose *)data;
3518 compose_wrap_line(compose);
3521 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
3523 compose_address_cb(data, 0, NULL);
3526 static void account_activated(GtkMenuItem *menuitem, gpointer data)
3528 Compose *compose = (Compose *)data;
3532 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
3533 g_return_if_fail(ac != NULL);
3535 if (ac != compose->account) {
3536 compose->account = ac;
3537 compose_set_title(compose);
3541 static void attach_selected(GtkCList *clist, gint row, gint column,
3542 GdkEvent *event, gpointer data)
3544 Compose *compose = (Compose *)data;
3546 if (event && event->type == GDK_2BUTTON_PRESS)
3547 compose_attach_property(compose);
3550 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
3553 Compose *compose = (Compose *)data;
3554 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3559 if (event->button == 3) {
3560 if ((clist->selection && !clist->selection->next) ||
3561 !clist->selection) {
3562 gtk_clist_unselect_all(clist);
3563 if (gtk_clist_get_selection_info(clist,
3566 gtk_clist_select_row(clist, row, column);
3567 gtkut_clist_set_focus_row(clist, row);
3570 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
3571 NULL, NULL, event->button, event->time);
3575 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
3578 Compose *compose = (Compose *)data;
3582 switch (event->keyval) {
3584 compose_attach_remove_selected(compose);
3589 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
3591 Compose *compose = (Compose *)data;
3594 val = compose_send(compose);
3596 if (val == 0) gtk_widget_destroy(compose->window);
3599 static void compose_send_later_cb(gpointer data, guint action,
3602 Compose *compose = (Compose *)data;
3604 gchar *to, *newsgroups;
3606 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3607 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3608 if (*to == '\0' && *newsgroups == '\0') {
3609 alertpanel_error(_("Recipient is not specified."));
3613 g_snprintf(tmp, 22, "%s%ctmpmsg%d",
3614 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3616 if (prefs_common.linewrap_at_send)
3617 compose_wrap_line(compose);
3619 if (compose_write_to_file(compose, tmp, FALSE) < 0 ||
3620 compose_queue(compose, tmp) < 0) {
3621 alertpanel_error(_("Can't queue the message."));
3625 if (prefs_common.savemsg) {
3626 if (compose_save_to_outbox(compose, tmp) < 0)
3628 (_("Can't save the message to outbox."));
3631 if (unlink(tmp) < 0)
3632 FILE_OP_ERROR(tmp, "unlink");
3634 gtk_widget_destroy(compose->window);
3637 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
3639 Compose *compose = (Compose *)data;
3643 draft = folder_get_default_draft();
3644 folder_item_scan(draft);
3646 if (procmsg_msg_exist(compose->targetinfo) &&
3647 compose->targetinfo->folder == draft) {
3648 if (folder_item_remove_msg(draft,
3649 compose->targetinfo->msgnum) < 0)
3650 g_warning(_("can't remove the old draft message\n"));
3652 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
3653 G_DIR_SEPARATOR, (gint)compose);
3655 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
3660 if (folder_item_add_msg(draft, tmp) < 0) {
3669 //folderview_scan_folder_a(DRAFT_DIR, TRUE);
3671 gtk_widget_destroy(compose->window);
3674 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
3676 Compose *compose = (Compose *)data;
3679 file = filesel_select_file(_("Select file"), NULL);
3682 compose_attach_append(compose, file, MIME_UNKNOWN);
3685 static void compose_insert_file_cb(gpointer data, guint action,
3688 Compose *compose = (Compose *)data;
3691 file = filesel_select_file(_("Select file"), NULL);
3694 compose_insert_file(compose, file);
3697 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
3700 compose_close_cb(data, 0, NULL);
3704 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
3706 Compose *compose = (Compose *)data;
3709 if (compose->exteditor_tag != -1) {
3710 if (!compose_ext_editor_kill(compose))
3714 if (compose->modified) {
3715 val = alertpanel(_("Discard message"),
3716 _("This message has been modified. discard it?"),
3717 _("Discard"), _("to Draft"), _("Cancel"));
3720 case G_ALERTDEFAULT:
3722 case G_ALERTALTERNATE:
3723 compose_draft_cb(data, 0, NULL);
3730 gtk_widget_destroy(compose->window);
3733 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
3735 Compose *compose = (Compose *)data;
3737 addressbook_open(compose);
3740 static void compose_ext_editor_cb(gpointer data, guint action,
3743 Compose *compose = (Compose *)data;
3745 compose_exec_ext_editor(compose);
3748 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
3750 compose_destroy(compose);
3753 static void compose_cut_cb(Compose *compose)
3755 if (compose->focused_editable &&
3756 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
3757 gtk_editable_cut_clipboard
3758 (GTK_EDITABLE(compose->focused_editable));
3761 static void compose_copy_cb(Compose *compose)
3763 if (compose->focused_editable &&
3764 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
3765 gtk_editable_copy_clipboard
3766 (GTK_EDITABLE(compose->focused_editable));
3769 static void compose_paste_cb(Compose *compose)
3771 if (compose->focused_editable &&
3772 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
3773 gtk_editable_paste_clipboard
3774 (GTK_EDITABLE(compose->focused_editable));
3777 static void compose_allsel_cb(Compose *compose)
3779 if (compose->focused_editable &&
3780 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
3781 gtk_editable_select_region
3782 (GTK_EDITABLE(compose->focused_editable), 0, -1);
3785 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
3787 if (GTK_IS_EDITABLE(widget))
3788 compose->focused_editable = widget;
3791 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
3793 if (compose->modified == FALSE) {
3794 compose->modified = TRUE;
3795 compose_set_title(compose);
3799 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
3802 gtk_stext_set_point(GTK_STEXT(widget),
3803 gtk_editable_get_position(GTK_EDITABLE(widget)));
3807 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
3810 gtk_stext_set_point(GTK_STEXT(widget),
3811 gtk_editable_get_position(GTK_EDITABLE(widget)));
3815 static void compose_toggle_to_cb(gpointer data, guint action,
3818 Compose *compose = (Compose *)data;
3820 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3821 gtk_widget_show(compose->to_hbox);
3822 gtk_widget_show(compose->to_entry);
3823 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
3824 compose->use_to = TRUE;
3826 gtk_widget_hide(compose->to_hbox);
3827 gtk_widget_hide(compose->to_entry);
3828 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
3829 gtk_widget_queue_resize(compose->table_vbox);
3830 compose->use_to = FALSE;
3833 if (addressbook_get_target_compose() == compose)
3834 addressbook_set_target_compose(compose);
3837 static void compose_toggle_cc_cb(gpointer data, guint action,
3840 Compose *compose = (Compose *)data;
3842 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3843 gtk_widget_show(compose->cc_hbox);
3844 gtk_widget_show(compose->cc_entry);
3845 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
3846 compose->use_cc = TRUE;
3848 gtk_widget_hide(compose->cc_hbox);
3849 gtk_widget_hide(compose->cc_entry);
3850 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
3851 gtk_widget_queue_resize(compose->table_vbox);
3852 compose->use_cc = FALSE;
3855 if (addressbook_get_target_compose() == compose)
3856 addressbook_set_target_compose(compose);
3859 static void compose_toggle_bcc_cb(gpointer data, guint action,
3862 Compose *compose = (Compose *)data;
3864 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3865 gtk_widget_show(compose->bcc_hbox);
3866 gtk_widget_show(compose->bcc_entry);
3867 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
3868 compose->use_bcc = TRUE;
3870 gtk_widget_hide(compose->bcc_hbox);
3871 gtk_widget_hide(compose->bcc_entry);
3872 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
3873 gtk_widget_queue_resize(compose->table_vbox);
3874 compose->use_bcc = FALSE;
3877 if (addressbook_get_target_compose() == compose)
3878 addressbook_set_target_compose(compose);
3881 static void compose_toggle_replyto_cb(gpointer data, guint action,
3884 Compose *compose = (Compose *)data;
3886 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3887 gtk_widget_show(compose->reply_hbox);
3888 gtk_widget_show(compose->reply_entry);
3889 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
3890 compose->use_replyto = TRUE;
3892 gtk_widget_hide(compose->reply_hbox);
3893 gtk_widget_hide(compose->reply_entry);
3894 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
3895 gtk_widget_queue_resize(compose->table_vbox);
3896 compose->use_replyto = FALSE;
3900 static void compose_toggle_followupto_cb(gpointer data, guint action,
3903 Compose *compose = (Compose *)data;
3905 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3906 gtk_widget_show(compose->followup_hbox);
3907 gtk_widget_show(compose->followup_entry);
3908 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
3909 compose->use_followupto = TRUE;
3911 gtk_widget_hide(compose->followup_hbox);
3912 gtk_widget_hide(compose->followup_entry);
3913 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
3914 gtk_widget_queue_resize(compose->table_vbox);
3915 compose->use_followupto = FALSE;
3919 static void compose_toggle_attach_cb(gpointer data, guint action,
3922 Compose *compose = (Compose *)data;
3924 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3925 gtk_widget_ref(compose->edit_vbox);
3927 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
3928 compose->edit_vbox);
3929 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
3930 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
3932 gtk_widget_show(compose->paned);
3934 gtk_widget_unref(compose->edit_vbox);
3935 gtk_widget_unref(compose->paned);
3937 compose->use_attach = TRUE;
3939 gtk_widget_ref(compose->paned);
3940 gtk_widget_ref(compose->edit_vbox);
3942 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
3944 gtk_container_remove(GTK_CONTAINER(compose->paned),
3945 compose->edit_vbox);
3946 gtk_box_pack_start(GTK_BOX(compose->vbox2),
3947 compose->edit_vbox, TRUE, TRUE, 0);
3949 gtk_widget_unref(compose->edit_vbox);
3951 compose->use_attach = FALSE;
3956 static void compose_toggle_sign_cb(gpointer data, guint action,
3959 Compose *compose = (Compose *)data;
3961 if (GTK_CHECK_MENU_ITEM(widget)->active)
3962 compose->use_signing = TRUE;
3964 compose->use_signing = FALSE;
3967 static void compose_toggle_encrypt_cb(gpointer data, guint action,
3970 Compose *compose = (Compose *)data;
3972 if (GTK_CHECK_MENU_ITEM(widget)->active)
3973 compose->use_encryption = TRUE;
3975 compose->use_encryption = FALSE;
3977 #endif /* USE_GPGME */
3979 static void compose_toggle_ruler_cb(gpointer data, guint action,
3982 Compose *compose = (Compose *)data;
3984 if (GTK_CHECK_MENU_ITEM(widget)->active) {
3985 gtk_widget_show(compose->ruler_hbox);
3986 prefs_common.show_ruler = TRUE;
3988 gtk_widget_hide(compose->ruler_hbox);
3989 gtk_widget_queue_resize(compose->edit_vbox);
3990 prefs_common.show_ruler = FALSE;
3994 static void compose_attach_drag_received_cb (GtkWidget *widget,
3995 GdkDragContext *drag_context,
3998 GtkSelectionData *data,
4003 Compose *compose = (Compose *)user_data;
4006 list = uri_list_extract_filenames((const gchar *)data->data);
4007 for (tmp = list; tmp != NULL; tmp = tmp->next)
4008 compose_attach_append(compose, (const gchar *)tmp->data,
4010 list_free_strings(list);
4014 static void compose_insert_drag_received_cb (GtkWidget *widget,
4015 GdkDragContext *drag_context,
4018 GtkSelectionData *data,
4023 Compose *compose = (Compose *)user_data;
4026 list = uri_list_extract_filenames((const gchar *)data->data);
4027 for (tmp = list; tmp != NULL; tmp = tmp->next)
4028 compose_insert_file(compose, (const gchar *)tmp->data);
4029 list_free_strings(list);
4033 static void to_activated(GtkWidget *widget, Compose *compose)
4035 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
4036 gtk_widget_grab_focus(compose->newsgroups_entry);
4038 gtk_widget_grab_focus(compose->subject_entry);
4041 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
4043 gtk_widget_grab_focus(compose->subject_entry);
4046 static void subject_activated(GtkWidget *widget, Compose *compose)
4048 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
4049 gtk_widget_grab_focus(compose->cc_entry);
4050 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4051 gtk_widget_grab_focus(compose->bcc_entry);
4052 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4053 gtk_widget_grab_focus(compose->reply_entry);
4054 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4055 gtk_widget_grab_focus(compose->followup_entry);
4057 gtk_widget_grab_focus(compose->text);
4060 static void cc_activated(GtkWidget *widget, Compose *compose)
4062 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4063 gtk_widget_grab_focus(compose->bcc_entry);
4064 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4065 gtk_widget_grab_focus(compose->reply_entry);
4066 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4067 gtk_widget_grab_focus(compose->followup_entry);
4069 gtk_widget_grab_focus(compose->text);
4072 static void bcc_activated(GtkWidget *widget, Compose *compose)
4074 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4075 gtk_widget_grab_focus(compose->reply_entry);
4076 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4077 gtk_widget_grab_focus(compose->followup_entry);
4079 gtk_widget_grab_focus(compose->text);
4082 static void replyto_activated(GtkWidget *widget, Compose *compose)
4084 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4085 gtk_widget_grab_focus(compose->followup_entry);
4087 gtk_widget_grab_focus(compose->text);
4090 static void followupto_activated(GtkWidget *widget, Compose *compose)
4092 gtk_widget_grab_focus(compose->text);
4095 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
4098 Compose *compose = (Compose *)data;
4100 if (GTK_CHECK_MENU_ITEM(widget)->active)
4101 compose->return_receipt = TRUE;
4103 compose->return_receipt = FALSE;