2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
31 #include <gtk/gtkitemfactory.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkclist.h>
36 #include <gtk/gtkctree.h>
37 #include <gtk/gtkvpaned.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkeditable.h>
40 #include <gtk/gtkwindow.h>
41 #include <gtk/gtksignal.h>
42 #include <gtk/gtkvbox.h>
43 #include <gtk/gtkcontainer.h>
44 #include <gtk/gtkhandlebox.h>
45 #include <gtk/gtktoolbar.h>
46 #include <gtk/gtktable.h>
47 #include <gtk/gtkhbox.h>
48 #include <gtk/gtklabel.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtkthemes.h>
51 #include <gtk/gtkdnd.h>
58 /* #include <sys/utsname.h> */
64 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
74 #include "mainwindow.h"
76 #include "addressbook.h"
77 #include "folderview.h"
82 #include "customheader.h"
83 #include "prefs_common.h"
84 #include "prefs_account.h"
87 #include "procheader.h"
89 #include "statusbar.h"
96 #include "alertpanel.h"
97 #include "manage_window.h"
98 #include "gtkshruler.h"
100 #include "addr_compl.h"
103 # include "rfc2015.h"
106 #include "quote_fmt.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_attach_append_with_type(Compose *compose,
158 ContentType cnttype);
159 static void compose_wrap_line (Compose *compose);
160 static void compose_set_title (Compose *compose);
162 static PrefsAccount *compose_current_mail_account(void);
163 /* static gint compose_send (Compose *compose); */
164 static gint compose_write_to_file (Compose *compose,
167 static gint compose_write_body_to_file (Compose *compose,
169 static gint compose_save_to_outbox (Compose *compose,
171 static gint compose_queue (Compose *compose,
173 static void compose_write_attach (Compose *compose,
175 static gint compose_write_headers (Compose *compose,
177 const gchar *charset,
178 EncodingType encoding,
181 static void compose_convert_header (gchar *dest,
185 static void compose_generate_msgid (Compose *compose,
189 static void compose_attach_info_free (AttachInfo *ainfo);
190 static void compose_attach_remove_selected (Compose *compose);
192 static void compose_attach_property (Compose *compose);
193 static void compose_attach_property_create (gboolean *cancelled);
194 static void attach_property_ok (GtkWidget *widget,
195 gboolean *cancelled);
196 static void attach_property_cancel (GtkWidget *widget,
197 gboolean *cancelled);
198 static gint attach_property_delete_event (GtkWidget *widget,
200 gboolean *cancelled);
201 static void attach_property_key_pressed (GtkWidget *widget,
203 gboolean *cancelled);
205 static void compose_exec_ext_editor (Compose *compose);
206 static gint compose_exec_ext_editor_real (const gchar *file);
207 static gboolean compose_ext_editor_kill (Compose *compose);
208 static void compose_input_cb (gpointer data,
210 GdkInputCondition condition);
211 static void compose_set_ext_editor_sensitive (Compose *compose,
214 static gint calc_cursor_xpos (GtkSText *text,
218 /* callback functions */
220 static gboolean compose_edit_size_alloc (GtkEditable *widget,
221 GtkAllocation *allocation,
222 GtkSHRuler *shruler);
224 static void toolbar_send_cb (GtkWidget *widget,
226 static void toolbar_send_later_cb (GtkWidget *widget,
228 static void toolbar_draft_cb (GtkWidget *widget,
230 static void toolbar_insert_cb (GtkWidget *widget,
232 static void toolbar_attach_cb (GtkWidget *widget,
234 static void toolbar_sig_cb (GtkWidget *widget,
236 static void toolbar_ext_editor_cb (GtkWidget *widget,
238 static void toolbar_linewrap_cb (GtkWidget *widget,
240 static void toolbar_address_cb (GtkWidget *widget,
243 static void select_account(Compose * compose, PrefsAccount * ac);
244 static void account_activated (GtkMenuItem *menuitem,
247 static void attach_selected (GtkCList *clist,
252 static void attach_button_pressed (GtkWidget *widget,
253 GdkEventButton *event,
255 static void attach_key_pressed (GtkWidget *widget,
259 static void compose_send_cb (gpointer data,
262 static void compose_send_later_cb (gpointer data,
266 static void compose_draft_cb (gpointer data,
270 static void compose_attach_cb (gpointer data,
273 static void compose_insert_file_cb (gpointer data,
277 static void compose_close_cb (gpointer data,
280 static void compose_address_cb (gpointer data,
284 static void compose_ext_editor_cb (gpointer data,
288 static gint compose_delete_cb (GtkWidget *widget,
291 static void compose_destroy_cb (GtkWidget *widget,
294 static void compose_cut_cb (Compose *compose);
295 static void compose_copy_cb (Compose *compose);
296 static void compose_paste_cb (Compose *compose);
297 static void compose_allsel_cb (Compose *compose);
299 static void compose_grab_focus_cb (GtkWidget *widget,
302 static void compose_changed_cb (GtkEditable *editable,
304 static void compose_button_press_cb (GtkWidget *widget,
305 GdkEventButton *event,
308 static void compose_key_press_cb (GtkWidget *widget,
313 static void compose_toggle_to_cb (gpointer data,
316 static void compose_toggle_cc_cb (gpointer data,
319 static void compose_toggle_bcc_cb (gpointer data,
322 static void compose_toggle_replyto_cb (gpointer data,
325 static void compose_toggle_followupto_cb(gpointer data,
328 static void compose_toggle_attach_cb (gpointer data,
331 static void compose_toggle_ruler_cb (gpointer data,
335 static void compose_toggle_sign_cb (gpointer data,
338 static void compose_toggle_encrypt_cb (gpointer data,
342 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
345 static void compose_attach_drag_received_cb (GtkWidget *widget,
346 GdkDragContext *drag_context,
349 GtkSelectionData *data,
353 static void compose_insert_drag_received_cb (GtkWidget *widget,
354 GdkDragContext *drag_context,
357 GtkSelectionData *data,
362 static void to_activated (GtkWidget *widget,
364 static void newsgroups_activated (GtkWidget *widget,
366 static void subject_activated (GtkWidget *widget,
368 static void cc_activated (GtkWidget *widget,
370 static void bcc_activated (GtkWidget *widget,
372 static void replyto_activated (GtkWidget *widget,
374 static void followupto_activated (GtkWidget *widget,
376 static void compose_attach_parts(Compose * compose,
379 static gchar *compose_quote_fmt (Compose *compose,
382 const gchar * qmark);
384 static GtkItemFactoryEntry compose_popup_entries[] =
386 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
387 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
388 {N_("/---"), NULL, NULL, 0, "<Separator>"},
389 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
392 static GtkItemFactoryEntry compose_entries[] =
394 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
395 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
396 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
397 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
398 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
399 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
401 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
402 {N_("/_Edit/_Undo"), "<control>Z", NULL, 0, NULL},
403 {N_("/_Edit/_Redo"), "<control>Y", NULL, 0, NULL},
404 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
405 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
406 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
407 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
408 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
409 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
410 {N_("/_Edit/Wrap long _lines"), "<alt>L", compose_wrap_line, 0, NULL},
411 {N_("/_Edit/Edit with e_xternal editor"), "<alt>X",
412 compose_ext_editor_cb, 0, NULL},
414 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
415 {N_("/_Message/_Send"), "<shift><control>S",
416 compose_send_cb, 0, NULL},
417 {N_("/_Message/Send _later"), "<shift><alt>S",
418 compose_send_later_cb, 0, NULL},
419 {N_("/_Message/Save to _draft folder"),
420 "<alt>D", compose_draft_cb, 0, NULL},
421 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
422 {N_("/_Message/_To"), NULL, compose_toggle_to_cb, 0, "<ToggleItem>"},
423 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb, 0, "<ToggleItem>"},
424 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb, 0, "<ToggleItem>"},
425 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
426 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
427 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
428 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
429 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
431 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
432 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb, 0, "<ToggleItem>"},
433 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
434 #endif /* USE_GPGME */
435 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
436 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
437 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
438 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
439 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb, 0, NULL},
440 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
441 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
444 static GtkTargetEntry compose_mime_types[] =
446 {"text/uri-list", 0, 0}
449 Compose * compose_new(PrefsAccount *account)
451 return compose_new_with_recipient(account, NULL);
454 Compose * compose_new_with_recipient(PrefsAccount *account, const gchar *to)
458 if (!account) account = cur_account;
459 g_return_val_if_fail(account != NULL, NULL);
461 compose = compose_create(account);
462 compose->mode = COMPOSE_NEW;
464 if (prefs_common.auto_sig)
465 compose_insert_sig(compose);
466 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
467 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
469 if (account->protocol != A_NNTP) {
471 compose_entry_append(compose, to, COMPOSE_TO);
472 gtk_widget_grab_focus(compose->subject_entry);
474 gtk_widget_grab_focus(compose->to_entry);
477 compose_entry_append(compose, to, COMPOSE_NEWSGROUPS);
478 gtk_widget_grab_focus(compose->subject_entry);
480 gtk_widget_grab_focus(compose->newsgroups_entry);
486 #define CHANGE_FLAGS(msginfo) \
488 if (msginfo->folder->folder->change_flags != NULL) \
489 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
494 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
495 gboolean ignore_replyto)
498 PrefsAccount *account;
499 PrefsAccount *reply_account;
502 g_return_if_fail(msginfo != NULL);
503 g_return_if_fail(msginfo->folder != NULL);
505 account = msginfo->folder->folder->account;
506 if (!account) account = cur_account;
507 g_return_if_fail(account != NULL);
509 if (ignore_replyto && account->protocol == A_NNTP) {
511 account_find_mail_from_address(account->address);
513 reply_account = compose_current_mail_account();
517 reply_account = account;
519 MSG_UNSET_FLAGS(msginfo->flags, MSG_FORWARDED);
520 MSG_SET_FLAGS(msginfo->flags, MSG_REPLIED);
522 CHANGE_FLAGS(msginfo);
524 compose = compose_create(reply_account);
525 compose->mode = COMPOSE_REPLY;
527 if (compose_parse_header(compose, msginfo) < 0) return;
528 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto);
530 text = GTK_STEXT(compose->text);
531 gtk_stext_freeze(text);
537 if ((fp = procmime_get_text_part(msginfo)) == NULL)
538 g_warning(_("Can't get text part\n"));
542 if (prefs_common.quotemark && *prefs_common.quotemark)
543 qmark = prefs_common.quotemark;
547 quote_str = compose_quote_fmt(compose, msginfo,
548 prefs_common.quotefmt,
552 quote_str = compose_quote_parse_fmt
553 (compose, msginfo, prefs_common.quotefmt);
556 if (quote_str != NULL)
557 gtk_stext_insert(text, NULL, NULL, NULL,
559 /* g_free(quote_str); */
560 /* compose_quote_file(compose, msginfo, fp); */
565 if (prefs_common.auto_sig)
566 compose_insert_sig(compose);
567 gtk_editable_set_position(GTK_EDITABLE(text), 0);
568 gtk_stext_set_point(text, 0);
570 gtk_stext_thaw(text);
571 gtk_widget_grab_focus(compose->text);
575 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
580 g_return_val_if_fail(mimeinfo != NULL, NULL);
582 base = mimeinfo->filename ? mimeinfo->filename
583 : mimeinfo->name ? mimeinfo->name : NULL;
585 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
586 filename = g_strdup_printf("%s%smimetmp%i.html",
593 base = base ? base : "";
594 base = g_basename(base);
596 filename = g_strdup_printf("%s%smimetmp%i",
604 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
610 static gchar * mime_extract_file(gchar * source, MimeInfo *partinfo)
614 if (!partinfo) return;
616 filename = procmime_get_file_name(partinfo);
618 if (procmime_get_part(filename, source, partinfo) < 0)
620 (_("Can't get the part of multipart message."));
625 static void compose_attach_parts(Compose * compose,
635 gint boundary_len = 0;
637 glong fpos, prev_fpos;
642 g_return_if_fail(msginfo != NULL);
646 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
647 mimeinfo = procmime_scan_mime_header(fp);
648 if (!mimeinfo) break;
650 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
651 rfc2015_is_encrypted(mimeinfo)) {
652 MSG_SET_FLAGS(msginfo->flags, MSG_ENCRYPTED);
654 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
655 !msginfo->plaintext_file &&
656 !msginfo->decryption_failed) {
657 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
658 if (msginfo->plaintext_file &&
659 !msginfo->decryption_failed) {
667 #else /* !USE_GPGME */
668 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
669 mimeinfo = procmime_scan_mime_header(fp);
670 #endif /* USE_GPGME */
673 if (!mimeinfo) return;
674 if (mimeinfo->mime_type == MIME_TEXT)
677 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
679 g_return_if_fail(mimeinfo != NULL);
680 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
682 if (mimeinfo->mime_type == MIME_MULTIPART) {
683 g_return_if_fail(mimeinfo->boundary != NULL);
684 g_return_if_fail(mimeinfo->sub == NULL);
686 g_return_if_fail(fp != NULL);
688 boundary = mimeinfo->boundary;
691 boundary_len = strlen(boundary);
693 /* look for first boundary */
694 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
695 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
702 if ((fpos = ftell(fp)) < 0) {
708 for (npart = 0;; npart++) {
710 gboolean eom = FALSE;
714 partinfo = procmime_scan_mime_header(fp);
715 if (!partinfo) break;
718 procmime_mimeinfo_insert(mimeinfo, partinfo);
720 procmime_mimeinfo_free(partinfo);
722 /* look for next boundary */
724 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
725 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
726 if (buf[2 + boundary_len] == '-' &&
727 buf[2 + boundary_len + 1] == '-')
733 eom = TRUE; /* broken MIME message */
736 partinfo->size = fpos - prev_fpos - strlen(buf);
741 source = procmsg_get_message_file_path(msginfo);
743 g_return_if_fail(mimeinfo != NULL);
745 if (!mimeinfo->main && mimeinfo->parent)
747 filename = mime_extract_file(source, mimeinfo);
749 compose_attach_append_with_type(compose, filename,
750 mimeinfo->content_type,
751 mimeinfo->mime_type);
756 if (mimeinfo->sub && mimeinfo->sub->children)
758 filename = mime_extract_file(source, mimeinfo->sub);
760 compose_attach_append_with_type(compose, filename,
761 mimeinfo->content_type,
762 mimeinfo->sub->mime_type);
767 if (mimeinfo->children) {
770 child = mimeinfo->children;
772 filename = mime_extract_file(source, child);
774 compose_attach_append_with_type(compose, filename,
786 procmime_mimeinfo_free_all(mimeinfo);
790 #define INSERT_FW_HEADER(var, hdr) \
791 if (msginfo->var && *msginfo->var) { \
792 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
793 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
794 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
797 Compose * compose_forward(PrefsAccount * account, MsgInfo *msginfo,
801 /* PrefsAccount *account; */
806 g_return_val_if_fail(msginfo != NULL, NULL);
807 g_return_val_if_fail(msginfo->folder != NULL, NULL);
809 if (account == NULL) {
810 account = msginfo->folder->folder->account;
811 if (!account) account = cur_account;
813 g_return_val_if_fail(account != NULL, NULL);
815 MSG_UNSET_FLAGS(msginfo->flags, MSG_REPLIED);
816 MSG_SET_FLAGS(msginfo->flags, MSG_FORWARDED);
818 CHANGE_FLAGS(msginfo);
820 compose = compose_create(account);
821 compose->mode = COMPOSE_FORWARD;
823 if (msginfo->subject && *msginfo->subject) {
824 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
825 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
829 text = GTK_STEXT(compose->text);
830 gtk_stext_freeze(text);
835 msgfile = procmsg_get_message_file_path(msginfo);
836 if (!is_file_exist(msgfile))
837 g_warning(_("%s: file not exist\n"), msgfile);
839 compose_attach_append(compose, msgfile,
840 MIME_MESSAGE_RFC822);
847 if ((fp = procmime_get_text_part(msginfo)) == NULL)
848 g_warning(_("Can't get text part\n"));
852 if (prefs_common.fw_quotemark &&
853 *prefs_common.fw_quotemark)
854 qmark = prefs_common.fw_quotemark;
858 quote_str = compose_quote_fmt(compose, msginfo,
859 prefs_common.fw_quotefmt,
862 if (quote_str != NULL)
863 gtk_stext_insert(text, NULL, NULL, NULL,
869 compose_attach_parts(compose, msginfo);
872 if (prefs_common.auto_sig)
873 compose_insert_sig(compose);
874 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
875 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
877 gtk_stext_thaw(text);
878 if (account->protocol != A_NNTP)
879 gtk_widget_grab_focus(compose->to_entry);
881 gtk_widget_grab_focus(compose->newsgroups_entry);
886 #undef INSERT_FW_HEADER
888 void compose_reedit(MsgInfo *msginfo)
891 PrefsAccount *account;
896 g_return_if_fail(msginfo != NULL);
897 g_return_if_fail(msginfo->folder != NULL);
899 account = msginfo->folder->folder->account;
900 if (!account) account = cur_account;
901 g_return_if_fail(account != NULL);
903 compose = compose_create(account);
904 compose->mode = COMPOSE_REEDIT_DRAFT;
905 compose->targetinfo = procmsg_msginfo_copy(msginfo);
907 if (compose_parse_header(compose, msginfo) < 0) return;
908 compose_reedit_set_entry(compose, msginfo);
910 text = GTK_STEXT(compose->text);
911 gtk_stext_freeze(text);
913 if ((fp = procmime_get_text_part(msginfo)) == NULL)
914 g_warning(_("Can't get text part\n"));
916 while (fgets(buf, sizeof(buf), fp) != NULL)
917 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
920 compose_attach_parts(compose, msginfo);
922 gtk_stext_thaw(text);
923 gtk_widget_grab_focus(compose->text);
926 GList *compose_get_compose_list(void)
931 void compose_entry_append(Compose *compose, const gchar *address,
932 ComposeEntryType type)
937 if (!address || *address == '\0') return;
941 entry = GTK_ENTRY(compose->cc_entry);
944 entry = GTK_ENTRY(compose->bcc_entry);
946 case COMPOSE_NEWSGROUPS:
947 entry = GTK_ENTRY(compose->newsgroups_entry);
951 entry = GTK_ENTRY(compose->to_entry);
955 text = gtk_entry_get_text(entry);
957 gtk_entry_append_text(entry, ", ");
958 gtk_entry_append_text(entry, address);
961 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
963 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
964 {"Cc:", NULL, FALSE},
965 {"References:", NULL, FALSE},
966 {"Bcc:", NULL, FALSE},
967 {"Newsgroups:", NULL, FALSE},
968 {"Followup-To:", NULL, FALSE},
969 {NULL, NULL, FALSE}};
983 g_return_val_if_fail(msginfo != NULL, -1);
985 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
986 procheader_get_header_fields(fp, hentry);
989 if (hentry[H_REPLY_TO].body != NULL) {
990 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
991 compose->replyto = hentry[H_REPLY_TO].body;
992 hentry[H_REPLY_TO].body = NULL;
994 if (hentry[H_CC].body != NULL) {
995 conv_unmime_header_overwrite(hentry[H_CC].body);
996 compose->cc = hentry[H_CC].body;
997 hentry[H_CC].body = NULL;
999 if (hentry[H_REFERENCES].body != NULL) {
1000 if (compose->mode == COMPOSE_REEDIT_DRAFT)
1001 compose->references = hentry[H_REFERENCES].body;
1003 compose->references = compose_parse_references
1004 (hentry[H_REFERENCES].body, msginfo->msgid);
1005 g_free(hentry[H_REFERENCES].body);
1007 hentry[H_REFERENCES].body = NULL;
1009 if (hentry[H_BCC].body != NULL) {
1010 if (compose->mode == COMPOSE_REEDIT_DRAFT) {
1011 conv_unmime_header_overwrite(hentry[H_BCC].body);
1012 compose->bcc = hentry[H_BCC].body;
1014 g_free(hentry[H_BCC].body);
1015 hentry[H_BCC].body = NULL;
1017 if (hentry[H_NEWSGROUPS].body != NULL) {
1018 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1019 hentry[H_NEWSGROUPS].body = NULL;
1021 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1022 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1023 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1024 hentry[H_FOLLOWUP_TO].body = NULL;
1027 if (compose->mode == COMPOSE_REEDIT_DRAFT && msginfo->inreplyto)
1028 compose->inreplyto = g_strdup(msginfo->inreplyto);
1029 else if (compose->mode != COMPOSE_REEDIT_DRAFT &&
1030 msginfo->msgid && *msginfo->msgid) {
1031 compose->inreplyto = g_strdup(msginfo->msgid);
1033 if (!compose->references) {
1034 if (msginfo->inreplyto && *msginfo->inreplyto)
1035 compose->references =
1036 g_strdup_printf("<%s>\n\t<%s>",
1040 compose->references =
1041 g_strconcat("<", msginfo->msgid, ">",
1049 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1051 GSList *ref_id_list, *cur;
1055 ref_id_list = references_list_append(NULL, ref);
1056 if (!ref_id_list) return NULL;
1057 if (msgid && *msgid)
1058 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1063 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1064 /* "<" + Message-ID + ">" + CR+LF+TAB */
1065 len += strlen((gchar *)cur->data) + 5;
1067 if (len > MAX_REFERENCES_LEN) {
1068 /* remove second message-ID */
1069 if (ref_id_list && ref_id_list->next &&
1070 ref_id_list->next->next) {
1071 g_free(ref_id_list->next->data);
1072 ref_id_list = g_slist_remove
1073 (ref_id_list, ref_id_list->next->data);
1075 slist_free_strings(ref_id_list);
1076 g_slist_free(ref_id_list);
1083 new_ref = g_string_new("");
1084 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1085 if (new_ref->len > 0)
1086 g_string_append(new_ref, "\n\t");
1087 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1090 slist_free_strings(ref_id_list);
1091 g_slist_free(ref_id_list);
1093 new_ref_str = new_ref->str;
1094 g_string_free(new_ref, FALSE);
1100 static void compose_quote_file(Compose *compose, MsgInfo *msginfo, FILE *fp)
1102 GtkSText *text = GTK_STEXT(compose->text);
1105 GdkColor *qcolor = NULL;
1106 gchar buf[BUFFSIZE];
1108 gchar *linep, *cur, *leftp;
1109 gint line_len, cur_len;
1114 // if (prefs_common.enable_color) qcolor = "e_color;
1115 if (prefs_common.quotemark && *prefs_common.quotemark)
1116 qmark = prefs_common.quotemark;
1119 quote_str = compose_quote_parse_fmt(compose, msginfo, qmark);
1120 g_return_if_fail(quote_str != NULL);
1121 qlen = strlen(quote_str);
1123 if (!prefs_common.linewrap_quote ||
1124 prefs_common.linewrap_len <= qlen) {
1125 while (fgets(buf, sizeof(buf), fp) != NULL) {
1126 gtk_stext_insert(text, NULL, qcolor, NULL,
1128 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1134 wrap_len = prefs_common.linewrap_len - qlen;
1136 while (fgets(buf, sizeof(buf), fp) != NULL) {
1138 str_len = strlen(buf);
1140 if (str_len <= wrap_len) {
1141 gtk_stext_insert(text, NULL, qcolor, NULL,
1143 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1144 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1148 linep = cur = leftp = buf;
1149 line_len = cur_len = 0;
1151 while (*cur != '\0') {
1152 ch_len = mblen(cur, MB_CUR_MAX);
1153 if (ch_len < 0) ch_len = 1;
1155 if (ch_len == 1 && isspace(*cur)) {
1156 linep = cur + ch_len;
1157 line_len = cur_len + ch_len;
1160 if (cur_len + ch_len > wrap_len && line_len > 0) {
1161 gtk_stext_insert(text, NULL, qcolor, NULL,
1164 if (isspace(*(linep - 1)))
1165 gtk_stext_insert(text, NULL,
1167 leftp, line_len - 1);
1169 gtk_stext_insert(text, NULL,
1172 gtk_stext_insert(text, NULL, NULL, NULL,
1176 cur_len = cur_len - line_len + ch_len;
1183 linep = cur + ch_len;
1184 line_len = cur_len + ch_len;
1191 gtk_stext_insert(text, NULL, qcolor, NULL,
1193 gtk_stext_insert(text, NULL, qcolor, NULL, leftp, -1);
1194 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1203 static gchar *compose_quote_parse_fmt(Compose *compose, MsgInfo *msginfo,
1207 size_t buf_len = 1024;
1215 if (!fmt || *fmt == '\0') return 0;
1217 Xalloca(mbs, sizeof(wchar_t) + 1, return 0);
1218 Xalloca(wcsfmt, (strlen(fmt) + 1) * sizeof(wchar_t), return 0);
1219 mbstowcs(wcsfmt, fmt, strlen(fmt) + 1);
1222 ext_str = g_malloc(sizeof(gchar) * buf_len);
1223 g_return_val_if_fail(ext_str != NULL, NULL);
1228 len = wctomb(mbs, *sp);
1234 wctomb(mbs, *(++sp));
1239 str = msginfo->date;
1243 str = msginfo->from;
1247 if (!msginfo->fromname) {sp++; break;}
1248 p = msginfo->fromname;
1249 tmp[0] = tmp[1] = tmp[2] = '\0';
1251 if (*p && isalnum(*p))
1252 tmp[0] = toupper(*p);
1259 while (*p && !isspace(*p)) p++;
1260 while (*p && isspace(*p)) p++;
1261 if (*p && isalnum(*p))
1262 tmp[1] = toupper(*p);
1265 if (tmp[1]) str = tmp;
1269 str = msginfo->fromname;
1273 if (!msginfo->fromname) {sp++; break;}
1274 Xstrdup_a(str, msginfo->fromname,
1277 while (*p && !isspace(*p)) p++;
1282 str = msginfo->subject;
1290 if (!msginfo->msgid) {sp++; break;}
1291 Xalloca(str, strlen(msginfo->msgid) + 3,
1293 g_snprintf(str, strlen(msginfo->msgid) + 3,
1294 "<%s>", msginfo->msgid);
1306 while (ext_len + strlen(str) + 1 > buf_len)
1308 ext_str = g_realloc(ext_str,
1309 sizeof(gchar) * buf_len);
1310 g_return_val_if_fail(ext_str != NULL, NULL);
1311 strcpy(ext_str + ext_len, str);
1312 ext_len += strlen(str);
1314 } else if (*mbs == '\\') {
1315 wctomb(mbs, *(++sp));
1333 while (ext_len + strlen(str) + 1 > buf_len)
1335 ext_str = g_realloc(ext_str,
1336 sizeof(gchar) * buf_len);
1337 g_return_val_if_fail(ext_str != NULL, NULL);
1338 strcpy(ext_str + ext_len, str);
1339 ext_len += strlen(str);
1343 while (ext_len + len + 1 > buf_len) buf_len += 1024;
1344 ext_str = g_realloc(ext_str, sizeof(gchar) * buf_len);
1345 g_return_val_if_fail(ext_str != NULL, NULL);
1346 strcpy(ext_str + ext_len, mbs);
1353 ext_str = g_realloc(ext_str, strlen(ext_str) + 1);
1359 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1360 gboolean to_all, gboolean ignore_replyto)
1365 GHashTable *to_table;
1367 g_return_if_fail(compose->account != NULL);
1368 g_return_if_fail(msginfo != NULL);
1370 if (compose->account->protocol != A_NNTP)
1371 gtk_entry_set_text(GTK_ENTRY(compose->to_entry),
1372 ( (compose->replyto && !ignore_replyto)
1374 : msginfo->from ? msginfo->from : ""));
1375 if (compose->account->protocol == A_NNTP)
1376 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry),
1377 compose->followup_to ? compose->followup_to
1378 : compose->newsgroups ? compose->newsgroups
1381 if (msginfo->subject && *msginfo->subject) {
1382 gchar *buf, *buf2, *p;
1384 buf = g_strdup(msginfo->subject);
1385 while (!strncasecmp(buf, "Re:", 3)) {
1387 while (isspace(*p)) p++;
1388 memmove(buf, p, strlen(p) + 1);
1391 buf2 = g_strdup_printf("Re: %s", buf);
1392 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1396 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1398 if (!to_all || compose->account->protocol == A_NNTP) return;
1400 from = g_strdup(compose->replyto ? compose->replyto :
1401 msginfo->from ? msginfo->from : "");
1402 extract_address(from);
1404 cc_list = address_list_append(NULL, msginfo->to);
1405 cc_list = address_list_append(cc_list, compose->cc);
1407 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1408 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1409 if (compose->account)
1410 g_hash_table_insert(to_table, compose->account->address,
1411 GINT_TO_POINTER(1));
1413 /* remove address on To: and that of current account */
1414 for (cur = cc_list; cur != NULL; ) {
1415 GSList *next = cur->next;
1417 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1418 cc_list = g_slist_remove(cc_list, cur->data);
1420 g_hash_table_insert(to_table, cur->data, cur);
1424 g_hash_table_destroy(to_table);
1428 for (cur = cc_list; cur != NULL; cur = cur->next)
1429 compose_entry_append(compose, (gchar *)cur->data,
1431 slist_free_strings(cc_list);
1432 g_slist_free(cc_list);
1436 #define SET_ENTRY(entry, str) \
1439 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1442 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1444 g_return_if_fail(msginfo != NULL);
1446 SET_ENTRY(to_entry, msginfo->to);
1447 SET_ENTRY(subject_entry, msginfo->subject);
1448 SET_ENTRY(cc_entry, compose->cc);
1449 SET_ENTRY(bcc_entry, compose->bcc);
1450 SET_ENTRY(reply_entry, compose->replyto);
1453 GtkItemFactory *ifactory;
1454 GtkWidget *menuitem;
1456 ifactory = gtk_item_factory_from_widget(compose->menubar);
1457 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1458 gtk_check_menu_item_set_active
1459 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1461 if (compose->replyto) {
1462 GtkItemFactory *ifactory;
1463 GtkWidget *menuitem;
1465 ifactory = gtk_item_factory_from_widget(compose->menubar);
1466 menuitem = gtk_item_factory_get_item
1467 (ifactory, "/Message/Reply to");
1468 gtk_check_menu_item_set_active
1469 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1475 static void compose_insert_sig(Compose *compose)
1479 if (compose->account && compose->account->sig_path)
1480 sigfile = g_strdup(compose->account->sig_path);
1482 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1483 DEFAULT_SIGNATURE, NULL);
1486 if (!is_file_or_fifo_exist(sigfile)) {
1491 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1492 if (prefs_common.sig_sep) {
1493 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1494 prefs_common.sig_sep, -1);
1495 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1499 compose_insert_file(compose, sigfile);
1503 static void compose_insert_file(Compose *compose, const gchar *file)
1505 GtkSText *text = GTK_STEXT(compose->text);
1506 gchar buf[BUFFSIZE];
1509 g_return_if_fail(file != NULL);
1511 if ((fp = fopen(file, "r")) == NULL) {
1512 FILE_OP_ERROR(file, "fopen");
1516 gtk_stext_freeze(text);
1518 while (fgets(buf, sizeof(buf), fp) != NULL)
1519 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1521 gtk_stext_thaw(text);
1526 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1527 ContentType cnttype)
1529 gchar *text[N_ATTACH_COLS];
1532 text[COL_MIMETYPE] = ainfo->content_type;
1533 text[COL_SIZE] = to_human_readable(ainfo->size);
1534 text[COL_NAME] = ainfo->name;
1536 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1537 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1539 if (cnttype != MIME_MESSAGE_RFC822)
1540 compose_changed_cb(NULL, compose);
1543 static void compose_attach_append_with_type(Compose *compose,
1546 ContentType cnttype)
1551 if (!is_file_exist(file)) {
1552 g_warning(_("File %s doesn't exist\n"), file);
1555 if ((size = get_file_size(file)) < 0) {
1556 g_warning(_("Can't get file size of %s\n"), file);
1560 alertpanel_notice(_("File %s is empty\n"), file);
1564 if (!compose->use_attach) {
1565 GtkItemFactory *ifactory;
1566 GtkWidget *menuitem;
1568 ifactory = gtk_item_factory_from_widget(compose->menubar);
1569 menuitem = gtk_item_factory_get_item(ifactory,
1571 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1575 ainfo = g_new0(AttachInfo, 1);
1576 ainfo->file = g_strdup(file);
1578 if (cnttype == MIME_MESSAGE_RFC822) {
1579 ainfo->encoding = ENC_7BIT;
1580 ainfo->name = g_strdup_printf(_("Message: %s"),
1583 ainfo->encoding = ENC_BASE64;
1584 ainfo->name = g_strdup(g_basename(file));
1587 ainfo->content_type = g_strdup(type);
1590 compose_attach_info(compose, ainfo, cnttype);
1593 static void compose_attach_append(Compose *compose, const gchar *file,
1594 ContentType cnttype)
1597 gchar *text[N_ATTACH_COLS];
1601 if (!is_file_exist(file)) {
1602 g_warning(_("File %s doesn't exist\n"), file);
1605 if ((size = get_file_size(file)) < 0) {
1606 g_warning(_("Can't get file size of %s\n"), file);
1610 alertpanel_notice(_("File %s is empty\n"), file);
1614 if (!compose->use_attach) {
1615 GtkItemFactory *ifactory;
1616 GtkWidget *menuitem;
1618 ifactory = gtk_item_factory_from_widget(compose->menubar);
1619 menuitem = gtk_item_factory_get_item(ifactory,
1621 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1625 ainfo = g_new0(AttachInfo, 1);
1626 ainfo->file = g_strdup(file);
1628 if (cnttype == MIME_MESSAGE_RFC822) {
1629 ainfo->content_type = g_strdup("message/rfc822");
1630 ainfo->encoding = ENC_7BIT;
1631 ainfo->name = g_strdup_printf(_("Message: %s"),
1634 ainfo->content_type = procmime_get_mime_type(file);
1635 if (!ainfo->content_type)
1636 ainfo->content_type =
1637 g_strdup("application/octet-stream");
1638 ainfo->encoding = ENC_BASE64;
1639 ainfo->name = g_strdup(g_basename(file));
1643 compose_attach_info(compose, ainfo, cnttype);
1646 static void compose_wrap_line(Compose *compose)
1648 GtkSText *text = GTK_STEXT(compose->text);
1650 guint line_pos = 0, cur_pos = 0;
1651 gint line_len = 0, cur_len = 0;
1653 gchar cbuf[MB_CUR_MAX];
1655 gtk_stext_freeze(text);
1657 text_len = gtk_stext_get_length(text);
1659 for (; cur_pos < text_len; cur_pos++) {
1660 if (text->use_wchar)
1662 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
1664 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
1668 if (ch_len == 1 && *cbuf == '\n') {
1669 line_pos = cur_pos + 1;
1670 line_len = cur_len = 0;
1679 if (ch_len == 1 && isspace(*cbuf)) {
1680 line_pos = cur_pos + 1;
1681 line_len = cur_len + ch_len;
1684 if (cur_len + ch_len > prefs_common.linewrap_len &&
1688 if (text->use_wchar)
1689 tlen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
1691 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
1694 if (tlen == 1 && isspace(*cbuf)) {
1695 gtk_stext_set_point(text, line_pos);
1696 gtk_stext_backward_delete(text, 1);
1704 gtk_stext_set_point(text, line_pos);
1705 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1709 cur_len = cur_len - line_len + ch_len;
1715 line_pos = cur_pos + 1;
1716 line_len = cur_len + ch_len;
1721 gtk_stext_thaw(text);
1724 static void compose_set_title(Compose *compose)
1729 edited = compose->modified ? _(" [Edited]") : "";
1730 if (compose->account && compose->account->address)
1731 str = g_strdup_printf(_("%s - Compose message%s"),
1732 compose->account->address, edited);
1734 str = g_strdup_printf(_("Compose message%s"), edited);
1735 gtk_window_set_title(GTK_WINDOW(compose->window), str);
1740 * compose_current_mail_account:
1742 * Find a current mail account (the currently selected account, or the
1743 * default account, if a news account is currently selected). If a
1744 * mail account cannot be found, display an error message.
1746 * Return value: Mail account, or NULL if not found.
1748 static PrefsAccount *
1749 compose_current_mail_account(void)
1753 if (cur_account && cur_account->protocol != A_NNTP)
1756 ac = account_get_default();
1757 if (!ac || ac->protocol == A_NNTP) {
1758 alertpanel_error(_("Account for sending mail is not specified.\n"
1759 "Please select a mail account before sending."));
1766 gint compose_send(Compose *compose)
1768 gchar tmp[MAXPATHLEN + 1];
1769 gchar *to, *newsgroups;
1771 static gboolean lock = FALSE;
1775 g_return_val_if_fail(compose->account != NULL, -1);
1776 g_return_val_if_fail(compose->orig_account != NULL, -1);
1780 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
1781 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
1782 if (*to == '\0' && *newsgroups == '\0') {
1783 alertpanel_error(_("Recipient is not specified."));
1788 /* write to temporary file */
1789 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
1790 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
1792 if (prefs_common.linewrap_at_send)
1793 compose_wrap_line(compose);
1795 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
1800 if (!compose->to_list && !compose->newsgroup_list) {
1801 g_warning(_("can't get recipient list."));
1807 if (compose->to_list) {
1811 if (compose->account->protocol != A_NNTP)
1812 ac = compose->account;
1813 else if (compose->orig_account->protocol != A_NNTP)
1814 ac = compose->orig_account;
1816 ac = compose_current_mail_account();
1824 ac = compose->account;
1826 ok = send_message(tmp, ac, compose->to_list);
1827 statusbar_pop_all();
1830 if (ok == 0 && compose->newsgroup_list) {
1833 if (compose->account->protocol == A_NNTP)
1834 folder = FOLDER(compose->account->folder);
1836 folder = FOLDER(compose->orig_account->folder);
1838 ok = news_post(folder, tmp);
1840 alertpanel_error(_("Error occurred while posting the message to %s ."),
1841 compose->account->nntp_server);
1848 /* queue message if failed to send */
1850 if (prefs_common.queue_msg) {
1855 _("Error occurred while sending the message.\n"
1856 "Put this message into queue folder?"),
1857 _("OK"), _("Cancel"), NULL);
1858 if (G_ALERTDEFAULT == val) {
1859 ok = compose_queue(compose, tmp);
1861 alertpanel_error(_("Can't queue the message."));
1864 alertpanel_error(_("Error occurred while sending the message."));
1867 /* save message to outbox */
1868 if (ok == 0 && prefs_common.savemsg) {
1869 if (compose_save_to_outbox(compose, tmp) < 0)
1871 (_("Can't save the message to outbox."));
1879 static gint compose_write_to_file(Compose *compose, const gchar *file,
1886 const gchar *out_codeset;
1887 EncodingType encoding;
1889 if ((fp = fopen(file, "w")) == NULL) {
1890 FILE_OP_ERROR(file, "fopen");
1894 /* chmod for security */
1895 if (change_file_mode_rw(fp, file) < 0) {
1896 FILE_OP_ERROR(file, "chmod");
1897 g_warning(_("can't change file mode\n"));
1900 /* get all composed text */
1901 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
1902 len = strlen(chars);
1903 if (is_ascii_str(chars)) {
1904 buf = g_strdup(chars);
1905 out_codeset = "US-ASCII";
1906 encoding = ENC_7BIT;
1908 const gchar *src_codeset;
1910 out_codeset = conv_get_outgoing_charset_str();
1911 if (!strcasecmp(out_codeset, "US-ASCII"))
1912 out_codeset = "ISO-8859-1";
1913 encoding = procmime_get_encoding_for_charset(out_codeset);
1914 debug_print("charset = %s, encoding = %s\n",
1915 out_codeset, procmime_get_encoding_str(encoding));
1917 src_codeset = conv_get_current_charset_str();
1918 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
1923 alertpanel_error(_("Can't convert the codeset of the message."));
1930 if (compose_write_headers
1931 (compose, fp, out_codeset, encoding, is_draft) < 0) {
1932 g_warning(_("can't write headers\n"));
1939 if (compose->use_attach) {
1941 /* This prolog message is ignored by mime software and
1942 * because it would make our signing/encryption task
1943 * tougher, we don't emit it in that case */
1944 if (!compose->use_signing && !compose->use_encryption)
1946 fputs("This is a multi-part message in MIME format.\n", fp);
1948 fprintf(fp, "\n--%s\n", compose->boundary);
1949 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
1951 fprintf(fp, "Content-Transfer-Encoding: %s\n",
1952 procmime_get_encoding_str(encoding));
1958 if (encoding == ENC_BASE64) {
1959 gchar outbuf[B64_BUFFSIZE];
1962 for (i = 0; i < len; i += B64_LINE_SIZE) {
1963 l = MIN(B64_LINE_SIZE, len - i);
1964 to64frombits(outbuf, buf + i, l);
1968 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
1969 FILE_OP_ERROR(file, "fwrite");
1977 if (compose->use_attach)
1978 compose_write_attach(compose, fp);
1980 if (fclose(fp) == EOF) {
1981 FILE_OP_ERROR(file, "fclose");
1987 if (compose->use_signing) {
1988 if (rfc2015_sign(file, compose->account) < 0) {
1993 if (compose->use_encryption) {
1994 if (rfc2015_encrypt(file, compose->to_list) < 0) {
1999 #endif /* USE_GPGME */
2004 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
2010 if ((fp = fopen(file, "w")) == NULL) {
2011 FILE_OP_ERROR(file, "fopen");
2015 /* chmod for security */
2016 if (change_file_mode_rw(fp, file) < 0) {
2017 FILE_OP_ERROR(file, "chmod");
2018 g_warning(_("can't change file mode\n"));
2021 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2024 len = strlen(chars);
2025 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
2026 FILE_OP_ERROR(file, "fwrite");
2035 if (fclose(fp) == EOF) {
2036 FILE_OP_ERROR(file, "fclose");
2043 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
2050 debug_print(_("saving sent message...\n"));
2052 outbox = folder_get_default_outbox();
2053 path = folder_item_get_path(outbox);
2054 if (!is_dir_exist(path))
2055 make_dir_hier(path);
2057 folder_item_scan(outbox);
2058 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
2060 g_warning(_("can't save message\n"));
2064 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
2065 g_warning(_("can't open mark file\n"));
2069 newmsginfo.msgnum = num;
2070 newmsginfo.flags = 0;
2071 procmsg_write_flags(&newmsginfo, fp);
2079 static gint compose_queue(Compose *compose, const gchar *file)
2082 gchar *tmp, *queue_path;
2085 gchar buf[BUFFSIZE];
2088 debug_print(_("queueing message...\n"));
2089 g_return_val_if_fail(compose->to_list != NULL, -1);
2090 g_return_val_if_fail(compose->account != NULL, -1);
2092 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
2093 G_DIR_SEPARATOR, (gint)compose);
2094 if ((fp = fopen(tmp, "w")) == NULL) {
2095 FILE_OP_ERROR(tmp, "fopen");
2099 if ((src_fp = fopen(file, "r")) == NULL) {
2100 FILE_OP_ERROR(file, "fopen");
2106 if (change_file_mode_rw(fp, tmp) < 0) {
2107 FILE_OP_ERROR(tmp, "chmod");
2108 g_warning(_("can't change file mode\n"));
2111 /* queueing variables */
2112 fprintf(fp, "AF:\n");
2113 fprintf(fp, "NF:0\n");
2114 fprintf(fp, "PS:10\n");
2115 fprintf(fp, "SRH:1\n");
2116 fprintf(fp, "SFN:\n");
2117 fprintf(fp, "DSR:\n");
2119 fprintf(fp, "MID:<%s>\n", compose->msgid);
2121 fprintf(fp, "MID:\n");
2122 fprintf(fp, "CFG:\n");
2123 fprintf(fp, "PT:0\n");
2124 fprintf(fp, "S:%s\n", compose->account->address);
2125 fprintf(fp, "RQ:\n");
2126 if (compose->account->smtp_server)
2127 fprintf(fp, "SSV:%s\n", compose->account->smtp_server);
2129 fprintf(fp, "SSV:\n");
2130 if (compose->account->nntp_server)
2131 fprintf(fp, "NSV:%s\n", compose->account->nntp_server);
2133 fprintf(fp, "NSV:\n");
2134 fprintf(fp, "SSH:\n");
2135 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
2136 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
2137 fprintf(fp, ",<%s>", (gchar *)cur->data);
2141 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
2142 if (fputs(buf, fp) == EOF) {
2143 FILE_OP_ERROR(tmp, "fputs");
2153 if (fclose(fp) == EOF) {
2154 FILE_OP_ERROR(tmp, "fclose");
2160 queue = folder_get_default_queue();
2161 folder_item_scan(queue);
2162 queue_path = folder_item_get_path(queue);
2163 if (!is_dir_exist(queue_path))
2164 make_dir_hier(queue_path);
2165 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
2166 g_warning(_("can't queue the message\n"));
2174 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
2175 g_warning(_("can't open mark file\n"));
2179 newmsginfo.msgnum = num;
2180 newmsginfo.flags = 0;
2181 procmsg_write_flags(&newmsginfo, fp);
2186 folder_item_scan(queue);
2187 folderview_update_item(queue, TRUE);
2192 static void compose_write_attach(Compose *compose, FILE *fp)
2195 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2198 gchar filename[BUFFSIZE];
2201 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
2203 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
2204 g_warning(_("Can't open file %s\n"), ainfo->file);
2208 fprintf(fp, "\n--%s\n", compose->boundary);
2210 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
2211 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
2212 fprintf(fp, "Content-Disposition: inline\n");
2214 conv_encode_header(filename, sizeof(filename),
2216 fprintf(fp, "Content-Type: %s;\n"
2218 ainfo->content_type, filename);
2219 fprintf(fp, "Content-Disposition: attachment;\n"
2220 " filename=\"%s\"\n", filename);
2223 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
2224 procmime_get_encoding_str(ainfo->encoding));
2226 if (ainfo->encoding == ENC_7BIT) {
2227 gchar buf[BUFFSIZE];
2229 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
2231 if (len > 1 && buf[len - 1] == '\n' &&
2232 buf[len - 2] == '\r') {
2233 buf[len - 2] = '\n';
2234 buf[len - 1] = '\0';
2239 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
2241 while ((len = fread(inbuf, sizeof(gchar),
2242 B64_LINE_SIZE, attach_fp))
2244 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
2248 if (len > 0 && feof(attach_fp)) {
2249 to64frombits(outbuf, inbuf, len);
2258 fprintf(fp, "\n--%s--\n", compose->boundary);
2261 #define IS_IN_CUSTOM_HEADER(header) \
2262 (compose->account->add_customhdr && \
2263 custom_header_find(compose->account->customhdr_list, header) != NULL)
2265 static gint compose_write_headers(Compose *compose, FILE *fp,
2266 const gchar *charset, EncodingType encoding,
2269 gchar buf[BUFFSIZE];
2271 /* struct utsname utsbuf; */
2273 g_return_val_if_fail(fp != NULL, -1);
2274 g_return_val_if_fail(charset != NULL, -1);
2275 g_return_val_if_fail(compose->account != NULL, -1);
2276 g_return_val_if_fail(compose->account->address != NULL, -1);
2279 if (compose->account->add_date) {
2280 get_rfc822_date(buf, sizeof(buf));
2281 fprintf(fp, "Date: %s\n", buf);
2285 if (!IS_IN_CUSTOM_HEADER("From")) {
2286 if (compose->account->name && *compose->account->name) {
2287 compose_convert_header
2288 (buf, sizeof(buf), compose->account->name,
2290 fprintf(fp, "From: %s <%s>\n",
2291 buf, compose->account->address);
2293 fprintf(fp, "From: %s\n", compose->account->address);
2296 slist_free_strings(compose->to_list);
2297 g_slist_free(compose->to_list);
2298 compose->to_list = NULL;
2301 if (compose->use_to) {
2302 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2304 Xstrdup_a(str, str, return -1);
2307 compose->to_list = address_list_append
2308 (compose->to_list, str);
2309 if (!IS_IN_CUSTOM_HEADER("To")) {
2310 compose_convert_header
2311 (buf, sizeof(buf), str,
2313 fprintf(fp, "To: %s\n", buf);
2319 slist_free_strings(compose->newsgroup_list);
2320 g_slist_free(compose->newsgroup_list);
2321 compose->newsgroup_list = NULL;
2324 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2326 Xstrdup_a(str, str, return -1);
2330 compose->newsgroup_list =
2331 newsgroup_list_append(compose->newsgroup_list,
2333 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
2334 compose_convert_header(buf, sizeof(buf), str,
2335 strlen("Newsgroups: "));
2336 fprintf(fp, "Newsgroups: %s\n", buf);
2341 if (!is_draft && !compose->to_list && !compose->newsgroup_list)
2345 if (compose->use_cc) {
2346 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
2348 Xstrdup_a(str, str, return -1);
2351 compose->to_list = address_list_append
2352 (compose->to_list, str);
2353 if (!IS_IN_CUSTOM_HEADER("Cc")) {
2354 compose_convert_header
2355 (buf, sizeof(buf), str,
2357 fprintf(fp, "Cc: %s\n", buf);
2364 if (compose->use_bcc) {
2365 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
2367 Xstrdup_a(str, str, return -1);
2370 compose->to_list = address_list_append
2371 (compose->to_list, str);
2373 compose_convert_header
2374 (buf, sizeof(buf), str,
2376 fprintf(fp, "Bcc: %s\n", buf);
2383 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2384 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
2385 Xstrdup_a(str, str, return -1);
2388 compose_convert_header(buf, sizeof(buf), str,
2389 strlen("Subject: "));
2390 fprintf(fp, "Subject: %s\n", buf);
2395 if (compose->account->gen_msgid) {
2396 compose_generate_msgid(compose, buf, sizeof(buf));
2397 fprintf(fp, "Message-Id: <%s>\n", buf);
2398 compose->msgid = g_strdup(buf);
2402 if (compose->inreplyto && compose->to_list)
2403 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
2406 if (compose->references)
2407 fprintf(fp, "References: %s\n", compose->references);
2410 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
2411 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
2413 Xstrdup_a(str, str, return -1);
2417 compose_convert_header(buf, sizeof(buf), str,
2418 strlen("Followup-To: "));
2419 fprintf(fp, "Followup-To: %s\n", buf);
2425 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
2426 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
2428 Xstrdup_a(str, str, return -1);
2431 compose_convert_header(buf, sizeof(buf), str,
2432 strlen("Reply-To: "));
2433 fprintf(fp, "Reply-To: %s\n", buf);
2439 if (compose->account->organization &&
2440 !IS_IN_CUSTOM_HEADER("Organization")) {
2441 compose_convert_header(buf, sizeof(buf),
2442 compose->account->organization,
2443 strlen("Organization: "));
2444 fprintf(fp, "Organization: %s\n", buf);
2447 /* Program version and system info */
2448 /* uname(&utsbuf); */
2449 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2450 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
2451 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
2453 gtk_major_version, gtk_minor_version, gtk_micro_version,
2455 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2457 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2458 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
2459 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
2461 gtk_major_version, gtk_minor_version, gtk_micro_version,
2463 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2466 /* custom headers */
2467 if (compose->account->add_customhdr) {
2470 for (cur = compose->account->customhdr_list; cur != NULL;
2472 CustomHeader *chdr = (CustomHeader *)cur->data;
2474 if (strcasecmp(chdr->name, "Date") != 0 &&
2475 strcasecmp(chdr->name, "From") != 0 &&
2476 strcasecmp(chdr->name, "To") != 0 &&
2477 strcasecmp(chdr->name, "Sender") != 0 &&
2478 strcasecmp(chdr->name, "Message-Id") != 0 &&
2479 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
2480 strcasecmp(chdr->name, "References") != 0 &&
2481 strcasecmp(chdr->name, "Mime-Version") != 0 &&
2482 strcasecmp(chdr->name, "Content-Type") != 0 &&
2483 strcasecmp(chdr->name, "Content-Transfer-Encoding")
2485 compose_convert_header
2487 chdr->value ? chdr->value : "",
2488 strlen(chdr->name) + 2);
2489 fprintf(fp, "%s: %s\n", chdr->name, buf);
2494 fprintf(fp, "Mime-Version: 1.0\n");
2495 if (compose->use_attach) {
2496 get_rfc822_date(buf, sizeof(buf));
2497 subst_char(buf, ' ', '_');
2498 subst_char(buf, ',', '_');
2499 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
2500 buf, (guint)compose);
2502 "Content-Type: multipart/mixed;\n"
2503 " boundary=\"%s\"\n", compose->boundary);
2505 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
2506 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2507 procmime_get_encoding_str(encoding));
2510 /* Request Return Receipt */
2511 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
2512 if (compose->return_receipt) {
2513 if (compose->account->name
2514 && *compose->account->name) {
2515 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
2516 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
2518 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
2522 /* separator between header and body */
2528 #undef IS_IN_CUSTOM_HEADER
2530 static void compose_convert_header(gchar *dest, gint len, gchar *src,
2533 g_return_if_fail(src != NULL);
2534 g_return_if_fail(dest != NULL);
2536 if (len < 1) return;
2540 if (is_ascii_str(src)) {
2541 strncpy2(dest, src, len);
2542 dest[len - 1] = '\0';
2545 conv_encode_header(dest, len, src, header_len);
2548 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
2557 if (compose->account && compose->account->address &&
2558 *compose->account->address) {
2559 if (strchr(compose->account->address, '@'))
2560 addr = g_strdup(compose->account->address);
2562 addr = g_strconcat(compose->account->address, "@",
2563 get_domain_name(), NULL);
2565 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
2568 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
2569 lt->tm_year + 1900, lt->tm_mon + 1,
2570 lt->tm_mday, lt->tm_hour,
2571 lt->tm_min, lt->tm_sec,
2572 (guint)random(), addr);
2574 debug_print(_("generated Message-ID: %s\n"), buf);
2579 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
2580 GtkWidget **entry, gint *count,
2581 const gchar *label_str,
2582 gboolean is_addr_entry)
2586 if (GTK_TABLE(table)->nrows < (*count) + 1)
2587 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
2589 *hbox = gtk_hbox_new(FALSE, 0);
2590 label = gtk_label_new
2591 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
2592 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
2593 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
2595 *entry = gtk_entry_new();
2596 gtk_table_attach_defaults
2597 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1);
2598 if (GTK_TABLE(table)->nrows > (*count) + 1)
2599 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
2602 address_completion_register_entry(GTK_ENTRY(*entry));
2607 static Compose *compose_create(PrefsAccount *account)
2613 GtkWidget *handlebox;
2617 GtkWidget *table_vbox;
2619 GtkWidget *from_optmenu_hbox;
2620 GtkWidget *to_entry;
2622 GtkWidget *newsgroups_entry;
2623 GtkWidget *newsgroups_hbox;
2624 GtkWidget *subject_entry;
2625 GtkWidget *cc_entry;
2627 GtkWidget *bcc_entry;
2628 GtkWidget *bcc_hbox;
2629 GtkWidget *reply_entry;
2630 GtkWidget *reply_hbox;
2631 GtkWidget *followup_entry;
2632 GtkWidget *followup_hbox;
2636 GtkWidget *attach_scrwin;
2637 GtkWidget *attach_clist;
2639 GtkWidget *edit_vbox;
2640 GtkWidget *ruler_hbox;
2642 GtkWidget *scrolledwin;
2648 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
2649 guint n_menu_entries;
2650 GtkStyle *style, *new_style;
2653 gboolean success[1];
2655 GtkWidget *popupmenu;
2656 GtkWidget *menuitem;
2657 GtkItemFactory *popupfactory;
2658 GtkItemFactory *ifactory;
2663 g_return_val_if_fail(account != NULL, NULL);
2665 debug_print(_("Creating compose window...\n"));
2666 compose = g_new0(Compose, 1);
2668 compose->account = account;
2669 compose->orig_account = account;
2671 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2672 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
2673 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
2674 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
2675 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
2676 gtk_signal_connect(GTK_OBJECT(window), "destroy",
2677 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
2678 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
2679 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
2680 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
2681 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
2682 gtk_widget_realize(window);
2684 vbox = gtk_vbox_new(FALSE, 0);
2685 gtk_container_add(GTK_CONTAINER(window), vbox);
2687 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
2688 menubar = menubar_create(window, compose_entries,
2689 n_menu_entries, "<Compose>", compose);
2690 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
2692 handlebox = gtk_handle_box_new();
2693 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
2695 compose_toolbar_create(compose, handlebox);
2697 vbox2 = gtk_vbox_new(FALSE, 2);
2698 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
2699 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
2701 table_vbox = gtk_vbox_new(FALSE, 0);
2702 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
2703 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
2706 table = gtk_table_new(8, 2, FALSE);
2707 gtk_box_pack_start(GTK_BOX(table_vbox), table, FALSE, TRUE, 0);
2709 /* option menu for selecting accounts */
2710 hbox = gtk_hbox_new(FALSE, 0);
2711 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
2712 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
2713 gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, count, count + 1,
2715 from_optmenu_hbox = compose_account_option_menu_create(compose);
2716 gtk_table_attach_defaults(GTK_TABLE(table), from_optmenu_hbox,
2717 1, 2, count, count + 1);
2718 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
2721 /* header labels and entries */
2722 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
2724 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
2725 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
2726 &count, "Newsgroups:", FALSE);
2727 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
2728 compose_add_entry_field(table, &hbox, &subject_entry, &count,
2730 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
2731 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
2733 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
2734 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
2736 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
2737 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
2739 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
2740 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
2741 "Followup-To:", FALSE);
2742 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
2744 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
2746 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
2747 GTK_SIGNAL_FUNC(to_activated), compose);
2748 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
2749 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
2750 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
2751 GTK_SIGNAL_FUNC(subject_activated), compose);
2752 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
2753 GTK_SIGNAL_FUNC(cc_activated), compose);
2754 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
2755 GTK_SIGNAL_FUNC(bcc_activated), compose);
2756 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
2757 GTK_SIGNAL_FUNC(replyto_activated), compose);
2758 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
2759 GTK_SIGNAL_FUNC(followupto_activated), compose);
2761 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
2762 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2763 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
2764 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2765 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
2766 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2767 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
2768 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2769 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
2770 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2771 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
2772 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2773 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
2774 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2776 /* attachment list */
2777 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
2778 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
2779 GTK_POLICY_AUTOMATIC,
2781 gtk_widget_set_usize(attach_scrwin, -1, 80);
2783 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
2784 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
2786 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
2787 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
2788 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
2789 GTK_SELECTION_EXTENDED);
2790 for (i = 0; i < N_ATTACH_COLS; i++)
2791 GTK_WIDGET_UNSET_FLAGS
2792 (GTK_CLIST(attach_clist)->column[i].button,
2794 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
2796 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
2797 GTK_SIGNAL_FUNC(attach_selected), compose);
2798 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
2799 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
2800 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
2801 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
2804 gtk_drag_dest_set(attach_clist,
2805 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
2807 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
2808 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
2811 /* pane between attach clist and text */
2812 paned = gtk_vpaned_new();
2813 gtk_paned_add1(GTK_PANED(paned), attach_scrwin);
2814 gtk_widget_ref(paned);
2815 gtk_widget_show_all(paned);
2817 edit_vbox = gtk_vbox_new(FALSE, 0);
2818 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
2821 ruler_hbox = gtk_hbox_new(FALSE, 0);
2822 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
2824 ruler = gtk_shruler_new();
2825 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
2826 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
2828 gtk_widget_set_usize(ruler_hbox, 1, -1);
2831 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
2832 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
2833 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
2834 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
2835 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
2837 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
2838 (GTK_SCROLLED_WINDOW(scrolledwin)),
2839 gtk_scrolled_window_get_vadjustment
2840 (GTK_SCROLLED_WINDOW(scrolledwin)));
2841 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
2842 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
2843 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
2845 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
2847 gtk_signal_connect(GTK_OBJECT(text), "changed",
2848 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
2849 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
2850 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2851 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
2852 GTK_SIGNAL_FUNC(compose_button_press_cb),
2855 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
2856 GTK_SIGNAL_FUNC(compose_key_press_cb),
2859 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
2860 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
2864 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
2866 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
2867 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
2870 gtk_widget_show_all(vbox);
2872 style = gtk_widget_get_style(text);
2874 /* workaround for the slow down of GtkSText when using Pixmap theme */
2875 if (style->engine) {
2876 GtkThemeEngine *engine;
2878 engine = style->engine;
2879 style->engine = NULL;
2880 new_style = gtk_style_copy(style);
2881 style->engine = engine;
2883 new_style = gtk_style_copy(style);
2885 if (prefs_common.textfont) {
2888 charset = conv_get_current_charset();
2889 if (MB_CUR_MAX == 1) {
2892 Xstrdup_a(fontstr, prefs_common.textfont, );
2893 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
2895 font = gdk_font_load(fontstr);
2897 font = gdk_fontset_load(prefs_common.textfont);
2899 gdk_font_unref(new_style->font);
2900 new_style->font = font;
2904 gtk_widget_set_style(text, new_style);
2906 color[0] = quote_color;
2907 cmap = gdk_window_get_colormap(window->window);
2908 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
2909 if (success[0] == FALSE) {
2910 g_warning("Compose: color allocation failed.\n");
2911 style = gtk_widget_get_style(text);
2912 quote_color = style->black;
2915 n_entries = sizeof(compose_popup_entries) /
2916 sizeof(compose_popup_entries[0]);
2917 popupmenu = menu_create_items(compose_popup_entries, n_entries,
2918 "<Compose>", &popupfactory,
2921 ifactory = gtk_item_factory_from_widget(menubar);
2922 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
2923 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
2926 if (account->protocol == A_NNTP) {
2927 gtk_widget_hide(to_hbox);
2928 gtk_widget_hide(to_entry);
2929 gtk_widget_hide(cc_hbox);
2930 gtk_widget_hide(cc_entry);
2931 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
2932 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
2934 gtk_widget_hide(newsgroups_hbox);
2935 gtk_widget_hide(newsgroups_entry);
2936 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
2938 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
2942 switch (prefs_common.toolbar_style) {
2944 gtk_widget_hide(handlebox);
2947 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
2951 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
2955 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
2960 gtk_widget_show(window);
2962 address_completion_start(window);
2964 compose->window = window;
2965 compose->vbox = vbox;
2966 compose->menubar = menubar;
2967 compose->handlebox = handlebox;
2969 compose->vbox2 = vbox2;
2971 compose->table_vbox = table_vbox;
2972 compose->table = table;
2973 compose->to_hbox = to_hbox;
2974 compose->to_entry = to_entry;
2975 compose->newsgroups_hbox = newsgroups_hbox;
2976 compose->newsgroups_entry = newsgroups_entry;
2977 compose->subject_entry = subject_entry;
2978 compose->cc_hbox = cc_hbox;
2979 compose->cc_entry = cc_entry;
2980 compose->bcc_hbox = bcc_hbox;
2981 compose->bcc_entry = bcc_entry;
2982 compose->reply_hbox = reply_hbox;
2983 compose->reply_entry = reply_entry;
2984 compose->followup_hbox = followup_hbox;
2985 compose->followup_entry = followup_entry;
2987 compose->paned = paned;
2989 compose->attach_scrwin = attach_scrwin;
2990 compose->attach_clist = attach_clist;
2992 compose->edit_vbox = edit_vbox;
2993 compose->ruler_hbox = ruler_hbox;
2994 compose->ruler = ruler;
2995 compose->scrolledwin = scrolledwin;
2996 compose->text = text;
2998 compose->focused_editable = NULL;
3000 compose->popupmenu = popupmenu;
3001 compose->popupfactory = popupfactory;
3003 compose->mode = COMPOSE_NEW;
3005 compose->replyto = NULL;
3007 compose->bcc = NULL;
3008 compose->followup_to = NULL;
3009 compose->inreplyto = NULL;
3010 compose->references = NULL;
3011 compose->msgid = NULL;
3012 compose->boundary = NULL;
3015 compose->use_signing = FALSE;
3016 compose->use_encryption = FALSE;
3017 #endif /* USE_GPGME */
3019 compose->modified = FALSE;
3021 compose->return_receipt = FALSE;
3023 compose->to_list = NULL;
3024 compose->newsgroup_list = NULL;
3026 compose->exteditor_file = NULL;
3027 compose->exteditor_pid = -1;
3028 compose->exteditor_readdes = -1;
3029 compose->exteditor_tag = -1;
3031 compose_set_title(compose);
3034 if (account->protocol != A_NNTP) {
3035 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
3036 gtk_check_menu_item_set_active
3037 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3038 gtk_widget_set_sensitive(menuitem, FALSE);
3039 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3040 gtk_check_menu_item_set_active
3041 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3042 gtk_widget_set_sensitive(menuitem, FALSE);
3045 if (account->set_autocc && account->auto_cc) {
3046 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
3047 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3048 gtk_check_menu_item_set_active
3049 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3052 if (account->set_autobcc) {
3053 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
3054 gtk_check_menu_item_set_active
3055 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3056 if (account->auto_bcc)
3057 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
3060 if (account->set_autoreplyto) {
3061 menuitem = gtk_item_factory_get_item(ifactory,
3062 "/Message/Reply to");
3063 gtk_check_menu_item_set_active
3064 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3065 if (account->auto_replyto)
3066 gtk_entry_set_text(GTK_ENTRY(reply_entry),
3067 account->auto_replyto);
3070 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
3071 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3072 prefs_common.show_ruler);
3075 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
3076 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3077 prefs_common.default_sign);
3078 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
3079 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3080 prefs_common.default_encrypt);
3081 #endif /* USE_GPGME */
3083 addressbook_set_target_compose(compose);
3085 compose_list = g_list_append(compose_list, compose);
3088 compose->use_to = FALSE;
3089 compose->use_cc = FALSE;
3091 compose->use_attach = FALSE;
3093 compose->use_bcc = FALSE;
3094 compose->use_replyto = FALSE;
3095 compose->use_followupto = FALSE;
3096 gtk_widget_hide(bcc_hbox);
3097 gtk_widget_hide(bcc_entry);
3098 gtk_widget_hide(reply_hbox);
3099 gtk_widget_hide(reply_entry);
3100 gtk_widget_hide(followup_hbox);
3101 gtk_widget_hide(followup_entry);
3102 gtk_widget_hide(ruler_hbox);
3103 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
3104 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
3105 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
3108 select_account(compose, account);
3113 #include "pixmaps/stock_mail_send.xpm"
3114 #include "pixmaps/stock_mail.xpm"
3115 #include "pixmaps/stock_paste.xpm"
3116 #include "pixmaps/stock_mail_attach.xpm"
3117 #include "pixmaps/stock_mail_compose.xpm"
3118 #include "pixmaps/linewrap.xpm"
3119 //#include "pixmaps/tb_mail_queue_send.xpm"
3120 #include "pixmaps/tb_address_book.xpm"
3122 #define CREATE_TOOLBAR_ICON(xpm_d) \
3124 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
3125 &container->style->white, \
3127 icon_wid = gtk_pixmap_new(icon, mask); \
3130 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
3135 GtkWidget *icon_wid;
3136 GtkWidget *send_btn;
3137 GtkWidget *sendl_btn;
3138 GtkWidget *draft_btn;
3139 GtkWidget *insert_btn;
3140 GtkWidget *attach_btn;
3142 GtkWidget *exteditor_btn;
3143 GtkWidget *linewrap_btn;
3144 GtkWidget *addrbook_btn;
3146 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
3148 gtk_container_add(GTK_CONTAINER(container), toolbar);
3149 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
3150 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
3151 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
3152 GTK_TOOLBAR_SPACE_LINE);
3154 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
3155 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3159 icon_wid, toolbar_send_cb, compose);
3161 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
3162 //CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm);
3163 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3165 _("Put into queue folder and send later"),
3167 icon_wid, toolbar_send_later_cb,
3170 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3171 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3173 _("Save to draft folder"),
3175 icon_wid, toolbar_draft_cb,
3178 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3180 CREATE_TOOLBAR_ICON(stock_paste_xpm);
3181 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3185 icon_wid, toolbar_insert_cb,
3188 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
3189 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3193 icon_wid, toolbar_attach_cb,
3196 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3198 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3199 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3201 _("Insert signature"),
3203 icon_wid, toolbar_sig_cb, compose);
3205 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3207 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
3208 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3210 _("Edit with external editor"),
3213 toolbar_ext_editor_cb,
3216 CREATE_TOOLBAR_ICON(linewrap_xpm);
3217 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3219 _("Wrap long lines"),
3222 toolbar_linewrap_cb,
3225 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3227 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
3228 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3232 icon_wid, toolbar_address_cb,
3235 compose->toolbar = toolbar;
3236 compose->send_btn = send_btn;
3237 compose->sendl_btn = sendl_btn;
3238 compose->draft_btn = draft_btn;
3239 compose->insert_btn = insert_btn;
3240 compose->attach_btn = attach_btn;
3241 compose->sig_btn = sig_btn;
3242 compose->exteditor_btn = exteditor_btn;
3243 compose->linewrap_btn = linewrap_btn;
3244 compose->addrbook_btn = addrbook_btn;
3246 gtk_widget_show_all(toolbar);
3249 #undef CREATE_TOOLBAR_ICON
3251 static GtkWidget *compose_account_option_menu_create(Compose *compose)
3257 gint num = 0, def_menu = 0;
3259 accounts = account_get_list();
3260 g_return_val_if_fail(accounts != NULL, NULL);
3262 hbox = gtk_hbox_new(FALSE, 0);
3263 optmenu = gtk_option_menu_new();
3264 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3265 menu = gtk_menu_new();
3267 for (; accounts != NULL; accounts = accounts->next, num++) {
3268 PrefsAccount *ac = (PrefsAccount *)accounts->data;
3269 GtkWidget *menuitem;
3272 if (ac == compose->account) def_menu = num;
3274 name = g_strdup_printf("%s <%s> (%s)",
3275 ac->name, ac->address, ac->account_name);
3276 MENUITEM_ADD(menu, menuitem, name, ac);
3278 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
3279 GTK_SIGNAL_FUNC(account_activated),
3283 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
3284 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
3289 static void compose_destroy(Compose *compose)
3292 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3295 /* NOTE: address_completion_end() does nothing with the window
3296 * however this may change. */
3297 address_completion_end(compose->window);
3299 slist_free_strings(compose->to_list);
3300 g_slist_free(compose->to_list);
3301 slist_free_strings(compose->newsgroup_list);
3302 g_slist_free(compose->newsgroup_list);
3304 procmsg_msginfo_free(compose->targetinfo);
3306 g_free(compose->replyto);
3307 g_free(compose->cc);
3308 g_free(compose->bcc);
3309 g_free(compose->newsgroups);
3310 g_free(compose->followup_to);
3312 g_free(compose->inreplyto);
3313 g_free(compose->references);
3314 g_free(compose->msgid);
3315 g_free(compose->boundary);
3317 g_free(compose->exteditor_file);
3319 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3321 compose_attach_info_free(ainfo);
3323 if (addressbook_get_target_compose() == compose)
3324 addressbook_set_target_compose(NULL);
3326 prefs_common.compose_width = compose->scrolledwin->allocation.width;
3327 prefs_common.compose_height = compose->window->allocation.height;
3329 gtk_widget_destroy(compose->paned);
3333 compose_list = g_list_remove(compose_list, compose);
3336 static void compose_attach_info_free(AttachInfo *ainfo)
3338 g_free(ainfo->file);
3339 g_free(ainfo->content_type);
3340 g_free(ainfo->name);
3344 static void compose_attach_remove_selected(Compose *compose)
3346 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3350 while (clist->selection != NULL) {
3351 row = GPOINTER_TO_INT(clist->selection->data);
3352 ainfo = gtk_clist_get_row_data(clist, row);
3353 compose_attach_info_free(ainfo);
3354 gtk_clist_remove(clist, row);
3358 static struct _AttachProperty
3361 GtkWidget *mimetype_entry;
3362 GtkWidget *encoding_optmenu;
3363 GtkWidget *path_entry;
3364 GtkWidget *filename_entry;
3366 GtkWidget *cancel_btn;
3369 static void compose_attach_property(Compose *compose)
3371 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3375 GtkOptionMenu *optmenu;
3377 if (!clist->selection) return;
3378 row = GPOINTER_TO_INT(clist->selection->data);
3380 ainfo = gtk_clist_get_row_data(clist, row);
3383 if (!attach_prop.window)
3384 compose_attach_property_create(&cancelled);
3385 gtk_widget_grab_focus(attach_prop.ok_btn);
3386 gtk_widget_show(attach_prop.window);
3387 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
3389 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
3390 if (ainfo->encoding == ENC_UNKNOWN)
3391 gtk_option_menu_set_history(optmenu, ENC_BASE64);
3393 gtk_option_menu_set_history(optmenu, ainfo->encoding);
3395 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
3396 ainfo->content_type ? ainfo->content_type : "");
3397 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
3398 ainfo->file ? ainfo->file : "");
3399 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
3400 ainfo->name ? ainfo->name : "");
3404 gchar *cnttype = NULL;
3408 GtkWidget *menuitem;
3412 if (cancelled == TRUE) {
3413 gtk_widget_hide(attach_prop.window);
3417 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
3418 if (*text != '\0') {
3421 text = g_strstrip(g_strdup(text));
3422 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
3423 cnttype = g_strdup(text);
3426 alertpanel_error(_("Invalid MIME type."));
3432 menu = gtk_option_menu_get_menu(optmenu);
3433 menuitem = gtk_menu_get_active(GTK_MENU(menu));
3434 ainfo->encoding = GPOINTER_TO_INT
3435 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
3437 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
3438 if (*text != '\0') {
3439 if (is_file_exist(text) &&
3440 (size = get_file_size(text)) > 0)
3441 file = g_strdup(text);
3444 (_("File doesn't exist or is empty."));
3450 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
3451 if (*text != '\0') {
3452 g_free(ainfo->name);
3453 ainfo->name = g_strdup(text);
3457 g_free(ainfo->content_type);
3458 ainfo->content_type = cnttype;
3461 g_free(ainfo->file);
3467 gtk_clist_set_text(clist, row, COL_MIMETYPE,
3468 ainfo->content_type);
3469 gtk_clist_set_text(clist, row, COL_SIZE,
3470 to_human_readable(ainfo->size));
3471 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
3473 gtk_widget_hide(attach_prop.window);
3478 #define SET_LABEL_AND_ENTRY(str, entry, top) \
3480 label = gtk_label_new(str); \
3481 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
3482 GTK_FILL, 0, 0, 0); \
3483 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
3485 entry = gtk_entry_new(); \
3486 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
3487 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
3490 static void compose_attach_property_create(gboolean *cancelled)
3496 GtkWidget *mimetype_entry;
3499 GtkWidget *optmenu_menu;
3500 GtkWidget *menuitem;
3501 GtkWidget *path_entry;
3502 GtkWidget *filename_entry;
3505 GtkWidget *cancel_btn;
3507 debug_print("Creating attach_property window...\n");
3509 window = gtk_window_new(GTK_WINDOW_DIALOG);
3510 gtk_widget_set_usize(window, 480, -1);
3511 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
3512 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
3513 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
3514 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
3515 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3516 GTK_SIGNAL_FUNC(attach_property_delete_event),
3518 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
3519 GTK_SIGNAL_FUNC(attach_property_key_pressed),
3522 vbox = gtk_vbox_new(FALSE, 8);
3523 gtk_container_add(GTK_CONTAINER(window), vbox);
3525 table = gtk_table_new(4, 2, FALSE);
3526 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
3527 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
3528 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
3530 SET_LABEL_AND_ENTRY(_("MIME type"), mimetype_entry, 0);
3532 label = gtk_label_new(_("Encoding"));
3533 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
3535 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3537 hbox = gtk_hbox_new(FALSE, 0);
3538 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
3539 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3541 optmenu = gtk_option_menu_new();
3542 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3544 optmenu_menu = gtk_menu_new();
3545 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
3546 gtk_widget_set_sensitive(menuitem, FALSE);
3547 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
3548 gtk_widget_set_sensitive(menuitem, FALSE);
3549 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
3550 gtk_widget_set_sensitive(menuitem, FALSE);
3551 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
3553 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
3555 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
3556 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
3558 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
3559 &cancel_btn, _("Cancel"), NULL, NULL);
3560 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
3561 gtk_widget_grab_default(ok_btn);
3563 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
3564 GTK_SIGNAL_FUNC(attach_property_ok),
3566 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
3567 GTK_SIGNAL_FUNC(attach_property_cancel),
3570 gtk_widget_show_all(vbox);
3572 attach_prop.window = window;
3573 attach_prop.mimetype_entry = mimetype_entry;
3574 attach_prop.encoding_optmenu = optmenu;
3575 attach_prop.path_entry = path_entry;
3576 attach_prop.filename_entry = filename_entry;
3577 attach_prop.ok_btn = ok_btn;
3578 attach_prop.cancel_btn = cancel_btn;
3581 #undef SET_LABEL_AND_ENTRY
3583 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
3589 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
3595 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
3596 gboolean *cancelled)
3604 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
3605 gboolean *cancelled)
3607 if (event && event->keyval == GDK_Escape) {
3613 static void compose_exec_ext_editor(Compose *compose)
3619 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
3620 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3622 if (pipe(pipe_fds) < 0) {
3627 if ((pid = fork()) < 0) {
3633 /* close the write side of the pipe */
3636 compose->exteditor_file = g_strdup(tmp);
3637 compose->exteditor_pid = pid;
3638 compose->exteditor_readdes = pipe_fds[0];
3640 compose_set_ext_editor_sensitive(compose, FALSE);
3642 compose->exteditor_tag =
3643 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
3644 compose_input_cb, compose);
3645 } else { /* process-monitoring process */
3651 /* close the read side of the pipe */
3654 if (compose_write_body_to_file(compose, tmp) < 0) {
3655 fd_write(pipe_fds[1], "2\n", 2);
3659 pid_ed = compose_exec_ext_editor_real(tmp);
3661 fd_write(pipe_fds[1], "1\n", 2);
3665 /* wait until editor is terminated */
3666 waitpid(pid_ed, NULL, 0);
3668 fd_write(pipe_fds[1], "0\n", 2);
3675 static gint compose_exec_ext_editor_real(const gchar *file)
3677 static gchar *def_cmd = "emacs %s";
3683 g_return_val_if_fail(file != NULL, -1);
3685 if ((pid = fork()) < 0) {
3690 if (pid != 0) return pid;
3692 /* grandchild process */
3694 if (setpgid(0, getppid()))
3697 if (prefs_common.ext_editor_cmd &&
3698 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
3699 *(p + 1) == 's' && !strchr(p + 2, '%')) {
3700 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
3702 if (prefs_common.ext_editor_cmd)
3703 g_warning(_("External editor command line is invalid: `%s'\n"),
3704 prefs_common.ext_editor_cmd);
3705 g_snprintf(buf, sizeof(buf), def_cmd, file);
3708 cmdline = g_strsplit(buf, " ", 1024);
3709 execvp(cmdline[0], cmdline);
3712 g_strfreev(cmdline);
3717 static gboolean compose_ext_editor_kill(Compose *compose)
3719 pid_t pgid = compose->exteditor_pid * -1;
3722 ret = kill(pgid, 0);
3724 if (ret == 0 || (ret == -1 && EPERM == errno)) {
3728 msg = g_strdup_printf
3729 (_("The external editor is still working.\n"
3730 "Force terminating the process?\n"
3731 "process group id: %d"), -pgid);
3732 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
3735 if (val == G_ALERTDEFAULT) {
3736 gdk_input_remove(compose->exteditor_tag);
3737 close(compose->exteditor_readdes);
3739 if (kill(pgid, SIGTERM) < 0) perror("kill");
3740 waitpid(compose->exteditor_pid, NULL, 0);
3742 g_warning(_("Terminated process group id: %d"), -pgid);
3743 g_warning(_("Temporary file: %s"),
3744 compose->exteditor_file);
3746 compose_set_ext_editor_sensitive(compose, TRUE);
3748 g_free(compose->exteditor_file);
3749 compose->exteditor_file = NULL;
3750 compose->exteditor_pid = -1;
3751 compose->exteditor_readdes = -1;
3752 compose->exteditor_tag = -1;
3760 static void compose_input_cb(gpointer data, gint source,
3761 GdkInputCondition condition)
3764 Compose *compose = (Compose *)data;
3767 debug_print(_("Compose: input from monitoring process\n"));
3769 gdk_input_remove(compose->exteditor_tag);
3772 if (read(source, &buf[i], 1) < 1) {
3776 if (buf[i] == '\n') {
3781 if (i == sizeof(buf) - 1)
3785 waitpid(compose->exteditor_pid, NULL, 0);
3787 if (buf[0] == '0') { /* success */
3788 GtkSText *text = GTK_STEXT(compose->text);
3790 gtk_stext_freeze(text);
3791 gtk_stext_set_point(text, 0);
3792 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
3793 compose_insert_file(compose, compose->exteditor_file);
3794 compose_changed_cb(NULL, compose);
3795 gtk_stext_thaw(text);
3797 if (unlink(compose->exteditor_file) < 0)
3798 FILE_OP_ERROR(compose->exteditor_file, "unlink");
3799 } else if (buf[0] == '1') { /* failed */
3800 g_warning(_("Couldn't exec external editor\n"));
3801 if (unlink(compose->exteditor_file) < 0)
3802 FILE_OP_ERROR(compose->exteditor_file, "unlink");
3803 } else if (buf[0] == '2') {
3804 g_warning(_("Couldn't write to file\n"));
3805 } else if (buf[0] == '3') {
3806 g_warning(_("Pipe read failed\n"));
3811 compose_set_ext_editor_sensitive(compose, TRUE);
3813 g_free(compose->exteditor_file);
3814 compose->exteditor_file = NULL;
3815 compose->exteditor_pid = -1;
3816 compose->exteditor_readdes = -1;
3817 compose->exteditor_tag = -1;
3820 static void compose_set_ext_editor_sensitive(Compose *compose,
3823 GtkItemFactory *ifactory;
3825 ifactory = gtk_item_factory_from_widget(compose->menubar);
3827 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
3828 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
3829 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
3831 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
3832 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
3833 menu_set_sensitive(ifactory, "/Edit/Wrap long lines", sensitive);
3834 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
3837 gtk_widget_set_sensitive(compose->text, sensitive);
3838 gtk_widget_set_sensitive(compose->send_btn, sensitive);
3839 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
3840 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
3841 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
3842 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
3843 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
3844 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
3847 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
3851 cursor_pos = (text->cursor_pos_x - extra) / char_width;
3852 cursor_pos = MAX(cursor_pos, 0);
3857 /* callback functions */
3859 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
3860 * includes "non-client" (windows-izm) in calculation, so this calculation
3861 * may not be accurate.
3863 static gboolean compose_edit_size_alloc(GtkEditable *widget,
3864 GtkAllocation *allocation,
3865 GtkSHRuler *shruler)
3867 if (prefs_common.show_ruler) {
3869 gint line_width_in_chars;
3871 char_width = gtkut_get_font_width
3872 (GTK_WIDGET(widget)->style->font);
3873 line_width_in_chars =
3874 (allocation->width - allocation->x) / char_width;
3876 /* got the maximum */
3877 gtk_ruler_set_range(GTK_RULER(shruler),
3878 0.0, line_width_in_chars,
3879 calc_cursor_xpos(GTK_STEXT(widget),
3882 /*line_width_in_chars*/ char_width);
3888 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
3890 compose_send_cb(data, 0, NULL);
3893 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
3895 compose_send_later_cb(data, 0, NULL);
3898 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
3900 compose_draft_cb(data, 0, NULL);
3903 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
3905 compose_insert_file_cb(data, 0, NULL);
3908 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
3910 compose_attach_cb(data, 0, NULL);
3913 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
3915 Compose *compose = (Compose *)data;
3917 compose_insert_sig(compose);
3920 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
3922 Compose *compose = (Compose *)data;
3924 compose_exec_ext_editor(compose);
3927 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
3929 Compose *compose = (Compose *)data;
3931 compose_wrap_line(compose);
3934 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
3936 compose_address_cb(data, 0, NULL);
3939 static void select_account(Compose * compose, PrefsAccount * ac)
3941 compose->account = ac;
3942 compose_set_title(compose);
3944 if (ac->protocol == A_NNTP) {
3945 GtkItemFactory *ifactory;
3946 GtkWidget *menuitem;
3948 ifactory = gtk_item_factory_from_widget(compose->menubar);
3949 menu_set_sensitive(ifactory,
3950 "/Message/Followup to", TRUE);
3952 gtk_widget_show(compose->newsgroups_hbox);
3953 gtk_widget_show(compose->newsgroups_entry);
3954 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
3957 compose->use_to = FALSE;
3958 compose->use_cc = FALSE;
3960 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
3961 gtk_check_menu_item_set_active
3962 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
3963 menu_set_sensitive(ifactory,
3964 "/Message/To", TRUE);
3965 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3966 gtk_check_menu_item_set_active
3967 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
3969 gtk_widget_hide(compose->to_hbox);
3970 gtk_widget_hide(compose->to_entry);
3971 gtk_widget_hide(compose->cc_hbox);
3972 gtk_widget_hide(compose->cc_entry);
3974 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
3976 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
3980 GtkItemFactory *ifactory;
3981 GtkWidget *menuitem;
3983 ifactory = gtk_item_factory_from_widget(compose->menubar);
3984 menu_set_sensitive(ifactory,
3985 "/Message/Followup to", FALSE);
3987 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
3988 gtk_widget_hide(compose->newsgroups_hbox);
3989 gtk_widget_hide(compose->newsgroups_entry);
3990 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
3993 compose->use_to = TRUE;
3994 compose->use_cc = TRUE;
3996 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
3997 gtk_check_menu_item_set_active
3998 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3999 menu_set_sensitive(ifactory,
4000 "/Message/To", FALSE);
4001 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4002 gtk_check_menu_item_set_active
4003 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4005 gtk_widget_show(compose->to_hbox);
4006 gtk_widget_show(compose->to_entry);
4007 gtk_widget_show(compose->cc_hbox);
4008 gtk_widget_show(compose->cc_entry);
4010 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4012 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4015 gtk_widget_queue_resize(compose->table_vbox);
4018 static void account_activated(GtkMenuItem *menuitem, gpointer data)
4020 Compose *compose = (Compose *)data;
4024 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
4025 g_return_if_fail(ac != NULL);
4027 if (ac != compose->account)
4028 select_account(compose, ac);
4031 static void attach_selected(GtkCList *clist, gint row, gint column,
4032 GdkEvent *event, gpointer data)
4034 Compose *compose = (Compose *)data;
4036 if (event && event->type == GDK_2BUTTON_PRESS)
4037 compose_attach_property(compose);
4040 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
4043 Compose *compose = (Compose *)data;
4044 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4049 if (event->button == 3) {
4050 if ((clist->selection && !clist->selection->next) ||
4051 !clist->selection) {
4052 gtk_clist_unselect_all(clist);
4053 if (gtk_clist_get_selection_info(clist,
4056 gtk_clist_select_row(clist, row, column);
4057 gtkut_clist_set_focus_row(clist, row);
4060 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
4061 NULL, NULL, event->button, event->time);
4065 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
4068 Compose *compose = (Compose *)data;
4072 switch (event->keyval) {
4074 compose_attach_remove_selected(compose);
4079 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
4081 Compose *compose = (Compose *)data;
4084 val = compose_send(compose);
4086 if (val == 0) gtk_widget_destroy(compose->window);
4089 static void compose_send_later_cb(gpointer data, guint action,
4092 Compose *compose = (Compose *)data;
4094 gchar *to, *newsgroups;
4096 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
4097 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
4098 if (*to == '\0' && *newsgroups == '\0') {
4099 alertpanel_error(_("Recipient is not specified."));
4103 g_snprintf(tmp, 22, "%s%ctmpmsg%d",
4104 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
4106 if (prefs_common.linewrap_at_send)
4107 compose_wrap_line(compose);
4109 if (compose_write_to_file(compose, tmp, FALSE) < 0 ||
4110 compose_queue(compose, tmp) < 0) {
4111 alertpanel_error(_("Can't queue the message."));
4115 if (prefs_common.savemsg) {
4116 if (compose_save_to_outbox(compose, tmp) < 0)
4118 (_("Can't save the message to outbox."));
4121 if (unlink(tmp) < 0)
4122 FILE_OP_ERROR(tmp, "unlink");
4124 gtk_widget_destroy(compose->window);
4127 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
4129 Compose *compose = (Compose *)data;
4133 draft = folder_get_default_draft();
4134 folder_item_scan(draft);
4136 if (procmsg_msg_exist(compose->targetinfo) &&
4137 compose->targetinfo->folder == draft) {
4138 if (folder_item_remove_msg(draft,
4139 compose->targetinfo->msgnum) < 0)
4140 g_warning(_("can't remove the old draft message\n"));
4142 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
4143 G_DIR_SEPARATOR, (gint)compose);
4145 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
4150 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
4158 //folderview_scan_folder_a(DRAFT_DIR, TRUE);
4160 gtk_widget_destroy(compose->window);
4163 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
4165 Compose *compose = (Compose *)data;
4168 file = filesel_select_file(_("Select file"), NULL);
4171 compose_attach_append(compose, file, MIME_UNKNOWN);
4174 static void compose_insert_file_cb(gpointer data, guint action,
4177 Compose *compose = (Compose *)data;
4180 file = filesel_select_file(_("Select file"), NULL);
4183 compose_insert_file(compose, file);
4186 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
4189 compose_close_cb(data, 0, NULL);
4193 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
4195 Compose *compose = (Compose *)data;
4198 if (compose->exteditor_tag != -1) {
4199 if (!compose_ext_editor_kill(compose))
4203 if (compose->modified) {
4204 val = alertpanel(_("Discard message"),
4205 _("This message has been modified. discard it?"),
4206 _("Discard"), _("to Draft"), _("Cancel"));
4209 case G_ALERTDEFAULT:
4211 case G_ALERTALTERNATE:
4212 compose_draft_cb(data, 0, NULL);
4219 gtk_widget_destroy(compose->window);
4222 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
4224 Compose *compose = (Compose *)data;
4226 addressbook_open(compose);
4229 static void compose_ext_editor_cb(gpointer data, guint action,
4232 Compose *compose = (Compose *)data;
4234 compose_exec_ext_editor(compose);
4237 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
4239 compose_destroy(compose);
4242 static void compose_cut_cb(Compose *compose)
4244 if (compose->focused_editable &&
4245 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4246 gtk_editable_cut_clipboard
4247 (GTK_EDITABLE(compose->focused_editable));
4250 static void compose_copy_cb(Compose *compose)
4252 if (compose->focused_editable &&
4253 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4254 gtk_editable_copy_clipboard
4255 (GTK_EDITABLE(compose->focused_editable));
4258 static void compose_paste_cb(Compose *compose)
4260 if (compose->focused_editable &&
4261 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4262 gtk_editable_paste_clipboard
4263 (GTK_EDITABLE(compose->focused_editable));
4266 static void compose_allsel_cb(Compose *compose)
4268 if (compose->focused_editable &&
4269 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4270 gtk_editable_select_region
4271 (GTK_EDITABLE(compose->focused_editable), 0, -1);
4274 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
4276 if (GTK_IS_EDITABLE(widget))
4277 compose->focused_editable = widget;
4280 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
4282 if (compose->modified == FALSE) {
4283 compose->modified = TRUE;
4284 compose_set_title(compose);
4288 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
4291 gtk_stext_set_point(GTK_STEXT(widget),
4292 gtk_editable_get_position(GTK_EDITABLE(widget)));
4296 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
4299 gtk_stext_set_point(GTK_STEXT(widget),
4300 gtk_editable_get_position(GTK_EDITABLE(widget)));
4304 static void compose_toggle_to_cb(gpointer data, guint action,
4307 Compose *compose = (Compose *)data;
4309 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4310 gtk_widget_show(compose->to_hbox);
4311 gtk_widget_show(compose->to_entry);
4312 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
4313 compose->use_to = TRUE;
4315 gtk_widget_hide(compose->to_hbox);
4316 gtk_widget_hide(compose->to_entry);
4317 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
4318 gtk_widget_queue_resize(compose->table_vbox);
4319 compose->use_to = FALSE;
4322 if (addressbook_get_target_compose() == compose)
4323 addressbook_set_target_compose(compose);
4326 static void compose_toggle_cc_cb(gpointer data, guint action,
4329 Compose *compose = (Compose *)data;
4331 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4332 gtk_widget_show(compose->cc_hbox);
4333 gtk_widget_show(compose->cc_entry);
4334 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
4335 compose->use_cc = TRUE;
4337 gtk_widget_hide(compose->cc_hbox);
4338 gtk_widget_hide(compose->cc_entry);
4339 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
4340 gtk_widget_queue_resize(compose->table_vbox);
4341 compose->use_cc = FALSE;
4344 if (addressbook_get_target_compose() == compose)
4345 addressbook_set_target_compose(compose);
4348 static void compose_toggle_bcc_cb(gpointer data, guint action,
4351 Compose *compose = (Compose *)data;
4353 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4354 gtk_widget_show(compose->bcc_hbox);
4355 gtk_widget_show(compose->bcc_entry);
4356 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
4357 compose->use_bcc = TRUE;
4359 gtk_widget_hide(compose->bcc_hbox);
4360 gtk_widget_hide(compose->bcc_entry);
4361 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
4362 gtk_widget_queue_resize(compose->table_vbox);
4363 compose->use_bcc = FALSE;
4366 if (addressbook_get_target_compose() == compose)
4367 addressbook_set_target_compose(compose);
4370 static void compose_toggle_replyto_cb(gpointer data, guint action,
4373 Compose *compose = (Compose *)data;
4375 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4376 gtk_widget_show(compose->reply_hbox);
4377 gtk_widget_show(compose->reply_entry);
4378 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
4379 compose->use_replyto = TRUE;
4381 gtk_widget_hide(compose->reply_hbox);
4382 gtk_widget_hide(compose->reply_entry);
4383 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
4384 gtk_widget_queue_resize(compose->table_vbox);
4385 compose->use_replyto = FALSE;
4389 static void compose_toggle_followupto_cb(gpointer data, guint action,
4392 Compose *compose = (Compose *)data;
4394 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4395 gtk_widget_show(compose->followup_hbox);
4396 gtk_widget_show(compose->followup_entry);
4397 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
4398 compose->use_followupto = TRUE;
4400 gtk_widget_hide(compose->followup_hbox);
4401 gtk_widget_hide(compose->followup_entry);
4402 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
4403 gtk_widget_queue_resize(compose->table_vbox);
4404 compose->use_followupto = FALSE;
4408 static void compose_toggle_attach_cb(gpointer data, guint action,
4411 Compose *compose = (Compose *)data;
4413 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4414 gtk_widget_ref(compose->edit_vbox);
4416 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4417 compose->edit_vbox);
4418 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
4419 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
4421 gtk_widget_show(compose->paned);
4423 gtk_widget_unref(compose->edit_vbox);
4424 gtk_widget_unref(compose->paned);
4426 compose->use_attach = TRUE;
4428 gtk_widget_ref(compose->paned);
4429 gtk_widget_ref(compose->edit_vbox);
4431 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4433 gtk_container_remove(GTK_CONTAINER(compose->paned),
4434 compose->edit_vbox);
4435 gtk_box_pack_start(GTK_BOX(compose->vbox2),
4436 compose->edit_vbox, TRUE, TRUE, 0);
4438 gtk_widget_unref(compose->edit_vbox);
4440 compose->use_attach = FALSE;
4445 static void compose_toggle_sign_cb(gpointer data, guint action,
4448 Compose *compose = (Compose *)data;
4450 if (GTK_CHECK_MENU_ITEM(widget)->active)
4451 compose->use_signing = TRUE;
4453 compose->use_signing = FALSE;
4456 static void compose_toggle_encrypt_cb(gpointer data, guint action,
4459 Compose *compose = (Compose *)data;
4461 if (GTK_CHECK_MENU_ITEM(widget)->active)
4462 compose->use_encryption = TRUE;
4464 compose->use_encryption = FALSE;
4466 #endif /* USE_GPGME */
4468 static void compose_toggle_ruler_cb(gpointer data, guint action,
4471 Compose *compose = (Compose *)data;
4473 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4474 gtk_widget_show(compose->ruler_hbox);
4475 prefs_common.show_ruler = TRUE;
4477 gtk_widget_hide(compose->ruler_hbox);
4478 gtk_widget_queue_resize(compose->edit_vbox);
4479 prefs_common.show_ruler = FALSE;
4483 static void compose_attach_drag_received_cb (GtkWidget *widget,
4484 GdkDragContext *drag_context,
4487 GtkSelectionData *data,
4492 Compose *compose = (Compose *)user_data;
4495 list = uri_list_extract_filenames((const gchar *)data->data);
4496 for (tmp = list; tmp != NULL; tmp = tmp->next)
4497 compose_attach_append(compose, (const gchar *)tmp->data,
4499 list_free_strings(list);
4503 static void compose_insert_drag_received_cb (GtkWidget *widget,
4504 GdkDragContext *drag_context,
4507 GtkSelectionData *data,
4512 Compose *compose = (Compose *)user_data;
4515 list = uri_list_extract_filenames((const gchar *)data->data);
4516 for (tmp = list; tmp != NULL; tmp = tmp->next)
4517 compose_insert_file(compose, (const gchar *)tmp->data);
4518 list_free_strings(list);
4522 static void to_activated(GtkWidget *widget, Compose *compose)
4524 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
4525 gtk_widget_grab_focus(compose->newsgroups_entry);
4527 gtk_widget_grab_focus(compose->subject_entry);
4530 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
4532 gtk_widget_grab_focus(compose->subject_entry);
4535 static void subject_activated(GtkWidget *widget, Compose *compose)
4537 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
4538 gtk_widget_grab_focus(compose->cc_entry);
4539 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4540 gtk_widget_grab_focus(compose->bcc_entry);
4541 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4542 gtk_widget_grab_focus(compose->reply_entry);
4543 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4544 gtk_widget_grab_focus(compose->followup_entry);
4546 gtk_widget_grab_focus(compose->text);
4549 static void cc_activated(GtkWidget *widget, Compose *compose)
4551 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4552 gtk_widget_grab_focus(compose->bcc_entry);
4553 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4554 gtk_widget_grab_focus(compose->reply_entry);
4555 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4556 gtk_widget_grab_focus(compose->followup_entry);
4558 gtk_widget_grab_focus(compose->text);
4561 static void bcc_activated(GtkWidget *widget, Compose *compose)
4563 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4564 gtk_widget_grab_focus(compose->reply_entry);
4565 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4566 gtk_widget_grab_focus(compose->followup_entry);
4568 gtk_widget_grab_focus(compose->text);
4571 static void replyto_activated(GtkWidget *widget, Compose *compose)
4573 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4574 gtk_widget_grab_focus(compose->followup_entry);
4576 gtk_widget_grab_focus(compose->text);
4579 static void followupto_activated(GtkWidget *widget, Compose *compose)
4581 gtk_widget_grab_focus(compose->text);
4584 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
4587 Compose *compose = (Compose *)data;
4589 if (GTK_CHECK_MENU_ITEM(widget)->active)
4590 compose->return_receipt = TRUE;
4592 compose->return_receipt = FALSE;
4595 static gchar *compose_quote_fmt (Compose *compose,
4600 gchar * quote_str = NULL;
4602 if (qmark != NULL) {
4605 quote_fmt_init(msginfo, NULL);
4606 quote_fmt_scan_string(qmark);
4609 p = quote_fmt_get_buffer();
4612 (_("Quote mark format error."));
4615 quote_str = alloca(strlen(p) + 1);
4616 strcpy(quote_str, p);
4620 quote_fmt_init(msginfo, quote_str);
4621 quote_fmt_scan_string(fmt);
4624 if (quote_fmt_get_buffer() == NULL)
4626 (_("Message reply/forward format error."));
4628 return quote_fmt_get_buffer();