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 account = msginfo->folder->folder->account;
1166 if(!account&& prefs_common.reedit_account_autosel) {
1167 gchar from[BUFFSIZE];
1168 if(!get_header_from_msginfo(msginfo,from,sizeof(from),"FROM:")){ /* Found a FROM header */
1169 extract_address(from);
1170 account = account_find_from_address(from);
1173 if (!account) account = cur_account;
1174 g_return_if_fail(account != NULL);
1176 compose = compose_create(account, COMPOSE_REEDIT);
1177 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1179 if (compose_parse_header(compose, msginfo) < 0) return;
1180 compose_reedit_set_entry(compose, msginfo);
1182 text = GTK_STEXT(compose->text);
1183 gtk_stext_freeze(text);
1185 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1186 g_warning(_("Can't get text part\n"));
1188 while (fgets(buf, sizeof(buf), fp) != NULL)
1189 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1192 compose_attach_parts(compose, msginfo);
1194 gtk_stext_thaw(text);
1195 gtk_widget_grab_focus(compose->text);
1197 if (prefs_common.auto_exteditor)
1198 compose_exec_ext_editor(compose);
1201 GList *compose_get_compose_list(void)
1203 return compose_list;
1206 void compose_entry_append(Compose *compose, const gchar *address,
1207 ComposeEntryType type)
1213 if (!address || *address == '\0') return;
1215 #if 0 /* NEW COMPOSE GUI */
1218 entry = GTK_ENTRY(compose->cc_entry);
1221 entry = GTK_ENTRY(compose->bcc_entry);
1223 case COMPOSE_NEWSGROUPS:
1224 entry = GTK_ENTRY(compose->newsgroups_entry);
1228 entry = GTK_ENTRY(compose->to_entry);
1232 text = gtk_entry_get_text(entry);
1234 gtk_entry_append_text(entry, ", ");
1235 gtk_entry_append_text(entry, address);
1243 header = N_("Bcc:");
1245 case COMPOSE_REPLYTO:
1246 header = N_("Reply-To:");
1248 case COMPOSE_NEWSGROUPS:
1249 header = N_("Newsgroups:");
1251 case COMPOSE_FOLLOWUPTO:
1252 header = N_( "Followup-To:");
1259 header = prefs_common.trans_hdr ? gettext(header) : header;
1261 compose_add_header_entry(compose, header, (gchar *)address);
1264 static void compose_entries_set(Compose *compose, const gchar *mailto)
1266 gchar *subject = NULL;
1274 Xstrdup_a(tmp_mailto, mailto, return);
1278 p = strchr(tmp_mailto, '?');
1285 gchar *field, *value;
1302 if (*value == '\0') continue;
1304 if (!g_strcasecmp(field, "subject")) {
1305 Xalloca(subject, strlen(value) + 1, return);
1306 decode_uri(subject, value);
1307 } else if (!g_strcasecmp(field, "cc")) {
1309 } else if (!g_strcasecmp(field, "bcc")) {
1311 } else if (!g_strcasecmp(field, "body")) {
1312 Xalloca(body, strlen(value) + 1, return);
1313 decode_uri(body, value);
1318 compose_entry_append(compose, to, COMPOSE_TO);
1320 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1322 compose_entry_append(compose, cc, COMPOSE_CC);
1324 compose_entry_append(compose, bcc, COMPOSE_BCC);
1326 gtk_stext_insert(GTK_STEXT(compose->text),
1327 NULL, NULL, NULL, body, -1);
1328 gtk_stext_insert(GTK_STEXT(compose->text),
1329 NULL, NULL, NULL, "\n", 1);
1333 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1335 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1336 {"Cc:", NULL, FALSE},
1337 {"References:", NULL, FALSE},
1338 {"Bcc:", NULL, FALSE},
1339 {"Newsgroups:", NULL, FALSE},
1340 {"Followup-To:", NULL, FALSE},
1341 {"X-Mailing-List:", NULL, FALSE},
1342 {"X-BeenThere:", NULL, FALSE},
1343 {NULL, NULL, FALSE}};
1353 H_X_MAILING_LIST = 6,
1359 g_return_val_if_fail(msginfo != NULL, -1);
1361 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1362 procheader_get_header_fields(fp, hentry);
1365 if (hentry[H_REPLY_TO].body != NULL) {
1366 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1367 compose->replyto = hentry[H_REPLY_TO].body;
1368 hentry[H_REPLY_TO].body = NULL;
1370 if (hentry[H_CC].body != NULL) {
1371 conv_unmime_header_overwrite(hentry[H_CC].body);
1372 compose->cc = hentry[H_CC].body;
1373 hentry[H_CC].body = NULL;
1375 if (hentry[H_X_MAILING_LIST].body != NULL) {
1376 /* this is good enough to parse debian-devel */
1377 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1378 g_return_val_if_fail(buf != NULL, -1 );
1379 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1380 compose->mailinglist = g_strdup(buf);
1382 g_free(hentry[H_X_MAILING_LIST].body);
1383 hentry[H_X_MAILING_LIST].body = NULL ;
1385 if (hentry[H_X_BEENTHERE].body != NULL) {
1386 /* this is good enough to parse the sylpheed-claws lists */
1387 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1388 g_return_val_if_fail(buf != NULL, -1 );
1389 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1390 compose->mailinglist = g_strdup(buf);
1392 g_free(hentry[H_X_BEENTHERE].body);
1393 hentry[H_X_BEENTHERE].body = NULL ;
1395 if (hentry[H_REFERENCES].body != NULL) {
1396 if (compose->mode == COMPOSE_REEDIT)
1397 compose->references = hentry[H_REFERENCES].body;
1399 compose->references = compose_parse_references
1400 (hentry[H_REFERENCES].body, msginfo->msgid);
1401 g_free(hentry[H_REFERENCES].body);
1403 hentry[H_REFERENCES].body = NULL;
1405 if (hentry[H_BCC].body != NULL) {
1406 if (compose->mode == COMPOSE_REEDIT) {
1407 conv_unmime_header_overwrite(hentry[H_BCC].body);
1408 compose->bcc = hentry[H_BCC].body;
1410 g_free(hentry[H_BCC].body);
1411 hentry[H_BCC].body = NULL;
1413 if (hentry[H_NEWSGROUPS].body != NULL) {
1414 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1415 hentry[H_NEWSGROUPS].body = NULL;
1417 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1418 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1419 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1420 hentry[H_FOLLOWUP_TO].body = NULL;
1423 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1424 compose->inreplyto = g_strdup(msginfo->inreplyto);
1425 else if (compose->mode != COMPOSE_REEDIT &&
1426 msginfo->msgid && *msginfo->msgid) {
1427 compose->inreplyto = g_strdup(msginfo->msgid);
1429 if (!compose->references) {
1430 if (msginfo->inreplyto && *msginfo->inreplyto)
1431 compose->references =
1432 g_strdup_printf("<%s>\n\t<%s>",
1436 compose->references =
1437 g_strconcat("<", msginfo->msgid, ">",
1445 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1447 GSList *ref_id_list, *cur;
1451 ref_id_list = references_list_append(NULL, ref);
1452 if (!ref_id_list) return NULL;
1453 if (msgid && *msgid)
1454 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1459 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1460 /* "<" + Message-ID + ">" + CR+LF+TAB */
1461 len += strlen((gchar *)cur->data) + 5;
1463 if (len > MAX_REFERENCES_LEN) {
1464 /* remove second message-ID */
1465 if (ref_id_list && ref_id_list->next &&
1466 ref_id_list->next->next) {
1467 g_free(ref_id_list->next->data);
1468 ref_id_list = g_slist_remove
1469 (ref_id_list, ref_id_list->next->data);
1471 slist_free_strings(ref_id_list);
1472 g_slist_free(ref_id_list);
1479 new_ref = g_string_new("");
1480 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1481 if (new_ref->len > 0)
1482 g_string_append(new_ref, "\n\t");
1483 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1486 slist_free_strings(ref_id_list);
1487 g_slist_free(ref_id_list);
1489 new_ref_str = new_ref->str;
1490 g_string_free(new_ref, FALSE);
1495 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1496 const gchar *fmt, const gchar *qmark)
1498 GtkSText *text = GTK_STEXT(compose->text);
1499 gchar *quote_str = NULL;
1504 if (qmark != NULL) {
1505 quote_fmt_init(msginfo, NULL);
1506 quote_fmt_scan_string(qmark);
1509 buf = quote_fmt_get_buffer();
1511 alertpanel_error(_("Quote mark format error."));
1513 Xstrdup_a(quote_str, buf, return NULL)
1516 if (fmt && *fmt != '\0') {
1517 quote_fmt_init(msginfo, quote_str);
1518 quote_fmt_scan_string(fmt);
1521 buf = quote_fmt_get_buffer();
1523 alertpanel_error(_("Message reply/forward format error."));
1529 gtk_stext_freeze(text);
1530 gtk_stext_set_point(text, 0);
1531 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
1533 for (p = buf; *p != '\0'; ) {
1534 lastp = strchr(p, '\n');
1535 len = lastp ? lastp - p + 1 : -1;
1536 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1543 gtk_stext_thaw(text);
1548 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1549 gboolean to_all, gboolean ignore_replyto,
1550 gboolean followup_and_reply_to)
1555 GHashTable *to_table;
1557 g_return_if_fail(compose->account != NULL);
1558 g_return_if_fail(msginfo != NULL);
1560 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1561 compose_entry_append(compose,
1562 ((compose->mailinglist && !ignore_replyto)
1563 ? compose->mailinglist
1564 : (compose->replyto && !ignore_replyto)
1566 : msginfo->from ? msginfo->from : ""),
1568 if (compose->account->protocol == A_NNTP) {
1570 compose_entry_append
1571 (compose, msginfo->from ? msginfo->from : "",
1574 compose_entry_append
1576 compose->followup_to ? compose->followup_to
1577 : compose->newsgroups ? compose->newsgroups
1579 COMPOSE_NEWSGROUPS);
1582 if (msginfo->subject && *msginfo->subject) {
1583 gchar *buf, *buf2, *p;
1585 buf = g_strdup(msginfo->subject);
1586 while (!strncasecmp(buf, "Re:", 3)) {
1588 while (isspace(*p)) p++;
1589 memmove(buf, p, strlen(p) + 1);
1592 buf2 = g_strdup_printf("Re: %s", buf);
1593 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1597 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1599 if (!to_all || compose->account->protocol == A_NNTP) return;
1601 from = g_strdup(compose->replyto ? compose->replyto :
1602 msginfo->from ? msginfo->from : "");
1603 extract_address(from);
1605 cc_list = address_list_append(NULL, msginfo->to);
1606 cc_list = address_list_append(cc_list, compose->cc);
1608 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1609 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1610 if (compose->account)
1611 g_hash_table_insert(to_table, compose->account->address,
1612 GINT_TO_POINTER(1));
1614 /* remove address on To: and that of current account */
1615 for (cur = cc_list; cur != NULL; ) {
1616 GSList *next = cur->next;
1618 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1619 cc_list = g_slist_remove(cc_list, cur->data);
1621 g_hash_table_insert(to_table, cur->data, cur);
1625 g_hash_table_destroy(to_table);
1629 for (cur = cc_list; cur != NULL; cur = cur->next)
1630 compose_entry_append(compose, (gchar *)cur->data,
1632 slist_free_strings(cc_list);
1633 g_slist_free(cc_list);
1637 #define SET_ENTRY(entry, str) \
1640 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1643 #define SET_ADDRESS(type, str) \
1646 compose_entry_append(compose, str, type); \
1649 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1651 g_return_if_fail(msginfo != NULL);
1653 SET_ENTRY(subject_entry, msginfo->subject);
1654 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1655 SET_ADDRESS(COMPOSE_CC, compose->cc);
1656 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1657 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1659 #if 0 /* NEW COMPOSE GUI */
1661 GtkItemFactory *ifactory;
1662 GtkWidget *menuitem;
1664 ifactory = gtk_item_factory_from_widget(compose->menubar);
1665 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1666 gtk_check_menu_item_set_active
1667 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1669 if (compose->replyto) {
1670 GtkItemFactory *ifactory;
1671 GtkWidget *menuitem;
1673 ifactory = gtk_item_factory_from_widget(compose->menubar);
1674 menuitem = gtk_item_factory_get_item
1675 (ifactory, "/Message/Reply to");
1676 gtk_check_menu_item_set_active
1677 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1685 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1692 size_t buf_len = 128;
1694 if (strlen(sigfile) < 2)
1697 sigprg = popen(sigfile+1, "r");
1700 buf = g_malloc(buf_len);
1703 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1704 "Unable to insert signature (malloc failed)\n", -1);
1710 while (!feof(sigprg)) {
1711 bzero(buf, buf_len);
1712 fread(buf, buf_len-1, 1, sigprg);
1713 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1721 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1722 "Can't exec file: ", -1);
1723 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1728 static void compose_insert_sig(Compose *compose)
1732 if (compose->account && compose->account->sig_path)
1733 sigfile = g_strdup(compose->account->sig_path);
1735 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1736 DEFAULT_SIGNATURE, NULL);
1739 if (!is_file_or_fifo_exist(sigfile) & (sigfile[0] != '|')) {
1744 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1745 if (prefs_common.sig_sep) {
1746 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1747 prefs_common.sig_sep, -1);
1748 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1752 if (sigfile[0] == '|')
1754 compose_exec_sig(compose, sigfile);
1758 compose_insert_file(compose, sigfile);
1763 static void compose_insert_file(Compose *compose, const gchar *file)
1765 GtkSText *text = GTK_STEXT(compose->text);
1766 gchar buf[BUFFSIZE];
1770 g_return_if_fail(file != NULL);
1772 if ((fp = fopen(file, "r")) == NULL) {
1773 FILE_OP_ERROR(file, "fopen");
1777 gtk_stext_freeze(text);
1779 while (fgets(buf, sizeof(buf), fp) != NULL) {
1780 /* Strip <CR> if DOS/Windoze file, replace <CR> with <LF> if MAC file */
1782 if (len > 1 && buf[len - 2] == '\r' && buf[len - 1] == '\n') {
1783 buf[len - 2] = '\n';
1784 buf[len - 1] = '\0';
1787 if (buf[len] == '\r')
1791 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1794 gtk_stext_thaw(text);
1799 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1800 ContentType cnttype)
1802 gchar *text[N_ATTACH_COLS];
1805 text[COL_MIMETYPE] = ainfo->content_type;
1806 text[COL_SIZE] = to_human_readable(ainfo->size);
1807 text[COL_NAME] = ainfo->name;
1809 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1810 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1812 if (cnttype != MIME_MESSAGE_RFC822)
1813 compose_changed_cb(NULL, compose);
1816 static void compose_attach_append_with_type(Compose *compose,
1819 ContentType cnttype)
1824 if (!is_file_exist(file)) {
1825 g_warning(_("File %s doesn't exist\n"), file);
1828 if ((size = get_file_size(file)) < 0) {
1829 g_warning(_("Can't get file size of %s\n"), file);
1833 alertpanel_notice(_("File %s is empty\n"), file);
1836 #if 0 /* NEW COMPOSE GUI */
1837 if (!compose->use_attach) {
1838 GtkItemFactory *ifactory;
1839 GtkWidget *menuitem;
1841 ifactory = gtk_item_factory_from_widget(compose->menubar);
1842 menuitem = gtk_item_factory_get_item(ifactory,
1844 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1848 ainfo = g_new0(AttachInfo, 1);
1849 ainfo->file = g_strdup(file);
1851 if (cnttype == MIME_MESSAGE_RFC822) {
1852 ainfo->encoding = ENC_7BIT;
1853 ainfo->name = g_strdup_printf(_("Message: %s"),
1856 ainfo->encoding = ENC_BASE64;
1857 ainfo->name = g_strdup(g_basename(file));
1860 ainfo->content_type = g_strdup(type);
1863 compose_attach_info(compose, ainfo, cnttype);
1866 static void compose_attach_append(Compose *compose, const gchar *file,
1867 ContentType cnttype)
1870 gchar *text[N_ATTACH_COLS];
1874 if (!is_file_exist(file)) {
1875 g_warning(_("File %s doesn't exist\n"), file);
1878 if ((size = get_file_size(file)) < 0) {
1879 g_warning(_("Can't get file size of %s\n"), file);
1883 alertpanel_notice(_("File %s is empty\n"), file);
1886 #if 0 /* NEW COMPOSE GUI */
1887 if (!compose->use_attach) {
1888 GtkItemFactory *ifactory;
1889 GtkWidget *menuitem;
1891 ifactory = gtk_item_factory_from_widget(compose->menubar);
1892 menuitem = gtk_item_factory_get_item(ifactory,
1894 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1898 ainfo = g_new0(AttachInfo, 1);
1899 ainfo->file = g_strdup(file);
1901 if (cnttype == MIME_MESSAGE_RFC822) {
1902 ainfo->content_type = g_strdup("message/rfc822");
1903 ainfo->encoding = ENC_7BIT;
1904 ainfo->name = g_strdup_printf(_("Message: %s"),
1907 ainfo->content_type = procmime_get_mime_type(file);
1908 if (!ainfo->content_type)
1909 ainfo->content_type =
1910 g_strdup("application/octet-stream");
1911 ainfo->encoding = ENC_BASE64;
1912 ainfo->name = g_strdup(g_basename(file));
1916 compose_attach_info(compose, ainfo, cnttype);
1919 #define GET_CHAR(pos, buf, len) \
1921 if (text->use_wchar) \
1922 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
1924 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
1929 static void compose_wrap_line(Compose *compose)
1931 GtkSText *text = GTK_STEXT(compose->text);
1932 gint ch_len, last_ch_len;
1933 gchar cbuf[MB_LEN_MAX], last_ch;
1937 gint p_start, p_end;
1938 gint line_pos, cur_pos;
1939 gint line_len, cur_len;
1942 gtk_stext_freeze(text);
1944 text_len = gtk_stext_get_length(text);
1946 /* check to see if the point is on the paragraph mark (empty line). */
1947 cur_pos = gtk_stext_get_point(text);
1948 GET_CHAR(cur_pos, cbuf, ch_len);
1949 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
1951 goto compose_end; /* on the paragraph mark */
1952 GET_CHAR(cur_pos - 1, cbuf, ch_len);
1953 if (ch_len == 1 && *cbuf == '\n')
1954 goto compose_end; /* on the paragraph mark */
1957 /* find paragraph start. */
1958 line_end = quoted = 0;
1959 for (p_start = cur_pos; p_start >= 0; --p_start) {
1960 GET_CHAR(p_start, cbuf, ch_len);
1961 if (ch_len == 1 && *cbuf == '\n') {
1963 goto compose_end; /* quoted part */
1970 if (ch_len == 1 && strchr(">:#", *cbuf))
1972 else if (ch_len != 1 || !isspace(*cbuf))
1981 /* find paragraph end. */
1983 for (p_end = cur_pos; p_end < text_len; p_end++) {
1984 GET_CHAR(p_end, cbuf, ch_len);
1985 if (ch_len == 1 && *cbuf == '\n') {
1992 if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
1993 goto compose_end; /* quoted part */
1998 if (p_end >= text_len)
2001 if (p_start >= p_end)
2004 line_len = cur_len = 0;
2008 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2011 GET_CHAR(cur_pos, cbuf, ch_len);
2018 if (ch_len == 1 && isspace(*cbuf))
2021 if (ch_len == 1 && *cbuf == '\n') {
2023 if (last_ch_len == 1 && !isspace(last_ch)) {
2024 if (cur_pos + 1 < p_end) {
2025 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2026 if (ch_len == 1 && !isspace(*cbuf))
2030 gtk_stext_set_point(text, cur_pos + 1);
2031 gtk_stext_backward_delete(text, 1);
2033 gtk_stext_set_point(text, cur_pos);
2034 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2044 last_ch_len = ch_len;
2048 line_pos = cur_pos + 1;
2049 line_len = cur_len + ch_len;
2052 if (cur_len + ch_len > prefs_common.linewrap_len &&
2056 GET_CHAR(line_pos - 1, cbuf, ch_len);
2057 if (ch_len == 1 && isspace(*cbuf)) {
2058 gtk_stext_set_point(text, line_pos);
2059 gtk_stext_backward_delete(text, 1);
2068 gtk_stext_set_point(text, line_pos);
2069 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2073 cur_len = cur_len - line_len + ch_len;
2079 line_pos = cur_pos + 1;
2080 line_len = cur_len + ch_len;
2086 gtk_stext_thaw(text);
2089 /* return indent length */
2090 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2092 gint indent_len = 0;
2094 gchar cbuf[MB_LEN_MAX];
2096 for (i = start_pos; i < text_len; i++) {
2097 GET_CHAR(i, cbuf, ch_len);
2100 /* allow space, tab, > or | */
2101 if (cbuf[0] != ' ' && cbuf[0] != '\t' &&
2102 cbuf[0] != '>' && cbuf[0] != '|')
2110 /* insert quotation string when line was wrapped */
2111 static guint ins_quote(GtkSText *text, guint quote_len, guint indent_len,
2112 guint prev_line_pos, guint text_len,
2119 for (i = 0; i < indent_len; i++) {
2120 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2121 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2123 ins_len = indent_len;
2125 gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
2126 ins_len = quote_len;
2134 /* Darko: used when I debug wrapping */
2135 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2140 printf("%d [", pos);
2141 for (i = pos; i < tlen; i++) {
2142 ch = GTK_STEXT_INDEX(text, i);
2143 if (breakoncr && ch == '\n')
2151 static void compose_wrap_line_all(Compose *compose)
2153 GtkSText *text = GTK_STEXT(compose->text);
2155 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2156 gint line_len = 0, cur_len = 0;
2158 gboolean is_new_line = TRUE, do_delete = FALSE;
2159 guint qlen = 0, i_len = 0;
2160 guint linewrap_quote = prefs_common.linewrap_quote;
2161 guint linewrap_len = prefs_common.linewrap_len;
2162 gchar *qfmt = prefs_common.quotemark;
2163 gchar cbuf[MB_LEN_MAX];
2165 gtk_stext_freeze(text);
2167 /* make text buffer contiguous */
2168 /* gtk_stext_compact_buffer(text); */
2170 tlen = gtk_stext_get_length(text);
2172 for (; cur_pos < tlen; cur_pos++) {
2173 /* mark position of new line - needed for quotation wrap */
2174 if (linewrap_quote && is_new_line) {
2175 qlen = gtkut_text_str_compare
2176 (text, cur_pos, tlen, qfmt);
2177 is_new_line = FALSE;
2179 i_len = get_indent_length(text, cur_pos, tlen);
2184 printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
2185 dump_text(text, p_pos, tlen, 1);
2189 GET_CHAR(cur_pos, cbuf, ch_len);
2191 /* fix line length for tabs */
2192 if (ch_len == 1 && *cbuf == '\t') {
2193 guint tab_width = text->default_tab_width;
2194 guint tab_offset = line_len % tab_width;
2197 printf("found tab at pos=%d line_len=%d ", cur_pos,
2201 line_len += tab_width - tab_offset - 1;
2205 printf("new_len=%d\n", line_len);
2209 /* we have encountered line break */
2210 if (ch_len == 1 && *cbuf == '\n') {
2213 gchar cb[MB_CUR_MAX];
2216 printf("found CR at %d next line is ", cur_pos);
2217 dump_text(text, cur_pos + 1, tlen, 1);
2219 /* if it's just quotation + newline skip it */
2220 if (i_len && (cur_pos + 1 < tlen)) {
2221 /* check if text at new line matches indent */
2222 ilen = gtkut_text_str_compare_n
2223 (text, cur_pos + 1, p_pos, i_len, tlen);
2224 if (cur_pos + ilen < tlen) {
2225 GET_CHAR(cur_pos + ilen + 1, cb, clen);
2226 /* no need to join the lines */
2227 if (clen == 1 && cb[0] == '\n')
2230 /* if it's just newline skip it */
2231 } else if (do_delete && (cur_pos + 1 < tlen)) {
2232 GET_CHAR(cur_pos + 1, cb, clen);
2233 /* no need to join the lines */
2234 if (clen == 1 && cb[0] == '\n')
2239 printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
2240 qlen, line_len, linewrap_len, do_delete);
2242 /* should we delete to perform smart wrapping */
2243 if (line_len < linewrap_len && do_delete) {
2244 /* get rid of newline */
2245 gtk_stext_set_point(text, cur_pos);
2246 gtk_stext_forward_delete(text, 1);
2249 /* if text starts with quote fmt or with
2250 indent string, delete them */
2252 ilen = gtkut_text_str_compare_n
2253 (text, cur_pos, p_pos, i_len,
2256 gtk_stext_forward_delete(text,
2261 if (gtkut_text_str_compare
2262 (text, cur_pos, tlen, qfmt)) {
2263 gtk_stext_forward_delete
2269 GET_CHAR(cur_pos, cb, clen);
2271 /* insert space if it's alphanumeric */
2272 if ((cur_pos != line_pos) &&
2273 ((clen > 1) || isalnum(cb[0]))) {
2274 gtk_stext_insert(text, NULL, NULL,
2276 /* gtk_text_compact_buffer(text); */
2280 /* and start over with current line */
2281 cur_pos = p_pos - 1;
2283 line_len = cur_len = 0;
2288 printf("after delete l_pos=");
2289 dump_text(text, line_pos, tlen, 1);
2294 /* mark new line beginning */
2295 line_pos = cur_pos + 1;
2296 line_len = cur_len = 0;
2308 /* possible line break */
2309 if (ch_len == 1 && isspace(*cbuf)) {
2310 line_pos = cur_pos + 1;
2311 line_len = cur_len + ch_len;
2314 /* are we over wrapping length set in preferences ? */
2315 if (cur_len + ch_len > linewrap_len) {
2319 printf("should wrap cur_pos=%d ", cur_pos);
2320 dump_text(text, p_pos, tlen, 1);
2321 dump_text(text, line_pos, tlen, 1);
2323 /* force wrapping if it is one long word but not URL */
2324 if (p_pos + i_len == line_pos)
2325 if (!gtkut_text_is_uri_string
2326 (text, line_pos, tlen))
2327 line_pos = cur_pos - 1;
2329 printf("new line_pos=%d\n", line_pos);
2332 GET_CHAR(line_pos - 1, cbuf, clen);
2334 /* if next character is space delete it */
2335 if (clen == 1 && isspace(*cbuf)) {
2336 if (p_pos + i_len != line_pos ||
2337 !gtkut_text_is_uri_string
2338 (text, line_pos, tlen)) {
2339 gtk_stext_set_point(text, line_pos);
2340 gtk_stext_backward_delete(text, 1);
2349 /* if it is URL at beginning of line don't wrap */
2350 if (p_pos + i_len == line_pos &&
2351 gtkut_text_is_uri_string(text, line_pos, tlen)) {
2353 printf("found URL at ");
2354 dump_text(text, line_pos, tlen, 1);
2360 gtk_stext_set_point(text, line_pos);
2361 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2362 /* gtk_stext_compact_buffer(text); */
2365 /* for loop will increase it */
2366 cur_pos = line_pos - 1;
2367 /* start over with current line */
2373 printf("after CR insert ");
2374 dump_text(text, line_pos, tlen, 1);
2375 dump_text(text, cur_pos, tlen, 1);
2378 /* should we insert quotation ? */
2379 if (linewrap_quote && qlen) {
2380 /* only if line is not already quoted */
2381 if (!gtkut_text_str_compare
2382 (text, line_pos, tlen, qfmt)) {
2385 if (line_pos - p_pos > i_len) {
2390 /* gtk_stext_compact_buffer(text); */
2394 printf("after quote insert ");
2395 dump_text(text, line_pos, tlen, 1);
2403 line_pos = cur_pos + 1;
2404 line_len = cur_len + ch_len;
2406 /* advance to next character in buffer */
2410 gtk_stext_thaw(text);
2414 static void compose_set_title(Compose *compose)
2419 edited = compose->modified ? _(" [Edited]") : "";
2420 if (compose->account && compose->account->address)
2421 str = g_strdup_printf(_("%s - Compose message%s"),
2422 compose->account->address, edited);
2424 str = g_strdup_printf(_("Compose message%s"), edited);
2425 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2430 * compose_current_mail_account:
2432 * Find a current mail account (the currently selected account, or the
2433 * default account, if a news account is currently selected). If a
2434 * mail account cannot be found, display an error message.
2436 * Return value: Mail account, or NULL if not found.
2438 static PrefsAccount *
2439 compose_current_mail_account(void)
2443 if (cur_account && cur_account->protocol != A_NNTP)
2446 ac = account_get_default();
2447 if (!ac || ac->protocol == A_NNTP) {
2448 alertpanel_error(_("Account for sending mail is not specified.\n"
2449 "Please select a mail account before sending."));
2456 gboolean compose_check_for_valid_recipient(Compose *compose) {
2457 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2458 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2459 gboolean recipient_found = FALSE;
2463 /* free to and newsgroup list */
2464 slist_free_strings(compose->to_list);
2465 g_slist_free(compose->to_list);
2466 compose->to_list = NULL;
2468 slist_free_strings(compose->newsgroup_list);
2469 g_slist_free(compose->newsgroup_list);
2470 compose->newsgroup_list = NULL;
2472 /* search header entries for to and newsgroup entries */
2473 for(list = compose->header_list; list; list = list->next) {
2476 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2477 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2479 if(entry[0] != '\0') {
2480 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2481 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2482 compose->to_list = address_list_append(compose->to_list, entry);
2483 recipient_found = TRUE;
2486 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2487 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2488 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2489 recipient_found = TRUE;
2495 return recipient_found;
2498 gint compose_send(Compose *compose)
2504 val = compose_queue(compose, &msgnum, &folder);
2506 alertpanel_error(_("Could not queue message for sending"));
2510 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2512 folder_item_remove_msg(folder, msgnum);
2513 folderview_update_item(folder, TRUE);
2519 #if 0 /* compose restructure */
2520 gint compose_send(Compose *compose)
2522 gchar tmp[MAXPATHLEN + 1];
2524 static gboolean lock = FALSE;
2528 g_return_val_if_fail(compose->account != NULL, -1);
2529 g_return_val_if_fail(compose->orig_account != NULL, -1);
2533 if(!compose_check_for_valid_recipient(compose)) {
2534 alertpanel_error(_("Recipient is not specified."));
2539 /* write to temporary file */
2540 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2541 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2543 if (prefs_common.linewrap_at_send)
2544 compose_wrap_line_all(compose);
2546 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2551 if (!compose->to_list && !compose->newsgroup_list) {
2552 g_warning(_("can't get recipient list."));
2558 if (compose->to_list) {
2561 #if 0 /* NEW COMPOSE GUI */
2562 if (compose->account->protocol != A_NNTP)
2563 ac = compose->account;
2564 else if (compose->orig_account->protocol != A_NNTP)
2565 ac = compose->orig_account;
2566 else if (cur_account && cur_account->protocol != A_NNTP)
2569 ac = compose_current_mail_account();
2577 ac = compose->account;
2579 ok = send_message(tmp, ac, compose->to_list);
2580 statusbar_pop_all();
2583 if (ok == 0 && compose->newsgroup_list) {
2586 if (compose->account->protocol == A_NNTP)
2587 folder = FOLDER(compose->account->folder);
2589 folder = FOLDER(compose->orig_account->folder);
2591 ok = news_post(folder, tmp);
2593 alertpanel_error(_("Error occurred while posting the message to %s ."),
2594 compose->account->nntp_server);
2601 /* queue message if failed to send */
2603 if (prefs_common.queue_msg) {
2608 _("Error occurred while sending the message.\n"
2609 "Put this message into queue folder?"),
2610 _("OK"), _("Cancel"), NULL);
2611 if (G_ALERTDEFAULT == val) {
2612 ok = compose_queue(compose, tmp);
2614 alertpanel_error(_("Can't queue the message."));
2617 alertpanel_error(_("Error occurred while sending the message."));
2619 if (compose->mode == COMPOSE_REEDIT) {
2620 compose_remove_reedit_target(compose);
2621 if (compose->targetinfo)
2622 folderview_update_item
2623 (compose->targetinfo->folder, TRUE);
2627 /* save message to outbox */
2628 if (ok == 0 && prefs_common.savemsg) {
2629 if (compose_save_to_outbox(compose, tmp) < 0)
2631 (_("Can't save the message to outbox."));
2640 static gboolean compose_use_attach(Compose *compose) {
2641 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2644 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2647 gchar buf[BUFFSIZE];
2649 gboolean first_address;
2651 ComposeHeaderEntry *headerentry;
2652 gchar *headerentryname;
2653 gchar *header_w_colon;
2657 debug_print(_("Writing bounce header\n"));
2659 header_w_colon = g_strconcat("To:", NULL);
2660 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2661 header_w_colon = g_strconcat("Cc:", NULL);
2662 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2664 first_address = TRUE;
2665 for(list = compose->header_list; list; list = list->next) {
2666 headerentry = ((ComposeHeaderEntry *)list->data);
2667 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2669 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2670 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2671 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2672 Xstrdup_a(str, str, return -1);
2674 if(str[0] != '\0') {
2675 compose_convert_header
2676 (buf, sizeof(buf), str,
2677 strlen("Resent-To") + 2);
2679 fprintf(fp, "Resent-To: ");
2680 first_address = FALSE;
2684 fprintf(fp, "%s", buf);
2688 /* if(!first_address) { */
2695 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2697 gchar buf[BUFFSIZE];
2699 /* struct utsname utsbuf; */
2701 g_return_val_if_fail(fp != NULL, -1);
2702 g_return_val_if_fail(compose->account != NULL, -1);
2703 g_return_val_if_fail(compose->account->address != NULL, -1);
2706 get_rfc822_date(buf, sizeof(buf));
2707 fprintf(fp, "Resent-Date: %s\n", buf);
2710 if (compose->account->name && *compose->account->name) {
2711 compose_convert_header
2712 (buf, sizeof(buf), compose->account->name,
2714 fprintf(fp, "Resent-From: %s <%s>\n",
2715 buf, compose->account->address);
2717 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2720 compose_bounce_write_headers_from_headerlist(compose, fp);
2722 /* separator between header and body */
2728 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2733 gchar buf[BUFFSIZE];
2735 if ((fp = fopen(compose->bounce_filename, "r")) == NULL) {
2736 FILE_OP_ERROR(file, "fopen");
2740 if ((fdest = fopen(file, "w")) == NULL) {
2741 FILE_OP_ERROR(file, "fopen");
2746 /* chmod for security */
2747 if (change_file_mode_rw(fdest, file) < 0) {
2748 FILE_OP_ERROR(file, "chmod");
2749 g_warning(_("can't change file mode\n"));
2752 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2753 /* should filter returnpath, delivered-to */
2754 if ((g_strncasecmp(buf, "Return-Path:",
2755 strlen("Return-Path:")) == 0)
2756 || (g_strncasecmp(buf, "Delivered-To:",
2757 strlen("Delivered-To:")) == 0))
2760 if (fputs(buf, fdest) == -1)
2763 if (g_strncasecmp(buf, "From:", strlen("From:")) == 0) {
2764 fputs(" (by way of ", fdest);
2765 if (compose->account->name
2766 && *compose->account->name) {
2767 compose_convert_header
2769 compose->account->name,
2771 fprintf(fdest, "%s <%s>",
2772 buf, compose->account->address);
2774 fprintf(fdest, "%s",
2775 compose->account->address);
2779 if (fputs("\n", fdest) == -1)
2783 compose_bounce_write_headers(compose, fdest);
2785 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
2786 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
2801 static gint compose_write_to_file(Compose *compose, const gchar *file,
2808 const gchar *out_codeset;
2809 EncodingType encoding;
2811 if ((fp = fopen(file, "w")) == NULL) {
2812 FILE_OP_ERROR(file, "fopen");
2816 /* chmod for security */
2817 if (change_file_mode_rw(fp, file) < 0) {
2818 FILE_OP_ERROR(file, "chmod");
2819 g_warning(_("can't change file mode\n"));
2822 /* get all composed text */
2823 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2824 len = strlen(chars);
2825 if (is_ascii_str(chars)) {
2826 buf = g_strdup(chars);
2827 out_codeset = CS_US_ASCII;
2828 encoding = ENC_7BIT;
2830 const gchar *src_codeset;
2832 out_codeset = conv_get_outgoing_charset_str();
2833 if (!strcasecmp(out_codeset, CS_US_ASCII))
2834 out_codeset = CS_ISO_8859_1;
2835 encoding = procmime_get_encoding_for_charset(out_codeset);
2837 src_codeset = conv_get_current_charset_str();
2838 /* if current encoding is US-ASCII, set it the same as
2839 outgoing one to prevent code conversion failure */
2840 if (!strcasecmp(src_codeset, CS_US_ASCII))
2841 src_codeset = out_codeset;
2843 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
2844 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
2846 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
2851 alertpanel_error(_("Can't convert the codeset of the message."));
2858 if (compose_write_headers
2859 (compose, fp, out_codeset, encoding, is_draft) < 0) {
2860 g_warning(_("can't write headers\n"));
2867 if (compose_use_attach(compose)) {
2869 /* This prolog message is ignored by mime software and
2870 * because it would make our signing/encryption task
2871 * tougher, we don't emit it in that case */
2872 if (!compose->use_signing && !compose->use_encryption)
2874 fputs("This is a multi-part message in MIME format.\n", fp);
2876 fprintf(fp, "\n--%s\n", compose->boundary);
2877 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
2879 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2880 procmime_get_encoding_str(encoding));
2886 if (encoding == ENC_BASE64) {
2887 gchar outbuf[B64_BUFFSIZE];
2890 for (i = 0; i < len; i += B64_LINE_SIZE) {
2891 l = MIN(B64_LINE_SIZE, len - i);
2892 to64frombits(outbuf, buf + i, l);
2896 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
2897 FILE_OP_ERROR(file, "fwrite");
2905 if (compose_use_attach(compose))
2906 compose_write_attach(compose, fp);
2908 if (fclose(fp) == EOF) {
2909 FILE_OP_ERROR(file, "fclose");
2915 if (compose->use_signing) {
2916 if (rfc2015_sign(file, compose->account) < 0) {
2921 if (compose->use_encryption) {
2922 if (rfc2015_encrypt(file, compose->to_list) < 0) {
2927 #endif /* USE_GPGME */
2932 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
2938 if ((fp = fopen(file, "w")) == NULL) {
2939 FILE_OP_ERROR(file, "fopen");
2943 /* chmod for security */
2944 if (change_file_mode_rw(fp, file) < 0) {
2945 FILE_OP_ERROR(file, "chmod");
2946 g_warning(_("can't change file mode\n"));
2949 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2952 len = strlen(chars);
2953 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
2954 FILE_OP_ERROR(file, "fwrite");
2963 if (fclose(fp) == EOF) {
2964 FILE_OP_ERROR(file, "fclose");
2971 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
2978 debug_print(_("saving sent message...\n"));
2980 outbox = folder_get_default_outbox();
2981 path = folder_item_get_path(outbox);
2982 if (!is_dir_exist(path))
2983 make_dir_hier(path);
2985 folder_item_scan(outbox);
2986 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
2988 g_warning(_("can't save message\n"));
2992 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
2993 g_warning(_("can't open mark file\n"));
2997 newmsginfo.msgnum = num;
2998 newmsginfo.flags.perm_flags = 0;
2999 newmsginfo.flags.tmp_flags = 0;
3000 procmsg_write_flags(&newmsginfo, fp);
3008 static gint compose_remove_reedit_target(Compose *compose)
3011 MsgInfo *msginfo = compose->targetinfo;
3013 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3014 if (!msginfo) return -1;
3016 item = msginfo->folder;
3017 g_return_val_if_fail(item != NULL, -1);
3019 folder_item_scan(item);
3020 if (procmsg_msg_exist(msginfo) &&
3021 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3022 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3023 g_warning(_("can't remove the old message\n"));
3032 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3035 gchar *tmp, *tmp2, *queue_path;
3038 gchar buf[BUFFSIZE];
3040 static gboolean lock = FALSE;
3041 PrefsAccount *mailac = NULL, *newsac = NULL;
3043 debug_print(_("queueing message...\n"));
3044 g_return_val_if_fail(compose->account != NULL, -1);
3045 g_return_val_if_fail(compose->orig_account != NULL, -1);
3049 if(!compose_check_for_valid_recipient(compose)) {
3050 alertpanel_error(_("Recipient is not specified."));
3055 if (!compose->to_list && !compose->newsgroup_list) {
3056 g_warning(_("can't get recipient list."));
3061 if(compose->to_list) {
3062 if (compose->account->protocol != A_NNTP)
3063 mailac = compose->account;
3064 else if (compose->orig_account->protocol != A_NNTP)
3065 mailac = compose->orig_account;
3066 else if (cur_account && cur_account->protocol != A_NNTP)
3067 mailac = cur_account;
3068 else if (!(mailac = compose_current_mail_account())) {
3070 alertpanel_error(_("No account for sending mails available!"));
3075 if(compose->newsgroup_list) {
3076 if (compose->account->protocol == A_NNTP)
3077 newsac = compose->account;
3078 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3080 alertpanel_error(_("No account for posting news available!"));
3085 if (prefs_common.linewrap_at_send)
3086 compose_wrap_line_all(compose);
3088 /* write to temporary file */
3089 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3090 G_DIR_SEPARATOR, (gint)compose);
3092 if (compose->bounce_filename != NULL) {
3093 if (compose_bounce_write_to_file(compose, tmp2) < 0) {
3100 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3107 /* add queue header */
3108 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3109 G_DIR_SEPARATOR, (gint)compose);
3110 if ((fp = fopen(tmp, "w")) == NULL) {
3111 FILE_OP_ERROR(tmp, "fopen");
3115 if ((src_fp = fopen(tmp2, "r")) == NULL) {
3116 FILE_OP_ERROR(tmp2, "fopen");
3124 if (change_file_mode_rw(fp, tmp) < 0) {
3125 FILE_OP_ERROR(tmp, "chmod");
3126 g_warning(_("can't change file mode\n"));
3129 /* queueing variables */
3130 fprintf(fp, "AF:\n");
3131 fprintf(fp, "NF:0\n");
3132 fprintf(fp, "PS:10\n");
3133 fprintf(fp, "SRH:1\n");
3134 fprintf(fp, "SFN:\n");
3135 fprintf(fp, "DSR:\n");
3137 fprintf(fp, "MID:<%s>\n", compose->msgid);
3139 fprintf(fp, "MID:\n");
3140 fprintf(fp, "CFG:\n");
3141 fprintf(fp, "PT:0\n");
3142 fprintf(fp, "S:%s\n", compose->account->address);
3143 fprintf(fp, "RQ:\n");
3145 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3147 fprintf(fp, "SSV:\n");
3149 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3151 fprintf(fp, "NSV:\n");
3152 fprintf(fp, "SSH:\n");
3153 /* write recepient list */
3155 if(compose->to_list) {
3156 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3157 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3158 fprintf(fp, ",<%s>", (gchar *)cur->data);
3161 /* write newsgroup list */
3163 if(compose->newsgroup_list) {
3164 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3165 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3166 fprintf(fp, ",%s", (gchar *)cur->data);
3169 /* Sylpheed account IDs */
3171 fprintf(fp, "MAID:%d\n", mailac->account_id);
3174 fprintf(fp, "NAID:%d\n", newsac->account_id);
3176 /* Save copy folder */
3177 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3180 str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3181 fprintf(fp, "SCF:%s\n", str);
3186 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3187 if (fputs(buf, fp) == EOF) {
3188 FILE_OP_ERROR(tmp, "fputs");
3199 if (fclose(fp) == EOF) {
3200 FILE_OP_ERROR(tmp, "fclose");
3209 queue = folder_get_default_queue();
3211 folder_item_scan(queue);
3212 queue_path = folder_item_get_path(queue);
3213 if (!is_dir_exist(queue_path))
3214 make_dir_hier(queue_path);
3215 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3216 g_warning(_("can't queue the message\n"));
3227 if (compose->mode == COMPOSE_REEDIT) {
3228 compose_remove_reedit_target(compose);
3229 if (compose->targetinfo &&
3230 compose->targetinfo->folder != queue)
3231 folderview_update_item
3232 (compose->targetinfo->folder, TRUE);
3235 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
3236 g_warning(_("can't open mark file\n"));
3240 newmsginfo.msgnum = num;
3241 newmsginfo.flags.perm_flags = 0;
3242 newmsginfo.flags.tmp_flags = 0;
3243 procmsg_write_flags(&newmsginfo, fp);
3248 folder_item_scan(queue);
3249 folderview_update_item(queue, TRUE);
3251 if((msgnum != NULL) && (item != NULL)) {
3259 static void compose_write_attach(Compose *compose, FILE *fp)
3262 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3265 gchar filename[BUFFSIZE];
3268 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3270 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
3271 g_warning(_("Can't open file %s\n"), ainfo->file);
3275 fprintf(fp, "\n--%s\n", compose->boundary);
3277 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3278 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3279 fprintf(fp, "Content-Disposition: inline\n");
3281 conv_encode_header(filename, sizeof(filename),
3283 fprintf(fp, "Content-Type: %s;\n"
3285 ainfo->content_type, filename);
3286 fprintf(fp, "Content-Disposition: attachment;\n"
3287 " filename=\"%s\"\n", filename);
3290 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3291 procmime_get_encoding_str(ainfo->encoding));
3293 if (ainfo->encoding == ENC_7BIT) {
3294 gchar buf[BUFFSIZE];
3296 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3301 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3303 while ((len = fread(inbuf, sizeof(gchar),
3304 B64_LINE_SIZE, attach_fp))
3306 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3310 if (len > 0 && feof(attach_fp)) {
3311 to64frombits(outbuf, inbuf, len);
3320 fprintf(fp, "\n--%s--\n", compose->boundary);
3323 #define IS_IN_CUSTOM_HEADER(header) \
3324 (compose->account->add_customhdr && \
3325 custom_header_find(compose->account->customhdr_list, header) != NULL)
3327 static gint compose_write_headers_from_headerlist(Compose *compose,
3331 gchar buf[BUFFSIZE];
3332 gchar *str, *header_w_colon, *trans_hdr;
3333 gboolean first_address;
3335 ComposeHeaderEntry *headerentry;
3336 gchar * headerentryname;
3338 if (IS_IN_CUSTOM_HEADER(header)) {
3342 debug_print(_("Writing %s-header\n"), header);
3344 header_w_colon = g_strconcat(header, ":", NULL);
3345 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3347 first_address = TRUE;
3348 for(list = compose->header_list; list; list = list->next) {
3349 headerentry = ((ComposeHeaderEntry *)list->data);
3350 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3352 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3353 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3354 Xstrdup_a(str, str, return -1);
3356 if(str[0] != '\0') {
3357 compose_convert_header
3358 (buf, sizeof(buf), str,
3359 strlen(header) + 2);
3361 fprintf(fp, "%s: ", header);
3362 first_address = FALSE;
3366 fprintf(fp, "%s", buf);
3370 if(!first_address) {
3374 g_free(header_w_colon);
3379 static gint compose_write_headers(Compose *compose, FILE *fp,
3380 const gchar *charset, EncodingType encoding,
3383 gchar buf[BUFFSIZE];
3385 /* struct utsname utsbuf; */
3387 g_return_val_if_fail(fp != NULL, -1);
3388 g_return_val_if_fail(charset != NULL, -1);
3389 g_return_val_if_fail(compose->account != NULL, -1);
3390 g_return_val_if_fail(compose->account->address != NULL, -1);
3393 if (compose->account->add_date) {
3394 get_rfc822_date(buf, sizeof(buf));
3395 fprintf(fp, "Date: %s\n", buf);
3399 if (!IS_IN_CUSTOM_HEADER("From")) {
3400 if (compose->account->name && *compose->account->name) {
3401 compose_convert_header
3402 (buf, sizeof(buf), compose->account->name,
3404 fprintf(fp, "From: %s <%s>\n",
3405 buf, compose->account->address);
3407 fprintf(fp, "From: %s\n", compose->account->address);
3411 compose_write_headers_from_headerlist(compose, fp, "To");
3412 #if 0 /* NEW COMPOSE GUI */
3413 if (compose->use_to) {
3414 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3416 Xstrdup_a(str, str, return -1);
3419 compose->to_list = address_list_append
3420 (compose->to_list, str);
3421 if (!IS_IN_CUSTOM_HEADER("To")) {
3422 compose_convert_header
3423 (buf, sizeof(buf), str,
3425 fprintf(fp, "To: %s\n", buf);
3433 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3434 #if 0 /* NEW COMPOSE GUI */
3435 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3437 Xstrdup_a(str, str, return -1);
3441 compose->newsgroup_list =
3442 newsgroup_list_append(compose->newsgroup_list,
3444 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3445 compose_convert_header(buf, sizeof(buf), str,
3446 strlen("Newsgroups: "));
3447 fprintf(fp, "Newsgroups: %s\n", buf);
3453 compose_write_headers_from_headerlist(compose, fp, "Cc");
3454 #if 0 /* NEW COMPOSE GUI */
3455 if (compose->use_cc) {
3456 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3458 Xstrdup_a(str, str, return -1);
3461 compose->to_list = address_list_append
3462 (compose->to_list, str);
3463 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3464 compose_convert_header
3465 (buf, sizeof(buf), str,
3467 fprintf(fp, "Cc: %s\n", buf);
3474 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3475 #if 0 /* NEW COMPOSE GUI */
3476 if (compose->use_bcc) {
3477 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3479 Xstrdup_a(str, str, return -1);
3482 compose->to_list = address_list_append
3483 (compose->to_list, str);
3484 compose_convert_header(buf, sizeof(buf), str,
3486 fprintf(fp, "Bcc: %s\n", buf);
3493 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3494 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3495 Xstrdup_a(str, str, return -1);
3498 compose_convert_header(buf, sizeof(buf), str,
3499 strlen("Subject: "));
3500 fprintf(fp, "Subject: %s\n", buf);
3505 if (compose->account->gen_msgid) {
3506 compose_generate_msgid(compose, buf, sizeof(buf));
3507 fprintf(fp, "Message-Id: <%s>\n", buf);
3508 compose->msgid = g_strdup(buf);
3512 if (compose->inreplyto && compose->to_list)
3513 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3516 if (compose->references)
3517 fprintf(fp, "References: %s\n", compose->references);
3520 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3521 #if 0 /* NEW COMPOSE GUI */
3522 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3523 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3525 Xstrdup_a(str, str, return -1);
3529 compose_convert_header(buf, sizeof(buf), str,
3530 strlen("Followup-To: "));
3531 fprintf(fp, "Followup-To: %s\n", buf);
3537 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3538 #if 0 /* NEW COMPOSE GUI */
3539 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3540 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3542 Xstrdup_a(str, str, return -1);
3545 compose_convert_header(buf, sizeof(buf), str,
3546 strlen("Reply-To: "));
3547 fprintf(fp, "Reply-To: %s\n", buf);
3553 if (compose->account->organization &&
3554 !IS_IN_CUSTOM_HEADER("Organization")) {
3555 compose_convert_header(buf, sizeof(buf),
3556 compose->account->organization,
3557 strlen("Organization: "));
3558 fprintf(fp, "Organization: %s\n", buf);
3561 /* Program version and system info */
3562 /* uname(&utsbuf); */
3563 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3564 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3566 gtk_major_version, gtk_minor_version, gtk_micro_version,
3568 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3570 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3571 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3573 gtk_major_version, gtk_minor_version, gtk_micro_version,
3575 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3578 /* custom headers */
3579 if (compose->account->add_customhdr) {
3582 for (cur = compose->account->customhdr_list; cur != NULL;
3584 CustomHeader *chdr = (CustomHeader *)cur->data;
3586 if (strcasecmp(chdr->name, "Date") != 0 &&
3587 strcasecmp(chdr->name, "From") != 0 &&
3588 strcasecmp(chdr->name, "To") != 0 &&
3589 /* strcasecmp(chdr->name, "Sender") != 0 && */
3590 strcasecmp(chdr->name, "Message-Id") != 0 &&
3591 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3592 strcasecmp(chdr->name, "References") != 0 &&
3593 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3594 strcasecmp(chdr->name, "Content-Type") != 0 &&
3595 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3597 compose_convert_header
3599 chdr->value ? chdr->value : "",
3600 strlen(chdr->name) + 2);
3601 fprintf(fp, "%s: %s\n", chdr->name, buf);
3607 fprintf(fp, "Mime-Version: 1.0\n");
3608 if (compose_use_attach(compose)) {
3609 get_rfc822_date(buf, sizeof(buf));
3610 subst_char(buf, ' ', '_');
3611 subst_char(buf, ',', '_');
3612 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3613 buf, (guint)compose);
3615 "Content-Type: multipart/mixed;\n"
3616 " boundary=\"%s\"\n", compose->boundary);
3618 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3619 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3620 procmime_get_encoding_str(encoding));
3623 /* Request Return Receipt */
3624 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3625 if (compose->return_receipt) {
3626 if (compose->account->name
3627 && *compose->account->name) {
3628 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3629 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3631 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3635 /* separator between header and body */
3641 #undef IS_IN_CUSTOM_HEADER
3643 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3646 g_return_if_fail(src != NULL);
3647 g_return_if_fail(dest != NULL);
3649 if (len < 1) return;
3653 if (is_ascii_str(src)) {
3654 strncpy2(dest, src, len);
3655 dest[len - 1] = '\0';
3658 conv_encode_header(dest, len, src, header_len);
3661 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3670 if (compose->account && compose->account->address &&
3671 *compose->account->address) {
3672 if (strchr(compose->account->address, '@'))
3673 addr = g_strdup(compose->account->address);
3675 addr = g_strconcat(compose->account->address, "@",
3676 get_domain_name(), NULL);
3678 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3681 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3682 lt->tm_year + 1900, lt->tm_mon + 1,
3683 lt->tm_mday, lt->tm_hour,
3684 lt->tm_min, lt->tm_sec,
3685 (guint)random(), addr);
3687 debug_print(_("generated Message-ID: %s\n"), buf);
3693 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3694 GtkWidget **entry, gint *count,
3695 const gchar *label_str,
3696 gboolean is_addr_entry)
3700 if (GTK_TABLE(table)->nrows < (*count) + 1)
3701 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3703 *hbox = gtk_hbox_new(FALSE, 0);
3704 label = gtk_label_new
3705 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3706 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3707 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3709 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3711 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3712 #if 0 /* NEW COMPOSE GUI */
3713 if (GTK_TABLE(table)->nrows > (*count) + 1)
3714 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3718 address_completion_register_entry(GTK_ENTRY(*entry));
3723 static void compose_create_header_entry(Compose *compose)
3725 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3729 GList *combo_list = NULL;
3730 gchar **string, *header;
3731 ComposeHeaderEntry *headerentry;
3733 headerentry = g_new0(ComposeHeaderEntry, 1);
3736 combo = gtk_combo_new();
3738 while(*string != NULL) {
3739 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3742 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3743 g_list_free(combo_list);
3744 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3745 gtk_widget_show(combo);
3746 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3747 if(compose->header_last) {
3748 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3750 switch(compose->account->protocol) {
3752 header = prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:";
3755 header = prefs_common.trans_hdr ? _("To:") : "To:";
3759 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
3762 entry = gtk_entry_new();
3763 gtk_widget_show(entry);
3764 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);
3766 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
3767 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
3769 address_completion_register_entry(GTK_ENTRY(entry));
3771 headerentry->compose = compose;
3772 headerentry->combo = combo;
3773 headerentry->entry = entry;
3774 headerentry->headernum = compose->header_nextrow;
3776 compose->header_nextrow++;
3777 compose->header_last = headerentry;
3780 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text)
3782 ComposeHeaderEntry *last_header;
3784 last_header = compose->header_last;
3786 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
3787 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
3790 static GtkWidget *compose_create_header(Compose *compose)
3793 GtkWidget *from_optmenu_hbox;
3794 #if 0 /* NEW COMPOSE GUI */
3795 GtkWidget *to_entry;
3797 GtkWidget *newsgroups_entry;
3798 GtkWidget *newsgroups_hbox;
3800 GtkWidget *header_scrolledwin;
3801 GtkWidget *header_table;
3802 GtkWidget *subject_entry;
3803 #if 0 /* NEW COMPOSE GUI */
3804 GtkWidget *cc_entry;
3806 GtkWidget *bcc_entry;
3807 GtkWidget *bcc_hbox;
3808 GtkWidget *reply_entry;
3809 GtkWidget *reply_hbox;
3810 GtkWidget *followup_entry;
3811 GtkWidget *followup_hbox;
3817 /* header labels and entries */
3818 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3819 gtk_widget_show(header_scrolledwin);
3820 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
3822 header_table = gtk_table_new(2, 2, FALSE);
3823 gtk_widget_show(header_table);
3824 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
3825 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
3828 /* option menu for selecting accounts */
3829 hbox = gtk_hbox_new(FALSE, 0);
3830 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
3831 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3832 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
3834 from_optmenu_hbox = compose_account_option_menu_create(compose);
3835 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
3836 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
3837 #if 0 /* NEW COMPOSE GUI */
3838 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3843 compose_add_entry_field(header_table, &hbox, &subject_entry, &count,
3846 compose->header_table = header_table;
3847 compose->header_list = NULL;
3848 compose->header_nextrow = count;
3850 compose_create_header_entry(compose);
3852 #if 0 /* NEW COMPOSE GUI */
3853 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
3855 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3856 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
3857 &count, "Newsgroups:", FALSE);
3858 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
3860 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
3862 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
3864 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
3865 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
3867 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
3868 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
3870 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
3871 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
3872 "Followup-To:", FALSE);
3873 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
3875 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
3877 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
3878 GTK_SIGNAL_FUNC(to_activated), compose);
3879 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
3880 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
3881 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
3882 GTK_SIGNAL_FUNC(subject_activated), compose);
3883 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
3884 GTK_SIGNAL_FUNC(cc_activated), compose);
3885 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
3886 GTK_SIGNAL_FUNC(bcc_activated), compose);
3887 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
3888 GTK_SIGNAL_FUNC(replyto_activated), compose);
3889 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
3890 GTK_SIGNAL_FUNC(followupto_activated), compose);
3892 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
3893 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3894 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
3895 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3896 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
3897 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3898 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
3899 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3900 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
3901 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3902 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
3903 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3904 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
3905 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3908 compose->table = NULL;
3909 #if 0 /* NEW COMPOSE GUI */
3910 compose->table = table;
3911 compose->to_hbox = to_hbox;
3912 compose->to_entry = to_entry;
3913 compose->newsgroups_hbox = newsgroups_hbox;
3914 compose->newsgroups_entry = newsgroups_entry;
3916 compose->subject_entry = subject_entry;
3917 #if 0 /* NEW COMPOSE GUI */
3918 compose->cc_hbox = cc_hbox;
3919 compose->cc_entry = cc_entry;
3920 compose->bcc_hbox = bcc_hbox;
3921 compose->bcc_entry = bcc_entry;
3922 compose->reply_hbox = reply_hbox;
3923 compose->reply_entry = reply_entry;
3924 compose->followup_hbox = followup_hbox;
3925 compose->followup_entry = followup_entry;
3928 return header_scrolledwin ;
3931 GtkWidget *compose_create_attach(Compose *compose)
3933 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
3936 GtkWidget *attach_scrwin;
3937 GtkWidget *attach_clist;
3939 /* attachment list */
3940 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
3941 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
3942 GTK_POLICY_AUTOMATIC,
3944 gtk_widget_set_usize(attach_scrwin, -1, 80);
3946 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
3947 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
3949 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
3950 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
3951 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
3952 GTK_SELECTION_EXTENDED);
3953 for (i = 0; i < N_ATTACH_COLS; i++)
3954 GTK_WIDGET_UNSET_FLAGS
3955 (GTK_CLIST(attach_clist)->column[i].button,
3957 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
3959 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
3960 GTK_SIGNAL_FUNC(attach_selected), compose);
3961 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
3962 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
3963 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
3964 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
3967 gtk_drag_dest_set(attach_clist,
3968 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3970 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
3971 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
3974 compose->attach_scrwin = attach_scrwin;
3975 compose->attach_clist = attach_clist;
3977 return attach_scrwin;
3980 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose);
3981 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose);
3983 static GtkWidget *compose_create_others(Compose *compose)
3986 GtkWidget *savemsg_checkbtn;
3987 GtkWidget *savemsg_entry;
3988 GtkWidget *savemsg_select;
3991 gchar *folderidentifier;
3993 /* Table for settings */
3994 table = gtk_table_new(3, 1, FALSE);
3995 gtk_widget_show(table);
3996 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
3999 /* Save Message to folder */
4000 savemsg_checkbtn = gtk_check_button_new_with_label(_("Save Message to "));
4001 gtk_widget_show(savemsg_checkbtn);
4002 gtk_table_attach(GTK_TABLE(table), savemsg_checkbtn, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4003 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), prefs_common.savemsg);
4004 gtk_signal_connect(GTK_OBJECT(savemsg_checkbtn), "toggled",
4005 GTK_SIGNAL_FUNC(compose_savemsg_checkbtn_cb), compose);
4007 savemsg_entry = gtk_entry_new();
4008 gtk_widget_show(savemsg_entry);
4009 gtk_table_attach_defaults(GTK_TABLE(table), savemsg_entry, 1, 2, rowcount, rowcount + 1);
4010 gtk_editable_set_editable(GTK_EDITABLE(savemsg_entry), prefs_common.savemsg);
4011 folderidentifier = folder_item_get_identifier(folder_get_default_outbox());
4012 gtk_entry_set_text(GTK_ENTRY(savemsg_entry), folderidentifier);
4013 g_free(folderidentifier);
4015 savemsg_select = gtk_button_new_with_label (_("Select ..."));
4016 gtk_widget_show (savemsg_select);
4017 gtk_table_attach(GTK_TABLE(table), savemsg_select, 2, 3, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
4018 gtk_signal_connect (GTK_OBJECT (savemsg_select), "clicked",
4019 GTK_SIGNAL_FUNC (compose_savemsg_select_cb),
4024 compose->savemsg_checkbtn = savemsg_checkbtn;
4025 compose->savemsg_entry = savemsg_entry;
4030 static void compose_savemsg_checkbtn_cb(GtkWidget *widget, Compose *compose)
4032 gtk_editable_set_editable(GTK_EDITABLE(compose->savemsg_entry),
4033 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn)));
4036 static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
4041 dest = foldersel_folder_sel(NULL, NULL);
4044 path = folder_item_get_identifier(dest);
4046 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), path);
4050 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
4056 GtkWidget *handlebox;
4058 GtkWidget *notebook;
4062 GtkWidget *table_vbox;
4066 GtkWidget *edit_vbox;
4067 GtkWidget *ruler_hbox;
4069 GtkWidget *scrolledwin;
4074 UndoMain *undostruct;
4076 guint n_menu_entries;
4077 GtkStyle *style, *new_style;
4080 gboolean success[1];
4082 GtkWidget *popupmenu;
4083 GtkWidget *menuitem;
4084 GtkItemFactory *popupfactory;
4085 GtkItemFactory *ifactory;
4086 GtkWidget *tmpl_menu;
4090 GtkPspell * gtkpspell = NULL;
4093 g_return_val_if_fail(account != NULL, NULL);
4095 debug_print(_("Creating compose window...\n"));
4096 compose = g_new0(Compose, 1);
4098 compose->account = account;
4099 compose->orig_account = account;
4101 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4102 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
4103 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
4104 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4105 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
4106 gtk_signal_connect(GTK_OBJECT(window), "destroy",
4107 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
4108 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
4109 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
4110 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
4111 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
4112 gtk_widget_realize(window);
4114 gtkut_widget_set_composer_icon(window);
4116 vbox = gtk_vbox_new(FALSE, 0);
4117 gtk_container_add(GTK_CONTAINER(window), vbox);
4119 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
4120 menubar = menubar_create(window, compose_entries,
4121 n_menu_entries, "<Compose>", compose);
4122 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
4124 handlebox = gtk_handle_box_new();
4125 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
4127 compose_toolbar_create(compose, handlebox);
4129 vbox2 = gtk_vbox_new(FALSE, 2);
4130 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
4131 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
4133 table_vbox = gtk_vbox_new(FALSE, 0);
4134 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
4135 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
4139 notebook = gtk_notebook_new();
4140 gtk_widget_set_usize(notebook, -1, 180);
4141 gtk_widget_show(notebook);
4143 /* header labels and entries */
4144 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_header(compose), gtk_label_new(_("Header")));
4145 /* attachment list */
4146 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), gtk_label_new(_("Attachments")));
4148 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
4150 edit_vbox = gtk_vbox_new(FALSE, 0);
4151 #if 0 /* NEW COMPOSE GUI */
4152 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4156 ruler_hbox = gtk_hbox_new(FALSE, 0);
4157 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4159 ruler = gtk_shruler_new();
4160 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4161 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4163 gtk_widget_set_usize(ruler_hbox, 1, -1);
4166 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4167 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4168 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4169 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4170 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4172 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4173 (GTK_SCROLLED_WINDOW(scrolledwin)),
4174 gtk_scrolled_window_get_vadjustment
4175 (GTK_SCROLLED_WINDOW(scrolledwin)));
4176 GTK_STEXT(text)->default_tab_width = 8;
4177 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4179 if (prefs_common.block_cursor) {
4180 GTK_STEXT(text)->cursor_type = STEXT_CURSOR_BLOCK;
4183 if (prefs_common.smart_wrapping) {
4184 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4185 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4188 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4190 gtk_signal_connect(GTK_OBJECT(text), "changed",
4191 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4192 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4193 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4194 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4195 GTK_SIGNAL_FUNC(compose_button_press_cb),
4198 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4199 GTK_SIGNAL_FUNC(compose_key_press_cb),
4202 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4203 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4207 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4209 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4210 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4213 if (prefs_common.enable_pspell) {
4214 gtkpspell = gtkpspell_new_with_config(gtkpspellconfig,
4215 prefs_common.pspell_path,
4216 prefs_common.dictionary,
4218 conv_get_current_charset_str());
4219 if (gtkpspell == NULL)
4220 prefs_common.enable_pspell = FALSE;
4222 gtkpspell_attach(gtkpspell, GTK_STEXT(text));
4225 gtk_widget_show_all(vbox);
4227 /* pane between attach clist and text */
4228 paned = gtk_vpaned_new();
4229 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4230 gtk_paned_add1(GTK_PANED(paned), notebook);
4231 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4232 gtk_widget_show_all(paned);
4234 style = gtk_widget_get_style(text);
4236 /* workaround for the slow down of GtkText when using Pixmap theme */
4237 if (style->engine) {
4238 GtkThemeEngine *engine;
4240 engine = style->engine;
4241 style->engine = NULL;
4242 new_style = gtk_style_copy(style);
4243 style->engine = engine;
4245 new_style = gtk_style_copy(style);
4247 if (prefs_common.textfont) {
4250 charset = conv_get_current_charset();
4251 if (MB_CUR_MAX == 1) {
4254 Xstrdup_a(fontstr, prefs_common.textfont, );
4255 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4257 font = gdk_font_load(fontstr);
4259 font = gdk_fontset_load(prefs_common.textfont);
4261 gdk_font_unref(new_style->font);
4262 new_style->font = font;
4266 gtk_widget_set_style(text, new_style);
4268 color[0] = quote_color;
4269 cmap = gdk_window_get_colormap(window->window);
4270 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4271 if (success[0] == FALSE) {
4272 g_warning("Compose: color allocation failed.\n");
4273 style = gtk_widget_get_style(text);
4274 quote_color = style->black;
4277 n_entries = sizeof(compose_popup_entries) /
4278 sizeof(compose_popup_entries[0]);
4279 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4280 "<Compose>", &popupfactory,
4283 ifactory = gtk_item_factory_from_widget(menubar);
4284 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4285 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4287 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tool/Template");
4288 #if 0 /* NEW COMPOSE GUI */
4289 if (account->protocol == A_NNTP) {
4290 gtk_widget_hide(to_hbox);
4291 gtk_widget_hide(to_entry);
4292 gtk_widget_hide(cc_hbox);
4293 gtk_widget_hide(cc_entry);
4294 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4295 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4297 gtk_widget_hide(newsgroups_hbox);
4298 gtk_widget_hide(newsgroups_entry);
4299 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4301 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
4305 switch (prefs_common.toolbar_style) {
4307 gtk_widget_hide(handlebox);
4310 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4314 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4318 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4323 gtk_widget_show(window);
4325 address_completion_start(window);
4327 compose->window = window;
4328 compose->vbox = vbox;
4329 compose->menubar = menubar;
4330 compose->handlebox = handlebox;
4332 compose->vbox2 = vbox2;
4334 compose->table_vbox = table_vbox;
4336 compose->paned = paned;
4338 compose->edit_vbox = edit_vbox;
4339 compose->ruler_hbox = ruler_hbox;
4340 compose->ruler = ruler;
4341 compose->scrolledwin = scrolledwin;
4342 compose->text = text;
4344 compose->focused_editable = NULL;
4346 compose->popupmenu = popupmenu;
4347 compose->popupfactory = popupfactory;
4349 compose->tmpl_menu = tmpl_menu;
4351 compose->mode = mode;
4353 compose->targetinfo = NULL;
4354 compose->replyinfo = NULL;
4356 compose->replyto = NULL;
4357 compose->mailinglist = NULL;
4359 compose->bcc = NULL;
4360 compose->followup_to = NULL;
4361 compose->inreplyto = NULL;
4362 compose->references = NULL;
4363 compose->msgid = NULL;
4364 compose->boundary = NULL;
4367 compose->use_signing = FALSE;
4368 compose->use_encryption = FALSE;
4369 #endif /* USE_GPGME */
4371 compose->modified = FALSE;
4373 compose->return_receipt = FALSE;
4375 compose->to_list = NULL;
4376 compose->newsgroup_list = NULL;
4378 compose->exteditor_file = NULL;
4379 compose->exteditor_pid = -1;
4380 compose->exteditor_readdes = -1;
4381 compose->exteditor_tag = -1;
4383 compose->bounce_filename = NULL;
4385 compose_set_title(compose);
4387 #if 0 /* NEW COMPOSE GUI */
4388 compose->use_bcc = FALSE;
4389 compose->use_replyto = FALSE;
4390 compose->use_followupto = FALSE;
4394 compose->gtkpspell = gtkpspell;
4397 undostruct = undo_init(text);
4399 compose->undostruct = undostruct;
4400 undo_set_undo_change_funct(undostruct, &compose_set_undo, GTK_WIDGET(compose->menubar));
4402 #if 0 /* NEW COMPOSE GUI */
4403 if (account->protocol != A_NNTP) {
4404 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4405 gtk_check_menu_item_set_active
4406 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4407 gtk_widget_set_sensitive(menuitem, FALSE);
4408 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4409 gtk_check_menu_item_set_active
4410 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4411 gtk_widget_set_sensitive(menuitem, FALSE);
4414 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4415 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4416 #if 0 /* NEW COMPOSE GUI */
4417 compose->use_cc = TRUE;
4418 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4419 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4420 gtk_check_menu_item_set_active
4421 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4424 if (account->set_autobcc) {
4425 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4426 #if 0 /* NEW COMPOSE GUI */
4427 compose->use_bcc = TRUE;
4428 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
4429 gtk_check_menu_item_set_active
4430 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4431 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4432 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4436 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4437 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4438 #if 0 /* NEW COMPOSE GUI */
4439 compose->use_replyto = TRUE;
4440 menuitem = gtk_item_factory_get_item(ifactory,
4441 "/Message/Reply to");
4442 gtk_check_menu_item_set_active
4443 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4444 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4445 account->auto_replyto);
4448 if (account->protocol != A_NNTP) {
4449 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("To:"));
4451 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("Newsgroups:"));
4454 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
4455 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4456 prefs_common.show_ruler);
4459 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4460 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4461 prefs_common.default_sign);
4462 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4463 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4464 prefs_common.default_encrypt);
4465 #endif /* USE_GPGME */
4467 addressbook_set_target_compose(compose);
4468 compose_set_template_menu(compose);
4470 compose_list = g_list_append(compose_list, compose);
4472 #if 0 /* NEW COMPOSE GUI */
4473 compose->use_to = FALSE;
4474 compose->use_cc = FALSE;
4475 compose->use_attach = TRUE;
4478 #if 0 /* NEW COMPOSE GUI */
4479 if (!compose->use_bcc) {
4480 gtk_widget_hide(bcc_hbox);
4481 gtk_widget_hide(bcc_entry);
4482 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4484 if (!compose->use_replyto) {
4485 gtk_widget_hide(reply_hbox);
4486 gtk_widget_hide(reply_entry);
4487 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4489 if (!compose->use_followupto) {
4490 gtk_widget_hide(followup_hbox);
4491 gtk_widget_hide(followup_entry);
4492 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4495 if (!prefs_common.show_ruler)
4496 gtk_widget_hide(ruler_hbox);
4498 select_account(compose, account);
4503 #include "pixmaps/stock_mail_send.xpm"
4504 #include "pixmaps/stock_mail_send_queue.xpm"
4505 #include "pixmaps/stock_mail.xpm"
4506 #include "pixmaps/stock_paste.xpm"
4507 #include "pixmaps/stock_mail_attach.xpm"
4508 #include "pixmaps/stock_mail_compose.xpm"
4509 #include "pixmaps/linewrap.xpm"
4510 #include "pixmaps/tb_address_book.xpm"
4512 #define CREATE_TOOLBAR_ICON(xpm_d) \
4514 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
4515 &container->style->white, \
4517 icon_wid = gtk_pixmap_new(icon, mask); \
4520 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4525 GtkWidget *icon_wid;
4526 GtkWidget *send_btn;
4527 GtkWidget *sendl_btn;
4528 GtkWidget *draft_btn;
4529 GtkWidget *insert_btn;
4530 GtkWidget *attach_btn;
4532 GtkWidget *exteditor_btn;
4533 GtkWidget *linewrap_btn;
4534 GtkWidget *addrbook_btn;
4536 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4538 gtk_container_add(GTK_CONTAINER(container), toolbar);
4539 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4540 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4541 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4542 GTK_TOOLBAR_SPACE_LINE);
4544 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
4545 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4549 icon_wid, toolbar_send_cb, compose);
4551 CREATE_TOOLBAR_ICON(stock_mail_send_queue_xpm);
4552 /* CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm); */
4553 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4555 _("Put into queue folder and send later"),
4557 icon_wid, toolbar_send_later_cb,
4560 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4561 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4563 _("Save to draft folder"),
4565 icon_wid, toolbar_draft_cb,
4568 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4570 CREATE_TOOLBAR_ICON(stock_paste_xpm);
4571 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4575 icon_wid, toolbar_insert_cb,
4578 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
4579 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4583 icon_wid, toolbar_attach_cb,
4586 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4588 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4589 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4591 _("Insert signature"),
4593 icon_wid, toolbar_sig_cb, compose);
4595 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4597 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
4598 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4600 _("Edit with external editor"),
4603 toolbar_ext_editor_cb,
4606 CREATE_TOOLBAR_ICON(linewrap_xpm);
4607 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4609 _("Wrap current paragraph"),
4612 toolbar_linewrap_cb,
4615 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4617 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
4618 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4622 icon_wid, toolbar_address_cb,
4625 compose->toolbar = toolbar;
4626 compose->send_btn = send_btn;
4627 compose->sendl_btn = sendl_btn;
4628 compose->draft_btn = draft_btn;
4629 compose->insert_btn = insert_btn;
4630 compose->attach_btn = attach_btn;
4631 compose->sig_btn = sig_btn;
4632 compose->exteditor_btn = exteditor_btn;
4633 compose->linewrap_btn = linewrap_btn;
4634 compose->addrbook_btn = addrbook_btn;
4636 gtk_widget_show_all(toolbar);
4639 #undef CREATE_TOOLBAR_ICON
4641 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4647 gint num = 0, def_menu = 0;
4649 accounts = account_get_list();
4650 g_return_val_if_fail(accounts != NULL, NULL);
4652 hbox = gtk_hbox_new(FALSE, 0);
4653 optmenu = gtk_option_menu_new();
4654 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4655 menu = gtk_menu_new();
4657 for (; accounts != NULL; accounts = accounts->next, num++) {
4658 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4659 GtkWidget *menuitem;
4662 if (ac == compose->account) def_menu = num;
4664 name = g_strdup_printf("%s: %s <%s>",
4665 ac->account_name, ac->name, ac->address);
4666 MENUITEM_ADD(menu, menuitem, name, ac);
4668 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4669 GTK_SIGNAL_FUNC(account_activated),
4673 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4674 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4679 static void compose_set_template_menu(Compose *compose)
4681 GSList *tmpl_list, *cur;
4685 tmpl_list = template_get_config();
4687 menu = gtk_menu_new();
4689 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4690 Template *tmpl = (Template *)cur->data;
4692 item = gtk_menu_item_new_with_label(tmpl->name);
4693 gtk_menu_append(GTK_MENU(menu), item);
4694 gtk_signal_connect(GTK_OBJECT(item), "activate",
4695 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4697 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4698 gtk_widget_show(item);
4701 gtk_widget_show(menu);
4702 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4705 void compose_reflect_prefs_all(void)
4710 for (cur = compose_list; cur != NULL; cur = cur->next) {
4711 compose = (Compose *)cur->data;
4712 compose_set_template_menu(compose);
4716 static void compose_template_apply(Compose *compose, Template *tmpl)
4721 if (!tmpl || !tmpl->value) return;
4723 gtk_stext_freeze(GTK_STEXT(compose->text));
4726 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
4729 compose_entry_append(compose, tmpl->to, COMPOSE_TO);
4731 if (compose->replyinfo == NULL) {
4734 memset(&dummyinfo, 0, sizeof(MsgInfo));
4735 parsed_str = compose_quote_fmt(compose, &dummyinfo,
4738 if (prefs_common.quotemark && *prefs_common.quotemark)
4739 qmark = prefs_common.quotemark;
4743 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
4744 tmpl->value, qmark);
4747 if (parsed_str && prefs_common.auto_sig)
4748 compose_insert_sig(compose);
4750 gtk_stext_thaw(GTK_STEXT(compose->text));
4753 static void compose_destroy(Compose *compose)
4756 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4759 /* NOTE: address_completion_end() does nothing with the window
4760 * however this may change. */
4761 address_completion_end(compose->window);
4763 slist_free_strings(compose->to_list);
4764 g_slist_free(compose->to_list);
4765 slist_free_strings(compose->newsgroup_list);
4766 g_slist_free(compose->newsgroup_list);
4767 slist_free_strings(compose->header_list);
4768 g_slist_free(compose->header_list);
4770 procmsg_msginfo_free(compose->targetinfo);
4771 procmsg_msginfo_free(compose->replyinfo);
4773 g_free(compose->replyto);
4774 g_free(compose->cc);
4775 g_free(compose->bcc);
4776 g_free(compose->newsgroups);
4777 g_free(compose->followup_to);
4779 g_free(compose->inreplyto);
4780 g_free(compose->references);
4781 g_free(compose->msgid);
4782 g_free(compose->boundary);
4784 if (compose->bounce_filename)
4785 g_free(compose->bounce_filename);
4787 g_free(compose->exteditor_file);
4789 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
4791 compose_attach_info_free(ainfo);
4793 if (addressbook_get_target_compose() == compose)
4794 addressbook_set_target_compose(NULL);
4796 prefs_common.compose_width = compose->scrolledwin->allocation.width;
4797 prefs_common.compose_height = compose->window->allocation.height;
4799 gtk_widget_destroy(compose->paned);
4803 compose_list = g_list_remove(compose_list, compose);
4806 static void compose_attach_info_free(AttachInfo *ainfo)
4808 g_free(ainfo->file);
4809 g_free(ainfo->content_type);
4810 g_free(ainfo->name);
4814 static void compose_attach_remove_selected(Compose *compose)
4816 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4820 while (clist->selection != NULL) {
4821 row = GPOINTER_TO_INT(clist->selection->data);
4822 ainfo = gtk_clist_get_row_data(clist, row);
4823 compose_attach_info_free(ainfo);
4824 gtk_clist_remove(clist, row);
4828 static struct _AttachProperty
4831 GtkWidget *mimetype_entry;
4832 GtkWidget *encoding_optmenu;
4833 GtkWidget *path_entry;
4834 GtkWidget *filename_entry;
4836 GtkWidget *cancel_btn;
4839 static void compose_attach_property(Compose *compose)
4841 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4844 GtkOptionMenu *optmenu;
4845 static gboolean cancelled;
4847 if (!clist->selection) return;
4848 row = GPOINTER_TO_INT(clist->selection->data);
4850 ainfo = gtk_clist_get_row_data(clist, row);
4853 if (!attach_prop.window)
4854 compose_attach_property_create(&cancelled);
4855 gtk_widget_grab_focus(attach_prop.ok_btn);
4856 gtk_widget_show(attach_prop.window);
4857 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
4859 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
4860 if (ainfo->encoding == ENC_UNKNOWN)
4861 gtk_option_menu_set_history(optmenu, ENC_BASE64);
4863 gtk_option_menu_set_history(optmenu, ainfo->encoding);
4865 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
4866 ainfo->content_type ? ainfo->content_type : "");
4867 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
4868 ainfo->file ? ainfo->file : "");
4869 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
4870 ainfo->name ? ainfo->name : "");
4874 gchar *cnttype = NULL;
4878 GtkWidget *menuitem;
4883 if (cancelled == TRUE) {
4884 gtk_widget_hide(attach_prop.window);
4888 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
4889 if (*text != '\0') {
4892 text = g_strstrip(g_strdup(text));
4893 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
4894 cnttype = g_strdup(text);
4897 alertpanel_error(_("Invalid MIME type."));
4903 menu = gtk_option_menu_get_menu(optmenu);
4904 menuitem = gtk_menu_get_active(GTK_MENU(menu));
4905 ainfo->encoding = GPOINTER_TO_INT
4906 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
4908 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
4909 if (*text != '\0') {
4910 if (is_file_exist(text) &&
4911 (size = get_file_size(text)) > 0)
4912 file = g_strdup(text);
4915 (_("File doesn't exist or is empty."));
4921 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
4922 if (*text != '\0') {
4923 g_free(ainfo->name);
4924 ainfo->name = g_strdup(text);
4928 g_free(ainfo->content_type);
4929 ainfo->content_type = cnttype;
4932 g_free(ainfo->file);
4938 gtk_clist_set_text(clist, row, COL_MIMETYPE,
4939 ainfo->content_type);
4940 gtk_clist_set_text(clist, row, COL_SIZE,
4941 to_human_readable(ainfo->size));
4942 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
4944 gtk_widget_hide(attach_prop.window);
4949 #define SET_LABEL_AND_ENTRY(str, entry, top) \
4951 label = gtk_label_new(str); \
4952 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
4953 GTK_FILL, 0, 0, 0); \
4954 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
4956 entry = gtk_entry_new(); \
4957 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
4958 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
4961 static void compose_attach_property_create(gboolean *cancelled)
4967 GtkWidget *mimetype_entry;
4970 GtkWidget *optmenu_menu;
4971 GtkWidget *menuitem;
4972 GtkWidget *path_entry;
4973 GtkWidget *filename_entry;
4976 GtkWidget *cancel_btn;
4977 GList *mime_type_list, *strlist;
4979 debug_print("Creating attach_property window...\n");
4981 window = gtk_window_new(GTK_WINDOW_DIALOG);
4982 gtk_widget_set_usize(window, 480, -1);
4983 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
4984 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
4985 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
4986 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
4987 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4988 GTK_SIGNAL_FUNC(attach_property_delete_event),
4990 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
4991 GTK_SIGNAL_FUNC(attach_property_key_pressed),
4994 vbox = gtk_vbox_new(FALSE, 8);
4995 gtk_container_add(GTK_CONTAINER(window), vbox);
4997 table = gtk_table_new(4, 2, FALSE);
4998 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
4999 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
5000 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
5002 label = gtk_label_new(_("MIME type"));
5003 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
5005 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5006 mimetype_entry = gtk_combo_new();
5007 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
5008 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5010 /* stuff with list */
5011 mime_type_list = procmime_get_mime_type_list();
5013 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5014 MimeType *type = (MimeType *) mime_type_list->data;
5015 strlist = g_list_append(strlist,
5016 g_strdup_printf("%s/%s",
5017 type->type, type->sub_type));
5020 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5022 for (mime_type_list = strlist; mime_type_list != NULL;
5023 mime_type_list = mime_type_list->next)
5024 g_free(mime_type_list->data);
5025 g_list_free(strlist);
5027 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5029 label = gtk_label_new(_("Encoding"));
5030 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5032 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5034 hbox = gtk_hbox_new(FALSE, 0);
5035 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5036 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5038 optmenu = gtk_option_menu_new();
5039 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5041 optmenu_menu = gtk_menu_new();
5042 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5043 gtk_widget_set_sensitive(menuitem, FALSE);
5044 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5045 gtk_widget_set_sensitive(menuitem, FALSE);
5046 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5047 gtk_widget_set_sensitive(menuitem, FALSE);
5048 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5050 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5052 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5053 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5055 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5056 &cancel_btn, _("Cancel"), NULL, NULL);
5057 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5058 gtk_widget_grab_default(ok_btn);
5060 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5061 GTK_SIGNAL_FUNC(attach_property_ok),
5063 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5064 GTK_SIGNAL_FUNC(attach_property_cancel),
5067 gtk_widget_show_all(vbox);
5069 attach_prop.window = window;
5070 attach_prop.mimetype_entry = mimetype_entry;
5071 attach_prop.encoding_optmenu = optmenu;
5072 attach_prop.path_entry = path_entry;
5073 attach_prop.filename_entry = filename_entry;
5074 attach_prop.ok_btn = ok_btn;
5075 attach_prop.cancel_btn = cancel_btn;
5078 #undef SET_LABEL_AND_ENTRY
5080 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5086 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5092 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5093 gboolean *cancelled)
5101 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5102 gboolean *cancelled)
5104 if (event && event->keyval == GDK_Escape) {
5110 static void compose_exec_ext_editor(Compose *compose)
5116 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5117 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5119 if (pipe(pipe_fds) < 0) {
5124 if ((pid = fork()) < 0) {
5130 /* close the write side of the pipe */
5133 compose->exteditor_file = g_strdup(tmp);
5134 compose->exteditor_pid = pid;
5135 compose->exteditor_readdes = pipe_fds[0];
5137 compose_set_ext_editor_sensitive(compose, FALSE);
5139 compose->exteditor_tag =
5140 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5141 compose_input_cb, compose);
5142 } else { /* process-monitoring process */
5148 /* close the read side of the pipe */
5151 if (compose_write_body_to_file(compose, tmp) < 0) {
5152 fd_write(pipe_fds[1], "2\n", 2);
5156 pid_ed = compose_exec_ext_editor_real(tmp);
5158 fd_write(pipe_fds[1], "1\n", 2);
5162 /* wait until editor is terminated */
5163 waitpid(pid_ed, NULL, 0);
5165 fd_write(pipe_fds[1], "0\n", 2);
5172 static gint compose_exec_ext_editor_real(const gchar *file)
5174 static gchar *def_cmd = "emacs %s";
5180 g_return_val_if_fail(file != NULL, -1);
5182 if ((pid = fork()) < 0) {
5187 if (pid != 0) return pid;
5189 /* grandchild process */
5191 if (setpgid(0, getppid()))
5194 if (prefs_common.ext_editor_cmd &&
5195 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5196 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5197 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5199 if (prefs_common.ext_editor_cmd)
5200 g_warning(_("External editor command line is invalid: `%s'\n"),
5201 prefs_common.ext_editor_cmd);
5202 g_snprintf(buf, sizeof(buf), def_cmd, file);
5205 cmdline = g_strsplit(buf, " ", 1024);
5206 execvp(cmdline[0], cmdline);
5209 g_strfreev(cmdline);
5214 static gboolean compose_ext_editor_kill(Compose *compose)
5216 pid_t pgid = compose->exteditor_pid * -1;
5219 ret = kill(pgid, 0);
5221 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5225 msg = g_strdup_printf
5226 (_("The external editor is still working.\n"
5227 "Force terminating the process?\n"
5228 "process group id: %d"), -pgid);
5229 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5232 if (val == G_ALERTDEFAULT) {
5233 gdk_input_remove(compose->exteditor_tag);
5234 close(compose->exteditor_readdes);
5236 if (kill(pgid, SIGTERM) < 0) perror("kill");
5237 waitpid(compose->exteditor_pid, NULL, 0);
5239 g_warning(_("Terminated process group id: %d"), -pgid);
5240 g_warning(_("Temporary file: %s"),
5241 compose->exteditor_file);
5243 compose_set_ext_editor_sensitive(compose, TRUE);
5245 g_free(compose->exteditor_file);
5246 compose->exteditor_file = NULL;
5247 compose->exteditor_pid = -1;
5248 compose->exteditor_readdes = -1;
5249 compose->exteditor_tag = -1;
5257 static void compose_input_cb(gpointer data, gint source,
5258 GdkInputCondition condition)
5261 Compose *compose = (Compose *)data;
5264 debug_print(_("Compose: input from monitoring process\n"));
5266 gdk_input_remove(compose->exteditor_tag);
5269 if (read(source, &buf[i], 1) < 1) {
5273 if (buf[i] == '\n') {
5278 if (i == sizeof(buf) - 1)
5282 waitpid(compose->exteditor_pid, NULL, 0);
5284 if (buf[0] == '0') { /* success */
5285 GtkSText *text = GTK_STEXT(compose->text);
5287 gtk_stext_freeze(text);
5288 gtk_stext_set_point(text, 0);
5289 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5290 compose_insert_file(compose, compose->exteditor_file);
5291 compose_changed_cb(NULL, compose);
5292 gtk_stext_thaw(text);
5294 if (unlink(compose->exteditor_file) < 0)
5295 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5296 } else if (buf[0] == '1') { /* failed */
5297 g_warning(_("Couldn't exec external editor\n"));
5298 if (unlink(compose->exteditor_file) < 0)
5299 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5300 } else if (buf[0] == '2') {
5301 g_warning(_("Couldn't write to file\n"));
5302 } else if (buf[0] == '3') {
5303 g_warning(_("Pipe read failed\n"));
5308 compose_set_ext_editor_sensitive(compose, TRUE);
5310 g_free(compose->exteditor_file);
5311 compose->exteditor_file = NULL;
5312 compose->exteditor_pid = -1;
5313 compose->exteditor_readdes = -1;
5314 compose->exteditor_tag = -1;
5317 static void compose_set_ext_editor_sensitive(Compose *compose,
5320 GtkItemFactory *ifactory;
5322 ifactory = gtk_item_factory_from_widget(compose->menubar);
5324 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5325 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5326 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5328 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5329 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5330 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5331 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5332 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5335 gtk_widget_set_sensitive(compose->text, sensitive);
5336 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5337 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5338 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5339 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5340 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5341 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5342 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5345 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5349 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5350 cursor_pos = MAX(cursor_pos, 0);
5355 /* callback functions */
5357 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5358 * includes "non-client" (windows-izm) in calculation, so this calculation
5359 * may not be accurate.
5361 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5362 GtkAllocation *allocation,
5363 GtkSHRuler *shruler)
5365 if (prefs_common.show_ruler) {
5367 gint line_width_in_chars;
5369 char_width = gtkut_get_font_width
5370 (GTK_WIDGET(widget)->style->font);
5371 line_width_in_chars =
5372 (allocation->width - allocation->x) / char_width;
5374 /* got the maximum */
5375 gtk_ruler_set_range(GTK_RULER(shruler),
5376 0.0, line_width_in_chars,
5377 calc_cursor_xpos(GTK_STEXT(widget),
5380 /*line_width_in_chars*/ char_width);
5386 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5388 compose_send_cb(data, 0, NULL);
5391 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5393 compose_send_later_cb(data, 0, NULL);
5396 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5398 compose_draft_cb(data, 0, NULL);
5401 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5403 compose_insert_file_cb(data, 0, NULL);
5406 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5408 compose_attach_cb(data, 0, NULL);
5411 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5413 Compose *compose = (Compose *)data;
5415 compose_insert_sig(compose);
5418 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5420 Compose *compose = (Compose *)data;
5422 compose_exec_ext_editor(compose);
5425 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5427 Compose *compose = (Compose *)data;
5429 compose_wrap_line(compose);
5432 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5434 compose_address_cb(data, 0, NULL);
5437 static void select_account(Compose * compose, PrefsAccount * ac)
5439 compose->account = ac;
5440 compose_set_title(compose);
5442 #if 0 /* NEW COMPOSE GUI */
5443 if (ac->protocol == A_NNTP) {
5444 GtkItemFactory *ifactory;
5445 GtkWidget *menuitem;
5447 ifactory = gtk_item_factory_from_widget(compose->menubar);
5448 menu_set_sensitive(ifactory,
5449 "/Message/Followup to", TRUE);
5450 gtk_widget_show(compose->newsgroups_hbox);
5451 gtk_widget_show(compose->newsgroups_entry);
5452 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5455 compose->use_to = FALSE;
5456 compose->use_cc = FALSE;
5458 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5459 gtk_check_menu_item_set_active
5460 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5462 menu_set_sensitive(ifactory,
5463 "/Message/To", TRUE);
5464 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5465 gtk_check_menu_item_set_active
5466 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5468 gtk_widget_hide(compose->to_hbox);
5469 gtk_widget_hide(compose->to_entry);
5470 gtk_widget_hide(compose->cc_hbox);
5471 gtk_widget_hide(compose->cc_entry);
5472 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5474 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5478 GtkItemFactory *ifactory;
5479 GtkWidget *menuitem;
5481 ifactory = gtk_item_factory_from_widget(compose->menubar);
5482 menu_set_sensitive(ifactory,
5483 "/Message/Followup to", FALSE);
5484 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5485 gtk_widget_hide(compose->newsgroups_hbox);
5486 gtk_widget_hide(compose->newsgroups_entry);
5487 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5490 compose->use_to = TRUE;
5491 compose->use_cc = TRUE;
5493 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5494 gtk_check_menu_item_set_active
5495 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5496 menu_set_sensitive(ifactory,
5497 "/Message/To", FALSE);
5498 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5499 gtk_check_menu_item_set_active
5500 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5501 gtk_widget_show(compose->to_hbox);
5502 gtk_widget_show(compose->to_entry);
5503 gtk_widget_show(compose->cc_hbox);
5504 gtk_widget_show(compose->cc_entry);
5506 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5508 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5511 gtk_widget_queue_resize(compose->table_vbox);
5515 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5517 Compose *compose = (Compose *)data;
5521 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5522 g_return_if_fail(ac != NULL);
5524 if (ac != compose->account)
5525 select_account(compose, ac);
5528 static void attach_selected(GtkCList *clist, gint row, gint column,
5529 GdkEvent *event, gpointer data)
5531 Compose *compose = (Compose *)data;
5533 if (event && event->type == GDK_2BUTTON_PRESS)
5534 compose_attach_property(compose);
5537 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5540 Compose *compose = (Compose *)data;
5541 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5546 if (event->button == 3) {
5547 if ((clist->selection && !clist->selection->next) ||
5548 !clist->selection) {
5549 gtk_clist_unselect_all(clist);
5550 if (gtk_clist_get_selection_info(clist,
5553 gtk_clist_select_row(clist, row, column);
5554 gtkut_clist_set_focus_row(clist, row);
5557 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5558 NULL, NULL, event->button, event->time);
5562 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5565 Compose *compose = (Compose *)data;
5569 switch (event->keyval) {
5571 compose_attach_remove_selected(compose);
5576 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5578 Compose *compose = (Compose *)data;
5581 val = compose_send(compose);
5582 if (val == 0) gtk_widget_destroy(compose->window);
5585 static void compose_send_later_cb(gpointer data, guint action,
5588 Compose *compose = (Compose *)data;
5591 val = compose_queue(compose, NULL, NULL);
5592 if (!val) gtk_widget_destroy(compose->window);
5595 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5597 Compose *compose = (Compose *)data;
5601 draft = folder_get_default_draft();
5603 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5604 G_DIR_SEPARATOR, (gint)compose);
5606 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5611 folder_item_scan(draft);
5612 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
5619 if (compose->mode == COMPOSE_REEDIT) {
5620 compose_remove_reedit_target(compose);
5621 if (compose->targetinfo &&
5622 compose->targetinfo->folder != draft)
5623 folderview_update_item(compose->targetinfo->folder,
5627 folder_item_scan(draft);
5628 folderview_update_item(draft, TRUE);
5630 gtk_widget_destroy(compose->window);
5633 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
5635 Compose *compose = (Compose *)data;
5638 if (compose->bounce_filename != NULL)
5641 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5646 for ( tmp = file_list; tmp; tmp = tmp->next) {
5647 gchar *file = (gchar *) tmp->data;
5648 compose_attach_append(compose, file, MIME_UNKNOWN);
5651 g_list_free(file_list);
5655 static void compose_insert_file_cb(gpointer data, guint action,
5658 Compose *compose = (Compose *)data;
5661 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5666 for ( tmp = file_list; tmp; tmp = tmp->next) {
5667 gchar *file = (gchar *) tmp->data;
5668 compose_insert_file(compose, file);
5671 g_list_free(file_list);
5675 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
5678 compose_close_cb(data, 0, NULL);
5682 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
5684 Compose *compose = (Compose *)data;
5687 if (compose->exteditor_tag != -1) {
5688 if (!compose_ext_editor_kill(compose))
5692 if (compose->modified) {
5693 val = alertpanel(_("Discard message"),
5694 _("This message has been modified. discard it?"),
5695 _("Discard"), _("to Draft"), _("Cancel"));
5698 case G_ALERTDEFAULT:
5700 case G_ALERTALTERNATE:
5701 compose_draft_cb(data, 0, NULL);
5708 if (compose->gtkpspell) {
5709 gtkpspell_detach(compose->gtkpspell);
5710 compose->gtkpspell = gtkpspell_delete(compose->gtkpspell);
5713 gtk_widget_destroy(compose->window);
5716 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
5718 Compose *compose = (Compose *)data;
5720 addressbook_open(compose);
5723 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
5725 Compose *compose = (Compose *)data;
5728 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
5729 g_return_if_fail(tmpl != NULL);
5731 compose_template_apply(compose, tmpl);
5734 static void compose_ext_editor_cb(gpointer data, guint action,
5737 Compose *compose = (Compose *)data;
5739 compose_exec_ext_editor(compose);
5742 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
5744 compose_destroy(compose);
5747 static void compose_undo_cb(Compose *compose)
5749 undo_undo(compose->undostruct);
5752 static void compose_redo_cb(Compose *compose)
5754 undo_redo(compose->undostruct);
5757 static void compose_cut_cb(Compose *compose)
5759 if (compose->focused_editable &&
5760 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5761 gtk_editable_cut_clipboard
5762 (GTK_EDITABLE(compose->focused_editable));
5765 static void compose_copy_cb(Compose *compose)
5767 if (compose->focused_editable &&
5768 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5769 gtk_editable_copy_clipboard
5770 (GTK_EDITABLE(compose->focused_editable));
5773 static void compose_paste_cb(Compose *compose)
5775 if (compose->focused_editable &&
5776 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5777 gtk_editable_paste_clipboard
5778 (GTK_EDITABLE(compose->focused_editable));
5781 static void compose_allsel_cb(Compose *compose)
5783 if (compose->focused_editable &&
5784 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5785 gtk_editable_select_region
5786 (GTK_EDITABLE(compose->focused_editable), 0, -1);
5789 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
5791 if (GTK_IS_EDITABLE(widget))
5792 compose->focused_editable = widget;
5795 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
5797 if (compose->modified == FALSE) {
5798 compose->modified = TRUE;
5799 compose_set_title(compose);
5803 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
5806 gtk_stext_set_point(GTK_STEXT(widget),
5807 gtk_editable_get_position(GTK_EDITABLE(widget)));
5811 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
5814 gtk_stext_set_point(GTK_STEXT(widget),
5815 gtk_editable_get_position(GTK_EDITABLE(widget)));
5819 #if 0 /* NEW COMPOSE GUI */
5820 static void compose_toggle_to_cb(gpointer data, guint action,
5823 Compose *compose = (Compose *)data;
5825 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5826 gtk_widget_show(compose->to_hbox);
5827 gtk_widget_show(compose->to_entry);
5828 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
5829 compose->use_to = TRUE;
5831 gtk_widget_hide(compose->to_hbox);
5832 gtk_widget_hide(compose->to_entry);
5833 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
5834 gtk_widget_queue_resize(compose->table_vbox);
5835 compose->use_to = FALSE;
5838 if (addressbook_get_target_compose() == compose)
5839 addressbook_set_target_compose(compose);
5842 static void compose_toggle_cc_cb(gpointer data, guint action,
5845 Compose *compose = (Compose *)data;
5847 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5848 gtk_widget_show(compose->cc_hbox);
5849 gtk_widget_show(compose->cc_entry);
5850 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
5851 compose->use_cc = TRUE;
5853 gtk_widget_hide(compose->cc_hbox);
5854 gtk_widget_hide(compose->cc_entry);
5855 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
5856 gtk_widget_queue_resize(compose->table_vbox);
5857 compose->use_cc = FALSE;
5860 if (addressbook_get_target_compose() == compose)
5861 addressbook_set_target_compose(compose);
5864 static void compose_toggle_bcc_cb(gpointer data, guint action,
5867 Compose *compose = (Compose *)data;
5869 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5870 gtk_widget_show(compose->bcc_hbox);
5871 gtk_widget_show(compose->bcc_entry);
5872 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
5873 compose->use_bcc = TRUE;
5875 gtk_widget_hide(compose->bcc_hbox);
5876 gtk_widget_hide(compose->bcc_entry);
5877 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
5878 gtk_widget_queue_resize(compose->table_vbox);
5879 compose->use_bcc = FALSE;
5882 if (addressbook_get_target_compose() == compose)
5883 addressbook_set_target_compose(compose);
5886 static void compose_toggle_replyto_cb(gpointer data, guint action,
5889 Compose *compose = (Compose *)data;
5891 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5892 gtk_widget_show(compose->reply_hbox);
5893 gtk_widget_show(compose->reply_entry);
5894 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
5895 compose->use_replyto = TRUE;
5897 gtk_widget_hide(compose->reply_hbox);
5898 gtk_widget_hide(compose->reply_entry);
5899 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
5900 gtk_widget_queue_resize(compose->table_vbox);
5901 compose->use_replyto = FALSE;
5905 static void compose_toggle_followupto_cb(gpointer data, guint action,
5908 Compose *compose = (Compose *)data;
5910 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5911 gtk_widget_show(compose->followup_hbox);
5912 gtk_widget_show(compose->followup_entry);
5913 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
5914 compose->use_followupto = TRUE;
5916 gtk_widget_hide(compose->followup_hbox);
5917 gtk_widget_hide(compose->followup_entry);
5918 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
5919 gtk_widget_queue_resize(compose->table_vbox);
5920 compose->use_followupto = FALSE;
5924 static void compose_toggle_attach_cb(gpointer data, guint action,
5927 Compose *compose = (Compose *)data;
5929 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5930 gtk_widget_ref(compose->edit_vbox);
5932 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5933 compose->edit_vbox);
5934 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
5935 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
5937 gtk_widget_show(compose->paned);
5939 gtk_widget_unref(compose->edit_vbox);
5940 gtk_widget_unref(compose->paned);
5942 compose->use_attach = TRUE;
5944 gtk_widget_ref(compose->paned);
5945 gtk_widget_ref(compose->edit_vbox);
5947 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5949 gtk_container_remove(GTK_CONTAINER(compose->paned),
5950 compose->edit_vbox);
5951 gtk_box_pack_start(GTK_BOX(compose->vbox2),
5952 compose->edit_vbox, TRUE, TRUE, 0);
5954 gtk_widget_unref(compose->edit_vbox);
5956 compose->use_attach = FALSE;
5962 static void compose_toggle_sign_cb(gpointer data, guint action,
5965 Compose *compose = (Compose *)data;
5967 if (GTK_CHECK_MENU_ITEM(widget)->active)
5968 compose->use_signing = TRUE;
5970 compose->use_signing = FALSE;
5973 static void compose_toggle_encrypt_cb(gpointer data, guint action,
5976 Compose *compose = (Compose *)data;
5978 if (GTK_CHECK_MENU_ITEM(widget)->active)
5979 compose->use_encryption = TRUE;
5981 compose->use_encryption = FALSE;
5983 #endif /* USE_GPGME */
5985 static void compose_toggle_ruler_cb(gpointer data, guint action,
5988 Compose *compose = (Compose *)data;
5990 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5991 gtk_widget_show(compose->ruler_hbox);
5992 prefs_common.show_ruler = TRUE;
5994 gtk_widget_hide(compose->ruler_hbox);
5995 gtk_widget_queue_resize(compose->edit_vbox);
5996 prefs_common.show_ruler = FALSE;
6000 static void compose_attach_drag_received_cb (GtkWidget *widget,
6001 GdkDragContext *drag_context,
6004 GtkSelectionData *data,
6009 Compose *compose = (Compose *)user_data;
6012 list = uri_list_extract_filenames((const gchar *)data->data);
6013 for (tmp = list; tmp != NULL; tmp = tmp->next)
6014 compose_attach_append(compose, (const gchar *)tmp->data,
6016 list_free_strings(list);
6020 static void compose_insert_drag_received_cb (GtkWidget *widget,
6021 GdkDragContext *drag_context,
6024 GtkSelectionData *data,
6029 Compose *compose = (Compose *)user_data;
6032 list = uri_list_extract_filenames((const gchar *)data->data);
6033 for (tmp = list; tmp != NULL; tmp = tmp->next)
6034 compose_insert_file(compose, (const gchar *)tmp->data);
6035 list_free_strings(list);
6039 #if 0 /* NEW COMPOSE GUI */
6040 static void to_activated(GtkWidget *widget, Compose *compose)
6042 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6043 gtk_widget_grab_focus(compose->newsgroups_entry);
6045 gtk_widget_grab_focus(compose->subject_entry);
6048 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6050 gtk_widget_grab_focus(compose->subject_entry);
6053 static void subject_activated(GtkWidget *widget, Compose *compose)
6055 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6056 gtk_widget_grab_focus(compose->cc_entry);
6057 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6058 gtk_widget_grab_focus(compose->bcc_entry);
6059 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6060 gtk_widget_grab_focus(compose->reply_entry);
6061 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6062 gtk_widget_grab_focus(compose->followup_entry);
6064 gtk_widget_grab_focus(compose->text);
6067 static void cc_activated(GtkWidget *widget, Compose *compose)
6069 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6070 gtk_widget_grab_focus(compose->bcc_entry);
6071 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6072 gtk_widget_grab_focus(compose->reply_entry);
6073 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6074 gtk_widget_grab_focus(compose->followup_entry);
6076 gtk_widget_grab_focus(compose->text);
6079 static void bcc_activated(GtkWidget *widget, Compose *compose)
6081 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6082 gtk_widget_grab_focus(compose->reply_entry);
6083 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6084 gtk_widget_grab_focus(compose->followup_entry);
6086 gtk_widget_grab_focus(compose->text);
6089 static void replyto_activated(GtkWidget *widget, Compose *compose)
6091 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6092 gtk_widget_grab_focus(compose->followup_entry);
6094 gtk_widget_grab_focus(compose->text);
6097 static void followupto_activated(GtkWidget *widget, Compose *compose)
6099 gtk_widget_grab_focus(compose->text);
6103 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6106 Compose *compose = (Compose *)data;
6108 if (GTK_CHECK_MENU_ITEM(widget)->active)
6109 compose->return_receipt = TRUE;
6111 compose->return_receipt = FALSE;
6114 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6116 ComposeHeaderEntry *headerentry)
6118 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6119 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6120 !(event->state & GDK_MODIFIER_MASK) &&
6121 (event->keyval == GDK_BackSpace) &&
6122 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6123 gtk_container_remove
6124 (GTK_CONTAINER(headerentry->compose->header_table),
6125 headerentry->combo);
6126 gtk_container_remove
6127 (GTK_CONTAINER(headerentry->compose->header_table),
6128 headerentry->entry);
6129 headerentry->compose->header_list =
6130 g_slist_remove(headerentry->compose->header_list,
6132 g_free(headerentry);
6136 void compose_headerentry_changed_cb(GtkWidget *entry,
6137 ComposeHeaderEntry *headerentry)
6139 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6140 headerentry->compose->header_list =
6141 g_slist_append(headerentry->compose->header_list,
6143 compose_create_header_entry(headerentry->compose);
6144 gtk_signal_disconnect_by_func
6146 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6154 * Change the sensivity of the menuentries undo and redo
6156 static void compose_set_undo(UndoMain *undostruct, gint undo_state,
6157 gint redo_state, GtkWidget *changewidget)
6159 GtkItemFactory *ifactory;
6160 debug_print ("Set_undo. UNDO:%i REDO:%i\n",
6164 g_return_if_fail (changewidget != NULL);
6166 ifactory = gtk_item_factory_from_widget(changewidget);
6169 switch (undo_state) {
6170 case UNDO_STATE_TRUE:
6171 if (!undostruct->undo_state) {
6172 debug_print ("Set_undo - Testpoint\n");
6173 undostruct->undo_state = TRUE;
6174 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6177 case UNDO_STATE_FALSE:
6178 if (undostruct->undo_state) {
6179 undostruct->undo_state = FALSE;
6180 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6183 case UNDO_STATE_UNCHANGED:
6185 case UNDO_STATE_REFRESH:
6186 menu_set_sensitive(ifactory, "/Edit/Undo", undostruct->undo_state);
6189 g_warning ("Undo state not recognized");
6194 switch (redo_state) {
6195 case UNDO_STATE_TRUE:
6196 if (!undostruct->redo_state) {
6197 undostruct->redo_state = TRUE;
6198 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6201 case UNDO_STATE_FALSE:
6202 if (undostruct->redo_state) {
6203 undostruct->redo_state = FALSE;
6204 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6207 case UNDO_STATE_UNCHANGED:
6209 case UNDO_STATE_REFRESH:
6210 menu_set_sensitive(ifactory, "/Edit/Redo", undostruct->redo_state);
6213 g_warning ("Redo state not recognized");