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_set_editable(GTK_STEXT(text), TRUE);
2995 if (prefs_common.smart_wrapping) {
2996 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
2997 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
3000 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
3002 gtk_signal_connect(GTK_OBJECT(text), "changed",
3003 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
3004 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
3005 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3006 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
3007 GTK_SIGNAL_FUNC(compose_button_press_cb),
3010 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
3011 GTK_SIGNAL_FUNC(compose_key_press_cb),
3014 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
3015 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
3019 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3021 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
3022 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
3025 gtk_widget_show_all(vbox);
3027 style = gtk_widget_get_style(text);
3029 /* workaround for the slow down of GtkText when using Pixmap theme */
3030 if (style->engine) {
3031 GtkThemeEngine *engine;
3033 engine = style->engine;
3034 style->engine = NULL;
3035 new_style = gtk_style_copy(style);
3036 style->engine = engine;
3038 new_style = gtk_style_copy(style);
3040 if (prefs_common.textfont) {
3043 charset = conv_get_current_charset();
3044 if (MB_CUR_MAX == 1) {
3047 Xstrdup_a(fontstr, prefs_common.textfont, );
3048 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
3050 font = gdk_font_load(fontstr);
3052 font = gdk_fontset_load(prefs_common.textfont);
3054 gdk_font_unref(new_style->font);
3055 new_style->font = font;
3059 gtk_widget_set_style(text, new_style);
3061 color[0] = quote_color;
3062 cmap = gdk_window_get_colormap(window->window);
3063 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
3064 if (success[0] == FALSE) {
3065 g_warning("Compose: color allocation failed.\n");
3066 style = gtk_widget_get_style(text);
3067 quote_color = style->black;
3070 n_entries = sizeof(compose_popup_entries) /
3071 sizeof(compose_popup_entries[0]);
3072 popupmenu = menu_create_items(compose_popup_entries, n_entries,
3073 "<Compose>", &popupfactory,
3076 ifactory = gtk_item_factory_from_widget(menubar);
3077 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
3078 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
3081 if (account->protocol == A_NNTP) {
3082 gtk_widget_hide(to_hbox);
3083 gtk_widget_hide(to_entry);
3084 gtk_widget_hide(cc_hbox);
3085 gtk_widget_hide(cc_entry);
3086 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
3087 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
3089 gtk_widget_hide(newsgroups_hbox);
3090 gtk_widget_hide(newsgroups_entry);
3091 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
3093 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
3097 switch (prefs_common.toolbar_style) {
3099 gtk_widget_hide(handlebox);
3102 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3106 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3110 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3115 gtk_widget_show(window);
3117 address_completion_start(window);
3119 compose->window = window;
3120 compose->vbox = vbox;
3121 compose->menubar = menubar;
3122 compose->handlebox = handlebox;
3124 compose->vbox2 = vbox2;
3126 compose->table_vbox = table_vbox;
3127 compose->table = table;
3128 compose->to_hbox = to_hbox;
3129 compose->to_entry = to_entry;
3130 compose->newsgroups_hbox = newsgroups_hbox;
3131 compose->newsgroups_entry = newsgroups_entry;
3132 compose->subject_entry = subject_entry;
3133 compose->cc_hbox = cc_hbox;
3134 compose->cc_entry = cc_entry;
3135 compose->bcc_hbox = bcc_hbox;
3136 compose->bcc_entry = bcc_entry;
3137 compose->reply_hbox = reply_hbox;
3138 compose->reply_entry = reply_entry;
3139 compose->followup_hbox = followup_hbox;
3140 compose->followup_entry = followup_entry;
3142 compose->paned = paned;
3144 compose->attach_scrwin = attach_scrwin;
3145 compose->attach_clist = attach_clist;
3147 compose->edit_vbox = edit_vbox;
3148 compose->ruler_hbox = ruler_hbox;
3149 compose->ruler = ruler;
3150 compose->scrolledwin = scrolledwin;
3151 compose->text = text;
3153 compose->focused_editable = NULL;
3155 compose->popupmenu = popupmenu;
3156 compose->popupfactory = popupfactory;
3158 compose->mode = COMPOSE_NEW;
3160 compose->replyto = NULL;
3162 compose->bcc = NULL;
3163 compose->followup_to = NULL;
3164 compose->inreplyto = NULL;
3165 compose->references = NULL;
3166 compose->msgid = NULL;
3167 compose->boundary = NULL;
3170 compose->use_signing = FALSE;
3171 compose->use_encryption = FALSE;
3172 #endif /* USE_GPGME */
3174 compose->modified = FALSE;
3176 compose->return_receipt = FALSE;
3178 compose->to_list = NULL;
3179 compose->newsgroup_list = NULL;
3181 compose->exteditor_file = NULL;
3182 compose->exteditor_pid = -1;
3183 compose->exteditor_readdes = -1;
3184 compose->exteditor_tag = -1;
3186 compose_set_title(compose);
3188 compose->use_bcc = FALSE;
3189 compose->use_replyto = FALSE;
3190 compose->use_followupto = FALSE;
3193 if (account->protocol != A_NNTP) {
3194 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
3195 gtk_check_menu_item_set_active
3196 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3197 gtk_widget_set_sensitive(menuitem, FALSE);
3198 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3199 gtk_check_menu_item_set_active
3200 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3201 gtk_widget_set_sensitive(menuitem, FALSE);
3204 if (account->set_autocc && account->auto_cc) {
3205 compose->use_cc = TRUE;
3206 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
3207 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3208 gtk_check_menu_item_set_active
3209 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3212 if (account->set_autobcc) {
3213 compose->use_bcc = TRUE;
3214 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
3215 gtk_check_menu_item_set_active
3216 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3217 if (account->auto_bcc)
3218 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
3221 if (account->set_autoreplyto) {
3222 compose->use_replyto = TRUE;
3223 menuitem = gtk_item_factory_get_item(ifactory,
3224 "/Message/Reply to");
3225 gtk_check_menu_item_set_active
3226 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3227 if (account->auto_replyto)
3228 gtk_entry_set_text(GTK_ENTRY(reply_entry),
3229 account->auto_replyto);
3232 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
3233 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3234 prefs_common.show_ruler);
3237 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
3238 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3239 prefs_common.default_sign);
3240 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
3241 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3242 prefs_common.default_encrypt);
3243 #endif /* USE_GPGME */
3245 addressbook_set_target_compose(compose);
3247 compose_list = g_list_append(compose_list, compose);
3250 compose->use_to = FALSE;
3251 compose->use_cc = FALSE;
3253 compose->use_attach = FALSE;
3255 if (!compose->use_bcc) {
3256 gtk_widget_hide(bcc_hbox);
3257 gtk_widget_hide(bcc_entry);
3258 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
3260 if (!compose->use_replyto) {
3261 gtk_widget_hide(reply_hbox);
3262 gtk_widget_hide(reply_entry);
3263 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
3265 if (!compose->use_followupto) {
3266 gtk_widget_hide(followup_hbox);
3267 gtk_widget_hide(followup_entry);
3268 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
3271 if (!prefs_common.show_ruler)
3272 gtk_widget_hide(ruler_hbox);
3274 select_account(compose, account);
3279 #include "pixmaps/stock_mail_send.xpm"
3280 #include "pixmaps/stock_mail_send_queue.xpm"
3281 #include "pixmaps/stock_mail.xpm"
3282 #include "pixmaps/stock_paste.xpm"
3283 #include "pixmaps/stock_mail_attach.xpm"
3284 #include "pixmaps/stock_mail_compose.xpm"
3285 #include "pixmaps/linewrap.xpm"
3286 #include "pixmaps/tb_address_book.xpm"
3288 #define CREATE_TOOLBAR_ICON(xpm_d) \
3290 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
3291 &container->style->white, \
3293 icon_wid = gtk_pixmap_new(icon, mask); \
3296 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
3301 GtkWidget *icon_wid;
3302 GtkWidget *send_btn;
3303 GtkWidget *sendl_btn;
3304 GtkWidget *draft_btn;
3305 GtkWidget *insert_btn;
3306 GtkWidget *attach_btn;
3308 GtkWidget *exteditor_btn;
3309 GtkWidget *linewrap_btn;
3310 GtkWidget *addrbook_btn;
3312 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
3314 gtk_container_add(GTK_CONTAINER(container), toolbar);
3315 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
3316 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
3317 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
3318 GTK_TOOLBAR_SPACE_LINE);
3320 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
3321 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3325 icon_wid, toolbar_send_cb, compose);
3327 CREATE_TOOLBAR_ICON(stock_mail_send_queue_xpm);
3328 /* CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm); */
3329 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3331 _("Put into queue folder and send later"),
3333 icon_wid, toolbar_send_later_cb,
3336 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3337 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3339 _("Save to draft folder"),
3341 icon_wid, toolbar_draft_cb,
3344 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3346 CREATE_TOOLBAR_ICON(stock_paste_xpm);
3347 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3351 icon_wid, toolbar_insert_cb,
3354 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
3355 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3359 icon_wid, toolbar_attach_cb,
3362 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3364 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3365 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3367 _("Insert signature"),
3369 icon_wid, toolbar_sig_cb, compose);
3371 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3373 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
3374 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3376 _("Edit with external editor"),
3379 toolbar_ext_editor_cb,
3382 CREATE_TOOLBAR_ICON(linewrap_xpm);
3383 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3385 _("Wrap long lines"),
3388 toolbar_linewrap_cb,
3391 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3393 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
3394 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3398 icon_wid, toolbar_address_cb,
3401 compose->toolbar = toolbar;
3402 compose->send_btn = send_btn;
3403 compose->sendl_btn = sendl_btn;
3404 compose->draft_btn = draft_btn;
3405 compose->insert_btn = insert_btn;
3406 compose->attach_btn = attach_btn;
3407 compose->sig_btn = sig_btn;
3408 compose->exteditor_btn = exteditor_btn;
3409 compose->linewrap_btn = linewrap_btn;
3410 compose->addrbook_btn = addrbook_btn;
3412 gtk_widget_show_all(toolbar);
3415 #undef CREATE_TOOLBAR_ICON
3417 static GtkWidget *compose_account_option_menu_create(Compose *compose)
3423 gint num = 0, def_menu = 0;
3425 accounts = account_get_list();
3426 g_return_val_if_fail(accounts != NULL, NULL);
3428 hbox = gtk_hbox_new(FALSE, 0);
3429 optmenu = gtk_option_menu_new();
3430 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3431 menu = gtk_menu_new();
3433 for (; accounts != NULL; accounts = accounts->next, num++) {
3434 PrefsAccount *ac = (PrefsAccount *)accounts->data;
3435 GtkWidget *menuitem;
3438 if (ac == compose->account) def_menu = num;
3440 name = g_strdup_printf("%s: %s <%s>",
3441 ac->account_name, ac->name, ac->address);
3442 MENUITEM_ADD(menu, menuitem, name, ac);
3444 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
3445 GTK_SIGNAL_FUNC(account_activated),
3449 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
3450 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
3455 static void compose_destroy(Compose *compose)
3458 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3461 /* NOTE: address_completion_end() does nothing with the window
3462 * however this may change. */
3463 address_completion_end(compose->window);
3465 slist_free_strings(compose->to_list);
3466 g_slist_free(compose->to_list);
3467 slist_free_strings(compose->newsgroup_list);
3468 g_slist_free(compose->newsgroup_list);
3470 procmsg_msginfo_free(compose->targetinfo);
3472 g_free(compose->replyto);
3473 g_free(compose->cc);
3474 g_free(compose->bcc);
3475 g_free(compose->newsgroups);
3476 g_free(compose->followup_to);
3478 g_free(compose->inreplyto);
3479 g_free(compose->references);
3480 g_free(compose->msgid);
3481 g_free(compose->boundary);
3483 g_free(compose->exteditor_file);
3485 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3487 compose_attach_info_free(ainfo);
3489 if (addressbook_get_target_compose() == compose)
3490 addressbook_set_target_compose(NULL);
3492 prefs_common.compose_width = compose->scrolledwin->allocation.width;
3493 prefs_common.compose_height = compose->window->allocation.height;
3495 gtk_widget_destroy(compose->paned);
3499 compose_list = g_list_remove(compose_list, compose);
3502 static void compose_attach_info_free(AttachInfo *ainfo)
3504 g_free(ainfo->file);
3505 g_free(ainfo->content_type);
3506 g_free(ainfo->name);
3510 static void compose_attach_remove_selected(Compose *compose)
3512 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3516 while (clist->selection != NULL) {
3517 row = GPOINTER_TO_INT(clist->selection->data);
3518 ainfo = gtk_clist_get_row_data(clist, row);
3519 compose_attach_info_free(ainfo);
3520 gtk_clist_remove(clist, row);
3524 static struct _AttachProperty
3527 GtkWidget *mimetype_entry;
3528 GtkWidget *encoding_optmenu;
3529 GtkWidget *path_entry;
3530 GtkWidget *filename_entry;
3532 GtkWidget *cancel_btn;
3535 static void compose_attach_property(Compose *compose)
3537 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3541 GtkOptionMenu *optmenu;
3543 if (!clist->selection) return;
3544 row = GPOINTER_TO_INT(clist->selection->data);
3546 ainfo = gtk_clist_get_row_data(clist, row);
3549 if (!attach_prop.window)
3550 compose_attach_property_create(&cancelled);
3551 gtk_widget_grab_focus(attach_prop.ok_btn);
3552 gtk_widget_show(attach_prop.window);
3553 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
3555 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
3556 if (ainfo->encoding == ENC_UNKNOWN)
3557 gtk_option_menu_set_history(optmenu, ENC_BASE64);
3559 gtk_option_menu_set_history(optmenu, ainfo->encoding);
3561 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
3562 ainfo->content_type ? ainfo->content_type : "");
3563 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
3564 ainfo->file ? ainfo->file : "");
3565 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
3566 ainfo->name ? ainfo->name : "");
3570 gchar *cnttype = NULL;
3574 GtkWidget *menuitem;
3578 if (cancelled == TRUE) {
3579 gtk_widget_hide(attach_prop.window);
3583 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
3584 if (*text != '\0') {
3587 text = g_strstrip(g_strdup(text));
3588 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
3589 cnttype = g_strdup(text);
3592 alertpanel_error(_("Invalid MIME type."));
3598 menu = gtk_option_menu_get_menu(optmenu);
3599 menuitem = gtk_menu_get_active(GTK_MENU(menu));
3600 ainfo->encoding = GPOINTER_TO_INT
3601 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
3603 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
3604 if (*text != '\0') {
3605 if (is_file_exist(text) &&
3606 (size = get_file_size(text)) > 0)
3607 file = g_strdup(text);
3610 (_("File doesn't exist or is empty."));
3616 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
3617 if (*text != '\0') {
3618 g_free(ainfo->name);
3619 ainfo->name = g_strdup(text);
3623 g_free(ainfo->content_type);
3624 ainfo->content_type = cnttype;
3627 g_free(ainfo->file);
3633 gtk_clist_set_text(clist, row, COL_MIMETYPE,
3634 ainfo->content_type);
3635 gtk_clist_set_text(clist, row, COL_SIZE,
3636 to_human_readable(ainfo->size));
3637 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
3639 gtk_widget_hide(attach_prop.window);
3644 #define SET_LABEL_AND_ENTRY(str, entry, top) \
3646 label = gtk_label_new(str); \
3647 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
3648 GTK_FILL, 0, 0, 0); \
3649 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
3651 entry = gtk_entry_new(); \
3652 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
3653 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
3656 static void compose_attach_property_create(gboolean *cancelled)
3662 GtkWidget *mimetype_entry;
3665 GtkWidget *optmenu_menu;
3666 GtkWidget *menuitem;
3667 GtkWidget *path_entry;
3668 GtkWidget *filename_entry;
3671 GtkWidget *cancel_btn;
3672 GList *mime_type_list, *strlist;
3674 debug_print("Creating attach_property window...\n");
3676 window = gtk_window_new(GTK_WINDOW_DIALOG);
3677 gtk_widget_set_usize(window, 480, -1);
3678 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
3679 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
3680 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
3681 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
3682 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3683 GTK_SIGNAL_FUNC(attach_property_delete_event),
3685 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
3686 GTK_SIGNAL_FUNC(attach_property_key_pressed),
3689 vbox = gtk_vbox_new(FALSE, 8);
3690 gtk_container_add(GTK_CONTAINER(window), vbox);
3692 table = gtk_table_new(4, 2, FALSE);
3693 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
3694 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
3695 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
3697 label = gtk_label_new(_("MIME type"));
3698 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
3700 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3701 mimetype_entry = gtk_combo_new();
3702 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
3703 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3705 /* stuff with list */
3706 mime_type_list = procmime_get_mime_type_list();
3708 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
3709 MimeType *type = (MimeType *) mime_type_list->data;
3710 strlist = g_list_append(strlist,
3711 g_strdup_printf("%s/%s",
3712 type->type, type->sub_type));
3715 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
3717 for (mime_type_list = strlist; mime_type_list != NULL;
3718 mime_type_list = mime_type_list->next)
3719 g_free(mime_type_list->data);
3720 g_list_free(strlist);
3722 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
3724 label = gtk_label_new(_("Encoding"));
3725 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
3727 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3729 hbox = gtk_hbox_new(FALSE, 0);
3730 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
3731 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3733 optmenu = gtk_option_menu_new();
3734 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3736 optmenu_menu = gtk_menu_new();
3737 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
3738 gtk_widget_set_sensitive(menuitem, FALSE);
3739 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
3740 gtk_widget_set_sensitive(menuitem, FALSE);
3741 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
3742 gtk_widget_set_sensitive(menuitem, FALSE);
3743 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
3745 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
3747 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
3748 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
3750 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
3751 &cancel_btn, _("Cancel"), NULL, NULL);
3752 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
3753 gtk_widget_grab_default(ok_btn);
3755 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
3756 GTK_SIGNAL_FUNC(attach_property_ok),
3758 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
3759 GTK_SIGNAL_FUNC(attach_property_cancel),
3762 gtk_widget_show_all(vbox);
3764 attach_prop.window = window;
3765 attach_prop.mimetype_entry = mimetype_entry;
3766 attach_prop.encoding_optmenu = optmenu;
3767 attach_prop.path_entry = path_entry;
3768 attach_prop.filename_entry = filename_entry;
3769 attach_prop.ok_btn = ok_btn;
3770 attach_prop.cancel_btn = cancel_btn;
3773 #undef SET_LABEL_AND_ENTRY
3775 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
3781 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
3787 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
3788 gboolean *cancelled)
3796 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
3797 gboolean *cancelled)
3799 if (event && event->keyval == GDK_Escape) {
3805 static void compose_exec_ext_editor(Compose *compose)
3811 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
3812 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3814 if (pipe(pipe_fds) < 0) {
3819 if ((pid = fork()) < 0) {
3825 /* close the write side of the pipe */
3828 compose->exteditor_file = g_strdup(tmp);
3829 compose->exteditor_pid = pid;
3830 compose->exteditor_readdes = pipe_fds[0];
3832 compose_set_ext_editor_sensitive(compose, FALSE);
3834 compose->exteditor_tag =
3835 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
3836 compose_input_cb, compose);
3837 } else { /* process-monitoring process */
3843 /* close the read side of the pipe */
3846 if (compose_write_body_to_file(compose, tmp) < 0) {
3847 fd_write(pipe_fds[1], "2\n", 2);
3851 pid_ed = compose_exec_ext_editor_real(tmp);
3853 fd_write(pipe_fds[1], "1\n", 2);
3857 /* wait until editor is terminated */
3858 waitpid(pid_ed, NULL, 0);
3860 fd_write(pipe_fds[1], "0\n", 2);
3867 static gint compose_exec_ext_editor_real(const gchar *file)
3869 static gchar *def_cmd = "emacs %s";
3875 g_return_val_if_fail(file != NULL, -1);
3877 if ((pid = fork()) < 0) {
3882 if (pid != 0) return pid;
3884 /* grandchild process */
3886 if (setpgid(0, getppid()))
3889 if (prefs_common.ext_editor_cmd &&
3890 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
3891 *(p + 1) == 's' && !strchr(p + 2, '%')) {
3892 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
3894 if (prefs_common.ext_editor_cmd)
3895 g_warning(_("External editor command line is invalid: `%s'\n"),
3896 prefs_common.ext_editor_cmd);
3897 g_snprintf(buf, sizeof(buf), def_cmd, file);
3900 cmdline = g_strsplit(buf, " ", 1024);
3901 execvp(cmdline[0], cmdline);
3904 g_strfreev(cmdline);
3909 static gboolean compose_ext_editor_kill(Compose *compose)
3911 pid_t pgid = compose->exteditor_pid * -1;
3914 ret = kill(pgid, 0);
3916 if (ret == 0 || (ret == -1 && EPERM == errno)) {
3920 msg = g_strdup_printf
3921 (_("The external editor is still working.\n"
3922 "Force terminating the process?\n"
3923 "process group id: %d"), -pgid);
3924 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
3927 if (val == G_ALERTDEFAULT) {
3928 gdk_input_remove(compose->exteditor_tag);
3929 close(compose->exteditor_readdes);
3931 if (kill(pgid, SIGTERM) < 0) perror("kill");
3932 waitpid(compose->exteditor_pid, NULL, 0);
3934 g_warning(_("Terminated process group id: %d"), -pgid);
3935 g_warning(_("Temporary file: %s"),
3936 compose->exteditor_file);
3938 compose_set_ext_editor_sensitive(compose, TRUE);
3940 g_free(compose->exteditor_file);
3941 compose->exteditor_file = NULL;
3942 compose->exteditor_pid = -1;
3943 compose->exteditor_readdes = -1;
3944 compose->exteditor_tag = -1;
3952 static void compose_input_cb(gpointer data, gint source,
3953 GdkInputCondition condition)
3956 Compose *compose = (Compose *)data;
3959 debug_print(_("Compose: input from monitoring process\n"));
3961 gdk_input_remove(compose->exteditor_tag);
3964 if (read(source, &buf[i], 1) < 1) {
3968 if (buf[i] == '\n') {
3973 if (i == sizeof(buf) - 1)
3977 waitpid(compose->exteditor_pid, NULL, 0);
3979 if (buf[0] == '0') { /* success */
3980 GtkSText *text = GTK_STEXT(compose->text);
3982 gtk_stext_freeze(text);
3983 gtk_stext_set_point(text, 0);
3984 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
3985 compose_insert_file(compose, compose->exteditor_file);
3986 compose_changed_cb(NULL, compose);
3987 gtk_stext_thaw(text);
3989 if (unlink(compose->exteditor_file) < 0)
3990 FILE_OP_ERROR(compose->exteditor_file, "unlink");
3991 } else if (buf[0] == '1') { /* failed */
3992 g_warning(_("Couldn't exec external editor\n"));
3993 if (unlink(compose->exteditor_file) < 0)
3994 FILE_OP_ERROR(compose->exteditor_file, "unlink");
3995 } else if (buf[0] == '2') {
3996 g_warning(_("Couldn't write to file\n"));
3997 } else if (buf[0] == '3') {
3998 g_warning(_("Pipe read failed\n"));
4003 compose_set_ext_editor_sensitive(compose, TRUE);
4005 g_free(compose->exteditor_file);
4006 compose->exteditor_file = NULL;
4007 compose->exteditor_pid = -1;
4008 compose->exteditor_readdes = -1;
4009 compose->exteditor_tag = -1;
4012 static void compose_set_ext_editor_sensitive(Compose *compose,
4015 GtkItemFactory *ifactory;
4017 ifactory = gtk_item_factory_from_widget(compose->menubar);
4019 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
4020 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
4021 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
4023 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
4024 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
4025 menu_set_sensitive(ifactory, "/Edit/Wrap long lines", sensitive);
4026 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
4029 gtk_widget_set_sensitive(compose->text, sensitive);
4030 gtk_widget_set_sensitive(compose->send_btn, sensitive);
4031 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
4032 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
4033 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
4034 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
4035 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
4036 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
4039 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
4043 cursor_pos = (text->cursor_pos_x - extra) / char_width;
4044 cursor_pos = MAX(cursor_pos, 0);
4049 /* callback functions */
4051 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
4052 * includes "non-client" (windows-izm) in calculation, so this calculation
4053 * may not be accurate.
4055 static gboolean compose_edit_size_alloc(GtkEditable *widget,
4056 GtkAllocation *allocation,
4057 GtkSHRuler *shruler)
4059 if (prefs_common.show_ruler) {
4061 gint line_width_in_chars;
4063 char_width = gtkut_get_font_width
4064 (GTK_WIDGET(widget)->style->font);
4065 line_width_in_chars =
4066 (allocation->width - allocation->x) / char_width;
4068 /* got the maximum */
4069 gtk_ruler_set_range(GTK_RULER(shruler),
4070 0.0, line_width_in_chars,
4071 calc_cursor_xpos(GTK_STEXT(widget),
4074 /*line_width_in_chars*/ char_width);
4080 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
4082 compose_send_cb(data, 0, NULL);
4085 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
4087 compose_send_later_cb(data, 0, NULL);
4090 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
4092 compose_draft_cb(data, 0, NULL);
4095 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
4097 compose_insert_file_cb(data, 0, NULL);
4100 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
4102 compose_attach_cb(data, 0, NULL);
4105 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
4107 Compose *compose = (Compose *)data;
4109 compose_insert_sig(compose);
4112 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
4114 Compose *compose = (Compose *)data;
4116 compose_exec_ext_editor(compose);
4119 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
4121 Compose *compose = (Compose *)data;
4123 compose_wrap_line(compose);
4126 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
4128 compose_address_cb(data, 0, NULL);
4131 static void select_account(Compose * compose, PrefsAccount * ac)
4133 compose->account = ac;
4134 compose_set_title(compose);
4136 if (ac->protocol == A_NNTP) {
4137 GtkItemFactory *ifactory;
4138 GtkWidget *menuitem;
4140 ifactory = gtk_item_factory_from_widget(compose->menubar);
4141 menu_set_sensitive(ifactory,
4142 "/Message/Followup to", TRUE);
4144 gtk_widget_show(compose->newsgroups_hbox);
4145 gtk_widget_show(compose->newsgroups_entry);
4146 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4149 compose->use_to = FALSE;
4150 compose->use_cc = FALSE;
4152 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4153 gtk_check_menu_item_set_active
4154 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
4155 menu_set_sensitive(ifactory,
4156 "/Message/To", TRUE);
4157 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4158 gtk_check_menu_item_set_active
4159 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
4161 gtk_widget_hide(compose->to_hbox);
4162 gtk_widget_hide(compose->to_entry);
4163 gtk_widget_hide(compose->cc_hbox);
4164 gtk_widget_hide(compose->cc_entry);
4166 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4168 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4172 GtkItemFactory *ifactory;
4173 GtkWidget *menuitem;
4175 ifactory = gtk_item_factory_from_widget(compose->menubar);
4176 menu_set_sensitive(ifactory,
4177 "/Message/Followup to", FALSE);
4179 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
4180 gtk_widget_hide(compose->newsgroups_hbox);
4181 gtk_widget_hide(compose->newsgroups_entry);
4182 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4185 compose->use_to = TRUE;
4186 compose->use_cc = TRUE;
4188 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4189 gtk_check_menu_item_set_active
4190 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4191 menu_set_sensitive(ifactory,
4192 "/Message/To", FALSE);
4193 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4194 gtk_check_menu_item_set_active
4195 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4197 gtk_widget_show(compose->to_hbox);
4198 gtk_widget_show(compose->to_entry);
4199 gtk_widget_show(compose->cc_hbox);
4200 gtk_widget_show(compose->cc_entry);
4202 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4204 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4207 gtk_widget_queue_resize(compose->table_vbox);
4210 static void account_activated(GtkMenuItem *menuitem, gpointer data)
4212 Compose *compose = (Compose *)data;
4216 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
4217 g_return_if_fail(ac != NULL);
4219 if (ac != compose->account)
4220 select_account(compose, ac);
4223 static void attach_selected(GtkCList *clist, gint row, gint column,
4224 GdkEvent *event, gpointer data)
4226 Compose *compose = (Compose *)data;
4228 if (event && event->type == GDK_2BUTTON_PRESS)
4229 compose_attach_property(compose);
4232 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
4235 Compose *compose = (Compose *)data;
4236 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4241 if (event->button == 3) {
4242 if ((clist->selection && !clist->selection->next) ||
4243 !clist->selection) {
4244 gtk_clist_unselect_all(clist);
4245 if (gtk_clist_get_selection_info(clist,
4248 gtk_clist_select_row(clist, row, column);
4249 gtkut_clist_set_focus_row(clist, row);
4252 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
4253 NULL, NULL, event->button, event->time);
4257 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
4260 Compose *compose = (Compose *)data;
4264 switch (event->keyval) {
4266 compose_attach_remove_selected(compose);
4271 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
4273 Compose *compose = (Compose *)data;
4276 val = compose_send(compose);
4278 if (val == 0) gtk_widget_destroy(compose->window);
4281 static void compose_send_later_cb(gpointer data, guint action,
4284 Compose *compose = (Compose *)data;
4286 gchar *to, *newsgroups;
4288 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
4289 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
4290 if (*to == '\0' && *newsgroups == '\0') {
4291 alertpanel_error(_("Recipient is not specified."));
4295 g_snprintf(tmp, 22, "%s%ctmpmsg%d",
4296 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
4298 if (prefs_common.linewrap_at_send)
4299 compose_wrap_line(compose);
4301 if (compose_write_to_file(compose, tmp, FALSE) < 0 ||
4302 compose_queue(compose, tmp) < 0) {
4303 alertpanel_error(_("Can't queue the message."));
4307 if (prefs_common.savemsg) {
4308 if (compose_save_to_outbox(compose, tmp) < 0)
4310 (_("Can't save the message to outbox."));
4313 if (unlink(tmp) < 0)
4314 FILE_OP_ERROR(tmp, "unlink");
4316 gtk_widget_destroy(compose->window);
4319 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
4321 Compose *compose = (Compose *)data;
4325 draft = folder_get_default_draft();
4326 folder_item_scan(draft);
4328 if (procmsg_msg_exist(compose->targetinfo) &&
4329 compose->targetinfo->folder == draft) {
4330 if (folder_item_remove_msg(draft,
4331 compose->targetinfo->msgnum) < 0)
4332 g_warning(_("can't remove the old draft message\n"));
4334 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
4335 G_DIR_SEPARATOR, (gint)compose);
4337 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
4342 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
4350 /* folderview_scan_folder_a(DRAFT_DIR, TRUE); */
4352 gtk_widget_destroy(compose->window);
4355 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
4357 Compose *compose = (Compose *)data;
4360 file_list = filesel_select_multiple_files(_("Select file"), NULL);
4365 for ( tmp = file_list; tmp; tmp = tmp->next) {
4366 gchar *file = (gchar *) tmp->data;
4367 compose_attach_append(compose, file, MIME_UNKNOWN);
4370 g_list_free(file_list);
4374 static void compose_insert_file_cb(gpointer data, guint action,
4377 Compose *compose = (Compose *)data;
4380 file_list = filesel_select_multiple_files(_("Select file"), NULL);
4385 for ( tmp = file_list; tmp; tmp = tmp->next) {
4386 gchar *file = (gchar *) tmp->data;
4387 compose_insert_file(compose, file);
4390 g_list_free(file_list);
4394 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
4397 compose_close_cb(data, 0, NULL);
4401 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
4403 Compose *compose = (Compose *)data;
4406 if (compose->exteditor_tag != -1) {
4407 if (!compose_ext_editor_kill(compose))
4411 if (compose->modified) {
4412 val = alertpanel(_("Discard message"),
4413 _("This message has been modified. discard it?"),
4414 _("Discard"), _("to Draft"), _("Cancel"));
4417 case G_ALERTDEFAULT:
4419 case G_ALERTALTERNATE:
4420 compose_draft_cb(data, 0, NULL);
4427 gtk_widget_destroy(compose->window);
4430 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
4432 Compose *compose = (Compose *)data;
4434 addressbook_open(compose);
4437 static void compose_ext_editor_cb(gpointer data, guint action,
4440 Compose *compose = (Compose *)data;
4442 compose_exec_ext_editor(compose);
4445 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
4447 compose_destroy(compose);
4450 static void compose_cut_cb(Compose *compose)
4452 if (compose->focused_editable &&
4453 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4454 gtk_editable_cut_clipboard
4455 (GTK_EDITABLE(compose->focused_editable));
4458 static void compose_copy_cb(Compose *compose)
4460 if (compose->focused_editable &&
4461 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4462 gtk_editable_copy_clipboard
4463 (GTK_EDITABLE(compose->focused_editable));
4466 static void compose_paste_cb(Compose *compose)
4468 if (compose->focused_editable &&
4469 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4470 gtk_editable_paste_clipboard
4471 (GTK_EDITABLE(compose->focused_editable));
4474 static void compose_allsel_cb(Compose *compose)
4476 if (compose->focused_editable &&
4477 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4478 gtk_editable_select_region
4479 (GTK_EDITABLE(compose->focused_editable), 0, -1);
4482 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
4484 if (GTK_IS_EDITABLE(widget))
4485 compose->focused_editable = widget;
4488 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
4490 if (compose->modified == FALSE) {
4491 compose->modified = TRUE;
4492 compose_set_title(compose);
4496 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
4499 gtk_stext_set_point(GTK_STEXT(widget),
4500 gtk_editable_get_position(GTK_EDITABLE(widget)));
4504 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
4507 gtk_stext_set_point(GTK_STEXT(widget),
4508 gtk_editable_get_position(GTK_EDITABLE(widget)));
4512 static void compose_toggle_to_cb(gpointer data, guint action,
4515 Compose *compose = (Compose *)data;
4517 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4518 gtk_widget_show(compose->to_hbox);
4519 gtk_widget_show(compose->to_entry);
4520 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
4521 compose->use_to = TRUE;
4523 gtk_widget_hide(compose->to_hbox);
4524 gtk_widget_hide(compose->to_entry);
4525 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
4526 gtk_widget_queue_resize(compose->table_vbox);
4527 compose->use_to = FALSE;
4530 if (addressbook_get_target_compose() == compose)
4531 addressbook_set_target_compose(compose);
4534 static void compose_toggle_cc_cb(gpointer data, guint action,
4537 Compose *compose = (Compose *)data;
4539 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4540 gtk_widget_show(compose->cc_hbox);
4541 gtk_widget_show(compose->cc_entry);
4542 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
4543 compose->use_cc = TRUE;
4545 gtk_widget_hide(compose->cc_hbox);
4546 gtk_widget_hide(compose->cc_entry);
4547 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
4548 gtk_widget_queue_resize(compose->table_vbox);
4549 compose->use_cc = FALSE;
4552 if (addressbook_get_target_compose() == compose)
4553 addressbook_set_target_compose(compose);
4556 static void compose_toggle_bcc_cb(gpointer data, guint action,
4559 Compose *compose = (Compose *)data;
4561 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4562 gtk_widget_show(compose->bcc_hbox);
4563 gtk_widget_show(compose->bcc_entry);
4564 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
4565 compose->use_bcc = TRUE;
4567 gtk_widget_hide(compose->bcc_hbox);
4568 gtk_widget_hide(compose->bcc_entry);
4569 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
4570 gtk_widget_queue_resize(compose->table_vbox);
4571 compose->use_bcc = FALSE;
4574 if (addressbook_get_target_compose() == compose)
4575 addressbook_set_target_compose(compose);
4578 static void compose_toggle_replyto_cb(gpointer data, guint action,
4581 Compose *compose = (Compose *)data;
4583 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4584 gtk_widget_show(compose->reply_hbox);
4585 gtk_widget_show(compose->reply_entry);
4586 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
4587 compose->use_replyto = TRUE;
4589 gtk_widget_hide(compose->reply_hbox);
4590 gtk_widget_hide(compose->reply_entry);
4591 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
4592 gtk_widget_queue_resize(compose->table_vbox);
4593 compose->use_replyto = FALSE;
4597 static void compose_toggle_followupto_cb(gpointer data, guint action,
4600 Compose *compose = (Compose *)data;
4602 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4603 gtk_widget_show(compose->followup_hbox);
4604 gtk_widget_show(compose->followup_entry);
4605 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
4606 compose->use_followupto = TRUE;
4608 gtk_widget_hide(compose->followup_hbox);
4609 gtk_widget_hide(compose->followup_entry);
4610 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
4611 gtk_widget_queue_resize(compose->table_vbox);
4612 compose->use_followupto = FALSE;
4616 static void compose_toggle_attach_cb(gpointer data, guint action,
4619 Compose *compose = (Compose *)data;
4621 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4622 gtk_widget_ref(compose->edit_vbox);
4624 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4625 compose->edit_vbox);
4626 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
4627 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
4629 gtk_widget_show(compose->paned);
4631 gtk_widget_unref(compose->edit_vbox);
4632 gtk_widget_unref(compose->paned);
4634 compose->use_attach = TRUE;
4636 gtk_widget_ref(compose->paned);
4637 gtk_widget_ref(compose->edit_vbox);
4639 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4641 gtk_container_remove(GTK_CONTAINER(compose->paned),
4642 compose->edit_vbox);
4643 gtk_box_pack_start(GTK_BOX(compose->vbox2),
4644 compose->edit_vbox, TRUE, TRUE, 0);
4646 gtk_widget_unref(compose->edit_vbox);
4648 compose->use_attach = FALSE;
4653 static void compose_toggle_sign_cb(gpointer data, guint action,
4656 Compose *compose = (Compose *)data;
4658 if (GTK_CHECK_MENU_ITEM(widget)->active)
4659 compose->use_signing = TRUE;
4661 compose->use_signing = FALSE;
4664 static void compose_toggle_encrypt_cb(gpointer data, guint action,
4667 Compose *compose = (Compose *)data;
4669 if (GTK_CHECK_MENU_ITEM(widget)->active)
4670 compose->use_encryption = TRUE;
4672 compose->use_encryption = FALSE;
4674 #endif /* USE_GPGME */
4676 static void compose_toggle_ruler_cb(gpointer data, guint action,
4679 Compose *compose = (Compose *)data;
4681 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4682 gtk_widget_show(compose->ruler_hbox);
4683 prefs_common.show_ruler = TRUE;
4685 gtk_widget_hide(compose->ruler_hbox);
4686 gtk_widget_queue_resize(compose->edit_vbox);
4687 prefs_common.show_ruler = FALSE;
4691 static void compose_attach_drag_received_cb (GtkWidget *widget,
4692 GdkDragContext *drag_context,
4695 GtkSelectionData *data,
4700 Compose *compose = (Compose *)user_data;
4703 list = uri_list_extract_filenames((const gchar *)data->data);
4704 for (tmp = list; tmp != NULL; tmp = tmp->next)
4705 compose_attach_append(compose, (const gchar *)tmp->data,
4707 list_free_strings(list);
4711 static void compose_insert_drag_received_cb (GtkWidget *widget,
4712 GdkDragContext *drag_context,
4715 GtkSelectionData *data,
4720 Compose *compose = (Compose *)user_data;
4723 list = uri_list_extract_filenames((const gchar *)data->data);
4724 for (tmp = list; tmp != NULL; tmp = tmp->next)
4725 compose_insert_file(compose, (const gchar *)tmp->data);
4726 list_free_strings(list);
4730 static void to_activated(GtkWidget *widget, Compose *compose)
4732 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
4733 gtk_widget_grab_focus(compose->newsgroups_entry);
4735 gtk_widget_grab_focus(compose->subject_entry);
4738 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
4740 gtk_widget_grab_focus(compose->subject_entry);
4743 static void subject_activated(GtkWidget *widget, Compose *compose)
4745 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
4746 gtk_widget_grab_focus(compose->cc_entry);
4747 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4748 gtk_widget_grab_focus(compose->bcc_entry);
4749 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4750 gtk_widget_grab_focus(compose->reply_entry);
4751 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4752 gtk_widget_grab_focus(compose->followup_entry);
4754 gtk_widget_grab_focus(compose->text);
4757 static void cc_activated(GtkWidget *widget, Compose *compose)
4759 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4760 gtk_widget_grab_focus(compose->bcc_entry);
4761 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4762 gtk_widget_grab_focus(compose->reply_entry);
4763 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4764 gtk_widget_grab_focus(compose->followup_entry);
4766 gtk_widget_grab_focus(compose->text);
4769 static void bcc_activated(GtkWidget *widget, Compose *compose)
4771 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4772 gtk_widget_grab_focus(compose->reply_entry);
4773 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4774 gtk_widget_grab_focus(compose->followup_entry);
4776 gtk_widget_grab_focus(compose->text);
4779 static void replyto_activated(GtkWidget *widget, Compose *compose)
4781 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4782 gtk_widget_grab_focus(compose->followup_entry);
4784 gtk_widget_grab_focus(compose->text);
4787 static void followupto_activated(GtkWidget *widget, Compose *compose)
4789 gtk_widget_grab_focus(compose->text);
4792 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
4795 Compose *compose = (Compose *)data;
4797 if (GTK_CHECK_MENU_ITEM(widget)->active)
4798 compose->return_receipt = TRUE;
4800 compose->return_receipt = FALSE;
4803 static gchar *compose_quote_fmt (Compose *compose,
4808 gchar * quote_str = NULL;
4810 if (qmark != NULL) {
4813 quote_fmt_init(msginfo, NULL);
4814 quote_fmt_scan_string(qmark);
4817 p = quote_fmt_get_buffer();
4820 (_("Quote mark format error."));
4823 quote_str = alloca(strlen(p) + 1);
4824 strcpy(quote_str, p);
4828 quote_fmt_init(msginfo, quote_str);
4829 quote_fmt_scan_string(fmt);
4832 if (quote_fmt_get_buffer() == NULL)
4834 (_("Message reply/forward format error."));
4836 return quote_fmt_get_buffer();