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"
102 #include "quote_fmt.h"
103 #include "template.h"
106 # include "rfc2015.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,
129 static void compose_toolbar_create (Compose *compose,
130 GtkWidget *container);
131 static GtkWidget *compose_account_option_menu_create
133 static void compose_set_template_menu (Compose *compose);
134 static void compose_destroy (Compose *compose);
136 static gint compose_parse_header (Compose *compose,
138 static gchar *compose_parse_references (const gchar *ref,
141 static gchar *compose_quote_fmt (Compose *compose,
146 static void compose_reply_set_entry (Compose *compose,
151 followup_and_reply_to);
152 static void compose_reedit_set_entry (Compose *compose,
154 static void compose_insert_sig (Compose *compose);
155 static void compose_insert_file (Compose *compose,
157 static void compose_attach_append (Compose *compose,
159 ContentType cnttype);
160 static void compose_attach_append_with_type(Compose *compose,
163 ContentType cnttype);
164 static void compose_wrap_line (Compose *compose);
165 static void compose_wrap_line_all (Compose *compose);
166 static void compose_set_title (Compose *compose);
168 static PrefsAccount *compose_current_mail_account(void);
169 /* static gint compose_send (Compose *compose); */
170 static gint compose_write_to_file (Compose *compose,
173 static gint compose_write_body_to_file (Compose *compose,
175 static gint compose_save_to_outbox (Compose *compose,
177 static gint compose_remove_reedit_target (Compose *compose);
178 static gint compose_queue (Compose *compose,
180 static void compose_write_attach (Compose *compose,
182 static gint compose_write_headers (Compose *compose,
184 const gchar *charset,
185 EncodingType encoding,
188 static void compose_convert_header (gchar *dest,
192 static void compose_generate_msgid (Compose *compose,
196 static void compose_attach_info_free (AttachInfo *ainfo);
197 static void compose_attach_remove_selected (Compose *compose);
199 static void compose_attach_property (Compose *compose);
200 static void compose_attach_property_create (gboolean *cancelled);
201 static void attach_property_ok (GtkWidget *widget,
202 gboolean *cancelled);
203 static void attach_property_cancel (GtkWidget *widget,
204 gboolean *cancelled);
205 static gint attach_property_delete_event (GtkWidget *widget,
207 gboolean *cancelled);
208 static void attach_property_key_pressed (GtkWidget *widget,
210 gboolean *cancelled);
212 static void compose_exec_ext_editor (Compose *compose);
213 static gint compose_exec_ext_editor_real (const gchar *file);
214 static gboolean compose_ext_editor_kill (Compose *compose);
215 static void compose_input_cb (gpointer data,
217 GdkInputCondition condition);
218 static void compose_set_ext_editor_sensitive (Compose *compose,
221 static gint calc_cursor_xpos (GtkSText *text,
225 static void compose_create_header_entry (Compose *compose);
226 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
228 /* callback functions */
230 static gboolean compose_edit_size_alloc (GtkEditable *widget,
231 GtkAllocation *allocation,
232 GtkSHRuler *shruler);
234 static void toolbar_send_cb (GtkWidget *widget,
236 static void toolbar_send_later_cb (GtkWidget *widget,
238 static void toolbar_draft_cb (GtkWidget *widget,
240 static void toolbar_insert_cb (GtkWidget *widget,
242 static void toolbar_attach_cb (GtkWidget *widget,
244 static void toolbar_sig_cb (GtkWidget *widget,
246 static void toolbar_ext_editor_cb (GtkWidget *widget,
248 static void toolbar_linewrap_cb (GtkWidget *widget,
250 static void toolbar_address_cb (GtkWidget *widget,
252 static void template_select_cb (gpointer daat,
257 static void select_account(Compose * compose, PrefsAccount * ac);
258 static void account_activated (GtkMenuItem *menuitem,
261 static void attach_selected (GtkCList *clist,
266 static void attach_button_pressed (GtkWidget *widget,
267 GdkEventButton *event,
269 static void attach_key_pressed (GtkWidget *widget,
273 static void compose_send_cb (gpointer data,
276 static void compose_send_later_cb (gpointer data,
280 static void compose_draft_cb (gpointer data,
284 static void compose_attach_cb (gpointer data,
287 static void compose_insert_file_cb (gpointer data,
291 static void compose_close_cb (gpointer data,
295 static void compose_address_cb (gpointer data,
298 static void compose_template_activate_cb(GtkWidget *widget,
301 static void compose_ext_editor_cb (gpointer data,
305 static gint compose_delete_cb (GtkWidget *widget,
308 static void compose_destroy_cb (GtkWidget *widget,
311 static void compose_cut_cb (Compose *compose);
312 static void compose_copy_cb (Compose *compose);
313 static void compose_paste_cb (Compose *compose);
314 static void compose_allsel_cb (Compose *compose);
316 static void compose_grab_focus_cb (GtkWidget *widget,
319 static void compose_changed_cb (GtkEditable *editable,
321 static void compose_button_press_cb (GtkWidget *widget,
322 GdkEventButton *event,
325 static void compose_key_press_cb (GtkWidget *widget,
330 static void compose_toggle_to_cb (gpointer data,
333 static void compose_toggle_cc_cb (gpointer data,
336 static void compose_toggle_bcc_cb (gpointer data,
339 static void compose_toggle_replyto_cb (gpointer data,
342 static void compose_toggle_followupto_cb(gpointer data,
345 static void compose_toggle_attach_cb (gpointer data,
348 static void compose_toggle_ruler_cb (gpointer data,
352 static void compose_toggle_sign_cb (gpointer data,
355 static void compose_toggle_encrypt_cb (gpointer data,
359 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
362 static void compose_attach_drag_received_cb (GtkWidget *widget,
363 GdkDragContext *drag_context,
366 GtkSelectionData *data,
370 static void compose_insert_drag_received_cb (GtkWidget *widget,
371 GdkDragContext *drag_context,
374 GtkSelectionData *data,
379 static void to_activated (GtkWidget *widget,
381 static void newsgroups_activated (GtkWidget *widget,
383 static void subject_activated (GtkWidget *widget,
385 static void cc_activated (GtkWidget *widget,
387 static void bcc_activated (GtkWidget *widget,
389 static void replyto_activated (GtkWidget *widget,
391 static void followupto_activated (GtkWidget *widget,
393 static void compose_attach_parts(Compose * compose,
396 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
398 gboolean ignore_replyto,
399 gboolean followup_and_reply_to);
401 void compose_headerentry_changed_cb (GtkWidget *entry,
402 compose_headerentry *headerentry);
403 void compose_headerentry_key_press_event_cb (GtkWidget *entry,
405 compose_headerentry *headerentry);
407 Compose * compose_generic_new (PrefsAccount *account,
411 static GtkItemFactoryEntry compose_popup_entries[] =
413 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
414 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
415 {N_("/---"), NULL, NULL, 0, "<Separator>"},
416 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
419 static GtkItemFactoryEntry compose_entries[] =
421 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
422 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
423 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
424 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
425 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
426 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
428 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
429 {N_("/_Edit/_Undo"), "<control>Z", NULL, 0, NULL},
430 {N_("/_Edit/_Redo"), "<control>Y", NULL, 0, NULL},
431 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
432 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
433 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
434 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
435 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
436 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
437 {N_("/_Edit/_Wrap current paragraph"), "<alt>L", compose_wrap_line, 0, NULL},
438 {N_("/_Edit/Wrap all long _lines"),
439 "<shift><alt>L", compose_wrap_line_all, 0, NULL},
440 {N_("/_Edit/Edit with e_xternal editor"),
441 "<alt>X", compose_ext_editor_cb, 0, NULL},
443 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
444 {N_("/_Message/_Send"), "<control>Return",
445 compose_send_cb, 0, NULL},
446 {N_("/_Message/Send _later"), "<shift><alt>S",
447 compose_send_later_cb, 0, NULL},
448 {N_("/_Message/Save to _draft folder"),
449 "<alt>D", compose_draft_cb, 0, NULL},
450 #if 0 /* NEW COMPOSE GUI */
451 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
452 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
453 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
454 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
455 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
456 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
457 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
458 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
459 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
462 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
463 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
464 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
465 #endif /* USE_GPGME */
466 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
467 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
468 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
469 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
470 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb , 0, NULL},
471 {N_("/_Tool/_Template"), NULL, NULL, 0, "<Branch>"},
472 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
473 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
476 static GtkTargetEntry compose_mime_types[] =
478 {"text/uri-list", 0, 0}
481 Compose * compose_new(PrefsAccount *account)
483 return compose_generic_new(account, NULL, NULL);
486 Compose * compose_new_with_recipient(PrefsAccount *account, const gchar *to)
488 return compose_generic_new(account, to, NULL);
491 Compose * compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
493 return compose_generic_new(account, NULL, item);
496 static void set_compose_entries(Compose * compose, const gchar * mailto)
498 gchar * subject = NULL;
507 Xstrdup_a(tmp_mailto, mailto, return);
511 p = strchr(cur, '?');
523 p = strchr(cur, '=');
531 p = strchr(cur, '&');
538 if (g_strcasecmp(field, "subject")==0) {
539 Xstrdup_a(subject, value, );
541 decode_uri(subject, value);
543 else if (g_strcasecmp(field, "cc")==0)
545 else if (g_strcasecmp(field, "bcc")==0)
547 else if (g_strcasecmp(field, "body")==0) {
548 Xstrdup_a(body, value, );
550 decode_uri(body, value);
556 compose_entry_append(compose, to, COMPOSE_TO);
558 gtk_widget_grab_focus(compose->text);
563 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
565 compose_entry_append(compose, cc, COMPOSE_CC);
567 compose_entry_append(compose, bcc, COMPOSE_BCC);
569 gtk_stext_insert(GTK_STEXT(compose->text),
570 NULL, NULL, NULL, body, -1);
571 gtk_stext_insert(GTK_STEXT(compose->text),
572 NULL, NULL, NULL, "\n", 1);
576 Compose * compose_generic_new(PrefsAccount *account, const gchar *to, FolderItem *item)
580 if (item && item->prefs && item->prefs->enable_default_account)
581 account = account_find_from_id(item->prefs->default_account);
583 if (!account) account = cur_account;
584 g_return_val_if_fail(account != NULL, NULL);
586 compose = compose_create(account, COMPOSE_NEW);
587 compose->replyinfo = NULL;
589 if (prefs_common.auto_sig)
590 compose_insert_sig(compose);
591 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
592 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
594 if (account->protocol != A_NNTP) {
596 set_compose_entries(compose, to);
598 } else if(item && item->prefs->enable_default_to) {
599 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
601 if (item && item->ret_rcpt) {
602 GtkItemFactory *ifactory;
604 ifactory = gtk_item_factory_from_widget(compose->menubar);
605 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
609 compose_entry_append(compose, to, COMPOSE_NEWSGROUPS);
612 gtk_widget_grab_focus(compose->subject_entry);
614 if (prefs_common.auto_exteditor)
615 compose_exec_ext_editor(compose);
620 #define CHANGE_FLAGS(msginfo) \
622 if (msginfo->folder->folder->change_flags != NULL) \
623 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
629 Compose * compose_new_followup_and_replyto(PrefsAccount *account,
630 const gchar *followupto, gchar * to)
634 if (!account) account = cur_account;
635 g_return_val_if_fail(account != NULL, NULL);
636 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
638 compose = compose_create(account, COMPOSE_NEW);
640 if (prefs_common.auto_sig)
641 compose_insert_sig(compose);
642 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
643 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
645 compose_entry_append(compose, to, COMPOSE_TO);
646 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
647 gtk_widget_grab_focus(compose->subject_entry);
653 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
654 gboolean ignore_replyto)
656 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
659 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
661 gboolean ignore_replyto)
663 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
666 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
668 gboolean ignore_replyto,
669 gboolean followup_and_reply_to)
672 PrefsAccount *account;
673 PrefsAccount *reply_account;
676 g_return_if_fail(msginfo != NULL);
677 g_return_if_fail(msginfo->folder != NULL);
680 /* select the account set in folderitem's property (if enabled) */
681 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
682 account = account_find_from_id(msginfo->folder->prefs->default_account);
684 /* select the account for the whole folder (IMAP / NNTP) */
686 account = msginfo->folder->folder->account;
688 /* select account by to: and cc: header if enabled */
689 if (prefs_common.reply_account_autosel) {
690 if (!account && msginfo->to) {
692 Xstrdup_a(to, msginfo->to, return);
694 account = account_find_from_address(to);
698 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
700 account = account_find_from_address(cc);
705 /* select current account */
706 if (!account) account = cur_account;
707 g_return_if_fail(account != NULL);
709 if (ignore_replyto && account->protocol == A_NNTP &&
710 !followup_and_reply_to) {
712 account_find_from_address(account->address);
714 reply_account = compose_current_mail_account();
718 reply_account = account;
720 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
721 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
723 CHANGE_FLAGS(msginfo);
725 compose = compose_create(account, COMPOSE_REPLY);
726 compose->replyinfo = procmsg_msginfo_copy(msginfo);
728 #if 0 /* NEW COMPOSE GUI */
729 if (followup_and_reply_to) {
730 gtk_widget_show(compose->to_hbox);
731 gtk_widget_show(compose->to_entry);
732 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
733 compose->use_to = TRUE;
736 if (msginfo->folder && msginfo->folder->ret_rcpt) {
737 GtkItemFactory *ifactory;
739 ifactory = gtk_item_factory_from_widget(compose->menubar);
740 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
743 if (compose_parse_header(compose, msginfo) < 0) return;
744 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
745 followup_and_reply_to);
747 text = GTK_STEXT(compose->text);
748 gtk_stext_freeze(text);
754 if (prefs_common.quotemark && *prefs_common.quotemark)
755 qmark = prefs_common.quotemark;
759 quote_str = compose_quote_fmt(compose, msginfo,
760 prefs_common.quotefmt,
764 if (prefs_common.auto_sig)
765 compose_insert_sig(compose);
766 gtk_editable_set_position(GTK_EDITABLE(text), 0);
767 gtk_stext_set_point(text, 0);
769 if (quote && prefs_common.linewrap_quote) {
770 compose_wrap_line_all(compose);
773 gtk_stext_thaw(text);
774 gtk_widget_grab_focus(compose->text);
776 if (prefs_common.auto_exteditor)
777 compose_exec_ext_editor(compose);
781 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
786 g_return_val_if_fail(mimeinfo != NULL, NULL);
788 base = mimeinfo->filename ? mimeinfo->filename
789 : mimeinfo->name ? mimeinfo->name : NULL;
791 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
792 filename = g_strdup_printf("%s%smimetmp%i.html",
799 base = base ? base : "";
800 base = g_basename(base);
802 filename = g_strdup_printf("%s%smimetmp%i",
810 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
816 static gchar * mime_extract_file(gchar * source, MimeInfo *partinfo)
820 if (!partinfo) return;
822 filename = procmime_get_file_name(partinfo);
824 if (procmime_get_part(filename, source, partinfo) < 0)
826 (_("Can't get the part of multipart message."));
831 static void compose_attach_parts(Compose * compose,
841 gint boundary_len = 0;
843 glong fpos, prev_fpos;
848 g_return_if_fail(msginfo != NULL);
852 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
853 mimeinfo = procmime_scan_mime_header(fp);
854 if (!mimeinfo) break;
856 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
857 rfc2015_is_encrypted(mimeinfo)) {
858 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
860 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
861 !msginfo->plaintext_file &&
862 !msginfo->decryption_failed) {
863 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
864 if (msginfo->plaintext_file &&
865 !msginfo->decryption_failed) {
873 #else /* !USE_GPGME */
874 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
875 mimeinfo = procmime_scan_mime_header(fp);
876 #endif /* USE_GPGME */
879 if (!mimeinfo) return;
880 if (mimeinfo->mime_type == MIME_TEXT)
883 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
885 g_return_if_fail(mimeinfo != NULL);
886 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
888 if (mimeinfo->mime_type == MIME_MULTIPART) {
889 g_return_if_fail(mimeinfo->boundary != NULL);
890 g_return_if_fail(mimeinfo->sub == NULL);
892 g_return_if_fail(fp != NULL);
894 boundary = mimeinfo->boundary;
897 boundary_len = strlen(boundary);
899 /* look for first boundary */
900 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
901 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
908 if ((fpos = ftell(fp)) < 0) {
914 for (npart = 0;; npart++) {
916 gboolean eom = FALSE;
920 partinfo = procmime_scan_mime_header(fp);
921 if (!partinfo) break;
924 procmime_mimeinfo_insert(mimeinfo, partinfo);
926 procmime_mimeinfo_free(partinfo);
928 /* look for next boundary */
930 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
931 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
932 if (buf[2 + boundary_len] == '-' &&
933 buf[2 + boundary_len + 1] == '-')
939 eom = TRUE; /* broken MIME message */
942 partinfo->size = fpos - prev_fpos - strlen(buf);
947 source = procmsg_get_message_file_path(msginfo);
949 g_return_if_fail(mimeinfo != NULL);
951 if (!mimeinfo->main && mimeinfo->parent)
953 filename = mime_extract_file(source, mimeinfo);
955 compose_attach_append_with_type(compose, filename,
956 mimeinfo->content_type,
957 mimeinfo->mime_type);
962 if (mimeinfo->sub && mimeinfo->sub->children)
964 filename = mime_extract_file(source, mimeinfo->sub);
966 compose_attach_append_with_type(compose, filename,
967 mimeinfo->content_type,
968 mimeinfo->sub->mime_type);
973 if (mimeinfo->children) {
976 child = mimeinfo->children;
978 filename = mime_extract_file(source, child);
980 compose_attach_append_with_type(compose, filename,
992 procmime_mimeinfo_free_all(mimeinfo);
996 #define INSERT_FW_HEADER(var, hdr) \
997 if (msginfo->var && *msginfo->var) { \
998 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
999 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1000 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1003 Compose *compose_forward(PrefsAccount * account, MsgInfo *msginfo,
1007 /* PrefsAccount *account; */
1010 g_return_val_if_fail(msginfo != NULL, NULL);
1011 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1013 account = msginfo->folder->folder->account;
1014 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1016 Xstrdup_a(to, msginfo->to, return);
1017 extract_address(to);
1018 account = account_find_from_address(to);
1021 if(!account && prefs_common.forward_account_autosel) {
1023 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1024 extract_address(cc);
1025 account = account_find_from_address(cc);
1029 if (account == NULL) {
1030 account = cur_account;
1032 account = msginfo->folder->folder->account;
1033 if (!account) account = cur_account;
1036 g_return_val_if_fail(account != NULL, NULL);
1038 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1039 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1040 CHANGE_FLAGS(msginfo);
1042 compose = compose_create(account, COMPOSE_FORWARD);
1044 if (msginfo->subject && *msginfo->subject) {
1045 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1046 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1050 text = GTK_STEXT(compose->text);
1051 gtk_stext_freeze(text);
1056 msgfile = procmsg_get_message_file_path(msginfo);
1057 if (!is_file_exist(msgfile))
1058 g_warning(_("%s: file not exist\n"), msgfile);
1060 compose_attach_append(compose, msgfile,
1061 MIME_MESSAGE_RFC822);
1068 if (prefs_common.fw_quotemark && *prefs_common.fw_quotemark)
1069 qmark = prefs_common.quotemark;
1073 quote_str = compose_quote_fmt(compose, msginfo,
1074 prefs_common.fw_quotefmt, qmark);
1075 compose_attach_parts(compose, msginfo);
1078 if (prefs_common.auto_sig)
1079 compose_insert_sig(compose);
1080 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1081 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1083 gtk_stext_thaw(text);
1084 #if 0 /* NEW COMPOSE GUI */
1085 if (account->protocol != A_NNTP)
1086 gtk_widget_grab_focus(compose->to_entry);
1088 gtk_widget_grab_focus(compose->newsgroups_entry);
1090 gtk_widget_grab_focus(compose->header_last->entry);
1092 if (prefs_common.auto_exteditor)
1093 compose_exec_ext_editor(compose);
1098 #undef INSERT_FW_HEADER
1100 Compose * compose_forward_multiple(PrefsAccount * account,
1101 GSList *msginfo_list)
1108 g_return_val_if_fail(msginfo_list != NULL, NULL);
1110 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1111 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1115 if (account == NULL) {
1116 account = cur_account;
1118 account = msginfo->folder->folder->account;
1119 if (!account) account = cur_account;
1122 g_return_val_if_fail(account != NULL, NULL);
1124 compose = compose_create(account, COMPOSE_FORWARD);
1126 text = GTK_STEXT(compose->text);
1127 gtk_stext_freeze(text);
1129 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1130 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1131 if (!is_file_exist(msgfile))
1132 g_warning(_("%s: file not exist\n"), msgfile);
1134 compose_attach_append(compose, msgfile,
1135 MIME_MESSAGE_RFC822);
1139 if (prefs_common.auto_sig)
1140 compose_insert_sig(compose);
1141 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1142 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1144 gtk_stext_thaw(text);
1145 #if 0 /* NEW COMPOSE GUI */
1146 if (account->protocol != A_NNTP)
1147 gtk_widget_grab_focus(compose->to_entry);
1149 gtk_widget_grab_focus(compose->newsgroups_entry);
1155 void compose_reedit(MsgInfo *msginfo)
1158 PrefsAccount *account;
1161 gchar buf[BUFFSIZE];
1163 g_return_if_fail(msginfo != NULL);
1164 g_return_if_fail(msginfo->folder != NULL);
1166 account = msginfo->folder->folder->account;
1168 if(!account&& prefs_common.reedit_account_autosel) {
1169 gchar from[BUFFSIZE];
1170 if(!get_header_from_msginfo(msginfo,from,sizeof(from),"FROM:")){ /* Found a FROM header */
1171 extract_address(from);
1172 account = account_find_from_address(from);
1175 if (!account) account = cur_account;
1176 g_return_if_fail(account != NULL);
1178 compose = compose_create(account, COMPOSE_REEDIT);
1179 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1181 if (compose_parse_header(compose, msginfo) < 0) return;
1182 compose_reedit_set_entry(compose, msginfo);
1184 text = GTK_STEXT(compose->text);
1185 gtk_stext_freeze(text);
1187 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1188 g_warning(_("Can't get text part\n"));
1190 while (fgets(buf, sizeof(buf), fp) != NULL)
1191 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1194 compose_attach_parts(compose, msginfo);
1196 gtk_stext_thaw(text);
1197 gtk_widget_grab_focus(compose->text);
1199 if (prefs_common.auto_exteditor)
1200 compose_exec_ext_editor(compose);
1203 GList *compose_get_compose_list(void)
1205 return compose_list;
1208 void compose_entry_append(Compose *compose, const gchar *address,
1209 ComposeEntryType type)
1215 if (!address || *address == '\0') return;
1217 #if 0 /* NEW COMPOSE GUI */
1220 entry = GTK_ENTRY(compose->cc_entry);
1223 entry = GTK_ENTRY(compose->bcc_entry);
1225 case COMPOSE_NEWSGROUPS:
1226 entry = GTK_ENTRY(compose->newsgroups_entry);
1230 entry = GTK_ENTRY(compose->to_entry);
1234 text = gtk_entry_get_text(entry);
1236 gtk_entry_append_text(entry, ", ");
1237 gtk_entry_append_text(entry, address);
1245 header = N_("Bcc:");
1247 case COMPOSE_REPLYTO:
1248 header = N_("Reply-To:");
1250 case COMPOSE_NEWSGROUPS:
1251 header = N_("Newsgroups:");
1253 case COMPOSE_FOLLOWUPTO:
1254 header = N_( "Followup-To:");
1261 header = prefs_common.trans_hdr ? gettext(header) : header;
1263 compose_add_header_entry(compose, header, (gchar *)address);
1266 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1268 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1269 {"Cc:", NULL, FALSE},
1270 {"References:", NULL, FALSE},
1271 {"Bcc:", NULL, FALSE},
1272 {"Newsgroups:", NULL, FALSE},
1273 {"Followup-To:", NULL, FALSE},
1274 {"X-Mailing-List:", NULL, FALSE},
1275 {"X-BeenThere:", NULL, FALSE},
1276 {NULL, NULL, FALSE}};
1286 H_X_MAILING_LIST = 6,
1292 g_return_val_if_fail(msginfo != NULL, -1);
1294 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1295 procheader_get_header_fields(fp, hentry);
1298 if (hentry[H_REPLY_TO].body != NULL) {
1299 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1300 compose->replyto = hentry[H_REPLY_TO].body;
1301 hentry[H_REPLY_TO].body = NULL;
1303 if (hentry[H_CC].body != NULL) {
1304 conv_unmime_header_overwrite(hentry[H_CC].body);
1305 compose->cc = hentry[H_CC].body;
1306 hentry[H_CC].body = NULL;
1308 if (hentry[H_X_MAILING_LIST].body != NULL) {
1309 /* this is good enough to parse debian-devel */
1310 char * buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1311 g_return_val_if_fail(buf != NULL, -1 );
1312 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1313 compose->mailinglist = g_strdup(buf);
1315 g_free(hentry[H_X_MAILING_LIST].body);
1316 hentry[H_X_MAILING_LIST].body = NULL ;
1318 if (hentry[H_X_BEENTHERE].body != NULL) {
1319 /* this is good enough to parse the sylpheed-claws lists */
1320 char * buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1321 g_return_val_if_fail(buf != NULL, -1 );
1322 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1323 compose->mailinglist = g_strdup(buf);
1325 g_free(hentry[H_X_BEENTHERE].body);
1326 hentry[H_X_BEENTHERE].body = NULL ;
1328 if (hentry[H_REFERENCES].body != NULL) {
1329 if (compose->mode == COMPOSE_REEDIT)
1330 compose->references = hentry[H_REFERENCES].body;
1332 compose->references = compose_parse_references
1333 (hentry[H_REFERENCES].body, msginfo->msgid);
1334 g_free(hentry[H_REFERENCES].body);
1336 hentry[H_REFERENCES].body = NULL;
1338 if (hentry[H_BCC].body != NULL) {
1339 if (compose->mode == COMPOSE_REEDIT) {
1340 conv_unmime_header_overwrite(hentry[H_BCC].body);
1341 compose->bcc = hentry[H_BCC].body;
1343 g_free(hentry[H_BCC].body);
1344 hentry[H_BCC].body = NULL;
1346 if (hentry[H_NEWSGROUPS].body != NULL) {
1347 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1348 hentry[H_NEWSGROUPS].body = NULL;
1350 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1351 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1352 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1353 hentry[H_FOLLOWUP_TO].body = NULL;
1356 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1357 compose->inreplyto = g_strdup(msginfo->inreplyto);
1358 else if (compose->mode != COMPOSE_REEDIT &&
1359 msginfo->msgid && *msginfo->msgid) {
1360 compose->inreplyto = g_strdup(msginfo->msgid);
1362 if (!compose->references) {
1363 if (msginfo->inreplyto && *msginfo->inreplyto)
1364 compose->references =
1365 g_strdup_printf("<%s>\n\t<%s>",
1369 compose->references =
1370 g_strconcat("<", msginfo->msgid, ">",
1378 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1380 GSList *ref_id_list, *cur;
1384 ref_id_list = references_list_append(NULL, ref);
1385 if (!ref_id_list) return NULL;
1386 if (msgid && *msgid)
1387 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1392 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1393 /* "<" + Message-ID + ">" + CR+LF+TAB */
1394 len += strlen((gchar *)cur->data) + 5;
1396 if (len > MAX_REFERENCES_LEN) {
1397 /* remove second message-ID */
1398 if (ref_id_list && ref_id_list->next &&
1399 ref_id_list->next->next) {
1400 g_free(ref_id_list->next->data);
1401 ref_id_list = g_slist_remove
1402 (ref_id_list, ref_id_list->next->data);
1404 slist_free_strings(ref_id_list);
1405 g_slist_free(ref_id_list);
1412 new_ref = g_string_new("");
1413 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1414 if (new_ref->len > 0)
1415 g_string_append(new_ref, "\n\t");
1416 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1419 slist_free_strings(ref_id_list);
1420 g_slist_free(ref_id_list);
1422 new_ref_str = new_ref->str;
1423 g_string_free(new_ref, FALSE);
1428 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1429 const gchar *fmt, const gchar *qmark)
1431 GtkSText *text = GTK_STEXT(compose->text);
1432 gchar *quote_str = NULL;
1437 if (qmark != NULL) {
1438 quote_fmt_init(msginfo, NULL);
1439 quote_fmt_scan_string(qmark);
1442 buf = quote_fmt_get_buffer();
1444 alertpanel_error(_("Quote mark format error."));
1446 Xstrdup_a(quote_str, buf, return NULL)
1449 quote_fmt_init(msginfo, quote_str);
1450 quote_fmt_scan_string(fmt);
1453 buf = quote_fmt_get_buffer();
1455 alertpanel_error(_("Message reply/forward format error."));
1459 gtk_stext_freeze(text);
1460 gtk_stext_set_point(text, 0);
1461 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
1463 for (p = buf; *p != '\0'; ) {
1464 lastp = strchr(p, '\n');
1465 len = lastp ? lastp - p + 1 : -1;
1466 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1473 gtk_stext_thaw(text);
1478 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1479 gboolean to_all, gboolean ignore_replyto,
1480 gboolean followup_and_reply_to)
1485 GHashTable *to_table;
1487 g_return_if_fail(compose->account != NULL);
1488 g_return_if_fail(msginfo != NULL);
1490 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1491 compose_entry_append(compose,
1492 ((compose->mailinglist && !ignore_replyto)
1493 ? compose->mailinglist
1494 : (compose->replyto && !ignore_replyto)
1496 : msginfo->from ? msginfo->from : ""),
1498 if (compose->account->protocol == A_NNTP)
1500 compose_entry_append(compose,
1501 msginfo->from ? msginfo->from : "",
1504 compose_entry_append(compose,
1505 compose->followup_to ? compose->followup_to
1506 : compose->newsgroups ? compose->newsgroups
1508 COMPOSE_NEWSGROUPS);
1510 compose_entry_append(compose,
1511 compose->followup_to ? compose->followup_to
1512 : compose->newsgroups ? compose->newsgroups
1514 COMPOSE_NEWSGROUPS);
1517 if (msginfo->subject && *msginfo->subject) {
1518 gchar *buf, *buf2, *p;
1520 buf = g_strdup(msginfo->subject);
1521 while (!strncasecmp(buf, "Re:", 3)) {
1523 while (isspace(*p)) p++;
1524 memmove(buf, p, strlen(p) + 1);
1527 buf2 = g_strdup_printf("Re: %s", buf);
1528 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1532 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1534 if (!to_all || compose->account->protocol == A_NNTP) return;
1536 from = g_strdup(compose->replyto ? compose->replyto :
1537 msginfo->from ? msginfo->from : "");
1538 extract_address(from);
1540 cc_list = address_list_append(NULL, msginfo->to);
1541 cc_list = address_list_append(cc_list, compose->cc);
1543 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1544 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1545 if (compose->account)
1546 g_hash_table_insert(to_table, compose->account->address,
1547 GINT_TO_POINTER(1));
1549 /* remove address on To: and that of current account */
1550 for (cur = cc_list; cur != NULL; ) {
1551 GSList *next = cur->next;
1553 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1554 cc_list = g_slist_remove(cc_list, cur->data);
1556 g_hash_table_insert(to_table, cur->data, cur);
1560 g_hash_table_destroy(to_table);
1564 for (cur = cc_list; cur != NULL; cur = cur->next)
1565 compose_entry_append(compose, (gchar *)cur->data,
1567 slist_free_strings(cc_list);
1568 g_slist_free(cc_list);
1572 #define SET_ENTRY(entry, str) \
1575 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1578 #define SET_ADDRESS(type, str) \
1581 compose_entry_append(compose, str, type); \
1584 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1586 g_return_if_fail(msginfo != NULL);
1588 SET_ENTRY(subject_entry, msginfo->subject);
1589 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1590 SET_ADDRESS(COMPOSE_CC, compose->cc);
1591 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1592 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1594 #if 0 /* NEW COMPOSE GUI */
1596 GtkItemFactory *ifactory;
1597 GtkWidget *menuitem;
1599 ifactory = gtk_item_factory_from_widget(compose->menubar);
1600 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1601 gtk_check_menu_item_set_active
1602 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1604 if (compose->replyto) {
1605 GtkItemFactory *ifactory;
1606 GtkWidget *menuitem;
1608 ifactory = gtk_item_factory_from_widget(compose->menubar);
1609 menuitem = gtk_item_factory_get_item
1610 (ifactory, "/Message/Reply to");
1611 gtk_check_menu_item_set_active
1612 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1620 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1627 size_t buf_len = 128;
1629 if (strlen(sigfile) < 2)
1632 sigprg = popen(sigfile+1, "r");
1635 buf = g_malloc(buf_len);
1638 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1639 "Unable to insert signature (malloc failed)\n", -1);
1645 while (!feof(sigprg)) {
1646 bzero(buf, buf_len);
1647 fread(buf, buf_len-1, 1, sigprg);
1648 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1656 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1657 "Can't exec file: ", -1);
1658 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1663 static void compose_insert_sig(Compose *compose)
1667 if (compose->account && compose->account->sig_path)
1668 sigfile = g_strdup(compose->account->sig_path);
1670 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1671 DEFAULT_SIGNATURE, NULL);
1674 if (!is_file_or_fifo_exist(sigfile) & (sigfile[0] != '|')) {
1679 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1680 if (prefs_common.sig_sep) {
1681 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1682 prefs_common.sig_sep, -1);
1683 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1687 if (sigfile[0] == '|')
1689 compose_exec_sig(compose, sigfile);
1693 compose_insert_file(compose, sigfile);
1698 static void compose_insert_file(Compose *compose, const gchar *file)
1700 GtkSText *text = GTK_STEXT(compose->text);
1701 gchar buf[BUFFSIZE];
1705 g_return_if_fail(file != NULL);
1707 if ((fp = fopen(file, "r")) == NULL) {
1708 FILE_OP_ERROR(file, "fopen");
1712 gtk_stext_freeze(text);
1714 while (fgets(buf, sizeof(buf), fp) != NULL) {
1715 /* Strip <CR> if DOS/Windoze file, replace <CR> with <LF> if MAC file */
1717 if (len > 1 && buf[len - 2] == '\r' && buf[len - 1] == '\n') {
1718 buf[len - 2] = '\n';
1719 buf[len - 1] = '\0';
1722 if (buf[len] == '\r')
1726 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1729 gtk_stext_thaw(text);
1734 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1735 ContentType cnttype)
1737 gchar *text[N_ATTACH_COLS];
1740 text[COL_MIMETYPE] = ainfo->content_type;
1741 text[COL_SIZE] = to_human_readable(ainfo->size);
1742 text[COL_NAME] = ainfo->name;
1744 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1745 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1747 if (cnttype != MIME_MESSAGE_RFC822)
1748 compose_changed_cb(NULL, compose);
1751 static void compose_attach_append_with_type(Compose *compose,
1754 ContentType cnttype)
1759 if (!is_file_exist(file)) {
1760 g_warning(_("File %s doesn't exist\n"), file);
1763 if ((size = get_file_size(file)) < 0) {
1764 g_warning(_("Can't get file size of %s\n"), file);
1768 alertpanel_notice(_("File %s is empty\n"), file);
1771 #if 0 /* NEW COMPOSE GUI */
1772 if (!compose->use_attach) {
1773 GtkItemFactory *ifactory;
1774 GtkWidget *menuitem;
1776 ifactory = gtk_item_factory_from_widget(compose->menubar);
1777 menuitem = gtk_item_factory_get_item(ifactory,
1779 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1783 ainfo = g_new0(AttachInfo, 1);
1784 ainfo->file = g_strdup(file);
1786 if (cnttype == MIME_MESSAGE_RFC822) {
1787 ainfo->encoding = ENC_7BIT;
1788 ainfo->name = g_strdup_printf(_("Message: %s"),
1791 ainfo->encoding = ENC_BASE64;
1792 ainfo->name = g_strdup(g_basename(file));
1795 ainfo->content_type = g_strdup(type);
1798 compose_attach_info(compose, ainfo, cnttype);
1801 static void compose_attach_append(Compose *compose, const gchar *file,
1802 ContentType cnttype)
1805 gchar *text[N_ATTACH_COLS];
1809 if (!is_file_exist(file)) {
1810 g_warning(_("File %s doesn't exist\n"), file);
1813 if ((size = get_file_size(file)) < 0) {
1814 g_warning(_("Can't get file size of %s\n"), file);
1818 alertpanel_notice(_("File %s is empty\n"), file);
1821 #if 0 /* NEW COMPOSE GUI */
1822 if (!compose->use_attach) {
1823 GtkItemFactory *ifactory;
1824 GtkWidget *menuitem;
1826 ifactory = gtk_item_factory_from_widget(compose->menubar);
1827 menuitem = gtk_item_factory_get_item(ifactory,
1829 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1833 ainfo = g_new0(AttachInfo, 1);
1834 ainfo->file = g_strdup(file);
1836 if (cnttype == MIME_MESSAGE_RFC822) {
1837 ainfo->content_type = g_strdup("message/rfc822");
1838 ainfo->encoding = ENC_7BIT;
1839 ainfo->name = g_strdup_printf(_("Message: %s"),
1842 ainfo->content_type = procmime_get_mime_type(file);
1843 if (!ainfo->content_type)
1844 ainfo->content_type =
1845 g_strdup("application/octet-stream");
1846 ainfo->encoding = ENC_BASE64;
1847 ainfo->name = g_strdup(g_basename(file));
1851 compose_attach_info(compose, ainfo, cnttype);
1854 static void compose_wrap_line(Compose *compose)
1856 GtkSText *text = GTK_STEXT(compose->text);
1857 gint ch_len, last_ch_len;
1858 gchar cbuf[MB_LEN_MAX], last_ch;
1862 gint p_start, p_end;
1863 gint line_pos, cur_pos;
1864 gint line_len, cur_len;
1866 #define GET_STEXT(pos) \
1867 if (text->use_wchar) \
1868 ch_len = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
1870 cbuf[0] = GTK_STEXT_INDEX(text, (pos)); \
1874 gtk_stext_freeze(text);
1876 text_len = gtk_stext_get_length(text);
1878 /* check to see if the point is on the paragraph mark (empty line). */
1879 cur_pos = gtk_stext_get_point(text);
1881 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
1883 goto compose_end; /* on the paragraph mark */
1884 GET_STEXT(cur_pos - 1);
1885 if (ch_len == 1 && *cbuf == '\n')
1886 goto compose_end; /* on the paragraph mark */
1889 /* find paragraph start. */
1890 line_end = quoted = 0;
1891 for (p_start = cur_pos; p_start >= 0; --p_start) {
1893 if (ch_len == 1 && *cbuf == '\n') {
1895 goto compose_end; /* quoted part */
1902 if (ch_len == 1 && strchr(">:#", *cbuf))
1904 else if (ch_len != 1 || !isspace(*cbuf))
1913 /* find paragraph end. */
1915 for (p_end = cur_pos; p_end < text_len; p_end++) {
1917 if (ch_len == 1 && *cbuf == '\n') {
1924 if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
1925 goto compose_end; /* quoted part */
1930 if (p_end >= text_len)
1933 if (p_start >= p_end)
1936 line_len = cur_len = 0;
1940 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
1950 if (ch_len == 1 && isspace(*cbuf))
1953 if (ch_len == 1 && *cbuf == '\n') {
1955 if (last_ch_len == 1 && !isspace(last_ch)) {
1956 if (cur_pos + 1 < p_end) {
1957 GET_STEXT(cur_pos + 1);
1958 if (ch_len == 1 && !isspace(*cbuf))
1962 gtk_stext_set_point(text, cur_pos + 1);
1963 gtk_stext_backward_delete(text, 1);
1965 gtk_stext_set_point(text, cur_pos);
1966 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
1976 last_ch_len = ch_len;
1980 line_pos = cur_pos + 1;
1981 line_len = cur_len + ch_len;
1984 if (cur_len + ch_len > prefs_common.linewrap_len &&
1988 GET_STEXT(line_pos - 1);
1989 if (ch_len == 1 && isspace(*cbuf)) {
1990 gtk_stext_set_point(text, line_pos);
1991 gtk_stext_backward_delete(text, 1);
2000 gtk_stext_set_point(text, line_pos);
2001 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2005 cur_len = cur_len - line_len + ch_len;
2011 line_pos = cur_pos + 1;
2012 line_len = cur_len + ch_len;
2018 gtk_stext_thaw(text);
2023 /* return indent length */
2024 static guint get_indent_length(GtkSText *text, guint start_pos,
2026 gint indent_len = 0;
2028 gchar cbuf[MB_CUR_MAX];
2030 for (i = start_pos; i < text_len; i++) {
2031 if (text->use_wchar)
2033 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, i));
2035 cbuf[0] = GTK_STEXT_INDEX(text, i);
2040 /* allow space, tab, > or | */
2041 if (cbuf[0] != ' ' && cbuf[0] != '\t' &&
2042 cbuf[0] != '>' && cbuf[0] != '|')
2050 /* insert quotation string when line was wrapped, we know these
2051 are single byte characters */
2052 static guint ins_quote(GtkSText *text, guint quote_len, guint indent_len,
2053 guint prev_line_pos, guint text_len,
2059 for (i = 0; i < indent_len; i++) {
2060 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2061 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2063 ins_len = indent_len;
2066 gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
2067 ins_len = quote_len;
2075 /* Darko: used when I debug wrapping */
2076 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2081 printf("%d [", pos);
2082 for (i = pos; i < tlen; i++)
2084 ch = GTK_STEXT_INDEX(text, i);
2085 if (breakoncr && ch == '\n')
2093 static void compose_wrap_line_all(Compose *compose)
2095 GtkSText *text = GTK_STEXT(compose->text);
2097 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2098 gint line_len = 0, cur_len = 0;
2100 gint is_new_line = 1, do_delete = 0;
2101 guint qlen = 0, i_len = 0;
2102 guint linewrap_quote = prefs_common.linewrap_quote;
2103 guint linewrap_len = prefs_common.linewrap_len;
2104 gchar *qfmt = prefs_common.quotemark;
2105 gchar cbuf[MB_LEN_MAX];
2107 gtk_stext_freeze(text);
2109 /* make text buffer contiguous */
2110 gtk_stext_compact_buffer(text);
2112 tlen = gtk_stext_get_length(text);
2114 for (; cur_pos < tlen; cur_pos++) {
2115 /* mark position of new line - needed for quotation wrap */
2116 if (linewrap_quote && is_new_line) {
2117 qlen = gtkstext_str_strcmp(text, cur_pos, tlen, qfmt);
2120 i_len = get_indent_length(text, cur_pos, tlen);
2126 printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
2127 dump_text(text, p_pos, tlen, 1);
2131 /* get character(s) at current position */
2132 if (text->use_wchar)
2134 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2136 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
2140 /* fix line length for tabs */
2141 if (ch_len == 1 && *cbuf == '\t') {
2142 guint tab_width = text->default_tab_width;
2143 guint tab_offset = line_len % tab_width;
2146 printf("found tab at pos=%d line_len=%d ", cur_pos,
2150 line_len += tab_width - tab_offset - 1;
2154 printf("new_len=%d\n", line_len);
2158 /* we have encountered line break */
2159 if (ch_len == 1 && *cbuf == '\n') {
2162 gchar cb[MB_CUR_MAX];
2165 printf("found CR at %d\n", cur_pos);
2167 /* if it's just quotation + newline skip it */
2168 if (i_len && (cur_pos + 1 < tlen)) {
2169 /* check if text at new line matches indent */
2170 ilen = gtkstext_strncmp(text, cur_pos + 1,
2171 p_pos, i_len, tlen);
2172 if (cur_pos + ilen < tlen) {
2173 if (text->use_wchar)
2174 clen = wctomb(cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos + ilen + 1));
2176 cb[0] = GTK_STEXT_INDEX(text,
2177 cur_pos + ilen + 1);
2180 /* no need to join the lines */
2181 if ((clen == 1) && (cb[0] == '\n'))
2187 printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
2188 qlen, line_len, linewrap_len, do_delete);
2190 /* should we delete to perform smart wrapping */
2191 if (qlen && line_len < linewrap_len && do_delete) {
2192 /* get rid of newline */
2193 gtk_stext_set_point(text, cur_pos);
2194 gtk_stext_forward_delete(text, 1);
2197 /* if text starts with quote fmt or with
2198 indent string, delete them */
2200 ilen = gtkstext_strncmp(text, cur_pos,
2204 gtk_stext_forward_delete(text,
2210 if (gtkstext_str_strcmp(text, cur_pos,
2212 gtk_stext_forward_delete(text,
2218 if (text->use_wchar)
2220 (cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2222 cb[0] = GTK_STEXT_INDEX(text, cur_pos);
2226 /* insert space if it's alphanumeric */
2227 if ((cur_pos != line_pos) &&
2228 ((clen > 1) || isalnum(cb[0]))) {
2229 gtk_stext_insert(text, NULL, NULL,
2231 gtk_stext_compact_buffer(text);
2235 /* and start over with current line */
2236 cur_pos = p_pos - 1;
2238 line_len = cur_len = 0;
2243 printf("after delete l_pos=");
2244 dump_text(text, line_pos, tlen, 1);
2249 /* mark new line beginning */
2250 line_pos = cur_pos + 1;
2251 line_len = cur_len = 0;
2263 /* possible line break */
2264 if (ch_len == 1 && isspace(*cbuf)) {
2265 line_pos = cur_pos + 1;
2266 line_len = cur_len + ch_len;
2269 /* are we over wrapping length set in preferences ? */
2270 if (cur_len + ch_len > linewrap_len) {
2274 printf("should wrap cur_pos=%d ", cur_pos);
2275 dump_text(text, p_pos, tlen, 1);
2276 dump_text(text, line_pos, tlen, 1);
2278 /* force wrapping if it is one long word but not URL */
2279 if (p_pos + i_len == line_pos)
2280 if (!is_url_string(text, line_pos, tlen))
2281 line_pos = cur_pos - 1;
2283 printf("new line_pos=%d\n", line_pos);
2286 /* if next character is space delete it */
2287 if (text->use_wchar)
2288 clen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
2290 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
2293 if (clen == 1 && isspace(*cbuf)) {
2294 if (p_pos + i_len != line_pos ||
2295 !is_url_string(text, line_pos, tlen)) {
2296 gtk_stext_set_point(text, line_pos);
2297 gtk_stext_backward_delete(text, 1);
2306 /* if it is URL at beginning of line don't wrap */
2307 if (p_pos + i_len == line_pos &&
2308 is_url_string(text, line_pos, tlen)) {
2310 printf("found URL at ");
2311 dump_text(text, line_pos, tlen, 1);
2317 gtk_stext_set_point(text, line_pos);
2318 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2319 gtk_stext_compact_buffer(text);
2323 cur_len = cur_len - line_len + ch_len;
2326 printf("after CR insert ");
2327 dump_text(text, line_pos, tlen, 1);
2330 /* should we insert quotation ? */
2331 if (linewrap_quote && qlen) {
2332 /* only if line is not already quoted */
2333 if (!gtkstext_str_strcmp(text, line_pos,
2337 if (line_pos - p_pos > i_len) {
2338 ins_len = ins_quote(text,
2345 gtk_stext_compact_buffer(text);
2349 /* for loop will increase it */
2350 cur_pos = line_pos - 1;
2353 /* start over with current line */
2357 printf("after quote insert ");
2358 dump_text(text, line_pos, tlen, 1);
2366 line_pos = cur_pos + 1;
2367 line_len = cur_len + ch_len;
2369 /* advance to next character in buffer */
2373 gtk_stext_thaw(text);
2376 static void compose_set_title(Compose *compose)
2381 edited = compose->modified ? _(" [Edited]") : "";
2382 if (compose->account && compose->account->address)
2383 str = g_strdup_printf(_("%s - Compose message%s"),
2384 compose->account->address, edited);
2386 str = g_strdup_printf(_("Compose message%s"), edited);
2387 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2392 * compose_current_mail_account:
2394 * Find a current mail account (the currently selected account, or the
2395 * default account, if a news account is currently selected). If a
2396 * mail account cannot be found, display an error message.
2398 * Return value: Mail account, or NULL if not found.
2400 static PrefsAccount *
2401 compose_current_mail_account(void)
2405 if (cur_account && cur_account->protocol != A_NNTP)
2408 ac = account_get_default();
2409 if (!ac || ac->protocol == A_NNTP) {
2410 alertpanel_error(_("Account for sending mail is not specified.\n"
2411 "Please select a mail account before sending."));
2418 gboolean compose_check_for_valid_recipient(Compose *compose) {
2419 gchar *recipient_headers[] = {"To:", "Newsgroups:", "Cc:", "Bcc:", NULL};
2420 gboolean recipient_found = FALSE;
2424 for(list = compose->header_list; list; list = list->next) {
2427 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((compose_headerentry *)list->data)->combo)->entry));
2428 entry = gtk_editable_get_chars(GTK_EDITABLE(((compose_headerentry *)list->data)->entry), 0, -1);
2430 if(entry[0] != '\0') {
2431 for(strptr = recipient_headers; *strptr != NULL; strptr++) {
2432 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2433 recipient_found = TRUE;
2439 return recipient_found;
2442 gint compose_send(Compose *compose)
2444 gchar tmp[MAXPATHLEN + 1];
2446 static gboolean lock = FALSE;
2450 g_return_val_if_fail(compose->account != NULL, -1);
2451 g_return_val_if_fail(compose->orig_account != NULL, -1);
2455 if(!compose_check_for_valid_recipient(compose)) {
2456 alertpanel_error(_("Recipient is not specified."));
2461 /* write to temporary file */
2462 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2463 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2465 if (prefs_common.linewrap_at_send)
2466 compose_wrap_line_all(compose);
2468 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2473 if (!compose->to_list && !compose->newsgroup_list) {
2474 g_warning(_("can't get recipient list."));
2480 if (compose->to_list) {
2483 #if 0 /* NEW COMPOSE GUI */
2484 if (compose->account->protocol != A_NNTP)
2485 ac = compose->account;
2486 else if (compose->orig_account->protocol != A_NNTP)
2487 ac = compose->orig_account;
2488 else if (cur_account && cur_account->protocol != A_NNTP)
2491 ac = compose_current_mail_account();
2499 ac = compose->account;
2501 ok = send_message(tmp, ac, compose->to_list);
2502 statusbar_pop_all();
2505 if (ok == 0 && compose->newsgroup_list) {
2508 if (compose->account->protocol == A_NNTP)
2509 folder = FOLDER(compose->account->folder);
2511 folder = FOLDER(compose->orig_account->folder);
2513 ok = news_post(folder, tmp);
2515 alertpanel_error(_("Error occurred while posting the message to %s ."),
2516 compose->account->nntp_server);
2523 /* queue message if failed to send */
2525 if (prefs_common.queue_msg) {
2530 _("Error occurred while sending the message.\n"
2531 "Put this message into queue folder?"),
2532 _("OK"), _("Cancel"), NULL);
2533 if (G_ALERTDEFAULT == val) {
2534 ok = compose_queue(compose, tmp);
2536 alertpanel_error(_("Can't queue the message."));
2539 alertpanel_error(_("Error occurred while sending the message."));
2541 if (compose->mode == COMPOSE_REEDIT) {
2542 compose_remove_reedit_target(compose);
2543 if (compose->targetinfo)
2544 folderview_update_item
2545 (compose->targetinfo->folder, TRUE);
2549 /* save message to outbox */
2550 if (ok == 0 && prefs_common.savemsg) {
2551 if (compose_save_to_outbox(compose, tmp) < 0)
2553 (_("Can't save the message to outbox."));
2561 static gboolean compose_use_attach(Compose *compose) {
2562 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2565 static gint compose_write_to_file(Compose *compose, const gchar *file,
2572 const gchar *out_codeset;
2573 EncodingType encoding;
2575 if ((fp = fopen(file, "w")) == NULL) {
2576 FILE_OP_ERROR(file, "fopen");
2580 /* chmod for security */
2581 if (change_file_mode_rw(fp, file) < 0) {
2582 FILE_OP_ERROR(file, "chmod");
2583 g_warning(_("can't change file mode\n"));
2586 /* get all composed text */
2587 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2588 len = strlen(chars);
2589 if (is_ascii_str(chars)) {
2590 buf = g_strdup(chars);
2591 out_codeset = CS_US_ASCII;
2592 encoding = ENC_7BIT;
2594 const gchar *src_codeset;
2596 out_codeset = conv_get_outgoing_charset_str();
2597 if (!strcasecmp(out_codeset, CS_US_ASCII))
2598 out_codeset = CS_ISO_8859_1;
2599 encoding = procmime_get_encoding_for_charset(out_codeset);
2601 src_codeset = conv_get_current_charset_str();
2602 /* if current encoding is US-ASCII, set it the same as
2603 outgoing one to prevent code conversion failure */
2604 if (!strcasecmp(src_codeset, CS_US_ASCII))
2605 src_codeset = out_codeset;
2607 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
2608 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
2610 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
2615 alertpanel_error(_("Can't convert the codeset of the message."));
2622 if (compose_write_headers
2623 (compose, fp, out_codeset, encoding, is_draft) < 0) {
2624 g_warning(_("can't write headers\n"));
2631 if (compose_use_attach(compose)) {
2633 /* This prolog message is ignored by mime software and
2634 * because it would make our signing/encryption task
2635 * tougher, we don't emit it in that case */
2636 if (!compose->use_signing && !compose->use_encryption)
2638 fputs("This is a multi-part message in MIME format.\n", fp);
2640 fprintf(fp, "\n--%s\n", compose->boundary);
2641 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
2643 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2644 procmime_get_encoding_str(encoding));
2650 if (encoding == ENC_BASE64) {
2651 gchar outbuf[B64_BUFFSIZE];
2654 for (i = 0; i < len; i += B64_LINE_SIZE) {
2655 l = MIN(B64_LINE_SIZE, len - i);
2656 to64frombits(outbuf, buf + i, l);
2660 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
2661 FILE_OP_ERROR(file, "fwrite");
2669 if (compose_use_attach(compose))
2670 compose_write_attach(compose, fp);
2672 if (fclose(fp) == EOF) {
2673 FILE_OP_ERROR(file, "fclose");
2679 if (compose->use_signing) {
2680 if (rfc2015_sign(file, compose->account) < 0) {
2685 if (compose->use_encryption) {
2686 if (rfc2015_encrypt(file, compose->to_list) < 0) {
2691 #endif /* USE_GPGME */
2696 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
2702 if ((fp = fopen(file, "w")) == NULL) {
2703 FILE_OP_ERROR(file, "fopen");
2707 /* chmod for security */
2708 if (change_file_mode_rw(fp, file) < 0) {
2709 FILE_OP_ERROR(file, "chmod");
2710 g_warning(_("can't change file mode\n"));
2713 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2716 len = strlen(chars);
2717 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
2718 FILE_OP_ERROR(file, "fwrite");
2727 if (fclose(fp) == EOF) {
2728 FILE_OP_ERROR(file, "fclose");
2735 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
2742 debug_print(_("saving sent message...\n"));
2744 outbox = folder_get_default_outbox();
2745 path = folder_item_get_path(outbox);
2746 if (!is_dir_exist(path))
2747 make_dir_hier(path);
2749 folder_item_scan(outbox);
2750 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
2752 g_warning(_("can't save message\n"));
2756 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
2757 g_warning(_("can't open mark file\n"));
2761 newmsginfo.msgnum = num;
2762 newmsginfo.flags.perm_flags = 0;
2763 newmsginfo.flags.tmp_flags = 0;
2764 procmsg_write_flags(&newmsginfo, fp);
2772 static gint compose_remove_reedit_target(Compose *compose)
2775 MsgInfo *msginfo = compose->targetinfo;
2777 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
2778 if (!msginfo) return -1;
2780 item = msginfo->folder;
2781 g_return_val_if_fail(item != NULL, -1);
2783 folder_item_scan(item);
2784 if (procmsg_msg_exist(msginfo) &&
2785 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
2786 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
2787 g_warning(_("can't remove the old message\n"));
2795 static gint compose_queue(Compose *compose, const gchar *file)
2798 gchar *tmp, *queue_path;
2801 gchar buf[BUFFSIZE];
2804 debug_print(_("queueing message...\n"));
2805 g_return_val_if_fail(compose->to_list != NULL, -1);
2806 g_return_val_if_fail(compose->account != NULL, -1);
2808 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
2809 G_DIR_SEPARATOR, (gint)compose);
2810 if ((fp = fopen(tmp, "w")) == NULL) {
2811 FILE_OP_ERROR(tmp, "fopen");
2815 if ((src_fp = fopen(file, "r")) == NULL) {
2816 FILE_OP_ERROR(file, "fopen");
2822 if (change_file_mode_rw(fp, tmp) < 0) {
2823 FILE_OP_ERROR(tmp, "chmod");
2824 g_warning(_("can't change file mode\n"));
2827 /* queueing variables */
2828 fprintf(fp, "AF:\n");
2829 fprintf(fp, "NF:0\n");
2830 fprintf(fp, "PS:10\n");
2831 fprintf(fp, "SRH:1\n");
2832 fprintf(fp, "SFN:\n");
2833 fprintf(fp, "DSR:\n");
2835 fprintf(fp, "MID:<%s>\n", compose->msgid);
2837 fprintf(fp, "MID:\n");
2838 fprintf(fp, "CFG:\n");
2839 fprintf(fp, "PT:0\n");
2840 fprintf(fp, "S:%s\n", compose->account->address);
2841 fprintf(fp, "RQ:\n");
2842 if (compose->account->smtp_server)
2843 fprintf(fp, "SSV:%s\n", compose->account->smtp_server);
2845 fprintf(fp, "SSV:\n");
2846 if (compose->account->nntp_server)
2847 fprintf(fp, "NSV:%s\n", compose->account->nntp_server);
2849 fprintf(fp, "NSV:\n");
2850 fprintf(fp, "SSH:\n");
2851 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
2852 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
2853 fprintf(fp, ",<%s>", (gchar *)cur->data);
2855 /* Sylpheed account ID */
2856 fprintf(fp, "AID:%d\n", compose->account->account_id);
2859 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
2860 if (fputs(buf, fp) == EOF) {
2861 FILE_OP_ERROR(tmp, "fputs");
2871 if (fclose(fp) == EOF) {
2872 FILE_OP_ERROR(tmp, "fclose");
2878 queue = folder_get_default_queue();
2880 folder_item_scan(queue);
2881 queue_path = folder_item_get_path(queue);
2882 if (!is_dir_exist(queue_path))
2883 make_dir_hier(queue_path);
2884 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
2885 g_warning(_("can't queue the message\n"));
2893 if (compose->mode == COMPOSE_REEDIT) {
2894 compose_remove_reedit_target(compose);
2895 if (compose->targetinfo &&
2896 compose->targetinfo->folder != queue)
2897 folderview_update_item
2898 (compose->targetinfo->folder, TRUE);
2901 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
2902 g_warning(_("can't open mark file\n"));
2906 newmsginfo.msgnum = num;
2907 newmsginfo.flags.perm_flags = 0;
2908 newmsginfo.flags.tmp_flags = 0;
2909 procmsg_write_flags(&newmsginfo, fp);
2914 folder_item_scan(queue);
2915 folderview_update_item(queue, TRUE);
2920 static void compose_write_attach(Compose *compose, FILE *fp)
2923 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2926 gchar filename[BUFFSIZE];
2929 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
2931 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
2932 g_warning(_("Can't open file %s\n"), ainfo->file);
2936 fprintf(fp, "\n--%s\n", compose->boundary);
2938 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
2939 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
2940 fprintf(fp, "Content-Disposition: inline\n");
2942 conv_encode_header(filename, sizeof(filename),
2944 fprintf(fp, "Content-Type: %s;\n"
2946 ainfo->content_type, filename);
2947 fprintf(fp, "Content-Disposition: attachment;\n"
2948 " filename=\"%s\"\n", filename);
2951 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
2952 procmime_get_encoding_str(ainfo->encoding));
2954 if (ainfo->encoding == ENC_7BIT) {
2955 gchar buf[BUFFSIZE];
2957 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
2962 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
2964 while ((len = fread(inbuf, sizeof(gchar),
2965 B64_LINE_SIZE, attach_fp))
2967 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
2971 if (len > 0 && feof(attach_fp)) {
2972 to64frombits(outbuf, inbuf, len);
2981 fprintf(fp, "\n--%s--\n", compose->boundary);
2984 #define IS_IN_CUSTOM_HEADER(header) \
2985 (compose->account->add_customhdr && \
2986 custom_header_find(compose->account->customhdr_list, header) != NULL)
2988 static gint compose_write_headers_from_headerlist(Compose *compose,
2991 GSList *(*list_append_func) (GSList *list, const gchar *str),
2994 gchar buf[BUFFSIZE];
2995 gchar *str, *header_w_colon, *trans_hdr;
2996 gboolean first_address;
2998 compose_headerentry *headerentry;
3000 if (IS_IN_CUSTOM_HEADER(header)) {
3004 debug_print(_("Writing %s-header\n"), header);
3006 header_w_colon = g_strconcat(header, ":", NULL);
3007 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3009 first_address = TRUE;
3010 for(list = compose->header_list; list; list = list->next) {
3011 headerentry = ((compose_headerentry *)list->data);
3012 if(!strcmp(trans_hdr, gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)))) {
3013 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3014 Xstrdup_a(str, str, return -1);
3016 if(str[0] != '\0') {
3017 if(list_append_func)
3018 *dest_list = list_append_func(*dest_list, str);
3019 compose_convert_header
3020 (buf, sizeof(buf), str,
3021 strlen(header) + 2);
3023 fprintf(fp, "%s: ", header);
3024 first_address = FALSE;
3028 fprintf(fp, "%s", buf);
3032 if(!first_address) {
3036 g_free(header_w_colon);
3041 static gint compose_write_headers(Compose *compose, FILE *fp,
3042 const gchar *charset, EncodingType encoding,
3045 gchar buf[BUFFSIZE];
3047 /* struct utsname utsbuf; */
3049 g_return_val_if_fail(fp != NULL, -1);
3050 g_return_val_if_fail(charset != NULL, -1);
3051 g_return_val_if_fail(compose->account != NULL, -1);
3052 g_return_val_if_fail(compose->account->address != NULL, -1);
3055 if (compose->account->add_date) {
3056 get_rfc822_date(buf, sizeof(buf));
3057 fprintf(fp, "Date: %s\n", buf);
3061 if (!IS_IN_CUSTOM_HEADER("From")) {
3062 if (compose->account->name && *compose->account->name) {
3063 compose_convert_header
3064 (buf, sizeof(buf), compose->account->name,
3066 fprintf(fp, "From: %s <%s>\n",
3067 buf, compose->account->address);
3069 fprintf(fp, "From: %s\n", compose->account->address);
3072 slist_free_strings(compose->to_list);
3073 g_slist_free(compose->to_list);
3074 compose->to_list = NULL;
3077 compose_write_headers_from_headerlist(compose, fp, "To", address_list_append, &compose->to_list);
3078 #if 0 /* NEW COMPOSE GUI */
3079 if (compose->use_to) {
3080 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3082 Xstrdup_a(str, str, return -1);
3085 compose->to_list = address_list_append
3086 (compose->to_list, str);
3087 if (!IS_IN_CUSTOM_HEADER("To")) {
3088 compose_convert_header
3089 (buf, sizeof(buf), str,
3091 fprintf(fp, "To: %s\n", buf);
3097 slist_free_strings(compose->newsgroup_list);
3098 g_slist_free(compose->newsgroup_list);
3099 compose->newsgroup_list = NULL;
3102 compose_write_headers_from_headerlist(compose, fp, "Newsgroups", newsgroup_list_append, &compose->newsgroup_list);
3103 #if 0 /* NEW COMPOSE GUI */
3104 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3106 Xstrdup_a(str, str, return -1);
3110 compose->newsgroup_list =
3111 newsgroup_list_append(compose->newsgroup_list,
3113 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3114 compose_convert_header(buf, sizeof(buf), str,
3115 strlen("Newsgroups: "));
3116 fprintf(fp, "Newsgroups: %s\n", buf);
3122 compose_write_headers_from_headerlist(compose, fp, "Cc", address_list_append, &compose->to_list);
3123 #if 0 /* NEW COMPOSE GUI */
3124 if (compose->use_cc) {
3125 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3127 Xstrdup_a(str, str, return -1);
3130 compose->to_list = address_list_append
3131 (compose->to_list, str);
3132 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3133 compose_convert_header
3134 (buf, sizeof(buf), str,
3136 fprintf(fp, "Cc: %s\n", buf);
3143 compose_write_headers_from_headerlist(compose, fp, "Bcc", address_list_append, &compose->to_list);
3144 #if 0 /* NEW COMPOSE GUI */
3145 if (compose->use_bcc) {
3146 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3148 Xstrdup_a(str, str, return -1);
3151 compose->to_list = address_list_append
3152 (compose->to_list, str);
3153 compose_convert_header(buf, sizeof(buf), str,
3155 fprintf(fp, "Bcc: %s\n", buf);
3160 if (!is_draft && !compose->to_list && !compose->newsgroup_list)
3164 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3165 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3166 Xstrdup_a(str, str, return -1);
3169 compose_convert_header(buf, sizeof(buf), str,
3170 strlen("Subject: "));
3171 fprintf(fp, "Subject: %s\n", buf);
3176 if (compose->account->gen_msgid) {
3177 compose_generate_msgid(compose, buf, sizeof(buf));
3178 fprintf(fp, "Message-Id: <%s>\n", buf);
3179 compose->msgid = g_strdup(buf);
3183 if (compose->inreplyto && compose->to_list)
3184 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3187 if (compose->references)
3188 fprintf(fp, "References: %s\n", compose->references);
3191 compose_write_headers_from_headerlist(compose, fp, "Followup-To", NULL, NULL);
3192 #if 0 /* NEW COMPOSE GUI */
3193 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3194 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3196 Xstrdup_a(str, str, return -1);
3200 compose_convert_header(buf, sizeof(buf), str,
3201 strlen("Followup-To: "));
3202 fprintf(fp, "Followup-To: %s\n", buf);
3208 compose_write_headers_from_headerlist(compose, fp, "Reply-To", NULL, NULL);
3209 #if 0 /* NEW COMPOSE GUI */
3210 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3211 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3213 Xstrdup_a(str, str, return -1);
3216 compose_convert_header(buf, sizeof(buf), str,
3217 strlen("Reply-To: "));
3218 fprintf(fp, "Reply-To: %s\n", buf);
3224 if (compose->account->organization &&
3225 !IS_IN_CUSTOM_HEADER("Organization")) {
3226 compose_convert_header(buf, sizeof(buf),
3227 compose->account->organization,
3228 strlen("Organization: "));
3229 fprintf(fp, "Organization: %s\n", buf);
3232 /* Program version and system info */
3233 /* uname(&utsbuf); */
3234 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3235 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3237 gtk_major_version, gtk_minor_version, gtk_micro_version,
3239 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3241 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3242 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3244 gtk_major_version, gtk_minor_version, gtk_micro_version,
3246 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3249 /* custom headers */
3250 if (compose->account->add_customhdr) {
3253 for (cur = compose->account->customhdr_list; cur != NULL;
3255 CustomHeader *chdr = (CustomHeader *)cur->data;
3257 if (strcasecmp(chdr->name, "Date") != 0 &&
3258 strcasecmp(chdr->name, "From") != 0 &&
3259 strcasecmp(chdr->name, "To") != 0 &&
3260 strcasecmp(chdr->name, "Sender") != 0 &&
3261 strcasecmp(chdr->name, "Message-Id") != 0 &&
3262 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3263 strcasecmp(chdr->name, "References") != 0 &&
3264 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3265 strcasecmp(chdr->name, "Content-Type") != 0 &&
3266 strcasecmp(chdr->name, "Content-Transfer-Encoding") != 0)
3267 compose_convert_header
3269 chdr->value ? chdr->value : "",
3270 strlen(chdr->name) + 2);
3271 fprintf(fp, "%s: %s\n", chdr->name, buf);
3276 fprintf(fp, "Mime-Version: 1.0\n");
3277 if (compose_use_attach(compose)) {
3278 get_rfc822_date(buf, sizeof(buf));
3279 subst_char(buf, ' ', '_');
3280 subst_char(buf, ',', '_');
3281 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3282 buf, (guint)compose);
3284 "Content-Type: multipart/mixed;\n"
3285 " boundary=\"%s\"\n", compose->boundary);
3287 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3288 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3289 procmime_get_encoding_str(encoding));
3292 /* Request Return Receipt */
3293 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3294 if (compose->return_receipt) {
3295 if (compose->account->name
3296 && *compose->account->name) {
3297 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3298 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3300 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3304 /* separator between header and body */
3310 #undef IS_IN_CUSTOM_HEADER
3312 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3315 g_return_if_fail(src != NULL);
3316 g_return_if_fail(dest != NULL);
3318 if (len < 1) return;
3322 if (is_ascii_str(src)) {
3323 strncpy2(dest, src, len);
3324 dest[len - 1] = '\0';
3327 conv_encode_header(dest, len, src, header_len);
3330 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3339 if (compose->account && compose->account->address &&
3340 *compose->account->address) {
3341 if (strchr(compose->account->address, '@'))
3342 addr = g_strdup(compose->account->address);
3344 addr = g_strconcat(compose->account->address, "@",
3345 get_domain_name(), NULL);
3347 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3350 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3351 lt->tm_year + 1900, lt->tm_mon + 1,
3352 lt->tm_mday, lt->tm_hour,
3353 lt->tm_min, lt->tm_sec,
3354 (guint)random(), addr);
3356 debug_print(_("generated Message-ID: %s\n"), buf);
3362 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3363 GtkWidget **entry, gint *count,
3364 const gchar *label_str,
3365 gboolean is_addr_entry)
3369 if (GTK_TABLE(table)->nrows < (*count) + 1)
3370 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3372 *hbox = gtk_hbox_new(FALSE, 0);
3373 label = gtk_label_new
3374 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3375 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3376 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3378 *entry = gtk_entry_new();
3380 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3381 #if 0 /* NEW COMPOSE GUI */
3382 if (GTK_TABLE(table)->nrows > (*count) + 1)
3383 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3387 address_completion_register_entry(GTK_ENTRY(*entry));
3392 static void compose_create_header_entry(Compose *compose) {
3393 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3397 GList *combo_list = NULL;
3398 gchar **string, *header;
3399 compose_headerentry *headerentry = g_new0(compose_headerentry, 1);
3402 combo = gtk_combo_new();
3404 while(*string != NULL) {
3405 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3408 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3409 g_list_free(combo_list);
3410 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3411 gtk_widget_show(combo);
3412 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3413 if(compose->header_last) {
3414 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3416 switch(compose->account->protocol) {
3418 header = _("Newsgroups:");
3425 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
3428 entry = gtk_entry_new();
3429 gtk_widget_show(entry);
3430 gtk_table_attach(GTK_TABLE(compose->header_table), entry, 1, 2, compose->header_nextrow, compose->header_nextrow+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
3432 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
3433 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
3435 address_completion_register_entry(GTK_ENTRY(entry));
3437 headerentry->compose = compose;
3438 headerentry->combo = combo;
3439 headerentry->entry = entry;
3440 headerentry->headernum = compose->header_nextrow;
3442 compose->header_nextrow++;
3443 compose->header_last = headerentry;
3446 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text) {
3447 compose_headerentry *last_header;
3449 last_header = compose->header_last;
3451 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
3452 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
3455 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
3461 GtkWidget *handlebox;
3463 GtkWidget *notebook;
3467 GtkWidget *table_vbox;
3469 GtkWidget *from_optmenu_hbox;
3470 #if 0 /* NEW COMPOSE GUI */
3471 GtkWidget *to_entry;
3473 GtkWidget *newsgroups_entry;
3474 GtkWidget *newsgroups_hbox;
3476 GtkWidget *header_scrolledwin;
3477 GtkWidget *header_table;
3478 GtkWidget *subject_entry;
3479 #if 0 /* NEW COMPOSE GUI */
3480 GtkWidget *cc_entry;
3482 GtkWidget *bcc_entry;
3483 GtkWidget *bcc_hbox;
3484 GtkWidget *reply_entry;
3485 GtkWidget *reply_hbox;
3486 GtkWidget *followup_entry;
3487 GtkWidget *followup_hbox;
3491 GtkWidget *attach_scrwin;
3492 GtkWidget *attach_clist;
3494 GtkWidget *edit_vbox;
3495 GtkWidget *ruler_hbox;
3497 GtkWidget *scrolledwin;
3503 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
3504 guint n_menu_entries;
3505 GtkStyle *style, *new_style;
3508 gboolean success[1];
3510 GtkWidget *popupmenu;
3511 GtkWidget *menuitem;
3512 GtkItemFactory *popupfactory;
3513 GtkItemFactory *ifactory;
3514 GtkWidget *tmpl_menu;
3520 GtkPspell * gtkpspell = NULL;
3523 g_return_val_if_fail(account != NULL, NULL);
3525 debug_print(_("Creating compose window...\n"));
3526 compose = g_new0(Compose, 1);
3528 compose->account = account;
3529 compose->orig_account = account;
3531 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
3532 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
3533 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
3534 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3535 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
3536 gtk_signal_connect(GTK_OBJECT(window), "destroy",
3537 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
3538 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
3539 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
3540 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
3541 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
3542 gtk_widget_realize(window);
3544 gtkut_widget_set_composer_icon(window);
3546 vbox = gtk_vbox_new(FALSE, 0);
3547 gtk_container_add(GTK_CONTAINER(window), vbox);
3549 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
3550 menubar = menubar_create(window, compose_entries,
3551 n_menu_entries, "<Compose>", compose);
3552 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
3554 handlebox = gtk_handle_box_new();
3555 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
3557 compose_toolbar_create(compose, handlebox);
3559 vbox2 = gtk_vbox_new(FALSE, 2);
3560 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
3561 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
3563 table_vbox = gtk_vbox_new(FALSE, 0);
3564 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
3565 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
3569 notebook = gtk_notebook_new();
3570 gtk_widget_set_usize(notebook, -1, 180);
3571 gtk_widget_show(notebook);
3573 /* header labels and entries */
3574 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3575 gtk_widget_show(header_scrolledwin);
3576 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
3577 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), header_scrolledwin, gtk_label_new(_("Header")));
3579 header_table = gtk_table_new(2, 2, FALSE);
3580 gtk_widget_show(header_table);
3581 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
3582 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
3585 /* option menu for selecting accounts */
3586 hbox = gtk_hbox_new(FALSE, 0);
3587 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
3588 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3589 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
3591 from_optmenu_hbox = compose_account_option_menu_create(compose);
3592 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
3593 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
3594 #if 0 /* NEW COMPOSE GUI */
3595 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3600 compose_add_entry_field(header_table, &hbox, &subject_entry, &count,
3603 compose->header_table = header_table;
3604 compose->header_list = NULL;
3605 compose->header_nextrow = count;
3607 compose_create_header_entry(compose);
3609 #if 0 /* NEW COMPOSE GUI */
3610 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
3612 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3613 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
3614 &count, "Newsgroups:", FALSE);
3615 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
3617 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
3619 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
3621 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
3622 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
3624 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
3625 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
3627 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
3628 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
3629 "Followup-To:", FALSE);
3630 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
3632 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
3634 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
3635 GTK_SIGNAL_FUNC(to_activated), compose);
3636 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
3637 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
3638 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
3639 GTK_SIGNAL_FUNC(subject_activated), compose);
3640 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
3641 GTK_SIGNAL_FUNC(cc_activated), compose);
3642 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
3643 GTK_SIGNAL_FUNC(bcc_activated), compose);
3644 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
3645 GTK_SIGNAL_FUNC(replyto_activated), compose);
3646 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
3647 GTK_SIGNAL_FUNC(followupto_activated), compose);
3649 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
3650 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3651 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
3652 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3653 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
3654 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3655 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
3656 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3657 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
3658 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3659 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
3660 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3661 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
3662 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3665 /* attachment list */
3666 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
3667 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), attach_scrwin, gtk_label_new(_("Attachments")));
3668 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
3669 GTK_POLICY_AUTOMATIC,
3671 gtk_widget_set_usize(attach_scrwin, -1, 80);
3673 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
3674 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
3676 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
3677 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
3678 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
3679 GTK_SELECTION_EXTENDED);
3680 for (i = 0; i < N_ATTACH_COLS; i++)
3681 GTK_WIDGET_UNSET_FLAGS
3682 (GTK_CLIST(attach_clist)->column[i].button,
3684 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
3686 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
3687 GTK_SIGNAL_FUNC(attach_selected), compose);
3688 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
3689 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
3690 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
3691 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
3694 gtk_drag_dest_set(attach_clist,
3695 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3697 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
3698 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
3702 edit_vbox = gtk_vbox_new(FALSE, 0);
3703 #if 0 /* NEW COMPOSE GUI */
3704 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
3708 ruler_hbox = gtk_hbox_new(FALSE, 0);
3709 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
3711 ruler = gtk_shruler_new();
3712 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
3713 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
3715 gtk_widget_set_usize(ruler_hbox, 1, -1);
3718 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3719 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
3720 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
3721 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
3722 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
3724 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
3725 (GTK_SCROLLED_WINDOW(scrolledwin)),
3726 gtk_scrolled_window_get_vadjustment
3727 (GTK_SCROLLED_WINDOW(scrolledwin)));
3728 GTK_STEXT(text)->default_tab_width = 8;
3729 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
3731 if (prefs_common.block_cursor) {
3732 GTK_STEXT(text)->cursor_type = STEXT_CURSOR_BLOCK;
3735 if (prefs_common.smart_wrapping) {
3736 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
3737 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
3740 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
3742 gtk_signal_connect(GTK_OBJECT(text), "changed",
3743 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
3744 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
3745 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3746 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
3747 GTK_SIGNAL_FUNC(compose_button_press_cb),
3750 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
3751 GTK_SIGNAL_FUNC(compose_key_press_cb),
3754 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
3755 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
3759 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3761 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
3762 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
3765 if (prefs_common.enable_pspell) {
3766 gtkpspell = gtkpspell_new_with_config(gtkpspellconfig,
3767 prefs_common.pspell_path,
3768 prefs_common.dictionary,
3770 conv_get_current_charset_str());
3771 if (gtkpspell == NULL)
3772 prefs_common.enable_pspell = FALSE;
3774 gtkpspell_attach(gtkpspell, GTK_STEXT(text));
3777 gtk_widget_show_all(vbox);
3779 /* pane between attach clist and text */
3780 paned = gtk_vpaned_new();
3781 gtk_container_add(GTK_CONTAINER(vbox2), paned);
3782 gtk_paned_add1(GTK_PANED(paned), notebook);
3783 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
3784 gtk_widget_show_all(paned);
3786 style = gtk_widget_get_style(text);
3788 /* workaround for the slow down of GtkText when using Pixmap theme */
3789 if (style->engine) {
3790 GtkThemeEngine *engine;
3792 engine = style->engine;
3793 style->engine = NULL;
3794 new_style = gtk_style_copy(style);
3795 style->engine = engine;
3797 new_style = gtk_style_copy(style);
3799 if (prefs_common.textfont) {
3802 charset = conv_get_current_charset();
3803 if (MB_CUR_MAX == 1) {
3806 Xstrdup_a(fontstr, prefs_common.textfont, );
3807 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
3809 font = gdk_font_load(fontstr);
3811 font = gdk_fontset_load(prefs_common.textfont);
3813 gdk_font_unref(new_style->font);
3814 new_style->font = font;
3818 gtk_widget_set_style(text, new_style);
3820 color[0] = quote_color;
3821 cmap = gdk_window_get_colormap(window->window);
3822 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
3823 if (success[0] == FALSE) {
3824 g_warning("Compose: color allocation failed.\n");
3825 style = gtk_widget_get_style(text);
3826 quote_color = style->black;
3829 n_entries = sizeof(compose_popup_entries) /
3830 sizeof(compose_popup_entries[0]);
3831 popupmenu = menu_create_items(compose_popup_entries, n_entries,
3832 "<Compose>", &popupfactory,
3835 ifactory = gtk_item_factory_from_widget(menubar);
3836 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
3837 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
3839 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tool/Template");
3840 #if 0 /* NEW COMPOSE GUI */
3841 if (account->protocol == A_NNTP) {
3842 gtk_widget_hide(to_hbox);
3843 gtk_widget_hide(to_entry);
3844 gtk_widget_hide(cc_hbox);
3845 gtk_widget_hide(cc_entry);
3846 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
3847 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
3849 gtk_widget_hide(newsgroups_hbox);
3850 gtk_widget_hide(newsgroups_entry);
3851 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
3853 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
3857 switch (prefs_common.toolbar_style) {
3859 gtk_widget_hide(handlebox);
3862 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3866 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3870 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
3875 gtk_widget_show(window);
3877 address_completion_start(window);
3879 compose->window = window;
3880 compose->vbox = vbox;
3881 compose->menubar = menubar;
3882 compose->handlebox = handlebox;
3884 compose->vbox2 = vbox2;
3886 compose->table_vbox = table_vbox;
3887 compose->table = table;
3888 #if 0 /* NEW COMPOSE GUI */
3889 compose->to_hbox = to_hbox;
3890 compose->to_entry = to_entry;
3891 compose->newsgroups_hbox = newsgroups_hbox;
3892 compose->newsgroups_entry = newsgroups_entry;
3894 compose->subject_entry = subject_entry;
3895 #if 0 /* NEW COMPOSE GUI */
3896 compose->cc_hbox = cc_hbox;
3897 compose->cc_entry = cc_entry;
3898 compose->bcc_hbox = bcc_hbox;
3899 compose->bcc_entry = bcc_entry;
3900 compose->reply_hbox = reply_hbox;
3901 compose->reply_entry = reply_entry;
3902 compose->followup_hbox = followup_hbox;
3903 compose->followup_entry = followup_entry;
3905 compose->paned = paned;
3907 compose->attach_scrwin = attach_scrwin;
3908 compose->attach_clist = attach_clist;
3910 compose->edit_vbox = edit_vbox;
3911 compose->ruler_hbox = ruler_hbox;
3912 compose->ruler = ruler;
3913 compose->scrolledwin = scrolledwin;
3914 compose->text = text;
3916 compose->focused_editable = NULL;
3918 compose->popupmenu = popupmenu;
3919 compose->popupfactory = popupfactory;
3921 compose->tmpl_menu = tmpl_menu;
3923 compose->mode = mode;
3925 compose->targetinfo = NULL;
3926 compose->replyinfo = NULL;
3928 compose->replyto = NULL;
3929 compose->mailinglist = NULL;
3931 compose->bcc = NULL;
3932 compose->followup_to = NULL;
3933 compose->inreplyto = NULL;
3934 compose->references = NULL;
3935 compose->msgid = NULL;
3936 compose->boundary = NULL;
3939 compose->use_signing = FALSE;
3940 compose->use_encryption = FALSE;
3941 #endif /* USE_GPGME */
3943 compose->modified = FALSE;
3945 compose->return_receipt = FALSE;
3947 compose->to_list = NULL;
3948 compose->newsgroup_list = NULL;
3950 compose->exteditor_file = NULL;
3951 compose->exteditor_pid = -1;
3952 compose->exteditor_readdes = -1;
3953 compose->exteditor_tag = -1;
3955 compose_set_title(compose);
3957 #if 0 /* NEW COMPOSE GUI */
3958 compose->use_bcc = FALSE;
3959 compose->use_replyto = FALSE;
3960 compose->use_followupto = FALSE;
3964 compose->gtkpspell = gtkpspell;
3967 #if 0 /* NEW COMPOSE GUI */
3968 if (account->protocol != A_NNTP) {
3969 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
3970 gtk_check_menu_item_set_active
3971 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3972 gtk_widget_set_sensitive(menuitem, FALSE);
3973 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3974 gtk_check_menu_item_set_active
3975 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3976 gtk_widget_set_sensitive(menuitem, FALSE);
3979 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
3980 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
3981 #if 0 /* NEW COMPOSE GUI */
3982 compose->use_cc = TRUE;
3983 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
3984 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
3985 gtk_check_menu_item_set_active
3986 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3989 if (account->set_autobcc) {
3990 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
3991 #if 0 /* NEW COMPOSE GUI */
3992 compose->use_bcc = TRUE;
3993 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
3994 gtk_check_menu_item_set_active
3995 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
3996 if (account->auto_bcc && mode != COMPOSE_REEDIT)
3997 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4001 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4002 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4003 #if 0 /* NEW COMPOSE GUI */
4004 compose->use_replyto = TRUE;
4005 menuitem = gtk_item_factory_get_item(ifactory,
4006 "/Message/Reply to");
4007 gtk_check_menu_item_set_active
4008 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4009 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4010 account->auto_replyto);
4013 if (account->protocol != A_NNTP) {
4014 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("To:"));
4016 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("Newsgroups:"));
4019 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
4020 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4021 prefs_common.show_ruler);
4024 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4025 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4026 prefs_common.default_sign);
4027 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4028 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4029 prefs_common.default_encrypt);
4030 #endif /* USE_GPGME */
4032 addressbook_set_target_compose(compose);
4033 compose_set_template_menu(compose);
4035 compose_list = g_list_append(compose_list, compose);
4037 #if 0 /* NEW COMPOSE GUI */
4038 compose->use_to = FALSE;
4039 compose->use_cc = FALSE;
4040 compose->use_attach = TRUE;
4043 #if 0 /* NEW COMPOSE GUI */
4044 if (!compose->use_bcc) {
4045 gtk_widget_hide(bcc_hbox);
4046 gtk_widget_hide(bcc_entry);
4047 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4049 if (!compose->use_replyto) {
4050 gtk_widget_hide(reply_hbox);
4051 gtk_widget_hide(reply_entry);
4052 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4054 if (!compose->use_followupto) {
4055 gtk_widget_hide(followup_hbox);
4056 gtk_widget_hide(followup_entry);
4057 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4060 if (!prefs_common.show_ruler)
4061 gtk_widget_hide(ruler_hbox);
4063 select_account(compose, account);
4068 #include "pixmaps/stock_mail_send.xpm"
4069 #include "pixmaps/stock_mail_send_queue.xpm"
4070 #include "pixmaps/stock_mail.xpm"
4071 #include "pixmaps/stock_paste.xpm"
4072 #include "pixmaps/stock_mail_attach.xpm"
4073 #include "pixmaps/stock_mail_compose.xpm"
4074 #include "pixmaps/linewrap.xpm"
4075 #include "pixmaps/tb_address_book.xpm"
4077 #define CREATE_TOOLBAR_ICON(xpm_d) \
4079 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
4080 &container->style->white, \
4082 icon_wid = gtk_pixmap_new(icon, mask); \
4085 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4090 GtkWidget *icon_wid;
4091 GtkWidget *send_btn;
4092 GtkWidget *sendl_btn;
4093 GtkWidget *draft_btn;
4094 GtkWidget *insert_btn;
4095 GtkWidget *attach_btn;
4097 GtkWidget *exteditor_btn;
4098 GtkWidget *linewrap_btn;
4099 GtkWidget *addrbook_btn;
4101 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4103 gtk_container_add(GTK_CONTAINER(container), toolbar);
4104 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4105 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4106 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4107 GTK_TOOLBAR_SPACE_LINE);
4109 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
4110 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4114 icon_wid, toolbar_send_cb, compose);
4116 CREATE_TOOLBAR_ICON(stock_mail_send_queue_xpm);
4117 /* CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm); */
4118 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4120 _("Put into queue folder and send later"),
4122 icon_wid, toolbar_send_later_cb,
4125 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4126 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4128 _("Save to draft folder"),
4130 icon_wid, toolbar_draft_cb,
4133 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4135 CREATE_TOOLBAR_ICON(stock_paste_xpm);
4136 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4140 icon_wid, toolbar_insert_cb,
4143 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
4144 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4148 icon_wid, toolbar_attach_cb,
4151 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4153 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4154 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4156 _("Insert signature"),
4158 icon_wid, toolbar_sig_cb, compose);
4160 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4162 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
4163 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4165 _("Edit with external editor"),
4168 toolbar_ext_editor_cb,
4171 CREATE_TOOLBAR_ICON(linewrap_xpm);
4172 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4174 _("Wrap current paragraph"),
4177 toolbar_linewrap_cb,
4180 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4182 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
4183 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4187 icon_wid, toolbar_address_cb,
4190 compose->toolbar = toolbar;
4191 compose->send_btn = send_btn;
4192 compose->sendl_btn = sendl_btn;
4193 compose->draft_btn = draft_btn;
4194 compose->insert_btn = insert_btn;
4195 compose->attach_btn = attach_btn;
4196 compose->sig_btn = sig_btn;
4197 compose->exteditor_btn = exteditor_btn;
4198 compose->linewrap_btn = linewrap_btn;
4199 compose->addrbook_btn = addrbook_btn;
4201 gtk_widget_show_all(toolbar);
4204 #undef CREATE_TOOLBAR_ICON
4206 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4212 gint num = 0, def_menu = 0;
4214 accounts = account_get_list();
4215 g_return_val_if_fail(accounts != NULL, NULL);
4217 hbox = gtk_hbox_new(FALSE, 0);
4218 optmenu = gtk_option_menu_new();
4219 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4220 menu = gtk_menu_new();
4222 for (; accounts != NULL; accounts = accounts->next, num++) {
4223 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4224 GtkWidget *menuitem;
4227 if (ac == compose->account) def_menu = num;
4229 name = g_strdup_printf("%s: %s <%s>",
4230 ac->account_name, ac->name, ac->address);
4231 MENUITEM_ADD(menu, menuitem, name, ac);
4233 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4234 GTK_SIGNAL_FUNC(account_activated),
4238 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4239 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4244 static void compose_set_template_menu(Compose *compose)
4246 GSList *tmpl_list, *cur;
4250 tmpl_list = template_get_config();
4252 menu = gtk_menu_new();
4254 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4255 Template *tmpl = (Template *)cur->data;
4257 item = gtk_menu_item_new_with_label(tmpl->name);
4258 gtk_menu_append(GTK_MENU(menu), item);
4259 gtk_signal_connect(GTK_OBJECT(item), "activate",
4260 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4262 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4263 gtk_widget_show(item);
4266 gtk_widget_show(menu);
4267 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4270 void compose_reflect_prefs_all(void)
4275 for (cur = compose_list; cur != NULL; cur = cur->next) {
4276 compose = (Compose *)cur->data;
4277 compose_set_template_menu(compose);
4281 static void compose_template_apply(Compose *compose, const gchar *tmpl_str)
4286 if (!tmpl_str) return;
4288 gtk_stext_freeze(GTK_STEXT(compose->text));
4290 if (compose->replyinfo == NULL) {
4293 memset(&dummyinfo, 0, sizeof(MsgInfo));
4294 parsed_str = compose_quote_fmt(compose, &dummyinfo, tmpl_str,
4297 if (prefs_common.quotemark && *prefs_common.quotemark)
4298 qmark = prefs_common.quotemark;
4302 parsed_str = compose_quote_fmt(compose, compose->replyinfo, tmpl_str,
4306 if (parsed_str && prefs_common.auto_sig)
4307 compose_insert_sig(compose);
4309 gtk_stext_thaw(GTK_STEXT(compose->text));
4312 static void compose_destroy(Compose *compose)
4315 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4318 /* NOTE: address_completion_end() does nothing with the window
4319 * however this may change. */
4320 address_completion_end(compose->window);
4322 slist_free_strings(compose->to_list);
4323 g_slist_free(compose->to_list);
4324 slist_free_strings(compose->newsgroup_list);
4325 g_slist_free(compose->newsgroup_list);
4326 slist_free_strings(compose->header_list);
4327 g_slist_free(compose->header_list);
4329 procmsg_msginfo_free(compose->targetinfo);
4330 procmsg_msginfo_free(compose->replyinfo);
4332 g_free(compose->replyto);
4333 g_free(compose->cc);
4334 g_free(compose->bcc);
4335 g_free(compose->newsgroups);
4336 g_free(compose->followup_to);
4338 g_free(compose->inreplyto);
4339 g_free(compose->references);
4340 g_free(compose->msgid);
4341 g_free(compose->boundary);
4343 g_free(compose->exteditor_file);
4345 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
4347 compose_attach_info_free(ainfo);
4349 if (addressbook_get_target_compose() == compose)
4350 addressbook_set_target_compose(NULL);
4352 prefs_common.compose_width = compose->scrolledwin->allocation.width;
4353 prefs_common.compose_height = compose->window->allocation.height;
4355 gtk_widget_destroy(compose->paned);
4359 compose_list = g_list_remove(compose_list, compose);
4362 static void compose_attach_info_free(AttachInfo *ainfo)
4364 g_free(ainfo->file);
4365 g_free(ainfo->content_type);
4366 g_free(ainfo->name);
4370 static void compose_attach_remove_selected(Compose *compose)
4372 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4376 while (clist->selection != NULL) {
4377 row = GPOINTER_TO_INT(clist->selection->data);
4378 ainfo = gtk_clist_get_row_data(clist, row);
4379 compose_attach_info_free(ainfo);
4380 gtk_clist_remove(clist, row);
4384 static struct _AttachProperty
4387 GtkWidget *mimetype_entry;
4388 GtkWidget *encoding_optmenu;
4389 GtkWidget *path_entry;
4390 GtkWidget *filename_entry;
4392 GtkWidget *cancel_btn;
4395 static void compose_attach_property(Compose *compose)
4397 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4400 GtkOptionMenu *optmenu;
4401 static gboolean cancelled;
4403 if (!clist->selection) return;
4404 row = GPOINTER_TO_INT(clist->selection->data);
4406 ainfo = gtk_clist_get_row_data(clist, row);
4409 if (!attach_prop.window)
4410 compose_attach_property_create(&cancelled);
4411 gtk_widget_grab_focus(attach_prop.ok_btn);
4412 gtk_widget_show(attach_prop.window);
4413 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
4415 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
4416 if (ainfo->encoding == ENC_UNKNOWN)
4417 gtk_option_menu_set_history(optmenu, ENC_BASE64);
4419 gtk_option_menu_set_history(optmenu, ainfo->encoding);
4421 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
4422 ainfo->content_type ? ainfo->content_type : "");
4423 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
4424 ainfo->file ? ainfo->file : "");
4425 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
4426 ainfo->name ? ainfo->name : "");
4430 gchar *cnttype = NULL;
4434 GtkWidget *menuitem;
4439 if (cancelled == TRUE) {
4440 gtk_widget_hide(attach_prop.window);
4444 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
4445 if (*text != '\0') {
4448 text = g_strstrip(g_strdup(text));
4449 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
4450 cnttype = g_strdup(text);
4453 alertpanel_error(_("Invalid MIME type."));
4459 menu = gtk_option_menu_get_menu(optmenu);
4460 menuitem = gtk_menu_get_active(GTK_MENU(menu));
4461 ainfo->encoding = GPOINTER_TO_INT
4462 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
4464 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
4465 if (*text != '\0') {
4466 if (is_file_exist(text) &&
4467 (size = get_file_size(text)) > 0)
4468 file = g_strdup(text);
4471 (_("File doesn't exist or is empty."));
4477 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
4478 if (*text != '\0') {
4479 g_free(ainfo->name);
4480 ainfo->name = g_strdup(text);
4484 g_free(ainfo->content_type);
4485 ainfo->content_type = cnttype;
4488 g_free(ainfo->file);
4494 gtk_clist_set_text(clist, row, COL_MIMETYPE,
4495 ainfo->content_type);
4496 gtk_clist_set_text(clist, row, COL_SIZE,
4497 to_human_readable(ainfo->size));
4498 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
4500 gtk_widget_hide(attach_prop.window);
4505 #define SET_LABEL_AND_ENTRY(str, entry, top) \
4507 label = gtk_label_new(str); \
4508 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
4509 GTK_FILL, 0, 0, 0); \
4510 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
4512 entry = gtk_entry_new(); \
4513 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
4514 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
4517 static void compose_attach_property_create(gboolean *cancelled)
4523 GtkWidget *mimetype_entry;
4526 GtkWidget *optmenu_menu;
4527 GtkWidget *menuitem;
4528 GtkWidget *path_entry;
4529 GtkWidget *filename_entry;
4532 GtkWidget *cancel_btn;
4533 GList *mime_type_list, *strlist;
4535 debug_print("Creating attach_property window...\n");
4537 window = gtk_window_new(GTK_WINDOW_DIALOG);
4538 gtk_widget_set_usize(window, 480, -1);
4539 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
4540 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
4541 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
4542 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
4543 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4544 GTK_SIGNAL_FUNC(attach_property_delete_event),
4546 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
4547 GTK_SIGNAL_FUNC(attach_property_key_pressed),
4550 vbox = gtk_vbox_new(FALSE, 8);
4551 gtk_container_add(GTK_CONTAINER(window), vbox);
4553 table = gtk_table_new(4, 2, FALSE);
4554 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
4555 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
4556 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
4558 label = gtk_label_new(_("MIME type"));
4559 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
4561 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
4562 mimetype_entry = gtk_combo_new();
4563 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
4564 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
4566 /* stuff with list */
4567 mime_type_list = procmime_get_mime_type_list();
4569 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
4570 MimeType *type = (MimeType *) mime_type_list->data;
4571 strlist = g_list_append(strlist,
4572 g_strdup_printf("%s/%s",
4573 type->type, type->sub_type));
4576 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
4578 for (mime_type_list = strlist; mime_type_list != NULL;
4579 mime_type_list = mime_type_list->next)
4580 g_free(mime_type_list->data);
4581 g_list_free(strlist);
4583 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
4585 label = gtk_label_new(_("Encoding"));
4586 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
4588 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
4590 hbox = gtk_hbox_new(FALSE, 0);
4591 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
4592 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
4594 optmenu = gtk_option_menu_new();
4595 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4597 optmenu_menu = gtk_menu_new();
4598 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
4599 gtk_widget_set_sensitive(menuitem, FALSE);
4600 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
4601 gtk_widget_set_sensitive(menuitem, FALSE);
4602 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
4603 gtk_widget_set_sensitive(menuitem, FALSE);
4604 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
4606 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
4608 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
4609 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
4611 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
4612 &cancel_btn, _("Cancel"), NULL, NULL);
4613 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
4614 gtk_widget_grab_default(ok_btn);
4616 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
4617 GTK_SIGNAL_FUNC(attach_property_ok),
4619 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
4620 GTK_SIGNAL_FUNC(attach_property_cancel),
4623 gtk_widget_show_all(vbox);
4625 attach_prop.window = window;
4626 attach_prop.mimetype_entry = mimetype_entry;
4627 attach_prop.encoding_optmenu = optmenu;
4628 attach_prop.path_entry = path_entry;
4629 attach_prop.filename_entry = filename_entry;
4630 attach_prop.ok_btn = ok_btn;
4631 attach_prop.cancel_btn = cancel_btn;
4634 #undef SET_LABEL_AND_ENTRY
4636 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
4642 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
4648 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
4649 gboolean *cancelled)
4657 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
4658 gboolean *cancelled)
4660 if (event && event->keyval == GDK_Escape) {
4666 static void compose_exec_ext_editor(Compose *compose)
4672 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
4673 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
4675 if (pipe(pipe_fds) < 0) {
4680 if ((pid = fork()) < 0) {
4686 /* close the write side of the pipe */
4689 compose->exteditor_file = g_strdup(tmp);
4690 compose->exteditor_pid = pid;
4691 compose->exteditor_readdes = pipe_fds[0];
4693 compose_set_ext_editor_sensitive(compose, FALSE);
4695 compose->exteditor_tag =
4696 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
4697 compose_input_cb, compose);
4698 } else { /* process-monitoring process */
4704 /* close the read side of the pipe */
4707 if (compose_write_body_to_file(compose, tmp) < 0) {
4708 fd_write(pipe_fds[1], "2\n", 2);
4712 pid_ed = compose_exec_ext_editor_real(tmp);
4714 fd_write(pipe_fds[1], "1\n", 2);
4718 /* wait until editor is terminated */
4719 waitpid(pid_ed, NULL, 0);
4721 fd_write(pipe_fds[1], "0\n", 2);
4728 static gint compose_exec_ext_editor_real(const gchar *file)
4730 static gchar *def_cmd = "emacs %s";
4736 g_return_val_if_fail(file != NULL, -1);
4738 if ((pid = fork()) < 0) {
4743 if (pid != 0) return pid;
4745 /* grandchild process */
4747 if (setpgid(0, getppid()))
4750 if (prefs_common.ext_editor_cmd &&
4751 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
4752 *(p + 1) == 's' && !strchr(p + 2, '%')) {
4753 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
4755 if (prefs_common.ext_editor_cmd)
4756 g_warning(_("External editor command line is invalid: `%s'\n"),
4757 prefs_common.ext_editor_cmd);
4758 g_snprintf(buf, sizeof(buf), def_cmd, file);
4761 cmdline = g_strsplit(buf, " ", 1024);
4762 execvp(cmdline[0], cmdline);
4765 g_strfreev(cmdline);
4770 static gboolean compose_ext_editor_kill(Compose *compose)
4772 pid_t pgid = compose->exteditor_pid * -1;
4775 ret = kill(pgid, 0);
4777 if (ret == 0 || (ret == -1 && EPERM == errno)) {
4781 msg = g_strdup_printf
4782 (_("The external editor is still working.\n"
4783 "Force terminating the process?\n"
4784 "process group id: %d"), -pgid);
4785 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
4788 if (val == G_ALERTDEFAULT) {
4789 gdk_input_remove(compose->exteditor_tag);
4790 close(compose->exteditor_readdes);
4792 if (kill(pgid, SIGTERM) < 0) perror("kill");
4793 waitpid(compose->exteditor_pid, NULL, 0);
4795 g_warning(_("Terminated process group id: %d"), -pgid);
4796 g_warning(_("Temporary file: %s"),
4797 compose->exteditor_file);
4799 compose_set_ext_editor_sensitive(compose, TRUE);
4801 g_free(compose->exteditor_file);
4802 compose->exteditor_file = NULL;
4803 compose->exteditor_pid = -1;
4804 compose->exteditor_readdes = -1;
4805 compose->exteditor_tag = -1;
4813 static void compose_input_cb(gpointer data, gint source,
4814 GdkInputCondition condition)
4817 Compose *compose = (Compose *)data;
4820 debug_print(_("Compose: input from monitoring process\n"));
4822 gdk_input_remove(compose->exteditor_tag);
4825 if (read(source, &buf[i], 1) < 1) {
4829 if (buf[i] == '\n') {
4834 if (i == sizeof(buf) - 1)
4838 waitpid(compose->exteditor_pid, NULL, 0);
4840 if (buf[0] == '0') { /* success */
4841 GtkSText *text = GTK_STEXT(compose->text);
4843 gtk_stext_freeze(text);
4844 gtk_stext_set_point(text, 0);
4845 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
4846 compose_insert_file(compose, compose->exteditor_file);
4847 compose_changed_cb(NULL, compose);
4848 gtk_stext_thaw(text);
4850 if (unlink(compose->exteditor_file) < 0)
4851 FILE_OP_ERROR(compose->exteditor_file, "unlink");
4852 } else if (buf[0] == '1') { /* failed */
4853 g_warning(_("Couldn't exec external editor\n"));
4854 if (unlink(compose->exteditor_file) < 0)
4855 FILE_OP_ERROR(compose->exteditor_file, "unlink");
4856 } else if (buf[0] == '2') {
4857 g_warning(_("Couldn't write to file\n"));
4858 } else if (buf[0] == '3') {
4859 g_warning(_("Pipe read failed\n"));
4864 compose_set_ext_editor_sensitive(compose, TRUE);
4866 g_free(compose->exteditor_file);
4867 compose->exteditor_file = NULL;
4868 compose->exteditor_pid = -1;
4869 compose->exteditor_readdes = -1;
4870 compose->exteditor_tag = -1;
4873 static void compose_set_ext_editor_sensitive(Compose *compose,
4876 GtkItemFactory *ifactory;
4878 ifactory = gtk_item_factory_from_widget(compose->menubar);
4880 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
4881 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
4882 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
4884 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
4885 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
4886 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
4887 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
4888 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
4891 gtk_widget_set_sensitive(compose->text, sensitive);
4892 gtk_widget_set_sensitive(compose->send_btn, sensitive);
4893 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
4894 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
4895 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
4896 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
4897 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
4898 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
4901 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
4905 cursor_pos = (text->cursor_pos_x - extra) / char_width;
4906 cursor_pos = MAX(cursor_pos, 0);
4911 /* callback functions */
4913 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
4914 * includes "non-client" (windows-izm) in calculation, so this calculation
4915 * may not be accurate.
4917 static gboolean compose_edit_size_alloc(GtkEditable *widget,
4918 GtkAllocation *allocation,
4919 GtkSHRuler *shruler)
4921 if (prefs_common.show_ruler) {
4923 gint line_width_in_chars;
4925 char_width = gtkut_get_font_width
4926 (GTK_WIDGET(widget)->style->font);
4927 line_width_in_chars =
4928 (allocation->width - allocation->x) / char_width;
4930 /* got the maximum */
4931 gtk_ruler_set_range(GTK_RULER(shruler),
4932 0.0, line_width_in_chars,
4933 calc_cursor_xpos(GTK_STEXT(widget),
4936 /*line_width_in_chars*/ char_width);
4942 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
4944 compose_send_cb(data, 0, NULL);
4947 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
4949 compose_send_later_cb(data, 0, NULL);
4952 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
4954 compose_draft_cb(data, 0, NULL);
4957 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
4959 compose_insert_file_cb(data, 0, NULL);
4962 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
4964 compose_attach_cb(data, 0, NULL);
4967 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
4969 Compose *compose = (Compose *)data;
4971 compose_insert_sig(compose);
4974 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
4976 Compose *compose = (Compose *)data;
4978 compose_exec_ext_editor(compose);
4981 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
4983 Compose *compose = (Compose *)data;
4985 compose_wrap_line(compose);
4988 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
4990 compose_address_cb(data, 0, NULL);
4993 static void select_account(Compose * compose, PrefsAccount * ac)
4995 compose->account = ac;
4996 compose_set_title(compose);
4998 #if 0 /* NEW COMPOSE GUI */
4999 if (ac->protocol == A_NNTP) {
5000 GtkItemFactory *ifactory;
5001 GtkWidget *menuitem;
5003 ifactory = gtk_item_factory_from_widget(compose->menubar);
5004 menu_set_sensitive(ifactory,
5005 "/Message/Followup to", TRUE);
5006 gtk_widget_show(compose->newsgroups_hbox);
5007 gtk_widget_show(compose->newsgroups_entry);
5008 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5011 compose->use_to = FALSE;
5012 compose->use_cc = FALSE;
5014 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5015 gtk_check_menu_item_set_active
5016 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5018 menu_set_sensitive(ifactory,
5019 "/Message/To", TRUE);
5020 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5021 gtk_check_menu_item_set_active
5022 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5024 gtk_widget_hide(compose->to_hbox);
5025 gtk_widget_hide(compose->to_entry);
5026 gtk_widget_hide(compose->cc_hbox);
5027 gtk_widget_hide(compose->cc_entry);
5028 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5030 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5034 GtkItemFactory *ifactory;
5035 GtkWidget *menuitem;
5037 ifactory = gtk_item_factory_from_widget(compose->menubar);
5038 menu_set_sensitive(ifactory,
5039 "/Message/Followup to", FALSE);
5040 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5041 gtk_widget_hide(compose->newsgroups_hbox);
5042 gtk_widget_hide(compose->newsgroups_entry);
5043 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5046 compose->use_to = TRUE;
5047 compose->use_cc = TRUE;
5049 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5050 gtk_check_menu_item_set_active
5051 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5052 menu_set_sensitive(ifactory,
5053 "/Message/To", FALSE);
5054 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5055 gtk_check_menu_item_set_active
5056 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5057 gtk_widget_show(compose->to_hbox);
5058 gtk_widget_show(compose->to_entry);
5059 gtk_widget_show(compose->cc_hbox);
5060 gtk_widget_show(compose->cc_entry);
5062 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5064 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5067 gtk_widget_queue_resize(compose->table_vbox);
5071 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5073 Compose *compose = (Compose *)data;
5077 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5078 g_return_if_fail(ac != NULL);
5080 if (ac != compose->account)
5081 select_account(compose, ac);
5084 static void attach_selected(GtkCList *clist, gint row, gint column,
5085 GdkEvent *event, gpointer data)
5087 Compose *compose = (Compose *)data;
5089 if (event && event->type == GDK_2BUTTON_PRESS)
5090 compose_attach_property(compose);
5093 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5096 Compose *compose = (Compose *)data;
5097 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5102 if (event->button == 3) {
5103 if ((clist->selection && !clist->selection->next) ||
5104 !clist->selection) {
5105 gtk_clist_unselect_all(clist);
5106 if (gtk_clist_get_selection_info(clist,
5109 gtk_clist_select_row(clist, row, column);
5110 gtkut_clist_set_focus_row(clist, row);
5113 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5114 NULL, NULL, event->button, event->time);
5118 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5121 Compose *compose = (Compose *)data;
5125 switch (event->keyval) {
5127 compose_attach_remove_selected(compose);
5132 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5134 Compose *compose = (Compose *)data;
5137 val = compose_send(compose);
5139 if (val == 0) gtk_widget_destroy(compose->window);
5142 static void compose_send_later_cb(gpointer data, guint action,
5145 Compose *compose = (Compose *)data;
5147 gboolean recipient_found;
5150 if(!compose_check_for_valid_recipient(compose)) {
5151 alertpanel_error(_("Recipient is not specified."));
5155 g_snprintf(tmp, 22, "%s%ctmpmsg%d",
5156 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5158 if (prefs_common.linewrap_at_send)
5159 compose_wrap_line_all(compose);
5161 if (compose_write_to_file(compose, tmp, FALSE) < 0 ||
5162 compose_queue(compose, tmp) < 0) {
5163 alertpanel_error(_("Can't queue the message."));
5167 if (prefs_common.savemsg) {
5168 if (compose_save_to_outbox(compose, tmp) < 0)
5170 (_("Can't save the message to outbox."));
5173 if (unlink(tmp) < 0)
5174 FILE_OP_ERROR(tmp, "unlink");
5176 gtk_widget_destroy(compose->window);
5179 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5181 Compose *compose = (Compose *)data;
5185 draft = folder_get_default_draft();
5187 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5188 G_DIR_SEPARATOR, (gint)compose);
5190 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5195 folder_item_scan(draft);
5196 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
5203 if (compose->mode == COMPOSE_REEDIT) {
5204 compose_remove_reedit_target(compose);
5205 if (compose->targetinfo &&
5206 compose->targetinfo->folder != draft)
5207 folderview_update_item(compose->targetinfo->folder,
5211 folder_item_scan(draft);
5212 folderview_update_item(draft, TRUE);
5214 gtk_widget_destroy(compose->window);
5217 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
5219 Compose *compose = (Compose *)data;
5222 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5227 for ( tmp = file_list; tmp; tmp = tmp->next) {
5228 gchar *file = (gchar *) tmp->data;
5229 compose_attach_append(compose, file, MIME_UNKNOWN);
5232 g_list_free(file_list);
5236 static void compose_insert_file_cb(gpointer data, guint action,
5239 Compose *compose = (Compose *)data;
5242 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5247 for ( tmp = file_list; tmp; tmp = tmp->next) {
5248 gchar *file = (gchar *) tmp->data;
5249 compose_insert_file(compose, file);
5252 g_list_free(file_list);
5256 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
5259 compose_close_cb(data, 0, NULL);
5263 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
5265 Compose *compose = (Compose *)data;
5268 if (compose->exteditor_tag != -1) {
5269 if (!compose_ext_editor_kill(compose))
5273 if (compose->modified) {
5274 val = alertpanel(_("Discard message"),
5275 _("This message has been modified. discard it?"),
5276 _("Discard"), _("to Draft"), _("Cancel"));
5279 case G_ALERTDEFAULT:
5281 case G_ALERTALTERNATE:
5282 compose_draft_cb(data, 0, NULL);
5289 if (compose->gtkpspell) {
5290 gtkpspell_detach(compose->gtkpspell);
5291 compose->gtkpspell = gtkpspell_delete(compose->gtkpspell);
5294 gtk_widget_destroy(compose->window);
5297 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
5299 Compose *compose = (Compose *)data;
5301 addressbook_open(compose);
5304 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
5306 Compose *compose = (Compose *)data;
5309 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
5310 g_return_if_fail(tmpl != NULL);
5312 compose_template_apply(compose, tmpl->value);
5315 static void compose_ext_editor_cb(gpointer data, guint action,
5318 Compose *compose = (Compose *)data;
5320 compose_exec_ext_editor(compose);
5323 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
5325 compose_destroy(compose);
5328 static void compose_cut_cb(Compose *compose)
5330 if (compose->focused_editable &&
5331 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5332 gtk_editable_cut_clipboard
5333 (GTK_EDITABLE(compose->focused_editable));
5336 static void compose_copy_cb(Compose *compose)
5338 if (compose->focused_editable &&
5339 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5340 gtk_editable_copy_clipboard
5341 (GTK_EDITABLE(compose->focused_editable));
5344 static void compose_paste_cb(Compose *compose)
5346 if (compose->focused_editable &&
5347 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5348 gtk_editable_paste_clipboard
5349 (GTK_EDITABLE(compose->focused_editable));
5352 static void compose_allsel_cb(Compose *compose)
5354 if (compose->focused_editable &&
5355 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5356 gtk_editable_select_region
5357 (GTK_EDITABLE(compose->focused_editable), 0, -1);
5360 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
5362 if (GTK_IS_EDITABLE(widget))
5363 compose->focused_editable = widget;
5366 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
5368 if (compose->modified == FALSE) {
5369 compose->modified = TRUE;
5370 compose_set_title(compose);
5374 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
5377 gtk_stext_set_point(GTK_STEXT(widget),
5378 gtk_editable_get_position(GTK_EDITABLE(widget)));
5382 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
5385 gtk_stext_set_point(GTK_STEXT(widget),
5386 gtk_editable_get_position(GTK_EDITABLE(widget)));
5390 #if 0 /* NEW COMPOSE GUI */
5391 static void compose_toggle_to_cb(gpointer data, guint action,
5394 Compose *compose = (Compose *)data;
5396 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5397 gtk_widget_show(compose->to_hbox);
5398 gtk_widget_show(compose->to_entry);
5399 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
5400 compose->use_to = TRUE;
5402 gtk_widget_hide(compose->to_hbox);
5403 gtk_widget_hide(compose->to_entry);
5404 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
5405 gtk_widget_queue_resize(compose->table_vbox);
5406 compose->use_to = FALSE;
5409 if (addressbook_get_target_compose() == compose)
5410 addressbook_set_target_compose(compose);
5413 static void compose_toggle_cc_cb(gpointer data, guint action,
5416 Compose *compose = (Compose *)data;
5418 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5419 gtk_widget_show(compose->cc_hbox);
5420 gtk_widget_show(compose->cc_entry);
5421 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
5422 compose->use_cc = TRUE;
5424 gtk_widget_hide(compose->cc_hbox);
5425 gtk_widget_hide(compose->cc_entry);
5426 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
5427 gtk_widget_queue_resize(compose->table_vbox);
5428 compose->use_cc = FALSE;
5431 if (addressbook_get_target_compose() == compose)
5432 addressbook_set_target_compose(compose);
5435 static void compose_toggle_bcc_cb(gpointer data, guint action,
5438 Compose *compose = (Compose *)data;
5440 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5441 gtk_widget_show(compose->bcc_hbox);
5442 gtk_widget_show(compose->bcc_entry);
5443 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
5444 compose->use_bcc = TRUE;
5446 gtk_widget_hide(compose->bcc_hbox);
5447 gtk_widget_hide(compose->bcc_entry);
5448 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
5449 gtk_widget_queue_resize(compose->table_vbox);
5450 compose->use_bcc = FALSE;
5453 if (addressbook_get_target_compose() == compose)
5454 addressbook_set_target_compose(compose);
5457 static void compose_toggle_replyto_cb(gpointer data, guint action,
5460 Compose *compose = (Compose *)data;
5462 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5463 gtk_widget_show(compose->reply_hbox);
5464 gtk_widget_show(compose->reply_entry);
5465 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
5466 compose->use_replyto = TRUE;
5468 gtk_widget_hide(compose->reply_hbox);
5469 gtk_widget_hide(compose->reply_entry);
5470 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
5471 gtk_widget_queue_resize(compose->table_vbox);
5472 compose->use_replyto = FALSE;
5476 static void compose_toggle_followupto_cb(gpointer data, guint action,
5479 Compose *compose = (Compose *)data;
5481 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5482 gtk_widget_show(compose->followup_hbox);
5483 gtk_widget_show(compose->followup_entry);
5484 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
5485 compose->use_followupto = TRUE;
5487 gtk_widget_hide(compose->followup_hbox);
5488 gtk_widget_hide(compose->followup_entry);
5489 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
5490 gtk_widget_queue_resize(compose->table_vbox);
5491 compose->use_followupto = FALSE;
5495 static void compose_toggle_attach_cb(gpointer data, guint action,
5498 Compose *compose = (Compose *)data;
5500 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5501 gtk_widget_ref(compose->edit_vbox);
5503 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5504 compose->edit_vbox);
5505 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
5506 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
5508 gtk_widget_show(compose->paned);
5510 gtk_widget_unref(compose->edit_vbox);
5511 gtk_widget_unref(compose->paned);
5513 compose->use_attach = TRUE;
5515 gtk_widget_ref(compose->paned);
5516 gtk_widget_ref(compose->edit_vbox);
5518 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5520 gtk_container_remove(GTK_CONTAINER(compose->paned),
5521 compose->edit_vbox);
5522 gtk_box_pack_start(GTK_BOX(compose->vbox2),
5523 compose->edit_vbox, TRUE, TRUE, 0);
5525 gtk_widget_unref(compose->edit_vbox);
5527 compose->use_attach = FALSE;
5533 static void compose_toggle_sign_cb(gpointer data, guint action,
5536 Compose *compose = (Compose *)data;
5538 if (GTK_CHECK_MENU_ITEM(widget)->active)
5539 compose->use_signing = TRUE;
5541 compose->use_signing = FALSE;
5544 static void compose_toggle_encrypt_cb(gpointer data, guint action,
5547 Compose *compose = (Compose *)data;
5549 if (GTK_CHECK_MENU_ITEM(widget)->active)
5550 compose->use_encryption = TRUE;
5552 compose->use_encryption = FALSE;
5554 #endif /* USE_GPGME */
5556 static void compose_toggle_ruler_cb(gpointer data, guint action,
5559 Compose *compose = (Compose *)data;
5561 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5562 gtk_widget_show(compose->ruler_hbox);
5563 prefs_common.show_ruler = TRUE;
5565 gtk_widget_hide(compose->ruler_hbox);
5566 gtk_widget_queue_resize(compose->edit_vbox);
5567 prefs_common.show_ruler = FALSE;
5571 static void compose_attach_drag_received_cb (GtkWidget *widget,
5572 GdkDragContext *drag_context,
5575 GtkSelectionData *data,
5580 Compose *compose = (Compose *)user_data;
5583 list = uri_list_extract_filenames((const gchar *)data->data);
5584 for (tmp = list; tmp != NULL; tmp = tmp->next)
5585 compose_attach_append(compose, (const gchar *)tmp->data,
5587 list_free_strings(list);
5591 static void compose_insert_drag_received_cb (GtkWidget *widget,
5592 GdkDragContext *drag_context,
5595 GtkSelectionData *data,
5600 Compose *compose = (Compose *)user_data;
5603 list = uri_list_extract_filenames((const gchar *)data->data);
5604 for (tmp = list; tmp != NULL; tmp = tmp->next)
5605 compose_insert_file(compose, (const gchar *)tmp->data);
5606 list_free_strings(list);
5610 #if 0 /* NEW COMPOSE GUI */
5611 static void to_activated(GtkWidget *widget, Compose *compose)
5613 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
5614 gtk_widget_grab_focus(compose->newsgroups_entry);
5616 gtk_widget_grab_focus(compose->subject_entry);
5619 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
5621 gtk_widget_grab_focus(compose->subject_entry);
5624 static void subject_activated(GtkWidget *widget, Compose *compose)
5626 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
5627 gtk_widget_grab_focus(compose->cc_entry);
5628 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
5629 gtk_widget_grab_focus(compose->bcc_entry);
5630 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
5631 gtk_widget_grab_focus(compose->reply_entry);
5632 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
5633 gtk_widget_grab_focus(compose->followup_entry);
5635 gtk_widget_grab_focus(compose->text);
5638 static void cc_activated(GtkWidget *widget, Compose *compose)
5640 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
5641 gtk_widget_grab_focus(compose->bcc_entry);
5642 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
5643 gtk_widget_grab_focus(compose->reply_entry);
5644 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
5645 gtk_widget_grab_focus(compose->followup_entry);
5647 gtk_widget_grab_focus(compose->text);
5650 static void bcc_activated(GtkWidget *widget, Compose *compose)
5652 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
5653 gtk_widget_grab_focus(compose->reply_entry);
5654 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
5655 gtk_widget_grab_focus(compose->followup_entry);
5657 gtk_widget_grab_focus(compose->text);
5660 static void replyto_activated(GtkWidget *widget, Compose *compose)
5662 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
5663 gtk_widget_grab_focus(compose->followup_entry);
5665 gtk_widget_grab_focus(compose->text);
5668 static void followupto_activated(GtkWidget *widget, Compose *compose)
5670 gtk_widget_grab_focus(compose->text);
5674 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
5677 Compose *compose = (Compose *)data;
5679 if (GTK_CHECK_MENU_ITEM(widget)->active)
5680 compose->return_receipt = TRUE;
5682 compose->return_receipt = FALSE;
5685 static void template_apply_cb(gchar *s, gpointer data)
5687 Compose *compose = (Compose*)data;
5688 GtkSText *text = GTK_STEXT(compose->text);
5693 gchar *old_tmpl = s;
5697 if(compose->replyinfo == NULL) {
5698 gtk_stext_freeze(text);
5699 gtk_stext_set_point(text, 0);
5700 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5701 gtk_stext_insert(text, NULL, NULL, NULL, s, -1);
5702 gtk_stext_thaw(text);
5707 parsed_text = g_new(gchar, strlen(s)*2 + 1);
5711 *parsed_text++ = '\\';
5712 *parsed_text++ = 'n';
5715 *parsed_text++ = *s++;
5718 *parsed_text = '\0';
5720 if (prefs_common.quotemark && *prefs_common.quotemark)
5721 qmark = prefs_common.quotemark;
5725 quote_str = compose_quote_fmt(compose, compose->replyinfo, tmpl, qmark);
5726 if (quote_str != NULL) {
5727 gtk_stext_freeze(text);
5728 gtk_stext_set_point(text, 0);
5729 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5730 gtk_stext_insert(text, NULL, NULL, NULL, quote_str, -1);
5731 gtk_stext_thaw(text);
5738 static void template_select_cb(gpointer data, guint action,
5741 template_select(&template_apply_cb, data);
5744 void compose_headerentry_key_press_event_cb(GtkWidget *entry, GdkEventKey *event, compose_headerentry *headerentry) {
5745 if((g_slist_length(headerentry->compose->header_list) > 0) &&
5746 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
5747 !(event->state & GDK_MODIFIER_MASK) &&
5748 (event->keyval == GDK_BackSpace) &&
5749 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
5750 gtk_container_remove(GTK_CONTAINER(headerentry->compose->header_table), headerentry->combo);
5751 gtk_container_remove(GTK_CONTAINER(headerentry->compose->header_table), headerentry->entry);
5752 headerentry->compose->header_list = g_slist_remove(headerentry->compose->header_list, headerentry);
5753 g_free(headerentry);
5757 void compose_headerentry_changed_cb(GtkWidget *entry, compose_headerentry *headerentry) {
5758 if(strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
5759 headerentry->compose->header_list = g_slist_append(headerentry->compose->header_list, headerentry);
5760 compose_create_header_entry(headerentry->compose);
5761 gtk_signal_disconnect_by_func(GTK_OBJECT(entry), GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);