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) account = cur_account;
593 g_return_if_fail(account != NULL);
595 if (ignore_replyto && account->protocol == A_NNTP &&
596 !followup_and_reply_to) {
598 account_find_from_address(account->address);
600 reply_account = compose_current_mail_account();
604 reply_account = account;
605 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
606 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
608 CHANGE_FLAGS(msginfo);
610 compose = compose_create(reply_account);
611 compose->mode = COMPOSE_REPLY;
612 compose->replyinfo = msginfo;
615 if (followup_and_reply_to) {
616 gtk_widget_show(compose->to_hbox);
617 gtk_widget_show(compose->to_entry);
618 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
619 compose->use_to = TRUE;
622 if(msginfo->folder && msginfo->folder->prefs->request_return_receipt) {
623 GtkItemFactory *ifactory;
625 ifactory = gtk_item_factory_from_widget(compose->menubar);
626 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
629 if (compose_parse_header(compose, msginfo) < 0) return;
630 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
631 followup_and_reply_to);
633 text = GTK_STEXT(compose->text);
634 gtk_stext_freeze(text);
640 if ((fp = procmime_get_text_part(msginfo)) == NULL)
641 g_warning(_("Can't get text part\n"));
645 if (prefs_common.quotemark && *prefs_common.quotemark)
646 qmark = prefs_common.quotemark;
650 quote_str = compose_quote_fmt(compose, msginfo,
651 prefs_common.quotefmt,
655 quote_str = compose_quote_parse_fmt
656 (compose, msginfo, prefs_common.quotefmt);
659 if (quote_str != NULL)
660 gtk_stext_insert(text, NULL, NULL, NULL,
662 /* g_free(quote_str); */
663 /* compose_quote_file(compose, msginfo, fp); */
668 if (prefs_common.auto_sig)
669 compose_insert_sig(compose);
670 gtk_editable_set_position(GTK_EDITABLE(text), 0);
671 gtk_stext_set_point(text, 0);
673 gtk_stext_thaw(text);
674 gtk_widget_grab_focus(compose->text);
678 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
683 g_return_val_if_fail(mimeinfo != NULL, NULL);
685 base = mimeinfo->filename ? mimeinfo->filename
686 : mimeinfo->name ? mimeinfo->name : NULL;
688 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
689 filename = g_strdup_printf("%s%smimetmp%i.html",
696 base = base ? base : "";
697 base = g_basename(base);
699 filename = g_strdup_printf("%s%smimetmp%i",
707 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
713 static gchar * mime_extract_file(gchar * source, MimeInfo *partinfo)
717 if (!partinfo) return;
719 filename = procmime_get_file_name(partinfo);
721 if (procmime_get_part(filename, source, partinfo) < 0)
723 (_("Can't get the part of multipart message."));
728 static void compose_attach_parts(Compose * compose,
738 gint boundary_len = 0;
740 glong fpos, prev_fpos;
745 g_return_if_fail(msginfo != NULL);
749 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
750 mimeinfo = procmime_scan_mime_header(fp);
751 if (!mimeinfo) break;
753 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
754 rfc2015_is_encrypted(mimeinfo)) {
755 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
757 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
758 !msginfo->plaintext_file &&
759 !msginfo->decryption_failed) {
760 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
761 if (msginfo->plaintext_file &&
762 !msginfo->decryption_failed) {
770 #else /* !USE_GPGME */
771 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
772 mimeinfo = procmime_scan_mime_header(fp);
773 #endif /* USE_GPGME */
776 if (!mimeinfo) return;
777 if (mimeinfo->mime_type == MIME_TEXT)
780 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
782 g_return_if_fail(mimeinfo != NULL);
783 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
785 if (mimeinfo->mime_type == MIME_MULTIPART) {
786 g_return_if_fail(mimeinfo->boundary != NULL);
787 g_return_if_fail(mimeinfo->sub == NULL);
789 g_return_if_fail(fp != NULL);
791 boundary = mimeinfo->boundary;
794 boundary_len = strlen(boundary);
796 /* look for first boundary */
797 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
798 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
805 if ((fpos = ftell(fp)) < 0) {
811 for (npart = 0;; npart++) {
813 gboolean eom = FALSE;
817 partinfo = procmime_scan_mime_header(fp);
818 if (!partinfo) break;
821 procmime_mimeinfo_insert(mimeinfo, partinfo);
823 procmime_mimeinfo_free(partinfo);
825 /* look for next boundary */
827 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
828 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
829 if (buf[2 + boundary_len] == '-' &&
830 buf[2 + boundary_len + 1] == '-')
836 eom = TRUE; /* broken MIME message */
839 partinfo->size = fpos - prev_fpos - strlen(buf);
844 source = procmsg_get_message_file_path(msginfo);
846 g_return_if_fail(mimeinfo != NULL);
848 if (!mimeinfo->main && mimeinfo->parent)
850 filename = mime_extract_file(source, mimeinfo);
852 compose_attach_append_with_type(compose, filename,
853 mimeinfo->content_type,
854 mimeinfo->mime_type);
859 if (mimeinfo->sub && mimeinfo->sub->children)
861 filename = mime_extract_file(source, mimeinfo->sub);
863 compose_attach_append_with_type(compose, filename,
864 mimeinfo->content_type,
865 mimeinfo->sub->mime_type);
870 if (mimeinfo->children) {
873 child = mimeinfo->children;
875 filename = mime_extract_file(source, child);
877 compose_attach_append_with_type(compose, filename,
889 procmime_mimeinfo_free_all(mimeinfo);
893 #define INSERT_FW_HEADER(var, hdr) \
894 if (msginfo->var && *msginfo->var) { \
895 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
896 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
897 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
900 Compose * compose_forward(PrefsAccount * account, MsgInfo *msginfo,
904 /* PrefsAccount *account; */
909 g_return_val_if_fail(msginfo != NULL, NULL);
910 g_return_val_if_fail(msginfo->folder != NULL, NULL);
912 if (account == NULL) {
913 account = cur_account;
915 account = msginfo->folder->folder->account;
916 if (!account) account = cur_account;
919 g_return_val_if_fail(account != NULL, NULL);
921 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
922 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
923 CHANGE_FLAGS(msginfo);
925 compose = compose_create(account);
926 compose->mode = COMPOSE_FORWARD;
928 if (msginfo->subject && *msginfo->subject) {
929 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
930 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
934 text = GTK_STEXT(compose->text);
935 gtk_stext_freeze(text);
940 msgfile = procmsg_get_message_file_path(msginfo);
941 if (!is_file_exist(msgfile))
942 g_warning(_("%s: file not exist\n"), msgfile);
944 compose_attach_append(compose, msgfile,
945 MIME_MESSAGE_RFC822);
952 if ((fp = procmime_get_text_part(msginfo)) == NULL)
953 g_warning(_("Can't get text part\n"));
957 if (prefs_common.fw_quotemark &&
958 *prefs_common.fw_quotemark)
959 qmark = prefs_common.fw_quotemark;
963 quote_str = compose_quote_fmt(compose, msginfo,
964 prefs_common.fw_quotefmt,
967 if (quote_str != NULL)
968 gtk_stext_insert(text, NULL, NULL, NULL,
974 compose_attach_parts(compose, msginfo);
977 if (prefs_common.auto_sig)
978 compose_insert_sig(compose);
979 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
980 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
982 gtk_stext_thaw(text);
983 if (account->protocol != A_NNTP)
984 gtk_widget_grab_focus(compose->to_entry);
986 gtk_widget_grab_focus(compose->newsgroups_entry);
991 #undef INSERT_FW_HEADER
993 Compose * compose_forward_multiple(PrefsAccount * account,
994 GSList *msginfo_list)
1001 g_return_val_if_fail(msginfo_list != NULL, NULL);
1003 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1004 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1008 if (account == NULL) {
1009 account = cur_account;
1011 account = msginfo->folder->folder->account;
1012 if (!account) account = cur_account;
1015 g_return_val_if_fail(account != NULL, NULL);
1017 compose = compose_create(account);
1018 compose->mode = COMPOSE_FORWARD;
1020 text = GTK_STEXT(compose->text);
1021 gtk_stext_freeze(text);
1023 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1024 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1025 if (!is_file_exist(msgfile))
1026 g_warning(_("%s: file not exist\n"), msgfile);
1028 compose_attach_append(compose, msgfile,
1029 MIME_MESSAGE_RFC822);
1033 if (prefs_common.auto_sig)
1034 compose_insert_sig(compose);
1035 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1036 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1038 gtk_stext_thaw(text);
1039 if (account->protocol != A_NNTP)
1040 gtk_widget_grab_focus(compose->to_entry);
1042 gtk_widget_grab_focus(compose->newsgroups_entry);
1047 void compose_reedit(MsgInfo *msginfo)
1050 PrefsAccount *account;
1053 gchar buf[BUFFSIZE];
1055 g_return_if_fail(msginfo != NULL);
1056 g_return_if_fail(msginfo->folder != NULL);
1058 account = msginfo->folder->folder->account;
1059 if (!account) account = cur_account;
1060 g_return_if_fail(account != NULL);
1062 compose = compose_create(account);
1063 compose->mode = COMPOSE_REEDIT_DRAFT;
1064 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1066 if (compose_parse_header(compose, msginfo) < 0) return;
1067 compose_reedit_set_entry(compose, msginfo);
1069 text = GTK_STEXT(compose->text);
1070 gtk_stext_freeze(text);
1072 if ((fp = procmime_get_text_part(msginfo)) == NULL)
1073 g_warning(_("Can't get text part\n"));
1075 while (fgets(buf, sizeof(buf), fp) != NULL)
1076 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1079 compose_attach_parts(compose, msginfo);
1081 gtk_stext_thaw(text);
1082 gtk_widget_grab_focus(compose->text);
1085 GList *compose_get_compose_list(void)
1087 return compose_list;
1090 void compose_entry_append(Compose *compose, const gchar *address,
1091 ComposeEntryType type)
1096 if (!address || *address == '\0') return;
1100 entry = GTK_ENTRY(compose->cc_entry);
1103 entry = GTK_ENTRY(compose->bcc_entry);
1105 case COMPOSE_NEWSGROUPS:
1106 entry = GTK_ENTRY(compose->newsgroups_entry);
1110 entry = GTK_ENTRY(compose->to_entry);
1114 text = gtk_entry_get_text(entry);
1116 gtk_entry_append_text(entry, ", ");
1117 gtk_entry_append_text(entry, address);
1120 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1122 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1123 {"Cc:", NULL, FALSE},
1124 {"References:", NULL, FALSE},
1125 {"Bcc:", NULL, FALSE},
1126 {"Newsgroups:", NULL, FALSE},
1127 {"Followup-To:", NULL, FALSE},
1128 {NULL, NULL, FALSE}};
1142 g_return_val_if_fail(msginfo != NULL, -1);
1144 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1145 procheader_get_header_fields(fp, hentry);
1148 if (hentry[H_REPLY_TO].body != NULL) {
1149 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1150 compose->replyto = hentry[H_REPLY_TO].body;
1151 hentry[H_REPLY_TO].body = NULL;
1153 if (hentry[H_CC].body != NULL) {
1154 conv_unmime_header_overwrite(hentry[H_CC].body);
1155 compose->cc = hentry[H_CC].body;
1156 hentry[H_CC].body = NULL;
1158 if (hentry[H_REFERENCES].body != NULL) {
1159 if (compose->mode == COMPOSE_REEDIT_DRAFT)
1160 compose->references = hentry[H_REFERENCES].body;
1162 compose->references = compose_parse_references
1163 (hentry[H_REFERENCES].body, msginfo->msgid);
1164 g_free(hentry[H_REFERENCES].body);
1166 hentry[H_REFERENCES].body = NULL;
1168 if (hentry[H_BCC].body != NULL) {
1169 if (compose->mode == COMPOSE_REEDIT_DRAFT) {
1170 conv_unmime_header_overwrite(hentry[H_BCC].body);
1171 compose->bcc = hentry[H_BCC].body;
1173 g_free(hentry[H_BCC].body);
1174 hentry[H_BCC].body = NULL;
1176 if (hentry[H_NEWSGROUPS].body != NULL) {
1177 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1178 hentry[H_NEWSGROUPS].body = NULL;
1180 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1181 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1182 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1183 hentry[H_FOLLOWUP_TO].body = NULL;
1186 if (compose->mode == COMPOSE_REEDIT_DRAFT && msginfo->inreplyto)
1187 compose->inreplyto = g_strdup(msginfo->inreplyto);
1188 else if (compose->mode != COMPOSE_REEDIT_DRAFT &&
1189 msginfo->msgid && *msginfo->msgid) {
1190 compose->inreplyto = g_strdup(msginfo->msgid);
1192 if (!compose->references) {
1193 if (msginfo->inreplyto && *msginfo->inreplyto)
1194 compose->references =
1195 g_strdup_printf("<%s>\n\t<%s>",
1199 compose->references =
1200 g_strconcat("<", msginfo->msgid, ">",
1208 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1210 GSList *ref_id_list, *cur;
1214 ref_id_list = references_list_append(NULL, ref);
1215 if (!ref_id_list) return NULL;
1216 if (msgid && *msgid)
1217 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1222 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1223 /* "<" + Message-ID + ">" + CR+LF+TAB */
1224 len += strlen((gchar *)cur->data) + 5;
1226 if (len > MAX_REFERENCES_LEN) {
1227 /* remove second message-ID */
1228 if (ref_id_list && ref_id_list->next &&
1229 ref_id_list->next->next) {
1230 g_free(ref_id_list->next->data);
1231 ref_id_list = g_slist_remove
1232 (ref_id_list, ref_id_list->next->data);
1234 slist_free_strings(ref_id_list);
1235 g_slist_free(ref_id_list);
1242 new_ref = g_string_new("");
1243 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1244 if (new_ref->len > 0)
1245 g_string_append(new_ref, "\n\t");
1246 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1249 slist_free_strings(ref_id_list);
1250 g_slist_free(ref_id_list);
1252 new_ref_str = new_ref->str;
1253 g_string_free(new_ref, FALSE);
1259 static void compose_quote_file(Compose *compose, MsgInfo *msginfo, FILE *fp)
1261 GtkSText *text = GTK_STEXT(compose->text);
1264 GdkColor *qcolor = NULL;
1265 gchar buf[BUFFSIZE];
1267 gchar *linep, *cur, *leftp;
1268 gint line_len, cur_len;
1273 // if (prefs_common.enable_color) qcolor = "e_color;
1274 if (prefs_common.quotemark && *prefs_common.quotemark)
1275 qmark = prefs_common.quotemark;
1278 quote_str = compose_quote_parse_fmt(compose, msginfo, qmark);
1279 g_return_if_fail(quote_str != NULL);
1280 qlen = strlen(quote_str);
1282 if (!prefs_common.linewrap_quote ||
1283 prefs_common.linewrap_len <= qlen) {
1284 while (fgets(buf, sizeof(buf), fp) != NULL) {
1285 gtk_stext_insert(text, NULL, qcolor, NULL,
1287 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1293 wrap_len = prefs_common.linewrap_len - qlen;
1295 while (fgets(buf, sizeof(buf), fp) != NULL) {
1297 str_len = strlen(buf);
1299 if (str_len <= wrap_len) {
1300 gtk_stext_insert(text, NULL, qcolor, NULL,
1302 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1303 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1307 linep = cur = leftp = buf;
1308 line_len = cur_len = 0;
1310 while (*cur != '\0') {
1311 ch_len = mblen(cur, MB_CUR_MAX);
1312 if (ch_len < 0) ch_len = 1;
1314 if (ch_len == 1 && isspace(*cur)) {
1315 linep = cur + ch_len;
1316 line_len = cur_len + ch_len;
1319 if (cur_len + ch_len > wrap_len && line_len > 0) {
1320 gtk_stext_insert(text, NULL, qcolor, NULL,
1323 if (isspace(*(linep - 1)))
1324 gtk_stext_insert(text, NULL,
1326 leftp, line_len - 1);
1328 gtk_stext_insert(text, NULL,
1331 gtk_stext_insert(text, NULL, NULL, NULL,
1335 cur_len = cur_len - line_len + ch_len;
1342 linep = cur + ch_len;
1343 line_len = cur_len + ch_len;
1350 gtk_stext_insert(text, NULL, qcolor, NULL,
1352 gtk_stext_insert(text, NULL, qcolor, NULL, leftp, -1);
1353 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1362 static gchar *compose_quote_parse_fmt(Compose *compose, MsgInfo *msginfo,
1366 size_t buf_len = 1024;
1374 if (!fmt || *fmt == '\0') return 0;
1376 Xalloca(mbs, sizeof(wchar_t) + 1, return 0);
1377 Xalloca(wcsfmt, (strlen(fmt) + 1) * sizeof(wchar_t), return 0);
1378 mbstowcs(wcsfmt, fmt, strlen(fmt) + 1);
1381 ext_str = g_malloc(sizeof(gchar) * buf_len);
1382 g_return_val_if_fail(ext_str != NULL, NULL);
1387 len = wctomb(mbs, *sp);
1393 wctomb(mbs, *(++sp));
1398 str = msginfo->date;
1402 str = msginfo->from;
1406 if (!msginfo->fromname) {sp++; break;}
1407 p = msginfo->fromname;
1408 tmp[0] = tmp[1] = tmp[2] = '\0';
1410 if (*p && isalnum(*p))
1411 tmp[0] = toupper(*p);
1418 while (*p && !isspace(*p)) p++;
1419 while (*p && isspace(*p)) p++;
1420 if (*p && isalnum(*p))
1421 tmp[1] = toupper(*p);
1424 if (tmp[1]) str = tmp;
1428 str = msginfo->fromname;
1432 if (!msginfo->fromname) {sp++; break;}
1433 Xstrdup_a(str, msginfo->fromname,
1436 while (*p && !isspace(*p)) p++;
1441 str = msginfo->subject;
1453 if (!msginfo->msgid) {sp++; break;}
1454 Xalloca(str, strlen(msginfo->msgid) + 3,
1456 g_snprintf(str, strlen(msginfo->msgid) + 3,
1457 "<%s>", msginfo->msgid);
1469 while (ext_len + strlen(str) + 1 > buf_len)
1471 ext_str = g_realloc(ext_str,
1472 sizeof(gchar) * buf_len);
1473 g_return_val_if_fail(ext_str != NULL, NULL);
1474 strcpy(ext_str + ext_len, str);
1475 ext_len += strlen(str);
1477 } else if (*mbs == '\\') {
1478 wctomb(mbs, *(++sp));
1496 while (ext_len + strlen(str) + 1 > buf_len)
1498 ext_str = g_realloc(ext_str,
1499 sizeof(gchar) * buf_len);
1500 g_return_val_if_fail(ext_str != NULL, NULL);
1501 strcpy(ext_str + ext_len, str);
1502 ext_len += strlen(str);
1506 while (ext_len + len + 1 > buf_len) buf_len += 1024;
1507 ext_str = g_realloc(ext_str, sizeof(gchar) * buf_len);
1508 g_return_val_if_fail(ext_str != NULL, NULL);
1509 strcpy(ext_str + ext_len, mbs);
1516 ext_str = g_realloc(ext_str, strlen(ext_str) + 1);
1522 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1523 gboolean to_all, gboolean ignore_replyto,
1524 gboolean followup_and_reply_to)
1529 GHashTable *to_table;
1531 g_return_if_fail(compose->account != NULL);
1532 g_return_if_fail(msginfo != NULL);
1534 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1535 gtk_entry_set_text(GTK_ENTRY(compose->to_entry),
1536 ( (compose->replyto && !ignore_replyto)
1538 : msginfo->from ? msginfo->from : ""));
1539 if (compose->account->protocol == A_NNTP)
1540 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry),
1541 compose->followup_to ? compose->followup_to
1542 : compose->newsgroups ? compose->newsgroups
1545 if (msginfo->subject && *msginfo->subject) {
1546 gchar *buf, *buf2, *p;
1548 buf = g_strdup(msginfo->subject);
1549 while (!strncasecmp(buf, "Re:", 3)) {
1551 while (isspace(*p)) p++;
1552 memmove(buf, p, strlen(p) + 1);
1555 buf2 = g_strdup_printf("Re: %s", buf);
1556 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1560 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1562 if (!to_all || compose->account->protocol == A_NNTP) return;
1564 from = g_strdup(compose->replyto ? compose->replyto :
1565 msginfo->from ? msginfo->from : "");
1566 extract_address(from);
1568 cc_list = address_list_append(NULL, msginfo->to);
1569 cc_list = address_list_append(cc_list, compose->cc);
1571 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1572 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1573 if (compose->account)
1574 g_hash_table_insert(to_table, compose->account->address,
1575 GINT_TO_POINTER(1));
1577 /* remove address on To: and that of current account */
1578 for (cur = cc_list; cur != NULL; ) {
1579 GSList *next = cur->next;
1581 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1582 cc_list = g_slist_remove(cc_list, cur->data);
1584 g_hash_table_insert(to_table, cur->data, cur);
1588 g_hash_table_destroy(to_table);
1592 for (cur = cc_list; cur != NULL; cur = cur->next)
1593 compose_entry_append(compose, (gchar *)cur->data,
1595 slist_free_strings(cc_list);
1596 g_slist_free(cc_list);
1600 #define SET_ENTRY(entry, str) \
1603 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1606 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1608 g_return_if_fail(msginfo != NULL);
1610 SET_ENTRY(to_entry, msginfo->to);
1611 SET_ENTRY(subject_entry, msginfo->subject);
1612 SET_ENTRY(cc_entry, compose->cc);
1613 SET_ENTRY(bcc_entry, compose->bcc);
1614 SET_ENTRY(reply_entry, compose->replyto);
1617 GtkItemFactory *ifactory;
1618 GtkWidget *menuitem;
1620 ifactory = gtk_item_factory_from_widget(compose->menubar);
1621 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1622 gtk_check_menu_item_set_active
1623 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1625 if (compose->replyto) {
1626 GtkItemFactory *ifactory;
1627 GtkWidget *menuitem;
1629 ifactory = gtk_item_factory_from_widget(compose->menubar);
1630 menuitem = gtk_item_factory_get_item
1631 (ifactory, "/Message/Reply to");
1632 gtk_check_menu_item_set_active
1633 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1639 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1646 size_t buf_len = 128;
1648 if (strlen(sigfile) < 2)
1651 sigprg = popen(sigfile+1, "r");
1654 buf = g_malloc(buf_len);
1657 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1658 "Unable to insert signature (malloc failed)\n", -1);
1664 while (!feof(sigprg)) {
1665 bzero(buf, buf_len);
1666 fread(buf, buf_len-1, 1, sigprg);
1667 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1675 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1676 "Can't exec file: ", -1);
1677 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1682 static void compose_insert_sig(Compose *compose)
1686 if (compose->account && compose->account->sig_path)
1687 sigfile = g_strdup(compose->account->sig_path);
1689 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1690 DEFAULT_SIGNATURE, NULL);
1693 if (!is_file_or_fifo_exist(sigfile) & (sigfile[0] != '|')) {
1698 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1699 if (prefs_common.sig_sep) {
1700 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1701 prefs_common.sig_sep, -1);
1702 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1706 if (sigfile[0] == '|')
1708 compose_exec_sig(compose, sigfile);
1712 compose_insert_file(compose, sigfile);
1717 static void compose_insert_file(Compose *compose, const gchar *file)
1719 GtkSText *text = GTK_STEXT(compose->text);
1720 gchar buf[BUFFSIZE];
1723 g_return_if_fail(file != NULL);
1725 if ((fp = fopen(file, "r")) == NULL) {
1726 FILE_OP_ERROR(file, "fopen");
1730 gtk_stext_freeze(text);
1732 while (fgets(buf, sizeof(buf), fp) != NULL)
1733 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1735 gtk_stext_thaw(text);
1740 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1741 ContentType cnttype)
1743 gchar *text[N_ATTACH_COLS];
1746 text[COL_MIMETYPE] = ainfo->content_type;
1747 text[COL_SIZE] = to_human_readable(ainfo->size);
1748 text[COL_NAME] = ainfo->name;
1750 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1751 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1753 if (cnttype != MIME_MESSAGE_RFC822)
1754 compose_changed_cb(NULL, compose);
1757 static void compose_attach_append_with_type(Compose *compose,
1760 ContentType cnttype)
1765 if (!is_file_exist(file)) {
1766 g_warning(_("File %s doesn't exist\n"), file);
1769 if ((size = get_file_size(file)) < 0) {
1770 g_warning(_("Can't get file size of %s\n"), file);
1774 alertpanel_notice(_("File %s is empty\n"), file);
1778 if (!compose->use_attach) {
1779 GtkItemFactory *ifactory;
1780 GtkWidget *menuitem;
1782 ifactory = gtk_item_factory_from_widget(compose->menubar);
1783 menuitem = gtk_item_factory_get_item(ifactory,
1785 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1789 ainfo = g_new0(AttachInfo, 1);
1790 ainfo->file = g_strdup(file);
1792 if (cnttype == MIME_MESSAGE_RFC822) {
1793 ainfo->encoding = ENC_7BIT;
1794 ainfo->name = g_strdup_printf(_("Message: %s"),
1797 ainfo->encoding = ENC_BASE64;
1798 ainfo->name = g_strdup(g_basename(file));
1801 ainfo->content_type = g_strdup(type);
1804 compose_attach_info(compose, ainfo, cnttype);
1807 static void compose_attach_append(Compose *compose, const gchar *file,
1808 ContentType cnttype)
1811 gchar *text[N_ATTACH_COLS];
1815 if (!is_file_exist(file)) {
1816 g_warning(_("File %s doesn't exist\n"), file);
1819 if ((size = get_file_size(file)) < 0) {
1820 g_warning(_("Can't get file size of %s\n"), file);
1824 alertpanel_notice(_("File %s is empty\n"), file);
1828 if (!compose->use_attach) {
1829 GtkItemFactory *ifactory;
1830 GtkWidget *menuitem;
1832 ifactory = gtk_item_factory_from_widget(compose->menubar);
1833 menuitem = gtk_item_factory_get_item(ifactory,
1835 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1839 ainfo = g_new0(AttachInfo, 1);
1840 ainfo->file = g_strdup(file);
1842 if (cnttype == MIME_MESSAGE_RFC822) {
1843 ainfo->content_type = g_strdup("message/rfc822");
1844 ainfo->encoding = ENC_7BIT;
1845 ainfo->name = g_strdup_printf(_("Message: %s"),
1848 ainfo->content_type = procmime_get_mime_type(file);
1849 if (!ainfo->content_type)
1850 ainfo->content_type =
1851 g_strdup("application/octet-stream");
1852 ainfo->encoding = ENC_BASE64;
1853 ainfo->name = g_strdup(g_basename(file));
1857 compose_attach_info(compose, ainfo, cnttype);
1860 static void compose_wrap_line(Compose *compose)
1862 GtkSText *text = GTK_STEXT(compose->text);
1864 guint line_pos = 0, cur_pos = 0;
1865 gint line_len = 0, cur_len = 0;
1867 gchar cbuf[MB_CUR_MAX];
1869 gtk_stext_freeze(text);
1871 text_len = gtk_stext_get_length(text);
1873 for (; cur_pos < text_len; cur_pos++) {
1874 if (text->use_wchar)
1876 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
1878 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
1882 if (ch_len == 1 && *cbuf == '\n') {
1883 line_pos = cur_pos + 1;
1884 line_len = cur_len = 0;
1893 if (ch_len == 1 && isspace(*cbuf)) {
1894 line_pos = cur_pos + 1;
1895 line_len = cur_len + ch_len;
1898 if (cur_len + ch_len > prefs_common.linewrap_len &&
1902 if (text->use_wchar)
1903 tlen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
1905 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
1908 if (tlen == 1 && isspace(*cbuf)) {
1909 gtk_stext_set_point(text, line_pos);
1910 gtk_stext_backward_delete(text, 1);
1918 gtk_stext_set_point(text, line_pos);
1919 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1923 cur_len = cur_len - line_len + ch_len;
1929 line_pos = cur_pos + 1;
1930 line_len = cur_len + ch_len;
1935 gtk_stext_thaw(text);
1938 static void compose_set_title(Compose *compose)
1943 edited = compose->modified ? _(" [Edited]") : "";
1944 if (compose->account && compose->account->address)
1945 str = g_strdup_printf(_("%s - Compose message%s"),
1946 compose->account->address, edited);
1948 str = g_strdup_printf(_("Compose message%s"), edited);
1949 gtk_window_set_title(GTK_WINDOW(compose->window), str);
1954 * compose_current_mail_account:
1956 * Find a current mail account (the currently selected account, or the
1957 * default account, if a news account is currently selected). If a
1958 * mail account cannot be found, display an error message.
1960 * Return value: Mail account, or NULL if not found.
1962 static PrefsAccount *
1963 compose_current_mail_account(void)
1967 if (cur_account && cur_account->protocol != A_NNTP)
1970 ac = account_get_default();
1971 if (!ac || ac->protocol == A_NNTP) {
1972 alertpanel_error(_("Account for sending mail is not specified.\n"
1973 "Please select a mail account before sending."));
1980 gint compose_send(Compose *compose)
1982 gchar tmp[MAXPATHLEN + 1];
1983 gchar *to, *newsgroups;
1985 static gboolean lock = FALSE;
1989 g_return_val_if_fail(compose->account != NULL, -1);
1990 g_return_val_if_fail(compose->orig_account != NULL, -1);
1994 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
1995 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
1996 if (*to == '\0' && *newsgroups == '\0') {
1997 alertpanel_error(_("Recipient is not specified."));
2002 /* write to temporary file */
2003 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2004 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2006 if (prefs_common.linewrap_at_send)
2007 compose_wrap_line(compose);
2009 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2014 if (!compose->to_list && !compose->newsgroup_list) {
2015 g_warning(_("can't get recipient list."));
2021 if (compose->to_list) {
2025 if (compose->account->protocol != A_NNTP)
2026 ac = compose->account;
2027 else if (compose->orig_account->protocol != A_NNTP)
2028 ac = compose->orig_account;
2029 else if (cur_account && cur_account->protocol != A_NNTP)
2032 ac = compose_current_mail_account();
2040 ac = compose->account;
2042 ok = send_message(tmp, ac, compose->to_list);
2043 statusbar_pop_all();
2046 if (ok == 0 && compose->newsgroup_list) {
2049 if (compose->account->protocol == A_NNTP)
2050 folder = FOLDER(compose->account->folder);
2052 folder = FOLDER(compose->orig_account->folder);
2054 ok = news_post(folder, tmp);
2056 alertpanel_error(_("Error occurred while posting the message to %s ."),
2057 compose->account->nntp_server);
2064 /* queue message if failed to send */
2066 if (prefs_common.queue_msg) {
2071 _("Error occurred while sending the message.\n"
2072 "Put this message into queue folder?"),
2073 _("OK"), _("Cancel"), NULL);
2074 if (G_ALERTDEFAULT == val) {
2075 ok = compose_queue(compose, tmp);
2077 alertpanel_error(_("Can't queue the message."));
2080 alertpanel_error(_("Error occurred while sending the message."));
2083 /* save message to outbox */
2084 if (ok == 0 && prefs_common.savemsg) {
2085 if (compose_save_to_outbox(compose, tmp) < 0)
2087 (_("Can't save the message to outbox."));
2095 static gint compose_write_to_file(Compose *compose, const gchar *file,
2102 const gchar *out_codeset;
2103 EncodingType encoding;
2105 if ((fp = fopen(file, "w")) == NULL) {
2106 FILE_OP_ERROR(file, "fopen");
2110 /* chmod for security */
2111 if (change_file_mode_rw(fp, file) < 0) {
2112 FILE_OP_ERROR(file, "chmod");
2113 g_warning(_("can't change file mode\n"));
2116 /* get all composed text */
2117 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2118 len = strlen(chars);
2119 if (is_ascii_str(chars)) {
2120 buf = g_strdup(chars);
2121 out_codeset = "US-ASCII";
2122 encoding = ENC_7BIT;
2124 const gchar *src_codeset;
2126 out_codeset = conv_get_outgoing_charset_str();
2127 if (!strcasecmp(out_codeset, "US-ASCII"))
2128 out_codeset = "ISO-8859-1";
2129 encoding = procmime_get_encoding_for_charset(out_codeset);
2130 debug_print("charset = %s, encoding = %s\n",
2131 out_codeset, procmime_get_encoding_str(encoding));
2133 src_codeset = conv_get_current_charset_str();
2134 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
2139 alertpanel_error(_("Can't convert the codeset of the message."));
2146 if (compose_write_headers
2147 (compose, fp, out_codeset, encoding, is_draft) < 0) {
2148 g_warning(_("can't write headers\n"));
2155 if (compose->use_attach) {
2157 /* This prolog message is ignored by mime software and
2158 * because it would make our signing/encryption task
2159 * tougher, we don't emit it in that case */
2160 if (!compose->use_signing && !compose->use_encryption)
2162 fputs("This is a multi-part message in MIME format.\n", fp);
2164 fprintf(fp, "\n--%s\n", compose->boundary);
2165 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
2167 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2168 procmime_get_encoding_str(encoding));
2174 if (encoding == ENC_BASE64) {
2175 gchar outbuf[B64_BUFFSIZE];
2178 for (i = 0; i < len; i += B64_LINE_SIZE) {
2179 l = MIN(B64_LINE_SIZE, len - i);
2180 to64frombits(outbuf, buf + i, l);
2184 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
2185 FILE_OP_ERROR(file, "fwrite");
2193 if (compose->use_attach)
2194 compose_write_attach(compose, fp);
2196 if (fclose(fp) == EOF) {
2197 FILE_OP_ERROR(file, "fclose");
2203 if (compose->use_signing) {
2204 if (rfc2015_sign(file, compose->account) < 0) {
2209 if (compose->use_encryption) {
2210 if (rfc2015_encrypt(file, compose->to_list) < 0) {
2215 #endif /* USE_GPGME */
2220 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
2226 if ((fp = fopen(file, "w")) == NULL) {
2227 FILE_OP_ERROR(file, "fopen");
2231 /* chmod for security */
2232 if (change_file_mode_rw(fp, file) < 0) {
2233 FILE_OP_ERROR(file, "chmod");
2234 g_warning(_("can't change file mode\n"));
2237 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2240 len = strlen(chars);
2241 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
2242 FILE_OP_ERROR(file, "fwrite");
2251 if (fclose(fp) == EOF) {
2252 FILE_OP_ERROR(file, "fclose");
2259 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
2266 debug_print(_("saving sent message...\n"));
2268 outbox = folder_get_default_outbox();
2269 path = folder_item_get_path(outbox);
2270 if (!is_dir_exist(path))
2271 make_dir_hier(path);
2273 folder_item_scan(outbox);
2274 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
2276 g_warning(_("can't save message\n"));
2280 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
2281 g_warning(_("can't open mark file\n"));
2285 newmsginfo.msgnum = num;
2286 newmsginfo.flags.perm_flags = 0;
2287 newmsginfo.flags.tmp_flags = 0;
2288 procmsg_write_flags(&newmsginfo, fp);
2296 static gint compose_queue(Compose *compose, const gchar *file)
2299 gchar *tmp, *queue_path;
2302 gchar buf[BUFFSIZE];
2305 debug_print(_("queueing message...\n"));
2306 g_return_val_if_fail(compose->to_list != NULL, -1);
2307 g_return_val_if_fail(compose->account != NULL, -1);
2309 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
2310 G_DIR_SEPARATOR, (gint)compose);
2311 if ((fp = fopen(tmp, "w")) == NULL) {
2312 FILE_OP_ERROR(tmp, "fopen");
2316 if ((src_fp = fopen(file, "r")) == NULL) {
2317 FILE_OP_ERROR(file, "fopen");
2323 if (change_file_mode_rw(fp, tmp) < 0) {
2324 FILE_OP_ERROR(tmp, "chmod");
2325 g_warning(_("can't change file mode\n"));
2328 /* queueing variables */
2329 fprintf(fp, "AF:\n");
2330 fprintf(fp, "NF:0\n");
2331 fprintf(fp, "PS:10\n");
2332 fprintf(fp, "SRH:1\n");
2333 fprintf(fp, "SFN:\n");
2334 fprintf(fp, "DSR:\n");
2336 fprintf(fp, "MID:<%s>\n", compose->msgid);
2338 fprintf(fp, "MID:\n");
2339 fprintf(fp, "CFG:\n");
2340 fprintf(fp, "PT:0\n");
2341 fprintf(fp, "S:%s\n", compose->account->address);
2342 fprintf(fp, "RQ:\n");
2343 if (compose->account->smtp_server)
2344 fprintf(fp, "SSV:%s\n", compose->account->smtp_server);
2346 fprintf(fp, "SSV:\n");
2347 if (compose->account->nntp_server)
2348 fprintf(fp, "NSV:%s\n", compose->account->nntp_server);
2350 fprintf(fp, "NSV:\n");
2351 fprintf(fp, "SSH:\n");
2352 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
2353 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
2354 fprintf(fp, ",<%s>", (gchar *)cur->data);
2358 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
2359 if (fputs(buf, fp) == EOF) {
2360 FILE_OP_ERROR(tmp, "fputs");
2370 if (fclose(fp) == EOF) {
2371 FILE_OP_ERROR(tmp, "fclose");
2377 queue = folder_get_default_queue();
2378 folder_item_scan(queue);
2379 queue_path = folder_item_get_path(queue);
2380 if (!is_dir_exist(queue_path))
2381 make_dir_hier(queue_path);
2382 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
2383 g_warning(_("can't queue the message\n"));
2391 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
2392 g_warning(_("can't open mark file\n"));
2396 newmsginfo.msgnum = num;
2397 newmsginfo.flags.perm_flags = 0;
2398 newmsginfo.flags.tmp_flags = 0;
2399 procmsg_write_flags(&newmsginfo, fp);
2404 folder_item_scan(queue);
2405 folderview_update_item(queue, TRUE);
2410 static void compose_write_attach(Compose *compose, FILE *fp)
2413 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2416 gchar filename[BUFFSIZE];
2419 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
2421 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
2422 g_warning(_("Can't open file %s\n"), ainfo->file);
2426 fprintf(fp, "\n--%s\n", compose->boundary);
2428 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
2429 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
2430 fprintf(fp, "Content-Disposition: inline\n");
2432 conv_encode_header(filename, sizeof(filename),
2434 fprintf(fp, "Content-Type: %s;\n"
2436 ainfo->content_type, filename);
2437 fprintf(fp, "Content-Disposition: attachment;\n"
2438 " filename=\"%s\"\n", filename);
2441 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
2442 procmime_get_encoding_str(ainfo->encoding));
2444 if (ainfo->encoding == ENC_7BIT) {
2445 gchar buf[BUFFSIZE];
2447 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
2449 if (len > 1 && buf[len - 1] == '\n' &&
2450 buf[len - 2] == '\r') {
2451 buf[len - 2] = '\n';
2452 buf[len - 1] = '\0';
2457 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
2459 while ((len = fread(inbuf, sizeof(gchar),
2460 B64_LINE_SIZE, attach_fp))
2462 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
2466 if (len > 0 && feof(attach_fp)) {
2467 to64frombits(outbuf, inbuf, len);
2476 fprintf(fp, "\n--%s--\n", compose->boundary);
2479 #define IS_IN_CUSTOM_HEADER(header) \
2480 (compose->account->add_customhdr && \
2481 custom_header_find(compose->account->customhdr_list, header) != NULL)
2483 static gint compose_write_headers(Compose *compose, FILE *fp,
2484 const gchar *charset, EncodingType encoding,
2487 gchar buf[BUFFSIZE];
2489 /* struct utsname utsbuf; */
2491 g_return_val_if_fail(fp != NULL, -1);
2492 g_return_val_if_fail(charset != NULL, -1);
2493 g_return_val_if_fail(compose->account != NULL, -1);
2494 g_return_val_if_fail(compose->account->address != NULL, -1);
2497 if (compose->account->add_date) {
2498 get_rfc822_date(buf, sizeof(buf));
2499 fprintf(fp, "Date: %s\n", buf);
2503 if (!IS_IN_CUSTOM_HEADER("From")) {
2504 if (compose->account->name && *compose->account->name) {
2505 compose_convert_header
2506 (buf, sizeof(buf), compose->account->name,
2508 fprintf(fp, "From: %s <%s>\n",
2509 buf, compose->account->address);
2511 fprintf(fp, "From: %s\n", compose->account->address);
2514 slist_free_strings(compose->to_list);
2515 g_slist_free(compose->to_list);
2516 compose->to_list = NULL;
2519 if (compose->use_to) {
2520 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2522 Xstrdup_a(str, str, return -1);
2525 compose->to_list = address_list_append
2526 (compose->to_list, str);
2527 if (!IS_IN_CUSTOM_HEADER("To")) {
2528 compose_convert_header
2529 (buf, sizeof(buf), str,
2531 fprintf(fp, "To: %s\n", buf);
2537 slist_free_strings(compose->newsgroup_list);
2538 g_slist_free(compose->newsgroup_list);
2539 compose->newsgroup_list = NULL;
2542 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2544 Xstrdup_a(str, str, return -1);
2548 compose->newsgroup_list =
2549 newsgroup_list_append(compose->newsgroup_list,
2551 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
2552 compose_convert_header(buf, sizeof(buf), str,
2553 strlen("Newsgroups: "));
2554 fprintf(fp, "Newsgroups: %s\n", buf);
2559 if (!is_draft && !compose->to_list && !compose->newsgroup_list)
2563 if (compose->use_cc) {
2564 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
2566 Xstrdup_a(str, str, return -1);
2569 compose->to_list = address_list_append
2570 (compose->to_list, str);
2571 if (!IS_IN_CUSTOM_HEADER("Cc")) {
2572 compose_convert_header
2573 (buf, sizeof(buf), str,
2575 fprintf(fp, "Cc: %s\n", buf);
2582 if (compose->use_bcc) {
2583 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
2585 Xstrdup_a(str, str, return -1);
2588 compose->to_list = address_list_append
2589 (compose->to_list, str);
2591 compose_convert_header
2592 (buf, sizeof(buf), str,
2594 fprintf(fp, "Bcc: %s\n", buf);
2601 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2602 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
2603 Xstrdup_a(str, str, return -1);
2606 compose_convert_header(buf, sizeof(buf), str,
2607 strlen("Subject: "));
2608 fprintf(fp, "Subject: %s\n", buf);
2613 if (compose->account->gen_msgid) {
2614 compose_generate_msgid(compose, buf, sizeof(buf));
2615 fprintf(fp, "Message-Id: <%s>\n", buf);
2616 compose->msgid = g_strdup(buf);
2620 if (compose->inreplyto && compose->to_list)
2621 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
2624 if (compose->references)
2625 fprintf(fp, "References: %s\n", compose->references);
2628 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
2629 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
2631 Xstrdup_a(str, str, return -1);
2635 compose_convert_header(buf, sizeof(buf), str,
2636 strlen("Followup-To: "));
2637 fprintf(fp, "Followup-To: %s\n", buf);
2643 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
2644 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
2646 Xstrdup_a(str, str, return -1);
2649 compose_convert_header(buf, sizeof(buf), str,
2650 strlen("Reply-To: "));
2651 fprintf(fp, "Reply-To: %s\n", buf);
2657 if (compose->account->organization &&
2658 !IS_IN_CUSTOM_HEADER("Organization")) {
2659 compose_convert_header(buf, sizeof(buf),
2660 compose->account->organization,
2661 strlen("Organization: "));
2662 fprintf(fp, "Organization: %s\n", buf);
2665 /* Program version and system info */
2666 /* uname(&utsbuf); */
2667 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2668 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
2669 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
2671 gtk_major_version, gtk_minor_version, gtk_micro_version,
2673 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2675 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2676 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
2677 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
2679 gtk_major_version, gtk_minor_version, gtk_micro_version,
2681 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2684 /* custom headers */
2685 if (compose->account->add_customhdr) {
2688 for (cur = compose->account->customhdr_list; cur != NULL;
2690 CustomHeader *chdr = (CustomHeader *)cur->data;
2692 if (strcasecmp(chdr->name, "Date") != 0 &&
2693 strcasecmp(chdr->name, "From") != 0 &&
2694 strcasecmp(chdr->name, "To") != 0 &&
2695 strcasecmp(chdr->name, "Sender") != 0 &&
2696 strcasecmp(chdr->name, "Message-Id") != 0 &&
2697 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
2698 strcasecmp(chdr->name, "References") != 0 &&
2699 strcasecmp(chdr->name, "Mime-Version") != 0 &&
2700 strcasecmp(chdr->name, "Content-Type") != 0 &&
2701 strcasecmp(chdr->name, "Content-Transfer-Encoding")
2703 compose_convert_header
2705 chdr->value ? chdr->value : "",
2706 strlen(chdr->name) + 2);
2707 fprintf(fp, "%s: %s\n", chdr->name, buf);
2712 fprintf(fp, "Mime-Version: 1.0\n");
2713 if (compose->use_attach) {
2714 get_rfc822_date(buf, sizeof(buf));
2715 subst_char(buf, ' ', '_');
2716 subst_char(buf, ',', '_');
2717 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
2718 buf, (guint)compose);
2720 "Content-Type: multipart/mixed;\n"
2721 " boundary=\"%s\"\n", compose->boundary);
2723 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
2724 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2725 procmime_get_encoding_str(encoding));
2728 /* Request Return Receipt */
2729 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
2730 if (compose->return_receipt) {
2731 if (compose->account->name
2732 && *compose->account->name) {
2733 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
2734 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
2736 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
2740 /* separator between header and body */
2746 #undef IS_IN_CUSTOM_HEADER
2748 static void compose_convert_header(gchar *dest, gint len, gchar *src,
2751 g_return_if_fail(src != NULL);
2752 g_return_if_fail(dest != NULL);
2754 if (len < 1) return;
2758 if (is_ascii_str(src)) {
2759 strncpy2(dest, src, len);
2760 dest[len - 1] = '\0';
2763 conv_encode_header(dest, len, src, header_len);
2766 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
2775 if (compose->account && compose->account->address &&
2776 *compose->account->address) {
2777 if (strchr(compose->account->address, '@'))
2778 addr = g_strdup(compose->account->address);
2780 addr = g_strconcat(compose->account->address, "@",
2781 get_domain_name(), NULL);
2783 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
2786 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
2787 lt->tm_year + 1900, lt->tm_mon + 1,
2788 lt->tm_mday, lt->tm_hour,
2789 lt->tm_min, lt->tm_sec,
2790 (guint)random(), addr);
2792 debug_print(_("generated Message-ID: %s\n"), buf);
2797 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
2798 GtkWidget **entry, gint *count,
2799 const gchar *label_str,
2800 gboolean is_addr_entry)
2804 if (GTK_TABLE(table)->nrows < (*count) + 1)
2805 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
2807 *hbox = gtk_hbox_new(FALSE, 0);
2808 label = gtk_label_new
2809 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
2810 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
2811 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
2813 *entry = gtk_entry_new();
2814 gtk_table_attach_defaults
2815 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1);
2816 if (GTK_TABLE(table)->nrows > (*count) + 1)
2817 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
2820 address_completion_register_entry(GTK_ENTRY(*entry));
2825 static Compose *compose_create(PrefsAccount *account)
2831 GtkWidget *handlebox;
2835 GtkWidget *table_vbox;
2837 GtkWidget *from_optmenu_hbox;
2838 GtkWidget *to_entry;
2840 GtkWidget *newsgroups_entry;
2841 GtkWidget *newsgroups_hbox;
2842 GtkWidget *subject_entry;
2843 GtkWidget *cc_entry;
2845 GtkWidget *bcc_entry;
2846 GtkWidget *bcc_hbox;
2847 GtkWidget *reply_entry;
2848 GtkWidget *reply_hbox;
2849 GtkWidget *followup_entry;
2850 GtkWidget *followup_hbox;
2854 GtkWidget *attach_scrwin;
2855 GtkWidget *attach_clist;
2857 GtkWidget *edit_vbox;
2858 GtkWidget *ruler_hbox;
2860 GtkWidget *scrolledwin;
2866 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
2867 guint n_menu_entries;
2868 GtkStyle *style, *new_style;
2871 gboolean success[1];
2873 GtkWidget *popupmenu;
2874 GtkWidget *menuitem;
2875 GtkItemFactory *popupfactory;
2876 GtkItemFactory *ifactory;
2881 g_return_val_if_fail(account != NULL, NULL);
2883 debug_print(_("Creating compose window...\n"));
2884 compose = g_new0(Compose, 1);
2886 compose->account = account;
2887 compose->orig_account = account;
2889 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2890 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
2891 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
2892 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
2893 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
2894 gtk_signal_connect(GTK_OBJECT(window), "destroy",
2895 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
2896 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
2897 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
2898 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
2899 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
2900 gtk_widget_realize(window);
2902 vbox = gtk_vbox_new(FALSE, 0);
2903 gtk_container_add(GTK_CONTAINER(window), vbox);
2905 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
2906 menubar = menubar_create(window, compose_entries,
2907 n_menu_entries, "<Compose>", compose);
2908 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
2910 handlebox = gtk_handle_box_new();
2911 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
2913 compose_toolbar_create(compose, handlebox);
2915 vbox2 = gtk_vbox_new(FALSE, 2);
2916 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
2917 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
2919 table_vbox = gtk_vbox_new(FALSE, 0);
2920 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
2921 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
2924 table = gtk_table_new(8, 2, FALSE);
2925 gtk_box_pack_start(GTK_BOX(table_vbox), table, FALSE, TRUE, 0);
2927 /* option menu for selecting accounts */
2928 hbox = gtk_hbox_new(FALSE, 0);
2929 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
2930 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
2931 gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, count, count + 1,
2933 from_optmenu_hbox = compose_account_option_menu_create(compose);
2934 gtk_table_attach_defaults(GTK_TABLE(table), from_optmenu_hbox,
2935 1, 2, count, count + 1);
2936 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
2939 /* header labels and entries */
2940 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
2942 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
2943 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
2944 &count, "Newsgroups:", FALSE);
2945 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
2946 compose_add_entry_field(table, &hbox, &subject_entry, &count,
2948 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
2949 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
2951 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
2952 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
2954 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
2955 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
2957 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
2958 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
2959 "Followup-To:", FALSE);
2960 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
2962 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
2964 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
2965 GTK_SIGNAL_FUNC(to_activated), compose);
2966 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
2967 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
2968 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
2969 GTK_SIGNAL_FUNC(subject_activated), compose);
2970 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
2971 GTK_SIGNAL_FUNC(cc_activated), compose);
2972 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
2973 GTK_SIGNAL_FUNC(bcc_activated), compose);
2974 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
2975 GTK_SIGNAL_FUNC(replyto_activated), compose);
2976 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
2977 GTK_SIGNAL_FUNC(followupto_activated), compose);
2979 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
2980 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2981 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
2982 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2983 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
2984 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2985 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
2986 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2987 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
2988 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2989 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
2990 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2991 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
2992 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
2994 /* attachment list */
2995 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
2996 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
2997 GTK_POLICY_AUTOMATIC,
2999 gtk_widget_set_usize(attach_scrwin, -1, 80);
3001 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
3002 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
3004 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
3005 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
3006 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
3007 GTK_SELECTION_EXTENDED);
3008 for (i = 0; i < N_ATTACH_COLS; i++)
3009 GTK_WIDGET_UNSET_FLAGS
3010 (GTK_CLIST(attach_clist)->column[i].button,
3012 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
3014 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
3015 GTK_SIGNAL_FUNC(attach_selected), compose);
3016 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
3017 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
3018 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
3019 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
3022 gtk_drag_dest_set(attach_clist,
3023 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3025 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
3026 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
3029 /* pane between attach clist and text */
3030 paned = gtk_vpaned_new();
3031 gtk_paned_add1(GTK_PANED(paned), attach_scrwin);
3032 gtk_widget_ref(paned);
3033 gtk_widget_show_all(paned);
3035 edit_vbox = gtk_vbox_new(FALSE, 0);
3036 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
3039 ruler_hbox = gtk_hbox_new(FALSE, 0);
3040 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
3042 ruler = gtk_shruler_new();
3043 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
3044 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
3046 gtk_widget_set_usize(ruler_hbox, 1, -1);
3049 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3050 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
3051 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
3052 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
3053 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
3055 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
3056 (GTK_SCROLLED_WINDOW(scrolledwin)),
3057 gtk_scrolled_window_get_vadjustment
3058 (GTK_SCROLLED_WINDOW(scrolledwin)));
3059 GTK_STEXT(text)->default_tab_width = 8;
3060 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
3061 if (prefs_common.smart_wrapping) {
3062 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
3063 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
3066 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
3068 gtk_signal_connect(GTK_OBJECT(text), "changed",
3069 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
3070 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
3071 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3072 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
3073 GTK_SIGNAL_FUNC(compose_button_press_cb),
3076 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
3077 GTK_SIGNAL_FUNC(compose_key_press_cb),
3080 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
3081 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
3085 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3087 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
3088 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
3091 gtk_widget_show_all(vbox);
3093 style = gtk_widget_get_style(text);
3095 /* workaround for the slow down of GtkText when using Pixmap theme */
3096 if (style->engine) {
3097 GtkThemeEngine *engine;
3099 engine = style->engine;
3100 style->engine = NULL;
3101 new_style = gtk_style_copy(style);
3102 style->engine = engine;
3104 new_style = gtk_style_copy(style);
3106 if (prefs_common.textfont) {
3109 charset = conv_get_current_charset();
3110 if (MB_CUR_MAX == 1) {
3113 Xstrdup_a(fontstr, prefs_common.textfont, );
3114 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
3116 font = gdk_font_load(fontstr);
3118 font = gdk_fontset_load(prefs_common.textfont);
3120 gdk_font_unref(new_style->font);
3121 new_style->font = font;
3125 gtk_widget_set_style(text, new_style);
3127 color[0] = quote_color;
3128 cmap = gdk_window_get_colormap(window->window);
3129 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
3130 if (success[0] == FALSE) {
3131 g_warning("Compose: color allocation failed.\n");
3132 style = gtk_widget_get_style(text);
3133 quote_color = style->black;
3136 n_entries = sizeof(compose_popup_entries) /
3137 sizeof(compose_popup_entries[0]);
3138 popupmenu = menu_create_items(compose_popup_entries, n_entries,
3139 "<Compose>", &popupfactory,
3142 ifactory = gtk_item_factory_from_widget(menubar);
3143 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
3144 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
3147 if (account->protocol == A_NNTP) {
3148 gtk_widget_hide(to_hbox);
3149 gtk_widget_hide(to_entry);
3150 gtk_widget_hide(cc_hbox);
3151 gtk_widget_hide(cc_entry);
3152 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
3153 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
3155 gtk_widget_hide(newsgroups_hbox);
3156 gtk_widget_hide(newsgroups_entry);
3157 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
3159 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
3163 switch (prefs_common.toolbar_style) {
3165 gtk_widget_hide(handlebox);
3168 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3172 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3176 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3181 gtk_widget_show(window);
3183 address_completion_start(window);
3185 compose->window = window;
3186 compose->vbox = vbox;
3187 compose->menubar = menubar;
3188 compose->handlebox = handlebox;
3190 compose->vbox2 = vbox2;
3192 compose->table_vbox = table_vbox;
3193 compose->table = table;
3194 compose->to_hbox = to_hbox;
3195 compose->to_entry = to_entry;
3196 compose->newsgroups_hbox = newsgroups_hbox;
3197 compose->newsgroups_entry = newsgroups_entry;
3198 compose->subject_entry = subject_entry;
3199 compose->cc_hbox = cc_hbox;
3200 compose->cc_entry = cc_entry;
3201 compose->bcc_hbox = bcc_hbox;
3202 compose->bcc_entry = bcc_entry;
3203 compose->reply_hbox = reply_hbox;
3204 compose->reply_entry = reply_entry;
3205 compose->followup_hbox = followup_hbox;
3206 compose->followup_entry = followup_entry;
3208 compose->paned = paned;
3210 compose->attach_scrwin = attach_scrwin;
3211 compose->attach_clist = attach_clist;
3213 compose->edit_vbox = edit_vbox;
3214 compose->ruler_hbox = ruler_hbox;
3215 compose->ruler = ruler;
3216 compose->scrolledwin = scrolledwin;
3217 compose->text = text;
3219 compose->focused_editable = NULL;
3221 compose->popupmenu = popupmenu;
3222 compose->popupfactory = popupfactory;
3224 compose->mode = COMPOSE_NEW;
3226 compose->replyto = NULL;
3228 compose->bcc = NULL;
3229 compose->followup_to = NULL;
3230 compose->inreplyto = NULL;
3231 compose->references = NULL;
3232 compose->msgid = NULL;
3233 compose->boundary = NULL;
3236 compose->use_signing = FALSE;
3237 compose->use_encryption = FALSE;
3238 #endif /* USE_GPGME */
3240 compose->modified = FALSE;
3242 compose->return_receipt = FALSE;
3244 compose->to_list = NULL;
3245 compose->newsgroup_list = NULL;
3247 compose->exteditor_file = NULL;
3248 compose->exteditor_pid = -1;
3249 compose->exteditor_readdes = -1;
3250 compose->exteditor_tag = -1;
3252 compose_set_title(compose);
3254 compose->use_bcc = FALSE;
3255 compose->use_replyto = FALSE;
3256 compose->use_followupto = FALSE;
3259 if (account->protocol != A_NNTP) {
3260 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
3261 gtk_check_menu_item_set_active
3262 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3263 gtk_widget_set_sensitive(menuitem, FALSE);
3264 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3265 gtk_check_menu_item_set_active
3266 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3267 gtk_widget_set_sensitive(menuitem, FALSE);
3270 if (account->set_autocc && account->auto_cc) {
3271 compose->use_cc = TRUE;
3272 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
3273 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3274 gtk_check_menu_item_set_active
3275 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3278 if (account->set_autobcc) {
3279 compose->use_bcc = TRUE;
3280 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
3281 gtk_check_menu_item_set_active
3282 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3283 if (account->auto_bcc)
3284 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
3287 if (account->set_autoreplyto) {
3288 compose->use_replyto = TRUE;
3289 menuitem = gtk_item_factory_get_item(ifactory,
3290 "/Message/Reply to");
3291 gtk_check_menu_item_set_active
3292 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3293 if (account->auto_replyto)
3294 gtk_entry_set_text(GTK_ENTRY(reply_entry),
3295 account->auto_replyto);
3298 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
3299 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3300 prefs_common.show_ruler);
3303 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
3304 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3305 prefs_common.default_sign);
3306 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
3307 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3308 prefs_common.default_encrypt);
3309 #endif /* USE_GPGME */
3311 addressbook_set_target_compose(compose);
3313 compose_list = g_list_append(compose_list, compose);
3316 compose->use_to = FALSE;
3317 compose->use_cc = FALSE;
3319 compose->use_attach = FALSE;
3321 if (!compose->use_bcc) {
3322 gtk_widget_hide(bcc_hbox);
3323 gtk_widget_hide(bcc_entry);
3324 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
3326 if (!compose->use_replyto) {
3327 gtk_widget_hide(reply_hbox);
3328 gtk_widget_hide(reply_entry);
3329 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
3331 if (!compose->use_followupto) {
3332 gtk_widget_hide(followup_hbox);
3333 gtk_widget_hide(followup_entry);
3334 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
3337 if (!prefs_common.show_ruler)
3338 gtk_widget_hide(ruler_hbox);
3340 select_account(compose, account);
3345 #include "pixmaps/stock_mail_send.xpm"
3346 #include "pixmaps/stock_mail_send_queue.xpm"
3347 #include "pixmaps/stock_mail.xpm"
3348 #include "pixmaps/stock_paste.xpm"
3349 #include "pixmaps/stock_mail_attach.xpm"
3350 #include "pixmaps/stock_mail_compose.xpm"
3351 #include "pixmaps/linewrap.xpm"
3352 #include "pixmaps/tb_address_book.xpm"
3354 #define CREATE_TOOLBAR_ICON(xpm_d) \
3356 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
3357 &container->style->white, \
3359 icon_wid = gtk_pixmap_new(icon, mask); \
3362 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
3367 GtkWidget *icon_wid;
3368 GtkWidget *send_btn;
3369 GtkWidget *sendl_btn;
3370 GtkWidget *draft_btn;
3371 GtkWidget *insert_btn;
3372 GtkWidget *attach_btn;
3374 GtkWidget *exteditor_btn;
3375 GtkWidget *linewrap_btn;
3376 GtkWidget *addrbook_btn;
3378 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
3380 gtk_container_add(GTK_CONTAINER(container), toolbar);
3381 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
3382 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
3383 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
3384 GTK_TOOLBAR_SPACE_LINE);
3386 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
3387 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3391 icon_wid, toolbar_send_cb, compose);
3393 CREATE_TOOLBAR_ICON(stock_mail_send_queue_xpm);
3394 /* CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm); */
3395 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3397 _("Put into queue folder and send later"),
3399 icon_wid, toolbar_send_later_cb,
3402 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3403 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3405 _("Save to draft folder"),
3407 icon_wid, toolbar_draft_cb,
3410 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3412 CREATE_TOOLBAR_ICON(stock_paste_xpm);
3413 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3417 icon_wid, toolbar_insert_cb,
3420 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
3421 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3425 icon_wid, toolbar_attach_cb,
3428 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3430 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3431 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3433 _("Insert signature"),
3435 icon_wid, toolbar_sig_cb, compose);
3437 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3439 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
3440 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3442 _("Edit with external editor"),
3445 toolbar_ext_editor_cb,
3448 CREATE_TOOLBAR_ICON(linewrap_xpm);
3449 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3451 _("Wrap long lines"),
3454 toolbar_linewrap_cb,
3457 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3459 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
3460 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3464 icon_wid, toolbar_address_cb,
3467 compose->toolbar = toolbar;
3468 compose->send_btn = send_btn;
3469 compose->sendl_btn = sendl_btn;
3470 compose->draft_btn = draft_btn;
3471 compose->insert_btn = insert_btn;
3472 compose->attach_btn = attach_btn;
3473 compose->sig_btn = sig_btn;
3474 compose->exteditor_btn = exteditor_btn;
3475 compose->linewrap_btn = linewrap_btn;
3476 compose->addrbook_btn = addrbook_btn;
3478 gtk_widget_show_all(toolbar);
3481 #undef CREATE_TOOLBAR_ICON
3483 static GtkWidget *compose_account_option_menu_create(Compose *compose)
3489 gint num = 0, def_menu = 0;
3491 accounts = account_get_list();
3492 g_return_val_if_fail(accounts != NULL, NULL);
3494 hbox = gtk_hbox_new(FALSE, 0);
3495 optmenu = gtk_option_menu_new();
3496 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3497 menu = gtk_menu_new();
3499 for (; accounts != NULL; accounts = accounts->next, num++) {
3500 PrefsAccount *ac = (PrefsAccount *)accounts->data;
3501 GtkWidget *menuitem;
3504 if (ac == compose->account) def_menu = num;
3506 name = g_strdup_printf("%s: %s <%s>",
3507 ac->account_name, ac->name, ac->address);
3508 MENUITEM_ADD(menu, menuitem, name, ac);
3510 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
3511 GTK_SIGNAL_FUNC(account_activated),
3515 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
3516 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
3521 static void compose_destroy(Compose *compose)
3524 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3527 /* NOTE: address_completion_end() does nothing with the window
3528 * however this may change. */
3529 address_completion_end(compose->window);
3531 slist_free_strings(compose->to_list);
3532 g_slist_free(compose->to_list);
3533 slist_free_strings(compose->newsgroup_list);
3534 g_slist_free(compose->newsgroup_list);
3536 procmsg_msginfo_free(compose->targetinfo);
3538 g_free(compose->replyto);
3539 g_free(compose->cc);
3540 g_free(compose->bcc);
3541 g_free(compose->newsgroups);
3542 g_free(compose->followup_to);
3544 g_free(compose->inreplyto);
3545 g_free(compose->references);
3546 g_free(compose->msgid);
3547 g_free(compose->boundary);
3549 g_free(compose->exteditor_file);
3551 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3553 compose_attach_info_free(ainfo);
3555 if (addressbook_get_target_compose() == compose)
3556 addressbook_set_target_compose(NULL);
3558 prefs_common.compose_width = compose->scrolledwin->allocation.width;
3559 prefs_common.compose_height = compose->window->allocation.height;
3561 gtk_widget_destroy(compose->paned);
3565 compose_list = g_list_remove(compose_list, compose);
3568 static void compose_attach_info_free(AttachInfo *ainfo)
3570 g_free(ainfo->file);
3571 g_free(ainfo->content_type);
3572 g_free(ainfo->name);
3576 static void compose_attach_remove_selected(Compose *compose)
3578 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3582 while (clist->selection != NULL) {
3583 row = GPOINTER_TO_INT(clist->selection->data);
3584 ainfo = gtk_clist_get_row_data(clist, row);
3585 compose_attach_info_free(ainfo);
3586 gtk_clist_remove(clist, row);
3590 static struct _AttachProperty
3593 GtkWidget *mimetype_entry;
3594 GtkWidget *encoding_optmenu;
3595 GtkWidget *path_entry;
3596 GtkWidget *filename_entry;
3598 GtkWidget *cancel_btn;
3601 static void compose_attach_property(Compose *compose)
3603 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3606 GtkOptionMenu *optmenu;
3607 static gboolean cancelled;
3609 if (!clist->selection) return;
3610 row = GPOINTER_TO_INT(clist->selection->data);
3612 ainfo = gtk_clist_get_row_data(clist, row);
3615 if (!attach_prop.window)
3616 compose_attach_property_create(&cancelled);
3617 gtk_widget_grab_focus(attach_prop.ok_btn);
3618 gtk_widget_show(attach_prop.window);
3619 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
3621 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
3622 if (ainfo->encoding == ENC_UNKNOWN)
3623 gtk_option_menu_set_history(optmenu, ENC_BASE64);
3625 gtk_option_menu_set_history(optmenu, ainfo->encoding);
3627 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
3628 ainfo->content_type ? ainfo->content_type : "");
3629 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
3630 ainfo->file ? ainfo->file : "");
3631 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
3632 ainfo->name ? ainfo->name : "");
3636 gchar *cnttype = NULL;
3640 GtkWidget *menuitem;
3645 if (cancelled == TRUE) {
3646 gtk_widget_hide(attach_prop.window);
3650 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
3651 if (*text != '\0') {
3654 text = g_strstrip(g_strdup(text));
3655 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
3656 cnttype = g_strdup(text);
3659 alertpanel_error(_("Invalid MIME type."));
3665 menu = gtk_option_menu_get_menu(optmenu);
3666 menuitem = gtk_menu_get_active(GTK_MENU(menu));
3667 ainfo->encoding = GPOINTER_TO_INT
3668 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
3670 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
3671 if (*text != '\0') {
3672 if (is_file_exist(text) &&
3673 (size = get_file_size(text)) > 0)
3674 file = g_strdup(text);
3677 (_("File doesn't exist or is empty."));
3683 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
3684 if (*text != '\0') {
3685 g_free(ainfo->name);
3686 ainfo->name = g_strdup(text);
3690 g_free(ainfo->content_type);
3691 ainfo->content_type = cnttype;
3694 g_free(ainfo->file);
3700 gtk_clist_set_text(clist, row, COL_MIMETYPE,
3701 ainfo->content_type);
3702 gtk_clist_set_text(clist, row, COL_SIZE,
3703 to_human_readable(ainfo->size));
3704 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
3706 gtk_widget_hide(attach_prop.window);
3711 #define SET_LABEL_AND_ENTRY(str, entry, top) \
3713 label = gtk_label_new(str); \
3714 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
3715 GTK_FILL, 0, 0, 0); \
3716 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
3718 entry = gtk_entry_new(); \
3719 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
3720 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
3723 static void compose_attach_property_create(gboolean *cancelled)
3729 GtkWidget *mimetype_entry;
3732 GtkWidget *optmenu_menu;
3733 GtkWidget *menuitem;
3734 GtkWidget *path_entry;
3735 GtkWidget *filename_entry;
3738 GtkWidget *cancel_btn;
3739 GList *mime_type_list, *strlist;
3741 debug_print("Creating attach_property window...\n");
3743 window = gtk_window_new(GTK_WINDOW_DIALOG);
3744 gtk_widget_set_usize(window, 480, -1);
3745 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
3746 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
3747 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
3748 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
3749 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3750 GTK_SIGNAL_FUNC(attach_property_delete_event),
3752 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
3753 GTK_SIGNAL_FUNC(attach_property_key_pressed),
3756 vbox = gtk_vbox_new(FALSE, 8);
3757 gtk_container_add(GTK_CONTAINER(window), vbox);
3759 table = gtk_table_new(4, 2, FALSE);
3760 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
3761 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
3762 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
3764 label = gtk_label_new(_("MIME type"));
3765 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
3767 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3768 mimetype_entry = gtk_combo_new();
3769 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
3770 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3772 /* stuff with list */
3773 mime_type_list = procmime_get_mime_type_list();
3775 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
3776 MimeType *type = (MimeType *) mime_type_list->data;
3777 strlist = g_list_append(strlist,
3778 g_strdup_printf("%s/%s",
3779 type->type, type->sub_type));
3782 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
3784 for (mime_type_list = strlist; mime_type_list != NULL;
3785 mime_type_list = mime_type_list->next)
3786 g_free(mime_type_list->data);
3787 g_list_free(strlist);
3789 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
3791 label = gtk_label_new(_("Encoding"));
3792 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
3794 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3796 hbox = gtk_hbox_new(FALSE, 0);
3797 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
3798 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3800 optmenu = gtk_option_menu_new();
3801 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3803 optmenu_menu = gtk_menu_new();
3804 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
3805 gtk_widget_set_sensitive(menuitem, FALSE);
3806 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
3807 gtk_widget_set_sensitive(menuitem, FALSE);
3808 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
3809 gtk_widget_set_sensitive(menuitem, FALSE);
3810 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
3812 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
3814 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
3815 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
3817 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
3818 &cancel_btn, _("Cancel"), NULL, NULL);
3819 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
3820 gtk_widget_grab_default(ok_btn);
3822 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
3823 GTK_SIGNAL_FUNC(attach_property_ok),
3825 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
3826 GTK_SIGNAL_FUNC(attach_property_cancel),
3829 gtk_widget_show_all(vbox);
3831 attach_prop.window = window;
3832 attach_prop.mimetype_entry = mimetype_entry;
3833 attach_prop.encoding_optmenu = optmenu;
3834 attach_prop.path_entry = path_entry;
3835 attach_prop.filename_entry = filename_entry;
3836 attach_prop.ok_btn = ok_btn;
3837 attach_prop.cancel_btn = cancel_btn;
3840 #undef SET_LABEL_AND_ENTRY
3842 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
3848 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
3854 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
3855 gboolean *cancelled)
3863 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
3864 gboolean *cancelled)
3866 if (event && event->keyval == GDK_Escape) {
3872 static void compose_exec_ext_editor(Compose *compose)
3878 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
3879 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3881 if (pipe(pipe_fds) < 0) {
3886 if ((pid = fork()) < 0) {
3892 /* close the write side of the pipe */
3895 compose->exteditor_file = g_strdup(tmp);
3896 compose->exteditor_pid = pid;
3897 compose->exteditor_readdes = pipe_fds[0];
3899 compose_set_ext_editor_sensitive(compose, FALSE);
3901 compose->exteditor_tag =
3902 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
3903 compose_input_cb, compose);
3904 } else { /* process-monitoring process */
3910 /* close the read side of the pipe */
3913 if (compose_write_body_to_file(compose, tmp) < 0) {
3914 fd_write(pipe_fds[1], "2\n", 2);
3918 pid_ed = compose_exec_ext_editor_real(tmp);
3920 fd_write(pipe_fds[1], "1\n", 2);
3924 /* wait until editor is terminated */
3925 waitpid(pid_ed, NULL, 0);
3927 fd_write(pipe_fds[1], "0\n", 2);
3934 static gint compose_exec_ext_editor_real(const gchar *file)
3936 static gchar *def_cmd = "emacs %s";
3942 g_return_val_if_fail(file != NULL, -1);
3944 if ((pid = fork()) < 0) {
3949 if (pid != 0) return pid;
3951 /* grandchild process */
3953 if (setpgid(0, getppid()))
3956 if (prefs_common.ext_editor_cmd &&
3957 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
3958 *(p + 1) == 's' && !strchr(p + 2, '%')) {
3959 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
3961 if (prefs_common.ext_editor_cmd)
3962 g_warning(_("External editor command line is invalid: `%s'\n"),
3963 prefs_common.ext_editor_cmd);
3964 g_snprintf(buf, sizeof(buf), def_cmd, file);
3967 cmdline = g_strsplit(buf, " ", 1024);
3968 execvp(cmdline[0], cmdline);
3971 g_strfreev(cmdline);
3976 static gboolean compose_ext_editor_kill(Compose *compose)
3978 pid_t pgid = compose->exteditor_pid * -1;
3981 ret = kill(pgid, 0);
3983 if (ret == 0 || (ret == -1 && EPERM == errno)) {
3987 msg = g_strdup_printf
3988 (_("The external editor is still working.\n"
3989 "Force terminating the process?\n"
3990 "process group id: %d"), -pgid);
3991 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
3994 if (val == G_ALERTDEFAULT) {
3995 gdk_input_remove(compose->exteditor_tag);
3996 close(compose->exteditor_readdes);
3998 if (kill(pgid, SIGTERM) < 0) perror("kill");
3999 waitpid(compose->exteditor_pid, NULL, 0);
4001 g_warning(_("Terminated process group id: %d"), -pgid);
4002 g_warning(_("Temporary file: %s"),
4003 compose->exteditor_file);
4005 compose_set_ext_editor_sensitive(compose, TRUE);
4007 g_free(compose->exteditor_file);
4008 compose->exteditor_file = NULL;
4009 compose->exteditor_pid = -1;
4010 compose->exteditor_readdes = -1;
4011 compose->exteditor_tag = -1;
4019 static void compose_input_cb(gpointer data, gint source,
4020 GdkInputCondition condition)
4023 Compose *compose = (Compose *)data;
4026 debug_print(_("Compose: input from monitoring process\n"));
4028 gdk_input_remove(compose->exteditor_tag);
4031 if (read(source, &buf[i], 1) < 1) {
4035 if (buf[i] == '\n') {
4040 if (i == sizeof(buf) - 1)
4044 waitpid(compose->exteditor_pid, NULL, 0);
4046 if (buf[0] == '0') { /* success */
4047 GtkSText *text = GTK_STEXT(compose->text);
4049 gtk_stext_freeze(text);
4050 gtk_stext_set_point(text, 0);
4051 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
4052 compose_insert_file(compose, compose->exteditor_file);
4053 compose_changed_cb(NULL, compose);
4054 gtk_stext_thaw(text);
4056 if (unlink(compose->exteditor_file) < 0)
4057 FILE_OP_ERROR(compose->exteditor_file, "unlink");
4058 } else if (buf[0] == '1') { /* failed */
4059 g_warning(_("Couldn't exec external editor\n"));
4060 if (unlink(compose->exteditor_file) < 0)
4061 FILE_OP_ERROR(compose->exteditor_file, "unlink");
4062 } else if (buf[0] == '2') {
4063 g_warning(_("Couldn't write to file\n"));
4064 } else if (buf[0] == '3') {
4065 g_warning(_("Pipe read failed\n"));
4070 compose_set_ext_editor_sensitive(compose, TRUE);
4072 g_free(compose->exteditor_file);
4073 compose->exteditor_file = NULL;
4074 compose->exteditor_pid = -1;
4075 compose->exteditor_readdes = -1;
4076 compose->exteditor_tag = -1;
4079 static void compose_set_ext_editor_sensitive(Compose *compose,
4082 GtkItemFactory *ifactory;
4084 ifactory = gtk_item_factory_from_widget(compose->menubar);
4086 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
4087 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
4088 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
4090 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
4091 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
4092 menu_set_sensitive(ifactory, "/Edit/Wrap long lines", sensitive);
4093 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
4096 gtk_widget_set_sensitive(compose->text, sensitive);
4097 gtk_widget_set_sensitive(compose->send_btn, sensitive);
4098 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
4099 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
4100 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
4101 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
4102 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
4103 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
4106 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
4110 cursor_pos = (text->cursor_pos_x - extra) / char_width;
4111 cursor_pos = MAX(cursor_pos, 0);
4116 /* callback functions */
4118 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
4119 * includes "non-client" (windows-izm) in calculation, so this calculation
4120 * may not be accurate.
4122 static gboolean compose_edit_size_alloc(GtkEditable *widget,
4123 GtkAllocation *allocation,
4124 GtkSHRuler *shruler)
4126 if (prefs_common.show_ruler) {
4128 gint line_width_in_chars;
4130 char_width = gtkut_get_font_width
4131 (GTK_WIDGET(widget)->style->font);
4132 line_width_in_chars =
4133 (allocation->width - allocation->x) / char_width;
4135 /* got the maximum */
4136 gtk_ruler_set_range(GTK_RULER(shruler),
4137 0.0, line_width_in_chars,
4138 calc_cursor_xpos(GTK_STEXT(widget),
4141 /*line_width_in_chars*/ char_width);
4147 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
4149 compose_send_cb(data, 0, NULL);
4152 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
4154 compose_send_later_cb(data, 0, NULL);
4157 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
4159 compose_draft_cb(data, 0, NULL);
4162 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
4164 compose_insert_file_cb(data, 0, NULL);
4167 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
4169 compose_attach_cb(data, 0, NULL);
4172 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
4174 Compose *compose = (Compose *)data;
4176 compose_insert_sig(compose);
4179 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
4181 Compose *compose = (Compose *)data;
4183 compose_exec_ext_editor(compose);
4186 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
4188 Compose *compose = (Compose *)data;
4190 compose_wrap_line(compose);
4193 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
4195 compose_address_cb(data, 0, NULL);
4198 static void select_account(Compose * compose, PrefsAccount * ac)
4200 compose->account = ac;
4201 compose_set_title(compose);
4203 if (ac->protocol == A_NNTP) {
4204 GtkItemFactory *ifactory;
4205 GtkWidget *menuitem;
4207 ifactory = gtk_item_factory_from_widget(compose->menubar);
4208 menu_set_sensitive(ifactory,
4209 "/Message/Followup to", TRUE);
4211 gtk_widget_show(compose->newsgroups_hbox);
4212 gtk_widget_show(compose->newsgroups_entry);
4213 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4216 compose->use_to = FALSE;
4217 compose->use_cc = FALSE;
4219 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4220 gtk_check_menu_item_set_active
4221 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
4222 menu_set_sensitive(ifactory,
4223 "/Message/To", TRUE);
4224 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4225 gtk_check_menu_item_set_active
4226 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
4228 gtk_widget_hide(compose->to_hbox);
4229 gtk_widget_hide(compose->to_entry);
4230 gtk_widget_hide(compose->cc_hbox);
4231 gtk_widget_hide(compose->cc_entry);
4233 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4235 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4239 GtkItemFactory *ifactory;
4240 GtkWidget *menuitem;
4242 ifactory = gtk_item_factory_from_widget(compose->menubar);
4243 menu_set_sensitive(ifactory,
4244 "/Message/Followup to", FALSE);
4246 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
4247 gtk_widget_hide(compose->newsgroups_hbox);
4248 gtk_widget_hide(compose->newsgroups_entry);
4249 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4252 compose->use_to = TRUE;
4253 compose->use_cc = TRUE;
4255 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4256 gtk_check_menu_item_set_active
4257 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4258 menu_set_sensitive(ifactory,
4259 "/Message/To", FALSE);
4260 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4261 gtk_check_menu_item_set_active
4262 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4264 gtk_widget_show(compose->to_hbox);
4265 gtk_widget_show(compose->to_entry);
4266 gtk_widget_show(compose->cc_hbox);
4267 gtk_widget_show(compose->cc_entry);
4269 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4271 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4274 gtk_widget_queue_resize(compose->table_vbox);
4277 static void account_activated(GtkMenuItem *menuitem, gpointer data)
4279 Compose *compose = (Compose *)data;
4283 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
4284 g_return_if_fail(ac != NULL);
4286 if (ac != compose->account)
4287 select_account(compose, ac);
4290 static void attach_selected(GtkCList *clist, gint row, gint column,
4291 GdkEvent *event, gpointer data)
4293 Compose *compose = (Compose *)data;
4295 if (event && event->type == GDK_2BUTTON_PRESS)
4296 compose_attach_property(compose);
4299 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
4302 Compose *compose = (Compose *)data;
4303 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4308 if (event->button == 3) {
4309 if ((clist->selection && !clist->selection->next) ||
4310 !clist->selection) {
4311 gtk_clist_unselect_all(clist);
4312 if (gtk_clist_get_selection_info(clist,
4315 gtk_clist_select_row(clist, row, column);
4316 gtkut_clist_set_focus_row(clist, row);
4319 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
4320 NULL, NULL, event->button, event->time);
4324 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
4327 Compose *compose = (Compose *)data;
4331 switch (event->keyval) {
4333 compose_attach_remove_selected(compose);
4338 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
4340 Compose *compose = (Compose *)data;
4343 val = compose_send(compose);
4345 if (val == 0) gtk_widget_destroy(compose->window);
4348 static void compose_send_later_cb(gpointer data, guint action,
4351 Compose *compose = (Compose *)data;
4353 gchar *to, *newsgroups;
4355 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
4356 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
4357 if (*to == '\0' && *newsgroups == '\0') {
4358 alertpanel_error(_("Recipient is not specified."));
4362 g_snprintf(tmp, 22, "%s%ctmpmsg%d",
4363 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
4365 if (prefs_common.linewrap_at_send)
4366 compose_wrap_line(compose);
4368 if (compose_write_to_file(compose, tmp, FALSE) < 0 ||
4369 compose_queue(compose, tmp) < 0) {
4370 alertpanel_error(_("Can't queue the message."));
4374 if (prefs_common.savemsg) {
4375 if (compose_save_to_outbox(compose, tmp) < 0)
4377 (_("Can't save the message to outbox."));
4380 if (unlink(tmp) < 0)
4381 FILE_OP_ERROR(tmp, "unlink");
4383 gtk_widget_destroy(compose->window);
4386 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
4388 Compose *compose = (Compose *)data;
4392 draft = folder_get_default_draft();
4393 folder_item_scan(draft);
4395 if (procmsg_msg_exist(compose->targetinfo) &&
4396 compose->targetinfo->folder == draft) {
4397 if (folder_item_remove_msg(draft,
4398 compose->targetinfo->msgnum) < 0)
4399 g_warning(_("can't remove the old draft message\n"));
4401 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
4402 G_DIR_SEPARATOR, (gint)compose);
4404 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
4409 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
4417 /* folderview_scan_folder_a(DRAFT_DIR, TRUE); */
4419 gtk_widget_destroy(compose->window);
4422 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
4424 Compose *compose = (Compose *)data;
4427 file_list = filesel_select_multiple_files(_("Select file"), NULL);
4432 for ( tmp = file_list; tmp; tmp = tmp->next) {
4433 gchar *file = (gchar *) tmp->data;
4434 compose_attach_append(compose, file, MIME_UNKNOWN);
4437 g_list_free(file_list);
4441 static void compose_insert_file_cb(gpointer data, guint action,
4444 Compose *compose = (Compose *)data;
4447 file_list = filesel_select_multiple_files(_("Select file"), NULL);
4452 for ( tmp = file_list; tmp; tmp = tmp->next) {
4453 gchar *file = (gchar *) tmp->data;
4454 compose_insert_file(compose, file);
4457 g_list_free(file_list);
4461 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
4464 compose_close_cb(data, 0, NULL);
4468 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
4470 Compose *compose = (Compose *)data;
4473 if (compose->exteditor_tag != -1) {
4474 if (!compose_ext_editor_kill(compose))
4478 if (compose->modified) {
4479 val = alertpanel(_("Discard message"),
4480 _("This message has been modified. discard it?"),
4481 _("Discard"), _("to Draft"), _("Cancel"));
4484 case G_ALERTDEFAULT:
4486 case G_ALERTALTERNATE:
4487 compose_draft_cb(data, 0, NULL);
4494 gtk_widget_destroy(compose->window);
4497 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
4499 Compose *compose = (Compose *)data;
4501 addressbook_open(compose);
4504 static void compose_ext_editor_cb(gpointer data, guint action,
4507 Compose *compose = (Compose *)data;
4509 compose_exec_ext_editor(compose);
4512 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
4514 compose_destroy(compose);
4517 static void compose_cut_cb(Compose *compose)
4519 if (compose->focused_editable &&
4520 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4521 gtk_editable_cut_clipboard
4522 (GTK_EDITABLE(compose->focused_editable));
4525 static void compose_copy_cb(Compose *compose)
4527 if (compose->focused_editable &&
4528 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4529 gtk_editable_copy_clipboard
4530 (GTK_EDITABLE(compose->focused_editable));
4533 static void compose_paste_cb(Compose *compose)
4535 if (compose->focused_editable &&
4536 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4537 gtk_editable_paste_clipboard
4538 (GTK_EDITABLE(compose->focused_editable));
4541 static void compose_allsel_cb(Compose *compose)
4543 if (compose->focused_editable &&
4544 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4545 gtk_editable_select_region
4546 (GTK_EDITABLE(compose->focused_editable), 0, -1);
4549 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
4551 if (GTK_IS_EDITABLE(widget))
4552 compose->focused_editable = widget;
4555 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
4557 if (compose->modified == FALSE) {
4558 compose->modified = TRUE;
4559 compose_set_title(compose);
4563 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
4566 gtk_stext_set_point(GTK_STEXT(widget),
4567 gtk_editable_get_position(GTK_EDITABLE(widget)));
4571 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
4574 gtk_stext_set_point(GTK_STEXT(widget),
4575 gtk_editable_get_position(GTK_EDITABLE(widget)));
4579 static void compose_toggle_to_cb(gpointer data, guint action,
4582 Compose *compose = (Compose *)data;
4584 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4585 gtk_widget_show(compose->to_hbox);
4586 gtk_widget_show(compose->to_entry);
4587 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
4588 compose->use_to = TRUE;
4590 gtk_widget_hide(compose->to_hbox);
4591 gtk_widget_hide(compose->to_entry);
4592 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
4593 gtk_widget_queue_resize(compose->table_vbox);
4594 compose->use_to = FALSE;
4597 if (addressbook_get_target_compose() == compose)
4598 addressbook_set_target_compose(compose);
4601 static void compose_toggle_cc_cb(gpointer data, guint action,
4604 Compose *compose = (Compose *)data;
4606 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4607 gtk_widget_show(compose->cc_hbox);
4608 gtk_widget_show(compose->cc_entry);
4609 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
4610 compose->use_cc = TRUE;
4612 gtk_widget_hide(compose->cc_hbox);
4613 gtk_widget_hide(compose->cc_entry);
4614 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
4615 gtk_widget_queue_resize(compose->table_vbox);
4616 compose->use_cc = FALSE;
4619 if (addressbook_get_target_compose() == compose)
4620 addressbook_set_target_compose(compose);
4623 static void compose_toggle_bcc_cb(gpointer data, guint action,
4626 Compose *compose = (Compose *)data;
4628 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4629 gtk_widget_show(compose->bcc_hbox);
4630 gtk_widget_show(compose->bcc_entry);
4631 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
4632 compose->use_bcc = TRUE;
4634 gtk_widget_hide(compose->bcc_hbox);
4635 gtk_widget_hide(compose->bcc_entry);
4636 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
4637 gtk_widget_queue_resize(compose->table_vbox);
4638 compose->use_bcc = FALSE;
4641 if (addressbook_get_target_compose() == compose)
4642 addressbook_set_target_compose(compose);
4645 static void compose_toggle_replyto_cb(gpointer data, guint action,
4648 Compose *compose = (Compose *)data;
4650 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4651 gtk_widget_show(compose->reply_hbox);
4652 gtk_widget_show(compose->reply_entry);
4653 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
4654 compose->use_replyto = TRUE;
4656 gtk_widget_hide(compose->reply_hbox);
4657 gtk_widget_hide(compose->reply_entry);
4658 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
4659 gtk_widget_queue_resize(compose->table_vbox);
4660 compose->use_replyto = FALSE;
4664 static void compose_toggle_followupto_cb(gpointer data, guint action,
4667 Compose *compose = (Compose *)data;
4669 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4670 gtk_widget_show(compose->followup_hbox);
4671 gtk_widget_show(compose->followup_entry);
4672 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
4673 compose->use_followupto = TRUE;
4675 gtk_widget_hide(compose->followup_hbox);
4676 gtk_widget_hide(compose->followup_entry);
4677 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
4678 gtk_widget_queue_resize(compose->table_vbox);
4679 compose->use_followupto = FALSE;
4683 static void compose_toggle_attach_cb(gpointer data, guint action,
4686 Compose *compose = (Compose *)data;
4688 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4689 gtk_widget_ref(compose->edit_vbox);
4691 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4692 compose->edit_vbox);
4693 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
4694 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
4696 gtk_widget_show(compose->paned);
4698 gtk_widget_unref(compose->edit_vbox);
4699 gtk_widget_unref(compose->paned);
4701 compose->use_attach = TRUE;
4703 gtk_widget_ref(compose->paned);
4704 gtk_widget_ref(compose->edit_vbox);
4706 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4708 gtk_container_remove(GTK_CONTAINER(compose->paned),
4709 compose->edit_vbox);
4710 gtk_box_pack_start(GTK_BOX(compose->vbox2),
4711 compose->edit_vbox, TRUE, TRUE, 0);
4713 gtk_widget_unref(compose->edit_vbox);
4715 compose->use_attach = FALSE;
4720 static void compose_toggle_sign_cb(gpointer data, guint action,
4723 Compose *compose = (Compose *)data;
4725 if (GTK_CHECK_MENU_ITEM(widget)->active)
4726 compose->use_signing = TRUE;
4728 compose->use_signing = FALSE;
4731 static void compose_toggle_encrypt_cb(gpointer data, guint action,
4734 Compose *compose = (Compose *)data;
4736 if (GTK_CHECK_MENU_ITEM(widget)->active)
4737 compose->use_encryption = TRUE;
4739 compose->use_encryption = FALSE;
4741 #endif /* USE_GPGME */
4743 static void compose_toggle_ruler_cb(gpointer data, guint action,
4746 Compose *compose = (Compose *)data;
4748 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4749 gtk_widget_show(compose->ruler_hbox);
4750 prefs_common.show_ruler = TRUE;
4752 gtk_widget_hide(compose->ruler_hbox);
4753 gtk_widget_queue_resize(compose->edit_vbox);
4754 prefs_common.show_ruler = FALSE;
4758 static void compose_attach_drag_received_cb (GtkWidget *widget,
4759 GdkDragContext *drag_context,
4762 GtkSelectionData *data,
4767 Compose *compose = (Compose *)user_data;
4770 list = uri_list_extract_filenames((const gchar *)data->data);
4771 for (tmp = list; tmp != NULL; tmp = tmp->next)
4772 compose_attach_append(compose, (const gchar *)tmp->data,
4774 list_free_strings(list);
4778 static void compose_insert_drag_received_cb (GtkWidget *widget,
4779 GdkDragContext *drag_context,
4782 GtkSelectionData *data,
4787 Compose *compose = (Compose *)user_data;
4790 list = uri_list_extract_filenames((const gchar *)data->data);
4791 for (tmp = list; tmp != NULL; tmp = tmp->next)
4792 compose_insert_file(compose, (const gchar *)tmp->data);
4793 list_free_strings(list);
4797 static void to_activated(GtkWidget *widget, Compose *compose)
4799 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
4800 gtk_widget_grab_focus(compose->newsgroups_entry);
4802 gtk_widget_grab_focus(compose->subject_entry);
4805 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
4807 gtk_widget_grab_focus(compose->subject_entry);
4810 static void subject_activated(GtkWidget *widget, Compose *compose)
4812 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
4813 gtk_widget_grab_focus(compose->cc_entry);
4814 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4815 gtk_widget_grab_focus(compose->bcc_entry);
4816 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4817 gtk_widget_grab_focus(compose->reply_entry);
4818 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4819 gtk_widget_grab_focus(compose->followup_entry);
4821 gtk_widget_grab_focus(compose->text);
4824 static void cc_activated(GtkWidget *widget, Compose *compose)
4826 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4827 gtk_widget_grab_focus(compose->bcc_entry);
4828 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4829 gtk_widget_grab_focus(compose->reply_entry);
4830 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4831 gtk_widget_grab_focus(compose->followup_entry);
4833 gtk_widget_grab_focus(compose->text);
4836 static void bcc_activated(GtkWidget *widget, Compose *compose)
4838 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4839 gtk_widget_grab_focus(compose->reply_entry);
4840 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4841 gtk_widget_grab_focus(compose->followup_entry);
4843 gtk_widget_grab_focus(compose->text);
4846 static void replyto_activated(GtkWidget *widget, Compose *compose)
4848 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4849 gtk_widget_grab_focus(compose->followup_entry);
4851 gtk_widget_grab_focus(compose->text);
4854 static void followupto_activated(GtkWidget *widget, Compose *compose)
4856 gtk_widget_grab_focus(compose->text);
4859 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
4862 Compose *compose = (Compose *)data;
4864 if (GTK_CHECK_MENU_ITEM(widget)->active)
4865 compose->return_receipt = TRUE;
4867 compose->return_receipt = FALSE;
4870 static gchar *compose_quote_fmt (Compose *compose,
4875 gchar * quote_str = NULL;
4877 if (qmark != NULL) {
4880 quote_fmt_init(msginfo, NULL);
4881 quote_fmt_scan_string(qmark);
4884 p = quote_fmt_get_buffer();
4887 (_("Quote mark format error."));
4890 quote_str = alloca(strlen(p) + 1);
4891 strcpy(quote_str, p);
4895 quote_fmt_init(msginfo, quote_str);
4896 quote_fmt_scan_string(fmt);
4899 if (quote_fmt_get_buffer() == NULL)
4901 (_("Message reply/forward format error."));
4903 return quote_fmt_get_buffer();
4906 static void template_apply_cb(gchar *s, gpointer data)
4908 Compose *compose = (Compose*)data;
4909 GtkSText *text = GTK_STEXT(compose->text);
4914 gchar *old_tmpl = s;
4918 if(compose->replyinfo == NULL) {
4919 gtk_stext_freeze(text);
4920 gtk_stext_set_point(text, 0);
4921 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
4922 gtk_stext_insert(text, NULL, NULL, NULL, s, -1);
4923 gtk_stext_thaw(text);
4928 parsed_text = g_new(gchar, strlen(s)*2 + 1);
4932 *parsed_text++ = '\\';
4933 *parsed_text++ = 'n';
4936 *parsed_text++ = *s++;
4939 *parsed_text = '\0';
4941 if (prefs_common.quotemark && *prefs_common.quotemark)
4942 qmark = prefs_common.quotemark;
4946 quote_str = compose_quote_fmt(compose, compose->replyinfo, tmpl, qmark);
4947 if (quote_str != NULL) {
4948 gtk_stext_freeze(text);
4949 gtk_stext_set_point(text, 0);
4950 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
4951 gtk_stext_insert(text, NULL, NULL, NULL, quote_str, -1);
4952 gtk_stext_thaw(text);
4959 static void template_select_cb(gpointer data, guint action,
4962 template_select(&template_apply_cb, data);