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"
101 #include "template_select.h"
104 # include "rfc2015.h"
107 #include "quote_fmt.h"
116 #define N_ATTACH_COLS 3
118 #define B64_LINE_SIZE 57
119 #define B64_BUFFSIZE 77
121 #define MAX_REFERENCES_LEN 999
123 static GdkColor quote_color = {0, 0, 0, 0xbfff};
125 static GList *compose_list = NULL;
127 static Compose *compose_create (PrefsAccount *account);
128 static void compose_toolbar_create (Compose *compose,
129 GtkWidget *container);
130 static GtkWidget *compose_account_option_menu_create
132 static void compose_destroy (Compose *compose);
134 static gint compose_parse_header (Compose *compose,
136 static gchar *compose_parse_references (const gchar *ref,
138 static void compose_quote_file (Compose *compose,
141 static gchar *compose_quote_parse_fmt (Compose *compose,
144 static void compose_reply_set_entry (Compose *compose,
149 followup_and_reply_to);
150 static void compose_reedit_set_entry (Compose *compose,
152 static void compose_insert_sig (Compose *compose);
153 static void compose_insert_file (Compose *compose,
155 static void compose_attach_append (Compose *compose,
157 ContentType cnttype);
158 static void compose_attach_append_with_type(Compose *compose,
161 ContentType cnttype);
162 static void compose_wrap_line (Compose *compose);
163 static void compose_set_title (Compose *compose);
165 static PrefsAccount *compose_current_mail_account(void);
166 /* static gint compose_send (Compose *compose); */
167 static gint compose_write_to_file (Compose *compose,
170 static gint compose_write_body_to_file (Compose *compose,
172 static gint compose_save_to_outbox (Compose *compose,
174 static gint compose_remove_reedit_target (Compose *compose);
175 static gint compose_queue (Compose *compose,
177 static void compose_write_attach (Compose *compose,
179 static gint compose_write_headers (Compose *compose,
181 const gchar *charset,
182 EncodingType encoding,
185 static void compose_convert_header (gchar *dest,
189 static void compose_generate_msgid (Compose *compose,
193 static void compose_attach_info_free (AttachInfo *ainfo);
194 static void compose_attach_remove_selected (Compose *compose);
196 static void compose_attach_property (Compose *compose);
197 static void compose_attach_property_create (gboolean *cancelled);
198 static void attach_property_ok (GtkWidget *widget,
199 gboolean *cancelled);
200 static void attach_property_cancel (GtkWidget *widget,
201 gboolean *cancelled);
202 static gint attach_property_delete_event (GtkWidget *widget,
204 gboolean *cancelled);
205 static void attach_property_key_pressed (GtkWidget *widget,
207 gboolean *cancelled);
209 static void compose_exec_ext_editor (Compose *compose);
210 static gint compose_exec_ext_editor_real (const gchar *file);
211 static gboolean compose_ext_editor_kill (Compose *compose);
212 static void compose_input_cb (gpointer data,
214 GdkInputCondition condition);
215 static void compose_set_ext_editor_sensitive (Compose *compose,
218 static gint calc_cursor_xpos (GtkSText *text,
222 /* callback functions */
224 static gboolean compose_edit_size_alloc (GtkEditable *widget,
225 GtkAllocation *allocation,
226 GtkSHRuler *shruler);
228 static void toolbar_send_cb (GtkWidget *widget,
230 static void toolbar_send_later_cb (GtkWidget *widget,
232 static void toolbar_draft_cb (GtkWidget *widget,
234 static void toolbar_insert_cb (GtkWidget *widget,
236 static void toolbar_attach_cb (GtkWidget *widget,
238 static void toolbar_sig_cb (GtkWidget *widget,
240 static void toolbar_ext_editor_cb (GtkWidget *widget,
242 static void toolbar_linewrap_cb (GtkWidget *widget,
244 static void toolbar_address_cb (GtkWidget *widget,
246 static void template_select_cb (gpointer daat,
251 static void select_account(Compose * compose, PrefsAccount * ac);
252 static void account_activated (GtkMenuItem *menuitem,
255 static void attach_selected (GtkCList *clist,
260 static void attach_button_pressed (GtkWidget *widget,
261 GdkEventButton *event,
263 static void attach_key_pressed (GtkWidget *widget,
267 static void compose_send_cb (gpointer data,
270 static void compose_send_later_cb (gpointer data,
274 static void compose_draft_cb (gpointer data,
278 static void compose_attach_cb (gpointer data,
281 static void compose_insert_file_cb (gpointer data,
285 static void compose_close_cb (gpointer data,
288 static void compose_address_cb (gpointer data,
292 static void compose_ext_editor_cb (gpointer data,
296 static gint compose_delete_cb (GtkWidget *widget,
299 static void compose_destroy_cb (GtkWidget *widget,
302 static void compose_cut_cb (Compose *compose);
303 static void compose_copy_cb (Compose *compose);
304 static void compose_paste_cb (Compose *compose);
305 static void compose_allsel_cb (Compose *compose);
307 static void compose_grab_focus_cb (GtkWidget *widget,
310 static void compose_changed_cb (GtkEditable *editable,
312 static void compose_button_press_cb (GtkWidget *widget,
313 GdkEventButton *event,
316 static void compose_key_press_cb (GtkWidget *widget,
321 static void compose_toggle_to_cb (gpointer data,
324 static void compose_toggle_cc_cb (gpointer data,
327 static void compose_toggle_bcc_cb (gpointer data,
330 static void compose_toggle_replyto_cb (gpointer data,
333 static void compose_toggle_followupto_cb(gpointer data,
336 static void compose_toggle_attach_cb (gpointer data,
339 static void compose_toggle_ruler_cb (gpointer data,
343 static void compose_toggle_sign_cb (gpointer data,
346 static void compose_toggle_encrypt_cb (gpointer data,
350 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
353 static void compose_attach_drag_received_cb (GtkWidget *widget,
354 GdkDragContext *drag_context,
357 GtkSelectionData *data,
361 static void compose_insert_drag_received_cb (GtkWidget *widget,
362 GdkDragContext *drag_context,
365 GtkSelectionData *data,
370 static void to_activated (GtkWidget *widget,
372 static void newsgroups_activated (GtkWidget *widget,
374 static void subject_activated (GtkWidget *widget,
376 static void cc_activated (GtkWidget *widget,
378 static void bcc_activated (GtkWidget *widget,
380 static void replyto_activated (GtkWidget *widget,
382 static void followupto_activated (GtkWidget *widget,
384 static void compose_attach_parts(Compose * compose,
387 static gchar *compose_quote_fmt (Compose *compose,
390 const gchar * qmark);
392 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
394 gboolean ignore_replyto,
395 gboolean followup_and_reply_to);
397 Compose * compose_generic_new (PrefsAccount *account,
401 static GtkItemFactoryEntry compose_popup_entries[] =
403 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
404 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
405 {N_("/---"), NULL, NULL, 0, "<Separator>"},
406 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
409 static GtkItemFactoryEntry compose_entries[] =
411 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
412 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
413 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
414 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
415 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
416 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
418 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
419 {N_("/_Edit/_Undo"), "<control>Z", NULL, 0, NULL},
420 {N_("/_Edit/_Redo"), "<control>Y", NULL, 0, NULL},
421 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
422 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
423 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
424 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
425 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
426 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
427 {N_("/_Edit/Wrap long _lines"), "<alt>L", compose_wrap_line, 0, NULL},
428 {N_("/_Edit/Edit with e_xternal editor"), "<alt>X",
429 compose_ext_editor_cb, 0, NULL},
431 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
432 {N_("/_Message/_Send"), "<shift><control>S",
433 compose_send_cb, 0, NULL},
434 {N_("/_Message/Send _later"), "<shift><alt>S",
435 compose_send_later_cb, 0, NULL},
436 {N_("/_Message/Save to _draft folder"),
437 "<alt>D", compose_draft_cb, 0, NULL},
438 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
439 {N_("/_Message/_To"), NULL, compose_toggle_to_cb, 0, "<ToggleItem>"},
440 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb, 0, "<ToggleItem>"},
441 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb, 0, "<ToggleItem>"},
442 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
443 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
444 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
445 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
446 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
448 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
449 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb, 0, "<ToggleItem>"},
450 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
451 #endif /* USE_GPGME */
452 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
453 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
454 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
455 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
456 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb, 0, NULL},
457 {N_("/_Tool/_Templates ..."), NULL, template_select_cb, 0, NULL},
458 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
459 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
462 static GtkTargetEntry compose_mime_types[] =
464 {"text/uri-list", 0, 0}
467 Compose * compose_new(PrefsAccount *account)
469 return compose_generic_new(account, NULL, NULL);
472 Compose * compose_new_with_recipient(PrefsAccount *account, const gchar *to)
474 return compose_generic_new(account, to, NULL);
477 Compose * compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
479 return compose_generic_new(account, NULL, item);
482 Compose * compose_generic_new(PrefsAccount *account, const gchar *to, FolderItem *item)
486 if (!account) account = cur_account;
487 g_return_val_if_fail(account != NULL, NULL);
489 compose = compose_create(account);
490 compose->mode = COMPOSE_NEW;
491 compose->replyinfo = NULL;
493 if (prefs_common.auto_sig)
494 compose_insert_sig(compose);
495 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
496 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
498 if (account->protocol != A_NNTP) {
500 compose_entry_append(compose, to, COMPOSE_TO);
501 gtk_widget_grab_focus(compose->subject_entry);
503 if(item && item->prefs->enable_default_to) {
504 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
506 gtk_widget_grab_focus(compose->to_entry);
509 if(item && item->prefs->request_return_receipt) {
510 GtkItemFactory *ifactory;
512 ifactory = gtk_item_factory_from_widget(compose->menubar);
513 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
517 compose_entry_append(compose, to, COMPOSE_NEWSGROUPS);
518 gtk_widget_grab_focus(compose->subject_entry);
520 gtk_widget_grab_focus(compose->newsgroups_entry);
526 #define CHANGE_FLAGS(msginfo) \
528 if (msginfo->folder->folder->change_flags != NULL) \
529 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
535 Compose * compose_new_followup_and_replyto(PrefsAccount *account,
536 const gchar *followupto, gchar * to)
540 if (!account) account = cur_account;
541 g_return_val_if_fail(account != NULL, NULL);
542 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
544 compose = compose_create(account);
545 compose->mode = COMPOSE_NEW;
547 if (prefs_common.auto_sig)
548 compose_insert_sig(compose);
549 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
550 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
552 compose_entry_append(compose, to, COMPOSE_TO);
553 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
554 gtk_widget_grab_focus(compose->subject_entry);
560 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
561 gboolean ignore_replyto)
563 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
566 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
568 gboolean ignore_replyto)
570 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
573 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
575 gboolean ignore_replyto,
576 gboolean followup_and_reply_to)
579 PrefsAccount *account;
580 PrefsAccount *reply_account;
583 g_return_if_fail(msginfo != NULL);
584 g_return_if_fail(msginfo->folder != NULL);
586 account = msginfo->folder->folder->account;
587 if (!account && msginfo->to && prefs_common.reply_account_autosel) {
589 Xstrdup_a(to, msginfo->to, return);
591 account = account_find_from_address(to);
593 if(!account&& prefs_common.reply_account_autosel) {
595 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
597 account = account_find_from_address(cc);
601 if (!account) account = cur_account;
602 g_return_if_fail(account != NULL);
604 if (ignore_replyto && account->protocol == A_NNTP &&
605 !followup_and_reply_to) {
607 account_find_from_address(account->address);
609 reply_account = compose_current_mail_account();
613 reply_account = account;
614 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
615 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
617 CHANGE_FLAGS(msginfo);
619 compose = compose_create(reply_account);
620 compose->mode = COMPOSE_REPLY;
621 compose->replyinfo = msginfo;
624 if (followup_and_reply_to) {
625 gtk_widget_show(compose->to_hbox);
626 gtk_widget_show(compose->to_entry);
627 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
628 compose->use_to = TRUE;
631 if(msginfo->folder && msginfo->folder->prefs->request_return_receipt) {
632 GtkItemFactory *ifactory;
634 ifactory = gtk_item_factory_from_widget(compose->menubar);
635 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
638 if (compose_parse_header(compose, msginfo) < 0) return;
639 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
640 followup_and_reply_to);
642 text = GTK_STEXT(compose->text);
643 gtk_stext_freeze(text);
649 if ((fp = procmime_get_text_part(msginfo)) == NULL)
650 g_warning(_("Can't get text part\n"));
654 if (prefs_common.quotemark && *prefs_common.quotemark)
655 qmark = prefs_common.quotemark;
659 quote_str = compose_quote_fmt(compose, msginfo,
660 prefs_common.quotefmt,
664 quote_str = compose_quote_parse_fmt
665 (compose, msginfo, prefs_common.quotefmt);
668 if (quote_str != NULL)
669 gtk_stext_insert(text, NULL, NULL, NULL,
671 /* g_free(quote_str); */
672 /* compose_quote_file(compose, msginfo, fp); */
677 if (prefs_common.auto_sig)
678 compose_insert_sig(compose);
679 gtk_editable_set_position(GTK_EDITABLE(text), 0);
680 gtk_stext_set_point(text, 0);
682 gtk_stext_thaw(text);
683 gtk_widget_grab_focus(compose->text);
687 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
692 g_return_val_if_fail(mimeinfo != NULL, NULL);
694 base = mimeinfo->filename ? mimeinfo->filename
695 : mimeinfo->name ? mimeinfo->name : NULL;
697 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
698 filename = g_strdup_printf("%s%smimetmp%i.html",
705 base = base ? base : "";
706 base = g_basename(base);
708 filename = g_strdup_printf("%s%smimetmp%i",
716 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
722 static gchar * mime_extract_file(gchar * source, MimeInfo *partinfo)
726 if (!partinfo) return;
728 filename = procmime_get_file_name(partinfo);
730 if (procmime_get_part(filename, source, partinfo) < 0)
732 (_("Can't get the part of multipart message."));
737 static void compose_attach_parts(Compose * compose,
747 gint boundary_len = 0;
749 glong fpos, prev_fpos;
754 g_return_if_fail(msginfo != NULL);
758 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
759 mimeinfo = procmime_scan_mime_header(fp);
760 if (!mimeinfo) break;
762 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
763 rfc2015_is_encrypted(mimeinfo)) {
764 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
766 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
767 !msginfo->plaintext_file &&
768 !msginfo->decryption_failed) {
769 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
770 if (msginfo->plaintext_file &&
771 !msginfo->decryption_failed) {
779 #else /* !USE_GPGME */
780 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
781 mimeinfo = procmime_scan_mime_header(fp);
782 #endif /* USE_GPGME */
785 if (!mimeinfo) return;
786 if (mimeinfo->mime_type == MIME_TEXT)
789 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
791 g_return_if_fail(mimeinfo != NULL);
792 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
794 if (mimeinfo->mime_type == MIME_MULTIPART) {
795 g_return_if_fail(mimeinfo->boundary != NULL);
796 g_return_if_fail(mimeinfo->sub == NULL);
798 g_return_if_fail(fp != NULL);
800 boundary = mimeinfo->boundary;
803 boundary_len = strlen(boundary);
805 /* look for first boundary */
806 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
807 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
814 if ((fpos = ftell(fp)) < 0) {
820 for (npart = 0;; npart++) {
822 gboolean eom = FALSE;
826 partinfo = procmime_scan_mime_header(fp);
827 if (!partinfo) break;
830 procmime_mimeinfo_insert(mimeinfo, partinfo);
832 procmime_mimeinfo_free(partinfo);
834 /* look for next boundary */
836 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
837 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
838 if (buf[2 + boundary_len] == '-' &&
839 buf[2 + boundary_len + 1] == '-')
845 eom = TRUE; /* broken MIME message */
848 partinfo->size = fpos - prev_fpos - strlen(buf);
853 source = procmsg_get_message_file_path(msginfo);
855 g_return_if_fail(mimeinfo != NULL);
857 if (!mimeinfo->main && mimeinfo->parent)
859 filename = mime_extract_file(source, mimeinfo);
861 compose_attach_append_with_type(compose, filename,
862 mimeinfo->content_type,
863 mimeinfo->mime_type);
868 if (mimeinfo->sub && mimeinfo->sub->children)
870 filename = mime_extract_file(source, mimeinfo->sub);
872 compose_attach_append_with_type(compose, filename,
873 mimeinfo->content_type,
874 mimeinfo->sub->mime_type);
879 if (mimeinfo->children) {
882 child = mimeinfo->children;
884 filename = mime_extract_file(source, child);
886 compose_attach_append_with_type(compose, filename,
898 procmime_mimeinfo_free_all(mimeinfo);
902 #define INSERT_FW_HEADER(var, hdr) \
903 if (msginfo->var && *msginfo->var) { \
904 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
905 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
906 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
909 Compose * compose_forward(PrefsAccount * account, MsgInfo *msginfo,
913 /* PrefsAccount *account; */
918 g_return_val_if_fail(msginfo != NULL, NULL);
919 g_return_val_if_fail(msginfo->folder != NULL, NULL);
921 account = msginfo->folder->folder->account;
922 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
924 Xstrdup_a(to, msginfo->to, return);
926 account = account_find_from_address(to);
929 if(!account&& prefs_common.forward_account_autosel) {
931 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
933 account = account_find_from_address(cc);
937 if (account == NULL) {
938 account = cur_account;
940 account = msginfo->folder->folder->account;
941 if (!account) account = cur_account;
944 g_return_val_if_fail(account != NULL, NULL);
946 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
947 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
948 CHANGE_FLAGS(msginfo);
950 compose = compose_create(account);
951 compose->mode = COMPOSE_FORWARD;
953 if (msginfo->subject && *msginfo->subject) {
954 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
955 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
959 text = GTK_STEXT(compose->text);
960 gtk_stext_freeze(text);
965 msgfile = procmsg_get_message_file_path(msginfo);
966 if (!is_file_exist(msgfile))
967 g_warning(_("%s: file not exist\n"), msgfile);
969 compose_attach_append(compose, msgfile,
970 MIME_MESSAGE_RFC822);
977 if ((fp = procmime_get_text_part(msginfo)) == NULL)
978 g_warning(_("Can't get text part\n"));
982 if (prefs_common.fw_quotemark &&
983 *prefs_common.fw_quotemark)
984 qmark = prefs_common.fw_quotemark;
988 quote_str = compose_quote_fmt(compose, msginfo,
989 prefs_common.fw_quotefmt,
992 if (quote_str != NULL)
993 gtk_stext_insert(text, NULL, NULL, NULL,
999 compose_attach_parts(compose, msginfo);
1002 if (prefs_common.auto_sig)
1003 compose_insert_sig(compose);
1004 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1005 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1007 gtk_stext_thaw(text);
1008 if (account->protocol != A_NNTP)
1009 gtk_widget_grab_focus(compose->to_entry);
1011 gtk_widget_grab_focus(compose->newsgroups_entry);
1016 #undef INSERT_FW_HEADER
1018 Compose * compose_forward_multiple(PrefsAccount * account,
1019 GSList *msginfo_list)
1026 g_return_val_if_fail(msginfo_list != NULL, NULL);
1028 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1029 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1033 if (account == NULL) {
1034 account = cur_account;
1036 account = msginfo->folder->folder->account;
1037 if (!account) account = cur_account;
1040 g_return_val_if_fail(account != NULL, NULL);
1042 compose = compose_create(account);
1043 compose->mode = COMPOSE_FORWARD;
1045 text = GTK_STEXT(compose->text);
1046 gtk_stext_freeze(text);
1048 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1049 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1050 if (!is_file_exist(msgfile))
1051 g_warning(_("%s: file not exist\n"), msgfile);
1053 compose_attach_append(compose, msgfile,
1054 MIME_MESSAGE_RFC822);
1058 if (prefs_common.auto_sig)
1059 compose_insert_sig(compose);
1060 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1061 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1063 gtk_stext_thaw(text);
1064 if (account->protocol != A_NNTP)
1065 gtk_widget_grab_focus(compose->to_entry);
1067 gtk_widget_grab_focus(compose->newsgroups_entry);
1072 void compose_reedit(MsgInfo *msginfo)
1075 PrefsAccount *account;
1078 gchar buf[BUFFSIZE];
1080 g_return_if_fail(msginfo != NULL);
1081 g_return_if_fail(msginfo->folder != NULL);
1083 account = msginfo->folder->folder->account;
1085 if(!account&& prefs_common.reedit_account_autosel) {
1086 gchar from[BUFFSIZE];
1087 if(!get_header_from_msginfo(msginfo,from,sizeof(from),"FROM:")){ /* Found a FROM header */
1088 extract_address(from);
1089 account = account_find_from_address(from);
1092 if (!account) account = cur_account;
1093 g_return_if_fail(account != NULL);
1095 compose = compose_create(account);
1096 compose->mode = COMPOSE_REEDIT;
1098 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1100 if (compose_parse_header(compose, msginfo) < 0) return;
1101 compose_reedit_set_entry(compose, msginfo);
1103 text = GTK_STEXT(compose->text);
1104 gtk_stext_freeze(text);
1106 if ((fp = procmime_get_text_part(msginfo)) == NULL)
1107 g_warning(_("Can't get text part\n"));
1109 while (fgets(buf, sizeof(buf), fp) != NULL)
1110 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1113 compose_attach_parts(compose, msginfo);
1115 gtk_stext_thaw(text);
1116 gtk_widget_grab_focus(compose->text);
1119 GList *compose_get_compose_list(void)
1121 return compose_list;
1124 void compose_entry_append(Compose *compose, const gchar *address,
1125 ComposeEntryType type)
1130 if (!address || *address == '\0') return;
1134 entry = GTK_ENTRY(compose->cc_entry);
1137 entry = GTK_ENTRY(compose->bcc_entry);
1139 case COMPOSE_NEWSGROUPS:
1140 entry = GTK_ENTRY(compose->newsgroups_entry);
1144 entry = GTK_ENTRY(compose->to_entry);
1148 text = gtk_entry_get_text(entry);
1150 gtk_entry_append_text(entry, ", ");
1151 gtk_entry_append_text(entry, address);
1154 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1156 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1157 {"Cc:", NULL, FALSE},
1158 {"References:", NULL, FALSE},
1159 {"Bcc:", NULL, FALSE},
1160 {"Newsgroups:", NULL, FALSE},
1161 {"Followup-To:", NULL, FALSE},
1162 {NULL, NULL, FALSE}};
1176 g_return_val_if_fail(msginfo != NULL, -1);
1178 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1179 procheader_get_header_fields(fp, hentry);
1182 if (hentry[H_REPLY_TO].body != NULL) {
1183 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1184 compose->replyto = hentry[H_REPLY_TO].body;
1185 hentry[H_REPLY_TO].body = NULL;
1187 if (hentry[H_CC].body != NULL) {
1188 conv_unmime_header_overwrite(hentry[H_CC].body);
1189 compose->cc = hentry[H_CC].body;
1190 hentry[H_CC].body = NULL;
1192 if (hentry[H_REFERENCES].body != NULL) {
1193 if (compose->mode == COMPOSE_REEDIT)
1194 compose->references = hentry[H_REFERENCES].body;
1196 compose->references = compose_parse_references
1197 (hentry[H_REFERENCES].body, msginfo->msgid);
1198 g_free(hentry[H_REFERENCES].body);
1200 hentry[H_REFERENCES].body = NULL;
1202 if (hentry[H_BCC].body != NULL) {
1203 if (compose->mode == COMPOSE_REEDIT) {
1204 conv_unmime_header_overwrite(hentry[H_BCC].body);
1205 compose->bcc = hentry[H_BCC].body;
1207 g_free(hentry[H_BCC].body);
1208 hentry[H_BCC].body = NULL;
1210 if (hentry[H_NEWSGROUPS].body != NULL) {
1211 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1212 hentry[H_NEWSGROUPS].body = NULL;
1214 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1215 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1216 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1217 hentry[H_FOLLOWUP_TO].body = NULL;
1220 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1221 compose->inreplyto = g_strdup(msginfo->inreplyto);
1222 else if (compose->mode != COMPOSE_REEDIT &&
1223 msginfo->msgid && *msginfo->msgid) {
1224 compose->inreplyto = g_strdup(msginfo->msgid);
1226 if (!compose->references) {
1227 if (msginfo->inreplyto && *msginfo->inreplyto)
1228 compose->references =
1229 g_strdup_printf("<%s>\n\t<%s>",
1233 compose->references =
1234 g_strconcat("<", msginfo->msgid, ">",
1242 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1244 GSList *ref_id_list, *cur;
1248 ref_id_list = references_list_append(NULL, ref);
1249 if (!ref_id_list) return NULL;
1250 if (msgid && *msgid)
1251 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1256 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1257 /* "<" + Message-ID + ">" + CR+LF+TAB */
1258 len += strlen((gchar *)cur->data) + 5;
1260 if (len > MAX_REFERENCES_LEN) {
1261 /* remove second message-ID */
1262 if (ref_id_list && ref_id_list->next &&
1263 ref_id_list->next->next) {
1264 g_free(ref_id_list->next->data);
1265 ref_id_list = g_slist_remove
1266 (ref_id_list, ref_id_list->next->data);
1268 slist_free_strings(ref_id_list);
1269 g_slist_free(ref_id_list);
1276 new_ref = g_string_new("");
1277 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1278 if (new_ref->len > 0)
1279 g_string_append(new_ref, "\n\t");
1280 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1283 slist_free_strings(ref_id_list);
1284 g_slist_free(ref_id_list);
1286 new_ref_str = new_ref->str;
1287 g_string_free(new_ref, FALSE);
1293 static void compose_quote_file(Compose *compose, MsgInfo *msginfo, FILE *fp)
1295 GtkSText *text = GTK_STEXT(compose->text);
1298 GdkColor *qcolor = NULL;
1299 gchar buf[BUFFSIZE];
1301 gchar *linep, *cur, *leftp;
1302 gint line_len, cur_len;
1307 // if (prefs_common.enable_color) qcolor = "e_color;
1308 if (prefs_common.quotemark && *prefs_common.quotemark)
1309 qmark = prefs_common.quotemark;
1312 quote_str = compose_quote_parse_fmt(compose, msginfo, qmark);
1313 g_return_if_fail(quote_str != NULL);
1314 qlen = strlen(quote_str);
1316 if (!prefs_common.linewrap_quote ||
1317 prefs_common.linewrap_len <= qlen) {
1318 while (fgets(buf, sizeof(buf), fp) != NULL) {
1319 gtk_stext_insert(text, NULL, qcolor, NULL,
1321 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1327 wrap_len = prefs_common.linewrap_len - qlen;
1329 while (fgets(buf, sizeof(buf), fp) != NULL) {
1331 str_len = strlen(buf);
1333 if (str_len <= wrap_len) {
1334 gtk_stext_insert(text, NULL, qcolor, NULL,
1336 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1337 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1341 linep = cur = leftp = buf;
1342 line_len = cur_len = 0;
1344 while (*cur != '\0') {
1345 ch_len = mblen(cur, MB_CUR_MAX);
1346 if (ch_len < 0) ch_len = 1;
1348 if (ch_len == 1 && isspace(*cur)) {
1349 linep = cur + ch_len;
1350 line_len = cur_len + ch_len;
1353 if (cur_len + ch_len > wrap_len && line_len > 0) {
1354 gtk_stext_insert(text, NULL, qcolor, NULL,
1357 if (isspace(*(linep - 1)))
1358 gtk_stext_insert(text, NULL,
1360 leftp, line_len - 1);
1362 gtk_stext_insert(text, NULL,
1365 gtk_stext_insert(text, NULL, NULL, NULL,
1369 cur_len = cur_len - line_len + ch_len;
1376 linep = cur + ch_len;
1377 line_len = cur_len + ch_len;
1384 gtk_stext_insert(text, NULL, qcolor, NULL,
1386 gtk_stext_insert(text, NULL, qcolor, NULL, leftp, -1);
1387 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1396 static gchar *compose_quote_parse_fmt(Compose *compose, MsgInfo *msginfo,
1400 size_t buf_len = 1024;
1408 if (!fmt || *fmt == '\0') return 0;
1410 Xalloca(mbs, sizeof(wchar_t) + 1, return 0);
1411 Xalloca(wcsfmt, (strlen(fmt) + 1) * sizeof(wchar_t), return 0);
1412 mbstowcs(wcsfmt, fmt, strlen(fmt) + 1);
1415 ext_str = g_malloc(sizeof(gchar) * buf_len);
1416 g_return_val_if_fail(ext_str != NULL, NULL);
1421 len = wctomb(mbs, *sp);
1427 wctomb(mbs, *(++sp));
1432 str = msginfo->date;
1436 str = msginfo->from;
1440 if (!msginfo->fromname) {sp++; break;}
1441 p = msginfo->fromname;
1442 tmp[0] = tmp[1] = tmp[2] = '\0';
1444 if (*p && isalnum(*p))
1445 tmp[0] = toupper(*p);
1452 while (*p && !isspace(*p)) p++;
1453 while (*p && isspace(*p)) p++;
1454 if (*p && isalnum(*p))
1455 tmp[1] = toupper(*p);
1458 if (tmp[1]) str = tmp;
1462 str = msginfo->fromname;
1466 if (!msginfo->fromname) {sp++; break;}
1467 Xstrdup_a(str, msginfo->fromname,
1470 while (*p && !isspace(*p)) p++;
1475 str = msginfo->subject;
1487 if (!msginfo->msgid) {sp++; break;}
1488 Xalloca(str, strlen(msginfo->msgid) + 3,
1490 g_snprintf(str, strlen(msginfo->msgid) + 3,
1491 "<%s>", msginfo->msgid);
1503 while (ext_len + strlen(str) + 1 > buf_len)
1505 ext_str = g_realloc(ext_str,
1506 sizeof(gchar) * buf_len);
1507 g_return_val_if_fail(ext_str != NULL, NULL);
1508 strcpy(ext_str + ext_len, str);
1509 ext_len += strlen(str);
1511 } else if (*mbs == '\\') {
1512 wctomb(mbs, *(++sp));
1530 while (ext_len + strlen(str) + 1 > buf_len)
1532 ext_str = g_realloc(ext_str,
1533 sizeof(gchar) * buf_len);
1534 g_return_val_if_fail(ext_str != NULL, NULL);
1535 strcpy(ext_str + ext_len, str);
1536 ext_len += strlen(str);
1540 while (ext_len + len + 1 > buf_len) buf_len += 1024;
1541 ext_str = g_realloc(ext_str, sizeof(gchar) * buf_len);
1542 g_return_val_if_fail(ext_str != NULL, NULL);
1543 strcpy(ext_str + ext_len, mbs);
1550 ext_str = g_realloc(ext_str, strlen(ext_str) + 1);
1556 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1557 gboolean to_all, gboolean ignore_replyto,
1558 gboolean followup_and_reply_to)
1563 GHashTable *to_table;
1565 g_return_if_fail(compose->account != NULL);
1566 g_return_if_fail(msginfo != NULL);
1568 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1569 gtk_entry_set_text(GTK_ENTRY(compose->to_entry),
1570 ( (compose->replyto && !ignore_replyto)
1572 : msginfo->from ? msginfo->from : ""));
1573 if (compose->account->protocol == A_NNTP)
1574 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry),
1575 compose->followup_to ? compose->followup_to
1576 : compose->newsgroups ? compose->newsgroups
1579 if (msginfo->subject && *msginfo->subject) {
1580 gchar *buf, *buf2, *p;
1582 buf = g_strdup(msginfo->subject);
1583 while (!strncasecmp(buf, "Re:", 3)) {
1585 while (isspace(*p)) p++;
1586 memmove(buf, p, strlen(p) + 1);
1589 buf2 = g_strdup_printf("Re: %s", buf);
1590 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1594 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1596 if (!to_all || compose->account->protocol == A_NNTP) return;
1598 from = g_strdup(compose->replyto ? compose->replyto :
1599 msginfo->from ? msginfo->from : "");
1600 extract_address(from);
1602 cc_list = address_list_append(NULL, msginfo->to);
1603 cc_list = address_list_append(cc_list, compose->cc);
1605 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1606 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1607 if (compose->account)
1608 g_hash_table_insert(to_table, compose->account->address,
1609 GINT_TO_POINTER(1));
1611 /* remove address on To: and that of current account */
1612 for (cur = cc_list; cur != NULL; ) {
1613 GSList *next = cur->next;
1615 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1616 cc_list = g_slist_remove(cc_list, cur->data);
1618 g_hash_table_insert(to_table, cur->data, cur);
1622 g_hash_table_destroy(to_table);
1626 for (cur = cc_list; cur != NULL; cur = cur->next)
1627 compose_entry_append(compose, (gchar *)cur->data,
1629 slist_free_strings(cc_list);
1630 g_slist_free(cc_list);
1634 #define SET_ENTRY(entry, str) \
1637 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1640 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1642 g_return_if_fail(msginfo != NULL);
1644 SET_ENTRY(to_entry, msginfo->to);
1645 SET_ENTRY(subject_entry, msginfo->subject);
1646 SET_ENTRY(cc_entry, compose->cc);
1647 SET_ENTRY(bcc_entry, compose->bcc);
1648 SET_ENTRY(reply_entry, compose->replyto);
1651 GtkItemFactory *ifactory;
1652 GtkWidget *menuitem;
1654 ifactory = gtk_item_factory_from_widget(compose->menubar);
1655 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1656 gtk_check_menu_item_set_active
1657 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1659 if (compose->replyto) {
1660 GtkItemFactory *ifactory;
1661 GtkWidget *menuitem;
1663 ifactory = gtk_item_factory_from_widget(compose->menubar);
1664 menuitem = gtk_item_factory_get_item
1665 (ifactory, "/Message/Reply to");
1666 gtk_check_menu_item_set_active
1667 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1673 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1680 size_t buf_len = 128;
1682 if (strlen(sigfile) < 2)
1685 sigprg = popen(sigfile+1, "r");
1688 buf = g_malloc(buf_len);
1691 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1692 "Unable to insert signature (malloc failed)\n", -1);
1698 while (!feof(sigprg)) {
1699 bzero(buf, buf_len);
1700 fread(buf, buf_len-1, 1, sigprg);
1701 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1709 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1710 "Can't exec file: ", -1);
1711 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1716 static void compose_insert_sig(Compose *compose)
1720 if (compose->account && compose->account->sig_path)
1721 sigfile = g_strdup(compose->account->sig_path);
1723 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1724 DEFAULT_SIGNATURE, NULL);
1727 if (!is_file_or_fifo_exist(sigfile) & (sigfile[0] != '|')) {
1732 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1733 if (prefs_common.sig_sep) {
1734 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1735 prefs_common.sig_sep, -1);
1736 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1740 if (sigfile[0] == '|')
1742 compose_exec_sig(compose, sigfile);
1746 compose_insert_file(compose, sigfile);
1751 static void compose_insert_file(Compose *compose, const gchar *file)
1753 GtkSText *text = GTK_STEXT(compose->text);
1754 gchar buf[BUFFSIZE];
1757 g_return_if_fail(file != NULL);
1759 if ((fp = fopen(file, "r")) == NULL) {
1760 FILE_OP_ERROR(file, "fopen");
1764 gtk_stext_freeze(text);
1766 while (fgets(buf, sizeof(buf), fp) != NULL)
1767 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1769 gtk_stext_thaw(text);
1774 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1775 ContentType cnttype)
1777 gchar *text[N_ATTACH_COLS];
1780 text[COL_MIMETYPE] = ainfo->content_type;
1781 text[COL_SIZE] = to_human_readable(ainfo->size);
1782 text[COL_NAME] = ainfo->name;
1784 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1785 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1787 if (cnttype != MIME_MESSAGE_RFC822)
1788 compose_changed_cb(NULL, compose);
1791 static void compose_attach_append_with_type(Compose *compose,
1794 ContentType cnttype)
1799 if (!is_file_exist(file)) {
1800 g_warning(_("File %s doesn't exist\n"), file);
1803 if ((size = get_file_size(file)) < 0) {
1804 g_warning(_("Can't get file size of %s\n"), file);
1808 alertpanel_notice(_("File %s is empty\n"), file);
1812 if (!compose->use_attach) {
1813 GtkItemFactory *ifactory;
1814 GtkWidget *menuitem;
1816 ifactory = gtk_item_factory_from_widget(compose->menubar);
1817 menuitem = gtk_item_factory_get_item(ifactory,
1819 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1823 ainfo = g_new0(AttachInfo, 1);
1824 ainfo->file = g_strdup(file);
1826 if (cnttype == MIME_MESSAGE_RFC822) {
1827 ainfo->encoding = ENC_7BIT;
1828 ainfo->name = g_strdup_printf(_("Message: %s"),
1831 ainfo->encoding = ENC_BASE64;
1832 ainfo->name = g_strdup(g_basename(file));
1835 ainfo->content_type = g_strdup(type);
1838 compose_attach_info(compose, ainfo, cnttype);
1841 static void compose_attach_append(Compose *compose, const gchar *file,
1842 ContentType cnttype)
1845 gchar *text[N_ATTACH_COLS];
1849 if (!is_file_exist(file)) {
1850 g_warning(_("File %s doesn't exist\n"), file);
1853 if ((size = get_file_size(file)) < 0) {
1854 g_warning(_("Can't get file size of %s\n"), file);
1858 alertpanel_notice(_("File %s is empty\n"), file);
1862 if (!compose->use_attach) {
1863 GtkItemFactory *ifactory;
1864 GtkWidget *menuitem;
1866 ifactory = gtk_item_factory_from_widget(compose->menubar);
1867 menuitem = gtk_item_factory_get_item(ifactory,
1869 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1873 ainfo = g_new0(AttachInfo, 1);
1874 ainfo->file = g_strdup(file);
1876 if (cnttype == MIME_MESSAGE_RFC822) {
1877 ainfo->content_type = g_strdup("message/rfc822");
1878 ainfo->encoding = ENC_7BIT;
1879 ainfo->name = g_strdup_printf(_("Message: %s"),
1882 ainfo->content_type = procmime_get_mime_type(file);
1883 if (!ainfo->content_type)
1884 ainfo->content_type =
1885 g_strdup("application/octet-stream");
1886 ainfo->encoding = ENC_BASE64;
1887 ainfo->name = g_strdup(g_basename(file));
1891 compose_attach_info(compose, ainfo, cnttype);
1894 static void compose_wrap_line(Compose *compose)
1896 GtkSText *text = GTK_STEXT(compose->text);
1898 guint line_pos = 0, cur_pos = 0;
1899 gint line_len = 0, cur_len = 0;
1901 gchar cbuf[MB_CUR_MAX];
1903 gtk_stext_freeze(text);
1905 text_len = gtk_stext_get_length(text);
1907 for (; cur_pos < text_len; cur_pos++) {
1908 if (text->use_wchar)
1910 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
1912 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
1916 if (ch_len == 1 && *cbuf == '\n') {
1917 line_pos = cur_pos + 1;
1918 line_len = cur_len = 0;
1927 if (ch_len == 1 && isspace(*cbuf)) {
1928 line_pos = cur_pos + 1;
1929 line_len = cur_len + ch_len;
1932 if (cur_len + ch_len > prefs_common.linewrap_len &&
1936 if (text->use_wchar)
1937 tlen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
1939 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
1942 if (tlen == 1 && isspace(*cbuf)) {
1943 gtk_stext_set_point(text, line_pos);
1944 gtk_stext_backward_delete(text, 1);
1952 gtk_stext_set_point(text, line_pos);
1953 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1957 cur_len = cur_len - line_len + ch_len;
1963 line_pos = cur_pos + 1;
1964 line_len = cur_len + ch_len;
1969 gtk_stext_thaw(text);
1972 static void compose_set_title(Compose *compose)
1977 edited = compose->modified ? _(" [Edited]") : "";
1978 if (compose->account && compose->account->address)
1979 str = g_strdup_printf(_("%s - Compose message%s"),
1980 compose->account->address, edited);
1982 str = g_strdup_printf(_("Compose message%s"), edited);
1983 gtk_window_set_title(GTK_WINDOW(compose->window), str);
1988 * compose_current_mail_account:
1990 * Find a current mail account (the currently selected account, or the
1991 * default account, if a news account is currently selected). If a
1992 * mail account cannot be found, display an error message.
1994 * Return value: Mail account, or NULL if not found.
1996 static PrefsAccount *
1997 compose_current_mail_account(void)
2001 if (cur_account && cur_account->protocol != A_NNTP)
2004 ac = account_get_default();
2005 if (!ac || ac->protocol == A_NNTP) {
2006 alertpanel_error(_("Account for sending mail is not specified.\n"
2007 "Please select a mail account before sending."));
2014 gint compose_send(Compose *compose)
2016 gchar tmp[MAXPATHLEN + 1];
2017 gchar *to, *newsgroups;
2019 static gboolean lock = FALSE;
2023 g_return_val_if_fail(compose->account != NULL, -1);
2024 g_return_val_if_fail(compose->orig_account != NULL, -1);
2028 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2029 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2030 if (*to == '\0' && *newsgroups == '\0') {
2031 alertpanel_error(_("Recipient is not specified."));
2036 /* write to temporary file */
2037 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2038 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2040 if (prefs_common.linewrap_at_send)
2041 compose_wrap_line(compose);
2043 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2048 if (!compose->to_list && !compose->newsgroup_list) {
2049 g_warning(_("can't get recipient list."));
2055 if (compose->to_list) {
2059 if (compose->account->protocol != A_NNTP)
2060 ac = compose->account;
2061 else if (compose->orig_account->protocol != A_NNTP)
2062 ac = compose->orig_account;
2063 else if (cur_account && cur_account->protocol != A_NNTP)
2066 ac = compose_current_mail_account();
2074 ac = compose->account;
2076 ok = send_message(tmp, ac, compose->to_list);
2077 statusbar_pop_all();
2080 if (ok == 0 && compose->newsgroup_list) {
2083 if (compose->account->protocol == A_NNTP)
2084 folder = FOLDER(compose->account->folder);
2086 folder = FOLDER(compose->orig_account->folder);
2088 ok = news_post(folder, tmp);
2090 alertpanel_error(_("Error occurred while posting the message to %s ."),
2091 compose->account->nntp_server);
2098 /* queue message if failed to send */
2100 if (prefs_common.queue_msg) {
2105 _("Error occurred while sending the message.\n"
2106 "Put this message into queue folder?"),
2107 _("OK"), _("Cancel"), NULL);
2108 if (G_ALERTDEFAULT == val) {
2109 ok = compose_queue(compose, tmp);
2111 alertpanel_error(_("Can't queue the message."));
2114 alertpanel_error(_("Error occurred while sending the message."));
2116 if (compose->mode == COMPOSE_REEDIT) {
2117 compose_remove_reedit_target(compose);
2118 if (compose->targetinfo)
2119 folderview_update_item
2120 (compose->targetinfo->folder, TRUE);
2124 /* save message to outbox */
2125 if (ok == 0 && prefs_common.savemsg) {
2126 if (compose_save_to_outbox(compose, tmp) < 0)
2128 (_("Can't save the message to outbox."));
2136 static gint compose_write_to_file(Compose *compose, const gchar *file,
2143 const gchar *out_codeset;
2144 EncodingType encoding;
2146 if ((fp = fopen(file, "w")) == NULL) {
2147 FILE_OP_ERROR(file, "fopen");
2151 /* chmod for security */
2152 if (change_file_mode_rw(fp, file) < 0) {
2153 FILE_OP_ERROR(file, "chmod");
2154 g_warning(_("can't change file mode\n"));
2157 /* get all composed text */
2158 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2159 len = strlen(chars);
2160 if (is_ascii_str(chars)) {
2161 buf = g_strdup(chars);
2162 out_codeset = "US-ASCII";
2163 encoding = ENC_7BIT;
2165 const gchar *src_codeset;
2167 out_codeset = conv_get_outgoing_charset_str();
2168 if (!strcasecmp(out_codeset, "US-ASCII"))
2169 out_codeset = "ISO-8859-1";
2170 encoding = procmime_get_encoding_for_charset(out_codeset);
2171 debug_print("charset = %s, encoding = %s\n",
2172 out_codeset, procmime_get_encoding_str(encoding));
2174 src_codeset = conv_get_current_charset_str();
2175 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
2180 alertpanel_error(_("Can't convert the codeset of the message."));
2187 if (compose_write_headers
2188 (compose, fp, out_codeset, encoding, is_draft) < 0) {
2189 g_warning(_("can't write headers\n"));
2196 if (compose->use_attach) {
2198 /* This prolog message is ignored by mime software and
2199 * because it would make our signing/encryption task
2200 * tougher, we don't emit it in that case */
2201 if (!compose->use_signing && !compose->use_encryption)
2203 fputs("This is a multi-part message in MIME format.\n", fp);
2205 fprintf(fp, "\n--%s\n", compose->boundary);
2206 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
2208 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2209 procmime_get_encoding_str(encoding));
2215 if (encoding == ENC_BASE64) {
2216 gchar outbuf[B64_BUFFSIZE];
2219 for (i = 0; i < len; i += B64_LINE_SIZE) {
2220 l = MIN(B64_LINE_SIZE, len - i);
2221 to64frombits(outbuf, buf + i, l);
2225 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
2226 FILE_OP_ERROR(file, "fwrite");
2234 if (compose->use_attach)
2235 compose_write_attach(compose, fp);
2237 if (fclose(fp) == EOF) {
2238 FILE_OP_ERROR(file, "fclose");
2244 if (compose->use_signing) {
2245 if (rfc2015_sign(file, compose->account) < 0) {
2250 if (compose->use_encryption) {
2251 if (rfc2015_encrypt(file, compose->to_list) < 0) {
2256 #endif /* USE_GPGME */
2261 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
2267 if ((fp = fopen(file, "w")) == NULL) {
2268 FILE_OP_ERROR(file, "fopen");
2272 /* chmod for security */
2273 if (change_file_mode_rw(fp, file) < 0) {
2274 FILE_OP_ERROR(file, "chmod");
2275 g_warning(_("can't change file mode\n"));
2278 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2281 len = strlen(chars);
2282 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
2283 FILE_OP_ERROR(file, "fwrite");
2292 if (fclose(fp) == EOF) {
2293 FILE_OP_ERROR(file, "fclose");
2300 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
2307 debug_print(_("saving sent message...\n"));
2309 outbox = folder_get_default_outbox();
2310 path = folder_item_get_path(outbox);
2311 if (!is_dir_exist(path))
2312 make_dir_hier(path);
2314 folder_item_scan(outbox);
2315 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
2317 g_warning(_("can't save message\n"));
2321 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
2322 g_warning(_("can't open mark file\n"));
2326 newmsginfo.msgnum = num;
2327 newmsginfo.flags.perm_flags = 0;
2328 newmsginfo.flags.tmp_flags = 0;
2329 procmsg_write_flags(&newmsginfo, fp);
2337 static gint compose_remove_reedit_target(Compose *compose)
2340 MsgInfo *msginfo = compose->targetinfo;
2342 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
2343 if (!msginfo) return -1;
2345 item = msginfo->folder;
2346 g_return_val_if_fail(item != NULL, -1);
2348 folder_item_scan(item);
2349 if (procmsg_msg_exist(msginfo) &&
2350 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
2351 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
2352 g_warning(_("can't remove the old message\n"));
2360 static gint compose_queue(Compose *compose, const gchar *file)
2363 gchar *tmp, *queue_path;
2366 gchar buf[BUFFSIZE];
2369 debug_print(_("queueing message...\n"));
2370 g_return_val_if_fail(compose->to_list != NULL, -1);
2371 g_return_val_if_fail(compose->account != NULL, -1);
2373 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
2374 G_DIR_SEPARATOR, (gint)compose);
2375 if ((fp = fopen(tmp, "w")) == NULL) {
2376 FILE_OP_ERROR(tmp, "fopen");
2380 if ((src_fp = fopen(file, "r")) == NULL) {
2381 FILE_OP_ERROR(file, "fopen");
2387 if (change_file_mode_rw(fp, tmp) < 0) {
2388 FILE_OP_ERROR(tmp, "chmod");
2389 g_warning(_("can't change file mode\n"));
2392 /* queueing variables */
2393 fprintf(fp, "AF:\n");
2394 fprintf(fp, "NF:0\n");
2395 fprintf(fp, "PS:10\n");
2396 fprintf(fp, "SRH:1\n");
2397 fprintf(fp, "SFN:\n");
2398 fprintf(fp, "DSR:\n");
2400 fprintf(fp, "MID:<%s>\n", compose->msgid);
2402 fprintf(fp, "MID:\n");
2403 fprintf(fp, "CFG:\n");
2404 fprintf(fp, "PT:0\n");
2405 fprintf(fp, "S:%s\n", compose->account->address);
2406 fprintf(fp, "RQ:\n");
2407 if (compose->account->smtp_server)
2408 fprintf(fp, "SSV:%s\n", compose->account->smtp_server);
2410 fprintf(fp, "SSV:\n");
2411 if (compose->account->nntp_server)
2412 fprintf(fp, "NSV:%s\n", compose->account->nntp_server);
2414 fprintf(fp, "NSV:\n");
2415 fprintf(fp, "SSH:\n");
2416 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
2417 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
2418 fprintf(fp, ",<%s>", (gchar *)cur->data);
2420 /* Sylpheed account ID */
2421 fprintf(fp, "AID:%d\n", compose->account->account_id);
2424 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
2425 if (fputs(buf, fp) == EOF) {
2426 FILE_OP_ERROR(tmp, "fputs");
2436 if (fclose(fp) == EOF) {
2437 FILE_OP_ERROR(tmp, "fclose");
2443 queue = folder_get_default_queue();
2445 folder_item_scan(queue);
2446 queue_path = folder_item_get_path(queue);
2447 if (!is_dir_exist(queue_path))
2448 make_dir_hier(queue_path);
2449 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
2450 g_warning(_("can't queue the message\n"));
2458 if (compose->mode == COMPOSE_REEDIT) {
2459 compose_remove_reedit_target(compose);
2460 if (compose->targetinfo &&
2461 compose->targetinfo->folder != queue)
2462 folderview_update_item
2463 (compose->targetinfo->folder, TRUE);
2466 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
2467 g_warning(_("can't open mark file\n"));
2471 newmsginfo.msgnum = num;
2472 newmsginfo.flags.perm_flags = 0;
2473 newmsginfo.flags.tmp_flags = 0;
2474 procmsg_write_flags(&newmsginfo, fp);
2479 folder_item_scan(queue);
2480 folderview_update_item(queue, TRUE);
2485 static void compose_write_attach(Compose *compose, FILE *fp)
2488 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2491 gchar filename[BUFFSIZE];
2494 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
2496 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
2497 g_warning(_("Can't open file %s\n"), ainfo->file);
2501 fprintf(fp, "\n--%s\n", compose->boundary);
2503 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
2504 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
2505 fprintf(fp, "Content-Disposition: inline\n");
2507 conv_encode_header(filename, sizeof(filename),
2509 fprintf(fp, "Content-Type: %s;\n"
2511 ainfo->content_type, filename);
2512 fprintf(fp, "Content-Disposition: attachment;\n"
2513 " filename=\"%s\"\n", filename);
2516 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
2517 procmime_get_encoding_str(ainfo->encoding));
2519 if (ainfo->encoding == ENC_7BIT) {
2520 gchar buf[BUFFSIZE];
2522 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
2524 if (len > 1 && buf[len - 1] == '\n' &&
2525 buf[len - 2] == '\r') {
2526 buf[len - 2] = '\n';
2527 buf[len - 1] = '\0';
2532 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
2534 while ((len = fread(inbuf, sizeof(gchar),
2535 B64_LINE_SIZE, attach_fp))
2537 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
2541 if (len > 0 && feof(attach_fp)) {
2542 to64frombits(outbuf, inbuf, len);
2551 fprintf(fp, "\n--%s--\n", compose->boundary);
2554 #define IS_IN_CUSTOM_HEADER(header) \
2555 (compose->account->add_customhdr && \
2556 custom_header_find(compose->account->customhdr_list, header) != NULL)
2558 static gint compose_write_headers(Compose *compose, FILE *fp,
2559 const gchar *charset, EncodingType encoding,
2562 gchar buf[BUFFSIZE];
2564 /* struct utsname utsbuf; */
2566 g_return_val_if_fail(fp != NULL, -1);
2567 g_return_val_if_fail(charset != NULL, -1);
2568 g_return_val_if_fail(compose->account != NULL, -1);
2569 g_return_val_if_fail(compose->account->address != NULL, -1);
2572 if (compose->account->add_date) {
2573 get_rfc822_date(buf, sizeof(buf));
2574 fprintf(fp, "Date: %s\n", buf);
2578 if (!IS_IN_CUSTOM_HEADER("From")) {
2579 if (compose->account->name && *compose->account->name) {
2580 compose_convert_header
2581 (buf, sizeof(buf), compose->account->name,
2583 fprintf(fp, "From: %s <%s>\n",
2584 buf, compose->account->address);
2586 fprintf(fp, "From: %s\n", compose->account->address);
2589 slist_free_strings(compose->to_list);
2590 g_slist_free(compose->to_list);
2591 compose->to_list = NULL;
2594 if (compose->use_to) {
2595 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2597 Xstrdup_a(str, str, return -1);
2600 compose->to_list = address_list_append
2601 (compose->to_list, str);
2602 if (!IS_IN_CUSTOM_HEADER("To")) {
2603 compose_convert_header
2604 (buf, sizeof(buf), str,
2606 fprintf(fp, "To: %s\n", buf);
2612 slist_free_strings(compose->newsgroup_list);
2613 g_slist_free(compose->newsgroup_list);
2614 compose->newsgroup_list = NULL;
2617 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2619 Xstrdup_a(str, str, return -1);
2623 compose->newsgroup_list =
2624 newsgroup_list_append(compose->newsgroup_list,
2626 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
2627 compose_convert_header(buf, sizeof(buf), str,
2628 strlen("Newsgroups: "));
2629 fprintf(fp, "Newsgroups: %s\n", buf);
2634 if (!is_draft && !compose->to_list && !compose->newsgroup_list)
2638 if (compose->use_cc) {
2639 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
2641 Xstrdup_a(str, str, return -1);
2644 compose->to_list = address_list_append
2645 (compose->to_list, str);
2646 if (!IS_IN_CUSTOM_HEADER("Cc")) {
2647 compose_convert_header
2648 (buf, sizeof(buf), str,
2650 fprintf(fp, "Cc: %s\n", buf);
2657 if (compose->use_bcc) {
2658 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
2660 Xstrdup_a(str, str, return -1);
2663 compose->to_list = address_list_append
2664 (compose->to_list, str);
2666 compose_convert_header
2667 (buf, sizeof(buf), str,
2669 fprintf(fp, "Bcc: %s\n", buf);
2676 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2677 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
2678 Xstrdup_a(str, str, return -1);
2681 compose_convert_header(buf, sizeof(buf), str,
2682 strlen("Subject: "));
2683 fprintf(fp, "Subject: %s\n", buf);
2688 if (compose->account->gen_msgid) {
2689 compose_generate_msgid(compose, buf, sizeof(buf));
2690 fprintf(fp, "Message-Id: <%s>\n", buf);
2691 compose->msgid = g_strdup(buf);
2695 if (compose->inreplyto && compose->to_list)
2696 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
2699 if (compose->references)
2700 fprintf(fp, "References: %s\n", compose->references);
2703 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
2704 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
2706 Xstrdup_a(str, str, return -1);
2710 compose_convert_header(buf, sizeof(buf), str,
2711 strlen("Followup-To: "));
2712 fprintf(fp, "Followup-To: %s\n", buf);
2718 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
2719 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
2721 Xstrdup_a(str, str, return -1);
2724 compose_convert_header(buf, sizeof(buf), str,
2725 strlen("Reply-To: "));
2726 fprintf(fp, "Reply-To: %s\n", buf);
2732 if (compose->account->organization &&
2733 !IS_IN_CUSTOM_HEADER("Organization")) {
2734 compose_convert_header(buf, sizeof(buf),
2735 compose->account->organization,
2736 strlen("Organization: "));
2737 fprintf(fp, "Organization: %s\n", buf);
2740 /* Program version and system info */
2741 /* uname(&utsbuf); */
2742 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2743 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
2744 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
2746 gtk_major_version, gtk_minor_version, gtk_micro_version,
2748 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2750 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2751 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
2752 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
2754 gtk_major_version, gtk_minor_version, gtk_micro_version,
2756 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2759 /* custom headers */
2760 if (compose->account->add_customhdr) {
2763 for (cur = compose->account->customhdr_list; cur != NULL;
2765 CustomHeader *chdr = (CustomHeader *)cur->data;
2767 if (strcasecmp(chdr->name, "Date") != 0 &&
2768 strcasecmp(chdr->name, "From") != 0 &&
2769 strcasecmp(chdr->name, "To") != 0 &&
2770 strcasecmp(chdr->name, "Sender") != 0 &&
2771 strcasecmp(chdr->name, "Message-Id") != 0 &&
2772 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
2773 strcasecmp(chdr->name, "References") != 0 &&
2774 strcasecmp(chdr->name, "Mime-Version") != 0 &&
2775 strcasecmp(chdr->name, "Content-Type") != 0 &&
2776 strcasecmp(chdr->name, "Content-Transfer-Encoding")
2778 compose_convert_header
2780 chdr->value ? chdr->value : "",
2781 strlen(chdr->name) + 2);
2782 fprintf(fp, "%s: %s\n", chdr->name, buf);
2787 fprintf(fp, "Mime-Version: 1.0\n");
2788 if (compose->use_attach) {
2789 get_rfc822_date(buf, sizeof(buf));
2790 subst_char(buf, ' ', '_');
2791 subst_char(buf, ',', '_');
2792 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
2793 buf, (guint)compose);
2795 "Content-Type: multipart/mixed;\n"
2796 " boundary=\"%s\"\n", compose->boundary);
2798 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
2799 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2800 procmime_get_encoding_str(encoding));
2803 /* Request Return Receipt */
2804 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
2805 if (compose->return_receipt) {
2806 if (compose->account->name
2807 && *compose->account->name) {
2808 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
2809 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
2811 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
2815 /* separator between header and body */
2821 #undef IS_IN_CUSTOM_HEADER
2823 static void compose_convert_header(gchar *dest, gint len, gchar *src,
2826 g_return_if_fail(src != NULL);
2827 g_return_if_fail(dest != NULL);
2829 if (len < 1) return;
2833 if (is_ascii_str(src)) {
2834 strncpy2(dest, src, len);
2835 dest[len - 1] = '\0';
2838 conv_encode_header(dest, len, src, header_len);
2841 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
2850 if (compose->account && compose->account->address &&
2851 *compose->account->address) {
2852 if (strchr(compose->account->address, '@'))
2853 addr = g_strdup(compose->account->address);
2855 addr = g_strconcat(compose->account->address, "@",
2856 get_domain_name(), NULL);
2858 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
2861 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
2862 lt->tm_year + 1900, lt->tm_mon + 1,
2863 lt->tm_mday, lt->tm_hour,
2864 lt->tm_min, lt->tm_sec,
2865 (guint)random(), addr);
2867 debug_print(_("generated Message-ID: %s\n"), buf);
2872 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
2873 GtkWidget **entry, gint *count,
2874 const gchar *label_str,
2875 gboolean is_addr_entry)
2879 if (GTK_TABLE(table)->nrows < (*count) + 1)
2880 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
2882 *hbox = gtk_hbox_new(FALSE, 0);
2883 label = gtk_label_new
2884 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
2885 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
2886 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
2888 *entry = gtk_entry_new();
2889 gtk_table_attach_defaults
2890 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1);
2891 if (GTK_TABLE(table)->nrows > (*count) + 1)
2892 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
2895 address_completion_register_entry(GTK_ENTRY(*entry));
2900 static Compose *compose_create(PrefsAccount *account)
2906 GtkWidget *handlebox;
2910 GtkWidget *table_vbox;
2912 GtkWidget *from_optmenu_hbox;
2913 GtkWidget *to_entry;
2915 GtkWidget *newsgroups_entry;
2916 GtkWidget *newsgroups_hbox;
2917 GtkWidget *subject_entry;
2918 GtkWidget *cc_entry;
2920 GtkWidget *bcc_entry;
2921 GtkWidget *bcc_hbox;
2922 GtkWidget *reply_entry;
2923 GtkWidget *reply_hbox;
2924 GtkWidget *followup_entry;
2925 GtkWidget *followup_hbox;
2929 GtkWidget *attach_scrwin;
2930 GtkWidget *attach_clist;
2932 GtkWidget *edit_vbox;
2933 GtkWidget *ruler_hbox;
2935 GtkWidget *scrolledwin;
2941 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
2942 guint n_menu_entries;
2943 GtkStyle *style, *new_style;
2946 gboolean success[1];
2948 GtkWidget *popupmenu;
2949 GtkWidget *menuitem;
2950 GtkItemFactory *popupfactory;
2951 GtkItemFactory *ifactory;
2956 g_return_val_if_fail(account != NULL, NULL);
2958 debug_print(_("Creating compose window...\n"));
2959 compose = g_new0(Compose, 1);
2961 compose->account = account;
2962 compose->orig_account = account;
2964 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2965 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
2966 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
2967 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
2968 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
2969 gtk_signal_connect(GTK_OBJECT(window), "destroy",
2970 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
2971 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
2972 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
2973 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
2974 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
2975 gtk_widget_realize(window);
2977 gtkut_widget_set_composer_icon(window);
2979 vbox = gtk_vbox_new(FALSE, 0);
2980 gtk_container_add(GTK_CONTAINER(window), vbox);
2982 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
2983 menubar = menubar_create(window, compose_entries,
2984 n_menu_entries, "<Compose>", compose);
2985 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
2987 handlebox = gtk_handle_box_new();
2988 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
2990 compose_toolbar_create(compose, handlebox);
2992 vbox2 = gtk_vbox_new(FALSE, 2);
2993 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
2994 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
2996 table_vbox = gtk_vbox_new(FALSE, 0);
2997 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
2998 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
3001 table = gtk_table_new(8, 2, FALSE);
3002 gtk_box_pack_start(GTK_BOX(table_vbox), table, FALSE, TRUE, 0);
3004 /* option menu for selecting accounts */
3005 hbox = gtk_hbox_new(FALSE, 0);
3006 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
3007 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3008 gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, count, count + 1,
3010 from_optmenu_hbox = compose_account_option_menu_create(compose);
3011 gtk_table_attach_defaults(GTK_TABLE(table), from_optmenu_hbox,
3012 1, 2, count, count + 1);
3013 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3016 /* header labels and entries */
3017 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
3019 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3020 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
3021 &count, "Newsgroups:", FALSE);
3022 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
3023 compose_add_entry_field(table, &hbox, &subject_entry, &count,
3025 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
3026 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
3028 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
3029 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
3031 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
3032 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
3034 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
3035 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
3036 "Followup-To:", FALSE);
3037 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
3039 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
3041 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
3042 GTK_SIGNAL_FUNC(to_activated), compose);
3043 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
3044 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
3045 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
3046 GTK_SIGNAL_FUNC(subject_activated), compose);
3047 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
3048 GTK_SIGNAL_FUNC(cc_activated), compose);
3049 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
3050 GTK_SIGNAL_FUNC(bcc_activated), compose);
3051 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
3052 GTK_SIGNAL_FUNC(replyto_activated), compose);
3053 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
3054 GTK_SIGNAL_FUNC(followupto_activated), compose);
3056 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
3057 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3058 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
3059 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3060 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
3061 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3062 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
3063 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3064 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
3065 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3066 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
3067 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3068 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
3069 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3071 /* attachment list */
3072 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
3073 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
3074 GTK_POLICY_AUTOMATIC,
3076 gtk_widget_set_usize(attach_scrwin, -1, 80);
3078 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
3079 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
3081 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
3082 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
3083 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
3084 GTK_SELECTION_EXTENDED);
3085 for (i = 0; i < N_ATTACH_COLS; i++)
3086 GTK_WIDGET_UNSET_FLAGS
3087 (GTK_CLIST(attach_clist)->column[i].button,
3089 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
3091 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
3092 GTK_SIGNAL_FUNC(attach_selected), compose);
3093 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
3094 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
3095 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
3096 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
3099 gtk_drag_dest_set(attach_clist,
3100 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3102 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
3103 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
3106 /* pane between attach clist and text */
3107 paned = gtk_vpaned_new();
3108 gtk_paned_add1(GTK_PANED(paned), attach_scrwin);
3109 gtk_widget_ref(paned);
3110 gtk_widget_show_all(paned);
3112 edit_vbox = gtk_vbox_new(FALSE, 0);
3113 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
3116 ruler_hbox = gtk_hbox_new(FALSE, 0);
3117 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
3119 ruler = gtk_shruler_new();
3120 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
3121 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
3123 gtk_widget_set_usize(ruler_hbox, 1, -1);
3126 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3127 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
3128 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
3129 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
3130 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
3132 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
3133 (GTK_SCROLLED_WINDOW(scrolledwin)),
3134 gtk_scrolled_window_get_vadjustment
3135 (GTK_SCROLLED_WINDOW(scrolledwin)));
3136 GTK_STEXT(text)->default_tab_width = 8;
3137 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
3138 if (prefs_common.smart_wrapping) {
3139 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
3140 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
3143 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
3145 gtk_signal_connect(GTK_OBJECT(text), "changed",
3146 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
3147 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
3148 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3149 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
3150 GTK_SIGNAL_FUNC(compose_button_press_cb),
3153 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
3154 GTK_SIGNAL_FUNC(compose_key_press_cb),
3157 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
3158 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
3162 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3164 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
3165 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
3168 gtk_widget_show_all(vbox);
3170 style = gtk_widget_get_style(text);
3172 /* workaround for the slow down of GtkText when using Pixmap theme */
3173 if (style->engine) {
3174 GtkThemeEngine *engine;
3176 engine = style->engine;
3177 style->engine = NULL;
3178 new_style = gtk_style_copy(style);
3179 style->engine = engine;
3181 new_style = gtk_style_copy(style);
3183 if (prefs_common.textfont) {
3186 charset = conv_get_current_charset();
3187 if (MB_CUR_MAX == 1) {
3190 Xstrdup_a(fontstr, prefs_common.textfont, );
3191 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
3193 font = gdk_font_load(fontstr);
3195 font = gdk_fontset_load(prefs_common.textfont);
3197 gdk_font_unref(new_style->font);
3198 new_style->font = font;
3202 gtk_widget_set_style(text, new_style);
3204 color[0] = quote_color;
3205 cmap = gdk_window_get_colormap(window->window);
3206 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
3207 if (success[0] == FALSE) {
3208 g_warning("Compose: color allocation failed.\n");
3209 style = gtk_widget_get_style(text);
3210 quote_color = style->black;
3213 n_entries = sizeof(compose_popup_entries) /
3214 sizeof(compose_popup_entries[0]);
3215 popupmenu = menu_create_items(compose_popup_entries, n_entries,
3216 "<Compose>", &popupfactory,
3219 ifactory = gtk_item_factory_from_widget(menubar);
3220 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
3221 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
3224 if (account->protocol == A_NNTP) {
3225 gtk_widget_hide(to_hbox);
3226 gtk_widget_hide(to_entry);
3227 gtk_widget_hide(cc_hbox);
3228 gtk_widget_hide(cc_entry);
3229 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
3230 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
3232 gtk_widget_hide(newsgroups_hbox);
3233 gtk_widget_hide(newsgroups_entry);
3234 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
3236 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
3240 switch (prefs_common.toolbar_style) {
3242 gtk_widget_hide(handlebox);
3245 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3249 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3253 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3258 gtk_widget_show(window);
3260 address_completion_start(window);
3262 compose->window = window;
3263 compose->vbox = vbox;
3264 compose->menubar = menubar;
3265 compose->handlebox = handlebox;
3267 compose->vbox2 = vbox2;
3269 compose->table_vbox = table_vbox;
3270 compose->table = table;
3271 compose->to_hbox = to_hbox;
3272 compose->to_entry = to_entry;
3273 compose->newsgroups_hbox = newsgroups_hbox;
3274 compose->newsgroups_entry = newsgroups_entry;
3275 compose->subject_entry = subject_entry;
3276 compose->cc_hbox = cc_hbox;
3277 compose->cc_entry = cc_entry;
3278 compose->bcc_hbox = bcc_hbox;
3279 compose->bcc_entry = bcc_entry;
3280 compose->reply_hbox = reply_hbox;
3281 compose->reply_entry = reply_entry;
3282 compose->followup_hbox = followup_hbox;
3283 compose->followup_entry = followup_entry;
3285 compose->paned = paned;
3287 compose->attach_scrwin = attach_scrwin;
3288 compose->attach_clist = attach_clist;
3290 compose->edit_vbox = edit_vbox;
3291 compose->ruler_hbox = ruler_hbox;
3292 compose->ruler = ruler;
3293 compose->scrolledwin = scrolledwin;
3294 compose->text = text;
3296 compose->focused_editable = NULL;
3298 compose->popupmenu = popupmenu;
3299 compose->popupfactory = popupfactory;
3301 compose->mode = COMPOSE_NEW;
3303 compose->replyto = NULL;
3305 compose->bcc = NULL;
3306 compose->followup_to = NULL;
3307 compose->inreplyto = NULL;
3308 compose->references = NULL;
3309 compose->msgid = NULL;
3310 compose->boundary = NULL;
3313 compose->use_signing = FALSE;
3314 compose->use_encryption = FALSE;
3315 #endif /* USE_GPGME */
3317 compose->modified = FALSE;
3319 compose->return_receipt = FALSE;
3321 compose->to_list = NULL;
3322 compose->newsgroup_list = NULL;
3324 compose->exteditor_file = NULL;
3325 compose->exteditor_pid = -1;
3326 compose->exteditor_readdes = -1;
3327 compose->exteditor_tag = -1;
3329 compose_set_title(compose);
3331 compose->use_bcc = FALSE;
3332 compose->use_replyto = FALSE;
3333 compose->use_followupto = FALSE;
3336 if (account->protocol != A_NNTP) {
3337 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
3338 gtk_check_menu_item_set_active
3339 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3340 gtk_widget_set_sensitive(menuitem, FALSE);
3341 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3342 gtk_check_menu_item_set_active
3343 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3344 gtk_widget_set_sensitive(menuitem, FALSE);
3347 if (account->set_autocc && account->auto_cc) {
3348 compose->use_cc = TRUE;
3349 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
3350 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3351 gtk_check_menu_item_set_active
3352 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3355 if (account->set_autobcc) {
3356 compose->use_bcc = TRUE;
3357 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
3358 gtk_check_menu_item_set_active
3359 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3360 if (account->auto_bcc)
3361 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
3364 if (account->set_autoreplyto) {
3365 compose->use_replyto = TRUE;
3366 menuitem = gtk_item_factory_get_item(ifactory,
3367 "/Message/Reply to");
3368 gtk_check_menu_item_set_active
3369 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3370 if (account->auto_replyto)
3371 gtk_entry_set_text(GTK_ENTRY(reply_entry),
3372 account->auto_replyto);
3375 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
3376 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3377 prefs_common.show_ruler);
3380 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
3381 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3382 prefs_common.default_sign);
3383 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
3384 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3385 prefs_common.default_encrypt);
3386 #endif /* USE_GPGME */
3388 addressbook_set_target_compose(compose);
3390 compose_list = g_list_append(compose_list, compose);
3393 compose->use_to = FALSE;
3394 compose->use_cc = FALSE;
3396 compose->use_attach = FALSE;
3398 if (!compose->use_bcc) {
3399 gtk_widget_hide(bcc_hbox);
3400 gtk_widget_hide(bcc_entry);
3401 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
3403 if (!compose->use_replyto) {
3404 gtk_widget_hide(reply_hbox);
3405 gtk_widget_hide(reply_entry);
3406 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
3408 if (!compose->use_followupto) {
3409 gtk_widget_hide(followup_hbox);
3410 gtk_widget_hide(followup_entry);
3411 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
3414 if (!prefs_common.show_ruler)
3415 gtk_widget_hide(ruler_hbox);
3417 select_account(compose, account);
3422 #include "pixmaps/stock_mail_send.xpm"
3423 #include "pixmaps/stock_mail_send_queue.xpm"
3424 #include "pixmaps/stock_mail.xpm"
3425 #include "pixmaps/stock_paste.xpm"
3426 #include "pixmaps/stock_mail_attach.xpm"
3427 #include "pixmaps/stock_mail_compose.xpm"
3428 #include "pixmaps/linewrap.xpm"
3429 #include "pixmaps/tb_address_book.xpm"
3431 #define CREATE_TOOLBAR_ICON(xpm_d) \
3433 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
3434 &container->style->white, \
3436 icon_wid = gtk_pixmap_new(icon, mask); \
3439 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
3444 GtkWidget *icon_wid;
3445 GtkWidget *send_btn;
3446 GtkWidget *sendl_btn;
3447 GtkWidget *draft_btn;
3448 GtkWidget *insert_btn;
3449 GtkWidget *attach_btn;
3451 GtkWidget *exteditor_btn;
3452 GtkWidget *linewrap_btn;
3453 GtkWidget *addrbook_btn;
3455 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
3457 gtk_container_add(GTK_CONTAINER(container), toolbar);
3458 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
3459 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
3460 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
3461 GTK_TOOLBAR_SPACE_LINE);
3463 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
3464 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3468 icon_wid, toolbar_send_cb, compose);
3470 CREATE_TOOLBAR_ICON(stock_mail_send_queue_xpm);
3471 /* CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm); */
3472 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3474 _("Put into queue folder and send later"),
3476 icon_wid, toolbar_send_later_cb,
3479 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3480 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3482 _("Save to draft folder"),
3484 icon_wid, toolbar_draft_cb,
3487 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3489 CREATE_TOOLBAR_ICON(stock_paste_xpm);
3490 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3494 icon_wid, toolbar_insert_cb,
3497 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
3498 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3502 icon_wid, toolbar_attach_cb,
3505 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3507 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3508 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3510 _("Insert signature"),
3512 icon_wid, toolbar_sig_cb, compose);
3514 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3516 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
3517 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3519 _("Edit with external editor"),
3522 toolbar_ext_editor_cb,
3525 CREATE_TOOLBAR_ICON(linewrap_xpm);
3526 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3528 _("Wrap long lines"),
3531 toolbar_linewrap_cb,
3534 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3536 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
3537 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3541 icon_wid, toolbar_address_cb,
3544 compose->toolbar = toolbar;
3545 compose->send_btn = send_btn;
3546 compose->sendl_btn = sendl_btn;
3547 compose->draft_btn = draft_btn;
3548 compose->insert_btn = insert_btn;
3549 compose->attach_btn = attach_btn;
3550 compose->sig_btn = sig_btn;
3551 compose->exteditor_btn = exteditor_btn;
3552 compose->linewrap_btn = linewrap_btn;
3553 compose->addrbook_btn = addrbook_btn;
3555 gtk_widget_show_all(toolbar);
3558 #undef CREATE_TOOLBAR_ICON
3560 static GtkWidget *compose_account_option_menu_create(Compose *compose)
3566 gint num = 0, def_menu = 0;
3568 accounts = account_get_list();
3569 g_return_val_if_fail(accounts != NULL, NULL);
3571 hbox = gtk_hbox_new(FALSE, 0);
3572 optmenu = gtk_option_menu_new();
3573 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3574 menu = gtk_menu_new();
3576 for (; accounts != NULL; accounts = accounts->next, num++) {
3577 PrefsAccount *ac = (PrefsAccount *)accounts->data;
3578 GtkWidget *menuitem;
3581 if (ac == compose->account) def_menu = num;
3583 name = g_strdup_printf("%s: %s <%s>",
3584 ac->account_name, ac->name, ac->address);
3585 MENUITEM_ADD(menu, menuitem, name, ac);
3587 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
3588 GTK_SIGNAL_FUNC(account_activated),
3592 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
3593 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
3598 static void compose_destroy(Compose *compose)
3601 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3604 /* NOTE: address_completion_end() does nothing with the window
3605 * however this may change. */
3606 address_completion_end(compose->window);
3608 slist_free_strings(compose->to_list);
3609 g_slist_free(compose->to_list);
3610 slist_free_strings(compose->newsgroup_list);
3611 g_slist_free(compose->newsgroup_list);
3613 procmsg_msginfo_free(compose->targetinfo);
3615 g_free(compose->replyto);
3616 g_free(compose->cc);
3617 g_free(compose->bcc);
3618 g_free(compose->newsgroups);
3619 g_free(compose->followup_to);
3621 g_free(compose->inreplyto);
3622 g_free(compose->references);
3623 g_free(compose->msgid);
3624 g_free(compose->boundary);
3626 g_free(compose->exteditor_file);
3628 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3630 compose_attach_info_free(ainfo);
3632 if (addressbook_get_target_compose() == compose)
3633 addressbook_set_target_compose(NULL);
3635 prefs_common.compose_width = compose->scrolledwin->allocation.width;
3636 prefs_common.compose_height = compose->window->allocation.height;
3638 gtk_widget_destroy(compose->paned);
3642 compose_list = g_list_remove(compose_list, compose);
3645 static void compose_attach_info_free(AttachInfo *ainfo)
3647 g_free(ainfo->file);
3648 g_free(ainfo->content_type);
3649 g_free(ainfo->name);
3653 static void compose_attach_remove_selected(Compose *compose)
3655 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3659 while (clist->selection != NULL) {
3660 row = GPOINTER_TO_INT(clist->selection->data);
3661 ainfo = gtk_clist_get_row_data(clist, row);
3662 compose_attach_info_free(ainfo);
3663 gtk_clist_remove(clist, row);
3667 static struct _AttachProperty
3670 GtkWidget *mimetype_entry;
3671 GtkWidget *encoding_optmenu;
3672 GtkWidget *path_entry;
3673 GtkWidget *filename_entry;
3675 GtkWidget *cancel_btn;
3678 static void compose_attach_property(Compose *compose)
3680 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3683 GtkOptionMenu *optmenu;
3684 static gboolean cancelled;
3686 if (!clist->selection) return;
3687 row = GPOINTER_TO_INT(clist->selection->data);
3689 ainfo = gtk_clist_get_row_data(clist, row);
3692 if (!attach_prop.window)
3693 compose_attach_property_create(&cancelled);
3694 gtk_widget_grab_focus(attach_prop.ok_btn);
3695 gtk_widget_show(attach_prop.window);
3696 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
3698 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
3699 if (ainfo->encoding == ENC_UNKNOWN)
3700 gtk_option_menu_set_history(optmenu, ENC_BASE64);
3702 gtk_option_menu_set_history(optmenu, ainfo->encoding);
3704 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
3705 ainfo->content_type ? ainfo->content_type : "");
3706 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
3707 ainfo->file ? ainfo->file : "");
3708 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
3709 ainfo->name ? ainfo->name : "");
3713 gchar *cnttype = NULL;
3717 GtkWidget *menuitem;
3722 if (cancelled == TRUE) {
3723 gtk_widget_hide(attach_prop.window);
3727 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
3728 if (*text != '\0') {
3731 text = g_strstrip(g_strdup(text));
3732 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
3733 cnttype = g_strdup(text);
3736 alertpanel_error(_("Invalid MIME type."));
3742 menu = gtk_option_menu_get_menu(optmenu);
3743 menuitem = gtk_menu_get_active(GTK_MENU(menu));
3744 ainfo->encoding = GPOINTER_TO_INT
3745 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
3747 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
3748 if (*text != '\0') {
3749 if (is_file_exist(text) &&
3750 (size = get_file_size(text)) > 0)
3751 file = g_strdup(text);
3754 (_("File doesn't exist or is empty."));
3760 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
3761 if (*text != '\0') {
3762 g_free(ainfo->name);
3763 ainfo->name = g_strdup(text);
3767 g_free(ainfo->content_type);
3768 ainfo->content_type = cnttype;
3771 g_free(ainfo->file);
3777 gtk_clist_set_text(clist, row, COL_MIMETYPE,
3778 ainfo->content_type);
3779 gtk_clist_set_text(clist, row, COL_SIZE,
3780 to_human_readable(ainfo->size));
3781 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
3783 gtk_widget_hide(attach_prop.window);
3788 #define SET_LABEL_AND_ENTRY(str, entry, top) \
3790 label = gtk_label_new(str); \
3791 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
3792 GTK_FILL, 0, 0, 0); \
3793 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
3795 entry = gtk_entry_new(); \
3796 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
3797 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
3800 static void compose_attach_property_create(gboolean *cancelled)
3806 GtkWidget *mimetype_entry;
3809 GtkWidget *optmenu_menu;
3810 GtkWidget *menuitem;
3811 GtkWidget *path_entry;
3812 GtkWidget *filename_entry;
3815 GtkWidget *cancel_btn;
3816 GList *mime_type_list, *strlist;
3818 debug_print("Creating attach_property window...\n");
3820 window = gtk_window_new(GTK_WINDOW_DIALOG);
3821 gtk_widget_set_usize(window, 480, -1);
3822 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
3823 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
3824 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
3825 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
3826 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3827 GTK_SIGNAL_FUNC(attach_property_delete_event),
3829 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
3830 GTK_SIGNAL_FUNC(attach_property_key_pressed),
3833 vbox = gtk_vbox_new(FALSE, 8);
3834 gtk_container_add(GTK_CONTAINER(window), vbox);
3836 table = gtk_table_new(4, 2, FALSE);
3837 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
3838 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
3839 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
3841 label = gtk_label_new(_("MIME type"));
3842 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
3844 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3845 mimetype_entry = gtk_combo_new();
3846 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
3847 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3849 /* stuff with list */
3850 mime_type_list = procmime_get_mime_type_list();
3852 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
3853 MimeType *type = (MimeType *) mime_type_list->data;
3854 strlist = g_list_append(strlist,
3855 g_strdup_printf("%s/%s",
3856 type->type, type->sub_type));
3859 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
3861 for (mime_type_list = strlist; mime_type_list != NULL;
3862 mime_type_list = mime_type_list->next)
3863 g_free(mime_type_list->data);
3864 g_list_free(strlist);
3866 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
3868 label = gtk_label_new(_("Encoding"));
3869 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
3871 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3873 hbox = gtk_hbox_new(FALSE, 0);
3874 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
3875 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3877 optmenu = gtk_option_menu_new();
3878 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3880 optmenu_menu = gtk_menu_new();
3881 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
3882 gtk_widget_set_sensitive(menuitem, FALSE);
3883 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
3884 gtk_widget_set_sensitive(menuitem, FALSE);
3885 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
3886 gtk_widget_set_sensitive(menuitem, FALSE);
3887 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
3889 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
3891 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
3892 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
3894 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
3895 &cancel_btn, _("Cancel"), NULL, NULL);
3896 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
3897 gtk_widget_grab_default(ok_btn);
3899 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
3900 GTK_SIGNAL_FUNC(attach_property_ok),
3902 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
3903 GTK_SIGNAL_FUNC(attach_property_cancel),
3906 gtk_widget_show_all(vbox);
3908 attach_prop.window = window;
3909 attach_prop.mimetype_entry = mimetype_entry;
3910 attach_prop.encoding_optmenu = optmenu;
3911 attach_prop.path_entry = path_entry;
3912 attach_prop.filename_entry = filename_entry;
3913 attach_prop.ok_btn = ok_btn;
3914 attach_prop.cancel_btn = cancel_btn;
3917 #undef SET_LABEL_AND_ENTRY
3919 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
3925 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
3931 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
3932 gboolean *cancelled)
3940 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
3941 gboolean *cancelled)
3943 if (event && event->keyval == GDK_Escape) {
3949 static void compose_exec_ext_editor(Compose *compose)
3955 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
3956 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3958 if (pipe(pipe_fds) < 0) {
3963 if ((pid = fork()) < 0) {
3969 /* close the write side of the pipe */
3972 compose->exteditor_file = g_strdup(tmp);
3973 compose->exteditor_pid = pid;
3974 compose->exteditor_readdes = pipe_fds[0];
3976 compose_set_ext_editor_sensitive(compose, FALSE);
3978 compose->exteditor_tag =
3979 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
3980 compose_input_cb, compose);
3981 } else { /* process-monitoring process */
3987 /* close the read side of the pipe */
3990 if (compose_write_body_to_file(compose, tmp) < 0) {
3991 fd_write(pipe_fds[1], "2\n", 2);
3995 pid_ed = compose_exec_ext_editor_real(tmp);
3997 fd_write(pipe_fds[1], "1\n", 2);
4001 /* wait until editor is terminated */
4002 waitpid(pid_ed, NULL, 0);
4004 fd_write(pipe_fds[1], "0\n", 2);
4011 static gint compose_exec_ext_editor_real(const gchar *file)
4013 static gchar *def_cmd = "emacs %s";
4019 g_return_val_if_fail(file != NULL, -1);
4021 if ((pid = fork()) < 0) {
4026 if (pid != 0) return pid;
4028 /* grandchild process */
4030 if (setpgid(0, getppid()))
4033 if (prefs_common.ext_editor_cmd &&
4034 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
4035 *(p + 1) == 's' && !strchr(p + 2, '%')) {
4036 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
4038 if (prefs_common.ext_editor_cmd)
4039 g_warning(_("External editor command line is invalid: `%s'\n"),
4040 prefs_common.ext_editor_cmd);
4041 g_snprintf(buf, sizeof(buf), def_cmd, file);
4044 cmdline = g_strsplit(buf, " ", 1024);
4045 execvp(cmdline[0], cmdline);
4048 g_strfreev(cmdline);
4053 static gboolean compose_ext_editor_kill(Compose *compose)
4055 pid_t pgid = compose->exteditor_pid * -1;
4058 ret = kill(pgid, 0);
4060 if (ret == 0 || (ret == -1 && EPERM == errno)) {
4064 msg = g_strdup_printf
4065 (_("The external editor is still working.\n"
4066 "Force terminating the process?\n"
4067 "process group id: %d"), -pgid);
4068 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
4071 if (val == G_ALERTDEFAULT) {
4072 gdk_input_remove(compose->exteditor_tag);
4073 close(compose->exteditor_readdes);
4075 if (kill(pgid, SIGTERM) < 0) perror("kill");
4076 waitpid(compose->exteditor_pid, NULL, 0);
4078 g_warning(_("Terminated process group id: %d"), -pgid);
4079 g_warning(_("Temporary file: %s"),
4080 compose->exteditor_file);
4082 compose_set_ext_editor_sensitive(compose, TRUE);
4084 g_free(compose->exteditor_file);
4085 compose->exteditor_file = NULL;
4086 compose->exteditor_pid = -1;
4087 compose->exteditor_readdes = -1;
4088 compose->exteditor_tag = -1;
4096 static void compose_input_cb(gpointer data, gint source,
4097 GdkInputCondition condition)
4100 Compose *compose = (Compose *)data;
4103 debug_print(_("Compose: input from monitoring process\n"));
4105 gdk_input_remove(compose->exteditor_tag);
4108 if (read(source, &buf[i], 1) < 1) {
4112 if (buf[i] == '\n') {
4117 if (i == sizeof(buf) - 1)
4121 waitpid(compose->exteditor_pid, NULL, 0);
4123 if (buf[0] == '0') { /* success */
4124 GtkSText *text = GTK_STEXT(compose->text);
4126 gtk_stext_freeze(text);
4127 gtk_stext_set_point(text, 0);
4128 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
4129 compose_insert_file(compose, compose->exteditor_file);
4130 compose_changed_cb(NULL, compose);
4131 gtk_stext_thaw(text);
4133 if (unlink(compose->exteditor_file) < 0)
4134 FILE_OP_ERROR(compose->exteditor_file, "unlink");
4135 } else if (buf[0] == '1') { /* failed */
4136 g_warning(_("Couldn't exec external editor\n"));
4137 if (unlink(compose->exteditor_file) < 0)
4138 FILE_OP_ERROR(compose->exteditor_file, "unlink");
4139 } else if (buf[0] == '2') {
4140 g_warning(_("Couldn't write to file\n"));
4141 } else if (buf[0] == '3') {
4142 g_warning(_("Pipe read failed\n"));
4147 compose_set_ext_editor_sensitive(compose, TRUE);
4149 g_free(compose->exteditor_file);
4150 compose->exteditor_file = NULL;
4151 compose->exteditor_pid = -1;
4152 compose->exteditor_readdes = -1;
4153 compose->exteditor_tag = -1;
4156 static void compose_set_ext_editor_sensitive(Compose *compose,
4159 GtkItemFactory *ifactory;
4161 ifactory = gtk_item_factory_from_widget(compose->menubar);
4163 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
4164 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
4165 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
4167 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
4168 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
4169 menu_set_sensitive(ifactory, "/Edit/Wrap long lines", sensitive);
4170 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
4173 gtk_widget_set_sensitive(compose->text, sensitive);
4174 gtk_widget_set_sensitive(compose->send_btn, sensitive);
4175 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
4176 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
4177 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
4178 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
4179 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
4180 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
4183 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
4187 cursor_pos = (text->cursor_pos_x - extra) / char_width;
4188 cursor_pos = MAX(cursor_pos, 0);
4193 /* callback functions */
4195 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
4196 * includes "non-client" (windows-izm) in calculation, so this calculation
4197 * may not be accurate.
4199 static gboolean compose_edit_size_alloc(GtkEditable *widget,
4200 GtkAllocation *allocation,
4201 GtkSHRuler *shruler)
4203 if (prefs_common.show_ruler) {
4205 gint line_width_in_chars;
4207 char_width = gtkut_get_font_width
4208 (GTK_WIDGET(widget)->style->font);
4209 line_width_in_chars =
4210 (allocation->width - allocation->x) / char_width;
4212 /* got the maximum */
4213 gtk_ruler_set_range(GTK_RULER(shruler),
4214 0.0, line_width_in_chars,
4215 calc_cursor_xpos(GTK_STEXT(widget),
4218 /*line_width_in_chars*/ char_width);
4224 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
4226 compose_send_cb(data, 0, NULL);
4229 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
4231 compose_send_later_cb(data, 0, NULL);
4234 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
4236 compose_draft_cb(data, 0, NULL);
4239 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
4241 compose_insert_file_cb(data, 0, NULL);
4244 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
4246 compose_attach_cb(data, 0, NULL);
4249 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
4251 Compose *compose = (Compose *)data;
4253 compose_insert_sig(compose);
4256 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
4258 Compose *compose = (Compose *)data;
4260 compose_exec_ext_editor(compose);
4263 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
4265 Compose *compose = (Compose *)data;
4267 compose_wrap_line(compose);
4270 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
4272 compose_address_cb(data, 0, NULL);
4275 static void select_account(Compose * compose, PrefsAccount * ac)
4277 compose->account = ac;
4278 compose_set_title(compose);
4280 if (ac->protocol == A_NNTP) {
4281 GtkItemFactory *ifactory;
4282 GtkWidget *menuitem;
4284 ifactory = gtk_item_factory_from_widget(compose->menubar);
4285 menu_set_sensitive(ifactory,
4286 "/Message/Followup to", TRUE);
4288 gtk_widget_show(compose->newsgroups_hbox);
4289 gtk_widget_show(compose->newsgroups_entry);
4290 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4293 compose->use_to = FALSE;
4294 compose->use_cc = FALSE;
4296 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4297 gtk_check_menu_item_set_active
4298 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
4299 menu_set_sensitive(ifactory,
4300 "/Message/To", TRUE);
4301 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4302 gtk_check_menu_item_set_active
4303 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
4305 gtk_widget_hide(compose->to_hbox);
4306 gtk_widget_hide(compose->to_entry);
4307 gtk_widget_hide(compose->cc_hbox);
4308 gtk_widget_hide(compose->cc_entry);
4310 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4312 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4316 GtkItemFactory *ifactory;
4317 GtkWidget *menuitem;
4319 ifactory = gtk_item_factory_from_widget(compose->menubar);
4320 menu_set_sensitive(ifactory,
4321 "/Message/Followup to", FALSE);
4323 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
4324 gtk_widget_hide(compose->newsgroups_hbox);
4325 gtk_widget_hide(compose->newsgroups_entry);
4326 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4329 compose->use_to = TRUE;
4330 compose->use_cc = TRUE;
4332 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4333 gtk_check_menu_item_set_active
4334 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4335 menu_set_sensitive(ifactory,
4336 "/Message/To", FALSE);
4337 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4338 gtk_check_menu_item_set_active
4339 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4341 gtk_widget_show(compose->to_hbox);
4342 gtk_widget_show(compose->to_entry);
4343 gtk_widget_show(compose->cc_hbox);
4344 gtk_widget_show(compose->cc_entry);
4346 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4348 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4351 gtk_widget_queue_resize(compose->table_vbox);
4354 static void account_activated(GtkMenuItem *menuitem, gpointer data)
4356 Compose *compose = (Compose *)data;
4360 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
4361 g_return_if_fail(ac != NULL);
4363 if (ac != compose->account)
4364 select_account(compose, ac);
4367 static void attach_selected(GtkCList *clist, gint row, gint column,
4368 GdkEvent *event, gpointer data)
4370 Compose *compose = (Compose *)data;
4372 if (event && event->type == GDK_2BUTTON_PRESS)
4373 compose_attach_property(compose);
4376 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
4379 Compose *compose = (Compose *)data;
4380 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4385 if (event->button == 3) {
4386 if ((clist->selection && !clist->selection->next) ||
4387 !clist->selection) {
4388 gtk_clist_unselect_all(clist);
4389 if (gtk_clist_get_selection_info(clist,
4392 gtk_clist_select_row(clist, row, column);
4393 gtkut_clist_set_focus_row(clist, row);
4396 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
4397 NULL, NULL, event->button, event->time);
4401 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
4404 Compose *compose = (Compose *)data;
4408 switch (event->keyval) {
4410 compose_attach_remove_selected(compose);
4415 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
4417 Compose *compose = (Compose *)data;
4420 val = compose_send(compose);
4422 if (val == 0) gtk_widget_destroy(compose->window);
4425 static void compose_send_later_cb(gpointer data, guint action,
4428 Compose *compose = (Compose *)data;
4430 gchar *to, *newsgroups;
4432 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
4433 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
4434 if (*to == '\0' && *newsgroups == '\0') {
4435 alertpanel_error(_("Recipient is not specified."));
4439 g_snprintf(tmp, 22, "%s%ctmpmsg%d",
4440 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
4442 if (prefs_common.linewrap_at_send)
4443 compose_wrap_line(compose);
4445 if (compose_write_to_file(compose, tmp, FALSE) < 0 ||
4446 compose_queue(compose, tmp) < 0) {
4447 alertpanel_error(_("Can't queue the message."));
4451 if (prefs_common.savemsg) {
4452 if (compose_save_to_outbox(compose, tmp) < 0)
4454 (_("Can't save the message to outbox."));
4457 if (unlink(tmp) < 0)
4458 FILE_OP_ERROR(tmp, "unlink");
4460 gtk_widget_destroy(compose->window);
4463 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
4465 Compose *compose = (Compose *)data;
4469 draft = folder_get_default_draft();
4471 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
4472 G_DIR_SEPARATOR, (gint)compose);
4474 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
4479 folder_item_scan(draft);
4480 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
4487 if (compose->mode == COMPOSE_REEDIT) {
4488 compose_remove_reedit_target(compose);
4489 if (compose->targetinfo &&
4490 compose->targetinfo->folder != draft)
4491 folderview_update_item(compose->targetinfo->folder,
4495 folder_item_scan(draft);
4496 folderview_update_item(draft, TRUE);
4498 gtk_widget_destroy(compose->window);
4501 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
4503 Compose *compose = (Compose *)data;
4506 file_list = filesel_select_multiple_files(_("Select file"), NULL);
4511 for ( tmp = file_list; tmp; tmp = tmp->next) {
4512 gchar *file = (gchar *) tmp->data;
4513 compose_attach_append(compose, file, MIME_UNKNOWN);
4516 g_list_free(file_list);
4520 static void compose_insert_file_cb(gpointer data, guint action,
4523 Compose *compose = (Compose *)data;
4526 file_list = filesel_select_multiple_files(_("Select file"), NULL);
4531 for ( tmp = file_list; tmp; tmp = tmp->next) {
4532 gchar *file = (gchar *) tmp->data;
4533 compose_insert_file(compose, file);
4536 g_list_free(file_list);
4540 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
4543 compose_close_cb(data, 0, NULL);
4547 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
4549 Compose *compose = (Compose *)data;
4552 if (compose->exteditor_tag != -1) {
4553 if (!compose_ext_editor_kill(compose))
4557 if (compose->modified) {
4558 val = alertpanel(_("Discard message"),
4559 _("This message has been modified. discard it?"),
4560 _("Discard"), _("to Draft"), _("Cancel"));
4563 case G_ALERTDEFAULT:
4565 case G_ALERTALTERNATE:
4566 compose_draft_cb(data, 0, NULL);
4573 gtk_widget_destroy(compose->window);
4576 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
4578 Compose *compose = (Compose *)data;
4580 addressbook_open(compose);
4583 static void compose_ext_editor_cb(gpointer data, guint action,
4586 Compose *compose = (Compose *)data;
4588 compose_exec_ext_editor(compose);
4591 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
4593 compose_destroy(compose);
4596 static void compose_cut_cb(Compose *compose)
4598 if (compose->focused_editable &&
4599 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4600 gtk_editable_cut_clipboard
4601 (GTK_EDITABLE(compose->focused_editable));
4604 static void compose_copy_cb(Compose *compose)
4606 if (compose->focused_editable &&
4607 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4608 gtk_editable_copy_clipboard
4609 (GTK_EDITABLE(compose->focused_editable));
4612 static void compose_paste_cb(Compose *compose)
4614 if (compose->focused_editable &&
4615 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4616 gtk_editable_paste_clipboard
4617 (GTK_EDITABLE(compose->focused_editable));
4620 static void compose_allsel_cb(Compose *compose)
4622 if (compose->focused_editable &&
4623 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4624 gtk_editable_select_region
4625 (GTK_EDITABLE(compose->focused_editable), 0, -1);
4628 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
4630 if (GTK_IS_EDITABLE(widget))
4631 compose->focused_editable = widget;
4634 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
4636 if (compose->modified == FALSE) {
4637 compose->modified = TRUE;
4638 compose_set_title(compose);
4642 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
4645 gtk_stext_set_point(GTK_STEXT(widget),
4646 gtk_editable_get_position(GTK_EDITABLE(widget)));
4650 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
4653 gtk_stext_set_point(GTK_STEXT(widget),
4654 gtk_editable_get_position(GTK_EDITABLE(widget)));
4658 static void compose_toggle_to_cb(gpointer data, guint action,
4661 Compose *compose = (Compose *)data;
4663 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4664 gtk_widget_show(compose->to_hbox);
4665 gtk_widget_show(compose->to_entry);
4666 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
4667 compose->use_to = TRUE;
4669 gtk_widget_hide(compose->to_hbox);
4670 gtk_widget_hide(compose->to_entry);
4671 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
4672 gtk_widget_queue_resize(compose->table_vbox);
4673 compose->use_to = FALSE;
4676 if (addressbook_get_target_compose() == compose)
4677 addressbook_set_target_compose(compose);
4680 static void compose_toggle_cc_cb(gpointer data, guint action,
4683 Compose *compose = (Compose *)data;
4685 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4686 gtk_widget_show(compose->cc_hbox);
4687 gtk_widget_show(compose->cc_entry);
4688 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
4689 compose->use_cc = TRUE;
4691 gtk_widget_hide(compose->cc_hbox);
4692 gtk_widget_hide(compose->cc_entry);
4693 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
4694 gtk_widget_queue_resize(compose->table_vbox);
4695 compose->use_cc = FALSE;
4698 if (addressbook_get_target_compose() == compose)
4699 addressbook_set_target_compose(compose);
4702 static void compose_toggle_bcc_cb(gpointer data, guint action,
4705 Compose *compose = (Compose *)data;
4707 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4708 gtk_widget_show(compose->bcc_hbox);
4709 gtk_widget_show(compose->bcc_entry);
4710 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
4711 compose->use_bcc = TRUE;
4713 gtk_widget_hide(compose->bcc_hbox);
4714 gtk_widget_hide(compose->bcc_entry);
4715 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
4716 gtk_widget_queue_resize(compose->table_vbox);
4717 compose->use_bcc = FALSE;
4720 if (addressbook_get_target_compose() == compose)
4721 addressbook_set_target_compose(compose);
4724 static void compose_toggle_replyto_cb(gpointer data, guint action,
4727 Compose *compose = (Compose *)data;
4729 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4730 gtk_widget_show(compose->reply_hbox);
4731 gtk_widget_show(compose->reply_entry);
4732 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
4733 compose->use_replyto = TRUE;
4735 gtk_widget_hide(compose->reply_hbox);
4736 gtk_widget_hide(compose->reply_entry);
4737 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
4738 gtk_widget_queue_resize(compose->table_vbox);
4739 compose->use_replyto = FALSE;
4743 static void compose_toggle_followupto_cb(gpointer data, guint action,
4746 Compose *compose = (Compose *)data;
4748 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4749 gtk_widget_show(compose->followup_hbox);
4750 gtk_widget_show(compose->followup_entry);
4751 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
4752 compose->use_followupto = TRUE;
4754 gtk_widget_hide(compose->followup_hbox);
4755 gtk_widget_hide(compose->followup_entry);
4756 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
4757 gtk_widget_queue_resize(compose->table_vbox);
4758 compose->use_followupto = FALSE;
4762 static void compose_toggle_attach_cb(gpointer data, guint action,
4765 Compose *compose = (Compose *)data;
4767 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4768 gtk_widget_ref(compose->edit_vbox);
4770 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4771 compose->edit_vbox);
4772 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
4773 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
4775 gtk_widget_show(compose->paned);
4777 gtk_widget_unref(compose->edit_vbox);
4778 gtk_widget_unref(compose->paned);
4780 compose->use_attach = TRUE;
4782 gtk_widget_ref(compose->paned);
4783 gtk_widget_ref(compose->edit_vbox);
4785 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4787 gtk_container_remove(GTK_CONTAINER(compose->paned),
4788 compose->edit_vbox);
4789 gtk_box_pack_start(GTK_BOX(compose->vbox2),
4790 compose->edit_vbox, TRUE, TRUE, 0);
4792 gtk_widget_unref(compose->edit_vbox);
4794 compose->use_attach = FALSE;
4799 static void compose_toggle_sign_cb(gpointer data, guint action,
4802 Compose *compose = (Compose *)data;
4804 if (GTK_CHECK_MENU_ITEM(widget)->active)
4805 compose->use_signing = TRUE;
4807 compose->use_signing = FALSE;
4810 static void compose_toggle_encrypt_cb(gpointer data, guint action,
4813 Compose *compose = (Compose *)data;
4815 if (GTK_CHECK_MENU_ITEM(widget)->active)
4816 compose->use_encryption = TRUE;
4818 compose->use_encryption = FALSE;
4820 #endif /* USE_GPGME */
4822 static void compose_toggle_ruler_cb(gpointer data, guint action,
4825 Compose *compose = (Compose *)data;
4827 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4828 gtk_widget_show(compose->ruler_hbox);
4829 prefs_common.show_ruler = TRUE;
4831 gtk_widget_hide(compose->ruler_hbox);
4832 gtk_widget_queue_resize(compose->edit_vbox);
4833 prefs_common.show_ruler = FALSE;
4837 static void compose_attach_drag_received_cb (GtkWidget *widget,
4838 GdkDragContext *drag_context,
4841 GtkSelectionData *data,
4846 Compose *compose = (Compose *)user_data;
4849 list = uri_list_extract_filenames((const gchar *)data->data);
4850 for (tmp = list; tmp != NULL; tmp = tmp->next)
4851 compose_attach_append(compose, (const gchar *)tmp->data,
4853 list_free_strings(list);
4857 static void compose_insert_drag_received_cb (GtkWidget *widget,
4858 GdkDragContext *drag_context,
4861 GtkSelectionData *data,
4866 Compose *compose = (Compose *)user_data;
4869 list = uri_list_extract_filenames((const gchar *)data->data);
4870 for (tmp = list; tmp != NULL; tmp = tmp->next)
4871 compose_insert_file(compose, (const gchar *)tmp->data);
4872 list_free_strings(list);
4876 static void to_activated(GtkWidget *widget, Compose *compose)
4878 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
4879 gtk_widget_grab_focus(compose->newsgroups_entry);
4881 gtk_widget_grab_focus(compose->subject_entry);
4884 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
4886 gtk_widget_grab_focus(compose->subject_entry);
4889 static void subject_activated(GtkWidget *widget, Compose *compose)
4891 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
4892 gtk_widget_grab_focus(compose->cc_entry);
4893 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4894 gtk_widget_grab_focus(compose->bcc_entry);
4895 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4896 gtk_widget_grab_focus(compose->reply_entry);
4897 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4898 gtk_widget_grab_focus(compose->followup_entry);
4900 gtk_widget_grab_focus(compose->text);
4903 static void cc_activated(GtkWidget *widget, Compose *compose)
4905 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4906 gtk_widget_grab_focus(compose->bcc_entry);
4907 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4908 gtk_widget_grab_focus(compose->reply_entry);
4909 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4910 gtk_widget_grab_focus(compose->followup_entry);
4912 gtk_widget_grab_focus(compose->text);
4915 static void bcc_activated(GtkWidget *widget, Compose *compose)
4917 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4918 gtk_widget_grab_focus(compose->reply_entry);
4919 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4920 gtk_widget_grab_focus(compose->followup_entry);
4922 gtk_widget_grab_focus(compose->text);
4925 static void replyto_activated(GtkWidget *widget, Compose *compose)
4927 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4928 gtk_widget_grab_focus(compose->followup_entry);
4930 gtk_widget_grab_focus(compose->text);
4933 static void followupto_activated(GtkWidget *widget, Compose *compose)
4935 gtk_widget_grab_focus(compose->text);
4938 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
4941 Compose *compose = (Compose *)data;
4943 if (GTK_CHECK_MENU_ITEM(widget)->active)
4944 compose->return_receipt = TRUE;
4946 compose->return_receipt = FALSE;
4949 static gchar *compose_quote_fmt (Compose *compose,
4954 gchar * quote_str = NULL;
4956 if (qmark != NULL) {
4959 quote_fmt_init(msginfo, NULL);
4960 quote_fmt_scan_string(qmark);
4963 p = quote_fmt_get_buffer();
4966 (_("Quote mark format error."));
4969 quote_str = alloca(strlen(p) + 1);
4970 strcpy(quote_str, p);
4974 quote_fmt_init(msginfo, quote_str);
4975 quote_fmt_scan_string(fmt);
4978 if (quote_fmt_get_buffer() == NULL)
4980 (_("Message reply/forward format error."));
4982 return quote_fmt_get_buffer();
4985 static void template_apply_cb(gchar *s, gpointer data)
4987 Compose *compose = (Compose*)data;
4988 GtkSText *text = GTK_STEXT(compose->text);
4993 gchar *old_tmpl = s;
4997 if(compose->replyinfo == NULL) {
4998 gtk_stext_freeze(text);
4999 gtk_stext_set_point(text, 0);
5000 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5001 gtk_stext_insert(text, NULL, NULL, NULL, s, -1);
5002 gtk_stext_thaw(text);
5007 parsed_text = g_new(gchar, strlen(s)*2 + 1);
5011 *parsed_text++ = '\\';
5012 *parsed_text++ = 'n';
5015 *parsed_text++ = *s++;
5018 *parsed_text = '\0';
5020 if (prefs_common.quotemark && *prefs_common.quotemark)
5021 qmark = prefs_common.quotemark;
5025 quote_str = compose_quote_fmt(compose, compose->replyinfo, tmpl, qmark);
5026 if (quote_str != NULL) {
5027 gtk_stext_freeze(text);
5028 gtk_stext_set_point(text, 0);
5029 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5030 gtk_stext_insert(text, NULL, NULL, NULL, quote_str, -1);
5031 gtk_stext_thaw(text);
5038 static void template_select_cb(gpointer data, guint action,
5041 template_select(&template_apply_cb, data);