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_queue (Compose *compose,
176 static void compose_write_attach (Compose *compose,
178 static gint compose_write_headers (Compose *compose,
180 const gchar *charset,
181 EncodingType encoding,
184 static void compose_convert_header (gchar *dest,
188 static void compose_generate_msgid (Compose *compose,
192 static void compose_attach_info_free (AttachInfo *ainfo);
193 static void compose_attach_remove_selected (Compose *compose);
195 static void compose_attach_property (Compose *compose);
196 static void compose_attach_property_create (gboolean *cancelled);
197 static void attach_property_ok (GtkWidget *widget,
198 gboolean *cancelled);
199 static void attach_property_cancel (GtkWidget *widget,
200 gboolean *cancelled);
201 static gint attach_property_delete_event (GtkWidget *widget,
203 gboolean *cancelled);
204 static void attach_property_key_pressed (GtkWidget *widget,
206 gboolean *cancelled);
208 static void compose_exec_ext_editor (Compose *compose);
209 static gint compose_exec_ext_editor_real (const gchar *file);
210 static gboolean compose_ext_editor_kill (Compose *compose);
211 static void compose_input_cb (gpointer data,
213 GdkInputCondition condition);
214 static void compose_set_ext_editor_sensitive (Compose *compose,
217 static gint calc_cursor_xpos (GtkSText *text,
221 /* callback functions */
223 static gboolean compose_edit_size_alloc (GtkEditable *widget,
224 GtkAllocation *allocation,
225 GtkSHRuler *shruler);
227 static void toolbar_send_cb (GtkWidget *widget,
229 static void toolbar_send_later_cb (GtkWidget *widget,
231 static void toolbar_draft_cb (GtkWidget *widget,
233 static void toolbar_insert_cb (GtkWidget *widget,
235 static void toolbar_attach_cb (GtkWidget *widget,
237 static void toolbar_sig_cb (GtkWidget *widget,
239 static void toolbar_ext_editor_cb (GtkWidget *widget,
241 static void toolbar_linewrap_cb (GtkWidget *widget,
243 static void toolbar_address_cb (GtkWidget *widget,
245 static void template_select_cb (gpointer daat,
250 static void select_account(Compose * compose, PrefsAccount * ac);
251 static void account_activated (GtkMenuItem *menuitem,
254 static void attach_selected (GtkCList *clist,
259 static void attach_button_pressed (GtkWidget *widget,
260 GdkEventButton *event,
262 static void attach_key_pressed (GtkWidget *widget,
266 static void compose_send_cb (gpointer data,
269 static void compose_send_later_cb (gpointer data,
273 static void compose_draft_cb (gpointer data,
277 static void compose_attach_cb (gpointer data,
280 static void compose_insert_file_cb (gpointer data,
284 static void compose_close_cb (gpointer data,
287 static void compose_address_cb (gpointer data,
291 static void compose_ext_editor_cb (gpointer data,
295 static gint compose_delete_cb (GtkWidget *widget,
298 static void compose_destroy_cb (GtkWidget *widget,
301 static void compose_cut_cb (Compose *compose);
302 static void compose_copy_cb (Compose *compose);
303 static void compose_paste_cb (Compose *compose);
304 static void compose_allsel_cb (Compose *compose);
306 static void compose_grab_focus_cb (GtkWidget *widget,
309 static void compose_changed_cb (GtkEditable *editable,
311 static void compose_button_press_cb (GtkWidget *widget,
312 GdkEventButton *event,
315 static void compose_key_press_cb (GtkWidget *widget,
320 static void compose_toggle_to_cb (gpointer data,
323 static void compose_toggle_cc_cb (gpointer data,
326 static void compose_toggle_bcc_cb (gpointer data,
329 static void compose_toggle_replyto_cb (gpointer data,
332 static void compose_toggle_followupto_cb(gpointer data,
335 static void compose_toggle_attach_cb (gpointer data,
338 static void compose_toggle_ruler_cb (gpointer data,
342 static void compose_toggle_sign_cb (gpointer data,
345 static void compose_toggle_encrypt_cb (gpointer data,
349 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
352 static void compose_attach_drag_received_cb (GtkWidget *widget,
353 GdkDragContext *drag_context,
356 GtkSelectionData *data,
360 static void compose_insert_drag_received_cb (GtkWidget *widget,
361 GdkDragContext *drag_context,
364 GtkSelectionData *data,
369 static void to_activated (GtkWidget *widget,
371 static void newsgroups_activated (GtkWidget *widget,
373 static void subject_activated (GtkWidget *widget,
375 static void cc_activated (GtkWidget *widget,
377 static void bcc_activated (GtkWidget *widget,
379 static void replyto_activated (GtkWidget *widget,
381 static void followupto_activated (GtkWidget *widget,
383 static void compose_attach_parts(Compose * compose,
386 static gchar *compose_quote_fmt (Compose *compose,
389 const gchar * qmark);
391 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
393 gboolean ignore_replyto,
394 gboolean followup_and_reply_to);
396 Compose * compose_generic_new (PrefsAccount *account,
400 static GtkItemFactoryEntry compose_popup_entries[] =
402 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
403 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
404 {N_("/---"), NULL, NULL, 0, "<Separator>"},
405 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
408 static GtkItemFactoryEntry compose_entries[] =
410 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
411 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
412 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
413 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
414 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
415 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
417 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
418 {N_("/_Edit/_Undo"), "<control>Z", NULL, 0, NULL},
419 {N_("/_Edit/_Redo"), "<control>Y", NULL, 0, NULL},
420 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
421 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
422 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
423 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
424 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
425 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
426 {N_("/_Edit/Wrap long _lines"), "<alt>L", compose_wrap_line, 0, NULL},
427 {N_("/_Edit/Edit with e_xternal editor"), "<alt>X",
428 compose_ext_editor_cb, 0, NULL},
430 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
431 {N_("/_Message/_Send"), "<shift><control>S",
432 compose_send_cb, 0, NULL},
433 {N_("/_Message/Send _later"), "<shift><alt>S",
434 compose_send_later_cb, 0, NULL},
435 {N_("/_Message/Save to _draft folder"),
436 "<alt>D", compose_draft_cb, 0, NULL},
437 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
438 {N_("/_Message/_To"), NULL, compose_toggle_to_cb, 0, "<ToggleItem>"},
439 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb, 0, "<ToggleItem>"},
440 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb, 0, "<ToggleItem>"},
441 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
442 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
443 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
444 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
445 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
447 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
448 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb, 0, "<ToggleItem>"},
449 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
450 #endif /* USE_GPGME */
451 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
452 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
453 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
454 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
455 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb, 0, NULL},
456 {N_("/_Tool/_Templates ..."), NULL, template_select_cb, 0, NULL},
457 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
458 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
461 static GtkTargetEntry compose_mime_types[] =
463 {"text/uri-list", 0, 0}
466 Compose * compose_new(PrefsAccount *account)
468 return compose_generic_new(account, NULL, NULL);
471 Compose * compose_new_with_recipient(PrefsAccount *account, const gchar *to)
473 return compose_generic_new(account, to, NULL);
476 Compose * compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
478 return compose_generic_new(account, NULL, item);
481 Compose * compose_generic_new(PrefsAccount *account, const gchar *to, FolderItem *item)
485 if (!account) account = cur_account;
486 g_return_val_if_fail(account != NULL, NULL);
488 compose = compose_create(account);
489 compose->mode = COMPOSE_NEW;
490 compose->replyinfo = NULL;
492 if (prefs_common.auto_sig)
493 compose_insert_sig(compose);
494 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
495 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
497 if (account->protocol != A_NNTP) {
499 compose_entry_append(compose, to, COMPOSE_TO);
500 gtk_widget_grab_focus(compose->subject_entry);
502 if(item && item->prefs->enable_default_to) {
503 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
505 gtk_widget_grab_focus(compose->to_entry);
508 if(item && item->prefs->request_return_receipt) {
509 GtkItemFactory *ifactory;
511 ifactory = gtk_item_factory_from_widget(compose->menubar);
512 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
516 compose_entry_append(compose, to, COMPOSE_NEWSGROUPS);
517 gtk_widget_grab_focus(compose->subject_entry);
519 gtk_widget_grab_focus(compose->newsgroups_entry);
525 #define CHANGE_FLAGS(msginfo) \
527 if (msginfo->folder->folder->change_flags != NULL) \
528 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
534 Compose * compose_new_followup_and_replyto(PrefsAccount *account,
535 const gchar *followupto, gchar * to)
539 if (!account) account = cur_account;
540 g_return_val_if_fail(account != NULL, NULL);
541 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
543 compose = compose_create(account);
544 compose->mode = COMPOSE_NEW;
546 if (prefs_common.auto_sig)
547 compose_insert_sig(compose);
548 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
549 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
551 compose_entry_append(compose, to, COMPOSE_TO);
552 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
553 gtk_widget_grab_focus(compose->subject_entry);
559 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
560 gboolean ignore_replyto)
562 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
565 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
567 gboolean ignore_replyto)
569 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
572 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
574 gboolean ignore_replyto,
575 gboolean followup_and_reply_to)
578 PrefsAccount *account;
579 PrefsAccount *reply_account;
582 g_return_if_fail(msginfo != NULL);
583 g_return_if_fail(msginfo->folder != NULL);
585 account = msginfo->folder->folder->account;
586 if (!account && msginfo->to && prefs_common.reply_account_autosel) {
588 Xstrdup_a(to, msginfo->to, return);
590 account = account_find_from_address(to);
592 if(!account&& prefs_common.reply_account_autosel) {
594 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
596 account = account_find_from_address(cc);
600 if (!account) account = cur_account;
601 g_return_if_fail(account != NULL);
603 if (ignore_replyto && account->protocol == A_NNTP &&
604 !followup_and_reply_to) {
606 account_find_from_address(account->address);
608 reply_account = compose_current_mail_account();
612 reply_account = account;
613 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
614 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
616 CHANGE_FLAGS(msginfo);
618 compose = compose_create(reply_account);
619 compose->mode = COMPOSE_REPLY;
620 compose->replyinfo = msginfo;
623 if (followup_and_reply_to) {
624 gtk_widget_show(compose->to_hbox);
625 gtk_widget_show(compose->to_entry);
626 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
627 compose->use_to = TRUE;
630 if(msginfo->folder && msginfo->folder->prefs->request_return_receipt) {
631 GtkItemFactory *ifactory;
633 ifactory = gtk_item_factory_from_widget(compose->menubar);
634 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
637 if (compose_parse_header(compose, msginfo) < 0) return;
638 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
639 followup_and_reply_to);
641 text = GTK_STEXT(compose->text);
642 gtk_stext_freeze(text);
648 if ((fp = procmime_get_text_part(msginfo)) == NULL)
649 g_warning(_("Can't get text part\n"));
653 if (prefs_common.quotemark && *prefs_common.quotemark)
654 qmark = prefs_common.quotemark;
658 quote_str = compose_quote_fmt(compose, msginfo,
659 prefs_common.quotefmt,
663 quote_str = compose_quote_parse_fmt
664 (compose, msginfo, prefs_common.quotefmt);
667 if (quote_str != NULL)
668 gtk_stext_insert(text, NULL, NULL, NULL,
670 /* g_free(quote_str); */
671 /* compose_quote_file(compose, msginfo, fp); */
676 if (prefs_common.auto_sig)
677 compose_insert_sig(compose);
678 gtk_editable_set_position(GTK_EDITABLE(text), 0);
679 gtk_stext_set_point(text, 0);
681 gtk_stext_thaw(text);
682 gtk_widget_grab_focus(compose->text);
686 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
691 g_return_val_if_fail(mimeinfo != NULL, NULL);
693 base = mimeinfo->filename ? mimeinfo->filename
694 : mimeinfo->name ? mimeinfo->name : NULL;
696 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
697 filename = g_strdup_printf("%s%smimetmp%i.html",
704 base = base ? base : "";
705 base = g_basename(base);
707 filename = g_strdup_printf("%s%smimetmp%i",
715 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
721 static gchar * mime_extract_file(gchar * source, MimeInfo *partinfo)
725 if (!partinfo) return;
727 filename = procmime_get_file_name(partinfo);
729 if (procmime_get_part(filename, source, partinfo) < 0)
731 (_("Can't get the part of multipart message."));
736 static void compose_attach_parts(Compose * compose,
746 gint boundary_len = 0;
748 glong fpos, prev_fpos;
753 g_return_if_fail(msginfo != NULL);
757 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
758 mimeinfo = procmime_scan_mime_header(fp);
759 if (!mimeinfo) break;
761 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
762 rfc2015_is_encrypted(mimeinfo)) {
763 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
765 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
766 !msginfo->plaintext_file &&
767 !msginfo->decryption_failed) {
768 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
769 if (msginfo->plaintext_file &&
770 !msginfo->decryption_failed) {
778 #else /* !USE_GPGME */
779 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
780 mimeinfo = procmime_scan_mime_header(fp);
781 #endif /* USE_GPGME */
784 if (!mimeinfo) return;
785 if (mimeinfo->mime_type == MIME_TEXT)
788 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
790 g_return_if_fail(mimeinfo != NULL);
791 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
793 if (mimeinfo->mime_type == MIME_MULTIPART) {
794 g_return_if_fail(mimeinfo->boundary != NULL);
795 g_return_if_fail(mimeinfo->sub == NULL);
797 g_return_if_fail(fp != NULL);
799 boundary = mimeinfo->boundary;
802 boundary_len = strlen(boundary);
804 /* look for first boundary */
805 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
806 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
813 if ((fpos = ftell(fp)) < 0) {
819 for (npart = 0;; npart++) {
821 gboolean eom = FALSE;
825 partinfo = procmime_scan_mime_header(fp);
826 if (!partinfo) break;
829 procmime_mimeinfo_insert(mimeinfo, partinfo);
831 procmime_mimeinfo_free(partinfo);
833 /* look for next boundary */
835 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
836 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
837 if (buf[2 + boundary_len] == '-' &&
838 buf[2 + boundary_len + 1] == '-')
844 eom = TRUE; /* broken MIME message */
847 partinfo->size = fpos - prev_fpos - strlen(buf);
852 source = procmsg_get_message_file_path(msginfo);
854 g_return_if_fail(mimeinfo != NULL);
856 if (!mimeinfo->main && mimeinfo->parent)
858 filename = mime_extract_file(source, mimeinfo);
860 compose_attach_append_with_type(compose, filename,
861 mimeinfo->content_type,
862 mimeinfo->mime_type);
867 if (mimeinfo->sub && mimeinfo->sub->children)
869 filename = mime_extract_file(source, mimeinfo->sub);
871 compose_attach_append_with_type(compose, filename,
872 mimeinfo->content_type,
873 mimeinfo->sub->mime_type);
878 if (mimeinfo->children) {
881 child = mimeinfo->children;
883 filename = mime_extract_file(source, child);
885 compose_attach_append_with_type(compose, filename,
897 procmime_mimeinfo_free_all(mimeinfo);
901 #define INSERT_FW_HEADER(var, hdr) \
902 if (msginfo->var && *msginfo->var) { \
903 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
904 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
905 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
908 Compose * compose_forward(PrefsAccount * account, MsgInfo *msginfo,
912 /* PrefsAccount *account; */
917 g_return_val_if_fail(msginfo != NULL, NULL);
918 g_return_val_if_fail(msginfo->folder != NULL, NULL);
920 account = msginfo->folder->folder->account;
921 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
923 Xstrdup_a(to, msginfo->to, return);
925 account = account_find_from_address(to);
928 if(!account&& prefs_common.forward_account_autosel) {
930 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
932 account = account_find_from_address(cc);
936 if (account == NULL) {
937 account = cur_account;
939 account = msginfo->folder->folder->account;
940 if (!account) account = cur_account;
943 g_return_val_if_fail(account != NULL, NULL);
945 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
946 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
947 CHANGE_FLAGS(msginfo);
949 compose = compose_create(account);
950 compose->mode = COMPOSE_FORWARD;
952 if (msginfo->subject && *msginfo->subject) {
953 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
954 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
958 text = GTK_STEXT(compose->text);
959 gtk_stext_freeze(text);
964 msgfile = procmsg_get_message_file_path(msginfo);
965 if (!is_file_exist(msgfile))
966 g_warning(_("%s: file not exist\n"), msgfile);
968 compose_attach_append(compose, msgfile,
969 MIME_MESSAGE_RFC822);
976 if ((fp = procmime_get_text_part(msginfo)) == NULL)
977 g_warning(_("Can't get text part\n"));
981 if (prefs_common.fw_quotemark &&
982 *prefs_common.fw_quotemark)
983 qmark = prefs_common.fw_quotemark;
987 quote_str = compose_quote_fmt(compose, msginfo,
988 prefs_common.fw_quotefmt,
991 if (quote_str != NULL)
992 gtk_stext_insert(text, NULL, NULL, NULL,
998 compose_attach_parts(compose, msginfo);
1001 if (prefs_common.auto_sig)
1002 compose_insert_sig(compose);
1003 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1004 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1006 gtk_stext_thaw(text);
1007 if (account->protocol != A_NNTP)
1008 gtk_widget_grab_focus(compose->to_entry);
1010 gtk_widget_grab_focus(compose->newsgroups_entry);
1015 #undef INSERT_FW_HEADER
1017 Compose * compose_forward_multiple(PrefsAccount * account,
1018 GSList *msginfo_list)
1025 g_return_val_if_fail(msginfo_list != NULL, NULL);
1027 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1028 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1032 if (account == NULL) {
1033 account = cur_account;
1035 account = msginfo->folder->folder->account;
1036 if (!account) account = cur_account;
1039 g_return_val_if_fail(account != NULL, NULL);
1041 compose = compose_create(account);
1042 compose->mode = COMPOSE_FORWARD;
1044 text = GTK_STEXT(compose->text);
1045 gtk_stext_freeze(text);
1047 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1048 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1049 if (!is_file_exist(msgfile))
1050 g_warning(_("%s: file not exist\n"), msgfile);
1052 compose_attach_append(compose, msgfile,
1053 MIME_MESSAGE_RFC822);
1057 if (prefs_common.auto_sig)
1058 compose_insert_sig(compose);
1059 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1060 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1062 gtk_stext_thaw(text);
1063 if (account->protocol != A_NNTP)
1064 gtk_widget_grab_focus(compose->to_entry);
1066 gtk_widget_grab_focus(compose->newsgroups_entry);
1071 void compose_reedit(MsgInfo *msginfo)
1074 PrefsAccount *account;
1077 gchar buf[BUFFSIZE];
1079 g_return_if_fail(msginfo != NULL);
1080 g_return_if_fail(msginfo->folder != NULL);
1082 if(!account&& prefs_common.reedit_account_autosel) {
1083 gchar from[BUFFSIZE];
1084 if(!get_header_from_msginfo(msginfo,from,sizeof(from),"FROM:")){ /* Found a FROM header */
1085 extract_address(from);
1086 account = account_find_from_address(from);
1089 if (!account) account = cur_account;
1090 g_return_if_fail(account != NULL);
1092 compose = compose_create(account);
1093 compose->mode = COMPOSE_REEDIT_DRAFT;
1094 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1096 if (compose_parse_header(compose, msginfo) < 0) return;
1097 compose_reedit_set_entry(compose, msginfo);
1099 text = GTK_STEXT(compose->text);
1100 gtk_stext_freeze(text);
1102 if ((fp = procmime_get_text_part(msginfo)) == NULL)
1103 g_warning(_("Can't get text part\n"));
1105 while (fgets(buf, sizeof(buf), fp) != NULL)
1106 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1109 compose_attach_parts(compose, msginfo);
1111 gtk_stext_thaw(text);
1112 gtk_widget_grab_focus(compose->text);
1115 GList *compose_get_compose_list(void)
1117 return compose_list;
1120 void compose_entry_append(Compose *compose, const gchar *address,
1121 ComposeEntryType type)
1126 if (!address || *address == '\0') return;
1130 entry = GTK_ENTRY(compose->cc_entry);
1133 entry = GTK_ENTRY(compose->bcc_entry);
1135 case COMPOSE_NEWSGROUPS:
1136 entry = GTK_ENTRY(compose->newsgroups_entry);
1140 entry = GTK_ENTRY(compose->to_entry);
1144 text = gtk_entry_get_text(entry);
1146 gtk_entry_append_text(entry, ", ");
1147 gtk_entry_append_text(entry, address);
1150 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1152 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1153 {"Cc:", NULL, FALSE},
1154 {"References:", NULL, FALSE},
1155 {"Bcc:", NULL, FALSE},
1156 {"Newsgroups:", NULL, FALSE},
1157 {"Followup-To:", NULL, FALSE},
1158 {NULL, NULL, FALSE}};
1172 g_return_val_if_fail(msginfo != NULL, -1);
1174 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1175 procheader_get_header_fields(fp, hentry);
1178 if (hentry[H_REPLY_TO].body != NULL) {
1179 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1180 compose->replyto = hentry[H_REPLY_TO].body;
1181 hentry[H_REPLY_TO].body = NULL;
1183 if (hentry[H_CC].body != NULL) {
1184 conv_unmime_header_overwrite(hentry[H_CC].body);
1185 compose->cc = hentry[H_CC].body;
1186 hentry[H_CC].body = NULL;
1188 if (hentry[H_REFERENCES].body != NULL) {
1189 if (compose->mode == COMPOSE_REEDIT_DRAFT)
1190 compose->references = hentry[H_REFERENCES].body;
1192 compose->references = compose_parse_references
1193 (hentry[H_REFERENCES].body, msginfo->msgid);
1194 g_free(hentry[H_REFERENCES].body);
1196 hentry[H_REFERENCES].body = NULL;
1198 if (hentry[H_BCC].body != NULL) {
1199 if (compose->mode == COMPOSE_REEDIT_DRAFT) {
1200 conv_unmime_header_overwrite(hentry[H_BCC].body);
1201 compose->bcc = hentry[H_BCC].body;
1203 g_free(hentry[H_BCC].body);
1204 hentry[H_BCC].body = NULL;
1206 if (hentry[H_NEWSGROUPS].body != NULL) {
1207 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1208 hentry[H_NEWSGROUPS].body = NULL;
1210 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1211 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1212 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1213 hentry[H_FOLLOWUP_TO].body = NULL;
1216 if (compose->mode == COMPOSE_REEDIT_DRAFT && msginfo->inreplyto)
1217 compose->inreplyto = g_strdup(msginfo->inreplyto);
1218 else if (compose->mode != COMPOSE_REEDIT_DRAFT &&
1219 msginfo->msgid && *msginfo->msgid) {
1220 compose->inreplyto = g_strdup(msginfo->msgid);
1222 if (!compose->references) {
1223 if (msginfo->inreplyto && *msginfo->inreplyto)
1224 compose->references =
1225 g_strdup_printf("<%s>\n\t<%s>",
1229 compose->references =
1230 g_strconcat("<", msginfo->msgid, ">",
1238 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1240 GSList *ref_id_list, *cur;
1244 ref_id_list = references_list_append(NULL, ref);
1245 if (!ref_id_list) return NULL;
1246 if (msgid && *msgid)
1247 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1252 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1253 /* "<" + Message-ID + ">" + CR+LF+TAB */
1254 len += strlen((gchar *)cur->data) + 5;
1256 if (len > MAX_REFERENCES_LEN) {
1257 /* remove second message-ID */
1258 if (ref_id_list && ref_id_list->next &&
1259 ref_id_list->next->next) {
1260 g_free(ref_id_list->next->data);
1261 ref_id_list = g_slist_remove
1262 (ref_id_list, ref_id_list->next->data);
1264 slist_free_strings(ref_id_list);
1265 g_slist_free(ref_id_list);
1272 new_ref = g_string_new("");
1273 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1274 if (new_ref->len > 0)
1275 g_string_append(new_ref, "\n\t");
1276 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1279 slist_free_strings(ref_id_list);
1280 g_slist_free(ref_id_list);
1282 new_ref_str = new_ref->str;
1283 g_string_free(new_ref, FALSE);
1289 static void compose_quote_file(Compose *compose, MsgInfo *msginfo, FILE *fp)
1291 GtkSText *text = GTK_STEXT(compose->text);
1294 GdkColor *qcolor = NULL;
1295 gchar buf[BUFFSIZE];
1297 gchar *linep, *cur, *leftp;
1298 gint line_len, cur_len;
1303 // if (prefs_common.enable_color) qcolor = "e_color;
1304 if (prefs_common.quotemark && *prefs_common.quotemark)
1305 qmark = prefs_common.quotemark;
1308 quote_str = compose_quote_parse_fmt(compose, msginfo, qmark);
1309 g_return_if_fail(quote_str != NULL);
1310 qlen = strlen(quote_str);
1312 if (!prefs_common.linewrap_quote ||
1313 prefs_common.linewrap_len <= qlen) {
1314 while (fgets(buf, sizeof(buf), fp) != NULL) {
1315 gtk_stext_insert(text, NULL, qcolor, NULL,
1317 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1323 wrap_len = prefs_common.linewrap_len - qlen;
1325 while (fgets(buf, sizeof(buf), fp) != NULL) {
1327 str_len = strlen(buf);
1329 if (str_len <= wrap_len) {
1330 gtk_stext_insert(text, NULL, qcolor, NULL,
1332 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1333 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1337 linep = cur = leftp = buf;
1338 line_len = cur_len = 0;
1340 while (*cur != '\0') {
1341 ch_len = mblen(cur, MB_CUR_MAX);
1342 if (ch_len < 0) ch_len = 1;
1344 if (ch_len == 1 && isspace(*cur)) {
1345 linep = cur + ch_len;
1346 line_len = cur_len + ch_len;
1349 if (cur_len + ch_len > wrap_len && line_len > 0) {
1350 gtk_stext_insert(text, NULL, qcolor, NULL,
1353 if (isspace(*(linep - 1)))
1354 gtk_stext_insert(text, NULL,
1356 leftp, line_len - 1);
1358 gtk_stext_insert(text, NULL,
1361 gtk_stext_insert(text, NULL, NULL, NULL,
1365 cur_len = cur_len - line_len + ch_len;
1372 linep = cur + ch_len;
1373 line_len = cur_len + ch_len;
1380 gtk_stext_insert(text, NULL, qcolor, NULL,
1382 gtk_stext_insert(text, NULL, qcolor, NULL, leftp, -1);
1383 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1392 static gchar *compose_quote_parse_fmt(Compose *compose, MsgInfo *msginfo,
1396 size_t buf_len = 1024;
1404 if (!fmt || *fmt == '\0') return 0;
1406 Xalloca(mbs, sizeof(wchar_t) + 1, return 0);
1407 Xalloca(wcsfmt, (strlen(fmt) + 1) * sizeof(wchar_t), return 0);
1408 mbstowcs(wcsfmt, fmt, strlen(fmt) + 1);
1411 ext_str = g_malloc(sizeof(gchar) * buf_len);
1412 g_return_val_if_fail(ext_str != NULL, NULL);
1417 len = wctomb(mbs, *sp);
1423 wctomb(mbs, *(++sp));
1428 str = msginfo->date;
1432 str = msginfo->from;
1436 if (!msginfo->fromname) {sp++; break;}
1437 p = msginfo->fromname;
1438 tmp[0] = tmp[1] = tmp[2] = '\0';
1440 if (*p && isalnum(*p))
1441 tmp[0] = toupper(*p);
1448 while (*p && !isspace(*p)) p++;
1449 while (*p && isspace(*p)) p++;
1450 if (*p && isalnum(*p))
1451 tmp[1] = toupper(*p);
1454 if (tmp[1]) str = tmp;
1458 str = msginfo->fromname;
1462 if (!msginfo->fromname) {sp++; break;}
1463 Xstrdup_a(str, msginfo->fromname,
1466 while (*p && !isspace(*p)) p++;
1471 str = msginfo->subject;
1483 if (!msginfo->msgid) {sp++; break;}
1484 Xalloca(str, strlen(msginfo->msgid) + 3,
1486 g_snprintf(str, strlen(msginfo->msgid) + 3,
1487 "<%s>", msginfo->msgid);
1499 while (ext_len + strlen(str) + 1 > buf_len)
1501 ext_str = g_realloc(ext_str,
1502 sizeof(gchar) * buf_len);
1503 g_return_val_if_fail(ext_str != NULL, NULL);
1504 strcpy(ext_str + ext_len, str);
1505 ext_len += strlen(str);
1507 } else if (*mbs == '\\') {
1508 wctomb(mbs, *(++sp));
1526 while (ext_len + strlen(str) + 1 > buf_len)
1528 ext_str = g_realloc(ext_str,
1529 sizeof(gchar) * buf_len);
1530 g_return_val_if_fail(ext_str != NULL, NULL);
1531 strcpy(ext_str + ext_len, str);
1532 ext_len += strlen(str);
1536 while (ext_len + len + 1 > buf_len) buf_len += 1024;
1537 ext_str = g_realloc(ext_str, sizeof(gchar) * buf_len);
1538 g_return_val_if_fail(ext_str != NULL, NULL);
1539 strcpy(ext_str + ext_len, mbs);
1546 ext_str = g_realloc(ext_str, strlen(ext_str) + 1);
1552 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1553 gboolean to_all, gboolean ignore_replyto,
1554 gboolean followup_and_reply_to)
1559 GHashTable *to_table;
1561 g_return_if_fail(compose->account != NULL);
1562 g_return_if_fail(msginfo != NULL);
1564 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1565 gtk_entry_set_text(GTK_ENTRY(compose->to_entry),
1566 ( (compose->replyto && !ignore_replyto)
1568 : msginfo->from ? msginfo->from : ""));
1569 if (compose->account->protocol == A_NNTP)
1570 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry),
1571 compose->followup_to ? compose->followup_to
1572 : compose->newsgroups ? compose->newsgroups
1575 if (msginfo->subject && *msginfo->subject) {
1576 gchar *buf, *buf2, *p;
1578 buf = g_strdup(msginfo->subject);
1579 while (!strncasecmp(buf, "Re:", 3)) {
1581 while (isspace(*p)) p++;
1582 memmove(buf, p, strlen(p) + 1);
1585 buf2 = g_strdup_printf("Re: %s", buf);
1586 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1590 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1592 if (!to_all || compose->account->protocol == A_NNTP) return;
1594 from = g_strdup(compose->replyto ? compose->replyto :
1595 msginfo->from ? msginfo->from : "");
1596 extract_address(from);
1598 cc_list = address_list_append(NULL, msginfo->to);
1599 cc_list = address_list_append(cc_list, compose->cc);
1601 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1602 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1603 if (compose->account)
1604 g_hash_table_insert(to_table, compose->account->address,
1605 GINT_TO_POINTER(1));
1607 /* remove address on To: and that of current account */
1608 for (cur = cc_list; cur != NULL; ) {
1609 GSList *next = cur->next;
1611 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1612 cc_list = g_slist_remove(cc_list, cur->data);
1614 g_hash_table_insert(to_table, cur->data, cur);
1618 g_hash_table_destroy(to_table);
1622 for (cur = cc_list; cur != NULL; cur = cur->next)
1623 compose_entry_append(compose, (gchar *)cur->data,
1625 slist_free_strings(cc_list);
1626 g_slist_free(cc_list);
1630 #define SET_ENTRY(entry, str) \
1633 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1636 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1638 g_return_if_fail(msginfo != NULL);
1640 SET_ENTRY(to_entry, msginfo->to);
1641 SET_ENTRY(subject_entry, msginfo->subject);
1642 SET_ENTRY(cc_entry, compose->cc);
1643 SET_ENTRY(bcc_entry, compose->bcc);
1644 SET_ENTRY(reply_entry, compose->replyto);
1647 GtkItemFactory *ifactory;
1648 GtkWidget *menuitem;
1650 ifactory = gtk_item_factory_from_widget(compose->menubar);
1651 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1652 gtk_check_menu_item_set_active
1653 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1655 if (compose->replyto) {
1656 GtkItemFactory *ifactory;
1657 GtkWidget *menuitem;
1659 ifactory = gtk_item_factory_from_widget(compose->menubar);
1660 menuitem = gtk_item_factory_get_item
1661 (ifactory, "/Message/Reply to");
1662 gtk_check_menu_item_set_active
1663 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1669 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1676 size_t buf_len = 128;
1678 if (strlen(sigfile) < 2)
1681 sigprg = popen(sigfile+1, "r");
1684 buf = g_malloc(buf_len);
1687 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1688 "Unable to insert signature (malloc failed)\n", -1);
1694 while (!feof(sigprg)) {
1695 bzero(buf, buf_len);
1696 fread(buf, buf_len-1, 1, sigprg);
1697 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1705 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1706 "Can't exec file: ", -1);
1707 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1712 static void compose_insert_sig(Compose *compose)
1716 if (compose->account && compose->account->sig_path)
1717 sigfile = g_strdup(compose->account->sig_path);
1719 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1720 DEFAULT_SIGNATURE, NULL);
1723 if (!is_file_or_fifo_exist(sigfile) & (sigfile[0] != '|')) {
1728 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1729 if (prefs_common.sig_sep) {
1730 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1731 prefs_common.sig_sep, -1);
1732 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1736 if (sigfile[0] == '|')
1738 compose_exec_sig(compose, sigfile);
1742 compose_insert_file(compose, sigfile);
1747 static void compose_insert_file(Compose *compose, const gchar *file)
1749 GtkSText *text = GTK_STEXT(compose->text);
1750 gchar buf[BUFFSIZE];
1753 g_return_if_fail(file != NULL);
1755 if ((fp = fopen(file, "r")) == NULL) {
1756 FILE_OP_ERROR(file, "fopen");
1760 gtk_stext_freeze(text);
1762 while (fgets(buf, sizeof(buf), fp) != NULL)
1763 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1765 gtk_stext_thaw(text);
1770 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1771 ContentType cnttype)
1773 gchar *text[N_ATTACH_COLS];
1776 text[COL_MIMETYPE] = ainfo->content_type;
1777 text[COL_SIZE] = to_human_readable(ainfo->size);
1778 text[COL_NAME] = ainfo->name;
1780 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1781 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1783 if (cnttype != MIME_MESSAGE_RFC822)
1784 compose_changed_cb(NULL, compose);
1787 static void compose_attach_append_with_type(Compose *compose,
1790 ContentType cnttype)
1795 if (!is_file_exist(file)) {
1796 g_warning(_("File %s doesn't exist\n"), file);
1799 if ((size = get_file_size(file)) < 0) {
1800 g_warning(_("Can't get file size of %s\n"), file);
1804 alertpanel_notice(_("File %s is empty\n"), file);
1808 if (!compose->use_attach) {
1809 GtkItemFactory *ifactory;
1810 GtkWidget *menuitem;
1812 ifactory = gtk_item_factory_from_widget(compose->menubar);
1813 menuitem = gtk_item_factory_get_item(ifactory,
1815 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1819 ainfo = g_new0(AttachInfo, 1);
1820 ainfo->file = g_strdup(file);
1822 if (cnttype == MIME_MESSAGE_RFC822) {
1823 ainfo->encoding = ENC_7BIT;
1824 ainfo->name = g_strdup_printf(_("Message: %s"),
1827 ainfo->encoding = ENC_BASE64;
1828 ainfo->name = g_strdup(g_basename(file));
1831 ainfo->content_type = g_strdup(type);
1834 compose_attach_info(compose, ainfo, cnttype);
1837 static void compose_attach_append(Compose *compose, const gchar *file,
1838 ContentType cnttype)
1841 gchar *text[N_ATTACH_COLS];
1845 if (!is_file_exist(file)) {
1846 g_warning(_("File %s doesn't exist\n"), file);
1849 if ((size = get_file_size(file)) < 0) {
1850 g_warning(_("Can't get file size of %s\n"), file);
1854 alertpanel_notice(_("File %s is empty\n"), file);
1858 if (!compose->use_attach) {
1859 GtkItemFactory *ifactory;
1860 GtkWidget *menuitem;
1862 ifactory = gtk_item_factory_from_widget(compose->menubar);
1863 menuitem = gtk_item_factory_get_item(ifactory,
1865 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1869 ainfo = g_new0(AttachInfo, 1);
1870 ainfo->file = g_strdup(file);
1872 if (cnttype == MIME_MESSAGE_RFC822) {
1873 ainfo->content_type = g_strdup("message/rfc822");
1874 ainfo->encoding = ENC_7BIT;
1875 ainfo->name = g_strdup_printf(_("Message: %s"),
1878 ainfo->content_type = procmime_get_mime_type(file);
1879 if (!ainfo->content_type)
1880 ainfo->content_type =
1881 g_strdup("application/octet-stream");
1882 ainfo->encoding = ENC_BASE64;
1883 ainfo->name = g_strdup(g_basename(file));
1887 compose_attach_info(compose, ainfo, cnttype);
1890 static void compose_wrap_line(Compose *compose)
1892 GtkSText *text = GTK_STEXT(compose->text);
1894 guint line_pos = 0, cur_pos = 0;
1895 gint line_len = 0, cur_len = 0;
1897 gchar cbuf[MB_CUR_MAX];
1899 gtk_stext_freeze(text);
1901 text_len = gtk_stext_get_length(text);
1903 for (; cur_pos < text_len; cur_pos++) {
1904 if (text->use_wchar)
1906 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
1908 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
1912 if (ch_len == 1 && *cbuf == '\n') {
1913 line_pos = cur_pos + 1;
1914 line_len = cur_len = 0;
1923 if (ch_len == 1 && isspace(*cbuf)) {
1924 line_pos = cur_pos + 1;
1925 line_len = cur_len + ch_len;
1928 if (cur_len + ch_len > prefs_common.linewrap_len &&
1932 if (text->use_wchar)
1933 tlen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
1935 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
1938 if (tlen == 1 && isspace(*cbuf)) {
1939 gtk_stext_set_point(text, line_pos);
1940 gtk_stext_backward_delete(text, 1);
1948 gtk_stext_set_point(text, line_pos);
1949 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1953 cur_len = cur_len - line_len + ch_len;
1959 line_pos = cur_pos + 1;
1960 line_len = cur_len + ch_len;
1965 gtk_stext_thaw(text);
1968 static void compose_set_title(Compose *compose)
1973 edited = compose->modified ? _(" [Edited]") : "";
1974 if (compose->account && compose->account->address)
1975 str = g_strdup_printf(_("%s - Compose message%s"),
1976 compose->account->address, edited);
1978 str = g_strdup_printf(_("Compose message%s"), edited);
1979 gtk_window_set_title(GTK_WINDOW(compose->window), str);
1984 * compose_current_mail_account:
1986 * Find a current mail account (the currently selected account, or the
1987 * default account, if a news account is currently selected). If a
1988 * mail account cannot be found, display an error message.
1990 * Return value: Mail account, or NULL if not found.
1992 static PrefsAccount *
1993 compose_current_mail_account(void)
1997 if (cur_account && cur_account->protocol != A_NNTP)
2000 ac = account_get_default();
2001 if (!ac || ac->protocol == A_NNTP) {
2002 alertpanel_error(_("Account for sending mail is not specified.\n"
2003 "Please select a mail account before sending."));
2010 gint compose_send(Compose *compose)
2012 gchar tmp[MAXPATHLEN + 1];
2013 gchar *to, *newsgroups;
2015 static gboolean lock = FALSE;
2019 g_return_val_if_fail(compose->account != NULL, -1);
2020 g_return_val_if_fail(compose->orig_account != NULL, -1);
2024 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2025 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2026 if (*to == '\0' && *newsgroups == '\0') {
2027 alertpanel_error(_("Recipient is not specified."));
2032 /* write to temporary file */
2033 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2034 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2036 if (prefs_common.linewrap_at_send)
2037 compose_wrap_line(compose);
2039 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2044 if (!compose->to_list && !compose->newsgroup_list) {
2045 g_warning(_("can't get recipient list."));
2051 if (compose->to_list) {
2055 if (compose->account->protocol != A_NNTP)
2056 ac = compose->account;
2057 else if (compose->orig_account->protocol != A_NNTP)
2058 ac = compose->orig_account;
2059 else if (cur_account && cur_account->protocol != A_NNTP)
2062 ac = compose_current_mail_account();
2070 ac = compose->account;
2072 ok = send_message(tmp, ac, compose->to_list);
2073 statusbar_pop_all();
2076 if (ok == 0 && compose->newsgroup_list) {
2079 if (compose->account->protocol == A_NNTP)
2080 folder = FOLDER(compose->account->folder);
2082 folder = FOLDER(compose->orig_account->folder);
2084 ok = news_post(folder, tmp);
2086 alertpanel_error(_("Error occurred while posting the message to %s ."),
2087 compose->account->nntp_server);
2094 /* queue message if failed to send */
2096 if (prefs_common.queue_msg) {
2101 _("Error occurred while sending the message.\n"
2102 "Put this message into queue folder?"),
2103 _("OK"), _("Cancel"), NULL);
2104 if (G_ALERTDEFAULT == val) {
2105 ok = compose_queue(compose, tmp);
2107 alertpanel_error(_("Can't queue the message."));
2110 alertpanel_error(_("Error occurred while sending the message."));
2113 /* save message to outbox */
2114 if (ok == 0 && prefs_common.savemsg) {
2115 if (compose_save_to_outbox(compose, tmp) < 0)
2117 (_("Can't save the message to outbox."));
2125 static gint compose_write_to_file(Compose *compose, const gchar *file,
2132 const gchar *out_codeset;
2133 EncodingType encoding;
2135 if ((fp = fopen(file, "w")) == NULL) {
2136 FILE_OP_ERROR(file, "fopen");
2140 /* chmod for security */
2141 if (change_file_mode_rw(fp, file) < 0) {
2142 FILE_OP_ERROR(file, "chmod");
2143 g_warning(_("can't change file mode\n"));
2146 /* get all composed text */
2147 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2148 len = strlen(chars);
2149 if (is_ascii_str(chars)) {
2150 buf = g_strdup(chars);
2151 out_codeset = "US-ASCII";
2152 encoding = ENC_7BIT;
2154 const gchar *src_codeset;
2156 out_codeset = conv_get_outgoing_charset_str();
2157 if (!strcasecmp(out_codeset, "US-ASCII"))
2158 out_codeset = "ISO-8859-1";
2159 encoding = procmime_get_encoding_for_charset(out_codeset);
2160 debug_print("charset = %s, encoding = %s\n",
2161 out_codeset, procmime_get_encoding_str(encoding));
2163 src_codeset = conv_get_current_charset_str();
2164 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
2169 alertpanel_error(_("Can't convert the codeset of the message."));
2176 if (compose_write_headers
2177 (compose, fp, out_codeset, encoding, is_draft) < 0) {
2178 g_warning(_("can't write headers\n"));
2185 if (compose->use_attach) {
2187 /* This prolog message is ignored by mime software and
2188 * because it would make our signing/encryption task
2189 * tougher, we don't emit it in that case */
2190 if (!compose->use_signing && !compose->use_encryption)
2192 fputs("This is a multi-part message in MIME format.\n", fp);
2194 fprintf(fp, "\n--%s\n", compose->boundary);
2195 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
2197 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2198 procmime_get_encoding_str(encoding));
2204 if (encoding == ENC_BASE64) {
2205 gchar outbuf[B64_BUFFSIZE];
2208 for (i = 0; i < len; i += B64_LINE_SIZE) {
2209 l = MIN(B64_LINE_SIZE, len - i);
2210 to64frombits(outbuf, buf + i, l);
2214 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
2215 FILE_OP_ERROR(file, "fwrite");
2223 if (compose->use_attach)
2224 compose_write_attach(compose, fp);
2226 if (fclose(fp) == EOF) {
2227 FILE_OP_ERROR(file, "fclose");
2233 if (compose->use_signing) {
2234 if (rfc2015_sign(file, compose->account) < 0) {
2239 if (compose->use_encryption) {
2240 if (rfc2015_encrypt(file, compose->to_list) < 0) {
2245 #endif /* USE_GPGME */
2250 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
2256 if ((fp = fopen(file, "w")) == NULL) {
2257 FILE_OP_ERROR(file, "fopen");
2261 /* chmod for security */
2262 if (change_file_mode_rw(fp, file) < 0) {
2263 FILE_OP_ERROR(file, "chmod");
2264 g_warning(_("can't change file mode\n"));
2267 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2270 len = strlen(chars);
2271 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
2272 FILE_OP_ERROR(file, "fwrite");
2281 if (fclose(fp) == EOF) {
2282 FILE_OP_ERROR(file, "fclose");
2289 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
2296 debug_print(_("saving sent message...\n"));
2298 outbox = folder_get_default_outbox();
2299 path = folder_item_get_path(outbox);
2300 if (!is_dir_exist(path))
2301 make_dir_hier(path);
2303 folder_item_scan(outbox);
2304 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
2306 g_warning(_("can't save message\n"));
2310 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
2311 g_warning(_("can't open mark file\n"));
2315 newmsginfo.msgnum = num;
2316 newmsginfo.flags.perm_flags = 0;
2317 newmsginfo.flags.tmp_flags = 0;
2318 procmsg_write_flags(&newmsginfo, fp);
2326 static gint compose_queue(Compose *compose, const gchar *file)
2329 gchar *tmp, *queue_path;
2332 gchar buf[BUFFSIZE];
2335 debug_print(_("queueing message...\n"));
2336 g_return_val_if_fail(compose->to_list != NULL, -1);
2337 g_return_val_if_fail(compose->account != NULL, -1);
2339 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
2340 G_DIR_SEPARATOR, (gint)compose);
2341 if ((fp = fopen(tmp, "w")) == NULL) {
2342 FILE_OP_ERROR(tmp, "fopen");
2346 if ((src_fp = fopen(file, "r")) == NULL) {
2347 FILE_OP_ERROR(file, "fopen");
2353 if (change_file_mode_rw(fp, tmp) < 0) {
2354 FILE_OP_ERROR(tmp, "chmod");
2355 g_warning(_("can't change file mode\n"));
2358 /* queueing variables */
2359 fprintf(fp, "AF:\n");
2360 fprintf(fp, "NF:0\n");
2361 fprintf(fp, "PS:10\n");
2362 fprintf(fp, "SRH:1\n");
2363 fprintf(fp, "SFN:\n");
2364 fprintf(fp, "DSR:\n");
2366 fprintf(fp, "MID:<%s>\n", compose->msgid);
2368 fprintf(fp, "MID:\n");
2369 fprintf(fp, "CFG:\n");
2370 fprintf(fp, "PT:0\n");
2371 fprintf(fp, "S:%s\n", compose->account->address);
2372 fprintf(fp, "RQ:\n");
2373 if (compose->account->smtp_server)
2374 fprintf(fp, "SSV:%s\n", compose->account->smtp_server);
2376 fprintf(fp, "SSV:\n");
2377 if (compose->account->nntp_server)
2378 fprintf(fp, "NSV:%s\n", compose->account->nntp_server);
2380 fprintf(fp, "NSV:\n");
2381 fprintf(fp, "SSH:\n");
2382 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
2383 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
2384 fprintf(fp, ",<%s>", (gchar *)cur->data);
2386 /* Sylpheed account ID */
2387 fprintf(fp, "AID:%d\n", compose->account->account_id);
2390 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
2391 if (fputs(buf, fp) == EOF) {
2392 FILE_OP_ERROR(tmp, "fputs");
2402 if (fclose(fp) == EOF) {
2403 FILE_OP_ERROR(tmp, "fclose");
2409 queue = folder_get_default_queue();
2410 folder_item_scan(queue);
2411 queue_path = folder_item_get_path(queue);
2412 if (!is_dir_exist(queue_path))
2413 make_dir_hier(queue_path);
2414 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
2415 g_warning(_("can't queue the message\n"));
2423 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
2424 g_warning(_("can't open mark file\n"));
2428 newmsginfo.msgnum = num;
2429 newmsginfo.flags.perm_flags = 0;
2430 newmsginfo.flags.tmp_flags = 0;
2431 procmsg_write_flags(&newmsginfo, fp);
2436 folder_item_scan(queue);
2437 folderview_update_item(queue, TRUE);
2442 static void compose_write_attach(Compose *compose, FILE *fp)
2445 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2448 gchar filename[BUFFSIZE];
2451 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
2453 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
2454 g_warning(_("Can't open file %s\n"), ainfo->file);
2458 fprintf(fp, "\n--%s\n", compose->boundary);
2460 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
2461 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
2462 fprintf(fp, "Content-Disposition: inline\n");
2464 conv_encode_header(filename, sizeof(filename),
2466 fprintf(fp, "Content-Type: %s;\n"
2468 ainfo->content_type, filename);
2469 fprintf(fp, "Content-Disposition: attachment;\n"
2470 " filename=\"%s\"\n", filename);
2473 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
2474 procmime_get_encoding_str(ainfo->encoding));
2476 if (ainfo->encoding == ENC_7BIT) {
2477 gchar buf[BUFFSIZE];
2479 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
2481 if (len > 1 && buf[len - 1] == '\n' &&
2482 buf[len - 2] == '\r') {
2483 buf[len - 2] = '\n';
2484 buf[len - 1] = '\0';
2489 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
2491 while ((len = fread(inbuf, sizeof(gchar),
2492 B64_LINE_SIZE, attach_fp))
2494 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
2498 if (len > 0 && feof(attach_fp)) {
2499 to64frombits(outbuf, inbuf, len);
2508 fprintf(fp, "\n--%s--\n", compose->boundary);
2511 #define IS_IN_CUSTOM_HEADER(header) \
2512 (compose->account->add_customhdr && \
2513 custom_header_find(compose->account->customhdr_list, header) != NULL)
2515 static gint compose_write_headers(Compose *compose, FILE *fp,
2516 const gchar *charset, EncodingType encoding,
2519 gchar buf[BUFFSIZE];
2521 /* struct utsname utsbuf; */
2523 g_return_val_if_fail(fp != NULL, -1);
2524 g_return_val_if_fail(charset != NULL, -1);
2525 g_return_val_if_fail(compose->account != NULL, -1);
2526 g_return_val_if_fail(compose->account->address != NULL, -1);
2529 if (compose->account->add_date) {
2530 get_rfc822_date(buf, sizeof(buf));
2531 fprintf(fp, "Date: %s\n", buf);
2535 if (!IS_IN_CUSTOM_HEADER("From")) {
2536 if (compose->account->name && *compose->account->name) {
2537 compose_convert_header
2538 (buf, sizeof(buf), compose->account->name,
2540 fprintf(fp, "From: %s <%s>\n",
2541 buf, compose->account->address);
2543 fprintf(fp, "From: %s\n", compose->account->address);
2546 slist_free_strings(compose->to_list);
2547 g_slist_free(compose->to_list);
2548 compose->to_list = NULL;
2551 if (compose->use_to) {
2552 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2554 Xstrdup_a(str, str, return -1);
2557 compose->to_list = address_list_append
2558 (compose->to_list, str);
2559 if (!IS_IN_CUSTOM_HEADER("To")) {
2560 compose_convert_header
2561 (buf, sizeof(buf), str,
2563 fprintf(fp, "To: %s\n", buf);
2569 slist_free_strings(compose->newsgroup_list);
2570 g_slist_free(compose->newsgroup_list);
2571 compose->newsgroup_list = NULL;
2574 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2576 Xstrdup_a(str, str, return -1);
2580 compose->newsgroup_list =
2581 newsgroup_list_append(compose->newsgroup_list,
2583 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
2584 compose_convert_header(buf, sizeof(buf), str,
2585 strlen("Newsgroups: "));
2586 fprintf(fp, "Newsgroups: %s\n", buf);
2591 if (!is_draft && !compose->to_list && !compose->newsgroup_list)
2595 if (compose->use_cc) {
2596 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
2598 Xstrdup_a(str, str, return -1);
2601 compose->to_list = address_list_append
2602 (compose->to_list, str);
2603 if (!IS_IN_CUSTOM_HEADER("Cc")) {
2604 compose_convert_header
2605 (buf, sizeof(buf), str,
2607 fprintf(fp, "Cc: %s\n", buf);
2614 if (compose->use_bcc) {
2615 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
2617 Xstrdup_a(str, str, return -1);
2620 compose->to_list = address_list_append
2621 (compose->to_list, str);
2623 compose_convert_header
2624 (buf, sizeof(buf), str,
2626 fprintf(fp, "Bcc: %s\n", buf);
2633 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2634 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
2635 Xstrdup_a(str, str, return -1);
2638 compose_convert_header(buf, sizeof(buf), str,
2639 strlen("Subject: "));
2640 fprintf(fp, "Subject: %s\n", buf);
2645 if (compose->account->gen_msgid) {
2646 compose_generate_msgid(compose, buf, sizeof(buf));
2647 fprintf(fp, "Message-Id: <%s>\n", buf);
2648 compose->msgid = g_strdup(buf);
2652 if (compose->inreplyto && compose->to_list)
2653 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
2656 if (compose->references)
2657 fprintf(fp, "References: %s\n", compose->references);
2660 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
2661 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
2663 Xstrdup_a(str, str, return -1);
2667 compose_convert_header(buf, sizeof(buf), str,
2668 strlen("Followup-To: "));
2669 fprintf(fp, "Followup-To: %s\n", buf);
2675 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
2676 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
2678 Xstrdup_a(str, str, return -1);
2681 compose_convert_header(buf, sizeof(buf), str,
2682 strlen("Reply-To: "));
2683 fprintf(fp, "Reply-To: %s\n", buf);
2689 if (compose->account->organization &&
2690 !IS_IN_CUSTOM_HEADER("Organization")) {
2691 compose_convert_header(buf, sizeof(buf),
2692 compose->account->organization,
2693 strlen("Organization: "));
2694 fprintf(fp, "Organization: %s\n", buf);
2697 /* Program version and system info */
2698 /* uname(&utsbuf); */
2699 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2700 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
2701 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
2703 gtk_major_version, gtk_minor_version, gtk_micro_version,
2705 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2707 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2708 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
2709 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
2711 gtk_major_version, gtk_minor_version, gtk_micro_version,
2713 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2716 /* custom headers */
2717 if (compose->account->add_customhdr) {
2720 for (cur = compose->account->customhdr_list; cur != NULL;
2722 CustomHeader *chdr = (CustomHeader *)cur->data;
2724 if (strcasecmp(chdr->name, "Date") != 0 &&
2725 strcasecmp(chdr->name, "From") != 0 &&
2726 strcasecmp(chdr->name, "To") != 0 &&
2727 strcasecmp(chdr->name, "Sender") != 0 &&
2728 strcasecmp(chdr->name, "Message-Id") != 0 &&
2729 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
2730 strcasecmp(chdr->name, "References") != 0 &&
2731 strcasecmp(chdr->name, "Mime-Version") != 0 &&
2732 strcasecmp(chdr->name, "Content-Type") != 0 &&
2733 strcasecmp(chdr->name, "Content-Transfer-Encoding")
2735 compose_convert_header
2737 chdr->value ? chdr->value : "",
2738 strlen(chdr->name) + 2);
2739 fprintf(fp, "%s: %s\n", chdr->name, buf);
2744 fprintf(fp, "Mime-Version: 1.0\n");
2745 if (compose->use_attach) {
2746 get_rfc822_date(buf, sizeof(buf));
2747 subst_char(buf, ' ', '_');
2748 subst_char(buf, ',', '_');
2749 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
2750 buf, (guint)compose);
2752 "Content-Type: multipart/mixed;\n"
2753 " boundary=\"%s\"\n", compose->boundary);
2755 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
2756 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2757 procmime_get_encoding_str(encoding));
2760 /* Request Return Receipt */
2761 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
2762 if (compose->return_receipt) {
2763 if (compose->account->name
2764 && *compose->account->name) {
2765 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
2766 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
2768 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
2772 /* separator between header and body */
2778 #undef IS_IN_CUSTOM_HEADER
2780 static void compose_convert_header(gchar *dest, gint len, gchar *src,
2783 g_return_if_fail(src != NULL);
2784 g_return_if_fail(dest != NULL);
2786 if (len < 1) return;
2790 if (is_ascii_str(src)) {
2791 strncpy2(dest, src, len);
2792 dest[len - 1] = '\0';
2795 conv_encode_header(dest, len, src, header_len);
2798 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
2807 if (compose->account && compose->account->address &&
2808 *compose->account->address) {
2809 if (strchr(compose->account->address, '@'))
2810 addr = g_strdup(compose->account->address);
2812 addr = g_strconcat(compose->account->address, "@",
2813 get_domain_name(), NULL);
2815 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
2818 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
2819 lt->tm_year + 1900, lt->tm_mon + 1,
2820 lt->tm_mday, lt->tm_hour,
2821 lt->tm_min, lt->tm_sec,
2822 (guint)random(), addr);
2824 debug_print(_("generated Message-ID: %s\n"), buf);
2829 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
2830 GtkWidget **entry, gint *count,
2831 const gchar *label_str,
2832 gboolean is_addr_entry)
2836 if (GTK_TABLE(table)->nrows < (*count) + 1)
2837 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
2839 *hbox = gtk_hbox_new(FALSE, 0);
2840 label = gtk_label_new
2841 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
2842 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
2843 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
2845 *entry = gtk_entry_new();
2846 gtk_table_attach_defaults
2847 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1);
2848 if (GTK_TABLE(table)->nrows > (*count) + 1)
2849 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
2852 address_completion_register_entry(GTK_ENTRY(*entry));
2857 static Compose *compose_create(PrefsAccount *account)
2863 GtkWidget *handlebox;
2867 GtkWidget *table_vbox;
2869 GtkWidget *from_optmenu_hbox;
2870 GtkWidget *to_entry;
2872 GtkWidget *newsgroups_entry;
2873 GtkWidget *newsgroups_hbox;
2874 GtkWidget *subject_entry;
2875 GtkWidget *cc_entry;
2877 GtkWidget *bcc_entry;
2878 GtkWidget *bcc_hbox;
2879 GtkWidget *reply_entry;
2880 GtkWidget *reply_hbox;
2881 GtkWidget *followup_entry;
2882 GtkWidget *followup_hbox;
2886 GtkWidget *attach_scrwin;
2887 GtkWidget *attach_clist;
2889 GtkWidget *edit_vbox;
2890 GtkWidget *ruler_hbox;
2892 GtkWidget *scrolledwin;
2898 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
2899 guint n_menu_entries;
2900 GtkStyle *style, *new_style;
2903 gboolean success[1];
2905 GtkWidget *popupmenu;
2906 GtkWidget *menuitem;
2907 GtkItemFactory *popupfactory;
2908 GtkItemFactory *ifactory;
2913 g_return_val_if_fail(account != NULL, NULL);
2915 debug_print(_("Creating compose window...\n"));
2916 compose = g_new0(Compose, 1);
2918 compose->account = account;
2919 compose->orig_account = account;
2921 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2922 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
2923 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
2924 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
2925 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
2926 gtk_signal_connect(GTK_OBJECT(window), "destroy",
2927 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
2928 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
2929 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
2930 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
2931 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
2932 gtk_widget_realize(window);
2934 gtkut_widget_set_composer_icon(window);
2936 vbox = gtk_vbox_new(FALSE, 0);
2937 gtk_container_add(GTK_CONTAINER(window), vbox);
2939 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
2940 menubar = menubar_create(window, compose_entries,
2941 n_menu_entries, "<Compose>", compose);
2942 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
2944 handlebox = gtk_handle_box_new();
2945 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
2947 compose_toolbar_create(compose, handlebox);
2949 vbox2 = gtk_vbox_new(FALSE, 2);
2950 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
2951 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
2953 table_vbox = gtk_vbox_new(FALSE, 0);
2954 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
2955 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
2958 table = gtk_table_new(8, 2, FALSE);
2959 gtk_box_pack_start(GTK_BOX(table_vbox), table, FALSE, TRUE, 0);
2961 /* option menu for selecting accounts */
2962 hbox = gtk_hbox_new(FALSE, 0);
2963 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
2964 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
2965 gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, count, count + 1,
2967 from_optmenu_hbox = compose_account_option_menu_create(compose);
2968 gtk_table_attach_defaults(GTK_TABLE(table), from_optmenu_hbox,
2969 1, 2, count, count + 1);
2970 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
2973 /* header labels and entries */
2974 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
2976 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
2977 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
2978 &count, "Newsgroups:", FALSE);
2979 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
2980 compose_add_entry_field(table, &hbox, &subject_entry, &count,
2982 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
2983 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
2985 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
2986 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
2988 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
2989 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
2991 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
2992 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
2993 "Followup-To:", FALSE);
2994 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
2996 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
2998 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
2999 GTK_SIGNAL_FUNC(to_activated), compose);
3000 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
3001 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
3002 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
3003 GTK_SIGNAL_FUNC(subject_activated), compose);
3004 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
3005 GTK_SIGNAL_FUNC(cc_activated), compose);
3006 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
3007 GTK_SIGNAL_FUNC(bcc_activated), compose);
3008 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
3009 GTK_SIGNAL_FUNC(replyto_activated), compose);
3010 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
3011 GTK_SIGNAL_FUNC(followupto_activated), compose);
3013 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
3014 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3015 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
3016 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3017 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
3018 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3019 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
3020 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3021 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
3022 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3023 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
3024 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3025 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
3026 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3028 /* attachment list */
3029 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
3030 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
3031 GTK_POLICY_AUTOMATIC,
3033 gtk_widget_set_usize(attach_scrwin, -1, 80);
3035 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
3036 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
3038 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
3039 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
3040 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
3041 GTK_SELECTION_EXTENDED);
3042 for (i = 0; i < N_ATTACH_COLS; i++)
3043 GTK_WIDGET_UNSET_FLAGS
3044 (GTK_CLIST(attach_clist)->column[i].button,
3046 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
3048 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
3049 GTK_SIGNAL_FUNC(attach_selected), compose);
3050 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
3051 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
3052 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
3053 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
3056 gtk_drag_dest_set(attach_clist,
3057 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3059 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
3060 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
3063 /* pane between attach clist and text */
3064 paned = gtk_vpaned_new();
3065 gtk_paned_add1(GTK_PANED(paned), attach_scrwin);
3066 gtk_widget_ref(paned);
3067 gtk_widget_show_all(paned);
3069 edit_vbox = gtk_vbox_new(FALSE, 0);
3070 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
3073 ruler_hbox = gtk_hbox_new(FALSE, 0);
3074 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
3076 ruler = gtk_shruler_new();
3077 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
3078 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
3080 gtk_widget_set_usize(ruler_hbox, 1, -1);
3083 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3084 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
3085 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
3086 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
3087 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
3089 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
3090 (GTK_SCROLLED_WINDOW(scrolledwin)),
3091 gtk_scrolled_window_get_vadjustment
3092 (GTK_SCROLLED_WINDOW(scrolledwin)));
3093 GTK_STEXT(text)->default_tab_width = 8;
3094 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
3095 if (prefs_common.smart_wrapping) {
3096 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
3097 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
3100 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
3102 gtk_signal_connect(GTK_OBJECT(text), "changed",
3103 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
3104 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
3105 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3106 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
3107 GTK_SIGNAL_FUNC(compose_button_press_cb),
3110 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
3111 GTK_SIGNAL_FUNC(compose_key_press_cb),
3114 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
3115 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
3119 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3121 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
3122 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
3125 gtk_widget_show_all(vbox);
3127 style = gtk_widget_get_style(text);
3129 /* workaround for the slow down of GtkText when using Pixmap theme */
3130 if (style->engine) {
3131 GtkThemeEngine *engine;
3133 engine = style->engine;
3134 style->engine = NULL;
3135 new_style = gtk_style_copy(style);
3136 style->engine = engine;
3138 new_style = gtk_style_copy(style);
3140 if (prefs_common.textfont) {
3143 charset = conv_get_current_charset();
3144 if (MB_CUR_MAX == 1) {
3147 Xstrdup_a(fontstr, prefs_common.textfont, );
3148 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
3150 font = gdk_font_load(fontstr);
3152 font = gdk_fontset_load(prefs_common.textfont);
3154 gdk_font_unref(new_style->font);
3155 new_style->font = font;
3159 gtk_widget_set_style(text, new_style);
3161 color[0] = quote_color;
3162 cmap = gdk_window_get_colormap(window->window);
3163 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
3164 if (success[0] == FALSE) {
3165 g_warning("Compose: color allocation failed.\n");
3166 style = gtk_widget_get_style(text);
3167 quote_color = style->black;
3170 n_entries = sizeof(compose_popup_entries) /
3171 sizeof(compose_popup_entries[0]);
3172 popupmenu = menu_create_items(compose_popup_entries, n_entries,
3173 "<Compose>", &popupfactory,
3176 ifactory = gtk_item_factory_from_widget(menubar);
3177 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
3178 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
3181 if (account->protocol == A_NNTP) {
3182 gtk_widget_hide(to_hbox);
3183 gtk_widget_hide(to_entry);
3184 gtk_widget_hide(cc_hbox);
3185 gtk_widget_hide(cc_entry);
3186 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
3187 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
3189 gtk_widget_hide(newsgroups_hbox);
3190 gtk_widget_hide(newsgroups_entry);
3191 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
3193 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
3197 switch (prefs_common.toolbar_style) {
3199 gtk_widget_hide(handlebox);
3202 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3206 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3210 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3215 gtk_widget_show(window);
3217 address_completion_start(window);
3219 compose->window = window;
3220 compose->vbox = vbox;
3221 compose->menubar = menubar;
3222 compose->handlebox = handlebox;
3224 compose->vbox2 = vbox2;
3226 compose->table_vbox = table_vbox;
3227 compose->table = table;
3228 compose->to_hbox = to_hbox;
3229 compose->to_entry = to_entry;
3230 compose->newsgroups_hbox = newsgroups_hbox;
3231 compose->newsgroups_entry = newsgroups_entry;
3232 compose->subject_entry = subject_entry;
3233 compose->cc_hbox = cc_hbox;
3234 compose->cc_entry = cc_entry;
3235 compose->bcc_hbox = bcc_hbox;
3236 compose->bcc_entry = bcc_entry;
3237 compose->reply_hbox = reply_hbox;
3238 compose->reply_entry = reply_entry;
3239 compose->followup_hbox = followup_hbox;
3240 compose->followup_entry = followup_entry;
3242 compose->paned = paned;
3244 compose->attach_scrwin = attach_scrwin;
3245 compose->attach_clist = attach_clist;
3247 compose->edit_vbox = edit_vbox;
3248 compose->ruler_hbox = ruler_hbox;
3249 compose->ruler = ruler;
3250 compose->scrolledwin = scrolledwin;
3251 compose->text = text;
3253 compose->focused_editable = NULL;
3255 compose->popupmenu = popupmenu;
3256 compose->popupfactory = popupfactory;
3258 compose->mode = COMPOSE_NEW;
3260 compose->replyto = NULL;
3262 compose->bcc = NULL;
3263 compose->followup_to = NULL;
3264 compose->inreplyto = NULL;
3265 compose->references = NULL;
3266 compose->msgid = NULL;
3267 compose->boundary = NULL;
3270 compose->use_signing = FALSE;
3271 compose->use_encryption = FALSE;
3272 #endif /* USE_GPGME */
3274 compose->modified = FALSE;
3276 compose->return_receipt = FALSE;
3278 compose->to_list = NULL;
3279 compose->newsgroup_list = NULL;
3281 compose->exteditor_file = NULL;
3282 compose->exteditor_pid = -1;
3283 compose->exteditor_readdes = -1;
3284 compose->exteditor_tag = -1;
3286 compose_set_title(compose);
3288 compose->use_bcc = FALSE;
3289 compose->use_replyto = FALSE;
3290 compose->use_followupto = FALSE;
3293 if (account->protocol != A_NNTP) {
3294 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
3295 gtk_check_menu_item_set_active
3296 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3297 gtk_widget_set_sensitive(menuitem, FALSE);
3298 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3299 gtk_check_menu_item_set_active
3300 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3301 gtk_widget_set_sensitive(menuitem, FALSE);
3304 if (account->set_autocc && account->auto_cc) {
3305 compose->use_cc = TRUE;
3306 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
3307 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3308 gtk_check_menu_item_set_active
3309 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3312 if (account->set_autobcc) {
3313 compose->use_bcc = TRUE;
3314 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
3315 gtk_check_menu_item_set_active
3316 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3317 if (account->auto_bcc)
3318 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
3321 if (account->set_autoreplyto) {
3322 compose->use_replyto = TRUE;
3323 menuitem = gtk_item_factory_get_item(ifactory,
3324 "/Message/Reply to");
3325 gtk_check_menu_item_set_active
3326 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3327 if (account->auto_replyto)
3328 gtk_entry_set_text(GTK_ENTRY(reply_entry),
3329 account->auto_replyto);
3332 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
3333 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3334 prefs_common.show_ruler);
3337 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
3338 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3339 prefs_common.default_sign);
3340 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
3341 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3342 prefs_common.default_encrypt);
3343 #endif /* USE_GPGME */
3345 addressbook_set_target_compose(compose);
3347 compose_list = g_list_append(compose_list, compose);
3350 compose->use_to = FALSE;
3351 compose->use_cc = FALSE;
3353 compose->use_attach = FALSE;
3355 if (!compose->use_bcc) {
3356 gtk_widget_hide(bcc_hbox);
3357 gtk_widget_hide(bcc_entry);
3358 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
3360 if (!compose->use_replyto) {
3361 gtk_widget_hide(reply_hbox);
3362 gtk_widget_hide(reply_entry);
3363 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
3365 if (!compose->use_followupto) {
3366 gtk_widget_hide(followup_hbox);
3367 gtk_widget_hide(followup_entry);
3368 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
3371 if (!prefs_common.show_ruler)
3372 gtk_widget_hide(ruler_hbox);
3374 select_account(compose, account);
3379 #include "pixmaps/stock_mail_send.xpm"
3380 #include "pixmaps/stock_mail_send_queue.xpm"
3381 #include "pixmaps/stock_mail.xpm"
3382 #include "pixmaps/stock_paste.xpm"
3383 #include "pixmaps/stock_mail_attach.xpm"
3384 #include "pixmaps/stock_mail_compose.xpm"
3385 #include "pixmaps/linewrap.xpm"
3386 #include "pixmaps/tb_address_book.xpm"
3388 #define CREATE_TOOLBAR_ICON(xpm_d) \
3390 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
3391 &container->style->white, \
3393 icon_wid = gtk_pixmap_new(icon, mask); \
3396 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
3401 GtkWidget *icon_wid;
3402 GtkWidget *send_btn;
3403 GtkWidget *sendl_btn;
3404 GtkWidget *draft_btn;
3405 GtkWidget *insert_btn;
3406 GtkWidget *attach_btn;
3408 GtkWidget *exteditor_btn;
3409 GtkWidget *linewrap_btn;
3410 GtkWidget *addrbook_btn;
3412 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
3414 gtk_container_add(GTK_CONTAINER(container), toolbar);
3415 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
3416 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
3417 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
3418 GTK_TOOLBAR_SPACE_LINE);
3420 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
3421 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3425 icon_wid, toolbar_send_cb, compose);
3427 CREATE_TOOLBAR_ICON(stock_mail_send_queue_xpm);
3428 /* CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm); */
3429 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3431 _("Put into queue folder and send later"),
3433 icon_wid, toolbar_send_later_cb,
3436 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3437 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3439 _("Save to draft folder"),
3441 icon_wid, toolbar_draft_cb,
3444 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3446 CREATE_TOOLBAR_ICON(stock_paste_xpm);
3447 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3451 icon_wid, toolbar_insert_cb,
3454 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
3455 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3459 icon_wid, toolbar_attach_cb,
3462 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3464 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3465 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3467 _("Insert signature"),
3469 icon_wid, toolbar_sig_cb, compose);
3471 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3473 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
3474 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3476 _("Edit with external editor"),
3479 toolbar_ext_editor_cb,
3482 CREATE_TOOLBAR_ICON(linewrap_xpm);
3483 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3485 _("Wrap long lines"),
3488 toolbar_linewrap_cb,
3491 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3493 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
3494 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3498 icon_wid, toolbar_address_cb,
3501 compose->toolbar = toolbar;
3502 compose->send_btn = send_btn;
3503 compose->sendl_btn = sendl_btn;
3504 compose->draft_btn = draft_btn;
3505 compose->insert_btn = insert_btn;
3506 compose->attach_btn = attach_btn;
3507 compose->sig_btn = sig_btn;
3508 compose->exteditor_btn = exteditor_btn;
3509 compose->linewrap_btn = linewrap_btn;
3510 compose->addrbook_btn = addrbook_btn;
3512 gtk_widget_show_all(toolbar);
3515 #undef CREATE_TOOLBAR_ICON
3517 static GtkWidget *compose_account_option_menu_create(Compose *compose)
3523 gint num = 0, def_menu = 0;
3525 accounts = account_get_list();
3526 g_return_val_if_fail(accounts != NULL, NULL);
3528 hbox = gtk_hbox_new(FALSE, 0);
3529 optmenu = gtk_option_menu_new();
3530 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3531 menu = gtk_menu_new();
3533 for (; accounts != NULL; accounts = accounts->next, num++) {
3534 PrefsAccount *ac = (PrefsAccount *)accounts->data;
3535 GtkWidget *menuitem;
3538 if (ac == compose->account) def_menu = num;
3540 name = g_strdup_printf("%s: %s <%s>",
3541 ac->account_name, ac->name, ac->address);
3542 MENUITEM_ADD(menu, menuitem, name, ac);
3544 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
3545 GTK_SIGNAL_FUNC(account_activated),
3549 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
3550 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
3555 static void compose_destroy(Compose *compose)
3558 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3561 /* NOTE: address_completion_end() does nothing with the window
3562 * however this may change. */
3563 address_completion_end(compose->window);
3565 slist_free_strings(compose->to_list);
3566 g_slist_free(compose->to_list);
3567 slist_free_strings(compose->newsgroup_list);
3568 g_slist_free(compose->newsgroup_list);
3570 procmsg_msginfo_free(compose->targetinfo);
3572 g_free(compose->replyto);
3573 g_free(compose->cc);
3574 g_free(compose->bcc);
3575 g_free(compose->newsgroups);
3576 g_free(compose->followup_to);
3578 g_free(compose->inreplyto);
3579 g_free(compose->references);
3580 g_free(compose->msgid);
3581 g_free(compose->boundary);
3583 g_free(compose->exteditor_file);
3585 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3587 compose_attach_info_free(ainfo);
3589 if (addressbook_get_target_compose() == compose)
3590 addressbook_set_target_compose(NULL);
3592 prefs_common.compose_width = compose->scrolledwin->allocation.width;
3593 prefs_common.compose_height = compose->window->allocation.height;
3595 gtk_widget_destroy(compose->paned);
3599 compose_list = g_list_remove(compose_list, compose);
3602 static void compose_attach_info_free(AttachInfo *ainfo)
3604 g_free(ainfo->file);
3605 g_free(ainfo->content_type);
3606 g_free(ainfo->name);
3610 static void compose_attach_remove_selected(Compose *compose)
3612 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3616 while (clist->selection != NULL) {
3617 row = GPOINTER_TO_INT(clist->selection->data);
3618 ainfo = gtk_clist_get_row_data(clist, row);
3619 compose_attach_info_free(ainfo);
3620 gtk_clist_remove(clist, row);
3624 static struct _AttachProperty
3627 GtkWidget *mimetype_entry;
3628 GtkWidget *encoding_optmenu;
3629 GtkWidget *path_entry;
3630 GtkWidget *filename_entry;
3632 GtkWidget *cancel_btn;
3635 static void compose_attach_property(Compose *compose)
3637 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3640 GtkOptionMenu *optmenu;
3641 static gboolean cancelled;
3643 if (!clist->selection) return;
3644 row = GPOINTER_TO_INT(clist->selection->data);
3646 ainfo = gtk_clist_get_row_data(clist, row);
3649 if (!attach_prop.window)
3650 compose_attach_property_create(&cancelled);
3651 gtk_widget_grab_focus(attach_prop.ok_btn);
3652 gtk_widget_show(attach_prop.window);
3653 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
3655 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
3656 if (ainfo->encoding == ENC_UNKNOWN)
3657 gtk_option_menu_set_history(optmenu, ENC_BASE64);
3659 gtk_option_menu_set_history(optmenu, ainfo->encoding);
3661 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
3662 ainfo->content_type ? ainfo->content_type : "");
3663 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
3664 ainfo->file ? ainfo->file : "");
3665 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
3666 ainfo->name ? ainfo->name : "");
3670 gchar *cnttype = NULL;
3674 GtkWidget *menuitem;
3679 if (cancelled == TRUE) {
3680 gtk_widget_hide(attach_prop.window);
3684 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
3685 if (*text != '\0') {
3688 text = g_strstrip(g_strdup(text));
3689 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
3690 cnttype = g_strdup(text);
3693 alertpanel_error(_("Invalid MIME type."));
3699 menu = gtk_option_menu_get_menu(optmenu);
3700 menuitem = gtk_menu_get_active(GTK_MENU(menu));
3701 ainfo->encoding = GPOINTER_TO_INT
3702 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
3704 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
3705 if (*text != '\0') {
3706 if (is_file_exist(text) &&
3707 (size = get_file_size(text)) > 0)
3708 file = g_strdup(text);
3711 (_("File doesn't exist or is empty."));
3717 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
3718 if (*text != '\0') {
3719 g_free(ainfo->name);
3720 ainfo->name = g_strdup(text);
3724 g_free(ainfo->content_type);
3725 ainfo->content_type = cnttype;
3728 g_free(ainfo->file);
3734 gtk_clist_set_text(clist, row, COL_MIMETYPE,
3735 ainfo->content_type);
3736 gtk_clist_set_text(clist, row, COL_SIZE,
3737 to_human_readable(ainfo->size));
3738 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
3740 gtk_widget_hide(attach_prop.window);
3745 #define SET_LABEL_AND_ENTRY(str, entry, top) \
3747 label = gtk_label_new(str); \
3748 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
3749 GTK_FILL, 0, 0, 0); \
3750 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
3752 entry = gtk_entry_new(); \
3753 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
3754 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
3757 static void compose_attach_property_create(gboolean *cancelled)
3763 GtkWidget *mimetype_entry;
3766 GtkWidget *optmenu_menu;
3767 GtkWidget *menuitem;
3768 GtkWidget *path_entry;
3769 GtkWidget *filename_entry;
3772 GtkWidget *cancel_btn;
3773 GList *mime_type_list, *strlist;
3775 debug_print("Creating attach_property window...\n");
3777 window = gtk_window_new(GTK_WINDOW_DIALOG);
3778 gtk_widget_set_usize(window, 480, -1);
3779 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
3780 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
3781 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
3782 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
3783 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3784 GTK_SIGNAL_FUNC(attach_property_delete_event),
3786 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
3787 GTK_SIGNAL_FUNC(attach_property_key_pressed),
3790 vbox = gtk_vbox_new(FALSE, 8);
3791 gtk_container_add(GTK_CONTAINER(window), vbox);
3793 table = gtk_table_new(4, 2, FALSE);
3794 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
3795 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
3796 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
3798 label = gtk_label_new(_("MIME type"));
3799 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
3801 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3802 mimetype_entry = gtk_combo_new();
3803 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
3804 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3806 /* stuff with list */
3807 mime_type_list = procmime_get_mime_type_list();
3809 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
3810 MimeType *type = (MimeType *) mime_type_list->data;
3811 strlist = g_list_append(strlist,
3812 g_strdup_printf("%s/%s",
3813 type->type, type->sub_type));
3816 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
3818 for (mime_type_list = strlist; mime_type_list != NULL;
3819 mime_type_list = mime_type_list->next)
3820 g_free(mime_type_list->data);
3821 g_list_free(strlist);
3823 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
3825 label = gtk_label_new(_("Encoding"));
3826 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
3828 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3830 hbox = gtk_hbox_new(FALSE, 0);
3831 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
3832 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3834 optmenu = gtk_option_menu_new();
3835 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3837 optmenu_menu = gtk_menu_new();
3838 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
3839 gtk_widget_set_sensitive(menuitem, FALSE);
3840 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
3841 gtk_widget_set_sensitive(menuitem, FALSE);
3842 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
3843 gtk_widget_set_sensitive(menuitem, FALSE);
3844 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
3846 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
3848 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
3849 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
3851 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
3852 &cancel_btn, _("Cancel"), NULL, NULL);
3853 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
3854 gtk_widget_grab_default(ok_btn);
3856 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
3857 GTK_SIGNAL_FUNC(attach_property_ok),
3859 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
3860 GTK_SIGNAL_FUNC(attach_property_cancel),
3863 gtk_widget_show_all(vbox);
3865 attach_prop.window = window;
3866 attach_prop.mimetype_entry = mimetype_entry;
3867 attach_prop.encoding_optmenu = optmenu;
3868 attach_prop.path_entry = path_entry;
3869 attach_prop.filename_entry = filename_entry;
3870 attach_prop.ok_btn = ok_btn;
3871 attach_prop.cancel_btn = cancel_btn;
3874 #undef SET_LABEL_AND_ENTRY
3876 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
3882 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
3888 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
3889 gboolean *cancelled)
3897 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
3898 gboolean *cancelled)
3900 if (event && event->keyval == GDK_Escape) {
3906 static void compose_exec_ext_editor(Compose *compose)
3912 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
3913 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3915 if (pipe(pipe_fds) < 0) {
3920 if ((pid = fork()) < 0) {
3926 /* close the write side of the pipe */
3929 compose->exteditor_file = g_strdup(tmp);
3930 compose->exteditor_pid = pid;
3931 compose->exteditor_readdes = pipe_fds[0];
3933 compose_set_ext_editor_sensitive(compose, FALSE);
3935 compose->exteditor_tag =
3936 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
3937 compose_input_cb, compose);
3938 } else { /* process-monitoring process */
3944 /* close the read side of the pipe */
3947 if (compose_write_body_to_file(compose, tmp) < 0) {
3948 fd_write(pipe_fds[1], "2\n", 2);
3952 pid_ed = compose_exec_ext_editor_real(tmp);
3954 fd_write(pipe_fds[1], "1\n", 2);
3958 /* wait until editor is terminated */
3959 waitpid(pid_ed, NULL, 0);
3961 fd_write(pipe_fds[1], "0\n", 2);
3968 static gint compose_exec_ext_editor_real(const gchar *file)
3970 static gchar *def_cmd = "emacs %s";
3976 g_return_val_if_fail(file != NULL, -1);
3978 if ((pid = fork()) < 0) {
3983 if (pid != 0) return pid;
3985 /* grandchild process */
3987 if (setpgid(0, getppid()))
3990 if (prefs_common.ext_editor_cmd &&
3991 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
3992 *(p + 1) == 's' && !strchr(p + 2, '%')) {
3993 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
3995 if (prefs_common.ext_editor_cmd)
3996 g_warning(_("External editor command line is invalid: `%s'\n"),
3997 prefs_common.ext_editor_cmd);
3998 g_snprintf(buf, sizeof(buf), def_cmd, file);
4001 cmdline = g_strsplit(buf, " ", 1024);
4002 execvp(cmdline[0], cmdline);
4005 g_strfreev(cmdline);
4010 static gboolean compose_ext_editor_kill(Compose *compose)
4012 pid_t pgid = compose->exteditor_pid * -1;
4015 ret = kill(pgid, 0);
4017 if (ret == 0 || (ret == -1 && EPERM == errno)) {
4021 msg = g_strdup_printf
4022 (_("The external editor is still working.\n"
4023 "Force terminating the process?\n"
4024 "process group id: %d"), -pgid);
4025 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
4028 if (val == G_ALERTDEFAULT) {
4029 gdk_input_remove(compose->exteditor_tag);
4030 close(compose->exteditor_readdes);
4032 if (kill(pgid, SIGTERM) < 0) perror("kill");
4033 waitpid(compose->exteditor_pid, NULL, 0);
4035 g_warning(_("Terminated process group id: %d"), -pgid);
4036 g_warning(_("Temporary file: %s"),
4037 compose->exteditor_file);
4039 compose_set_ext_editor_sensitive(compose, TRUE);
4041 g_free(compose->exteditor_file);
4042 compose->exteditor_file = NULL;
4043 compose->exteditor_pid = -1;
4044 compose->exteditor_readdes = -1;
4045 compose->exteditor_tag = -1;
4053 static void compose_input_cb(gpointer data, gint source,
4054 GdkInputCondition condition)
4057 Compose *compose = (Compose *)data;
4060 debug_print(_("Compose: input from monitoring process\n"));
4062 gdk_input_remove(compose->exteditor_tag);
4065 if (read(source, &buf[i], 1) < 1) {
4069 if (buf[i] == '\n') {
4074 if (i == sizeof(buf) - 1)
4078 waitpid(compose->exteditor_pid, NULL, 0);
4080 if (buf[0] == '0') { /* success */
4081 GtkSText *text = GTK_STEXT(compose->text);
4083 gtk_stext_freeze(text);
4084 gtk_stext_set_point(text, 0);
4085 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
4086 compose_insert_file(compose, compose->exteditor_file);
4087 compose_changed_cb(NULL, compose);
4088 gtk_stext_thaw(text);
4090 if (unlink(compose->exteditor_file) < 0)
4091 FILE_OP_ERROR(compose->exteditor_file, "unlink");
4092 } else if (buf[0] == '1') { /* failed */
4093 g_warning(_("Couldn't exec external editor\n"));
4094 if (unlink(compose->exteditor_file) < 0)
4095 FILE_OP_ERROR(compose->exteditor_file, "unlink");
4096 } else if (buf[0] == '2') {
4097 g_warning(_("Couldn't write to file\n"));
4098 } else if (buf[0] == '3') {
4099 g_warning(_("Pipe read failed\n"));
4104 compose_set_ext_editor_sensitive(compose, TRUE);
4106 g_free(compose->exteditor_file);
4107 compose->exteditor_file = NULL;
4108 compose->exteditor_pid = -1;
4109 compose->exteditor_readdes = -1;
4110 compose->exteditor_tag = -1;
4113 static void compose_set_ext_editor_sensitive(Compose *compose,
4116 GtkItemFactory *ifactory;
4118 ifactory = gtk_item_factory_from_widget(compose->menubar);
4120 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
4121 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
4122 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
4124 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
4125 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
4126 menu_set_sensitive(ifactory, "/Edit/Wrap long lines", sensitive);
4127 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
4130 gtk_widget_set_sensitive(compose->text, sensitive);
4131 gtk_widget_set_sensitive(compose->send_btn, sensitive);
4132 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
4133 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
4134 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
4135 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
4136 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
4137 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
4140 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
4144 cursor_pos = (text->cursor_pos_x - extra) / char_width;
4145 cursor_pos = MAX(cursor_pos, 0);
4150 /* callback functions */
4152 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
4153 * includes "non-client" (windows-izm) in calculation, so this calculation
4154 * may not be accurate.
4156 static gboolean compose_edit_size_alloc(GtkEditable *widget,
4157 GtkAllocation *allocation,
4158 GtkSHRuler *shruler)
4160 if (prefs_common.show_ruler) {
4162 gint line_width_in_chars;
4164 char_width = gtkut_get_font_width
4165 (GTK_WIDGET(widget)->style->font);
4166 line_width_in_chars =
4167 (allocation->width - allocation->x) / char_width;
4169 /* got the maximum */
4170 gtk_ruler_set_range(GTK_RULER(shruler),
4171 0.0, line_width_in_chars,
4172 calc_cursor_xpos(GTK_STEXT(widget),
4175 /*line_width_in_chars*/ char_width);
4181 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
4183 compose_send_cb(data, 0, NULL);
4186 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
4188 compose_send_later_cb(data, 0, NULL);
4191 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
4193 compose_draft_cb(data, 0, NULL);
4196 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
4198 compose_insert_file_cb(data, 0, NULL);
4201 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
4203 compose_attach_cb(data, 0, NULL);
4206 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
4208 Compose *compose = (Compose *)data;
4210 compose_insert_sig(compose);
4213 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
4215 Compose *compose = (Compose *)data;
4217 compose_exec_ext_editor(compose);
4220 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
4222 Compose *compose = (Compose *)data;
4224 compose_wrap_line(compose);
4227 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
4229 compose_address_cb(data, 0, NULL);
4232 static void select_account(Compose * compose, PrefsAccount * ac)
4234 compose->account = ac;
4235 compose_set_title(compose);
4237 if (ac->protocol == A_NNTP) {
4238 GtkItemFactory *ifactory;
4239 GtkWidget *menuitem;
4241 ifactory = gtk_item_factory_from_widget(compose->menubar);
4242 menu_set_sensitive(ifactory,
4243 "/Message/Followup to", TRUE);
4245 gtk_widget_show(compose->newsgroups_hbox);
4246 gtk_widget_show(compose->newsgroups_entry);
4247 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4250 compose->use_to = FALSE;
4251 compose->use_cc = FALSE;
4253 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4254 gtk_check_menu_item_set_active
4255 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
4256 menu_set_sensitive(ifactory,
4257 "/Message/To", TRUE);
4258 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4259 gtk_check_menu_item_set_active
4260 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
4262 gtk_widget_hide(compose->to_hbox);
4263 gtk_widget_hide(compose->to_entry);
4264 gtk_widget_hide(compose->cc_hbox);
4265 gtk_widget_hide(compose->cc_entry);
4267 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4269 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4273 GtkItemFactory *ifactory;
4274 GtkWidget *menuitem;
4276 ifactory = gtk_item_factory_from_widget(compose->menubar);
4277 menu_set_sensitive(ifactory,
4278 "/Message/Followup to", FALSE);
4280 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
4281 gtk_widget_hide(compose->newsgroups_hbox);
4282 gtk_widget_hide(compose->newsgroups_entry);
4283 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4286 compose->use_to = TRUE;
4287 compose->use_cc = TRUE;
4289 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4290 gtk_check_menu_item_set_active
4291 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4292 menu_set_sensitive(ifactory,
4293 "/Message/To", FALSE);
4294 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4295 gtk_check_menu_item_set_active
4296 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4298 gtk_widget_show(compose->to_hbox);
4299 gtk_widget_show(compose->to_entry);
4300 gtk_widget_show(compose->cc_hbox);
4301 gtk_widget_show(compose->cc_entry);
4303 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4305 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4308 gtk_widget_queue_resize(compose->table_vbox);
4311 static void account_activated(GtkMenuItem *menuitem, gpointer data)
4313 Compose *compose = (Compose *)data;
4317 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
4318 g_return_if_fail(ac != NULL);
4320 if (ac != compose->account)
4321 select_account(compose, ac);
4324 static void attach_selected(GtkCList *clist, gint row, gint column,
4325 GdkEvent *event, gpointer data)
4327 Compose *compose = (Compose *)data;
4329 if (event && event->type == GDK_2BUTTON_PRESS)
4330 compose_attach_property(compose);
4333 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
4336 Compose *compose = (Compose *)data;
4337 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4342 if (event->button == 3) {
4343 if ((clist->selection && !clist->selection->next) ||
4344 !clist->selection) {
4345 gtk_clist_unselect_all(clist);
4346 if (gtk_clist_get_selection_info(clist,
4349 gtk_clist_select_row(clist, row, column);
4350 gtkut_clist_set_focus_row(clist, row);
4353 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
4354 NULL, NULL, event->button, event->time);
4358 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
4361 Compose *compose = (Compose *)data;
4365 switch (event->keyval) {
4367 compose_attach_remove_selected(compose);
4372 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
4374 Compose *compose = (Compose *)data;
4377 val = compose_send(compose);
4379 if (val == 0) gtk_widget_destroy(compose->window);
4382 static void compose_send_later_cb(gpointer data, guint action,
4385 Compose *compose = (Compose *)data;
4387 gchar *to, *newsgroups;
4389 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
4390 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
4391 if (*to == '\0' && *newsgroups == '\0') {
4392 alertpanel_error(_("Recipient is not specified."));
4396 g_snprintf(tmp, 22, "%s%ctmpmsg%d",
4397 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
4399 if (prefs_common.linewrap_at_send)
4400 compose_wrap_line(compose);
4402 if (compose_write_to_file(compose, tmp, FALSE) < 0 ||
4403 compose_queue(compose, tmp) < 0) {
4404 alertpanel_error(_("Can't queue the message."));
4408 if (prefs_common.savemsg) {
4409 if (compose_save_to_outbox(compose, tmp) < 0)
4411 (_("Can't save the message to outbox."));
4414 if (unlink(tmp) < 0)
4415 FILE_OP_ERROR(tmp, "unlink");
4417 gtk_widget_destroy(compose->window);
4420 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
4422 Compose *compose = (Compose *)data;
4426 draft = folder_get_default_draft();
4427 folder_item_scan(draft);
4429 if (procmsg_msg_exist(compose->targetinfo) &&
4430 compose->targetinfo->folder == draft) {
4431 if (folder_item_remove_msg(draft,
4432 compose->targetinfo->msgnum) < 0)
4433 g_warning(_("can't remove the old draft message\n"));
4435 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
4436 G_DIR_SEPARATOR, (gint)compose);
4438 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
4443 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
4451 /* folderview_scan_folder_a(DRAFT_DIR, TRUE); */
4453 gtk_widget_destroy(compose->window);
4456 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
4458 Compose *compose = (Compose *)data;
4461 file_list = filesel_select_multiple_files(_("Select file"), NULL);
4466 for ( tmp = file_list; tmp; tmp = tmp->next) {
4467 gchar *file = (gchar *) tmp->data;
4468 compose_attach_append(compose, file, MIME_UNKNOWN);
4471 g_list_free(file_list);
4475 static void compose_insert_file_cb(gpointer data, guint action,
4478 Compose *compose = (Compose *)data;
4481 file_list = filesel_select_multiple_files(_("Select file"), NULL);
4486 for ( tmp = file_list; tmp; tmp = tmp->next) {
4487 gchar *file = (gchar *) tmp->data;
4488 compose_insert_file(compose, file);
4491 g_list_free(file_list);
4495 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
4498 compose_close_cb(data, 0, NULL);
4502 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
4504 Compose *compose = (Compose *)data;
4507 if (compose->exteditor_tag != -1) {
4508 if (!compose_ext_editor_kill(compose))
4512 if (compose->modified) {
4513 val = alertpanel(_("Discard message"),
4514 _("This message has been modified. discard it?"),
4515 _("Discard"), _("to Draft"), _("Cancel"));
4518 case G_ALERTDEFAULT:
4520 case G_ALERTALTERNATE:
4521 compose_draft_cb(data, 0, NULL);
4528 gtk_widget_destroy(compose->window);
4531 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
4533 Compose *compose = (Compose *)data;
4535 addressbook_open(compose);
4538 static void compose_ext_editor_cb(gpointer data, guint action,
4541 Compose *compose = (Compose *)data;
4543 compose_exec_ext_editor(compose);
4546 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
4548 compose_destroy(compose);
4551 static void compose_cut_cb(Compose *compose)
4553 if (compose->focused_editable &&
4554 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4555 gtk_editable_cut_clipboard
4556 (GTK_EDITABLE(compose->focused_editable));
4559 static void compose_copy_cb(Compose *compose)
4561 if (compose->focused_editable &&
4562 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4563 gtk_editable_copy_clipboard
4564 (GTK_EDITABLE(compose->focused_editable));
4567 static void compose_paste_cb(Compose *compose)
4569 if (compose->focused_editable &&
4570 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4571 gtk_editable_paste_clipboard
4572 (GTK_EDITABLE(compose->focused_editable));
4575 static void compose_allsel_cb(Compose *compose)
4577 if (compose->focused_editable &&
4578 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4579 gtk_editable_select_region
4580 (GTK_EDITABLE(compose->focused_editable), 0, -1);
4583 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
4585 if (GTK_IS_EDITABLE(widget))
4586 compose->focused_editable = widget;
4589 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
4591 if (compose->modified == FALSE) {
4592 compose->modified = TRUE;
4593 compose_set_title(compose);
4597 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
4600 gtk_stext_set_point(GTK_STEXT(widget),
4601 gtk_editable_get_position(GTK_EDITABLE(widget)));
4605 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
4608 gtk_stext_set_point(GTK_STEXT(widget),
4609 gtk_editable_get_position(GTK_EDITABLE(widget)));
4613 static void compose_toggle_to_cb(gpointer data, guint action,
4616 Compose *compose = (Compose *)data;
4618 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4619 gtk_widget_show(compose->to_hbox);
4620 gtk_widget_show(compose->to_entry);
4621 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
4622 compose->use_to = TRUE;
4624 gtk_widget_hide(compose->to_hbox);
4625 gtk_widget_hide(compose->to_entry);
4626 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
4627 gtk_widget_queue_resize(compose->table_vbox);
4628 compose->use_to = FALSE;
4631 if (addressbook_get_target_compose() == compose)
4632 addressbook_set_target_compose(compose);
4635 static void compose_toggle_cc_cb(gpointer data, guint action,
4638 Compose *compose = (Compose *)data;
4640 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4641 gtk_widget_show(compose->cc_hbox);
4642 gtk_widget_show(compose->cc_entry);
4643 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
4644 compose->use_cc = TRUE;
4646 gtk_widget_hide(compose->cc_hbox);
4647 gtk_widget_hide(compose->cc_entry);
4648 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
4649 gtk_widget_queue_resize(compose->table_vbox);
4650 compose->use_cc = FALSE;
4653 if (addressbook_get_target_compose() == compose)
4654 addressbook_set_target_compose(compose);
4657 static void compose_toggle_bcc_cb(gpointer data, guint action,
4660 Compose *compose = (Compose *)data;
4662 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4663 gtk_widget_show(compose->bcc_hbox);
4664 gtk_widget_show(compose->bcc_entry);
4665 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
4666 compose->use_bcc = TRUE;
4668 gtk_widget_hide(compose->bcc_hbox);
4669 gtk_widget_hide(compose->bcc_entry);
4670 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
4671 gtk_widget_queue_resize(compose->table_vbox);
4672 compose->use_bcc = FALSE;
4675 if (addressbook_get_target_compose() == compose)
4676 addressbook_set_target_compose(compose);
4679 static void compose_toggle_replyto_cb(gpointer data, guint action,
4682 Compose *compose = (Compose *)data;
4684 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4685 gtk_widget_show(compose->reply_hbox);
4686 gtk_widget_show(compose->reply_entry);
4687 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
4688 compose->use_replyto = TRUE;
4690 gtk_widget_hide(compose->reply_hbox);
4691 gtk_widget_hide(compose->reply_entry);
4692 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
4693 gtk_widget_queue_resize(compose->table_vbox);
4694 compose->use_replyto = FALSE;
4698 static void compose_toggle_followupto_cb(gpointer data, guint action,
4701 Compose *compose = (Compose *)data;
4703 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4704 gtk_widget_show(compose->followup_hbox);
4705 gtk_widget_show(compose->followup_entry);
4706 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
4707 compose->use_followupto = TRUE;
4709 gtk_widget_hide(compose->followup_hbox);
4710 gtk_widget_hide(compose->followup_entry);
4711 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
4712 gtk_widget_queue_resize(compose->table_vbox);
4713 compose->use_followupto = FALSE;
4717 static void compose_toggle_attach_cb(gpointer data, guint action,
4720 Compose *compose = (Compose *)data;
4722 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4723 gtk_widget_ref(compose->edit_vbox);
4725 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4726 compose->edit_vbox);
4727 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
4728 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
4730 gtk_widget_show(compose->paned);
4732 gtk_widget_unref(compose->edit_vbox);
4733 gtk_widget_unref(compose->paned);
4735 compose->use_attach = TRUE;
4737 gtk_widget_ref(compose->paned);
4738 gtk_widget_ref(compose->edit_vbox);
4740 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4742 gtk_container_remove(GTK_CONTAINER(compose->paned),
4743 compose->edit_vbox);
4744 gtk_box_pack_start(GTK_BOX(compose->vbox2),
4745 compose->edit_vbox, TRUE, TRUE, 0);
4747 gtk_widget_unref(compose->edit_vbox);
4749 compose->use_attach = FALSE;
4754 static void compose_toggle_sign_cb(gpointer data, guint action,
4757 Compose *compose = (Compose *)data;
4759 if (GTK_CHECK_MENU_ITEM(widget)->active)
4760 compose->use_signing = TRUE;
4762 compose->use_signing = FALSE;
4765 static void compose_toggle_encrypt_cb(gpointer data, guint action,
4768 Compose *compose = (Compose *)data;
4770 if (GTK_CHECK_MENU_ITEM(widget)->active)
4771 compose->use_encryption = TRUE;
4773 compose->use_encryption = FALSE;
4775 #endif /* USE_GPGME */
4777 static void compose_toggle_ruler_cb(gpointer data, guint action,
4780 Compose *compose = (Compose *)data;
4782 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4783 gtk_widget_show(compose->ruler_hbox);
4784 prefs_common.show_ruler = TRUE;
4786 gtk_widget_hide(compose->ruler_hbox);
4787 gtk_widget_queue_resize(compose->edit_vbox);
4788 prefs_common.show_ruler = FALSE;
4792 static void compose_attach_drag_received_cb (GtkWidget *widget,
4793 GdkDragContext *drag_context,
4796 GtkSelectionData *data,
4801 Compose *compose = (Compose *)user_data;
4804 list = uri_list_extract_filenames((const gchar *)data->data);
4805 for (tmp = list; tmp != NULL; tmp = tmp->next)
4806 compose_attach_append(compose, (const gchar *)tmp->data,
4808 list_free_strings(list);
4812 static void compose_insert_drag_received_cb (GtkWidget *widget,
4813 GdkDragContext *drag_context,
4816 GtkSelectionData *data,
4821 Compose *compose = (Compose *)user_data;
4824 list = uri_list_extract_filenames((const gchar *)data->data);
4825 for (tmp = list; tmp != NULL; tmp = tmp->next)
4826 compose_insert_file(compose, (const gchar *)tmp->data);
4827 list_free_strings(list);
4831 static void to_activated(GtkWidget *widget, Compose *compose)
4833 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
4834 gtk_widget_grab_focus(compose->newsgroups_entry);
4836 gtk_widget_grab_focus(compose->subject_entry);
4839 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
4841 gtk_widget_grab_focus(compose->subject_entry);
4844 static void subject_activated(GtkWidget *widget, Compose *compose)
4846 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
4847 gtk_widget_grab_focus(compose->cc_entry);
4848 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4849 gtk_widget_grab_focus(compose->bcc_entry);
4850 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4851 gtk_widget_grab_focus(compose->reply_entry);
4852 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4853 gtk_widget_grab_focus(compose->followup_entry);
4855 gtk_widget_grab_focus(compose->text);
4858 static void cc_activated(GtkWidget *widget, Compose *compose)
4860 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4861 gtk_widget_grab_focus(compose->bcc_entry);
4862 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4863 gtk_widget_grab_focus(compose->reply_entry);
4864 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4865 gtk_widget_grab_focus(compose->followup_entry);
4867 gtk_widget_grab_focus(compose->text);
4870 static void bcc_activated(GtkWidget *widget, Compose *compose)
4872 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4873 gtk_widget_grab_focus(compose->reply_entry);
4874 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4875 gtk_widget_grab_focus(compose->followup_entry);
4877 gtk_widget_grab_focus(compose->text);
4880 static void replyto_activated(GtkWidget *widget, Compose *compose)
4882 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4883 gtk_widget_grab_focus(compose->followup_entry);
4885 gtk_widget_grab_focus(compose->text);
4888 static void followupto_activated(GtkWidget *widget, Compose *compose)
4890 gtk_widget_grab_focus(compose->text);
4893 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
4896 Compose *compose = (Compose *)data;
4898 if (GTK_CHECK_MENU_ITEM(widget)->active)
4899 compose->return_receipt = TRUE;
4901 compose->return_receipt = FALSE;
4904 static gchar *compose_quote_fmt (Compose *compose,
4909 gchar * quote_str = NULL;
4911 if (qmark != NULL) {
4914 quote_fmt_init(msginfo, NULL);
4915 quote_fmt_scan_string(qmark);
4918 p = quote_fmt_get_buffer();
4921 (_("Quote mark format error."));
4924 quote_str = alloca(strlen(p) + 1);
4925 strcpy(quote_str, p);
4929 quote_fmt_init(msginfo, quote_str);
4930 quote_fmt_scan_string(fmt);
4933 if (quote_fmt_get_buffer() == NULL)
4935 (_("Message reply/forward format error."));
4937 return quote_fmt_get_buffer();
4940 static void template_apply_cb(gchar *s, gpointer data)
4942 Compose *compose = (Compose*)data;
4943 GtkSText *text = GTK_STEXT(compose->text);
4948 gchar *old_tmpl = s;
4952 if(compose->replyinfo == NULL) {
4953 gtk_stext_freeze(text);
4954 gtk_stext_set_point(text, 0);
4955 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
4956 gtk_stext_insert(text, NULL, NULL, NULL, s, -1);
4957 gtk_stext_thaw(text);
4962 parsed_text = g_new(gchar, strlen(s)*2 + 1);
4966 *parsed_text++ = '\\';
4967 *parsed_text++ = 'n';
4970 *parsed_text++ = *s++;
4973 *parsed_text = '\0';
4975 if (prefs_common.quotemark && *prefs_common.quotemark)
4976 qmark = prefs_common.quotemark;
4980 quote_str = compose_quote_fmt(compose, compose->replyinfo, tmpl, qmark);
4981 if (quote_str != NULL) {
4982 gtk_stext_freeze(text);
4983 gtk_stext_set_point(text, 0);
4984 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
4985 gtk_stext_insert(text, NULL, NULL, NULL, quote_str, -1);
4986 gtk_stext_thaw(text);
4993 static void template_select_cb(gpointer data, guint action,
4996 template_select(&template_apply_cb, data);