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"
104 #include "foldersel.h"
107 # include "rfc2015.h"
117 #define N_ATTACH_COLS 3
119 #define B64_LINE_SIZE 57
120 #define B64_BUFFSIZE 77
122 #define MAX_REFERENCES_LEN 999
124 static GdkColor quote_color = {0, 0, 0, 0xbfff};
126 static GList *compose_list = NULL;
128 static void compose_set_undo (UndoMain *undostruct,
131 GtkWidget *changewidget);
132 Compose *compose_generic_new (PrefsAccount *account,
136 static Compose *compose_create (PrefsAccount *account,
138 static void compose_toolbar_create (Compose *compose,
139 GtkWidget *container);
140 static GtkWidget *compose_account_option_menu_create
142 static void compose_set_template_menu (Compose *compose);
143 static void compose_template_apply (Compose *compose,
145 static void compose_destroy (Compose *compose);
147 static void compose_entries_set (Compose *compose,
148 const gchar *mailto);
149 static gint compose_parse_header (Compose *compose,
151 static gchar *compose_parse_references (const gchar *ref,
154 static gchar *compose_quote_fmt (Compose *compose,
159 static void compose_reply_set_entry (Compose *compose,
164 followup_and_reply_to);
165 static void compose_reedit_set_entry (Compose *compose,
167 static void compose_insert_sig (Compose *compose);
168 static void compose_insert_file (Compose *compose,
170 static void compose_attach_append (Compose *compose,
172 ContentType cnttype);
173 static void compose_attach_append_with_type(Compose *compose,
176 ContentType cnttype);
177 static void compose_wrap_line (Compose *compose);
178 static void compose_wrap_line_all (Compose *compose);
179 static void compose_set_title (Compose *compose);
181 static PrefsAccount *compose_current_mail_account(void);
182 /* static gint compose_send (Compose *compose); */
183 static gint compose_write_to_file (Compose *compose,
186 static gint compose_write_body_to_file (Compose *compose,
188 static gint compose_save_to_outbox (Compose *compose,
190 static gint compose_remove_reedit_target (Compose *compose);
191 static gint compose_queue (Compose *compose,
194 static void compose_write_attach (Compose *compose,
196 static gint compose_write_headers (Compose *compose,
198 const gchar *charset,
199 EncodingType encoding,
202 static void compose_convert_header (gchar *dest,
206 static void compose_generate_msgid (Compose *compose,
210 static void compose_attach_info_free (AttachInfo *ainfo);
211 static void compose_attach_remove_selected (Compose *compose);
213 static void compose_attach_property (Compose *compose);
214 static void compose_attach_property_create (gboolean *cancelled);
215 static void attach_property_ok (GtkWidget *widget,
216 gboolean *cancelled);
217 static void attach_property_cancel (GtkWidget *widget,
218 gboolean *cancelled);
219 static gint attach_property_delete_event (GtkWidget *widget,
221 gboolean *cancelled);
222 static void attach_property_key_pressed (GtkWidget *widget,
224 gboolean *cancelled);
226 static void compose_exec_ext_editor (Compose *compose);
227 static gint compose_exec_ext_editor_real (const gchar *file);
228 static gboolean compose_ext_editor_kill (Compose *compose);
229 static void compose_input_cb (gpointer data,
231 GdkInputCondition condition);
232 static void compose_set_ext_editor_sensitive (Compose *compose,
235 static gint calc_cursor_xpos (GtkSText *text,
239 static void compose_create_header_entry (Compose *compose);
240 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
242 /* callback functions */
244 static gboolean compose_edit_size_alloc (GtkEditable *widget,
245 GtkAllocation *allocation,
246 GtkSHRuler *shruler);
248 static void toolbar_send_cb (GtkWidget *widget,
250 static void toolbar_send_later_cb (GtkWidget *widget,
252 static void toolbar_draft_cb (GtkWidget *widget,
254 static void toolbar_insert_cb (GtkWidget *widget,
256 static void toolbar_attach_cb (GtkWidget *widget,
258 static void toolbar_sig_cb (GtkWidget *widget,
260 static void toolbar_ext_editor_cb (GtkWidget *widget,
262 static void toolbar_linewrap_cb (GtkWidget *widget,
264 static void toolbar_address_cb (GtkWidget *widget,
267 static void select_account (Compose *compose,
270 static void account_activated (GtkMenuItem *menuitem,
273 static void attach_selected (GtkCList *clist,
278 static void attach_button_pressed (GtkWidget *widget,
279 GdkEventButton *event,
281 static void attach_key_pressed (GtkWidget *widget,
285 static void compose_send_cb (gpointer data,
288 static void compose_send_later_cb (gpointer data,
292 static void compose_draft_cb (gpointer data,
296 static void compose_attach_cb (gpointer data,
299 static void compose_insert_file_cb (gpointer data,
303 static void compose_close_cb (gpointer data,
307 static void compose_address_cb (gpointer data,
310 static void compose_template_activate_cb(GtkWidget *widget,
313 static void compose_ext_editor_cb (gpointer data,
317 static gint compose_delete_cb (GtkWidget *widget,
320 static void compose_destroy_cb (GtkWidget *widget,
323 static void compose_undo_cb (Compose *compose);
324 static void compose_redo_cb (Compose *compose);
325 static void compose_cut_cb (Compose *compose);
326 static void compose_copy_cb (Compose *compose);
327 static void compose_paste_cb (Compose *compose);
328 static void compose_allsel_cb (Compose *compose);
330 static void compose_grab_focus_cb (GtkWidget *widget,
333 static void compose_changed_cb (GtkEditable *editable,
335 static void compose_button_press_cb (GtkWidget *widget,
336 GdkEventButton *event,
339 static void compose_key_press_cb (GtkWidget *widget,
345 static void compose_toggle_to_cb (gpointer data,
348 static void compose_toggle_cc_cb (gpointer data,
351 static void compose_toggle_bcc_cb (gpointer data,
354 static void compose_toggle_replyto_cb (gpointer data,
357 static void compose_toggle_followupto_cb(gpointer data,
360 static void compose_toggle_attach_cb (gpointer data,
364 static void compose_toggle_ruler_cb (gpointer data,
368 static void compose_toggle_sign_cb (gpointer data,
371 static void compose_toggle_encrypt_cb (gpointer data,
375 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
378 static void compose_attach_drag_received_cb (GtkWidget *widget,
379 GdkDragContext *drag_context,
382 GtkSelectionData *data,
386 static void compose_insert_drag_received_cb (GtkWidget *widget,
387 GdkDragContext *drag_context,
390 GtkSelectionData *data,
396 static void to_activated (GtkWidget *widget,
398 static void newsgroups_activated (GtkWidget *widget,
400 static void subject_activated (GtkWidget *widget,
402 static void cc_activated (GtkWidget *widget,
404 static void bcc_activated (GtkWidget *widget,
406 static void replyto_activated (GtkWidget *widget,
408 static void followupto_activated (GtkWidget *widget,
412 static void compose_attach_parts (Compose *compose,
415 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
417 gboolean ignore_replyto,
418 gboolean followup_and_reply_to);
420 void compose_headerentry_changed_cb (GtkWidget *entry,
421 ComposeHeaderEntry *headerentry);
422 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
424 ComposeHeaderEntry *headerentry);
426 static GtkItemFactoryEntry compose_popup_entries[] =
428 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
429 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
430 {N_("/---"), NULL, NULL, 0, "<Separator>"},
431 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
434 static GtkItemFactoryEntry compose_entries[] =
436 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
437 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
438 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
439 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
440 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
441 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
443 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
444 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
445 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
446 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
447 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
448 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
449 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
450 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
451 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
452 {N_("/_Edit/_Wrap current paragraph"), "<alt>L", compose_wrap_line, 0, NULL},
453 {N_("/_Edit/Wrap all long _lines"),
454 "<shift><alt>L", compose_wrap_line_all, 0, NULL},
455 {N_("/_Edit/Edit with e_xternal editor"),
456 "<alt>X", compose_ext_editor_cb, 0, NULL},
458 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
459 {N_("/_Message/_Send"), "<control>Return",
460 compose_send_cb, 0, NULL},
461 {N_("/_Message/Send _later"), "<shift><alt>S",
462 compose_send_later_cb, 0, NULL},
463 {N_("/_Message/Save to _draft folder"),
464 "<alt>D", compose_draft_cb, 0, NULL},
465 #if 0 /* NEW COMPOSE GUI */
466 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
467 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
468 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
469 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
470 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
471 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
472 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
473 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
474 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
477 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
478 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
479 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
480 #endif /* USE_GPGME */
481 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
482 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
483 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
484 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
485 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb , 0, NULL},
486 {N_("/_Tool/_Template"), NULL, NULL, 0, "<Branch>"},
487 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
488 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
491 static GtkTargetEntry compose_mime_types[] =
493 {"text/uri-list", 0, 0}
496 Compose *compose_new(PrefsAccount *account)
498 return compose_generic_new(account, NULL, NULL);
501 Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
505 GtkItemFactory *ifactory;
507 c = compose_generic_new(account, NULL, NULL);
509 filename = procmsg_get_message_file(msginfo);
510 if (filename == NULL)
513 c->bounce_filename = filename;
515 if (msginfo->subject)
516 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
518 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
520 compose_quote_fmt(c, msginfo, "%M", NULL);
521 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
523 ifactory = gtk_item_factory_from_widget(c->popupmenu);
524 menu_set_sensitive(ifactory, "/Add...", FALSE);
525 menu_set_sensitive(ifactory, "/Remove", FALSE);
526 menu_set_sensitive(ifactory, "/Property...", FALSE);
528 ifactory = gtk_item_factory_from_widget(c->menubar);
529 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
530 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
531 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
532 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
533 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
534 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
535 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
536 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
538 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
539 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
541 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
542 menu_set_sensitive(ifactory, "/Tool/Template", FALSE);
544 gtk_widget_set_sensitive(c->insert_btn, FALSE);
545 gtk_widget_set_sensitive(c->attach_btn, FALSE);
546 gtk_widget_set_sensitive(c->sig_btn, FALSE);
547 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
548 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
553 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
555 return compose_generic_new(account, mailto, NULL);
558 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
560 return compose_generic_new(account, NULL, item);
563 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
567 if (item && item->prefs && item->prefs->enable_default_account)
568 account = account_find_from_id(item->prefs->default_account);
570 if (!account) account = cur_account;
571 g_return_val_if_fail(account != NULL, NULL);
573 compose = compose_create(account, COMPOSE_NEW);
574 compose->replyinfo = NULL;
576 if (prefs_common.auto_sig)
577 compose_insert_sig(compose);
578 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
579 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
581 if (account->protocol != A_NNTP) {
583 compose_entries_set(compose, mailto);
585 } else if(item && item->prefs->enable_default_to) {
586 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
588 if (item && item->ret_rcpt) {
589 GtkItemFactory *ifactory;
591 ifactory = gtk_item_factory_from_widget(compose->menubar);
592 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
596 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
599 gtk_widget_grab_focus(compose->subject_entry);
601 if (prefs_common.auto_exteditor)
602 compose_exec_ext_editor(compose);
607 #define CHANGE_FLAGS(msginfo) \
609 if (msginfo->folder->folder->change_flags != NULL) \
610 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
616 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
617 const gchar *followupto, gchar * to)
621 if (!account) account = cur_account;
622 g_return_val_if_fail(account != NULL, NULL);
623 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
625 compose = compose_create(account, COMPOSE_NEW);
627 if (prefs_common.auto_sig)
628 compose_insert_sig(compose);
629 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
630 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
632 compose_entry_append(compose, to, COMPOSE_TO);
633 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
634 gtk_widget_grab_focus(compose->subject_entry);
640 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
641 gboolean ignore_replyto)
643 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
646 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
648 gboolean ignore_replyto)
650 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
653 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
655 gboolean ignore_replyto,
656 gboolean followup_and_reply_to)
659 PrefsAccount *account;
660 PrefsAccount *reply_account;
663 g_return_if_fail(msginfo != NULL);
664 g_return_if_fail(msginfo->folder != NULL);
667 /* select the account set in folderitem's property (if enabled) */
668 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
669 account = account_find_from_id(msginfo->folder->prefs->default_account);
671 /* select the account for the whole folder (IMAP / NNTP) */
673 account = msginfo->folder->folder->account;
675 /* select account by to: and cc: header if enabled */
676 if (prefs_common.reply_account_autosel) {
677 if (!account && msginfo->to) {
679 Xstrdup_a(to, msginfo->to, return);
681 account = account_find_from_address(to);
685 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
687 account = account_find_from_address(cc);
692 /* select current account */
693 if (!account) account = cur_account;
694 g_return_if_fail(account != NULL);
696 if (ignore_replyto && account->protocol == A_NNTP &&
697 !followup_and_reply_to) {
699 account_find_from_address(account->address);
701 reply_account = compose_current_mail_account();
705 reply_account = account;
707 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
708 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
710 CHANGE_FLAGS(msginfo);
712 compose = compose_create(account, COMPOSE_REPLY);
713 compose->replyinfo = procmsg_msginfo_copy(msginfo);
715 #if 0 /* NEW COMPOSE GUI */
716 if (followup_and_reply_to) {
717 gtk_widget_show(compose->to_hbox);
718 gtk_widget_show(compose->to_entry);
719 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
720 compose->use_to = TRUE;
723 if (msginfo->folder && msginfo->folder->ret_rcpt) {
724 GtkItemFactory *ifactory;
726 ifactory = gtk_item_factory_from_widget(compose->menubar);
727 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
730 if (compose_parse_header(compose, msginfo) < 0) return;
731 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
732 followup_and_reply_to);
734 text = GTK_STEXT(compose->text);
735 gtk_stext_freeze(text);
741 if (prefs_common.quotemark && *prefs_common.quotemark)
742 qmark = prefs_common.quotemark;
746 quote_str = compose_quote_fmt(compose, msginfo,
747 prefs_common.quotefmt,
751 if (prefs_common.auto_sig)
752 compose_insert_sig(compose);
754 if (quote && prefs_common.linewrap_quote)
755 compose_wrap_line_all(compose);
757 gtk_editable_set_position(GTK_EDITABLE(text), 0);
758 gtk_stext_set_point(text, 0);
760 gtk_stext_thaw(text);
761 gtk_widget_grab_focus(compose->text);
763 if (prefs_common.auto_exteditor)
764 compose_exec_ext_editor(compose);
768 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
773 g_return_val_if_fail(mimeinfo != NULL, NULL);
775 base = mimeinfo->filename ? mimeinfo->filename
776 : mimeinfo->name ? mimeinfo->name : NULL;
778 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
779 filename = g_strdup_printf("%s%smimetmp.%08x.html",
786 base = base ? base : "";
787 base = g_basename(base);
789 filename = g_strdup_printf("%s%smimetmp.%08x",
797 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
803 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
807 if (!partinfo) return NULL;
809 filename = procmime_get_file_name(partinfo);
811 if (procmime_get_part(filename, source, partinfo) < 0)
813 (_("Can't get the part of multipart message."));
818 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
826 gint boundary_len = 0;
828 glong fpos, prev_fpos;
833 g_return_if_fail(msginfo != NULL);
837 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
838 mimeinfo = procmime_scan_mime_header(fp);
839 if (!mimeinfo) break;
841 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
842 rfc2015_is_encrypted(mimeinfo)) {
843 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
845 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
846 !msginfo->plaintext_file &&
847 !msginfo->decryption_failed) {
848 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
849 if (msginfo->plaintext_file &&
850 !msginfo->decryption_failed) {
858 #else /* !USE_GPGME */
859 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
860 mimeinfo = procmime_scan_mime_header(fp);
861 #endif /* USE_GPGME */
864 if (!mimeinfo) return;
865 if (mimeinfo->mime_type == MIME_TEXT)
868 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
870 g_return_if_fail(mimeinfo != NULL);
871 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
873 if (mimeinfo->mime_type == MIME_MULTIPART) {
874 g_return_if_fail(mimeinfo->boundary != NULL);
875 g_return_if_fail(mimeinfo->sub == NULL);
877 g_return_if_fail(fp != NULL);
879 boundary = mimeinfo->boundary;
882 boundary_len = strlen(boundary);
884 /* look for first boundary */
885 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
886 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
893 if ((fpos = ftell(fp)) < 0) {
899 for (npart = 0;; npart++) {
901 gboolean eom = FALSE;
905 partinfo = procmime_scan_mime_header(fp);
906 if (!partinfo) break;
909 procmime_mimeinfo_insert(mimeinfo, partinfo);
911 procmime_mimeinfo_free(partinfo);
913 /* look for next boundary */
915 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
916 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
917 if (buf[2 + boundary_len] == '-' &&
918 buf[2 + boundary_len + 1] == '-')
924 eom = TRUE; /* broken MIME message */
927 partinfo->size = fpos - prev_fpos - strlen(buf);
932 source = procmsg_get_message_file_path(msginfo);
934 g_return_if_fail(mimeinfo != NULL);
936 if (!mimeinfo->main && mimeinfo->parent)
938 filename = mime_extract_file(source, mimeinfo);
940 compose_attach_append_with_type(compose, filename,
941 mimeinfo->content_type,
942 mimeinfo->mime_type);
947 if (mimeinfo->sub && mimeinfo->sub->children)
949 filename = mime_extract_file(source, mimeinfo->sub);
951 compose_attach_append_with_type(compose, filename,
952 mimeinfo->content_type,
953 mimeinfo->sub->mime_type);
958 if (mimeinfo->children) {
961 child = mimeinfo->children;
963 filename = mime_extract_file(source, child);
965 compose_attach_append_with_type(compose, filename,
977 procmime_mimeinfo_free_all(mimeinfo);
981 #define INSERT_FW_HEADER(var, hdr) \
982 if (msginfo->var && *msginfo->var) { \
983 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
984 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
985 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
988 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
992 /* PrefsAccount *account; */
995 g_return_val_if_fail(msginfo != NULL, NULL);
996 g_return_val_if_fail(msginfo->folder != NULL, NULL);
998 account = msginfo->folder->folder->account;
999 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1001 Xstrdup_a(to, msginfo->to, return NULL);
1002 extract_address(to);
1003 account = account_find_from_address(to);
1006 if(!account && prefs_common.forward_account_autosel) {
1008 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1009 extract_address(cc);
1010 account = account_find_from_address(cc);
1014 if (account == NULL) {
1015 account = cur_account;
1017 account = msginfo->folder->folder->account;
1018 if (!account) account = cur_account;
1021 g_return_val_if_fail(account != NULL, NULL);
1023 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1024 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1025 CHANGE_FLAGS(msginfo);
1027 compose = compose_create(account, COMPOSE_FORWARD);
1029 if (msginfo->subject && *msginfo->subject) {
1030 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1031 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1035 text = GTK_STEXT(compose->text);
1036 gtk_stext_freeze(text);
1041 msgfile = procmsg_get_message_file_path(msginfo);
1042 if (!is_file_exist(msgfile))
1043 g_warning(_("%s: file not exist\n"), msgfile);
1045 compose_attach_append(compose, msgfile,
1046 MIME_MESSAGE_RFC822);
1053 if (prefs_common.fw_quotemark && *prefs_common.fw_quotemark)
1054 qmark = prefs_common.fw_quotemark;
1058 quote_str = compose_quote_fmt(compose, msginfo,
1059 prefs_common.fw_quotefmt, qmark);
1060 compose_attach_parts(compose, msginfo);
1063 if (prefs_common.auto_sig)
1064 compose_insert_sig(compose);
1066 if (prefs_common.linewrap_quote)
1067 compose_wrap_line_all(compose);
1069 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1070 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1072 gtk_stext_thaw(text);
1073 #if 0 /* NEW COMPOSE GUI */
1074 if (account->protocol != A_NNTP)
1075 gtk_widget_grab_focus(compose->to_entry);
1077 gtk_widget_grab_focus(compose->newsgroups_entry);
1079 gtk_widget_grab_focus(compose->header_last->entry);
1081 if (prefs_common.auto_exteditor)
1082 compose_exec_ext_editor(compose);
1087 #undef INSERT_FW_HEADER
1089 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1096 g_return_val_if_fail(msginfo_list != NULL, NULL);
1098 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1099 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1103 if (account == NULL) {
1104 account = cur_account;
1106 account = msginfo->folder->folder->account;
1107 if (!account) account = cur_account;
1110 g_return_val_if_fail(account != NULL, NULL);
1112 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1113 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1114 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1115 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1118 compose = compose_create(account, COMPOSE_FORWARD);
1120 text = GTK_STEXT(compose->text);
1121 gtk_stext_freeze(text);
1123 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1124 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1125 if (!is_file_exist(msgfile))
1126 g_warning(_("%s: file not exist\n"), msgfile);
1128 compose_attach_append(compose, msgfile,
1129 MIME_MESSAGE_RFC822);
1133 if (prefs_common.auto_sig)
1134 compose_insert_sig(compose);
1136 if (prefs_common.linewrap_quote)
1137 compose_wrap_line_all(compose);
1139 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1140 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1142 gtk_stext_thaw(text);
1143 #if 0 /* NEW COMPOSE GUI */
1144 if (account->protocol != A_NNTP)
1145 gtk_widget_grab_focus(compose->to_entry);
1147 gtk_widget_grab_focus(compose->newsgroups_entry);
1153 void compose_reedit(MsgInfo *msginfo)
1156 PrefsAccount *account;
1159 gchar buf[BUFFSIZE];
1161 g_return_if_fail(msginfo != NULL);
1162 g_return_if_fail(msginfo->folder != NULL);
1164 if (msginfo->folder->stype == F_QUEUE) {
1165 gchar account_address[BUFFSIZE];
1166 if (!get_header_from_msginfo(msginfo, account_address, sizeof(account_address), "S:")) {
1167 account = account_find_from_address(account_address);
1170 account = msginfo->folder->folder->account;
1172 if (!account && prefs_common.reedit_account_autosel) {
1173 gchar from[BUFFSIZE];
1174 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1175 extract_address(from);
1176 account = account_find_from_address(from);
1179 if (!account) account = cur_account;
1180 g_return_if_fail(account != NULL);
1182 compose = compose_create(account, COMPOSE_REEDIT);
1183 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1185 if (compose_parse_header(compose, msginfo) < 0) return;
1186 compose_reedit_set_entry(compose, msginfo);
1188 text = GTK_STEXT(compose->text);
1189 gtk_stext_freeze(text);
1191 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1192 g_warning(_("Can't get text part\n"));
1194 while (fgets(buf, sizeof(buf), fp) != NULL)
1195 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1198 compose_attach_parts(compose, msginfo);
1200 gtk_stext_thaw(text);
1201 gtk_widget_grab_focus(compose->text);
1203 if (prefs_common.auto_exteditor)
1204 compose_exec_ext_editor(compose);
1207 GList *compose_get_compose_list(void)
1209 return compose_list;
1212 void compose_entry_append(Compose *compose, const gchar *address,
1213 ComposeEntryType type)
1219 if (!address || *address == '\0') return;
1221 #if 0 /* NEW COMPOSE GUI */
1224 entry = GTK_ENTRY(compose->cc_entry);
1227 entry = GTK_ENTRY(compose->bcc_entry);
1229 case COMPOSE_NEWSGROUPS:
1230 entry = GTK_ENTRY(compose->newsgroups_entry);
1234 entry = GTK_ENTRY(compose->to_entry);
1238 text = gtk_entry_get_text(entry);
1240 gtk_entry_append_text(entry, ", ");
1241 gtk_entry_append_text(entry, address);
1249 header = N_("Bcc:");
1251 case COMPOSE_REPLYTO:
1252 header = N_("Reply-To:");
1254 case COMPOSE_NEWSGROUPS:
1255 header = N_("Newsgroups:");
1257 case COMPOSE_FOLLOWUPTO:
1258 header = N_( "Followup-To:");
1265 header = prefs_common.trans_hdr ? gettext(header) : header;
1267 compose_add_header_entry(compose, header, (gchar *)address);
1270 static void compose_entries_set(Compose *compose, const gchar *mailto)
1272 gchar *subject = NULL;
1280 Xstrdup_a(tmp_mailto, mailto, return);
1284 p = strchr(tmp_mailto, '?');
1291 gchar *field, *value;
1308 if (*value == '\0') continue;
1310 if (!g_strcasecmp(field, "subject")) {
1311 Xalloca(subject, strlen(value) + 1, return);
1312 decode_uri(subject, value);
1313 } else if (!g_strcasecmp(field, "cc")) {
1315 } else if (!g_strcasecmp(field, "bcc")) {
1317 } else if (!g_strcasecmp(field, "body")) {
1318 Xalloca(body, strlen(value) + 1, return);
1319 decode_uri(body, value);
1324 compose_entry_append(compose, to, COMPOSE_TO);
1326 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1328 compose_entry_append(compose, cc, COMPOSE_CC);
1330 compose_entry_append(compose, bcc, COMPOSE_BCC);
1332 gtk_stext_insert(GTK_STEXT(compose->text),
1333 NULL, NULL, NULL, body, -1);
1334 gtk_stext_insert(GTK_STEXT(compose->text),
1335 NULL, NULL, NULL, "\n", 1);
1339 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1341 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1342 {"Cc:", NULL, FALSE},
1343 {"References:", NULL, FALSE},
1344 {"Bcc:", NULL, FALSE},
1345 {"Newsgroups:", NULL, FALSE},
1346 {"Followup-To:", NULL, FALSE},
1347 {"X-Mailing-List:", NULL, FALSE},
1348 {"X-BeenThere:", NULL, FALSE},
1349 {NULL, NULL, FALSE}};
1359 H_X_MAILING_LIST = 6,
1365 g_return_val_if_fail(msginfo != NULL, -1);
1367 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1368 procheader_get_header_fields(fp, hentry);
1371 if (hentry[H_REPLY_TO].body != NULL) {
1372 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1373 compose->replyto = hentry[H_REPLY_TO].body;
1374 hentry[H_REPLY_TO].body = NULL;
1376 if (hentry[H_CC].body != NULL) {
1377 conv_unmime_header_overwrite(hentry[H_CC].body);
1378 compose->cc = hentry[H_CC].body;
1379 hentry[H_CC].body = NULL;
1381 if (hentry[H_X_MAILING_LIST].body != NULL) {
1382 /* this is good enough to parse debian-devel */
1383 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1384 g_return_val_if_fail(buf != NULL, -1 );
1385 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1386 compose->mailinglist = g_strdup(buf);
1388 g_free(hentry[H_X_MAILING_LIST].body);
1389 hentry[H_X_MAILING_LIST].body = NULL ;
1391 if (hentry[H_X_BEENTHERE].body != NULL) {
1392 /* this is good enough to parse the sylpheed-claws lists */
1393 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1394 g_return_val_if_fail(buf != NULL, -1 );
1395 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1396 compose->mailinglist = g_strdup(buf);
1398 g_free(hentry[H_X_BEENTHERE].body);
1399 hentry[H_X_BEENTHERE].body = NULL ;
1401 if (hentry[H_REFERENCES].body != NULL) {
1402 if (compose->mode == COMPOSE_REEDIT)
1403 compose->references = hentry[H_REFERENCES].body;
1405 compose->references = compose_parse_references
1406 (hentry[H_REFERENCES].body, msginfo->msgid);
1407 g_free(hentry[H_REFERENCES].body);
1409 hentry[H_REFERENCES].body = NULL;
1411 if (hentry[H_BCC].body != NULL) {
1412 if (compose->mode == COMPOSE_REEDIT) {
1413 conv_unmime_header_overwrite(hentry[H_BCC].body);
1414 compose->bcc = hentry[H_BCC].body;
1416 g_free(hentry[H_BCC].body);
1417 hentry[H_BCC].body = NULL;
1419 if (hentry[H_NEWSGROUPS].body != NULL) {
1420 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1421 hentry[H_NEWSGROUPS].body = NULL;
1423 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1424 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1425 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1426 hentry[H_FOLLOWUP_TO].body = NULL;
1429 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1430 compose->inreplyto = g_strdup(msginfo->inreplyto);
1431 else if (compose->mode != COMPOSE_REEDIT &&
1432 msginfo->msgid && *msginfo->msgid) {
1433 compose->inreplyto = g_strdup(msginfo->msgid);
1435 if (!compose->references) {
1436 if (msginfo->inreplyto && *msginfo->inreplyto)
1437 compose->references =
1438 g_strdup_printf("<%s>\n\t<%s>",
1442 compose->references =
1443 g_strconcat("<", msginfo->msgid, ">",
1451 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1453 GSList *ref_id_list, *cur;
1457 ref_id_list = references_list_append(NULL, ref);
1458 if (!ref_id_list) return NULL;
1459 if (msgid && *msgid)
1460 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1465 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1466 /* "<" + Message-ID + ">" + CR+LF+TAB */
1467 len += strlen((gchar *)cur->data) + 5;
1469 if (len > MAX_REFERENCES_LEN) {
1470 /* remove second message-ID */
1471 if (ref_id_list && ref_id_list->next &&
1472 ref_id_list->next->next) {
1473 g_free(ref_id_list->next->data);
1474 ref_id_list = g_slist_remove
1475 (ref_id_list, ref_id_list->next->data);
1477 slist_free_strings(ref_id_list);
1478 g_slist_free(ref_id_list);
1485 new_ref = g_string_new("");
1486 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1487 if (new_ref->len > 0)
1488 g_string_append(new_ref, "\n\t");
1489 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1492 slist_free_strings(ref_id_list);
1493 g_slist_free(ref_id_list);
1495 new_ref_str = new_ref->str;
1496 g_string_free(new_ref, FALSE);
1501 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1502 const gchar *fmt, const gchar *qmark)
1504 GtkSText *text = GTK_STEXT(compose->text);
1505 gchar *quote_str = NULL;
1510 if (qmark != NULL) {
1511 quote_fmt_init(msginfo, NULL);
1512 quote_fmt_scan_string(qmark);
1515 buf = quote_fmt_get_buffer();
1517 alertpanel_error(_("Quote mark format error."));
1519 Xstrdup_a(quote_str, buf, return NULL)
1522 if (fmt && *fmt != '\0') {
1523 quote_fmt_init(msginfo, quote_str);
1524 quote_fmt_scan_string(fmt);
1527 buf = quote_fmt_get_buffer();
1529 alertpanel_error(_("Message reply/forward format error."));
1535 gtk_stext_freeze(text);
1536 gtk_stext_set_point(text, 0);
1537 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
1539 for (p = buf; *p != '\0'; ) {
1540 lastp = strchr(p, '\n');
1541 len = lastp ? lastp - p + 1 : -1;
1542 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1549 gtk_stext_thaw(text);
1554 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1555 gboolean to_all, gboolean ignore_replyto,
1556 gboolean followup_and_reply_to)
1561 GHashTable *to_table;
1563 g_return_if_fail(compose->account != NULL);
1564 g_return_if_fail(msginfo != NULL);
1566 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1567 compose_entry_append(compose,
1568 ((compose->mailinglist && !ignore_replyto)
1569 ? compose->mailinglist
1570 : (compose->replyto && !ignore_replyto)
1572 : msginfo->from ? msginfo->from : ""),
1574 if (compose->account->protocol == A_NNTP) {
1576 compose_entry_append
1577 (compose, msginfo->from ? msginfo->from : "",
1580 compose_entry_append
1582 compose->followup_to ? compose->followup_to
1583 : compose->newsgroups ? compose->newsgroups
1585 COMPOSE_NEWSGROUPS);
1588 if (msginfo->subject && *msginfo->subject) {
1589 gchar *buf, *buf2, *p;
1591 buf = g_strdup(msginfo->subject);
1592 while (!strncasecmp(buf, "Re:", 3)) {
1594 while (isspace(*p)) p++;
1595 memmove(buf, p, strlen(p) + 1);
1598 buf2 = g_strdup_printf("Re: %s", buf);
1599 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1603 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1605 if (!to_all || compose->account->protocol == A_NNTP) return;
1607 from = g_strdup(compose->replyto ? compose->replyto :
1608 msginfo->from ? msginfo->from : "");
1609 extract_address(from);
1611 cc_list = address_list_append(NULL, msginfo->to);
1612 cc_list = address_list_append(cc_list, compose->cc);
1614 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1615 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1616 if (compose->account)
1617 g_hash_table_insert(to_table, compose->account->address,
1618 GINT_TO_POINTER(1));
1620 /* remove address on To: and that of current account */
1621 for (cur = cc_list; cur != NULL; ) {
1622 GSList *next = cur->next;
1624 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1625 cc_list = g_slist_remove(cc_list, cur->data);
1627 g_hash_table_insert(to_table, cur->data, cur);
1631 g_hash_table_destroy(to_table);
1635 for (cur = cc_list; cur != NULL; cur = cur->next)
1636 compose_entry_append(compose, (gchar *)cur->data,
1638 slist_free_strings(cc_list);
1639 g_slist_free(cc_list);
1643 #define SET_ENTRY(entry, str) \
1646 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1649 #define SET_ADDRESS(type, str) \
1652 compose_entry_append(compose, str, type); \
1655 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1657 g_return_if_fail(msginfo != NULL);
1659 SET_ENTRY(subject_entry, msginfo->subject);
1660 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1661 SET_ADDRESS(COMPOSE_CC, compose->cc);
1662 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1663 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1665 #if 0 /* NEW COMPOSE GUI */
1667 GtkItemFactory *ifactory;
1668 GtkWidget *menuitem;
1670 ifactory = gtk_item_factory_from_widget(compose->menubar);
1671 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1672 gtk_check_menu_item_set_active
1673 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1675 if (compose->replyto) {
1676 GtkItemFactory *ifactory;
1677 GtkWidget *menuitem;
1679 ifactory = gtk_item_factory_from_widget(compose->menubar);
1680 menuitem = gtk_item_factory_get_item
1681 (ifactory, "/Message/Reply to");
1682 gtk_check_menu_item_set_active
1683 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1691 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1698 size_t buf_len = 128;
1700 if (strlen(sigfile) < 2)
1703 sigprg = popen(sigfile+1, "r");
1706 buf = g_malloc(buf_len);
1709 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1710 "Unable to insert signature (malloc failed)\n", -1);
1716 while (!feof(sigprg)) {
1717 bzero(buf, buf_len);
1718 fread(buf, buf_len-1, 1, sigprg);
1719 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1727 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1728 "Can't exec file: ", -1);
1729 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1734 static void compose_insert_sig(Compose *compose)
1738 if (compose->account && compose->account->sig_path)
1739 sigfile = g_strdup(compose->account->sig_path);
1741 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1742 DEFAULT_SIGNATURE, NULL);
1745 if (!is_file_or_fifo_exist(sigfile) & (sigfile[0] != '|')) {
1750 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1751 if (prefs_common.sig_sep) {
1752 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1753 prefs_common.sig_sep, -1);
1754 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1758 if (sigfile[0] == '|')
1760 compose_exec_sig(compose, sigfile);
1764 compose_insert_file(compose, sigfile);
1769 static void compose_insert_file(Compose *compose, const gchar *file)
1771 GtkSText *text = GTK_STEXT(compose->text);
1772 gchar buf[BUFFSIZE];
1776 g_return_if_fail(file != NULL);
1778 if ((fp = fopen(file, "r")) == NULL) {
1779 FILE_OP_ERROR(file, "fopen");
1783 gtk_stext_freeze(text);
1785 while (fgets(buf, sizeof(buf), fp) != NULL) {
1786 /* Strip <CR> if DOS/Windoze file, replace <CR> with <LF> if MAC file */
1788 if (len > 1 && buf[len - 2] == '\r' && buf[len - 1] == '\n') {
1789 buf[len - 2] = '\n';
1790 buf[len - 1] = '\0';
1793 if (buf[len] == '\r')
1797 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1800 gtk_stext_thaw(text);
1805 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1806 ContentType cnttype)
1808 gchar *text[N_ATTACH_COLS];
1811 text[COL_MIMETYPE] = ainfo->content_type;
1812 text[COL_SIZE] = to_human_readable(ainfo->size);
1813 text[COL_NAME] = ainfo->name;
1815 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1816 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1818 if (cnttype != MIME_MESSAGE_RFC822)
1819 compose_changed_cb(NULL, compose);
1822 static void compose_attach_append_with_type(Compose *compose,
1825 ContentType cnttype)
1830 if (!is_file_exist(file)) {
1831 g_warning(_("File %s doesn't exist\n"), file);
1834 if ((size = get_file_size(file)) < 0) {
1835 g_warning(_("Can't get file size of %s\n"), file);
1839 alertpanel_notice(_("File %s is empty\n"), file);
1842 #if 0 /* NEW COMPOSE GUI */
1843 if (!compose->use_attach) {
1844 GtkItemFactory *ifactory;
1845 GtkWidget *menuitem;
1847 ifactory = gtk_item_factory_from_widget(compose->menubar);
1848 menuitem = gtk_item_factory_get_item(ifactory,
1850 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1854 ainfo = g_new0(AttachInfo, 1);
1855 ainfo->file = g_strdup(file);
1857 if (cnttype == MIME_MESSAGE_RFC822) {
1858 ainfo->encoding = ENC_7BIT;
1859 ainfo->name = g_strdup_printf(_("Message: %s"),
1862 ainfo->encoding = ENC_BASE64;
1863 ainfo->name = g_strdup(g_basename(file));
1866 ainfo->content_type = g_strdup(type);
1869 compose_attach_info(compose, ainfo, cnttype);
1872 static void compose_attach_append(Compose *compose, const gchar *file,
1873 ContentType cnttype)
1876 gchar *text[N_ATTACH_COLS];
1880 if (!is_file_exist(file)) {
1881 g_warning(_("File %s doesn't exist\n"), file);
1884 if ((size = get_file_size(file)) < 0) {
1885 g_warning(_("Can't get file size of %s\n"), file);
1889 alertpanel_notice(_("File %s is empty\n"), file);
1892 #if 0 /* NEW COMPOSE GUI */
1893 if (!compose->use_attach) {
1894 GtkItemFactory *ifactory;
1895 GtkWidget *menuitem;
1897 ifactory = gtk_item_factory_from_widget(compose->menubar);
1898 menuitem = gtk_item_factory_get_item(ifactory,
1900 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1904 ainfo = g_new0(AttachInfo, 1);
1905 ainfo->file = g_strdup(file);
1907 if (cnttype == MIME_MESSAGE_RFC822) {
1908 ainfo->content_type = g_strdup("message/rfc822");
1909 ainfo->encoding = ENC_7BIT;
1910 ainfo->name = g_strdup_printf(_("Message: %s"),
1913 ainfo->content_type = procmime_get_mime_type(file);
1914 if (!ainfo->content_type)
1915 ainfo->content_type =
1916 g_strdup("application/octet-stream");
1917 ainfo->encoding = ENC_BASE64;
1918 ainfo->name = g_strdup(g_basename(file));
1922 compose_attach_info(compose, ainfo, cnttype);
1925 #define GET_CHAR(pos, buf, len) \
1927 if (text->use_wchar) \
1928 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
1930 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
1935 static void compose_wrap_line(Compose *compose)
1937 GtkSText *text = GTK_STEXT(compose->text);
1938 gint ch_len, last_ch_len;
1939 gchar cbuf[MB_LEN_MAX], last_ch;
1943 gint p_start, p_end;
1944 gint line_pos, cur_pos;
1945 gint line_len, cur_len;
1948 gtk_stext_freeze(text);
1950 text_len = gtk_stext_get_length(text);
1952 /* check to see if the point is on the paragraph mark (empty line). */
1953 cur_pos = gtk_stext_get_point(text);
1954 GET_CHAR(cur_pos, cbuf, ch_len);
1955 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
1957 goto compose_end; /* on the paragraph mark */
1958 GET_CHAR(cur_pos - 1, cbuf, ch_len);
1959 if (ch_len == 1 && *cbuf == '\n')
1960 goto compose_end; /* on the paragraph mark */
1963 /* find paragraph start. */
1964 line_end = quoted = 0;
1965 for (p_start = cur_pos; p_start >= 0; --p_start) {
1966 GET_CHAR(p_start, cbuf, ch_len);
1967 if (ch_len == 1 && *cbuf == '\n') {
1969 goto compose_end; /* quoted part */
1976 if (ch_len == 1 && strchr(">:#", *cbuf))
1978 else if (ch_len != 1 || !isspace(*cbuf))
1987 /* find paragraph end. */
1989 for (p_end = cur_pos; p_end < text_len; p_end++) {
1990 GET_CHAR(p_end, cbuf, ch_len);
1991 if (ch_len == 1 && *cbuf == '\n') {
1998 if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
1999 goto compose_end; /* quoted part */
2004 if (p_end >= text_len)
2007 if (p_start >= p_end)
2010 line_len = cur_len = 0;
2014 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2017 GET_CHAR(cur_pos, cbuf, ch_len);
2024 if (ch_len == 1 && isspace(*cbuf))
2027 if (ch_len == 1 && *cbuf == '\n') {
2029 if (last_ch_len == 1 && !isspace(last_ch)) {
2030 if (cur_pos + 1 < p_end) {
2031 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2032 if (ch_len == 1 && !isspace(*cbuf))
2036 gtk_stext_set_point(text, cur_pos + 1);
2037 gtk_stext_backward_delete(text, 1);
2039 gtk_stext_set_point(text, cur_pos);
2040 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2050 last_ch_len = ch_len;
2054 line_pos = cur_pos + 1;
2055 line_len = cur_len + ch_len;
2058 if (cur_len + ch_len > prefs_common.linewrap_len &&
2062 GET_CHAR(line_pos - 1, cbuf, ch_len);
2063 if (ch_len == 1 && isspace(*cbuf)) {
2064 gtk_stext_set_point(text, line_pos);
2065 gtk_stext_backward_delete(text, 1);
2074 gtk_stext_set_point(text, line_pos);
2075 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2079 cur_len = cur_len - line_len + ch_len;
2085 line_pos = cur_pos + 1;
2086 line_len = cur_len + ch_len;
2092 gtk_stext_thaw(text);
2095 /* return indent length */
2096 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2098 gint indent_len = 0;
2100 gchar cbuf[MB_LEN_MAX];
2102 for (i = start_pos; i < text_len; i++) {
2103 GET_CHAR(i, cbuf, ch_len);
2106 /* allow space, tab, > or | */
2107 if (cbuf[0] != ' ' && cbuf[0] != '\t' &&
2108 cbuf[0] != '>' && cbuf[0] != '|')
2116 /* insert quotation string when line was wrapped */
2117 static guint ins_quote(GtkSText *text, guint quote_len, guint indent_len,
2118 guint prev_line_pos, guint text_len,
2125 for (i = 0; i < indent_len; i++) {
2126 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2127 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2129 ins_len = indent_len;
2131 gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
2132 ins_len = quote_len;
2140 /* Darko: used when I debug wrapping */
2141 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2146 printf("%d [", pos);
2147 for (i = pos; i < tlen; i++) {
2148 ch = GTK_STEXT_INDEX(text, i);
2149 if (breakoncr && ch == '\n')
2157 static void compose_wrap_line_all(Compose *compose)
2159 GtkSText *text = GTK_STEXT(compose->text);
2161 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2162 gint line_len = 0, cur_len = 0;
2164 gboolean is_new_line = TRUE, do_delete = FALSE;
2165 guint qlen = 0, i_len = 0;
2166 guint linewrap_quote = prefs_common.linewrap_quote;
2167 guint linewrap_len = prefs_common.linewrap_len;
2168 gchar *qfmt = prefs_common.quotemark;
2169 gchar cbuf[MB_LEN_MAX];
2171 gtk_stext_freeze(text);
2173 /* make text buffer contiguous */
2174 /* gtk_stext_compact_buffer(text); */
2176 tlen = gtk_stext_get_length(text);
2178 for (; cur_pos < tlen; cur_pos++) {
2179 /* mark position of new line - needed for quotation wrap */
2180 if (linewrap_quote && is_new_line) {
2181 qlen = gtkut_text_str_compare
2182 (text, cur_pos, tlen, qfmt);
2183 is_new_line = FALSE;
2185 i_len = get_indent_length(text, cur_pos, tlen);
2190 printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
2191 dump_text(text, p_pos, tlen, 1);
2195 GET_CHAR(cur_pos, cbuf, ch_len);
2197 /* fix line length for tabs */
2198 if (ch_len == 1 && *cbuf == '\t') {
2199 guint tab_width = text->default_tab_width;
2200 guint tab_offset = line_len % tab_width;
2203 printf("found tab at pos=%d line_len=%d ", cur_pos,
2207 line_len += tab_width - tab_offset - 1;
2211 printf("new_len=%d\n", line_len);
2215 /* we have encountered line break */
2216 if (ch_len == 1 && *cbuf == '\n') {
2219 gchar cb[MB_CUR_MAX];
2222 printf("found CR at %d next line is ", cur_pos);
2223 dump_text(text, cur_pos + 1, tlen, 1);
2225 /* if it's just quotation + newline skip it */
2226 if (i_len && (cur_pos + 1 < tlen)) {
2227 /* check if text at new line matches indent */
2228 ilen = gtkut_text_str_compare_n
2229 (text, cur_pos + 1, p_pos, i_len, tlen);
2230 if (cur_pos + ilen < tlen) {
2231 GET_CHAR(cur_pos + ilen + 1, cb, clen);
2232 /* no need to join the lines */
2233 if (clen == 1 && cb[0] == '\n')
2236 /* if it's just newline skip it */
2237 } else if (do_delete && (cur_pos + 1 < tlen)) {
2238 GET_CHAR(cur_pos + 1, cb, clen);
2239 /* no need to join the lines */
2240 if (clen == 1 && cb[0] == '\n')
2245 printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
2246 qlen, line_len, linewrap_len, do_delete);
2248 /* should we delete to perform smart wrapping */
2249 if (line_len < linewrap_len && do_delete) {
2250 /* get rid of newline */
2251 gtk_stext_set_point(text, cur_pos);
2252 gtk_stext_forward_delete(text, 1);
2255 /* if text starts with quote fmt or with
2256 indent string, delete them */
2258 ilen = gtkut_text_str_compare_n
2259 (text, cur_pos, p_pos, i_len,
2262 gtk_stext_forward_delete(text,
2267 if (gtkut_text_str_compare
2268 (text, cur_pos, tlen, qfmt)) {
2269 gtk_stext_forward_delete
2275 GET_CHAR(cur_pos, cb, clen);
2277 /* insert space if it's alphanumeric */
2278 if ((cur_pos != line_pos) &&
2279 ((clen > 1) || isalnum(cb[0]))) {
2280 gtk_stext_insert(text, NULL, NULL,
2282 /* gtk_text_compact_buffer(text); */
2286 /* and start over with current line */
2287 cur_pos = p_pos - 1;
2289 line_len = cur_len = 0;
2294 printf("after delete l_pos=");
2295 dump_text(text, line_pos, tlen, 1);
2300 /* mark new line beginning */
2301 line_pos = cur_pos + 1;
2302 line_len = cur_len = 0;
2314 /* possible line break */
2315 if (ch_len == 1 && isspace(*cbuf)) {
2316 line_pos = cur_pos + 1;
2317 line_len = cur_len + ch_len;
2320 /* are we over wrapping length set in preferences ? */
2321 if (cur_len + ch_len > linewrap_len) {
2325 printf("should wrap cur_pos=%d ", cur_pos);
2326 dump_text(text, p_pos, tlen, 1);
2327 dump_text(text, line_pos, tlen, 1);
2329 /* force wrapping if it is one long word but not URL */
2330 if (p_pos + i_len == line_pos)
2331 if (!gtkut_text_is_uri_string
2332 (text, line_pos, tlen))
2333 line_pos = cur_pos - 1;
2335 printf("new line_pos=%d\n", line_pos);
2338 GET_CHAR(line_pos - 1, cbuf, clen);
2340 /* if next character is space delete it */
2341 if (clen == 1 && isspace(*cbuf)) {
2342 if (p_pos + i_len != line_pos ||
2343 !gtkut_text_is_uri_string
2344 (text, line_pos, tlen)) {
2345 gtk_stext_set_point(text, line_pos);
2346 gtk_stext_backward_delete(text, 1);
2355 /* if it is URL at beginning of line don't wrap */
2356 if (p_pos + i_len == line_pos &&
2357 gtkut_text_is_uri_string(text, line_pos, tlen)) {
2359 printf("found URL at ");
2360 dump_text(text, line_pos, tlen, 1);
2366 gtk_stext_set_point(text, line_pos);
2367 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2368 /* gtk_stext_compact_buffer(text); */
2371 /* for loop will increase it */
2372 cur_pos = line_pos - 1;
2373 /* start over with current line */
2379 printf("after CR insert ");
2380 dump_text(text, line_pos, tlen, 1);
2381 dump_text(text, cur_pos, tlen, 1);
2384 /* should we insert quotation ? */
2385 if (linewrap_quote && qlen) {
2386 /* only if line is not already quoted */
2387 if (!gtkut_text_str_compare
2388 (text, line_pos, tlen, qfmt)) {
2391 if (line_pos - p_pos > i_len) {
2396 /* gtk_stext_compact_buffer(text); */
2400 printf("after quote insert ");
2401 dump_text(text, line_pos, tlen, 1);
2409 line_pos = cur_pos + 1;
2410 line_len = cur_len + ch_len;
2412 /* advance to next character in buffer */
2416 gtk_stext_thaw(text);
2420 static void compose_set_title(Compose *compose)
2425 edited = compose->modified ? _(" [Edited]") : "";
2426 if (compose->account && compose->account->address)
2427 str = g_strdup_printf(_("%s - Compose message%s"),
2428 compose->account->address, edited);
2430 str = g_strdup_printf(_("Compose message%s"), edited);
2431 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2436 * compose_current_mail_account:
2438 * Find a current mail account (the currently selected account, or the
2439 * default account, if a news account is currently selected). If a
2440 * mail account cannot be found, display an error message.
2442 * Return value: Mail account, or NULL if not found.
2444 static PrefsAccount *
2445 compose_current_mail_account(void)
2449 if (cur_account && cur_account->protocol != A_NNTP)
2452 ac = account_get_default();
2453 if (!ac || ac->protocol == A_NNTP) {
2454 alertpanel_error(_("Account for sending mail is not specified.\n"
2455 "Please select a mail account before sending."));
2462 gboolean compose_check_for_valid_recipient(Compose *compose) {
2463 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2464 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2465 gboolean recipient_found = FALSE;
2469 /* free to and newsgroup list */
2470 slist_free_strings(compose->to_list);
2471 g_slist_free(compose->to_list);
2472 compose->to_list = NULL;
2474 slist_free_strings(compose->newsgroup_list);
2475 g_slist_free(compose->newsgroup_list);
2476 compose->newsgroup_list = NULL;
2478 /* search header entries for to and newsgroup entries */
2479 for(list = compose->header_list; list; list = list->next) {
2482 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2483 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2485 if(entry[0] != '\0') {
2486 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2487 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2488 compose->to_list = address_list_append(compose->to_list, entry);
2489 recipient_found = TRUE;
2492 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2493 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2494 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2495 recipient_found = TRUE;
2501 return recipient_found;
2504 gint compose_send(Compose *compose)
2510 val = compose_queue(compose, &msgnum, &folder);
2512 alertpanel_error(_("Could not queue message for sending"));
2516 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2518 folder_item_remove_msg(folder, msgnum);
2519 folderview_update_item(folder, TRUE);
2525 #if 0 /* compose restructure */
2526 gint compose_send(Compose *compose)
2528 gchar tmp[MAXPATHLEN + 1];
2530 static gboolean lock = FALSE;
2534 g_return_val_if_fail(compose->account != NULL, -1);
2535 g_return_val_if_fail(compose->orig_account != NULL, -1);
2539 if(!compose_check_for_valid_recipient(compose)) {
2540 alertpanel_error(_("Recipient is not specified."));
2545 /* write to temporary file */
2546 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2547 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2549 if (prefs_common.linewrap_at_send)
2550 compose_wrap_line_all(compose);
2552 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2557 if (!compose->to_list && !compose->newsgroup_list) {
2558 g_warning(_("can't get recipient list."));
2564 if (compose->to_list) {
2567 #if 0 /* NEW COMPOSE GUI */
2568 if (compose->account->protocol != A_NNTP)
2569 ac = compose->account;
2570 else if (compose->orig_account->protocol != A_NNTP)
2571 ac = compose->orig_account;
2572 else if (cur_account && cur_account->protocol != A_NNTP)
2575 ac = compose_current_mail_account();
2583 ac = compose->account;
2585 ok = send_message(tmp, ac, compose->to_list);
2586 statusbar_pop_all();
2589 if (ok == 0 && compose->newsgroup_list) {
2592 if (compose->account->protocol == A_NNTP)
2593 folder = FOLDER(compose->account->folder);
2595 folder = FOLDER(compose->orig_account->folder);
2597 ok = news_post(folder, tmp);
2599 alertpanel_error(_("Error occurred while posting the message to %s ."),
2600 compose->account->nntp_server);
2607 /* queue message if failed to send */
2609 if (prefs_common.queue_msg) {
2614 _("Error occurred while sending the message.\n"
2615 "Put this message into queue folder?"),
2616 _("OK"), _("Cancel"), NULL);
2617 if (G_ALERTDEFAULT == val) {
2618 ok = compose_queue(compose, tmp);
2620 alertpanel_error(_("Can't queue the message."));
2623 alertpanel_error(_("Error occurred while sending the message."));
2625 if (compose->mode == COMPOSE_REEDIT) {
2626 compose_remove_reedit_target(compose);
2627 if (compose->targetinfo)
2628 folderview_update_item
2629 (compose->targetinfo->folder, TRUE);
2633 /* save message to outbox */
2634 if (ok == 0 && prefs_common.savemsg) {
2635 if (compose_save_to_outbox(compose, tmp) < 0)
2637 (_("Can't save the message to outbox."));
2646 static gboolean compose_use_attach(Compose *compose) {
2647 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2650 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2653 gchar buf[BUFFSIZE];
2655 gboolean first_address;
2657 ComposeHeaderEntry *headerentry;
2658 gchar *headerentryname;
2659 gchar *header_w_colon;
2663 debug_print(_("Writing bounce header\n"));
2665 header_w_colon = g_strconcat("To:", NULL);
2666 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2667 header_w_colon = g_strconcat("Cc:", NULL);
2668 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2670 first_address = TRUE;
2671 for(list = compose->header_list; list; list = list->next) {
2672 headerentry = ((ComposeHeaderEntry *)list->data);
2673 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2675 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2676 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2677 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2678 Xstrdup_a(str, str, return -1);
2680 if(str[0] != '\0') {
2681 compose_convert_header
2682 (buf, sizeof(buf), str,
2683 strlen("Resent-To") + 2);
2685 fprintf(fp, "Resent-To: ");
2686 first_address = FALSE;
2690 fprintf(fp, "%s", buf);
2694 /* if(!first_address) { */
2701 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2703 gchar buf[BUFFSIZE];
2705 /* struct utsname utsbuf; */
2707 g_return_val_if_fail(fp != NULL, -1);
2708 g_return_val_if_fail(compose->account != NULL, -1);
2709 g_return_val_if_fail(compose->account->address != NULL, -1);
2712 get_rfc822_date(buf, sizeof(buf));
2713 fprintf(fp, "Resent-Date: %s\n", buf);
2716 if (compose->account->name && *compose->account->name) {
2717 compose_convert_header
2718 (buf, sizeof(buf), compose->account->name,
2720 fprintf(fp, "Resent-From: %s <%s>\n",
2721 buf, compose->account->address);
2723 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2726 compose_bounce_write_headers_from_headerlist(compose, fp);
2728 /* separator between header and body */
2734 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2739 gchar buf[BUFFSIZE];
2741 if ((fp = fopen(compose->bounce_filename, "r")) == NULL) {
2742 FILE_OP_ERROR(file, "fopen");
2746 if ((fdest = fopen(file, "w")) == NULL) {
2747 FILE_OP_ERROR(file, "fopen");
2752 /* chmod for security */
2753 if (change_file_mode_rw(fdest, file) < 0) {
2754 FILE_OP_ERROR(file, "chmod");
2755 g_warning(_("can't change file mode\n"));
2758 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2759 /* should filter returnpath, delivered-to */
2760 if ((g_strncasecmp(buf, "Return-Path:",
2761 strlen("Return-Path:")) == 0)
2762 || (g_strncasecmp(buf, "Delivered-To:",
2763 strlen("Delivered-To:")) == 0))
2766 if (fputs(buf, fdest) == -1)
2769 if (g_strncasecmp(buf, "From:", strlen("From:")) == 0) {
2770 fputs(" (by way of ", fdest);
2771 if (compose->account->name
2772 && *compose->account->name) {
2773 compose_convert_header
2775 compose->account->name,
2777 fprintf(fdest, "%s <%s>",
2778 buf, compose->account->address);
2780 fprintf(fdest, "%s",
2781 compose->account->address);
2785 if (fputs("\n", fdest) == -1)
2789 compose_bounce_write_headers(compose, fdest);
2791 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
2792 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
2807 static gint compose_write_to_file(Compose *compose, const gchar *file,
2814 const gchar *out_codeset;
2815 EncodingType encoding;
2817 if ((fp = fopen(file, "w")) == NULL) {
2818 FILE_OP_ERROR(file, "fopen");
2822 /* chmod for security */
2823 if (change_file_mode_rw(fp, file) < 0) {
2824 FILE_OP_ERROR(file, "chmod");
2825 g_warning(_("can't change file mode\n"));
2828 /* get all composed text */
2829 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2830 len = strlen(chars);
2831 if (is_ascii_str(chars)) {
2832 buf = g_strdup(chars);
2833 out_codeset = CS_US_ASCII;
2834 encoding = ENC_7BIT;
2836 const gchar *src_codeset;
2838 out_codeset = conv_get_outgoing_charset_str();
2839 if (!strcasecmp(out_codeset, CS_US_ASCII))
2840 out_codeset = CS_ISO_8859_1;
2841 encoding = procmime_get_encoding_for_charset(out_codeset);
2843 src_codeset = conv_get_current_charset_str();
2844 /* if current encoding is US-ASCII, set it the same as
2845 outgoing one to prevent code conversion failure */
2846 if (!strcasecmp(src_codeset, CS_US_ASCII))
2847 src_codeset = out_codeset;
2849 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
2850 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
2852 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
2857 alertpanel_error(_("Can't convert the codeset of the message."));
2864 if (compose_write_headers
2865 (compose, fp, out_codeset, encoding, is_draft) < 0) {
2866 g_warning(_("can't write headers\n"));
2873 if (compose_use_attach(compose)) {
2875 /* This prolog message is ignored by mime software and
2876 * because it would make our signing/encryption task
2877 * tougher, we don't emit it in that case */
2878 if (!compose->use_signing && !compose->use_encryption)
2880 fputs("This is a multi-part message in MIME format.\n", fp);
2882 fprintf(fp, "\n--%s\n", compose->boundary);
2883 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
2885 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2886 procmime_get_encoding_str(encoding));
2892 if (encoding == ENC_BASE64) {
2893 gchar outbuf[B64_BUFFSIZE];
2896 for (i = 0; i < len; i += B64_LINE_SIZE) {
2897 l = MIN(B64_LINE_SIZE, len - i);
2898 to64frombits(outbuf, buf + i, l);
2902 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
2903 FILE_OP_ERROR(file, "fwrite");
2911 if (compose_use_attach(compose))
2912 compose_write_attach(compose, fp);
2914 if (fclose(fp) == EOF) {
2915 FILE_OP_ERROR(file, "fclose");
2921 if (compose->use_signing) {
2922 if (rfc2015_sign(file, compose->account) < 0) {
2927 if (compose->use_encryption) {
2928 if (rfc2015_encrypt(file, compose->to_list) < 0) {
2933 #endif /* USE_GPGME */
2938 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
2944 if ((fp = fopen(file, "w")) == NULL) {
2945 FILE_OP_ERROR(file, "fopen");
2949 /* chmod for security */
2950 if (change_file_mode_rw(fp, file) < 0) {
2951 FILE_OP_ERROR(file, "chmod");
2952 g_warning(_("can't change file mode\n"));
2955 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2958 len = strlen(chars);
2959 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
2960 FILE_OP_ERROR(file, "fwrite");
2969 if (fclose(fp) == EOF) {
2970 FILE_OP_ERROR(file, "fclose");
2977 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
2984 debug_print(_("saving sent message...\n"));
2986 outbox = folder_get_default_outbox();
2987 path = folder_item_get_path(outbox);
2988 if (!is_dir_exist(path))
2989 make_dir_hier(path);
2991 folder_item_scan(outbox);
2992 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
2994 g_warning(_("can't save message\n"));
2998 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
2999 g_warning(_("can't open mark file\n"));
3003 newmsginfo.msgnum = num;
3004 newmsginfo.flags.perm_flags = 0;
3005 newmsginfo.flags.tmp_flags = 0;
3006 procmsg_write_flags(&newmsginfo, fp);
3014 static gint compose_remove_reedit_target(Compose *compose)
3017 MsgInfo *msginfo = compose->targetinfo;
3019 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3020 if (!msginfo) return -1;
3022 item = msginfo->folder;
3023 g_return_val_if_fail(item != NULL, -1);
3025 folder_item_scan(item);
3026 if (procmsg_msg_exist(msginfo) &&
3027 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3028 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3029 g_warning(_("can't remove the old message\n"));
3038 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3041 gchar *tmp, *tmp2, *queue_path;
3044 gchar buf[BUFFSIZE];
3046 static gboolean lock = FALSE;
3047 PrefsAccount *mailac = NULL, *newsac = NULL;
3049 debug_print(_("queueing message...\n"));
3050 g_return_val_if_fail(compose->account != NULL, -1);
3051 g_return_val_if_fail(compose->orig_account != NULL, -1);
3055 if(!compose_check_for_valid_recipient(compose)) {
3056 alertpanel_error(_("Recipient is not specified."));
3061 if (!compose->to_list && !compose->newsgroup_list) {
3062 g_warning(_("can't get recipient list."));
3067 if(compose->to_list) {
3068 if (compose->account->protocol != A_NNTP)
3069 mailac = compose->account;
3070 else if (compose->orig_account->protocol != A_NNTP)
3071 mailac = compose->orig_account;
3072 else if (cur_account && cur_account->protocol != A_NNTP)
3073 mailac = cur_account;
3074 else if (!(mailac = compose_current_mail_account())) {
3076 alertpanel_error(_("No account for sending mails available!"));
3081 if(compose->newsgroup_list) {
3082 if (compose->account->protocol == A_NNTP)
3083 newsac = compose->account;
3084 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3086 alertpanel_error(_("No account for posting news available!"));
3091 if (prefs_common.linewrap_at_send)
3092 compose_wrap_line_all(compose);
3094 /* write to temporary file */
3095 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3096 G_DIR_SEPARATOR, (gint)compose);
3098 if (compose->bounce_filename != NULL) {
3099 if (compose_bounce_write_to_file(compose, tmp2) < 0) {
3106 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3113 /* add queue header */
3114 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3115 G_DIR_SEPARATOR, (gint)compose);
3116 if ((fp = fopen(tmp, "w")) == NULL) {
3117 FILE_OP_ERROR(tmp, "fopen");
3121 if ((src_fp = fopen(tmp2, "r")) == NULL) {
3122 FILE_OP_ERROR(tmp2, "fopen");
3130 if (change_file_mode_rw(fp, tmp) < 0) {
3131 FILE_OP_ERROR(tmp, "chmod");
3132 g_warning(_("can't change file mode\n"));
3135 /* queueing variables */
3136 fprintf(fp, "AF:\n");
3137 fprintf(fp, "NF:0\n");
3138 fprintf(fp, "PS:10\n");
3139 fprintf(fp, "SRH:1\n");
3140 fprintf(fp, "SFN:\n");
3141 fprintf(fp, "DSR:\n");
3143 fprintf(fp, "MID:<%s>\n", compose->msgid);
3145 fprintf(fp, "MID:\n");
3146 fprintf(fp, "CFG:\n");
3147 fprintf(fp, "PT:0\n");
3148 fprintf(fp, "S:%s\n", compose->account->address);
3149 fprintf(fp, "RQ:\n");
3151 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3153 fprintf(fp, "SSV:\n");
3155 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3157 fprintf(fp, "NSV:\n");
3158 fprintf(fp, "SSH:\n");
3159 /* write recepient list */
3161 if(compose->to_list) {
3162 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3163 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3164 fprintf(fp, ",<%s>", (gchar *)cur->data);
3167 /* write newsgroup list */
3169 if(compose->newsgroup_list) {
3170 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3171 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3172 fprintf(fp, ",%s", (gchar *)cur->data);
3175 /* Sylpheed account IDs */
3177 fprintf(fp, "MAID:%d\n", mailac->account_id);
3180 fprintf(fp, "NAID:%d\n", newsac->account_id);
3182 /* Save copy folder */
3183 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3186 str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3187 fprintf(fp, "SCF:%s\n", str);
3192 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3193 if (fputs(buf, fp) == EOF) {
3194 FILE_OP_ERROR(tmp, "fputs");
3205 if (fclose(fp) == EOF) {
3206 FILE_OP_ERROR(tmp, "fclose");
3215 queue = folder_get_default_queue();
3217 folder_item_scan(queue);
3218 queue_path = folder_item_get_path(queue);
3219 if (!is_dir_exist(queue_path))
3220 make_dir_hier(queue_path);
3221 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3222 g_warning(_("can't queue the message\n"));
3233 if (compose->mode == COMPOSE_REEDIT) {
3234 compose_remove_reedit_target(compose);
3235 if (compose->targetinfo &&
3236 compose->targetinfo->folder != queue)
3237 folderview_update_item
3238 (compose->targetinfo->folder, TRUE);
3241 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
3242 g_warning(_("can't open mark file\n"));
3246 newmsginfo.msgnum = num;
3247 newmsginfo.flags.perm_flags = 0;
3248 newmsginfo.flags.tmp_flags = 0;
3249 procmsg_write_flags(&newmsginfo, fp);
3254 folder_item_scan(queue);
3255 folderview_update_item(queue, TRUE);
3257 if((msgnum != NULL) && (item != NULL)) {
3265 static void compose_write_attach(Compose *compose, FILE *fp)
3268 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3271 gchar filename[BUFFSIZE];
3274 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3276 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
3277 g_warning(_("Can't open file %s\n"), ainfo->file);
3281 fprintf(fp, "\n--%s\n", compose->boundary);
3283 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3284 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3285 fprintf(fp, "Content-Disposition: inline\n");
3287 conv_encode_header(filename, sizeof(filename),
3289 fprintf(fp, "Content-Type: %s;\n"
3291 ainfo->content_type, filename);
3292 fprintf(fp, "Content-Disposition: attachment;\n"
3293 " filename=\"%s\"\n", filename);
3296 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3297 procmime_get_encoding_str(ainfo->encoding));
3299 if (ainfo->encoding == ENC_7BIT) {
3300 gchar buf[BUFFSIZE];
3302 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3307 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3309 while ((len = fread(inbuf, sizeof(gchar),
3310 B64_LINE_SIZE, attach_fp))
3312 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3316 if (len > 0 && feof(attach_fp)) {
3317 to64frombits(outbuf, inbuf, len);
3326 fprintf(fp, "\n--%s--\n", compose->boundary);
3329 #define IS_IN_CUSTOM_HEADER(header) \
3330 (compose->account->add_customhdr && \
3331 custom_header_find(compose->account->customhdr_list, header) != NULL)
3333 static gint compose_write_headers_from_headerlist(Compose *compose,
3337 gchar buf[BUFFSIZE];
3338 gchar *str, *header_w_colon, *trans_hdr;
3339 gboolean first_address;
3341 ComposeHeaderEntry *headerentry;
3342 gchar * headerentryname;
3344 if (IS_IN_CUSTOM_HEADER(header)) {
3348 debug_print(_("Writing %s-header\n"), header);
3350 header_w_colon = g_strconcat(header, ":", NULL);
3351 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3353 first_address = TRUE;
3354 for(list = compose->header_list; list; list = list->next) {
3355 headerentry = ((ComposeHeaderEntry *)list->data);
3356 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3358 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3359 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3360 Xstrdup_a(str, str, return -1);
3362 if(str[0] != '\0') {
3363 compose_convert_header
3364 (buf, sizeof(buf), str,
3365 strlen(header) + 2);
3367 fprintf(fp, "%s: ", header);
3368 first_address = FALSE;
3372 fprintf(fp, "%s", buf);
3376 if(!first_address) {
3380 g_free(header_w_colon);
3385 static gint compose_write_headers(Compose *compose, FILE *fp,
3386 const gchar *charset, EncodingType encoding,
3389 gchar buf[BUFFSIZE];
3391 /* struct utsname utsbuf; */
3393 g_return_val_if_fail(fp != NULL, -1);
3394 g_return_val_if_fail(charset != NULL, -1);
3395 g_return_val_if_fail(compose->account != NULL, -1);
3396 g_return_val_if_fail(compose->account->address != NULL, -1);
3399 if (compose->account->add_date) {
3400 get_rfc822_date(buf, sizeof(buf));
3401 fprintf(fp, "Date: %s\n", buf);
3405 if (!IS_IN_CUSTOM_HEADER("From")) {
3406 if (compose->account->name && *compose->account->name) {
3407 compose_convert_header
3408 (buf, sizeof(buf), compose->account->name,
3410 fprintf(fp, "From: %s <%s>\n",
3411 buf, compose->account->address);
3413 fprintf(fp, "From: %s\n", compose->account->address);
3417 compose_write_headers_from_headerlist(compose, fp, "To");
3418 #if 0 /* NEW COMPOSE GUI */
3419 if (compose->use_to) {
3420 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3422 Xstrdup_a(str, str, return -1);
3425 compose->to_list = address_list_append
3426 (compose->to_list, str);
3427 if (!IS_IN_CUSTOM_HEADER("To")) {
3428 compose_convert_header
3429 (buf, sizeof(buf), str,
3431 fprintf(fp, "To: %s\n", buf);
3439 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3440 #if 0 /* NEW COMPOSE GUI */
3441 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3443 Xstrdup_a(str, str, return -1);
3447 compose->newsgroup_list =
3448 newsgroup_list_append(compose->newsgroup_list,
3450 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3451 compose_convert_header(buf, sizeof(buf), str,
3452 strlen("Newsgroups: "));
3453 fprintf(fp, "Newsgroups: %s\n", buf);
3459 compose_write_headers_from_headerlist(compose, fp, "Cc");
3460 #if 0 /* NEW COMPOSE GUI */
3461 if (compose->use_cc) {
3462 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3464 Xstrdup_a(str, str, return -1);
3467 compose->to_list = address_list_append
3468 (compose->to_list, str);
3469 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3470 compose_convert_header
3471 (buf, sizeof(buf), str,
3473 fprintf(fp, "Cc: %s\n", buf);
3480 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3481 #if 0 /* NEW COMPOSE GUI */
3482 if (compose->use_bcc) {
3483 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3485 Xstrdup_a(str, str, return -1);
3488 compose->to_list = address_list_append
3489 (compose->to_list, str);
3490 compose_convert_header(buf, sizeof(buf), str,
3492 fprintf(fp, "Bcc: %s\n", buf);
3499 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3500 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3501 Xstrdup_a(str, str, return -1);
3504 compose_convert_header(buf, sizeof(buf), str,
3505 strlen("Subject: "));
3506 fprintf(fp, "Subject: %s\n", buf);
3511 if (compose->account->gen_msgid) {
3512 compose_generate_msgid(compose, buf, sizeof(buf));
3513 fprintf(fp, "Message-Id: <%s>\n", buf);
3514 compose->msgid = g_strdup(buf);
3518 if (compose->inreplyto && compose->to_list)
3519 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3522 if (compose->references)
3523 fprintf(fp, "References: %s\n", compose->references);
3526 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3527 #if 0 /* NEW COMPOSE GUI */
3528 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3529 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3531 Xstrdup_a(str, str, return -1);
3535 compose_convert_header(buf, sizeof(buf), str,
3536 strlen("Followup-To: "));
3537 fprintf(fp, "Followup-To: %s\n", buf);
3543 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3544 #if 0 /* NEW COMPOSE GUI */
3545 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3546 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3548 Xstrdup_a(str, str, return -1);
3551 compose_convert_header(buf, sizeof(buf), str,
3552 strlen("Reply-To: "));
3553 fprintf(fp, "Reply-To: %s\n", buf);
3559 if (compose->account->organization &&
3560 !IS_IN_CUSTOM_HEADER("Organization")) {
3561 compose_convert_header(buf, sizeof(buf),
3562 compose->account->organization,
3563 strlen("Organization: "));
3564 fprintf(fp, "Organization: %s\n", buf);
3567 /* Program version and system info */
3568 /* uname(&utsbuf); */
3569 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3570 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3572 gtk_major_version, gtk_minor_version, gtk_micro_version,
3574 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3576 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3577 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3579 gtk_major_version, gtk_minor_version, gtk_micro_version,
3581 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3584 /* custom headers */
3585 if (compose->account->add_customhdr) {
3588 for (cur = compose->account->customhdr_list; cur != NULL;
3590 CustomHeader *chdr = (CustomHeader *)cur->data;
3592 if (strcasecmp(chdr->name, "Date") != 0 &&
3593 strcasecmp(chdr->name, "From") != 0 &&
3594 strcasecmp(chdr->name, "To") != 0 &&
3595 /* strcasecmp(chdr->name, "Sender") != 0 && */
3596 strcasecmp(chdr->name, "Message-Id") != 0 &&
3597 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3598 strcasecmp(chdr->name, "References") != 0 &&
3599 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3600 strcasecmp(chdr->name, "Content-Type") != 0 &&
3601 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3603 compose_convert_header
3605 chdr->value ? chdr->value : "",
3606 strlen(chdr->name) + 2);
3607 fprintf(fp, "%s: %s\n", chdr->name, buf);
3613 fprintf(fp, "Mime-Version: 1.0\n");
3614 if (compose_use_attach(compose)) {
3615 get_rfc822_date(buf, sizeof(buf));
3616 subst_char(buf, ' ', '_');
3617 subst_char(buf, ',', '_');
3618 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3619 buf, (guint)compose);
3621 "Content-Type: multipart/mixed;\n"
3622 " boundary=\"%s\"\n", compose->boundary);
3624 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3625 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3626 procmime_get_encoding_str(encoding));
3629 /* Request Return Receipt */
3630 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3631 if (compose->return_receipt) {
3632 if (compose->account->name
3633 && *compose->account->name) {
3634 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3635 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3637 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3641 /* separator between header and body */
3647 #undef IS_IN_CUSTOM_HEADER
3649 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3652 g_return_if_fail(src != NULL);
3653 g_return_if_fail(dest != NULL);
3655 if (len < 1) return;
3659 if (is_ascii_str(src)) {
3660 strncpy2(dest, src, len);
3661 dest[len - 1] = '\0';
3664 conv_encode_header(dest, len, src, header_len);
3667 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3676 if (compose->account && compose->account->address &&
3677 *compose->account->address) {
3678 if (strchr(compose->account->address, '@'))
3679 addr = g_strdup(compose->account->address);
3681 addr = g_strconcat(compose->account->address, "@",
3682 get_domain_name(), NULL);
3684 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3687 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3688 lt->tm_year + 1900, lt->tm_mon + 1,
3689 lt->tm_mday, lt->tm_hour,
3690 lt->tm_min, lt->tm_sec,
3691 (guint)random(), addr);
3693 debug_print(_("generated Message-ID: %s\n"), buf);
3699 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3700 GtkWidget **entry, gint *count,
3701 const gchar *label_str,
3702 gboolean is_addr_entry)
3706 if (GTK_TABLE(table)->nrows < (*count) + 1)
3707 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3709 *hbox = gtk_hbox_new(FALSE, 0);
3710 label = gtk_label_new
3711 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3712 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3713 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3715 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3717 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3718 #if 0 /* NEW COMPOSE GUI */
3719 if (GTK_TABLE(table)->nrows > (*count) + 1)
3720 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3724 address_completion_register_entry(GTK_ENTRY(*entry));
3729 static void compose_create_header_entry(Compose *compose)
3731 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3735 GList *combo_list = NULL;
3736 gchar **string, *header;
3737 ComposeHeaderEntry *headerentry;
3739 headerentry = g_new0(ComposeHeaderEntry, 1);
3742 combo = gtk_combo_new();
3744 while(*string != NULL) {
3745 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3748 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3749 g_list_free(combo_list);
3750 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3751 gtk_widget_show(combo);
3752 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3753 if(compose->header_last) {
3754 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3756 switch(compose->account->protocol) {
3758 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
3761 header = prefs_common.trans_hdr ? _("To:") : "To:";
3765 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
3768 entry = gtk_entry_new();
3769 gtk_widget_show(entry);
3770 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);
3772 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
3773 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
3775 address_completion_register_entry(GTK_ENTRY(entry));
3777 headerentry->compose = compose;
3778 headerentry->combo = combo;
3779 headerentry->entry = entry;
3780 headerentry->headernum = compose->header_nextrow;
3782 compose->header_nextrow++;
3783 compose->header_last = headerentry;
3786 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
3788 ComposeHeaderEntry *last_header;
3790 last_header = compose->header_last;
3792 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
3793 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
3796 static GtkWidget *compose_create_header(Compose *compose)
3799 GtkWidget *from_optmenu_hbox;
3800 #if 0 /* NEW COMPOSE GUI */
3801 GtkWidget *to_entry;
3803 GtkWidget *newsgroups_entry;
3804 GtkWidget *newsgroups_hbox;
3806 GtkWidget *header_scrolledwin;
3807 GtkWidget *header_table;
3808 GtkWidget *subject_entry;
3809 #if 0 /* NEW COMPOSE GUI */
3810 GtkWidget *cc_entry;
3812 GtkWidget *bcc_entry;
3813 GtkWidget *bcc_hbox;
3814 GtkWidget *reply_entry;
3815 GtkWidget *reply_hbox;
3816 GtkWidget *followup_entry;
3817 GtkWidget *followup_hbox;
3823 /* header labels and entries */
3824 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3825 gtk_widget_show(header_scrolledwin);
3826 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
3828 header_table = gtk_table_new(2, 2, FALSE);
3829 gtk_widget_show(header_table);
3830 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
3831 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
3834 /* option menu for selecting accounts */
3835 hbox = gtk_hbox_new(FALSE, 0);
3836 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
3837 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3838 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
3840 from_optmenu_hbox = compose_account_option_menu_create(compose);
3841 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
3842 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
3843 #if 0 /* NEW COMPOSE GUI */
3844 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3849 compose_add_entry_field(header_table, &hbox, &subject_entry, &count,
3852 compose->header_table = header_table;
3853 compose->header_list = NULL;
3854 compose->header_nextrow = count;
3856 compose_create_header_entry(compose);
3858 #if 0 /* NEW COMPOSE GUI */
3859 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
3861 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3862 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
3863 &count, "Newsgroups:", FALSE);
3864 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
3866 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
3868 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
3870 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
3871 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
3873 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
3874 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
3876 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
3877 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
3878 "Followup-To:", FALSE);
3879 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
3881 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
3883 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
3884 GTK_SIGNAL_FUNC(to_activated), compose);
3885 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
3886 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
3887 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
3888 GTK_SIGNAL_FUNC(subject_activated), compose);
3889 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
3890 GTK_SIGNAL_FUNC(cc_activated), compose);
3891 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
3892 GTK_SIGNAL_FUNC(bcc_activated), compose);
3893 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
3894 GTK_SIGNAL_FUNC(replyto_activated), compose);
3895 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
3896 GTK_SIGNAL_FUNC(followupto_activated), compose);
3898 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
3899 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3900 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
3901 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3902 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
3903 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3904 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
3905 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3906 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
3907 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3908 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
3909 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3910 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
3911 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3914 compose->table = NULL;
3915 #if 0 /* NEW COMPOSE GUI */
3916 compose->table = table;
3917 compose->to_hbox = to_hbox;
3918 compose->to_entry = to_entry;
3919 compose->newsgroups_hbox = newsgroups_hbox;
3920 compose->newsgroups_entry = newsgroups_entry;
3922 compose->subject_entry = subject_entry;
3923 #if 0 /* NEW COMPOSE GUI */
3924 compose->cc_hbox = cc_hbox;
3925 compose->cc_entry = cc_entry;
3926 compose->bcc_hbox = bcc_hbox;
3927 compose->bcc_entry = bcc_entry;
3928 compose->reply_hbox = reply_hbox;
3929 compose->reply_entry = reply_entry;
3930 compose->followup_hbox = followup_hbox;
3931 compose->followup_entry = followup_entry;
3934 return header_scrolledwin ;
3937 GtkWidget *compose_create_attach(Compose *compose)
3939 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
3942 GtkWidget *attach_scrwin;
3943 GtkWidget *attach_clist;
3945 /* attachment list */
3946 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
3947 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
3948 GTK_POLICY_AUTOMATIC,
3950 gtk_widget_set_usize(attach_scrwin, -1, 80);
3952 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
3953 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
3955 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
3956 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
3957 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
3958 GTK_SELECTION_EXTENDED);
3959 for (i = 0; i < N_ATTACH_COLS; i++)
3960 GTK_WIDGET_UNSET_FLAGS
3961 (GTK_CLIST(attach_clist)->column[i].button,
3963 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
3965 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
3966 GTK_SIGNAL_FUNC(attach_selected), compose);
3967 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
3968 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
3969 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
3970 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
3973 gtk_drag_dest_set(attach_clist,
3974 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3976 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
3977 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
3980 compose->attach_scrwin = attach_scrwin;
3981 compose->attach_clist = attach_clist;
3983 return attach_scrwin;
3986 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
3987 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
3989 static GtkWidget *compose_create_others(Compose *compose)
3992 GtkWidget *savemsg_checkbtn;
3993 GtkWidget *savemsg_entry;
3994 GtkWidget *savemsg_select;
3997 gchar *folderidentifier;
3999 /* Table for settings */
4000 table = gtk_table_new(3, 1, FALSE);
4001 gtk_widget_show(table);
4002 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
4005 /* Save Message to folder */
4006 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4007 gtk_widget_show(savemsg_checkbtn);
4008 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4009 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4010 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4011 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4013 savemsg_entry = gtk_entry_new();
4014 gtk_widget_show(savemsg_entry);
4015 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4016 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4017 folderidentifier = folder_item_get_identifier(folder_get_default_outbox());
4018 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4019 g_free(folderidentifier);
4021 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4022 gtk_widget_show (savemsg_select);
4023 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4024 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4025 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4030 compose->savemsg_checkbtn = savemsg_checkbtn;
4031 compose->savemsg_entry = savemsg_entry;
4036 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4038 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4039 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4042 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4047 dest = foldersel_folder_sel(NULL, NULL);
4050 path = folder_item_get_identifier(dest);
4052 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4056 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4062 GtkWidget *handlebox;
4064 GtkWidget *notebook;
4068 GtkWidget *table_vbox;
4072 GtkWidget *edit_vbox;
4073 GtkWidget *ruler_hbox;
4075 GtkWidget *scrolledwin;
4080 UndoMain *undostruct;
4082 guint n_menu_entries;
4083 GtkStyle *style, *new_style;
4086 gboolean success[1];
4088 GtkWidget *popupmenu;
4089 GtkWidget *menuitem;
4090 GtkItemFactory *popupfactory;
4091 GtkItemFactory *ifactory;
4092 GtkWidget *tmpl_menu;
4096 GtkPspell * gtkpspell = NULL;
4099 g_return_val_if_fail(account != NULL, NULL);
4101 debug_print(_("Creating compose window...\n"));
4102 compose = g_new0(Compose, 1);
4104 compose->account = account;
4105 compose->orig_account = account;
4107 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4108 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4109 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4110 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4111 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4112 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4113 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4114 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
4115 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
4116 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
4117 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
4118 gtk_widget_realize(window);
4120 gtkut_widget_set_composer_icon(window);
4122 vbox = gtk_vbox_new(FALSE, 0);
4123 gtk_container_add(GTK_CONTAINER(window), vbox);
4125 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4126 menubar = menubar_create(window, compose_entries,
4127 n_menu_entries, "<Compose>", compose);
4128 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4130 handlebox = gtk_handle_box_new();
4131 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4133 compose_toolbar_create(compose, handlebox);
4135 vbox2 = gtk_vbox_new(FALSE, 2);
4136 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4137 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4139 table_vbox = gtk_vbox_new(FALSE, 0);
4140 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
4141 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
4145 notebook = gtk_notebook_new();
4146 gtk_widget_set_usize(notebook, -1, 180);
4147 gtk_widget_show(notebook);
4149 /* header labels and entries */
4150 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4151 /* attachment list */
4152 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4154 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4156 edit_vbox = gtk_vbox_new(FALSE, 0);
4157 #if 0 /* NEW COMPOSE GUI */
4158 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4162 ruler_hbox = gtk_hbox_new(FALSE, 0);
4163 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4165 ruler = gtk_shruler_new();
4166 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4167 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4169 gtk_widget_set_usize(ruler_hbox, 1, -1);
4172 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4173 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4174 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4175 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4176 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4178 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4179 (GTK_SCROLLED_WINDOW(scrolledwin)),
4180 gtk_scrolled_window_get_vadjustment
4181 (GTK_SCROLLED_WINDOW(scrolledwin)));
4182 GTK_STEXT(text)->default_tab_width = 8;
4183 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4185 if (prefs_common.block_cursor) {
4186 GTK_STEXT(text)->cursor_type = STEXT_CURSOR_BLOCK;
4189 if (prefs_common.smart_wrapping) {
4190 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4191 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4194 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4196 gtk_signal_connect(GTK_OBJECT(text), "changed",
4197 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4198 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4199 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4200 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4201 GTK_SIGNAL_FUNC(compose_button_press_cb),
4204 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4205 GTK_SIGNAL_FUNC(compose_key_press_cb),
4208 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4209 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4213 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4215 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4216 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4219 if (prefs_common.enable_pspell) {
4220 gtkpspell = gtkpspell_new_with_config(gtkpspellconfig,
4221 prefs_common.pspell_path,
4222 prefs_common.dictionary,
4224 conv_get_current_charset_str());
4225 if (gtkpspell == NULL)
4226 prefs_common.enable_pspell = FALSE;
4228 gtkpspell_attach(gtkpspell, GTK_STEXT(text));
4231 gtk_widget_show_all(vbox);
4233 /* pane between attach clist and text */
4234 paned = gtk_vpaned_new();
4235 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4236 gtk_paned_add1(GTK_PANED(paned), notebook);
4237 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4238 gtk_widget_show_all(paned);
4240 style = gtk_widget_get_style(text);
4242 /* workaround for the slow down of GtkText when using Pixmap theme */
4243 if (style->engine) {
4244 GtkThemeEngine *engine;
4246 engine = style->engine;
4247 style->engine = NULL;
4248 new_style = gtk_style_copy(style);
4249 style->engine = engine;
4251 new_style = gtk_style_copy(style);
4253 if (prefs_common.textfont) {
4256 charset = conv_get_current_charset();
4257 if (MB_CUR_MAX == 1) {
4260 Xstrdup_a(fontstr, prefs_common.textfont, );
4261 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4263 font = gdk_font_load(fontstr);
4265 font = gdk_fontset_load(prefs_common.textfont);
4267 gdk_font_unref(new_style->font);
4268 new_style->font = font;
4272 gtk_widget_set_style(text, new_style);
4274 color[0] = quote_color;
4275 cmap = gdk_window_get_colormap(window->window);
4276 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4277 if (success[0] == FALSE) {
4278 g_warning("Compose: color allocation failed.\n");
4279 style = gtk_widget_get_style(text);
4280 quote_color = style->black;
4283 n_entries = sizeof(compose_popup_entries) /
4284 sizeof(compose_popup_entries[0]);
4285 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4286 "<Compose>", &popupfactory,
4289 ifactory = gtk_item_factory_from_widget(menubar);
4290 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4291 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4293 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tool/Template");
4294 #if 0 /* NEW COMPOSE GUI */
4295 if (account->protocol == A_NNTP) {
4296 gtk_widget_hide(to_hbox);
4297 gtk_widget_hide(to_entry);
4298 gtk_widget_hide(cc_hbox);
4299 gtk_widget_hide(cc_entry);
4300 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4301 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4303 gtk_widget_hide(newsgroups_hbox);
4304 gtk_widget_hide(newsgroups_entry);
4305 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4307 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
4311 switch (prefs_common.toolbar_style) {
4313 gtk_widget_hide(handlebox);
4316 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4320 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4324 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4329 gtk_widget_show(window);
4331 address_completion_start(window);
4333 compose->window = window;
4334 compose->vbox = vbox;
4335 compose->menubar = menubar;
4336 compose->handlebox = handlebox;
4338 compose->vbox2 = vbox2;
4340 compose->table_vbox = table_vbox;
4342 compose->paned = paned;
4344 compose->edit_vbox = edit_vbox;
4345 compose->ruler_hbox = ruler_hbox;
4346 compose->ruler = ruler;
4347 compose->scrolledwin = scrolledwin;
4348 compose->text = text;
4350 compose->focused_editable = NULL;
4352 compose->popupmenu = popupmenu;
4353 compose->popupfactory = popupfactory;
4355 compose->tmpl_menu = tmpl_menu;
4357 compose->mode = mode;
4359 compose->targetinfo = NULL;
4360 compose->replyinfo = NULL;
4362 compose->replyto = NULL;
4363 compose->mailinglist = NULL;
4365 compose->bcc = NULL;
4366 compose->followup_to = NULL;
4367 compose->inreplyto = NULL;
4368 compose->references = NULL;
4369 compose->msgid = NULL;
4370 compose->boundary = NULL;
4373 compose->use_signing = FALSE;
4374 compose->use_encryption = FALSE;
4375 #endif /* USE_GPGME */
4377 compose->modified = FALSE;
4379 compose->return_receipt = FALSE;
4381 compose->to_list = NULL;
4382 compose->newsgroup_list = NULL;
4384 compose->exteditor_file = NULL;
4385 compose->exteditor_pid = -1;
4386 compose->exteditor_readdes = -1;
4387 compose->exteditor_tag = -1;
4389 compose->bounce_filename = NULL;
4391 compose_set_title(compose);
4393 #if 0 /* NEW COMPOSE GUI */
4394 compose->use_bcc = FALSE;
4395 compose->use_replyto = FALSE;
4396 compose->use_followupto = FALSE;
4400 compose->gtkpspell = gtkpspell;
4403 undostruct = undo_init(text);
4405 compose->undostruct = undostruct;
4406 undo_set_undo_change_funct(undostruct, &compose_set_undo, GTK_WIDGET(compose->menubar));
4408 #if 0 /* NEW COMPOSE GUI */
4409 if (account->protocol != A_NNTP) {
4410 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4411 gtk_check_menu_item_set_active
4412 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4413 gtk_widget_set_sensitive(menuitem, FALSE);
4414 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4415 gtk_check_menu_item_set_active
4416 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4417 gtk_widget_set_sensitive(menuitem, FALSE);
4420 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4421 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4422 #if 0 /* NEW COMPOSE GUI */
4423 compose->use_cc = TRUE;
4424 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4425 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4426 gtk_check_menu_item_set_active
4427 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4430 if (account->set_autobcc) {
4431 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4432 #if 0 /* NEW COMPOSE GUI */
4433 compose->use_bcc = TRUE;
4434 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
4435 gtk_check_menu_item_set_active
4436 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4437 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4438 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4442 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4443 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4444 #if 0 /* NEW COMPOSE GUI */
4445 compose->use_replyto = TRUE;
4446 menuitem = gtk_item_factory_get_item(ifactory,
4447 "/Message/Reply to");
4448 gtk_check_menu_item_set_active
4449 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4450 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4451 account->auto_replyto);
4454 if (account->protocol != A_NNTP) {
4455 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("To:"));
4457 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("Newsgroups:"));
4460 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
4461 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4462 prefs_common.show_ruler);
4465 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4466 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4467 prefs_common.default_sign);
4468 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4469 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4470 prefs_common.default_encrypt);
4471 #endif /* USE_GPGME */
4473 addressbook_set_target_compose(compose);
4474 compose_set_template_menu(compose);
4476 compose_list = g_list_append(compose_list, compose);
4478 #if 0 /* NEW COMPOSE GUI */
4479 compose->use_to = FALSE;
4480 compose->use_cc = FALSE;
4481 compose->use_attach = TRUE;
4484 #if 0 /* NEW COMPOSE GUI */
4485 if (!compose->use_bcc) {
4486 gtk_widget_hide(bcc_hbox);
4487 gtk_widget_hide(bcc_entry);
4488 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4490 if (!compose->use_replyto) {
4491 gtk_widget_hide(reply_hbox);
4492 gtk_widget_hide(reply_entry);
4493 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4495 if (!compose->use_followupto) {
4496 gtk_widget_hide(followup_hbox);
4497 gtk_widget_hide(followup_entry);
4498 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4501 if (!prefs_common.show_ruler)
4502 gtk_widget_hide(ruler_hbox);
4504 select_account(compose, account);
4509 #include "pixmaps/stock_mail_send.xpm"
4510 #include "pixmaps/stock_mail_send_queue.xpm"
4511 #include "pixmaps/stock_mail.xpm"
4512 #include "pixmaps/stock_paste.xpm"
4513 #include "pixmaps/stock_mail_attach.xpm"
4514 #include "pixmaps/stock_mail_compose.xpm"
4515 #include "pixmaps/linewrap.xpm"
4516 #include "pixmaps/tb_address_book.xpm"
4518 #define CREATE_TOOLBAR_ICON(xpm_d) \
4520 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
4521 &container->style->white, \
4523 icon_wid = gtk_pixmap_new(icon, mask); \
4526 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4531 GtkWidget *icon_wid;
4532 GtkWidget *send_btn;
4533 GtkWidget *sendl_btn;
4534 GtkWidget *draft_btn;
4535 GtkWidget *insert_btn;
4536 GtkWidget *attach_btn;
4538 GtkWidget *exteditor_btn;
4539 GtkWidget *linewrap_btn;
4540 GtkWidget *addrbook_btn;
4542 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4544 gtk_container_add(GTK_CONTAINER(container), toolbar);
4545 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4546 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4547 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4548 GTK_TOOLBAR_SPACE_LINE);
4550 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
4551 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4555 icon_wid, toolbar_send_cb, compose);
4557 CREATE_TOOLBAR_ICON(stock_mail_send_queue_xpm);
4558 /* CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm); */
4559 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4561 _("Put into queue folder and send later"),
4563 icon_wid, toolbar_send_later_cb,
4566 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4567 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4569 _("Save to draft folder"),
4571 icon_wid, toolbar_draft_cb,
4574 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4576 CREATE_TOOLBAR_ICON(stock_paste_xpm);
4577 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4581 icon_wid, toolbar_insert_cb,
4584 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
4585 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4589 icon_wid, toolbar_attach_cb,
4592 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4594 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4595 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4597 _("Insert signature"),
4599 icon_wid, toolbar_sig_cb, compose);
4601 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4603 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
4604 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4606 _("Edit with external editor"),
4609 toolbar_ext_editor_cb,
4612 CREATE_TOOLBAR_ICON(linewrap_xpm);
4613 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4615 _("Wrap current paragraph"),
4618 toolbar_linewrap_cb,
4621 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4623 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
4624 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4628 icon_wid, toolbar_address_cb,
4631 compose->toolbar = toolbar;
4632 compose->send_btn = send_btn;
4633 compose->sendl_btn = sendl_btn;
4634 compose->draft_btn = draft_btn;
4635 compose->insert_btn = insert_btn;
4636 compose->attach_btn = attach_btn;
4637 compose->sig_btn = sig_btn;
4638 compose->exteditor_btn = exteditor_btn;
4639 compose->linewrap_btn = linewrap_btn;
4640 compose->addrbook_btn = addrbook_btn;
4642 gtk_widget_show_all(toolbar);
4645 #undef CREATE_TOOLBAR_ICON
4647 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4653 gint num = 0, def_menu = 0;
4655 accounts = account_get_list();
4656 g_return_val_if_fail(accounts != NULL, NULL);
4658 hbox = gtk_hbox_new(FALSE, 0);
4659 optmenu = gtk_option_menu_new();
4660 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4661 menu = gtk_menu_new();
4663 for (; accounts != NULL; accounts = accounts->next, num++) {
4664 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4665 GtkWidget *menuitem;
4668 if (ac == compose->account) def_menu = num;
4670 name = g_strdup_printf("%s: %s <%s>",
4671 ac->account_name, ac->name, ac->address);
4672 MENUITEM_ADD(menu, menuitem, name, ac);
4674 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4675 GTK_SIGNAL_FUNC(account_activated),
4679 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4680 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4685 static void compose_set_template_menu(Compose *compose)
4687 GSList *tmpl_list, *cur;
4691 tmpl_list = template_get_config();
4693 menu = gtk_menu_new();
4695 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4696 Template *tmpl = (Template *)cur->data;
4698 item = gtk_menu_item_new_with_label(tmpl->name);
4699 gtk_menu_append(GTK_MENU(menu), item);
4700 gtk_signal_connect(GTK_OBJECT(item), "activate",
4701 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4703 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4704 gtk_widget_show(item);
4707 gtk_widget_show(menu);
4708 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4711 void compose_reflect_prefs_all(void)
4716 for (cur = compose_list; cur != NULL; cur = cur->next) {
4717 compose = (Compose *)cur->data;
4718 compose_set_template_menu(compose);
4722 static void compose_template_apply(Compose *compose, Template *tmpl)
4727 if (!tmpl || !tmpl->value) return;
4729 gtk_stext_freeze(GTK_STEXT(compose->text));
4732 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
4735 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
4737 if (compose->replyinfo == NULL) {
4740 memset(&dummyinfo, 0, sizeof(MsgInfo));
4741 parsed_str = compose_quote_fmt(compose, &dummyinfo,
4744 if (prefs_common.quotemark && *prefs_common.quotemark)
4745 qmark = prefs_common.quotemark;
4749 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
4750 tmpl->value, qmark);
4753 if (parsed_str && prefs_common.auto_sig)
4754 compose_insert_sig(compose);
4756 gtk_stext_thaw(GTK_STEXT(compose->text));
4759 static void compose_destroy(Compose *compose)
4762 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4765 /* NOTE: address_completion_end() does nothing with the window
4766 * however this may change. */
4767 address_completion_end(compose->window);
4769 slist_free_strings(compose->to_list);
4770 g_slist_free(compose->to_list);
4771 slist_free_strings(compose->newsgroup_list);
4772 g_slist_free(compose->newsgroup_list);
4773 slist_free_strings(compose->header_list);
4774 g_slist_free(compose->header_list);
4776 procmsg_msginfo_free(compose->targetinfo);
4777 procmsg_msginfo_free(compose->replyinfo);
4779 g_free(compose->replyto);
4780 g_free(compose->cc);
4781 g_free(compose->bcc);
4782 g_free(compose->newsgroups);
4783 g_free(compose->followup_to);
4785 g_free(compose->inreplyto);
4786 g_free(compose->references);
4787 g_free(compose->msgid);
4788 g_free(compose->boundary);
4790 if (compose->bounce_filename)
4791 g_free(compose->bounce_filename);
4793 g_free(compose->exteditor_file);
4795 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
4797 compose_attach_info_free(ainfo);
4799 if (addressbook_get_target_compose() == compose)
4800 addressbook_set_target_compose(NULL);
4802 prefs_common.compose_width = compose->scrolledwin->allocation.width;
4803 prefs_common.compose_height = compose->window->allocation.height;
4805 gtk_widget_destroy(compose->paned);
4809 compose_list = g_list_remove(compose_list, compose);
4812 static void compose_attach_info_free(AttachInfo *ainfo)
4814 g_free(ainfo->file);
4815 g_free(ainfo->content_type);
4816 g_free(ainfo->name);
4820 static void compose_attach_remove_selected(Compose *compose)
4822 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4826 while (clist->selection != NULL) {
4827 row = GPOINTER_TO_INT(clist->selection->data);
4828 ainfo = gtk_clist_get_row_data(clist, row);
4829 compose_attach_info_free(ainfo);
4830 gtk_clist_remove(clist, row);
4834 static struct _AttachProperty
4837 GtkWidget *mimetype_entry;
4838 GtkWidget *encoding_optmenu;
4839 GtkWidget *path_entry;
4840 GtkWidget *filename_entry;
4842 GtkWidget *cancel_btn;
4845 static void compose_attach_property(Compose *compose)
4847 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4850 GtkOptionMenu *optmenu;
4851 static gboolean cancelled;
4853 if (!clist->selection) return;
4854 row = GPOINTER_TO_INT(clist->selection->data);
4856 ainfo = gtk_clist_get_row_data(clist, row);
4859 if (!attach_prop.window)
4860 compose_attach_property_create(&cancelled);
4861 gtk_widget_grab_focus(attach_prop.ok_btn);
4862 gtk_widget_show(attach_prop.window);
4863 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
4865 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
4866 if (ainfo->encoding == ENC_UNKNOWN)
4867 gtk_option_menu_set_history(optmenu, ENC_BASE64);
4869 gtk_option_menu_set_history(optmenu, ainfo->encoding);
4871 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
4872 ainfo->content_type ? ainfo->content_type : "");
4873 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
4874 ainfo->file ? ainfo->file : "");
4875 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
4876 ainfo->name ? ainfo->name : "");
4880 gchar *cnttype = NULL;
4884 GtkWidget *menuitem;
4889 if (cancelled == TRUE) {
4890 gtk_widget_hide(attach_prop.window);
4894 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
4895 if (*text != '\0') {
4898 text = g_strstrip(g_strdup(text));
4899 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
4900 cnttype = g_strdup(text);
4903 alertpanel_error(_("Invalid MIME type."));
4909 menu = gtk_option_menu_get_menu(optmenu);
4910 menuitem = gtk_menu_get_active(GTK_MENU(menu));
4911 ainfo->encoding = GPOINTER_TO_INT
4912 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
4914 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
4915 if (*text != '\0') {
4916 if (is_file_exist(text) &&
4917 (size = get_file_size(text)) > 0)
4918 file = g_strdup(text);
4921 (_("File doesn't exist or is empty."));
4927 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
4928 if (*text != '\0') {
4929 g_free(ainfo->name);
4930 ainfo->name = g_strdup(text);
4934 g_free(ainfo->content_type);
4935 ainfo->content_type = cnttype;
4938 g_free(ainfo->file);
4944 gtk_clist_set_text(clist, row, COL_MIMETYPE,
4945 ainfo->content_type);
4946 gtk_clist_set_text(clist, row, COL_SIZE,
4947 to_human_readable(ainfo->size));
4948 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
4950 gtk_widget_hide(attach_prop.window);
4955 #define SET_LABEL_AND_ENTRY(str, entry, top) \
4957 label = gtk_label_new(str); \
4958 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
4959 GTK_FILL, 0, 0, 0); \
4960 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
4962 entry = gtk_entry_new(); \
4963 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
4964 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
4967 static void compose_attach_property_create(gboolean *cancelled)
4973 GtkWidget *mimetype_entry;
4976 GtkWidget *optmenu_menu;
4977 GtkWidget *menuitem;
4978 GtkWidget *path_entry;
4979 GtkWidget *filename_entry;
4982 GtkWidget *cancel_btn;
4983 GList *mime_type_list, *strlist;
4985 debug_print("Creating attach_property window...\n");
4987 window = gtk_window_new(GTK_WINDOW_DIALOG);
4988 gtk_widget_set_usize(window, 480, -1);
4989 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
4990 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
4991 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
4992 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
4993 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4994 GTK_SIGNAL_FUNC(attach_property_delete_event),
4996 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
4997 GTK_SIGNAL_FUNC(attach_property_key_pressed),
5000 vbox = gtk_vbox_new(FALSE, 8);
5001 gtk_container_add(GTK_CONTAINER(window), vbox);
5003 table = gtk_table_new(4, 2, FALSE);
5004 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
5005 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5006 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5008 label = gtk_label_new(_("MIME type"));
5009 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5011 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5012 mimetype_entry = gtk_combo_new();
5013 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5014 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5016 /* stuff with list */
5017 mime_type_list = procmime_get_mime_type_list();
5019 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5020 MimeType *type = (MimeType *) mime_type_list->data;
5021 strlist = g_list_append(strlist,
5022 g_strdup_printf("%s/%s",
5023 type->type, type->sub_type));
5026 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5028 for (mime_type_list = strlist; mime_type_list != NULL;
5029 mime_type_list = mime_type_list->next)
5030 g_free(mime_type_list->data);
5031 g_list_free(strlist);
5033 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5035 label = gtk_label_new(_("Encoding"));
5036 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5038 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5040 hbox = gtk_hbox_new(FALSE, 0);
5041 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5042 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5044 optmenu = gtk_option_menu_new();
5045 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5047 optmenu_menu = gtk_menu_new();
5048 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5049 gtk_widget_set_sensitive(menuitem, FALSE);
5050 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5051 gtk_widget_set_sensitive(menuitem, FALSE);
5052 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5053 gtk_widget_set_sensitive(menuitem, FALSE);
5054 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5056 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5058 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5059 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5061 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5062 &cancel_btn, _("Cancel"), NULL, NULL);
5063 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5064 gtk_widget_grab_default(ok_btn);
5066 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5067 GTK_SIGNAL_FUNC(attach_property_ok),
5069 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5070 GTK_SIGNAL_FUNC(attach_property_cancel),
5073 gtk_widget_show_all(vbox);
5075 attach_prop.window = window;
5076 attach_prop.mimetype_entry = mimetype_entry;
5077 attach_prop.encoding_optmenu = optmenu;
5078 attach_prop.path_entry = path_entry;
5079 attach_prop.filename_entry = filename_entry;
5080 attach_prop.ok_btn = ok_btn;
5081 attach_prop.cancel_btn = cancel_btn;
5084 #undef SET_LABEL_AND_ENTRY
5086 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5092 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5098 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5099 gboolean *cancelled)
5107 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5108 gboolean *cancelled)
5110 if (event && event->keyval == GDK_Escape) {
5116 static void compose_exec_ext_editor(Compose *compose)
5122 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5123 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5125 if (pipe(pipe_fds) < 0) {
5130 if ((pid = fork()) < 0) {
5136 /* close the write side of the pipe */
5139 compose->exteditor_file = g_strdup(tmp);
5140 compose->exteditor_pid = pid;
5141 compose->exteditor_readdes = pipe_fds[0];
5143 compose_set_ext_editor_sensitive(compose, FALSE);
5145 compose->exteditor_tag =
5146 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5147 compose_input_cb, compose);
5148 } else { /* process-monitoring process */
5154 /* close the read side of the pipe */
5157 if (compose_write_body_to_file(compose, tmp) < 0) {
5158 fd_write(pipe_fds[1], "2\n", 2);
5162 pid_ed = compose_exec_ext_editor_real(tmp);
5164 fd_write(pipe_fds[1], "1\n", 2);
5168 /* wait until editor is terminated */
5169 waitpid(pid_ed, NULL, 0);
5171 fd_write(pipe_fds[1], "0\n", 2);
5178 static gint compose_exec_ext_editor_real(const gchar *file)
5180 static gchar *def_cmd = "emacs %s";
5186 g_return_val_if_fail(file != NULL, -1);
5188 if ((pid = fork()) < 0) {
5193 if (pid != 0) return pid;
5195 /* grandchild process */
5197 if (setpgid(0, getppid()))
5200 if (prefs_common.ext_editor_cmd &&
5201 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5202 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5203 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5205 if (prefs_common.ext_editor_cmd)
5206 g_warning(_("External editor command line is invalid: `%s'\n"),
5207 prefs_common.ext_editor_cmd);
5208 g_snprintf(buf, sizeof(buf), def_cmd, file);
5211 cmdline = g_strsplit(buf, " ", 1024);
5212 execvp(cmdline[0], cmdline);
5215 g_strfreev(cmdline);
5220 static gboolean compose_ext_editor_kill(Compose *compose)
5222 pid_t pgid = compose->exteditor_pid * -1;
5225 ret = kill(pgid, 0);
5227 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5231 msg = g_strdup_printf
5232 (_("The external editor is still working.\n"
5233 "Force terminating the process?\n"
5234 "process group id: %d"), -pgid);
5235 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5238 if (val == G_ALERTDEFAULT) {
5239 gdk_input_remove(compose->exteditor_tag);
5240 close(compose->exteditor_readdes);
5242 if (kill(pgid, SIGTERM) < 0) perror("kill");
5243 waitpid(compose->exteditor_pid, NULL, 0);
5245 g_warning(_("Terminated process group id: %d"), -pgid);
5246 g_warning(_("Temporary file: %s"),
5247 compose->exteditor_file);
5249 compose_set_ext_editor_sensitive(compose, TRUE);
5251 g_free(compose->exteditor_file);
5252 compose->exteditor_file = NULL;
5253 compose->exteditor_pid = -1;
5254 compose->exteditor_readdes = -1;
5255 compose->exteditor_tag = -1;
5263 static void compose_input_cb(gpointer data, gint source,
5264 GdkInputCondition condition)
5267 Compose *compose = (Compose *)data;
5270 debug_print(_("Compose: input from monitoring process\n"));
5272 gdk_input_remove(compose->exteditor_tag);
5275 if (read(source, &buf[i], 1) < 1) {
5279 if (buf[i] == '\n') {
5284 if (i == sizeof(buf) - 1)
5288 waitpid(compose->exteditor_pid, NULL, 0);
5290 if (buf[0] == '0') { /* success */
5291 GtkSText *text = GTK_STEXT(compose->text);
5293 gtk_stext_freeze(text);
5294 gtk_stext_set_point(text, 0);
5295 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5296 compose_insert_file(compose, compose->exteditor_file);
5297 compose_changed_cb(NULL, compose);
5298 gtk_stext_thaw(text);
5300 if (unlink(compose->exteditor_file) < 0)
5301 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5302 } else if (buf[0] == '1') { /* failed */
5303 g_warning(_("Couldn't exec external editor\n"));
5304 if (unlink(compose->exteditor_file) < 0)
5305 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5306 } else if (buf[0] == '2') {
5307 g_warning(_("Couldn't write to file\n"));
5308 } else if (buf[0] == '3') {
5309 g_warning(_("Pipe read failed\n"));
5314 compose_set_ext_editor_sensitive(compose, TRUE);
5316 g_free(compose->exteditor_file);
5317 compose->exteditor_file = NULL;
5318 compose->exteditor_pid = -1;
5319 compose->exteditor_readdes = -1;
5320 compose->exteditor_tag = -1;
5323 static void compose_set_ext_editor_sensitive(Compose *compose,
5326 GtkItemFactory *ifactory;
5328 ifactory = gtk_item_factory_from_widget(compose->menubar);
5330 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5331 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5332 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5334 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5335 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5336 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5337 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5338 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5341 gtk_widget_set_sensitive(compose->text, sensitive);
5342 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5343 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5344 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5345 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5346 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5347 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5348 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5351 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5355 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5356 cursor_pos = MAX(cursor_pos, 0);
5361 /* callback functions */
5363 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5364 * includes "non-client" (windows-izm) in calculation, so this calculation
5365 * may not be accurate.
5367 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5368 GtkAllocation *allocation,
5369 GtkSHRuler *shruler)
5371 if (prefs_common.show_ruler) {
5373 gint line_width_in_chars;
5375 char_width = gtkut_get_font_width
5376 (GTK_WIDGET(widget)->style->font);
5377 line_width_in_chars =
5378 (allocation->width - allocation->x) / char_width;
5380 /* got the maximum */
5381 gtk_ruler_set_range(GTK_RULER(shruler),
5382 0.0, line_width_in_chars,
5383 calc_cursor_xpos(GTK_STEXT(widget),
5386 /*line_width_in_chars*/ char_width);
5392 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5394 compose_send_cb(data, 0, NULL);
5397 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5399 compose_send_later_cb(data, 0, NULL);
5402 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5404 compose_draft_cb(data, 0, NULL);
5407 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5409 compose_insert_file_cb(data, 0, NULL);
5412 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5414 compose_attach_cb(data, 0, NULL);
5417 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5419 Compose *compose = (Compose *)data;
5421 compose_insert_sig(compose);
5424 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5426 Compose *compose = (Compose *)data;
5428 compose_exec_ext_editor(compose);
5431 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5433 Compose *compose = (Compose *)data;
5435 compose_wrap_line(compose);
5438 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5440 compose_address_cb(data, 0, NULL);
5443 static void select_account(Compose * compose, PrefsAccount * ac)
5445 compose->account = ac;
5446 compose_set_title(compose);
5448 #if 0 /* NEW COMPOSE GUI */
5449 if (ac->protocol == A_NNTP) {
5450 GtkItemFactory *ifactory;
5451 GtkWidget *menuitem;
5453 ifactory = gtk_item_factory_from_widget(compose->menubar);
5454 menu_set_sensitive(ifactory,
5455 "/Message/Followup to", TRUE);
5456 gtk_widget_show(compose->newsgroups_hbox);
5457 gtk_widget_show(compose->newsgroups_entry);
5458 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5461 compose->use_to = FALSE;
5462 compose->use_cc = FALSE;
5464 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5465 gtk_check_menu_item_set_active
5466 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5468 menu_set_sensitive(ifactory,
5469 "/Message/To", TRUE);
5470 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5471 gtk_check_menu_item_set_active
5472 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5474 gtk_widget_hide(compose->to_hbox);
5475 gtk_widget_hide(compose->to_entry);
5476 gtk_widget_hide(compose->cc_hbox);
5477 gtk_widget_hide(compose->cc_entry);
5478 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5480 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5484 GtkItemFactory *ifactory;
5485 GtkWidget *menuitem;
5487 ifactory = gtk_item_factory_from_widget(compose->menubar);
5488 menu_set_sensitive(ifactory,
5489 "/Message/Followup to", FALSE);
5490 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5491 gtk_widget_hide(compose->newsgroups_hbox);
5492 gtk_widget_hide(compose->newsgroups_entry);
5493 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5496 compose->use_to = TRUE;
5497 compose->use_cc = TRUE;
5499 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5500 gtk_check_menu_item_set_active
5501 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5502 menu_set_sensitive(ifactory,
5503 "/Message/To", FALSE);
5504 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5505 gtk_check_menu_item_set_active
5506 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5507 gtk_widget_show(compose->to_hbox);
5508 gtk_widget_show(compose->to_entry);
5509 gtk_widget_show(compose->cc_hbox);
5510 gtk_widget_show(compose->cc_entry);
5512 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5514 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5517 gtk_widget_queue_resize(compose->table_vbox);
5521 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5523 Compose *compose = (Compose *)data;
5527 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5528 g_return_if_fail(ac != NULL);
5530 if (ac != compose->account)
5531 select_account(compose, ac);
5534 static void attach_selected(GtkCList *clist, gint row, gint column,
5535 GdkEvent *event, gpointer data)
5537 Compose *compose = (Compose *)data;
5539 if (event && event->type == GDK_2BUTTON_PRESS)
5540 compose_attach_property(compose);
5543 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5546 Compose *compose = (Compose *)data;
5547 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5552 if (event->button == 3) {
5553 if ((clist->selection && !clist->selection->next) ||
5554 !clist->selection) {
5555 gtk_clist_unselect_all(clist);
5556 if (gtk_clist_get_selection_info(clist,
5559 gtk_clist_select_row(clist, row, column);
5560 gtkut_clist_set_focus_row(clist, row);
5563 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5564 NULL, NULL, event->button, event->time);
5568 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5571 Compose *compose = (Compose *)data;
5575 switch (event->keyval) {
5577 compose_attach_remove_selected(compose);
5582 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5584 Compose *compose = (Compose *)data;
5587 val = compose_send(compose);
5588 if (val == 0) gtk_widget_destroy(compose->window);
5591 static void compose_send_later_cb(gpointer data, guint action,
5594 Compose *compose = (Compose *)data;
5597 val = compose_queue(compose, NULL, NULL);
5598 if (!val) gtk_widget_destroy(compose->window);
5601 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5603 Compose *compose = (Compose *)data;
5607 draft = folder_get_default_draft();
5609 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5610 G_DIR_SEPARATOR, (gint)compose);
5612 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5617 folder_item_scan(draft);
5618 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
5625 if (compose->mode == COMPOSE_REEDIT) {
5626 compose_remove_reedit_target(compose);
5627 if (compose->targetinfo &&
5628 compose->targetinfo->folder != draft)
5629 folderview_update_item(compose->targetinfo->folder,
5633 folder_item_scan(draft);
5634 folderview_update_item(draft, TRUE);
5636 gtk_widget_destroy(compose->window);
5639 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
5641 Compose *compose = (Compose *)data;
5644 if (compose->bounce_filename != NULL)
5647 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5652 for ( tmp = file_list; tmp; tmp = tmp->next) {
5653 gchar *file = (gchar *) tmp->data;
5654 compose_attach_append(compose, file, MIME_UNKNOWN);
5657 g_list_free(file_list);
5661 static void compose_insert_file_cb(gpointer data, guint action,
5664 Compose *compose = (Compose *)data;
5667 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5672 for ( tmp = file_list; tmp; tmp = tmp->next) {
5673 gchar *file = (gchar *) tmp->data;
5674 compose_insert_file(compose, file);
5677 g_list_free(file_list);
5681 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
5684 compose_close_cb(data, 0, NULL);
5688 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
5690 Compose *compose = (Compose *)data;
5693 if (compose->exteditor_tag != -1) {
5694 if (!compose_ext_editor_kill(compose))
5698 if (compose->modified) {
5699 val = alertpanel(_("Discard message"),
5700 _("This message has been modified. discard it?"),
5701 _("Discard"), _("to Draft"), _("Cancel"));
5704 case G_ALERTDEFAULT:
5706 case G_ALERTALTERNATE:
5707 compose_draft_cb(data, 0, NULL);
5714 if (compose->gtkpspell) {
5715 gtkpspell_detach(compose->gtkpspell);
5716 compose->gtkpspell = gtkpspell_delete(compose->gtkpspell);
5719 gtk_widget_destroy(compose->window);
5722 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
5724 Compose *compose = (Compose *)data;
5726 addressbook_open(compose);
5729 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
5731 Compose *compose = (Compose *)data;
5734 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
5735 g_return_if_fail(tmpl != NULL);
5737 compose_template_apply(compose, tmpl);
5740 static void compose_ext_editor_cb(gpointer data, guint action,
5743 Compose *compose = (Compose *)data;
5745 compose_exec_ext_editor(compose);
5748 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
5750 compose_destroy(compose);
5753 static void compose_undo_cb(Compose *compose)
5755 undo_undo(compose->undostruct);
5758 static void compose_redo_cb(Compose *compose)
5760 undo_redo(compose->undostruct);
5763 static void compose_cut_cb(Compose *compose)
5765 if (compose->focused_editable &&
5766 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5767 gtk_editable_cut_clipboard
5768 (GTK_EDITABLE(compose->focused_editable));
5771 static void compose_copy_cb(Compose *compose)
5773 if (compose->focused_editable &&
5774 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5775 gtk_editable_copy_clipboard
5776 (GTK_EDITABLE(compose->focused_editable));
5779 static void compose_paste_cb(Compose *compose)
5781 if (compose->focused_editable &&
5782 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5783 gtk_editable_paste_clipboard
5784 (GTK_EDITABLE(compose->focused_editable));
5787 static void compose_allsel_cb(Compose *compose)
5789 if (compose->focused_editable &&
5790 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5791 gtk_editable_select_region
5792 (GTK_EDITABLE(compose->focused_editable), 0, -1);
5795 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
5797 if (GTK_IS_EDITABLE(widget))
5798 compose->focused_editable = widget;
5801 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
5803 if (compose->modified == FALSE) {
5804 compose->modified = TRUE;
5805 compose_set_title(compose);
5809 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
5812 gtk_stext_set_point(GTK_STEXT(widget),
5813 gtk_editable_get_position(GTK_EDITABLE(widget)));
5817 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
5820 gtk_stext_set_point(GTK_STEXT(widget),
5821 gtk_editable_get_position(GTK_EDITABLE(widget)));
5825 #if 0 /* NEW COMPOSE GUI */
5826 static void compose_toggle_to_cb(gpointer data, guint action,
5829 Compose *compose = (Compose *)data;
5831 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5832 gtk_widget_show(compose->to_hbox);
5833 gtk_widget_show(compose->to_entry);
5834 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
5835 compose->use_to = TRUE;
5837 gtk_widget_hide(compose->to_hbox);
5838 gtk_widget_hide(compose->to_entry);
5839 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
5840 gtk_widget_queue_resize(compose->table_vbox);
5841 compose->use_to = FALSE;
5844 if (addressbook_get_target_compose() == compose)
5845 addressbook_set_target_compose(compose);
5848 static void compose_toggle_cc_cb(gpointer data, guint action,
5851 Compose *compose = (Compose *)data;
5853 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5854 gtk_widget_show(compose->cc_hbox);
5855 gtk_widget_show(compose->cc_entry);
5856 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
5857 compose->use_cc = TRUE;
5859 gtk_widget_hide(compose->cc_hbox);
5860 gtk_widget_hide(compose->cc_entry);
5861 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
5862 gtk_widget_queue_resize(compose->table_vbox);
5863 compose->use_cc = FALSE;
5866 if (addressbook_get_target_compose() == compose)
5867 addressbook_set_target_compose(compose);
5870 static void compose_toggle_bcc_cb(gpointer data, guint action,
5873 Compose *compose = (Compose *)data;
5875 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5876 gtk_widget_show(compose->bcc_hbox);
5877 gtk_widget_show(compose->bcc_entry);
5878 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
5879 compose->use_bcc = TRUE;
5881 gtk_widget_hide(compose->bcc_hbox);
5882 gtk_widget_hide(compose->bcc_entry);
5883 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
5884 gtk_widget_queue_resize(compose->table_vbox);
5885 compose->use_bcc = FALSE;
5888 if (addressbook_get_target_compose() == compose)
5889 addressbook_set_target_compose(compose);
5892 static void compose_toggle_replyto_cb(gpointer data, guint action,
5895 Compose *compose = (Compose *)data;
5897 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5898 gtk_widget_show(compose->reply_hbox);
5899 gtk_widget_show(compose->reply_entry);
5900 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
5901 compose->use_replyto = TRUE;
5903 gtk_widget_hide(compose->reply_hbox);
5904 gtk_widget_hide(compose->reply_entry);
5905 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
5906 gtk_widget_queue_resize(compose->table_vbox);
5907 compose->use_replyto = FALSE;
5911 static void compose_toggle_followupto_cb(gpointer data, guint action,
5914 Compose *compose = (Compose *)data;
5916 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5917 gtk_widget_show(compose->followup_hbox);
5918 gtk_widget_show(compose->followup_entry);
5919 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
5920 compose->use_followupto = TRUE;
5922 gtk_widget_hide(compose->followup_hbox);
5923 gtk_widget_hide(compose->followup_entry);
5924 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
5925 gtk_widget_queue_resize(compose->table_vbox);
5926 compose->use_followupto = FALSE;
5930 static void compose_toggle_attach_cb(gpointer data, guint action,
5933 Compose *compose = (Compose *)data;
5935 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5936 gtk_widget_ref(compose->edit_vbox);
5938 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5939 compose->edit_vbox);
5940 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
5941 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
5943 gtk_widget_show(compose->paned);
5945 gtk_widget_unref(compose->edit_vbox);
5946 gtk_widget_unref(compose->paned);
5948 compose->use_attach = TRUE;
5950 gtk_widget_ref(compose->paned);
5951 gtk_widget_ref(compose->edit_vbox);
5953 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5955 gtk_container_remove(GTK_CONTAINER(compose->paned),
5956 compose->edit_vbox);
5957 gtk_box_pack_start(GTK_BOX(compose->vbox2),
5958 compose->edit_vbox, TRUE, TRUE, 0);
5960 gtk_widget_unref(compose->edit_vbox);
5962 compose->use_attach = FALSE;
5968 static void compose_toggle_sign_cb(gpointer data, guint action,
5971 Compose *compose = (Compose *)data;
5973 if (GTK_CHECK_MENU_ITEM(widget)->active)
5974 compose->use_signing = TRUE;
5976 compose->use_signing = FALSE;
5979 static void compose_toggle_encrypt_cb(gpointer data, guint action,
5982 Compose *compose = (Compose *)data;
5984 if (GTK_CHECK_MENU_ITEM(widget)->active)
5985 compose->use_encryption = TRUE;
5987 compose->use_encryption = FALSE;
5989 #endif /* USE_GPGME */
5991 static void compose_toggle_ruler_cb(gpointer data, guint action,
5994 Compose *compose = (Compose *)data;
5996 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5997 gtk_widget_show(compose->ruler_hbox);
5998 prefs_common.show_ruler = TRUE;
6000 gtk_widget_hide(compose->ruler_hbox);
6001 gtk_widget_queue_resize(compose->edit_vbox);
6002 prefs_common.show_ruler = FALSE;
6006 static void compose_attach_drag_received_cb (GtkWidget *widget,
6007 GdkDragContext *drag_context,
6010 GtkSelectionData *data,
6015 Compose *compose = (Compose *)user_data;
6018 list = uri_list_extract_filenames((const gchar *)data->data);
6019 for (tmp = list; tmp != NULL; tmp = tmp->next)
6020 compose_attach_append(compose, (const gchar *)tmp->data,
6022 list_free_strings(list);
6026 static void compose_insert_drag_received_cb (GtkWidget *widget,
6027 GdkDragContext *drag_context,
6030 GtkSelectionData *data,
6035 Compose *compose = (Compose *)user_data;
6038 list = uri_list_extract_filenames((const gchar *)data->data);
6039 for (tmp = list; tmp != NULL; tmp = tmp->next)
6040 compose_insert_file(compose, (const gchar *)tmp->data);
6041 list_free_strings(list);
6045 #if 0 /* NEW COMPOSE GUI */
6046 static void to_activated(GtkWidget *widget, Compose *compose)
6048 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6049 gtk_widget_grab_focus(compose->newsgroups_entry);
6051 gtk_widget_grab_focus(compose->subject_entry);
6054 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6056 gtk_widget_grab_focus(compose->subject_entry);
6059 static void subject_activated(GtkWidget *widget, Compose *compose)
6061 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6062 gtk_widget_grab_focus(compose->cc_entry);
6063 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6064 gtk_widget_grab_focus(compose->bcc_entry);
6065 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6066 gtk_widget_grab_focus(compose->reply_entry);
6067 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6068 gtk_widget_grab_focus(compose->followup_entry);
6070 gtk_widget_grab_focus(compose->text);
6073 static void cc_activated(GtkWidget *widget, Compose *compose)
6075 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6076 gtk_widget_grab_focus(compose->bcc_entry);
6077 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6078 gtk_widget_grab_focus(compose->reply_entry);
6079 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6080 gtk_widget_grab_focus(compose->followup_entry);
6082 gtk_widget_grab_focus(compose->text);
6085 static void bcc_activated(GtkWidget *widget, Compose *compose)
6087 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6088 gtk_widget_grab_focus(compose->reply_entry);
6089 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6090 gtk_widget_grab_focus(compose->followup_entry);
6092 gtk_widget_grab_focus(compose->text);
6095 static void replyto_activated(GtkWidget *widget, Compose *compose)
6097 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6098 gtk_widget_grab_focus(compose->followup_entry);
6100 gtk_widget_grab_focus(compose->text);
6103 static void followupto_activated(GtkWidget *widget, Compose *compose)
6105 gtk_widget_grab_focus(compose->text);
6109 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6112 Compose *compose = (Compose *)data;
6114 if (GTK_CHECK_MENU_ITEM(widget)->active)
6115 compose->return_receipt = TRUE;
6117 compose->return_receipt = FALSE;
6120 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6122 ComposeHeaderEntry *headerentry)
6124 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6125 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6126 !(event->state & GDK_MODIFIER_MASK) &&
6127 (event->keyval == GDK_BackSpace) &&
6128 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6129 gtk_container_remove
6130 (GTK_CONTAINER(headerentry->compose->header_table),
6131 headerentry->combo);
6132 gtk_container_remove
6133 (GTK_CONTAINER(headerentry->compose->header_table),
6134 headerentry->entry);
6135 headerentry->compose->header_list =
6136 g_slist_remove(headerentry->compose->header_list,
6138 g_free(headerentry);
6142 void compose_headerentry_changed_cb(GtkWidget *entry,
6143 ComposeHeaderEntry *headerentry)
6145 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6146 headerentry->compose->header_list =
6147 g_slist_append(headerentry->compose->header_list,
6149 compose_create_header_entry(headerentry->compose);
6150 gtk_signal_disconnect_by_func
6152 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6160 * Change the sensivity of the menuentries undo and redo
6162 static void compose_set_undo(UndoMain *undostruct, gint undo_state,
6163 gint redo_state, GtkWidget *changewidget)
6165 GtkItemFactory *ifactory;
6166 debug_print ("Set_undo. UNDO:%i REDO:%i\n",
6170 g_return_if_fail (changewidget != NULL);
6172 ifactory = gtk_item_factory_from_widget(changewidget);
6175 switch (undo_state) {
6176 case UNDO_STATE_TRUE:
6177 if (!undostruct->undo_state) {
6178 debug_print ("Set_undo - Testpoint\n");
6179 undostruct->undo_state = TRUE;
6180 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6183 case UNDO_STATE_FALSE:
6184 if (undostruct->undo_state) {
6185 undostruct->undo_state = FALSE;
6186 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6189 case UNDO_STATE_UNCHANGED:
6191 case UNDO_STATE_REFRESH:
6192 menu_set_sensitive(ifactory, "/Edit/Undo", undostruct->undo_state);
6195 g_warning ("Undo state not recognized");
6200 switch (redo_state) {
6201 case UNDO_STATE_TRUE:
6202 if (!undostruct->redo_state) {
6203 undostruct->redo_state = TRUE;
6204 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6207 case UNDO_STATE_FALSE:
6208 if (undostruct->redo_state) {
6209 undostruct->redo_state = FALSE;
6210 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6213 case UNDO_STATE_UNCHANGED:
6215 case UNDO_STATE_REFRESH:
6216 menu_set_sensitive(ifactory, "/Edit/Redo", undostruct->redo_state);
6219 g_warning ("Redo state not recognized");