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 "quote_fmt.h"
102 #include "template.h"
105 # include "rfc2015.h"
115 #define N_ATTACH_COLS 3
117 #define B64_LINE_SIZE 57
118 #define B64_BUFFSIZE 77
120 #define MAX_REFERENCES_LEN 999
122 static GdkColor quote_color = {0, 0, 0, 0xbfff};
124 static GList *compose_list = NULL;
126 Compose *compose_generic_new (PrefsAccount *account,
130 static Compose *compose_create (PrefsAccount *account,
132 static void compose_toolbar_create (Compose *compose,
133 GtkWidget *container);
134 static GtkWidget *compose_account_option_menu_create
136 static void compose_set_template_menu (Compose *compose);
137 static void compose_template_apply (Compose *compose,
139 static void compose_destroy (Compose *compose);
141 static void compose_entries_set (Compose *compose,
142 const gchar *mailto);
143 static gint compose_parse_header (Compose *compose,
145 static gchar *compose_parse_references (const gchar *ref,
148 static gchar *compose_quote_fmt (Compose *compose,
153 static void compose_reply_set_entry (Compose *compose,
158 followup_and_reply_to);
159 static void compose_reedit_set_entry (Compose *compose,
161 static void compose_insert_sig (Compose *compose);
162 static void compose_insert_file (Compose *compose,
164 static void compose_attach_append (Compose *compose,
166 ContentType cnttype);
167 static void compose_attach_append_with_type(Compose *compose,
170 ContentType cnttype);
171 static void compose_wrap_line (Compose *compose);
172 static void compose_wrap_line_all (Compose *compose);
173 static void compose_set_title (Compose *compose);
175 static PrefsAccount *compose_current_mail_account(void);
176 /* static gint compose_send (Compose *compose); */
177 static gint compose_write_to_file (Compose *compose,
180 static gint compose_write_body_to_file (Compose *compose,
182 static gint compose_save_to_outbox (Compose *compose,
184 static gint compose_remove_reedit_target (Compose *compose);
185 static gint compose_queue (Compose *compose,
188 static void compose_write_attach (Compose *compose,
190 static gint compose_write_headers (Compose *compose,
192 const gchar *charset,
193 EncodingType encoding,
196 static void compose_convert_header (gchar *dest,
200 static void compose_generate_msgid (Compose *compose,
204 static void compose_attach_info_free (AttachInfo *ainfo);
205 static void compose_attach_remove_selected (Compose *compose);
207 static void compose_attach_property (Compose *compose);
208 static void compose_attach_property_create (gboolean *cancelled);
209 static void attach_property_ok (GtkWidget *widget,
210 gboolean *cancelled);
211 static void attach_property_cancel (GtkWidget *widget,
212 gboolean *cancelled);
213 static gint attach_property_delete_event (GtkWidget *widget,
215 gboolean *cancelled);
216 static void attach_property_key_pressed (GtkWidget *widget,
218 gboolean *cancelled);
220 static void compose_exec_ext_editor (Compose *compose);
221 static gint compose_exec_ext_editor_real (const gchar *file);
222 static gboolean compose_ext_editor_kill (Compose *compose);
223 static void compose_input_cb (gpointer data,
225 GdkInputCondition condition);
226 static void compose_set_ext_editor_sensitive (Compose *compose,
229 static gint calc_cursor_xpos (GtkSText *text,
233 static void compose_create_header_entry (Compose *compose);
234 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
236 /* callback functions */
238 static gboolean compose_edit_size_alloc (GtkEditable *widget,
239 GtkAllocation *allocation,
240 GtkSHRuler *shruler);
242 static void toolbar_send_cb (GtkWidget *widget,
244 static void toolbar_send_later_cb (GtkWidget *widget,
246 static void toolbar_draft_cb (GtkWidget *widget,
248 static void toolbar_insert_cb (GtkWidget *widget,
250 static void toolbar_attach_cb (GtkWidget *widget,
252 static void toolbar_sig_cb (GtkWidget *widget,
254 static void toolbar_ext_editor_cb (GtkWidget *widget,
256 static void toolbar_linewrap_cb (GtkWidget *widget,
258 static void toolbar_address_cb (GtkWidget *widget,
261 static void select_account (Compose *compose,
264 static void account_activated (GtkMenuItem *menuitem,
267 static void attach_selected (GtkCList *clist,
272 static void attach_button_pressed (GtkWidget *widget,
273 GdkEventButton *event,
275 static void attach_key_pressed (GtkWidget *widget,
279 static void compose_send_cb (gpointer data,
282 static void compose_send_later_cb (gpointer data,
286 static void compose_draft_cb (gpointer data,
290 static void compose_attach_cb (gpointer data,
293 static void compose_insert_file_cb (gpointer data,
297 static void compose_close_cb (gpointer data,
301 static void compose_address_cb (gpointer data,
304 static void compose_template_activate_cb(GtkWidget *widget,
307 static void compose_ext_editor_cb (gpointer data,
311 static gint compose_delete_cb (GtkWidget *widget,
314 static void compose_destroy_cb (GtkWidget *widget,
317 static void compose_cut_cb (Compose *compose);
318 static void compose_copy_cb (Compose *compose);
319 static void compose_paste_cb (Compose *compose);
320 static void compose_allsel_cb (Compose *compose);
322 static void compose_grab_focus_cb (GtkWidget *widget,
325 static void compose_changed_cb (GtkEditable *editable,
327 static void compose_button_press_cb (GtkWidget *widget,
328 GdkEventButton *event,
331 static void compose_key_press_cb (GtkWidget *widget,
337 static void compose_toggle_to_cb (gpointer data,
340 static void compose_toggle_cc_cb (gpointer data,
343 static void compose_toggle_bcc_cb (gpointer data,
346 static void compose_toggle_replyto_cb (gpointer data,
349 static void compose_toggle_followupto_cb(gpointer data,
352 static void compose_toggle_attach_cb (gpointer data,
356 static void compose_toggle_ruler_cb (gpointer data,
360 static void compose_toggle_sign_cb (gpointer data,
363 static void compose_toggle_encrypt_cb (gpointer data,
367 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
370 static void compose_attach_drag_received_cb (GtkWidget *widget,
371 GdkDragContext *drag_context,
374 GtkSelectionData *data,
378 static void compose_insert_drag_received_cb (GtkWidget *widget,
379 GdkDragContext *drag_context,
382 GtkSelectionData *data,
388 static void to_activated (GtkWidget *widget,
390 static void newsgroups_activated (GtkWidget *widget,
392 static void subject_activated (GtkWidget *widget,
394 static void cc_activated (GtkWidget *widget,
396 static void bcc_activated (GtkWidget *widget,
398 static void replyto_activated (GtkWidget *widget,
400 static void followupto_activated (GtkWidget *widget,
404 static void compose_attach_parts (Compose *compose,
407 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
409 gboolean ignore_replyto,
410 gboolean followup_and_reply_to);
412 void compose_headerentry_changed_cb (GtkWidget *entry,
413 ComposeHeaderEntry *headerentry);
414 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
416 ComposeHeaderEntry *headerentry);
418 static GtkItemFactoryEntry compose_popup_entries[] =
420 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
421 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
422 {N_("/---"), NULL, NULL, 0, "<Separator>"},
423 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
426 static GtkItemFactoryEntry compose_entries[] =
428 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
429 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
430 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
431 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
432 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
433 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
435 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
436 {N_("/_Edit/_Undo"), "<control>Z", NULL, 0, NULL},
437 {N_("/_Edit/_Redo"), "<control>Y", NULL, 0, NULL},
438 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
439 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
440 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
441 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
442 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
443 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
444 {N_("/_Edit/_Wrap current paragraph"), "<alt>L", compose_wrap_line, 0, NULL},
445 {N_("/_Edit/Wrap all long _lines"),
446 "<shift><alt>L", compose_wrap_line_all, 0, NULL},
447 {N_("/_Edit/Edit with e_xternal editor"),
448 "<alt>X", compose_ext_editor_cb, 0, NULL},
450 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
451 {N_("/_Message/_Send"), "<control>Return",
452 compose_send_cb, 0, NULL},
453 {N_("/_Message/Send _later"), "<shift><alt>S",
454 compose_send_later_cb, 0, NULL},
455 {N_("/_Message/Save to _draft folder"),
456 "<alt>D", compose_draft_cb, 0, NULL},
457 #if 0 /* NEW COMPOSE GUI */
458 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
459 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
460 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
461 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
462 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
463 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
464 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
465 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
466 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
469 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
470 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
471 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
472 #endif /* USE_GPGME */
473 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
474 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
475 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
476 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
477 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb , 0, NULL},
478 {N_("/_Tool/_Template"), NULL, NULL, 0, "<Branch>"},
479 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
480 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
483 static GtkTargetEntry compose_mime_types[] =
485 {"text/uri-list", 0, 0}
488 Compose *compose_new(PrefsAccount *account)
490 return compose_generic_new(account, NULL, NULL);
493 Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
497 GtkItemFactory *ifactory;
499 c = compose_generic_new(account, NULL, NULL);
501 filename = procmsg_get_message_file(msginfo);
502 if (filename == NULL)
505 c->bounce_filename = filename;
507 if (msginfo->subject)
508 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
510 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
512 compose_quote_fmt(c, msginfo, "%M", NULL);
513 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
515 ifactory = gtk_item_factory_from_widget(c->popupmenu);
516 menu_set_sensitive(ifactory, "/Add...", FALSE);
517 menu_set_sensitive(ifactory, "/Remove", FALSE);
518 menu_set_sensitive(ifactory, "/Property...", FALSE);
520 ifactory = gtk_item_factory_from_widget(c->menubar);
521 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
522 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
523 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
524 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
525 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
526 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
527 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
528 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
530 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
531 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
533 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
534 menu_set_sensitive(ifactory, "/Tool/Template", FALSE);
536 gtk_widget_set_sensitive(c->insert_btn, FALSE);
537 gtk_widget_set_sensitive(c->attach_btn, FALSE);
538 gtk_widget_set_sensitive(c->sig_btn, FALSE);
539 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
540 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
545 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
547 return compose_generic_new(account, mailto, NULL);
550 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
552 return compose_generic_new(account, NULL, item);
555 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
559 if (item && item->prefs && item->prefs->enable_default_account)
560 account = account_find_from_id(item->prefs->default_account);
562 if (!account) account = cur_account;
563 g_return_val_if_fail(account != NULL, NULL);
565 compose = compose_create(account, COMPOSE_NEW);
566 compose->replyinfo = NULL;
568 if (prefs_common.auto_sig)
569 compose_insert_sig(compose);
570 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
571 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
573 if (account->protocol != A_NNTP) {
575 compose_entries_set(compose, mailto);
577 } else if(item && item->prefs->enable_default_to) {
578 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
580 if (item && item->ret_rcpt) {
581 GtkItemFactory *ifactory;
583 ifactory = gtk_item_factory_from_widget(compose->menubar);
584 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
588 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
591 gtk_widget_grab_focus(compose->subject_entry);
593 if (prefs_common.auto_exteditor)
594 compose_exec_ext_editor(compose);
599 #define CHANGE_FLAGS(msginfo) \
601 if (msginfo->folder->folder->change_flags != NULL) \
602 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
608 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
609 const gchar *followupto, gchar * to)
613 if (!account) account = cur_account;
614 g_return_val_if_fail(account != NULL, NULL);
615 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
617 compose = compose_create(account, COMPOSE_NEW);
619 if (prefs_common.auto_sig)
620 compose_insert_sig(compose);
621 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
622 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
624 compose_entry_append(compose, to, COMPOSE_TO);
625 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
626 gtk_widget_grab_focus(compose->subject_entry);
632 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
633 gboolean ignore_replyto)
635 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
638 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
640 gboolean ignore_replyto)
642 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
645 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
647 gboolean ignore_replyto,
648 gboolean followup_and_reply_to)
651 PrefsAccount *account;
652 PrefsAccount *reply_account;
655 g_return_if_fail(msginfo != NULL);
656 g_return_if_fail(msginfo->folder != NULL);
659 /* select the account set in folderitem's property (if enabled) */
660 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
661 account = account_find_from_id(msginfo->folder->prefs->default_account);
663 /* select the account for the whole folder (IMAP / NNTP) */
665 account = msginfo->folder->folder->account;
667 /* select account by to: and cc: header if enabled */
668 if (prefs_common.reply_account_autosel) {
669 if (!account && msginfo->to) {
671 Xstrdup_a(to, msginfo->to, return);
673 account = account_find_from_address(to);
677 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
679 account = account_find_from_address(cc);
684 /* select current account */
685 if (!account) account = cur_account;
686 g_return_if_fail(account != NULL);
688 if (ignore_replyto && account->protocol == A_NNTP &&
689 !followup_and_reply_to) {
691 account_find_from_address(account->address);
693 reply_account = compose_current_mail_account();
697 reply_account = account;
699 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
700 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
702 CHANGE_FLAGS(msginfo);
704 compose = compose_create(account, COMPOSE_REPLY);
705 compose->replyinfo = procmsg_msginfo_copy(msginfo);
707 #if 0 /* NEW COMPOSE GUI */
708 if (followup_and_reply_to) {
709 gtk_widget_show(compose->to_hbox);
710 gtk_widget_show(compose->to_entry);
711 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
712 compose->use_to = TRUE;
715 if (msginfo->folder && msginfo->folder->ret_rcpt) {
716 GtkItemFactory *ifactory;
718 ifactory = gtk_item_factory_from_widget(compose->menubar);
719 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
722 if (compose_parse_header(compose, msginfo) < 0) return;
723 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
724 followup_and_reply_to);
726 text = GTK_STEXT(compose->text);
727 gtk_stext_freeze(text);
733 if (prefs_common.quotemark && *prefs_common.quotemark)
734 qmark = prefs_common.quotemark;
738 quote_str = compose_quote_fmt(compose, msginfo,
739 prefs_common.quotefmt,
743 if (prefs_common.auto_sig)
744 compose_insert_sig(compose);
745 gtk_editable_set_position(GTK_EDITABLE(text), 0);
746 gtk_stext_set_point(text, 0);
748 if (quote && prefs_common.linewrap_quote)
749 compose_wrap_line_all(compose);
751 gtk_stext_thaw(text);
752 gtk_widget_grab_focus(compose->text);
754 if (prefs_common.auto_exteditor)
755 compose_exec_ext_editor(compose);
759 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
764 g_return_val_if_fail(mimeinfo != NULL, NULL);
766 base = mimeinfo->filename ? mimeinfo->filename
767 : mimeinfo->name ? mimeinfo->name : NULL;
769 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
770 filename = g_strdup_printf("%s%smimetmp.%08x.html",
777 base = base ? base : "";
778 base = g_basename(base);
780 filename = g_strdup_printf("%s%smimetmp.%08x",
788 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
794 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
798 if (!partinfo) return NULL;
800 filename = procmime_get_file_name(partinfo);
802 if (procmime_get_part(filename, source, partinfo) < 0)
804 (_("Can't get the part of multipart message."));
809 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
817 gint boundary_len = 0;
819 glong fpos, prev_fpos;
824 g_return_if_fail(msginfo != NULL);
828 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
829 mimeinfo = procmime_scan_mime_header(fp);
830 if (!mimeinfo) break;
832 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
833 rfc2015_is_encrypted(mimeinfo)) {
834 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
836 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
837 !msginfo->plaintext_file &&
838 !msginfo->decryption_failed) {
839 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
840 if (msginfo->plaintext_file &&
841 !msginfo->decryption_failed) {
849 #else /* !USE_GPGME */
850 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
851 mimeinfo = procmime_scan_mime_header(fp);
852 #endif /* USE_GPGME */
855 if (!mimeinfo) return;
856 if (mimeinfo->mime_type == MIME_TEXT)
859 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
861 g_return_if_fail(mimeinfo != NULL);
862 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
864 if (mimeinfo->mime_type == MIME_MULTIPART) {
865 g_return_if_fail(mimeinfo->boundary != NULL);
866 g_return_if_fail(mimeinfo->sub == NULL);
868 g_return_if_fail(fp != NULL);
870 boundary = mimeinfo->boundary;
873 boundary_len = strlen(boundary);
875 /* look for first boundary */
876 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
877 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
884 if ((fpos = ftell(fp)) < 0) {
890 for (npart = 0;; npart++) {
892 gboolean eom = FALSE;
896 partinfo = procmime_scan_mime_header(fp);
897 if (!partinfo) break;
900 procmime_mimeinfo_insert(mimeinfo, partinfo);
902 procmime_mimeinfo_free(partinfo);
904 /* look for next boundary */
906 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
907 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
908 if (buf[2 + boundary_len] == '-' &&
909 buf[2 + boundary_len + 1] == '-')
915 eom = TRUE; /* broken MIME message */
918 partinfo->size = fpos - prev_fpos - strlen(buf);
923 source = procmsg_get_message_file_path(msginfo);
925 g_return_if_fail(mimeinfo != NULL);
927 if (!mimeinfo->main && mimeinfo->parent)
929 filename = mime_extract_file(source, mimeinfo);
931 compose_attach_append_with_type(compose, filename,
932 mimeinfo->content_type,
933 mimeinfo->mime_type);
938 if (mimeinfo->sub && mimeinfo->sub->children)
940 filename = mime_extract_file(source, mimeinfo->sub);
942 compose_attach_append_with_type(compose, filename,
943 mimeinfo->content_type,
944 mimeinfo->sub->mime_type);
949 if (mimeinfo->children) {
952 child = mimeinfo->children;
954 filename = mime_extract_file(source, child);
956 compose_attach_append_with_type(compose, filename,
968 procmime_mimeinfo_free_all(mimeinfo);
972 #define INSERT_FW_HEADER(var, hdr) \
973 if (msginfo->var && *msginfo->var) { \
974 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
975 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
976 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
979 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
983 /* PrefsAccount *account; */
986 g_return_val_if_fail(msginfo != NULL, NULL);
987 g_return_val_if_fail(msginfo->folder != NULL, NULL);
989 account = msginfo->folder->folder->account;
990 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
992 Xstrdup_a(to, msginfo->to, return NULL);
994 account = account_find_from_address(to);
997 if(!account && prefs_common.forward_account_autosel) {
999 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1000 extract_address(cc);
1001 account = account_find_from_address(cc);
1005 if (account == NULL) {
1006 account = cur_account;
1008 account = msginfo->folder->folder->account;
1009 if (!account) account = cur_account;
1012 g_return_val_if_fail(account != NULL, NULL);
1014 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1015 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1016 CHANGE_FLAGS(msginfo);
1018 compose = compose_create(account, COMPOSE_FORWARD);
1020 if (msginfo->subject && *msginfo->subject) {
1021 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1022 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1026 text = GTK_STEXT(compose->text);
1027 gtk_stext_freeze(text);
1032 msgfile = procmsg_get_message_file_path(msginfo);
1033 if (!is_file_exist(msgfile))
1034 g_warning(_("%s: file not exist\n"), msgfile);
1036 compose_attach_append(compose, msgfile,
1037 MIME_MESSAGE_RFC822);
1044 if (prefs_common.fw_quotemark && *prefs_common.fw_quotemark)
1045 qmark = prefs_common.fw_quotemark;
1049 quote_str = compose_quote_fmt(compose, msginfo,
1050 prefs_common.fw_quotefmt, qmark);
1051 compose_attach_parts(compose, msginfo);
1054 if (prefs_common.auto_sig)
1055 compose_insert_sig(compose);
1057 if (prefs_common.linewrap_quote)
1058 compose_wrap_line_all(compose);
1060 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1061 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1063 gtk_stext_thaw(text);
1064 #if 0 /* NEW COMPOSE GUI */
1065 if (account->protocol != A_NNTP)
1066 gtk_widget_grab_focus(compose->to_entry);
1068 gtk_widget_grab_focus(compose->newsgroups_entry);
1070 gtk_widget_grab_focus(compose->header_last->entry);
1072 if (prefs_common.auto_exteditor)
1073 compose_exec_ext_editor(compose);
1078 #undef INSERT_FW_HEADER
1080 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1087 g_return_val_if_fail(msginfo_list != NULL, NULL);
1089 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1090 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1094 if (account == NULL) {
1095 account = cur_account;
1097 account = msginfo->folder->folder->account;
1098 if (!account) account = cur_account;
1101 g_return_val_if_fail(account != NULL, NULL);
1103 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1104 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1105 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1106 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1109 compose = compose_create(account, COMPOSE_FORWARD);
1111 text = GTK_STEXT(compose->text);
1112 gtk_stext_freeze(text);
1114 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1115 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1116 if (!is_file_exist(msgfile))
1117 g_warning(_("%s: file not exist\n"), msgfile);
1119 compose_attach_append(compose, msgfile,
1120 MIME_MESSAGE_RFC822);
1124 if (prefs_common.auto_sig)
1125 compose_insert_sig(compose);
1127 if (prefs_common.linewrap_quote)
1128 compose_wrap_line_all(compose);
1130 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1131 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1133 gtk_stext_thaw(text);
1134 #if 0 /* NEW COMPOSE GUI */
1135 if (account->protocol != A_NNTP)
1136 gtk_widget_grab_focus(compose->to_entry);
1138 gtk_widget_grab_focus(compose->newsgroups_entry);
1144 void compose_reedit(MsgInfo *msginfo)
1147 PrefsAccount *account;
1150 gchar buf[BUFFSIZE];
1152 g_return_if_fail(msginfo != NULL);
1153 g_return_if_fail(msginfo->folder != NULL);
1155 account = msginfo->folder->folder->account;
1157 if(!account&& prefs_common.reedit_account_autosel) {
1158 gchar from[BUFFSIZE];
1159 if(!get_header_from_msginfo(msginfo,from,sizeof(from),"FROM:")){ /* Found a FROM header */
1160 extract_address(from);
1161 account = account_find_from_address(from);
1164 if (!account) account = cur_account;
1165 g_return_if_fail(account != NULL);
1167 compose = compose_create(account, COMPOSE_REEDIT);
1168 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1170 if (compose_parse_header(compose, msginfo) < 0) return;
1171 compose_reedit_set_entry(compose, msginfo);
1173 text = GTK_STEXT(compose->text);
1174 gtk_stext_freeze(text);
1176 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1177 g_warning(_("Can't get text part\n"));
1179 while (fgets(buf, sizeof(buf), fp) != NULL)
1180 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1183 compose_attach_parts(compose, msginfo);
1185 gtk_stext_thaw(text);
1186 gtk_widget_grab_focus(compose->text);
1188 if (prefs_common.auto_exteditor)
1189 compose_exec_ext_editor(compose);
1192 GList *compose_get_compose_list(void)
1194 return compose_list;
1197 void compose_entry_append(Compose *compose, const gchar *address,
1198 ComposeEntryType type)
1204 if (!address || *address == '\0') return;
1206 #if 0 /* NEW COMPOSE GUI */
1209 entry = GTK_ENTRY(compose->cc_entry);
1212 entry = GTK_ENTRY(compose->bcc_entry);
1214 case COMPOSE_NEWSGROUPS:
1215 entry = GTK_ENTRY(compose->newsgroups_entry);
1219 entry = GTK_ENTRY(compose->to_entry);
1223 text = gtk_entry_get_text(entry);
1225 gtk_entry_append_text(entry, ", ");
1226 gtk_entry_append_text(entry, address);
1234 header = N_("Bcc:");
1236 case COMPOSE_REPLYTO:
1237 header = N_("Reply-To:");
1239 case COMPOSE_NEWSGROUPS:
1240 header = N_("Newsgroups:");
1242 case COMPOSE_FOLLOWUPTO:
1243 header = N_( "Followup-To:");
1250 header = prefs_common.trans_hdr ? gettext(header) : header;
1252 compose_add_header_entry(compose, header, (gchar *)address);
1255 static void compose_entries_set(Compose *compose, const gchar *mailto)
1257 gchar *subject = NULL;
1265 Xstrdup_a(tmp_mailto, mailto, return);
1269 p = strchr(tmp_mailto, '?');
1276 gchar *field, *value;
1293 if (*value == '\0') continue;
1295 if (!g_strcasecmp(field, "subject")) {
1296 Xalloca(subject, strlen(value) + 1, return);
1297 decode_uri(subject, value);
1298 } else if (!g_strcasecmp(field, "cc")) {
1300 } else if (!g_strcasecmp(field, "bcc")) {
1302 } else if (!g_strcasecmp(field, "body")) {
1303 Xalloca(body, strlen(value) + 1, return);
1304 decode_uri(body, value);
1309 compose_entry_append(compose, to, COMPOSE_TO);
1311 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1313 compose_entry_append(compose, cc, COMPOSE_CC);
1315 compose_entry_append(compose, bcc, COMPOSE_BCC);
1317 gtk_stext_insert(GTK_STEXT(compose->text),
1318 NULL, NULL, NULL, body, -1);
1319 gtk_stext_insert(GTK_STEXT(compose->text),
1320 NULL, NULL, NULL, "\n", 1);
1324 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1326 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1327 {"Cc:", NULL, FALSE},
1328 {"References:", NULL, FALSE},
1329 {"Bcc:", NULL, FALSE},
1330 {"Newsgroups:", NULL, FALSE},
1331 {"Followup-To:", NULL, FALSE},
1332 {"X-Mailing-List:", NULL, FALSE},
1333 {"X-BeenThere:", NULL, FALSE},
1334 {NULL, NULL, FALSE}};
1344 H_X_MAILING_LIST = 6,
1350 g_return_val_if_fail(msginfo != NULL, -1);
1352 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1353 procheader_get_header_fields(fp, hentry);
1356 if (hentry[H_REPLY_TO].body != NULL) {
1357 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1358 compose->replyto = hentry[H_REPLY_TO].body;
1359 hentry[H_REPLY_TO].body = NULL;
1361 if (hentry[H_CC].body != NULL) {
1362 conv_unmime_header_overwrite(hentry[H_CC].body);
1363 compose->cc = hentry[H_CC].body;
1364 hentry[H_CC].body = NULL;
1366 if (hentry[H_X_MAILING_LIST].body != NULL) {
1367 /* this is good enough to parse debian-devel */
1368 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1369 g_return_val_if_fail(buf != NULL, -1 );
1370 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1371 compose->mailinglist = g_strdup(buf);
1373 g_free(hentry[H_X_MAILING_LIST].body);
1374 hentry[H_X_MAILING_LIST].body = NULL ;
1376 if (hentry[H_X_BEENTHERE].body != NULL) {
1377 /* this is good enough to parse the sylpheed-claws lists */
1378 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1379 g_return_val_if_fail(buf != NULL, -1 );
1380 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1381 compose->mailinglist = g_strdup(buf);
1383 g_free(hentry[H_X_BEENTHERE].body);
1384 hentry[H_X_BEENTHERE].body = NULL ;
1386 if (hentry[H_REFERENCES].body != NULL) {
1387 if (compose->mode == COMPOSE_REEDIT)
1388 compose->references = hentry[H_REFERENCES].body;
1390 compose->references = compose_parse_references
1391 (hentry[H_REFERENCES].body, msginfo->msgid);
1392 g_free(hentry[H_REFERENCES].body);
1394 hentry[H_REFERENCES].body = NULL;
1396 if (hentry[H_BCC].body != NULL) {
1397 if (compose->mode == COMPOSE_REEDIT) {
1398 conv_unmime_header_overwrite(hentry[H_BCC].body);
1399 compose->bcc = hentry[H_BCC].body;
1401 g_free(hentry[H_BCC].body);
1402 hentry[H_BCC].body = NULL;
1404 if (hentry[H_NEWSGROUPS].body != NULL) {
1405 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1406 hentry[H_NEWSGROUPS].body = NULL;
1408 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1409 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1410 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1411 hentry[H_FOLLOWUP_TO].body = NULL;
1414 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1415 compose->inreplyto = g_strdup(msginfo->inreplyto);
1416 else if (compose->mode != COMPOSE_REEDIT &&
1417 msginfo->msgid && *msginfo->msgid) {
1418 compose->inreplyto = g_strdup(msginfo->msgid);
1420 if (!compose->references) {
1421 if (msginfo->inreplyto && *msginfo->inreplyto)
1422 compose->references =
1423 g_strdup_printf("<%s>\n\t<%s>",
1427 compose->references =
1428 g_strconcat("<", msginfo->msgid, ">",
1436 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1438 GSList *ref_id_list, *cur;
1442 ref_id_list = references_list_append(NULL, ref);
1443 if (!ref_id_list) return NULL;
1444 if (msgid && *msgid)
1445 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1450 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1451 /* "<" + Message-ID + ">" + CR+LF+TAB */
1452 len += strlen((gchar *)cur->data) + 5;
1454 if (len > MAX_REFERENCES_LEN) {
1455 /* remove second message-ID */
1456 if (ref_id_list && ref_id_list->next &&
1457 ref_id_list->next->next) {
1458 g_free(ref_id_list->next->data);
1459 ref_id_list = g_slist_remove
1460 (ref_id_list, ref_id_list->next->data);
1462 slist_free_strings(ref_id_list);
1463 g_slist_free(ref_id_list);
1470 new_ref = g_string_new("");
1471 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1472 if (new_ref->len > 0)
1473 g_string_append(new_ref, "\n\t");
1474 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1477 slist_free_strings(ref_id_list);
1478 g_slist_free(ref_id_list);
1480 new_ref_str = new_ref->str;
1481 g_string_free(new_ref, FALSE);
1486 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1487 const gchar *fmt, const gchar *qmark)
1489 GtkSText *text = GTK_STEXT(compose->text);
1490 gchar *quote_str = NULL;
1495 if (qmark != NULL) {
1496 quote_fmt_init(msginfo, NULL);
1497 quote_fmt_scan_string(qmark);
1500 buf = quote_fmt_get_buffer();
1502 alertpanel_error(_("Quote mark format error."));
1504 Xstrdup_a(quote_str, buf, return NULL)
1507 quote_fmt_init(msginfo, quote_str);
1508 quote_fmt_scan_string(fmt);
1511 buf = quote_fmt_get_buffer();
1513 alertpanel_error(_("Message reply/forward format error."));
1517 gtk_stext_freeze(text);
1518 gtk_stext_set_point(text, 0);
1519 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
1521 for (p = buf; *p != '\0'; ) {
1522 lastp = strchr(p, '\n');
1523 len = lastp ? lastp - p + 1 : -1;
1524 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1531 gtk_stext_thaw(text);
1536 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1537 gboolean to_all, gboolean ignore_replyto,
1538 gboolean followup_and_reply_to)
1543 GHashTable *to_table;
1545 g_return_if_fail(compose->account != NULL);
1546 g_return_if_fail(msginfo != NULL);
1548 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1549 compose_entry_append(compose,
1550 ((compose->mailinglist && !ignore_replyto)
1551 ? compose->mailinglist
1552 : (compose->replyto && !ignore_replyto)
1554 : msginfo->from ? msginfo->from : ""),
1556 if (compose->account->protocol == A_NNTP) {
1558 compose_entry_append
1559 (compose, msginfo->from ? msginfo->from : "",
1562 compose_entry_append
1564 compose->followup_to ? compose->followup_to
1565 : compose->newsgroups ? compose->newsgroups
1567 COMPOSE_NEWSGROUPS);
1570 if (msginfo->subject && *msginfo->subject) {
1571 gchar *buf, *buf2, *p;
1573 buf = g_strdup(msginfo->subject);
1574 while (!strncasecmp(buf, "Re:", 3)) {
1576 while (isspace(*p)) p++;
1577 memmove(buf, p, strlen(p) + 1);
1580 buf2 = g_strdup_printf("Re: %s", buf);
1581 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1585 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1587 if (!to_all || compose->account->protocol == A_NNTP) return;
1589 from = g_strdup(compose->replyto ? compose->replyto :
1590 msginfo->from ? msginfo->from : "");
1591 extract_address(from);
1593 cc_list = address_list_append(NULL, msginfo->to);
1594 cc_list = address_list_append(cc_list, compose->cc);
1596 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1597 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1598 if (compose->account)
1599 g_hash_table_insert(to_table, compose->account->address,
1600 GINT_TO_POINTER(1));
1602 /* remove address on To: and that of current account */
1603 for (cur = cc_list; cur != NULL; ) {
1604 GSList *next = cur->next;
1606 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1607 cc_list = g_slist_remove(cc_list, cur->data);
1609 g_hash_table_insert(to_table, cur->data, cur);
1613 g_hash_table_destroy(to_table);
1617 for (cur = cc_list; cur != NULL; cur = cur->next)
1618 compose_entry_append(compose, (gchar *)cur->data,
1620 slist_free_strings(cc_list);
1621 g_slist_free(cc_list);
1625 #define SET_ENTRY(entry, str) \
1628 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1631 #define SET_ADDRESS(type, str) \
1634 compose_entry_append(compose, str, type); \
1637 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1639 g_return_if_fail(msginfo != NULL);
1641 SET_ENTRY(subject_entry, msginfo->subject);
1642 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1643 SET_ADDRESS(COMPOSE_CC, compose->cc);
1644 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1645 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1647 #if 0 /* NEW COMPOSE GUI */
1649 GtkItemFactory *ifactory;
1650 GtkWidget *menuitem;
1652 ifactory = gtk_item_factory_from_widget(compose->menubar);
1653 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1654 gtk_check_menu_item_set_active
1655 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1657 if (compose->replyto) {
1658 GtkItemFactory *ifactory;
1659 GtkWidget *menuitem;
1661 ifactory = gtk_item_factory_from_widget(compose->menubar);
1662 menuitem = gtk_item_factory_get_item
1663 (ifactory, "/Message/Reply to");
1664 gtk_check_menu_item_set_active
1665 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1673 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1680 size_t buf_len = 128;
1682 if (strlen(sigfile) < 2)
1685 sigprg = popen(sigfile+1, "r");
1688 buf = g_malloc(buf_len);
1691 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1692 "Unable to insert signature (malloc failed)\n", -1);
1698 while (!feof(sigprg)) {
1699 bzero(buf, buf_len);
1700 fread(buf, buf_len-1, 1, sigprg);
1701 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1709 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1710 "Can't exec file: ", -1);
1711 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1716 static void compose_insert_sig(Compose *compose)
1720 if (compose->account && compose->account->sig_path)
1721 sigfile = g_strdup(compose->account->sig_path);
1723 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1724 DEFAULT_SIGNATURE, NULL);
1727 if (!is_file_or_fifo_exist(sigfile) & (sigfile[0] != '|')) {
1732 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1733 if (prefs_common.sig_sep) {
1734 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1735 prefs_common.sig_sep, -1);
1736 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1740 if (sigfile[0] == '|')
1742 compose_exec_sig(compose, sigfile);
1746 compose_insert_file(compose, sigfile);
1751 static void compose_insert_file(Compose *compose, const gchar *file)
1753 GtkSText *text = GTK_STEXT(compose->text);
1754 gchar buf[BUFFSIZE];
1758 g_return_if_fail(file != NULL);
1760 if ((fp = fopen(file, "r")) == NULL) {
1761 FILE_OP_ERROR(file, "fopen");
1765 gtk_stext_freeze(text);
1767 while (fgets(buf, sizeof(buf), fp) != NULL) {
1768 /* Strip <CR> if DOS/Windoze file, replace <CR> with <LF> if MAC file */
1770 if (len > 1 && buf[len - 2] == '\r' && buf[len - 1] == '\n') {
1771 buf[len - 2] = '\n';
1772 buf[len - 1] = '\0';
1775 if (buf[len] == '\r')
1779 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1782 gtk_stext_thaw(text);
1787 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1788 ContentType cnttype)
1790 gchar *text[N_ATTACH_COLS];
1793 text[COL_MIMETYPE] = ainfo->content_type;
1794 text[COL_SIZE] = to_human_readable(ainfo->size);
1795 text[COL_NAME] = ainfo->name;
1797 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1798 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1800 if (cnttype != MIME_MESSAGE_RFC822)
1801 compose_changed_cb(NULL, compose);
1804 static void compose_attach_append_with_type(Compose *compose,
1807 ContentType cnttype)
1812 if (!is_file_exist(file)) {
1813 g_warning(_("File %s doesn't exist\n"), file);
1816 if ((size = get_file_size(file)) < 0) {
1817 g_warning(_("Can't get file size of %s\n"), file);
1821 alertpanel_notice(_("File %s is empty\n"), file);
1824 #if 0 /* NEW COMPOSE GUI */
1825 if (!compose->use_attach) {
1826 GtkItemFactory *ifactory;
1827 GtkWidget *menuitem;
1829 ifactory = gtk_item_factory_from_widget(compose->menubar);
1830 menuitem = gtk_item_factory_get_item(ifactory,
1832 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1836 ainfo = g_new0(AttachInfo, 1);
1837 ainfo->file = g_strdup(file);
1839 if (cnttype == MIME_MESSAGE_RFC822) {
1840 ainfo->encoding = ENC_7BIT;
1841 ainfo->name = g_strdup_printf(_("Message: %s"),
1844 ainfo->encoding = ENC_BASE64;
1845 ainfo->name = g_strdup(g_basename(file));
1848 ainfo->content_type = g_strdup(type);
1851 compose_attach_info(compose, ainfo, cnttype);
1854 static void compose_attach_append(Compose *compose, const gchar *file,
1855 ContentType cnttype)
1858 gchar *text[N_ATTACH_COLS];
1862 if (!is_file_exist(file)) {
1863 g_warning(_("File %s doesn't exist\n"), file);
1866 if ((size = get_file_size(file)) < 0) {
1867 g_warning(_("Can't get file size of %s\n"), file);
1871 alertpanel_notice(_("File %s is empty\n"), file);
1874 #if 0 /* NEW COMPOSE GUI */
1875 if (!compose->use_attach) {
1876 GtkItemFactory *ifactory;
1877 GtkWidget *menuitem;
1879 ifactory = gtk_item_factory_from_widget(compose->menubar);
1880 menuitem = gtk_item_factory_get_item(ifactory,
1882 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1886 ainfo = g_new0(AttachInfo, 1);
1887 ainfo->file = g_strdup(file);
1889 if (cnttype == MIME_MESSAGE_RFC822) {
1890 ainfo->content_type = g_strdup("message/rfc822");
1891 ainfo->encoding = ENC_7BIT;
1892 ainfo->name = g_strdup_printf(_("Message: %s"),
1895 ainfo->content_type = procmime_get_mime_type(file);
1896 if (!ainfo->content_type)
1897 ainfo->content_type =
1898 g_strdup("application/octet-stream");
1899 ainfo->encoding = ENC_BASE64;
1900 ainfo->name = g_strdup(g_basename(file));
1904 compose_attach_info(compose, ainfo, cnttype);
1907 static void compose_wrap_line(Compose *compose)
1909 GtkSText *text = GTK_STEXT(compose->text);
1910 gint ch_len, last_ch_len;
1911 gchar cbuf[MB_LEN_MAX], last_ch;
1915 gint p_start, p_end;
1916 gint line_pos, cur_pos;
1917 gint line_len, cur_len;
1919 #define GET_STEXT(pos) \
1920 if (text->use_wchar) \
1921 ch_len = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
1923 cbuf[0] = GTK_STEXT_INDEX(text, (pos)); \
1927 gtk_stext_freeze(text);
1929 text_len = gtk_stext_get_length(text);
1931 /* check to see if the point is on the paragraph mark (empty line). */
1932 cur_pos = gtk_stext_get_point(text);
1934 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
1936 goto compose_end; /* on the paragraph mark */
1937 GET_STEXT(cur_pos - 1);
1938 if (ch_len == 1 && *cbuf == '\n')
1939 goto compose_end; /* on the paragraph mark */
1942 /* find paragraph start. */
1943 line_end = quoted = 0;
1944 for (p_start = cur_pos; p_start >= 0; --p_start) {
1946 if (ch_len == 1 && *cbuf == '\n') {
1948 goto compose_end; /* quoted part */
1955 if (ch_len == 1 && strchr(">:#", *cbuf))
1957 else if (ch_len != 1 || !isspace(*cbuf))
1966 /* find paragraph end. */
1968 for (p_end = cur_pos; p_end < text_len; p_end++) {
1970 if (ch_len == 1 && *cbuf == '\n') {
1977 if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
1978 goto compose_end; /* quoted part */
1983 if (p_end >= text_len)
1986 if (p_start >= p_end)
1989 line_len = cur_len = 0;
1993 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2003 if (ch_len == 1 && isspace(*cbuf))
2006 if (ch_len == 1 && *cbuf == '\n') {
2008 if (last_ch_len == 1 && !isspace(last_ch)) {
2009 if (cur_pos + 1 < p_end) {
2010 GET_STEXT(cur_pos + 1);
2011 if (ch_len == 1 && !isspace(*cbuf))
2015 gtk_stext_set_point(text, cur_pos + 1);
2016 gtk_stext_backward_delete(text, 1);
2018 gtk_stext_set_point(text, cur_pos);
2019 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2029 last_ch_len = ch_len;
2033 line_pos = cur_pos + 1;
2034 line_len = cur_len + ch_len;
2037 if (cur_len + ch_len > prefs_common.linewrap_len &&
2041 GET_STEXT(line_pos - 1);
2042 if (ch_len == 1 && isspace(*cbuf)) {
2043 gtk_stext_set_point(text, line_pos);
2044 gtk_stext_backward_delete(text, 1);
2053 gtk_stext_set_point(text, line_pos);
2054 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2058 cur_len = cur_len - line_len + ch_len;
2064 line_pos = cur_pos + 1;
2065 line_len = cur_len + ch_len;
2071 gtk_stext_thaw(text);
2076 /* return indent length */
2077 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2079 gint indent_len = 0;
2081 gchar cbuf[MB_LEN_MAX];
2083 for (i = start_pos; i < text_len; i++) {
2084 if (text->use_wchar)
2086 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, i));
2088 cbuf[0] = GTK_STEXT_INDEX(text, i);
2093 /* allow space, tab, > or | */
2094 if (cbuf[0] != ' ' && cbuf[0] != '\t' &&
2095 cbuf[0] != '>' && cbuf[0] != '|')
2103 /* insert quotation string when line was wrapped */
2104 static guint ins_quote(GtkSText *text, guint quote_len, guint indent_len,
2105 guint prev_line_pos, guint text_len,
2112 for (i = 0; i < indent_len; i++) {
2113 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2114 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2116 ins_len = indent_len;
2119 gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
2120 ins_len = quote_len;
2128 /* Darko: used when I debug wrapping */
2129 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2134 printf("%d [", pos);
2135 for (i = pos; i < tlen; i++) {
2136 ch = GTK_STEXT_INDEX(text, i);
2137 if (breakoncr && ch == '\n')
2145 static void compose_wrap_line_all(Compose *compose)
2147 GtkSText *text = GTK_STEXT(compose->text);
2149 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2150 gint line_len = 0, cur_len = 0;
2152 gint is_new_line = 1, do_delete = 0;
2153 guint qlen = 0, i_len = 0;
2154 guint linewrap_quote = prefs_common.linewrap_quote;
2155 guint linewrap_len = prefs_common.linewrap_len;
2156 gchar *qfmt = prefs_common.quotemark;
2157 gchar cbuf[MB_LEN_MAX];
2159 gtk_stext_freeze(text);
2161 /* make text buffer contiguous */
2162 /* gtk_stext_compact_buffer(text); */
2164 tlen = gtk_stext_get_length(text);
2166 for (; cur_pos < tlen; cur_pos++) {
2167 /* mark position of new line - needed for quotation wrap */
2168 if (linewrap_quote && is_new_line) {
2169 qlen = gtkut_text_str_compare
2170 (text, cur_pos, tlen, qfmt);
2173 i_len = get_indent_length(text, cur_pos, tlen);
2178 printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
2179 dump_text(text, p_pos, tlen, 1);
2183 /* get character(s) at current position */
2184 if (text->use_wchar)
2186 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2188 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
2192 /* fix line length for tabs */
2193 if (ch_len == 1 && *cbuf == '\t') {
2194 guint tab_width = text->default_tab_width;
2195 guint tab_offset = line_len % tab_width;
2198 printf("found tab at pos=%d line_len=%d ", cur_pos,
2202 line_len += tab_width - tab_offset - 1;
2206 printf("new_len=%d\n", line_len);
2210 /* we have encountered line break */
2211 if (ch_len == 1 && *cbuf == '\n') {
2214 gchar cb[MB_CUR_MAX];
2217 printf("found CR at %d next line is ", cur_pos);
2218 dump_text(text, cur_pos + 1, tlen, 1);
2220 /* if it's just quotation + newline skip it */
2221 if (i_len && (cur_pos + 1 < tlen)) {
2222 /* check if text at new line matches indent */
2223 ilen = gtkut_text_str_compare_n
2224 (text, cur_pos + 1, p_pos, i_len, tlen);
2225 if (cur_pos + ilen < tlen) {
2226 if (text->use_wchar)
2227 clen = wctomb(cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos + ilen + 1));
2229 cb[0] = GTK_STEXT_INDEX(text,
2230 cur_pos + ilen + 1);
2233 /* no need to join the lines */
2234 if ((clen == 1) && (cb[0] == '\n'))
2238 /* if it's just newline skip it */
2239 else if (do_delete && (cur_pos + 1 < tlen)) {
2240 if (text->use_wchar)
2241 clen = wctomb(cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos + 1));
2243 cb[0] = GTK_STEXT_INDEX(text,
2247 /* no need to join the lines */
2248 if ((clen == 1) && (cb[0] == '\n'))
2253 printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
2254 qlen, line_len, linewrap_len, do_delete);
2256 /* should we delete to perform smart wrapping */
2257 if (line_len < linewrap_len && do_delete) {
2258 /* get rid of newline */
2259 gtk_stext_set_point(text, cur_pos);
2260 gtk_stext_forward_delete(text, 1);
2263 /* if text starts with quote fmt or with
2264 indent string, delete them */
2266 ilen = gtkut_text_str_compare_n
2267 (text, cur_pos, p_pos, i_len,
2270 gtk_stext_forward_delete(text,
2275 if (gtkut_text_str_compare
2276 (text, cur_pos, tlen, qfmt)) {
2277 gtk_stext_forward_delete
2283 if (text->use_wchar)
2285 (cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2287 cb[0] = GTK_STEXT_INDEX(text, cur_pos);
2291 /* insert space if it's alphanumeric */
2292 if ((cur_pos != line_pos) &&
2293 ((clen > 1) || isalnum(cb[0]))) {
2294 gtk_stext_insert(text, NULL, NULL,
2296 /* gtk_text_compact_buffer(text); */
2300 /* and start over with current line */
2301 cur_pos = p_pos - 1;
2303 line_len = cur_len = 0;
2308 printf("after delete l_pos=");
2309 dump_text(text, line_pos, tlen, 1);
2314 /* mark new line beginning */
2315 line_pos = cur_pos + 1;
2316 line_len = cur_len = 0;
2328 /* possible line break */
2329 if (ch_len == 1 && isspace(*cbuf)) {
2330 line_pos = cur_pos + 1;
2331 line_len = cur_len + ch_len;
2334 /* are we over wrapping length set in preferences ? */
2335 if (cur_len + ch_len > linewrap_len) {
2339 printf("should wrap cur_pos=%d ", cur_pos);
2340 dump_text(text, p_pos, tlen, 1);
2341 dump_text(text, line_pos, tlen, 1);
2343 /* force wrapping if it is one long word but not URL */
2344 if (p_pos + i_len == line_pos)
2345 if (!gtkut_text_is_uri_string
2346 (text, line_pos, tlen))
2347 line_pos = cur_pos - 1;
2349 printf("new line_pos=%d\n", line_pos);
2352 /* if next character is space delete it */
2353 if (text->use_wchar)
2354 clen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
2356 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
2359 if (clen == 1 && isspace(*cbuf)) {
2360 if (p_pos + i_len != line_pos ||
2361 !gtkut_text_is_uri_string
2362 (text, line_pos, tlen)) {
2363 gtk_stext_set_point(text, line_pos);
2364 gtk_stext_backward_delete(text, 1);
2373 /* if it is URL at beginning of line don't wrap */
2374 if (p_pos + i_len == line_pos &&
2375 gtkut_text_is_uri_string(text, line_pos, tlen)) {
2377 printf("found URL at ");
2378 dump_text(text, line_pos, tlen, 1);
2384 gtk_stext_set_point(text, line_pos);
2385 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2386 /* gtk_stext_compact_buffer(text); */
2389 /* for loop will increase it */
2390 cur_pos = line_pos - 1;
2391 /* start over with current line */
2397 printf("after CR insert ");
2398 dump_text(text, line_pos, tlen, 1);
2399 dump_text(text, cur_pos, tlen, 1);
2402 /* should we insert quotation ? */
2403 if (linewrap_quote && qlen) {
2404 /* only if line is not already quoted */
2405 if (!gtkut_text_str_compare
2406 (text, line_pos, tlen, qfmt)) {
2409 if (line_pos - p_pos > i_len) {
2414 /* gtk_stext_compact_buffer(text); */
2418 printf("after quote insert ");
2419 dump_text(text, line_pos, tlen, 1);
2427 line_pos = cur_pos + 1;
2428 line_len = cur_len + ch_len;
2430 /* advance to next character in buffer */
2434 gtk_stext_thaw(text);
2438 static void compose_wrap_line_all(Compose *compose)
2440 GtkText *text = GTK_STEXT(compose->text);
2442 guint line_pos = 0, cur_pos = 0;
2443 gint line_len = 0, cur_len = 0;
2445 gchar cbuf[MB_LEN_MAX];
2447 gtk_stext_freeze(text);
2449 text_len = gtk_stext_get_length(text);
2451 for (; cur_pos < text_len; cur_pos++) {
2452 if (text->use_wchar)
2454 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2456 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
2460 if (ch_len == 1 && *cbuf == '\n') {
2461 line_pos = cur_pos + 1;
2462 line_len = cur_len = 0;
2471 if (ch_len == 1 && isspace(*cbuf)) {
2472 line_pos = cur_pos + 1;
2473 line_len = cur_len + ch_len;
2476 if (cur_len + ch_len > prefs_common.linewrap_len &&
2480 if (text->use_wchar)
2481 tlen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
2483 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
2486 if (tlen == 1 && isspace(*cbuf)) {
2487 gtk_stext_set_point(text, line_pos);
2488 gtk_stext_backward_delete(text, 1);
2496 gtk_stext_set_point(text, line_pos);
2497 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2501 cur_len = cur_len - line_len + ch_len;
2507 line_pos = cur_pos + 1;
2508 line_len = cur_len + ch_len;
2513 gtk_stext_thaw(text);
2517 static void compose_set_title(Compose *compose)
2522 edited = compose->modified ? _(" [Edited]") : "";
2523 if (compose->account && compose->account->address)
2524 str = g_strdup_printf(_("%s - Compose message%s"),
2525 compose->account->address, edited);
2527 str = g_strdup_printf(_("Compose message%s"), edited);
2528 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2533 * compose_current_mail_account:
2535 * Find a current mail account (the currently selected account, or the
2536 * default account, if a news account is currently selected). If a
2537 * mail account cannot be found, display an error message.
2539 * Return value: Mail account, or NULL if not found.
2541 static PrefsAccount *
2542 compose_current_mail_account(void)
2546 if (cur_account && cur_account->protocol != A_NNTP)
2549 ac = account_get_default();
2550 if (!ac || ac->protocol == A_NNTP) {
2551 alertpanel_error(_("Account for sending mail is not specified.\n"
2552 "Please select a mail account before sending."));
2559 gboolean compose_check_for_valid_recipient(Compose *compose) {
2560 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2561 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2562 gboolean recipient_found = FALSE;
2566 /* free to and newsgroup list */
2567 slist_free_strings(compose->to_list);
2568 g_slist_free(compose->to_list);
2569 compose->to_list = NULL;
2571 slist_free_strings(compose->newsgroup_list);
2572 g_slist_free(compose->newsgroup_list);
2573 compose->newsgroup_list = NULL;
2575 /* search header entries for to and newsgroup entries */
2576 for(list = compose->header_list; list; list = list->next) {
2579 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2580 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2582 if(entry[0] != '\0') {
2583 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2584 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2585 compose->to_list = address_list_append(compose->to_list, entry);
2586 recipient_found = TRUE;
2589 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2590 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2591 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2592 recipient_found = TRUE;
2598 return recipient_found;
2601 gint compose_send(Compose *compose)
2607 val = compose_queue(compose, &msgnum, &folder);
2609 alertpanel_error(_("Could not queue message for sending"));
2613 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2615 folder_item_remove_msg(folder, msgnum);
2616 folderview_update_item(folder, TRUE);
2622 #if 0 /* compose restructure */
2623 gint compose_send(Compose *compose)
2625 gchar tmp[MAXPATHLEN + 1];
2627 static gboolean lock = FALSE;
2631 g_return_val_if_fail(compose->account != NULL, -1);
2632 g_return_val_if_fail(compose->orig_account != NULL, -1);
2636 if(!compose_check_for_valid_recipient(compose)) {
2637 alertpanel_error(_("Recipient is not specified."));
2642 /* write to temporary file */
2643 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2644 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2646 if (prefs_common.linewrap_at_send)
2647 compose_wrap_line_all(compose);
2649 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2654 if (!compose->to_list && !compose->newsgroup_list) {
2655 g_warning(_("can't get recipient list."));
2661 if (compose->to_list) {
2664 #if 0 /* NEW COMPOSE GUI */
2665 if (compose->account->protocol != A_NNTP)
2666 ac = compose->account;
2667 else if (compose->orig_account->protocol != A_NNTP)
2668 ac = compose->orig_account;
2669 else if (cur_account && cur_account->protocol != A_NNTP)
2672 ac = compose_current_mail_account();
2680 ac = compose->account;
2682 ok = send_message(tmp, ac, compose->to_list);
2683 statusbar_pop_all();
2686 if (ok == 0 && compose->newsgroup_list) {
2689 if (compose->account->protocol == A_NNTP)
2690 folder = FOLDER(compose->account->folder);
2692 folder = FOLDER(compose->orig_account->folder);
2694 ok = news_post(folder, tmp);
2696 alertpanel_error(_("Error occurred while posting the message to %s ."),
2697 compose->account->nntp_server);
2704 /* queue message if failed to send */
2706 if (prefs_common.queue_msg) {
2711 _("Error occurred while sending the message.\n"
2712 "Put this message into queue folder?"),
2713 _("OK"), _("Cancel"), NULL);
2714 if (G_ALERTDEFAULT == val) {
2715 ok = compose_queue(compose, tmp);
2717 alertpanel_error(_("Can't queue the message."));
2720 alertpanel_error(_("Error occurred while sending the message."));
2722 if (compose->mode == COMPOSE_REEDIT) {
2723 compose_remove_reedit_target(compose);
2724 if (compose->targetinfo)
2725 folderview_update_item
2726 (compose->targetinfo->folder, TRUE);
2730 /* save message to outbox */
2731 if (ok == 0 && prefs_common.savemsg) {
2732 if (compose_save_to_outbox(compose, tmp) < 0)
2734 (_("Can't save the message to outbox."));
2743 static gboolean compose_use_attach(Compose *compose) {
2744 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2747 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2750 gchar buf[BUFFSIZE];
2752 gboolean first_address;
2754 ComposeHeaderEntry *headerentry;
2755 gchar *headerentryname;
2756 gchar *header_w_colon;
2760 debug_print(_("Writing bounce header\n"));
2762 header_w_colon = g_strconcat("To:", NULL);
2763 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2764 header_w_colon = g_strconcat("Cc:", NULL);
2765 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2767 first_address = TRUE;
2768 for(list = compose->header_list; list; list = list->next) {
2769 headerentry = ((ComposeHeaderEntry *)list->data);
2770 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2772 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2773 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2774 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2775 Xstrdup_a(str, str, return -1);
2777 if(str[0] != '\0') {
2778 compose_convert_header
2779 (buf, sizeof(buf), str,
2780 strlen("Resent-To") + 2);
2782 fprintf(fp, "Resent-To: ");
2783 first_address = FALSE;
2787 fprintf(fp, "%s", buf);
2791 /* if(!first_address) { */
2798 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2800 gchar buf[BUFFSIZE];
2802 /* struct utsname utsbuf; */
2804 g_return_val_if_fail(fp != NULL, -1);
2805 g_return_val_if_fail(compose->account != NULL, -1);
2806 g_return_val_if_fail(compose->account->address != NULL, -1);
2809 get_rfc822_date(buf, sizeof(buf));
2810 fprintf(fp, "Resent-Date: %s\n", buf);
2813 if (compose->account->name && *compose->account->name) {
2814 compose_convert_header
2815 (buf, sizeof(buf), compose->account->name,
2817 fprintf(fp, "Resent-From: %s <%s>\n",
2818 buf, compose->account->address);
2820 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2823 compose_bounce_write_headers_from_headerlist(compose, fp);
2825 /* separator between header and body */
2831 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2836 gchar buf[BUFFSIZE];
2838 if ((fp = fopen(compose->bounce_filename, "r")) == NULL) {
2839 FILE_OP_ERROR(file, "fopen");
2843 if ((fdest = fopen(file, "w")) == NULL) {
2844 FILE_OP_ERROR(file, "fopen");
2849 /* chmod for security */
2850 if (change_file_mode_rw(fdest, file) < 0) {
2851 FILE_OP_ERROR(file, "chmod");
2852 g_warning(_("can't change file mode\n"));
2855 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2856 /* should filter returnpath, delivered-to */
2857 if ((g_strncasecmp(buf, "Return-Path:",
2858 strlen("Return-Path:")) == 0)
2859 || (g_strncasecmp(buf, "Delivered-To:",
2860 strlen("Delivered-To:")) == 0))
2862 if (fputs(buf, fdest) == -1)
2864 if (fputs("\n", fdest) == -1)
2868 compose_bounce_write_headers(compose, fdest);
2870 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
2871 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
2886 static gint compose_write_to_file(Compose *compose, const gchar *file,
2893 const gchar *out_codeset;
2894 EncodingType encoding;
2896 if ((fp = fopen(file, "w")) == NULL) {
2897 FILE_OP_ERROR(file, "fopen");
2901 /* chmod for security */
2902 if (change_file_mode_rw(fp, file) < 0) {
2903 FILE_OP_ERROR(file, "chmod");
2904 g_warning(_("can't change file mode\n"));
2907 /* get all composed text */
2908 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2909 len = strlen(chars);
2910 if (is_ascii_str(chars)) {
2911 buf = g_strdup(chars);
2912 out_codeset = CS_US_ASCII;
2913 encoding = ENC_7BIT;
2915 const gchar *src_codeset;
2917 out_codeset = conv_get_outgoing_charset_str();
2918 if (!strcasecmp(out_codeset, CS_US_ASCII))
2919 out_codeset = CS_ISO_8859_1;
2920 encoding = procmime_get_encoding_for_charset(out_codeset);
2922 src_codeset = conv_get_current_charset_str();
2923 /* if current encoding is US-ASCII, set it the same as
2924 outgoing one to prevent code conversion failure */
2925 if (!strcasecmp(src_codeset, CS_US_ASCII))
2926 src_codeset = out_codeset;
2928 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
2929 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
2931 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
2936 alertpanel_error(_("Can't convert the codeset of the message."));
2943 if (compose_write_headers
2944 (compose, fp, out_codeset, encoding, is_draft) < 0) {
2945 g_warning(_("can't write headers\n"));
2952 if (compose_use_attach(compose)) {
2954 /* This prolog message is ignored by mime software and
2955 * because it would make our signing/encryption task
2956 * tougher, we don't emit it in that case */
2957 if (!compose->use_signing && !compose->use_encryption)
2959 fputs("This is a multi-part message in MIME format.\n", fp);
2961 fprintf(fp, "\n--%s\n", compose->boundary);
2962 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
2964 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2965 procmime_get_encoding_str(encoding));
2971 if (encoding == ENC_BASE64) {
2972 gchar outbuf[B64_BUFFSIZE];
2975 for (i = 0; i < len; i += B64_LINE_SIZE) {
2976 l = MIN(B64_LINE_SIZE, len - i);
2977 to64frombits(outbuf, buf + i, l);
2981 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
2982 FILE_OP_ERROR(file, "fwrite");
2990 if (compose_use_attach(compose))
2991 compose_write_attach(compose, fp);
2993 if (fclose(fp) == EOF) {
2994 FILE_OP_ERROR(file, "fclose");
3000 if (compose->use_signing) {
3001 if (rfc2015_sign(file, compose->account) < 0) {
3006 if (compose->use_encryption) {
3007 if (rfc2015_encrypt(file, compose->to_list) < 0) {
3012 #endif /* USE_GPGME */
3017 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3023 if ((fp = fopen(file, "w")) == NULL) {
3024 FILE_OP_ERROR(file, "fopen");
3028 /* chmod for security */
3029 if (change_file_mode_rw(fp, file) < 0) {
3030 FILE_OP_ERROR(file, "chmod");
3031 g_warning(_("can't change file mode\n"));
3034 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3037 len = strlen(chars);
3038 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3039 FILE_OP_ERROR(file, "fwrite");
3048 if (fclose(fp) == EOF) {
3049 FILE_OP_ERROR(file, "fclose");
3056 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
3063 debug_print(_("saving sent message...\n"));
3065 outbox = folder_get_default_outbox();
3066 path = folder_item_get_path(outbox);
3067 if (!is_dir_exist(path))
3068 make_dir_hier(path);
3070 folder_item_scan(outbox);
3071 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
3073 g_warning(_("can't save message\n"));
3077 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
3078 g_warning(_("can't open mark file\n"));
3082 newmsginfo.msgnum = num;
3083 newmsginfo.flags.perm_flags = 0;
3084 newmsginfo.flags.tmp_flags = 0;
3085 procmsg_write_flags(&newmsginfo, fp);
3093 static gint compose_remove_reedit_target(Compose *compose)
3096 MsgInfo *msginfo = compose->targetinfo;
3098 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3099 if (!msginfo) return -1;
3101 item = msginfo->folder;
3102 g_return_val_if_fail(item != NULL, -1);
3104 folder_item_scan(item);
3105 if (procmsg_msg_exist(msginfo) &&
3106 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3107 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3108 g_warning(_("can't remove the old message\n"));
3117 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3120 gchar *tmp, *tmp2, *queue_path;
3123 gchar buf[BUFFSIZE];
3125 static gboolean lock = FALSE;
3126 PrefsAccount *mailac = NULL, *newsac = NULL;
3128 debug_print(_("queueing message...\n"));
3129 g_return_val_if_fail(compose->account != NULL, -1);
3130 g_return_val_if_fail(compose->orig_account != NULL, -1);
3134 if(!compose_check_for_valid_recipient(compose)) {
3135 alertpanel_error(_("Recipient is not specified."));
3140 if (!compose->to_list && !compose->newsgroup_list) {
3141 g_warning(_("can't get recipient list."));
3146 if(compose->to_list) {
3147 if (compose->account->protocol != A_NNTP)
3148 mailac = compose->account;
3149 else if (compose->orig_account->protocol != A_NNTP)
3150 mailac = compose->orig_account;
3151 else if (cur_account && cur_account->protocol != A_NNTP)
3152 mailac = cur_account;
3153 else if (!(mailac = compose_current_mail_account())) {
3155 alertpanel_error(_("No account for sending mails available!"));
3160 if(compose->newsgroup_list) {
3161 if (compose->account->protocol == A_NNTP)
3162 newsac = compose->account;
3163 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3165 alertpanel_error(_("No account for posting news available!"));
3170 if (prefs_common.linewrap_at_send)
3171 compose_wrap_line_all(compose);
3173 /* write to temporary file */
3174 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3175 G_DIR_SEPARATOR, (gint)compose);
3177 if (compose->bounce_filename != NULL) {
3178 if (compose_bounce_write_to_file(compose, tmp2) < 0) {
3185 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3192 /* add queue header */
3193 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3194 G_DIR_SEPARATOR, (gint)compose);
3195 if ((fp = fopen(tmp, "w")) == NULL) {
3196 FILE_OP_ERROR(tmp, "fopen");
3200 if ((src_fp = fopen(tmp2, "r")) == NULL) {
3201 FILE_OP_ERROR(tmp2, "fopen");
3209 if (change_file_mode_rw(fp, tmp) < 0) {
3210 FILE_OP_ERROR(tmp, "chmod");
3211 g_warning(_("can't change file mode\n"));
3214 /* queueing variables */
3215 fprintf(fp, "AF:\n");
3216 fprintf(fp, "NF:0\n");
3217 fprintf(fp, "PS:10\n");
3218 fprintf(fp, "SRH:1\n");
3219 fprintf(fp, "SFN:\n");
3220 fprintf(fp, "DSR:\n");
3222 fprintf(fp, "MID:<%s>\n", compose->msgid);
3224 fprintf(fp, "MID:\n");
3225 fprintf(fp, "CFG:\n");
3226 fprintf(fp, "PT:0\n");
3227 fprintf(fp, "S:%s\n", compose->account->address);
3228 fprintf(fp, "RQ:\n");
3230 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3232 fprintf(fp, "SSV:\n");
3234 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3236 fprintf(fp, "NSV:\n");
3237 fprintf(fp, "SSH:\n");
3238 /* write recepient list */
3240 if(compose->to_list) {
3241 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3242 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3243 fprintf(fp, ",<%s>", (gchar *)cur->data);
3246 /* write newsgroup list */
3248 if(compose->newsgroup_list) {
3249 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3250 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3251 fprintf(fp, ",%s", (gchar *)cur->data);
3254 /* Sylpheed account IDs */
3256 fprintf(fp, "MAID:%d\n", mailac->account_id);
3259 fprintf(fp, "NAID:%d\n", newsac->account_id);
3263 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3264 if (fputs(buf, fp) == EOF) {
3265 FILE_OP_ERROR(tmp, "fputs");
3276 if (fclose(fp) == EOF) {
3277 FILE_OP_ERROR(tmp, "fclose");
3286 queue = folder_get_default_queue();
3288 folder_item_scan(queue);
3289 queue_path = folder_item_get_path(queue);
3290 if (!is_dir_exist(queue_path))
3291 make_dir_hier(queue_path);
3292 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3293 g_warning(_("can't queue the message\n"));
3304 if (compose->mode == COMPOSE_REEDIT) {
3305 compose_remove_reedit_target(compose);
3306 if (compose->targetinfo &&
3307 compose->targetinfo->folder != queue)
3308 folderview_update_item
3309 (compose->targetinfo->folder, TRUE);
3312 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
3313 g_warning(_("can't open mark file\n"));
3317 newmsginfo.msgnum = num;
3318 newmsginfo.flags.perm_flags = 0;
3319 newmsginfo.flags.tmp_flags = 0;
3320 procmsg_write_flags(&newmsginfo, fp);
3325 folder_item_scan(queue);
3326 folderview_update_item(queue, TRUE);
3328 if((msgnum != NULL) && (item != NULL)) {
3336 static void compose_write_attach(Compose *compose, FILE *fp)
3339 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3342 gchar filename[BUFFSIZE];
3345 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3347 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
3348 g_warning(_("Can't open file %s\n"), ainfo->file);
3352 fprintf(fp, "\n--%s\n", compose->boundary);
3354 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3355 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3356 fprintf(fp, "Content-Disposition: inline\n");
3358 conv_encode_header(filename, sizeof(filename),
3360 fprintf(fp, "Content-Type: %s;\n"
3362 ainfo->content_type, filename);
3363 fprintf(fp, "Content-Disposition: attachment;\n"
3364 " filename=\"%s\"\n", filename);
3367 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3368 procmime_get_encoding_str(ainfo->encoding));
3370 if (ainfo->encoding == ENC_7BIT) {
3371 gchar buf[BUFFSIZE];
3373 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3378 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3380 while ((len = fread(inbuf, sizeof(gchar),
3381 B64_LINE_SIZE, attach_fp))
3383 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3387 if (len > 0 && feof(attach_fp)) {
3388 to64frombits(outbuf, inbuf, len);
3397 fprintf(fp, "\n--%s--\n", compose->boundary);
3400 #define IS_IN_CUSTOM_HEADER(header) \
3401 (compose->account->add_customhdr && \
3402 custom_header_find(compose->account->customhdr_list, header) != NULL)
3404 static gint compose_write_headers_from_headerlist(Compose *compose,
3408 gchar buf[BUFFSIZE];
3409 gchar *str, *header_w_colon, *trans_hdr;
3410 gboolean first_address;
3412 ComposeHeaderEntry *headerentry;
3413 gchar * headerentryname;
3415 if (IS_IN_CUSTOM_HEADER(header)) {
3419 debug_print(_("Writing %s-header\n"), header);
3421 header_w_colon = g_strconcat(header, ":", NULL);
3422 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3424 first_address = TRUE;
3425 for(list = compose->header_list; list; list = list->next) {
3426 headerentry = ((ComposeHeaderEntry *)list->data);
3427 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3429 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3430 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3431 Xstrdup_a(str, str, return -1);
3433 if(str[0] != '\0') {
3434 compose_convert_header
3435 (buf, sizeof(buf), str,
3436 strlen(header) + 2);
3438 fprintf(fp, "%s: ", header);
3439 first_address = FALSE;
3443 fprintf(fp, "%s", buf);
3447 if(!first_address) {
3451 g_free(header_w_colon);
3456 static gint compose_write_headers(Compose *compose, FILE *fp,
3457 const gchar *charset, EncodingType encoding,
3460 gchar buf[BUFFSIZE];
3462 /* struct utsname utsbuf; */
3464 g_return_val_if_fail(fp != NULL, -1);
3465 g_return_val_if_fail(charset != NULL, -1);
3466 g_return_val_if_fail(compose->account != NULL, -1);
3467 g_return_val_if_fail(compose->account->address != NULL, -1);
3470 if (compose->account->add_date) {
3471 get_rfc822_date(buf, sizeof(buf));
3472 fprintf(fp, "Date: %s\n", buf);
3476 if (!IS_IN_CUSTOM_HEADER("From")) {
3477 if (compose->account->name && *compose->account->name) {
3478 compose_convert_header
3479 (buf, sizeof(buf), compose->account->name,
3481 fprintf(fp, "From: %s <%s>\n",
3482 buf, compose->account->address);
3484 fprintf(fp, "From: %s\n", compose->account->address);
3488 compose_write_headers_from_headerlist(compose, fp, "To");
3489 #if 0 /* NEW COMPOSE GUI */
3490 if (compose->use_to) {
3491 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3493 Xstrdup_a(str, str, return -1);
3496 compose->to_list = address_list_append
3497 (compose->to_list, str);
3498 if (!IS_IN_CUSTOM_HEADER("To")) {
3499 compose_convert_header
3500 (buf, sizeof(buf), str,
3502 fprintf(fp, "To: %s\n", buf);
3510 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3511 #if 0 /* NEW COMPOSE GUI */
3512 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3514 Xstrdup_a(str, str, return -1);
3518 compose->newsgroup_list =
3519 newsgroup_list_append(compose->newsgroup_list,
3521 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3522 compose_convert_header(buf, sizeof(buf), str,
3523 strlen("Newsgroups: "));
3524 fprintf(fp, "Newsgroups: %s\n", buf);
3530 compose_write_headers_from_headerlist(compose, fp, "Cc");
3531 #if 0 /* NEW COMPOSE GUI */
3532 if (compose->use_cc) {
3533 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3535 Xstrdup_a(str, str, return -1);
3538 compose->to_list = address_list_append
3539 (compose->to_list, str);
3540 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3541 compose_convert_header
3542 (buf, sizeof(buf), str,
3544 fprintf(fp, "Cc: %s\n", buf);
3551 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3552 #if 0 /* NEW COMPOSE GUI */
3553 if (compose->use_bcc) {
3554 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3556 Xstrdup_a(str, str, return -1);
3559 compose->to_list = address_list_append
3560 (compose->to_list, str);
3561 compose_convert_header(buf, sizeof(buf), str,
3563 fprintf(fp, "Bcc: %s\n", buf);
3570 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3571 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3572 Xstrdup_a(str, str, return -1);
3575 compose_convert_header(buf, sizeof(buf), str,
3576 strlen("Subject: "));
3577 fprintf(fp, "Subject: %s\n", buf);
3582 if (compose->account->gen_msgid) {
3583 compose_generate_msgid(compose, buf, sizeof(buf));
3584 fprintf(fp, "Message-Id: <%s>\n", buf);
3585 compose->msgid = g_strdup(buf);
3589 if (compose->inreplyto && compose->to_list)
3590 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3593 if (compose->references)
3594 fprintf(fp, "References: %s\n", compose->references);
3597 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3598 #if 0 /* NEW COMPOSE GUI */
3599 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3600 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3602 Xstrdup_a(str, str, return -1);
3606 compose_convert_header(buf, sizeof(buf), str,
3607 strlen("Followup-To: "));
3608 fprintf(fp, "Followup-To: %s\n", buf);
3614 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3615 #if 0 /* NEW COMPOSE GUI */
3616 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3617 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3619 Xstrdup_a(str, str, return -1);
3622 compose_convert_header(buf, sizeof(buf), str,
3623 strlen("Reply-To: "));
3624 fprintf(fp, "Reply-To: %s\n", buf);
3630 if (compose->account->organization &&
3631 !IS_IN_CUSTOM_HEADER("Organization")) {
3632 compose_convert_header(buf, sizeof(buf),
3633 compose->account->organization,
3634 strlen("Organization: "));
3635 fprintf(fp, "Organization: %s\n", buf);
3638 /* Program version and system info */
3639 /* uname(&utsbuf); */
3640 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3641 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3643 gtk_major_version, gtk_minor_version, gtk_micro_version,
3645 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3647 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3648 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3650 gtk_major_version, gtk_minor_version, gtk_micro_version,
3652 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3655 /* custom headers */
3656 if (compose->account->add_customhdr) {
3659 for (cur = compose->account->customhdr_list; cur != NULL;
3661 CustomHeader *chdr = (CustomHeader *)cur->data;
3663 if (strcasecmp(chdr->name, "Date") != 0 &&
3664 strcasecmp(chdr->name, "From") != 0 &&
3665 strcasecmp(chdr->name, "To") != 0 &&
3666 /* strcasecmp(chdr->name, "Sender") != 0 && */
3667 strcasecmp(chdr->name, "Message-Id") != 0 &&
3668 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3669 strcasecmp(chdr->name, "References") != 0 &&
3670 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3671 strcasecmp(chdr->name, "Content-Type") != 0 &&
3672 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3674 compose_convert_header
3676 chdr->value ? chdr->value : "",
3677 strlen(chdr->name) + 2);
3678 fprintf(fp, "%s: %s\n", chdr->name, buf);
3684 fprintf(fp, "Mime-Version: 1.0\n");
3685 if (compose_use_attach(compose)) {
3686 get_rfc822_date(buf, sizeof(buf));
3687 subst_char(buf, ' ', '_');
3688 subst_char(buf, ',', '_');
3689 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3690 buf, (guint)compose);
3692 "Content-Type: multipart/mixed;\n"
3693 " boundary=\"%s\"\n", compose->boundary);
3695 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3696 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3697 procmime_get_encoding_str(encoding));
3700 /* Request Return Receipt */
3701 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3702 if (compose->return_receipt) {
3703 if (compose->account->name
3704 && *compose->account->name) {
3705 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3706 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3708 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3712 /* separator between header and body */
3718 #undef IS_IN_CUSTOM_HEADER
3720 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3723 g_return_if_fail(src != NULL);
3724 g_return_if_fail(dest != NULL);
3726 if (len < 1) return;
3730 if (is_ascii_str(src)) {
3731 strncpy2(dest, src, len);
3732 dest[len - 1] = '\0';
3735 conv_encode_header(dest, len, src, header_len);
3738 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3747 if (compose->account && compose->account->address &&
3748 *compose->account->address) {
3749 if (strchr(compose->account->address, '@'))
3750 addr = g_strdup(compose->account->address);
3752 addr = g_strconcat(compose->account->address, "@",
3753 get_domain_name(), NULL);
3755 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3758 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3759 lt->tm_year + 1900, lt->tm_mon + 1,
3760 lt->tm_mday, lt->tm_hour,
3761 lt->tm_min, lt->tm_sec,
3762 (guint)random(), addr);
3764 debug_print(_("generated Message-ID: %s\n"), buf);
3770 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3771 GtkWidget **entry, gint *count,
3772 const gchar *label_str,
3773 gboolean is_addr_entry)
3777 if (GTK_TABLE(table)->nrows < (*count) + 1)
3778 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3780 *hbox = gtk_hbox_new(FALSE, 0);
3781 label = gtk_label_new
3782 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3783 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3784 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3786 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3788 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3789 #if 0 /* NEW COMPOSE GUI */
3790 if (GTK_TABLE(table)->nrows > (*count) + 1)
3791 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3795 address_completion_register_entry(GTK_ENTRY(*entry));
3800 static void compose_create_header_entry(Compose *compose) {
3801 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3805 GList *combo_list = NULL;
3806 gchar **string, *header;
3807 ComposeHeaderEntry *headerentry;
3809 headerentry = g_new0(ComposeHeaderEntry, 1);
3812 combo = gtk_combo_new();
3814 while(*string != NULL) {
3815 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3818 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3819 g_list_free(combo_list);
3820 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3821 gtk_widget_show(combo);
3822 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3823 if(compose->header_last) {
3824 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3826 switch(compose->account->protocol) {
3828 header = _("Newsgroups:");
3835 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
3838 entry = gtk_entry_new();
3839 gtk_widget_show(entry);
3840 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);
3842 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
3843 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
3845 address_completion_register_entry(GTK_ENTRY(entry));
3847 headerentry->compose = compose;
3848 headerentry->combo = combo;
3849 headerentry->entry = entry;
3850 headerentry->headernum = compose->header_nextrow;
3852 compose->header_nextrow++;
3853 compose->header_last = headerentry;
3856 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text) {
3857 ComposeHeaderEntry *last_header;
3859 last_header = compose->header_last;
3861 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
3862 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
3865 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
3871 GtkWidget *handlebox;
3873 GtkWidget *notebook;
3877 GtkWidget *table_vbox;
3879 GtkWidget *from_optmenu_hbox;
3880 #if 0 /* NEW COMPOSE GUI */
3881 GtkWidget *to_entry;
3883 GtkWidget *newsgroups_entry;
3884 GtkWidget *newsgroups_hbox;
3886 GtkWidget *header_scrolledwin;
3887 GtkWidget *header_table;
3888 GtkWidget *subject_entry;
3889 #if 0 /* NEW COMPOSE GUI */
3890 GtkWidget *cc_entry;
3892 GtkWidget *bcc_entry;
3893 GtkWidget *bcc_hbox;
3894 GtkWidget *reply_entry;
3895 GtkWidget *reply_hbox;
3896 GtkWidget *followup_entry;
3897 GtkWidget *followup_hbox;
3901 GtkWidget *attach_scrwin;
3902 GtkWidget *attach_clist;
3904 GtkWidget *edit_vbox;
3905 GtkWidget *ruler_hbox;
3907 GtkWidget *scrolledwin;
3913 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
3914 guint n_menu_entries;
3915 GtkStyle *style, *new_style;
3918 gboolean success[1];
3920 GtkWidget *popupmenu;
3921 GtkWidget *menuitem;
3922 GtkItemFactory *popupfactory;
3923 GtkItemFactory *ifactory;
3924 GtkWidget *tmpl_menu;
3930 GtkPspell * gtkpspell = NULL;
3933 g_return_val_if_fail(account != NULL, NULL);
3935 debug_print(_("Creating compose window...\n"));
3936 compose = g_new0(Compose, 1);
3938 compose->account = account;
3939 compose->orig_account = account;
3941 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
3942 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
3943 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
3944 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3945 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
3946 gtk_signal_connect(GTK_OBJECT(window), "destroy",
3947 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
3948 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
3949 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
3950 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
3951 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
3952 gtk_widget_realize(window);
3954 gtkut_widget_set_composer_icon(window);
3956 vbox = gtk_vbox_new(FALSE, 0);
3957 gtk_container_add(GTK_CONTAINER(window), vbox);
3959 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
3960 menubar = menubar_create(window, compose_entries,
3961 n_menu_entries, "<Compose>", compose);
3962 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
3964 handlebox = gtk_handle_box_new();
3965 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
3967 compose_toolbar_create(compose, handlebox);
3969 vbox2 = gtk_vbox_new(FALSE, 2);
3970 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
3971 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
3973 table_vbox = gtk_vbox_new(FALSE, 0);
3974 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
3975 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
3979 notebook = gtk_notebook_new();
3980 gtk_widget_set_usize(notebook, -1, 180);
3981 gtk_widget_show(notebook);
3983 /* header labels and entries */
3984 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3985 gtk_widget_show(header_scrolledwin);
3986 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
3987 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), header_scrolledwin, gtk_label_new(_("Header")));
3989 header_table = gtk_table_new(2, 2, FALSE);
3990 gtk_widget_show(header_table);
3991 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
3992 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
3995 /* option menu for selecting accounts */
3996 hbox = gtk_hbox_new(FALSE, 0);
3997 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
3998 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3999 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4001 from_optmenu_hbox = compose_account_option_menu_create(compose);
4002 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4003 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4004 #if 0 /* NEW COMPOSE GUI */
4005 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4010 compose_add_entry_field(header_table, &hbox, &subject_entry, &count,
4013 compose->header_table = header_table;
4014 compose->header_list = NULL;
4015 compose->header_nextrow = count;
4017 compose_create_header_entry(compose);
4019 #if 0 /* NEW COMPOSE GUI */
4020 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4022 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4023 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4024 &count, "Newsgroups:", FALSE);
4025 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4027 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4029 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4031 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4032 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4034 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4035 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4037 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4038 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4039 "Followup-To:", FALSE);
4040 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4042 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4044 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4045 GTK_SIGNAL_FUNC(to_activated), compose);
4046 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4047 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4048 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4049 GTK_SIGNAL_FUNC(subject_activated), compose);
4050 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4051 GTK_SIGNAL_FUNC(cc_activated), compose);
4052 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4053 GTK_SIGNAL_FUNC(bcc_activated), compose);
4054 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4055 GTK_SIGNAL_FUNC(replyto_activated), compose);
4056 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4057 GTK_SIGNAL_FUNC(followupto_activated), compose);
4059 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4060 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4061 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4062 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4063 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4064 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4065 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4066 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4067 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4068 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4069 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4070 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4071 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4072 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4075 /* attachment list */
4076 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4077 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), attach_scrwin, gtk_label_new(_("Attachments")));
4078 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4079 GTK_POLICY_AUTOMATIC,
4081 gtk_widget_set_usize(attach_scrwin, -1, 80);
4083 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4084 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4086 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4087 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4088 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4089 GTK_SELECTION_EXTENDED);
4090 for (i = 0; i < N_ATTACH_COLS; i++)
4091 GTK_WIDGET_UNSET_FLAGS
4092 (GTK_CLIST(attach_clist)->column[i].button,
4094 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4096 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4097 GTK_SIGNAL_FUNC(attach_selected), compose);
4098 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4099 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4100 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4101 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4104 gtk_drag_dest_set(attach_clist,
4105 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4107 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4108 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4112 edit_vbox = gtk_vbox_new(FALSE, 0);
4113 #if 0 /* NEW COMPOSE GUI */
4114 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4118 ruler_hbox = gtk_hbox_new(FALSE, 0);
4119 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4121 ruler = gtk_shruler_new();
4122 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4123 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4125 gtk_widget_set_usize(ruler_hbox, 1, -1);
4128 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4129 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4130 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4131 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4132 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4134 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4135 (GTK_SCROLLED_WINDOW(scrolledwin)),
4136 gtk_scrolled_window_get_vadjustment
4137 (GTK_SCROLLED_WINDOW(scrolledwin)));
4138 GTK_STEXT(text)->default_tab_width = 8;
4139 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4141 if (prefs_common.block_cursor) {
4142 GTK_STEXT(text)->cursor_type = STEXT_CURSOR_BLOCK;
4145 if (prefs_common.smart_wrapping) {
4146 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4147 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4150 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4152 gtk_signal_connect(GTK_OBJECT(text), "changed",
4153 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4154 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4155 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4156 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4157 GTK_SIGNAL_FUNC(compose_button_press_cb),
4160 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4161 GTK_SIGNAL_FUNC(compose_key_press_cb),
4164 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4165 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4169 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4171 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4172 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4175 if (prefs_common.enable_pspell) {
4176 gtkpspell = gtkpspell_new_with_config(gtkpspellconfig,
4177 prefs_common.pspell_path,
4178 prefs_common.dictionary,
4180 conv_get_current_charset_str());
4181 if (gtkpspell == NULL)
4182 prefs_common.enable_pspell = FALSE;
4184 gtkpspell_attach(gtkpspell, GTK_STEXT(text));
4187 gtk_widget_show_all(vbox);
4189 /* pane between attach clist and text */
4190 paned = gtk_vpaned_new();
4191 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4192 gtk_paned_add1(GTK_PANED(paned), notebook);
4193 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4194 gtk_widget_show_all(paned);
4196 style = gtk_widget_get_style(text);
4198 /* workaround for the slow down of GtkText when using Pixmap theme */
4199 if (style->engine) {
4200 GtkThemeEngine *engine;
4202 engine = style->engine;
4203 style->engine = NULL;
4204 new_style = gtk_style_copy(style);
4205 style->engine = engine;
4207 new_style = gtk_style_copy(style);
4209 if (prefs_common.textfont) {
4212 charset = conv_get_current_charset();
4213 if (MB_CUR_MAX == 1) {
4216 Xstrdup_a(fontstr, prefs_common.textfont, );
4217 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4219 font = gdk_font_load(fontstr);
4221 font = gdk_fontset_load(prefs_common.textfont);
4223 gdk_font_unref(new_style->font);
4224 new_style->font = font;
4228 gtk_widget_set_style(text, new_style);
4230 color[0] = quote_color;
4231 cmap = gdk_window_get_colormap(window->window);
4232 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4233 if (success[0] == FALSE) {
4234 g_warning("Compose: color allocation failed.\n");
4235 style = gtk_widget_get_style(text);
4236 quote_color = style->black;
4239 n_entries = sizeof(compose_popup_entries) /
4240 sizeof(compose_popup_entries[0]);
4241 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4242 "<Compose>", &popupfactory,
4245 ifactory = gtk_item_factory_from_widget(menubar);
4246 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4247 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4249 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tool/Template");
4250 #if 0 /* NEW COMPOSE GUI */
4251 if (account->protocol == A_NNTP) {
4252 gtk_widget_hide(to_hbox);
4253 gtk_widget_hide(to_entry);
4254 gtk_widget_hide(cc_hbox);
4255 gtk_widget_hide(cc_entry);
4256 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4257 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4259 gtk_widget_hide(newsgroups_hbox);
4260 gtk_widget_hide(newsgroups_entry);
4261 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4263 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
4267 switch (prefs_common.toolbar_style) {
4269 gtk_widget_hide(handlebox);
4272 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4276 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4280 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4285 gtk_widget_show(window);
4287 address_completion_start(window);
4289 compose->window = window;
4290 compose->vbox = vbox;
4291 compose->menubar = menubar;
4292 compose->handlebox = handlebox;
4294 compose->vbox2 = vbox2;
4296 compose->table_vbox = table_vbox;
4297 compose->table = NULL;
4298 #if 0 /* NEW COMPOSE GUI */
4299 compose->table = table;
4300 compose->to_hbox = to_hbox;
4301 compose->to_entry = to_entry;
4302 compose->newsgroups_hbox = newsgroups_hbox;
4303 compose->newsgroups_entry = newsgroups_entry;
4305 compose->subject_entry = subject_entry;
4306 #if 0 /* NEW COMPOSE GUI */
4307 compose->cc_hbox = cc_hbox;
4308 compose->cc_entry = cc_entry;
4309 compose->bcc_hbox = bcc_hbox;
4310 compose->bcc_entry = bcc_entry;
4311 compose->reply_hbox = reply_hbox;
4312 compose->reply_entry = reply_entry;
4313 compose->followup_hbox = followup_hbox;
4314 compose->followup_entry = followup_entry;
4316 compose->paned = paned;
4318 compose->attach_scrwin = attach_scrwin;
4319 compose->attach_clist = attach_clist;
4321 compose->edit_vbox = edit_vbox;
4322 compose->ruler_hbox = ruler_hbox;
4323 compose->ruler = ruler;
4324 compose->scrolledwin = scrolledwin;
4325 compose->text = text;
4327 compose->focused_editable = NULL;
4329 compose->popupmenu = popupmenu;
4330 compose->popupfactory = popupfactory;
4332 compose->tmpl_menu = tmpl_menu;
4334 compose->mode = mode;
4336 compose->targetinfo = NULL;
4337 compose->replyinfo = NULL;
4339 compose->replyto = NULL;
4340 compose->mailinglist = NULL;
4342 compose->bcc = NULL;
4343 compose->followup_to = NULL;
4344 compose->inreplyto = NULL;
4345 compose->references = NULL;
4346 compose->msgid = NULL;
4347 compose->boundary = NULL;
4350 compose->use_signing = FALSE;
4351 compose->use_encryption = FALSE;
4352 #endif /* USE_GPGME */
4354 compose->modified = FALSE;
4356 compose->return_receipt = FALSE;
4358 compose->to_list = NULL;
4359 compose->newsgroup_list = NULL;
4361 compose->exteditor_file = NULL;
4362 compose->exteditor_pid = -1;
4363 compose->exteditor_readdes = -1;
4364 compose->exteditor_tag = -1;
4366 compose->bounce_filename = NULL;
4368 compose_set_title(compose);
4370 #if 0 /* NEW COMPOSE GUI */
4371 compose->use_bcc = FALSE;
4372 compose->use_replyto = FALSE;
4373 compose->use_followupto = FALSE;
4377 compose->gtkpspell = gtkpspell;
4380 #if 0 /* NEW COMPOSE GUI */
4381 if (account->protocol != A_NNTP) {
4382 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4383 gtk_check_menu_item_set_active
4384 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4385 gtk_widget_set_sensitive(menuitem, FALSE);
4386 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4387 gtk_check_menu_item_set_active
4388 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4389 gtk_widget_set_sensitive(menuitem, FALSE);
4392 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4393 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4394 #if 0 /* NEW COMPOSE GUI */
4395 compose->use_cc = TRUE;
4396 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4397 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4398 gtk_check_menu_item_set_active
4399 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4402 if (account->set_autobcc) {
4403 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4404 #if 0 /* NEW COMPOSE GUI */
4405 compose->use_bcc = TRUE;
4406 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
4407 gtk_check_menu_item_set_active
4408 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4409 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4410 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4414 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4415 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4416 #if 0 /* NEW COMPOSE GUI */
4417 compose->use_replyto = TRUE;
4418 menuitem = gtk_item_factory_get_item(ifactory,
4419 "/Message/Reply to");
4420 gtk_check_menu_item_set_active
4421 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4422 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4423 account->auto_replyto);
4426 if (account->protocol != A_NNTP) {
4427 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("To:"));
4429 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("Newsgroups:"));
4432 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
4433 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4434 prefs_common.show_ruler);
4437 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4438 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4439 prefs_common.default_sign);
4440 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4441 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4442 prefs_common.default_encrypt);
4443 #endif /* USE_GPGME */
4445 addressbook_set_target_compose(compose);
4446 compose_set_template_menu(compose);
4448 compose_list = g_list_append(compose_list, compose);
4450 #if 0 /* NEW COMPOSE GUI */
4451 compose->use_to = FALSE;
4452 compose->use_cc = FALSE;
4453 compose->use_attach = TRUE;
4456 #if 0 /* NEW COMPOSE GUI */
4457 if (!compose->use_bcc) {
4458 gtk_widget_hide(bcc_hbox);
4459 gtk_widget_hide(bcc_entry);
4460 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4462 if (!compose->use_replyto) {
4463 gtk_widget_hide(reply_hbox);
4464 gtk_widget_hide(reply_entry);
4465 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4467 if (!compose->use_followupto) {
4468 gtk_widget_hide(followup_hbox);
4469 gtk_widget_hide(followup_entry);
4470 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4473 if (!prefs_common.show_ruler)
4474 gtk_widget_hide(ruler_hbox);
4476 select_account(compose, account);
4481 #include "pixmaps/stock_mail_send.xpm"
4482 #include "pixmaps/stock_mail_send_queue.xpm"
4483 #include "pixmaps/stock_mail.xpm"
4484 #include "pixmaps/stock_paste.xpm"
4485 #include "pixmaps/stock_mail_attach.xpm"
4486 #include "pixmaps/stock_mail_compose.xpm"
4487 #include "pixmaps/linewrap.xpm"
4488 #include "pixmaps/tb_address_book.xpm"
4490 #define CREATE_TOOLBAR_ICON(xpm_d) \
4492 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
4493 &container->style->white, \
4495 icon_wid = gtk_pixmap_new(icon, mask); \
4498 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4503 GtkWidget *icon_wid;
4504 GtkWidget *send_btn;
4505 GtkWidget *sendl_btn;
4506 GtkWidget *draft_btn;
4507 GtkWidget *insert_btn;
4508 GtkWidget *attach_btn;
4510 GtkWidget *exteditor_btn;
4511 GtkWidget *linewrap_btn;
4512 GtkWidget *addrbook_btn;
4514 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4516 gtk_container_add(GTK_CONTAINER(container), toolbar);
4517 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4518 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4519 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4520 GTK_TOOLBAR_SPACE_LINE);
4522 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
4523 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4527 icon_wid, toolbar_send_cb, compose);
4529 CREATE_TOOLBAR_ICON(stock_mail_send_queue_xpm);
4530 /* CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm); */
4531 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4533 _("Put into queue folder and send later"),
4535 icon_wid, toolbar_send_later_cb,
4538 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4539 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4541 _("Save to draft folder"),
4543 icon_wid, toolbar_draft_cb,
4546 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4548 CREATE_TOOLBAR_ICON(stock_paste_xpm);
4549 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4553 icon_wid, toolbar_insert_cb,
4556 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
4557 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4561 icon_wid, toolbar_attach_cb,
4564 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4566 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4567 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4569 _("Insert signature"),
4571 icon_wid, toolbar_sig_cb, compose);
4573 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4575 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
4576 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4578 _("Edit with external editor"),
4581 toolbar_ext_editor_cb,
4584 CREATE_TOOLBAR_ICON(linewrap_xpm);
4585 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4587 _("Wrap current paragraph"),
4590 toolbar_linewrap_cb,
4593 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4595 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
4596 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4600 icon_wid, toolbar_address_cb,
4603 compose->toolbar = toolbar;
4604 compose->send_btn = send_btn;
4605 compose->sendl_btn = sendl_btn;
4606 compose->draft_btn = draft_btn;
4607 compose->insert_btn = insert_btn;
4608 compose->attach_btn = attach_btn;
4609 compose->sig_btn = sig_btn;
4610 compose->exteditor_btn = exteditor_btn;
4611 compose->linewrap_btn = linewrap_btn;
4612 compose->addrbook_btn = addrbook_btn;
4614 gtk_widget_show_all(toolbar);
4617 #undef CREATE_TOOLBAR_ICON
4619 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4625 gint num = 0, def_menu = 0;
4627 accounts = account_get_list();
4628 g_return_val_if_fail(accounts != NULL, NULL);
4630 hbox = gtk_hbox_new(FALSE, 0);
4631 optmenu = gtk_option_menu_new();
4632 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4633 menu = gtk_menu_new();
4635 for (; accounts != NULL; accounts = accounts->next, num++) {
4636 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4637 GtkWidget *menuitem;
4640 if (ac == compose->account) def_menu = num;
4642 name = g_strdup_printf("%s: %s <%s>",
4643 ac->account_name, ac->name, ac->address);
4644 MENUITEM_ADD(menu, menuitem, name, ac);
4646 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4647 GTK_SIGNAL_FUNC(account_activated),
4651 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4652 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4657 static void compose_set_template_menu(Compose *compose)
4659 GSList *tmpl_list, *cur;
4663 tmpl_list = template_get_config();
4665 menu = gtk_menu_new();
4667 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4668 Template *tmpl = (Template *)cur->data;
4670 item = gtk_menu_item_new_with_label(tmpl->name);
4671 gtk_menu_append(GTK_MENU(menu), item);
4672 gtk_signal_connect(GTK_OBJECT(item), "activate",
4673 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4675 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4676 gtk_widget_show(item);
4679 gtk_widget_show(menu);
4680 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4683 void compose_reflect_prefs_all(void)
4688 for (cur = compose_list; cur != NULL; cur = cur->next) {
4689 compose = (Compose *)cur->data;
4690 compose_set_template_menu(compose);
4694 static void compose_template_apply(Compose *compose, Template *tmpl)
4699 if (!tmpl || !tmpl->value) return;
4701 gtk_stext_freeze(GTK_STEXT(compose->text));
4704 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
4707 if (compose->replyinfo == NULL) {
4710 memset(&dummyinfo, 0, sizeof(MsgInfo));
4711 parsed_str = compose_quote_fmt(compose, &dummyinfo,
4714 if (prefs_common.quotemark && *prefs_common.quotemark)
4715 qmark = prefs_common.quotemark;
4719 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
4720 tmpl->value, qmark);
4723 if (parsed_str && prefs_common.auto_sig)
4724 compose_insert_sig(compose);
4726 gtk_stext_thaw(GTK_STEXT(compose->text));
4729 static void compose_destroy(Compose *compose)
4732 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4735 /* NOTE: address_completion_end() does nothing with the window
4736 * however this may change. */
4737 address_completion_end(compose->window);
4739 slist_free_strings(compose->to_list);
4740 g_slist_free(compose->to_list);
4741 slist_free_strings(compose->newsgroup_list);
4742 g_slist_free(compose->newsgroup_list);
4743 slist_free_strings(compose->header_list);
4744 g_slist_free(compose->header_list);
4746 procmsg_msginfo_free(compose->targetinfo);
4747 procmsg_msginfo_free(compose->replyinfo);
4749 g_free(compose->replyto);
4750 g_free(compose->cc);
4751 g_free(compose->bcc);
4752 g_free(compose->newsgroups);
4753 g_free(compose->followup_to);
4755 g_free(compose->inreplyto);
4756 g_free(compose->references);
4757 g_free(compose->msgid);
4758 g_free(compose->boundary);
4760 if (compose->bounce_filename)
4761 g_free(compose->bounce_filename);
4763 g_free(compose->exteditor_file);
4765 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
4767 compose_attach_info_free(ainfo);
4769 if (addressbook_get_target_compose() == compose)
4770 addressbook_set_target_compose(NULL);
4772 prefs_common.compose_width = compose->scrolledwin->allocation.width;
4773 prefs_common.compose_height = compose->window->allocation.height;
4775 gtk_widget_destroy(compose->paned);
4779 compose_list = g_list_remove(compose_list, compose);
4782 static void compose_attach_info_free(AttachInfo *ainfo)
4784 g_free(ainfo->file);
4785 g_free(ainfo->content_type);
4786 g_free(ainfo->name);
4790 static void compose_attach_remove_selected(Compose *compose)
4792 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4796 while (clist->selection != NULL) {
4797 row = GPOINTER_TO_INT(clist->selection->data);
4798 ainfo = gtk_clist_get_row_data(clist, row);
4799 compose_attach_info_free(ainfo);
4800 gtk_clist_remove(clist, row);
4804 static struct _AttachProperty
4807 GtkWidget *mimetype_entry;
4808 GtkWidget *encoding_optmenu;
4809 GtkWidget *path_entry;
4810 GtkWidget *filename_entry;
4812 GtkWidget *cancel_btn;
4815 static void compose_attach_property(Compose *compose)
4817 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4820 GtkOptionMenu *optmenu;
4821 static gboolean cancelled;
4823 if (!clist->selection) return;
4824 row = GPOINTER_TO_INT(clist->selection->data);
4826 ainfo = gtk_clist_get_row_data(clist, row);
4829 if (!attach_prop.window)
4830 compose_attach_property_create(&cancelled);
4831 gtk_widget_grab_focus(attach_prop.ok_btn);
4832 gtk_widget_show(attach_prop.window);
4833 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
4835 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
4836 if (ainfo->encoding == ENC_UNKNOWN)
4837 gtk_option_menu_set_history(optmenu, ENC_BASE64);
4839 gtk_option_menu_set_history(optmenu, ainfo->encoding);
4841 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
4842 ainfo->content_type ? ainfo->content_type : "");
4843 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
4844 ainfo->file ? ainfo->file : "");
4845 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
4846 ainfo->name ? ainfo->name : "");
4850 gchar *cnttype = NULL;
4854 GtkWidget *menuitem;
4859 if (cancelled == TRUE) {
4860 gtk_widget_hide(attach_prop.window);
4864 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
4865 if (*text != '\0') {
4868 text = g_strstrip(g_strdup(text));
4869 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
4870 cnttype = g_strdup(text);
4873 alertpanel_error(_("Invalid MIME type."));
4879 menu = gtk_option_menu_get_menu(optmenu);
4880 menuitem = gtk_menu_get_active(GTK_MENU(menu));
4881 ainfo->encoding = GPOINTER_TO_INT
4882 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
4884 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
4885 if (*text != '\0') {
4886 if (is_file_exist(text) &&
4887 (size = get_file_size(text)) > 0)
4888 file = g_strdup(text);
4891 (_("File doesn't exist or is empty."));
4897 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
4898 if (*text != '\0') {
4899 g_free(ainfo->name);
4900 ainfo->name = g_strdup(text);
4904 g_free(ainfo->content_type);
4905 ainfo->content_type = cnttype;
4908 g_free(ainfo->file);
4914 gtk_clist_set_text(clist, row, COL_MIMETYPE,
4915 ainfo->content_type);
4916 gtk_clist_set_text(clist, row, COL_SIZE,
4917 to_human_readable(ainfo->size));
4918 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
4920 gtk_widget_hide(attach_prop.window);
4925 #define SET_LABEL_AND_ENTRY(str, entry, top) \
4927 label = gtk_label_new(str); \
4928 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
4929 GTK_FILL, 0, 0, 0); \
4930 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
4932 entry = gtk_entry_new(); \
4933 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
4934 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
4937 static void compose_attach_property_create(gboolean *cancelled)
4943 GtkWidget *mimetype_entry;
4946 GtkWidget *optmenu_menu;
4947 GtkWidget *menuitem;
4948 GtkWidget *path_entry;
4949 GtkWidget *filename_entry;
4952 GtkWidget *cancel_btn;
4953 GList *mime_type_list, *strlist;
4955 debug_print("Creating attach_property window...\n");
4957 window = gtk_window_new(GTK_WINDOW_DIALOG);
4958 gtk_widget_set_usize(window, 480, -1);
4959 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
4960 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
4961 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
4962 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
4963 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4964 GTK_SIGNAL_FUNC(attach_property_delete_event),
4966 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
4967 GTK_SIGNAL_FUNC(attach_property_key_pressed),
4970 vbox = gtk_vbox_new(FALSE, 8);
4971 gtk_container_add(GTK_CONTAINER(window), vbox);
4973 table = gtk_table_new(4, 2, FALSE);
4974 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
4975 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
4976 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
4978 label = gtk_label_new(_("MIME type"));
4979 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
4981 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
4982 mimetype_entry = gtk_combo_new();
4983 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
4984 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
4986 /* stuff with list */
4987 mime_type_list = procmime_get_mime_type_list();
4989 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
4990 MimeType *type = (MimeType *) mime_type_list->data;
4991 strlist = g_list_append(strlist,
4992 g_strdup_printf("%s/%s",
4993 type->type, type->sub_type));
4996 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
4998 for (mime_type_list = strlist; mime_type_list != NULL;
4999 mime_type_list = mime_type_list->next)
5000 g_free(mime_type_list->data);
5001 g_list_free(strlist);
5003 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5005 label = gtk_label_new(_("Encoding"));
5006 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5008 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5010 hbox = gtk_hbox_new(FALSE, 0);
5011 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5012 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5014 optmenu = gtk_option_menu_new();
5015 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5017 optmenu_menu = gtk_menu_new();
5018 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5019 gtk_widget_set_sensitive(menuitem, FALSE);
5020 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5021 gtk_widget_set_sensitive(menuitem, FALSE);
5022 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5023 gtk_widget_set_sensitive(menuitem, FALSE);
5024 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5026 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5028 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5029 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5031 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5032 &cancel_btn, _("Cancel"), NULL, NULL);
5033 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5034 gtk_widget_grab_default(ok_btn);
5036 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5037 GTK_SIGNAL_FUNC(attach_property_ok),
5039 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5040 GTK_SIGNAL_FUNC(attach_property_cancel),
5043 gtk_widget_show_all(vbox);
5045 attach_prop.window = window;
5046 attach_prop.mimetype_entry = mimetype_entry;
5047 attach_prop.encoding_optmenu = optmenu;
5048 attach_prop.path_entry = path_entry;
5049 attach_prop.filename_entry = filename_entry;
5050 attach_prop.ok_btn = ok_btn;
5051 attach_prop.cancel_btn = cancel_btn;
5054 #undef SET_LABEL_AND_ENTRY
5056 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5062 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5068 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5069 gboolean *cancelled)
5077 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5078 gboolean *cancelled)
5080 if (event && event->keyval == GDK_Escape) {
5086 static void compose_exec_ext_editor(Compose *compose)
5092 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5093 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5095 if (pipe(pipe_fds) < 0) {
5100 if ((pid = fork()) < 0) {
5106 /* close the write side of the pipe */
5109 compose->exteditor_file = g_strdup(tmp);
5110 compose->exteditor_pid = pid;
5111 compose->exteditor_readdes = pipe_fds[0];
5113 compose_set_ext_editor_sensitive(compose, FALSE);
5115 compose->exteditor_tag =
5116 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5117 compose_input_cb, compose);
5118 } else { /* process-monitoring process */
5124 /* close the read side of the pipe */
5127 if (compose_write_body_to_file(compose, tmp) < 0) {
5128 fd_write(pipe_fds[1], "2\n", 2);
5132 pid_ed = compose_exec_ext_editor_real(tmp);
5134 fd_write(pipe_fds[1], "1\n", 2);
5138 /* wait until editor is terminated */
5139 waitpid(pid_ed, NULL, 0);
5141 fd_write(pipe_fds[1], "0\n", 2);
5148 static gint compose_exec_ext_editor_real(const gchar *file)
5150 static gchar *def_cmd = "emacs %s";
5156 g_return_val_if_fail(file != NULL, -1);
5158 if ((pid = fork()) < 0) {
5163 if (pid != 0) return pid;
5165 /* grandchild process */
5167 if (setpgid(0, getppid()))
5170 if (prefs_common.ext_editor_cmd &&
5171 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5172 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5173 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5175 if (prefs_common.ext_editor_cmd)
5176 g_warning(_("External editor command line is invalid: `%s'\n"),
5177 prefs_common.ext_editor_cmd);
5178 g_snprintf(buf, sizeof(buf), def_cmd, file);
5181 cmdline = g_strsplit(buf, " ", 1024);
5182 execvp(cmdline[0], cmdline);
5185 g_strfreev(cmdline);
5190 static gboolean compose_ext_editor_kill(Compose *compose)
5192 pid_t pgid = compose->exteditor_pid * -1;
5195 ret = kill(pgid, 0);
5197 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5201 msg = g_strdup_printf
5202 (_("The external editor is still working.\n"
5203 "Force terminating the process?\n"
5204 "process group id: %d"), -pgid);
5205 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5208 if (val == G_ALERTDEFAULT) {
5209 gdk_input_remove(compose->exteditor_tag);
5210 close(compose->exteditor_readdes);
5212 if (kill(pgid, SIGTERM) < 0) perror("kill");
5213 waitpid(compose->exteditor_pid, NULL, 0);
5215 g_warning(_("Terminated process group id: %d"), -pgid);
5216 g_warning(_("Temporary file: %s"),
5217 compose->exteditor_file);
5219 compose_set_ext_editor_sensitive(compose, TRUE);
5221 g_free(compose->exteditor_file);
5222 compose->exteditor_file = NULL;
5223 compose->exteditor_pid = -1;
5224 compose->exteditor_readdes = -1;
5225 compose->exteditor_tag = -1;
5233 static void compose_input_cb(gpointer data, gint source,
5234 GdkInputCondition condition)
5237 Compose *compose = (Compose *)data;
5240 debug_print(_("Compose: input from monitoring process\n"));
5242 gdk_input_remove(compose->exteditor_tag);
5245 if (read(source, &buf[i], 1) < 1) {
5249 if (buf[i] == '\n') {
5254 if (i == sizeof(buf) - 1)
5258 waitpid(compose->exteditor_pid, NULL, 0);
5260 if (buf[0] == '0') { /* success */
5261 GtkSText *text = GTK_STEXT(compose->text);
5263 gtk_stext_freeze(text);
5264 gtk_stext_set_point(text, 0);
5265 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5266 compose_insert_file(compose, compose->exteditor_file);
5267 compose_changed_cb(NULL, compose);
5268 gtk_stext_thaw(text);
5270 if (unlink(compose->exteditor_file) < 0)
5271 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5272 } else if (buf[0] == '1') { /* failed */
5273 g_warning(_("Couldn't exec external editor\n"));
5274 if (unlink(compose->exteditor_file) < 0)
5275 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5276 } else if (buf[0] == '2') {
5277 g_warning(_("Couldn't write to file\n"));
5278 } else if (buf[0] == '3') {
5279 g_warning(_("Pipe read failed\n"));
5284 compose_set_ext_editor_sensitive(compose, TRUE);
5286 g_free(compose->exteditor_file);
5287 compose->exteditor_file = NULL;
5288 compose->exteditor_pid = -1;
5289 compose->exteditor_readdes = -1;
5290 compose->exteditor_tag = -1;
5293 static void compose_set_ext_editor_sensitive(Compose *compose,
5296 GtkItemFactory *ifactory;
5298 ifactory = gtk_item_factory_from_widget(compose->menubar);
5300 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5301 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5302 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5304 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5305 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5306 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5307 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5308 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5311 gtk_widget_set_sensitive(compose->text, sensitive);
5312 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5313 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5314 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5315 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5316 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5317 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5318 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5321 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5325 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5326 cursor_pos = MAX(cursor_pos, 0);
5331 /* callback functions */
5333 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5334 * includes "non-client" (windows-izm) in calculation, so this calculation
5335 * may not be accurate.
5337 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5338 GtkAllocation *allocation,
5339 GtkSHRuler *shruler)
5341 if (prefs_common.show_ruler) {
5343 gint line_width_in_chars;
5345 char_width = gtkut_get_font_width
5346 (GTK_WIDGET(widget)->style->font);
5347 line_width_in_chars =
5348 (allocation->width - allocation->x) / char_width;
5350 /* got the maximum */
5351 gtk_ruler_set_range(GTK_RULER(shruler),
5352 0.0, line_width_in_chars,
5353 calc_cursor_xpos(GTK_STEXT(widget),
5356 /*line_width_in_chars*/ char_width);
5362 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5364 compose_send_cb(data, 0, NULL);
5367 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5369 compose_send_later_cb(data, 0, NULL);
5372 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5374 compose_draft_cb(data, 0, NULL);
5377 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5379 compose_insert_file_cb(data, 0, NULL);
5382 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5384 compose_attach_cb(data, 0, NULL);
5387 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5389 Compose *compose = (Compose *)data;
5391 compose_insert_sig(compose);
5394 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5396 Compose *compose = (Compose *)data;
5398 compose_exec_ext_editor(compose);
5401 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5403 Compose *compose = (Compose *)data;
5405 compose_wrap_line(compose);
5408 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5410 compose_address_cb(data, 0, NULL);
5413 static void select_account(Compose * compose, PrefsAccount * ac)
5415 compose->account = ac;
5416 compose_set_title(compose);
5418 #if 0 /* NEW COMPOSE GUI */
5419 if (ac->protocol == A_NNTP) {
5420 GtkItemFactory *ifactory;
5421 GtkWidget *menuitem;
5423 ifactory = gtk_item_factory_from_widget(compose->menubar);
5424 menu_set_sensitive(ifactory,
5425 "/Message/Followup to", TRUE);
5426 gtk_widget_show(compose->newsgroups_hbox);
5427 gtk_widget_show(compose->newsgroups_entry);
5428 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5431 compose->use_to = FALSE;
5432 compose->use_cc = FALSE;
5434 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5435 gtk_check_menu_item_set_active
5436 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5438 menu_set_sensitive(ifactory,
5439 "/Message/To", TRUE);
5440 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5441 gtk_check_menu_item_set_active
5442 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5444 gtk_widget_hide(compose->to_hbox);
5445 gtk_widget_hide(compose->to_entry);
5446 gtk_widget_hide(compose->cc_hbox);
5447 gtk_widget_hide(compose->cc_entry);
5448 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5450 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5454 GtkItemFactory *ifactory;
5455 GtkWidget *menuitem;
5457 ifactory = gtk_item_factory_from_widget(compose->menubar);
5458 menu_set_sensitive(ifactory,
5459 "/Message/Followup to", FALSE);
5460 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5461 gtk_widget_hide(compose->newsgroups_hbox);
5462 gtk_widget_hide(compose->newsgroups_entry);
5463 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5466 compose->use_to = TRUE;
5467 compose->use_cc = TRUE;
5469 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5470 gtk_check_menu_item_set_active
5471 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5472 menu_set_sensitive(ifactory,
5473 "/Message/To", FALSE);
5474 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5475 gtk_check_menu_item_set_active
5476 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5477 gtk_widget_show(compose->to_hbox);
5478 gtk_widget_show(compose->to_entry);
5479 gtk_widget_show(compose->cc_hbox);
5480 gtk_widget_show(compose->cc_entry);
5482 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5484 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5487 gtk_widget_queue_resize(compose->table_vbox);
5491 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5493 Compose *compose = (Compose *)data;
5497 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5498 g_return_if_fail(ac != NULL);
5500 if (ac != compose->account)
5501 select_account(compose, ac);
5504 static void attach_selected(GtkCList *clist, gint row, gint column,
5505 GdkEvent *event, gpointer data)
5507 Compose *compose = (Compose *)data;
5509 if (event && event->type == GDK_2BUTTON_PRESS)
5510 compose_attach_property(compose);
5513 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5516 Compose *compose = (Compose *)data;
5517 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5522 if (event->button == 3) {
5523 if ((clist->selection && !clist->selection->next) ||
5524 !clist->selection) {
5525 gtk_clist_unselect_all(clist);
5526 if (gtk_clist_get_selection_info(clist,
5529 gtk_clist_select_row(clist, row, column);
5530 gtkut_clist_set_focus_row(clist, row);
5533 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5534 NULL, NULL, event->button, event->time);
5538 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5541 Compose *compose = (Compose *)data;
5545 switch (event->keyval) {
5547 compose_attach_remove_selected(compose);
5552 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5554 Compose *compose = (Compose *)data;
5557 val = compose_send(compose);
5558 if (val == 0) gtk_widget_destroy(compose->window);
5561 static void compose_send_later_cb(gpointer data, guint action,
5564 Compose *compose = (Compose *)data;
5567 val = compose_queue(compose, NULL, NULL);
5568 if (!val) gtk_widget_destroy(compose->window);
5571 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5573 Compose *compose = (Compose *)data;
5577 draft = folder_get_default_draft();
5579 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5580 G_DIR_SEPARATOR, (gint)compose);
5582 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5587 folder_item_scan(draft);
5588 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
5595 if (compose->mode == COMPOSE_REEDIT) {
5596 compose_remove_reedit_target(compose);
5597 if (compose->targetinfo &&
5598 compose->targetinfo->folder != draft)
5599 folderview_update_item(compose->targetinfo->folder,
5603 folder_item_scan(draft);
5604 folderview_update_item(draft, TRUE);
5606 gtk_widget_destroy(compose->window);
5609 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
5611 Compose *compose = (Compose *)data;
5614 if (compose->bounce_filename != NULL)
5617 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5622 for ( tmp = file_list; tmp; tmp = tmp->next) {
5623 gchar *file = (gchar *) tmp->data;
5624 compose_attach_append(compose, file, MIME_UNKNOWN);
5627 g_list_free(file_list);
5631 static void compose_insert_file_cb(gpointer data, guint action,
5634 Compose *compose = (Compose *)data;
5637 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5642 for ( tmp = file_list; tmp; tmp = tmp->next) {
5643 gchar *file = (gchar *) tmp->data;
5644 compose_insert_file(compose, file);
5647 g_list_free(file_list);
5651 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
5654 compose_close_cb(data, 0, NULL);
5658 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
5660 Compose *compose = (Compose *)data;
5663 if (compose->exteditor_tag != -1) {
5664 if (!compose_ext_editor_kill(compose))
5668 if (compose->modified) {
5669 val = alertpanel(_("Discard message"),
5670 _("This message has been modified. discard it?"),
5671 _("Discard"), _("to Draft"), _("Cancel"));
5674 case G_ALERTDEFAULT:
5676 case G_ALERTALTERNATE:
5677 compose_draft_cb(data, 0, NULL);
5684 if (compose->gtkpspell) {
5685 gtkpspell_detach(compose->gtkpspell);
5686 compose->gtkpspell = gtkpspell_delete(compose->gtkpspell);
5689 gtk_widget_destroy(compose->window);
5692 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
5694 Compose *compose = (Compose *)data;
5696 addressbook_open(compose);
5699 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
5701 Compose *compose = (Compose *)data;
5704 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
5705 g_return_if_fail(tmpl != NULL);
5707 compose_template_apply(compose, tmpl);
5710 static void compose_ext_editor_cb(gpointer data, guint action,
5713 Compose *compose = (Compose *)data;
5715 compose_exec_ext_editor(compose);
5718 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
5720 compose_destroy(compose);
5723 static void compose_cut_cb(Compose *compose)
5725 if (compose->focused_editable &&
5726 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5727 gtk_editable_cut_clipboard
5728 (GTK_EDITABLE(compose->focused_editable));
5731 static void compose_copy_cb(Compose *compose)
5733 if (compose->focused_editable &&
5734 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5735 gtk_editable_copy_clipboard
5736 (GTK_EDITABLE(compose->focused_editable));
5739 static void compose_paste_cb(Compose *compose)
5741 if (compose->focused_editable &&
5742 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5743 gtk_editable_paste_clipboard
5744 (GTK_EDITABLE(compose->focused_editable));
5747 static void compose_allsel_cb(Compose *compose)
5749 if (compose->focused_editable &&
5750 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5751 gtk_editable_select_region
5752 (GTK_EDITABLE(compose->focused_editable), 0, -1);
5755 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
5757 if (GTK_IS_EDITABLE(widget))
5758 compose->focused_editable = widget;
5761 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
5763 if (compose->modified == FALSE) {
5764 compose->modified = TRUE;
5765 compose_set_title(compose);
5769 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
5772 gtk_stext_set_point(GTK_STEXT(widget),
5773 gtk_editable_get_position(GTK_EDITABLE(widget)));
5777 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
5780 gtk_stext_set_point(GTK_STEXT(widget),
5781 gtk_editable_get_position(GTK_EDITABLE(widget)));
5785 #if 0 /* NEW COMPOSE GUI */
5786 static void compose_toggle_to_cb(gpointer data, guint action,
5789 Compose *compose = (Compose *)data;
5791 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5792 gtk_widget_show(compose->to_hbox);
5793 gtk_widget_show(compose->to_entry);
5794 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
5795 compose->use_to = TRUE;
5797 gtk_widget_hide(compose->to_hbox);
5798 gtk_widget_hide(compose->to_entry);
5799 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
5800 gtk_widget_queue_resize(compose->table_vbox);
5801 compose->use_to = FALSE;
5804 if (addressbook_get_target_compose() == compose)
5805 addressbook_set_target_compose(compose);
5808 static void compose_toggle_cc_cb(gpointer data, guint action,
5811 Compose *compose = (Compose *)data;
5813 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5814 gtk_widget_show(compose->cc_hbox);
5815 gtk_widget_show(compose->cc_entry);
5816 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
5817 compose->use_cc = TRUE;
5819 gtk_widget_hide(compose->cc_hbox);
5820 gtk_widget_hide(compose->cc_entry);
5821 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
5822 gtk_widget_queue_resize(compose->table_vbox);
5823 compose->use_cc = FALSE;
5826 if (addressbook_get_target_compose() == compose)
5827 addressbook_set_target_compose(compose);
5830 static void compose_toggle_bcc_cb(gpointer data, guint action,
5833 Compose *compose = (Compose *)data;
5835 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5836 gtk_widget_show(compose->bcc_hbox);
5837 gtk_widget_show(compose->bcc_entry);
5838 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
5839 compose->use_bcc = TRUE;
5841 gtk_widget_hide(compose->bcc_hbox);
5842 gtk_widget_hide(compose->bcc_entry);
5843 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
5844 gtk_widget_queue_resize(compose->table_vbox);
5845 compose->use_bcc = FALSE;
5848 if (addressbook_get_target_compose() == compose)
5849 addressbook_set_target_compose(compose);
5852 static void compose_toggle_replyto_cb(gpointer data, guint action,
5855 Compose *compose = (Compose *)data;
5857 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5858 gtk_widget_show(compose->reply_hbox);
5859 gtk_widget_show(compose->reply_entry);
5860 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
5861 compose->use_replyto = TRUE;
5863 gtk_widget_hide(compose->reply_hbox);
5864 gtk_widget_hide(compose->reply_entry);
5865 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
5866 gtk_widget_queue_resize(compose->table_vbox);
5867 compose->use_replyto = FALSE;
5871 static void compose_toggle_followupto_cb(gpointer data, guint action,
5874 Compose *compose = (Compose *)data;
5876 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5877 gtk_widget_show(compose->followup_hbox);
5878 gtk_widget_show(compose->followup_entry);
5879 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
5880 compose->use_followupto = TRUE;
5882 gtk_widget_hide(compose->followup_hbox);
5883 gtk_widget_hide(compose->followup_entry);
5884 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
5885 gtk_widget_queue_resize(compose->table_vbox);
5886 compose->use_followupto = FALSE;
5890 static void compose_toggle_attach_cb(gpointer data, guint action,
5893 Compose *compose = (Compose *)data;
5895 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5896 gtk_widget_ref(compose->edit_vbox);
5898 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5899 compose->edit_vbox);
5900 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
5901 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
5903 gtk_widget_show(compose->paned);
5905 gtk_widget_unref(compose->edit_vbox);
5906 gtk_widget_unref(compose->paned);
5908 compose->use_attach = TRUE;
5910 gtk_widget_ref(compose->paned);
5911 gtk_widget_ref(compose->edit_vbox);
5913 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5915 gtk_container_remove(GTK_CONTAINER(compose->paned),
5916 compose->edit_vbox);
5917 gtk_box_pack_start(GTK_BOX(compose->vbox2),
5918 compose->edit_vbox, TRUE, TRUE, 0);
5920 gtk_widget_unref(compose->edit_vbox);
5922 compose->use_attach = FALSE;
5928 static void compose_toggle_sign_cb(gpointer data, guint action,
5931 Compose *compose = (Compose *)data;
5933 if (GTK_CHECK_MENU_ITEM(widget)->active)
5934 compose->use_signing = TRUE;
5936 compose->use_signing = FALSE;
5939 static void compose_toggle_encrypt_cb(gpointer data, guint action,
5942 Compose *compose = (Compose *)data;
5944 if (GTK_CHECK_MENU_ITEM(widget)->active)
5945 compose->use_encryption = TRUE;
5947 compose->use_encryption = FALSE;
5949 #endif /* USE_GPGME */
5951 static void compose_toggle_ruler_cb(gpointer data, guint action,
5954 Compose *compose = (Compose *)data;
5956 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5957 gtk_widget_show(compose->ruler_hbox);
5958 prefs_common.show_ruler = TRUE;
5960 gtk_widget_hide(compose->ruler_hbox);
5961 gtk_widget_queue_resize(compose->edit_vbox);
5962 prefs_common.show_ruler = FALSE;
5966 static void compose_attach_drag_received_cb (GtkWidget *widget,
5967 GdkDragContext *drag_context,
5970 GtkSelectionData *data,
5975 Compose *compose = (Compose *)user_data;
5978 list = uri_list_extract_filenames((const gchar *)data->data);
5979 for (tmp = list; tmp != NULL; tmp = tmp->next)
5980 compose_attach_append(compose, (const gchar *)tmp->data,
5982 list_free_strings(list);
5986 static void compose_insert_drag_received_cb (GtkWidget *widget,
5987 GdkDragContext *drag_context,
5990 GtkSelectionData *data,
5995 Compose *compose = (Compose *)user_data;
5998 list = uri_list_extract_filenames((const gchar *)data->data);
5999 for (tmp = list; tmp != NULL; tmp = tmp->next)
6000 compose_insert_file(compose, (const gchar *)tmp->data);
6001 list_free_strings(list);
6005 #if 0 /* NEW COMPOSE GUI */
6006 static void to_activated(GtkWidget *widget, Compose *compose)
6008 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6009 gtk_widget_grab_focus(compose->newsgroups_entry);
6011 gtk_widget_grab_focus(compose->subject_entry);
6014 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6016 gtk_widget_grab_focus(compose->subject_entry);
6019 static void subject_activated(GtkWidget *widget, Compose *compose)
6021 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6022 gtk_widget_grab_focus(compose->cc_entry);
6023 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6024 gtk_widget_grab_focus(compose->bcc_entry);
6025 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6026 gtk_widget_grab_focus(compose->reply_entry);
6027 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6028 gtk_widget_grab_focus(compose->followup_entry);
6030 gtk_widget_grab_focus(compose->text);
6033 static void cc_activated(GtkWidget *widget, Compose *compose)
6035 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6036 gtk_widget_grab_focus(compose->bcc_entry);
6037 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6038 gtk_widget_grab_focus(compose->reply_entry);
6039 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6040 gtk_widget_grab_focus(compose->followup_entry);
6042 gtk_widget_grab_focus(compose->text);
6045 static void bcc_activated(GtkWidget *widget, Compose *compose)
6047 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6048 gtk_widget_grab_focus(compose->reply_entry);
6049 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6050 gtk_widget_grab_focus(compose->followup_entry);
6052 gtk_widget_grab_focus(compose->text);
6055 static void replyto_activated(GtkWidget *widget, Compose *compose)
6057 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6058 gtk_widget_grab_focus(compose->followup_entry);
6060 gtk_widget_grab_focus(compose->text);
6063 static void followupto_activated(GtkWidget *widget, Compose *compose)
6065 gtk_widget_grab_focus(compose->text);
6069 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6072 Compose *compose = (Compose *)data;
6074 if (GTK_CHECK_MENU_ITEM(widget)->active)
6075 compose->return_receipt = TRUE;
6077 compose->return_receipt = FALSE;
6080 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6082 ComposeHeaderEntry *headerentry)
6084 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6085 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6086 !(event->state & GDK_MODIFIER_MASK) &&
6087 (event->keyval == GDK_BackSpace) &&
6088 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6089 gtk_container_remove
6090 (GTK_CONTAINER(headerentry->compose->header_table),
6091 headerentry->combo);
6092 gtk_container_remove
6093 (GTK_CONTAINER(headerentry->compose->header_table),
6094 headerentry->entry);
6095 headerentry->compose->header_list =
6096 g_slist_remove(headerentry->compose->header_list,
6098 g_free(headerentry);
6102 void compose_headerentry_changed_cb(GtkWidget *entry,
6103 ComposeHeaderEntry *headerentry)
6105 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6106 headerentry->compose->header_list =
6107 g_slist_append(headerentry->compose->header_list,
6109 compose_create_header_entry(headerentry->compose);
6110 gtk_signal_disconnect_by_func
6112 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),