2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999,2000 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
31 #include <gtk/gtkitemfactory.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkclist.h>
36 #include <gtk/gtkctree.h>
37 #include <gtk/gtkvpaned.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkeditable.h>
40 #include <gtk/gtkwindow.h>
41 #include <gtk/gtksignal.h>
42 #include <gtk/gtkvbox.h>
43 #include <gtk/gtkcontainer.h>
44 #include <gtk/gtkhandlebox.h>
45 #include <gtk/gtktoolbar.h>
46 #include <gtk/gtktable.h>
47 #include <gtk/gtkhbox.h>
48 #include <gtk/gtklabel.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtkthemes.h>
51 #include <gtk/gtkdnd.h>
58 /* #include <sys/utsname.h> */
64 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
74 #include "mainwindow.h"
76 #include "addressbook.h"
77 #include "folderview.h"
82 #include "customheader.h"
83 #include "prefs_common.h"
84 #include "prefs_account.h"
87 #include "procheader.h"
89 #include "statusbar.h"
96 #include "alertpanel.h"
97 #include "manage_window.h"
98 #include "gtkshruler.h"
100 #include "addr_compl.h"
103 # include "rfc2015.h"
113 #define N_ATTACH_COLS 3
115 #define B64_LINE_SIZE 57
116 #define B64_BUFFSIZE 77
118 #define MAX_REFERENCES_LEN 999
120 static GdkColor quote_color = {0, 0, 0, 0xbfff};
122 static GList *compose_list = NULL;
124 static Compose *compose_create (PrefsAccount *account);
125 static void compose_toolbar_create (Compose *compose,
126 GtkWidget *container);
127 static GtkWidget *compose_account_option_menu_create
129 static void compose_destroy (Compose *compose);
131 static gint compose_parse_header (Compose *compose,
133 static gchar *compose_parse_references (const gchar *ref,
135 static void compose_quote_file (Compose *compose,
138 static gchar *compose_quote_parse_fmt (Compose *compose,
141 static void compose_reply_set_entry (Compose *compose,
145 static void compose_reedit_set_entry (Compose *compose,
147 static void compose_insert_sig (Compose *compose);
148 static void compose_insert_file (Compose *compose,
150 static void compose_attach_append (Compose *compose,
152 ContentType cnttype);
153 static void compose_wrap_line (Compose *compose);
154 static void compose_set_title (Compose *compose);
156 static PrefsAccount *compose_current_mail_account(void);
157 /* static gint compose_send (Compose *compose); */
158 static gint compose_write_to_file (Compose *compose,
161 static gint compose_write_body_to_file (Compose *compose,
163 static gint compose_save_to_outbox (Compose *compose,
165 static gint compose_queue (Compose *compose,
167 static void compose_write_attach (Compose *compose,
169 static gint compose_write_headers (Compose *compose,
171 const gchar *charset,
172 EncodingType encoding,
175 static void compose_convert_header (gchar *dest,
179 static void compose_generate_msgid (Compose *compose,
183 static void compose_attach_info_free (AttachInfo *ainfo);
184 static void compose_attach_remove_selected (Compose *compose);
186 static void compose_attach_property (Compose *compose);
187 static void compose_attach_property_create (gboolean *cancelled);
188 static void attach_property_ok (GtkWidget *widget,
189 gboolean *cancelled);
190 static void attach_property_cancel (GtkWidget *widget,
191 gboolean *cancelled);
192 static gint attach_property_delete_event (GtkWidget *widget,
194 gboolean *cancelled);
195 static void attach_property_key_pressed (GtkWidget *widget,
197 gboolean *cancelled);
199 static void compose_exec_ext_editor (Compose *compose);
200 static gint compose_exec_ext_editor_real (const gchar *file);
201 static gboolean compose_ext_editor_kill (Compose *compose);
202 static void compose_input_cb (gpointer data,
204 GdkInputCondition condition);
205 static void compose_set_ext_editor_sensitive (Compose *compose,
208 static gint calc_cursor_xpos (GtkSText *text,
212 /* callback functions */
214 static gboolean compose_edit_size_alloc (GtkEditable *widget,
215 GtkAllocation *allocation,
216 GtkSHRuler *shruler);
218 static void toolbar_send_cb (GtkWidget *widget,
220 static void toolbar_send_later_cb (GtkWidget *widget,
222 static void toolbar_draft_cb (GtkWidget *widget,
224 static void toolbar_insert_cb (GtkWidget *widget,
226 static void toolbar_attach_cb (GtkWidget *widget,
228 static void toolbar_sig_cb (GtkWidget *widget,
230 static void toolbar_ext_editor_cb (GtkWidget *widget,
232 static void toolbar_linewrap_cb (GtkWidget *widget,
234 static void toolbar_address_cb (GtkWidget *widget,
237 static void account_activated (GtkMenuItem *menuitem,
240 static void attach_selected (GtkCList *clist,
245 static void attach_button_pressed (GtkWidget *widget,
246 GdkEventButton *event,
248 static void attach_key_pressed (GtkWidget *widget,
252 static void compose_send_cb (gpointer data,
255 static void compose_send_later_cb (gpointer data,
259 static void compose_draft_cb (gpointer data,
263 static void compose_attach_cb (gpointer data,
266 static void compose_insert_file_cb (gpointer data,
270 static void compose_close_cb (gpointer data,
273 static void compose_address_cb (gpointer data,
277 static void compose_ext_editor_cb (gpointer data,
281 static gint compose_delete_cb (GtkWidget *widget,
284 static void compose_destroy_cb (GtkWidget *widget,
287 static void compose_cut_cb (Compose *compose);
288 static void compose_copy_cb (Compose *compose);
289 static void compose_paste_cb (Compose *compose);
290 static void compose_allsel_cb (Compose *compose);
292 static void compose_grab_focus_cb (GtkWidget *widget,
295 static void compose_changed_cb (GtkEditable *editable,
297 static void compose_button_press_cb (GtkWidget *widget,
298 GdkEventButton *event,
301 static void compose_key_press_cb (GtkWidget *widget,
306 static void compose_toggle_to_cb (gpointer data,
309 static void compose_toggle_cc_cb (gpointer data,
312 static void compose_toggle_bcc_cb (gpointer data,
315 static void compose_toggle_replyto_cb (gpointer data,
318 static void compose_toggle_followupto_cb(gpointer data,
321 static void compose_toggle_attach_cb (gpointer data,
324 static void compose_toggle_ruler_cb (gpointer data,
328 static void compose_toggle_sign_cb (gpointer data,
331 static void compose_toggle_encrypt_cb (gpointer data,
335 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
338 static void compose_attach_drag_received_cb (GtkWidget *widget,
339 GdkDragContext *drag_context,
342 GtkSelectionData *data,
346 static void compose_insert_drag_received_cb (GtkWidget *widget,
347 GdkDragContext *drag_context,
350 GtkSelectionData *data,
355 static void to_activated (GtkWidget *widget,
357 static void newsgroups_activated (GtkWidget *widget,
359 static void subject_activated (GtkWidget *widget,
361 static void cc_activated (GtkWidget *widget,
363 static void bcc_activated (GtkWidget *widget,
365 static void replyto_activated (GtkWidget *widget,
367 static void followupto_activated (GtkWidget *widget,
369 static void compose_attach_parts(Compose * compose,
372 static GtkItemFactoryEntry compose_popup_entries[] =
374 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
375 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
376 {N_("/---"), NULL, NULL, 0, "<Separator>"},
377 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
380 static GtkItemFactoryEntry compose_entries[] =
382 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
383 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
384 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
385 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
386 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
387 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
389 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
390 {N_("/_Edit/_Undo"), "<control>Z", NULL, 0, NULL},
391 {N_("/_Edit/_Redo"), "<control>Y", NULL, 0, NULL},
392 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
393 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
394 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
395 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
396 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
397 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
398 {N_("/_Edit/Wrap long _lines"), "<alt>L", compose_wrap_line, 0, NULL},
399 {N_("/_Edit/Edit with e_xternal editor"), "<alt>X",
400 compose_ext_editor_cb, 0, NULL},
402 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
403 {N_("/_Message/_Send"), "<shift><control>S",
404 compose_send_cb, 0, NULL},
405 {N_("/_Message/Send _later"), "<shift><alt>S",
406 compose_send_later_cb, 0, NULL},
407 {N_("/_Message/Save to _draft folder"),
408 "<alt>D", compose_draft_cb, 0, NULL},
409 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
410 {N_("/_Message/_To"), NULL, compose_toggle_to_cb, 0, "<ToggleItem>"},
411 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb, 0, "<ToggleItem>"},
412 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb, 0, "<ToggleItem>"},
413 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
414 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
415 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
416 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
417 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
419 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
420 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb, 0, "<ToggleItem>"},
421 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
422 #endif /* USE_GPGME */
423 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
424 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
425 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
426 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
427 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb, 0, NULL},
428 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
429 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
432 static GtkTargetEntry compose_mime_types[] =
434 {"text/uri-list", 0, 0}
437 Compose * compose_new(PrefsAccount *account)
439 return compose_new_with_recipient(account, NULL);
442 Compose * compose_new_with_recipient(PrefsAccount *account, const gchar *to)
446 if (!account) account = cur_account;
447 g_return_val_if_fail(account != NULL, NULL);
449 compose = compose_create(account);
450 compose->mode = COMPOSE_NEW;
452 if (prefs_common.auto_sig)
453 compose_insert_sig(compose);
454 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
455 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
457 if (account->protocol != A_NNTP) {
459 compose_entry_append(compose, to, COMPOSE_TO);
460 gtk_widget_grab_focus(compose->subject_entry);
462 gtk_widget_grab_focus(compose->to_entry);
464 gtk_widget_grab_focus(compose->newsgroups_entry);
469 #define CHANGE_FLAGS(msginfo) \
471 if (msginfo->folder->folder->change_flags != NULL) \
472 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
477 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
481 PrefsAccount *account;
482 PrefsAccount *reply_account;
485 g_return_if_fail(msginfo != NULL);
486 g_return_if_fail(msginfo->folder != NULL);
488 account = msginfo->folder->folder->account;
489 if (!account) account = cur_account;
490 g_return_if_fail(account != NULL);
492 if (to_author && account->protocol == A_NNTP) {
494 account_find_mail_from_address(account->address);
496 reply_account = compose_current_mail_account();
500 reply_account = account;
502 MSG_UNSET_FLAGS(msginfo->flags, MSG_FORWARDED);
503 MSG_SET_FLAGS(msginfo->flags, MSG_REPLIED);
505 CHANGE_FLAGS(msginfo);
507 compose = compose_create(reply_account);
508 compose->mode = COMPOSE_REPLY;
510 if (compose_parse_header(compose, msginfo) < 0) return;
511 compose_reply_set_entry(compose, msginfo, to_all, to_author);
513 text = GTK_STEXT(compose->text);
514 gtk_stext_freeze(text);
520 if ((fp = procmime_get_text_part(msginfo)) == NULL)
521 g_warning(_("Can't get text part\n"));
523 quote_str = compose_quote_parse_fmt
524 (compose, msginfo, prefs_common.quotefmt);
525 gtk_stext_insert(text, NULL, NULL, NULL, quote_str, -1);
527 compose_quote_file(compose, msginfo, fp);
532 if (prefs_common.auto_sig)
533 compose_insert_sig(compose);
534 gtk_editable_set_position(GTK_EDITABLE(text), 0);
535 gtk_stext_set_point(text, 0);
537 gtk_stext_thaw(text);
538 gtk_widget_grab_focus(compose->text);
542 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
547 g_return_val_if_fail(mimeinfo != NULL, NULL);
549 base = mimeinfo->filename ? mimeinfo->filename
550 : mimeinfo->name ? mimeinfo->name : NULL;
552 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL)
553 base = "mimetmp.html";
555 base = base ? base : "mimetmp";
556 base = g_basename(base);
557 if (*base == '\0') base = "mimetmp";
560 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
566 static gchar * mime_extract_file(gchar * source, MimeInfo *partinfo)
570 if (!partinfo) return;
572 filename = procmime_get_file_name(partinfo);
574 if (procmime_get_part(filename, source, partinfo) < 0)
576 (_("Can't get the part of multipart message."));
581 static void compose_attach_parts(Compose * compose,
591 gint boundary_len = 0;
593 glong fpos, prev_fpos;
598 g_return_if_fail(msginfo != NULL);
602 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
603 mimeinfo = procmime_scan_mime_header(fp);
604 if (!mimeinfo) break;
606 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
607 rfc2015_is_encrypted(mimeinfo)) {
608 MSG_SET_FLAGS(msginfo->flags, MSG_ENCRYPTED);
610 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
611 !msginfo->plaintext_file &&
612 !msginfo->decryption_failed) {
613 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
614 if (msginfo->plaintext_file &&
615 !msginfo->decryption_failed) {
623 #else /* !USE_GPGME */
624 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
625 mimeinfo = procmime_scan_mime_header(fp);
626 #endif /* USE_GPGME */
629 if (!mimeinfo) return;
631 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
633 g_return_if_fail(mimeinfo != NULL);
634 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
636 if (mimeinfo->mime_type == MIME_MULTIPART) {
637 g_return_if_fail(mimeinfo->boundary != NULL);
638 g_return_if_fail(mimeinfo->sub == NULL);
640 g_return_if_fail(fp != NULL);
642 boundary = mimeinfo->boundary;
645 boundary_len = strlen(boundary);
647 /* look for first boundary */
648 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
649 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
656 if ((fpos = ftell(fp)) < 0) {
662 for (npart = 0;; npart++) {
664 gboolean eom = FALSE;
668 partinfo = procmime_scan_mime_header(fp);
669 if (!partinfo) break;
672 procmime_mimeinfo_insert(mimeinfo, partinfo);
674 procmime_mimeinfo_free(partinfo);
676 /* look for next boundary */
678 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
679 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
680 if (buf[2 + boundary_len] == '-' &&
681 buf[2 + boundary_len + 1] == '-')
687 eom = TRUE; /* broken MIME message */
690 partinfo->size = fpos - prev_fpos - strlen(buf);
695 source = procmsg_get_message_file_path(msginfo);
697 g_return_if_fail(mimeinfo != NULL);
699 if (!mimeinfo->main && mimeinfo->parent)
701 filename = mime_extract_file(source, mimeinfo);
703 compose_attach_append(compose, filename,
704 mimeinfo->mime_type);
709 if (mimeinfo->sub && mimeinfo->sub->children)
711 filename = mime_extract_file(source, mimeinfo->sub);
713 compose_attach_append(compose, filename,
714 mimeinfo->sub->mime_type);
719 if (mimeinfo->children) {
722 child = mimeinfo->children;
724 filename = mime_extract_file(source, child);
726 compose_attach_append(compose, filename,
737 procmime_mimeinfo_free_all(mimeinfo);
741 #define INSERT_FW_HEADER(var, hdr) \
742 if (msginfo->var && *msginfo->var) { \
743 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
744 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
745 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
748 Compose * compose_forward(PrefsAccount * account, MsgInfo *msginfo,
752 /* PrefsAccount *account; */
757 g_return_val_if_fail(msginfo != NULL, NULL);
758 g_return_val_if_fail(msginfo->folder != NULL, NULL);
760 if (account == NULL) {
761 account = msginfo->folder->folder->account;
762 if (!account) account = cur_account;
764 g_return_val_if_fail(account != NULL, NULL);
766 MSG_UNSET_FLAGS(msginfo->flags, MSG_REPLIED);
767 MSG_SET_FLAGS(msginfo->flags, MSG_FORWARDED);
769 CHANGE_FLAGS(msginfo);
771 compose = compose_create(account);
772 compose->mode = COMPOSE_FORWARD;
774 if (msginfo->subject && *msginfo->subject) {
775 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
776 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
780 text = GTK_STEXT(compose->text);
781 gtk_stext_freeze(text);
786 msgfile = procmsg_get_message_file_path(msginfo);
787 if (!is_file_exist(msgfile))
788 g_warning(_("%s: file not exist\n"), msgfile);
790 compose_attach_append(compose, msgfile,
791 MIME_MESSAGE_RFC822);
795 if ((fp = procmime_get_text_part(msginfo)) == NULL)
796 g_warning(_("Can't get text part\n"));
799 gtk_stext_insert(text, NULL, NULL, NULL,
800 _("\n\nBegin forwarded message:\n\n"), -1);
801 INSERT_FW_HEADER(date, "Date: ");
802 INSERT_FW_HEADER(from, "From: ");
803 INSERT_FW_HEADER(to, "To: ");
804 INSERT_FW_HEADER(newsgroups, "Newsgroups: ");
805 INSERT_FW_HEADER(subject, "Subject: ");
806 gtk_stext_insert(text, NULL, NULL, NULL, "\n\n", 2);
809 while (fgets(buf, sizeof(buf), fp) != NULL)
810 gtk_stext_insert(text, NULL, NULL, NULL,
814 compose_attach_parts(compose, msginfo);
817 if (prefs_common.auto_sig)
818 compose_insert_sig(compose);
819 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
820 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
822 gtk_stext_thaw(text);
823 if (account->protocol != A_NNTP)
824 gtk_widget_grab_focus(compose->to_entry);
826 gtk_widget_grab_focus(compose->newsgroups_entry);
831 #undef INSERT_FW_HEADER
833 void compose_reedit(MsgInfo *msginfo)
836 PrefsAccount *account;
841 g_return_if_fail(msginfo != NULL);
842 g_return_if_fail(msginfo->folder != NULL);
844 account = msginfo->folder->folder->account;
845 if (!account) account = cur_account;
846 g_return_if_fail(account != NULL);
848 compose = compose_create(account);
849 compose->mode = COMPOSE_REEDIT_DRAFT;
850 compose->targetinfo = procmsg_msginfo_copy(msginfo);
852 if (compose_parse_header(compose, msginfo) < 0) return;
853 compose_reedit_set_entry(compose, msginfo);
855 text = GTK_STEXT(compose->text);
856 gtk_stext_freeze(text);
858 if ((fp = procmime_get_text_part(msginfo)) == NULL)
859 g_warning(_("Can't get text part\n"));
861 while (fgets(buf, sizeof(buf), fp) != NULL)
862 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
865 compose_attach_parts(compose, msginfo);
867 gtk_stext_thaw(text);
868 gtk_widget_grab_focus(compose->text);
871 GList *compose_get_compose_list(void)
876 void compose_entry_append(Compose *compose, const gchar *address,
877 ComposeEntryType type)
882 if (!address || *address == '\0') return;
886 entry = GTK_ENTRY(compose->cc_entry);
889 entry = GTK_ENTRY(compose->bcc_entry);
891 case COMPOSE_NEWSGROUPS:
892 entry = GTK_ENTRY(compose->newsgroups_entry);
896 entry = GTK_ENTRY(compose->to_entry);
900 text = gtk_entry_get_text(entry);
902 gtk_entry_append_text(entry, ", ");
903 gtk_entry_append_text(entry, address);
906 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
908 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
909 {"Cc:", NULL, FALSE},
910 {"References:", NULL, FALSE},
911 {"Bcc:", NULL, FALSE},
912 {"Newsgroups:", NULL, FALSE},
913 {"Followup-To:", NULL, FALSE},
914 {NULL, NULL, FALSE}};
928 g_return_val_if_fail(msginfo != NULL, -1);
930 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
931 procheader_get_header_fields(fp, hentry);
934 if (hentry[H_REPLY_TO].body != NULL) {
935 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
936 compose->replyto = hentry[H_REPLY_TO].body;
937 hentry[H_REPLY_TO].body = NULL;
939 if (hentry[H_CC].body != NULL) {
940 conv_unmime_header_overwrite(hentry[H_CC].body);
941 compose->cc = hentry[H_CC].body;
942 hentry[H_CC].body = NULL;
944 if (hentry[H_REFERENCES].body != NULL) {
945 if (compose->mode == COMPOSE_REEDIT_DRAFT)
946 compose->references = hentry[H_REFERENCES].body;
948 compose->references = compose_parse_references
949 (hentry[H_REFERENCES].body, msginfo->msgid);
950 g_free(hentry[H_REFERENCES].body);
952 hentry[H_REFERENCES].body = NULL;
954 if (hentry[H_BCC].body != NULL) {
955 if (compose->mode == COMPOSE_REEDIT_DRAFT) {
956 conv_unmime_header_overwrite(hentry[H_BCC].body);
957 compose->bcc = hentry[H_BCC].body;
959 g_free(hentry[H_BCC].body);
960 hentry[H_BCC].body = NULL;
962 if (hentry[H_NEWSGROUPS].body != NULL) {
963 compose->newsgroups = hentry[H_NEWSGROUPS].body;
964 hentry[H_NEWSGROUPS].body = NULL;
966 if (hentry[H_FOLLOWUP_TO].body != NULL) {
967 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
968 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
969 hentry[H_FOLLOWUP_TO].body = NULL;
972 if (compose->mode == COMPOSE_REEDIT_DRAFT && msginfo->inreplyto)
973 compose->inreplyto = g_strdup(msginfo->inreplyto);
974 else if (compose->mode != COMPOSE_REEDIT_DRAFT &&
975 msginfo->msgid && *msginfo->msgid) {
976 compose->inreplyto = g_strdup(msginfo->msgid);
978 if (!compose->references) {
979 if (msginfo->inreplyto && *msginfo->inreplyto)
980 compose->references =
981 g_strdup_printf("<%s>\n\t<%s>",
985 compose->references =
986 g_strconcat("<", msginfo->msgid, ">",
994 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
996 GSList *ref_id_list, *cur;
1000 ref_id_list = references_list_append(NULL, ref);
1001 if (!ref_id_list) return NULL;
1002 if (msgid && *msgid)
1003 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1008 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1009 /* "<" + Message-ID + ">" + CR+LF+TAB */
1010 len += strlen((gchar *)cur->data) + 5;
1012 if (len > MAX_REFERENCES_LEN) {
1013 /* remove second message-ID */
1014 if (ref_id_list && ref_id_list->next &&
1015 ref_id_list->next->next) {
1016 g_free(ref_id_list->next->data);
1017 ref_id_list = g_slist_remove
1018 (ref_id_list, ref_id_list->next->data);
1020 slist_free_strings(ref_id_list);
1021 g_slist_free(ref_id_list);
1028 new_ref = g_string_new("");
1029 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1030 if (new_ref->len > 0)
1031 g_string_append(new_ref, "\n\t");
1032 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1035 slist_free_strings(ref_id_list);
1036 g_slist_free(ref_id_list);
1038 new_ref_str = new_ref->str;
1039 g_string_free(new_ref, FALSE);
1044 static void compose_quote_file(Compose *compose, MsgInfo *msginfo, FILE *fp)
1046 GtkSText *text = GTK_STEXT(compose->text);
1049 GdkColor *qcolor = NULL;
1050 gchar buf[BUFFSIZE];
1052 gchar *linep, *cur, *leftp;
1053 gint line_len, cur_len;
1058 /* if (prefs_common.enable_color) qcolor = "e_color; */
1059 if (prefs_common.quotemark && *prefs_common.quotemark)
1060 qmark = prefs_common.quotemark;
1063 quote_str = compose_quote_parse_fmt(compose, msginfo, qmark);
1064 g_return_if_fail(quote_str != NULL);
1065 qlen = strlen(quote_str);
1067 if (!prefs_common.linewrap_quote ||
1068 prefs_common.linewrap_len <= qlen) {
1069 while (fgets(buf, sizeof(buf), fp) != NULL) {
1070 gtk_stext_insert(text, NULL, qcolor, NULL,
1072 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1078 wrap_len = prefs_common.linewrap_len - qlen;
1080 while (fgets(buf, sizeof(buf), fp) != NULL) {
1082 str_len = strlen(buf);
1084 if (str_len <= wrap_len) {
1085 gtk_stext_insert(text, NULL, qcolor, NULL,
1087 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1088 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1092 linep = cur = leftp = buf;
1093 line_len = cur_len = 0;
1095 while (*cur != '\0') {
1096 ch_len = mblen(cur, MB_CUR_MAX);
1097 if (ch_len < 0) ch_len = 1;
1099 if (ch_len == 1 && isspace(*cur)) {
1100 linep = cur + ch_len;
1101 line_len = cur_len + ch_len;
1104 if (cur_len + ch_len > wrap_len && line_len > 0) {
1105 gtk_stext_insert(text, NULL, qcolor, NULL,
1108 if (isspace(*(linep - 1)))
1109 gtk_stext_insert(text, NULL,
1111 leftp, line_len - 1);
1113 gtk_stext_insert(text, NULL,
1116 gtk_stext_insert(text, NULL, NULL, NULL,
1120 cur_len = cur_len - line_len + ch_len;
1127 linep = cur + ch_len;
1128 line_len = cur_len + ch_len;
1135 gtk_stext_insert(text, NULL, qcolor, NULL,
1137 gtk_stext_insert(text, NULL, qcolor, NULL, leftp, -1);
1138 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1145 static gchar *compose_quote_parse_fmt(Compose *compose, MsgInfo *msginfo,
1149 size_t buf_len = 1024;
1157 if (!fmt || *fmt == '\0') return 0;
1159 Xalloca(mbs, sizeof(wchar_t) + 1, return 0);
1160 Xalloca(wcsfmt, (strlen(fmt) + 1) * sizeof(wchar_t), return 0);
1161 mbstowcs(wcsfmt, fmt, strlen(fmt) + 1);
1164 ext_str = g_malloc(sizeof(gchar) * buf_len);
1165 g_return_val_if_fail(ext_str != NULL, NULL);
1170 len = wctomb(mbs, *sp);
1176 wctomb(mbs, *(++sp));
1181 str = msginfo->date;
1185 str = msginfo->from;
1188 case 'I': /* initial */
1189 if (!msginfo->fromname) {sp++; break;}
1190 p = msginfo->fromname;
1191 tmp[0] = tmp[1] = tmp[2] = '\0';
1193 if (*p && isalnum(*p))
1194 tmp[0] = toupper(*p);
1201 while (*p && !isspace(*p)) p++;
1202 while (*p && isspace(*p)) p++;
1203 if (*p && isalnum(*p))
1204 tmp[1] = toupper(*p);
1207 if (tmp[1]) str = tmp;
1211 str = msginfo->fromname;
1215 if (!msginfo->fromname) {sp++; break;}
1216 Xstrdup_a(str, msginfo->fromname,
1219 while (*p && !isspace(*p)) p++;
1224 str = msginfo->subject;
1232 if (!msginfo->msgid) {sp++; break;}
1233 Xalloca(str, strlen(msginfo->msgid) + 3,
1235 g_snprintf(str, strlen(msginfo->msgid) + 3,
1236 "<%s>", msginfo->msgid);
1248 while (ext_len + strlen(str) + 1 > buf_len)
1250 ext_str = g_realloc(ext_str,
1251 sizeof(gchar) * buf_len);
1252 g_return_val_if_fail(ext_str != NULL, NULL);
1253 strcpy(ext_str + ext_len, str);
1254 ext_len += strlen(str);
1256 } else if (*mbs == '\\') {
1257 wctomb(mbs, *(++sp));
1275 while (ext_len + strlen(str) + 1 > buf_len)
1277 ext_str = g_realloc(ext_str,
1278 sizeof(gchar) * buf_len);
1279 g_return_val_if_fail(ext_str != NULL, NULL);
1280 strcpy(ext_str + ext_len, str);
1281 ext_len += strlen(str);
1285 while (ext_len + len + 1 > buf_len) buf_len += 1024;
1286 ext_str = g_realloc(ext_str, sizeof(gchar) * buf_len);
1287 g_return_val_if_fail(ext_str != NULL, NULL);
1288 strcpy(ext_str + ext_len, mbs);
1295 ext_str = g_realloc(ext_str, strlen(ext_str) + 1);
1300 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1301 gboolean to_all, gboolean to_author)
1306 GHashTable *to_table;
1308 g_return_if_fail(compose->account != NULL);
1309 g_return_if_fail(msginfo != NULL);
1311 if (compose->account->protocol != A_NNTP)
1312 gtk_entry_set_text(GTK_ENTRY(compose->to_entry),
1313 ( (compose->replyto && !to_author)
1315 : msginfo->from ? msginfo->from : ""));
1316 if (compose->account->protocol == A_NNTP)
1317 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry),
1318 compose->followup_to ? compose->followup_to
1319 : compose->newsgroups ? compose->newsgroups
1322 if (msginfo->subject && *msginfo->subject) {
1323 gchar *buf, *buf2, *p;
1325 buf = g_strdup(msginfo->subject);
1326 while (!strncasecmp(buf, "Re:", 3)) {
1328 while (isspace(*p)) p++;
1329 memmove(buf, p, strlen(p) + 1);
1332 buf2 = g_strdup_printf("Re: %s", buf);
1333 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1337 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1339 if (!to_all || compose->account->protocol == A_NNTP) return;
1341 from = g_strdup(compose->replyto ? compose->replyto :
1342 msginfo->from ? msginfo->from : "");
1343 extract_address(from);
1345 cc_list = address_list_append(NULL, msginfo->to);
1346 cc_list = address_list_append(cc_list, compose->cc);
1348 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1349 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1350 if (compose->account)
1351 g_hash_table_insert(to_table, compose->account->address,
1352 GINT_TO_POINTER(1));
1354 /* remove address on To: and that of current account */
1355 for (cur = cc_list; cur != NULL; ) {
1356 GSList *next = cur->next;
1358 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1359 cc_list = g_slist_remove(cc_list, cur->data);
1361 g_hash_table_insert(to_table, cur->data, cur);
1365 g_hash_table_destroy(to_table);
1369 for (cur = cc_list; cur != NULL; cur = cur->next)
1370 compose_entry_append(compose, (gchar *)cur->data,
1372 slist_free_strings(cc_list);
1373 g_slist_free(cc_list);
1377 #define SET_ENTRY(entry, str) \
1380 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1383 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1385 g_return_if_fail(msginfo != NULL);
1387 SET_ENTRY(to_entry, msginfo->to);
1388 SET_ENTRY(subject_entry, msginfo->subject);
1389 SET_ENTRY(cc_entry, compose->cc);
1390 SET_ENTRY(bcc_entry, compose->bcc);
1391 SET_ENTRY(reply_entry, compose->replyto);
1394 GtkItemFactory *ifactory;
1395 GtkWidget *menuitem;
1397 ifactory = gtk_item_factory_from_widget(compose->menubar);
1398 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1399 gtk_check_menu_item_set_active
1400 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1402 if (compose->replyto) {
1403 GtkItemFactory *ifactory;
1404 GtkWidget *menuitem;
1406 ifactory = gtk_item_factory_from_widget(compose->menubar);
1407 menuitem = gtk_item_factory_get_item
1408 (ifactory, "/Message/Reply to");
1409 gtk_check_menu_item_set_active
1410 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1416 static void compose_insert_sig(Compose *compose)
1420 if (compose->account && compose->account->sig_path)
1421 sigfile = g_strdup(compose->account->sig_path);
1423 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1424 DEFAULT_SIGNATURE, NULL);
1427 if (!is_file_or_fifo_exist(sigfile)) {
1432 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1433 if (prefs_common.sig_sep) {
1434 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1435 prefs_common.sig_sep, -1);
1436 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1440 compose_insert_file(compose, sigfile);
1444 static void compose_insert_file(Compose *compose, const gchar *file)
1446 GtkSText *text = GTK_STEXT(compose->text);
1447 gchar buf[BUFFSIZE];
1450 g_return_if_fail(file != NULL);
1452 if ((fp = fopen(file, "r")) == NULL) {
1453 FILE_OP_ERROR(file, "fopen");
1457 gtk_stext_freeze(text);
1459 while (fgets(buf, sizeof(buf), fp) != NULL)
1460 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1462 gtk_stext_thaw(text);
1467 static void compose_attach_append(Compose *compose, const gchar *file,
1468 ContentType cnttype)
1471 gchar *text[N_ATTACH_COLS];
1475 if (!is_file_exist(file)) {
1476 g_warning(_("File %s doesn't exist\n"), file);
1479 if ((size = get_file_size(file)) < 0) {
1480 g_warning(_("Can't get file size of %s\n"), file);
1484 alertpanel_notice(_("File %s is empty\n"), file);
1488 if (!compose->use_attach) {
1489 GtkItemFactory *ifactory;
1490 GtkWidget *menuitem;
1492 ifactory = gtk_item_factory_from_widget(compose->menubar);
1493 menuitem = gtk_item_factory_get_item(ifactory,
1495 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1499 ainfo = g_new0(AttachInfo, 1);
1500 ainfo->file = g_strdup(file);
1502 if (cnttype == MIME_MESSAGE_RFC822) {
1503 ainfo->content_type = g_strdup("message/rfc822");
1504 ainfo->encoding = ENC_7BIT;
1505 ainfo->name = g_strdup_printf(_("Message: %s"),
1508 ainfo->content_type = procmime_get_mime_type(file);
1509 if (!ainfo->content_type)
1510 ainfo->content_type =
1511 g_strdup("application/octet-stream");
1512 ainfo->encoding = ENC_BASE64;
1513 ainfo->name = g_strdup(g_basename(file));
1517 text[COL_MIMETYPE] = ainfo->content_type;
1518 text[COL_SIZE] = to_human_readable(size);
1519 text[COL_NAME] = ainfo->name;
1521 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1522 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1524 if (cnttype != MIME_MESSAGE_RFC822)
1525 compose_changed_cb(NULL, compose);
1528 static void compose_wrap_line(Compose *compose)
1530 GtkSText *text = GTK_STEXT(compose->text);
1532 guint line_pos = 0, cur_pos = 0;
1533 gint line_len = 0, cur_len = 0;
1535 gchar cbuf[MB_CUR_MAX];
1537 gtk_stext_freeze(text);
1539 text_len = gtk_stext_get_length(text);
1541 for (; cur_pos < text_len; cur_pos++) {
1542 if (text->use_wchar)
1544 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
1546 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
1550 if (ch_len == 1 && *cbuf == '\n') {
1551 line_pos = cur_pos + 1;
1552 line_len = cur_len = 0;
1561 if (ch_len == 1 && isspace(*cbuf)) {
1562 line_pos = cur_pos + 1;
1563 line_len = cur_len + ch_len;
1566 if (cur_len + ch_len > prefs_common.linewrap_len &&
1570 if (text->use_wchar)
1571 tlen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
1573 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
1576 if (tlen == 1 && isspace(*cbuf)) {
1577 gtk_stext_set_point(text, line_pos);
1578 gtk_stext_backward_delete(text, 1);
1586 gtk_stext_set_point(text, line_pos);
1587 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1591 cur_len = cur_len - line_len + ch_len;
1597 line_pos = cur_pos + 1;
1598 line_len = cur_len + ch_len;
1603 gtk_stext_thaw(text);
1606 static void compose_set_title(Compose *compose)
1611 edited = compose->modified ? _(" [Edited]") : "";
1612 if (compose->account && compose->account->address)
1613 str = g_strdup_printf(_("%s - Compose message%s"),
1614 compose->account->address, edited);
1616 str = g_strdup_printf(_("Compose message%s"), edited);
1617 gtk_window_set_title(GTK_WINDOW(compose->window), str);
1622 * compose_current_mail_account:
1624 * Find a current mail account (the currently selected account, or the
1625 * default account, if a news account is currently selected). If a
1626 * mail account cannot be found, display an error message.
1628 * Return value: Mail account, or NULL if not found.
1630 static PrefsAccount *
1631 compose_current_mail_account(void)
1635 if (cur_account && cur_account->protocol != A_NNTP)
1638 ac = account_get_default();
1639 if (!ac || ac->protocol == A_NNTP) {
1640 alertpanel_error(_("Account for sending mail is not specified.\n"
1641 "Please select a mail account before sending."));
1648 gint compose_send(Compose *compose)
1650 gchar tmp[MAXPATHLEN + 1];
1651 gchar *to, *newsgroups;
1653 static gboolean lock = FALSE;
1657 g_return_val_if_fail(compose->account != NULL, -1);
1658 g_return_val_if_fail(compose->orig_account != NULL, -1);
1662 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
1663 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
1664 if (*to == '\0' && *newsgroups == '\0') {
1665 alertpanel_error(_("Recipient is not specified."));
1670 /* write to temporary file */
1671 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
1672 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
1674 if (prefs_common.linewrap_at_send)
1675 compose_wrap_line(compose);
1677 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
1682 if (!compose->to_list && !compose->newsgroup_list) {
1683 g_warning(_("can't get recipient list."));
1689 if (compose->to_list) {
1692 if (compose->account->protocol != A_NNTP)
1693 ac = compose->account;
1694 else if (compose->orig_account->protocol != A_NNTP)
1695 ac = compose->orig_account;
1697 ac = compose_current_mail_account();
1704 ok = send_message(tmp, ac, compose->to_list);
1705 statusbar_pop_all();
1708 if (ok == 0 && compose->newsgroup_list) {
1711 if (compose->account->protocol == A_NNTP)
1712 folder = FOLDER(compose->account->folder);
1714 folder = FOLDER(compose->orig_account->folder);
1716 ok = news_post(folder, tmp);
1718 alertpanel_error(_("Error occurred while posting the message to %s ."),
1719 compose->account->nntp_server);
1726 /* queue message if failed to send */
1728 if (prefs_common.queue_msg) {
1733 _("Error occurred while sending the message.\n"
1734 "Put this message into queue folder?"),
1735 _("OK"), _("Cancel"), NULL);
1736 if (G_ALERTDEFAULT == val) {
1737 ok = compose_queue(compose, tmp);
1739 alertpanel_error(_("Can't queue the message."));
1742 alertpanel_error(_("Error occurred while sending the message."));
1745 /* save message to outbox */
1746 if (ok == 0 && prefs_common.savemsg) {
1747 if (compose_save_to_outbox(compose, tmp) < 0)
1749 (_("Can't save the message to outbox."));
1757 static gint compose_write_to_file(Compose *compose, const gchar *file,
1764 const gchar *out_codeset;
1765 EncodingType encoding;
1767 if ((fp = fopen(file, "w")) == NULL) {
1768 FILE_OP_ERROR(file, "fopen");
1772 /* chmod for security */
1773 if (change_file_mode_rw(fp, file) < 0) {
1774 FILE_OP_ERROR(file, "chmod");
1775 g_warning(_("can't change file mode\n"));
1778 /* get all composed text */
1779 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
1780 len = strlen(chars);
1781 if (is_ascii_str(chars)) {
1782 buf = g_strdup(chars);
1783 out_codeset = "US-ASCII";
1784 encoding = ENC_7BIT;
1786 const gchar *src_codeset;
1788 out_codeset = conv_get_outgoing_charset_str();
1789 if (!strcasecmp(out_codeset, "US-ASCII"))
1790 out_codeset = "ISO-8859-1";
1791 encoding = procmime_get_encoding_for_charset(out_codeset);
1792 debug_print("charset = %s, encoding = %s\n",
1793 out_codeset, procmime_get_encoding_str(encoding));
1795 src_codeset = conv_get_current_charset_str();
1796 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
1801 alertpanel_error(_("Can't convert the codeset of the message."));
1808 if (compose_write_headers
1809 (compose, fp, out_codeset, encoding, is_draft) < 0) {
1810 g_warning(_("can't write headers\n"));
1817 if (compose->use_attach) {
1819 /* This prolog message is ignored by mime software and
1820 * because it would make our signing/encryption task
1821 * tougher, we don't emit it in that case */
1822 if (!compose->use_signing && !compose->use_encryption)
1824 fputs("This is a multi-part message in MIME format.\n", fp);
1826 fprintf(fp, "\n--%s\n", compose->boundary);
1827 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
1829 fprintf(fp, "Content-Transfer-Encoding: %s\n",
1830 procmime_get_encoding_str(encoding));
1836 if (encoding == ENC_BASE64) {
1837 gchar outbuf[B64_BUFFSIZE];
1840 for (i = 0; i < len; i += B64_LINE_SIZE) {
1841 l = MIN(B64_LINE_SIZE, len - i);
1842 to64frombits(outbuf, buf + i, l);
1846 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
1847 FILE_OP_ERROR(file, "fwrite");
1855 if (compose->use_attach)
1856 compose_write_attach(compose, fp);
1858 if (fclose(fp) == EOF) {
1859 FILE_OP_ERROR(file, "fclose");
1865 if (compose->use_signing) {
1866 if (rfc2015_sign(file, compose->account) < 0) {
1871 if (compose->use_encryption) {
1872 if (rfc2015_encrypt(file, compose->to_list) < 0) {
1877 #endif /* USE_GPGME */
1882 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
1888 if ((fp = fopen(file, "w")) == NULL) {
1889 FILE_OP_ERROR(file, "fopen");
1893 /* chmod for security */
1894 if (change_file_mode_rw(fp, file) < 0) {
1895 FILE_OP_ERROR(file, "chmod");
1896 g_warning(_("can't change file mode\n"));
1899 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
1902 len = strlen(chars);
1903 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
1904 FILE_OP_ERROR(file, "fwrite");
1913 if (fclose(fp) == EOF) {
1914 FILE_OP_ERROR(file, "fclose");
1921 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
1928 debug_print(_("saving sent message...\n"));
1930 outbox = folder_get_default_outbox();
1931 path = folder_item_get_path(outbox);
1932 if (!is_dir_exist(path))
1933 make_dir_hier(path);
1935 folder_item_scan(outbox);
1936 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
1938 g_warning(_("can't save message\n"));
1942 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
1943 g_warning(_("can't open mark file\n"));
1947 newmsginfo.msgnum = num;
1948 newmsginfo.flags = 0;
1949 procmsg_write_flags(&newmsginfo, fp);
1957 static gint compose_queue(Compose *compose, const gchar *file)
1960 gchar *tmp, *queue_path;
1963 gchar buf[BUFFSIZE];
1966 debug_print(_("queueing message...\n"));
1967 g_return_val_if_fail(compose->to_list != NULL, -1);
1968 g_return_val_if_fail(compose->account != NULL, -1);
1970 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
1971 G_DIR_SEPARATOR, (gint)compose);
1972 if ((fp = fopen(tmp, "w")) == NULL) {
1973 FILE_OP_ERROR(tmp, "fopen");
1977 if ((src_fp = fopen(file, "r")) == NULL) {
1978 FILE_OP_ERROR(file, "fopen");
1984 if (change_file_mode_rw(fp, tmp) < 0) {
1985 FILE_OP_ERROR(tmp, "chmod");
1986 g_warning(_("can't change file mode\n"));
1989 /* queueing variables */
1990 fprintf(fp, "AF:\n");
1991 fprintf(fp, "NF:0\n");
1992 fprintf(fp, "PS:10\n");
1993 fprintf(fp, "SRH:1\n");
1994 fprintf(fp, "SFN:\n");
1995 fprintf(fp, "DSR:\n");
1997 fprintf(fp, "MID:<%s>\n", compose->msgid);
1999 fprintf(fp, "MID:\n");
2000 fprintf(fp, "CFG:\n");
2001 fprintf(fp, "PT:0\n");
2002 fprintf(fp, "S:%s\n", compose->account->address);
2003 fprintf(fp, "RQ:\n");
2004 if (compose->account->smtp_server)
2005 fprintf(fp, "SSV:%s\n", compose->account->smtp_server);
2007 fprintf(fp, "SSV:\n");
2008 if (compose->account->nntp_server)
2009 fprintf(fp, "NSV:%s\n", compose->account->nntp_server);
2011 fprintf(fp, "NSV:\n");
2012 fprintf(fp, "SSH:\n");
2013 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
2014 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
2015 fprintf(fp, ",<%s>", (gchar *)cur->data);
2019 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
2020 if (fputs(buf, fp) == EOF) {
2021 FILE_OP_ERROR(tmp, "fputs");
2031 if (fclose(fp) == EOF) {
2032 FILE_OP_ERROR(tmp, "fclose");
2038 queue = folder_get_default_queue();
2039 folder_item_scan(queue);
2040 queue_path = folder_item_get_path(queue);
2041 if (!is_dir_exist(queue_path))
2042 make_dir_hier(queue_path);
2043 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
2044 g_warning(_("can't queue the message\n"));
2052 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
2053 g_warning(_("can't open mark file\n"));
2057 newmsginfo.msgnum = num;
2058 newmsginfo.flags = 0;
2059 procmsg_write_flags(&newmsginfo, fp);
2064 folder_item_scan(queue);
2065 folderview_update_item(queue, TRUE);
2070 static void compose_write_attach(Compose *compose, FILE *fp)
2073 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2076 gchar filename[BUFFSIZE];
2079 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
2081 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
2082 g_warning(_("Can't open file %s\n"), ainfo->file);
2086 fprintf(fp, "\n--%s\n", compose->boundary);
2088 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
2089 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
2090 fprintf(fp, "Content-Disposition: inline\n");
2092 conv_encode_header(filename, sizeof(filename),
2094 fprintf(fp, "Content-Type: %s;\n"
2096 ainfo->content_type, filename);
2097 fprintf(fp, "Content-Disposition: attachment;\n"
2098 " filename=\"%s\"\n", filename);
2101 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
2102 procmime_get_encoding_str(ainfo->encoding));
2104 if (ainfo->encoding == ENC_7BIT) {
2105 gchar buf[BUFFSIZE];
2107 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
2109 if (len > 1 && buf[len - 1] == '\n' &&
2110 buf[len - 2] == '\r') {
2111 buf[len - 2] = '\n';
2112 buf[len - 1] = '\0';
2117 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
2119 while ((len = fread(inbuf, sizeof(gchar),
2120 B64_LINE_SIZE, attach_fp))
2122 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
2126 if (len > 0 && feof(attach_fp)) {
2127 to64frombits(outbuf, inbuf, len);
2136 fprintf(fp, "\n--%s--\n", compose->boundary);
2139 #define IS_IN_CUSTOM_HEADER(header) \
2140 (compose->account->add_customhdr && \
2141 custom_header_find(compose->account->customhdr_list, header) != NULL)
2143 static gint compose_write_headers(Compose *compose, FILE *fp,
2144 const gchar *charset, EncodingType encoding,
2147 gchar buf[BUFFSIZE];
2149 /* struct utsname utsbuf; */
2151 g_return_val_if_fail(fp != NULL, -1);
2152 g_return_val_if_fail(charset != NULL, -1);
2153 g_return_val_if_fail(compose->account != NULL, -1);
2154 g_return_val_if_fail(compose->account->address != NULL, -1);
2157 if (compose->account->add_date) {
2158 get_rfc822_date(buf, sizeof(buf));
2159 fprintf(fp, "Date: %s\n", buf);
2163 if (!IS_IN_CUSTOM_HEADER("From")) {
2164 if (compose->account->name && *compose->account->name) {
2165 compose_convert_header
2166 (buf, sizeof(buf), compose->account->name,
2168 fprintf(fp, "From: %s <%s>\n",
2169 buf, compose->account->address);
2171 fprintf(fp, "From: %s\n", compose->account->address);
2174 slist_free_strings(compose->to_list);
2175 g_slist_free(compose->to_list);
2176 compose->to_list = NULL;
2179 if (compose->use_to) {
2180 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2182 Xstrdup_a(str, str, return -1);
2185 compose->to_list = address_list_append
2186 (compose->to_list, str);
2187 if (!IS_IN_CUSTOM_HEADER("To")) {
2188 compose_convert_header
2189 (buf, sizeof(buf), str,
2191 fprintf(fp, "To: %s\n", buf);
2197 slist_free_strings(compose->newsgroup_list);
2198 g_slist_free(compose->newsgroup_list);
2199 compose->newsgroup_list = NULL;
2202 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2204 Xstrdup_a(str, str, return -1);
2208 compose->newsgroup_list =
2209 newsgroup_list_append(compose->newsgroup_list,
2211 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
2212 compose_convert_header(buf, sizeof(buf), str,
2213 strlen("Newsgroups: "));
2214 fprintf(fp, "Newsgroups: %s\n", buf);
2219 if (!is_draft && !compose->to_list && !compose->newsgroup_list)
2223 if (compose->use_cc) {
2224 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
2226 Xstrdup_a(str, str, return -1);
2229 compose->to_list = address_list_append
2230 (compose->to_list, str);
2231 if (!IS_IN_CUSTOM_HEADER("Cc")) {
2232 compose_convert_header
2233 (buf, sizeof(buf), str,
2235 fprintf(fp, "Cc: %s\n", buf);
2242 if (compose->use_bcc) {
2243 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
2245 Xstrdup_a(str, str, return -1);
2248 compose->to_list = address_list_append
2249 (compose->to_list, str);
2251 compose_convert_header
2252 (buf, sizeof(buf), str,
2254 fprintf(fp, "Bcc: %s\n", buf);
2261 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2262 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
2263 Xstrdup_a(str, str, return -1);
2266 compose_convert_header(buf, sizeof(buf), str,
2267 strlen("Subject: "));
2268 fprintf(fp, "Subject: %s\n", buf);
2273 if (compose->account->gen_msgid) {
2274 compose_generate_msgid(compose, buf, sizeof(buf));
2275 fprintf(fp, "Message-Id: <%s>\n", buf);
2276 compose->msgid = g_strdup(buf);
2280 if (compose->inreplyto && compose->to_list)
2281 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
2284 if (compose->references)
2285 fprintf(fp, "References: %s\n", compose->references);
2288 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
2289 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
2291 Xstrdup_a(str, str, return -1);
2295 compose_convert_header(buf, sizeof(buf), str,
2296 strlen("Followup-To: "));
2297 fprintf(fp, "Followup-To: %s\n", buf);
2303 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
2304 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
2306 Xstrdup_a(str, str, return -1);
2309 compose_convert_header(buf, sizeof(buf), str,
2310 strlen("Reply-To: "));
2311 fprintf(fp, "Reply-To: %s\n", buf);
2317 if (compose->account->organization &&
2318 !IS_IN_CUSTOM_HEADER("Organization")) {
2319 compose_convert_header(buf, sizeof(buf),
2320 compose->account->organization,
2321 strlen("Organization: "));
2322 fprintf(fp, "Organization: %s\n", buf);
2325 /* Program version and system info */
2326 /* uname(&utsbuf); */
2327 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2328 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
2329 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
2331 gtk_major_version, gtk_minor_version, gtk_micro_version,
2333 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2335 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2336 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
2337 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
2339 gtk_major_version, gtk_minor_version, gtk_micro_version,
2341 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2344 /* custom headers */
2345 if (compose->account->add_customhdr) {
2348 for (cur = compose->account->customhdr_list; cur != NULL;
2350 CustomHeader *chdr = (CustomHeader *)cur->data;
2352 if (strcasecmp(chdr->name, "Date") != 0 &&
2353 strcasecmp(chdr->name, "From") != 0 &&
2354 strcasecmp(chdr->name, "To") != 0 &&
2355 strcasecmp(chdr->name, "Sender") != 0 &&
2356 strcasecmp(chdr->name, "Message-Id") != 0 &&
2357 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
2358 strcasecmp(chdr->name, "References") != 0 &&
2359 strcasecmp(chdr->name, "Mime-Version") != 0 &&
2360 strcasecmp(chdr->name, "Content-Type") != 0 &&
2361 strcasecmp(chdr->name, "Content-Transfer-Encoding")
2363 compose_convert_header
2365 chdr->value ? chdr->value : "",
2366 strlen(chdr->name) + 2);
2367 fprintf(fp, "%s: %s\n", chdr->name, buf);
2372 fprintf(fp, "Mime-Version: 1.0\n");
2373 if (compose->use_attach) {
2374 get_rfc822_date(buf, sizeof(buf));
2375 subst_char(buf, ' ', '_');
2376 subst_char(buf, ',', '_');
2377 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
2378 buf, (guint)compose);
2380 "Content-Type: multipart/mixed;\n"
2381 " boundary=\"%s\"\n", compose->boundary);
2383 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
2384 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2385 procmime_get_encoding_str(encoding));
2388 /* Request Return Receipt */
2389 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
2390 if (compose->return_receipt) {
2391 if (compose->account->name
2392 && *compose->account->name) {
2393 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
2394 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
2396 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
2400 /* separator between header and body */
2406 #undef IS_IN_CUSTOM_HEADER
2408 static void compose_convert_header(gchar *dest, gint len, gchar *src,
2411 g_return_if_fail(src != NULL);
2412 g_return_if_fail(dest != NULL);
2414 if (len < 1) return;
2418 if (is_ascii_str(src)) {
2419 strncpy2(dest, src, len);
2420 dest[len - 1] = '\0';
2423 conv_encode_header(dest, len, src, header_len);
2426 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
2435 if (compose->account && compose->account->address &&
2436 *compose->account->address) {
2437 if (strchr(compose->account->address, '@'))
2438 addr = g_strdup(compose->account->address);
2440 addr = g_strconcat(compose->account->address, "@",
2441 get_domain_name(), NULL);
2443 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
2446 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
2447 lt->tm_year + 1900, lt->tm_mon + 1,
2448 lt->tm_mday, lt->tm_hour,
2449 lt->tm_min, lt->tm_sec,
2450 (guint)random(), addr);
2452 debug_print(_("generated Message-ID: %s\n"), buf);
2457 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
2458 GtkWidget **entry, gint *count,
2459 const gchar *label_str,
2460 gboolean is_addr_entry)
2464 if (GTK_TABLE(table)->nrows < (*count) + 1)
2465 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
2467 *hbox = gtk_hbox_new(FALSE, 0);
2468 label = gtk_label_new
2469 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
2470 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
2471 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
2473 *entry = gtk_entry_new();
2474 gtk_table_attach_defaults
2475 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1);
2476 if (GTK_TABLE(table)->nrows > (*count) + 1)
2477 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
2480 address_completion_register_entry(GTK_ENTRY(*entry));
2485 static Compose *compose_create(PrefsAccount *account)
2491 GtkWidget *handlebox;
2495 GtkWidget *table_vbox;
2497 GtkWidget *from_optmenu_hbox;
2498 GtkWidget *to_entry;
2500 GtkWidget *newsgroups_entry;
2501 GtkWidget *newsgroups_hbox;
2502 GtkWidget *subject_entry;
2503 GtkWidget *cc_entry;
2505 GtkWidget *bcc_entry;
2506 GtkWidget *bcc_hbox;
2507 GtkWidget *reply_entry;
2508 GtkWidget *reply_hbox;
2509 GtkWidget *followup_entry;
2510 GtkWidget *followup_hbox;
2514 GtkWidget *attach_scrwin;
2515 GtkWidget *attach_clist;
2517 GtkWidget *edit_vbox;
2518 GtkWidget *ruler_hbox;
2520 GtkWidget *scrolledwin;
2526 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
2527 guint n_menu_entries;
2528 GtkStyle *style, *new_style;
2531 gboolean success[1];
2533 GtkWidget *popupmenu;
2534 GtkWidget *menuitem;
2535 GtkItemFactory *popupfactory;
2536 GtkItemFactory *ifactory;
2541 g_return_val_if_fail(account != NULL, NULL);
2543 debug_print(_("Creating compose window...\n"));
2544 compose = g_new0(Compose, 1);
2546 compose->account = account;
2547 compose->orig_account = account;
2549 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2550 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
2551 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
2552 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
2553 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
2554 gtk_signal_connect(GTK_OBJECT(window), "destroy",
2555 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
2556 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
2557 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
2558 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
2559 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
2560 gtk_widget_realize(window);
2562 vbox = gtk_vbox_new(FALSE, 0);
2563 gtk_container_add(GTK_CONTAINER(window), vbox);
2565 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
2566 menubar = menubar_create(window, compose_entries,
2567 n_menu_entries, "<Compose>", compose);
2568 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
2570 handlebox = gtk_handle_box_new();
2571 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
2573 compose_toolbar_create(compose, handlebox);
2575 vbox2 = gtk_vbox_new(FALSE, 2);
2576 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
2577 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
2579 table_vbox = gtk_vbox_new(FALSE, 0);
2580 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
2581 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
2584 table = gtk_table_new(8, 2, FALSE);
2585 gtk_box_pack_start(GTK_BOX(table_vbox), table, FALSE, TRUE, 0);
2587 /* option menu for selecting accounts */
2588 hbox = gtk_hbox_new(FALSE, 0);
2589 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
2590 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
2591 gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, count, count + 1,
2593 from_optmenu_hbox = compose_account_option_menu_create(compose);
2594 gtk_table_attach_defaults(GTK_TABLE(table), from_optmenu_hbox,
2595 1, 2, count, count + 1);
2596 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
2599 /* header labels and entries */
2600 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
2602 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
2603 &count, "Newsgroups:", FALSE);
2604 compose_add_entry_field(table, &hbox, &subject_entry, &count,
2606 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
2608 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
2610 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
2612 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
2613 "Followup-To:", FALSE);
2615 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
2617 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
2618 GTK_SIGNAL_FUNC(to_activated), compose);
2619 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
2620 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
2621 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
2622 GTK_SIGNAL_FUNC(subject_activated), compose);
2623 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
2624 GTK_SIGNAL_FUNC(cc_activated), compose);
2625 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
2626 GTK_SIGNAL_FUNC(bcc_activated), compose);
2627 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
2628 GTK_SIGNAL_FUNC(replyto_activated), compose);
2629 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
2630 GTK_SIGNAL_FUNC(followupto_activated), compose);
2632 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
2633 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2634 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
2635 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2636 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
2637 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2638 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
2639 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2640 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
2641 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2642 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
2643 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2644 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
2645 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2647 /* attachment list */
2648 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
2649 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
2650 GTK_POLICY_AUTOMATIC,
2652 gtk_widget_set_usize(attach_scrwin, -1, 80);
2654 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
2655 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
2657 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
2658 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
2659 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
2660 GTK_SELECTION_EXTENDED);
2661 for (i = 0; i < N_ATTACH_COLS; i++)
2662 GTK_WIDGET_UNSET_FLAGS
2663 (GTK_CLIST(attach_clist)->column[i].button,
2665 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
2667 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
2668 GTK_SIGNAL_FUNC(attach_selected), compose);
2669 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
2670 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
2671 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
2672 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
2675 gtk_drag_dest_set(attach_clist,
2676 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
2678 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
2679 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
2682 /* pane between attach clist and text */
2683 paned = gtk_vpaned_new();
2684 gtk_paned_add1(GTK_PANED(paned), attach_scrwin);
2685 gtk_widget_ref(paned);
2686 gtk_widget_show_all(paned);
2688 edit_vbox = gtk_vbox_new(FALSE, 0);
2689 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
2692 ruler_hbox = gtk_hbox_new(FALSE, 0);
2693 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
2695 ruler = gtk_shruler_new();
2696 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
2697 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
2699 gtk_widget_set_usize(ruler_hbox, 1, -1);
2702 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
2703 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
2704 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
2705 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
2706 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
2708 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
2709 (GTK_SCROLLED_WINDOW(scrolledwin)),
2710 gtk_scrolled_window_get_vadjustment
2711 (GTK_SCROLLED_WINDOW(scrolledwin)));
2712 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
2713 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
2714 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
2716 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
2718 gtk_signal_connect(GTK_OBJECT(text), "changed",
2719 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
2720 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
2721 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2722 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
2723 GTK_SIGNAL_FUNC(compose_button_press_cb),
2726 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
2727 GTK_SIGNAL_FUNC(compose_key_press_cb),
2730 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
2731 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
2735 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
2737 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
2738 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
2741 gtk_widget_show_all(vbox);
2743 style = gtk_widget_get_style(text);
2745 /* workaround for the slow down of GtkSText when using Pixmap theme */
2746 if (style->engine) {
2747 GtkThemeEngine *engine;
2749 engine = style->engine;
2750 style->engine = NULL;
2751 new_style = gtk_style_copy(style);
2752 style->engine = engine;
2754 new_style = gtk_style_copy(style);
2756 if (prefs_common.textfont) {
2759 charset = conv_get_current_charset();
2760 if (MB_CUR_MAX == 1) {
2763 Xstrdup_a(fontstr, prefs_common.textfont, );
2764 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
2766 font = gdk_font_load(fontstr);
2768 font = gdk_fontset_load(prefs_common.textfont);
2770 gdk_font_unref(new_style->font);
2771 new_style->font = font;
2775 gtk_widget_set_style(text, new_style);
2777 color[0] = quote_color;
2778 cmap = gdk_window_get_colormap(window->window);
2779 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
2780 if (success[0] == FALSE) {
2781 g_warning("Compose: color allocation failed.\n");
2782 style = gtk_widget_get_style(text);
2783 quote_color = style->black;
2786 n_entries = sizeof(compose_popup_entries) /
2787 sizeof(compose_popup_entries[0]);
2788 popupmenu = menu_create_items(compose_popup_entries, n_entries,
2789 "<Compose>", &popupfactory,
2792 ifactory = gtk_item_factory_from_widget(menubar);
2793 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
2794 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
2796 gtk_widget_hide(bcc_hbox);
2797 gtk_widget_hide(bcc_entry);
2798 gtk_widget_hide(reply_hbox);
2799 gtk_widget_hide(reply_entry);
2800 gtk_widget_hide(followup_hbox);
2801 gtk_widget_hide(followup_entry);
2802 gtk_widget_hide(ruler_hbox);
2803 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
2804 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
2805 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
2807 if (account->protocol == A_NNTP) {
2808 gtk_widget_hide(to_hbox);
2809 gtk_widget_hide(to_entry);
2810 gtk_widget_hide(cc_hbox);
2811 gtk_widget_hide(cc_entry);
2812 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
2813 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
2815 gtk_widget_hide(newsgroups_hbox);
2816 gtk_widget_hide(newsgroups_entry);
2817 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
2818 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
2821 switch (prefs_common.toolbar_style) {
2823 gtk_widget_hide(handlebox);
2826 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
2830 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
2834 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
2839 gtk_widget_show(window);
2841 address_completion_start(window);
2843 compose->window = window;
2844 compose->vbox = vbox;
2845 compose->menubar = menubar;
2846 compose->handlebox = handlebox;
2848 compose->vbox2 = vbox2;
2850 compose->table_vbox = table_vbox;
2851 compose->table = table;
2852 compose->to_hbox = to_hbox;
2853 compose->to_entry = to_entry;
2854 compose->newsgroups_hbox = newsgroups_hbox;
2855 compose->newsgroups_entry = newsgroups_entry;
2856 compose->subject_entry = subject_entry;
2857 compose->cc_hbox = cc_hbox;
2858 compose->cc_entry = cc_entry;
2859 compose->bcc_hbox = bcc_hbox;
2860 compose->bcc_entry = bcc_entry;
2861 compose->reply_hbox = reply_hbox;
2862 compose->reply_entry = reply_entry;
2863 compose->followup_hbox = followup_hbox;
2864 compose->followup_entry = followup_entry;
2866 compose->paned = paned;
2868 compose->attach_scrwin = attach_scrwin;
2869 compose->attach_clist = attach_clist;
2871 compose->edit_vbox = edit_vbox;
2872 compose->ruler_hbox = ruler_hbox;
2873 compose->ruler = ruler;
2874 compose->scrolledwin = scrolledwin;
2875 compose->text = text;
2877 compose->focused_editable = NULL;
2879 compose->popupmenu = popupmenu;
2880 compose->popupfactory = popupfactory;
2882 compose->mode = COMPOSE_NEW;
2884 compose->replyto = NULL;
2886 compose->bcc = NULL;
2887 compose->followup_to = NULL;
2888 compose->inreplyto = NULL;
2889 compose->references = NULL;
2890 compose->msgid = NULL;
2891 compose->boundary = NULL;
2893 compose->use_to = FALSE;
2894 compose->use_cc = FALSE;
2895 compose->use_bcc = FALSE;
2896 compose->use_replyto = FALSE;
2897 compose->use_followupto = FALSE;
2898 compose->use_attach = FALSE;
2901 compose->use_signing = FALSE;
2902 compose->use_encryption = FALSE;
2903 #endif /* USE_GPGME */
2905 compose->modified = FALSE;
2907 compose->return_receipt = FALSE;
2909 compose->to_list = NULL;
2910 compose->newsgroup_list = NULL;
2912 compose->exteditor_file = NULL;
2913 compose->exteditor_pid = -1;
2914 compose->exteditor_readdes = -1;
2915 compose->exteditor_tag = -1;
2917 compose_set_title(compose);
2919 if (account->protocol != A_NNTP) {
2920 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
2921 gtk_check_menu_item_set_active
2922 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2923 gtk_widget_set_sensitive(menuitem, FALSE);
2924 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
2925 gtk_check_menu_item_set_active
2926 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2927 gtk_widget_set_sensitive(menuitem, FALSE);
2929 if (account->set_autocc && account->auto_cc) {
2930 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
2931 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
2932 gtk_check_menu_item_set_active
2933 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2935 if (account->set_autobcc) {
2936 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
2937 gtk_check_menu_item_set_active
2938 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2939 if (account->auto_bcc)
2940 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
2943 if (account->set_autoreplyto) {
2944 menuitem = gtk_item_factory_get_item(ifactory,
2945 "/Message/Reply to");
2946 gtk_check_menu_item_set_active
2947 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2948 if (account->auto_replyto)
2949 gtk_entry_set_text(GTK_ENTRY(reply_entry),
2950 account->auto_replyto);
2953 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
2954 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2955 prefs_common.show_ruler);
2958 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
2959 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2960 prefs_common.default_sign);
2961 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
2962 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2963 prefs_common.default_encrypt);
2964 #endif /* USE_GPGME */
2966 addressbook_set_target_compose(compose);
2968 compose_list = g_list_append(compose_list, compose);
2973 #include "pixmaps/stock_mail_send.xpm"
2974 #include "pixmaps/stock_mail.xpm"
2975 #include "pixmaps/stock_paste.xpm"
2976 #include "pixmaps/stock_mail_attach.xpm"
2977 #include "pixmaps/stock_mail_compose.xpm"
2978 #include "pixmaps/linewrap.xpm"
2979 //#include "pixmaps/tb_mail_queue_send.xpm"
2980 #include "pixmaps/tb_address_book.xpm"
2982 #define CREATE_TOOLBAR_ICON(xpm_d) \
2984 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
2985 &container->style->white, \
2987 icon_wid = gtk_pixmap_new(icon, mask); \
2990 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
2995 GtkWidget *icon_wid;
2996 GtkWidget *send_btn;
2997 GtkWidget *sendl_btn;
2998 GtkWidget *draft_btn;
2999 GtkWidget *insert_btn;
3000 GtkWidget *attach_btn;
3002 GtkWidget *exteditor_btn;
3003 GtkWidget *linewrap_btn;
3004 GtkWidget *addrbook_btn;
3006 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
3008 gtk_container_add(GTK_CONTAINER(container), toolbar);
3009 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
3010 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
3011 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
3012 GTK_TOOLBAR_SPACE_LINE);
3014 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
3015 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3019 icon_wid, toolbar_send_cb, compose);
3021 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
3022 //CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm);
3023 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3025 _("Put into queue folder and send later"),
3027 icon_wid, toolbar_send_later_cb,
3030 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3031 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3033 _("Save to draft folder"),
3035 icon_wid, toolbar_draft_cb,
3038 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3040 CREATE_TOOLBAR_ICON(stock_paste_xpm);
3041 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3045 icon_wid, toolbar_insert_cb,
3048 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
3049 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3053 icon_wid, toolbar_attach_cb,
3056 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3058 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3059 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3061 _("Insert signature"),
3063 icon_wid, toolbar_sig_cb, compose);
3065 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3067 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
3068 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3070 _("Edit with external editor"),
3073 toolbar_ext_editor_cb,
3076 CREATE_TOOLBAR_ICON(linewrap_xpm);
3077 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3079 _("Wrap long lines"),
3082 toolbar_linewrap_cb,
3085 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3087 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
3088 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3092 icon_wid, toolbar_address_cb,
3095 compose->toolbar = toolbar;
3096 compose->send_btn = send_btn;
3097 compose->sendl_btn = sendl_btn;
3098 compose->draft_btn = draft_btn;
3099 compose->insert_btn = insert_btn;
3100 compose->attach_btn = attach_btn;
3101 compose->sig_btn = sig_btn;
3102 compose->exteditor_btn = exteditor_btn;
3103 compose->linewrap_btn = linewrap_btn;
3104 compose->addrbook_btn = addrbook_btn;
3106 gtk_widget_show_all(toolbar);
3109 #undef CREATE_TOOLBAR_ICON
3111 static GtkWidget *compose_account_option_menu_create(Compose *compose)
3117 gint num = 0, def_menu = 0;
3119 accounts = account_get_list();
3120 g_return_val_if_fail(accounts != NULL, NULL);
3122 hbox = gtk_hbox_new(FALSE, 0);
3123 optmenu = gtk_option_menu_new();
3124 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3125 menu = gtk_menu_new();
3127 for (; accounts != NULL; accounts = accounts->next, num++) {
3128 PrefsAccount *ac = (PrefsAccount *)accounts->data;
3129 GtkWidget *menuitem;
3132 if (ac == compose->account) def_menu = num;
3134 name = g_strdup_printf("%s <%s> (%s)",
3135 ac->name, ac->address, ac->account_name);
3136 MENUITEM_ADD(menu, menuitem, name, ac);
3138 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
3139 GTK_SIGNAL_FUNC(account_activated),
3143 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
3144 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
3149 static void compose_destroy(Compose *compose)
3152 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3155 /* NOTE: address_completion_end() does nothing with the window
3156 * however this may change. */
3157 address_completion_end(compose->window);
3159 slist_free_strings(compose->to_list);
3160 g_slist_free(compose->to_list);
3161 slist_free_strings(compose->newsgroup_list);
3162 g_slist_free(compose->newsgroup_list);
3164 procmsg_msginfo_free(compose->targetinfo);
3166 g_free(compose->replyto);
3167 g_free(compose->cc);
3168 g_free(compose->bcc);
3169 g_free(compose->newsgroups);
3170 g_free(compose->followup_to);
3172 g_free(compose->inreplyto);
3173 g_free(compose->references);
3174 g_free(compose->msgid);
3175 g_free(compose->boundary);
3177 g_free(compose->exteditor_file);
3179 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3181 compose_attach_info_free(ainfo);
3183 if (addressbook_get_target_compose() == compose)
3184 addressbook_set_target_compose(NULL);
3186 prefs_common.compose_width = compose->scrolledwin->allocation.width;
3187 prefs_common.compose_height = compose->window->allocation.height;
3189 gtk_widget_destroy(compose->paned);
3193 compose_list = g_list_remove(compose_list, compose);
3196 static void compose_attach_info_free(AttachInfo *ainfo)
3198 g_free(ainfo->file);
3199 g_free(ainfo->content_type);
3200 g_free(ainfo->name);
3204 static void compose_attach_remove_selected(Compose *compose)
3206 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3210 while (clist->selection != NULL) {
3211 row = GPOINTER_TO_INT(clist->selection->data);
3212 ainfo = gtk_clist_get_row_data(clist, row);
3213 compose_attach_info_free(ainfo);
3214 gtk_clist_remove(clist, row);
3218 static struct _AttachProperty
3221 GtkWidget *mimetype_entry;
3222 GtkWidget *encoding_optmenu;
3223 GtkWidget *path_entry;
3224 GtkWidget *filename_entry;
3226 GtkWidget *cancel_btn;
3229 static void compose_attach_property(Compose *compose)
3231 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3235 GtkOptionMenu *optmenu;
3237 if (!clist->selection) return;
3238 row = GPOINTER_TO_INT(clist->selection->data);
3240 ainfo = gtk_clist_get_row_data(clist, row);
3243 if (!attach_prop.window)
3244 compose_attach_property_create(&cancelled);
3245 gtk_widget_grab_focus(attach_prop.ok_btn);
3246 gtk_widget_show(attach_prop.window);
3247 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
3249 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
3250 if (ainfo->encoding == ENC_UNKNOWN)
3251 gtk_option_menu_set_history(optmenu, ENC_BASE64);
3253 gtk_option_menu_set_history(optmenu, ainfo->encoding);
3255 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
3256 ainfo->content_type ? ainfo->content_type : "");
3257 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
3258 ainfo->file ? ainfo->file : "");
3259 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
3260 ainfo->name ? ainfo->name : "");
3264 gchar *cnttype = NULL;
3268 GtkWidget *menuitem;
3272 if (cancelled == TRUE) {
3273 gtk_widget_hide(attach_prop.window);
3277 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
3278 if (*text != '\0') {
3281 text = g_strstrip(g_strdup(text));
3282 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
3283 cnttype = g_strdup(text);
3286 alertpanel_error(_("Invalid MIME type."));
3292 menu = gtk_option_menu_get_menu(optmenu);
3293 menuitem = gtk_menu_get_active(GTK_MENU(menu));
3294 ainfo->encoding = GPOINTER_TO_INT
3295 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
3297 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
3298 if (*text != '\0') {
3299 if (is_file_exist(text) &&
3300 (size = get_file_size(text)) > 0)
3301 file = g_strdup(text);
3304 (_("File doesn't exist or is empty."));
3310 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
3311 if (*text != '\0') {
3312 g_free(ainfo->name);
3313 ainfo->name = g_strdup(text);
3317 g_free(ainfo->content_type);
3318 ainfo->content_type = cnttype;
3321 g_free(ainfo->file);
3327 gtk_clist_set_text(clist, row, COL_MIMETYPE,
3328 ainfo->content_type);
3329 gtk_clist_set_text(clist, row, COL_SIZE,
3330 to_human_readable(ainfo->size));
3331 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
3333 gtk_widget_hide(attach_prop.window);
3338 #define SET_LABEL_AND_ENTRY(str, entry, top) \
3340 label = gtk_label_new(str); \
3341 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
3342 GTK_FILL, 0, 0, 0); \
3343 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
3345 entry = gtk_entry_new(); \
3346 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
3347 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
3350 static void compose_attach_property_create(gboolean *cancelled)
3356 GtkWidget *mimetype_entry;
3359 GtkWidget *optmenu_menu;
3360 GtkWidget *menuitem;
3361 GtkWidget *path_entry;
3362 GtkWidget *filename_entry;
3365 GtkWidget *cancel_btn;
3367 debug_print("Creating attach_property window...\n");
3369 window = gtk_window_new(GTK_WINDOW_DIALOG);
3370 gtk_widget_set_usize(window, 480, -1);
3371 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
3372 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
3373 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
3374 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
3375 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3376 GTK_SIGNAL_FUNC(attach_property_delete_event),
3378 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
3379 GTK_SIGNAL_FUNC(attach_property_key_pressed),
3382 vbox = gtk_vbox_new(FALSE, 8);
3383 gtk_container_add(GTK_CONTAINER(window), vbox);
3385 table = gtk_table_new(4, 2, FALSE);
3386 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
3387 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
3388 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
3390 SET_LABEL_AND_ENTRY(_("MIME type"), mimetype_entry, 0);
3392 label = gtk_label_new(_("Encoding"));
3393 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
3395 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3397 hbox = gtk_hbox_new(FALSE, 0);
3398 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
3399 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3401 optmenu = gtk_option_menu_new();
3402 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3404 optmenu_menu = gtk_menu_new();
3405 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
3406 gtk_widget_set_sensitive(menuitem, FALSE);
3407 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
3408 gtk_widget_set_sensitive(menuitem, FALSE);
3409 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
3410 gtk_widget_set_sensitive(menuitem, FALSE);
3411 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
3413 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
3415 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
3416 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
3418 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
3419 &cancel_btn, _("Cancel"), NULL, NULL);
3420 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
3421 gtk_widget_grab_default(ok_btn);
3423 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
3424 GTK_SIGNAL_FUNC(attach_property_ok),
3426 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
3427 GTK_SIGNAL_FUNC(attach_property_cancel),
3430 gtk_widget_show_all(vbox);
3432 attach_prop.window = window;
3433 attach_prop.mimetype_entry = mimetype_entry;
3434 attach_prop.encoding_optmenu = optmenu;
3435 attach_prop.path_entry = path_entry;
3436 attach_prop.filename_entry = filename_entry;
3437 attach_prop.ok_btn = ok_btn;
3438 attach_prop.cancel_btn = cancel_btn;
3441 #undef SET_LABEL_AND_ENTRY
3443 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
3449 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
3455 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
3456 gboolean *cancelled)
3464 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
3465 gboolean *cancelled)
3467 if (event && event->keyval == GDK_Escape) {
3473 static void compose_exec_ext_editor(Compose *compose)
3479 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
3480 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3482 if (pipe(pipe_fds) < 0) {
3487 if ((pid = fork()) < 0) {
3493 /* close the write side of the pipe */
3496 compose->exteditor_file = g_strdup(tmp);
3497 compose->exteditor_pid = pid;
3498 compose->exteditor_readdes = pipe_fds[0];
3500 compose_set_ext_editor_sensitive(compose, FALSE);
3502 compose->exteditor_tag =
3503 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
3504 compose_input_cb, compose);
3505 } else { /* process-monitoring process */
3511 /* close the read side of the pipe */
3514 if (compose_write_body_to_file(compose, tmp) < 0) {
3515 fd_write(pipe_fds[1], "2\n", 2);
3519 pid_ed = compose_exec_ext_editor_real(tmp);
3521 fd_write(pipe_fds[1], "1\n", 2);
3525 /* wait until editor is terminated */
3526 waitpid(pid_ed, NULL, 0);
3528 fd_write(pipe_fds[1], "0\n", 2);
3535 static gint compose_exec_ext_editor_real(const gchar *file)
3537 static gchar *def_cmd = "emacs %s";
3543 g_return_val_if_fail(file != NULL, -1);
3545 if ((pid = fork()) < 0) {
3550 if (pid != 0) return pid;
3552 /* grandchild process */
3554 if (setpgid(0, getppid()))
3557 if (prefs_common.ext_editor_cmd &&
3558 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
3559 *(p + 1) == 's' && !strchr(p + 2, '%')) {
3560 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
3562 if (prefs_common.ext_editor_cmd)
3563 g_warning(_("External editor command line is invalid: `%s'\n"),
3564 prefs_common.ext_editor_cmd);
3565 g_snprintf(buf, sizeof(buf), def_cmd, file);
3568 cmdline = g_strsplit(buf, " ", 1024);
3569 execvp(cmdline[0], cmdline);
3572 g_strfreev(cmdline);
3577 static gboolean compose_ext_editor_kill(Compose *compose)
3579 pid_t pgid = compose->exteditor_pid * -1;
3582 ret = kill(pgid, 0);
3584 if (ret == 0 || (ret == -1 && EPERM == errno)) {
3588 msg = g_strdup_printf
3589 (_("The external editor is still working.\n"
3590 "Force terminating the process?\n"
3591 "process group id: %d"), -pgid);
3592 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
3595 if (val == G_ALERTDEFAULT) {
3596 gdk_input_remove(compose->exteditor_tag);
3597 close(compose->exteditor_readdes);
3599 if (kill(pgid, SIGTERM) < 0) perror("kill");
3600 waitpid(compose->exteditor_pid, NULL, 0);
3602 g_warning(_("Terminated process group id: %d"), -pgid);
3603 g_warning(_("Temporary file: %s"),
3604 compose->exteditor_file);
3606 compose_set_ext_editor_sensitive(compose, TRUE);
3608 g_free(compose->exteditor_file);
3609 compose->exteditor_file = NULL;
3610 compose->exteditor_pid = -1;
3611 compose->exteditor_readdes = -1;
3612 compose->exteditor_tag = -1;
3620 static void compose_input_cb(gpointer data, gint source,
3621 GdkInputCondition condition)
3624 Compose *compose = (Compose *)data;
3627 debug_print(_("Compose: input from monitoring process\n"));
3629 gdk_input_remove(compose->exteditor_tag);
3632 if (read(source, &buf[i], 1) < 1) {
3636 if (buf[i] == '\n') {
3641 if (i == sizeof(buf) - 1)
3645 waitpid(compose->exteditor_pid, NULL, 0);
3647 if (buf[0] == '0') { /* success */
3648 GtkSText *text = GTK_STEXT(compose->text);
3650 gtk_stext_freeze(text);
3651 gtk_stext_set_point(text, 0);
3652 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
3653 compose_insert_file(compose, compose->exteditor_file);
3654 compose_changed_cb(NULL, compose);
3655 gtk_stext_thaw(text);
3657 if (unlink(compose->exteditor_file) < 0)
3658 FILE_OP_ERROR(compose->exteditor_file, "unlink");
3659 } else if (buf[0] == '1') { /* failed */
3660 g_warning(_("Couldn't exec external editor\n"));
3661 if (unlink(compose->exteditor_file) < 0)
3662 FILE_OP_ERROR(compose->exteditor_file, "unlink");
3663 } else if (buf[0] == '2') {
3664 g_warning(_("Couldn't write to file\n"));
3665 } else if (buf[0] == '3') {
3666 g_warning(_("Pipe read failed\n"));
3671 compose_set_ext_editor_sensitive(compose, TRUE);
3673 g_free(compose->exteditor_file);
3674 compose->exteditor_file = NULL;
3675 compose->exteditor_pid = -1;
3676 compose->exteditor_readdes = -1;
3677 compose->exteditor_tag = -1;
3680 static void compose_set_ext_editor_sensitive(Compose *compose,
3683 GtkItemFactory *ifactory;
3685 ifactory = gtk_item_factory_from_widget(compose->menubar);
3687 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
3688 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
3689 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
3691 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
3692 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
3693 menu_set_sensitive(ifactory, "/Edit/Wrap long lines", sensitive);
3694 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
3697 gtk_widget_set_sensitive(compose->text, sensitive);
3698 gtk_widget_set_sensitive(compose->send_btn, sensitive);
3699 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
3700 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
3701 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
3702 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
3703 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
3704 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
3707 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
3711 cursor_pos = (text->cursor_pos_x - extra) / char_width;
3712 cursor_pos = MAX(cursor_pos, 0);
3717 /* callback functions */
3719 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
3720 * includes "non-client" (windows-izm) in calculation, so this calculation
3721 * may not be accurate.
3723 static gboolean compose_edit_size_alloc(GtkEditable *widget,
3724 GtkAllocation *allocation,
3725 GtkSHRuler *shruler)
3727 if (prefs_common.show_ruler) {
3729 gint line_width_in_chars;
3731 char_width = gtkut_get_font_width
3732 (GTK_WIDGET(widget)->style->font);
3733 line_width_in_chars =
3734 (allocation->width - allocation->x) / char_width;
3736 /* got the maximum */
3737 gtk_ruler_set_range(GTK_RULER(shruler),
3738 0.0, line_width_in_chars,
3739 calc_cursor_xpos(GTK_STEXT(widget),
3742 /*line_width_in_chars*/ char_width);
3748 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
3750 compose_send_cb(data, 0, NULL);
3753 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
3755 compose_send_later_cb(data, 0, NULL);
3758 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
3760 compose_draft_cb(data, 0, NULL);
3763 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
3765 compose_insert_file_cb(data, 0, NULL);
3768 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
3770 compose_attach_cb(data, 0, NULL);
3773 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
3775 Compose *compose = (Compose *)data;
3777 compose_insert_sig(compose);
3780 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
3782 Compose *compose = (Compose *)data;
3784 compose_exec_ext_editor(compose);
3787 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
3789 Compose *compose = (Compose *)data;
3791 compose_wrap_line(compose);
3794 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
3796 compose_address_cb(data, 0, NULL);
3799 static void account_activated(GtkMenuItem *menuitem, gpointer data)
3801 Compose *compose = (Compose *)data;
3805 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
3806 g_return_if_fail(ac != NULL);
3808 if (ac != compose->account) {
3809 compose->account = ac;
3810 compose_set_title(compose);
3814 static void attach_selected(GtkCList *clist, gint row, gint column,
3815 GdkEvent *event, gpointer data)
3817 Compose *compose = (Compose *)data;
3819 if (event && event->type == GDK_2BUTTON_PRESS)
3820 compose_attach_property(compose);
3823 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
3826 Compose *compose = (Compose *)data;
3827 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3832 if (event->button == 3) {
3833 if ((clist->selection && !clist->selection->next) ||
3834 !clist->selection) {
3835 gtk_clist_unselect_all(clist);
3836 if (gtk_clist_get_selection_info(clist,
3839 gtk_clist_select_row(clist, row, column);
3840 gtkut_clist_set_focus_row(clist, row);
3843 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
3844 NULL, NULL, event->button, event->time);
3848 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
3851 Compose *compose = (Compose *)data;
3855 switch (event->keyval) {
3857 compose_attach_remove_selected(compose);
3862 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
3864 Compose *compose = (Compose *)data;
3867 val = compose_send(compose);
3869 if (val == 0) gtk_widget_destroy(compose->window);
3872 static void compose_send_later_cb(gpointer data, guint action,
3875 Compose *compose = (Compose *)data;
3877 gchar *to, *newsgroups;
3879 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3880 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3881 if (*to == '\0' && *newsgroups == '\0') {
3882 alertpanel_error(_("Recipient is not specified."));
3886 g_snprintf(tmp, 22, "%s%ctmpmsg%d",
3887 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3889 if (prefs_common.linewrap_at_send)
3890 compose_wrap_line(compose);
3892 if (compose_write_to_file(compose, tmp, FALSE) < 0 ||
3893 compose_queue(compose, tmp) < 0) {
3894 alertpanel_error(_("Can't queue the message."));
3898 if (prefs_common.savemsg) {
3899 if (compose_save_to_outbox(compose, tmp) < 0)
3901 (_("Can't save the message to outbox."));
3904 if (unlink(tmp) < 0)
3905 FILE_OP_ERROR(tmp, "unlink");
3907 gtk_widget_destroy(compose->window);
3910 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
3912 Compose *compose = (Compose *)data;
3916 draft = folder_get_default_draft();
3917 folder_item_scan(draft);
3919 if (procmsg_msg_exist(compose->targetinfo) &&
3920 compose->targetinfo->folder == draft) {
3921 if (folder_item_remove_msg(draft,
3922 compose->targetinfo->msgnum) < 0)
3923 g_warning(_("can't remove the old draft message\n"));
3925 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
3926 G_DIR_SEPARATOR, (gint)compose);
3928 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
3933 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
3941 //folderview_scan_folder_a(DRAFT_DIR, TRUE);
3943 gtk_widget_destroy(compose->window);
3946 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
3948 Compose *compose = (Compose *)data;
3951 file = filesel_select_file(_("Select file"), NULL);
3954 compose_attach_append(compose, file, MIME_UNKNOWN);
3957 static void compose_insert_file_cb(gpointer data, guint action,
3960 Compose *compose = (Compose *)data;
3963 file = filesel_select_file(_("Select file"), NULL);
3966 compose_insert_file(compose, file);
3969 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
3972 compose_close_cb(data, 0, NULL);
3976 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
3978 Compose *compose = (Compose *)data;
3981 if (compose->exteditor_tag != -1) {
3982 if (!compose_ext_editor_kill(compose))
3986 if (compose->modified) {
3987 val = alertpanel(_("Discard message"),
3988 _("This message has been modified. discard it?"),
3989 _("Discard"), _("to Draft"), _("Cancel"));
3992 case G_ALERTDEFAULT:
3994 case G_ALERTALTERNATE:
3995 compose_draft_cb(data, 0, NULL);
4002 gtk_widget_destroy(compose->window);
4005 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
4007 Compose *compose = (Compose *)data;
4009 addressbook_open(compose);
4012 static void compose_ext_editor_cb(gpointer data, guint action,
4015 Compose *compose = (Compose *)data;
4017 compose_exec_ext_editor(compose);
4020 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
4022 compose_destroy(compose);
4025 static void compose_cut_cb(Compose *compose)
4027 if (compose->focused_editable &&
4028 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4029 gtk_editable_cut_clipboard
4030 (GTK_EDITABLE(compose->focused_editable));
4033 static void compose_copy_cb(Compose *compose)
4035 if (compose->focused_editable &&
4036 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4037 gtk_editable_copy_clipboard
4038 (GTK_EDITABLE(compose->focused_editable));
4041 static void compose_paste_cb(Compose *compose)
4043 if (compose->focused_editable &&
4044 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4045 gtk_editable_paste_clipboard
4046 (GTK_EDITABLE(compose->focused_editable));
4049 static void compose_allsel_cb(Compose *compose)
4051 if (compose->focused_editable &&
4052 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4053 gtk_editable_select_region
4054 (GTK_EDITABLE(compose->focused_editable), 0, -1);
4057 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
4059 if (GTK_IS_EDITABLE(widget))
4060 compose->focused_editable = widget;
4063 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
4065 if (compose->modified == FALSE) {
4066 compose->modified = TRUE;
4067 compose_set_title(compose);
4071 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
4074 gtk_stext_set_point(GTK_STEXT(widget),
4075 gtk_editable_get_position(GTK_EDITABLE(widget)));
4079 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
4082 gtk_stext_set_point(GTK_STEXT(widget),
4083 gtk_editable_get_position(GTK_EDITABLE(widget)));
4087 static void compose_toggle_to_cb(gpointer data, guint action,
4090 Compose *compose = (Compose *)data;
4092 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4093 gtk_widget_show(compose->to_hbox);
4094 gtk_widget_show(compose->to_entry);
4095 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
4096 compose->use_to = TRUE;
4098 gtk_widget_hide(compose->to_hbox);
4099 gtk_widget_hide(compose->to_entry);
4100 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
4101 gtk_widget_queue_resize(compose->table_vbox);
4102 compose->use_to = FALSE;
4105 if (addressbook_get_target_compose() == compose)
4106 addressbook_set_target_compose(compose);
4109 static void compose_toggle_cc_cb(gpointer data, guint action,
4112 Compose *compose = (Compose *)data;
4114 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4115 gtk_widget_show(compose->cc_hbox);
4116 gtk_widget_show(compose->cc_entry);
4117 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
4118 compose->use_cc = TRUE;
4120 gtk_widget_hide(compose->cc_hbox);
4121 gtk_widget_hide(compose->cc_entry);
4122 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
4123 gtk_widget_queue_resize(compose->table_vbox);
4124 compose->use_cc = FALSE;
4127 if (addressbook_get_target_compose() == compose)
4128 addressbook_set_target_compose(compose);
4131 static void compose_toggle_bcc_cb(gpointer data, guint action,
4134 Compose *compose = (Compose *)data;
4136 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4137 gtk_widget_show(compose->bcc_hbox);
4138 gtk_widget_show(compose->bcc_entry);
4139 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
4140 compose->use_bcc = TRUE;
4142 gtk_widget_hide(compose->bcc_hbox);
4143 gtk_widget_hide(compose->bcc_entry);
4144 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
4145 gtk_widget_queue_resize(compose->table_vbox);
4146 compose->use_bcc = FALSE;
4149 if (addressbook_get_target_compose() == compose)
4150 addressbook_set_target_compose(compose);
4153 static void compose_toggle_replyto_cb(gpointer data, guint action,
4156 Compose *compose = (Compose *)data;
4158 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4159 gtk_widget_show(compose->reply_hbox);
4160 gtk_widget_show(compose->reply_entry);
4161 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
4162 compose->use_replyto = TRUE;
4164 gtk_widget_hide(compose->reply_hbox);
4165 gtk_widget_hide(compose->reply_entry);
4166 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
4167 gtk_widget_queue_resize(compose->table_vbox);
4168 compose->use_replyto = FALSE;
4172 static void compose_toggle_followupto_cb(gpointer data, guint action,
4175 Compose *compose = (Compose *)data;
4177 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4178 gtk_widget_show(compose->followup_hbox);
4179 gtk_widget_show(compose->followup_entry);
4180 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
4181 compose->use_followupto = TRUE;
4183 gtk_widget_hide(compose->followup_hbox);
4184 gtk_widget_hide(compose->followup_entry);
4185 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
4186 gtk_widget_queue_resize(compose->table_vbox);
4187 compose->use_followupto = FALSE;
4191 static void compose_toggle_attach_cb(gpointer data, guint action,
4194 Compose *compose = (Compose *)data;
4196 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4197 gtk_widget_ref(compose->edit_vbox);
4199 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4200 compose->edit_vbox);
4201 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
4202 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
4204 gtk_widget_show(compose->paned);
4206 gtk_widget_unref(compose->edit_vbox);
4207 gtk_widget_unref(compose->paned);
4209 compose->use_attach = TRUE;
4211 gtk_widget_ref(compose->paned);
4212 gtk_widget_ref(compose->edit_vbox);
4214 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4216 gtk_container_remove(GTK_CONTAINER(compose->paned),
4217 compose->edit_vbox);
4218 gtk_box_pack_start(GTK_BOX(compose->vbox2),
4219 compose->edit_vbox, TRUE, TRUE, 0);
4221 gtk_widget_unref(compose->edit_vbox);
4223 compose->use_attach = FALSE;
4228 static void compose_toggle_sign_cb(gpointer data, guint action,
4231 Compose *compose = (Compose *)data;
4233 if (GTK_CHECK_MENU_ITEM(widget)->active)
4234 compose->use_signing = TRUE;
4236 compose->use_signing = FALSE;
4239 static void compose_toggle_encrypt_cb(gpointer data, guint action,
4242 Compose *compose = (Compose *)data;
4244 if (GTK_CHECK_MENU_ITEM(widget)->active)
4245 compose->use_encryption = TRUE;
4247 compose->use_encryption = FALSE;
4249 #endif /* USE_GPGME */
4251 static void compose_toggle_ruler_cb(gpointer data, guint action,
4254 Compose *compose = (Compose *)data;
4256 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4257 gtk_widget_show(compose->ruler_hbox);
4258 prefs_common.show_ruler = TRUE;
4260 gtk_widget_hide(compose->ruler_hbox);
4261 gtk_widget_queue_resize(compose->edit_vbox);
4262 prefs_common.show_ruler = FALSE;
4266 static void compose_attach_drag_received_cb (GtkWidget *widget,
4267 GdkDragContext *drag_context,
4270 GtkSelectionData *data,
4275 Compose *compose = (Compose *)user_data;
4278 list = uri_list_extract_filenames((const gchar *)data->data);
4279 for (tmp = list; tmp != NULL; tmp = tmp->next)
4280 compose_attach_append(compose, (const gchar *)tmp->data,
4282 list_free_strings(list);
4286 static void compose_insert_drag_received_cb (GtkWidget *widget,
4287 GdkDragContext *drag_context,
4290 GtkSelectionData *data,
4295 Compose *compose = (Compose *)user_data;
4298 list = uri_list_extract_filenames((const gchar *)data->data);
4299 for (tmp = list; tmp != NULL; tmp = tmp->next)
4300 compose_insert_file(compose, (const gchar *)tmp->data);
4301 list_free_strings(list);
4305 static void to_activated(GtkWidget *widget, Compose *compose)
4307 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
4308 gtk_widget_grab_focus(compose->newsgroups_entry);
4310 gtk_widget_grab_focus(compose->subject_entry);
4313 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
4315 gtk_widget_grab_focus(compose->subject_entry);
4318 static void subject_activated(GtkWidget *widget, Compose *compose)
4320 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
4321 gtk_widget_grab_focus(compose->cc_entry);
4322 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4323 gtk_widget_grab_focus(compose->bcc_entry);
4324 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4325 gtk_widget_grab_focus(compose->reply_entry);
4326 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4327 gtk_widget_grab_focus(compose->followup_entry);
4329 gtk_widget_grab_focus(compose->text);
4332 static void cc_activated(GtkWidget *widget, Compose *compose)
4334 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4335 gtk_widget_grab_focus(compose->bcc_entry);
4336 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4337 gtk_widget_grab_focus(compose->reply_entry);
4338 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4339 gtk_widget_grab_focus(compose->followup_entry);
4341 gtk_widget_grab_focus(compose->text);
4344 static void bcc_activated(GtkWidget *widget, Compose *compose)
4346 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4347 gtk_widget_grab_focus(compose->reply_entry);
4348 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4349 gtk_widget_grab_focus(compose->followup_entry);
4351 gtk_widget_grab_focus(compose->text);
4354 static void replyto_activated(GtkWidget *widget, Compose *compose)
4356 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4357 gtk_widget_grab_focus(compose->followup_entry);
4359 gtk_widget_grab_focus(compose->text);
4362 static void followupto_activated(GtkWidget *widget, Compose *compose)
4364 gtk_widget_grab_focus(compose->text);
4367 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
4370 Compose *compose = (Compose *)data;
4372 if (GTK_CHECK_MENU_ITEM(widget)->active)
4373 compose->return_receipt = TRUE;
4375 compose->return_receipt = FALSE;