2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
31 #include <gtk/gtkitemfactory.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkclist.h>
36 #include <gtk/gtkctree.h>
37 #include <gtk/gtkvpaned.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkeditable.h>
40 #include <gtk/gtkwindow.h>
41 #include <gtk/gtksignal.h>
42 #include <gtk/gtkvbox.h>
43 #include <gtk/gtkcontainer.h>
44 #include <gtk/gtkhandlebox.h>
45 #include <gtk/gtktoolbar.h>
46 #include <gtk/gtktable.h>
47 #include <gtk/gtkhbox.h>
48 #include <gtk/gtklabel.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtkthemes.h>
51 #include <gtk/gtkdnd.h>
58 /* #include <sys/utsname.h> */
64 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
74 #include "mainwindow.h"
76 #include "addressbook.h"
77 #include "folderview.h"
82 #include "customheader.h"
83 #include "prefs_common.h"
84 #include "prefs_account.h"
87 #include "procheader.h"
89 #include "statusbar.h"
96 #include "alertpanel.h"
97 #include "manage_window.h"
98 #include "gtkshruler.h"
100 #include "addr_compl.h"
103 # include "rfc2015.h"
106 #include "quote_fmt.h"
115 #define N_ATTACH_COLS 3
117 #define B64_LINE_SIZE 57
118 #define B64_BUFFSIZE 77
120 #define MAX_REFERENCES_LEN 999
122 static GdkColor quote_color = {0, 0, 0, 0xbfff};
124 static GList *compose_list = NULL;
126 static Compose *compose_create (PrefsAccount *account);
127 static void compose_toolbar_create (Compose *compose,
128 GtkWidget *container);
129 static GtkWidget *compose_account_option_menu_create
131 static void compose_destroy (Compose *compose);
133 static gint compose_parse_header (Compose *compose,
135 static gchar *compose_parse_references (const gchar *ref,
137 static void compose_quote_file (Compose *compose,
140 static gchar *compose_quote_parse_fmt (Compose *compose,
143 static void compose_reply_set_entry (Compose *compose,
148 followup_and_reply_to);
149 static void compose_reedit_set_entry (Compose *compose,
151 static void compose_insert_sig (Compose *compose);
152 static void compose_insert_file (Compose *compose,
154 static void compose_attach_append (Compose *compose,
156 ContentType cnttype);
157 static void compose_attach_append_with_type(Compose *compose,
160 ContentType cnttype);
161 static void compose_wrap_line (Compose *compose);
162 static void compose_set_title (Compose *compose);
164 static PrefsAccount *compose_current_mail_account(void);
165 /* static gint compose_send (Compose *compose); */
166 static gint compose_write_to_file (Compose *compose,
169 static gint compose_write_body_to_file (Compose *compose,
171 static gint compose_save_to_outbox (Compose *compose,
173 static gint compose_queue (Compose *compose,
175 static void compose_write_attach (Compose *compose,
177 static gint compose_write_headers (Compose *compose,
179 const gchar *charset,
180 EncodingType encoding,
183 static void compose_convert_header (gchar *dest,
187 static void compose_generate_msgid (Compose *compose,
191 static void compose_attach_info_free (AttachInfo *ainfo);
192 static void compose_attach_remove_selected (Compose *compose);
194 static void compose_attach_property (Compose *compose);
195 static void compose_attach_property_create (gboolean *cancelled);
196 static void attach_property_ok (GtkWidget *widget,
197 gboolean *cancelled);
198 static void attach_property_cancel (GtkWidget *widget,
199 gboolean *cancelled);
200 static gint attach_property_delete_event (GtkWidget *widget,
202 gboolean *cancelled);
203 static void attach_property_key_pressed (GtkWidget *widget,
205 gboolean *cancelled);
207 static void compose_exec_ext_editor (Compose *compose);
208 static gint compose_exec_ext_editor_real (const gchar *file);
209 static gboolean compose_ext_editor_kill (Compose *compose);
210 static void compose_input_cb (gpointer data,
212 GdkInputCondition condition);
213 static void compose_set_ext_editor_sensitive (Compose *compose,
216 static gint calc_cursor_xpos (GtkSText *text,
220 /* callback functions */
222 static gboolean compose_edit_size_alloc (GtkEditable *widget,
223 GtkAllocation *allocation,
224 GtkSHRuler *shruler);
226 static void toolbar_send_cb (GtkWidget *widget,
228 static void toolbar_send_later_cb (GtkWidget *widget,
230 static void toolbar_draft_cb (GtkWidget *widget,
232 static void toolbar_insert_cb (GtkWidget *widget,
234 static void toolbar_attach_cb (GtkWidget *widget,
236 static void toolbar_sig_cb (GtkWidget *widget,
238 static void toolbar_ext_editor_cb (GtkWidget *widget,
240 static void toolbar_linewrap_cb (GtkWidget *widget,
242 static void toolbar_address_cb (GtkWidget *widget,
245 static void select_account(Compose * compose, PrefsAccount * ac);
246 static void account_activated (GtkMenuItem *menuitem,
249 static void attach_selected (GtkCList *clist,
254 static void attach_button_pressed (GtkWidget *widget,
255 GdkEventButton *event,
257 static void attach_key_pressed (GtkWidget *widget,
261 static void compose_send_cb (gpointer data,
264 static void compose_send_later_cb (gpointer data,
268 static void compose_draft_cb (gpointer data,
272 static void compose_attach_cb (gpointer data,
275 static void compose_insert_file_cb (gpointer data,
279 static void compose_close_cb (gpointer data,
282 static void compose_address_cb (gpointer data,
286 static void compose_ext_editor_cb (gpointer data,
290 static gint compose_delete_cb (GtkWidget *widget,
293 static void compose_destroy_cb (GtkWidget *widget,
296 static void compose_cut_cb (Compose *compose);
297 static void compose_copy_cb (Compose *compose);
298 static void compose_paste_cb (Compose *compose);
299 static void compose_allsel_cb (Compose *compose);
301 static void compose_grab_focus_cb (GtkWidget *widget,
304 static void compose_changed_cb (GtkEditable *editable,
306 static void compose_button_press_cb (GtkWidget *widget,
307 GdkEventButton *event,
310 static void compose_key_press_cb (GtkWidget *widget,
315 static void compose_toggle_to_cb (gpointer data,
318 static void compose_toggle_cc_cb (gpointer data,
321 static void compose_toggle_bcc_cb (gpointer data,
324 static void compose_toggle_replyto_cb (gpointer data,
327 static void compose_toggle_followupto_cb(gpointer data,
330 static void compose_toggle_attach_cb (gpointer data,
333 static void compose_toggle_ruler_cb (gpointer data,
337 static void compose_toggle_sign_cb (gpointer data,
340 static void compose_toggle_encrypt_cb (gpointer data,
344 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
347 static void compose_attach_drag_received_cb (GtkWidget *widget,
348 GdkDragContext *drag_context,
351 GtkSelectionData *data,
355 static void compose_insert_drag_received_cb (GtkWidget *widget,
356 GdkDragContext *drag_context,
359 GtkSelectionData *data,
364 static void to_activated (GtkWidget *widget,
366 static void newsgroups_activated (GtkWidget *widget,
368 static void subject_activated (GtkWidget *widget,
370 static void cc_activated (GtkWidget *widget,
372 static void bcc_activated (GtkWidget *widget,
374 static void replyto_activated (GtkWidget *widget,
376 static void followupto_activated (GtkWidget *widget,
378 static void compose_attach_parts(Compose * compose,
381 static gchar *compose_quote_fmt (Compose *compose,
384 const gchar * qmark);
386 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
388 gboolean ignore_replyto,
389 gboolean followup_and_reply_to);
391 Compose * compose_generic_new (PrefsAccount *account,
395 static GtkItemFactoryEntry compose_popup_entries[] =
397 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
398 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
399 {N_("/---"), NULL, NULL, 0, "<Separator>"},
400 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
403 static GtkItemFactoryEntry compose_entries[] =
405 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
406 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
407 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
408 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
409 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
410 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
412 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
413 {N_("/_Edit/_Undo"), "<control>Z", NULL, 0, NULL},
414 {N_("/_Edit/_Redo"), "<control>Y", NULL, 0, NULL},
415 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
416 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
417 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
418 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
419 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
420 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
421 {N_("/_Edit/Wrap long _lines"), "<alt>L", compose_wrap_line, 0, NULL},
422 {N_("/_Edit/Edit with e_xternal editor"), "<alt>X",
423 compose_ext_editor_cb, 0, NULL},
425 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
426 {N_("/_Message/_Send"), "<shift><control>S",
427 compose_send_cb, 0, NULL},
428 {N_("/_Message/Send _later"), "<shift><alt>S",
429 compose_send_later_cb, 0, NULL},
430 {N_("/_Message/Save to _draft folder"),
431 "<alt>D", compose_draft_cb, 0, NULL},
432 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
433 {N_("/_Message/_To"), NULL, compose_toggle_to_cb, 0, "<ToggleItem>"},
434 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb, 0, "<ToggleItem>"},
435 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb, 0, "<ToggleItem>"},
436 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
437 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
438 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
439 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
440 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
442 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
443 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb, 0, "<ToggleItem>"},
444 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
445 #endif /* USE_GPGME */
446 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
447 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
448 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
449 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
450 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb, 0, NULL},
451 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
452 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
455 static GtkTargetEntry compose_mime_types[] =
457 {"text/uri-list", 0, 0}
460 Compose * compose_new(PrefsAccount *account)
462 return compose_generic_new(account, NULL, NULL);
465 Compose * compose_new_with_recipient(PrefsAccount *account, const gchar *to)
467 return compose_generic_new(account, to, NULL);
470 Compose * compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
472 return compose_generic_new(account, NULL, item);
475 Compose * compose_generic_new(PrefsAccount *account, const gchar *to, FolderItem *item)
479 if (!account) account = cur_account;
480 g_return_val_if_fail(account != NULL, NULL);
482 compose = compose_create(account);
483 compose->mode = COMPOSE_NEW;
485 if (prefs_common.auto_sig)
486 compose_insert_sig(compose);
487 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
488 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
490 if (account->protocol != A_NNTP) {
492 compose_entry_append(compose, to, COMPOSE_TO);
493 gtk_widget_grab_focus(compose->subject_entry);
495 if(item && item->prefs->enable_default_to) {
496 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
498 gtk_widget_grab_focus(compose->to_entry);
501 if(item && item->prefs->request_return_receipt) {
502 GtkItemFactory *ifactory;
504 ifactory = gtk_item_factory_from_widget(compose->menubar);
505 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
509 compose_entry_append(compose, to, COMPOSE_NEWSGROUPS);
510 gtk_widget_grab_focus(compose->subject_entry);
512 gtk_widget_grab_focus(compose->newsgroups_entry);
518 #define CHANGE_FLAGS(msginfo) \
520 if (msginfo->folder->folder->change_flags != NULL) \
521 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
527 Compose * compose_new_followup_and_replyto(PrefsAccount *account,
528 const gchar *followupto, gchar * to)
532 if (!account) account = cur_account;
533 g_return_val_if_fail(account != NULL, NULL);
534 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
536 compose = compose_create(account);
537 compose->mode = COMPOSE_NEW;
539 if (prefs_common.auto_sig)
540 compose_insert_sig(compose);
541 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
542 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
544 compose_entry_append(compose, to, COMPOSE_TO);
545 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
546 gtk_widget_grab_focus(compose->subject_entry);
552 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
553 gboolean ignore_replyto)
555 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
558 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
560 gboolean ignore_replyto)
562 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
565 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
567 gboolean ignore_replyto,
568 gboolean followup_and_reply_to)
571 PrefsAccount *account;
572 PrefsAccount *reply_account;
575 g_return_if_fail(msginfo != NULL);
576 g_return_if_fail(msginfo->folder != NULL);
578 account = msginfo->folder->folder->account;
579 if (!account && msginfo->to && prefs_common.reply_account_autosel) {
581 Xstrdup_a(to, msginfo->to, return);
583 account = account_find_from_address(to);
585 if (!account) account = cur_account;
586 g_return_if_fail(account != NULL);
588 if (ignore_replyto && account->protocol == A_NNTP &&
589 !followup_and_reply_to) {
591 account_find_from_address(account->address);
593 reply_account = compose_current_mail_account();
597 reply_account = account;
598 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
599 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
601 CHANGE_FLAGS(msginfo);
603 compose = compose_create(reply_account);
604 compose->mode = COMPOSE_REPLY;
607 if (followup_and_reply_to) {
608 gtk_widget_show(compose->to_hbox);
609 gtk_widget_show(compose->to_entry);
610 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
611 compose->use_to = TRUE;
614 if (compose_parse_header(compose, msginfo) < 0) return;
615 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
616 followup_and_reply_to);
618 text = GTK_STEXT(compose->text);
619 gtk_stext_freeze(text);
625 if ((fp = procmime_get_text_part(msginfo)) == NULL)
626 g_warning(_("Can't get text part\n"));
630 if (prefs_common.quotemark && *prefs_common.quotemark)
631 qmark = prefs_common.quotemark;
635 quote_str = compose_quote_fmt(compose, msginfo,
636 prefs_common.quotefmt,
640 quote_str = compose_quote_parse_fmt
641 (compose, msginfo, prefs_common.quotefmt);
644 if (quote_str != NULL)
645 gtk_stext_insert(text, NULL, NULL, NULL,
647 /* g_free(quote_str); */
648 /* compose_quote_file(compose, msginfo, fp); */
653 if (prefs_common.auto_sig)
654 compose_insert_sig(compose);
655 gtk_editable_set_position(GTK_EDITABLE(text), 0);
656 gtk_stext_set_point(text, 0);
658 gtk_stext_thaw(text);
659 gtk_widget_grab_focus(compose->text);
663 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
668 g_return_val_if_fail(mimeinfo != NULL, NULL);
670 base = mimeinfo->filename ? mimeinfo->filename
671 : mimeinfo->name ? mimeinfo->name : NULL;
673 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
674 filename = g_strdup_printf("%s%smimetmp%i.html",
681 base = base ? base : "";
682 base = g_basename(base);
684 filename = g_strdup_printf("%s%smimetmp%i",
692 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
698 static gchar * mime_extract_file(gchar * source, MimeInfo *partinfo)
702 if (!partinfo) return;
704 filename = procmime_get_file_name(partinfo);
706 if (procmime_get_part(filename, source, partinfo) < 0)
708 (_("Can't get the part of multipart message."));
713 static void compose_attach_parts(Compose * compose,
723 gint boundary_len = 0;
725 glong fpos, prev_fpos;
730 g_return_if_fail(msginfo != NULL);
734 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
735 mimeinfo = procmime_scan_mime_header(fp);
736 if (!mimeinfo) break;
738 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
739 rfc2015_is_encrypted(mimeinfo)) {
740 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
742 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
743 !msginfo->plaintext_file &&
744 !msginfo->decryption_failed) {
745 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
746 if (msginfo->plaintext_file &&
747 !msginfo->decryption_failed) {
755 #else /* !USE_GPGME */
756 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
757 mimeinfo = procmime_scan_mime_header(fp);
758 #endif /* USE_GPGME */
761 if (!mimeinfo) return;
762 if (mimeinfo->mime_type == MIME_TEXT)
765 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
767 g_return_if_fail(mimeinfo != NULL);
768 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
770 if (mimeinfo->mime_type == MIME_MULTIPART) {
771 g_return_if_fail(mimeinfo->boundary != NULL);
772 g_return_if_fail(mimeinfo->sub == NULL);
774 g_return_if_fail(fp != NULL);
776 boundary = mimeinfo->boundary;
779 boundary_len = strlen(boundary);
781 /* look for first boundary */
782 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
783 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
790 if ((fpos = ftell(fp)) < 0) {
796 for (npart = 0;; npart++) {
798 gboolean eom = FALSE;
802 partinfo = procmime_scan_mime_header(fp);
803 if (!partinfo) break;
806 procmime_mimeinfo_insert(mimeinfo, partinfo);
808 procmime_mimeinfo_free(partinfo);
810 /* look for next boundary */
812 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
813 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
814 if (buf[2 + boundary_len] == '-' &&
815 buf[2 + boundary_len + 1] == '-')
821 eom = TRUE; /* broken MIME message */
824 partinfo->size = fpos - prev_fpos - strlen(buf);
829 source = procmsg_get_message_file_path(msginfo);
831 g_return_if_fail(mimeinfo != NULL);
833 if (!mimeinfo->main && mimeinfo->parent)
835 filename = mime_extract_file(source, mimeinfo);
837 compose_attach_append_with_type(compose, filename,
838 mimeinfo->content_type,
839 mimeinfo->mime_type);
844 if (mimeinfo->sub && mimeinfo->sub->children)
846 filename = mime_extract_file(source, mimeinfo->sub);
848 compose_attach_append_with_type(compose, filename,
849 mimeinfo->content_type,
850 mimeinfo->sub->mime_type);
855 if (mimeinfo->children) {
858 child = mimeinfo->children;
860 filename = mime_extract_file(source, child);
862 compose_attach_append_with_type(compose, filename,
874 procmime_mimeinfo_free_all(mimeinfo);
878 #define INSERT_FW_HEADER(var, hdr) \
879 if (msginfo->var && *msginfo->var) { \
880 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
881 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
882 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
885 Compose * compose_forward(PrefsAccount * account, MsgInfo *msginfo,
889 /* PrefsAccount *account; */
894 g_return_val_if_fail(msginfo != NULL, NULL);
895 g_return_val_if_fail(msginfo->folder != NULL, NULL);
897 if (account == NULL) {
898 account = cur_account;
900 account = msginfo->folder->folder->account;
901 if (!account) account = cur_account;
904 g_return_val_if_fail(account != NULL, NULL);
906 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
907 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
908 CHANGE_FLAGS(msginfo);
910 compose = compose_create(account);
911 compose->mode = COMPOSE_FORWARD;
913 if (msginfo->subject && *msginfo->subject) {
914 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
915 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
919 text = GTK_STEXT(compose->text);
920 gtk_stext_freeze(text);
925 msgfile = procmsg_get_message_file_path(msginfo);
926 if (!is_file_exist(msgfile))
927 g_warning(_("%s: file not exist\n"), msgfile);
929 compose_attach_append(compose, msgfile,
930 MIME_MESSAGE_RFC822);
937 if ((fp = procmime_get_text_part(msginfo)) == NULL)
938 g_warning(_("Can't get text part\n"));
942 if (prefs_common.fw_quotemark &&
943 *prefs_common.fw_quotemark)
944 qmark = prefs_common.fw_quotemark;
948 quote_str = compose_quote_fmt(compose, msginfo,
949 prefs_common.fw_quotefmt,
952 if (quote_str != NULL)
953 gtk_stext_insert(text, NULL, NULL, NULL,
959 compose_attach_parts(compose, msginfo);
962 if (prefs_common.auto_sig)
963 compose_insert_sig(compose);
964 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
965 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
967 gtk_stext_thaw(text);
968 if (account->protocol != A_NNTP)
969 gtk_widget_grab_focus(compose->to_entry);
971 gtk_widget_grab_focus(compose->newsgroups_entry);
976 #undef INSERT_FW_HEADER
978 Compose * compose_forward_multiple(PrefsAccount * account,
979 GSList *msginfo_list)
986 g_return_val_if_fail(msginfo_list != NULL, NULL);
988 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
989 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
993 if (account == NULL) {
994 account = cur_account;
996 account = msginfo->folder->folder->account;
997 if (!account) account = cur_account;
1000 g_return_val_if_fail(account != NULL, NULL);
1002 compose = compose_create(account);
1003 compose->mode = COMPOSE_FORWARD;
1005 text = GTK_STEXT(compose->text);
1006 gtk_stext_freeze(text);
1008 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1009 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1010 if (!is_file_exist(msgfile))
1011 g_warning(_("%s: file not exist\n"), msgfile);
1013 compose_attach_append(compose, msgfile,
1014 MIME_MESSAGE_RFC822);
1018 if (prefs_common.auto_sig)
1019 compose_insert_sig(compose);
1020 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1021 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1023 gtk_stext_thaw(text);
1024 if (account->protocol != A_NNTP)
1025 gtk_widget_grab_focus(compose->to_entry);
1027 gtk_widget_grab_focus(compose->newsgroups_entry);
1032 void compose_reedit(MsgInfo *msginfo)
1035 PrefsAccount *account;
1038 gchar buf[BUFFSIZE];
1040 g_return_if_fail(msginfo != NULL);
1041 g_return_if_fail(msginfo->folder != NULL);
1043 account = msginfo->folder->folder->account;
1044 if (!account) account = cur_account;
1045 g_return_if_fail(account != NULL);
1047 compose = compose_create(account);
1048 compose->mode = COMPOSE_REEDIT_DRAFT;
1049 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1051 if (compose_parse_header(compose, msginfo) < 0) return;
1052 compose_reedit_set_entry(compose, msginfo);
1054 text = GTK_STEXT(compose->text);
1055 gtk_stext_freeze(text);
1057 if ((fp = procmime_get_text_part(msginfo)) == NULL)
1058 g_warning(_("Can't get text part\n"));
1060 while (fgets(buf, sizeof(buf), fp) != NULL)
1061 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1064 compose_attach_parts(compose, msginfo);
1066 gtk_stext_thaw(text);
1067 gtk_widget_grab_focus(compose->text);
1070 GList *compose_get_compose_list(void)
1072 return compose_list;
1075 void compose_entry_append(Compose *compose, const gchar *address,
1076 ComposeEntryType type)
1081 if (!address || *address == '\0') return;
1085 entry = GTK_ENTRY(compose->cc_entry);
1088 entry = GTK_ENTRY(compose->bcc_entry);
1090 case COMPOSE_NEWSGROUPS:
1091 entry = GTK_ENTRY(compose->newsgroups_entry);
1095 entry = GTK_ENTRY(compose->to_entry);
1099 text = gtk_entry_get_text(entry);
1101 gtk_entry_append_text(entry, ", ");
1102 gtk_entry_append_text(entry, address);
1105 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1107 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1108 {"Cc:", NULL, FALSE},
1109 {"References:", NULL, FALSE},
1110 {"Bcc:", NULL, FALSE},
1111 {"Newsgroups:", NULL, FALSE},
1112 {"Followup-To:", NULL, FALSE},
1113 {NULL, NULL, FALSE}};
1127 g_return_val_if_fail(msginfo != NULL, -1);
1129 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1130 procheader_get_header_fields(fp, hentry);
1133 if (hentry[H_REPLY_TO].body != NULL) {
1134 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1135 compose->replyto = hentry[H_REPLY_TO].body;
1136 hentry[H_REPLY_TO].body = NULL;
1138 if (hentry[H_CC].body != NULL) {
1139 conv_unmime_header_overwrite(hentry[H_CC].body);
1140 compose->cc = hentry[H_CC].body;
1141 hentry[H_CC].body = NULL;
1143 if (hentry[H_REFERENCES].body != NULL) {
1144 if (compose->mode == COMPOSE_REEDIT_DRAFT)
1145 compose->references = hentry[H_REFERENCES].body;
1147 compose->references = compose_parse_references
1148 (hentry[H_REFERENCES].body, msginfo->msgid);
1149 g_free(hentry[H_REFERENCES].body);
1151 hentry[H_REFERENCES].body = NULL;
1153 if (hentry[H_BCC].body != NULL) {
1154 if (compose->mode == COMPOSE_REEDIT_DRAFT) {
1155 conv_unmime_header_overwrite(hentry[H_BCC].body);
1156 compose->bcc = hentry[H_BCC].body;
1158 g_free(hentry[H_BCC].body);
1159 hentry[H_BCC].body = NULL;
1161 if (hentry[H_NEWSGROUPS].body != NULL) {
1162 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1163 hentry[H_NEWSGROUPS].body = NULL;
1165 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1166 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1167 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1168 hentry[H_FOLLOWUP_TO].body = NULL;
1171 if (compose->mode == COMPOSE_REEDIT_DRAFT && msginfo->inreplyto)
1172 compose->inreplyto = g_strdup(msginfo->inreplyto);
1173 else if (compose->mode != COMPOSE_REEDIT_DRAFT &&
1174 msginfo->msgid && *msginfo->msgid) {
1175 compose->inreplyto = g_strdup(msginfo->msgid);
1177 if (!compose->references) {
1178 if (msginfo->inreplyto && *msginfo->inreplyto)
1179 compose->references =
1180 g_strdup_printf("<%s>\n\t<%s>",
1184 compose->references =
1185 g_strconcat("<", msginfo->msgid, ">",
1193 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1195 GSList *ref_id_list, *cur;
1199 ref_id_list = references_list_append(NULL, ref);
1200 if (!ref_id_list) return NULL;
1201 if (msgid && *msgid)
1202 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1207 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1208 /* "<" + Message-ID + ">" + CR+LF+TAB */
1209 len += strlen((gchar *)cur->data) + 5;
1211 if (len > MAX_REFERENCES_LEN) {
1212 /* remove second message-ID */
1213 if (ref_id_list && ref_id_list->next &&
1214 ref_id_list->next->next) {
1215 g_free(ref_id_list->next->data);
1216 ref_id_list = g_slist_remove
1217 (ref_id_list, ref_id_list->next->data);
1219 slist_free_strings(ref_id_list);
1220 g_slist_free(ref_id_list);
1227 new_ref = g_string_new("");
1228 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1229 if (new_ref->len > 0)
1230 g_string_append(new_ref, "\n\t");
1231 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1234 slist_free_strings(ref_id_list);
1235 g_slist_free(ref_id_list);
1237 new_ref_str = new_ref->str;
1238 g_string_free(new_ref, FALSE);
1244 static void compose_quote_file(Compose *compose, MsgInfo *msginfo, FILE *fp)
1246 GtkSText *text = GTK_STEXT(compose->text);
1249 GdkColor *qcolor = NULL;
1250 gchar buf[BUFFSIZE];
1252 gchar *linep, *cur, *leftp;
1253 gint line_len, cur_len;
1258 // if (prefs_common.enable_color) qcolor = "e_color;
1259 if (prefs_common.quotemark && *prefs_common.quotemark)
1260 qmark = prefs_common.quotemark;
1263 quote_str = compose_quote_parse_fmt(compose, msginfo, qmark);
1264 g_return_if_fail(quote_str != NULL);
1265 qlen = strlen(quote_str);
1267 if (!prefs_common.linewrap_quote ||
1268 prefs_common.linewrap_len <= qlen) {
1269 while (fgets(buf, sizeof(buf), fp) != NULL) {
1270 gtk_stext_insert(text, NULL, qcolor, NULL,
1272 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1278 wrap_len = prefs_common.linewrap_len - qlen;
1280 while (fgets(buf, sizeof(buf), fp) != NULL) {
1282 str_len = strlen(buf);
1284 if (str_len <= wrap_len) {
1285 gtk_stext_insert(text, NULL, qcolor, NULL,
1287 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1288 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1292 linep = cur = leftp = buf;
1293 line_len = cur_len = 0;
1295 while (*cur != '\0') {
1296 ch_len = mblen(cur, MB_CUR_MAX);
1297 if (ch_len < 0) ch_len = 1;
1299 if (ch_len == 1 && isspace(*cur)) {
1300 linep = cur + ch_len;
1301 line_len = cur_len + ch_len;
1304 if (cur_len + ch_len > wrap_len && line_len > 0) {
1305 gtk_stext_insert(text, NULL, qcolor, NULL,
1308 if (isspace(*(linep - 1)))
1309 gtk_stext_insert(text, NULL,
1311 leftp, line_len - 1);
1313 gtk_stext_insert(text, NULL,
1316 gtk_stext_insert(text, NULL, NULL, NULL,
1320 cur_len = cur_len - line_len + ch_len;
1327 linep = cur + ch_len;
1328 line_len = cur_len + ch_len;
1335 gtk_stext_insert(text, NULL, qcolor, NULL,
1337 gtk_stext_insert(text, NULL, qcolor, NULL, leftp, -1);
1338 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1347 static gchar *compose_quote_parse_fmt(Compose *compose, MsgInfo *msginfo,
1351 size_t buf_len = 1024;
1359 if (!fmt || *fmt == '\0') return 0;
1361 Xalloca(mbs, sizeof(wchar_t) + 1, return 0);
1362 Xalloca(wcsfmt, (strlen(fmt) + 1) * sizeof(wchar_t), return 0);
1363 mbstowcs(wcsfmt, fmt, strlen(fmt) + 1);
1366 ext_str = g_malloc(sizeof(gchar) * buf_len);
1367 g_return_val_if_fail(ext_str != NULL, NULL);
1372 len = wctomb(mbs, *sp);
1378 wctomb(mbs, *(++sp));
1383 str = msginfo->date;
1387 str = msginfo->from;
1391 if (!msginfo->fromname) {sp++; break;}
1392 p = msginfo->fromname;
1393 tmp[0] = tmp[1] = tmp[2] = '\0';
1395 if (*p && isalnum(*p))
1396 tmp[0] = toupper(*p);
1403 while (*p && !isspace(*p)) p++;
1404 while (*p && isspace(*p)) p++;
1405 if (*p && isalnum(*p))
1406 tmp[1] = toupper(*p);
1409 if (tmp[1]) str = tmp;
1413 str = msginfo->fromname;
1417 if (!msginfo->fromname) {sp++; break;}
1418 Xstrdup_a(str, msginfo->fromname,
1421 while (*p && !isspace(*p)) p++;
1426 str = msginfo->subject;
1438 if (!msginfo->msgid) {sp++; break;}
1439 Xalloca(str, strlen(msginfo->msgid) + 3,
1441 g_snprintf(str, strlen(msginfo->msgid) + 3,
1442 "<%s>", msginfo->msgid);
1454 while (ext_len + strlen(str) + 1 > buf_len)
1456 ext_str = g_realloc(ext_str,
1457 sizeof(gchar) * buf_len);
1458 g_return_val_if_fail(ext_str != NULL, NULL);
1459 strcpy(ext_str + ext_len, str);
1460 ext_len += strlen(str);
1462 } else if (*mbs == '\\') {
1463 wctomb(mbs, *(++sp));
1481 while (ext_len + strlen(str) + 1 > buf_len)
1483 ext_str = g_realloc(ext_str,
1484 sizeof(gchar) * buf_len);
1485 g_return_val_if_fail(ext_str != NULL, NULL);
1486 strcpy(ext_str + ext_len, str);
1487 ext_len += strlen(str);
1491 while (ext_len + len + 1 > buf_len) buf_len += 1024;
1492 ext_str = g_realloc(ext_str, sizeof(gchar) * buf_len);
1493 g_return_val_if_fail(ext_str != NULL, NULL);
1494 strcpy(ext_str + ext_len, mbs);
1501 ext_str = g_realloc(ext_str, strlen(ext_str) + 1);
1507 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1508 gboolean to_all, gboolean ignore_replyto,
1509 gboolean followup_and_reply_to)
1514 GHashTable *to_table;
1516 g_return_if_fail(compose->account != NULL);
1517 g_return_if_fail(msginfo != NULL);
1519 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1520 gtk_entry_set_text(GTK_ENTRY(compose->to_entry),
1521 ( (compose->replyto && !ignore_replyto)
1523 : msginfo->from ? msginfo->from : ""));
1524 if (compose->account->protocol == A_NNTP)
1525 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry),
1526 compose->followup_to ? compose->followup_to
1527 : compose->newsgroups ? compose->newsgroups
1530 if (msginfo->subject && *msginfo->subject) {
1531 gchar *buf, *buf2, *p;
1533 buf = g_strdup(msginfo->subject);
1534 while (!strncasecmp(buf, "Re:", 3)) {
1536 while (isspace(*p)) p++;
1537 memmove(buf, p, strlen(p) + 1);
1540 buf2 = g_strdup_printf("Re: %s", buf);
1541 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1545 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1547 if (!to_all || compose->account->protocol == A_NNTP) return;
1549 from = g_strdup(compose->replyto ? compose->replyto :
1550 msginfo->from ? msginfo->from : "");
1551 extract_address(from);
1553 cc_list = address_list_append(NULL, msginfo->to);
1554 cc_list = address_list_append(cc_list, compose->cc);
1556 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1557 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1558 if (compose->account)
1559 g_hash_table_insert(to_table, compose->account->address,
1560 GINT_TO_POINTER(1));
1562 /* remove address on To: and that of current account */
1563 for (cur = cc_list; cur != NULL; ) {
1564 GSList *next = cur->next;
1566 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1567 cc_list = g_slist_remove(cc_list, cur->data);
1569 g_hash_table_insert(to_table, cur->data, cur);
1573 g_hash_table_destroy(to_table);
1577 for (cur = cc_list; cur != NULL; cur = cur->next)
1578 compose_entry_append(compose, (gchar *)cur->data,
1580 slist_free_strings(cc_list);
1581 g_slist_free(cc_list);
1585 #define SET_ENTRY(entry, str) \
1588 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1591 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1593 g_return_if_fail(msginfo != NULL);
1595 SET_ENTRY(to_entry, msginfo->to);
1596 SET_ENTRY(subject_entry, msginfo->subject);
1597 SET_ENTRY(cc_entry, compose->cc);
1598 SET_ENTRY(bcc_entry, compose->bcc);
1599 SET_ENTRY(reply_entry, compose->replyto);
1602 GtkItemFactory *ifactory;
1603 GtkWidget *menuitem;
1605 ifactory = gtk_item_factory_from_widget(compose->menubar);
1606 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1607 gtk_check_menu_item_set_active
1608 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1610 if (compose->replyto) {
1611 GtkItemFactory *ifactory;
1612 GtkWidget *menuitem;
1614 ifactory = gtk_item_factory_from_widget(compose->menubar);
1615 menuitem = gtk_item_factory_get_item
1616 (ifactory, "/Message/Reply to");
1617 gtk_check_menu_item_set_active
1618 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1624 static void compose_insert_sig(Compose *compose)
1628 if (compose->account && compose->account->sig_path)
1629 sigfile = g_strdup(compose->account->sig_path);
1631 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1632 DEFAULT_SIGNATURE, NULL);
1635 if (!is_file_or_fifo_exist(sigfile)) {
1640 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1641 if (prefs_common.sig_sep) {
1642 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1643 prefs_common.sig_sep, -1);
1644 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1648 compose_insert_file(compose, sigfile);
1652 static void compose_insert_file(Compose *compose, const gchar *file)
1654 GtkSText *text = GTK_STEXT(compose->text);
1655 gchar buf[BUFFSIZE];
1658 g_return_if_fail(file != NULL);
1660 if ((fp = fopen(file, "r")) == NULL) {
1661 FILE_OP_ERROR(file, "fopen");
1665 gtk_stext_freeze(text);
1667 while (fgets(buf, sizeof(buf), fp) != NULL)
1668 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1670 gtk_stext_thaw(text);
1675 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1676 ContentType cnttype)
1678 gchar *text[N_ATTACH_COLS];
1681 text[COL_MIMETYPE] = ainfo->content_type;
1682 text[COL_SIZE] = to_human_readable(ainfo->size);
1683 text[COL_NAME] = ainfo->name;
1685 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1686 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1688 if (cnttype != MIME_MESSAGE_RFC822)
1689 compose_changed_cb(NULL, compose);
1692 static void compose_attach_append_with_type(Compose *compose,
1695 ContentType cnttype)
1700 if (!is_file_exist(file)) {
1701 g_warning(_("File %s doesn't exist\n"), file);
1704 if ((size = get_file_size(file)) < 0) {
1705 g_warning(_("Can't get file size of %s\n"), file);
1709 alertpanel_notice(_("File %s is empty\n"), file);
1713 if (!compose->use_attach) {
1714 GtkItemFactory *ifactory;
1715 GtkWidget *menuitem;
1717 ifactory = gtk_item_factory_from_widget(compose->menubar);
1718 menuitem = gtk_item_factory_get_item(ifactory,
1720 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1724 ainfo = g_new0(AttachInfo, 1);
1725 ainfo->file = g_strdup(file);
1727 if (cnttype == MIME_MESSAGE_RFC822) {
1728 ainfo->encoding = ENC_7BIT;
1729 ainfo->name = g_strdup_printf(_("Message: %s"),
1732 ainfo->encoding = ENC_BASE64;
1733 ainfo->name = g_strdup(g_basename(file));
1736 ainfo->content_type = g_strdup(type);
1739 compose_attach_info(compose, ainfo, cnttype);
1742 static void compose_attach_append(Compose *compose, const gchar *file,
1743 ContentType cnttype)
1746 gchar *text[N_ATTACH_COLS];
1750 if (!is_file_exist(file)) {
1751 g_warning(_("File %s doesn't exist\n"), file);
1754 if ((size = get_file_size(file)) < 0) {
1755 g_warning(_("Can't get file size of %s\n"), file);
1759 alertpanel_notice(_("File %s is empty\n"), file);
1763 if (!compose->use_attach) {
1764 GtkItemFactory *ifactory;
1765 GtkWidget *menuitem;
1767 ifactory = gtk_item_factory_from_widget(compose->menubar);
1768 menuitem = gtk_item_factory_get_item(ifactory,
1770 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1774 ainfo = g_new0(AttachInfo, 1);
1775 ainfo->file = g_strdup(file);
1777 if (cnttype == MIME_MESSAGE_RFC822) {
1778 ainfo->content_type = g_strdup("message/rfc822");
1779 ainfo->encoding = ENC_7BIT;
1780 ainfo->name = g_strdup_printf(_("Message: %s"),
1783 ainfo->content_type = procmime_get_mime_type(file);
1784 if (!ainfo->content_type)
1785 ainfo->content_type =
1786 g_strdup("application/octet-stream");
1787 ainfo->encoding = ENC_BASE64;
1788 ainfo->name = g_strdup(g_basename(file));
1792 compose_attach_info(compose, ainfo, cnttype);
1795 static void compose_wrap_line(Compose *compose)
1797 GtkSText *text = GTK_STEXT(compose->text);
1799 guint line_pos = 0, cur_pos = 0;
1800 gint line_len = 0, cur_len = 0;
1802 gchar cbuf[MB_CUR_MAX];
1804 gtk_stext_freeze(text);
1806 text_len = gtk_stext_get_length(text);
1808 for (; cur_pos < text_len; cur_pos++) {
1809 if (text->use_wchar)
1811 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
1813 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
1817 if (ch_len == 1 && *cbuf == '\n') {
1818 line_pos = cur_pos + 1;
1819 line_len = cur_len = 0;
1828 if (ch_len == 1 && isspace(*cbuf)) {
1829 line_pos = cur_pos + 1;
1830 line_len = cur_len + ch_len;
1833 if (cur_len + ch_len > prefs_common.linewrap_len &&
1837 if (text->use_wchar)
1838 tlen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
1840 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
1843 if (tlen == 1 && isspace(*cbuf)) {
1844 gtk_stext_set_point(text, line_pos);
1845 gtk_stext_backward_delete(text, 1);
1853 gtk_stext_set_point(text, line_pos);
1854 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1858 cur_len = cur_len - line_len + ch_len;
1864 line_pos = cur_pos + 1;
1865 line_len = cur_len + ch_len;
1870 gtk_stext_thaw(text);
1873 static void compose_set_title(Compose *compose)
1878 edited = compose->modified ? _(" [Edited]") : "";
1879 if (compose->account && compose->account->address)
1880 str = g_strdup_printf(_("%s - Compose message%s"),
1881 compose->account->address, edited);
1883 str = g_strdup_printf(_("Compose message%s"), edited);
1884 gtk_window_set_title(GTK_WINDOW(compose->window), str);
1889 * compose_current_mail_account:
1891 * Find a current mail account (the currently selected account, or the
1892 * default account, if a news account is currently selected). If a
1893 * mail account cannot be found, display an error message.
1895 * Return value: Mail account, or NULL if not found.
1897 static PrefsAccount *
1898 compose_current_mail_account(void)
1902 if (cur_account && cur_account->protocol != A_NNTP)
1905 ac = account_get_default();
1906 if (!ac || ac->protocol == A_NNTP) {
1907 alertpanel_error(_("Account for sending mail is not specified.\n"
1908 "Please select a mail account before sending."));
1915 gint compose_send(Compose *compose)
1917 gchar tmp[MAXPATHLEN + 1];
1918 gchar *to, *newsgroups;
1920 static gboolean lock = FALSE;
1924 g_return_val_if_fail(compose->account != NULL, -1);
1925 g_return_val_if_fail(compose->orig_account != NULL, -1);
1929 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
1930 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
1931 if (*to == '\0' && *newsgroups == '\0') {
1932 alertpanel_error(_("Recipient is not specified."));
1937 /* write to temporary file */
1938 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
1939 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
1941 if (prefs_common.linewrap_at_send)
1942 compose_wrap_line(compose);
1944 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
1949 if (!compose->to_list && !compose->newsgroup_list) {
1950 g_warning(_("can't get recipient list."));
1956 if (compose->to_list) {
1960 if (compose->account->protocol != A_NNTP)
1961 ac = compose->account;
1962 else if (compose->orig_account->protocol != A_NNTP)
1963 ac = compose->orig_account;
1964 else if (cur_account && cur_account->protocol != A_NNTP)
1967 ac = compose_current_mail_account();
1975 ac = compose->account;
1977 ok = send_message(tmp, ac, compose->to_list);
1978 statusbar_pop_all();
1981 if (ok == 0 && compose->newsgroup_list) {
1984 if (compose->account->protocol == A_NNTP)
1985 folder = FOLDER(compose->account->folder);
1987 folder = FOLDER(compose->orig_account->folder);
1989 ok = news_post(folder, tmp);
1991 alertpanel_error(_("Error occurred while posting the message to %s ."),
1992 compose->account->nntp_server);
1999 /* queue message if failed to send */
2001 if (prefs_common.queue_msg) {
2006 _("Error occurred while sending the message.\n"
2007 "Put this message into queue folder?"),
2008 _("OK"), _("Cancel"), NULL);
2009 if (G_ALERTDEFAULT == val) {
2010 ok = compose_queue(compose, tmp);
2012 alertpanel_error(_("Can't queue the message."));
2015 alertpanel_error(_("Error occurred while sending the message."));
2018 /* save message to outbox */
2019 if (ok == 0 && prefs_common.savemsg) {
2020 if (compose_save_to_outbox(compose, tmp) < 0)
2022 (_("Can't save the message to outbox."));
2030 static gint compose_write_to_file(Compose *compose, const gchar *file,
2037 const gchar *out_codeset;
2038 EncodingType encoding;
2040 if ((fp = fopen(file, "w")) == NULL) {
2041 FILE_OP_ERROR(file, "fopen");
2045 /* chmod for security */
2046 if (change_file_mode_rw(fp, file) < 0) {
2047 FILE_OP_ERROR(file, "chmod");
2048 g_warning(_("can't change file mode\n"));
2051 /* get all composed text */
2052 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2053 len = strlen(chars);
2054 if (is_ascii_str(chars)) {
2055 buf = g_strdup(chars);
2056 out_codeset = "US-ASCII";
2057 encoding = ENC_7BIT;
2059 const gchar *src_codeset;
2061 out_codeset = conv_get_outgoing_charset_str();
2062 if (!strcasecmp(out_codeset, "US-ASCII"))
2063 out_codeset = "ISO-8859-1";
2064 encoding = procmime_get_encoding_for_charset(out_codeset);
2065 debug_print("charset = %s, encoding = %s\n",
2066 out_codeset, procmime_get_encoding_str(encoding));
2068 src_codeset = conv_get_current_charset_str();
2069 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
2074 alertpanel_error(_("Can't convert the codeset of the message."));
2081 if (compose_write_headers
2082 (compose, fp, out_codeset, encoding, is_draft) < 0) {
2083 g_warning(_("can't write headers\n"));
2090 if (compose->use_attach) {
2092 /* This prolog message is ignored by mime software and
2093 * because it would make our signing/encryption task
2094 * tougher, we don't emit it in that case */
2095 if (!compose->use_signing && !compose->use_encryption)
2097 fputs("This is a multi-part message in MIME format.\n", fp);
2099 fprintf(fp, "\n--%s\n", compose->boundary);
2100 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
2102 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2103 procmime_get_encoding_str(encoding));
2109 if (encoding == ENC_BASE64) {
2110 gchar outbuf[B64_BUFFSIZE];
2113 for (i = 0; i < len; i += B64_LINE_SIZE) {
2114 l = MIN(B64_LINE_SIZE, len - i);
2115 to64frombits(outbuf, buf + i, l);
2119 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
2120 FILE_OP_ERROR(file, "fwrite");
2128 if (compose->use_attach)
2129 compose_write_attach(compose, fp);
2131 if (fclose(fp) == EOF) {
2132 FILE_OP_ERROR(file, "fclose");
2138 if (compose->use_signing) {
2139 if (rfc2015_sign(file, compose->account) < 0) {
2144 if (compose->use_encryption) {
2145 if (rfc2015_encrypt(file, compose->to_list) < 0) {
2150 #endif /* USE_GPGME */
2155 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
2161 if ((fp = fopen(file, "w")) == NULL) {
2162 FILE_OP_ERROR(file, "fopen");
2166 /* chmod for security */
2167 if (change_file_mode_rw(fp, file) < 0) {
2168 FILE_OP_ERROR(file, "chmod");
2169 g_warning(_("can't change file mode\n"));
2172 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2175 len = strlen(chars);
2176 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
2177 FILE_OP_ERROR(file, "fwrite");
2186 if (fclose(fp) == EOF) {
2187 FILE_OP_ERROR(file, "fclose");
2194 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
2201 debug_print(_("saving sent message...\n"));
2203 outbox = folder_get_default_outbox();
2204 path = folder_item_get_path(outbox);
2205 if (!is_dir_exist(path))
2206 make_dir_hier(path);
2208 folder_item_scan(outbox);
2209 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
2211 g_warning(_("can't save message\n"));
2215 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
2216 g_warning(_("can't open mark file\n"));
2220 newmsginfo.msgnum = num;
2221 newmsginfo.flags.perm_flags = 0;
2222 newmsginfo.flags.tmp_flags = 0;
2223 procmsg_write_flags(&newmsginfo, fp);
2231 static gint compose_queue(Compose *compose, const gchar *file)
2234 gchar *tmp, *queue_path;
2237 gchar buf[BUFFSIZE];
2240 debug_print(_("queueing message...\n"));
2241 g_return_val_if_fail(compose->to_list != NULL, -1);
2242 g_return_val_if_fail(compose->account != NULL, -1);
2244 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
2245 G_DIR_SEPARATOR, (gint)compose);
2246 if ((fp = fopen(tmp, "w")) == NULL) {
2247 FILE_OP_ERROR(tmp, "fopen");
2251 if ((src_fp = fopen(file, "r")) == NULL) {
2252 FILE_OP_ERROR(file, "fopen");
2258 if (change_file_mode_rw(fp, tmp) < 0) {
2259 FILE_OP_ERROR(tmp, "chmod");
2260 g_warning(_("can't change file mode\n"));
2263 /* queueing variables */
2264 fprintf(fp, "AF:\n");
2265 fprintf(fp, "NF:0\n");
2266 fprintf(fp, "PS:10\n");
2267 fprintf(fp, "SRH:1\n");
2268 fprintf(fp, "SFN:\n");
2269 fprintf(fp, "DSR:\n");
2271 fprintf(fp, "MID:<%s>\n", compose->msgid);
2273 fprintf(fp, "MID:\n");
2274 fprintf(fp, "CFG:\n");
2275 fprintf(fp, "PT:0\n");
2276 fprintf(fp, "S:%s\n", compose->account->address);
2277 fprintf(fp, "RQ:\n");
2278 if (compose->account->smtp_server)
2279 fprintf(fp, "SSV:%s\n", compose->account->smtp_server);
2281 fprintf(fp, "SSV:\n");
2282 if (compose->account->nntp_server)
2283 fprintf(fp, "NSV:%s\n", compose->account->nntp_server);
2285 fprintf(fp, "NSV:\n");
2286 fprintf(fp, "SSH:\n");
2287 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
2288 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
2289 fprintf(fp, ",<%s>", (gchar *)cur->data);
2293 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
2294 if (fputs(buf, fp) == EOF) {
2295 FILE_OP_ERROR(tmp, "fputs");
2305 if (fclose(fp) == EOF) {
2306 FILE_OP_ERROR(tmp, "fclose");
2312 queue = folder_get_default_queue();
2313 folder_item_scan(queue);
2314 queue_path = folder_item_get_path(queue);
2315 if (!is_dir_exist(queue_path))
2316 make_dir_hier(queue_path);
2317 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
2318 g_warning(_("can't queue the message\n"));
2326 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
2327 g_warning(_("can't open mark file\n"));
2331 newmsginfo.msgnum = num;
2332 newmsginfo.flags.perm_flags = 0;
2333 newmsginfo.flags.tmp_flags = 0;
2334 procmsg_write_flags(&newmsginfo, fp);
2339 folder_item_scan(queue);
2340 folderview_update_item(queue, TRUE);
2345 static void compose_write_attach(Compose *compose, FILE *fp)
2348 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2351 gchar filename[BUFFSIZE];
2354 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
2356 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
2357 g_warning(_("Can't open file %s\n"), ainfo->file);
2361 fprintf(fp, "\n--%s\n", compose->boundary);
2363 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
2364 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
2365 fprintf(fp, "Content-Disposition: inline\n");
2367 conv_encode_header(filename, sizeof(filename),
2369 fprintf(fp, "Content-Type: %s;\n"
2371 ainfo->content_type, filename);
2372 fprintf(fp, "Content-Disposition: attachment;\n"
2373 " filename=\"%s\"\n", filename);
2376 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
2377 procmime_get_encoding_str(ainfo->encoding));
2379 if (ainfo->encoding == ENC_7BIT) {
2380 gchar buf[BUFFSIZE];
2382 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
2384 if (len > 1 && buf[len - 1] == '\n' &&
2385 buf[len - 2] == '\r') {
2386 buf[len - 2] = '\n';
2387 buf[len - 1] = '\0';
2392 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
2394 while ((len = fread(inbuf, sizeof(gchar),
2395 B64_LINE_SIZE, attach_fp))
2397 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
2401 if (len > 0 && feof(attach_fp)) {
2402 to64frombits(outbuf, inbuf, len);
2411 fprintf(fp, "\n--%s--\n", compose->boundary);
2414 #define IS_IN_CUSTOM_HEADER(header) \
2415 (compose->account->add_customhdr && \
2416 custom_header_find(compose->account->customhdr_list, header) != NULL)
2418 static gint compose_write_headers(Compose *compose, FILE *fp,
2419 const gchar *charset, EncodingType encoding,
2422 gchar buf[BUFFSIZE];
2424 /* struct utsname utsbuf; */
2426 g_return_val_if_fail(fp != NULL, -1);
2427 g_return_val_if_fail(charset != NULL, -1);
2428 g_return_val_if_fail(compose->account != NULL, -1);
2429 g_return_val_if_fail(compose->account->address != NULL, -1);
2432 if (compose->account->add_date) {
2433 get_rfc822_date(buf, sizeof(buf));
2434 fprintf(fp, "Date: %s\n", buf);
2438 if (!IS_IN_CUSTOM_HEADER("From")) {
2439 if (compose->account->name && *compose->account->name) {
2440 compose_convert_header
2441 (buf, sizeof(buf), compose->account->name,
2443 fprintf(fp, "From: %s <%s>\n",
2444 buf, compose->account->address);
2446 fprintf(fp, "From: %s\n", compose->account->address);
2449 slist_free_strings(compose->to_list);
2450 g_slist_free(compose->to_list);
2451 compose->to_list = NULL;
2454 if (compose->use_to) {
2455 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2457 Xstrdup_a(str, str, return -1);
2460 compose->to_list = address_list_append
2461 (compose->to_list, str);
2462 if (!IS_IN_CUSTOM_HEADER("To")) {
2463 compose_convert_header
2464 (buf, sizeof(buf), str,
2466 fprintf(fp, "To: %s\n", buf);
2472 slist_free_strings(compose->newsgroup_list);
2473 g_slist_free(compose->newsgroup_list);
2474 compose->newsgroup_list = NULL;
2477 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2479 Xstrdup_a(str, str, return -1);
2483 compose->newsgroup_list =
2484 newsgroup_list_append(compose->newsgroup_list,
2486 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
2487 compose_convert_header(buf, sizeof(buf), str,
2488 strlen("Newsgroups: "));
2489 fprintf(fp, "Newsgroups: %s\n", buf);
2494 if (!is_draft && !compose->to_list && !compose->newsgroup_list)
2498 if (compose->use_cc) {
2499 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
2501 Xstrdup_a(str, str, return -1);
2504 compose->to_list = address_list_append
2505 (compose->to_list, str);
2506 if (!IS_IN_CUSTOM_HEADER("Cc")) {
2507 compose_convert_header
2508 (buf, sizeof(buf), str,
2510 fprintf(fp, "Cc: %s\n", buf);
2517 if (compose->use_bcc) {
2518 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
2520 Xstrdup_a(str, str, return -1);
2523 compose->to_list = address_list_append
2524 (compose->to_list, str);
2526 compose_convert_header
2527 (buf, sizeof(buf), str,
2529 fprintf(fp, "Bcc: %s\n", buf);
2536 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2537 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
2538 Xstrdup_a(str, str, return -1);
2541 compose_convert_header(buf, sizeof(buf), str,
2542 strlen("Subject: "));
2543 fprintf(fp, "Subject: %s\n", buf);
2548 if (compose->account->gen_msgid) {
2549 compose_generate_msgid(compose, buf, sizeof(buf));
2550 fprintf(fp, "Message-Id: <%s>\n", buf);
2551 compose->msgid = g_strdup(buf);
2555 if (compose->inreplyto && compose->to_list)
2556 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
2559 if (compose->references)
2560 fprintf(fp, "References: %s\n", compose->references);
2563 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
2564 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
2566 Xstrdup_a(str, str, return -1);
2570 compose_convert_header(buf, sizeof(buf), str,
2571 strlen("Followup-To: "));
2572 fprintf(fp, "Followup-To: %s\n", buf);
2578 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
2579 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
2581 Xstrdup_a(str, str, return -1);
2584 compose_convert_header(buf, sizeof(buf), str,
2585 strlen("Reply-To: "));
2586 fprintf(fp, "Reply-To: %s\n", buf);
2592 if (compose->account->organization &&
2593 !IS_IN_CUSTOM_HEADER("Organization")) {
2594 compose_convert_header(buf, sizeof(buf),
2595 compose->account->organization,
2596 strlen("Organization: "));
2597 fprintf(fp, "Organization: %s\n", buf);
2600 /* Program version and system info */
2601 /* uname(&utsbuf); */
2602 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2603 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
2604 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
2606 gtk_major_version, gtk_minor_version, gtk_micro_version,
2608 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2610 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2611 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
2612 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
2614 gtk_major_version, gtk_minor_version, gtk_micro_version,
2616 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2619 /* custom headers */
2620 if (compose->account->add_customhdr) {
2623 for (cur = compose->account->customhdr_list; cur != NULL;
2625 CustomHeader *chdr = (CustomHeader *)cur->data;
2627 if (strcasecmp(chdr->name, "Date") != 0 &&
2628 strcasecmp(chdr->name, "From") != 0 &&
2629 strcasecmp(chdr->name, "To") != 0 &&
2630 strcasecmp(chdr->name, "Sender") != 0 &&
2631 strcasecmp(chdr->name, "Message-Id") != 0 &&
2632 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
2633 strcasecmp(chdr->name, "References") != 0 &&
2634 strcasecmp(chdr->name, "Mime-Version") != 0 &&
2635 strcasecmp(chdr->name, "Content-Type") != 0 &&
2636 strcasecmp(chdr->name, "Content-Transfer-Encoding")
2638 compose_convert_header
2640 chdr->value ? chdr->value : "",
2641 strlen(chdr->name) + 2);
2642 fprintf(fp, "%s: %s\n", chdr->name, buf);
2647 fprintf(fp, "Mime-Version: 1.0\n");
2648 if (compose->use_attach) {
2649 get_rfc822_date(buf, sizeof(buf));
2650 subst_char(buf, ' ', '_');
2651 subst_char(buf, ',', '_');
2652 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
2653 buf, (guint)compose);
2655 "Content-Type: multipart/mixed;\n"
2656 " boundary=\"%s\"\n", compose->boundary);
2658 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
2659 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2660 procmime_get_encoding_str(encoding));
2663 /* Request Return Receipt */
2664 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
2665 if (compose->return_receipt) {
2666 if (compose->account->name
2667 && *compose->account->name) {
2668 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
2669 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
2671 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
2675 /* separator between header and body */
2681 #undef IS_IN_CUSTOM_HEADER
2683 static void compose_convert_header(gchar *dest, gint len, gchar *src,
2686 g_return_if_fail(src != NULL);
2687 g_return_if_fail(dest != NULL);
2689 if (len < 1) return;
2693 if (is_ascii_str(src)) {
2694 strncpy2(dest, src, len);
2695 dest[len - 1] = '\0';
2698 conv_encode_header(dest, len, src, header_len);
2701 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
2710 if (compose->account && compose->account->address &&
2711 *compose->account->address) {
2712 if (strchr(compose->account->address, '@'))
2713 addr = g_strdup(compose->account->address);
2715 addr = g_strconcat(compose->account->address, "@",
2716 get_domain_name(), NULL);
2718 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
2721 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
2722 lt->tm_year + 1900, lt->tm_mon + 1,
2723 lt->tm_mday, lt->tm_hour,
2724 lt->tm_min, lt->tm_sec,
2725 (guint)random(), addr);
2727 debug_print(_("generated Message-ID: %s\n"), buf);
2732 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
2733 GtkWidget **entry, gint *count,
2734 const gchar *label_str,
2735 gboolean is_addr_entry)
2739 if (GTK_TABLE(table)->nrows < (*count) + 1)
2740 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
2742 *hbox = gtk_hbox_new(FALSE, 0);
2743 label = gtk_label_new
2744 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
2745 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
2746 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
2748 *entry = gtk_entry_new();
2749 gtk_table_attach_defaults
2750 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1);
2751 if (GTK_TABLE(table)->nrows > (*count) + 1)
2752 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
2755 address_completion_register_entry(GTK_ENTRY(*entry));
2760 static Compose *compose_create(PrefsAccount *account)
2766 GtkWidget *handlebox;
2770 GtkWidget *table_vbox;
2772 GtkWidget *from_optmenu_hbox;
2773 GtkWidget *to_entry;
2775 GtkWidget *newsgroups_entry;
2776 GtkWidget *newsgroups_hbox;
2777 GtkWidget *subject_entry;
2778 GtkWidget *cc_entry;
2780 GtkWidget *bcc_entry;
2781 GtkWidget *bcc_hbox;
2782 GtkWidget *reply_entry;
2783 GtkWidget *reply_hbox;
2784 GtkWidget *followup_entry;
2785 GtkWidget *followup_hbox;
2789 GtkWidget *attach_scrwin;
2790 GtkWidget *attach_clist;
2792 GtkWidget *edit_vbox;
2793 GtkWidget *ruler_hbox;
2795 GtkWidget *scrolledwin;
2801 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
2802 guint n_menu_entries;
2803 GtkStyle *style, *new_style;
2806 gboolean success[1];
2808 GtkWidget *popupmenu;
2809 GtkWidget *menuitem;
2810 GtkItemFactory *popupfactory;
2811 GtkItemFactory *ifactory;
2816 g_return_val_if_fail(account != NULL, NULL);
2818 debug_print(_("Creating compose window...\n"));
2819 compose = g_new0(Compose, 1);
2821 compose->account = account;
2822 compose->orig_account = account;
2824 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2825 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
2826 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
2827 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
2828 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
2829 gtk_signal_connect(GTK_OBJECT(window), "destroy",
2830 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
2831 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
2832 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
2833 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
2834 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
2835 gtk_widget_realize(window);
2837 vbox = gtk_vbox_new(FALSE, 0);
2838 gtk_container_add(GTK_CONTAINER(window), vbox);
2840 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
2841 menubar = menubar_create(window, compose_entries,
2842 n_menu_entries, "<Compose>", compose);
2843 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
2845 handlebox = gtk_handle_box_new();
2846 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
2848 compose_toolbar_create(compose, handlebox);
2850 vbox2 = gtk_vbox_new(FALSE, 2);
2851 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
2852 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
2854 table_vbox = gtk_vbox_new(FALSE, 0);
2855 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
2856 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
2859 table = gtk_table_new(8, 2, FALSE);
2860 gtk_box_pack_start(GTK_BOX(table_vbox), table, FALSE, TRUE, 0);
2862 /* option menu for selecting accounts */
2863 hbox = gtk_hbox_new(FALSE, 0);
2864 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
2865 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
2866 gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, count, count + 1,
2868 from_optmenu_hbox = compose_account_option_menu_create(compose);
2869 gtk_table_attach_defaults(GTK_TABLE(table), from_optmenu_hbox,
2870 1, 2, count, count + 1);
2871 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
2874 /* header labels and entries */
2875 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
2877 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
2878 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
2879 &count, "Newsgroups:", FALSE);
2880 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
2881 compose_add_entry_field(table, &hbox, &subject_entry, &count,
2883 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
2884 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
2886 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
2887 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
2889 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
2890 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
2892 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
2893 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
2894 "Followup-To:", FALSE);
2895 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
2897 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
2899 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
2900 GTK_SIGNAL_FUNC(to_activated), compose);
2901 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
2902 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
2903 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
2904 GTK_SIGNAL_FUNC(subject_activated), compose);
2905 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
2906 GTK_SIGNAL_FUNC(cc_activated), compose);
2907 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
2908 GTK_SIGNAL_FUNC(bcc_activated), compose);
2909 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
2910 GTK_SIGNAL_FUNC(replyto_activated), compose);
2911 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
2912 GTK_SIGNAL_FUNC(followupto_activated), compose);
2914 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
2915 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2916 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
2917 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2918 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
2919 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2920 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
2921 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2922 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
2923 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2924 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
2925 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2926 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
2927 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2929 /* attachment list */
2930 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
2931 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
2932 GTK_POLICY_AUTOMATIC,
2934 gtk_widget_set_usize(attach_scrwin, -1, 80);
2936 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
2937 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
2939 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
2940 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
2941 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
2942 GTK_SELECTION_EXTENDED);
2943 for (i = 0; i < N_ATTACH_COLS; i++)
2944 GTK_WIDGET_UNSET_FLAGS
2945 (GTK_CLIST(attach_clist)->column[i].button,
2947 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
2949 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
2950 GTK_SIGNAL_FUNC(attach_selected), compose);
2951 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
2952 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
2953 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
2954 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
2957 gtk_drag_dest_set(attach_clist,
2958 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
2960 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
2961 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
2964 /* pane between attach clist and text */
2965 paned = gtk_vpaned_new();
2966 gtk_paned_add1(GTK_PANED(paned), attach_scrwin);
2967 gtk_widget_ref(paned);
2968 gtk_widget_show_all(paned);
2970 edit_vbox = gtk_vbox_new(FALSE, 0);
2971 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
2974 ruler_hbox = gtk_hbox_new(FALSE, 0);
2975 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
2977 ruler = gtk_shruler_new();
2978 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
2979 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
2981 gtk_widget_set_usize(ruler_hbox, 1, -1);
2984 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
2985 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
2986 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
2987 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
2988 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
2990 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
2991 (GTK_SCROLLED_WINDOW(scrolledwin)),
2992 gtk_scrolled_window_get_vadjustment
2993 (GTK_SCROLLED_WINDOW(scrolledwin)));
2994 GTK_STEXT(text)->default_tab_width = 8;
2995 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
2996 if (prefs_common.smart_wrapping) {
2997 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
2998 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
3001 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
3003 gtk_signal_connect(GTK_OBJECT(text), "changed",
3004 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
3005 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
3006 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3007 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
3008 GTK_SIGNAL_FUNC(compose_button_press_cb),
3011 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
3012 GTK_SIGNAL_FUNC(compose_key_press_cb),
3015 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
3016 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
3020 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3022 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
3023 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
3026 gtk_widget_show_all(vbox);
3028 style = gtk_widget_get_style(text);
3030 /* workaround for the slow down of GtkText when using Pixmap theme */
3031 if (style->engine) {
3032 GtkThemeEngine *engine;
3034 engine = style->engine;
3035 style->engine = NULL;
3036 new_style = gtk_style_copy(style);
3037 style->engine = engine;
3039 new_style = gtk_style_copy(style);
3041 if (prefs_common.textfont) {
3044 charset = conv_get_current_charset();
3045 if (MB_CUR_MAX == 1) {
3048 Xstrdup_a(fontstr, prefs_common.textfont, );
3049 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
3051 font = gdk_font_load(fontstr);
3053 font = gdk_fontset_load(prefs_common.textfont);
3055 gdk_font_unref(new_style->font);
3056 new_style->font = font;
3060 gtk_widget_set_style(text, new_style);
3062 color[0] = quote_color;
3063 cmap = gdk_window_get_colormap(window->window);
3064 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
3065 if (success[0] == FALSE) {
3066 g_warning("Compose: color allocation failed.\n");
3067 style = gtk_widget_get_style(text);
3068 quote_color = style->black;
3071 n_entries = sizeof(compose_popup_entries) /
3072 sizeof(compose_popup_entries[0]);
3073 popupmenu = menu_create_items(compose_popup_entries, n_entries,
3074 "<Compose>", &popupfactory,
3077 ifactory = gtk_item_factory_from_widget(menubar);
3078 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
3079 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
3082 if (account->protocol == A_NNTP) {
3083 gtk_widget_hide(to_hbox);
3084 gtk_widget_hide(to_entry);
3085 gtk_widget_hide(cc_hbox);
3086 gtk_widget_hide(cc_entry);
3087 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
3088 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
3090 gtk_widget_hide(newsgroups_hbox);
3091 gtk_widget_hide(newsgroups_entry);
3092 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
3094 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
3098 switch (prefs_common.toolbar_style) {
3100 gtk_widget_hide(handlebox);
3103 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3107 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3111 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3116 gtk_widget_show(window);
3118 address_completion_start(window);
3120 compose->window = window;
3121 compose->vbox = vbox;
3122 compose->menubar = menubar;
3123 compose->handlebox = handlebox;
3125 compose->vbox2 = vbox2;
3127 compose->table_vbox = table_vbox;
3128 compose->table = table;
3129 compose->to_hbox = to_hbox;
3130 compose->to_entry = to_entry;
3131 compose->newsgroups_hbox = newsgroups_hbox;
3132 compose->newsgroups_entry = newsgroups_entry;
3133 compose->subject_entry = subject_entry;
3134 compose->cc_hbox = cc_hbox;
3135 compose->cc_entry = cc_entry;
3136 compose->bcc_hbox = bcc_hbox;
3137 compose->bcc_entry = bcc_entry;
3138 compose->reply_hbox = reply_hbox;
3139 compose->reply_entry = reply_entry;
3140 compose->followup_hbox = followup_hbox;
3141 compose->followup_entry = followup_entry;
3143 compose->paned = paned;
3145 compose->attach_scrwin = attach_scrwin;
3146 compose->attach_clist = attach_clist;
3148 compose->edit_vbox = edit_vbox;
3149 compose->ruler_hbox = ruler_hbox;
3150 compose->ruler = ruler;
3151 compose->scrolledwin = scrolledwin;
3152 compose->text = text;
3154 compose->focused_editable = NULL;
3156 compose->popupmenu = popupmenu;
3157 compose->popupfactory = popupfactory;
3159 compose->mode = COMPOSE_NEW;
3161 compose->replyto = NULL;
3163 compose->bcc = NULL;
3164 compose->followup_to = NULL;
3165 compose->inreplyto = NULL;
3166 compose->references = NULL;
3167 compose->msgid = NULL;
3168 compose->boundary = NULL;
3171 compose->use_signing = FALSE;
3172 compose->use_encryption = FALSE;
3173 #endif /* USE_GPGME */
3175 compose->modified = FALSE;
3177 compose->return_receipt = FALSE;
3179 compose->to_list = NULL;
3180 compose->newsgroup_list = NULL;
3182 compose->exteditor_file = NULL;
3183 compose->exteditor_pid = -1;
3184 compose->exteditor_readdes = -1;
3185 compose->exteditor_tag = -1;
3187 compose_set_title(compose);
3189 compose->use_bcc = FALSE;
3190 compose->use_replyto = FALSE;
3191 compose->use_followupto = FALSE;
3194 if (account->protocol != A_NNTP) {
3195 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
3196 gtk_check_menu_item_set_active
3197 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3198 gtk_widget_set_sensitive(menuitem, FALSE);
3199 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3200 gtk_check_menu_item_set_active
3201 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3202 gtk_widget_set_sensitive(menuitem, FALSE);
3205 if (account->set_autocc && account->auto_cc) {
3206 compose->use_cc = TRUE;
3207 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
3208 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3209 gtk_check_menu_item_set_active
3210 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3213 if (account->set_autobcc) {
3214 compose->use_bcc = TRUE;
3215 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
3216 gtk_check_menu_item_set_active
3217 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3218 if (account->auto_bcc)
3219 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
3222 if (account->set_autoreplyto) {
3223 compose->use_replyto = TRUE;
3224 menuitem = gtk_item_factory_get_item(ifactory,
3225 "/Message/Reply to");
3226 gtk_check_menu_item_set_active
3227 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3228 if (account->auto_replyto)
3229 gtk_entry_set_text(GTK_ENTRY(reply_entry),
3230 account->auto_replyto);
3233 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
3234 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3235 prefs_common.show_ruler);
3238 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
3239 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3240 prefs_common.default_sign);
3241 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
3242 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3243 prefs_common.default_encrypt);
3244 #endif /* USE_GPGME */
3246 addressbook_set_target_compose(compose);
3248 compose_list = g_list_append(compose_list, compose);
3251 compose->use_to = FALSE;
3252 compose->use_cc = FALSE;
3254 compose->use_attach = FALSE;
3256 if (!compose->use_bcc) {
3257 gtk_widget_hide(bcc_hbox);
3258 gtk_widget_hide(bcc_entry);
3259 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
3261 if (!compose->use_replyto) {
3262 gtk_widget_hide(reply_hbox);
3263 gtk_widget_hide(reply_entry);
3264 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
3266 if (!compose->use_followupto) {
3267 gtk_widget_hide(followup_hbox);
3268 gtk_widget_hide(followup_entry);
3269 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
3272 if (!prefs_common.show_ruler)
3273 gtk_widget_hide(ruler_hbox);
3275 select_account(compose, account);
3280 #include "pixmaps/stock_mail_send.xpm"
3281 #include "pixmaps/stock_mail_send_queue.xpm"
3282 #include "pixmaps/stock_mail.xpm"
3283 #include "pixmaps/stock_paste.xpm"
3284 #include "pixmaps/stock_mail_attach.xpm"
3285 #include "pixmaps/stock_mail_compose.xpm"
3286 #include "pixmaps/linewrap.xpm"
3287 #include "pixmaps/tb_address_book.xpm"
3289 #define CREATE_TOOLBAR_ICON(xpm_d) \
3291 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
3292 &container->style->white, \
3294 icon_wid = gtk_pixmap_new(icon, mask); \
3297 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
3302 GtkWidget *icon_wid;
3303 GtkWidget *send_btn;
3304 GtkWidget *sendl_btn;
3305 GtkWidget *draft_btn;
3306 GtkWidget *insert_btn;
3307 GtkWidget *attach_btn;
3309 GtkWidget *exteditor_btn;
3310 GtkWidget *linewrap_btn;
3311 GtkWidget *addrbook_btn;
3313 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
3315 gtk_container_add(GTK_CONTAINER(container), toolbar);
3316 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
3317 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
3318 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
3319 GTK_TOOLBAR_SPACE_LINE);
3321 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
3322 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3326 icon_wid, toolbar_send_cb, compose);
3328 CREATE_TOOLBAR_ICON(stock_mail_send_queue_xpm);
3329 /* CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm); */
3330 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3332 _("Put into queue folder and send later"),
3334 icon_wid, toolbar_send_later_cb,
3337 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3338 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3340 _("Save to draft folder"),
3342 icon_wid, toolbar_draft_cb,
3345 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3347 CREATE_TOOLBAR_ICON(stock_paste_xpm);
3348 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3352 icon_wid, toolbar_insert_cb,
3355 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
3356 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3360 icon_wid, toolbar_attach_cb,
3363 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3365 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3366 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3368 _("Insert signature"),
3370 icon_wid, toolbar_sig_cb, compose);
3372 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3374 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
3375 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3377 _("Edit with external editor"),
3380 toolbar_ext_editor_cb,
3383 CREATE_TOOLBAR_ICON(linewrap_xpm);
3384 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3386 _("Wrap long lines"),
3389 toolbar_linewrap_cb,
3392 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3394 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
3395 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3399 icon_wid, toolbar_address_cb,
3402 compose->toolbar = toolbar;
3403 compose->send_btn = send_btn;
3404 compose->sendl_btn = sendl_btn;
3405 compose->draft_btn = draft_btn;
3406 compose->insert_btn = insert_btn;
3407 compose->attach_btn = attach_btn;
3408 compose->sig_btn = sig_btn;
3409 compose->exteditor_btn = exteditor_btn;
3410 compose->linewrap_btn = linewrap_btn;
3411 compose->addrbook_btn = addrbook_btn;
3413 gtk_widget_show_all(toolbar);
3416 #undef CREATE_TOOLBAR_ICON
3418 static GtkWidget *compose_account_option_menu_create(Compose *compose)
3424 gint num = 0, def_menu = 0;
3426 accounts = account_get_list();
3427 g_return_val_if_fail(accounts != NULL, NULL);
3429 hbox = gtk_hbox_new(FALSE, 0);
3430 optmenu = gtk_option_menu_new();
3431 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3432 menu = gtk_menu_new();
3434 for (; accounts != NULL; accounts = accounts->next, num++) {
3435 PrefsAccount *ac = (PrefsAccount *)accounts->data;
3436 GtkWidget *menuitem;
3439 if (ac == compose->account) def_menu = num;
3441 name = g_strdup_printf("%s: %s <%s>",
3442 ac->account_name, ac->name, ac->address);
3443 MENUITEM_ADD(menu, menuitem, name, ac);
3445 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
3446 GTK_SIGNAL_FUNC(account_activated),
3450 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
3451 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
3456 static void compose_destroy(Compose *compose)
3459 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3462 /* NOTE: address_completion_end() does nothing with the window
3463 * however this may change. */
3464 address_completion_end(compose->window);
3466 slist_free_strings(compose->to_list);
3467 g_slist_free(compose->to_list);
3468 slist_free_strings(compose->newsgroup_list);
3469 g_slist_free(compose->newsgroup_list);
3471 procmsg_msginfo_free(compose->targetinfo);
3473 g_free(compose->replyto);
3474 g_free(compose->cc);
3475 g_free(compose->bcc);
3476 g_free(compose->newsgroups);
3477 g_free(compose->followup_to);
3479 g_free(compose->inreplyto);
3480 g_free(compose->references);
3481 g_free(compose->msgid);
3482 g_free(compose->boundary);
3484 g_free(compose->exteditor_file);
3486 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3488 compose_attach_info_free(ainfo);
3490 if (addressbook_get_target_compose() == compose)
3491 addressbook_set_target_compose(NULL);
3493 prefs_common.compose_width = compose->scrolledwin->allocation.width;
3494 prefs_common.compose_height = compose->window->allocation.height;
3496 gtk_widget_destroy(compose->paned);
3500 compose_list = g_list_remove(compose_list, compose);
3503 static void compose_attach_info_free(AttachInfo *ainfo)
3505 g_free(ainfo->file);
3506 g_free(ainfo->content_type);
3507 g_free(ainfo->name);
3511 static void compose_attach_remove_selected(Compose *compose)
3513 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3517 while (clist->selection != NULL) {
3518 row = GPOINTER_TO_INT(clist->selection->data);
3519 ainfo = gtk_clist_get_row_data(clist, row);
3520 compose_attach_info_free(ainfo);
3521 gtk_clist_remove(clist, row);
3525 static struct _AttachProperty
3528 GtkWidget *mimetype_entry;
3529 GtkWidget *encoding_optmenu;
3530 GtkWidget *path_entry;
3531 GtkWidget *filename_entry;
3533 GtkWidget *cancel_btn;
3536 static void compose_attach_property(Compose *compose)
3538 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3542 GtkOptionMenu *optmenu;
3544 if (!clist->selection) return;
3545 row = GPOINTER_TO_INT(clist->selection->data);
3547 ainfo = gtk_clist_get_row_data(clist, row);
3550 if (!attach_prop.window)
3551 compose_attach_property_create(&cancelled);
3552 gtk_widget_grab_focus(attach_prop.ok_btn);
3553 gtk_widget_show(attach_prop.window);
3554 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
3556 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
3557 if (ainfo->encoding == ENC_UNKNOWN)
3558 gtk_option_menu_set_history(optmenu, ENC_BASE64);
3560 gtk_option_menu_set_history(optmenu, ainfo->encoding);
3562 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
3563 ainfo->content_type ? ainfo->content_type : "");
3564 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
3565 ainfo->file ? ainfo->file : "");
3566 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
3567 ainfo->name ? ainfo->name : "");
3571 gchar *cnttype = NULL;
3575 GtkWidget *menuitem;
3579 if (cancelled == TRUE) {
3580 gtk_widget_hide(attach_prop.window);
3584 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
3585 if (*text != '\0') {
3588 text = g_strstrip(g_strdup(text));
3589 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
3590 cnttype = g_strdup(text);
3593 alertpanel_error(_("Invalid MIME type."));
3599 menu = gtk_option_menu_get_menu(optmenu);
3600 menuitem = gtk_menu_get_active(GTK_MENU(menu));
3601 ainfo->encoding = GPOINTER_TO_INT
3602 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
3604 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
3605 if (*text != '\0') {
3606 if (is_file_exist(text) &&
3607 (size = get_file_size(text)) > 0)
3608 file = g_strdup(text);
3611 (_("File doesn't exist or is empty."));
3617 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
3618 if (*text != '\0') {
3619 g_free(ainfo->name);
3620 ainfo->name = g_strdup(text);
3624 g_free(ainfo->content_type);
3625 ainfo->content_type = cnttype;
3628 g_free(ainfo->file);
3634 gtk_clist_set_text(clist, row, COL_MIMETYPE,
3635 ainfo->content_type);
3636 gtk_clist_set_text(clist, row, COL_SIZE,
3637 to_human_readable(ainfo->size));
3638 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
3640 gtk_widget_hide(attach_prop.window);
3645 #define SET_LABEL_AND_ENTRY(str, entry, top) \
3647 label = gtk_label_new(str); \
3648 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
3649 GTK_FILL, 0, 0, 0); \
3650 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
3652 entry = gtk_entry_new(); \
3653 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
3654 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
3657 static void compose_attach_property_create(gboolean *cancelled)
3663 GtkWidget *mimetype_entry;
3666 GtkWidget *optmenu_menu;
3667 GtkWidget *menuitem;
3668 GtkWidget *path_entry;
3669 GtkWidget *filename_entry;
3672 GtkWidget *cancel_btn;
3673 GList *mime_type_list, *strlist;
3675 debug_print("Creating attach_property window...\n");
3677 window = gtk_window_new(GTK_WINDOW_DIALOG);
3678 gtk_widget_set_usize(window, 480, -1);
3679 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
3680 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
3681 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
3682 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
3683 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3684 GTK_SIGNAL_FUNC(attach_property_delete_event),
3686 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
3687 GTK_SIGNAL_FUNC(attach_property_key_pressed),
3690 vbox = gtk_vbox_new(FALSE, 8);
3691 gtk_container_add(GTK_CONTAINER(window), vbox);
3693 table = gtk_table_new(4, 2, FALSE);
3694 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
3695 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
3696 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
3698 label = gtk_label_new(_("MIME type"));
3699 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
3701 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3702 mimetype_entry = gtk_combo_new();
3703 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
3704 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3706 /* stuff with list */
3707 mime_type_list = procmime_get_mime_type_list();
3709 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
3710 MimeType *type = (MimeType *) mime_type_list->data;
3711 strlist = g_list_append(strlist,
3712 g_strdup_printf("%s/%s",
3713 type->type, type->sub_type));
3716 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
3718 for (mime_type_list = strlist; mime_type_list != NULL;
3719 mime_type_list = mime_type_list->next)
3720 g_free(mime_type_list->data);
3721 g_list_free(strlist);
3723 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
3725 label = gtk_label_new(_("Encoding"));
3726 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
3728 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3730 hbox = gtk_hbox_new(FALSE, 0);
3731 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
3732 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3734 optmenu = gtk_option_menu_new();
3735 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3737 optmenu_menu = gtk_menu_new();
3738 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
3739 gtk_widget_set_sensitive(menuitem, FALSE);
3740 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
3741 gtk_widget_set_sensitive(menuitem, FALSE);
3742 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
3743 gtk_widget_set_sensitive(menuitem, FALSE);
3744 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
3746 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
3748 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
3749 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
3751 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
3752 &cancel_btn, _("Cancel"), NULL, NULL);
3753 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
3754 gtk_widget_grab_default(ok_btn);
3756 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
3757 GTK_SIGNAL_FUNC(attach_property_ok),
3759 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
3760 GTK_SIGNAL_FUNC(attach_property_cancel),
3763 gtk_widget_show_all(vbox);
3765 attach_prop.window = window;
3766 attach_prop.mimetype_entry = mimetype_entry;
3767 attach_prop.encoding_optmenu = optmenu;
3768 attach_prop.path_entry = path_entry;
3769 attach_prop.filename_entry = filename_entry;
3770 attach_prop.ok_btn = ok_btn;
3771 attach_prop.cancel_btn = cancel_btn;
3774 #undef SET_LABEL_AND_ENTRY
3776 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
3782 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
3788 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
3789 gboolean *cancelled)
3797 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
3798 gboolean *cancelled)
3800 if (event && event->keyval == GDK_Escape) {
3806 static void compose_exec_ext_editor(Compose *compose)
3812 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
3813 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3815 if (pipe(pipe_fds) < 0) {
3820 if ((pid = fork()) < 0) {
3826 /* close the write side of the pipe */
3829 compose->exteditor_file = g_strdup(tmp);
3830 compose->exteditor_pid = pid;
3831 compose->exteditor_readdes = pipe_fds[0];
3833 compose_set_ext_editor_sensitive(compose, FALSE);
3835 compose->exteditor_tag =
3836 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
3837 compose_input_cb, compose);
3838 } else { /* process-monitoring process */
3844 /* close the read side of the pipe */
3847 if (compose_write_body_to_file(compose, tmp) < 0) {
3848 fd_write(pipe_fds[1], "2\n", 2);
3852 pid_ed = compose_exec_ext_editor_real(tmp);
3854 fd_write(pipe_fds[1], "1\n", 2);
3858 /* wait until editor is terminated */
3859 waitpid(pid_ed, NULL, 0);
3861 fd_write(pipe_fds[1], "0\n", 2);
3868 static gint compose_exec_ext_editor_real(const gchar *file)
3870 static gchar *def_cmd = "emacs %s";
3876 g_return_val_if_fail(file != NULL, -1);
3878 if ((pid = fork()) < 0) {
3883 if (pid != 0) return pid;
3885 /* grandchild process */
3887 if (setpgid(0, getppid()))
3890 if (prefs_common.ext_editor_cmd &&
3891 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
3892 *(p + 1) == 's' && !strchr(p + 2, '%')) {
3893 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
3895 if (prefs_common.ext_editor_cmd)
3896 g_warning(_("External editor command line is invalid: `%s'\n"),
3897 prefs_common.ext_editor_cmd);
3898 g_snprintf(buf, sizeof(buf), def_cmd, file);
3901 cmdline = g_strsplit(buf, " ", 1024);
3902 execvp(cmdline[0], cmdline);
3905 g_strfreev(cmdline);
3910 static gboolean compose_ext_editor_kill(Compose *compose)
3912 pid_t pgid = compose->exteditor_pid * -1;
3915 ret = kill(pgid, 0);
3917 if (ret == 0 || (ret == -1 && EPERM == errno)) {
3921 msg = g_strdup_printf
3922 (_("The external editor is still working.\n"
3923 "Force terminating the process?\n"
3924 "process group id: %d"), -pgid);
3925 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
3928 if (val == G_ALERTDEFAULT) {
3929 gdk_input_remove(compose->exteditor_tag);
3930 close(compose->exteditor_readdes);
3932 if (kill(pgid, SIGTERM) < 0) perror("kill");
3933 waitpid(compose->exteditor_pid, NULL, 0);
3935 g_warning(_("Terminated process group id: %d"), -pgid);
3936 g_warning(_("Temporary file: %s"),
3937 compose->exteditor_file);
3939 compose_set_ext_editor_sensitive(compose, TRUE);
3941 g_free(compose->exteditor_file);
3942 compose->exteditor_file = NULL;
3943 compose->exteditor_pid = -1;
3944 compose->exteditor_readdes = -1;
3945 compose->exteditor_tag = -1;
3953 static void compose_input_cb(gpointer data, gint source,
3954 GdkInputCondition condition)
3957 Compose *compose = (Compose *)data;
3960 debug_print(_("Compose: input from monitoring process\n"));
3962 gdk_input_remove(compose->exteditor_tag);
3965 if (read(source, &buf[i], 1) < 1) {
3969 if (buf[i] == '\n') {
3974 if (i == sizeof(buf) - 1)
3978 waitpid(compose->exteditor_pid, NULL, 0);
3980 if (buf[0] == '0') { /* success */
3981 GtkSText *text = GTK_STEXT(compose->text);
3983 gtk_stext_freeze(text);
3984 gtk_stext_set_point(text, 0);
3985 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
3986 compose_insert_file(compose, compose->exteditor_file);
3987 compose_changed_cb(NULL, compose);
3988 gtk_stext_thaw(text);
3990 if (unlink(compose->exteditor_file) < 0)
3991 FILE_OP_ERROR(compose->exteditor_file, "unlink");
3992 } else if (buf[0] == '1') { /* failed */
3993 g_warning(_("Couldn't exec external editor\n"));
3994 if (unlink(compose->exteditor_file) < 0)
3995 FILE_OP_ERROR(compose->exteditor_file, "unlink");
3996 } else if (buf[0] == '2') {
3997 g_warning(_("Couldn't write to file\n"));
3998 } else if (buf[0] == '3') {
3999 g_warning(_("Pipe read failed\n"));
4004 compose_set_ext_editor_sensitive(compose, TRUE);
4006 g_free(compose->exteditor_file);
4007 compose->exteditor_file = NULL;
4008 compose->exteditor_pid = -1;
4009 compose->exteditor_readdes = -1;
4010 compose->exteditor_tag = -1;
4013 static void compose_set_ext_editor_sensitive(Compose *compose,
4016 GtkItemFactory *ifactory;
4018 ifactory = gtk_item_factory_from_widget(compose->menubar);
4020 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
4021 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
4022 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
4024 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
4025 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
4026 menu_set_sensitive(ifactory, "/Edit/Wrap long lines", sensitive);
4027 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
4030 gtk_widget_set_sensitive(compose->text, sensitive);
4031 gtk_widget_set_sensitive(compose->send_btn, sensitive);
4032 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
4033 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
4034 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
4035 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
4036 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
4037 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
4040 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
4044 cursor_pos = (text->cursor_pos_x - extra) / char_width;
4045 cursor_pos = MAX(cursor_pos, 0);
4050 /* callback functions */
4052 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
4053 * includes "non-client" (windows-izm) in calculation, so this calculation
4054 * may not be accurate.
4056 static gboolean compose_edit_size_alloc(GtkEditable *widget,
4057 GtkAllocation *allocation,
4058 GtkSHRuler *shruler)
4060 if (prefs_common.show_ruler) {
4062 gint line_width_in_chars;
4064 char_width = gtkut_get_font_width
4065 (GTK_WIDGET(widget)->style->font);
4066 line_width_in_chars =
4067 (allocation->width - allocation->x) / char_width;
4069 /* got the maximum */
4070 gtk_ruler_set_range(GTK_RULER(shruler),
4071 0.0, line_width_in_chars,
4072 calc_cursor_xpos(GTK_STEXT(widget),
4075 /*line_width_in_chars*/ char_width);
4081 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
4083 compose_send_cb(data, 0, NULL);
4086 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
4088 compose_send_later_cb(data, 0, NULL);
4091 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
4093 compose_draft_cb(data, 0, NULL);
4096 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
4098 compose_insert_file_cb(data, 0, NULL);
4101 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
4103 compose_attach_cb(data, 0, NULL);
4106 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
4108 Compose *compose = (Compose *)data;
4110 compose_insert_sig(compose);
4113 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
4115 Compose *compose = (Compose *)data;
4117 compose_exec_ext_editor(compose);
4120 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
4122 Compose *compose = (Compose *)data;
4124 compose_wrap_line(compose);
4127 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
4129 compose_address_cb(data, 0, NULL);
4132 static void select_account(Compose * compose, PrefsAccount * ac)
4134 compose->account = ac;
4135 compose_set_title(compose);
4137 if (ac->protocol == A_NNTP) {
4138 GtkItemFactory *ifactory;
4139 GtkWidget *menuitem;
4141 ifactory = gtk_item_factory_from_widget(compose->menubar);
4142 menu_set_sensitive(ifactory,
4143 "/Message/Followup to", TRUE);
4145 gtk_widget_show(compose->newsgroups_hbox);
4146 gtk_widget_show(compose->newsgroups_entry);
4147 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4150 compose->use_to = FALSE;
4151 compose->use_cc = FALSE;
4153 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4154 gtk_check_menu_item_set_active
4155 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
4156 menu_set_sensitive(ifactory,
4157 "/Message/To", TRUE);
4158 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4159 gtk_check_menu_item_set_active
4160 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
4162 gtk_widget_hide(compose->to_hbox);
4163 gtk_widget_hide(compose->to_entry);
4164 gtk_widget_hide(compose->cc_hbox);
4165 gtk_widget_hide(compose->cc_entry);
4167 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4169 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4173 GtkItemFactory *ifactory;
4174 GtkWidget *menuitem;
4176 ifactory = gtk_item_factory_from_widget(compose->menubar);
4177 menu_set_sensitive(ifactory,
4178 "/Message/Followup to", FALSE);
4180 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
4181 gtk_widget_hide(compose->newsgroups_hbox);
4182 gtk_widget_hide(compose->newsgroups_entry);
4183 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4186 compose->use_to = TRUE;
4187 compose->use_cc = TRUE;
4189 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4190 gtk_check_menu_item_set_active
4191 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4192 menu_set_sensitive(ifactory,
4193 "/Message/To", FALSE);
4194 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4195 gtk_check_menu_item_set_active
4196 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4198 gtk_widget_show(compose->to_hbox);
4199 gtk_widget_show(compose->to_entry);
4200 gtk_widget_show(compose->cc_hbox);
4201 gtk_widget_show(compose->cc_entry);
4203 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4205 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4208 gtk_widget_queue_resize(compose->table_vbox);
4211 static void account_activated(GtkMenuItem *menuitem, gpointer data)
4213 Compose *compose = (Compose *)data;
4217 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
4218 g_return_if_fail(ac != NULL);
4220 if (ac != compose->account)
4221 select_account(compose, ac);
4224 static void attach_selected(GtkCList *clist, gint row, gint column,
4225 GdkEvent *event, gpointer data)
4227 Compose *compose = (Compose *)data;
4229 if (event && event->type == GDK_2BUTTON_PRESS)
4230 compose_attach_property(compose);
4233 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
4236 Compose *compose = (Compose *)data;
4237 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4242 if (event->button == 3) {
4243 if ((clist->selection && !clist->selection->next) ||
4244 !clist->selection) {
4245 gtk_clist_unselect_all(clist);
4246 if (gtk_clist_get_selection_info(clist,
4249 gtk_clist_select_row(clist, row, column);
4250 gtkut_clist_set_focus_row(clist, row);
4253 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
4254 NULL, NULL, event->button, event->time);
4258 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
4261 Compose *compose = (Compose *)data;
4265 switch (event->keyval) {
4267 compose_attach_remove_selected(compose);
4272 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
4274 Compose *compose = (Compose *)data;
4277 val = compose_send(compose);
4279 if (val == 0) gtk_widget_destroy(compose->window);
4282 static void compose_send_later_cb(gpointer data, guint action,
4285 Compose *compose = (Compose *)data;
4287 gchar *to, *newsgroups;
4289 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
4290 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
4291 if (*to == '\0' && *newsgroups == '\0') {
4292 alertpanel_error(_("Recipient is not specified."));
4296 g_snprintf(tmp, 22, "%s%ctmpmsg%d",
4297 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
4299 if (prefs_common.linewrap_at_send)
4300 compose_wrap_line(compose);
4302 if (compose_write_to_file(compose, tmp, FALSE) < 0 ||
4303 compose_queue(compose, tmp) < 0) {
4304 alertpanel_error(_("Can't queue the message."));
4308 if (prefs_common.savemsg) {
4309 if (compose_save_to_outbox(compose, tmp) < 0)
4311 (_("Can't save the message to outbox."));
4314 if (unlink(tmp) < 0)
4315 FILE_OP_ERROR(tmp, "unlink");
4317 gtk_widget_destroy(compose->window);
4320 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
4322 Compose *compose = (Compose *)data;
4326 draft = folder_get_default_draft();
4327 folder_item_scan(draft);
4329 if (procmsg_msg_exist(compose->targetinfo) &&
4330 compose->targetinfo->folder == draft) {
4331 if (folder_item_remove_msg(draft,
4332 compose->targetinfo->msgnum) < 0)
4333 g_warning(_("can't remove the old draft message\n"));
4335 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
4336 G_DIR_SEPARATOR, (gint)compose);
4338 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
4343 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
4351 /* folderview_scan_folder_a(DRAFT_DIR, TRUE); */
4353 gtk_widget_destroy(compose->window);
4356 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
4358 Compose *compose = (Compose *)data;
4361 file_list = filesel_select_multiple_files(_("Select file"), NULL);
4366 for ( tmp = file_list; tmp; tmp = tmp->next) {
4367 gchar *file = (gchar *) tmp->data;
4368 compose_attach_append(compose, file, MIME_UNKNOWN);
4371 g_list_free(file_list);
4375 static void compose_insert_file_cb(gpointer data, guint action,
4378 Compose *compose = (Compose *)data;
4381 file_list = filesel_select_multiple_files(_("Select file"), NULL);
4386 for ( tmp = file_list; tmp; tmp = tmp->next) {
4387 gchar *file = (gchar *) tmp->data;
4388 compose_insert_file(compose, file);
4391 g_list_free(file_list);
4395 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
4398 compose_close_cb(data, 0, NULL);
4402 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
4404 Compose *compose = (Compose *)data;
4407 if (compose->exteditor_tag != -1) {
4408 if (!compose_ext_editor_kill(compose))
4412 if (compose->modified) {
4413 val = alertpanel(_("Discard message"),
4414 _("This message has been modified. discard it?"),
4415 _("Discard"), _("to Draft"), _("Cancel"));
4418 case G_ALERTDEFAULT:
4420 case G_ALERTALTERNATE:
4421 compose_draft_cb(data, 0, NULL);
4428 gtk_widget_destroy(compose->window);
4431 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
4433 Compose *compose = (Compose *)data;
4435 addressbook_open(compose);
4438 static void compose_ext_editor_cb(gpointer data, guint action,
4441 Compose *compose = (Compose *)data;
4443 compose_exec_ext_editor(compose);
4446 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
4448 compose_destroy(compose);
4451 static void compose_cut_cb(Compose *compose)
4453 if (compose->focused_editable &&
4454 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4455 gtk_editable_cut_clipboard
4456 (GTK_EDITABLE(compose->focused_editable));
4459 static void compose_copy_cb(Compose *compose)
4461 if (compose->focused_editable &&
4462 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4463 gtk_editable_copy_clipboard
4464 (GTK_EDITABLE(compose->focused_editable));
4467 static void compose_paste_cb(Compose *compose)
4469 if (compose->focused_editable &&
4470 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4471 gtk_editable_paste_clipboard
4472 (GTK_EDITABLE(compose->focused_editable));
4475 static void compose_allsel_cb(Compose *compose)
4477 if (compose->focused_editable &&
4478 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4479 gtk_editable_select_region
4480 (GTK_EDITABLE(compose->focused_editable), 0, -1);
4483 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
4485 if (GTK_IS_EDITABLE(widget))
4486 compose->focused_editable = widget;
4489 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
4491 if (compose->modified == FALSE) {
4492 compose->modified = TRUE;
4493 compose_set_title(compose);
4497 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
4500 gtk_stext_set_point(GTK_STEXT(widget),
4501 gtk_editable_get_position(GTK_EDITABLE(widget)));
4505 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
4508 gtk_stext_set_point(GTK_STEXT(widget),
4509 gtk_editable_get_position(GTK_EDITABLE(widget)));
4513 static void compose_toggle_to_cb(gpointer data, guint action,
4516 Compose *compose = (Compose *)data;
4518 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4519 gtk_widget_show(compose->to_hbox);
4520 gtk_widget_show(compose->to_entry);
4521 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
4522 compose->use_to = TRUE;
4524 gtk_widget_hide(compose->to_hbox);
4525 gtk_widget_hide(compose->to_entry);
4526 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
4527 gtk_widget_queue_resize(compose->table_vbox);
4528 compose->use_to = FALSE;
4531 if (addressbook_get_target_compose() == compose)
4532 addressbook_set_target_compose(compose);
4535 static void compose_toggle_cc_cb(gpointer data, guint action,
4538 Compose *compose = (Compose *)data;
4540 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4541 gtk_widget_show(compose->cc_hbox);
4542 gtk_widget_show(compose->cc_entry);
4543 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
4544 compose->use_cc = TRUE;
4546 gtk_widget_hide(compose->cc_hbox);
4547 gtk_widget_hide(compose->cc_entry);
4548 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
4549 gtk_widget_queue_resize(compose->table_vbox);
4550 compose->use_cc = FALSE;
4553 if (addressbook_get_target_compose() == compose)
4554 addressbook_set_target_compose(compose);
4557 static void compose_toggle_bcc_cb(gpointer data, guint action,
4560 Compose *compose = (Compose *)data;
4562 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4563 gtk_widget_show(compose->bcc_hbox);
4564 gtk_widget_show(compose->bcc_entry);
4565 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
4566 compose->use_bcc = TRUE;
4568 gtk_widget_hide(compose->bcc_hbox);
4569 gtk_widget_hide(compose->bcc_entry);
4570 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
4571 gtk_widget_queue_resize(compose->table_vbox);
4572 compose->use_bcc = FALSE;
4575 if (addressbook_get_target_compose() == compose)
4576 addressbook_set_target_compose(compose);
4579 static void compose_toggle_replyto_cb(gpointer data, guint action,
4582 Compose *compose = (Compose *)data;
4584 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4585 gtk_widget_show(compose->reply_hbox);
4586 gtk_widget_show(compose->reply_entry);
4587 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
4588 compose->use_replyto = TRUE;
4590 gtk_widget_hide(compose->reply_hbox);
4591 gtk_widget_hide(compose->reply_entry);
4592 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
4593 gtk_widget_queue_resize(compose->table_vbox);
4594 compose->use_replyto = FALSE;
4598 static void compose_toggle_followupto_cb(gpointer data, guint action,
4601 Compose *compose = (Compose *)data;
4603 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4604 gtk_widget_show(compose->followup_hbox);
4605 gtk_widget_show(compose->followup_entry);
4606 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
4607 compose->use_followupto = TRUE;
4609 gtk_widget_hide(compose->followup_hbox);
4610 gtk_widget_hide(compose->followup_entry);
4611 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
4612 gtk_widget_queue_resize(compose->table_vbox);
4613 compose->use_followupto = FALSE;
4617 static void compose_toggle_attach_cb(gpointer data, guint action,
4620 Compose *compose = (Compose *)data;
4622 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4623 gtk_widget_ref(compose->edit_vbox);
4625 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4626 compose->edit_vbox);
4627 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
4628 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
4630 gtk_widget_show(compose->paned);
4632 gtk_widget_unref(compose->edit_vbox);
4633 gtk_widget_unref(compose->paned);
4635 compose->use_attach = TRUE;
4637 gtk_widget_ref(compose->paned);
4638 gtk_widget_ref(compose->edit_vbox);
4640 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4642 gtk_container_remove(GTK_CONTAINER(compose->paned),
4643 compose->edit_vbox);
4644 gtk_box_pack_start(GTK_BOX(compose->vbox2),
4645 compose->edit_vbox, TRUE, TRUE, 0);
4647 gtk_widget_unref(compose->edit_vbox);
4649 compose->use_attach = FALSE;
4654 static void compose_toggle_sign_cb(gpointer data, guint action,
4657 Compose *compose = (Compose *)data;
4659 if (GTK_CHECK_MENU_ITEM(widget)->active)
4660 compose->use_signing = TRUE;
4662 compose->use_signing = FALSE;
4665 static void compose_toggle_encrypt_cb(gpointer data, guint action,
4668 Compose *compose = (Compose *)data;
4670 if (GTK_CHECK_MENU_ITEM(widget)->active)
4671 compose->use_encryption = TRUE;
4673 compose->use_encryption = FALSE;
4675 #endif /* USE_GPGME */
4677 static void compose_toggle_ruler_cb(gpointer data, guint action,
4680 Compose *compose = (Compose *)data;
4682 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4683 gtk_widget_show(compose->ruler_hbox);
4684 prefs_common.show_ruler = TRUE;
4686 gtk_widget_hide(compose->ruler_hbox);
4687 gtk_widget_queue_resize(compose->edit_vbox);
4688 prefs_common.show_ruler = FALSE;
4692 static void compose_attach_drag_received_cb (GtkWidget *widget,
4693 GdkDragContext *drag_context,
4696 GtkSelectionData *data,
4701 Compose *compose = (Compose *)user_data;
4704 list = uri_list_extract_filenames((const gchar *)data->data);
4705 for (tmp = list; tmp != NULL; tmp = tmp->next)
4706 compose_attach_append(compose, (const gchar *)tmp->data,
4708 list_free_strings(list);
4712 static void compose_insert_drag_received_cb (GtkWidget *widget,
4713 GdkDragContext *drag_context,
4716 GtkSelectionData *data,
4721 Compose *compose = (Compose *)user_data;
4724 list = uri_list_extract_filenames((const gchar *)data->data);
4725 for (tmp = list; tmp != NULL; tmp = tmp->next)
4726 compose_insert_file(compose, (const gchar *)tmp->data);
4727 list_free_strings(list);
4731 static void to_activated(GtkWidget *widget, Compose *compose)
4733 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
4734 gtk_widget_grab_focus(compose->newsgroups_entry);
4736 gtk_widget_grab_focus(compose->subject_entry);
4739 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
4741 gtk_widget_grab_focus(compose->subject_entry);
4744 static void subject_activated(GtkWidget *widget, Compose *compose)
4746 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
4747 gtk_widget_grab_focus(compose->cc_entry);
4748 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4749 gtk_widget_grab_focus(compose->bcc_entry);
4750 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4751 gtk_widget_grab_focus(compose->reply_entry);
4752 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4753 gtk_widget_grab_focus(compose->followup_entry);
4755 gtk_widget_grab_focus(compose->text);
4758 static void cc_activated(GtkWidget *widget, Compose *compose)
4760 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4761 gtk_widget_grab_focus(compose->bcc_entry);
4762 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4763 gtk_widget_grab_focus(compose->reply_entry);
4764 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4765 gtk_widget_grab_focus(compose->followup_entry);
4767 gtk_widget_grab_focus(compose->text);
4770 static void bcc_activated(GtkWidget *widget, Compose *compose)
4772 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4773 gtk_widget_grab_focus(compose->reply_entry);
4774 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4775 gtk_widget_grab_focus(compose->followup_entry);
4777 gtk_widget_grab_focus(compose->text);
4780 static void replyto_activated(GtkWidget *widget, Compose *compose)
4782 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4783 gtk_widget_grab_focus(compose->followup_entry);
4785 gtk_widget_grab_focus(compose->text);
4788 static void followupto_activated(GtkWidget *widget, Compose *compose)
4790 gtk_widget_grab_focus(compose->text);
4793 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
4796 Compose *compose = (Compose *)data;
4798 if (GTK_CHECK_MENU_ITEM(widget)->active)
4799 compose->return_receipt = TRUE;
4801 compose->return_receipt = FALSE;
4804 static gchar *compose_quote_fmt (Compose *compose,
4809 gchar * quote_str = NULL;
4811 if (qmark != NULL) {
4814 quote_fmt_init(msginfo, NULL);
4815 quote_fmt_scan_string(qmark);
4818 p = quote_fmt_get_buffer();
4821 (_("Quote mark format error."));
4824 quote_str = alloca(strlen(p) + 1);
4825 strcpy(quote_str, p);
4829 quote_fmt_init(msginfo, quote_str);
4830 quote_fmt_scan_string(fmt);
4833 if (quote_fmt_get_buffer() == NULL)
4835 (_("Message reply/forward format error."));
4837 return quote_fmt_get_buffer();