2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
31 #include <gtk/gtkitemfactory.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkclist.h>
36 #include <gtk/gtkctree.h>
37 #include <gtk/gtkvpaned.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkeditable.h>
40 #include <gtk/gtkwindow.h>
41 #include <gtk/gtksignal.h>
42 #include <gtk/gtkvbox.h>
43 #include <gtk/gtkcontainer.h>
44 #include <gtk/gtkhandlebox.h>
45 #include <gtk/gtktoolbar.h>
46 #include <gtk/gtktable.h>
47 #include <gtk/gtkhbox.h>
48 #include <gtk/gtklabel.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtkthemes.h>
51 #include <gtk/gtkdnd.h>
58 /* #include <sys/utsname.h> */
64 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
74 #include "mainwindow.h"
76 #include "addressbook.h"
77 #include "folderview.h"
82 #include "customheader.h"
83 #include "prefs_common.h"
84 #include "prefs_account.h"
87 #include "procheader.h"
89 #include "statusbar.h"
96 #include "alertpanel.h"
97 #include "manage_window.h"
98 #include "gtkshruler.h"
100 #include "addr_compl.h"
101 #include "template_select.h"
104 # include "rfc2015.h"
107 #include "quote_fmt.h"
116 #define N_ATTACH_COLS 3
118 #define B64_LINE_SIZE 57
119 #define B64_BUFFSIZE 77
121 #define MAX_REFERENCES_LEN 999
123 static GdkColor quote_color = {0, 0, 0, 0xbfff};
125 static GList *compose_list = NULL;
127 static Compose *compose_create (PrefsAccount *account);
128 static void compose_toolbar_create (Compose *compose,
129 GtkWidget *container);
130 static GtkWidget *compose_account_option_menu_create
132 static void compose_destroy (Compose *compose);
134 static gint compose_parse_header (Compose *compose,
136 static gchar *compose_parse_references (const gchar *ref,
138 static void compose_quote_file (Compose *compose,
141 static gchar *compose_quote_parse_fmt (Compose *compose,
144 static void compose_reply_set_entry (Compose *compose,
149 followup_and_reply_to);
150 static void compose_reedit_set_entry (Compose *compose,
152 static void compose_insert_sig (Compose *compose);
153 static void compose_insert_file (Compose *compose,
155 static void compose_attach_append (Compose *compose,
157 ContentType cnttype);
158 static void compose_attach_append_with_type(Compose *compose,
161 ContentType cnttype);
162 static void compose_wrap_line (Compose *compose);
163 static void compose_set_title (Compose *compose);
165 static PrefsAccount *compose_current_mail_account(void);
166 /* static gint compose_send (Compose *compose); */
167 static gint compose_write_to_file (Compose *compose,
170 static gint compose_write_body_to_file (Compose *compose,
172 static gint compose_save_to_outbox (Compose *compose,
174 static gint compose_remove_reedit_target (Compose *compose);
175 static gint compose_queue (Compose *compose,
177 static void compose_write_attach (Compose *compose,
179 static gint compose_write_headers (Compose *compose,
181 const gchar *charset,
182 EncodingType encoding,
185 static void compose_convert_header (gchar *dest,
189 static void compose_generate_msgid (Compose *compose,
193 static void compose_attach_info_free (AttachInfo *ainfo);
194 static void compose_attach_remove_selected (Compose *compose);
196 static void compose_attach_property (Compose *compose);
197 static void compose_attach_property_create (gboolean *cancelled);
198 static void attach_property_ok (GtkWidget *widget,
199 gboolean *cancelled);
200 static void attach_property_cancel (GtkWidget *widget,
201 gboolean *cancelled);
202 static gint attach_property_delete_event (GtkWidget *widget,
204 gboolean *cancelled);
205 static void attach_property_key_pressed (GtkWidget *widget,
207 gboolean *cancelled);
209 static void compose_exec_ext_editor (Compose *compose);
210 static gint compose_exec_ext_editor_real (const gchar *file);
211 static gboolean compose_ext_editor_kill (Compose *compose);
212 static void compose_input_cb (gpointer data,
214 GdkInputCondition condition);
215 static void compose_set_ext_editor_sensitive (Compose *compose,
218 static gint calc_cursor_xpos (GtkSText *text,
222 /* callback functions */
224 static gboolean compose_edit_size_alloc (GtkEditable *widget,
225 GtkAllocation *allocation,
226 GtkSHRuler *shruler);
228 static void toolbar_send_cb (GtkWidget *widget,
230 static void toolbar_send_later_cb (GtkWidget *widget,
232 static void toolbar_draft_cb (GtkWidget *widget,
234 static void toolbar_insert_cb (GtkWidget *widget,
236 static void toolbar_attach_cb (GtkWidget *widget,
238 static void toolbar_sig_cb (GtkWidget *widget,
240 static void toolbar_ext_editor_cb (GtkWidget *widget,
242 static void toolbar_linewrap_cb (GtkWidget *widget,
244 static void toolbar_address_cb (GtkWidget *widget,
246 static void template_select_cb (gpointer daat,
251 static void select_account(Compose * compose, PrefsAccount * ac);
252 static void account_activated (GtkMenuItem *menuitem,
255 static void attach_selected (GtkCList *clist,
260 static void attach_button_pressed (GtkWidget *widget,
261 GdkEventButton *event,
263 static void attach_key_pressed (GtkWidget *widget,
267 static void compose_send_cb (gpointer data,
270 static void compose_send_later_cb (gpointer data,
274 static void compose_draft_cb (gpointer data,
278 static void compose_attach_cb (gpointer data,
281 static void compose_insert_file_cb (gpointer data,
285 static void compose_close_cb (gpointer data,
288 static void compose_address_cb (gpointer data,
292 static void compose_ext_editor_cb (gpointer data,
296 static gint compose_delete_cb (GtkWidget *widget,
299 static void compose_destroy_cb (GtkWidget *widget,
302 static void compose_cut_cb (Compose *compose);
303 static void compose_copy_cb (Compose *compose);
304 static void compose_paste_cb (Compose *compose);
305 static void compose_allsel_cb (Compose *compose);
307 static void compose_grab_focus_cb (GtkWidget *widget,
310 static void compose_changed_cb (GtkEditable *editable,
312 static void compose_button_press_cb (GtkWidget *widget,
313 GdkEventButton *event,
316 static void compose_key_press_cb (GtkWidget *widget,
321 static void compose_toggle_to_cb (gpointer data,
324 static void compose_toggle_cc_cb (gpointer data,
327 static void compose_toggle_bcc_cb (gpointer data,
330 static void compose_toggle_replyto_cb (gpointer data,
333 static void compose_toggle_followupto_cb(gpointer data,
336 static void compose_toggle_attach_cb (gpointer data,
339 static void compose_toggle_ruler_cb (gpointer data,
343 static void compose_toggle_sign_cb (gpointer data,
346 static void compose_toggle_encrypt_cb (gpointer data,
350 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
353 static void compose_attach_drag_received_cb (GtkWidget *widget,
354 GdkDragContext *drag_context,
357 GtkSelectionData *data,
361 static void compose_insert_drag_received_cb (GtkWidget *widget,
362 GdkDragContext *drag_context,
365 GtkSelectionData *data,
370 static void to_activated (GtkWidget *widget,
372 static void newsgroups_activated (GtkWidget *widget,
374 static void subject_activated (GtkWidget *widget,
376 static void cc_activated (GtkWidget *widget,
378 static void bcc_activated (GtkWidget *widget,
380 static void replyto_activated (GtkWidget *widget,
382 static void followupto_activated (GtkWidget *widget,
384 static void compose_attach_parts(Compose * compose,
387 static gchar *compose_quote_fmt (Compose *compose,
390 const gchar * qmark);
392 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
394 gboolean ignore_replyto,
395 gboolean followup_and_reply_to);
397 Compose * compose_generic_new (PrefsAccount *account,
401 static GtkItemFactoryEntry compose_popup_entries[] =
403 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
404 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
405 {N_("/---"), NULL, NULL, 0, "<Separator>"},
406 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
409 static GtkItemFactoryEntry compose_entries[] =
411 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
412 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
413 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
414 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
415 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
416 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
418 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
419 {N_("/_Edit/_Undo"), "<control>Z", NULL, 0, NULL},
420 {N_("/_Edit/_Redo"), "<control>Y", NULL, 0, NULL},
421 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
422 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
423 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
424 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
425 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
426 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
427 {N_("/_Edit/Wrap long _lines"), "<alt>L", compose_wrap_line, 0, NULL},
428 {N_("/_Edit/Edit with e_xternal editor"), "<alt>X",
429 compose_ext_editor_cb, 0, NULL},
431 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
432 {N_("/_Message/_Send"), "<shift><control>S",
433 compose_send_cb, 0, NULL},
434 {N_("/_Message/Send _later"), "<shift><alt>S",
435 compose_send_later_cb, 0, NULL},
436 {N_("/_Message/Save to _draft folder"),
437 "<alt>D", compose_draft_cb, 0, NULL},
438 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
439 {N_("/_Message/_To"), NULL, compose_toggle_to_cb, 0, "<ToggleItem>"},
440 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb, 0, "<ToggleItem>"},
441 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb, 0, "<ToggleItem>"},
442 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
443 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
444 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
445 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
446 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
448 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
449 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb, 0, "<ToggleItem>"},
450 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
451 #endif /* USE_GPGME */
452 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
453 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
454 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
455 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
456 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb, 0, NULL},
457 {N_("/_Tool/_Templates ..."), NULL, template_select_cb, 0, NULL},
458 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
459 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
462 static GtkTargetEntry compose_mime_types[] =
464 {"text/uri-list", 0, 0}
467 Compose * compose_new(PrefsAccount *account)
469 return compose_generic_new(account, NULL, NULL);
472 Compose * compose_new_with_recipient(PrefsAccount *account, const gchar *to)
474 return compose_generic_new(account, to, NULL);
477 Compose * compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
479 return compose_generic_new(account, NULL, item);
482 Compose * compose_generic_new(PrefsAccount *account, const gchar *to, FolderItem *item)
486 if (!account) account = cur_account;
487 g_return_val_if_fail(account != NULL, NULL);
489 compose = compose_create(account);
490 compose->mode = COMPOSE_NEW;
491 compose->replyinfo = NULL;
493 if (prefs_common.auto_sig)
494 compose_insert_sig(compose);
495 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
496 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
498 if (account->protocol != A_NNTP) {
500 compose_entry_append(compose, to, COMPOSE_TO);
501 gtk_widget_grab_focus(compose->subject_entry);
503 if(item && item->prefs->enable_default_to) {
504 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
506 gtk_widget_grab_focus(compose->to_entry);
509 if(item && item->prefs->request_return_receipt) {
510 GtkItemFactory *ifactory;
512 ifactory = gtk_item_factory_from_widget(compose->menubar);
513 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
517 compose_entry_append(compose, to, COMPOSE_NEWSGROUPS);
518 gtk_widget_grab_focus(compose->subject_entry);
520 gtk_widget_grab_focus(compose->newsgroups_entry);
526 #define CHANGE_FLAGS(msginfo) \
528 if (msginfo->folder->folder->change_flags != NULL) \
529 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
535 Compose * compose_new_followup_and_replyto(PrefsAccount *account,
536 const gchar *followupto, gchar * to)
540 if (!account) account = cur_account;
541 g_return_val_if_fail(account != NULL, NULL);
542 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
544 compose = compose_create(account);
545 compose->mode = COMPOSE_NEW;
547 if (prefs_common.auto_sig)
548 compose_insert_sig(compose);
549 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
550 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
552 compose_entry_append(compose, to, COMPOSE_TO);
553 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
554 gtk_widget_grab_focus(compose->subject_entry);
560 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
561 gboolean ignore_replyto)
563 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
566 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
568 gboolean ignore_replyto)
570 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
573 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
575 gboolean ignore_replyto,
576 gboolean followup_and_reply_to)
579 PrefsAccount *account;
580 PrefsAccount *reply_account;
583 g_return_if_fail(msginfo != NULL);
584 g_return_if_fail(msginfo->folder != NULL);
586 account = msginfo->folder->folder->account;
587 if (!account && msginfo->to && prefs_common.reply_account_autosel) {
589 Xstrdup_a(to, msginfo->to, return);
591 account = account_find_from_address(to);
593 if(!account&& prefs_common.reply_account_autosel) {
595 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
597 account = account_find_from_address(cc);
601 if (!account) account = cur_account;
602 g_return_if_fail(account != NULL);
604 if (ignore_replyto && account->protocol == A_NNTP &&
605 !followup_and_reply_to) {
607 account_find_from_address(account->address);
609 reply_account = compose_current_mail_account();
613 reply_account = account;
614 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
615 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
617 CHANGE_FLAGS(msginfo);
619 compose = compose_create(reply_account);
620 compose->mode = COMPOSE_REPLY;
621 compose->replyinfo = msginfo;
624 if (followup_and_reply_to) {
625 gtk_widget_show(compose->to_hbox);
626 gtk_widget_show(compose->to_entry);
627 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
628 compose->use_to = TRUE;
631 if(msginfo->folder && msginfo->folder->prefs->request_return_receipt) {
632 GtkItemFactory *ifactory;
634 ifactory = gtk_item_factory_from_widget(compose->menubar);
635 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
638 if (compose_parse_header(compose, msginfo) < 0) return;
639 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
640 followup_and_reply_to);
642 text = GTK_STEXT(compose->text);
643 gtk_stext_freeze(text);
649 if ((fp = procmime_get_text_part(msginfo)) == NULL)
650 g_warning(_("Can't get text part\n"));
654 if (prefs_common.quotemark && *prefs_common.quotemark)
655 qmark = prefs_common.quotemark;
659 quote_str = compose_quote_fmt(compose, msginfo,
660 prefs_common.quotefmt,
664 quote_str = compose_quote_parse_fmt
665 (compose, msginfo, prefs_common.quotefmt);
668 if (quote_str != NULL)
669 gtk_stext_insert(text, NULL, NULL, NULL,
671 /* g_free(quote_str); */
672 /* compose_quote_file(compose, msginfo, fp); */
677 if (prefs_common.auto_sig)
678 compose_insert_sig(compose);
679 gtk_editable_set_position(GTK_EDITABLE(text), 0);
680 gtk_stext_set_point(text, 0);
682 gtk_stext_thaw(text);
683 gtk_widget_grab_focus(compose->text);
687 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
692 g_return_val_if_fail(mimeinfo != NULL, NULL);
694 base = mimeinfo->filename ? mimeinfo->filename
695 : mimeinfo->name ? mimeinfo->name : NULL;
697 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
698 filename = g_strdup_printf("%s%smimetmp%i.html",
705 base = base ? base : "";
706 base = g_basename(base);
708 filename = g_strdup_printf("%s%smimetmp%i",
716 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
722 static gchar * mime_extract_file(gchar * source, MimeInfo *partinfo)
726 if (!partinfo) return;
728 filename = procmime_get_file_name(partinfo);
730 if (procmime_get_part(filename, source, partinfo) < 0)
732 (_("Can't get the part of multipart message."));
737 static void compose_attach_parts(Compose * compose,
747 gint boundary_len = 0;
749 glong fpos, prev_fpos;
754 g_return_if_fail(msginfo != NULL);
758 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
759 mimeinfo = procmime_scan_mime_header(fp);
760 if (!mimeinfo) break;
762 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
763 rfc2015_is_encrypted(mimeinfo)) {
764 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
766 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
767 !msginfo->plaintext_file &&
768 !msginfo->decryption_failed) {
769 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
770 if (msginfo->plaintext_file &&
771 !msginfo->decryption_failed) {
779 #else /* !USE_GPGME */
780 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
781 mimeinfo = procmime_scan_mime_header(fp);
782 #endif /* USE_GPGME */
785 if (!mimeinfo) return;
786 if (mimeinfo->mime_type == MIME_TEXT)
789 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
791 g_return_if_fail(mimeinfo != NULL);
792 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
794 if (mimeinfo->mime_type == MIME_MULTIPART) {
795 g_return_if_fail(mimeinfo->boundary != NULL);
796 g_return_if_fail(mimeinfo->sub == NULL);
798 g_return_if_fail(fp != NULL);
800 boundary = mimeinfo->boundary;
803 boundary_len = strlen(boundary);
805 /* look for first boundary */
806 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
807 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
814 if ((fpos = ftell(fp)) < 0) {
820 for (npart = 0;; npart++) {
822 gboolean eom = FALSE;
826 partinfo = procmime_scan_mime_header(fp);
827 if (!partinfo) break;
830 procmime_mimeinfo_insert(mimeinfo, partinfo);
832 procmime_mimeinfo_free(partinfo);
834 /* look for next boundary */
836 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
837 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
838 if (buf[2 + boundary_len] == '-' &&
839 buf[2 + boundary_len + 1] == '-')
845 eom = TRUE; /* broken MIME message */
848 partinfo->size = fpos - prev_fpos - strlen(buf);
853 source = procmsg_get_message_file_path(msginfo);
855 g_return_if_fail(mimeinfo != NULL);
857 if (!mimeinfo->main && mimeinfo->parent)
859 filename = mime_extract_file(source, mimeinfo);
861 compose_attach_append_with_type(compose, filename,
862 mimeinfo->content_type,
863 mimeinfo->mime_type);
868 if (mimeinfo->sub && mimeinfo->sub->children)
870 filename = mime_extract_file(source, mimeinfo->sub);
872 compose_attach_append_with_type(compose, filename,
873 mimeinfo->content_type,
874 mimeinfo->sub->mime_type);
879 if (mimeinfo->children) {
882 child = mimeinfo->children;
884 filename = mime_extract_file(source, child);
886 compose_attach_append_with_type(compose, filename,
898 procmime_mimeinfo_free_all(mimeinfo);
902 #define INSERT_FW_HEADER(var, hdr) \
903 if (msginfo->var && *msginfo->var) { \
904 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
905 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
906 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
909 Compose * compose_forward(PrefsAccount * account, MsgInfo *msginfo,
913 /* PrefsAccount *account; */
918 g_return_val_if_fail(msginfo != NULL, NULL);
919 g_return_val_if_fail(msginfo->folder != NULL, NULL);
921 account = msginfo->folder->folder->account;
922 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
924 Xstrdup_a(to, msginfo->to, return);
926 account = account_find_from_address(to);
929 if(!account&& prefs_common.forward_account_autosel) {
931 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
933 account = account_find_from_address(cc);
937 if (account == NULL) {
938 account = cur_account;
940 account = msginfo->folder->folder->account;
941 if (!account) account = cur_account;
944 g_return_val_if_fail(account != NULL, NULL);
946 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
947 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
948 CHANGE_FLAGS(msginfo);
950 compose = compose_create(account);
951 compose->mode = COMPOSE_FORWARD;
953 if (msginfo->subject && *msginfo->subject) {
954 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
955 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
959 text = GTK_STEXT(compose->text);
960 gtk_stext_freeze(text);
965 msgfile = procmsg_get_message_file_path(msginfo);
966 if (!is_file_exist(msgfile))
967 g_warning(_("%s: file not exist\n"), msgfile);
969 compose_attach_append(compose, msgfile,
970 MIME_MESSAGE_RFC822);
977 if ((fp = procmime_get_text_part(msginfo)) == NULL)
978 g_warning(_("Can't get text part\n"));
982 if (prefs_common.fw_quotemark &&
983 *prefs_common.fw_quotemark)
984 qmark = prefs_common.fw_quotemark;
988 quote_str = compose_quote_fmt(compose, msginfo,
989 prefs_common.fw_quotefmt,
992 if (quote_str != NULL)
993 gtk_stext_insert(text, NULL, NULL, NULL,
999 compose_attach_parts(compose, msginfo);
1002 if (prefs_common.auto_sig)
1003 compose_insert_sig(compose);
1004 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1005 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1007 gtk_stext_thaw(text);
1008 if (account->protocol != A_NNTP)
1009 gtk_widget_grab_focus(compose->to_entry);
1011 gtk_widget_grab_focus(compose->newsgroups_entry);
1016 #undef INSERT_FW_HEADER
1018 Compose * compose_forward_multiple(PrefsAccount * account,
1019 GSList *msginfo_list)
1026 g_return_val_if_fail(msginfo_list != NULL, NULL);
1028 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1029 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1033 if (account == NULL) {
1034 account = cur_account;
1036 account = msginfo->folder->folder->account;
1037 if (!account) account = cur_account;
1040 g_return_val_if_fail(account != NULL, NULL);
1042 compose = compose_create(account);
1043 compose->mode = COMPOSE_FORWARD;
1045 text = GTK_STEXT(compose->text);
1046 gtk_stext_freeze(text);
1048 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1049 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1050 if (!is_file_exist(msgfile))
1051 g_warning(_("%s: file not exist\n"), msgfile);
1053 compose_attach_append(compose, msgfile,
1054 MIME_MESSAGE_RFC822);
1058 if (prefs_common.auto_sig)
1059 compose_insert_sig(compose);
1060 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1061 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1063 gtk_stext_thaw(text);
1064 if (account->protocol != A_NNTP)
1065 gtk_widget_grab_focus(compose->to_entry);
1067 gtk_widget_grab_focus(compose->newsgroups_entry);
1072 void compose_reedit(MsgInfo *msginfo)
1075 PrefsAccount *account;
1078 gchar buf[BUFFSIZE];
1080 g_return_if_fail(msginfo != NULL);
1081 g_return_if_fail(msginfo->folder != NULL);
1083 if(!account&& prefs_common.reedit_account_autosel) {
1084 gchar from[BUFFSIZE];
1085 if(!get_header_from_msginfo(msginfo,from,sizeof(from),"FROM:")){ /* Found a FROM header */
1086 extract_address(from);
1087 account = account_find_from_address(from);
1090 if (!account) account = cur_account;
1091 g_return_if_fail(account != NULL);
1093 compose = compose_create(account);
1094 compose->mode = COMPOSE_REEDIT;
1096 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1098 if (compose_parse_header(compose, msginfo) < 0) return;
1099 compose_reedit_set_entry(compose, msginfo);
1101 text = GTK_STEXT(compose->text);
1102 gtk_stext_freeze(text);
1104 if ((fp = procmime_get_text_part(msginfo)) == NULL)
1105 g_warning(_("Can't get text part\n"));
1107 while (fgets(buf, sizeof(buf), fp) != NULL)
1108 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1111 compose_attach_parts(compose, msginfo);
1113 gtk_stext_thaw(text);
1114 gtk_widget_grab_focus(compose->text);
1117 GList *compose_get_compose_list(void)
1119 return compose_list;
1122 void compose_entry_append(Compose *compose, const gchar *address,
1123 ComposeEntryType type)
1128 if (!address || *address == '\0') return;
1132 entry = GTK_ENTRY(compose->cc_entry);
1135 entry = GTK_ENTRY(compose->bcc_entry);
1137 case COMPOSE_NEWSGROUPS:
1138 entry = GTK_ENTRY(compose->newsgroups_entry);
1142 entry = GTK_ENTRY(compose->to_entry);
1146 text = gtk_entry_get_text(entry);
1148 gtk_entry_append_text(entry, ", ");
1149 gtk_entry_append_text(entry, address);
1152 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1154 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1155 {"Cc:", NULL, FALSE},
1156 {"References:", NULL, FALSE},
1157 {"Bcc:", NULL, FALSE},
1158 {"Newsgroups:", NULL, FALSE},
1159 {"Followup-To:", NULL, FALSE},
1160 {NULL, NULL, FALSE}};
1174 g_return_val_if_fail(msginfo != NULL, -1);
1176 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1177 procheader_get_header_fields(fp, hentry);
1180 if (hentry[H_REPLY_TO].body != NULL) {
1181 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1182 compose->replyto = hentry[H_REPLY_TO].body;
1183 hentry[H_REPLY_TO].body = NULL;
1185 if (hentry[H_CC].body != NULL) {
1186 conv_unmime_header_overwrite(hentry[H_CC].body);
1187 compose->cc = hentry[H_CC].body;
1188 hentry[H_CC].body = NULL;
1190 if (hentry[H_REFERENCES].body != NULL) {
1191 if (compose->mode == COMPOSE_REEDIT)
1192 compose->references = hentry[H_REFERENCES].body;
1194 compose->references = compose_parse_references
1195 (hentry[H_REFERENCES].body, msginfo->msgid);
1196 g_free(hentry[H_REFERENCES].body);
1198 hentry[H_REFERENCES].body = NULL;
1200 if (hentry[H_BCC].body != NULL) {
1201 if (compose->mode == COMPOSE_REEDIT) {
1202 conv_unmime_header_overwrite(hentry[H_BCC].body);
1203 compose->bcc = hentry[H_BCC].body;
1205 g_free(hentry[H_BCC].body);
1206 hentry[H_BCC].body = NULL;
1208 if (hentry[H_NEWSGROUPS].body != NULL) {
1209 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1210 hentry[H_NEWSGROUPS].body = NULL;
1212 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1213 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1214 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1215 hentry[H_FOLLOWUP_TO].body = NULL;
1218 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1219 compose->inreplyto = g_strdup(msginfo->inreplyto);
1220 else if (compose->mode != COMPOSE_REEDIT &&
1221 msginfo->msgid && *msginfo->msgid) {
1222 compose->inreplyto = g_strdup(msginfo->msgid);
1224 if (!compose->references) {
1225 if (msginfo->inreplyto && *msginfo->inreplyto)
1226 compose->references =
1227 g_strdup_printf("<%s>\n\t<%s>",
1231 compose->references =
1232 g_strconcat("<", msginfo->msgid, ">",
1240 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1242 GSList *ref_id_list, *cur;
1246 ref_id_list = references_list_append(NULL, ref);
1247 if (!ref_id_list) return NULL;
1248 if (msgid && *msgid)
1249 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1254 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1255 /* "<" + Message-ID + ">" + CR+LF+TAB */
1256 len += strlen((gchar *)cur->data) + 5;
1258 if (len > MAX_REFERENCES_LEN) {
1259 /* remove second message-ID */
1260 if (ref_id_list && ref_id_list->next &&
1261 ref_id_list->next->next) {
1262 g_free(ref_id_list->next->data);
1263 ref_id_list = g_slist_remove
1264 (ref_id_list, ref_id_list->next->data);
1266 slist_free_strings(ref_id_list);
1267 g_slist_free(ref_id_list);
1274 new_ref = g_string_new("");
1275 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1276 if (new_ref->len > 0)
1277 g_string_append(new_ref, "\n\t");
1278 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1281 slist_free_strings(ref_id_list);
1282 g_slist_free(ref_id_list);
1284 new_ref_str = new_ref->str;
1285 g_string_free(new_ref, FALSE);
1291 static void compose_quote_file(Compose *compose, MsgInfo *msginfo, FILE *fp)
1293 GtkSText *text = GTK_STEXT(compose->text);
1296 GdkColor *qcolor = NULL;
1297 gchar buf[BUFFSIZE];
1299 gchar *linep, *cur, *leftp;
1300 gint line_len, cur_len;
1305 // if (prefs_common.enable_color) qcolor = "e_color;
1306 if (prefs_common.quotemark && *prefs_common.quotemark)
1307 qmark = prefs_common.quotemark;
1310 quote_str = compose_quote_parse_fmt(compose, msginfo, qmark);
1311 g_return_if_fail(quote_str != NULL);
1312 qlen = strlen(quote_str);
1314 if (!prefs_common.linewrap_quote ||
1315 prefs_common.linewrap_len <= qlen) {
1316 while (fgets(buf, sizeof(buf), fp) != NULL) {
1317 gtk_stext_insert(text, NULL, qcolor, NULL,
1319 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1325 wrap_len = prefs_common.linewrap_len - qlen;
1327 while (fgets(buf, sizeof(buf), fp) != NULL) {
1329 str_len = strlen(buf);
1331 if (str_len <= wrap_len) {
1332 gtk_stext_insert(text, NULL, qcolor, NULL,
1334 gtk_stext_insert(text, NULL, qcolor, NULL, buf, -1);
1335 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1339 linep = cur = leftp = buf;
1340 line_len = cur_len = 0;
1342 while (*cur != '\0') {
1343 ch_len = mblen(cur, MB_CUR_MAX);
1344 if (ch_len < 0) ch_len = 1;
1346 if (ch_len == 1 && isspace(*cur)) {
1347 linep = cur + ch_len;
1348 line_len = cur_len + ch_len;
1351 if (cur_len + ch_len > wrap_len && line_len > 0) {
1352 gtk_stext_insert(text, NULL, qcolor, NULL,
1355 if (isspace(*(linep - 1)))
1356 gtk_stext_insert(text, NULL,
1358 leftp, line_len - 1);
1360 gtk_stext_insert(text, NULL,
1363 gtk_stext_insert(text, NULL, NULL, NULL,
1367 cur_len = cur_len - line_len + ch_len;
1374 linep = cur + ch_len;
1375 line_len = cur_len + ch_len;
1382 gtk_stext_insert(text, NULL, qcolor, NULL,
1384 gtk_stext_insert(text, NULL, qcolor, NULL, leftp, -1);
1385 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1394 static gchar *compose_quote_parse_fmt(Compose *compose, MsgInfo *msginfo,
1398 size_t buf_len = 1024;
1406 if (!fmt || *fmt == '\0') return 0;
1408 Xalloca(mbs, sizeof(wchar_t) + 1, return 0);
1409 Xalloca(wcsfmt, (strlen(fmt) + 1) * sizeof(wchar_t), return 0);
1410 mbstowcs(wcsfmt, fmt, strlen(fmt) + 1);
1413 ext_str = g_malloc(sizeof(gchar) * buf_len);
1414 g_return_val_if_fail(ext_str != NULL, NULL);
1419 len = wctomb(mbs, *sp);
1425 wctomb(mbs, *(++sp));
1430 str = msginfo->date;
1434 str = msginfo->from;
1438 if (!msginfo->fromname) {sp++; break;}
1439 p = msginfo->fromname;
1440 tmp[0] = tmp[1] = tmp[2] = '\0';
1442 if (*p && isalnum(*p))
1443 tmp[0] = toupper(*p);
1450 while (*p && !isspace(*p)) p++;
1451 while (*p && isspace(*p)) p++;
1452 if (*p && isalnum(*p))
1453 tmp[1] = toupper(*p);
1456 if (tmp[1]) str = tmp;
1460 str = msginfo->fromname;
1464 if (!msginfo->fromname) {sp++; break;}
1465 Xstrdup_a(str, msginfo->fromname,
1468 while (*p && !isspace(*p)) p++;
1473 str = msginfo->subject;
1485 if (!msginfo->msgid) {sp++; break;}
1486 Xalloca(str, strlen(msginfo->msgid) + 3,
1488 g_snprintf(str, strlen(msginfo->msgid) + 3,
1489 "<%s>", msginfo->msgid);
1501 while (ext_len + strlen(str) + 1 > buf_len)
1503 ext_str = g_realloc(ext_str,
1504 sizeof(gchar) * buf_len);
1505 g_return_val_if_fail(ext_str != NULL, NULL);
1506 strcpy(ext_str + ext_len, str);
1507 ext_len += strlen(str);
1509 } else if (*mbs == '\\') {
1510 wctomb(mbs, *(++sp));
1528 while (ext_len + strlen(str) + 1 > buf_len)
1530 ext_str = g_realloc(ext_str,
1531 sizeof(gchar) * buf_len);
1532 g_return_val_if_fail(ext_str != NULL, NULL);
1533 strcpy(ext_str + ext_len, str);
1534 ext_len += strlen(str);
1538 while (ext_len + len + 1 > buf_len) buf_len += 1024;
1539 ext_str = g_realloc(ext_str, sizeof(gchar) * buf_len);
1540 g_return_val_if_fail(ext_str != NULL, NULL);
1541 strcpy(ext_str + ext_len, mbs);
1548 ext_str = g_realloc(ext_str, strlen(ext_str) + 1);
1554 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1555 gboolean to_all, gboolean ignore_replyto,
1556 gboolean followup_and_reply_to)
1561 GHashTable *to_table;
1563 g_return_if_fail(compose->account != NULL);
1564 g_return_if_fail(msginfo != NULL);
1566 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1567 gtk_entry_set_text(GTK_ENTRY(compose->to_entry),
1568 ( (compose->replyto && !ignore_replyto)
1570 : msginfo->from ? msginfo->from : ""));
1571 if (compose->account->protocol == A_NNTP)
1572 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry),
1573 compose->followup_to ? compose->followup_to
1574 : compose->newsgroups ? compose->newsgroups
1577 if (msginfo->subject && *msginfo->subject) {
1578 gchar *buf, *buf2, *p;
1580 buf = g_strdup(msginfo->subject);
1581 while (!strncasecmp(buf, "Re:", 3)) {
1583 while (isspace(*p)) p++;
1584 memmove(buf, p, strlen(p) + 1);
1587 buf2 = g_strdup_printf("Re: %s", buf);
1588 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1592 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1594 if (!to_all || compose->account->protocol == A_NNTP) return;
1596 from = g_strdup(compose->replyto ? compose->replyto :
1597 msginfo->from ? msginfo->from : "");
1598 extract_address(from);
1600 cc_list = address_list_append(NULL, msginfo->to);
1601 cc_list = address_list_append(cc_list, compose->cc);
1603 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1604 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1605 if (compose->account)
1606 g_hash_table_insert(to_table, compose->account->address,
1607 GINT_TO_POINTER(1));
1609 /* remove address on To: and that of current account */
1610 for (cur = cc_list; cur != NULL; ) {
1611 GSList *next = cur->next;
1613 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1614 cc_list = g_slist_remove(cc_list, cur->data);
1616 g_hash_table_insert(to_table, cur->data, cur);
1620 g_hash_table_destroy(to_table);
1624 for (cur = cc_list; cur != NULL; cur = cur->next)
1625 compose_entry_append(compose, (gchar *)cur->data,
1627 slist_free_strings(cc_list);
1628 g_slist_free(cc_list);
1632 #define SET_ENTRY(entry, str) \
1635 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1638 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1640 g_return_if_fail(msginfo != NULL);
1642 SET_ENTRY(to_entry, msginfo->to);
1643 SET_ENTRY(subject_entry, msginfo->subject);
1644 SET_ENTRY(cc_entry, compose->cc);
1645 SET_ENTRY(bcc_entry, compose->bcc);
1646 SET_ENTRY(reply_entry, compose->replyto);
1649 GtkItemFactory *ifactory;
1650 GtkWidget *menuitem;
1652 ifactory = gtk_item_factory_from_widget(compose->menubar);
1653 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1654 gtk_check_menu_item_set_active
1655 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1657 if (compose->replyto) {
1658 GtkItemFactory *ifactory;
1659 GtkWidget *menuitem;
1661 ifactory = gtk_item_factory_from_widget(compose->menubar);
1662 menuitem = gtk_item_factory_get_item
1663 (ifactory, "/Message/Reply to");
1664 gtk_check_menu_item_set_active
1665 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1671 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1678 size_t buf_len = 128;
1680 if (strlen(sigfile) < 2)
1683 sigprg = popen(sigfile+1, "r");
1686 buf = g_malloc(buf_len);
1689 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1690 "Unable to insert signature (malloc failed)\n", -1);
1696 while (!feof(sigprg)) {
1697 bzero(buf, buf_len);
1698 fread(buf, buf_len-1, 1, sigprg);
1699 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1707 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1708 "Can't exec file: ", -1);
1709 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1714 static void compose_insert_sig(Compose *compose)
1718 if (compose->account && compose->account->sig_path)
1719 sigfile = g_strdup(compose->account->sig_path);
1721 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1722 DEFAULT_SIGNATURE, NULL);
1725 if (!is_file_or_fifo_exist(sigfile) & (sigfile[0] != '|')) {
1730 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1731 if (prefs_common.sig_sep) {
1732 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1733 prefs_common.sig_sep, -1);
1734 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1738 if (sigfile[0] == '|')
1740 compose_exec_sig(compose, sigfile);
1744 compose_insert_file(compose, sigfile);
1749 static void compose_insert_file(Compose *compose, const gchar *file)
1751 GtkSText *text = GTK_STEXT(compose->text);
1752 gchar buf[BUFFSIZE];
1755 g_return_if_fail(file != NULL);
1757 if ((fp = fopen(file, "r")) == NULL) {
1758 FILE_OP_ERROR(file, "fopen");
1762 gtk_stext_freeze(text);
1764 while (fgets(buf, sizeof(buf), fp) != NULL)
1765 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1767 gtk_stext_thaw(text);
1772 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1773 ContentType cnttype)
1775 gchar *text[N_ATTACH_COLS];
1778 text[COL_MIMETYPE] = ainfo->content_type;
1779 text[COL_SIZE] = to_human_readable(ainfo->size);
1780 text[COL_NAME] = ainfo->name;
1782 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1783 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1785 if (cnttype != MIME_MESSAGE_RFC822)
1786 compose_changed_cb(NULL, compose);
1789 static void compose_attach_append_with_type(Compose *compose,
1792 ContentType cnttype)
1797 if (!is_file_exist(file)) {
1798 g_warning(_("File %s doesn't exist\n"), file);
1801 if ((size = get_file_size(file)) < 0) {
1802 g_warning(_("Can't get file size of %s\n"), file);
1806 alertpanel_notice(_("File %s is empty\n"), file);
1810 if (!compose->use_attach) {
1811 GtkItemFactory *ifactory;
1812 GtkWidget *menuitem;
1814 ifactory = gtk_item_factory_from_widget(compose->menubar);
1815 menuitem = gtk_item_factory_get_item(ifactory,
1817 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1821 ainfo = g_new0(AttachInfo, 1);
1822 ainfo->file = g_strdup(file);
1824 if (cnttype == MIME_MESSAGE_RFC822) {
1825 ainfo->encoding = ENC_7BIT;
1826 ainfo->name = g_strdup_printf(_("Message: %s"),
1829 ainfo->encoding = ENC_BASE64;
1830 ainfo->name = g_strdup(g_basename(file));
1833 ainfo->content_type = g_strdup(type);
1836 compose_attach_info(compose, ainfo, cnttype);
1839 static void compose_attach_append(Compose *compose, const gchar *file,
1840 ContentType cnttype)
1843 gchar *text[N_ATTACH_COLS];
1847 if (!is_file_exist(file)) {
1848 g_warning(_("File %s doesn't exist\n"), file);
1851 if ((size = get_file_size(file)) < 0) {
1852 g_warning(_("Can't get file size of %s\n"), file);
1856 alertpanel_notice(_("File %s is empty\n"), file);
1860 if (!compose->use_attach) {
1861 GtkItemFactory *ifactory;
1862 GtkWidget *menuitem;
1864 ifactory = gtk_item_factory_from_widget(compose->menubar);
1865 menuitem = gtk_item_factory_get_item(ifactory,
1867 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1871 ainfo = g_new0(AttachInfo, 1);
1872 ainfo->file = g_strdup(file);
1874 if (cnttype == MIME_MESSAGE_RFC822) {
1875 ainfo->content_type = g_strdup("message/rfc822");
1876 ainfo->encoding = ENC_7BIT;
1877 ainfo->name = g_strdup_printf(_("Message: %s"),
1880 ainfo->content_type = procmime_get_mime_type(file);
1881 if (!ainfo->content_type)
1882 ainfo->content_type =
1883 g_strdup("application/octet-stream");
1884 ainfo->encoding = ENC_BASE64;
1885 ainfo->name = g_strdup(g_basename(file));
1889 compose_attach_info(compose, ainfo, cnttype);
1892 static void compose_wrap_line(Compose *compose)
1894 GtkSText *text = GTK_STEXT(compose->text);
1896 guint line_pos = 0, cur_pos = 0;
1897 gint line_len = 0, cur_len = 0;
1899 gchar cbuf[MB_CUR_MAX];
1901 gtk_stext_freeze(text);
1903 text_len = gtk_stext_get_length(text);
1905 for (; cur_pos < text_len; cur_pos++) {
1906 if (text->use_wchar)
1908 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
1910 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
1914 if (ch_len == 1 && *cbuf == '\n') {
1915 line_pos = cur_pos + 1;
1916 line_len = cur_len = 0;
1925 if (ch_len == 1 && isspace(*cbuf)) {
1926 line_pos = cur_pos + 1;
1927 line_len = cur_len + ch_len;
1930 if (cur_len + ch_len > prefs_common.linewrap_len &&
1934 if (text->use_wchar)
1935 tlen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
1937 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
1940 if (tlen == 1 && isspace(*cbuf)) {
1941 gtk_stext_set_point(text, line_pos);
1942 gtk_stext_backward_delete(text, 1);
1950 gtk_stext_set_point(text, line_pos);
1951 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
1955 cur_len = cur_len - line_len + ch_len;
1961 line_pos = cur_pos + 1;
1962 line_len = cur_len + ch_len;
1967 gtk_stext_thaw(text);
1970 static void compose_set_title(Compose *compose)
1975 edited = compose->modified ? _(" [Edited]") : "";
1976 if (compose->account && compose->account->address)
1977 str = g_strdup_printf(_("%s - Compose message%s"),
1978 compose->account->address, edited);
1980 str = g_strdup_printf(_("Compose message%s"), edited);
1981 gtk_window_set_title(GTK_WINDOW(compose->window), str);
1986 * compose_current_mail_account:
1988 * Find a current mail account (the currently selected account, or the
1989 * default account, if a news account is currently selected). If a
1990 * mail account cannot be found, display an error message.
1992 * Return value: Mail account, or NULL if not found.
1994 static PrefsAccount *
1995 compose_current_mail_account(void)
1999 if (cur_account && cur_account->protocol != A_NNTP)
2002 ac = account_get_default();
2003 if (!ac || ac->protocol == A_NNTP) {
2004 alertpanel_error(_("Account for sending mail is not specified.\n"
2005 "Please select a mail account before sending."));
2012 gint compose_send(Compose *compose)
2014 gchar tmp[MAXPATHLEN + 1];
2015 gchar *to, *newsgroups;
2017 static gboolean lock = FALSE;
2021 g_return_val_if_fail(compose->account != NULL, -1);
2022 g_return_val_if_fail(compose->orig_account != NULL, -1);
2026 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2027 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2028 if (*to == '\0' && *newsgroups == '\0') {
2029 alertpanel_error(_("Recipient is not specified."));
2034 /* write to temporary file */
2035 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2036 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2038 if (prefs_common.linewrap_at_send)
2039 compose_wrap_line(compose);
2041 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2046 if (!compose->to_list && !compose->newsgroup_list) {
2047 g_warning(_("can't get recipient list."));
2053 if (compose->to_list) {
2057 if (compose->account->protocol != A_NNTP)
2058 ac = compose->account;
2059 else if (compose->orig_account->protocol != A_NNTP)
2060 ac = compose->orig_account;
2061 else if (cur_account && cur_account->protocol != A_NNTP)
2064 ac = compose_current_mail_account();
2072 ac = compose->account;
2074 ok = send_message(tmp, ac, compose->to_list);
2075 statusbar_pop_all();
2078 if (ok == 0 && compose->newsgroup_list) {
2081 if (compose->account->protocol == A_NNTP)
2082 folder = FOLDER(compose->account->folder);
2084 folder = FOLDER(compose->orig_account->folder);
2086 ok = news_post(folder, tmp);
2088 alertpanel_error(_("Error occurred while posting the message to %s ."),
2089 compose->account->nntp_server);
2096 /* queue message if failed to send */
2098 if (prefs_common.queue_msg) {
2103 _("Error occurred while sending the message.\n"
2104 "Put this message into queue folder?"),
2105 _("OK"), _("Cancel"), NULL);
2106 if (G_ALERTDEFAULT == val) {
2107 ok = compose_queue(compose, tmp);
2109 alertpanel_error(_("Can't queue the message."));
2112 alertpanel_error(_("Error occurred while sending the message."));
2114 if (compose->mode == COMPOSE_REEDIT) {
2115 compose_remove_reedit_target(compose);
2116 if (compose->targetinfo)
2117 folderview_update_item
2118 (compose->targetinfo->folder, TRUE);
2122 /* save message to outbox */
2123 if (ok == 0 && prefs_common.savemsg) {
2124 if (compose_save_to_outbox(compose, tmp) < 0)
2126 (_("Can't save the message to outbox."));
2134 static gint compose_write_to_file(Compose *compose, const gchar *file,
2141 const gchar *out_codeset;
2142 EncodingType encoding;
2144 if ((fp = fopen(file, "w")) == NULL) {
2145 FILE_OP_ERROR(file, "fopen");
2149 /* chmod for security */
2150 if (change_file_mode_rw(fp, file) < 0) {
2151 FILE_OP_ERROR(file, "chmod");
2152 g_warning(_("can't change file mode\n"));
2155 /* get all composed text */
2156 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2157 len = strlen(chars);
2158 if (is_ascii_str(chars)) {
2159 buf = g_strdup(chars);
2160 out_codeset = "US-ASCII";
2161 encoding = ENC_7BIT;
2163 const gchar *src_codeset;
2165 out_codeset = conv_get_outgoing_charset_str();
2166 if (!strcasecmp(out_codeset, "US-ASCII"))
2167 out_codeset = "ISO-8859-1";
2168 encoding = procmime_get_encoding_for_charset(out_codeset);
2169 debug_print("charset = %s, encoding = %s\n",
2170 out_codeset, procmime_get_encoding_str(encoding));
2172 src_codeset = conv_get_current_charset_str();
2173 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
2178 alertpanel_error(_("Can't convert the codeset of the message."));
2185 if (compose_write_headers
2186 (compose, fp, out_codeset, encoding, is_draft) < 0) {
2187 g_warning(_("can't write headers\n"));
2194 if (compose->use_attach) {
2196 /* This prolog message is ignored by mime software and
2197 * because it would make our signing/encryption task
2198 * tougher, we don't emit it in that case */
2199 if (!compose->use_signing && !compose->use_encryption)
2201 fputs("This is a multi-part message in MIME format.\n", fp);
2203 fprintf(fp, "\n--%s\n", compose->boundary);
2204 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
2206 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2207 procmime_get_encoding_str(encoding));
2213 if (encoding == ENC_BASE64) {
2214 gchar outbuf[B64_BUFFSIZE];
2217 for (i = 0; i < len; i += B64_LINE_SIZE) {
2218 l = MIN(B64_LINE_SIZE, len - i);
2219 to64frombits(outbuf, buf + i, l);
2223 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
2224 FILE_OP_ERROR(file, "fwrite");
2232 if (compose->use_attach)
2233 compose_write_attach(compose, fp);
2235 if (fclose(fp) == EOF) {
2236 FILE_OP_ERROR(file, "fclose");
2242 if (compose->use_signing) {
2243 if (rfc2015_sign(file, compose->account) < 0) {
2248 if (compose->use_encryption) {
2249 if (rfc2015_encrypt(file, compose->to_list) < 0) {
2254 #endif /* USE_GPGME */
2259 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
2265 if ((fp = fopen(file, "w")) == NULL) {
2266 FILE_OP_ERROR(file, "fopen");
2270 /* chmod for security */
2271 if (change_file_mode_rw(fp, file) < 0) {
2272 FILE_OP_ERROR(file, "chmod");
2273 g_warning(_("can't change file mode\n"));
2276 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2279 len = strlen(chars);
2280 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
2281 FILE_OP_ERROR(file, "fwrite");
2290 if (fclose(fp) == EOF) {
2291 FILE_OP_ERROR(file, "fclose");
2298 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
2305 debug_print(_("saving sent message...\n"));
2307 outbox = folder_get_default_outbox();
2308 path = folder_item_get_path(outbox);
2309 if (!is_dir_exist(path))
2310 make_dir_hier(path);
2312 folder_item_scan(outbox);
2313 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
2315 g_warning(_("can't save message\n"));
2319 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
2320 g_warning(_("can't open mark file\n"));
2324 newmsginfo.msgnum = num;
2325 newmsginfo.flags.perm_flags = 0;
2326 newmsginfo.flags.tmp_flags = 0;
2327 procmsg_write_flags(&newmsginfo, fp);
2335 static gint compose_remove_reedit_target(Compose *compose)
2338 MsgInfo *msginfo = compose->targetinfo;
2340 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
2341 if (!msginfo) return -1;
2343 item = msginfo->folder;
2344 g_return_val_if_fail(item != NULL, -1);
2346 folder_item_scan(item);
2347 if (procmsg_msg_exist(msginfo) &&
2348 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
2349 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
2350 g_warning(_("can't remove the old message\n"));
2358 static gint compose_queue(Compose *compose, const gchar *file)
2361 gchar *tmp, *queue_path;
2364 gchar buf[BUFFSIZE];
2367 debug_print(_("queueing message...\n"));
2368 g_return_val_if_fail(compose->to_list != NULL, -1);
2369 g_return_val_if_fail(compose->account != NULL, -1);
2371 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
2372 G_DIR_SEPARATOR, (gint)compose);
2373 if ((fp = fopen(tmp, "w")) == NULL) {
2374 FILE_OP_ERROR(tmp, "fopen");
2378 if ((src_fp = fopen(file, "r")) == NULL) {
2379 FILE_OP_ERROR(file, "fopen");
2385 if (change_file_mode_rw(fp, tmp) < 0) {
2386 FILE_OP_ERROR(tmp, "chmod");
2387 g_warning(_("can't change file mode\n"));
2390 /* queueing variables */
2391 fprintf(fp, "AF:\n");
2392 fprintf(fp, "NF:0\n");
2393 fprintf(fp, "PS:10\n");
2394 fprintf(fp, "SRH:1\n");
2395 fprintf(fp, "SFN:\n");
2396 fprintf(fp, "DSR:\n");
2398 fprintf(fp, "MID:<%s>\n", compose->msgid);
2400 fprintf(fp, "MID:\n");
2401 fprintf(fp, "CFG:\n");
2402 fprintf(fp, "PT:0\n");
2403 fprintf(fp, "S:%s\n", compose->account->address);
2404 fprintf(fp, "RQ:\n");
2405 if (compose->account->smtp_server)
2406 fprintf(fp, "SSV:%s\n", compose->account->smtp_server);
2408 fprintf(fp, "SSV:\n");
2409 if (compose->account->nntp_server)
2410 fprintf(fp, "NSV:%s\n", compose->account->nntp_server);
2412 fprintf(fp, "NSV:\n");
2413 fprintf(fp, "SSH:\n");
2414 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
2415 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
2416 fprintf(fp, ",<%s>", (gchar *)cur->data);
2418 /* Sylpheed account ID */
2419 fprintf(fp, "AID:%d\n", compose->account->account_id);
2422 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
2423 if (fputs(buf, fp) == EOF) {
2424 FILE_OP_ERROR(tmp, "fputs");
2434 if (fclose(fp) == EOF) {
2435 FILE_OP_ERROR(tmp, "fclose");
2441 queue = folder_get_default_queue();
2443 folder_item_scan(queue);
2444 queue_path = folder_item_get_path(queue);
2445 if (!is_dir_exist(queue_path))
2446 make_dir_hier(queue_path);
2447 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
2448 g_warning(_("can't queue the message\n"));
2456 if (compose->mode == COMPOSE_REEDIT) {
2457 compose_remove_reedit_target(compose);
2458 if (compose->targetinfo &&
2459 compose->targetinfo->folder != queue)
2460 folderview_update_item
2461 (compose->targetinfo->folder, TRUE);
2464 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
2465 g_warning(_("can't open mark file\n"));
2469 newmsginfo.msgnum = num;
2470 newmsginfo.flags.perm_flags = 0;
2471 newmsginfo.flags.tmp_flags = 0;
2472 procmsg_write_flags(&newmsginfo, fp);
2477 folder_item_scan(queue);
2478 folderview_update_item(queue, TRUE);
2483 static void compose_write_attach(Compose *compose, FILE *fp)
2486 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2489 gchar filename[BUFFSIZE];
2492 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
2494 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
2495 g_warning(_("Can't open file %s\n"), ainfo->file);
2499 fprintf(fp, "\n--%s\n", compose->boundary);
2501 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
2502 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
2503 fprintf(fp, "Content-Disposition: inline\n");
2505 conv_encode_header(filename, sizeof(filename),
2507 fprintf(fp, "Content-Type: %s;\n"
2509 ainfo->content_type, filename);
2510 fprintf(fp, "Content-Disposition: attachment;\n"
2511 " filename=\"%s\"\n", filename);
2514 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
2515 procmime_get_encoding_str(ainfo->encoding));
2517 if (ainfo->encoding == ENC_7BIT) {
2518 gchar buf[BUFFSIZE];
2520 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
2522 if (len > 1 && buf[len - 1] == '\n' &&
2523 buf[len - 2] == '\r') {
2524 buf[len - 2] = '\n';
2525 buf[len - 1] = '\0';
2530 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
2532 while ((len = fread(inbuf, sizeof(gchar),
2533 B64_LINE_SIZE, attach_fp))
2535 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
2539 if (len > 0 && feof(attach_fp)) {
2540 to64frombits(outbuf, inbuf, len);
2549 fprintf(fp, "\n--%s--\n", compose->boundary);
2552 #define IS_IN_CUSTOM_HEADER(header) \
2553 (compose->account->add_customhdr && \
2554 custom_header_find(compose->account->customhdr_list, header) != NULL)
2556 static gint compose_write_headers(Compose *compose, FILE *fp,
2557 const gchar *charset, EncodingType encoding,
2560 gchar buf[BUFFSIZE];
2562 /* struct utsname utsbuf; */
2564 g_return_val_if_fail(fp != NULL, -1);
2565 g_return_val_if_fail(charset != NULL, -1);
2566 g_return_val_if_fail(compose->account != NULL, -1);
2567 g_return_val_if_fail(compose->account->address != NULL, -1);
2570 if (compose->account->add_date) {
2571 get_rfc822_date(buf, sizeof(buf));
2572 fprintf(fp, "Date: %s\n", buf);
2576 if (!IS_IN_CUSTOM_HEADER("From")) {
2577 if (compose->account->name && *compose->account->name) {
2578 compose_convert_header
2579 (buf, sizeof(buf), compose->account->name,
2581 fprintf(fp, "From: %s <%s>\n",
2582 buf, compose->account->address);
2584 fprintf(fp, "From: %s\n", compose->account->address);
2587 slist_free_strings(compose->to_list);
2588 g_slist_free(compose->to_list);
2589 compose->to_list = NULL;
2592 if (compose->use_to) {
2593 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2595 Xstrdup_a(str, str, return -1);
2598 compose->to_list = address_list_append
2599 (compose->to_list, str);
2600 if (!IS_IN_CUSTOM_HEADER("To")) {
2601 compose_convert_header
2602 (buf, sizeof(buf), str,
2604 fprintf(fp, "To: %s\n", buf);
2610 slist_free_strings(compose->newsgroup_list);
2611 g_slist_free(compose->newsgroup_list);
2612 compose->newsgroup_list = NULL;
2615 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2617 Xstrdup_a(str, str, return -1);
2621 compose->newsgroup_list =
2622 newsgroup_list_append(compose->newsgroup_list,
2624 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
2625 compose_convert_header(buf, sizeof(buf), str,
2626 strlen("Newsgroups: "));
2627 fprintf(fp, "Newsgroups: %s\n", buf);
2632 if (!is_draft && !compose->to_list && !compose->newsgroup_list)
2636 if (compose->use_cc) {
2637 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
2639 Xstrdup_a(str, str, return -1);
2642 compose->to_list = address_list_append
2643 (compose->to_list, str);
2644 if (!IS_IN_CUSTOM_HEADER("Cc")) {
2645 compose_convert_header
2646 (buf, sizeof(buf), str,
2648 fprintf(fp, "Cc: %s\n", buf);
2655 if (compose->use_bcc) {
2656 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
2658 Xstrdup_a(str, str, return -1);
2661 compose->to_list = address_list_append
2662 (compose->to_list, str);
2664 compose_convert_header
2665 (buf, sizeof(buf), str,
2667 fprintf(fp, "Bcc: %s\n", buf);
2674 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2675 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
2676 Xstrdup_a(str, str, return -1);
2679 compose_convert_header(buf, sizeof(buf), str,
2680 strlen("Subject: "));
2681 fprintf(fp, "Subject: %s\n", buf);
2686 if (compose->account->gen_msgid) {
2687 compose_generate_msgid(compose, buf, sizeof(buf));
2688 fprintf(fp, "Message-Id: <%s>\n", buf);
2689 compose->msgid = g_strdup(buf);
2693 if (compose->inreplyto && compose->to_list)
2694 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
2697 if (compose->references)
2698 fprintf(fp, "References: %s\n", compose->references);
2701 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
2702 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
2704 Xstrdup_a(str, str, return -1);
2708 compose_convert_header(buf, sizeof(buf), str,
2709 strlen("Followup-To: "));
2710 fprintf(fp, "Followup-To: %s\n", buf);
2716 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
2717 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
2719 Xstrdup_a(str, str, return -1);
2722 compose_convert_header(buf, sizeof(buf), str,
2723 strlen("Reply-To: "));
2724 fprintf(fp, "Reply-To: %s\n", buf);
2730 if (compose->account->organization &&
2731 !IS_IN_CUSTOM_HEADER("Organization")) {
2732 compose_convert_header(buf, sizeof(buf),
2733 compose->account->organization,
2734 strlen("Organization: "));
2735 fprintf(fp, "Organization: %s\n", buf);
2738 /* Program version and system info */
2739 /* uname(&utsbuf); */
2740 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
2741 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
2742 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
2744 gtk_major_version, gtk_minor_version, gtk_micro_version,
2746 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2748 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
2749 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
2750 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
2752 gtk_major_version, gtk_minor_version, gtk_micro_version,
2754 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
2757 /* custom headers */
2758 if (compose->account->add_customhdr) {
2761 for (cur = compose->account->customhdr_list; cur != NULL;
2763 CustomHeader *chdr = (CustomHeader *)cur->data;
2765 if (strcasecmp(chdr->name, "Date") != 0 &&
2766 strcasecmp(chdr->name, "From") != 0 &&
2767 strcasecmp(chdr->name, "To") != 0 &&
2768 strcasecmp(chdr->name, "Sender") != 0 &&
2769 strcasecmp(chdr->name, "Message-Id") != 0 &&
2770 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
2771 strcasecmp(chdr->name, "References") != 0 &&
2772 strcasecmp(chdr->name, "Mime-Version") != 0 &&
2773 strcasecmp(chdr->name, "Content-Type") != 0 &&
2774 strcasecmp(chdr->name, "Content-Transfer-Encoding")
2776 compose_convert_header
2778 chdr->value ? chdr->value : "",
2779 strlen(chdr->name) + 2);
2780 fprintf(fp, "%s: %s\n", chdr->name, buf);
2785 fprintf(fp, "Mime-Version: 1.0\n");
2786 if (compose->use_attach) {
2787 get_rfc822_date(buf, sizeof(buf));
2788 subst_char(buf, ' ', '_');
2789 subst_char(buf, ',', '_');
2790 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
2791 buf, (guint)compose);
2793 "Content-Type: multipart/mixed;\n"
2794 " boundary=\"%s\"\n", compose->boundary);
2796 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
2797 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2798 procmime_get_encoding_str(encoding));
2801 /* Request Return Receipt */
2802 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
2803 if (compose->return_receipt) {
2804 if (compose->account->name
2805 && *compose->account->name) {
2806 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
2807 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
2809 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
2813 /* separator between header and body */
2819 #undef IS_IN_CUSTOM_HEADER
2821 static void compose_convert_header(gchar *dest, gint len, gchar *src,
2824 g_return_if_fail(src != NULL);
2825 g_return_if_fail(dest != NULL);
2827 if (len < 1) return;
2831 if (is_ascii_str(src)) {
2832 strncpy2(dest, src, len);
2833 dest[len - 1] = '\0';
2836 conv_encode_header(dest, len, src, header_len);
2839 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
2848 if (compose->account && compose->account->address &&
2849 *compose->account->address) {
2850 if (strchr(compose->account->address, '@'))
2851 addr = g_strdup(compose->account->address);
2853 addr = g_strconcat(compose->account->address, "@",
2854 get_domain_name(), NULL);
2856 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
2859 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
2860 lt->tm_year + 1900, lt->tm_mon + 1,
2861 lt->tm_mday, lt->tm_hour,
2862 lt->tm_min, lt->tm_sec,
2863 (guint)random(), addr);
2865 debug_print(_("generated Message-ID: %s\n"), buf);
2870 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
2871 GtkWidget **entry, gint *count,
2872 const gchar *label_str,
2873 gboolean is_addr_entry)
2877 if (GTK_TABLE(table)->nrows < (*count) + 1)
2878 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
2880 *hbox = gtk_hbox_new(FALSE, 0);
2881 label = gtk_label_new
2882 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
2883 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
2884 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
2886 *entry = gtk_entry_new();
2887 gtk_table_attach_defaults
2888 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1);
2889 if (GTK_TABLE(table)->nrows > (*count) + 1)
2890 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
2893 address_completion_register_entry(GTK_ENTRY(*entry));
2898 static Compose *compose_create(PrefsAccount *account)
2904 GtkWidget *handlebox;
2908 GtkWidget *table_vbox;
2910 GtkWidget *from_optmenu_hbox;
2911 GtkWidget *to_entry;
2913 GtkWidget *newsgroups_entry;
2914 GtkWidget *newsgroups_hbox;
2915 GtkWidget *subject_entry;
2916 GtkWidget *cc_entry;
2918 GtkWidget *bcc_entry;
2919 GtkWidget *bcc_hbox;
2920 GtkWidget *reply_entry;
2921 GtkWidget *reply_hbox;
2922 GtkWidget *followup_entry;
2923 GtkWidget *followup_hbox;
2927 GtkWidget *attach_scrwin;
2928 GtkWidget *attach_clist;
2930 GtkWidget *edit_vbox;
2931 GtkWidget *ruler_hbox;
2933 GtkWidget *scrolledwin;
2939 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
2940 guint n_menu_entries;
2941 GtkStyle *style, *new_style;
2944 gboolean success[1];
2946 GtkWidget *popupmenu;
2947 GtkWidget *menuitem;
2948 GtkItemFactory *popupfactory;
2949 GtkItemFactory *ifactory;
2954 g_return_val_if_fail(account != NULL, NULL);
2956 debug_print(_("Creating compose window...\n"));
2957 compose = g_new0(Compose, 1);
2959 compose->account = account;
2960 compose->orig_account = account;
2962 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2963 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
2964 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
2965 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
2966 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
2967 gtk_signal_connect(GTK_OBJECT(window), "destroy",
2968 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
2969 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
2970 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
2971 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
2972 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
2973 gtk_widget_realize(window);
2975 gtkut_widget_set_composer_icon(window);
2977 vbox = gtk_vbox_new(FALSE, 0);
2978 gtk_container_add(GTK_CONTAINER(window), vbox);
2980 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
2981 menubar = menubar_create(window, compose_entries,
2982 n_menu_entries, "<Compose>", compose);
2983 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
2985 handlebox = gtk_handle_box_new();
2986 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
2988 compose_toolbar_create(compose, handlebox);
2990 vbox2 = gtk_vbox_new(FALSE, 2);
2991 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
2992 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
2994 table_vbox = gtk_vbox_new(FALSE, 0);
2995 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
2996 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
2999 table = gtk_table_new(8, 2, FALSE);
3000 gtk_box_pack_start(GTK_BOX(table_vbox), table, FALSE, TRUE, 0);
3002 /* option menu for selecting accounts */
3003 hbox = gtk_hbox_new(FALSE, 0);
3004 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
3005 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3006 gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, count, count + 1,
3008 from_optmenu_hbox = compose_account_option_menu_create(compose);
3009 gtk_table_attach_defaults(GTK_TABLE(table), from_optmenu_hbox,
3010 1, 2, count, count + 1);
3011 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3014 /* header labels and entries */
3015 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
3017 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3018 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
3019 &count, "Newsgroups:", FALSE);
3020 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
3021 compose_add_entry_field(table, &hbox, &subject_entry, &count,
3023 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
3024 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
3026 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
3027 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
3029 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
3030 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
3032 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
3033 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
3034 "Followup-To:", FALSE);
3035 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
3037 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
3039 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
3040 GTK_SIGNAL_FUNC(to_activated), compose);
3041 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
3042 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
3043 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
3044 GTK_SIGNAL_FUNC(subject_activated), compose);
3045 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
3046 GTK_SIGNAL_FUNC(cc_activated), compose);
3047 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
3048 GTK_SIGNAL_FUNC(bcc_activated), compose);
3049 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
3050 GTK_SIGNAL_FUNC(replyto_activated), compose);
3051 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
3052 GTK_SIGNAL_FUNC(followupto_activated), compose);
3054 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
3055 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3056 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
3057 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3058 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
3059 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3060 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
3061 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3062 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
3063 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3064 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
3065 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3066 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
3067 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3069 /* attachment list */
3070 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
3071 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
3072 GTK_POLICY_AUTOMATIC,
3074 gtk_widget_set_usize(attach_scrwin, -1, 80);
3076 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
3077 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
3079 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
3080 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
3081 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
3082 GTK_SELECTION_EXTENDED);
3083 for (i = 0; i < N_ATTACH_COLS; i++)
3084 GTK_WIDGET_UNSET_FLAGS
3085 (GTK_CLIST(attach_clist)->column[i].button,
3087 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
3089 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
3090 GTK_SIGNAL_FUNC(attach_selected), compose);
3091 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
3092 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
3093 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
3094 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
3097 gtk_drag_dest_set(attach_clist,
3098 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3100 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
3101 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
3104 /* pane between attach clist and text */
3105 paned = gtk_vpaned_new();
3106 gtk_paned_add1(GTK_PANED(paned), attach_scrwin);
3107 gtk_widget_ref(paned);
3108 gtk_widget_show_all(paned);
3110 edit_vbox = gtk_vbox_new(FALSE, 0);
3111 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
3114 ruler_hbox = gtk_hbox_new(FALSE, 0);
3115 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
3117 ruler = gtk_shruler_new();
3118 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
3119 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
3121 gtk_widget_set_usize(ruler_hbox, 1, -1);
3124 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3125 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
3126 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
3127 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
3128 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
3130 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
3131 (GTK_SCROLLED_WINDOW(scrolledwin)),
3132 gtk_scrolled_window_get_vadjustment
3133 (GTK_SCROLLED_WINDOW(scrolledwin)));
3134 GTK_STEXT(text)->default_tab_width = 8;
3135 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
3136 if (prefs_common.smart_wrapping) {
3137 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
3138 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
3141 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
3143 gtk_signal_connect(GTK_OBJECT(text), "changed",
3144 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
3145 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
3146 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3147 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
3148 GTK_SIGNAL_FUNC(compose_button_press_cb),
3151 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
3152 GTK_SIGNAL_FUNC(compose_key_press_cb),
3155 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
3156 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
3160 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3162 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
3163 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
3166 gtk_widget_show_all(vbox);
3168 style = gtk_widget_get_style(text);
3170 /* workaround for the slow down of GtkText when using Pixmap theme */
3171 if (style->engine) {
3172 GtkThemeEngine *engine;
3174 engine = style->engine;
3175 style->engine = NULL;
3176 new_style = gtk_style_copy(style);
3177 style->engine = engine;
3179 new_style = gtk_style_copy(style);
3181 if (prefs_common.textfont) {
3184 charset = conv_get_current_charset();
3185 if (MB_CUR_MAX == 1) {
3188 Xstrdup_a(fontstr, prefs_common.textfont, );
3189 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
3191 font = gdk_font_load(fontstr);
3193 font = gdk_fontset_load(prefs_common.textfont);
3195 gdk_font_unref(new_style->font);
3196 new_style->font = font;
3200 gtk_widget_set_style(text, new_style);
3202 color[0] = quote_color;
3203 cmap = gdk_window_get_colormap(window->window);
3204 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
3205 if (success[0] == FALSE) {
3206 g_warning("Compose: color allocation failed.\n");
3207 style = gtk_widget_get_style(text);
3208 quote_color = style->black;
3211 n_entries = sizeof(compose_popup_entries) /
3212 sizeof(compose_popup_entries[0]);
3213 popupmenu = menu_create_items(compose_popup_entries, n_entries,
3214 "<Compose>", &popupfactory,
3217 ifactory = gtk_item_factory_from_widget(menubar);
3218 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
3219 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
3222 if (account->protocol == A_NNTP) {
3223 gtk_widget_hide(to_hbox);
3224 gtk_widget_hide(to_entry);
3225 gtk_widget_hide(cc_hbox);
3226 gtk_widget_hide(cc_entry);
3227 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
3228 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
3230 gtk_widget_hide(newsgroups_hbox);
3231 gtk_widget_hide(newsgroups_entry);
3232 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
3234 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
3238 switch (prefs_common.toolbar_style) {
3240 gtk_widget_hide(handlebox);
3243 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3247 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3251 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3256 gtk_widget_show(window);
3258 address_completion_start(window);
3260 compose->window = window;
3261 compose->vbox = vbox;
3262 compose->menubar = menubar;
3263 compose->handlebox = handlebox;
3265 compose->vbox2 = vbox2;
3267 compose->table_vbox = table_vbox;
3268 compose->table = table;
3269 compose->to_hbox = to_hbox;
3270 compose->to_entry = to_entry;
3271 compose->newsgroups_hbox = newsgroups_hbox;
3272 compose->newsgroups_entry = newsgroups_entry;
3273 compose->subject_entry = subject_entry;
3274 compose->cc_hbox = cc_hbox;
3275 compose->cc_entry = cc_entry;
3276 compose->bcc_hbox = bcc_hbox;
3277 compose->bcc_entry = bcc_entry;
3278 compose->reply_hbox = reply_hbox;
3279 compose->reply_entry = reply_entry;
3280 compose->followup_hbox = followup_hbox;
3281 compose->followup_entry = followup_entry;
3283 compose->paned = paned;
3285 compose->attach_scrwin = attach_scrwin;
3286 compose->attach_clist = attach_clist;
3288 compose->edit_vbox = edit_vbox;
3289 compose->ruler_hbox = ruler_hbox;
3290 compose->ruler = ruler;
3291 compose->scrolledwin = scrolledwin;
3292 compose->text = text;
3294 compose->focused_editable = NULL;
3296 compose->popupmenu = popupmenu;
3297 compose->popupfactory = popupfactory;
3299 compose->mode = COMPOSE_NEW;
3301 compose->replyto = NULL;
3303 compose->bcc = NULL;
3304 compose->followup_to = NULL;
3305 compose->inreplyto = NULL;
3306 compose->references = NULL;
3307 compose->msgid = NULL;
3308 compose->boundary = NULL;
3311 compose->use_signing = FALSE;
3312 compose->use_encryption = FALSE;
3313 #endif /* USE_GPGME */
3315 compose->modified = FALSE;
3317 compose->return_receipt = FALSE;
3319 compose->to_list = NULL;
3320 compose->newsgroup_list = NULL;
3322 compose->exteditor_file = NULL;
3323 compose->exteditor_pid = -1;
3324 compose->exteditor_readdes = -1;
3325 compose->exteditor_tag = -1;
3327 compose_set_title(compose);
3329 compose->use_bcc = FALSE;
3330 compose->use_replyto = FALSE;
3331 compose->use_followupto = FALSE;
3334 if (account->protocol != A_NNTP) {
3335 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
3336 gtk_check_menu_item_set_active
3337 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3338 gtk_widget_set_sensitive(menuitem, FALSE);
3339 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3340 gtk_check_menu_item_set_active
3341 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3342 gtk_widget_set_sensitive(menuitem, FALSE);
3345 if (account->set_autocc && account->auto_cc) {
3346 compose->use_cc = TRUE;
3347 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
3348 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3349 gtk_check_menu_item_set_active
3350 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3353 if (account->set_autobcc) {
3354 compose->use_bcc = TRUE;
3355 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
3356 gtk_check_menu_item_set_active
3357 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3358 if (account->auto_bcc)
3359 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
3362 if (account->set_autoreplyto) {
3363 compose->use_replyto = TRUE;
3364 menuitem = gtk_item_factory_get_item(ifactory,
3365 "/Message/Reply to");
3366 gtk_check_menu_item_set_active
3367 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3368 if (account->auto_replyto)
3369 gtk_entry_set_text(GTK_ENTRY(reply_entry),
3370 account->auto_replyto);
3373 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
3374 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3375 prefs_common.show_ruler);
3378 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
3379 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3380 prefs_common.default_sign);
3381 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
3382 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3383 prefs_common.default_encrypt);
3384 #endif /* USE_GPGME */
3386 addressbook_set_target_compose(compose);
3388 compose_list = g_list_append(compose_list, compose);
3391 compose->use_to = FALSE;
3392 compose->use_cc = FALSE;
3394 compose->use_attach = FALSE;
3396 if (!compose->use_bcc) {
3397 gtk_widget_hide(bcc_hbox);
3398 gtk_widget_hide(bcc_entry);
3399 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
3401 if (!compose->use_replyto) {
3402 gtk_widget_hide(reply_hbox);
3403 gtk_widget_hide(reply_entry);
3404 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
3406 if (!compose->use_followupto) {
3407 gtk_widget_hide(followup_hbox);
3408 gtk_widget_hide(followup_entry);
3409 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
3412 if (!prefs_common.show_ruler)
3413 gtk_widget_hide(ruler_hbox);
3415 select_account(compose, account);
3420 #include "pixmaps/stock_mail_send.xpm"
3421 #include "pixmaps/stock_mail_send_queue.xpm"
3422 #include "pixmaps/stock_mail.xpm"
3423 #include "pixmaps/stock_paste.xpm"
3424 #include "pixmaps/stock_mail_attach.xpm"
3425 #include "pixmaps/stock_mail_compose.xpm"
3426 #include "pixmaps/linewrap.xpm"
3427 #include "pixmaps/tb_address_book.xpm"
3429 #define CREATE_TOOLBAR_ICON(xpm_d) \
3431 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
3432 &container->style->white, \
3434 icon_wid = gtk_pixmap_new(icon, mask); \
3437 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
3442 GtkWidget *icon_wid;
3443 GtkWidget *send_btn;
3444 GtkWidget *sendl_btn;
3445 GtkWidget *draft_btn;
3446 GtkWidget *insert_btn;
3447 GtkWidget *attach_btn;
3449 GtkWidget *exteditor_btn;
3450 GtkWidget *linewrap_btn;
3451 GtkWidget *addrbook_btn;
3453 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
3455 gtk_container_add(GTK_CONTAINER(container), toolbar);
3456 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
3457 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
3458 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
3459 GTK_TOOLBAR_SPACE_LINE);
3461 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
3462 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3466 icon_wid, toolbar_send_cb, compose);
3468 CREATE_TOOLBAR_ICON(stock_mail_send_queue_xpm);
3469 /* CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm); */
3470 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3472 _("Put into queue folder and send later"),
3474 icon_wid, toolbar_send_later_cb,
3477 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3478 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3480 _("Save to draft folder"),
3482 icon_wid, toolbar_draft_cb,
3485 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3487 CREATE_TOOLBAR_ICON(stock_paste_xpm);
3488 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3492 icon_wid, toolbar_insert_cb,
3495 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
3496 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3500 icon_wid, toolbar_attach_cb,
3503 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3505 CREATE_TOOLBAR_ICON(stock_mail_xpm);
3506 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3508 _("Insert signature"),
3510 icon_wid, toolbar_sig_cb, compose);
3512 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3514 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
3515 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3517 _("Edit with external editor"),
3520 toolbar_ext_editor_cb,
3523 CREATE_TOOLBAR_ICON(linewrap_xpm);
3524 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3526 _("Wrap long lines"),
3529 toolbar_linewrap_cb,
3532 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
3534 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
3535 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
3539 icon_wid, toolbar_address_cb,
3542 compose->toolbar = toolbar;
3543 compose->send_btn = send_btn;
3544 compose->sendl_btn = sendl_btn;
3545 compose->draft_btn = draft_btn;
3546 compose->insert_btn = insert_btn;
3547 compose->attach_btn = attach_btn;
3548 compose->sig_btn = sig_btn;
3549 compose->exteditor_btn = exteditor_btn;
3550 compose->linewrap_btn = linewrap_btn;
3551 compose->addrbook_btn = addrbook_btn;
3553 gtk_widget_show_all(toolbar);
3556 #undef CREATE_TOOLBAR_ICON
3558 static GtkWidget *compose_account_option_menu_create(Compose *compose)
3564 gint num = 0, def_menu = 0;
3566 accounts = account_get_list();
3567 g_return_val_if_fail(accounts != NULL, NULL);
3569 hbox = gtk_hbox_new(FALSE, 0);
3570 optmenu = gtk_option_menu_new();
3571 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3572 menu = gtk_menu_new();
3574 for (; accounts != NULL; accounts = accounts->next, num++) {
3575 PrefsAccount *ac = (PrefsAccount *)accounts->data;
3576 GtkWidget *menuitem;
3579 if (ac == compose->account) def_menu = num;
3581 name = g_strdup_printf("%s: %s <%s>",
3582 ac->account_name, ac->name, ac->address);
3583 MENUITEM_ADD(menu, menuitem, name, ac);
3585 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
3586 GTK_SIGNAL_FUNC(account_activated),
3590 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
3591 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
3596 static void compose_destroy(Compose *compose)
3599 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3602 /* NOTE: address_completion_end() does nothing with the window
3603 * however this may change. */
3604 address_completion_end(compose->window);
3606 slist_free_strings(compose->to_list);
3607 g_slist_free(compose->to_list);
3608 slist_free_strings(compose->newsgroup_list);
3609 g_slist_free(compose->newsgroup_list);
3611 procmsg_msginfo_free(compose->targetinfo);
3613 g_free(compose->replyto);
3614 g_free(compose->cc);
3615 g_free(compose->bcc);
3616 g_free(compose->newsgroups);
3617 g_free(compose->followup_to);
3619 g_free(compose->inreplyto);
3620 g_free(compose->references);
3621 g_free(compose->msgid);
3622 g_free(compose->boundary);
3624 g_free(compose->exteditor_file);
3626 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3628 compose_attach_info_free(ainfo);
3630 if (addressbook_get_target_compose() == compose)
3631 addressbook_set_target_compose(NULL);
3633 prefs_common.compose_width = compose->scrolledwin->allocation.width;
3634 prefs_common.compose_height = compose->window->allocation.height;
3636 gtk_widget_destroy(compose->paned);
3640 compose_list = g_list_remove(compose_list, compose);
3643 static void compose_attach_info_free(AttachInfo *ainfo)
3645 g_free(ainfo->file);
3646 g_free(ainfo->content_type);
3647 g_free(ainfo->name);
3651 static void compose_attach_remove_selected(Compose *compose)
3653 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3657 while (clist->selection != NULL) {
3658 row = GPOINTER_TO_INT(clist->selection->data);
3659 ainfo = gtk_clist_get_row_data(clist, row);
3660 compose_attach_info_free(ainfo);
3661 gtk_clist_remove(clist, row);
3665 static struct _AttachProperty
3668 GtkWidget *mimetype_entry;
3669 GtkWidget *encoding_optmenu;
3670 GtkWidget *path_entry;
3671 GtkWidget *filename_entry;
3673 GtkWidget *cancel_btn;
3676 static void compose_attach_property(Compose *compose)
3678 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3681 GtkOptionMenu *optmenu;
3682 static gboolean cancelled;
3684 if (!clist->selection) return;
3685 row = GPOINTER_TO_INT(clist->selection->data);
3687 ainfo = gtk_clist_get_row_data(clist, row);
3690 if (!attach_prop.window)
3691 compose_attach_property_create(&cancelled);
3692 gtk_widget_grab_focus(attach_prop.ok_btn);
3693 gtk_widget_show(attach_prop.window);
3694 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
3696 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
3697 if (ainfo->encoding == ENC_UNKNOWN)
3698 gtk_option_menu_set_history(optmenu, ENC_BASE64);
3700 gtk_option_menu_set_history(optmenu, ainfo->encoding);
3702 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
3703 ainfo->content_type ? ainfo->content_type : "");
3704 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
3705 ainfo->file ? ainfo->file : "");
3706 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
3707 ainfo->name ? ainfo->name : "");
3711 gchar *cnttype = NULL;
3715 GtkWidget *menuitem;
3720 if (cancelled == TRUE) {
3721 gtk_widget_hide(attach_prop.window);
3725 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
3726 if (*text != '\0') {
3729 text = g_strstrip(g_strdup(text));
3730 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
3731 cnttype = g_strdup(text);
3734 alertpanel_error(_("Invalid MIME type."));
3740 menu = gtk_option_menu_get_menu(optmenu);
3741 menuitem = gtk_menu_get_active(GTK_MENU(menu));
3742 ainfo->encoding = GPOINTER_TO_INT
3743 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
3745 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
3746 if (*text != '\0') {
3747 if (is_file_exist(text) &&
3748 (size = get_file_size(text)) > 0)
3749 file = g_strdup(text);
3752 (_("File doesn't exist or is empty."));
3758 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
3759 if (*text != '\0') {
3760 g_free(ainfo->name);
3761 ainfo->name = g_strdup(text);
3765 g_free(ainfo->content_type);
3766 ainfo->content_type = cnttype;
3769 g_free(ainfo->file);
3775 gtk_clist_set_text(clist, row, COL_MIMETYPE,
3776 ainfo->content_type);
3777 gtk_clist_set_text(clist, row, COL_SIZE,
3778 to_human_readable(ainfo->size));
3779 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
3781 gtk_widget_hide(attach_prop.window);
3786 #define SET_LABEL_AND_ENTRY(str, entry, top) \
3788 label = gtk_label_new(str); \
3789 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
3790 GTK_FILL, 0, 0, 0); \
3791 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
3793 entry = gtk_entry_new(); \
3794 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
3795 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
3798 static void compose_attach_property_create(gboolean *cancelled)
3804 GtkWidget *mimetype_entry;
3807 GtkWidget *optmenu_menu;
3808 GtkWidget *menuitem;
3809 GtkWidget *path_entry;
3810 GtkWidget *filename_entry;
3813 GtkWidget *cancel_btn;
3814 GList *mime_type_list, *strlist;
3816 debug_print("Creating attach_property window...\n");
3818 window = gtk_window_new(GTK_WINDOW_DIALOG);
3819 gtk_widget_set_usize(window, 480, -1);
3820 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
3821 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
3822 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
3823 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
3824 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3825 GTK_SIGNAL_FUNC(attach_property_delete_event),
3827 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
3828 GTK_SIGNAL_FUNC(attach_property_key_pressed),
3831 vbox = gtk_vbox_new(FALSE, 8);
3832 gtk_container_add(GTK_CONTAINER(window), vbox);
3834 table = gtk_table_new(4, 2, FALSE);
3835 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
3836 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
3837 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
3839 label = gtk_label_new(_("MIME type"));
3840 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
3842 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3843 mimetype_entry = gtk_combo_new();
3844 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
3845 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3847 /* stuff with list */
3848 mime_type_list = procmime_get_mime_type_list();
3850 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
3851 MimeType *type = (MimeType *) mime_type_list->data;
3852 strlist = g_list_append(strlist,
3853 g_strdup_printf("%s/%s",
3854 type->type, type->sub_type));
3857 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
3859 for (mime_type_list = strlist; mime_type_list != NULL;
3860 mime_type_list = mime_type_list->next)
3861 g_free(mime_type_list->data);
3862 g_list_free(strlist);
3864 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
3866 label = gtk_label_new(_("Encoding"));
3867 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
3869 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
3871 hbox = gtk_hbox_new(FALSE, 0);
3872 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
3873 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
3875 optmenu = gtk_option_menu_new();
3876 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
3878 optmenu_menu = gtk_menu_new();
3879 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
3880 gtk_widget_set_sensitive(menuitem, FALSE);
3881 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
3882 gtk_widget_set_sensitive(menuitem, FALSE);
3883 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
3884 gtk_widget_set_sensitive(menuitem, FALSE);
3885 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
3887 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
3889 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
3890 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
3892 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
3893 &cancel_btn, _("Cancel"), NULL, NULL);
3894 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
3895 gtk_widget_grab_default(ok_btn);
3897 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
3898 GTK_SIGNAL_FUNC(attach_property_ok),
3900 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
3901 GTK_SIGNAL_FUNC(attach_property_cancel),
3904 gtk_widget_show_all(vbox);
3906 attach_prop.window = window;
3907 attach_prop.mimetype_entry = mimetype_entry;
3908 attach_prop.encoding_optmenu = optmenu;
3909 attach_prop.path_entry = path_entry;
3910 attach_prop.filename_entry = filename_entry;
3911 attach_prop.ok_btn = ok_btn;
3912 attach_prop.cancel_btn = cancel_btn;
3915 #undef SET_LABEL_AND_ENTRY
3917 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
3923 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
3929 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
3930 gboolean *cancelled)
3938 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
3939 gboolean *cancelled)
3941 if (event && event->keyval == GDK_Escape) {
3947 static void compose_exec_ext_editor(Compose *compose)
3953 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
3954 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3956 if (pipe(pipe_fds) < 0) {
3961 if ((pid = fork()) < 0) {
3967 /* close the write side of the pipe */
3970 compose->exteditor_file = g_strdup(tmp);
3971 compose->exteditor_pid = pid;
3972 compose->exteditor_readdes = pipe_fds[0];
3974 compose_set_ext_editor_sensitive(compose, FALSE);
3976 compose->exteditor_tag =
3977 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
3978 compose_input_cb, compose);
3979 } else { /* process-monitoring process */
3985 /* close the read side of the pipe */
3988 if (compose_write_body_to_file(compose, tmp) < 0) {
3989 fd_write(pipe_fds[1], "2\n", 2);
3993 pid_ed = compose_exec_ext_editor_real(tmp);
3995 fd_write(pipe_fds[1], "1\n", 2);
3999 /* wait until editor is terminated */
4000 waitpid(pid_ed, NULL, 0);
4002 fd_write(pipe_fds[1], "0\n", 2);
4009 static gint compose_exec_ext_editor_real(const gchar *file)
4011 static gchar *def_cmd = "emacs %s";
4017 g_return_val_if_fail(file != NULL, -1);
4019 if ((pid = fork()) < 0) {
4024 if (pid != 0) return pid;
4026 /* grandchild process */
4028 if (setpgid(0, getppid()))
4031 if (prefs_common.ext_editor_cmd &&
4032 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
4033 *(p + 1) == 's' && !strchr(p + 2, '%')) {
4034 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
4036 if (prefs_common.ext_editor_cmd)
4037 g_warning(_("External editor command line is invalid: `%s'\n"),
4038 prefs_common.ext_editor_cmd);
4039 g_snprintf(buf, sizeof(buf), def_cmd, file);
4042 cmdline = g_strsplit(buf, " ", 1024);
4043 execvp(cmdline[0], cmdline);
4046 g_strfreev(cmdline);
4051 static gboolean compose_ext_editor_kill(Compose *compose)
4053 pid_t pgid = compose->exteditor_pid * -1;
4056 ret = kill(pgid, 0);
4058 if (ret == 0 || (ret == -1 && EPERM == errno)) {
4062 msg = g_strdup_printf
4063 (_("The external editor is still working.\n"
4064 "Force terminating the process?\n"
4065 "process group id: %d"), -pgid);
4066 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
4069 if (val == G_ALERTDEFAULT) {
4070 gdk_input_remove(compose->exteditor_tag);
4071 close(compose->exteditor_readdes);
4073 if (kill(pgid, SIGTERM) < 0) perror("kill");
4074 waitpid(compose->exteditor_pid, NULL, 0);
4076 g_warning(_("Terminated process group id: %d"), -pgid);
4077 g_warning(_("Temporary file: %s"),
4078 compose->exteditor_file);
4080 compose_set_ext_editor_sensitive(compose, TRUE);
4082 g_free(compose->exteditor_file);
4083 compose->exteditor_file = NULL;
4084 compose->exteditor_pid = -1;
4085 compose->exteditor_readdes = -1;
4086 compose->exteditor_tag = -1;
4094 static void compose_input_cb(gpointer data, gint source,
4095 GdkInputCondition condition)
4098 Compose *compose = (Compose *)data;
4101 debug_print(_("Compose: input from monitoring process\n"));
4103 gdk_input_remove(compose->exteditor_tag);
4106 if (read(source, &buf[i], 1) < 1) {
4110 if (buf[i] == '\n') {
4115 if (i == sizeof(buf) - 1)
4119 waitpid(compose->exteditor_pid, NULL, 0);
4121 if (buf[0] == '0') { /* success */
4122 GtkSText *text = GTK_STEXT(compose->text);
4124 gtk_stext_freeze(text);
4125 gtk_stext_set_point(text, 0);
4126 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
4127 compose_insert_file(compose, compose->exteditor_file);
4128 compose_changed_cb(NULL, compose);
4129 gtk_stext_thaw(text);
4131 if (unlink(compose->exteditor_file) < 0)
4132 FILE_OP_ERROR(compose->exteditor_file, "unlink");
4133 } else if (buf[0] == '1') { /* failed */
4134 g_warning(_("Couldn't exec external editor\n"));
4135 if (unlink(compose->exteditor_file) < 0)
4136 FILE_OP_ERROR(compose->exteditor_file, "unlink");
4137 } else if (buf[0] == '2') {
4138 g_warning(_("Couldn't write to file\n"));
4139 } else if (buf[0] == '3') {
4140 g_warning(_("Pipe read failed\n"));
4145 compose_set_ext_editor_sensitive(compose, TRUE);
4147 g_free(compose->exteditor_file);
4148 compose->exteditor_file = NULL;
4149 compose->exteditor_pid = -1;
4150 compose->exteditor_readdes = -1;
4151 compose->exteditor_tag = -1;
4154 static void compose_set_ext_editor_sensitive(Compose *compose,
4157 GtkItemFactory *ifactory;
4159 ifactory = gtk_item_factory_from_widget(compose->menubar);
4161 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
4162 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
4163 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
4165 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
4166 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
4167 menu_set_sensitive(ifactory, "/Edit/Wrap long lines", sensitive);
4168 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
4171 gtk_widget_set_sensitive(compose->text, sensitive);
4172 gtk_widget_set_sensitive(compose->send_btn, sensitive);
4173 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
4174 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
4175 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
4176 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
4177 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
4178 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
4181 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
4185 cursor_pos = (text->cursor_pos_x - extra) / char_width;
4186 cursor_pos = MAX(cursor_pos, 0);
4191 /* callback functions */
4193 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
4194 * includes "non-client" (windows-izm) in calculation, so this calculation
4195 * may not be accurate.
4197 static gboolean compose_edit_size_alloc(GtkEditable *widget,
4198 GtkAllocation *allocation,
4199 GtkSHRuler *shruler)
4201 if (prefs_common.show_ruler) {
4203 gint line_width_in_chars;
4205 char_width = gtkut_get_font_width
4206 (GTK_WIDGET(widget)->style->font);
4207 line_width_in_chars =
4208 (allocation->width - allocation->x) / char_width;
4210 /* got the maximum */
4211 gtk_ruler_set_range(GTK_RULER(shruler),
4212 0.0, line_width_in_chars,
4213 calc_cursor_xpos(GTK_STEXT(widget),
4216 /*line_width_in_chars*/ char_width);
4222 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
4224 compose_send_cb(data, 0, NULL);
4227 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
4229 compose_send_later_cb(data, 0, NULL);
4232 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
4234 compose_draft_cb(data, 0, NULL);
4237 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
4239 compose_insert_file_cb(data, 0, NULL);
4242 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
4244 compose_attach_cb(data, 0, NULL);
4247 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
4249 Compose *compose = (Compose *)data;
4251 compose_insert_sig(compose);
4254 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
4256 Compose *compose = (Compose *)data;
4258 compose_exec_ext_editor(compose);
4261 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
4263 Compose *compose = (Compose *)data;
4265 compose_wrap_line(compose);
4268 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
4270 compose_address_cb(data, 0, NULL);
4273 static void select_account(Compose * compose, PrefsAccount * ac)
4275 compose->account = ac;
4276 compose_set_title(compose);
4278 if (ac->protocol == A_NNTP) {
4279 GtkItemFactory *ifactory;
4280 GtkWidget *menuitem;
4282 ifactory = gtk_item_factory_from_widget(compose->menubar);
4283 menu_set_sensitive(ifactory,
4284 "/Message/Followup to", TRUE);
4286 gtk_widget_show(compose->newsgroups_hbox);
4287 gtk_widget_show(compose->newsgroups_entry);
4288 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4291 compose->use_to = FALSE;
4292 compose->use_cc = FALSE;
4294 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4295 gtk_check_menu_item_set_active
4296 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
4297 menu_set_sensitive(ifactory,
4298 "/Message/To", TRUE);
4299 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4300 gtk_check_menu_item_set_active
4301 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
4303 gtk_widget_hide(compose->to_hbox);
4304 gtk_widget_hide(compose->to_entry);
4305 gtk_widget_hide(compose->cc_hbox);
4306 gtk_widget_hide(compose->cc_entry);
4308 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4310 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4314 GtkItemFactory *ifactory;
4315 GtkWidget *menuitem;
4317 ifactory = gtk_item_factory_from_widget(compose->menubar);
4318 menu_set_sensitive(ifactory,
4319 "/Message/Followup to", FALSE);
4321 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
4322 gtk_widget_hide(compose->newsgroups_hbox);
4323 gtk_widget_hide(compose->newsgroups_entry);
4324 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4327 compose->use_to = TRUE;
4328 compose->use_cc = TRUE;
4330 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4331 gtk_check_menu_item_set_active
4332 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4333 menu_set_sensitive(ifactory,
4334 "/Message/To", FALSE);
4335 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4336 gtk_check_menu_item_set_active
4337 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4339 gtk_widget_show(compose->to_hbox);
4340 gtk_widget_show(compose->to_entry);
4341 gtk_widget_show(compose->cc_hbox);
4342 gtk_widget_show(compose->cc_entry);
4344 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4346 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
4349 gtk_widget_queue_resize(compose->table_vbox);
4352 static void account_activated(GtkMenuItem *menuitem, gpointer data)
4354 Compose *compose = (Compose *)data;
4358 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
4359 g_return_if_fail(ac != NULL);
4361 if (ac != compose->account)
4362 select_account(compose, ac);
4365 static void attach_selected(GtkCList *clist, gint row, gint column,
4366 GdkEvent *event, gpointer data)
4368 Compose *compose = (Compose *)data;
4370 if (event && event->type == GDK_2BUTTON_PRESS)
4371 compose_attach_property(compose);
4374 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
4377 Compose *compose = (Compose *)data;
4378 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4383 if (event->button == 3) {
4384 if ((clist->selection && !clist->selection->next) ||
4385 !clist->selection) {
4386 gtk_clist_unselect_all(clist);
4387 if (gtk_clist_get_selection_info(clist,
4390 gtk_clist_select_row(clist, row, column);
4391 gtkut_clist_set_focus_row(clist, row);
4394 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
4395 NULL, NULL, event->button, event->time);
4399 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
4402 Compose *compose = (Compose *)data;
4406 switch (event->keyval) {
4408 compose_attach_remove_selected(compose);
4413 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
4415 Compose *compose = (Compose *)data;
4418 val = compose_send(compose);
4420 if (val == 0) gtk_widget_destroy(compose->window);
4423 static void compose_send_later_cb(gpointer data, guint action,
4426 Compose *compose = (Compose *)data;
4428 gchar *to, *newsgroups;
4430 to = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
4431 newsgroups = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
4432 if (*to == '\0' && *newsgroups == '\0') {
4433 alertpanel_error(_("Recipient is not specified."));
4437 g_snprintf(tmp, 22, "%s%ctmpmsg%d",
4438 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
4440 if (prefs_common.linewrap_at_send)
4441 compose_wrap_line(compose);
4443 if (compose_write_to_file(compose, tmp, FALSE) < 0 ||
4444 compose_queue(compose, tmp) < 0) {
4445 alertpanel_error(_("Can't queue the message."));
4449 if (prefs_common.savemsg) {
4450 if (compose_save_to_outbox(compose, tmp) < 0)
4452 (_("Can't save the message to outbox."));
4455 if (unlink(tmp) < 0)
4456 FILE_OP_ERROR(tmp, "unlink");
4458 gtk_widget_destroy(compose->window);
4461 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
4463 Compose *compose = (Compose *)data;
4467 draft = folder_get_default_draft();
4469 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
4470 G_DIR_SEPARATOR, (gint)compose);
4472 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
4477 folder_item_scan(draft);
4478 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
4485 if (compose->mode == COMPOSE_REEDIT) {
4486 compose_remove_reedit_target(compose);
4487 if (compose->targetinfo &&
4488 compose->targetinfo->folder != draft)
4489 folderview_update_item(compose->targetinfo->folder,
4493 folder_item_scan(draft);
4494 folderview_update_item(draft, TRUE);
4496 gtk_widget_destroy(compose->window);
4499 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
4501 Compose *compose = (Compose *)data;
4504 file_list = filesel_select_multiple_files(_("Select file"), NULL);
4509 for ( tmp = file_list; tmp; tmp = tmp->next) {
4510 gchar *file = (gchar *) tmp->data;
4511 compose_attach_append(compose, file, MIME_UNKNOWN);
4514 g_list_free(file_list);
4518 static void compose_insert_file_cb(gpointer data, guint action,
4521 Compose *compose = (Compose *)data;
4524 file_list = filesel_select_multiple_files(_("Select file"), NULL);
4529 for ( tmp = file_list; tmp; tmp = tmp->next) {
4530 gchar *file = (gchar *) tmp->data;
4531 compose_insert_file(compose, file);
4534 g_list_free(file_list);
4538 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
4541 compose_close_cb(data, 0, NULL);
4545 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
4547 Compose *compose = (Compose *)data;
4550 if (compose->exteditor_tag != -1) {
4551 if (!compose_ext_editor_kill(compose))
4555 if (compose->modified) {
4556 val = alertpanel(_("Discard message"),
4557 _("This message has been modified. discard it?"),
4558 _("Discard"), _("to Draft"), _("Cancel"));
4561 case G_ALERTDEFAULT:
4563 case G_ALERTALTERNATE:
4564 compose_draft_cb(data, 0, NULL);
4571 gtk_widget_destroy(compose->window);
4574 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
4576 Compose *compose = (Compose *)data;
4578 addressbook_open(compose);
4581 static void compose_ext_editor_cb(gpointer data, guint action,
4584 Compose *compose = (Compose *)data;
4586 compose_exec_ext_editor(compose);
4589 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
4591 compose_destroy(compose);
4594 static void compose_cut_cb(Compose *compose)
4596 if (compose->focused_editable &&
4597 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4598 gtk_editable_cut_clipboard
4599 (GTK_EDITABLE(compose->focused_editable));
4602 static void compose_copy_cb(Compose *compose)
4604 if (compose->focused_editable &&
4605 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4606 gtk_editable_copy_clipboard
4607 (GTK_EDITABLE(compose->focused_editable));
4610 static void compose_paste_cb(Compose *compose)
4612 if (compose->focused_editable &&
4613 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4614 gtk_editable_paste_clipboard
4615 (GTK_EDITABLE(compose->focused_editable));
4618 static void compose_allsel_cb(Compose *compose)
4620 if (compose->focused_editable &&
4621 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
4622 gtk_editable_select_region
4623 (GTK_EDITABLE(compose->focused_editable), 0, -1);
4626 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
4628 if (GTK_IS_EDITABLE(widget))
4629 compose->focused_editable = widget;
4632 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
4634 if (compose->modified == FALSE) {
4635 compose->modified = TRUE;
4636 compose_set_title(compose);
4640 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
4643 gtk_stext_set_point(GTK_STEXT(widget),
4644 gtk_editable_get_position(GTK_EDITABLE(widget)));
4648 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
4651 gtk_stext_set_point(GTK_STEXT(widget),
4652 gtk_editable_get_position(GTK_EDITABLE(widget)));
4656 static void compose_toggle_to_cb(gpointer data, guint action,
4659 Compose *compose = (Compose *)data;
4661 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4662 gtk_widget_show(compose->to_hbox);
4663 gtk_widget_show(compose->to_entry);
4664 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
4665 compose->use_to = TRUE;
4667 gtk_widget_hide(compose->to_hbox);
4668 gtk_widget_hide(compose->to_entry);
4669 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
4670 gtk_widget_queue_resize(compose->table_vbox);
4671 compose->use_to = FALSE;
4674 if (addressbook_get_target_compose() == compose)
4675 addressbook_set_target_compose(compose);
4678 static void compose_toggle_cc_cb(gpointer data, guint action,
4681 Compose *compose = (Compose *)data;
4683 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4684 gtk_widget_show(compose->cc_hbox);
4685 gtk_widget_show(compose->cc_entry);
4686 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
4687 compose->use_cc = TRUE;
4689 gtk_widget_hide(compose->cc_hbox);
4690 gtk_widget_hide(compose->cc_entry);
4691 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
4692 gtk_widget_queue_resize(compose->table_vbox);
4693 compose->use_cc = FALSE;
4696 if (addressbook_get_target_compose() == compose)
4697 addressbook_set_target_compose(compose);
4700 static void compose_toggle_bcc_cb(gpointer data, guint action,
4703 Compose *compose = (Compose *)data;
4705 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4706 gtk_widget_show(compose->bcc_hbox);
4707 gtk_widget_show(compose->bcc_entry);
4708 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
4709 compose->use_bcc = TRUE;
4711 gtk_widget_hide(compose->bcc_hbox);
4712 gtk_widget_hide(compose->bcc_entry);
4713 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
4714 gtk_widget_queue_resize(compose->table_vbox);
4715 compose->use_bcc = FALSE;
4718 if (addressbook_get_target_compose() == compose)
4719 addressbook_set_target_compose(compose);
4722 static void compose_toggle_replyto_cb(gpointer data, guint action,
4725 Compose *compose = (Compose *)data;
4727 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4728 gtk_widget_show(compose->reply_hbox);
4729 gtk_widget_show(compose->reply_entry);
4730 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
4731 compose->use_replyto = TRUE;
4733 gtk_widget_hide(compose->reply_hbox);
4734 gtk_widget_hide(compose->reply_entry);
4735 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
4736 gtk_widget_queue_resize(compose->table_vbox);
4737 compose->use_replyto = FALSE;
4741 static void compose_toggle_followupto_cb(gpointer data, guint action,
4744 Compose *compose = (Compose *)data;
4746 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4747 gtk_widget_show(compose->followup_hbox);
4748 gtk_widget_show(compose->followup_entry);
4749 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
4750 compose->use_followupto = TRUE;
4752 gtk_widget_hide(compose->followup_hbox);
4753 gtk_widget_hide(compose->followup_entry);
4754 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
4755 gtk_widget_queue_resize(compose->table_vbox);
4756 compose->use_followupto = FALSE;
4760 static void compose_toggle_attach_cb(gpointer data, guint action,
4763 Compose *compose = (Compose *)data;
4765 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4766 gtk_widget_ref(compose->edit_vbox);
4768 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4769 compose->edit_vbox);
4770 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
4771 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
4773 gtk_widget_show(compose->paned);
4775 gtk_widget_unref(compose->edit_vbox);
4776 gtk_widget_unref(compose->paned);
4778 compose->use_attach = TRUE;
4780 gtk_widget_ref(compose->paned);
4781 gtk_widget_ref(compose->edit_vbox);
4783 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
4785 gtk_container_remove(GTK_CONTAINER(compose->paned),
4786 compose->edit_vbox);
4787 gtk_box_pack_start(GTK_BOX(compose->vbox2),
4788 compose->edit_vbox, TRUE, TRUE, 0);
4790 gtk_widget_unref(compose->edit_vbox);
4792 compose->use_attach = FALSE;
4797 static void compose_toggle_sign_cb(gpointer data, guint action,
4800 Compose *compose = (Compose *)data;
4802 if (GTK_CHECK_MENU_ITEM(widget)->active)
4803 compose->use_signing = TRUE;
4805 compose->use_signing = FALSE;
4808 static void compose_toggle_encrypt_cb(gpointer data, guint action,
4811 Compose *compose = (Compose *)data;
4813 if (GTK_CHECK_MENU_ITEM(widget)->active)
4814 compose->use_encryption = TRUE;
4816 compose->use_encryption = FALSE;
4818 #endif /* USE_GPGME */
4820 static void compose_toggle_ruler_cb(gpointer data, guint action,
4823 Compose *compose = (Compose *)data;
4825 if (GTK_CHECK_MENU_ITEM(widget)->active) {
4826 gtk_widget_show(compose->ruler_hbox);
4827 prefs_common.show_ruler = TRUE;
4829 gtk_widget_hide(compose->ruler_hbox);
4830 gtk_widget_queue_resize(compose->edit_vbox);
4831 prefs_common.show_ruler = FALSE;
4835 static void compose_attach_drag_received_cb (GtkWidget *widget,
4836 GdkDragContext *drag_context,
4839 GtkSelectionData *data,
4844 Compose *compose = (Compose *)user_data;
4847 list = uri_list_extract_filenames((const gchar *)data->data);
4848 for (tmp = list; tmp != NULL; tmp = tmp->next)
4849 compose_attach_append(compose, (const gchar *)tmp->data,
4851 list_free_strings(list);
4855 static void compose_insert_drag_received_cb (GtkWidget *widget,
4856 GdkDragContext *drag_context,
4859 GtkSelectionData *data,
4864 Compose *compose = (Compose *)user_data;
4867 list = uri_list_extract_filenames((const gchar *)data->data);
4868 for (tmp = list; tmp != NULL; tmp = tmp->next)
4869 compose_insert_file(compose, (const gchar *)tmp->data);
4870 list_free_strings(list);
4874 static void to_activated(GtkWidget *widget, Compose *compose)
4876 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
4877 gtk_widget_grab_focus(compose->newsgroups_entry);
4879 gtk_widget_grab_focus(compose->subject_entry);
4882 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
4884 gtk_widget_grab_focus(compose->subject_entry);
4887 static void subject_activated(GtkWidget *widget, Compose *compose)
4889 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
4890 gtk_widget_grab_focus(compose->cc_entry);
4891 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4892 gtk_widget_grab_focus(compose->bcc_entry);
4893 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4894 gtk_widget_grab_focus(compose->reply_entry);
4895 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4896 gtk_widget_grab_focus(compose->followup_entry);
4898 gtk_widget_grab_focus(compose->text);
4901 static void cc_activated(GtkWidget *widget, Compose *compose)
4903 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
4904 gtk_widget_grab_focus(compose->bcc_entry);
4905 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4906 gtk_widget_grab_focus(compose->reply_entry);
4907 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4908 gtk_widget_grab_focus(compose->followup_entry);
4910 gtk_widget_grab_focus(compose->text);
4913 static void bcc_activated(GtkWidget *widget, Compose *compose)
4915 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
4916 gtk_widget_grab_focus(compose->reply_entry);
4917 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4918 gtk_widget_grab_focus(compose->followup_entry);
4920 gtk_widget_grab_focus(compose->text);
4923 static void replyto_activated(GtkWidget *widget, Compose *compose)
4925 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
4926 gtk_widget_grab_focus(compose->followup_entry);
4928 gtk_widget_grab_focus(compose->text);
4931 static void followupto_activated(GtkWidget *widget, Compose *compose)
4933 gtk_widget_grab_focus(compose->text);
4936 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
4939 Compose *compose = (Compose *)data;
4941 if (GTK_CHECK_MENU_ITEM(widget)->active)
4942 compose->return_receipt = TRUE;
4944 compose->return_receipt = FALSE;
4947 static gchar *compose_quote_fmt (Compose *compose,
4952 gchar * quote_str = NULL;
4954 if (qmark != NULL) {
4957 quote_fmt_init(msginfo, NULL);
4958 quote_fmt_scan_string(qmark);
4961 p = quote_fmt_get_buffer();
4964 (_("Quote mark format error."));
4967 quote_str = alloca(strlen(p) + 1);
4968 strcpy(quote_str, p);
4972 quote_fmt_init(msginfo, quote_str);
4973 quote_fmt_scan_string(fmt);
4976 if (quote_fmt_get_buffer() == NULL)
4978 (_("Message reply/forward format error."));
4980 return quote_fmt_get_buffer();
4983 static void template_apply_cb(gchar *s, gpointer data)
4985 Compose *compose = (Compose*)data;
4986 GtkSText *text = GTK_STEXT(compose->text);
4991 gchar *old_tmpl = s;
4995 if(compose->replyinfo == NULL) {
4996 gtk_stext_freeze(text);
4997 gtk_stext_set_point(text, 0);
4998 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
4999 gtk_stext_insert(text, NULL, NULL, NULL, s, -1);
5000 gtk_stext_thaw(text);
5005 parsed_text = g_new(gchar, strlen(s)*2 + 1);
5009 *parsed_text++ = '\\';
5010 *parsed_text++ = 'n';
5013 *parsed_text++ = *s++;
5016 *parsed_text = '\0';
5018 if (prefs_common.quotemark && *prefs_common.quotemark)
5019 qmark = prefs_common.quotemark;
5023 quote_str = compose_quote_fmt(compose, compose->replyinfo, tmpl, qmark);
5024 if (quote_str != NULL) {
5025 gtk_stext_freeze(text);
5026 gtk_stext_set_point(text, 0);
5027 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5028 gtk_stext_insert(text, NULL, NULL, NULL, quote_str, -1);
5029 gtk_stext_thaw(text);
5036 static void template_select_cb(gpointer data, guint action,
5039 template_select(&template_apply_cb, data);