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"
106 # include "rfc2015.h"
116 #define N_ATTACH_COLS 3
118 #define B64_LINE_SIZE 57
119 #define B64_BUFFSIZE 77
121 #define MAX_REFERENCES_LEN 999
123 static GdkColor quote_color = {0, 0, 0, 0xbfff};
125 static GList *compose_list = NULL;
127 static void compose_set_undo (UndoMain *undostruct,
130 GtkWidget *changewidget);
131 Compose *compose_generic_new (PrefsAccount *account,
135 static Compose *compose_create (PrefsAccount *account,
137 static void compose_toolbar_create (Compose *compose,
138 GtkWidget *container);
139 static GtkWidget *compose_account_option_menu_create
141 static void compose_set_template_menu (Compose *compose);
142 static void compose_template_apply (Compose *compose,
144 static void compose_destroy (Compose *compose);
146 static void compose_entries_set (Compose *compose,
147 const gchar *mailto);
148 static gint compose_parse_header (Compose *compose,
150 static gchar *compose_parse_references (const gchar *ref,
153 static gchar *compose_quote_fmt (Compose *compose,
158 static void compose_reply_set_entry (Compose *compose,
163 followup_and_reply_to);
164 static void compose_reedit_set_entry (Compose *compose,
166 static void compose_insert_sig (Compose *compose);
167 static void compose_insert_file (Compose *compose,
169 static void compose_attach_append (Compose *compose,
171 ContentType cnttype);
172 static void compose_attach_append_with_type(Compose *compose,
175 ContentType cnttype);
176 static void compose_wrap_line (Compose *compose);
177 static void compose_wrap_line_all (Compose *compose);
178 static void compose_set_title (Compose *compose);
180 static PrefsAccount *compose_current_mail_account(void);
181 /* static gint compose_send (Compose *compose); */
182 static gint compose_write_to_file (Compose *compose,
185 static gint compose_write_body_to_file (Compose *compose,
187 static gint compose_save_to_outbox (Compose *compose,
189 static gint compose_remove_reedit_target (Compose *compose);
190 static gint compose_queue (Compose *compose,
193 static void compose_write_attach (Compose *compose,
195 static gint compose_write_headers (Compose *compose,
197 const gchar *charset,
198 EncodingType encoding,
201 static void compose_convert_header (gchar *dest,
205 static void compose_generate_msgid (Compose *compose,
209 static void compose_attach_info_free (AttachInfo *ainfo);
210 static void compose_attach_remove_selected (Compose *compose);
212 static void compose_attach_property (Compose *compose);
213 static void compose_attach_property_create (gboolean *cancelled);
214 static void attach_property_ok (GtkWidget *widget,
215 gboolean *cancelled);
216 static void attach_property_cancel (GtkWidget *widget,
217 gboolean *cancelled);
218 static gint attach_property_delete_event (GtkWidget *widget,
220 gboolean *cancelled);
221 static void attach_property_key_pressed (GtkWidget *widget,
223 gboolean *cancelled);
225 static void compose_exec_ext_editor (Compose *compose);
226 static gint compose_exec_ext_editor_real (const gchar *file);
227 static gboolean compose_ext_editor_kill (Compose *compose);
228 static void compose_input_cb (gpointer data,
230 GdkInputCondition condition);
231 static void compose_set_ext_editor_sensitive (Compose *compose,
234 static gint calc_cursor_xpos (GtkSText *text,
238 static void compose_create_header_entry (Compose *compose);
239 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
241 /* callback functions */
243 static gboolean compose_edit_size_alloc (GtkEditable *widget,
244 GtkAllocation *allocation,
245 GtkSHRuler *shruler);
247 static void toolbar_send_cb (GtkWidget *widget,
249 static void toolbar_send_later_cb (GtkWidget *widget,
251 static void toolbar_draft_cb (GtkWidget *widget,
253 static void toolbar_insert_cb (GtkWidget *widget,
255 static void toolbar_attach_cb (GtkWidget *widget,
257 static void toolbar_sig_cb (GtkWidget *widget,
259 static void toolbar_ext_editor_cb (GtkWidget *widget,
261 static void toolbar_linewrap_cb (GtkWidget *widget,
263 static void toolbar_address_cb (GtkWidget *widget,
266 static void select_account (Compose *compose,
269 static void account_activated (GtkMenuItem *menuitem,
272 static void attach_selected (GtkCList *clist,
277 static void attach_button_pressed (GtkWidget *widget,
278 GdkEventButton *event,
280 static void attach_key_pressed (GtkWidget *widget,
284 static void compose_send_cb (gpointer data,
287 static void compose_send_later_cb (gpointer data,
291 static void compose_draft_cb (gpointer data,
295 static void compose_attach_cb (gpointer data,
298 static void compose_insert_file_cb (gpointer data,
302 static void compose_close_cb (gpointer data,
306 static void compose_address_cb (gpointer data,
309 static void compose_template_activate_cb(GtkWidget *widget,
312 static void compose_ext_editor_cb (gpointer data,
316 static gint compose_delete_cb (GtkWidget *widget,
319 static void compose_destroy_cb (GtkWidget *widget,
322 static void compose_undo_cb (Compose *compose);
323 static void compose_redo_cb (Compose *compose);
324 static void compose_cut_cb (Compose *compose);
325 static void compose_copy_cb (Compose *compose);
326 static void compose_paste_cb (Compose *compose);
327 static void compose_allsel_cb (Compose *compose);
329 static void compose_grab_focus_cb (GtkWidget *widget,
332 static void compose_changed_cb (GtkEditable *editable,
334 static void compose_button_press_cb (GtkWidget *widget,
335 GdkEventButton *event,
338 static void compose_key_press_cb (GtkWidget *widget,
344 static void compose_toggle_to_cb (gpointer data,
347 static void compose_toggle_cc_cb (gpointer data,
350 static void compose_toggle_bcc_cb (gpointer data,
353 static void compose_toggle_replyto_cb (gpointer data,
356 static void compose_toggle_followupto_cb(gpointer data,
359 static void compose_toggle_attach_cb (gpointer data,
363 static void compose_toggle_ruler_cb (gpointer data,
367 static void compose_toggle_sign_cb (gpointer data,
370 static void compose_toggle_encrypt_cb (gpointer data,
374 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
377 static void compose_attach_drag_received_cb (GtkWidget *widget,
378 GdkDragContext *drag_context,
381 GtkSelectionData *data,
385 static void compose_insert_drag_received_cb (GtkWidget *widget,
386 GdkDragContext *drag_context,
389 GtkSelectionData *data,
395 static void to_activated (GtkWidget *widget,
397 static void newsgroups_activated (GtkWidget *widget,
399 static void subject_activated (GtkWidget *widget,
401 static void cc_activated (GtkWidget *widget,
403 static void bcc_activated (GtkWidget *widget,
405 static void replyto_activated (GtkWidget *widget,
407 static void followupto_activated (GtkWidget *widget,
411 static void compose_attach_parts (Compose *compose,
414 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
416 gboolean ignore_replyto,
417 gboolean followup_and_reply_to);
419 void compose_headerentry_changed_cb (GtkWidget *entry,
420 ComposeHeaderEntry *headerentry);
421 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
423 ComposeHeaderEntry *headerentry);
425 static GtkItemFactoryEntry compose_popup_entries[] =
427 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
428 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
429 {N_("/---"), NULL, NULL, 0, "<Separator>"},
430 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
433 static GtkItemFactoryEntry compose_entries[] =
435 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
436 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
437 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
438 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
439 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
440 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
442 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
443 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
444 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
445 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
446 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
447 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
448 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
449 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
450 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
451 {N_("/_Edit/_Wrap current paragraph"), "<alt>L", compose_wrap_line, 0, NULL},
452 {N_("/_Edit/Wrap all long _lines"),
453 "<shift><alt>L", compose_wrap_line_all, 0, NULL},
454 {N_("/_Edit/Edit with e_xternal editor"),
455 "<alt>X", compose_ext_editor_cb, 0, NULL},
457 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
458 {N_("/_Message/_Send"), "<control>Return",
459 compose_send_cb, 0, NULL},
460 {N_("/_Message/Send _later"), "<shift><alt>S",
461 compose_send_later_cb, 0, NULL},
462 {N_("/_Message/Save to _draft folder"),
463 "<alt>D", compose_draft_cb, 0, NULL},
464 #if 0 /* NEW COMPOSE GUI */
465 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
466 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
467 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
468 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
469 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
470 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
471 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
472 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
473 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
476 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
477 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
478 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
479 #endif /* USE_GPGME */
480 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
481 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
482 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
483 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
484 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb , 0, NULL},
485 {N_("/_Tool/_Template"), NULL, NULL, 0, "<Branch>"},
486 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
487 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
490 static GtkTargetEntry compose_mime_types[] =
492 {"text/uri-list", 0, 0}
495 Compose *compose_new(PrefsAccount *account)
497 return compose_generic_new(account, NULL, NULL);
500 Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
504 GtkItemFactory *ifactory;
506 c = compose_generic_new(account, NULL, NULL);
508 filename = procmsg_get_message_file(msginfo);
509 if (filename == NULL)
512 c->bounce_filename = filename;
514 if (msginfo->subject)
515 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
517 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
519 compose_quote_fmt(c, msginfo, "%M", NULL);
520 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
522 ifactory = gtk_item_factory_from_widget(c->popupmenu);
523 menu_set_sensitive(ifactory, "/Add...", FALSE);
524 menu_set_sensitive(ifactory, "/Remove", FALSE);
525 menu_set_sensitive(ifactory, "/Property...", FALSE);
527 ifactory = gtk_item_factory_from_widget(c->menubar);
528 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
529 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
530 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
531 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
532 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
533 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
534 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
535 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
537 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
538 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
540 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
541 menu_set_sensitive(ifactory, "/Tool/Template", FALSE);
543 gtk_widget_set_sensitive(c->insert_btn, FALSE);
544 gtk_widget_set_sensitive(c->attach_btn, FALSE);
545 gtk_widget_set_sensitive(c->sig_btn, FALSE);
546 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
547 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
552 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
554 return compose_generic_new(account, mailto, NULL);
557 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
559 return compose_generic_new(account, NULL, item);
562 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
566 if (item && item->prefs && item->prefs->enable_default_account)
567 account = account_find_from_id(item->prefs->default_account);
569 if (!account) account = cur_account;
570 g_return_val_if_fail(account != NULL, NULL);
572 compose = compose_create(account, COMPOSE_NEW);
573 compose->replyinfo = NULL;
575 if (prefs_common.auto_sig)
576 compose_insert_sig(compose);
577 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
578 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
580 if (account->protocol != A_NNTP) {
582 compose_entries_set(compose, mailto);
584 } else if(item && item->prefs->enable_default_to) {
585 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
587 if (item && item->ret_rcpt) {
588 GtkItemFactory *ifactory;
590 ifactory = gtk_item_factory_from_widget(compose->menubar);
591 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
595 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
598 gtk_widget_grab_focus(compose->subject_entry);
600 if (prefs_common.auto_exteditor)
601 compose_exec_ext_editor(compose);
606 #define CHANGE_FLAGS(msginfo) \
608 if (msginfo->folder->folder->change_flags != NULL) \
609 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
615 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
616 const gchar *followupto, gchar * to)
620 if (!account) account = cur_account;
621 g_return_val_if_fail(account != NULL, NULL);
622 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
624 compose = compose_create(account, COMPOSE_NEW);
626 if (prefs_common.auto_sig)
627 compose_insert_sig(compose);
628 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
629 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
631 compose_entry_append(compose, to, COMPOSE_TO);
632 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
633 gtk_widget_grab_focus(compose->subject_entry);
639 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
640 gboolean ignore_replyto)
642 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
645 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
647 gboolean ignore_replyto)
649 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
652 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
654 gboolean ignore_replyto,
655 gboolean followup_and_reply_to)
658 PrefsAccount *account;
659 PrefsAccount *reply_account;
662 g_return_if_fail(msginfo != NULL);
663 g_return_if_fail(msginfo->folder != NULL);
666 /* select the account set in folderitem's property (if enabled) */
667 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
668 account = account_find_from_id(msginfo->folder->prefs->default_account);
670 /* select the account for the whole folder (IMAP / NNTP) */
672 account = msginfo->folder->folder->account;
674 /* select account by to: and cc: header if enabled */
675 if (prefs_common.reply_account_autosel) {
676 if (!account && msginfo->to) {
678 Xstrdup_a(to, msginfo->to, return);
680 account = account_find_from_address(to);
684 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
686 account = account_find_from_address(cc);
691 /* select current account */
692 if (!account) account = cur_account;
693 g_return_if_fail(account != NULL);
695 if (ignore_replyto && account->protocol == A_NNTP &&
696 !followup_and_reply_to) {
698 account_find_from_address(account->address);
700 reply_account = compose_current_mail_account();
704 reply_account = account;
706 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
707 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
709 CHANGE_FLAGS(msginfo);
711 compose = compose_create(account, COMPOSE_REPLY);
712 compose->replyinfo = procmsg_msginfo_copy(msginfo);
714 #if 0 /* NEW COMPOSE GUI */
715 if (followup_and_reply_to) {
716 gtk_widget_show(compose->to_hbox);
717 gtk_widget_show(compose->to_entry);
718 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
719 compose->use_to = TRUE;
722 if (msginfo->folder && msginfo->folder->ret_rcpt) {
723 GtkItemFactory *ifactory;
725 ifactory = gtk_item_factory_from_widget(compose->menubar);
726 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
729 if (compose_parse_header(compose, msginfo) < 0) return;
730 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
731 followup_and_reply_to);
733 text = GTK_STEXT(compose->text);
734 gtk_stext_freeze(text);
740 if (prefs_common.quotemark && *prefs_common.quotemark)
741 qmark = prefs_common.quotemark;
745 quote_str = compose_quote_fmt(compose, msginfo,
746 prefs_common.quotefmt,
750 if (prefs_common.auto_sig)
751 compose_insert_sig(compose);
752 gtk_editable_set_position(GTK_EDITABLE(text), 0);
753 gtk_stext_set_point(text, 0);
755 if (quote && prefs_common.linewrap_quote)
756 compose_wrap_line_all(compose);
758 gtk_stext_thaw(text);
759 gtk_widget_grab_focus(compose->text);
761 if (prefs_common.auto_exteditor)
762 compose_exec_ext_editor(compose);
766 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
771 g_return_val_if_fail(mimeinfo != NULL, NULL);
773 base = mimeinfo->filename ? mimeinfo->filename
774 : mimeinfo->name ? mimeinfo->name : NULL;
776 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
777 filename = g_strdup_printf("%s%smimetmp.%08x.html",
784 base = base ? base : "";
785 base = g_basename(base);
787 filename = g_strdup_printf("%s%smimetmp.%08x",
795 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
801 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
805 if (!partinfo) return NULL;
807 filename = procmime_get_file_name(partinfo);
809 if (procmime_get_part(filename, source, partinfo) < 0)
811 (_("Can't get the part of multipart message."));
816 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
824 gint boundary_len = 0;
826 glong fpos, prev_fpos;
831 g_return_if_fail(msginfo != NULL);
835 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
836 mimeinfo = procmime_scan_mime_header(fp);
837 if (!mimeinfo) break;
839 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
840 rfc2015_is_encrypted(mimeinfo)) {
841 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
843 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
844 !msginfo->plaintext_file &&
845 !msginfo->decryption_failed) {
846 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
847 if (msginfo->plaintext_file &&
848 !msginfo->decryption_failed) {
856 #else /* !USE_GPGME */
857 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
858 mimeinfo = procmime_scan_mime_header(fp);
859 #endif /* USE_GPGME */
862 if (!mimeinfo) return;
863 if (mimeinfo->mime_type == MIME_TEXT)
866 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
868 g_return_if_fail(mimeinfo != NULL);
869 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
871 if (mimeinfo->mime_type == MIME_MULTIPART) {
872 g_return_if_fail(mimeinfo->boundary != NULL);
873 g_return_if_fail(mimeinfo->sub == NULL);
875 g_return_if_fail(fp != NULL);
877 boundary = mimeinfo->boundary;
880 boundary_len = strlen(boundary);
882 /* look for first boundary */
883 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
884 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
891 if ((fpos = ftell(fp)) < 0) {
897 for (npart = 0;; npart++) {
899 gboolean eom = FALSE;
903 partinfo = procmime_scan_mime_header(fp);
904 if (!partinfo) break;
907 procmime_mimeinfo_insert(mimeinfo, partinfo);
909 procmime_mimeinfo_free(partinfo);
911 /* look for next boundary */
913 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
914 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
915 if (buf[2 + boundary_len] == '-' &&
916 buf[2 + boundary_len + 1] == '-')
922 eom = TRUE; /* broken MIME message */
925 partinfo->size = fpos - prev_fpos - strlen(buf);
930 source = procmsg_get_message_file_path(msginfo);
932 g_return_if_fail(mimeinfo != NULL);
934 if (!mimeinfo->main && mimeinfo->parent)
936 filename = mime_extract_file(source, mimeinfo);
938 compose_attach_append_with_type(compose, filename,
939 mimeinfo->content_type,
940 mimeinfo->mime_type);
945 if (mimeinfo->sub && mimeinfo->sub->children)
947 filename = mime_extract_file(source, mimeinfo->sub);
949 compose_attach_append_with_type(compose, filename,
950 mimeinfo->content_type,
951 mimeinfo->sub->mime_type);
956 if (mimeinfo->children) {
959 child = mimeinfo->children;
961 filename = mime_extract_file(source, child);
963 compose_attach_append_with_type(compose, filename,
975 procmime_mimeinfo_free_all(mimeinfo);
979 #define INSERT_FW_HEADER(var, hdr) \
980 if (msginfo->var && *msginfo->var) { \
981 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
982 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
983 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
986 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
990 /* PrefsAccount *account; */
993 g_return_val_if_fail(msginfo != NULL, NULL);
994 g_return_val_if_fail(msginfo->folder != NULL, NULL);
996 account = msginfo->folder->folder->account;
997 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
999 Xstrdup_a(to, msginfo->to, return NULL);
1000 extract_address(to);
1001 account = account_find_from_address(to);
1004 if(!account && prefs_common.forward_account_autosel) {
1006 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1007 extract_address(cc);
1008 account = account_find_from_address(cc);
1012 if (account == NULL) {
1013 account = cur_account;
1015 account = msginfo->folder->folder->account;
1016 if (!account) account = cur_account;
1019 g_return_val_if_fail(account != NULL, NULL);
1021 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1022 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1023 CHANGE_FLAGS(msginfo);
1025 compose = compose_create(account, COMPOSE_FORWARD);
1027 if (msginfo->subject && *msginfo->subject) {
1028 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1029 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1033 text = GTK_STEXT(compose->text);
1034 gtk_stext_freeze(text);
1039 msgfile = procmsg_get_message_file_path(msginfo);
1040 if (!is_file_exist(msgfile))
1041 g_warning(_("%s: file not exist\n"), msgfile);
1043 compose_attach_append(compose, msgfile,
1044 MIME_MESSAGE_RFC822);
1051 if (prefs_common.fw_quotemark && *prefs_common.fw_quotemark)
1052 qmark = prefs_common.fw_quotemark;
1056 quote_str = compose_quote_fmt(compose, msginfo,
1057 prefs_common.fw_quotefmt, qmark);
1058 compose_attach_parts(compose, msginfo);
1061 if (prefs_common.auto_sig)
1062 compose_insert_sig(compose);
1064 if (prefs_common.linewrap_quote)
1065 compose_wrap_line_all(compose);
1067 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1068 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1070 gtk_stext_thaw(text);
1071 #if 0 /* NEW COMPOSE GUI */
1072 if (account->protocol != A_NNTP)
1073 gtk_widget_grab_focus(compose->to_entry);
1075 gtk_widget_grab_focus(compose->newsgroups_entry);
1077 gtk_widget_grab_focus(compose->header_last->entry);
1079 if (prefs_common.auto_exteditor)
1080 compose_exec_ext_editor(compose);
1085 #undef INSERT_FW_HEADER
1087 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1094 g_return_val_if_fail(msginfo_list != NULL, NULL);
1096 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1097 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1101 if (account == NULL) {
1102 account = cur_account;
1104 account = msginfo->folder->folder->account;
1105 if (!account) account = cur_account;
1108 g_return_val_if_fail(account != NULL, NULL);
1110 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1111 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1112 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1113 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1116 compose = compose_create(account, COMPOSE_FORWARD);
1118 text = GTK_STEXT(compose->text);
1119 gtk_stext_freeze(text);
1121 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1122 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1123 if (!is_file_exist(msgfile))
1124 g_warning(_("%s: file not exist\n"), msgfile);
1126 compose_attach_append(compose, msgfile,
1127 MIME_MESSAGE_RFC822);
1131 if (prefs_common.auto_sig)
1132 compose_insert_sig(compose);
1134 if (prefs_common.linewrap_quote)
1135 compose_wrap_line_all(compose);
1137 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1138 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1140 gtk_stext_thaw(text);
1141 #if 0 /* NEW COMPOSE GUI */
1142 if (account->protocol != A_NNTP)
1143 gtk_widget_grab_focus(compose->to_entry);
1145 gtk_widget_grab_focus(compose->newsgroups_entry);
1151 void compose_reedit(MsgInfo *msginfo)
1154 PrefsAccount *account;
1157 gchar buf[BUFFSIZE];
1159 g_return_if_fail(msginfo != NULL);
1160 g_return_if_fail(msginfo->folder != NULL);
1162 account = msginfo->folder->folder->account;
1164 if(!account&& prefs_common.reedit_account_autosel) {
1165 gchar from[BUFFSIZE];
1166 if(!get_header_from_msginfo(msginfo,from,sizeof(from),"FROM:")){ /* Found a FROM header */
1167 extract_address(from);
1168 account = account_find_from_address(from);
1171 if (!account) account = cur_account;
1172 g_return_if_fail(account != NULL);
1174 compose = compose_create(account, COMPOSE_REEDIT);
1175 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1177 if (compose_parse_header(compose, msginfo) < 0) return;
1178 compose_reedit_set_entry(compose, msginfo);
1180 text = GTK_STEXT(compose->text);
1181 gtk_stext_freeze(text);
1183 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1184 g_warning(_("Can't get text part\n"));
1186 while (fgets(buf, sizeof(buf), fp) != NULL)
1187 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1190 compose_attach_parts(compose, msginfo);
1192 gtk_stext_thaw(text);
1193 gtk_widget_grab_focus(compose->text);
1195 if (prefs_common.auto_exteditor)
1196 compose_exec_ext_editor(compose);
1199 GList *compose_get_compose_list(void)
1201 return compose_list;
1204 void compose_entry_append(Compose *compose, const gchar *address,
1205 ComposeEntryType type)
1211 if (!address || *address == '\0') return;
1213 #if 0 /* NEW COMPOSE GUI */
1216 entry = GTK_ENTRY(compose->cc_entry);
1219 entry = GTK_ENTRY(compose->bcc_entry);
1221 case COMPOSE_NEWSGROUPS:
1222 entry = GTK_ENTRY(compose->newsgroups_entry);
1226 entry = GTK_ENTRY(compose->to_entry);
1230 text = gtk_entry_get_text(entry);
1232 gtk_entry_append_text(entry, ", ");
1233 gtk_entry_append_text(entry, address);
1241 header = N_("Bcc:");
1243 case COMPOSE_REPLYTO:
1244 header = N_("Reply-To:");
1246 case COMPOSE_NEWSGROUPS:
1247 header = N_("Newsgroups:");
1249 case COMPOSE_FOLLOWUPTO:
1250 header = N_( "Followup-To:");
1257 header = prefs_common.trans_hdr ? gettext(header) : header;
1259 compose_add_header_entry(compose, header, (gchar *)address);
1262 static void compose_entries_set(Compose *compose, const gchar *mailto)
1264 gchar *subject = NULL;
1272 Xstrdup_a(tmp_mailto, mailto, return);
1276 p = strchr(tmp_mailto, '?');
1283 gchar *field, *value;
1300 if (*value == '\0') continue;
1302 if (!g_strcasecmp(field, "subject")) {
1303 Xalloca(subject, strlen(value) + 1, return);
1304 decode_uri(subject, value);
1305 } else if (!g_strcasecmp(field, "cc")) {
1307 } else if (!g_strcasecmp(field, "bcc")) {
1309 } else if (!g_strcasecmp(field, "body")) {
1310 Xalloca(body, strlen(value) + 1, return);
1311 decode_uri(body, value);
1316 compose_entry_append(compose, to, COMPOSE_TO);
1318 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1320 compose_entry_append(compose, cc, COMPOSE_CC);
1322 compose_entry_append(compose, bcc, COMPOSE_BCC);
1324 gtk_stext_insert(GTK_STEXT(compose->text),
1325 NULL, NULL, NULL, body, -1);
1326 gtk_stext_insert(GTK_STEXT(compose->text),
1327 NULL, NULL, NULL, "\n", 1);
1331 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1333 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1334 {"Cc:", NULL, FALSE},
1335 {"References:", NULL, FALSE},
1336 {"Bcc:", NULL, FALSE},
1337 {"Newsgroups:", NULL, FALSE},
1338 {"Followup-To:", NULL, FALSE},
1339 {"X-Mailing-List:", NULL, FALSE},
1340 {"X-BeenThere:", NULL, FALSE},
1341 {NULL, NULL, FALSE}};
1351 H_X_MAILING_LIST = 6,
1357 g_return_val_if_fail(msginfo != NULL, -1);
1359 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1360 procheader_get_header_fields(fp, hentry);
1363 if (hentry[H_REPLY_TO].body != NULL) {
1364 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1365 compose->replyto = hentry[H_REPLY_TO].body;
1366 hentry[H_REPLY_TO].body = NULL;
1368 if (hentry[H_CC].body != NULL) {
1369 conv_unmime_header_overwrite(hentry[H_CC].body);
1370 compose->cc = hentry[H_CC].body;
1371 hentry[H_CC].body = NULL;
1373 if (hentry[H_X_MAILING_LIST].body != NULL) {
1374 /* this is good enough to parse debian-devel */
1375 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1376 g_return_val_if_fail(buf != NULL, -1 );
1377 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1378 compose->mailinglist = g_strdup(buf);
1380 g_free(hentry[H_X_MAILING_LIST].body);
1381 hentry[H_X_MAILING_LIST].body = NULL ;
1383 if (hentry[H_X_BEENTHERE].body != NULL) {
1384 /* this is good enough to parse the sylpheed-claws lists */
1385 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1386 g_return_val_if_fail(buf != NULL, -1 );
1387 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1388 compose->mailinglist = g_strdup(buf);
1390 g_free(hentry[H_X_BEENTHERE].body);
1391 hentry[H_X_BEENTHERE].body = NULL ;
1393 if (hentry[H_REFERENCES].body != NULL) {
1394 if (compose->mode == COMPOSE_REEDIT)
1395 compose->references = hentry[H_REFERENCES].body;
1397 compose->references = compose_parse_references
1398 (hentry[H_REFERENCES].body, msginfo->msgid);
1399 g_free(hentry[H_REFERENCES].body);
1401 hentry[H_REFERENCES].body = NULL;
1403 if (hentry[H_BCC].body != NULL) {
1404 if (compose->mode == COMPOSE_REEDIT) {
1405 conv_unmime_header_overwrite(hentry[H_BCC].body);
1406 compose->bcc = hentry[H_BCC].body;
1408 g_free(hentry[H_BCC].body);
1409 hentry[H_BCC].body = NULL;
1411 if (hentry[H_NEWSGROUPS].body != NULL) {
1412 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1413 hentry[H_NEWSGROUPS].body = NULL;
1415 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1416 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1417 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1418 hentry[H_FOLLOWUP_TO].body = NULL;
1421 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1422 compose->inreplyto = g_strdup(msginfo->inreplyto);
1423 else if (compose->mode != COMPOSE_REEDIT &&
1424 msginfo->msgid && *msginfo->msgid) {
1425 compose->inreplyto = g_strdup(msginfo->msgid);
1427 if (!compose->references) {
1428 if (msginfo->inreplyto && *msginfo->inreplyto)
1429 compose->references =
1430 g_strdup_printf("<%s>\n\t<%s>",
1434 compose->references =
1435 g_strconcat("<", msginfo->msgid, ">",
1443 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1445 GSList *ref_id_list, *cur;
1449 ref_id_list = references_list_append(NULL, ref);
1450 if (!ref_id_list) return NULL;
1451 if (msgid && *msgid)
1452 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1457 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1458 /* "<" + Message-ID + ">" + CR+LF+TAB */
1459 len += strlen((gchar *)cur->data) + 5;
1461 if (len > MAX_REFERENCES_LEN) {
1462 /* remove second message-ID */
1463 if (ref_id_list && ref_id_list->next &&
1464 ref_id_list->next->next) {
1465 g_free(ref_id_list->next->data);
1466 ref_id_list = g_slist_remove
1467 (ref_id_list, ref_id_list->next->data);
1469 slist_free_strings(ref_id_list);
1470 g_slist_free(ref_id_list);
1477 new_ref = g_string_new("");
1478 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1479 if (new_ref->len > 0)
1480 g_string_append(new_ref, "\n\t");
1481 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1484 slist_free_strings(ref_id_list);
1485 g_slist_free(ref_id_list);
1487 new_ref_str = new_ref->str;
1488 g_string_free(new_ref, FALSE);
1493 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1494 const gchar *fmt, const gchar *qmark)
1496 GtkSText *text = GTK_STEXT(compose->text);
1497 gchar *quote_str = NULL;
1502 if (qmark != NULL) {
1503 quote_fmt_init(msginfo, NULL);
1504 quote_fmt_scan_string(qmark);
1507 buf = quote_fmt_get_buffer();
1509 alertpanel_error(_("Quote mark format error."));
1511 Xstrdup_a(quote_str, buf, return NULL)
1514 quote_fmt_init(msginfo, quote_str);
1515 quote_fmt_scan_string(fmt);
1518 buf = quote_fmt_get_buffer();
1520 alertpanel_error(_("Message reply/forward format error."));
1524 gtk_stext_freeze(text);
1525 gtk_stext_set_point(text, 0);
1526 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
1528 for (p = buf; *p != '\0'; ) {
1529 lastp = strchr(p, '\n');
1530 len = lastp ? lastp - p + 1 : -1;
1531 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1538 gtk_stext_thaw(text);
1543 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1544 gboolean to_all, gboolean ignore_replyto,
1545 gboolean followup_and_reply_to)
1550 GHashTable *to_table;
1552 g_return_if_fail(compose->account != NULL);
1553 g_return_if_fail(msginfo != NULL);
1555 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1556 compose_entry_append(compose,
1557 ((compose->mailinglist && !ignore_replyto)
1558 ? compose->mailinglist
1559 : (compose->replyto && !ignore_replyto)
1561 : msginfo->from ? msginfo->from : ""),
1563 if (compose->account->protocol == A_NNTP) {
1565 compose_entry_append
1566 (compose, msginfo->from ? msginfo->from : "",
1569 compose_entry_append
1571 compose->followup_to ? compose->followup_to
1572 : compose->newsgroups ? compose->newsgroups
1574 COMPOSE_NEWSGROUPS);
1577 if (msginfo->subject && *msginfo->subject) {
1578 gchar *buf, *buf2, *p;
1580 buf = g_strdup(msginfo->subject);
1581 while (!strncasecmp(buf, "Re:", 3)) {
1583 while (isspace(*p)) p++;
1584 memmove(buf, p, strlen(p) + 1);
1587 buf2 = g_strdup_printf("Re: %s", buf);
1588 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1592 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1594 if (!to_all || compose->account->protocol == A_NNTP) return;
1596 from = g_strdup(compose->replyto ? compose->replyto :
1597 msginfo->from ? msginfo->from : "");
1598 extract_address(from);
1600 cc_list = address_list_append(NULL, msginfo->to);
1601 cc_list = address_list_append(cc_list, compose->cc);
1603 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1604 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1605 if (compose->account)
1606 g_hash_table_insert(to_table, compose->account->address,
1607 GINT_TO_POINTER(1));
1609 /* remove address on To: and that of current account */
1610 for (cur = cc_list; cur != NULL; ) {
1611 GSList *next = cur->next;
1613 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1614 cc_list = g_slist_remove(cc_list, cur->data);
1616 g_hash_table_insert(to_table, cur->data, cur);
1620 g_hash_table_destroy(to_table);
1624 for (cur = cc_list; cur != NULL; cur = cur->next)
1625 compose_entry_append(compose, (gchar *)cur->data,
1627 slist_free_strings(cc_list);
1628 g_slist_free(cc_list);
1632 #define SET_ENTRY(entry, str) \
1635 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1638 #define SET_ADDRESS(type, str) \
1641 compose_entry_append(compose, str, type); \
1644 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1646 g_return_if_fail(msginfo != NULL);
1648 SET_ENTRY(subject_entry, msginfo->subject);
1649 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1650 SET_ADDRESS(COMPOSE_CC, compose->cc);
1651 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1652 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1654 #if 0 /* NEW COMPOSE GUI */
1656 GtkItemFactory *ifactory;
1657 GtkWidget *menuitem;
1659 ifactory = gtk_item_factory_from_widget(compose->menubar);
1660 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1661 gtk_check_menu_item_set_active
1662 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1664 if (compose->replyto) {
1665 GtkItemFactory *ifactory;
1666 GtkWidget *menuitem;
1668 ifactory = gtk_item_factory_from_widget(compose->menubar);
1669 menuitem = gtk_item_factory_get_item
1670 (ifactory, "/Message/Reply to");
1671 gtk_check_menu_item_set_active
1672 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1680 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1687 size_t buf_len = 128;
1689 if (strlen(sigfile) < 2)
1692 sigprg = popen(sigfile+1, "r");
1695 buf = g_malloc(buf_len);
1698 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1699 "Unable to insert signature (malloc failed)\n", -1);
1705 while (!feof(sigprg)) {
1706 bzero(buf, buf_len);
1707 fread(buf, buf_len-1, 1, sigprg);
1708 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1716 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1717 "Can't exec file: ", -1);
1718 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1723 static void compose_insert_sig(Compose *compose)
1727 if (compose->account && compose->account->sig_path)
1728 sigfile = g_strdup(compose->account->sig_path);
1730 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1731 DEFAULT_SIGNATURE, NULL);
1734 if (!is_file_or_fifo_exist(sigfile) & (sigfile[0] != '|')) {
1739 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1740 if (prefs_common.sig_sep) {
1741 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1742 prefs_common.sig_sep, -1);
1743 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1747 if (sigfile[0] == '|')
1749 compose_exec_sig(compose, sigfile);
1753 compose_insert_file(compose, sigfile);
1758 static void compose_insert_file(Compose *compose, const gchar *file)
1760 GtkSText *text = GTK_STEXT(compose->text);
1761 gchar buf[BUFFSIZE];
1765 g_return_if_fail(file != NULL);
1767 if ((fp = fopen(file, "r")) == NULL) {
1768 FILE_OP_ERROR(file, "fopen");
1772 gtk_stext_freeze(text);
1774 while (fgets(buf, sizeof(buf), fp) != NULL) {
1775 /* Strip <CR> if DOS/Windoze file, replace <CR> with <LF> if MAC file */
1777 if (len > 1 && buf[len - 2] == '\r' && buf[len - 1] == '\n') {
1778 buf[len - 2] = '\n';
1779 buf[len - 1] = '\0';
1782 if (buf[len] == '\r')
1786 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1789 gtk_stext_thaw(text);
1794 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1795 ContentType cnttype)
1797 gchar *text[N_ATTACH_COLS];
1800 text[COL_MIMETYPE] = ainfo->content_type;
1801 text[COL_SIZE] = to_human_readable(ainfo->size);
1802 text[COL_NAME] = ainfo->name;
1804 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1805 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1807 if (cnttype != MIME_MESSAGE_RFC822)
1808 compose_changed_cb(NULL, compose);
1811 static void compose_attach_append_with_type(Compose *compose,
1814 ContentType cnttype)
1819 if (!is_file_exist(file)) {
1820 g_warning(_("File %s doesn't exist\n"), file);
1823 if ((size = get_file_size(file)) < 0) {
1824 g_warning(_("Can't get file size of %s\n"), file);
1828 alertpanel_notice(_("File %s is empty\n"), file);
1831 #if 0 /* NEW COMPOSE GUI */
1832 if (!compose->use_attach) {
1833 GtkItemFactory *ifactory;
1834 GtkWidget *menuitem;
1836 ifactory = gtk_item_factory_from_widget(compose->menubar);
1837 menuitem = gtk_item_factory_get_item(ifactory,
1839 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1843 ainfo = g_new0(AttachInfo, 1);
1844 ainfo->file = g_strdup(file);
1846 if (cnttype == MIME_MESSAGE_RFC822) {
1847 ainfo->encoding = ENC_7BIT;
1848 ainfo->name = g_strdup_printf(_("Message: %s"),
1851 ainfo->encoding = ENC_BASE64;
1852 ainfo->name = g_strdup(g_basename(file));
1855 ainfo->content_type = g_strdup(type);
1858 compose_attach_info(compose, ainfo, cnttype);
1861 static void compose_attach_append(Compose *compose, const gchar *file,
1862 ContentType cnttype)
1865 gchar *text[N_ATTACH_COLS];
1869 if (!is_file_exist(file)) {
1870 g_warning(_("File %s doesn't exist\n"), file);
1873 if ((size = get_file_size(file)) < 0) {
1874 g_warning(_("Can't get file size of %s\n"), file);
1878 alertpanel_notice(_("File %s is empty\n"), file);
1881 #if 0 /* NEW COMPOSE GUI */
1882 if (!compose->use_attach) {
1883 GtkItemFactory *ifactory;
1884 GtkWidget *menuitem;
1886 ifactory = gtk_item_factory_from_widget(compose->menubar);
1887 menuitem = gtk_item_factory_get_item(ifactory,
1889 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1893 ainfo = g_new0(AttachInfo, 1);
1894 ainfo->file = g_strdup(file);
1896 if (cnttype == MIME_MESSAGE_RFC822) {
1897 ainfo->content_type = g_strdup("message/rfc822");
1898 ainfo->encoding = ENC_7BIT;
1899 ainfo->name = g_strdup_printf(_("Message: %s"),
1902 ainfo->content_type = procmime_get_mime_type(file);
1903 if (!ainfo->content_type)
1904 ainfo->content_type =
1905 g_strdup("application/octet-stream");
1906 ainfo->encoding = ENC_BASE64;
1907 ainfo->name = g_strdup(g_basename(file));
1911 compose_attach_info(compose, ainfo, cnttype);
1914 static void compose_wrap_line(Compose *compose)
1916 GtkSText *text = GTK_STEXT(compose->text);
1917 gint ch_len, last_ch_len;
1918 gchar cbuf[MB_LEN_MAX], last_ch;
1922 gint p_start, p_end;
1923 gint line_pos, cur_pos;
1924 gint line_len, cur_len;
1926 #define GET_STEXT(pos) \
1927 if (text->use_wchar) \
1928 ch_len = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
1930 cbuf[0] = GTK_STEXT_INDEX(text, (pos)); \
1934 gtk_stext_freeze(text);
1936 text_len = gtk_stext_get_length(text);
1938 /* check to see if the point is on the paragraph mark (empty line). */
1939 cur_pos = gtk_stext_get_point(text);
1941 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
1943 goto compose_end; /* on the paragraph mark */
1944 GET_STEXT(cur_pos - 1);
1945 if (ch_len == 1 && *cbuf == '\n')
1946 goto compose_end; /* on the paragraph mark */
1949 /* find paragraph start. */
1950 line_end = quoted = 0;
1951 for (p_start = cur_pos; p_start >= 0; --p_start) {
1953 if (ch_len == 1 && *cbuf == '\n') {
1955 goto compose_end; /* quoted part */
1962 if (ch_len == 1 && strchr(">:#", *cbuf))
1964 else if (ch_len != 1 || !isspace(*cbuf))
1973 /* find paragraph end. */
1975 for (p_end = cur_pos; p_end < text_len; p_end++) {
1977 if (ch_len == 1 && *cbuf == '\n') {
1984 if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
1985 goto compose_end; /* quoted part */
1990 if (p_end >= text_len)
1993 if (p_start >= p_end)
1996 line_len = cur_len = 0;
2000 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2010 if (ch_len == 1 && isspace(*cbuf))
2013 if (ch_len == 1 && *cbuf == '\n') {
2015 if (last_ch_len == 1 && !isspace(last_ch)) {
2016 if (cur_pos + 1 < p_end) {
2017 GET_STEXT(cur_pos + 1);
2018 if (ch_len == 1 && !isspace(*cbuf))
2022 gtk_stext_set_point(text, cur_pos + 1);
2023 gtk_stext_backward_delete(text, 1);
2025 gtk_stext_set_point(text, cur_pos);
2026 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2036 last_ch_len = ch_len;
2040 line_pos = cur_pos + 1;
2041 line_len = cur_len + ch_len;
2044 if (cur_len + ch_len > prefs_common.linewrap_len &&
2048 GET_STEXT(line_pos - 1);
2049 if (ch_len == 1 && isspace(*cbuf)) {
2050 gtk_stext_set_point(text, line_pos);
2051 gtk_stext_backward_delete(text, 1);
2060 gtk_stext_set_point(text, line_pos);
2061 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2065 cur_len = cur_len - line_len + ch_len;
2071 line_pos = cur_pos + 1;
2072 line_len = cur_len + ch_len;
2078 gtk_stext_thaw(text);
2083 /* return indent length */
2084 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2086 gint indent_len = 0;
2088 gchar cbuf[MB_LEN_MAX];
2090 for (i = start_pos; i < text_len; i++) {
2091 if (text->use_wchar)
2093 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, i));
2095 cbuf[0] = GTK_STEXT_INDEX(text, i);
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;
2126 gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
2127 ins_len = quote_len;
2135 /* Darko: used when I debug wrapping */
2136 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2141 printf("%d [", pos);
2142 for (i = pos; i < tlen; i++) {
2143 ch = GTK_STEXT_INDEX(text, i);
2144 if (breakoncr && ch == '\n')
2152 static void compose_wrap_line_all(Compose *compose)
2154 GtkSText *text = GTK_STEXT(compose->text);
2156 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2157 gint line_len = 0, cur_len = 0;
2159 gint is_new_line = 1, do_delete = 0;
2160 guint qlen = 0, i_len = 0;
2161 guint linewrap_quote = prefs_common.linewrap_quote;
2162 guint linewrap_len = prefs_common.linewrap_len;
2163 gchar *qfmt = prefs_common.quotemark;
2164 gchar cbuf[MB_LEN_MAX];
2166 gtk_stext_freeze(text);
2168 /* make text buffer contiguous */
2169 /* gtk_stext_compact_buffer(text); */
2171 tlen = gtk_stext_get_length(text);
2173 for (; cur_pos < tlen; cur_pos++) {
2174 /* mark position of new line - needed for quotation wrap */
2175 if (linewrap_quote && is_new_line) {
2176 qlen = gtkut_text_str_compare
2177 (text, cur_pos, tlen, qfmt);
2180 i_len = get_indent_length(text, cur_pos, tlen);
2185 printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
2186 dump_text(text, p_pos, tlen, 1);
2190 /* get character(s) at current position */
2191 if (text->use_wchar)
2193 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2195 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
2199 /* fix line length for tabs */
2200 if (ch_len == 1 && *cbuf == '\t') {
2201 guint tab_width = text->default_tab_width;
2202 guint tab_offset = line_len % tab_width;
2205 printf("found tab at pos=%d line_len=%d ", cur_pos,
2209 line_len += tab_width - tab_offset - 1;
2213 printf("new_len=%d\n", line_len);
2217 /* we have encountered line break */
2218 if (ch_len == 1 && *cbuf == '\n') {
2221 gchar cb[MB_CUR_MAX];
2224 printf("found CR at %d next line is ", cur_pos);
2225 dump_text(text, cur_pos + 1, tlen, 1);
2227 /* if it's just quotation + newline skip it */
2228 if (i_len && (cur_pos + 1 < tlen)) {
2229 /* check if text at new line matches indent */
2230 ilen = gtkut_text_str_compare_n
2231 (text, cur_pos + 1, p_pos, i_len, tlen);
2232 if (cur_pos + ilen < tlen) {
2233 if (text->use_wchar)
2234 clen = wctomb(cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos + ilen + 1));
2236 cb[0] = GTK_STEXT_INDEX(text,
2237 cur_pos + ilen + 1);
2240 /* no need to join the lines */
2241 if ((clen == 1) && (cb[0] == '\n'))
2245 /* if it's just newline skip it */
2246 else if (do_delete && (cur_pos + 1 < tlen)) {
2247 if (text->use_wchar)
2248 clen = wctomb(cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos + 1));
2250 cb[0] = GTK_STEXT_INDEX(text,
2254 /* no need to join the lines */
2255 if ((clen == 1) && (cb[0] == '\n'))
2260 printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
2261 qlen, line_len, linewrap_len, do_delete);
2263 /* should we delete to perform smart wrapping */
2264 if (line_len < linewrap_len && do_delete) {
2265 /* get rid of newline */
2266 gtk_stext_set_point(text, cur_pos);
2267 gtk_stext_forward_delete(text, 1);
2270 /* if text starts with quote fmt or with
2271 indent string, delete them */
2273 ilen = gtkut_text_str_compare_n
2274 (text, cur_pos, p_pos, i_len,
2277 gtk_stext_forward_delete(text,
2282 if (gtkut_text_str_compare
2283 (text, cur_pos, tlen, qfmt)) {
2284 gtk_stext_forward_delete
2290 if (text->use_wchar)
2292 (cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2294 cb[0] = GTK_STEXT_INDEX(text, cur_pos);
2298 /* insert space if it's alphanumeric */
2299 if ((cur_pos != line_pos) &&
2300 ((clen > 1) || isalnum(cb[0]))) {
2301 gtk_stext_insert(text, NULL, NULL,
2303 /* gtk_text_compact_buffer(text); */
2307 /* and start over with current line */
2308 cur_pos = p_pos - 1;
2310 line_len = cur_len = 0;
2315 printf("after delete l_pos=");
2316 dump_text(text, line_pos, tlen, 1);
2321 /* mark new line beginning */
2322 line_pos = cur_pos + 1;
2323 line_len = cur_len = 0;
2335 /* possible line break */
2336 if (ch_len == 1 && isspace(*cbuf)) {
2337 line_pos = cur_pos + 1;
2338 line_len = cur_len + ch_len;
2341 /* are we over wrapping length set in preferences ? */
2342 if (cur_len + ch_len > linewrap_len) {
2346 printf("should wrap cur_pos=%d ", cur_pos);
2347 dump_text(text, p_pos, tlen, 1);
2348 dump_text(text, line_pos, tlen, 1);
2350 /* force wrapping if it is one long word but not URL */
2351 if (p_pos + i_len == line_pos)
2352 if (!gtkut_text_is_uri_string
2353 (text, line_pos, tlen))
2354 line_pos = cur_pos - 1;
2356 printf("new line_pos=%d\n", line_pos);
2359 /* if next character is space delete it */
2360 if (text->use_wchar)
2361 clen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
2363 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
2366 if (clen == 1 && isspace(*cbuf)) {
2367 if (p_pos + i_len != line_pos ||
2368 !gtkut_text_is_uri_string
2369 (text, line_pos, tlen)) {
2370 gtk_stext_set_point(text, line_pos);
2371 gtk_stext_backward_delete(text, 1);
2380 /* if it is URL at beginning of line don't wrap */
2381 if (p_pos + i_len == line_pos &&
2382 gtkut_text_is_uri_string(text, line_pos, tlen)) {
2384 printf("found URL at ");
2385 dump_text(text, line_pos, tlen, 1);
2391 gtk_stext_set_point(text, line_pos);
2392 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2393 /* gtk_stext_compact_buffer(text); */
2396 /* for loop will increase it */
2397 cur_pos = line_pos - 1;
2398 /* start over with current line */
2404 printf("after CR insert ");
2405 dump_text(text, line_pos, tlen, 1);
2406 dump_text(text, cur_pos, tlen, 1);
2409 /* should we insert quotation ? */
2410 if (linewrap_quote && qlen) {
2411 /* only if line is not already quoted */
2412 if (!gtkut_text_str_compare
2413 (text, line_pos, tlen, qfmt)) {
2416 if (line_pos - p_pos > i_len) {
2421 /* gtk_stext_compact_buffer(text); */
2425 printf("after quote insert ");
2426 dump_text(text, line_pos, tlen, 1);
2434 line_pos = cur_pos + 1;
2435 line_len = cur_len + ch_len;
2437 /* advance to next character in buffer */
2441 gtk_stext_thaw(text);
2445 static void compose_wrap_line_all(Compose *compose)
2447 GtkText *text = GTK_STEXT(compose->text);
2449 guint line_pos = 0, cur_pos = 0;
2450 gint line_len = 0, cur_len = 0;
2452 gchar cbuf[MB_LEN_MAX];
2454 gtk_stext_freeze(text);
2456 text_len = gtk_stext_get_length(text);
2458 for (; cur_pos < text_len; cur_pos++) {
2459 if (text->use_wchar)
2461 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2463 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
2467 if (ch_len == 1 && *cbuf == '\n') {
2468 line_pos = cur_pos + 1;
2469 line_len = cur_len = 0;
2478 if (ch_len == 1 && isspace(*cbuf)) {
2479 line_pos = cur_pos + 1;
2480 line_len = cur_len + ch_len;
2483 if (cur_len + ch_len > prefs_common.linewrap_len &&
2487 if (text->use_wchar)
2488 tlen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
2490 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
2493 if (tlen == 1 && isspace(*cbuf)) {
2494 gtk_stext_set_point(text, line_pos);
2495 gtk_stext_backward_delete(text, 1);
2503 gtk_stext_set_point(text, line_pos);
2504 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2508 cur_len = cur_len - line_len + ch_len;
2514 line_pos = cur_pos + 1;
2515 line_len = cur_len + ch_len;
2520 gtk_stext_thaw(text);
2524 static void compose_set_title(Compose *compose)
2529 edited = compose->modified ? _(" [Edited]") : "";
2530 if (compose->account && compose->account->address)
2531 str = g_strdup_printf(_("%s - Compose message%s"),
2532 compose->account->address, edited);
2534 str = g_strdup_printf(_("Compose message%s"), edited);
2535 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2540 * compose_current_mail_account:
2542 * Find a current mail account (the currently selected account, or the
2543 * default account, if a news account is currently selected). If a
2544 * mail account cannot be found, display an error message.
2546 * Return value: Mail account, or NULL if not found.
2548 static PrefsAccount *
2549 compose_current_mail_account(void)
2553 if (cur_account && cur_account->protocol != A_NNTP)
2556 ac = account_get_default();
2557 if (!ac || ac->protocol == A_NNTP) {
2558 alertpanel_error(_("Account for sending mail is not specified.\n"
2559 "Please select a mail account before sending."));
2566 gboolean compose_check_for_valid_recipient(Compose *compose) {
2567 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2568 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2569 gboolean recipient_found = FALSE;
2573 /* free to and newsgroup list */
2574 slist_free_strings(compose->to_list);
2575 g_slist_free(compose->to_list);
2576 compose->to_list = NULL;
2578 slist_free_strings(compose->newsgroup_list);
2579 g_slist_free(compose->newsgroup_list);
2580 compose->newsgroup_list = NULL;
2582 /* search header entries for to and newsgroup entries */
2583 for(list = compose->header_list; list; list = list->next) {
2586 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2587 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2589 if(entry[0] != '\0') {
2590 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2591 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2592 compose->to_list = address_list_append(compose->to_list, entry);
2593 recipient_found = TRUE;
2596 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2597 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2598 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2599 recipient_found = TRUE;
2605 return recipient_found;
2608 gint compose_send(Compose *compose)
2614 val = compose_queue(compose, &msgnum, &folder);
2616 alertpanel_error(_("Could not queue message for sending"));
2620 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2622 folder_item_remove_msg(folder, msgnum);
2623 folderview_update_item(folder, TRUE);
2629 #if 0 /* compose restructure */
2630 gint compose_send(Compose *compose)
2632 gchar tmp[MAXPATHLEN + 1];
2634 static gboolean lock = FALSE;
2638 g_return_val_if_fail(compose->account != NULL, -1);
2639 g_return_val_if_fail(compose->orig_account != NULL, -1);
2643 if(!compose_check_for_valid_recipient(compose)) {
2644 alertpanel_error(_("Recipient is not specified."));
2649 /* write to temporary file */
2650 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2651 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2653 if (prefs_common.linewrap_at_send)
2654 compose_wrap_line_all(compose);
2656 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2661 if (!compose->to_list && !compose->newsgroup_list) {
2662 g_warning(_("can't get recipient list."));
2668 if (compose->to_list) {
2671 #if 0 /* NEW COMPOSE GUI */
2672 if (compose->account->protocol != A_NNTP)
2673 ac = compose->account;
2674 else if (compose->orig_account->protocol != A_NNTP)
2675 ac = compose->orig_account;
2676 else if (cur_account && cur_account->protocol != A_NNTP)
2679 ac = compose_current_mail_account();
2687 ac = compose->account;
2689 ok = send_message(tmp, ac, compose->to_list);
2690 statusbar_pop_all();
2693 if (ok == 0 && compose->newsgroup_list) {
2696 if (compose->account->protocol == A_NNTP)
2697 folder = FOLDER(compose->account->folder);
2699 folder = FOLDER(compose->orig_account->folder);
2701 ok = news_post(folder, tmp);
2703 alertpanel_error(_("Error occurred while posting the message to %s ."),
2704 compose->account->nntp_server);
2711 /* queue message if failed to send */
2713 if (prefs_common.queue_msg) {
2718 _("Error occurred while sending the message.\n"
2719 "Put this message into queue folder?"),
2720 _("OK"), _("Cancel"), NULL);
2721 if (G_ALERTDEFAULT == val) {
2722 ok = compose_queue(compose, tmp);
2724 alertpanel_error(_("Can't queue the message."));
2727 alertpanel_error(_("Error occurred while sending the message."));
2729 if (compose->mode == COMPOSE_REEDIT) {
2730 compose_remove_reedit_target(compose);
2731 if (compose->targetinfo)
2732 folderview_update_item
2733 (compose->targetinfo->folder, TRUE);
2737 /* save message to outbox */
2738 if (ok == 0 && prefs_common.savemsg) {
2739 if (compose_save_to_outbox(compose, tmp) < 0)
2741 (_("Can't save the message to outbox."));
2750 static gboolean compose_use_attach(Compose *compose) {
2751 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2754 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2757 gchar buf[BUFFSIZE];
2759 gboolean first_address;
2761 ComposeHeaderEntry *headerentry;
2762 gchar *headerentryname;
2763 gchar *header_w_colon;
2767 debug_print(_("Writing bounce header\n"));
2769 header_w_colon = g_strconcat("To:", NULL);
2770 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2771 header_w_colon = g_strconcat("Cc:", NULL);
2772 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2774 first_address = TRUE;
2775 for(list = compose->header_list; list; list = list->next) {
2776 headerentry = ((ComposeHeaderEntry *)list->data);
2777 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2779 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2780 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2781 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2782 Xstrdup_a(str, str, return -1);
2784 if(str[0] != '\0') {
2785 compose_convert_header
2786 (buf, sizeof(buf), str,
2787 strlen("Resent-To") + 2);
2789 fprintf(fp, "Resent-To: ");
2790 first_address = FALSE;
2794 fprintf(fp, "%s", buf);
2798 /* if(!first_address) { */
2805 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2807 gchar buf[BUFFSIZE];
2809 /* struct utsname utsbuf; */
2811 g_return_val_if_fail(fp != NULL, -1);
2812 g_return_val_if_fail(compose->account != NULL, -1);
2813 g_return_val_if_fail(compose->account->address != NULL, -1);
2816 get_rfc822_date(buf, sizeof(buf));
2817 fprintf(fp, "Resent-Date: %s\n", buf);
2820 if (compose->account->name && *compose->account->name) {
2821 compose_convert_header
2822 (buf, sizeof(buf), compose->account->name,
2824 fprintf(fp, "Resent-From: %s <%s>\n",
2825 buf, compose->account->address);
2827 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2830 compose_bounce_write_headers_from_headerlist(compose, fp);
2832 /* separator between header and body */
2838 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2843 gchar buf[BUFFSIZE];
2845 if ((fp = fopen(compose->bounce_filename, "r")) == NULL) {
2846 FILE_OP_ERROR(file, "fopen");
2850 if ((fdest = fopen(file, "w")) == NULL) {
2851 FILE_OP_ERROR(file, "fopen");
2856 /* chmod for security */
2857 if (change_file_mode_rw(fdest, file) < 0) {
2858 FILE_OP_ERROR(file, "chmod");
2859 g_warning(_("can't change file mode\n"));
2862 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2863 /* should filter returnpath, delivered-to */
2864 if ((g_strncasecmp(buf, "Return-Path:",
2865 strlen("Return-Path:")) == 0)
2866 || (g_strncasecmp(buf, "Delivered-To:",
2867 strlen("Delivered-To:")) == 0))
2869 if (fputs(buf, fdest) == -1)
2871 if (fputs("\n", fdest) == -1)
2875 compose_bounce_write_headers(compose, fdest);
2877 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
2878 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
2893 static gint compose_write_to_file(Compose *compose, const gchar *file,
2900 const gchar *out_codeset;
2901 EncodingType encoding;
2903 if ((fp = fopen(file, "w")) == NULL) {
2904 FILE_OP_ERROR(file, "fopen");
2908 /* chmod for security */
2909 if (change_file_mode_rw(fp, file) < 0) {
2910 FILE_OP_ERROR(file, "chmod");
2911 g_warning(_("can't change file mode\n"));
2914 /* get all composed text */
2915 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2916 len = strlen(chars);
2917 if (is_ascii_str(chars)) {
2918 buf = g_strdup(chars);
2919 out_codeset = CS_US_ASCII;
2920 encoding = ENC_7BIT;
2922 const gchar *src_codeset;
2924 out_codeset = conv_get_outgoing_charset_str();
2925 if (!strcasecmp(out_codeset, CS_US_ASCII))
2926 out_codeset = CS_ISO_8859_1;
2927 encoding = procmime_get_encoding_for_charset(out_codeset);
2929 src_codeset = conv_get_current_charset_str();
2930 /* if current encoding is US-ASCII, set it the same as
2931 outgoing one to prevent code conversion failure */
2932 if (!strcasecmp(src_codeset, CS_US_ASCII))
2933 src_codeset = out_codeset;
2935 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
2936 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
2938 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
2943 alertpanel_error(_("Can't convert the codeset of the message."));
2950 if (compose_write_headers
2951 (compose, fp, out_codeset, encoding, is_draft) < 0) {
2952 g_warning(_("can't write headers\n"));
2959 if (compose_use_attach(compose)) {
2961 /* This prolog message is ignored by mime software and
2962 * because it would make our signing/encryption task
2963 * tougher, we don't emit it in that case */
2964 if (!compose->use_signing && !compose->use_encryption)
2966 fputs("This is a multi-part message in MIME format.\n", fp);
2968 fprintf(fp, "\n--%s\n", compose->boundary);
2969 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
2971 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2972 procmime_get_encoding_str(encoding));
2978 if (encoding == ENC_BASE64) {
2979 gchar outbuf[B64_BUFFSIZE];
2982 for (i = 0; i < len; i += B64_LINE_SIZE) {
2983 l = MIN(B64_LINE_SIZE, len - i);
2984 to64frombits(outbuf, buf + i, l);
2988 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
2989 FILE_OP_ERROR(file, "fwrite");
2997 if (compose_use_attach(compose))
2998 compose_write_attach(compose, fp);
3000 if (fclose(fp) == EOF) {
3001 FILE_OP_ERROR(file, "fclose");
3007 if (compose->use_signing) {
3008 if (rfc2015_sign(file, compose->account) < 0) {
3013 if (compose->use_encryption) {
3014 if (rfc2015_encrypt(file, compose->to_list) < 0) {
3019 #endif /* USE_GPGME */
3024 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3030 if ((fp = fopen(file, "w")) == NULL) {
3031 FILE_OP_ERROR(file, "fopen");
3035 /* chmod for security */
3036 if (change_file_mode_rw(fp, file) < 0) {
3037 FILE_OP_ERROR(file, "chmod");
3038 g_warning(_("can't change file mode\n"));
3041 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3044 len = strlen(chars);
3045 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3046 FILE_OP_ERROR(file, "fwrite");
3055 if (fclose(fp) == EOF) {
3056 FILE_OP_ERROR(file, "fclose");
3063 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
3070 debug_print(_("saving sent message...\n"));
3072 outbox = folder_get_default_outbox();
3073 path = folder_item_get_path(outbox);
3074 if (!is_dir_exist(path))
3075 make_dir_hier(path);
3077 folder_item_scan(outbox);
3078 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
3080 g_warning(_("can't save message\n"));
3084 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
3085 g_warning(_("can't open mark file\n"));
3089 newmsginfo.msgnum = num;
3090 newmsginfo.flags.perm_flags = 0;
3091 newmsginfo.flags.tmp_flags = 0;
3092 procmsg_write_flags(&newmsginfo, fp);
3100 static gint compose_remove_reedit_target(Compose *compose)
3103 MsgInfo *msginfo = compose->targetinfo;
3105 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3106 if (!msginfo) return -1;
3108 item = msginfo->folder;
3109 g_return_val_if_fail(item != NULL, -1);
3111 folder_item_scan(item);
3112 if (procmsg_msg_exist(msginfo) &&
3113 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3114 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3115 g_warning(_("can't remove the old message\n"));
3124 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3127 gchar *tmp, *tmp2, *queue_path;
3130 gchar buf[BUFFSIZE];
3132 static gboolean lock = FALSE;
3133 PrefsAccount *mailac = NULL, *newsac = NULL;
3135 debug_print(_("queueing message...\n"));
3136 g_return_val_if_fail(compose->account != NULL, -1);
3137 g_return_val_if_fail(compose->orig_account != NULL, -1);
3141 if(!compose_check_for_valid_recipient(compose)) {
3142 alertpanel_error(_("Recipient is not specified."));
3147 if (!compose->to_list && !compose->newsgroup_list) {
3148 g_warning(_("can't get recipient list."));
3153 if(compose->to_list) {
3154 if (compose->account->protocol != A_NNTP)
3155 mailac = compose->account;
3156 else if (compose->orig_account->protocol != A_NNTP)
3157 mailac = compose->orig_account;
3158 else if (cur_account && cur_account->protocol != A_NNTP)
3159 mailac = cur_account;
3160 else if (!(mailac = compose_current_mail_account())) {
3162 alertpanel_error(_("No account for sending mails available!"));
3167 if(compose->newsgroup_list) {
3168 if (compose->account->protocol == A_NNTP)
3169 newsac = compose->account;
3170 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3172 alertpanel_error(_("No account for posting news available!"));
3177 if (prefs_common.linewrap_at_send)
3178 compose_wrap_line_all(compose);
3180 /* write to temporary file */
3181 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3182 G_DIR_SEPARATOR, (gint)compose);
3184 if (compose->bounce_filename != NULL) {
3185 if (compose_bounce_write_to_file(compose, tmp2) < 0) {
3192 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3199 /* add queue header */
3200 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3201 G_DIR_SEPARATOR, (gint)compose);
3202 if ((fp = fopen(tmp, "w")) == NULL) {
3203 FILE_OP_ERROR(tmp, "fopen");
3207 if ((src_fp = fopen(tmp2, "r")) == NULL) {
3208 FILE_OP_ERROR(tmp2, "fopen");
3216 if (change_file_mode_rw(fp, tmp) < 0) {
3217 FILE_OP_ERROR(tmp, "chmod");
3218 g_warning(_("can't change file mode\n"));
3221 /* queueing variables */
3222 fprintf(fp, "AF:\n");
3223 fprintf(fp, "NF:0\n");
3224 fprintf(fp, "PS:10\n");
3225 fprintf(fp, "SRH:1\n");
3226 fprintf(fp, "SFN:\n");
3227 fprintf(fp, "DSR:\n");
3229 fprintf(fp, "MID:<%s>\n", compose->msgid);
3231 fprintf(fp, "MID:\n");
3232 fprintf(fp, "CFG:\n");
3233 fprintf(fp, "PT:0\n");
3234 fprintf(fp, "S:%s\n", compose->account->address);
3235 fprintf(fp, "RQ:\n");
3237 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3239 fprintf(fp, "SSV:\n");
3241 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3243 fprintf(fp, "NSV:\n");
3244 fprintf(fp, "SSH:\n");
3245 /* write recepient list */
3247 if(compose->to_list) {
3248 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3249 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3250 fprintf(fp, ",<%s>", (gchar *)cur->data);
3253 /* write newsgroup list */
3255 if(compose->newsgroup_list) {
3256 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3257 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3258 fprintf(fp, ",%s", (gchar *)cur->data);
3261 /* Sylpheed account IDs */
3263 fprintf(fp, "MAID:%d\n", mailac->account_id);
3266 fprintf(fp, "NAID:%d\n", newsac->account_id);
3270 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3271 if (fputs(buf, fp) == EOF) {
3272 FILE_OP_ERROR(tmp, "fputs");
3283 if (fclose(fp) == EOF) {
3284 FILE_OP_ERROR(tmp, "fclose");
3293 queue = folder_get_default_queue();
3295 folder_item_scan(queue);
3296 queue_path = folder_item_get_path(queue);
3297 if (!is_dir_exist(queue_path))
3298 make_dir_hier(queue_path);
3299 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3300 g_warning(_("can't queue the message\n"));
3311 if (compose->mode == COMPOSE_REEDIT) {
3312 compose_remove_reedit_target(compose);
3313 if (compose->targetinfo &&
3314 compose->targetinfo->folder != queue)
3315 folderview_update_item
3316 (compose->targetinfo->folder, TRUE);
3319 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
3320 g_warning(_("can't open mark file\n"));
3324 newmsginfo.msgnum = num;
3325 newmsginfo.flags.perm_flags = 0;
3326 newmsginfo.flags.tmp_flags = 0;
3327 procmsg_write_flags(&newmsginfo, fp);
3332 folder_item_scan(queue);
3333 folderview_update_item(queue, TRUE);
3335 if((msgnum != NULL) && (item != NULL)) {
3343 static void compose_write_attach(Compose *compose, FILE *fp)
3346 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3349 gchar filename[BUFFSIZE];
3352 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3354 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
3355 g_warning(_("Can't open file %s\n"), ainfo->file);
3359 fprintf(fp, "\n--%s\n", compose->boundary);
3361 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3362 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3363 fprintf(fp, "Content-Disposition: inline\n");
3365 conv_encode_header(filename, sizeof(filename),
3367 fprintf(fp, "Content-Type: %s;\n"
3369 ainfo->content_type, filename);
3370 fprintf(fp, "Content-Disposition: attachment;\n"
3371 " filename=\"%s\"\n", filename);
3374 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3375 procmime_get_encoding_str(ainfo->encoding));
3377 if (ainfo->encoding == ENC_7BIT) {
3378 gchar buf[BUFFSIZE];
3380 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3385 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3387 while ((len = fread(inbuf, sizeof(gchar),
3388 B64_LINE_SIZE, attach_fp))
3390 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3394 if (len > 0 && feof(attach_fp)) {
3395 to64frombits(outbuf, inbuf, len);
3404 fprintf(fp, "\n--%s--\n", compose->boundary);
3407 #define IS_IN_CUSTOM_HEADER(header) \
3408 (compose->account->add_customhdr && \
3409 custom_header_find(compose->account->customhdr_list, header) != NULL)
3411 static gint compose_write_headers_from_headerlist(Compose *compose,
3415 gchar buf[BUFFSIZE];
3416 gchar *str, *header_w_colon, *trans_hdr;
3417 gboolean first_address;
3419 ComposeHeaderEntry *headerentry;
3420 gchar * headerentryname;
3422 if (IS_IN_CUSTOM_HEADER(header)) {
3426 debug_print(_("Writing %s-header\n"), header);
3428 header_w_colon = g_strconcat(header, ":", NULL);
3429 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3431 first_address = TRUE;
3432 for(list = compose->header_list; list; list = list->next) {
3433 headerentry = ((ComposeHeaderEntry *)list->data);
3434 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3436 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3437 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3438 Xstrdup_a(str, str, return -1);
3440 if(str[0] != '\0') {
3441 compose_convert_header
3442 (buf, sizeof(buf), str,
3443 strlen(header) + 2);
3445 fprintf(fp, "%s: ", header);
3446 first_address = FALSE;
3450 fprintf(fp, "%s", buf);
3454 if(!first_address) {
3458 g_free(header_w_colon);
3463 static gint compose_write_headers(Compose *compose, FILE *fp,
3464 const gchar *charset, EncodingType encoding,
3467 gchar buf[BUFFSIZE];
3469 /* struct utsname utsbuf; */
3471 g_return_val_if_fail(fp != NULL, -1);
3472 g_return_val_if_fail(charset != NULL, -1);
3473 g_return_val_if_fail(compose->account != NULL, -1);
3474 g_return_val_if_fail(compose->account->address != NULL, -1);
3477 if (compose->account->add_date) {
3478 get_rfc822_date(buf, sizeof(buf));
3479 fprintf(fp, "Date: %s\n", buf);
3483 if (!IS_IN_CUSTOM_HEADER("From")) {
3484 if (compose->account->name && *compose->account->name) {
3485 compose_convert_header
3486 (buf, sizeof(buf), compose->account->name,
3488 fprintf(fp, "From: %s <%s>\n",
3489 buf, compose->account->address);
3491 fprintf(fp, "From: %s\n", compose->account->address);
3495 compose_write_headers_from_headerlist(compose, fp, "To");
3496 #if 0 /* NEW COMPOSE GUI */
3497 if (compose->use_to) {
3498 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3500 Xstrdup_a(str, str, return -1);
3503 compose->to_list = address_list_append
3504 (compose->to_list, str);
3505 if (!IS_IN_CUSTOM_HEADER("To")) {
3506 compose_convert_header
3507 (buf, sizeof(buf), str,
3509 fprintf(fp, "To: %s\n", buf);
3517 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3518 #if 0 /* NEW COMPOSE GUI */
3519 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3521 Xstrdup_a(str, str, return -1);
3525 compose->newsgroup_list =
3526 newsgroup_list_append(compose->newsgroup_list,
3528 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3529 compose_convert_header(buf, sizeof(buf), str,
3530 strlen("Newsgroups: "));
3531 fprintf(fp, "Newsgroups: %s\n", buf);
3537 compose_write_headers_from_headerlist(compose, fp, "Cc");
3538 #if 0 /* NEW COMPOSE GUI */
3539 if (compose->use_cc) {
3540 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3542 Xstrdup_a(str, str, return -1);
3545 compose->to_list = address_list_append
3546 (compose->to_list, str);
3547 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3548 compose_convert_header
3549 (buf, sizeof(buf), str,
3551 fprintf(fp, "Cc: %s\n", buf);
3558 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3559 #if 0 /* NEW COMPOSE GUI */
3560 if (compose->use_bcc) {
3561 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3563 Xstrdup_a(str, str, return -1);
3566 compose->to_list = address_list_append
3567 (compose->to_list, str);
3568 compose_convert_header(buf, sizeof(buf), str,
3570 fprintf(fp, "Bcc: %s\n", buf);
3577 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3578 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3579 Xstrdup_a(str, str, return -1);
3582 compose_convert_header(buf, sizeof(buf), str,
3583 strlen("Subject: "));
3584 fprintf(fp, "Subject: %s\n", buf);
3589 if (compose->account->gen_msgid) {
3590 compose_generate_msgid(compose, buf, sizeof(buf));
3591 fprintf(fp, "Message-Id: <%s>\n", buf);
3592 compose->msgid = g_strdup(buf);
3596 if (compose->inreplyto && compose->to_list)
3597 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3600 if (compose->references)
3601 fprintf(fp, "References: %s\n", compose->references);
3604 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3605 #if 0 /* NEW COMPOSE GUI */
3606 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3607 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3609 Xstrdup_a(str, str, return -1);
3613 compose_convert_header(buf, sizeof(buf), str,
3614 strlen("Followup-To: "));
3615 fprintf(fp, "Followup-To: %s\n", buf);
3621 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3622 #if 0 /* NEW COMPOSE GUI */
3623 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3624 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3626 Xstrdup_a(str, str, return -1);
3629 compose_convert_header(buf, sizeof(buf), str,
3630 strlen("Reply-To: "));
3631 fprintf(fp, "Reply-To: %s\n", buf);
3637 if (compose->account->organization &&
3638 !IS_IN_CUSTOM_HEADER("Organization")) {
3639 compose_convert_header(buf, sizeof(buf),
3640 compose->account->organization,
3641 strlen("Organization: "));
3642 fprintf(fp, "Organization: %s\n", buf);
3645 /* Program version and system info */
3646 /* uname(&utsbuf); */
3647 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3648 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3650 gtk_major_version, gtk_minor_version, gtk_micro_version,
3652 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3654 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3655 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3657 gtk_major_version, gtk_minor_version, gtk_micro_version,
3659 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3662 /* custom headers */
3663 if (compose->account->add_customhdr) {
3666 for (cur = compose->account->customhdr_list; cur != NULL;
3668 CustomHeader *chdr = (CustomHeader *)cur->data;
3670 if (strcasecmp(chdr->name, "Date") != 0 &&
3671 strcasecmp(chdr->name, "From") != 0 &&
3672 strcasecmp(chdr->name, "To") != 0 &&
3673 /* strcasecmp(chdr->name, "Sender") != 0 && */
3674 strcasecmp(chdr->name, "Message-Id") != 0 &&
3675 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3676 strcasecmp(chdr->name, "References") != 0 &&
3677 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3678 strcasecmp(chdr->name, "Content-Type") != 0 &&
3679 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3681 compose_convert_header
3683 chdr->value ? chdr->value : "",
3684 strlen(chdr->name) + 2);
3685 fprintf(fp, "%s: %s\n", chdr->name, buf);
3691 fprintf(fp, "Mime-Version: 1.0\n");
3692 if (compose_use_attach(compose)) {
3693 get_rfc822_date(buf, sizeof(buf));
3694 subst_char(buf, ' ', '_');
3695 subst_char(buf, ',', '_');
3696 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3697 buf, (guint)compose);
3699 "Content-Type: multipart/mixed;\n"
3700 " boundary=\"%s\"\n", compose->boundary);
3702 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3703 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3704 procmime_get_encoding_str(encoding));
3707 /* Request Return Receipt */
3708 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3709 if (compose->return_receipt) {
3710 if (compose->account->name
3711 && *compose->account->name) {
3712 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3713 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3715 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3719 /* separator between header and body */
3725 #undef IS_IN_CUSTOM_HEADER
3727 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3730 g_return_if_fail(src != NULL);
3731 g_return_if_fail(dest != NULL);
3733 if (len < 1) return;
3737 if (is_ascii_str(src)) {
3738 strncpy2(dest, src, len);
3739 dest[len - 1] = '\0';
3742 conv_encode_header(dest, len, src, header_len);
3745 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3754 if (compose->account && compose->account->address &&
3755 *compose->account->address) {
3756 if (strchr(compose->account->address, '@'))
3757 addr = g_strdup(compose->account->address);
3759 addr = g_strconcat(compose->account->address, "@",
3760 get_domain_name(), NULL);
3762 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3765 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3766 lt->tm_year + 1900, lt->tm_mon + 1,
3767 lt->tm_mday, lt->tm_hour,
3768 lt->tm_min, lt->tm_sec,
3769 (guint)random(), addr);
3771 debug_print(_("generated Message-ID: %s\n"), buf);
3777 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3778 GtkWidget **entry, gint *count,
3779 const gchar *label_str,
3780 gboolean is_addr_entry)
3784 if (GTK_TABLE(table)->nrows < (*count) + 1)
3785 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3787 *hbox = gtk_hbox_new(FALSE, 0);
3788 label = gtk_label_new
3789 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3790 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3791 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3793 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3795 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3796 #if 0 /* NEW COMPOSE GUI */
3797 if (GTK_TABLE(table)->nrows > (*count) + 1)
3798 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3802 address_completion_register_entry(GTK_ENTRY(*entry));
3807 static void compose_create_header_entry(Compose *compose) {
3808 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3812 GList *combo_list = NULL;
3813 gchar **string, *header;
3814 ComposeHeaderEntry *headerentry;
3816 headerentry = g_new0(ComposeHeaderEntry, 1);
3819 combo = gtk_combo_new();
3821 while(*string != NULL) {
3822 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3825 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3826 g_list_free(combo_list);
3827 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3828 gtk_widget_show(combo);
3829 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3830 if(compose->header_last) {
3831 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3833 switch(compose->account->protocol) {
3835 header = _("Newsgroups:");
3842 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
3845 entry = gtk_entry_new();
3846 gtk_widget_show(entry);
3847 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);
3849 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
3850 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
3852 address_completion_register_entry(GTK_ENTRY(entry));
3854 headerentry->compose = compose;
3855 headerentry->combo = combo;
3856 headerentry->entry = entry;
3857 headerentry->headernum = compose->header_nextrow;
3859 compose->header_nextrow++;
3860 compose->header_last = headerentry;
3863 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text) {
3864 ComposeHeaderEntry *last_header;
3866 last_header = compose->header_last;
3868 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
3869 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
3872 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
3878 GtkWidget *handlebox;
3880 GtkWidget *notebook;
3884 GtkWidget *table_vbox;
3886 GtkWidget *from_optmenu_hbox;
3887 #if 0 /* NEW COMPOSE GUI */
3888 GtkWidget *to_entry;
3890 GtkWidget *newsgroups_entry;
3891 GtkWidget *newsgroups_hbox;
3893 GtkWidget *header_scrolledwin;
3894 GtkWidget *header_table;
3895 GtkWidget *subject_entry;
3896 #if 0 /* NEW COMPOSE GUI */
3897 GtkWidget *cc_entry;
3899 GtkWidget *bcc_entry;
3900 GtkWidget *bcc_hbox;
3901 GtkWidget *reply_entry;
3902 GtkWidget *reply_hbox;
3903 GtkWidget *followup_entry;
3904 GtkWidget *followup_hbox;
3908 GtkWidget *attach_scrwin;
3909 GtkWidget *attach_clist;
3911 GtkWidget *edit_vbox;
3912 GtkWidget *ruler_hbox;
3914 GtkWidget *scrolledwin;
3920 UndoMain *undostruct;
3922 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
3923 guint n_menu_entries;
3924 GtkStyle *style, *new_style;
3927 gboolean success[1];
3929 GtkWidget *popupmenu;
3930 GtkWidget *menuitem;
3931 GtkItemFactory *popupfactory;
3932 GtkItemFactory *ifactory;
3933 GtkWidget *tmpl_menu;
3939 GtkPspell * gtkpspell = NULL;
3942 g_return_val_if_fail(account != NULL, NULL);
3944 debug_print(_("Creating compose window...\n"));
3945 compose = g_new0(Compose, 1);
3947 compose->account = account;
3948 compose->orig_account = account;
3950 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
3951 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
3952 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
3953 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3954 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
3955 gtk_signal_connect(GTK_OBJECT(window), "destroy",
3956 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
3957 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
3958 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
3959 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
3960 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
3961 gtk_widget_realize(window);
3963 gtkut_widget_set_composer_icon(window);
3965 vbox = gtk_vbox_new(FALSE, 0);
3966 gtk_container_add(GTK_CONTAINER(window), vbox);
3968 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
3969 menubar = menubar_create(window, compose_entries,
3970 n_menu_entries, "<Compose>", compose);
3971 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
3973 handlebox = gtk_handle_box_new();
3974 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
3976 compose_toolbar_create(compose, handlebox);
3978 vbox2 = gtk_vbox_new(FALSE, 2);
3979 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
3980 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
3982 table_vbox = gtk_vbox_new(FALSE, 0);
3983 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
3984 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
3988 notebook = gtk_notebook_new();
3989 gtk_widget_set_usize(notebook, -1, 180);
3990 gtk_widget_show(notebook);
3992 /* header labels and entries */
3993 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3994 gtk_widget_show(header_scrolledwin);
3995 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
3996 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), header_scrolledwin, gtk_label_new(_("Header")));
3998 header_table = gtk_table_new(2, 2, FALSE);
3999 gtk_widget_show(header_table);
4000 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
4001 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
4004 /* option menu for selecting accounts */
4005 hbox = gtk_hbox_new(FALSE, 0);
4006 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
4007 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
4008 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
4010 from_optmenu_hbox = compose_account_option_menu_create(compose);
4011 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
4012 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
4013 #if 0 /* NEW COMPOSE GUI */
4014 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4019 compose_add_entry_field(header_table, &hbox, &subject_entry, &count,
4022 compose->header_table = header_table;
4023 compose->header_list = NULL;
4024 compose->header_nextrow = count;
4026 compose_create_header_entry(compose);
4028 #if 0 /* NEW COMPOSE GUI */
4029 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
4031 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
4032 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
4033 &count, "Newsgroups:", FALSE);
4034 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
4036 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
4038 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
4040 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
4041 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
4043 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
4044 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
4046 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
4047 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
4048 "Followup-To:", FALSE);
4049 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
4051 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
4053 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
4054 GTK_SIGNAL_FUNC(to_activated), compose);
4055 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
4056 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
4057 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
4058 GTK_SIGNAL_FUNC(subject_activated), compose);
4059 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
4060 GTK_SIGNAL_FUNC(cc_activated), compose);
4061 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
4062 GTK_SIGNAL_FUNC(bcc_activated), compose);
4063 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4064 GTK_SIGNAL_FUNC(replyto_activated), compose);
4065 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4066 GTK_SIGNAL_FUNC(followupto_activated), compose);
4068 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4069 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4070 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4071 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4072 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4073 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4074 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4075 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4076 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4077 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4078 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4079 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4080 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4081 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4084 /* attachment list */
4085 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4086 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), attach_scrwin, gtk_label_new(_("Attachments")));
4087 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4088 GTK_POLICY_AUTOMATIC,
4090 gtk_widget_set_usize(attach_scrwin, -1, 80);
4092 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4093 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4095 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4096 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4097 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4098 GTK_SELECTION_EXTENDED);
4099 for (i = 0; i < N_ATTACH_COLS; i++)
4100 GTK_WIDGET_UNSET_FLAGS
4101 (GTK_CLIST(attach_clist)->column[i].button,
4103 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4105 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4106 GTK_SIGNAL_FUNC(attach_selected), compose);
4107 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4108 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4109 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4110 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4113 gtk_drag_dest_set(attach_clist,
4114 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4116 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4117 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4121 edit_vbox = gtk_vbox_new(FALSE, 0);
4122 #if 0 /* NEW COMPOSE GUI */
4123 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4127 ruler_hbox = gtk_hbox_new(FALSE, 0);
4128 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4130 ruler = gtk_shruler_new();
4131 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4132 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4134 gtk_widget_set_usize(ruler_hbox, 1, -1);
4137 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4138 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4139 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4140 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4141 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4143 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4144 (GTK_SCROLLED_WINDOW(scrolledwin)),
4145 gtk_scrolled_window_get_vadjustment
4146 (GTK_SCROLLED_WINDOW(scrolledwin)));
4147 GTK_STEXT(text)->default_tab_width = 8;
4148 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4150 if (prefs_common.block_cursor) {
4151 GTK_STEXT(text)->cursor_type = STEXT_CURSOR_BLOCK;
4154 if (prefs_common.smart_wrapping) {
4155 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4156 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4159 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4161 gtk_signal_connect(GTK_OBJECT(text), "changed",
4162 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4163 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4164 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4165 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4166 GTK_SIGNAL_FUNC(compose_button_press_cb),
4169 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4170 GTK_SIGNAL_FUNC(compose_key_press_cb),
4173 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4174 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4178 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4180 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4181 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4184 if (prefs_common.enable_pspell) {
4185 gtkpspell = gtkpspell_new_with_config(gtkpspellconfig,
4186 prefs_common.pspell_path,
4187 prefs_common.dictionary,
4189 conv_get_current_charset_str());
4190 if (gtkpspell == NULL)
4191 prefs_common.enable_pspell = FALSE;
4193 gtkpspell_attach(gtkpspell, GTK_STEXT(text));
4196 gtk_widget_show_all(vbox);
4198 /* pane between attach clist and text */
4199 paned = gtk_vpaned_new();
4200 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4201 gtk_paned_add1(GTK_PANED(paned), notebook);
4202 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4203 gtk_widget_show_all(paned);
4205 style = gtk_widget_get_style(text);
4207 /* workaround for the slow down of GtkText when using Pixmap theme */
4208 if (style->engine) {
4209 GtkThemeEngine *engine;
4211 engine = style->engine;
4212 style->engine = NULL;
4213 new_style = gtk_style_copy(style);
4214 style->engine = engine;
4216 new_style = gtk_style_copy(style);
4218 if (prefs_common.textfont) {
4221 charset = conv_get_current_charset();
4222 if (MB_CUR_MAX == 1) {
4225 Xstrdup_a(fontstr, prefs_common.textfont, );
4226 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4228 font = gdk_font_load(fontstr);
4230 font = gdk_fontset_load(prefs_common.textfont);
4232 gdk_font_unref(new_style->font);
4233 new_style->font = font;
4237 gtk_widget_set_style(text, new_style);
4239 color[0] = quote_color;
4240 cmap = gdk_window_get_colormap(window->window);
4241 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4242 if (success[0] == FALSE) {
4243 g_warning("Compose: color allocation failed.\n");
4244 style = gtk_widget_get_style(text);
4245 quote_color = style->black;
4248 n_entries = sizeof(compose_popup_entries) /
4249 sizeof(compose_popup_entries[0]);
4250 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4251 "<Compose>", &popupfactory,
4254 ifactory = gtk_item_factory_from_widget(menubar);
4255 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4256 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4258 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tool/Template");
4259 #if 0 /* NEW COMPOSE GUI */
4260 if (account->protocol == A_NNTP) {
4261 gtk_widget_hide(to_hbox);
4262 gtk_widget_hide(to_entry);
4263 gtk_widget_hide(cc_hbox);
4264 gtk_widget_hide(cc_entry);
4265 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4266 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4268 gtk_widget_hide(newsgroups_hbox);
4269 gtk_widget_hide(newsgroups_entry);
4270 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4272 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
4276 switch (prefs_common.toolbar_style) {
4278 gtk_widget_hide(handlebox);
4281 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4285 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4289 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4294 gtk_widget_show(window);
4296 address_completion_start(window);
4298 compose->window = window;
4299 compose->vbox = vbox;
4300 compose->menubar = menubar;
4301 compose->handlebox = handlebox;
4303 compose->vbox2 = vbox2;
4305 compose->table_vbox = table_vbox;
4306 compose->table = NULL;
4307 #if 0 /* NEW COMPOSE GUI */
4308 compose->table = table;
4309 compose->to_hbox = to_hbox;
4310 compose->to_entry = to_entry;
4311 compose->newsgroups_hbox = newsgroups_hbox;
4312 compose->newsgroups_entry = newsgroups_entry;
4314 compose->subject_entry = subject_entry;
4315 #if 0 /* NEW COMPOSE GUI */
4316 compose->cc_hbox = cc_hbox;
4317 compose->cc_entry = cc_entry;
4318 compose->bcc_hbox = bcc_hbox;
4319 compose->bcc_entry = bcc_entry;
4320 compose->reply_hbox = reply_hbox;
4321 compose->reply_entry = reply_entry;
4322 compose->followup_hbox = followup_hbox;
4323 compose->followup_entry = followup_entry;
4325 compose->paned = paned;
4327 compose->attach_scrwin = attach_scrwin;
4328 compose->attach_clist = attach_clist;
4330 compose->edit_vbox = edit_vbox;
4331 compose->ruler_hbox = ruler_hbox;
4332 compose->ruler = ruler;
4333 compose->scrolledwin = scrolledwin;
4334 compose->text = text;
4336 compose->focused_editable = NULL;
4338 compose->popupmenu = popupmenu;
4339 compose->popupfactory = popupfactory;
4341 compose->tmpl_menu = tmpl_menu;
4343 compose->mode = mode;
4345 compose->targetinfo = NULL;
4346 compose->replyinfo = NULL;
4348 compose->replyto = NULL;
4349 compose->mailinglist = NULL;
4351 compose->bcc = NULL;
4352 compose->followup_to = NULL;
4353 compose->inreplyto = NULL;
4354 compose->references = NULL;
4355 compose->msgid = NULL;
4356 compose->boundary = NULL;
4359 compose->use_signing = FALSE;
4360 compose->use_encryption = FALSE;
4361 #endif /* USE_GPGME */
4363 compose->modified = FALSE;
4365 compose->return_receipt = FALSE;
4367 compose->to_list = NULL;
4368 compose->newsgroup_list = NULL;
4370 compose->exteditor_file = NULL;
4371 compose->exteditor_pid = -1;
4372 compose->exteditor_readdes = -1;
4373 compose->exteditor_tag = -1;
4375 compose->bounce_filename = NULL;
4377 compose_set_title(compose);
4379 #if 0 /* NEW COMPOSE GUI */
4380 compose->use_bcc = FALSE;
4381 compose->use_replyto = FALSE;
4382 compose->use_followupto = FALSE;
4386 compose->gtkpspell = gtkpspell;
4389 undostruct = undo_init(text);
4391 compose->undostruct = undostruct;
4392 undo_set_undo_change_funct(undostruct, &compose_set_undo, GTK_WIDGET(compose->menubar));
4394 #if 0 /* NEW COMPOSE GUI */
4395 if (account->protocol != A_NNTP) {
4396 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4397 gtk_check_menu_item_set_active
4398 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4399 gtk_widget_set_sensitive(menuitem, FALSE);
4400 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4401 gtk_check_menu_item_set_active
4402 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4403 gtk_widget_set_sensitive(menuitem, FALSE);
4406 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4407 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4408 #if 0 /* NEW COMPOSE GUI */
4409 compose->use_cc = TRUE;
4410 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4411 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4412 gtk_check_menu_item_set_active
4413 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4416 if (account->set_autobcc) {
4417 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4418 #if 0 /* NEW COMPOSE GUI */
4419 compose->use_bcc = TRUE;
4420 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
4421 gtk_check_menu_item_set_active
4422 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4423 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4424 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4428 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4429 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4430 #if 0 /* NEW COMPOSE GUI */
4431 compose->use_replyto = TRUE;
4432 menuitem = gtk_item_factory_get_item(ifactory,
4433 "/Message/Reply to");
4434 gtk_check_menu_item_set_active
4435 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4436 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4437 account->auto_replyto);
4440 if (account->protocol != A_NNTP) {
4441 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("To:"));
4443 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("Newsgroups:"));
4446 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
4447 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4448 prefs_common.show_ruler);
4451 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4452 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4453 prefs_common.default_sign);
4454 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4455 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4456 prefs_common.default_encrypt);
4457 #endif /* USE_GPGME */
4459 addressbook_set_target_compose(compose);
4460 compose_set_template_menu(compose);
4462 compose_list = g_list_append(compose_list, compose);
4464 #if 0 /* NEW COMPOSE GUI */
4465 compose->use_to = FALSE;
4466 compose->use_cc = FALSE;
4467 compose->use_attach = TRUE;
4470 #if 0 /* NEW COMPOSE GUI */
4471 if (!compose->use_bcc) {
4472 gtk_widget_hide(bcc_hbox);
4473 gtk_widget_hide(bcc_entry);
4474 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4476 if (!compose->use_replyto) {
4477 gtk_widget_hide(reply_hbox);
4478 gtk_widget_hide(reply_entry);
4479 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4481 if (!compose->use_followupto) {
4482 gtk_widget_hide(followup_hbox);
4483 gtk_widget_hide(followup_entry);
4484 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4487 if (!prefs_common.show_ruler)
4488 gtk_widget_hide(ruler_hbox);
4490 select_account(compose, account);
4495 #include "pixmaps/stock_mail_send.xpm"
4496 #include "pixmaps/stock_mail_send_queue.xpm"
4497 #include "pixmaps/stock_mail.xpm"
4498 #include "pixmaps/stock_paste.xpm"
4499 #include "pixmaps/stock_mail_attach.xpm"
4500 #include "pixmaps/stock_mail_compose.xpm"
4501 #include "pixmaps/linewrap.xpm"
4502 #include "pixmaps/tb_address_book.xpm"
4504 #define CREATE_TOOLBAR_ICON(xpm_d) \
4506 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
4507 &container->style->white, \
4509 icon_wid = gtk_pixmap_new(icon, mask); \
4512 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4517 GtkWidget *icon_wid;
4518 GtkWidget *send_btn;
4519 GtkWidget *sendl_btn;
4520 GtkWidget *draft_btn;
4521 GtkWidget *insert_btn;
4522 GtkWidget *attach_btn;
4524 GtkWidget *exteditor_btn;
4525 GtkWidget *linewrap_btn;
4526 GtkWidget *addrbook_btn;
4528 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4530 gtk_container_add(GTK_CONTAINER(container), toolbar);
4531 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4532 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4533 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4534 GTK_TOOLBAR_SPACE_LINE);
4536 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
4537 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4541 icon_wid, toolbar_send_cb, compose);
4543 CREATE_TOOLBAR_ICON(stock_mail_send_queue_xpm);
4544 /* CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm); */
4545 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4547 _("Put into queue folder and send later"),
4549 icon_wid, toolbar_send_later_cb,
4552 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4553 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4555 _("Save to draft folder"),
4557 icon_wid, toolbar_draft_cb,
4560 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4562 CREATE_TOOLBAR_ICON(stock_paste_xpm);
4563 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4567 icon_wid, toolbar_insert_cb,
4570 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
4571 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4575 icon_wid, toolbar_attach_cb,
4578 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4580 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4581 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4583 _("Insert signature"),
4585 icon_wid, toolbar_sig_cb, compose);
4587 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4589 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
4590 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4592 _("Edit with external editor"),
4595 toolbar_ext_editor_cb,
4598 CREATE_TOOLBAR_ICON(linewrap_xpm);
4599 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4601 _("Wrap current paragraph"),
4604 toolbar_linewrap_cb,
4607 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4609 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
4610 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4614 icon_wid, toolbar_address_cb,
4617 compose->toolbar = toolbar;
4618 compose->send_btn = send_btn;
4619 compose->sendl_btn = sendl_btn;
4620 compose->draft_btn = draft_btn;
4621 compose->insert_btn = insert_btn;
4622 compose->attach_btn = attach_btn;
4623 compose->sig_btn = sig_btn;
4624 compose->exteditor_btn = exteditor_btn;
4625 compose->linewrap_btn = linewrap_btn;
4626 compose->addrbook_btn = addrbook_btn;
4628 gtk_widget_show_all(toolbar);
4631 #undef CREATE_TOOLBAR_ICON
4633 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4639 gint num = 0, def_menu = 0;
4641 accounts = account_get_list();
4642 g_return_val_if_fail(accounts != NULL, NULL);
4644 hbox = gtk_hbox_new(FALSE, 0);
4645 optmenu = gtk_option_menu_new();
4646 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4647 menu = gtk_menu_new();
4649 for (; accounts != NULL; accounts = accounts->next, num++) {
4650 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4651 GtkWidget *menuitem;
4654 if (ac == compose->account) def_menu = num;
4656 name = g_strdup_printf("%s: %s <%s>",
4657 ac->account_name, ac->name, ac->address);
4658 MENUITEM_ADD(menu, menuitem, name, ac);
4660 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4661 GTK_SIGNAL_FUNC(account_activated),
4665 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4666 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4671 static void compose_set_template_menu(Compose *compose)
4673 GSList *tmpl_list, *cur;
4677 tmpl_list = template_get_config();
4679 menu = gtk_menu_new();
4681 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4682 Template *tmpl = (Template *)cur->data;
4684 item = gtk_menu_item_new_with_label(tmpl->name);
4685 gtk_menu_append(GTK_MENU(menu), item);
4686 gtk_signal_connect(GTK_OBJECT(item), "activate",
4687 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4689 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4690 gtk_widget_show(item);
4693 gtk_widget_show(menu);
4694 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4697 void compose_reflect_prefs_all(void)
4702 for (cur = compose_list; cur != NULL; cur = cur->next) {
4703 compose = (Compose *)cur->data;
4704 compose_set_template_menu(compose);
4708 static void compose_template_apply(Compose *compose, Template *tmpl)
4713 if (!tmpl || !tmpl->value) return;
4715 gtk_stext_freeze(GTK_STEXT(compose->text));
4718 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
4721 if (compose->replyinfo == NULL) {
4724 memset(&dummyinfo, 0, sizeof(MsgInfo));
4725 parsed_str = compose_quote_fmt(compose, &dummyinfo,
4728 if (prefs_common.quotemark && *prefs_common.quotemark)
4729 qmark = prefs_common.quotemark;
4733 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
4734 tmpl->value, qmark);
4737 if (parsed_str && prefs_common.auto_sig)
4738 compose_insert_sig(compose);
4740 gtk_stext_thaw(GTK_STEXT(compose->text));
4743 static void compose_destroy(Compose *compose)
4746 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4749 /* NOTE: address_completion_end() does nothing with the window
4750 * however this may change. */
4751 address_completion_end(compose->window);
4753 slist_free_strings(compose->to_list);
4754 g_slist_free(compose->to_list);
4755 slist_free_strings(compose->newsgroup_list);
4756 g_slist_free(compose->newsgroup_list);
4757 slist_free_strings(compose->header_list);
4758 g_slist_free(compose->header_list);
4760 procmsg_msginfo_free(compose->targetinfo);
4761 procmsg_msginfo_free(compose->replyinfo);
4763 g_free(compose->replyto);
4764 g_free(compose->cc);
4765 g_free(compose->bcc);
4766 g_free(compose->newsgroups);
4767 g_free(compose->followup_to);
4769 g_free(compose->inreplyto);
4770 g_free(compose->references);
4771 g_free(compose->msgid);
4772 g_free(compose->boundary);
4774 if (compose->bounce_filename)
4775 g_free(compose->bounce_filename);
4777 g_free(compose->exteditor_file);
4779 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
4781 compose_attach_info_free(ainfo);
4783 if (addressbook_get_target_compose() == compose)
4784 addressbook_set_target_compose(NULL);
4786 prefs_common.compose_width = compose->scrolledwin->allocation.width;
4787 prefs_common.compose_height = compose->window->allocation.height;
4789 gtk_widget_destroy(compose->paned);
4793 compose_list = g_list_remove(compose_list, compose);
4796 static void compose_attach_info_free(AttachInfo *ainfo)
4798 g_free(ainfo->file);
4799 g_free(ainfo->content_type);
4800 g_free(ainfo->name);
4804 static void compose_attach_remove_selected(Compose *compose)
4806 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4810 while (clist->selection != NULL) {
4811 row = GPOINTER_TO_INT(clist->selection->data);
4812 ainfo = gtk_clist_get_row_data(clist, row);
4813 compose_attach_info_free(ainfo);
4814 gtk_clist_remove(clist, row);
4818 static struct _AttachProperty
4821 GtkWidget *mimetype_entry;
4822 GtkWidget *encoding_optmenu;
4823 GtkWidget *path_entry;
4824 GtkWidget *filename_entry;
4826 GtkWidget *cancel_btn;
4829 static void compose_attach_property(Compose *compose)
4831 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4834 GtkOptionMenu *optmenu;
4835 static gboolean cancelled;
4837 if (!clist->selection) return;
4838 row = GPOINTER_TO_INT(clist->selection->data);
4840 ainfo = gtk_clist_get_row_data(clist, row);
4843 if (!attach_prop.window)
4844 compose_attach_property_create(&cancelled);
4845 gtk_widget_grab_focus(attach_prop.ok_btn);
4846 gtk_widget_show(attach_prop.window);
4847 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
4849 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
4850 if (ainfo->encoding == ENC_UNKNOWN)
4851 gtk_option_menu_set_history(optmenu, ENC_BASE64);
4853 gtk_option_menu_set_history(optmenu, ainfo->encoding);
4855 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
4856 ainfo->content_type ? ainfo->content_type : "");
4857 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
4858 ainfo->file ? ainfo->file : "");
4859 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
4860 ainfo->name ? ainfo->name : "");
4864 gchar *cnttype = NULL;
4868 GtkWidget *menuitem;
4873 if (cancelled == TRUE) {
4874 gtk_widget_hide(attach_prop.window);
4878 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
4879 if (*text != '\0') {
4882 text = g_strstrip(g_strdup(text));
4883 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
4884 cnttype = g_strdup(text);
4887 alertpanel_error(_("Invalid MIME type."));
4893 menu = gtk_option_menu_get_menu(optmenu);
4894 menuitem = gtk_menu_get_active(GTK_MENU(menu));
4895 ainfo->encoding = GPOINTER_TO_INT
4896 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
4898 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
4899 if (*text != '\0') {
4900 if (is_file_exist(text) &&
4901 (size = get_file_size(text)) > 0)
4902 file = g_strdup(text);
4905 (_("File doesn't exist or is empty."));
4911 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
4912 if (*text != '\0') {
4913 g_free(ainfo->name);
4914 ainfo->name = g_strdup(text);
4918 g_free(ainfo->content_type);
4919 ainfo->content_type = cnttype;
4922 g_free(ainfo->file);
4928 gtk_clist_set_text(clist, row, COL_MIMETYPE,
4929 ainfo->content_type);
4930 gtk_clist_set_text(clist, row, COL_SIZE,
4931 to_human_readable(ainfo->size));
4932 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
4934 gtk_widget_hide(attach_prop.window);
4939 #define SET_LABEL_AND_ENTRY(str, entry, top) \
4941 label = gtk_label_new(str); \
4942 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
4943 GTK_FILL, 0, 0, 0); \
4944 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
4946 entry = gtk_entry_new(); \
4947 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
4948 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
4951 static void compose_attach_property_create(gboolean *cancelled)
4957 GtkWidget *mimetype_entry;
4960 GtkWidget *optmenu_menu;
4961 GtkWidget *menuitem;
4962 GtkWidget *path_entry;
4963 GtkWidget *filename_entry;
4966 GtkWidget *cancel_btn;
4967 GList *mime_type_list, *strlist;
4969 debug_print("Creating attach_property window...\n");
4971 window = gtk_window_new(GTK_WINDOW_DIALOG);
4972 gtk_widget_set_usize(window, 480, -1);
4973 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
4974 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
4975 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
4976 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
4977 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4978 GTK_SIGNAL_FUNC(attach_property_delete_event),
4980 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
4981 GTK_SIGNAL_FUNC(attach_property_key_pressed),
4984 vbox = gtk_vbox_new(FALSE, 8);
4985 gtk_container_add(GTK_CONTAINER(window), vbox);
4987 table = gtk_table_new(4, 2, FALSE);
4988 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
4989 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
4990 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
4992 label = gtk_label_new(_("MIME type"));
4993 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
4995 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
4996 mimetype_entry = gtk_combo_new();
4997 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
4998 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5000 /* stuff with list */
5001 mime_type_list = procmime_get_mime_type_list();
5003 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
5004 MimeType *type = (MimeType *) mime_type_list->data;
5005 strlist = g_list_append(strlist,
5006 g_strdup_printf("%s/%s",
5007 type->type, type->sub_type));
5010 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
5012 for (mime_type_list = strlist; mime_type_list != NULL;
5013 mime_type_list = mime_type_list->next)
5014 g_free(mime_type_list->data);
5015 g_list_free(strlist);
5017 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
5019 label = gtk_label_new(_("Encoding"));
5020 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
5022 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5024 hbox = gtk_hbox_new(FALSE, 0);
5025 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
5026 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
5028 optmenu = gtk_option_menu_new();
5029 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
5031 optmenu_menu = gtk_menu_new();
5032 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
5033 gtk_widget_set_sensitive(menuitem, FALSE);
5034 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
5035 gtk_widget_set_sensitive(menuitem, FALSE);
5036 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
5037 gtk_widget_set_sensitive(menuitem, FALSE);
5038 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
5040 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
5042 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
5043 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
5045 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
5046 &cancel_btn, _("Cancel"), NULL, NULL);
5047 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
5048 gtk_widget_grab_default(ok_btn);
5050 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
5051 GTK_SIGNAL_FUNC(attach_property_ok),
5053 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
5054 GTK_SIGNAL_FUNC(attach_property_cancel),
5057 gtk_widget_show_all(vbox);
5059 attach_prop.window = window;
5060 attach_prop.mimetype_entry = mimetype_entry;
5061 attach_prop.encoding_optmenu = optmenu;
5062 attach_prop.path_entry = path_entry;
5063 attach_prop.filename_entry = filename_entry;
5064 attach_prop.ok_btn = ok_btn;
5065 attach_prop.cancel_btn = cancel_btn;
5068 #undef SET_LABEL_AND_ENTRY
5070 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5076 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5082 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5083 gboolean *cancelled)
5091 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5092 gboolean *cancelled)
5094 if (event && event->keyval == GDK_Escape) {
5100 static void compose_exec_ext_editor(Compose *compose)
5106 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5107 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5109 if (pipe(pipe_fds) < 0) {
5114 if ((pid = fork()) < 0) {
5120 /* close the write side of the pipe */
5123 compose->exteditor_file = g_strdup(tmp);
5124 compose->exteditor_pid = pid;
5125 compose->exteditor_readdes = pipe_fds[0];
5127 compose_set_ext_editor_sensitive(compose, FALSE);
5129 compose->exteditor_tag =
5130 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5131 compose_input_cb, compose);
5132 } else { /* process-monitoring process */
5138 /* close the read side of the pipe */
5141 if (compose_write_body_to_file(compose, tmp) < 0) {
5142 fd_write(pipe_fds[1], "2\n", 2);
5146 pid_ed = compose_exec_ext_editor_real(tmp);
5148 fd_write(pipe_fds[1], "1\n", 2);
5152 /* wait until editor is terminated */
5153 waitpid(pid_ed, NULL, 0);
5155 fd_write(pipe_fds[1], "0\n", 2);
5162 static gint compose_exec_ext_editor_real(const gchar *file)
5164 static gchar *def_cmd = "emacs %s";
5170 g_return_val_if_fail(file != NULL, -1);
5172 if ((pid = fork()) < 0) {
5177 if (pid != 0) return pid;
5179 /* grandchild process */
5181 if (setpgid(0, getppid()))
5184 if (prefs_common.ext_editor_cmd &&
5185 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5186 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5187 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5189 if (prefs_common.ext_editor_cmd)
5190 g_warning(_("External editor command line is invalid: `%s'\n"),
5191 prefs_common.ext_editor_cmd);
5192 g_snprintf(buf, sizeof(buf), def_cmd, file);
5195 cmdline = g_strsplit(buf, " ", 1024);
5196 execvp(cmdline[0], cmdline);
5199 g_strfreev(cmdline);
5204 static gboolean compose_ext_editor_kill(Compose *compose)
5206 pid_t pgid = compose->exteditor_pid * -1;
5209 ret = kill(pgid, 0);
5211 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5215 msg = g_strdup_printf
5216 (_("The external editor is still working.\n"
5217 "Force terminating the process?\n"
5218 "process group id: %d"), -pgid);
5219 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5222 if (val == G_ALERTDEFAULT) {
5223 gdk_input_remove(compose->exteditor_tag);
5224 close(compose->exteditor_readdes);
5226 if (kill(pgid, SIGTERM) < 0) perror("kill");
5227 waitpid(compose->exteditor_pid, NULL, 0);
5229 g_warning(_("Terminated process group id: %d"), -pgid);
5230 g_warning(_("Temporary file: %s"),
5231 compose->exteditor_file);
5233 compose_set_ext_editor_sensitive(compose, TRUE);
5235 g_free(compose->exteditor_file);
5236 compose->exteditor_file = NULL;
5237 compose->exteditor_pid = -1;
5238 compose->exteditor_readdes = -1;
5239 compose->exteditor_tag = -1;
5247 static void compose_input_cb(gpointer data, gint source,
5248 GdkInputCondition condition)
5251 Compose *compose = (Compose *)data;
5254 debug_print(_("Compose: input from monitoring process\n"));
5256 gdk_input_remove(compose->exteditor_tag);
5259 if (read(source, &buf[i], 1) < 1) {
5263 if (buf[i] == '\n') {
5268 if (i == sizeof(buf) - 1)
5272 waitpid(compose->exteditor_pid, NULL, 0);
5274 if (buf[0] == '0') { /* success */
5275 GtkSText *text = GTK_STEXT(compose->text);
5277 gtk_stext_freeze(text);
5278 gtk_stext_set_point(text, 0);
5279 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5280 compose_insert_file(compose, compose->exteditor_file);
5281 compose_changed_cb(NULL, compose);
5282 gtk_stext_thaw(text);
5284 if (unlink(compose->exteditor_file) < 0)
5285 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5286 } else if (buf[0] == '1') { /* failed */
5287 g_warning(_("Couldn't exec external editor\n"));
5288 if (unlink(compose->exteditor_file) < 0)
5289 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5290 } else if (buf[0] == '2') {
5291 g_warning(_("Couldn't write to file\n"));
5292 } else if (buf[0] == '3') {
5293 g_warning(_("Pipe read failed\n"));
5298 compose_set_ext_editor_sensitive(compose, TRUE);
5300 g_free(compose->exteditor_file);
5301 compose->exteditor_file = NULL;
5302 compose->exteditor_pid = -1;
5303 compose->exteditor_readdes = -1;
5304 compose->exteditor_tag = -1;
5307 static void compose_set_ext_editor_sensitive(Compose *compose,
5310 GtkItemFactory *ifactory;
5312 ifactory = gtk_item_factory_from_widget(compose->menubar);
5314 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5315 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5316 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5318 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5319 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5320 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5321 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5322 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5325 gtk_widget_set_sensitive(compose->text, sensitive);
5326 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5327 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5328 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5329 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5330 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5331 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5332 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5335 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5339 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5340 cursor_pos = MAX(cursor_pos, 0);
5345 /* callback functions */
5347 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5348 * includes "non-client" (windows-izm) in calculation, so this calculation
5349 * may not be accurate.
5351 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5352 GtkAllocation *allocation,
5353 GtkSHRuler *shruler)
5355 if (prefs_common.show_ruler) {
5357 gint line_width_in_chars;
5359 char_width = gtkut_get_font_width
5360 (GTK_WIDGET(widget)->style->font);
5361 line_width_in_chars =
5362 (allocation->width - allocation->x) / char_width;
5364 /* got the maximum */
5365 gtk_ruler_set_range(GTK_RULER(shruler),
5366 0.0, line_width_in_chars,
5367 calc_cursor_xpos(GTK_STEXT(widget),
5370 /*line_width_in_chars*/ char_width);
5376 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5378 compose_send_cb(data, 0, NULL);
5381 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5383 compose_send_later_cb(data, 0, NULL);
5386 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5388 compose_draft_cb(data, 0, NULL);
5391 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5393 compose_insert_file_cb(data, 0, NULL);
5396 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5398 compose_attach_cb(data, 0, NULL);
5401 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5403 Compose *compose = (Compose *)data;
5405 compose_insert_sig(compose);
5408 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5410 Compose *compose = (Compose *)data;
5412 compose_exec_ext_editor(compose);
5415 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5417 Compose *compose = (Compose *)data;
5419 compose_wrap_line(compose);
5422 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5424 compose_address_cb(data, 0, NULL);
5427 static void select_account(Compose * compose, PrefsAccount * ac)
5429 compose->account = ac;
5430 compose_set_title(compose);
5432 #if 0 /* NEW COMPOSE GUI */
5433 if (ac->protocol == A_NNTP) {
5434 GtkItemFactory *ifactory;
5435 GtkWidget *menuitem;
5437 ifactory = gtk_item_factory_from_widget(compose->menubar);
5438 menu_set_sensitive(ifactory,
5439 "/Message/Followup to", TRUE);
5440 gtk_widget_show(compose->newsgroups_hbox);
5441 gtk_widget_show(compose->newsgroups_entry);
5442 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5445 compose->use_to = FALSE;
5446 compose->use_cc = FALSE;
5448 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5449 gtk_check_menu_item_set_active
5450 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5452 menu_set_sensitive(ifactory,
5453 "/Message/To", TRUE);
5454 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5455 gtk_check_menu_item_set_active
5456 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5458 gtk_widget_hide(compose->to_hbox);
5459 gtk_widget_hide(compose->to_entry);
5460 gtk_widget_hide(compose->cc_hbox);
5461 gtk_widget_hide(compose->cc_entry);
5462 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5464 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5468 GtkItemFactory *ifactory;
5469 GtkWidget *menuitem;
5471 ifactory = gtk_item_factory_from_widget(compose->menubar);
5472 menu_set_sensitive(ifactory,
5473 "/Message/Followup to", FALSE);
5474 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5475 gtk_widget_hide(compose->newsgroups_hbox);
5476 gtk_widget_hide(compose->newsgroups_entry);
5477 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5480 compose->use_to = TRUE;
5481 compose->use_cc = TRUE;
5483 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5484 gtk_check_menu_item_set_active
5485 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5486 menu_set_sensitive(ifactory,
5487 "/Message/To", FALSE);
5488 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5489 gtk_check_menu_item_set_active
5490 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5491 gtk_widget_show(compose->to_hbox);
5492 gtk_widget_show(compose->to_entry);
5493 gtk_widget_show(compose->cc_hbox);
5494 gtk_widget_show(compose->cc_entry);
5496 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5498 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5501 gtk_widget_queue_resize(compose->table_vbox);
5505 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5507 Compose *compose = (Compose *)data;
5511 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5512 g_return_if_fail(ac != NULL);
5514 if (ac != compose->account)
5515 select_account(compose, ac);
5518 static void attach_selected(GtkCList *clist, gint row, gint column,
5519 GdkEvent *event, gpointer data)
5521 Compose *compose = (Compose *)data;
5523 if (event && event->type == GDK_2BUTTON_PRESS)
5524 compose_attach_property(compose);
5527 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5530 Compose *compose = (Compose *)data;
5531 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5536 if (event->button == 3) {
5537 if ((clist->selection && !clist->selection->next) ||
5538 !clist->selection) {
5539 gtk_clist_unselect_all(clist);
5540 if (gtk_clist_get_selection_info(clist,
5543 gtk_clist_select_row(clist, row, column);
5544 gtkut_clist_set_focus_row(clist, row);
5547 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5548 NULL, NULL, event->button, event->time);
5552 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5555 Compose *compose = (Compose *)data;
5559 switch (event->keyval) {
5561 compose_attach_remove_selected(compose);
5566 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5568 Compose *compose = (Compose *)data;
5571 val = compose_send(compose);
5572 if (val == 0) gtk_widget_destroy(compose->window);
5575 static void compose_send_later_cb(gpointer data, guint action,
5578 Compose *compose = (Compose *)data;
5581 val = compose_queue(compose, NULL, NULL);
5582 if (!val) gtk_widget_destroy(compose->window);
5585 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5587 Compose *compose = (Compose *)data;
5591 draft = folder_get_default_draft();
5593 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5594 G_DIR_SEPARATOR, (gint)compose);
5596 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5601 folder_item_scan(draft);
5602 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
5609 if (compose->mode == COMPOSE_REEDIT) {
5610 compose_remove_reedit_target(compose);
5611 if (compose->targetinfo &&
5612 compose->targetinfo->folder != draft)
5613 folderview_update_item(compose->targetinfo->folder,
5617 folder_item_scan(draft);
5618 folderview_update_item(draft, TRUE);
5620 gtk_widget_destroy(compose->window);
5623 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
5625 Compose *compose = (Compose *)data;
5628 if (compose->bounce_filename != NULL)
5631 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5636 for ( tmp = file_list; tmp; tmp = tmp->next) {
5637 gchar *file = (gchar *) tmp->data;
5638 compose_attach_append(compose, file, MIME_UNKNOWN);
5641 g_list_free(file_list);
5645 static void compose_insert_file_cb(gpointer data, guint action,
5648 Compose *compose = (Compose *)data;
5651 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5656 for ( tmp = file_list; tmp; tmp = tmp->next) {
5657 gchar *file = (gchar *) tmp->data;
5658 compose_insert_file(compose, file);
5661 g_list_free(file_list);
5665 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
5668 compose_close_cb(data, 0, NULL);
5672 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
5674 Compose *compose = (Compose *)data;
5677 if (compose->exteditor_tag != -1) {
5678 if (!compose_ext_editor_kill(compose))
5682 if (compose->modified) {
5683 val = alertpanel(_("Discard message"),
5684 _("This message has been modified. discard it?"),
5685 _("Discard"), _("to Draft"), _("Cancel"));
5688 case G_ALERTDEFAULT:
5690 case G_ALERTALTERNATE:
5691 compose_draft_cb(data, 0, NULL);
5698 if (compose->gtkpspell) {
5699 gtkpspell_detach(compose->gtkpspell);
5700 compose->gtkpspell = gtkpspell_delete(compose->gtkpspell);
5703 gtk_widget_destroy(compose->window);
5706 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
5708 Compose *compose = (Compose *)data;
5710 addressbook_open(compose);
5713 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
5715 Compose *compose = (Compose *)data;
5718 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
5719 g_return_if_fail(tmpl != NULL);
5721 compose_template_apply(compose, tmpl);
5724 static void compose_ext_editor_cb(gpointer data, guint action,
5727 Compose *compose = (Compose *)data;
5729 compose_exec_ext_editor(compose);
5732 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
5734 compose_destroy(compose);
5737 static void compose_undo_cb(Compose *compose)
5739 undo_undo(compose->undostruct);
5742 static void compose_redo_cb(Compose *compose)
5744 undo_redo(compose->undostruct);
5747 static void compose_cut_cb(Compose *compose)
5749 if (compose->focused_editable &&
5750 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5751 gtk_editable_cut_clipboard
5752 (GTK_EDITABLE(compose->focused_editable));
5755 static void compose_copy_cb(Compose *compose)
5757 if (compose->focused_editable &&
5758 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5759 gtk_editable_copy_clipboard
5760 (GTK_EDITABLE(compose->focused_editable));
5763 static void compose_paste_cb(Compose *compose)
5765 if (compose->focused_editable &&
5766 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5767 gtk_editable_paste_clipboard
5768 (GTK_EDITABLE(compose->focused_editable));
5771 static void compose_allsel_cb(Compose *compose)
5773 if (compose->focused_editable &&
5774 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5775 gtk_editable_select_region
5776 (GTK_EDITABLE(compose->focused_editable), 0, -1);
5779 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
5781 if (GTK_IS_EDITABLE(widget))
5782 compose->focused_editable = widget;
5785 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
5787 if (compose->modified == FALSE) {
5788 compose->modified = TRUE;
5789 compose_set_title(compose);
5793 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
5796 gtk_stext_set_point(GTK_STEXT(widget),
5797 gtk_editable_get_position(GTK_EDITABLE(widget)));
5801 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
5804 gtk_stext_set_point(GTK_STEXT(widget),
5805 gtk_editable_get_position(GTK_EDITABLE(widget)));
5809 #if 0 /* NEW COMPOSE GUI */
5810 static void compose_toggle_to_cb(gpointer data, guint action,
5813 Compose *compose = (Compose *)data;
5815 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5816 gtk_widget_show(compose->to_hbox);
5817 gtk_widget_show(compose->to_entry);
5818 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
5819 compose->use_to = TRUE;
5821 gtk_widget_hide(compose->to_hbox);
5822 gtk_widget_hide(compose->to_entry);
5823 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
5824 gtk_widget_queue_resize(compose->table_vbox);
5825 compose->use_to = FALSE;
5828 if (addressbook_get_target_compose() == compose)
5829 addressbook_set_target_compose(compose);
5832 static void compose_toggle_cc_cb(gpointer data, guint action,
5835 Compose *compose = (Compose *)data;
5837 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5838 gtk_widget_show(compose->cc_hbox);
5839 gtk_widget_show(compose->cc_entry);
5840 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
5841 compose->use_cc = TRUE;
5843 gtk_widget_hide(compose->cc_hbox);
5844 gtk_widget_hide(compose->cc_entry);
5845 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
5846 gtk_widget_queue_resize(compose->table_vbox);
5847 compose->use_cc = FALSE;
5850 if (addressbook_get_target_compose() == compose)
5851 addressbook_set_target_compose(compose);
5854 static void compose_toggle_bcc_cb(gpointer data, guint action,
5857 Compose *compose = (Compose *)data;
5859 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5860 gtk_widget_show(compose->bcc_hbox);
5861 gtk_widget_show(compose->bcc_entry);
5862 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
5863 compose->use_bcc = TRUE;
5865 gtk_widget_hide(compose->bcc_hbox);
5866 gtk_widget_hide(compose->bcc_entry);
5867 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
5868 gtk_widget_queue_resize(compose->table_vbox);
5869 compose->use_bcc = FALSE;
5872 if (addressbook_get_target_compose() == compose)
5873 addressbook_set_target_compose(compose);
5876 static void compose_toggle_replyto_cb(gpointer data, guint action,
5879 Compose *compose = (Compose *)data;
5881 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5882 gtk_widget_show(compose->reply_hbox);
5883 gtk_widget_show(compose->reply_entry);
5884 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
5885 compose->use_replyto = TRUE;
5887 gtk_widget_hide(compose->reply_hbox);
5888 gtk_widget_hide(compose->reply_entry);
5889 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
5890 gtk_widget_queue_resize(compose->table_vbox);
5891 compose->use_replyto = FALSE;
5895 static void compose_toggle_followupto_cb(gpointer data, guint action,
5898 Compose *compose = (Compose *)data;
5900 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5901 gtk_widget_show(compose->followup_hbox);
5902 gtk_widget_show(compose->followup_entry);
5903 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
5904 compose->use_followupto = TRUE;
5906 gtk_widget_hide(compose->followup_hbox);
5907 gtk_widget_hide(compose->followup_entry);
5908 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
5909 gtk_widget_queue_resize(compose->table_vbox);
5910 compose->use_followupto = FALSE;
5914 static void compose_toggle_attach_cb(gpointer data, guint action,
5917 Compose *compose = (Compose *)data;
5919 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5920 gtk_widget_ref(compose->edit_vbox);
5922 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5923 compose->edit_vbox);
5924 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
5925 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
5927 gtk_widget_show(compose->paned);
5929 gtk_widget_unref(compose->edit_vbox);
5930 gtk_widget_unref(compose->paned);
5932 compose->use_attach = TRUE;
5934 gtk_widget_ref(compose->paned);
5935 gtk_widget_ref(compose->edit_vbox);
5937 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5939 gtk_container_remove(GTK_CONTAINER(compose->paned),
5940 compose->edit_vbox);
5941 gtk_box_pack_start(GTK_BOX(compose->vbox2),
5942 compose->edit_vbox, TRUE, TRUE, 0);
5944 gtk_widget_unref(compose->edit_vbox);
5946 compose->use_attach = FALSE;
5952 static void compose_toggle_sign_cb(gpointer data, guint action,
5955 Compose *compose = (Compose *)data;
5957 if (GTK_CHECK_MENU_ITEM(widget)->active)
5958 compose->use_signing = TRUE;
5960 compose->use_signing = FALSE;
5963 static void compose_toggle_encrypt_cb(gpointer data, guint action,
5966 Compose *compose = (Compose *)data;
5968 if (GTK_CHECK_MENU_ITEM(widget)->active)
5969 compose->use_encryption = TRUE;
5971 compose->use_encryption = FALSE;
5973 #endif /* USE_GPGME */
5975 static void compose_toggle_ruler_cb(gpointer data, guint action,
5978 Compose *compose = (Compose *)data;
5980 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5981 gtk_widget_show(compose->ruler_hbox);
5982 prefs_common.show_ruler = TRUE;
5984 gtk_widget_hide(compose->ruler_hbox);
5985 gtk_widget_queue_resize(compose->edit_vbox);
5986 prefs_common.show_ruler = FALSE;
5990 static void compose_attach_drag_received_cb (GtkWidget *widget,
5991 GdkDragContext *drag_context,
5994 GtkSelectionData *data,
5999 Compose *compose = (Compose *)user_data;
6002 list = uri_list_extract_filenames((const gchar *)data->data);
6003 for (tmp = list; tmp != NULL; tmp = tmp->next)
6004 compose_attach_append(compose, (const gchar *)tmp->data,
6006 list_free_strings(list);
6010 static void compose_insert_drag_received_cb (GtkWidget *widget,
6011 GdkDragContext *drag_context,
6014 GtkSelectionData *data,
6019 Compose *compose = (Compose *)user_data;
6022 list = uri_list_extract_filenames((const gchar *)data->data);
6023 for (tmp = list; tmp != NULL; tmp = tmp->next)
6024 compose_insert_file(compose, (const gchar *)tmp->data);
6025 list_free_strings(list);
6029 #if 0 /* NEW COMPOSE GUI */
6030 static void to_activated(GtkWidget *widget, Compose *compose)
6032 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
6033 gtk_widget_grab_focus(compose->newsgroups_entry);
6035 gtk_widget_grab_focus(compose->subject_entry);
6038 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
6040 gtk_widget_grab_focus(compose->subject_entry);
6043 static void subject_activated(GtkWidget *widget, Compose *compose)
6045 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
6046 gtk_widget_grab_focus(compose->cc_entry);
6047 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6048 gtk_widget_grab_focus(compose->bcc_entry);
6049 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6050 gtk_widget_grab_focus(compose->reply_entry);
6051 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6052 gtk_widget_grab_focus(compose->followup_entry);
6054 gtk_widget_grab_focus(compose->text);
6057 static void cc_activated(GtkWidget *widget, Compose *compose)
6059 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
6060 gtk_widget_grab_focus(compose->bcc_entry);
6061 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
6062 gtk_widget_grab_focus(compose->reply_entry);
6063 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6064 gtk_widget_grab_focus(compose->followup_entry);
6066 gtk_widget_grab_focus(compose->text);
6069 static void bcc_activated(GtkWidget *widget, Compose *compose)
6071 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 replyto_activated(GtkWidget *widget, Compose *compose)
6081 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6082 gtk_widget_grab_focus(compose->followup_entry);
6084 gtk_widget_grab_focus(compose->text);
6087 static void followupto_activated(GtkWidget *widget, Compose *compose)
6089 gtk_widget_grab_focus(compose->text);
6093 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6096 Compose *compose = (Compose *)data;
6098 if (GTK_CHECK_MENU_ITEM(widget)->active)
6099 compose->return_receipt = TRUE;
6101 compose->return_receipt = FALSE;
6104 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6106 ComposeHeaderEntry *headerentry)
6108 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6109 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6110 !(event->state & GDK_MODIFIER_MASK) &&
6111 (event->keyval == GDK_BackSpace) &&
6112 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6113 gtk_container_remove
6114 (GTK_CONTAINER(headerentry->compose->header_table),
6115 headerentry->combo);
6116 gtk_container_remove
6117 (GTK_CONTAINER(headerentry->compose->header_table),
6118 headerentry->entry);
6119 headerentry->compose->header_list =
6120 g_slist_remove(headerentry->compose->header_list,
6122 g_free(headerentry);
6126 void compose_headerentry_changed_cb(GtkWidget *entry,
6127 ComposeHeaderEntry *headerentry)
6129 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6130 headerentry->compose->header_list =
6131 g_slist_append(headerentry->compose->header_list,
6133 compose_create_header_entry(headerentry->compose);
6134 gtk_signal_disconnect_by_func
6136 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
6144 * Change the sensivity of the menuentries undo and redo
6146 static void compose_set_undo(UndoMain *undostruct, gint undo_state,
6147 gint redo_state, GtkWidget *changewidget)
6149 GtkItemFactory *ifactory;
6150 debug_print ("Set_undo. UNDO:%i REDO:%i\n",
6154 g_return_if_fail (changewidget != NULL);
6156 ifactory = gtk_item_factory_from_widget(changewidget);
6159 switch (undo_state) {
6160 case UNDO_STATE_TRUE:
6161 if (!undostruct->undo_state) {
6162 debug_print ("Set_undo - Testpoint\n");
6163 undostruct->undo_state = TRUE;
6164 menu_set_sensitive(ifactory, "/Edit/Undo", TRUE);
6167 case UNDO_STATE_FALSE:
6168 if (undostruct->undo_state) {
6169 undostruct->undo_state = FALSE;
6170 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
6173 case UNDO_STATE_UNCHANGED:
6175 case UNDO_STATE_REFRESH:
6176 menu_set_sensitive(ifactory, "/Edit/Undo", undostruct->undo_state);
6179 g_warning ("Undo state not recognized");
6184 switch (redo_state) {
6185 case UNDO_STATE_TRUE:
6186 if (!undostruct->redo_state) {
6187 undostruct->redo_state = TRUE;
6188 menu_set_sensitive(ifactory, "/Edit/Redo", TRUE);
6191 case UNDO_STATE_FALSE:
6192 if (undostruct->redo_state) {
6193 undostruct->redo_state = FALSE;
6194 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
6197 case UNDO_STATE_UNCHANGED:
6199 case UNDO_STATE_REFRESH:
6200 menu_set_sensitive(ifactory, "/Edit/Redo", undostruct->redo_state);
6203 g_warning ("Redo state not recognized");