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"
106 #include "quote_fmt.tab.h"
115 #define N_ATTACH_COLS 3
117 #define B64_LINE_SIZE 57
118 #define B64_BUFFSIZE 77
120 #define MAX_REFERENCES_LEN 999
122 static GdkColor quote_color = {0, 0, 0, 0xbfff};
124 static GList *compose_list = NULL;
126 static Compose *compose_create (PrefsAccount *account);
127 static void compose_toolbar_create (Compose *compose,
128 GtkWidget *container);
129 static GtkWidget *compose_account_option_menu_create
131 static void compose_destroy (Compose *compose);
133 static gint compose_parse_header (Compose *compose,
135 static gchar *compose_parse_references (const gchar *ref,
137 static void compose_quote_file (Compose *compose,
140 static gchar *compose_quote_parse_fmt (Compose *compose,
143 static void compose_reply_set_entry (Compose *compose,
147 static void compose_reedit_set_entry (Compose *compose,
149 static void compose_insert_sig (Compose *compose);
150 static void compose_insert_file (Compose *compose,
152 static void compose_attach_append (Compose *compose,
154 ContentType cnttype);
155 static void compose_wrap_line (Compose *compose);
156 static void compose_set_title (Compose *compose);
158 static PrefsAccount *compose_current_mail_account(void);
159 /* static gint compose_send (Compose *compose); */
160 static gint compose_write_to_file (Compose *compose,
163 static gint compose_write_body_to_file (Compose *compose,
165 static gint compose_save_to_outbox (Compose *compose,
167 static gint compose_queue (Compose *compose,
169 static void compose_write_attach (Compose *compose,
171 static gint compose_write_headers (Compose *compose,
173 const gchar *charset,
174 EncodingType encoding,
177 static void compose_convert_header (gchar *dest,
181 static void compose_generate_msgid (Compose *compose,
185 static void compose_attach_info_free (AttachInfo *ainfo);
186 static void compose_attach_remove_selected (Compose *compose);
188 static void compose_attach_property (Compose *compose);
189 static void compose_attach_property_create (gboolean *cancelled);
190 static void attach_property_ok (GtkWidget *widget,
191 gboolean *cancelled);
192 static void attach_property_cancel (GtkWidget *widget,
193 gboolean *cancelled);
194 static gint attach_property_delete_event (GtkWidget *widget,
196 gboolean *cancelled);
197 static void attach_property_key_pressed (GtkWidget *widget,
199 gboolean *cancelled);
201 static void compose_exec_ext_editor (Compose *compose);
202 static gint compose_exec_ext_editor_real (const gchar *file);
203 static gboolean compose_ext_editor_kill (Compose *compose);
204 static void compose_input_cb (gpointer data,
206 GdkInputCondition condition);
207 static void compose_set_ext_editor_sensitive (Compose *compose,
210 static gint calc_cursor_xpos (GtkSText *text,
214 /* callback functions */
216 static gboolean compose_edit_size_alloc (GtkEditable *widget,
217 GtkAllocation *allocation,
218 GtkSHRuler *shruler);
220 static void toolbar_send_cb (GtkWidget *widget,
222 static void toolbar_send_later_cb (GtkWidget *widget,
224 static void toolbar_draft_cb (GtkWidget *widget,
226 static void toolbar_insert_cb (GtkWidget *widget,
228 static void toolbar_attach_cb (GtkWidget *widget,
230 static void toolbar_sig_cb (GtkWidget *widget,
232 static void toolbar_ext_editor_cb (GtkWidget *widget,
234 static void toolbar_linewrap_cb (GtkWidget *widget,
236 static void toolbar_address_cb (GtkWidget *widget,
239 static void account_activated (GtkMenuItem *menuitem,
242 static void attach_selected (GtkCList *clist,
247 static void attach_button_pressed (GtkWidget *widget,
248 GdkEventButton *event,
250 static void attach_key_pressed (GtkWidget *widget,
254 static void compose_send_cb (gpointer data,
257 static void compose_send_later_cb (gpointer data,
261 static void compose_draft_cb (gpointer data,
265 static void compose_attach_cb (gpointer data,
268 static void compose_insert_file_cb (gpointer data,
272 static void compose_close_cb (gpointer data,
275 static void compose_address_cb (gpointer data,
279 static void compose_ext_editor_cb (gpointer data,
283 static gint compose_delete_cb (GtkWidget *widget,
286 static void compose_destroy_cb (GtkWidget *widget,
289 static void compose_cut_cb (Compose *compose);
290 static void compose_copy_cb (Compose *compose);
291 static void compose_paste_cb (Compose *compose);
292 static void compose_allsel_cb (Compose *compose);
294 static void compose_grab_focus_cb (GtkWidget *widget,
297 static void compose_changed_cb (GtkEditable *editable,
299 static void compose_button_press_cb (GtkWidget *widget,
300 GdkEventButton *event,
303 static void compose_key_press_cb (GtkWidget *widget,
308 static void compose_toggle_to_cb (gpointer data,
311 static void compose_toggle_cc_cb (gpointer data,
314 static void compose_toggle_bcc_cb (gpointer data,
317 static void compose_toggle_replyto_cb (gpointer data,
320 static void compose_toggle_followupto_cb(gpointer data,
323 static void compose_toggle_attach_cb (gpointer data,
326 static void compose_toggle_ruler_cb (gpointer data,
330 static void compose_toggle_sign_cb (gpointer data,
333 static void compose_toggle_encrypt_cb (gpointer data,
337 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
340 static void compose_attach_drag_received_cb (GtkWidget *widget,
341 GdkDragContext *drag_context,
344 GtkSelectionData *data,
348 static void compose_insert_drag_received_cb (GtkWidget *widget,
349 GdkDragContext *drag_context,
352 GtkSelectionData *data,
357 static void to_activated (GtkWidget *widget,
359 static void newsgroups_activated (GtkWidget *widget,
361 static void subject_activated (GtkWidget *widget,
363 static void cc_activated (GtkWidget *widget,
365 static void bcc_activated (GtkWidget *widget,
367 static void replyto_activated (GtkWidget *widget,
369 static void followupto_activated (GtkWidget *widget,
371 static void compose_attach_parts(Compose * compose,
374 static gchar *compose_quote_fmt (Compose *compose,
377 const gchar * qmark);
379 static GtkItemFactoryEntry compose_popup_entries[] =
381 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
382 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
383 {N_("/---"), NULL, NULL, 0, "<Separator>"},
384 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
387 static GtkItemFactoryEntry compose_entries[] =
389 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
390 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
391 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
392 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
393 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
394 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
396 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
397 {N_("/_Edit/_Undo"), "<control>Z", NULL, 0, NULL},
398 {N_("/_Edit/_Redo"), "<control>Y", NULL, 0, NULL},
399 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
400 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
401 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
402 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
403 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
404 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
405 {N_("/_Edit/Wrap long _lines"), "<alt>L", compose_wrap_line, 0, NULL},
406 {N_("/_Edit/Edit with e_xternal editor"), "<alt>X",
407 compose_ext_editor_cb, 0, NULL},
409 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
410 {N_("/_Message/_Send"), "<shift><control>S",
411 compose_send_cb, 0, NULL},
412 {N_("/_Message/Send _later"), "<shift><alt>S",
413 compose_send_later_cb, 0, NULL},
414 {N_("/_Message/Save to _draft folder"),
415 "<alt>D", compose_draft_cb, 0, NULL},
416 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
417 {N_("/_Message/_To"), NULL, compose_toggle_to_cb, 0, "<ToggleItem>"},
418 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb, 0, "<ToggleItem>"},
419 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb, 0, "<ToggleItem>"},
420 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
421 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
422 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
423 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
424 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
426 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
427 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb, 0, "<ToggleItem>"},
428 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
429 #endif /* USE_GPGME */
430 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
431 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
432 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
433 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
434 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb, 0, NULL},
435 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
436 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
439 static GtkTargetEntry compose_mime_types[] =
441 {"text/uri-list", 0, 0}
444 Compose * compose_new(PrefsAccount *account)
446 return compose_new_with_recipient(account, NULL);
449 Compose * compose_new_with_recipient(PrefsAccount *account, const gchar *to)
453 if (!account) account = cur_account;
454 g_return_val_if_fail(account != NULL, NULL);
456 compose = compose_create(account);
457 compose->mode = COMPOSE_NEW;
459 if (prefs_common.auto_sig)
460 compose_insert_sig(compose);
461 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
462 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
464 if (account->protocol != A_NNTP) {
466 compose_entry_append(compose, to, COMPOSE_TO);
467 gtk_widget_grab_focus(compose->subject_entry);
469 gtk_widget_grab_focus(compose->to_entry);
471 gtk_widget_grab_focus(compose->newsgroups_entry);
476 #define CHANGE_FLAGS(msginfo) \
478 if (msginfo->folder->folder->change_flags != NULL) \
479 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
484 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
488 PrefsAccount *account;
489 PrefsAccount *reply_account;
492 g_return_if_fail(msginfo != NULL);
493 g_return_if_fail(msginfo->folder != NULL);
495 account = msginfo->folder->folder->account;
496 if (!account) account = cur_account;
497 g_return_if_fail(account != NULL);
499 if (to_author && account->protocol == A_NNTP) {
501 account_find_mail_from_address(account->address);
503 reply_account = compose_current_mail_account();
507 reply_account = account;
509 MSG_UNSET_FLAGS(msginfo->flags, MSG_FORWARDED);
510 MSG_SET_FLAGS(msginfo->flags, MSG_REPLIED);
512 CHANGE_FLAGS(msginfo);
514 compose = compose_create(reply_account);
515 compose->mode = COMPOSE_REPLY;
517 if (compose_parse_header(compose, msginfo) < 0) return;
518 compose_reply_set_entry(compose, msginfo, to_all, to_author);
520 text = GTK_STEXT(compose->text);
521 gtk_stext_freeze(text);
527 if ((fp = procmime_get_text_part(msginfo)) == NULL)
528 g_warning(_("Can't get text part\n"));
532 if (prefs_common.quotemark && *prefs_common.quotemark)
533 qmark = prefs_common.quotemark;
537 quote_str = compose_quote_fmt(compose, msginfo,
538 prefs_common.quotefmt,
542 quote_str = compose_quote_parse_fmt
543 (compose, msginfo, prefs_common.quotefmt);
546 if (quote_str != NULL)
547 gtk_stext_insert(text, NULL, NULL, NULL,
549 /* g_free(quote_str); */
550 /* compose_quote_file(compose, msginfo, fp); */
555 if (prefs_common.auto_sig)
556 compose_insert_sig(compose);
557 gtk_editable_set_position(GTK_EDITABLE(text), 0);
558 gtk_stext_set_point(text, 0);
560 gtk_stext_thaw(text);
561 gtk_widget_grab_focus(compose->text);
565 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
570 g_return_val_if_fail(mimeinfo != NULL, NULL);
572 base = mimeinfo->filename ? mimeinfo->filename
573 : mimeinfo->name ? mimeinfo->name : NULL;
575 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL)
576 base = "mimetmp.html";
578 base = base ? base : "mimetmp";
579 base = g_basename(base);
580 if (*base == '\0') base = "mimetmp";
583 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
589 static gchar * mime_extract_file(gchar * source, MimeInfo *partinfo)
593 if (!partinfo) return;
595 filename = procmime_get_file_name(partinfo);
597 if (procmime_get_part(filename, source, partinfo) < 0)
599 (_("Can't get the part of multipart message."));
604 static void compose_attach_parts(Compose * compose,
614 gint boundary_len = 0;
616 glong fpos, prev_fpos;
621 g_return_if_fail(msginfo != NULL);
625 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
626 mimeinfo = procmime_scan_mime_header(fp);
627 if (!mimeinfo) break;
629 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
630 rfc2015_is_encrypted(mimeinfo)) {
631 MSG_SET_FLAGS(msginfo->flags, MSG_ENCRYPTED);
633 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
634 !msginfo->plaintext_file &&
635 !msginfo->decryption_failed) {
636 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
637 if (msginfo->plaintext_file &&
638 !msginfo->decryption_failed) {
646 #else /* !USE_GPGME */
647 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
648 mimeinfo = procmime_scan_mime_header(fp);
649 #endif /* USE_GPGME */
652 if (!mimeinfo) return;
653 if (mimeinfo->mime_type == MIME_TEXT)
656 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
658 g_return_if_fail(mimeinfo != NULL);
659 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
661 if (mimeinfo->mime_type == MIME_MULTIPART) {
662 g_return_if_fail(mimeinfo->boundary != NULL);
663 g_return_if_fail(mimeinfo->sub == NULL);
665 g_return_if_fail(fp != NULL);
667 boundary = mimeinfo->boundary;
670 boundary_len = strlen(boundary);
672 /* look for first boundary */
673 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
674 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
681 if ((fpos = ftell(fp)) < 0) {
687 for (npart = 0;; npart++) {
689 gboolean eom = FALSE;
693 partinfo = procmime_scan_mime_header(fp);
694 if (!partinfo) break;
697 procmime_mimeinfo_insert(mimeinfo, partinfo);
699 procmime_mimeinfo_free(partinfo);
701 /* look for next boundary */
703 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
704 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
705 if (buf[2 + boundary_len] == '-' &&
706 buf[2 + boundary_len + 1] == '-')
712 eom = TRUE; /* broken MIME message */
715 partinfo->size = fpos - prev_fpos - strlen(buf);
720 source = procmsg_get_message_file_path(msginfo);
722 g_return_if_fail(mimeinfo != NULL);
724 if (!mimeinfo->main && mimeinfo->parent)
726 filename = mime_extract_file(source, mimeinfo);
728 compose_attach_append(compose, filename,
729 mimeinfo->mime_type);
734 if (mimeinfo->sub && mimeinfo->sub->children)
736 filename = mime_extract_file(source, mimeinfo->sub);
738 compose_attach_append(compose, filename,
739 mimeinfo->sub->mime_type);
744 if (mimeinfo->children) {
747 child = mimeinfo->children;
749 filename = mime_extract_file(source, child);
751 compose_attach_append(compose, filename,
762 procmime_mimeinfo_free_all(mimeinfo);
766 #define INSERT_FW_HEADER(var, hdr) \
767 if (msginfo->var && *msginfo->var) { \
768 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
769 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
770 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
773 Compose * compose_forward(PrefsAccount * account, MsgInfo *msginfo,
777 /* PrefsAccount *account; */
782 g_return_val_if_fail(msginfo != NULL, NULL);
783 g_return_val_if_fail(msginfo->folder != NULL, NULL);
785 if (account == NULL) {
786 account = msginfo->folder->folder->account;
787 if (!account) account = cur_account;
789 g_return_val_if_fail(account != NULL, NULL);
791 MSG_UNSET_FLAGS(msginfo->flags, MSG_REPLIED);
792 MSG_SET_FLAGS(msginfo->flags, MSG_FORWARDED);
794 CHANGE_FLAGS(msginfo);
796 compose = compose_create(account);
797 compose->mode = COMPOSE_FORWARD;
799 if (msginfo->subject && *msginfo->subject) {
800 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
801 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
805 text = GTK_STEXT(compose->text);
806 gtk_stext_freeze(text);
811 msgfile = procmsg_get_message_file_path(msginfo);
812 if (!is_file_exist(msgfile))
813 g_warning(_("%s: file not exist\n"), msgfile);
815 compose_attach_append(compose, msgfile,
816 MIME_MESSAGE_RFC822);
823 if ((fp = procmime_get_text_part(msginfo)) == NULL)
824 g_warning(_("Can't get text part\n"));
828 if (prefs_common.fw_quotemark &&
829 *prefs_common.fw_quotemark)
830 qmark = prefs_common.fw_quotemark;
834 quote_str = compose_quote_fmt(compose, msginfo,
835 prefs_common.fw_quotefmt,
838 if (quote_str != NULL)
839 gtk_stext_insert(text, NULL, NULL, NULL,
845 compose_attach_parts(compose, msginfo);
848 if (prefs_common.auto_sig)
849 compose_insert_sig(compose);
850 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
851 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
853 gtk_stext_thaw(text);
854 if (account->protocol != A_NNTP)
855 gtk_widget_grab_focus(compose->to_entry);
857 gtk_widget_grab_focus(compose->newsgroups_entry);
862 #undef INSERT_FW_HEADER
864 void compose_reedit(MsgInfo *msginfo)
867 PrefsAccount *account;
872 g_return_if_fail(msginfo != NULL);
873 g_return_if_fail(msginfo->folder != NULL);
875 account = msginfo->folder->folder->account;
876 if (!account) account = cur_account;
877 g_return_if_fail(account != NULL);
879 compose = compose_create(account);
880 compose->mode = COMPOSE_REEDIT_DRAFT;
881 compose->targetinfo = procmsg_msginfo_copy(msginfo);
883 if (compose_parse_header(compose, msginfo) < 0) return;
884 compose_reedit_set_entry(compose, msginfo);
886 text = GTK_STEXT(compose->text);
887 gtk_stext_freeze(text);
889 if ((fp = procmime_get_text_part(msginfo)) == NULL)
890 g_warning(_("Can't get text part\n"));
892 while (fgets(buf, sizeof(buf), fp) != NULL)
893 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
896 compose_attach_parts(compose, msginfo);
898 gtk_stext_thaw(text);
899 gtk_widget_grab_focus(compose->text);
902 GList *compose_get_compose_list(void)
907 void compose_entry_append(Compose *compose, const gchar *address,
908 ComposeEntryType type)
913 if (!address || *address == '\0') return;
917 entry = GTK_ENTRY(compose->cc_entry);
920 entry = GTK_ENTRY(compose->bcc_entry);
922 case COMPOSE_NEWSGROUPS:
923 entry = GTK_ENTRY(compose->newsgroups_entry);
927 entry = GTK_ENTRY(compose->to_entry);
931 text = gtk_entry_get_text(entry);
933 gtk_entry_append_text(entry, ", ");
934 gtk_entry_append_text(entry, address);
937 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
939 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
940 {"Cc:", NULL, FALSE},
941 {"References:", NULL, FALSE},
942 {"Bcc:", NULL, FALSE},
943 {"Newsgroups:", NULL, FALSE},
944 {"Followup-To:", NULL, FALSE},
945 {NULL, NULL, FALSE}};
959 g_return_val_if_fail(msginfo != NULL, -1);
961 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
962 procheader_get_header_fields(fp, hentry);
965 if (hentry[H_REPLY_TO].body != NULL) {
966 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
967 compose->replyto = hentry[H_REPLY_TO].body;
968 hentry[H_REPLY_TO].body = NULL;
970 if (hentry[H_CC].body != NULL) {
971 conv_unmime_header_overwrite(hentry[H_CC].body);
972 compose->cc = hentry[H_CC].body;
973 hentry[H_CC].body = NULL;
975 if (hentry[H_REFERENCES].body != NULL) {
976 if (compose->mode == COMPOSE_REEDIT_DRAFT)
977 compose->references = hentry[H_REFERENCES].body;
979 compose->references = compose_parse_references
980 (hentry[H_REFERENCES].body, msginfo->msgid);
981 g_free(hentry[H_REFERENCES].body);
983 hentry[H_REFERENCES].body = NULL;
985 if (hentry[H_BCC].body != NULL) {
986 if (compose->mode == COMPOSE_REEDIT_DRAFT) {
987 conv_unmime_header_overwrite(hentry[H_BCC].body);
988 compose->bcc = hentry[H_BCC].body;
990 g_free(hentry[H_BCC].body);
991 hentry[H_BCC].body = NULL;
993 if (hentry[H_NEWSGROUPS].body != NULL) {
994 compose->newsgroups = hentry[H_NEWSGROUPS].body;
995 hentry[H_NEWSGROUPS].body = NULL;
997 if (hentry[H_FOLLOWUP_TO].body != NULL) {
998 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
999 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1000 hentry[H_FOLLOWUP_TO].body = NULL;
1003 if (compose->mode == COMPOSE_REEDIT_DRAFT && msginfo->inreplyto)
1004 compose->inreplyto = g_strdup(msginfo->inreplyto);
1005 else if (compose->mode != COMPOSE_REEDIT_DRAFT &&
1006 msginfo->msgid && *msginfo->msgid) {
1007 compose->inreplyto = g_strdup(msginfo->msgid);
1009 if (!compose->references) {
1010 if (msginfo->inreplyto && *msginfo->inreplyto)
1011 compose->references =
1012 g_strdup_printf("<%s>\n\t<%s>",
1016 compose->references =
1017 g_strconcat("<", msginfo->msgid, ">",
1025 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1027 GSList *ref_id_list, *cur;
1031 ref_id_list = references_list_append(NULL, ref);
1032 if (!ref_id_list) return NULL;
1033 if (msgid && *msgid)
1034 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1039 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1040 /* "<" + Message-ID + ">" + CR+LF+TAB */
1041 len += strlen((gchar *)cur->data) + 5;
1043 if (len > MAX_REFERENCES_LEN) {
1044 /* remove second message-ID */
1045 if (ref_id_list && ref_id_list->next &&
1046 ref_id_list->next->next) {
1047 g_free(ref_id_list->next->data);
1048 ref_id_list = g_slist_remove
1049 (ref_id_list, ref_id_list->next->data);
1051 slist_free_strings(ref_id_list);
1052 g_slist_free(ref_id_list);
1059 new_ref = g_string_new("");
1060 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1061 if (new_ref->len > 0)
1062 g_string_append(new_ref, "\n\t");
1063 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1066 slist_free_strings(ref_id_list);
1067 g_slist_free(ref_id_list);
1069 new_ref_str = new_ref->str;
1070 g_string_free(new_ref, FALSE);
1076 static void compose_quote_file(Compose *compose, MsgInfo *msginfo, FILE *fp)
1078 GtkSText *text = GTK_STEXT(compose->text);
1081 GdkColor *qcolor = NULL;
1082 gchar buf[BUFFSIZE];
1084 gchar *linep, *cur, *leftp;
1085 gint line_len, cur_len;
1090 // if (prefs_common.enable_color) qcolor = "e_color;
1091 if (prefs_common.quotemark && *prefs_common.quotemark)
1092 qmark = prefs_common.quotemark;
1095 quote_str = compose_quote_parse_fmt(compose, msginfo, qmark);
1096 g_return_if_fail(quote_str != NULL);
1097 qlen = strlen(quote_str);
1099 if (!prefs_common.linewrap_quote ||
1100 prefs_common.linewrap_len <= qlen) {
1101 while (fgets(buf, sizeof(buf), fp) != NULL) {
1102 gtk_stext_insert(text, NULL, qcolor, NULL,
1104 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1110 wrap_len = prefs_common.linewrap_len - qlen;
1112 while (fgets(buf, sizeof(buf), fp) != NULL) {
1114 str_len = strlen(buf);
1116 if (str_len <= wrap_len) {
1117 gtk_stext_insert(text, NULL, qcolor, NULL,
1119 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1120 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1124 linep = cur = leftp = buf;
1125 line_len = cur_len = 0;
1127 while (*cur != '\0') {
1128 ch_len = mblen(cur, MB_CUR_MAX);
1129 if (ch_len < 0) ch_len = 1;
1131 if (ch_len == 1 && isspace(*cur)) {
1132 linep = cur + ch_len;
1133 line_len = cur_len + ch_len;
1136 if (cur_len + ch_len > wrap_len && line_len > 0) {
1137 gtk_stext_insert(text, NULL, qcolor, NULL,
1140 if (isspace(*(linep - 1)))
1141 gtk_stext_insert(text, NULL,
1143 leftp, line_len - 1);
1145 gtk_stext_insert(text, NULL,
1148 gtk_stext_insert(text, NULL, NULL, NULL,
1152 cur_len = cur_len - line_len + ch_len;
1159 linep = cur + ch_len;
1160 line_len = cur_len + ch_len;
1167 gtk_stext_insert(text, NULL, qcolor, NULL,
1169 gtk_stext_insert(text, NULL, qcolor, NULL, leftp, -1);
1170 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1179 static gchar *compose_quote_parse_fmt(Compose *compose, MsgInfo *msginfo,
1183 size_t buf_len = 1024;
1191 if (!fmt || *fmt == '\0') return 0;
1193 Xalloca(mbs, sizeof(wchar_t) + 1, return 0);
1194 Xalloca(wcsfmt, (strlen(fmt) + 1) * sizeof(wchar_t), return 0);
1195 mbstowcs(wcsfmt, fmt, strlen(fmt) + 1);
1198 ext_str = g_malloc(sizeof(gchar) * buf_len);
1199 g_return_val_if_fail(ext_str != NULL, NULL);
1204 len = wctomb(mbs, *sp);
1210 wctomb(mbs, *(++sp));
1215 str = msginfo->date;
1219 str = msginfo->from;
1223 if (!msginfo->fromname) {sp++; break;}
1224 p = msginfo->fromname;
1225 tmp[0] = tmp[1] = tmp[2] = '\0';
1227 if (*p && isalnum(*p))
1228 tmp[0] = toupper(*p);
1235 while (*p && !isspace(*p)) p++;
1236 while (*p && isspace(*p)) p++;
1237 if (*p && isalnum(*p))
1238 tmp[1] = toupper(*p);
1241 if (tmp[1]) str = tmp;
1245 str = msginfo->fromname;
1249 if (!msginfo->fromname) {sp++; break;}
1250 Xstrdup_a(str, msginfo->fromname,
1253 while (*p && !isspace(*p)) p++;
1258 str = msginfo->subject;
1266 if (!msginfo->msgid) {sp++; break;}
1267 Xalloca(str, strlen(msginfo->msgid) + 3,
1269 g_snprintf(str, strlen(msginfo->msgid) + 3,
1270 "<%s>", msginfo->msgid);
1282 while (ext_len + strlen(str) + 1 > buf_len)
1284 ext_str = g_realloc(ext_str,
1285 sizeof(gchar) * buf_len);
1286 g_return_val_if_fail(ext_str != NULL, NULL);
1287 strcpy(ext_str + ext_len, str);
1288 ext_len += strlen(str);
1290 } else if (*mbs == '\\') {
1291 wctomb(mbs, *(++sp));
1309 while (ext_len + strlen(str) + 1 > buf_len)
1311 ext_str = g_realloc(ext_str,
1312 sizeof(gchar) * buf_len);
1313 g_return_val_if_fail(ext_str != NULL, NULL);
1314 strcpy(ext_str + ext_len, str);
1315 ext_len += strlen(str);
1319 while (ext_len + len + 1 > buf_len) buf_len += 1024;
1320 ext_str = g_realloc(ext_str, sizeof(gchar) * buf_len);
1321 g_return_val_if_fail(ext_str != NULL, NULL);
1322 strcpy(ext_str + ext_len, mbs);
1329 ext_str = g_realloc(ext_str, strlen(ext_str) + 1);
1335 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1336 gboolean to_all, gboolean to_author)
1341 GHashTable *to_table;
1343 g_return_if_fail(compose->account != NULL);
1344 g_return_if_fail(msginfo != NULL);
1346 if (compose->account->protocol != A_NNTP)
1347 gtk_entry_set_text(GTK_ENTRY(compose->to_entry),
1348 ( (compose->replyto && !to_author)
1350 : msginfo->from ? msginfo->from : ""));
1351 if (compose->account->protocol == A_NNTP)
1352 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry),
1353 compose->followup_to ? compose->followup_to
1354 : compose->newsgroups ? compose->newsgroups
1357 if (msginfo->subject && *msginfo->subject) {
1358 gchar *buf, *buf2, *p;
1360 buf = g_strdup(msginfo->subject);
1361 while (!strncasecmp(buf, "Re:", 3)) {
1363 while (isspace(*p)) p++;
1364 memmove(buf, p, strlen(p) + 1);
1367 buf2 = g_strdup_printf("Re: %s", buf);
1368 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1372 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1374 if (!to_all || compose->account->protocol == A_NNTP) return;
1376 from = g_strdup(compose->replyto ? compose->replyto :
1377 msginfo->from ? msginfo->from : "");
1378 extract_address(from);
1380 cc_list = address_list_append(NULL, msginfo->to);
1381 cc_list = address_list_append(cc_list, compose->cc);
1383 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1384 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1385 if (compose->account)
1386 g_hash_table_insert(to_table, compose->account->address,
1387 GINT_TO_POINTER(1));
1389 /* remove address on To: and that of current account */
1390 for (cur = cc_list; cur != NULL; ) {
1391 GSList *next = cur->next;
1393 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1394 cc_list = g_slist_remove(cc_list, cur->data);
1396 g_hash_table_insert(to_table, cur->data, cur);
1400 g_hash_table_destroy(to_table);
1404 for (cur = cc_list; cur != NULL; cur = cur->next)
1405 compose_entry_append(compose, (gchar *)cur->data,
1407 slist_free_strings(cc_list);
1408 g_slist_free(cc_list);
1412 #define SET_ENTRY(entry, str) \
1415 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1418 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1420 g_return_if_fail(msginfo != NULL);
1422 SET_ENTRY(to_entry, msginfo->to);
1423 SET_ENTRY(subject_entry, msginfo->subject);
1424 SET_ENTRY(cc_entry, compose->cc);
1425 SET_ENTRY(bcc_entry, compose->bcc);
1426 SET_ENTRY(reply_entry, compose->replyto);
1429 GtkItemFactory *ifactory;
1430 GtkWidget *menuitem;
1432 ifactory = gtk_item_factory_from_widget(compose->menubar);
1433 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1434 gtk_check_menu_item_set_active
1435 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1437 if (compose->replyto) {
1438 GtkItemFactory *ifactory;
1439 GtkWidget *menuitem;
1441 ifactory = gtk_item_factory_from_widget(compose->menubar);
1442 menuitem = gtk_item_factory_get_item
1443 (ifactory, "/Message/Reply to");
1444 gtk_check_menu_item_set_active
1445 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1451 static void compose_insert_sig(Compose *compose)
1455 if (compose->account && compose->account->sig_path)
1456 sigfile = g_strdup(compose->account->sig_path);
1458 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1459 DEFAULT_SIGNATURE, NULL);
1462 if (!is_file_or_fifo_exist(sigfile)) {
1467 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1468 if (prefs_common.sig_sep) {
1469 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1470 prefs_common.sig_sep, -1);
1471 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1475 compose_insert_file(compose, sigfile);
1479 static void compose_insert_file(Compose *compose, const gchar *file)
1481 GtkSText *text = GTK_STEXT(compose->text);
1482 gchar buf[BUFFSIZE];
1485 g_return_if_fail(file != NULL);
1487 if ((fp = fopen(file, "r")) == NULL) {
1488 FILE_OP_ERROR(file, "fopen");
1492 gtk_stext_freeze(text);
1494 while (fgets(buf, sizeof(buf), fp) != NULL)
1495 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1497 gtk_stext_thaw(text);
1502 static void compose_attach_append(Compose *compose, const gchar *file,
1503 ContentType cnttype)
1506 gchar *text[N_ATTACH_COLS];
1510 if (!is_file_exist(file)) {
1511 g_warning(_("File %s doesn't exist\n"), file);
1514 if ((size = get_file_size(file)) < 0) {
1515 g_warning(_("Can't get file size of %s\n"), file);
1519 alertpanel_notice(_("File %s is empty\n"), file);
1523 if (!compose->use_attach) {
1524 GtkItemFactory *ifactory;
1525 GtkWidget *menuitem;
1527 ifactory = gtk_item_factory_from_widget(compose->menubar);
1528 menuitem = gtk_item_factory_get_item(ifactory,
1530 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1534 ainfo = g_new0(AttachInfo, 1);
1535 ainfo->file = g_strdup(file);
1537 if (cnttype == MIME_MESSAGE_RFC822) {
1538 ainfo->content_type = g_strdup("message/rfc822");
1539 ainfo->encoding = ENC_7BIT;
1540 ainfo->name = g_strdup_printf(_("Message: %s"),
1543 ainfo->content_type = procmime_get_mime_type(file);
1544 if (!ainfo->content_type)
1545 ainfo->content_type =
1546 g_strdup("application/octet-stream");
1547 ainfo->encoding = ENC_BASE64;
1548 ainfo->name = g_strdup(g_basename(file));
1552 text[COL_MIMETYPE] = ainfo->content_type;
1553 text[COL_SIZE] = to_human_readable(size);
1554 text[COL_NAME] = ainfo->name;
1556 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1557 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1559 if (cnttype != MIME_MESSAGE_RFC822)
1560 compose_changed_cb(NULL, compose);
1563 static void compose_wrap_line(Compose *compose)
1565 GtkSText *text = GTK_STEXT(compose->text);
1567 guint line_pos = 0, cur_pos = 0;
1568 gint line_len = 0, cur_len = 0;
1570 gchar cbuf[MB_CUR_MAX];
1572 gtk_stext_freeze(text);
1574 text_len = gtk_stext_get_length(text);
1576 for (; cur_pos < text_len; cur_pos++) {
1577 if (text->use_wchar)
1579 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
1581 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
1585 if (ch_len == 1 && *cbuf == '\n') {
1586 line_pos = cur_pos + 1;
1587 line_len = cur_len = 0;
1596 if (ch_len == 1 && isspace(*cbuf)) {
1597 line_pos = cur_pos + 1;
1598 line_len = cur_len + ch_len;
1601 if (cur_len + ch_len > prefs_common.linewrap_len &&
1605 if (text->use_wchar)
1606 tlen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
1608 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
1611 if (tlen == 1 && isspace(*cbuf)) {
1612 gtk_stext_set_point(text, line_pos);
1613 gtk_stext_backward_delete(text, 1);
1621 gtk_stext_set_point(text, line_pos);
1622 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1626 cur_len = cur_len - line_len + ch_len;
1632 line_pos = cur_pos + 1;
1633 line_len = cur_len + ch_len;
1638 gtk_stext_thaw(text);
1641 static void compose_set_title(Compose *compose)
1646 edited = compose->modified ? _(" [Edited]") : "";
1647 if (compose->account && compose->account->address)
1648 str = g_strdup_printf(_("%s - Compose message%s"),
1649 compose->account->address, edited);
1651 str = g_strdup_printf(_("Compose message%s"), edited);
1652 gtk_window_set_title(GTK_WINDOW(compose->window), str);
1657 * compose_current_mail_account:
1659 * Find a current mail account (the currently selected account, or the
1660 * default account, if a news account is currently selected). If a
1661 * mail account cannot be found, display an error message.
1663 * Return value: Mail account, or NULL if not found.
1665 static PrefsAccount *
1666 compose_current_mail_account(void)
1670 if (cur_account && cur_account->protocol != A_NNTP)
1673 ac = account_get_default();
1674 if (!ac || ac->protocol == A_NNTP) {
1675 alertpanel_error(_("Account for sending mail is not specified.\n"
1676 "Please select a mail account before sending."));
1683 gint compose_send(Compose *compose)
1685 gchar tmp[MAXPATHLEN + 1];
1686 gchar *to, *newsgroups;
1688 static gboolean lock = FALSE;
1692 g_return_val_if_fail(compose->account != NULL, -1);
1693 g_return_val_if_fail(compose->orig_account != NULL, -1);
1697 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
1698 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
1699 if (*to == '\0' && *newsgroups == '\0') {
1700 alertpanel_error(_("Recipient is not specified."));
1705 /* write to temporary file */
1706 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
1707 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
1709 if (prefs_common.linewrap_at_send)
1710 compose_wrap_line(compose);
1712 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
1717 if (!compose->to_list && !compose->newsgroup_list) {
1718 g_warning(_("can't get recipient list."));
1724 if (compose->to_list) {
1727 if (compose->account->protocol != A_NNTP)
1728 ac = compose->account;
1729 else if (compose->orig_account->protocol != A_NNTP)
1730 ac = compose->orig_account;
1732 ac = compose_current_mail_account();
1739 ok = send_message(tmp, ac, compose->to_list);
1740 statusbar_pop_all();
1743 if (ok == 0 && compose->newsgroup_list) {
1746 if (compose->account->protocol == A_NNTP)
1747 folder = FOLDER(compose->account->folder);
1749 folder = FOLDER(compose->orig_account->folder);
1751 ok = news_post(folder, tmp);
1753 alertpanel_error(_("Error occurred while posting the message to %s ."),
1754 compose->account->nntp_server);
1761 /* queue message if failed to send */
1763 if (prefs_common.queue_msg) {
1768 _("Error occurred while sending the message.\n"
1769 "Put this message into queue folder?"),
1770 _("OK"), _("Cancel"), NULL);
1771 if (G_ALERTDEFAULT == val) {
1772 ok = compose_queue(compose, tmp);
1774 alertpanel_error(_("Can't queue the message."));
1777 alertpanel_error(_("Error occurred while sending the message."));
1780 /* save message to outbox */
1781 if (ok == 0 && prefs_common.savemsg) {
1782 if (compose_save_to_outbox(compose, tmp) < 0)
1784 (_("Can't save the message to outbox."));
1792 static gint compose_write_to_file(Compose *compose, const gchar *file,
1799 const gchar *out_codeset;
1800 EncodingType encoding;
1802 if ((fp = fopen(file, "w")) == NULL) {
1803 FILE_OP_ERROR(file, "fopen");
1807 /* chmod for security */
1808 if (change_file_mode_rw(fp, file) < 0) {
1809 FILE_OP_ERROR(file, "chmod");
1810 g_warning(_("can't change file mode\n"));
1813 /* get all composed text */
1814 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
1815 len = strlen(chars);
1816 if (is_ascii_str(chars)) {
1817 buf = g_strdup(chars);
1818 out_codeset = "US-ASCII";
1819 encoding = ENC_7BIT;
1821 const gchar *src_codeset;
1823 out_codeset = conv_get_outgoing_charset_str();
1824 if (!strcasecmp(out_codeset, "US-ASCII"))
1825 out_codeset = "ISO-8859-1";
1826 encoding = procmime_get_encoding_for_charset(out_codeset);
1827 debug_print("charset = %s, encoding = %s\n",
1828 out_codeset, procmime_get_encoding_str(encoding));
1830 src_codeset = conv_get_current_charset_str();
1831 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
1836 alertpanel_error(_("Can't convert the codeset of the message."));
1843 if (compose_write_headers
1844 (compose, fp, out_codeset, encoding, is_draft) < 0) {
1845 g_warning(_("can't write headers\n"));
1852 if (compose->use_attach) {
1854 /* This prolog message is ignored by mime software and
1855 * because it would make our signing/encryption task
1856 * tougher, we don't emit it in that case */
1857 if (!compose->use_signing && !compose->use_encryption)
1859 fputs("This is a multi-part message in MIME format.\n", fp);
1861 fprintf(fp, "\n--%s\n", compose->boundary);
1862 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
1864 fprintf(fp, "Content-Transfer-Encoding: %s\n",
1865 procmime_get_encoding_str(encoding));
1871 if (encoding == ENC_BASE64) {
1872 gchar outbuf[B64_BUFFSIZE];
1875 for (i = 0; i < len; i += B64_LINE_SIZE) {
1876 l = MIN(B64_LINE_SIZE, len - i);
1877 to64frombits(outbuf, buf + i, l);
1881 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
1882 FILE_OP_ERROR(file, "fwrite");
1890 if (compose->use_attach)
1891 compose_write_attach(compose, fp);
1893 if (fclose(fp) == EOF) {
1894 FILE_OP_ERROR(file, "fclose");
1900 if (compose->use_signing) {
1901 if (rfc2015_sign(file, compose->account) < 0) {
1906 if (compose->use_encryption) {
1907 if (rfc2015_encrypt(file, compose->to_list) < 0) {
1912 #endif /* USE_GPGME */
1917 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
1923 if ((fp = fopen(file, "w")) == NULL) {
1924 FILE_OP_ERROR(file, "fopen");
1928 /* chmod for security */
1929 if (change_file_mode_rw(fp, file) < 0) {
1930 FILE_OP_ERROR(file, "chmod");
1931 g_warning(_("can't change file mode\n"));
1934 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
1937 len = strlen(chars);
1938 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
1939 FILE_OP_ERROR(file, "fwrite");
1948 if (fclose(fp) == EOF) {
1949 FILE_OP_ERROR(file, "fclose");
1956 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
1963 debug_print(_("saving sent message...\n"));
1965 outbox = folder_get_default_outbox();
1966 path = folder_item_get_path(outbox);
1967 if (!is_dir_exist(path))
1968 make_dir_hier(path);
1970 folder_item_scan(outbox);
1971 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
1973 g_warning(_("can't save message\n"));
1977 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
1978 g_warning(_("can't open mark file\n"));
1982 newmsginfo.msgnum = num;
1983 newmsginfo.flags = 0;
1984 procmsg_write_flags(&newmsginfo, fp);
1992 static gint compose_queue(Compose *compose, const gchar *file)
1995 gchar *tmp, *queue_path;
1998 gchar buf[BUFFSIZE];
2001 debug_print(_("queueing message...\n"));
2002 g_return_val_if_fail(compose->to_list != NULL, -1);
2003 g_return_val_if_fail(compose->account != NULL, -1);
2005 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
2006 G_DIR_SEPARATOR, (gint)compose);
2007 if ((fp = fopen(tmp, "w")) == NULL) {
2008 FILE_OP_ERROR(tmp, "fopen");
2012 if ((src_fp = fopen(file, "r")) == NULL) {
2013 FILE_OP_ERROR(file, "fopen");
2019 if (change_file_mode_rw(fp, tmp) < 0) {
2020 FILE_OP_ERROR(tmp, "chmod");
2021 g_warning(_("can't change file mode\n"));
2024 /* queueing variables */
2025 fprintf(fp, "AF:\n");
2026 fprintf(fp, "NF:0\n");
2027 fprintf(fp, "PS:10\n");
2028 fprintf(fp, "SRH:1\n");
2029 fprintf(fp, "SFN:\n");
2030 fprintf(fp, "DSR:\n");
2032 fprintf(fp, "MID:<%s>\n", compose->msgid);
2034 fprintf(fp, "MID:\n");
2035 fprintf(fp, "CFG:\n");
2036 fprintf(fp, "PT:0\n");
2037 fprintf(fp, "S:%s\n", compose->account->address);
2038 fprintf(fp, "RQ:\n");
2039 if (compose->account->smtp_server)
2040 fprintf(fp, "SSV:%s\n", compose->account->smtp_server);
2042 fprintf(fp, "SSV:\n");
2043 if (compose->account->nntp_server)
2044 fprintf(fp, "NSV:%s\n", compose->account->nntp_server);
2046 fprintf(fp, "NSV:\n");
2047 fprintf(fp, "SSH:\n");
2048 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
2049 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
2050 fprintf(fp, ",<%s>", (gchar *)cur->data);
2054 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
2055 if (fputs(buf, fp) == EOF) {
2056 FILE_OP_ERROR(tmp, "fputs");
2066 if (fclose(fp) == EOF) {
2067 FILE_OP_ERROR(tmp, "fclose");
2073 queue = folder_get_default_queue();
2074 folder_item_scan(queue);
2075 queue_path = folder_item_get_path(queue);
2076 if (!is_dir_exist(queue_path))
2077 make_dir_hier(queue_path);
2078 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
2079 g_warning(_("can't queue the message\n"));
2087 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
2088 g_warning(_("can't open mark file\n"));
2092 newmsginfo.msgnum = num;
2093 newmsginfo.flags = 0;
2094 procmsg_write_flags(&newmsginfo, fp);
2099 folder_item_scan(queue);
2100 folderview_update_item(queue, TRUE);
2105 static void compose_write_attach(Compose *compose, FILE *fp)
2108 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2111 gchar filename[BUFFSIZE];
2114 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
2116 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
2117 g_warning(_("Can't open file %s\n"), ainfo->file);
2121 fprintf(fp, "\n--%s\n", compose->boundary);
2123 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
2124 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
2125 fprintf(fp, "Content-Disposition: inline\n");
2127 conv_encode_header(filename, sizeof(filename),
2129 fprintf(fp, "Content-Type: %s;\n"
2131 ainfo->content_type, filename);
2132 fprintf(fp, "Content-Disposition: attachment;\n"
2133 " filename=\"%s\"\n", filename);
2136 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
2137 procmime_get_encoding_str(ainfo->encoding));
2139 if (ainfo->encoding == ENC_7BIT) {
2140 gchar buf[BUFFSIZE];
2142 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
2144 if (len > 1 && buf[len - 1] == '\n' &&
2145 buf[len - 2] == '\r') {
2146 buf[len - 2] = '\n';
2147 buf[len - 1] = '\0';
2152 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
2154 while ((len = fread(inbuf, sizeof(gchar),
2155 B64_LINE_SIZE, attach_fp))
2157 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
2161 if (len > 0 && feof(attach_fp)) {
2162 to64frombits(outbuf, inbuf, len);
2171 fprintf(fp, "\n--%s--\n", compose->boundary);
2174 #define IS_IN_CUSTOM_HEADER(header) \
2175 (compose->account->add_customhdr && \
2176 custom_header_find(compose->account->customhdr_list, header) != NULL)
2178 static gint compose_write_headers(Compose *compose, FILE *fp,
2179 const gchar *charset, EncodingType encoding,
2182 gchar buf[BUFFSIZE];
2184 /* struct utsname utsbuf; */
2186 g_return_val_if_fail(fp != NULL, -1);
2187 g_return_val_if_fail(charset != NULL, -1);
2188 g_return_val_if_fail(compose->account != NULL, -1);
2189 g_return_val_if_fail(compose->account->address != NULL, -1);
2192 if (compose->account->add_date) {
2193 get_rfc822_date(buf, sizeof(buf));
2194 fprintf(fp, "Date: %s\n", buf);
2198 if (!IS_IN_CUSTOM_HEADER("From")) {
2199 if (compose->account->name && *compose->account->name) {
2200 compose_convert_header
2201 (buf, sizeof(buf), compose->account->name,
2203 fprintf(fp, "From: %s <%s>\n",
2204 buf, compose->account->address);
2206 fprintf(fp, "From: %s\n", compose->account->address);
2209 slist_free_strings(compose->to_list);
2210 g_slist_free(compose->to_list);
2211 compose->to_list = NULL;
2214 if (compose->use_to) {
2215 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2217 Xstrdup_a(str, str, return -1);
2220 compose->to_list = address_list_append
2221 (compose->to_list, str);
2222 if (!IS_IN_CUSTOM_HEADER("To")) {
2223 compose_convert_header
2224 (buf, sizeof(buf), str,
2226 fprintf(fp, "To: %s\n", buf);
2232 slist_free_strings(compose->newsgroup_list);
2233 g_slist_free(compose->newsgroup_list);
2234 compose->newsgroup_list = NULL;
2237 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2239 Xstrdup_a(str, str, return -1);
2243 compose->newsgroup_list =
2244 newsgroup_list_append(compose->newsgroup_list,
2246 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
2247 compose_convert_header(buf, sizeof(buf), str,
2248 strlen("Newsgroups: "));
2249 fprintf(fp, "Newsgroups: %s\n", buf);
2254 if (!is_draft && !compose->to_list && !compose->newsgroup_list)
2258 if (compose->use_cc) {
2259 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
2261 Xstrdup_a(str, str, return -1);
2264 compose->to_list = address_list_append
2265 (compose->to_list, str);
2266 if (!IS_IN_CUSTOM_HEADER("Cc")) {
2267 compose_convert_header
2268 (buf, sizeof(buf), str,
2270 fprintf(fp, "Cc: %s\n", buf);
2277 if (compose->use_bcc) {
2278 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
2280 Xstrdup_a(str, str, return -1);
2283 compose->to_list = address_list_append
2284 (compose->to_list, str);
2286 compose_convert_header
2287 (buf, sizeof(buf), str,
2289 fprintf(fp, "Bcc: %s\n", buf);
2296 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2297 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
2298 Xstrdup_a(str, str, return -1);
2301 compose_convert_header(buf, sizeof(buf), str,
2302 strlen("Subject: "));
2303 fprintf(fp, "Subject: %s\n", buf);
2308 if (compose->account->gen_msgid) {
2309 compose_generate_msgid(compose, buf, sizeof(buf));
2310 fprintf(fp, "Message-Id: <%s>\n", buf);
2311 compose->msgid = g_strdup(buf);
2315 if (compose->inreplyto && compose->to_list)
2316 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
2319 if (compose->references)
2320 fprintf(fp, "References: %s\n", compose->references);
2323 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
2324 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
2326 Xstrdup_a(str, str, return -1);
2330 compose_convert_header(buf, sizeof(buf), str,
2331 strlen("Followup-To: "));
2332 fprintf(fp, "Followup-To: %s\n", buf);
2338 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
2339 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
2341 Xstrdup_a(str, str, return -1);
2344 compose_convert_header(buf, sizeof(buf), str,
2345 strlen("Reply-To: "));
2346 fprintf(fp, "Reply-To: %s\n", buf);
2352 if (compose->account->organization &&
2353 !IS_IN_CUSTOM_HEADER("Organization")) {
2354 compose_convert_header(buf, sizeof(buf),
2355 compose->account->organization,
2356 strlen("Organization: "));
2357 fprintf(fp, "Organization: %s\n", buf);
2360 /* Program version and system info */
2361 /* uname(&utsbuf); */
2362 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2363 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
2364 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
2366 gtk_major_version, gtk_minor_version, gtk_micro_version,
2368 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2370 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2371 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
2372 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
2374 gtk_major_version, gtk_minor_version, gtk_micro_version,
2376 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2379 /* custom headers */
2380 if (compose->account->add_customhdr) {
2383 for (cur = compose->account->customhdr_list; cur != NULL;
2385 CustomHeader *chdr = (CustomHeader *)cur->data;
2387 if (strcasecmp(chdr->name, "Date") != 0 &&
2388 strcasecmp(chdr->name, "From") != 0 &&
2389 strcasecmp(chdr->name, "To") != 0 &&
2390 strcasecmp(chdr->name, "Sender") != 0 &&
2391 strcasecmp(chdr->name, "Message-Id") != 0 &&
2392 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
2393 strcasecmp(chdr->name, "References") != 0 &&
2394 strcasecmp(chdr->name, "Mime-Version") != 0 &&
2395 strcasecmp(chdr->name, "Content-Type") != 0 &&
2396 strcasecmp(chdr->name, "Content-Transfer-Encoding")
2398 compose_convert_header
2400 chdr->value ? chdr->value : "",
2401 strlen(chdr->name) + 2);
2402 fprintf(fp, "%s: %s\n", chdr->name, buf);
2407 fprintf(fp, "Mime-Version: 1.0\n");
2408 if (compose->use_attach) {
2409 get_rfc822_date(buf, sizeof(buf));
2410 subst_char(buf, ' ', '_');
2411 subst_char(buf, ',', '_');
2412 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
2413 buf, (guint)compose);
2415 "Content-Type: multipart/mixed;\n"
2416 " boundary=\"%s\"\n", compose->boundary);
2418 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
2419 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2420 procmime_get_encoding_str(encoding));
2423 /* Request Return Receipt */
2424 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
2425 if (compose->return_receipt) {
2426 if (compose->account->name
2427 && *compose->account->name) {
2428 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
2429 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
2431 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
2435 /* separator between header and body */
2441 #undef IS_IN_CUSTOM_HEADER
2443 static void compose_convert_header(gchar *dest, gint len, gchar *src,
2446 g_return_if_fail(src != NULL);
2447 g_return_if_fail(dest != NULL);
2449 if (len < 1) return;
2453 if (is_ascii_str(src)) {
2454 strncpy2(dest, src, len);
2455 dest[len - 1] = '\0';
2458 conv_encode_header(dest, len, src, header_len);
2461 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
2470 if (compose->account && compose->account->address &&
2471 *compose->account->address) {
2472 if (strchr(compose->account->address, '@'))
2473 addr = g_strdup(compose->account->address);
2475 addr = g_strconcat(compose->account->address, "@",
2476 get_domain_name(), NULL);
2478 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
2481 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
2482 lt->tm_year + 1900, lt->tm_mon + 1,
2483 lt->tm_mday, lt->tm_hour,
2484 lt->tm_min, lt->tm_sec,
2485 (guint)random(), addr);
2487 debug_print(_("generated Message-ID: %s\n"), buf);
2492 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
2493 GtkWidget **entry, gint *count,
2494 const gchar *label_str,
2495 gboolean is_addr_entry)
2499 if (GTK_TABLE(table)->nrows < (*count) + 1)
2500 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
2502 *hbox = gtk_hbox_new(FALSE, 0);
2503 label = gtk_label_new
2504 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
2505 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
2506 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
2508 *entry = gtk_entry_new();
2509 gtk_table_attach_defaults
2510 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1);
2511 if (GTK_TABLE(table)->nrows > (*count) + 1)
2512 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
2515 address_completion_register_entry(GTK_ENTRY(*entry));
2520 static Compose *compose_create(PrefsAccount *account)
2526 GtkWidget *handlebox;
2530 GtkWidget *table_vbox;
2532 GtkWidget *from_optmenu_hbox;
2533 GtkWidget *to_entry;
2535 GtkWidget *newsgroups_entry;
2536 GtkWidget *newsgroups_hbox;
2537 GtkWidget *subject_entry;
2538 GtkWidget *cc_entry;
2540 GtkWidget *bcc_entry;
2541 GtkWidget *bcc_hbox;
2542 GtkWidget *reply_entry;
2543 GtkWidget *reply_hbox;
2544 GtkWidget *followup_entry;
2545 GtkWidget *followup_hbox;
2549 GtkWidget *attach_scrwin;
2550 GtkWidget *attach_clist;
2552 GtkWidget *edit_vbox;
2553 GtkWidget *ruler_hbox;
2555 GtkWidget *scrolledwin;
2561 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
2562 guint n_menu_entries;
2563 GtkStyle *style, *new_style;
2566 gboolean success[1];
2568 GtkWidget *popupmenu;
2569 GtkWidget *menuitem;
2570 GtkItemFactory *popupfactory;
2571 GtkItemFactory *ifactory;
2576 g_return_val_if_fail(account != NULL, NULL);
2578 debug_print(_("Creating compose window...\n"));
2579 compose = g_new0(Compose, 1);
2581 compose->account = account;
2582 compose->orig_account = account;
2584 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2585 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
2586 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
2587 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
2588 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
2589 gtk_signal_connect(GTK_OBJECT(window), "destroy",
2590 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
2591 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
2592 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
2593 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
2594 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
2595 gtk_widget_realize(window);
2597 vbox = gtk_vbox_new(FALSE, 0);
2598 gtk_container_add(GTK_CONTAINER(window), vbox);
2600 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
2601 menubar = menubar_create(window, compose_entries,
2602 n_menu_entries, "<Compose>", compose);
2603 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
2605 handlebox = gtk_handle_box_new();
2606 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
2608 compose_toolbar_create(compose, handlebox);
2610 vbox2 = gtk_vbox_new(FALSE, 2);
2611 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
2612 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
2614 table_vbox = gtk_vbox_new(FALSE, 0);
2615 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
2616 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
2619 table = gtk_table_new(8, 2, FALSE);
2620 gtk_box_pack_start(GTK_BOX(table_vbox), table, FALSE, TRUE, 0);
2622 /* option menu for selecting accounts */
2623 hbox = gtk_hbox_new(FALSE, 0);
2624 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
2625 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
2626 gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, count, count + 1,
2628 from_optmenu_hbox = compose_account_option_menu_create(compose);
2629 gtk_table_attach_defaults(GTK_TABLE(table), from_optmenu_hbox,
2630 1, 2, count, count + 1);
2631 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
2634 /* header labels and entries */
2635 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
2637 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
2638 &count, "Newsgroups:", FALSE);
2639 compose_add_entry_field(table, &hbox, &subject_entry, &count,
2641 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
2643 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
2645 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
2647 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
2648 "Followup-To:", FALSE);
2650 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
2652 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
2653 GTK_SIGNAL_FUNC(to_activated), compose);
2654 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
2655 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
2656 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
2657 GTK_SIGNAL_FUNC(subject_activated), compose);
2658 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
2659 GTK_SIGNAL_FUNC(cc_activated), compose);
2660 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
2661 GTK_SIGNAL_FUNC(bcc_activated), compose);
2662 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
2663 GTK_SIGNAL_FUNC(replyto_activated), compose);
2664 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
2665 GTK_SIGNAL_FUNC(followupto_activated), compose);
2667 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
2668 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2669 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
2670 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2671 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
2672 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2673 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
2674 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2675 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
2676 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2677 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
2678 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2679 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
2680 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2682 /* attachment list */
2683 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
2684 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
2685 GTK_POLICY_AUTOMATIC,
2687 gtk_widget_set_usize(attach_scrwin, -1, 80);
2689 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
2690 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
2692 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
2693 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
2694 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
2695 GTK_SELECTION_EXTENDED);
2696 for (i = 0; i < N_ATTACH_COLS; i++)
2697 GTK_WIDGET_UNSET_FLAGS
2698 (GTK_CLIST(attach_clist)->column[i].button,
2700 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
2702 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
2703 GTK_SIGNAL_FUNC(attach_selected), compose);
2704 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
2705 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
2706 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
2707 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
2710 gtk_drag_dest_set(attach_clist,
2711 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
2713 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
2714 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
2717 /* pane between attach clist and text */
2718 paned = gtk_vpaned_new();
2719 gtk_paned_add1(GTK_PANED(paned), attach_scrwin);
2720 gtk_widget_ref(paned);
2721 gtk_widget_show_all(paned);
2723 edit_vbox = gtk_vbox_new(FALSE, 0);
2724 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
2727 ruler_hbox = gtk_hbox_new(FALSE, 0);
2728 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
2730 ruler = gtk_shruler_new();
2731 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
2732 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
2734 gtk_widget_set_usize(ruler_hbox, 1, -1);
2737 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
2738 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
2739 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
2740 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
2741 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
2743 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
2744 (GTK_SCROLLED_WINDOW(scrolledwin)),
2745 gtk_scrolled_window_get_vadjustment
2746 (GTK_SCROLLED_WINDOW(scrolledwin)));
2747 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
2748 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
2749 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
2751 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
2753 gtk_signal_connect(GTK_OBJECT(text), "changed",
2754 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
2755 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
2756 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2757 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
2758 GTK_SIGNAL_FUNC(compose_button_press_cb),
2761 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
2762 GTK_SIGNAL_FUNC(compose_key_press_cb),
2765 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
2766 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
2770 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
2772 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
2773 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
2776 gtk_widget_show_all(vbox);
2778 style = gtk_widget_get_style(text);
2780 /* workaround for the slow down of GtkSText when using Pixmap theme */
2781 if (style->engine) {
2782 GtkThemeEngine *engine;
2784 engine = style->engine;
2785 style->engine = NULL;
2786 new_style = gtk_style_copy(style);
2787 style->engine = engine;
2789 new_style = gtk_style_copy(style);
2791 if (prefs_common.textfont) {
2794 charset = conv_get_current_charset();
2795 if (MB_CUR_MAX == 1) {
2798 Xstrdup_a(fontstr, prefs_common.textfont, );
2799 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
2801 font = gdk_font_load(fontstr);
2803 font = gdk_fontset_load(prefs_common.textfont);
2805 gdk_font_unref(new_style->font);
2806 new_style->font = font;
2810 gtk_widget_set_style(text, new_style);
2812 color[0] = quote_color;
2813 cmap = gdk_window_get_colormap(window->window);
2814 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
2815 if (success[0] == FALSE) {
2816 g_warning("Compose: color allocation failed.\n");
2817 style = gtk_widget_get_style(text);
2818 quote_color = style->black;
2821 n_entries = sizeof(compose_popup_entries) /
2822 sizeof(compose_popup_entries[0]);
2823 popupmenu = menu_create_items(compose_popup_entries, n_entries,
2824 "<Compose>", &popupfactory,
2827 ifactory = gtk_item_factory_from_widget(menubar);
2828 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
2829 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
2831 gtk_widget_hide(bcc_hbox);
2832 gtk_widget_hide(bcc_entry);
2833 gtk_widget_hide(reply_hbox);
2834 gtk_widget_hide(reply_entry);
2835 gtk_widget_hide(followup_hbox);
2836 gtk_widget_hide(followup_entry);
2837 gtk_widget_hide(ruler_hbox);
2838 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
2839 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
2840 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
2842 if (account->protocol == A_NNTP) {
2843 gtk_widget_hide(to_hbox);
2844 gtk_widget_hide(to_entry);
2845 gtk_widget_hide(cc_hbox);
2846 gtk_widget_hide(cc_entry);
2847 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
2848 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
2850 gtk_widget_hide(newsgroups_hbox);
2851 gtk_widget_hide(newsgroups_entry);
2852 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
2853 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
2856 switch (prefs_common.toolbar_style) {
2858 gtk_widget_hide(handlebox);
2861 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
2865 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
2869 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
2874 gtk_widget_show(window);
2876 address_completion_start(window);
2878 compose->window = window;
2879 compose->vbox = vbox;
2880 compose->menubar = menubar;
2881 compose->handlebox = handlebox;
2883 compose->vbox2 = vbox2;
2885 compose->table_vbox = table_vbox;
2886 compose->table = table;
2887 compose->to_hbox = to_hbox;
2888 compose->to_entry = to_entry;
2889 compose->newsgroups_hbox = newsgroups_hbox;
2890 compose->newsgroups_entry = newsgroups_entry;
2891 compose->subject_entry = subject_entry;
2892 compose->cc_hbox = cc_hbox;
2893 compose->cc_entry = cc_entry;
2894 compose->bcc_hbox = bcc_hbox;
2895 compose->bcc_entry = bcc_entry;
2896 compose->reply_hbox = reply_hbox;
2897 compose->reply_entry = reply_entry;
2898 compose->followup_hbox = followup_hbox;
2899 compose->followup_entry = followup_entry;
2901 compose->paned = paned;
2903 compose->attach_scrwin = attach_scrwin;
2904 compose->attach_clist = attach_clist;
2906 compose->edit_vbox = edit_vbox;
2907 compose->ruler_hbox = ruler_hbox;
2908 compose->ruler = ruler;
2909 compose->scrolledwin = scrolledwin;
2910 compose->text = text;
2912 compose->focused_editable = NULL;
2914 compose->popupmenu = popupmenu;
2915 compose->popupfactory = popupfactory;
2917 compose->mode = COMPOSE_NEW;
2919 compose->replyto = NULL;
2921 compose->bcc = NULL;
2922 compose->followup_to = NULL;
2923 compose->inreplyto = NULL;
2924 compose->references = NULL;
2925 compose->msgid = NULL;
2926 compose->boundary = NULL;
2928 compose->use_to = FALSE;
2929 compose->use_cc = FALSE;
2930 compose->use_bcc = FALSE;
2931 compose->use_replyto = FALSE;
2932 compose->use_followupto = FALSE;
2933 compose->use_attach = FALSE;
2936 compose->use_signing = FALSE;
2937 compose->use_encryption = FALSE;
2938 #endif /* USE_GPGME */
2940 compose->modified = FALSE;
2942 compose->return_receipt = FALSE;
2944 compose->to_list = NULL;
2945 compose->newsgroup_list = NULL;
2947 compose->exteditor_file = NULL;
2948 compose->exteditor_pid = -1;
2949 compose->exteditor_readdes = -1;
2950 compose->exteditor_tag = -1;
2952 compose_set_title(compose);
2954 if (account->protocol != A_NNTP) {
2955 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
2956 gtk_check_menu_item_set_active
2957 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2958 gtk_widget_set_sensitive(menuitem, FALSE);
2959 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
2960 gtk_check_menu_item_set_active
2961 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2962 gtk_widget_set_sensitive(menuitem, FALSE);
2964 if (account->set_autocc && account->auto_cc) {
2965 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
2966 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
2967 gtk_check_menu_item_set_active
2968 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2970 if (account->set_autobcc) {
2971 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
2972 gtk_check_menu_item_set_active
2973 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2974 if (account->auto_bcc)
2975 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
2978 if (account->set_autoreplyto) {
2979 menuitem = gtk_item_factory_get_item(ifactory,
2980 "/Message/Reply to");
2981 gtk_check_menu_item_set_active
2982 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2983 if (account->auto_replyto)
2984 gtk_entry_set_text(GTK_ENTRY(reply_entry),
2985 account->auto_replyto);
2988 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
2989 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2990 prefs_common.show_ruler);
2993 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
2994 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2995 prefs_common.default_sign);
2996 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
2997 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2998 prefs_common.default_encrypt);
2999 #endif /* USE_GPGME */
3001 addressbook_set_target_compose(compose);
3003 compose_list = g_list_append(compose_list, compose);
3008 #include "pixmaps/stock_mail_send.xpm"
3009 #include "pixmaps/stock_mail.xpm"
3010 #include "pixmaps/stock_paste.xpm"
3011 #include "pixmaps/stock_mail_attach.xpm"
3012 #include "pixmaps/stock_mail_compose.xpm"
3013 #include "pixmaps/linewrap.xpm"
3014 //#include "pixmaps/tb_mail_queue_send.xpm"
3015 #include "pixmaps/tb_address_book.xpm"
3017 #define CREATE_TOOLBAR_ICON(xpm_d) \
3019 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
3020 &container->style->white, \
3022 icon_wid = gtk_pixmap_new(icon, mask); \
3025 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
3030 GtkWidget *icon_wid;
3031 GtkWidget *send_btn;
3032 GtkWidget *sendl_btn;
3033 GtkWidget *draft_btn;
3034 GtkWidget *insert_btn;
3035 GtkWidget *attach_btn;
3037 GtkWidget *exteditor_btn;
3038 GtkWidget *linewrap_btn;
3039 GtkWidget *addrbook_btn;
3041 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
3043 gtk_container_add(GTK_CONTAINER(container), toolbar);
3044 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
3045 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
3046 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
3047 GTK_TOOLBAR_SPACE_LINE);
3049 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
3050 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3054 icon_wid, toolbar_send_cb, compose);
3056 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
3057 //CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm);
3058 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3060 _("Put into queue folder and send later"),
3062 icon_wid, toolbar_send_later_cb,
3065 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3066 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3068 _("Save to draft folder"),
3070 icon_wid, toolbar_draft_cb,
3073 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3075 CREATE_TOOLBAR_ICON(stock_paste_xpm);
3076 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3080 icon_wid, toolbar_insert_cb,
3083 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
3084 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3088 icon_wid, toolbar_attach_cb,
3091 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3093 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3094 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3096 _("Insert signature"),
3098 icon_wid, toolbar_sig_cb, compose);
3100 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3102 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
3103 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3105 _("Edit with external editor"),
3108 toolbar_ext_editor_cb,
3111 CREATE_TOOLBAR_ICON(linewrap_xpm);
3112 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3114 _("Wrap long lines"),
3117 toolbar_linewrap_cb,
3120 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3122 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
3123 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3127 icon_wid, toolbar_address_cb,
3130 compose->toolbar = toolbar;
3131 compose->send_btn = send_btn;
3132 compose->sendl_btn = sendl_btn;
3133 compose->draft_btn = draft_btn;
3134 compose->insert_btn = insert_btn;
3135 compose->attach_btn = attach_btn;
3136 compose->sig_btn = sig_btn;
3137 compose->exteditor_btn = exteditor_btn;
3138 compose->linewrap_btn = linewrap_btn;
3139 compose->addrbook_btn = addrbook_btn;
3141 gtk_widget_show_all(toolbar);
3144 #undef CREATE_TOOLBAR_ICON
3146 static GtkWidget *compose_account_option_menu_create(Compose *compose)
3152 gint num = 0, def_menu = 0;
3154 accounts = account_get_list();
3155 g_return_val_if_fail(accounts != NULL, NULL);
3157 hbox = gtk_hbox_new(FALSE, 0);
3158 optmenu = gtk_option_menu_new();
3159 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3160 menu = gtk_menu_new();
3162 for (; accounts != NULL; accounts = accounts->next, num++) {
3163 PrefsAccount *ac = (PrefsAccount *)accounts->data;
3164 GtkWidget *menuitem;
3167 if (ac == compose->account) def_menu = num;
3169 name = g_strdup_printf("%s <%s> (%s)",
3170 ac->name, ac->address, ac->account_name);
3171 MENUITEM_ADD(menu, menuitem, name, ac);
3173 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
3174 GTK_SIGNAL_FUNC(account_activated),
3178 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
3179 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
3184 static void compose_destroy(Compose *compose)
3187 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3190 /* NOTE: address_completion_end() does nothing with the window
3191 * however this may change. */
3192 address_completion_end(compose->window);
3194 slist_free_strings(compose->to_list);
3195 g_slist_free(compose->to_list);
3196 slist_free_strings(compose->newsgroup_list);
3197 g_slist_free(compose->newsgroup_list);
3199 procmsg_msginfo_free(compose->targetinfo);
3201 g_free(compose->replyto);
3202 g_free(compose->cc);
3203 g_free(compose->bcc);
3204 g_free(compose->newsgroups);
3205 g_free(compose->followup_to);
3207 g_free(compose->inreplyto);
3208 g_free(compose->references);
3209 g_free(compose->msgid);
3210 g_free(compose->boundary);
3212 g_free(compose->exteditor_file);
3214 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3216 compose_attach_info_free(ainfo);
3218 if (addressbook_get_target_compose() == compose)
3219 addressbook_set_target_compose(NULL);
3221 prefs_common.compose_width = compose->scrolledwin->allocation.width;
3222 prefs_common.compose_height = compose->window->allocation.height;
3224 gtk_widget_destroy(compose->paned);
3228 compose_list = g_list_remove(compose_list, compose);
3231 static void compose_attach_info_free(AttachInfo *ainfo)
3233 g_free(ainfo->file);
3234 g_free(ainfo->content_type);
3235 g_free(ainfo->name);
3239 static void compose_attach_remove_selected(Compose *compose)
3241 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3245 while (clist->selection != NULL) {
3246 row = GPOINTER_TO_INT(clist->selection->data);
3247 ainfo = gtk_clist_get_row_data(clist, row);
3248 compose_attach_info_free(ainfo);
3249 gtk_clist_remove(clist, row);
3253 static struct _AttachProperty
3256 GtkWidget *mimetype_entry;
3257 GtkWidget *encoding_optmenu;
3258 GtkWidget *path_entry;
3259 GtkWidget *filename_entry;
3261 GtkWidget *cancel_btn;
3264 static void compose_attach_property(Compose *compose)
3266 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3270 GtkOptionMenu *optmenu;
3272 if (!clist->selection) return;
3273 row = GPOINTER_TO_INT(clist->selection->data);
3275 ainfo = gtk_clist_get_row_data(clist, row);
3278 if (!attach_prop.window)
3279 compose_attach_property_create(&cancelled);
3280 gtk_widget_grab_focus(attach_prop.ok_btn);
3281 gtk_widget_show(attach_prop.window);
3282 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
3284 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
3285 if (ainfo->encoding == ENC_UNKNOWN)
3286 gtk_option_menu_set_history(optmenu, ENC_BASE64);
3288 gtk_option_menu_set_history(optmenu, ainfo->encoding);
3290 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
3291 ainfo->content_type ? ainfo->content_type : "");
3292 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
3293 ainfo->file ? ainfo->file : "");
3294 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
3295 ainfo->name ? ainfo->name : "");
3299 gchar *cnttype = NULL;
3303 GtkWidget *menuitem;
3307 if (cancelled == TRUE) {
3308 gtk_widget_hide(attach_prop.window);
3312 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
3313 if (*text != '\0') {
3316 text = g_strstrip(g_strdup(text));
3317 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
3318 cnttype = g_strdup(text);
3321 alertpanel_error(_("Invalid MIME type."));
3327 menu = gtk_option_menu_get_menu(optmenu);
3328 menuitem = gtk_menu_get_active(GTK_MENU(menu));
3329 ainfo->encoding = GPOINTER_TO_INT
3330 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
3332 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
3333 if (*text != '\0') {
3334 if (is_file_exist(text) &&
3335 (size = get_file_size(text)) > 0)
3336 file = g_strdup(text);
3339 (_("File doesn't exist or is empty."));
3345 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
3346 if (*text != '\0') {
3347 g_free(ainfo->name);
3348 ainfo->name = g_strdup(text);
3352 g_free(ainfo->content_type);
3353 ainfo->content_type = cnttype;
3356 g_free(ainfo->file);
3362 gtk_clist_set_text(clist, row, COL_MIMETYPE,
3363 ainfo->content_type);
3364 gtk_clist_set_text(clist, row, COL_SIZE,
3365 to_human_readable(ainfo->size));
3366 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
3368 gtk_widget_hide(attach_prop.window);
3373 #define SET_LABEL_AND_ENTRY(str, entry, top) \
3375 label = gtk_label_new(str); \
3376 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
3377 GTK_FILL, 0, 0, 0); \
3378 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
3380 entry = gtk_entry_new(); \
3381 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
3382 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
3385 static void compose_attach_property_create(gboolean *cancelled)
3391 GtkWidget *mimetype_entry;
3394 GtkWidget *optmenu_menu;
3395 GtkWidget *menuitem;
3396 GtkWidget *path_entry;
3397 GtkWidget *filename_entry;
3400 GtkWidget *cancel_btn;
3402 debug_print("Creating attach_property window...\n");
3404 window = gtk_window_new(GTK_WINDOW_DIALOG);
3405 gtk_widget_set_usize(window, 480, -1);
3406 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
3407 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
3408 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
3409 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
3410 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3411 GTK_SIGNAL_FUNC(attach_property_delete_event),
3413 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
3414 GTK_SIGNAL_FUNC(attach_property_key_pressed),
3417 vbox = gtk_vbox_new(FALSE, 8);
3418 gtk_container_add(GTK_CONTAINER(window), vbox);
3420 table = gtk_table_new(4, 2, FALSE);
3421 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
3422 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
3423 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
3425 SET_LABEL_AND_ENTRY(_("MIME type"), mimetype_entry, 0);
3427 label = gtk_label_new(_("Encoding"));
3428 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
3430 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3432 hbox = gtk_hbox_new(FALSE, 0);
3433 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
3434 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3436 optmenu = gtk_option_menu_new();
3437 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3439 optmenu_menu = gtk_menu_new();
3440 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
3441 gtk_widget_set_sensitive(menuitem, FALSE);
3442 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
3443 gtk_widget_set_sensitive(menuitem, FALSE);
3444 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
3445 gtk_widget_set_sensitive(menuitem, FALSE);
3446 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
3448 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
3450 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
3451 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
3453 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
3454 &cancel_btn, _("Cancel"), NULL, NULL);
3455 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
3456 gtk_widget_grab_default(ok_btn);
3458 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
3459 GTK_SIGNAL_FUNC(attach_property_ok),
3461 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
3462 GTK_SIGNAL_FUNC(attach_property_cancel),
3465 gtk_widget_show_all(vbox);
3467 attach_prop.window = window;
3468 attach_prop.mimetype_entry = mimetype_entry;
3469 attach_prop.encoding_optmenu = optmenu;
3470 attach_prop.path_entry = path_entry;
3471 attach_prop.filename_entry = filename_entry;
3472 attach_prop.ok_btn = ok_btn;
3473 attach_prop.cancel_btn = cancel_btn;
3476 #undef SET_LABEL_AND_ENTRY
3478 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
3484 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
3490 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
3491 gboolean *cancelled)
3499 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
3500 gboolean *cancelled)
3502 if (event && event->keyval == GDK_Escape) {
3508 static void compose_exec_ext_editor(Compose *compose)
3514 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
3515 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3517 if (pipe(pipe_fds) < 0) {
3522 if ((pid = fork()) < 0) {
3528 /* close the write side of the pipe */
3531 compose->exteditor_file = g_strdup(tmp);
3532 compose->exteditor_pid = pid;
3533 compose->exteditor_readdes = pipe_fds[0];
3535 compose_set_ext_editor_sensitive(compose, FALSE);
3537 compose->exteditor_tag =
3538 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
3539 compose_input_cb, compose);
3540 } else { /* process-monitoring process */
3546 /* close the read side of the pipe */
3549 if (compose_write_body_to_file(compose, tmp) < 0) {
3550 fd_write(pipe_fds[1], "2\n", 2);
3554 pid_ed = compose_exec_ext_editor_real(tmp);
3556 fd_write(pipe_fds[1], "1\n", 2);
3560 /* wait until editor is terminated */
3561 waitpid(pid_ed, NULL, 0);
3563 fd_write(pipe_fds[1], "0\n", 2);
3570 static gint compose_exec_ext_editor_real(const gchar *file)
3572 static gchar *def_cmd = "emacs %s";
3578 g_return_val_if_fail(file != NULL, -1);
3580 if ((pid = fork()) < 0) {
3585 if (pid != 0) return pid;
3587 /* grandchild process */
3589 if (setpgid(0, getppid()))
3592 if (prefs_common.ext_editor_cmd &&
3593 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
3594 *(p + 1) == 's' && !strchr(p + 2, '%')) {
3595 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
3597 if (prefs_common.ext_editor_cmd)
3598 g_warning(_("External editor command line is invalid: `%s'\n"),
3599 prefs_common.ext_editor_cmd);
3600 g_snprintf(buf, sizeof(buf), def_cmd, file);
3603 cmdline = g_strsplit(buf, " ", 1024);
3604 execvp(cmdline[0], cmdline);
3607 g_strfreev(cmdline);
3612 static gboolean compose_ext_editor_kill(Compose *compose)
3614 pid_t pgid = compose->exteditor_pid * -1;
3617 ret = kill(pgid, 0);
3619 if (ret == 0 || (ret == -1 && EPERM == errno)) {
3623 msg = g_strdup_printf
3624 (_("The external editor is still working.\n"
3625 "Force terminating the process?\n"
3626 "process group id: %d"), -pgid);
3627 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
3630 if (val == G_ALERTDEFAULT) {
3631 gdk_input_remove(compose->exteditor_tag);
3632 close(compose->exteditor_readdes);
3634 if (kill(pgid, SIGTERM) < 0) perror("kill");
3635 waitpid(compose->exteditor_pid, NULL, 0);
3637 g_warning(_("Terminated process group id: %d"), -pgid);
3638 g_warning(_("Temporary file: %s"),
3639 compose->exteditor_file);
3641 compose_set_ext_editor_sensitive(compose, TRUE);
3643 g_free(compose->exteditor_file);
3644 compose->exteditor_file = NULL;
3645 compose->exteditor_pid = -1;
3646 compose->exteditor_readdes = -1;
3647 compose->exteditor_tag = -1;
3655 static void compose_input_cb(gpointer data, gint source,
3656 GdkInputCondition condition)
3659 Compose *compose = (Compose *)data;
3662 debug_print(_("Compose: input from monitoring process\n"));
3664 gdk_input_remove(compose->exteditor_tag);
3667 if (read(source, &buf[i], 1) < 1) {
3671 if (buf[i] == '\n') {
3676 if (i == sizeof(buf) - 1)
3680 waitpid(compose->exteditor_pid, NULL, 0);
3682 if (buf[0] == '0') { /* success */
3683 GtkSText *text = GTK_STEXT(compose->text);
3685 gtk_stext_freeze(text);
3686 gtk_stext_set_point(text, 0);
3687 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
3688 compose_insert_file(compose, compose->exteditor_file);
3689 compose_changed_cb(NULL, compose);
3690 gtk_stext_thaw(text);
3692 if (unlink(compose->exteditor_file) < 0)
3693 FILE_OP_ERROR(compose->exteditor_file, "unlink");
3694 } else if (buf[0] == '1') { /* failed */
3695 g_warning(_("Couldn't exec external editor\n"));
3696 if (unlink(compose->exteditor_file) < 0)
3697 FILE_OP_ERROR(compose->exteditor_file, "unlink");
3698 } else if (buf[0] == '2') {
3699 g_warning(_("Couldn't write to file\n"));
3700 } else if (buf[0] == '3') {
3701 g_warning(_("Pipe read failed\n"));
3706 compose_set_ext_editor_sensitive(compose, TRUE);
3708 g_free(compose->exteditor_file);
3709 compose->exteditor_file = NULL;
3710 compose->exteditor_pid = -1;
3711 compose->exteditor_readdes = -1;
3712 compose->exteditor_tag = -1;
3715 static void compose_set_ext_editor_sensitive(Compose *compose,
3718 GtkItemFactory *ifactory;
3720 ifactory = gtk_item_factory_from_widget(compose->menubar);
3722 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
3723 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
3724 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
3726 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
3727 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
3728 menu_set_sensitive(ifactory, "/Edit/Wrap long lines", sensitive);
3729 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
3732 gtk_widget_set_sensitive(compose->text, sensitive);
3733 gtk_widget_set_sensitive(compose->send_btn, sensitive);
3734 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
3735 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
3736 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
3737 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
3738 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
3739 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
3742 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
3746 cursor_pos = (text->cursor_pos_x - extra) / char_width;
3747 cursor_pos = MAX(cursor_pos, 0);
3752 /* callback functions */
3754 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
3755 * includes "non-client" (windows-izm) in calculation, so this calculation
3756 * may not be accurate.
3758 static gboolean compose_edit_size_alloc(GtkEditable *widget,
3759 GtkAllocation *allocation,
3760 GtkSHRuler *shruler)
3762 if (prefs_common.show_ruler) {
3764 gint line_width_in_chars;
3766 char_width = gtkut_get_font_width
3767 (GTK_WIDGET(widget)->style->font);
3768 line_width_in_chars =
3769 (allocation->width - allocation->x) / char_width;
3771 /* got the maximum */
3772 gtk_ruler_set_range(GTK_RULER(shruler),
3773 0.0, line_width_in_chars,
3774 calc_cursor_xpos(GTK_STEXT(widget),
3777 /*line_width_in_chars*/ char_width);
3783 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
3785 compose_send_cb(data, 0, NULL);
3788 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
3790 compose_send_later_cb(data, 0, NULL);
3793 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
3795 compose_draft_cb(data, 0, NULL);
3798 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
3800 compose_insert_file_cb(data, 0, NULL);
3803 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
3805 compose_attach_cb(data, 0, NULL);
3808 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
3810 Compose *compose = (Compose *)data;
3812 compose_insert_sig(compose);
3815 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
3817 Compose *compose = (Compose *)data;
3819 compose_exec_ext_editor(compose);
3822 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
3824 Compose *compose = (Compose *)data;
3826 compose_wrap_line(compose);
3829 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
3831 compose_address_cb(data, 0, NULL);
3834 static void account_activated(GtkMenuItem *menuitem, gpointer data)
3836 Compose *compose = (Compose *)data;
3840 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
3841 g_return_if_fail(ac != NULL);
3843 if (ac != compose->account) {
3844 compose->account = ac;
3845 compose_set_title(compose);
3849 static void attach_selected(GtkCList *clist, gint row, gint column,
3850 GdkEvent *event, gpointer data)
3852 Compose *compose = (Compose *)data;
3854 if (event && event->type == GDK_2BUTTON_PRESS)
3855 compose_attach_property(compose);
3858 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
3861 Compose *compose = (Compose *)data;
3862 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3867 if (event->button == 3) {
3868 if ((clist->selection && !clist->selection->next) ||
3869 !clist->selection) {
3870 gtk_clist_unselect_all(clist);
3871 if (gtk_clist_get_selection_info(clist,
3874 gtk_clist_select_row(clist, row, column);
3875 gtkut_clist_set_focus_row(clist, row);
3878 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
3879 NULL, NULL, event->button, event->time);
3883 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
3886 Compose *compose = (Compose *)data;
3890 switch (event->keyval) {
3892 compose_attach_remove_selected(compose);
3897 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
3899 Compose *compose = (Compose *)data;
3902 val = compose_send(compose);
3904 if (val == 0) gtk_widget_destroy(compose->window);
3907 static void compose_send_later_cb(gpointer data, guint action,
3910 Compose *compose = (Compose *)data;
3912 gchar *to, *newsgroups;
3914 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3915 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3916 if (*to == '\0' && *newsgroups == '\0') {
3917 alertpanel_error(_("Recipient is not specified."));
3921 g_snprintf(tmp, 22, "%s%ctmpmsg%d",
3922 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3924 if (prefs_common.linewrap_at_send)
3925 compose_wrap_line(compose);
3927 if (compose_write_to_file(compose, tmp, FALSE) < 0 ||
3928 compose_queue(compose, tmp) < 0) {
3929 alertpanel_error(_("Can't queue the message."));
3933 if (prefs_common.savemsg) {
3934 if (compose_save_to_outbox(compose, tmp) < 0)
3936 (_("Can't save the message to outbox."));
3939 if (unlink(tmp) < 0)
3940 FILE_OP_ERROR(tmp, "unlink");
3942 gtk_widget_destroy(compose->window);
3945 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
3947 Compose *compose = (Compose *)data;
3951 draft = folder_get_default_draft();
3952 folder_item_scan(draft);
3954 if (procmsg_msg_exist(compose->targetinfo) &&
3955 compose->targetinfo->folder == draft) {
3956 if (folder_item_remove_msg(draft,
3957 compose->targetinfo->msgnum) < 0)
3958 g_warning(_("can't remove the old draft message\n"));
3960 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
3961 G_DIR_SEPARATOR, (gint)compose);
3963 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
3968 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
3976 //folderview_scan_folder_a(DRAFT_DIR, TRUE);
3978 gtk_widget_destroy(compose->window);
3981 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
3983 Compose *compose = (Compose *)data;
3986 file = filesel_select_file(_("Select file"), NULL);
3989 compose_attach_append(compose, file, MIME_UNKNOWN);
3992 static void compose_insert_file_cb(gpointer data, guint action,
3995 Compose *compose = (Compose *)data;
3998 file = filesel_select_file(_("Select file"), NULL);
4001 compose_insert_file(compose, file);
4004 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
4007 compose_close_cb(data, 0, NULL);
4011 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
4013 Compose *compose = (Compose *)data;
4016 if (compose->exteditor_tag != -1) {
4017 if (!compose_ext_editor_kill(compose))
4021 if (compose->modified) {
4022 val = alertpanel(_("Discard message"),
4023 _("This message has been modified. discard it?"),
4024 _("Discard"), _("to Draft"), _("Cancel"));
4027 case G_ALERTDEFAULT:
4029 case G_ALERTALTERNATE:
4030 compose_draft_cb(data, 0, NULL);
4037 gtk_widget_destroy(compose->window);
4040 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
4042 Compose *compose = (Compose *)data;
4044 addressbook_open(compose);
4047 static void compose_ext_editor_cb(gpointer data, guint action,
4050 Compose *compose = (Compose *)data;
4052 compose_exec_ext_editor(compose);
4055 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
4057 compose_destroy(compose);
4060 static void compose_cut_cb(Compose *compose)
4062 if (compose->focused_editable &&
4063 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4064 gtk_editable_cut_clipboard
4065 (GTK_EDITABLE(compose->focused_editable));
4068 static void compose_copy_cb(Compose *compose)
4070 if (compose->focused_editable &&
4071 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4072 gtk_editable_copy_clipboard
4073 (GTK_EDITABLE(compose->focused_editable));
4076 static void compose_paste_cb(Compose *compose)
4078 if (compose->focused_editable &&
4079 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4080 gtk_editable_paste_clipboard
4081 (GTK_EDITABLE(compose->focused_editable));
4084 static void compose_allsel_cb(Compose *compose)
4086 if (compose->focused_editable &&
4087 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4088 gtk_editable_select_region
4089 (GTK_EDITABLE(compose->focused_editable), 0, -1);
4092 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
4094 if (GTK_IS_EDITABLE(widget))
4095 compose->focused_editable = widget;
4098 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
4100 if (compose->modified == FALSE) {
4101 compose->modified = TRUE;
4102 compose_set_title(compose);
4106 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
4109 gtk_stext_set_point(GTK_STEXT(widget),
4110 gtk_editable_get_position(GTK_EDITABLE(widget)));
4114 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
4117 gtk_stext_set_point(GTK_STEXT(widget),
4118 gtk_editable_get_position(GTK_EDITABLE(widget)));
4122 static void compose_toggle_to_cb(gpointer data, guint action,
4125 Compose *compose = (Compose *)data;
4127 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4128 gtk_widget_show(compose->to_hbox);
4129 gtk_widget_show(compose->to_entry);
4130 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
4131 compose->use_to = TRUE;
4133 gtk_widget_hide(compose->to_hbox);
4134 gtk_widget_hide(compose->to_entry);
4135 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
4136 gtk_widget_queue_resize(compose->table_vbox);
4137 compose->use_to = FALSE;
4140 if (addressbook_get_target_compose() == compose)
4141 addressbook_set_target_compose(compose);
4144 static void compose_toggle_cc_cb(gpointer data, guint action,
4147 Compose *compose = (Compose *)data;
4149 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4150 gtk_widget_show(compose->cc_hbox);
4151 gtk_widget_show(compose->cc_entry);
4152 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
4153 compose->use_cc = TRUE;
4155 gtk_widget_hide(compose->cc_hbox);
4156 gtk_widget_hide(compose->cc_entry);
4157 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
4158 gtk_widget_queue_resize(compose->table_vbox);
4159 compose->use_cc = FALSE;
4162 if (addressbook_get_target_compose() == compose)
4163 addressbook_set_target_compose(compose);
4166 static void compose_toggle_bcc_cb(gpointer data, guint action,
4169 Compose *compose = (Compose *)data;
4171 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4172 gtk_widget_show(compose->bcc_hbox);
4173 gtk_widget_show(compose->bcc_entry);
4174 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
4175 compose->use_bcc = TRUE;
4177 gtk_widget_hide(compose->bcc_hbox);
4178 gtk_widget_hide(compose->bcc_entry);
4179 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
4180 gtk_widget_queue_resize(compose->table_vbox);
4181 compose->use_bcc = FALSE;
4184 if (addressbook_get_target_compose() == compose)
4185 addressbook_set_target_compose(compose);
4188 static void compose_toggle_replyto_cb(gpointer data, guint action,
4191 Compose *compose = (Compose *)data;
4193 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4194 gtk_widget_show(compose->reply_hbox);
4195 gtk_widget_show(compose->reply_entry);
4196 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
4197 compose->use_replyto = TRUE;
4199 gtk_widget_hide(compose->reply_hbox);
4200 gtk_widget_hide(compose->reply_entry);
4201 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
4202 gtk_widget_queue_resize(compose->table_vbox);
4203 compose->use_replyto = FALSE;
4207 static void compose_toggle_followupto_cb(gpointer data, guint action,
4210 Compose *compose = (Compose *)data;
4212 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4213 gtk_widget_show(compose->followup_hbox);
4214 gtk_widget_show(compose->followup_entry);
4215 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
4216 compose->use_followupto = TRUE;
4218 gtk_widget_hide(compose->followup_hbox);
4219 gtk_widget_hide(compose->followup_entry);
4220 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
4221 gtk_widget_queue_resize(compose->table_vbox);
4222 compose->use_followupto = FALSE;
4226 static void compose_toggle_attach_cb(gpointer data, guint action,
4229 Compose *compose = (Compose *)data;
4231 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4232 gtk_widget_ref(compose->edit_vbox);
4234 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4235 compose->edit_vbox);
4236 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
4237 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
4239 gtk_widget_show(compose->paned);
4241 gtk_widget_unref(compose->edit_vbox);
4242 gtk_widget_unref(compose->paned);
4244 compose->use_attach = TRUE;
4246 gtk_widget_ref(compose->paned);
4247 gtk_widget_ref(compose->edit_vbox);
4249 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4251 gtk_container_remove(GTK_CONTAINER(compose->paned),
4252 compose->edit_vbox);
4253 gtk_box_pack_start(GTK_BOX(compose->vbox2),
4254 compose->edit_vbox, TRUE, TRUE, 0);
4256 gtk_widget_unref(compose->edit_vbox);
4258 compose->use_attach = FALSE;
4263 static void compose_toggle_sign_cb(gpointer data, guint action,
4266 Compose *compose = (Compose *)data;
4268 if (GTK_CHECK_MENU_ITEM(widget)->active)
4269 compose->use_signing = TRUE;
4271 compose->use_signing = FALSE;
4274 static void compose_toggle_encrypt_cb(gpointer data, guint action,
4277 Compose *compose = (Compose *)data;
4279 if (GTK_CHECK_MENU_ITEM(widget)->active)
4280 compose->use_encryption = TRUE;
4282 compose->use_encryption = FALSE;
4284 #endif /* USE_GPGME */
4286 static void compose_toggle_ruler_cb(gpointer data, guint action,
4289 Compose *compose = (Compose *)data;
4291 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4292 gtk_widget_show(compose->ruler_hbox);
4293 prefs_common.show_ruler = TRUE;
4295 gtk_widget_hide(compose->ruler_hbox);
4296 gtk_widget_queue_resize(compose->edit_vbox);
4297 prefs_common.show_ruler = FALSE;
4301 static void compose_attach_drag_received_cb (GtkWidget *widget,
4302 GdkDragContext *drag_context,
4305 GtkSelectionData *data,
4310 Compose *compose = (Compose *)user_data;
4313 list = uri_list_extract_filenames((const gchar *)data->data);
4314 for (tmp = list; tmp != NULL; tmp = tmp->next)
4315 compose_attach_append(compose, (const gchar *)tmp->data,
4317 list_free_strings(list);
4321 static void compose_insert_drag_received_cb (GtkWidget *widget,
4322 GdkDragContext *drag_context,
4325 GtkSelectionData *data,
4330 Compose *compose = (Compose *)user_data;
4333 list = uri_list_extract_filenames((const gchar *)data->data);
4334 for (tmp = list; tmp != NULL; tmp = tmp->next)
4335 compose_insert_file(compose, (const gchar *)tmp->data);
4336 list_free_strings(list);
4340 static void to_activated(GtkWidget *widget, Compose *compose)
4342 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
4343 gtk_widget_grab_focus(compose->newsgroups_entry);
4345 gtk_widget_grab_focus(compose->subject_entry);
4348 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
4350 gtk_widget_grab_focus(compose->subject_entry);
4353 static void subject_activated(GtkWidget *widget, Compose *compose)
4355 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
4356 gtk_widget_grab_focus(compose->cc_entry);
4357 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4358 gtk_widget_grab_focus(compose->bcc_entry);
4359 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4360 gtk_widget_grab_focus(compose->reply_entry);
4361 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4362 gtk_widget_grab_focus(compose->followup_entry);
4364 gtk_widget_grab_focus(compose->text);
4367 static void cc_activated(GtkWidget *widget, Compose *compose)
4369 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4370 gtk_widget_grab_focus(compose->bcc_entry);
4371 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4372 gtk_widget_grab_focus(compose->reply_entry);
4373 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4374 gtk_widget_grab_focus(compose->followup_entry);
4376 gtk_widget_grab_focus(compose->text);
4379 static void bcc_activated(GtkWidget *widget, Compose *compose)
4381 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4382 gtk_widget_grab_focus(compose->reply_entry);
4383 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4384 gtk_widget_grab_focus(compose->followup_entry);
4386 gtk_widget_grab_focus(compose->text);
4389 static void replyto_activated(GtkWidget *widget, Compose *compose)
4391 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4392 gtk_widget_grab_focus(compose->followup_entry);
4394 gtk_widget_grab_focus(compose->text);
4397 static void followupto_activated(GtkWidget *widget, Compose *compose)
4399 gtk_widget_grab_focus(compose->text);
4402 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
4405 Compose *compose = (Compose *)data;
4407 if (GTK_CHECK_MENU_ITEM(widget)->active)
4408 compose->return_receipt = TRUE;
4410 compose->return_receipt = FALSE;
4413 static gchar *compose_quote_fmt (Compose *compose,
4418 gchar * quote_str = NULL;
4420 if (qmark != NULL) {
4423 quote_fmt_init(msginfo, NULL);
4424 quote_fmt_scan_string(qmark);
4427 p = quote_fmt_get_buffer();
4430 (_("Quote mark format error."));
4433 quote_str = alloca(strlen(p) + 1);
4434 strcpy(quote_str, p);
4438 quote_fmt_init(msginfo, quote_str);
4439 quote_fmt_scan_string(fmt);
4442 if (quote_fmt_get_buffer() == NULL)
4444 (_("Message reply/forward format error."));
4446 return quote_fmt_get_buffer();